{ "version": 3, "sources": ["../../node_modules/mersenne-twister/src/mersenne-twister.js", "../../node_modules/urijs/src/punycode.js", "../../node_modules/urijs/src/IPv6.js", "../../node_modules/urijs/src/SecondLevelDomains.js", "../../node_modules/urijs/src/URI.js", "../../node_modules/dompurify/src/utils.js", "../../node_modules/dompurify/src/tags.js", "../../node_modules/dompurify/src/attrs.js", "../../node_modules/dompurify/src/regexp.js", "../../node_modules/dompurify/src/purify.js", "../../node_modules/bitmap-sdf/index.js", "../../node_modules/grapheme-splitter/index.js", "../../node_modules/earcut/src/earcut.js", "../../node_modules/rbush/rbush.min.js", "../../node_modules/protobufjs/dist/minimal/lib/prelude.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/aspromise/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/base64/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/eventemitter/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/float/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/inquire/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/pool/index.js", "../../node_modules/protobufjs/dist/node_modules/@protobufjs/utf8/index.js", "../../node_modules/protobufjs/dist/src/index-minimal", "../../node_modules/protobufjs/dist/src/reader.js", "../../node_modules/protobufjs/dist/src/reader_buffer.js", "../../node_modules/protobufjs/dist/src/roots.js", "../../node_modules/protobufjs/dist/src/rpc.js", "../../node_modules/protobufjs/dist/src/rpc/service.js", "../../node_modules/protobufjs/dist/src/util/longbits.js", "../../node_modules/protobufjs/dist/src/util/minimal.js", "../../node_modules/protobufjs/dist/src/writer.js", "../../node_modules/protobufjs/dist/src/writer_buffer.js", "../../node_modules/lerc/LercDecode.js", "../../node_modules/nosleep.js/src/media.js", "../../node_modules/nosleep.js/src/index.js", "../../Source/Cesium.js", "../../node_modules/@cesium/engine/Source/Core/defined.js", "../../node_modules/@cesium/engine/Source/Core/DeveloperError.js", "../../node_modules/@cesium/engine/Source/Core/Check.js", "../../node_modules/@cesium/engine/Source/Core/defaultValue.js", "../../node_modules/@cesium/engine/Source/Core/Math.js", "../../node_modules/@cesium/engine/Source/Core/Cartesian3.js", "../../node_modules/@cesium/engine/Source/Core/Cartesian4.js", "../../node_modules/@cesium/engine/Source/Core/Matrix3.js", "../../node_modules/@cesium/engine/Source/Core/RuntimeError.js", "../../node_modules/@cesium/engine/Source/Core/Matrix4.js", "../../node_modules/@cesium/engine/Source/Core/WebGLConstants.js", "../../node_modules/@cesium/engine/Source/Renderer/AutomaticUniforms.js", "../../node_modules/@cesium/engine/Source/Core/createGuid.js", "../../node_modules/@cesium/engine/Source/Core/destroyObject.js", "../../node_modules/@cesium/engine/Source/Core/IndexDatatype.js", "../../node_modules/@cesium/engine/Source/Renderer/BufferUsage.js", "../../node_modules/@cesium/engine/Source/Renderer/Buffer.js", "../../node_modules/@cesium/engine/Source/Core/Fullscreen.js", "../../node_modules/@cesium/engine/Source/Core/FeatureDetection.js", "../../node_modules/@cesium/engine/Source/Core/Color.js", "../../node_modules/@cesium/engine/Source/Renderer/ClearCommand.js", "../../node_modules/@cesium/engine/Source/Renderer/Pass.js", "../../node_modules/@cesium/engine/Source/Renderer/ComputeCommand.js", "../../node_modules/@cesium/engine/Source/Core/Cartesian2.js", "../../node_modules/@cesium/engine/Source/Core/scaleToGeodeticSurface.js", "../../node_modules/@cesium/engine/Source/Core/Cartographic.js", "../../node_modules/@cesium/engine/Source/Core/Ellipsoid.js", "../../node_modules/@cesium/engine/Source/Core/GeographicProjection.js", "../../node_modules/@cesium/engine/Source/Core/Intersect.js", "../../node_modules/@cesium/engine/Source/Core/Rectangle.js", "../../node_modules/@cesium/engine/Source/Core/BoundingRectangle.js", "../../node_modules/@cesium/engine/Source/Core/PrimitiveType.js", "../../node_modules/@cesium/engine/Source/Shaders/ViewportQuadVS.js", "../../node_modules/@cesium/engine/Source/Renderer/DrawCommand.js", "../../node_modules/@cesium/engine/Source/Renderer/PixelDatatype.js", "../../node_modules/@cesium/engine/Source/Core/PixelFormat.js", "../../node_modules/@cesium/engine/Source/Renderer/ContextLimits.js", "../../node_modules/@cesium/engine/Source/Renderer/Framebuffer.js", "../../node_modules/@cesium/engine/Source/Core/WindingOrder.js", "../../node_modules/@cesium/engine/Source/Renderer/freezeRenderState.js", "../../node_modules/@cesium/engine/Source/Renderer/RenderState.js", "../../node_modules/@cesium/engine/Source/Core/Matrix2.js", "../../node_modules/@cesium/engine/Source/Renderer/createUniform.js", "../../node_modules/@cesium/engine/Source/Renderer/createUniformArray.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderProgram.js", "../../node_modules/@cesium/engine/Source/Renderer/ComputeEngine.js", "../../node_modules/@cesium/engine/Source/Core/ComponentDatatype.js", "../../node_modules/@cesium/engine/Source/Core/oneTimeWarning.js", "../../node_modules/@cesium/engine/Source/Core/deprecationWarning.js", "../../node_modules/@cesium/engine/Source/Core/GeometryType.js", "../../node_modules/@cesium/engine/Source/Core/Quaternion.js", "../../node_modules/@cesium/engine/Source/Core/binarySearch.js", "../../node_modules/@cesium/engine/Source/Core/EarthOrientationParametersSample.js", "../../node_modules/@cesium/engine/Source/Core/GregorianDate.js", "../../node_modules/@cesium/engine/Source/Core/isLeapYear.js", "../../node_modules/@cesium/engine/Source/Core/LeapSecond.js", "../../node_modules/@cesium/engine/Source/Core/TimeConstants.js", "../../node_modules/@cesium/engine/Source/Core/TimeStandard.js", "../../node_modules/@cesium/engine/Source/Core/JulianDate.js", "../../node_modules/@cesium/engine/Source/Core/Resource.js", "../../node_modules/@cesium/engine/Source/Core/appendForwardSlash.js", "../../node_modules/@cesium/engine/Source/Core/clone.js", "../../node_modules/@cesium/engine/Source/Core/combine.js", "../../node_modules/@cesium/engine/Source/Core/defer.js", "../../node_modules/@cesium/engine/Source/Core/getAbsoluteUri.js", "../../node_modules/@cesium/engine/Source/Core/getBaseUri.js", "../../node_modules/@cesium/engine/Source/Core/getExtensionFromUri.js", "../../node_modules/@cesium/engine/Source/Core/getImagePixels.js", "../../node_modules/@cesium/engine/Source/Core/isBlobUri.js", "../../node_modules/@cesium/engine/Source/Core/isCrossOriginUrl.js", "../../node_modules/@cesium/engine/Source/Core/isDataUri.js", "../../node_modules/@cesium/engine/Source/Core/loadAndExecuteScript.js", "../../node_modules/@cesium/engine/Source/Core/objectToQuery.js", "../../node_modules/@cesium/engine/Source/Core/queryToObject.js", "../../node_modules/@cesium/engine/Source/Core/RequestState.js", "../../node_modules/@cesium/engine/Source/Core/RequestType.js", "../../node_modules/@cesium/engine/Source/Core/Request.js", "../../node_modules/@cesium/engine/Source/Core/parseResponseHeaders.js", "../../node_modules/@cesium/engine/Source/Core/RequestErrorEvent.js", "../../node_modules/@cesium/engine/Source/Core/RequestScheduler.js", "../../node_modules/@cesium/engine/Source/Core/Event.js", "../../node_modules/@cesium/engine/Source/Core/Heap.js", "../../node_modules/@cesium/engine/Source/Core/TrustedServers.js", "../../node_modules/@cesium/engine/Source/Core/EarthOrientationParameters.js", "../../node_modules/@cesium/engine/Source/Core/HeadingPitchRoll.js", "../../node_modules/@cesium/engine/Source/Core/buildModuleUrl.js", "../../node_modules/@cesium/engine/Source/Core/Iau2006XysSample.js", "../../node_modules/@cesium/engine/Source/Core/Iau2006XysData.js", "../../node_modules/@cesium/engine/Source/Core/Transforms.js", "../../node_modules/@cesium/engine/Source/Core/Geometry.js", "../../node_modules/@cesium/engine/Source/Core/GeometryAttribute.js", "../../node_modules/@cesium/engine/Source/Core/CompressedTextureBuffer.js", "../../node_modules/@cesium/engine/Source/Core/TaskProcessor.js", "../../node_modules/@cesium/engine/Source/Core/KTX2Transcoder.js", "../../node_modules/@cesium/engine/Source/Core/loadKTX2.js", "../../node_modules/@cesium/engine/Source/Renderer/CubeMapFace.js", "../../node_modules/@cesium/engine/Source/Renderer/MipmapHint.js", "../../node_modules/@cesium/engine/Source/Renderer/TextureMagnificationFilter.js", "../../node_modules/@cesium/engine/Source/Renderer/TextureMinificationFilter.js", "../../node_modules/@cesium/engine/Source/Renderer/TextureWrap.js", "../../node_modules/@cesium/engine/Source/Renderer/Sampler.js", "../../node_modules/@cesium/engine/Source/Renderer/CubeMap.js", "../../node_modules/@cesium/engine/Source/Renderer/PassState.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/degreesPerRadian.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/depthRange.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon1.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon2.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon3.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon4.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon5.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon6.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/epsilon7.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/infinity.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/oneOverPi.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/oneOverTwoPi.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passCesium3DTile.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passClassification.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passCompute.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passEnvironment.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passGlobe.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passOpaque.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passOverlay.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passTerrainClassification.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passTranslucent.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/passVoxels.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/pi.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/piOverFour.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/piOverSix.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/piOverThree.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/piOverTwo.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/radiansPerDegree.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/sceneMode2D.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/sceneMode3D.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/sceneModeColumbusView.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/sceneModeMorphing.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/solarRadius.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/threePiOver2.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/twoPi.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Constants/webMercatorMaxLatitude.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/depthRangeStruct.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/material.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/materialInput.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/modelMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/modelVertexOutput.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/pbrParameters.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/ray.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/raySegment.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Structs/shadowParameters.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/HSBToRGB.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/HSLToRGB.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/RGBToHSB.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/RGBToHSL.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/RGBToXYZ.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/XYZToRGB.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/acesTonemapping.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/alphaWeight.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/antialias.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/approximateSphericalCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/backFacing.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/branchFreeTernary.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/cascadeColor.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/cascadeDistance.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/cascadeMatrix.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/cascadeWeights.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/columbusViewMorph.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/computePosition.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/cosineAndSine.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/decompressTextureCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/defaultPbrMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/depthClamp.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/eastNorthUpToEyeCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/ellipsoidContainsPoint.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/ellipsoidWgs84TextureCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/equalsEpsilon.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/eyeOffset.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/eyeToWindowCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/fastApproximateAtan.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/fog.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/gammaCorrect.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/geodeticSurfaceNormal.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/getDefaultMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/getLambertDiffuse.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/getSpecular.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/getWaterNoise.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/hue.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/inverseGamma.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/isEmpty.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/isFull.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/latitudeToWebMercatorFraction.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/lineDistance.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/linearToSrgb.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/luminance.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/metersPerPixel.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/multiplyWithColorBalance.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/nearFarScalar.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/octDecode.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/packDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/pbrLighting.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/phong.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/planeDistance.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/pointAlongRay.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/rayEllipsoidIntersectionInterval.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/raySphereIntersectionInterval.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/readDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/readNonPerspective.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/reverseLogDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/round.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/saturation.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/shadowDepthCompare.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/shadowVisibility.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/signNotZero.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/sphericalHarmonics.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/srgbToLinear.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/tangentToEyeSpaceMatrix.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/textureCube.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/transformPlane.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/translateRelativeToEye.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/translucentPhong.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/transpose.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/unpackDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/unpackFloat.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/unpackUint.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/valueTransform.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/vertexLogDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/writeDepthClamp.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/writeLogDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/Functions/writeNonPerspective.js", "../../node_modules/@cesium/engine/Source/Shaders/Builtin/CzmBuiltins.js", "../../node_modules/@cesium/engine/Source/Renderer/demodernizeShader.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderSource.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderCache.js", "../../node_modules/@cesium/engine/Source/Renderer/Texture.js", "../../node_modules/@cesium/engine/Source/Renderer/TextureCache.js", "../../node_modules/@cesium/engine/Source/Core/EncodedCartesian3.js", "../../node_modules/@cesium/engine/Source/Core/Plane.js", "../../node_modules/@cesium/engine/Source/Core/CullingVolume.js", "../../node_modules/@cesium/engine/Source/Core/OrthographicOffCenterFrustum.js", "../../node_modules/@cesium/engine/Source/Core/OrthographicFrustum.js", "../../node_modules/@cesium/engine/Source/Core/Simon1994PlanetaryPositions.js", "../../node_modules/@cesium/engine/Source/Scene/SceneMode.js", "../../node_modules/@cesium/engine/Source/Scene/SunLight.js", "../../node_modules/@cesium/engine/Source/Renderer/UniformState.js", "../../node_modules/@cesium/engine/Source/Renderer/VertexArray.js", "../../node_modules/@cesium/engine/Source/Renderer/Context.js", "../../node_modules/@cesium/engine/Source/Renderer/MultisampleFramebuffer.js", "../../node_modules/@cesium/engine/Source/Renderer/RenderbufferFormat.js", "../../node_modules/@cesium/engine/Source/Renderer/Renderbuffer.js", "../../node_modules/@cesium/engine/Source/Renderer/FramebufferManager.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderDestination.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderStruct.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderFunction.js", "../../node_modules/@cesium/engine/Source/Renderer/ShaderBuilder.js", "../../node_modules/@cesium/engine/Source/Renderer/VertexArrayFacade.js", "../../node_modules/@cesium/engine/Source/Renderer/loadCubeMap.js", "../../node_modules/@cesium/engine/Source/DataSources/ConstantProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/createPropertyDescriptor.js", "../../node_modules/@cesium/engine/Source/DataSources/BillboardGraphics.js", "../../node_modules/@cesium/engine/Source/Core/AssociativeArray.js", "../../node_modules/@cesium/engine/Source/Core/DistanceDisplayCondition.js", "../../node_modules/@cesium/engine/Source/Core/NearFarScalar.js", "../../node_modules/@cesium/engine/Source/Scene/HeightReference.js", "../../node_modules/@cesium/engine/Source/Scene/HorizontalOrigin.js", "../../node_modules/@cesium/engine/Source/Scene/VerticalOrigin.js", "../../node_modules/@cesium/engine/Source/DataSources/BoundingSphereState.js", "../../node_modules/@cesium/engine/Source/DataSources/Property.js", "../../node_modules/@cesium/engine/Source/DataSources/BillboardVisualizer.js", "../../node_modules/@cesium/engine/Source/Core/Interval.js", "../../node_modules/@cesium/engine/Source/Core/BoundingSphere.js", "../../node_modules/@cesium/engine/Source/Core/GeometryAttributes.js", "../../node_modules/@cesium/engine/Source/Core/GeometryOffsetAttribute.js", "../../node_modules/@cesium/engine/Source/Core/VertexFormat.js", "../../node_modules/@cesium/engine/Source/Core/BoxGeometry.js", "../../node_modules/@cesium/engine/Source/Core/BoxOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Core/ColorGeometryInstanceAttribute.js", "../../node_modules/@cesium/engine/Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js", "../../node_modules/@cesium/engine/Source/Core/GeometryInstance.js", "../../node_modules/@cesium/engine/Source/Core/TimeInterval.js", "../../node_modules/@cesium/engine/Source/Core/Iso8601.js", "../../node_modules/@cesium/engine/Source/Core/OffsetGeometryInstanceAttribute.js", "../../node_modules/@cesium/engine/Source/Core/ShowGeometryInstanceAttribute.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/AllMaterialAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/AllMaterialAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/BasicMaterialAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/BasicMaterialAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/TexturedMaterialAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Scene/BlendEquation.js", "../../node_modules/@cesium/engine/Source/Scene/BlendFunction.js", "../../node_modules/@cesium/engine/Source/Scene/BlendingState.js", "../../node_modules/@cesium/engine/Source/Scene/CullFace.js", "../../node_modules/@cesium/engine/Source/Scene/Appearance.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/AspectRampMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/BumpMapMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/CheckerboardMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/DotMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/ElevationBandMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/ElevationContourMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/ElevationRampMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/FadeMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/GridMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/NormalMapMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/PolylineArrowMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/PolylineDashMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/PolylineGlowMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/PolylineOutlineMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/RimLightingMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/SlopeRampMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/StripeMaterial.js", "../../node_modules/@cesium/engine/Source/Shaders/Materials/Water.js", "../../node_modules/@cesium/engine/Source/Scene/Material.js", "../../node_modules/@cesium/engine/Source/Scene/MaterialAppearance.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PerInstanceColorAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PerInstanceFlatColorAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Scene/PerInstanceColorAppearance.js", "../../node_modules/@cesium/engine/Source/DataSources/ColorMaterialProperty.js", "../../node_modules/@cesium/engine/Source/Core/GeographicTilingScheme.js", "../../node_modules/@cesium/engine/Source/Core/ApproximateTerrainHeights.js", "../../node_modules/@cesium/engine/Source/Core/AxisAlignedBoundingBox.js", "../../node_modules/@cesium/engine/Source/Core/QuadraticRealPolynomial.js", "../../node_modules/@cesium/engine/Source/Core/CubicRealPolynomial.js", "../../node_modules/@cesium/engine/Source/Core/QuarticRealPolynomial.js", "../../node_modules/@cesium/engine/Source/Core/Ray.js", "../../node_modules/@cesium/engine/Source/Core/IntersectionTests.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidTangentPlane.js", "../../node_modules/@cesium/engine/Source/Core/OrientedBoundingBox.js", "../../node_modules/@cesium/engine/Source/Core/TerrainExaggeration.js", "../../node_modules/@cesium/engine/Source/Shaders/ShadowVolumeAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/ShadowVolumeFS.js", "../../node_modules/@cesium/engine/Source/Scene/ClassificationType.js", "../../node_modules/@cesium/engine/Source/Scene/DepthFunction.js", "../../node_modules/@cesium/engine/Source/Core/subdivideArray.js", "../../node_modules/@cesium/engine/Source/Scene/BatchTable.js", "../../node_modules/@cesium/engine/Source/Scene/AttributeType.js", "../../node_modules/@cesium/engine/Source/Core/AttributeCompression.js", "../../node_modules/@cesium/engine/Source/Core/barycentricCoordinates.js", "../../node_modules/@cesium/engine/Source/Core/Tipsify.js", "../../node_modules/@cesium/engine/Source/Core/GeometryPipeline.js", "../../node_modules/@cesium/engine/Source/Core/WebMercatorProjection.js", "../../node_modules/@cesium/engine/Source/Scene/PrimitivePipeline.js", "../../node_modules/@cesium/engine/Source/Scene/PrimitiveState.js", "../../node_modules/@cesium/engine/Source/Scene/ShadowMode.js", "../../node_modules/@cesium/engine/Source/Scene/Primitive.js", "../../node_modules/@cesium/engine/Source/Core/GeometryInstanceAttribute.js", "../../node_modules/@cesium/engine/Source/Shaders/ShadowVolumeAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Scene/ShadowVolumeAppearance.js", "../../node_modules/@cesium/engine/Source/Scene/StencilFunction.js", "../../node_modules/@cesium/engine/Source/Scene/StencilOperation.js", "../../node_modules/@cesium/engine/Source/Scene/StencilConstants.js", "../../node_modules/@cesium/engine/Source/Scene/ClassificationPrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/GroundPrimitive.js", "../../node_modules/@cesium/engine/Source/DataSources/MaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/DynamicGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/ArcType.js", "../../node_modules/@cesium/engine/Source/Core/arrayRemoveDuplicates.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidGeodesic.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidRhumbLine.js", "../../node_modules/@cesium/engine/Source/Core/GroundPolylineGeometry.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineShadowVolumeFS.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineShadowVolumeMorphFS.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineShadowVolumeMorphVS.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineShadowVolumeVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PolylineColorAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineCommon.js", "../../node_modules/@cesium/engine/Source/Scene/PolylineColorAppearance.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/PolylineMaterialAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineFS.js", "../../node_modules/@cesium/engine/Source/Scene/PolylineMaterialAppearance.js", "../../node_modules/@cesium/engine/Source/Scene/GroundPolylinePrimitive.js", "../../node_modules/@cesium/engine/Source/DataSources/ImageMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/createMaterialPropertyDescriptor.js", "../../node_modules/@cesium/engine/Source/DataSources/BoxGraphics.js", "../../node_modules/@cesium/engine/Source/Core/ReferenceFrame.js", "../../node_modules/@cesium/engine/Source/DataSources/PositionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/ConstantPositionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/CorridorGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/createRawPropertyDescriptor.js", "../../node_modules/@cesium/engine/Source/DataSources/CylinderGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/EllipseGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/EllipsoidGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/LabelGraphics.js", "../../node_modules/@cesium/engine/Source/Core/TranslationRotationScale.js", "../../node_modules/@cesium/engine/Source/DataSources/NodeTransformationProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PropertyBag.js", "../../node_modules/@cesium/engine/Source/DataSources/ModelGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/Cesium3DTilesetGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/PathGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/PlaneGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/PointGraphics.js", "../../node_modules/@cesium/engine/Source/Core/PolygonHierarchy.js", "../../node_modules/@cesium/engine/Source/DataSources/PolygonGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineVolumeGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/RectangleGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/WallGraphics.js", "../../node_modules/@cesium/engine/Source/DataSources/Entity.js", "../../node_modules/@cesium/engine/Source/DataSources/GeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/CallbackProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/TerrainOffsetProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/heightReferenceOnEntityPropertyChanged.js", "../../node_modules/@cesium/engine/Source/DataSources/BoxGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/Credit.js", "../../node_modules/@cesium/engine/Source/Shaders/OctahedralProjectionAtlasFS.js", "../../node_modules/@cesium/engine/Source/Shaders/OctahedralProjectionFS.js", "../../node_modules/@cesium/engine/Source/Shaders/OctahedralProjectionVS.js", "../../node_modules/@cesium/engine/Source/Scene/OctahedralProjectedCubeMap.js", "../../node_modules/@cesium/engine/Source/Scene/ImageBasedLighting.js", "../../node_modules/@cesium/engine/Source/Core/IonResource.js", "../../node_modules/@cesium/engine/Source/Core/Ion.js", "../../node_modules/@cesium/engine/Source/Core/ManagedArray.js", "../../node_modules/@cesium/engine/Source/Scene/Axis.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DContentGroup.js", "../../node_modules/@cesium/engine/Source/Core/getStringFromTypedArray.js", "../../node_modules/@cesium/engine/Source/Core/getMagic.js", "../../node_modules/@cesium/engine/Source/Scene/Composite3DTileContent.js", "../../node_modules/@cesium/engine/Source/Core/getJsonFromTypedArray.js", "../../node_modules/@cesium/engine/Source/Scene/BatchTexture.js", "../../node_modules/@cesium/engine/Source/Scene/getBinaryAccessor.js", "../../node_modules/@cesium/engine/Source/Scene/BatchTableHierarchy.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileColorBlendMode.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileBatchTable.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTileBatch.js", "../../node_modules/@cesium/engine/Source/Shaders/VectorTileVS.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileFeature.js", "../../node_modules/jsep/dist/jsep.js", "../../node_modules/@cesium/engine/Source/Scene/ExpressionNodeType.js", "../../node_modules/@cesium/engine/Source/Scene/Expression.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTilePrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTileGeometry.js", "../../node_modules/@cesium/engine/Source/Scene/Geometry3DTileContent.js", "../../node_modules/@cesium/engine/Source/Core/HilbertOrder.js", "../../node_modules/@cesium/engine/Source/Core/S2Cell.js", "../../node_modules/@cesium/engine/Source/Scene/hasExtension.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitAvailabilityBitstream.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitMetadataView.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitSubdivisionScheme.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataEntity.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitSubtreeMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataComponentType.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataType.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataClassProperty.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataTableProperty.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataTable.js", "../../node_modules/@cesium/engine/Source/Scene/ResourceLoader.js", "../../node_modules/@cesium/engine/Source/Scene/ResourceLoaderState.js", "../../node_modules/@cesium/engine/Source/Scene/BufferLoader.js", "../../node_modules/meshoptimizer/meshopt_encoder.module.js", "../../node_modules/meshoptimizer/meshopt_decoder.module.js", "../../node_modules/meshoptimizer/meshopt_simplifier.module.js", "../../node_modules/@cesium/engine/Source/Scene/GltfBufferViewLoader.js", "../../node_modules/@cesium/engine/Source/Scene/DracoLoader.js", "../../node_modules/@cesium/engine/Source/Scene/GltfDracoLoader.js", "../../node_modules/@cesium/engine/Source/Core/loadImageFromTypedArray.js", "../../node_modules/@cesium/engine/Source/Scene/GltfImageLoader.js", "../../node_modules/@cesium/engine/Source/Scene/JobType.js", "../../node_modules/@cesium/engine/Source/Scene/GltfIndexBufferLoader.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addToArray.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/usesExtension.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/ForEach.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/numberOfComponentsForType.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/getAccessorByteStride.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addDefaults.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addPipelineExtras.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/removeExtensionsRequired.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/removeExtensionsUsed.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/parseGlb.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/removePipelineExtras.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addExtensionsUsed.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/getComponentReader.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/findAccessorMinMax.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/moveTechniqueRenderStates.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addExtensionsRequired.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/moveTechniquesToExtension.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/forEachTextureInMaterial.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/removeUnusedElements.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/addBuffer.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/readAccessorPacked.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/updateAccessorComponentTypes.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/removeExtension.js", "../../node_modules/@cesium/engine/Source/Scene/GltfPipeline/updateVersion.js", "../../node_modules/@cesium/engine/Source/Scene/VertexAttributeSemantic.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelUtility.js", "../../node_modules/@cesium/engine/Source/Scene/GltfJsonLoader.js", "../../node_modules/@cesium/engine/Source/Scene/AlphaMode.js", "../../node_modules/@cesium/engine/Source/Scene/ModelComponents.js", "../../node_modules/@cesium/engine/Source/Scene/GltfLoaderUtil.js", "../../node_modules/@cesium/engine/Source/Core/resizeImageToNextPowerOfTwo.js", "../../node_modules/@cesium/engine/Source/Scene/GltfTextureLoader.js", "../../node_modules/@cesium/engine/Source/Scene/GltfVertexBufferLoader.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataClass.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataEnumValue.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataEnum.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataSchema.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataSchemaLoader.js", "../../node_modules/@cesium/engine/Source/Scene/ResourceCacheKey.js", "../../node_modules/@cesium/engine/Source/Scene/ResourceCacheStatistics.js", "../../node_modules/@cesium/engine/Source/Scene/ResourceCache.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitSubtree.js", "../../node_modules/@cesium/engine/Source/Scene/MetadataSemantic.js", "../../node_modules/@cesium/engine/Source/Scene/BoundingVolumeSemantics.js", "../../node_modules/@cesium/engine/Source/Scene/Implicit3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/ModelAnimationLoop.js", "../../node_modules/@cesium/engine/Source/Scene/ClippingPlane.js", "../../node_modules/@cesium/engine/Source/Scene/ClippingPlaneCollection.js", "../../node_modules/@cesium/engine/Source/Scene/ColorBlendMode.js", "../../node_modules/@cesium/engine/Source/Core/ArticulationStageType.js", "../../node_modules/@cesium/engine/Source/Core/InterpolationType.js", "../../node_modules/@cesium/engine/Source/Scene/JsonMetadataTable.js", "../../node_modules/@cesium/engine/Source/Scene/PropertyTable.js", "../../node_modules/@cesium/engine/Source/Scene/PropertyTextureProperty.js", "../../node_modules/@cesium/engine/Source/Scene/PropertyTexture.js", "../../node_modules/@cesium/engine/Source/Scene/PropertyAttributeProperty.js", "../../node_modules/@cesium/engine/Source/Scene/PropertyAttribute.js", "../../node_modules/@cesium/engine/Source/Scene/StructuralMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/parseStructuralMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/parseFeatureMetadataLegacy.js", "../../node_modules/@cesium/engine/Source/Scene/GltfStructuralMetadataLoader.js", "../../node_modules/@cesium/engine/Source/Scene/InstanceAttributeSemantic.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PrimitiveOutlineGenerator.js", "../../node_modules/@cesium/engine/Source/Scene/PrimitiveLoadPlan.js", "../../node_modules/@cesium/engine/Source/Scene/SupportedImageFormats.js", "../../node_modules/@cesium/engine/Source/Scene/GltfLoader.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.js", "../../node_modules/@cesium/engine/Source/Scene/PointCloudEyeDomeLighting.js", "../../node_modules/@cesium/engine/Source/Scene/PointCloudShading.js", "../../node_modules/@cesium/engine/Source/Scene/SceneTransforms.js", "../../node_modules/@cesium/engine/Source/Scene/SplitDirection.js", "../../node_modules/@cesium/engine/Source/Scene/B3dmParser.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileFeatureTable.js", "../../node_modules/@cesium/engine/Source/Scene/parseBatchTable.js", "../../node_modules/@cesium/engine/Source/Scene/Model/B3dmLoader.js", "../../node_modules/@cesium/engine/Source/Scene/Model/GeoJsonLoader.js", "../../node_modules/@cesium/engine/Source/Scene/I3dmParser.js", "../../node_modules/@cesium/engine/Source/Scene/Model/I3dmLoader.js", "../../node_modules/@cesium/engine/Source/Scene/ModelAnimationState.js", "../../node_modules/@cesium/engine/Source/Core/Spline.js", "../../node_modules/@cesium/engine/Source/Core/ConstantSpline.js", "../../node_modules/@cesium/engine/Source/Core/LinearSpline.js", "../../node_modules/@cesium/engine/Source/Core/TridiagonalSystemSolver.js", "../../node_modules/@cesium/engine/Source/Core/HermiteSpline.js", "../../node_modules/@cesium/engine/Source/Core/SteppedSpline.js", "../../node_modules/@cesium/engine/Source/Core/QuaternionSpline.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelAnimationChannel.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelAnimation.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelAnimationCollection.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelFeature.js", "../../node_modules/@cesium/engine/Source/Scene/Model/StyleCommandsNeeded.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelType.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelFeatureTable.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ClassificationModelDrawCommand.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelDrawCommand.js", "../../node_modules/@cesium/engine/Source/Scene/Model/buildDrawCommand.js", "../../node_modules/@cesium/engine/Source/Scene/Model/TilesetPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ImageBasedLightingStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ImageBasedLightingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelArticulationStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelArticulation.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelColorStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelColorPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelClippingPlanesStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelClippingPlanesPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelNode.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/InstancingStageCommon.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/InstancingStageVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/LegacyInstancingStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/InstancingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelMatrixUpdateStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/NodeStatisticsPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelRuntimeNode.js", "../../node_modules/@cesium/engine/Source/Scene/Model/AlphaPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/BatchTexturePipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ClassificationPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/CPUStylingStageVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/CPUStylingStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/CPUStylingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/CustomShaderMode.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/CustomShaderStageVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/CustomShaderStageFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/FeatureIdStageFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/FeatureIdStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/FeatureIdPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/MetadataStageFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/MetadataStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/MetadataPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/CustomShaderTranslucencyMode.js", "../../node_modules/@cesium/engine/Source/Scene/Model/CustomShaderPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/DequantizationPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/GeometryStageFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/GeometryStageVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/SelectedFeatureIdStageCommon.js", "../../node_modules/@cesium/engine/Source/Scene/Model/SelectedFeatureIdPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/GeometryPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/LightingStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/LightingModel.js", "../../node_modules/@cesium/engine/Source/Scene/Model/LightingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/MaterialStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/MaterialPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/MorphTargetsStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/MorphTargetsPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PickingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileRefine.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/PointCloudStylingStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/PrimitiveOutlineStageVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/PrimitiveOutlineStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PrimitiveOutlinePipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PrimitiveStatisticsPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/SceneMode2DPipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/SkinningStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/SkinningPipelineStage.js", "../../node_modules/@cesium/engine/Source/Core/WireframeIndexGenerator.js", "../../node_modules/@cesium/engine/Source/Scene/Model/WireframePipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelRuntimePrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelSkin.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelAlphaOptions.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelRenderResources.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelSilhouetteStageFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelSilhouetteStageVS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelSilhouettePipelineStage.js", "../../node_modules/@cesium/engine/Source/Shaders/Model/ModelSplitterStageFS.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelSplitterPipelineStage.js", "../../node_modules/@cesium/engine/Source/Scene/Model/NodeRenderResources.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelLightingOptions.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PrimitiveRenderResources.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelSceneGraph.js", "../../node_modules/@cesium/engine/Source/Scene/Model/ModelStatistics.js", "../../node_modules/@cesium/engine/Source/Scene/Model/PntsLoader.js", "../../node_modules/@cesium/engine/Source/Scene/PntsParser.js", "../../node_modules/@cesium/engine/Source/Scene/Model/Model.js", "../../node_modules/@cesium/engine/Source/Scene/Model/Model3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/Tileset3DTileContent.js", "../../node_modules/@cesium/engine/Source/Shaders/BillboardCollectionFS.js", "../../node_modules/@cesium/engine/Source/Shaders/BillboardCollectionVS.js", "../../node_modules/@cesium/engine/Source/Scene/Billboard.js", "../../node_modules/@cesium/engine/Source/Scene/BlendOption.js", "../../node_modules/@cesium/engine/Source/Scene/SDFSettings.js", "../../node_modules/@cesium/engine/Source/Scene/TextureAtlas.js", "../../node_modules/@cesium/engine/Source/Scene/BillboardCollection.js", "../../node_modules/@cesium/engine/Source/Scene/createBillboardPointCallback.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilePointFeature.js", "../../node_modules/@cesium/engine/Source/Core/writeTextToCanvas.js", "../../node_modules/@cesium/engine/Source/Scene/LabelCollection.js", "../../node_modules/@cesium/engine/Source/Scene/LabelStyle.js", "../../node_modules/@cesium/engine/Source/Scene/Label.js", "../../node_modules/@cesium/engine/Source/Shaders/PolylineVS.js", "../../node_modules/@cesium/engine/Source/Core/PolylinePipeline.js", "../../node_modules/@cesium/engine/Source/Scene/Polyline.js", "../../node_modules/@cesium/engine/Source/Scene/PolylineCollection.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTilePoints.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTilePolygons.js", "../../node_modules/@cesium/engine/Source/Shaders/Vector3DTilePolylinesVS.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTilePolylines.js", "../../node_modules/@cesium/engine/Source/Shaders/Vector3DTileClampedPolylinesVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Vector3DTileClampedPolylinesFS.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTileClampedPolylines.js", "../../node_modules/@cesium/engine/Source/Core/decodeVectorPolylinePositions.js", "../../node_modules/@cesium/engine/Source/Scene/Vector3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileContentFactory.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileContentState.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileContentType.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileOptimizationHint.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilePass.js", "../../node_modules/@cesium/engine/Source/Scene/Empty3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/ContentMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/findContentMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/findGroupMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/TileMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/findTileMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/preprocess3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/Multiple3DTileContent.js", "../../node_modules/@cesium/engine/Source/Core/PolygonPipeline.js", "../../node_modules/@cesium/engine/Source/Core/RectangleGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/RectangleOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Scene/TileBoundingRegion.js", "../../node_modules/@cesium/engine/Source/Core/CoplanarPolygonGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/Queue.js", "../../node_modules/@cesium/engine/Source/Core/PolygonGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/CoplanarPolygonOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Scene/TileBoundingS2Cell.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Core/SphereOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Scene/TileBoundingSphere.js", "../../node_modules/@cesium/engine/Source/Scene/TileOrientedBoundingBox.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTile.js", "../../node_modules/@cesium/engine/Source/Scene/GroupMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/TilesetMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetMetadata.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileOptimizations.js", "../../node_modules/@cesium/engine/Source/Core/DoublyLinkedList.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetCache.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetHeatmap.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetStatistics.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileStyleEngine.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitTileset.js", "../../node_modules/@cesium/engine/Source/Core/MortonOrder.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitTileCoordinates.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetTraversal.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetMostDetailedTraversal.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetBaseTraversal.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesetSkipTraversal.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileset.js", "../../node_modules/@cesium/engine/Source/DataSources/Cesium3DTilesetVisualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/CheckerboardMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/EntityCollection.js", "../../node_modules/@cesium/engine/Source/DataSources/CompositeEntityCollection.js", "../../node_modules/@cesium/engine/Source/Core/EventHelper.js", "../../node_modules/@cesium/engine/Source/Core/TimeIntervalCollection.js", "../../node_modules/@cesium/engine/Source/DataSources/CompositeProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/CompositeMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/CompositePositionProperty.js", "../../node_modules/@cesium/engine/Source/Core/CornerType.js", "../../node_modules/@cesium/engine/Source/Core/PolylineVolumeGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/CorridorGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/CorridorGeometry.js", "../../node_modules/@cesium/engine/Source/Core/CorridorOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/GroundGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/CorridorGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/DataSource.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidalOccluder.js", "../../node_modules/@cesium/engine/Source/Scene/PointPrimitive.js", "../../node_modules/@cesium/engine/Source/Shaders/PointPrimitiveCollectionFS.js", "../../node_modules/@cesium/engine/Source/Shaders/PointPrimitiveCollectionVS.js", "../../node_modules/@cesium/engine/Source/Scene/PointPrimitiveCollection.js", "../../node_modules/kdbush/index.js", "../../node_modules/@cesium/engine/Source/DataSources/EntityCluster.js", "../../node_modules/@cesium/engine/Source/DataSources/CustomDataSource.js", "../../node_modules/@cesium/engine/Source/Core/CylinderGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/CylinderGeometry.js", "../../node_modules/@cesium/engine/Source/Core/CylinderOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/CylinderGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/ClockRange.js", "../../node_modules/@cesium/engine/Source/Core/ClockStep.js", "../../node_modules/@cesium/engine/Source/Core/ExtrapolationType.js", "../../node_modules/@cesium/engine/Source/Core/getFilenameFromUri.js", "../../node_modules/@cesium/engine/Source/Core/HermitePolynomialApproximation.js", "../../node_modules/@cesium/engine/Source/Core/LagrangePolynomialApproximation.js", "../../node_modules/@cesium/engine/Source/Core/LinearApproximation.js", "../../node_modules/@cesium/engine/Source/Core/Spherical.js", "../../node_modules/@cesium/engine/Source/DataSources/CzmlDataSource.js", "../../node_modules/@cesium/engine/Source/Core/getTimestamp.js", "../../node_modules/@cesium/engine/Source/Core/Clock.js", "../../node_modules/@cesium/engine/Source/DataSources/DataSourceClock.js", "../../node_modules/@cesium/engine/Source/DataSources/GridMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineArrowMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineDashMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineGlowMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineOutlineMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PositionPropertyArray.js", "../../node_modules/@cesium/engine/Source/DataSources/PropertyArray.js", "../../node_modules/@cesium/engine/Source/DataSources/ReferenceProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/Rotation.js", "../../node_modules/@cesium/engine/Source/DataSources/SampledProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/SampledPositionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/StripeOrientation.js", "../../node_modules/@cesium/engine/Source/DataSources/StripeMaterialProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/TimeIntervalCollectionPositionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/TimeIntervalCollectionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/VelocityVectorProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/VelocityOrientationProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/DataSourceCollection.js", "../../node_modules/@cesium/engine/Source/Scene/PrimitiveCollection.js", "../../node_modules/@cesium/engine/Source/Scene/OrderedGroundPrimitiveCollection.js", "../../node_modules/@cesium/engine/Source/DataSources/DynamicGeometryBatch.js", "../../node_modules/@cesium/engine/Source/Core/EllipseGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/EllipseGeometry.js", "../../node_modules/@cesium/engine/Source/Core/EllipseOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/EllipseGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/EllipsoidGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/PlaneGeometry.js", "../../node_modules/@cesium/engine/Source/Core/PlaneOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/PlaneGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/CoplanarPolygonGeometry.js", "../../node_modules/@cesium/engine/Source/Core/PolygonGeometry.js", "../../node_modules/@cesium/engine/Source/Core/PolygonOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/PolygonGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/PolylineVolumeGeometry.js", "../../node_modules/@cesium/engine/Source/Core/PolylineVolumeOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineVolumeGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/Core/RectangleGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/RectangleGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticGeometryColorBatch.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticGeometryPerMaterialBatch.js", "../../node_modules/@cesium/engine/Source/Core/RectangleCollisionChecker.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticGroundGeometryColorBatch.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticOutlineGeometryBatch.js", "../../node_modules/@cesium/engine/Source/Core/WallGeometryLibrary.js", "../../node_modules/@cesium/engine/Source/Core/WallGeometry.js", "../../node_modules/@cesium/engine/Source/Core/WallOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/WallGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/GeometryVisualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/LabelVisualizer.js", "../../node_modules/@cesium/engine/Source/Core/sampleTerrain.js", "../../node_modules/@cesium/engine/Source/Core/sampleTerrainMostDetailed.js", "../../node_modules/@cesium/engine/Source/DataSources/ModelVisualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/ScaledPositionProperty.js", "../../node_modules/@cesium/engine/Source/DataSources/PathVisualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/PointVisualizer.js", "../../node_modules/@cesium/engine/Source/Core/PolylineGeometry.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineGeometryUpdater.js", "../../node_modules/@cesium/engine/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js", "../../node_modules/@cesium/engine/Source/DataSources/PolylineVisualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/DataSourceDisplay.js", "../../node_modules/@cesium/engine/Source/Core/HeadingPitchRange.js", "../../node_modules/@cesium/engine/Source/DataSources/EntityView.js", "../../node_modules/@cesium/engine/Source/Core/PinBuilder.js", "../../node_modules/topojson-client/src/identity.js", "../../node_modules/topojson-client/src/transform.js", "../../node_modules/topojson-client/src/reverse.js", "../../node_modules/topojson-client/src/feature.js", "../../node_modules/@cesium/engine/Source/DataSources/GeoJsonDataSource.js", "../../node_modules/autolinker/src/version.ts", "../../node_modules/autolinker/src/utils.ts", "../../node_modules/autolinker/src/regex-lib.ts", "../../node_modules/autolinker/src/html-tag.ts", "../../node_modules/autolinker/src/truncate/truncate-smart.ts", "../../node_modules/autolinker/src/truncate/truncate-middle.ts", "../../node_modules/autolinker/src/truncate/truncate-end.ts", "../../node_modules/autolinker/src/anchor-tag-builder.ts", "../../node_modules/tslib/tslib.es6.mjs", "../../node_modules/autolinker/src/match/abstract-match.ts", "../../node_modules/autolinker/src/parser/tld-regex.ts", "../../node_modules/autolinker/src/parser/uri-utils.ts", "../../node_modules/autolinker/src/match/url-match.ts", "../../node_modules/autolinker/src/parser/email-utils.ts", "../../node_modules/autolinker/src/match/email-match.ts", "../../node_modules/autolinker/src/parser/hashtag-utils.ts", "../../node_modules/autolinker/src/match/hashtag-match.ts", "../../node_modules/autolinker/src/parser/mention-utils.ts", "../../node_modules/autolinker/src/match/mention-match.ts", "../../node_modules/autolinker/src/parser/phone-number-utils.ts", "../../node_modules/autolinker/src/match/phone-match.ts", "../../node_modules/autolinker/src/parser/parse-matches.ts", "../../node_modules/autolinker/src/htmlParser/parse-html.ts", "../../node_modules/autolinker/src/autolinker.ts", "../../node_modules/autolinker/src/index.ts", "../../node_modules/@cesium/engine/Source/DataSources/GpxDataSource.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlCamera.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlDataSource.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/deflate.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/inflate.js", "../../node_modules/@zip.js/zip.js/lib/core/configuration.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/crc32.js", "../../node_modules/@zip.js/zip.js/lib/core/util/encode-text.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/sjcl.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/aes-crypto.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/zip-crypto.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/codec.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/codec-pool-worker.js", "../../node_modules/@zip.js/zip.js/lib/core/codecs/codec-pool.js", "../../node_modules/@zip.js/zip.js/lib/core/engine.js", "../../node_modules/@zip.js/zip.js/lib/core/io.js", "../../node_modules/@zip.js/zip.js/lib/core/constants.js", "../../node_modules/@zip.js/zip.js/lib/core/util/cp437-decode.js", "../../node_modules/@zip.js/zip.js/lib/core/util/decode-text.js", "../../node_modules/@zip.js/zip.js/lib/core/zip-entry.js", "../../node_modules/@zip.js/zip.js/lib/core/zip-reader.js", "../../node_modules/@zip.js/zip.js/lib/core/zip-writer.js", "../../node_modules/@zip.js/zip.js/lib/zip-no-worker.js", "../../node_modules/@cesium/engine/Source/DataSources/getElement.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlLookAt.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlTour.js", "../../node_modules/@tweenjs/tween.js/dist/tween.esm.js", "../../node_modules/@cesium/engine/Source/Core/EasingFunction.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlTourFlyTo.js", "../../node_modules/@cesium/engine/Source/DataSources/KmlTourWait.js", "../../node_modules/@cesium/engine/Source/DataSources/Visualizer.js", "../../node_modules/@cesium/engine/Source/DataSources/exportKml.js", "../../node_modules/@cesium/engine/Source/Core/HeightmapEncoding.js", "../../node_modules/@cesium/engine/Source/Core/TerrainQuantization.js", "../../node_modules/@cesium/engine/Source/Core/TerrainEncoding.js", "../../node_modules/@cesium/engine/Source/Core/HeightmapTessellator.js", "../../node_modules/@cesium/engine/Source/Core/TerrainData.js", "../../node_modules/@cesium/engine/Source/Core/TerrainMesh.js", "../../node_modules/@cesium/engine/Source/Core/TerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/HeightmapTerrainData.js", "../../node_modules/@cesium/engine/Source/Core/TileAvailability.js", "../../node_modules/@cesium/engine/Source/Core/formatError.js", "../../node_modules/@cesium/engine/Source/Core/TileProviderError.js", "../../node_modules/@cesium/engine/Source/Core/WebMercatorTilingScheme.js", "../../node_modules/@cesium/engine/Source/Core/ArcGISTiledElevationTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/BingMapsGeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/CartographicGeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/CatmullRomSpline.js", "../../node_modules/@cesium/engine/Source/Core/Intersections2D.js", "../../node_modules/@cesium/engine/Source/Core/QuantizedMeshTerrainData.js", "../../node_modules/@cesium/engine/Source/Core/CesiumTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/CircleGeometry.js", "../../node_modules/@cesium/engine/Source/Core/CircleOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Core/CustomHeightmapTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/DefaultProxy.js", "../../node_modules/@cesium/engine/Source/Core/DoubleEndedPriorityQueue.js", "../../node_modules/@cesium/engine/Source/Core/EllipsoidTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/PerspectiveOffCenterFrustum.js", "../../node_modules/@cesium/engine/Source/Core/PerspectiveFrustum.js", "../../node_modules/@cesium/engine/Source/Core/FrustumGeometry.js", "../../node_modules/@cesium/engine/Source/Core/FrustumOutlineGeometry.js", "../../node_modules/@cesium/engine/Source/Core/GeocodeType.js", "../../node_modules/@cesium/engine/Source/Core/GeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/GeometryFactory.js", "../../node_modules/@cesium/engine/Source/Core/GoogleEarthEnterpriseMetadata.js", "../../node_modules/@cesium/engine/Source/Core/isBitSet.js", "../../node_modules/@cesium/engine/Source/Core/GoogleEarthEnterpriseTileInformation.js", "../../node_modules/@cesium/engine/Source/Core/GoogleEarthEnterpriseTerrainData.js", "../../node_modules/@cesium/engine/Source/Core/GoogleEarthEnterpriseTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/GoogleMaps.js", "../../node_modules/@cesium/engine/Source/Core/IauOrientationParameters.js", "../../node_modules/@cesium/engine/Source/Core/Iau2000Orientation.js", "../../node_modules/@cesium/engine/Source/Core/IauOrientationAxes.js", "../../node_modules/@cesium/engine/Source/Core/InterpolationAlgorithm.js", "../../node_modules/@cesium/engine/Source/Core/PeliasGeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/IonGeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/KeyboardEventModifier.js", "../../node_modules/@cesium/engine/Source/Core/MapProjection.js", "../../node_modules/@cesium/engine/Source/Core/MorphWeightSpline.js", "../../node_modules/@cesium/engine/Source/Core/Visibility.js", "../../node_modules/@cesium/engine/Source/Core/Occluder.js", "../../node_modules/@cesium/engine/Source/Core/OpenCageGeocoderService.js", "../../node_modules/@cesium/engine/Source/Core/Packable.js", "../../node_modules/@cesium/engine/Source/Core/PackableForInterpolation.js", "../../node_modules/@cesium/engine/Source/Core/Proxy.js", "../../node_modules/@cesium/engine/Source/Core/ScreenSpaceEventType.js", "../../node_modules/@cesium/engine/Source/Core/ScreenSpaceEventHandler.js", "../../node_modules/@cesium/engine/Source/Core/SimplePolylineGeometry.js", "../../node_modules/@cesium/engine/Source/Core/SphereGeometry.js", "../../node_modules/@cesium/engine/Source/Core/TileEdge.js", "../../node_modules/@cesium/engine/Source/Core/TilingScheme.js", "../../node_modules/@cesium/engine/Source/Core/VRTheWorldTerrainProvider.js", "../../node_modules/@cesium/engine/Source/Core/VideoSynchronizer.js", "../../node_modules/@cesium/engine/Source/Core/VulkanConstants.js", "../../node_modules/@cesium/engine/Source/Core/createWorldTerrainAsync.js", "../../node_modules/@cesium/engine/Source/Core/decodeGoogleEarthEnterpriseData.js", "../../node_modules/@cesium/engine/Source/Core/getImageFromTypedArray.js", "../../node_modules/@cesium/engine/Source/Core/mergeSort.js", "../../node_modules/@cesium/engine/Source/Core/pointInsideTriangle.js", "../../node_modules/@cesium/engine/Source/Core/webGLConstantToGlslType.js", "../../node_modules/@cesium/engine/Source/Core/wrapFunction.js", "../../node_modules/@cesium/engine/Source/Scene/ArcGisBaseMapType.js", "../../node_modules/@cesium/engine/Source/Scene/ArcGisMapService.js", "../../node_modules/@cesium/engine/Source/Scene/DiscardMissingTileImagePolicy.js", "../../node_modules/@cesium/engine/Source/Scene/ImageryLayerFeatureInfo.js", "../../node_modules/@cesium/engine/Source/Scene/ImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/ArcGisMapServerImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/AutoExposure.js", "../../node_modules/@cesium/engine/Source/Scene/BingMapsStyle.js", "../../node_modules/@cesium/engine/Source/Scene/DiscardEmptyTileImagePolicy.js", "../../node_modules/@cesium/engine/Source/Scene/BingMapsImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/BoxEmitter.js", "../../node_modules/@cesium/engine/Source/Shaders/BrdfLutGeneratorFS.js", "../../node_modules/@cesium/engine/Source/Scene/BrdfLutGenerator.js", "../../node_modules/@cesium/engine/Source/Scene/CameraFlightPath.js", "../../node_modules/@cesium/engine/Source/Scene/MapMode2D.js", "../../node_modules/@cesium/engine/Source/Scene/Camera.js", "../../node_modules/@cesium/engine/Source/Scene/CameraEventType.js", "../../node_modules/@cesium/engine/Source/Scene/CameraEventAggregator.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileContent.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilePassState.js", "../../node_modules/@cesium/engine/Source/Scene/ConditionsExpression.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTileStyle.js", "../../node_modules/@cesium/engine/Source/Scene/ImplicitSubtreeCache.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelBoxShape.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelContent.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelCylinderShape.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelEllipsoidShape.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelShapeType.js", "../../node_modules/@cesium/engine/Source/Scene/Cesium3DTilesVoxelProvider.js", "../../node_modules/@cesium/engine/Source/Scene/CircleEmitter.js", "../../node_modules/@cesium/engine/Source/Scene/CloudType.js", "../../node_modules/@cesium/engine/Source/Shaders/CloudCollectionFS.js", "../../node_modules/@cesium/engine/Source/Shaders/CloudCollectionVS.js", "../../node_modules/@cesium/engine/Source/Shaders/CloudNoiseFS.js", "../../node_modules/@cesium/engine/Source/Shaders/CloudNoiseVS.js", "../../node_modules/@cesium/engine/Source/Scene/CumulusCloud.js", "../../node_modules/@cesium/engine/Source/Scene/CloudCollection.js", "../../node_modules/@cesium/engine/Source/Scene/ConeEmitter.js", "../../node_modules/@cesium/engine/Source/Scene/CreditDisplay.js", "../../node_modules/@cesium/engine/Source/Scene/DebugAppearance.js", "../../node_modules/@cesium/engine/Source/Scene/DebugCameraPrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/DebugInspector.js", "../../node_modules/@cesium/engine/Source/Scene/DebugModelMatrixPrimitive.js", "../../node_modules/@cesium/engine/Source/Shaders/DepthPlaneFS.js", "../../node_modules/@cesium/engine/Source/Shaders/DepthPlaneVS.js", "../../node_modules/@cesium/engine/Source/Scene/DepthPlane.js", "../../node_modules/@cesium/engine/Source/Scene/DerivedCommand.js", "../../node_modules/@cesium/engine/Source/Scene/DeviceOrientationCameraController.js", "../../node_modules/@cesium/engine/Source/Scene/DirectionalLight.js", "../../node_modules/@cesium/engine/Source/Shaders/EllipsoidFS.js", "../../node_modules/@cesium/engine/Source/Shaders/EllipsoidVS.js", "../../node_modules/@cesium/engine/Source/Scene/EllipsoidPrimitive.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.js", "../../node_modules/@cesium/engine/Source/Scene/EllipsoidSurfaceAppearance.js", "../../node_modules/@cesium/engine/Source/Scene/Fog.js", "../../node_modules/@cesium/engine/Source/Scene/FrameRateMonitor.js", "../../node_modules/@cesium/engine/Source/Scene/FrameState.js", "../../node_modules/@cesium/engine/Source/Scene/FrustumCommands.js", "../../node_modules/@cesium/engine/Source/Scene/GetFeatureInfoFormat.js", "../../node_modules/@cesium/engine/Source/Shaders/GlobeFS.js", "../../node_modules/@cesium/engine/Source/Shaders/GlobeVS.js", "../../node_modules/@cesium/engine/Source/Shaders/AtmosphereCommon.js", "../../node_modules/@cesium/engine/Source/Shaders/GroundAtmosphere.js", "../../node_modules/@cesium/engine/Source/Scene/getClippingFunction.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeSurfaceShaderSet.js", "../../node_modules/@cesium/engine/Source/Scene/ImageryState.js", "../../node_modules/@cesium/engine/Source/Scene/QuadtreeTileLoadState.js", "../../node_modules/@cesium/engine/Source/Scene/TerrainState.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeSurfaceTile.js", "../../node_modules/@cesium/engine/Source/Scene/UrlTemplateImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/TileMapServiceImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/GoogleEarthEnterpriseMapsProvider.js", "../../node_modules/@cesium/engine/Source/Scene/MapboxImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/SingleTileImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/TimeDynamicImagery.js", "../../node_modules/@cesium/engine/Source/Scene/WebMapServiceImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/WebMapTileServiceImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/IonImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/IonWorldImageryStyle.js", "../../node_modules/@cesium/engine/Source/Scene/createWorldImageryAsync.js", "../../node_modules/@cesium/engine/Source/Shaders/ReprojectWebMercatorFS.js", "../../node_modules/@cesium/engine/Source/Shaders/ReprojectWebMercatorVS.js", "../../node_modules/@cesium/engine/Source/Scene/Imagery.js", "../../node_modules/@cesium/engine/Source/Scene/TileImagery.js", "../../node_modules/@cesium/engine/Source/Scene/ImageryLayer.js", "../../node_modules/@cesium/engine/Source/Scene/TileSelectionResult.js", "../../node_modules/@cesium/engine/Source/Scene/TerrainFillMesh.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeSurfaceTileProvider.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeTranslucency.js", "../../node_modules/@cesium/engine/Source/Scene/ImageryLayerCollection.js", "../../node_modules/@cesium/engine/Source/Scene/QuadtreeOccluders.js", "../../node_modules/@cesium/engine/Source/Scene/QuadtreeTile.js", "../../node_modules/@cesium/engine/Source/Scene/TileReplacementQueue.js", "../../node_modules/@cesium/engine/Source/Scene/QuadtreePrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/Globe.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/PassThrough.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/PassThroughDepth.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeDepth.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeTranslucencyFramebuffer.js", "../../node_modules/@cesium/engine/Source/Scene/GlobeTranslucencyState.js", "../../node_modules/@cesium/engine/Source/Scene/GoogleEarthEnterpriseImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/GridImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/I3SFeature.js", "../../node_modules/@cesium/engine/Source/Scene/I3SField.js", "../../node_modules/@cesium/engine/Source/Scene/I3SGeometry.js", "../../node_modules/@cesium/engine/Source/Scene/I3SNode.js", "../../node_modules/@cesium/engine/Source/Scene/I3SLayer.js", "../../node_modules/@cesium/engine/Source/Scene/I3SDataProvider.js", "../../node_modules/@cesium/engine/Source/Scene/InvertClassification.js", "../../node_modules/@cesium/engine/Source/Scene/JobScheduler.js", "../../node_modules/@cesium/engine/Source/Scene/KeyframeNode.js", "../../node_modules/@cesium/engine/Source/Scene/Light.js", "../../node_modules/@cesium/engine/Source/Scene/MapboxStyleImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/Megatexture.js", "../../node_modules/@cesium/engine/Source/Scene/Moon.js", "../../node_modules/@cesium/engine/Source/Scene/NeverTileDiscardPolicy.js", "../../node_modules/@cesium/engine/Source/Shaders/AdjustTranslucentFS.js", "../../node_modules/@cesium/engine/Source/Shaders/CompositeOITFS.js", "../../node_modules/@cesium/engine/Source/Scene/OIT.js", "../../node_modules/@cesium/engine/Source/Scene/OpenStreetMapImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/Particle.js", "../../node_modules/@cesium/engine/Source/Scene/ParticleBurst.js", "../../node_modules/@cesium/engine/Source/Scene/ParticleEmitter.js", "../../node_modules/@cesium/engine/Source/Scene/ParticleSystem.js", "../../node_modules/@cesium/engine/Source/Scene/PerformanceDisplay.js", "../../node_modules/@cesium/engine/Source/Scene/PickDepth.js", "../../node_modules/@cesium/engine/Source/Scene/PickDepthFramebuffer.js", "../../node_modules/@cesium/engine/Source/Scene/PickFramebuffer.js", "../../node_modules/@cesium/engine/Source/Scene/SceneFramebuffer.js", "../../node_modules/@cesium/engine/Source/Scene/ShadowMapShader.js", "../../node_modules/@cesium/engine/Source/Scene/ShadowMap.js", "../../node_modules/@cesium/engine/Source/Shaders/CompareAndPackTranslucentDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/CompositeTranslucentClassification.js", "../../node_modules/@cesium/engine/Source/Scene/TranslucentTileClassification.js", "../../node_modules/@cesium/engine/Source/Scene/View.js", "../../node_modules/@cesium/engine/Source/Scene/Picking.js", "../../node_modules/@cesium/engine/Source/Scene/PointCloud.js", "../../node_modules/@cesium/engine/Source/Scene/getClipAndStyleCode.js", "../../node_modules/@cesium/engine/Source/Scene/Splitter.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStageSampleMode.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStage.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/AcesTonemappingStage.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/BlackAndWhite.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/BloomComposite.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/Brightness.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/ContrastBias.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/DepthOfField.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/DepthView.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/EdgeDetection.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/FilmicTonemapping.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/FXAA.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/GaussianBlur1D.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/LensFlare.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/NightVision.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/ReinhardTonemapping.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/Silhouette.js", "../../node_modules/@cesium/engine/Source/Shaders/FXAA3_11.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStageComposite.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStageLibrary.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStageTextureCache.js", "../../node_modules/@cesium/engine/Source/Scene/Tonemapper.js", "../../node_modules/@cesium/engine/Source/Scene/PostProcessStageCollection.js", "../../node_modules/@cesium/engine/Source/Scene/QuadtreeTileProvider.js", "../../node_modules/@cesium/engine/Source/Scene/SceneTransitioner.js", "../../node_modules/@cesium/engine/Source/Scene/TweenCollection.js", "../../node_modules/@cesium/engine/Source/Scene/ScreenSpaceCameraController.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/AdditiveBlend.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/BrightPass.js", "../../node_modules/@cesium/engine/Source/Scene/SunPostProcess.js", "../../node_modules/@cesium/engine/Source/Scene/Scene.js", "../../node_modules/@cesium/engine/Source/Shaders/SkyAtmosphereCommon.js", "../../node_modules/@cesium/engine/Source/Shaders/SkyAtmosphereFS.js", "../../node_modules/@cesium/engine/Source/Shaders/SkyAtmosphereVS.js", "../../node_modules/@cesium/engine/Source/Scene/SkyAtmosphere.js", "../../node_modules/@cesium/engine/Source/Shaders/SkyBoxFS.js", "../../node_modules/@cesium/engine/Source/Shaders/SkyBoxVS.js", "../../node_modules/@cesium/engine/Source/Scene/SkyBox.js", "../../node_modules/@cesium/engine/Source/Scene/SpatialNode.js", "../../node_modules/@cesium/engine/Source/Scene/SphereEmitter.js", "../../node_modules/@cesium/engine/Source/Scene/StyleExpression.js", "../../node_modules/@cesium/engine/Source/Shaders/SunFS.js", "../../node_modules/@cesium/engine/Source/Shaders/SunTextureFS.js", "../../node_modules/@cesium/engine/Source/Shaders/SunVS.js", "../../node_modules/@cesium/engine/Source/Scene/Sun.js", "../../node_modules/@cesium/engine/Source/Scene/Terrain.js", "../../node_modules/@cesium/engine/Source/Scene/TileBoundingVolume.js", "../../node_modules/@cesium/engine/Source/Scene/TileCoordinatesImageryProvider.js", "../../node_modules/@cesium/engine/Source/Scene/TileDiscardPolicy.js", "../../node_modules/@cesium/engine/Source/Scene/TileState.js", "../../node_modules/@cesium/engine/Source/Scene/TimeDynamicPointCloud.js", "../../node_modules/@cesium/engine/Source/Shaders/ViewportQuadFS.js", "../../node_modules/@cesium/engine/Source/Scene/ViewportQuad.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/VoxelFS.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/VoxelVS.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectionUtils.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectDepth.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectClippingPlanes.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectBox.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectCylinder.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/IntersectEllipsoid.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/Intersection.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/convertUvToBox.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/convertUvToCylinder.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/convertUvToEllipsoid.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/Octree.js", "../../node_modules/@cesium/engine/Source/Shaders/Voxels/Megatexture.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelRenderResources.js", "../../node_modules/@cesium/engine/Source/Scene/processVoxelProperties.js", "../../node_modules/@cesium/engine/Source/Scene/buildVoxelDrawCommands.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelTraversal.js", "../../node_modules/@cesium/engine/Source/Scene/Model/UniformType.js", "../../node_modules/@cesium/engine/Source/Scene/Model/TextureManager.js", "../../node_modules/@cesium/engine/Source/Scene/Model/CustomShader.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelPrimitive.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelProvider.js", "../../node_modules/@cesium/engine/Source/Scene/VoxelShape.js", "../../node_modules/@cesium/engine/Source/Scene/computeFlyToLocationForRectangle.js", "../../node_modules/@cesium/engine/Source/Scene/createElevationBandMaterial.js", "../../node_modules/@cesium/engine/Source/Scene/createGooglePhotorealistic3DTileset.js", "../../node_modules/@cesium/engine/Source/Scene/createOsmBuildingsAsync.js", "../../node_modules/@cesium/engine/Source/Scene/createTangentSpaceDebugPrimitive.js", "../../node_modules/@cesium/engine/Source/Widget/CesiumWidget.js", "../../node_modules/@cesium/engine/Source/Scene/Model/TextureUniform.js", "../../node_modules/@cesium/engine/Source/Scene/Model/VaryingType.js", "../../node_modules/@cesium/engine/Source/Shaders/PostProcessStages/DepthViewPacked.js", "../../node_modules/@cesium/engine/Source/WorkersES6/createTaskProcessorWorker.js", "../../node_modules/@cesium/engine/index.js", "../../node_modules/@cesium/widgets/Source/ThirdParty/knockout-3.5.1.js", "../../node_modules/@cesium/widgets/Source/ThirdParty/knockout-es5.js", "../../node_modules/@cesium/widgets/Source/SvgPathBindingHandler.js", "../../node_modules/@cesium/widgets/Source/ThirdParty/knockout.js", "../../node_modules/@cesium/widgets/Source/ClockViewModel.js", "../../node_modules/@cesium/widgets/Source/Command.js", "../../node_modules/@cesium/widgets/Source/InspectorShared.js", "../../node_modules/@cesium/widgets/Source/ToggleButtonViewModel.js", "../../node_modules/@cesium/widgets/Source/createCommand.js", "../../node_modules/@cesium/widgets/Source/subscribeAndEvaluate.js", "../../node_modules/@cesium/widgets/Source/Animation/Animation.js", "../../node_modules/@cesium/widgets/Source/Animation/AnimationViewModel.js", "../../node_modules/@cesium/widgets/Source/BaseLayerPicker/BaseLayerPickerViewModel.js", "../../node_modules/@cesium/widgets/Source/BaseLayerPicker/BaseLayerPicker.js", "../../node_modules/@cesium/widgets/Source/BaseLayerPicker/ProviderViewModel.js", "../../node_modules/@cesium/widgets/Source/BaseLayerPicker/createDefaultImageryProviderViewModels.js", "../../node_modules/@cesium/widgets/Source/BaseLayerPicker/createDefaultTerrainProviderViewModels.js", "../../node_modules/@cesium/widgets/Source/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js", "../../node_modules/@cesium/widgets/Source/Cesium3DTilesInspector/Cesium3DTilesInspector.js", "../../node_modules/@cesium/widgets/Source/CesiumInspector/CesiumInspectorViewModel.js", "../../node_modules/@cesium/widgets/Source/CesiumInspector/CesiumInspector.js", "../../node_modules/@cesium/widgets/Source/FullscreenButton/FullscreenButtonViewModel.js", "../../node_modules/@cesium/widgets/Source/FullscreenButton/FullscreenButton.js", "../../node_modules/@cesium/widgets/Source/Geocoder/GeocoderViewModel.js", "../../node_modules/@cesium/widgets/Source/Geocoder/Geocoder.js", "../../node_modules/@cesium/widgets/Source/HomeButton/HomeButtonViewModel.js", "../../node_modules/@cesium/widgets/Source/HomeButton/HomeButton.js", "../../node_modules/@cesium/widgets/Source/InfoBox/InfoBoxViewModel.js", "../../node_modules/@cesium/widgets/Source/InfoBox/InfoBox.js", "../../node_modules/@cesium/widgets/Source/NavigationHelpButton/NavigationHelpButtonViewModel.js", "../../node_modules/@cesium/widgets/Source/NavigationHelpButton/NavigationHelpButton.js", "../../node_modules/@cesium/widgets/Source/PerformanceWatchdog/PerformanceWatchdogViewModel.js", "../../node_modules/@cesium/widgets/Source/PerformanceWatchdog/PerformanceWatchdog.js", "../../node_modules/@cesium/widgets/Source/ProjectionPicker/ProjectionPickerViewModel.js", "../../node_modules/@cesium/widgets/Source/ProjectionPicker/ProjectionPicker.js", "../../node_modules/@cesium/widgets/Source/SceneModePicker/SceneModePickerViewModel.js", "../../node_modules/@cesium/widgets/Source/SceneModePicker/SceneModePicker.js", "../../node_modules/@cesium/widgets/Source/SelectionIndicator/SelectionIndicatorViewModel.js", "../../node_modules/@cesium/widgets/Source/SelectionIndicator/SelectionIndicator.js", "../../node_modules/@cesium/widgets/Source/Timeline/TimelineHighlightRange.js", "../../node_modules/@cesium/widgets/Source/Timeline/TimelineTrack.js", "../../node_modules/@cesium/widgets/Source/Timeline/Timeline.js", "../../node_modules/@cesium/widgets/Source/VRButton/VRButtonViewModel.js", "../../node_modules/@cesium/widgets/Source/VRButton/VRButton.js", "../../node_modules/@cesium/widgets/Source/Viewer/Viewer.js", "../../node_modules/@cesium/widgets/Source/Viewer/viewerCesium3DTilesInspectorMixin.js", "../../node_modules/@cesium/widgets/Source/Viewer/viewerCesiumInspectorMixin.js", "../../node_modules/@cesium/widgets/Source/Viewer/viewerDragDropMixin.js", "../../node_modules/@cesium/widgets/Source/Viewer/viewerPerformanceWatchdogMixin.js", "../../node_modules/@cesium/widgets/Source/VoxelInspector/VoxelInspectorViewModel.js", "../../node_modules/@cesium/widgets/Source/VoxelInspector/VoxelInspector.js", "../../node_modules/@cesium/widgets/Source/Viewer/viewerVoxelInspectorMixin.js", "../../node_modules/@cesium/widgets/index.js"], "sourcesContent": ["/*\n https://github.com/banksean wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace\n so it's better encapsulated. Now you can have multiple random number generators\n and they won't stomp all over eachother's state.\n\n If you want to use this as a substitute for Math.random(), use the random()\n method like so:\n\n var m = new MersenneTwister();\n var randomNumber = m.random();\n\n You can also call the other genrand_{foo}() methods on the instance.\n\n If you want to use a specific seed in order to get a repeatable random\n sequence, pass an integer into the constructor:\n\n var m = new MersenneTwister(123);\n\n and that will always produce the same random sequence.\n\n Sean McCullough (banksean@gmail.com)\n*/\n\n/*\n A C-program for MT19937, with initialization improved 2002/1/26.\n Coded by Takuji Nishimura and Makoto Matsumoto.\n\n Before using, initialize the state by using init_seed(seed)\n or init_by_array(init_key, key_length).\n\n Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,\n All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n 1. Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in the\n documentation and/or other materials provided with the distribution.\n\n 3. The names of its contributors may not be used to endorse or promote\n products derived from this software without specific prior written\n permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n Any feedback is very welcome.\n http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html\n email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)\n*/\n\nvar MersenneTwister = function(seed) {\n\tif (seed == undefined) {\n\t\tseed = new Date().getTime();\n\t}\n\n\t/* Period parameters */\n\tthis.N = 624;\n\tthis.M = 397;\n\tthis.MATRIX_A = 0x9908b0df; /* constant vector a */\n\tthis.UPPER_MASK = 0x80000000; /* most significant w-r bits */\n\tthis.LOWER_MASK = 0x7fffffff; /* least significant r bits */\n\n\tthis.mt = new Array(this.N); /* the array for the state vector */\n\tthis.mti=this.N+1; /* mti==N+1 means mt[N] is not initialized */\n\n\tif (seed.constructor == Array) {\n\t\tthis.init_by_array(seed, seed.length);\n\t}\n\telse {\n\t\tthis.init_seed(seed);\n\t}\n}\n\n/* initializes mt[N] with a seed */\n/* origin name init_genrand */\nMersenneTwister.prototype.init_seed = function(s) {\n\tthis.mt[0] = s >>> 0;\n\tfor (this.mti=1; this.mti>> 30);\n\t\tthis.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)\n\t\t+ this.mti;\n\t\t/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */\n\t\t/* In the previous versions, MSBs of the seed affect */\n\t\t/* only MSBs of the array mt[]. */\n\t\t/* 2002/01/09 modified by Makoto Matsumoto */\n\t\tthis.mt[this.mti] >>>= 0;\n\t\t/* for >32 bit machines */\n\t}\n}\n\n/* initialize by an array with array-length */\n/* init_key is the array for initializing keys */\n/* key_length is its length */\n/* slight change for C++, 2004/2/26 */\nMersenneTwister.prototype.init_by_array = function(init_key, key_length) {\n\tvar i, j, k;\n\tthis.init_seed(19650218);\n\ti=1; j=0;\n\tk = (this.N>key_length ? this.N : key_length);\n\tfor (; k; k--) {\n\t\tvar s = this.mt[i-1] ^ (this.mt[i-1] >>> 30)\n\t\tthis.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525)))\n\t\t+ init_key[j] + j; /* non linear */\n\t\tthis.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */\n\t\ti++; j++;\n\t\tif (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }\n\t\tif (j>=key_length) j=0;\n\t}\n\tfor (k=this.N-1; k; k--) {\n\t\tvar s = this.mt[i-1] ^ (this.mt[i-1] >>> 30);\n\t\tthis.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941))\n\t\t- i; /* non linear */\n\t\tthis.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */\n\t\ti++;\n\t\tif (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }\n\t}\n\n\tthis.mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */\n}\n\n/* generates a random number on [0,0xffffffff]-interval */\n/* origin name genrand_int32 */\nMersenneTwister.prototype.random_int = function() {\n\tvar y;\n\tvar mag01 = new Array(0x0, this.MATRIX_A);\n\t/* mag01[x] = x * MATRIX_A for x=0,1 */\n\n\tif (this.mti >= this.N) { /* generate N words at one time */\n\t\tvar kk;\n\n\t\tif (this.mti == this.N+1) /* if init_seed() has not been called, */\n\t\t\tthis.init_seed(5489); /* a default initial seed is used */\n\n\t\tfor (kk=0;kk>> 1) ^ mag01[y & 0x1];\n\t\t}\n\t\tfor (;kk>> 1) ^ mag01[y & 0x1];\n\t\t}\n\t\ty = (this.mt[this.N-1]&this.UPPER_MASK)|(this.mt[0]&this.LOWER_MASK);\n\t\tthis.mt[this.N-1] = this.mt[this.M-1] ^ (y >>> 1) ^ mag01[y & 0x1];\n\n\t\tthis.mti = 0;\n\t}\n\n\ty = this.mt[this.mti++];\n\n\t/* Tempering */\n\ty ^= (y >>> 11);\n\ty ^= (y << 7) & 0x9d2c5680;\n\ty ^= (y << 15) & 0xefc60000;\n\ty ^= (y >>> 18);\n\n\treturn y >>> 0;\n}\n\n/* generates a random number on [0,0x7fffffff]-interval */\n/* origin name genrand_int31 */\nMersenneTwister.prototype.random_int31 = function() {\n\treturn (this.random_int()>>>1);\n}\n\n/* generates a random number on [0,1]-real-interval */\n/* origin name genrand_real1 */\nMersenneTwister.prototype.random_incl = function() {\n\treturn this.random_int()*(1.0/4294967295.0);\n\t/* divided by 2^32-1 */\n}\n\n/* generates a random number on [0,1)-real-interval */\nMersenneTwister.prototype.random = function() {\n\treturn this.random_int()*(1.0/4294967296.0);\n\t/* divided by 2^32 */\n}\n\n/* generates a random number on (0,1)-real-interval */\n/* origin name genrand_real3 */\nMersenneTwister.prototype.random_excl = function() {\n\treturn (this.random_int() + 0.5)*(1.0/4294967296.0);\n\t/* divided by 2^32 */\n}\n\n/* generates a random number on [0,1) with 53-bit resolution*/\n/* origin name genrand_res53 */\nMersenneTwister.prototype.random_long = function() {\n\tvar a=this.random_int()>>>5, b=this.random_int()>>>6;\n\treturn(a*67108864.0+b)*(1.0/9007199254740992.0);\n}\n\n/* These real versions are due to Isaku Wada, 2002/01/09 added */\n\nmodule.exports = MersenneTwister;\n", "/*! https://mths.be/punycode v1.4.0 by @mathias */\n;(function(root) {\n\n\t/** Detect free variables */\n\tvar freeExports = typeof exports == 'object' && exports &&\n\t\t!exports.nodeType && exports;\n\tvar freeModule = typeof module == 'object' && module &&\n\t\t!module.nodeType && module;\n\tvar freeGlobal = typeof global == 'object' && global;\n\tif (\n\t\tfreeGlobal.global === freeGlobal ||\n\t\tfreeGlobal.window === freeGlobal ||\n\t\tfreeGlobal.self === freeGlobal\n\t) {\n\t\troot = freeGlobal;\n\t}\n\n\t/**\n\t * The `punycode` object.\n\t * @name punycode\n\t * @type Object\n\t */\n\tvar punycode,\n\n\t/** Highest positive signed 32-bit float value */\n\tmaxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1\n\n\t/** Bootstring parameters */\n\tbase = 36,\n\ttMin = 1,\n\ttMax = 26,\n\tskew = 38,\n\tdamp = 700,\n\tinitialBias = 72,\n\tinitialN = 128, // 0x80\n\tdelimiter = '-', // '\\x2D'\n\n\t/** Regular expressions */\n\tregexPunycode = /^xn--/,\n\tregexNonASCII = /[^\\x20-\\x7E]/, // unprintable ASCII chars + non-ASCII chars\n\tregexSeparators = /[\\x2E\\u3002\\uFF0E\\uFF61]/g, // RFC 3490 separators\n\n\t/** Error messages */\n\terrors = {\n\t\t'overflow': 'Overflow: input needs wider integers to process',\n\t\t'not-basic': 'Illegal input >= 0x80 (not a basic code point)',\n\t\t'invalid-input': 'Invalid input'\n\t},\n\n\t/** Convenience shortcuts */\n\tbaseMinusTMin = base - tMin,\n\tfloor = Math.floor,\n\tstringFromCharCode = String.fromCharCode,\n\n\t/** Temporary variable */\n\tkey;\n\n\t/*--------------------------------------------------------------------------*/\n\n\t/**\n\t * A generic error utility function.\n\t * @private\n\t * @param {String} type The error type.\n\t * @returns {Error} Throws a `RangeError` with the applicable error message.\n\t */\n\tfunction error(type) {\n\t\tthrow new RangeError(errors[type]);\n\t}\n\n\t/**\n\t * A generic `Array#map` utility function.\n\t * @private\n\t * @param {Array} array The array to iterate over.\n\t * @param {Function} callback The function that gets called for every array\n\t * item.\n\t * @returns {Array} A new array of values returned by the callback function.\n\t */\n\tfunction map(array, fn) {\n\t\tvar length = array.length;\n\t\tvar result = [];\n\t\twhile (length--) {\n\t\t\tresult[length] = fn(array[length]);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * A simple `Array#map`-like wrapper to work with domain name strings or email\n\t * addresses.\n\t * @private\n\t * @param {String} domain The domain name or email address.\n\t * @param {Function} callback The function that gets called for every\n\t * character.\n\t * @returns {Array} A new string of characters returned by the callback\n\t * function.\n\t */\n\tfunction mapDomain(string, fn) {\n\t\tvar parts = string.split('@');\n\t\tvar result = '';\n\t\tif (parts.length > 1) {\n\t\t\t// In email addresses, only the domain name should be punycoded. Leave\n\t\t\t// the local part (i.e. everything up to `@`) intact.\n\t\t\tresult = parts[0] + '@';\n\t\t\tstring = parts[1];\n\t\t}\n\t\t// Avoid `split(regex)` for IE8 compatibility. See #17.\n\t\tstring = string.replace(regexSeparators, '\\x2E');\n\t\tvar labels = string.split('.');\n\t\tvar encoded = map(labels, fn).join('.');\n\t\treturn result + encoded;\n\t}\n\n\t/**\n\t * Creates an array containing the numeric code points of each Unicode\n\t * character in the string. While JavaScript uses UCS-2 internally,\n\t * this function will convert a pair of surrogate halves (each of which\n\t * UCS-2 exposes as separate characters) into a single code point,\n\t * matching UTF-16.\n\t * @see `punycode.ucs2.encode`\n\t * @see \n\t * @memberOf punycode.ucs2\n\t * @name decode\n\t * @param {String} string The Unicode input string (UCS-2).\n\t * @returns {Array} The new array of code points.\n\t */\n\tfunction ucs2decode(string) {\n\t\tvar output = [],\n\t\t counter = 0,\n\t\t length = string.length,\n\t\t value,\n\t\t extra;\n\t\twhile (counter < length) {\n\t\t\tvalue = string.charCodeAt(counter++);\n\t\t\tif (value >= 0xD800 && value <= 0xDBFF && counter < length) {\n\t\t\t\t// high surrogate, and there is a next character\n\t\t\t\textra = string.charCodeAt(counter++);\n\t\t\t\tif ((extra & 0xFC00) == 0xDC00) { // low surrogate\n\t\t\t\t\toutput.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);\n\t\t\t\t} else {\n\t\t\t\t\t// unmatched surrogate; only append this code unit, in case the next\n\t\t\t\t\t// code unit is the high surrogate of a surrogate pair\n\t\t\t\t\toutput.push(value);\n\t\t\t\t\tcounter--;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\toutput.push(value);\n\t\t\t}\n\t\t}\n\t\treturn output;\n\t}\n\n\t/**\n\t * Creates a string based on an array of numeric code points.\n\t * @see `punycode.ucs2.decode`\n\t * @memberOf punycode.ucs2\n\t * @name encode\n\t * @param {Array} codePoints The array of numeric code points.\n\t * @returns {String} The new Unicode string (UCS-2).\n\t */\n\tfunction ucs2encode(array) {\n\t\treturn map(array, function(value) {\n\t\t\tvar output = '';\n\t\t\tif (value > 0xFFFF) {\n\t\t\t\tvalue -= 0x10000;\n\t\t\t\toutput += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);\n\t\t\t\tvalue = 0xDC00 | value & 0x3FF;\n\t\t\t}\n\t\t\toutput += stringFromCharCode(value);\n\t\t\treturn output;\n\t\t}).join('');\n\t}\n\n\t/**\n\t * Converts a basic code point into a digit/integer.\n\t * @see `digitToBasic()`\n\t * @private\n\t * @param {Number} codePoint The basic numeric code point value.\n\t * @returns {Number} The numeric value of a basic code point (for use in\n\t * representing integers) in the range `0` to `base - 1`, or `base` if\n\t * the code point does not represent a value.\n\t */\n\tfunction basicToDigit(codePoint) {\n\t\tif (codePoint - 48 < 10) {\n\t\t\treturn codePoint - 22;\n\t\t}\n\t\tif (codePoint - 65 < 26) {\n\t\t\treturn codePoint - 65;\n\t\t}\n\t\tif (codePoint - 97 < 26) {\n\t\t\treturn codePoint - 97;\n\t\t}\n\t\treturn base;\n\t}\n\n\t/**\n\t * Converts a digit/integer into a basic code point.\n\t * @see `basicToDigit()`\n\t * @private\n\t * @param {Number} digit The numeric value of a basic code point.\n\t * @returns {Number} The basic code point whose value (when used for\n\t * representing integers) is `digit`, which needs to be in the range\n\t * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is\n\t * used; else, the lowercase form is used. The behavior is undefined\n\t * if `flag` is non-zero and `digit` has no uppercase form.\n\t */\n\tfunction digitToBasic(digit, flag) {\n\t\t// 0..25 map to ASCII a..z or A..Z\n\t\t// 26..35 map to ASCII 0..9\n\t\treturn digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);\n\t}\n\n\t/**\n\t * Bias adaptation function as per section 3.4 of RFC 3492.\n\t * https://tools.ietf.org/html/rfc3492#section-3.4\n\t * @private\n\t */\n\tfunction adapt(delta, numPoints, firstTime) {\n\t\tvar k = 0;\n\t\tdelta = firstTime ? floor(delta / damp) : delta >> 1;\n\t\tdelta += floor(delta / numPoints);\n\t\tfor (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {\n\t\t\tdelta = floor(delta / baseMinusTMin);\n\t\t}\n\t\treturn floor(k + (baseMinusTMin + 1) * delta / (delta + skew));\n\t}\n\n\t/**\n\t * Converts a Punycode string of ASCII-only symbols to a string of Unicode\n\t * symbols.\n\t * @memberOf punycode\n\t * @param {String} input The Punycode string of ASCII-only symbols.\n\t * @returns {String} The resulting string of Unicode symbols.\n\t */\n\tfunction decode(input) {\n\t\t// Don't use UCS-2\n\t\tvar output = [],\n\t\t inputLength = input.length,\n\t\t out,\n\t\t i = 0,\n\t\t n = initialN,\n\t\t bias = initialBias,\n\t\t basic,\n\t\t j,\n\t\t index,\n\t\t oldi,\n\t\t w,\n\t\t k,\n\t\t digit,\n\t\t t,\n\t\t /** Cached calculation results */\n\t\t baseMinusT;\n\n\t\t// Handle the basic code points: let `basic` be the number of input code\n\t\t// points before the last delimiter, or `0` if there is none, then copy\n\t\t// the first basic code points to the output.\n\n\t\tbasic = input.lastIndexOf(delimiter);\n\t\tif (basic < 0) {\n\t\t\tbasic = 0;\n\t\t}\n\n\t\tfor (j = 0; j < basic; ++j) {\n\t\t\t// if it's not a basic code point\n\t\t\tif (input.charCodeAt(j) >= 0x80) {\n\t\t\t\terror('not-basic');\n\t\t\t}\n\t\t\toutput.push(input.charCodeAt(j));\n\t\t}\n\n\t\t// Main decoding loop: start just after the last delimiter if any basic code\n\t\t// points were copied; start at the beginning otherwise.\n\n\t\tfor (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {\n\n\t\t\t// `index` is the index of the next character to be consumed.\n\t\t\t// Decode a generalized variable-length integer into `delta`,\n\t\t\t// which gets added to `i`. The overflow checking is easier\n\t\t\t// if we increase `i` as we go, then subtract off its starting\n\t\t\t// value at the end to obtain `delta`.\n\t\t\tfor (oldi = i, w = 1, k = base; /* no condition */; k += base) {\n\n\t\t\t\tif (index >= inputLength) {\n\t\t\t\t\terror('invalid-input');\n\t\t\t\t}\n\n\t\t\t\tdigit = basicToDigit(input.charCodeAt(index++));\n\n\t\t\t\tif (digit >= base || digit > floor((maxInt - i) / w)) {\n\t\t\t\t\terror('overflow');\n\t\t\t\t}\n\n\t\t\t\ti += digit * w;\n\t\t\t\tt = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);\n\n\t\t\t\tif (digit < t) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tbaseMinusT = base - t;\n\t\t\t\tif (w > floor(maxInt / baseMinusT)) {\n\t\t\t\t\terror('overflow');\n\t\t\t\t}\n\n\t\t\t\tw *= baseMinusT;\n\n\t\t\t}\n\n\t\t\tout = output.length + 1;\n\t\t\tbias = adapt(i - oldi, out, oldi == 0);\n\n\t\t\t// `i` was supposed to wrap around from `out` to `0`,\n\t\t\t// incrementing `n` each time, so we'll fix that now:\n\t\t\tif (floor(i / out) > maxInt - n) {\n\t\t\t\terror('overflow');\n\t\t\t}\n\n\t\t\tn += floor(i / out);\n\t\t\ti %= out;\n\n\t\t\t// Insert `n` at position `i` of the output\n\t\t\toutput.splice(i++, 0, n);\n\n\t\t}\n\n\t\treturn ucs2encode(output);\n\t}\n\n\t/**\n\t * Converts a string of Unicode symbols (e.g. a domain name label) to a\n\t * Punycode string of ASCII-only symbols.\n\t * @memberOf punycode\n\t * @param {String} input The string of Unicode symbols.\n\t * @returns {String} The resulting Punycode string of ASCII-only symbols.\n\t */\n\tfunction encode(input) {\n\t\tvar n,\n\t\t delta,\n\t\t handledCPCount,\n\t\t basicLength,\n\t\t bias,\n\t\t j,\n\t\t m,\n\t\t q,\n\t\t k,\n\t\t t,\n\t\t currentValue,\n\t\t output = [],\n\t\t /** `inputLength` will hold the number of code points in `input`. */\n\t\t inputLength,\n\t\t /** Cached calculation results */\n\t\t handledCPCountPlusOne,\n\t\t baseMinusT,\n\t\t qMinusT;\n\n\t\t// Convert the input in UCS-2 to Unicode\n\t\tinput = ucs2decode(input);\n\n\t\t// Cache the length\n\t\tinputLength = input.length;\n\n\t\t// Initialize the state\n\t\tn = initialN;\n\t\tdelta = 0;\n\t\tbias = initialBias;\n\n\t\t// Handle the basic code points\n\t\tfor (j = 0; j < inputLength; ++j) {\n\t\t\tcurrentValue = input[j];\n\t\t\tif (currentValue < 0x80) {\n\t\t\t\toutput.push(stringFromCharCode(currentValue));\n\t\t\t}\n\t\t}\n\n\t\thandledCPCount = basicLength = output.length;\n\n\t\t// `handledCPCount` is the number of code points that have been handled;\n\t\t// `basicLength` is the number of basic code points.\n\n\t\t// Finish the basic string - if it is not empty - with a delimiter\n\t\tif (basicLength) {\n\t\t\toutput.push(delimiter);\n\t\t}\n\n\t\t// Main encoding loop:\n\t\twhile (handledCPCount < inputLength) {\n\n\t\t\t// All non-basic code points < n have been handled already. Find the next\n\t\t\t// larger one:\n\t\t\tfor (m = maxInt, j = 0; j < inputLength; ++j) {\n\t\t\t\tcurrentValue = input[j];\n\t\t\t\tif (currentValue >= n && currentValue < m) {\n\t\t\t\t\tm = currentValue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Increase `delta` enough to advance the decoder's state to ,\n\t\t\t// but guard against overflow\n\t\t\thandledCPCountPlusOne = handledCPCount + 1;\n\t\t\tif (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {\n\t\t\t\terror('overflow');\n\t\t\t}\n\n\t\t\tdelta += (m - n) * handledCPCountPlusOne;\n\t\t\tn = m;\n\n\t\t\tfor (j = 0; j < inputLength; ++j) {\n\t\t\t\tcurrentValue = input[j];\n\n\t\t\t\tif (currentValue < n && ++delta > maxInt) {\n\t\t\t\t\terror('overflow');\n\t\t\t\t}\n\n\t\t\t\tif (currentValue == n) {\n\t\t\t\t\t// Represent delta as a generalized variable-length integer\n\t\t\t\t\tfor (q = delta, k = base; /* no condition */; k += base) {\n\t\t\t\t\t\tt = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);\n\t\t\t\t\t\tif (q < t) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tqMinusT = q - t;\n\t\t\t\t\t\tbaseMinusT = base - t;\n\t\t\t\t\t\toutput.push(\n\t\t\t\t\t\t\tstringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))\n\t\t\t\t\t\t);\n\t\t\t\t\t\tq = floor(qMinusT / baseMinusT);\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(stringFromCharCode(digitToBasic(q, 0)));\n\t\t\t\t\tbias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);\n\t\t\t\t\tdelta = 0;\n\t\t\t\t\t++handledCPCount;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t++delta;\n\t\t\t++n;\n\n\t\t}\n\t\treturn output.join('');\n\t}\n\n\t/**\n\t * Converts a Punycode string representing a domain name or an email address\n\t * to Unicode. Only the Punycoded parts of the input will be converted, i.e.\n\t * it doesn't matter if you call it on a string that has already been\n\t * converted to Unicode.\n\t * @memberOf punycode\n\t * @param {String} input The Punycoded domain name or email address to\n\t * convert to Unicode.\n\t * @returns {String} The Unicode representation of the given Punycode\n\t * string.\n\t */\n\tfunction toUnicode(input) {\n\t\treturn mapDomain(input, function(string) {\n\t\t\treturn regexPunycode.test(string)\n\t\t\t\t? decode(string.slice(4).toLowerCase())\n\t\t\t\t: string;\n\t\t});\n\t}\n\n\t/**\n\t * Converts a Unicode string representing a domain name or an email address to\n\t * Punycode. Only the non-ASCII parts of the domain name will be converted,\n\t * i.e. it doesn't matter if you call it with a domain that's already in\n\t * ASCII.\n\t * @memberOf punycode\n\t * @param {String} input The domain name or email address to convert, as a\n\t * Unicode string.\n\t * @returns {String} The Punycode representation of the given domain name or\n\t * email address.\n\t */\n\tfunction toASCII(input) {\n\t\treturn mapDomain(input, function(string) {\n\t\t\treturn regexNonASCII.test(string)\n\t\t\t\t? 'xn--' + encode(string)\n\t\t\t\t: string;\n\t\t});\n\t}\n\n\t/*--------------------------------------------------------------------------*/\n\n\t/** Define the public API */\n\tpunycode = {\n\t\t/**\n\t\t * A string representing the current Punycode.js version number.\n\t\t * @memberOf punycode\n\t\t * @type String\n\t\t */\n\t\t'version': '1.3.2',\n\t\t/**\n\t\t * An object of methods to convert from JavaScript's internal character\n\t\t * representation (UCS-2) to Unicode code points, and back.\n\t\t * @see \n\t\t * @memberOf punycode\n\t\t * @type Object\n\t\t */\n\t\t'ucs2': {\n\t\t\t'decode': ucs2decode,\n\t\t\t'encode': ucs2encode\n\t\t},\n\t\t'decode': decode,\n\t\t'encode': encode,\n\t\t'toASCII': toASCII,\n\t\t'toUnicode': toUnicode\n\t};\n\n\t/** Expose `punycode` */\n\t// Some AMD build optimizers, like r.js, check for specific condition patterns\n\t// like the following:\n\tif (\n\t\ttypeof define == 'function' &&\n\t\ttypeof define.amd == 'object' &&\n\t\tdefine.amd\n\t) {\n\t\tdefine('punycode', function() {\n\t\t\treturn punycode;\n\t\t});\n\t} else if (freeExports && freeModule) {\n\t\tif (module.exports == freeExports) {\n\t\t\t// in Node.js, io.js, or RingoJS v0.8.0+\n\t\t\tfreeModule.exports = punycode;\n\t\t} else {\n\t\t\t// in Narwhal or RingoJS v0.7.0-\n\t\t\tfor (key in punycode) {\n\t\t\t\tpunycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// in Rhino or a web browser\n\t\troot.punycode = punycode;\n\t}\n\n}(this));\n", "/*!\n * URI.js - Mutating URLs\n * IPv6 Support\n *\n * Version: 1.19.11\n *\n * Author: Rodney Rehm\n * Web: http://medialize.github.io/URI.js/\n *\n * Licensed under\n * MIT License http://www.opensource.org/licenses/mit-license\n *\n */\n\n(function (root, factory) {\n 'use strict';\n // https://github.com/umdjs/umd/blob/master/returnExports.js\n if (typeof module === 'object' && module.exports) {\n // Node\n module.exports = factory();\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(factory);\n } else {\n // Browser globals (root is window)\n root.IPv6 = factory(root);\n }\n}(this, function (root) {\n 'use strict';\n\n /*\n var _in = \"fe80:0000:0000:0000:0204:61ff:fe9d:f156\";\n var _out = IPv6.best(_in);\n var _expected = \"fe80::204:61ff:fe9d:f156\";\n\n console.log(_in, _out, _expected, _out === _expected);\n */\n\n // save current IPv6 variable, if any\n var _IPv6 = root && root.IPv6;\n\n function bestPresentation(address) {\n // based on:\n // Javascript to test an IPv6 address for proper format, and to\n // present the \"best text representation\" according to IETF Draft RFC at\n // http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04\n // 8 Feb 2010 Rich Brown, Dartware, LLC\n // Please feel free to use this code as long as you provide a link to\n // http://www.intermapper.com\n // http://intermapper.com/support/tools/IPV6-Validator.aspx\n // http://download.dartware.com/thirdparty/ipv6validator.js\n\n var _address = address.toLowerCase();\n var segments = _address.split(':');\n var length = segments.length;\n var total = 8;\n\n // trim colons (:: or ::a:b:c\u2026 or \u2026a:b:c::)\n if (segments[0] === '' && segments[1] === '' && segments[2] === '') {\n // must have been ::\n // remove first two items\n segments.shift();\n segments.shift();\n } else if (segments[0] === '' && segments[1] === '') {\n // must have been ::xxxx\n // remove the first item\n segments.shift();\n } else if (segments[length - 1] === '' && segments[length - 2] === '') {\n // must have been xxxx::\n segments.pop();\n }\n\n length = segments.length;\n\n // adjust total segments for IPv4 trailer\n if (segments[length - 1].indexOf('.') !== -1) {\n // found a \".\" which means IPv4\n total = 7;\n }\n\n // fill empty segments them with \"0000\"\n var pos;\n for (pos = 0; pos < length; pos++) {\n if (segments[pos] === '') {\n break;\n }\n }\n\n if (pos < total) {\n segments.splice(pos, 1, '0000');\n while (segments.length < total) {\n segments.splice(pos, 0, '0000');\n }\n }\n\n // strip leading zeros\n var _segments;\n for (var i = 0; i < total; i++) {\n _segments = segments[i].split('');\n for (var j = 0; j < 3 ; j++) {\n if (_segments[0] === '0' && _segments.length > 1) {\n _segments.splice(0,1);\n } else {\n break;\n }\n }\n\n segments[i] = _segments.join('');\n }\n\n // find longest sequence of zeroes and coalesce them into one segment\n var best = -1;\n var _best = 0;\n var _current = 0;\n var current = -1;\n var inzeroes = false;\n // i; already declared\n\n for (i = 0; i < total; i++) {\n if (inzeroes) {\n if (segments[i] === '0') {\n _current += 1;\n } else {\n inzeroes = false;\n if (_current > _best) {\n best = current;\n _best = _current;\n }\n }\n } else {\n if (segments[i] === '0') {\n inzeroes = true;\n current = i;\n _current = 1;\n }\n }\n }\n\n if (_current > _best) {\n best = current;\n _best = _current;\n }\n\n if (_best > 1) {\n segments.splice(best, _best, '');\n }\n\n length = segments.length;\n\n // assemble remaining segments\n var result = '';\n if (segments[0] === '') {\n result = ':';\n }\n\n for (i = 0; i < length; i++) {\n result += segments[i];\n if (i === length - 1) {\n break;\n }\n\n result += ':';\n }\n\n if (segments[length - 1] === '') {\n result += ':';\n }\n\n return result;\n }\n\n function noConflict() {\n /*jshint validthis: true */\n if (root.IPv6 === this) {\n root.IPv6 = _IPv6;\n }\n\n return this;\n }\n\n return {\n best: bestPresentation,\n noConflict: noConflict\n };\n}));\n", "/*!\n * URI.js - Mutating URLs\n * Second Level Domain (SLD) Support\n *\n * Version: 1.19.11\n *\n * Author: Rodney Rehm\n * Web: http://medialize.github.io/URI.js/\n *\n * Licensed under\n * MIT License http://www.opensource.org/licenses/mit-license\n *\n */\n\n(function (root, factory) {\n 'use strict';\n // https://github.com/umdjs/umd/blob/master/returnExports.js\n if (typeof module === 'object' && module.exports) {\n // Node\n module.exports = factory();\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(factory);\n } else {\n // Browser globals (root is window)\n root.SecondLevelDomains = factory(root);\n }\n}(this, function (root) {\n 'use strict';\n\n // save current SecondLevelDomains variable, if any\n var _SecondLevelDomains = root && root.SecondLevelDomains;\n\n var SLD = {\n // list of known Second Level Domains\n // converted list of SLDs from https://github.com/gavingmiller/second-level-domains\n // ----\n // publicsuffix.org is more current and actually used by a couple of browsers internally.\n // downside is it also contains domains like \"dyndns.org\" - which is fine for the security\n // issues browser have to deal with (SOP for cookies, etc) - but is way overboard for URI.js\n // ----\n list: {\n 'ac':' com gov mil net org ',\n 'ae':' ac co gov mil name net org pro sch ',\n 'af':' com edu gov net org ',\n 'al':' com edu gov mil net org ',\n 'ao':' co ed gv it og pb ',\n 'ar':' com edu gob gov int mil net org tur ',\n 'at':' ac co gv or ',\n 'au':' asn com csiro edu gov id net org ',\n 'ba':' co com edu gov mil net org rs unbi unmo unsa untz unze ',\n 'bb':' biz co com edu gov info net org store tv ',\n 'bh':' biz cc com edu gov info net org ',\n 'bn':' com edu gov net org ',\n 'bo':' com edu gob gov int mil net org tv ',\n 'br':' adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ',\n 'bs':' com edu gov net org ',\n 'bz':' du et om ov rg ',\n 'ca':' ab bc mb nb nf nl ns nt nu on pe qc sk yk ',\n 'ck':' biz co edu gen gov info net org ',\n 'cn':' ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ',\n 'co':' com edu gov mil net nom org ',\n 'cr':' ac c co ed fi go or sa ',\n 'cy':' ac biz com ekloges gov ltd name net org parliament press pro tm ',\n 'do':' art com edu gob gov mil net org sld web ',\n 'dz':' art asso com edu gov net org pol ',\n 'ec':' com edu fin gov info med mil net org pro ',\n 'eg':' com edu eun gov mil name net org sci ',\n 'er':' com edu gov ind mil net org rochest w ',\n 'es':' com edu gob nom org ',\n 'et':' biz com edu gov info name net org ',\n 'fj':' ac biz com info mil name net org pro ',\n 'fk':' ac co gov net nom org ',\n 'fr':' asso com f gouv nom prd presse tm ',\n 'gg':' co net org ',\n 'gh':' com edu gov mil org ',\n 'gn':' ac com gov net org ',\n 'gr':' com edu gov mil net org ',\n 'gt':' com edu gob ind mil net org ',\n 'gu':' com edu gov net org ',\n 'hk':' com edu gov idv net org ',\n 'hu':' 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ',\n 'id':' ac co go mil net or sch web ',\n 'il':' ac co gov idf k12 muni net org ',\n 'in':' ac co edu ernet firm gen gov i ind mil net nic org res ',\n 'iq':' com edu gov i mil net org ',\n 'ir':' ac co dnssec gov i id net org sch ',\n 'it':' edu gov ',\n 'je':' co net org ',\n 'jo':' com edu gov mil name net org sch ',\n 'jp':' ac ad co ed go gr lg ne or ',\n 'ke':' ac co go info me mobi ne or sc ',\n 'kh':' com edu gov mil net org per ',\n 'ki':' biz com de edu gov info mob net org tel ',\n 'km':' asso com coop edu gouv k medecin mil nom notaires pharmaciens presse tm veterinaire ',\n 'kn':' edu gov net org ',\n 'kr':' ac busan chungbuk chungnam co daegu daejeon es gangwon go gwangju gyeongbuk gyeonggi gyeongnam hs incheon jeju jeonbuk jeonnam k kg mil ms ne or pe re sc seoul ulsan ',\n 'kw':' com edu gov net org ',\n 'ky':' com edu gov net org ',\n 'kz':' com edu gov mil net org ',\n 'lb':' com edu gov net org ',\n 'lk':' assn com edu gov grp hotel int ltd net ngo org sch soc web ',\n 'lr':' com edu gov net org ',\n 'lv':' asn com conf edu gov id mil net org ',\n 'ly':' com edu gov id med net org plc sch ',\n 'ma':' ac co gov m net org press ',\n 'mc':' asso tm ',\n 'me':' ac co edu gov its net org priv ',\n 'mg':' com edu gov mil nom org prd tm ',\n 'mk':' com edu gov inf name net org pro ',\n 'ml':' com edu gov net org presse ',\n 'mn':' edu gov org ',\n 'mo':' com edu gov net org ',\n 'mt':' com edu gov net org ',\n 'mv':' aero biz com coop edu gov info int mil museum name net org pro ',\n 'mw':' ac co com coop edu gov int museum net org ',\n 'mx':' com edu gob net org ',\n 'my':' com edu gov mil name net org sch ',\n 'nf':' arts com firm info net other per rec store web ',\n 'ng':' biz com edu gov mil mobi name net org sch ',\n 'ni':' ac co com edu gob mil net nom org ',\n 'np':' com edu gov mil net org ',\n 'nr':' biz com edu gov info net org ',\n 'om':' ac biz co com edu gov med mil museum net org pro sch ',\n 'pe':' com edu gob mil net nom org sld ',\n 'ph':' com edu gov i mil net ngo org ',\n 'pk':' biz com edu fam gob gok gon gop gos gov net org web ',\n 'pl':' art bialystok biz com edu gda gdansk gorzow gov info katowice krakow lodz lublin mil net ngo olsztyn org poznan pwr radom slupsk szczecin torun warszawa waw wroc wroclaw zgora ',\n 'pr':' ac biz com edu est gov info isla name net org pro prof ',\n 'ps':' com edu gov net org plo sec ',\n 'pw':' belau co ed go ne or ',\n 'ro':' arts com firm info nom nt org rec store tm www ',\n 'rs':' ac co edu gov in org ',\n 'sb':' com edu gov net org ',\n 'sc':' com edu gov net org ',\n 'sh':' co com edu gov net nom org ',\n 'sl':' com edu gov net org ',\n 'st':' co com consulado edu embaixada gov mil net org principe saotome store ',\n 'sv':' com edu gob org red ',\n 'sz':' ac co org ',\n 'tr':' av bbs bel biz com dr edu gen gov info k12 name net org pol tel tsk tv web ',\n 'tt':' aero biz cat co com coop edu gov info int jobs mil mobi museum name net org pro tel travel ',\n 'tw':' club com ebiz edu game gov idv mil net org ',\n 'mu':' ac co com gov net or org ',\n 'mz':' ac co edu gov org ',\n 'na':' co com ',\n 'nz':' ac co cri geek gen govt health iwi maori mil net org parliament school ',\n 'pa':' abo ac com edu gob ing med net nom org sld ',\n 'pt':' com edu gov int net nome org publ ',\n 'py':' com edu gov mil net org ',\n 'qa':' com edu gov mil net org ',\n 're':' asso com nom ',\n 'ru':' ac adygeya altai amur arkhangelsk astrakhan bashkiria belgorod bir bryansk buryatia cbg chel chelyabinsk chita chukotka chuvashia com dagestan e-burg edu gov grozny int irkutsk ivanovo izhevsk jar joshkar-ola kalmykia kaluga kamchatka karelia kazan kchr kemerovo khabarovsk khakassia khv kirov koenig komi kostroma kranoyarsk kuban kurgan kursk lipetsk magadan mari mari-el marine mil mordovia mosreg msk murmansk nalchik net nnov nov novosibirsk nsk omsk orenburg org oryol penza perm pp pskov ptz rnd ryazan sakhalin samara saratov simbirsk smolensk spb stavropol stv surgut tambov tatarstan tom tomsk tsaritsyn tsk tula tuva tver tyumen udm udmurtia ulan-ude vladikavkaz vladimir vladivostok volgograd vologda voronezh vrn vyatka yakutia yamal yekaterinburg yuzhno-sakhalinsk ',\n 'rw':' ac co com edu gouv gov int mil net ',\n 'sa':' com edu gov med net org pub sch ',\n 'sd':' com edu gov info med net org tv ',\n 'se':' a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ',\n 'sg':' com edu gov idn net org per ',\n 'sn':' art com edu gouv org perso univ ',\n 'sy':' com edu gov mil net news org ',\n 'th':' ac co go in mi net or ',\n 'tj':' ac biz co com edu go gov info int mil name net nic org test web ',\n 'tn':' agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ',\n 'tz':' ac co go ne or ',\n 'ua':' biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ',\n 'ug':' ac co go ne or org sc ',\n 'uk':' ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ',\n 'us':' dni fed isa kids nsn ',\n 'uy':' com edu gub mil net org ',\n 've':' co com edu gob info mil net org web ',\n 'vi':' co com k12 net org ',\n 'vn':' ac biz com edu gov health info int name net org pro ',\n 'ye':' co com gov ltd me net org plc ',\n 'yu':' ac co edu gov org ',\n 'za':' ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ',\n 'zm':' ac co com edu gov net org sch ',\n // https://en.wikipedia.org/wiki/CentralNic#Second-level_domains\n 'com': 'ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ',\n 'net': 'gb jp se uk ',\n 'org': 'ae',\n 'de': 'com '\n },\n // gorhill 2013-10-25: Using indexOf() instead Regexp(). Significant boost\n // in both performance and memory footprint. No initialization required.\n // http://jsperf.com/uri-js-sld-regex-vs-binary-search/4\n // Following methods use lastIndexOf() rather than array.split() in order\n // to avoid any memory allocations.\n has: function(domain) {\n var tldOffset = domain.lastIndexOf('.');\n if (tldOffset <= 0 || tldOffset >= (domain.length-1)) {\n return false;\n }\n var sldOffset = domain.lastIndexOf('.', tldOffset-1);\n if (sldOffset <= 0 || sldOffset >= (tldOffset-1)) {\n return false;\n }\n var sldList = SLD.list[domain.slice(tldOffset+1)];\n if (!sldList) {\n return false;\n }\n return sldList.indexOf(' ' + domain.slice(sldOffset+1, tldOffset) + ' ') >= 0;\n },\n is: function(domain) {\n var tldOffset = domain.lastIndexOf('.');\n if (tldOffset <= 0 || tldOffset >= (domain.length-1)) {\n return false;\n }\n var sldOffset = domain.lastIndexOf('.', tldOffset-1);\n if (sldOffset >= 0) {\n return false;\n }\n var sldList = SLD.list[domain.slice(tldOffset+1)];\n if (!sldList) {\n return false;\n }\n return sldList.indexOf(' ' + domain.slice(0, tldOffset) + ' ') >= 0;\n },\n get: function(domain) {\n var tldOffset = domain.lastIndexOf('.');\n if (tldOffset <= 0 || tldOffset >= (domain.length-1)) {\n return null;\n }\n var sldOffset = domain.lastIndexOf('.', tldOffset-1);\n if (sldOffset <= 0 || sldOffset >= (tldOffset-1)) {\n return null;\n }\n var sldList = SLD.list[domain.slice(tldOffset+1)];\n if (!sldList) {\n return null;\n }\n if (sldList.indexOf(' ' + domain.slice(sldOffset+1, tldOffset) + ' ') < 0) {\n return null;\n }\n return domain.slice(sldOffset+1);\n },\n noConflict: function(){\n if (root.SecondLevelDomains === this) {\n root.SecondLevelDomains = _SecondLevelDomains;\n }\n return this;\n }\n };\n\n return SLD;\n}));\n", "/*!\n * URI.js - Mutating URLs\n *\n * Version: 1.19.11\n *\n * Author: Rodney Rehm\n * Web: http://medialize.github.io/URI.js/\n *\n * Licensed under\n * MIT License http://www.opensource.org/licenses/mit-license\n *\n */\n(function (root, factory) {\n 'use strict';\n // https://github.com/umdjs/umd/blob/master/returnExports.js\n if (typeof module === 'object' && module.exports) {\n // Node\n module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(['./punycode', './IPv6', './SecondLevelDomains'], factory);\n } else {\n // Browser globals (root is window)\n root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains, root);\n }\n}(this, function (punycode, IPv6, SLD, root) {\n 'use strict';\n /*global location, escape, unescape */\n // FIXME: v2.0.0 renamce non-camelCase properties to uppercase\n /*jshint camelcase: false */\n\n // save current URI variable, if any\n var _URI = root && root.URI;\n\n function URI(url, base) {\n var _urlSupplied = arguments.length >= 1;\n var _baseSupplied = arguments.length >= 2;\n\n // Allow instantiation without the 'new' keyword\n if (!(this instanceof URI)) {\n if (_urlSupplied) {\n if (_baseSupplied) {\n return new URI(url, base);\n }\n\n return new URI(url);\n }\n\n return new URI();\n }\n\n if (url === undefined) {\n if (_urlSupplied) {\n throw new TypeError('undefined is not a valid argument for URI');\n }\n\n if (typeof location !== 'undefined') {\n url = location.href + '';\n } else {\n url = '';\n }\n }\n\n if (url === null) {\n if (_urlSupplied) {\n throw new TypeError('null is not a valid argument for URI');\n }\n }\n\n this.href(url);\n\n // resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor\n if (base !== undefined) {\n return this.absoluteTo(base);\n }\n\n return this;\n }\n\n function isInteger(value) {\n return /^[0-9]+$/.test(value);\n }\n\n URI.version = '1.19.11';\n\n var p = URI.prototype;\n var hasOwn = Object.prototype.hasOwnProperty;\n\n function escapeRegEx(string) {\n // https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963\n return string.replace(/([.*+?^=!:${}()|[\\]\\/\\\\])/g, '\\\\$1');\n }\n\n function getType(value) {\n // IE8 doesn't return [Object Undefined] but [Object Object] for undefined value\n if (value === undefined) {\n return 'Undefined';\n }\n\n return String(Object.prototype.toString.call(value)).slice(8, -1);\n }\n\n function isArray(obj) {\n return getType(obj) === 'Array';\n }\n\n function filterArrayValues(data, value) {\n var lookup = {};\n var i, length;\n\n if (getType(value) === 'RegExp') {\n lookup = null;\n } else if (isArray(value)) {\n for (i = 0, length = value.length; i < length; i++) {\n lookup[value[i]] = true;\n }\n } else {\n lookup[value] = true;\n }\n\n for (i = 0, length = data.length; i < length; i++) {\n /*jshint laxbreak: true */\n var _match = lookup && lookup[data[i]] !== undefined\n || !lookup && value.test(data[i]);\n /*jshint laxbreak: false */\n if (_match) {\n data.splice(i, 1);\n length--;\n i--;\n }\n }\n\n return data;\n }\n\n function arrayContains(list, value) {\n var i, length;\n\n // value may be string, number, array, regexp\n if (isArray(value)) {\n // Note: this can be optimized to O(n) (instead of current O(m * n))\n for (i = 0, length = value.length; i < length; i++) {\n if (!arrayContains(list, value[i])) {\n return false;\n }\n }\n\n return true;\n }\n\n var _type = getType(value);\n for (i = 0, length = list.length; i < length; i++) {\n if (_type === 'RegExp') {\n if (typeof list[i] === 'string' && list[i].match(value)) {\n return true;\n }\n } else if (list[i] === value) {\n return true;\n }\n }\n\n return false;\n }\n\n function arraysEqual(one, two) {\n if (!isArray(one) || !isArray(two)) {\n return false;\n }\n\n // arrays can't be equal if they have different amount of content\n if (one.length !== two.length) {\n return false;\n }\n\n one.sort();\n two.sort();\n\n for (var i = 0, l = one.length; i < l; i++) {\n if (one[i] !== two[i]) {\n return false;\n }\n }\n\n return true;\n }\n\n function trimSlashes(text) {\n var trim_expression = /^\\/+|\\/+$/g;\n return text.replace(trim_expression, '');\n }\n\n URI._parts = function() {\n return {\n protocol: null,\n username: null,\n password: null,\n hostname: null,\n urn: null,\n port: null,\n path: null,\n query: null,\n fragment: null,\n // state\n preventInvalidHostname: URI.preventInvalidHostname,\n duplicateQueryParameters: URI.duplicateQueryParameters,\n escapeQuerySpace: URI.escapeQuerySpace\n };\n };\n // state: throw on invalid hostname\n // see https://github.com/medialize/URI.js/pull/345\n // and https://github.com/medialize/URI.js/issues/354\n URI.preventInvalidHostname = false;\n // state: allow duplicate query parameters (a=1&a=1)\n URI.duplicateQueryParameters = false;\n // state: replaces + with %20 (space in query strings)\n URI.escapeQuerySpace = true;\n // static properties\n URI.protocol_expression = /^[a-z][a-z0-9.+-]*$/i;\n URI.idn_expression = /[^a-z0-9\\._-]/i;\n URI.punycode_expression = /(xn--)/i;\n // well, 333.444.555.666 matches, but it sure ain't no IPv4 - do we care?\n URI.ip4_expression = /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/;\n // credits to Rich Brown\n // source: http://forums.intermapper.com/viewtopic.php?p=1096#1096\n // specification: http://www.ietf.org/rfc/rfc4291.txt\n URI.ip6_expression = /^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$/;\n // expression used is \"gruber revised\" (@gruber v2) determined to be the\n // best solution in a regex-golf we did a couple of ages ago at\n // * http://mathiasbynens.be/demo/url-regex\n // * http://rodneyrehm.de/t/url-regex.html\n URI.find_uri_expression = /\\b((?:[a-z][\\w-]+:(?:\\/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}\\/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]))/ig;\n URI.findUri = {\n // valid \"scheme://\" or \"www.\"\n start: /\\b(?:([a-z][a-z0-9.+-]*:\\/\\/)|www\\.)/gi,\n // everything up to the next whitespace\n end: /[\\s\\r\\n]|$/,\n // trim trailing punctuation captured by end RegExp\n trim: /[`!()\\[\\]{};:'\".,<>?\u00AB\u00BB\u201C\u201D\u201E\u2018\u2019]+$/,\n // balanced parens inclusion (), [], {}, <>\n parens: /(\\([^\\)]*\\)|\\[[^\\]]*\\]|\\{[^}]*\\}|<[^>]*>)/g,\n };\n URI.leading_whitespace_expression = /^[\\x00-\\x20\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]+/\n // https://infra.spec.whatwg.org/#ascii-tab-or-newline\n URI.ascii_tab_whitespace = /[\\u0009\\u000A\\u000D]+/g\n // http://www.iana.org/assignments/uri-schemes.html\n // http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports\n URI.defaultPorts = {\n http: '80',\n https: '443',\n ftp: '21',\n gopher: '70',\n ws: '80',\n wss: '443'\n };\n // list of protocols which always require a hostname\n URI.hostProtocols = [\n 'http',\n 'https'\n ];\n\n // allowed hostname characters according to RFC 3986\n // ALPHA DIGIT \"-\" \".\" \"_\" \"~\" \"!\" \"$\" \"&\" \"'\" \"(\" \")\" \"*\" \"+\" \",\" \";\" \"=\" %encoded\n // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - _\n URI.invalid_hostname_characters = /[^a-zA-Z0-9\\.\\-:_]/;\n // map DOM Elements to their URI attribute\n URI.domAttributes = {\n 'a': 'href',\n 'blockquote': 'cite',\n 'link': 'href',\n 'base': 'href',\n 'script': 'src',\n 'form': 'action',\n 'img': 'src',\n 'area': 'href',\n 'iframe': 'src',\n 'embed': 'src',\n 'source': 'src',\n 'track': 'src',\n 'input': 'src', // but only if type=\"image\"\n 'audio': 'src',\n 'video': 'src'\n };\n URI.getDomAttribute = function(node) {\n if (!node || !node.nodeName) {\n return undefined;\n }\n\n var nodeName = node.nodeName.toLowerCase();\n // should only expose src for type=\"image\"\n if (nodeName === 'input' && node.type !== 'image') {\n return undefined;\n }\n\n return URI.domAttributes[nodeName];\n };\n\n function escapeForDumbFirefox36(value) {\n // https://github.com/medialize/URI.js/issues/91\n return escape(value);\n }\n\n // encoding / decoding according to RFC3986\n function strictEncodeURIComponent(string) {\n // see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent\n return encodeURIComponent(string)\n .replace(/[!'()*]/g, escapeForDumbFirefox36)\n .replace(/\\*/g, '%2A');\n }\n URI.encode = strictEncodeURIComponent;\n URI.decode = decodeURIComponent;\n URI.iso8859 = function() {\n URI.encode = escape;\n URI.decode = unescape;\n };\n URI.unicode = function() {\n URI.encode = strictEncodeURIComponent;\n URI.decode = decodeURIComponent;\n };\n URI.characters = {\n pathname: {\n encode: {\n // RFC3986 2.1: For consistency, URI producers and normalizers should\n // use uppercase hexadecimal digits for all percent-encodings.\n expression: /%(24|26|2B|2C|3B|3D|3A|40)/ig,\n map: {\n // -._~!'()*\n '%24': '$',\n '%26': '&',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '=',\n '%3A': ':',\n '%40': '@'\n }\n },\n decode: {\n expression: /[\\/\\?#]/g,\n map: {\n '/': '%2F',\n '?': '%3F',\n '#': '%23'\n }\n }\n },\n reserved: {\n encode: {\n // RFC3986 2.1: For consistency, URI producers and normalizers should\n // use uppercase hexadecimal digits for all percent-encodings.\n expression: /%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,\n map: {\n // gen-delims\n '%3A': ':',\n '%2F': '/',\n '%3F': '?',\n '%23': '#',\n '%5B': '[',\n '%5D': ']',\n '%40': '@',\n // sub-delims\n '%21': '!',\n '%24': '$',\n '%26': '&',\n '%27': '\\'',\n '%28': '(',\n '%29': ')',\n '%2A': '*',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '='\n }\n }\n },\n urnpath: {\n // The characters under `encode` are the characters called out by RFC 2141 as being acceptable\n // for usage in a URN. RFC2141 also calls out \"-\", \".\", and \"_\" as acceptable characters, but\n // these aren't encoded by encodeURIComponent, so we don't have to call them out here. Also\n // note that the colon character is not featured in the encoding map; this is because URI.js\n // gives the colons in URNs semantic meaning as the delimiters of path segements, and so it\n // should not appear unencoded in a segment itself.\n // See also the note above about RFC3986 and capitalalized hex digits.\n encode: {\n expression: /%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,\n map: {\n '%21': '!',\n '%24': '$',\n '%27': '\\'',\n '%28': '(',\n '%29': ')',\n '%2A': '*',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '=',\n '%40': '@'\n }\n },\n // These characters are the characters called out by RFC2141 as \"reserved\" characters that\n // should never appear in a URN, plus the colon character (see note above).\n decode: {\n expression: /[\\/\\?#:]/g,\n map: {\n '/': '%2F',\n '?': '%3F',\n '#': '%23',\n ':': '%3A'\n }\n }\n }\n };\n URI.encodeQuery = function(string, escapeQuerySpace) {\n var escaped = URI.encode(string + '');\n if (escapeQuerySpace === undefined) {\n escapeQuerySpace = URI.escapeQuerySpace;\n }\n\n return escapeQuerySpace ? escaped.replace(/%20/g, '+') : escaped;\n };\n URI.decodeQuery = function(string, escapeQuerySpace) {\n string += '';\n if (escapeQuerySpace === undefined) {\n escapeQuerySpace = URI.escapeQuerySpace;\n }\n\n try {\n return URI.decode(escapeQuerySpace ? string.replace(/\\+/g, '%20') : string);\n } catch(e) {\n // we're not going to mess with weird encodings,\n // give up and return the undecoded original string\n // see https://github.com/medialize/URI.js/issues/87\n // see https://github.com/medialize/URI.js/issues/92\n return string;\n }\n };\n // generate encode/decode path functions\n var _parts = {'encode':'encode', 'decode':'decode'};\n var _part;\n var generateAccessor = function(_group, _part) {\n return function(string) {\n try {\n return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function(c) {\n return URI.characters[_group][_part].map[c];\n });\n } catch (e) {\n // we're not going to mess with weird encodings,\n // give up and return the undecoded original string\n // see https://github.com/medialize/URI.js/issues/87\n // see https://github.com/medialize/URI.js/issues/92\n return string;\n }\n };\n };\n\n for (_part in _parts) {\n URI[_part + 'PathSegment'] = generateAccessor('pathname', _parts[_part]);\n URI[_part + 'UrnPathSegment'] = generateAccessor('urnpath', _parts[_part]);\n }\n\n var generateSegmentedPathFunction = function(_sep, _codingFuncName, _innerCodingFuncName) {\n return function(string) {\n // Why pass in names of functions, rather than the function objects themselves? The\n // definitions of some functions (but in particular, URI.decode) will occasionally change due\n // to URI.js having ISO8859 and Unicode modes. Passing in the name and getting it will ensure\n // that the functions we use here are \"fresh\".\n var actualCodingFunc;\n if (!_innerCodingFuncName) {\n actualCodingFunc = URI[_codingFuncName];\n } else {\n actualCodingFunc = function(string) {\n return URI[_codingFuncName](URI[_innerCodingFuncName](string));\n };\n }\n\n var segments = (string + '').split(_sep);\n\n for (var i = 0, length = segments.length; i < length; i++) {\n segments[i] = actualCodingFunc(segments[i]);\n }\n\n return segments.join(_sep);\n };\n };\n\n // This takes place outside the above loop because we don't want, e.g., encodeUrnPath functions.\n URI.decodePath = generateSegmentedPathFunction('/', 'decodePathSegment');\n URI.decodeUrnPath = generateSegmentedPathFunction(':', 'decodeUrnPathSegment');\n URI.recodePath = generateSegmentedPathFunction('/', 'encodePathSegment', 'decode');\n URI.recodeUrnPath = generateSegmentedPathFunction(':', 'encodeUrnPathSegment', 'decode');\n\n URI.encodeReserved = generateAccessor('reserved', 'encode');\n\n URI.parse = function(string, parts) {\n var pos;\n if (!parts) {\n parts = {\n preventInvalidHostname: URI.preventInvalidHostname\n };\n }\n\n string = string.replace(URI.leading_whitespace_expression, '')\n // https://infra.spec.whatwg.org/#ascii-tab-or-newline\n string = string.replace(URI.ascii_tab_whitespace, '')\n\n // [protocol\"://\"[username[\":\"password]\"@\"]hostname[\":\"port]\"/\"?][path][\"?\"querystring][\"#\"fragment]\n\n // extract fragment\n pos = string.indexOf('#');\n if (pos > -1) {\n // escaping?\n parts.fragment = string.substring(pos + 1) || null;\n string = string.substring(0, pos);\n }\n\n // extract query\n pos = string.indexOf('?');\n if (pos > -1) {\n // escaping?\n parts.query = string.substring(pos + 1) || null;\n string = string.substring(0, pos);\n }\n\n // slashes and backslashes have lost all meaning for the web protocols (https, http, wss, ws)\n string = string.replace(/^(https?|ftp|wss?)?:+[/\\\\]*/i, '$1://');\n // slashes and backslashes have lost all meaning for scheme relative URLs\n string = string.replace(/^[/\\\\]{2,}/i, '//');\n\n // extract protocol\n if (string.substring(0, 2) === '//') {\n // relative-scheme\n parts.protocol = null;\n string = string.substring(2);\n // extract \"user:pass@host:port\"\n string = URI.parseAuthority(string, parts);\n } else {\n pos = string.indexOf(':');\n if (pos > -1) {\n parts.protocol = string.substring(0, pos) || null;\n if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {\n // : may be within the path\n parts.protocol = undefined;\n } else if (string.substring(pos + 1, pos + 3).replace(/\\\\/g, '/') === '//') {\n string = string.substring(pos + 3);\n\n // extract \"user:pass@host:port\"\n string = URI.parseAuthority(string, parts);\n } else {\n string = string.substring(pos + 1);\n parts.urn = true;\n }\n }\n }\n\n // what's left must be the path\n parts.path = string;\n\n // and we're done\n return parts;\n };\n URI.parseHost = function(string, parts) {\n if (!string) {\n string = '';\n }\n\n // Copy chrome, IE, opera backslash-handling behavior.\n // Back slashes before the query string get converted to forward slashes\n // See: https://github.com/joyent/node/blob/386fd24f49b0e9d1a8a076592a404168faeecc34/lib/url.js#L115-L124\n // See: https://code.google.com/p/chromium/issues/detail?id=25916\n // https://github.com/medialize/URI.js/pull/233\n string = string.replace(/\\\\/g, '/');\n\n // extract host:port\n var pos = string.indexOf('/');\n var bracketPos;\n var t;\n\n if (pos === -1) {\n pos = string.length;\n }\n\n if (string.charAt(0) === '[') {\n // IPv6 host - http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04#section-6\n // I claim most client software breaks on IPv6 anyways. To simplify things, URI only accepts\n // IPv6+port in the format [2001:db8::1]:80 (for the time being)\n bracketPos = string.indexOf(']');\n parts.hostname = string.substring(1, bracketPos) || null;\n parts.port = string.substring(bracketPos + 2, pos) || null;\n if (parts.port === '/') {\n parts.port = null;\n }\n } else {\n var firstColon = string.indexOf(':');\n var firstSlash = string.indexOf('/');\n var nextColon = string.indexOf(':', firstColon + 1);\n if (nextColon !== -1 && (firstSlash === -1 || nextColon < firstSlash)) {\n // IPv6 host contains multiple colons - but no port\n // this notation is actually not allowed by RFC 3986, but we're a liberal parser\n parts.hostname = string.substring(0, pos) || null;\n parts.port = null;\n } else {\n t = string.substring(0, pos).split(':');\n parts.hostname = t[0] || null;\n parts.port = t[1] || null;\n }\n }\n\n if (parts.hostname && string.substring(pos).charAt(0) !== '/') {\n pos++;\n string = '/' + string;\n }\n\n if (parts.preventInvalidHostname) {\n URI.ensureValidHostname(parts.hostname, parts.protocol);\n }\n\n if (parts.port) {\n URI.ensureValidPort(parts.port);\n }\n\n return string.substring(pos) || '/';\n };\n URI.parseAuthority = function(string, parts) {\n string = URI.parseUserinfo(string, parts);\n return URI.parseHost(string, parts);\n };\n URI.parseUserinfo = function(string, parts) {\n // extract username:password\n var _string = string\n var firstBackSlash = string.indexOf('\\\\');\n if (firstBackSlash !== -1) {\n string = string.replace(/\\\\/g, '/')\n }\n var firstSlash = string.indexOf('/');\n var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1);\n var t;\n\n // authority@ must come before /path or \\path\n if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) {\n t = string.substring(0, pos).split(':');\n parts.username = t[0] ? URI.decode(t[0]) : null;\n t.shift();\n parts.password = t[0] ? URI.decode(t.join(':')) : null;\n string = _string.substring(pos + 1);\n } else {\n parts.username = null;\n parts.password = null;\n }\n\n return string;\n };\n URI.parseQuery = function(string, escapeQuerySpace) {\n if (!string) {\n return {};\n }\n\n // throw out the funky business - \"?\"[name\"=\"value\"&\"]+\n string = string.replace(/&+/g, '&').replace(/^\\?*&*|&+$/g, '');\n\n if (!string) {\n return {};\n }\n\n var items = {};\n var splits = string.split('&');\n var length = splits.length;\n var v, name, value;\n\n for (var i = 0; i < length; i++) {\n v = splits[i].split('=');\n name = URI.decodeQuery(v.shift(), escapeQuerySpace);\n // no \"=\" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters\n value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;\n\n if (name === '__proto__') {\n // ignore attempt at exploiting JavaScript internals\n continue;\n } else if (hasOwn.call(items, name)) {\n if (typeof items[name] === 'string' || items[name] === null) {\n items[name] = [items[name]];\n }\n\n items[name].push(value);\n } else {\n items[name] = value;\n }\n }\n\n return items;\n };\n\n URI.build = function(parts) {\n var t = '';\n var requireAbsolutePath = false\n\n if (parts.protocol) {\n t += parts.protocol + ':';\n }\n\n if (!parts.urn && (t || parts.hostname)) {\n t += '//';\n requireAbsolutePath = true\n }\n\n t += (URI.buildAuthority(parts) || '');\n\n if (typeof parts.path === 'string') {\n if (parts.path.charAt(0) !== '/' && requireAbsolutePath) {\n t += '/';\n }\n\n t += parts.path;\n }\n\n if (typeof parts.query === 'string' && parts.query) {\n t += '?' + parts.query;\n }\n\n if (typeof parts.fragment === 'string' && parts.fragment) {\n t += '#' + parts.fragment;\n }\n return t;\n };\n URI.buildHost = function(parts) {\n var t = '';\n\n if (!parts.hostname) {\n return '';\n } else if (URI.ip6_expression.test(parts.hostname)) {\n t += '[' + parts.hostname + ']';\n } else {\n t += parts.hostname;\n }\n\n if (parts.port) {\n t += ':' + parts.port;\n }\n\n return t;\n };\n URI.buildAuthority = function(parts) {\n return URI.buildUserinfo(parts) + URI.buildHost(parts);\n };\n URI.buildUserinfo = function(parts) {\n var t = '';\n\n if (parts.username) {\n t += URI.encode(parts.username);\n }\n\n if (parts.password) {\n t += ':' + URI.encode(parts.password);\n }\n\n if (t) {\n t += '@';\n }\n\n return t;\n };\n URI.buildQuery = function(data, duplicateQueryParameters, escapeQuerySpace) {\n // according to http://tools.ietf.org/html/rfc3986 or http://labs.apache.org/webarch/uri/rfc/rfc3986.html\n // being \u00BB-._~!$&'()*+,;=:@/?\u00AB %HEX and alnum are allowed\n // the RFC explicitly states ?/foo being a valid use case, no mention of parameter syntax!\n // URI.js treats the query string as being application/x-www-form-urlencoded\n // see http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type\n\n var t = '';\n var unique, key, i, length;\n for (key in data) {\n if (key === '__proto__') {\n // ignore attempt at exploiting JavaScript internals\n continue;\n } else if (hasOwn.call(data, key)) {\n if (isArray(data[key])) {\n unique = {};\n for (i = 0, length = data[key].length; i < length; i++) {\n if (data[key][i] !== undefined && unique[data[key][i] + ''] === undefined) {\n t += '&' + URI.buildQueryParameter(key, data[key][i], escapeQuerySpace);\n if (duplicateQueryParameters !== true) {\n unique[data[key][i] + ''] = true;\n }\n }\n }\n } else if (data[key] !== undefined) {\n t += '&' + URI.buildQueryParameter(key, data[key], escapeQuerySpace);\n }\n }\n }\n\n return t.substring(1);\n };\n URI.buildQueryParameter = function(name, value, escapeQuerySpace) {\n // http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type -- application/x-www-form-urlencoded\n // don't append \"=\" for null values, according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#url-parameter-serialization\n return URI.encodeQuery(name, escapeQuerySpace) + (value !== null ? '=' + URI.encodeQuery(value, escapeQuerySpace) : '');\n };\n\n URI.addQuery = function(data, name, value) {\n if (typeof name === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n URI.addQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n if (data[name] === undefined) {\n data[name] = value;\n return;\n } else if (typeof data[name] === 'string') {\n data[name] = [data[name]];\n }\n\n if (!isArray(value)) {\n value = [value];\n }\n\n data[name] = (data[name] || []).concat(value);\n } else {\n throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');\n }\n };\n\n URI.setQuery = function(data, name, value) {\n if (typeof name === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n URI.setQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n data[name] = value === undefined ? null : value;\n } else {\n throw new TypeError('URI.setQuery() accepts an object, string as the name parameter');\n }\n };\n\n URI.removeQuery = function(data, name, value) {\n var i, length, key;\n\n if (isArray(name)) {\n for (i = 0, length = name.length; i < length; i++) {\n data[name[i]] = undefined;\n }\n } else if (getType(name) === 'RegExp') {\n for (key in data) {\n if (name.test(key)) {\n data[key] = undefined;\n }\n }\n } else if (typeof name === 'object') {\n for (key in name) {\n if (hasOwn.call(name, key)) {\n URI.removeQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n if (value !== undefined) {\n if (getType(value) === 'RegExp') {\n if (!isArray(data[name]) && value.test(data[name])) {\n data[name] = undefined;\n } else {\n data[name] = filterArrayValues(data[name], value);\n }\n } else if (data[name] === String(value) && (!isArray(value) || value.length === 1)) {\n data[name] = undefined;\n } else if (isArray(data[name])) {\n data[name] = filterArrayValues(data[name], value);\n }\n } else {\n data[name] = undefined;\n }\n } else {\n throw new TypeError('URI.removeQuery() accepts an object, string, RegExp as the first parameter');\n }\n };\n URI.hasQuery = function(data, name, value, withinArray) {\n switch (getType(name)) {\n case 'String':\n // Nothing to do here\n break;\n\n case 'RegExp':\n for (var key in data) {\n if (hasOwn.call(data, key)) {\n if (name.test(key) && (value === undefined || URI.hasQuery(data, key, value))) {\n return true;\n }\n }\n }\n\n return false;\n\n case 'Object':\n for (var _key in name) {\n if (hasOwn.call(name, _key)) {\n if (!URI.hasQuery(data, _key, name[_key])) {\n return false;\n }\n }\n }\n\n return true;\n\n default:\n throw new TypeError('URI.hasQuery() accepts a string, regular expression or object as the name parameter');\n }\n\n switch (getType(value)) {\n case 'Undefined':\n // true if exists (but may be empty)\n return name in data; // data[name] !== undefined;\n\n case 'Boolean':\n // true if exists and non-empty\n var _booly = Boolean(isArray(data[name]) ? data[name].length : data[name]);\n return value === _booly;\n\n case 'Function':\n // allow complex comparison\n return !!value(data[name], name, data);\n\n case 'Array':\n if (!isArray(data[name])) {\n return false;\n }\n\n var op = withinArray ? arrayContains : arraysEqual;\n return op(data[name], value);\n\n case 'RegExp':\n if (!isArray(data[name])) {\n return Boolean(data[name] && data[name].match(value));\n }\n\n if (!withinArray) {\n return false;\n }\n\n return arrayContains(data[name], value);\n\n case 'Number':\n value = String(value);\n /* falls through */\n case 'String':\n if (!isArray(data[name])) {\n return data[name] === value;\n }\n\n if (!withinArray) {\n return false;\n }\n\n return arrayContains(data[name], value);\n\n default:\n throw new TypeError('URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter');\n }\n };\n\n\n URI.joinPaths = function() {\n var input = [];\n var segments = [];\n var nonEmptySegments = 0;\n\n for (var i = 0; i < arguments.length; i++) {\n var url = new URI(arguments[i]);\n input.push(url);\n var _segments = url.segment();\n for (var s = 0; s < _segments.length; s++) {\n if (typeof _segments[s] === 'string') {\n segments.push(_segments[s]);\n }\n\n if (_segments[s]) {\n nonEmptySegments++;\n }\n }\n }\n\n if (!segments.length || !nonEmptySegments) {\n return new URI('');\n }\n\n var uri = new URI('').segment(segments);\n\n if (input[0].path() === '' || input[0].path().slice(0, 1) === '/') {\n uri.path('/' + uri.path());\n }\n\n return uri.normalize();\n };\n\n URI.commonPath = function(one, two) {\n var length = Math.min(one.length, two.length);\n var pos;\n\n // find first non-matching character\n for (pos = 0; pos < length; pos++) {\n if (one.charAt(pos) !== two.charAt(pos)) {\n pos--;\n break;\n }\n }\n\n if (pos < 1) {\n return one.charAt(0) === two.charAt(0) && one.charAt(0) === '/' ? '/' : '';\n }\n\n // revert to last /\n if (one.charAt(pos) !== '/' || two.charAt(pos) !== '/') {\n pos = one.substring(0, pos).lastIndexOf('/');\n }\n\n return one.substring(0, pos + 1);\n };\n\n URI.withinString = function(string, callback, options) {\n options || (options = {});\n var _start = options.start || URI.findUri.start;\n var _end = options.end || URI.findUri.end;\n var _trim = options.trim || URI.findUri.trim;\n var _parens = options.parens || URI.findUri.parens;\n var _attributeOpen = /[a-z0-9-]=[\"']?$/i;\n\n _start.lastIndex = 0;\n while (true) {\n var match = _start.exec(string);\n if (!match) {\n break;\n }\n\n var start = match.index;\n if (options.ignoreHtml) {\n // attribut(e=[\"']?$)\n var attributeOpen = string.slice(Math.max(start - 3, 0), start);\n if (attributeOpen && _attributeOpen.test(attributeOpen)) {\n continue;\n }\n }\n\n var end = start + string.slice(start).search(_end);\n var slice = string.slice(start, end);\n // make sure we include well balanced parens\n var parensEnd = -1;\n while (true) {\n var parensMatch = _parens.exec(slice);\n if (!parensMatch) {\n break;\n }\n\n var parensMatchEnd = parensMatch.index + parensMatch[0].length;\n parensEnd = Math.max(parensEnd, parensMatchEnd);\n }\n\n if (parensEnd > -1) {\n slice = slice.slice(0, parensEnd) + slice.slice(parensEnd).replace(_trim, '');\n } else {\n slice = slice.replace(_trim, '');\n }\n\n if (slice.length <= match[0].length) {\n // the extract only contains the starting marker of a URI,\n // e.g. \"www\" or \"http://\"\n continue;\n }\n\n if (options.ignore && options.ignore.test(slice)) {\n continue;\n }\n\n end = start + slice.length;\n var result = callback(slice, start, end, string);\n if (result === undefined) {\n _start.lastIndex = end;\n continue;\n }\n\n result = String(result);\n string = string.slice(0, start) + result + string.slice(end);\n _start.lastIndex = start + result.length;\n }\n\n _start.lastIndex = 0;\n return string;\n };\n\n URI.ensureValidHostname = function(v, protocol) {\n // Theoretically URIs allow percent-encoding in Hostnames (according to RFC 3986)\n // they are not part of DNS and therefore ignored by URI.js\n\n var hasHostname = !!v; // not null and not an empty string\n var hasProtocol = !!protocol;\n var rejectEmptyHostname = false;\n\n if (hasProtocol) {\n rejectEmptyHostname = arrayContains(URI.hostProtocols, protocol);\n }\n\n if (rejectEmptyHostname && !hasHostname) {\n throw new TypeError('Hostname cannot be empty, if protocol is ' + protocol);\n } else if (v && v.match(URI.invalid_hostname_characters)) {\n // test punycode\n if (!punycode) {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available');\n }\n if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-:_]');\n }\n }\n };\n\n URI.ensureValidPort = function (v) {\n if (!v) {\n return;\n }\n\n var port = Number(v);\n if (isInteger(port) && (port > 0) && (port < 65536)) {\n return;\n }\n\n throw new TypeError('Port \"' + v + '\" is not a valid port');\n };\n\n // noConflict\n URI.noConflict = function(removeAll) {\n if (removeAll) {\n var unconflicted = {\n URI: this.noConflict()\n };\n\n if (root.URITemplate && typeof root.URITemplate.noConflict === 'function') {\n unconflicted.URITemplate = root.URITemplate.noConflict();\n }\n\n if (root.IPv6 && typeof root.IPv6.noConflict === 'function') {\n unconflicted.IPv6 = root.IPv6.noConflict();\n }\n\n if (root.SecondLevelDomains && typeof root.SecondLevelDomains.noConflict === 'function') {\n unconflicted.SecondLevelDomains = root.SecondLevelDomains.noConflict();\n }\n\n return unconflicted;\n } else if (root.URI === this) {\n root.URI = _URI;\n }\n\n return this;\n };\n\n p.build = function(deferBuild) {\n if (deferBuild === true) {\n this._deferred_build = true;\n } else if (deferBuild === undefined || this._deferred_build) {\n this._string = URI.build(this._parts);\n this._deferred_build = false;\n }\n\n return this;\n };\n\n p.clone = function() {\n return new URI(this);\n };\n\n p.valueOf = p.toString = function() {\n return this.build(false)._string;\n };\n\n\n function generateSimpleAccessor(_part){\n return function(v, build) {\n if (v === undefined) {\n return this._parts[_part] || '';\n } else {\n this._parts[_part] = v || null;\n this.build(!build);\n return this;\n }\n };\n }\n\n function generatePrefixAccessor(_part, _key){\n return function(v, build) {\n if (v === undefined) {\n return this._parts[_part] || '';\n } else {\n if (v !== null) {\n v = v + '';\n if (v.charAt(0) === _key) {\n v = v.substring(1);\n }\n }\n\n this._parts[_part] = v;\n this.build(!build);\n return this;\n }\n };\n }\n\n p.protocol = generateSimpleAccessor('protocol');\n p.username = generateSimpleAccessor('username');\n p.password = generateSimpleAccessor('password');\n p.hostname = generateSimpleAccessor('hostname');\n p.port = generateSimpleAccessor('port');\n p.query = generatePrefixAccessor('query', '?');\n p.fragment = generatePrefixAccessor('fragment', '#');\n\n p.search = function(v, build) {\n var t = this.query(v, build);\n return typeof t === 'string' && t.length ? ('?' + t) : t;\n };\n p.hash = function(v, build) {\n var t = this.fragment(v, build);\n return typeof t === 'string' && t.length ? ('#' + t) : t;\n };\n\n p.pathname = function(v, build) {\n if (v === undefined || v === true) {\n var res = this._parts.path || (this._parts.hostname ? '/' : '');\n return v ? (this._parts.urn ? URI.decodeUrnPath : URI.decodePath)(res) : res;\n } else {\n if (this._parts.urn) {\n this._parts.path = v ? URI.recodeUrnPath(v) : '';\n } else {\n this._parts.path = v ? URI.recodePath(v) : '/';\n }\n this.build(!build);\n return this;\n }\n };\n p.path = p.pathname;\n p.href = function(href, build) {\n var key;\n\n if (href === undefined) {\n return this.toString();\n }\n\n this._string = '';\n this._parts = URI._parts();\n\n var _URI = href instanceof URI;\n var _object = typeof href === 'object' && (href.hostname || href.path || href.pathname);\n if (href.nodeName) {\n var attribute = URI.getDomAttribute(href);\n href = href[attribute] || '';\n _object = false;\n }\n\n // window.location is reported to be an object, but it's not the sort\n // of object we're looking for:\n // * location.protocol ends with a colon\n // * location.query != object.search\n // * location.hash != object.fragment\n // simply serializing the unknown object should do the trick\n // (for location, not for everything...)\n if (!_URI && _object && href.pathname !== undefined) {\n href = href.toString();\n }\n\n if (typeof href === 'string' || href instanceof String) {\n this._parts = URI.parse(String(href), this._parts);\n } else if (_URI || _object) {\n var src = _URI ? href._parts : href;\n for (key in src) {\n if (key === 'query') { continue; }\n if (hasOwn.call(this._parts, key)) {\n this._parts[key] = src[key];\n }\n }\n if (src.query) {\n this.query(src.query, false);\n }\n } else {\n throw new TypeError('invalid input');\n }\n\n this.build(!build);\n return this;\n };\n\n // identification accessors\n p.is = function(what) {\n var ip = false;\n var ip4 = false;\n var ip6 = false;\n var name = false;\n var sld = false;\n var idn = false;\n var punycode = false;\n var relative = !this._parts.urn;\n\n if (this._parts.hostname) {\n relative = false;\n ip4 = URI.ip4_expression.test(this._parts.hostname);\n ip6 = URI.ip6_expression.test(this._parts.hostname);\n ip = ip4 || ip6;\n name = !ip;\n sld = name && SLD && SLD.has(this._parts.hostname);\n idn = name && URI.idn_expression.test(this._parts.hostname);\n punycode = name && URI.punycode_expression.test(this._parts.hostname);\n }\n\n switch (what.toLowerCase()) {\n case 'relative':\n return relative;\n\n case 'absolute':\n return !relative;\n\n // hostname identification\n case 'domain':\n case 'name':\n return name;\n\n case 'sld':\n return sld;\n\n case 'ip':\n return ip;\n\n case 'ip4':\n case 'ipv4':\n case 'inet4':\n return ip4;\n\n case 'ip6':\n case 'ipv6':\n case 'inet6':\n return ip6;\n\n case 'idn':\n return idn;\n\n case 'url':\n return !this._parts.urn;\n\n case 'urn':\n return !!this._parts.urn;\n\n case 'punycode':\n return punycode;\n }\n\n return null;\n };\n\n // component specific input validation\n var _protocol = p.protocol;\n var _port = p.port;\n var _hostname = p.hostname;\n\n p.protocol = function(v, build) {\n if (v) {\n // accept trailing ://\n v = v.replace(/:(\\/\\/)?$/, '');\n\n if (!v.match(URI.protocol_expression)) {\n throw new TypeError('Protocol \"' + v + '\" contains characters other than [A-Z0-9.+-] or doesn\\'t start with [A-Z]');\n }\n }\n\n return _protocol.call(this, v, build);\n };\n p.scheme = p.protocol;\n p.port = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v !== undefined) {\n if (v === 0) {\n v = null;\n }\n\n if (v) {\n v += '';\n if (v.charAt(0) === ':') {\n v = v.substring(1);\n }\n\n URI.ensureValidPort(v);\n }\n }\n return _port.call(this, v, build);\n };\n p.hostname = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v !== undefined) {\n var x = { preventInvalidHostname: this._parts.preventInvalidHostname };\n var res = URI.parseHost(v, x);\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n v = x.hostname;\n if (this._parts.preventInvalidHostname) {\n URI.ensureValidHostname(v, this._parts.protocol);\n }\n }\n\n return _hostname.call(this, v, build);\n };\n\n // compound accessors\n p.origin = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n var protocol = this.protocol();\n var authority = this.authority();\n if (!authority) {\n return '';\n }\n\n return (protocol ? protocol + '://' : '') + this.authority();\n } else {\n var origin = URI(v);\n this\n .protocol(origin.protocol())\n .authority(origin.authority())\n .build(!build);\n return this;\n }\n };\n p.host = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n return this._parts.hostname ? URI.buildHost(this._parts) : '';\n } else {\n var res = URI.parseHost(v, this._parts);\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n this.build(!build);\n return this;\n }\n };\n p.authority = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n return this._parts.hostname ? URI.buildAuthority(this._parts) : '';\n } else {\n var res = URI.parseAuthority(v, this._parts);\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n this.build(!build);\n return this;\n }\n };\n p.userinfo = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n var t = URI.buildUserinfo(this._parts);\n return t ? t.substring(0, t.length -1) : t;\n } else {\n if (v[v.length-1] !== '@') {\n v += '@';\n }\n\n URI.parseUserinfo(v, this._parts);\n this.build(!build);\n return this;\n }\n };\n p.resource = function(v, build) {\n var parts;\n\n if (v === undefined) {\n return this.path() + this.search() + this.hash();\n }\n\n parts = URI.parse(v);\n this._parts.path = parts.path;\n this._parts.query = parts.query;\n this._parts.fragment = parts.fragment;\n this.build(!build);\n return this;\n };\n\n // fraction accessors\n p.subdomain = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n // convenience, return \"www\" from \"www.example.org\"\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n }\n\n // grab domain and add another segment\n var end = this._parts.hostname.length - this.domain().length - 1;\n return this._parts.hostname.substring(0, end) || '';\n } else {\n var e = this._parts.hostname.length - this.domain().length;\n var sub = this._parts.hostname.substring(0, e);\n var replace = new RegExp('^' + escapeRegEx(sub));\n\n if (v && v.charAt(v.length - 1) !== '.') {\n v += '.';\n }\n\n if (v.indexOf(':') !== -1) {\n throw new TypeError('Domains cannot contain colons');\n }\n\n if (v) {\n URI.ensureValidHostname(v, this._parts.protocol);\n }\n\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n this.build(!build);\n return this;\n }\n };\n p.domain = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v === 'boolean') {\n build = v;\n v = undefined;\n }\n\n // convenience, return \"example.org\" from \"www.example.org\"\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n }\n\n // if hostname consists of 1 or 2 segments, it must be the domain\n var t = this._parts.hostname.match(/\\./g);\n if (t && t.length < 2) {\n return this._parts.hostname;\n }\n\n // grab tld and add another segment\n var end = this._parts.hostname.length - this.tld(build).length - 1;\n end = this._parts.hostname.lastIndexOf('.', end -1) + 1;\n return this._parts.hostname.substring(end) || '';\n } else {\n if (!v) {\n throw new TypeError('cannot set domain empty');\n }\n\n if (v.indexOf(':') !== -1) {\n throw new TypeError('Domains cannot contain colons');\n }\n\n URI.ensureValidHostname(v, this._parts.protocol);\n\n if (!this._parts.hostname || this.is('IP')) {\n this._parts.hostname = v;\n } else {\n var replace = new RegExp(escapeRegEx(this.domain()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n p.tld = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v === 'boolean') {\n build = v;\n v = undefined;\n }\n\n // return \"org\" from \"www.example.org\"\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n }\n\n var pos = this._parts.hostname.lastIndexOf('.');\n var tld = this._parts.hostname.substring(pos + 1);\n\n if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {\n return SLD.get(this._parts.hostname) || tld;\n }\n\n return tld;\n } else {\n var replace;\n\n if (!v) {\n throw new TypeError('cannot set TLD empty');\n } else if (v.match(/[^a-zA-Z0-9-]/)) {\n if (SLD && SLD.is(v)) {\n replace = new RegExp(escapeRegEx(this.tld()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n } else {\n throw new TypeError('TLD \"' + v + '\" contains characters other than [A-Z0-9]');\n }\n } else if (!this._parts.hostname || this.is('IP')) {\n throw new ReferenceError('cannot set TLD on non-domain host');\n } else {\n replace = new RegExp(escapeRegEx(this.tld()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n p.directory = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined || v === true) {\n if (!this._parts.path && !this._parts.hostname) {\n return '';\n }\n\n if (this._parts.path === '/') {\n return '/';\n }\n\n var end = this._parts.path.length - this.filename().length - 1;\n var res = this._parts.path.substring(0, end) || (this._parts.hostname ? '/' : '');\n\n return v ? URI.decodePath(res) : res;\n\n } else {\n var e = this._parts.path.length - this.filename().length;\n var directory = this._parts.path.substring(0, e);\n var replace = new RegExp('^' + escapeRegEx(directory));\n\n // fully qualifier directories begin with a slash\n if (!this.is('relative')) {\n if (!v) {\n v = '/';\n }\n\n if (v.charAt(0) !== '/') {\n v = '/' + v;\n }\n }\n\n // directories always end with a slash\n if (v && v.charAt(v.length - 1) !== '/') {\n v += '/';\n }\n\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n this.build(!build);\n return this;\n }\n };\n p.filename = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v !== 'string') {\n if (!this._parts.path || this._parts.path === '/') {\n return '';\n }\n\n var pos = this._parts.path.lastIndexOf('/');\n var res = this._parts.path.substring(pos+1);\n\n return v ? URI.decodePathSegment(res) : res;\n } else {\n var mutatedDirectory = false;\n\n if (v.charAt(0) === '/') {\n v = v.substring(1);\n }\n\n if (v.match(/\\.?\\//)) {\n mutatedDirectory = true;\n }\n\n var replace = new RegExp(escapeRegEx(this.filename()) + '$');\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n\n if (mutatedDirectory) {\n this.normalizePath(build);\n } else {\n this.build(!build);\n }\n\n return this;\n }\n };\n p.suffix = function(v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined || v === true) {\n if (!this._parts.path || this._parts.path === '/') {\n return '';\n }\n\n var filename = this.filename();\n var pos = filename.lastIndexOf('.');\n var s, res;\n\n if (pos === -1) {\n return '';\n }\n\n // suffix may only contain alnum characters (yup, I made this up.)\n s = filename.substring(pos+1);\n res = (/^[a-z0-9%]+$/i).test(s) ? s : '';\n return v ? URI.decodePathSegment(res) : res;\n } else {\n if (v.charAt(0) === '.') {\n v = v.substring(1);\n }\n\n var suffix = this.suffix();\n var replace;\n\n if (!suffix) {\n if (!v) {\n return this;\n }\n\n this._parts.path += '.' + URI.recodePath(v);\n } else if (!v) {\n replace = new RegExp(escapeRegEx('.' + suffix) + '$');\n } else {\n replace = new RegExp(escapeRegEx(suffix) + '$');\n }\n\n if (replace) {\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n p.segment = function(segment, v, build) {\n var separator = this._parts.urn ? ':' : '/';\n var path = this.path();\n var absolute = path.substring(0, 1) === '/';\n var segments = path.split(separator);\n\n if (segment !== undefined && typeof segment !== 'number') {\n build = v;\n v = segment;\n segment = undefined;\n }\n\n if (segment !== undefined && typeof segment !== 'number') {\n throw new Error('Bad segment \"' + segment + '\", must be 0-based integer');\n }\n\n if (absolute) {\n segments.shift();\n }\n\n if (segment < 0) {\n // allow negative indexes to address from the end\n segment = Math.max(segments.length + segment, 0);\n }\n\n if (v === undefined) {\n /*jshint laxbreak: true */\n return segment === undefined\n ? segments\n : segments[segment];\n /*jshint laxbreak: false */\n } else if (segment === null || segments[segment] === undefined) {\n if (isArray(v)) {\n segments = [];\n // collapse empty elements within array\n for (var i=0, l=v.length; i < l; i++) {\n if (!v[i].length && (!segments.length || !segments[segments.length -1].length)) {\n continue;\n }\n\n if (segments.length && !segments[segments.length -1].length) {\n segments.pop();\n }\n\n segments.push(trimSlashes(v[i]));\n }\n } else if (v || typeof v === 'string') {\n v = trimSlashes(v);\n if (segments[segments.length -1] === '') {\n // empty trailing elements have to be overwritten\n // to prevent results such as /foo//bar\n segments[segments.length -1] = v;\n } else {\n segments.push(v);\n }\n }\n } else {\n if (v) {\n segments[segment] = trimSlashes(v);\n } else {\n segments.splice(segment, 1);\n }\n }\n\n if (absolute) {\n segments.unshift('');\n }\n\n return this.path(segments.join(separator), build);\n };\n p.segmentCoded = function(segment, v, build) {\n var segments, i, l;\n\n if (typeof segment !== 'number') {\n build = v;\n v = segment;\n segment = undefined;\n }\n\n if (v === undefined) {\n segments = this.segment(segment, v, build);\n if (!isArray(segments)) {\n segments = segments !== undefined ? URI.decode(segments) : undefined;\n } else {\n for (i = 0, l = segments.length; i < l; i++) {\n segments[i] = URI.decode(segments[i]);\n }\n }\n\n return segments;\n }\n\n if (!isArray(v)) {\n v = (typeof v === 'string' || v instanceof String) ? URI.encode(v) : v;\n } else {\n for (i = 0, l = v.length; i < l; i++) {\n v[i] = URI.encode(v[i]);\n }\n }\n\n return this.segment(segment, v, build);\n };\n\n // mutating query string\n var q = p.query;\n p.query = function(v, build) {\n if (v === true) {\n return URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n } else if (typeof v === 'function') {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n var result = v.call(this, data);\n this._parts.query = URI.buildQuery(result || data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n this.build(!build);\n return this;\n } else if (v !== undefined && typeof v !== 'string') {\n this._parts.query = URI.buildQuery(v, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n this.build(!build);\n return this;\n } else {\n return q.call(this, v, build);\n }\n };\n p.setQuery = function(name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n\n if (typeof name === 'string' || name instanceof String) {\n data[name] = value !== undefined ? value : null;\n } else if (typeof name === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n data[key] = name[key];\n }\n }\n } else {\n throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');\n }\n\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n p.addQuery = function(name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n URI.addQuery(data, name, value === undefined ? null : value);\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n p.removeQuery = function(name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n URI.removeQuery(data, name, value);\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n p.hasQuery = function(name, value, withinArray) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n return URI.hasQuery(data, name, value, withinArray);\n };\n p.setSearch = p.setQuery;\n p.addSearch = p.addQuery;\n p.removeSearch = p.removeQuery;\n p.hasSearch = p.hasQuery;\n\n // sanitizing URLs\n p.normalize = function() {\n if (this._parts.urn) {\n return this\n .normalizeProtocol(false)\n .normalizePath(false)\n .normalizeQuery(false)\n .normalizeFragment(false)\n .build();\n }\n\n return this\n .normalizeProtocol(false)\n .normalizeHostname(false)\n .normalizePort(false)\n .normalizePath(false)\n .normalizeQuery(false)\n .normalizeFragment(false)\n .build();\n };\n p.normalizeProtocol = function(build) {\n if (typeof this._parts.protocol === 'string') {\n this._parts.protocol = this._parts.protocol.toLowerCase();\n this.build(!build);\n }\n\n return this;\n };\n p.normalizeHostname = function(build) {\n if (this._parts.hostname) {\n if (this.is('IDN') && punycode) {\n this._parts.hostname = punycode.toASCII(this._parts.hostname);\n } else if (this.is('IPv6') && IPv6) {\n this._parts.hostname = IPv6.best(this._parts.hostname);\n }\n\n this._parts.hostname = this._parts.hostname.toLowerCase();\n this.build(!build);\n }\n\n return this;\n };\n p.normalizePort = function(build) {\n // remove port of it's the protocol's default\n if (typeof this._parts.protocol === 'string' && this._parts.port === URI.defaultPorts[this._parts.protocol]) {\n this._parts.port = null;\n this.build(!build);\n }\n\n return this;\n };\n p.normalizePath = function(build) {\n var _path = this._parts.path;\n if (!_path) {\n return this;\n }\n\n if (this._parts.urn) {\n this._parts.path = URI.recodeUrnPath(this._parts.path);\n this.build(!build);\n return this;\n }\n\n if (this._parts.path === '/') {\n return this;\n }\n\n _path = URI.recodePath(_path);\n\n var _was_relative;\n var _leadingParents = '';\n var _parent, _pos;\n\n // handle relative paths\n if (_path.charAt(0) !== '/') {\n _was_relative = true;\n _path = '/' + _path;\n }\n\n // handle relative files (as opposed to directories)\n if (_path.slice(-3) === '/..' || _path.slice(-2) === '/.') {\n _path += '/';\n }\n\n // resolve simples\n _path = _path\n .replace(/(\\/(\\.\\/)+)|(\\/\\.$)/g, '/')\n .replace(/\\/{2,}/g, '/');\n\n // remember leading parents\n if (_was_relative) {\n _leadingParents = _path.substring(1).match(/^(\\.\\.\\/)+/) || '';\n if (_leadingParents) {\n _leadingParents = _leadingParents[0];\n }\n }\n\n // resolve parents\n while (true) {\n _parent = _path.search(/\\/\\.\\.(\\/|$)/);\n if (_parent === -1) {\n // no more ../ to resolve\n break;\n } else if (_parent === 0) {\n // top level cannot be relative, skip it\n _path = _path.substring(3);\n continue;\n }\n\n _pos = _path.substring(0, _parent).lastIndexOf('/');\n if (_pos === -1) {\n _pos = _parent;\n }\n _path = _path.substring(0, _pos) + _path.substring(_parent + 3);\n }\n\n // revert to relative\n if (_was_relative && this.is('relative')) {\n _path = _leadingParents + _path.substring(1);\n }\n\n this._parts.path = _path;\n this.build(!build);\n return this;\n };\n p.normalizePathname = p.normalizePath;\n p.normalizeQuery = function(build) {\n if (typeof this._parts.query === 'string') {\n if (!this._parts.query.length) {\n this._parts.query = null;\n } else {\n this.query(URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace));\n }\n\n this.build(!build);\n }\n\n return this;\n };\n p.normalizeFragment = function(build) {\n if (!this._parts.fragment) {\n this._parts.fragment = null;\n this.build(!build);\n }\n\n return this;\n };\n p.normalizeSearch = p.normalizeQuery;\n p.normalizeHash = p.normalizeFragment;\n\n p.iso8859 = function() {\n // expect unicode input, iso8859 output\n var e = URI.encode;\n var d = URI.decode;\n\n URI.encode = escape;\n URI.decode = decodeURIComponent;\n try {\n this.normalize();\n } finally {\n URI.encode = e;\n URI.decode = d;\n }\n return this;\n };\n\n p.unicode = function() {\n // expect iso8859 input, unicode output\n var e = URI.encode;\n var d = URI.decode;\n\n URI.encode = strictEncodeURIComponent;\n URI.decode = unescape;\n try {\n this.normalize();\n } finally {\n URI.encode = e;\n URI.decode = d;\n }\n return this;\n };\n\n p.readable = function() {\n var uri = this.clone();\n // removing username, password, because they shouldn't be displayed according to RFC 3986\n uri.username('').password('').normalize();\n var t = '';\n if (uri._parts.protocol) {\n t += uri._parts.protocol + '://';\n }\n\n if (uri._parts.hostname) {\n if (uri.is('punycode') && punycode) {\n t += punycode.toUnicode(uri._parts.hostname);\n if (uri._parts.port) {\n t += ':' + uri._parts.port;\n }\n } else {\n t += uri.host();\n }\n }\n\n if (uri._parts.hostname && uri._parts.path && uri._parts.path.charAt(0) !== '/') {\n t += '/';\n }\n\n t += uri.path(true);\n if (uri._parts.query) {\n var q = '';\n for (var i = 0, qp = uri._parts.query.split('&'), l = qp.length; i < l; i++) {\n var kv = (qp[i] || '').split('=');\n q += '&' + URI.decodeQuery(kv[0], this._parts.escapeQuerySpace)\n .replace(/&/g, '%26');\n\n if (kv[1] !== undefined) {\n q += '=' + URI.decodeQuery(kv[1], this._parts.escapeQuerySpace)\n .replace(/&/g, '%26');\n }\n }\n t += '?' + q.substring(1);\n }\n\n t += URI.decodeQuery(uri.hash(), true);\n return t;\n };\n\n // resolving relative and absolute URLs\n p.absoluteTo = function(base) {\n var resolved = this.clone();\n var properties = ['protocol', 'username', 'password', 'hostname', 'port'];\n var basedir, i, p;\n\n if (this._parts.urn) {\n throw new Error('URNs do not have any generally defined hierarchical components');\n }\n\n if (!(base instanceof URI)) {\n base = new URI(base);\n }\n\n if (resolved._parts.protocol) {\n // Directly returns even if this._parts.hostname is empty.\n return resolved;\n } else {\n resolved._parts.protocol = base._parts.protocol;\n }\n\n if (this._parts.hostname) {\n return resolved;\n }\n\n for (i = 0; (p = properties[i]); i++) {\n resolved._parts[p] = base._parts[p];\n }\n\n if (!resolved._parts.path) {\n resolved._parts.path = base._parts.path;\n if (!resolved._parts.query) {\n resolved._parts.query = base._parts.query;\n }\n } else {\n if (resolved._parts.path.substring(-2) === '..') {\n resolved._parts.path += '/';\n }\n\n if (resolved.path().charAt(0) !== '/') {\n basedir = base.directory();\n basedir = basedir ? basedir : base.path().indexOf('/') === 0 ? '/' : '';\n resolved._parts.path = (basedir ? (basedir + '/') : '') + resolved._parts.path;\n resolved.normalizePath();\n }\n }\n\n resolved.build();\n return resolved;\n };\n p.relativeTo = function(base) {\n var relative = this.clone().normalize();\n var relativeParts, baseParts, common, relativePath, basePath;\n\n if (relative._parts.urn) {\n throw new Error('URNs do not have any generally defined hierarchical components');\n }\n\n base = new URI(base).normalize();\n relativeParts = relative._parts;\n baseParts = base._parts;\n relativePath = relative.path();\n basePath = base.path();\n\n if (relativePath.charAt(0) !== '/') {\n throw new Error('URI is already relative');\n }\n\n if (basePath.charAt(0) !== '/') {\n throw new Error('Cannot calculate a URI relative to another relative URI');\n }\n\n if (relativeParts.protocol === baseParts.protocol) {\n relativeParts.protocol = null;\n }\n\n if (relativeParts.username !== baseParts.username || relativeParts.password !== baseParts.password) {\n return relative.build();\n }\n\n if (relativeParts.protocol !== null || relativeParts.username !== null || relativeParts.password !== null) {\n return relative.build();\n }\n\n if (relativeParts.hostname === baseParts.hostname && relativeParts.port === baseParts.port) {\n relativeParts.hostname = null;\n relativeParts.port = null;\n } else {\n return relative.build();\n }\n\n if (relativePath === basePath) {\n relativeParts.path = '';\n return relative.build();\n }\n\n // determine common sub path\n common = URI.commonPath(relativePath, basePath);\n\n // If the paths have nothing in common, return a relative URL with the absolute path.\n if (!common) {\n return relative.build();\n }\n\n var parents = baseParts.path\n .substring(common.length)\n .replace(/[^\\/]*$/, '')\n .replace(/.*?\\//g, '../');\n\n relativeParts.path = (parents + relativeParts.path.substring(common.length)) || './';\n\n return relative.build();\n };\n\n // comparing URIs\n p.equals = function(uri) {\n var one = this.clone();\n var two = new URI(uri);\n var one_map = {};\n var two_map = {};\n var checked = {};\n var one_query, two_query, key;\n\n one.normalize();\n two.normalize();\n\n // exact match\n if (one.toString() === two.toString()) {\n return true;\n }\n\n // extract query string\n one_query = one.query();\n two_query = two.query();\n one.query('');\n two.query('');\n\n // definitely not equal if not even non-query parts match\n if (one.toString() !== two.toString()) {\n return false;\n }\n\n // query parameters have the same length, even if they're permuted\n if (one_query.length !== two_query.length) {\n return false;\n }\n\n one_map = URI.parseQuery(one_query, this._parts.escapeQuerySpace);\n two_map = URI.parseQuery(two_query, this._parts.escapeQuerySpace);\n\n for (key in one_map) {\n if (hasOwn.call(one_map, key)) {\n if (!isArray(one_map[key])) {\n if (one_map[key] !== two_map[key]) {\n return false;\n }\n } else if (!arraysEqual(one_map[key], two_map[key])) {\n return false;\n }\n\n checked[key] = true;\n }\n }\n\n for (key in two_map) {\n if (hasOwn.call(two_map, key)) {\n if (!checked[key]) {\n // two contains a parameter not present in one\n return false;\n }\n }\n }\n\n return true;\n };\n\n // state\n p.preventInvalidHostname = function(v) {\n this._parts.preventInvalidHostname = !!v;\n return this;\n };\n\n p.duplicateQueryParameters = function(v) {\n this._parts.duplicateQueryParameters = !!v;\n return this;\n };\n\n p.escapeQuerySpace = function(v) {\n this._parts.escapeQuerySpace = !!v;\n return this;\n };\n\n return URI;\n}));\n", "const {\n entries,\n setPrototypeOf,\n isFrozen,\n getPrototypeOf,\n getOwnPropertyDescriptor,\n} = Object;\n\nlet { freeze, seal, create } = Object; // eslint-disable-line import/no-mutable-exports\nlet { apply, construct } = typeof Reflect !== 'undefined' && Reflect;\n\nif (!apply) {\n apply = function (fun, thisValue, args) {\n return fun.apply(thisValue, args);\n };\n}\n\nif (!freeze) {\n freeze = function (x) {\n return x;\n };\n}\n\nif (!seal) {\n seal = function (x) {\n return x;\n };\n}\n\nif (!construct) {\n construct = function (Func, args) {\n return new Func(...args);\n };\n}\n\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayIndexOf = unapply(Array.prototype.indexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySlice = unapply(Array.prototype.slice);\n\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\n\nconst regExpTest = unapply(RegExp.prototype.test);\n\nconst typeErrorCreate = unconstruct(TypeError);\n\nexport function unapply(func) {\n return (thisArg, ...args) => apply(func, thisArg, args);\n}\n\nexport function unconstruct(func) {\n return (...args) => construct(func, args);\n}\n\n/* Add properties to a lookup table */\nexport function addToSet(set, array, transformCaseFunc) {\n transformCaseFunc = transformCaseFunc ?? stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n\n element = lcElement;\n }\n }\n\n set[element] = true;\n }\n\n return set;\n}\n\n/* Shallow clone an object */\nexport function clone(object) {\n const newObject = create(null);\n\n for (const [property, value] of entries(object)) {\n newObject[property] = value;\n }\n\n return newObject;\n}\n\n/* This method automatically checks if the prop is function\n * or getter and behaves accordingly. */\nfunction lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n\n object = getPrototypeOf(object);\n }\n\n function fallbackValue(element) {\n console.warn('fallback value for', element);\n return null;\n }\n\n return fallbackValue;\n}\n\nexport {\n // Array\n arrayForEach,\n arrayIndexOf,\n arrayPop,\n arrayPush,\n arraySlice,\n // Object\n entries,\n freeze,\n getPrototypeOf,\n getOwnPropertyDescriptor,\n isFrozen,\n setPrototypeOf,\n seal,\n // RegExp\n regExpTest,\n // String\n stringIndexOf,\n stringMatch,\n stringReplace,\n stringToLowerCase,\n stringToString,\n stringTrim,\n // Errors\n typeErrorCreate,\n // Other\n lookupGetter,\n};\n", "import { freeze } from './utils.js';\n\nexport const html = freeze([\n 'a',\n 'abbr',\n 'acronym',\n 'address',\n 'area',\n 'article',\n 'aside',\n 'audio',\n 'b',\n 'bdi',\n 'bdo',\n 'big',\n 'blink',\n 'blockquote',\n 'body',\n 'br',\n 'button',\n 'canvas',\n 'caption',\n 'center',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'content',\n 'data',\n 'datalist',\n 'dd',\n 'decorator',\n 'del',\n 'details',\n 'dfn',\n 'dialog',\n 'dir',\n 'div',\n 'dl',\n 'dt',\n 'element',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'font',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'head',\n 'header',\n 'hgroup',\n 'hr',\n 'html',\n 'i',\n 'img',\n 'input',\n 'ins',\n 'kbd',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'map',\n 'mark',\n 'marquee',\n 'menu',\n 'menuitem',\n 'meter',\n 'nav',\n 'nobr',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'picture',\n 'pre',\n 'progress',\n 'q',\n 'rp',\n 'rt',\n 'ruby',\n 's',\n 'samp',\n 'section',\n 'select',\n 'shadow',\n 'small',\n 'source',\n 'spacer',\n 'span',\n 'strike',\n 'strong',\n 'style',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'template',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'track',\n 'tt',\n 'u',\n 'ul',\n 'var',\n 'video',\n 'wbr',\n]);\n\n// SVG\nexport const svg = freeze([\n 'svg',\n 'a',\n 'altglyph',\n 'altglyphdef',\n 'altglyphitem',\n 'animatecolor',\n 'animatemotion',\n 'animatetransform',\n 'circle',\n 'clippath',\n 'defs',\n 'desc',\n 'ellipse',\n 'filter',\n 'font',\n 'g',\n 'glyph',\n 'glyphref',\n 'hkern',\n 'image',\n 'line',\n 'lineargradient',\n 'marker',\n 'mask',\n 'metadata',\n 'mpath',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialgradient',\n 'rect',\n 'stop',\n 'style',\n 'switch',\n 'symbol',\n 'text',\n 'textpath',\n 'title',\n 'tref',\n 'tspan',\n 'view',\n 'vkern',\n]);\n\nexport const svgFilters = freeze([\n 'feBlend',\n 'feColorMatrix',\n 'feComponentTransfer',\n 'feComposite',\n 'feConvolveMatrix',\n 'feDiffuseLighting',\n 'feDisplacementMap',\n 'feDistantLight',\n 'feDropShadow',\n 'feFlood',\n 'feFuncA',\n 'feFuncB',\n 'feFuncG',\n 'feFuncR',\n 'feGaussianBlur',\n 'feImage',\n 'feMerge',\n 'feMergeNode',\n 'feMorphology',\n 'feOffset',\n 'fePointLight',\n 'feSpecularLighting',\n 'feSpotLight',\n 'feTile',\n 'feTurbulence',\n]);\n\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nexport const svgDisallowed = freeze([\n 'animate',\n 'color-profile',\n 'cursor',\n 'discard',\n 'font-face',\n 'font-face-format',\n 'font-face-name',\n 'font-face-src',\n 'font-face-uri',\n 'foreignobject',\n 'hatch',\n 'hatchpath',\n 'mesh',\n 'meshgradient',\n 'meshpatch',\n 'meshrow',\n 'missing-glyph',\n 'script',\n 'set',\n 'solidcolor',\n 'unknown',\n 'use',\n]);\n\nexport const mathMl = freeze([\n 'math',\n 'menclose',\n 'merror',\n 'mfenced',\n 'mfrac',\n 'mglyph',\n 'mi',\n 'mlabeledtr',\n 'mmultiscripts',\n 'mn',\n 'mo',\n 'mover',\n 'mpadded',\n 'mphantom',\n 'mroot',\n 'mrow',\n 'ms',\n 'mspace',\n 'msqrt',\n 'mstyle',\n 'msub',\n 'msup',\n 'msubsup',\n 'mtable',\n 'mtd',\n 'mtext',\n 'mtr',\n 'munder',\n 'munderover',\n 'mprescripts',\n]);\n\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nexport const mathMlDisallowed = freeze([\n 'maction',\n 'maligngroup',\n 'malignmark',\n 'mlongdiv',\n 'mscarries',\n 'mscarry',\n 'msgroup',\n 'mstack',\n 'msline',\n 'msrow',\n 'semantics',\n 'annotation',\n 'annotation-xml',\n 'mprescripts',\n 'none',\n]);\n\nexport const text = freeze(['#text']);\n", "import { freeze } from './utils.js';\n\nexport const html = freeze([\n 'accept',\n 'action',\n 'align',\n 'alt',\n 'autocapitalize',\n 'autocomplete',\n 'autopictureinpicture',\n 'autoplay',\n 'background',\n 'bgcolor',\n 'border',\n 'capture',\n 'cellpadding',\n 'cellspacing',\n 'checked',\n 'cite',\n 'class',\n 'clear',\n 'color',\n 'cols',\n 'colspan',\n 'controls',\n 'controlslist',\n 'coords',\n 'crossorigin',\n 'datetime',\n 'decoding',\n 'default',\n 'dir',\n 'disabled',\n 'disablepictureinpicture',\n 'disableremoteplayback',\n 'download',\n 'draggable',\n 'enctype',\n 'enterkeyhint',\n 'face',\n 'for',\n 'headers',\n 'height',\n 'hidden',\n 'high',\n 'href',\n 'hreflang',\n 'id',\n 'inputmode',\n 'integrity',\n 'ismap',\n 'kind',\n 'label',\n 'lang',\n 'list',\n 'loading',\n 'loop',\n 'low',\n 'max',\n 'maxlength',\n 'media',\n 'method',\n 'min',\n 'minlength',\n 'multiple',\n 'muted',\n 'name',\n 'nonce',\n 'noshade',\n 'novalidate',\n 'nowrap',\n 'open',\n 'optimum',\n 'pattern',\n 'placeholder',\n 'playsinline',\n 'poster',\n 'preload',\n 'pubdate',\n 'radiogroup',\n 'readonly',\n 'rel',\n 'required',\n 'rev',\n 'reversed',\n 'role',\n 'rows',\n 'rowspan',\n 'spellcheck',\n 'scope',\n 'selected',\n 'shape',\n 'size',\n 'sizes',\n 'span',\n 'srclang',\n 'start',\n 'src',\n 'srcset',\n 'step',\n 'style',\n 'summary',\n 'tabindex',\n 'title',\n 'translate',\n 'type',\n 'usemap',\n 'valign',\n 'value',\n 'width',\n 'xmlns',\n 'slot',\n]);\n\nexport const svg = freeze([\n 'accent-height',\n 'accumulate',\n 'additive',\n 'alignment-baseline',\n 'ascent',\n 'attributename',\n 'attributetype',\n 'azimuth',\n 'basefrequency',\n 'baseline-shift',\n 'begin',\n 'bias',\n 'by',\n 'class',\n 'clip',\n 'clippathunits',\n 'clip-path',\n 'clip-rule',\n 'color',\n 'color-interpolation',\n 'color-interpolation-filters',\n 'color-profile',\n 'color-rendering',\n 'cx',\n 'cy',\n 'd',\n 'dx',\n 'dy',\n 'diffuseconstant',\n 'direction',\n 'display',\n 'divisor',\n 'dur',\n 'edgemode',\n 'elevation',\n 'end',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'filter',\n 'filterunits',\n 'flood-color',\n 'flood-opacity',\n 'font-family',\n 'font-size',\n 'font-size-adjust',\n 'font-stretch',\n 'font-style',\n 'font-variant',\n 'font-weight',\n 'fx',\n 'fy',\n 'g1',\n 'g2',\n 'glyph-name',\n 'glyphref',\n 'gradientunits',\n 'gradienttransform',\n 'height',\n 'href',\n 'id',\n 'image-rendering',\n 'in',\n 'in2',\n 'k',\n 'k1',\n 'k2',\n 'k3',\n 'k4',\n 'kerning',\n 'keypoints',\n 'keysplines',\n 'keytimes',\n 'lang',\n 'lengthadjust',\n 'letter-spacing',\n 'kernelmatrix',\n 'kernelunitlength',\n 'lighting-color',\n 'local',\n 'marker-end',\n 'marker-mid',\n 'marker-start',\n 'markerheight',\n 'markerunits',\n 'markerwidth',\n 'maskcontentunits',\n 'maskunits',\n 'max',\n 'mask',\n 'media',\n 'method',\n 'mode',\n 'min',\n 'name',\n 'numoctaves',\n 'offset',\n 'operator',\n 'opacity',\n 'order',\n 'orient',\n 'orientation',\n 'origin',\n 'overflow',\n 'paint-order',\n 'path',\n 'pathlength',\n 'patterncontentunits',\n 'patterntransform',\n 'patternunits',\n 'points',\n 'preservealpha',\n 'preserveaspectratio',\n 'primitiveunits',\n 'r',\n 'rx',\n 'ry',\n 'radius',\n 'refx',\n 'refy',\n 'repeatcount',\n 'repeatdur',\n 'restart',\n 'result',\n 'rotate',\n 'scale',\n 'seed',\n 'shape-rendering',\n 'specularconstant',\n 'specularexponent',\n 'spreadmethod',\n 'startoffset',\n 'stddeviation',\n 'stitchtiles',\n 'stop-color',\n 'stop-opacity',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke',\n 'stroke-width',\n 'style',\n 'surfacescale',\n 'systemlanguage',\n 'tabindex',\n 'targetx',\n 'targety',\n 'transform',\n 'transform-origin',\n 'text-anchor',\n 'text-decoration',\n 'text-rendering',\n 'textlength',\n 'type',\n 'u1',\n 'u2',\n 'unicode',\n 'values',\n 'viewbox',\n 'visibility',\n 'version',\n 'vert-adv-y',\n 'vert-origin-x',\n 'vert-origin-y',\n 'width',\n 'word-spacing',\n 'wrap',\n 'writing-mode',\n 'xchannelselector',\n 'ychannelselector',\n 'x',\n 'x1',\n 'x2',\n 'xmlns',\n 'y',\n 'y1',\n 'y2',\n 'z',\n 'zoomandpan',\n]);\n\nexport const mathMl = freeze([\n 'accent',\n 'accentunder',\n 'align',\n 'bevelled',\n 'close',\n 'columnsalign',\n 'columnlines',\n 'columnspan',\n 'denomalign',\n 'depth',\n 'dir',\n 'display',\n 'displaystyle',\n 'encoding',\n 'fence',\n 'frame',\n 'height',\n 'href',\n 'id',\n 'largeop',\n 'length',\n 'linethickness',\n 'lspace',\n 'lquote',\n 'mathbackground',\n 'mathcolor',\n 'mathsize',\n 'mathvariant',\n 'maxsize',\n 'minsize',\n 'movablelimits',\n 'notation',\n 'numalign',\n 'open',\n 'rowalign',\n 'rowlines',\n 'rowspacing',\n 'rowspan',\n 'rspace',\n 'rquote',\n 'scriptlevel',\n 'scriptminsize',\n 'scriptsizemultiplier',\n 'selection',\n 'separator',\n 'separators',\n 'stretchy',\n 'subscriptshift',\n 'supscriptshift',\n 'symmetric',\n 'voffset',\n 'width',\n 'xmlns',\n]);\n\nexport const xml = freeze([\n 'xlink:href',\n 'xml:id',\n 'xlink:title',\n 'xml:space',\n 'xmlns:xlink',\n]);\n", "import { seal } from './utils.js';\n\n// eslint-disable-next-line unicorn/better-regex\nexport const MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\nexport const ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\nexport const TMPLIT_EXPR = seal(/\\${[\\w\\W]*}/gm);\nexport const DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]/); // eslint-disable-line no-useless-escape\nexport const ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nexport const IS_ALLOWED_URI = seal(\n /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nexport const IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nexport const ATTR_WHITESPACE = seal(\n /[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nexport const DOCTYPE_NAME = seal(/^html$/i);\n", "import * as TAGS from './tags.js';\nimport * as ATTRS from './attrs.js';\nimport * as EXPRESSIONS from './regexp.js';\nimport {\n addToSet,\n clone,\n entries,\n freeze,\n arrayForEach,\n arrayPop,\n arrayPush,\n stringMatch,\n stringReplace,\n stringToLowerCase,\n stringToString,\n stringIndexOf,\n stringTrim,\n regExpTest,\n typeErrorCreate,\n lookupGetter,\n} from './utils.js';\n\nconst getGlobal = () => (typeof window === 'undefined' ? null : window);\n\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.\n * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function (trustedTypes, purifyHostElement) {\n if (\n typeof trustedTypes !== 'object' ||\n typeof trustedTypes.createPolicy !== 'function'\n ) {\n return null;\n }\n\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n },\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn(\n 'TrustedTypes policy ' + policyName + ' could not be created.'\n );\n return null;\n }\n};\n\nfunction createDOMPurify(window = getGlobal()) {\n const DOMPurify = (root) => createDOMPurify(root);\n\n /**\n * Version label, exposed for easier checks\n * if DOMPurify is up to date or not\n */\n DOMPurify.version = VERSION;\n\n /**\n * Array of elements that DOMPurify removed during sanitation.\n * Empty if nothing was removed.\n */\n DOMPurify.removed = [];\n\n if (!window || !window.document || window.document.nodeType !== 9) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n\n return DOMPurify;\n }\n\n const originalDocument = window.document;\n const currentScript = originalDocument.currentScript;\n\n let { document } = window;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes,\n } = window;\n\n const ElementPrototype = Element.prototype;\n\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n\n let trustedTypesPolicy;\n let emptyHTML = '';\n\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName,\n } = document;\n const { importNode } = originalDocument;\n\n let hooks = {};\n\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported =\n typeof entries === 'function' &&\n typeof getParentNode === 'function' &&\n implementation &&\n implementation.createHTMLDocument !== undefined;\n\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n } = EXPRESSIONS;\n\n let { IS_ALLOWED_URI } = EXPRESSIONS;\n\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [\n ...TAGS.html,\n ...TAGS.svg,\n ...TAGS.svgFilters,\n ...TAGS.mathMl,\n ...TAGS.text,\n ]);\n\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [\n ...ATTRS.html,\n ...ATTRS.svg,\n ...ATTRS.mathMl,\n ...ATTRS.xml,\n ]);\n\n /*\n * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(\n Object.create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false,\n },\n })\n );\n\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (§7.3.3)\n * - DOM Tree Accessors (§3.1.5)\n * - Form Element Parent-Child Relations (§4.10.3)\n * - Iframe srcdoc / Nested WindowProxies (§4.8.5)\n * - HTMLCollection (§4.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, [\n 'annotation-xml',\n 'audio',\n 'colgroup',\n 'desc',\n 'foreignobject',\n 'head',\n 'iframe',\n 'math',\n 'mi',\n 'mn',\n 'mo',\n 'ms',\n 'mtext',\n 'noembed',\n 'noframes',\n 'noscript',\n 'plaintext',\n 'script',\n 'style',\n 'svg',\n 'template',\n 'thead',\n 'title',\n 'video',\n 'xmp',\n ]);\n\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, [\n 'audio',\n 'video',\n 'img',\n 'source',\n 'image',\n 'track',\n ]);\n\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [\n 'alt',\n 'class',\n 'for',\n 'id',\n 'label',\n 'name',\n 'pattern',\n 'placeholder',\n 'role',\n 'summary',\n 'title',\n 'value',\n 'style',\n 'xmlns',\n ]);\n\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet(\n {},\n [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE],\n stringToString\n );\n\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc;\n\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n\n const formElement = document.createElement('form');\n\n const isRegexOrFunction = function (testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n\n /**\n * _parseConfig\n *\n * @param {Object} cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function (cfg) {\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1\n ? (PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE)\n : (PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE);\n\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc =\n PARSER_MEDIA_TYPE === 'application/xhtml+xml'\n ? stringToString\n : stringToLowerCase;\n\n /* Set configuration parameters */\n ALLOWED_TAGS =\n 'ALLOWED_TAGS' in cfg\n ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc)\n : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR =\n 'ALLOWED_ATTR' in cfg\n ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc)\n : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES =\n 'ALLOWED_NAMESPACES' in cfg\n ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString)\n : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES =\n 'ADD_URI_SAFE_ATTR' in cfg\n ? addToSet(\n clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent\n cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent\n transformCaseFunc // eslint-disable-line indent\n ) // eslint-disable-line indent\n : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS =\n 'ADD_DATA_URI_TAGS' in cfg\n ? addToSet(\n clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent\n cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent\n transformCaseFunc // eslint-disable-line indent\n ) // eslint-disable-line indent\n : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS =\n 'FORBID_CONTENTS' in cfg\n ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc)\n : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS =\n 'FORBID_TAGS' in cfg\n ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc)\n : {};\n FORBID_ATTR =\n 'FORBID_ATTR' in cfg\n ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc)\n : {};\n USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || EXPRESSIONS.IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (\n cfg.CUSTOM_ELEMENT_HANDLING &&\n isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)\n ) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck =\n cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n\n if (\n cfg.CUSTOM_ELEMENT_HANDLING &&\n isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)\n ) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck =\n cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n\n if (\n cfg.CUSTOM_ELEMENT_HANDLING &&\n typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements ===\n 'boolean'\n ) {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements =\n cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, [...TAGS.text]);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, TAGS.html);\n addToSet(ALLOWED_ATTR, ATTRS.html);\n }\n\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, TAGS.svg);\n addToSet(ALLOWED_ATTR, ATTRS.svg);\n addToSet(ALLOWED_ATTR, ATTRS.xml);\n }\n\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, TAGS.svgFilters);\n addToSet(ALLOWED_ATTR, ATTRS.svg);\n addToSet(ALLOWED_ATTR, ATTRS.xml);\n }\n\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, TAGS.mathMl);\n addToSet(ALLOWED_ATTR, ATTRS.mathMl);\n addToSet(ALLOWED_ATTR, ATTRS.xml);\n }\n }\n\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n\n if (cfg.ADD_ATTR) {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate(\n 'TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.'\n );\n }\n\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate(\n 'TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.'\n );\n }\n\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(\n trustedTypes,\n currentScript\n );\n }\n\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n\n CONFIG = cfg;\n };\n\n const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [\n 'mi',\n 'mo',\n 'mn',\n 'ms',\n 'mtext',\n ]);\n\n const HTML_INTEGRATION_POINTS = addToSet({}, [\n 'foreignobject',\n 'desc',\n 'title',\n 'annotation-xml',\n ]);\n\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [\n 'title',\n 'style',\n 'font',\n 'a',\n 'script',\n ]);\n\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, TAGS.svg);\n addToSet(ALL_SVG_TAGS, TAGS.svgFilters);\n addToSet(ALL_SVG_TAGS, TAGS.svgDisallowed);\n\n const ALL_MATHML_TAGS = addToSet({}, TAGS.mathMl);\n addToSet(ALL_MATHML_TAGS, TAGS.mathMlDisallowed);\n\n /**\n *\n *\n * @param {Element} element a DOM element whose namespace is being checked\n * @returns {boolean} Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function (element) {\n let parent = getParentNode(element);\n\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template',\n };\n }\n\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return (\n tagName === 'svg' &&\n (parentTagName === 'annotation-xml' ||\n MATHML_TEXT_INTEGRATION_POINTS[parentTagName])\n );\n }\n\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (\n parent.namespaceURI === SVG_NAMESPACE &&\n !HTML_INTEGRATION_POINTS[parentTagName]\n ) {\n return false;\n }\n\n if (\n parent.namespaceURI === MATHML_NAMESPACE &&\n !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]\n ) {\n return false;\n }\n\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return (\n !ALL_MATHML_TAGS[tagName] &&\n (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName])\n );\n }\n\n // For XHTML and XML documents that support custom namespaces\n if (\n PARSER_MEDIA_TYPE === 'application/xhtml+xml' &&\n ALLOWED_NAMESPACES[element.namespaceURI]\n ) {\n return true;\n }\n\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n\n /**\n * _forceRemove\n *\n * @param {Node} node a DOM node\n */\n const _forceRemove = function (node) {\n arrayPush(DOMPurify.removed, { element: node });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n node.parentNode.removeChild(node);\n } catch (_) {\n node.remove();\n }\n };\n\n /**\n * _removeAttribute\n *\n * @param {String} name an Attribute name\n * @param {Node} node a DOM node\n */\n const _removeAttribute = function (name, node) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: node.getAttributeNode(name),\n from: node,\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: node,\n });\n }\n\n node.removeAttribute(name);\n\n // We void attribute values for unremovable \"is\"\" attributes\n if (name === 'is' && !ALLOWED_ATTR[name]) {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(node);\n } catch (_) {}\n } else {\n try {\n node.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n\n /**\n * _initDocument\n *\n * @param {String} dirty a string of dirty markup\n * @return {Document} a DOM, filled with the dirty markup\n */\n const _initDocument = function (dirty) {\n /* Create a HTML document */\n let doc;\n let leadingWhitespace;\n\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n\n if (\n PARSER_MEDIA_TYPE === 'application/xhtml+xml' &&\n NAMESPACE === HTML_NAMESPACE\n ) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty =\n '' +\n dirty +\n '';\n }\n\n const dirtyPayload = trustedTypesPolicy\n ? trustedTypesPolicy.createHTML(dirty)\n : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT\n ? emptyHTML\n : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n\n const body = doc.body || doc.documentElement;\n\n if (dirty && leadingWhitespace) {\n body.insertBefore(\n document.createTextNode(leadingWhitespace),\n body.childNodes[0] || null\n );\n }\n\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(\n doc,\n WHOLE_DOCUMENT ? 'html' : 'body'\n )[0];\n }\n\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n\n /**\n * _createIterator\n *\n * @param {Document} root document/fragment to create iterator for\n * @return {Iterator} iterator instance\n */\n const _createIterator = function (root) {\n return createNodeIterator.call(\n root.ownerDocument || root,\n root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,\n null,\n false\n );\n };\n\n /**\n * _isClobbered\n *\n * @param {Node} elm element to check for clobbering attacks\n * @return {Boolean} true if clobbered, false if safe\n */\n const _isClobbered = function (elm) {\n return (\n elm instanceof HTMLFormElement &&\n (typeof elm.nodeName !== 'string' ||\n typeof elm.textContent !== 'string' ||\n typeof elm.removeChild !== 'function' ||\n !(elm.attributes instanceof NamedNodeMap) ||\n typeof elm.removeAttribute !== 'function' ||\n typeof elm.setAttribute !== 'function' ||\n typeof elm.namespaceURI !== 'string' ||\n typeof elm.insertBefore !== 'function' ||\n typeof elm.hasChildNodes !== 'function')\n );\n };\n\n /**\n * _isNode\n *\n * @param {Node} obj object to check whether it's a DOM node\n * @return {Boolean} true is object is a DOM node\n */\n const _isNode = function (object) {\n return typeof Node === 'object'\n ? object instanceof Node\n : object &&\n typeof object === 'object' &&\n typeof object.nodeType === 'number' &&\n typeof object.nodeName === 'string';\n };\n\n /**\n * _executeHook\n * Execute user configurable hooks\n *\n * @param {String} entryPoint Name of the hook's entry point\n * @param {Node} currentNode node to work on with the hook\n * @param {Object} data additional hook parameters\n */\n const _executeHook = function (entryPoint, currentNode, data) {\n if (!hooks[entryPoint]) {\n return;\n }\n\n arrayForEach(hooks[entryPoint], (hook) => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n };\n\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n *\n * @param {Node} currentNode to check for permission to exist\n * @return {Boolean} true if node was killed, false if left alive\n */\n const _sanitizeElements = function (currentNode) {\n let content;\n\n /* Execute a hook if present */\n _executeHook('beforeSanitizeElements', currentNode, null);\n\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n\n /* Execute a hook if present */\n _executeHook('uponSanitizeElement', currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS,\n });\n\n /* Detect mXSS attempts abusing namespace confusion */\n if (\n currentNode.hasChildNodes() &&\n !_isNode(currentNode.firstElementChild) &&\n (!_isNode(currentNode.content) ||\n !_isNode(currentNode.content.firstElementChild)) &&\n regExpTest(/<[/\\w]/g, currentNode.innerHTML) &&\n regExpTest(/<[/\\w]/g, currentNode.textContent)\n ) {\n _forceRemove(currentNode);\n return true;\n }\n\n /* Remove element if anything forbids its presence */\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {\n if (\n CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp &&\n regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)\n )\n return false;\n if (\n CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function &&\n CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)\n )\n return false;\n }\n\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n\n for (let i = childCount - 1; i >= 0; --i) {\n parentNode.insertBefore(\n cloneNode(childNodes[i], true),\n getNextSibling(currentNode)\n );\n }\n }\n }\n\n _forceRemove(currentNode);\n return true;\n }\n\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if (\n (tagName === 'noscript' ||\n tagName === 'noembed' ||\n tagName === 'noframes') &&\n regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)\n ) {\n _forceRemove(currentNode);\n return true;\n }\n\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {\n /* Get the element's text content */\n content = currentNode.textContent;\n content = stringReplace(content, MUSTACHE_EXPR, ' ');\n content = stringReplace(content, ERB_EXPR, ' ');\n content = stringReplace(content, TMPLIT_EXPR, ' ');\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });\n currentNode.textContent = content;\n }\n }\n\n /* Execute a hook if present */\n _executeHook('afterSanitizeElements', currentNode, null);\n\n return false;\n };\n\n /**\n * _isValidAttribute\n *\n * @param {string} lcTag Lowercase tag name of containing element.\n * @param {string} lcName Lowercase attribute name.\n * @param {string} value Attribute value.\n * @return {Boolean} Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function (lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (\n SANITIZE_DOM &&\n (lcName === 'id' || lcName === 'name') &&\n (value in document || value in formElement)\n ) {\n return false;\n }\n\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (\n ALLOW_DATA_ATTR &&\n !FORBID_ATTR[lcName] &&\n regExpTest(DATA_ATTR, lcName)\n ) {\n // This attribute is safe\n } else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) {\n // This attribute is safe\n /* Otherwise, check the name is permitted */\n } else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n (_basicCustomElementTest(lcTag) &&\n ((CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp &&\n regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag)) ||\n (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function &&\n CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag))) &&\n ((CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp &&\n regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName)) ||\n (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function &&\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)))) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n (lcName === 'is' &&\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements &&\n ((CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp &&\n regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value)) ||\n (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function &&\n CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))))\n ) {\n // If user has supplied a regexp or function in CUSTOM_ELEMENT_HANDLING.tagNameCheck, we need to also allow derived custom elements using the same tagName test.\n // Additionally, we need to allow attributes passing the CUSTOM_ELEMENT_HANDLING.attributeNameCheck user has configured, as custom elements can define these at their own discretion.\n } else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) {\n // This attribute is safe\n /* Check no script, data or unknown possibly unsafe URI\n unless we know URI values are safe for that attribute */\n } else if (\n regExpTest(IS_ALLOWED_URI, stringReplace(value, ATTR_WHITESPACE, ''))\n ) {\n // This attribute is safe\n /* Keep image data URIs alive if src/xlink:href is allowed */\n /* Further prevent gadget XSS for dynamically built script tags */\n } else if (\n (lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') &&\n lcTag !== 'script' &&\n stringIndexOf(value, 'data:') === 0 &&\n DATA_URI_TAGS[lcTag]\n ) {\n // This attribute is safe\n /* Allow unknown protocols: This provides support for links that\n are handled by protocol handlers which may be unknown ahead of\n time, e.g. fb:, spotify: */\n } else if (\n ALLOW_UNKNOWN_PROTOCOLS &&\n !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))\n ) {\n // This attribute is safe\n /* Check for binary attributes */\n } else if (value) {\n return false;\n } else {\n // Binary attributes are safe at this point\n /* Anything else, presume unsafe, do not add it back */\n }\n\n return true;\n };\n\n /**\n * _basicCustomElementCheck\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n * @param {string} tagName name of the tag of the node to sanitize\n */\n const _basicCustomElementTest = function (tagName) {\n return tagName.indexOf('-') > 0;\n };\n\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param {Node} currentNode to sanitize\n */\n const _sanitizeAttributes = function (currentNode) {\n let attr;\n let value;\n let lcName;\n let l;\n /* Execute a hook if present */\n _executeHook('beforeSanitizeAttributes', currentNode, null);\n\n const { attributes } = currentNode;\n\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes) {\n return;\n }\n\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n };\n l = attributes.length;\n\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n attr = attributes[l];\n const { name, namespaceURI } = attr;\n value = name === 'value' ? attr.value : stringTrim(attr.value);\n lcName = transformCaseFunc(name);\n\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHook('uponSanitizeAttribute', currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n\n /* Remove attribute */\n _removeAttribute(name, currentNode);\n\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n continue;\n }\n\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n value = stringReplace(value, MUSTACHE_EXPR, ' ');\n value = stringReplace(value, ERB_EXPR, ' ');\n value = stringReplace(value, TMPLIT_EXPR, ' ');\n }\n\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n continue;\n }\n\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n\n /* Handle attributes that require Trusted Types */\n if (\n trustedTypesPolicy &&\n typeof trustedTypes === 'object' &&\n typeof trustedTypes.getAttributeType === 'function'\n ) {\n if (namespaceURI) {\n /* Namespaces are not yet supported, see https://bugs.chromium.org/p/chromium/issues/detail?id=1305293 */\n } else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML': {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n\n case 'TrustedScriptURL': {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n\n default: {\n break;\n }\n }\n }\n }\n\n /* Handle invalid data-* attribute set by try-catching it */\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n\n arrayPop(DOMPurify.removed);\n } catch (_) {}\n }\n\n /* Execute a hook if present */\n _executeHook('afterSanitizeAttributes', currentNode, null);\n };\n\n /**\n * _sanitizeShadowDOM\n *\n * @param {DocumentFragment} fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function (fragment) {\n let shadowNode;\n const shadowIterator = _createIterator(fragment);\n\n /* Execute a hook if present */\n _executeHook('beforeSanitizeShadowDOM', fragment, null);\n\n while ((shadowNode = shadowIterator.nextNode())) {\n /* Execute a hook if present */\n _executeHook('uponSanitizeShadowNode', shadowNode, null);\n\n /* Sanitize tags and elements */\n if (_sanitizeElements(shadowNode)) {\n continue;\n }\n\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n\n /* Check attributes, sanitize if necessary */\n _sanitizeAttributes(shadowNode);\n }\n\n /* Execute a hook if present */\n _executeHook('afterSanitizeShadowDOM', fragment, null);\n };\n\n /**\n * Sanitize\n * Public method providing core sanitation functionality\n *\n * @param {String|Node} dirty string or DOM node\n * @param {Object} configuration object\n */\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty, cfg = {}) {\n let body;\n let importedNode;\n let currentNode;\n let returnNode;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n\n /* Clean up removed elements */\n DOMPurify.removed = [];\n\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate(\n 'root node is forbidden and cannot be sanitized in-place'\n );\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (\n !RETURN_DOM &&\n !SAFE_FOR_TEMPLATES &&\n !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1\n ) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE\n ? trustedTypesPolicy.createHTML(dirty)\n : dirty;\n }\n\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n\n /* Get node iterator */\n const nodeIterator = _createIterator(IN_PLACE ? dirty : body);\n\n /* Now start iterating over the created document */\n while ((currentNode = nodeIterator.nextNode())) {\n /* Sanitize tags and elements */\n if (_sanitizeElements(currentNode)) {\n continue;\n }\n\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n\n /* Check attributes, sanitize if necessary */\n _sanitizeAttributes(currentNode);\n }\n\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n\n return returnNode;\n }\n\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n\n /* Serialize doctype if allowed */\n if (\n WHOLE_DOCUMENT &&\n ALLOWED_TAGS['!doctype'] &&\n body.ownerDocument &&\n body.ownerDocument.doctype &&\n body.ownerDocument.doctype.name &&\n regExpTest(EXPRESSIONS.DOCTYPE_NAME, body.ownerDocument.doctype.name)\n ) {\n serializedHTML =\n '\\n' + serializedHTML;\n }\n\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');\n serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');\n serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');\n }\n\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE\n ? trustedTypesPolicy.createHTML(serializedHTML)\n : serializedHTML;\n };\n\n /**\n * Public method to set the configuration once\n * setConfig\n *\n * @param {Object} cfg configuration object\n */\n DOMPurify.setConfig = function (cfg) {\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n\n /**\n * Public method to remove the configuration\n * clearConfig\n *\n */\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n\n /**\n * Public method to check if an attribute value is valid.\n * Uses last set config, if any. Otherwise, uses config defaults.\n * isValidAttribute\n *\n * @param {string} tag Tag name of containing element.\n * @param {string} attr Attribute name.\n * @param {string} value Attribute value.\n * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.\n */\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n\n /**\n * AddHook\n * Public method to add DOMPurify hooks\n *\n * @param {String} entryPoint entry point for the hook to add\n * @param {Function} hookFunction function to execute\n */\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n\n hooks[entryPoint] = hooks[entryPoint] || [];\n arrayPush(hooks[entryPoint], hookFunction);\n };\n\n /**\n * RemoveHook\n * Public method to remove a DOMPurify hook at a given entryPoint\n * (pops it from the stack of hooks if more are present)\n *\n * @param {String} entryPoint entry point for the hook to remove\n * @return {Function} removed(popped) hook\n */\n DOMPurify.removeHook = function (entryPoint) {\n if (hooks[entryPoint]) {\n return arrayPop(hooks[entryPoint]);\n }\n };\n\n /**\n * RemoveHooks\n * Public method to remove all DOMPurify hooks at a given entryPoint\n *\n * @param {String} entryPoint entry point for the hooks to remove\n */\n DOMPurify.removeHooks = function (entryPoint) {\n if (hooks[entryPoint]) {\n hooks[entryPoint] = [];\n }\n };\n\n /**\n * RemoveAllHooks\n * Public method to remove all DOMPurify hooks\n *\n */\n DOMPurify.removeAllHooks = function () {\n hooks = {};\n };\n\n return DOMPurify;\n}\n\nexport default createDOMPurify();\n", "'use strict'\r\n\r\nmodule.exports = calcSDF\r\n\r\nvar INF = 1e20\r\n\r\nfunction calcSDF(src, options) {\r\n if (!options) options = {}\r\n\r\n var cutoff = options.cutoff == null ? 0.25 : options.cutoff\r\n var radius = options.radius == null ? 8 : options.radius\r\n var channel = options.channel || 0\r\n var w, h, size, data, intData, stride, ctx, canvas, imgData, i, l\r\n\r\n // handle image container\r\n if (ArrayBuffer.isView(src) || Array.isArray(src)) {\r\n if (!options.width || !options.height) throw Error('For raw data width and height should be provided by options')\r\n w = options.width, h = options.height\r\n data = src\r\n\r\n if (!options.stride) stride = Math.floor(src.length / w / h)\r\n else stride = options.stride\r\n }\r\n else {\r\n if (window.HTMLCanvasElement && src instanceof window.HTMLCanvasElement) {\r\n canvas = src\r\n ctx = canvas.getContext('2d')\r\n w = canvas.width, h = canvas.height\r\n imgData = ctx.getImageData(0, 0, w, h)\r\n data = imgData.data\r\n stride = 4\r\n }\r\n else if (window.CanvasRenderingContext2D && src instanceof window.CanvasRenderingContext2D) {\r\n canvas = src.canvas\r\n ctx = src\r\n w = canvas.width, h = canvas.height\r\n imgData = ctx.getImageData(0, 0, w, h)\r\n data = imgData.data\r\n stride = 4\r\n }\r\n else if (window.ImageData && src instanceof window.ImageData) {\r\n imgData = src\r\n w = src.width, h = src.height\r\n data = imgData.data\r\n stride = 4\r\n }\r\n }\r\n\r\n size = Math.max(w, h)\r\n\r\n //convert int data to floats\r\n if ((window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) || (window.Uint8Array && data instanceof window.Uint8Array)) {\r\n intData = data\r\n data = Array(w*h)\r\n\r\n for (i = 0, l = Math.floor(intData.length / stride); i < l; i++) {\r\n data[i] = intData[i*stride + channel] / 255\r\n }\r\n }\r\n else {\r\n if (stride !== 1) throw Error('Raw data can have only 1 value per pixel')\r\n }\r\n\r\n // temporary arrays for the distance transform\r\n var gridOuter = Array(w * h)\r\n var gridInner = Array(w * h)\r\n var f = Array(size)\r\n var d = Array(size)\r\n var z = Array(size + 1)\r\n var v = Array(size)\r\n\r\n for (i = 0, l = w * h; i < l; i++) {\r\n var a = data[i]\r\n gridOuter[i] = a === 1 ? 0 : a === 0 ? INF : Math.pow(Math.max(0, 0.5 - a), 2)\r\n gridInner[i] = a === 1 ? INF : a === 0 ? 0 : Math.pow(Math.max(0, a - 0.5), 2)\r\n }\r\n\r\n edt(gridOuter, w, h, f, d, v, z)\r\n edt(gridInner, w, h, f, d, v, z)\r\n\r\n var dist = window.Float32Array ? new Float32Array(w * h) : new Array(w * h)\r\n\r\n for (i = 0, l = w*h; i < l; i++) {\r\n dist[i] = Math.min(Math.max(1 - ( (gridOuter[i] - gridInner[i]) / radius + cutoff), 0), 1)\r\n }\r\n\r\n return dist\r\n}\r\n\r\n// 2D Euclidean distance transform by Felzenszwalb & Huttenlocher https://cs.brown.edu/~pff/dt/\r\nfunction edt(data, width, height, f, d, v, z) {\r\n for (var x = 0; x < width; x++) {\r\n for (var y = 0; y < height; y++) {\r\n f[y] = data[y * width + x]\r\n }\r\n edt1d(f, d, v, z, height)\r\n for (y = 0; y < height; y++) {\r\n data[y * width + x] = d[y]\r\n }\r\n }\r\n for (y = 0; y < height; y++) {\r\n for (x = 0; x < width; x++) {\r\n f[x] = data[y * width + x]\r\n }\r\n edt1d(f, d, v, z, width)\r\n for (x = 0; x < width; x++) {\r\n data[y * width + x] = Math.sqrt(d[x])\r\n }\r\n }\r\n}\r\n\r\n// 1D squared distance transform\r\nfunction edt1d(f, d, v, z, n) {\r\n v[0] = 0;\r\n z[0] = -INF\r\n z[1] = +INF\r\n\r\n for (var q = 1, k = 0; q < n; q++) {\r\n var s = ((f[q] + q * q) - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k])\r\n while (s <= z[k]) {\r\n k--\r\n s = ((f[q] + q * q) - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k])\r\n }\r\n k++\r\n v[k] = q\r\n z[k] = s\r\n z[k + 1] = +INF\r\n }\r\n\r\n for (q = 0, k = 0; q < n; q++) {\r\n while (z[k + 1] < q) k++\r\n d[q] = (q - v[k]) * (q - v[k]) + f[v[k]]\r\n }\r\n}\r\n", "/*\r\nBreaks a Javascript string into individual user-perceived \"characters\" \r\ncalled extended grapheme clusters by implementing the Unicode UAX-29 standard, version 10.0.0\r\n\r\nUsage:\r\nvar splitter = new GraphemeSplitter();\r\n//returns an array of strings, one string for each grapheme cluster\r\nvar graphemes = splitter.splitGraphemes(string); \r\n\r\n*/\r\nfunction GraphemeSplitter(){\r\n\tvar CR = 0,\r\n\t\tLF = 1,\r\n\t\tControl = 2,\r\n\t\tExtend = 3,\r\n\t\tRegional_Indicator = 4,\r\n\t\tSpacingMark = 5,\r\n\t\tL = 6,\r\n\t\tV = 7,\r\n\t\tT = 8,\r\n\t\tLV = 9,\r\n\t\tLVT = 10,\r\n\t\tOther = 11,\r\n\t\tPrepend = 12,\r\n\t\tE_Base = 13,\r\n\t\tE_Modifier = 14,\r\n\t\tZWJ = 15,\r\n\t\tGlue_After_Zwj = 16,\r\n\t\tE_Base_GAZ = 17;\r\n\t\t\r\n\t// BreakTypes\r\n\tvar NotBreak = 0,\r\n\t\tBreakStart = 1,\r\n\t\tBreak = 2,\r\n\t\tBreakLastRegional = 3,\r\n\t\tBreakPenultimateRegional = 4;\r\n\t\t\r\n\tfunction isSurrogate(str, pos) {\r\n\t\treturn 0xd800 <= str.charCodeAt(pos) && str.charCodeAt(pos) <= 0xdbff && \r\n\t\t\t\t0xdc00 <= str.charCodeAt(pos + 1) && str.charCodeAt(pos + 1) <= 0xdfff;\r\n\t}\r\n\t\t\r\n\t// Private function, gets a Unicode code point from a JavaScript UTF-16 string\r\n\t// handling surrogate pairs appropriately\r\n\tfunction codePointAt(str, idx){\r\n\t\tif(idx === undefined){\r\n\t\t\tidx = 0;\r\n\t\t}\r\n\t\tvar code = str.charCodeAt(idx);\r\n\r\n\t\t// if a high surrogate\r\n\t\tif (0xD800 <= code && code <= 0xDBFF && \r\n\t\t\tidx < str.length - 1){\r\n\t\t\tvar hi = code;\r\n\t\t\tvar low = str.charCodeAt(idx + 1);\r\n\t\t\tif (0xDC00 <= low && low <= 0xDFFF){\r\n\t\t\t\treturn ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;\r\n\t\t\t}\r\n\t\t\treturn hi;\r\n\t\t}\r\n\t\t\r\n\t\t// if a low surrogate\r\n\t\tif (0xDC00 <= code && code <= 0xDFFF &&\r\n\t\t\tidx >= 1){\r\n\t\t\tvar hi = str.charCodeAt(idx - 1);\r\n\t\t\tvar low = code;\r\n\t\t\tif (0xD800 <= hi && hi <= 0xDBFF){\r\n\t\t\t\treturn ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;\r\n\t\t\t}\r\n\t\t\treturn low;\r\n\t\t}\r\n\t\t\r\n\t\t//just return the char if an unmatched surrogate half or a \r\n\t\t//single-char codepoint\r\n\t\treturn code;\r\n\t}\r\n\t\r\n\t// Private function, returns whether a break is allowed between the \r\n\t// two given grapheme breaking classes\r\n\tfunction shouldBreak(start, mid, end){\r\n\t\tvar all = [start].concat(mid).concat([end]);\r\n\t\tvar previous = all[all.length - 2]\r\n\t\tvar next = end\r\n\t\t\r\n\t\t// Lookahead termintor for:\r\n\t\t// GB10. (E_Base | EBG) Extend* ?\tE_Modifier\r\n\t\tvar eModifierIndex = all.lastIndexOf(E_Modifier)\r\n\t\tif(eModifierIndex > 1 &&\r\n\t\t\tall.slice(1, eModifierIndex).every(function(c){return c == Extend}) &&\r\n\t\t\t[Extend, E_Base, E_Base_GAZ].indexOf(start) == -1){\r\n\t\t\treturn Break\r\n\t\t}\r\n\r\n\t\t// Lookahead termintor for:\r\n\t\t// GB12. ^ (RI RI)* RI\t?\tRI\r\n\t\t// GB13. [^RI] (RI RI)* RI\t?\tRI\r\n\t\tvar rIIndex = all.lastIndexOf(Regional_Indicator)\r\n\t\tif(rIIndex > 0 &&\r\n\t\t\tall.slice(1, rIIndex).every(function(c){return c == Regional_Indicator}) &&\r\n\t\t\t[Prepend, Regional_Indicator].indexOf(previous) == -1) { \r\n\t\t\tif(all.filter(function(c){return c == Regional_Indicator}).length % 2 == 1) {\r\n\t\t\t\treturn BreakLastRegional\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\treturn BreakPenultimateRegional\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t// GB3. CR X LF\r\n\t\tif(previous == CR && next == LF){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB4. (Control|CR|LF) \u00F7\r\n\t\telse if(previous == Control || previous == CR || previous == LF){\r\n\t\t\tif(next == E_Modifier && mid.every(function(c){return c == Extend})){\r\n\t\t\t\treturn Break\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\treturn BreakStart\r\n\t\t\t}\r\n\t\t}\r\n\t\t// GB5. \u00F7 (Control|CR|LF)\r\n\t\telse if(next == Control || next == CR || next == LF){\r\n\t\t\treturn BreakStart;\r\n\t\t}\r\n\t\t// GB6. L X (L|V|LV|LVT)\r\n\t\telse if(previous == L && \r\n\t\t\t(next == L || next == V || next == LV || next == LVT)){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB7. (LV|V) X (V|T)\r\n\t\telse if((previous == LV || previous == V) && \r\n\t\t\t(next == V || next == T)){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB8. (LVT|T) X (T)\r\n\t\telse if((previous == LVT || previous == T) && \r\n\t\t\tnext == T){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB9. X (Extend|ZWJ)\r\n\t\telse if (next == Extend || next == ZWJ){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB9a. X SpacingMark\r\n\t\telse if(next == SpacingMark){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t// GB9b. Prepend X\r\n\t\telse if (previous == Prepend){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t\r\n\t\t// GB10. (E_Base | EBG) Extend* ?\tE_Modifier\r\n\t\tvar previousNonExtendIndex = all.indexOf(Extend) != -1 ? all.lastIndexOf(Extend) - 1 : all.length - 2;\r\n\t\tif([E_Base, E_Base_GAZ].indexOf(all[previousNonExtendIndex]) != -1 &&\r\n\t\t\tall.slice(previousNonExtendIndex + 1, -1).every(function(c){return c == Extend}) &&\r\n\t\t\tnext == E_Modifier){\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\t\t\r\n\t\t// GB11. ZWJ ? (Glue_After_Zwj | EBG)\r\n\t\tif(previous == ZWJ && [Glue_After_Zwj, E_Base_GAZ].indexOf(next) != -1) {\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\r\n\t\t// GB12. ^ (RI RI)* RI ? RI\r\n\t\t// GB13. [^RI] (RI RI)* RI ? RI\r\n\t\tif(mid.indexOf(Regional_Indicator) != -1) { \r\n\t\t\treturn Break;\r\n\t\t}\r\n\t\tif(previous == Regional_Indicator && next == Regional_Indicator) {\r\n\t\t\treturn NotBreak;\r\n\t\t}\r\n\r\n\t\t// GB999. Any ? Any\r\n\t\treturn BreakStart;\r\n\t}\r\n\t\r\n\t// Returns the next grapheme break in the string after the given index\r\n\tthis.nextBreak = function(string, index){\r\n\t\tif(index === undefined){\r\n\t\t\tindex = 0;\r\n\t\t}\r\n\t\tif(index < 0){\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tif(index >= string.length - 1){\r\n\t\t\treturn string.length;\r\n\t\t}\r\n\t\tvar prev = getGraphemeBreakProperty(codePointAt(string, index));\r\n\t\tvar mid = []\r\n\t\tfor (var i = index + 1; i < string.length; i++) {\r\n\t\t\t// check for already processed low surrogates\r\n\t\t\tif(isSurrogate(string, i - 1)){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\r\n\t\t\tvar next = getGraphemeBreakProperty(codePointAt(string, i));\r\n\t\t\tif(shouldBreak(prev, mid, next)){\r\n\t\t\t\treturn i;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tmid.push(next);\r\n\t\t}\r\n\t\treturn string.length;\r\n\t};\r\n\t\r\n\t// Breaks the given string into an array of grapheme cluster strings\r\n\tthis.splitGraphemes = function(str){\r\n\t\tvar res = [];\r\n\t\tvar index = 0;\r\n\t\tvar brk;\r\n\t\twhile((brk = this.nextBreak(str, index)) < str.length){\r\n\t\t\tres.push(str.slice(index, brk));\r\n\t\t\tindex = brk;\r\n\t\t}\r\n\t\tif(index < str.length){\r\n\t\t\tres.push(str.slice(index));\r\n\t\t}\r\n\t\treturn res;\r\n\t};\r\n\r\n\t// Returns the iterator of grapheme clusters there are in the given string\r\n\tthis.iterateGraphemes = function(str) {\r\n\t\tvar index = 0;\r\n\t\tvar res = {\r\n\t\t\tnext: (function() {\r\n\t\t\t\tvar value;\r\n\t\t\t\tvar brk;\r\n\t\t\t\tif ((brk = this.nextBreak(str, index)) < str.length) {\r\n\t\t\t\t\tvalue = str.slice(index, brk);\r\n\t\t\t\t\tindex = brk;\r\n\t\t\t\t\treturn { value: value, done: false };\r\n\t\t\t\t}\r\n\t\t\t\tif (index < str.length) {\r\n\t\t\t\t\tvalue = str.slice(index);\r\n\t\t\t\t\tindex = str.length;\r\n\t\t\t\t\treturn { value: value, done: false };\r\n\t\t\t\t}\r\n\t\t\t\treturn { value: undefined, done: true };\r\n\t\t\t}).bind(this)\r\n\t\t};\r\n\t\t// ES2015 @@iterator method (iterable) for spread syntax and for...of statement\r\n\t\tif (typeof Symbol !== 'undefined' && Symbol.iterator) {\r\n\t\t\tres[Symbol.iterator] = function() {return res};\r\n\t\t}\r\n\t\treturn res;\r\n\t};\r\n\r\n\t// Returns the number of grapheme clusters there are in the given string\r\n\tthis.countGraphemes = function(str){\r\n\t\tvar count = 0;\r\n\t\tvar index = 0;\r\n\t\tvar brk;\r\n\t\twhile((brk = this.nextBreak(str, index)) < str.length){\r\n\t\t\tindex = brk;\r\n\t\t\tcount++;\r\n\t\t}\r\n\t\tif(index < str.length){\r\n\t\t\tcount++;\r\n\t\t}\r\n\t\treturn count;\r\n\t};\r\n\t\r\n\t//given a Unicode code point, determines this symbol's grapheme break property\r\n\tfunction getGraphemeBreakProperty(code){\r\n\t\t\r\n\t\t//grapheme break property for Unicode 10.0.0, \r\n\t\t//taken from http://www.unicode.org/Public/10.0.0/ucd/auxiliary/GraphemeBreakProperty.txt\r\n\t\t//and adapted to JavaScript rules\r\n\t\t\r\n\t\tif(\t\t\r\n\t\t(0x0600 <= code && code <= 0x0605) || // Cf [6] ARABIC NUMBER SIGN..ARABIC NUMBER MARK ABOVE\r\n\t\t0x06DD == code || // Cf ARABIC END OF AYAH\r\n\t\t0x070F == code || // Cf SYRIAC ABBREVIATION MARK\r\n\t\t0x08E2 == code || // Cf ARABIC DISPUTED END OF AYAH\r\n\t\t0x0D4E == code || // Lo MALAYALAM LETTER DOT REPH\r\n\t\t0x110BD == code || // Cf KAITHI NUMBER SIGN\r\n\t\t(0x111C2 <= code && code <= 0x111C3) || // Lo [2] SHARADA SIGN JIHVAMULIYA..SHARADA SIGN UPADHMANIYA\r\n\t\t0x11A3A == code || // Lo ZANABAZAR SQUARE CLUSTER-INITIAL LETTER RA\r\n\t\t(0x11A86 <= code && code <= 0x11A89) || // Lo [4] SOYOMBO CLUSTER-INITIAL LETTER RA..SOYOMBO CLUSTER-INITIAL LETTER SA\r\n\t\t0x11D46 == code // Lo MASARAM GONDI REPHA\r\n\t\t){\r\n\t\t\treturn Prepend;\r\n\t\t}\r\n\t\tif(\r\n\t\t0x000D == code // Cc \r\n\t\t){\r\n\t\t\treturn CR;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t0x000A == code // Cc \r\n\t\t){\r\n\t\t\treturn LF;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(\r\n\t\t(0x0000 <= code && code <= 0x0009) || // Cc [10] ..\r\n\t\t(0x000B <= code && code <= 0x000C) || // Cc [2] ..\r\n\t\t(0x000E <= code && code <= 0x001F) || // Cc [18] ..\r\n\t\t(0x007F <= code && code <= 0x009F) || // Cc [33] ..\r\n\t\t0x00AD == code || // Cf SOFT HYPHEN\r\n\t\t0x061C == code || // Cf ARABIC LETTER MARK\r\n\t\r\n\t\t0x180E == code || // Cf MONGOLIAN VOWEL SEPARATOR\r\n\t\t0x200B == code || // Cf ZERO WIDTH SPACE\r\n\t\t(0x200E <= code && code <= 0x200F) || // Cf [2] LEFT-TO-RIGHT MARK..RIGHT-TO-LEFT MARK\r\n\t\t0x2028 == code || // Zl LINE SEPARATOR\r\n\t\t0x2029 == code || // Zp PARAGRAPH SEPARATOR\r\n\t\t(0x202A <= code && code <= 0x202E) || // Cf [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE\r\n\t\t(0x2060 <= code && code <= 0x2064) || // Cf [5] WORD JOINER..INVISIBLE PLUS\r\n\t\t0x2065 == code || // Cn \r\n\t\t(0x2066 <= code && code <= 0x206F) || // Cf [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES\r\n\t\t(0xD800 <= code && code <= 0xDFFF) || // Cs [2048] ..\r\n\t\t0xFEFF == code || // Cf ZERO WIDTH NO-BREAK SPACE\r\n\t\t(0xFFF0 <= code && code <= 0xFFF8) || // Cn [9] ..\r\n\t\t(0xFFF9 <= code && code <= 0xFFFB) || // Cf [3] INTERLINEAR ANNOTATION ANCHOR..INTERLINEAR ANNOTATION TERMINATOR\r\n\t\t(0x1BCA0 <= code && code <= 0x1BCA3) || // Cf [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP\r\n\t\t(0x1D173 <= code && code <= 0x1D17A) || // Cf [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE\r\n\t\t0xE0000 == code || // Cn \r\n\t\t0xE0001 == code || // Cf LANGUAGE TAG\r\n\t\t(0xE0002 <= code && code <= 0xE001F) || // Cn [30] ..\r\n\t\t(0xE0080 <= code && code <= 0xE00FF) || // Cn [128] ..\r\n\t\t(0xE01F0 <= code && code <= 0xE0FFF) // Cn [3600] ..\r\n\t\t){\r\n\t\t\treturn Control;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(\r\n\t\t(0x0300 <= code && code <= 0x036F) || // Mn [112] COMBINING GRAVE ACCENT..COMBINING LATIN SMALL LETTER X\r\n\t\t(0x0483 <= code && code <= 0x0487) || // Mn [5] COMBINING CYRILLIC TITLO..COMBINING CYRILLIC POKRYTIE\r\n\t\t(0x0488 <= code && code <= 0x0489) || // Me [2] COMBINING CYRILLIC HUNDRED THOUSANDS SIGN..COMBINING CYRILLIC MILLIONS SIGN\r\n\t\t(0x0591 <= code && code <= 0x05BD) || // Mn [45] HEBREW ACCENT ETNAHTA..HEBREW POINT METEG\r\n\t\t0x05BF == code || // Mn HEBREW POINT RAFE\r\n\t\t(0x05C1 <= code && code <= 0x05C2) || // Mn [2] HEBREW POINT SHIN DOT..HEBREW POINT SIN DOT\r\n\t\t(0x05C4 <= code && code <= 0x05C5) || // Mn [2] HEBREW MARK UPPER DOT..HEBREW MARK LOWER DOT\r\n\t\t0x05C7 == code || // Mn HEBREW POINT QAMATS QATAN\r\n\t\t(0x0610 <= code && code <= 0x061A) || // Mn [11] ARABIC SIGN SALLALLAHOU ALAYHE WASSALLAM..ARABIC SMALL KASRA\r\n\t\t(0x064B <= code && code <= 0x065F) || // Mn [21] ARABIC FATHATAN..ARABIC WAVY HAMZA BELOW\r\n\t\t0x0670 == code || // Mn ARABIC LETTER SUPERSCRIPT ALEF\r\n\t\t(0x06D6 <= code && code <= 0x06DC) || // Mn [7] ARABIC SMALL HIGH LIGATURE SAD WITH LAM WITH ALEF MAKSURA..ARABIC SMALL HIGH SEEN\r\n\t\t(0x06DF <= code && code <= 0x06E4) || // Mn [6] ARABIC SMALL HIGH ROUNDED ZERO..ARABIC SMALL HIGH MADDA\r\n\t\t(0x06E7 <= code && code <= 0x06E8) || // Mn [2] ARABIC SMALL HIGH YEH..ARABIC SMALL HIGH NOON\r\n\t\t(0x06EA <= code && code <= 0x06ED) || // Mn [4] ARABIC EMPTY CENTRE LOW STOP..ARABIC SMALL LOW MEEM\r\n\t\t0x0711 == code || // Mn SYRIAC LETTER SUPERSCRIPT ALAPH\r\n\t\t(0x0730 <= code && code <= 0x074A) || // Mn [27] SYRIAC PTHAHA ABOVE..SYRIAC BARREKH\r\n\t\t(0x07A6 <= code && code <= 0x07B0) || // Mn [11] THAANA ABAFILI..THAANA SUKUN\r\n\t\t(0x07EB <= code && code <= 0x07F3) || // Mn [9] NKO COMBINING SHORT HIGH TONE..NKO COMBINING DOUBLE DOT ABOVE\r\n\t\t(0x0816 <= code && code <= 0x0819) || // Mn [4] SAMARITAN MARK IN..SAMARITAN MARK DAGESH\r\n\t\t(0x081B <= code && code <= 0x0823) || // Mn [9] SAMARITAN MARK EPENTHETIC YUT..SAMARITAN VOWEL SIGN A\r\n\t\t(0x0825 <= code && code <= 0x0827) || // Mn [3] SAMARITAN VOWEL SIGN SHORT A..SAMARITAN VOWEL SIGN U\r\n\t\t(0x0829 <= code && code <= 0x082D) || // Mn [5] SAMARITAN VOWEL SIGN LONG I..SAMARITAN MARK NEQUDAA\r\n\t\t(0x0859 <= code && code <= 0x085B) || // Mn [3] MANDAIC AFFRICATION MARK..MANDAIC GEMINATION MARK\r\n\t\t(0x08D4 <= code && code <= 0x08E1) || // Mn [14] ARABIC SMALL HIGH WORD AR-RUB..ARABIC SMALL HIGH SIGN SAFHA\r\n\t\t(0x08E3 <= code && code <= 0x0902) || // Mn [32] ARABIC TURNED DAMMA BELOW..DEVANAGARI SIGN ANUSVARA\r\n\t\t0x093A == code || // Mn DEVANAGARI VOWEL SIGN OE\r\n\t\t0x093C == code || // Mn DEVANAGARI SIGN NUKTA\r\n\t\t(0x0941 <= code && code <= 0x0948) || // Mn [8] DEVANAGARI VOWEL SIGN U..DEVANAGARI VOWEL SIGN AI\r\n\t\t0x094D == code || // Mn DEVANAGARI SIGN VIRAMA\r\n\t\t(0x0951 <= code && code <= 0x0957) || // Mn [7] DEVANAGARI STRESS SIGN UDATTA..DEVANAGARI VOWEL SIGN UUE\r\n\t\t(0x0962 <= code && code <= 0x0963) || // Mn [2] DEVANAGARI VOWEL SIGN VOCALIC L..DEVANAGARI VOWEL SIGN VOCALIC LL\r\n\t\t0x0981 == code || // Mn BENGALI SIGN CANDRABINDU\r\n\t\t0x09BC == code || // Mn BENGALI SIGN NUKTA\r\n\t\t0x09BE == code || // Mc BENGALI VOWEL SIGN AA\r\n\t\t(0x09C1 <= code && code <= 0x09C4) || // Mn [4] BENGALI VOWEL SIGN U..BENGALI VOWEL SIGN VOCALIC RR\r\n\t\t0x09CD == code || // Mn BENGALI SIGN VIRAMA\r\n\t\t0x09D7 == code || // Mc BENGALI AU LENGTH MARK\r\n\t\t(0x09E2 <= code && code <= 0x09E3) || // Mn [2] BENGALI VOWEL SIGN VOCALIC L..BENGALI VOWEL SIGN VOCALIC LL\r\n\t\t(0x0A01 <= code && code <= 0x0A02) || // Mn [2] GURMUKHI SIGN ADAK BINDI..GURMUKHI SIGN BINDI\r\n\t\t0x0A3C == code || // Mn GURMUKHI SIGN NUKTA\r\n\t\t(0x0A41 <= code && code <= 0x0A42) || // Mn [2] GURMUKHI VOWEL SIGN U..GURMUKHI VOWEL SIGN UU\r\n\t\t(0x0A47 <= code && code <= 0x0A48) || // Mn [2] GURMUKHI VOWEL SIGN EE..GURMUKHI VOWEL SIGN AI\r\n\t\t(0x0A4B <= code && code <= 0x0A4D) || // Mn [3] GURMUKHI VOWEL SIGN OO..GURMUKHI SIGN VIRAMA\r\n\t\t0x0A51 == code || // Mn GURMUKHI SIGN UDAAT\r\n\t\t(0x0A70 <= code && code <= 0x0A71) || // Mn [2] GURMUKHI TIPPI..GURMUKHI ADDAK\r\n\t\t0x0A75 == code || // Mn GURMUKHI SIGN YAKASH\r\n\t\t(0x0A81 <= code && code <= 0x0A82) || // Mn [2] GUJARATI SIGN CANDRABINDU..GUJARATI SIGN ANUSVARA\r\n\t\t0x0ABC == code || // Mn GUJARATI SIGN NUKTA\r\n\t\t(0x0AC1 <= code && code <= 0x0AC5) || // Mn [5] GUJARATI VOWEL SIGN U..GUJARATI VOWEL SIGN CANDRA E\r\n\t\t(0x0AC7 <= code && code <= 0x0AC8) || // Mn [2] GUJARATI VOWEL SIGN E..GUJARATI VOWEL SIGN AI\r\n\t\t0x0ACD == code || // Mn GUJARATI SIGN VIRAMA\r\n\t\t(0x0AE2 <= code && code <= 0x0AE3) || // Mn [2] GUJARATI VOWEL SIGN VOCALIC L..GUJARATI VOWEL SIGN VOCALIC LL\r\n\t\t(0x0AFA <= code && code <= 0x0AFF) || // Mn [6] GUJARATI SIGN SUKUN..GUJARATI SIGN TWO-CIRCLE NUKTA ABOVE\r\n\t\t0x0B01 == code || // Mn ORIYA SIGN CANDRABINDU\r\n\t\t0x0B3C == code || // Mn ORIYA SIGN NUKTA\r\n\t\t0x0B3E == code || // Mc ORIYA VOWEL SIGN AA\r\n\t\t0x0B3F == code || // Mn ORIYA VOWEL SIGN I\r\n\t\t(0x0B41 <= code && code <= 0x0B44) || // Mn [4] ORIYA VOWEL SIGN U..ORIYA VOWEL SIGN VOCALIC RR\r\n\t\t0x0B4D == code || // Mn ORIYA SIGN VIRAMA\r\n\t\t0x0B56 == code || // Mn ORIYA AI LENGTH MARK\r\n\t\t0x0B57 == code || // Mc ORIYA AU LENGTH MARK\r\n\t\t(0x0B62 <= code && code <= 0x0B63) || // Mn [2] ORIYA VOWEL SIGN VOCALIC L..ORIYA VOWEL SIGN VOCALIC LL\r\n\t\t0x0B82 == code || // Mn TAMIL SIGN ANUSVARA\r\n\t\t0x0BBE == code || // Mc TAMIL VOWEL SIGN AA\r\n\t\t0x0BC0 == code || // Mn TAMIL VOWEL SIGN II\r\n\t\t0x0BCD == code || // Mn TAMIL SIGN VIRAMA\r\n\t\t0x0BD7 == code || // Mc TAMIL AU LENGTH MARK\r\n\t\t0x0C00 == code || // Mn TELUGU SIGN COMBINING CANDRABINDU ABOVE\r\n\t\t(0x0C3E <= code && code <= 0x0C40) || // Mn [3] TELUGU VOWEL SIGN AA..TELUGU VOWEL SIGN II\r\n\t\t(0x0C46 <= code && code <= 0x0C48) || // Mn [3] TELUGU VOWEL SIGN E..TELUGU VOWEL SIGN AI\r\n\t\t(0x0C4A <= code && code <= 0x0C4D) || // Mn [4] TELUGU VOWEL SIGN O..TELUGU SIGN VIRAMA\r\n\t\t(0x0C55 <= code && code <= 0x0C56) || // Mn [2] TELUGU LENGTH MARK..TELUGU AI LENGTH MARK\r\n\t\t(0x0C62 <= code && code <= 0x0C63) || // Mn [2] TELUGU VOWEL SIGN VOCALIC L..TELUGU VOWEL SIGN VOCALIC LL\r\n\t\t0x0C81 == code || // Mn KANNADA SIGN CANDRABINDU\r\n\t\t0x0CBC == code || // Mn KANNADA SIGN NUKTA\r\n\t\t0x0CBF == code || // Mn KANNADA VOWEL SIGN I\r\n\t\t0x0CC2 == code || // Mc KANNADA VOWEL SIGN UU\r\n\t\t0x0CC6 == code || // Mn KANNADA VOWEL SIGN E\r\n\t\t(0x0CCC <= code && code <= 0x0CCD) || // Mn [2] KANNADA VOWEL SIGN AU..KANNADA SIGN VIRAMA\r\n\t\t(0x0CD5 <= code && code <= 0x0CD6) || // Mc [2] KANNADA LENGTH MARK..KANNADA AI LENGTH MARK\r\n\t\t(0x0CE2 <= code && code <= 0x0CE3) || // Mn [2] KANNADA VOWEL SIGN VOCALIC L..KANNADA VOWEL SIGN VOCALIC LL\r\n\t\t(0x0D00 <= code && code <= 0x0D01) || // Mn [2] MALAYALAM SIGN COMBINING ANUSVARA ABOVE..MALAYALAM SIGN CANDRABINDU\r\n\t\t(0x0D3B <= code && code <= 0x0D3C) || // Mn [2] MALAYALAM SIGN VERTICAL BAR VIRAMA..MALAYALAM SIGN CIRCULAR VIRAMA\r\n\t\t0x0D3E == code || // Mc MALAYALAM VOWEL SIGN AA\r\n\t\t(0x0D41 <= code && code <= 0x0D44) || // Mn [4] MALAYALAM VOWEL SIGN U..MALAYALAM VOWEL SIGN VOCALIC RR\r\n\t\t0x0D4D == code || // Mn MALAYALAM SIGN VIRAMA\r\n\t\t0x0D57 == code || // Mc MALAYALAM AU LENGTH MARK\r\n\t\t(0x0D62 <= code && code <= 0x0D63) || // Mn [2] MALAYALAM VOWEL SIGN VOCALIC L..MALAYALAM VOWEL SIGN VOCALIC LL\r\n\t\t0x0DCA == code || // Mn SINHALA SIGN AL-LAKUNA\r\n\t\t0x0DCF == code || // Mc SINHALA VOWEL SIGN AELA-PILLA\r\n\t\t(0x0DD2 <= code && code <= 0x0DD4) || // Mn [3] SINHALA VOWEL SIGN KETTI IS-PILLA..SINHALA VOWEL SIGN KETTI PAA-PILLA\r\n\t\t0x0DD6 == code || // Mn SINHALA VOWEL SIGN DIGA PAA-PILLA\r\n\t\t0x0DDF == code || // Mc SINHALA VOWEL SIGN GAYANUKITTA\r\n\t\t0x0E31 == code || // Mn THAI CHARACTER MAI HAN-AKAT\r\n\t\t(0x0E34 <= code && code <= 0x0E3A) || // Mn [7] THAI CHARACTER SARA I..THAI CHARACTER PHINTHU\r\n\t\t(0x0E47 <= code && code <= 0x0E4E) || // Mn [8] THAI CHARACTER MAITAIKHU..THAI CHARACTER YAMAKKAN\r\n\t\t0x0EB1 == code || // Mn LAO VOWEL SIGN MAI KAN\r\n\t\t(0x0EB4 <= code && code <= 0x0EB9) || // Mn [6] LAO VOWEL SIGN I..LAO VOWEL SIGN UU\r\n\t\t(0x0EBB <= code && code <= 0x0EBC) || // Mn [2] LAO VOWEL SIGN MAI KON..LAO SEMIVOWEL SIGN LO\r\n\t\t(0x0EC8 <= code && code <= 0x0ECD) || // Mn [6] LAO TONE MAI EK..LAO NIGGAHITA\r\n\t\t(0x0F18 <= code && code <= 0x0F19) || // Mn [2] TIBETAN ASTROLOGICAL SIGN -KHYUD PA..TIBETAN ASTROLOGICAL SIGN SDONG TSHUGS\r\n\t\t0x0F35 == code || // Mn TIBETAN MARK NGAS BZUNG NYI ZLA\r\n\t\t0x0F37 == code || // Mn TIBETAN MARK NGAS BZUNG SGOR RTAGS\r\n\t\t0x0F39 == code || // Mn TIBETAN MARK TSA -PHRU\r\n\t\t(0x0F71 <= code && code <= 0x0F7E) || // Mn [14] TIBETAN VOWEL SIGN AA..TIBETAN SIGN RJES SU NGA RO\r\n\t\t(0x0F80 <= code && code <= 0x0F84) || // Mn [5] TIBETAN VOWEL SIGN REVERSED I..TIBETAN MARK HALANTA\r\n\t\t(0x0F86 <= code && code <= 0x0F87) || // Mn [2] TIBETAN SIGN LCI RTAGS..TIBETAN SIGN YANG RTAGS\r\n\t\t(0x0F8D <= code && code <= 0x0F97) || // Mn [11] TIBETAN SUBJOINED SIGN LCE TSA CAN..TIBETAN SUBJOINED LETTER JA\r\n\t\t(0x0F99 <= code && code <= 0x0FBC) || // Mn [36] TIBETAN SUBJOINED LETTER NYA..TIBETAN SUBJOINED LETTER FIXED-FORM RA\r\n\t\t0x0FC6 == code || // Mn TIBETAN SYMBOL PADMA GDAN\r\n\t\t(0x102D <= code && code <= 0x1030) || // Mn [4] MYANMAR VOWEL SIGN I..MYANMAR VOWEL SIGN UU\r\n\t\t(0x1032 <= code && code <= 0x1037) || // Mn [6] MYANMAR VOWEL SIGN AI..MYANMAR SIGN DOT BELOW\r\n\t\t(0x1039 <= code && code <= 0x103A) || // Mn [2] MYANMAR SIGN VIRAMA..MYANMAR SIGN ASAT\r\n\t\t(0x103D <= code && code <= 0x103E) || // Mn [2] MYANMAR CONSONANT SIGN MEDIAL WA..MYANMAR CONSONANT SIGN MEDIAL HA\r\n\t\t(0x1058 <= code && code <= 0x1059) || // Mn [2] MYANMAR VOWEL SIGN VOCALIC L..MYANMAR VOWEL SIGN VOCALIC LL\r\n\t\t(0x105E <= code && code <= 0x1060) || // Mn [3] MYANMAR CONSONANT SIGN MON MEDIAL NA..MYANMAR CONSONANT SIGN MON MEDIAL LA\r\n\t\t(0x1071 <= code && code <= 0x1074) || // Mn [4] MYANMAR VOWEL SIGN GEBA KAREN I..MYANMAR VOWEL SIGN KAYAH EE\r\n\t\t0x1082 == code || // Mn MYANMAR CONSONANT SIGN SHAN MEDIAL WA\r\n\t\t(0x1085 <= code && code <= 0x1086) || // Mn [2] MYANMAR VOWEL SIGN SHAN E ABOVE..MYANMAR VOWEL SIGN SHAN FINAL Y\r\n\t\t0x108D == code || // Mn MYANMAR SIGN SHAN COUNCIL EMPHATIC TONE\r\n\t\t0x109D == code || // Mn MYANMAR VOWEL SIGN AITON AI\r\n\t\t(0x135D <= code && code <= 0x135F) || // Mn [3] ETHIOPIC COMBINING GEMINATION AND VOWEL LENGTH MARK..ETHIOPIC COMBINING GEMINATION MARK\r\n\t\t(0x1712 <= code && code <= 0x1714) || // Mn [3] TAGALOG VOWEL SIGN I..TAGALOG SIGN VIRAMA\r\n\t\t(0x1732 <= code && code <= 0x1734) || // Mn [3] HANUNOO VOWEL SIGN I..HANUNOO SIGN PAMUDPOD\r\n\t\t(0x1752 <= code && code <= 0x1753) || // Mn [2] BUHID VOWEL SIGN I..BUHID VOWEL SIGN U\r\n\t\t(0x1772 <= code && code <= 0x1773) || // Mn [2] TAGBANWA VOWEL SIGN I..TAGBANWA VOWEL SIGN U\r\n\t\t(0x17B4 <= code && code <= 0x17B5) || // Mn [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA\r\n\t\t(0x17B7 <= code && code <= 0x17BD) || // Mn [7] KHMER VOWEL SIGN I..KHMER VOWEL SIGN UA\r\n\t\t0x17C6 == code || // Mn KHMER SIGN NIKAHIT\r\n\t\t(0x17C9 <= code && code <= 0x17D3) || // Mn [11] KHMER SIGN MUUSIKATOAN..KHMER SIGN BATHAMASAT\r\n\t\t0x17DD == code || // Mn KHMER SIGN ATTHACAN\r\n\t\t(0x180B <= code && code <= 0x180D) || // Mn [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE\r\n\t\t(0x1885 <= code && code <= 0x1886) || // Mn [2] MONGOLIAN LETTER ALI GALI BALUDA..MONGOLIAN LETTER ALI GALI THREE BALUDA\r\n\t\t0x18A9 == code || // Mn MONGOLIAN LETTER ALI GALI DAGALGA\r\n\t\t(0x1920 <= code && code <= 0x1922) || // Mn [3] LIMBU VOWEL SIGN A..LIMBU VOWEL SIGN U\r\n\t\t(0x1927 <= code && code <= 0x1928) || // Mn [2] LIMBU VOWEL SIGN E..LIMBU VOWEL SIGN O\r\n\t\t0x1932 == code || // Mn LIMBU SMALL LETTER ANUSVARA\r\n\t\t(0x1939 <= code && code <= 0x193B) || // Mn [3] LIMBU SIGN MUKPHRENG..LIMBU SIGN SA-I\r\n\t\t(0x1A17 <= code && code <= 0x1A18) || // Mn [2] BUGINESE VOWEL SIGN I..BUGINESE VOWEL SIGN U\r\n\t\t0x1A1B == code || // Mn BUGINESE VOWEL SIGN AE\r\n\t\t0x1A56 == code || // Mn TAI THAM CONSONANT SIGN MEDIAL LA\r\n\t\t(0x1A58 <= code && code <= 0x1A5E) || // Mn [7] TAI THAM SIGN MAI KANG LAI..TAI THAM CONSONANT SIGN SA\r\n\t\t0x1A60 == code || // Mn TAI THAM SIGN SAKOT\r\n\t\t0x1A62 == code || // Mn TAI THAM VOWEL SIGN MAI SAT\r\n\t\t(0x1A65 <= code && code <= 0x1A6C) || // Mn [8] TAI THAM VOWEL SIGN I..TAI THAM VOWEL SIGN OA BELOW\r\n\t\t(0x1A73 <= code && code <= 0x1A7C) || // Mn [10] TAI THAM VOWEL SIGN OA ABOVE..TAI THAM SIGN KHUEN-LUE KARAN\r\n\t\t0x1A7F == code || // Mn TAI THAM COMBINING CRYPTOGRAMMIC DOT\r\n\t\t(0x1AB0 <= code && code <= 0x1ABD) || // Mn [14] COMBINING DOUBLED CIRCUMFLEX ACCENT..COMBINING PARENTHESES BELOW\r\n\t\t0x1ABE == code || // Me COMBINING PARENTHESES OVERLAY\r\n\t\t(0x1B00 <= code && code <= 0x1B03) || // Mn [4] BALINESE SIGN ULU RICEM..BALINESE SIGN SURANG\r\n\t\t0x1B34 == code || // Mn BALINESE SIGN REREKAN\r\n\t\t(0x1B36 <= code && code <= 0x1B3A) || // Mn [5] BALINESE VOWEL SIGN ULU..BALINESE VOWEL SIGN RA REPA\r\n\t\t0x1B3C == code || // Mn BALINESE VOWEL SIGN LA LENGA\r\n\t\t0x1B42 == code || // Mn BALINESE VOWEL SIGN PEPET\r\n\t\t(0x1B6B <= code && code <= 0x1B73) || // Mn [9] BALINESE MUSICAL SYMBOL COMBINING TEGEH..BALINESE MUSICAL SYMBOL COMBINING GONG\r\n\t\t(0x1B80 <= code && code <= 0x1B81) || // Mn [2] SUNDANESE SIGN PANYECEK..SUNDANESE SIGN PANGLAYAR\r\n\t\t(0x1BA2 <= code && code <= 0x1BA5) || // Mn [4] SUNDANESE CONSONANT SIGN PANYAKRA..SUNDANESE VOWEL SIGN PANYUKU\r\n\t\t(0x1BA8 <= code && code <= 0x1BA9) || // Mn [2] SUNDANESE VOWEL SIGN PAMEPET..SUNDANESE VOWEL SIGN PANEULEUNG\r\n\t\t(0x1BAB <= code && code <= 0x1BAD) || // Mn [3] SUNDANESE SIGN VIRAMA..SUNDANESE CONSONANT SIGN PASANGAN WA\r\n\t\t0x1BE6 == code || // Mn BATAK SIGN TOMPI\r\n\t\t(0x1BE8 <= code && code <= 0x1BE9) || // Mn [2] BATAK VOWEL SIGN PAKPAK E..BATAK VOWEL SIGN EE\r\n\t\t0x1BED == code || // Mn BATAK VOWEL SIGN KARO O\r\n\t\t(0x1BEF <= code && code <= 0x1BF1) || // Mn [3] BATAK VOWEL SIGN U FOR SIMALUNGUN SA..BATAK CONSONANT SIGN H\r\n\t\t(0x1C2C <= code && code <= 0x1C33) || // Mn [8] LEPCHA VOWEL SIGN E..LEPCHA CONSONANT SIGN T\r\n\t\t(0x1C36 <= code && code <= 0x1C37) || // Mn [2] LEPCHA SIGN RAN..LEPCHA SIGN NUKTA\r\n\t\t(0x1CD0 <= code && code <= 0x1CD2) || // Mn [3] VEDIC TONE KARSHANA..VEDIC TONE PRENKHA\r\n\t\t(0x1CD4 <= code && code <= 0x1CE0) || // Mn [13] VEDIC SIGN YAJURVEDIC MIDLINE SVARITA..VEDIC TONE RIGVEDIC KASHMIRI INDEPENDENT SVARITA\r\n\t\t(0x1CE2 <= code && code <= 0x1CE8) || // Mn [7] VEDIC SIGN VISARGA SVARITA..VEDIC SIGN VISARGA ANUDATTA WITH TAIL\r\n\t\t0x1CED == code || // Mn VEDIC SIGN TIRYAK\r\n\t\t0x1CF4 == code || // Mn VEDIC TONE CANDRA ABOVE\r\n\t\t(0x1CF8 <= code && code <= 0x1CF9) || // Mn [2] VEDIC TONE RING ABOVE..VEDIC TONE DOUBLE RING ABOVE\r\n\t\t(0x1DC0 <= code && code <= 0x1DF9) || // Mn [58] COMBINING DOTTED GRAVE ACCENT..COMBINING WIDE INVERTED BRIDGE BELOW\r\n\t\t(0x1DFB <= code && code <= 0x1DFF) || // Mn [5] COMBINING DELETION MARK..COMBINING RIGHT ARROWHEAD AND DOWN ARROWHEAD BELOW\r\n\t\t0x200C == code || // Cf ZERO WIDTH NON-JOINER\r\n\t\t(0x20D0 <= code && code <= 0x20DC) || // Mn [13] COMBINING LEFT HARPOON ABOVE..COMBINING FOUR DOTS ABOVE\r\n\t\t(0x20DD <= code && code <= 0x20E0) || // Me [4] COMBINING ENCLOSING CIRCLE..COMBINING ENCLOSING CIRCLE BACKSLASH\r\n\t\t0x20E1 == code || // Mn COMBINING LEFT RIGHT ARROW ABOVE\r\n\t\t(0x20E2 <= code && code <= 0x20E4) || // Me [3] COMBINING ENCLOSING SCREEN..COMBINING ENCLOSING UPWARD POINTING TRIANGLE\r\n\t\t(0x20E5 <= code && code <= 0x20F0) || // Mn [12] COMBINING REVERSE SOLIDUS OVERLAY..COMBINING ASTERISK ABOVE\r\n\t\t(0x2CEF <= code && code <= 0x2CF1) || // Mn [3] COPTIC COMBINING NI ABOVE..COPTIC COMBINING SPIRITUS LENIS\r\n\t\t0x2D7F == code || // Mn TIFINAGH CONSONANT JOINER\r\n\t\t(0x2DE0 <= code && code <= 0x2DFF) || // Mn [32] COMBINING CYRILLIC LETTER BE..COMBINING CYRILLIC LETTER IOTIFIED BIG YUS\r\n\t\t(0x302A <= code && code <= 0x302D) || // Mn [4] IDEOGRAPHIC LEVEL TONE MARK..IDEOGRAPHIC ENTERING TONE MARK\r\n\t\t(0x302E <= code && code <= 0x302F) || // Mc [2] HANGUL SINGLE DOT TONE MARK..HANGUL DOUBLE DOT TONE MARK\r\n\t\t(0x3099 <= code && code <= 0x309A) || // Mn [2] COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK..COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK\r\n\t\t0xA66F == code || // Mn COMBINING CYRILLIC VZMET\r\n\t\t(0xA670 <= code && code <= 0xA672) || // Me [3] COMBINING CYRILLIC TEN MILLIONS SIGN..COMBINING CYRILLIC THOUSAND MILLIONS SIGN\r\n\t\t(0xA674 <= code && code <= 0xA67D) || // Mn [10] COMBINING CYRILLIC LETTER UKRAINIAN IE..COMBINING CYRILLIC PAYEROK\r\n\t\t(0xA69E <= code && code <= 0xA69F) || // Mn [2] COMBINING CYRILLIC LETTER EF..COMBINING CYRILLIC LETTER IOTIFIED E\r\n\t\t(0xA6F0 <= code && code <= 0xA6F1) || // Mn [2] BAMUM COMBINING MARK KOQNDON..BAMUM COMBINING MARK TUKWENTIS\r\n\t\t0xA802 == code || // Mn SYLOTI NAGRI SIGN DVISVARA\r\n\t\t0xA806 == code || // Mn SYLOTI NAGRI SIGN HASANTA\r\n\t\t0xA80B == code || // Mn SYLOTI NAGRI SIGN ANUSVARA\r\n\t\t(0xA825 <= code && code <= 0xA826) || // Mn [2] SYLOTI NAGRI VOWEL SIGN U..SYLOTI NAGRI VOWEL SIGN E\r\n\t\t(0xA8C4 <= code && code <= 0xA8C5) || // Mn [2] SAURASHTRA SIGN VIRAMA..SAURASHTRA SIGN CANDRABINDU\r\n\t\t(0xA8E0 <= code && code <= 0xA8F1) || // Mn [18] COMBINING DEVANAGARI DIGIT ZERO..COMBINING DEVANAGARI SIGN AVAGRAHA\r\n\t\t(0xA926 <= code && code <= 0xA92D) || // Mn [8] KAYAH LI VOWEL UE..KAYAH LI TONE CALYA PLOPHU\r\n\t\t(0xA947 <= code && code <= 0xA951) || // Mn [11] REJANG VOWEL SIGN I..REJANG CONSONANT SIGN R\r\n\t\t(0xA980 <= code && code <= 0xA982) || // Mn [3] JAVANESE SIGN PANYANGGA..JAVANESE SIGN LAYAR\r\n\t\t0xA9B3 == code || // Mn JAVANESE SIGN CECAK TELU\r\n\t\t(0xA9B6 <= code && code <= 0xA9B9) || // Mn [4] JAVANESE VOWEL SIGN WULU..JAVANESE VOWEL SIGN SUKU MENDUT\r\n\t\t0xA9BC == code || // Mn JAVANESE VOWEL SIGN PEPET\r\n\t\t0xA9E5 == code || // Mn MYANMAR SIGN SHAN SAW\r\n\t\t(0xAA29 <= code && code <= 0xAA2E) || // Mn [6] CHAM VOWEL SIGN AA..CHAM VOWEL SIGN OE\r\n\t\t(0xAA31 <= code && code <= 0xAA32) || // Mn [2] CHAM VOWEL SIGN AU..CHAM VOWEL SIGN UE\r\n\t\t(0xAA35 <= code && code <= 0xAA36) || // Mn [2] CHAM CONSONANT SIGN LA..CHAM CONSONANT SIGN WA\r\n\t\t0xAA43 == code || // Mn CHAM CONSONANT SIGN FINAL NG\r\n\t\t0xAA4C == code || // Mn CHAM CONSONANT SIGN FINAL M\r\n\t\t0xAA7C == code || // Mn MYANMAR SIGN TAI LAING TONE-2\r\n\t\t0xAAB0 == code || // Mn TAI VIET MAI KANG\r\n\t\t(0xAAB2 <= code && code <= 0xAAB4) || // Mn [3] TAI VIET VOWEL I..TAI VIET VOWEL U\r\n\t\t(0xAAB7 <= code && code <= 0xAAB8) || // Mn [2] TAI VIET MAI KHIT..TAI VIET VOWEL IA\r\n\t\t(0xAABE <= code && code <= 0xAABF) || // Mn [2] TAI VIET VOWEL AM..TAI VIET TONE MAI EK\r\n\t\t0xAAC1 == code || // Mn TAI VIET TONE MAI THO\r\n\t\t(0xAAEC <= code && code <= 0xAAED) || // Mn [2] MEETEI MAYEK VOWEL SIGN UU..MEETEI MAYEK VOWEL SIGN AAI\r\n\t\t0xAAF6 == code || // Mn MEETEI MAYEK VIRAMA\r\n\t\t0xABE5 == code || // Mn MEETEI MAYEK VOWEL SIGN ANAP\r\n\t\t0xABE8 == code || // Mn MEETEI MAYEK VOWEL SIGN UNAP\r\n\t\t0xABED == code || // Mn MEETEI MAYEK APUN IYEK\r\n\t\t0xFB1E == code || // Mn HEBREW POINT JUDEO-SPANISH VARIKA\r\n\t\t(0xFE00 <= code && code <= 0xFE0F) || // Mn [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16\r\n\t\t(0xFE20 <= code && code <= 0xFE2F) || // Mn [16] COMBINING LIGATURE LEFT HALF..COMBINING CYRILLIC TITLO RIGHT HALF\r\n\t\t(0xFF9E <= code && code <= 0xFF9F) || // Lm [2] HALFWIDTH KATAKANA VOICED SOUND MARK..HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK\r\n\t\t0x101FD == code || // Mn PHAISTOS DISC SIGN COMBINING OBLIQUE STROKE\r\n\t\t0x102E0 == code || // Mn COPTIC EPACT THOUSANDS MARK\r\n\t\t(0x10376 <= code && code <= 0x1037A) || // Mn [5] COMBINING OLD PERMIC LETTER AN..COMBINING OLD PERMIC LETTER SII\r\n\t\t(0x10A01 <= code && code <= 0x10A03) || // Mn [3] KHAROSHTHI VOWEL SIGN I..KHAROSHTHI VOWEL SIGN VOCALIC R\r\n\t\t(0x10A05 <= code && code <= 0x10A06) || // Mn [2] KHAROSHTHI VOWEL SIGN E..KHAROSHTHI VOWEL SIGN O\r\n\t\t(0x10A0C <= code && code <= 0x10A0F) || // Mn [4] KHAROSHTHI VOWEL LENGTH MARK..KHAROSHTHI SIGN VISARGA\r\n\t\t(0x10A38 <= code && code <= 0x10A3A) || // Mn [3] KHAROSHTHI SIGN BAR ABOVE..KHAROSHTHI SIGN DOT BELOW\r\n\t\t0x10A3F == code || // Mn KHAROSHTHI VIRAMA\r\n\t\t(0x10AE5 <= code && code <= 0x10AE6) || // Mn [2] MANICHAEAN ABBREVIATION MARK ABOVE..MANICHAEAN ABBREVIATION MARK BELOW\r\n\t\t0x11001 == code || // Mn BRAHMI SIGN ANUSVARA\r\n\t\t(0x11038 <= code && code <= 0x11046) || // Mn [15] BRAHMI VOWEL SIGN AA..BRAHMI VIRAMA\r\n\t\t(0x1107F <= code && code <= 0x11081) || // Mn [3] BRAHMI NUMBER JOINER..KAITHI SIGN ANUSVARA\r\n\t\t(0x110B3 <= code && code <= 0x110B6) || // Mn [4] KAITHI VOWEL SIGN U..KAITHI VOWEL SIGN AI\r\n\t\t(0x110B9 <= code && code <= 0x110BA) || // Mn [2] KAITHI SIGN VIRAMA..KAITHI SIGN NUKTA\r\n\t\t(0x11100 <= code && code <= 0x11102) || // Mn [3] CHAKMA SIGN CANDRABINDU..CHAKMA SIGN VISARGA\r\n\t\t(0x11127 <= code && code <= 0x1112B) || // Mn [5] CHAKMA VOWEL SIGN A..CHAKMA VOWEL SIGN UU\r\n\t\t(0x1112D <= code && code <= 0x11134) || // Mn [8] CHAKMA VOWEL SIGN AI..CHAKMA MAAYYAA\r\n\t\t0x11173 == code || // Mn MAHAJANI SIGN NUKTA\r\n\t\t(0x11180 <= code && code <= 0x11181) || // Mn [2] SHARADA SIGN CANDRABINDU..SHARADA SIGN ANUSVARA\r\n\t\t(0x111B6 <= code && code <= 0x111BE) || // Mn [9] SHARADA VOWEL SIGN U..SHARADA VOWEL SIGN O\r\n\t\t(0x111CA <= code && code <= 0x111CC) || // Mn [3] SHARADA SIGN NUKTA..SHARADA EXTRA SHORT VOWEL MARK\r\n\t\t(0x1122F <= code && code <= 0x11231) || // Mn [3] KHOJKI VOWEL SIGN U..KHOJKI VOWEL SIGN AI\r\n\t\t0x11234 == code || // Mn KHOJKI SIGN ANUSVARA\r\n\t\t(0x11236 <= code && code <= 0x11237) || // Mn [2] KHOJKI SIGN NUKTA..KHOJKI SIGN SHADDA\r\n\t\t0x1123E == code || // Mn KHOJKI SIGN SUKUN\r\n\t\t0x112DF == code || // Mn KHUDAWADI SIGN ANUSVARA\r\n\t\t(0x112E3 <= code && code <= 0x112EA) || // Mn [8] KHUDAWADI VOWEL SIGN U..KHUDAWADI SIGN VIRAMA\r\n\t\t(0x11300 <= code && code <= 0x11301) || // Mn [2] GRANTHA SIGN COMBINING ANUSVARA ABOVE..GRANTHA SIGN CANDRABINDU\r\n\t\t0x1133C == code || // Mn GRANTHA SIGN NUKTA\r\n\t\t0x1133E == code || // Mc GRANTHA VOWEL SIGN AA\r\n\t\t0x11340 == code || // Mn GRANTHA VOWEL SIGN II\r\n\t\t0x11357 == code || // Mc GRANTHA AU LENGTH MARK\r\n\t\t(0x11366 <= code && code <= 0x1136C) || // Mn [7] COMBINING GRANTHA DIGIT ZERO..COMBINING GRANTHA DIGIT SIX\r\n\t\t(0x11370 <= code && code <= 0x11374) || // Mn [5] COMBINING GRANTHA LETTER A..COMBINING GRANTHA LETTER PA\r\n\t\t(0x11438 <= code && code <= 0x1143F) || // Mn [8] NEWA VOWEL SIGN U..NEWA VOWEL SIGN AI\r\n\t\t(0x11442 <= code && code <= 0x11444) || // Mn [3] NEWA SIGN VIRAMA..NEWA SIGN ANUSVARA\r\n\t\t0x11446 == code || // Mn NEWA SIGN NUKTA\r\n\t\t0x114B0 == code || // Mc TIRHUTA VOWEL SIGN AA\r\n\t\t(0x114B3 <= code && code <= 0x114B8) || // Mn [6] TIRHUTA VOWEL SIGN U..TIRHUTA VOWEL SIGN VOCALIC LL\r\n\t\t0x114BA == code || // Mn TIRHUTA VOWEL SIGN SHORT E\r\n\t\t0x114BD == code || // Mc TIRHUTA VOWEL SIGN SHORT O\r\n\t\t(0x114BF <= code && code <= 0x114C0) || // Mn [2] TIRHUTA SIGN CANDRABINDU..TIRHUTA SIGN ANUSVARA\r\n\t\t(0x114C2 <= code && code <= 0x114C3) || // Mn [2] TIRHUTA SIGN VIRAMA..TIRHUTA SIGN NUKTA\r\n\t\t0x115AF == code || // Mc SIDDHAM VOWEL SIGN AA\r\n\t\t(0x115B2 <= code && code <= 0x115B5) || // Mn [4] SIDDHAM VOWEL SIGN U..SIDDHAM VOWEL SIGN VOCALIC RR\r\n\t\t(0x115BC <= code && code <= 0x115BD) || // Mn [2] SIDDHAM SIGN CANDRABINDU..SIDDHAM SIGN ANUSVARA\r\n\t\t(0x115BF <= code && code <= 0x115C0) || // Mn [2] SIDDHAM SIGN VIRAMA..SIDDHAM SIGN NUKTA\r\n\t\t(0x115DC <= code && code <= 0x115DD) || // Mn [2] SIDDHAM VOWEL SIGN ALTERNATE U..SIDDHAM VOWEL SIGN ALTERNATE UU\r\n\t\t(0x11633 <= code && code <= 0x1163A) || // Mn [8] MODI VOWEL SIGN U..MODI VOWEL SIGN AI\r\n\t\t0x1163D == code || // Mn MODI SIGN ANUSVARA\r\n\t\t(0x1163F <= code && code <= 0x11640) || // Mn [2] MODI SIGN VIRAMA..MODI SIGN ARDHACANDRA\r\n\t\t0x116AB == code || // Mn TAKRI SIGN ANUSVARA\r\n\t\t0x116AD == code || // Mn TAKRI VOWEL SIGN AA\r\n\t\t(0x116B0 <= code && code <= 0x116B5) || // Mn [6] TAKRI VOWEL SIGN U..TAKRI VOWEL SIGN AU\r\n\t\t0x116B7 == code || // Mn TAKRI SIGN NUKTA\r\n\t\t(0x1171D <= code && code <= 0x1171F) || // Mn [3] AHOM CONSONANT SIGN MEDIAL LA..AHOM CONSONANT SIGN MEDIAL LIGATING RA\r\n\t\t(0x11722 <= code && code <= 0x11725) || // Mn [4] AHOM VOWEL SIGN I..AHOM VOWEL SIGN UU\r\n\t\t(0x11727 <= code && code <= 0x1172B) || // Mn [5] AHOM VOWEL SIGN AW..AHOM SIGN KILLER\r\n\t\t(0x11A01 <= code && code <= 0x11A06) || // Mn [6] ZANABAZAR SQUARE VOWEL SIGN I..ZANABAZAR SQUARE VOWEL SIGN O\r\n\t\t(0x11A09 <= code && code <= 0x11A0A) || // Mn [2] ZANABAZAR SQUARE VOWEL SIGN REVERSED I..ZANABAZAR SQUARE VOWEL LENGTH MARK\r\n\t\t(0x11A33 <= code && code <= 0x11A38) || // Mn [6] ZANABAZAR SQUARE FINAL CONSONANT MARK..ZANABAZAR SQUARE SIGN ANUSVARA\r\n\t\t(0x11A3B <= code && code <= 0x11A3E) || // Mn [4] ZANABAZAR SQUARE CLUSTER-FINAL LETTER YA..ZANABAZAR SQUARE CLUSTER-FINAL LETTER VA\r\n\t\t0x11A47 == code || // Mn ZANABAZAR SQUARE SUBJOINER\r\n\t\t(0x11A51 <= code && code <= 0x11A56) || // Mn [6] SOYOMBO VOWEL SIGN I..SOYOMBO VOWEL SIGN OE\r\n\t\t(0x11A59 <= code && code <= 0x11A5B) || // Mn [3] SOYOMBO VOWEL SIGN VOCALIC R..SOYOMBO VOWEL LENGTH MARK\r\n\t\t(0x11A8A <= code && code <= 0x11A96) || // Mn [13] SOYOMBO FINAL CONSONANT SIGN G..SOYOMBO SIGN ANUSVARA\r\n\t\t(0x11A98 <= code && code <= 0x11A99) || // Mn [2] SOYOMBO GEMINATION MARK..SOYOMBO SUBJOINER\r\n\t\t(0x11C30 <= code && code <= 0x11C36) || // Mn [7] BHAIKSUKI VOWEL SIGN I..BHAIKSUKI VOWEL SIGN VOCALIC L\r\n\t\t(0x11C38 <= code && code <= 0x11C3D) || // Mn [6] BHAIKSUKI VOWEL SIGN E..BHAIKSUKI SIGN ANUSVARA\r\n\t\t0x11C3F == code || // Mn BHAIKSUKI SIGN VIRAMA\r\n\t\t(0x11C92 <= code && code <= 0x11CA7) || // Mn [22] MARCHEN SUBJOINED LETTER KA..MARCHEN SUBJOINED LETTER ZA\r\n\t\t(0x11CAA <= code && code <= 0x11CB0) || // Mn [7] MARCHEN SUBJOINED LETTER RA..MARCHEN VOWEL SIGN AA\r\n\t\t(0x11CB2 <= code && code <= 0x11CB3) || // Mn [2] MARCHEN VOWEL SIGN U..MARCHEN VOWEL SIGN E\r\n\t\t(0x11CB5 <= code && code <= 0x11CB6) || // Mn [2] MARCHEN SIGN ANUSVARA..MARCHEN SIGN CANDRABINDU\r\n\t\t(0x11D31 <= code && code <= 0x11D36) || // Mn [6] MASARAM GONDI VOWEL SIGN AA..MASARAM GONDI VOWEL SIGN VOCALIC R\r\n\t\t0x11D3A == code || // Mn MASARAM GONDI VOWEL SIGN E\r\n\t\t(0x11D3C <= code && code <= 0x11D3D) || // Mn [2] MASARAM GONDI VOWEL SIGN AI..MASARAM GONDI VOWEL SIGN O\r\n\t\t(0x11D3F <= code && code <= 0x11D45) || // Mn [7] MASARAM GONDI VOWEL SIGN AU..MASARAM GONDI VIRAMA\r\n\t\t0x11D47 == code || // Mn MASARAM GONDI RA-KARA\r\n\t\t(0x16AF0 <= code && code <= 0x16AF4) || // Mn [5] BASSA VAH COMBINING HIGH TONE..BASSA VAH COMBINING HIGH-LOW TONE\r\n\t\t(0x16B30 <= code && code <= 0x16B36) || // Mn [7] PAHAWH HMONG MARK CIM TUB..PAHAWH HMONG MARK CIM TAUM\r\n\t\t(0x16F8F <= code && code <= 0x16F92) || // Mn [4] MIAO TONE RIGHT..MIAO TONE BELOW\r\n\t\t(0x1BC9D <= code && code <= 0x1BC9E) || // Mn [2] DUPLOYAN THICK LETTER SELECTOR..DUPLOYAN DOUBLE MARK\r\n\t\t0x1D165 == code || // Mc MUSICAL SYMBOL COMBINING STEM\r\n\t\t(0x1D167 <= code && code <= 0x1D169) || // Mn [3] MUSICAL SYMBOL COMBINING TREMOLO-1..MUSICAL SYMBOL COMBINING TREMOLO-3\r\n\t\t(0x1D16E <= code && code <= 0x1D172) || // Mc [5] MUSICAL SYMBOL COMBINING FLAG-1..MUSICAL SYMBOL COMBINING FLAG-5\r\n\t\t(0x1D17B <= code && code <= 0x1D182) || // Mn [8] MUSICAL SYMBOL COMBINING ACCENT..MUSICAL SYMBOL COMBINING LOURE\r\n\t\t(0x1D185 <= code && code <= 0x1D18B) || // Mn [7] MUSICAL SYMBOL COMBINING DOIT..MUSICAL SYMBOL COMBINING TRIPLE TONGUE\r\n\t\t(0x1D1AA <= code && code <= 0x1D1AD) || // Mn [4] MUSICAL SYMBOL COMBINING DOWN BOW..MUSICAL SYMBOL COMBINING SNAP PIZZICATO\r\n\t\t(0x1D242 <= code && code <= 0x1D244) || // Mn [3] COMBINING GREEK MUSICAL TRISEME..COMBINING GREEK MUSICAL PENTASEME\r\n\t\t(0x1DA00 <= code && code <= 0x1DA36) || // Mn [55] SIGNWRITING HEAD RIM..SIGNWRITING AIR SUCKING IN\r\n\t\t(0x1DA3B <= code && code <= 0x1DA6C) || // Mn [50] SIGNWRITING MOUTH CLOSED NEUTRAL..SIGNWRITING EXCITEMENT\r\n\t\t0x1DA75 == code || // Mn SIGNWRITING UPPER BODY TILTING FROM HIP JOINTS\r\n\t\t0x1DA84 == code || // Mn SIGNWRITING LOCATION HEAD NECK\r\n\t\t(0x1DA9B <= code && code <= 0x1DA9F) || // Mn [5] SIGNWRITING FILL MODIFIER-2..SIGNWRITING FILL MODIFIER-6\r\n\t\t(0x1DAA1 <= code && code <= 0x1DAAF) || // Mn [15] SIGNWRITING ROTATION MODIFIER-2..SIGNWRITING ROTATION MODIFIER-16\r\n\t\t(0x1E000 <= code && code <= 0x1E006) || // Mn [7] COMBINING GLAGOLITIC LETTER AZU..COMBINING GLAGOLITIC LETTER ZHIVETE\r\n\t\t(0x1E008 <= code && code <= 0x1E018) || // Mn [17] COMBINING GLAGOLITIC LETTER ZEMLJA..COMBINING GLAGOLITIC LETTER HERU\r\n\t\t(0x1E01B <= code && code <= 0x1E021) || // Mn [7] COMBINING GLAGOLITIC LETTER SHTA..COMBINING GLAGOLITIC LETTER YATI\r\n\t\t(0x1E023 <= code && code <= 0x1E024) || // Mn [2] COMBINING GLAGOLITIC LETTER YU..COMBINING GLAGOLITIC LETTER SMALL YUS\r\n\t\t(0x1E026 <= code && code <= 0x1E02A) || // Mn [5] COMBINING GLAGOLITIC LETTER YO..COMBINING GLAGOLITIC LETTER FITA\r\n\t\t(0x1E8D0 <= code && code <= 0x1E8D6) || // Mn [7] MENDE KIKAKUI COMBINING NUMBER TEENS..MENDE KIKAKUI COMBINING NUMBER MILLIONS\r\n\t\t(0x1E944 <= code && code <= 0x1E94A) || // Mn [7] ADLAM ALIF LENGTHENER..ADLAM NUKTA\r\n\t\t(0xE0020 <= code && code <= 0xE007F) || // Cf [96] TAG SPACE..CANCEL TAG\r\n\t\t(0xE0100 <= code && code <= 0xE01EF) // Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256\r\n\t\t){\r\n\t\t\treturn Extend;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(\r\n\t\t(0x1F1E6 <= code && code <= 0x1F1FF) // So [26] REGIONAL INDICATOR SYMBOL LETTER A..REGIONAL INDICATOR SYMBOL LETTER Z\r\n\t\t){\r\n\t\t\treturn Regional_Indicator;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t0x0903 == code || // Mc DEVANAGARI SIGN VISARGA\r\n\t\t0x093B == code || // Mc DEVANAGARI VOWEL SIGN OOE\r\n\t\t(0x093E <= code && code <= 0x0940) || // Mc [3] DEVANAGARI VOWEL SIGN AA..DEVANAGARI VOWEL SIGN II\r\n\t\t(0x0949 <= code && code <= 0x094C) || // Mc [4] DEVANAGARI VOWEL SIGN CANDRA O..DEVANAGARI VOWEL SIGN AU\r\n\t\t(0x094E <= code && code <= 0x094F) || // Mc [2] DEVANAGARI VOWEL SIGN PRISHTHAMATRA E..DEVANAGARI VOWEL SIGN AW\r\n\t\t(0x0982 <= code && code <= 0x0983) || // Mc [2] BENGALI SIGN ANUSVARA..BENGALI SIGN VISARGA\r\n\t\t(0x09BF <= code && code <= 0x09C0) || // Mc [2] BENGALI VOWEL SIGN I..BENGALI VOWEL SIGN II\r\n\t\t(0x09C7 <= code && code <= 0x09C8) || // Mc [2] BENGALI VOWEL SIGN E..BENGALI VOWEL SIGN AI\r\n\t\t(0x09CB <= code && code <= 0x09CC) || // Mc [2] BENGALI VOWEL SIGN O..BENGALI VOWEL SIGN AU\r\n\t\t0x0A03 == code || // Mc GURMUKHI SIGN VISARGA\r\n\t\t(0x0A3E <= code && code <= 0x0A40) || // Mc [3] GURMUKHI VOWEL SIGN AA..GURMUKHI VOWEL SIGN II\r\n\t\t0x0A83 == code || // Mc GUJARATI SIGN VISARGA\r\n\t\t(0x0ABE <= code && code <= 0x0AC0) || // Mc [3] GUJARATI VOWEL SIGN AA..GUJARATI VOWEL SIGN II\r\n\t\t0x0AC9 == code || // Mc GUJARATI VOWEL SIGN CANDRA O\r\n\t\t(0x0ACB <= code && code <= 0x0ACC) || // Mc [2] GUJARATI VOWEL SIGN O..GUJARATI VOWEL SIGN AU\r\n\t\t(0x0B02 <= code && code <= 0x0B03) || // Mc [2] ORIYA SIGN ANUSVARA..ORIYA SIGN VISARGA\r\n\t\t0x0B40 == code || // Mc ORIYA VOWEL SIGN II\r\n\t\t(0x0B47 <= code && code <= 0x0B48) || // Mc [2] ORIYA VOWEL SIGN E..ORIYA VOWEL SIGN AI\r\n\t\t(0x0B4B <= code && code <= 0x0B4C) || // Mc [2] ORIYA VOWEL SIGN O..ORIYA VOWEL SIGN AU\r\n\t\t0x0BBF == code || // Mc TAMIL VOWEL SIGN I\r\n\t\t(0x0BC1 <= code && code <= 0x0BC2) || // Mc [2] TAMIL VOWEL SIGN U..TAMIL VOWEL SIGN UU\r\n\t\t(0x0BC6 <= code && code <= 0x0BC8) || // Mc [3] TAMIL VOWEL SIGN E..TAMIL VOWEL SIGN AI\r\n\t\t(0x0BCA <= code && code <= 0x0BCC) || // Mc [3] TAMIL VOWEL SIGN O..TAMIL VOWEL SIGN AU\r\n\t\t(0x0C01 <= code && code <= 0x0C03) || // Mc [3] TELUGU SIGN CANDRABINDU..TELUGU SIGN VISARGA\r\n\t\t(0x0C41 <= code && code <= 0x0C44) || // Mc [4] TELUGU VOWEL SIGN U..TELUGU VOWEL SIGN VOCALIC RR\r\n\t\t(0x0C82 <= code && code <= 0x0C83) || // Mc [2] KANNADA SIGN ANUSVARA..KANNADA SIGN VISARGA\r\n\t\t0x0CBE == code || // Mc KANNADA VOWEL SIGN AA\r\n\t\t(0x0CC0 <= code && code <= 0x0CC1) || // Mc [2] KANNADA VOWEL SIGN II..KANNADA VOWEL SIGN U\r\n\t\t(0x0CC3 <= code && code <= 0x0CC4) || // Mc [2] KANNADA VOWEL SIGN VOCALIC R..KANNADA VOWEL SIGN VOCALIC RR\r\n\t\t(0x0CC7 <= code && code <= 0x0CC8) || // Mc [2] KANNADA VOWEL SIGN EE..KANNADA VOWEL SIGN AI\r\n\t\t(0x0CCA <= code && code <= 0x0CCB) || // Mc [2] KANNADA VOWEL SIGN O..KANNADA VOWEL SIGN OO\r\n\t\t(0x0D02 <= code && code <= 0x0D03) || // Mc [2] MALAYALAM SIGN ANUSVARA..MALAYALAM SIGN VISARGA\r\n\t\t(0x0D3F <= code && code <= 0x0D40) || // Mc [2] MALAYALAM VOWEL SIGN I..MALAYALAM VOWEL SIGN II\r\n\t\t(0x0D46 <= code && code <= 0x0D48) || // Mc [3] MALAYALAM VOWEL SIGN E..MALAYALAM VOWEL SIGN AI\r\n\t\t(0x0D4A <= code && code <= 0x0D4C) || // Mc [3] MALAYALAM VOWEL SIGN O..MALAYALAM VOWEL SIGN AU\r\n\t\t(0x0D82 <= code && code <= 0x0D83) || // Mc [2] SINHALA SIGN ANUSVARAYA..SINHALA SIGN VISARGAYA\r\n\t\t(0x0DD0 <= code && code <= 0x0DD1) || // Mc [2] SINHALA VOWEL SIGN KETTI AEDA-PILLA..SINHALA VOWEL SIGN DIGA AEDA-PILLA\r\n\t\t(0x0DD8 <= code && code <= 0x0DDE) || // Mc [7] SINHALA VOWEL SIGN GAETTA-PILLA..SINHALA VOWEL SIGN KOMBUVA HAA GAYANUKITTA\r\n\t\t(0x0DF2 <= code && code <= 0x0DF3) || // Mc [2] SINHALA VOWEL SIGN DIGA GAETTA-PILLA..SINHALA VOWEL SIGN DIGA GAYANUKITTA\r\n\t\t0x0E33 == code || // Lo THAI CHARACTER SARA AM\r\n\t\t0x0EB3 == code || // Lo LAO VOWEL SIGN AM\r\n\t\t(0x0F3E <= code && code <= 0x0F3F) || // Mc [2] TIBETAN SIGN YAR TSHES..TIBETAN SIGN MAR TSHES\r\n\t\t0x0F7F == code || // Mc TIBETAN SIGN RNAM BCAD\r\n\t\t0x1031 == code || // Mc MYANMAR VOWEL SIGN E\r\n\t\t(0x103B <= code && code <= 0x103C) || // Mc [2] MYANMAR CONSONANT SIGN MEDIAL YA..MYANMAR CONSONANT SIGN MEDIAL RA\r\n\t\t(0x1056 <= code && code <= 0x1057) || // Mc [2] MYANMAR VOWEL SIGN VOCALIC R..MYANMAR VOWEL SIGN VOCALIC RR\r\n\t\t0x1084 == code || // Mc MYANMAR VOWEL SIGN SHAN E\r\n\t\t0x17B6 == code || // Mc KHMER VOWEL SIGN AA\r\n\t\t(0x17BE <= code && code <= 0x17C5) || // Mc [8] KHMER VOWEL SIGN OE..KHMER VOWEL SIGN AU\r\n\t\t(0x17C7 <= code && code <= 0x17C8) || // Mc [2] KHMER SIGN REAHMUK..KHMER SIGN YUUKALEAPINTU\r\n\t\t(0x1923 <= code && code <= 0x1926) || // Mc [4] LIMBU VOWEL SIGN EE..LIMBU VOWEL SIGN AU\r\n\t\t(0x1929 <= code && code <= 0x192B) || // Mc [3] LIMBU SUBJOINED LETTER YA..LIMBU SUBJOINED LETTER WA\r\n\t\t(0x1930 <= code && code <= 0x1931) || // Mc [2] LIMBU SMALL LETTER KA..LIMBU SMALL LETTER NGA\r\n\t\t(0x1933 <= code && code <= 0x1938) || // Mc [6] LIMBU SMALL LETTER TA..LIMBU SMALL LETTER LA\r\n\t\t(0x1A19 <= code && code <= 0x1A1A) || // Mc [2] BUGINESE VOWEL SIGN E..BUGINESE VOWEL SIGN O\r\n\t\t0x1A55 == code || // Mc TAI THAM CONSONANT SIGN MEDIAL RA\r\n\t\t0x1A57 == code || // Mc TAI THAM CONSONANT SIGN LA TANG LAI\r\n\t\t(0x1A6D <= code && code <= 0x1A72) || // Mc [6] TAI THAM VOWEL SIGN OY..TAI THAM VOWEL SIGN THAM AI\r\n\t\t0x1B04 == code || // Mc BALINESE SIGN BISAH\r\n\t\t0x1B35 == code || // Mc BALINESE VOWEL SIGN TEDUNG\r\n\t\t0x1B3B == code || // Mc BALINESE VOWEL SIGN RA REPA TEDUNG\r\n\t\t(0x1B3D <= code && code <= 0x1B41) || // Mc [5] BALINESE VOWEL SIGN LA LENGA TEDUNG..BALINESE VOWEL SIGN TALING REPA TEDUNG\r\n\t\t(0x1B43 <= code && code <= 0x1B44) || // Mc [2] BALINESE VOWEL SIGN PEPET TEDUNG..BALINESE ADEG ADEG\r\n\t\t0x1B82 == code || // Mc SUNDANESE SIGN PANGWISAD\r\n\t\t0x1BA1 == code || // Mc SUNDANESE CONSONANT SIGN PAMINGKAL\r\n\t\t(0x1BA6 <= code && code <= 0x1BA7) || // Mc [2] SUNDANESE VOWEL SIGN PANAELAENG..SUNDANESE VOWEL SIGN PANOLONG\r\n\t\t0x1BAA == code || // Mc SUNDANESE SIGN PAMAAEH\r\n\t\t0x1BE7 == code || // Mc BATAK VOWEL SIGN E\r\n\t\t(0x1BEA <= code && code <= 0x1BEC) || // Mc [3] BATAK VOWEL SIGN I..BATAK VOWEL SIGN O\r\n\t\t0x1BEE == code || // Mc BATAK VOWEL SIGN U\r\n\t\t(0x1BF2 <= code && code <= 0x1BF3) || // Mc [2] BATAK PANGOLAT..BATAK PANONGONAN\r\n\t\t(0x1C24 <= code && code <= 0x1C2B) || // Mc [8] LEPCHA SUBJOINED LETTER YA..LEPCHA VOWEL SIGN UU\r\n\t\t(0x1C34 <= code && code <= 0x1C35) || // Mc [2] LEPCHA CONSONANT SIGN NYIN-DO..LEPCHA CONSONANT SIGN KANG\r\n\t\t0x1CE1 == code || // Mc VEDIC TONE ATHARVAVEDIC INDEPENDENT SVARITA\r\n\t\t(0x1CF2 <= code && code <= 0x1CF3) || // Mc [2] VEDIC SIGN ARDHAVISARGA..VEDIC SIGN ROTATED ARDHAVISARGA\r\n\t\t0x1CF7 == code || // Mc VEDIC SIGN ATIKRAMA\r\n\t\t(0xA823 <= code && code <= 0xA824) || // Mc [2] SYLOTI NAGRI VOWEL SIGN A..SYLOTI NAGRI VOWEL SIGN I\r\n\t\t0xA827 == code || // Mc SYLOTI NAGRI VOWEL SIGN OO\r\n\t\t(0xA880 <= code && code <= 0xA881) || // Mc [2] SAURASHTRA SIGN ANUSVARA..SAURASHTRA SIGN VISARGA\r\n\t\t(0xA8B4 <= code && code <= 0xA8C3) || // Mc [16] SAURASHTRA CONSONANT SIGN HAARU..SAURASHTRA VOWEL SIGN AU\r\n\t\t(0xA952 <= code && code <= 0xA953) || // Mc [2] REJANG CONSONANT SIGN H..REJANG VIRAMA\r\n\t\t0xA983 == code || // Mc JAVANESE SIGN WIGNYAN\r\n\t\t(0xA9B4 <= code && code <= 0xA9B5) || // Mc [2] JAVANESE VOWEL SIGN TARUNG..JAVANESE VOWEL SIGN TOLONG\r\n\t\t(0xA9BA <= code && code <= 0xA9BB) || // Mc [2] JAVANESE VOWEL SIGN TALING..JAVANESE VOWEL SIGN DIRGA MURE\r\n\t\t(0xA9BD <= code && code <= 0xA9C0) || // Mc [4] JAVANESE CONSONANT SIGN KERET..JAVANESE PANGKON\r\n\t\t(0xAA2F <= code && code <= 0xAA30) || // Mc [2] CHAM VOWEL SIGN O..CHAM VOWEL SIGN AI\r\n\t\t(0xAA33 <= code && code <= 0xAA34) || // Mc [2] CHAM CONSONANT SIGN YA..CHAM CONSONANT SIGN RA\r\n\t\t0xAA4D == code || // Mc CHAM CONSONANT SIGN FINAL H\r\n\t\t0xAAEB == code || // Mc MEETEI MAYEK VOWEL SIGN II\r\n\t\t(0xAAEE <= code && code <= 0xAAEF) || // Mc [2] MEETEI MAYEK VOWEL SIGN AU..MEETEI MAYEK VOWEL SIGN AAU\r\n\t\t0xAAF5 == code || // Mc MEETEI MAYEK VOWEL SIGN VISARGA\r\n\t\t(0xABE3 <= code && code <= 0xABE4) || // Mc [2] MEETEI MAYEK VOWEL SIGN ONAP..MEETEI MAYEK VOWEL SIGN INAP\r\n\t\t(0xABE6 <= code && code <= 0xABE7) || // Mc [2] MEETEI MAYEK VOWEL SIGN YENAP..MEETEI MAYEK VOWEL SIGN SOUNAP\r\n\t\t(0xABE9 <= code && code <= 0xABEA) || // Mc [2] MEETEI MAYEK VOWEL SIGN CHEINAP..MEETEI MAYEK VOWEL SIGN NUNG\r\n\t\t0xABEC == code || // Mc MEETEI MAYEK LUM IYEK\r\n\t\t0x11000 == code || // Mc BRAHMI SIGN CANDRABINDU\r\n\t\t0x11002 == code || // Mc BRAHMI SIGN VISARGA\r\n\t\t0x11082 == code || // Mc KAITHI SIGN VISARGA\r\n\t\t(0x110B0 <= code && code <= 0x110B2) || // Mc [3] KAITHI VOWEL SIGN AA..KAITHI VOWEL SIGN II\r\n\t\t(0x110B7 <= code && code <= 0x110B8) || // Mc [2] KAITHI VOWEL SIGN O..KAITHI VOWEL SIGN AU\r\n\t\t0x1112C == code || // Mc CHAKMA VOWEL SIGN E\r\n\t\t0x11182 == code || // Mc SHARADA SIGN VISARGA\r\n\t\t(0x111B3 <= code && code <= 0x111B5) || // Mc [3] SHARADA VOWEL SIGN AA..SHARADA VOWEL SIGN II\r\n\t\t(0x111BF <= code && code <= 0x111C0) || // Mc [2] SHARADA VOWEL SIGN AU..SHARADA SIGN VIRAMA\r\n\t\t(0x1122C <= code && code <= 0x1122E) || // Mc [3] KHOJKI VOWEL SIGN AA..KHOJKI VOWEL SIGN II\r\n\t\t(0x11232 <= code && code <= 0x11233) || // Mc [2] KHOJKI VOWEL SIGN O..KHOJKI VOWEL SIGN AU\r\n\t\t0x11235 == code || // Mc KHOJKI SIGN VIRAMA\r\n\t\t(0x112E0 <= code && code <= 0x112E2) || // Mc [3] KHUDAWADI VOWEL SIGN AA..KHUDAWADI VOWEL SIGN II\r\n\t\t(0x11302 <= code && code <= 0x11303) || // Mc [2] GRANTHA SIGN ANUSVARA..GRANTHA SIGN VISARGA\r\n\t\t0x1133F == code || // Mc GRANTHA VOWEL SIGN I\r\n\t\t(0x11341 <= code && code <= 0x11344) || // Mc [4] GRANTHA VOWEL SIGN U..GRANTHA VOWEL SIGN VOCALIC RR\r\n\t\t(0x11347 <= code && code <= 0x11348) || // Mc [2] GRANTHA VOWEL SIGN EE..GRANTHA VOWEL SIGN AI\r\n\t\t(0x1134B <= code && code <= 0x1134D) || // Mc [3] GRANTHA VOWEL SIGN OO..GRANTHA SIGN VIRAMA\r\n\t\t(0x11362 <= code && code <= 0x11363) || // Mc [2] GRANTHA VOWEL SIGN VOCALIC L..GRANTHA VOWEL SIGN VOCALIC LL\r\n\t\t(0x11435 <= code && code <= 0x11437) || // Mc [3] NEWA VOWEL SIGN AA..NEWA VOWEL SIGN II\r\n\t\t(0x11440 <= code && code <= 0x11441) || // Mc [2] NEWA VOWEL SIGN O..NEWA VOWEL SIGN AU\r\n\t\t0x11445 == code || // Mc NEWA SIGN VISARGA\r\n\t\t(0x114B1 <= code && code <= 0x114B2) || // Mc [2] TIRHUTA VOWEL SIGN I..TIRHUTA VOWEL SIGN II\r\n\t\t0x114B9 == code || // Mc TIRHUTA VOWEL SIGN E\r\n\t\t(0x114BB <= code && code <= 0x114BC) || // Mc [2] TIRHUTA VOWEL SIGN AI..TIRHUTA VOWEL SIGN O\r\n\t\t0x114BE == code || // Mc TIRHUTA VOWEL SIGN AU\r\n\t\t0x114C1 == code || // Mc TIRHUTA SIGN VISARGA\r\n\t\t(0x115B0 <= code && code <= 0x115B1) || // Mc [2] SIDDHAM VOWEL SIGN I..SIDDHAM VOWEL SIGN II\r\n\t\t(0x115B8 <= code && code <= 0x115BB) || // Mc [4] SIDDHAM VOWEL SIGN E..SIDDHAM VOWEL SIGN AU\r\n\t\t0x115BE == code || // Mc SIDDHAM SIGN VISARGA\r\n\t\t(0x11630 <= code && code <= 0x11632) || // Mc [3] MODI VOWEL SIGN AA..MODI VOWEL SIGN II\r\n\t\t(0x1163B <= code && code <= 0x1163C) || // Mc [2] MODI VOWEL SIGN O..MODI VOWEL SIGN AU\r\n\t\t0x1163E == code || // Mc MODI SIGN VISARGA\r\n\t\t0x116AC == code || // Mc TAKRI SIGN VISARGA\r\n\t\t(0x116AE <= code && code <= 0x116AF) || // Mc [2] TAKRI VOWEL SIGN I..TAKRI VOWEL SIGN II\r\n\t\t0x116B6 == code || // Mc TAKRI SIGN VIRAMA\r\n\t\t(0x11720 <= code && code <= 0x11721) || // Mc [2] AHOM VOWEL SIGN A..AHOM VOWEL SIGN AA\r\n\t\t0x11726 == code || // Mc AHOM VOWEL SIGN E\r\n\t\t(0x11A07 <= code && code <= 0x11A08) || // Mc [2] ZANABAZAR SQUARE VOWEL SIGN AI..ZANABAZAR SQUARE VOWEL SIGN AU\r\n\t\t0x11A39 == code || // Mc ZANABAZAR SQUARE SIGN VISARGA\r\n\t\t(0x11A57 <= code && code <= 0x11A58) || // Mc [2] SOYOMBO VOWEL SIGN AI..SOYOMBO VOWEL SIGN AU\r\n\t\t0x11A97 == code || // Mc SOYOMBO SIGN VISARGA\r\n\t\t0x11C2F == code || // Mc BHAIKSUKI VOWEL SIGN AA\r\n\t\t0x11C3E == code || // Mc BHAIKSUKI SIGN VISARGA\r\n\t\t0x11CA9 == code || // Mc MARCHEN SUBJOINED LETTER YA\r\n\t\t0x11CB1 == code || // Mc MARCHEN VOWEL SIGN I\r\n\t\t0x11CB4 == code || // Mc MARCHEN VOWEL SIGN O\r\n\t\t(0x16F51 <= code && code <= 0x16F7E) || // Mc [46] MIAO SIGN ASPIRATION..MIAO VOWEL SIGN NG\r\n\t\t0x1D166 == code || // Mc MUSICAL SYMBOL COMBINING SPRECHGESANG STEM\r\n\t\t0x1D16D == code // Mc MUSICAL SYMBOL COMBINING AUGMENTATION DOT\r\n\t\t){\r\n\t\t\treturn SpacingMark;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(\r\n\t\t(0x1100 <= code && code <= 0x115F) || // Lo [96] HANGUL CHOSEONG KIYEOK..HANGUL CHOSEONG FILLER\r\n\t\t(0xA960 <= code && code <= 0xA97C) // Lo [29] HANGUL CHOSEONG TIKEUT-MIEUM..HANGUL CHOSEONG SSANGYEORINHIEUH\r\n\t\t){\r\n\t\t\treturn L;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t(0x1160 <= code && code <= 0x11A7) || // Lo [72] HANGUL JUNGSEONG FILLER..HANGUL JUNGSEONG O-YAE\r\n\t\t(0xD7B0 <= code && code <= 0xD7C6) // Lo [23] HANGUL JUNGSEONG O-YEO..HANGUL JUNGSEONG ARAEA-E\r\n\t\t){\r\n\t\t\treturn V;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tif(\r\n\t\t(0x11A8 <= code && code <= 0x11FF) || // Lo [88] HANGUL JONGSEONG KIYEOK..HANGUL JONGSEONG SSANGNIEUN\r\n\t\t(0xD7CB <= code && code <= 0xD7FB) // Lo [49] HANGUL JONGSEONG NIEUN-RIEUL..HANGUL JONGSEONG PHIEUPH-THIEUTH\r\n\t\t){\r\n\t\t\treturn T;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t0xAC00 == code || // Lo HANGUL SYLLABLE GA\r\n\t\t0xAC1C == code || // Lo HANGUL SYLLABLE GAE\r\n\t\t0xAC38 == code || // Lo HANGUL SYLLABLE GYA\r\n\t\t0xAC54 == code || // Lo HANGUL SYLLABLE GYAE\r\n\t\t0xAC70 == code || // Lo HANGUL SYLLABLE GEO\r\n\t\t0xAC8C == code || // Lo HANGUL SYLLABLE GE\r\n\t\t0xACA8 == code || // Lo HANGUL SYLLABLE GYEO\r\n\t\t0xACC4 == code || // Lo HANGUL SYLLABLE GYE\r\n\t\t0xACE0 == code || // Lo HANGUL SYLLABLE GO\r\n\t\t0xACFC == code || // Lo HANGUL SYLLABLE GWA\r\n\t\t0xAD18 == code || // Lo HANGUL SYLLABLE GWAE\r\n\t\t0xAD34 == code || // Lo HANGUL SYLLABLE GOE\r\n\t\t0xAD50 == code || // Lo HANGUL SYLLABLE GYO\r\n\t\t0xAD6C == code || // Lo HANGUL SYLLABLE GU\r\n\t\t0xAD88 == code || // Lo HANGUL SYLLABLE GWEO\r\n\t\t0xADA4 == code || // Lo HANGUL SYLLABLE GWE\r\n\t\t0xADC0 == code || // Lo HANGUL SYLLABLE GWI\r\n\t\t0xADDC == code || // Lo HANGUL SYLLABLE GYU\r\n\t\t0xADF8 == code || // Lo HANGUL SYLLABLE GEU\r\n\t\t0xAE14 == code || // Lo HANGUL SYLLABLE GYI\r\n\t\t0xAE30 == code || // Lo HANGUL SYLLABLE GI\r\n\t\t0xAE4C == code || // Lo HANGUL SYLLABLE GGA\r\n\t\t0xAE68 == code || // Lo HANGUL SYLLABLE GGAE\r\n\t\t0xAE84 == code || // Lo HANGUL SYLLABLE GGYA\r\n\t\t0xAEA0 == code || // Lo HANGUL SYLLABLE GGYAE\r\n\t\t0xAEBC == code || // Lo HANGUL SYLLABLE GGEO\r\n\t\t0xAED8 == code || // Lo HANGUL SYLLABLE GGE\r\n\t\t0xAEF4 == code || // Lo HANGUL SYLLABLE GGYEO\r\n\t\t0xAF10 == code || // Lo HANGUL SYLLABLE GGYE\r\n\t\t0xAF2C == code || // Lo HANGUL SYLLABLE GGO\r\n\t\t0xAF48 == code || // Lo HANGUL SYLLABLE GGWA\r\n\t\t0xAF64 == code || // Lo HANGUL SYLLABLE GGWAE\r\n\t\t0xAF80 == code || // Lo HANGUL SYLLABLE GGOE\r\n\t\t0xAF9C == code || // Lo HANGUL SYLLABLE GGYO\r\n\t\t0xAFB8 == code || // Lo HANGUL SYLLABLE GGU\r\n\t\t0xAFD4 == code || // Lo HANGUL SYLLABLE GGWEO\r\n\t\t0xAFF0 == code || // Lo HANGUL SYLLABLE GGWE\r\n\t\t0xB00C == code || // Lo HANGUL SYLLABLE GGWI\r\n\t\t0xB028 == code || // Lo HANGUL SYLLABLE GGYU\r\n\t\t0xB044 == code || // Lo HANGUL SYLLABLE GGEU\r\n\t\t0xB060 == code || // Lo HANGUL SYLLABLE GGYI\r\n\t\t0xB07C == code || // Lo HANGUL SYLLABLE GGI\r\n\t\t0xB098 == code || // Lo HANGUL SYLLABLE NA\r\n\t\t0xB0B4 == code || // Lo HANGUL SYLLABLE NAE\r\n\t\t0xB0D0 == code || // Lo HANGUL SYLLABLE NYA\r\n\t\t0xB0EC == code || // Lo HANGUL SYLLABLE NYAE\r\n\t\t0xB108 == code || // Lo HANGUL SYLLABLE NEO\r\n\t\t0xB124 == code || // Lo HANGUL SYLLABLE NE\r\n\t\t0xB140 == code || // Lo HANGUL SYLLABLE NYEO\r\n\t\t0xB15C == code || // Lo HANGUL SYLLABLE NYE\r\n\t\t0xB178 == code || // Lo HANGUL SYLLABLE NO\r\n\t\t0xB194 == code || // Lo HANGUL SYLLABLE NWA\r\n\t\t0xB1B0 == code || // Lo HANGUL SYLLABLE NWAE\r\n\t\t0xB1CC == code || // Lo HANGUL SYLLABLE NOE\r\n\t\t0xB1E8 == code || // Lo HANGUL SYLLABLE NYO\r\n\t\t0xB204 == code || // Lo HANGUL SYLLABLE NU\r\n\t\t0xB220 == code || // Lo HANGUL SYLLABLE NWEO\r\n\t\t0xB23C == code || // Lo HANGUL SYLLABLE NWE\r\n\t\t0xB258 == code || // Lo HANGUL SYLLABLE NWI\r\n\t\t0xB274 == code || // Lo HANGUL SYLLABLE NYU\r\n\t\t0xB290 == code || // Lo HANGUL SYLLABLE NEU\r\n\t\t0xB2AC == code || // Lo HANGUL SYLLABLE NYI\r\n\t\t0xB2C8 == code || // Lo HANGUL SYLLABLE NI\r\n\t\t0xB2E4 == code || // Lo HANGUL SYLLABLE DA\r\n\t\t0xB300 == code || // Lo HANGUL SYLLABLE DAE\r\n\t\t0xB31C == code || // Lo HANGUL SYLLABLE DYA\r\n\t\t0xB338 == code || // Lo HANGUL SYLLABLE DYAE\r\n\t\t0xB354 == code || // Lo HANGUL SYLLABLE DEO\r\n\t\t0xB370 == code || // Lo HANGUL SYLLABLE DE\r\n\t\t0xB38C == code || // Lo HANGUL SYLLABLE DYEO\r\n\t\t0xB3A8 == code || // Lo HANGUL SYLLABLE DYE\r\n\t\t0xB3C4 == code || // Lo HANGUL SYLLABLE DO\r\n\t\t0xB3E0 == code || // Lo HANGUL SYLLABLE DWA\r\n\t\t0xB3FC == code || // Lo HANGUL SYLLABLE DWAE\r\n\t\t0xB418 == code || // Lo HANGUL SYLLABLE DOE\r\n\t\t0xB434 == code || // Lo HANGUL SYLLABLE DYO\r\n\t\t0xB450 == code || // Lo HANGUL SYLLABLE DU\r\n\t\t0xB46C == code || // Lo HANGUL SYLLABLE DWEO\r\n\t\t0xB488 == code || // Lo HANGUL SYLLABLE DWE\r\n\t\t0xB4A4 == code || // Lo HANGUL SYLLABLE DWI\r\n\t\t0xB4C0 == code || // Lo HANGUL SYLLABLE DYU\r\n\t\t0xB4DC == code || // Lo HANGUL SYLLABLE DEU\r\n\t\t0xB4F8 == code || // Lo HANGUL SYLLABLE DYI\r\n\t\t0xB514 == code || // Lo HANGUL SYLLABLE DI\r\n\t\t0xB530 == code || // Lo HANGUL SYLLABLE DDA\r\n\t\t0xB54C == code || // Lo HANGUL SYLLABLE DDAE\r\n\t\t0xB568 == code || // Lo HANGUL SYLLABLE DDYA\r\n\t\t0xB584 == code || // Lo HANGUL SYLLABLE DDYAE\r\n\t\t0xB5A0 == code || // Lo HANGUL SYLLABLE DDEO\r\n\t\t0xB5BC == code || // Lo HANGUL SYLLABLE DDE\r\n\t\t0xB5D8 == code || // Lo HANGUL SYLLABLE DDYEO\r\n\t\t0xB5F4 == code || // Lo HANGUL SYLLABLE DDYE\r\n\t\t0xB610 == code || // Lo HANGUL SYLLABLE DDO\r\n\t\t0xB62C == code || // Lo HANGUL SYLLABLE DDWA\r\n\t\t0xB648 == code || // Lo HANGUL SYLLABLE DDWAE\r\n\t\t0xB664 == code || // Lo HANGUL SYLLABLE DDOE\r\n\t\t0xB680 == code || // Lo HANGUL SYLLABLE DDYO\r\n\t\t0xB69C == code || // Lo HANGUL SYLLABLE DDU\r\n\t\t0xB6B8 == code || // Lo HANGUL SYLLABLE DDWEO\r\n\t\t0xB6D4 == code || // Lo HANGUL SYLLABLE DDWE\r\n\t\t0xB6F0 == code || // Lo HANGUL SYLLABLE DDWI\r\n\t\t0xB70C == code || // Lo HANGUL SYLLABLE DDYU\r\n\t\t0xB728 == code || // Lo HANGUL SYLLABLE DDEU\r\n\t\t0xB744 == code || // Lo HANGUL SYLLABLE DDYI\r\n\t\t0xB760 == code || // Lo HANGUL SYLLABLE DDI\r\n\t\t0xB77C == code || // Lo HANGUL SYLLABLE RA\r\n\t\t0xB798 == code || // Lo HANGUL SYLLABLE RAE\r\n\t\t0xB7B4 == code || // Lo HANGUL SYLLABLE RYA\r\n\t\t0xB7D0 == code || // Lo HANGUL SYLLABLE RYAE\r\n\t\t0xB7EC == code || // Lo HANGUL SYLLABLE REO\r\n\t\t0xB808 == code || // Lo HANGUL SYLLABLE RE\r\n\t\t0xB824 == code || // Lo HANGUL SYLLABLE RYEO\r\n\t\t0xB840 == code || // Lo HANGUL SYLLABLE RYE\r\n\t\t0xB85C == code || // Lo HANGUL SYLLABLE RO\r\n\t\t0xB878 == code || // Lo HANGUL SYLLABLE RWA\r\n\t\t0xB894 == code || // Lo HANGUL SYLLABLE RWAE\r\n\t\t0xB8B0 == code || // Lo HANGUL SYLLABLE ROE\r\n\t\t0xB8CC == code || // Lo HANGUL SYLLABLE RYO\r\n\t\t0xB8E8 == code || // Lo HANGUL SYLLABLE RU\r\n\t\t0xB904 == code || // Lo HANGUL SYLLABLE RWEO\r\n\t\t0xB920 == code || // Lo HANGUL SYLLABLE RWE\r\n\t\t0xB93C == code || // Lo HANGUL SYLLABLE RWI\r\n\t\t0xB958 == code || // Lo HANGUL SYLLABLE RYU\r\n\t\t0xB974 == code || // Lo HANGUL SYLLABLE REU\r\n\t\t0xB990 == code || // Lo HANGUL SYLLABLE RYI\r\n\t\t0xB9AC == code || // Lo HANGUL SYLLABLE RI\r\n\t\t0xB9C8 == code || // Lo HANGUL SYLLABLE MA\r\n\t\t0xB9E4 == code || // Lo HANGUL SYLLABLE MAE\r\n\t\t0xBA00 == code || // Lo HANGUL SYLLABLE MYA\r\n\t\t0xBA1C == code || // Lo HANGUL SYLLABLE MYAE\r\n\t\t0xBA38 == code || // Lo HANGUL SYLLABLE MEO\r\n\t\t0xBA54 == code || // Lo HANGUL SYLLABLE ME\r\n\t\t0xBA70 == code || // Lo HANGUL SYLLABLE MYEO\r\n\t\t0xBA8C == code || // Lo HANGUL SYLLABLE MYE\r\n\t\t0xBAA8 == code || // Lo HANGUL SYLLABLE MO\r\n\t\t0xBAC4 == code || // Lo HANGUL SYLLABLE MWA\r\n\t\t0xBAE0 == code || // Lo HANGUL SYLLABLE MWAE\r\n\t\t0xBAFC == code || // Lo HANGUL SYLLABLE MOE\r\n\t\t0xBB18 == code || // Lo HANGUL SYLLABLE MYO\r\n\t\t0xBB34 == code || // Lo HANGUL SYLLABLE MU\r\n\t\t0xBB50 == code || // Lo HANGUL SYLLABLE MWEO\r\n\t\t0xBB6C == code || // Lo HANGUL SYLLABLE MWE\r\n\t\t0xBB88 == code || // Lo HANGUL SYLLABLE MWI\r\n\t\t0xBBA4 == code || // Lo HANGUL SYLLABLE MYU\r\n\t\t0xBBC0 == code || // Lo HANGUL SYLLABLE MEU\r\n\t\t0xBBDC == code || // Lo HANGUL SYLLABLE MYI\r\n\t\t0xBBF8 == code || // Lo HANGUL SYLLABLE MI\r\n\t\t0xBC14 == code || // Lo HANGUL SYLLABLE BA\r\n\t\t0xBC30 == code || // Lo HANGUL SYLLABLE BAE\r\n\t\t0xBC4C == code || // Lo HANGUL SYLLABLE BYA\r\n\t\t0xBC68 == code || // Lo HANGUL SYLLABLE BYAE\r\n\t\t0xBC84 == code || // Lo HANGUL SYLLABLE BEO\r\n\t\t0xBCA0 == code || // Lo HANGUL SYLLABLE BE\r\n\t\t0xBCBC == code || // Lo HANGUL SYLLABLE BYEO\r\n\t\t0xBCD8 == code || // Lo HANGUL SYLLABLE BYE\r\n\t\t0xBCF4 == code || // Lo HANGUL SYLLABLE BO\r\n\t\t0xBD10 == code || // Lo HANGUL SYLLABLE BWA\r\n\t\t0xBD2C == code || // Lo HANGUL SYLLABLE BWAE\r\n\t\t0xBD48 == code || // Lo HANGUL SYLLABLE BOE\r\n\t\t0xBD64 == code || // Lo HANGUL SYLLABLE BYO\r\n\t\t0xBD80 == code || // Lo HANGUL SYLLABLE BU\r\n\t\t0xBD9C == code || // Lo HANGUL SYLLABLE BWEO\r\n\t\t0xBDB8 == code || // Lo HANGUL SYLLABLE BWE\r\n\t\t0xBDD4 == code || // Lo HANGUL SYLLABLE BWI\r\n\t\t0xBDF0 == code || // Lo HANGUL SYLLABLE BYU\r\n\t\t0xBE0C == code || // Lo HANGUL SYLLABLE BEU\r\n\t\t0xBE28 == code || // Lo HANGUL SYLLABLE BYI\r\n\t\t0xBE44 == code || // Lo HANGUL SYLLABLE BI\r\n\t\t0xBE60 == code || // Lo HANGUL SYLLABLE BBA\r\n\t\t0xBE7C == code || // Lo HANGUL SYLLABLE BBAE\r\n\t\t0xBE98 == code || // Lo HANGUL SYLLABLE BBYA\r\n\t\t0xBEB4 == code || // Lo HANGUL SYLLABLE BBYAE\r\n\t\t0xBED0 == code || // Lo HANGUL SYLLABLE BBEO\r\n\t\t0xBEEC == code || // Lo HANGUL SYLLABLE BBE\r\n\t\t0xBF08 == code || // Lo HANGUL SYLLABLE BBYEO\r\n\t\t0xBF24 == code || // Lo HANGUL SYLLABLE BBYE\r\n\t\t0xBF40 == code || // Lo HANGUL SYLLABLE BBO\r\n\t\t0xBF5C == code || // Lo HANGUL SYLLABLE BBWA\r\n\t\t0xBF78 == code || // Lo HANGUL SYLLABLE BBWAE\r\n\t\t0xBF94 == code || // Lo HANGUL SYLLABLE BBOE\r\n\t\t0xBFB0 == code || // Lo HANGUL SYLLABLE BBYO\r\n\t\t0xBFCC == code || // Lo HANGUL SYLLABLE BBU\r\n\t\t0xBFE8 == code || // Lo HANGUL SYLLABLE BBWEO\r\n\t\t0xC004 == code || // Lo HANGUL SYLLABLE BBWE\r\n\t\t0xC020 == code || // Lo HANGUL SYLLABLE BBWI\r\n\t\t0xC03C == code || // Lo HANGUL SYLLABLE BBYU\r\n\t\t0xC058 == code || // Lo HANGUL SYLLABLE BBEU\r\n\t\t0xC074 == code || // Lo HANGUL SYLLABLE BBYI\r\n\t\t0xC090 == code || // Lo HANGUL SYLLABLE BBI\r\n\t\t0xC0AC == code || // Lo HANGUL SYLLABLE SA\r\n\t\t0xC0C8 == code || // Lo HANGUL SYLLABLE SAE\r\n\t\t0xC0E4 == code || // Lo HANGUL SYLLABLE SYA\r\n\t\t0xC100 == code || // Lo HANGUL SYLLABLE SYAE\r\n\t\t0xC11C == code || // Lo HANGUL SYLLABLE SEO\r\n\t\t0xC138 == code || // Lo HANGUL SYLLABLE SE\r\n\t\t0xC154 == code || // Lo HANGUL SYLLABLE SYEO\r\n\t\t0xC170 == code || // Lo HANGUL SYLLABLE SYE\r\n\t\t0xC18C == code || // Lo HANGUL SYLLABLE SO\r\n\t\t0xC1A8 == code || // Lo HANGUL SYLLABLE SWA\r\n\t\t0xC1C4 == code || // Lo HANGUL SYLLABLE SWAE\r\n\t\t0xC1E0 == code || // Lo HANGUL SYLLABLE SOE\r\n\t\t0xC1FC == code || // Lo HANGUL SYLLABLE SYO\r\n\t\t0xC218 == code || // Lo HANGUL SYLLABLE SU\r\n\t\t0xC234 == code || // Lo HANGUL SYLLABLE SWEO\r\n\t\t0xC250 == code || // Lo HANGUL SYLLABLE SWE\r\n\t\t0xC26C == code || // Lo HANGUL SYLLABLE SWI\r\n\t\t0xC288 == code || // Lo HANGUL SYLLABLE SYU\r\n\t\t0xC2A4 == code || // Lo HANGUL SYLLABLE SEU\r\n\t\t0xC2C0 == code || // Lo HANGUL SYLLABLE SYI\r\n\t\t0xC2DC == code || // Lo HANGUL SYLLABLE SI\r\n\t\t0xC2F8 == code || // Lo HANGUL SYLLABLE SSA\r\n\t\t0xC314 == code || // Lo HANGUL SYLLABLE SSAE\r\n\t\t0xC330 == code || // Lo HANGUL SYLLABLE SSYA\r\n\t\t0xC34C == code || // Lo HANGUL SYLLABLE SSYAE\r\n\t\t0xC368 == code || // Lo HANGUL SYLLABLE SSEO\r\n\t\t0xC384 == code || // Lo HANGUL SYLLABLE SSE\r\n\t\t0xC3A0 == code || // Lo HANGUL SYLLABLE SSYEO\r\n\t\t0xC3BC == code || // Lo HANGUL SYLLABLE SSYE\r\n\t\t0xC3D8 == code || // Lo HANGUL SYLLABLE SSO\r\n\t\t0xC3F4 == code || // Lo HANGUL SYLLABLE SSWA\r\n\t\t0xC410 == code || // Lo HANGUL SYLLABLE SSWAE\r\n\t\t0xC42C == code || // Lo HANGUL SYLLABLE SSOE\r\n\t\t0xC448 == code || // Lo HANGUL SYLLABLE SSYO\r\n\t\t0xC464 == code || // Lo HANGUL SYLLABLE SSU\r\n\t\t0xC480 == code || // Lo HANGUL SYLLABLE SSWEO\r\n\t\t0xC49C == code || // Lo HANGUL SYLLABLE SSWE\r\n\t\t0xC4B8 == code || // Lo HANGUL SYLLABLE SSWI\r\n\t\t0xC4D4 == code || // Lo HANGUL SYLLABLE SSYU\r\n\t\t0xC4F0 == code || // Lo HANGUL SYLLABLE SSEU\r\n\t\t0xC50C == code || // Lo HANGUL SYLLABLE SSYI\r\n\t\t0xC528 == code || // Lo HANGUL SYLLABLE SSI\r\n\t\t0xC544 == code || // Lo HANGUL SYLLABLE A\r\n\t\t0xC560 == code || // Lo HANGUL SYLLABLE AE\r\n\t\t0xC57C == code || // Lo HANGUL SYLLABLE YA\r\n\t\t0xC598 == code || // Lo HANGUL SYLLABLE YAE\r\n\t\t0xC5B4 == code || // Lo HANGUL SYLLABLE EO\r\n\t\t0xC5D0 == code || // Lo HANGUL SYLLABLE E\r\n\t\t0xC5EC == code || // Lo HANGUL SYLLABLE YEO\r\n\t\t0xC608 == code || // Lo HANGUL SYLLABLE YE\r\n\t\t0xC624 == code || // Lo HANGUL SYLLABLE O\r\n\t\t0xC640 == code || // Lo HANGUL SYLLABLE WA\r\n\t\t0xC65C == code || // Lo HANGUL SYLLABLE WAE\r\n\t\t0xC678 == code || // Lo HANGUL SYLLABLE OE\r\n\t\t0xC694 == code || // Lo HANGUL SYLLABLE YO\r\n\t\t0xC6B0 == code || // Lo HANGUL SYLLABLE U\r\n\t\t0xC6CC == code || // Lo HANGUL SYLLABLE WEO\r\n\t\t0xC6E8 == code || // Lo HANGUL SYLLABLE WE\r\n\t\t0xC704 == code || // Lo HANGUL SYLLABLE WI\r\n\t\t0xC720 == code || // Lo HANGUL SYLLABLE YU\r\n\t\t0xC73C == code || // Lo HANGUL SYLLABLE EU\r\n\t\t0xC758 == code || // Lo HANGUL SYLLABLE YI\r\n\t\t0xC774 == code || // Lo HANGUL SYLLABLE I\r\n\t\t0xC790 == code || // Lo HANGUL SYLLABLE JA\r\n\t\t0xC7AC == code || // Lo HANGUL SYLLABLE JAE\r\n\t\t0xC7C8 == code || // Lo HANGUL SYLLABLE JYA\r\n\t\t0xC7E4 == code || // Lo HANGUL SYLLABLE JYAE\r\n\t\t0xC800 == code || // Lo HANGUL SYLLABLE JEO\r\n\t\t0xC81C == code || // Lo HANGUL SYLLABLE JE\r\n\t\t0xC838 == code || // Lo HANGUL SYLLABLE JYEO\r\n\t\t0xC854 == code || // Lo HANGUL SYLLABLE JYE\r\n\t\t0xC870 == code || // Lo HANGUL SYLLABLE JO\r\n\t\t0xC88C == code || // Lo HANGUL SYLLABLE JWA\r\n\t\t0xC8A8 == code || // Lo HANGUL SYLLABLE JWAE\r\n\t\t0xC8C4 == code || // Lo HANGUL SYLLABLE JOE\r\n\t\t0xC8E0 == code || // Lo HANGUL SYLLABLE JYO\r\n\t\t0xC8FC == code || // Lo HANGUL SYLLABLE JU\r\n\t\t0xC918 == code || // Lo HANGUL SYLLABLE JWEO\r\n\t\t0xC934 == code || // Lo HANGUL SYLLABLE JWE\r\n\t\t0xC950 == code || // Lo HANGUL SYLLABLE JWI\r\n\t\t0xC96C == code || // Lo HANGUL SYLLABLE JYU\r\n\t\t0xC988 == code || // Lo HANGUL SYLLABLE JEU\r\n\t\t0xC9A4 == code || // Lo HANGUL SYLLABLE JYI\r\n\t\t0xC9C0 == code || // Lo HANGUL SYLLABLE JI\r\n\t\t0xC9DC == code || // Lo HANGUL SYLLABLE JJA\r\n\t\t0xC9F8 == code || // Lo HANGUL SYLLABLE JJAE\r\n\t\t0xCA14 == code || // Lo HANGUL SYLLABLE JJYA\r\n\t\t0xCA30 == code || // Lo HANGUL SYLLABLE JJYAE\r\n\t\t0xCA4C == code || // Lo HANGUL SYLLABLE JJEO\r\n\t\t0xCA68 == code || // Lo HANGUL SYLLABLE JJE\r\n\t\t0xCA84 == code || // Lo HANGUL SYLLABLE JJYEO\r\n\t\t0xCAA0 == code || // Lo HANGUL SYLLABLE JJYE\r\n\t\t0xCABC == code || // Lo HANGUL SYLLABLE JJO\r\n\t\t0xCAD8 == code || // Lo HANGUL SYLLABLE JJWA\r\n\t\t0xCAF4 == code || // Lo HANGUL SYLLABLE JJWAE\r\n\t\t0xCB10 == code || // Lo HANGUL SYLLABLE JJOE\r\n\t\t0xCB2C == code || // Lo HANGUL SYLLABLE JJYO\r\n\t\t0xCB48 == code || // Lo HANGUL SYLLABLE JJU\r\n\t\t0xCB64 == code || // Lo HANGUL SYLLABLE JJWEO\r\n\t\t0xCB80 == code || // Lo HANGUL SYLLABLE JJWE\r\n\t\t0xCB9C == code || // Lo HANGUL SYLLABLE JJWI\r\n\t\t0xCBB8 == code || // Lo HANGUL SYLLABLE JJYU\r\n\t\t0xCBD4 == code || // Lo HANGUL SYLLABLE JJEU\r\n\t\t0xCBF0 == code || // Lo HANGUL SYLLABLE JJYI\r\n\t\t0xCC0C == code || // Lo HANGUL SYLLABLE JJI\r\n\t\t0xCC28 == code || // Lo HANGUL SYLLABLE CA\r\n\t\t0xCC44 == code || // Lo HANGUL SYLLABLE CAE\r\n\t\t0xCC60 == code || // Lo HANGUL SYLLABLE CYA\r\n\t\t0xCC7C == code || // Lo HANGUL SYLLABLE CYAE\r\n\t\t0xCC98 == code || // Lo HANGUL SYLLABLE CEO\r\n\t\t0xCCB4 == code || // Lo HANGUL SYLLABLE CE\r\n\t\t0xCCD0 == code || // Lo HANGUL SYLLABLE CYEO\r\n\t\t0xCCEC == code || // Lo HANGUL SYLLABLE CYE\r\n\t\t0xCD08 == code || // Lo HANGUL SYLLABLE CO\r\n\t\t0xCD24 == code || // Lo HANGUL SYLLABLE CWA\r\n\t\t0xCD40 == code || // Lo HANGUL SYLLABLE CWAE\r\n\t\t0xCD5C == code || // Lo HANGUL SYLLABLE COE\r\n\t\t0xCD78 == code || // Lo HANGUL SYLLABLE CYO\r\n\t\t0xCD94 == code || // Lo HANGUL SYLLABLE CU\r\n\t\t0xCDB0 == code || // Lo HANGUL SYLLABLE CWEO\r\n\t\t0xCDCC == code || // Lo HANGUL SYLLABLE CWE\r\n\t\t0xCDE8 == code || // Lo HANGUL SYLLABLE CWI\r\n\t\t0xCE04 == code || // Lo HANGUL SYLLABLE CYU\r\n\t\t0xCE20 == code || // Lo HANGUL SYLLABLE CEU\r\n\t\t0xCE3C == code || // Lo HANGUL SYLLABLE CYI\r\n\t\t0xCE58 == code || // Lo HANGUL SYLLABLE CI\r\n\t\t0xCE74 == code || // Lo HANGUL SYLLABLE KA\r\n\t\t0xCE90 == code || // Lo HANGUL SYLLABLE KAE\r\n\t\t0xCEAC == code || // Lo HANGUL SYLLABLE KYA\r\n\t\t0xCEC8 == code || // Lo HANGUL SYLLABLE KYAE\r\n\t\t0xCEE4 == code || // Lo HANGUL SYLLABLE KEO\r\n\t\t0xCF00 == code || // Lo HANGUL SYLLABLE KE\r\n\t\t0xCF1C == code || // Lo HANGUL SYLLABLE KYEO\r\n\t\t0xCF38 == code || // Lo HANGUL SYLLABLE KYE\r\n\t\t0xCF54 == code || // Lo HANGUL SYLLABLE KO\r\n\t\t0xCF70 == code || // Lo HANGUL SYLLABLE KWA\r\n\t\t0xCF8C == code || // Lo HANGUL SYLLABLE KWAE\r\n\t\t0xCFA8 == code || // Lo HANGUL SYLLABLE KOE\r\n\t\t0xCFC4 == code || // Lo HANGUL SYLLABLE KYO\r\n\t\t0xCFE0 == code || // Lo HANGUL SYLLABLE KU\r\n\t\t0xCFFC == code || // Lo HANGUL SYLLABLE KWEO\r\n\t\t0xD018 == code || // Lo HANGUL SYLLABLE KWE\r\n\t\t0xD034 == code || // Lo HANGUL SYLLABLE KWI\r\n\t\t0xD050 == code || // Lo HANGUL SYLLABLE KYU\r\n\t\t0xD06C == code || // Lo HANGUL SYLLABLE KEU\r\n\t\t0xD088 == code || // Lo HANGUL SYLLABLE KYI\r\n\t\t0xD0A4 == code || // Lo HANGUL SYLLABLE KI\r\n\t\t0xD0C0 == code || // Lo HANGUL SYLLABLE TA\r\n\t\t0xD0DC == code || // Lo HANGUL SYLLABLE TAE\r\n\t\t0xD0F8 == code || // Lo HANGUL SYLLABLE TYA\r\n\t\t0xD114 == code || // Lo HANGUL SYLLABLE TYAE\r\n\t\t0xD130 == code || // Lo HANGUL SYLLABLE TEO\r\n\t\t0xD14C == code || // Lo HANGUL SYLLABLE TE\r\n\t\t0xD168 == code || // Lo HANGUL SYLLABLE TYEO\r\n\t\t0xD184 == code || // Lo HANGUL SYLLABLE TYE\r\n\t\t0xD1A0 == code || // Lo HANGUL SYLLABLE TO\r\n\t\t0xD1BC == code || // Lo HANGUL SYLLABLE TWA\r\n\t\t0xD1D8 == code || // Lo HANGUL SYLLABLE TWAE\r\n\t\t0xD1F4 == code || // Lo HANGUL SYLLABLE TOE\r\n\t\t0xD210 == code || // Lo HANGUL SYLLABLE TYO\r\n\t\t0xD22C == code || // Lo HANGUL SYLLABLE TU\r\n\t\t0xD248 == code || // Lo HANGUL SYLLABLE TWEO\r\n\t\t0xD264 == code || // Lo HANGUL SYLLABLE TWE\r\n\t\t0xD280 == code || // Lo HANGUL SYLLABLE TWI\r\n\t\t0xD29C == code || // Lo HANGUL SYLLABLE TYU\r\n\t\t0xD2B8 == code || // Lo HANGUL SYLLABLE TEU\r\n\t\t0xD2D4 == code || // Lo HANGUL SYLLABLE TYI\r\n\t\t0xD2F0 == code || // Lo HANGUL SYLLABLE TI\r\n\t\t0xD30C == code || // Lo HANGUL SYLLABLE PA\r\n\t\t0xD328 == code || // Lo HANGUL SYLLABLE PAE\r\n\t\t0xD344 == code || // Lo HANGUL SYLLABLE PYA\r\n\t\t0xD360 == code || // Lo HANGUL SYLLABLE PYAE\r\n\t\t0xD37C == code || // Lo HANGUL SYLLABLE PEO\r\n\t\t0xD398 == code || // Lo HANGUL SYLLABLE PE\r\n\t\t0xD3B4 == code || // Lo HANGUL SYLLABLE PYEO\r\n\t\t0xD3D0 == code || // Lo HANGUL SYLLABLE PYE\r\n\t\t0xD3EC == code || // Lo HANGUL SYLLABLE PO\r\n\t\t0xD408 == code || // Lo HANGUL SYLLABLE PWA\r\n\t\t0xD424 == code || // Lo HANGUL SYLLABLE PWAE\r\n\t\t0xD440 == code || // Lo HANGUL SYLLABLE POE\r\n\t\t0xD45C == code || // Lo HANGUL SYLLABLE PYO\r\n\t\t0xD478 == code || // Lo HANGUL SYLLABLE PU\r\n\t\t0xD494 == code || // Lo HANGUL SYLLABLE PWEO\r\n\t\t0xD4B0 == code || // Lo HANGUL SYLLABLE PWE\r\n\t\t0xD4CC == code || // Lo HANGUL SYLLABLE PWI\r\n\t\t0xD4E8 == code || // Lo HANGUL SYLLABLE PYU\r\n\t\t0xD504 == code || // Lo HANGUL SYLLABLE PEU\r\n\t\t0xD520 == code || // Lo HANGUL SYLLABLE PYI\r\n\t\t0xD53C == code || // Lo HANGUL SYLLABLE PI\r\n\t\t0xD558 == code || // Lo HANGUL SYLLABLE HA\r\n\t\t0xD574 == code || // Lo HANGUL SYLLABLE HAE\r\n\t\t0xD590 == code || // Lo HANGUL SYLLABLE HYA\r\n\t\t0xD5AC == code || // Lo HANGUL SYLLABLE HYAE\r\n\t\t0xD5C8 == code || // Lo HANGUL SYLLABLE HEO\r\n\t\t0xD5E4 == code || // Lo HANGUL SYLLABLE HE\r\n\t\t0xD600 == code || // Lo HANGUL SYLLABLE HYEO\r\n\t\t0xD61C == code || // Lo HANGUL SYLLABLE HYE\r\n\t\t0xD638 == code || // Lo HANGUL SYLLABLE HO\r\n\t\t0xD654 == code || // Lo HANGUL SYLLABLE HWA\r\n\t\t0xD670 == code || // Lo HANGUL SYLLABLE HWAE\r\n\t\t0xD68C == code || // Lo HANGUL SYLLABLE HOE\r\n\t\t0xD6A8 == code || // Lo HANGUL SYLLABLE HYO\r\n\t\t0xD6C4 == code || // Lo HANGUL SYLLABLE HU\r\n\t\t0xD6E0 == code || // Lo HANGUL SYLLABLE HWEO\r\n\t\t0xD6FC == code || // Lo HANGUL SYLLABLE HWE\r\n\t\t0xD718 == code || // Lo HANGUL SYLLABLE HWI\r\n\t\t0xD734 == code || // Lo HANGUL SYLLABLE HYU\r\n\t\t0xD750 == code || // Lo HANGUL SYLLABLE HEU\r\n\t\t0xD76C == code || // Lo HANGUL SYLLABLE HYI\r\n\t\t0xD788 == code // Lo HANGUL SYLLABLE HI\r\n\t\t){\r\n\t\t\treturn LV;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t(0xAC01 <= code && code <= 0xAC1B) || // Lo [27] HANGUL SYLLABLE GAG..HANGUL SYLLABLE GAH\r\n\t\t(0xAC1D <= code && code <= 0xAC37) || // Lo [27] HANGUL SYLLABLE GAEG..HANGUL SYLLABLE GAEH\r\n\t\t(0xAC39 <= code && code <= 0xAC53) || // Lo [27] HANGUL SYLLABLE GYAG..HANGUL SYLLABLE GYAH\r\n\t\t(0xAC55 <= code && code <= 0xAC6F) || // Lo [27] HANGUL SYLLABLE GYAEG..HANGUL SYLLABLE GYAEH\r\n\t\t(0xAC71 <= code && code <= 0xAC8B) || // Lo [27] HANGUL SYLLABLE GEOG..HANGUL SYLLABLE GEOH\r\n\t\t(0xAC8D <= code && code <= 0xACA7) || // Lo [27] HANGUL SYLLABLE GEG..HANGUL SYLLABLE GEH\r\n\t\t(0xACA9 <= code && code <= 0xACC3) || // Lo [27] HANGUL SYLLABLE GYEOG..HANGUL SYLLABLE GYEOH\r\n\t\t(0xACC5 <= code && code <= 0xACDF) || // Lo [27] HANGUL SYLLABLE GYEG..HANGUL SYLLABLE GYEH\r\n\t\t(0xACE1 <= code && code <= 0xACFB) || // Lo [27] HANGUL SYLLABLE GOG..HANGUL SYLLABLE GOH\r\n\t\t(0xACFD <= code && code <= 0xAD17) || // Lo [27] HANGUL SYLLABLE GWAG..HANGUL SYLLABLE GWAH\r\n\t\t(0xAD19 <= code && code <= 0xAD33) || // Lo [27] HANGUL SYLLABLE GWAEG..HANGUL SYLLABLE GWAEH\r\n\t\t(0xAD35 <= code && code <= 0xAD4F) || // Lo [27] HANGUL SYLLABLE GOEG..HANGUL SYLLABLE GOEH\r\n\t\t(0xAD51 <= code && code <= 0xAD6B) || // Lo [27] HANGUL SYLLABLE GYOG..HANGUL SYLLABLE GYOH\r\n\t\t(0xAD6D <= code && code <= 0xAD87) || // Lo [27] HANGUL SYLLABLE GUG..HANGUL SYLLABLE GUH\r\n\t\t(0xAD89 <= code && code <= 0xADA3) || // Lo [27] HANGUL SYLLABLE GWEOG..HANGUL SYLLABLE GWEOH\r\n\t\t(0xADA5 <= code && code <= 0xADBF) || // Lo [27] HANGUL SYLLABLE GWEG..HANGUL SYLLABLE GWEH\r\n\t\t(0xADC1 <= code && code <= 0xADDB) || // Lo [27] HANGUL SYLLABLE GWIG..HANGUL SYLLABLE GWIH\r\n\t\t(0xADDD <= code && code <= 0xADF7) || // Lo [27] HANGUL SYLLABLE GYUG..HANGUL SYLLABLE GYUH\r\n\t\t(0xADF9 <= code && code <= 0xAE13) || // Lo [27] HANGUL SYLLABLE GEUG..HANGUL SYLLABLE GEUH\r\n\t\t(0xAE15 <= code && code <= 0xAE2F) || // Lo [27] HANGUL SYLLABLE GYIG..HANGUL SYLLABLE GYIH\r\n\t\t(0xAE31 <= code && code <= 0xAE4B) || // Lo [27] HANGUL SYLLABLE GIG..HANGUL SYLLABLE GIH\r\n\t\t(0xAE4D <= code && code <= 0xAE67) || // Lo [27] HANGUL SYLLABLE GGAG..HANGUL SYLLABLE GGAH\r\n\t\t(0xAE69 <= code && code <= 0xAE83) || // Lo [27] HANGUL SYLLABLE GGAEG..HANGUL SYLLABLE GGAEH\r\n\t\t(0xAE85 <= code && code <= 0xAE9F) || // Lo [27] HANGUL SYLLABLE GGYAG..HANGUL SYLLABLE GGYAH\r\n\t\t(0xAEA1 <= code && code <= 0xAEBB) || // Lo [27] HANGUL SYLLABLE GGYAEG..HANGUL SYLLABLE GGYAEH\r\n\t\t(0xAEBD <= code && code <= 0xAED7) || // Lo [27] HANGUL SYLLABLE GGEOG..HANGUL SYLLABLE GGEOH\r\n\t\t(0xAED9 <= code && code <= 0xAEF3) || // Lo [27] HANGUL SYLLABLE GGEG..HANGUL SYLLABLE GGEH\r\n\t\t(0xAEF5 <= code && code <= 0xAF0F) || // Lo [27] HANGUL SYLLABLE GGYEOG..HANGUL SYLLABLE GGYEOH\r\n\t\t(0xAF11 <= code && code <= 0xAF2B) || // Lo [27] HANGUL SYLLABLE GGYEG..HANGUL SYLLABLE GGYEH\r\n\t\t(0xAF2D <= code && code <= 0xAF47) || // Lo [27] HANGUL SYLLABLE GGOG..HANGUL SYLLABLE GGOH\r\n\t\t(0xAF49 <= code && code <= 0xAF63) || // Lo [27] HANGUL SYLLABLE GGWAG..HANGUL SYLLABLE GGWAH\r\n\t\t(0xAF65 <= code && code <= 0xAF7F) || // Lo [27] HANGUL SYLLABLE GGWAEG..HANGUL SYLLABLE GGWAEH\r\n\t\t(0xAF81 <= code && code <= 0xAF9B) || // Lo [27] HANGUL SYLLABLE GGOEG..HANGUL SYLLABLE GGOEH\r\n\t\t(0xAF9D <= code && code <= 0xAFB7) || // Lo [27] HANGUL SYLLABLE GGYOG..HANGUL SYLLABLE GGYOH\r\n\t\t(0xAFB9 <= code && code <= 0xAFD3) || // Lo [27] HANGUL SYLLABLE GGUG..HANGUL SYLLABLE GGUH\r\n\t\t(0xAFD5 <= code && code <= 0xAFEF) || // Lo [27] HANGUL SYLLABLE GGWEOG..HANGUL SYLLABLE GGWEOH\r\n\t\t(0xAFF1 <= code && code <= 0xB00B) || // Lo [27] HANGUL SYLLABLE GGWEG..HANGUL SYLLABLE GGWEH\r\n\t\t(0xB00D <= code && code <= 0xB027) || // Lo [27] HANGUL SYLLABLE GGWIG..HANGUL SYLLABLE GGWIH\r\n\t\t(0xB029 <= code && code <= 0xB043) || // Lo [27] HANGUL SYLLABLE GGYUG..HANGUL SYLLABLE GGYUH\r\n\t\t(0xB045 <= code && code <= 0xB05F) || // Lo [27] HANGUL SYLLABLE GGEUG..HANGUL SYLLABLE GGEUH\r\n\t\t(0xB061 <= code && code <= 0xB07B) || // Lo [27] HANGUL SYLLABLE GGYIG..HANGUL SYLLABLE GGYIH\r\n\t\t(0xB07D <= code && code <= 0xB097) || // Lo [27] HANGUL SYLLABLE GGIG..HANGUL SYLLABLE GGIH\r\n\t\t(0xB099 <= code && code <= 0xB0B3) || // Lo [27] HANGUL SYLLABLE NAG..HANGUL SYLLABLE NAH\r\n\t\t(0xB0B5 <= code && code <= 0xB0CF) || // Lo [27] HANGUL SYLLABLE NAEG..HANGUL SYLLABLE NAEH\r\n\t\t(0xB0D1 <= code && code <= 0xB0EB) || // Lo [27] HANGUL SYLLABLE NYAG..HANGUL SYLLABLE NYAH\r\n\t\t(0xB0ED <= code && code <= 0xB107) || // Lo [27] HANGUL SYLLABLE NYAEG..HANGUL SYLLABLE NYAEH\r\n\t\t(0xB109 <= code && code <= 0xB123) || // Lo [27] HANGUL SYLLABLE NEOG..HANGUL SYLLABLE NEOH\r\n\t\t(0xB125 <= code && code <= 0xB13F) || // Lo [27] HANGUL SYLLABLE NEG..HANGUL SYLLABLE NEH\r\n\t\t(0xB141 <= code && code <= 0xB15B) || // Lo [27] HANGUL SYLLABLE NYEOG..HANGUL SYLLABLE NYEOH\r\n\t\t(0xB15D <= code && code <= 0xB177) || // Lo [27] HANGUL SYLLABLE NYEG..HANGUL SYLLABLE NYEH\r\n\t\t(0xB179 <= code && code <= 0xB193) || // Lo [27] HANGUL SYLLABLE NOG..HANGUL SYLLABLE NOH\r\n\t\t(0xB195 <= code && code <= 0xB1AF) || // Lo [27] HANGUL SYLLABLE NWAG..HANGUL SYLLABLE NWAH\r\n\t\t(0xB1B1 <= code && code <= 0xB1CB) || // Lo [27] HANGUL SYLLABLE NWAEG..HANGUL SYLLABLE NWAEH\r\n\t\t(0xB1CD <= code && code <= 0xB1E7) || // Lo [27] HANGUL SYLLABLE NOEG..HANGUL SYLLABLE NOEH\r\n\t\t(0xB1E9 <= code && code <= 0xB203) || // Lo [27] HANGUL SYLLABLE NYOG..HANGUL SYLLABLE NYOH\r\n\t\t(0xB205 <= code && code <= 0xB21F) || // Lo [27] HANGUL SYLLABLE NUG..HANGUL SYLLABLE NUH\r\n\t\t(0xB221 <= code && code <= 0xB23B) || // Lo [27] HANGUL SYLLABLE NWEOG..HANGUL SYLLABLE NWEOH\r\n\t\t(0xB23D <= code && code <= 0xB257) || // Lo [27] HANGUL SYLLABLE NWEG..HANGUL SYLLABLE NWEH\r\n\t\t(0xB259 <= code && code <= 0xB273) || // Lo [27] HANGUL SYLLABLE NWIG..HANGUL SYLLABLE NWIH\r\n\t\t(0xB275 <= code && code <= 0xB28F) || // Lo [27] HANGUL SYLLABLE NYUG..HANGUL SYLLABLE NYUH\r\n\t\t(0xB291 <= code && code <= 0xB2AB) || // Lo [27] HANGUL SYLLABLE NEUG..HANGUL SYLLABLE NEUH\r\n\t\t(0xB2AD <= code && code <= 0xB2C7) || // Lo [27] HANGUL SYLLABLE NYIG..HANGUL SYLLABLE NYIH\r\n\t\t(0xB2C9 <= code && code <= 0xB2E3) || // Lo [27] HANGUL SYLLABLE NIG..HANGUL SYLLABLE NIH\r\n\t\t(0xB2E5 <= code && code <= 0xB2FF) || // Lo [27] HANGUL SYLLABLE DAG..HANGUL SYLLABLE DAH\r\n\t\t(0xB301 <= code && code <= 0xB31B) || // Lo [27] HANGUL SYLLABLE DAEG..HANGUL SYLLABLE DAEH\r\n\t\t(0xB31D <= code && code <= 0xB337) || // Lo [27] HANGUL SYLLABLE DYAG..HANGUL SYLLABLE DYAH\r\n\t\t(0xB339 <= code && code <= 0xB353) || // Lo [27] HANGUL SYLLABLE DYAEG..HANGUL SYLLABLE DYAEH\r\n\t\t(0xB355 <= code && code <= 0xB36F) || // Lo [27] HANGUL SYLLABLE DEOG..HANGUL SYLLABLE DEOH\r\n\t\t(0xB371 <= code && code <= 0xB38B) || // Lo [27] HANGUL SYLLABLE DEG..HANGUL SYLLABLE DEH\r\n\t\t(0xB38D <= code && code <= 0xB3A7) || // Lo [27] HANGUL SYLLABLE DYEOG..HANGUL SYLLABLE DYEOH\r\n\t\t(0xB3A9 <= code && code <= 0xB3C3) || // Lo [27] HANGUL SYLLABLE DYEG..HANGUL SYLLABLE DYEH\r\n\t\t(0xB3C5 <= code && code <= 0xB3DF) || // Lo [27] HANGUL SYLLABLE DOG..HANGUL SYLLABLE DOH\r\n\t\t(0xB3E1 <= code && code <= 0xB3FB) || // Lo [27] HANGUL SYLLABLE DWAG..HANGUL SYLLABLE DWAH\r\n\t\t(0xB3FD <= code && code <= 0xB417) || // Lo [27] HANGUL SYLLABLE DWAEG..HANGUL SYLLABLE DWAEH\r\n\t\t(0xB419 <= code && code <= 0xB433) || // Lo [27] HANGUL SYLLABLE DOEG..HANGUL SYLLABLE DOEH\r\n\t\t(0xB435 <= code && code <= 0xB44F) || // Lo [27] HANGUL SYLLABLE DYOG..HANGUL SYLLABLE DYOH\r\n\t\t(0xB451 <= code && code <= 0xB46B) || // Lo [27] HANGUL SYLLABLE DUG..HANGUL SYLLABLE DUH\r\n\t\t(0xB46D <= code && code <= 0xB487) || // Lo [27] HANGUL SYLLABLE DWEOG..HANGUL SYLLABLE DWEOH\r\n\t\t(0xB489 <= code && code <= 0xB4A3) || // Lo [27] HANGUL SYLLABLE DWEG..HANGUL SYLLABLE DWEH\r\n\t\t(0xB4A5 <= code && code <= 0xB4BF) || // Lo [27] HANGUL SYLLABLE DWIG..HANGUL SYLLABLE DWIH\r\n\t\t(0xB4C1 <= code && code <= 0xB4DB) || // Lo [27] HANGUL SYLLABLE DYUG..HANGUL SYLLABLE DYUH\r\n\t\t(0xB4DD <= code && code <= 0xB4F7) || // Lo [27] HANGUL SYLLABLE DEUG..HANGUL SYLLABLE DEUH\r\n\t\t(0xB4F9 <= code && code <= 0xB513) || // Lo [27] HANGUL SYLLABLE DYIG..HANGUL SYLLABLE DYIH\r\n\t\t(0xB515 <= code && code <= 0xB52F) || // Lo [27] HANGUL SYLLABLE DIG..HANGUL SYLLABLE DIH\r\n\t\t(0xB531 <= code && code <= 0xB54B) || // Lo [27] HANGUL SYLLABLE DDAG..HANGUL SYLLABLE DDAH\r\n\t\t(0xB54D <= code && code <= 0xB567) || // Lo [27] HANGUL SYLLABLE DDAEG..HANGUL SYLLABLE DDAEH\r\n\t\t(0xB569 <= code && code <= 0xB583) || // Lo [27] HANGUL SYLLABLE DDYAG..HANGUL SYLLABLE DDYAH\r\n\t\t(0xB585 <= code && code <= 0xB59F) || // Lo [27] HANGUL SYLLABLE DDYAEG..HANGUL SYLLABLE DDYAEH\r\n\t\t(0xB5A1 <= code && code <= 0xB5BB) || // Lo [27] HANGUL SYLLABLE DDEOG..HANGUL SYLLABLE DDEOH\r\n\t\t(0xB5BD <= code && code <= 0xB5D7) || // Lo [27] HANGUL SYLLABLE DDEG..HANGUL SYLLABLE DDEH\r\n\t\t(0xB5D9 <= code && code <= 0xB5F3) || // Lo [27] HANGUL SYLLABLE DDYEOG..HANGUL SYLLABLE DDYEOH\r\n\t\t(0xB5F5 <= code && code <= 0xB60F) || // Lo [27] HANGUL SYLLABLE DDYEG..HANGUL SYLLABLE DDYEH\r\n\t\t(0xB611 <= code && code <= 0xB62B) || // Lo [27] HANGUL SYLLABLE DDOG..HANGUL SYLLABLE DDOH\r\n\t\t(0xB62D <= code && code <= 0xB647) || // Lo [27] HANGUL SYLLABLE DDWAG..HANGUL SYLLABLE DDWAH\r\n\t\t(0xB649 <= code && code <= 0xB663) || // Lo [27] HANGUL SYLLABLE DDWAEG..HANGUL SYLLABLE DDWAEH\r\n\t\t(0xB665 <= code && code <= 0xB67F) || // Lo [27] HANGUL SYLLABLE DDOEG..HANGUL SYLLABLE DDOEH\r\n\t\t(0xB681 <= code && code <= 0xB69B) || // Lo [27] HANGUL SYLLABLE DDYOG..HANGUL SYLLABLE DDYOH\r\n\t\t(0xB69D <= code && code <= 0xB6B7) || // Lo [27] HANGUL SYLLABLE DDUG..HANGUL SYLLABLE DDUH\r\n\t\t(0xB6B9 <= code && code <= 0xB6D3) || // Lo [27] HANGUL SYLLABLE DDWEOG..HANGUL SYLLABLE DDWEOH\r\n\t\t(0xB6D5 <= code && code <= 0xB6EF) || // Lo [27] HANGUL SYLLABLE DDWEG..HANGUL SYLLABLE DDWEH\r\n\t\t(0xB6F1 <= code && code <= 0xB70B) || // Lo [27] HANGUL SYLLABLE DDWIG..HANGUL SYLLABLE DDWIH\r\n\t\t(0xB70D <= code && code <= 0xB727) || // Lo [27] HANGUL SYLLABLE DDYUG..HANGUL SYLLABLE DDYUH\r\n\t\t(0xB729 <= code && code <= 0xB743) || // Lo [27] HANGUL SYLLABLE DDEUG..HANGUL SYLLABLE DDEUH\r\n\t\t(0xB745 <= code && code <= 0xB75F) || // Lo [27] HANGUL SYLLABLE DDYIG..HANGUL SYLLABLE DDYIH\r\n\t\t(0xB761 <= code && code <= 0xB77B) || // Lo [27] HANGUL SYLLABLE DDIG..HANGUL SYLLABLE DDIH\r\n\t\t(0xB77D <= code && code <= 0xB797) || // Lo [27] HANGUL SYLLABLE RAG..HANGUL SYLLABLE RAH\r\n\t\t(0xB799 <= code && code <= 0xB7B3) || // Lo [27] HANGUL SYLLABLE RAEG..HANGUL SYLLABLE RAEH\r\n\t\t(0xB7B5 <= code && code <= 0xB7CF) || // Lo [27] HANGUL SYLLABLE RYAG..HANGUL SYLLABLE RYAH\r\n\t\t(0xB7D1 <= code && code <= 0xB7EB) || // Lo [27] HANGUL SYLLABLE RYAEG..HANGUL SYLLABLE RYAEH\r\n\t\t(0xB7ED <= code && code <= 0xB807) || // Lo [27] HANGUL SYLLABLE REOG..HANGUL SYLLABLE REOH\r\n\t\t(0xB809 <= code && code <= 0xB823) || // Lo [27] HANGUL SYLLABLE REG..HANGUL SYLLABLE REH\r\n\t\t(0xB825 <= code && code <= 0xB83F) || // Lo [27] HANGUL SYLLABLE RYEOG..HANGUL SYLLABLE RYEOH\r\n\t\t(0xB841 <= code && code <= 0xB85B) || // Lo [27] HANGUL SYLLABLE RYEG..HANGUL SYLLABLE RYEH\r\n\t\t(0xB85D <= code && code <= 0xB877) || // Lo [27] HANGUL SYLLABLE ROG..HANGUL SYLLABLE ROH\r\n\t\t(0xB879 <= code && code <= 0xB893) || // Lo [27] HANGUL SYLLABLE RWAG..HANGUL SYLLABLE RWAH\r\n\t\t(0xB895 <= code && code <= 0xB8AF) || // Lo [27] HANGUL SYLLABLE RWAEG..HANGUL SYLLABLE RWAEH\r\n\t\t(0xB8B1 <= code && code <= 0xB8CB) || // Lo [27] HANGUL SYLLABLE ROEG..HANGUL SYLLABLE ROEH\r\n\t\t(0xB8CD <= code && code <= 0xB8E7) || // Lo [27] HANGUL SYLLABLE RYOG..HANGUL SYLLABLE RYOH\r\n\t\t(0xB8E9 <= code && code <= 0xB903) || // Lo [27] HANGUL SYLLABLE RUG..HANGUL SYLLABLE RUH\r\n\t\t(0xB905 <= code && code <= 0xB91F) || // Lo [27] HANGUL SYLLABLE RWEOG..HANGUL SYLLABLE RWEOH\r\n\t\t(0xB921 <= code && code <= 0xB93B) || // Lo [27] HANGUL SYLLABLE RWEG..HANGUL SYLLABLE RWEH\r\n\t\t(0xB93D <= code && code <= 0xB957) || // Lo [27] HANGUL SYLLABLE RWIG..HANGUL SYLLABLE RWIH\r\n\t\t(0xB959 <= code && code <= 0xB973) || // Lo [27] HANGUL SYLLABLE RYUG..HANGUL SYLLABLE RYUH\r\n\t\t(0xB975 <= code && code <= 0xB98F) || // Lo [27] HANGUL SYLLABLE REUG..HANGUL SYLLABLE REUH\r\n\t\t(0xB991 <= code && code <= 0xB9AB) || // Lo [27] HANGUL SYLLABLE RYIG..HANGUL SYLLABLE RYIH\r\n\t\t(0xB9AD <= code && code <= 0xB9C7) || // Lo [27] HANGUL SYLLABLE RIG..HANGUL SYLLABLE RIH\r\n\t\t(0xB9C9 <= code && code <= 0xB9E3) || // Lo [27] HANGUL SYLLABLE MAG..HANGUL SYLLABLE MAH\r\n\t\t(0xB9E5 <= code && code <= 0xB9FF) || // Lo [27] HANGUL SYLLABLE MAEG..HANGUL SYLLABLE MAEH\r\n\t\t(0xBA01 <= code && code <= 0xBA1B) || // Lo [27] HANGUL SYLLABLE MYAG..HANGUL SYLLABLE MYAH\r\n\t\t(0xBA1D <= code && code <= 0xBA37) || // Lo [27] HANGUL SYLLABLE MYAEG..HANGUL SYLLABLE MYAEH\r\n\t\t(0xBA39 <= code && code <= 0xBA53) || // Lo [27] HANGUL SYLLABLE MEOG..HANGUL SYLLABLE MEOH\r\n\t\t(0xBA55 <= code && code <= 0xBA6F) || // Lo [27] HANGUL SYLLABLE MEG..HANGUL SYLLABLE MEH\r\n\t\t(0xBA71 <= code && code <= 0xBA8B) || // Lo [27] HANGUL SYLLABLE MYEOG..HANGUL SYLLABLE MYEOH\r\n\t\t(0xBA8D <= code && code <= 0xBAA7) || // Lo [27] HANGUL SYLLABLE MYEG..HANGUL SYLLABLE MYEH\r\n\t\t(0xBAA9 <= code && code <= 0xBAC3) || // Lo [27] HANGUL SYLLABLE MOG..HANGUL SYLLABLE MOH\r\n\t\t(0xBAC5 <= code && code <= 0xBADF) || // Lo [27] HANGUL SYLLABLE MWAG..HANGUL SYLLABLE MWAH\r\n\t\t(0xBAE1 <= code && code <= 0xBAFB) || // Lo [27] HANGUL SYLLABLE MWAEG..HANGUL SYLLABLE MWAEH\r\n\t\t(0xBAFD <= code && code <= 0xBB17) || // Lo [27] HANGUL SYLLABLE MOEG..HANGUL SYLLABLE MOEH\r\n\t\t(0xBB19 <= code && code <= 0xBB33) || // Lo [27] HANGUL SYLLABLE MYOG..HANGUL SYLLABLE MYOH\r\n\t\t(0xBB35 <= code && code <= 0xBB4F) || // Lo [27] HANGUL SYLLABLE MUG..HANGUL SYLLABLE MUH\r\n\t\t(0xBB51 <= code && code <= 0xBB6B) || // Lo [27] HANGUL SYLLABLE MWEOG..HANGUL SYLLABLE MWEOH\r\n\t\t(0xBB6D <= code && code <= 0xBB87) || // Lo [27] HANGUL SYLLABLE MWEG..HANGUL SYLLABLE MWEH\r\n\t\t(0xBB89 <= code && code <= 0xBBA3) || // Lo [27] HANGUL SYLLABLE MWIG..HANGUL SYLLABLE MWIH\r\n\t\t(0xBBA5 <= code && code <= 0xBBBF) || // Lo [27] HANGUL SYLLABLE MYUG..HANGUL SYLLABLE MYUH\r\n\t\t(0xBBC1 <= code && code <= 0xBBDB) || // Lo [27] HANGUL SYLLABLE MEUG..HANGUL SYLLABLE MEUH\r\n\t\t(0xBBDD <= code && code <= 0xBBF7) || // Lo [27] HANGUL SYLLABLE MYIG..HANGUL SYLLABLE MYIH\r\n\t\t(0xBBF9 <= code && code <= 0xBC13) || // Lo [27] HANGUL SYLLABLE MIG..HANGUL SYLLABLE MIH\r\n\t\t(0xBC15 <= code && code <= 0xBC2F) || // Lo [27] HANGUL SYLLABLE BAG..HANGUL SYLLABLE BAH\r\n\t\t(0xBC31 <= code && code <= 0xBC4B) || // Lo [27] HANGUL SYLLABLE BAEG..HANGUL SYLLABLE BAEH\r\n\t\t(0xBC4D <= code && code <= 0xBC67) || // Lo [27] HANGUL SYLLABLE BYAG..HANGUL SYLLABLE BYAH\r\n\t\t(0xBC69 <= code && code <= 0xBC83) || // Lo [27] HANGUL SYLLABLE BYAEG..HANGUL SYLLABLE BYAEH\r\n\t\t(0xBC85 <= code && code <= 0xBC9F) || // Lo [27] HANGUL SYLLABLE BEOG..HANGUL SYLLABLE BEOH\r\n\t\t(0xBCA1 <= code && code <= 0xBCBB) || // Lo [27] HANGUL SYLLABLE BEG..HANGUL SYLLABLE BEH\r\n\t\t(0xBCBD <= code && code <= 0xBCD7) || // Lo [27] HANGUL SYLLABLE BYEOG..HANGUL SYLLABLE BYEOH\r\n\t\t(0xBCD9 <= code && code <= 0xBCF3) || // Lo [27] HANGUL SYLLABLE BYEG..HANGUL SYLLABLE BYEH\r\n\t\t(0xBCF5 <= code && code <= 0xBD0F) || // Lo [27] HANGUL SYLLABLE BOG..HANGUL SYLLABLE BOH\r\n\t\t(0xBD11 <= code && code <= 0xBD2B) || // Lo [27] HANGUL SYLLABLE BWAG..HANGUL SYLLABLE BWAH\r\n\t\t(0xBD2D <= code && code <= 0xBD47) || // Lo [27] HANGUL SYLLABLE BWAEG..HANGUL SYLLABLE BWAEH\r\n\t\t(0xBD49 <= code && code <= 0xBD63) || // Lo [27] HANGUL SYLLABLE BOEG..HANGUL SYLLABLE BOEH\r\n\t\t(0xBD65 <= code && code <= 0xBD7F) || // Lo [27] HANGUL SYLLABLE BYOG..HANGUL SYLLABLE BYOH\r\n\t\t(0xBD81 <= code && code <= 0xBD9B) || // Lo [27] HANGUL SYLLABLE BUG..HANGUL SYLLABLE BUH\r\n\t\t(0xBD9D <= code && code <= 0xBDB7) || // Lo [27] HANGUL SYLLABLE BWEOG..HANGUL SYLLABLE BWEOH\r\n\t\t(0xBDB9 <= code && code <= 0xBDD3) || // Lo [27] HANGUL SYLLABLE BWEG..HANGUL SYLLABLE BWEH\r\n\t\t(0xBDD5 <= code && code <= 0xBDEF) || // Lo [27] HANGUL SYLLABLE BWIG..HANGUL SYLLABLE BWIH\r\n\t\t(0xBDF1 <= code && code <= 0xBE0B) || // Lo [27] HANGUL SYLLABLE BYUG..HANGUL SYLLABLE BYUH\r\n\t\t(0xBE0D <= code && code <= 0xBE27) || // Lo [27] HANGUL SYLLABLE BEUG..HANGUL SYLLABLE BEUH\r\n\t\t(0xBE29 <= code && code <= 0xBE43) || // Lo [27] HANGUL SYLLABLE BYIG..HANGUL SYLLABLE BYIH\r\n\t\t(0xBE45 <= code && code <= 0xBE5F) || // Lo [27] HANGUL SYLLABLE BIG..HANGUL SYLLABLE BIH\r\n\t\t(0xBE61 <= code && code <= 0xBE7B) || // Lo [27] HANGUL SYLLABLE BBAG..HANGUL SYLLABLE BBAH\r\n\t\t(0xBE7D <= code && code <= 0xBE97) || // Lo [27] HANGUL SYLLABLE BBAEG..HANGUL SYLLABLE BBAEH\r\n\t\t(0xBE99 <= code && code <= 0xBEB3) || // Lo [27] HANGUL SYLLABLE BBYAG..HANGUL SYLLABLE BBYAH\r\n\t\t(0xBEB5 <= code && code <= 0xBECF) || // Lo [27] HANGUL SYLLABLE BBYAEG..HANGUL SYLLABLE BBYAEH\r\n\t\t(0xBED1 <= code && code <= 0xBEEB) || // Lo [27] HANGUL SYLLABLE BBEOG..HANGUL SYLLABLE BBEOH\r\n\t\t(0xBEED <= code && code <= 0xBF07) || // Lo [27] HANGUL SYLLABLE BBEG..HANGUL SYLLABLE BBEH\r\n\t\t(0xBF09 <= code && code <= 0xBF23) || // Lo [27] HANGUL SYLLABLE BBYEOG..HANGUL SYLLABLE BBYEOH\r\n\t\t(0xBF25 <= code && code <= 0xBF3F) || // Lo [27] HANGUL SYLLABLE BBYEG..HANGUL SYLLABLE BBYEH\r\n\t\t(0xBF41 <= code && code <= 0xBF5B) || // Lo [27] HANGUL SYLLABLE BBOG..HANGUL SYLLABLE BBOH\r\n\t\t(0xBF5D <= code && code <= 0xBF77) || // Lo [27] HANGUL SYLLABLE BBWAG..HANGUL SYLLABLE BBWAH\r\n\t\t(0xBF79 <= code && code <= 0xBF93) || // Lo [27] HANGUL SYLLABLE BBWAEG..HANGUL SYLLABLE BBWAEH\r\n\t\t(0xBF95 <= code && code <= 0xBFAF) || // Lo [27] HANGUL SYLLABLE BBOEG..HANGUL SYLLABLE BBOEH\r\n\t\t(0xBFB1 <= code && code <= 0xBFCB) || // Lo [27] HANGUL SYLLABLE BBYOG..HANGUL SYLLABLE BBYOH\r\n\t\t(0xBFCD <= code && code <= 0xBFE7) || // Lo [27] HANGUL SYLLABLE BBUG..HANGUL SYLLABLE BBUH\r\n\t\t(0xBFE9 <= code && code <= 0xC003) || // Lo [27] HANGUL SYLLABLE BBWEOG..HANGUL SYLLABLE BBWEOH\r\n\t\t(0xC005 <= code && code <= 0xC01F) || // Lo [27] HANGUL SYLLABLE BBWEG..HANGUL SYLLABLE BBWEH\r\n\t\t(0xC021 <= code && code <= 0xC03B) || // Lo [27] HANGUL SYLLABLE BBWIG..HANGUL SYLLABLE BBWIH\r\n\t\t(0xC03D <= code && code <= 0xC057) || // Lo [27] HANGUL SYLLABLE BBYUG..HANGUL SYLLABLE BBYUH\r\n\t\t(0xC059 <= code && code <= 0xC073) || // Lo [27] HANGUL SYLLABLE BBEUG..HANGUL SYLLABLE BBEUH\r\n\t\t(0xC075 <= code && code <= 0xC08F) || // Lo [27] HANGUL SYLLABLE BBYIG..HANGUL SYLLABLE BBYIH\r\n\t\t(0xC091 <= code && code <= 0xC0AB) || // Lo [27] HANGUL SYLLABLE BBIG..HANGUL SYLLABLE BBIH\r\n\t\t(0xC0AD <= code && code <= 0xC0C7) || // Lo [27] HANGUL SYLLABLE SAG..HANGUL SYLLABLE SAH\r\n\t\t(0xC0C9 <= code && code <= 0xC0E3) || // Lo [27] HANGUL SYLLABLE SAEG..HANGUL SYLLABLE SAEH\r\n\t\t(0xC0E5 <= code && code <= 0xC0FF) || // Lo [27] HANGUL SYLLABLE SYAG..HANGUL SYLLABLE SYAH\r\n\t\t(0xC101 <= code && code <= 0xC11B) || // Lo [27] HANGUL SYLLABLE SYAEG..HANGUL SYLLABLE SYAEH\r\n\t\t(0xC11D <= code && code <= 0xC137) || // Lo [27] HANGUL SYLLABLE SEOG..HANGUL SYLLABLE SEOH\r\n\t\t(0xC139 <= code && code <= 0xC153) || // Lo [27] HANGUL SYLLABLE SEG..HANGUL SYLLABLE SEH\r\n\t\t(0xC155 <= code && code <= 0xC16F) || // Lo [27] HANGUL SYLLABLE SYEOG..HANGUL SYLLABLE SYEOH\r\n\t\t(0xC171 <= code && code <= 0xC18B) || // Lo [27] HANGUL SYLLABLE SYEG..HANGUL SYLLABLE SYEH\r\n\t\t(0xC18D <= code && code <= 0xC1A7) || // Lo [27] HANGUL SYLLABLE SOG..HANGUL SYLLABLE SOH\r\n\t\t(0xC1A9 <= code && code <= 0xC1C3) || // Lo [27] HANGUL SYLLABLE SWAG..HANGUL SYLLABLE SWAH\r\n\t\t(0xC1C5 <= code && code <= 0xC1DF) || // Lo [27] HANGUL SYLLABLE SWAEG..HANGUL SYLLABLE SWAEH\r\n\t\t(0xC1E1 <= code && code <= 0xC1FB) || // Lo [27] HANGUL SYLLABLE SOEG..HANGUL SYLLABLE SOEH\r\n\t\t(0xC1FD <= code && code <= 0xC217) || // Lo [27] HANGUL SYLLABLE SYOG..HANGUL SYLLABLE SYOH\r\n\t\t(0xC219 <= code && code <= 0xC233) || // Lo [27] HANGUL SYLLABLE SUG..HANGUL SYLLABLE SUH\r\n\t\t(0xC235 <= code && code <= 0xC24F) || // Lo [27] HANGUL SYLLABLE SWEOG..HANGUL SYLLABLE SWEOH\r\n\t\t(0xC251 <= code && code <= 0xC26B) || // Lo [27] HANGUL SYLLABLE SWEG..HANGUL SYLLABLE SWEH\r\n\t\t(0xC26D <= code && code <= 0xC287) || // Lo [27] HANGUL SYLLABLE SWIG..HANGUL SYLLABLE SWIH\r\n\t\t(0xC289 <= code && code <= 0xC2A3) || // Lo [27] HANGUL SYLLABLE SYUG..HANGUL SYLLABLE SYUH\r\n\t\t(0xC2A5 <= code && code <= 0xC2BF) || // Lo [27] HANGUL SYLLABLE SEUG..HANGUL SYLLABLE SEUH\r\n\t\t(0xC2C1 <= code && code <= 0xC2DB) || // Lo [27] HANGUL SYLLABLE SYIG..HANGUL SYLLABLE SYIH\r\n\t\t(0xC2DD <= code && code <= 0xC2F7) || // Lo [27] HANGUL SYLLABLE SIG..HANGUL SYLLABLE SIH\r\n\t\t(0xC2F9 <= code && code <= 0xC313) || // Lo [27] HANGUL SYLLABLE SSAG..HANGUL SYLLABLE SSAH\r\n\t\t(0xC315 <= code && code <= 0xC32F) || // Lo [27] HANGUL SYLLABLE SSAEG..HANGUL SYLLABLE SSAEH\r\n\t\t(0xC331 <= code && code <= 0xC34B) || // Lo [27] HANGUL SYLLABLE SSYAG..HANGUL SYLLABLE SSYAH\r\n\t\t(0xC34D <= code && code <= 0xC367) || // Lo [27] HANGUL SYLLABLE SSYAEG..HANGUL SYLLABLE SSYAEH\r\n\t\t(0xC369 <= code && code <= 0xC383) || // Lo [27] HANGUL SYLLABLE SSEOG..HANGUL SYLLABLE SSEOH\r\n\t\t(0xC385 <= code && code <= 0xC39F) || // Lo [27] HANGUL SYLLABLE SSEG..HANGUL SYLLABLE SSEH\r\n\t\t(0xC3A1 <= code && code <= 0xC3BB) || // Lo [27] HANGUL SYLLABLE SSYEOG..HANGUL SYLLABLE SSYEOH\r\n\t\t(0xC3BD <= code && code <= 0xC3D7) || // Lo [27] HANGUL SYLLABLE SSYEG..HANGUL SYLLABLE SSYEH\r\n\t\t(0xC3D9 <= code && code <= 0xC3F3) || // Lo [27] HANGUL SYLLABLE SSOG..HANGUL SYLLABLE SSOH\r\n\t\t(0xC3F5 <= code && code <= 0xC40F) || // Lo [27] HANGUL SYLLABLE SSWAG..HANGUL SYLLABLE SSWAH\r\n\t\t(0xC411 <= code && code <= 0xC42B) || // Lo [27] HANGUL SYLLABLE SSWAEG..HANGUL SYLLABLE SSWAEH\r\n\t\t(0xC42D <= code && code <= 0xC447) || // Lo [27] HANGUL SYLLABLE SSOEG..HANGUL SYLLABLE SSOEH\r\n\t\t(0xC449 <= code && code <= 0xC463) || // Lo [27] HANGUL SYLLABLE SSYOG..HANGUL SYLLABLE SSYOH\r\n\t\t(0xC465 <= code && code <= 0xC47F) || // Lo [27] HANGUL SYLLABLE SSUG..HANGUL SYLLABLE SSUH\r\n\t\t(0xC481 <= code && code <= 0xC49B) || // Lo [27] HANGUL SYLLABLE SSWEOG..HANGUL SYLLABLE SSWEOH\r\n\t\t(0xC49D <= code && code <= 0xC4B7) || // Lo [27] HANGUL SYLLABLE SSWEG..HANGUL SYLLABLE SSWEH\r\n\t\t(0xC4B9 <= code && code <= 0xC4D3) || // Lo [27] HANGUL SYLLABLE SSWIG..HANGUL SYLLABLE SSWIH\r\n\t\t(0xC4D5 <= code && code <= 0xC4EF) || // Lo [27] HANGUL SYLLABLE SSYUG..HANGUL SYLLABLE SSYUH\r\n\t\t(0xC4F1 <= code && code <= 0xC50B) || // Lo [27] HANGUL SYLLABLE SSEUG..HANGUL SYLLABLE SSEUH\r\n\t\t(0xC50D <= code && code <= 0xC527) || // Lo [27] HANGUL SYLLABLE SSYIG..HANGUL SYLLABLE SSYIH\r\n\t\t(0xC529 <= code && code <= 0xC543) || // Lo [27] HANGUL SYLLABLE SSIG..HANGUL SYLLABLE SSIH\r\n\t\t(0xC545 <= code && code <= 0xC55F) || // Lo [27] HANGUL SYLLABLE AG..HANGUL SYLLABLE AH\r\n\t\t(0xC561 <= code && code <= 0xC57B) || // Lo [27] HANGUL SYLLABLE AEG..HANGUL SYLLABLE AEH\r\n\t\t(0xC57D <= code && code <= 0xC597) || // Lo [27] HANGUL SYLLABLE YAG..HANGUL SYLLABLE YAH\r\n\t\t(0xC599 <= code && code <= 0xC5B3) || // Lo [27] HANGUL SYLLABLE YAEG..HANGUL SYLLABLE YAEH\r\n\t\t(0xC5B5 <= code && code <= 0xC5CF) || // Lo [27] HANGUL SYLLABLE EOG..HANGUL SYLLABLE EOH\r\n\t\t(0xC5D1 <= code && code <= 0xC5EB) || // Lo [27] HANGUL SYLLABLE EG..HANGUL SYLLABLE EH\r\n\t\t(0xC5ED <= code && code <= 0xC607) || // Lo [27] HANGUL SYLLABLE YEOG..HANGUL SYLLABLE YEOH\r\n\t\t(0xC609 <= code && code <= 0xC623) || // Lo [27] HANGUL SYLLABLE YEG..HANGUL SYLLABLE YEH\r\n\t\t(0xC625 <= code && code <= 0xC63F) || // Lo [27] HANGUL SYLLABLE OG..HANGUL SYLLABLE OH\r\n\t\t(0xC641 <= code && code <= 0xC65B) || // Lo [27] HANGUL SYLLABLE WAG..HANGUL SYLLABLE WAH\r\n\t\t(0xC65D <= code && code <= 0xC677) || // Lo [27] HANGUL SYLLABLE WAEG..HANGUL SYLLABLE WAEH\r\n\t\t(0xC679 <= code && code <= 0xC693) || // Lo [27] HANGUL SYLLABLE OEG..HANGUL SYLLABLE OEH\r\n\t\t(0xC695 <= code && code <= 0xC6AF) || // Lo [27] HANGUL SYLLABLE YOG..HANGUL SYLLABLE YOH\r\n\t\t(0xC6B1 <= code && code <= 0xC6CB) || // Lo [27] HANGUL SYLLABLE UG..HANGUL SYLLABLE UH\r\n\t\t(0xC6CD <= code && code <= 0xC6E7) || // Lo [27] HANGUL SYLLABLE WEOG..HANGUL SYLLABLE WEOH\r\n\t\t(0xC6E9 <= code && code <= 0xC703) || // Lo [27] HANGUL SYLLABLE WEG..HANGUL SYLLABLE WEH\r\n\t\t(0xC705 <= code && code <= 0xC71F) || // Lo [27] HANGUL SYLLABLE WIG..HANGUL SYLLABLE WIH\r\n\t\t(0xC721 <= code && code <= 0xC73B) || // Lo [27] HANGUL SYLLABLE YUG..HANGUL SYLLABLE YUH\r\n\t\t(0xC73D <= code && code <= 0xC757) || // Lo [27] HANGUL SYLLABLE EUG..HANGUL SYLLABLE EUH\r\n\t\t(0xC759 <= code && code <= 0xC773) || // Lo [27] HANGUL SYLLABLE YIG..HANGUL SYLLABLE YIH\r\n\t\t(0xC775 <= code && code <= 0xC78F) || // Lo [27] HANGUL SYLLABLE IG..HANGUL SYLLABLE IH\r\n\t\t(0xC791 <= code && code <= 0xC7AB) || // Lo [27] HANGUL SYLLABLE JAG..HANGUL SYLLABLE JAH\r\n\t\t(0xC7AD <= code && code <= 0xC7C7) || // Lo [27] HANGUL SYLLABLE JAEG..HANGUL SYLLABLE JAEH\r\n\t\t(0xC7C9 <= code && code <= 0xC7E3) || // Lo [27] HANGUL SYLLABLE JYAG..HANGUL SYLLABLE JYAH\r\n\t\t(0xC7E5 <= code && code <= 0xC7FF) || // Lo [27] HANGUL SYLLABLE JYAEG..HANGUL SYLLABLE JYAEH\r\n\t\t(0xC801 <= code && code <= 0xC81B) || // Lo [27] HANGUL SYLLABLE JEOG..HANGUL SYLLABLE JEOH\r\n\t\t(0xC81D <= code && code <= 0xC837) || // Lo [27] HANGUL SYLLABLE JEG..HANGUL SYLLABLE JEH\r\n\t\t(0xC839 <= code && code <= 0xC853) || // Lo [27] HANGUL SYLLABLE JYEOG..HANGUL SYLLABLE JYEOH\r\n\t\t(0xC855 <= code && code <= 0xC86F) || // Lo [27] HANGUL SYLLABLE JYEG..HANGUL SYLLABLE JYEH\r\n\t\t(0xC871 <= code && code <= 0xC88B) || // Lo [27] HANGUL SYLLABLE JOG..HANGUL SYLLABLE JOH\r\n\t\t(0xC88D <= code && code <= 0xC8A7) || // Lo [27] HANGUL SYLLABLE JWAG..HANGUL SYLLABLE JWAH\r\n\t\t(0xC8A9 <= code && code <= 0xC8C3) || // Lo [27] HANGUL SYLLABLE JWAEG..HANGUL SYLLABLE JWAEH\r\n\t\t(0xC8C5 <= code && code <= 0xC8DF) || // Lo [27] HANGUL SYLLABLE JOEG..HANGUL SYLLABLE JOEH\r\n\t\t(0xC8E1 <= code && code <= 0xC8FB) || // Lo [27] HANGUL SYLLABLE JYOG..HANGUL SYLLABLE JYOH\r\n\t\t(0xC8FD <= code && code <= 0xC917) || // Lo [27] HANGUL SYLLABLE JUG..HANGUL SYLLABLE JUH\r\n\t\t(0xC919 <= code && code <= 0xC933) || // Lo [27] HANGUL SYLLABLE JWEOG..HANGUL SYLLABLE JWEOH\r\n\t\t(0xC935 <= code && code <= 0xC94F) || // Lo [27] HANGUL SYLLABLE JWEG..HANGUL SYLLABLE JWEH\r\n\t\t(0xC951 <= code && code <= 0xC96B) || // Lo [27] HANGUL SYLLABLE JWIG..HANGUL SYLLABLE JWIH\r\n\t\t(0xC96D <= code && code <= 0xC987) || // Lo [27] HANGUL SYLLABLE JYUG..HANGUL SYLLABLE JYUH\r\n\t\t(0xC989 <= code && code <= 0xC9A3) || // Lo [27] HANGUL SYLLABLE JEUG..HANGUL SYLLABLE JEUH\r\n\t\t(0xC9A5 <= code && code <= 0xC9BF) || // Lo [27] HANGUL SYLLABLE JYIG..HANGUL SYLLABLE JYIH\r\n\t\t(0xC9C1 <= code && code <= 0xC9DB) || // Lo [27] HANGUL SYLLABLE JIG..HANGUL SYLLABLE JIH\r\n\t\t(0xC9DD <= code && code <= 0xC9F7) || // Lo [27] HANGUL SYLLABLE JJAG..HANGUL SYLLABLE JJAH\r\n\t\t(0xC9F9 <= code && code <= 0xCA13) || // Lo [27] HANGUL SYLLABLE JJAEG..HANGUL SYLLABLE JJAEH\r\n\t\t(0xCA15 <= code && code <= 0xCA2F) || // Lo [27] HANGUL SYLLABLE JJYAG..HANGUL SYLLABLE JJYAH\r\n\t\t(0xCA31 <= code && code <= 0xCA4B) || // Lo [27] HANGUL SYLLABLE JJYAEG..HANGUL SYLLABLE JJYAEH\r\n\t\t(0xCA4D <= code && code <= 0xCA67) || // Lo [27] HANGUL SYLLABLE JJEOG..HANGUL SYLLABLE JJEOH\r\n\t\t(0xCA69 <= code && code <= 0xCA83) || // Lo [27] HANGUL SYLLABLE JJEG..HANGUL SYLLABLE JJEH\r\n\t\t(0xCA85 <= code && code <= 0xCA9F) || // Lo [27] HANGUL SYLLABLE JJYEOG..HANGUL SYLLABLE JJYEOH\r\n\t\t(0xCAA1 <= code && code <= 0xCABB) || // Lo [27] HANGUL SYLLABLE JJYEG..HANGUL SYLLABLE JJYEH\r\n\t\t(0xCABD <= code && code <= 0xCAD7) || // Lo [27] HANGUL SYLLABLE JJOG..HANGUL SYLLABLE JJOH\r\n\t\t(0xCAD9 <= code && code <= 0xCAF3) || // Lo [27] HANGUL SYLLABLE JJWAG..HANGUL SYLLABLE JJWAH\r\n\t\t(0xCAF5 <= code && code <= 0xCB0F) || // Lo [27] HANGUL SYLLABLE JJWAEG..HANGUL SYLLABLE JJWAEH\r\n\t\t(0xCB11 <= code && code <= 0xCB2B) || // Lo [27] HANGUL SYLLABLE JJOEG..HANGUL SYLLABLE JJOEH\r\n\t\t(0xCB2D <= code && code <= 0xCB47) || // Lo [27] HANGUL SYLLABLE JJYOG..HANGUL SYLLABLE JJYOH\r\n\t\t(0xCB49 <= code && code <= 0xCB63) || // Lo [27] HANGUL SYLLABLE JJUG..HANGUL SYLLABLE JJUH\r\n\t\t(0xCB65 <= code && code <= 0xCB7F) || // Lo [27] HANGUL SYLLABLE JJWEOG..HANGUL SYLLABLE JJWEOH\r\n\t\t(0xCB81 <= code && code <= 0xCB9B) || // Lo [27] HANGUL SYLLABLE JJWEG..HANGUL SYLLABLE JJWEH\r\n\t\t(0xCB9D <= code && code <= 0xCBB7) || // Lo [27] HANGUL SYLLABLE JJWIG..HANGUL SYLLABLE JJWIH\r\n\t\t(0xCBB9 <= code && code <= 0xCBD3) || // Lo [27] HANGUL SYLLABLE JJYUG..HANGUL SYLLABLE JJYUH\r\n\t\t(0xCBD5 <= code && code <= 0xCBEF) || // Lo [27] HANGUL SYLLABLE JJEUG..HANGUL SYLLABLE JJEUH\r\n\t\t(0xCBF1 <= code && code <= 0xCC0B) || // Lo [27] HANGUL SYLLABLE JJYIG..HANGUL SYLLABLE JJYIH\r\n\t\t(0xCC0D <= code && code <= 0xCC27) || // Lo [27] HANGUL SYLLABLE JJIG..HANGUL SYLLABLE JJIH\r\n\t\t(0xCC29 <= code && code <= 0xCC43) || // Lo [27] HANGUL SYLLABLE CAG..HANGUL SYLLABLE CAH\r\n\t\t(0xCC45 <= code && code <= 0xCC5F) || // Lo [27] HANGUL SYLLABLE CAEG..HANGUL SYLLABLE CAEH\r\n\t\t(0xCC61 <= code && code <= 0xCC7B) || // Lo [27] HANGUL SYLLABLE CYAG..HANGUL SYLLABLE CYAH\r\n\t\t(0xCC7D <= code && code <= 0xCC97) || // Lo [27] HANGUL SYLLABLE CYAEG..HANGUL SYLLABLE CYAEH\r\n\t\t(0xCC99 <= code && code <= 0xCCB3) || // Lo [27] HANGUL SYLLABLE CEOG..HANGUL SYLLABLE CEOH\r\n\t\t(0xCCB5 <= code && code <= 0xCCCF) || // Lo [27] HANGUL SYLLABLE CEG..HANGUL SYLLABLE CEH\r\n\t\t(0xCCD1 <= code && code <= 0xCCEB) || // Lo [27] HANGUL SYLLABLE CYEOG..HANGUL SYLLABLE CYEOH\r\n\t\t(0xCCED <= code && code <= 0xCD07) || // Lo [27] HANGUL SYLLABLE CYEG..HANGUL SYLLABLE CYEH\r\n\t\t(0xCD09 <= code && code <= 0xCD23) || // Lo [27] HANGUL SYLLABLE COG..HANGUL SYLLABLE COH\r\n\t\t(0xCD25 <= code && code <= 0xCD3F) || // Lo [27] HANGUL SYLLABLE CWAG..HANGUL SYLLABLE CWAH\r\n\t\t(0xCD41 <= code && code <= 0xCD5B) || // Lo [27] HANGUL SYLLABLE CWAEG..HANGUL SYLLABLE CWAEH\r\n\t\t(0xCD5D <= code && code <= 0xCD77) || // Lo [27] HANGUL SYLLABLE COEG..HANGUL SYLLABLE COEH\r\n\t\t(0xCD79 <= code && code <= 0xCD93) || // Lo [27] HANGUL SYLLABLE CYOG..HANGUL SYLLABLE CYOH\r\n\t\t(0xCD95 <= code && code <= 0xCDAF) || // Lo [27] HANGUL SYLLABLE CUG..HANGUL SYLLABLE CUH\r\n\t\t(0xCDB1 <= code && code <= 0xCDCB) || // Lo [27] HANGUL SYLLABLE CWEOG..HANGUL SYLLABLE CWEOH\r\n\t\t(0xCDCD <= code && code <= 0xCDE7) || // Lo [27] HANGUL SYLLABLE CWEG..HANGUL SYLLABLE CWEH\r\n\t\t(0xCDE9 <= code && code <= 0xCE03) || // Lo [27] HANGUL SYLLABLE CWIG..HANGUL SYLLABLE CWIH\r\n\t\t(0xCE05 <= code && code <= 0xCE1F) || // Lo [27] HANGUL SYLLABLE CYUG..HANGUL SYLLABLE CYUH\r\n\t\t(0xCE21 <= code && code <= 0xCE3B) || // Lo [27] HANGUL SYLLABLE CEUG..HANGUL SYLLABLE CEUH\r\n\t\t(0xCE3D <= code && code <= 0xCE57) || // Lo [27] HANGUL SYLLABLE CYIG..HANGUL SYLLABLE CYIH\r\n\t\t(0xCE59 <= code && code <= 0xCE73) || // Lo [27] HANGUL SYLLABLE CIG..HANGUL SYLLABLE CIH\r\n\t\t(0xCE75 <= code && code <= 0xCE8F) || // Lo [27] HANGUL SYLLABLE KAG..HANGUL SYLLABLE KAH\r\n\t\t(0xCE91 <= code && code <= 0xCEAB) || // Lo [27] HANGUL SYLLABLE KAEG..HANGUL SYLLABLE KAEH\r\n\t\t(0xCEAD <= code && code <= 0xCEC7) || // Lo [27] HANGUL SYLLABLE KYAG..HANGUL SYLLABLE KYAH\r\n\t\t(0xCEC9 <= code && code <= 0xCEE3) || // Lo [27] HANGUL SYLLABLE KYAEG..HANGUL SYLLABLE KYAEH\r\n\t\t(0xCEE5 <= code && code <= 0xCEFF) || // Lo [27] HANGUL SYLLABLE KEOG..HANGUL SYLLABLE KEOH\r\n\t\t(0xCF01 <= code && code <= 0xCF1B) || // Lo [27] HANGUL SYLLABLE KEG..HANGUL SYLLABLE KEH\r\n\t\t(0xCF1D <= code && code <= 0xCF37) || // Lo [27] HANGUL SYLLABLE KYEOG..HANGUL SYLLABLE KYEOH\r\n\t\t(0xCF39 <= code && code <= 0xCF53) || // Lo [27] HANGUL SYLLABLE KYEG..HANGUL SYLLABLE KYEH\r\n\t\t(0xCF55 <= code && code <= 0xCF6F) || // Lo [27] HANGUL SYLLABLE KOG..HANGUL SYLLABLE KOH\r\n\t\t(0xCF71 <= code && code <= 0xCF8B) || // Lo [27] HANGUL SYLLABLE KWAG..HANGUL SYLLABLE KWAH\r\n\t\t(0xCF8D <= code && code <= 0xCFA7) || // Lo [27] HANGUL SYLLABLE KWAEG..HANGUL SYLLABLE KWAEH\r\n\t\t(0xCFA9 <= code && code <= 0xCFC3) || // Lo [27] HANGUL SYLLABLE KOEG..HANGUL SYLLABLE KOEH\r\n\t\t(0xCFC5 <= code && code <= 0xCFDF) || // Lo [27] HANGUL SYLLABLE KYOG..HANGUL SYLLABLE KYOH\r\n\t\t(0xCFE1 <= code && code <= 0xCFFB) || // Lo [27] HANGUL SYLLABLE KUG..HANGUL SYLLABLE KUH\r\n\t\t(0xCFFD <= code && code <= 0xD017) || // Lo [27] HANGUL SYLLABLE KWEOG..HANGUL SYLLABLE KWEOH\r\n\t\t(0xD019 <= code && code <= 0xD033) || // Lo [27] HANGUL SYLLABLE KWEG..HANGUL SYLLABLE KWEH\r\n\t\t(0xD035 <= code && code <= 0xD04F) || // Lo [27] HANGUL SYLLABLE KWIG..HANGUL SYLLABLE KWIH\r\n\t\t(0xD051 <= code && code <= 0xD06B) || // Lo [27] HANGUL SYLLABLE KYUG..HANGUL SYLLABLE KYUH\r\n\t\t(0xD06D <= code && code <= 0xD087) || // Lo [27] HANGUL SYLLABLE KEUG..HANGUL SYLLABLE KEUH\r\n\t\t(0xD089 <= code && code <= 0xD0A3) || // Lo [27] HANGUL SYLLABLE KYIG..HANGUL SYLLABLE KYIH\r\n\t\t(0xD0A5 <= code && code <= 0xD0BF) || // Lo [27] HANGUL SYLLABLE KIG..HANGUL SYLLABLE KIH\r\n\t\t(0xD0C1 <= code && code <= 0xD0DB) || // Lo [27] HANGUL SYLLABLE TAG..HANGUL SYLLABLE TAH\r\n\t\t(0xD0DD <= code && code <= 0xD0F7) || // Lo [27] HANGUL SYLLABLE TAEG..HANGUL SYLLABLE TAEH\r\n\t\t(0xD0F9 <= code && code <= 0xD113) || // Lo [27] HANGUL SYLLABLE TYAG..HANGUL SYLLABLE TYAH\r\n\t\t(0xD115 <= code && code <= 0xD12F) || // Lo [27] HANGUL SYLLABLE TYAEG..HANGUL SYLLABLE TYAEH\r\n\t\t(0xD131 <= code && code <= 0xD14B) || // Lo [27] HANGUL SYLLABLE TEOG..HANGUL SYLLABLE TEOH\r\n\t\t(0xD14D <= code && code <= 0xD167) || // Lo [27] HANGUL SYLLABLE TEG..HANGUL SYLLABLE TEH\r\n\t\t(0xD169 <= code && code <= 0xD183) || // Lo [27] HANGUL SYLLABLE TYEOG..HANGUL SYLLABLE TYEOH\r\n\t\t(0xD185 <= code && code <= 0xD19F) || // Lo [27] HANGUL SYLLABLE TYEG..HANGUL SYLLABLE TYEH\r\n\t\t(0xD1A1 <= code && code <= 0xD1BB) || // Lo [27] HANGUL SYLLABLE TOG..HANGUL SYLLABLE TOH\r\n\t\t(0xD1BD <= code && code <= 0xD1D7) || // Lo [27] HANGUL SYLLABLE TWAG..HANGUL SYLLABLE TWAH\r\n\t\t(0xD1D9 <= code && code <= 0xD1F3) || // Lo [27] HANGUL SYLLABLE TWAEG..HANGUL SYLLABLE TWAEH\r\n\t\t(0xD1F5 <= code && code <= 0xD20F) || // Lo [27] HANGUL SYLLABLE TOEG..HANGUL SYLLABLE TOEH\r\n\t\t(0xD211 <= code && code <= 0xD22B) || // Lo [27] HANGUL SYLLABLE TYOG..HANGUL SYLLABLE TYOH\r\n\t\t(0xD22D <= code && code <= 0xD247) || // Lo [27] HANGUL SYLLABLE TUG..HANGUL SYLLABLE TUH\r\n\t\t(0xD249 <= code && code <= 0xD263) || // Lo [27] HANGUL SYLLABLE TWEOG..HANGUL SYLLABLE TWEOH\r\n\t\t(0xD265 <= code && code <= 0xD27F) || // Lo [27] HANGUL SYLLABLE TWEG..HANGUL SYLLABLE TWEH\r\n\t\t(0xD281 <= code && code <= 0xD29B) || // Lo [27] HANGUL SYLLABLE TWIG..HANGUL SYLLABLE TWIH\r\n\t\t(0xD29D <= code && code <= 0xD2B7) || // Lo [27] HANGUL SYLLABLE TYUG..HANGUL SYLLABLE TYUH\r\n\t\t(0xD2B9 <= code && code <= 0xD2D3) || // Lo [27] HANGUL SYLLABLE TEUG..HANGUL SYLLABLE TEUH\r\n\t\t(0xD2D5 <= code && code <= 0xD2EF) || // Lo [27] HANGUL SYLLABLE TYIG..HANGUL SYLLABLE TYIH\r\n\t\t(0xD2F1 <= code && code <= 0xD30B) || // Lo [27] HANGUL SYLLABLE TIG..HANGUL SYLLABLE TIH\r\n\t\t(0xD30D <= code && code <= 0xD327) || // Lo [27] HANGUL SYLLABLE PAG..HANGUL SYLLABLE PAH\r\n\t\t(0xD329 <= code && code <= 0xD343) || // Lo [27] HANGUL SYLLABLE PAEG..HANGUL SYLLABLE PAEH\r\n\t\t(0xD345 <= code && code <= 0xD35F) || // Lo [27] HANGUL SYLLABLE PYAG..HANGUL SYLLABLE PYAH\r\n\t\t(0xD361 <= code && code <= 0xD37B) || // Lo [27] HANGUL SYLLABLE PYAEG..HANGUL SYLLABLE PYAEH\r\n\t\t(0xD37D <= code && code <= 0xD397) || // Lo [27] HANGUL SYLLABLE PEOG..HANGUL SYLLABLE PEOH\r\n\t\t(0xD399 <= code && code <= 0xD3B3) || // Lo [27] HANGUL SYLLABLE PEG..HANGUL SYLLABLE PEH\r\n\t\t(0xD3B5 <= code && code <= 0xD3CF) || // Lo [27] HANGUL SYLLABLE PYEOG..HANGUL SYLLABLE PYEOH\r\n\t\t(0xD3D1 <= code && code <= 0xD3EB) || // Lo [27] HANGUL SYLLABLE PYEG..HANGUL SYLLABLE PYEH\r\n\t\t(0xD3ED <= code && code <= 0xD407) || // Lo [27] HANGUL SYLLABLE POG..HANGUL SYLLABLE POH\r\n\t\t(0xD409 <= code && code <= 0xD423) || // Lo [27] HANGUL SYLLABLE PWAG..HANGUL SYLLABLE PWAH\r\n\t\t(0xD425 <= code && code <= 0xD43F) || // Lo [27] HANGUL SYLLABLE PWAEG..HANGUL SYLLABLE PWAEH\r\n\t\t(0xD441 <= code && code <= 0xD45B) || // Lo [27] HANGUL SYLLABLE POEG..HANGUL SYLLABLE POEH\r\n\t\t(0xD45D <= code && code <= 0xD477) || // Lo [27] HANGUL SYLLABLE PYOG..HANGUL SYLLABLE PYOH\r\n\t\t(0xD479 <= code && code <= 0xD493) || // Lo [27] HANGUL SYLLABLE PUG..HANGUL SYLLABLE PUH\r\n\t\t(0xD495 <= code && code <= 0xD4AF) || // Lo [27] HANGUL SYLLABLE PWEOG..HANGUL SYLLABLE PWEOH\r\n\t\t(0xD4B1 <= code && code <= 0xD4CB) || // Lo [27] HANGUL SYLLABLE PWEG..HANGUL SYLLABLE PWEH\r\n\t\t(0xD4CD <= code && code <= 0xD4E7) || // Lo [27] HANGUL SYLLABLE PWIG..HANGUL SYLLABLE PWIH\r\n\t\t(0xD4E9 <= code && code <= 0xD503) || // Lo [27] HANGUL SYLLABLE PYUG..HANGUL SYLLABLE PYUH\r\n\t\t(0xD505 <= code && code <= 0xD51F) || // Lo [27] HANGUL SYLLABLE PEUG..HANGUL SYLLABLE PEUH\r\n\t\t(0xD521 <= code && code <= 0xD53B) || // Lo [27] HANGUL SYLLABLE PYIG..HANGUL SYLLABLE PYIH\r\n\t\t(0xD53D <= code && code <= 0xD557) || // Lo [27] HANGUL SYLLABLE PIG..HANGUL SYLLABLE PIH\r\n\t\t(0xD559 <= code && code <= 0xD573) || // Lo [27] HANGUL SYLLABLE HAG..HANGUL SYLLABLE HAH\r\n\t\t(0xD575 <= code && code <= 0xD58F) || // Lo [27] HANGUL SYLLABLE HAEG..HANGUL SYLLABLE HAEH\r\n\t\t(0xD591 <= code && code <= 0xD5AB) || // Lo [27] HANGUL SYLLABLE HYAG..HANGUL SYLLABLE HYAH\r\n\t\t(0xD5AD <= code && code <= 0xD5C7) || // Lo [27] HANGUL SYLLABLE HYAEG..HANGUL SYLLABLE HYAEH\r\n\t\t(0xD5C9 <= code && code <= 0xD5E3) || // Lo [27] HANGUL SYLLABLE HEOG..HANGUL SYLLABLE HEOH\r\n\t\t(0xD5E5 <= code && code <= 0xD5FF) || // Lo [27] HANGUL SYLLABLE HEG..HANGUL SYLLABLE HEH\r\n\t\t(0xD601 <= code && code <= 0xD61B) || // Lo [27] HANGUL SYLLABLE HYEOG..HANGUL SYLLABLE HYEOH\r\n\t\t(0xD61D <= code && code <= 0xD637) || // Lo [27] HANGUL SYLLABLE HYEG..HANGUL SYLLABLE HYEH\r\n\t\t(0xD639 <= code && code <= 0xD653) || // Lo [27] HANGUL SYLLABLE HOG..HANGUL SYLLABLE HOH\r\n\t\t(0xD655 <= code && code <= 0xD66F) || // Lo [27] HANGUL SYLLABLE HWAG..HANGUL SYLLABLE HWAH\r\n\t\t(0xD671 <= code && code <= 0xD68B) || // Lo [27] HANGUL SYLLABLE HWAEG..HANGUL SYLLABLE HWAEH\r\n\t\t(0xD68D <= code && code <= 0xD6A7) || // Lo [27] HANGUL SYLLABLE HOEG..HANGUL SYLLABLE HOEH\r\n\t\t(0xD6A9 <= code && code <= 0xD6C3) || // Lo [27] HANGUL SYLLABLE HYOG..HANGUL SYLLABLE HYOH\r\n\t\t(0xD6C5 <= code && code <= 0xD6DF) || // Lo [27] HANGUL SYLLABLE HUG..HANGUL SYLLABLE HUH\r\n\t\t(0xD6E1 <= code && code <= 0xD6FB) || // Lo [27] HANGUL SYLLABLE HWEOG..HANGUL SYLLABLE HWEOH\r\n\t\t(0xD6FD <= code && code <= 0xD717) || // Lo [27] HANGUL SYLLABLE HWEG..HANGUL SYLLABLE HWEH\r\n\t\t(0xD719 <= code && code <= 0xD733) || // Lo [27] HANGUL SYLLABLE HWIG..HANGUL SYLLABLE HWIH\r\n\t\t(0xD735 <= code && code <= 0xD74F) || // Lo [27] HANGUL SYLLABLE HYUG..HANGUL SYLLABLE HYUH\r\n\t\t(0xD751 <= code && code <= 0xD76B) || // Lo [27] HANGUL SYLLABLE HEUG..HANGUL SYLLABLE HEUH\r\n\t\t(0xD76D <= code && code <= 0xD787) || // Lo [27] HANGUL SYLLABLE HYIG..HANGUL SYLLABLE HYIH\r\n\t\t(0xD789 <= code && code <= 0xD7A3) // Lo [27] HANGUL SYLLABLE HIG..HANGUL SYLLABLE HIH\r\n\t\t){\r\n\t\t\treturn LVT;\r\n\t\t}\r\n\t\t\r\n\t\tif(\r\n\t\t0x261D == code || // So WHITE UP POINTING INDEX\r\n\t\t0x26F9 == code || // So PERSON WITH BALL\r\n\t\t(0x270A <= code && code <= 0x270D) || // So [4] RAISED FIST..WRITING HAND\r\n\t\t0x1F385 == code || // So FATHER CHRISTMAS\r\n\t\t(0x1F3C2 <= code && code <= 0x1F3C4) || // So [3] SNOWBOARDER..SURFER\r\n\t\t0x1F3C7 == code || // So HORSE RACING\r\n\t\t(0x1F3CA <= code && code <= 0x1F3CC) || // So [3] SWIMMER..GOLFER\r\n\t\t(0x1F442 <= code && code <= 0x1F443) || // So [2] EAR..NOSE\r\n\t\t(0x1F446 <= code && code <= 0x1F450) || // So [11] WHITE UP POINTING BACKHAND INDEX..OPEN HANDS SIGN\r\n\t\t0x1F46E == code || // So POLICE OFFICER\r\n\t\t(0x1F470 <= code && code <= 0x1F478) || // So [9] BRIDE WITH VEIL..PRINCESS\r\n\t\t0x1F47C == code || // So BABY ANGEL\r\n\t\t(0x1F481 <= code && code <= 0x1F483) || // So [3] INFORMATION DESK PERSON..DANCER\r\n\t\t(0x1F485 <= code && code <= 0x1F487) || // So [3] NAIL POLISH..HAIRCUT\r\n\t\t0x1F4AA == code || // So FLEXED BICEPS\r\n\t\t(0x1F574 <= code && code <= 0x1F575) || // So [2] MAN IN BUSINESS SUIT LEVITATING..SLEUTH OR SPY\r\n\t\t0x1F57A == code || // So MAN DANCING\r\n\t\t0x1F590 == code || // So RAISED HAND WITH FINGERS SPLAYED\r\n\t\t(0x1F595 <= code && code <= 0x1F596) || // So [2] REVERSED HAND WITH MIDDLE FINGER EXTENDED..RAISED HAND WITH PART BETWEEN MIDDLE AND RING FINGERS\r\n\t\t(0x1F645 <= code && code <= 0x1F647) || // So [3] FACE WITH NO GOOD GESTURE..PERSON BOWING DEEPLY\r\n\t\t(0x1F64B <= code && code <= 0x1F64F) || // So [5] HAPPY PERSON RAISING ONE HAND..PERSON WITH FOLDED HANDS\r\n\t\t0x1F6A3 == code || // So ROWBOAT\r\n\t\t(0x1F6B4 <= code && code <= 0x1F6B6) || // So [3] BICYCLIST..PEDESTRIAN\r\n\t\t0x1F6C0 == code || // So BATH\r\n\t\t0x1F6CC == code || // So SLEEPING ACCOMMODATION\r\n\t\t(0x1F918 <= code && code <= 0x1F91C) || // So [5] SIGN OF THE HORNS..RIGHT-FACING FIST\r\n\t\t(0x1F91E <= code && code <= 0x1F91F) || // So [2] HAND WITH INDEX AND MIDDLE FINGERS CROSSED..I LOVE YOU HAND SIGN\r\n\t\t0x1F926 == code || // So FACE PALM\r\n\t\t(0x1F930 <= code && code <= 0x1F939) || // So [10] PREGNANT WOMAN..JUGGLING\r\n\t\t(0x1F93D <= code && code <= 0x1F93E) || // So [2] WATER POLO..HANDBALL\r\n\t\t(0x1F9D1 <= code && code <= 0x1F9DD) // So [13] ADULT..ELF\r\n\t\t){\r\n\t\t\treturn E_Base;\r\n\t\t}\r\n\r\n\t\tif(\r\n\t\t(0x1F3FB <= code && code <= 0x1F3FF) // Sk [5] EMOJI MODIFIER FITZPATRICK TYPE-1-2..EMOJI MODIFIER FITZPATRICK TYPE-6\r\n\t\t){\r\n\t\t\treturn E_Modifier;\r\n\t\t}\r\n\r\n\t\tif(\r\n\t\t0x200D == code // Cf ZERO WIDTH JOINER\r\n\t\t){\r\n\t\t\treturn ZWJ;\r\n\t\t}\r\n\r\n\t\tif(\r\n\t\t0x2640 == code || // So FEMALE SIGN\r\n\t\t0x2642 == code || // So MALE SIGN\r\n\t\t(0x2695 <= code && code <= 0x2696) || // So [2] STAFF OF AESCULAPIUS..SCALES\r\n\t\t0x2708 == code || // So AIRPLANE\r\n\t\t0x2764 == code || // So HEAVY BLACK HEART\r\n\t\t0x1F308 == code || // So RAINBOW\r\n\t\t0x1F33E == code || // So EAR OF RICE\r\n\t\t0x1F373 == code || // So COOKING\r\n\t\t0x1F393 == code || // So GRADUATION CAP\r\n\t\t0x1F3A4 == code || // So MICROPHONE\r\n\t\t0x1F3A8 == code || // So ARTIST PALETTE\r\n\t\t0x1F3EB == code || // So SCHOOL\r\n\t\t0x1F3ED == code || // So FACTORY\r\n\t\t0x1F48B == code || // So KISS MARK\r\n\t\t(0x1F4BB <= code && code <= 0x1F4BC) || // So [2] PERSONAL COMPUTER..BRIEFCASE\r\n\t\t0x1F527 == code || // So WRENCH\r\n\t\t0x1F52C == code || // So MICROSCOPE\r\n\t\t0x1F5E8 == code || // So LEFT SPEECH BUBBLE\r\n\t\t0x1F680 == code || // So ROCKET\r\n\t\t0x1F692 == code // So FIRE ENGINE\r\n\t\t){\r\n\t\t\treturn Glue_After_Zwj;\r\n\t\t}\r\n\r\n\t\tif(\r\n\t\t(0x1F466 <= code && code <= 0x1F469) // So [4] BOY..WOMAN\r\n\t\t){\r\n\t\t\treturn E_Base_GAZ;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\t//all unlisted characters have a grapheme break property of \"Other\"\r\n\t\treturn Other;\r\n\t}\r\n\treturn this;\r\n}\r\n\r\nif (typeof module != 'undefined' && module.exports) {\r\n module.exports = GraphemeSplitter;\r\n}\r\n", "'use strict';\n\nmodule.exports = earcut;\nmodule.exports.default = earcut;\n\nfunction earcut(data, holeIndices, dim) {\n\n dim = dim || 2;\n\n var hasHoles = holeIndices && holeIndices.length,\n outerLen = hasHoles ? holeIndices[0] * dim : data.length,\n outerNode = linkedList(data, 0, outerLen, dim, true),\n triangles = [];\n\n if (!outerNode || outerNode.next === outerNode.prev) return triangles;\n\n var minX, minY, maxX, maxY, x, y, invSize;\n\n if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);\n\n // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox\n if (data.length > 80 * dim) {\n minX = maxX = data[0];\n minY = maxY = data[1];\n\n for (var i = dim; i < outerLen; i += dim) {\n x = data[i];\n y = data[i + 1];\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n\n // minX, minY and invSize are later used to transform coords into integers for z-order calculation\n invSize = Math.max(maxX - minX, maxY - minY);\n invSize = invSize !== 0 ? 32767 / invSize : 0;\n }\n\n earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);\n\n return triangles;\n}\n\n// create a circular doubly linked list from polygon points in the specified winding order\nfunction linkedList(data, start, end, dim, clockwise) {\n var i, last;\n\n if (clockwise === (signedArea(data, start, end, dim) > 0)) {\n for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);\n } else {\n for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);\n }\n\n if (last && equals(last, last.next)) {\n removeNode(last);\n last = last.next;\n }\n\n return last;\n}\n\n// eliminate colinear or duplicate points\nfunction filterPoints(start, end) {\n if (!start) return start;\n if (!end) end = start;\n\n var p = start,\n again;\n do {\n again = false;\n\n if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {\n removeNode(p);\n p = end = p.prev;\n if (p === p.next) break;\n again = true;\n\n } else {\n p = p.next;\n }\n } while (again || p !== end);\n\n return end;\n}\n\n// main ear slicing loop which triangulates a polygon (given as a linked list)\nfunction earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {\n if (!ear) return;\n\n // interlink polygon nodes in z-order\n if (!pass && invSize) indexCurve(ear, minX, minY, invSize);\n\n var stop = ear,\n prev, next;\n\n // iterate through ears, slicing them one by one\n while (ear.prev !== ear.next) {\n prev = ear.prev;\n next = ear.next;\n\n if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {\n // cut off the triangle\n triangles.push(prev.i / dim | 0);\n triangles.push(ear.i / dim | 0);\n triangles.push(next.i / dim | 0);\n\n removeNode(ear);\n\n // skipping the next vertex leads to less sliver triangles\n ear = next.next;\n stop = next.next;\n\n continue;\n }\n\n ear = next;\n\n // if we looped through the whole remaining polygon and can't find any more ears\n if (ear === stop) {\n // try filtering points and slicing again\n if (!pass) {\n earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);\n\n // if this didn't work, try curing all small self-intersections locally\n } else if (pass === 1) {\n ear = cureLocalIntersections(filterPoints(ear), triangles, dim);\n earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);\n\n // as a last resort, try splitting the remaining polygon into two\n } else if (pass === 2) {\n splitEarcut(ear, triangles, dim, minX, minY, invSize);\n }\n\n break;\n }\n }\n}\n\n// check whether a polygon node forms a valid ear with adjacent nodes\nfunction isEar(ear) {\n var a = ear.prev,\n b = ear,\n c = ear.next;\n\n if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\n\n // now make sure we don't have other points inside the potential ear\n var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;\n\n // triangle bbox; min & max are calculated like this for speed\n var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx),\n y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy),\n x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx),\n y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);\n\n var p = c.next;\n while (p !== a) {\n if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&\n area(p.prev, p, p.next) >= 0) return false;\n p = p.next;\n }\n\n return true;\n}\n\nfunction isEarHashed(ear, minX, minY, invSize) {\n var a = ear.prev,\n b = ear,\n c = ear.next;\n\n if (area(a, b, c) >= 0) return false; // reflex, can't be an ear\n\n var ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;\n\n // triangle bbox; min & max are calculated like this for speed\n var x0 = ax < bx ? (ax < cx ? ax : cx) : (bx < cx ? bx : cx),\n y0 = ay < by ? (ay < cy ? ay : cy) : (by < cy ? by : cy),\n x1 = ax > bx ? (ax > cx ? ax : cx) : (bx > cx ? bx : cx),\n y1 = ay > by ? (ay > cy ? ay : cy) : (by > cy ? by : cy);\n\n // z-order range for the current triangle bbox;\n var minZ = zOrder(x0, y0, minX, minY, invSize),\n maxZ = zOrder(x1, y1, minX, minY, invSize);\n\n var p = ear.prevZ,\n n = ear.nextZ;\n\n // look for points inside the triangle in both directions\n while (p && p.z >= minZ && n && n.z <= maxZ) {\n if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;\n p = p.prevZ;\n\n if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;\n n = n.nextZ;\n }\n\n // look for remaining points in decreasing z-order\n while (p && p.z >= minZ) {\n if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;\n p = p.prevZ;\n }\n\n // look for remaining points in increasing z-order\n while (n && n.z <= maxZ) {\n if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&\n pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;\n n = n.nextZ;\n }\n\n return true;\n}\n\n// go through all polygon nodes and cure small local self-intersections\nfunction cureLocalIntersections(start, triangles, dim) {\n var p = start;\n do {\n var a = p.prev,\n b = p.next.next;\n\n if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {\n\n triangles.push(a.i / dim | 0);\n triangles.push(p.i / dim | 0);\n triangles.push(b.i / dim | 0);\n\n // remove two nodes involved\n removeNode(p);\n removeNode(p.next);\n\n p = start = b;\n }\n p = p.next;\n } while (p !== start);\n\n return filterPoints(p);\n}\n\n// try splitting polygon into two and triangulate them independently\nfunction splitEarcut(start, triangles, dim, minX, minY, invSize) {\n // look for a valid diagonal that divides the polygon into two\n var a = start;\n do {\n var b = a.next.next;\n while (b !== a.prev) {\n if (a.i !== b.i && isValidDiagonal(a, b)) {\n // split the polygon in two by the diagonal\n var c = splitPolygon(a, b);\n\n // filter colinear points around the cuts\n a = filterPoints(a, a.next);\n c = filterPoints(c, c.next);\n\n // run earcut on each half\n earcutLinked(a, triangles, dim, minX, minY, invSize, 0);\n earcutLinked(c, triangles, dim, minX, minY, invSize, 0);\n return;\n }\n b = b.next;\n }\n a = a.next;\n } while (a !== start);\n}\n\n// link every hole into the outer loop, producing a single-ring polygon without holes\nfunction eliminateHoles(data, holeIndices, outerNode, dim) {\n var queue = [],\n i, len, start, end, list;\n\n for (i = 0, len = holeIndices.length; i < len; i++) {\n start = holeIndices[i] * dim;\n end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n list = linkedList(data, start, end, dim, false);\n if (list === list.next) list.steiner = true;\n queue.push(getLeftmost(list));\n }\n\n queue.sort(compareX);\n\n // process holes from left to right\n for (i = 0; i < queue.length; i++) {\n outerNode = eliminateHole(queue[i], outerNode);\n }\n\n return outerNode;\n}\n\nfunction compareX(a, b) {\n return a.x - b.x;\n}\n\n// find a bridge between vertices that connects hole with an outer ring and and link it\nfunction eliminateHole(hole, outerNode) {\n var bridge = findHoleBridge(hole, outerNode);\n if (!bridge) {\n return outerNode;\n }\n\n var bridgeReverse = splitPolygon(bridge, hole);\n\n // filter collinear points around the cuts\n filterPoints(bridgeReverse, bridgeReverse.next);\n return filterPoints(bridge, bridge.next);\n}\n\n// David Eberly's algorithm for finding a bridge between hole and outer polygon\nfunction findHoleBridge(hole, outerNode) {\n var p = outerNode,\n hx = hole.x,\n hy = hole.y,\n qx = -Infinity,\n m;\n\n // find a segment intersected by a ray from the hole's leftmost point to the left;\n // segment's endpoint with lesser x will be potential connection point\n do {\n if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {\n var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);\n if (x <= hx && x > qx) {\n qx = x;\n m = p.x < p.next.x ? p : p.next;\n if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint\n }\n }\n p = p.next;\n } while (p !== outerNode);\n\n if (!m) return null;\n\n // look for points inside the triangle of hole point, segment intersection and endpoint;\n // if there are no points found, we have a valid connection;\n // otherwise choose the point of the minimum angle with the ray as connection point\n\n var stop = m,\n mx = m.x,\n my = m.y,\n tanMin = Infinity,\n tan;\n\n p = m;\n\n do {\n if (hx >= p.x && p.x >= mx && hx !== p.x &&\n pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {\n\n tan = Math.abs(hy - p.y) / (hx - p.x); // tangential\n\n if (locallyInside(p, hole) &&\n (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {\n m = p;\n tanMin = tan;\n }\n }\n\n p = p.next;\n } while (p !== stop);\n\n return m;\n}\n\n// whether sector in vertex m contains sector in vertex p in the same coordinates\nfunction sectorContainsSector(m, p) {\n return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;\n}\n\n// interlink polygon nodes in z-order\nfunction indexCurve(start, minX, minY, invSize) {\n var p = start;\n do {\n if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);\n p.prevZ = p.prev;\n p.nextZ = p.next;\n p = p.next;\n } while (p !== start);\n\n p.prevZ.nextZ = null;\n p.prevZ = null;\n\n sortLinked(p);\n}\n\n// Simon Tatham's linked list merge sort algorithm\n// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html\nfunction sortLinked(list) {\n var i, p, q, e, tail, numMerges, pSize, qSize,\n inSize = 1;\n\n do {\n p = list;\n list = null;\n tail = null;\n numMerges = 0;\n\n while (p) {\n numMerges++;\n q = p;\n pSize = 0;\n for (i = 0; i < inSize; i++) {\n pSize++;\n q = q.nextZ;\n if (!q) break;\n }\n qSize = inSize;\n\n while (pSize > 0 || (qSize > 0 && q)) {\n\n if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {\n e = p;\n p = p.nextZ;\n pSize--;\n } else {\n e = q;\n q = q.nextZ;\n qSize--;\n }\n\n if (tail) tail.nextZ = e;\n else list = e;\n\n e.prevZ = tail;\n tail = e;\n }\n\n p = q;\n }\n\n tail.nextZ = null;\n inSize *= 2;\n\n } while (numMerges > 1);\n\n return list;\n}\n\n// z-order of a point given coords and inverse of the longer side of data bbox\nfunction zOrder(x, y, minX, minY, invSize) {\n // coords are transformed into non-negative 15-bit integer range\n x = (x - minX) * invSize | 0;\n y = (y - minY) * invSize | 0;\n\n x = (x | (x << 8)) & 0x00FF00FF;\n x = (x | (x << 4)) & 0x0F0F0F0F;\n x = (x | (x << 2)) & 0x33333333;\n x = (x | (x << 1)) & 0x55555555;\n\n y = (y | (y << 8)) & 0x00FF00FF;\n y = (y | (y << 4)) & 0x0F0F0F0F;\n y = (y | (y << 2)) & 0x33333333;\n y = (y | (y << 1)) & 0x55555555;\n\n return x | (y << 1);\n}\n\n// find the leftmost node of a polygon ring\nfunction getLeftmost(start) {\n var p = start,\n leftmost = start;\n do {\n if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;\n p = p.next;\n } while (p !== start);\n\n return leftmost;\n}\n\n// check if a point lies within a convex triangle\nfunction pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {\n return (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&\n (ax - px) * (by - py) >= (bx - px) * (ay - py) &&\n (bx - px) * (cy - py) >= (cx - px) * (by - py);\n}\n\n// check if a diagonal between two polygon nodes is valid (lies in polygon interior)\nfunction isValidDiagonal(a, b) {\n return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges\n (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible\n (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors\n equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case\n}\n\n// signed area of a triangle\nfunction area(p, q, r) {\n return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);\n}\n\n// check if two points are equal\nfunction equals(p1, p2) {\n return p1.x === p2.x && p1.y === p2.y;\n}\n\n// check if two segments intersect\nfunction intersects(p1, q1, p2, q2) {\n var o1 = sign(area(p1, q1, p2));\n var o2 = sign(area(p1, q1, q2));\n var o3 = sign(area(p2, q2, p1));\n var o4 = sign(area(p2, q2, q1));\n\n if (o1 !== o2 && o3 !== o4) return true; // general case\n\n if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1\n if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1\n if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2\n if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2\n\n return false;\n}\n\n// for collinear points p, q, r, check if point q lies on segment pr\nfunction onSegment(p, q, r) {\n return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);\n}\n\nfunction sign(num) {\n return num > 0 ? 1 : num < 0 ? -1 : 0;\n}\n\n// check if a polygon diagonal intersects any polygon segments\nfunction intersectsPolygon(a, b) {\n var p = a;\n do {\n if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&\n intersects(p, p.next, a, b)) return true;\n p = p.next;\n } while (p !== a);\n\n return false;\n}\n\n// check if a polygon diagonal is locally inside the polygon\nfunction locallyInside(a, b) {\n return area(a.prev, a, a.next) < 0 ?\n area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :\n area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;\n}\n\n// check if the middle point of a polygon diagonal is inside the polygon\nfunction middleInside(a, b) {\n var p = a,\n inside = false,\n px = (a.x + b.x) / 2,\n py = (a.y + b.y) / 2;\n do {\n if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&\n (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))\n inside = !inside;\n p = p.next;\n } while (p !== a);\n\n return inside;\n}\n\n// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;\n// if one belongs to the outer ring and another to a hole, it merges it into a single ring\nfunction splitPolygon(a, b) {\n var a2 = new Node(a.i, a.x, a.y),\n b2 = new Node(b.i, b.x, b.y),\n an = a.next,\n bp = b.prev;\n\n a.next = b;\n b.prev = a;\n\n a2.next = an;\n an.prev = a2;\n\n b2.next = a2;\n a2.prev = b2;\n\n bp.next = b2;\n b2.prev = bp;\n\n return b2;\n}\n\n// create a node and optionally link it with previous one (in a circular doubly linked list)\nfunction insertNode(i, x, y, last) {\n var p = new Node(i, x, y);\n\n if (!last) {\n p.prev = p;\n p.next = p;\n\n } else {\n p.next = last.next;\n p.prev = last;\n last.next.prev = p;\n last.next = p;\n }\n return p;\n}\n\nfunction removeNode(p) {\n p.next.prev = p.prev;\n p.prev.next = p.next;\n\n if (p.prevZ) p.prevZ.nextZ = p.nextZ;\n if (p.nextZ) p.nextZ.prevZ = p.prevZ;\n}\n\nfunction Node(i, x, y) {\n // vertex index in coordinates array\n this.i = i;\n\n // vertex coordinates\n this.x = x;\n this.y = y;\n\n // previous and next vertex nodes in a polygon ring\n this.prev = null;\n this.next = null;\n\n // z-order curve value\n this.z = 0;\n\n // previous and next nodes in z-order\n this.prevZ = null;\n this.nextZ = null;\n\n // indicates whether this is a steiner point\n this.steiner = false;\n}\n\n// return a percentage difference between the polygon area and its triangulation area;\n// used to verify correctness of triangulation\nearcut.deviation = function (data, holeIndices, dim, triangles) {\n var hasHoles = holeIndices && holeIndices.length;\n var outerLen = hasHoles ? holeIndices[0] * dim : data.length;\n\n var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));\n if (hasHoles) {\n for (var i = 0, len = holeIndices.length; i < len; i++) {\n var start = holeIndices[i] * dim;\n var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;\n polygonArea -= Math.abs(signedArea(data, start, end, dim));\n }\n }\n\n var trianglesArea = 0;\n for (i = 0; i < triangles.length; i += 3) {\n var a = triangles[i] * dim;\n var b = triangles[i + 1] * dim;\n var c = triangles[i + 2] * dim;\n trianglesArea += Math.abs(\n (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -\n (data[a] - data[b]) * (data[c + 1] - data[a + 1]));\n }\n\n return polygonArea === 0 && trianglesArea === 0 ? 0 :\n Math.abs((trianglesArea - polygonArea) / polygonArea);\n};\n\nfunction signedArea(data, start, end, dim) {\n var sum = 0;\n for (var i = start, j = end - dim; i < end; i += dim) {\n sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);\n j = i;\n }\n return sum;\n}\n\n// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts\nearcut.flatten = function (data) {\n var dim = data[0][0].length,\n result = {vertices: [], holes: [], dimensions: dim},\n holeIndex = 0;\n\n for (var i = 0; i < data.length; i++) {\n for (var j = 0; j < data[i].length; j++) {\n for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);\n }\n if (i > 0) {\n holeIndex += data[i - 1].length;\n result.holes.push(holeIndex);\n }\n }\n return result;\n};\n", "!function(t,i){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=i():\"function\"==typeof define&&define.amd?define(i):(t=t||self).RBush=i()}(this,function(){\"use strict\";function t(t,r,e,a,h){!function t(n,r,e,a,h){for(;a>e;){if(a-e>600){var o=a-e+1,s=r-e+1,l=Math.log(o),f=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*f*(o-f)/o)*(s-o/2<0?-1:1),m=Math.max(e,Math.floor(r-s*f/o+u)),c=Math.min(a,Math.floor(r+(o-s)*f/o+u));t(n,r,m,c,h)}var p=n[r],d=e,x=a;for(i(n,e,r),h(n[a],p)>0&&i(n,e,a);d0;)x--}0===h(n[e],p)?i(n,e,x):i(n,++x,a),x<=r&&(e=x+1),r<=x&&(a=x-1)}}(t,r,e||0,a||t.length-1,h||n)}function i(t,i,n){var r=t[i];t[i]=t[n],t[n]=r}function n(t,i){return ti?1:0}var r=function(t){void 0===t&&(t=9),this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function e(t,i,n){if(!n)return i.indexOf(t);for(var r=0;r=t.minX&&i.maxY>=t.minY}function p(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function d(i,n,r,e,a){for(var h=[n,r];h.length;)if(!((r=h.pop())-(n=h.pop())<=e)){var o=n+Math.ceil((r-n)/e/2)*e;t(i,o,n,r,a),h.push(n,o,o,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(t){var i=this.data,n=[];if(!c(t,i))return n;for(var r=this.toBBox,e=[];i;){for(var a=0;a=0&&e[i].children.length>this._maxEntries;)this._split(e,i),i--;this._adjustParentBBoxes(r,e,i)},r.prototype._split=function(t,i){var n=t[i],r=n.children.length,e=this._minEntries;this._chooseSplitAxis(n,e,r);var h=this._chooseSplitIndex(n,e,r),o=p(n.children.splice(h,n.children.length-h));o.height=n.height,o.leaf=n.leaf,a(n,this.toBBox),a(o,this.toBBox),i?t[i-1].children.push(o):this._splitRoot(n,o)},r.prototype._splitRoot=function(t,i){this.data=p([t,i]),this.data.height=t.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(t,i,n){for(var r,e,a,o,s,l,u,m=1/0,c=1/0,p=i;p<=n-i;p++){var d=h(t,0,p,this.toBBox),x=h(t,p,n,this.toBBox),v=(e=d,a=x,o=void 0,s=void 0,l=void 0,u=void 0,o=Math.max(e.minX,a.minX),s=Math.max(e.minY,a.minY),l=Math.min(e.maxX,a.maxX),u=Math.min(e.maxY,a.maxY),Math.max(0,l-o)*Math.max(0,u-s)),M=f(d)+f(x);v=i;c--){var p=t.children[c];o(s,t.leaf?e(p):p),l+=u(s)}return l},r.prototype._adjustParentBBoxes=function(t,i,n){for(var r=n;r>=0;r--)o(i[r],t)},r.prototype._condense=function(t){for(var i=t.length-1,n=void 0;i>=0;i--)0===t[i].children.length?i>0?(n=t[i-1].children).splice(n.indexOf(t[i]),1):this.clear():a(t[i],this.toBBox)},r});\n", "(function prelude(modules, cache, entries) {\n\n // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS\n // sources through a conflict-free require shim and is again wrapped within an iife that\n // provides a minification-friendly `undefined` var plus a global \"use strict\" directive\n // so that minification can remove the directives of each module.\n\n function $require(name) {\n var $module = cache[name];\n if (!$module)\n modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);\n return $module.exports;\n }\n\n var protobuf = $require(entries[0]);\n\n // Expose globally\n protobuf.util.global.protobuf = protobuf;\n\n // Be nice to AMD\n if (typeof define === \"function\" && define.amd)\n define([\"long\"], function(Long) {\n if (Long && Long.isLong) {\n protobuf.util.Long = Long;\n protobuf.configure();\n }\n return protobuf;\n });\n\n // Be nice to CommonJS\n if (typeof module === \"object\" && module && module.exports)\n module.exports = protobuf;\n\n})/* end of prelude */", "\"use strict\";\r\nmodule.exports = asPromise;\r\n\r\n/**\r\n * Callback as used by {@link util.asPromise}.\r\n * @typedef asPromiseCallback\r\n * @type {function}\r\n * @param {Error|null} error Error, if any\r\n * @param {...*} params Additional arguments\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Returns a promise from a node-style callback function.\r\n * @memberof util\r\n * @param {asPromiseCallback} fn Function to call\r\n * @param {*} ctx Function context\r\n * @param {...*} params Function arguments\r\n * @returns {Promise<*>} Promisified function\r\n */\r\nfunction asPromise(fn, ctx/*, varargs */) {\r\n var params = new Array(arguments.length - 1),\r\n offset = 0,\r\n index = 2,\r\n pending = true;\r\n while (index < arguments.length)\r\n params[offset++] = arguments[index++];\r\n return new Promise(function executor(resolve, reject) {\r\n params[offset] = function callback(err/*, varargs */) {\r\n if (pending) {\r\n pending = false;\r\n if (err)\r\n reject(err);\r\n else {\r\n var params = new Array(arguments.length - 1),\r\n offset = 0;\r\n while (offset < params.length)\r\n params[offset++] = arguments[offset];\r\n resolve.apply(null, params);\r\n }\r\n }\r\n };\r\n try {\r\n fn.apply(ctx || null, params);\r\n } catch (err) {\r\n if (pending) {\r\n pending = false;\r\n reject(err);\r\n }\r\n }\r\n });\r\n}\r\n", "\"use strict\";\r\n\r\n/**\r\n * A minimal base64 implementation for number arrays.\r\n * @memberof util\r\n * @namespace\r\n */\r\nvar base64 = exports;\r\n\r\n/**\r\n * Calculates the byte length of a base64 encoded string.\r\n * @param {string} string Base64 encoded string\r\n * @returns {number} Byte length\r\n */\r\nbase64.length = function length(string) {\r\n var p = string.length;\r\n if (!p)\r\n return 0;\r\n var n = 0;\r\n while (--p % 4 > 1 && string.charAt(p) === \"=\")\r\n ++n;\r\n return Math.ceil(string.length * 3) / 4 - n;\r\n};\r\n\r\n// Base64 encoding table\r\nvar b64 = new Array(64);\r\n\r\n// Base64 decoding table\r\nvar s64 = new Array(123);\r\n\r\n// 65..90, 97..122, 48..57, 43, 47\r\nfor (var i = 0; i < 64;)\r\n s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;\r\n\r\n/**\r\n * Encodes a buffer to a base64 encoded string.\r\n * @param {Uint8Array} buffer Source buffer\r\n * @param {number} start Source start\r\n * @param {number} end Source end\r\n * @returns {string} Base64 encoded string\r\n */\r\nbase64.encode = function encode(buffer, start, end) {\r\n var parts = null,\r\n chunk = [];\r\n var i = 0, // output index\r\n j = 0, // goto index\r\n t; // temporary\r\n while (start < end) {\r\n var b = buffer[start++];\r\n switch (j) {\r\n case 0:\r\n chunk[i++] = b64[b >> 2];\r\n t = (b & 3) << 4;\r\n j = 1;\r\n break;\r\n case 1:\r\n chunk[i++] = b64[t | b >> 4];\r\n t = (b & 15) << 2;\r\n j = 2;\r\n break;\r\n case 2:\r\n chunk[i++] = b64[t | b >> 6];\r\n chunk[i++] = b64[b & 63];\r\n j = 0;\r\n break;\r\n }\r\n if (i > 8191) {\r\n (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));\r\n i = 0;\r\n }\r\n }\r\n if (j) {\r\n chunk[i++] = b64[t];\r\n chunk[i++] = 61;\r\n if (j === 1)\r\n chunk[i++] = 61;\r\n }\r\n if (parts) {\r\n if (i)\r\n parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));\r\n return parts.join(\"\");\r\n }\r\n return String.fromCharCode.apply(String, chunk.slice(0, i));\r\n};\r\n\r\nvar invalidEncoding = \"invalid encoding\";\r\n\r\n/**\r\n * Decodes a base64 encoded string to a buffer.\r\n * @param {string} string Source string\r\n * @param {Uint8Array} buffer Destination buffer\r\n * @param {number} offset Destination offset\r\n * @returns {number} Number of bytes written\r\n * @throws {Error} If encoding is invalid\r\n */\r\nbase64.decode = function decode(string, buffer, offset) {\r\n var start = offset;\r\n var j = 0, // goto index\r\n t; // temporary\r\n for (var i = 0; i < string.length;) {\r\n var c = string.charCodeAt(i++);\r\n if (c === 61 && j > 1)\r\n break;\r\n if ((c = s64[c]) === undefined)\r\n throw Error(invalidEncoding);\r\n switch (j) {\r\n case 0:\r\n t = c;\r\n j = 1;\r\n break;\r\n case 1:\r\n buffer[offset++] = t << 2 | (c & 48) >> 4;\r\n t = c;\r\n j = 2;\r\n break;\r\n case 2:\r\n buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;\r\n t = c;\r\n j = 3;\r\n break;\r\n case 3:\r\n buffer[offset++] = (t & 3) << 6 | c;\r\n j = 0;\r\n break;\r\n }\r\n }\r\n if (j === 1)\r\n throw Error(invalidEncoding);\r\n return offset - start;\r\n};\r\n\r\n/**\r\n * Tests if the specified string appears to be base64 encoded.\r\n * @param {string} string String to test\r\n * @returns {boolean} `true` if probably base64 encoded, otherwise false\r\n */\r\nbase64.test = function test(string) {\r\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);\r\n};\r\n", "\"use strict\";\r\nmodule.exports = EventEmitter;\r\n\r\n/**\r\n * Constructs a new event emitter instance.\r\n * @classdesc A minimal event emitter.\r\n * @memberof util\r\n * @constructor\r\n */\r\nfunction EventEmitter() {\r\n\r\n /**\r\n * Registered listeners.\r\n * @type {Object.}\r\n * @private\r\n */\r\n this._listeners = {};\r\n}\r\n\r\n/**\r\n * Registers an event listener.\r\n * @param {string} evt Event name\r\n * @param {function} fn Listener\r\n * @param {*} [ctx] Listener context\r\n * @returns {util.EventEmitter} `this`\r\n */\r\nEventEmitter.prototype.on = function on(evt, fn, ctx) {\r\n (this._listeners[evt] || (this._listeners[evt] = [])).push({\r\n fn : fn,\r\n ctx : ctx || this\r\n });\r\n return this;\r\n};\r\n\r\n/**\r\n * Removes an event listener or any matching listeners if arguments are omitted.\r\n * @param {string} [evt] Event name. Removes all listeners if omitted.\r\n * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.\r\n * @returns {util.EventEmitter} `this`\r\n */\r\nEventEmitter.prototype.off = function off(evt, fn) {\r\n if (evt === undefined)\r\n this._listeners = {};\r\n else {\r\n if (fn === undefined)\r\n this._listeners[evt] = [];\r\n else {\r\n var listeners = this._listeners[evt];\r\n for (var i = 0; i < listeners.length;)\r\n if (listeners[i].fn === fn)\r\n listeners.splice(i, 1);\r\n else\r\n ++i;\r\n }\r\n }\r\n return this;\r\n};\r\n\r\n/**\r\n * Emits an event by calling its listeners with the specified arguments.\r\n * @param {string} evt Event name\r\n * @param {...*} args Arguments\r\n * @returns {util.EventEmitter} `this`\r\n */\r\nEventEmitter.prototype.emit = function emit(evt) {\r\n var listeners = this._listeners[evt];\r\n if (listeners) {\r\n var args = [],\r\n i = 1;\r\n for (; i < arguments.length;)\r\n args.push(arguments[i++]);\r\n for (i = 0; i < listeners.length;)\r\n listeners[i].fn.apply(listeners[i++].ctx, args);\r\n }\r\n return this;\r\n};\r\n", "\"use strict\";\r\n\r\nmodule.exports = factory(factory);\r\n\r\n/**\r\n * Reads / writes floats / doubles from / to buffers.\r\n * @name util.float\r\n * @namespace\r\n */\r\n\r\n/**\r\n * Writes a 32 bit float to a buffer using little endian byte order.\r\n * @name util.float.writeFloatLE\r\n * @function\r\n * @param {number} val Value to write\r\n * @param {Uint8Array} buf Target buffer\r\n * @param {number} pos Target buffer offset\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Writes a 32 bit float to a buffer using big endian byte order.\r\n * @name util.float.writeFloatBE\r\n * @function\r\n * @param {number} val Value to write\r\n * @param {Uint8Array} buf Target buffer\r\n * @param {number} pos Target buffer offset\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Reads a 32 bit float from a buffer using little endian byte order.\r\n * @name util.float.readFloatLE\r\n * @function\r\n * @param {Uint8Array} buf Source buffer\r\n * @param {number} pos Source buffer offset\r\n * @returns {number} Value read\r\n */\r\n\r\n/**\r\n * Reads a 32 bit float from a buffer using big endian byte order.\r\n * @name util.float.readFloatBE\r\n * @function\r\n * @param {Uint8Array} buf Source buffer\r\n * @param {number} pos Source buffer offset\r\n * @returns {number} Value read\r\n */\r\n\r\n/**\r\n * Writes a 64 bit double to a buffer using little endian byte order.\r\n * @name util.float.writeDoubleLE\r\n * @function\r\n * @param {number} val Value to write\r\n * @param {Uint8Array} buf Target buffer\r\n * @param {number} pos Target buffer offset\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Writes a 64 bit double to a buffer using big endian byte order.\r\n * @name util.float.writeDoubleBE\r\n * @function\r\n * @param {number} val Value to write\r\n * @param {Uint8Array} buf Target buffer\r\n * @param {number} pos Target buffer offset\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Reads a 64 bit double from a buffer using little endian byte order.\r\n * @name util.float.readDoubleLE\r\n * @function\r\n * @param {Uint8Array} buf Source buffer\r\n * @param {number} pos Source buffer offset\r\n * @returns {number} Value read\r\n */\r\n\r\n/**\r\n * Reads a 64 bit double from a buffer using big endian byte order.\r\n * @name util.float.readDoubleBE\r\n * @function\r\n * @param {Uint8Array} buf Source buffer\r\n * @param {number} pos Source buffer offset\r\n * @returns {number} Value read\r\n */\r\n\r\n// Factory function for the purpose of node-based testing in modified global environments\r\nfunction factory(exports) {\r\n\r\n // float: typed array\r\n if (typeof Float32Array !== \"undefined\") (function() {\r\n\r\n var f32 = new Float32Array([ -0 ]),\r\n f8b = new Uint8Array(f32.buffer),\r\n le = f8b[3] === 128;\r\n\r\n function writeFloat_f32_cpy(val, buf, pos) {\r\n f32[0] = val;\r\n buf[pos ] = f8b[0];\r\n buf[pos + 1] = f8b[1];\r\n buf[pos + 2] = f8b[2];\r\n buf[pos + 3] = f8b[3];\r\n }\r\n\r\n function writeFloat_f32_rev(val, buf, pos) {\r\n f32[0] = val;\r\n buf[pos ] = f8b[3];\r\n buf[pos + 1] = f8b[2];\r\n buf[pos + 2] = f8b[1];\r\n buf[pos + 3] = f8b[0];\r\n }\r\n\r\n /* istanbul ignore next */\r\n exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;\r\n /* istanbul ignore next */\r\n exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;\r\n\r\n function readFloat_f32_cpy(buf, pos) {\r\n f8b[0] = buf[pos ];\r\n f8b[1] = buf[pos + 1];\r\n f8b[2] = buf[pos + 2];\r\n f8b[3] = buf[pos + 3];\r\n return f32[0];\r\n }\r\n\r\n function readFloat_f32_rev(buf, pos) {\r\n f8b[3] = buf[pos ];\r\n f8b[2] = buf[pos + 1];\r\n f8b[1] = buf[pos + 2];\r\n f8b[0] = buf[pos + 3];\r\n return f32[0];\r\n }\r\n\r\n /* istanbul ignore next */\r\n exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;\r\n /* istanbul ignore next */\r\n exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;\r\n\r\n // float: ieee754\r\n })(); else (function() {\r\n\r\n function writeFloat_ieee754(writeUint, val, buf, pos) {\r\n var sign = val < 0 ? 1 : 0;\r\n if (sign)\r\n val = -val;\r\n if (val === 0)\r\n writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);\r\n else if (isNaN(val))\r\n writeUint(2143289344, buf, pos);\r\n else if (val > 3.4028234663852886e+38) // +-Infinity\r\n writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);\r\n else if (val < 1.1754943508222875e-38) // denormal\r\n writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);\r\n else {\r\n var exponent = Math.floor(Math.log(val) / Math.LN2),\r\n mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;\r\n writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);\r\n }\r\n }\r\n\r\n exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);\r\n exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);\r\n\r\n function readFloat_ieee754(readUint, buf, pos) {\r\n var uint = readUint(buf, pos),\r\n sign = (uint >> 31) * 2 + 1,\r\n exponent = uint >>> 23 & 255,\r\n mantissa = uint & 8388607;\r\n return exponent === 255\r\n ? mantissa\r\n ? NaN\r\n : sign * Infinity\r\n : exponent === 0 // denormal\r\n ? sign * 1.401298464324817e-45 * mantissa\r\n : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);\r\n }\r\n\r\n exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);\r\n exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);\r\n\r\n })();\r\n\r\n // double: typed array\r\n if (typeof Float64Array !== \"undefined\") (function() {\r\n\r\n var f64 = new Float64Array([-0]),\r\n f8b = new Uint8Array(f64.buffer),\r\n le = f8b[7] === 128;\r\n\r\n function writeDouble_f64_cpy(val, buf, pos) {\r\n f64[0] = val;\r\n buf[pos ] = f8b[0];\r\n buf[pos + 1] = f8b[1];\r\n buf[pos + 2] = f8b[2];\r\n buf[pos + 3] = f8b[3];\r\n buf[pos + 4] = f8b[4];\r\n buf[pos + 5] = f8b[5];\r\n buf[pos + 6] = f8b[6];\r\n buf[pos + 7] = f8b[7];\r\n }\r\n\r\n function writeDouble_f64_rev(val, buf, pos) {\r\n f64[0] = val;\r\n buf[pos ] = f8b[7];\r\n buf[pos + 1] = f8b[6];\r\n buf[pos + 2] = f8b[5];\r\n buf[pos + 3] = f8b[4];\r\n buf[pos + 4] = f8b[3];\r\n buf[pos + 5] = f8b[2];\r\n buf[pos + 6] = f8b[1];\r\n buf[pos + 7] = f8b[0];\r\n }\r\n\r\n /* istanbul ignore next */\r\n exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;\r\n /* istanbul ignore next */\r\n exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;\r\n\r\n function readDouble_f64_cpy(buf, pos) {\r\n f8b[0] = buf[pos ];\r\n f8b[1] = buf[pos + 1];\r\n f8b[2] = buf[pos + 2];\r\n f8b[3] = buf[pos + 3];\r\n f8b[4] = buf[pos + 4];\r\n f8b[5] = buf[pos + 5];\r\n f8b[6] = buf[pos + 6];\r\n f8b[7] = buf[pos + 7];\r\n return f64[0];\r\n }\r\n\r\n function readDouble_f64_rev(buf, pos) {\r\n f8b[7] = buf[pos ];\r\n f8b[6] = buf[pos + 1];\r\n f8b[5] = buf[pos + 2];\r\n f8b[4] = buf[pos + 3];\r\n f8b[3] = buf[pos + 4];\r\n f8b[2] = buf[pos + 5];\r\n f8b[1] = buf[pos + 6];\r\n f8b[0] = buf[pos + 7];\r\n return f64[0];\r\n }\r\n\r\n /* istanbul ignore next */\r\n exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;\r\n /* istanbul ignore next */\r\n exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;\r\n\r\n // double: ieee754\r\n })(); else (function() {\r\n\r\n function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {\r\n var sign = val < 0 ? 1 : 0;\r\n if (sign)\r\n val = -val;\r\n if (val === 0) {\r\n writeUint(0, buf, pos + off0);\r\n writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);\r\n } else if (isNaN(val)) {\r\n writeUint(0, buf, pos + off0);\r\n writeUint(2146959360, buf, pos + off1);\r\n } else if (val > 1.7976931348623157e+308) { // +-Infinity\r\n writeUint(0, buf, pos + off0);\r\n writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);\r\n } else {\r\n var mantissa;\r\n if (val < 2.2250738585072014e-308) { // denormal\r\n mantissa = val / 5e-324;\r\n writeUint(mantissa >>> 0, buf, pos + off0);\r\n writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);\r\n } else {\r\n var exponent = Math.floor(Math.log(val) / Math.LN2);\r\n if (exponent === 1024)\r\n exponent = 1023;\r\n mantissa = val * Math.pow(2, -exponent);\r\n writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);\r\n writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);\r\n }\r\n }\r\n }\r\n\r\n exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);\r\n exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);\r\n\r\n function readDouble_ieee754(readUint, off0, off1, buf, pos) {\r\n var lo = readUint(buf, pos + off0),\r\n hi = readUint(buf, pos + off1);\r\n var sign = (hi >> 31) * 2 + 1,\r\n exponent = hi >>> 20 & 2047,\r\n mantissa = 4294967296 * (hi & 1048575) + lo;\r\n return exponent === 2047\r\n ? mantissa\r\n ? NaN\r\n : sign * Infinity\r\n : exponent === 0 // denormal\r\n ? sign * 5e-324 * mantissa\r\n : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);\r\n }\r\n\r\n exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);\r\n exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);\r\n\r\n })();\r\n\r\n return exports;\r\n}\r\n\r\n// uint helpers\r\n\r\nfunction writeUintLE(val, buf, pos) {\r\n buf[pos ] = val & 255;\r\n buf[pos + 1] = val >>> 8 & 255;\r\n buf[pos + 2] = val >>> 16 & 255;\r\n buf[pos + 3] = val >>> 24;\r\n}\r\n\r\nfunction writeUintBE(val, buf, pos) {\r\n buf[pos ] = val >>> 24;\r\n buf[pos + 1] = val >>> 16 & 255;\r\n buf[pos + 2] = val >>> 8 & 255;\r\n buf[pos + 3] = val & 255;\r\n}\r\n\r\nfunction readUintLE(buf, pos) {\r\n return (buf[pos ]\r\n | buf[pos + 1] << 8\r\n | buf[pos + 2] << 16\r\n | buf[pos + 3] << 24) >>> 0;\r\n}\r\n\r\nfunction readUintBE(buf, pos) {\r\n return (buf[pos ] << 24\r\n | buf[pos + 1] << 16\r\n | buf[pos + 2] << 8\r\n | buf[pos + 3]) >>> 0;\r\n}\r\n", "\"use strict\";\r\nmodule.exports = inquire;\r\n\r\n/**\r\n * Requires a module only if available.\r\n * @memberof util\r\n * @param {string} moduleName Module to require\r\n * @returns {?Object} Required module if available and not empty, otherwise `null`\r\n */\r\nfunction inquire(moduleName) {\r\n try {\r\n var mod = eval(\"quire\".replace(/^/,\"re\"))(moduleName); // eslint-disable-line no-eval\r\n if (mod && (mod.length || Object.keys(mod).length))\r\n return mod;\r\n } catch (e) {} // eslint-disable-line no-empty\r\n return null;\r\n}\r\n", "\"use strict\";\r\nmodule.exports = pool;\r\n\r\n/**\r\n * An allocator as used by {@link util.pool}.\r\n * @typedef PoolAllocator\r\n * @type {function}\r\n * @param {number} size Buffer size\r\n * @returns {Uint8Array} Buffer\r\n */\r\n\r\n/**\r\n * A slicer as used by {@link util.pool}.\r\n * @typedef PoolSlicer\r\n * @type {function}\r\n * @param {number} start Start offset\r\n * @param {number} end End offset\r\n * @returns {Uint8Array} Buffer slice\r\n * @this {Uint8Array}\r\n */\r\n\r\n/**\r\n * A general purpose buffer pool.\r\n * @memberof util\r\n * @function\r\n * @param {PoolAllocator} alloc Allocator\r\n * @param {PoolSlicer} slice Slicer\r\n * @param {number} [size=8192] Slab size\r\n * @returns {PoolAllocator} Pooled allocator\r\n */\r\nfunction pool(alloc, slice, size) {\r\n var SIZE = size || 8192;\r\n var MAX = SIZE >>> 1;\r\n var slab = null;\r\n var offset = SIZE;\r\n return function pool_alloc(size) {\r\n if (size < 1 || size > MAX)\r\n return alloc(size);\r\n if (offset + size > SIZE) {\r\n slab = alloc(SIZE);\r\n offset = 0;\r\n }\r\n var buf = slice.call(slab, offset, offset += size);\r\n if (offset & 7) // align to 32 bit\r\n offset = (offset | 7) + 1;\r\n return buf;\r\n };\r\n}\r\n", "\"use strict\";\r\n\r\n/**\r\n * A minimal UTF8 implementation for number arrays.\r\n * @memberof util\r\n * @namespace\r\n */\r\nvar utf8 = exports;\r\n\r\n/**\r\n * Calculates the UTF8 byte length of a string.\r\n * @param {string} string String\r\n * @returns {number} Byte length\r\n */\r\nutf8.length = function utf8_length(string) {\r\n var len = 0,\r\n c = 0;\r\n for (var i = 0; i < string.length; ++i) {\r\n c = string.charCodeAt(i);\r\n if (c < 128)\r\n len += 1;\r\n else if (c < 2048)\r\n len += 2;\r\n else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {\r\n ++i;\r\n len += 4;\r\n } else\r\n len += 3;\r\n }\r\n return len;\r\n};\r\n\r\n/**\r\n * Reads UTF8 bytes as a string.\r\n * @param {Uint8Array} buffer Source buffer\r\n * @param {number} start Source start\r\n * @param {number} end Source end\r\n * @returns {string} String read\r\n */\r\nutf8.read = function utf8_read(buffer, start, end) {\r\n var len = end - start;\r\n if (len < 1)\r\n return \"\";\r\n var parts = null,\r\n chunk = [],\r\n i = 0, // char offset\r\n t; // temporary\r\n while (start < end) {\r\n t = buffer[start++];\r\n if (t < 128)\r\n chunk[i++] = t;\r\n else if (t > 191 && t < 224)\r\n chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;\r\n else if (t > 239 && t < 365) {\r\n t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;\r\n chunk[i++] = 0xD800 + (t >> 10);\r\n chunk[i++] = 0xDC00 + (t & 1023);\r\n } else\r\n chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;\r\n if (i > 8191) {\r\n (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));\r\n i = 0;\r\n }\r\n }\r\n if (parts) {\r\n if (i)\r\n parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));\r\n return parts.join(\"\");\r\n }\r\n return String.fromCharCode.apply(String, chunk.slice(0, i));\r\n};\r\n\r\n/**\r\n * Writes a string as UTF8 bytes.\r\n * @param {string} string Source string\r\n * @param {Uint8Array} buffer Destination buffer\r\n * @param {number} offset Destination offset\r\n * @returns {number} Bytes written\r\n */\r\nutf8.write = function utf8_write(string, buffer, offset) {\r\n var start = offset,\r\n c1, // character 1\r\n c2; // character 2\r\n for (var i = 0; i < string.length; ++i) {\r\n c1 = string.charCodeAt(i);\r\n if (c1 < 128) {\r\n buffer[offset++] = c1;\r\n } else if (c1 < 2048) {\r\n buffer[offset++] = c1 >> 6 | 192;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {\r\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);\r\n ++i;\r\n buffer[offset++] = c1 >> 18 | 240;\r\n buffer[offset++] = c1 >> 12 & 63 | 128;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else {\r\n buffer[offset++] = c1 >> 12 | 224;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n }\r\n }\r\n return offset - start;\r\n};\r\n", "\"use strict\";\nvar protobuf = exports;\n\n/**\n * Build type, one of `\"full\"`, `\"light\"` or `\"minimal\"`.\n * @name build\n * @type {string}\n * @const\n */\nprotobuf.build = \"minimal\";\n\n// Serialization\nprotobuf.Writer = require(16);\nprotobuf.BufferWriter = require(17);\nprotobuf.Reader = require(9);\nprotobuf.BufferReader = require(10);\n\n// Utility\nprotobuf.util = require(15);\nprotobuf.rpc = require(12);\nprotobuf.roots = require(11);\nprotobuf.configure = configure;\n\n/* istanbul ignore next */\n/**\n * Reconfigures the library according to the environment.\n * @returns {undefined}\n */\nfunction configure() {\n protobuf.util._configure();\n protobuf.Writer._configure(protobuf.BufferWriter);\n protobuf.Reader._configure(protobuf.BufferReader);\n}\n\n// Set up buffer utility according to the environment\nconfigure();\n", "\"use strict\";\nmodule.exports = Reader;\n\nvar util = require(15);\n\nvar BufferReader; // cyclic\n\nvar LongBits = util.LongBits,\n utf8 = util.utf8;\n\n/* istanbul ignore next */\nfunction indexOutOfRange(reader, writeLength) {\n return RangeError(\"index out of range: \" + reader.pos + \" + \" + (writeLength || 1) + \" > \" + reader.len);\n}\n\n/**\n * Constructs a new reader instance using the specified buffer.\n * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.\n * @constructor\n * @param {Uint8Array} buffer Buffer to read from\n */\nfunction Reader(buffer) {\n\n /**\n * Read buffer.\n * @type {Uint8Array}\n */\n this.buf = buffer;\n\n /**\n * Read buffer position.\n * @type {number}\n */\n this.pos = 0;\n\n /**\n * Read buffer length.\n * @type {number}\n */\n this.len = buffer.length;\n}\n\nvar create_array = typeof Uint8Array !== \"undefined\"\n ? function create_typed_array(buffer) {\n if (buffer instanceof Uint8Array || Array.isArray(buffer))\n return new Reader(buffer);\n throw Error(\"illegal buffer\");\n }\n /* istanbul ignore next */\n : function create_array(buffer) {\n if (Array.isArray(buffer))\n return new Reader(buffer);\n throw Error(\"illegal buffer\");\n };\n\nvar create = function create() {\n return util.Buffer\n ? function create_buffer_setup(buffer) {\n return (Reader.create = function create_buffer(buffer) {\n return util.Buffer.isBuffer(buffer)\n ? new BufferReader(buffer)\n /* istanbul ignore next */\n : create_array(buffer);\n })(buffer);\n }\n /* istanbul ignore next */\n : create_array;\n};\n\n/**\n * Creates a new reader using the specified buffer.\n * @function\n * @param {Uint8Array|Buffer} buffer Buffer to read from\n * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}\n * @throws {Error} If `buffer` is not a valid buffer\n */\nReader.create = create();\n\nReader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;\n\n/**\n * Reads a varint as an unsigned 32 bit value.\n * @function\n * @returns {number} Value read\n */\nReader.prototype.uint32 = (function read_uint32_setup() {\n var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)\n return function read_uint32() {\n value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;\n value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;\n value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;\n value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;\n value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;\n\n /* istanbul ignore if */\n if ((this.pos += 5) > this.len) {\n this.pos = this.len;\n throw indexOutOfRange(this, 10);\n }\n return value;\n };\n})();\n\n/**\n * Reads a varint as a signed 32 bit value.\n * @returns {number} Value read\n */\nReader.prototype.int32 = function read_int32() {\n return this.uint32() | 0;\n};\n\n/**\n * Reads a zig-zag encoded varint as a signed 32 bit value.\n * @returns {number} Value read\n */\nReader.prototype.sint32 = function read_sint32() {\n var value = this.uint32();\n return value >>> 1 ^ -(value & 1) | 0;\n};\n\n/* eslint-disable no-invalid-this */\n\nfunction readLongVarint() {\n // tends to deopt with local vars for octet etc.\n var bits = new LongBits(0, 0);\n var i = 0;\n if (this.len - this.pos > 4) { // fast route (lo)\n for (; i < 4; ++i) {\n // 1st..4th\n bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;\n if (this.buf[this.pos++] < 128)\n return bits;\n }\n // 5th\n bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;\n bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;\n if (this.buf[this.pos++] < 128)\n return bits;\n i = 0;\n } else {\n for (; i < 3; ++i) {\n /* istanbul ignore if */\n if (this.pos >= this.len)\n throw indexOutOfRange(this);\n // 1st..3th\n bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;\n if (this.buf[this.pos++] < 128)\n return bits;\n }\n // 4th\n bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;\n return bits;\n }\n if (this.len - this.pos > 4) { // fast route (hi)\n for (; i < 5; ++i) {\n // 6th..10th\n bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;\n if (this.buf[this.pos++] < 128)\n return bits;\n }\n } else {\n for (; i < 5; ++i) {\n /* istanbul ignore if */\n if (this.pos >= this.len)\n throw indexOutOfRange(this);\n // 6th..10th\n bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;\n if (this.buf[this.pos++] < 128)\n return bits;\n }\n }\n /* istanbul ignore next */\n throw Error(\"invalid varint encoding\");\n}\n\n/* eslint-enable no-invalid-this */\n\n/**\n * Reads a varint as a signed 64 bit value.\n * @name Reader#int64\n * @function\n * @returns {Long} Value read\n */\n\n/**\n * Reads a varint as an unsigned 64 bit value.\n * @name Reader#uint64\n * @function\n * @returns {Long} Value read\n */\n\n/**\n * Reads a zig-zag encoded varint as a signed 64 bit value.\n * @name Reader#sint64\n * @function\n * @returns {Long} Value read\n */\n\n/**\n * Reads a varint as a boolean.\n * @returns {boolean} Value read\n */\nReader.prototype.bool = function read_bool() {\n return this.uint32() !== 0;\n};\n\nfunction readFixed32_end(buf, end) { // note that this uses `end`, not `pos`\n return (buf[end - 4]\n | buf[end - 3] << 8\n | buf[end - 2] << 16\n | buf[end - 1] << 24) >>> 0;\n}\n\n/**\n * Reads fixed 32 bits as an unsigned 32 bit integer.\n * @returns {number} Value read\n */\nReader.prototype.fixed32 = function read_fixed32() {\n\n /* istanbul ignore if */\n if (this.pos + 4 > this.len)\n throw indexOutOfRange(this, 4);\n\n return readFixed32_end(this.buf, this.pos += 4);\n};\n\n/**\n * Reads fixed 32 bits as a signed 32 bit integer.\n * @returns {number} Value read\n */\nReader.prototype.sfixed32 = function read_sfixed32() {\n\n /* istanbul ignore if */\n if (this.pos + 4 > this.len)\n throw indexOutOfRange(this, 4);\n\n return readFixed32_end(this.buf, this.pos += 4) | 0;\n};\n\n/* eslint-disable no-invalid-this */\n\nfunction readFixed64(/* this: Reader */) {\n\n /* istanbul ignore if */\n if (this.pos + 8 > this.len)\n throw indexOutOfRange(this, 8);\n\n return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));\n}\n\n/* eslint-enable no-invalid-this */\n\n/**\n * Reads fixed 64 bits.\n * @name Reader#fixed64\n * @function\n * @returns {Long} Value read\n */\n\n/**\n * Reads zig-zag encoded fixed 64 bits.\n * @name Reader#sfixed64\n * @function\n * @returns {Long} Value read\n */\n\n/**\n * Reads a float (32 bit) as a number.\n * @function\n * @returns {number} Value read\n */\nReader.prototype.float = function read_float() {\n\n /* istanbul ignore if */\n if (this.pos + 4 > this.len)\n throw indexOutOfRange(this, 4);\n\n var value = util.float.readFloatLE(this.buf, this.pos);\n this.pos += 4;\n return value;\n};\n\n/**\n * Reads a double (64 bit float) as a number.\n * @function\n * @returns {number} Value read\n */\nReader.prototype.double = function read_double() {\n\n /* istanbul ignore if */\n if (this.pos + 8 > this.len)\n throw indexOutOfRange(this, 4);\n\n var value = util.float.readDoubleLE(this.buf, this.pos);\n this.pos += 8;\n return value;\n};\n\n/**\n * Reads a sequence of bytes preceeded by its length as a varint.\n * @returns {Uint8Array} Value read\n */\nReader.prototype.bytes = function read_bytes() {\n var length = this.uint32(),\n start = this.pos,\n end = this.pos + length;\n\n /* istanbul ignore if */\n if (end > this.len)\n throw indexOutOfRange(this, length);\n\n this.pos += length;\n if (Array.isArray(this.buf)) // plain array\n return this.buf.slice(start, end);\n return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1\n ? new this.buf.constructor(0)\n : this._slice.call(this.buf, start, end);\n};\n\n/**\n * Reads a string preceeded by its byte length as a varint.\n * @returns {string} Value read\n */\nReader.prototype.string = function read_string() {\n var bytes = this.bytes();\n return utf8.read(bytes, 0, bytes.length);\n};\n\n/**\n * Skips the specified number of bytes if specified, otherwise skips a varint.\n * @param {number} [length] Length if known, otherwise a varint is assumed\n * @returns {Reader} `this`\n */\nReader.prototype.skip = function skip(length) {\n if (typeof length === \"number\") {\n /* istanbul ignore if */\n if (this.pos + length > this.len)\n throw indexOutOfRange(this, length);\n this.pos += length;\n } else {\n do {\n /* istanbul ignore if */\n if (this.pos >= this.len)\n throw indexOutOfRange(this);\n } while (this.buf[this.pos++] & 128);\n }\n return this;\n};\n\n/**\n * Skips the next element of the specified wire type.\n * @param {number} wireType Wire type received\n * @returns {Reader} `this`\n */\nReader.prototype.skipType = function(wireType) {\n switch (wireType) {\n case 0:\n this.skip();\n break;\n case 1:\n this.skip(8);\n break;\n case 2:\n this.skip(this.uint32());\n break;\n case 3:\n while ((wireType = this.uint32() & 7) !== 4) {\n this.skipType(wireType);\n }\n break;\n case 5:\n this.skip(4);\n break;\n\n /* istanbul ignore next */\n default:\n throw Error(\"invalid wire type \" + wireType + \" at offset \" + this.pos);\n }\n return this;\n};\n\nReader._configure = function(BufferReader_) {\n BufferReader = BufferReader_;\n Reader.create = create();\n BufferReader._configure();\n\n var fn = util.Long ? \"toLong\" : /* istanbul ignore next */ \"toNumber\";\n util.merge(Reader.prototype, {\n\n int64: function read_int64() {\n return readLongVarint.call(this)[fn](false);\n },\n\n uint64: function read_uint64() {\n return readLongVarint.call(this)[fn](true);\n },\n\n sint64: function read_sint64() {\n return readLongVarint.call(this).zzDecode()[fn](false);\n },\n\n fixed64: function read_fixed64() {\n return readFixed64.call(this)[fn](true);\n },\n\n sfixed64: function read_sfixed64() {\n return readFixed64.call(this)[fn](false);\n }\n\n });\n};\n", "\"use strict\";\nmodule.exports = BufferReader;\n\n// extends Reader\nvar Reader = require(9);\n(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;\n\nvar util = require(15);\n\n/**\n * Constructs a new buffer reader instance.\n * @classdesc Wire format reader using node buffers.\n * @extends Reader\n * @constructor\n * @param {Buffer} buffer Buffer to read from\n */\nfunction BufferReader(buffer) {\n Reader.call(this, buffer);\n\n /**\n * Read buffer.\n * @name BufferReader#buf\n * @type {Buffer}\n */\n}\n\nBufferReader._configure = function () {\n /* istanbul ignore else */\n if (util.Buffer)\n BufferReader.prototype._slice = util.Buffer.prototype.slice;\n};\n\n\n/**\n * @override\n */\nBufferReader.prototype.string = function read_string_buffer() {\n var len = this.uint32(); // modifies pos\n return this.buf.utf8Slice\n ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len))\n : this.buf.toString(\"utf-8\", this.pos, this.pos = Math.min(this.pos + len, this.len));\n};\n\n/**\n * Reads a sequence of bytes preceeded by its length as a varint.\n * @name BufferReader#bytes\n * @function\n * @returns {Buffer} Value read\n */\n\nBufferReader._configure();\n", "\"use strict\";\nmodule.exports = {};\n\n/**\n * Named roots.\n * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).\n * Can also be used manually to make roots available across modules.\n * @name roots\n * @type {Object.}\n * @example\n * // pbjs -r myroot -o compiled.js ...\n *\n * // in another module:\n * require(\"./compiled.js\");\n *\n * // in any subsequent module:\n * var root = protobuf.roots[\"myroot\"];\n */\n", "\"use strict\";\n\n/**\n * Streaming RPC helpers.\n * @namespace\n */\nvar rpc = exports;\n\n/**\n * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.\n * @typedef RPCImpl\n * @type {function}\n * @param {Method|rpc.ServiceMethod,Message<{}>>} method Reflected or static method being called\n * @param {Uint8Array} requestData Request data\n * @param {RPCImplCallback} callback Callback function\n * @returns {undefined}\n * @example\n * function rpcImpl(method, requestData, callback) {\n * if (protobuf.util.lcFirst(method.name) !== \"myMethod\") // compatible with static code\n * throw Error(\"no such method\");\n * asynchronouslyObtainAResponse(requestData, function(err, responseData) {\n * callback(err, responseData);\n * });\n * }\n */\n\n/**\n * Node-style callback as used by {@link RPCImpl}.\n * @typedef RPCImplCallback\n * @type {function}\n * @param {Error|null} error Error, if any, otherwise `null`\n * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error\n * @returns {undefined}\n */\n\nrpc.Service = require(13);\n", "\"use strict\";\nmodule.exports = Service;\n\nvar util = require(15);\n\n// Extends EventEmitter\n(Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;\n\n/**\n * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.\n *\n * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.\n * @typedef rpc.ServiceMethodCallback\n * @template TRes extends Message\n * @type {function}\n * @param {Error|null} error Error, if any\n * @param {TRes} [response] Response message\n * @returns {undefined}\n */\n\n/**\n * A service method part of a {@link rpc.Service} as created by {@link Service.create}.\n * @typedef rpc.ServiceMethod\n * @template TReq extends Message\n * @template TRes extends Message\n * @type {function}\n * @param {TReq|Properties} request Request message or plain object\n * @param {rpc.ServiceMethodCallback} [callback] Node-style callback called with the error, if any, and the response message\n * @returns {Promise>} Promise if `callback` has been omitted, otherwise `undefined`\n */\n\n/**\n * Constructs a new RPC service instance.\n * @classdesc An RPC service as returned by {@link Service#create}.\n * @exports rpc.Service\n * @extends util.EventEmitter\n * @constructor\n * @param {RPCImpl} rpcImpl RPC implementation\n * @param {boolean} [requestDelimited=false] Whether requests are length-delimited\n * @param {boolean} [responseDelimited=false] Whether responses are length-delimited\n */\nfunction Service(rpcImpl, requestDelimited, responseDelimited) {\n\n if (typeof rpcImpl !== \"function\")\n throw TypeError(\"rpcImpl must be a function\");\n\n util.EventEmitter.call(this);\n\n /**\n * RPC implementation. Becomes `null` once the service is ended.\n * @type {RPCImpl|null}\n */\n this.rpcImpl = rpcImpl;\n\n /**\n * Whether requests are length-delimited.\n * @type {boolean}\n */\n this.requestDelimited = Boolean(requestDelimited);\n\n /**\n * Whether responses are length-delimited.\n * @type {boolean}\n */\n this.responseDelimited = Boolean(responseDelimited);\n}\n\n/**\n * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.\n * @param {Method|rpc.ServiceMethod} method Reflected or static method\n * @param {Constructor} requestCtor Request constructor\n * @param {Constructor} responseCtor Response constructor\n * @param {TReq|Properties} request Request message or plain object\n * @param {rpc.ServiceMethodCallback} callback Service callback\n * @returns {undefined}\n * @template TReq extends Message\n * @template TRes extends Message\n */\nService.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {\n\n if (!request)\n throw TypeError(\"request must be specified\");\n\n var self = this;\n if (!callback)\n return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);\n\n if (!self.rpcImpl) {\n setTimeout(function() { callback(Error(\"already ended\")); }, 0);\n return undefined;\n }\n\n try {\n return self.rpcImpl(\n method,\n requestCtor[self.requestDelimited ? \"encodeDelimited\" : \"encode\"](request).finish(),\n function rpcCallback(err, response) {\n\n if (err) {\n self.emit(\"error\", err, method);\n return callback(err);\n }\n\n if (response === null) {\n self.end(/* endedByRPC */ true);\n return undefined;\n }\n\n if (!(response instanceof responseCtor)) {\n try {\n response = responseCtor[self.responseDelimited ? \"decodeDelimited\" : \"decode\"](response);\n } catch (err) {\n self.emit(\"error\", err, method);\n return callback(err);\n }\n }\n\n self.emit(\"data\", response, method);\n return callback(null, response);\n }\n );\n } catch (err) {\n self.emit(\"error\", err, method);\n setTimeout(function() { callback(err); }, 0);\n return undefined;\n }\n};\n\n/**\n * Ends this service and emits the `end` event.\n * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.\n * @returns {rpc.Service} `this`\n */\nService.prototype.end = function end(endedByRPC) {\n if (this.rpcImpl) {\n if (!endedByRPC) // signal end to rpcImpl\n this.rpcImpl(null, null, null);\n this.rpcImpl = null;\n this.emit(\"end\").off();\n }\n return this;\n};\n", "\"use strict\";\nmodule.exports = LongBits;\n\nvar util = require(15);\n\n/**\n * Constructs new long bits.\n * @classdesc Helper class for working with the low and high bits of a 64 bit value.\n * @memberof util\n * @constructor\n * @param {number} lo Low 32 bits, unsigned\n * @param {number} hi High 32 bits, unsigned\n */\nfunction LongBits(lo, hi) {\n\n // note that the casts below are theoretically unnecessary as of today, but older statically\n // generated converter code might still call the ctor with signed 32bits. kept for compat.\n\n /**\n * Low bits.\n * @type {number}\n */\n this.lo = lo >>> 0;\n\n /**\n * High bits.\n * @type {number}\n */\n this.hi = hi >>> 0;\n}\n\n/**\n * Zero bits.\n * @memberof util.LongBits\n * @type {util.LongBits}\n */\nvar zero = LongBits.zero = new LongBits(0, 0);\n\nzero.toNumber = function() { return 0; };\nzero.zzEncode = zero.zzDecode = function() { return this; };\nzero.length = function() { return 1; };\n\n/**\n * Zero hash.\n * @memberof util.LongBits\n * @type {string}\n */\nvar zeroHash = LongBits.zeroHash = \"\\0\\0\\0\\0\\0\\0\\0\\0\";\n\n/**\n * Constructs new long bits from the specified number.\n * @param {number} value Value\n * @returns {util.LongBits} Instance\n */\nLongBits.fromNumber = function fromNumber(value) {\n if (value === 0)\n return zero;\n var sign = value < 0;\n if (sign)\n value = -value;\n var lo = value >>> 0,\n hi = (value - lo) / 4294967296 >>> 0;\n if (sign) {\n hi = ~hi >>> 0;\n lo = ~lo >>> 0;\n if (++lo > 4294967295) {\n lo = 0;\n if (++hi > 4294967295)\n hi = 0;\n }\n }\n return new LongBits(lo, hi);\n};\n\n/**\n * Constructs new long bits from a number, long or string.\n * @param {Long|number|string} value Value\n * @returns {util.LongBits} Instance\n */\nLongBits.from = function from(value) {\n if (typeof value === \"number\")\n return LongBits.fromNumber(value);\n if (util.isString(value)) {\n /* istanbul ignore else */\n if (util.Long)\n value = util.Long.fromString(value);\n else\n return LongBits.fromNumber(parseInt(value, 10));\n }\n return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;\n};\n\n/**\n * Converts this long bits to a possibly unsafe JavaScript number.\n * @param {boolean} [unsigned=false] Whether unsigned or not\n * @returns {number} Possibly unsafe number\n */\nLongBits.prototype.toNumber = function toNumber(unsigned) {\n if (!unsigned && this.hi >>> 31) {\n var lo = ~this.lo + 1 >>> 0,\n hi = ~this.hi >>> 0;\n if (!lo)\n hi = hi + 1 >>> 0;\n return -(lo + hi * 4294967296);\n }\n return this.lo + this.hi * 4294967296;\n};\n\n/**\n * Converts this long bits to a long.\n * @param {boolean} [unsigned=false] Whether unsigned or not\n * @returns {Long} Long\n */\nLongBits.prototype.toLong = function toLong(unsigned) {\n return util.Long\n ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))\n /* istanbul ignore next */\n : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };\n};\n\nvar charCodeAt = String.prototype.charCodeAt;\n\n/**\n * Constructs new long bits from the specified 8 characters long hash.\n * @param {string} hash Hash\n * @returns {util.LongBits} Bits\n */\nLongBits.fromHash = function fromHash(hash) {\n if (hash === zeroHash)\n return zero;\n return new LongBits(\n ( charCodeAt.call(hash, 0)\n | charCodeAt.call(hash, 1) << 8\n | charCodeAt.call(hash, 2) << 16\n | charCodeAt.call(hash, 3) << 24) >>> 0\n ,\n ( charCodeAt.call(hash, 4)\n | charCodeAt.call(hash, 5) << 8\n | charCodeAt.call(hash, 6) << 16\n | charCodeAt.call(hash, 7) << 24) >>> 0\n );\n};\n\n/**\n * Converts this long bits to a 8 characters long hash.\n * @returns {string} Hash\n */\nLongBits.prototype.toHash = function toHash() {\n return String.fromCharCode(\n this.lo & 255,\n this.lo >>> 8 & 255,\n this.lo >>> 16 & 255,\n this.lo >>> 24 ,\n this.hi & 255,\n this.hi >>> 8 & 255,\n this.hi >>> 16 & 255,\n this.hi >>> 24\n );\n};\n\n/**\n * Zig-zag encodes this long bits.\n * @returns {util.LongBits} `this`\n */\nLongBits.prototype.zzEncode = function zzEncode() {\n var mask = this.hi >> 31;\n this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;\n this.lo = ( this.lo << 1 ^ mask) >>> 0;\n return this;\n};\n\n/**\n * Zig-zag decodes this long bits.\n * @returns {util.LongBits} `this`\n */\nLongBits.prototype.zzDecode = function zzDecode() {\n var mask = -(this.lo & 1);\n this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;\n this.hi = ( this.hi >>> 1 ^ mask) >>> 0;\n return this;\n};\n\n/**\n * Calculates the length of this longbits when encoded as a varint.\n * @returns {number} Length\n */\nLongBits.prototype.length = function length() {\n var part0 = this.lo,\n part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,\n part2 = this.hi >>> 24;\n return part2 === 0\n ? part1 === 0\n ? part0 < 16384\n ? part0 < 128 ? 1 : 2\n : part0 < 2097152 ? 3 : 4\n : part1 < 16384\n ? part1 < 128 ? 5 : 6\n : part1 < 2097152 ? 7 : 8\n : part2 < 128 ? 9 : 10;\n};\n", "\"use strict\";\nvar util = exports;\n\n// used to return a Promise where callback is omitted\nutil.asPromise = require(1);\n\n// converts to / from base64 encoded strings\nutil.base64 = require(2);\n\n// base class of rpc.Service\nutil.EventEmitter = require(3);\n\n// float handling accross browsers\nutil.float = require(4);\n\n// requires modules optionally and hides the call from bundlers\nutil.inquire = require(5);\n\n// converts to / from utf8 encoded strings\nutil.utf8 = require(7);\n\n// provides a node-like buffer pool in the browser\nutil.pool = require(6);\n\n// utility to work with the low and high bits of a 64 bit value\nutil.LongBits = require(14);\n\n/**\n * Whether running within node or not.\n * @memberof util\n * @type {boolean}\n */\nutil.isNode = Boolean(typeof global !== \"undefined\"\n && global\n && global.process\n && global.process.versions\n && global.process.versions.node);\n\n/**\n * Global object reference.\n * @memberof util\n * @type {Object}\n */\nutil.global = util.isNode && global\n || typeof window !== \"undefined\" && window\n || typeof self !== \"undefined\" && self\n || this; // eslint-disable-line no-invalid-this\n\n/**\n * An immuable empty array.\n * @memberof util\n * @type {Array.<*>}\n * @const\n */\nutil.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes\n\n/**\n * An immutable empty object.\n * @type {Object}\n * @const\n */\nutil.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes\n\n/**\n * Tests if the specified value is an integer.\n * @function\n * @param {*} value Value to test\n * @returns {boolean} `true` if the value is an integer\n */\nutil.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {\n return typeof value === \"number\" && isFinite(value) && Math.floor(value) === value;\n};\n\n/**\n * Tests if the specified value is a string.\n * @param {*} value Value to test\n * @returns {boolean} `true` if the value is a string\n */\nutil.isString = function isString(value) {\n return typeof value === \"string\" || value instanceof String;\n};\n\n/**\n * Tests if the specified value is a non-null object.\n * @param {*} value Value to test\n * @returns {boolean} `true` if the value is a non-null object\n */\nutil.isObject = function isObject(value) {\n return value && typeof value === \"object\";\n};\n\n/**\n * Checks if a property on a message is considered to be present.\n * This is an alias of {@link util.isSet}.\n * @function\n * @param {Object} obj Plain object or message instance\n * @param {string} prop Property name\n * @returns {boolean} `true` if considered to be present, otherwise `false`\n */\nutil.isset =\n\n/**\n * Checks if a property on a message is considered to be present.\n * @param {Object} obj Plain object or message instance\n * @param {string} prop Property name\n * @returns {boolean} `true` if considered to be present, otherwise `false`\n */\nutil.isSet = function isSet(obj, prop) {\n var value = obj[prop];\n if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins\n return typeof value !== \"object\" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;\n return false;\n};\n\n/**\n * Any compatible Buffer instance.\n * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.\n * @interface Buffer\n * @extends Uint8Array\n */\n\n/**\n * Node's Buffer class if available.\n * @type {Constructor}\n */\nutil.Buffer = (function() {\n try {\n var Buffer = util.inquire(\"buffer\").Buffer;\n // refuse to use non-node buffers if not explicitly assigned (perf reasons):\n return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;\n } catch (e) {\n /* istanbul ignore next */\n return null;\n }\n})();\n\n// Internal alias of or polyfull for Buffer.from.\nutil._Buffer_from = null;\n\n// Internal alias of or polyfill for Buffer.allocUnsafe.\nutil._Buffer_allocUnsafe = null;\n\n/**\n * Creates a new buffer of whatever type supported by the environment.\n * @param {number|number[]} [sizeOrArray=0] Buffer size or number array\n * @returns {Uint8Array|Buffer} Buffer\n */\nutil.newBuffer = function newBuffer(sizeOrArray) {\n /* istanbul ignore next */\n return typeof sizeOrArray === \"number\"\n ? util.Buffer\n ? util._Buffer_allocUnsafe(sizeOrArray)\n : new util.Array(sizeOrArray)\n : util.Buffer\n ? util._Buffer_from(sizeOrArray)\n : typeof Uint8Array === \"undefined\"\n ? sizeOrArray\n : new Uint8Array(sizeOrArray);\n};\n\n/**\n * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.\n * @type {Constructor}\n */\nutil.Array = typeof Uint8Array !== \"undefined\" ? Uint8Array /* istanbul ignore next */ : Array;\n\n/**\n * Any compatible Long instance.\n * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.\n * @interface Long\n * @property {number} low Low bits\n * @property {number} high High bits\n * @property {boolean} unsigned Whether unsigned or not\n */\n\n/**\n * Long.js's Long class if available.\n * @type {Constructor}\n */\nutil.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long\n || /* istanbul ignore next */ util.global.Long\n || util.inquire(\"long\");\n\n/**\n * Regular expression used to verify 2 bit (`bool`) map keys.\n * @type {RegExp}\n * @const\n */\nutil.key2Re = /^true|false|0|1$/;\n\n/**\n * Regular expression used to verify 32 bit (`int32` etc.) map keys.\n * @type {RegExp}\n * @const\n */\nutil.key32Re = /^-?(?:0|[1-9][0-9]*)$/;\n\n/**\n * Regular expression used to verify 64 bit (`int64` etc.) map keys.\n * @type {RegExp}\n * @const\n */\nutil.key64Re = /^(?:[\\\\x00-\\\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;\n\n/**\n * Converts a number or long to an 8 characters long hash string.\n * @param {Long|number} value Value to convert\n * @returns {string} Hash\n */\nutil.longToHash = function longToHash(value) {\n return value\n ? util.LongBits.from(value).toHash()\n : util.LongBits.zeroHash;\n};\n\n/**\n * Converts an 8 characters long hash string to a long or number.\n * @param {string} hash Hash\n * @param {boolean} [unsigned=false] Whether unsigned or not\n * @returns {Long|number} Original value\n */\nutil.longFromHash = function longFromHash(hash, unsigned) {\n var bits = util.LongBits.fromHash(hash);\n if (util.Long)\n return util.Long.fromBits(bits.lo, bits.hi, unsigned);\n return bits.toNumber(Boolean(unsigned));\n};\n\n/**\n * Merges the properties of the source object into the destination object.\n * @memberof util\n * @param {Object.} dst Destination object\n * @param {Object.} src Source object\n * @param {boolean} [ifNotSet=false] Merges only if the key is not already set\n * @returns {Object.} Destination object\n */\nfunction merge(dst, src, ifNotSet) { // used by converters\n for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)\n if (dst[keys[i]] === undefined || !ifNotSet)\n dst[keys[i]] = src[keys[i]];\n return dst;\n}\n\nutil.merge = merge;\n\n/**\n * Converts the first character of a string to lower case.\n * @param {string} str String to convert\n * @returns {string} Converted string\n */\nutil.lcFirst = function lcFirst(str) {\n return str.charAt(0).toLowerCase() + str.substring(1);\n};\n\n/**\n * Creates a custom error constructor.\n * @memberof util\n * @param {string} name Error name\n * @returns {Constructor} Custom error constructor\n */\nfunction newError(name) {\n\n function CustomError(message, properties) {\n\n if (!(this instanceof CustomError))\n return new CustomError(message, properties);\n\n // Error.call(this, message);\n // ^ just returns a new error instance because the ctor can be called as a function\n\n Object.defineProperty(this, \"message\", { get: function() { return message; } });\n\n /* istanbul ignore next */\n if (Error.captureStackTrace) // node\n Error.captureStackTrace(this, CustomError);\n else\n Object.defineProperty(this, \"stack\", { value: new Error().stack || \"\" });\n\n if (properties)\n merge(this, properties);\n }\n\n CustomError.prototype = Object.create(Error.prototype, {\n constructor: {\n value: CustomError,\n writable: true,\n enumerable: false,\n configurable: true,\n },\n name: {\n get() { return name; },\n set: undefined,\n enumerable: false,\n // configurable: false would accurately preserve the behavior of\n // the original, but I'm guessing that was not intentional.\n // For an actual error subclass, this property would\n // be configurable.\n configurable: true,\n },\n toString: {\n value() { return this.name + \": \" + this.message; },\n writable: true,\n enumerable: false,\n configurable: true,\n },\n });\n\n return CustomError;\n}\n\nutil.newError = newError;\n\n/**\n * Constructs a new protocol error.\n * @classdesc Error subclass indicating a protocol specifc error.\n * @memberof util\n * @extends Error\n * @template T extends Message\n * @constructor\n * @param {string} message Error message\n * @param {Object.} [properties] Additional properties\n * @example\n * try {\n * MyMessage.decode(someBuffer); // throws if required fields are missing\n * } catch (e) {\n * if (e instanceof ProtocolError && e.instance)\n * console.log(\"decoded so far: \" + JSON.stringify(e.instance));\n * }\n */\nutil.ProtocolError = newError(\"ProtocolError\");\n\n/**\n * So far decoded message instance.\n * @name util.ProtocolError#instance\n * @type {Message}\n */\n\n/**\n * A OneOf getter as returned by {@link util.oneOfGetter}.\n * @typedef OneOfGetter\n * @type {function}\n * @returns {string|undefined} Set field name, if any\n */\n\n/**\n * Builds a getter for a oneof's present field name.\n * @param {string[]} fieldNames Field names\n * @returns {OneOfGetter} Unbound getter\n */\nutil.oneOfGetter = function getOneOf(fieldNames) {\n var fieldMap = {};\n for (var i = 0; i < fieldNames.length; ++i)\n fieldMap[fieldNames[i]] = 1;\n\n /**\n * @returns {string|undefined} Set field name, if any\n * @this Object\n * @ignore\n */\n return function() { // eslint-disable-line consistent-return\n for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)\n if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)\n return keys[i];\n };\n};\n\n/**\n * A OneOf setter as returned by {@link util.oneOfSetter}.\n * @typedef OneOfSetter\n * @type {function}\n * @param {string|undefined} value Field name\n * @returns {undefined}\n */\n\n/**\n * Builds a setter for a oneof's present field name.\n * @param {string[]} fieldNames Field names\n * @returns {OneOfSetter} Unbound setter\n */\nutil.oneOfSetter = function setOneOf(fieldNames) {\n\n /**\n * @param {string} name Field name\n * @returns {undefined}\n * @this Object\n * @ignore\n */\n return function(name) {\n for (var i = 0; i < fieldNames.length; ++i)\n if (fieldNames[i] !== name)\n delete this[fieldNames[i]];\n };\n};\n\n/**\n * Default conversion options used for {@link Message#toJSON} implementations.\n *\n * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:\n *\n * - Longs become strings\n * - Enums become string keys\n * - Bytes become base64 encoded strings\n * - (Sub-)Messages become plain objects\n * - Maps become plain objects with all string keys\n * - Repeated fields become arrays\n * - NaN and Infinity for float and double fields become strings\n *\n * @type {IConversionOptions}\n * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json\n */\nutil.toJSONOptions = {\n longs: String,\n enums: String,\n bytes: String,\n json: true\n};\n\n// Sets up buffer utility according to the environment (called in index-minimal)\nutil._configure = function() {\n var Buffer = util.Buffer;\n /* istanbul ignore if */\n if (!Buffer) {\n util._Buffer_from = util._Buffer_allocUnsafe = null;\n return;\n }\n // because node 4.x buffers are incompatible & immutable\n // see: https://github.com/dcodeIO/protobuf.js/pull/665\n util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||\n /* istanbul ignore next */\n function Buffer_from(value, encoding) {\n return new Buffer(value, encoding);\n };\n util._Buffer_allocUnsafe = Buffer.allocUnsafe ||\n /* istanbul ignore next */\n function Buffer_allocUnsafe(size) {\n return new Buffer(size);\n };\n};\n", "\"use strict\";\nmodule.exports = Writer;\n\nvar util = require(15);\n\nvar BufferWriter; // cyclic\n\nvar LongBits = util.LongBits,\n base64 = util.base64,\n utf8 = util.utf8;\n\n/**\n * Constructs a new writer operation instance.\n * @classdesc Scheduled writer operation.\n * @constructor\n * @param {function(*, Uint8Array, number)} fn Function to call\n * @param {number} len Value byte length\n * @param {*} val Value to write\n * @ignore\n */\nfunction Op(fn, len, val) {\n\n /**\n * Function to call.\n * @type {function(Uint8Array, number, *)}\n */\n this.fn = fn;\n\n /**\n * Value byte length.\n * @type {number}\n */\n this.len = len;\n\n /**\n * Next operation.\n * @type {Writer.Op|undefined}\n */\n this.next = undefined;\n\n /**\n * Value to write.\n * @type {*}\n */\n this.val = val; // type varies\n}\n\n/* istanbul ignore next */\nfunction noop() {} // eslint-disable-line no-empty-function\n\n/**\n * Constructs a new writer state instance.\n * @classdesc Copied writer state.\n * @memberof Writer\n * @constructor\n * @param {Writer} writer Writer to copy state from\n * @ignore\n */\nfunction State(writer) {\n\n /**\n * Current head.\n * @type {Writer.Op}\n */\n this.head = writer.head;\n\n /**\n * Current tail.\n * @type {Writer.Op}\n */\n this.tail = writer.tail;\n\n /**\n * Current buffer length.\n * @type {number}\n */\n this.len = writer.len;\n\n /**\n * Next state.\n * @type {State|null}\n */\n this.next = writer.states;\n}\n\n/**\n * Constructs a new writer instance.\n * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.\n * @constructor\n */\nfunction Writer() {\n\n /**\n * Current length.\n * @type {number}\n */\n this.len = 0;\n\n /**\n * Operations head.\n * @type {Object}\n */\n this.head = new Op(noop, 0, 0);\n\n /**\n * Operations tail\n * @type {Object}\n */\n this.tail = this.head;\n\n /**\n * Linked forked states.\n * @type {Object|null}\n */\n this.states = null;\n\n // When a value is written, the writer calculates its byte length and puts it into a linked\n // list of operations to perform when finish() is called. This both allows us to allocate\n // buffers of the exact required size and reduces the amount of work we have to do compared\n // to first calculating over objects and then encoding over objects. In our case, the encoding\n // part is just a linked list walk calling operations with already prepared values.\n}\n\nvar create = function create() {\n return util.Buffer\n ? function create_buffer_setup() {\n return (Writer.create = function create_buffer() {\n return new BufferWriter();\n })();\n }\n /* istanbul ignore next */\n : function create_array() {\n return new Writer();\n };\n};\n\n/**\n * Creates a new writer.\n * @function\n * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}\n */\nWriter.create = create();\n\n/**\n * Allocates a buffer of the specified size.\n * @param {number} size Buffer size\n * @returns {Uint8Array} Buffer\n */\nWriter.alloc = function alloc(size) {\n return new util.Array(size);\n};\n\n// Use Uint8Array buffer pool in the browser, just like node does with buffers\n/* istanbul ignore else */\nif (util.Array !== Array)\n Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);\n\n/**\n * Pushes a new operation to the queue.\n * @param {function(Uint8Array, number, *)} fn Function to call\n * @param {number} len Value byte length\n * @param {number} val Value to write\n * @returns {Writer} `this`\n * @private\n */\nWriter.prototype._push = function push(fn, len, val) {\n this.tail = this.tail.next = new Op(fn, len, val);\n this.len += len;\n return this;\n};\n\nfunction writeByte(val, buf, pos) {\n buf[pos] = val & 255;\n}\n\nfunction writeVarint32(val, buf, pos) {\n while (val > 127) {\n buf[pos++] = val & 127 | 128;\n val >>>= 7;\n }\n buf[pos] = val;\n}\n\n/**\n * Constructs a new varint writer operation instance.\n * @classdesc Scheduled varint writer operation.\n * @extends Op\n * @constructor\n * @param {number} len Value byte length\n * @param {number} val Value to write\n * @ignore\n */\nfunction VarintOp(len, val) {\n this.len = len;\n this.next = undefined;\n this.val = val;\n}\n\nVarintOp.prototype = Object.create(Op.prototype);\nVarintOp.prototype.fn = writeVarint32;\n\n/**\n * Writes an unsigned 32 bit value as a varint.\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.uint32 = function write_uint32(value) {\n // here, the call to this.push has been inlined and a varint specific Op subclass is used.\n // uint32 is by far the most frequently used operation and benefits significantly from this.\n this.len += (this.tail = this.tail.next = new VarintOp(\n (value = value >>> 0)\n < 128 ? 1\n : value < 16384 ? 2\n : value < 2097152 ? 3\n : value < 268435456 ? 4\n : 5,\n value)).len;\n return this;\n};\n\n/**\n * Writes a signed 32 bit value as a varint.\n * @function\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.int32 = function write_int32(value) {\n return value < 0\n ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec\n : this.uint32(value);\n};\n\n/**\n * Writes a 32 bit value as a varint, zig-zag encoded.\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.sint32 = function write_sint32(value) {\n return this.uint32((value << 1 ^ value >> 31) >>> 0);\n};\n\nfunction writeVarint64(val, buf, pos) {\n while (val.hi) {\n buf[pos++] = val.lo & 127 | 128;\n val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;\n val.hi >>>= 7;\n }\n while (val.lo > 127) {\n buf[pos++] = val.lo & 127 | 128;\n val.lo = val.lo >>> 7;\n }\n buf[pos++] = val.lo;\n}\n\n/**\n * Writes an unsigned 64 bit value as a varint.\n * @param {Long|number|string} value Value to write\n * @returns {Writer} `this`\n * @throws {TypeError} If `value` is a string and no long library is present.\n */\nWriter.prototype.uint64 = function write_uint64(value) {\n var bits = LongBits.from(value);\n return this._push(writeVarint64, bits.length(), bits);\n};\n\n/**\n * Writes a signed 64 bit value as a varint.\n * @function\n * @param {Long|number|string} value Value to write\n * @returns {Writer} `this`\n * @throws {TypeError} If `value` is a string and no long library is present.\n */\nWriter.prototype.int64 = Writer.prototype.uint64;\n\n/**\n * Writes a signed 64 bit value as a varint, zig-zag encoded.\n * @param {Long|number|string} value Value to write\n * @returns {Writer} `this`\n * @throws {TypeError} If `value` is a string and no long library is present.\n */\nWriter.prototype.sint64 = function write_sint64(value) {\n var bits = LongBits.from(value).zzEncode();\n return this._push(writeVarint64, bits.length(), bits);\n};\n\n/**\n * Writes a boolish value as a varint.\n * @param {boolean} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.bool = function write_bool(value) {\n return this._push(writeByte, 1, value ? 1 : 0);\n};\n\nfunction writeFixed32(val, buf, pos) {\n buf[pos ] = val & 255;\n buf[pos + 1] = val >>> 8 & 255;\n buf[pos + 2] = val >>> 16 & 255;\n buf[pos + 3] = val >>> 24;\n}\n\n/**\n * Writes an unsigned 32 bit value as fixed 32 bits.\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.fixed32 = function write_fixed32(value) {\n return this._push(writeFixed32, 4, value >>> 0);\n};\n\n/**\n * Writes a signed 32 bit value as fixed 32 bits.\n * @function\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.sfixed32 = Writer.prototype.fixed32;\n\n/**\n * Writes an unsigned 64 bit value as fixed 64 bits.\n * @param {Long|number|string} value Value to write\n * @returns {Writer} `this`\n * @throws {TypeError} If `value` is a string and no long library is present.\n */\nWriter.prototype.fixed64 = function write_fixed64(value) {\n var bits = LongBits.from(value);\n return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);\n};\n\n/**\n * Writes a signed 64 bit value as fixed 64 bits.\n * @function\n * @param {Long|number|string} value Value to write\n * @returns {Writer} `this`\n * @throws {TypeError} If `value` is a string and no long library is present.\n */\nWriter.prototype.sfixed64 = Writer.prototype.fixed64;\n\n/**\n * Writes a float (32 bit).\n * @function\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.float = function write_float(value) {\n return this._push(util.float.writeFloatLE, 4, value);\n};\n\n/**\n * Writes a double (64 bit float).\n * @function\n * @param {number} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.double = function write_double(value) {\n return this._push(util.float.writeDoubleLE, 8, value);\n};\n\nvar writeBytes = util.Array.prototype.set\n ? function writeBytes_set(val, buf, pos) {\n buf.set(val, pos); // also works for plain array values\n }\n /* istanbul ignore next */\n : function writeBytes_for(val, buf, pos) {\n for (var i = 0; i < val.length; ++i)\n buf[pos + i] = val[i];\n };\n\n/**\n * Writes a sequence of bytes.\n * @param {Uint8Array|string} value Buffer or base64 encoded string to write\n * @returns {Writer} `this`\n */\nWriter.prototype.bytes = function write_bytes(value) {\n var len = value.length >>> 0;\n if (!len)\n return this._push(writeByte, 1, 0);\n if (util.isString(value)) {\n var buf = Writer.alloc(len = base64.length(value));\n base64.decode(value, buf, 0);\n value = buf;\n }\n return this.uint32(len)._push(writeBytes, len, value);\n};\n\n/**\n * Writes a string.\n * @param {string} value Value to write\n * @returns {Writer} `this`\n */\nWriter.prototype.string = function write_string(value) {\n var len = utf8.length(value);\n return len\n ? this.uint32(len)._push(utf8.write, len, value)\n : this._push(writeByte, 1, 0);\n};\n\n/**\n * Forks this writer's state by pushing it to a stack.\n * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.\n * @returns {Writer} `this`\n */\nWriter.prototype.fork = function fork() {\n this.states = new State(this);\n this.head = this.tail = new Op(noop, 0, 0);\n this.len = 0;\n return this;\n};\n\n/**\n * Resets this instance to the last state.\n * @returns {Writer} `this`\n */\nWriter.prototype.reset = function reset() {\n if (this.states) {\n this.head = this.states.head;\n this.tail = this.states.tail;\n this.len = this.states.len;\n this.states = this.states.next;\n } else {\n this.head = this.tail = new Op(noop, 0, 0);\n this.len = 0;\n }\n return this;\n};\n\n/**\n * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.\n * @returns {Writer} `this`\n */\nWriter.prototype.ldelim = function ldelim() {\n var head = this.head,\n tail = this.tail,\n len = this.len;\n this.reset().uint32(len);\n if (len) {\n this.tail.next = head.next; // skip noop\n this.tail = tail;\n this.len += len;\n }\n return this;\n};\n\n/**\n * Finishes the write operation.\n * @returns {Uint8Array} Finished buffer\n */\nWriter.prototype.finish = function finish() {\n var head = this.head.next, // skip noop\n buf = this.constructor.alloc(this.len),\n pos = 0;\n while (head) {\n head.fn(head.val, buf, pos);\n pos += head.len;\n head = head.next;\n }\n // this.head = this.tail = null;\n return buf;\n};\n\nWriter._configure = function(BufferWriter_) {\n BufferWriter = BufferWriter_;\n Writer.create = create();\n BufferWriter._configure();\n};\n", "\"use strict\";\nmodule.exports = BufferWriter;\n\n// extends Writer\nvar Writer = require(16);\n(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;\n\nvar util = require(15);\n\n/**\n * Constructs a new buffer writer instance.\n * @classdesc Wire format writer using node buffers.\n * @extends Writer\n * @constructor\n */\nfunction BufferWriter() {\n Writer.call(this);\n}\n\nBufferWriter._configure = function () {\n /**\n * Allocates a buffer of the specified size.\n * @function\n * @param {number} size Buffer size\n * @returns {Buffer} Buffer\n */\n BufferWriter.alloc = util._Buffer_allocUnsafe;\n\n BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === \"set\"\n ? function writeBytesBuffer_set(val, buf, pos) {\n buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)\n // also works for plain array values\n }\n /* istanbul ignore next */\n : function writeBytesBuffer_copy(val, buf, pos) {\n if (val.copy) // Buffer values\n val.copy(buf, pos, 0, val.length);\n else for (var i = 0; i < val.length;) // plain array values\n buf[pos++] = val[i++];\n };\n};\n\n\n/**\n * @override\n */\nBufferWriter.prototype.bytes = function write_bytes_buffer(value) {\n if (util.isString(value))\n value = util._Buffer_from(value, \"base64\");\n var len = value.length >>> 0;\n this.uint32(len);\n if (len)\n this._push(BufferWriter.writeBytesBuffer, len, value);\n return this;\n};\n\nfunction writeStringBuffer(val, buf, pos) {\n if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)\n util.utf8.write(val, buf, pos);\n else if (buf.utf8Write)\n buf.utf8Write(val, pos);\n else\n buf.write(val, pos);\n}\n\n/**\n * @override\n */\nBufferWriter.prototype.string = function write_string_buffer(value) {\n var len = util.Buffer.byteLength(value);\n this.uint32(len);\n if (len)\n this._push(writeStringBuffer, len, value);\n return this;\n};\n\n\n/**\n * Finishes the write operation.\n * @name BufferWriter#finish\n * @function\n * @returns {Buffer} Finished buffer\n */\n\nBufferWriter._configure();\n", "/* jshint forin: false, bitwise: false */\n/*\nCopyright 2015-2018 Esri\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nA copy of the license and additional notices are located with the\nsource distribution at:\n\nhttp://github.com/Esri/lerc/\n\nContributors: Johannes Schmid, (LERC v1)\n Chayanika Khatua, (LERC v1)\n Wenxue Ju (LERC v1, v2.x)\n*/\n\n/* Copyright 2015-2018 Esri. Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @preserve */\n\n/**\n * a module for decoding LERC blobs\n * @module Lerc\n */\n(function() {\n //the original LercDecode for Version 1\n var LercDecode = (function() {\n\n // WARNING: This decoder version can only read old version 1 Lerc blobs. Use with caution.\n\n // Note: currently, this module only has an implementation for decoding LERC data, not encoding. The name of\n // the class was chosen to be future proof.\n\n var CntZImage = {};\n\n CntZImage.defaultNoDataValue = -3.4027999387901484e+38; // smallest Float32 value\n\n /**\n * Decode a LERC byte stream and return an object containing the pixel data and some required and optional\n * information about it, such as the image's width and height.\n *\n * @param {ArrayBuffer} input The LERC input byte stream\n * @param {object} [options] Decoding options, containing any of the following properties:\n * @config {number} [inputOffset = 0]\n * Skip the first inputOffset bytes of the input byte stream. A valid LERC file is expected at that position.\n * @config {Uint8Array} [encodedMask = null]\n * If specified, the decoder will not read mask information from the input and use the specified encoded\n * mask data instead. Mask header/data must not be present in the LERC byte stream in this case.\n * @config {number} [noDataValue = LercCode.defaultNoDataValue]\n * Pixel value to use for masked pixels.\n * @config {ArrayBufferView|Array} [pixelType = Float32Array]\n * The desired type of the pixelData array in the return value. Note that it is the caller's responsibility to\n * provide an appropriate noDataValue if the default pixelType is overridden.\n * @config {boolean} [returnMask = false]\n * If true, the return value will contain a maskData property of type Uint8Array which has one element per\n * pixel, the value of which is 1 or 0 depending on whether that pixel's data is present or masked. If the\n * input LERC data does not contain a mask, maskData will not be returned.\n * @config {boolean} [returnEncodedMask = false]\n * If true, the return value will contain a encodedMaskData property, which can be passed into encode() as\n * encodedMask.\n * @config {boolean} [returnFileInfo = false]\n * If true, the return value will have a fileInfo property that contains metadata obtained from the\n * LERC headers and the decoding process.\n * @config {boolean} [computeUsedBitDepths = false]\n * If true, the fileInfo property in the return value will contain the set of all block bit depths\n * encountered during decoding. Will only have an effect if returnFileInfo option is true.\n * @returns {{width, height, pixelData, minValue, maxValue, noDataValue, maskData, encodedMaskData, fileInfo}}\n */\n CntZImage.decode = function(input, options) {\n options = options || {};\n\n var skipMask = options.encodedMaskData || (options.encodedMaskData === null);\n var parsedData = parse(input, options.inputOffset || 0, skipMask);\n\n var noDataValue = (options.noDataValue !== null) ? options.noDataValue : CntZImage.defaultNoDataValue;\n\n var uncompressedData = uncompressPixelValues(parsedData, options.pixelType || Float32Array,\n options.encodedMaskData, noDataValue, options.returnMask);\n\n var result = {\n width: parsedData.width,\n height: parsedData.height,\n pixelData: uncompressedData.resultPixels,\n minValue: uncompressedData.minValue,\n maxValue: parsedData.pixels.maxValue,\n noDataValue: noDataValue\n };\n\n if (uncompressedData.resultMask) {\n result.maskData = uncompressedData.resultMask;\n }\n\n if (options.returnEncodedMask && parsedData.mask) {\n result.encodedMaskData = parsedData.mask.bitset ? parsedData.mask.bitset : null;\n }\n\n if (options.returnFileInfo) {\n result.fileInfo = formatFileInfo(parsedData);\n if (options.computeUsedBitDepths) {\n result.fileInfo.bitDepths = computeUsedBitDepths(parsedData);\n }\n }\n\n return result;\n };\n\n var uncompressPixelValues = function(data, TypedArrayClass, maskBitset, noDataValue, storeDecodedMask) {\n var blockIdx = 0;\n var numX = data.pixels.numBlocksX;\n var numY = data.pixels.numBlocksY;\n var blockWidth = Math.floor(data.width / numX);\n var blockHeight = Math.floor(data.height / numY);\n var scale = 2 * data.maxZError;\n var minValue = Number.MAX_VALUE, currentValue;\n maskBitset = maskBitset || ((data.mask) ? data.mask.bitset : null);\n\n var resultPixels, resultMask;\n resultPixels = new TypedArrayClass(data.width * data.height);\n if (storeDecodedMask && maskBitset) {\n resultMask = new Uint8Array(data.width * data.height);\n }\n var blockDataBuffer = new Float32Array(blockWidth * blockHeight);\n\n var xx, yy;\n for (var y = 0; y <= numY; y++) {\n var thisBlockHeight = (y !== numY) ? blockHeight : (data.height % numY);\n if (thisBlockHeight === 0) {\n continue;\n }\n for (var x = 0; x <= numX; x++) {\n var thisBlockWidth = (x !== numX) ? blockWidth : (data.width % numX);\n if (thisBlockWidth === 0) {\n continue;\n }\n\n var outPtr = y * data.width * blockHeight + x * blockWidth;\n var outStride = data.width - thisBlockWidth;\n\n var block = data.pixels.blocks[blockIdx];\n\n var blockData, blockPtr, constValue;\n if (block.encoding < 2) {\n // block is either uncompressed or bit-stuffed (encodings 0 and 1)\n if (block.encoding === 0) {\n // block is uncompressed\n blockData = block.rawData;\n } else {\n // block is bit-stuffed\n unstuff(block.stuffedData, block.bitsPerPixel, block.numValidPixels, block.offset, scale, blockDataBuffer, data.pixels.maxValue);\n blockData = blockDataBuffer;\n }\n blockPtr = 0;\n }\n else if (block.encoding === 2) {\n // block is all 0\n constValue = 0;\n }\n else {\n // block has constant value (encoding === 3)\n constValue = block.offset;\n }\n\n var maskByte;\n if (maskBitset) {\n for (yy = 0; yy < thisBlockHeight; yy++) {\n if (outPtr & 7) {\n //\n maskByte = maskBitset[outPtr >> 3];\n maskByte <<= outPtr & 7;\n }\n for (xx = 0; xx < thisBlockWidth; xx++) {\n if (!(outPtr & 7)) {\n // read next byte from mask\n maskByte = maskBitset[outPtr >> 3];\n }\n if (maskByte & 128) {\n // pixel data present\n if (resultMask) {\n resultMask[outPtr] = 1;\n }\n currentValue = (block.encoding < 2) ? blockData[blockPtr++] : constValue;\n minValue = minValue > currentValue ? currentValue : minValue;\n resultPixels[outPtr++] = currentValue;\n } else {\n // pixel data not present\n if (resultMask) {\n resultMask[outPtr] = 0;\n }\n resultPixels[outPtr++] = noDataValue;\n }\n maskByte <<= 1;\n }\n outPtr += outStride;\n }\n } else {\n // mask not present, simply copy block over\n if (block.encoding < 2) {\n // duplicating this code block for performance reasons\n // blockData case:\n for (yy = 0; yy < thisBlockHeight; yy++) {\n for (xx = 0; xx < thisBlockWidth; xx++) {\n currentValue = blockData[blockPtr++];\n minValue = minValue > currentValue ? currentValue : minValue;\n resultPixels[outPtr++] = currentValue;\n }\n outPtr += outStride;\n }\n }\n else {\n // constValue case:\n minValue = minValue > constValue ? constValue : minValue;\n for (yy = 0; yy < thisBlockHeight; yy++) {\n for (xx = 0; xx < thisBlockWidth; xx++) {\n resultPixels[outPtr++] = constValue;\n }\n outPtr += outStride;\n }\n }\n }\n if ((block.encoding === 1) && (blockPtr !== block.numValidPixels)) {\n throw \"Block and Mask do not match\";\n }\n blockIdx++;\n }\n }\n\n return {\n resultPixels: resultPixels,\n resultMask: resultMask,\n minValue: minValue\n };\n };\n\n var formatFileInfo = function(data) {\n return {\n \"fileIdentifierString\": data.fileIdentifierString,\n \"fileVersion\": data.fileVersion,\n \"imageType\": data.imageType,\n \"height\": data.height,\n \"width\": data.width,\n \"maxZError\": data.maxZError,\n \"eofOffset\": data.eofOffset,\n \"mask\": data.mask ? {\n \"numBlocksX\": data.mask.numBlocksX,\n \"numBlocksY\": data.mask.numBlocksY,\n \"numBytes\": data.mask.numBytes,\n \"maxValue\": data.mask.maxValue\n } : null,\n \"pixels\": {\n \"numBlocksX\": data.pixels.numBlocksX,\n \"numBlocksY\": data.pixels.numBlocksY,\n \"numBytes\": data.pixels.numBytes,\n \"maxValue\": data.pixels.maxValue,\n \"noDataValue\": data.noDataValue\n }\n };\n };\n\n var computeUsedBitDepths = function(data) {\n var numBlocks = data.pixels.numBlocksX * data.pixels.numBlocksY;\n var bitDepths = {};\n for (var i = 0; i < numBlocks; i++) {\n var block = data.pixels.blocks[i];\n if (block.encoding === 0) {\n bitDepths.float32 = true;\n } else if (block.encoding === 1) {\n bitDepths[block.bitsPerPixel] = true;\n } else {\n bitDepths[0] = true;\n }\n }\n\n return Object.keys(bitDepths);\n };\n\n var parse = function(input, fp, skipMask) {\n var data = {};\n\n // File header\n var fileIdView = new Uint8Array(input, fp, 10);\n data.fileIdentifierString = String.fromCharCode.apply(null, fileIdView);\n if (data.fileIdentifierString.trim() !== \"CntZImage\") {\n throw \"Unexpected file identifier string: \" + data.fileIdentifierString;\n }\n fp += 10;\n var view = new DataView(input, fp, 24);\n data.fileVersion = view.getInt32(0, true);\n data.imageType = view.getInt32(4, true);\n data.height = view.getUint32(8, true);\n data.width = view.getUint32(12, true);\n data.maxZError = view.getFloat64(16, true);\n fp += 24;\n\n // Mask Header\n if (!skipMask) {\n view = new DataView(input, fp, 16);\n data.mask = {};\n data.mask.numBlocksY = view.getUint32(0, true);\n data.mask.numBlocksX = view.getUint32(4, true);\n data.mask.numBytes = view.getUint32(8, true);\n data.mask.maxValue = view.getFloat32(12, true);\n fp += 16;\n\n // Mask Data\n if (data.mask.numBytes > 0) {\n var bitset = new Uint8Array(Math.ceil(data.width * data.height / 8));\n view = new DataView(input, fp, data.mask.numBytes);\n var cnt = view.getInt16(0, true);\n var ip = 2, op = 0;\n do {\n if (cnt > 0) {\n while (cnt--) { bitset[op++] = view.getUint8(ip++); }\n } else {\n var val = view.getUint8(ip++);\n cnt = -cnt;\n while (cnt--) { bitset[op++] = val; }\n }\n cnt = view.getInt16(ip, true);\n ip += 2;\n } while (ip < data.mask.numBytes);\n if ((cnt !== -32768) || (op < bitset.length)) {\n throw \"Unexpected end of mask RLE encoding\";\n }\n data.mask.bitset = bitset;\n fp += data.mask.numBytes;\n }\n else if ((data.mask.numBytes | data.mask.numBlocksY | data.mask.maxValue) === 0) { // Special case, all nodata\n data.mask.bitset = new Uint8Array(Math.ceil(data.width * data.height / 8));\n }\n }\n\n // Pixel Header\n view = new DataView(input, fp, 16);\n data.pixels = {};\n data.pixels.numBlocksY = view.getUint32(0, true);\n data.pixels.numBlocksX = view.getUint32(4, true);\n data.pixels.numBytes = view.getUint32(8, true);\n data.pixels.maxValue = view.getFloat32(12, true);\n fp += 16;\n\n var numBlocksX = data.pixels.numBlocksX;\n var numBlocksY = data.pixels.numBlocksY;\n // the number of blocks specified in the header does not take into account the blocks at the end of\n // each row/column with a special width/height that make the image complete in case the width is not\n // evenly divisible by the number of blocks.\n var actualNumBlocksX = numBlocksX + ((data.width % numBlocksX) > 0 ? 1 : 0);\n var actualNumBlocksY = numBlocksY + ((data.height % numBlocksY) > 0 ? 1 : 0);\n data.pixels.blocks = new Array(actualNumBlocksX * actualNumBlocksY);\n var blockI = 0;\n for (var blockY = 0; blockY < actualNumBlocksY; blockY++) {\n for (var blockX = 0; blockX < actualNumBlocksX; blockX++) {\n\n // Block\n var size = 0;\n var bytesLeft = input.byteLength - fp;\n view = new DataView(input, fp, Math.min(10, bytesLeft));\n var block = {};\n data.pixels.blocks[blockI++] = block;\n var headerByte = view.getUint8(0); size++;\n block.encoding = headerByte & 63;\n if (block.encoding > 3) {\n throw \"Invalid block encoding (\" + block.encoding + \")\";\n }\n if (block.encoding === 2) {\n fp++;\n continue;\n }\n if ((headerByte !== 0) && (headerByte !== 2)) {\n headerByte >>= 6;\n block.offsetType = headerByte;\n if (headerByte === 2) {\n block.offset = view.getInt8(1); size++;\n } else if (headerByte === 1) {\n block.offset = view.getInt16(1, true); size += 2;\n } else if (headerByte === 0) {\n block.offset = view.getFloat32(1, true); size += 4;\n } else {\n throw \"Invalid block offset type\";\n }\n\n if (block.encoding === 1) {\n headerByte = view.getUint8(size); size++;\n block.bitsPerPixel = headerByte & 63;\n headerByte >>= 6;\n block.numValidPixelsType = headerByte;\n if (headerByte === 2) {\n block.numValidPixels = view.getUint8(size); size++;\n } else if (headerByte === 1) {\n block.numValidPixels = view.getUint16(size, true); size += 2;\n } else if (headerByte === 0) {\n block.numValidPixels = view.getUint32(size, true); size += 4;\n } else {\n throw \"Invalid valid pixel count type\";\n }\n }\n }\n fp += size;\n\n if (block.encoding === 3) {\n continue;\n }\n\n var arrayBuf, store8;\n if (block.encoding === 0) {\n var numPixels = (data.pixels.numBytes - 1) / 4;\n if (numPixels !== Math.floor(numPixels)) {\n throw \"uncompressed block has invalid length\";\n }\n arrayBuf = new ArrayBuffer(numPixels * 4);\n store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, fp, numPixels * 4));\n var rawData = new Float32Array(arrayBuf);\n block.rawData = rawData;\n fp += numPixels * 4;\n } else if (block.encoding === 1) {\n var dataBytes = Math.ceil(block.numValidPixels * block.bitsPerPixel / 8);\n var dataWords = Math.ceil(dataBytes / 4);\n arrayBuf = new ArrayBuffer(dataWords * 4);\n store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, fp, dataBytes));\n block.stuffedData = new Uint32Array(arrayBuf);\n fp += dataBytes;\n }\n }\n }\n data.eofOffset = fp;\n return data;\n };\n\n var unstuff = function(src, bitsPerPixel, numPixels, offset, scale, dest, maxValue) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o;\n var bitsLeft = 0;\n var n, buffer;\n var nmax = Math.ceil((maxValue - offset) / scale);\n // get rid of trailing bytes that are already part of next block\n var numInvalidTailBytes = src.length * 4 - Math.ceil(bitsPerPixel * numPixels / 8);\n src[src.length - 1] <<= 8 * numInvalidTailBytes;\n\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = (buffer >>> (bitsLeft - bitsPerPixel)) & bitMask;\n bitsLeft -= bitsPerPixel;\n } else {\n var missingBits = (bitsPerPixel - bitsLeft);\n n = ((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n += (buffer >>> bitsLeft);\n }\n //pixel values may exceed max due to quantization\n dest[o] = n < nmax ? offset + n * scale : maxValue;\n }\n return dest;\n };\n\n return CntZImage;\n })();\n\n //version 2. Supports 2.1, 2.2, 2.3\n var Lerc2Decode = (function() {\n \"use strict\";\n // Note: currently, this module only has an implementation for decoding LERC data, not encoding. The name of\n // the class was chosen to be future proof, following LercDecode.\n\n /*****************************************\n * private static class bitsutffer used by Lerc2Decode\n *******************************************/\n var BitStuffer = {\n //methods ending with 2 are for the new byte order used by Lerc2.3 and above.\n //originalUnstuff is used to unpack Huffman code table. code is duplicated to unstuffx for performance reasons.\n unstuff: function(src, dest, bitsPerPixel, numPixels, lutArr, offset, scale, maxValue) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o;\n var bitsLeft = 0;\n var n, buffer, missingBits, nmax;\n\n // get rid of trailing bytes that are already part of next block\n var numInvalidTailBytes = src.length * 4 - Math.ceil(bitsPerPixel * numPixels / 8);\n src[src.length - 1] <<= 8 * numInvalidTailBytes;\n if (lutArr) {\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = (buffer >>> (bitsLeft - bitsPerPixel)) & bitMask;\n bitsLeft -= bitsPerPixel;\n }\n else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = ((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n += (buffer >>> bitsLeft);\n }\n dest[o] = lutArr[n];//offset + lutArr[n] * scale;\n }\n }\n else {\n nmax = Math.ceil((maxValue - offset) / scale);\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = (buffer >>> (bitsLeft - bitsPerPixel)) & bitMask;\n bitsLeft -= bitsPerPixel;\n }\n else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = ((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n += (buffer >>> bitsLeft);\n }\n //pixel values may exceed max due to quantization\n dest[o] = n < nmax ? offset + n * scale : maxValue;\n }\n }\n },\n\n unstuffLUT: function(src, bitsPerPixel, numPixels, offset, scale, maxValue) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o = 0, missingBits = 0, bitsLeft = 0, n = 0;\n var buffer;\n var dest = [];\n\n // get rid of trailing bytes that are already part of next block\n var numInvalidTailBytes = src.length * 4 - Math.ceil(bitsPerPixel * numPixels / 8);\n src[src.length - 1] <<= 8 * numInvalidTailBytes;\n\n var nmax = Math.ceil((maxValue - offset) / scale);\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = (buffer >>> (bitsLeft - bitsPerPixel)) & bitMask;\n bitsLeft -= bitsPerPixel;\n } else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = ((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n += (buffer >>> bitsLeft);\n }\n //dest.push(n);\n dest[o] = n < nmax ? offset + n * scale : maxValue;\n }\n dest.unshift(offset);//1st one\n return dest;\n },\n\n unstuff2: function(src, dest, bitsPerPixel, numPixels, lutArr, offset, scale, maxValue) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o;\n var bitsLeft = 0, bitPos = 0;\n var n, buffer, missingBits;\n if (lutArr) {\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n bitPos = 0;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = ((buffer >>> bitPos) & bitMask);\n bitsLeft -= bitsPerPixel;\n bitPos += bitsPerPixel;\n } else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = (buffer >>> bitPos) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n |= (buffer & ((1 << missingBits) - 1)) << (bitsPerPixel - missingBits);\n bitPos = missingBits;\n }\n dest[o] = lutArr[n];\n }\n }\n else {\n var nmax = Math.ceil((maxValue - offset) / scale);\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n bitPos = 0;\n }\n if (bitsLeft >= bitsPerPixel) {\n //no unsigned left shift\n n = ((buffer >>> bitPos) & bitMask);\n bitsLeft -= bitsPerPixel;\n bitPos += bitsPerPixel;\n } else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = (buffer >>> bitPos) & bitMask;//((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n |= (buffer & ((1 << missingBits) - 1)) << (bitsPerPixel - missingBits);\n bitPos = missingBits;\n }\n //pixel values may exceed max due to quantization\n dest[o] = n < nmax ? offset + n * scale : maxValue;\n }\n }\n return dest;\n },\n\n unstuffLUT2: function(src, bitsPerPixel, numPixels, offset, scale, maxValue) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o = 0, missingBits = 0, bitsLeft = 0, n = 0, bitPos = 0;\n var buffer;\n var dest = [];\n var nmax = Math.ceil((maxValue - offset) / scale);\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n bitPos = 0;\n }\n if (bitsLeft >= bitsPerPixel) {\n //no unsigned left shift\n n = ((buffer >>> bitPos) & bitMask);\n bitsLeft -= bitsPerPixel;\n bitPos += bitsPerPixel;\n } else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = (buffer >>> bitPos) & bitMask;//((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n |= (buffer & ((1 << missingBits) - 1)) << (bitsPerPixel - missingBits);\n bitPos = missingBits;\n }\n //dest.push(n);\n dest[o] = n < nmax ? offset + n * scale : maxValue;\n }\n dest.unshift(offset);\n return dest;\n },\n\n originalUnstuff: function(src, dest, bitsPerPixel, numPixels) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o;\n var bitsLeft = 0;\n var n, buffer, missingBits;\n\n // get rid of trailing bytes that are already part of next block\n var numInvalidTailBytes = src.length * 4 - Math.ceil(bitsPerPixel * numPixels / 8);\n src[src.length - 1] <<= 8 * numInvalidTailBytes;\n\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n }\n if (bitsLeft >= bitsPerPixel) {\n n = (buffer >>> (bitsLeft - bitsPerPixel)) & bitMask;\n bitsLeft -= bitsPerPixel;\n }\n else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = ((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n += (buffer >>> bitsLeft);\n }\n dest[o] = n;\n }\n return dest;\n },\n\n originalUnstuff2: function(src, dest, bitsPerPixel, numPixels) {\n var bitMask = (1 << bitsPerPixel) - 1;\n var i = 0, o;\n var bitsLeft = 0, bitPos = 0;\n var n, buffer, missingBits;\n //micro-optimizations\n for (o = 0; o < numPixels; o++) {\n if (bitsLeft === 0) {\n buffer = src[i++];\n bitsLeft = 32;\n bitPos = 0;\n }\n if (bitsLeft >= bitsPerPixel) {\n //no unsigned left shift\n n = ((buffer >>> bitPos) & bitMask);\n bitsLeft -= bitsPerPixel;\n bitPos += bitsPerPixel;\n } else {\n missingBits = (bitsPerPixel - bitsLeft);\n n = (buffer >>> bitPos) & bitMask;//((buffer & bitMask) << missingBits) & bitMask;\n buffer = src[i++];\n bitsLeft = 32 - missingBits;\n n |= (buffer & ((1 << missingBits) - 1)) << (bitsPerPixel - missingBits);\n bitPos = missingBits;\n }\n dest[o] = n;\n }\n return dest;\n }\n };\n\n /*****************************************\n *private static class used by Lerc2Decode\n ******************************************/\n var Lerc2Helpers = {\n HUFFMAN_LUT_BITS_MAX: 12, //use 2^12 lut, treat it like constant\n computeChecksumFletcher32: function(input) {\n\n var sum1 = 0xffff, sum2 = 0xffff;\n var len = input.length;\n var words = Math.floor(len / 2);\n var i = 0;\n while (words) {\n var tlen = (words >= 359) ? 359 : words;\n words -= tlen;\n do {\n sum1 += (input[i++] << 8);\n sum2 += sum1 += input[i++];\n } while (--tlen);\n\n sum1 = (sum1 & 0xffff) + (sum1 >>> 16);\n sum2 = (sum2 & 0xffff) + (sum2 >>> 16);\n }\n\n // add the straggler byte if it exists\n if (len & 1) {\n sum2 += sum1 += (input[i] << 8);\n }\n // second reduction step to reduce sums to 16 bits\n sum1 = (sum1 & 0xffff) + (sum1 >>> 16);\n sum2 = (sum2 & 0xffff) + (sum2 >>> 16);\n\n return (sum2 << 16 | sum1) >>> 0;\n },\n\n readHeaderInfo: function(input, data) {\n var ptr = data.ptr;\n var fileIdView = new Uint8Array(input, ptr, 6);\n var headerInfo = {};\n headerInfo.fileIdentifierString = String.fromCharCode.apply(null, fileIdView);\n if (headerInfo.fileIdentifierString.lastIndexOf(\"Lerc2\", 0) !== 0) {\n throw \"Unexpected file identifier string (expect Lerc2 ): \" + headerInfo.fileIdentifierString;\n }\n ptr += 6;\n var view = new DataView(input, ptr, 8);\n var fileVersion = view.getInt32(0, true);\n headerInfo.fileVersion = fileVersion;\n ptr += 4;\n if (fileVersion >= 3) {\n headerInfo.checksum = view.getUint32(4, true); //nrows\n ptr += 4;\n }\n\n //keys start from here\n view = new DataView(input, ptr, 12);\n headerInfo.height = view.getUint32(0, true); //nrows\n headerInfo.width = view.getUint32(4, true); //ncols\n ptr += 8;\n if (fileVersion >= 4) {\n headerInfo.numDims = view.getUint32(8, true);\n ptr += 4;\n }\n else {\n headerInfo.numDims = 1;\n }\n\n view = new DataView(input, ptr, 40);\n headerInfo.numValidPixel = view.getUint32(0, true);\n headerInfo.microBlockSize = view.getInt32(4, true);\n headerInfo.blobSize = view.getInt32(8, true);\n headerInfo.imageType = view.getInt32(12, true);\n\n headerInfo.maxZError = view.getFloat64(16, true);\n headerInfo.zMin = view.getFloat64(24, true);\n headerInfo.zMax = view.getFloat64(32, true);\n ptr += 40;\n data.headerInfo = headerInfo;\n data.ptr = ptr;\n\n var checksum, keyLength;\n if (fileVersion >= 3) {\n keyLength = fileVersion >= 4 ? 52 : 48;\n checksum = this.computeChecksumFletcher32(new Uint8Array(input, ptr - keyLength, headerInfo.blobSize - 14));\n if (checksum !== headerInfo.checksum) {\n throw \"Checksum failed.\";\n }\n }\n return true;\n },\n\n checkMinMaxRanges: function(input, data) {\n var headerInfo = data.headerInfo;\n var OutPixelTypeArray = this.getDataTypeArray(headerInfo.imageType);\n var rangeBytes = headerInfo.numDims * this.getDataTypeSize(headerInfo.imageType);\n var minValues = this.readSubArray(input, data.ptr, OutPixelTypeArray, rangeBytes);\n var maxValues = this.readSubArray(input, data.ptr + rangeBytes, OutPixelTypeArray, rangeBytes);\n data.ptr += (2 * rangeBytes);\n var i, equal = true;\n for (i = 0; i < headerInfo.numDims; i++) {\n if (minValues[i] !== maxValues[i]) {\n equal = false;\n break;\n }\n }\n headerInfo.minValues = minValues;\n headerInfo.maxValues = maxValues;\n return equal;\n },\n\n readSubArray: function(input, ptr, OutPixelTypeArray, numBytes) {\n var rawData;\n if (OutPixelTypeArray === Uint8Array) {\n rawData = new Uint8Array(input, ptr, numBytes);\n }\n else {\n var arrayBuf = new ArrayBuffer(numBytes);\n var store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, ptr, numBytes));\n rawData = new OutPixelTypeArray(arrayBuf);\n }\n return rawData;\n },\n\n readMask: function(input, data) {\n var ptr = data.ptr;\n var headerInfo = data.headerInfo;\n var numPixels = headerInfo.width * headerInfo.height;\n var numValidPixel = headerInfo.numValidPixel;\n\n var view = new DataView(input, ptr, 4);\n var mask = {};\n mask.numBytes = view.getUint32(0, true);\n ptr += 4;\n\n // Mask Data\n if ((0 === numValidPixel || numPixels === numValidPixel) && 0 !== mask.numBytes) {\n throw (\"invalid mask\");\n }\n var bitset, resultMask;\n if (numValidPixel === 0) {\n bitset = new Uint8Array(Math.ceil(numPixels / 8));\n mask.bitset = bitset;\n resultMask = new Uint8Array(numPixels);\n data.pixels.resultMask = resultMask;\n ptr += mask.numBytes;\n }// ????? else if (data.mask.numBytes > 0 && data.mask.numBytes< data.numValidPixel) {\n else if (mask.numBytes > 0) {\n bitset = new Uint8Array(Math.ceil(numPixels / 8));\n view = new DataView(input, ptr, mask.numBytes);\n var cnt = view.getInt16(0, true);\n var ip = 2, op = 0, val = 0;\n do {\n if (cnt > 0) {\n while (cnt--) { bitset[op++] = view.getUint8(ip++); }\n } else {\n val = view.getUint8(ip++);\n cnt = -cnt;\n while (cnt--) { bitset[op++] = val; }\n }\n cnt = view.getInt16(ip, true);\n ip += 2;\n } while (ip < mask.numBytes);\n if ((cnt !== -32768) || (op < bitset.length)) {\n throw \"Unexpected end of mask RLE encoding\";\n }\n\n resultMask = new Uint8Array(numPixels);\n var mb = 0, k = 0;\n\n for (k = 0; k < numPixels; k++) {\n if (k & 7) {\n mb = bitset[k >> 3];\n mb <<= k & 7;\n }\n else {\n mb = bitset[k >> 3];\n }\n if (mb & 128) {\n resultMask[k] = 1;\n }\n }\n data.pixels.resultMask = resultMask;\n\n mask.bitset = bitset;\n ptr += mask.numBytes;\n }\n data.ptr = ptr;\n data.mask = mask;\n return true;\n },\n\n readDataOneSweep: function(input, data, OutPixelTypeArray) {\n var ptr = data.ptr;\n var headerInfo = data.headerInfo;\n var numDims = headerInfo.numDims;\n var numPixels = headerInfo.width * headerInfo.height;\n var imageType = headerInfo.imageType;\n var numBytes = headerInfo.numValidPixel * Lerc2Helpers.getDataTypeSize(imageType) * numDims;\n //data.pixels.numBytes = numBytes;\n var rawData;\n var mask = data.pixels.resultMask;\n if (OutPixelTypeArray === Uint8Array) {\n rawData = new Uint8Array(input, ptr, numBytes);\n }\n else {\n var arrayBuf = new ArrayBuffer(numBytes);\n var store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, ptr, numBytes));\n rawData = new OutPixelTypeArray(arrayBuf);\n }\n if (rawData.length === numPixels * numDims) {\n data.pixels.resultPixels = rawData;\n }\n else //mask\n {\n data.pixels.resultPixels = new OutPixelTypeArray(numPixels * numDims);\n var z = 0, k = 0, i = 0, nStart = 0;\n if (numDims > 1) {\n for (i=0; i < numDims; i++) {\n nStart = i * numPixels;\n for (k = 0; k < numPixels; k++) {\n if (mask[k]) {\n data.pixels.resultPixels[nStart + k] = rawData[z++];\n }\n }\n }\n }\n else {\n for (k = 0; k < numPixels; k++) {\n if (mask[k]) {\n data.pixels.resultPixels[k] = rawData[z++];\n }\n }\n }\n }\n ptr += numBytes;\n data.ptr = ptr; //return data;\n return true;\n },\n\n readHuffmanTree: function(input, data) {\n var BITS_MAX = this.HUFFMAN_LUT_BITS_MAX; //8 is slow for the large test image\n //var size_max = 1 << BITS_MAX;\n /* ************************\n * reading code table\n *************************/\n var view = new DataView(input, data.ptr, 16);\n data.ptr += 16;\n var version = view.getInt32(0, true);\n if (version < 2) {\n throw \"unsupported Huffman version\";\n }\n var size = view.getInt32(4, true);\n var i0 = view.getInt32(8, true);\n var i1 = view.getInt32(12, true);\n if (i0 >= i1) {\n return false;\n }\n var blockDataBuffer = new Uint32Array(i1 - i0);\n Lerc2Helpers.decodeBits(input, data, blockDataBuffer);\n var codeTable = []; //size\n var i, j, k, len;\n\n for (i = i0; i < i1; i++) {\n j = i - (i < size ? 0 : size);//wrap around\n codeTable[j] = { first: blockDataBuffer[i - i0], second: null };\n }\n\n var dataBytes = input.byteLength - data.ptr;\n var dataWords = Math.ceil(dataBytes / 4);\n var arrayBuf = new ArrayBuffer(dataWords * 4);\n var store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, data.ptr, dataBytes));\n var stuffedData = new Uint32Array(arrayBuf); //must start from x*4\n var bitPos = 0, word, srcPtr = 0;\n word = stuffedData[0];\n for (i = i0; i < i1; i++) {\n j = i - (i < size ? 0 : size);//wrap around\n len = codeTable[j].first;\n if (len > 0) {\n codeTable[j].second = (word << bitPos) >>> (32 - len);\n\n if (32 - bitPos >= len) {\n bitPos += len;\n if (bitPos === 32) {\n bitPos = 0;\n srcPtr++;\n word = stuffedData[srcPtr];\n }\n }\n else {\n bitPos += len - 32;\n srcPtr++;\n word = stuffedData[srcPtr];\n codeTable[j].second |= word >>> (32 - bitPos);\n }\n }\n }\n\n //finished reading code table\n\n /* ************************\n * building lut\n *************************/\n var numBitsLUT = 0, numBitsLUTQick = 0;\n var tree = new TreeNode();\n for (i = 0; i < codeTable.length; i++) {\n if (codeTable[i] !== undefined) {\n numBitsLUT = Math.max(numBitsLUT, codeTable[i].first);\n }\n }\n if (numBitsLUT >= BITS_MAX) {\n numBitsLUTQick = BITS_MAX;\n }\n else {\n numBitsLUTQick = numBitsLUT;\n }\n if (numBitsLUT >= 30) {\n console.log(\"WARning, large NUM LUT BITS IS \" + numBitsLUT);\n }\n var decodeLut = [], entry, code, numEntries, jj, currentBit, node;\n for (i = i0; i < i1; i++) {\n j = i - (i < size ? 0 : size);//wrap around\n len = codeTable[j].first;\n if (len > 0) {\n entry = [len, j];\n if (len <= numBitsLUTQick) {\n code = codeTable[j].second << (numBitsLUTQick - len);\n numEntries = 1 << (numBitsLUTQick - len);\n for (k = 0; k < numEntries; k++) {\n decodeLut[code | k] = entry;\n }\n }\n else {\n //build tree\n code = codeTable[j].second;\n node = tree;\n for (jj = len - 1; jj >= 0; jj--) {\n currentBit = code >>> jj & 1; //no left shift as length could be 30,31\n if (currentBit) {\n if (!node.right) {\n node.right = new TreeNode();\n }\n node = node.right;\n }\n else {\n if (!node.left) {\n node.left = new TreeNode();\n }\n node = node.left;\n }\n if (jj === 0 && !node.val) {\n node.val = entry[1];\n }\n }\n }\n }\n }\n return {\n decodeLut: decodeLut,\n numBitsLUTQick: numBitsLUTQick,\n numBitsLUT: numBitsLUT,\n tree: tree,\n stuffedData: stuffedData,\n srcPtr: srcPtr,\n bitPos: bitPos\n };\n },\n\n readHuffman: function(input, data, OutPixelTypeArray) {\n var headerInfo = data.headerInfo;\n var numDims = headerInfo.numDims;\n var height = data.headerInfo.height;\n var width = data.headerInfo.width;\n var numPixels = width * height;\n //var size_max = 1 << BITS_MAX;\n /* ************************\n * reading huffman structure info\n *************************/\n var huffmanInfo = this.readHuffmanTree(input, data);\n var decodeLut = huffmanInfo.decodeLut;\n var tree = huffmanInfo.tree;\n //stuffedData includes huffman headers\n var stuffedData = huffmanInfo.stuffedData;\n var srcPtr = huffmanInfo.srcPtr;\n var bitPos = huffmanInfo.bitPos;\n var numBitsLUTQick = huffmanInfo.numBitsLUTQick;\n var numBitsLUT = huffmanInfo.numBitsLUT;\n var offset = data.headerInfo.imageType === 0 ? 128 : 0;\n /*************************\n * decode\n ***************************/\n var node, val, delta, mask = data.pixels.resultMask, valTmp, valTmpQuick, currentBit;\n var i, j, k, ii;\n var prevVal = 0;\n if (bitPos > 0) {\n srcPtr++;\n bitPos = 0;\n }\n var word = stuffedData[srcPtr];\n var deltaEncode = data.encodeMode === 1;\n var resultPixelsAllDim = new OutPixelTypeArray(numPixels * numDims);\n var resultPixels = resultPixelsAllDim;\n var iDim;\n for (iDim = 0; iDim < headerInfo.numDims; iDim++) {\n if (numDims > 1) {\n //get the mem block of current dimension\n resultPixels = new OutPixelTypeArray(resultPixelsAllDim.buffer, numPixels * iDim, numPixels);\n prevVal = 0;\n }\n if (data.headerInfo.numValidPixel === width * height) { //all valid\n for (k = 0, i = 0; i < height; i++) {\n for (j = 0; j < width; j++, k++) {\n val = 0;\n valTmp = (word << bitPos) >>> (32 - numBitsLUTQick);\n valTmpQuick = valTmp;// >>> deltaBits;\n if (32 - bitPos < numBitsLUTQick) {\n valTmp |= ((stuffedData[srcPtr + 1]) >>> (64 - bitPos - numBitsLUTQick));\n valTmpQuick = valTmp;// >>> deltaBits;\n }\n if (decodeLut[valTmpQuick]) // if there, move the correct number of bits and done\n {\n val = decodeLut[valTmpQuick][1];\n bitPos += decodeLut[valTmpQuick][0];\n }\n else {\n valTmp = (word << bitPos) >>> (32 - numBitsLUT);\n valTmpQuick = valTmp;// >>> deltaBits;\n if (32 - bitPos < numBitsLUT) {\n valTmp |= ((stuffedData[srcPtr + 1]) >>> (64 - bitPos - numBitsLUT));\n valTmpQuick = valTmp;// >>> deltaBits;\n }\n node = tree;\n for (ii = 0; ii < numBitsLUT; ii++) {\n currentBit = valTmp >>> (numBitsLUT - ii - 1) & 1;\n node = currentBit ? node.right : node.left;\n if (!(node.left || node.right)) {\n val = node.val;\n bitPos = bitPos + ii + 1;\n break;\n }\n }\n }\n\n if (bitPos >= 32) {\n bitPos -= 32;\n srcPtr++;\n word = stuffedData[srcPtr];\n }\n\n delta = val - offset;\n if (deltaEncode) {\n if (j > 0) {\n delta += prevVal; // use overflow\n }\n else if (i > 0) {\n delta += resultPixels[k - width];\n }\n else {\n delta += prevVal;\n }\n delta &= 0xFF; //overflow\n resultPixels[k] = delta;//overflow\n prevVal = delta;\n }\n else {\n resultPixels[k] = delta;\n }\n }\n }\n }\n else { //not all valid, use mask\n for (k = 0, i = 0; i < height; i++) {\n for (j = 0; j < width; j++, k++) {\n if (mask[k]) {\n val = 0;\n valTmp = (word << bitPos) >>> (32 - numBitsLUTQick);\n valTmpQuick = valTmp;// >>> deltaBits;\n if (32 - bitPos < numBitsLUTQick) {\n valTmp |= ((stuffedData[srcPtr + 1]) >>> (64 - bitPos - numBitsLUTQick));\n valTmpQuick = valTmp;// >>> deltaBits;\n }\n if (decodeLut[valTmpQuick]) // if there, move the correct number of bits and done\n {\n val = decodeLut[valTmpQuick][1];\n bitPos += decodeLut[valTmpQuick][0];\n }\n else {\n valTmp = (word << bitPos) >>> (32 - numBitsLUT);\n valTmpQuick = valTmp;// >>> deltaBits;\n if (32 - bitPos < numBitsLUT) {\n valTmp |= ((stuffedData[srcPtr + 1]) >>> (64 - bitPos - numBitsLUT));\n valTmpQuick = valTmp;// >>> deltaBits;\n }\n node = tree;\n for (ii = 0; ii < numBitsLUT; ii++) {\n currentBit = valTmp >>> (numBitsLUT - ii - 1) & 1;\n node = currentBit ? node.right : node.left;\n if (!(node.left || node.right)) {\n val = node.val;\n bitPos = bitPos + ii + 1;\n break;\n }\n }\n }\n\n if (bitPos >= 32) {\n bitPos -= 32;\n srcPtr++;\n word = stuffedData[srcPtr];\n }\n\n delta = val - offset;\n if (deltaEncode) {\n if (j > 0 && mask[k - 1]) {\n delta += prevVal; // use overflow\n }\n else if (i > 0 && mask[k - width]) {\n delta += resultPixels[k - width];\n }\n else {\n delta += prevVal;\n }\n\n delta &= 0xFF; //overflow\n resultPixels[k] = delta;//overflow\n prevVal = delta;\n }\n else {\n resultPixels[k] = delta;\n }\n }\n }\n }\n }\n data.ptr = data.ptr + (srcPtr + 1) * 4 + (bitPos > 0 ? 4 : 0);\n }\n data.pixels.resultPixels = resultPixelsAllDim;\n },\n\n decodeBits: function(input, data, blockDataBuffer, offset, iDim) {\n {\n //bitstuff encoding is 3\n var headerInfo = data.headerInfo;\n var fileVersion = headerInfo.fileVersion;\n //var block = {};\n var blockPtr = 0;\n var view = new DataView(input, data.ptr, 5);//to do\n var headerByte = view.getUint8(0);\n blockPtr++;\n var bits67 = headerByte >> 6;\n var n = (bits67 === 0) ? 4 : 3 - bits67;\n var doLut = (headerByte & 32) > 0 ? true : false;//5th bit\n var numBits = headerByte & 31;\n var numElements = 0;\n if (n === 1) {\n numElements = view.getUint8(blockPtr); blockPtr++;\n } else if (n === 2) {\n numElements = view.getUint16(blockPtr, true); blockPtr += 2;\n } else if (n === 4) {\n numElements = view.getUint32(blockPtr, true); blockPtr += 4;\n } else {\n throw \"Invalid valid pixel count type\";\n }\n //fix: huffman codes are bit stuffed, but not bound by data's max value, so need to use originalUnstuff\n //offset = offset || 0;\n var scale = 2 * headerInfo.maxZError;\n var stuffedData, arrayBuf, store8, dataBytes, dataWords;\n var lutArr, lutData, lutBytes, lutBitsPerElement, bitsPerPixel;\n var zMax = headerInfo.numDims > 1 ? headerInfo.maxValues[iDim] : headerInfo.zMax;\n if (doLut) {\n data.counter.lut++;\n lutBytes = view.getUint8(blockPtr);\n lutBitsPerElement = numBits;\n blockPtr++;\n dataBytes = Math.ceil((lutBytes - 1) * numBits / 8);\n dataWords = Math.ceil(dataBytes / 4);\n arrayBuf = new ArrayBuffer(dataWords * 4);\n store8 = new Uint8Array(arrayBuf);\n\n data.ptr += blockPtr;\n store8.set(new Uint8Array(input, data.ptr, dataBytes));\n\n lutData = new Uint32Array(arrayBuf);\n data.ptr += dataBytes;\n\n bitsPerPixel = 0;\n while ((lutBytes - 1) >>> bitsPerPixel) {\n bitsPerPixel++;\n }\n dataBytes = Math.ceil(numElements * bitsPerPixel / 8);\n dataWords = Math.ceil(dataBytes / 4);\n arrayBuf = new ArrayBuffer(dataWords * 4);\n store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, data.ptr, dataBytes));\n stuffedData = new Uint32Array(arrayBuf);\n data.ptr += dataBytes;\n if (fileVersion >= 3) {\n lutArr = BitStuffer.unstuffLUT2(lutData, numBits, lutBytes - 1, offset, scale, zMax);\n }\n else {\n lutArr = BitStuffer.unstuffLUT(lutData, numBits, lutBytes - 1, offset, scale, zMax);\n }\n //lutArr.unshift(0);\n if (fileVersion >= 3) {\n //BitStuffer.unstuff2(block, blockDataBuffer, headerInfo.zMax);\n BitStuffer.unstuff2(stuffedData, blockDataBuffer, bitsPerPixel, numElements, lutArr);\n }\n else {\n BitStuffer.unstuff(stuffedData, blockDataBuffer, bitsPerPixel, numElements, lutArr);\n }\n }\n else {\n //console.debug(\"bitstuffer\");\n data.counter.bitstuffer++;\n bitsPerPixel = numBits;\n data.ptr += blockPtr;\n if (bitsPerPixel > 0) {\n dataBytes = Math.ceil(numElements * bitsPerPixel / 8);\n dataWords = Math.ceil(dataBytes / 4);\n arrayBuf = new ArrayBuffer(dataWords * 4);\n store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, data.ptr, dataBytes));\n stuffedData = new Uint32Array(arrayBuf);\n data.ptr += dataBytes;\n if (fileVersion >= 3) {\n if (offset == null) {\n BitStuffer.originalUnstuff2(stuffedData, blockDataBuffer, bitsPerPixel, numElements);\n }\n else {\n BitStuffer.unstuff2(stuffedData, blockDataBuffer, bitsPerPixel, numElements, false, offset, scale, zMax);\n }\n }\n else {\n if (offset == null) {\n BitStuffer.originalUnstuff(stuffedData, blockDataBuffer, bitsPerPixel, numElements);\n }\n else {\n BitStuffer.unstuff(stuffedData, blockDataBuffer, bitsPerPixel, numElements, false, offset, scale, zMax);\n }\n }\n }\n }\n }\n\n },\n\n readTiles: function(input, data, OutPixelTypeArray) {\n var headerInfo = data.headerInfo;\n var width = headerInfo.width;\n var height = headerInfo.height;\n var microBlockSize = headerInfo.microBlockSize;\n var imageType = headerInfo.imageType;\n var dataTypeSize = Lerc2Helpers.getDataTypeSize(imageType);\n var numBlocksX = Math.ceil(width / microBlockSize);\n var numBlocksY = Math.ceil(height / microBlockSize);\n data.pixels.numBlocksY = numBlocksY;\n data.pixels.numBlocksX = numBlocksX;\n data.pixels.ptr = 0;\n var row = 0, col = 0, blockY = 0, blockX = 0, thisBlockHeight = 0, thisBlockWidth = 0, bytesLeft = 0, headerByte = 0, bits67 = 0, testCode = 0, outPtr = 0, outStride = 0, numBytes = 0, bytesleft = 0, z = 0, blockPtr = 0;\n var view, block, arrayBuf, store8, rawData;\n var blockEncoding;\n var blockDataBuffer = new OutPixelTypeArray(microBlockSize * microBlockSize);\n var lastBlockHeight = (height % microBlockSize) || microBlockSize;\n var lastBlockWidth = (width % microBlockSize) || microBlockSize;\n var offsetType, offset;\n var numDims = headerInfo.numDims, iDim;\n var mask = data.pixels.resultMask;\n var resultPixels = data.pixels.resultPixels;\n for (blockY = 0; blockY < numBlocksY; blockY++) {\n thisBlockHeight = (blockY !== numBlocksY - 1) ? microBlockSize : lastBlockHeight;\n for (blockX = 0; blockX < numBlocksX; blockX++) {\n //console.debug(\"y\" + blockY + \" x\" + blockX);\n thisBlockWidth = (blockX !== numBlocksX - 1) ? microBlockSize : lastBlockWidth;\n\n outPtr = blockY * width * microBlockSize + blockX * microBlockSize;\n outStride = width - thisBlockWidth;\n\n\n for (iDim = 0; iDim < numDims; iDim++) {\n if (numDims > 1) {\n resultPixels = new OutPixelTypeArray(data.pixels.resultPixels.buffer, width * height * iDim * dataTypeSize, width * height);\n }\n bytesLeft = input.byteLength - data.ptr;\n view = new DataView(input, data.ptr, Math.min(10, bytesLeft));\n block = {};\n blockPtr = 0;\n headerByte = view.getUint8(0);\n blockPtr++;\n bits67 = (headerByte >> 6) & 0xFF;\n testCode = (headerByte >> 2) & 15; // use bits 2345 for integrity check\n if (testCode !== (((blockX * microBlockSize) >> 3) & 15)) {\n throw \"integrity issue\";\n //return false;\n }\n\n blockEncoding = headerByte & 3;\n if (blockEncoding > 3) {\n data.ptr += blockPtr;\n throw \"Invalid block encoding (\" + blockEncoding + \")\";\n }\n else if (blockEncoding === 2) { //constant 0\n data.counter.constant++;\n data.ptr += blockPtr;\n continue;\n }\n else if (blockEncoding === 0) { //uncompressed\n data.counter.uncompressed++;\n data.ptr += blockPtr;\n numBytes = thisBlockHeight * thisBlockWidth * dataTypeSize;\n bytesleft = input.byteLength - data.ptr;\n numBytes = numBytes < bytesleft ? numBytes : bytesleft;\n //bit alignment\n arrayBuf = new ArrayBuffer((numBytes % dataTypeSize) === 0 ? numBytes : (numBytes + dataTypeSize - numBytes % dataTypeSize));\n store8 = new Uint8Array(arrayBuf);\n store8.set(new Uint8Array(input, data.ptr, numBytes));\n rawData = new OutPixelTypeArray(arrayBuf);\n z = 0;\n if (mask) {\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n if (mask[outPtr]) {\n resultPixels[outPtr] = rawData[z++];\n }\n outPtr++;\n }\n outPtr += outStride;\n }\n }\n else {//all valid\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n resultPixels[outPtr++] = rawData[z++];\n }\n outPtr += outStride;\n }\n }\n data.ptr += z * dataTypeSize;\n }\n else { //1 or 3\n offsetType = Lerc2Helpers.getDataTypeUsed(imageType, bits67);\n offset = Lerc2Helpers.getOnePixel(block, blockPtr, offsetType, view);\n blockPtr += Lerc2Helpers.getDataTypeSize(offsetType);\n if (blockEncoding === 3) //constant offset value\n {\n data.ptr += blockPtr;\n data.counter.constantoffset++;\n //you can delete the following resultMask case in favor of performance because val is constant and users use nodata mask, otherwise nodatavalue post processing handles it too.\n //while the above statement is true, we're not doing it as we want to keep invalid pixel value at 0 rather than arbitrary values\n if (mask) {\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n if (mask[outPtr]) {\n resultPixels[outPtr] = offset;\n }\n outPtr++;\n }\n outPtr += outStride;\n }\n }\n else {\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n resultPixels[outPtr++] = offset;\n }\n outPtr += outStride;\n }\n }\n }\n else { //bitstuff encoding is 3\n data.ptr += blockPtr;\n //heavy lifting\n Lerc2Helpers.decodeBits(input, data, blockDataBuffer, offset, iDim);\n blockPtr = 0;\n if (mask) {\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n if (mask[outPtr]) {\n resultPixels[outPtr] = blockDataBuffer[blockPtr++];\n }\n outPtr++;\n }\n outPtr += outStride;\n }\n }\n else {\n for (row = 0; row < thisBlockHeight; row++) {\n for (col = 0; col < thisBlockWidth; col++) {\n resultPixels[outPtr++] = blockDataBuffer[blockPtr++];\n }\n outPtr += outStride;\n }\n }\n }\n }\n }\n }\n }\n },\n\n /*****************\n * private methods (helper methods)\n *****************/\n\n formatFileInfo: function(data) {\n return {\n \"fileIdentifierString\": data.headerInfo.fileIdentifierString,\n \"fileVersion\": data.headerInfo.fileVersion,\n \"imageType\": data.headerInfo.imageType,\n \"height\": data.headerInfo.height,\n \"width\": data.headerInfo.width,\n \"numValidPixel\": data.headerInfo.numValidPixel,\n \"microBlockSize\": data.headerInfo.microBlockSize,\n \"blobSize\": data.headerInfo.blobSize,\n \"maxZError\": data.headerInfo.maxZError,\n \"pixelType\": Lerc2Helpers.getPixelType(data.headerInfo.imageType),\n \"eofOffset\": data.eofOffset,\n \"mask\": data.mask ? {\n \"numBytes\": data.mask.numBytes\n } : null,\n \"pixels\": {\n \"numBlocksX\": data.pixels.numBlocksX,\n \"numBlocksY\": data.pixels.numBlocksY,\n //\"numBytes\": data.pixels.numBytes,\n \"maxValue\": data.headerInfo.zMax,\n \"minValue\": data.headerInfo.zMin,\n \"noDataValue\": data.noDataValue\n }\n };\n },\n\n constructConstantSurface: function(data) {\n var val = data.headerInfo.zMax;\n var numDims = data.headerInfo.numDims;\n var numPixels = data.headerInfo.height * data.headerInfo.width;\n var numPixelAllDims = numPixels * numDims;\n var i=0, k = 0, nStart=0;\n var mask = data.pixels.resultMask;\n if (mask) {\n if (numDims > 1) {\n for (i=0; i < numDims; i++) {\n nStart = i * numPixels;\n for (k = 0; k < numPixels; k++) {\n if (mask[k]) {\n data.pixels.resultPixels[nStart + k] = val;\n }\n }\n }\n }\n else {\n for (k = 0; k < numPixels; k++) {\n if (mask[k]) {\n data.pixels.resultPixels[k] = val;\n }\n }\n }\n }\n else {\n if (data.pixels.resultPixels.fill) {\n data.pixels.resultPixels.fill(val);\n }\n else {\n for (k = 0; k < numPixelAllDims; k++) {\n data.pixels.resultPixels[k] = val;\n }\n }\n }\n return;\n },\n\n getDataTypeArray: function(t) {\n var tp;\n switch (t) {\n case 0: //char\n tp = Int8Array;\n break;\n case 1: //byte\n tp = Uint8Array;\n break;\n case 2: //short\n tp = Int16Array;\n break;\n case 3: //ushort\n tp = Uint16Array;\n break;\n case 4:\n tp = Int32Array;\n break;\n case 5:\n tp = Uint32Array;\n break;\n case 6:\n tp = Float32Array;\n break;\n case 7:\n tp = Float64Array;\n break;\n default:\n tp = Float32Array;\n }\n return tp;\n },\n\n getPixelType: function(t) {\n var tp;\n switch (t) {\n case 0: //char\n tp = \"S8\";\n break;\n case 1: //byte\n tp = \"U8\";\n break;\n case 2: //short\n tp = \"S16\";\n break;\n case 3: //ushort\n tp = \"U16\";\n break;\n case 4:\n tp = \"S32\";\n break;\n case 5:\n tp = \"U32\";\n break;\n case 6:\n tp = \"F32\";\n break;\n case 7:\n tp = \"F64\"; //not supported\n break;\n default:\n tp = \"F32\";\n }\n return tp;\n },\n\n isValidPixelValue: function(t, val) {\n if (val == null) {\n return false;\n }\n var isValid;\n switch (t) {\n case 0: //char\n isValid = val >= -128 && val <= 127;\n break;\n case 1: //byte (unsigned char)\n isValid = val >= 0 && val <= 255;\n break;\n case 2: //short\n isValid = val >= -32768 && val <= 32767;\n break;\n case 3: //ushort\n isValid = val >= 0 && val <= 65536;\n break;\n case 4: //int 32\n isValid = val >= -2147483648 && val <= 2147483647;\n break;\n case 5: //uinit 32\n isValid = val >= 0 && val <= 4294967296;\n break;\n case 6:\n isValid = val >= -3.4027999387901484e+38 && val <= 3.4027999387901484e+38;\n break;\n case 7:\n isValid = val >= 5e-324 && val <= 1.7976931348623157e+308;\n break;\n default:\n isValid = false;\n }\n return isValid;\n },\n\n getDataTypeSize: function(t) {\n var s = 0;\n switch (t) {\n case 0: //ubyte\n case 1: //byte\n s = 1;\n break;\n case 2: //short\n case 3: //ushort\n s = 2;\n break;\n case 4:\n case 5:\n case 6:\n s = 4;\n break;\n case 7:\n s = 8;\n break;\n default:\n s = t;\n }\n return s;\n },\n\n getDataTypeUsed: function(dt, tc) {\n var t = dt;\n switch (dt) {\n case 2: //short\n case 4: //long\n t = dt - tc;\n break;\n case 3: //ushort\n case 5: //ulong\n t = dt - 2 * tc;\n break;\n case 6: //float\n if (0 === tc) {\n t = dt;\n }\n else if (1 === tc) {\n t = 2;\n }\n else {\n t = 1;//byte\n }\n break;\n case 7: //double\n if (0 === tc) {\n t = dt;\n }\n else {\n t = dt - 2 * tc + 1;\n }\n break;\n default:\n t = dt;\n break;\n }\n return t;\n },\n\n getOnePixel: function(block, blockPtr, offsetType, view) {\n var temp = 0;\n switch (offsetType) {\n case 0: //char\n temp = view.getInt8(blockPtr);\n break;\n case 1: //byte\n temp = view.getUint8(blockPtr);\n break;\n case 2:\n temp = view.getInt16(blockPtr, true);\n break;\n case 3:\n temp = view.getUint16(blockPtr, true);\n break;\n case 4:\n temp = view.getInt32(blockPtr, true);\n break;\n case 5:\n temp = view.getUInt32(blockPtr, true);\n break;\n case 6:\n temp = view.getFloat32(blockPtr, true);\n break;\n case 7:\n //temp = view.getFloat64(blockPtr, true);\n //blockPtr += 8;\n //lerc2 encoding doesnt handle float 64, force to float32???\n temp = view.getFloat64(blockPtr, true);\n break;\n default:\n throw (\"the decoder does not understand this pixel type\");\n }\n return temp;\n }\n };\n\n /***************************************************\n *private class for a tree node. Huffman code is in Lerc2Helpers\n ****************************************************/\n var TreeNode = function(val, left, right) {\n this.val = val;\n this.left = left;\n this.right = right;\n };\n\n var Lerc2Decode = {\n /*\n * ********removed options compared to LERC1. We can bring some of them back if needed.\n * removed pixel type. LERC2 is typed and doesn't require user to give pixel type\n * changed encodedMaskData to maskData. LERC2 's js version make it faster to use maskData directly.\n * removed returnMask. mask is used by LERC2 internally and is cost free. In case of user input mask, it's returned as well and has neglible cost.\n * removed nodatavalue. Because LERC2 pixels are typed, nodatavalue will sacrify a useful value for many types (8bit, 16bit) etc,\n * user has to be knowledgable enough about raster and their data to avoid usability issues. so nodata value is simply removed now.\n * We can add it back later if their's a clear requirement.\n * removed encodedMask. This option was not implemented in LercDecode. It can be done after decoding (less efficient)\n * removed computeUsedBitDepths.\n *\n *\n * response changes compared to LERC1\n * 1. encodedMaskData is not available\n * 2. noDataValue is optional (returns only if user's noDataValue is with in the valid data type range)\n * 3. maskData is always available\n */\n /*****************\n * public properties\n ******************/\n //HUFFMAN_LUT_BITS_MAX: 12, //use 2^12 lut, not configurable\n\n /*****************\n * public methods\n *****************/\n\n /**\n * Decode a LERC2 byte stream and return an object containing the pixel data and optional metadata.\n *\n * @param {ArrayBuffer} input The LERC input byte stream\n * @param {object} [options] options Decoding options\n * @param {number} [options.inputOffset] The number of bytes to skip in the input byte stream. A valid LERC file is expected at that position\n * @param {boolean} [options.returnFileInfo] If true, the return value will have a fileInfo property that contains metadata obtained from the LERC headers and the decoding process\n */\n decode: function(/*byte array*/ input, /*object*/ options) {\n //currently there's a bug in the sparse array, so please do not set to false\n options = options || {};\n var noDataValue = options.noDataValue;\n\n //initialize\n var i = 0, data = {};\n data.ptr = options.inputOffset || 0;\n data.pixels = {};\n\n // File header\n if (!Lerc2Helpers.readHeaderInfo(input, data)) {\n return;\n }\n var headerInfo = data.headerInfo;\n var fileVersion = headerInfo.fileVersion;\n var OutPixelTypeArray = Lerc2Helpers.getDataTypeArray(headerInfo.imageType);\n\n // Mask Header\n Lerc2Helpers.readMask(input, data);\n if (headerInfo.numValidPixel !== headerInfo.width * headerInfo.height && !data.pixels.resultMask) {\n data.pixels.resultMask = options.maskData;\n }\n\n var numPixels = headerInfo.width * headerInfo.height;\n data.pixels.resultPixels = new OutPixelTypeArray(numPixels * headerInfo.numDims);\n\n data.counter = {\n onesweep: 0,\n uncompressed: 0,\n lut: 0,\n bitstuffer: 0,\n constant: 0,\n constantoffset: 0\n };\n if (headerInfo.numValidPixel !== 0) {\n //not tested\n if (headerInfo.zMax === headerInfo.zMin) //constant surface\n {\n Lerc2Helpers.constructConstantSurface(data);\n }\n else if (fileVersion >= 4 && Lerc2Helpers.checkMinMaxRanges(input, data)) {\n Lerc2Helpers.constructConstantSurface(data);\n }\n else {\n var view = new DataView(input, data.ptr, 2);\n var bReadDataOneSweep = view.getUint8(0);\n data.ptr++;\n if (bReadDataOneSweep) {\n //console.debug(\"OneSweep\");\n Lerc2Helpers.readDataOneSweep(input, data, OutPixelTypeArray);\n }\n else {\n //lerc2.1: //bitstuffing + lut\n //lerc2.2: //bitstuffing + lut + huffman\n //lerc2.3: new bitstuffer\n if (fileVersion > 1 && headerInfo.imageType <= 1 && Math.abs(headerInfo.maxZError - 0.5) < 0.00001) {\n //this is 2.x plus 8 bit (unsigned and signed) data, possiblity of Huffman\n var flagHuffman = view.getUint8(1);\n data.ptr++;\n data.encodeMode = flagHuffman;\n if (flagHuffman > 2 || (fileVersion < 4 && flagHuffman > 1)) {\n throw \"Invalid Huffman flag \" + flagHuffman;\n }\n if (flagHuffman) {//1 - delta Huffman, 2 - Huffman\n //console.log(\"Huffman\");\n Lerc2Helpers.readHuffman(input, data, OutPixelTypeArray);\n }\n else {\n //console.log(\"Tiles\");\n Lerc2Helpers.readTiles(input, data, OutPixelTypeArray);\n }\n }\n else { //lerc2.x non-8 bit data\n //console.log(\"Tiles\");\n Lerc2Helpers.readTiles(input, data, OutPixelTypeArray);\n }\n }\n }\n }\n\n data.eofOffset = data.ptr;\n var diff;\n if (options.inputOffset) {\n diff = data.headerInfo.blobSize + options.inputOffset - data.ptr;\n if (Math.abs(diff) >= 1) {\n //console.debug(\"incorrect eof: dataptr \" + data.ptr + \" offset \" + options.inputOffset + \" blobsize \" + data.headerInfo.blobSize + \" diff: \" + diff);\n data.eofOffset = options.inputOffset + data.headerInfo.blobSize;\n }\n }\n else {\n diff = data.headerInfo.blobSize - data.ptr;\n if (Math.abs(diff) >= 1) {\n //console.debug(\"incorrect first band eof: dataptr \" + data.ptr + \" blobsize \" + data.headerInfo.blobSize + \" diff: \" + diff);\n data.eofOffset = data.headerInfo.blobSize;\n }\n }\n\n var result = {\n width: headerInfo.width,\n height: headerInfo.height,\n pixelData: data.pixels.resultPixels,\n minValue: headerInfo.zMin,\n maxValue: headerInfo.zMax,\n validPixelCount: headerInfo.numValidPixel,\n dimCount: headerInfo.numDims,\n dimStats: {\n minValues: headerInfo.minValues,\n maxValues: headerInfo.maxValues\n },\n maskData: data.pixels.resultMask\n //noDataValue: noDataValue\n };\n\n //we should remove this if there's no existing client\n //optional noDataValue processing, it's user's responsiblity\n if (data.pixels.resultMask && Lerc2Helpers.isValidPixelValue(headerInfo.imageType, noDataValue)) {\n var mask = data.pixels.resultMask;\n for (i = 0; i < numPixels; i++) {\n if (!mask[i]) {\n result.pixelData[i] = noDataValue;\n }\n }\n result.noDataValue = noDataValue;\n }\n data.noDataValue = noDataValue;\n if (options.returnFileInfo) {\n result.fileInfo = Lerc2Helpers.formatFileInfo(data);\n }\n return result;\n },\n\n getBandCount: function(/*byte array*/ input) {\n var count = 0;\n var i = 0;\n var temp = {};\n temp.ptr = 0;\n temp.pixels = {};\n while (i < input.byteLength - 58) {\n Lerc2Helpers.readHeaderInfo(input, temp);\n i += temp.headerInfo.blobSize;\n count++;\n temp.ptr = i;\n }\n return count;\n }\n };\n\n return Lerc2Decode;\n })();\n\n var isPlatformLittleEndian = (function() {\n var a = new ArrayBuffer(4);\n var b = new Uint8Array(a);\n var c = new Uint32Array(a);\n c[0] = 1;\n return b[0] === 1;\n })();\n\n var Lerc = {\n /************wrapper**********************************************/\n /**\n * A wrapper for decoding both LERC1 and LERC2 byte streams capable of handling multiband pixel blocks for various pixel types.\n *\n * @alias module:Lerc\n * @param {ArrayBuffer} input The LERC input byte stream\n * @param {object} [options] The decoding options below are optional.\n * @param {number} [options.inputOffset] The number of bytes to skip in the input byte stream. A valid Lerc file is expected at that position.\n * @param {string} [options.pixelType] (LERC1 only) Default value is F32. Valid pixel types for input are U8/S8/S16/U16/S32/U32/F32.\n * @param {number} [options.noDataValue] (LERC1 only). It is recommended to use the returned mask instead of setting this value.\n * @returns {{width, height, pixels, pixelType, mask, statistics}}\n * @property {number} width Width of decoded image.\n * @property {number} height Height of decoded image.\n * @property {array} pixels [band1, band2, \u2026] Each band is a typed array of width*height.\n * @property {string} pixelType The type of pixels represented in the output.\n * @property {mask} mask Typed array with a size of width*height, or null if all pixels are valid.\n * @property {array} statistics [statistics_band1, statistics_band2, \u2026] Each element is a statistics object representing min and max values\n **/\n decode: function(encodedData, options) {\n if (!isPlatformLittleEndian) {\n throw \"Big endian system is not supported.\";\n }\n options = options || {};\n var inputOffset = options.inputOffset || 0;\n var fileIdView = new Uint8Array(encodedData, inputOffset, 10);\n var fileIdentifierString = String.fromCharCode.apply(null, fileIdView);\n var lerc, majorVersion;\n if (fileIdentifierString.trim() === \"CntZImage\") {\n lerc = LercDecode;\n majorVersion = 1;\n }\n else if (fileIdentifierString.substring(0, 5) === \"Lerc2\") {\n lerc = Lerc2Decode;\n majorVersion = 2;\n }\n else {\n throw \"Unexpected file identifier string: \" + fileIdentifierString;\n }\n\n var iPlane = 0, eof = encodedData.byteLength - 10, encodedMaskData, bandMasks = [], bandMask, maskData;\n var decodedPixelBlock = {\n width: 0,\n height: 0,\n pixels: [],\n pixelType: options.pixelType,\n mask: null,\n statistics: []\n };\n\n while (inputOffset < eof) {\n var result = lerc.decode(encodedData, {\n inputOffset: inputOffset,//for both lerc1 and lerc2\n encodedMaskData: encodedMaskData,//lerc1 only\n maskData: maskData,//lerc2 only\n returnMask: iPlane === 0 ? true : false,//lerc1 only\n returnEncodedMask: iPlane === 0 ? true : false,//lerc1 only\n returnFileInfo: true,//for both lerc1 and lerc2\n pixelType: options.pixelType || null,//lerc1 only\n noDataValue: options.noDataValue || null//lerc1 only\n });\n\n inputOffset = result.fileInfo.eofOffset;\n if (iPlane === 0) {\n encodedMaskData = result.encodedMaskData;//lerc1\n maskData = result.maskData;//lerc2\n decodedPixelBlock.width = result.width;\n decodedPixelBlock.height = result.height;\n decodedPixelBlock.dimCount = result.dimCount || 1;\n //decodedPixelBlock.dimStats = decodedPixelBlock.dimStats;\n decodedPixelBlock.pixelType = result.pixelType || result.fileInfo.pixelType;\n decodedPixelBlock.mask = result.maskData;\n }\n if (majorVersion >1 && result.fileInfo.mask && result.fileInfo.mask.numBytes > 0) {\n bandMasks.push(result.maskData);\n }\n\n iPlane++;\n decodedPixelBlock.pixels.push(result.pixelData);\n decodedPixelBlock.statistics.push({\n minValue: result.minValue,\n maxValue: result.maxValue,\n noDataValue: result.noDataValue,\n dimStats: result.dimStats\n });\n }\n var i, j, numPixels;\n if (majorVersion > 1 && bandMasks.length > 1) {\n numPixels = decodedPixelBlock.width * decodedPixelBlock.height;\n decodedPixelBlock.bandMasks = bandMasks;\n maskData = new Uint8Array(numPixels);\n maskData.set(bandMasks[0]);\n for (i = 1; i < bandMasks.length; i++) {\n bandMask = bandMasks[i];\n for (j = 0; j < numPixels; j++) {\n maskData[j] = maskData[j] & bandMask[j];\n }\n }\n decodedPixelBlock.maskData = maskData;\n }\n\n return decodedPixelBlock;\n }\n };\n\n if (typeof define === \"function\" && define.amd) {/* jshint ignore:line */\n //amd loaders such as dojo and requireJS\n //http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition\n define([], function() { return Lerc; });/* jshint ignore:line */\n }\n else if (typeof module !== \"undefined\" && module.exports) {/* jshint ignore:line */\n //commonJS module 1.0/1.1/1.1.1 systems, such as nodeJS\n //http://wiki.commonjs.org/wiki/Modules\n module.exports = Lerc;/* jshint ignore:line */\n }\n else {\n //assign to this, most likely window\n this.Lerc = Lerc;\n }\n\n})();\n", "module.exports = {\n webm:\n \"data:video/webm;base64,GkXfowEAAAAAAAAfQoaBAUL3gQFC8oEEQvOBCEKChHdlYm1Ch4EEQoWBAhhTgGcBAAAAAAAVkhFNm3RALE27i1OrhBVJqWZTrIHfTbuMU6uEFlSua1OsggEwTbuMU6uEHFO7a1OsghV17AEAAAAAAACkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmAQAAAAAAAEUq17GDD0JATYCNTGF2ZjU1LjMzLjEwMFdBjUxhdmY1NS4zMy4xMDBzpJBlrrXf3DCDVB8KcgbMpcr+RImIQJBgAAAAAAAWVK5rAQAAAAAAD++uAQAAAAAAADLXgQFzxYEBnIEAIrWcg3VuZIaFVl9WUDiDgQEj44OEAmJaAOABAAAAAAAABrCBsLqBkK4BAAAAAAAPq9eBAnPFgQKcgQAitZyDdW5khohBX1ZPUkJJU4OBAuEBAAAAAAAAEZ+BArWIQOdwAAAAAABiZIEgY6JPbwIeVgF2b3JiaXMAAAAAAoC7AAAAAAAAgLUBAAAAAAC4AQN2b3JiaXMtAAAAWGlwaC5PcmcgbGliVm9yYmlzIEkgMjAxMDExMDEgKFNjaGF1ZmVudWdnZXQpAQAAABUAAABlbmNvZGVyPUxhdmM1NS41Mi4xMDIBBXZvcmJpcyVCQ1YBAEAAACRzGCpGpXMWhBAaQlAZ4xxCzmvsGUJMEYIcMkxbyyVzkCGkoEKIWyiB0JBVAABAAACHQXgUhIpBCCGEJT1YkoMnPQghhIg5eBSEaUEIIYQQQgghhBBCCCGERTlokoMnQQgdhOMwOAyD5Tj4HIRFOVgQgydB6CCED0K4moOsOQghhCQ1SFCDBjnoHITCLCiKgsQwuBaEBDUojILkMMjUgwtCiJqDSTX4GoRnQXgWhGlBCCGEJEFIkIMGQcgYhEZBWJKDBjm4FITLQagahCo5CB+EIDRkFQCQAACgoiiKoigKEBqyCgDIAAAQQFEUx3EcyZEcybEcCwgNWQUAAAEACAAAoEiKpEiO5EiSJFmSJVmSJVmS5omqLMuyLMuyLMsyEBqyCgBIAABQUQxFcRQHCA1ZBQBkAAAIoDiKpViKpWiK54iOCISGrAIAgAAABAAAEDRDUzxHlETPVFXXtm3btm3btm3btm3btm1blmUZCA1ZBQBAAAAQ0mlmqQaIMAMZBkJDVgEACAAAgBGKMMSA0JBVAABAAACAGEoOogmtOd+c46BZDppKsTkdnEi1eZKbirk555xzzsnmnDHOOeecopxZDJoJrTnnnMSgWQqaCa0555wnsXnQmiqtOeeccc7pYJwRxjnnnCateZCajbU555wFrWmOmkuxOeecSLl5UptLtTnnnHPOOeecc84555zqxekcnBPOOeecqL25lpvQxTnnnE/G6d6cEM4555xzzjnnnHPOOeecIDRkFQAABABAEIaNYdwpCNLnaCBGEWIaMulB9+gwCRqDnELq0ehopJQ6CCWVcVJKJwgNWQUAAAIAQAghhRRSSCGFFFJIIYUUYoghhhhyyimnoIJKKqmooowyyyyzzDLLLLPMOuyssw47DDHEEEMrrcRSU2011lhr7jnnmoO0VlprrbVSSimllFIKQkNWAQAgAAAEQgYZZJBRSCGFFGKIKaeccgoqqIDQkFUAACAAgAAAAABP8hzRER3RER3RER3RER3R8RzPESVREiVREi3TMjXTU0VVdWXXlnVZt31b2IVd933d933d+HVhWJZlWZZlWZZlWZZlWZZlWZYgNGQVAAACAAAghBBCSCGFFFJIKcYYc8w56CSUEAgNWQUAAAIACAAAAHAUR3EcyZEcSbIkS9IkzdIsT/M0TxM9URRF0zRV0RVdUTdtUTZl0zVdUzZdVVZtV5ZtW7Z125dl2/d93/d93/d93/d93/d9XQdCQ1YBABIAADqSIymSIimS4ziOJElAaMgqAEAGAEAAAIriKI7jOJIkSZIlaZJneZaomZrpmZ4qqkBoyCoAABAAQAAAAAAAAIqmeIqpeIqoeI7oiJJomZaoqZoryqbsuq7ruq7ruq7ruq7ruq7ruq7ruq7ruq7ruq7ruq7ruq7ruq4LhIasAgAkAAB0JEdyJEdSJEVSJEdygNCQVQCADACAAAAcwzEkRXIsy9I0T/M0TxM90RM901NFV3SB0JBVAAAgAIAAAAAAAAAMybAUy9EcTRIl1VItVVMt1VJF1VNVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVN0zRNEwgNWQkAkAEAkBBTLS3GmgmLJGLSaqugYwxS7KWxSCpntbfKMYUYtV4ah5RREHupJGOKQcwtpNApJq3WVEKFFKSYYyoVUg5SIDRkhQAQmgHgcBxAsixAsiwAAAAAAAAAkDQN0DwPsDQPAAAAAAAAACRNAyxPAzTPAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA0jRA8zxA8zwAAAAAAAAA0DwP8DwR8EQRAAAAAAAAACzPAzTRAzxRBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA0jRA8zxA8zwAAAAAAAAAsDwP8EQR0DwRAAAAAAAAACzPAzxRBDzRAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAEOAAABBgIRQasiIAiBMAcEgSJAmSBM0DSJYFTYOmwTQBkmVB06BpME0AAAAAAAAAAAAAJE2DpkHTIIoASdOgadA0iCIAAAAAAAAAAAAAkqZB06BpEEWApGnQNGgaRBEAAAAAAAAAAAAAzzQhihBFmCbAM02IIkQRpgkAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAGHAAAAgwoQwUGrIiAIgTAHA4imUBAIDjOJYFAACO41gWAABYliWKAABgWZooAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAYcAAACDChDBQashIAiAIAcCiKZQHHsSzgOJYFJMmyAJYF0DyApgFEEQAIAAAocAAACLBBU2JxgEJDVgIAUQAABsWxLE0TRZKkaZoniiRJ0zxPFGma53meacLzPM80IYqiaJoQRVE0TZimaaoqME1VFQAAUOAAABBgg6bE4gCFhqwEAEICAByKYlma5nmeJ4qmqZokSdM8TxRF0TRNU1VJkqZ5niiKommapqqyLE3zPFEURdNUVVWFpnmeKIqiaaqq6sLzPE8URdE0VdV14XmeJ4qiaJqq6roQRVE0TdNUTVV1XSCKpmmaqqqqrgtETxRNU1Vd13WB54miaaqqq7ouEE3TVFVVdV1ZBpimaaqq68oyQFVV1XVdV5YBqqqqruu6sgxQVdd1XVmWZQCu67qyLMsCAAAOHAAAAoygk4wqi7DRhAsPQKEhKwKAKAAAwBimFFPKMCYhpBAaxiSEFEImJaXSUqogpFJSKRWEVEoqJaOUUmopVRBSKamUCkIqJZVSAADYgQMA2IGFUGjISgAgDwCAMEYpxhhzTiKkFGPOOScRUoox55yTSjHmnHPOSSkZc8w556SUzjnnnHNSSuacc845KaVzzjnnnJRSSuecc05KKSWEzkEnpZTSOeecEwAAVOAAABBgo8jmBCNBhYasBABSAQAMjmNZmuZ5omialiRpmud5niiapiZJmuZ5nieKqsnzPE8URdE0VZXneZ4oiqJpqirXFUXTNE1VVV2yLIqmaZqq6rowTdNUVdd1XZimaaqq67oubFtVVdV1ZRm2raqq6rqyDFzXdWXZloEsu67s2rIAAPAEBwCgAhtWRzgpGgssNGQlAJABAEAYg5BCCCFlEEIKIYSUUggJAAAYcAAACDChDBQashIASAUAAIyx1lprrbXWQGettdZaa62AzFprrbXWWmuttdZaa6211lJrrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmuttdZaa6211lprrbXWWmstpZRSSimllFJKKaWUUkoppZRSSgUA+lU4APg/2LA6wknRWGChISsBgHAAAMAYpRhzDEIppVQIMeacdFRai7FCiDHnJKTUWmzFc85BKCGV1mIsnnMOQikpxVZjUSmEUlJKLbZYi0qho5JSSq3VWIwxqaTWWoutxmKMSSm01FqLMRYjbE2ptdhqq7EYY2sqLbQYY4zFCF9kbC2m2moNxggjWywt1VprMMYY3VuLpbaaizE++NpSLDHWXAAAd4MDAESCjTOsJJ0VjgYXGrISAAgJACAQUooxxhhzzjnnpFKMOeaccw5CCKFUijHGnHMOQgghlIwx5pxzEEIIIYRSSsaccxBCCCGEkFLqnHMQQgghhBBKKZ1zDkIIIYQQQimlgxBCCCGEEEoopaQUQgghhBBCCKmklEIIIYRSQighlZRSCCGEEEIpJaSUUgohhFJCCKGElFJKKYUQQgillJJSSimlEkoJJYQSUikppRRKCCGUUkpKKaVUSgmhhBJKKSWllFJKIYQQSikFAAAcOAAABBhBJxlVFmGjCRcegEJDVgIAZAAAkKKUUiktRYIipRikGEtGFXNQWoqocgxSzalSziDmJJaIMYSUk1Qy5hRCDELqHHVMKQYtlRhCxhik2HJLoXMOAAAAQQCAgJAAAAMEBTMAwOAA4XMQdAIERxsAgCBEZohEw0JweFAJEBFTAUBigkIuAFRYXKRdXECXAS7o4q4DIQQhCEEsDqCABByccMMTb3jCDU7QKSp1IAAAAAAADADwAACQXAAREdHMYWRobHB0eHyAhIiMkAgAAAAAABcAfAAAJCVAREQ0cxgZGhscHR4fICEiIyQBAIAAAgAAAAAggAAEBAQAAAAAAAIAAAAEBB9DtnUBAAAAAAAEPueBAKOFggAAgACjzoEAA4BwBwCdASqwAJAAAEcIhYWIhYSIAgIABhwJ7kPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99YAD+/6tQgKOFggADgAqjhYIAD4AOo4WCACSADqOZgQArADECAAEQEAAYABhYL/QACIBDmAYAAKOFggA6gA6jhYIAT4AOo5mBAFMAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCAGSADqOFggB6gA6jmYEAewAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYIAj4AOo5mBAKMAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCAKSADqOFggC6gA6jmYEAywAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYIAz4AOo4WCAOSADqOZgQDzADECAAEQEAAYABhYL/QACIBDmAYAAKOFggD6gA6jhYIBD4AOo5iBARsAEQIAARAQFGAAYWC/0AAiAQ5gGACjhYIBJIAOo4WCATqADqOZgQFDADECAAEQEAAYABhYL/QACIBDmAYAAKOFggFPgA6jhYIBZIAOo5mBAWsAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCAXqADqOFggGPgA6jmYEBkwAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYIBpIAOo4WCAbqADqOZgQG7ADECAAEQEAAYABhYL/QACIBDmAYAAKOFggHPgA6jmYEB4wAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYIB5IAOo4WCAfqADqOZgQILADECAAEQEAAYABhYL/QACIBDmAYAAKOFggIPgA6jhYICJIAOo5mBAjMAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCAjqADqOFggJPgA6jmYECWwAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYICZIAOo4WCAnqADqOZgQKDADECAAEQEAAYABhYL/QACIBDmAYAAKOFggKPgA6jhYICpIAOo5mBAqsAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCArqADqOFggLPgA6jmIEC0wARAgABEBAUYABhYL/QACIBDmAYAKOFggLkgA6jhYIC+oAOo5mBAvsAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCAw+ADqOZgQMjADECAAEQEAAYABhYL/QACIBDmAYAAKOFggMkgA6jhYIDOoAOo5mBA0sAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCA0+ADqOFggNkgA6jmYEDcwAxAgABEBAAGAAYWC/0AAiAQ5gGAACjhYIDeoAOo4WCA4+ADqOZgQObADECAAEQEAAYABhYL/QACIBDmAYAAKOFggOkgA6jhYIDuoAOo5mBA8MAMQIAARAQABgAGFgv9AAIgEOYBgAAo4WCA8+ADqOFggPkgA6jhYID+oAOo4WCBA+ADhxTu2sBAAAAAAAAEbuPs4EDt4r3gQHxghEr8IEK\",\n mp4:\n \"data:video/mp4;base64,AAAAHGZ0eXBNNFYgAAACAGlzb21pc28yYXZjMQAAAAhmcmVlAAAGF21kYXTeBAAAbGliZmFhYyAxLjI4AABCAJMgBDIARwAAArEGBf//rdxF6b3m2Ui3lizYINkj7u94MjY0IC0gY29yZSAxNDIgcjIgOTU2YzhkOCAtIEguMjY0L01QRUctNCBBVkMgY29kZWMgLSBDb3B5bGVmdCAyMDAzLTIwMTQgLSBodHRwOi8vd3d3LnZpZGVvbGFuLm9yZy94MjY0Lmh0bWwgLSBvcHRpb25zOiBjYWJhYz0wIHJlZj0zIGRlYmxvY2s9MTowOjAgYW5hbHlzZT0weDE6MHgxMTEgbWU9aGV4IHN1Ym1lPTcgcHN5PTEgcHN5X3JkPTEuMDA6MC4wMCBtaXhlZF9yZWY9MSBtZV9yYW5nZT0xNiBjaHJvbWFfbWU9MSB0cmVsbGlzPTEgOHg4ZGN0PTAgY3FtPTAgZGVhZHpvbmU9MjEsMTEgZmFzdF9wc2tpcD0xIGNocm9tYV9xcF9vZmZzZXQ9LTIgdGhyZWFkcz02IGxvb2thaGVhZF90aHJlYWRzPTEgc2xpY2VkX3RocmVhZHM9MCBucj0wIGRlY2ltYXRlPTEgaW50ZXJsYWNlZD0wIGJsdXJheV9jb21wYXQ9MCBjb25zdHJhaW5lZF9pbnRyYT0wIGJmcmFtZXM9MCB3ZWlnaHRwPTAga2V5aW50PTI1MCBrZXlpbnRfbWluPTI1IHNjZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NDAgcmM9Y3JmIG1idHJlZT0xIGNyZj0yMy4wIHFjb21wPTAuNjAgcXBtaW49MCBxcG1heD02OSBxcHN0ZXA9NCB2YnZfbWF4cmF0ZT03NjggdmJ2X2J1ZnNpemU9MzAwMCBjcmZfbWF4PTAuMCBuYWxfaHJkPW5vbmUgZmlsbGVyPTAgaXBfcmF0aW89MS40MCBhcT0xOjEuMDAAgAAAAFZliIQL8mKAAKvMnJycnJycnJycnXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXiEASZACGQAjgCEASZACGQAjgAAAAAdBmjgX4GSAIQBJkAIZACOAAAAAB0GaVAX4GSAhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZpgL8DJIQBJkAIZACOAIQBJkAIZACOAAAAABkGagC/AySEASZACGQAjgAAAAAZBmqAvwMkhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZrAL8DJIQBJkAIZACOAAAAABkGa4C/AySEASZACGQAjgCEASZACGQAjgAAAAAZBmwAvwMkhAEmQAhkAI4AAAAAGQZsgL8DJIQBJkAIZACOAIQBJkAIZACOAAAAABkGbQC/AySEASZACGQAjgCEASZACGQAjgAAAAAZBm2AvwMkhAEmQAhkAI4AAAAAGQZuAL8DJIQBJkAIZACOAIQBJkAIZACOAAAAABkGboC/AySEASZACGQAjgAAAAAZBm8AvwMkhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZvgL8DJIQBJkAIZACOAAAAABkGaAC/AySEASZACGQAjgCEASZACGQAjgAAAAAZBmiAvwMkhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZpAL8DJIQBJkAIZACOAAAAABkGaYC/AySEASZACGQAjgCEASZACGQAjgAAAAAZBmoAvwMkhAEmQAhkAI4AAAAAGQZqgL8DJIQBJkAIZACOAIQBJkAIZACOAAAAABkGawC/AySEASZACGQAjgAAAAAZBmuAvwMkhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZsAL8DJIQBJkAIZACOAAAAABkGbIC/AySEASZACGQAjgCEASZACGQAjgAAAAAZBm0AvwMkhAEmQAhkAI4AhAEmQAhkAI4AAAAAGQZtgL8DJIQBJkAIZACOAAAAABkGbgCvAySEASZACGQAjgCEASZACGQAjgAAAAAZBm6AnwMkhAEmQAhkAI4AhAEmQAhkAI4AhAEmQAhkAI4AhAEmQAhkAI4AAAAhubW9vdgAAAGxtdmhkAAAAAAAAAAAAAAAAAAAD6AAABDcAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAzB0cmFrAAAAXHRraGQAAAADAAAAAAAAAAAAAAABAAAAAAAAA+kAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAALAAAACQAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAAPpAAAAAAABAAAAAAKobWRpYQAAACBtZGhkAAAAAAAAAAAAAAAAAAB1MAAAdU5VxAAAAAAALWhkbHIAAAAAAAAAAHZpZGUAAAAAAAAAAAAAAABWaWRlb0hhbmRsZXIAAAACU21pbmYAAAAUdm1oZAAAAAEAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAhNzdGJsAAAAr3N0c2QAAAAAAAAAAQAAAJ9hdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAALAAkABIAAAASAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGP//AAAALWF2Y0MBQsAN/+EAFWdCwA3ZAsTsBEAAAPpAADqYA8UKkgEABWjLg8sgAAAAHHV1aWRraEDyXyRPxbo5pRvPAyPzAAAAAAAAABhzdHRzAAAAAAAAAAEAAAAeAAAD6QAAABRzdHNzAAAAAAAAAAEAAAABAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAABAAAAAQAAAIxzdHN6AAAAAAAAAAAAAAAeAAADDwAAAAsAAAALAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAACgAAAAoAAAAKAAAAiHN0Y28AAAAAAAAAHgAAAEYAAANnAAADewAAA5gAAAO0AAADxwAAA+MAAAP2AAAEEgAABCUAAARBAAAEXQAABHAAAASMAAAEnwAABLsAAATOAAAE6gAABQYAAAUZAAAFNQAABUgAAAVkAAAFdwAABZMAAAWmAAAFwgAABd4AAAXxAAAGDQAABGh0cmFrAAAAXHRraGQAAAADAAAAAAAAAAAAAAACAAAAAAAABDcAAAAAAAAAAAAAAAEBAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAAQkAAADcAABAAAAAAPgbWRpYQAAACBtZGhkAAAAAAAAAAAAAAAAAAC7gAAAykBVxAAAAAAALWhkbHIAAAAAAAAAAHNvdW4AAAAAAAAAAAAAAABTb3VuZEhhbmRsZXIAAAADi21pbmYAAAAQc21oZAAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAADT3N0YmwAAABnc3RzZAAAAAAAAAABAAAAV21wNGEAAAAAAAAAAQAAAAAAAAAAAAIAEAAAAAC7gAAAAAAAM2VzZHMAAAAAA4CAgCIAAgAEgICAFEAVBbjYAAu4AAAADcoFgICAAhGQBoCAgAECAAAAIHN0dHMAAAAAAAAAAgAAADIAAAQAAAAAAQAAAkAAAAFUc3RzYwAAAAAAAAAbAAAAAQAAAAEAAAABAAAAAgAAAAIAAAABAAAAAwAAAAEAAAABAAAABAAAAAIAAAABAAAABgAAAAEAAAABAAAABwAAAAIAAAABAAAACAAAAAEAAAABAAAACQAAAAIAAAABAAAACgAAAAEAAAABAAAACwAAAAIAAAABAAAADQAAAAEAAAABAAAADgAAAAIAAAABAAAADwAAAAEAAAABAAAAEAAAAAIAAAABAAAAEQAAAAEAAAABAAAAEgAAAAIAAAABAAAAFAAAAAEAAAABAAAAFQAAAAIAAAABAAAAFgAAAAEAAAABAAAAFwAAAAIAAAABAAAAGAAAAAEAAAABAAAAGQAAAAIAAAABAAAAGgAAAAEAAAABAAAAGwAAAAIAAAABAAAAHQAAAAEAAAABAAAAHgAAAAIAAAABAAAAHwAAAAQAAAABAAAA4HN0c3oAAAAAAAAAAAAAADMAAAAaAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAACMc3RjbwAAAAAAAAAfAAAALAAAA1UAAANyAAADhgAAA6IAAAO+AAAD0QAAA+0AAAQAAAAEHAAABC8AAARLAAAEZwAABHoAAASWAAAEqQAABMUAAATYAAAE9AAABRAAAAUjAAAFPwAABVIAAAVuAAAFgQAABZ0AAAWwAAAFzAAABegAAAX7AAAGFwAAAGJ1ZHRhAAAAWm1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAALWlsc3QAAAAlqXRvbwAAAB1kYXRhAAAAAQAAAABMYXZmNTUuMzMuMTAw\",\n};\n", "const { webm, mp4 } = require(\"./media.js\");\n\n// Detect iOS browsers < version 10\nconst oldIOS = () =>\n typeof navigator !== \"undefined\" &&\n parseFloat(\n (\n \"\" +\n (/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec(\n navigator.userAgent\n ) || [0, \"\"])[1]\n )\n .replace(\"undefined\", \"3_2\")\n .replace(\"_\", \".\")\n .replace(\"_\", \"\")\n ) < 10 &&\n !window.MSStream;\n\n// Detect native Wake Lock API support\nconst nativeWakeLock = () => \"wakeLock\" in navigator;\n\nclass NoSleep {\n constructor() {\n this.enabled = false;\n if (nativeWakeLock()) {\n this._wakeLock = null;\n const handleVisibilityChange = () => {\n if (this._wakeLock !== null && document.visibilityState === \"visible\") {\n this.enable();\n }\n };\n document.addEventListener(\"visibilitychange\", handleVisibilityChange);\n document.addEventListener(\"fullscreenchange\", handleVisibilityChange);\n } else if (oldIOS()) {\n this.noSleepTimer = null;\n } else {\n // Set up no sleep video element\n this.noSleepVideo = document.createElement(\"video\");\n\n this.noSleepVideo.setAttribute(\"title\", \"No Sleep\");\n this.noSleepVideo.setAttribute(\"playsinline\", \"\");\n\n this._addSourceToVideo(this.noSleepVideo, \"webm\", webm);\n this._addSourceToVideo(this.noSleepVideo, \"mp4\", mp4);\n\n this.noSleepVideo.addEventListener(\"loadedmetadata\", () => {\n if (this.noSleepVideo.duration <= 1) {\n // webm source\n this.noSleepVideo.setAttribute(\"loop\", \"\");\n } else {\n // mp4 source\n this.noSleepVideo.addEventListener(\"timeupdate\", () => {\n if (this.noSleepVideo.currentTime > 0.5) {\n this.noSleepVideo.currentTime = Math.random();\n }\n });\n }\n });\n }\n }\n\n _addSourceToVideo(element, type, dataURI) {\n var source = document.createElement(\"source\");\n source.src = dataURI;\n source.type = `video/${type}`;\n element.appendChild(source);\n }\n\n get isEnabled() {\n return this.enabled;\n }\n\n enable() {\n if (nativeWakeLock()) {\n return navigator.wakeLock\n .request(\"screen\")\n .then((wakeLock) => {\n this._wakeLock = wakeLock;\n this.enabled = true;\n console.log(\"Wake Lock active.\");\n this._wakeLock.addEventListener(\"release\", () => {\n // ToDo: Potentially emit an event for the page to observe since\n // Wake Lock releases happen when page visibility changes.\n // (https://web.dev/wakelock/#wake-lock-lifecycle)\n console.log(\"Wake Lock released.\");\n });\n })\n .catch((err) => {\n this.enabled = false;\n console.error(`${err.name}, ${err.message}`);\n throw err;\n });\n } else if (oldIOS()) {\n this.disable();\n console.warn(`\n NoSleep enabled for older iOS devices. This can interrupt\n active or long-running network requests from completing successfully.\n See https://github.com/richtr/NoSleep.js/issues/15 for more details.\n `);\n this.noSleepTimer = window.setInterval(() => {\n if (!document.hidden) {\n window.location.href = window.location.href.split(\"#\")[0];\n window.setTimeout(window.stop, 0);\n }\n }, 15000);\n this.enabled = true;\n return Promise.resolve();\n } else {\n let playPromise = this.noSleepVideo.play();\n return playPromise\n .then((res) => {\n this.enabled = true;\n return res;\n })\n .catch((err) => {\n this.enabled = false;\n throw err;\n });\n }\n }\n\n disable() {\n if (nativeWakeLock()) {\n if (this._wakeLock) {\n this._wakeLock.release();\n }\n this._wakeLock = null;\n } else if (oldIOS()) {\n if (this.noSleepTimer) {\n console.warn(`\n NoSleep now disabled for older iOS devices.\n `);\n window.clearInterval(this.noSleepTimer);\n this.noSleepTimer = null;\n }\n } else {\n this.noSleepVideo.pause();\n }\n this.enabled = false;\n }\n}\n\nmodule.exports = NoSleep;\n", "export const VERSION = '1.108';\nexport { appendForwardSlash } from '@cesium/engine';\r\nexport { ApproximateTerrainHeights } from '@cesium/engine';\r\nexport { ArcGISTiledElevationTerrainProvider } from '@cesium/engine';\r\nexport { ArcType } from '@cesium/engine';\r\nexport { arrayRemoveDuplicates } from '@cesium/engine';\r\nexport { ArticulationStageType } from '@cesium/engine';\r\nexport { AssociativeArray } from '@cesium/engine';\r\nexport { AttributeCompression } from '@cesium/engine';\r\nexport { AxisAlignedBoundingBox } from '@cesium/engine';\r\nexport { barycentricCoordinates } from '@cesium/engine';\r\nexport { binarySearch } from '@cesium/engine';\r\nexport { BingMapsGeocoderService } from '@cesium/engine';\r\nexport { BoundingRectangle } from '@cesium/engine';\r\nexport { BoundingSphere } from '@cesium/engine';\r\nexport { BoxGeometry } from '@cesium/engine';\r\nexport { BoxOutlineGeometry } from '@cesium/engine';\r\nexport { buildModuleUrl } from '@cesium/engine';\r\nexport { Cartesian2 } from '@cesium/engine';\r\nexport { Cartesian3 } from '@cesium/engine';\r\nexport { Cartesian4 } from '@cesium/engine';\r\nexport { Cartographic } from '@cesium/engine';\r\nexport { CartographicGeocoderService } from '@cesium/engine';\r\nexport { CatmullRomSpline } from '@cesium/engine';\r\nexport { CesiumTerrainProvider } from '@cesium/engine';\r\nexport { Check } from '@cesium/engine';\r\nexport { CircleGeometry } from '@cesium/engine';\r\nexport { CircleOutlineGeometry } from '@cesium/engine';\r\nexport { Clock } from '@cesium/engine';\r\nexport { ClockRange } from '@cesium/engine';\r\nexport { ClockStep } from '@cesium/engine';\r\nexport { clone } from '@cesium/engine';\r\nexport { Color } from '@cesium/engine';\r\nexport { ColorGeometryInstanceAttribute } from '@cesium/engine';\r\nexport { combine } from '@cesium/engine';\r\nexport { ComponentDatatype } from '@cesium/engine';\r\nexport { CompressedTextureBuffer } from '@cesium/engine';\r\nexport { ConstantSpline } from '@cesium/engine';\r\nexport { CoplanarPolygonGeometry } from '@cesium/engine';\r\nexport { CoplanarPolygonGeometryLibrary } from '@cesium/engine';\r\nexport { CoplanarPolygonOutlineGeometry } from '@cesium/engine';\r\nexport { CornerType } from '@cesium/engine';\r\nexport { CorridorGeometry } from '@cesium/engine';\r\nexport { CorridorGeometryLibrary } from '@cesium/engine';\r\nexport { CorridorOutlineGeometry } from '@cesium/engine';\r\nexport { createGuid } from '@cesium/engine';\r\nexport { createWorldTerrainAsync } from '@cesium/engine';\r\nexport { Credit } from '@cesium/engine';\r\nexport { CubicRealPolynomial } from '@cesium/engine';\r\nexport { CullingVolume } from '@cesium/engine';\r\nexport { CustomHeightmapTerrainProvider } from '@cesium/engine';\r\nexport { CylinderGeometry } from '@cesium/engine';\r\nexport { CylinderGeometryLibrary } from '@cesium/engine';\r\nexport { CylinderOutlineGeometry } from '@cesium/engine';\r\nexport { decodeGoogleEarthEnterpriseData } from '@cesium/engine';\r\nexport { decodeVectorPolylinePositions } from '@cesium/engine';\r\nexport { DefaultProxy } from '@cesium/engine';\r\nexport { defaultValue } from '@cesium/engine';\r\nexport { defer } from '@cesium/engine';\r\nexport { defined } from '@cesium/engine';\r\nexport { deprecationWarning } from '@cesium/engine';\r\nexport { destroyObject } from '@cesium/engine';\r\nexport { DeveloperError } from '@cesium/engine';\r\nexport { DistanceDisplayCondition } from '@cesium/engine';\r\nexport { DistanceDisplayConditionGeometryInstanceAttribute } from '@cesium/engine';\r\nexport { DoubleEndedPriorityQueue } from '@cesium/engine';\r\nexport { DoublyLinkedList } from '@cesium/engine';\r\nexport { EarthOrientationParameters } from '@cesium/engine';\r\nexport { EarthOrientationParametersSample } from '@cesium/engine';\r\nexport { EasingFunction } from '@cesium/engine';\r\nexport { EllipseGeometry } from '@cesium/engine';\r\nexport { EllipseGeometryLibrary } from '@cesium/engine';\r\nexport { EllipseOutlineGeometry } from '@cesium/engine';\r\nexport { Ellipsoid } from '@cesium/engine';\r\nexport { EllipsoidalOccluder } from '@cesium/engine';\r\nexport { EllipsoidGeodesic } from '@cesium/engine';\r\nexport { EllipsoidGeometry } from '@cesium/engine';\r\nexport { EllipsoidOutlineGeometry } from '@cesium/engine';\r\nexport { EllipsoidRhumbLine } from '@cesium/engine';\r\nexport { EllipsoidTangentPlane } from '@cesium/engine';\r\nexport { EllipsoidTerrainProvider } from '@cesium/engine';\r\nexport { EncodedCartesian3 } from '@cesium/engine';\r\nexport { Event } from '@cesium/engine';\r\nexport { EventHelper } from '@cesium/engine';\r\nexport { ExtrapolationType } from '@cesium/engine';\r\nexport { FeatureDetection } from '@cesium/engine';\r\nexport { formatError } from '@cesium/engine';\r\nexport { FrustumGeometry } from '@cesium/engine';\r\nexport { FrustumOutlineGeometry } from '@cesium/engine';\r\nexport { Fullscreen } from '@cesium/engine';\r\nexport { GeocoderService } from '@cesium/engine';\r\nexport { GeocodeType } from '@cesium/engine';\r\nexport { GeographicProjection } from '@cesium/engine';\r\nexport { GeographicTilingScheme } from '@cesium/engine';\r\nexport { Geometry } from '@cesium/engine';\r\nexport { GeometryAttribute } from '@cesium/engine';\r\nexport { GeometryAttributes } from '@cesium/engine';\r\nexport { GeometryFactory } from '@cesium/engine';\r\nexport { GeometryInstance } from '@cesium/engine';\r\nexport { GeometryInstanceAttribute } from '@cesium/engine';\r\nexport { GeometryOffsetAttribute } from '@cesium/engine';\r\nexport { GeometryPipeline } from '@cesium/engine';\r\nexport { GeometryType } from '@cesium/engine';\r\nexport { getAbsoluteUri } from '@cesium/engine';\r\nexport { getBaseUri } from '@cesium/engine';\r\nexport { getExtensionFromUri } from '@cesium/engine';\r\nexport { getFilenameFromUri } from '@cesium/engine';\r\nexport { getImageFromTypedArray } from '@cesium/engine';\r\nexport { getImagePixels } from '@cesium/engine';\r\nexport { getJsonFromTypedArray } from '@cesium/engine';\r\nexport { getMagic } from '@cesium/engine';\r\nexport { getStringFromTypedArray } from '@cesium/engine';\r\nexport { getTimestamp } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseMetadata } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseTerrainData } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseTerrainProvider } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseTileInformation } from '@cesium/engine';\r\nexport { GoogleMaps } from '@cesium/engine';\r\nexport { GregorianDate } from '@cesium/engine';\r\nexport { GroundPolylineGeometry } from '@cesium/engine';\r\nexport { HeadingPitchRange } from '@cesium/engine';\r\nexport { HeadingPitchRoll } from '@cesium/engine';\r\nexport { Heap } from '@cesium/engine';\r\nexport { HeightmapEncoding } from '@cesium/engine';\r\nexport { HeightmapTerrainData } from '@cesium/engine';\r\nexport { HeightmapTessellator } from '@cesium/engine';\r\nexport { HermitePolynomialApproximation } from '@cesium/engine';\r\nexport { HermiteSpline } from '@cesium/engine';\r\nexport { HilbertOrder } from '@cesium/engine';\r\nexport { Iau2000Orientation } from '@cesium/engine';\r\nexport { Iau2006XysData } from '@cesium/engine';\r\nexport { Iau2006XysSample } from '@cesium/engine';\r\nexport { IauOrientationAxes } from '@cesium/engine';\r\nexport { IauOrientationParameters } from '@cesium/engine';\r\nexport { IndexDatatype } from '@cesium/engine';\r\nexport { InterpolationAlgorithm } from '@cesium/engine';\r\nexport { InterpolationType } from '@cesium/engine';\r\nexport { Intersect } from '@cesium/engine';\r\nexport { Intersections2D } from '@cesium/engine';\r\nexport { IntersectionTests } from '@cesium/engine';\r\nexport { Interval } from '@cesium/engine';\r\nexport { Ion } from '@cesium/engine';\r\nexport { IonGeocoderService } from '@cesium/engine';\r\nexport { IonResource } from '@cesium/engine';\r\nexport { isBitSet } from '@cesium/engine';\r\nexport { isBlobUri } from '@cesium/engine';\r\nexport { isCrossOriginUrl } from '@cesium/engine';\r\nexport { isDataUri } from '@cesium/engine';\r\nexport { isLeapYear } from '@cesium/engine';\r\nexport { Iso8601 } from '@cesium/engine';\r\nexport { JulianDate } from '@cesium/engine';\r\nexport { KeyboardEventModifier } from '@cesium/engine';\r\nexport { KTX2Transcoder } from '@cesium/engine';\r\nexport { LagrangePolynomialApproximation } from '@cesium/engine';\r\nexport { LeapSecond } from '@cesium/engine';\r\nexport { LinearApproximation } from '@cesium/engine';\r\nexport { LinearSpline } from '@cesium/engine';\r\nexport { loadAndExecuteScript } from '@cesium/engine';\r\nexport { loadImageFromTypedArray } from '@cesium/engine';\r\nexport { loadKTX2 } from '@cesium/engine';\r\nexport { ManagedArray } from '@cesium/engine';\r\nexport { MapProjection } from '@cesium/engine';\r\nexport { Math } from '@cesium/engine';\r\nexport { Matrix2 } from '@cesium/engine';\r\nexport { Matrix3 } from '@cesium/engine';\r\nexport { Matrix4 } from '@cesium/engine';\r\nexport { mergeSort } from '@cesium/engine';\r\nexport { MorphWeightSpline } from '@cesium/engine';\r\nexport { MortonOrder } from '@cesium/engine';\r\nexport { NearFarScalar } from '@cesium/engine';\r\nexport { objectToQuery } from '@cesium/engine';\r\nexport { Occluder } from '@cesium/engine';\r\nexport { OffsetGeometryInstanceAttribute } from '@cesium/engine';\r\nexport { oneTimeWarning } from '@cesium/engine';\r\nexport { OpenCageGeocoderService } from '@cesium/engine';\r\nexport { OrientedBoundingBox } from '@cesium/engine';\r\nexport { OrthographicFrustum } from '@cesium/engine';\r\nexport { OrthographicOffCenterFrustum } from '@cesium/engine';\r\nexport { Packable } from '@cesium/engine';\r\nexport { PackableForInterpolation } from '@cesium/engine';\r\nexport { parseResponseHeaders } from '@cesium/engine';\r\nexport { PeliasGeocoderService } from '@cesium/engine';\r\nexport { PerspectiveFrustum } from '@cesium/engine';\r\nexport { PerspectiveOffCenterFrustum } from '@cesium/engine';\r\nexport { PinBuilder } from '@cesium/engine';\r\nexport { PixelFormat } from '@cesium/engine';\r\nexport { Plane } from '@cesium/engine';\r\nexport { PlaneGeometry } from '@cesium/engine';\r\nexport { PlaneOutlineGeometry } from '@cesium/engine';\r\nexport { pointInsideTriangle } from '@cesium/engine';\r\nexport { PolygonGeometry } from '@cesium/engine';\r\nexport { PolygonGeometryLibrary } from '@cesium/engine';\r\nexport { PolygonHierarchy } from '@cesium/engine';\r\nexport { PolygonOutlineGeometry } from '@cesium/engine';\r\nexport { PolygonPipeline } from '@cesium/engine';\r\nexport { PolylineGeometry } from '@cesium/engine';\r\nexport { PolylinePipeline } from '@cesium/engine';\r\nexport { PolylineVolumeGeometry } from '@cesium/engine';\r\nexport { PolylineVolumeGeometryLibrary } from '@cesium/engine';\r\nexport { PolylineVolumeOutlineGeometry } from '@cesium/engine';\r\nexport { PrimitiveType } from '@cesium/engine';\r\nexport { Proxy } from '@cesium/engine';\r\nexport { QuadraticRealPolynomial } from '@cesium/engine';\r\nexport { QuantizedMeshTerrainData } from '@cesium/engine';\r\nexport { QuarticRealPolynomial } from '@cesium/engine';\r\nexport { Quaternion } from '@cesium/engine';\r\nexport { QuaternionSpline } from '@cesium/engine';\r\nexport { queryToObject } from '@cesium/engine';\r\nexport { Queue } from '@cesium/engine';\r\nexport { Ray } from '@cesium/engine';\r\nexport { Rectangle } from '@cesium/engine';\r\nexport { RectangleCollisionChecker } from '@cesium/engine';\r\nexport { RectangleGeometry } from '@cesium/engine';\r\nexport { RectangleGeometryLibrary } from '@cesium/engine';\r\nexport { RectangleOutlineGeometry } from '@cesium/engine';\r\nexport { ReferenceFrame } from '@cesium/engine';\r\nexport { Request } from '@cesium/engine';\r\nexport { RequestErrorEvent } from '@cesium/engine';\r\nexport { RequestScheduler } from '@cesium/engine';\r\nexport { RequestState } from '@cesium/engine';\r\nexport { RequestType } from '@cesium/engine';\r\nexport { resizeImageToNextPowerOfTwo } from '@cesium/engine';\r\nexport { Resource } from '@cesium/engine';\r\nexport { RuntimeError } from '@cesium/engine';\r\nexport { S2Cell } from '@cesium/engine';\r\nexport { sampleTerrain } from '@cesium/engine';\r\nexport { sampleTerrainMostDetailed } from '@cesium/engine';\r\nexport { scaleToGeodeticSurface } from '@cesium/engine';\r\nexport { ScreenSpaceEventHandler } from '@cesium/engine';\r\nexport { ScreenSpaceEventType } from '@cesium/engine';\r\nexport { ShowGeometryInstanceAttribute } from '@cesium/engine';\r\nexport { Simon1994PlanetaryPositions } from '@cesium/engine';\r\nexport { SimplePolylineGeometry } from '@cesium/engine';\r\nexport { SphereGeometry } from '@cesium/engine';\r\nexport { SphereOutlineGeometry } from '@cesium/engine';\r\nexport { Spherical } from '@cesium/engine';\r\nexport { Spline } from '@cesium/engine';\r\nexport { SteppedSpline } from '@cesium/engine';\r\nexport { subdivideArray } from '@cesium/engine';\r\nexport { TaskProcessor } from '@cesium/engine';\r\nexport { TerrainData } from '@cesium/engine';\r\nexport { TerrainEncoding } from '@cesium/engine';\r\nexport { TerrainExaggeration } from '@cesium/engine';\r\nexport { TerrainMesh } from '@cesium/engine';\r\nexport { TerrainProvider } from '@cesium/engine';\r\nexport { TerrainQuantization } from '@cesium/engine';\r\nexport { TileAvailability } from '@cesium/engine';\r\nexport { TileEdge } from '@cesium/engine';\r\nexport { TileProviderError } from '@cesium/engine';\r\nexport { TilingScheme } from '@cesium/engine';\r\nexport { TimeConstants } from '@cesium/engine';\r\nexport { TimeInterval } from '@cesium/engine';\r\nexport { TimeIntervalCollection } from '@cesium/engine';\r\nexport { TimeStandard } from '@cesium/engine';\r\nexport { Tipsify } from '@cesium/engine';\r\nexport { Transforms } from '@cesium/engine';\r\nexport { TranslationRotationScale } from '@cesium/engine';\r\nexport { TridiagonalSystemSolver } from '@cesium/engine';\r\nexport { TrustedServers } from '@cesium/engine';\r\nexport { VertexFormat } from '@cesium/engine';\r\nexport { VideoSynchronizer } from '@cesium/engine';\r\nexport { Visibility } from '@cesium/engine';\r\nexport { VRTheWorldTerrainProvider } from '@cesium/engine';\r\nexport { VulkanConstants } from '@cesium/engine';\r\nexport { WallGeometry } from '@cesium/engine';\r\nexport { WallGeometryLibrary } from '@cesium/engine';\r\nexport { WallOutlineGeometry } from '@cesium/engine';\r\nexport { WebGLConstants } from '@cesium/engine';\r\nexport { webGLConstantToGlslType } from '@cesium/engine';\r\nexport { WebMercatorProjection } from '@cesium/engine';\r\nexport { WebMercatorTilingScheme } from '@cesium/engine';\r\nexport { WindingOrder } from '@cesium/engine';\r\nexport { WireframeIndexGenerator } from '@cesium/engine';\r\nexport { wrapFunction } from '@cesium/engine';\r\nexport { writeTextToCanvas } from '@cesium/engine';\r\nexport { AutomaticUniforms } from '@cesium/engine';\r\nexport { Buffer } from '@cesium/engine';\r\nexport { BufferUsage } from '@cesium/engine';\r\nexport { ClearCommand } from '@cesium/engine';\r\nexport { ComputeCommand } from '@cesium/engine';\r\nexport { ComputeEngine } from '@cesium/engine';\r\nexport { Context } from '@cesium/engine';\r\nexport { ContextLimits } from '@cesium/engine';\r\nexport { createUniform } from '@cesium/engine';\r\nexport { createUniformArray } from '@cesium/engine';\r\nexport { CubeMap } from '@cesium/engine';\r\nexport { CubeMapFace } from '@cesium/engine';\r\nexport { demodernizeShader } from '@cesium/engine';\r\nexport { DrawCommand } from '@cesium/engine';\r\nexport { Framebuffer } from '@cesium/engine';\r\nexport { FramebufferManager } from '@cesium/engine';\r\nexport { freezeRenderState } from '@cesium/engine';\r\nexport { loadCubeMap } from '@cesium/engine';\r\nexport { MipmapHint } from '@cesium/engine';\r\nexport { MultisampleFramebuffer } from '@cesium/engine';\r\nexport { Pass } from '@cesium/engine';\r\nexport { PassState } from '@cesium/engine';\r\nexport { PixelDatatype } from '@cesium/engine';\r\nexport { Renderbuffer } from '@cesium/engine';\r\nexport { RenderbufferFormat } from '@cesium/engine';\r\nexport { RenderState } from '@cesium/engine';\r\nexport { Sampler } from '@cesium/engine';\r\nexport { ShaderBuilder } from '@cesium/engine';\r\nexport { ShaderCache } from '@cesium/engine';\r\nexport { ShaderDestination } from '@cesium/engine';\r\nexport { ShaderFunction } from '@cesium/engine';\r\nexport { ShaderProgram } from '@cesium/engine';\r\nexport { ShaderSource } from '@cesium/engine';\r\nexport { ShaderStruct } from '@cesium/engine';\r\nexport { Texture } from '@cesium/engine';\r\nexport { TextureCache } from '@cesium/engine';\r\nexport { TextureMagnificationFilter } from '@cesium/engine';\r\nexport { TextureMinificationFilter } from '@cesium/engine';\r\nexport { TextureWrap } from '@cesium/engine';\r\nexport { UniformState } from '@cesium/engine';\r\nexport { VertexArray } from '@cesium/engine';\r\nexport { VertexArrayFacade } from '@cesium/engine';\r\nexport { BillboardGraphics } from '@cesium/engine';\r\nexport { BillboardVisualizer } from '@cesium/engine';\r\nexport { BoundingSphereState } from '@cesium/engine';\r\nexport { BoxGeometryUpdater } from '@cesium/engine';\r\nexport { BoxGraphics } from '@cesium/engine';\r\nexport { CallbackProperty } from '@cesium/engine';\r\nexport { Cesium3DTilesetGraphics } from '@cesium/engine';\r\nexport { Cesium3DTilesetVisualizer } from '@cesium/engine';\r\nexport { CheckerboardMaterialProperty } from '@cesium/engine';\r\nexport { ColorMaterialProperty } from '@cesium/engine';\r\nexport { CompositeEntityCollection } from '@cesium/engine';\r\nexport { CompositeMaterialProperty } from '@cesium/engine';\r\nexport { CompositePositionProperty } from '@cesium/engine';\r\nexport { CompositeProperty } from '@cesium/engine';\r\nexport { ConstantPositionProperty } from '@cesium/engine';\r\nexport { ConstantProperty } from '@cesium/engine';\r\nexport { CorridorGeometryUpdater } from '@cesium/engine';\r\nexport { CorridorGraphics } from '@cesium/engine';\r\nexport { createMaterialPropertyDescriptor } from '@cesium/engine';\r\nexport { createPropertyDescriptor } from '@cesium/engine';\r\nexport { createRawPropertyDescriptor } from '@cesium/engine';\r\nexport { CustomDataSource } from '@cesium/engine';\r\nexport { CylinderGeometryUpdater } from '@cesium/engine';\r\nexport { CylinderGraphics } from '@cesium/engine';\r\nexport { CzmlDataSource } from '@cesium/engine';\r\nexport { DataSource } from '@cesium/engine';\r\nexport { DataSourceClock } from '@cesium/engine';\r\nexport { DataSourceCollection } from '@cesium/engine';\r\nexport { DataSourceDisplay } from '@cesium/engine';\r\nexport { DynamicGeometryBatch } from '@cesium/engine';\r\nexport { DynamicGeometryUpdater } from '@cesium/engine';\r\nexport { EllipseGeometryUpdater } from '@cesium/engine';\r\nexport { EllipseGraphics } from '@cesium/engine';\r\nexport { EllipsoidGeometryUpdater } from '@cesium/engine';\r\nexport { EllipsoidGraphics } from '@cesium/engine';\r\nexport { Entity } from '@cesium/engine';\r\nexport { EntityCluster } from '@cesium/engine';\r\nexport { EntityCollection } from '@cesium/engine';\r\nexport { EntityView } from '@cesium/engine';\r\nexport { exportKml } from '@cesium/engine';\r\nexport { GeoJsonDataSource } from '@cesium/engine';\r\nexport { GeometryUpdater } from '@cesium/engine';\r\nexport { GeometryVisualizer } from '@cesium/engine';\r\nexport { getElement } from '@cesium/engine';\r\nexport { GpxDataSource } from '@cesium/engine';\r\nexport { GridMaterialProperty } from '@cesium/engine';\r\nexport { GroundGeometryUpdater } from '@cesium/engine';\r\nexport { heightReferenceOnEntityPropertyChanged } from '@cesium/engine';\r\nexport { ImageMaterialProperty } from '@cesium/engine';\r\nexport { KmlCamera } from '@cesium/engine';\r\nexport { KmlDataSource } from '@cesium/engine';\r\nexport { KmlLookAt } from '@cesium/engine';\r\nexport { KmlTour } from '@cesium/engine';\r\nexport { KmlTourFlyTo } from '@cesium/engine';\r\nexport { KmlTourWait } from '@cesium/engine';\r\nexport { LabelGraphics } from '@cesium/engine';\r\nexport { LabelVisualizer } from '@cesium/engine';\r\nexport { MaterialProperty } from '@cesium/engine';\r\nexport { ModelGraphics } from '@cesium/engine';\r\nexport { ModelVisualizer } from '@cesium/engine';\r\nexport { NodeTransformationProperty } from '@cesium/engine';\r\nexport { PathGraphics } from '@cesium/engine';\r\nexport { PathVisualizer } from '@cesium/engine';\r\nexport { PlaneGeometryUpdater } from '@cesium/engine';\r\nexport { PlaneGraphics } from '@cesium/engine';\r\nexport { PointGraphics } from '@cesium/engine';\r\nexport { PointVisualizer } from '@cesium/engine';\r\nexport { PolygonGeometryUpdater } from '@cesium/engine';\r\nexport { PolygonGraphics } from '@cesium/engine';\r\nexport { PolylineArrowMaterialProperty } from '@cesium/engine';\r\nexport { PolylineDashMaterialProperty } from '@cesium/engine';\r\nexport { PolylineGeometryUpdater } from '@cesium/engine';\r\nexport { PolylineGlowMaterialProperty } from '@cesium/engine';\r\nexport { PolylineGraphics } from '@cesium/engine';\r\nexport { PolylineOutlineMaterialProperty } from '@cesium/engine';\r\nexport { PolylineVisualizer } from '@cesium/engine';\r\nexport { PolylineVolumeGeometryUpdater } from '@cesium/engine';\r\nexport { PolylineVolumeGraphics } from '@cesium/engine';\r\nexport { PositionProperty } from '@cesium/engine';\r\nexport { PositionPropertyArray } from '@cesium/engine';\r\nexport { Property } from '@cesium/engine';\r\nexport { PropertyArray } from '@cesium/engine';\r\nexport { PropertyBag } from '@cesium/engine';\r\nexport { RectangleGeometryUpdater } from '@cesium/engine';\r\nexport { RectangleGraphics } from '@cesium/engine';\r\nexport { ReferenceProperty } from '@cesium/engine';\r\nexport { Rotation } from '@cesium/engine';\r\nexport { SampledPositionProperty } from '@cesium/engine';\r\nexport { SampledProperty } from '@cesium/engine';\r\nexport { ScaledPositionProperty } from '@cesium/engine';\r\nexport { StaticGeometryColorBatch } from '@cesium/engine';\r\nexport { StaticGeometryPerMaterialBatch } from '@cesium/engine';\r\nexport { StaticGroundGeometryColorBatch } from '@cesium/engine';\r\nexport { StaticGroundGeometryPerMaterialBatch } from '@cesium/engine';\r\nexport { StaticGroundPolylinePerMaterialBatch } from '@cesium/engine';\r\nexport { StaticOutlineGeometryBatch } from '@cesium/engine';\r\nexport { StripeMaterialProperty } from '@cesium/engine';\r\nexport { StripeOrientation } from '@cesium/engine';\r\nexport { TerrainOffsetProperty } from '@cesium/engine';\r\nexport { TimeIntervalCollectionPositionProperty } from '@cesium/engine';\r\nexport { TimeIntervalCollectionProperty } from '@cesium/engine';\r\nexport { VelocityOrientationProperty } from '@cesium/engine';\r\nexport { VelocityVectorProperty } from '@cesium/engine';\r\nexport { Visualizer } from '@cesium/engine';\r\nexport { WallGeometryUpdater } from '@cesium/engine';\r\nexport { WallGraphics } from '@cesium/engine';\r\nexport { _shadersAdjustTranslucentFS } from '@cesium/engine';\r\nexport { _shadersAtmosphereCommon } from '@cesium/engine';\r\nexport { _shadersBillboardCollectionFS } from '@cesium/engine';\r\nexport { _shadersBillboardCollectionVS } from '@cesium/engine';\r\nexport { _shadersBrdfLutGeneratorFS } from '@cesium/engine';\r\nexport { _shadersCloudCollectionFS } from '@cesium/engine';\r\nexport { _shadersCloudCollectionVS } from '@cesium/engine';\r\nexport { _shadersCloudNoiseFS } from '@cesium/engine';\r\nexport { _shadersCloudNoiseVS } from '@cesium/engine';\r\nexport { _shadersCompareAndPackTranslucentDepth } from '@cesium/engine';\r\nexport { _shadersCompositeOITFS } from '@cesium/engine';\r\nexport { _shadersDepthPlaneFS } from '@cesium/engine';\r\nexport { _shadersDepthPlaneVS } from '@cesium/engine';\r\nexport { _shadersEllipsoidFS } from '@cesium/engine';\r\nexport { _shadersEllipsoidVS } from '@cesium/engine';\r\nexport { _shadersFXAA3_11 } from '@cesium/engine';\r\nexport { _shadersGlobeFS } from '@cesium/engine';\r\nexport { _shadersGlobeVS } from '@cesium/engine';\r\nexport { _shadersGroundAtmosphere } from '@cesium/engine';\r\nexport { _shadersOctahedralProjectionAtlasFS } from '@cesium/engine';\r\nexport { _shadersOctahedralProjectionFS } from '@cesium/engine';\r\nexport { _shadersOctahedralProjectionVS } from '@cesium/engine';\r\nexport { _shadersPointPrimitiveCollectionFS } from '@cesium/engine';\r\nexport { _shadersPointPrimitiveCollectionVS } from '@cesium/engine';\r\nexport { _shadersPolylineCommon } from '@cesium/engine';\r\nexport { _shadersPolylineFS } from '@cesium/engine';\r\nexport { _shadersPolylineShadowVolumeFS } from '@cesium/engine';\r\nexport { _shadersPolylineShadowVolumeMorphFS } from '@cesium/engine';\r\nexport { _shadersPolylineShadowVolumeMorphVS } from '@cesium/engine';\r\nexport { _shadersPolylineShadowVolumeVS } from '@cesium/engine';\r\nexport { _shadersPolylineVS } from '@cesium/engine';\r\nexport { _shadersReprojectWebMercatorFS } from '@cesium/engine';\r\nexport { _shadersReprojectWebMercatorVS } from '@cesium/engine';\r\nexport { _shadersShadowVolumeAppearanceFS } from '@cesium/engine';\r\nexport { _shadersShadowVolumeAppearanceVS } from '@cesium/engine';\r\nexport { _shadersShadowVolumeFS } from '@cesium/engine';\r\nexport { _shadersSkyAtmosphereCommon } from '@cesium/engine';\r\nexport { _shadersSkyAtmosphereFS } from '@cesium/engine';\r\nexport { _shadersSkyAtmosphereVS } from '@cesium/engine';\r\nexport { _shadersSkyBoxFS } from '@cesium/engine';\r\nexport { _shadersSkyBoxVS } from '@cesium/engine';\r\nexport { _shadersSunFS } from '@cesium/engine';\r\nexport { _shadersSunTextureFS } from '@cesium/engine';\r\nexport { _shadersSunVS } from '@cesium/engine';\r\nexport { _shadersVector3DTileClampedPolylinesFS } from '@cesium/engine';\r\nexport { _shadersVector3DTileClampedPolylinesVS } from '@cesium/engine';\r\nexport { _shadersVector3DTilePolylinesVS } from '@cesium/engine';\r\nexport { _shadersVectorTileVS } from '@cesium/engine';\r\nexport { _shadersViewportQuadFS } from '@cesium/engine';\r\nexport { _shadersViewportQuadVS } from '@cesium/engine';\r\nexport { CesiumWidget } from '@cesium/engine';\r\nexport { AlphaMode } from '@cesium/engine';\r\nexport { Appearance } from '@cesium/engine';\r\nexport { ArcGisBaseMapType } from '@cesium/engine';\r\nexport { ArcGisMapServerImageryProvider } from '@cesium/engine';\r\nexport { ArcGisMapService } from '@cesium/engine';\r\nexport { AttributeType } from '@cesium/engine';\r\nexport { AutoExposure } from '@cesium/engine';\r\nexport { Axis } from '@cesium/engine';\r\nexport { B3dmParser } from '@cesium/engine';\r\nexport { BatchTable } from '@cesium/engine';\r\nexport { BatchTableHierarchy } from '@cesium/engine';\r\nexport { BatchTexture } from '@cesium/engine';\r\nexport { Billboard } from '@cesium/engine';\r\nexport { BillboardCollection } from '@cesium/engine';\r\nexport { BingMapsImageryProvider } from '@cesium/engine';\r\nexport { BingMapsStyle } from '@cesium/engine';\r\nexport { BlendEquation } from '@cesium/engine';\r\nexport { BlendFunction } from '@cesium/engine';\r\nexport { BlendingState } from '@cesium/engine';\r\nexport { BlendOption } from '@cesium/engine';\r\nexport { BoundingVolumeSemantics } from '@cesium/engine';\r\nexport { BoxEmitter } from '@cesium/engine';\r\nexport { BrdfLutGenerator } from '@cesium/engine';\r\nexport { BufferLoader } from '@cesium/engine';\r\nexport { buildVoxelDrawCommands } from '@cesium/engine';\r\nexport { Camera } from '@cesium/engine';\r\nexport { CameraEventAggregator } from '@cesium/engine';\r\nexport { CameraEventType } from '@cesium/engine';\r\nexport { CameraFlightPath } from '@cesium/engine';\r\nexport { Cesium3DContentGroup } from '@cesium/engine';\r\nexport { Cesium3DTile } from '@cesium/engine';\r\nexport { Cesium3DTileBatchTable } from '@cesium/engine';\r\nexport { Cesium3DTileColorBlendMode } from '@cesium/engine';\r\nexport { Cesium3DTileContent } from '@cesium/engine';\r\nexport { Cesium3DTileContentFactory } from '@cesium/engine';\r\nexport { Cesium3DTileContentState } from '@cesium/engine';\r\nexport { Cesium3DTileContentType } from '@cesium/engine';\r\nexport { Cesium3DTileFeature } from '@cesium/engine';\r\nexport { Cesium3DTileFeatureTable } from '@cesium/engine';\r\nexport { Cesium3DTileOptimizationHint } from '@cesium/engine';\r\nexport { Cesium3DTileOptimizations } from '@cesium/engine';\r\nexport { Cesium3DTilePass } from '@cesium/engine';\r\nexport { Cesium3DTilePassState } from '@cesium/engine';\r\nexport { Cesium3DTilePointFeature } from '@cesium/engine';\r\nexport { Cesium3DTileRefine } from '@cesium/engine';\r\nexport { Cesium3DTileset } from '@cesium/engine';\r\nexport { Cesium3DTilesetBaseTraversal } from '@cesium/engine';\r\nexport { Cesium3DTilesetCache } from '@cesium/engine';\r\nexport { Cesium3DTilesetHeatmap } from '@cesium/engine';\r\nexport { Cesium3DTilesetMetadata } from '@cesium/engine';\r\nexport { Cesium3DTilesetMostDetailedTraversal } from '@cesium/engine';\r\nexport { Cesium3DTilesetSkipTraversal } from '@cesium/engine';\r\nexport { Cesium3DTilesetStatistics } from '@cesium/engine';\r\nexport { Cesium3DTilesetTraversal } from '@cesium/engine';\r\nexport { Cesium3DTileStyle } from '@cesium/engine';\r\nexport { Cesium3DTileStyleEngine } from '@cesium/engine';\r\nexport { Cesium3DTilesVoxelProvider } from '@cesium/engine';\r\nexport { CircleEmitter } from '@cesium/engine';\r\nexport { ClassificationPrimitive } from '@cesium/engine';\r\nexport { ClassificationType } from '@cesium/engine';\r\nexport { ClippingPlane } from '@cesium/engine';\r\nexport { ClippingPlaneCollection } from '@cesium/engine';\r\nexport { CloudCollection } from '@cesium/engine';\r\nexport { CloudType } from '@cesium/engine';\r\nexport { ColorBlendMode } from '@cesium/engine';\r\nexport { Composite3DTileContent } from '@cesium/engine';\r\nexport { computeFlyToLocationForRectangle } from '@cesium/engine';\r\nexport { ConditionsExpression } from '@cesium/engine';\r\nexport { ConeEmitter } from '@cesium/engine';\r\nexport { ContentMetadata } from '@cesium/engine';\r\nexport { createBillboardPointCallback } from '@cesium/engine';\r\nexport { createElevationBandMaterial } from '@cesium/engine';\r\nexport { createGooglePhotorealistic3DTileset } from '@cesium/engine';\r\nexport { createOsmBuildingsAsync } from '@cesium/engine';\r\nexport { createTangentSpaceDebugPrimitive } from '@cesium/engine';\r\nexport { createWorldImageryAsync } from '@cesium/engine';\r\nexport { CreditDisplay } from '@cesium/engine';\r\nexport { CullFace } from '@cesium/engine';\r\nexport { CumulusCloud } from '@cesium/engine';\r\nexport { DebugAppearance } from '@cesium/engine';\r\nexport { DebugCameraPrimitive } from '@cesium/engine';\r\nexport { DebugInspector } from '@cesium/engine';\r\nexport { DebugModelMatrixPrimitive } from '@cesium/engine';\r\nexport { DepthFunction } from '@cesium/engine';\r\nexport { DepthPlane } from '@cesium/engine';\r\nexport { DerivedCommand } from '@cesium/engine';\r\nexport { DeviceOrientationCameraController } from '@cesium/engine';\r\nexport { DirectionalLight } from '@cesium/engine';\r\nexport { DiscardEmptyTileImagePolicy } from '@cesium/engine';\r\nexport { DiscardMissingTileImagePolicy } from '@cesium/engine';\r\nexport { DracoLoader } from '@cesium/engine';\r\nexport { EllipsoidPrimitive } from '@cesium/engine';\r\nexport { EllipsoidSurfaceAppearance } from '@cesium/engine';\r\nexport { Empty3DTileContent } from '@cesium/engine';\r\nexport { Expression } from '@cesium/engine';\r\nexport { ExpressionNodeType } from '@cesium/engine';\r\nexport { findContentMetadata } from '@cesium/engine';\r\nexport { findGroupMetadata } from '@cesium/engine';\r\nexport { findTileMetadata } from '@cesium/engine';\r\nexport { Fog } from '@cesium/engine';\r\nexport { FrameRateMonitor } from '@cesium/engine';\r\nexport { FrameState } from '@cesium/engine';\r\nexport { FrustumCommands } from '@cesium/engine';\r\nexport { Geometry3DTileContent } from '@cesium/engine';\r\nexport { getBinaryAccessor } from '@cesium/engine';\r\nexport { getClipAndStyleCode } from '@cesium/engine';\r\nexport { getClippingFunction } from '@cesium/engine';\r\nexport { GetFeatureInfoFormat } from '@cesium/engine';\r\nexport { Globe } from '@cesium/engine';\r\nexport { GlobeDepth } from '@cesium/engine';\r\nexport { GlobeSurfaceShaderSet } from '@cesium/engine';\r\nexport { GlobeSurfaceTile } from '@cesium/engine';\r\nexport { GlobeSurfaceTileProvider } from '@cesium/engine';\r\nexport { GlobeTranslucency } from '@cesium/engine';\r\nexport { GlobeTranslucencyFramebuffer } from '@cesium/engine';\r\nexport { GlobeTranslucencyState } from '@cesium/engine';\r\nexport { GltfBufferViewLoader } from '@cesium/engine';\r\nexport { GltfDracoLoader } from '@cesium/engine';\r\nexport { GltfImageLoader } from '@cesium/engine';\r\nexport { GltfIndexBufferLoader } from '@cesium/engine';\r\nexport { GltfJsonLoader } from '@cesium/engine';\r\nexport { GltfLoader } from '@cesium/engine';\r\nexport { GltfLoaderUtil } from '@cesium/engine';\r\nexport { GltfStructuralMetadataLoader } from '@cesium/engine';\r\nexport { GltfTextureLoader } from '@cesium/engine';\r\nexport { GltfVertexBufferLoader } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseImageryProvider } from '@cesium/engine';\r\nexport { GoogleEarthEnterpriseMapsProvider } from '@cesium/engine';\r\nexport { GridImageryProvider } from '@cesium/engine';\r\nexport { GroundPolylinePrimitive } from '@cesium/engine';\r\nexport { GroundPrimitive } from '@cesium/engine';\r\nexport { GroupMetadata } from '@cesium/engine';\r\nexport { hasExtension } from '@cesium/engine';\r\nexport { HeightReference } from '@cesium/engine';\r\nexport { HorizontalOrigin } from '@cesium/engine';\r\nexport { I3dmParser } from '@cesium/engine';\r\nexport { I3SDataProvider } from '@cesium/engine';\r\nexport { I3SFeature } from '@cesium/engine';\r\nexport { I3SField } from '@cesium/engine';\r\nexport { I3SGeometry } from '@cesium/engine';\r\nexport { I3SLayer } from '@cesium/engine';\r\nexport { I3SNode } from '@cesium/engine';\r\nexport { ImageBasedLighting } from '@cesium/engine';\r\nexport { Imagery } from '@cesium/engine';\r\nexport { ImageryLayer } from '@cesium/engine';\r\nexport { ImageryLayerCollection } from '@cesium/engine';\r\nexport { ImageryLayerFeatureInfo } from '@cesium/engine';\r\nexport { ImageryProvider } from '@cesium/engine';\r\nexport { ImageryState } from '@cesium/engine';\r\nexport { Implicit3DTileContent } from '@cesium/engine';\r\nexport { ImplicitAvailabilityBitstream } from '@cesium/engine';\r\nexport { ImplicitMetadataView } from '@cesium/engine';\r\nexport { ImplicitSubdivisionScheme } from '@cesium/engine';\r\nexport { ImplicitSubtree } from '@cesium/engine';\r\nexport { ImplicitSubtreeCache } from '@cesium/engine';\r\nexport { ImplicitSubtreeMetadata } from '@cesium/engine';\r\nexport { ImplicitTileCoordinates } from '@cesium/engine';\r\nexport { ImplicitTileset } from '@cesium/engine';\r\nexport { InstanceAttributeSemantic } from '@cesium/engine';\r\nexport { InvertClassification } from '@cesium/engine';\r\nexport { IonImageryProvider } from '@cesium/engine';\r\nexport { IonWorldImageryStyle } from '@cesium/engine';\r\nexport { JobScheduler } from '@cesium/engine';\r\nexport { JobType } from '@cesium/engine';\r\nexport { JsonMetadataTable } from '@cesium/engine';\r\nexport { KeyframeNode } from '@cesium/engine';\r\nexport { Label } from '@cesium/engine';\r\nexport { LabelCollection } from '@cesium/engine';\r\nexport { LabelStyle } from '@cesium/engine';\r\nexport { Light } from '@cesium/engine';\r\nexport { MapboxImageryProvider } from '@cesium/engine';\r\nexport { MapboxStyleImageryProvider } from '@cesium/engine';\r\nexport { MapMode2D } from '@cesium/engine';\r\nexport { Material } from '@cesium/engine';\r\nexport { MaterialAppearance } from '@cesium/engine';\r\nexport { Megatexture } from '@cesium/engine';\r\nexport { MetadataClass } from '@cesium/engine';\r\nexport { MetadataClassProperty } from '@cesium/engine';\r\nexport { MetadataComponentType } from '@cesium/engine';\r\nexport { MetadataEntity } from '@cesium/engine';\r\nexport { MetadataEnum } from '@cesium/engine';\r\nexport { MetadataEnumValue } from '@cesium/engine';\r\nexport { MetadataSchema } from '@cesium/engine';\r\nexport { MetadataSchemaLoader } from '@cesium/engine';\r\nexport { MetadataSemantic } from '@cesium/engine';\r\nexport { MetadataTable } from '@cesium/engine';\r\nexport { MetadataTableProperty } from '@cesium/engine';\r\nexport { MetadataType } from '@cesium/engine';\r\nexport { ModelAnimationLoop } from '@cesium/engine';\r\nexport { ModelAnimationState } from '@cesium/engine';\r\nexport { ModelComponents } from '@cesium/engine';\r\nexport { Moon } from '@cesium/engine';\r\nexport { Multiple3DTileContent } from '@cesium/engine';\r\nexport { NeverTileDiscardPolicy } from '@cesium/engine';\r\nexport { OctahedralProjectedCubeMap } from '@cesium/engine';\r\nexport { OIT } from '@cesium/engine';\r\nexport { OpenStreetMapImageryProvider } from '@cesium/engine';\r\nexport { OrderedGroundPrimitiveCollection } from '@cesium/engine';\r\nexport { parseBatchTable } from '@cesium/engine';\r\nexport { parseFeatureMetadataLegacy } from '@cesium/engine';\r\nexport { parseStructuralMetadata } from '@cesium/engine';\r\nexport { Particle } from '@cesium/engine';\r\nexport { ParticleBurst } from '@cesium/engine';\r\nexport { ParticleEmitter } from '@cesium/engine';\r\nexport { ParticleSystem } from '@cesium/engine';\r\nexport { PerformanceDisplay } from '@cesium/engine';\r\nexport { PerInstanceColorAppearance } from '@cesium/engine';\r\nexport { PickDepth } from '@cesium/engine';\r\nexport { PickDepthFramebuffer } from '@cesium/engine';\r\nexport { PickFramebuffer } from '@cesium/engine';\r\nexport { Picking } from '@cesium/engine';\r\nexport { PntsParser } from '@cesium/engine';\r\nexport { PointCloud } from '@cesium/engine';\r\nexport { PointCloudEyeDomeLighting } from '@cesium/engine';\r\nexport { PointCloudShading } from '@cesium/engine';\r\nexport { PointPrimitive } from '@cesium/engine';\r\nexport { PointPrimitiveCollection } from '@cesium/engine';\r\nexport { Polyline } from '@cesium/engine';\r\nexport { PolylineCollection } from '@cesium/engine';\r\nexport { PolylineColorAppearance } from '@cesium/engine';\r\nexport { PolylineMaterialAppearance } from '@cesium/engine';\r\nexport { PostProcessStage } from '@cesium/engine';\r\nexport { PostProcessStageCollection } from '@cesium/engine';\r\nexport { PostProcessStageComposite } from '@cesium/engine';\r\nexport { PostProcessStageLibrary } from '@cesium/engine';\r\nexport { PostProcessStageSampleMode } from '@cesium/engine';\r\nexport { PostProcessStageTextureCache } from '@cesium/engine';\r\nexport { preprocess3DTileContent } from '@cesium/engine';\r\nexport { Primitive } from '@cesium/engine';\r\nexport { PrimitiveCollection } from '@cesium/engine';\r\nexport { PrimitiveLoadPlan } from '@cesium/engine';\r\nexport { PrimitivePipeline } from '@cesium/engine';\r\nexport { PrimitiveState } from '@cesium/engine';\r\nexport { processVoxelProperties } from '@cesium/engine';\r\nexport { PropertyAttribute } from '@cesium/engine';\r\nexport { PropertyAttributeProperty } from '@cesium/engine';\r\nexport { PropertyTable } from '@cesium/engine';\r\nexport { PropertyTexture } from '@cesium/engine';\r\nexport { PropertyTextureProperty } from '@cesium/engine';\r\nexport { QuadtreeOccluders } from '@cesium/engine';\r\nexport { QuadtreePrimitive } from '@cesium/engine';\r\nexport { QuadtreeTile } from '@cesium/engine';\r\nexport { QuadtreeTileLoadState } from '@cesium/engine';\r\nexport { QuadtreeTileProvider } from '@cesium/engine';\r\nexport { ResourceCache } from '@cesium/engine';\r\nexport { ResourceCacheKey } from '@cesium/engine';\r\nexport { ResourceCacheStatistics } from '@cesium/engine';\r\nexport { ResourceLoader } from '@cesium/engine';\r\nexport { ResourceLoaderState } from '@cesium/engine';\r\nexport { Scene } from '@cesium/engine';\r\nexport { SceneFramebuffer } from '@cesium/engine';\r\nexport { SceneMode } from '@cesium/engine';\r\nexport { SceneTransforms } from '@cesium/engine';\r\nexport { SceneTransitioner } from '@cesium/engine';\r\nexport { ScreenSpaceCameraController } from '@cesium/engine';\r\nexport { SDFSettings } from '@cesium/engine';\r\nexport { ShadowMap } from '@cesium/engine';\r\nexport { ShadowMapShader } from '@cesium/engine';\r\nexport { ShadowMode } from '@cesium/engine';\r\nexport { ShadowVolumeAppearance } from '@cesium/engine';\r\nexport { SingleTileImageryProvider } from '@cesium/engine';\r\nexport { SkyAtmosphere } from '@cesium/engine';\r\nexport { SkyBox } from '@cesium/engine';\r\nexport { SpatialNode } from '@cesium/engine';\r\nexport { SphereEmitter } from '@cesium/engine';\r\nexport { SplitDirection } from '@cesium/engine';\r\nexport { Splitter } from '@cesium/engine';\r\nexport { StencilConstants } from '@cesium/engine';\r\nexport { StencilFunction } from '@cesium/engine';\r\nexport { StencilOperation } from '@cesium/engine';\r\nexport { StructuralMetadata } from '@cesium/engine';\r\nexport { StyleExpression } from '@cesium/engine';\r\nexport { Sun } from '@cesium/engine';\r\nexport { SunLight } from '@cesium/engine';\r\nexport { SunPostProcess } from '@cesium/engine';\r\nexport { SupportedImageFormats } from '@cesium/engine';\r\nexport { Terrain } from '@cesium/engine';\r\nexport { TerrainFillMesh } from '@cesium/engine';\r\nexport { TerrainState } from '@cesium/engine';\r\nexport { TextureAtlas } from '@cesium/engine';\r\nexport { TileBoundingRegion } from '@cesium/engine';\r\nexport { TileBoundingS2Cell } from '@cesium/engine';\r\nexport { TileBoundingSphere } from '@cesium/engine';\r\nexport { TileBoundingVolume } from '@cesium/engine';\r\nexport { TileCoordinatesImageryProvider } from '@cesium/engine';\r\nexport { TileDiscardPolicy } from '@cesium/engine';\r\nexport { TileImagery } from '@cesium/engine';\r\nexport { TileMapServiceImageryProvider } from '@cesium/engine';\r\nexport { TileMetadata } from '@cesium/engine';\r\nexport { TileOrientedBoundingBox } from '@cesium/engine';\r\nexport { TileReplacementQueue } from '@cesium/engine';\r\nexport { TileSelectionResult } from '@cesium/engine';\r\nexport { Tileset3DTileContent } from '@cesium/engine';\r\nexport { TilesetMetadata } from '@cesium/engine';\r\nexport { TileState } from '@cesium/engine';\r\nexport { TimeDynamicImagery } from '@cesium/engine';\r\nexport { TimeDynamicPointCloud } from '@cesium/engine';\r\nexport { Tonemapper } from '@cesium/engine';\r\nexport { TranslucentTileClassification } from '@cesium/engine';\r\nexport { TweenCollection } from '@cesium/engine';\r\nexport { UrlTemplateImageryProvider } from '@cesium/engine';\r\nexport { Vector3DTileBatch } from '@cesium/engine';\r\nexport { Vector3DTileClampedPolylines } from '@cesium/engine';\r\nexport { Vector3DTileContent } from '@cesium/engine';\r\nexport { Vector3DTileGeometry } from '@cesium/engine';\r\nexport { Vector3DTilePoints } from '@cesium/engine';\r\nexport { Vector3DTilePolygons } from '@cesium/engine';\r\nexport { Vector3DTilePolylines } from '@cesium/engine';\r\nexport { Vector3DTilePrimitive } from '@cesium/engine';\r\nexport { VertexAttributeSemantic } from '@cesium/engine';\r\nexport { VerticalOrigin } from '@cesium/engine';\r\nexport { View } from '@cesium/engine';\r\nexport { ViewportQuad } from '@cesium/engine';\r\nexport { VoxelBoxShape } from '@cesium/engine';\r\nexport { VoxelContent } from '@cesium/engine';\r\nexport { VoxelCylinderShape } from '@cesium/engine';\r\nexport { VoxelEllipsoidShape } from '@cesium/engine';\r\nexport { VoxelPrimitive } from '@cesium/engine';\r\nexport { VoxelProvider } from '@cesium/engine';\r\nexport { VoxelRenderResources } from '@cesium/engine';\r\nexport { VoxelShape } from '@cesium/engine';\r\nexport { VoxelShapeType } from '@cesium/engine';\r\nexport { VoxelTraversal } from '@cesium/engine';\r\nexport { WebMapServiceImageryProvider } from '@cesium/engine';\r\nexport { WebMapTileServiceImageryProvider } from '@cesium/engine';\r\nexport { _shadersAllMaterialAppearanceFS } from '@cesium/engine';\r\nexport { _shadersAllMaterialAppearanceVS } from '@cesium/engine';\r\nexport { _shadersBasicMaterialAppearanceFS } from '@cesium/engine';\r\nexport { _shadersBasicMaterialAppearanceVS } from '@cesium/engine';\r\nexport { _shadersEllipsoidSurfaceAppearanceFS } from '@cesium/engine';\r\nexport { _shadersEllipsoidSurfaceAppearanceVS } from '@cesium/engine';\r\nexport { _shadersPerInstanceColorAppearanceFS } from '@cesium/engine';\r\nexport { _shadersPerInstanceColorAppearanceVS } from '@cesium/engine';\r\nexport { _shadersPerInstanceFlatColorAppearanceFS } from '@cesium/engine';\r\nexport { _shadersPerInstanceFlatColorAppearanceVS } from '@cesium/engine';\r\nexport { _shadersPolylineColorAppearanceVS } from '@cesium/engine';\r\nexport { _shadersPolylineMaterialAppearanceVS } from '@cesium/engine';\r\nexport { _shadersTexturedMaterialAppearanceFS } from '@cesium/engine';\r\nexport { _shadersTexturedMaterialAppearanceVS } from '@cesium/engine';\r\nexport { _shadersCzmBuiltins } from '@cesium/engine';\r\nexport { _shadersAspectRampMaterial } from '@cesium/engine';\r\nexport { _shadersBumpMapMaterial } from '@cesium/engine';\r\nexport { _shadersCheckerboardMaterial } from '@cesium/engine';\r\nexport { _shadersDotMaterial } from '@cesium/engine';\r\nexport { _shadersElevationBandMaterial } from '@cesium/engine';\r\nexport { _shadersElevationContourMaterial } from '@cesium/engine';\r\nexport { _shadersElevationRampMaterial } from '@cesium/engine';\r\nexport { _shadersFadeMaterial } from '@cesium/engine';\r\nexport { _shadersGridMaterial } from '@cesium/engine';\r\nexport { _shadersNormalMapMaterial } from '@cesium/engine';\r\nexport { _shadersPolylineArrowMaterial } from '@cesium/engine';\r\nexport { _shadersPolylineDashMaterial } from '@cesium/engine';\r\nexport { _shadersPolylineGlowMaterial } from '@cesium/engine';\r\nexport { _shadersPolylineOutlineMaterial } from '@cesium/engine';\r\nexport { _shadersRimLightingMaterial } from '@cesium/engine';\r\nexport { _shadersSlopeRampMaterial } from '@cesium/engine';\r\nexport { _shadersStripeMaterial } from '@cesium/engine';\r\nexport { _shadersWater } from '@cesium/engine';\r\nexport { _shadersCPUStylingStageFS } from '@cesium/engine';\r\nexport { _shadersCPUStylingStageVS } from '@cesium/engine';\r\nexport { _shadersCustomShaderStageFS } from '@cesium/engine';\r\nexport { _shadersCustomShaderStageVS } from '@cesium/engine';\r\nexport { _shadersFeatureIdStageFS } from '@cesium/engine';\r\nexport { _shadersFeatureIdStageVS } from '@cesium/engine';\r\nexport { _shadersGeometryStageFS } from '@cesium/engine';\r\nexport { _shadersGeometryStageVS } from '@cesium/engine';\r\nexport { _shadersImageBasedLightingStageFS } from '@cesium/engine';\r\nexport { _shadersInstancingStageCommon } from '@cesium/engine';\r\nexport { _shadersInstancingStageVS } from '@cesium/engine';\r\nexport { _shadersLegacyInstancingStageVS } from '@cesium/engine';\r\nexport { _shadersLightingStageFS } from '@cesium/engine';\r\nexport { _shadersMaterialStageFS } from '@cesium/engine';\r\nexport { _shadersMetadataStageFS } from '@cesium/engine';\r\nexport { _shadersMetadataStageVS } from '@cesium/engine';\r\nexport { _shadersModelClippingPlanesStageFS } from '@cesium/engine';\r\nexport { _shadersModelColorStageFS } from '@cesium/engine';\r\nexport { _shadersModelFS } from '@cesium/engine';\r\nexport { _shadersModelSilhouetteStageFS } from '@cesium/engine';\r\nexport { _shadersModelSilhouetteStageVS } from '@cesium/engine';\r\nexport { _shadersModelSplitterStageFS } from '@cesium/engine';\r\nexport { _shadersModelVS } from '@cesium/engine';\r\nexport { _shadersMorphTargetsStageVS } from '@cesium/engine';\r\nexport { _shadersPointCloudStylingStageVS } from '@cesium/engine';\r\nexport { _shadersPrimitiveOutlineStageFS } from '@cesium/engine';\r\nexport { _shadersPrimitiveOutlineStageVS } from '@cesium/engine';\r\nexport { _shadersSelectedFeatureIdStageCommon } from '@cesium/engine';\r\nexport { _shadersSkinningStageVS } from '@cesium/engine';\r\nexport { _shadersAcesTonemappingStage } from '@cesium/engine';\r\nexport { _shadersAdditiveBlend } from '@cesium/engine';\r\nexport { _shadersAmbientOcclusionGenerate } from '@cesium/engine';\r\nexport { _shadersAmbientOcclusionModulate } from '@cesium/engine';\r\nexport { _shadersBlackAndWhite } from '@cesium/engine';\r\nexport { _shadersBloomComposite } from '@cesium/engine';\r\nexport { _shadersBrightness } from '@cesium/engine';\r\nexport { _shadersBrightPass } from '@cesium/engine';\r\nexport { _shadersCompositeTranslucentClassification } from '@cesium/engine';\r\nexport { _shadersContrastBias } from '@cesium/engine';\r\nexport { _shadersDepthOfField } from '@cesium/engine';\r\nexport { _shadersDepthView } from '@cesium/engine';\r\nexport { _shadersDepthViewPacked } from '@cesium/engine';\r\nexport { _shadersEdgeDetection } from '@cesium/engine';\r\nexport { _shadersFilmicTonemapping } from '@cesium/engine';\r\nexport { _shadersFXAA } from '@cesium/engine';\r\nexport { _shadersGaussianBlur1D } from '@cesium/engine';\r\nexport { _shadersLensFlare } from '@cesium/engine';\r\nexport { _shadersModifiedReinhardTonemapping } from '@cesium/engine';\r\nexport { _shadersNightVision } from '@cesium/engine';\r\nexport { _shadersPassThrough } from '@cesium/engine';\r\nexport { _shadersPassThroughDepth } from '@cesium/engine';\r\nexport { _shadersPointCloudEyeDomeLighting } from '@cesium/engine';\r\nexport { _shadersReinhardTonemapping } from '@cesium/engine';\r\nexport { _shadersSilhouette } from '@cesium/engine';\r\nexport { _shadersconvertUvToBox } from '@cesium/engine';\r\nexport { _shadersconvertUvToCylinder } from '@cesium/engine';\r\nexport { _shadersconvertUvToEllipsoid } from '@cesium/engine';\r\nexport { _shadersIntersectBox } from '@cesium/engine';\r\nexport { _shadersIntersectClippingPlanes } from '@cesium/engine';\r\nexport { _shadersIntersectCylinder } from '@cesium/engine';\r\nexport { _shadersIntersectDepth } from '@cesium/engine';\r\nexport { _shadersIntersectEllipsoid } from '@cesium/engine';\r\nexport { _shadersIntersection } from '@cesium/engine';\r\nexport { _shadersIntersectionUtils } from '@cesium/engine';\r\nexport { _shadersMegatexture } from '@cesium/engine';\r\nexport { _shadersOctree } from '@cesium/engine';\r\nexport { _shadersVoxelFS } from '@cesium/engine';\r\nexport { _shadersVoxelVS } from '@cesium/engine';\r\nexport { addBuffer } from '@cesium/engine';\r\nexport { addDefaults } from '@cesium/engine';\r\nexport { addExtensionsRequired } from '@cesium/engine';\r\nexport { addExtensionsUsed } from '@cesium/engine';\r\nexport { addPipelineExtras } from '@cesium/engine';\r\nexport { addToArray } from '@cesium/engine';\r\nexport { findAccessorMinMax } from '@cesium/engine';\r\nexport { ForEach } from '@cesium/engine';\r\nexport { forEachTextureInMaterial } from '@cesium/engine';\r\nexport { getAccessorByteStride } from '@cesium/engine';\r\nexport { getComponentReader } from '@cesium/engine';\r\nexport { moveTechniqueRenderStates } from '@cesium/engine';\r\nexport { moveTechniquesToExtension } from '@cesium/engine';\r\nexport { numberOfComponentsForType } from '@cesium/engine';\r\nexport { parseGlb } from '@cesium/engine';\r\nexport { readAccessorPacked } from '@cesium/engine';\r\nexport { removeExtension } from '@cesium/engine';\r\nexport { removeExtensionsRequired } from '@cesium/engine';\r\nexport { removeExtensionsUsed } from '@cesium/engine';\r\nexport { removePipelineExtras } from '@cesium/engine';\r\nexport { removeUnusedElements } from '@cesium/engine';\r\nexport { updateAccessorComponentTypes } from '@cesium/engine';\r\nexport { updateVersion } from '@cesium/engine';\r\nexport { usesExtension } from '@cesium/engine';\r\nexport { AlphaPipelineStage } from '@cesium/engine';\r\nexport { B3dmLoader } from '@cesium/engine';\r\nexport { BatchTexturePipelineStage } from '@cesium/engine';\r\nexport { buildDrawCommand } from '@cesium/engine';\r\nexport { ClassificationModelDrawCommand } from '@cesium/engine';\r\nexport { ClassificationPipelineStage } from '@cesium/engine';\r\nexport { CPUStylingPipelineStage } from '@cesium/engine';\r\nexport { CustomShader } from '@cesium/engine';\r\nexport { CustomShaderMode } from '@cesium/engine';\r\nexport { CustomShaderPipelineStage } from '@cesium/engine';\r\nexport { CustomShaderTranslucencyMode } from '@cesium/engine';\r\nexport { DequantizationPipelineStage } from '@cesium/engine';\r\nexport { FeatureIdPipelineStage } from '@cesium/engine';\r\nexport { GeoJsonLoader } from '@cesium/engine';\r\nexport { GeometryPipelineStage } from '@cesium/engine';\r\nexport { I3dmLoader } from '@cesium/engine';\r\nexport { ImageBasedLightingPipelineStage } from '@cesium/engine';\r\nexport { InstancingPipelineStage } from '@cesium/engine';\r\nexport { LightingModel } from '@cesium/engine';\r\nexport { LightingPipelineStage } from '@cesium/engine';\r\nexport { MaterialPipelineStage } from '@cesium/engine';\r\nexport { MetadataPipelineStage } from '@cesium/engine';\r\nexport { Model } from '@cesium/engine';\r\nexport { Model3DTileContent } from '@cesium/engine';\r\nexport { ModelAlphaOptions } from '@cesium/engine';\r\nexport { ModelAnimation } from '@cesium/engine';\r\nexport { ModelAnimationChannel } from '@cesium/engine';\r\nexport { ModelAnimationCollection } from '@cesium/engine';\r\nexport { ModelArticulation } from '@cesium/engine';\r\nexport { ModelArticulationStage } from '@cesium/engine';\r\nexport { ModelClippingPlanesPipelineStage } from '@cesium/engine';\r\nexport { ModelColorPipelineStage } from '@cesium/engine';\r\nexport { ModelDrawCommand } from '@cesium/engine';\r\nexport { ModelFeature } from '@cesium/engine';\r\nexport { ModelFeatureTable } from '@cesium/engine';\r\nexport { ModelLightingOptions } from '@cesium/engine';\r\nexport { ModelMatrixUpdateStage } from '@cesium/engine';\r\nexport { ModelNode } from '@cesium/engine';\r\nexport { ModelRenderResources } from '@cesium/engine';\r\nexport { ModelRuntimeNode } from '@cesium/engine';\r\nexport { ModelRuntimePrimitive } from '@cesium/engine';\r\nexport { ModelSceneGraph } from '@cesium/engine';\r\nexport { ModelSilhouettePipelineStage } from '@cesium/engine';\r\nexport { ModelSkin } from '@cesium/engine';\r\nexport { ModelSplitterPipelineStage } from '@cesium/engine';\r\nexport { ModelStatistics } from '@cesium/engine';\r\nexport { ModelType } from '@cesium/engine';\r\nexport { ModelUtility } from '@cesium/engine';\r\nexport { MorphTargetsPipelineStage } from '@cesium/engine';\r\nexport { NodeRenderResources } from '@cesium/engine';\r\nexport { NodeStatisticsPipelineStage } from '@cesium/engine';\r\nexport { PickingPipelineStage } from '@cesium/engine';\r\nexport { PntsLoader } from '@cesium/engine';\r\nexport { PointCloudStylingPipelineStage } from '@cesium/engine';\r\nexport { PrimitiveOutlineGenerator } from '@cesium/engine';\r\nexport { PrimitiveOutlinePipelineStage } from '@cesium/engine';\r\nexport { PrimitiveRenderResources } from '@cesium/engine';\r\nexport { PrimitiveStatisticsPipelineStage } from '@cesium/engine';\r\nexport { SceneMode2DPipelineStage } from '@cesium/engine';\r\nexport { SelectedFeatureIdPipelineStage } from '@cesium/engine';\r\nexport { SkinningPipelineStage } from '@cesium/engine';\r\nexport { StyleCommandsNeeded } from '@cesium/engine';\r\nexport { TextureManager } from '@cesium/engine';\r\nexport { TextureUniform } from '@cesium/engine';\r\nexport { TilesetPipelineStage } from '@cesium/engine';\r\nexport { UniformType } from '@cesium/engine';\r\nexport { VaryingType } from '@cesium/engine';\r\nexport { WireframePipelineStage } from '@cesium/engine';\r\nexport { _shadersdegreesPerRadian } from '@cesium/engine';\r\nexport { _shadersdepthRange } from '@cesium/engine';\r\nexport { _shadersepsilon1 } from '@cesium/engine';\r\nexport { _shadersepsilon2 } from '@cesium/engine';\r\nexport { _shadersepsilon3 } from '@cesium/engine';\r\nexport { _shadersepsilon4 } from '@cesium/engine';\r\nexport { _shadersepsilon5 } from '@cesium/engine';\r\nexport { _shadersepsilon6 } from '@cesium/engine';\r\nexport { _shadersepsilon7 } from '@cesium/engine';\r\nexport { _shadersinfinity } from '@cesium/engine';\r\nexport { _shadersoneOverPi } from '@cesium/engine';\r\nexport { _shadersoneOverTwoPi } from '@cesium/engine';\r\nexport { _shaderspassCesium3DTile } from '@cesium/engine';\r\nexport { _shaderspassCesium3DTileClassification } from '@cesium/engine';\r\nexport { _shaderspassCesium3DTileClassificationIgnoreShow } from '@cesium/engine';\r\nexport { _shaderspassClassification } from '@cesium/engine';\r\nexport { _shaderspassCompute } from '@cesium/engine';\r\nexport { _shaderspassEnvironment } from '@cesium/engine';\r\nexport { _shaderspassGlobe } from '@cesium/engine';\r\nexport { _shaderspassOpaque } from '@cesium/engine';\r\nexport { _shaderspassOverlay } from '@cesium/engine';\r\nexport { _shaderspassTerrainClassification } from '@cesium/engine';\r\nexport { _shaderspassTranslucent } from '@cesium/engine';\r\nexport { _shaderspassVoxels } from '@cesium/engine';\r\nexport { _shaderspi } from '@cesium/engine';\r\nexport { _shaderspiOverFour } from '@cesium/engine';\r\nexport { _shaderspiOverSix } from '@cesium/engine';\r\nexport { _shaderspiOverThree } from '@cesium/engine';\r\nexport { _shaderspiOverTwo } from '@cesium/engine';\r\nexport { _shadersradiansPerDegree } from '@cesium/engine';\r\nexport { _shaderssceneMode2D } from '@cesium/engine';\r\nexport { _shaderssceneMode3D } from '@cesium/engine';\r\nexport { _shaderssceneModeColumbusView } from '@cesium/engine';\r\nexport { _shaderssceneModeMorphing } from '@cesium/engine';\r\nexport { _shaderssolarRadius } from '@cesium/engine';\r\nexport { _shadersthreePiOver2 } from '@cesium/engine';\r\nexport { _shaderstwoPi } from '@cesium/engine';\r\nexport { _shaderswebMercatorMaxLatitude } from '@cesium/engine';\r\nexport { _shadersacesTonemapping } from '@cesium/engine';\r\nexport { _shadersalphaWeight } from '@cesium/engine';\r\nexport { _shadersantialias } from '@cesium/engine';\r\nexport { _shadersapproximateSphericalCoordinates } from '@cesium/engine';\r\nexport { _shadersbackFacing } from '@cesium/engine';\r\nexport { _shadersbranchFreeTernary } from '@cesium/engine';\r\nexport { _shaderscascadeColor } from '@cesium/engine';\r\nexport { _shaderscascadeDistance } from '@cesium/engine';\r\nexport { _shaderscascadeMatrix } from '@cesium/engine';\r\nexport { _shaderscascadeWeights } from '@cesium/engine';\r\nexport { _shaderscolumbusViewMorph } from '@cesium/engine';\r\nexport { _shaderscomputePosition } from '@cesium/engine';\r\nexport { _shaderscosineAndSine } from '@cesium/engine';\r\nexport { _shadersdecompressTextureCoordinates } from '@cesium/engine';\r\nexport { _shadersdefaultPbrMaterial } from '@cesium/engine';\r\nexport { _shadersdepthClamp } from '@cesium/engine';\r\nexport { _shaderseastNorthUpToEyeCoordinates } from '@cesium/engine';\r\nexport { _shadersellipsoidContainsPoint } from '@cesium/engine';\r\nexport { _shadersellipsoidWgs84TextureCoordinates } from '@cesium/engine';\r\nexport { _shadersequalsEpsilon } from '@cesium/engine';\r\nexport { _shaderseyeOffset } from '@cesium/engine';\r\nexport { _shaderseyeToWindowCoordinates } from '@cesium/engine';\r\nexport { _shadersfastApproximateAtan } from '@cesium/engine';\r\nexport { _shadersfog } from '@cesium/engine';\r\nexport { _shadersgammaCorrect } from '@cesium/engine';\r\nexport { _shadersgeodeticSurfaceNormal } from '@cesium/engine';\r\nexport { _shadersgetDefaultMaterial } from '@cesium/engine';\r\nexport { _shadersgetLambertDiffuse } from '@cesium/engine';\r\nexport { _shadersgetSpecular } from '@cesium/engine';\r\nexport { _shadersgetWaterNoise } from '@cesium/engine';\r\nexport { _shadersHSBToRGB } from '@cesium/engine';\r\nexport { _shadersHSLToRGB } from '@cesium/engine';\r\nexport { _shadershue } from '@cesium/engine';\r\nexport { _shadersinverseGamma } from '@cesium/engine';\r\nexport { _shadersisEmpty } from '@cesium/engine';\r\nexport { _shadersisFull } from '@cesium/engine';\r\nexport { _shaderslatitudeToWebMercatorFraction } from '@cesium/engine';\r\nexport { _shaderslinearToSrgb } from '@cesium/engine';\r\nexport { _shaderslineDistance } from '@cesium/engine';\r\nexport { _shadersluminance } from '@cesium/engine';\r\nexport { _shadersmetersPerPixel } from '@cesium/engine';\r\nexport { _shadersmodelToWindowCoordinates } from '@cesium/engine';\r\nexport { _shadersmultiplyWithColorBalance } from '@cesium/engine';\r\nexport { _shadersnearFarScalar } from '@cesium/engine';\r\nexport { _shadersoctDecode } from '@cesium/engine';\r\nexport { _shaderspackDepth } from '@cesium/engine';\r\nexport { _shaderspbrLighting } from '@cesium/engine';\r\nexport { _shaderspbrMetallicRoughnessMaterial } from '@cesium/engine';\r\nexport { _shaderspbrSpecularGlossinessMaterial } from '@cesium/engine';\r\nexport { _shadersphong } from '@cesium/engine';\r\nexport { _shadersplaneDistance } from '@cesium/engine';\r\nexport { _shaderspointAlongRay } from '@cesium/engine';\r\nexport { _shadersrayEllipsoidIntersectionInterval } from '@cesium/engine';\r\nexport { _shadersraySphereIntersectionInterval } from '@cesium/engine';\r\nexport { _shadersreadDepth } from '@cesium/engine';\r\nexport { _shadersreadNonPerspective } from '@cesium/engine';\r\nexport { _shadersreverseLogDepth } from '@cesium/engine';\r\nexport { _shadersRGBToHSB } from '@cesium/engine';\r\nexport { _shadersRGBToHSL } from '@cesium/engine';\r\nexport { _shadersRGBToXYZ } from '@cesium/engine';\r\nexport { _shadersround } from '@cesium/engine';\r\nexport { _shaderssampleOctahedralProjection } from '@cesium/engine';\r\nexport { _shaderssaturation } from '@cesium/engine';\r\nexport { _shadersshadowDepthCompare } from '@cesium/engine';\r\nexport { _shadersshadowVisibility } from '@cesium/engine';\r\nexport { _shaderssignNotZero } from '@cesium/engine';\r\nexport { _shaderssphericalHarmonics } from '@cesium/engine';\r\nexport { _shaderssrgbToLinear } from '@cesium/engine';\r\nexport { _shaderstangentToEyeSpaceMatrix } from '@cesium/engine';\r\nexport { _shaderstextureCube } from '@cesium/engine';\r\nexport { _shaderstransformPlane } from '@cesium/engine';\r\nexport { _shaderstranslateRelativeToEye } from '@cesium/engine';\r\nexport { _shaderstranslucentPhong } from '@cesium/engine';\r\nexport { _shaderstranspose } from '@cesium/engine';\r\nexport { _shadersunpackDepth } from '@cesium/engine';\r\nexport { _shadersunpackFloat } from '@cesium/engine';\r\nexport { _shadersunpackUint } from '@cesium/engine';\r\nexport { _shadersvalueTransform } from '@cesium/engine';\r\nexport { _shadersvertexLogDepth } from '@cesium/engine';\r\nexport { _shaderswindowToEyeCoordinates } from '@cesium/engine';\r\nexport { _shaderswriteDepthClamp } from '@cesium/engine';\r\nexport { _shaderswriteLogDepth } from '@cesium/engine';\r\nexport { _shaderswriteNonPerspective } from '@cesium/engine';\r\nexport { _shadersXYZToRGB } from '@cesium/engine';\r\nexport { _shadersdepthRangeStruct } from '@cesium/engine';\r\nexport { _shadersmaterial } from '@cesium/engine';\r\nexport { _shadersmaterialInput } from '@cesium/engine';\r\nexport { _shadersmodelMaterial } from '@cesium/engine';\r\nexport { _shadersmodelVertexOutput } from '@cesium/engine';\r\nexport { _shaderspbrParameters } from '@cesium/engine';\r\nexport { _shadersray } from '@cesium/engine';\r\nexport { _shadersraySegment } from '@cesium/engine';\r\nexport { _shadersshadowParameters } from '@cesium/engine';\r\nexport { createTaskProcessorWorker } from '@cesium/engine';\nexport { ClockViewModel } from '@cesium/widgets';\r\nexport { Command } from '@cesium/widgets';\r\nexport { createCommand } from '@cesium/widgets';\r\nexport { InspectorShared } from '@cesium/widgets';\r\nexport { subscribeAndEvaluate } from '@cesium/widgets';\r\nexport { SvgPathBindingHandler } from '@cesium/widgets';\r\nexport { ToggleButtonViewModel } from '@cesium/widgets';\r\nexport { Animation } from '@cesium/widgets';\r\nexport { AnimationViewModel } from '@cesium/widgets';\r\nexport { BaseLayerPicker } from '@cesium/widgets';\r\nexport { BaseLayerPickerViewModel } from '@cesium/widgets';\r\nexport { createDefaultImageryProviderViewModels } from '@cesium/widgets';\r\nexport { createDefaultTerrainProviderViewModels } from '@cesium/widgets';\r\nexport { ProviderViewModel } from '@cesium/widgets';\r\nexport { Cesium3DTilesInspector } from '@cesium/widgets';\r\nexport { Cesium3DTilesInspectorViewModel } from '@cesium/widgets';\r\nexport { CesiumInspector } from '@cesium/widgets';\r\nexport { CesiumInspectorViewModel } from '@cesium/widgets';\r\nexport { FullscreenButton } from '@cesium/widgets';\r\nexport { FullscreenButtonViewModel } from '@cesium/widgets';\r\nexport { Geocoder } from '@cesium/widgets';\r\nexport { GeocoderViewModel } from '@cesium/widgets';\r\nexport { HomeButton } from '@cesium/widgets';\r\nexport { HomeButtonViewModel } from '@cesium/widgets';\r\nexport { InfoBox } from '@cesium/widgets';\r\nexport { InfoBoxViewModel } from '@cesium/widgets';\r\nexport { NavigationHelpButton } from '@cesium/widgets';\r\nexport { NavigationHelpButtonViewModel } from '@cesium/widgets';\r\nexport { PerformanceWatchdog } from '@cesium/widgets';\r\nexport { PerformanceWatchdogViewModel } from '@cesium/widgets';\r\nexport { ProjectionPicker } from '@cesium/widgets';\r\nexport { ProjectionPickerViewModel } from '@cesium/widgets';\r\nexport { SceneModePicker } from '@cesium/widgets';\r\nexport { SceneModePickerViewModel } from '@cesium/widgets';\r\nexport { SelectionIndicator } from '@cesium/widgets';\r\nexport { SelectionIndicatorViewModel } from '@cesium/widgets';\r\nexport { knockout_3_5_1 } from '@cesium/widgets';\r\nexport { knockout_es5 } from '@cesium/widgets';\r\nexport { knockout } from '@cesium/widgets';\r\nexport { Timeline } from '@cesium/widgets';\r\nexport { TimelineHighlightRange } from '@cesium/widgets';\r\nexport { TimelineTrack } from '@cesium/widgets';\r\nexport { Viewer } from '@cesium/widgets';\r\nexport { viewerCesium3DTilesInspectorMixin } from '@cesium/widgets';\r\nexport { viewerCesiumInspectorMixin } from '@cesium/widgets';\r\nexport { viewerDragDropMixin } from '@cesium/widgets';\r\nexport { viewerPerformanceWatchdogMixin } from '@cesium/widgets';\r\nexport { viewerVoxelInspectorMixin } from '@cesium/widgets';\r\nexport { VoxelInspector } from '@cesium/widgets';\r\nexport { VoxelInspectorViewModel } from '@cesium/widgets';\r\nexport { VRButton } from '@cesium/widgets';\r\nexport { VRButtonViewModel } from '@cesium/widgets';\n", "/**\n * @function\n *\n * @param {*} value The object.\n * @returns {boolean} Returns true if the object is defined, returns false otherwise.\n *\n * @example\n * if (Cesium.defined(positions)) {\n * doSomething();\n * } else {\n * doSomethingElse();\n * }\n */\nfunction defined(value) {\n return value !== undefined && value !== null;\n}\nexport default defined;\n", "import defined from \"./defined.js\";\n\n/**\n * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,\n * argument out of range, etc. This exception should only be thrown during development;\n * it usually indicates a bug in the calling code. This exception should never be\n * caught; instead the calling code should strive not to generate it.\n *

\n * On the other hand, a {@link RuntimeError} indicates an exception that may\n * be thrown at runtime, e.g., out of memory, that the calling code should be prepared\n * to catch.\n *\n * @alias DeveloperError\n * @constructor\n * @extends Error\n *\n * @param {string} [message] The error message for this exception.\n *\n * @see RuntimeError\n */\nfunction DeveloperError(message) {\n /**\n * 'DeveloperError' indicating that this exception was thrown due to a developer error.\n * @type {string}\n * @readonly\n */\n this.name = \"DeveloperError\";\n\n /**\n * The explanation for why this exception was thrown.\n * @type {string}\n * @readonly\n */\n this.message = message;\n\n //Browsers such as IE don't have a stack property until you actually throw the error.\n let stack;\n try {\n throw new Error();\n } catch (e) {\n stack = e.stack;\n }\n\n /**\n * The stack trace of this exception, if available.\n * @type {string}\n * @readonly\n */\n this.stack = stack;\n}\n\nif (defined(Object.create)) {\n DeveloperError.prototype = Object.create(Error.prototype);\n DeveloperError.prototype.constructor = DeveloperError;\n}\n\nDeveloperError.prototype.toString = function () {\n let str = `${this.name}: ${this.message}`;\n\n if (defined(this.stack)) {\n str += `\\n${this.stack.toString()}`;\n }\n\n return str;\n};\n\n/**\n * @private\n */\nDeveloperError.throwInstantiationError = function () {\n throw new DeveloperError(\n \"This function defines an interface and should not be called directly.\"\n );\n};\nexport default DeveloperError;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Contains functions for checking that supplied arguments are of a specified type\n * or meet specified conditions\n * @private\n */\nconst Check = {};\n\n/**\n * Contains type checking functions, all using the typeof operator\n */\nCheck.typeOf = {};\n\nfunction getUndefinedErrorMessage(name) {\n return `${name} is required, actual value was undefined`;\n}\n\nfunction getFailedTypeErrorMessage(actual, expected, name) {\n return `Expected ${name} to be typeof ${expected}, actual typeof was ${actual}`;\n}\n\n/**\n * Throws if test is not defined\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value that is to be checked\n * @exception {DeveloperError} test must be defined\n */\nCheck.defined = function (name, test) {\n if (!defined(test)) {\n throw new DeveloperError(getUndefinedErrorMessage(name));\n }\n};\n\n/**\n * Throws if test is not typeof 'function'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'function'\n */\nCheck.typeOf.func = function (name, test) {\n if (typeof test !== \"function\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"function\", name)\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'string'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'string'\n */\nCheck.typeOf.string = function (name, test) {\n if (typeof test !== \"string\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"string\", name)\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'number'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'number'\n */\nCheck.typeOf.number = function (name, test) {\n if (typeof test !== \"number\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"number\", name)\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'number' and less than limit\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @param {number} limit The limit value to compare against\n * @exception {DeveloperError} test must be typeof 'number' and less than limit\n */\nCheck.typeOf.number.lessThan = function (name, test, limit) {\n Check.typeOf.number(name, test);\n if (test >= limit) {\n throw new DeveloperError(\n `Expected ${name} to be less than ${limit}, actual value was ${test}`\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'number' and less than or equal to limit\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @param {number} limit The limit value to compare against\n * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit\n */\nCheck.typeOf.number.lessThanOrEquals = function (name, test, limit) {\n Check.typeOf.number(name, test);\n if (test > limit) {\n throw new DeveloperError(\n `Expected ${name} to be less than or equal to ${limit}, actual value was ${test}`\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'number' and greater than limit\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @param {number} limit The limit value to compare against\n * @exception {DeveloperError} test must be typeof 'number' and greater than limit\n */\nCheck.typeOf.number.greaterThan = function (name, test, limit) {\n Check.typeOf.number(name, test);\n if (test <= limit) {\n throw new DeveloperError(\n `Expected ${name} to be greater than ${limit}, actual value was ${test}`\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'number' and greater than or equal to limit\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @param {number} limit The limit value to compare against\n * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit\n */\nCheck.typeOf.number.greaterThanOrEquals = function (name, test, limit) {\n Check.typeOf.number(name, test);\n if (test < limit) {\n throw new DeveloperError(\n `Expected ${name} to be greater than or equal to ${limit}, actual value was ${test}`\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'object'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'object'\n */\nCheck.typeOf.object = function (name, test) {\n if (typeof test !== \"object\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"object\", name)\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'boolean'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'boolean'\n */\nCheck.typeOf.bool = function (name, test) {\n if (typeof test !== \"boolean\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"boolean\", name)\n );\n }\n};\n\n/**\n * Throws if test is not typeof 'bigint'\n *\n * @param {string} name The name of the variable being tested\n * @param {*} test The value to test\n * @exception {DeveloperError} test must be typeof 'bigint'\n */\nCheck.typeOf.bigint = function (name, test) {\n if (typeof test !== \"bigint\") {\n throw new DeveloperError(\n getFailedTypeErrorMessage(typeof test, \"bigint\", name)\n );\n }\n};\n\n/**\n * Throws if test1 and test2 is not typeof 'number' and not equal in value\n *\n * @param {string} name1 The name of the first variable being tested\n * @param {string} name2 The name of the second variable being tested against\n * @param {*} test1 The value to test\n * @param {*} test2 The value to test against\n * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value\n */\nCheck.typeOf.number.equals = function (name1, name2, test1, test2) {\n Check.typeOf.number(name1, test1);\n Check.typeOf.number(name2, test2);\n if (test1 !== test2) {\n throw new DeveloperError(\n `${name1} must be equal to ${name2}, the actual values are ${test1} and ${test2}`\n );\n }\n};\nexport default Check;\n", "/**\n * Returns the first parameter if not undefined, otherwise the second parameter.\n * Useful for setting a default value for a parameter.\n *\n * @function\n *\n * @param {*} a\n * @param {*} b\n * @returns {*} Returns the first parameter if not undefined, otherwise the second parameter.\n *\n * @example\n * param = Cesium.defaultValue(param, 'default');\n */\nfunction defaultValue(a, b) {\n if (a !== undefined && a !== null) {\n return a;\n }\n return b;\n}\n\n/**\n * A frozen empty object that can be used as the default value for options passed as\n * an object literal.\n * @type {object}\n * @memberof defaultValue\n */\ndefaultValue.EMPTY_OBJECT = Object.freeze({});\n\nexport default defaultValue;\n", "import MersenneTwister from \"mersenne-twister\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Math functions.\n *\n * @exports CesiumMath\n * @alias Math\n */\nconst CesiumMath = {};\n\n/**\n * 0.1\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON1 = 0.1;\n\n/**\n * 0.01\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON2 = 0.01;\n\n/**\n * 0.001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON3 = 0.001;\n\n/**\n * 0.0001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON4 = 0.0001;\n\n/**\n * 0.00001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON5 = 0.00001;\n\n/**\n * 0.000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON6 = 0.000001;\n\n/**\n * 0.0000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON7 = 0.0000001;\n\n/**\n * 0.00000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON8 = 0.00000001;\n\n/**\n * 0.000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON9 = 0.000000001;\n\n/**\n * 0.0000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON10 = 0.0000000001;\n\n/**\n * 0.00000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON11 = 0.00000000001;\n\n/**\n * 0.000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON12 = 0.000000000001;\n\n/**\n * 0.0000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON13 = 0.0000000000001;\n\n/**\n * 0.00000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON14 = 0.00000000000001;\n\n/**\n * 0.000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON15 = 0.000000000000001;\n\n/**\n * 0.0000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON16 = 0.0000000000000001;\n\n/**\n * 0.00000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON17 = 0.00000000000000001;\n\n/**\n * 0.000000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON18 = 0.000000000000000001;\n\n/**\n * 0.0000000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON19 = 0.0000000000000000001;\n\n/**\n * 0.00000000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON20 = 0.00000000000000000001;\n\n/**\n * 0.000000000000000000001\n * @type {number}\n * @constant\n */\nCesiumMath.EPSILON21 = 0.000000000000000000001;\n\n/**\n * The gravitational parameter of the Earth in meters cubed\n * per second squared as defined by the WGS84 model: 3.986004418e14\n * @type {number}\n * @constant\n */\nCesiumMath.GRAVITATIONALPARAMETER = 3.986004418e14;\n\n/**\n * Radius of the sun in meters: 6.955e8\n * @type {number}\n * @constant\n */\nCesiumMath.SOLAR_RADIUS = 6.955e8;\n\n/**\n * The mean radius of the moon, according to the \"Report of the IAU/IAG Working Group on\n * Cartographic Coordinates and Rotational Elements of the Planets and satellites: 2000\",\n * Celestial Mechanics 82: 83-110, 2002.\n * @type {number}\n * @constant\n */\nCesiumMath.LUNAR_RADIUS = 1737400.0;\n\n/**\n * 64 * 1024\n * @type {number}\n * @constant\n */\nCesiumMath.SIXTY_FOUR_KILOBYTES = 64 * 1024;\n\n/**\n * 4 * 1024 * 1024 * 1024\n * @type {number}\n * @constant\n */\nCesiumMath.FOUR_GIGABYTES = 4 * 1024 * 1024 * 1024;\n\n/**\n * Returns the sign of the value; 1 if the value is positive, -1 if the value is\n * negative, or 0 if the value is 0.\n *\n * @function\n * @param {number} value The value to return the sign of.\n * @returns {number} The sign of value.\n */\n// eslint-disable-next-line es/no-math-sign\nCesiumMath.sign = defaultValue(Math.sign, function sign(value) {\n value = +value; // coerce to number\n if (value === 0 || value !== value) {\n // zero or NaN\n return value;\n }\n return value > 0 ? 1 : -1;\n});\n\n/**\n * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.\n * This is similar to {@link CesiumMath#sign} except that returns 1.0 instead of\n * 0.0 when the input value is 0.0.\n * @param {number} value The value to return the sign of.\n * @returns {number} The sign of value.\n */\nCesiumMath.signNotZero = function (value) {\n return value < 0.0 ? -1.0 : 1.0;\n};\n\n/**\n * Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum]\n * @param {number} value The scalar value in the range [-1.0, 1.0]\n * @param {number} [rangeMaximum=255] The maximum value in the mapped range, 255 by default.\n * @returns {number} A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.\n *\n * @see CesiumMath.fromSNorm\n */\nCesiumMath.toSNorm = function (value, rangeMaximum) {\n rangeMaximum = defaultValue(rangeMaximum, 255);\n return Math.round(\n (CesiumMath.clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum\n );\n};\n\n/**\n * Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].\n * @param {number} value SNORM value in the range [0, rangeMaximum]\n * @param {number} [rangeMaximum=255] The maximum value in the SNORM range, 255 by default.\n * @returns {number} Scalar in the range [-1.0, 1.0].\n *\n * @see CesiumMath.toSNorm\n */\nCesiumMath.fromSNorm = function (value, rangeMaximum) {\n rangeMaximum = defaultValue(rangeMaximum, 255);\n return (\n (CesiumMath.clamp(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0\n );\n};\n\n/**\n * Converts a scalar value in the range [rangeMinimum, rangeMaximum] to a scalar in the range [0.0, 1.0]\n * @param {number} value The scalar value in the range [rangeMinimum, rangeMaximum]\n * @param {number} rangeMinimum The minimum value in the mapped range.\n * @param {number} rangeMaximum The maximum value in the mapped range.\n * @returns {number} A scalar value, where rangeMinimum maps to 0.0 and rangeMaximum maps to 1.0.\n */\nCesiumMath.normalize = function (value, rangeMinimum, rangeMaximum) {\n rangeMaximum = Math.max(rangeMaximum - rangeMinimum, 0.0);\n return rangeMaximum === 0.0\n ? 0.0\n : CesiumMath.clamp((value - rangeMinimum) / rangeMaximum, 0.0, 1.0);\n};\n\n/**\n * Returns the hyperbolic sine of a number.\n * The hyperbolic sine of value is defined to be\n * (ex - e-x)/2.0\n * where e is Euler's number, approximately 2.71828183.\n *\n *

Special cases:\n *

    \n *
  • If the argument is NaN, then the result is NaN.
  • \n *\n *
  • If the argument is infinite, then the result is an infinity\n * with the same sign as the argument.
  • \n *\n *
  • If the argument is zero, then the result is a zero with the\n * same sign as the argument.
  • \n *
\n *

\n *\n * @function\n * @param {number} value The number whose hyperbolic sine is to be returned.\n * @returns {number} The hyperbolic sine of value.\n */\n// eslint-disable-next-line es/no-math-sinh\nCesiumMath.sinh = defaultValue(Math.sinh, function sinh(value) {\n return (Math.exp(value) - Math.exp(-value)) / 2.0;\n});\n\n/**\n * Returns the hyperbolic cosine of a number.\n * The hyperbolic cosine of value is defined to be\n * (ex + e-x)/2.0\n * where e is Euler's number, approximately 2.71828183.\n *\n *

Special cases:\n *

    \n *
  • If the argument is NaN, then the result is NaN.
  • \n *\n *
  • If the argument is infinite, then the result is positive infinity.
  • \n *\n *
  • If the argument is zero, then the result is 1.0.
  • \n *
\n *

\n *\n * @function\n * @param {number} value The number whose hyperbolic cosine is to be returned.\n * @returns {number} The hyperbolic cosine of value.\n */\n// eslint-disable-next-line es/no-math-cosh\nCesiumMath.cosh = defaultValue(Math.cosh, function cosh(value) {\n return (Math.exp(value) + Math.exp(-value)) / 2.0;\n});\n\n/**\n * Computes the linear interpolation of two values.\n *\n * @param {number} p The start value to interpolate.\n * @param {number} q The end value to interpolate.\n * @param {number} time The time of interpolation generally in the range [0.0, 1.0].\n * @returns {number} The linearly interpolated value.\n *\n * @example\n * const n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0\n */\nCesiumMath.lerp = function (p, q, time) {\n return (1.0 - time) * p + time * q;\n};\n\n/**\n * pi\n *\n * @type {number}\n * @constant\n */\nCesiumMath.PI = Math.PI;\n\n/**\n * 1/pi\n *\n * @type {number}\n * @constant\n */\nCesiumMath.ONE_OVER_PI = 1.0 / Math.PI;\n\n/**\n * pi/2\n *\n * @type {number}\n * @constant\n */\nCesiumMath.PI_OVER_TWO = Math.PI / 2.0;\n\n/**\n * pi/3\n *\n * @type {number}\n * @constant\n */\nCesiumMath.PI_OVER_THREE = Math.PI / 3.0;\n\n/**\n * pi/4\n *\n * @type {number}\n * @constant\n */\nCesiumMath.PI_OVER_FOUR = Math.PI / 4.0;\n\n/**\n * pi/6\n *\n * @type {number}\n * @constant\n */\nCesiumMath.PI_OVER_SIX = Math.PI / 6.0;\n\n/**\n * 3pi/2\n *\n * @type {number}\n * @constant\n */\nCesiumMath.THREE_PI_OVER_TWO = (3.0 * Math.PI) / 2.0;\n\n/**\n * 2pi\n *\n * @type {number}\n * @constant\n */\nCesiumMath.TWO_PI = 2.0 * Math.PI;\n\n/**\n * 1/2pi\n *\n * @type {number}\n * @constant\n */\nCesiumMath.ONE_OVER_TWO_PI = 1.0 / (2.0 * Math.PI);\n\n/**\n * The number of radians in a degree.\n *\n * @type {number}\n * @constant\n */\nCesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0;\n\n/**\n * The number of degrees in a radian.\n *\n * @type {number}\n * @constant\n */\nCesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI;\n\n/**\n * The number of radians in an arc second.\n *\n * @type {number}\n * @constant\n */\nCesiumMath.RADIANS_PER_ARCSECOND = CesiumMath.RADIANS_PER_DEGREE / 3600.0;\n\n/**\n * Converts degrees to radians.\n * @param {number} degrees The angle to convert in degrees.\n * @returns {number} The corresponding angle in radians.\n */\nCesiumMath.toRadians = function (degrees) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(degrees)) {\n throw new DeveloperError(\"degrees is required.\");\n }\n //>>includeEnd('debug');\n return degrees * CesiumMath.RADIANS_PER_DEGREE;\n};\n\n/**\n * Converts radians to degrees.\n * @param {number} radians The angle to convert in radians.\n * @returns {number} The corresponding angle in degrees.\n */\nCesiumMath.toDegrees = function (radians) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(radians)) {\n throw new DeveloperError(\"radians is required.\");\n }\n //>>includeEnd('debug');\n return radians * CesiumMath.DEGREES_PER_RADIAN;\n};\n\n/**\n * Converts a longitude value, in radians, to the range [-Math.PI, Math.PI).\n *\n * @param {number} angle The longitude value, in radians, to convert to the range [-Math.PI, Math.PI).\n * @returns {number} The equivalent longitude value in the range [-Math.PI, Math.PI).\n *\n * @example\n * // Convert 270 degrees to -90 degrees longitude\n * const longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));\n */\nCesiumMath.convertLongitudeRange = function (angle) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(angle)) {\n throw new DeveloperError(\"angle is required.\");\n }\n //>>includeEnd('debug');\n const twoPi = CesiumMath.TWO_PI;\n\n const simplified = angle - Math.floor(angle / twoPi) * twoPi;\n\n if (simplified < -Math.PI) {\n return simplified + twoPi;\n }\n if (simplified >= Math.PI) {\n return simplified - twoPi;\n }\n\n return simplified;\n};\n\n/**\n * Convenience function that clamps a latitude value, in radians, to the range [-Math.PI/2, Math.PI/2).\n * Useful for sanitizing data before use in objects requiring correct range.\n *\n * @param {number} angle The latitude value, in radians, to clamp to the range [-Math.PI/2, Math.PI/2).\n * @returns {number} The latitude value clamped to the range [-Math.PI/2, Math.PI/2).\n *\n * @example\n * // Clamp 108 degrees latitude to 90 degrees latitude\n * const latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));\n */\nCesiumMath.clampToLatitudeRange = function (angle) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(angle)) {\n throw new DeveloperError(\"angle is required.\");\n }\n //>>includeEnd('debug');\n\n return CesiumMath.clamp(\n angle,\n -1 * CesiumMath.PI_OVER_TWO,\n CesiumMath.PI_OVER_TWO\n );\n};\n\n/**\n * Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.\n *\n * @param {number} angle in radians\n * @returns {number} The angle in the range [-CesiumMath.PI, CesiumMath.PI].\n */\nCesiumMath.negativePiToPi = function (angle) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(angle)) {\n throw new DeveloperError(\"angle is required.\");\n }\n //>>includeEnd('debug');\n if (angle >= -CesiumMath.PI && angle <= CesiumMath.PI) {\n // Early exit if the input is already inside the range. This avoids\n // unnecessary math which could introduce floating point error.\n return angle;\n }\n return CesiumMath.zeroToTwoPi(angle + CesiumMath.PI) - CesiumMath.PI;\n};\n\n/**\n * Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.\n *\n * @param {number} angle in radians\n * @returns {number} The angle in the range [0, CesiumMath.TWO_PI].\n */\nCesiumMath.zeroToTwoPi = function (angle) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(angle)) {\n throw new DeveloperError(\"angle is required.\");\n }\n //>>includeEnd('debug');\n if (angle >= 0 && angle <= CesiumMath.TWO_PI) {\n // Early exit if the input is already inside the range. This avoids\n // unnecessary math which could introduce floating point error.\n return angle;\n }\n const mod = CesiumMath.mod(angle, CesiumMath.TWO_PI);\n if (\n Math.abs(mod) < CesiumMath.EPSILON14 &&\n Math.abs(angle) > CesiumMath.EPSILON14\n ) {\n return CesiumMath.TWO_PI;\n }\n return mod;\n};\n\n/**\n * The modulo operation that also works for negative dividends.\n *\n * @param {number} m The dividend.\n * @param {number} n The divisor.\n * @returns {number} The remainder.\n */\nCesiumMath.mod = function (m, n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(m)) {\n throw new DeveloperError(\"m is required.\");\n }\n if (!defined(n)) {\n throw new DeveloperError(\"n is required.\");\n }\n if (n === 0.0) {\n throw new DeveloperError(\"divisor cannot be 0.\");\n }\n //>>includeEnd('debug');\n if (CesiumMath.sign(m) === CesiumMath.sign(n) && Math.abs(m) < Math.abs(n)) {\n // Early exit if the input does not need to be modded. This avoids\n // unnecessary math which could introduce floating point error.\n return m;\n }\n\n return ((m % n) + n) % n;\n};\n\n/**\n * Determines if two values are equal using an absolute or relative tolerance test. This is useful\n * to avoid problems due to roundoff error when comparing floating-point values directly. The values are\n * first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed.\n * Use this test if you are unsure of the magnitudes of left and right.\n *\n * @param {number} left The first value to compare.\n * @param {number} right The other value to compare.\n * @param {number} [relativeEpsilon=0] The maximum inclusive delta between left and right for the relative tolerance test.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The maximum inclusive delta between left and right for the absolute tolerance test.\n * @returns {boolean} true if the values are equal within the epsilon; otherwise, false.\n *\n * @example\n * const a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true\n * const b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2); // false\n * const c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true\n * const d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false\n */\nCesiumMath.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n relativeEpsilon = defaultValue(relativeEpsilon, 0.0);\n absoluteEpsilon = defaultValue(absoluteEpsilon, relativeEpsilon);\n const absDiff = Math.abs(left - right);\n return (\n absDiff <= absoluteEpsilon ||\n absDiff <= relativeEpsilon * Math.max(Math.abs(left), Math.abs(right))\n );\n};\n\n/**\n * Determines if the left value is less than the right value. If the two values are within\n * absoluteEpsilon of each other, they are considered equal and this function returns false.\n *\n * @param {number} left The first number to compare.\n * @param {number} right The second number to compare.\n * @param {number} absoluteEpsilon The absolute epsilon to use in comparison.\n * @returns {boolean} true if left is less than right by more than\n * absoluteEpsilon. false if left is greater or if the two\n * values are nearly equal.\n */\nCesiumMath.lessThan = function (left, right, absoluteEpsilon) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"first is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"second is required.\");\n }\n if (!defined(absoluteEpsilon)) {\n throw new DeveloperError(\"absoluteEpsilon is required.\");\n }\n //>>includeEnd('debug');\n return left - right < -absoluteEpsilon;\n};\n\n/**\n * Determines if the left value is less than or equal to the right value. If the two values are within\n * absoluteEpsilon of each other, they are considered equal and this function returns true.\n *\n * @param {number} left The first number to compare.\n * @param {number} right The second number to compare.\n * @param {number} absoluteEpsilon The absolute epsilon to use in comparison.\n * @returns {boolean} true if left is less than right or if the\n * the values are nearly equal.\n */\nCesiumMath.lessThanOrEquals = function (left, right, absoluteEpsilon) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"first is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"second is required.\");\n }\n if (!defined(absoluteEpsilon)) {\n throw new DeveloperError(\"absoluteEpsilon is required.\");\n }\n //>>includeEnd('debug');\n return left - right < absoluteEpsilon;\n};\n\n/**\n * Determines if the left value is greater the right value. If the two values are within\n * absoluteEpsilon of each other, they are considered equal and this function returns false.\n *\n * @param {number} left The first number to compare.\n * @param {number} right The second number to compare.\n * @param {number} absoluteEpsilon The absolute epsilon to use in comparison.\n * @returns {boolean} true if left is greater than right by more than\n * absoluteEpsilon. false if left is less or if the two\n * values are nearly equal.\n */\nCesiumMath.greaterThan = function (left, right, absoluteEpsilon) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"first is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"second is required.\");\n }\n if (!defined(absoluteEpsilon)) {\n throw new DeveloperError(\"absoluteEpsilon is required.\");\n }\n //>>includeEnd('debug');\n return left - right > absoluteEpsilon;\n};\n\n/**\n * Determines if the left value is greater than or equal to the right value. If the two values are within\n * absoluteEpsilon of each other, they are considered equal and this function returns true.\n *\n * @param {number} left The first number to compare.\n * @param {number} right The second number to compare.\n * @param {number} absoluteEpsilon The absolute epsilon to use in comparison.\n * @returns {boolean} true if left is greater than right or if the\n * the values are nearly equal.\n */\nCesiumMath.greaterThanOrEquals = function (left, right, absoluteEpsilon) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"first is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"second is required.\");\n }\n if (!defined(absoluteEpsilon)) {\n throw new DeveloperError(\"absoluteEpsilon is required.\");\n }\n //>>includeEnd('debug');\n return left - right > -absoluteEpsilon;\n};\n\nconst factorials = [1];\n\n/**\n * Computes the factorial of the provided number.\n *\n * @param {number} n The number whose factorial is to be computed.\n * @returns {number} The factorial of the provided number or undefined if the number is less than 0.\n *\n * @exception {DeveloperError} A number greater than or equal to 0 is required.\n *\n *\n * @example\n * //Compute 7!, which is equal to 5040\n * const computedFactorial = Cesium.Math.factorial(7);\n *\n * @see {@link http://en.wikipedia.org/wiki/Factorial|Factorial on Wikipedia}\n */\nCesiumMath.factorial = function (n) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof n !== \"number\" || n < 0) {\n throw new DeveloperError(\n \"A number greater than or equal to 0 is required.\"\n );\n }\n //>>includeEnd('debug');\n\n const length = factorials.length;\n if (n >= length) {\n let sum = factorials[length - 1];\n for (let i = length; i <= n; i++) {\n const next = sum * i;\n factorials.push(next);\n sum = next;\n }\n }\n return factorials[n];\n};\n\n/**\n * Increments a number with a wrapping to a minimum value if the number exceeds the maximum value.\n *\n * @param {number} [n] The number to be incremented.\n * @param {number} [maximumValue] The maximum incremented value before rolling over to the minimum value.\n * @param {number} [minimumValue=0.0] The number reset to after the maximum value has been exceeded.\n * @returns {number} The incremented number.\n *\n * @exception {DeveloperError} Maximum value must be greater than minimum value.\n *\n * @example\n * const n = Cesium.Math.incrementWrap(5, 10, 0); // returns 6\n * const m = Cesium.Math.incrementWrap(10, 10, 0); // returns 0\n */\nCesiumMath.incrementWrap = function (n, maximumValue, minimumValue) {\n minimumValue = defaultValue(minimumValue, 0.0);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(n)) {\n throw new DeveloperError(\"n is required.\");\n }\n if (maximumValue <= minimumValue) {\n throw new DeveloperError(\"maximumValue must be greater than minimumValue.\");\n }\n //>>includeEnd('debug');\n\n ++n;\n if (n > maximumValue) {\n n = minimumValue;\n }\n return n;\n};\n\n/**\n * Determines if a non-negative integer is a power of two.\n * The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.\n *\n * @param {number} n The integer to test in the range [0, (2^32)-1].\n * @returns {boolean} true if the number if a power of two; otherwise, false.\n *\n * @exception {DeveloperError} A number between 0 and (2^32)-1 is required.\n *\n * @example\n * const t = Cesium.Math.isPowerOfTwo(16); // true\n * const f = Cesium.Math.isPowerOfTwo(20); // false\n */\nCesiumMath.isPowerOfTwo = function (n) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof n !== \"number\" || n < 0 || n > 4294967295) {\n throw new DeveloperError(\"A number between 0 and (2^32)-1 is required.\");\n }\n //>>includeEnd('debug');\n\n return n !== 0 && (n & (n - 1)) === 0;\n};\n\n/**\n * Computes the next power-of-two integer greater than or equal to the provided non-negative integer.\n * The maximum allowed input is 2^31 due to 32-bit bitwise operator limitation in Javascript.\n *\n * @param {number} n The integer to test in the range [0, 2^31].\n * @returns {number} The next power-of-two integer.\n *\n * @exception {DeveloperError} A number between 0 and 2^31 is required.\n *\n * @example\n * const n = Cesium.Math.nextPowerOfTwo(29); // 32\n * const m = Cesium.Math.nextPowerOfTwo(32); // 32\n */\nCesiumMath.nextPowerOfTwo = function (n) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof n !== \"number\" || n < 0 || n > 2147483648) {\n throw new DeveloperError(\"A number between 0 and 2^31 is required.\");\n }\n //>>includeEnd('debug');\n\n // From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2\n --n;\n n |= n >> 1;\n n |= n >> 2;\n n |= n >> 4;\n n |= n >> 8;\n n |= n >> 16;\n ++n;\n\n return n;\n};\n\n/**\n * Computes the previous power-of-two integer less than or equal to the provided non-negative integer.\n * The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.\n *\n * @param {number} n The integer to test in the range [0, (2^32)-1].\n * @returns {number} The previous power-of-two integer.\n *\n * @exception {DeveloperError} A number between 0 and (2^32)-1 is required.\n *\n * @example\n * const n = Cesium.Math.previousPowerOfTwo(29); // 16\n * const m = Cesium.Math.previousPowerOfTwo(32); // 32\n */\nCesiumMath.previousPowerOfTwo = function (n) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof n !== \"number\" || n < 0 || n > 4294967295) {\n throw new DeveloperError(\"A number between 0 and (2^32)-1 is required.\");\n }\n //>>includeEnd('debug');\n\n n |= n >> 1;\n n |= n >> 2;\n n |= n >> 4;\n n |= n >> 8;\n n |= n >> 16;\n n |= n >> 32;\n\n // The previous bitwise operations implicitly convert to signed 32-bit. Use `>>>` to convert to unsigned\n n = (n >>> 0) - (n >>> 1);\n\n return n;\n};\n\n/**\n * Constraint a value to lie between two values.\n *\n * @param {number} value The value to clamp.\n * @param {number} min The minimum value.\n * @param {number} max The maximum value.\n * @returns {number} The clamped value such that min <= result <= max.\n */\nCesiumMath.clamp = function (value, min, max) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n Check.typeOf.number(\"min\", min);\n Check.typeOf.number(\"max\", max);\n //>>includeEnd('debug');\n\n return value < min ? min : value > max ? max : value;\n};\n\nlet randomNumberGenerator = new MersenneTwister();\n\n/**\n * Sets the seed used by the random number generator\n * in {@link CesiumMath#nextRandomNumber}.\n *\n * @param {number} seed An integer used as the seed.\n */\nCesiumMath.setRandomNumberSeed = function (seed) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(seed)) {\n throw new DeveloperError(\"seed is required.\");\n }\n //>>includeEnd('debug');\n\n randomNumberGenerator = new MersenneTwister(seed);\n};\n\n/**\n * Generates a random floating point number in the range of [0.0, 1.0)\n * using a Mersenne twister.\n *\n * @returns {number} A random number in the range of [0.0, 1.0).\n *\n * @see CesiumMath.setRandomNumberSeed\n * @see {@link http://en.wikipedia.org/wiki/Mersenne_twister|Mersenne twister on Wikipedia}\n */\nCesiumMath.nextRandomNumber = function () {\n return randomNumberGenerator.random();\n};\n\n/**\n * Generates a random number between two numbers.\n *\n * @param {number} min The minimum value.\n * @param {number} max The maximum value.\n * @returns {number} A random number between the min and max.\n */\nCesiumMath.randomBetween = function (min, max) {\n return CesiumMath.nextRandomNumber() * (max - min) + min;\n};\n\n/**\n * Computes Math.acos(value), but first clamps value to the range [-1.0, 1.0]\n * so that the function will never return NaN.\n *\n * @param {number} value The value for which to compute acos.\n * @returns {number} The acos of the value if the value is in the range [-1.0, 1.0], or the acos of -1.0 or 1.0,\n * whichever is closer, if the value is outside the range.\n */\nCesiumMath.acosClamped = function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n return Math.acos(CesiumMath.clamp(value, -1.0, 1.0));\n};\n\n/**\n * Computes Math.asin(value), but first clamps value to the range [-1.0, 1.0]\n * so that the function will never return NaN.\n *\n * @param {number} value The value for which to compute asin.\n * @returns {number} The asin of the value if the value is in the range [-1.0, 1.0], or the asin of -1.0 or 1.0,\n * whichever is closer, if the value is outside the range.\n */\nCesiumMath.asinClamped = function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n return Math.asin(CesiumMath.clamp(value, -1.0, 1.0));\n};\n\n/**\n * Finds the chord length between two points given the circle's radius and the angle between the points.\n *\n * @param {number} angle The angle between the two points.\n * @param {number} radius The radius of the circle.\n * @returns {number} The chord length.\n */\nCesiumMath.chordLength = function (angle, radius) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(angle)) {\n throw new DeveloperError(\"angle is required.\");\n }\n if (!defined(radius)) {\n throw new DeveloperError(\"radius is required.\");\n }\n //>>includeEnd('debug');\n return 2.0 * radius * Math.sin(angle * 0.5);\n};\n\n/**\n * Finds the logarithm of a number to a base.\n *\n * @param {number} number The number.\n * @param {number} base The base.\n * @returns {number} The result.\n */\nCesiumMath.logBase = function (number, base) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(number)) {\n throw new DeveloperError(\"number is required.\");\n }\n if (!defined(base)) {\n throw new DeveloperError(\"base is required.\");\n }\n //>>includeEnd('debug');\n return Math.log(number) / Math.log(base);\n};\n\n/**\n * Finds the cube root of a number.\n * Returns NaN if number is not provided.\n *\n * @function\n * @param {number} [number] The number.\n * @returns {number} The result.\n */\n// eslint-disable-next-line es/no-math-cbrt\nCesiumMath.cbrt = defaultValue(Math.cbrt, function cbrt(number) {\n const result = Math.pow(Math.abs(number), 1.0 / 3.0);\n return number < 0.0 ? -result : result;\n});\n\n/**\n * Finds the base 2 logarithm of a number.\n *\n * @function\n * @param {number} number The number.\n * @returns {number} The result.\n */\n// eslint-disable-next-line es/no-math-log2\nCesiumMath.log2 = defaultValue(Math.log2, function log2(number) {\n return Math.log(number) * Math.LOG2E;\n});\n\n/**\n * @private\n */\nCesiumMath.fog = function (distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n};\n\n/**\n * Computes a fast approximation of Atan for input in the range [-1, 1].\n *\n * Based on Michal Drobot's approximation from ShaderFastLibs,\n * which in turn is based on \"Efficient approximations for the arctangent function,\"\n * Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.\n * Adapted from ShaderFastLibs under MIT License.\n *\n * @param {number} x An input number in the range [-1, 1]\n * @returns {number} An approximation of atan(x)\n */\nCesiumMath.fastApproximateAtan = function (x) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"x\", x);\n //>>includeEnd('debug');\n\n return x * (-0.1784 * Math.abs(x) - 0.0663 * x * x + 1.0301);\n};\n\n/**\n * Computes a fast approximation of Atan2(x, y) for arbitrary input scalars.\n *\n * Range reduction math based on nvidia's cg reference implementation: http://developer.download.nvidia.com/cg/atan2.html\n *\n * @param {number} x An input number that isn't zero if y is zero.\n * @param {number} y An input number that isn't zero if x is zero.\n * @returns {number} An approximation of atan2(x, y)\n */\nCesiumMath.fastApproximateAtan2 = function (x, y) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n //>>includeEnd('debug');\n\n // atan approximations are usually only reliable over [-1, 1]\n // So reduce the range by flipping whether x or y is on top based on which is bigger.\n let opposite;\n let t = Math.abs(x); // t used as swap and atan result.\n opposite = Math.abs(y);\n const adjacent = Math.max(t, opposite);\n opposite = Math.min(t, opposite);\n\n const oppositeOverAdjacent = opposite / adjacent;\n //>>includeStart('debug', pragmas.debug);\n if (isNaN(oppositeOverAdjacent)) {\n throw new DeveloperError(\"either x or y must be nonzero\");\n }\n //>>includeEnd('debug');\n t = CesiumMath.fastApproximateAtan(oppositeOverAdjacent);\n\n // Undo range reduction\n t = Math.abs(y) > Math.abs(x) ? CesiumMath.PI_OVER_TWO - t : t;\n t = x < 0.0 ? CesiumMath.PI - t : t;\n t = y < 0.0 ? -t : t;\n return t;\n};\nexport default CesiumMath;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A 3D Cartesian point.\n * @alias Cartesian3\n * @constructor\n *\n * @param {number} [x=0.0] The X component.\n * @param {number} [y=0.0] The Y component.\n * @param {number} [z=0.0] The Z component.\n *\n * @see Cartesian2\n * @see Cartesian4\n * @see Packable\n */\nfunction Cartesian3(x, y, z) {\n /**\n * The X component.\n * @type {number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The Y component.\n * @type {number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n\n /**\n * The Z component.\n * @type {number}\n * @default 0.0\n */\n this.z = defaultValue(z, 0.0);\n}\n\n/**\n * Converts the provided Spherical into Cartesian3 coordinates.\n *\n * @param {Spherical} spherical The Spherical to be converted to Cartesian3.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nCartesian3.fromSpherical = function (spherical, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"spherical\", spherical);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const clock = spherical.clock;\n const cone = spherical.cone;\n const magnitude = defaultValue(spherical.magnitude, 1.0);\n const radial = magnitude * Math.sin(cone);\n result.x = radial * Math.cos(clock);\n result.y = radial * Math.sin(clock);\n result.z = magnitude * Math.cos(cone);\n return result;\n};\n\n/**\n * Creates a Cartesian3 instance from x, y and z coordinates.\n *\n * @param {number} x The x coordinate.\n * @param {number} y The y coordinate.\n * @param {number} z The z coordinate.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nCartesian3.fromElements = function (x, y, z, result) {\n if (!defined(result)) {\n return new Cartesian3(x, y, z);\n }\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Duplicates a Cartesian3 instance.\n *\n * @param {Cartesian3} cartesian The Cartesian to duplicate.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)\n */\nCartesian3.clone = function (cartesian, result) {\n if (!defined(cartesian)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);\n }\n\n result.x = cartesian.x;\n result.y = cartesian.y;\n result.z = cartesian.z;\n return result;\n};\n\n/**\n * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the\n * x, y, and z properties of the Cartesian4 and drops w.\n * @function\n *\n * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nCartesian3.fromCartesian4 = Cartesian3.clone;\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nCartesian3.packedLength = 3;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Cartesian3} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCartesian3.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex++] = value.y;\n array[startingIndex] = value.z;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Cartesian3} [result] The object into which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nCartesian3.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n result.x = array[startingIndex++];\n result.y = array[startingIndex++];\n result.z = array[startingIndex];\n return result;\n};\n\n/**\n * Flattens an array of Cartesian3s into an array of components.\n *\n * @param {Cartesian3[]} array The array of cartesians to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.\n * @returns {number[]} The packed array.\n */\nCartesian3.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 3;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 3 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Cartesian3.pack(array[i], result, i * 3);\n }\n return result;\n};\n\n/**\n * Unpacks an array of cartesian components into an array of Cartesian3s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Cartesian3[]} [result] The array onto which to store the result.\n * @returns {Cartesian3[]} The unpacked array.\n */\nCartesian3.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 3);\n if (array.length % 3 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 3.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 3);\n } else {\n result.length = length / 3;\n }\n\n for (let i = 0; i < length; i += 3) {\n const index = i / 3;\n result[index] = Cartesian3.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Creates a Cartesian3 from three consecutive elements in an array.\n * @function\n *\n * @param {number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n *\n * @example\n * // Create a Cartesian3 with (1.0, 2.0, 3.0)\n * const v = [1.0, 2.0, 3.0];\n * const p = Cesium.Cartesian3.fromArray(v);\n *\n * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0];\n * const p2 = Cesium.Cartesian3.fromArray(v2, 2);\n */\nCartesian3.fromArray = Cartesian3.unpack;\n\n/**\n * Computes the value of the maximum component for the supplied Cartesian.\n *\n * @param {Cartesian3} cartesian The cartesian to use.\n * @returns {number} The value of the maximum component.\n */\nCartesian3.maximumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.max(cartesian.x, cartesian.y, cartesian.z);\n};\n\n/**\n * Computes the value of the minimum component for the supplied Cartesian.\n *\n * @param {Cartesian3} cartesian The cartesian to use.\n * @returns {number} The value of the minimum component.\n */\nCartesian3.minimumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.min(cartesian.x, cartesian.y, cartesian.z);\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\n *\n * @param {Cartesian3} first A cartesian to compare.\n * @param {Cartesian3} second A cartesian to compare.\n * @param {Cartesian3} result The object into which to store the result.\n * @returns {Cartesian3} A cartesian with the minimum components.\n */\nCartesian3.minimumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.min(first.x, second.x);\n result.y = Math.min(first.y, second.y);\n result.z = Math.min(first.z, second.z);\n\n return result;\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\n *\n * @param {Cartesian3} first A cartesian to compare.\n * @param {Cartesian3} second A cartesian to compare.\n * @param {Cartesian3} result The object into which to store the result.\n * @returns {Cartesian3} A cartesian with the maximum components.\n */\nCartesian3.maximumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.max(first.x, second.x);\n result.y = Math.max(first.y, second.y);\n result.z = Math.max(first.z, second.z);\n return result;\n};\n\n/**\n * Constrain a value to lie between two values.\n *\n * @param {Cartesian3} cartesian The value to clamp.\n * @param {Cartesian3} min The minimum bound.\n * @param {Cartesian3} max The maximum bound.\n * @param {Cartesian3} result The object into which to store the result.\n * @returns {Cartesian3} The clamped value such that min <= value <= max.\n */\nCartesian3.clamp = function (value, min, max, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.typeOf.object(\"min\", min);\n Check.typeOf.object(\"max\", max);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = CesiumMath.clamp(value.x, min.x, max.x);\n const y = CesiumMath.clamp(value.y, min.y, max.y);\n const z = CesiumMath.clamp(value.z, min.z, max.z);\n\n result.x = x;\n result.y = y;\n result.z = z;\n\n return result;\n};\n\n/**\n * Computes the provided Cartesian's squared magnitude.\n *\n * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.\n * @returns {number} The squared magnitude.\n */\nCartesian3.magnitudeSquared = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return (\n cartesian.x * cartesian.x +\n cartesian.y * cartesian.y +\n cartesian.z * cartesian.z\n );\n};\n\n/**\n * Computes the Cartesian's magnitude (length).\n *\n * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.\n * @returns {number} The magnitude.\n */\nCartesian3.magnitude = function (cartesian) {\n return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));\n};\n\nconst distanceScratch = new Cartesian3();\n\n/**\n * Computes the distance between two points.\n *\n * @param {Cartesian3} left The first point to compute the distance from.\n * @param {Cartesian3} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 1.0\n * const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));\n */\nCartesian3.distance = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian3.subtract(left, right, distanceScratch);\n return Cartesian3.magnitude(distanceScratch);\n};\n\n/**\n * Computes the squared distance between two points. Comparing squared distances\n * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.\n *\n * @param {Cartesian3} left The first point to compute the distance from.\n * @param {Cartesian3} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 4.0, not 2.0\n * const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));\n */\nCartesian3.distanceSquared = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian3.subtract(left, right, distanceScratch);\n return Cartesian3.magnitudeSquared(distanceScratch);\n};\n\n/**\n * Computes the normalized form of the supplied Cartesian.\n *\n * @param {Cartesian3} cartesian The Cartesian to be normalized.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.normalize = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const magnitude = Cartesian3.magnitude(cartesian);\n\n result.x = cartesian.x / magnitude;\n result.y = cartesian.y / magnitude;\n result.z = cartesian.z / magnitude;\n\n //>>includeStart('debug', pragmas.debug);\n if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {\n throw new DeveloperError(\"normalized result is not a number\");\n }\n //>>includeEnd('debug');\n\n return result;\n};\n\n/**\n * Computes the dot (scalar) product of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @returns {number} The dot product.\n */\nCartesian3.dot = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return left.x * right.x + left.y * right.y + left.z * right.z;\n};\n\n/**\n * Computes the componentwise product of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.multiplyComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x * right.x;\n result.y = left.y * right.y;\n result.z = left.z * right.z;\n return result;\n};\n\n/**\n * Computes the componentwise quotient of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.divideComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x / right.x;\n result.y = left.y / right.y;\n result.z = left.z / right.z;\n return result;\n};\n\n/**\n * Computes the componentwise sum of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x + right.x;\n result.y = left.y + right.y;\n result.z = left.z + right.z;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x - right.x;\n result.y = left.y - right.y;\n result.z = left.z - right.z;\n return result;\n};\n\n/**\n * Multiplies the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian3} cartesian The Cartesian to be scaled.\n * @param {number} scalar The scalar to multiply with.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.multiplyByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x * scalar;\n result.y = cartesian.y * scalar;\n result.z = cartesian.z * scalar;\n return result;\n};\n\n/**\n * Divides the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian3} cartesian The Cartesian to be divided.\n * @param {number} scalar The scalar to divide by.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.divideByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x / scalar;\n result.y = cartesian.y / scalar;\n result.z = cartesian.z / scalar;\n return result;\n};\n\n/**\n * Negates the provided Cartesian.\n *\n * @param {Cartesian3} cartesian The Cartesian to be negated.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.negate = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -cartesian.x;\n result.y = -cartesian.y;\n result.z = -cartesian.z;\n return result;\n};\n\n/**\n * Computes the absolute value of the provided Cartesian.\n *\n * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.abs = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.abs(cartesian.x);\n result.y = Math.abs(cartesian.y);\n result.z = Math.abs(cartesian.z);\n return result;\n};\n\nconst lerpScratch = new Cartesian3();\n/**\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\n *\n * @param {Cartesian3} start The value corresponding to t at 0.0.\n * @param {Cartesian3} end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nCartesian3.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n Cartesian3.multiplyByScalar(end, t, lerpScratch);\n result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);\n return Cartesian3.add(lerpScratch, result, result);\n};\n\nconst angleBetweenScratch = new Cartesian3();\nconst angleBetweenScratch2 = new Cartesian3();\n/**\n * Returns the angle, in radians, between the provided Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @returns {number} The angle between the Cartesians.\n */\nCartesian3.angleBetween = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian3.normalize(left, angleBetweenScratch);\n Cartesian3.normalize(right, angleBetweenScratch2);\n const cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);\n const sine = Cartesian3.magnitude(\n Cartesian3.cross(\n angleBetweenScratch,\n angleBetweenScratch2,\n angleBetweenScratch\n )\n );\n return Math.atan2(sine, cosine);\n};\n\nconst mostOrthogonalAxisScratch = new Cartesian3();\n/**\n * Returns the axis that is most orthogonal to the provided Cartesian.\n *\n * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The most orthogonal axis.\n */\nCartesian3.mostOrthogonalAxis = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);\n Cartesian3.abs(f, f);\n\n if (f.x <= f.y) {\n if (f.x <= f.z) {\n result = Cartesian3.clone(Cartesian3.UNIT_X, result);\n } else {\n result = Cartesian3.clone(Cartesian3.UNIT_Z, result);\n }\n } else if (f.y <= f.z) {\n result = Cartesian3.clone(Cartesian3.UNIT_Y, result);\n } else {\n result = Cartesian3.clone(Cartesian3.UNIT_Z, result);\n }\n\n return result;\n};\n\n/**\n * Projects vector a onto vector b\n * @param {Cartesian3} a The vector that needs projecting\n * @param {Cartesian3} b The vector to project onto\n * @param {Cartesian3} result The result cartesian\n * @returns {Cartesian3} The modified result parameter\n */\nCartesian3.projectVector = function (a, b, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"a\", a);\n Check.defined(\"b\", b);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n const scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);\n return Cartesian3.multiplyByScalar(b, scalar, result);\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian3} [left] The first Cartesian.\n * @param {Cartesian3} [right] The second Cartesian.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCartesian3.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y &&\n left.z === right.z)\n );\n};\n\n/**\n * @private\n */\nCartesian3.equalsArray = function (cartesian, array, offset) {\n return (\n cartesian.x === array[offset] &&\n cartesian.y === array[offset + 1] &&\n cartesian.z === array[offset + 2]\n );\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian3} [left] The first Cartesian.\n * @param {Cartesian3} [right] The second Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nCartesian3.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n CesiumMath.equalsEpsilon(\n left.x,\n right.x,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.y,\n right.y,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.z,\n right.z,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\n\n/**\n * Computes the cross (outer) product of two Cartesians.\n *\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The cross product.\n */\nCartesian3.cross = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const leftX = left.x;\n const leftY = left.y;\n const leftZ = left.z;\n const rightX = right.x;\n const rightY = right.y;\n const rightZ = right.z;\n\n const x = leftY * rightZ - leftZ * rightY;\n const y = leftZ * rightX - leftX * rightZ;\n const z = leftX * rightY - leftY * rightX;\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes the midpoint between the right and left Cartesian.\n * @param {Cartesian3} left The first Cartesian.\n * @param {Cartesian3} right The second Cartesian.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The midpoint.\n */\nCartesian3.midpoint = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = (left.x + right.x) * 0.5;\n result.y = (left.y + right.y) * 0.5;\n result.z = (left.z + right.z) * 0.5;\n\n return result;\n};\n\n/**\n * Returns a Cartesian3 position from longitude and latitude values given in degrees.\n *\n * @param {number} longitude The longitude, in degrees\n * @param {number} latitude The latitude, in degrees\n * @param {number} [height=0.0] The height, in meters, above the ellipsoid.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The position\n *\n * @example\n * const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);\n */\nCartesian3.fromDegrees = function (\n longitude,\n latitude,\n height,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"longitude\", longitude);\n Check.typeOf.number(\"latitude\", latitude);\n //>>includeEnd('debug');\n\n longitude = CesiumMath.toRadians(longitude);\n latitude = CesiumMath.toRadians(latitude);\n return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);\n};\n\nlet scratchN = new Cartesian3();\nlet scratchK = new Cartesian3();\nconst wgs84RadiiSquared = new Cartesian3(\n 6378137.0 * 6378137.0,\n 6378137.0 * 6378137.0,\n 6356752.3142451793 * 6356752.3142451793\n);\n\n/**\n * Returns a Cartesian3 position from longitude and latitude values given in radians.\n *\n * @param {number} longitude The longitude, in radians\n * @param {number} latitude The latitude, in radians\n * @param {number} [height=0.0] The height, in meters, above the ellipsoid.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The position\n *\n * @example\n * const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);\n */\nCartesian3.fromRadians = function (\n longitude,\n latitude,\n height,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"longitude\", longitude);\n Check.typeOf.number(\"latitude\", latitude);\n //>>includeEnd('debug');\n\n height = defaultValue(height, 0.0);\n const radiiSquared = defined(ellipsoid)\n ? ellipsoid.radiiSquared\n : wgs84RadiiSquared;\n\n const cosLatitude = Math.cos(latitude);\n scratchN.x = cosLatitude * Math.cos(longitude);\n scratchN.y = cosLatitude * Math.sin(longitude);\n scratchN.z = Math.sin(latitude);\n scratchN = Cartesian3.normalize(scratchN, scratchN);\n\n Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);\n const gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));\n scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);\n scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n return Cartesian3.add(scratchK, scratchN, result);\n};\n\n/**\n * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.\n *\n * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\n * @returns {Cartesian3[]} The array of positions.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);\n */\nCartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"coordinates\", coordinates);\n if (coordinates.length < 2 || coordinates.length % 2 !== 0) {\n throw new DeveloperError(\n \"the number of coordinates must be a multiple of 2 and at least 2\"\n );\n }\n //>>includeEnd('debug');\n\n const length = coordinates.length;\n if (!defined(result)) {\n result = new Array(length / 2);\n } else {\n result.length = length / 2;\n }\n\n for (let i = 0; i < length; i += 2) {\n const longitude = coordinates[i];\n const latitude = coordinates[i + 1];\n const index = i / 2;\n result[index] = Cartesian3.fromDegrees(\n longitude,\n latitude,\n 0,\n ellipsoid,\n result[index]\n );\n }\n\n return result;\n};\n\n/**\n * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.\n *\n * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\n * @returns {Cartesian3[]} The array of positions.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);\n */\nCartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"coordinates\", coordinates);\n if (coordinates.length < 2 || coordinates.length % 2 !== 0) {\n throw new DeveloperError(\n \"the number of coordinates must be a multiple of 2 and at least 2\"\n );\n }\n //>>includeEnd('debug');\n\n const length = coordinates.length;\n if (!defined(result)) {\n result = new Array(length / 2);\n } else {\n result.length = length / 2;\n }\n\n for (let i = 0; i < length; i += 2) {\n const longitude = coordinates[i];\n const latitude = coordinates[i + 1];\n const index = i / 2;\n result[index] = Cartesian3.fromRadians(\n longitude,\n latitude,\n 0,\n ellipsoid,\n result[index]\n );\n }\n\n return result;\n};\n\n/**\n * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.\n *\n * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\n * @returns {Cartesian3[]} The array of positions.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);\n */\nCartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"coordinates\", coordinates);\n if (coordinates.length < 3 || coordinates.length % 3 !== 0) {\n throw new DeveloperError(\n \"the number of coordinates must be a multiple of 3 and at least 3\"\n );\n }\n //>>includeEnd('debug');\n\n const length = coordinates.length;\n if (!defined(result)) {\n result = new Array(length / 3);\n } else {\n result.length = length / 3;\n }\n\n for (let i = 0; i < length; i += 3) {\n const longitude = coordinates[i];\n const latitude = coordinates[i + 1];\n const height = coordinates[i + 2];\n const index = i / 3;\n result[index] = Cartesian3.fromDegrees(\n longitude,\n latitude,\n height,\n ellipsoid,\n result[index]\n );\n }\n\n return result;\n};\n\n/**\n * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.\n *\n * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.\n * @returns {Cartesian3[]} The array of positions.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);\n */\nCartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"coordinates\", coordinates);\n if (coordinates.length < 3 || coordinates.length % 3 !== 0) {\n throw new DeveloperError(\n \"the number of coordinates must be a multiple of 3 and at least 3\"\n );\n }\n //>>includeEnd('debug');\n\n const length = coordinates.length;\n if (!defined(result)) {\n result = new Array(length / 3);\n } else {\n result.length = length / 3;\n }\n\n for (let i = 0; i < length; i += 3) {\n const longitude = coordinates[i];\n const latitude = coordinates[i + 1];\n const height = coordinates[i + 2];\n const index = i / 3;\n result[index] = Cartesian3.fromRadians(\n longitude,\n latitude,\n height,\n ellipsoid,\n result[index]\n );\n }\n\n return result;\n};\n\n/**\n * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).\n *\n * @type {Cartesian3}\n * @constant\n */\nCartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));\n\n/**\n * An immutable Cartesian3 instance initialized to (1.0, 1.0, 1.0).\n *\n * @type {Cartesian3}\n * @constant\n */\nCartesian3.ONE = Object.freeze(new Cartesian3(1.0, 1.0, 1.0));\n\n/**\n * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).\n *\n * @type {Cartesian3}\n * @constant\n */\nCartesian3.UNIT_X = Object.freeze(new Cartesian3(1.0, 0.0, 0.0));\n\n/**\n * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).\n *\n * @type {Cartesian3}\n * @constant\n */\nCartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));\n\n/**\n * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).\n *\n * @type {Cartesian3}\n * @constant\n */\nCartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));\n\n/**\n * Duplicates this Cartesian3 instance.\n *\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nCartesian3.prototype.clone = function (result) {\n return Cartesian3.clone(this, result);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian3} [right] The right hand side Cartesian.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nCartesian3.prototype.equals = function (right) {\n return Cartesian3.equals(this, right);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian3} [right] The right hand side Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nCartesian3.prototype.equalsEpsilon = function (\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return Cartesian3.equalsEpsilon(\n this,\n right,\n relativeEpsilon,\n absoluteEpsilon\n );\n};\n\n/**\n * Creates a string representing this Cartesian in the format '(x, y, z)'.\n *\n * @returns {string} A string representing this Cartesian in the format '(x, y, z)'.\n */\nCartesian3.prototype.toString = function () {\n return `(${this.x}, ${this.y}, ${this.z})`;\n};\nexport default Cartesian3;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A 4D Cartesian point.\n * @alias Cartesian4\n * @constructor\n *\n * @param {number} [x=0.0] The X component.\n * @param {number} [y=0.0] The Y component.\n * @param {number} [z=0.0] The Z component.\n * @param {number} [w=0.0] The W component.\n *\n * @see Cartesian2\n * @see Cartesian3\n * @see Packable\n */\nfunction Cartesian4(x, y, z, w) {\n /**\n * The X component.\n * @type {number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The Y component.\n * @type {number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n\n /**\n * The Z component.\n * @type {number}\n * @default 0.0\n */\n this.z = defaultValue(z, 0.0);\n\n /**\n * The W component.\n * @type {number}\n * @default 0.0\n */\n this.w = defaultValue(w, 0.0);\n}\n\n/**\n * Creates a Cartesian4 instance from x, y, z and w coordinates.\n *\n * @param {number} x The x coordinate.\n * @param {number} y The y coordinate.\n * @param {number} z The z coordinate.\n * @param {number} w The w coordinate.\n * @param {Cartesian4} [result] The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\n */\nCartesian4.fromElements = function (x, y, z, w, result) {\n if (!defined(result)) {\n return new Cartesian4(x, y, z, w);\n }\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Creates a Cartesian4 instance from a {@link Color}. red, green, blue,\n * and alpha map to x, y, z, and w, respectively.\n *\n * @param {Color} color The source color.\n * @param {Cartesian4} [result] The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\n */\nCartesian4.fromColor = function (color, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"color\", color);\n //>>includeEnd('debug');\n if (!defined(result)) {\n return new Cartesian4(color.red, color.green, color.blue, color.alpha);\n }\n\n result.x = color.red;\n result.y = color.green;\n result.z = color.blue;\n result.w = color.alpha;\n return result;\n};\n\n/**\n * Duplicates a Cartesian4 instance.\n *\n * @param {Cartesian4} cartesian The Cartesian to duplicate.\n * @param {Cartesian4} [result] The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)\n */\nCartesian4.clone = function (cartesian, result) {\n if (!defined(cartesian)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\n }\n\n result.x = cartesian.x;\n result.y = cartesian.y;\n result.z = cartesian.z;\n result.w = cartesian.w;\n return result;\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nCartesian4.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Cartesian4} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCartesian4.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex++] = value.y;\n array[startingIndex++] = value.z;\n array[startingIndex] = value.w;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Cartesian4} [result] The object into which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\n */\nCartesian4.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Cartesian4();\n }\n result.x = array[startingIndex++];\n result.y = array[startingIndex++];\n result.z = array[startingIndex++];\n result.w = array[startingIndex];\n return result;\n};\n\n/**\n * Flattens an array of Cartesian4s into an array of components.\n *\n * @param {Cartesian4[]} array The array of cartesians to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.\n * @returns {number[]} The packed array.\n */\nCartesian4.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 4;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 4 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Cartesian4.pack(array[i], result, i * 4);\n }\n return result;\n};\n\n/**\n * Unpacks an array of cartesian components into an array of Cartesian4s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Cartesian4[]} [result] The array onto which to store the result.\n * @returns {Cartesian4[]} The unpacked array.\n */\nCartesian4.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 4);\n if (array.length % 4 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 4.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 4);\n } else {\n result.length = length / 4;\n }\n\n for (let i = 0; i < length; i += 4) {\n const index = i / 4;\n result[index] = Cartesian4.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Creates a Cartesian4 from four consecutive elements in an array.\n * @function\n *\n * @param {number[]} array The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\n * @param {Cartesian4} [result] The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\n *\n * @example\n * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)\n * const v = [1.0, 2.0, 3.0, 4.0];\n * const p = Cesium.Cartesian4.fromArray(v);\n *\n * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];\n * const p2 = Cesium.Cartesian4.fromArray(v2, 2);\n */\nCartesian4.fromArray = Cartesian4.unpack;\n\n/**\n * Computes the value of the maximum component for the supplied Cartesian.\n *\n * @param {Cartesian4} cartesian The cartesian to use.\n * @returns {number} The value of the maximum component.\n */\nCartesian4.maximumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\n};\n\n/**\n * Computes the value of the minimum component for the supplied Cartesian.\n *\n * @param {Cartesian4} cartesian The cartesian to use.\n * @returns {number} The value of the minimum component.\n */\nCartesian4.minimumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\n *\n * @param {Cartesian4} first A cartesian to compare.\n * @param {Cartesian4} second A cartesian to compare.\n * @param {Cartesian4} result The object into which to store the result.\n * @returns {Cartesian4} A cartesian with the minimum components.\n */\nCartesian4.minimumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.min(first.x, second.x);\n result.y = Math.min(first.y, second.y);\n result.z = Math.min(first.z, second.z);\n result.w = Math.min(first.w, second.w);\n\n return result;\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\n *\n * @param {Cartesian4} first A cartesian to compare.\n * @param {Cartesian4} second A cartesian to compare.\n * @param {Cartesian4} result The object into which to store the result.\n * @returns {Cartesian4} A cartesian with the maximum components.\n */\nCartesian4.maximumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.max(first.x, second.x);\n result.y = Math.max(first.y, second.y);\n result.z = Math.max(first.z, second.z);\n result.w = Math.max(first.w, second.w);\n\n return result;\n};\n\n/**\n * Constrain a value to lie between two values.\n *\n * @param {Cartesian4} value The value to clamp.\n * @param {Cartesian4} min The minimum bound.\n * @param {Cartesian4} max The maximum bound.\n * @param {Cartesian4} result The object into which to store the result.\n * @returns {Cartesian4} The clamped value such that min <= result <= max.\n */\nCartesian4.clamp = function (value, min, max, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.typeOf.object(\"min\", min);\n Check.typeOf.object(\"max\", max);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = CesiumMath.clamp(value.x, min.x, max.x);\n const y = CesiumMath.clamp(value.y, min.y, max.y);\n const z = CesiumMath.clamp(value.z, min.z, max.z);\n const w = CesiumMath.clamp(value.w, min.w, max.w);\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n\n return result;\n};\n\n/**\n * Computes the provided Cartesian's squared magnitude.\n *\n * @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.\n * @returns {number} The squared magnitude.\n */\nCartesian4.magnitudeSquared = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return (\n cartesian.x * cartesian.x +\n cartesian.y * cartesian.y +\n cartesian.z * cartesian.z +\n cartesian.w * cartesian.w\n );\n};\n\n/**\n * Computes the Cartesian's magnitude (length).\n *\n * @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.\n * @returns {number} The magnitude.\n */\nCartesian4.magnitude = function (cartesian) {\n return Math.sqrt(Cartesian4.magnitudeSquared(cartesian));\n};\n\nconst distanceScratch = new Cartesian4();\n\n/**\n * Computes the 4-space distance between two points.\n *\n * @param {Cartesian4} left The first point to compute the distance from.\n * @param {Cartesian4} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 1.0\n * const d = Cesium.Cartesian4.distance(\n * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),\n * new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));\n */\nCartesian4.distance = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian4.subtract(left, right, distanceScratch);\n return Cartesian4.magnitude(distanceScratch);\n};\n\n/**\n * Computes the squared distance between two points. Comparing squared distances\n * using this function is more efficient than comparing distances using {@link Cartesian4#distance}.\n *\n * @param {Cartesian4} left The first point to compute the distance from.\n * @param {Cartesian4} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 4.0, not 2.0\n * const d = Cesium.Cartesian4.distance(\n * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),\n * new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));\n */\nCartesian4.distanceSquared = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian4.subtract(left, right, distanceScratch);\n return Cartesian4.magnitudeSquared(distanceScratch);\n};\n\n/**\n * Computes the normalized form of the supplied Cartesian.\n *\n * @param {Cartesian4} cartesian The Cartesian to be normalized.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.normalize = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const magnitude = Cartesian4.magnitude(cartesian);\n\n result.x = cartesian.x / magnitude;\n result.y = cartesian.y / magnitude;\n result.z = cartesian.z / magnitude;\n result.w = cartesian.w / magnitude;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n isNaN(result.x) ||\n isNaN(result.y) ||\n isNaN(result.z) ||\n isNaN(result.w)\n ) {\n throw new DeveloperError(\"normalized result is not a number\");\n }\n //>>includeEnd('debug');\n\n return result;\n};\n\n/**\n * Computes the dot (scalar) product of two Cartesians.\n *\n * @param {Cartesian4} left The first Cartesian.\n * @param {Cartesian4} right The second Cartesian.\n * @returns {number} The dot product.\n */\nCartesian4.dot = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return (\n left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w\n );\n};\n\n/**\n * Computes the componentwise product of two Cartesians.\n *\n * @param {Cartesian4} left The first Cartesian.\n * @param {Cartesian4} right The second Cartesian.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.multiplyComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x * right.x;\n result.y = left.y * right.y;\n result.z = left.z * right.z;\n result.w = left.w * right.w;\n return result;\n};\n\n/**\n * Computes the componentwise quotient of two Cartesians.\n *\n * @param {Cartesian4} left The first Cartesian.\n * @param {Cartesian4} right The second Cartesian.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.divideComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x / right.x;\n result.y = left.y / right.y;\n result.z = left.z / right.z;\n result.w = left.w / right.w;\n return result;\n};\n\n/**\n * Computes the componentwise sum of two Cartesians.\n *\n * @param {Cartesian4} left The first Cartesian.\n * @param {Cartesian4} right The second Cartesian.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x + right.x;\n result.y = left.y + right.y;\n result.z = left.z + right.z;\n result.w = left.w + right.w;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two Cartesians.\n *\n * @param {Cartesian4} left The first Cartesian.\n * @param {Cartesian4} right The second Cartesian.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x - right.x;\n result.y = left.y - right.y;\n result.z = left.z - right.z;\n result.w = left.w - right.w;\n return result;\n};\n\n/**\n * Multiplies the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian4} cartesian The Cartesian to be scaled.\n * @param {number} scalar The scalar to multiply with.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.multiplyByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x * scalar;\n result.y = cartesian.y * scalar;\n result.z = cartesian.z * scalar;\n result.w = cartesian.w * scalar;\n return result;\n};\n\n/**\n * Divides the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian4} cartesian The Cartesian to be divided.\n * @param {number} scalar The scalar to divide by.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.divideByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x / scalar;\n result.y = cartesian.y / scalar;\n result.z = cartesian.z / scalar;\n result.w = cartesian.w / scalar;\n return result;\n};\n\n/**\n * Negates the provided Cartesian.\n *\n * @param {Cartesian4} cartesian The Cartesian to be negated.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.negate = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -cartesian.x;\n result.y = -cartesian.y;\n result.z = -cartesian.z;\n result.w = -cartesian.w;\n return result;\n};\n\n/**\n * Computes the absolute value of the provided Cartesian.\n *\n * @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.abs = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.abs(cartesian.x);\n result.y = Math.abs(cartesian.y);\n result.z = Math.abs(cartesian.z);\n result.w = Math.abs(cartesian.w);\n return result;\n};\n\nconst lerpScratch = new Cartesian4();\n/**\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\n *\n * @param {Cartesian4} start The value corresponding to t at 0.0.\n * @param {Cartesian4}end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nCartesian4.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n Cartesian4.multiplyByScalar(end, t, lerpScratch);\n result = Cartesian4.multiplyByScalar(start, 1.0 - t, result);\n return Cartesian4.add(lerpScratch, result, result);\n};\n\nconst mostOrthogonalAxisScratch = new Cartesian4();\n/**\n * Returns the axis that is most orthogonal to the provided Cartesian.\n *\n * @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The most orthogonal axis.\n */\nCartesian4.mostOrthogonalAxis = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);\n Cartesian4.abs(f, f);\n\n if (f.x <= f.y) {\n if (f.x <= f.z) {\n if (f.x <= f.w) {\n result = Cartesian4.clone(Cartesian4.UNIT_X, result);\n } else {\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\n }\n } else if (f.z <= f.w) {\n result = Cartesian4.clone(Cartesian4.UNIT_Z, result);\n } else {\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\n }\n } else if (f.y <= f.z) {\n if (f.y <= f.w) {\n result = Cartesian4.clone(Cartesian4.UNIT_Y, result);\n } else {\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\n }\n } else if (f.z <= f.w) {\n result = Cartesian4.clone(Cartesian4.UNIT_Z, result);\n } else {\n result = Cartesian4.clone(Cartesian4.UNIT_W, result);\n }\n\n return result;\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian4} [left] The first Cartesian.\n * @param {Cartesian4} [right] The second Cartesian.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCartesian4.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y &&\n left.z === right.z &&\n left.w === right.w)\n );\n};\n\n/**\n * @private\n */\nCartesian4.equalsArray = function (cartesian, array, offset) {\n return (\n cartesian.x === array[offset] &&\n cartesian.y === array[offset + 1] &&\n cartesian.z === array[offset + 2] &&\n cartesian.w === array[offset + 3]\n );\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian4} [left] The first Cartesian.\n * @param {Cartesian4} [right] The second Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nCartesian4.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n CesiumMath.equalsEpsilon(\n left.x,\n right.x,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.y,\n right.y,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.z,\n right.z,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.w,\n right.w,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\n\n/**\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.ZERO = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 0.0));\n\n/**\n * An immutable Cartesian4 instance initialized to (1.0, 1.0, 1.0, 1.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.ONE = Object.freeze(new Cartesian4(1.0, 1.0, 1.0, 1.0));\n\n/**\n * An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.UNIT_X = Object.freeze(new Cartesian4(1.0, 0.0, 0.0, 0.0));\n\n/**\n * An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.UNIT_Y = Object.freeze(new Cartesian4(0.0, 1.0, 0.0, 0.0));\n\n/**\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.UNIT_Z = Object.freeze(new Cartesian4(0.0, 0.0, 1.0, 0.0));\n\n/**\n * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).\n *\n * @type {Cartesian4}\n * @constant\n */\nCartesian4.UNIT_W = Object.freeze(new Cartesian4(0.0, 0.0, 0.0, 1.0));\n\n/**\n * Duplicates this Cartesian4 instance.\n *\n * @param {Cartesian4} [result] The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.\n */\nCartesian4.prototype.clone = function (result) {\n return Cartesian4.clone(this, result);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian4} [right] The right hand side Cartesian.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nCartesian4.prototype.equals = function (right) {\n return Cartesian4.equals(this, right);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian4} [right] The right hand side Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nCartesian4.prototype.equalsEpsilon = function (\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return Cartesian4.equalsEpsilon(\n this,\n right,\n relativeEpsilon,\n absoluteEpsilon\n );\n};\n\n/**\n * Creates a string representing this Cartesian in the format '(x, y, z, w)'.\n *\n * @returns {string} A string representing the provided Cartesian in the format '(x, y, z, w)'.\n */\nCartesian4.prototype.toString = function () {\n return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;\n};\n\n// scratchU8Array and scratchF32Array are views into the same buffer\nconst scratchF32Array = new Float32Array(1);\nconst scratchU8Array = new Uint8Array(scratchF32Array.buffer);\n\nconst testU32 = new Uint32Array([0x11223344]);\nconst testU8 = new Uint8Array(testU32.buffer);\nconst littleEndian = testU8[0] === 0x44;\n\n/**\n * Packs an arbitrary floating point value to 4 values representable using uint8.\n *\n * @param {number} value A floating point number.\n * @param {Cartesian4} [result] The Cartesian4 that will contain the packed float.\n * @returns {Cartesian4} A Cartesian4 representing the float packed to values in x, y, z, and w.\n */\nCartesian4.packFloat = function (value, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian4();\n }\n\n // scratchU8Array and scratchF32Array are views into the same buffer\n scratchF32Array[0] = value;\n\n if (littleEndian) {\n result.x = scratchU8Array[0];\n result.y = scratchU8Array[1];\n result.z = scratchU8Array[2];\n result.w = scratchU8Array[3];\n } else {\n // convert from big-endian to little-endian\n result.x = scratchU8Array[3];\n result.y = scratchU8Array[2];\n result.z = scratchU8Array[1];\n result.w = scratchU8Array[0];\n }\n return result;\n};\n\n/**\n * Unpacks a float packed using Cartesian4.packFloat.\n *\n * @param {Cartesian4} packedFloat A Cartesian4 containing a float packed to 4 values representable using uint8.\n * @returns {number} The unpacked float.\n * @private\n */\nCartesian4.unpackFloat = function (packedFloat) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"packedFloat\", packedFloat);\n //>>includeEnd('debug');\n\n // scratchU8Array and scratchF32Array are views into the same buffer\n if (littleEndian) {\n scratchU8Array[0] = packedFloat.x;\n scratchU8Array[1] = packedFloat.y;\n scratchU8Array[2] = packedFloat.z;\n scratchU8Array[3] = packedFloat.w;\n } else {\n // convert from little-endian to big-endian\n scratchU8Array[0] = packedFloat.w;\n scratchU8Array[1] = packedFloat.z;\n scratchU8Array[2] = packedFloat.y;\n scratchU8Array[3] = packedFloat.x;\n }\n return scratchF32Array[0];\n};\nexport default Cartesian4;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A 3x3 matrix, indexable as a column-major order array.\n * Constructor parameters are in row-major order for code readability.\n * @alias Matrix3\n * @constructor\n * @implements {ArrayLike}\n *\n * @param {number} [column0Row0=0.0] The value for column 0, row 0.\n * @param {number} [column1Row0=0.0] The value for column 1, row 0.\n * @param {number} [column2Row0=0.0] The value for column 2, row 0.\n * @param {number} [column0Row1=0.0] The value for column 0, row 1.\n * @param {number} [column1Row1=0.0] The value for column 1, row 1.\n * @param {number} [column2Row1=0.0] The value for column 2, row 1.\n * @param {number} [column0Row2=0.0] The value for column 0, row 2.\n * @param {number} [column1Row2=0.0] The value for column 1, row 2.\n * @param {number} [column2Row2=0.0] The value for column 2, row 2.\n *\n * @see Matrix3.fromArray\n * @see Matrix3.fromColumnMajorArray\n * @see Matrix3.fromRowMajorArray\n * @see Matrix3.fromQuaternion\n * @see Matrix3.fromHeadingPitchRoll\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.fromCrossProduct\n * @see Matrix3.fromRotationX\n * @see Matrix3.fromRotationY\n * @see Matrix3.fromRotationZ\n * @see Matrix2\n * @see Matrix4\n */\nfunction Matrix3(\n column0Row0,\n column1Row0,\n column2Row0,\n column0Row1,\n column1Row1,\n column2Row1,\n column0Row2,\n column1Row2,\n column2Row2\n) {\n this[0] = defaultValue(column0Row0, 0.0);\n this[1] = defaultValue(column0Row1, 0.0);\n this[2] = defaultValue(column0Row2, 0.0);\n this[3] = defaultValue(column1Row0, 0.0);\n this[4] = defaultValue(column1Row1, 0.0);\n this[5] = defaultValue(column1Row2, 0.0);\n this[6] = defaultValue(column2Row0, 0.0);\n this[7] = defaultValue(column2Row1, 0.0);\n this[8] = defaultValue(column2Row2, 0.0);\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nMatrix3.packedLength = 9;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Matrix3} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nMatrix3.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value[0];\n array[startingIndex++] = value[1];\n array[startingIndex++] = value[2];\n array[startingIndex++] = value[3];\n array[startingIndex++] = value[4];\n array[startingIndex++] = value[5];\n array[startingIndex++] = value[6];\n array[startingIndex++] = value[7];\n array[startingIndex++] = value[8];\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Matrix3} [result] The object into which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\n */\nMatrix3.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Matrix3();\n }\n\n result[0] = array[startingIndex++];\n result[1] = array[startingIndex++];\n result[2] = array[startingIndex++];\n result[3] = array[startingIndex++];\n result[4] = array[startingIndex++];\n result[5] = array[startingIndex++];\n result[6] = array[startingIndex++];\n result[7] = array[startingIndex++];\n result[8] = array[startingIndex++];\n return result;\n};\n\n/**\n * Flattens an array of Matrix3s into an array of components. The components\n * are stored in column-major order.\n *\n * @param {Matrix3[]} array The array of matrices to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 9 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 9) elements.\n * @returns {number[]} The packed array.\n */\nMatrix3.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 9;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 9 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Matrix3.pack(array[i], result, i * 9);\n }\n return result;\n};\n\n/**\n * Unpacks an array of column-major matrix components into an array of Matrix3s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Matrix3[]} [result] The array onto which to store the result.\n * @returns {Matrix3[]} The unpacked array.\n */\nMatrix3.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 9);\n if (array.length % 9 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 9.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 9);\n } else {\n result.length = length / 9;\n }\n\n for (let i = 0; i < length; i += 9) {\n const index = i / 9;\n result[index] = Matrix3.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Duplicates a Matrix3 instance.\n *\n * @param {Matrix3} matrix The matrix to duplicate.\n * @param {Matrix3} [result] The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)\n */\nMatrix3.clone = function (matrix, result) {\n if (!defined(matrix)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Matrix3(\n matrix[0],\n matrix[3],\n matrix[6],\n matrix[1],\n matrix[4],\n matrix[7],\n matrix[2],\n matrix[5],\n matrix[8]\n );\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n result[8] = matrix[8];\n return result;\n};\n\n/**\n * Creates a Matrix3 from 9 consecutive elements in an array.\n *\n * @function\n * @param {number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.\n * @param {Matrix3} [result] The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Create the Matrix3:\n * // [1.0, 2.0, 3.0]\n * // [1.0, 2.0, 3.0]\n * // [1.0, 2.0, 3.0]\n *\n * const v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];\n * const m = Cesium.Matrix3.fromArray(v);\n *\n * // Create same Matrix3 with using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];\n * const m2 = Cesium.Matrix3.fromArray(v2, 2);\n */\nMatrix3.fromArray = Matrix3.unpack;\n\n/**\n * Creates a Matrix3 instance from a column-major order array.\n *\n * @param {number[]} values The column-major order array.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n */\nMatrix3.fromColumnMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n return Matrix3.clone(values, result);\n};\n\n/**\n * Creates a Matrix3 instance from a row-major order array.\n * The resulting matrix will be in column-major order.\n *\n * @param {number[]} values The row-major order array.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n */\nMatrix3.fromRowMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix3(\n values[0],\n values[1],\n values[2],\n values[3],\n values[4],\n values[5],\n values[6],\n values[7],\n values[8]\n );\n }\n result[0] = values[0];\n result[1] = values[3];\n result[2] = values[6];\n result[3] = values[1];\n result[4] = values[4];\n result[5] = values[7];\n result[6] = values[2];\n result[7] = values[5];\n result[8] = values[8];\n return result;\n};\n\n/**\n * Computes a 3x3 rotation matrix from the provided quaternion.\n *\n * @param {Quaternion} quaternion the quaternion to use.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.\n */\nMatrix3.fromQuaternion = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n //>>includeEnd('debug');\n\n const x2 = quaternion.x * quaternion.x;\n const xy = quaternion.x * quaternion.y;\n const xz = quaternion.x * quaternion.z;\n const xw = quaternion.x * quaternion.w;\n const y2 = quaternion.y * quaternion.y;\n const yz = quaternion.y * quaternion.z;\n const yw = quaternion.y * quaternion.w;\n const z2 = quaternion.z * quaternion.z;\n const zw = quaternion.z * quaternion.w;\n const w2 = quaternion.w * quaternion.w;\n\n const m00 = x2 - y2 - z2 + w2;\n const m01 = 2.0 * (xy - zw);\n const m02 = 2.0 * (xz + yw);\n\n const m10 = 2.0 * (xy + zw);\n const m11 = -x2 + y2 - z2 + w2;\n const m12 = 2.0 * (yz - xw);\n\n const m20 = 2.0 * (xz - yw);\n const m21 = 2.0 * (yz + xw);\n const m22 = -x2 - y2 + z2 + w2;\n\n if (!defined(result)) {\n return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);\n }\n result[0] = m00;\n result[1] = m10;\n result[2] = m20;\n result[3] = m01;\n result[4] = m11;\n result[5] = m21;\n result[6] = m02;\n result[7] = m12;\n result[8] = m22;\n return result;\n};\n\n/**\n * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )\n *\n * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.\n */\nMatrix3.fromHeadingPitchRoll = function (headingPitchRoll, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"headingPitchRoll\", headingPitchRoll);\n //>>includeEnd('debug');\n\n const cosTheta = Math.cos(-headingPitchRoll.pitch);\n const cosPsi = Math.cos(-headingPitchRoll.heading);\n const cosPhi = Math.cos(headingPitchRoll.roll);\n const sinTheta = Math.sin(-headingPitchRoll.pitch);\n const sinPsi = Math.sin(-headingPitchRoll.heading);\n const sinPhi = Math.sin(headingPitchRoll.roll);\n\n const m00 = cosTheta * cosPsi;\n const m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;\n const m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;\n\n const m10 = cosTheta * sinPsi;\n const m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;\n const m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;\n\n const m20 = -sinTheta;\n const m21 = sinPhi * cosTheta;\n const m22 = cosPhi * cosTheta;\n\n if (!defined(result)) {\n return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);\n }\n result[0] = m00;\n result[1] = m10;\n result[2] = m20;\n result[3] = m01;\n result[4] = m11;\n result[5] = m21;\n result[6] = m02;\n result[7] = m12;\n result[8] = m22;\n return result;\n};\n\n/**\n * Computes a Matrix3 instance representing a non-uniform scale.\n *\n * @param {Cartesian3} scale The x, y, and z scale factors.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [7.0, 0.0, 0.0]\n * // [0.0, 8.0, 0.0]\n * // [0.0, 0.0, 9.0]\n * const m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));\n */\nMatrix3.fromScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix3(scale.x, 0.0, 0.0, 0.0, scale.y, 0.0, 0.0, 0.0, scale.z);\n }\n\n result[0] = scale.x;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = scale.y;\n result[5] = 0.0;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = scale.z;\n return result;\n};\n\n/**\n * Computes a Matrix3 instance representing a uniform scale.\n *\n * @param {number} scale The uniform scale factor.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [2.0, 0.0, 0.0]\n * // [0.0, 2.0, 0.0]\n * // [0.0, 0.0, 2.0]\n * const m = Cesium.Matrix3.fromUniformScale(2.0);\n */\nMatrix3.fromUniformScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix3(scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, scale);\n }\n\n result[0] = scale;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = scale;\n result[5] = 0.0;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = scale;\n return result;\n};\n\n/**\n * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.\n *\n * @param {Cartesian3} vector the vector on the left hand side of the cross product operation.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [0.0, -9.0, 8.0]\n * // [9.0, 0.0, -7.0]\n * // [-8.0, 7.0, 0.0]\n * const m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));\n */\nMatrix3.fromCrossProduct = function (vector, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"vector\", vector);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix3(\n 0.0,\n -vector.z,\n vector.y,\n vector.z,\n 0.0,\n -vector.x,\n -vector.y,\n vector.x,\n 0.0\n );\n }\n\n result[0] = 0.0;\n result[1] = vector.z;\n result[2] = -vector.y;\n result[3] = -vector.z;\n result[4] = 0.0;\n result[5] = vector.x;\n result[6] = vector.y;\n result[7] = -vector.x;\n result[8] = 0.0;\n return result;\n};\n\n/**\n * Creates a rotation matrix around the x-axis.\n *\n * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Rotate a point 45 degrees counterclockwise around the x-axis.\n * const p = new Cesium.Cartesian3(5, 6, 7);\n * const m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));\n * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\n */\nMatrix3.fromRotationX = function (angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const cosAngle = Math.cos(angle);\n const sinAngle = Math.sin(angle);\n\n if (!defined(result)) {\n return new Matrix3(\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n cosAngle,\n -sinAngle,\n 0.0,\n sinAngle,\n cosAngle\n );\n }\n\n result[0] = 1.0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = cosAngle;\n result[5] = sinAngle;\n result[6] = 0.0;\n result[7] = -sinAngle;\n result[8] = cosAngle;\n\n return result;\n};\n\n/**\n * Creates a rotation matrix around the y-axis.\n *\n * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Rotate a point 45 degrees counterclockwise around the y-axis.\n * const p = new Cesium.Cartesian3(5, 6, 7);\n * const m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));\n * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\n */\nMatrix3.fromRotationY = function (angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const cosAngle = Math.cos(angle);\n const sinAngle = Math.sin(angle);\n\n if (!defined(result)) {\n return new Matrix3(\n cosAngle,\n 0.0,\n sinAngle,\n 0.0,\n 1.0,\n 0.0,\n -sinAngle,\n 0.0,\n cosAngle\n );\n }\n\n result[0] = cosAngle;\n result[1] = 0.0;\n result[2] = -sinAngle;\n result[3] = 0.0;\n result[4] = 1.0;\n result[5] = 0.0;\n result[6] = sinAngle;\n result[7] = 0.0;\n result[8] = cosAngle;\n\n return result;\n};\n\n/**\n * Creates a rotation matrix around the z-axis.\n *\n * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\n * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.\n *\n * @example\n * // Rotate a point 45 degrees counterclockwise around the z-axis.\n * const p = new Cesium.Cartesian3(5, 6, 7);\n * const m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));\n * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());\n */\nMatrix3.fromRotationZ = function (angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const cosAngle = Math.cos(angle);\n const sinAngle = Math.sin(angle);\n\n if (!defined(result)) {\n return new Matrix3(\n cosAngle,\n -sinAngle,\n 0.0,\n sinAngle,\n cosAngle,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n\n result[0] = cosAngle;\n result[1] = sinAngle;\n result[2] = 0.0;\n result[3] = -sinAngle;\n result[4] = cosAngle;\n result[5] = 0.0;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 1.0;\n\n return result;\n};\n\n/**\n * Creates an Array from the provided Matrix3 instance.\n * The array will be in column-major order.\n *\n * @param {Matrix3} matrix The matrix to use..\n * @param {number[]} [result] The Array onto which to store the result.\n * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.\n */\nMatrix3.toArray = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return [\n matrix[0],\n matrix[1],\n matrix[2],\n matrix[3],\n matrix[4],\n matrix[5],\n matrix[6],\n matrix[7],\n matrix[8],\n ];\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n result[8] = matrix[8];\n return result;\n};\n\n/**\n * Computes the array index of the element at the provided row and column.\n *\n * @param {number} column The zero-based index of the column.\n * @param {number} row The zero-based index of the row.\n * @returns {number} The index of the element at the provided row and column.\n *\n * @exception {DeveloperError} row must be 0, 1, or 2.\n * @exception {DeveloperError} column must be 0, 1, or 2.\n *\n * @example\n * const myMatrix = new Cesium.Matrix3();\n * const column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);\n * const column1Row0 = myMatrix[column1Row0Index]\n * myMatrix[column1Row0Index] = 10.0;\n */\nMatrix3.getElementIndex = function (column, row) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"row\", row, 0);\n Check.typeOf.number.lessThanOrEquals(\"row\", row, 2);\n Check.typeOf.number.greaterThanOrEquals(\"column\", column, 0);\n Check.typeOf.number.lessThanOrEquals(\"column\", column, 2);\n //>>includeEnd('debug');\n\n return column * 3 + row;\n};\n\n/**\n * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to retrieve.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, or 2.\n */\nMatrix3.getColumn = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const startIndex = index * 3;\n const x = matrix[startIndex];\n const y = matrix[startIndex + 1];\n const z = matrix[startIndex + 2];\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to set.\n * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, or 2.\n */\nMatrix3.setColumn = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix3.clone(matrix, result);\n const startIndex = index * 3;\n result[startIndex] = cartesian.x;\n result[startIndex + 1] = cartesian.y;\n result[startIndex + 2] = cartesian.z;\n return result;\n};\n\n/**\n * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to retrieve.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, or 2.\n */\nMatrix3.getRow = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = matrix[index];\n const y = matrix[index + 3];\n const z = matrix[index + 6];\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to set.\n * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, or 2.\n */\nMatrix3.setRow = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 2);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix3.clone(matrix, result);\n result[index] = cartesian.x;\n result[index + 3] = cartesian.y;\n result[index + 6] = cartesian.z;\n return result;\n};\n\nconst scaleScratch1 = new Cartesian3();\n\n/**\n * Computes a new matrix that replaces the scale with the provided scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @see Matrix3.setUniformScale\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.multiplyByScale\n * @see Matrix3.multiplyByUniformScale\n * @see Matrix3.getScale\n */\nMatrix3.setScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix3.getScale(matrix, scaleScratch1);\n const scaleRatioX = scale.x / existingScale.x;\n const scaleRatioY = scale.y / existingScale.y;\n const scaleRatioZ = scale.z / existingScale.z;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioX;\n result[3] = matrix[3] * scaleRatioY;\n result[4] = matrix[4] * scaleRatioY;\n result[5] = matrix[5] * scaleRatioY;\n result[6] = matrix[6] * scaleRatioZ;\n result[7] = matrix[7] * scaleRatioZ;\n result[8] = matrix[8] * scaleRatioZ;\n\n return result;\n};\n\nconst scaleScratch2 = new Cartesian3();\n\n/**\n * Computes a new matrix that replaces the scale with the provided uniform scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @param {number} scale The uniform scale that replaces the scale of the provided matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @see Matrix3.setScale\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.multiplyByScale\n * @see Matrix3.multiplyByUniformScale\n * @see Matrix3.getScale\n */\nMatrix3.setUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix3.getScale(matrix, scaleScratch2);\n const scaleRatioX = scale / existingScale.x;\n const scaleRatioY = scale / existingScale.y;\n const scaleRatioZ = scale / existingScale.z;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioX;\n result[3] = matrix[3] * scaleRatioY;\n result[4] = matrix[4] * scaleRatioY;\n result[5] = matrix[5] * scaleRatioY;\n result[6] = matrix[6] * scaleRatioZ;\n result[7] = matrix[7] * scaleRatioZ;\n result[8] = matrix[8] * scaleRatioZ;\n\n return result;\n};\n\nconst scratchColumn = new Cartesian3();\n\n/**\n * Extracts the non-uniform scale assuming the matrix is an affine transformation.\n *\n * @param {Matrix3} matrix The matrix.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n *\n * @see Matrix3.multiplyByScale\n * @see Matrix3.multiplyByUniformScale\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.setScale\n * @see Matrix3.setUniformScale\n */\nMatrix3.getScale = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)\n );\n result.y = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn)\n );\n result.z = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn)\n );\n return result;\n};\n\nconst scaleScratch3 = new Cartesian3();\n\n/**\n * Computes the maximum scale assuming the matrix is an affine transformation.\n * The maximum scale is the maximum length of the column vectors.\n *\n * @param {Matrix3} matrix The matrix.\n * @returns {number} The maximum scale.\n */\nMatrix3.getMaximumScale = function (matrix) {\n Matrix3.getScale(matrix, scaleScratch3);\n return Cartesian3.maximumComponent(scaleScratch3);\n};\n\nconst scaleScratch4 = new Cartesian3();\n\n/**\n * Sets the rotation assuming the matrix is an affine transformation.\n *\n * @param {Matrix3} matrix The matrix.\n * @param {Matrix3} rotation The rotation matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @see Matrix3.getRotation\n */\nMatrix3.setRotation = function (matrix, rotation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix3.getScale(matrix, scaleScratch4);\n\n result[0] = rotation[0] * scale.x;\n result[1] = rotation[1] * scale.x;\n result[2] = rotation[2] * scale.x;\n result[3] = rotation[3] * scale.y;\n result[4] = rotation[4] * scale.y;\n result[5] = rotation[5] * scale.y;\n result[6] = rotation[6] * scale.z;\n result[7] = rotation[7] * scale.z;\n result[8] = rotation[8] * scale.z;\n\n return result;\n};\n\nconst scaleScratch5 = new Cartesian3();\n\n/**\n * Extracts the rotation matrix assuming the matrix is an affine transformation.\n *\n * @param {Matrix3} matrix The matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @see Matrix3.setRotation\n */\nMatrix3.getRotation = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix3.getScale(matrix, scaleScratch5);\n\n result[0] = matrix[0] / scale.x;\n result[1] = matrix[1] / scale.x;\n result[2] = matrix[2] / scale.x;\n result[3] = matrix[3] / scale.y;\n result[4] = matrix[4] / scale.y;\n result[5] = matrix[5] / scale.y;\n result[6] = matrix[6] / scale.z;\n result[7] = matrix[7] / scale.z;\n result[8] = matrix[8] / scale.z;\n\n return result;\n};\n\n/**\n * Computes the product of two matrices.\n *\n * @param {Matrix3} left The first matrix.\n * @param {Matrix3} right The second matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 =\n left[0] * right[0] + left[3] * right[1] + left[6] * right[2];\n const column0Row1 =\n left[1] * right[0] + left[4] * right[1] + left[7] * right[2];\n const column0Row2 =\n left[2] * right[0] + left[5] * right[1] + left[8] * right[2];\n\n const column1Row0 =\n left[0] * right[3] + left[3] * right[4] + left[6] * right[5];\n const column1Row1 =\n left[1] * right[3] + left[4] * right[4] + left[7] * right[5];\n const column1Row2 =\n left[2] * right[3] + left[5] * right[4] + left[8] * right[5];\n\n const column2Row0 =\n left[0] * right[6] + left[3] * right[7] + left[6] * right[8];\n const column2Row1 =\n left[1] * right[6] + left[4] * right[7] + left[7] * right[8];\n const column2Row2 =\n left[2] * right[6] + left[5] * right[7] + left[8] * right[8];\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column0Row2;\n result[3] = column1Row0;\n result[4] = column1Row1;\n result[5] = column1Row2;\n result[6] = column2Row0;\n result[7] = column2Row1;\n result[8] = column2Row2;\n return result;\n};\n\n/**\n * Computes the sum of two matrices.\n *\n * @param {Matrix3} left The first matrix.\n * @param {Matrix3} right The second matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] + right[0];\n result[1] = left[1] + right[1];\n result[2] = left[2] + right[2];\n result[3] = left[3] + right[3];\n result[4] = left[4] + right[4];\n result[5] = left[5] + right[5];\n result[6] = left[6] + right[6];\n result[7] = left[7] + right[7];\n result[8] = left[8] + right[8];\n return result;\n};\n\n/**\n * Computes the difference of two matrices.\n *\n * @param {Matrix3} left The first matrix.\n * @param {Matrix3} right The second matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] - right[0];\n result[1] = left[1] - right[1];\n result[2] = left[2] - right[2];\n result[3] = left[3] - right[3];\n result[4] = left[4] - right[4];\n result[5] = left[5] - right[5];\n result[6] = left[6] - right[6];\n result[7] = left[7] - right[7];\n result[8] = left[8] - right[8];\n return result;\n};\n\n/**\n * Computes the product of a matrix and a column vector.\n *\n * @param {Matrix3} matrix The matrix.\n * @param {Cartesian3} cartesian The column.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nMatrix3.multiplyByVector = function (matrix, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const vX = cartesian.x;\n const vY = cartesian.y;\n const vZ = cartesian.z;\n\n const x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;\n const y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;\n const z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes the product of a matrix and a scalar.\n *\n * @param {Matrix3} matrix The matrix.\n * @param {number} scalar The number to multiply by.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.multiplyByScalar = function (matrix, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scalar;\n result[1] = matrix[1] * scalar;\n result[2] = matrix[2] * scalar;\n result[3] = matrix[3] * scalar;\n result[4] = matrix[4] * scalar;\n result[5] = matrix[5] * scalar;\n result[6] = matrix[6] * scalar;\n result[7] = matrix[7] * scalar;\n result[8] = matrix[8] * scalar;\n return result;\n};\n\n/**\n * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.\n *\n * @param {Matrix3} matrix The matrix on the left-hand side.\n * @param {Cartesian3} scale The non-uniform scale on the right-hand side.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n *\n * @example\n * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);\n * Cesium.Matrix3.multiplyByScale(m, scale, m);\n *\n * @see Matrix3.multiplyByUniformScale\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.setScale\n * @see Matrix3.setUniformScale\n * @see Matrix3.getScale\n */\nMatrix3.multiplyByScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scale.x;\n result[1] = matrix[1] * scale.x;\n result[2] = matrix[2] * scale.x;\n result[3] = matrix[3] * scale.y;\n result[4] = matrix[4] * scale.y;\n result[5] = matrix[5] * scale.y;\n result[6] = matrix[6] * scale.z;\n result[7] = matrix[7] * scale.z;\n result[8] = matrix[8] * scale.z;\n\n return result;\n};\n\n/**\n * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.\n *\n * @param {Matrix3} matrix The matrix on the left-hand side.\n * @param {number} scale The uniform scale on the right-hand side.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @example\n * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromUniformScale(scale), m);\n * Cesium.Matrix3.multiplyByUniformScale(m, scale, m);\n *\n * @see Matrix3.multiplyByScale\n * @see Matrix3.fromScale\n * @see Matrix3.fromUniformScale\n * @see Matrix3.setScale\n * @see Matrix3.setUniformScale\n * @see Matrix3.getScale\n */\nMatrix3.multiplyByUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scale;\n result[1] = matrix[1] * scale;\n result[2] = matrix[2] * scale;\n result[3] = matrix[3] * scale;\n result[4] = matrix[4] * scale;\n result[5] = matrix[5] * scale;\n result[6] = matrix[6] * scale;\n result[7] = matrix[7] * scale;\n result[8] = matrix[8] * scale;\n\n return result;\n};\n\n/**\n * Creates a negated copy of the provided matrix.\n *\n * @param {Matrix3} matrix The matrix to negate.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.negate = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = -matrix[0];\n result[1] = -matrix[1];\n result[2] = -matrix[2];\n result[3] = -matrix[3];\n result[4] = -matrix[4];\n result[5] = -matrix[5];\n result[6] = -matrix[6];\n result[7] = -matrix[7];\n result[8] = -matrix[8];\n return result;\n};\n\n/**\n * Computes the transpose of the provided matrix.\n *\n * @param {Matrix3} matrix The matrix to transpose.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.transpose = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 = matrix[0];\n const column0Row1 = matrix[3];\n const column0Row2 = matrix[6];\n const column1Row0 = matrix[1];\n const column1Row1 = matrix[4];\n const column1Row2 = matrix[7];\n const column2Row0 = matrix[2];\n const column2Row1 = matrix[5];\n const column2Row2 = matrix[8];\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column0Row2;\n result[3] = column1Row0;\n result[4] = column1Row1;\n result[5] = column1Row2;\n result[6] = column2Row0;\n result[7] = column2Row1;\n result[8] = column2Row2;\n return result;\n};\n\nfunction computeFrobeniusNorm(matrix) {\n let norm = 0.0;\n for (let i = 0; i < 9; ++i) {\n const temp = matrix[i];\n norm += temp * temp;\n }\n\n return Math.sqrt(norm);\n}\n\nconst rowVal = [1, 0, 0];\nconst colVal = [2, 2, 1];\n\nfunction offDiagonalFrobeniusNorm(matrix) {\n // Computes the \"off-diagonal\" Frobenius norm.\n // Assumes matrix is symmetric.\n\n let norm = 0.0;\n for (let i = 0; i < 3; ++i) {\n const temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];\n norm += 2.0 * temp * temp;\n }\n\n return Math.sqrt(norm);\n}\n\nfunction shurDecomposition(matrix, result) {\n // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n // section 8.4.2 The 2by2 Symmetric Schur Decomposition.\n //\n // The routine takes a matrix, which is assumed to be symmetric, and\n // finds the largest off-diagonal term, and then creates\n // a matrix (result) which can be used to help reduce it\n\n const tolerance = CesiumMath.EPSILON15;\n\n let maxDiagonal = 0.0;\n let rotAxis = 1;\n\n // find pivot (rotAxis) based on max diagonal of matrix\n for (let i = 0; i < 3; ++i) {\n const temp = Math.abs(\n matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]\n );\n if (temp > maxDiagonal) {\n rotAxis = i;\n maxDiagonal = temp;\n }\n }\n\n let c = 1.0;\n let s = 0.0;\n\n const p = rowVal[rotAxis];\n const q = colVal[rotAxis];\n\n if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {\n const qq = matrix[Matrix3.getElementIndex(q, q)];\n const pp = matrix[Matrix3.getElementIndex(p, p)];\n const qp = matrix[Matrix3.getElementIndex(q, p)];\n\n const tau = (qq - pp) / 2.0 / qp;\n let t;\n\n if (tau < 0.0) {\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\n } else {\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\n }\n\n c = 1.0 / Math.sqrt(1.0 + t * t);\n s = t * c;\n }\n\n result = Matrix3.clone(Matrix3.IDENTITY, result);\n\n result[Matrix3.getElementIndex(p, p)] = result[\n Matrix3.getElementIndex(q, q)\n ] = c;\n result[Matrix3.getElementIndex(q, p)] = s;\n result[Matrix3.getElementIndex(p, q)] = -s;\n\n return result;\n}\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *

\n * Returns a diagonal matrix and unitary matrix such that:\n * matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)\n *

\n *

\n * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n *

\n *\n * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param {object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns {object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symetric matrix\n * const result = {\n * unitary : new Cesium.Matrix3(),\n * diagonal : new Cesium.Matrix3()\n * };\n * Cesium.Matrix3.computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());\n * const b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());\n * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue\n * const v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector\n * const c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)\n */\nMatrix3.computeEigenDecomposition = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n // section 8.4.3 The Classical Jacobi Algorithm\n\n const tolerance = CesiumMath.EPSILON20;\n const maxSweeps = 10;\n\n let count = 0;\n let sweep = 0;\n\n if (!defined(result)) {\n result = {};\n }\n\n const unitaryMatrix = (result.unitary = Matrix3.clone(\n Matrix3.IDENTITY,\n result.unitary\n ));\n const diagMatrix = (result.diagonal = Matrix3.clone(matrix, result.diagonal));\n\n const epsilon = tolerance * computeFrobeniusNorm(diagMatrix);\n\n while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {\n shurDecomposition(diagMatrix, jMatrix);\n Matrix3.transpose(jMatrix, jMatrixTranspose);\n Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);\n Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);\n Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n return result;\n};\n\n/**\n * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.\n *\n * @param {Matrix3} matrix The matrix with signed elements.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.abs = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = Math.abs(matrix[0]);\n result[1] = Math.abs(matrix[1]);\n result[2] = Math.abs(matrix[2]);\n result[3] = Math.abs(matrix[3]);\n result[4] = Math.abs(matrix[4]);\n result[5] = Math.abs(matrix[5]);\n result[6] = Math.abs(matrix[6]);\n result[7] = Math.abs(matrix[7]);\n result[8] = Math.abs(matrix[8]);\n\n return result;\n};\n\n/**\n * Computes the determinant of the provided matrix.\n *\n * @param {Matrix3} matrix The matrix to use.\n * @returns {number} The value of the determinant of the matrix.\n */\nMatrix3.determinant = function (matrix) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n const m11 = matrix[0];\n const m21 = matrix[3];\n const m31 = matrix[6];\n const m12 = matrix[1];\n const m22 = matrix[4];\n const m32 = matrix[7];\n const m13 = matrix[2];\n const m23 = matrix[5];\n const m33 = matrix[8];\n\n return (\n m11 * (m22 * m33 - m23 * m32) +\n m12 * (m23 * m31 - m21 * m33) +\n m13 * (m21 * m32 - m22 * m31)\n );\n};\n\n/**\n * Computes the inverse of the provided matrix.\n *\n * @param {Matrix3} matrix The matrix to invert.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @exception {DeveloperError} matrix is not invertible.\n */\nMatrix3.inverse = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const m11 = matrix[0];\n const m21 = matrix[1];\n const m31 = matrix[2];\n const m12 = matrix[3];\n const m22 = matrix[4];\n const m32 = matrix[5];\n const m13 = matrix[6];\n const m23 = matrix[7];\n const m33 = matrix[8];\n\n const determinant = Matrix3.determinant(matrix);\n\n //>>includeStart('debug', pragmas.debug);\n if (Math.abs(determinant) <= CesiumMath.EPSILON15) {\n throw new DeveloperError(\"matrix is not invertible\");\n }\n //>>includeEnd('debug');\n\n result[0] = m22 * m33 - m23 * m32;\n result[1] = m23 * m31 - m21 * m33;\n result[2] = m21 * m32 - m22 * m31;\n result[3] = m13 * m32 - m12 * m33;\n result[4] = m11 * m33 - m13 * m31;\n result[5] = m12 * m31 - m11 * m32;\n result[6] = m12 * m23 - m13 * m22;\n result[7] = m13 * m21 - m11 * m23;\n result[8] = m11 * m22 - m12 * m21;\n\n const scale = 1.0 / determinant;\n return Matrix3.multiplyByScalar(result, scale, result);\n};\n\nconst scratchTransposeMatrix = new Matrix3();\n\n/**\n * Computes the inverse transpose of a matrix.\n *\n * @param {Matrix3} matrix The matrix to transpose and invert.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n */\nMatrix3.inverseTranspose = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n return Matrix3.inverse(\n Matrix3.transpose(matrix, scratchTransposeMatrix),\n result\n );\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix3} [left] The first matrix.\n * @param {Matrix3} [right] The second matrix.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nMatrix3.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left[0] === right[0] &&\n left[1] === right[1] &&\n left[2] === right[2] &&\n left[3] === right[3] &&\n left[4] === right[4] &&\n left[5] === right[5] &&\n left[6] === right[6] &&\n left[7] === right[7] &&\n left[8] === right[8])\n );\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix3} [left] The first matrix.\n * @param {Matrix3} [right] The second matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nMatrix3.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left[0] - right[0]) <= epsilon &&\n Math.abs(left[1] - right[1]) <= epsilon &&\n Math.abs(left[2] - right[2]) <= epsilon &&\n Math.abs(left[3] - right[3]) <= epsilon &&\n Math.abs(left[4] - right[4]) <= epsilon &&\n Math.abs(left[5] - right[5]) <= epsilon &&\n Math.abs(left[6] - right[6]) <= epsilon &&\n Math.abs(left[7] - right[7]) <= epsilon &&\n Math.abs(left[8] - right[8]) <= epsilon)\n );\n};\n\n/**\n * An immutable Matrix3 instance initialized to the identity matrix.\n *\n * @type {Matrix3}\n * @constant\n */\nMatrix3.IDENTITY = Object.freeze(\n new Matrix3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)\n);\n\n/**\n * An immutable Matrix3 instance initialized to the zero matrix.\n *\n * @type {Matrix3}\n * @constant\n */\nMatrix3.ZERO = Object.freeze(\n new Matrix3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)\n);\n\n/**\n * The index into Matrix3 for column 0, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN0ROW0 = 0;\n\n/**\n * The index into Matrix3 for column 0, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN0ROW1 = 1;\n\n/**\n * The index into Matrix3 for column 0, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN0ROW2 = 2;\n\n/**\n * The index into Matrix3 for column 1, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN1ROW0 = 3;\n\n/**\n * The index into Matrix3 for column 1, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN1ROW1 = 4;\n\n/**\n * The index into Matrix3 for column 1, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN1ROW2 = 5;\n\n/**\n * The index into Matrix3 for column 2, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN2ROW0 = 6;\n\n/**\n * The index into Matrix3 for column 2, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN2ROW1 = 7;\n\n/**\n * The index into Matrix3 for column 2, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix3.COLUMN2ROW2 = 8;\n\nObject.defineProperties(Matrix3.prototype, {\n /**\n * Gets the number of items in the collection.\n * @memberof Matrix3.prototype\n *\n * @type {number}\n */\n length: {\n get: function () {\n return Matrix3.packedLength;\n },\n },\n});\n\n/**\n * Duplicates the provided Matrix3 instance.\n *\n * @param {Matrix3} [result] The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.\n */\nMatrix3.prototype.clone = function (result) {\n return Matrix3.clone(this, result);\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix3} [right] The right hand side matrix.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nMatrix3.prototype.equals = function (right) {\n return Matrix3.equals(this, right);\n};\n\n/**\n * @private\n */\nMatrix3.equalsArray = function (matrix, array, offset) {\n return (\n matrix[0] === array[offset] &&\n matrix[1] === array[offset + 1] &&\n matrix[2] === array[offset + 2] &&\n matrix[3] === array[offset + 3] &&\n matrix[4] === array[offset + 4] &&\n matrix[5] === array[offset + 5] &&\n matrix[6] === array[offset + 6] &&\n matrix[7] === array[offset + 7] &&\n matrix[8] === array[offset + 8]\n );\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix3} [right] The right hand side matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nMatrix3.prototype.equalsEpsilon = function (right, epsilon) {\n return Matrix3.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Creates a string representing this Matrix with each row being\n * on a separate line and in the format '(column0, column1, column2)'.\n *\n * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.\n */\nMatrix3.prototype.toString = function () {\n return (\n `(${this[0]}, ${this[3]}, ${this[6]})\\n` +\n `(${this[1]}, ${this[4]}, ${this[7]})\\n` +\n `(${this[2]}, ${this[5]}, ${this[8]})`\n );\n};\nexport default Matrix3;\n", "import defined from \"./defined.js\";\n\n/**\n * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,\n * out of memory, could not compile shader, etc. If a function may throw this\n * exception, the calling code should be prepared to catch it.\n *

\n * On the other hand, a {@link DeveloperError} indicates an exception due\n * to a developer error, e.g., invalid argument, that usually indicates a bug in the\n * calling code.\n *\n * @alias RuntimeError\n * @constructor\n * @extends Error\n *\n * @param {string} [message] The error message for this exception.\n *\n * @see DeveloperError\n */\nfunction RuntimeError(message) {\n /**\n * 'RuntimeError' indicating that this exception was thrown due to a runtime error.\n * @type {string}\n * @readonly\n */\n this.name = \"RuntimeError\";\n\n /**\n * The explanation for why this exception was thrown.\n * @type {string}\n * @readonly\n */\n this.message = message;\n\n //Browsers such as IE don't have a stack property until you actually throw the error.\n let stack;\n try {\n throw new Error();\n } catch (e) {\n stack = e.stack;\n }\n\n /**\n * The stack trace of this exception, if available.\n * @type {string}\n * @readonly\n */\n this.stack = stack;\n}\n\nif (defined(Object.create)) {\n RuntimeError.prototype = Object.create(Error.prototype);\n RuntimeError.prototype.constructor = RuntimeError;\n}\n\nRuntimeError.prototype.toString = function () {\n let str = `${this.name}: ${this.message}`;\n\n if (defined(this.stack)) {\n str += `\\n${this.stack.toString()}`;\n }\n\n return str;\n};\nexport default RuntimeError;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\n/**\n * A 4x4 matrix, indexable as a column-major order array.\n * Constructor parameters are in row-major order for code readability.\n * @alias Matrix4\n * @constructor\n * @implements {ArrayLike}\n *\n * @param {number} [column0Row0=0.0] The value for column 0, row 0.\n * @param {number} [column1Row0=0.0] The value for column 1, row 0.\n * @param {number} [column2Row0=0.0] The value for column 2, row 0.\n * @param {number} [column3Row0=0.0] The value for column 3, row 0.\n * @param {number} [column0Row1=0.0] The value for column 0, row 1.\n * @param {number} [column1Row1=0.0] The value for column 1, row 1.\n * @param {number} [column2Row1=0.0] The value for column 2, row 1.\n * @param {number} [column3Row1=0.0] The value for column 3, row 1.\n * @param {number} [column0Row2=0.0] The value for column 0, row 2.\n * @param {number} [column1Row2=0.0] The value for column 1, row 2.\n * @param {number} [column2Row2=0.0] The value for column 2, row 2.\n * @param {number} [column3Row2=0.0] The value for column 3, row 2.\n * @param {number} [column0Row3=0.0] The value for column 0, row 3.\n * @param {number} [column1Row3=0.0] The value for column 1, row 3.\n * @param {number} [column2Row3=0.0] The value for column 2, row 3.\n * @param {number} [column3Row3=0.0] The value for column 3, row 3.\n *\n * @see Matrix4.fromArray\n * @see Matrix4.fromColumnMajorArray\n * @see Matrix4.fromRowMajorArray\n * @see Matrix4.fromRotationTranslation\n * @see Matrix4.fromTranslationQuaternionRotationScale\n * @see Matrix4.fromTranslationRotationScale\n * @see Matrix4.fromTranslation\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.fromRotation\n * @see Matrix4.fromCamera\n * @see Matrix4.computePerspectiveFieldOfView\n * @see Matrix4.computeOrthographicOffCenter\n * @see Matrix4.computePerspectiveOffCenter\n * @see Matrix4.computeInfinitePerspectiveOffCenter\n * @see Matrix4.computeViewportTransformation\n * @see Matrix4.computeView\n * @see Matrix2\n * @see Matrix3\n * @see Packable\n */\nfunction Matrix4(\n column0Row0,\n column1Row0,\n column2Row0,\n column3Row0,\n column0Row1,\n column1Row1,\n column2Row1,\n column3Row1,\n column0Row2,\n column1Row2,\n column2Row2,\n column3Row2,\n column0Row3,\n column1Row3,\n column2Row3,\n column3Row3\n) {\n this[0] = defaultValue(column0Row0, 0.0);\n this[1] = defaultValue(column0Row1, 0.0);\n this[2] = defaultValue(column0Row2, 0.0);\n this[3] = defaultValue(column0Row3, 0.0);\n this[4] = defaultValue(column1Row0, 0.0);\n this[5] = defaultValue(column1Row1, 0.0);\n this[6] = defaultValue(column1Row2, 0.0);\n this[7] = defaultValue(column1Row3, 0.0);\n this[8] = defaultValue(column2Row0, 0.0);\n this[9] = defaultValue(column2Row1, 0.0);\n this[10] = defaultValue(column2Row2, 0.0);\n this[11] = defaultValue(column2Row3, 0.0);\n this[12] = defaultValue(column3Row0, 0.0);\n this[13] = defaultValue(column3Row1, 0.0);\n this[14] = defaultValue(column3Row2, 0.0);\n this[15] = defaultValue(column3Row3, 0.0);\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nMatrix4.packedLength = 16;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Matrix4} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nMatrix4.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value[0];\n array[startingIndex++] = value[1];\n array[startingIndex++] = value[2];\n array[startingIndex++] = value[3];\n array[startingIndex++] = value[4];\n array[startingIndex++] = value[5];\n array[startingIndex++] = value[6];\n array[startingIndex++] = value[7];\n array[startingIndex++] = value[8];\n array[startingIndex++] = value[9];\n array[startingIndex++] = value[10];\n array[startingIndex++] = value[11];\n array[startingIndex++] = value[12];\n array[startingIndex++] = value[13];\n array[startingIndex++] = value[14];\n array[startingIndex] = value[15];\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Matrix4} [result] The object into which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\n */\nMatrix4.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Matrix4();\n }\n\n result[0] = array[startingIndex++];\n result[1] = array[startingIndex++];\n result[2] = array[startingIndex++];\n result[3] = array[startingIndex++];\n result[4] = array[startingIndex++];\n result[5] = array[startingIndex++];\n result[6] = array[startingIndex++];\n result[7] = array[startingIndex++];\n result[8] = array[startingIndex++];\n result[9] = array[startingIndex++];\n result[10] = array[startingIndex++];\n result[11] = array[startingIndex++];\n result[12] = array[startingIndex++];\n result[13] = array[startingIndex++];\n result[14] = array[startingIndex++];\n result[15] = array[startingIndex];\n return result;\n};\n\n/**\n * Flattens an array of Matrix4s into an array of components. The components\n * are stored in column-major order.\n *\n * @param {Matrix4[]} array The array of matrices to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 16 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 16) elements.\n * @returns {number[]} The packed array.\n */\nMatrix4.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 16;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 16 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Matrix4.pack(array[i], result, i * 16);\n }\n return result;\n};\n\n/**\n * Unpacks an array of column-major matrix components into an array of Matrix4s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Matrix4[]} [result] The array onto which to store the result.\n * @returns {Matrix4[]} The unpacked array.\n */\nMatrix4.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 16);\n if (array.length % 16 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 16.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 16);\n } else {\n result.length = length / 16;\n }\n\n for (let i = 0; i < length; i += 16) {\n const index = i / 16;\n result[index] = Matrix4.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Duplicates a Matrix4 instance.\n *\n * @param {Matrix4} matrix The matrix to duplicate.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. (Returns undefined if matrix is undefined)\n */\nMatrix4.clone = function (matrix, result) {\n if (!defined(matrix)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Matrix4(\n matrix[0],\n matrix[4],\n matrix[8],\n matrix[12],\n matrix[1],\n matrix[5],\n matrix[9],\n matrix[13],\n matrix[2],\n matrix[6],\n matrix[10],\n matrix[14],\n matrix[3],\n matrix[7],\n matrix[11],\n matrix[15]\n );\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n result[8] = matrix[8];\n result[9] = matrix[9];\n result[10] = matrix[10];\n result[11] = matrix[11];\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n return result;\n};\n\n/**\n * Creates a Matrix4 from 16 consecutive elements in an array.\n * @function\n *\n * @param {number[]} array The array whose 16 consecutive elements correspond to the positions of the matrix. Assumes column-major order.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\n *\n * @example\n * // Create the Matrix4:\n * // [1.0, 2.0, 3.0, 4.0]\n * // [1.0, 2.0, 3.0, 4.0]\n * // [1.0, 2.0, 3.0, 4.0]\n * // [1.0, 2.0, 3.0, 4.0]\n *\n * const v = [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];\n * const m = Cesium.Matrix4.fromArray(v);\n *\n * // Create same Matrix4 with using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];\n * const m2 = Cesium.Matrix4.fromArray(v2, 2);\n */\nMatrix4.fromArray = Matrix4.unpack;\n\n/**\n * Computes a Matrix4 instance from a column-major order array.\n *\n * @param {number[]} values The column-major order array.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromColumnMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n return Matrix4.clone(values, result);\n};\n\n/**\n * Computes a Matrix4 instance from a row-major order array.\n * The resulting matrix will be in column-major order.\n *\n * @param {number[]} values The row-major order array.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromRowMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix4(\n values[0],\n values[1],\n values[2],\n values[3],\n values[4],\n values[5],\n values[6],\n values[7],\n values[8],\n values[9],\n values[10],\n values[11],\n values[12],\n values[13],\n values[14],\n values[15]\n );\n }\n result[0] = values[0];\n result[1] = values[4];\n result[2] = values[8];\n result[3] = values[12];\n result[4] = values[1];\n result[5] = values[5];\n result[6] = values[9];\n result[7] = values[13];\n result[8] = values[2];\n result[9] = values[6];\n result[10] = values[10];\n result[11] = values[14];\n result[12] = values[3];\n result[13] = values[7];\n result[14] = values[11];\n result[15] = values[15];\n return result;\n};\n\n/**\n * Computes a Matrix4 instance from a Matrix3 representing the rotation\n * and a Cartesian3 representing the translation.\n *\n * @param {Matrix3} rotation The upper left portion of the matrix representing the rotation.\n * @param {Cartesian3} [translation=Cartesian3.ZERO] The upper right portion of the matrix representing the translation.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromRotationTranslation = function (rotation, translation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rotation\", rotation);\n //>>includeEnd('debug');\n\n translation = defaultValue(translation, Cartesian3.ZERO);\n\n if (!defined(result)) {\n return new Matrix4(\n rotation[0],\n rotation[3],\n rotation[6],\n translation.x,\n rotation[1],\n rotation[4],\n rotation[7],\n translation.y,\n rotation[2],\n rotation[5],\n rotation[8],\n translation.z,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n\n result[0] = rotation[0];\n result[1] = rotation[1];\n result[2] = rotation[2];\n result[3] = 0.0;\n result[4] = rotation[3];\n result[5] = rotation[4];\n result[6] = rotation[5];\n result[7] = 0.0;\n result[8] = rotation[6];\n result[9] = rotation[7];\n result[10] = rotation[8];\n result[11] = 0.0;\n result[12] = translation.x;\n result[13] = translation.y;\n result[14] = translation.z;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance from a translation, rotation, and scale (TRS)\n * representation with the rotation represented as a quaternion.\n *\n * @param {Cartesian3} translation The translation transformation.\n * @param {Quaternion} rotation The rotation transformation.\n * @param {Cartesian3} scale The non-uniform scale transformation.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n *\n * @example\n * const result = Cesium.Matrix4.fromTranslationQuaternionRotationScale(\n * new Cesium.Cartesian3(1.0, 2.0, 3.0), // translation\n * Cesium.Quaternion.IDENTITY, // rotation\n * new Cesium.Cartesian3(7.0, 8.0, 9.0), // scale\n * result);\n */\nMatrix4.fromTranslationQuaternionRotationScale = function (\n translation,\n rotation,\n scale,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"translation\", translation);\n Check.typeOf.object(\"rotation\", rotation);\n Check.typeOf.object(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Matrix4();\n }\n\n const scaleX = scale.x;\n const scaleY = scale.y;\n const scaleZ = scale.z;\n\n const x2 = rotation.x * rotation.x;\n const xy = rotation.x * rotation.y;\n const xz = rotation.x * rotation.z;\n const xw = rotation.x * rotation.w;\n const y2 = rotation.y * rotation.y;\n const yz = rotation.y * rotation.z;\n const yw = rotation.y * rotation.w;\n const z2 = rotation.z * rotation.z;\n const zw = rotation.z * rotation.w;\n const w2 = rotation.w * rotation.w;\n\n const m00 = x2 - y2 - z2 + w2;\n const m01 = 2.0 * (xy - zw);\n const m02 = 2.0 * (xz + yw);\n\n const m10 = 2.0 * (xy + zw);\n const m11 = -x2 + y2 - z2 + w2;\n const m12 = 2.0 * (yz - xw);\n\n const m20 = 2.0 * (xz - yw);\n const m21 = 2.0 * (yz + xw);\n const m22 = -x2 - y2 + z2 + w2;\n\n result[0] = m00 * scaleX;\n result[1] = m10 * scaleX;\n result[2] = m20 * scaleX;\n result[3] = 0.0;\n result[4] = m01 * scaleY;\n result[5] = m11 * scaleY;\n result[6] = m21 * scaleY;\n result[7] = 0.0;\n result[8] = m02 * scaleZ;\n result[9] = m12 * scaleZ;\n result[10] = m22 * scaleZ;\n result[11] = 0.0;\n result[12] = translation.x;\n result[13] = translation.y;\n result[14] = translation.z;\n result[15] = 1.0;\n\n return result;\n};\n\n/**\n * Creates a Matrix4 instance from a {@link TranslationRotationScale} instance.\n *\n * @param {TranslationRotationScale} translationRotationScale The instance.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromTranslationRotationScale = function (\n translationRotationScale,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"translationRotationScale\", translationRotationScale);\n //>>includeEnd('debug');\n\n return Matrix4.fromTranslationQuaternionRotationScale(\n translationRotationScale.translation,\n translationRotationScale.rotation,\n translationRotationScale.scale,\n result\n );\n};\n\n/**\n * Creates a Matrix4 instance from a Cartesian3 representing the translation.\n *\n * @param {Cartesian3} translation The upper right portion of the matrix representing the translation.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n *\n * @see Matrix4.multiplyByTranslation\n */\nMatrix4.fromTranslation = function (translation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"translation\", translation);\n //>>includeEnd('debug');\n\n return Matrix4.fromRotationTranslation(Matrix3.IDENTITY, translation, result);\n};\n\n/**\n * Computes a Matrix4 instance representing a non-uniform scale.\n *\n * @param {Cartesian3} scale The x, y, and z scale factors.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [7.0, 0.0, 0.0, 0.0]\n * // [0.0, 8.0, 0.0, 0.0]\n * // [0.0, 0.0, 9.0, 0.0]\n * // [0.0, 0.0, 0.0, 1.0]\n * const m = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));\n */\nMatrix4.fromScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix4(\n scale.x,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n scale.y,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n scale.z,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n\n result[0] = scale.x;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = scale.y;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = scale.z;\n result[11] = 0.0;\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = 0.0;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance representing a uniform scale.\n *\n * @param {number} scale The uniform scale factor.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [2.0, 0.0, 0.0, 0.0]\n * // [0.0, 2.0, 0.0, 0.0]\n * // [0.0, 0.0, 2.0, 0.0]\n * // [0.0, 0.0, 0.0, 1.0]\n * const m = Cesium.Matrix4.fromUniformScale(2.0);\n */\nMatrix4.fromUniformScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix4(\n scale,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n scale,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n scale,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n\n result[0] = scale;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = scale;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = scale;\n result[11] = 0.0;\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = 0.0;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Creates a rotation matrix.\n *\n * @param {Matrix3} rotation The rotation matrix.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromRotation = function (rotation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rotation\", rotation);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Matrix4();\n }\n result[0] = rotation[0];\n result[1] = rotation[1];\n result[2] = rotation[2];\n result[3] = 0.0;\n\n result[4] = rotation[3];\n result[5] = rotation[4];\n result[6] = rotation[5];\n result[7] = 0.0;\n\n result[8] = rotation[6];\n result[9] = rotation[7];\n result[10] = rotation[8];\n result[11] = 0.0;\n\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = 0.0;\n result[15] = 1.0;\n\n return result;\n};\n\nconst fromCameraF = new Cartesian3();\nconst fromCameraR = new Cartesian3();\nconst fromCameraU = new Cartesian3();\n\n/**\n * Computes a Matrix4 instance from a Camera.\n *\n * @param {Camera} camera The camera to use.\n * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.\n */\nMatrix4.fromCamera = function (camera, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"camera\", camera);\n //>>includeEnd('debug');\n\n const position = camera.position;\n const direction = camera.direction;\n const up = camera.up;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"camera.position\", position);\n Check.typeOf.object(\"camera.direction\", direction);\n Check.typeOf.object(\"camera.up\", up);\n //>>includeEnd('debug');\n\n Cartesian3.normalize(direction, fromCameraF);\n Cartesian3.normalize(\n Cartesian3.cross(fromCameraF, up, fromCameraR),\n fromCameraR\n );\n Cartesian3.normalize(\n Cartesian3.cross(fromCameraR, fromCameraF, fromCameraU),\n fromCameraU\n );\n\n const sX = fromCameraR.x;\n const sY = fromCameraR.y;\n const sZ = fromCameraR.z;\n const fX = fromCameraF.x;\n const fY = fromCameraF.y;\n const fZ = fromCameraF.z;\n const uX = fromCameraU.x;\n const uY = fromCameraU.y;\n const uZ = fromCameraU.z;\n const positionX = position.x;\n const positionY = position.y;\n const positionZ = position.z;\n const t0 = sX * -positionX + sY * -positionY + sZ * -positionZ;\n const t1 = uX * -positionX + uY * -positionY + uZ * -positionZ;\n const t2 = fX * positionX + fY * positionY + fZ * positionZ;\n\n // The code below this comment is an optimized\n // version of the commented lines.\n // Rather that create two matrices and then multiply,\n // we just bake in the multiplcation as part of creation.\n // const rotation = new Matrix4(\n // sX, sY, sZ, 0.0,\n // uX, uY, uZ, 0.0,\n // -fX, -fY, -fZ, 0.0,\n // 0.0, 0.0, 0.0, 1.0);\n // const translation = new Matrix4(\n // 1.0, 0.0, 0.0, -position.x,\n // 0.0, 1.0, 0.0, -position.y,\n // 0.0, 0.0, 1.0, -position.z,\n // 0.0, 0.0, 0.0, 1.0);\n // return rotation.multiply(translation);\n if (!defined(result)) {\n return new Matrix4(\n sX,\n sY,\n sZ,\n t0,\n uX,\n uY,\n uZ,\n t1,\n -fX,\n -fY,\n -fZ,\n t2,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n result[0] = sX;\n result[1] = uX;\n result[2] = -fX;\n result[3] = 0.0;\n result[4] = sY;\n result[5] = uY;\n result[6] = -fY;\n result[7] = 0.0;\n result[8] = sZ;\n result[9] = uZ;\n result[10] = -fZ;\n result[11] = 0.0;\n result[12] = t0;\n result[13] = t1;\n result[14] = t2;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance representing a perspective transformation matrix.\n *\n * @param {number} fovY The field of view along the Y axis in radians.\n * @param {number} aspectRatio The aspect ratio.\n * @param {number} near The distance to the near plane in meters.\n * @param {number} far The distance to the far plane in meters.\n * @param {Matrix4} result The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n *\n * @exception {DeveloperError} fovY must be in (0, PI].\n * @exception {DeveloperError} aspectRatio must be greater than zero.\n * @exception {DeveloperError} near must be greater than zero.\n * @exception {DeveloperError} far must be greater than zero.\n */\nMatrix4.computePerspectiveFieldOfView = function (\n fovY,\n aspectRatio,\n near,\n far,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"fovY\", fovY, 0.0);\n Check.typeOf.number.lessThan(\"fovY\", fovY, Math.PI);\n Check.typeOf.number.greaterThan(\"near\", near, 0.0);\n Check.typeOf.number.greaterThan(\"far\", far, 0.0);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const bottom = Math.tan(fovY * 0.5);\n\n const column1Row1 = 1.0 / bottom;\n const column0Row0 = column1Row1 / aspectRatio;\n const column2Row2 = (far + near) / (near - far);\n const column3Row2 = (2.0 * far * near) / (near - far);\n\n result[0] = column0Row0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = column1Row1;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = column2Row2;\n result[11] = -1.0;\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = column3Row2;\n result[15] = 0.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance representing an orthographic transformation matrix.\n *\n * @param {number} left The number of meters to the left of the camera that will be in view.\n * @param {number} right The number of meters to the right of the camera that will be in view.\n * @param {number} bottom The number of meters below of the camera that will be in view.\n * @param {number} top The number of meters above of the camera that will be in view.\n * @param {number} near The distance to the near plane in meters.\n * @param {number} far The distance to the far plane in meters.\n * @param {Matrix4} result The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.computeOrthographicOffCenter = function (\n left,\n right,\n bottom,\n top,\n near,\n far,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"left\", left);\n Check.typeOf.number(\"right\", right);\n Check.typeOf.number(\"bottom\", bottom);\n Check.typeOf.number(\"top\", top);\n Check.typeOf.number(\"near\", near);\n Check.typeOf.number(\"far\", far);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n let a = 1.0 / (right - left);\n let b = 1.0 / (top - bottom);\n let c = 1.0 / (far - near);\n\n const tx = -(right + left) * a;\n const ty = -(top + bottom) * b;\n const tz = -(far + near) * c;\n a *= 2.0;\n b *= 2.0;\n c *= -2.0;\n\n result[0] = a;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = b;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = c;\n result[11] = 0.0;\n result[12] = tx;\n result[13] = ty;\n result[14] = tz;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance representing an off center perspective transformation.\n *\n * @param {number} left The number of meters to the left of the camera that will be in view.\n * @param {number} right The number of meters to the right of the camera that will be in view.\n * @param {number} bottom The number of meters below of the camera that will be in view.\n * @param {number} top The number of meters above of the camera that will be in view.\n * @param {number} near The distance to the near plane in meters.\n * @param {number} far The distance to the far plane in meters.\n * @param {Matrix4} result The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.computePerspectiveOffCenter = function (\n left,\n right,\n bottom,\n top,\n near,\n far,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"left\", left);\n Check.typeOf.number(\"right\", right);\n Check.typeOf.number(\"bottom\", bottom);\n Check.typeOf.number(\"top\", top);\n Check.typeOf.number(\"near\", near);\n Check.typeOf.number(\"far\", far);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 = (2.0 * near) / (right - left);\n const column1Row1 = (2.0 * near) / (top - bottom);\n const column2Row0 = (right + left) / (right - left);\n const column2Row1 = (top + bottom) / (top - bottom);\n const column2Row2 = -(far + near) / (far - near);\n const column2Row3 = -1.0;\n const column3Row2 = (-2.0 * far * near) / (far - near);\n\n result[0] = column0Row0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = column1Row1;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = column2Row0;\n result[9] = column2Row1;\n result[10] = column2Row2;\n result[11] = column2Row3;\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = column3Row2;\n result[15] = 0.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance representing an infinite off center perspective transformation.\n *\n * @param {number} left The number of meters to the left of the camera that will be in view.\n * @param {number} right The number of meters to the right of the camera that will be in view.\n * @param {number} bottom The number of meters below of the camera that will be in view.\n * @param {number} top The number of meters above of the camera that will be in view.\n * @param {number} near The distance to the near plane in meters.\n * @param {Matrix4} result The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.computeInfinitePerspectiveOffCenter = function (\n left,\n right,\n bottom,\n top,\n near,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"left\", left);\n Check.typeOf.number(\"right\", right);\n Check.typeOf.number(\"bottom\", bottom);\n Check.typeOf.number(\"top\", top);\n Check.typeOf.number(\"near\", near);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 = (2.0 * near) / (right - left);\n const column1Row1 = (2.0 * near) / (top - bottom);\n const column2Row0 = (right + left) / (right - left);\n const column2Row1 = (top + bottom) / (top - bottom);\n const column2Row2 = -1.0;\n const column2Row3 = -1.0;\n const column3Row2 = -2.0 * near;\n\n result[0] = column0Row0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = column1Row1;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = column2Row0;\n result[9] = column2Row1;\n result[10] = column2Row2;\n result[11] = column2Row3;\n result[12] = 0.0;\n result[13] = 0.0;\n result[14] = column3Row2;\n result[15] = 0.0;\n return result;\n};\n\n/**\n * Computes a Matrix4 instance that transforms from normalized device coordinates to window coordinates.\n *\n * @param {object} [viewport = { x : 0.0, y : 0.0, width : 0.0, height : 0.0 }] The viewport's corners as shown in Example 1.\n * @param {number} [nearDepthRange=0.0] The near plane distance in window coordinates.\n * @param {number} [farDepthRange=1.0] The far plane distance in window coordinates.\n * @param {Matrix4} [result] The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * // Create viewport transformation using an explicit viewport and depth range.\n * const m = Cesium.Matrix4.computeViewportTransformation({\n * x : 0.0,\n * y : 0.0,\n * width : 1024.0,\n * height : 768.0\n * }, 0.0, 1.0, new Cesium.Matrix4());\n */\nMatrix4.computeViewportTransformation = function (\n viewport,\n nearDepthRange,\n farDepthRange,\n result\n) {\n if (!defined(result)) {\n result = new Matrix4();\n }\n\n viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT);\n const x = defaultValue(viewport.x, 0.0);\n const y = defaultValue(viewport.y, 0.0);\n const width = defaultValue(viewport.width, 0.0);\n const height = defaultValue(viewport.height, 0.0);\n nearDepthRange = defaultValue(nearDepthRange, 0.0);\n farDepthRange = defaultValue(farDepthRange, 1.0);\n\n const halfWidth = width * 0.5;\n const halfHeight = height * 0.5;\n const halfDepth = (farDepthRange - nearDepthRange) * 0.5;\n\n const column0Row0 = halfWidth;\n const column1Row1 = halfHeight;\n const column2Row2 = halfDepth;\n const column3Row0 = x + halfWidth;\n const column3Row1 = y + halfHeight;\n const column3Row2 = nearDepthRange + halfDepth;\n const column3Row3 = 1.0;\n\n result[0] = column0Row0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = column1Row1;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = column2Row2;\n result[11] = 0.0;\n result[12] = column3Row0;\n result[13] = column3Row1;\n result[14] = column3Row2;\n result[15] = column3Row3;\n\n return result;\n};\n\n/**\n * Computes a Matrix4 instance that transforms from world space to view space.\n *\n * @param {Cartesian3} position The position of the camera.\n * @param {Cartesian3} direction The forward direction.\n * @param {Cartesian3} up The up direction.\n * @param {Cartesian3} right The right direction.\n * @param {Matrix4} result The object in which the result will be stored.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.computeView = function (position, direction, up, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"position\", position);\n Check.typeOf.object(\"direction\", direction);\n Check.typeOf.object(\"up\", up);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = right.x;\n result[1] = up.x;\n result[2] = -direction.x;\n result[3] = 0.0;\n result[4] = right.y;\n result[5] = up.y;\n result[6] = -direction.y;\n result[7] = 0.0;\n result[8] = right.z;\n result[9] = up.z;\n result[10] = -direction.z;\n result[11] = 0.0;\n result[12] = -Cartesian3.dot(right, position);\n result[13] = -Cartesian3.dot(up, position);\n result[14] = Cartesian3.dot(direction, position);\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Computes an Array from the provided Matrix4 instance.\n * The array will be in column-major order.\n *\n * @param {Matrix4} matrix The matrix to use..\n * @param {number[]} [result] The Array onto which to store the result.\n * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.\n *\n * @example\n * //create an array from an instance of Matrix4\n * // m = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n * const a = Cesium.Matrix4.toArray(m);\n *\n * // m remains the same\n * //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]\n */\nMatrix4.toArray = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return [\n matrix[0],\n matrix[1],\n matrix[2],\n matrix[3],\n matrix[4],\n matrix[5],\n matrix[6],\n matrix[7],\n matrix[8],\n matrix[9],\n matrix[10],\n matrix[11],\n matrix[12],\n matrix[13],\n matrix[14],\n matrix[15],\n ];\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n result[8] = matrix[8];\n result[9] = matrix[9];\n result[10] = matrix[10];\n result[11] = matrix[11];\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n return result;\n};\n\n/**\n * Computes the array index of the element at the provided row and column.\n *\n * @param {number} row The zero-based index of the row.\n * @param {number} column The zero-based index of the column.\n * @returns {number} The index of the element at the provided row and column.\n *\n * @exception {DeveloperError} row must be 0, 1, 2, or 3.\n * @exception {DeveloperError} column must be 0, 1, 2, or 3.\n *\n * @example\n * const myMatrix = new Cesium.Matrix4();\n * const column1Row0Index = Cesium.Matrix4.getElementIndex(1, 0);\n * const column1Row0 = myMatrix[column1Row0Index];\n * myMatrix[column1Row0Index] = 10.0;\n */\nMatrix4.getElementIndex = function (column, row) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"row\", row, 0);\n Check.typeOf.number.lessThanOrEquals(\"row\", row, 3);\n\n Check.typeOf.number.greaterThanOrEquals(\"column\", column, 0);\n Check.typeOf.number.lessThanOrEquals(\"column\", column, 3);\n //>>includeEnd('debug');\n\n return column * 4 + row;\n};\n\n/**\n * Retrieves a copy of the matrix column at the provided index as a Cartesian4 instance.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to retrieve.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\n *\n * @example\n * //returns a Cartesian4 instance with values from the specified column\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * //Example 1: Creates an instance of Cartesian\n * const a = Cesium.Matrix4.getColumn(m, 2, new Cesium.Cartesian4());\n *\n * @example\n * //Example 2: Sets values for Cartesian instance\n * const a = new Cesium.Cartesian4();\n * Cesium.Matrix4.getColumn(m, 2, a);\n *\n * // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;\n */\nMatrix4.getColumn = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\n\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const startIndex = index * 4;\n const x = matrix[startIndex];\n const y = matrix[startIndex + 1];\n const z = matrix[startIndex + 2];\n const w = matrix[startIndex + 3];\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian4 instance.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to set.\n * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified column.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\n *\n * @example\n * //creates a new Matrix4 instance with new column values from the Cartesian4 instance\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * const a = Cesium.Matrix4.setColumn(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());\n *\n * // m remains the same\n * // a = [10.0, 11.0, 99.0, 13.0]\n * // [14.0, 15.0, 98.0, 17.0]\n * // [18.0, 19.0, 97.0, 21.0]\n * // [22.0, 23.0, 96.0, 25.0]\n */\nMatrix4.setColumn = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\n\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix4.clone(matrix, result);\n const startIndex = index * 4;\n result[startIndex] = cartesian.x;\n result[startIndex + 1] = cartesian.y;\n result[startIndex + 2] = cartesian.z;\n result[startIndex + 3] = cartesian.w;\n return result;\n};\n\n/**\n * Retrieves a copy of the matrix row at the provided index as a Cartesian4 instance.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to retrieve.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\n *\n * @example\n * //returns a Cartesian4 instance with values from the specified column\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * //Example 1: Returns an instance of Cartesian\n * const a = Cesium.Matrix4.getRow(m, 2, new Cesium.Cartesian4());\n *\n * @example\n * //Example 2: Sets values for a Cartesian instance\n * const a = new Cesium.Cartesian4();\n * Cesium.Matrix4.getRow(m, 2, a);\n *\n * // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;\n */\nMatrix4.getRow = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\n\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = matrix[index];\n const y = matrix[index + 4];\n const z = matrix[index + 8];\n const w = matrix[index + 12];\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian4 instance.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to set.\n * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified row.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0, 1, 2, or 3.\n *\n * @example\n * //create a new Matrix4 instance with new row values from the Cartesian4 instance\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * const a = Cesium.Matrix4.setRow(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());\n *\n * // m remains the same\n * // a = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [99.0, 98.0, 97.0, 96.0]\n * // [22.0, 23.0, 24.0, 25.0]\n */\nMatrix4.setRow = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 3);\n\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix4.clone(matrix, result);\n result[index] = cartesian.x;\n result[index + 4] = cartesian.y;\n result[index + 8] = cartesian.z;\n result[index + 12] = cartesian.w;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the translation in the rightmost column of the provided\n * matrix with the provided translation. This assumes the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {Cartesian3} translation The translation that replaces the translation of the provided matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.setTranslation = function (matrix, translation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"translation\", translation);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n\n result[8] = matrix[8];\n result[9] = matrix[9];\n result[10] = matrix[10];\n result[11] = matrix[11];\n\n result[12] = translation.x;\n result[13] = translation.y;\n result[14] = translation.z;\n result[15] = matrix[15];\n\n return result;\n};\n\nconst scaleScratch1 = new Cartesian3();\n\n/**\n * Computes a new matrix that replaces the scale with the provided scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @see Matrix4.setUniformScale\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.multiplyByScale\n * @see Matrix4.multiplyByUniformScale\n * @see Matrix4.getScale\n */\nMatrix4.setScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix4.getScale(matrix, scaleScratch1);\n const scaleRatioX = scale.x / existingScale.x;\n const scaleRatioY = scale.y / existingScale.y;\n const scaleRatioZ = scale.z / existingScale.z;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioX;\n result[3] = matrix[3];\n\n result[4] = matrix[4] * scaleRatioY;\n result[5] = matrix[5] * scaleRatioY;\n result[6] = matrix[6] * scaleRatioY;\n result[7] = matrix[7];\n\n result[8] = matrix[8] * scaleRatioZ;\n result[9] = matrix[9] * scaleRatioZ;\n result[10] = matrix[10] * scaleRatioZ;\n result[11] = matrix[11];\n\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n\n return result;\n};\n\nconst scaleScratch2 = new Cartesian3();\n\n/**\n * Computes a new matrix that replaces the scale with the provided uniform scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {number} scale The uniform scale that replaces the scale of the provided matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @see Matrix4.setScale\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.multiplyByScale\n * @see Matrix4.multiplyByUniformScale\n * @see Matrix4.getScale\n */\nMatrix4.setUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix4.getScale(matrix, scaleScratch2);\n const scaleRatioX = scale / existingScale.x;\n const scaleRatioY = scale / existingScale.y;\n const scaleRatioZ = scale / existingScale.z;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioX;\n result[3] = matrix[3];\n\n result[4] = matrix[4] * scaleRatioY;\n result[5] = matrix[5] * scaleRatioY;\n result[6] = matrix[6] * scaleRatioY;\n result[7] = matrix[7];\n\n result[8] = matrix[8] * scaleRatioZ;\n result[9] = matrix[9] * scaleRatioZ;\n result[10] = matrix[10] * scaleRatioZ;\n result[11] = matrix[11];\n\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n\n return result;\n};\n\nconst scratchColumn = new Cartesian3();\n\n/**\n * Extracts the non-uniform scale assuming the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter\n *\n * @see Matrix4.multiplyByScale\n * @see Matrix4.multiplyByUniformScale\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.setScale\n * @see Matrix4.setUniformScale\n */\nMatrix4.getScale = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)\n );\n result.y = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[4], matrix[5], matrix[6], scratchColumn)\n );\n result.z = Cartesian3.magnitude(\n Cartesian3.fromElements(matrix[8], matrix[9], matrix[10], scratchColumn)\n );\n return result;\n};\n\nconst scaleScratch3 = new Cartesian3();\n\n/**\n * Computes the maximum scale assuming the matrix is an affine transformation.\n * The maximum scale is the maximum length of the column vectors in the upper-left\n * 3x3 matrix.\n *\n * @param {Matrix4} matrix The matrix.\n * @returns {number} The maximum scale.\n */\nMatrix4.getMaximumScale = function (matrix) {\n Matrix4.getScale(matrix, scaleScratch3);\n return Cartesian3.maximumComponent(scaleScratch3);\n};\n\nconst scaleScratch4 = new Cartesian3();\n\n/**\n * Sets the rotation assuming the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Matrix3} rotation The rotation matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @see Matrix4.fromRotation\n * @see Matrix4.getRotation\n */\nMatrix4.setRotation = function (matrix, rotation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix4.getScale(matrix, scaleScratch4);\n\n result[0] = rotation[0] * scale.x;\n result[1] = rotation[1] * scale.x;\n result[2] = rotation[2] * scale.x;\n result[3] = matrix[3];\n\n result[4] = rotation[3] * scale.y;\n result[5] = rotation[4] * scale.y;\n result[6] = rotation[5] * scale.y;\n result[7] = matrix[7];\n\n result[8] = rotation[6] * scale.z;\n result[9] = rotation[7] * scale.z;\n result[10] = rotation[8] * scale.z;\n result[11] = matrix[11];\n\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n\n return result;\n};\n\nconst scaleScratch5 = new Cartesian3();\n\n/**\n * Extracts the rotation matrix assuming the matrix is an affine transformation.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @see Matrix4.setRotation\n * @see Matrix4.fromRotation\n */\nMatrix4.getRotation = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix4.getScale(matrix, scaleScratch5);\n\n result[0] = matrix[0] / scale.x;\n result[1] = matrix[1] / scale.x;\n result[2] = matrix[2] / scale.x;\n\n result[3] = matrix[4] / scale.y;\n result[4] = matrix[5] / scale.y;\n result[5] = matrix[6] / scale.y;\n\n result[6] = matrix[8] / scale.z;\n result[7] = matrix[9] / scale.z;\n result[8] = matrix[10] / scale.z;\n\n return result;\n};\n\n/**\n * Computes the product of two matrices.\n *\n * @param {Matrix4} left The first matrix.\n * @param {Matrix4} right The second matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const left0 = left[0];\n const left1 = left[1];\n const left2 = left[2];\n const left3 = left[3];\n const left4 = left[4];\n const left5 = left[5];\n const left6 = left[6];\n const left7 = left[7];\n const left8 = left[8];\n const left9 = left[9];\n const left10 = left[10];\n const left11 = left[11];\n const left12 = left[12];\n const left13 = left[13];\n const left14 = left[14];\n const left15 = left[15];\n\n const right0 = right[0];\n const right1 = right[1];\n const right2 = right[2];\n const right3 = right[3];\n const right4 = right[4];\n const right5 = right[5];\n const right6 = right[6];\n const right7 = right[7];\n const right8 = right[8];\n const right9 = right[9];\n const right10 = right[10];\n const right11 = right[11];\n const right12 = right[12];\n const right13 = right[13];\n const right14 = right[14];\n const right15 = right[15];\n\n const column0Row0 =\n left0 * right0 + left4 * right1 + left8 * right2 + left12 * right3;\n const column0Row1 =\n left1 * right0 + left5 * right1 + left9 * right2 + left13 * right3;\n const column0Row2 =\n left2 * right0 + left6 * right1 + left10 * right2 + left14 * right3;\n const column0Row3 =\n left3 * right0 + left7 * right1 + left11 * right2 + left15 * right3;\n\n const column1Row0 =\n left0 * right4 + left4 * right5 + left8 * right6 + left12 * right7;\n const column1Row1 =\n left1 * right4 + left5 * right5 + left9 * right6 + left13 * right7;\n const column1Row2 =\n left2 * right4 + left6 * right5 + left10 * right6 + left14 * right7;\n const column1Row3 =\n left3 * right4 + left7 * right5 + left11 * right6 + left15 * right7;\n\n const column2Row0 =\n left0 * right8 + left4 * right9 + left8 * right10 + left12 * right11;\n const column2Row1 =\n left1 * right8 + left5 * right9 + left9 * right10 + left13 * right11;\n const column2Row2 =\n left2 * right8 + left6 * right9 + left10 * right10 + left14 * right11;\n const column2Row3 =\n left3 * right8 + left7 * right9 + left11 * right10 + left15 * right11;\n\n const column3Row0 =\n left0 * right12 + left4 * right13 + left8 * right14 + left12 * right15;\n const column3Row1 =\n left1 * right12 + left5 * right13 + left9 * right14 + left13 * right15;\n const column3Row2 =\n left2 * right12 + left6 * right13 + left10 * right14 + left14 * right15;\n const column3Row3 =\n left3 * right12 + left7 * right13 + left11 * right14 + left15 * right15;\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column0Row2;\n result[3] = column0Row3;\n result[4] = column1Row0;\n result[5] = column1Row1;\n result[6] = column1Row2;\n result[7] = column1Row3;\n result[8] = column2Row0;\n result[9] = column2Row1;\n result[10] = column2Row2;\n result[11] = column2Row3;\n result[12] = column3Row0;\n result[13] = column3Row1;\n result[14] = column3Row2;\n result[15] = column3Row3;\n return result;\n};\n\n/**\n * Computes the sum of two matrices.\n *\n * @param {Matrix4} left The first matrix.\n * @param {Matrix4} right The second matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] + right[0];\n result[1] = left[1] + right[1];\n result[2] = left[2] + right[2];\n result[3] = left[3] + right[3];\n result[4] = left[4] + right[4];\n result[5] = left[5] + right[5];\n result[6] = left[6] + right[6];\n result[7] = left[7] + right[7];\n result[8] = left[8] + right[8];\n result[9] = left[9] + right[9];\n result[10] = left[10] + right[10];\n result[11] = left[11] + right[11];\n result[12] = left[12] + right[12];\n result[13] = left[13] + right[13];\n result[14] = left[14] + right[14];\n result[15] = left[15] + right[15];\n return result;\n};\n\n/**\n * Computes the difference of two matrices.\n *\n * @param {Matrix4} left The first matrix.\n * @param {Matrix4} right The second matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] - right[0];\n result[1] = left[1] - right[1];\n result[2] = left[2] - right[2];\n result[3] = left[3] - right[3];\n result[4] = left[4] - right[4];\n result[5] = left[5] - right[5];\n result[6] = left[6] - right[6];\n result[7] = left[7] - right[7];\n result[8] = left[8] - right[8];\n result[9] = left[9] - right[9];\n result[10] = left[10] - right[10];\n result[11] = left[11] - right[11];\n result[12] = left[12] - right[12];\n result[13] = left[13] - right[13];\n result[14] = left[14] - right[14];\n result[15] = left[15] - right[15];\n return result;\n};\n\n/**\n * Computes the product of two matrices assuming the matrices are affine transformation matrices,\n * where the upper left 3x3 elements are any matrix, and\n * the upper three elements in the fourth column are the translation.\n * The bottom row is assumed to be [0, 0, 0, 1].\n * The matrix is not verified to be in the proper form.\n * This method is faster than computing the product for general 4x4\n * matrices using {@link Matrix4.multiply}.\n *\n * @param {Matrix4} left The first matrix.\n * @param {Matrix4} right The second matrix.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * const m1 = new Cesium.Matrix4(1.0, 6.0, 7.0, 0.0, 2.0, 5.0, 8.0, 0.0, 3.0, 4.0, 9.0, 0.0, 0.0, 0.0, 0.0, 1.0);\n * const m2 = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3(1.0, 1.0, 1.0));\n * const m3 = Cesium.Matrix4.multiplyTransformation(m1, m2, new Cesium.Matrix4());\n */\nMatrix4.multiplyTransformation = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const left0 = left[0];\n const left1 = left[1];\n const left2 = left[2];\n const left4 = left[4];\n const left5 = left[5];\n const left6 = left[6];\n const left8 = left[8];\n const left9 = left[9];\n const left10 = left[10];\n const left12 = left[12];\n const left13 = left[13];\n const left14 = left[14];\n\n const right0 = right[0];\n const right1 = right[1];\n const right2 = right[2];\n const right4 = right[4];\n const right5 = right[5];\n const right6 = right[6];\n const right8 = right[8];\n const right9 = right[9];\n const right10 = right[10];\n const right12 = right[12];\n const right13 = right[13];\n const right14 = right[14];\n\n const column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;\n const column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;\n const column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;\n\n const column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;\n const column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;\n const column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;\n\n const column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;\n const column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;\n const column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;\n\n const column3Row0 =\n left0 * right12 + left4 * right13 + left8 * right14 + left12;\n const column3Row1 =\n left1 * right12 + left5 * right13 + left9 * right14 + left13;\n const column3Row2 =\n left2 * right12 + left6 * right13 + left10 * right14 + left14;\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column0Row2;\n result[3] = 0.0;\n result[4] = column1Row0;\n result[5] = column1Row1;\n result[6] = column1Row2;\n result[7] = 0.0;\n result[8] = column2Row0;\n result[9] = column2Row1;\n result[10] = column2Row2;\n result[11] = 0.0;\n result[12] = column3Row0;\n result[13] = column3Row1;\n result[14] = column3Row2;\n result[15] = 1.0;\n return result;\n};\n\n/**\n * Multiplies a transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0])\n * by a 3x3 rotation matrix. This is an optimization\n * for Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m); with less allocations and arithmetic operations.\n *\n * @param {Matrix4} matrix The matrix on the left-hand side.\n * @param {Matrix3} rotation The 3x3 rotation matrix on the right-hand side.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromRotationTranslation(rotation), m);\n * Cesium.Matrix4.multiplyByMatrix3(m, rotation, m);\n */\nMatrix4.multiplyByMatrix3 = function (matrix, rotation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"rotation\", rotation);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const left0 = matrix[0];\n const left1 = matrix[1];\n const left2 = matrix[2];\n const left4 = matrix[4];\n const left5 = matrix[5];\n const left6 = matrix[6];\n const left8 = matrix[8];\n const left9 = matrix[9];\n const left10 = matrix[10];\n\n const right0 = rotation[0];\n const right1 = rotation[1];\n const right2 = rotation[2];\n const right4 = rotation[3];\n const right5 = rotation[4];\n const right6 = rotation[5];\n const right8 = rotation[6];\n const right9 = rotation[7];\n const right10 = rotation[8];\n\n const column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;\n const column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;\n const column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;\n\n const column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;\n const column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;\n const column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;\n\n const column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;\n const column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;\n const column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column0Row2;\n result[3] = 0.0;\n result[4] = column1Row0;\n result[5] = column1Row1;\n result[6] = column1Row2;\n result[7] = 0.0;\n result[8] = column2Row0;\n result[9] = column2Row1;\n result[10] = column2Row2;\n result[11] = 0.0;\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n return result;\n};\n\n/**\n * Multiplies a transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0])\n * by an implicit translation matrix defined by a {@link Cartesian3}. This is an optimization\n * for Matrix4.multiply(m, Matrix4.fromTranslation(position), m); with less allocations and arithmetic operations.\n *\n * @param {Matrix4} matrix The matrix on the left-hand side.\n * @param {Cartesian3} translation The translation on the right-hand side.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromTranslation(position), m);\n * Cesium.Matrix4.multiplyByTranslation(m, position, m);\n */\nMatrix4.multiplyByTranslation = function (matrix, translation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"translation\", translation);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = translation.x;\n const y = translation.y;\n const z = translation.z;\n\n const tx = x * matrix[0] + y * matrix[4] + z * matrix[8] + matrix[12];\n const ty = x * matrix[1] + y * matrix[5] + z * matrix[9] + matrix[13];\n const tz = x * matrix[2] + y * matrix[6] + z * matrix[10] + matrix[14];\n\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n result[4] = matrix[4];\n result[5] = matrix[5];\n result[6] = matrix[6];\n result[7] = matrix[7];\n result[8] = matrix[8];\n result[9] = matrix[9];\n result[10] = matrix[10];\n result[11] = matrix[11];\n result[12] = tx;\n result[13] = ty;\n result[14] = tz;\n result[15] = matrix[15];\n return result;\n};\n\n/**\n * Multiplies an affine transformation matrix (with a bottom row of [0.0, 0.0, 0.0, 1.0])\n * by an implicit non-uniform scale matrix. This is an optimization\n * for Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);, where\n * m must be an affine matrix.\n * This function performs fewer allocations and arithmetic operations.\n *\n * @param {Matrix4} matrix The affine matrix on the left-hand side.\n * @param {Cartesian3} scale The non-uniform scale on the right-hand side.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n *\n * @example\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromScale(scale), m);\n * Cesium.Matrix4.multiplyByScale(m, scale, m);\n *\n * @see Matrix4.multiplyByUniformScale\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.setScale\n * @see Matrix4.setUniformScale\n * @see Matrix4.getScale\n */\nMatrix4.multiplyByScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scaleX = scale.x;\n const scaleY = scale.y;\n const scaleZ = scale.z;\n\n // Faster than Cartesian3.equals\n if (scaleX === 1.0 && scaleY === 1.0 && scaleZ === 1.0) {\n return Matrix4.clone(matrix, result);\n }\n\n result[0] = scaleX * matrix[0];\n result[1] = scaleX * matrix[1];\n result[2] = scaleX * matrix[2];\n result[3] = matrix[3];\n\n result[4] = scaleY * matrix[4];\n result[5] = scaleY * matrix[5];\n result[6] = scaleY * matrix[6];\n result[7] = matrix[7];\n\n result[8] = scaleZ * matrix[8];\n result[9] = scaleZ * matrix[9];\n result[10] = scaleZ * matrix[10];\n result[11] = matrix[11];\n\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n\n return result;\n};\n\n/**\n * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.\n *\n * @param {Matrix4} matrix The matrix on the left-hand side.\n * @param {number} scale The uniform scale on the right-hand side.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromUniformScale(scale), m);\n * Cesium.Matrix4.multiplyByUniformScale(m, scale, m);\n *\n * @see Matrix4.multiplyByScale\n * @see Matrix4.fromScale\n * @see Matrix4.fromUniformScale\n * @see Matrix4.setScale\n * @see Matrix4.setUniformScale\n * @see Matrix4.getScale\n */\nMatrix4.multiplyByUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scale;\n result[1] = matrix[1] * scale;\n result[2] = matrix[2] * scale;\n result[3] = matrix[3];\n\n result[4] = matrix[4] * scale;\n result[5] = matrix[5] * scale;\n result[6] = matrix[6] * scale;\n result[7] = matrix[7];\n\n result[8] = matrix[8] * scale;\n result[9] = matrix[9] * scale;\n result[10] = matrix[10] * scale;\n result[11] = matrix[11];\n\n result[12] = matrix[12];\n result[13] = matrix[13];\n result[14] = matrix[14];\n result[15] = matrix[15];\n\n return result;\n};\n\n/**\n * Computes the product of a matrix and a column vector.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Cartesian4} cartesian The vector.\n * @param {Cartesian4} result The object onto which to store the result.\n * @returns {Cartesian4} The modified result parameter.\n */\nMatrix4.multiplyByVector = function (matrix, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const vX = cartesian.x;\n const vY = cartesian.y;\n const vZ = cartesian.z;\n const vW = cartesian.w;\n\n const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12] * vW;\n const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13] * vW;\n const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14] * vW;\n const w = matrix[3] * vX + matrix[7] * vY + matrix[11] * vZ + matrix[15] * vW;\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}\n * with a {@link Cartesian4} with a w component of zero.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Cartesian3} cartesian The point.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n *\n * @example\n * const p = new Cesium.Cartesian3(1.0, 2.0, 3.0);\n * const result = Cesium.Matrix4.multiplyByPointAsVector(matrix, p, new Cesium.Cartesian3());\n * // A shortcut for\n * // Cartesian3 p = ...\n * // Cesium.Matrix4.multiplyByVector(matrix, new Cesium.Cartesian4(p.x, p.y, p.z, 0.0), result);\n */\nMatrix4.multiplyByPointAsVector = function (matrix, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const vX = cartesian.x;\n const vY = cartesian.y;\n const vZ = cartesian.z;\n\n const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ;\n const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ;\n const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ;\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}\n * with a {@link Cartesian4} with a w component of 1, but returns a {@link Cartesian3} instead of a {@link Cartesian4}.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {Cartesian3} cartesian The point.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n *\n * @example\n * const p = new Cesium.Cartesian3(1.0, 2.0, 3.0);\n * const result = Cesium.Matrix4.multiplyByPoint(matrix, p, new Cesium.Cartesian3());\n */\nMatrix4.multiplyByPoint = function (matrix, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const vX = cartesian.x;\n const vY = cartesian.y;\n const vZ = cartesian.z;\n\n const x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12];\n const y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13];\n const z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14];\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Computes the product of a matrix and a scalar.\n *\n * @param {Matrix4} matrix The matrix.\n * @param {number} scalar The number to multiply by.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * //create a Matrix4 instance which is a scaled version of the supplied Matrix4\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * const a = Cesium.Matrix4.multiplyByScalar(m, -2, new Cesium.Matrix4());\n *\n * // m remains the same\n * // a = [-20.0, -22.0, -24.0, -26.0]\n * // [-28.0, -30.0, -32.0, -34.0]\n * // [-36.0, -38.0, -40.0, -42.0]\n * // [-44.0, -46.0, -48.0, -50.0]\n */\nMatrix4.multiplyByScalar = function (matrix, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scalar;\n result[1] = matrix[1] * scalar;\n result[2] = matrix[2] * scalar;\n result[3] = matrix[3] * scalar;\n result[4] = matrix[4] * scalar;\n result[5] = matrix[5] * scalar;\n result[6] = matrix[6] * scalar;\n result[7] = matrix[7] * scalar;\n result[8] = matrix[8] * scalar;\n result[9] = matrix[9] * scalar;\n result[10] = matrix[10] * scalar;\n result[11] = matrix[11] * scalar;\n result[12] = matrix[12] * scalar;\n result[13] = matrix[13] * scalar;\n result[14] = matrix[14] * scalar;\n result[15] = matrix[15] * scalar;\n return result;\n};\n\n/**\n * Computes a negated copy of the provided matrix.\n *\n * @param {Matrix4} matrix The matrix to negate.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * //create a new Matrix4 instance which is a negation of a Matrix4\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * const a = Cesium.Matrix4.negate(m, new Cesium.Matrix4());\n *\n * // m remains the same\n * // a = [-10.0, -11.0, -12.0, -13.0]\n * // [-14.0, -15.0, -16.0, -17.0]\n * // [-18.0, -19.0, -20.0, -21.0]\n * // [-22.0, -23.0, -24.0, -25.0]\n */\nMatrix4.negate = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = -matrix[0];\n result[1] = -matrix[1];\n result[2] = -matrix[2];\n result[3] = -matrix[3];\n result[4] = -matrix[4];\n result[5] = -matrix[5];\n result[6] = -matrix[6];\n result[7] = -matrix[7];\n result[8] = -matrix[8];\n result[9] = -matrix[9];\n result[10] = -matrix[10];\n result[11] = -matrix[11];\n result[12] = -matrix[12];\n result[13] = -matrix[13];\n result[14] = -matrix[14];\n result[15] = -matrix[15];\n return result;\n};\n\n/**\n * Computes the transpose of the provided matrix.\n *\n * @param {Matrix4} matrix The matrix to transpose.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @example\n * //returns transpose of a Matrix4\n * // m = [10.0, 11.0, 12.0, 13.0]\n * // [14.0, 15.0, 16.0, 17.0]\n * // [18.0, 19.0, 20.0, 21.0]\n * // [22.0, 23.0, 24.0, 25.0]\n *\n * const a = Cesium.Matrix4.transpose(m, new Cesium.Matrix4());\n *\n * // m remains the same\n * // a = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n */\nMatrix4.transpose = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const matrix1 = matrix[1];\n const matrix2 = matrix[2];\n const matrix3 = matrix[3];\n const matrix6 = matrix[6];\n const matrix7 = matrix[7];\n const matrix11 = matrix[11];\n\n result[0] = matrix[0];\n result[1] = matrix[4];\n result[2] = matrix[8];\n result[3] = matrix[12];\n result[4] = matrix1;\n result[5] = matrix[5];\n result[6] = matrix[9];\n result[7] = matrix[13];\n result[8] = matrix2;\n result[9] = matrix6;\n result[10] = matrix[10];\n result[11] = matrix[14];\n result[12] = matrix3;\n result[13] = matrix7;\n result[14] = matrix11;\n result[15] = matrix[15];\n return result;\n};\n\n/**\n * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.\n *\n * @param {Matrix4} matrix The matrix with signed elements.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.abs = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = Math.abs(matrix[0]);\n result[1] = Math.abs(matrix[1]);\n result[2] = Math.abs(matrix[2]);\n result[3] = Math.abs(matrix[3]);\n result[4] = Math.abs(matrix[4]);\n result[5] = Math.abs(matrix[5]);\n result[6] = Math.abs(matrix[6]);\n result[7] = Math.abs(matrix[7]);\n result[8] = Math.abs(matrix[8]);\n result[9] = Math.abs(matrix[9]);\n result[10] = Math.abs(matrix[10]);\n result[11] = Math.abs(matrix[11]);\n result[12] = Math.abs(matrix[12]);\n result[13] = Math.abs(matrix[13]);\n result[14] = Math.abs(matrix[14]);\n result[15] = Math.abs(matrix[15]);\n\n return result;\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix4} [left] The first matrix.\n * @param {Matrix4} [right] The second matrix.\n * @returns {boolean} true if left and right are equal, false otherwise.\n *\n * @example\n * //compares two Matrix4 instances\n *\n * // a = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n *\n * // b = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n *\n * if(Cesium.Matrix4.equals(a,b)) {\n * console.log(\"Both matrices are equal\");\n * } else {\n * console.log(\"They are not equal\");\n * }\n *\n * //Prints \"Both matrices are equal\" on the console\n */\nMatrix4.equals = function (left, right) {\n // Given that most matrices will be transformation matrices, the elements\n // are tested in order such that the test is likely to fail as early\n // as possible. I _think_ this is just as friendly to the L1 cache\n // as testing in index order. It is certainty faster in practice.\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n // Translation\n left[12] === right[12] &&\n left[13] === right[13] &&\n left[14] === right[14] &&\n // Rotation/scale\n left[0] === right[0] &&\n left[1] === right[1] &&\n left[2] === right[2] &&\n left[4] === right[4] &&\n left[5] === right[5] &&\n left[6] === right[6] &&\n left[8] === right[8] &&\n left[9] === right[9] &&\n left[10] === right[10] &&\n // Bottom row\n left[3] === right[3] &&\n left[7] === right[7] &&\n left[11] === right[11] &&\n left[15] === right[15])\n );\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix4} [left] The first matrix.\n * @param {Matrix4} [right] The second matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n *\n * @example\n * //compares two Matrix4 instances\n *\n * // a = [10.5, 14.5, 18.5, 22.5]\n * // [11.5, 15.5, 19.5, 23.5]\n * // [12.5, 16.5, 20.5, 24.5]\n * // [13.5, 17.5, 21.5, 25.5]\n *\n * // b = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n *\n * if(Cesium.Matrix4.equalsEpsilon(a,b,0.1)){\n * console.log(\"Difference between both the matrices is less than 0.1\");\n * } else {\n * console.log(\"Difference between both the matrices is not less than 0.1\");\n * }\n *\n * //Prints \"Difference between both the matrices is not less than 0.1\" on the console\n */\nMatrix4.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left[0] - right[0]) <= epsilon &&\n Math.abs(left[1] - right[1]) <= epsilon &&\n Math.abs(left[2] - right[2]) <= epsilon &&\n Math.abs(left[3] - right[3]) <= epsilon &&\n Math.abs(left[4] - right[4]) <= epsilon &&\n Math.abs(left[5] - right[5]) <= epsilon &&\n Math.abs(left[6] - right[6]) <= epsilon &&\n Math.abs(left[7] - right[7]) <= epsilon &&\n Math.abs(left[8] - right[8]) <= epsilon &&\n Math.abs(left[9] - right[9]) <= epsilon &&\n Math.abs(left[10] - right[10]) <= epsilon &&\n Math.abs(left[11] - right[11]) <= epsilon &&\n Math.abs(left[12] - right[12]) <= epsilon &&\n Math.abs(left[13] - right[13]) <= epsilon &&\n Math.abs(left[14] - right[14]) <= epsilon &&\n Math.abs(left[15] - right[15]) <= epsilon)\n );\n};\n\n/**\n * Gets the translation portion of the provided matrix, assuming the matrix is an affine transformation matrix.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nMatrix4.getTranslation = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = matrix[12];\n result.y = matrix[13];\n result.z = matrix[14];\n return result;\n};\n\n/**\n * Gets the upper left 3x3 matrix of the provided matrix.\n *\n * @param {Matrix4} matrix The matrix to use.\n * @param {Matrix3} result The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter.\n *\n * @example\n * // returns a Matrix3 instance from a Matrix4 instance\n *\n * // m = [10.0, 14.0, 18.0, 22.0]\n * // [11.0, 15.0, 19.0, 23.0]\n * // [12.0, 16.0, 20.0, 24.0]\n * // [13.0, 17.0, 21.0, 25.0]\n *\n * const b = new Cesium.Matrix3();\n * Cesium.Matrix4.getMatrix3(m,b);\n *\n * // b = [10.0, 14.0, 18.0]\n * // [11.0, 15.0, 19.0]\n * // [12.0, 16.0, 20.0]\n */\nMatrix4.getMatrix3 = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[4];\n result[4] = matrix[5];\n result[5] = matrix[6];\n result[6] = matrix[8];\n result[7] = matrix[9];\n result[8] = matrix[10];\n return result;\n};\n\nconst scratchInverseRotation = new Matrix3();\nconst scratchMatrix3Zero = new Matrix3();\nconst scratchBottomRow = new Cartesian4();\nconst scratchExpectedBottomRow = new Cartesian4(0.0, 0.0, 0.0, 1.0);\n\n/**\n * Computes the inverse of the provided matrix using Cramers Rule.\n * If the determinant is zero, the matrix can not be inverted, and an exception is thrown.\n * If the matrix is a proper rigid transformation, it is more efficient\n * to invert it with {@link Matrix4.inverseTransformation}.\n *\n * @param {Matrix4} matrix The matrix to invert.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n *\n * @exception {RuntimeError} matrix is not invertible because its determinate is zero.\n */\nMatrix4.inverse = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n //\n // Ported from:\n // ftp://download.intel.com/design/PentiumIII/sml/24504301.pdf\n //\n const src0 = matrix[0];\n const src1 = matrix[4];\n const src2 = matrix[8];\n const src3 = matrix[12];\n const src4 = matrix[1];\n const src5 = matrix[5];\n const src6 = matrix[9];\n const src7 = matrix[13];\n const src8 = matrix[2];\n const src9 = matrix[6];\n const src10 = matrix[10];\n const src11 = matrix[14];\n const src12 = matrix[3];\n const src13 = matrix[7];\n const src14 = matrix[11];\n const src15 = matrix[15];\n\n // calculate pairs for first 8 elements (cofactors)\n let tmp0 = src10 * src15;\n let tmp1 = src11 * src14;\n let tmp2 = src9 * src15;\n let tmp3 = src11 * src13;\n let tmp4 = src9 * src14;\n let tmp5 = src10 * src13;\n let tmp6 = src8 * src15;\n let tmp7 = src11 * src12;\n let tmp8 = src8 * src14;\n let tmp9 = src10 * src12;\n let tmp10 = src8 * src13;\n let tmp11 = src9 * src12;\n\n // calculate first 8 elements (cofactors)\n const dst0 =\n tmp0 * src5 +\n tmp3 * src6 +\n tmp4 * src7 -\n (tmp1 * src5 + tmp2 * src6 + tmp5 * src7);\n const dst1 =\n tmp1 * src4 +\n tmp6 * src6 +\n tmp9 * src7 -\n (tmp0 * src4 + tmp7 * src6 + tmp8 * src7);\n const dst2 =\n tmp2 * src4 +\n tmp7 * src5 +\n tmp10 * src7 -\n (tmp3 * src4 + tmp6 * src5 + tmp11 * src7);\n const dst3 =\n tmp5 * src4 +\n tmp8 * src5 +\n tmp11 * src6 -\n (tmp4 * src4 + tmp9 * src5 + tmp10 * src6);\n const dst4 =\n tmp1 * src1 +\n tmp2 * src2 +\n tmp5 * src3 -\n (tmp0 * src1 + tmp3 * src2 + tmp4 * src3);\n const dst5 =\n tmp0 * src0 +\n tmp7 * src2 +\n tmp8 * src3 -\n (tmp1 * src0 + tmp6 * src2 + tmp9 * src3);\n const dst6 =\n tmp3 * src0 +\n tmp6 * src1 +\n tmp11 * src3 -\n (tmp2 * src0 + tmp7 * src1 + tmp10 * src3);\n const dst7 =\n tmp4 * src0 +\n tmp9 * src1 +\n tmp10 * src2 -\n (tmp5 * src0 + tmp8 * src1 + tmp11 * src2);\n\n // calculate pairs for second 8 elements (cofactors)\n tmp0 = src2 * src7;\n tmp1 = src3 * src6;\n tmp2 = src1 * src7;\n tmp3 = src3 * src5;\n tmp4 = src1 * src6;\n tmp5 = src2 * src5;\n tmp6 = src0 * src7;\n tmp7 = src3 * src4;\n tmp8 = src0 * src6;\n tmp9 = src2 * src4;\n tmp10 = src0 * src5;\n tmp11 = src1 * src4;\n\n // calculate second 8 elements (cofactors)\n const dst8 =\n tmp0 * src13 +\n tmp3 * src14 +\n tmp4 * src15 -\n (tmp1 * src13 + tmp2 * src14 + tmp5 * src15);\n const dst9 =\n tmp1 * src12 +\n tmp6 * src14 +\n tmp9 * src15 -\n (tmp0 * src12 + tmp7 * src14 + tmp8 * src15);\n const dst10 =\n tmp2 * src12 +\n tmp7 * src13 +\n tmp10 * src15 -\n (tmp3 * src12 + tmp6 * src13 + tmp11 * src15);\n const dst11 =\n tmp5 * src12 +\n tmp8 * src13 +\n tmp11 * src14 -\n (tmp4 * src12 + tmp9 * src13 + tmp10 * src14);\n const dst12 =\n tmp2 * src10 +\n tmp5 * src11 +\n tmp1 * src9 -\n (tmp4 * src11 + tmp0 * src9 + tmp3 * src10);\n const dst13 =\n tmp8 * src11 +\n tmp0 * src8 +\n tmp7 * src10 -\n (tmp6 * src10 + tmp9 * src11 + tmp1 * src8);\n const dst14 =\n tmp6 * src9 +\n tmp11 * src11 +\n tmp3 * src8 -\n (tmp10 * src11 + tmp2 * src8 + tmp7 * src9);\n const dst15 =\n tmp10 * src10 +\n tmp4 * src8 +\n tmp9 * src9 -\n (tmp8 * src9 + tmp11 * src10 + tmp5 * src8);\n\n // calculate determinant\n let det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;\n\n if (Math.abs(det) < CesiumMath.EPSILON21) {\n // Special case for a zero scale matrix that can occur, for example,\n // when a model's node has a [0, 0, 0] scale.\n if (\n Matrix3.equalsEpsilon(\n Matrix4.getMatrix3(matrix, scratchInverseRotation),\n scratchMatrix3Zero,\n CesiumMath.EPSILON7\n ) &&\n Cartesian4.equals(\n Matrix4.getRow(matrix, 3, scratchBottomRow),\n scratchExpectedBottomRow\n )\n ) {\n result[0] = 0.0;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = 0.0;\n result[4] = 0.0;\n result[5] = 0.0;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 0.0;\n result[9] = 0.0;\n result[10] = 0.0;\n result[11] = 0.0;\n result[12] = -matrix[12];\n result[13] = -matrix[13];\n result[14] = -matrix[14];\n result[15] = 1.0;\n return result;\n }\n\n throw new RuntimeError(\n \"matrix is not invertible because its determinate is zero.\"\n );\n }\n\n // calculate matrix inverse\n det = 1.0 / det;\n\n result[0] = dst0 * det;\n result[1] = dst1 * det;\n result[2] = dst2 * det;\n result[3] = dst3 * det;\n result[4] = dst4 * det;\n result[5] = dst5 * det;\n result[6] = dst6 * det;\n result[7] = dst7 * det;\n result[8] = dst8 * det;\n result[9] = dst9 * det;\n result[10] = dst10 * det;\n result[11] = dst11 * det;\n result[12] = dst12 * det;\n result[13] = dst13 * det;\n result[14] = dst14 * det;\n result[15] = dst15 * det;\n return result;\n};\n\n/**\n * Computes the inverse of the provided matrix assuming it is a proper rigid matrix,\n * where the upper left 3x3 elements are a rotation matrix,\n * and the upper three elements in the fourth column are the translation.\n * The bottom row is assumed to be [0, 0, 0, 1].\n * The matrix is not verified to be in the proper form.\n * This method is faster than computing the inverse for a general 4x4\n * matrix using {@link Matrix4.inverse}.\n *\n * @param {Matrix4} matrix The matrix to invert.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.inverseTransformation = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n //This function is an optimized version of the below 4 lines.\n //const rT = Matrix3.transpose(Matrix4.getMatrix3(matrix));\n //const rTN = Matrix3.negate(rT);\n //const rTT = Matrix3.multiplyByVector(rTN, Matrix4.getTranslation(matrix));\n //return Matrix4.fromRotationTranslation(rT, rTT, result);\n\n const matrix0 = matrix[0];\n const matrix1 = matrix[1];\n const matrix2 = matrix[2];\n const matrix4 = matrix[4];\n const matrix5 = matrix[5];\n const matrix6 = matrix[6];\n const matrix8 = matrix[8];\n const matrix9 = matrix[9];\n const matrix10 = matrix[10];\n\n const vX = matrix[12];\n const vY = matrix[13];\n const vZ = matrix[14];\n\n const x = -matrix0 * vX - matrix1 * vY - matrix2 * vZ;\n const y = -matrix4 * vX - matrix5 * vY - matrix6 * vZ;\n const z = -matrix8 * vX - matrix9 * vY - matrix10 * vZ;\n\n result[0] = matrix0;\n result[1] = matrix4;\n result[2] = matrix8;\n result[3] = 0.0;\n result[4] = matrix1;\n result[5] = matrix5;\n result[6] = matrix9;\n result[7] = 0.0;\n result[8] = matrix2;\n result[9] = matrix6;\n result[10] = matrix10;\n result[11] = 0.0;\n result[12] = x;\n result[13] = y;\n result[14] = z;\n result[15] = 1.0;\n return result;\n};\n\nconst scratchTransposeMatrix = new Matrix4();\n\n/**\n * Computes the inverse transpose of a matrix.\n *\n * @param {Matrix4} matrix The matrix to transpose and invert.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter.\n */\nMatrix4.inverseTranspose = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n return Matrix4.inverse(\n Matrix4.transpose(matrix, scratchTransposeMatrix),\n result\n );\n};\n\n/**\n * An immutable Matrix4 instance initialized to the identity matrix.\n *\n * @type {Matrix4}\n * @constant\n */\nMatrix4.IDENTITY = Object.freeze(\n new Matrix4(\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n )\n);\n\n/**\n * An immutable Matrix4 instance initialized to the zero matrix.\n *\n * @type {Matrix4}\n * @constant\n */\nMatrix4.ZERO = Object.freeze(\n new Matrix4(\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0\n )\n);\n\n/**\n * The index into Matrix4 for column 0, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN0ROW0 = 0;\n\n/**\n * The index into Matrix4 for column 0, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN0ROW1 = 1;\n\n/**\n * The index into Matrix4 for column 0, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN0ROW2 = 2;\n\n/**\n * The index into Matrix4 for column 0, row 3.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN0ROW3 = 3;\n\n/**\n * The index into Matrix4 for column 1, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN1ROW0 = 4;\n\n/**\n * The index into Matrix4 for column 1, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN1ROW1 = 5;\n\n/**\n * The index into Matrix4 for column 1, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN1ROW2 = 6;\n\n/**\n * The index into Matrix4 for column 1, row 3.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN1ROW3 = 7;\n\n/**\n * The index into Matrix4 for column 2, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN2ROW0 = 8;\n\n/**\n * The index into Matrix4 for column 2, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN2ROW1 = 9;\n\n/**\n * The index into Matrix4 for column 2, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN2ROW2 = 10;\n\n/**\n * The index into Matrix4 for column 2, row 3.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN2ROW3 = 11;\n\n/**\n * The index into Matrix4 for column 3, row 0.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN3ROW0 = 12;\n\n/**\n * The index into Matrix4 for column 3, row 1.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN3ROW1 = 13;\n\n/**\n * The index into Matrix4 for column 3, row 2.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN3ROW2 = 14;\n\n/**\n * The index into Matrix4 for column 3, row 3.\n *\n * @type {number}\n * @constant\n */\nMatrix4.COLUMN3ROW3 = 15;\n\nObject.defineProperties(Matrix4.prototype, {\n /**\n * Gets the number of items in the collection.\n * @memberof Matrix4.prototype\n *\n * @type {number}\n */\n length: {\n get: function () {\n return Matrix4.packedLength;\n },\n },\n});\n\n/**\n * Duplicates the provided Matrix4 instance.\n *\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.\n */\nMatrix4.prototype.clone = function (result) {\n return Matrix4.clone(this, result);\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix4} [right] The right hand side matrix.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nMatrix4.prototype.equals = function (right) {\n return Matrix4.equals(this, right);\n};\n\n/**\n * @private\n */\nMatrix4.equalsArray = function (matrix, array, offset) {\n return (\n matrix[0] === array[offset] &&\n matrix[1] === array[offset + 1] &&\n matrix[2] === array[offset + 2] &&\n matrix[3] === array[offset + 3] &&\n matrix[4] === array[offset + 4] &&\n matrix[5] === array[offset + 5] &&\n matrix[6] === array[offset + 6] &&\n matrix[7] === array[offset + 7] &&\n matrix[8] === array[offset + 8] &&\n matrix[9] === array[offset + 9] &&\n matrix[10] === array[offset + 10] &&\n matrix[11] === array[offset + 11] &&\n matrix[12] === array[offset + 12] &&\n matrix[13] === array[offset + 13] &&\n matrix[14] === array[offset + 14] &&\n matrix[15] === array[offset + 15]\n );\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix4} [right] The right hand side matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nMatrix4.prototype.equalsEpsilon = function (right, epsilon) {\n return Matrix4.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Computes a string representing this Matrix with each row being\n * on a separate line and in the format '(column0, column1, column2, column3)'.\n *\n * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'.\n */\nMatrix4.prototype.toString = function () {\n return (\n `(${this[0]}, ${this[4]}, ${this[8]}, ${this[12]})\\n` +\n `(${this[1]}, ${this[5]}, ${this[9]}, ${this[13]})\\n` +\n `(${this[2]}, ${this[6]}, ${this[10]}, ${this[14]})\\n` +\n `(${this[3]}, ${this[7]}, ${this[11]}, ${this[15]})`\n );\n};\nexport default Matrix4;\n", "/**\n * Enum containing WebGL Constant values by name.\n * for use without an active WebGL context, or in cases where certain constants are unavailable using the WebGL context\n * (For example, in [Safari 9]{@link https://github.com/CesiumGS/cesium/issues/2989}).\n *\n * These match the constants from the [WebGL 1.0]{@link https://www.khronos.org/registry/webgl/specs/latest/1.0/}\n * and [WebGL 2.0]{@link https://www.khronos.org/registry/webgl/specs/latest/2.0/}\n * specifications.\n *\n * @enum {number}\n */\nconst WebGLConstants = {\n DEPTH_BUFFER_BIT: 0x00000100,\n STENCIL_BUFFER_BIT: 0x00000400,\n COLOR_BUFFER_BIT: 0x00004000,\n POINTS: 0x0000,\n LINES: 0x0001,\n LINE_LOOP: 0x0002,\n LINE_STRIP: 0x0003,\n TRIANGLES: 0x0004,\n TRIANGLE_STRIP: 0x0005,\n TRIANGLE_FAN: 0x0006,\n ZERO: 0,\n ONE: 1,\n SRC_COLOR: 0x0300,\n ONE_MINUS_SRC_COLOR: 0x0301,\n SRC_ALPHA: 0x0302,\n ONE_MINUS_SRC_ALPHA: 0x0303,\n DST_ALPHA: 0x0304,\n ONE_MINUS_DST_ALPHA: 0x0305,\n DST_COLOR: 0x0306,\n ONE_MINUS_DST_COLOR: 0x0307,\n SRC_ALPHA_SATURATE: 0x0308,\n FUNC_ADD: 0x8006,\n BLEND_EQUATION: 0x8009,\n BLEND_EQUATION_RGB: 0x8009, // same as BLEND_EQUATION\n BLEND_EQUATION_ALPHA: 0x883d,\n FUNC_SUBTRACT: 0x800a,\n FUNC_REVERSE_SUBTRACT: 0x800b,\n BLEND_DST_RGB: 0x80c8,\n BLEND_SRC_RGB: 0x80c9,\n BLEND_DST_ALPHA: 0x80ca,\n BLEND_SRC_ALPHA: 0x80cb,\n CONSTANT_COLOR: 0x8001,\n ONE_MINUS_CONSTANT_COLOR: 0x8002,\n CONSTANT_ALPHA: 0x8003,\n ONE_MINUS_CONSTANT_ALPHA: 0x8004,\n BLEND_COLOR: 0x8005,\n ARRAY_BUFFER: 0x8892,\n ELEMENT_ARRAY_BUFFER: 0x8893,\n ARRAY_BUFFER_BINDING: 0x8894,\n ELEMENT_ARRAY_BUFFER_BINDING: 0x8895,\n STREAM_DRAW: 0x88e0,\n STATIC_DRAW: 0x88e4,\n DYNAMIC_DRAW: 0x88e8,\n BUFFER_SIZE: 0x8764,\n BUFFER_USAGE: 0x8765,\n CURRENT_VERTEX_ATTRIB: 0x8626,\n FRONT: 0x0404,\n BACK: 0x0405,\n FRONT_AND_BACK: 0x0408,\n CULL_FACE: 0x0b44,\n BLEND: 0x0be2,\n DITHER: 0x0bd0,\n STENCIL_TEST: 0x0b90,\n DEPTH_TEST: 0x0b71,\n SCISSOR_TEST: 0x0c11,\n POLYGON_OFFSET_FILL: 0x8037,\n SAMPLE_ALPHA_TO_COVERAGE: 0x809e,\n SAMPLE_COVERAGE: 0x80a0,\n NO_ERROR: 0,\n INVALID_ENUM: 0x0500,\n INVALID_VALUE: 0x0501,\n INVALID_OPERATION: 0x0502,\n OUT_OF_MEMORY: 0x0505,\n CW: 0x0900,\n CCW: 0x0901,\n LINE_WIDTH: 0x0b21,\n ALIASED_POINT_SIZE_RANGE: 0x846d,\n ALIASED_LINE_WIDTH_RANGE: 0x846e,\n CULL_FACE_MODE: 0x0b45,\n FRONT_FACE: 0x0b46,\n DEPTH_RANGE: 0x0b70,\n DEPTH_WRITEMASK: 0x0b72,\n DEPTH_CLEAR_VALUE: 0x0b73,\n DEPTH_FUNC: 0x0b74,\n STENCIL_CLEAR_VALUE: 0x0b91,\n STENCIL_FUNC: 0x0b92,\n STENCIL_FAIL: 0x0b94,\n STENCIL_PASS_DEPTH_FAIL: 0x0b95,\n STENCIL_PASS_DEPTH_PASS: 0x0b96,\n STENCIL_REF: 0x0b97,\n STENCIL_VALUE_MASK: 0x0b93,\n STENCIL_WRITEMASK: 0x0b98,\n STENCIL_BACK_FUNC: 0x8800,\n STENCIL_BACK_FAIL: 0x8801,\n STENCIL_BACK_PASS_DEPTH_FAIL: 0x8802,\n STENCIL_BACK_PASS_DEPTH_PASS: 0x8803,\n STENCIL_BACK_REF: 0x8ca3,\n STENCIL_BACK_VALUE_MASK: 0x8ca4,\n STENCIL_BACK_WRITEMASK: 0x8ca5,\n VIEWPORT: 0x0ba2,\n SCISSOR_BOX: 0x0c10,\n COLOR_CLEAR_VALUE: 0x0c22,\n COLOR_WRITEMASK: 0x0c23,\n UNPACK_ALIGNMENT: 0x0cf5,\n PACK_ALIGNMENT: 0x0d05,\n MAX_TEXTURE_SIZE: 0x0d33,\n MAX_VIEWPORT_DIMS: 0x0d3a,\n SUBPIXEL_BITS: 0x0d50,\n RED_BITS: 0x0d52,\n GREEN_BITS: 0x0d53,\n BLUE_BITS: 0x0d54,\n ALPHA_BITS: 0x0d55,\n DEPTH_BITS: 0x0d56,\n STENCIL_BITS: 0x0d57,\n POLYGON_OFFSET_UNITS: 0x2a00,\n POLYGON_OFFSET_FACTOR: 0x8038,\n TEXTURE_BINDING_2D: 0x8069,\n SAMPLE_BUFFERS: 0x80a8,\n SAMPLES: 0x80a9,\n SAMPLE_COVERAGE_VALUE: 0x80aa,\n SAMPLE_COVERAGE_INVERT: 0x80ab,\n COMPRESSED_TEXTURE_FORMATS: 0x86a3,\n DONT_CARE: 0x1100,\n FASTEST: 0x1101,\n NICEST: 0x1102,\n GENERATE_MIPMAP_HINT: 0x8192,\n BYTE: 0x1400,\n UNSIGNED_BYTE: 0x1401,\n SHORT: 0x1402,\n UNSIGNED_SHORT: 0x1403,\n INT: 0x1404,\n UNSIGNED_INT: 0x1405,\n FLOAT: 0x1406,\n DEPTH_COMPONENT: 0x1902,\n ALPHA: 0x1906,\n RGB: 0x1907,\n RGBA: 0x1908,\n LUMINANCE: 0x1909,\n LUMINANCE_ALPHA: 0x190a,\n UNSIGNED_SHORT_4_4_4_4: 0x8033,\n UNSIGNED_SHORT_5_5_5_1: 0x8034,\n UNSIGNED_SHORT_5_6_5: 0x8363,\n FRAGMENT_SHADER: 0x8b30,\n VERTEX_SHADER: 0x8b31,\n MAX_VERTEX_ATTRIBS: 0x8869,\n MAX_VERTEX_UNIFORM_VECTORS: 0x8dfb,\n MAX_VARYING_VECTORS: 0x8dfc,\n MAX_COMBINED_TEXTURE_IMAGE_UNITS: 0x8b4d,\n MAX_VERTEX_TEXTURE_IMAGE_UNITS: 0x8b4c,\n MAX_TEXTURE_IMAGE_UNITS: 0x8872,\n MAX_FRAGMENT_UNIFORM_VECTORS: 0x8dfd,\n SHADER_TYPE: 0x8b4f,\n DELETE_STATUS: 0x8b80,\n LINK_STATUS: 0x8b82,\n VALIDATE_STATUS: 0x8b83,\n ATTACHED_SHADERS: 0x8b85,\n ACTIVE_UNIFORMS: 0x8b86,\n ACTIVE_ATTRIBUTES: 0x8b89,\n SHADING_LANGUAGE_VERSION: 0x8b8c,\n CURRENT_PROGRAM: 0x8b8d,\n NEVER: 0x0200,\n LESS: 0x0201,\n EQUAL: 0x0202,\n LEQUAL: 0x0203,\n GREATER: 0x0204,\n NOTEQUAL: 0x0205,\n GEQUAL: 0x0206,\n ALWAYS: 0x0207,\n KEEP: 0x1e00,\n REPLACE: 0x1e01,\n INCR: 0x1e02,\n DECR: 0x1e03,\n INVERT: 0x150a,\n INCR_WRAP: 0x8507,\n DECR_WRAP: 0x8508,\n VENDOR: 0x1f00,\n RENDERER: 0x1f01,\n VERSION: 0x1f02,\n NEAREST: 0x2600,\n LINEAR: 0x2601,\n NEAREST_MIPMAP_NEAREST: 0x2700,\n LINEAR_MIPMAP_NEAREST: 0x2701,\n NEAREST_MIPMAP_LINEAR: 0x2702,\n LINEAR_MIPMAP_LINEAR: 0x2703,\n TEXTURE_MAG_FILTER: 0x2800,\n TEXTURE_MIN_FILTER: 0x2801,\n TEXTURE_WRAP_S: 0x2802,\n TEXTURE_WRAP_T: 0x2803,\n TEXTURE_2D: 0x0de1,\n TEXTURE: 0x1702,\n TEXTURE_CUBE_MAP: 0x8513,\n TEXTURE_BINDING_CUBE_MAP: 0x8514,\n TEXTURE_CUBE_MAP_POSITIVE_X: 0x8515,\n TEXTURE_CUBE_MAP_NEGATIVE_X: 0x8516,\n TEXTURE_CUBE_MAP_POSITIVE_Y: 0x8517,\n TEXTURE_CUBE_MAP_NEGATIVE_Y: 0x8518,\n TEXTURE_CUBE_MAP_POSITIVE_Z: 0x8519,\n TEXTURE_CUBE_MAP_NEGATIVE_Z: 0x851a,\n MAX_CUBE_MAP_TEXTURE_SIZE: 0x851c,\n TEXTURE0: 0x84c0,\n TEXTURE1: 0x84c1,\n TEXTURE2: 0x84c2,\n TEXTURE3: 0x84c3,\n TEXTURE4: 0x84c4,\n TEXTURE5: 0x84c5,\n TEXTURE6: 0x84c6,\n TEXTURE7: 0x84c7,\n TEXTURE8: 0x84c8,\n TEXTURE9: 0x84c9,\n TEXTURE10: 0x84ca,\n TEXTURE11: 0x84cb,\n TEXTURE12: 0x84cc,\n TEXTURE13: 0x84cd,\n TEXTURE14: 0x84ce,\n TEXTURE15: 0x84cf,\n TEXTURE16: 0x84d0,\n TEXTURE17: 0x84d1,\n TEXTURE18: 0x84d2,\n TEXTURE19: 0x84d3,\n TEXTURE20: 0x84d4,\n TEXTURE21: 0x84d5,\n TEXTURE22: 0x84d6,\n TEXTURE23: 0x84d7,\n TEXTURE24: 0x84d8,\n TEXTURE25: 0x84d9,\n TEXTURE26: 0x84da,\n TEXTURE27: 0x84db,\n TEXTURE28: 0x84dc,\n TEXTURE29: 0x84dd,\n TEXTURE30: 0x84de,\n TEXTURE31: 0x84df,\n ACTIVE_TEXTURE: 0x84e0,\n REPEAT: 0x2901,\n CLAMP_TO_EDGE: 0x812f,\n MIRRORED_REPEAT: 0x8370,\n FLOAT_VEC2: 0x8b50,\n FLOAT_VEC3: 0x8b51,\n FLOAT_VEC4: 0x8b52,\n INT_VEC2: 0x8b53,\n INT_VEC3: 0x8b54,\n INT_VEC4: 0x8b55,\n BOOL: 0x8b56,\n BOOL_VEC2: 0x8b57,\n BOOL_VEC3: 0x8b58,\n BOOL_VEC4: 0x8b59,\n FLOAT_MAT2: 0x8b5a,\n FLOAT_MAT3: 0x8b5b,\n FLOAT_MAT4: 0x8b5c,\n SAMPLER_2D: 0x8b5e,\n SAMPLER_CUBE: 0x8b60,\n VERTEX_ATTRIB_ARRAY_ENABLED: 0x8622,\n VERTEX_ATTRIB_ARRAY_SIZE: 0x8623,\n VERTEX_ATTRIB_ARRAY_STRIDE: 0x8624,\n VERTEX_ATTRIB_ARRAY_TYPE: 0x8625,\n VERTEX_ATTRIB_ARRAY_NORMALIZED: 0x886a,\n VERTEX_ATTRIB_ARRAY_POINTER: 0x8645,\n VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 0x889f,\n IMPLEMENTATION_COLOR_READ_TYPE: 0x8b9a,\n IMPLEMENTATION_COLOR_READ_FORMAT: 0x8b9b,\n COMPILE_STATUS: 0x8b81,\n LOW_FLOAT: 0x8df0,\n MEDIUM_FLOAT: 0x8df1,\n HIGH_FLOAT: 0x8df2,\n LOW_INT: 0x8df3,\n MEDIUM_INT: 0x8df4,\n HIGH_INT: 0x8df5,\n FRAMEBUFFER: 0x8d40,\n RENDERBUFFER: 0x8d41,\n RGBA4: 0x8056,\n RGB5_A1: 0x8057,\n RGB565: 0x8d62,\n DEPTH_COMPONENT16: 0x81a5,\n STENCIL_INDEX: 0x1901,\n STENCIL_INDEX8: 0x8d48,\n DEPTH_STENCIL: 0x84f9,\n RENDERBUFFER_WIDTH: 0x8d42,\n RENDERBUFFER_HEIGHT: 0x8d43,\n RENDERBUFFER_INTERNAL_FORMAT: 0x8d44,\n RENDERBUFFER_RED_SIZE: 0x8d50,\n RENDERBUFFER_GREEN_SIZE: 0x8d51,\n RENDERBUFFER_BLUE_SIZE: 0x8d52,\n RENDERBUFFER_ALPHA_SIZE: 0x8d53,\n RENDERBUFFER_DEPTH_SIZE: 0x8d54,\n RENDERBUFFER_STENCIL_SIZE: 0x8d55,\n FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 0x8cd0,\n FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 0x8cd1,\n FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 0x8cd2,\n FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 0x8cd3,\n COLOR_ATTACHMENT0: 0x8ce0,\n DEPTH_ATTACHMENT: 0x8d00,\n STENCIL_ATTACHMENT: 0x8d20,\n DEPTH_STENCIL_ATTACHMENT: 0x821a,\n NONE: 0,\n FRAMEBUFFER_COMPLETE: 0x8cd5,\n FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 0x8cd6,\n FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 0x8cd7,\n FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 0x8cd9,\n FRAMEBUFFER_UNSUPPORTED: 0x8cdd,\n FRAMEBUFFER_BINDING: 0x8ca6,\n RENDERBUFFER_BINDING: 0x8ca7,\n MAX_RENDERBUFFER_SIZE: 0x84e8,\n INVALID_FRAMEBUFFER_OPERATION: 0x0506,\n UNPACK_FLIP_Y_WEBGL: 0x9240,\n UNPACK_PREMULTIPLY_ALPHA_WEBGL: 0x9241,\n CONTEXT_LOST_WEBGL: 0x9242,\n UNPACK_COLORSPACE_CONVERSION_WEBGL: 0x9243,\n BROWSER_DEFAULT_WEBGL: 0x9244,\n\n // WEBGL_compressed_texture_s3tc\n COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0,\n COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1,\n COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2,\n COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3,\n\n // WEBGL_compressed_texture_pvrtc\n COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00,\n COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01,\n COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02,\n COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03,\n\n // WEBGL_compressed_texture_astc\n COMPRESSED_RGBA_ASTC_4x4_WEBGL: 0x93b0,\n\n // WEBGL_compressed_texture_etc1\n COMPRESSED_RGB_ETC1_WEBGL: 0x8d64,\n\n // EXT_texture_compression_bptc\n COMPRESSED_RGBA_BPTC_UNORM: 0x8e8c,\n\n // EXT_color_buffer_half_float\n HALF_FLOAT_OES: 0x8d61,\n\n // Desktop OpenGL\n DOUBLE: 0x140a,\n\n // WebGL 2\n READ_BUFFER: 0x0c02,\n UNPACK_ROW_LENGTH: 0x0cf2,\n UNPACK_SKIP_ROWS: 0x0cf3,\n UNPACK_SKIP_PIXELS: 0x0cf4,\n PACK_ROW_LENGTH: 0x0d02,\n PACK_SKIP_ROWS: 0x0d03,\n PACK_SKIP_PIXELS: 0x0d04,\n COLOR: 0x1800,\n DEPTH: 0x1801,\n STENCIL: 0x1802,\n RED: 0x1903,\n RGB8: 0x8051,\n RGBA8: 0x8058,\n RGB10_A2: 0x8059,\n TEXTURE_BINDING_3D: 0x806a,\n UNPACK_SKIP_IMAGES: 0x806d,\n UNPACK_IMAGE_HEIGHT: 0x806e,\n TEXTURE_3D: 0x806f,\n TEXTURE_WRAP_R: 0x8072,\n MAX_3D_TEXTURE_SIZE: 0x8073,\n UNSIGNED_INT_2_10_10_10_REV: 0x8368,\n MAX_ELEMENTS_VERTICES: 0x80e8,\n MAX_ELEMENTS_INDICES: 0x80e9,\n TEXTURE_MIN_LOD: 0x813a,\n TEXTURE_MAX_LOD: 0x813b,\n TEXTURE_BASE_LEVEL: 0x813c,\n TEXTURE_MAX_LEVEL: 0x813d,\n MIN: 0x8007,\n MAX: 0x8008,\n DEPTH_COMPONENT24: 0x81a6,\n MAX_TEXTURE_LOD_BIAS: 0x84fd,\n TEXTURE_COMPARE_MODE: 0x884c,\n TEXTURE_COMPARE_FUNC: 0x884d,\n CURRENT_QUERY: 0x8865,\n QUERY_RESULT: 0x8866,\n QUERY_RESULT_AVAILABLE: 0x8867,\n STREAM_READ: 0x88e1,\n STREAM_COPY: 0x88e2,\n STATIC_READ: 0x88e5,\n STATIC_COPY: 0x88e6,\n DYNAMIC_READ: 0x88e9,\n DYNAMIC_COPY: 0x88ea,\n MAX_DRAW_BUFFERS: 0x8824,\n DRAW_BUFFER0: 0x8825,\n DRAW_BUFFER1: 0x8826,\n DRAW_BUFFER2: 0x8827,\n DRAW_BUFFER3: 0x8828,\n DRAW_BUFFER4: 0x8829,\n DRAW_BUFFER5: 0x882a,\n DRAW_BUFFER6: 0x882b,\n DRAW_BUFFER7: 0x882c,\n DRAW_BUFFER8: 0x882d,\n DRAW_BUFFER9: 0x882e,\n DRAW_BUFFER10: 0x882f,\n DRAW_BUFFER11: 0x8830,\n DRAW_BUFFER12: 0x8831,\n DRAW_BUFFER13: 0x8832,\n DRAW_BUFFER14: 0x8833,\n DRAW_BUFFER15: 0x8834,\n MAX_FRAGMENT_UNIFORM_COMPONENTS: 0x8b49,\n MAX_VERTEX_UNIFORM_COMPONENTS: 0x8b4a,\n SAMPLER_3D: 0x8b5f,\n SAMPLER_2D_SHADOW: 0x8b62,\n FRAGMENT_SHADER_DERIVATIVE_HINT: 0x8b8b,\n PIXEL_PACK_BUFFER: 0x88eb,\n PIXEL_UNPACK_BUFFER: 0x88ec,\n PIXEL_PACK_BUFFER_BINDING: 0x88ed,\n PIXEL_UNPACK_BUFFER_BINDING: 0x88ef,\n FLOAT_MAT2x3: 0x8b65,\n FLOAT_MAT2x4: 0x8b66,\n FLOAT_MAT3x2: 0x8b67,\n FLOAT_MAT3x4: 0x8b68,\n FLOAT_MAT4x2: 0x8b69,\n FLOAT_MAT4x3: 0x8b6a,\n SRGB: 0x8c40,\n SRGB8: 0x8c41,\n SRGB8_ALPHA8: 0x8c43,\n COMPARE_REF_TO_TEXTURE: 0x884e,\n RGBA32F: 0x8814,\n RGB32F: 0x8815,\n RGBA16F: 0x881a,\n RGB16F: 0x881b,\n VERTEX_ATTRIB_ARRAY_INTEGER: 0x88fd,\n MAX_ARRAY_TEXTURE_LAYERS: 0x88ff,\n MIN_PROGRAM_TEXEL_OFFSET: 0x8904,\n MAX_PROGRAM_TEXEL_OFFSET: 0x8905,\n MAX_VARYING_COMPONENTS: 0x8b4b,\n TEXTURE_2D_ARRAY: 0x8c1a,\n TEXTURE_BINDING_2D_ARRAY: 0x8c1d,\n R11F_G11F_B10F: 0x8c3a,\n UNSIGNED_INT_10F_11F_11F_REV: 0x8c3b,\n RGB9_E5: 0x8c3d,\n UNSIGNED_INT_5_9_9_9_REV: 0x8c3e,\n TRANSFORM_FEEDBACK_BUFFER_MODE: 0x8c7f,\n MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: 0x8c80,\n TRANSFORM_FEEDBACK_VARYINGS: 0x8c83,\n TRANSFORM_FEEDBACK_BUFFER_START: 0x8c84,\n TRANSFORM_FEEDBACK_BUFFER_SIZE: 0x8c85,\n TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: 0x8c88,\n RASTERIZER_DISCARD: 0x8c89,\n MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: 0x8c8a,\n MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: 0x8c8b,\n INTERLEAVED_ATTRIBS: 0x8c8c,\n SEPARATE_ATTRIBS: 0x8c8d,\n TRANSFORM_FEEDBACK_BUFFER: 0x8c8e,\n TRANSFORM_FEEDBACK_BUFFER_BINDING: 0x8c8f,\n RGBA32UI: 0x8d70,\n RGB32UI: 0x8d71,\n RGBA16UI: 0x8d76,\n RGB16UI: 0x8d77,\n RGBA8UI: 0x8d7c,\n RGB8UI: 0x8d7d,\n RGBA32I: 0x8d82,\n RGB32I: 0x8d83,\n RGBA16I: 0x8d88,\n RGB16I: 0x8d89,\n RGBA8I: 0x8d8e,\n RGB8I: 0x8d8f,\n RED_INTEGER: 0x8d94,\n RGB_INTEGER: 0x8d98,\n RGBA_INTEGER: 0x8d99,\n SAMPLER_2D_ARRAY: 0x8dc1,\n SAMPLER_2D_ARRAY_SHADOW: 0x8dc4,\n SAMPLER_CUBE_SHADOW: 0x8dc5,\n UNSIGNED_INT_VEC2: 0x8dc6,\n UNSIGNED_INT_VEC3: 0x8dc7,\n UNSIGNED_INT_VEC4: 0x8dc8,\n INT_SAMPLER_2D: 0x8dca,\n INT_SAMPLER_3D: 0x8dcb,\n INT_SAMPLER_CUBE: 0x8dcc,\n INT_SAMPLER_2D_ARRAY: 0x8dcf,\n UNSIGNED_INT_SAMPLER_2D: 0x8dd2,\n UNSIGNED_INT_SAMPLER_3D: 0x8dd3,\n UNSIGNED_INT_SAMPLER_CUBE: 0x8dd4,\n UNSIGNED_INT_SAMPLER_2D_ARRAY: 0x8dd7,\n DEPTH_COMPONENT32F: 0x8cac,\n DEPTH32F_STENCIL8: 0x8cad,\n FLOAT_32_UNSIGNED_INT_24_8_REV: 0x8dad,\n FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: 0x8210,\n FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: 0x8211,\n FRAMEBUFFER_ATTACHMENT_RED_SIZE: 0x8212,\n FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: 0x8213,\n FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: 0x8214,\n FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: 0x8215,\n FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: 0x8216,\n FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: 0x8217,\n FRAMEBUFFER_DEFAULT: 0x8218,\n UNSIGNED_INT_24_8: 0x84fa,\n DEPTH24_STENCIL8: 0x88f0,\n UNSIGNED_NORMALIZED: 0x8c17,\n DRAW_FRAMEBUFFER_BINDING: 0x8ca6, // Same as FRAMEBUFFER_BINDING\n READ_FRAMEBUFFER: 0x8ca8,\n DRAW_FRAMEBUFFER: 0x8ca9,\n READ_FRAMEBUFFER_BINDING: 0x8caa,\n RENDERBUFFER_SAMPLES: 0x8cab,\n FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: 0x8cd4,\n MAX_COLOR_ATTACHMENTS: 0x8cdf,\n COLOR_ATTACHMENT1: 0x8ce1,\n COLOR_ATTACHMENT2: 0x8ce2,\n COLOR_ATTACHMENT3: 0x8ce3,\n COLOR_ATTACHMENT4: 0x8ce4,\n COLOR_ATTACHMENT5: 0x8ce5,\n COLOR_ATTACHMENT6: 0x8ce6,\n COLOR_ATTACHMENT7: 0x8ce7,\n COLOR_ATTACHMENT8: 0x8ce8,\n COLOR_ATTACHMENT9: 0x8ce9,\n COLOR_ATTACHMENT10: 0x8cea,\n COLOR_ATTACHMENT11: 0x8ceb,\n COLOR_ATTACHMENT12: 0x8cec,\n COLOR_ATTACHMENT13: 0x8ced,\n COLOR_ATTACHMENT14: 0x8cee,\n COLOR_ATTACHMENT15: 0x8cef,\n FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: 0x8d56,\n MAX_SAMPLES: 0x8d57,\n HALF_FLOAT: 0x140b,\n RG: 0x8227,\n RG_INTEGER: 0x8228,\n R8: 0x8229,\n RG8: 0x822b,\n R16F: 0x822d,\n R32F: 0x822e,\n RG16F: 0x822f,\n RG32F: 0x8230,\n R8I: 0x8231,\n R8UI: 0x8232,\n R16I: 0x8233,\n R16UI: 0x8234,\n R32I: 0x8235,\n R32UI: 0x8236,\n RG8I: 0x8237,\n RG8UI: 0x8238,\n RG16I: 0x8239,\n RG16UI: 0x823a,\n RG32I: 0x823b,\n RG32UI: 0x823c,\n VERTEX_ARRAY_BINDING: 0x85b5,\n R8_SNORM: 0x8f94,\n RG8_SNORM: 0x8f95,\n RGB8_SNORM: 0x8f96,\n RGBA8_SNORM: 0x8f97,\n SIGNED_NORMALIZED: 0x8f9c,\n COPY_READ_BUFFER: 0x8f36,\n COPY_WRITE_BUFFER: 0x8f37,\n COPY_READ_BUFFER_BINDING: 0x8f36, // Same as COPY_READ_BUFFER\n COPY_WRITE_BUFFER_BINDING: 0x8f37, // Same as COPY_WRITE_BUFFER\n UNIFORM_BUFFER: 0x8a11,\n UNIFORM_BUFFER_BINDING: 0x8a28,\n UNIFORM_BUFFER_START: 0x8a29,\n UNIFORM_BUFFER_SIZE: 0x8a2a,\n MAX_VERTEX_UNIFORM_BLOCKS: 0x8a2b,\n MAX_FRAGMENT_UNIFORM_BLOCKS: 0x8a2d,\n MAX_COMBINED_UNIFORM_BLOCKS: 0x8a2e,\n MAX_UNIFORM_BUFFER_BINDINGS: 0x8a2f,\n MAX_UNIFORM_BLOCK_SIZE: 0x8a30,\n MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: 0x8a31,\n MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: 0x8a33,\n UNIFORM_BUFFER_OFFSET_ALIGNMENT: 0x8a34,\n ACTIVE_UNIFORM_BLOCKS: 0x8a36,\n UNIFORM_TYPE: 0x8a37,\n UNIFORM_SIZE: 0x8a38,\n UNIFORM_BLOCK_INDEX: 0x8a3a,\n UNIFORM_OFFSET: 0x8a3b,\n UNIFORM_ARRAY_STRIDE: 0x8a3c,\n UNIFORM_MATRIX_STRIDE: 0x8a3d,\n UNIFORM_IS_ROW_MAJOR: 0x8a3e,\n UNIFORM_BLOCK_BINDING: 0x8a3f,\n UNIFORM_BLOCK_DATA_SIZE: 0x8a40,\n UNIFORM_BLOCK_ACTIVE_UNIFORMS: 0x8a42,\n UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: 0x8a43,\n UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: 0x8a44,\n UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: 0x8a46,\n INVALID_INDEX: 0xffffffff,\n MAX_VERTEX_OUTPUT_COMPONENTS: 0x9122,\n MAX_FRAGMENT_INPUT_COMPONENTS: 0x9125,\n MAX_SERVER_WAIT_TIMEOUT: 0x9111,\n OBJECT_TYPE: 0x9112,\n SYNC_CONDITION: 0x9113,\n SYNC_STATUS: 0x9114,\n SYNC_FLAGS: 0x9115,\n SYNC_FENCE: 0x9116,\n SYNC_GPU_COMMANDS_COMPLETE: 0x9117,\n UNSIGNALED: 0x9118,\n SIGNALED: 0x9119,\n ALREADY_SIGNALED: 0x911a,\n TIMEOUT_EXPIRED: 0x911b,\n CONDITION_SATISFIED: 0x911c,\n WAIT_FAILED: 0x911d,\n SYNC_FLUSH_COMMANDS_BIT: 0x00000001,\n VERTEX_ATTRIB_ARRAY_DIVISOR: 0x88fe,\n ANY_SAMPLES_PASSED: 0x8c2f,\n ANY_SAMPLES_PASSED_CONSERVATIVE: 0x8d6a,\n SAMPLER_BINDING: 0x8919,\n RGB10_A2UI: 0x906f,\n INT_2_10_10_10_REV: 0x8d9f,\n TRANSFORM_FEEDBACK: 0x8e22,\n TRANSFORM_FEEDBACK_PAUSED: 0x8e23,\n TRANSFORM_FEEDBACK_ACTIVE: 0x8e24,\n TRANSFORM_FEEDBACK_BINDING: 0x8e25,\n COMPRESSED_R11_EAC: 0x9270,\n COMPRESSED_SIGNED_R11_EAC: 0x9271,\n COMPRESSED_RG11_EAC: 0x9272,\n COMPRESSED_SIGNED_RG11_EAC: 0x9273,\n COMPRESSED_RGB8_ETC2: 0x9274,\n COMPRESSED_SRGB8_ETC2: 0x9275,\n COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9276,\n COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9277,\n COMPRESSED_RGBA8_ETC2_EAC: 0x9278,\n COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9279,\n TEXTURE_IMMUTABLE_FORMAT: 0x912f,\n MAX_ELEMENT_INDEX: 0x8d6b,\n TEXTURE_IMMUTABLE_LEVELS: 0x82df,\n\n // Extensions\n MAX_TEXTURE_MAX_ANISOTROPY_EXT: 0x84ff,\n};\nexport default Object.freeze(WebGLConstants);\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\n\nconst viewerPositionWCScratch = new Cartesian3();\n\nfunction AutomaticUniform(options) {\n this._size = options.size;\n this._datatype = options.datatype;\n this.getValue = options.getValue;\n}\n\nconst datatypeToGlsl = {};\ndatatypeToGlsl[WebGLConstants.FLOAT] = \"float\";\ndatatypeToGlsl[WebGLConstants.FLOAT_VEC2] = \"vec2\";\ndatatypeToGlsl[WebGLConstants.FLOAT_VEC3] = \"vec3\";\ndatatypeToGlsl[WebGLConstants.FLOAT_VEC4] = \"vec4\";\ndatatypeToGlsl[WebGLConstants.INT] = \"int\";\ndatatypeToGlsl[WebGLConstants.INT_VEC2] = \"ivec2\";\ndatatypeToGlsl[WebGLConstants.INT_VEC3] = \"ivec3\";\ndatatypeToGlsl[WebGLConstants.INT_VEC4] = \"ivec4\";\ndatatypeToGlsl[WebGLConstants.BOOL] = \"bool\";\ndatatypeToGlsl[WebGLConstants.BOOL_VEC2] = \"bvec2\";\ndatatypeToGlsl[WebGLConstants.BOOL_VEC3] = \"bvec3\";\ndatatypeToGlsl[WebGLConstants.BOOL_VEC4] = \"bvec4\";\ndatatypeToGlsl[WebGLConstants.FLOAT_MAT2] = \"mat2\";\ndatatypeToGlsl[WebGLConstants.FLOAT_MAT3] = \"mat3\";\ndatatypeToGlsl[WebGLConstants.FLOAT_MAT4] = \"mat4\";\ndatatypeToGlsl[WebGLConstants.SAMPLER_2D] = \"sampler2D\";\ndatatypeToGlsl[WebGLConstants.SAMPLER_CUBE] = \"samplerCube\";\n\nAutomaticUniform.prototype.getDeclaration = function (name) {\n let declaration = `uniform ${datatypeToGlsl[this._datatype]} ${name}`;\n\n const size = this._size;\n if (size === 1) {\n declaration += \";\";\n } else {\n declaration += `[${size.toString()}];`;\n }\n\n return declaration;\n};\n\n/**\n * @private\n */\nconst AutomaticUniforms = {\n /**\n * An automatic GLSL uniform containing the viewport's x, y, width,\n * and height properties in an vec4's x, y, z,\n * and w components, respectively.\n *\n * @example\n * // GLSL declaration\n * uniform vec4 czm_viewport;\n *\n * // Scale the window coordinate components to [0, 1] by dividing\n * // by the viewport's width and height.\n * vec2 v = gl_FragCoord.xy / czm_viewport.zw;\n *\n * @see Context#getViewport\n */\n czm_viewport: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC4,\n getValue: function (uniformState) {\n return uniformState.viewportCartesian4;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 orthographic projection matrix that\n * transforms window coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *

\n * This transform is useful when a vertex shader inputs or manipulates window coordinates\n * as done by {@link BillboardCollection}.\n *

\n * Do not confuse {@link czm_viewportTransformation} with czm_viewportOrthographic.\n * The former transforms from normalized device coordinates to window coordinates; the later transforms\n * from window coordinates to clip coordinates, and is often used to assign to gl_Position.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_viewportOrthographic;\n *\n * // Example\n * gl_Position = czm_viewportOrthographic * vec4(windowPosition, 0.0, 1.0);\n *\n * @see UniformState#viewportOrthographic\n * @see czm_viewport\n * @see czm_viewportTransformation\n * @see BillboardCollection\n */\n czm_viewportOrthographic: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.viewportOrthographic;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 transformation matrix that\n * transforms normalized device coordinates to window coordinates. The context's\n * full viewport is used, and the depth range is assumed to be near = 0\n * and far = 1.\n *

\n * This transform is useful when there is a need to manipulate window coordinates\n * in a vertex shader as done by {@link BillboardCollection}. In many cases,\n * this matrix will not be used directly; instead, {@link czm_modelToWindowCoordinates}\n * will be used to transform directly from model to window coordinates.\n *

\n * Do not confuse czm_viewportTransformation with {@link czm_viewportOrthographic}.\n * The former transforms from normalized device coordinates to window coordinates; the later transforms\n * from window coordinates to clip coordinates, and is often used to assign to gl_Position.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_viewportTransformation;\n *\n * // Use czm_viewportTransformation as part of the\n * // transform from model to window coordinates.\n * vec4 q = czm_modelViewProjection * positionMC; // model to clip coordinates\n * q.xyz /= q.w; // clip to normalized device coordinates (ndc)\n * q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // ndc to window coordinates\n *\n * @see UniformState#viewportTransformation\n * @see czm_viewport\n * @see czm_viewportOrthographic\n * @see czm_modelToWindowCoordinates\n * @see BillboardCollection\n */\n czm_viewportTransformation: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.viewportTransformation;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the depth of the scene\n * after the globe pass and then updated after the 3D Tiles pass.\n * The depth is packed into an RGBA texture.\n *\n * @example\n * // GLSL declaration\n * uniform sampler2D czm_globeDepthTexture;\n *\n * // Get the depth at the current fragment\n * vec2 coords = gl_FragCoord.xy / czm_viewport.zw;\n * float depth = czm_unpackDepth(texture(czm_globeDepthTexture, coords));\n */\n czm_globeDepthTexture: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.SAMPLER_2D,\n getValue: function (uniformState) {\n return uniformState.globeDepthTexture;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model transformation matrix that\n * transforms model coordinates to world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_model;\n *\n * // Example\n * vec4 worldPosition = czm_model * modelPosition;\n *\n * @see UniformState#model\n * @see czm_inverseModel\n * @see czm_modelView\n * @see czm_modelViewProjection\n */\n czm_model: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.model;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model transformation matrix that\n * transforms world coordinates to model coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseModel;\n *\n * // Example\n * vec4 modelPosition = czm_inverseModel * worldPosition;\n *\n * @see UniformState#inverseModel\n * @see czm_model\n * @see czm_inverseModelView\n */\n czm_inverseModel: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseModel;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 view transformation matrix that\n * transforms world coordinates to eye coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_view;\n *\n * // Example\n * vec4 eyePosition = czm_view * worldPosition;\n *\n * @see UniformState#view\n * @see czm_viewRotation\n * @see czm_modelView\n * @see czm_viewProjection\n * @see czm_modelViewProjection\n * @see czm_inverseView\n */\n czm_view: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.view;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 view transformation matrix that\n * transforms 3D world coordinates to eye coordinates. In 3D mode, this is identical to\n * {@link czm_view}, but in 2D and Columbus View it represents the view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_view3D;\n *\n * // Example\n * vec4 eyePosition3D = czm_view3D * worldPosition3D;\n *\n * @see UniformState#view3D\n * @see czm_view\n */\n czm_view3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.view3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 view rotation matrix that\n * transforms vectors in world coordinates to eye coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_viewRotation;\n *\n * // Example\n * vec3 eyeVector = czm_viewRotation * worldVector;\n *\n * @see UniformState#viewRotation\n * @see czm_view\n * @see czm_inverseView\n * @see czm_inverseViewRotation\n */\n czm_viewRotation: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.viewRotation;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 view rotation matrix that\n * transforms vectors in 3D world coordinates to eye coordinates. In 3D mode, this is identical to\n * {@link czm_viewRotation}, but in 2D and Columbus View it represents the view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_viewRotation3D;\n *\n * // Example\n * vec3 eyeVector = czm_viewRotation3D * worldVector;\n *\n * @see UniformState#viewRotation3D\n * @see czm_viewRotation\n */\n czm_viewRotation3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.viewRotation3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 transformation matrix that\n * transforms from eye coordinates to world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseView;\n *\n * // Example\n * vec4 worldPosition = czm_inverseView * eyePosition;\n *\n * @see UniformState#inverseView\n * @see czm_view\n * @see czm_inverseNormal\n */\n czm_inverseView: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseView;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 transformation matrix that\n * transforms from 3D eye coordinates to world coordinates. In 3D mode, this is identical to\n * {@link czm_inverseView}, but in 2D and Columbus View it represents the inverse view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseView3D;\n *\n * // Example\n * vec4 worldPosition = czm_inverseView3D * eyePosition;\n *\n * @see UniformState#inverseView3D\n * @see czm_inverseView\n */\n czm_inverseView3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseView3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 rotation matrix that\n * transforms vectors from eye coordinates to world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_inverseViewRotation;\n *\n * // Example\n * vec4 worldVector = czm_inverseViewRotation * eyeVector;\n *\n * @see UniformState#inverseView\n * @see czm_view\n * @see czm_viewRotation\n * @see czm_inverseViewRotation\n */\n czm_inverseViewRotation: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.inverseViewRotation;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 rotation matrix that\n * transforms vectors from 3D eye coordinates to world coordinates. In 3D mode, this is identical to\n * {@link czm_inverseViewRotation}, but in 2D and Columbus View it represents the inverse view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_inverseViewRotation3D;\n *\n * // Example\n * vec4 worldVector = czm_inverseViewRotation3D * eyeVector;\n *\n * @see UniformState#inverseView3D\n * @see czm_inverseViewRotation\n */\n czm_inverseViewRotation3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.inverseViewRotation3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 projection transformation matrix that\n * transforms eye coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_projection;\n *\n * // Example\n * gl_Position = czm_projection * eyePosition;\n *\n * @see UniformState#projection\n * @see czm_viewProjection\n * @see czm_modelViewProjection\n * @see czm_infiniteProjection\n */\n czm_projection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.projection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 inverse projection transformation matrix that\n * transforms from clip coordinates to eye coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseProjection;\n *\n * // Example\n * vec4 eyePosition = czm_inverseProjection * clipPosition;\n *\n * @see UniformState#inverseProjection\n * @see czm_projection\n */\n czm_inverseProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 projection transformation matrix with the far plane at infinity,\n * that transforms eye coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output. An infinite far plane is used\n * in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles\n * are not clipped by the far plane.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_infiniteProjection;\n *\n * // Example\n * gl_Position = czm_infiniteProjection * eyePosition;\n *\n * @see UniformState#infiniteProjection\n * @see czm_projection\n * @see czm_modelViewInfiniteProjection\n */\n czm_infiniteProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.infiniteProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that\n * transforms model coordinates to eye coordinates.\n *

\n * Positions should be transformed to eye coordinates using czm_modelView and\n * normals should be transformed using {@link czm_normal}.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelView;\n *\n * // Example\n * vec4 eyePosition = czm_modelView * modelPosition;\n *\n * // The above is equivalent to, but more efficient than:\n * vec4 eyePosition = czm_view * czm_model * modelPosition;\n *\n * @see UniformState#modelView\n * @see czm_model\n * @see czm_view\n * @see czm_modelViewProjection\n * @see czm_normal\n */\n czm_modelView: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelView;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that\n * transforms 3D model coordinates to eye coordinates. In 3D mode, this is identical to\n * {@link czm_modelView}, but in 2D and Columbus View it represents the model-view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *

\n * Positions should be transformed to eye coordinates using czm_modelView3D and\n * normals should be transformed using {@link czm_normal3D}.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelView3D;\n *\n * // Example\n * vec4 eyePosition = czm_modelView3D * modelPosition;\n *\n * // The above is equivalent to, but more efficient than:\n * vec4 eyePosition = czm_view3D * czm_model * modelPosition;\n *\n * @see UniformState#modelView3D\n * @see czm_modelView\n */\n czm_modelView3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelView3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that\n * transforms model coordinates, relative to the eye, to eye coordinates. This is used\n * in conjunction with {@link czm_translateRelativeToEye}.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelViewRelativeToEye;\n *\n * // Example\n * attribute vec3 positionHigh;\n * attribute vec3 positionLow;\n *\n * void main()\n * {\n * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\n * gl_Position = czm_projection * (czm_modelViewRelativeToEye * p);\n * }\n *\n * @see czm_modelViewProjectionRelativeToEye\n * @see czm_translateRelativeToEye\n * @see EncodedCartesian3\n */\n czm_modelViewRelativeToEye: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelViewRelativeToEye;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 transformation matrix that\n * transforms from eye coordinates to model coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseModelView;\n *\n * // Example\n * vec4 modelPosition = czm_inverseModelView * eyePosition;\n *\n * @see UniformState#inverseModelView\n * @see czm_modelView\n */\n czm_inverseModelView: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseModelView;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 transformation matrix that\n * transforms from eye coordinates to 3D model coordinates. In 3D mode, this is identical to\n * {@link czm_inverseModelView}, but in 2D and Columbus View it represents the inverse model-view matrix\n * as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseModelView3D;\n *\n * // Example\n * vec4 modelPosition = czm_inverseModelView3D * eyePosition;\n *\n * @see UniformState#inverseModelView\n * @see czm_inverseModelView\n * @see czm_modelView3D\n */\n czm_inverseModelView3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseModelView3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that\n * transforms world coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_viewProjection;\n *\n * // Example\n * vec4 gl_Position = czm_viewProjection * czm_model * modelPosition;\n *\n * // The above is equivalent to, but more efficient than:\n * gl_Position = czm_projection * czm_view * czm_model * modelPosition;\n *\n * @see UniformState#viewProjection\n * @see czm_view\n * @see czm_projection\n * @see czm_modelViewProjection\n * @see czm_inverseViewProjection\n */\n czm_viewProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.viewProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that\n * transforms clip coordinates to world coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseViewProjection;\n *\n * // Example\n * vec4 worldPosition = czm_inverseViewProjection * clipPosition;\n *\n * @see UniformState#inverseViewProjection\n * @see czm_viewProjection\n */\n czm_inverseViewProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseViewProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that\n * transforms model coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelViewProjection;\n *\n * // Example\n * vec4 gl_Position = czm_modelViewProjection * modelPosition;\n *\n * // The above is equivalent to, but more efficient than:\n * gl_Position = czm_projection * czm_view * czm_model * modelPosition;\n *\n * @see UniformState#modelViewProjection\n * @see czm_model\n * @see czm_view\n * @see czm_projection\n * @see czm_modelView\n * @see czm_viewProjection\n * @see czm_modelViewInfiniteProjection\n * @see czm_inverseModelViewProjection\n */\n czm_modelViewProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelViewProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 inverse model-view-projection transformation matrix that\n * transforms clip coordinates to model coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_inverseModelViewProjection;\n *\n * // Example\n * vec4 modelPosition = czm_inverseModelViewProjection * clipPosition;\n *\n * @see UniformState#modelViewProjection\n * @see czm_modelViewProjection\n */\n czm_inverseModelViewProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.inverseModelViewProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that\n * transforms model coordinates, relative to the eye, to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output. This is used in\n * conjunction with {@link czm_translateRelativeToEye}.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelViewProjectionRelativeToEye;\n *\n * // Example\n * attribute vec3 positionHigh;\n * attribute vec3 positionLow;\n *\n * void main()\n * {\n * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\n * gl_Position = czm_modelViewProjectionRelativeToEye * p;\n * }\n *\n * @see czm_modelViewRelativeToEye\n * @see czm_translateRelativeToEye\n * @see EncodedCartesian3\n */\n czm_modelViewProjectionRelativeToEye: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelViewProjectionRelativeToEye;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that\n * transforms model coordinates to clip coordinates. Clip coordinates is the\n * coordinate system for a vertex shader's gl_Position output. The projection matrix places\n * the far plane at infinity. This is useful in algorithms like shadow volumes and GPU ray casting with\n * proxy geometry to ensure that triangles are not clipped by the far plane.\n *\n * @example\n * // GLSL declaration\n * uniform mat4 czm_modelViewInfiniteProjection;\n *\n * // Example\n * vec4 gl_Position = czm_modelViewInfiniteProjection * modelPosition;\n *\n * // The above is equivalent to, but more efficient than:\n * gl_Position = czm_infiniteProjection * czm_view * czm_model * modelPosition;\n *\n * @see UniformState#modelViewInfiniteProjection\n * @see czm_model\n * @see czm_view\n * @see czm_infiniteProjection\n * @see czm_modelViewProjection\n */\n czm_modelViewInfiniteProjection: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT4,\n getValue: function (uniformState) {\n return uniformState.modelViewInfiniteProjection;\n },\n }),\n\n /**\n * An automatic GLSL uniform that indicates if the current camera is orthographic in 3D.\n *\n * @see UniformState#orthographicIn3D\n */\n czm_orthographicIn3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.orthographicIn3D ? 1 : 0;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 normal transformation matrix that\n * transforms normal vectors in model coordinates to eye coordinates.\n *

\n * Positions should be transformed to eye coordinates using {@link czm_modelView} and\n * normals should be transformed using czm_normal.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_normal;\n *\n * // Example\n * vec3 eyeNormal = czm_normal * normal;\n *\n * @see UniformState#normal\n * @see czm_inverseNormal\n * @see czm_modelView\n */\n czm_normal: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.normal;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 normal transformation matrix that\n * transforms normal vectors in 3D model coordinates to eye coordinates.\n * In 3D mode, this is identical to\n * {@link czm_normal}, but in 2D and Columbus View it represents the normal transformation\n * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *

\n * Positions should be transformed to eye coordinates using {@link czm_modelView3D} and\n * normals should be transformed using czm_normal3D.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_normal3D;\n *\n * // Example\n * vec3 eyeNormal = czm_normal3D * normal;\n *\n * @see UniformState#normal3D\n * @see czm_normal\n */\n czm_normal3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.normal3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 normal transformation matrix that\n * transforms normal vectors in eye coordinates to model coordinates. This is\n * the opposite of the transform provided by {@link czm_normal}.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_inverseNormal;\n *\n * // Example\n * vec3 normalMC = czm_inverseNormal * normalEC;\n *\n * @see UniformState#inverseNormal\n * @see czm_normal\n * @see czm_modelView\n * @see czm_inverseView\n */\n czm_inverseNormal: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.inverseNormal;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 normal transformation matrix that\n * transforms normal vectors in eye coordinates to 3D model coordinates. This is\n * the opposite of the transform provided by {@link czm_normal}.\n * In 3D mode, this is identical to\n * {@link czm_inverseNormal}, but in 2D and Columbus View it represents the inverse normal transformation\n * matrix as if the camera were at an equivalent location in 3D mode. This is useful for lighting\n * 2D and Columbus View in the same way that 3D is lit.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_inverseNormal3D;\n *\n * // Example\n * vec3 normalMC = czm_inverseNormal3D * normalEC;\n *\n * @see UniformState#inverseNormal3D\n * @see czm_inverseNormal\n */\n czm_inverseNormal3D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.inverseNormal3D;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the height in meters of the\n * eye (camera) above or below the ellipsoid.\n *\n * @see UniformState#eyeHeight\n */\n czm_eyeHeight: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.eyeHeight;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing height (x) and height squared (y)\n * in meters of the eye (camera) above the 2D world plane. This uniform is only valid\n * when the {@link SceneMode} is SCENE2D.\n *\n * @see UniformState#eyeHeight2D\n */\n czm_eyeHeight2D: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC2,\n getValue: function (uniformState) {\n return uniformState.eyeHeight2D;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the near distance (x) and the far distance (y)\n * of the frustum defined by the camera. This is the largest possible frustum, not an individual\n * frustum used for multi-frustum rendering.\n *\n * @example\n * // GLSL declaration\n * uniform vec2 czm_entireFrustum;\n *\n * // Example\n * float frustumLength = czm_entireFrustum.y - czm_entireFrustum.x;\n *\n * @see UniformState#entireFrustum\n * @see czm_currentFrustum\n */\n czm_entireFrustum: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC2,\n getValue: function (uniformState) {\n return uniformState.entireFrustum;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the near distance (x) and the far distance (y)\n * of the frustum defined by the camera. This is the individual\n * frustum used for multi-frustum rendering.\n *\n * @example\n * // GLSL declaration\n * uniform vec2 czm_currentFrustum;\n *\n * // Example\n * float frustumLength = czm_currentFrustum.y - czm_currentFrustum.x;\n *\n * @see UniformState#currentFrustum\n * @see czm_entireFrustum\n */\n czm_currentFrustum: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC2,\n getValue: function (uniformState) {\n return uniformState.currentFrustum;\n },\n }),\n\n /**\n * The distances to the frustum planes. The top, bottom, left and right distances are\n * the x, y, z, and w components, respectively.\n */\n czm_frustumPlanes: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC4,\n getValue: function (uniformState) {\n return uniformState.frustumPlanes;\n },\n }),\n\n /**\n * Gets the far plane's distance from the near plane, plus 1.0.\n */\n czm_farDepthFromNearPlusOne: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.farDepthFromNearPlusOne;\n },\n }),\n\n /**\n * Gets the log2 of {@link AutomaticUniforms#czm_farDepthFromNearPlusOne}.\n */\n czm_log2FarDepthFromNearPlusOne: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.log2FarDepthFromNearPlusOne;\n },\n }),\n\n /**\n * Gets 1.0 divided by {@link AutomaticUniforms#czm_log2FarDepthFromNearPlusOne}.\n */\n czm_oneOverLog2FarDepthFromNearPlusOne: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.oneOverLog2FarDepthFromNearPlusOne;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the sun position in world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_sunPositionWC;\n *\n * @see UniformState#sunPositionWC\n * @see czm_sunPositionColumbusView\n * @see czm_sunDirectionWC\n */\n czm_sunPositionWC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.sunPositionWC;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the sun position in Columbus view world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_sunPositionColumbusView;\n *\n * @see UniformState#sunPositionColumbusView\n * @see czm_sunPositionWC\n */\n czm_sunPositionColumbusView: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.sunPositionColumbusView;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the normalized direction to the sun in eye coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_sunDirectionEC;\n *\n * // Example\n * float diffuse = max(dot(czm_sunDirectionEC, normalEC), 0.0);\n *\n * @see UniformState#sunDirectionEC\n * @see czm_moonDirectionEC\n * @see czm_sunDirectionWC\n */\n czm_sunDirectionEC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.sunDirectionEC;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the normalized direction to the sun in world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_sunDirectionWC;\n *\n * // Example\n * float diffuse = max(dot(czm_sunDirectionWC, normalWC), 0.0);\n *\n * @see UniformState#sunDirectionWC\n * @see czm_sunPositionWC\n * @see czm_sunDirectionEC\n */\n czm_sunDirectionWC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.sunDirectionWC;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the normalized direction to the moon in eye coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_moonDirectionEC;\n *\n * // Example\n * float diffuse = max(dot(czm_moonDirectionEC, normalEC), 0.0);\n *\n * @see UniformState#moonDirectionEC\n * @see czm_sunDirectionEC\n */\n czm_moonDirectionEC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.moonDirectionEC;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the normalized direction to the scene's light source in eye coordinates.\n * This is commonly used for directional lighting computations.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_lightDirectionEC;\n *\n * // Example\n * float diffuse = max(dot(czm_lightDirectionEC, normalEC), 0.0);\n *\n * @see UniformState#lightDirectionEC\n * @see czm_lightDirectionWC\n */\n czm_lightDirectionEC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.lightDirectionEC;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the normalized direction to the scene's light source in world coordinates.\n * This is commonly used for directional lighting computations.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_lightDirectionWC;\n *\n * // Example\n * float diffuse = max(dot(czm_lightDirectionWC, normalWC), 0.0);\n *\n * @see UniformState#lightDirectionWC\n * @see czm_lightDirectionEC\n */\n czm_lightDirectionWC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.lightDirectionWC;\n },\n }),\n\n /**\n * An automatic GLSL uniform that represents the color of light emitted by the scene's light source. This\n * is equivalent to the light color multiplied by the light intensity limited to a maximum luminance of 1.0\n * suitable for non-HDR lighting.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_lightColor;\n *\n * // Example\n * vec3 diffuseColor = czm_lightColor * max(dot(czm_lightDirectionWC, normalWC), 0.0);\n *\n * @see UniformState#lightColor\n * @see czm_lightColorHdr\n */\n czm_lightColor: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.lightColor;\n },\n }),\n\n /**\n * An automatic GLSL uniform that represents the high dynamic range color of light emitted by the scene's light\n * source. This is equivalent to the light color multiplied by the light intensity suitable for HDR lighting.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_lightColorHdr;\n *\n * // Example\n * vec3 diffuseColor = czm_lightColorHdr * max(dot(czm_lightDirectionWC, normalWC), 0.0);\n *\n * @see UniformState#lightColorHdr\n * @see czm_lightColor\n */\n czm_lightColorHdr: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.lightColorHdr;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the high bits of the camera position in model\n * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering\n * as described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_encodedCameraPositionMCHigh;\n *\n * @see czm_encodedCameraPositionMCLow\n * @see czm_modelViewRelativeToEye\n * @see czm_modelViewProjectionRelativeToEye\n */\n czm_encodedCameraPositionMCHigh: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.encodedCameraPositionMCHigh;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the low bits of the camera position in model\n * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering\n * as described in {@linkhttp://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_encodedCameraPositionMCLow;\n *\n * @see czm_encodedCameraPositionMCHigh\n * @see czm_modelViewRelativeToEye\n * @see czm_modelViewProjectionRelativeToEye\n */\n czm_encodedCameraPositionMCLow: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.encodedCameraPositionMCLow;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the position of the viewer (camera) in world coordinates.\n *\n * @example\n * // GLSL declaration\n * uniform vec3 czm_viewerPositionWC;\n */\n czm_viewerPositionWC: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return Matrix4.getTranslation(\n uniformState.inverseView,\n viewerPositionWCScratch\n );\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the frame number. This uniform is automatically incremented\n * every frame.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_frameNumber;\n */\n czm_frameNumber: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.frameState.frameNumber;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the current morph transition time between\n * 2D/Columbus View and 3D, with 0.0 being 2D or Columbus View and 1.0 being 3D.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_morphTime;\n *\n * // Example\n * vec4 p = czm_columbusViewMorph(position2D, position3D, czm_morphTime);\n */\n czm_morphTime: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.frameState.morphTime;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the current {@link SceneMode}, expressed\n * as a float.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_sceneMode;\n *\n * // Example\n * if (czm_sceneMode == czm_sceneMode2D)\n * {\n * eyeHeightSq = czm_eyeHeight2D.y;\n * }\n *\n * @see czm_sceneMode2D\n * @see czm_sceneModeColumbusView\n * @see czm_sceneMode3D\n * @see czm_sceneModeMorphing\n */\n czm_sceneMode: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.frameState.mode;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the current rendering pass.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_pass;\n *\n * // Example\n * if ((czm_pass == czm_passTranslucent) && isOpaque())\n * {\n * gl_Position *= 0.0; // Cull opaque geometry in the translucent pass\n * }\n */\n czm_pass: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.pass;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the current scene background color.\n *\n * @example\n * // GLSL declaration\n * uniform vec4 czm_backgroundColor;\n *\n * // Example: If the given color's RGB matches the background color, invert it.\n * vec4 adjustColorForContrast(vec4 color)\n * {\n * if (czm_backgroundColor.rgb == color.rgb)\n * {\n * color.rgb = vec3(1.0) - color.rgb;\n * }\n *\n * return color;\n * }\n */\n czm_backgroundColor: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC4,\n getValue: function (uniformState) {\n return uniformState.backgroundColor;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the BRDF look up texture used for image-based lighting computations.\n *\n * @example\n * // GLSL declaration\n * uniform sampler2D czm_brdfLut;\n *\n * // Example: For a given roughness and NdotV value, find the material's BRDF information in the red and green channels\n * float roughness = 0.5;\n * float NdotV = dot(normal, view);\n * vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, 1.0 - roughness)).rg;\n */\n czm_brdfLut: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.SAMPLER_2D,\n getValue: function (uniformState) {\n return uniformState.brdfLut;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the environment map used within the scene.\n *\n * @example\n * // GLSL declaration\n * uniform samplerCube czm_environmentMap;\n *\n * // Example: Create a perfect reflection of the environment map on a model\n * float reflected = reflect(view, normal);\n * vec4 reflectedColor = texture(czm_environmentMap, reflected);\n */\n czm_environmentMap: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.SAMPLER_CUBE,\n getValue: function (uniformState) {\n return uniformState.environmentMap;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the specular environment map atlas used within the scene.\n *\n * @example\n * // GLSL declaration\n * uniform sampler2D czm_specularEnvironmentMaps;\n */\n czm_specularEnvironmentMaps: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.SAMPLER_2D,\n getValue: function (uniformState) {\n return uniformState.specularEnvironmentMaps;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the size of the specular environment map atlas used within the scene.\n *\n * @example\n * // GLSL declaration\n * uniform vec2 czm_specularEnvironmentMapSize;\n */\n czm_specularEnvironmentMapSize: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC2,\n getValue: function (uniformState) {\n return uniformState.specularEnvironmentMapsDimensions;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the maximum level-of-detail of the specular environment map atlas used within the scene.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_specularEnvironmentMapsMaximumLOD;\n */\n czm_specularEnvironmentMapsMaximumLOD: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.specularEnvironmentMapsMaximumLOD;\n },\n }),\n\n /**\n * An automatic GLSL uniform containing the spherical harmonic coefficients used within the scene.\n *\n * @example\n * // GLSL declaration\n * uniform vec3[9] czm_sphericalHarmonicCoefficients;\n */\n czm_sphericalHarmonicCoefficients: new AutomaticUniform({\n size: 9,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.sphericalHarmonicCoefficients;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing a 3x3 rotation matrix that transforms\n * from True Equator Mean Equinox (TEME) axes to the pseudo-fixed axes at the current scene time.\n *\n * @example\n * // GLSL declaration\n * uniform mat3 czm_temeToPseudoFixed;\n *\n * // Example\n * vec3 pseudoFixed = czm_temeToPseudoFixed * teme;\n *\n * @see UniformState#temeToPseudoFixedMatrix\n * @see Transforms.computeTemeToPseudoFixedMatrix\n */\n czm_temeToPseudoFixed: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_MAT3,\n getValue: function (uniformState) {\n return uniformState.temeToPseudoFixedMatrix;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the ratio of canvas coordinate space to canvas pixel space.\n *\n * @example\n * uniform float czm_pixelRatio;\n */\n czm_pixelRatio: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.pixelRatio;\n },\n }),\n\n /**\n * An automatic GLSL uniform scalar used to mix a color with the fog color based on the distance to the camera.\n *\n * @see czm_fog\n */\n czm_fogDensity: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.fogDensity;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the splitter position to use when rendering with a splitter.\n * This will be in pixel coordinates relative to the canvas.\n *\n * @example\n * // GLSL declaration\n * uniform float czm_splitPosition;\n */\n czm_splitPosition: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.splitPosition;\n },\n }),\n\n /**\n * An automatic GLSL uniform scalar representing the geometric tolerance per meter\n */\n czm_geometricToleranceOverMeter: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.geometricToleranceOverMeter;\n },\n }),\n\n /**\n * An automatic GLSL uniform representing the distance from the camera at which to disable the depth test of billboards, labels and points\n * to, for example, prevent clipping against terrain. When set to zero, the depth test should always be applied. When less than zero,\n * the depth test should never be applied.\n */\n czm_minimumDisableDepthTestDistance: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.minimumDisableDepthTestDistance;\n },\n }),\n\n /**\n * An automatic GLSL uniform that will be the highlight color of unclassified 3D Tiles.\n */\n czm_invertClassificationColor: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC4,\n getValue: function (uniformState) {\n return uniformState.invertClassificationColor;\n },\n }),\n\n /**\n * An automatic GLSL uniform that is used for gamma correction.\n */\n czm_gamma: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT,\n getValue: function (uniformState) {\n return uniformState.gamma;\n },\n }),\n\n /**\n * An automatic GLSL uniform that stores the ellipsoid radii.\n */\n czm_ellipsoidRadii: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.ellipsoid.radii;\n },\n }),\n\n /**\n * An automatic GLSL uniform that stores the ellipsoid inverse radii.\n */\n czm_ellipsoidInverseRadii: new AutomaticUniform({\n size: 1,\n datatype: WebGLConstants.FLOAT_VEC3,\n getValue: function (uniformState) {\n return uniformState.ellipsoid.oneOverRadii;\n },\n }),\n};\nexport default AutomaticUniforms;\n", "/**\n * Creates a Globally unique identifier (GUID) string. A GUID is 128 bits long, and can guarantee uniqueness across space and time.\n *\n * @function\n *\n * @returns {string}\n *\n *\n * @example\n * this.guid = Cesium.createGuid();\n *\n * @see {@link http://www.ietf.org/rfc/rfc4122.txt|RFC 4122 A Universally Unique IDentifier (UUID) URN Namespace}\n */\nfunction createGuid() {\n // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n const r = (Math.random() * 16) | 0;\n const v = c === \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\nexport default createGuid;\n", "import defaultValue from \"./defaultValue.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\nfunction returnTrue() {\n return true;\n}\n\n/**\n * Destroys an object. Each of the object's functions, including functions in its prototype,\n * is replaced with a function that throws a {@link DeveloperError}, except for the object's\n * isDestroyed function, which is set to a function that returns true.\n * The object's properties are removed with delete.\n *

\n * This function is used by objects that hold native resources, e.g., WebGL resources, which\n * need to be explicitly released. Client code calls an object's destroy function,\n * which then releases the native resource and calls destroyObject to put itself\n * in a destroyed state.\n *\n * @function\n *\n * @param {object} object The object to destroy.\n * @param {string} [message] The message to include in the exception that is thrown if\n * a destroyed object's function is called.\n *\n *\n * @example\n * // How a texture would destroy itself.\n * this.destroy = function () {\n * _gl.deleteTexture(_texture);\n * return Cesium.destroyObject(this);\n * };\n *\n * @see DeveloperError\n */\nfunction destroyObject(object, message) {\n message = defaultValue(\n message,\n \"This object was destroyed, i.e., destroy() was called.\"\n );\n\n function throwOnDestroyed() {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(message);\n //>>includeEnd('debug');\n }\n\n for (const key in object) {\n if (typeof object[key] === \"function\") {\n object[key] = throwOnDestroyed;\n }\n }\n\n object.isDestroyed = returnTrue;\n\n return undefined;\n}\nexport default destroyObject;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport WebGLConstants from \"./WebGLConstants.js\";\n\n/**\n * Constants for WebGL index datatypes. These corresponds to the\n * type parameter of {@link http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawElements.xml|drawElements}.\n *\n * @enum {number}\n */\nconst IndexDatatype = {\n /**\n * 8-bit unsigned byte corresponding to UNSIGNED_BYTE and the type\n * of an element in Uint8Array.\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_BYTE: WebGLConstants.UNSIGNED_BYTE,\n\n /**\n * 16-bit unsigned short corresponding to UNSIGNED_SHORT and the type\n * of an element in Uint16Array.\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_SHORT: WebGLConstants.UNSIGNED_SHORT,\n\n /**\n * 32-bit unsigned int corresponding to UNSIGNED_INT and the type\n * of an element in Uint32Array.\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_INT: WebGLConstants.UNSIGNED_INT,\n};\n\n/**\n * Returns the size, in bytes, of the corresponding datatype.\n *\n * @param {IndexDatatype} indexDatatype The index datatype to get the size of.\n * @returns {number} The size in bytes.\n *\n * @example\n * // Returns 2\n * const size = Cesium.IndexDatatype.getSizeInBytes(Cesium.IndexDatatype.UNSIGNED_SHORT);\n */\nIndexDatatype.getSizeInBytes = function (indexDatatype) {\n switch (indexDatatype) {\n case IndexDatatype.UNSIGNED_BYTE:\n return Uint8Array.BYTES_PER_ELEMENT;\n case IndexDatatype.UNSIGNED_SHORT:\n return Uint16Array.BYTES_PER_ELEMENT;\n case IndexDatatype.UNSIGNED_INT:\n return Uint32Array.BYTES_PER_ELEMENT;\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"indexDatatype is required and must be a valid IndexDatatype constant.\"\n );\n //>>includeEnd('debug');\n};\n\n/**\n * Gets the datatype with a given size in bytes.\n *\n * @param {number} sizeInBytes The size of a single index in bytes.\n * @returns {IndexDatatype} The index datatype with the given size.\n */\nIndexDatatype.fromSizeInBytes = function (sizeInBytes) {\n switch (sizeInBytes) {\n case 2:\n return IndexDatatype.UNSIGNED_SHORT;\n case 4:\n return IndexDatatype.UNSIGNED_INT;\n case 1:\n return IndexDatatype.UNSIGNED_BYTE;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\n \"Size in bytes cannot be mapped to an IndexDatatype\"\n );\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Validates that the provided index datatype is a valid {@link IndexDatatype}.\n *\n * @param {IndexDatatype} indexDatatype The index datatype to validate.\n * @returns {boolean} true if the provided index datatype is a valid value; otherwise, false.\n *\n * @example\n * if (!Cesium.IndexDatatype.validate(indexDatatype)) {\n * throw new Cesium.DeveloperError('indexDatatype must be a valid value.');\n * }\n */\nIndexDatatype.validate = function (indexDatatype) {\n return (\n defined(indexDatatype) &&\n (indexDatatype === IndexDatatype.UNSIGNED_BYTE ||\n indexDatatype === IndexDatatype.UNSIGNED_SHORT ||\n indexDatatype === IndexDatatype.UNSIGNED_INT)\n );\n};\n\n/**\n * Creates a typed array that will store indices, using either \n * or Uint32Array depending on the number of vertices.\n *\n * @param {number} numberOfVertices Number of vertices that the indices will reference.\n * @param {number|Array} indicesLengthOrArray Passed through to the typed array constructor.\n * @returns {Uint16Array|Uint32Array} A Uint16Array or Uint32Array constructed with indicesLengthOrArray.\n *\n * @example\n * this.indices = Cesium.IndexDatatype.createTypedArray(positions.length / 3, numberOfIndices);\n */\nIndexDatatype.createTypedArray = function (\n numberOfVertices,\n indicesLengthOrArray\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(numberOfVertices)) {\n throw new DeveloperError(\"numberOfVertices is required.\");\n }\n //>>includeEnd('debug');\n\n if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {\n return new Uint32Array(indicesLengthOrArray);\n }\n\n return new Uint16Array(indicesLengthOrArray);\n};\n\n/**\n * Creates a typed array from a source array buffer. The resulting typed array will store indices, using either \n * or Uint32Array depending on the number of vertices.\n *\n * @param {number} numberOfVertices Number of vertices that the indices will reference.\n * @param {ArrayBuffer} sourceArray Passed through to the typed array constructor.\n * @param {number} byteOffset Passed through to the typed array constructor.\n * @param {number} length Passed through to the typed array constructor.\n * @returns {Uint16Array|Uint32Array} A Uint16Array or Uint32Array constructed with sourceArray, byteOffset, and length.\n *\n */\nIndexDatatype.createTypedArrayFromArrayBuffer = function (\n numberOfVertices,\n sourceArray,\n byteOffset,\n length\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(numberOfVertices)) {\n throw new DeveloperError(\"numberOfVertices is required.\");\n }\n if (!defined(sourceArray)) {\n throw new DeveloperError(\"sourceArray is required.\");\n }\n if (!defined(byteOffset)) {\n throw new DeveloperError(\"byteOffset is required.\");\n }\n //>>includeEnd('debug');\n\n if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {\n return new Uint32Array(sourceArray, byteOffset, length);\n }\n\n return new Uint16Array(sourceArray, byteOffset, length);\n};\n\n/**\n * Gets the {@link IndexDatatype} for the provided TypedArray instance.\n *\n * @param {Uint8Array|Uint16Array|Uint32Array} array The typed array.\n * @returns {IndexDatatype} The IndexDatatype for the provided array, or undefined if the array is not a Uint8Array, Uint16Array, or Uint32Array.\n */\nIndexDatatype.fromTypedArray = function (array) {\n if (array instanceof Uint8Array) {\n return IndexDatatype.UNSIGNED_BYTE;\n }\n if (array instanceof Uint16Array) {\n return IndexDatatype.UNSIGNED_SHORT;\n }\n if (array instanceof Uint32Array) {\n return IndexDatatype.UNSIGNED_INT;\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"array must be a Uint8Array, Uint16Array, or Uint32Array.\"\n );\n //>>includeEnd('debug');\n};\n\nexport default Object.freeze(IndexDatatype);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * @private\n */\nconst BufferUsage = {\n STREAM_DRAW: WebGLConstants.STREAM_DRAW,\n STATIC_DRAW: WebGLConstants.STATIC_DRAW,\n DYNAMIC_DRAW: WebGLConstants.DYNAMIC_DRAW,\n\n validate: function (bufferUsage) {\n return (\n bufferUsage === BufferUsage.STREAM_DRAW ||\n bufferUsage === BufferUsage.STATIC_DRAW ||\n bufferUsage === BufferUsage.DYNAMIC_DRAW\n );\n },\n};\nexport default Object.freeze(BufferUsage);\n", "import Check from \"../Core/Check.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\nimport BufferUsage from \"./BufferUsage.js\";\n\n/**\n * @private\n */\nfunction Buffer(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n\n if (!defined(options.typedArray) && !defined(options.sizeInBytes)) {\n throw new DeveloperError(\n \"Either options.sizeInBytes or options.typedArray is required.\"\n );\n }\n\n if (defined(options.typedArray) && defined(options.sizeInBytes)) {\n throw new DeveloperError(\n \"Cannot pass in both options.sizeInBytes and options.typedArray.\"\n );\n }\n\n if (defined(options.typedArray)) {\n Check.typeOf.object(\"options.typedArray\", options.typedArray);\n Check.typeOf.number(\n \"options.typedArray.byteLength\",\n options.typedArray.byteLength\n );\n }\n\n if (!BufferUsage.validate(options.usage)) {\n throw new DeveloperError(\"usage is invalid.\");\n }\n //>>includeEnd('debug');\n\n const gl = options.context._gl;\n const bufferTarget = options.bufferTarget;\n const typedArray = options.typedArray;\n let sizeInBytes = options.sizeInBytes;\n const usage = options.usage;\n const hasArray = defined(typedArray);\n\n if (hasArray) {\n sizeInBytes = typedArray.byteLength;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"sizeInBytes\", sizeInBytes, 0);\n //>>includeEnd('debug');\n\n const buffer = gl.createBuffer();\n gl.bindBuffer(bufferTarget, buffer);\n gl.bufferData(bufferTarget, hasArray ? typedArray : sizeInBytes, usage);\n gl.bindBuffer(bufferTarget, null);\n\n this._id = createGuid();\n this._gl = gl;\n this._webgl2 = options.context._webgl2;\n this._bufferTarget = bufferTarget;\n this._sizeInBytes = sizeInBytes;\n this._usage = usage;\n this._buffer = buffer;\n this.vertexArrayDestroyable = true;\n}\n\n/**\n * Creates a vertex buffer, which contains untyped vertex data in GPU-controlled memory.\n *

\n * A vertex array defines the actual makeup of a vertex, e.g., positions, normals, texture coordinates,\n * etc., by interpreting the raw data in one or more vertex buffers.\n *\n * @param {object} options An object containing the following properties:\n * @param {Context} options.context The context in which to create the buffer\n * @param {ArrayBufferView} [options.typedArray] A typed array containing the data to copy to the buffer.\n * @param {number} [options.sizeInBytes] A Number defining the size of the buffer in bytes. Required if options.typedArray is not given.\n * @param {BufferUsage} options.usage Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See {@link BufferUsage}.\n * @returns {VertexBuffer} The vertex buffer, ready to be attached to a vertex array.\n *\n * @exception {DeveloperError} Must specify either or , but not both.\n * @exception {DeveloperError} The buffer size must be greater than zero.\n * @exception {DeveloperError} Invalid usage.\n *\n *\n * @example\n * // Example 1. Create a dynamic vertex buffer 16 bytes in size.\n * const buffer = Buffer.createVertexBuffer({\n * context : context,\n * sizeInBytes : 16,\n * usage : BufferUsage.DYNAMIC_DRAW\n * });\n *\n * @example\n * // Example 2. Create a dynamic vertex buffer from three floating-point values.\n * // The data copied to the vertex buffer is considered raw bytes until it is\n * // interpreted as vertices using a vertex array.\n * const positionBuffer = buffer.createVertexBuffer({\n * context : context,\n * typedArray : new Float32Array([0, 0, 0]),\n * usage : BufferUsage.STATIC_DRAW\n * });\n *\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenBuffer.xml|glGenBuffer}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindBuffer.xml|glBindBuffer} with ARRAY_BUFFER\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml|glBufferData} with ARRAY_BUFFER\n */\nBuffer.createVertexBuffer = function (options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n return new Buffer({\n context: options.context,\n bufferTarget: WebGLConstants.ARRAY_BUFFER,\n typedArray: options.typedArray,\n sizeInBytes: options.sizeInBytes,\n usage: options.usage,\n });\n};\n\n/**\n * Creates an index buffer, which contains typed indices in GPU-controlled memory.\n *

\n * An index buffer can be attached to a vertex array to select vertices for rendering.\n * Context.draw can render using the entire index buffer or a subset\n * of the index buffer defined by an offset and count.\n *\n * @param {object} options An object containing the following properties:\n * @param {Context} options.context The context in which to create the buffer\n * @param {ArrayBufferView} [options.typedArray] A typed array containing the data to copy to the buffer.\n * @param {number} [options.sizeInBytes] A Number defining the size of the buffer in bytes. Required if options.typedArray is not given.\n * @param {BufferUsage} options.usage Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See {@link BufferUsage}.\n * @param {IndexDatatype} options.indexDatatype The datatype of indices in the buffer.\n * @returns {IndexBuffer} The index buffer, ready to be attached to a vertex array.\n *\n * @exception {DeveloperError} Must specify either or , but not both.\n * @exception {DeveloperError} IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.\n * @exception {DeveloperError} The size in bytes must be greater than zero.\n * @exception {DeveloperError} Invalid usage.\n * @exception {DeveloperError} Invalid indexDatatype.\n *\n *\n * @example\n * // Example 1. Create a stream index buffer of unsigned shorts that is\n * // 16 bytes in size.\n * const buffer = Buffer.createIndexBuffer({\n * context : context,\n * sizeInBytes : 16,\n * usage : BufferUsage.STREAM_DRAW,\n * indexDatatype : IndexDatatype.UNSIGNED_SHORT\n * });\n *\n * @example\n * // Example 2. Create a static index buffer containing three unsigned shorts.\n * const buffer = Buffer.createIndexBuffer({\n * context : context,\n * typedArray : new Uint16Array([0, 1, 2]),\n * usage : BufferUsage.STATIC_DRAW,\n * indexDatatype : IndexDatatype.UNSIGNED_SHORT\n * });\n *\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenBuffer.xml|glGenBuffer}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindBuffer.xml|glBindBuffer} with ELEMENT_ARRAY_BUFFER\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBufferData.xml|glBufferData} with ELEMENT_ARRAY_BUFFER\n */\nBuffer.createIndexBuffer = function (options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n\n if (!IndexDatatype.validate(options.indexDatatype)) {\n throw new DeveloperError(\"Invalid indexDatatype.\");\n }\n\n if (\n options.indexDatatype === IndexDatatype.UNSIGNED_INT &&\n !options.context.elementIndexUint\n ) {\n throw new DeveloperError(\n \"IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.\"\n );\n }\n //>>includeEnd('debug');\n\n const context = options.context;\n const indexDatatype = options.indexDatatype;\n\n const bytesPerIndex = IndexDatatype.getSizeInBytes(indexDatatype);\n const buffer = new Buffer({\n context: context,\n bufferTarget: WebGLConstants.ELEMENT_ARRAY_BUFFER,\n typedArray: options.typedArray,\n sizeInBytes: options.sizeInBytes,\n usage: options.usage,\n });\n\n const numberOfIndices = buffer.sizeInBytes / bytesPerIndex;\n\n Object.defineProperties(buffer, {\n indexDatatype: {\n get: function () {\n return indexDatatype;\n },\n },\n bytesPerIndex: {\n get: function () {\n return bytesPerIndex;\n },\n },\n numberOfIndices: {\n get: function () {\n return numberOfIndices;\n },\n },\n });\n\n return buffer;\n};\n\nObject.defineProperties(Buffer.prototype, {\n sizeInBytes: {\n get: function () {\n return this._sizeInBytes;\n },\n },\n\n usage: {\n get: function () {\n return this._usage;\n },\n },\n});\n\nBuffer.prototype._getBuffer = function () {\n return this._buffer;\n};\n\nBuffer.prototype.copyFromArrayView = function (arrayView, offsetInBytes) {\n offsetInBytes = defaultValue(offsetInBytes, 0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"arrayView\", arrayView);\n Check.typeOf.number.lessThanOrEquals(\n \"offsetInBytes + arrayView.byteLength\",\n offsetInBytes + arrayView.byteLength,\n this._sizeInBytes\n );\n //>>includeEnd('debug');\n\n const gl = this._gl;\n const target = this._bufferTarget;\n gl.bindBuffer(target, this._buffer);\n gl.bufferSubData(target, offsetInBytes, arrayView);\n gl.bindBuffer(target, null);\n};\n\nBuffer.prototype.copyFromBuffer = function (\n readBuffer,\n readOffset,\n writeOffset,\n sizeInBytes\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!this._webgl2) {\n throw new DeveloperError(\"A WebGL 2 context is required.\");\n }\n if (!defined(readBuffer)) {\n throw new DeveloperError(\"readBuffer must be defined.\");\n }\n if (!defined(sizeInBytes) || sizeInBytes <= 0) {\n throw new DeveloperError(\n \"sizeInBytes must be defined and be greater than zero.\"\n );\n }\n if (\n !defined(readOffset) ||\n readOffset < 0 ||\n readOffset + sizeInBytes > readBuffer._sizeInBytes\n ) {\n throw new DeveloperError(\n \"readOffset must be greater than or equal to zero and readOffset + sizeInBytes must be less than of equal to readBuffer.sizeInBytes.\"\n );\n }\n if (\n !defined(writeOffset) ||\n writeOffset < 0 ||\n writeOffset + sizeInBytes > this._sizeInBytes\n ) {\n throw new DeveloperError(\n \"writeOffset must be greater than or equal to zero and writeOffset + sizeInBytes must be less than of equal to this.sizeInBytes.\"\n );\n }\n if (\n this._buffer === readBuffer._buffer &&\n ((writeOffset >= readOffset && writeOffset < readOffset + sizeInBytes) ||\n (readOffset > writeOffset && readOffset < writeOffset + sizeInBytes))\n ) {\n throw new DeveloperError(\n \"When readBuffer is equal to this, the ranges [readOffset + sizeInBytes) and [writeOffset, writeOffset + sizeInBytes) must not overlap.\"\n );\n }\n if (\n (this._bufferTarget === WebGLConstants.ELEMENT_ARRAY_BUFFER &&\n readBuffer._bufferTarget !== WebGLConstants.ELEMENT_ARRAY_BUFFER) ||\n (this._bufferTarget !== WebGLConstants.ELEMENT_ARRAY_BUFFER &&\n readBuffer._bufferTarget === WebGLConstants.ELEMENT_ARRAY_BUFFER)\n ) {\n throw new DeveloperError(\n \"Can not copy an index buffer into another buffer type.\"\n );\n }\n //>>includeEnd('debug');\n\n const readTarget = WebGLConstants.COPY_READ_BUFFER;\n const writeTarget = WebGLConstants.COPY_WRITE_BUFFER;\n\n const gl = this._gl;\n gl.bindBuffer(writeTarget, this._buffer);\n gl.bindBuffer(readTarget, readBuffer._buffer);\n gl.copyBufferSubData(\n readTarget,\n writeTarget,\n readOffset,\n writeOffset,\n sizeInBytes\n );\n gl.bindBuffer(writeTarget, null);\n gl.bindBuffer(readTarget, null);\n};\n\nBuffer.prototype.getBufferData = function (\n arrayView,\n sourceOffset,\n destinationOffset,\n length\n) {\n sourceOffset = defaultValue(sourceOffset, 0);\n destinationOffset = defaultValue(destinationOffset, 0);\n\n //>>includeStart('debug', pragmas.debug);\n if (!this._webgl2) {\n throw new DeveloperError(\"A WebGL 2 context is required.\");\n }\n if (!defined(arrayView)) {\n throw new DeveloperError(\"arrayView is required.\");\n }\n\n let copyLength;\n let elementSize;\n let arrayLength = arrayView.byteLength;\n if (!defined(length)) {\n if (defined(arrayLength)) {\n copyLength = arrayLength - destinationOffset;\n elementSize = 1;\n } else {\n arrayLength = arrayView.length;\n copyLength = arrayLength - destinationOffset;\n elementSize = arrayView.BYTES_PER_ELEMENT;\n }\n } else {\n copyLength = length;\n if (defined(arrayLength)) {\n elementSize = 1;\n } else {\n arrayLength = arrayView.length;\n elementSize = arrayView.BYTES_PER_ELEMENT;\n }\n }\n\n if (destinationOffset < 0 || destinationOffset > arrayLength) {\n throw new DeveloperError(\n \"destinationOffset must be greater than zero and less than the arrayView length.\"\n );\n }\n if (destinationOffset + copyLength > arrayLength) {\n throw new DeveloperError(\n \"destinationOffset + length must be less than or equal to the arrayViewLength.\"\n );\n }\n if (sourceOffset < 0 || sourceOffset > this._sizeInBytes) {\n throw new DeveloperError(\n \"sourceOffset must be greater than zero and less than the buffers size.\"\n );\n }\n if (sourceOffset + copyLength * elementSize > this._sizeInBytes) {\n throw new DeveloperError(\n \"sourceOffset + length must be less than the buffers size.\"\n );\n }\n //>>includeEnd('debug');\n\n const gl = this._gl;\n const target = WebGLConstants.COPY_READ_BUFFER;\n gl.bindBuffer(target, this._buffer);\n gl.getBufferSubData(\n target,\n sourceOffset,\n arrayView,\n destinationOffset,\n length\n );\n gl.bindBuffer(target, null);\n};\n\nBuffer.prototype.isDestroyed = function () {\n return false;\n};\n\nBuffer.prototype.destroy = function () {\n this._gl.deleteBuffer(this._buffer);\n return destroyObject(this);\n};\nexport default Buffer;\n", "import defined from \"./defined.js\";\n\nlet _supportsFullscreen;\nconst _names = {\n requestFullscreen: undefined,\n exitFullscreen: undefined,\n fullscreenEnabled: undefined,\n fullscreenElement: undefined,\n fullscreenchange: undefined,\n fullscreenerror: undefined,\n};\n\n/**\n * Browser-independent functions for working with the standard fullscreen API.\n *\n * @namespace Fullscreen\n *\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\n */\nconst Fullscreen = {};\n\nObject.defineProperties(Fullscreen, {\n /**\n * The element that is currently fullscreen, if any. To simply check if the\n * browser is in fullscreen mode or not, use {@link Fullscreen#fullscreen}.\n * @memberof Fullscreen\n * @type {object}\n * @readonly\n */\n element: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return document[_names.fullscreenElement];\n },\n },\n\n /**\n * The name of the event on the document that is fired when fullscreen is\n * entered or exited. This event name is intended for use with addEventListener.\n * In your event handler, to determine if the browser is in fullscreen mode or not,\n * use {@link Fullscreen#fullscreen}.\n * @memberof Fullscreen\n * @type {string}\n * @readonly\n */\n changeEventName: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return _names.fullscreenchange;\n },\n },\n\n /**\n * The name of the event that is fired when a fullscreen error\n * occurs. This event name is intended for use with addEventListener.\n * @memberof Fullscreen\n * @type {string}\n * @readonly\n */\n errorEventName: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return _names.fullscreenerror;\n },\n },\n\n /**\n * Determine whether the browser will allow an element to be made fullscreen, or not.\n * For example, by default, iframes cannot go fullscreen unless the containing page\n * adds an \"allowfullscreen\" attribute (or prefixed equivalent).\n * @memberof Fullscreen\n * @type {boolean}\n * @readonly\n */\n enabled: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return document[_names.fullscreenEnabled];\n },\n },\n\n /**\n * Determines if the browser is currently in fullscreen mode.\n * @memberof Fullscreen\n * @type {boolean}\n * @readonly\n */\n fullscreen: {\n get: function () {\n if (!Fullscreen.supportsFullscreen()) {\n return undefined;\n }\n\n return Fullscreen.element !== null;\n },\n },\n});\n\n/**\n * Detects whether the browser supports the standard fullscreen API.\n *\n * @returns {boolean} true if the browser supports the standard fullscreen API,\n * false otherwise.\n */\nFullscreen.supportsFullscreen = function () {\n if (defined(_supportsFullscreen)) {\n return _supportsFullscreen;\n }\n\n _supportsFullscreen = false;\n\n const body = document.body;\n if (typeof body.requestFullscreen === \"function\") {\n // go with the unprefixed, standard set of names\n _names.requestFullscreen = \"requestFullscreen\";\n _names.exitFullscreen = \"exitFullscreen\";\n _names.fullscreenEnabled = \"fullscreenEnabled\";\n _names.fullscreenElement = \"fullscreenElement\";\n _names.fullscreenchange = \"fullscreenchange\";\n _names.fullscreenerror = \"fullscreenerror\";\n _supportsFullscreen = true;\n return _supportsFullscreen;\n }\n\n //check for the correct combination of prefix plus the various names that browsers use\n const prefixes = [\"webkit\", \"moz\", \"o\", \"ms\", \"khtml\"];\n let name;\n for (let i = 0, len = prefixes.length; i < len; ++i) {\n const prefix = prefixes[i];\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}RequestFullscreen`;\n if (typeof body[name] === \"function\") {\n _names.requestFullscreen = name;\n _supportsFullscreen = true;\n } else {\n name = `${prefix}RequestFullScreen`;\n if (typeof body[name] === \"function\") {\n _names.requestFullscreen = name;\n _supportsFullscreen = true;\n }\n }\n\n // disagreement about whether it's \"exit\" as per spec, or \"cancel\"\n name = `${prefix}ExitFullscreen`;\n if (typeof document[name] === \"function\") {\n _names.exitFullscreen = name;\n } else {\n name = `${prefix}CancelFullScreen`;\n if (typeof document[name] === \"function\") {\n _names.exitFullscreen = name;\n }\n }\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}FullscreenEnabled`;\n if (document[name] !== undefined) {\n _names.fullscreenEnabled = name;\n } else {\n name = `${prefix}FullScreenEnabled`;\n if (document[name] !== undefined) {\n _names.fullscreenEnabled = name;\n }\n }\n\n // casing of Fullscreen differs across browsers\n name = `${prefix}FullscreenElement`;\n if (document[name] !== undefined) {\n _names.fullscreenElement = name;\n } else {\n name = `${prefix}FullScreenElement`;\n if (document[name] !== undefined) {\n _names.fullscreenElement = name;\n }\n }\n\n // thankfully, event names are all lowercase per spec\n name = `${prefix}fullscreenchange`;\n // event names do not have 'on' in the front, but the property on the document does\n if (document[`on${name}`] !== undefined) {\n //except on IE\n if (prefix === \"ms\") {\n name = \"MSFullscreenChange\";\n }\n _names.fullscreenchange = name;\n }\n\n name = `${prefix}fullscreenerror`;\n if (document[`on${name}`] !== undefined) {\n //except on IE\n if (prefix === \"ms\") {\n name = \"MSFullscreenError\";\n }\n _names.fullscreenerror = name;\n }\n }\n\n return _supportsFullscreen;\n};\n\n/**\n * Asynchronously requests the browser to enter fullscreen mode on the given element.\n * If fullscreen mode is not supported by the browser, does nothing.\n *\n * @param {object} element The HTML element which will be placed into fullscreen mode.\n * @param {object} [vrDevice] The HMDVRDevice device.\n *\n * @example\n * // Put the entire page into fullscreen.\n * Cesium.Fullscreen.requestFullscreen(document.body)\n *\n * // Place only the Cesium canvas into fullscreen.\n * Cesium.Fullscreen.requestFullscreen(scene.canvas)\n */\nFullscreen.requestFullscreen = function (element, vrDevice) {\n if (!Fullscreen.supportsFullscreen()) {\n return;\n }\n\n element[_names.requestFullscreen]({ vrDisplay: vrDevice });\n};\n\n/**\n * Asynchronously exits fullscreen mode. If the browser is not currently\n * in fullscreen, or if fullscreen mode is not supported by the browser, does nothing.\n */\nFullscreen.exitFullscreen = function () {\n if (!Fullscreen.supportsFullscreen()) {\n return;\n }\n\n document[_names.exitFullscreen]();\n};\n\n//For unit tests\nFullscreen._names = _names;\nexport default Fullscreen;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Fullscreen from \"./Fullscreen.js\";\n\nlet theNavigator;\nif (typeof navigator !== \"undefined\") {\n theNavigator = navigator;\n} else {\n theNavigator = {};\n}\n\nfunction extractVersion(versionString) {\n const parts = versionString.split(\".\");\n for (let i = 0, len = parts.length; i < len; ++i) {\n parts[i] = parseInt(parts[i], 10);\n }\n return parts;\n}\n\nlet isChromeResult;\nlet chromeVersionResult;\nfunction isChrome() {\n if (!defined(isChromeResult)) {\n isChromeResult = false;\n // Edge contains Chrome in the user agent too\n if (!isEdge()) {\n const fields = / Chrome\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isChromeResult = true;\n chromeVersionResult = extractVersion(fields[1]);\n }\n }\n }\n\n return isChromeResult;\n}\n\nfunction chromeVersion() {\n return isChrome() && chromeVersionResult;\n}\n\nlet isSafariResult;\nlet safariVersionResult;\nfunction isSafari() {\n if (!defined(isSafariResult)) {\n isSafariResult = false;\n\n // Chrome and Edge contain Safari in the user agent too\n if (\n !isChrome() &&\n !isEdge() &&\n / Safari\\/[\\.0-9]+/.test(theNavigator.userAgent)\n ) {\n const fields = / Version\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isSafariResult = true;\n safariVersionResult = extractVersion(fields[1]);\n }\n }\n }\n\n return isSafariResult;\n}\n\nfunction safariVersion() {\n return isSafari() && safariVersionResult;\n}\n\nlet isWebkitResult;\nlet webkitVersionResult;\nfunction isWebkit() {\n if (!defined(isWebkitResult)) {\n isWebkitResult = false;\n\n const fields = / AppleWebKit\\/([\\.0-9]+)(\\+?)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isWebkitResult = true;\n webkitVersionResult = extractVersion(fields[1]);\n webkitVersionResult.isNightly = !!fields[2];\n }\n }\n\n return isWebkitResult;\n}\n\nfunction webkitVersion() {\n return isWebkit() && webkitVersionResult;\n}\n\nlet isInternetExplorerResult;\nlet internetExplorerVersionResult;\nfunction isInternetExplorer() {\n if (!defined(isInternetExplorerResult)) {\n isInternetExplorerResult = false;\n\n let fields;\n if (theNavigator.appName === \"Microsoft Internet Explorer\") {\n fields = /MSIE ([0-9]{1,}[\\.0-9]{0,})/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isInternetExplorerResult = true;\n internetExplorerVersionResult = extractVersion(fields[1]);\n }\n } else if (theNavigator.appName === \"Netscape\") {\n fields = /Trident\\/.*rv:([0-9]{1,}[\\.0-9]{0,})/.exec(\n theNavigator.userAgent\n );\n if (fields !== null) {\n isInternetExplorerResult = true;\n internetExplorerVersionResult = extractVersion(fields[1]);\n }\n }\n }\n return isInternetExplorerResult;\n}\n\nfunction internetExplorerVersion() {\n return isInternetExplorer() && internetExplorerVersionResult;\n}\n\nlet isEdgeResult;\nlet edgeVersionResult;\nfunction isEdge() {\n if (!defined(isEdgeResult)) {\n isEdgeResult = false;\n const fields = / Edg\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isEdgeResult = true;\n edgeVersionResult = extractVersion(fields[1]);\n }\n }\n return isEdgeResult;\n}\n\nfunction edgeVersion() {\n return isEdge() && edgeVersionResult;\n}\n\nlet isFirefoxResult;\nlet firefoxVersionResult;\nfunction isFirefox() {\n if (!defined(isFirefoxResult)) {\n isFirefoxResult = false;\n\n const fields = /Firefox\\/([\\.0-9]+)/.exec(theNavigator.userAgent);\n if (fields !== null) {\n isFirefoxResult = true;\n firefoxVersionResult = extractVersion(fields[1]);\n }\n }\n return isFirefoxResult;\n}\n\nlet isWindowsResult;\nfunction isWindows() {\n if (!defined(isWindowsResult)) {\n isWindowsResult = /Windows/i.test(theNavigator.appVersion);\n }\n return isWindowsResult;\n}\n\nlet isIPadOrIOSResult;\nfunction isIPadOrIOS() {\n if (!defined(isIPadOrIOSResult)) {\n isIPadOrIOSResult =\n navigator.platform === \"iPhone\" ||\n navigator.platform === \"iPod\" ||\n navigator.platform === \"iPad\";\n }\n\n return isIPadOrIOSResult;\n}\n\nfunction firefoxVersion() {\n return isFirefox() && firefoxVersionResult;\n}\n\nlet hasPointerEvents;\nfunction supportsPointerEvents() {\n if (!defined(hasPointerEvents)) {\n //While navigator.pointerEnabled is deprecated in the W3C specification\n //we still need to use it if it exists in order to support browsers\n //that rely on it, such as the Windows WebBrowser control which defines\n //PointerEvent but sets navigator.pointerEnabled to false.\n\n //Firefox disabled because of https://github.com/CesiumGS/cesium/issues/6372\n hasPointerEvents =\n !isFirefox() &&\n typeof PointerEvent !== \"undefined\" &&\n (!defined(theNavigator.pointerEnabled) || theNavigator.pointerEnabled);\n }\n return hasPointerEvents;\n}\n\nlet imageRenderingValueResult;\nlet supportsImageRenderingPixelatedResult;\nfunction supportsImageRenderingPixelated() {\n if (!defined(supportsImageRenderingPixelatedResult)) {\n const canvas = document.createElement(\"canvas\");\n canvas.setAttribute(\n \"style\",\n \"image-rendering: -moz-crisp-edges;\" + \"image-rendering: pixelated;\"\n );\n //canvas.style.imageRendering will be undefined, null or an empty string on unsupported browsers.\n const tmp = canvas.style.imageRendering;\n supportsImageRenderingPixelatedResult = defined(tmp) && tmp !== \"\";\n if (supportsImageRenderingPixelatedResult) {\n imageRenderingValueResult = tmp;\n }\n }\n return supportsImageRenderingPixelatedResult;\n}\n\nfunction imageRenderingValue() {\n return supportsImageRenderingPixelated()\n ? imageRenderingValueResult\n : undefined;\n}\n\nfunction supportsWebP() {\n //>>includeStart('debug', pragmas.debug);\n if (!supportsWebP.initialized) {\n throw new DeveloperError(\n \"You must call FeatureDetection.supportsWebP.initialize and wait for the promise to resolve before calling FeatureDetection.supportsWebP\"\n );\n }\n //>>includeEnd('debug');\n return supportsWebP._result;\n}\nsupportsWebP._promise = undefined;\nsupportsWebP._result = undefined;\nsupportsWebP.initialize = function () {\n // From https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp\n if (defined(supportsWebP._promise)) {\n return supportsWebP._promise;\n }\n\n supportsWebP._promise = new Promise((resolve) => {\n const image = new Image();\n image.onload = function () {\n supportsWebP._result = image.width > 0 && image.height > 0;\n resolve(supportsWebP._result);\n };\n\n image.onerror = function () {\n supportsWebP._result = false;\n resolve(supportsWebP._result);\n };\n image.src =\n \"data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA\";\n });\n\n return supportsWebP._promise;\n};\nObject.defineProperties(supportsWebP, {\n initialized: {\n get: function () {\n return defined(supportsWebP._result);\n },\n },\n});\n\nconst typedArrayTypes = [];\nif (typeof ArrayBuffer !== \"undefined\") {\n typedArrayTypes.push(\n Int8Array,\n Uint8Array,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array\n );\n\n if (typeof Uint8ClampedArray !== \"undefined\") {\n typedArrayTypes.push(Uint8ClampedArray);\n }\n\n if (typeof Uint8ClampedArray !== \"undefined\") {\n typedArrayTypes.push(Uint8ClampedArray);\n }\n\n if (typeof BigInt64Array !== \"undefined\") {\n // eslint-disable-next-line no-undef\n typedArrayTypes.push(BigInt64Array);\n }\n\n if (typeof BigUint64Array !== \"undefined\") {\n // eslint-disable-next-line no-undef\n typedArrayTypes.push(BigUint64Array);\n }\n}\n\n/**\n * A set of functions to detect whether the current browser supports\n * various features.\n *\n * @namespace FeatureDetection\n */\nconst FeatureDetection = {\n isChrome: isChrome,\n chromeVersion: chromeVersion,\n isSafari: isSafari,\n safariVersion: safariVersion,\n isWebkit: isWebkit,\n webkitVersion: webkitVersion,\n isInternetExplorer: isInternetExplorer,\n internetExplorerVersion: internetExplorerVersion,\n isEdge: isEdge,\n edgeVersion: edgeVersion,\n isFirefox: isFirefox,\n firefoxVersion: firefoxVersion,\n isWindows: isWindows,\n isIPadOrIOS: isIPadOrIOS,\n hardwareConcurrency: defaultValue(theNavigator.hardwareConcurrency, 3),\n supportsPointerEvents: supportsPointerEvents,\n supportsImageRenderingPixelated: supportsImageRenderingPixelated,\n supportsWebP: supportsWebP,\n imageRenderingValue: imageRenderingValue,\n typedArrayTypes: typedArrayTypes,\n};\n\n/**\n * Detects whether the current browser supports Basis Universal textures and the web assembly modules needed to transcode them.\n *\n * @param {Scene} scene\n * @returns {boolean} true if the browser supports web assembly modules and the scene supports Basis Universal textures, false if not.\n */\nFeatureDetection.supportsBasis = function (scene) {\n return FeatureDetection.supportsWebAssembly() && scene.context.supportsBasis;\n};\n\n/**\n * Detects whether the current browser supports the full screen standard.\n *\n * @returns {boolean} true if the browser supports the full screen standard, false if not.\n *\n * @see Fullscreen\n * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}\n */\nFeatureDetection.supportsFullscreen = function () {\n return Fullscreen.supportsFullscreen();\n};\n\n/**\n * Detects whether the current browser supports typed arrays.\n *\n * @returns {boolean} true if the browser supports typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsTypedArrays = function () {\n return typeof ArrayBuffer !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigInt64Array typed arrays.\n *\n * @returns {boolean} true if the browser supports BigInt64Array typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsBigInt64Array = function () {\n return typeof BigInt64Array !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigUint64Array typed arrays.\n *\n * @returns {boolean} true if the browser supports BigUint64Array typed arrays, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-typedarray-objects|Typed Array Specification}\n */\nFeatureDetection.supportsBigUint64Array = function () {\n return typeof BigUint64Array !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports BigInt.\n *\n * @returns {boolean} true if the browser supports BigInt, false if not.\n *\n * @see {@link https://tc39.es/ecma262/#sec-bigint-objects|BigInt Specification}\n */\nFeatureDetection.supportsBigInt = function () {\n return typeof BigInt !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports Web Workers.\n *\n * @returns {boolean} true if the browsers supports Web Workers, false if not.\n *\n * @see {@link http://www.w3.org/TR/workers/}\n */\nFeatureDetection.supportsWebWorkers = function () {\n return typeof Worker !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports Web Assembly.\n *\n * @returns {boolean} true if the browsers supports Web Assembly, false if not.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/WebAssembly}\n */\nFeatureDetection.supportsWebAssembly = function () {\n return typeof WebAssembly !== \"undefined\";\n};\n\n/**\n * Detects whether the current browser supports a WebGL2 rendering context for the specified scene.\n *\n * @param {Scene} scene the Cesium scene specifying the rendering context\n * @returns {boolean} true if the browser supports a WebGL2 rendering context, false if not.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext|WebGL2RenderingContext}\n */\nFeatureDetection.supportsWebgl2 = function (scene) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"scene\", scene);\n //>>includeEnd('debug');\n\n return scene.context.webgl2;\n};\n\nexport default FeatureDetection;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport FeatureDetection from \"./FeatureDetection.js\";\nimport CesiumMath from \"./Math.js\";\n\nfunction hue2rgb(m1, m2, h) {\n if (h < 0) {\n h += 1;\n }\n if (h > 1) {\n h -= 1;\n }\n if (h * 6 < 1) {\n return m1 + (m2 - m1) * 6 * h;\n }\n if (h * 2 < 1) {\n return m2;\n }\n if (h * 3 < 2) {\n return m1 + (m2 - m1) * (2 / 3 - h) * 6;\n }\n return m1;\n}\n\n/**\n * A color, specified using red, green, blue, and alpha values,\n * which range from 0 (no intensity) to 1.0 (full intensity).\n * @param {number} [red=1.0] The red component.\n * @param {number} [green=1.0] The green component.\n * @param {number} [blue=1.0] The blue component.\n * @param {number} [alpha=1.0] The alpha component.\n *\n * @constructor\n * @alias Color\n *\n * @see Packable\n */\nfunction Color(red, green, blue, alpha) {\n /**\n * The red component.\n * @type {number}\n * @default 1.0\n */\n this.red = defaultValue(red, 1.0);\n /**\n * The green component.\n * @type {number}\n * @default 1.0\n */\n this.green = defaultValue(green, 1.0);\n /**\n * The blue component.\n * @type {number}\n * @default 1.0\n */\n this.blue = defaultValue(blue, 1.0);\n /**\n * The alpha component.\n * @type {number}\n * @default 1.0\n */\n this.alpha = defaultValue(alpha, 1.0);\n}\n\n/**\n * Creates a Color instance from a {@link Cartesian4}. x, y, z,\n * and w map to red, green, blue, and alpha, respectively.\n *\n * @param {Cartesian4} cartesian The source cartesian.\n * @param {Color} [result] The object onto which to store the result.\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n */\nColor.fromCartesian4 = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Color(cartesian.x, cartesian.y, cartesian.z, cartesian.w);\n }\n\n result.red = cartesian.x;\n result.green = cartesian.y;\n result.blue = cartesian.z;\n result.alpha = cartesian.w;\n return result;\n};\n\n/**\n * Creates a new Color specified using red, green, blue, and alpha values\n * that are in the range of 0 to 255, converting them internally to a range of 0.0 to 1.0.\n *\n * @param {number} [red=255] The red component.\n * @param {number} [green=255] The green component.\n * @param {number} [blue=255] The blue component.\n * @param {number} [alpha=255] The alpha component.\n * @param {Color} [result] The object onto which to store the result.\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n */\nColor.fromBytes = function (red, green, blue, alpha, result) {\n red = Color.byteToFloat(defaultValue(red, 255.0));\n green = Color.byteToFloat(defaultValue(green, 255.0));\n blue = Color.byteToFloat(defaultValue(blue, 255.0));\n alpha = Color.byteToFloat(defaultValue(alpha, 255.0));\n\n if (!defined(result)) {\n return new Color(red, green, blue, alpha);\n }\n\n result.red = red;\n result.green = green;\n result.blue = blue;\n result.alpha = alpha;\n return result;\n};\n\n/**\n * Creates a new Color that has the same red, green, and blue components\n * of the specified color, but with the specified alpha value.\n *\n * @param {Color} color The base color\n * @param {number} alpha The new alpha component.\n * @param {Color} [result] The object onto which to store the result.\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n *\n * @example const translucentRed = Cesium.Color.fromAlpha(Cesium.Color.RED, 0.9);\n */\nColor.fromAlpha = function (color, alpha, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"color\", color);\n Check.typeOf.number(\"alpha\", alpha);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Color(color.red, color.green, color.blue, alpha);\n }\n\n result.red = color.red;\n result.green = color.green;\n result.blue = color.blue;\n result.alpha = alpha;\n return result;\n};\n\nlet scratchArrayBuffer;\nlet scratchUint32Array;\nlet scratchUint8Array;\nif (FeatureDetection.supportsTypedArrays()) {\n scratchArrayBuffer = new ArrayBuffer(4);\n scratchUint32Array = new Uint32Array(scratchArrayBuffer);\n scratchUint8Array = new Uint8Array(scratchArrayBuffer);\n}\n\n/**\n * Creates a new Color from a single numeric unsigned 32-bit RGBA value, using the endianness\n * of the system.\n *\n * @param {number} rgba A single numeric unsigned 32-bit RGBA value.\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The color object.\n *\n * @example\n * const color = Cesium.Color.fromRgba(0x67ADDFFF);\n *\n * @see Color#toRgba\n */\nColor.fromRgba = function (rgba, result) {\n // scratchUint32Array and scratchUint8Array share an underlying array buffer\n scratchUint32Array[0] = rgba;\n return Color.fromBytes(\n scratchUint8Array[0],\n scratchUint8Array[1],\n scratchUint8Array[2],\n scratchUint8Array[3],\n result\n );\n};\n\n/**\n * Creates a Color instance from hue, saturation, and lightness.\n *\n * @param {number} [hue=0] The hue angle 0...1\n * @param {number} [saturation=0] The saturation value 0...1\n * @param {number} [lightness=0] The lightness value 0...1\n * @param {number} [alpha=1.0] The alpha component 0...1\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The color object.\n *\n * @see {@link http://www.w3.org/TR/css3-color/#hsl-color|CSS color values}\n */\nColor.fromHsl = function (hue, saturation, lightness, alpha, result) {\n hue = defaultValue(hue, 0.0) % 1.0;\n saturation = defaultValue(saturation, 0.0);\n lightness = defaultValue(lightness, 0.0);\n alpha = defaultValue(alpha, 1.0);\n\n let red = lightness;\n let green = lightness;\n let blue = lightness;\n\n if (saturation !== 0) {\n let m2;\n if (lightness < 0.5) {\n m2 = lightness * (1 + saturation);\n } else {\n m2 = lightness + saturation - lightness * saturation;\n }\n\n const m1 = 2.0 * lightness - m2;\n red = hue2rgb(m1, m2, hue + 1 / 3);\n green = hue2rgb(m1, m2, hue);\n blue = hue2rgb(m1, m2, hue - 1 / 3);\n }\n\n if (!defined(result)) {\n return new Color(red, green, blue, alpha);\n }\n\n result.red = red;\n result.green = green;\n result.blue = blue;\n result.alpha = alpha;\n return result;\n};\n\n/**\n * Creates a random color using the provided options. For reproducible random colors, you should\n * call {@link CesiumMath#setRandomNumberSeed} once at the beginning of your application.\n *\n * @param {object} [options] Object with the following properties:\n * @param {number} [options.red] If specified, the red component to use instead of a randomized value.\n * @param {number} [options.minimumRed=0.0] The maximum red value to generate if none was specified.\n * @param {number} [options.maximumRed=1.0] The minimum red value to generate if none was specified.\n * @param {number} [options.green] If specified, the green component to use instead of a randomized value.\n * @param {number} [options.minimumGreen=0.0] The maximum green value to generate if none was specified.\n * @param {number} [options.maximumGreen=1.0] The minimum green value to generate if none was specified.\n * @param {number} [options.blue] If specified, the blue component to use instead of a randomized value.\n * @param {number} [options.minimumBlue=0.0] The maximum blue value to generate if none was specified.\n * @param {number} [options.maximumBlue=1.0] The minimum blue value to generate if none was specified.\n * @param {number} [options.alpha] If specified, the alpha component to use instead of a randomized value.\n * @param {number} [options.minimumAlpha=0.0] The maximum alpha value to generate if none was specified.\n * @param {number} [options.maximumAlpha=1.0] The minimum alpha value to generate if none was specified.\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The modified result parameter or a new instance if result was undefined.\n *\n * @exception {DeveloperError} minimumRed must be less than or equal to maximumRed.\n * @exception {DeveloperError} minimumGreen must be less than or equal to maximumGreen.\n * @exception {DeveloperError} minimumBlue must be less than or equal to maximumBlue.\n * @exception {DeveloperError} minimumAlpha must be less than or equal to maximumAlpha.\n *\n * @example\n * //Create a completely random color\n * const color = Cesium.Color.fromRandom();\n *\n * //Create a random shade of yellow.\n * const color1 = Cesium.Color.fromRandom({\n * red : 1.0,\n * green : 1.0,\n * alpha : 1.0\n * });\n *\n * //Create a random bright color.\n * const color2 = Cesium.Color.fromRandom({\n * minimumRed : 0.75,\n * minimumGreen : 0.75,\n * minimumBlue : 0.75,\n * alpha : 1.0\n * });\n */\nColor.fromRandom = function (options, result) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n let red = options.red;\n if (!defined(red)) {\n const minimumRed = defaultValue(options.minimumRed, 0);\n const maximumRed = defaultValue(options.maximumRed, 1.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThanOrEquals(\"minimumRed\", minimumRed, maximumRed);\n //>>includeEnd('debug');\n\n red =\n minimumRed + CesiumMath.nextRandomNumber() * (maximumRed - minimumRed);\n }\n\n let green = options.green;\n if (!defined(green)) {\n const minimumGreen = defaultValue(options.minimumGreen, 0);\n const maximumGreen = defaultValue(options.maximumGreen, 1.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThanOrEquals(\n \"minimumGreen\",\n minimumGreen,\n maximumGreen\n );\n //>>includeEnd('debug');\n green =\n minimumGreen +\n CesiumMath.nextRandomNumber() * (maximumGreen - minimumGreen);\n }\n\n let blue = options.blue;\n if (!defined(blue)) {\n const minimumBlue = defaultValue(options.minimumBlue, 0);\n const maximumBlue = defaultValue(options.maximumBlue, 1.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThanOrEquals(\n \"minimumBlue\",\n minimumBlue,\n maximumBlue\n );\n //>>includeEnd('debug');\n\n blue =\n minimumBlue + CesiumMath.nextRandomNumber() * (maximumBlue - minimumBlue);\n }\n\n let alpha = options.alpha;\n if (!defined(alpha)) {\n const minimumAlpha = defaultValue(options.minimumAlpha, 0);\n const maximumAlpha = defaultValue(options.maximumAlpha, 1.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThanOrEquals(\n \"minumumAlpha\",\n minimumAlpha,\n maximumAlpha\n );\n //>>includeEnd('debug');\n\n alpha =\n minimumAlpha +\n CesiumMath.nextRandomNumber() * (maximumAlpha - minimumAlpha);\n }\n\n if (!defined(result)) {\n return new Color(red, green, blue, alpha);\n }\n\n result.red = red;\n result.green = green;\n result.blue = blue;\n result.alpha = alpha;\n return result;\n};\n\n//#rgba\nconst rgbaMatcher = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i;\n//#rrggbbaa\nconst rrggbbaaMatcher = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i;\n//rgb(), rgba(), or rgb%()\nconst rgbParenthesesMatcher = /^rgba?\\s*\\(\\s*([0-9.]+%?)\\s*[,\\s]+\\s*([0-9.]+%?)\\s*[,\\s]+\\s*([0-9.]+%?)(?:\\s*[,\\s/]+\\s*([0-9.]+))?\\s*\\)$/i;\n//hsl() or hsla()\nconst hslParenthesesMatcher = /^hsla?\\s*\\(\\s*([0-9.]+)\\s*[,\\s]+\\s*([0-9.]+%)\\s*[,\\s]+\\s*([0-9.]+%)(?:\\s*[,\\s/]+\\s*([0-9.]+))?\\s*\\)$/i;\n\n/**\n * Creates a Color instance from a CSS color value.\n *\n * @param {string} color The CSS color value in #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(), or hsla() format.\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The color object, or undefined if the string was not a valid CSS color.\n *\n *\n * @example\n * const cesiumBlue = Cesium.Color.fromCssColorString('#67ADDF');\n * const green = Cesium.Color.fromCssColorString('green');\n *\n * @see {@link http://www.w3.org/TR/css3-color|CSS color values}\n */\nColor.fromCssColorString = function (color, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"color\", color);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Color();\n }\n\n // Remove all surrounding whitespaces from the color string\n color = color.trim();\n\n const namedColor = Color[color.toUpperCase()];\n if (defined(namedColor)) {\n Color.clone(namedColor, result);\n return result;\n }\n\n let matches = rgbaMatcher.exec(color);\n if (matches !== null) {\n result.red = parseInt(matches[1], 16) / 15;\n result.green = parseInt(matches[2], 16) / 15.0;\n result.blue = parseInt(matches[3], 16) / 15.0;\n result.alpha = parseInt(defaultValue(matches[4], \"f\"), 16) / 15.0;\n return result;\n }\n\n matches = rrggbbaaMatcher.exec(color);\n if (matches !== null) {\n result.red = parseInt(matches[1], 16) / 255.0;\n result.green = parseInt(matches[2], 16) / 255.0;\n result.blue = parseInt(matches[3], 16) / 255.0;\n result.alpha = parseInt(defaultValue(matches[4], \"ff\"), 16) / 255.0;\n return result;\n }\n\n matches = rgbParenthesesMatcher.exec(color);\n if (matches !== null) {\n result.red =\n parseFloat(matches[1]) / (\"%\" === matches[1].substr(-1) ? 100.0 : 255.0);\n result.green =\n parseFloat(matches[2]) / (\"%\" === matches[2].substr(-1) ? 100.0 : 255.0);\n result.blue =\n parseFloat(matches[3]) / (\"%\" === matches[3].substr(-1) ? 100.0 : 255.0);\n result.alpha = parseFloat(defaultValue(matches[4], \"1.0\"));\n return result;\n }\n\n matches = hslParenthesesMatcher.exec(color);\n if (matches !== null) {\n return Color.fromHsl(\n parseFloat(matches[1]) / 360.0,\n parseFloat(matches[2]) / 100.0,\n parseFloat(matches[3]) / 100.0,\n parseFloat(defaultValue(matches[4], \"1.0\")),\n result\n );\n }\n\n result = undefined;\n return result;\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nColor.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Color} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nColor.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n array[startingIndex++] = value.red;\n array[startingIndex++] = value.green;\n array[startingIndex++] = value.blue;\n array[startingIndex] = value.alpha;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Color} [result] The object into which to store the result.\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n */\nColor.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n if (!defined(result)) {\n result = new Color();\n }\n result.red = array[startingIndex++];\n result.green = array[startingIndex++];\n result.blue = array[startingIndex++];\n result.alpha = array[startingIndex];\n return result;\n};\n\n/**\n * Converts a 'byte' color component in the range of 0 to 255 into\n * a 'float' color component in the range of 0 to 1.0.\n *\n * @param {number} number The number to be converted.\n * @returns {number} The converted number.\n */\nColor.byteToFloat = function (number) {\n return number / 255.0;\n};\n\n/**\n * Converts a 'float' color component in the range of 0 to 1.0 into\n * a 'byte' color component in the range of 0 to 255.\n *\n * @param {number} number The number to be converted.\n * @returns {number} The converted number.\n */\nColor.floatToByte = function (number) {\n return number === 1.0 ? 255.0 : (number * 256.0) | 0;\n};\n\n/**\n * Duplicates a Color.\n *\n * @param {Color} color The Color to duplicate.\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The modified result parameter or a new instance if result was undefined. (Returns undefined if color is undefined)\n */\nColor.clone = function (color, result) {\n if (!defined(color)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Color(color.red, color.green, color.blue, color.alpha);\n }\n result.red = color.red;\n result.green = color.green;\n result.blue = color.blue;\n result.alpha = color.alpha;\n return result;\n};\n\n/**\n * Returns true if the first Color equals the second color.\n *\n * @param {Color} left The first Color to compare for equality.\n * @param {Color} right The second Color to compare for equality.\n * @returns {boolean} true if the Colors are equal; otherwise, false.\n */\nColor.equals = function (left, right) {\n return (\n left === right || //\n (defined(left) && //\n defined(right) && //\n left.red === right.red && //\n left.green === right.green && //\n left.blue === right.blue && //\n left.alpha === right.alpha)\n );\n};\n\n/**\n * @private\n */\nColor.equalsArray = function (color, array, offset) {\n return (\n color.red === array[offset] &&\n color.green === array[offset + 1] &&\n color.blue === array[offset + 2] &&\n color.alpha === array[offset + 3]\n );\n};\n\n/**\n * Returns a duplicate of a Color instance.\n *\n * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.\n * @returns {Color} The modified result parameter or a new instance if result was undefined.\n */\nColor.prototype.clone = function (result) {\n return Color.clone(this, result);\n};\n\n/**\n * Returns true if this Color equals other.\n *\n * @param {Color} other The Color to compare for equality.\n * @returns {boolean} true if the Colors are equal; otherwise, false.\n */\nColor.prototype.equals = function (other) {\n return Color.equals(this, other);\n};\n\n/**\n * Returns true if this Color equals other componentwise within the specified epsilon.\n *\n * @param {Color} other The Color to compare for equality.\n * @param {number} [epsilon=0.0] The epsilon to use for equality testing.\n * @returns {boolean} true if the Colors are equal within the specified epsilon; otherwise, false.\n */\nColor.prototype.equalsEpsilon = function (other, epsilon) {\n return (\n this === other || //\n (defined(other) && //\n Math.abs(this.red - other.red) <= epsilon && //\n Math.abs(this.green - other.green) <= epsilon && //\n Math.abs(this.blue - other.blue) <= epsilon && //\n Math.abs(this.alpha - other.alpha) <= epsilon)\n );\n};\n\n/**\n * Creates a string representing this Color in the format '(red, green, blue, alpha)'.\n *\n * @returns {string} A string representing this Color in the format '(red, green, blue, alpha)'.\n */\nColor.prototype.toString = function () {\n return `(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;\n};\n\n/**\n * Creates a string containing the CSS color value for this color.\n *\n * @returns {string} The CSS equivalent of this color.\n *\n * @see {@link http://www.w3.org/TR/css3-color/#rgba-color|CSS RGB or RGBA color values}\n */\nColor.prototype.toCssColorString = function () {\n const red = Color.floatToByte(this.red);\n const green = Color.floatToByte(this.green);\n const blue = Color.floatToByte(this.blue);\n if (this.alpha === 1) {\n return `rgb(${red},${green},${blue})`;\n }\n return `rgba(${red},${green},${blue},${this.alpha})`;\n};\n\n/**\n * Creates a string containing CSS hex string color value for this color.\n *\n * @returns {string} The CSS hex string equivalent of this color.\n */\nColor.prototype.toCssHexString = function () {\n let r = Color.floatToByte(this.red).toString(16);\n if (r.length < 2) {\n r = `0${r}`;\n }\n let g = Color.floatToByte(this.green).toString(16);\n if (g.length < 2) {\n g = `0${g}`;\n }\n let b = Color.floatToByte(this.blue).toString(16);\n if (b.length < 2) {\n b = `0${b}`;\n }\n if (this.alpha < 1) {\n let hexAlpha = Color.floatToByte(this.alpha).toString(16);\n if (hexAlpha.length < 2) {\n hexAlpha = `0${hexAlpha}`;\n }\n return `#${r}${g}${b}${hexAlpha}`;\n }\n return `#${r}${g}${b}`;\n};\n\n/**\n * Converts this color to an array of red, green, blue, and alpha values\n * that are in the range of 0 to 255.\n *\n * @param {number[]} [result] The array to store the result in, if undefined a new instance will be created.\n * @returns {number[]} The modified result parameter or a new instance if result was undefined.\n */\nColor.prototype.toBytes = function (result) {\n const red = Color.floatToByte(this.red);\n const green = Color.floatToByte(this.green);\n const blue = Color.floatToByte(this.blue);\n const alpha = Color.floatToByte(this.alpha);\n\n if (!defined(result)) {\n return [red, green, blue, alpha];\n }\n result[0] = red;\n result[1] = green;\n result[2] = blue;\n result[3] = alpha;\n return result;\n};\n\n/**\n * Converts this color to a single numeric unsigned 32-bit RGBA value, using the endianness\n * of the system.\n *\n * @returns {number} A single numeric unsigned 32-bit RGBA value.\n *\n *\n * @example\n * const rgba = Cesium.Color.BLUE.toRgba();\n *\n * @see Color.fromRgba\n */\nColor.prototype.toRgba = function () {\n // scratchUint32Array and scratchUint8Array share an underlying array buffer\n scratchUint8Array[0] = Color.floatToByte(this.red);\n scratchUint8Array[1] = Color.floatToByte(this.green);\n scratchUint8Array[2] = Color.floatToByte(this.blue);\n scratchUint8Array[3] = Color.floatToByte(this.alpha);\n return scratchUint32Array[0];\n};\n\n/**\n * Brightens this color by the provided magnitude.\n *\n * @param {number} magnitude A positive number indicating the amount to brighten.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n *\n * @example\n * const brightBlue = Cesium.Color.BLUE.brighten(0.5, new Cesium.Color());\n */\nColor.prototype.brighten = function (magnitude, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"magnitude\", magnitude);\n Check.typeOf.number.greaterThanOrEquals(\"magnitude\", magnitude, 0.0);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n magnitude = 1.0 - magnitude;\n result.red = 1.0 - (1.0 - this.red) * magnitude;\n result.green = 1.0 - (1.0 - this.green) * magnitude;\n result.blue = 1.0 - (1.0 - this.blue) * magnitude;\n result.alpha = this.alpha;\n return result;\n};\n\n/**\n * Darkens this color by the provided magnitude.\n *\n * @param {number} magnitude A positive number indicating the amount to darken.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n *\n * @example\n * const darkBlue = Cesium.Color.BLUE.darken(0.5, new Cesium.Color());\n */\nColor.prototype.darken = function (magnitude, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"magnitude\", magnitude);\n Check.typeOf.number.greaterThanOrEquals(\"magnitude\", magnitude, 0.0);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n magnitude = 1.0 - magnitude;\n result.red = this.red * magnitude;\n result.green = this.green * magnitude;\n result.blue = this.blue * magnitude;\n result.alpha = this.alpha;\n return result;\n};\n\n/**\n * Creates a new Color that has the same red, green, and blue components\n * as this Color, but with the specified alpha value.\n *\n * @param {number} alpha The new alpha component.\n * @param {Color} [result] The object onto which to store the result.\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n *\n * @example const translucentRed = Cesium.Color.RED.withAlpha(0.9);\n */\nColor.prototype.withAlpha = function (alpha, result) {\n return Color.fromAlpha(this, alpha, result);\n};\n\n/**\n * Computes the componentwise sum of two Colors.\n *\n * @param {Color} left The first Color.\n * @param {Color} right The second Color.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = left.red + right.red;\n result.green = left.green + right.green;\n result.blue = left.blue + right.blue;\n result.alpha = left.alpha + right.alpha;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two Colors.\n *\n * @param {Color} left The first Color.\n * @param {Color} right The second Color.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = left.red - right.red;\n result.green = left.green - right.green;\n result.blue = left.blue - right.blue;\n result.alpha = left.alpha - right.alpha;\n return result;\n};\n\n/**\n * Computes the componentwise product of two Colors.\n *\n * @param {Color} left The first Color.\n * @param {Color} right The second Color.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = left.red * right.red;\n result.green = left.green * right.green;\n result.blue = left.blue * right.blue;\n result.alpha = left.alpha * right.alpha;\n return result;\n};\n\n/**\n * Computes the componentwise quotient of two Colors.\n *\n * @param {Color} left The first Color.\n * @param {Color} right The second Color.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.divide = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = left.red / right.red;\n result.green = left.green / right.green;\n result.blue = left.blue / right.blue;\n result.alpha = left.alpha / right.alpha;\n return result;\n};\n\n/**\n * Computes the componentwise modulus of two Colors.\n *\n * @param {Color} left The first Color.\n * @param {Color} right The second Color.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.mod = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = left.red % right.red;\n result.green = left.green % right.green;\n result.blue = left.blue % right.blue;\n result.alpha = left.alpha % right.alpha;\n return result;\n};\n\n/**\n * Computes the linear interpolation or extrapolation at t between the provided colors.\n *\n * @param {Color} start The color corresponding to t at 0.0.\n * @param {Color} end The color corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = CesiumMath.lerp(start.red, end.red, t);\n result.green = CesiumMath.lerp(start.green, end.green, t);\n result.blue = CesiumMath.lerp(start.blue, end.blue, t);\n result.alpha = CesiumMath.lerp(start.alpha, end.alpha, t);\n return result;\n};\n\n/**\n * Multiplies the provided Color componentwise by the provided scalar.\n *\n * @param {Color} color The Color to be scaled.\n * @param {number} scalar The scalar to multiply with.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.multiplyByScalar = function (color, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"color\", color);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = color.red * scalar;\n result.green = color.green * scalar;\n result.blue = color.blue * scalar;\n result.alpha = color.alpha * scalar;\n return result;\n};\n\n/**\n * Divides the provided Color componentwise by the provided scalar.\n *\n * @param {Color} color The Color to be divided.\n * @param {number} scalar The scalar to divide with.\n * @param {Color} result The object onto which to store the result.\n * @returns {Color} The modified result parameter.\n */\nColor.divideByScalar = function (color, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"color\", color);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.red = color.red / scalar;\n result.green = color.green / scalar;\n result.blue = color.blue / scalar;\n result.alpha = color.alpha / scalar;\n return result;\n};\n\n/**\n * An immutable Color instance initialized to CSS color #F0F8FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ALICEBLUE = Object.freeze(Color.fromCssColorString(\"#F0F8FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FAEBD7\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ANTIQUEWHITE = Object.freeze(Color.fromCssColorString(\"#FAEBD7\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00FFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.AQUA = Object.freeze(Color.fromCssColorString(\"#00FFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #7FFFD4\n * \n *\n * @constant\n * @type {Color}\n */\nColor.AQUAMARINE = Object.freeze(Color.fromCssColorString(\"#7FFFD4\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F0FFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.AZURE = Object.freeze(Color.fromCssColorString(\"#F0FFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F5F5DC\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BEIGE = Object.freeze(Color.fromCssColorString(\"#F5F5DC\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFE4C4\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BISQUE = Object.freeze(Color.fromCssColorString(\"#FFE4C4\"));\n\n/**\n * An immutable Color instance initialized to CSS color #000000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BLACK = Object.freeze(Color.fromCssColorString(\"#000000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFEBCD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BLANCHEDALMOND = Object.freeze(Color.fromCssColorString(\"#FFEBCD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #0000FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BLUE = Object.freeze(Color.fromCssColorString(\"#0000FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #8A2BE2\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BLUEVIOLET = Object.freeze(Color.fromCssColorString(\"#8A2BE2\"));\n\n/**\n * An immutable Color instance initialized to CSS color #A52A2A\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BROWN = Object.freeze(Color.fromCssColorString(\"#A52A2A\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DEB887\n * \n *\n * @constant\n * @type {Color}\n */\nColor.BURLYWOOD = Object.freeze(Color.fromCssColorString(\"#DEB887\"));\n\n/**\n * An immutable Color instance initialized to CSS color #5F9EA0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CADETBLUE = Object.freeze(Color.fromCssColorString(\"#5F9EA0\"));\n/**\n * An immutable Color instance initialized to CSS color #7FFF00\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CHARTREUSE = Object.freeze(Color.fromCssColorString(\"#7FFF00\"));\n\n/**\n * An immutable Color instance initialized to CSS color #D2691E\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CHOCOLATE = Object.freeze(Color.fromCssColorString(\"#D2691E\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF7F50\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CORAL = Object.freeze(Color.fromCssColorString(\"#FF7F50\"));\n\n/**\n * An immutable Color instance initialized to CSS color #6495ED\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CORNFLOWERBLUE = Object.freeze(Color.fromCssColorString(\"#6495ED\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFF8DC\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CORNSILK = Object.freeze(Color.fromCssColorString(\"#FFF8DC\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DC143C\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CRIMSON = Object.freeze(Color.fromCssColorString(\"#DC143C\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00FFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.CYAN = Object.freeze(Color.fromCssColorString(\"#00FFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00008B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKBLUE = Object.freeze(Color.fromCssColorString(\"#00008B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #008B8B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKCYAN = Object.freeze(Color.fromCssColorString(\"#008B8B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #B8860B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKGOLDENROD = Object.freeze(Color.fromCssColorString(\"#B8860B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #A9A9A9\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKGRAY = Object.freeze(Color.fromCssColorString(\"#A9A9A9\"));\n\n/**\n * An immutable Color instance initialized to CSS color #006400\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKGREEN = Object.freeze(Color.fromCssColorString(\"#006400\"));\n\n/**\n * An immutable Color instance initialized to CSS color #A9A9A9\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKGREY = Color.DARKGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #BDB76B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKKHAKI = Object.freeze(Color.fromCssColorString(\"#BDB76B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #8B008B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKMAGENTA = Object.freeze(Color.fromCssColorString(\"#8B008B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #556B2F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKOLIVEGREEN = Object.freeze(Color.fromCssColorString(\"#556B2F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF8C00\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKORANGE = Object.freeze(Color.fromCssColorString(\"#FF8C00\"));\n\n/**\n * An immutable Color instance initialized to CSS color #9932CC\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKORCHID = Object.freeze(Color.fromCssColorString(\"#9932CC\"));\n\n/**\n * An immutable Color instance initialized to CSS color #8B0000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKRED = Object.freeze(Color.fromCssColorString(\"#8B0000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #E9967A\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKSALMON = Object.freeze(Color.fromCssColorString(\"#E9967A\"));\n\n/**\n * An immutable Color instance initialized to CSS color #8FBC8F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKSEAGREEN = Object.freeze(Color.fromCssColorString(\"#8FBC8F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #483D8B\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKSLATEBLUE = Object.freeze(Color.fromCssColorString(\"#483D8B\"));\n\n/**\n * An immutable Color instance initialized to CSS color #2F4F4F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKSLATEGRAY = Object.freeze(Color.fromCssColorString(\"#2F4F4F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #2F4F4F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKSLATEGREY = Color.DARKSLATEGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #00CED1\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKTURQUOISE = Object.freeze(Color.fromCssColorString(\"#00CED1\"));\n\n/**\n * An immutable Color instance initialized to CSS color #9400D3\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DARKVIOLET = Object.freeze(Color.fromCssColorString(\"#9400D3\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF1493\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DEEPPINK = Object.freeze(Color.fromCssColorString(\"#FF1493\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00BFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DEEPSKYBLUE = Object.freeze(Color.fromCssColorString(\"#00BFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #696969\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DIMGRAY = Object.freeze(Color.fromCssColorString(\"#696969\"));\n\n/**\n * An immutable Color instance initialized to CSS color #696969\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DIMGREY = Color.DIMGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #1E90FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.DODGERBLUE = Object.freeze(Color.fromCssColorString(\"#1E90FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #B22222\n * \n *\n * @constant\n * @type {Color}\n */\nColor.FIREBRICK = Object.freeze(Color.fromCssColorString(\"#B22222\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFAF0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.FLORALWHITE = Object.freeze(Color.fromCssColorString(\"#FFFAF0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #228B22\n * \n *\n * @constant\n * @type {Color}\n */\nColor.FORESTGREEN = Object.freeze(Color.fromCssColorString(\"#228B22\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF00FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.FUCHSIA = Object.freeze(Color.fromCssColorString(\"#FF00FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DCDCDC\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GAINSBORO = Object.freeze(Color.fromCssColorString(\"#DCDCDC\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F8F8FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GHOSTWHITE = Object.freeze(Color.fromCssColorString(\"#F8F8FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFD700\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GOLD = Object.freeze(Color.fromCssColorString(\"#FFD700\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DAA520\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GOLDENROD = Object.freeze(Color.fromCssColorString(\"#DAA520\"));\n\n/**\n * An immutable Color instance initialized to CSS color #808080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GRAY = Object.freeze(Color.fromCssColorString(\"#808080\"));\n\n/**\n * An immutable Color instance initialized to CSS color #008000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GREEN = Object.freeze(Color.fromCssColorString(\"#008000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #ADFF2F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GREENYELLOW = Object.freeze(Color.fromCssColorString(\"#ADFF2F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #808080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.GREY = Color.GRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #F0FFF0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.HONEYDEW = Object.freeze(Color.fromCssColorString(\"#F0FFF0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF69B4\n * \n *\n * @constant\n * @type {Color}\n */\nColor.HOTPINK = Object.freeze(Color.fromCssColorString(\"#FF69B4\"));\n\n/**\n * An immutable Color instance initialized to CSS color #CD5C5C\n * \n *\n * @constant\n * @type {Color}\n */\nColor.INDIANRED = Object.freeze(Color.fromCssColorString(\"#CD5C5C\"));\n\n/**\n * An immutable Color instance initialized to CSS color #4B0082\n * \n *\n * @constant\n * @type {Color}\n */\nColor.INDIGO = Object.freeze(Color.fromCssColorString(\"#4B0082\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFFF0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.IVORY = Object.freeze(Color.fromCssColorString(\"#FFFFF0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F0E68C\n * \n *\n * @constant\n * @type {Color}\n */\nColor.KHAKI = Object.freeze(Color.fromCssColorString(\"#F0E68C\"));\n\n/**\n * An immutable Color instance initialized to CSS color #E6E6FA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LAVENDER = Object.freeze(Color.fromCssColorString(\"#E6E6FA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFF0F5\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LAVENDAR_BLUSH = Object.freeze(Color.fromCssColorString(\"#FFF0F5\"));\n\n/**\n * An immutable Color instance initialized to CSS color #7CFC00\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LAWNGREEN = Object.freeze(Color.fromCssColorString(\"#7CFC00\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFACD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LEMONCHIFFON = Object.freeze(Color.fromCssColorString(\"#FFFACD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #ADD8E6\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTBLUE = Object.freeze(Color.fromCssColorString(\"#ADD8E6\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F08080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTCORAL = Object.freeze(Color.fromCssColorString(\"#F08080\"));\n\n/**\n * An immutable Color instance initialized to CSS color #E0FFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTCYAN = Object.freeze(Color.fromCssColorString(\"#E0FFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FAFAD2\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTGOLDENRODYELLOW = Object.freeze(Color.fromCssColorString(\"#FAFAD2\"));\n\n/**\n * An immutable Color instance initialized to CSS color #D3D3D3\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTGRAY = Object.freeze(Color.fromCssColorString(\"#D3D3D3\"));\n\n/**\n * An immutable Color instance initialized to CSS color #90EE90\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTGREEN = Object.freeze(Color.fromCssColorString(\"#90EE90\"));\n\n/**\n * An immutable Color instance initialized to CSS color #D3D3D3\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTGREY = Color.LIGHTGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #FFB6C1\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTPINK = Object.freeze(Color.fromCssColorString(\"#FFB6C1\"));\n\n/**\n * An immutable Color instance initialized to CSS color #20B2AA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTSEAGREEN = Object.freeze(Color.fromCssColorString(\"#20B2AA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #87CEFA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTSKYBLUE = Object.freeze(Color.fromCssColorString(\"#87CEFA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #778899\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTSLATEGRAY = Object.freeze(Color.fromCssColorString(\"#778899\"));\n\n/**\n * An immutable Color instance initialized to CSS color #778899\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTSLATEGREY = Color.LIGHTSLATEGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #B0C4DE\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTSTEELBLUE = Object.freeze(Color.fromCssColorString(\"#B0C4DE\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFFE0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIGHTYELLOW = Object.freeze(Color.fromCssColorString(\"#FFFFE0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00FF00\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIME = Object.freeze(Color.fromCssColorString(\"#00FF00\"));\n\n/**\n * An immutable Color instance initialized to CSS color #32CD32\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LIMEGREEN = Object.freeze(Color.fromCssColorString(\"#32CD32\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FAF0E6\n * \n *\n * @constant\n * @type {Color}\n */\nColor.LINEN = Object.freeze(Color.fromCssColorString(\"#FAF0E6\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF00FF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MAGENTA = Object.freeze(Color.fromCssColorString(\"#FF00FF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #800000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MAROON = Object.freeze(Color.fromCssColorString(\"#800000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #66CDAA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMAQUAMARINE = Object.freeze(Color.fromCssColorString(\"#66CDAA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #0000CD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMBLUE = Object.freeze(Color.fromCssColorString(\"#0000CD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #BA55D3\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMORCHID = Object.freeze(Color.fromCssColorString(\"#BA55D3\"));\n\n/**\n * An immutable Color instance initialized to CSS color #9370DB\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMPURPLE = Object.freeze(Color.fromCssColorString(\"#9370DB\"));\n\n/**\n * An immutable Color instance initialized to CSS color #3CB371\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMSEAGREEN = Object.freeze(Color.fromCssColorString(\"#3CB371\"));\n\n/**\n * An immutable Color instance initialized to CSS color #7B68EE\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMSLATEBLUE = Object.freeze(Color.fromCssColorString(\"#7B68EE\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00FA9A\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMSPRINGGREEN = Object.freeze(Color.fromCssColorString(\"#00FA9A\"));\n\n/**\n * An immutable Color instance initialized to CSS color #48D1CC\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMTURQUOISE = Object.freeze(Color.fromCssColorString(\"#48D1CC\"));\n\n/**\n * An immutable Color instance initialized to CSS color #C71585\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MEDIUMVIOLETRED = Object.freeze(Color.fromCssColorString(\"#C71585\"));\n\n/**\n * An immutable Color instance initialized to CSS color #191970\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MIDNIGHTBLUE = Object.freeze(Color.fromCssColorString(\"#191970\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F5FFFA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MINTCREAM = Object.freeze(Color.fromCssColorString(\"#F5FFFA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFE4E1\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MISTYROSE = Object.freeze(Color.fromCssColorString(\"#FFE4E1\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFE4B5\n * \n *\n * @constant\n * @type {Color}\n */\nColor.MOCCASIN = Object.freeze(Color.fromCssColorString(\"#FFE4B5\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFDEAD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.NAVAJOWHITE = Object.freeze(Color.fromCssColorString(\"#FFDEAD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #000080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.NAVY = Object.freeze(Color.fromCssColorString(\"#000080\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FDF5E6\n * \n *\n * @constant\n * @type {Color}\n */\nColor.OLDLACE = Object.freeze(Color.fromCssColorString(\"#FDF5E6\"));\n\n/**\n * An immutable Color instance initialized to CSS color #808000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.OLIVE = Object.freeze(Color.fromCssColorString(\"#808000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #6B8E23\n * \n *\n * @constant\n * @type {Color}\n */\nColor.OLIVEDRAB = Object.freeze(Color.fromCssColorString(\"#6B8E23\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFA500\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ORANGE = Object.freeze(Color.fromCssColorString(\"#FFA500\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF4500\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ORANGERED = Object.freeze(Color.fromCssColorString(\"#FF4500\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DA70D6\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ORCHID = Object.freeze(Color.fromCssColorString(\"#DA70D6\"));\n\n/**\n * An immutable Color instance initialized to CSS color #EEE8AA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PALEGOLDENROD = Object.freeze(Color.fromCssColorString(\"#EEE8AA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #98FB98\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PALEGREEN = Object.freeze(Color.fromCssColorString(\"#98FB98\"));\n\n/**\n * An immutable Color instance initialized to CSS color #AFEEEE\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PALETURQUOISE = Object.freeze(Color.fromCssColorString(\"#AFEEEE\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DB7093\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PALEVIOLETRED = Object.freeze(Color.fromCssColorString(\"#DB7093\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFEFD5\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PAPAYAWHIP = Object.freeze(Color.fromCssColorString(\"#FFEFD5\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFDAB9\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PEACHPUFF = Object.freeze(Color.fromCssColorString(\"#FFDAB9\"));\n\n/**\n * An immutable Color instance initialized to CSS color #CD853F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PERU = Object.freeze(Color.fromCssColorString(\"#CD853F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFC0CB\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PINK = Object.freeze(Color.fromCssColorString(\"#FFC0CB\"));\n\n/**\n * An immutable Color instance initialized to CSS color #DDA0DD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PLUM = Object.freeze(Color.fromCssColorString(\"#DDA0DD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #B0E0E6\n * \n *\n * @constant\n * @type {Color}\n */\nColor.POWDERBLUE = Object.freeze(Color.fromCssColorString(\"#B0E0E6\"));\n\n/**\n * An immutable Color instance initialized to CSS color #800080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.PURPLE = Object.freeze(Color.fromCssColorString(\"#800080\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF0000\n * \n *\n * @constant\n * @type {Color}\n */\nColor.RED = Object.freeze(Color.fromCssColorString(\"#FF0000\"));\n\n/**\n * An immutable Color instance initialized to CSS color #BC8F8F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ROSYBROWN = Object.freeze(Color.fromCssColorString(\"#BC8F8F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #4169E1\n * \n *\n * @constant\n * @type {Color}\n */\nColor.ROYALBLUE = Object.freeze(Color.fromCssColorString(\"#4169E1\"));\n\n/**\n * An immutable Color instance initialized to CSS color #8B4513\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SADDLEBROWN = Object.freeze(Color.fromCssColorString(\"#8B4513\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FA8072\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SALMON = Object.freeze(Color.fromCssColorString(\"#FA8072\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F4A460\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SANDYBROWN = Object.freeze(Color.fromCssColorString(\"#F4A460\"));\n\n/**\n * An immutable Color instance initialized to CSS color #2E8B57\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SEAGREEN = Object.freeze(Color.fromCssColorString(\"#2E8B57\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFF5EE\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SEASHELL = Object.freeze(Color.fromCssColorString(\"#FFF5EE\"));\n\n/**\n * An immutable Color instance initialized to CSS color #A0522D\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SIENNA = Object.freeze(Color.fromCssColorString(\"#A0522D\"));\n\n/**\n * An immutable Color instance initialized to CSS color #C0C0C0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SILVER = Object.freeze(Color.fromCssColorString(\"#C0C0C0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #87CEEB\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SKYBLUE = Object.freeze(Color.fromCssColorString(\"#87CEEB\"));\n\n/**\n * An immutable Color instance initialized to CSS color #6A5ACD\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SLATEBLUE = Object.freeze(Color.fromCssColorString(\"#6A5ACD\"));\n\n/**\n * An immutable Color instance initialized to CSS color #708090\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SLATEGRAY = Object.freeze(Color.fromCssColorString(\"#708090\"));\n\n/**\n * An immutable Color instance initialized to CSS color #708090\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SLATEGREY = Color.SLATEGRAY;\n\n/**\n * An immutable Color instance initialized to CSS color #FFFAFA\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SNOW = Object.freeze(Color.fromCssColorString(\"#FFFAFA\"));\n\n/**\n * An immutable Color instance initialized to CSS color #00FF7F\n * \n *\n * @constant\n * @type {Color}\n */\nColor.SPRINGGREEN = Object.freeze(Color.fromCssColorString(\"#00FF7F\"));\n\n/**\n * An immutable Color instance initialized to CSS color #4682B4\n * \n *\n * @constant\n * @type {Color}\n */\nColor.STEELBLUE = Object.freeze(Color.fromCssColorString(\"#4682B4\"));\n\n/**\n * An immutable Color instance initialized to CSS color #D2B48C\n * \n *\n * @constant\n * @type {Color}\n */\nColor.TAN = Object.freeze(Color.fromCssColorString(\"#D2B48C\"));\n\n/**\n * An immutable Color instance initialized to CSS color #008080\n * \n *\n * @constant\n * @type {Color}\n */\nColor.TEAL = Object.freeze(Color.fromCssColorString(\"#008080\"));\n\n/**\n * An immutable Color instance initialized to CSS color #D8BFD8\n * \n *\n * @constant\n * @type {Color}\n */\nColor.THISTLE = Object.freeze(Color.fromCssColorString(\"#D8BFD8\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FF6347\n * \n *\n * @constant\n * @type {Color}\n */\nColor.TOMATO = Object.freeze(Color.fromCssColorString(\"#FF6347\"));\n\n/**\n * An immutable Color instance initialized to CSS color #40E0D0\n * \n *\n * @constant\n * @type {Color}\n */\nColor.TURQUOISE = Object.freeze(Color.fromCssColorString(\"#40E0D0\"));\n\n/**\n * An immutable Color instance initialized to CSS color #EE82EE\n * \n *\n * @constant\n * @type {Color}\n */\nColor.VIOLET = Object.freeze(Color.fromCssColorString(\"#EE82EE\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F5DEB3\n * \n *\n * @constant\n * @type {Color}\n */\nColor.WHEAT = Object.freeze(Color.fromCssColorString(\"#F5DEB3\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFFFF\n * \n *\n * @constant\n * @type {Color}\n */\nColor.WHITE = Object.freeze(Color.fromCssColorString(\"#FFFFFF\"));\n\n/**\n * An immutable Color instance initialized to CSS color #F5F5F5\n * \n *\n * @constant\n * @type {Color}\n */\nColor.WHITESMOKE = Object.freeze(Color.fromCssColorString(\"#F5F5F5\"));\n\n/**\n * An immutable Color instance initialized to CSS color #FFFF00\n * \n *\n * @constant\n * @type {Color}\n */\nColor.YELLOW = Object.freeze(Color.fromCssColorString(\"#FFFF00\"));\n\n/**\n * An immutable Color instance initialized to CSS color #9ACD32\n * \n *\n * @constant\n * @type {Color}\n */\nColor.YELLOWGREEN = Object.freeze(Color.fromCssColorString(\"#9ACD32\"));\n\n/**\n * An immutable Color instance initialized to CSS transparent.\n * \n *\n * @constant\n * @type {Color}\n */\nColor.TRANSPARENT = Object.freeze(new Color(0, 0, 0, 0));\nexport default Color;\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * Represents a command to the renderer for clearing a framebuffer.\n *\n * @private\n * @constructor\n */\nfunction ClearCommand(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The value to clear the color buffer to. When undefined, the color buffer is not cleared.\n *\n * @type {Color}\n *\n * @default undefined\n */\n this.color = options.color;\n\n /**\n * The value to clear the depth buffer to. When undefined, the depth buffer is not cleared.\n *\n * @type {number}\n *\n * @default undefined\n */\n this.depth = options.depth;\n\n /**\n * The value to clear the stencil buffer to. When undefined, the stencil buffer is not cleared.\n *\n * @type {number}\n *\n * @default undefined\n */\n this.stencil = options.stencil;\n\n /**\n * The render state to apply when executing the clear command. The following states affect clearing:\n * scissor test, color mask, depth mask, and stencil mask. When the render state is\n * undefined, the default render state is used.\n *\n * @type {RenderState}\n *\n * @default undefined\n */\n this.renderState = options.renderState;\n\n /**\n * The framebuffer to clear.\n *\n * @type {Framebuffer}\n *\n * @default undefined\n */\n this.framebuffer = options.framebuffer;\n\n /**\n * The object who created this command. This is useful for debugging command\n * execution; it allows you to see who created a command when you only have a\n * reference to the command, and can be used to selectively execute commands\n * with {@link Scene#debugCommandFilter}.\n *\n * @type {object}\n *\n * @default undefined\n *\n * @see Scene#debugCommandFilter\n */\n this.owner = options.owner;\n\n /**\n * The pass in which to run this command.\n *\n * @type {Pass}\n *\n * @default undefined\n */\n this.pass = options.pass;\n}\n\n/**\n * Clears color to (0.0, 0.0, 0.0, 0.0); depth to 1.0; and stencil to 0.\n *\n * @type {ClearCommand}\n *\n * @constant\n */\nClearCommand.ALL = Object.freeze(\n new ClearCommand({\n color: new Color(0.0, 0.0, 0.0, 0.0),\n depth: 1.0,\n stencil: 0.0,\n })\n);\n\nClearCommand.prototype.execute = function (context, passState) {\n context.clear(this, passState);\n};\nexport default ClearCommand;\n", "/**\n * The render pass for a command.\n *\n * @private\n */\nconst Pass = {\n // If you add/modify/remove Pass constants, also change the automatic GLSL constants\n // that start with 'czm_pass'\n //\n // Commands are executed in order by pass up to the translucent pass.\n // Translucent geometry needs special handling (sorting/OIT). The compute pass\n // is executed first and the overlay pass is executed last. Both are not sorted\n // by frustum.\n ENVIRONMENT: 0,\n COMPUTE: 1,\n GLOBE: 2,\n TERRAIN_CLASSIFICATION: 3,\n CESIUM_3D_TILE: 4,\n CESIUM_3D_TILE_CLASSIFICATION: 5,\n CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW: 6,\n OPAQUE: 7,\n TRANSLUCENT: 8,\n VOXELS: 9,\n OVERLAY: 10,\n NUMBER_OF_PASSES: 11,\n};\nexport default Object.freeze(Pass);\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport Pass from \"./Pass.js\";\n\n/**\n * Represents a command to the renderer for GPU Compute (using old-school GPGPU).\n *\n * @private\n * @constructor\n */\nfunction ComputeCommand(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The vertex array. If none is provided, a viewport quad will be used.\n *\n * @type {VertexArray}\n * @default undefined\n */\n this.vertexArray = options.vertexArray;\n\n /**\n * The fragment shader source. The default vertex shader is ViewportQuadVS.\n *\n * @type {ShaderSource}\n * @default undefined\n */\n this.fragmentShaderSource = options.fragmentShaderSource;\n\n /**\n * The shader program to apply.\n *\n * @type {ShaderProgram}\n * @default undefined\n */\n this.shaderProgram = options.shaderProgram;\n\n /**\n * An object with functions whose names match the uniforms in the shader program\n * and return values to set those uniforms.\n *\n * @type {object}\n * @default undefined\n */\n this.uniformMap = options.uniformMap;\n\n /**\n * Texture to use for offscreen rendering.\n *\n * @type {Texture}\n * @default undefined\n */\n this.outputTexture = options.outputTexture;\n\n /**\n * Function that is called immediately before the ComputeCommand is executed. Used to\n * update any renderer resources. Takes the ComputeCommand as its single argument.\n *\n * @type {Function}\n * @default undefined\n */\n this.preExecute = options.preExecute;\n\n /**\n * Function that is called after the ComputeCommand is executed. Takes the output\n * texture as its single argument.\n *\n * @type {Function}\n * @default undefined\n */\n this.postExecute = options.postExecute;\n\n /**\n * Function that is called when the command is canceled\n *\n * @type {Function}\n * @default undefined\n */\n this.canceled = options.canceled;\n\n /**\n * Whether the renderer resources will persist beyond this call. If not, they\n * will be destroyed after completion.\n *\n * @type {boolean}\n * @default false\n */\n this.persists = defaultValue(options.persists, false);\n\n /**\n * The pass when to render. Always compute pass.\n *\n * @type {Pass}\n * @default Pass.COMPUTE;\n */\n this.pass = Pass.COMPUTE;\n\n /**\n * The object who created this command. This is useful for debugging command\n * execution; it allows us to see who created a command when we only have a\n * reference to the command, and can be used to selectively execute commands\n * with {@link Scene#debugCommandFilter}.\n *\n * @type {object}\n * @default undefined\n *\n * @see Scene#debugCommandFilter\n */\n this.owner = options.owner;\n}\n\n/**\n * Executes the compute command.\n *\n * @param {ComputeEngine} computeEngine The context that processes the compute command.\n */\nComputeCommand.prototype.execute = function (computeEngine) {\n computeEngine.execute(this);\n};\nexport default ComputeCommand;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A 2D Cartesian point.\n * @alias Cartesian2\n * @constructor\n *\n * @param {number} [x=0.0] The X component.\n * @param {number} [y=0.0] The Y component.\n *\n * @see Cartesian3\n * @see Cartesian4\n * @see Packable\n */\nfunction Cartesian2(x, y) {\n /**\n * The X component.\n * @type {number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The Y component.\n * @type {number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n}\n\n/**\n * Creates a Cartesian2 instance from x and y coordinates.\n *\n * @param {number} x The x coordinate.\n * @param {number} y The y coordinate.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n */\nCartesian2.fromElements = function (x, y, result) {\n if (!defined(result)) {\n return new Cartesian2(x, y);\n }\n\n result.x = x;\n result.y = y;\n return result;\n};\n\n/**\n * Duplicates a Cartesian2 instance.\n *\n * @param {Cartesian2} cartesian The Cartesian to duplicate.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)\n */\nCartesian2.clone = function (cartesian, result) {\n if (!defined(cartesian)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Cartesian2(cartesian.x, cartesian.y);\n }\n\n result.x = cartesian.x;\n result.y = cartesian.y;\n return result;\n};\n\n/**\n * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the\n * x and y properties of the Cartesian3 and drops z.\n * @function\n *\n * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n */\nCartesian2.fromCartesian3 = Cartesian2.clone;\n\n/**\n * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the\n * x and y properties of the Cartesian4 and drops z and w.\n * @function\n *\n * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n */\nCartesian2.fromCartesian4 = Cartesian2.clone;\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nCartesian2.packedLength = 2;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Cartesian2} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCartesian2.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex] = value.y;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Cartesian2} [result] The object into which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n */\nCartesian2.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Cartesian2();\n }\n result.x = array[startingIndex++];\n result.y = array[startingIndex];\n return result;\n};\n\n/**\n * Flattens an array of Cartesian2s into an array of components.\n *\n * @param {Cartesian2[]} array The array of cartesians to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 2 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 2) elements.\n * @returns {number[]} The packed array.\n */\nCartesian2.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 2;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 2 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Cartesian2.pack(array[i], result, i * 2);\n }\n return result;\n};\n\n/**\n * Unpacks an array of cartesian components into an array of Cartesian2s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Cartesian2[]} [result] The array onto which to store the result.\n * @returns {Cartesian2[]} The unpacked array.\n */\nCartesian2.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 2);\n if (array.length % 2 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 2.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 2);\n } else {\n result.length = length / 2;\n }\n\n for (let i = 0; i < length; i += 2) {\n const index = i / 2;\n result[index] = Cartesian2.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Creates a Cartesian2 from two consecutive elements in an array.\n * @function\n *\n * @param {number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n *\n * @example\n * // Create a Cartesian2 with (1.0, 2.0)\n * const v = [1.0, 2.0];\n * const p = Cesium.Cartesian2.fromArray(v);\n *\n * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 2.0];\n * const p2 = Cesium.Cartesian2.fromArray(v2, 2);\n */\nCartesian2.fromArray = Cartesian2.unpack;\n\n/**\n * Computes the value of the maximum component for the supplied Cartesian.\n *\n * @param {Cartesian2} cartesian The cartesian to use.\n * @returns {number} The value of the maximum component.\n */\nCartesian2.maximumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.max(cartesian.x, cartesian.y);\n};\n\n/**\n * Computes the value of the minimum component for the supplied Cartesian.\n *\n * @param {Cartesian2} cartesian The cartesian to use.\n * @returns {number} The value of the minimum component.\n */\nCartesian2.minimumComponent = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return Math.min(cartesian.x, cartesian.y);\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.\n *\n * @param {Cartesian2} first A cartesian to compare.\n * @param {Cartesian2} second A cartesian to compare.\n * @param {Cartesian2} result The object into which to store the result.\n * @returns {Cartesian2} A cartesian with the minimum components.\n */\nCartesian2.minimumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.min(first.x, second.x);\n result.y = Math.min(first.y, second.y);\n\n return result;\n};\n\n/**\n * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.\n *\n * @param {Cartesian2} first A cartesian to compare.\n * @param {Cartesian2} second A cartesian to compare.\n * @param {Cartesian2} result The object into which to store the result.\n * @returns {Cartesian2} A cartesian with the maximum components.\n */\nCartesian2.maximumByComponent = function (first, second, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"first\", first);\n Check.typeOf.object(\"second\", second);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.max(first.x, second.x);\n result.y = Math.max(first.y, second.y);\n return result;\n};\n\n/**\n * Constrain a value to lie between two values.\n *\n * @param {Cartesian2} value The value to clamp.\n * @param {Cartesian2} min The minimum bound.\n * @param {Cartesian2} max The maximum bound.\n * @param {Cartesian2} result The object into which to store the result.\n * @returns {Cartesian2} The clamped value such that min <= result <= max.\n */\nCartesian2.clamp = function (value, min, max, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.typeOf.object(\"min\", min);\n Check.typeOf.object(\"max\", max);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = CesiumMath.clamp(value.x, min.x, max.x);\n const y = CesiumMath.clamp(value.y, min.y, max.y);\n\n result.x = x;\n result.y = y;\n\n return result;\n};\n\n/**\n * Computes the provided Cartesian's squared magnitude.\n *\n * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.\n * @returns {number} The squared magnitude.\n */\nCartesian2.magnitudeSquared = function (cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n return cartesian.x * cartesian.x + cartesian.y * cartesian.y;\n};\n\n/**\n * Computes the Cartesian's magnitude (length).\n *\n * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.\n * @returns {number} The magnitude.\n */\nCartesian2.magnitude = function (cartesian) {\n return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));\n};\n\nconst distanceScratch = new Cartesian2();\n\n/**\n * Computes the distance between two points.\n *\n * @param {Cartesian2} left The first point to compute the distance from.\n * @param {Cartesian2} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 1.0\n * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));\n */\nCartesian2.distance = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian2.subtract(left, right, distanceScratch);\n return Cartesian2.magnitude(distanceScratch);\n};\n\n/**\n * Computes the squared distance between two points. Comparing squared distances\n * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.\n *\n * @param {Cartesian2} left The first point to compute the distance from.\n * @param {Cartesian2} right The second point to compute the distance to.\n * @returns {number} The distance between two points.\n *\n * @example\n * // Returns 4.0, not 2.0\n * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));\n */\nCartesian2.distanceSquared = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian2.subtract(left, right, distanceScratch);\n return Cartesian2.magnitudeSquared(distanceScratch);\n};\n\n/**\n * Computes the normalized form of the supplied Cartesian.\n *\n * @param {Cartesian2} cartesian The Cartesian to be normalized.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.normalize = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const magnitude = Cartesian2.magnitude(cartesian);\n\n result.x = cartesian.x / magnitude;\n result.y = cartesian.y / magnitude;\n\n //>>includeStart('debug', pragmas.debug);\n if (isNaN(result.x) || isNaN(result.y)) {\n throw new DeveloperError(\"normalized result is not a number\");\n }\n //>>includeEnd('debug');\n\n return result;\n};\n\n/**\n * Computes the dot (scalar) product of two Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @returns {number} The dot product.\n */\nCartesian2.dot = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return left.x * right.x + left.y * right.y;\n};\n\n/**\n * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @returns {number} The cross product.\n */\nCartesian2.cross = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return left.x * right.y - left.y * right.x;\n};\n\n/**\n * Computes the componentwise product of two Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.multiplyComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x * right.x;\n result.y = left.y * right.y;\n return result;\n};\n\n/**\n * Computes the componentwise quotient of two Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.divideComponents = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x / right.x;\n result.y = left.y / right.y;\n return result;\n};\n\n/**\n * Computes the componentwise sum of two Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x + right.x;\n result.y = left.y + right.y;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x - right.x;\n result.y = left.y - right.y;\n return result;\n};\n\n/**\n * Multiplies the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian2} cartesian The Cartesian to be scaled.\n * @param {number} scalar The scalar to multiply with.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.multiplyByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x * scalar;\n result.y = cartesian.y * scalar;\n return result;\n};\n\n/**\n * Divides the provided Cartesian componentwise by the provided scalar.\n *\n * @param {Cartesian2} cartesian The Cartesian to be divided.\n * @param {number} scalar The scalar to divide by.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.divideByScalar = function (cartesian, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = cartesian.x / scalar;\n result.y = cartesian.y / scalar;\n return result;\n};\n\n/**\n * Negates the provided Cartesian.\n *\n * @param {Cartesian2} cartesian The Cartesian to be negated.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.negate = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -cartesian.x;\n result.y = -cartesian.y;\n return result;\n};\n\n/**\n * Computes the absolute value of the provided Cartesian.\n *\n * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.abs = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Math.abs(cartesian.x);\n result.y = Math.abs(cartesian.y);\n return result;\n};\n\nconst lerpScratch = new Cartesian2();\n/**\n * Computes the linear interpolation or extrapolation at t using the provided cartesians.\n *\n * @param {Cartesian2} start The value corresponding to t at 0.0.\n * @param {Cartesian2} end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nCartesian2.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n Cartesian2.multiplyByScalar(end, t, lerpScratch);\n result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);\n return Cartesian2.add(lerpScratch, result, result);\n};\n\nconst angleBetweenScratch = new Cartesian2();\nconst angleBetweenScratch2 = new Cartesian2();\n/**\n * Returns the angle, in radians, between the provided Cartesians.\n *\n * @param {Cartesian2} left The first Cartesian.\n * @param {Cartesian2} right The second Cartesian.\n * @returns {number} The angle between the Cartesians.\n */\nCartesian2.angleBetween = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n Cartesian2.normalize(left, angleBetweenScratch);\n Cartesian2.normalize(right, angleBetweenScratch2);\n return CesiumMath.acosClamped(\n Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2)\n );\n};\n\nconst mostOrthogonalAxisScratch = new Cartesian2();\n/**\n * Returns the axis that is most orthogonal to the provided Cartesian.\n *\n * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The most orthogonal axis.\n */\nCartesian2.mostOrthogonalAxis = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);\n Cartesian2.abs(f, f);\n\n if (f.x <= f.y) {\n result = Cartesian2.clone(Cartesian2.UNIT_X, result);\n } else {\n result = Cartesian2.clone(Cartesian2.UNIT_Y, result);\n }\n\n return result;\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian2} [left] The first Cartesian.\n * @param {Cartesian2} [right] The second Cartesian.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCartesian2.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y)\n );\n};\n\n/**\n * @private\n */\nCartesian2.equalsArray = function (cartesian, array, offset) {\n return cartesian.x === array[offset] && cartesian.y === array[offset + 1];\n};\n\n/**\n * Compares the provided Cartesians componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian2} [left] The first Cartesian.\n * @param {Cartesian2} [right] The second Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nCartesian2.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n CesiumMath.equalsEpsilon(\n left.x,\n right.x,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.y,\n right.y,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\n\n/**\n * An immutable Cartesian2 instance initialized to (0.0, 0.0).\n *\n * @type {Cartesian2}\n * @constant\n */\nCartesian2.ZERO = Object.freeze(new Cartesian2(0.0, 0.0));\n\n/**\n * An immutable Cartesian2 instance initialized to (1.0, 1.0).\n *\n * @type {Cartesian2}\n * @constant\n */\nCartesian2.ONE = Object.freeze(new Cartesian2(1.0, 1.0));\n\n/**\n * An immutable Cartesian2 instance initialized to (1.0, 0.0).\n *\n * @type {Cartesian2}\n * @constant\n */\nCartesian2.UNIT_X = Object.freeze(new Cartesian2(1.0, 0.0));\n\n/**\n * An immutable Cartesian2 instance initialized to (0.0, 1.0).\n *\n * @type {Cartesian2}\n * @constant\n */\nCartesian2.UNIT_Y = Object.freeze(new Cartesian2(0.0, 1.0));\n\n/**\n * Duplicates this Cartesian2 instance.\n *\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.\n */\nCartesian2.prototype.clone = function (result) {\n return Cartesian2.clone(this, result);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartesian2} [right] The right hand side Cartesian.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nCartesian2.prototype.equals = function (right) {\n return Cartesian2.equals(this, right);\n};\n\n/**\n * Compares this Cartesian against the provided Cartesian componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Cartesian2} [right] The right hand side Cartesian.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nCartesian2.prototype.equalsEpsilon = function (\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return Cartesian2.equalsEpsilon(\n this,\n right,\n relativeEpsilon,\n absoluteEpsilon\n );\n};\n\n/**\n * Creates a string representing this Cartesian in the format '(x, y)'.\n *\n * @returns {string} A string representing the provided Cartesian in the format '(x, y)'.\n */\nCartesian2.prototype.toString = function () {\n return `(${this.x}, ${this.y})`;\n};\nexport default Cartesian2;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst scaleToGeodeticSurfaceIntersection = new Cartesian3();\nconst scaleToGeodeticSurfaceGradient = new Cartesian3();\n\n/**\n * Scales the provided Cartesian position along the geodetic surface normal\n * so that it is on the surface of this ellipsoid. If the position is\n * at the center of the ellipsoid, this function returns undefined.\n *\n * @param {Cartesian3} cartesian The Cartesian position to scale.\n * @param {Cartesian3} oneOverRadii One over radii of the ellipsoid.\n * @param {Cartesian3} oneOverRadiiSquared One over radii squared of the ellipsoid.\n * @param {number} centerToleranceSquared Tolerance for closeness to the center.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.\n *\n * @function scaleToGeodeticSurface\n *\n * @private\n */\nfunction scaleToGeodeticSurface(\n cartesian,\n oneOverRadii,\n oneOverRadiiSquared,\n centerToleranceSquared,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cartesian)) {\n throw new DeveloperError(\"cartesian is required.\");\n }\n if (!defined(oneOverRadii)) {\n throw new DeveloperError(\"oneOverRadii is required.\");\n }\n if (!defined(oneOverRadiiSquared)) {\n throw new DeveloperError(\"oneOverRadiiSquared is required.\");\n }\n if (!defined(centerToleranceSquared)) {\n throw new DeveloperError(\"centerToleranceSquared is required.\");\n }\n //>>includeEnd('debug');\n\n const positionX = cartesian.x;\n const positionY = cartesian.y;\n const positionZ = cartesian.z;\n\n const oneOverRadiiX = oneOverRadii.x;\n const oneOverRadiiY = oneOverRadii.y;\n const oneOverRadiiZ = oneOverRadii.z;\n\n const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;\n const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;\n const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;\n\n // Compute the squared ellipsoid norm.\n const squaredNorm = x2 + y2 + z2;\n const ratio = Math.sqrt(1.0 / squaredNorm);\n\n // As an initial approximation, assume that the radial intersection is the projection point.\n const intersection = Cartesian3.multiplyByScalar(\n cartesian,\n ratio,\n scaleToGeodeticSurfaceIntersection\n );\n\n // If the position is near the center, the iteration will not converge.\n if (squaredNorm < centerToleranceSquared) {\n return !isFinite(ratio)\n ? undefined\n : Cartesian3.clone(intersection, result);\n }\n\n const oneOverRadiiSquaredX = oneOverRadiiSquared.x;\n const oneOverRadiiSquaredY = oneOverRadiiSquared.y;\n const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;\n\n // Use the gradient at the intersection point in place of the true unit normal.\n // The difference in magnitude will be absorbed in the multiplier.\n const gradient = scaleToGeodeticSurfaceGradient;\n gradient.x = intersection.x * oneOverRadiiSquaredX * 2.0;\n gradient.y = intersection.y * oneOverRadiiSquaredY * 2.0;\n gradient.z = intersection.z * oneOverRadiiSquaredZ * 2.0;\n\n // Compute the initial guess at the normal vector multiplier, lambda.\n let lambda =\n ((1.0 - ratio) * Cartesian3.magnitude(cartesian)) /\n (0.5 * Cartesian3.magnitude(gradient));\n let correction = 0.0;\n\n let func;\n let denominator;\n let xMultiplier;\n let yMultiplier;\n let zMultiplier;\n let xMultiplier2;\n let yMultiplier2;\n let zMultiplier2;\n let xMultiplier3;\n let yMultiplier3;\n let zMultiplier3;\n\n do {\n lambda -= correction;\n\n xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);\n yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);\n zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);\n\n xMultiplier2 = xMultiplier * xMultiplier;\n yMultiplier2 = yMultiplier * yMultiplier;\n zMultiplier2 = zMultiplier * zMultiplier;\n\n xMultiplier3 = xMultiplier2 * xMultiplier;\n yMultiplier3 = yMultiplier2 * yMultiplier;\n zMultiplier3 = zMultiplier2 * zMultiplier;\n\n func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;\n\n // \"denominator\" here refers to the use of this expression in the velocity and acceleration\n // computations in the sections to follow.\n denominator =\n x2 * xMultiplier3 * oneOverRadiiSquaredX +\n y2 * yMultiplier3 * oneOverRadiiSquaredY +\n z2 * zMultiplier3 * oneOverRadiiSquaredZ;\n\n const derivative = -2.0 * denominator;\n\n correction = func / derivative;\n } while (Math.abs(func) > CesiumMath.EPSILON12);\n\n if (!defined(result)) {\n return new Cartesian3(\n positionX * xMultiplier,\n positionY * yMultiplier,\n positionZ * zMultiplier\n );\n }\n result.x = positionX * xMultiplier;\n result.y = positionY * yMultiplier;\n result.z = positionZ * zMultiplier;\n return result;\n}\nexport default scaleToGeodeticSurface;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\nimport scaleToGeodeticSurface from \"./scaleToGeodeticSurface.js\";\n\n/**\n * A position defined by longitude, latitude, and height.\n * @alias Cartographic\n * @constructor\n *\n * @param {number} [longitude=0.0] The longitude, in radians.\n * @param {number} [latitude=0.0] The latitude, in radians.\n * @param {number} [height=0.0] The height, in meters, above the ellipsoid.\n *\n * @see Ellipsoid\n */\nfunction Cartographic(longitude, latitude, height) {\n /**\n * The longitude, in radians.\n * @type {number}\n * @default 0.0\n */\n this.longitude = defaultValue(longitude, 0.0);\n\n /**\n * The latitude, in radians.\n * @type {number}\n * @default 0.0\n */\n this.latitude = defaultValue(latitude, 0.0);\n\n /**\n * The height, in meters, above the ellipsoid.\n * @type {number}\n * @default 0.0\n */\n this.height = defaultValue(height, 0.0);\n}\n\n/**\n * Creates a new Cartographic instance from longitude and latitude\n * specified in radians.\n *\n * @param {number} longitude The longitude, in radians.\n * @param {number} latitude The latitude, in radians.\n * @param {number} [height=0.0] The height, in meters, above the ellipsoid.\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\n */\nCartographic.fromRadians = function (longitude, latitude, height, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"longitude\", longitude);\n Check.typeOf.number(\"latitude\", latitude);\n //>>includeEnd('debug');\n\n height = defaultValue(height, 0.0);\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\n\n/**\n * Creates a new Cartographic instance from longitude and latitude\n * specified in degrees. The values in the resulting object will\n * be in radians.\n *\n * @param {number} longitude The longitude, in degrees.\n * @param {number} latitude The latitude, in degrees.\n * @param {number} [height=0.0] The height, in meters, above the ellipsoid.\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\n */\nCartographic.fromDegrees = function (longitude, latitude, height, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"longitude\", longitude);\n Check.typeOf.number(\"latitude\", latitude);\n //>>includeEnd('debug');\n longitude = CesiumMath.toRadians(longitude);\n latitude = CesiumMath.toRadians(latitude);\n\n return Cartographic.fromRadians(longitude, latitude, height, result);\n};\n\nconst cartesianToCartographicN = new Cartesian3();\nconst cartesianToCartographicP = new Cartesian3();\nconst cartesianToCartographicH = new Cartesian3();\nconst wgs84OneOverRadii = new Cartesian3(\n 1.0 / 6378137.0,\n 1.0 / 6378137.0,\n 1.0 / 6356752.3142451793\n);\nconst wgs84OneOverRadiiSquared = new Cartesian3(\n 1.0 / (6378137.0 * 6378137.0),\n 1.0 / (6378137.0 * 6378137.0),\n 1.0 / (6356752.3142451793 * 6356752.3142451793)\n);\nconst wgs84CenterToleranceSquared = CesiumMath.EPSILON1;\n\n/**\n * Creates a new Cartographic instance from a Cartesian position. The values in the\n * resulting object will be in radians.\n *\n * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.\n */\nCartographic.fromCartesian = function (cartesian, ellipsoid, result) {\n const oneOverRadii = defined(ellipsoid)\n ? ellipsoid.oneOverRadii\n : wgs84OneOverRadii;\n const oneOverRadiiSquared = defined(ellipsoid)\n ? ellipsoid.oneOverRadiiSquared\n : wgs84OneOverRadiiSquared;\n const centerToleranceSquared = defined(ellipsoid)\n ? ellipsoid._centerToleranceSquared\n : wgs84CenterToleranceSquared;\n\n //`cartesian is required.` is thrown from scaleToGeodeticSurface\n const p = scaleToGeodeticSurface(\n cartesian,\n oneOverRadii,\n oneOverRadiiSquared,\n centerToleranceSquared,\n cartesianToCartographicP\n );\n\n if (!defined(p)) {\n return undefined;\n }\n\n let n = Cartesian3.multiplyComponents(\n p,\n oneOverRadiiSquared,\n cartesianToCartographicN\n );\n n = Cartesian3.normalize(n, n);\n\n const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);\n\n const longitude = Math.atan2(n.y, n.x);\n const latitude = Math.asin(n.z);\n const height =\n CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\n\n/**\n * Creates a new Cartesian3 instance from a Cartographic input. The values in the inputted\n * object should be in radians.\n *\n * @param {Cartographic} cartographic Input to be converted into a Cartesian3 output.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The position\n */\nCartographic.toCartesian = function (cartographic, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartographic\", cartographic);\n //>>includeEnd('debug');\n\n return Cartesian3.fromRadians(\n cartographic.longitude,\n cartographic.latitude,\n cartographic.height,\n ellipsoid,\n result\n );\n};\n\n/**\n * Duplicates a Cartographic instance.\n *\n * @param {Cartographic} cartographic The cartographic to duplicate.\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided. (Returns undefined if cartographic is undefined)\n */\nCartographic.clone = function (cartographic, result) {\n if (!defined(cartographic)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Cartographic(\n cartographic.longitude,\n cartographic.latitude,\n cartographic.height\n );\n }\n result.longitude = cartographic.longitude;\n result.latitude = cartographic.latitude;\n result.height = cartographic.height;\n return result;\n};\n\n/**\n * Compares the provided cartographics componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartographic} [left] The first cartographic.\n * @param {Cartographic} [right] The second cartographic.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCartographic.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.longitude === right.longitude &&\n left.latitude === right.latitude &&\n left.height === right.height)\n );\n};\n\n/**\n * Compares the provided cartographics componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Cartographic} [left] The first cartographic.\n * @param {Cartographic} [right] The second cartographic.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nCartographic.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left.longitude - right.longitude) <= epsilon &&\n Math.abs(left.latitude - right.latitude) <= epsilon &&\n Math.abs(left.height - right.height) <= epsilon)\n );\n};\n\n/**\n * An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).\n *\n * @type {Cartographic}\n * @constant\n */\nCartographic.ZERO = Object.freeze(new Cartographic(0.0, 0.0, 0.0));\n\n/**\n * Duplicates this instance.\n *\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.\n */\nCartographic.prototype.clone = function (result) {\n return Cartographic.clone(this, result);\n};\n\n/**\n * Compares the provided against this cartographic componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Cartographic} [right] The second cartographic.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCartographic.prototype.equals = function (right) {\n return Cartographic.equals(this, right);\n};\n\n/**\n * Compares the provided against this cartographic componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Cartographic} [right] The second cartographic.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nCartographic.prototype.equalsEpsilon = function (right, epsilon) {\n return Cartographic.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Creates a string representing this cartographic in the format '(longitude, latitude, height)'.\n *\n * @returns {string} A string representing the provided cartographic in the format '(longitude, latitude, height)'.\n */\nCartographic.prototype.toString = function () {\n return `(${this.longitude}, ${this.latitude}, ${this.height})`;\n};\nexport default Cartographic;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport scaleToGeodeticSurface from \"./scaleToGeodeticSurface.js\";\n\nfunction initialize(ellipsoid, x, y, z) {\n x = defaultValue(x, 0.0);\n y = defaultValue(y, 0.0);\n z = defaultValue(z, 0.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"x\", x, 0.0);\n Check.typeOf.number.greaterThanOrEquals(\"y\", y, 0.0);\n Check.typeOf.number.greaterThanOrEquals(\"z\", z, 0.0);\n //>>includeEnd('debug');\n\n ellipsoid._radii = new Cartesian3(x, y, z);\n\n ellipsoid._radiiSquared = new Cartesian3(x * x, y * y, z * z);\n\n ellipsoid._radiiToTheFourth = new Cartesian3(\n x * x * x * x,\n y * y * y * y,\n z * z * z * z\n );\n\n ellipsoid._oneOverRadii = new Cartesian3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n ellipsoid._oneOverRadiiSquared = new Cartesian3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n ellipsoid._minimumRadius = Math.min(x, y, z);\n\n ellipsoid._maximumRadius = Math.max(x, y, z);\n\n ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;\n\n if (ellipsoid._radiiSquared.z !== 0) {\n ellipsoid._squaredXOverSquaredZ =\n ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;\n }\n}\n\n/**\n * A quadratic surface defined in Cartesian coordinates by the equation\n * (x / a)^2 + (y / b)^2 + (z / c)^2 = 1. Primarily used\n * by Cesium to represent the shape of planetary bodies.\n *\n * Rather than constructing this object directly, one of the provided\n * constants is normally used.\n * @alias Ellipsoid\n * @constructor\n *\n * @param {number} [x=0] The radius in the x direction.\n * @param {number} [y=0] The radius in the y direction.\n * @param {number} [z=0] The radius in the z direction.\n *\n * @exception {DeveloperError} All radii components must be greater than or equal to zero.\n *\n * @see Ellipsoid.fromCartesian3\n * @see Ellipsoid.WGS84\n * @see Ellipsoid.UNIT_SPHERE\n */\nfunction Ellipsoid(x, y, z) {\n this._radii = undefined;\n this._radiiSquared = undefined;\n this._radiiToTheFourth = undefined;\n this._oneOverRadii = undefined;\n this._oneOverRadiiSquared = undefined;\n this._minimumRadius = undefined;\n this._maximumRadius = undefined;\n this._centerToleranceSquared = undefined;\n this._squaredXOverSquaredZ = undefined;\n\n initialize(this, x, y, z);\n}\n\nObject.defineProperties(Ellipsoid.prototype, {\n /**\n * Gets the radii of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {Cartesian3}\n * @readonly\n */\n radii: {\n get: function () {\n return this._radii;\n },\n },\n /**\n * Gets the squared radii of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {Cartesian3}\n * @readonly\n */\n radiiSquared: {\n get: function () {\n return this._radiiSquared;\n },\n },\n /**\n * Gets the radii of the ellipsoid raise to the fourth power.\n * @memberof Ellipsoid.prototype\n * @type {Cartesian3}\n * @readonly\n */\n radiiToTheFourth: {\n get: function () {\n return this._radiiToTheFourth;\n },\n },\n /**\n * Gets one over the radii of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {Cartesian3}\n * @readonly\n */\n oneOverRadii: {\n get: function () {\n return this._oneOverRadii;\n },\n },\n /**\n * Gets one over the squared radii of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {Cartesian3}\n * @readonly\n */\n oneOverRadiiSquared: {\n get: function () {\n return this._oneOverRadiiSquared;\n },\n },\n /**\n * Gets the minimum radius of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {number}\n * @readonly\n */\n minimumRadius: {\n get: function () {\n return this._minimumRadius;\n },\n },\n /**\n * Gets the maximum radius of the ellipsoid.\n * @memberof Ellipsoid.prototype\n * @type {number}\n * @readonly\n */\n maximumRadius: {\n get: function () {\n return this._maximumRadius;\n },\n },\n});\n\n/**\n * Duplicates an Ellipsoid instance.\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\n * instance should be created.\n * @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)\n */\nEllipsoid.clone = function (ellipsoid, result) {\n if (!defined(ellipsoid)) {\n return undefined;\n }\n const radii = ellipsoid._radii;\n\n if (!defined(result)) {\n return new Ellipsoid(radii.x, radii.y, radii.z);\n }\n\n Cartesian3.clone(radii, result._radii);\n Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);\n Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);\n Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);\n Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);\n result._minimumRadius = ellipsoid._minimumRadius;\n result._maximumRadius = ellipsoid._maximumRadius;\n result._centerToleranceSquared = ellipsoid._centerToleranceSquared;\n\n return result;\n};\n\n/**\n * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n *\n * @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\n * instance should be created.\n * @returns {Ellipsoid} A new Ellipsoid instance.\n *\n * @exception {DeveloperError} All radii components must be greater than or equal to zero.\n *\n * @see Ellipsoid.WGS84\n * @see Ellipsoid.UNIT_SPHERE\n */\nEllipsoid.fromCartesian3 = function (cartesian, result) {\n if (!defined(result)) {\n result = new Ellipsoid();\n }\n\n if (!defined(cartesian)) {\n return result;\n }\n\n initialize(result, cartesian.x, cartesian.y, cartesian.z);\n return result;\n};\n\n/**\n * An Ellipsoid instance initialized to the WGS84 standard.\n *\n * @type {Ellipsoid}\n * @constant\n */\nEllipsoid.WGS84 = Object.freeze(\n new Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793)\n);\n\n/**\n * An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).\n *\n * @type {Ellipsoid}\n * @constant\n */\nEllipsoid.UNIT_SPHERE = Object.freeze(new Ellipsoid(1.0, 1.0, 1.0));\n\n/**\n * An Ellipsoid instance initialized to a sphere with the lunar radius.\n *\n * @type {Ellipsoid}\n * @constant\n */\nEllipsoid.MOON = Object.freeze(\n new Ellipsoid(\n CesiumMath.LUNAR_RADIUS,\n CesiumMath.LUNAR_RADIUS,\n CesiumMath.LUNAR_RADIUS\n )\n);\n\n/**\n * Duplicates an Ellipsoid instance.\n *\n * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new\n * instance should be created.\n * @returns {Ellipsoid} The cloned Ellipsoid.\n */\nEllipsoid.prototype.clone = function (result) {\n return Ellipsoid.clone(this, result);\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nEllipsoid.packedLength = Cartesian3.packedLength;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Ellipsoid} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nEllipsoid.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._radii, array, startingIndex);\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Ellipsoid} [result] The object into which to store the result.\n * @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.\n */\nEllipsoid.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const radii = Cartesian3.unpack(array, startingIndex);\n return Ellipsoid.fromCartesian3(radii, result);\n};\n\n/**\n * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.\n * @function\n *\n * @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\n */\nEllipsoid.prototype.geocentricSurfaceNormal = Cartesian3.normalize;\n\n/**\n * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n *\n * @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\n */\nEllipsoid.prototype.geodeticSurfaceNormalCartographic = function (\n cartographic,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartographic\", cartographic);\n //>>includeEnd('debug');\n\n const longitude = cartographic.longitude;\n const latitude = cartographic.latitude;\n const cosLatitude = Math.cos(latitude);\n\n const x = cosLatitude * Math.cos(longitude);\n const y = cosLatitude * Math.sin(longitude);\n const z = Math.sin(latitude);\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n result.x = x;\n result.y = y;\n result.z = z;\n return Cartesian3.normalize(result, result);\n};\n\n/**\n * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n *\n * @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided, or undefined if a normal cannot be found.\n */\nEllipsoid.prototype.geodeticSurfaceNormal = function (cartesian, result) {\n if (\n Cartesian3.equalsEpsilon(cartesian, Cartesian3.ZERO, CesiumMath.EPSILON14)\n ) {\n return undefined;\n }\n if (!defined(result)) {\n result = new Cartesian3();\n }\n result = Cartesian3.multiplyComponents(\n cartesian,\n this._oneOverRadiiSquared,\n result\n );\n return Cartesian3.normalize(result, result);\n};\n\nconst cartographicToCartesianNormal = new Cartesian3();\nconst cartographicToCartesianK = new Cartesian3();\n\n/**\n * Converts the provided cartographic to Cartesian representation.\n *\n * @param {Cartographic} cartographic The cartographic position.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\n *\n * @example\n * //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.\n * const position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);\n * const cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);\n */\nEllipsoid.prototype.cartographicToCartesian = function (cartographic, result) {\n //`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.\n const n = cartographicToCartesianNormal;\n const k = cartographicToCartesianK;\n this.geodeticSurfaceNormalCartographic(cartographic, n);\n Cartesian3.multiplyComponents(this._radiiSquared, n, k);\n const gamma = Math.sqrt(Cartesian3.dot(n, k));\n Cartesian3.divideByScalar(k, gamma, k);\n Cartesian3.multiplyByScalar(n, cartographic.height, n);\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n return Cartesian3.add(k, n, result);\n};\n\n/**\n * Converts the provided array of cartographics to an array of Cartesians.\n *\n * @param {Cartographic[]} cartographics An array of cartographic positions.\n * @param {Cartesian3[]} [result] The object onto which to store the result.\n * @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.\n *\n * @example\n * //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.\n * const positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),\n * new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),\n * new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];\n * const cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);\n */\nEllipsoid.prototype.cartographicArrayToCartesianArray = function (\n cartographics,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartographics\", cartographics);\n //>>includeEnd('debug')\n\n const length = cartographics.length;\n if (!defined(result)) {\n result = new Array(length);\n } else {\n result.length = length;\n }\n for (let i = 0; i < length; i++) {\n result[i] = this.cartographicToCartesian(cartographics[i], result[i]);\n }\n return result;\n};\n\nconst cartesianToCartographicN = new Cartesian3();\nconst cartesianToCartographicP = new Cartesian3();\nconst cartesianToCartographicH = new Cartesian3();\n\n/**\n * Converts the provided cartesian to cartographic representation.\n * The cartesian is undefined at the center of the ellipsoid.\n *\n * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.\n *\n * @example\n * //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.\n * const position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);\n * const cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);\n */\nEllipsoid.prototype.cartesianToCartographic = function (cartesian, result) {\n //`cartesian is required.` is thrown from scaleToGeodeticSurface\n const p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);\n\n if (!defined(p)) {\n return undefined;\n }\n\n const n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);\n const h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);\n\n const longitude = Math.atan2(n.y, n.x);\n const latitude = Math.asin(n.z);\n const height =\n CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\n\n/**\n * Converts the provided array of cartesians to an array of cartographics.\n *\n * @param {Cartesian3[]} cartesians An array of Cartesian positions.\n * @param {Cartographic[]} [result] The object onto which to store the result.\n * @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.\n *\n * @example\n * //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.\n * const positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),\n * new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),\n * new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]\n * const cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);\n */\nEllipsoid.prototype.cartesianArrayToCartographicArray = function (\n cartesians,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n\n const length = cartesians.length;\n if (!defined(result)) {\n result = new Array(length);\n } else {\n result.length = length;\n }\n for (let i = 0; i < length; ++i) {\n result[i] = this.cartesianToCartographic(cartesians[i], result[i]);\n }\n return result;\n};\n\n/**\n * Scales the provided Cartesian position along the geodetic surface normal\n * so that it is on the surface of this ellipsoid. If the position is\n * at the center of the ellipsoid, this function returns undefined.\n *\n * @param {Cartesian3} cartesian The Cartesian position to scale.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.\n */\nEllipsoid.prototype.scaleToGeodeticSurface = function (cartesian, result) {\n return scaleToGeodeticSurface(\n cartesian,\n this._oneOverRadii,\n this._oneOverRadiiSquared,\n this._centerToleranceSquared,\n result\n );\n};\n\n/**\n * Scales the provided Cartesian position along the geocentric surface normal\n * so that it is on the surface of this ellipsoid.\n *\n * @param {Cartesian3} cartesian The Cartesian position to scale.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\n */\nEllipsoid.prototype.scaleToGeocentricSurface = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const positionX = cartesian.x;\n const positionY = cartesian.y;\n const positionZ = cartesian.z;\n const oneOverRadiiSquared = this._oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return Cartesian3.multiplyByScalar(cartesian, beta, result);\n};\n\n/**\n * Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n * its components by the result of {@link Ellipsoid#oneOverRadii}.\n *\n * @param {Cartesian3} position The position to transform.\n * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and\n * return a new instance.\n * @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the\n * one passed as the result parameter if it is not undefined, or a new instance of it is.\n */\nEllipsoid.prototype.transformPositionToScaledSpace = function (\n position,\n result\n) {\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n return Cartesian3.multiplyComponents(position, this._oneOverRadii, result);\n};\n\n/**\n * Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n * its components by the result of {@link Ellipsoid#radii}.\n *\n * @param {Cartesian3} position The position to transform.\n * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and\n * return a new instance.\n * @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the\n * one passed as the result parameter if it is not undefined, or a new instance of it is.\n */\nEllipsoid.prototype.transformPositionFromScaledSpace = function (\n position,\n result\n) {\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n return Cartesian3.multiplyComponents(position, this._radii, result);\n};\n\n/**\n * Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Ellipsoid} [right] The other Ellipsoid.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nEllipsoid.prototype.equals = function (right) {\n return (\n this === right ||\n (defined(right) && Cartesian3.equals(this._radii, right._radii))\n );\n};\n\n/**\n * Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n *\n * @returns {string} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n */\nEllipsoid.prototype.toString = function () {\n return this._radii.toString();\n};\n\n/**\n * Computes a point which is the intersection of the surface normal with the z-axis.\n *\n * @param {Cartesian3} position the position. must be on the surface of the ellipsoid.\n * @param {number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.\n * In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.\n * In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).\n * Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2\n * @param {Cartesian3} [result] The cartesian to which to copy the result, or undefined to create and\n * return a new instance.\n * @returns {Cartesian3 | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise\n *\n * @exception {DeveloperError} position is required.\n * @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).\n * @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.\n */\nEllipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function (\n position,\n buffer,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"position\", position);\n\n if (\n !CesiumMath.equalsEpsilon(\n this._radii.x,\n this._radii.y,\n CesiumMath.EPSILON15\n )\n ) {\n throw new DeveloperError(\n \"Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\"\n );\n }\n\n Check.typeOf.number.greaterThan(\"Ellipsoid.radii.z\", this._radii.z, 0);\n //>>includeEnd('debug');\n\n buffer = defaultValue(buffer, 0.0);\n\n const squaredXOverSquaredZ = this._squaredXOverSquaredZ;\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n result.x = 0.0;\n result.y = 0.0;\n result.z = position.z * (1 - squaredXOverSquaredZ);\n\n if (Math.abs(result.z) >= this._radii.z - buffer) {\n return undefined;\n }\n\n return result;\n};\n\nconst abscissas = [\n 0.14887433898163,\n 0.43339539412925,\n 0.67940956829902,\n 0.86506336668898,\n 0.97390652851717,\n 0.0,\n];\nconst weights = [\n 0.29552422471475,\n 0.26926671930999,\n 0.21908636251598,\n 0.14945134915058,\n 0.066671344308684,\n 0.0,\n];\n\n/**\n * Compute the 10th order Gauss-Legendre Quadrature of the given definite integral.\n *\n * @param {number} a The lower bound for the integration.\n * @param {number} b The upper bound for the integration.\n * @param {Ellipsoid~RealValuedScalarFunction} func The function to integrate.\n * @returns {number} The value of the integral of the given function over the given domain.\n *\n * @private\n */\nfunction gaussLegendreQuadrature(a, b, func) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"a\", a);\n Check.typeOf.number(\"b\", b);\n Check.typeOf.func(\"func\", func);\n //>>includeEnd('debug');\n\n // The range is half of the normal range since the five weights add to one (ten weights add to two).\n // The values of the abscissas are multiplied by two to account for this.\n const xMean = 0.5 * (b + a);\n const xRange = 0.5 * (b - a);\n\n let sum = 0.0;\n for (let i = 0; i < 5; i++) {\n const dx = xRange * abscissas[i];\n sum += weights[i] * (func(xMean + dx) + func(xMean - dx));\n }\n\n // Scale the sum to the range of x.\n sum *= xRange;\n return sum;\n}\n\n/**\n * A real valued scalar function.\n * @callback Ellipsoid~RealValuedScalarFunction\n *\n * @param {number} x The value used to evaluate the function.\n * @returns {number} The value of the function at x.\n *\n * @private\n */\n\n/**\n * Computes an approximation of the surface area of a rectangle on the surface of an ellipsoid using\n * Gauss-Legendre 10th order quadrature.\n *\n * @param {Rectangle} rectangle The rectangle used for computing the surface area.\n * @returns {number} The approximate area of the rectangle on the surface of this ellipsoid.\n */\nEllipsoid.prototype.surfaceArea = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n const minLongitude = rectangle.west;\n let maxLongitude = rectangle.east;\n const minLatitude = rectangle.south;\n const maxLatitude = rectangle.north;\n\n while (maxLongitude < minLongitude) {\n maxLongitude += CesiumMath.TWO_PI;\n }\n\n const radiiSquared = this._radiiSquared;\n const a2 = radiiSquared.x;\n const b2 = radiiSquared.y;\n const c2 = radiiSquared.z;\n const a2b2 = a2 * b2;\n return gaussLegendreQuadrature(minLatitude, maxLatitude, function (lat) {\n // phi represents the angle measured from the north pole\n // sin(phi) = sin(pi / 2 - lat) = cos(lat), cos(phi) is similar\n const sinPhi = Math.cos(lat);\n const cosPhi = Math.sin(lat);\n return (\n Math.cos(lat) *\n gaussLegendreQuadrature(minLongitude, maxLongitude, function (lon) {\n const cosTheta = Math.cos(lon);\n const sinTheta = Math.sin(lon);\n return Math.sqrt(\n a2b2 * cosPhi * cosPhi +\n c2 *\n (b2 * cosTheta * cosTheta + a2 * sinTheta * sinTheta) *\n sinPhi *\n sinPhi\n );\n })\n );\n });\n};\n\nexport default Ellipsoid;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\n\n/**\n * A simple map projection where longitude and latitude are linearly mapped to X and Y by multiplying\n * them by the {@link Ellipsoid#maximumRadius}. This projection\n * is commonly known as geographic, equirectangular, equidistant cylindrical, or plate carr\u00E9e. It\n * is also known as EPSG:4326.\n *\n * @alias GeographicProjection\n * @constructor\n *\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n *\n * @see WebMercatorProjection\n */\nfunction GeographicProjection(ellipsoid) {\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._semimajorAxis = this._ellipsoid.maximumRadius;\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\n}\n\nObject.defineProperties(GeographicProjection.prototype, {\n /**\n * Gets the {@link Ellipsoid}.\n *\n * @memberof GeographicProjection.prototype\n *\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n});\n\n/**\n * Projects a set of {@link Cartographic} coordinates, in radians, to map coordinates, in meters.\n * X and Y are the longitude and latitude, respectively, multiplied by the maximum radius of the\n * ellipsoid. Z is the unmodified height.\n *\n * @param {Cartographic} cartographic The coordinates to project.\n * @param {Cartesian3} [result] An instance into which to copy the result. If this parameter is\n * undefined, a new instance is created and returned.\n * @returns {Cartesian3} The projected coordinates. If the result parameter is not undefined, the\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\n * created and returned.\n */\nGeographicProjection.prototype.project = function (cartographic, result) {\n // Actually this is the special case of equidistant cylindrical called the plate carree\n const semimajorAxis = this._semimajorAxis;\n const x = cartographic.longitude * semimajorAxis;\n const y = cartographic.latitude * semimajorAxis;\n const z = cartographic.height;\n\n if (!defined(result)) {\n return new Cartesian3(x, y, z);\n }\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Unprojects a set of projected {@link Cartesian3} coordinates, in meters, to {@link Cartographic}\n * coordinates, in radians. Longitude and Latitude are the X and Y coordinates, respectively,\n * divided by the maximum radius of the ellipsoid. Height is the unmodified Z coordinate.\n *\n * @param {Cartesian3} cartesian The Cartesian position to unproject with height (z) in meters.\n * @param {Cartographic} [result] An instance into which to copy the result. If this parameter is\n * undefined, a new instance is created and returned.\n * @returns {Cartographic} The unprojected coordinates. If the result parameter is not undefined, the\n * coordinates are copied there and that instance is returned. Otherwise, a new instance is\n * created and returned.\n */\nGeographicProjection.prototype.unproject = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cartesian)) {\n throw new DeveloperError(\"cartesian is required\");\n }\n //>>includeEnd('debug');\n\n const oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;\n const longitude = cartesian.x * oneOverEarthSemimajorAxis;\n const latitude = cartesian.y * oneOverEarthSemimajorAxis;\n const height = cartesian.z;\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\nexport default GeographicProjection;\n", "/**\n * This enumerated type is used in determining where, relative to the frustum, an\n * object is located. The object can either be fully contained within the frustum (INSIDE),\n * partially inside the frustum and partially outside (INTERSECTING), or somewhere entirely\n * outside of the frustum's 6 planes (OUTSIDE).\n *\n * @enum {number}\n */\nconst Intersect = {\n /**\n * Represents that an object is not contained within the frustum.\n *\n * @type {number}\n * @constant\n */\n OUTSIDE: -1,\n\n /**\n * Represents that an object intersects one of the frustum's planes.\n *\n * @type {number}\n * @constant\n */\n INTERSECTING: 0,\n\n /**\n * Represents that an object is fully within the frustum.\n *\n * @type {number}\n * @constant\n */\n INSIDE: 1,\n};\nexport default Object.freeze(Intersect);\n", "import Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A two dimensional region specified as longitude and latitude coordinates.\n *\n * @alias Rectangle\n * @constructor\n *\n * @param {number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].\n * @param {number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].\n * @param {number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].\n * @param {number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].\n *\n * @see Packable\n */\nfunction Rectangle(west, south, east, north) {\n /**\n * The westernmost longitude in radians in the range [-Pi, Pi].\n *\n * @type {number}\n * @default 0.0\n */\n this.west = defaultValue(west, 0.0);\n\n /**\n * The southernmost latitude in radians in the range [-Pi/2, Pi/2].\n *\n * @type {number}\n * @default 0.0\n */\n this.south = defaultValue(south, 0.0);\n\n /**\n * The easternmost longitude in radians in the range [-Pi, Pi].\n *\n * @type {number}\n * @default 0.0\n */\n this.east = defaultValue(east, 0.0);\n\n /**\n * The northernmost latitude in radians in the range [-Pi/2, Pi/2].\n *\n * @type {number}\n * @default 0.0\n */\n this.north = defaultValue(north, 0.0);\n}\n\nObject.defineProperties(Rectangle.prototype, {\n /**\n * Gets the width of the rectangle in radians.\n * @memberof Rectangle.prototype\n * @type {number}\n * @readonly\n */\n width: {\n get: function () {\n return Rectangle.computeWidth(this);\n },\n },\n\n /**\n * Gets the height of the rectangle in radians.\n * @memberof Rectangle.prototype\n * @type {number}\n * @readonly\n */\n height: {\n get: function () {\n return Rectangle.computeHeight(this);\n },\n },\n});\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nRectangle.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Rectangle} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nRectangle.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.west;\n array[startingIndex++] = value.south;\n array[startingIndex++] = value.east;\n array[startingIndex] = value.north;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Rectangle} [result] The object into which to store the result.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.\n */\nRectangle.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Rectangle();\n }\n\n result.west = array[startingIndex++];\n result.south = array[startingIndex++];\n result.east = array[startingIndex++];\n result.north = array[startingIndex];\n return result;\n};\n\n/**\n * Computes the width of a rectangle in radians.\n * @param {Rectangle} rectangle The rectangle to compute the width of.\n * @returns {number} The width.\n */\nRectangle.computeWidth = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n let east = rectangle.east;\n const west = rectangle.west;\n if (east < west) {\n east += CesiumMath.TWO_PI;\n }\n return east - west;\n};\n\n/**\n * Computes the height of a rectangle in radians.\n * @param {Rectangle} rectangle The rectangle to compute the height of.\n * @returns {number} The height.\n */\nRectangle.computeHeight = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n return rectangle.north - rectangle.south;\n};\n\n/**\n * Creates a rectangle given the boundary longitude and latitude in degrees.\n *\n * @param {number} [west=0.0] The westernmost longitude in degrees in the range [-180.0, 180.0].\n * @param {number} [south=0.0] The southernmost latitude in degrees in the range [-90.0, 90.0].\n * @param {number} [east=0.0] The easternmost longitude in degrees in the range [-180.0, 180.0].\n * @param {number} [north=0.0] The northernmost latitude in degrees in the range [-90.0, 90.0].\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n *\n * @example\n * const rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0);\n */\nRectangle.fromDegrees = function (west, south, east, north, result) {\n west = CesiumMath.toRadians(defaultValue(west, 0.0));\n south = CesiumMath.toRadians(defaultValue(south, 0.0));\n east = CesiumMath.toRadians(defaultValue(east, 0.0));\n north = CesiumMath.toRadians(defaultValue(north, 0.0));\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n\n return result;\n};\n\n/**\n * Creates a rectangle given the boundary longitude and latitude in radians.\n *\n * @param {number} [west=0.0] The westernmost longitude in radians in the range [-Math.PI, Math.PI].\n * @param {number} [south=0.0] The southernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].\n * @param {number} [east=0.0] The easternmost longitude in radians in the range [-Math.PI, Math.PI].\n * @param {number} [north=0.0] The northernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n *\n * @example\n * const rectangle = Cesium.Rectangle.fromRadians(0.0, Math.PI/4, Math.PI/8, 3*Math.PI/4);\n */\nRectangle.fromRadians = function (west, south, east, north, result) {\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = defaultValue(west, 0.0);\n result.south = defaultValue(south, 0.0);\n result.east = defaultValue(east, 0.0);\n result.north = defaultValue(north, 0.0);\n\n return result;\n};\n\n/**\n * Creates the smallest possible Rectangle that encloses all positions in the provided array.\n *\n * @param {Cartographic[]} cartographics The list of Cartographic instances.\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n */\nRectangle.fromCartographicArray = function (cartographics, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartographics\", cartographics);\n //>>includeEnd('debug');\n\n let west = Number.MAX_VALUE;\n let east = -Number.MAX_VALUE;\n let westOverIDL = Number.MAX_VALUE;\n let eastOverIDL = -Number.MAX_VALUE;\n let south = Number.MAX_VALUE;\n let north = -Number.MAX_VALUE;\n\n for (let i = 0, len = cartographics.length; i < len; i++) {\n const position = cartographics[i];\n west = Math.min(west, position.longitude);\n east = Math.max(east, position.longitude);\n south = Math.min(south, position.latitude);\n north = Math.max(north, position.latitude);\n\n const lonAdjusted =\n position.longitude >= 0\n ? position.longitude\n : position.longitude + CesiumMath.TWO_PI;\n westOverIDL = Math.min(westOverIDL, lonAdjusted);\n eastOverIDL = Math.max(eastOverIDL, lonAdjusted);\n }\n\n if (east - west > eastOverIDL - westOverIDL) {\n west = westOverIDL;\n east = eastOverIDL;\n\n if (east > CesiumMath.PI) {\n east = east - CesiumMath.TWO_PI;\n }\n if (west > CesiumMath.PI) {\n west = west - CesiumMath.TWO_PI;\n }\n }\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Creates the smallest possible Rectangle that encloses all positions in the provided array.\n *\n * @param {Cartesian3[]} cartesians The list of Cartesian instances.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid the cartesians are on.\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n */\nRectangle.fromCartesianArray = function (cartesians, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n let west = Number.MAX_VALUE;\n let east = -Number.MAX_VALUE;\n let westOverIDL = Number.MAX_VALUE;\n let eastOverIDL = -Number.MAX_VALUE;\n let south = Number.MAX_VALUE;\n let north = -Number.MAX_VALUE;\n\n for (let i = 0, len = cartesians.length; i < len; i++) {\n const position = ellipsoid.cartesianToCartographic(cartesians[i]);\n west = Math.min(west, position.longitude);\n east = Math.max(east, position.longitude);\n south = Math.min(south, position.latitude);\n north = Math.max(north, position.latitude);\n\n const lonAdjusted =\n position.longitude >= 0\n ? position.longitude\n : position.longitude + CesiumMath.TWO_PI;\n westOverIDL = Math.min(westOverIDL, lonAdjusted);\n eastOverIDL = Math.max(eastOverIDL, lonAdjusted);\n }\n\n if (east - west > eastOverIDL - westOverIDL) {\n west = westOverIDL;\n east = eastOverIDL;\n\n if (east > CesiumMath.PI) {\n east = east - CesiumMath.TWO_PI;\n }\n if (west > CesiumMath.PI) {\n west = west - CesiumMath.TWO_PI;\n }\n }\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Duplicates a Rectangle.\n *\n * @param {Rectangle} rectangle The rectangle to clone.\n * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided. (Returns undefined if rectangle is undefined)\n */\nRectangle.clone = function (rectangle, result) {\n if (!defined(rectangle)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Rectangle(\n rectangle.west,\n rectangle.south,\n rectangle.east,\n rectangle.north\n );\n }\n\n result.west = rectangle.west;\n result.south = rectangle.south;\n result.east = rectangle.east;\n result.north = rectangle.north;\n return result;\n};\n\n/**\n * Compares the provided Rectangles componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {Rectangle} [left] The first Rectangle.\n * @param {Rectangle} [right] The second Rectangle.\n * @param {number} [absoluteEpsilon=0] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nRectangle.equalsEpsilon = function (left, right, absoluteEpsilon) {\n absoluteEpsilon = defaultValue(absoluteEpsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left.west - right.west) <= absoluteEpsilon &&\n Math.abs(left.south - right.south) <= absoluteEpsilon &&\n Math.abs(left.east - right.east) <= absoluteEpsilon &&\n Math.abs(left.north - right.north) <= absoluteEpsilon)\n );\n};\n\n/**\n * Duplicates this Rectangle.\n *\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n */\nRectangle.prototype.clone = function (result) {\n return Rectangle.clone(this, result);\n};\n\n/**\n * Compares the provided Rectangle with this Rectangle componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Rectangle} [other] The Rectangle to compare.\n * @returns {boolean} true if the Rectangles are equal, false otherwise.\n */\nRectangle.prototype.equals = function (other) {\n return Rectangle.equals(this, other);\n};\n\n/**\n * Compares the provided rectangles and returns true if they are equal,\n * false otherwise.\n *\n * @param {Rectangle} [left] The first Rectangle.\n * @param {Rectangle} [right] The second Rectangle.\n * @returns {boolean} true if left and right are equal; otherwise false.\n */\nRectangle.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.west === right.west &&\n left.south === right.south &&\n left.east === right.east &&\n left.north === right.north)\n );\n};\n\n/**\n * Compares the provided Rectangle with this Rectangle componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Rectangle} [other] The Rectangle to compare.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if the Rectangles are within the provided epsilon, false otherwise.\n */\nRectangle.prototype.equalsEpsilon = function (other, epsilon) {\n return Rectangle.equalsEpsilon(this, other, epsilon);\n};\n\n/**\n * Checks a Rectangle's properties and throws if they are not in valid ranges.\n *\n * @param {Rectangle} rectangle The rectangle to validate\n *\n * @exception {DeveloperError} north must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} south must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} east must be in the interval [-Pi, Pi].\n * @exception {DeveloperError} west must be in the interval [-Pi, Pi].\n */\nRectangle.validate = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n\n const north = rectangle.north;\n Check.typeOf.number.greaterThanOrEquals(\n \"north\",\n north,\n -CesiumMath.PI_OVER_TWO\n );\n Check.typeOf.number.lessThanOrEquals(\"north\", north, CesiumMath.PI_OVER_TWO);\n\n const south = rectangle.south;\n Check.typeOf.number.greaterThanOrEquals(\n \"south\",\n south,\n -CesiumMath.PI_OVER_TWO\n );\n Check.typeOf.number.lessThanOrEquals(\"south\", south, CesiumMath.PI_OVER_TWO);\n\n const west = rectangle.west;\n Check.typeOf.number.greaterThanOrEquals(\"west\", west, -Math.PI);\n Check.typeOf.number.lessThanOrEquals(\"west\", west, Math.PI);\n\n const east = rectangle.east;\n Check.typeOf.number.greaterThanOrEquals(\"east\", east, -Math.PI);\n Check.typeOf.number.lessThanOrEquals(\"east\", east, Math.PI);\n //>>includeEnd('debug');\n};\n\n/**\n * Computes the southwest corner of a rectangle.\n *\n * @param {Rectangle} rectangle The rectangle for which to find the corner\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\n */\nRectangle.southwest = function (rectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Cartographic(rectangle.west, rectangle.south);\n }\n result.longitude = rectangle.west;\n result.latitude = rectangle.south;\n result.height = 0.0;\n return result;\n};\n\n/**\n * Computes the northwest corner of a rectangle.\n *\n * @param {Rectangle} rectangle The rectangle for which to find the corner\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\n */\nRectangle.northwest = function (rectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Cartographic(rectangle.west, rectangle.north);\n }\n result.longitude = rectangle.west;\n result.latitude = rectangle.north;\n result.height = 0.0;\n return result;\n};\n\n/**\n * Computes the northeast corner of a rectangle.\n *\n * @param {Rectangle} rectangle The rectangle for which to find the corner\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\n */\nRectangle.northeast = function (rectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Cartographic(rectangle.east, rectangle.north);\n }\n result.longitude = rectangle.east;\n result.latitude = rectangle.north;\n result.height = 0.0;\n return result;\n};\n\n/**\n * Computes the southeast corner of a rectangle.\n *\n * @param {Rectangle} rectangle The rectangle for which to find the corner\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\n */\nRectangle.southeast = function (rectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Cartographic(rectangle.east, rectangle.south);\n }\n result.longitude = rectangle.east;\n result.latitude = rectangle.south;\n result.height = 0.0;\n return result;\n};\n\n/**\n * Computes the center of a rectangle.\n *\n * @param {Rectangle} rectangle The rectangle for which to find the center\n * @param {Cartographic} [result] The object onto which to store the result.\n * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.\n */\nRectangle.center = function (rectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n let east = rectangle.east;\n const west = rectangle.west;\n\n if (east < west) {\n east += CesiumMath.TWO_PI;\n }\n\n const longitude = CesiumMath.negativePiToPi((west + east) * 0.5);\n const latitude = (rectangle.south + rectangle.north) * 0.5;\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude);\n }\n\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = 0.0;\n return result;\n};\n\n/**\n * Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are\n * latitude and longitude in radians and produces a correct intersection, taking into account the fact that\n * the same angle can be represented with multiple values as well as the wrapping of longitude at the\n * anti-meridian. For a simple intersection that ignores these factors and can be used with projected\n * coordinates, see {@link Rectangle.simpleIntersection}.\n *\n * @param {Rectangle} rectangle On rectangle to find an intersection\n * @param {Rectangle} otherRectangle Another rectangle to find an intersection\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.\n */\nRectangle.intersection = function (rectangle, otherRectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\n //>>includeEnd('debug');\n\n let rectangleEast = rectangle.east;\n let rectangleWest = rectangle.west;\n\n let otherRectangleEast = otherRectangle.east;\n let otherRectangleWest = otherRectangle.west;\n\n if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {\n rectangleEast += CesiumMath.TWO_PI;\n } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {\n otherRectangleEast += CesiumMath.TWO_PI;\n }\n\n if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {\n otherRectangleWest += CesiumMath.TWO_PI;\n } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {\n rectangleWest += CesiumMath.TWO_PI;\n }\n\n const west = CesiumMath.negativePiToPi(\n Math.max(rectangleWest, otherRectangleWest)\n );\n const east = CesiumMath.negativePiToPi(\n Math.min(rectangleEast, otherRectangleEast)\n );\n\n if (\n (rectangle.west < rectangle.east ||\n otherRectangle.west < otherRectangle.east) &&\n east <= west\n ) {\n return undefined;\n }\n\n const south = Math.max(rectangle.south, otherRectangle.south);\n const north = Math.min(rectangle.north, otherRectangle.north);\n\n if (south >= north) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function\n * does not attempt to put the angular coordinates into a consistent range or to account for crossing the\n * anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude\n * and longitude (i.e. projected coordinates).\n *\n * @param {Rectangle} rectangle On rectangle to find an intersection\n * @param {Rectangle} otherRectangle Another rectangle to find an intersection\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.\n */\nRectangle.simpleIntersection = function (rectangle, otherRectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\n //>>includeEnd('debug');\n\n const west = Math.max(rectangle.west, otherRectangle.west);\n const south = Math.max(rectangle.south, otherRectangle.south);\n const east = Math.min(rectangle.east, otherRectangle.east);\n const north = Math.min(rectangle.north, otherRectangle.north);\n\n if (south >= north || west >= east) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Computes a rectangle that is the union of two rectangles.\n *\n * @param {Rectangle} rectangle A rectangle to enclose in rectangle.\n * @param {Rectangle} otherRectangle A rectangle to enclose in a rectangle.\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n */\nRectangle.union = function (rectangle, otherRectangle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"otherRectangle\", otherRectangle);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Rectangle();\n }\n\n let rectangleEast = rectangle.east;\n let rectangleWest = rectangle.west;\n\n let otherRectangleEast = otherRectangle.east;\n let otherRectangleWest = otherRectangle.west;\n\n if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {\n rectangleEast += CesiumMath.TWO_PI;\n } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {\n otherRectangleEast += CesiumMath.TWO_PI;\n }\n\n if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {\n otherRectangleWest += CesiumMath.TWO_PI;\n } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {\n rectangleWest += CesiumMath.TWO_PI;\n }\n\n const west = CesiumMath.negativePiToPi(\n Math.min(rectangleWest, otherRectangleWest)\n );\n const east = CesiumMath.negativePiToPi(\n Math.max(rectangleEast, otherRectangleEast)\n );\n\n result.west = west;\n result.south = Math.min(rectangle.south, otherRectangle.south);\n result.east = east;\n result.north = Math.max(rectangle.north, otherRectangle.north);\n\n return result;\n};\n\n/**\n * Computes a rectangle by enlarging the provided rectangle until it contains the provided cartographic.\n *\n * @param {Rectangle} rectangle A rectangle to expand.\n * @param {Cartographic} cartographic A cartographic to enclose in a rectangle.\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.\n */\nRectangle.expand = function (rectangle, cartographic, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"cartographic\", cartographic);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Rectangle();\n }\n\n result.west = Math.min(rectangle.west, cartographic.longitude);\n result.south = Math.min(rectangle.south, cartographic.latitude);\n result.east = Math.max(rectangle.east, cartographic.longitude);\n result.north = Math.max(rectangle.north, cartographic.latitude);\n\n return result;\n};\n\n/**\n * Returns true if the cartographic is on or inside the rectangle, false otherwise.\n *\n * @param {Rectangle} rectangle The rectangle\n * @param {Cartographic} cartographic The cartographic to test.\n * @returns {boolean} true if the provided cartographic is inside the rectangle, false otherwise.\n */\nRectangle.contains = function (rectangle, cartographic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"cartographic\", cartographic);\n //>>includeEnd('debug');\n\n let longitude = cartographic.longitude;\n const latitude = cartographic.latitude;\n\n const west = rectangle.west;\n let east = rectangle.east;\n\n if (east < west) {\n east += CesiumMath.TWO_PI;\n if (longitude < 0.0) {\n longitude += CesiumMath.TWO_PI;\n }\n }\n return (\n (longitude > west ||\n CesiumMath.equalsEpsilon(longitude, west, CesiumMath.EPSILON14)) &&\n (longitude < east ||\n CesiumMath.equalsEpsilon(longitude, east, CesiumMath.EPSILON14)) &&\n latitude >= rectangle.south &&\n latitude <= rectangle.north\n );\n};\n\nconst subsampleLlaScratch = new Cartographic();\n/**\n * Samples a rectangle so that it includes a list of Cartesian points suitable for passing to\n * {@link BoundingSphere#fromPoints}. Sampling is necessary to account\n * for rectangles that cover the poles or cross the equator.\n *\n * @param {Rectangle} rectangle The rectangle to subsample.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\n * @param {number} [surfaceHeight=0.0] The height of the rectangle above the ellipsoid.\n * @param {Cartesian3[]} [result] The array of Cartesians onto which to store the result.\n * @returns {Cartesian3[]} The modified result parameter or a new Array of Cartesians instances if none was provided.\n */\nRectangle.subsample = function (rectangle, ellipsoid, surfaceHeight, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n surfaceHeight = defaultValue(surfaceHeight, 0.0);\n\n if (!defined(result)) {\n result = [];\n }\n let length = 0;\n\n const north = rectangle.north;\n const south = rectangle.south;\n const east = rectangle.east;\n const west = rectangle.west;\n\n const lla = subsampleLlaScratch;\n lla.height = surfaceHeight;\n\n lla.longitude = west;\n lla.latitude = north;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n\n lla.longitude = east;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n\n lla.latitude = south;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n\n lla.longitude = west;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n\n if (north < 0.0) {\n lla.latitude = north;\n } else if (south > 0.0) {\n lla.latitude = south;\n } else {\n lla.latitude = 0.0;\n }\n\n for (let i = 1; i < 8; ++i) {\n lla.longitude = -Math.PI + i * CesiumMath.PI_OVER_TWO;\n if (Rectangle.contains(rectangle, lla)) {\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n }\n }\n\n if (lla.latitude === 0.0) {\n lla.longitude = west;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n lla.longitude = east;\n result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);\n length++;\n }\n result.length = length;\n return result;\n};\n\n/**\n * Computes a subsection of a rectangle from normalized coordinates in the range [0.0, 1.0].\n *\n * @param {Rectangle} rectangle The rectangle to subsection.\n * @param {number} westLerp The west interpolation factor in the range [0.0, 1.0]. Must be less than or equal to eastLerp.\n * @param {number} southLerp The south interpolation factor in the range [0.0, 1.0]. Must be less than or equal to northLerp.\n * @param {number} eastLerp The east interpolation factor in the range [0.0, 1.0]. Must be greater than or equal to westLerp.\n * @param {number} northLerp The north interpolation factor in the range [0.0, 1.0]. Must be greater than or equal to southLerp.\n * @param {Rectangle} [result] The object onto which to store the result.\n * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.\n */\nRectangle.subsection = function (\n rectangle,\n westLerp,\n southLerp,\n eastLerp,\n northLerp,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.number.greaterThanOrEquals(\"westLerp\", westLerp, 0.0);\n Check.typeOf.number.lessThanOrEquals(\"westLerp\", westLerp, 1.0);\n Check.typeOf.number.greaterThanOrEquals(\"southLerp\", southLerp, 0.0);\n Check.typeOf.number.lessThanOrEquals(\"southLerp\", southLerp, 1.0);\n Check.typeOf.number.greaterThanOrEquals(\"eastLerp\", eastLerp, 0.0);\n Check.typeOf.number.lessThanOrEquals(\"eastLerp\", eastLerp, 1.0);\n Check.typeOf.number.greaterThanOrEquals(\"northLerp\", northLerp, 0.0);\n Check.typeOf.number.lessThanOrEquals(\"northLerp\", northLerp, 1.0);\n\n Check.typeOf.number.lessThanOrEquals(\"westLerp\", westLerp, eastLerp);\n Check.typeOf.number.lessThanOrEquals(\"southLerp\", southLerp, northLerp);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Rectangle();\n }\n\n // This function doesn't use CesiumMath.lerp because it has floating point precision problems\n // when the start and end values are the same but the t changes.\n\n if (rectangle.west <= rectangle.east) {\n const width = rectangle.east - rectangle.west;\n result.west = rectangle.west + westLerp * width;\n result.east = rectangle.west + eastLerp * width;\n } else {\n const width = CesiumMath.TWO_PI + rectangle.east - rectangle.west;\n result.west = CesiumMath.negativePiToPi(rectangle.west + westLerp * width);\n result.east = CesiumMath.negativePiToPi(rectangle.west + eastLerp * width);\n }\n const height = rectangle.north - rectangle.south;\n result.south = rectangle.south + southLerp * height;\n result.north = rectangle.south + northLerp * height;\n\n // Fix floating point precision problems when t = 1\n if (westLerp === 1.0) {\n result.west = rectangle.east;\n }\n if (eastLerp === 1.0) {\n result.east = rectangle.east;\n }\n if (southLerp === 1.0) {\n result.south = rectangle.north;\n }\n if (northLerp === 1.0) {\n result.north = rectangle.north;\n }\n\n return result;\n};\n\n/**\n * The largest possible rectangle.\n *\n * @type {Rectangle}\n * @constant\n */\nRectangle.MAX_VALUE = Object.freeze(\n new Rectangle(\n -Math.PI,\n -CesiumMath.PI_OVER_TWO,\n Math.PI,\n CesiumMath.PI_OVER_TWO\n )\n);\nexport default Rectangle;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Intersect from \"./Intersect.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * A bounding rectangle given by a corner, width and height.\n * @alias BoundingRectangle\n * @constructor\n *\n * @param {number} [x=0.0] The x coordinate of the rectangle.\n * @param {number} [y=0.0] The y coordinate of the rectangle.\n * @param {number} [width=0.0] The width of the rectangle.\n * @param {number} [height=0.0] The height of the rectangle.\n *\n * @see BoundingSphere\n * @see Packable\n */\nfunction BoundingRectangle(x, y, width, height) {\n /**\n * The x coordinate of the rectangle.\n * @type {number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The y coordinate of the rectangle.\n * @type {number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n\n /**\n * The width of the rectangle.\n * @type {number}\n * @default 0.0\n */\n this.width = defaultValue(width, 0.0);\n\n /**\n * The height of the rectangle.\n * @type {number}\n * @default 0.0\n */\n this.height = defaultValue(height, 0.0);\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nBoundingRectangle.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {BoundingRectangle} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nBoundingRectangle.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex++] = value.y;\n array[startingIndex++] = value.width;\n array[startingIndex] = value.height;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {BoundingRectangle} [result] The object into which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n result.x = array[startingIndex++];\n result.y = array[startingIndex++];\n result.width = array[startingIndex++];\n result.height = array[startingIndex];\n return result;\n};\n\n/**\n * Computes a bounding rectangle enclosing the list of 2D points.\n * The rectangle is oriented with the corner at the bottom left.\n *\n * @param {Cartesian2[]} positions List of points that the bounding rectangle will enclose. Each point must have x and y properties.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.fromPoints = function (positions, result) {\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.x = 0;\n result.y = 0;\n result.width = 0;\n result.height = 0;\n return result;\n }\n\n const length = positions.length;\n\n let minimumX = positions[0].x;\n let minimumY = positions[0].y;\n\n let maximumX = positions[0].x;\n let maximumY = positions[0].y;\n\n for (let i = 1; i < length; i++) {\n const p = positions[i];\n const x = p.x;\n const y = p.y;\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n }\n\n result.x = minimumX;\n result.y = minimumY;\n result.width = maximumX - minimumX;\n result.height = maximumY - minimumY;\n return result;\n};\n\nconst defaultProjection = new GeographicProjection();\nconst fromRectangleLowerLeft = new Cartographic();\nconst fromRectangleUpperRight = new Cartographic();\n/**\n * Computes a bounding rectangle from a rectangle.\n *\n * @param {Rectangle} rectangle The valid rectangle used to create a bounding rectangle.\n * @param {object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.fromRectangle = function (rectangle, projection, result) {\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n if (!defined(rectangle)) {\n result.x = 0;\n result.y = 0;\n result.width = 0;\n result.height = 0;\n return result;\n }\n\n projection = defaultValue(projection, defaultProjection);\n\n const lowerLeft = projection.project(\n Rectangle.southwest(rectangle, fromRectangleLowerLeft)\n );\n const upperRight = projection.project(\n Rectangle.northeast(rectangle, fromRectangleUpperRight)\n );\n\n Cartesian2.subtract(upperRight, lowerLeft, upperRight);\n\n result.x = lowerLeft.x;\n result.y = lowerLeft.y;\n result.width = upperRight.x;\n result.height = upperRight.y;\n return result;\n};\n\n/**\n * Duplicates a BoundingRectangle instance.\n *\n * @param {BoundingRectangle} rectangle The bounding rectangle to duplicate.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided. (Returns undefined if rectangle is undefined)\n */\nBoundingRectangle.clone = function (rectangle, result) {\n if (!defined(rectangle)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new BoundingRectangle(\n rectangle.x,\n rectangle.y,\n rectangle.width,\n rectangle.height\n );\n }\n\n result.x = rectangle.x;\n result.y = rectangle.y;\n result.width = rectangle.width;\n result.height = rectangle.height;\n return result;\n};\n\n/**\n * Computes a bounding rectangle that is the union of the left and right bounding rectangles.\n *\n * @param {BoundingRectangle} left A rectangle to enclose in bounding rectangle.\n * @param {BoundingRectangle} right A rectangle to enclose in a bounding rectangle.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.union = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n const lowerLeftX = Math.min(left.x, right.x);\n const lowerLeftY = Math.min(left.y, right.y);\n const upperRightX = Math.max(left.x + left.width, right.x + right.width);\n const upperRightY = Math.max(left.y + left.height, right.y + right.height);\n\n result.x = lowerLeftX;\n result.y = lowerLeftY;\n result.width = upperRightX - lowerLeftX;\n result.height = upperRightY - lowerLeftY;\n return result;\n};\n\n/**\n * Computes a bounding rectangle by enlarging the provided rectangle until it contains the provided point.\n *\n * @param {BoundingRectangle} rectangle A rectangle to expand.\n * @param {Cartesian2} point A point to enclose in a bounding rectangle.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.expand = function (rectangle, point, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Check.typeOf.object(\"point\", point);\n //>>includeEnd('debug');\n\n result = BoundingRectangle.clone(rectangle, result);\n\n const width = point.x - result.x;\n const height = point.y - result.y;\n\n if (width > result.width) {\n result.width = width;\n } else if (width < 0) {\n result.width -= width;\n result.x = point.x;\n }\n\n if (height > result.height) {\n result.height = height;\n } else if (height < 0) {\n result.height -= height;\n result.y = point.y;\n }\n\n return result;\n};\n\n/**\n * Determines if two rectangles intersect.\n *\n * @param {BoundingRectangle} left A rectangle to check for intersection.\n * @param {BoundingRectangle} right The other rectangle to check for intersection.\n * @returns {Intersect} Intersect.INTERSECTING if the rectangles intersect, Intersect.OUTSIDE otherwise.\n */\nBoundingRectangle.intersect = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n const leftX = left.x;\n const leftY = left.y;\n const rightX = right.x;\n const rightY = right.y;\n if (\n !(\n leftX > rightX + right.width ||\n leftX + left.width < rightX ||\n leftY + left.height < rightY ||\n leftY > rightY + right.height\n )\n ) {\n return Intersect.INTERSECTING;\n }\n\n return Intersect.OUTSIDE;\n};\n\n/**\n * Compares the provided BoundingRectangles componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {BoundingRectangle} [left] The first BoundingRectangle.\n * @param {BoundingRectangle} [right] The second BoundingRectangle.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nBoundingRectangle.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y &&\n left.width === right.width &&\n left.height === right.height)\n );\n};\n\n/**\n * Duplicates this BoundingRectangle instance.\n *\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The modified result parameter or a new BoundingRectangle instance if one was not provided.\n */\nBoundingRectangle.prototype.clone = function (result) {\n return BoundingRectangle.clone(this, result);\n};\n\n/**\n * Determines if this rectangle intersects with another.\n *\n * @param {BoundingRectangle} right A rectangle to check for intersection.\n * @returns {Intersect} Intersect.INTERSECTING if the rectangles intersect, Intersect.OUTSIDE otherwise.\n */\nBoundingRectangle.prototype.intersect = function (right) {\n return BoundingRectangle.intersect(this, right);\n};\n\n/**\n * Compares this BoundingRectangle against the provided BoundingRectangle componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {BoundingRectangle} [right] The right hand side BoundingRectangle.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nBoundingRectangle.prototype.equals = function (right) {\n return BoundingRectangle.equals(this, right);\n};\nexport default BoundingRectangle;\n", "import WebGLConstants from \"./WebGLConstants.js\";\n\n/**\n * The type of a geometric primitive, i.e., points, lines, and triangles.\n *\n * @enum {number}\n */\nconst PrimitiveType = {\n /**\n * Points primitive where each vertex (or index) is a separate point.\n *\n * @type {number}\n * @constant\n */\n POINTS: WebGLConstants.POINTS,\n\n /**\n * Lines primitive where each two vertices (or indices) is a line segment. Line segments are not necessarily connected.\n *\n * @type {number}\n * @constant\n */\n LINES: WebGLConstants.LINES,\n\n /**\n * Line loop primitive where each vertex (or index) after the first connects a line to\n * the previous vertex, and the last vertex implicitly connects to the first.\n *\n * @type {number}\n * @constant\n */\n LINE_LOOP: WebGLConstants.LINE_LOOP,\n\n /**\n * Line strip primitive where each vertex (or index) after the first connects a line to the previous vertex.\n *\n * @type {number}\n * @constant\n */\n LINE_STRIP: WebGLConstants.LINE_STRIP,\n\n /**\n * Triangles primitive where each three vertices (or indices) is a triangle. Triangles do not necessarily share edges.\n *\n * @type {number}\n * @constant\n */\n TRIANGLES: WebGLConstants.TRIANGLES,\n\n /**\n * Triangle strip primitive where each vertex (or index) after the first two connect to\n * the previous two vertices forming a triangle. For example, this can be used to model a wall.\n *\n * @type {number}\n * @constant\n */\n TRIANGLE_STRIP: WebGLConstants.TRIANGLE_STRIP,\n\n /**\n * Triangle fan primitive where each vertex (or index) after the first two connect to\n * the previous vertex and the first vertex forming a triangle. For example, this can be used\n * to model a cone or circle.\n *\n * @type {number}\n * @constant\n */\n TRIANGLE_FAN: WebGLConstants.TRIANGLE_FAN,\n};\n\n/**\n * @private\n */\nPrimitiveType.isLines = function (primitiveType) {\n return (\n primitiveType === PrimitiveType.LINES ||\n primitiveType === PrimitiveType.LINE_LOOP ||\n primitiveType === PrimitiveType.LINE_STRIP\n );\n};\n\n/**\n * @private\n */\nPrimitiveType.isTriangles = function (primitiveType) {\n return (\n primitiveType === PrimitiveType.TRIANGLES ||\n primitiveType === PrimitiveType.TRIANGLE_STRIP ||\n primitiveType === PrimitiveType.TRIANGLE_FAN\n );\n};\n\n/**\n * @private\n */\nPrimitiveType.validate = function (primitiveType) {\n return (\n primitiveType === PrimitiveType.POINTS ||\n primitiveType === PrimitiveType.LINES ||\n primitiveType === PrimitiveType.LINE_LOOP ||\n primitiveType === PrimitiveType.LINE_STRIP ||\n primitiveType === PrimitiveType.TRIANGLES ||\n primitiveType === PrimitiveType.TRIANGLE_STRIP ||\n primitiveType === PrimitiveType.TRIANGLE_FAN\n );\n};\n\nexport default Object.freeze(PrimitiveType);\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 position;\\n\\\nin vec2 textureCoordinates;\\n\\\n\\n\\\nout vec2 v_textureCoordinates;\\n\\\n\\n\\\nvoid main() \\n\\\n{\\n\\\n gl_Position = position;\\n\\\n v_textureCoordinates = textureCoordinates;\\n\\\n}\\n\\\n\";\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\n\nconst Flags = {\n CULL: 1,\n OCCLUDE: 2,\n EXECUTE_IN_CLOSEST_FRUSTUM: 4,\n DEBUG_SHOW_BOUNDING_VOLUME: 8,\n CAST_SHADOWS: 16,\n RECEIVE_SHADOWS: 32,\n PICK_ONLY: 64,\n DEPTH_FOR_TRANSLUCENT_CLASSIFICATION: 128,\n};\n\n/**\n * Represents a command to the renderer for drawing.\n *\n * @private\n */\nfunction DrawCommand(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._boundingVolume = options.boundingVolume;\n this._orientedBoundingBox = options.orientedBoundingBox;\n this._modelMatrix = options.modelMatrix;\n this._primitiveType = defaultValue(\n options.primitiveType,\n PrimitiveType.TRIANGLES\n );\n this._vertexArray = options.vertexArray;\n this._count = options.count;\n this._offset = defaultValue(options.offset, 0);\n this._instanceCount = defaultValue(options.instanceCount, 0);\n this._shaderProgram = options.shaderProgram;\n this._uniformMap = options.uniformMap;\n this._renderState = options.renderState;\n this._framebuffer = options.framebuffer;\n this._pass = options.pass;\n this._owner = options.owner;\n this._debugOverlappingFrustums = 0;\n this._pickId = options.pickId;\n\n // Set initial flags.\n this._flags = 0;\n this.cull = defaultValue(options.cull, true);\n this.occlude = defaultValue(options.occlude, true);\n this.executeInClosestFrustum = defaultValue(\n options.executeInClosestFrustum,\n false\n );\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n this.castShadows = defaultValue(options.castShadows, false);\n this.receiveShadows = defaultValue(options.receiveShadows, false);\n this.pickOnly = defaultValue(options.pickOnly, false);\n this.depthForTranslucentClassification = defaultValue(\n options.depthForTranslucentClassification,\n false\n );\n\n this.dirty = true;\n this.lastDirtyTime = 0;\n\n /**\n * @private\n */\n this.derivedCommands = {};\n}\n\nfunction hasFlag(command, flag) {\n return (command._flags & flag) === flag;\n}\n\nfunction setFlag(command, flag, value) {\n if (value) {\n command._flags |= flag;\n } else {\n command._flags &= ~flag;\n }\n}\n\nObject.defineProperties(DrawCommand.prototype, {\n /**\n * The bounding volume of the geometry in world space. This is used for culling and frustum selection.\n *

\n * For best rendering performance, use the tightest possible bounding volume. Although\n * undefined is allowed, always try to provide a bounding volume to\n * allow the tightest possible near and far planes to be computed for the scene, and\n * minimize the number of frustums needed.\n *

\n *\n * @memberof DrawCommand.prototype\n * @type {object}\n * @default undefined\n *\n * @see DrawCommand#debugShowBoundingVolume\n */\n boundingVolume: {\n get: function () {\n return this._boundingVolume;\n },\n set: function (value) {\n if (this._boundingVolume !== value) {\n this._boundingVolume = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The oriented bounding box of the geometry in world space. If this is defined, it is used instead of\n * {@link DrawCommand#boundingVolume} for plane intersection testing.\n *\n * @memberof DrawCommand.prototype\n * @type {OrientedBoundingBox}\n * @default undefined\n *\n * @see DrawCommand#debugShowBoundingVolume\n */\n orientedBoundingBox: {\n get: function () {\n return this._orientedBoundingBox;\n },\n set: function (value) {\n if (this._orientedBoundingBox !== value) {\n this._orientedBoundingBox = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * When true, the renderer frustum and horizon culls the command based on its {@link DrawCommand#boundingVolume}.\n * If the command was already culled, set this to false for a performance improvement.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default true\n */\n cull: {\n get: function () {\n return hasFlag(this, Flags.CULL);\n },\n set: function (value) {\n if (hasFlag(this, Flags.CULL) !== value) {\n setFlag(this, Flags.CULL, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * When true, the horizon culls the command based on its {@link DrawCommand#boundingVolume}.\n * {@link DrawCommand#cull} must also be true in order for the command to be culled.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default true\n */\n occlude: {\n get: function () {\n return hasFlag(this, Flags.OCCLUDE);\n },\n set: function (value) {\n if (hasFlag(this, Flags.OCCLUDE) !== value) {\n setFlag(this, Flags.OCCLUDE, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * The transformation from the geometry in model space to world space.\n *

\n * When undefined, the geometry is assumed to be defined in world space.\n *

\n *\n * @memberof DrawCommand.prototype\n * @type {Matrix4}\n * @default undefined\n */\n modelMatrix: {\n get: function () {\n return this._modelMatrix;\n },\n set: function (value) {\n if (this._modelMatrix !== value) {\n this._modelMatrix = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The type of geometry in the vertex array.\n *\n * @memberof DrawCommand.prototype\n * @type {PrimitiveType}\n * @default PrimitiveType.TRIANGLES\n */\n primitiveType: {\n get: function () {\n return this._primitiveType;\n },\n set: function (value) {\n if (this._primitiveType !== value) {\n this._primitiveType = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The vertex array.\n *\n * @memberof DrawCommand.prototype\n * @type {VertexArray}\n * @default undefined\n */\n vertexArray: {\n get: function () {\n return this._vertexArray;\n },\n set: function (value) {\n if (this._vertexArray !== value) {\n this._vertexArray = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The number of vertices to draw in the vertex array.\n *\n * @memberof DrawCommand.prototype\n * @type {number}\n * @default undefined\n */\n count: {\n get: function () {\n return this._count;\n },\n set: function (value) {\n if (this._count !== value) {\n this._count = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The offset to start drawing in the vertex array.\n *\n * @memberof DrawCommand.prototype\n * @type {number}\n * @default 0\n */\n offset: {\n get: function () {\n return this._offset;\n },\n set: function (value) {\n if (this._offset !== value) {\n this._offset = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The number of instances to draw.\n *\n * @memberof DrawCommand.prototype\n * @type {number}\n * @default 0\n */\n instanceCount: {\n get: function () {\n return this._instanceCount;\n },\n set: function (value) {\n if (this._instanceCount !== value) {\n this._instanceCount = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The shader program to apply.\n *\n * @memberof DrawCommand.prototype\n * @type {ShaderProgram}\n * @default undefined\n */\n shaderProgram: {\n get: function () {\n return this._shaderProgram;\n },\n set: function (value) {\n if (this._shaderProgram !== value) {\n this._shaderProgram = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * Whether this command should cast shadows when shadowing is enabled.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n */\n castShadows: {\n get: function () {\n return hasFlag(this, Flags.CAST_SHADOWS);\n },\n set: function (value) {\n if (hasFlag(this, Flags.CAST_SHADOWS) !== value) {\n setFlag(this, Flags.CAST_SHADOWS, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * Whether this command should receive shadows when shadowing is enabled.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n */\n receiveShadows: {\n get: function () {\n return hasFlag(this, Flags.RECEIVE_SHADOWS);\n },\n set: function (value) {\n if (hasFlag(this, Flags.RECEIVE_SHADOWS) !== value) {\n setFlag(this, Flags.RECEIVE_SHADOWS, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * An object with functions whose names match the uniforms in the shader program\n * and return values to set those uniforms.\n *\n * @memberof DrawCommand.prototype\n * @type {object}\n * @default undefined\n */\n uniformMap: {\n get: function () {\n return this._uniformMap;\n },\n set: function (value) {\n if (this._uniformMap !== value) {\n this._uniformMap = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The render state.\n *\n * @memberof DrawCommand.prototype\n * @type {RenderState}\n * @default undefined\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n set: function (value) {\n if (this._renderState !== value) {\n this._renderState = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The framebuffer to draw to.\n *\n * @memberof DrawCommand.prototype\n * @type {Framebuffer}\n * @default undefined\n */\n framebuffer: {\n get: function () {\n return this._framebuffer;\n },\n set: function (value) {\n if (this._framebuffer !== value) {\n this._framebuffer = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * The pass when to render.\n *\n * @memberof DrawCommand.prototype\n * @type {Pass}\n * @default undefined\n */\n pass: {\n get: function () {\n return this._pass;\n },\n set: function (value) {\n if (this._pass !== value) {\n this._pass = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * Specifies if this command is only to be executed in the frustum closest\n * to the eye containing the bounding volume. Defaults to false.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n */\n executeInClosestFrustum: {\n get: function () {\n return hasFlag(this, Flags.EXECUTE_IN_CLOSEST_FRUSTUM);\n },\n set: function (value) {\n if (hasFlag(this, Flags.EXECUTE_IN_CLOSEST_FRUSTUM) !== value) {\n setFlag(this, Flags.EXECUTE_IN_CLOSEST_FRUSTUM, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * The object who created this command. This is useful for debugging command\n * execution; it allows us to see who created a command when we only have a\n * reference to the command, and can be used to selectively execute commands\n * with {@link Scene#debugCommandFilter}.\n *\n * @memberof DrawCommand.prototype\n * @type {object}\n * @default undefined\n *\n * @see Scene#debugCommandFilter\n */\n owner: {\n get: function () {\n return this._owner;\n },\n set: function (value) {\n if (this._owner !== value) {\n this._owner = value;\n this.dirty = true;\n }\n },\n },\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the {@link DrawCommand#boundingVolume} for this command, assuming it is a sphere, when the command executes.\n *

\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n *\n * @see DrawCommand#boundingVolume\n */\n debugShowBoundingVolume: {\n get: function () {\n return hasFlag(this, Flags.DEBUG_SHOW_BOUNDING_VOLUME);\n },\n set: function (value) {\n if (hasFlag(this, Flags.DEBUG_SHOW_BOUNDING_VOLUME) !== value) {\n setFlag(this, Flags.DEBUG_SHOW_BOUNDING_VOLUME, value);\n this.dirty = true;\n }\n },\n },\n\n /**\n * Used to implement Scene.debugShowFrustums.\n * @private\n */\n debugOverlappingFrustums: {\n get: function () {\n return this._debugOverlappingFrustums;\n },\n set: function (value) {\n if (this._debugOverlappingFrustums !== value) {\n this._debugOverlappingFrustums = value;\n this.dirty = true;\n }\n },\n },\n /**\n * A GLSL string that will evaluate to a pick id. When undefined, the command will only draw depth\n * during the pick pass.\n *\n * @memberof DrawCommand.prototype\n * @type {string}\n * @default undefined\n */\n pickId: {\n get: function () {\n return this._pickId;\n },\n set: function (value) {\n if (this._pickId !== value) {\n this._pickId = value;\n this.dirty = true;\n }\n },\n },\n /**\n * Whether this command should be executed in the pick pass only.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n */\n pickOnly: {\n get: function () {\n return hasFlag(this, Flags.PICK_ONLY);\n },\n set: function (value) {\n if (hasFlag(this, Flags.PICK_ONLY) !== value) {\n setFlag(this, Flags.PICK_ONLY, value);\n this.dirty = true;\n }\n },\n },\n /**\n * Whether this command should be derived to draw depth for classification of translucent primitives.\n *\n * @memberof DrawCommand.prototype\n * @type {boolean}\n * @default false\n */\n depthForTranslucentClassification: {\n get: function () {\n return hasFlag(this, Flags.DEPTH_FOR_TRANSLUCENT_CLASSIFICATION);\n },\n set: function (value) {\n if (hasFlag(this, Flags.DEPTH_FOR_TRANSLUCENT_CLASSIFICATION) !== value) {\n setFlag(this, Flags.DEPTH_FOR_TRANSLUCENT_CLASSIFICATION, value);\n this.dirty = true;\n }\n },\n },\n});\n\n/**\n * @private\n */\nDrawCommand.shallowClone = function (command, result) {\n if (!defined(command)) {\n return undefined;\n }\n if (!defined(result)) {\n result = new DrawCommand();\n }\n\n result._boundingVolume = command._boundingVolume;\n result._orientedBoundingBox = command._orientedBoundingBox;\n result._modelMatrix = command._modelMatrix;\n result._primitiveType = command._primitiveType;\n result._vertexArray = command._vertexArray;\n result._count = command._count;\n result._offset = command._offset;\n result._instanceCount = command._instanceCount;\n result._shaderProgram = command._shaderProgram;\n result._uniformMap = command._uniformMap;\n result._renderState = command._renderState;\n result._framebuffer = command._framebuffer;\n result._pass = command._pass;\n result._owner = command._owner;\n result._debugOverlappingFrustums = command._debugOverlappingFrustums;\n result._pickId = command._pickId;\n result._flags = command._flags;\n\n result.dirty = true;\n result.lastDirtyTime = 0;\n\n return result;\n};\n\n/**\n * Executes the draw command.\n *\n * @param {Context} context The renderer context in which to draw.\n * @param {PassState} [passState] The state for the current render pass.\n */\nDrawCommand.prototype.execute = function (context, passState) {\n context.draw(this, passState);\n};\nexport default DrawCommand;\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * The data type of a pixel.\n *\n * @enum {number}\n * @see PostProcessStage\n */\nconst PixelDatatype = {\n UNSIGNED_BYTE: WebGLConstants.UNSIGNED_BYTE,\n UNSIGNED_SHORT: WebGLConstants.UNSIGNED_SHORT,\n UNSIGNED_INT: WebGLConstants.UNSIGNED_INT,\n FLOAT: WebGLConstants.FLOAT,\n HALF_FLOAT: WebGLConstants.HALF_FLOAT_OES,\n UNSIGNED_INT_24_8: WebGLConstants.UNSIGNED_INT_24_8,\n UNSIGNED_SHORT_4_4_4_4: WebGLConstants.UNSIGNED_SHORT_4_4_4_4,\n UNSIGNED_SHORT_5_5_5_1: WebGLConstants.UNSIGNED_SHORT_5_5_5_1,\n UNSIGNED_SHORT_5_6_5: WebGLConstants.UNSIGNED_SHORT_5_6_5,\n};\n\n/**\n @private\n*/\nPixelDatatype.toWebGLConstant = function (pixelDatatype, context) {\n switch (pixelDatatype) {\n case PixelDatatype.UNSIGNED_BYTE:\n return WebGLConstants.UNSIGNED_BYTE;\n case PixelDatatype.UNSIGNED_SHORT:\n return WebGLConstants.UNSIGNED_SHORT;\n case PixelDatatype.UNSIGNED_INT:\n return WebGLConstants.UNSIGNED_INT;\n case PixelDatatype.FLOAT:\n return WebGLConstants.FLOAT;\n case PixelDatatype.HALF_FLOAT:\n return context.webgl2\n ? WebGLConstants.HALF_FLOAT\n : WebGLConstants.HALF_FLOAT_OES;\n case PixelDatatype.UNSIGNED_INT_24_8:\n return WebGLConstants.UNSIGNED_INT_24_8;\n case PixelDatatype.UNSIGNED_SHORT_4_4_4_4:\n return WebGLConstants.UNSIGNED_SHORT_4_4_4_4;\n case PixelDatatype.UNSIGNED_SHORT_5_5_5_1:\n return WebGLConstants.UNSIGNED_SHORT_5_5_5_1;\n case PixelDatatype.UNSIGNED_SHORT_5_6_5:\n return PixelDatatype.UNSIGNED_SHORT_5_6_5;\n }\n};\n\n/**\n @private\n*/\nPixelDatatype.isPacked = function (pixelDatatype) {\n return (\n pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5\n );\n};\n\n/**\n @private\n*/\nPixelDatatype.sizeInBytes = function (pixelDatatype) {\n switch (pixelDatatype) {\n case PixelDatatype.UNSIGNED_BYTE:\n return 1;\n case PixelDatatype.UNSIGNED_SHORT:\n case PixelDatatype.UNSIGNED_SHORT_4_4_4_4:\n case PixelDatatype.UNSIGNED_SHORT_5_5_5_1:\n case PixelDatatype.UNSIGNED_SHORT_5_6_5:\n case PixelDatatype.HALF_FLOAT:\n return 2;\n case PixelDatatype.UNSIGNED_INT:\n case PixelDatatype.FLOAT:\n case PixelDatatype.UNSIGNED_INT_24_8:\n return 4;\n }\n};\n\n/**\n @private\n*/\nPixelDatatype.validate = function (pixelDatatype) {\n return (\n pixelDatatype === PixelDatatype.UNSIGNED_BYTE ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT ||\n pixelDatatype === PixelDatatype.UNSIGNED_INT ||\n pixelDatatype === PixelDatatype.FLOAT ||\n pixelDatatype === PixelDatatype.HALF_FLOAT ||\n pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1 ||\n pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5\n );\n};\n\nexport default Object.freeze(PixelDatatype);\n", "import PixelDatatype from \"../Renderer/PixelDatatype.js\";\nimport WebGLConstants from \"./WebGLConstants.js\";\n\n/**\n * The format of a pixel, i.e., the number of components it has and what they represent.\n *\n * @enum {number}\n */\nconst PixelFormat = {\n /**\n * A pixel format containing a depth value.\n *\n * @type {number}\n * @constant\n */\n DEPTH_COMPONENT: WebGLConstants.DEPTH_COMPONENT,\n\n /**\n * A pixel format containing a depth and stencil value, most often used with {@link PixelDatatype.UNSIGNED_INT_24_8}.\n *\n * @type {number}\n * @constant\n */\n DEPTH_STENCIL: WebGLConstants.DEPTH_STENCIL,\n\n /**\n * A pixel format containing an alpha channel.\n *\n * @type {number}\n * @constant\n */\n ALPHA: WebGLConstants.ALPHA,\n\n /**\n * A pixel format containing a red channel\n *\n * @type {number}\n * @constant\n */\n RED: WebGLConstants.RED,\n\n /**\n * A pixel format containing red and green channels.\n *\n * @type {number}\n * @constant\n */\n RG: WebGLConstants.RG,\n\n /**\n * A pixel format containing red, green, and blue channels.\n *\n * @type {number}\n * @constant\n */\n RGB: WebGLConstants.RGB,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels.\n *\n * @type {number}\n * @constant\n */\n RGBA: WebGLConstants.RGBA,\n\n /**\n * A pixel format containing a luminance (intensity) channel.\n *\n * @type {number}\n * @constant\n */\n LUMINANCE: WebGLConstants.LUMINANCE,\n\n /**\n * A pixel format containing luminance (intensity) and alpha channels.\n *\n * @type {number}\n * @constant\n */\n LUMINANCE_ALPHA: WebGLConstants.LUMINANCE_ALPHA,\n\n /**\n * A pixel format containing red, green, and blue channels that is DXT1 compressed.\n *\n * @type {number}\n * @constant\n */\n RGB_DXT1: WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is DXT1 compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_DXT1: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is DXT3 compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_DXT3: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is DXT5 compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_DXT5: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,\n\n /**\n * A pixel format containing red, green, and blue channels that is PVR 4bpp compressed.\n *\n * @type {number}\n * @constant\n */\n RGB_PVRTC_4BPPV1: WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,\n\n /**\n * A pixel format containing red, green, and blue channels that is PVR 2bpp compressed.\n *\n * @type {number}\n * @constant\n */\n RGB_PVRTC_2BPPV1: WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is PVR 4bpp compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_PVRTC_4BPPV1: WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is PVR 2bpp compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_PVRTC_2BPPV1: WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is ASTC compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_ASTC: WebGLConstants.COMPRESSED_RGBA_ASTC_4x4_WEBGL,\n\n /**\n * A pixel format containing red, green, and blue channels that is ETC1 compressed.\n *\n * @type {number}\n * @constant\n */\n RGB_ETC1: WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,\n\n /**\n * A pixel format containing red, green, and blue channels that is ETC2 compressed.\n *\n * @type {number}\n * @constant\n */\n RGB8_ETC2: WebGLConstants.COMPRESSED_RGB8_ETC2,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is ETC2 compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA8_ETC2_EAC: WebGLConstants.COMPRESSED_RGBA8_ETC2_EAC,\n\n /**\n * A pixel format containing red, green, blue, and alpha channels that is BC7 compressed.\n *\n * @type {number}\n * @constant\n */\n RGBA_BC7: WebGLConstants.COMPRESSED_RGBA_BPTC_UNORM,\n};\n\n/**\n * @private\n */\nPixelFormat.componentsLength = function (pixelFormat) {\n switch (pixelFormat) {\n case PixelFormat.RGB:\n return 3;\n case PixelFormat.RGBA:\n return 4;\n case PixelFormat.LUMINANCE_ALPHA:\n case PixelFormat.RG:\n return 2;\n case PixelFormat.ALPHA:\n case PixelFormat.RED:\n case PixelFormat.LUMINANCE:\n return 1;\n default:\n return 1;\n }\n};\n\n/**\n * @private\n */\nPixelFormat.validate = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.DEPTH_COMPONENT ||\n pixelFormat === PixelFormat.DEPTH_STENCIL ||\n pixelFormat === PixelFormat.ALPHA ||\n pixelFormat === PixelFormat.RED ||\n pixelFormat === PixelFormat.RG ||\n pixelFormat === PixelFormat.RGB ||\n pixelFormat === PixelFormat.RGBA ||\n pixelFormat === PixelFormat.LUMINANCE ||\n pixelFormat === PixelFormat.LUMINANCE_ALPHA ||\n pixelFormat === PixelFormat.RGB_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT3 ||\n pixelFormat === PixelFormat.RGBA_DXT5 ||\n pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||\n pixelFormat === PixelFormat.RGBA_ASTC ||\n pixelFormat === PixelFormat.RGB_ETC1 ||\n pixelFormat === PixelFormat.RGB8_ETC2 ||\n pixelFormat === PixelFormat.RGBA8_ETC2_EAC ||\n pixelFormat === PixelFormat.RGBA_BC7\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isColorFormat = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.ALPHA ||\n pixelFormat === PixelFormat.RGB ||\n pixelFormat === PixelFormat.RGBA ||\n pixelFormat === PixelFormat.LUMINANCE ||\n pixelFormat === PixelFormat.LUMINANCE_ALPHA\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isDepthFormat = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.DEPTH_COMPONENT ||\n pixelFormat === PixelFormat.DEPTH_STENCIL\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isCompressedFormat = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.RGB_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT3 ||\n pixelFormat === PixelFormat.RGBA_DXT5 ||\n pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||\n pixelFormat === PixelFormat.RGBA_ASTC ||\n pixelFormat === PixelFormat.RGB_ETC1 ||\n pixelFormat === PixelFormat.RGB8_ETC2 ||\n pixelFormat === PixelFormat.RGBA8_ETC2_EAC ||\n pixelFormat === PixelFormat.RGBA_BC7\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isDXTFormat = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.RGB_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT1 ||\n pixelFormat === PixelFormat.RGBA_DXT3 ||\n pixelFormat === PixelFormat.RGBA_DXT5\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isPVRTCFormat = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||\n pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isASTCFormat = function (pixelFormat) {\n return pixelFormat === PixelFormat.RGBA_ASTC;\n};\n\n/**\n * @private\n */\nPixelFormat.isETC1Format = function (pixelFormat) {\n return pixelFormat === PixelFormat.RGB_ETC1;\n};\n\n/**\n * @private\n */\nPixelFormat.isETC2Format = function (pixelFormat) {\n return (\n pixelFormat === PixelFormat.RGB8_ETC2 ||\n pixelFormat === PixelFormat.RGBA8_ETC2_EAC\n );\n};\n\n/**\n * @private\n */\nPixelFormat.isBC7Format = function (pixelFormat) {\n return pixelFormat === PixelFormat.RGBA_BC7;\n};\n\n/**\n * @private\n */\nPixelFormat.compressedTextureSizeInBytes = function (\n pixelFormat,\n width,\n height\n) {\n switch (pixelFormat) {\n case PixelFormat.RGB_DXT1:\n case PixelFormat.RGBA_DXT1:\n case PixelFormat.RGB_ETC1:\n case PixelFormat.RGB8_ETC2:\n return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;\n\n case PixelFormat.RGBA_DXT3:\n case PixelFormat.RGBA_DXT5:\n case PixelFormat.RGBA_ASTC:\n case PixelFormat.RGBA8_ETC2_EAC:\n return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;\n\n case PixelFormat.RGB_PVRTC_4BPPV1:\n case PixelFormat.RGBA_PVRTC_4BPPV1:\n return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);\n\n case PixelFormat.RGB_PVRTC_2BPPV1:\n case PixelFormat.RGBA_PVRTC_2BPPV1:\n return Math.floor(\n (Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8\n );\n\n case PixelFormat.RGBA_BC7:\n return Math.ceil(width / 4) * Math.ceil(height / 4) * 16;\n\n default:\n return 0;\n }\n};\n\n/**\n * @private\n */\nPixelFormat.textureSizeInBytes = function (\n pixelFormat,\n pixelDatatype,\n width,\n height\n) {\n let componentsLength = PixelFormat.componentsLength(pixelFormat);\n if (PixelDatatype.isPacked(pixelDatatype)) {\n componentsLength = 1;\n }\n return (\n componentsLength * PixelDatatype.sizeInBytes(pixelDatatype) * width * height\n );\n};\n\n/**\n * @private\n */\nPixelFormat.alignmentInBytes = function (pixelFormat, pixelDatatype, width) {\n const mod =\n PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, 1) % 4;\n return mod === 0 ? 4 : mod === 2 ? 2 : 1;\n};\n\n/**\n * @private\n */\nPixelFormat.createTypedArray = function (\n pixelFormat,\n pixelDatatype,\n width,\n height\n) {\n let constructor;\n const sizeInBytes = PixelDatatype.sizeInBytes(pixelDatatype);\n if (sizeInBytes === Uint8Array.BYTES_PER_ELEMENT) {\n constructor = Uint8Array;\n } else if (sizeInBytes === Uint16Array.BYTES_PER_ELEMENT) {\n constructor = Uint16Array;\n } else if (\n sizeInBytes === Float32Array.BYTES_PER_ELEMENT &&\n pixelDatatype === PixelDatatype.FLOAT\n ) {\n constructor = Float32Array;\n } else {\n constructor = Uint32Array;\n }\n\n const size = PixelFormat.componentsLength(pixelFormat) * width * height;\n return new constructor(size);\n};\n\n/**\n * @private\n */\nPixelFormat.flipY = function (\n bufferView,\n pixelFormat,\n pixelDatatype,\n width,\n height\n) {\n if (height === 1) {\n return bufferView;\n }\n const flipped = PixelFormat.createTypedArray(\n pixelFormat,\n pixelDatatype,\n width,\n height\n );\n const numberOfComponents = PixelFormat.componentsLength(pixelFormat);\n const textureWidth = width * numberOfComponents;\n for (let i = 0; i < height; ++i) {\n const row = i * width * numberOfComponents;\n const flippedRow = (height - i - 1) * width * numberOfComponents;\n for (let j = 0; j < textureWidth; ++j) {\n flipped[flippedRow + j] = bufferView[row + j];\n }\n }\n return flipped;\n};\n\n/**\n * @private\n */\nPixelFormat.toInternalFormat = function (pixelFormat, pixelDatatype, context) {\n // WebGL 1 require internalFormat to be the same as PixelFormat\n if (!context.webgl2) {\n return pixelFormat;\n }\n\n // Convert pixelFormat to correct internalFormat for WebGL 2\n if (pixelFormat === PixelFormat.DEPTH_STENCIL) {\n return WebGLConstants.DEPTH24_STENCIL8;\n }\n\n if (pixelFormat === PixelFormat.DEPTH_COMPONENT) {\n if (pixelDatatype === PixelDatatype.UNSIGNED_SHORT) {\n return WebGLConstants.DEPTH_COMPONENT16;\n } else if (pixelDatatype === PixelDatatype.UNSIGNED_INT) {\n return WebGLConstants.DEPTH_COMPONENT24;\n }\n }\n\n if (pixelDatatype === PixelDatatype.FLOAT) {\n switch (pixelFormat) {\n case PixelFormat.RGBA:\n return WebGLConstants.RGBA32F;\n case PixelFormat.RGB:\n return WebGLConstants.RGB32F;\n case PixelFormat.RG:\n return WebGLConstants.RG32F;\n case PixelFormat.RED:\n return WebGLConstants.R32F;\n }\n }\n\n if (pixelDatatype === PixelDatatype.HALF_FLOAT) {\n switch (pixelFormat) {\n case PixelFormat.RGBA:\n return WebGLConstants.RGBA16F;\n case PixelFormat.RGB:\n return WebGLConstants.RGB16F;\n case PixelFormat.RG:\n return WebGLConstants.RG16F;\n case PixelFormat.RED:\n return WebGLConstants.R16F;\n }\n }\n\n return pixelFormat;\n};\n\nexport default Object.freeze(PixelFormat);\n", "/**\n * @private\n */\nconst ContextLimits = {\n _maximumCombinedTextureImageUnits: 0,\n _maximumCubeMapSize: 0,\n _maximumFragmentUniformVectors: 0,\n _maximumTextureImageUnits: 0,\n _maximumRenderbufferSize: 0,\n _maximumTextureSize: 0,\n _maximumVaryingVectors: 0,\n _maximumVertexAttributes: 0,\n _maximumVertexTextureImageUnits: 0,\n _maximumVertexUniformVectors: 0,\n _minimumAliasedLineWidth: 0,\n _maximumAliasedLineWidth: 0,\n _minimumAliasedPointSize: 0,\n _maximumAliasedPointSize: 0,\n _maximumViewportWidth: 0,\n _maximumViewportHeight: 0,\n _maximumTextureFilterAnisotropy: 0,\n _maximumDrawBuffers: 0,\n _maximumColorAttachments: 0,\n _maximumSamples: 0,\n _highpFloatSupported: false,\n _highpIntSupported: false,\n};\n\nObject.defineProperties(ContextLimits, {\n /**\n * The maximum number of texture units that can be used from the vertex and fragment\n * shader with this WebGL implementation. The minimum is eight. If both shaders access the\n * same texture unit, this counts as two texture units.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_COMBINED_TEXTURE_IMAGE_UNITS.\n */\n maximumCombinedTextureImageUnits: {\n get: function () {\n return ContextLimits._maximumCombinedTextureImageUnits;\n },\n },\n\n /**\n * The approximate maximum cube mape width and height supported by this WebGL implementation.\n * The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_CUBE_MAP_TEXTURE_SIZE.\n */\n maximumCubeMapSize: {\n get: function () {\n return ContextLimits._maximumCubeMapSize;\n },\n },\n\n /**\n * The maximum number of vec4, ivec4, and bvec4\n * uniforms that can be used by a fragment shader with this WebGL implementation. The minimum is 16.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_FRAGMENT_UNIFORM_VECTORS.\n */\n maximumFragmentUniformVectors: {\n get: function () {\n return ContextLimits._maximumFragmentUniformVectors;\n },\n },\n\n /**\n * The maximum number of texture units that can be used from the fragment shader with this WebGL implementation. The minimum is eight.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_TEXTURE_IMAGE_UNITS.\n */\n maximumTextureImageUnits: {\n get: function () {\n return ContextLimits._maximumTextureImageUnits;\n },\n },\n\n /**\n * The maximum renderbuffer width and height supported by this WebGL implementation.\n * The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_RENDERBUFFER_SIZE.\n */\n maximumRenderbufferSize: {\n get: function () {\n return ContextLimits._maximumRenderbufferSize;\n },\n },\n\n /**\n * The approximate maximum texture width and height supported by this WebGL implementation.\n * The minimum is 64, but most desktop and laptop implementations will support much larger sizes like 8,192.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_TEXTURE_SIZE.\n */\n maximumTextureSize: {\n get: function () {\n return ContextLimits._maximumTextureSize;\n },\n },\n\n /**\n * The maximum number of vec4 varying variables supported by this WebGL implementation.\n * The minimum is eight. Matrices and arrays count as multiple vec4s.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VARYING_VECTORS.\n */\n maximumVaryingVectors: {\n get: function () {\n return ContextLimits._maximumVaryingVectors;\n },\n },\n\n /**\n * The maximum number of vec4 vertex attributes supported by this WebGL implementation. The minimum is eight.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VERTEX_ATTRIBS.\n */\n maximumVertexAttributes: {\n get: function () {\n return ContextLimits._maximumVertexAttributes;\n },\n },\n\n /**\n * The maximum number of texture units that can be used from the vertex shader with this WebGL implementation.\n * The minimum is zero, which means the GL does not support vertex texture fetch.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VERTEX_TEXTURE_IMAGE_UNITS.\n */\n maximumVertexTextureImageUnits: {\n get: function () {\n return ContextLimits._maximumVertexTextureImageUnits;\n },\n },\n\n /**\n * The maximum number of vec4, ivec4, and bvec4\n * uniforms that can be used by a vertex shader with this WebGL implementation. The minimum is 16.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VERTEX_UNIFORM_VECTORS.\n */\n maximumVertexUniformVectors: {\n get: function () {\n return ContextLimits._maximumVertexUniformVectors;\n },\n },\n\n /**\n * The minimum aliased line width, in pixels, supported by this WebGL implementation. It will be at most one.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with ALIASED_LINE_WIDTH_RANGE.\n */\n minimumAliasedLineWidth: {\n get: function () {\n return ContextLimits._minimumAliasedLineWidth;\n },\n },\n\n /**\n * The maximum aliased line width, in pixels, supported by this WebGL implementation. It will be at least one.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with ALIASED_LINE_WIDTH_RANGE.\n */\n maximumAliasedLineWidth: {\n get: function () {\n return ContextLimits._maximumAliasedLineWidth;\n },\n },\n\n /**\n * The minimum aliased point size, in pixels, supported by this WebGL implementation. It will be at most one.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with ALIASED_POINT_SIZE_RANGE.\n */\n minimumAliasedPointSize: {\n get: function () {\n return ContextLimits._minimumAliasedPointSize;\n },\n },\n\n /**\n * The maximum aliased point size, in pixels, supported by this WebGL implementation. It will be at least one.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with ALIASED_POINT_SIZE_RANGE.\n */\n maximumAliasedPointSize: {\n get: function () {\n return ContextLimits._maximumAliasedPointSize;\n },\n },\n\n /**\n * The maximum supported width of the viewport. It will be at least as large as the visible width of the associated canvas.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VIEWPORT_DIMS.\n */\n maximumViewportWidth: {\n get: function () {\n return ContextLimits._maximumViewportWidth;\n },\n },\n\n /**\n * The maximum supported height of the viewport. It will be at least as large as the visible height of the associated canvas.\n * @memberof ContextLimits\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with MAX_VIEWPORT_DIMS.\n */\n maximumViewportHeight: {\n get: function () {\n return ContextLimits._maximumViewportHeight;\n },\n },\n\n /**\n * The maximum degree of anisotropy for texture filtering\n * @memberof ContextLimits\n * @type {number}\n */\n maximumTextureFilterAnisotropy: {\n get: function () {\n return ContextLimits._maximumTextureFilterAnisotropy;\n },\n },\n\n /**\n * The maximum number of simultaneous outputs that may be written in a fragment shader.\n * @memberof ContextLimits\n * @type {number}\n */\n maximumDrawBuffers: {\n get: function () {\n return ContextLimits._maximumDrawBuffers;\n },\n },\n\n /**\n * The maximum number of color attachments supported.\n * @memberof ContextLimits\n * @type {number}\n */\n maximumColorAttachments: {\n get: function () {\n return ContextLimits._maximumColorAttachments;\n },\n },\n\n /**\n * The maximum number of samples supported for multisampling.\n * @memberof ContextLimits\n * @type {number}\n */\n maximumSamples: {\n get: function () {\n return ContextLimits._maximumSamples;\n },\n },\n\n /**\n * High precision float supported (highp) in fragment shaders.\n * @memberof ContextLimits\n * @type {boolean}\n */\n highpFloatSupported: {\n get: function () {\n return ContextLimits._highpFloatSupported;\n },\n },\n\n /**\n * High precision int supported (highp) in fragment shaders.\n * @memberof ContextLimits\n * @type {boolean}\n */\n highpIntSupported: {\n get: function () {\n return ContextLimits._highpIntSupported;\n },\n },\n});\nexport default ContextLimits;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\n\nfunction attachTexture(framebuffer, attachment, texture) {\n const gl = framebuffer._gl;\n gl.framebufferTexture2D(\n gl.FRAMEBUFFER,\n attachment,\n texture._target,\n texture._texture,\n 0\n );\n}\n\nfunction attachRenderbuffer(framebuffer, attachment, renderbuffer) {\n const gl = framebuffer._gl;\n gl.framebufferRenderbuffer(\n gl.FRAMEBUFFER,\n attachment,\n gl.RENDERBUFFER,\n renderbuffer._getRenderbuffer()\n );\n}\n\n/**\n * Creates a framebuffer with optional initial color, depth, and stencil attachments.\n * Framebuffers are used for render-to-texture effects; they allow us to render to\n * textures in one pass, and read from it in a later pass.\n *\n * @param {object} options The initial framebuffer attachments as shown in the example below. context is required. The possible properties are colorTextures, colorRenderbuffers, depthTexture, depthRenderbuffer, stencilRenderbuffer, depthStencilTexture, depthStencilRenderbuffer, and destroyAttachments.\n *\n * @exception {DeveloperError} Cannot have both color texture and color renderbuffer attachments.\n * @exception {DeveloperError} Cannot have both a depth texture and depth renderbuffer attachment.\n * @exception {DeveloperError} Cannot have both a depth-stencil texture and depth-stencil renderbuffer attachment.\n * @exception {DeveloperError} Cannot have both a depth and depth-stencil renderbuffer.\n * @exception {DeveloperError} Cannot have both a stencil and depth-stencil renderbuffer.\n * @exception {DeveloperError} Cannot have both a depth and stencil renderbuffer.\n * @exception {DeveloperError} The color-texture pixel-format must be a color format.\n * @exception {DeveloperError} The depth-texture pixel-format must be DEPTH_COMPONENT.\n * @exception {DeveloperError} The depth-stencil-texture pixel-format must be DEPTH_STENCIL.\n * @exception {DeveloperError} The number of color attachments exceeds the number supported.\n * @exception {DeveloperError} The color-texture pixel datatype is HALF_FLOAT and the WebGL implementation does not support the EXT_color_buffer_half_float extension.\n * @exception {DeveloperError} The color-texture pixel datatype is FLOAT and the WebGL implementation does not support the EXT_color_buffer_float or WEBGL_color_buffer_float extensions.\n *\n * @example\n * // Create a framebuffer with color and depth texture attachments.\n * const width = context.canvas.clientWidth;\n * const height = context.canvas.clientHeight;\n * const framebuffer = new Framebuffer({\n * context : context,\n * colorTextures : [new Texture({\n * context : context,\n * width : width,\n * height : height,\n * pixelFormat : PixelFormat.RGBA\n * })],\n * depthTexture : new Texture({\n * context : context,\n * width : width,\n * height : height,\n * pixelFormat : PixelFormat.DEPTH_COMPONENT,\n * pixelDatatype : PixelDatatype.UNSIGNED_SHORT\n * })\n * });\n *\n * @private\n * @constructor\n */\nfunction Framebuffer(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const context = options.context;\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", context);\n //>>includeEnd('debug');\n\n const gl = context._gl;\n const maximumColorAttachments = ContextLimits.maximumColorAttachments;\n\n this._gl = gl;\n this._framebuffer = gl.createFramebuffer();\n\n this._colorTextures = [];\n this._colorRenderbuffers = [];\n this._activeColorAttachments = [];\n\n this._depthTexture = undefined;\n this._depthRenderbuffer = undefined;\n this._stencilRenderbuffer = undefined;\n this._depthStencilTexture = undefined;\n this._depthStencilRenderbuffer = undefined;\n\n /**\n * When true, the framebuffer owns its attachments so they will be destroyed when\n * {@link Framebuffer#destroy} is called or when a new attachment is assigned\n * to an attachment point.\n *\n * @type {boolean}\n * @default true\n *\n * @see Framebuffer#destroy\n */\n this.destroyAttachments = defaultValue(options.destroyAttachments, true);\n\n // Throw if a texture and renderbuffer are attached to the same point. This won't\n // cause a WebGL error (because only one will be attached), but is likely a developer error.\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(options.colorTextures) && defined(options.colorRenderbuffers)) {\n throw new DeveloperError(\n \"Cannot have both color texture and color renderbuffer attachments.\"\n );\n }\n if (defined(options.depthTexture) && defined(options.depthRenderbuffer)) {\n throw new DeveloperError(\n \"Cannot have both a depth texture and depth renderbuffer attachment.\"\n );\n }\n if (\n defined(options.depthStencilTexture) &&\n defined(options.depthStencilRenderbuffer)\n ) {\n throw new DeveloperError(\n \"Cannot have both a depth-stencil texture and depth-stencil renderbuffer attachment.\"\n );\n }\n //>>includeEnd('debug');\n\n // Avoid errors defined in Section 6.5 of the WebGL spec\n const depthAttachment =\n defined(options.depthTexture) || defined(options.depthRenderbuffer);\n const depthStencilAttachment =\n defined(options.depthStencilTexture) ||\n defined(options.depthStencilRenderbuffer);\n\n //>>includeStart('debug', pragmas.debug);\n if (depthAttachment && depthStencilAttachment) {\n throw new DeveloperError(\n \"Cannot have both a depth and depth-stencil attachment.\"\n );\n }\n if (defined(options.stencilRenderbuffer) && depthStencilAttachment) {\n throw new DeveloperError(\n \"Cannot have both a stencil and depth-stencil attachment.\"\n );\n }\n if (depthAttachment && defined(options.stencilRenderbuffer)) {\n throw new DeveloperError(\n \"Cannot have both a depth and stencil attachment.\"\n );\n }\n //>>includeEnd('debug');\n\n ///////////////////////////////////////////////////////////////////\n\n this._bind();\n\n let texture;\n let renderbuffer;\n let i;\n let length;\n let attachmentEnum;\n\n if (defined(options.colorTextures)) {\n const textures = options.colorTextures;\n length = this._colorTextures.length = this._activeColorAttachments.length =\n textures.length;\n\n //>>includeStart('debug', pragmas.debug);\n if (length > maximumColorAttachments) {\n throw new DeveloperError(\n \"The number of color attachments exceeds the number supported.\"\n );\n }\n //>>includeEnd('debug');\n\n for (i = 0; i < length; ++i) {\n texture = textures[i];\n\n //>>includeStart('debug', pragmas.debug);\n if (!PixelFormat.isColorFormat(texture.pixelFormat)) {\n throw new DeveloperError(\n \"The color-texture pixel-format must be a color format.\"\n );\n }\n if (\n texture.pixelDatatype === PixelDatatype.FLOAT &&\n !context.colorBufferFloat\n ) {\n throw new DeveloperError(\n \"The color texture pixel datatype is FLOAT and the WebGL implementation does not support the EXT_color_buffer_float or WEBGL_color_buffer_float extensions. See Context.colorBufferFloat.\"\n );\n }\n if (\n texture.pixelDatatype === PixelDatatype.HALF_FLOAT &&\n !context.colorBufferHalfFloat\n ) {\n throw new DeveloperError(\n \"The color texture pixel datatype is HALF_FLOAT and the WebGL implementation does not support the EXT_color_buffer_half_float extension. See Context.colorBufferHalfFloat.\"\n );\n }\n //>>includeEnd('debug');\n\n attachmentEnum = this._gl.COLOR_ATTACHMENT0 + i;\n attachTexture(this, attachmentEnum, texture);\n this._activeColorAttachments[i] = attachmentEnum;\n this._colorTextures[i] = texture;\n }\n }\n\n if (defined(options.colorRenderbuffers)) {\n const renderbuffers = options.colorRenderbuffers;\n length = this._colorRenderbuffers.length = this._activeColorAttachments.length =\n renderbuffers.length;\n\n //>>includeStart('debug', pragmas.debug);\n if (length > maximumColorAttachments) {\n throw new DeveloperError(\n \"The number of color attachments exceeds the number supported.\"\n );\n }\n //>>includeEnd('debug');\n\n for (i = 0; i < length; ++i) {\n renderbuffer = renderbuffers[i];\n attachmentEnum = this._gl.COLOR_ATTACHMENT0 + i;\n attachRenderbuffer(this, attachmentEnum, renderbuffer);\n this._activeColorAttachments[i] = attachmentEnum;\n this._colorRenderbuffers[i] = renderbuffer;\n }\n }\n\n if (defined(options.depthTexture)) {\n texture = options.depthTexture;\n\n //>>includeStart('debug', pragmas.debug);\n if (texture.pixelFormat !== PixelFormat.DEPTH_COMPONENT) {\n throw new DeveloperError(\n \"The depth-texture pixel-format must be DEPTH_COMPONENT.\"\n );\n }\n //>>includeEnd('debug');\n\n attachTexture(this, this._gl.DEPTH_ATTACHMENT, texture);\n this._depthTexture = texture;\n }\n\n if (defined(options.depthRenderbuffer)) {\n renderbuffer = options.depthRenderbuffer;\n attachRenderbuffer(this, this._gl.DEPTH_ATTACHMENT, renderbuffer);\n this._depthRenderbuffer = renderbuffer;\n }\n\n if (defined(options.stencilRenderbuffer)) {\n renderbuffer = options.stencilRenderbuffer;\n attachRenderbuffer(this, this._gl.STENCIL_ATTACHMENT, renderbuffer);\n this._stencilRenderbuffer = renderbuffer;\n }\n\n if (defined(options.depthStencilTexture)) {\n texture = options.depthStencilTexture;\n\n //>>includeStart('debug', pragmas.debug);\n if (texture.pixelFormat !== PixelFormat.DEPTH_STENCIL) {\n throw new DeveloperError(\n \"The depth-stencil pixel-format must be DEPTH_STENCIL.\"\n );\n }\n //>>includeEnd('debug');\n\n attachTexture(this, this._gl.DEPTH_STENCIL_ATTACHMENT, texture);\n this._depthStencilTexture = texture;\n }\n\n if (defined(options.depthStencilRenderbuffer)) {\n renderbuffer = options.depthStencilRenderbuffer;\n attachRenderbuffer(this, this._gl.DEPTH_STENCIL_ATTACHMENT, renderbuffer);\n this._depthStencilRenderbuffer = renderbuffer;\n }\n\n this._unBind();\n}\n\nObject.defineProperties(Framebuffer.prototype, {\n /**\n * The status of the framebuffer. If the status is not WebGLConstants.FRAMEBUFFER_COMPLETE,\n * a {@link DeveloperError} will be thrown when attempting to render to the framebuffer.\n * @memberof Framebuffer.prototype\n * @type {number}\n */\n status: {\n get: function () {\n this._bind();\n const status = this._gl.checkFramebufferStatus(this._gl.FRAMEBUFFER);\n this._unBind();\n return status;\n },\n },\n numberOfColorAttachments: {\n get: function () {\n return this._activeColorAttachments.length;\n },\n },\n depthTexture: {\n get: function () {\n return this._depthTexture;\n },\n },\n depthRenderbuffer: {\n get: function () {\n return this._depthRenderbuffer;\n },\n },\n stencilRenderbuffer: {\n get: function () {\n return this._stencilRenderbuffer;\n },\n },\n depthStencilTexture: {\n get: function () {\n return this._depthStencilTexture;\n },\n },\n depthStencilRenderbuffer: {\n get: function () {\n return this._depthStencilRenderbuffer;\n },\n },\n\n /**\n * True if the framebuffer has a depth attachment. Depth attachments include\n * depth and depth-stencil textures, and depth and depth-stencil renderbuffers. When\n * rendering to a framebuffer, a depth attachment is required for the depth test to have effect.\n * @memberof Framebuffer.prototype\n * @type {boolean}\n */\n hasDepthAttachment: {\n get: function () {\n return !!(\n this.depthTexture ||\n this.depthRenderbuffer ||\n this.depthStencilTexture ||\n this.depthStencilRenderbuffer\n );\n },\n },\n});\n\nFramebuffer.prototype._bind = function () {\n const gl = this._gl;\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);\n};\n\nFramebuffer.prototype._unBind = function () {\n const gl = this._gl;\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n};\n\nFramebuffer.prototype.bindDraw = function () {\n const gl = this._gl;\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this._framebuffer);\n};\n\nFramebuffer.prototype.bindRead = function () {\n const gl = this._gl;\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._framebuffer);\n};\n\nFramebuffer.prototype._getActiveColorAttachments = function () {\n return this._activeColorAttachments;\n};\n\nFramebuffer.prototype.getColorTexture = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index) || index < 0 || index >= this._colorTextures.length) {\n throw new DeveloperError(\n \"index is required, must be greater than or equal to zero and must be less than the number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n\n return this._colorTextures[index];\n};\n\nFramebuffer.prototype.getColorRenderbuffer = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(index) ||\n index < 0 ||\n index >= this._colorRenderbuffers.length\n ) {\n throw new DeveloperError(\n \"index is required, must be greater than or equal to zero and must be less than the number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n\n return this._colorRenderbuffers[index];\n};\n\nFramebuffer.prototype.isDestroyed = function () {\n return false;\n};\n\nFramebuffer.prototype.destroy = function () {\n if (this.destroyAttachments) {\n // If the color texture is a cube map face, it is owned by the cube map, and will not be destroyed.\n let i = 0;\n const textures = this._colorTextures;\n let length = textures.length;\n for (; i < length; ++i) {\n const texture = textures[i];\n if (defined(texture)) {\n texture.destroy();\n }\n }\n\n const renderbuffers = this._colorRenderbuffers;\n length = renderbuffers.length;\n for (i = 0; i < length; ++i) {\n const renderbuffer = renderbuffers[i];\n if (defined(renderbuffer)) {\n renderbuffer.destroy();\n }\n }\n\n this._depthTexture = this._depthTexture && this._depthTexture.destroy();\n this._depthRenderbuffer =\n this._depthRenderbuffer && this._depthRenderbuffer.destroy();\n this._stencilRenderbuffer =\n this._stencilRenderbuffer && this._stencilRenderbuffer.destroy();\n this._depthStencilTexture =\n this._depthStencilTexture && this._depthStencilTexture.destroy();\n this._depthStencilRenderbuffer =\n this._depthStencilRenderbuffer &&\n this._depthStencilRenderbuffer.destroy();\n }\n\n this._gl.deleteFramebuffer(this._framebuffer);\n return destroyObject(this);\n};\nexport default Framebuffer;\n", "import WebGLConstants from \"./WebGLConstants.js\";\n\n/**\n * Winding order defines the order of vertices for a triangle to be considered front-facing.\n *\n * @enum {number}\n */\nconst WindingOrder = {\n /**\n * Vertices are in clockwise order.\n *\n * @type {number}\n * @constant\n */\n CLOCKWISE: WebGLConstants.CW,\n\n /**\n * Vertices are in counter-clockwise order.\n *\n * @type {number}\n * @constant\n */\n COUNTER_CLOCKWISE: WebGLConstants.CCW,\n};\n\n/**\n * @private\n */\nWindingOrder.validate = function (windingOrder) {\n return (\n windingOrder === WindingOrder.CLOCKWISE ||\n windingOrder === WindingOrder.COUNTER_CLOCKWISE\n );\n};\n\nexport default Object.freeze(WindingOrder);\n", "/**\n * Returns frozen renderState as well as all of the object literal properties. This function is deep object freeze\n * function ignoring properties named \"_applyFunctions\".\n *\n * @private\n *\n * @param {object} renderState\n * @returns {object} Returns frozen renderState.\n *\n */\nfunction freezeRenderState(renderState) {\n if (typeof renderState !== \"object\" || renderState === null) {\n return renderState;\n }\n\n let propName;\n const propNames = Object.keys(renderState);\n\n for (let i = 0; i < propNames.length; i++) {\n propName = propNames[i];\n if (\n renderState.hasOwnProperty(propName) &&\n propName !== \"_applyFunctions\"\n ) {\n renderState[propName] = freezeRenderState(renderState[propName]);\n }\n }\n return Object.freeze(renderState);\n}\nexport default freezeRenderState;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\nimport WindingOrder from \"../Core/WindingOrder.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport freezeRenderState from \"./freezeRenderState.js\";\n\nfunction validateBlendEquation(blendEquation) {\n return (\n blendEquation === WebGLConstants.FUNC_ADD ||\n blendEquation === WebGLConstants.FUNC_SUBTRACT ||\n blendEquation === WebGLConstants.FUNC_REVERSE_SUBTRACT ||\n blendEquation === WebGLConstants.MIN ||\n blendEquation === WebGLConstants.MAX\n );\n}\n\nfunction validateBlendFunction(blendFunction) {\n return (\n blendFunction === WebGLConstants.ZERO ||\n blendFunction === WebGLConstants.ONE ||\n blendFunction === WebGLConstants.SRC_COLOR ||\n blendFunction === WebGLConstants.ONE_MINUS_SRC_COLOR ||\n blendFunction === WebGLConstants.DST_COLOR ||\n blendFunction === WebGLConstants.ONE_MINUS_DST_COLOR ||\n blendFunction === WebGLConstants.SRC_ALPHA ||\n blendFunction === WebGLConstants.ONE_MINUS_SRC_ALPHA ||\n blendFunction === WebGLConstants.DST_ALPHA ||\n blendFunction === WebGLConstants.ONE_MINUS_DST_ALPHA ||\n blendFunction === WebGLConstants.CONSTANT_COLOR ||\n blendFunction === WebGLConstants.ONE_MINUS_CONSTANT_COLOR ||\n blendFunction === WebGLConstants.CONSTANT_ALPHA ||\n blendFunction === WebGLConstants.ONE_MINUS_CONSTANT_ALPHA ||\n blendFunction === WebGLConstants.SRC_ALPHA_SATURATE\n );\n}\n\nfunction validateCullFace(cullFace) {\n return (\n cullFace === WebGLConstants.FRONT ||\n cullFace === WebGLConstants.BACK ||\n cullFace === WebGLConstants.FRONT_AND_BACK\n );\n}\n\nfunction validateDepthFunction(depthFunction) {\n return (\n depthFunction === WebGLConstants.NEVER ||\n depthFunction === WebGLConstants.LESS ||\n depthFunction === WebGLConstants.EQUAL ||\n depthFunction === WebGLConstants.LEQUAL ||\n depthFunction === WebGLConstants.GREATER ||\n depthFunction === WebGLConstants.NOTEQUAL ||\n depthFunction === WebGLConstants.GEQUAL ||\n depthFunction === WebGLConstants.ALWAYS\n );\n}\n\nfunction validateStencilFunction(stencilFunction) {\n return (\n stencilFunction === WebGLConstants.NEVER ||\n stencilFunction === WebGLConstants.LESS ||\n stencilFunction === WebGLConstants.EQUAL ||\n stencilFunction === WebGLConstants.LEQUAL ||\n stencilFunction === WebGLConstants.GREATER ||\n stencilFunction === WebGLConstants.NOTEQUAL ||\n stencilFunction === WebGLConstants.GEQUAL ||\n stencilFunction === WebGLConstants.ALWAYS\n );\n}\n\nfunction validateStencilOperation(stencilOperation) {\n return (\n stencilOperation === WebGLConstants.ZERO ||\n stencilOperation === WebGLConstants.KEEP ||\n stencilOperation === WebGLConstants.REPLACE ||\n stencilOperation === WebGLConstants.INCR ||\n stencilOperation === WebGLConstants.DECR ||\n stencilOperation === WebGLConstants.INVERT ||\n stencilOperation === WebGLConstants.INCR_WRAP ||\n stencilOperation === WebGLConstants.DECR_WRAP\n );\n}\n\n/**\n * @private\n */\nfunction RenderState(renderState) {\n const rs = defaultValue(renderState, defaultValue.EMPTY_OBJECT);\n const cull = defaultValue(rs.cull, defaultValue.EMPTY_OBJECT);\n const polygonOffset = defaultValue(\n rs.polygonOffset,\n defaultValue.EMPTY_OBJECT\n );\n const scissorTest = defaultValue(rs.scissorTest, defaultValue.EMPTY_OBJECT);\n const scissorTestRectangle = defaultValue(\n scissorTest.rectangle,\n defaultValue.EMPTY_OBJECT\n );\n const depthRange = defaultValue(rs.depthRange, defaultValue.EMPTY_OBJECT);\n const depthTest = defaultValue(rs.depthTest, defaultValue.EMPTY_OBJECT);\n const colorMask = defaultValue(rs.colorMask, defaultValue.EMPTY_OBJECT);\n const blending = defaultValue(rs.blending, defaultValue.EMPTY_OBJECT);\n const blendingColor = defaultValue(blending.color, defaultValue.EMPTY_OBJECT);\n const stencilTest = defaultValue(rs.stencilTest, defaultValue.EMPTY_OBJECT);\n const stencilTestFrontOperation = defaultValue(\n stencilTest.frontOperation,\n defaultValue.EMPTY_OBJECT\n );\n const stencilTestBackOperation = defaultValue(\n stencilTest.backOperation,\n defaultValue.EMPTY_OBJECT\n );\n const sampleCoverage = defaultValue(\n rs.sampleCoverage,\n defaultValue.EMPTY_OBJECT\n );\n const viewport = rs.viewport;\n\n this.frontFace = defaultValue(rs.frontFace, WindingOrder.COUNTER_CLOCKWISE);\n this.cull = {\n enabled: defaultValue(cull.enabled, false),\n face: defaultValue(cull.face, WebGLConstants.BACK),\n };\n this.lineWidth = defaultValue(rs.lineWidth, 1.0);\n this.polygonOffset = {\n enabled: defaultValue(polygonOffset.enabled, false),\n factor: defaultValue(polygonOffset.factor, 0),\n units: defaultValue(polygonOffset.units, 0),\n };\n this.scissorTest = {\n enabled: defaultValue(scissorTest.enabled, false),\n rectangle: BoundingRectangle.clone(scissorTestRectangle),\n };\n this.depthRange = {\n near: defaultValue(depthRange.near, 0),\n far: defaultValue(depthRange.far, 1),\n };\n this.depthTest = {\n enabled: defaultValue(depthTest.enabled, false),\n func: defaultValue(depthTest.func, WebGLConstants.LESS), // func, because function is a JavaScript keyword\n };\n this.colorMask = {\n red: defaultValue(colorMask.red, true),\n green: defaultValue(colorMask.green, true),\n blue: defaultValue(colorMask.blue, true),\n alpha: defaultValue(colorMask.alpha, true),\n };\n this.depthMask = defaultValue(rs.depthMask, true);\n this.stencilMask = defaultValue(rs.stencilMask, ~0);\n this.blending = {\n enabled: defaultValue(blending.enabled, false),\n color: new Color(\n defaultValue(blendingColor.red, 0.0),\n defaultValue(blendingColor.green, 0.0),\n defaultValue(blendingColor.blue, 0.0),\n defaultValue(blendingColor.alpha, 0.0)\n ),\n equationRgb: defaultValue(blending.equationRgb, WebGLConstants.FUNC_ADD),\n equationAlpha: defaultValue(\n blending.equationAlpha,\n WebGLConstants.FUNC_ADD\n ),\n functionSourceRgb: defaultValue(\n blending.functionSourceRgb,\n WebGLConstants.ONE\n ),\n functionSourceAlpha: defaultValue(\n blending.functionSourceAlpha,\n WebGLConstants.ONE\n ),\n functionDestinationRgb: defaultValue(\n blending.functionDestinationRgb,\n WebGLConstants.ZERO\n ),\n functionDestinationAlpha: defaultValue(\n blending.functionDestinationAlpha,\n WebGLConstants.ZERO\n ),\n };\n this.stencilTest = {\n enabled: defaultValue(stencilTest.enabled, false),\n frontFunction: defaultValue(\n stencilTest.frontFunction,\n WebGLConstants.ALWAYS\n ),\n backFunction: defaultValue(stencilTest.backFunction, WebGLConstants.ALWAYS),\n reference: defaultValue(stencilTest.reference, 0),\n mask: defaultValue(stencilTest.mask, ~0),\n frontOperation: {\n fail: defaultValue(stencilTestFrontOperation.fail, WebGLConstants.KEEP),\n zFail: defaultValue(stencilTestFrontOperation.zFail, WebGLConstants.KEEP),\n zPass: defaultValue(stencilTestFrontOperation.zPass, WebGLConstants.KEEP),\n },\n backOperation: {\n fail: defaultValue(stencilTestBackOperation.fail, WebGLConstants.KEEP),\n zFail: defaultValue(stencilTestBackOperation.zFail, WebGLConstants.KEEP),\n zPass: defaultValue(stencilTestBackOperation.zPass, WebGLConstants.KEEP),\n },\n };\n this.sampleCoverage = {\n enabled: defaultValue(sampleCoverage.enabled, false),\n value: defaultValue(sampleCoverage.value, 1.0),\n invert: defaultValue(sampleCoverage.invert, false),\n };\n this.viewport = defined(viewport)\n ? new BoundingRectangle(\n viewport.x,\n viewport.y,\n viewport.width,\n viewport.height\n )\n : undefined;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n this.lineWidth < ContextLimits.minimumAliasedLineWidth ||\n this.lineWidth > ContextLimits.maximumAliasedLineWidth\n ) {\n throw new DeveloperError(\n \"renderState.lineWidth is out of range. Check minimumAliasedLineWidth and maximumAliasedLineWidth.\"\n );\n }\n if (!WindingOrder.validate(this.frontFace)) {\n throw new DeveloperError(\"Invalid renderState.frontFace.\");\n }\n if (!validateCullFace(this.cull.face)) {\n throw new DeveloperError(\"Invalid renderState.cull.face.\");\n }\n if (\n this.scissorTest.rectangle.width < 0 ||\n this.scissorTest.rectangle.height < 0\n ) {\n throw new DeveloperError(\n \"renderState.scissorTest.rectangle.width and renderState.scissorTest.rectangle.height must be greater than or equal to zero.\"\n );\n }\n if (this.depthRange.near > this.depthRange.far) {\n // WebGL specific - not an error in GL ES\n throw new DeveloperError(\n \"renderState.depthRange.near can not be greater than renderState.depthRange.far.\"\n );\n }\n if (this.depthRange.near < 0) {\n // Would be clamped by GL\n throw new DeveloperError(\n \"renderState.depthRange.near must be greater than or equal to zero.\"\n );\n }\n if (this.depthRange.far > 1) {\n // Would be clamped by GL\n throw new DeveloperError(\n \"renderState.depthRange.far must be less than or equal to one.\"\n );\n }\n if (!validateDepthFunction(this.depthTest.func)) {\n throw new DeveloperError(\"Invalid renderState.depthTest.func.\");\n }\n if (\n this.blending.color.red < 0.0 ||\n this.blending.color.red > 1.0 ||\n this.blending.color.green < 0.0 ||\n this.blending.color.green > 1.0 ||\n this.blending.color.blue < 0.0 ||\n this.blending.color.blue > 1.0 ||\n this.blending.color.alpha < 0.0 ||\n this.blending.color.alpha > 1.0\n ) {\n // Would be clamped by GL\n throw new DeveloperError(\n \"renderState.blending.color components must be greater than or equal to zero and less than or equal to one.\"\n );\n }\n if (!validateBlendEquation(this.blending.equationRgb)) {\n throw new DeveloperError(\"Invalid renderState.blending.equationRgb.\");\n }\n if (!validateBlendEquation(this.blending.equationAlpha)) {\n throw new DeveloperError(\"Invalid renderState.blending.equationAlpha.\");\n }\n if (!validateBlendFunction(this.blending.functionSourceRgb)) {\n throw new DeveloperError(\"Invalid renderState.blending.functionSourceRgb.\");\n }\n if (!validateBlendFunction(this.blending.functionSourceAlpha)) {\n throw new DeveloperError(\n \"Invalid renderState.blending.functionSourceAlpha.\"\n );\n }\n if (!validateBlendFunction(this.blending.functionDestinationRgb)) {\n throw new DeveloperError(\n \"Invalid renderState.blending.functionDestinationRgb.\"\n );\n }\n if (!validateBlendFunction(this.blending.functionDestinationAlpha)) {\n throw new DeveloperError(\n \"Invalid renderState.blending.functionDestinationAlpha.\"\n );\n }\n if (!validateStencilFunction(this.stencilTest.frontFunction)) {\n throw new DeveloperError(\"Invalid renderState.stencilTest.frontFunction.\");\n }\n if (!validateStencilFunction(this.stencilTest.backFunction)) {\n throw new DeveloperError(\"Invalid renderState.stencilTest.backFunction.\");\n }\n if (!validateStencilOperation(this.stencilTest.frontOperation.fail)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.frontOperation.fail.\"\n );\n }\n if (!validateStencilOperation(this.stencilTest.frontOperation.zFail)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.frontOperation.zFail.\"\n );\n }\n if (!validateStencilOperation(this.stencilTest.frontOperation.zPass)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.frontOperation.zPass.\"\n );\n }\n if (!validateStencilOperation(this.stencilTest.backOperation.fail)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.backOperation.fail.\"\n );\n }\n if (!validateStencilOperation(this.stencilTest.backOperation.zFail)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.backOperation.zFail.\"\n );\n }\n if (!validateStencilOperation(this.stencilTest.backOperation.zPass)) {\n throw new DeveloperError(\n \"Invalid renderState.stencilTest.backOperation.zPass.\"\n );\n }\n\n if (defined(this.viewport)) {\n if (this.viewport.width < 0) {\n throw new DeveloperError(\n \"renderState.viewport.width must be greater than or equal to zero.\"\n );\n }\n if (this.viewport.height < 0) {\n throw new DeveloperError(\n \"renderState.viewport.height must be greater than or equal to zero.\"\n );\n }\n\n if (this.viewport.width > ContextLimits.maximumViewportWidth) {\n throw new DeveloperError(\n `renderState.viewport.width must be less than or equal to the maximum viewport width (${ContextLimits.maximumViewportWidth.toString()}). Check maximumViewportWidth.`\n );\n }\n if (this.viewport.height > ContextLimits.maximumViewportHeight) {\n throw new DeveloperError(\n `renderState.viewport.height must be less than or equal to the maximum viewport height (${ContextLimits.maximumViewportHeight.toString()}). Check maximumViewportHeight.`\n );\n }\n }\n //>>includeEnd('debug');\n\n this.id = 0;\n this._applyFunctions = [];\n}\n\nlet nextRenderStateId = 0;\nlet renderStateCache = {};\n\n/**\n * Validates and then finds or creates an immutable render state, which defines the pipeline\n * state for a {@link DrawCommand} or {@link ClearCommand}. All inputs states are optional. Omitted states\n * use the defaults shown in the example below.\n *\n * @param {object} [renderState] The states defining the render state as shown in the example below.\n *\n * @exception {RuntimeError} renderState.lineWidth is out of range.\n * @exception {DeveloperError} Invalid renderState.frontFace.\n * @exception {DeveloperError} Invalid renderState.cull.face.\n * @exception {DeveloperError} scissorTest.rectangle.width and scissorTest.rectangle.height must be greater than or equal to zero.\n * @exception {DeveloperError} renderState.depthRange.near can't be greater than renderState.depthRange.far.\n * @exception {DeveloperError} renderState.depthRange.near must be greater than or equal to zero.\n * @exception {DeveloperError} renderState.depthRange.far must be less than or equal to zero.\n * @exception {DeveloperError} Invalid renderState.depthTest.func.\n * @exception {DeveloperError} renderState.blending.color components must be greater than or equal to zero and less than or equal to one\n * @exception {DeveloperError} Invalid renderState.blending.equationRgb.\n * @exception {DeveloperError} Invalid renderState.blending.equationAlpha.\n * @exception {DeveloperError} Invalid renderState.blending.functionSourceRgb.\n * @exception {DeveloperError} Invalid renderState.blending.functionSourceAlpha.\n * @exception {DeveloperError} Invalid renderState.blending.functionDestinationRgb.\n * @exception {DeveloperError} Invalid renderState.blending.functionDestinationAlpha.\n * @exception {DeveloperError} Invalid renderState.stencilTest.frontFunction.\n * @exception {DeveloperError} Invalid renderState.stencilTest.backFunction.\n * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.fail.\n * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.zFail.\n * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.zPass.\n * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.fail.\n * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.zFail.\n * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.zPass.\n * @exception {DeveloperError} renderState.viewport.width must be greater than or equal to zero.\n * @exception {DeveloperError} renderState.viewport.width must be less than or equal to the maximum viewport width.\n * @exception {DeveloperError} renderState.viewport.height must be greater than or equal to zero.\n * @exception {DeveloperError} renderState.viewport.height must be less than or equal to the maximum viewport height.\n *\n *\n * @example\n * const defaults = {\n * frontFace : WindingOrder.COUNTER_CLOCKWISE,\n * cull : {\n * enabled : false,\n * face : CullFace.BACK\n * },\n * lineWidth : 1,\n * polygonOffset : {\n * enabled : false,\n * factor : 0,\n * units : 0\n * },\n * scissorTest : {\n * enabled : false,\n * rectangle : {\n * x : 0,\n * y : 0,\n * width : 0,\n * height : 0\n * }\n * },\n * depthRange : {\n * near : 0,\n * far : 1\n * },\n * depthTest : {\n * enabled : false,\n * func : DepthFunction.LESS\n * },\n * colorMask : {\n * red : true,\n * green : true,\n * blue : true,\n * alpha : true\n * },\n * depthMask : true,\n * stencilMask : ~0,\n * blending : {\n * enabled : false,\n * color : {\n * red : 0.0,\n * green : 0.0,\n * blue : 0.0,\n * alpha : 0.0\n * },\n * equationRgb : BlendEquation.ADD,\n * equationAlpha : BlendEquation.ADD,\n * functionSourceRgb : BlendFunction.ONE,\n * functionSourceAlpha : BlendFunction.ONE,\n * functionDestinationRgb : BlendFunction.ZERO,\n * functionDestinationAlpha : BlendFunction.ZERO\n * },\n * stencilTest : {\n * enabled : false,\n * frontFunction : StencilFunction.ALWAYS,\n * backFunction : StencilFunction.ALWAYS,\n * reference : 0,\n * mask : ~0,\n * frontOperation : {\n * fail : StencilOperation.KEEP,\n * zFail : StencilOperation.KEEP,\n * zPass : StencilOperation.KEEP\n * },\n * backOperation : {\n * fail : StencilOperation.KEEP,\n * zFail : StencilOperation.KEEP,\n * zPass : StencilOperation.KEEP\n * }\n * },\n * sampleCoverage : {\n * enabled : false,\n * value : 1.0,\n * invert : false\n * }\n * };\n *\n * const rs = RenderState.fromCache(defaults);\n *\n * @see DrawCommand\n * @see ClearCommand\n *\n * @private\n */\nRenderState.fromCache = function (renderState) {\n const partialKey = JSON.stringify(renderState);\n let cachedState = renderStateCache[partialKey];\n if (defined(cachedState)) {\n ++cachedState.referenceCount;\n return cachedState.state;\n }\n\n // Cache miss. Fully define render state and try again.\n let states = new RenderState(renderState);\n const fullKey = JSON.stringify(states);\n cachedState = renderStateCache[fullKey];\n if (!defined(cachedState)) {\n states.id = nextRenderStateId++;\n //>>includeStart('debug', pragmas.debug);\n states = freezeRenderState(states);\n //>>includeEnd('debug');\n cachedState = {\n referenceCount: 0,\n state: states,\n };\n\n // Cache full render state. Multiple partially defined render states may map to this.\n renderStateCache[fullKey] = cachedState;\n }\n\n ++cachedState.referenceCount;\n\n // Cache partial render state so we can skip validation on a cache hit for a partially defined render state\n renderStateCache[partialKey] = {\n referenceCount: 1,\n state: cachedState.state,\n };\n\n return cachedState.state;\n};\n\n/**\n * @private\n */\nRenderState.removeFromCache = function (renderState) {\n const states = new RenderState(renderState);\n const fullKey = JSON.stringify(states);\n const fullCachedState = renderStateCache[fullKey];\n\n // decrement partial key reference count\n const partialKey = JSON.stringify(renderState);\n const cachedState = renderStateCache[partialKey];\n if (defined(cachedState)) {\n --cachedState.referenceCount;\n\n if (cachedState.referenceCount === 0) {\n // remove partial key\n delete renderStateCache[partialKey];\n\n // decrement full key reference count\n if (defined(fullCachedState)) {\n --fullCachedState.referenceCount;\n }\n }\n }\n\n // remove full key if reference count is zero\n if (defined(fullCachedState) && fullCachedState.referenceCount === 0) {\n delete renderStateCache[fullKey];\n }\n};\n\n/**\n * This function is for testing purposes only.\n * @private\n */\nRenderState.getCache = function () {\n return renderStateCache;\n};\n\n/**\n * This function is for testing purposes only.\n * @private\n */\nRenderState.clearCache = function () {\n renderStateCache = {};\n};\n\nfunction enableOrDisable(gl, glEnum, enable) {\n if (enable) {\n gl.enable(glEnum);\n } else {\n gl.disable(glEnum);\n }\n}\n\nfunction applyFrontFace(gl, renderState) {\n gl.frontFace(renderState.frontFace);\n}\n\nfunction applyCull(gl, renderState) {\n const cull = renderState.cull;\n const enabled = cull.enabled;\n\n enableOrDisable(gl, gl.CULL_FACE, enabled);\n\n if (enabled) {\n gl.cullFace(cull.face);\n }\n}\n\nfunction applyLineWidth(gl, renderState) {\n gl.lineWidth(renderState.lineWidth);\n}\n\nfunction applyPolygonOffset(gl, renderState) {\n const polygonOffset = renderState.polygonOffset;\n const enabled = polygonOffset.enabled;\n\n enableOrDisable(gl, gl.POLYGON_OFFSET_FILL, enabled);\n\n if (enabled) {\n gl.polygonOffset(polygonOffset.factor, polygonOffset.units);\n }\n}\n\nfunction applyScissorTest(gl, renderState, passState) {\n const scissorTest = renderState.scissorTest;\n const enabled = defined(passState.scissorTest)\n ? passState.scissorTest.enabled\n : scissorTest.enabled;\n\n enableOrDisable(gl, gl.SCISSOR_TEST, enabled);\n\n if (enabled) {\n const rectangle = defined(passState.scissorTest)\n ? passState.scissorTest.rectangle\n : scissorTest.rectangle;\n gl.scissor(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\n }\n}\n\nfunction applyDepthRange(gl, renderState) {\n const depthRange = renderState.depthRange;\n gl.depthRange(depthRange.near, depthRange.far);\n}\n\nfunction applyDepthTest(gl, renderState) {\n const depthTest = renderState.depthTest;\n const enabled = depthTest.enabled;\n\n enableOrDisable(gl, gl.DEPTH_TEST, enabled);\n\n if (enabled) {\n gl.depthFunc(depthTest.func);\n }\n}\n\nfunction applyColorMask(gl, renderState) {\n const colorMask = renderState.colorMask;\n gl.colorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha);\n}\n\nfunction applyDepthMask(gl, renderState) {\n gl.depthMask(renderState.depthMask);\n}\n\nfunction applyStencilMask(gl, renderState) {\n gl.stencilMask(renderState.stencilMask);\n}\n\nfunction applyBlendingColor(gl, color) {\n gl.blendColor(color.red, color.green, color.blue, color.alpha);\n}\n\nfunction applyBlending(gl, renderState, passState) {\n const blending = renderState.blending;\n const enabled = defined(passState.blendingEnabled)\n ? passState.blendingEnabled\n : blending.enabled;\n\n enableOrDisable(gl, gl.BLEND, enabled);\n\n if (enabled) {\n applyBlendingColor(gl, blending.color);\n gl.blendEquationSeparate(blending.equationRgb, blending.equationAlpha);\n gl.blendFuncSeparate(\n blending.functionSourceRgb,\n blending.functionDestinationRgb,\n blending.functionSourceAlpha,\n blending.functionDestinationAlpha\n );\n }\n}\n\nfunction applyStencilTest(gl, renderState) {\n const stencilTest = renderState.stencilTest;\n const enabled = stencilTest.enabled;\n\n enableOrDisable(gl, gl.STENCIL_TEST, enabled);\n\n if (enabled) {\n const frontFunction = stencilTest.frontFunction;\n const backFunction = stencilTest.backFunction;\n const reference = stencilTest.reference;\n const mask = stencilTest.mask;\n\n // Section 6.8 of the WebGL spec requires the reference and masks to be the same for\n // front- and back-face tests. This call prevents invalid operation errors when calling\n // stencilFuncSeparate on Firefox. Perhaps they should delay validation to avoid requiring this.\n gl.stencilFunc(frontFunction, reference, mask);\n gl.stencilFuncSeparate(gl.BACK, backFunction, reference, mask);\n gl.stencilFuncSeparate(gl.FRONT, frontFunction, reference, mask);\n\n const frontOperation = stencilTest.frontOperation;\n const frontOperationFail = frontOperation.fail;\n const frontOperationZFail = frontOperation.zFail;\n const frontOperationZPass = frontOperation.zPass;\n\n gl.stencilOpSeparate(\n gl.FRONT,\n frontOperationFail,\n frontOperationZFail,\n frontOperationZPass\n );\n\n const backOperation = stencilTest.backOperation;\n const backOperationFail = backOperation.fail;\n const backOperationZFail = backOperation.zFail;\n const backOperationZPass = backOperation.zPass;\n\n gl.stencilOpSeparate(\n gl.BACK,\n backOperationFail,\n backOperationZFail,\n backOperationZPass\n );\n }\n}\n\nfunction applySampleCoverage(gl, renderState) {\n const sampleCoverage = renderState.sampleCoverage;\n const enabled = sampleCoverage.enabled;\n\n enableOrDisable(gl, gl.SAMPLE_COVERAGE, enabled);\n\n if (enabled) {\n gl.sampleCoverage(sampleCoverage.value, sampleCoverage.invert);\n }\n}\n\nconst scratchViewport = new BoundingRectangle();\n\nfunction applyViewport(gl, renderState, passState) {\n let viewport = defaultValue(renderState.viewport, passState.viewport);\n if (!defined(viewport)) {\n viewport = scratchViewport;\n viewport.width = passState.context.drawingBufferWidth;\n viewport.height = passState.context.drawingBufferHeight;\n }\n\n passState.context.uniformState.viewport = viewport;\n gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);\n}\n\nRenderState.apply = function (gl, renderState, passState) {\n applyFrontFace(gl, renderState);\n applyCull(gl, renderState);\n applyLineWidth(gl, renderState);\n applyPolygonOffset(gl, renderState);\n applyDepthRange(gl, renderState);\n applyDepthTest(gl, renderState);\n applyColorMask(gl, renderState);\n applyDepthMask(gl, renderState);\n applyStencilMask(gl, renderState);\n applyStencilTest(gl, renderState);\n applySampleCoverage(gl, renderState);\n applyScissorTest(gl, renderState, passState);\n applyBlending(gl, renderState, passState);\n applyViewport(gl, renderState, passState);\n};\n\nfunction createFuncs(previousState, nextState) {\n const funcs = [];\n\n if (previousState.frontFace !== nextState.frontFace) {\n funcs.push(applyFrontFace);\n }\n\n if (\n previousState.cull.enabled !== nextState.cull.enabled ||\n previousState.cull.face !== nextState.cull.face\n ) {\n funcs.push(applyCull);\n }\n\n if (previousState.lineWidth !== nextState.lineWidth) {\n funcs.push(applyLineWidth);\n }\n\n if (\n previousState.polygonOffset.enabled !== nextState.polygonOffset.enabled ||\n previousState.polygonOffset.factor !== nextState.polygonOffset.factor ||\n previousState.polygonOffset.units !== nextState.polygonOffset.units\n ) {\n funcs.push(applyPolygonOffset);\n }\n\n if (\n previousState.depthRange.near !== nextState.depthRange.near ||\n previousState.depthRange.far !== nextState.depthRange.far\n ) {\n funcs.push(applyDepthRange);\n }\n\n if (\n previousState.depthTest.enabled !== nextState.depthTest.enabled ||\n previousState.depthTest.func !== nextState.depthTest.func\n ) {\n funcs.push(applyDepthTest);\n }\n\n if (\n previousState.colorMask.red !== nextState.colorMask.red ||\n previousState.colorMask.green !== nextState.colorMask.green ||\n previousState.colorMask.blue !== nextState.colorMask.blue ||\n previousState.colorMask.alpha !== nextState.colorMask.alpha\n ) {\n funcs.push(applyColorMask);\n }\n\n if (previousState.depthMask !== nextState.depthMask) {\n funcs.push(applyDepthMask);\n }\n\n if (previousState.stencilMask !== nextState.stencilMask) {\n funcs.push(applyStencilMask);\n }\n\n if (\n previousState.stencilTest.enabled !== nextState.stencilTest.enabled ||\n previousState.stencilTest.frontFunction !==\n nextState.stencilTest.frontFunction ||\n previousState.stencilTest.backFunction !==\n nextState.stencilTest.backFunction ||\n previousState.stencilTest.reference !== nextState.stencilTest.reference ||\n previousState.stencilTest.mask !== nextState.stencilTest.mask ||\n previousState.stencilTest.frontOperation.fail !==\n nextState.stencilTest.frontOperation.fail ||\n previousState.stencilTest.frontOperation.zFail !==\n nextState.stencilTest.frontOperation.zFail ||\n previousState.stencilTest.backOperation.fail !==\n nextState.stencilTest.backOperation.fail ||\n previousState.stencilTest.backOperation.zFail !==\n nextState.stencilTest.backOperation.zFail ||\n previousState.stencilTest.backOperation.zPass !==\n nextState.stencilTest.backOperation.zPass\n ) {\n funcs.push(applyStencilTest);\n }\n\n if (\n previousState.sampleCoverage.enabled !== nextState.sampleCoverage.enabled ||\n previousState.sampleCoverage.value !== nextState.sampleCoverage.value ||\n previousState.sampleCoverage.invert !== nextState.sampleCoverage.invert\n ) {\n funcs.push(applySampleCoverage);\n }\n\n return funcs;\n}\n\nRenderState.partialApply = function (\n gl,\n previousRenderState,\n renderState,\n previousPassState,\n passState,\n clear\n) {\n if (previousRenderState !== renderState) {\n // When a new render state is applied, instead of making WebGL calls for all the states or first\n // comparing the states one-by-one with the previous state (basically a linear search), we take\n // advantage of RenderState's immutability, and store a dynamically populated sparse data structure\n // containing functions that make the minimum number of WebGL calls when transitioning from one state\n // to the other. In practice, this works well since state-to-state transitions generally only require a\n // few WebGL calls, especially if commands are stored by state.\n let funcs = renderState._applyFunctions[previousRenderState.id];\n if (!defined(funcs)) {\n funcs = createFuncs(previousRenderState, renderState);\n renderState._applyFunctions[previousRenderState.id] = funcs;\n }\n\n const len = funcs.length;\n for (let i = 0; i < len; ++i) {\n funcs[i](gl, renderState);\n }\n }\n\n const previousScissorTest = defined(previousPassState.scissorTest)\n ? previousPassState.scissorTest\n : previousRenderState.scissorTest;\n const scissorTest = defined(passState.scissorTest)\n ? passState.scissorTest\n : renderState.scissorTest;\n\n // Our scissor rectangle can get out of sync with the GL scissor rectangle on clears.\n // Seems to be a problem only on ANGLE. See https://github.com/CesiumGS/cesium/issues/2994\n if (previousScissorTest !== scissorTest || clear) {\n applyScissorTest(gl, renderState, passState);\n }\n\n const previousBlendingEnabled = defined(previousPassState.blendingEnabled)\n ? previousPassState.blendingEnabled\n : previousRenderState.blending.enabled;\n const blendingEnabled = defined(passState.blendingEnabled)\n ? passState.blendingEnabled\n : renderState.blending.enabled;\n if (\n previousBlendingEnabled !== blendingEnabled ||\n (blendingEnabled && previousRenderState.blending !== renderState.blending)\n ) {\n applyBlending(gl, renderState, passState);\n }\n\n if (\n previousRenderState !== renderState ||\n previousPassState !== passState ||\n previousPassState.context !== passState.context\n ) {\n applyViewport(gl, renderState, passState);\n }\n};\n\nRenderState.getState = function (renderState) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(renderState)) {\n throw new DeveloperError(\"renderState is required.\");\n }\n //>>includeEnd('debug');\n\n return {\n frontFace: renderState.frontFace,\n cull: {\n enabled: renderState.cull.enabled,\n face: renderState.cull.face,\n },\n lineWidth: renderState.lineWidth,\n polygonOffset: {\n enabled: renderState.polygonOffset.enabled,\n factor: renderState.polygonOffset.factor,\n units: renderState.polygonOffset.units,\n },\n scissorTest: {\n enabled: renderState.scissorTest.enabled,\n rectangle: BoundingRectangle.clone(renderState.scissorTest.rectangle),\n },\n depthRange: {\n near: renderState.depthRange.near,\n far: renderState.depthRange.far,\n },\n depthTest: {\n enabled: renderState.depthTest.enabled,\n func: renderState.depthTest.func,\n },\n colorMask: {\n red: renderState.colorMask.red,\n green: renderState.colorMask.green,\n blue: renderState.colorMask.blue,\n alpha: renderState.colorMask.alpha,\n },\n depthMask: renderState.depthMask,\n stencilMask: renderState.stencilMask,\n blending: {\n enabled: renderState.blending.enabled,\n color: Color.clone(renderState.blending.color),\n equationRgb: renderState.blending.equationRgb,\n equationAlpha: renderState.blending.equationAlpha,\n functionSourceRgb: renderState.blending.functionSourceRgb,\n functionSourceAlpha: renderState.blending.functionSourceAlpha,\n functionDestinationRgb: renderState.blending.functionDestinationRgb,\n functionDestinationAlpha: renderState.blending.functionDestinationAlpha,\n },\n stencilTest: {\n enabled: renderState.stencilTest.enabled,\n frontFunction: renderState.stencilTest.frontFunction,\n backFunction: renderState.stencilTest.backFunction,\n reference: renderState.stencilTest.reference,\n mask: renderState.stencilTest.mask,\n frontOperation: {\n fail: renderState.stencilTest.frontOperation.fail,\n zFail: renderState.stencilTest.frontOperation.zFail,\n zPass: renderState.stencilTest.frontOperation.zPass,\n },\n backOperation: {\n fail: renderState.stencilTest.backOperation.fail,\n zFail: renderState.stencilTest.backOperation.zFail,\n zPass: renderState.stencilTest.backOperation.zPass,\n },\n },\n sampleCoverage: {\n enabled: renderState.sampleCoverage.enabled,\n value: renderState.sampleCoverage.value,\n invert: renderState.sampleCoverage.invert,\n },\n viewport: defined(renderState.viewport)\n ? BoundingRectangle.clone(renderState.viewport)\n : undefined,\n };\n};\nexport default RenderState;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A 2x2 matrix, indexable as a column-major order array.\n * Constructor parameters are in row-major order for code readability.\n * @alias Matrix2\n * @constructor\n * @implements {ArrayLike}\n *\n * @param {number} [column0Row0=0.0] The value for column 0, row 0.\n * @param {number} [column1Row0=0.0] The value for column 1, row 0.\n * @param {number} [column0Row1=0.0] The value for column 0, row 1.\n * @param {number} [column1Row1=0.0] The value for column 1, row 1.\n *\n * @see Matrix2.fromArray\n * @see Matrix2.fromColumnMajorArray\n * @see Matrix2.fromRowMajorArray\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.fromRotation\n * @see Matrix3\n * @see Matrix4\n */\nfunction Matrix2(column0Row0, column1Row0, column0Row1, column1Row1) {\n this[0] = defaultValue(column0Row0, 0.0);\n this[1] = defaultValue(column0Row1, 0.0);\n this[2] = defaultValue(column1Row0, 0.0);\n this[3] = defaultValue(column1Row1, 0.0);\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nMatrix2.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Matrix2} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nMatrix2.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value[0];\n array[startingIndex++] = value[1];\n array[startingIndex++] = value[2];\n array[startingIndex++] = value[3];\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Matrix2} [result] The object into which to store the result.\n * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.\n */\nMatrix2.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Matrix2();\n }\n\n result[0] = array[startingIndex++];\n result[1] = array[startingIndex++];\n result[2] = array[startingIndex++];\n result[3] = array[startingIndex++];\n return result;\n};\n\n/**\n * Flattens an array of Matrix2s into an array of components. The components\n * are stored in column-major order.\n *\n * @param {Matrix2[]} array The array of matrices to pack.\n * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.\n * @returns {number[]} The packed array.\n */\nMatrix2.packArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n const length = array.length;\n const resultLength = length * 4;\n if (!defined(result)) {\n result = new Array(resultLength);\n } else if (!Array.isArray(result) && result.length !== resultLength) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"If result is a typed array, it must have exactly array.length * 4 elements\"\n );\n //>>includeEnd('debug');\n } else if (result.length !== resultLength) {\n result.length = resultLength;\n }\n\n for (let i = 0; i < length; ++i) {\n Matrix2.pack(array[i], result, i * 4);\n }\n return result;\n};\n\n/**\n * Unpacks an array of column-major matrix components into an array of Matrix2s.\n *\n * @param {number[]} array The array of components to unpack.\n * @param {Matrix2[]} [result] The array onto which to store the result.\n * @returns {Matrix2[]} The unpacked array.\n */\nMatrix2.unpackArray = function (array, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.typeOf.number.greaterThanOrEquals(\"array.length\", array.length, 4);\n if (array.length % 4 !== 0) {\n throw new DeveloperError(\"array length must be a multiple of 4.\");\n }\n //>>includeEnd('debug');\n\n const length = array.length;\n if (!defined(result)) {\n result = new Array(length / 4);\n } else {\n result.length = length / 4;\n }\n\n for (let i = 0; i < length; i += 4) {\n const index = i / 4;\n result[index] = Matrix2.unpack(array, i, result[index]);\n }\n return result;\n};\n\n/**\n * Duplicates a Matrix2 instance.\n *\n * @param {Matrix2} matrix The matrix to duplicate.\n * @param {Matrix2} [result] The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided. (Returns undefined if matrix is undefined)\n */\nMatrix2.clone = function (matrix, result) {\n if (!defined(matrix)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Matrix2(matrix[0], matrix[2], matrix[1], matrix[3]);\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n return result;\n};\n\n/**\n * Creates a Matrix2 from 4 consecutive elements in an array.\n *\n * @function\n * @param {number[]} array The array whose 4 consecutive elements correspond to the positions of the matrix. Assumes column-major order.\n * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.\n * @param {Matrix2} [result] The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.\n *\n * @example\n * // Create the Matrix2:\n * // [1.0, 2.0]\n * // [1.0, 2.0]\n *\n * const v = [1.0, 1.0, 2.0, 2.0];\n * const m = Cesium.Matrix2.fromArray(v);\n *\n * // Create same Matrix2 with using an offset into an array\n * const v2 = [0.0, 0.0, 1.0, 1.0, 2.0, 2.0];\n * const m2 = Cesium.Matrix2.fromArray(v2, 2);\n */\nMatrix2.fromArray = Matrix2.unpack;\n/**\n * Creates a Matrix2 instance from a column-major order array.\n *\n * @param {number[]} values The column-major order array.\n * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.\n */\nMatrix2.fromColumnMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n return Matrix2.clone(values, result);\n};\n\n/**\n * Creates a Matrix2 instance from a row-major order array.\n * The resulting matrix will be in column-major order.\n *\n * @param {number[]} values The row-major order array.\n * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.\n */\nMatrix2.fromRowMajorArray = function (values, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"values\", values);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix2(values[0], values[1], values[2], values[3]);\n }\n result[0] = values[0];\n result[1] = values[2];\n result[2] = values[1];\n result[3] = values[3];\n return result;\n};\n\n/**\n * Computes a Matrix2 instance representing a non-uniform scale.\n *\n * @param {Cartesian2} scale The x and y scale factors.\n * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [7.0, 0.0]\n * // [0.0, 8.0]\n * const m = Cesium.Matrix2.fromScale(new Cesium.Cartesian2(7.0, 8.0));\n */\nMatrix2.fromScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix2(scale.x, 0.0, 0.0, scale.y);\n }\n\n result[0] = scale.x;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = scale.y;\n return result;\n};\n\n/**\n * Computes a Matrix2 instance representing a uniform scale.\n *\n * @param {number} scale The uniform scale factor.\n * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.\n *\n * @example\n * // Creates\n * // [2.0, 0.0]\n * // [0.0, 2.0]\n * const m = Cesium.Matrix2.fromUniformScale(2.0);\n */\nMatrix2.fromUniformScale = function (scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"scale\", scale);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Matrix2(scale, 0.0, 0.0, scale);\n }\n\n result[0] = scale;\n result[1] = 0.0;\n result[2] = 0.0;\n result[3] = scale;\n return result;\n};\n\n/**\n * Creates a rotation matrix.\n *\n * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.\n * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.\n *\n * @example\n * // Rotate a point 45 degrees counterclockwise.\n * const p = new Cesium.Cartesian2(5, 6);\n * const m = Cesium.Matrix2.fromRotation(Cesium.Math.toRadians(45.0));\n * const rotated = Cesium.Matrix2.multiplyByVector(m, p, new Cesium.Cartesian2());\n */\nMatrix2.fromRotation = function (angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const cosAngle = Math.cos(angle);\n const sinAngle = Math.sin(angle);\n\n if (!defined(result)) {\n return new Matrix2(cosAngle, -sinAngle, sinAngle, cosAngle);\n }\n result[0] = cosAngle;\n result[1] = sinAngle;\n result[2] = -sinAngle;\n result[3] = cosAngle;\n return result;\n};\n\n/**\n * Creates an Array from the provided Matrix2 instance.\n * The array will be in column-major order.\n *\n * @param {Matrix2} matrix The matrix to use..\n * @param {number[]} [result] The Array onto which to store the result.\n * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.\n */\nMatrix2.toArray = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return [matrix[0], matrix[1], matrix[2], matrix[3]];\n }\n result[0] = matrix[0];\n result[1] = matrix[1];\n result[2] = matrix[2];\n result[3] = matrix[3];\n return result;\n};\n\n/**\n * Computes the array index of the element at the provided row and column.\n *\n * @param {number} row The zero-based index of the row.\n * @param {number} column The zero-based index of the column.\n * @returns {number} The index of the element at the provided row and column.\n *\n * @exception {DeveloperError} row must be 0 or 1.\n * @exception {DeveloperError} column must be 0 or 1.\n *\n * @example\n * const myMatrix = new Cesium.Matrix2();\n * const column1Row0Index = Cesium.Matrix2.getElementIndex(1, 0);\n * const column1Row0 = myMatrix[column1Row0Index]\n * myMatrix[column1Row0Index] = 10.0;\n */\nMatrix2.getElementIndex = function (column, row) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"row\", row, 0);\n Check.typeOf.number.lessThanOrEquals(\"row\", row, 1);\n\n Check.typeOf.number.greaterThanOrEquals(\"column\", column, 0);\n Check.typeOf.number.lessThanOrEquals(\"column\", column, 1);\n //>>includeEnd('debug');\n\n return column * 2 + row;\n};\n\n/**\n * Retrieves a copy of the matrix column at the provided index as a Cartesian2 instance.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to retrieve.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0 or 1.\n */\nMatrix2.getColumn = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 1);\n\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const startIndex = index * 2;\n const x = matrix[startIndex];\n const y = matrix[startIndex + 1];\n\n result.x = x;\n result.y = y;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian2 instance.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {number} index The zero-based index of the column to set.\n * @param {Cartesian2} cartesian The Cartesian whose values will be assigned to the specified column.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0 or 1.\n */\nMatrix2.setColumn = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 1);\n\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix2.clone(matrix, result);\n const startIndex = index * 2;\n result[startIndex] = cartesian.x;\n result[startIndex + 1] = cartesian.y;\n return result;\n};\n\n/**\n * Retrieves a copy of the matrix row at the provided index as a Cartesian2 instance.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to retrieve.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0 or 1.\n */\nMatrix2.getRow = function (matrix, index, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 1);\n\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = matrix[index];\n const y = matrix[index + 2];\n\n result.x = x;\n result.y = y;\n return result;\n};\n\n/**\n * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian2 instance.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {number} index The zero-based index of the row to set.\n * @param {Cartesian2} cartesian The Cartesian whose values will be assigned to the specified row.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @exception {DeveloperError} index must be 0 or 1.\n */\nMatrix2.setRow = function (matrix, index, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n Check.typeOf.number.lessThanOrEquals(\"index\", index, 1);\n\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result = Matrix2.clone(matrix, result);\n result[index] = cartesian.x;\n result[index + 2] = cartesian.y;\n return result;\n};\n\nconst scaleScratch1 = new Cartesian2();\n\n/**\n * Computes a new matrix that replaces the scale with the provided scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {Cartesian2} scale The scale that replaces the scale of the provided matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @see Matrix2.setUniformScale\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.multiplyByScale\n * @see Matrix2.multiplyByUniformScale\n * @see Matrix2.getScale\n */\nMatrix2.setScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix2.getScale(matrix, scaleScratch1);\n const scaleRatioX = scale.x / existingScale.x;\n const scaleRatioY = scale.y / existingScale.y;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioY;\n result[3] = matrix[3] * scaleRatioY;\n\n return result;\n};\n\nconst scaleScratch2 = new Cartesian2();\n\n/**\n * Computes a new matrix that replaces the scale with the provided uniform scale.\n * This assumes the matrix is an affine transformation.\n *\n * @param {Matrix2} matrix The matrix to use.\n * @param {number} scale The uniform scale that replaces the scale of the provided matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @see Matrix2.setScale\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.multiplyByScale\n * @see Matrix2.multiplyByUniformScale\n * @see Matrix2.getScale\n */\nMatrix2.setUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const existingScale = Matrix2.getScale(matrix, scaleScratch2);\n const scaleRatioX = scale / existingScale.x;\n const scaleRatioY = scale / existingScale.y;\n\n result[0] = matrix[0] * scaleRatioX;\n result[1] = matrix[1] * scaleRatioX;\n result[2] = matrix[2] * scaleRatioY;\n result[3] = matrix[3] * scaleRatioY;\n\n return result;\n};\n\nconst scratchColumn = new Cartesian2();\n\n/**\n * Extracts the non-uniform scale assuming the matrix is an affine transformation.\n *\n * @param {Matrix2} matrix The matrix.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n *\n * @see Matrix2.multiplyByScale\n * @see Matrix2.multiplyByUniformScale\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.setScale\n * @see Matrix2.setUniformScale\n */\nMatrix2.getScale = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = Cartesian2.magnitude(\n Cartesian2.fromElements(matrix[0], matrix[1], scratchColumn)\n );\n result.y = Cartesian2.magnitude(\n Cartesian2.fromElements(matrix[2], matrix[3], scratchColumn)\n );\n return result;\n};\n\nconst scaleScratch3 = new Cartesian2();\n\n/**\n * Computes the maximum scale assuming the matrix is an affine transformation.\n * The maximum scale is the maximum length of the column vectors.\n *\n * @param {Matrix2} matrix The matrix.\n * @returns {number} The maximum scale.\n */\nMatrix2.getMaximumScale = function (matrix) {\n Matrix2.getScale(matrix, scaleScratch3);\n return Cartesian2.maximumComponent(scaleScratch3);\n};\n\nconst scaleScratch4 = new Cartesian2();\n\n/**\n * Sets the rotation assuming the matrix is an affine transformation.\n *\n * @param {Matrix2} matrix The matrix.\n * @param {Matrix2} rotation The rotation matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @see Matrix2.fromRotation\n * @see Matrix2.getRotation\n */\nMatrix2.setRotation = function (matrix, rotation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix2.getScale(matrix, scaleScratch4);\n\n result[0] = rotation[0] * scale.x;\n result[1] = rotation[1] * scale.x;\n result[2] = rotation[2] * scale.y;\n result[3] = rotation[3] * scale.y;\n\n return result;\n};\n\nconst scaleScratch5 = new Cartesian2();\n\n/**\n * Extracts the rotation matrix assuming the matrix is an affine transformation.\n *\n * @param {Matrix2} matrix The matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @see Matrix2.setRotation\n * @see Matrix2.fromRotation\n */\nMatrix2.getRotation = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const scale = Matrix2.getScale(matrix, scaleScratch5);\n\n result[0] = matrix[0] / scale.x;\n result[1] = matrix[1] / scale.x;\n result[2] = matrix[2] / scale.y;\n result[3] = matrix[3] / scale.y;\n\n return result;\n};\n\n/**\n * Computes the product of two matrices.\n *\n * @param {Matrix2} left The first matrix.\n * @param {Matrix2} right The second matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 = left[0] * right[0] + left[2] * right[1];\n const column1Row0 = left[0] * right[2] + left[2] * right[3];\n const column0Row1 = left[1] * right[0] + left[3] * right[1];\n const column1Row1 = left[1] * right[2] + left[3] * right[3];\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column1Row0;\n result[3] = column1Row1;\n return result;\n};\n\n/**\n * Computes the sum of two matrices.\n *\n * @param {Matrix2} left The first matrix.\n * @param {Matrix2} right The second matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] + right[0];\n result[1] = left[1] + right[1];\n result[2] = left[2] + right[2];\n result[3] = left[3] + right[3];\n return result;\n};\n\n/**\n * Computes the difference of two matrices.\n *\n * @param {Matrix2} left The first matrix.\n * @param {Matrix2} right The second matrix.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = left[0] - right[0];\n result[1] = left[1] - right[1];\n result[2] = left[2] - right[2];\n result[3] = left[3] - right[3];\n return result;\n};\n\n/**\n * Computes the product of a matrix and a column vector.\n *\n * @param {Matrix2} matrix The matrix.\n * @param {Cartesian2} cartesian The column.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter.\n */\nMatrix2.multiplyByVector = function (matrix, cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const x = matrix[0] * cartesian.x + matrix[2] * cartesian.y;\n const y = matrix[1] * cartesian.x + matrix[3] * cartesian.y;\n\n result.x = x;\n result.y = y;\n return result;\n};\n\n/**\n * Computes the product of a matrix and a scalar.\n *\n * @param {Matrix2} matrix The matrix.\n * @param {number} scalar The number to multiply by.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.multiplyByScalar = function (matrix, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scalar;\n result[1] = matrix[1] * scalar;\n result[2] = matrix[2] * scalar;\n result[3] = matrix[3] * scalar;\n return result;\n};\n\n/**\n * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.\n *\n * @param {Matrix2} matrix The matrix on the left-hand side.\n * @param {Cartesian2} scale The non-uniform scale on the right-hand side.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n *\n * @example\n * // Instead of Cesium.Matrix2.multiply(m, Cesium.Matrix2.fromScale(scale), m);\n * Cesium.Matrix2.multiplyByScale(m, scale, m);\n *\n * @see Matrix2.multiplyByUniformScale\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.setScale\n * @see Matrix2.setUniformScale\n * @see Matrix2.getScale\n */\nMatrix2.multiplyByScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scale.x;\n result[1] = matrix[1] * scale.x;\n result[2] = matrix[2] * scale.y;\n result[3] = matrix[3] * scale.y;\n\n return result;\n};\n\n/**\n * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.\n *\n * @param {Matrix2} matrix The matrix on the left-hand side.\n * @param {number} scale The uniform scale on the right-hand side.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n *\n * @example\n * // Instead of Cesium.Matrix2.multiply(m, Cesium.Matrix2.fromUniformScale(scale), m);\n * Cesium.Matrix2.multiplyByUniformScale(m, scale, m);\n *\n * @see Matrix2.multiplyByScale\n * @see Matrix2.fromScale\n * @see Matrix2.fromUniformScale\n * @see Matrix2.setScale\n * @see Matrix2.setUniformScale\n * @see Matrix2.getScale\n */\nMatrix2.multiplyByUniformScale = function (matrix, scale, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.number(\"scale\", scale);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = matrix[0] * scale;\n result[1] = matrix[1] * scale;\n result[2] = matrix[2] * scale;\n result[3] = matrix[3] * scale;\n\n return result;\n};\n\n/**\n * Creates a negated copy of the provided matrix.\n *\n * @param {Matrix2} matrix The matrix to negate.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.negate = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = -matrix[0];\n result[1] = -matrix[1];\n result[2] = -matrix[2];\n result[3] = -matrix[3];\n return result;\n};\n\n/**\n * Computes the transpose of the provided matrix.\n *\n * @param {Matrix2} matrix The matrix to transpose.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.transpose = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const column0Row0 = matrix[0];\n const column0Row1 = matrix[2];\n const column1Row0 = matrix[1];\n const column1Row1 = matrix[3];\n\n result[0] = column0Row0;\n result[1] = column0Row1;\n result[2] = column1Row0;\n result[3] = column1Row1;\n return result;\n};\n\n/**\n * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.\n *\n * @param {Matrix2} matrix The matrix with signed elements.\n * @param {Matrix2} result The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter.\n */\nMatrix2.abs = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result[0] = Math.abs(matrix[0]);\n result[1] = Math.abs(matrix[1]);\n result[2] = Math.abs(matrix[2]);\n result[3] = Math.abs(matrix[3]);\n\n return result;\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix2} [left] The first matrix.\n * @param {Matrix2} [right] The second matrix.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nMatrix2.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left[0] === right[0] &&\n left[1] === right[1] &&\n left[2] === right[2] &&\n left[3] === right[3])\n );\n};\n\n/**\n * @private\n */\nMatrix2.equalsArray = function (matrix, array, offset) {\n return (\n matrix[0] === array[offset] &&\n matrix[1] === array[offset + 1] &&\n matrix[2] === array[offset + 2] &&\n matrix[3] === array[offset + 3]\n );\n};\n\n/**\n * Compares the provided matrices componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix2} [left] The first matrix.\n * @param {Matrix2} [right] The second matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nMatrix2.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left[0] - right[0]) <= epsilon &&\n Math.abs(left[1] - right[1]) <= epsilon &&\n Math.abs(left[2] - right[2]) <= epsilon &&\n Math.abs(left[3] - right[3]) <= epsilon)\n );\n};\n\n/**\n * An immutable Matrix2 instance initialized to the identity matrix.\n *\n * @type {Matrix2}\n * @constant\n */\nMatrix2.IDENTITY = Object.freeze(new Matrix2(1.0, 0.0, 0.0, 1.0));\n\n/**\n * An immutable Matrix2 instance initialized to the zero matrix.\n *\n * @type {Matrix2}\n * @constant\n */\nMatrix2.ZERO = Object.freeze(new Matrix2(0.0, 0.0, 0.0, 0.0));\n\n/**\n * The index into Matrix2 for column 0, row 0.\n *\n * @type {number}\n * @constant\n *\n * @example\n * const matrix = new Cesium.Matrix2();\n * matrix[Cesium.Matrix2.COLUMN0ROW0] = 5.0; // set column 0, row 0 to 5.0\n */\nMatrix2.COLUMN0ROW0 = 0;\n\n/**\n * The index into Matrix2 for column 0, row 1.\n *\n * @type {number}\n * @constant\n *\n * @example\n * const matrix = new Cesium.Matrix2();\n * matrix[Cesium.Matrix2.COLUMN0ROW1] = 5.0; // set column 0, row 1 to 5.0\n */\nMatrix2.COLUMN0ROW1 = 1;\n\n/**\n * The index into Matrix2 for column 1, row 0.\n *\n * @type {number}\n * @constant\n *\n * @example\n * const matrix = new Cesium.Matrix2();\n * matrix[Cesium.Matrix2.COLUMN1ROW0] = 5.0; // set column 1, row 0 to 5.0\n */\nMatrix2.COLUMN1ROW0 = 2;\n\n/**\n * The index into Matrix2 for column 1, row 1.\n *\n * @type {number}\n * @constant\n *\n * @example\n * const matrix = new Cesium.Matrix2();\n * matrix[Cesium.Matrix2.COLUMN1ROW1] = 5.0; // set column 1, row 1 to 5.0\n */\nMatrix2.COLUMN1ROW1 = 3;\n\nObject.defineProperties(Matrix2.prototype, {\n /**\n * Gets the number of items in the collection.\n * @memberof Matrix2.prototype\n *\n * @type {number}\n */\n length: {\n get: function () {\n return Matrix2.packedLength;\n },\n },\n});\n\n/**\n * Duplicates the provided Matrix2 instance.\n *\n * @param {Matrix2} [result] The object onto which to store the result.\n * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.\n */\nMatrix2.prototype.clone = function (result) {\n return Matrix2.clone(this, result);\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Matrix2} [right] The right hand side matrix.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nMatrix2.prototype.equals = function (right) {\n return Matrix2.equals(this, right);\n};\n\n/**\n * Compares this matrix to the provided matrix componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Matrix2} [right] The right hand side matrix.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nMatrix2.prototype.equalsEpsilon = function (right, epsilon) {\n return Matrix2.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Creates a string representing this Matrix with each row being\n * on a separate line and in the format '(column0, column1)'.\n *\n * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1)'.\n */\nMatrix2.prototype.toString = function () {\n return `(${this[0]}, ${this[2]})\\n` + `(${this[1]}, ${this[3]})`;\n};\nexport default Matrix2;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * @private\n * @constructor\n */\nfunction createUniform(gl, activeUniform, uniformName, location) {\n switch (activeUniform.type) {\n case gl.FLOAT:\n return new UniformFloat(gl, activeUniform, uniformName, location);\n case gl.FLOAT_VEC2:\n return new UniformFloatVec2(gl, activeUniform, uniformName, location);\n case gl.FLOAT_VEC3:\n return new UniformFloatVec3(gl, activeUniform, uniformName, location);\n case gl.FLOAT_VEC4:\n return new UniformFloatVec4(gl, activeUniform, uniformName, location);\n case gl.SAMPLER_2D:\n case gl.SAMPLER_CUBE:\n return new UniformSampler(gl, activeUniform, uniformName, location);\n case gl.INT:\n case gl.BOOL:\n return new UniformInt(gl, activeUniform, uniformName, location);\n case gl.INT_VEC2:\n case gl.BOOL_VEC2:\n return new UniformIntVec2(gl, activeUniform, uniformName, location);\n case gl.INT_VEC3:\n case gl.BOOL_VEC3:\n return new UniformIntVec3(gl, activeUniform, uniformName, location);\n case gl.INT_VEC4:\n case gl.BOOL_VEC4:\n return new UniformIntVec4(gl, activeUniform, uniformName, location);\n case gl.FLOAT_MAT2:\n return new UniformMat2(gl, activeUniform, uniformName, location);\n case gl.FLOAT_MAT3:\n return new UniformMat3(gl, activeUniform, uniformName, location);\n case gl.FLOAT_MAT4:\n return new UniformMat4(gl, activeUniform, uniformName, location);\n default:\n throw new RuntimeError(\n `Unrecognized uniform type: ${activeUniform.type} for uniform \"${uniformName}\".`\n );\n }\n}\n\n/**\n * @private\n * @constructor\n */\nfunction UniformFloat(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = 0.0;\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformFloat.prototype.set = function () {\n if (this.value !== this._value) {\n this._value = this.value;\n this._gl.uniform1f(this._location, this.value);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformFloatVec2(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Cartesian2();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformFloatVec2.prototype.set = function () {\n const v = this.value;\n if (!Cartesian2.equals(v, this._value)) {\n Cartesian2.clone(v, this._value);\n this._gl.uniform2f(this._location, v.x, v.y);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformFloatVec3(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = undefined;\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformFloatVec3.prototype.set = function () {\n const v = this.value;\n\n if (defined(v.red)) {\n if (!Color.equals(v, this._value)) {\n this._value = Color.clone(v, this._value);\n this._gl.uniform3f(this._location, v.red, v.green, v.blue);\n }\n } else if (defined(v.x)) {\n if (!Cartesian3.equals(v, this._value)) {\n this._value = Cartesian3.clone(v, this._value);\n this._gl.uniform3f(this._location, v.x, v.y, v.z);\n }\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Invalid vec3 value for uniform \"${this.name}\".`);\n //>>includeEnd('debug');\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformFloatVec4(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = undefined;\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformFloatVec4.prototype.set = function () {\n const v = this.value;\n\n if (defined(v.red)) {\n if (!Color.equals(v, this._value)) {\n this._value = Color.clone(v, this._value);\n this._gl.uniform4f(this._location, v.red, v.green, v.blue, v.alpha);\n }\n } else if (defined(v.x)) {\n if (!Cartesian4.equals(v, this._value)) {\n this._value = Cartesian4.clone(v, this._value);\n this._gl.uniform4f(this._location, v.x, v.y, v.z, v.w);\n }\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Invalid vec4 value for uniform \"${this.name}\".`);\n //>>includeEnd('debug');\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformSampler(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n\n this._gl = gl;\n this._location = location;\n\n this.textureUnitIndex = undefined;\n}\n\nUniformSampler.prototype.set = function () {\n const gl = this._gl;\n gl.activeTexture(gl.TEXTURE0 + this.textureUnitIndex);\n\n const v = this.value;\n gl.bindTexture(v._target, v._texture);\n};\n\nUniformSampler.prototype._setSampler = function (textureUnitIndex) {\n this.textureUnitIndex = textureUnitIndex;\n this._gl.uniform1i(this._location, textureUnitIndex);\n return textureUnitIndex + 1;\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformInt(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = 0.0;\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformInt.prototype.set = function () {\n if (this.value !== this._value) {\n this._value = this.value;\n this._gl.uniform1i(this._location, this.value);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n/**\n * @private\n * @constructor\n */\nfunction UniformIntVec2(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Cartesian2();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformIntVec2.prototype.set = function () {\n const v = this.value;\n if (!Cartesian2.equals(v, this._value)) {\n Cartesian2.clone(v, this._value);\n this._gl.uniform2i(this._location, v.x, v.y);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n/**\n * @private\n * @constructor\n */\nfunction UniformIntVec3(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Cartesian3();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformIntVec3.prototype.set = function () {\n const v = this.value;\n if (!Cartesian3.equals(v, this._value)) {\n Cartesian3.clone(v, this._value);\n this._gl.uniform3i(this._location, v.x, v.y, v.z);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n/**\n * @private\n * @constructor\n */\nfunction UniformIntVec4(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Cartesian4();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformIntVec4.prototype.set = function () {\n const v = this.value;\n if (!Cartesian4.equals(v, this._value)) {\n Cartesian4.clone(v, this._value);\n this._gl.uniform4i(this._location, v.x, v.y, v.z, v.w);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\nconst scratchUniformArray = new Float32Array(4);\n/**\n * @private\n * @constructor\n */\nfunction UniformMat2(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Matrix2();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformMat2.prototype.set = function () {\n if (!Matrix2.equalsArray(this.value, this._value, 0)) {\n Matrix2.clone(this.value, this._value);\n\n const array = Matrix2.toArray(this.value, scratchUniformArray);\n this._gl.uniformMatrix2fv(this._location, false, array);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\nconst scratchMat3Array = new Float32Array(9);\n/**\n * @private\n * @constructor\n */\nfunction UniformMat3(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Matrix3();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformMat3.prototype.set = function () {\n if (!Matrix3.equalsArray(this.value, this._value, 0)) {\n Matrix3.clone(this.value, this._value);\n\n const array = Matrix3.toArray(this.value, scratchMat3Array);\n this._gl.uniformMatrix3fv(this._location, false, array);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\nconst scratchMat4Array = new Float32Array(16);\n/**\n * @private\n * @constructor\n */\nfunction UniformMat4(gl, activeUniform, uniformName, location) {\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = undefined;\n this._value = new Matrix4();\n\n this._gl = gl;\n this._location = location;\n}\n\nUniformMat4.prototype.set = function () {\n if (!Matrix4.equalsArray(this.value, this._value, 0)) {\n Matrix4.clone(this.value, this._value);\n\n const array = Matrix4.toArray(this.value, scratchMat4Array);\n this._gl.uniformMatrix4fv(this._location, false, array);\n }\n};\nexport default createUniform;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * @private\n * @constructor\n */\nfunction createUniformArray(gl, activeUniform, uniformName, locations) {\n switch (activeUniform.type) {\n case gl.FLOAT:\n return new UniformArrayFloat(gl, activeUniform, uniformName, locations);\n case gl.FLOAT_VEC2:\n return new UniformArrayFloatVec2(\n gl,\n activeUniform,\n uniformName,\n locations\n );\n case gl.FLOAT_VEC3:\n return new UniformArrayFloatVec3(\n gl,\n activeUniform,\n uniformName,\n locations\n );\n case gl.FLOAT_VEC4:\n return new UniformArrayFloatVec4(\n gl,\n activeUniform,\n uniformName,\n locations\n );\n case gl.SAMPLER_2D:\n case gl.SAMPLER_CUBE:\n return new UniformArraySampler(gl, activeUniform, uniformName, locations);\n case gl.INT:\n case gl.BOOL:\n return new UniformArrayInt(gl, activeUniform, uniformName, locations);\n case gl.INT_VEC2:\n case gl.BOOL_VEC2:\n return new UniformArrayIntVec2(gl, activeUniform, uniformName, locations);\n case gl.INT_VEC3:\n case gl.BOOL_VEC3:\n return new UniformArrayIntVec3(gl, activeUniform, uniformName, locations);\n case gl.INT_VEC4:\n case gl.BOOL_VEC4:\n return new UniformArrayIntVec4(gl, activeUniform, uniformName, locations);\n case gl.FLOAT_MAT2:\n return new UniformArrayMat2(gl, activeUniform, uniformName, locations);\n case gl.FLOAT_MAT3:\n return new UniformArrayMat3(gl, activeUniform, uniformName, locations);\n case gl.FLOAT_MAT4:\n return new UniformArrayMat4(gl, activeUniform, uniformName, locations);\n default:\n throw new RuntimeError(\n `Unrecognized uniform type: ${activeUniform.type} for uniform \"${uniformName}\".`\n );\n }\n}\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayFloat(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayFloat.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (v !== arraybuffer[i]) {\n arraybuffer[i] = v;\n changed = true;\n }\n }\n\n if (changed) {\n this._gl.uniform1fv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayFloatVec2(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 2);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayFloatVec2.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Cartesian2.equalsArray(v, arraybuffer, j)) {\n Cartesian2.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 2;\n }\n\n if (changed) {\n this._gl.uniform2fv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayFloatVec3(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 3);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayFloatVec3.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (defined(v.red)) {\n if (\n v.red !== arraybuffer[j] ||\n v.green !== arraybuffer[j + 1] ||\n v.blue !== arraybuffer[j + 2]\n ) {\n arraybuffer[j] = v.red;\n arraybuffer[j + 1] = v.green;\n arraybuffer[j + 2] = v.blue;\n changed = true;\n }\n } else if (defined(v.x)) {\n if (!Cartesian3.equalsArray(v, arraybuffer, j)) {\n Cartesian3.pack(v, arraybuffer, j);\n changed = true;\n }\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\"Invalid vec3 value.\");\n //>>includeEnd('debug');\n }\n\n j += 3;\n }\n\n if (changed) {\n this._gl.uniform3fv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayFloatVec4(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 4);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayFloatVec4.prototype.set = function () {\n // PERFORMANCE_IDEA: if it is a common case that only a few elements\n // in a uniform array change, we could use heuristics to determine\n // when it is better to call uniform4f for each element that changed\n // vs. call uniform4fv once to set the entire array. This applies\n // to all uniform array types, not just vec4. We might not care\n // once we have uniform buffers since that will be the fast path.\n\n // PERFORMANCE_IDEA: Micro-optimization (I bet it works though):\n // As soon as changed is true, break into a separate loop that\n // does the copy without the equals check.\n\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (defined(v.red)) {\n if (!Color.equalsArray(v, arraybuffer, j)) {\n Color.pack(v, arraybuffer, j);\n changed = true;\n }\n } else if (defined(v.x)) {\n if (!Cartesian4.equalsArray(v, arraybuffer, j)) {\n Cartesian4.pack(v, arraybuffer, j);\n changed = true;\n }\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\"Invalid vec4 value.\");\n //>>includeEnd('debug');\n }\n\n j += 4;\n }\n\n if (changed) {\n this._gl.uniform4fv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArraySampler(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length);\n\n this._gl = gl;\n this._locations = locations;\n\n this.textureUnitIndex = undefined;\n}\n\nUniformArraySampler.prototype.set = function () {\n const gl = this._gl;\n const textureUnitIndex = gl.TEXTURE0 + this.textureUnitIndex;\n\n const value = this.value;\n const length = value.length;\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n gl.activeTexture(textureUnitIndex + i);\n gl.bindTexture(v._target, v._texture);\n }\n};\n\nUniformArraySampler.prototype._setSampler = function (textureUnitIndex) {\n this.textureUnitIndex = textureUnitIndex;\n\n const locations = this._locations;\n const length = locations.length;\n for (let i = 0; i < length; ++i) {\n const index = textureUnitIndex + i;\n this._gl.uniform1i(locations[i], index);\n }\n\n return textureUnitIndex + length;\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayInt(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Int32Array(length);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayInt.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (v !== arraybuffer[i]) {\n arraybuffer[i] = v;\n changed = true;\n }\n }\n\n if (changed) {\n this._gl.uniform1iv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayIntVec2(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Int32Array(length * 2);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayIntVec2.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Cartesian2.equalsArray(v, arraybuffer, j)) {\n Cartesian2.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 2;\n }\n\n if (changed) {\n this._gl.uniform2iv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayIntVec3(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Int32Array(length * 3);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayIntVec3.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Cartesian3.equalsArray(v, arraybuffer, j)) {\n Cartesian3.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 3;\n }\n\n if (changed) {\n this._gl.uniform3iv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayIntVec4(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Int32Array(length * 4);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayIntVec4.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Cartesian4.equalsArray(v, arraybuffer, j)) {\n Cartesian4.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 4;\n }\n\n if (changed) {\n this._gl.uniform4iv(this._location, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayMat2(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 4);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayMat2.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Matrix2.equalsArray(v, arraybuffer, j)) {\n Matrix2.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 4;\n }\n\n if (changed) {\n this._gl.uniformMatrix2fv(this._location, false, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayMat3(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 9);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayMat3.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Matrix3.equalsArray(v, arraybuffer, j)) {\n Matrix3.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 9;\n }\n\n if (changed) {\n this._gl.uniformMatrix3fv(this._location, false, arraybuffer);\n }\n};\n\n///////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n * @constructor\n */\nfunction UniformArrayMat4(gl, activeUniform, uniformName, locations) {\n const length = locations.length;\n\n /**\n * @type {string}\n * @readonly\n */\n this.name = uniformName;\n\n this.value = new Array(length);\n this._value = new Float32Array(length * 16);\n\n this._gl = gl;\n this._location = locations[0];\n}\n\nUniformArrayMat4.prototype.set = function () {\n const value = this.value;\n const length = value.length;\n const arraybuffer = this._value;\n let changed = false;\n let j = 0;\n\n for (let i = 0; i < length; ++i) {\n const v = value[i];\n\n if (!Matrix4.equalsArray(v, arraybuffer, j)) {\n Matrix4.pack(v, arraybuffer, j);\n changed = true;\n }\n j += 16;\n }\n\n if (changed) {\n this._gl.uniformMatrix4fv(this._location, false, arraybuffer);\n }\n};\nexport default createUniformArray;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport AutomaticUniforms from \"./AutomaticUniforms.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport createUniform from \"./createUniform.js\";\nimport createUniformArray from \"./createUniformArray.js\";\n\nlet nextShaderProgramId = 0;\n\n/**\n * @private\n */\nfunction ShaderProgram(options) {\n let vertexShaderText = options.vertexShaderText;\n let fragmentShaderText = options.fragmentShaderText;\n\n if (typeof spector !== \"undefined\") {\n // The #line statements common in Cesium shaders interfere with the ability of the\n // SpectorJS to show errors on the correct line. So remove them when SpectorJS\n // is active.\n vertexShaderText = vertexShaderText.replace(/^#line/gm, \"//#line\");\n fragmentShaderText = fragmentShaderText.replace(/^#line/gm, \"//#line\");\n }\n\n const modifiedFS = handleUniformPrecisionMismatches(\n vertexShaderText,\n fragmentShaderText\n );\n\n this._gl = options.gl;\n this._logShaderCompilation = options.logShaderCompilation;\n this._debugShaders = options.debugShaders;\n this._attributeLocations = options.attributeLocations;\n\n this._program = undefined;\n this._numberOfVertexAttributes = undefined;\n this._vertexAttributes = undefined;\n this._uniformsByName = undefined;\n this._uniforms = undefined;\n this._automaticUniforms = undefined;\n this._manualUniforms = undefined;\n this._duplicateUniformNames = modifiedFS.duplicateUniformNames;\n this._cachedShader = undefined; // Used by ShaderCache\n\n /**\n * @private\n */\n this.maximumTextureUnitIndex = undefined;\n\n this._vertexShaderSource = options.vertexShaderSource;\n this._vertexShaderText = options.vertexShaderText;\n this._fragmentShaderSource = options.fragmentShaderSource;\n this._fragmentShaderText = modifiedFS.fragmentShaderText;\n\n /**\n * @private\n */\n this.id = nextShaderProgramId++;\n}\n\nShaderProgram.fromCache = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n return options.context.shaderCache.getShaderProgram(options);\n};\n\nShaderProgram.replaceCache = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n return options.context.shaderCache.replaceShaderProgram(options);\n};\n\nObject.defineProperties(ShaderProgram.prototype, {\n /**\n * GLSL source for the shader program's vertex shader.\n * @memberof ShaderProgram.prototype\n *\n * @type {ShaderSource}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n return this._vertexShaderSource;\n },\n },\n /**\n * GLSL source for the shader program's fragment shader.\n * @memberof ShaderProgram.prototype\n *\n * @type {ShaderSource}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n vertexAttributes: {\n get: function () {\n initialize(this);\n return this._vertexAttributes;\n },\n },\n numberOfVertexAttributes: {\n get: function () {\n initialize(this);\n return this._numberOfVertexAttributes;\n },\n },\n allUniforms: {\n get: function () {\n initialize(this);\n return this._uniformsByName;\n },\n },\n});\n\nfunction extractUniforms(shaderText) {\n const uniformNames = [];\n const uniformLines = shaderText.match(/uniform.*?(?![^{]*})(?=[=\\[;])/g);\n if (defined(uniformLines)) {\n const len = uniformLines.length;\n for (let i = 0; i < len; i++) {\n const line = uniformLines[i].trim();\n const name = line.slice(line.lastIndexOf(\" \") + 1);\n uniformNames.push(name);\n }\n }\n return uniformNames;\n}\n\nfunction handleUniformPrecisionMismatches(\n vertexShaderText,\n fragmentShaderText\n) {\n // If a uniform exists in both the vertex and fragment shader but with different precision qualifiers,\n // give the fragment shader uniform a different name. This fixes shader compilation errors on devices\n // that only support mediump in the fragment shader.\n const duplicateUniformNames = {};\n\n if (!ContextLimits.highpFloatSupported || !ContextLimits.highpIntSupported) {\n let i, j;\n let uniformName;\n let duplicateName;\n const vertexShaderUniforms = extractUniforms(vertexShaderText);\n const fragmentShaderUniforms = extractUniforms(fragmentShaderText);\n const vertexUniformsCount = vertexShaderUniforms.length;\n const fragmentUniformsCount = fragmentShaderUniforms.length;\n\n for (i = 0; i < vertexUniformsCount; i++) {\n for (j = 0; j < fragmentUniformsCount; j++) {\n if (vertexShaderUniforms[i] === fragmentShaderUniforms[j]) {\n uniformName = vertexShaderUniforms[i];\n duplicateName = `czm_mediump_${uniformName}`;\n // Update fragmentShaderText with renamed uniforms\n const re = new RegExp(`${uniformName}\\\\b`, \"g\");\n fragmentShaderText = fragmentShaderText.replace(re, duplicateName);\n duplicateUniformNames[duplicateName] = uniformName;\n }\n }\n }\n }\n\n return {\n fragmentShaderText: fragmentShaderText,\n duplicateUniformNames: duplicateUniformNames,\n };\n}\n\nconst consolePrefix = \"[Cesium WebGL] \";\n\nfunction createAndLinkProgram(gl, shader) {\n const vsSource = shader._vertexShaderText;\n const fsSource = shader._fragmentShaderText;\n\n const vertexShader = gl.createShader(gl.VERTEX_SHADER);\n gl.shaderSource(vertexShader, vsSource);\n gl.compileShader(vertexShader);\n\n const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);\n gl.shaderSource(fragmentShader, fsSource);\n gl.compileShader(fragmentShader);\n\n const program = gl.createProgram();\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n\n const attributeLocations = shader._attributeLocations;\n if (defined(attributeLocations)) {\n for (const attribute in attributeLocations) {\n if (attributeLocations.hasOwnProperty(attribute)) {\n gl.bindAttribLocation(\n program,\n attributeLocations[attribute],\n attribute\n );\n }\n }\n }\n\n gl.linkProgram(program);\n let log;\n\n // For performance: if linker succeeds, return without checking compile status\n if (gl.getProgramParameter(program, gl.LINK_STATUS)) {\n if (shader._logShaderCompilation) {\n log = gl.getShaderInfoLog(vertexShader);\n if (defined(log) && log.length > 0) {\n console.log(`${consolePrefix}Vertex shader compile log: ${log}`);\n }\n\n log = gl.getShaderInfoLog(fragmentShader);\n if (defined(log) && log.length > 0) {\n console.log(`${consolePrefix}Fragment shader compile log: ${log}`);\n }\n\n log = gl.getProgramInfoLog(program);\n if (defined(log) && log.length > 0) {\n console.log(`${consolePrefix}Shader program link log: ${log}`);\n }\n }\n\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n\n return program;\n }\n\n // Program failed to link. Try to find and report the reason\n let errorMessage;\n const debugShaders = shader._debugShaders;\n\n if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {\n log = gl.getShaderInfoLog(fragmentShader);\n console.error(`${consolePrefix}Fragment shader compile log: ${log}`);\n console.error(`${consolePrefix} Fragment shader source:\\n${fsSource}`);\n errorMessage = `Fragment shader failed to compile. Compile log: ${log}`;\n } else if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {\n log = gl.getShaderInfoLog(vertexShader);\n console.error(`${consolePrefix}Vertex shader compile log: ${log}`);\n console.error(`${consolePrefix} Vertex shader source:\\n${vsSource}`);\n errorMessage = `Vertex shader failed to compile. Compile log: ${log}`;\n } else {\n log = gl.getProgramInfoLog(program);\n console.error(`${consolePrefix}Shader program link log: ${log}`);\n logTranslatedSource(vertexShader, \"vertex\");\n logTranslatedSource(fragmentShader, \"fragment\");\n errorMessage = `Program failed to link. Link log: ${log}`;\n }\n\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n gl.deleteProgram(program);\n throw new RuntimeError(errorMessage);\n\n function logTranslatedSource(compiledShader, name) {\n if (!defined(debugShaders)) {\n return;\n }\n const translation = debugShaders.getTranslatedShaderSource(compiledShader);\n if (translation === \"\") {\n console.error(`${consolePrefix}${name} shader translation failed.`);\n return;\n }\n console.error(\n `${consolePrefix}Translated ${name} shaderSource:\\n${translation}`\n );\n }\n}\n\nfunction findVertexAttributes(gl, program, numberOfAttributes) {\n const attributes = {};\n for (let i = 0; i < numberOfAttributes; ++i) {\n const attr = gl.getActiveAttrib(program, i);\n const location = gl.getAttribLocation(program, attr.name);\n\n attributes[attr.name] = {\n name: attr.name,\n type: attr.type,\n index: location,\n };\n }\n\n return attributes;\n}\n\nfunction findUniforms(gl, program) {\n const uniformsByName = {};\n const uniforms = [];\n const samplerUniforms = [];\n\n const numberOfUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);\n\n for (let i = 0; i < numberOfUniforms; ++i) {\n const activeUniform = gl.getActiveUniform(program, i);\n const suffix = \"[0]\";\n const uniformName =\n activeUniform.name.indexOf(\n suffix,\n activeUniform.name.length - suffix.length\n ) !== -1\n ? activeUniform.name.slice(0, activeUniform.name.length - 3)\n : activeUniform.name;\n\n // Ignore GLSL built-in uniforms returned in Firefox.\n if (uniformName.indexOf(\"gl_\") !== 0) {\n if (activeUniform.name.indexOf(\"[\") < 0) {\n // Single uniform\n const location = gl.getUniformLocation(program, uniformName);\n\n // IE 11.0.9 needs this check since getUniformLocation can return null\n // if the uniform is not active (e.g., it is optimized out). Looks like\n // getActiveUniform() above returns uniforms that are not actually active.\n if (location !== null) {\n const uniform = createUniform(\n gl,\n activeUniform,\n uniformName,\n location\n );\n\n uniformsByName[uniformName] = uniform;\n uniforms.push(uniform);\n\n if (uniform._setSampler) {\n samplerUniforms.push(uniform);\n }\n }\n } else {\n // Uniform array\n\n let uniformArray;\n let locations;\n let value;\n let loc;\n\n // On some platforms - Nexus 4 in Firefox for one - an array of sampler2D ends up being represented\n // as separate uniforms, one for each array element. Check for and handle that case.\n const indexOfBracket = uniformName.indexOf(\"[\");\n if (indexOfBracket >= 0) {\n // We're assuming the array elements show up in numerical order - it seems to be true.\n uniformArray = uniformsByName[uniformName.slice(0, indexOfBracket)];\n\n // Nexus 4 with Android 4.3 needs this check, because it reports a uniform\n // with the strange name webgl_3467e0265d05c3c1[1] in our globe surface shader.\n if (!defined(uniformArray)) {\n continue;\n }\n\n locations = uniformArray._locations;\n\n // On the Nexus 4 in Chrome, we get one uniform per sampler, just like in Firefox,\n // but the size is not 1 like it is in Firefox. So if we push locations here,\n // we'll end up adding too many locations.\n if (locations.length <= 1) {\n value = uniformArray.value;\n loc = gl.getUniformLocation(program, uniformName);\n\n // Workaround for IE 11.0.9. See above.\n if (loc !== null) {\n locations.push(loc);\n value.push(gl.getUniform(program, loc));\n }\n }\n } else {\n locations = [];\n for (let j = 0; j < activeUniform.size; ++j) {\n loc = gl.getUniformLocation(program, `${uniformName}[${j}]`);\n\n // Workaround for IE 11.0.9. See above.\n if (loc !== null) {\n locations.push(loc);\n }\n }\n uniformArray = createUniformArray(\n gl,\n activeUniform,\n uniformName,\n locations\n );\n\n uniformsByName[uniformName] = uniformArray;\n uniforms.push(uniformArray);\n\n if (uniformArray._setSampler) {\n samplerUniforms.push(uniformArray);\n }\n }\n }\n }\n }\n\n return {\n uniformsByName: uniformsByName,\n uniforms: uniforms,\n samplerUniforms: samplerUniforms,\n };\n}\n\nfunction partitionUniforms(shader, uniforms) {\n const automaticUniforms = [];\n const manualUniforms = [];\n\n for (const uniform in uniforms) {\n if (uniforms.hasOwnProperty(uniform)) {\n const uniformObject = uniforms[uniform];\n let uniformName = uniform;\n // if it's a duplicate uniform, use its original name so it is updated correctly\n const duplicateUniform = shader._duplicateUniformNames[uniformName];\n if (defined(duplicateUniform)) {\n uniformObject.name = duplicateUniform;\n uniformName = duplicateUniform;\n }\n const automaticUniform = AutomaticUniforms[uniformName];\n if (defined(automaticUniform)) {\n automaticUniforms.push({\n uniform: uniformObject,\n automaticUniform: automaticUniform,\n });\n } else {\n manualUniforms.push(uniformObject);\n }\n }\n }\n\n return {\n automaticUniforms: automaticUniforms,\n manualUniforms: manualUniforms,\n };\n}\n\nfunction setSamplerUniforms(gl, program, samplerUniforms) {\n gl.useProgram(program);\n\n let textureUnitIndex = 0;\n const length = samplerUniforms.length;\n for (let i = 0; i < length; ++i) {\n textureUnitIndex = samplerUniforms[i]._setSampler(textureUnitIndex);\n }\n\n gl.useProgram(null);\n\n return textureUnitIndex;\n}\n\nfunction initialize(shader) {\n if (defined(shader._program)) {\n return;\n }\n\n reinitialize(shader);\n}\n\nfunction reinitialize(shader) {\n const oldProgram = shader._program;\n\n const gl = shader._gl;\n const program = createAndLinkProgram(gl, shader, shader._debugShaders);\n const numberOfVertexAttributes = gl.getProgramParameter(\n program,\n gl.ACTIVE_ATTRIBUTES\n );\n const uniforms = findUniforms(gl, program);\n const partitionedUniforms = partitionUniforms(\n shader,\n uniforms.uniformsByName\n );\n\n shader._program = program;\n shader._numberOfVertexAttributes = numberOfVertexAttributes;\n shader._vertexAttributes = findVertexAttributes(\n gl,\n program,\n numberOfVertexAttributes\n );\n shader._uniformsByName = uniforms.uniformsByName;\n shader._uniforms = uniforms.uniforms;\n shader._automaticUniforms = partitionedUniforms.automaticUniforms;\n shader._manualUniforms = partitionedUniforms.manualUniforms;\n\n shader.maximumTextureUnitIndex = setSamplerUniforms(\n gl,\n program,\n uniforms.samplerUniforms\n );\n\n if (oldProgram) {\n shader._gl.deleteProgram(oldProgram);\n }\n\n // If SpectorJS is active, add the hook to make the shader editor work.\n // https://github.com/BabylonJS/Spector.js/blob/master/documentation/extension.md#shader-editor\n if (typeof spector !== \"undefined\") {\n shader._program.__SPECTOR_rebuildProgram = function (\n vertexSourceCode, // The new vertex shader source\n fragmentSourceCode, // The new fragment shader source\n onCompiled, // Callback triggered by your engine when the compilation is successful. It needs to send back the new linked program.\n onError // Callback triggered by your engine in case of error. It needs to send the WebGL error to allow the editor to display the error in the gutter.\n ) {\n const originalVS = shader._vertexShaderText;\n const originalFS = shader._fragmentShaderText;\n\n // SpectorJS likes to replace `!=` with `! =` for unknown reasons,\n // and that causes glsl compile failures. So fix that up.\n const regex = / ! = /g;\n shader._vertexShaderText = vertexSourceCode.replace(regex, \" != \");\n shader._fragmentShaderText = fragmentSourceCode.replace(regex, \" != \");\n\n try {\n reinitialize(shader);\n onCompiled(shader._program);\n } catch (e) {\n shader._vertexShaderText = originalVS;\n shader._fragmentShaderText = originalFS;\n\n // Only pass on the WebGL error:\n const errorMatcher = /(?:Compile|Link) error: ([^]*)/;\n const match = errorMatcher.exec(e.message);\n if (match) {\n onError(match[1]);\n } else {\n onError(e.message);\n }\n }\n };\n }\n}\n\nShaderProgram.prototype._bind = function () {\n initialize(this);\n this._gl.useProgram(this._program);\n};\n\nShaderProgram.prototype._setUniforms = function (\n uniformMap,\n uniformState,\n validate\n) {\n let len;\n let i;\n\n if (defined(uniformMap)) {\n const manualUniforms = this._manualUniforms;\n len = manualUniforms.length;\n for (i = 0; i < len; ++i) {\n const mu = manualUniforms[i];\n mu.value = uniformMap[mu.name]();\n }\n }\n\n const automaticUniforms = this._automaticUniforms;\n len = automaticUniforms.length;\n for (i = 0; i < len; ++i) {\n const au = automaticUniforms[i];\n au.uniform.value = au.automaticUniform.getValue(uniformState);\n }\n\n ///////////////////////////////////////////////////////////////////\n\n // It appears that assigning the uniform values above and then setting them here\n // (which makes the GL calls) is faster than removing this loop and making\n // the GL calls above. I suspect this is because each GL call pollutes the\n // L2 cache making our JavaScript and the browser/driver ping-pong cache lines.\n const uniforms = this._uniforms;\n len = uniforms.length;\n for (i = 0; i < len; ++i) {\n uniforms[i].set();\n }\n\n if (validate) {\n const gl = this._gl;\n const program = this._program;\n\n gl.validateProgram(program);\n //>>includeStart('debug', pragmas.debug);\n if (!gl.getProgramParameter(program, gl.VALIDATE_STATUS)) {\n throw new DeveloperError(\n `Program validation failed. Program info log: ${gl.getProgramInfoLog(\n program\n )}`\n );\n }\n //>>includeEnd('debug');\n }\n};\n\nShaderProgram.prototype.isDestroyed = function () {\n return false;\n};\n\nShaderProgram.prototype.destroy = function () {\n this._cachedShader.cache.releaseShaderProgram(this);\n return undefined;\n};\n\nShaderProgram.prototype.finalDestroy = function () {\n this._gl.deleteProgram(this._program);\n return destroyObject(this);\n};\nexport default ShaderProgram;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport ViewportQuadVS from \"../Shaders/ViewportQuadVS.js\";\nimport ClearCommand from \"./ClearCommand.js\";\nimport DrawCommand from \"./DrawCommand.js\";\nimport Framebuffer from \"./Framebuffer.js\";\nimport RenderState from \"./RenderState.js\";\nimport ShaderProgram from \"./ShaderProgram.js\";\n\n/**\n * @private\n */\nfunction ComputeEngine(context) {\n this._context = context;\n}\n\nlet renderStateScratch;\nconst drawCommandScratch = new DrawCommand({\n primitiveType: PrimitiveType.TRIANGLES,\n});\nconst clearCommandScratch = new ClearCommand({\n color: new Color(0.0, 0.0, 0.0, 0.0),\n});\n\nfunction createFramebuffer(context, outputTexture) {\n return new Framebuffer({\n context: context,\n colorTextures: [outputTexture],\n destroyAttachments: false,\n });\n}\n\nfunction createViewportQuadShader(context, fragmentShaderSource) {\n return ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: ViewportQuadVS,\n fragmentShaderSource: fragmentShaderSource,\n attributeLocations: {\n position: 0,\n textureCoordinates: 1,\n },\n });\n}\n\nfunction createRenderState(width, height) {\n if (\n !defined(renderStateScratch) ||\n renderStateScratch.viewport.width !== width ||\n renderStateScratch.viewport.height !== height\n ) {\n renderStateScratch = RenderState.fromCache({\n viewport: new BoundingRectangle(0, 0, width, height),\n });\n }\n return renderStateScratch;\n}\n\nComputeEngine.prototype.execute = function (computeCommand) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"computeCommand\", computeCommand);\n //>>includeEnd('debug');\n\n // This may modify the command's resources, so do error checking afterwards\n if (defined(computeCommand.preExecute)) {\n computeCommand.preExecute(computeCommand);\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(computeCommand.fragmentShaderSource) &&\n !defined(computeCommand.shaderProgram)\n ) {\n throw new DeveloperError(\n \"computeCommand.fragmentShaderSource or computeCommand.shaderProgram is required.\"\n );\n }\n\n Check.defined(\"computeCommand.outputTexture\", computeCommand.outputTexture);\n //>>includeEnd('debug');\n\n const outputTexture = computeCommand.outputTexture;\n const width = outputTexture.width;\n const height = outputTexture.height;\n\n const context = this._context;\n const vertexArray = defined(computeCommand.vertexArray)\n ? computeCommand.vertexArray\n : context.getViewportQuadVertexArray();\n const shaderProgram = defined(computeCommand.shaderProgram)\n ? computeCommand.shaderProgram\n : createViewportQuadShader(context, computeCommand.fragmentShaderSource);\n const framebuffer = createFramebuffer(context, outputTexture);\n const renderState = createRenderState(width, height);\n const uniformMap = computeCommand.uniformMap;\n\n const clearCommand = clearCommandScratch;\n clearCommand.framebuffer = framebuffer;\n clearCommand.renderState = renderState;\n clearCommand.execute(context);\n\n const drawCommand = drawCommandScratch;\n drawCommand.vertexArray = vertexArray;\n drawCommand.renderState = renderState;\n drawCommand.shaderProgram = shaderProgram;\n drawCommand.uniformMap = uniformMap;\n drawCommand.framebuffer = framebuffer;\n drawCommand.execute(context);\n\n framebuffer.destroy();\n\n if (!computeCommand.persists) {\n shaderProgram.destroy();\n if (defined(computeCommand.vertexArray)) {\n vertexArray.destroy();\n }\n }\n\n if (defined(computeCommand.postExecute)) {\n computeCommand.postExecute(outputTexture);\n }\n};\n\nComputeEngine.prototype.isDestroyed = function () {\n return false;\n};\n\nComputeEngine.prototype.destroy = function () {\n return destroyObject(this);\n};\nexport default ComputeEngine;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport WebGLConstants from \"./WebGLConstants.js\";\n\n/**\n * WebGL component datatypes. Components are intrinsics,\n * which form attributes, which form vertices.\n *\n * @enum {number}\n */\nconst ComponentDatatype = {\n /**\n * 8-bit signed byte corresponding to gl.BYTE and the type\n * of an element in Int8Array.\n *\n * @type {number}\n * @constant\n */\n BYTE: WebGLConstants.BYTE,\n\n /**\n * 8-bit unsigned byte corresponding to UNSIGNED_BYTE and the type\n * of an element in Uint8Array.\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_BYTE: WebGLConstants.UNSIGNED_BYTE,\n\n /**\n * 16-bit signed short corresponding to SHORT and the type\n * of an element in Int16Array.\n *\n * @type {number}\n * @constant\n */\n SHORT: WebGLConstants.SHORT,\n\n /**\n * 16-bit unsigned short corresponding to UNSIGNED_SHORT and the type\n * of an element in Uint16Array.\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_SHORT: WebGLConstants.UNSIGNED_SHORT,\n\n /**\n * 32-bit signed int corresponding to INT and the type\n * of an element in Int32Array.\n *\n * @memberOf ComponentDatatype\n *\n * @type {number}\n * @constant\n */\n INT: WebGLConstants.INT,\n\n /**\n * 32-bit unsigned int corresponding to UNSIGNED_INT and the type\n * of an element in Uint32Array.\n *\n * @memberOf ComponentDatatype\n *\n * @type {number}\n * @constant\n */\n UNSIGNED_INT: WebGLConstants.UNSIGNED_INT,\n\n /**\n * 32-bit floating-point corresponding to FLOAT and the type\n * of an element in Float32Array.\n *\n * @type {number}\n * @constant\n */\n FLOAT: WebGLConstants.FLOAT,\n\n /**\n * 64-bit floating-point corresponding to gl.DOUBLE (in Desktop OpenGL;\n * this is not supported in WebGL, and is emulated in Cesium via {@link GeometryPipeline.encodeAttribute})\n * and the type of an element in Float64Array.\n *\n * @memberOf ComponentDatatype\n *\n * @type {number}\n * @constant\n * @default 0x140A\n */\n DOUBLE: WebGLConstants.DOUBLE,\n};\n\n/**\n * Returns the size, in bytes, of the corresponding datatype.\n *\n * @param {ComponentDatatype} componentDatatype The component datatype to get the size of.\n * @returns {number} The size in bytes.\n *\n * @exception {DeveloperError} componentDatatype is not a valid value.\n *\n * @example\n * // Returns Int8Array.BYTES_PER_ELEMENT\n * const size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE);\n */\nComponentDatatype.getSizeInBytes = function (componentDatatype) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(componentDatatype)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n return Int8Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.UNSIGNED_BYTE:\n return Uint8Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.SHORT:\n return Int16Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.UNSIGNED_SHORT:\n return Uint16Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.INT:\n return Int32Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.UNSIGNED_INT:\n return Uint32Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.FLOAT:\n return Float32Array.BYTES_PER_ELEMENT;\n case ComponentDatatype.DOUBLE:\n return Float64Array.BYTES_PER_ELEMENT;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the {@link ComponentDatatype} for the provided TypedArray instance.\n *\n * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} array The typed array.\n * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.\n */\nComponentDatatype.fromTypedArray = function (array) {\n if (array instanceof Int8Array) {\n return ComponentDatatype.BYTE;\n }\n if (array instanceof Uint8Array) {\n return ComponentDatatype.UNSIGNED_BYTE;\n }\n if (array instanceof Int16Array) {\n return ComponentDatatype.SHORT;\n }\n if (array instanceof Uint16Array) {\n return ComponentDatatype.UNSIGNED_SHORT;\n }\n if (array instanceof Int32Array) {\n return ComponentDatatype.INT;\n }\n if (array instanceof Uint32Array) {\n return ComponentDatatype.UNSIGNED_INT;\n }\n if (array instanceof Float32Array) {\n return ComponentDatatype.FLOAT;\n }\n if (array instanceof Float64Array) {\n return ComponentDatatype.DOUBLE;\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"array must be an Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, or Float64Array.\"\n );\n //>>includeEnd('debug');\n};\n\n/**\n * Validates that the provided component datatype is a valid {@link ComponentDatatype}\n *\n * @param {ComponentDatatype} componentDatatype The component datatype to validate.\n * @returns {boolean} true if the provided component datatype is a valid value; otherwise, false.\n *\n * @example\n * if (!Cesium.ComponentDatatype.validate(componentDatatype)) {\n * throw new Cesium.DeveloperError('componentDatatype must be a valid value.');\n * }\n */\nComponentDatatype.validate = function (componentDatatype) {\n return (\n defined(componentDatatype) &&\n (componentDatatype === ComponentDatatype.BYTE ||\n componentDatatype === ComponentDatatype.UNSIGNED_BYTE ||\n componentDatatype === ComponentDatatype.SHORT ||\n componentDatatype === ComponentDatatype.UNSIGNED_SHORT ||\n componentDatatype === ComponentDatatype.INT ||\n componentDatatype === ComponentDatatype.UNSIGNED_INT ||\n componentDatatype === ComponentDatatype.FLOAT ||\n componentDatatype === ComponentDatatype.DOUBLE)\n );\n};\n\n/**\n * Creates a typed array corresponding to component data type.\n *\n * @param {ComponentDatatype} componentDatatype The component data type.\n * @param {number|Array} valuesOrLength The length of the array to create or an array.\n * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array.\n *\n * @exception {DeveloperError} componentDatatype is not a valid value.\n *\n * @example\n * // creates a Float32Array with length of 100\n * const typedArray = Cesium.ComponentDatatype.createTypedArray(Cesium.ComponentDatatype.FLOAT, 100);\n */\nComponentDatatype.createTypedArray = function (\n componentDatatype,\n valuesOrLength\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(componentDatatype)) {\n throw new DeveloperError(\"componentDatatype is required.\");\n }\n if (!defined(valuesOrLength)) {\n throw new DeveloperError(\"valuesOrLength is required.\");\n }\n //>>includeEnd('debug');\n\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n return new Int8Array(valuesOrLength);\n case ComponentDatatype.UNSIGNED_BYTE:\n return new Uint8Array(valuesOrLength);\n case ComponentDatatype.SHORT:\n return new Int16Array(valuesOrLength);\n case ComponentDatatype.UNSIGNED_SHORT:\n return new Uint16Array(valuesOrLength);\n case ComponentDatatype.INT:\n return new Int32Array(valuesOrLength);\n case ComponentDatatype.UNSIGNED_INT:\n return new Uint32Array(valuesOrLength);\n case ComponentDatatype.FLOAT:\n return new Float32Array(valuesOrLength);\n case ComponentDatatype.DOUBLE:\n return new Float64Array(valuesOrLength);\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Creates a typed view of an array of bytes.\n *\n * @param {ComponentDatatype} componentDatatype The type of the view to create.\n * @param {ArrayBuffer} buffer The buffer storage to use for the view.\n * @param {number} [byteOffset] The offset, in bytes, to the first element in the view.\n * @param {number} [length] The number of elements in the view.\n * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array view of the buffer.\n *\n * @exception {DeveloperError} componentDatatype is not a valid value.\n */\nComponentDatatype.createArrayBufferView = function (\n componentDatatype,\n buffer,\n byteOffset,\n length\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(componentDatatype)) {\n throw new DeveloperError(\"componentDatatype is required.\");\n }\n if (!defined(buffer)) {\n throw new DeveloperError(\"buffer is required.\");\n }\n //>>includeEnd('debug');\n\n byteOffset = defaultValue(byteOffset, 0);\n length = defaultValue(\n length,\n (buffer.byteLength - byteOffset) /\n ComponentDatatype.getSizeInBytes(componentDatatype)\n );\n\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n return new Int8Array(buffer, byteOffset, length);\n case ComponentDatatype.UNSIGNED_BYTE:\n return new Uint8Array(buffer, byteOffset, length);\n case ComponentDatatype.SHORT:\n return new Int16Array(buffer, byteOffset, length);\n case ComponentDatatype.UNSIGNED_SHORT:\n return new Uint16Array(buffer, byteOffset, length);\n case ComponentDatatype.INT:\n return new Int32Array(buffer, byteOffset, length);\n case ComponentDatatype.UNSIGNED_INT:\n return new Uint32Array(buffer, byteOffset, length);\n case ComponentDatatype.FLOAT:\n return new Float32Array(buffer, byteOffset, length);\n case ComponentDatatype.DOUBLE:\n return new Float64Array(buffer, byteOffset, length);\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"componentDatatype is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Get the ComponentDatatype from its name.\n *\n * @param {string} name The name of the ComponentDatatype.\n * @returns {ComponentDatatype} The ComponentDatatype.\n *\n * @exception {DeveloperError} name is not a valid value.\n */\nComponentDatatype.fromName = function (name) {\n switch (name) {\n case \"BYTE\":\n return ComponentDatatype.BYTE;\n case \"UNSIGNED_BYTE\":\n return ComponentDatatype.UNSIGNED_BYTE;\n case \"SHORT\":\n return ComponentDatatype.SHORT;\n case \"UNSIGNED_SHORT\":\n return ComponentDatatype.UNSIGNED_SHORT;\n case \"INT\":\n return ComponentDatatype.INT;\n case \"UNSIGNED_INT\":\n return ComponentDatatype.UNSIGNED_INT;\n case \"FLOAT\":\n return ComponentDatatype.FLOAT;\n case \"DOUBLE\":\n return ComponentDatatype.DOUBLE;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"name is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\nexport default Object.freeze(ComponentDatatype);\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\nconst warnings = {};\n\n/**\n * Logs a one time message to the console. Use this function instead of\n * console.log directly since this does not log duplicate messages\n * unless it is called from multiple workers.\n *\n * @function oneTimeWarning\n *\n * @param {string} identifier The unique identifier for this warning.\n * @param {string} [message=identifier] The message to log to the console.\n *\n * @example\n * for(let i=0;i>includeStart('debug', pragmas.debug);\n if (!defined(identifier)) {\n throw new DeveloperError(\"identifier is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(warnings[identifier])) {\n warnings[identifier] = true;\n console.warn(defaultValue(message, identifier));\n }\n}\n\noneTimeWarning.geometryOutlines =\n \"Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.\";\n\noneTimeWarning.geometryZIndex =\n \"Entity geometry with zIndex are unsupported when height or extrudedHeight are defined. zIndex will be ignored\";\n\noneTimeWarning.geometryHeightReference =\n \"Entity corridor, ellipse, polygon or rectangle with heightReference must also have a defined height. heightReference will be ignored\";\noneTimeWarning.geometryExtrudedHeightReference =\n \"Entity corridor, ellipse, polygon or rectangle with extrudedHeightReference must also have a defined extrudedHeight. extrudedHeightReference will be ignored\";\nexport default oneTimeWarning;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport oneTimeWarning from \"./oneTimeWarning.js\";\n\n/**\n * Logs a deprecation message to the console. Use this function instead of\n * console.log directly since this does not log duplicate messages\n * unless it is called from multiple workers.\n *\n * @function deprecationWarning\n *\n * @param {string} identifier The unique identifier for this deprecated API.\n * @param {string} message The message to log to the console.\n *\n * @example\n * // Deprecated function or class\n * function Foo() {\n * deprecationWarning('Foo', 'Foo was deprecated in Cesium 1.01. It will be removed in 1.03. Use newFoo instead.');\n * // ...\n * }\n *\n * // Deprecated function\n * Bar.prototype.func = function() {\n * deprecationWarning('Bar.func', 'Bar.func() was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newFunc() instead.');\n * // ...\n * };\n *\n * // Deprecated property\n * Object.defineProperties(Bar.prototype, {\n * prop : {\n * get : function() {\n * deprecationWarning('Bar.prop', 'Bar.prop was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newProp instead.');\n * // ...\n * },\n * set : function(value) {\n * deprecationWarning('Bar.prop', 'Bar.prop was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newProp instead.');\n * // ...\n * }\n * }\n * });\n *\n * @private\n */\nfunction deprecationWarning(identifier, message) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(identifier) || !defined(message)) {\n throw new DeveloperError(\"identifier and message are required.\");\n }\n //>>includeEnd('debug');\n\n oneTimeWarning(identifier, message);\n}\nexport default deprecationWarning;\n", "/**\n * @private\n */\nconst GeometryType = {\n NONE: 0,\n TRIANGLES: 1,\n LINES: 2,\n POLYLINES: 3,\n};\nexport default Object.freeze(GeometryType);\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport FeatureDetection from \"./FeatureDetection.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\n\n/**\n * A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.\n * @alias Quaternion\n * @constructor\n *\n * @param {number} [x=0.0] The X component.\n * @param {number} [y=0.0] The Y component.\n * @param {number} [z=0.0] The Z component.\n * @param {number} [w=0.0] The W component.\n *\n * @see PackableForInterpolation\n */\nfunction Quaternion(x, y, z, w) {\n /**\n * The X component.\n * @type {number}\n * @default 0.0\n */\n this.x = defaultValue(x, 0.0);\n\n /**\n * The Y component.\n * @type {number}\n * @default 0.0\n */\n this.y = defaultValue(y, 0.0);\n\n /**\n * The Z component.\n * @type {number}\n * @default 0.0\n */\n this.z = defaultValue(z, 0.0);\n\n /**\n * The W component.\n * @type {number}\n * @default 0.0\n */\n this.w = defaultValue(w, 0.0);\n}\n\nlet fromAxisAngleScratch = new Cartesian3();\n\n/**\n * Computes a quaternion representing a rotation around an axis.\n *\n * @param {Cartesian3} axis The axis of rotation.\n * @param {number} angle The angle in radians to rotate around the axis.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.fromAxisAngle = function (axis, angle, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"axis\", axis);\n Check.typeOf.number(\"angle\", angle);\n //>>includeEnd('debug');\n\n const halfAngle = angle / 2.0;\n const s = Math.sin(halfAngle);\n fromAxisAngleScratch = Cartesian3.normalize(axis, fromAxisAngleScratch);\n\n const x = fromAxisAngleScratch.x * s;\n const y = fromAxisAngleScratch.y * s;\n const z = fromAxisAngleScratch.z * s;\n const w = Math.cos(halfAngle);\n if (!defined(result)) {\n return new Quaternion(x, y, z, w);\n }\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\nconst fromRotationMatrixNext = [1, 2, 0];\nconst fromRotationMatrixQuat = new Array(3);\n/**\n * Computes a Quaternion from the provided Matrix3 instance.\n *\n * @param {Matrix3} matrix The rotation matrix.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n *\n * @see Matrix3.fromQuaternion\n */\nQuaternion.fromRotationMatrix = function (matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"matrix\", matrix);\n //>>includeEnd('debug');\n\n let root;\n let x;\n let y;\n let z;\n let w;\n\n const m00 = matrix[Matrix3.COLUMN0ROW0];\n const m11 = matrix[Matrix3.COLUMN1ROW1];\n const m22 = matrix[Matrix3.COLUMN2ROW2];\n const trace = m00 + m11 + m22;\n\n if (trace > 0.0) {\n // |w| > 1/2, may as well choose w > 1/2\n root = Math.sqrt(trace + 1.0); // 2w\n w = 0.5 * root;\n root = 0.5 / root; // 1/(4w)\n\n x = (matrix[Matrix3.COLUMN1ROW2] - matrix[Matrix3.COLUMN2ROW1]) * root;\n y = (matrix[Matrix3.COLUMN2ROW0] - matrix[Matrix3.COLUMN0ROW2]) * root;\n z = (matrix[Matrix3.COLUMN0ROW1] - matrix[Matrix3.COLUMN1ROW0]) * root;\n } else {\n // |w| <= 1/2\n const next = fromRotationMatrixNext;\n\n let i = 0;\n if (m11 > m00) {\n i = 1;\n }\n if (m22 > m00 && m22 > m11) {\n i = 2;\n }\n const j = next[i];\n const k = next[j];\n\n root = Math.sqrt(\n matrix[Matrix3.getElementIndex(i, i)] -\n matrix[Matrix3.getElementIndex(j, j)] -\n matrix[Matrix3.getElementIndex(k, k)] +\n 1.0\n );\n\n const quat = fromRotationMatrixQuat;\n quat[i] = 0.5 * root;\n root = 0.5 / root;\n w =\n (matrix[Matrix3.getElementIndex(k, j)] -\n matrix[Matrix3.getElementIndex(j, k)]) *\n root;\n quat[j] =\n (matrix[Matrix3.getElementIndex(j, i)] +\n matrix[Matrix3.getElementIndex(i, j)]) *\n root;\n quat[k] =\n (matrix[Matrix3.getElementIndex(k, i)] +\n matrix[Matrix3.getElementIndex(i, k)]) *\n root;\n\n x = -quat[0];\n y = -quat[1];\n z = -quat[2];\n }\n\n if (!defined(result)) {\n return new Quaternion(x, y, z, w);\n }\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\nconst scratchHPRQuaternion = new Quaternion();\nlet scratchHeadingQuaternion = new Quaternion();\nlet scratchPitchQuaternion = new Quaternion();\nlet scratchRollQuaternion = new Quaternion();\n\n/**\n * Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the\n * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about\n * the positive x axis.\n *\n * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.\n */\nQuaternion.fromHeadingPitchRoll = function (headingPitchRoll, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"headingPitchRoll\", headingPitchRoll);\n //>>includeEnd('debug');\n\n scratchRollQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_X,\n headingPitchRoll.roll,\n scratchHPRQuaternion\n );\n scratchPitchQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_Y,\n -headingPitchRoll.pitch,\n result\n );\n result = Quaternion.multiply(\n scratchPitchQuaternion,\n scratchRollQuaternion,\n scratchPitchQuaternion\n );\n scratchHeadingQuaternion = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_Z,\n -headingPitchRoll.heading,\n scratchHPRQuaternion\n );\n return Quaternion.multiply(scratchHeadingQuaternion, result, result);\n};\n\nconst sampledQuaternionAxis = new Cartesian3();\nconst sampledQuaternionRotation = new Cartesian3();\nconst sampledQuaternionTempQuaternion = new Quaternion();\nconst sampledQuaternionQuaternion0 = new Quaternion();\nconst sampledQuaternionQuaternion0Conjugate = new Quaternion();\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nQuaternion.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {Quaternion} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nQuaternion.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.x;\n array[startingIndex++] = value.y;\n array[startingIndex++] = value.z;\n array[startingIndex] = value.w;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Quaternion} [result] The object into which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new Quaternion();\n }\n result.x = array[startingIndex];\n result.y = array[startingIndex + 1];\n result.z = array[startingIndex + 2];\n result.w = array[startingIndex + 3];\n return result;\n};\n\n/**\n * The number of elements used to store the object into an array in its interpolatable form.\n * @type {number}\n */\nQuaternion.packedInterpolationLength = 3;\n\n/**\n * Converts a packed array into a form suitable for interpolation.\n *\n * @param {number[]} packedArray The packed array.\n * @param {number} [startingIndex=0] The index of the first element to be converted.\n * @param {number} [lastIndex=packedArray.length] The index of the last element to be converted.\n * @param {number[]} [result] The object into which to store the result.\n */\nQuaternion.convertPackedArrayForInterpolation = function (\n packedArray,\n startingIndex,\n lastIndex,\n result\n) {\n Quaternion.unpack(\n packedArray,\n lastIndex * 4,\n sampledQuaternionQuaternion0Conjugate\n );\n Quaternion.conjugate(\n sampledQuaternionQuaternion0Conjugate,\n sampledQuaternionQuaternion0Conjugate\n );\n\n for (let i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {\n const offset = i * 3;\n Quaternion.unpack(\n packedArray,\n (startingIndex + i) * 4,\n sampledQuaternionTempQuaternion\n );\n\n Quaternion.multiply(\n sampledQuaternionTempQuaternion,\n sampledQuaternionQuaternion0Conjugate,\n sampledQuaternionTempQuaternion\n );\n\n if (sampledQuaternionTempQuaternion.w < 0) {\n Quaternion.negate(\n sampledQuaternionTempQuaternion,\n sampledQuaternionTempQuaternion\n );\n }\n\n Quaternion.computeAxis(\n sampledQuaternionTempQuaternion,\n sampledQuaternionAxis\n );\n const angle = Quaternion.computeAngle(sampledQuaternionTempQuaternion);\n if (!defined(result)) {\n result = [];\n }\n result[offset] = sampledQuaternionAxis.x * angle;\n result[offset + 1] = sampledQuaternionAxis.y * angle;\n result[offset + 2] = sampledQuaternionAxis.z * angle;\n }\n};\n\n/**\n * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}.\n *\n * @param {number[]} array The array previously packed for interpolation.\n * @param {number[]} sourceArray The original packed array.\n * @param {number} [firstIndex=0] The firstIndex used to convert the array.\n * @param {number} [lastIndex=packedArray.length] The lastIndex used to convert the array.\n * @param {Quaternion} [result] The object into which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.unpackInterpolationResult = function (\n array,\n sourceArray,\n firstIndex,\n lastIndex,\n result\n) {\n if (!defined(result)) {\n result = new Quaternion();\n }\n Cartesian3.fromArray(array, 0, sampledQuaternionRotation);\n const magnitude = Cartesian3.magnitude(sampledQuaternionRotation);\n\n Quaternion.unpack(sourceArray, lastIndex * 4, sampledQuaternionQuaternion0);\n\n if (magnitude === 0) {\n Quaternion.clone(Quaternion.IDENTITY, sampledQuaternionTempQuaternion);\n } else {\n Quaternion.fromAxisAngle(\n sampledQuaternionRotation,\n magnitude,\n sampledQuaternionTempQuaternion\n );\n }\n\n return Quaternion.multiply(\n sampledQuaternionTempQuaternion,\n sampledQuaternionQuaternion0,\n result\n );\n};\n\n/**\n * Duplicates a Quaternion instance.\n *\n * @param {Quaternion} quaternion The quaternion to duplicate.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided. (Returns undefined if quaternion is undefined)\n */\nQuaternion.clone = function (quaternion, result) {\n if (!defined(quaternion)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Quaternion(\n quaternion.x,\n quaternion.y,\n quaternion.z,\n quaternion.w\n );\n }\n\n result.x = quaternion.x;\n result.y = quaternion.y;\n result.z = quaternion.z;\n result.w = quaternion.w;\n return result;\n};\n\n/**\n * Computes the conjugate of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.conjugate = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -quaternion.x;\n result.y = -quaternion.y;\n result.z = -quaternion.z;\n result.w = quaternion.w;\n return result;\n};\n\n/**\n * Computes magnitude squared for the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @returns {number} The magnitude squared.\n */\nQuaternion.magnitudeSquared = function (quaternion) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n //>>includeEnd('debug');\n\n return (\n quaternion.x * quaternion.x +\n quaternion.y * quaternion.y +\n quaternion.z * quaternion.z +\n quaternion.w * quaternion.w\n );\n};\n\n/**\n * Computes magnitude for the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to conjugate.\n * @returns {number} The magnitude.\n */\nQuaternion.magnitude = function (quaternion) {\n return Math.sqrt(Quaternion.magnitudeSquared(quaternion));\n};\n\n/**\n * Computes the normalized form of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to normalize.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.normalize = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion);\n const x = quaternion.x * inverseMagnitude;\n const y = quaternion.y * inverseMagnitude;\n const z = quaternion.z * inverseMagnitude;\n const w = quaternion.w * inverseMagnitude;\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Computes the inverse of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to normalize.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.inverse = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const magnitudeSquared = Quaternion.magnitudeSquared(quaternion);\n result = Quaternion.conjugate(quaternion, result);\n return Quaternion.multiplyByScalar(result, 1.0 / magnitudeSquared, result);\n};\n\n/**\n * Computes the componentwise sum of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.add = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x + right.x;\n result.y = left.y + right.y;\n result.z = left.z + right.z;\n result.w = left.w + right.w;\n return result;\n};\n\n/**\n * Computes the componentwise difference of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.subtract = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = left.x - right.x;\n result.y = left.y - right.y;\n result.z = left.z - right.z;\n result.w = left.w - right.w;\n return result;\n};\n\n/**\n * Negates the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to be negated.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.negate = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = -quaternion.x;\n result.y = -quaternion.y;\n result.z = -quaternion.z;\n result.w = -quaternion.w;\n return result;\n};\n\n/**\n * Computes the dot (scalar) product of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @returns {number} The dot product.\n */\nQuaternion.dot = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return (\n left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w\n );\n};\n\n/**\n * Computes the product of two quaternions.\n *\n * @param {Quaternion} left The first quaternion.\n * @param {Quaternion} right The second quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.multiply = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const leftX = left.x;\n const leftY = left.y;\n const leftZ = left.z;\n const leftW = left.w;\n\n const rightX = right.x;\n const rightY = right.y;\n const rightZ = right.z;\n const rightW = right.w;\n\n const x = leftW * rightX + leftX * rightW + leftY * rightZ - leftZ * rightY;\n const y = leftW * rightY - leftX * rightZ + leftY * rightW + leftZ * rightX;\n const z = leftW * rightZ + leftX * rightY - leftY * rightX + leftZ * rightW;\n const w = leftW * rightW - leftX * rightX - leftY * rightY - leftZ * rightZ;\n\n result.x = x;\n result.y = y;\n result.z = z;\n result.w = w;\n return result;\n};\n\n/**\n * Multiplies the provided quaternion componentwise by the provided scalar.\n *\n * @param {Quaternion} quaternion The quaternion to be scaled.\n * @param {number} scalar The scalar to multiply with.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.multiplyByScalar = function (quaternion, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = quaternion.x * scalar;\n result.y = quaternion.y * scalar;\n result.z = quaternion.z * scalar;\n result.w = quaternion.w * scalar;\n return result;\n};\n\n/**\n * Divides the provided quaternion componentwise by the provided scalar.\n *\n * @param {Quaternion} quaternion The quaternion to be divided.\n * @param {number} scalar The scalar to divide by.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.divideByScalar = function (quaternion, scalar, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.number(\"scalar\", scalar);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n result.x = quaternion.x / scalar;\n result.y = quaternion.y / scalar;\n result.z = quaternion.z / scalar;\n result.w = quaternion.w / scalar;\n return result;\n};\n\n/**\n * Computes the axis of rotation of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to use.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nQuaternion.computeAxis = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const w = quaternion.w;\n if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) {\n result.x = result.y = result.z = 0;\n return result;\n }\n\n const scalar = 1.0 / Math.sqrt(1.0 - w * w);\n\n result.x = quaternion.x * scalar;\n result.y = quaternion.y * scalar;\n result.z = quaternion.z * scalar;\n return result;\n};\n\n/**\n * Computes the angle of rotation of the provided quaternion.\n *\n * @param {Quaternion} quaternion The quaternion to use.\n * @returns {number} The angle of rotation.\n */\nQuaternion.computeAngle = function (quaternion) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n //>>includeEnd('debug');\n\n if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) {\n return 0.0;\n }\n return 2.0 * Math.acos(quaternion.w);\n};\n\nlet lerpScratch = new Quaternion();\n/**\n * Computes the linear interpolation or extrapolation at t using the provided quaternions.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.lerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch);\n result = Quaternion.multiplyByScalar(start, 1.0 - t, result);\n return Quaternion.add(lerpScratch, result, result);\n};\n\nlet slerpEndNegated = new Quaternion();\nlet slerpScaledP = new Quaternion();\nlet slerpScaledR = new Quaternion();\n/**\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#fastSlerp\n */\nQuaternion.slerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n let dot = Quaternion.dot(start, end);\n\n // The angle between start must be acute. Since q and -q represent\n // the same rotation, negate q to get the acute angle.\n let r = end;\n if (dot < 0.0) {\n dot = -dot;\n r = slerpEndNegated = Quaternion.negate(end, slerpEndNegated);\n }\n\n // dot > 0, as the dot product approaches 1, the angle between the\n // quaternions vanishes. use linear interpolation.\n if (1.0 - dot < CesiumMath.EPSILON6) {\n return Quaternion.lerp(start, r, t, result);\n }\n\n const theta = Math.acos(dot);\n slerpScaledP = Quaternion.multiplyByScalar(\n start,\n Math.sin((1 - t) * theta),\n slerpScaledP\n );\n slerpScaledR = Quaternion.multiplyByScalar(\n r,\n Math.sin(t * theta),\n slerpScaledR\n );\n result = Quaternion.add(slerpScaledP, slerpScaledR, result);\n return Quaternion.multiplyByScalar(result, 1.0 / Math.sin(theta), result);\n};\n\n/**\n * The logarithmic quaternion function.\n *\n * @param {Quaternion} quaternion The unit quaternion.\n * @param {Cartesian3} result The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter.\n */\nQuaternion.log = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"quaternion\", quaternion);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const theta = CesiumMath.acosClamped(quaternion.w);\n let thetaOverSinTheta = 0.0;\n\n if (theta !== 0.0) {\n thetaOverSinTheta = theta / Math.sin(theta);\n }\n\n return Cartesian3.multiplyByScalar(quaternion, thetaOverSinTheta, result);\n};\n\n/**\n * The exponential quaternion function.\n *\n * @param {Cartesian3} cartesian The cartesian.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n */\nQuaternion.exp = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const theta = Cartesian3.magnitude(cartesian);\n let sinThetaOverTheta = 0.0;\n\n if (theta !== 0.0) {\n sinThetaOverTheta = Math.sin(theta) / theta;\n }\n\n result.x = cartesian.x * sinThetaOverTheta;\n result.y = cartesian.y * sinThetaOverTheta;\n result.z = cartesian.z * sinThetaOverTheta;\n result.w = Math.cos(theta);\n\n return result;\n};\n\nconst squadScratchCartesian0 = new Cartesian3();\nconst squadScratchCartesian1 = new Cartesian3();\nconst squadScratchQuaternion0 = new Quaternion();\nconst squadScratchQuaternion1 = new Quaternion();\n\n/**\n * Computes an inner quadrangle point.\n *

This will compute quaternions that ensure a squad curve is C1.

\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} q2 The third quaternion.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#squad\n */\nQuaternion.computeInnerQuadrangle = function (q0, q1, q2, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"q2\", q2);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const qInv = Quaternion.conjugate(q1, squadScratchQuaternion0);\n Quaternion.multiply(qInv, q2, squadScratchQuaternion1);\n const cart0 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian0);\n\n Quaternion.multiply(qInv, q0, squadScratchQuaternion1);\n const cart1 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian1);\n\n Cartesian3.add(cart0, cart1, cart0);\n Cartesian3.multiplyByScalar(cart0, 0.25, cart0);\n Cartesian3.negate(cart0, cart0);\n Quaternion.exp(cart0, squadScratchQuaternion0);\n\n return Quaternion.multiply(q1, squadScratchQuaternion0, result);\n};\n\n/**\n * Computes the spherical quadrangle interpolation between quaternions.\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} s0 The first inner quadrangle.\n * @param {Quaternion} s1 The second inner quadrangle.\n * @param {number} t The time in [0,1] used to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n *\n * @example\n * // 1. compute the squad interpolation between two quaternions on a curve\n * const s0 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new Cesium.Quaternion());\n * const s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new Cesium.Quaternion());\n * const q = Cesium.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new Cesium.Quaternion());\n *\n * // 2. compute the squad interpolation as above but where the first quaternion is a end point.\n * const s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[0], quaternions[1], quaternions[2], new Cesium.Quaternion());\n * const q = Cesium.Quaternion.squad(quaternions[0], quaternions[1], quaternions[0], s1, t, new Cesium.Quaternion());\n *\n * @see Quaternion#computeInnerQuadrangle\n */\nQuaternion.squad = function (q0, q1, s0, s1, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"s0\", s0);\n Check.typeOf.object(\"s1\", s1);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0);\n const slerp1 = Quaternion.slerp(s0, s1, t, squadScratchQuaternion1);\n return Quaternion.slerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\n};\n\nconst fastSlerpScratchQuaternion = new Quaternion();\n// eslint-disable-next-line no-loss-of-precision\nconst opmu = 1.90110745351730037;\nconst u = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst v = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst bT = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\nconst bD = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];\n\nfor (let i = 0; i < 7; ++i) {\n const s = i + 1.0;\n const t = 2.0 * s + 1.0;\n u[i] = 1.0 / (s * t);\n v[i] = s / t;\n}\n\nu[7] = opmu / (8.0 * 17.0);\nv[7] = (opmu * 8.0) / 17.0;\n\n/**\n * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.\n * This implementation is faster than {@link Quaternion#slerp}, but is only accurate up to 10-6.\n *\n * @param {Quaternion} start The value corresponding to t at 0.0.\n * @param {Quaternion} end The value corresponding to t at 1.0.\n * @param {number} t The point along t at which to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter.\n *\n * @see Quaternion#slerp\n */\nQuaternion.fastSlerp = function (start, end, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"start\", start);\n Check.typeOf.object(\"end\", end);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n let x = Quaternion.dot(start, end);\n\n let sign;\n if (x >= 0) {\n sign = 1.0;\n } else {\n sign = -1.0;\n x = -x;\n }\n\n const xm1 = x - 1.0;\n const d = 1.0 - t;\n const sqrT = t * t;\n const sqrD = d * d;\n\n for (let i = 7; i >= 0; --i) {\n bT[i] = (u[i] * sqrT - v[i]) * xm1;\n bD[i] = (u[i] * sqrD - v[i]) * xm1;\n }\n\n const cT =\n sign *\n t *\n (1.0 +\n bT[0] *\n (1.0 +\n bT[1] *\n (1.0 +\n bT[2] *\n (1.0 +\n bT[3] *\n (1.0 +\n bT[4] *\n (1.0 + bT[5] * (1.0 + bT[6] * (1.0 + bT[7]))))))));\n const cD =\n d *\n (1.0 +\n bD[0] *\n (1.0 +\n bD[1] *\n (1.0 +\n bD[2] *\n (1.0 +\n bD[3] *\n (1.0 +\n bD[4] *\n (1.0 + bD[5] * (1.0 + bD[6] * (1.0 + bD[7]))))))));\n\n const temp = Quaternion.multiplyByScalar(\n start,\n cD,\n fastSlerpScratchQuaternion\n );\n Quaternion.multiplyByScalar(end, cT, result);\n return Quaternion.add(temp, result, result);\n};\n\n/**\n * Computes the spherical quadrangle interpolation between quaternions.\n * An implementation that is faster than {@link Quaternion#squad}, but less accurate.\n *\n * @param {Quaternion} q0 The first quaternion.\n * @param {Quaternion} q1 The second quaternion.\n * @param {Quaternion} s0 The first inner quadrangle.\n * @param {Quaternion} s1 The second inner quadrangle.\n * @param {number} t The time in [0,1] used to interpolate.\n * @param {Quaternion} result The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new instance if none was provided.\n *\n * @see Quaternion#squad\n */\nQuaternion.fastSquad = function (q0, q1, s0, s1, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"q0\", q0);\n Check.typeOf.object(\"q1\", q1);\n Check.typeOf.object(\"s0\", s0);\n Check.typeOf.object(\"s1\", s1);\n Check.typeOf.number(\"t\", t);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0);\n const slerp1 = Quaternion.fastSlerp(s0, s1, t, squadScratchQuaternion1);\n return Quaternion.fastSlerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);\n};\n\n/**\n * Compares the provided quaternions componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Quaternion} [left] The first quaternion.\n * @param {Quaternion} [right] The second quaternion.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nQuaternion.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.x === right.x &&\n left.y === right.y &&\n left.z === right.z &&\n left.w === right.w)\n );\n};\n\n/**\n * Compares the provided quaternions componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Quaternion} [left] The first quaternion.\n * @param {Quaternion} [right] The second quaternion.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nQuaternion.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left.x - right.x) <= epsilon &&\n Math.abs(left.y - right.y) <= epsilon &&\n Math.abs(left.z - right.z) <= epsilon &&\n Math.abs(left.w - right.w) <= epsilon)\n );\n};\n\n/**\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 0.0).\n *\n * @type {Quaternion}\n * @constant\n */\nQuaternion.ZERO = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 0.0));\n\n/**\n * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 1.0).\n *\n * @type {Quaternion}\n * @constant\n */\nQuaternion.IDENTITY = Object.freeze(new Quaternion(0.0, 0.0, 0.0, 1.0));\n\n/**\n * Duplicates this Quaternion instance.\n *\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nQuaternion.prototype.clone = function (result) {\n return Quaternion.clone(this, result);\n};\n\n/**\n * Compares this and the provided quaternion componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {Quaternion} [right] The right hand side quaternion.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nQuaternion.prototype.equals = function (right) {\n return Quaternion.equals(this, right);\n};\n\n/**\n * Compares this and the provided quaternion componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {Quaternion} [right] The right hand side quaternion.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nQuaternion.prototype.equalsEpsilon = function (right, epsilon) {\n return Quaternion.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Returns a string representing this quaternion in the format (x, y, z, w).\n *\n * @returns {string} A string representing this Quaternion.\n */\nQuaternion.prototype.toString = function () {\n return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;\n};\nexport default Quaternion;\n", "import Check from \"./Check.js\";\n\n/**\n * Finds an item in a sorted array.\n *\n * @function\n * @param {Array} array The sorted array to search.\n * @param {*} itemToFind The item to find in the array.\n * @param {binarySearchComparator} comparator The function to use to compare the item to\n * elements in the array.\n * @returns {number} The index of itemToFind in the array, if it exists. If itemToFind\n * does not exist, the return value is a negative number which is the bitwise complement (~)\n * of the index before which the itemToFind should be inserted in order to maintain the\n * sorted order of the array.\n *\n * @example\n * // Create a comparator function to search through an array of numbers.\n * function comparator(a, b) {\n * return a - b;\n * };\n * const numbers = [0, 2, 4, 6, 8];\n * const index = Cesium.binarySearch(numbers, 6, comparator); // 3\n */\nfunction binarySearch(array, itemToFind, comparator) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n Check.defined(\"itemToFind\", itemToFind);\n Check.defined(\"comparator\", comparator);\n //>>includeEnd('debug');\n\n let low = 0;\n let high = array.length - 1;\n let i;\n let comparison;\n\n while (low <= high) {\n i = ~~((low + high) / 2);\n comparison = comparator(array[i], itemToFind);\n if (comparison < 0) {\n low = i + 1;\n continue;\n }\n if (comparison > 0) {\n high = i - 1;\n continue;\n }\n return i;\n }\n return ~(high + 1);\n}\n\n/**\n * A function used to compare two items while performing a binary search.\n * @callback binarySearchComparator\n *\n * @param {*} a An item in the array.\n * @param {*} b The item being searched for.\n * @returns {number} Returns a negative value if a is less than b,\n * a positive value if a is greater than b, or\n * 0 if a is equal to b.\n *\n * @example\n * function compareNumbers(a, b) {\n * return a - b;\n * }\n */\nexport default binarySearch;\n", "/**\n * A set of Earth Orientation Parameters (EOP) sampled at a time.\n *\n * @alias EarthOrientationParametersSample\n * @constructor\n *\n * @param {number} xPoleWander The pole wander about the X axis, in radians.\n * @param {number} yPoleWander The pole wander about the Y axis, in radians.\n * @param {number} xPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\n * @param {number} yPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\n * @param {number} ut1MinusUtc The difference in time standards, UT1 - UTC, in seconds.\n *\n * @private\n */\nfunction EarthOrientationParametersSample(\n xPoleWander,\n yPoleWander,\n xPoleOffset,\n yPoleOffset,\n ut1MinusUtc\n) {\n /**\n * The pole wander about the X axis, in radians.\n * @type {number}\n */\n this.xPoleWander = xPoleWander;\n\n /**\n * The pole wander about the Y axis, in radians.\n * @type {number}\n */\n this.yPoleWander = yPoleWander;\n\n /**\n * The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.\n * @type {number}\n */\n this.xPoleOffset = xPoleOffset;\n\n /**\n * The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.\n * @type {number}\n */\n this.yPoleOffset = yPoleOffset;\n\n /**\n * The difference in time standards, UT1 - UTC, in seconds.\n * @type {number}\n */\n this.ut1MinusUtc = ut1MinusUtc;\n}\nexport default EarthOrientationParametersSample;\n", "/**\n * Represents a Gregorian date in a more precise format than the JavaScript Date object.\n * In addition to submillisecond precision, this object can also represent leap seconds.\n * @alias GregorianDate\n * @constructor\n *\n * @param {number} [year] The year as a whole number.\n * @param {number} [month] The month as a whole number with range [1, 12].\n * @param {number} [day] The day of the month as a whole number starting at 1.\n * @param {number} [hour] The hour as a whole number with range [0, 23].\n * @param {number} [minute] The minute of the hour as a whole number with range [0, 59].\n * @param {number} [second] The second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\n * @param {number} [millisecond] The millisecond of the second as a floating point number with range [0.0, 1000.0).\n * @param {boolean} [isLeapSecond] Whether this time is during a leap second.\n *\n * @see JulianDate#toGregorianDate\n */\nfunction GregorianDate(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond,\n isLeapSecond\n) {\n /**\n * Gets or sets the year as a whole number.\n * @type {number}\n */\n this.year = year;\n /**\n * Gets or sets the month as a whole number with range [1, 12].\n * @type {number}\n */\n this.month = month;\n /**\n * Gets or sets the day of the month as a whole number starting at 1.\n * @type {number}\n */\n this.day = day;\n /**\n * Gets or sets the hour as a whole number with range [0, 23].\n * @type {number}\n */\n this.hour = hour;\n /**\n * Gets or sets the minute of the hour as a whole number with range [0, 59].\n * @type {number}\n */\n this.minute = minute;\n /**\n * Gets or sets the second of the minute as a whole number with range [0, 60], with 60 representing a leap second.\n * @type {number}\n */\n this.second = second;\n /**\n * Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0).\n * @type {number}\n */\n this.millisecond = millisecond;\n /**\n * Gets or sets whether this time is during a leap second.\n * @type {boolean}\n */\n this.isLeapSecond = isLeapSecond;\n}\nexport default GregorianDate;\n", "import DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Determines if a given date is a leap year.\n *\n * @function isLeapYear\n *\n * @param {number} year The year to be tested.\n * @returns {boolean} True if year is a leap year.\n *\n * @example\n * const leapYear = Cesium.isLeapYear(2000); // true\n */\nfunction isLeapYear(year) {\n //>>includeStart('debug', pragmas.debug);\n if (year === null || isNaN(year)) {\n throw new DeveloperError(\"year is required and must be a number.\");\n }\n //>>includeEnd('debug');\n\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\nexport default isLeapYear;\n", "/**\n * Describes a single leap second, which is constructed from a {@link JulianDate} and a\n * numerical offset representing the number of seconds TAI is ahead of the UTC time standard.\n * @alias LeapSecond\n * @constructor\n *\n * @param {JulianDate} [date] A Julian date representing the time of the leap second.\n * @param {number} [offset] The cumulative number of seconds that TAI is ahead of UTC at the provided date.\n */\nfunction LeapSecond(date, offset) {\n /**\n * Gets or sets the date at which this leap second occurs.\n * @type {JulianDate}\n */\n this.julianDate = date;\n\n /**\n * Gets or sets the cumulative number of seconds between the UTC and TAI time standards at the time\n * of this leap second.\n * @type {number}\n */\n this.offset = offset;\n}\nexport default LeapSecond;\n", "/**\n * Constants for time conversions like those done by {@link JulianDate}.\n *\n * @namespace TimeConstants\n *\n * @see JulianDate\n *\n * @private\n */\nconst TimeConstants = {\n /**\n * The number of seconds in one millisecond: 0.001\n * @type {number}\n * @constant\n */\n SECONDS_PER_MILLISECOND: 0.001,\n\n /**\n * The number of seconds in one minute: 60.\n * @type {number}\n * @constant\n */\n SECONDS_PER_MINUTE: 60.0,\n\n /**\n * The number of minutes in one hour: 60.\n * @type {number}\n * @constant\n */\n MINUTES_PER_HOUR: 60.0,\n\n /**\n * The number of hours in one day: 24.\n * @type {number}\n * @constant\n */\n HOURS_PER_DAY: 24.0,\n\n /**\n * The number of seconds in one hour: 3600.\n * @type {number}\n * @constant\n */\n SECONDS_PER_HOUR: 3600.0,\n\n /**\n * The number of minutes in one day: 1440.\n * @type {number}\n * @constant\n */\n MINUTES_PER_DAY: 1440.0,\n\n /**\n * The number of seconds in one day, ignoring leap seconds: 86400.\n * @type {number}\n * @constant\n */\n SECONDS_PER_DAY: 86400.0,\n\n /**\n * The number of days in one Julian century: 36525.\n * @type {number}\n * @constant\n */\n DAYS_PER_JULIAN_CENTURY: 36525.0,\n\n /**\n * One trillionth of a second.\n * @type {number}\n * @constant\n */\n PICOSECOND: 0.000000001,\n\n /**\n * The number of days to subtract from a Julian date to determine the\n * modified Julian date, which gives the number of days since midnight\n * on November 17, 1858.\n * @type {number}\n * @constant\n */\n MODIFIED_JULIAN_DATE_DIFFERENCE: 2400000.5,\n};\nexport default Object.freeze(TimeConstants);\n", "/**\n * Provides the type of time standards which JulianDate can take as input.\n *\n * @enum {number}\n *\n * @see JulianDate\n */\nconst TimeStandard = {\n /**\n * Represents the coordinated Universal Time (UTC) time standard.\n *\n * UTC is related to TAI according to the relationship\n * UTC = TAI - deltaT where deltaT is the number of leap\n * seconds which have been introduced as of the time in TAI.\n *\n * @type {number}\n * @constant\n */\n UTC: 0,\n\n /**\n * Represents the International Atomic Time (TAI) time standard.\n * TAI is the principal time standard to which the other time standards are related.\n *\n * @type {number}\n * @constant\n */\n TAI: 1,\n};\nexport default Object.freeze(TimeStandard);\n", "import binarySearch from \"./binarySearch.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport GregorianDate from \"./GregorianDate.js\";\nimport isLeapYear from \"./isLeapYear.js\";\nimport LeapSecond from \"./LeapSecond.js\";\nimport TimeConstants from \"./TimeConstants.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\nconst gregorianDateScratch = new GregorianDate();\nconst daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst daysInLeapFeburary = 29;\n\nfunction compareLeapSecondDates(leapSecond, dateToFind) {\n return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate);\n}\n\n// we don't really need a leap second instance, anything with a julianDate property will do\nconst binarySearchScratchLeapSecond = new LeapSecond();\n\nfunction convertUtcToTai(julianDate) {\n //Even though julianDate is in UTC, we'll treat it as TAI and\n //search the leap second table for it.\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n\n if (index < 0) {\n index = ~index;\n }\n\n if (index >= leapSeconds.length) {\n index = leapSeconds.length - 1;\n }\n\n let offset = leapSeconds[index].offset;\n if (index > 0) {\n //Now we have the index of the closest leap second that comes on or after our UTC time.\n //However, if the difference between the UTC date being converted and the TAI\n //defined leap second is greater than the offset, we are off by one and need to use\n //the previous leap second.\n const difference = JulianDate.secondsDifference(\n leapSeconds[index].julianDate,\n julianDate\n );\n if (difference > offset) {\n index--;\n offset = leapSeconds[index].offset;\n }\n }\n\n JulianDate.addSeconds(julianDate, offset, julianDate);\n}\n\nfunction convertTaiToUtc(julianDate, result) {\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n if (index < 0) {\n index = ~index;\n }\n\n //All times before our first leap second get the first offset.\n if (index === 0) {\n return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result);\n }\n\n //All times after our leap second get the last offset.\n if (index >= leapSeconds.length) {\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[index - 1].offset,\n result\n );\n }\n\n //Compute the difference between the found leap second and the time we are converting.\n const difference = JulianDate.secondsDifference(\n leapSeconds[index].julianDate,\n julianDate\n );\n\n if (difference === 0) {\n //The date is in our leap second table.\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[index].offset,\n result\n );\n }\n\n if (difference <= 1.0) {\n //The requested date is during the moment of a leap second, then we cannot convert to UTC\n return undefined;\n }\n\n //The time is in between two leap seconds, index is the leap second after the date\n //we're converting, so we subtract one to get the correct LeapSecond instance.\n return JulianDate.addSeconds(\n julianDate,\n -leapSeconds[--index].offset,\n result\n );\n}\n\nfunction setComponents(wholeDays, secondsOfDay, julianDate) {\n const extraDays = (secondsOfDay / TimeConstants.SECONDS_PER_DAY) | 0;\n wholeDays += extraDays;\n secondsOfDay -= TimeConstants.SECONDS_PER_DAY * extraDays;\n\n if (secondsOfDay < 0) {\n wholeDays--;\n secondsOfDay += TimeConstants.SECONDS_PER_DAY;\n }\n\n julianDate.dayNumber = wholeDays;\n julianDate.secondsOfDay = secondsOfDay;\n return julianDate;\n}\n\nfunction computeJulianDateComponents(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond\n) {\n // Algorithm from page 604 of the Explanatory Supplement to the\n // Astronomical Almanac (Seidelmann 1992).\n\n const a = ((month - 14) / 12) | 0;\n const b = year + 4800 + a;\n let dayNumber =\n (((1461 * b) / 4) | 0) +\n (((367 * (month - 2 - 12 * a)) / 12) | 0) -\n (((3 * (((b + 100) / 100) | 0)) / 4) | 0) +\n day -\n 32075;\n\n // JulianDates are noon-based\n hour = hour - 12;\n if (hour < 0) {\n hour += 24;\n }\n\n const secondsOfDay =\n second +\n (hour * TimeConstants.SECONDS_PER_HOUR +\n minute * TimeConstants.SECONDS_PER_MINUTE +\n millisecond * TimeConstants.SECONDS_PER_MILLISECOND);\n\n if (secondsOfDay >= 43200.0) {\n dayNumber -= 1;\n }\n\n return [dayNumber, secondsOfDay];\n}\n\n//Regular expressions used for ISO8601 date parsing.\n//YYYY\nconst matchCalendarYear = /^(\\d{4})$/;\n//YYYY-MM (YYYYMM is invalid)\nconst matchCalendarMonth = /^(\\d{4})-(\\d{2})$/;\n//YYYY-DDD or YYYYDDD\nconst matchOrdinalDate = /^(\\d{4})-?(\\d{3})$/;\n//YYYY-Www or YYYYWww or YYYY-Www-D or YYYYWwwD\nconst matchWeekDate = /^(\\d{4})-?W(\\d{2})-?(\\d{1})?$/;\n//YYYY-MM-DD or YYYYMMDD\nconst matchCalendarDate = /^(\\d{4})-?(\\d{2})-?(\\d{2})$/;\n// Match utc offset\nconst utcOffset = /([Z+\\-])?(\\d{2})?:?(\\d{2})?$/;\n// Match hours HH or HH.xxxxx\nconst matchHours = /^(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n// Match hours/minutes HH:MM HHMM.xxxxx\nconst matchHoursMinutes = /^(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n// Match hours/minutes HH:MM:SS HHMMSS.xxxxx\nconst matchHoursMinutesSeconds =\n /^(\\d{2}):?(\\d{2}):?(\\d{2})(\\.\\d+)?/.source + utcOffset.source;\n\nconst iso8601ErrorMessage = \"Invalid ISO 8601 date.\";\n\n/**\n * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC).\n * For increased precision, this class stores the whole number part of the date and the seconds\n * part of the date in separate components. In order to be safe for arithmetic and represent\n * leap seconds, the date is always stored in the International Atomic Time standard\n * {@link TimeStandard.TAI}.\n * @alias JulianDate\n * @constructor\n *\n * @param {number} [julianDayNumber=0.0] The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly.\n * @param {number} [secondsOfDay=0.0] The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly.\n * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined.\n */\nfunction JulianDate(julianDayNumber, secondsOfDay, timeStandard) {\n /**\n * Gets or sets the number of whole days.\n * @type {number}\n */\n this.dayNumber = undefined;\n\n /**\n * Gets or sets the number of seconds into the current day.\n * @type {number}\n */\n this.secondsOfDay = undefined;\n\n julianDayNumber = defaultValue(julianDayNumber, 0.0);\n secondsOfDay = defaultValue(secondsOfDay, 0.0);\n timeStandard = defaultValue(timeStandard, TimeStandard.UTC);\n\n //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented.\n const wholeDays = julianDayNumber | 0;\n secondsOfDay =\n secondsOfDay +\n (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY;\n\n setComponents(wholeDays, secondsOfDay, this);\n\n if (timeStandard === TimeStandard.UTC) {\n convertUtcToTai(this);\n }\n}\n\n/**\n * Creates a new instance from a GregorianDate.\n *\n * @param {GregorianDate} date A GregorianDate.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} date must be a valid GregorianDate.\n */\nJulianDate.fromGregorianDate = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!(date instanceof GregorianDate)) {\n throw new DeveloperError(\"date must be a valid GregorianDate.\");\n }\n //>>includeEnd('debug');\n\n const components = computeJulianDateComponents(\n date.year,\n date.month,\n date.day,\n date.hour,\n date.minute,\n date.second,\n date.millisecond\n );\n if (!defined(result)) {\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\n }\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n return result;\n};\n\n/**\n * Creates a new instance from a JavaScript Date.\n *\n * @param {Date} date A JavaScript Date.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} date must be a valid JavaScript Date.\n */\nJulianDate.fromDate = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!(date instanceof Date) || isNaN(date.getTime())) {\n throw new DeveloperError(\"date must be a valid JavaScript Date.\");\n }\n //>>includeEnd('debug');\n\n const components = computeJulianDateComponents(\n date.getUTCFullYear(),\n date.getUTCMonth() + 1,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds()\n );\n if (!defined(result)) {\n return new JulianDate(components[0], components[1], TimeStandard.UTC);\n }\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n return result;\n};\n\n/**\n * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date.\n * This method is superior to Date.parse because it will handle all valid formats defined by the ISO 8601\n * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations.\n *\n * @param {string} iso8601String An ISO 8601 date.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n *\n * @exception {DeveloperError} Invalid ISO 8601 date.\n */\nJulianDate.fromIso8601 = function (iso8601String, result) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof iso8601String !== \"string\") {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n\n //Comma and decimal point both indicate a fractional number according to ISO 8601,\n //start out by blanket replacing , with . which is the only valid such symbol in JS.\n iso8601String = iso8601String.replace(\",\", \".\");\n\n //Split the string into its date and time components, denoted by a mandatory T\n let tokens = iso8601String.split(\"T\");\n let year;\n let month = 1;\n let day = 1;\n let hour = 0;\n let minute = 0;\n let second = 0;\n let millisecond = 0;\n\n //Lacking a time is okay, but a missing date is illegal.\n const date = tokens[0];\n const time = tokens[1];\n let tmp;\n let inLeapYear;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n\n let dashCount;\n //>>includeEnd('debug');\n\n //First match the date against possible regular expressions.\n tokens = date.match(matchCalendarDate);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = date.split(\"-\").length - 1;\n if (dashCount > 0 && dashCount !== 2) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n year = +tokens[1];\n month = +tokens[2];\n day = +tokens[3];\n } else {\n tokens = date.match(matchCalendarMonth);\n if (tokens !== null) {\n year = +tokens[1];\n month = +tokens[2];\n } else {\n tokens = date.match(matchCalendarYear);\n if (tokens !== null) {\n year = +tokens[1];\n } else {\n //Not a year/month/day so it must be an ordinal date.\n let dayOfYear;\n tokens = date.match(matchOrdinalDate);\n if (tokens !== null) {\n year = +tokens[1];\n dayOfYear = +tokens[2];\n inLeapYear = isLeapYear(year);\n\n //This validation is only applicable for this format.\n //>>includeStart('debug', pragmas.debug);\n if (\n dayOfYear < 1 ||\n (inLeapYear && dayOfYear > 366) ||\n (!inLeapYear && dayOfYear > 365)\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n } else {\n tokens = date.match(matchWeekDate);\n if (tokens !== null) {\n //ISO week date to ordinal date from\n //http://en.wikipedia.org/w/index.php?title=ISO_week_date&oldid=474176775\n year = +tokens[1];\n const weekNumber = +tokens[2];\n const dayOfWeek = +tokens[3] || 0;\n\n //>>includeStart('debug', pragmas.debug);\n dashCount = date.split(\"-\").length - 1;\n if (\n dashCount > 0 &&\n ((!defined(tokens[3]) && dashCount !== 1) ||\n (defined(tokens[3]) && dashCount !== 2))\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n const january4 = new Date(Date.UTC(year, 0, 4));\n dayOfYear = weekNumber * 7 + dayOfWeek - january4.getUTCDay() - 3;\n } else {\n //None of our regular expressions succeeded in parsing the date properly.\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(iso8601ErrorMessage);\n //>>includeEnd('debug')\n }\n }\n //Split an ordinal date into month/day.\n tmp = new Date(Date.UTC(year, 0, 1));\n tmp.setUTCDate(dayOfYear);\n month = tmp.getUTCMonth() + 1;\n day = tmp.getUTCDate();\n }\n }\n }\n\n //Now that we have all of the date components, validate them to make sure nothing is out of range.\n inLeapYear = isLeapYear(year);\n //>>includeStart('debug', pragmas.debug);\n if (\n month < 1 ||\n month > 12 ||\n day < 1 ||\n ((month !== 2 || !inLeapYear) && day > daysInMonth[month - 1]) ||\n (inLeapYear && month === 2 && day > daysInLeapFeburary)\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n //Now move onto the time string, which is much simpler.\n //If no time is specified, it is considered the beginning of the day, UTC to match Javascript's implementation.\n let offsetIndex;\n if (defined(time)) {\n tokens = time.match(matchHoursMinutesSeconds);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = time.split(\":\").length - 1;\n if (dashCount > 0 && dashCount !== 2 && dashCount !== 3) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n hour = +tokens[1];\n minute = +tokens[2];\n second = +tokens[3];\n millisecond = +(tokens[4] || 0) * 1000.0;\n offsetIndex = 5;\n } else {\n tokens = time.match(matchHoursMinutes);\n if (tokens !== null) {\n //>>includeStart('debug', pragmas.debug);\n dashCount = time.split(\":\").length - 1;\n if (dashCount > 2) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug')\n\n hour = +tokens[1];\n minute = +tokens[2];\n second = +(tokens[3] || 0) * 60.0;\n offsetIndex = 4;\n } else {\n tokens = time.match(matchHours);\n if (tokens !== null) {\n hour = +tokens[1];\n minute = +(tokens[2] || 0) * 60.0;\n offsetIndex = 3;\n } else {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(iso8601ErrorMessage);\n //>>includeEnd('debug')\n }\n }\n }\n\n //Validate that all values are in proper range. Minutes and hours have special cases at 60 and 24.\n //>>includeStart('debug', pragmas.debug);\n if (\n minute >= 60 ||\n second >= 61 ||\n hour > 24 ||\n (hour === 24 && (minute > 0 || second > 0 || millisecond > 0))\n ) {\n throw new DeveloperError(iso8601ErrorMessage);\n }\n //>>includeEnd('debug');\n\n //Check the UTC offset value, if no value exists, use local time\n //a Z indicates UTC, + or - are offsets.\n const offset = tokens[offsetIndex];\n const offsetHours = +tokens[offsetIndex + 1];\n const offsetMinutes = +(tokens[offsetIndex + 2] || 0);\n switch (offset) {\n case \"+\":\n hour = hour - offsetHours;\n minute = minute - offsetMinutes;\n break;\n case \"-\":\n hour = hour + offsetHours;\n minute = minute + offsetMinutes;\n break;\n case \"Z\":\n break;\n default:\n minute =\n minute +\n new Date(\n Date.UTC(year, month - 1, day, hour, minute)\n ).getTimezoneOffset();\n break;\n }\n }\n\n //ISO8601 denotes a leap second by any time having a seconds component of 60 seconds.\n //If that's the case, we need to temporarily subtract a second in order to build a UTC date.\n //Then we add it back in after converting to TAI.\n const isLeapSecond = second === 60;\n if (isLeapSecond) {\n second--;\n }\n\n //Even if we successfully parsed the string into its components, after applying UTC offset or\n //special cases like 24:00:00 denoting midnight, we need to normalize the data appropriately.\n\n //milliseconds can never be greater than 1000, and seconds can't be above 60, so we start with minutes\n while (minute >= 60) {\n minute -= 60;\n hour++;\n }\n\n while (hour >= 24) {\n hour -= 24;\n day++;\n }\n\n tmp = inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n while (day > tmp) {\n day -= tmp;\n month++;\n\n if (month > 12) {\n month -= 12;\n year++;\n }\n\n tmp =\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n }\n\n //If UTC offset is at the beginning/end of the day, minutes can be negative.\n while (minute < 0) {\n minute += 60;\n hour--;\n }\n\n while (hour < 0) {\n hour += 24;\n day--;\n }\n\n while (day < 1) {\n month--;\n if (month < 1) {\n month += 12;\n year--;\n }\n\n tmp =\n inLeapYear && month === 2 ? daysInLeapFeburary : daysInMonth[month - 1];\n day += tmp;\n }\n\n //Now create the JulianDate components from the Gregorian date and actually create our instance.\n const components = computeJulianDateComponents(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond\n );\n\n if (!defined(result)) {\n result = new JulianDate(components[0], components[1], TimeStandard.UTC);\n } else {\n setComponents(components[0], components[1], result);\n convertUtcToTai(result);\n }\n\n //If we were on a leap second, add it back.\n if (isLeapSecond) {\n JulianDate.addSeconds(result, 1, result);\n }\n\n return result;\n};\n\n/**\n * Creates a new instance that represents the current system time.\n * This is equivalent to calling JulianDate.fromDate(new Date());.\n *\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.now = function (result) {\n return JulianDate.fromDate(new Date(), result);\n};\n\nconst toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI);\n\n/**\n * Creates a {@link GregorianDate} from the provided instance.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @param {GregorianDate} [result] An existing instance to use for the result.\n * @returns {GregorianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.toGregorianDate = function (julianDate, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n let isLeapSecond = false;\n let thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch);\n if (!defined(thisUtc)) {\n //Conversion to UTC will fail if we are during a leap second.\n //If that's the case, subtract a second and convert again.\n //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice.\n JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch);\n thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch);\n isLeapSecond = true;\n }\n\n let julianDayNumber = thisUtc.dayNumber;\n const secondsOfDay = thisUtc.secondsOfDay;\n\n if (secondsOfDay >= 43200.0) {\n julianDayNumber += 1;\n }\n\n // Algorithm from page 604 of the Explanatory Supplement to the\n // Astronomical Almanac (Seidelmann 1992).\n let L = (julianDayNumber + 68569) | 0;\n const N = ((4 * L) / 146097) | 0;\n L = (L - (((146097 * N + 3) / 4) | 0)) | 0;\n const I = ((4000 * (L + 1)) / 1461001) | 0;\n L = (L - (((1461 * I) / 4) | 0) + 31) | 0;\n const J = ((80 * L) / 2447) | 0;\n const day = (L - (((2447 * J) / 80) | 0)) | 0;\n L = (J / 11) | 0;\n const month = (J + 2 - 12 * L) | 0;\n const year = (100 * (N - 49) + I + L) | 0;\n\n let hour = (secondsOfDay / TimeConstants.SECONDS_PER_HOUR) | 0;\n let remainingSeconds = secondsOfDay - hour * TimeConstants.SECONDS_PER_HOUR;\n const minute = (remainingSeconds / TimeConstants.SECONDS_PER_MINUTE) | 0;\n remainingSeconds =\n remainingSeconds - minute * TimeConstants.SECONDS_PER_MINUTE;\n let second = remainingSeconds | 0;\n const millisecond =\n (remainingSeconds - second) / TimeConstants.SECONDS_PER_MILLISECOND;\n\n // JulianDates are noon-based\n hour += 12;\n if (hour > 23) {\n hour -= 24;\n }\n\n //If we were on a leap second, add it back.\n if (isLeapSecond) {\n second += 1;\n }\n\n if (!defined(result)) {\n return new GregorianDate(\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond,\n isLeapSecond\n );\n }\n\n result.year = year;\n result.month = month;\n result.day = day;\n result.hour = hour;\n result.minute = minute;\n result.second = second;\n result.millisecond = millisecond;\n result.isLeapSecond = isLeapSecond;\n return result;\n};\n\n/**\n * Creates a JavaScript Date from the provided instance.\n * Since JavaScript dates are only accurate to the nearest millisecond and\n * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead.\n * If the provided JulianDate is during a leap second, the previous second is used.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @returns {Date} A new instance representing the provided date.\n */\nJulianDate.toDate = function (julianDate) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n const gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\n let second = gDate.second;\n if (gDate.isLeapSecond) {\n second -= 1;\n }\n return new Date(\n Date.UTC(\n gDate.year,\n gDate.month - 1,\n gDate.day,\n gDate.hour,\n gDate.minute,\n second,\n gDate.millisecond\n )\n );\n};\n\n/**\n * Creates an ISO8601 representation of the provided date.\n *\n * @param {JulianDate} julianDate The date to be converted.\n * @param {number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.\n * @returns {string} The ISO8601 representation of the provided date.\n */\nJulianDate.toIso8601 = function (julianDate, precision) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n\n const gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);\n let year = gDate.year;\n let month = gDate.month;\n let day = gDate.day;\n let hour = gDate.hour;\n const minute = gDate.minute;\n const second = gDate.second;\n const millisecond = gDate.millisecond;\n\n // special case - Iso8601.MAXIMUM_VALUE produces a string which we can't parse unless we adjust.\n // 10000-01-01T00:00:00 is the same instant as 9999-12-31T24:00:00\n if (\n year === 10000 &&\n month === 1 &&\n day === 1 &&\n hour === 0 &&\n minute === 0 &&\n second === 0 &&\n millisecond === 0\n ) {\n year = 9999;\n month = 12;\n day = 31;\n hour = 24;\n }\n\n let millisecondStr;\n\n if (!defined(precision) && millisecond !== 0) {\n //Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is.\n millisecondStr = (millisecond * 0.01).toString().replace(\".\", \"\");\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second\n .toString()\n .padStart(2, \"0\")}.${millisecondStr}Z`;\n }\n\n //Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely\n if (!defined(precision) || precision === 0) {\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second.toString().padStart(2, \"0\")}Z`;\n }\n\n //Forces milliseconds into a number with at least 3 digits to whatever the specified precision is.\n millisecondStr = (millisecond * 0.01)\n .toFixed(precision)\n .replace(\".\", \"\")\n .slice(0, precision);\n return `${year.toString().padStart(4, \"0\")}-${month\n .toString()\n .padStart(2, \"0\")}-${day\n .toString()\n .padStart(2, \"0\")}T${hour\n .toString()\n .padStart(2, \"0\")}:${minute\n .toString()\n .padStart(2, \"0\")}:${second\n .toString()\n .padStart(2, \"0\")}.${millisecondStr}Z`;\n};\n\n/**\n * Duplicates a JulianDate instance.\n *\n * @param {JulianDate} julianDate The date to duplicate.\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined.\n */\nJulianDate.clone = function (julianDate, result) {\n if (!defined(julianDate)) {\n return undefined;\n }\n if (!defined(result)) {\n return new JulianDate(\n julianDate.dayNumber,\n julianDate.secondsOfDay,\n TimeStandard.TAI\n );\n }\n result.dayNumber = julianDate.dayNumber;\n result.secondsOfDay = julianDate.secondsOfDay;\n return result;\n};\n\n/**\n * Compares two instances.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {number} A negative value if left is less than right, a positive value if left is greater than right, or zero if left and right are equal.\n */\nJulianDate.compare = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const julianDayNumberDifference = left.dayNumber - right.dayNumber;\n if (julianDayNumberDifference !== 0) {\n return julianDayNumberDifference;\n }\n return left.secondsOfDay - right.secondsOfDay;\n};\n\n/**\n * Compares two instances and returns true if they are equal, false otherwise.\n *\n * @param {JulianDate} [left] The first instance.\n * @param {JulianDate} [right] The second instance.\n * @returns {boolean} true if the dates are equal; otherwise, false.\n */\nJulianDate.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.dayNumber === right.dayNumber &&\n left.secondsOfDay === right.secondsOfDay)\n );\n};\n\n/**\n * Compares two instances and returns true if they are within epsilon seconds of\n * each other. That is, in order for the dates to be considered equal (and for\n * this function to return true), the absolute value of the difference between them, in\n * seconds, must be less than epsilon.\n *\n * @param {JulianDate} [left] The first instance.\n * @param {JulianDate} [right] The second instance.\n * @param {number} [epsilon=0] The maximum number of seconds that should separate the two instances.\n * @returns {boolean} true if the two dates are within epsilon seconds of each other; otherwise false.\n */\nJulianDate.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(JulianDate.secondsDifference(left, right)) <= epsilon)\n );\n};\n\n/**\n * Computes the total number of whole and fractional days represented by the provided instance.\n *\n * @param {JulianDate} julianDate The date.\n * @returns {number} The Julian date as single floating point number.\n */\nJulianDate.totalDays = function (julianDate) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n //>>includeEnd('debug');\n return (\n julianDate.dayNumber +\n julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY\n );\n};\n\n/**\n * Computes the difference in seconds between the provided instance.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {number} The difference, in seconds, when subtracting right from left.\n */\nJulianDate.secondsDifference = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const dayDifference =\n (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY;\n return dayDifference + (left.secondsOfDay - right.secondsOfDay);\n};\n\n/**\n * Computes the difference in days between the provided instance.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {number} The difference, in days, when subtracting right from left.\n */\nJulianDate.daysDifference = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\"left is required.\");\n }\n if (!defined(right)) {\n throw new DeveloperError(\"right is required.\");\n }\n //>>includeEnd('debug');\n\n const dayDifference = left.dayNumber - right.dayNumber;\n const secondDifference =\n (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY;\n return dayDifference + secondDifference;\n};\n\n/**\n * Computes the number of seconds the provided instance is ahead of UTC.\n *\n * @param {JulianDate} julianDate The date.\n * @returns {number} The number of seconds the provided instance is ahead of UTC\n */\nJulianDate.computeTaiMinusUtc = function (julianDate) {\n binarySearchScratchLeapSecond.julianDate = julianDate;\n const leapSeconds = JulianDate.leapSeconds;\n let index = binarySearch(\n leapSeconds,\n binarySearchScratchLeapSecond,\n compareLeapSecondDates\n );\n if (index < 0) {\n index = ~index;\n --index;\n if (index < 0) {\n index = 0;\n }\n }\n return leapSeconds[index].offset;\n};\n\n/**\n * Adds the provided number of seconds to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {number} seconds The number of seconds to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addSeconds = function (julianDate, seconds, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(seconds)) {\n throw new DeveloperError(\"seconds is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n return setComponents(\n julianDate.dayNumber,\n julianDate.secondsOfDay + seconds,\n result\n );\n};\n\n/**\n * Adds the provided number of minutes to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {number} minutes The number of minutes to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addMinutes = function (julianDate, minutes, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(minutes)) {\n throw new DeveloperError(\"minutes is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newSecondsOfDay =\n julianDate.secondsOfDay + minutes * TimeConstants.SECONDS_PER_MINUTE;\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\n};\n\n/**\n * Adds the provided number of hours to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {number} hours The number of hours to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addHours = function (julianDate, hours, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(hours)) {\n throw new DeveloperError(\"hours is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newSecondsOfDay =\n julianDate.secondsOfDay + hours * TimeConstants.SECONDS_PER_HOUR;\n return setComponents(julianDate.dayNumber, newSecondsOfDay, result);\n};\n\n/**\n * Adds the provided number of days to the provided date instance.\n *\n * @param {JulianDate} julianDate The date.\n * @param {number} days The number of days to add or subtract.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n */\nJulianDate.addDays = function (julianDate, days, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(julianDate)) {\n throw new DeveloperError(\"julianDate is required.\");\n }\n if (!defined(days)) {\n throw new DeveloperError(\"days is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const newJulianDayNumber = julianDate.dayNumber + days;\n return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result);\n};\n\n/**\n * Compares the provided instances and returns true if left is earlier than right, false otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {boolean} true if left is earlier than right, false otherwise.\n */\nJulianDate.lessThan = function (left, right) {\n return JulianDate.compare(left, right) < 0;\n};\n\n/**\n * Compares the provided instances and returns true if left is earlier than or equal to right, false otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {boolean} true if left is earlier than or equal to right, false otherwise.\n */\nJulianDate.lessThanOrEquals = function (left, right) {\n return JulianDate.compare(left, right) <= 0;\n};\n\n/**\n * Compares the provided instances and returns true if left is later than right, false otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {boolean} true if left is later than right, false otherwise.\n */\nJulianDate.greaterThan = function (left, right) {\n return JulianDate.compare(left, right) > 0;\n};\n\n/**\n * Compares the provided instances and returns true if left is later than or equal to right, false otherwise.\n *\n * @param {JulianDate} left The first instance.\n * @param {JulianDate} right The second instance.\n * @returns {boolean} true if left is later than or equal to right, false otherwise.\n */\nJulianDate.greaterThanOrEquals = function (left, right) {\n return JulianDate.compare(left, right) >= 0;\n};\n\n/**\n * Duplicates this instance.\n *\n * @param {JulianDate} [result] An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter or a new instance if none was provided.\n */\nJulianDate.prototype.clone = function (result) {\n return JulianDate.clone(this, result);\n};\n\n/**\n * Compares this and the provided instance and returns true if they are equal, false otherwise.\n *\n * @param {JulianDate} [right] The second instance.\n * @returns {boolean} true if the dates are equal; otherwise, false.\n */\nJulianDate.prototype.equals = function (right) {\n return JulianDate.equals(this, right);\n};\n\n/**\n * Compares this and the provided instance and returns true if they are within epsilon seconds of\n * each other. That is, in order for the dates to be considered equal (and for\n * this function to return true), the absolute value of the difference between them, in\n * seconds, must be less than epsilon.\n *\n * @param {JulianDate} [right] The second instance.\n * @param {number} [epsilon=0] The maximum number of seconds that should separate the two instances.\n * @returns {boolean} true if the two dates are within epsilon seconds of each other; otherwise false.\n */\nJulianDate.prototype.equalsEpsilon = function (right, epsilon) {\n return JulianDate.equalsEpsilon(this, right, epsilon);\n};\n\n/**\n * Creates a string representing this date in ISO8601 format.\n *\n * @returns {string} A string representing this date in ISO8601 format.\n */\nJulianDate.prototype.toString = function () {\n return JulianDate.toIso8601(this);\n};\n\n/**\n * Gets or sets the list of leap seconds used throughout Cesium.\n * @memberof JulianDate\n * @type {LeapSecond[]}\n */\nJulianDate.leapSeconds = [\n new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC\n new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC\n new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC\n new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC\n new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC\n new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC\n new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC\n new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC\n new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC\n new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC\n new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC\n new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC\n new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC\n new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC\n new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC\n new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC\n new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC\n new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC\n new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC\n new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC\n new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC\n new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC\n new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC\n new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC\n new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC\n new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35), // July 1, 2012 00:00:00 UTC\n new LeapSecond(new JulianDate(2457204, 43236.0, TimeStandard.TAI), 36), // July 1, 2015 00:00:00 UTC\n new LeapSecond(new JulianDate(2457754, 43237.0, TimeStandard.TAI), 37), // January 1, 2017 00:00:00 UTC\n];\nexport default JulianDate;\n", "import Uri from \"urijs\";\nimport appendForwardSlash from \"./appendForwardSlash.js\";\nimport Check from \"./Check.js\";\nimport clone from \"./clone.js\";\nimport combine from \"./combine.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defer from \"./defer.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\nimport getBaseUri from \"./getBaseUri.js\";\nimport getExtensionFromUri from \"./getExtensionFromUri.js\";\nimport getImagePixels from \"./getImagePixels.js\";\nimport isBlobUri from \"./isBlobUri.js\";\nimport isCrossOriginUrl from \"./isCrossOriginUrl.js\";\nimport isDataUri from \"./isDataUri.js\";\nimport loadAndExecuteScript from \"./loadAndExecuteScript.js\";\nimport CesiumMath from \"./Math.js\";\nimport objectToQuery from \"./objectToQuery.js\";\nimport queryToObject from \"./queryToObject.js\";\nimport Request from \"./Request.js\";\nimport RequestErrorEvent from \"./RequestErrorEvent.js\";\nimport RequestScheduler from \"./RequestScheduler.js\";\nimport RequestState from \"./RequestState.js\";\nimport RuntimeError from \"./RuntimeError.js\";\nimport TrustedServers from \"./TrustedServers.js\";\n\nconst xhrBlobSupported = (function () {\n try {\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", \"#\", true);\n xhr.responseType = \"blob\";\n return xhr.responseType === \"blob\";\n } catch (e) {\n return false;\n }\n})();\n\n/**\n * @typedef {object} Resource.ConstructorOptions\n *\n * Initialization options for the Resource constructor\n *\n * @property {string} url The url of the resource.\n * @property {object} [queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @property {object} [templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @property {object} [headers={}] Additional HTTP headers that will be sent.\n * @property {Proxy} [proxy] A proxy to be used when loading the resource.\n * @property {Resource.RetryCallback} [retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @property {number} [retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @property {Request} [request] A Request object that will be used. Intended for internal use only.\n * @property {boolean} [parseUrl=true] If true, parse the url for query parameters; otherwise store the url without change\n */\n\n/**\n * A resource that includes the location and any other parameters we need to retrieve it or create derived resources. It also provides the ability to retry requests.\n *\n * @alias Resource\n * @constructor\n *\n * @param {string|Resource.ConstructorOptions} options A url or an object describing initialization options\n *\n * @example\n * function refreshTokenRetryCallback(resource, error) {\n * if (error.statusCode === 403) {\n * // 403 status code means a new token should be generated\n * return getNewAccessToken()\n * .then(function(token) {\n * resource.queryParameters.access_token = token;\n * return true;\n * })\n * .catch(function() {\n * return false;\n * });\n * }\n *\n * return false;\n * }\n *\n * const resource = new Resource({\n * url: 'http://server.com/path/to/resource.json',\n * proxy: new DefaultProxy('/proxy/'),\n * headers: {\n * 'X-My-Header': 'valueOfHeader'\n * },\n * queryParameters: {\n * 'access_token': '123-435-456-000'\n * },\n * retryCallback: refreshTokenRetryCallback,\n * retryAttempts: 1\n * });\n */\nfunction Resource(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n if (typeof options === \"string\") {\n options = {\n url: options,\n };\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.url\", options.url);\n //>>includeEnd('debug');\n\n this._url = undefined;\n this._templateValues = defaultClone(options.templateValues, {});\n this._queryParameters = defaultClone(options.queryParameters, {});\n\n /**\n * Additional HTTP headers that will be sent with the request.\n *\n * @type {object}\n */\n this.headers = defaultClone(options.headers, {});\n\n /**\n * A Request object that will be used. Intended for internal use only.\n *\n * @type {Request}\n */\n this.request = defaultValue(options.request, new Request());\n\n /**\n * A proxy to be used when loading the resource.\n *\n * @type {Proxy}\n */\n this.proxy = options.proxy;\n\n /**\n * Function to call when a request for this resource fails. If it returns true or a Promise that resolves to true, the request will be retried.\n *\n * @type {Function}\n */\n this.retryCallback = options.retryCallback;\n\n /**\n * The number of times the retryCallback should be called before giving up.\n *\n * @type {number}\n */\n this.retryAttempts = defaultValue(options.retryAttempts, 0);\n this._retryCount = 0;\n\n const parseUrl = defaultValue(options.parseUrl, true);\n if (parseUrl) {\n this.parseUrl(options.url, true, true);\n } else {\n this._url = options.url;\n }\n\n this._credits = options.credits;\n}\n\n/**\n * Clones a value if it is defined, otherwise returns the default value\n *\n * @param {object} [value] The value to clone.\n * @param {object} [defaultValue] The default value.\n *\n * @returns {object} A clone of value or the defaultValue.\n *\n * @private\n */\nfunction defaultClone(value, defaultValue) {\n return defined(value) ? clone(value) : defaultValue;\n}\n\n/**\n * A helper function to create a resource depending on whether we have a String or a Resource\n *\n * @param {Resource|string} resource A Resource or a String to use when creating a new Resource.\n *\n * @returns {Resource} If resource is a String, a Resource constructed with the url and options. Otherwise the resource parameter is returned.\n *\n * @private\n */\nResource.createIfNeeded = function (resource) {\n if (resource instanceof Resource) {\n // Keep existing request object. This function is used internally to duplicate a Resource, so that it can't\n // be modified outside of a class that holds it (eg. an imagery or terrain provider). Since the Request objects\n // are managed outside of the providers, by the tile loading code, we want to keep the request property the same so if it is changed\n // in the underlying tiling code the requests for this resource will use it.\n return resource.getDerivedResource({\n request: resource.request,\n });\n }\n\n if (typeof resource !== \"string\") {\n return resource;\n }\n\n return new Resource({\n url: resource,\n });\n};\n\nlet supportsImageBitmapOptionsPromise;\n/**\n * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions.\n *\n * @returns {Promise} A promise that resolves to true if this browser supports creating an ImageBitmap with options.\n *\n * @private\n */\nResource.supportsImageBitmapOptions = function () {\n // Until the HTML folks figure out what to do about this, we need to actually try loading an image to\n // know if this browser supports passing options to the createImageBitmap function.\n // https://github.com/whatwg/html/pull/4248\n //\n // We also need to check whether the colorSpaceConversion option is supported.\n // We do this by loading a PNG with an embedded color profile, first with\n // colorSpaceConversion: \"none\" and then with colorSpaceConversion: \"default\".\n // If the pixel color is different then we know the option is working.\n // As of Webkit 17612.3.6.1.6 the createImageBitmap promise resolves but the\n // option is not actually supported.\n if (defined(supportsImageBitmapOptionsPromise)) {\n return supportsImageBitmapOptionsPromise;\n }\n\n if (typeof createImageBitmap !== \"function\") {\n supportsImageBitmapOptionsPromise = Promise.resolve(false);\n return supportsImageBitmapOptionsPromise;\n }\n\n const imageDataUri =\n \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAABGdBTUEAAE4g3rEiDgAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAADElEQVQI12Ng6GAAAAEUAIngE3ZiAAAAAElFTkSuQmCC\";\n\n supportsImageBitmapOptionsPromise = Resource.fetchBlob({\n url: imageDataUri,\n })\n .then(function (blob) {\n const imageBitmapOptions = {\n imageOrientation: \"flipY\", // default is \"none\"\n premultiplyAlpha: \"none\", // default is \"default\"\n colorSpaceConversion: \"none\", // default is \"default\"\n };\n return Promise.all([\n createImageBitmap(blob, imageBitmapOptions),\n createImageBitmap(blob),\n ]);\n })\n .then(function (imageBitmaps) {\n // Check whether the colorSpaceConversion option had any effect on the green channel\n const colorWithOptions = getImagePixels(imageBitmaps[0]);\n const colorWithDefaults = getImagePixels(imageBitmaps[1]);\n return colorWithOptions[1] !== colorWithDefaults[1];\n })\n .catch(function () {\n return false;\n });\n\n return supportsImageBitmapOptionsPromise;\n};\n\nObject.defineProperties(Resource, {\n /**\n * Returns true if blobs are supported.\n *\n * @memberof Resource\n * @type {boolean}\n *\n * @readonly\n */\n isBlobSupported: {\n get: function () {\n return xhrBlobSupported;\n },\n },\n});\n\nObject.defineProperties(Resource.prototype, {\n /**\n * Query parameters appended to the url.\n *\n * @memberof Resource.prototype\n * @type {object}\n *\n * @readonly\n */\n queryParameters: {\n get: function () {\n return this._queryParameters;\n },\n },\n\n /**\n * The key/value pairs used to replace template parameters in the url.\n *\n * @memberof Resource.prototype\n * @type {object}\n *\n * @readonly\n */\n templateValues: {\n get: function () {\n return this._templateValues;\n },\n },\n\n /**\n * The url to the resource with template values replaced, query string appended and encoded by proxy if one was set.\n *\n * @memberof Resource.prototype\n * @type {string}\n */\n url: {\n get: function () {\n return this.getUrlComponent(true, true);\n },\n set: function (value) {\n this.parseUrl(value, false, false);\n },\n },\n\n /**\n * The file extension of the resource.\n *\n * @memberof Resource.prototype\n * @type {string}\n *\n * @readonly\n */\n extension: {\n get: function () {\n return getExtensionFromUri(this._url);\n },\n },\n\n /**\n * True if the Resource refers to a data URI.\n *\n * @memberof Resource.prototype\n * @type {boolean}\n */\n isDataUri: {\n get: function () {\n return isDataUri(this._url);\n },\n },\n\n /**\n * True if the Resource refers to a blob URI.\n *\n * @memberof Resource.prototype\n * @type {boolean}\n */\n isBlobUri: {\n get: function () {\n return isBlobUri(this._url);\n },\n },\n\n /**\n * True if the Resource refers to a cross origin URL.\n *\n * @memberof Resource.prototype\n * @type {boolean}\n */\n isCrossOriginUrl: {\n get: function () {\n return isCrossOriginUrl(this._url);\n },\n },\n\n /**\n * True if the Resource has request headers. This is equivalent to checking if the headers property has any keys.\n *\n * @memberof Resource.prototype\n * @type {boolean}\n */\n hasHeaders: {\n get: function () {\n return Object.keys(this.headers).length > 0;\n },\n },\n\n /**\n * Gets the credits required for attribution of an asset.\n * @private\n */\n credits: {\n get: function () {\n return this._credits;\n },\n },\n});\n\n/**\n * Override Object#toString so that implicit string conversion gives the\n * complete URL represented by this Resource.\n *\n * @returns {string} The URL represented by this Resource\n */\nResource.prototype.toString = function () {\n return this.getUrlComponent(true, true);\n};\n\n/**\n * Parse a url string, and store its info\n *\n * @param {string} url The input url string.\n * @param {boolean} merge If true, we'll merge with the resource's existing queryParameters. Otherwise they will be replaced.\n * @param {boolean} preserveQuery If true duplicate parameters will be concatenated into an array. If false, keys in url will take precedence.\n * @param {string} [baseUrl] If supplied, and input url is a relative url, it will be made absolute relative to baseUrl\n *\n * @private\n */\nResource.prototype.parseUrl = function (url, merge, preserveQuery, baseUrl) {\n let uri = new Uri(url);\n const query = parseQueryString(uri.query());\n\n this._queryParameters = merge\n ? combineQueryParameters(query, this.queryParameters, preserveQuery)\n : query;\n\n // Remove unneeded info from the Uri\n uri.search(\"\");\n uri.fragment(\"\");\n\n if (defined(baseUrl) && uri.scheme() === \"\") {\n uri = uri.absoluteTo(getAbsoluteUri(baseUrl));\n }\n\n this._url = uri.toString();\n};\n\n/**\n * Parses a query string and returns the object equivalent.\n *\n * @param {string} queryString The query string\n * @returns {object}\n *\n * @private\n */\nfunction parseQueryString(queryString) {\n if (queryString.length === 0) {\n return {};\n }\n\n // Special case where the querystring is just a string, not key/value pairs\n if (queryString.indexOf(\"=\") === -1) {\n return { [queryString]: undefined };\n }\n\n return queryToObject(queryString);\n}\n\n/**\n * This combines a map of query parameters.\n *\n * @param {object} q1 The first map of query parameters. Values in this map will take precedence if preserveQueryParameters is false.\n * @param {object} q2 The second map of query parameters.\n * @param {boolean} preserveQueryParameters If true duplicate parameters will be concatenated into an array. If false, keys in q1 will take precedence.\n *\n * @returns {object} The combined map of query parameters.\n *\n * @example\n * const q1 = {\n * a: 1,\n * b: 2\n * };\n * const q2 = {\n * a: 3,\n * c: 4\n * };\n * const q3 = {\n * b: [5, 6],\n * d: 7\n * }\n *\n * // Returns\n * // {\n * // a: [1, 3],\n * // b: 2,\n * // c: 4\n * // };\n * combineQueryParameters(q1, q2, true);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: 2,\n * // c: 4\n * // };\n * combineQueryParameters(q1, q2, false);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: [2, 5, 6],\n * // d: 7\n * // };\n * combineQueryParameters(q1, q3, true);\n *\n * // Returns\n * // {\n * // a: 1,\n * // b: 2,\n * // d: 7\n * // };\n * combineQueryParameters(q1, q3, false);\n *\n * @private\n */\nfunction combineQueryParameters(q1, q2, preserveQueryParameters) {\n if (!preserveQueryParameters) {\n return combine(q1, q2);\n }\n\n const result = clone(q1, true);\n for (const param in q2) {\n if (q2.hasOwnProperty(param)) {\n let value = result[param];\n const q2Value = q2[param];\n if (defined(value)) {\n if (!Array.isArray(value)) {\n value = result[param] = [value];\n }\n\n result[param] = value.concat(q2Value);\n } else {\n result[param] = Array.isArray(q2Value) ? q2Value.slice() : q2Value;\n }\n }\n }\n\n return result;\n}\n\n/**\n * Returns the url, optional with the query string and processed by a proxy.\n *\n * @param {boolean} [query=false] If true, the query string is included.\n * @param {boolean} [proxy=false] If true, the url is processed by the proxy object, if defined.\n *\n * @returns {string} The url with all the requested components.\n */\nResource.prototype.getUrlComponent = function (query, proxy) {\n if (this.isDataUri) {\n return this._url;\n }\n\n let url = this._url;\n if (query) {\n url = `${url}${stringifyQuery(this.queryParameters)}`;\n }\n\n // Restore the placeholders, which may have been escaped in objectToQuery or elsewhere\n url = url.replace(/%7B/g, \"{\").replace(/%7D/g, \"}\");\n\n const templateValues = this._templateValues;\n if (Object.keys(templateValues).length > 0) {\n url = url.replace(/{(.*?)}/g, function (match, key) {\n const replacement = templateValues[key];\n if (defined(replacement)) {\n // use the replacement value from templateValues if there is one...\n return encodeURIComponent(replacement);\n }\n // otherwise leave it unchanged\n return match;\n });\n }\n\n if (proxy && defined(this.proxy)) {\n url = this.proxy.getURL(url);\n }\n\n return url;\n};\n\n/**\n * Converts a query object into a string.\n *\n * @param {object} queryObject The object with query parameters\n * @returns {string}\n *\n * @private\n */\nfunction stringifyQuery(queryObject) {\n const keys = Object.keys(queryObject);\n\n if (keys.length === 0) {\n return \"\";\n }\n if (keys.length === 1 && !defined(queryObject[keys[0]])) {\n // We have 1 key with an undefined value, so this is just a string, not key/value pairs\n return `?${keys[0]}`;\n }\n\n return `?${objectToQuery(queryObject)}`;\n}\n\n/**\n * Combines the specified object and the existing query parameters. This allows you to add many parameters at once,\n * as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.\n *\n * @param {object} params The query parameters\n * @param {boolean} [useAsDefault=false] If true the params will be used as the default values, so they will only be set if they are undefined.\n */\nResource.prototype.setQueryParameters = function (params, useAsDefault) {\n if (useAsDefault) {\n this._queryParameters = combineQueryParameters(\n this._queryParameters,\n params,\n false\n );\n } else {\n this._queryParameters = combineQueryParameters(\n params,\n this._queryParameters,\n false\n );\n }\n};\n\n/**\n * Combines the specified object and the existing query parameters. This allows you to add many parameters at once,\n * as opposed to adding them one at a time to the queryParameters property.\n *\n * @param {object} params The query parameters\n */\nResource.prototype.appendQueryParameters = function (params) {\n this._queryParameters = combineQueryParameters(\n params,\n this._queryParameters,\n true\n );\n};\n\n/**\n * Combines the specified object and the existing template values. This allows you to add many values at once,\n * as opposed to adding them one at a time to the templateValues property. If a value is already set, it will become an array and the new value will be appended.\n *\n * @param {object} template The template values\n * @param {boolean} [useAsDefault=false] If true the values will be used as the default values, so they will only be set if they are undefined.\n */\nResource.prototype.setTemplateValues = function (template, useAsDefault) {\n if (useAsDefault) {\n this._templateValues = combine(this._templateValues, template);\n } else {\n this._templateValues = combine(template, this._templateValues);\n }\n};\n\n/**\n * Returns a resource relative to the current instance. All properties remain the same as the current instance unless overridden in options.\n *\n * @param {object} options An object with the following properties\n * @param {string} [options.url] The url that will be resolved relative to the url of the current instance.\n * @param {object} [options.queryParameters] An object containing query parameters that will be combined with those of the current instance.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance.\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The function to call when loading the resource fails.\n * @param {number} [options.retryAttempts] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {boolean} [options.preserveQueryParameters=false] If true, this will keep all query parameters from the current resource and derived resource. If false, derived parameters will replace those of the current resource.\n *\n * @returns {Resource} The resource derived from the current one.\n */\nResource.prototype.getDerivedResource = function (options) {\n const resource = this.clone();\n resource._retryCount = 0;\n\n if (defined(options.url)) {\n const preserveQuery = defaultValue(options.preserveQueryParameters, false);\n resource.parseUrl(options.url, true, preserveQuery, this._url);\n }\n\n if (defined(options.queryParameters)) {\n resource._queryParameters = combine(\n options.queryParameters,\n resource.queryParameters\n );\n }\n if (defined(options.templateValues)) {\n resource._templateValues = combine(\n options.templateValues,\n resource.templateValues\n );\n }\n if (defined(options.headers)) {\n resource.headers = combine(options.headers, resource.headers);\n }\n if (defined(options.proxy)) {\n resource.proxy = options.proxy;\n }\n if (defined(options.request)) {\n resource.request = options.request;\n }\n if (defined(options.retryCallback)) {\n resource.retryCallback = options.retryCallback;\n }\n if (defined(options.retryAttempts)) {\n resource.retryAttempts = options.retryAttempts;\n }\n\n return resource;\n};\n\n/**\n * Called when a resource fails to load. This will call the retryCallback function if defined until retryAttempts is reached.\n *\n * @param {RequestErrorEvent} [error] The error that was encountered.\n *\n * @returns {Promise} A promise to a boolean, that if true will cause the resource request to be retried.\n *\n * @private\n */\nResource.prototype.retryOnError = function (error) {\n const retryCallback = this.retryCallback;\n if (\n typeof retryCallback !== \"function\" ||\n this._retryCount >= this.retryAttempts\n ) {\n return Promise.resolve(false);\n }\n\n const that = this;\n return Promise.resolve(retryCallback(this, error)).then(function (result) {\n ++that._retryCount;\n\n return result;\n });\n};\n\n/**\n * Duplicates a Resource instance.\n *\n * @param {Resource} [result] The object onto which to store the result.\n *\n * @returns {Resource} The modified result parameter or a new Resource instance if one was not provided.\n */\nResource.prototype.clone = function (result) {\n if (!defined(result)) {\n return new Resource({\n url: this._url,\n queryParameters: this.queryParameters,\n templateValues: this.templateValues,\n headers: this.headers,\n proxy: this.proxy,\n retryCallback: this.retryCallback,\n retryAttempts: this.retryAttempts,\n request: this.request.clone(),\n parseUrl: false,\n credits: defined(this.credits) ? this.credits.slice() : undefined,\n });\n }\n\n result._url = this._url;\n result._queryParameters = clone(this._queryParameters);\n result._templateValues = clone(this._templateValues);\n result.headers = clone(this.headers);\n result.proxy = this.proxy;\n result.retryCallback = this.retryCallback;\n result.retryAttempts = this.retryAttempts;\n result._retryCount = 0;\n result.request = this.request.clone();\n\n return result;\n};\n\n/**\n * Returns the base path of the Resource.\n *\n * @param {boolean} [includeQuery = false] Whether or not to include the query string and fragment form the uri\n *\n * @returns {string} The base URI of the resource\n */\nResource.prototype.getBaseUri = function (includeQuery) {\n return getBaseUri(this.getUrlComponent(includeQuery), includeQuery);\n};\n\n/**\n * Appends a forward slash to the URL.\n */\nResource.prototype.appendForwardSlash = function () {\n this._url = appendForwardSlash(this._url);\n};\n\n/**\n * Asynchronously loads the resource as raw binary data. Returns a promise that will resolve to\n * an ArrayBuffer once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n * @example\n * // load a single URL asynchronously\n * resource.fetchArrayBuffer().then(function(arrayBuffer) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchArrayBuffer = function () {\n return this.fetch({\n responseType: \"arraybuffer\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchArrayBuffer() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchArrayBuffer = function (options) {\n const resource = new Resource(options);\n return resource.fetchArrayBuffer();\n};\n\n/**\n * Asynchronously loads the given resource as a blob. Returns a promise that will resolve to\n * a Blob once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n * @example\n * // load a single URL asynchronously\n * resource.fetchBlob().then(function(blob) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchBlob = function () {\n return this.fetch({\n responseType: \"blob\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchBlob() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchBlob = function (options) {\n const resource = new Resource(options);\n return resource.fetchBlob();\n};\n\n/**\n * Asynchronously loads the given image resource. Returns a promise that will resolve to\n * an {@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap|ImageBitmap} if preferImageBitmap is true and the browser supports createImageBitmap or otherwise an\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement|Image} once loaded, or reject if the image failed to load.\n *\n * @param {object} [options] An object with the following properties.\n * @param {boolean} [options.preferBlob=false] If true, we will load the image via a blob.\n * @param {boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap is returned.\n * @param {boolean} [options.flipY=false] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap.\n * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports createImageBitmap.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load a single image asynchronously\n * resource.fetchImage().then(function(image) {\n * // use the loaded image\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * // load several images in parallel\n * Promise.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {\n * // images is an array containing all the loaded images\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchImage = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const preferImageBitmap = defaultValue(options.preferImageBitmap, false);\n const preferBlob = defaultValue(options.preferBlob, false);\n const flipY = defaultValue(options.flipY, false);\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n checkAndResetRequest(this.request);\n // We try to load the image normally if\n // 1. Blobs aren't supported\n // 2. It's a data URI\n // 3. It's a blob URI\n // 4. It doesn't have request headers and we preferBlob is false\n if (\n !xhrBlobSupported ||\n this.isDataUri ||\n this.isBlobUri ||\n (!this.hasHeaders && !preferBlob)\n ) {\n return fetchImage({\n resource: this,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: preferImageBitmap,\n });\n }\n\n const blobPromise = this.fetchBlob();\n if (!defined(blobPromise)) {\n return;\n }\n\n let supportsImageBitmap;\n let useImageBitmap;\n let generatedBlobResource;\n let generatedBlob;\n return Resource.supportsImageBitmapOptions()\n .then(function (result) {\n supportsImageBitmap = result;\n useImageBitmap = supportsImageBitmap && preferImageBitmap;\n return blobPromise;\n })\n .then(function (blob) {\n if (!defined(blob)) {\n return;\n }\n generatedBlob = blob;\n if (useImageBitmap) {\n return Resource.createImageBitmapFromBlob(blob, {\n flipY: flipY,\n premultiplyAlpha: false,\n skipColorSpaceConversion: skipColorSpaceConversion,\n });\n }\n const blobUrl = window.URL.createObjectURL(blob);\n generatedBlobResource = new Resource({\n url: blobUrl,\n });\n\n return fetchImage({\n resource: generatedBlobResource,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: false,\n });\n })\n .then(function (image) {\n if (!defined(image)) {\n return;\n }\n\n // The blob object may be needed for use by a TileDiscardPolicy,\n // so attach it to the image.\n image.blob = generatedBlob;\n\n if (useImageBitmap) {\n return image;\n }\n\n window.URL.revokeObjectURL(generatedBlobResource.url);\n return image;\n })\n .catch(function (error) {\n if (defined(generatedBlobResource)) {\n window.URL.revokeObjectURL(generatedBlobResource.url);\n }\n\n // If the blob load succeeded but the image decode failed, attach the blob\n // to the error object for use by a TileDiscardPolicy.\n // In particular, BingMapsImageryProvider uses this to detect the\n // zero-length response that is returned when a tile is not available.\n error.blob = generatedBlob;\n\n return Promise.reject(error);\n });\n};\n\n/**\n * Fetches an image and returns a promise to it.\n *\n * @param {object} [options] An object with the following properties.\n * @param {Resource} [options.resource] Resource object that points to an image to fetch.\n * @param {boolean} [options.preferImageBitmap] If true, image will be decoded during fetch and an ImageBitmap is returned.\n * @param {boolean} [options.flipY] If true, image will be vertically flipped during decode. Only applies if the browser supports createImageBitmap.\n * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports createImageBitmap.\n * @private\n */\nfunction fetchImage(options) {\n const resource = options.resource;\n const flipY = options.flipY;\n const skipColorSpaceConversion = options.skipColorSpaceConversion;\n const preferImageBitmap = options.preferImageBitmap;\n\n const request = resource.request;\n request.url = resource.url;\n request.requestFunction = function () {\n let crossOrigin = false;\n\n // data URIs can't have crossorigin set.\n if (!resource.isDataUri && !resource.isBlobUri) {\n crossOrigin = resource.isCrossOriginUrl;\n }\n\n const deferred = defer();\n Resource._Implementations.createImage(\n request,\n crossOrigin,\n deferred,\n flipY,\n skipColorSpaceConversion,\n preferImageBitmap\n );\n\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise.catch(function (e) {\n // Don't retry cancelled or otherwise aborted requests\n if (request.state !== RequestState.FAILED) {\n return Promise.reject(e);\n }\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return fetchImage({\n resource: resource,\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: preferImageBitmap,\n });\n }\n return Promise.reject(e);\n });\n });\n}\n\n/**\n * Creates a Resource and calls fetchImage() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {boolean} [options.flipY=false] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {boolean} [options.preferBlob=false] If true, we will load the image via a blob.\n * @param {boolean} [options.preferImageBitmap=false] If true, image will be decoded during fetch and an ImageBitmap is returned.\n * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the image will be ignored. Only applies when requesting an image and the browser supports createImageBitmap.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchImage = function (options) {\n const resource = new Resource(options);\n return resource.fetchImage({\n flipY: options.flipY,\n skipColorSpaceConversion: options.skipColorSpaceConversion,\n preferBlob: options.preferBlob,\n preferImageBitmap: options.preferImageBitmap,\n });\n};\n\n/**\n * Asynchronously loads the given resource as text. Returns a promise that will resolve to\n * a String once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n * @example\n * // load text from a URL, setting a custom header\n * const resource = new Resource({\n * url: 'http://someUrl.com/someJson.txt',\n * headers: {\n * 'X-Custom-Header' : 'some value'\n * }\n * });\n * resource.fetchText().then(function(text) {\n * // Do something with the text\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchText = function () {\n return this.fetch({\n responseType: \"text\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchText() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchText = function (options) {\n const resource = new Resource(options);\n return resource.fetchText();\n};\n\n// note: */* below is */* but that ends the comment block early\n/**\n * Asynchronously loads the given resource as JSON. Returns a promise that will resolve to\n * a JSON object once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function\n * adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not\n * already specified.\n *\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.fetchJson().then(function(jsonData) {\n * // Do something with the JSON object\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchJson = function () {\n const promise = this.fetch({\n responseType: \"text\",\n headers: {\n Accept: \"application/json,*/*;q=0.01\",\n },\n });\n\n if (!defined(promise)) {\n return undefined;\n }\n\n return promise.then(function (value) {\n if (!defined(value)) {\n return;\n }\n return JSON.parse(value);\n });\n};\n\n/**\n * Creates a Resource and calls fetchJson() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchJson = function (options) {\n const resource = new Resource(options);\n return resource.fetchJson();\n};\n\n/**\n * Asynchronously loads the given resource as XML. Returns a promise that will resolve to\n * an XML Document once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load XML from a URL, setting a custom header\n * Cesium.loadXML('http://someUrl.com/someXML.xml', {\n * 'X-Custom-Header' : 'some value'\n * }).then(function(document) {\n * // Do something with the document\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchXML = function () {\n return this.fetch({\n responseType: \"document\",\n overrideMimeType: \"text/xml\",\n });\n};\n\n/**\n * Creates a Resource and calls fetchXML() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchXML = function (options) {\n const resource = new Resource(options);\n return resource.fetchXML();\n};\n\n/**\n * Requests a resource using JSONP.\n *\n * @param {string} [callbackParameterName='callback'] The callback parameter name that the server expects.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * // load a data asynchronously\n * resource.fetchJsonp().then(function(data) {\n * // use the loaded data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetchJsonp = function (callbackParameterName) {\n callbackParameterName = defaultValue(callbackParameterName, \"callback\");\n\n checkAndResetRequest(this.request);\n\n //generate a unique function name\n let functionName;\n do {\n functionName = `loadJsonp${CesiumMath.nextRandomNumber()\n .toString()\n .substring(2, 8)}`;\n } while (defined(window[functionName]));\n\n return fetchJsonp(this, callbackParameterName, functionName);\n};\n\nfunction fetchJsonp(resource, callbackParameterName, functionName) {\n const callbackQuery = {};\n callbackQuery[callbackParameterName] = functionName;\n resource.setQueryParameters(callbackQuery);\n\n const request = resource.request;\n const url = resource.url;\n request.url = url;\n request.requestFunction = function () {\n const deferred = defer();\n\n //assign a function with that name in the global scope\n window[functionName] = function (data) {\n deferred.resolve(data);\n\n try {\n delete window[functionName];\n } catch (e) {\n window[functionName] = undefined;\n }\n };\n\n Resource._Implementations.loadAndExecuteScript(url, functionName, deferred);\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise.catch(function (e) {\n if (request.state !== RequestState.FAILED) {\n return Promise.reject(e);\n }\n\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return fetchJsonp(resource, callbackParameterName, functionName);\n }\n\n return Promise.reject(e);\n });\n });\n}\n\n/**\n * Creates a Resource from a URL and calls fetchJsonp() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.callbackParameterName='callback'] The callback parameter name that the server expects.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetchJsonp = function (options) {\n const resource = new Resource(options);\n return resource.fetchJsonp(options.callbackParameterName);\n};\n\n/**\n * @private\n */\nResource.prototype._makeRequest = function (options) {\n const resource = this;\n checkAndResetRequest(resource.request);\n\n const request = resource.request;\n const url = resource.url;\n request.url = url;\n\n request.requestFunction = function () {\n const responseType = options.responseType;\n const headers = combine(options.headers, resource.headers);\n const overrideMimeType = options.overrideMimeType;\n const method = options.method;\n const data = options.data;\n const deferred = defer();\n const xhr = Resource._Implementations.loadWithXhr(\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n );\n if (defined(xhr) && defined(xhr.abort)) {\n request.cancelFunction = function () {\n xhr.abort();\n };\n }\n return deferred.promise;\n };\n\n const promise = RequestScheduler.request(request);\n if (!defined(promise)) {\n return;\n }\n\n return promise\n .then(function (data) {\n // explicitly set to undefined to ensure GC of request response data. See #8843\n request.cancelFunction = undefined;\n return data;\n })\n .catch(function (e) {\n request.cancelFunction = undefined;\n if (request.state !== RequestState.FAILED) {\n return Promise.reject(e);\n }\n\n return resource.retryOnError(e).then(function (retry) {\n if (retry) {\n // Reset request so it can try again\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n\n return resource.fetch(options);\n }\n\n return Promise.reject(e);\n });\n });\n};\n\n/**\n * Checks to make sure the Resource isn't already being requested.\n *\n * @param {Request} request The request to check.\n *\n * @private\n */\nfunction checkAndResetRequest(request) {\n if (\n request.state === RequestState.ISSUED ||\n request.state === RequestState.ACTIVE\n ) {\n throw new RuntimeError(\"The Resource is already being fetched.\");\n }\n\n request.state = RequestState.UNISSUED;\n request.deferred = undefined;\n}\n\nconst dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;\n\nfunction decodeDataUriText(isBase64, data) {\n const result = decodeURIComponent(data);\n if (isBase64) {\n return atob(result);\n }\n return result;\n}\n\nfunction decodeDataUriArrayBuffer(isBase64, data) {\n const byteString = decodeDataUriText(isBase64, data);\n const buffer = new ArrayBuffer(byteString.length);\n const view = new Uint8Array(buffer);\n for (let i = 0; i < byteString.length; i++) {\n view[i] = byteString.charCodeAt(i);\n }\n return buffer;\n}\n\nfunction decodeDataUri(dataUriRegexResult, responseType) {\n responseType = defaultValue(responseType, \"\");\n const mimeType = dataUriRegexResult[1];\n const isBase64 = !!dataUriRegexResult[2];\n const data = dataUriRegexResult[3];\n let buffer;\n let parser;\n\n switch (responseType) {\n case \"\":\n case \"text\":\n return decodeDataUriText(isBase64, data);\n case \"arraybuffer\":\n return decodeDataUriArrayBuffer(isBase64, data);\n case \"blob\":\n buffer = decodeDataUriArrayBuffer(isBase64, data);\n return new Blob([buffer], {\n type: mimeType,\n });\n case \"document\":\n parser = new DOMParser();\n return parser.parseFromString(\n decodeDataUriText(isBase64, data),\n mimeType\n );\n case \"json\":\n return JSON.parse(decodeDataUriText(isBase64, data));\n default:\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Unhandled responseType: ${responseType}`);\n //>>includeEnd('debug');\n }\n}\n\n/**\n * Asynchronously loads the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. It's recommended that you use\n * the more specific functions eg. fetchJson, fetchBlob, etc.\n *\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.fetch()\n * .then(function(body) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.fetch = function (options) {\n options = defaultClone(options, {});\n options.method = \"GET\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls fetch() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.fetch = function (options) {\n const resource = new Resource(options);\n return resource.fetch({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously deletes the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.delete()\n * .then(function(body) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.delete = function (options) {\n options = defaultClone(options, {});\n options.method = \"DELETE\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls delete() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.data] Data that is posted with the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.delete = function (options) {\n const resource = new Resource(options);\n return resource.delete({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n data: options.data,\n });\n};\n\n/**\n * Asynchronously gets headers the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.head()\n * .then(function(headers) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.head = function (options) {\n options = defaultClone(options, {});\n options.method = \"HEAD\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls head() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.head = function (options) {\n const resource = new Resource(options);\n return resource.head({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously gets options the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.options()\n * .then(function(headers) {\n * // use the data\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.options = function (options) {\n options = defaultClone(options, {});\n options.method = \"OPTIONS\";\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls options() on it.\n *\n * @param {string|object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.options = function (options) {\n const resource = new Resource(options);\n return resource.options({\n // Make copy of just the needed fields because headers can be passed to both the constructor and to fetch\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously posts data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} data Data that is posted with the resource.\n * @param {object} [options] Object with the following properties:\n * @param {object} [options.data] Data that is posted with the resource.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.post(data)\n * .then(function(result) {\n * // use the result\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.post = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"POST\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls post() on it.\n *\n * @param {object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} options.data Data that is posted with the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.post = function (options) {\n const resource = new Resource(options);\n return resource.post(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously puts data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} data Data that is posted with the resource.\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.put(data)\n * .then(function(result) {\n * // use the result\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.put = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"PUT\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls put() on it.\n *\n * @param {object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} options.data Data that is posted with the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.put = function (options) {\n const resource = new Resource(options);\n return resource.put(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Asynchronously patches data to the given resource. Returns a promise that will resolve to\n * the result once loaded, or reject if the resource failed to load. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.\n *\n * @param {object} data Data that is posted with the resource.\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {object} [options.headers] Additional HTTP headers to send with the request, if any.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n *\n * @example\n * resource.patch(data)\n * .then(function(result) {\n * // use the result\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n */\nResource.prototype.patch = function (data, options) {\n Check.defined(\"data\", data);\n\n options = defaultClone(options, {});\n options.method = \"PATCH\";\n options.data = data;\n\n return this._makeRequest(options);\n};\n\n/**\n * Creates a Resource from a URL and calls patch() on it.\n *\n * @param {object} options A url or an object with the following properties\n * @param {string} options.url The url of the resource.\n * @param {object} options.data Data that is posted with the resource.\n * @param {object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.\n * @param {object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).\n * @param {object} [options.headers={}] Additional HTTP headers that will be sent.\n * @param {Proxy} [options.proxy] A proxy to be used when loading the resource.\n * @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.\n * @param {number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.\n * @param {Request} [options.request] A Request object that will be used. Intended for internal use only.\n * @param {string} [options.responseType] The type of response. This controls the type of item returned.\n * @param {string} [options.overrideMimeType] Overrides the MIME type returned by the server.\n * @returns {Promise|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n */\nResource.patch = function (options) {\n const resource = new Resource(options);\n return resource.patch(options.data, {\n // Make copy of just the needed fields because headers can be passed to both the constructor and to post\n responseType: options.responseType,\n overrideMimeType: options.overrideMimeType,\n });\n};\n\n/**\n * Contains implementations of functions that can be replaced for testing\n *\n * @private\n */\nResource._Implementations = {};\n\nResource._Implementations.loadImageElement = function (\n url,\n crossOrigin,\n deferred\n) {\n const image = new Image();\n\n image.onload = function () {\n // work-around a known issue with Firefox and dimensionless SVG, see:\n // - https://github.com/whatwg/html/issues/3510\n // - https://bugzilla.mozilla.org/show_bug.cgi?id=700533\n if (\n image.naturalWidth === 0 &&\n image.naturalHeight === 0 &&\n image.width === 0 &&\n image.height === 0\n ) {\n // these values affect rasterization and will likely mar the content\n // until Firefox takes a stance on the issue, marred content is better than no content\n // Chromium uses a more refined heuristic about its choice given nil viewBox, and a better stance and solution is\n // proposed later in the original issue thread:\n // - Chromium behavior: https://github.com/CesiumGS/cesium/issues/9188#issuecomment-704400825\n // - Cesium's stance/solve: https://github.com/CesiumGS/cesium/issues/9188#issuecomment-720645777\n image.width = 300;\n image.height = 150;\n }\n deferred.resolve(image);\n };\n\n image.onerror = function (e) {\n deferred.reject(e);\n };\n\n if (crossOrigin) {\n if (TrustedServers.contains(url)) {\n image.crossOrigin = \"use-credentials\";\n } else {\n image.crossOrigin = \"\";\n }\n }\n\n image.src = url;\n};\n\nResource._Implementations.createImage = function (\n request,\n crossOrigin,\n deferred,\n flipY,\n skipColorSpaceConversion,\n preferImageBitmap\n) {\n const url = request.url;\n // Passing an Image to createImageBitmap will force it to run on the main thread\n // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking.\n // See:\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38\n // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10\n Resource.supportsImageBitmapOptions()\n .then(function (supportsImageBitmap) {\n // We can only use ImageBitmap if we can flip on decode.\n // See: https://github.com/CesiumGS/cesium/pull/7579#issuecomment-466146898\n if (!(supportsImageBitmap && preferImageBitmap)) {\n Resource._Implementations.loadImageElement(url, crossOrigin, deferred);\n return;\n }\n const responseType = \"blob\";\n const method = \"GET\";\n const xhrDeferred = defer();\n const xhr = Resource._Implementations.loadWithXhr(\n url,\n responseType,\n method,\n undefined,\n undefined,\n xhrDeferred,\n undefined,\n undefined,\n undefined\n );\n\n if (defined(xhr) && defined(xhr.abort)) {\n request.cancelFunction = function () {\n xhr.abort();\n };\n }\n return xhrDeferred.promise\n .then(function (blob) {\n if (!defined(blob)) {\n deferred.reject(\n new RuntimeError(\n `Successfully retrieved ${url} but it contained no content.`\n )\n );\n return;\n }\n\n return Resource.createImageBitmapFromBlob(blob, {\n flipY: flipY,\n premultiplyAlpha: false,\n skipColorSpaceConversion: skipColorSpaceConversion,\n });\n })\n .then(function (image) {\n deferred.resolve(image);\n });\n })\n .catch(function (e) {\n deferred.reject(e);\n });\n};\n\n/**\n * Wrapper for createImageBitmap\n *\n * @private\n */\nResource.createImageBitmapFromBlob = function (blob, options) {\n Check.defined(\"options\", options);\n Check.typeOf.bool(\"options.flipY\", options.flipY);\n Check.typeOf.bool(\"options.premultiplyAlpha\", options.premultiplyAlpha);\n Check.typeOf.bool(\n \"options.skipColorSpaceConversion\",\n options.skipColorSpaceConversion\n );\n\n return createImageBitmap(blob, {\n imageOrientation: options.flipY ? \"flipY\" : \"none\",\n premultiplyAlpha: options.premultiplyAlpha ? \"premultiply\" : \"none\",\n colorSpaceConversion: options.skipColorSpaceConversion ? \"none\" : \"default\",\n });\n};\n\nfunction decodeResponse(loadWithHttpResponse, responseType) {\n switch (responseType) {\n case \"text\":\n return loadWithHttpResponse.toString(\"utf8\");\n case \"json\":\n return JSON.parse(loadWithHttpResponse.toString(\"utf8\"));\n default:\n return new Uint8Array(loadWithHttpResponse).buffer;\n }\n}\n\nfunction loadWithHttpRequest(\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n) {\n // Note: only the 'json' and 'text' responseTypes transforms the loaded buffer\n let URL;\n let zlib;\n Promise.all([import(\"url\"), import(\"zlib\")])\n .then(([urlImport, zlibImport]) => {\n URL = urlImport.parse(url);\n zlib = zlibImport;\n\n return URL.protocol === \"https:\" ? import(\"https\") : import(\"http\");\n })\n .then((http) => {\n const options = {\n protocol: URL.protocol,\n hostname: URL.hostname,\n port: URL.port,\n path: URL.path,\n query: URL.query,\n method: method,\n headers: headers,\n };\n http\n .request(options)\n .on(\"response\", function (res) {\n if (res.statusCode < 200 || res.statusCode >= 300) {\n deferred.reject(\n new RequestErrorEvent(res.statusCode, res, res.headers)\n );\n return;\n }\n\n const chunkArray = [];\n res.on(\"data\", function (chunk) {\n chunkArray.push(chunk);\n });\n\n res.on(\"end\", function () {\n // eslint-disable-next-line no-undef\n const result = Buffer.concat(chunkArray);\n if (res.headers[\"content-encoding\"] === \"gzip\") {\n zlib.gunzip(result, function (error, resultUnzipped) {\n if (error) {\n deferred.reject(\n new RuntimeError(\"Error decompressing response.\")\n );\n } else {\n deferred.resolve(\n decodeResponse(resultUnzipped, responseType)\n );\n }\n });\n } else {\n deferred.resolve(decodeResponse(result, responseType));\n }\n });\n })\n .on(\"error\", function (e) {\n deferred.reject(new RequestErrorEvent());\n })\n .end();\n });\n}\n\nconst noXMLHttpRequest = typeof XMLHttpRequest === \"undefined\";\nResource._Implementations.loadWithXhr = function (\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n) {\n const dataUriRegexResult = dataUriRegex.exec(url);\n if (dataUriRegexResult !== null) {\n deferred.resolve(decodeDataUri(dataUriRegexResult, responseType));\n return;\n }\n\n if (noXMLHttpRequest) {\n loadWithHttpRequest(\n url,\n responseType,\n method,\n data,\n headers,\n deferred,\n overrideMimeType\n );\n return;\n }\n\n const xhr = new XMLHttpRequest();\n\n if (TrustedServers.contains(url)) {\n xhr.withCredentials = true;\n }\n\n xhr.open(method, url, true);\n\n if (defined(overrideMimeType) && defined(xhr.overrideMimeType)) {\n xhr.overrideMimeType(overrideMimeType);\n }\n\n if (defined(headers)) {\n for (const key in headers) {\n if (headers.hasOwnProperty(key)) {\n xhr.setRequestHeader(key, headers[key]);\n }\n }\n }\n\n if (defined(responseType)) {\n xhr.responseType = responseType;\n }\n\n // While non-standard, file protocol always returns a status of 0 on success\n let localFile = false;\n if (typeof url === \"string\") {\n localFile =\n url.indexOf(\"file://\") === 0 ||\n (typeof window !== \"undefined\" && window.location.origin === \"file://\");\n }\n\n xhr.onload = function () {\n if (\n (xhr.status < 200 || xhr.status >= 300) &&\n !(localFile && xhr.status === 0)\n ) {\n deferred.reject(\n new RequestErrorEvent(\n xhr.status,\n xhr.response,\n xhr.getAllResponseHeaders()\n )\n );\n return;\n }\n\n const response = xhr.response;\n const browserResponseType = xhr.responseType;\n\n if (method === \"HEAD\" || method === \"OPTIONS\") {\n const responseHeaderString = xhr.getAllResponseHeaders();\n const splitHeaders = responseHeaderString.trim().split(/[\\r\\n]+/);\n\n const responseHeaders = {};\n splitHeaders.forEach(function (line) {\n const parts = line.split(\": \");\n const header = parts.shift();\n responseHeaders[header] = parts.join(\": \");\n });\n\n deferred.resolve(responseHeaders);\n return;\n }\n\n //All modern browsers will go into either the first or second if block or last else block.\n //Other code paths support older browsers that either do not support the supplied responseType\n //or do not support the xhr.response property.\n if (xhr.status === 204) {\n // accept no content\n deferred.resolve();\n } else if (\n defined(response) &&\n (!defined(responseType) || browserResponseType === responseType)\n ) {\n deferred.resolve(response);\n } else if (responseType === \"json\" && typeof response === \"string\") {\n try {\n deferred.resolve(JSON.parse(response));\n } catch (e) {\n deferred.reject(e);\n }\n } else if (\n (browserResponseType === \"\" || browserResponseType === \"document\") &&\n defined(xhr.responseXML) &&\n xhr.responseXML.hasChildNodes()\n ) {\n deferred.resolve(xhr.responseXML);\n } else if (\n (browserResponseType === \"\" || browserResponseType === \"text\") &&\n defined(xhr.responseText)\n ) {\n deferred.resolve(xhr.responseText);\n } else {\n deferred.reject(\n new RuntimeError(\"Invalid XMLHttpRequest response type.\")\n );\n }\n };\n\n xhr.onerror = function (e) {\n deferred.reject(new RequestErrorEvent());\n };\n\n xhr.send(data);\n\n return xhr;\n};\n\nResource._Implementations.loadAndExecuteScript = function (\n url,\n functionName,\n deferred\n) {\n return loadAndExecuteScript(url, functionName).catch(function (e) {\n deferred.reject(e);\n });\n};\n\n/**\n * The default implementations\n *\n * @private\n */\nResource._DefaultImplementations = {};\nResource._DefaultImplementations.createImage =\n Resource._Implementations.createImage;\nResource._DefaultImplementations.loadWithXhr =\n Resource._Implementations.loadWithXhr;\nResource._DefaultImplementations.loadAndExecuteScript =\n Resource._Implementations.loadAndExecuteScript;\n\n/**\n * A resource instance initialized to the current browser location\n *\n * @type {Resource}\n * @constant\n */\nResource.DEFAULT = Object.freeze(\n new Resource({\n url:\n typeof document === \"undefined\"\n ? \"\"\n : document.location.href.split(\"?\")[0],\n })\n);\n\n/**\n * A function that returns the value of the property.\n * @callback Resource.RetryCallback\n *\n * @param {Resource} [resource] The resource that failed to load.\n * @param {RequestErrorEvent} [error] The error that occurred during the loading of the resource.\n * @returns {boolean|Promise} If true or a promise that resolved to true, the resource will be retried. Otherwise the failure will be returned.\n */\nexport default Resource;\n", "/**\n * @private\n */\nfunction appendForwardSlash(url) {\n if (url.length === 0 || url[url.length - 1] !== \"/\") {\n url = `${url}/`;\n }\n return url;\n}\nexport default appendForwardSlash;\n", "import defaultValue from \"./defaultValue.js\";\n\n/**\n * Clones an object, returning a new object containing the same properties.\n *\n * @function\n *\n * @param {object} object The object to clone.\n * @param {boolean} [deep=false] If true, all properties will be deep cloned recursively.\n * @returns {object} The cloned object.\n */\nfunction clone(object, deep) {\n if (object === null || typeof object !== \"object\") {\n return object;\n }\n\n deep = defaultValue(deep, false);\n\n const result = new object.constructor();\n for (const propertyName in object) {\n if (object.hasOwnProperty(propertyName)) {\n let value = object[propertyName];\n if (deep) {\n value = clone(value, deep);\n }\n result[propertyName] = value;\n }\n }\n\n return result;\n}\nexport default clone;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Merges two objects, copying their properties onto a new combined object. When two objects have the same\n * property, the value of the property on the first object is used. If either object is undefined,\n * it will be treated as an empty object.\n *\n * @example\n * const object1 = {\n * propOne : 1,\n * propTwo : {\n * value1 : 10\n * }\n * }\n * const object2 = {\n * propTwo : 2\n * }\n * const final = Cesium.combine(object1, object2);\n *\n * // final === {\n * // propOne : 1,\n * // propTwo : {\n * // value1 : 10\n * // }\n * // }\n *\n * @param {object} [object1] The first object to merge.\n * @param {object} [object2] The second object to merge.\n * @param {boolean} [deep=false] Perform a recursive merge.\n * @returns {object} The combined object containing all properties from both objects.\n *\n * @function\n */\nfunction combine(object1, object2, deep) {\n deep = defaultValue(deep, false);\n\n const result = {};\n\n const object1Defined = defined(object1);\n const object2Defined = defined(object2);\n let property;\n let object1Value;\n let object2Value;\n if (object1Defined) {\n for (property in object1) {\n if (object1.hasOwnProperty(property)) {\n object1Value = object1[property];\n if (\n object2Defined &&\n deep &&\n typeof object1Value === \"object\" &&\n object2.hasOwnProperty(property)\n ) {\n object2Value = object2[property];\n if (typeof object2Value === \"object\") {\n result[property] = combine(object1Value, object2Value, deep);\n } else {\n result[property] = object1Value;\n }\n } else {\n result[property] = object1Value;\n }\n }\n }\n }\n if (object2Defined) {\n for (property in object2) {\n if (\n object2.hasOwnProperty(property) &&\n !result.hasOwnProperty(property)\n ) {\n object2Value = object2[property];\n result[property] = object2Value;\n }\n }\n }\n return result;\n}\nexport default combine;\n", "/**\n * A function used to resolve a promise upon completion .\n * @callback defer.resolve\n *\n * @param {*} value The resulting value.\n */\n\n/**\n * A function used to reject a promise upon failure.\n * @callback defer.reject\n *\n * @param {*} error The error.\n */\n\n/**\n * An object which contains a promise object, and functions to resolve or reject the promise.\n *\n * @typedef {object} defer.deferred\n * @property {defer.resolve} resolve Resolves the promise when called.\n * @property {defer.reject} reject Rejects the promise when called.\n * @property {Promise} promise Promise object.\n */\n\n/**\n * Creates a deferred object, containing a promise object, and functions to resolve or reject the promise.\n * @returns {defer.deferred}\n * @private\n */\nfunction defer() {\n let resolve;\n let reject;\n const promise = new Promise(function (res, rej) {\n resolve = res;\n reject = rej;\n });\n\n return {\n resolve: resolve,\n reject: reject,\n promise: promise,\n };\n}\n\nexport default defer;\n", "import Uri from \"urijs\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Given a relative Uri and a base Uri, returns the absolute Uri of the relative Uri.\n * @function\n *\n * @param {string} relative The relative Uri.\n * @param {string} [base] The base Uri.\n * @returns {string} The absolute Uri of the given relative Uri.\n *\n * @example\n * //absolute Uri will be \"https://test.com/awesome.png\";\n * const absoluteUri = Cesium.getAbsoluteUri('awesome.png', 'https://test.com');\n */\nfunction getAbsoluteUri(relative, base) {\n let documentObject;\n if (typeof document !== \"undefined\") {\n documentObject = document;\n }\n\n return getAbsoluteUri._implementation(relative, base, documentObject);\n}\n\ngetAbsoluteUri._implementation = function (relative, base, documentObject) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(relative)) {\n throw new DeveloperError(\"relative uri is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(base)) {\n if (typeof documentObject === \"undefined\") {\n return relative;\n }\n base = defaultValue(documentObject.baseURI, documentObject.location.href);\n }\n\n const relativeUri = new Uri(relative);\n if (relativeUri.scheme() !== \"\") {\n return relativeUri.toString();\n }\n return relativeUri.absoluteTo(base).toString();\n};\nexport default getAbsoluteUri;\n", "import Uri from \"urijs\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Given a URI, returns the base path of the URI.\n * @function\n *\n * @param {string} uri The Uri.\n * @param {boolean} [includeQuery = false] Whether or not to include the query string and fragment form the uri\n * @returns {string} The base path of the Uri.\n *\n * @example\n * // basePath will be \"/Gallery/\";\n * const basePath = Cesium.getBaseUri('/Gallery/simple.czml?value=true&example=false');\n *\n * // basePath will be \"/Gallery/?value=true&example=false\";\n * const basePath = Cesium.getBaseUri('/Gallery/simple.czml?value=true&example=false', true);\n */\nfunction getBaseUri(uri, includeQuery) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(uri)) {\n throw new DeveloperError(\"uri is required.\");\n }\n //>>includeEnd('debug');\n\n let basePath = \"\";\n const i = uri.lastIndexOf(\"/\");\n if (i !== -1) {\n basePath = uri.substring(0, i + 1);\n }\n\n if (!includeQuery) {\n return basePath;\n }\n\n uri = new Uri(uri);\n if (uri.query().length !== 0) {\n basePath += `?${uri.query()}`;\n }\n if (uri.fragment().length !== 0) {\n basePath += `#${uri.fragment()}`;\n }\n\n return basePath;\n}\nexport default getBaseUri;\n", "import Uri from \"urijs\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Given a URI, returns the extension of the URI.\n * @function getExtensionFromUri\n *\n * @param {string} uri The Uri.\n * @returns {string} The extension of the Uri.\n *\n * @example\n * //extension will be \"czml\";\n * const extension = Cesium.getExtensionFromUri('/Gallery/simple.czml?value=true&example=false');\n */\nfunction getExtensionFromUri(uri) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(uri)) {\n throw new DeveloperError(\"uri is required.\");\n }\n //>>includeEnd('debug');\n\n const uriObject = new Uri(uri);\n uriObject.normalize();\n let path = uriObject.path();\n let index = path.lastIndexOf(\"/\");\n if (index !== -1) {\n path = path.substr(index + 1);\n }\n index = path.lastIndexOf(\".\");\n if (index === -1) {\n path = \"\";\n } else {\n path = path.substr(index + 1);\n }\n return path;\n}\nexport default getExtensionFromUri;\n", "import defined from \"./defined.js\";\n\nconst context2DsByWidthAndHeight = {};\n\n/**\n * Extract a pixel array from a loaded image. Draws the image\n * into a canvas so it can read the pixels back.\n *\n * @function getImagePixels\n *\n * @param {HTMLImageElement|ImageBitmap} image The image to extract pixels from.\n * @param {number} width The width of the image. If not defined, then image.width is assigned.\n * @param {number} height The height of the image. If not defined, then image.height is assigned.\n * @returns {ImageData} The pixels of the image.\n */\nfunction getImagePixels(image, width, height) {\n if (!defined(width)) {\n width = image.width;\n }\n if (!defined(height)) {\n height = image.height;\n }\n\n let context2DsByHeight = context2DsByWidthAndHeight[width];\n if (!defined(context2DsByHeight)) {\n context2DsByHeight = {};\n context2DsByWidthAndHeight[width] = context2DsByHeight;\n }\n\n let context2d = context2DsByHeight[height];\n if (!defined(context2d)) {\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n // Since we re-use contexts, use the willReadFrequently option \u2013 See https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently\n context2d = canvas.getContext(\"2d\", { willReadFrequently: true });\n context2d.globalCompositeOperation = \"copy\";\n context2DsByHeight[height] = context2d;\n }\n\n context2d.drawImage(image, 0, 0, width, height);\n return context2d.getImageData(0, 0, width, height).data;\n}\nexport default getImagePixels;\n", "import Check from \"./Check.js\";\n\nconst blobUriRegex = /^blob:/i;\n\n/**\n * Determines if the specified uri is a blob uri.\n *\n * @function isBlobUri\n *\n * @param {string} uri The uri to test.\n * @returns {boolean} true when the uri is a blob uri; otherwise, false.\n *\n * @private\n */\nfunction isBlobUri(uri) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"uri\", uri);\n //>>includeEnd('debug');\n\n return blobUriRegex.test(uri);\n}\nexport default isBlobUri;\n", "import defined from \"./defined.js\";\n\nlet a;\n\n/**\n * Given a URL, determine whether that URL is considered cross-origin to the current page.\n *\n * @private\n */\nfunction isCrossOriginUrl(url) {\n if (!defined(a)) {\n a = document.createElement(\"a\");\n }\n\n // copy window location into the anchor to get consistent results\n // when the port is default for the protocol (e.g. 80 for HTTP)\n a.href = window.location.href;\n\n // host includes both hostname and port if the port is not standard\n const host = a.host;\n const protocol = a.protocol;\n\n a.href = url;\n // IE only absolutizes href on get, not set\n // eslint-disable-next-line no-self-assign\n a.href = a.href;\n\n return protocol !== a.protocol || host !== a.host;\n}\nexport default isCrossOriginUrl;\n", "import Check from \"./Check.js\";\n\nconst dataUriRegex = /^data:/i;\n\n/**\n * Determines if the specified uri is a data uri.\n *\n * @function isDataUri\n *\n * @param {string} uri The uri to test.\n * @returns {boolean} true when the uri is a data uri; otherwise, false.\n *\n * @private\n */\nfunction isDataUri(uri) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"uri\", uri);\n //>>includeEnd('debug');\n\n return dataUriRegex.test(uri);\n}\nexport default isDataUri;\n", "/**\n * @private\n */\nfunction loadAndExecuteScript(url) {\n const script = document.createElement(\"script\");\n script.async = true;\n script.src = url;\n\n return new Promise((resolve, reject) => {\n if (window.crossOriginIsolated) {\n script.setAttribute(\"crossorigin\", \"anonymous\");\n }\n\n const head = document.getElementsByTagName(\"head\")[0];\n script.onload = function () {\n script.onload = undefined;\n head.removeChild(script);\n resolve();\n };\n script.onerror = function (e) {\n reject(e);\n };\n\n head.appendChild(script);\n });\n}\nexport default loadAndExecuteScript;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Converts an object representing a set of name/value pairs into a query string,\n * with names and values encoded properly for use in a URL. Values that are arrays\n * will produce multiple values with the same name.\n * @function objectToQuery\n *\n * @param {object} obj The object containing data to encode.\n * @returns {string} An encoded query string.\n *\n *\n * @example\n * const str = Cesium.objectToQuery({\n * key1 : 'some value',\n * key2 : 'a/b',\n * key3 : ['x', 'y']\n * });\n *\n * @see queryToObject\n * // str will be:\n * // 'key1=some%20value&key2=a%2Fb&key3=x&key3=y'\n */\nfunction objectToQuery(obj) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(obj)) {\n throw new DeveloperError(\"obj is required.\");\n }\n //>>includeEnd('debug');\n\n let result = \"\";\n for (const propName in obj) {\n if (obj.hasOwnProperty(propName)) {\n const value = obj[propName];\n\n const part = `${encodeURIComponent(propName)}=`;\n if (Array.isArray(value)) {\n for (let i = 0, len = value.length; i < len; ++i) {\n result += `${part + encodeURIComponent(value[i])}&`;\n }\n } else {\n result += `${part + encodeURIComponent(value)}&`;\n }\n }\n }\n\n // trim last &\n result = result.slice(0, -1);\n\n // This function used to replace %20 with + which is more compact and readable.\n // However, some servers didn't properly handle + as a space.\n // https://github.com/CesiumGS/cesium/issues/2192\n\n return result;\n}\nexport default objectToQuery;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Parses a query string into an object, where the keys and values of the object are the\n * name/value pairs from the query string, decoded. If a name appears multiple times,\n * the value in the object will be an array of values.\n * @function queryToObject\n *\n * @param {string} queryString The query string.\n * @returns {object} An object containing the parameters parsed from the query string.\n *\n *\n * @example\n * const obj = Cesium.queryToObject('key1=some%20value&key2=a%2Fb&key3=x&key3=y');\n * // obj will be:\n * // {\n * // key1 : 'some value',\n * // key2 : 'a/b',\n * // key3 : ['x', 'y']\n * // }\n *\n * @see objectToQuery\n */\nfunction queryToObject(queryString) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(queryString)) {\n throw new DeveloperError(\"queryString is required.\");\n }\n //>>includeEnd('debug');\n\n const result = {};\n if (queryString === \"\") {\n return result;\n }\n const parts = queryString.replace(/\\+/g, \"%20\").split(/[&;]/);\n for (let i = 0, len = parts.length; i < len; ++i) {\n const subparts = parts[i].split(\"=\");\n\n const name = decodeURIComponent(subparts[0]);\n let value = subparts[1];\n if (defined(value)) {\n value = decodeURIComponent(value);\n } else {\n value = \"\";\n }\n\n const resultValue = result[name];\n if (typeof resultValue === \"string\") {\n // expand the single value to an array\n result[name] = [resultValue, value];\n } else if (Array.isArray(resultValue)) {\n resultValue.push(value);\n } else {\n result[name] = value;\n }\n }\n return result;\n}\nexport default queryToObject;\n", "/**\n * State of the request.\n *\n * @enum {number}\n */\nconst RequestState = {\n /**\n * Initial unissued state.\n *\n * @type {number}\n * @constant\n */\n UNISSUED: 0,\n\n /**\n * Issued but not yet active. Will become active when open slots are available.\n *\n * @type {number}\n * @constant\n */\n ISSUED: 1,\n\n /**\n * Actual http request has been sent.\n *\n * @type {number}\n * @constant\n */\n ACTIVE: 2,\n\n /**\n * Request completed successfully.\n *\n * @type {number}\n * @constant\n */\n RECEIVED: 3,\n\n /**\n * Request was cancelled, either explicitly or automatically because of low priority.\n *\n * @type {number}\n * @constant\n */\n CANCELLED: 4,\n\n /**\n * Request failed.\n *\n * @type {number}\n * @constant\n */\n FAILED: 5,\n};\nexport default Object.freeze(RequestState);\n", "/**\n * An enum identifying the type of request. Used for finer grained logging and priority sorting.\n *\n * @enum {number}\n */\nconst RequestType = {\n /**\n * Terrain request.\n *\n * @type {number}\n * @constant\n */\n TERRAIN: 0,\n\n /**\n * Imagery request.\n *\n * @type {number}\n * @constant\n */\n IMAGERY: 1,\n\n /**\n * 3D Tiles request.\n *\n * @type {number}\n * @constant\n */\n TILES3D: 2,\n\n /**\n * Other request.\n *\n * @type {number}\n * @constant\n */\n OTHER: 3,\n};\nexport default Object.freeze(RequestType);\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport RequestState from \"./RequestState.js\";\nimport RequestType from \"./RequestType.js\";\n\n/**\n * Stores information for making a request. In general this does not need to be constructed directly.\n *\n * @alias Request\n * @constructor\n\n * @param {object} [options] An object with the following properties:\n * @param {string} [options.url] The url to request.\n * @param {Request.RequestCallback} [options.requestFunction] The function that makes the actual data request.\n * @param {Request.CancelCallback} [options.cancelFunction] The function that is called when the request is cancelled.\n * @param {Request.PriorityCallback} [options.priorityFunction] The function that is called to update the request's priority, which occurs once per frame.\n * @param {number} [options.priority=0.0] The initial priority of the request.\n * @param {boolean} [options.throttle=false] Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the request will be throttled and sent based on priority.\n * @param {boolean} [options.throttleByServer=false] Whether to throttle the request by server.\n * @param {RequestType} [options.type=RequestType.OTHER] The type of request.\n * @param {string} [options.serverKey] A key used to identify the server that a request is going to.\n */\nfunction Request(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const throttleByServer = defaultValue(options.throttleByServer, false);\n const throttle = defaultValue(options.throttle, false);\n\n /**\n * The URL to request.\n *\n * @type {string}\n */\n this.url = options.url;\n\n /**\n * The function that makes the actual data request.\n *\n * @type {Request.RequestCallback}\n */\n this.requestFunction = options.requestFunction;\n\n /**\n * The function that is called when the request is cancelled.\n *\n * @type {Request.CancelCallback}\n */\n this.cancelFunction = options.cancelFunction;\n\n /**\n * The function that is called to update the request's priority, which occurs once per frame.\n *\n * @type {Request.PriorityCallback}\n */\n this.priorityFunction = options.priorityFunction;\n\n /**\n * Priority is a unit-less value where lower values represent higher priority.\n * For world-based objects, this is usually the distance from the camera.\n * A request that does not have a priority function defaults to a priority of 0.\n *\n * If priorityFunction is defined, this value is updated every frame with the result of that call.\n *\n * @type {number}\n * @default 0.0\n */\n this.priority = defaultValue(options.priority, 0.0);\n\n /**\n * Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the\n * request will be throttled and sent based on priority.\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n this.throttle = throttle;\n\n /**\n * Whether to throttle the request by server. Browsers typically support about 6-8 parallel connections\n * for HTTP/1 servers, and an unlimited amount of connections for HTTP/2 servers. Setting this value\n * to true is preferable for requests going through HTTP/1 servers.\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n this.throttleByServer = throttleByServer;\n\n /**\n * Type of request.\n *\n * @type {RequestType}\n * @readonly\n *\n * @default RequestType.OTHER\n */\n this.type = defaultValue(options.type, RequestType.OTHER);\n\n /**\n * A key used to identify the server that a request is going to. It is derived from the url's authority and scheme.\n *\n * @type {string}\n *\n * @private\n */\n this.serverKey = options.serverKey;\n\n /**\n * The current state of the request.\n *\n * @type {RequestState}\n * @readonly\n */\n this.state = RequestState.UNISSUED;\n\n /**\n * The requests's deferred promise.\n *\n * @type {object}\n *\n * @private\n */\n this.deferred = undefined;\n\n /**\n * Whether the request was explicitly cancelled.\n *\n * @type {boolean}\n *\n * @private\n */\n this.cancelled = false;\n}\n\n/**\n * Mark the request as cancelled.\n *\n * @private\n */\nRequest.prototype.cancel = function () {\n this.cancelled = true;\n};\n\n/**\n * Duplicates a Request instance.\n *\n * @param {Request} [result] The object onto which to store the result.\n *\n * @returns {Request} The modified result parameter or a new Resource instance if one was not provided.\n */\nRequest.prototype.clone = function (result) {\n if (!defined(result)) {\n return new Request(this);\n }\n\n result.url = this.url;\n result.requestFunction = this.requestFunction;\n result.cancelFunction = this.cancelFunction;\n result.priorityFunction = this.priorityFunction;\n result.priority = this.priority;\n result.throttle = this.throttle;\n result.throttleByServer = this.throttleByServer;\n result.type = this.type;\n result.serverKey = this.serverKey;\n\n // These get defaulted because the cloned request hasn't been issued\n result.state = RequestState.UNISSUED;\n result.deferred = undefined;\n result.cancelled = false;\n\n return result;\n};\n\n/**\n * The function that makes the actual data request.\n * @callback Request.RequestCallback\n * @returns {Promise} A promise for the requested data.\n */\n\n/**\n * The function that is called when the request is cancelled.\n * @callback Request.CancelCallback\n */\n\n/**\n * The function that is called to update the request's priority, which occurs once per frame.\n * @callback Request.PriorityCallback\n * @returns {number} The updated priority value.\n */\nexport default Request;\n", "/**\n * Parses the result of XMLHttpRequest's getAllResponseHeaders() method into\n * a dictionary.\n *\n * @function parseResponseHeaders\n *\n * @param {string} headerString The header string returned by getAllResponseHeaders(). The format is\n * described here: http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method\n * @returns {object} A dictionary of key/value pairs, where each key is the name of a header and the corresponding value\n * is that header's value.\n *\n * @private\n */\nfunction parseResponseHeaders(headerString) {\n const headers = {};\n\n if (!headerString) {\n return headers;\n }\n\n const headerPairs = headerString.split(\"\\u000d\\u000a\");\n\n for (let i = 0; i < headerPairs.length; ++i) {\n const headerPair = headerPairs[i];\n // Can't use split() here because it does the wrong thing\n // if the header value has the string \": \" in it.\n const index = headerPair.indexOf(\"\\u003a\\u0020\");\n if (index > 0) {\n const key = headerPair.substring(0, index);\n const val = headerPair.substring(index + 2);\n headers[key] = val;\n }\n }\n\n return headers;\n}\nexport default parseResponseHeaders;\n", "import defined from \"./defined.js\";\nimport parseResponseHeaders from \"./parseResponseHeaders.js\";\n\n/**\n * An event that is raised when a request encounters an error.\n *\n * @constructor\n * @alias RequestErrorEvent\n *\n * @param {number} [statusCode] The HTTP error status code, such as 404.\n * @param {object} [response] The response included along with the error.\n * @param {string|object} [responseHeaders] The response headers, represented either as an object literal or as a\n * string in the format returned by XMLHttpRequest's getAllResponseHeaders() function.\n */\nfunction RequestErrorEvent(statusCode, response, responseHeaders) {\n /**\n * The HTTP error status code, such as 404. If the error does not have a particular\n * HTTP code, this property will be undefined.\n *\n * @type {number}\n */\n this.statusCode = statusCode;\n\n /**\n * The response included along with the error. If the error does not include a response,\n * this property will be undefined.\n *\n * @type {object}\n */\n this.response = response;\n\n /**\n * The headers included in the response, represented as an object literal of key/value pairs.\n * If the error does not include any headers, this property will be undefined.\n *\n * @type {object}\n */\n this.responseHeaders = responseHeaders;\n\n if (typeof this.responseHeaders === \"string\") {\n this.responseHeaders = parseResponseHeaders(this.responseHeaders);\n }\n}\n\n/**\n * Creates a string representing this RequestErrorEvent.\n * @memberof RequestErrorEvent\n *\n * @returns {string} A string representing the provided RequestErrorEvent.\n */\nRequestErrorEvent.prototype.toString = function () {\n let str = \"Request has failed.\";\n if (defined(this.statusCode)) {\n str += ` Status Code: ${this.statusCode}`;\n }\n return str;\n};\nexport default RequestErrorEvent;\n", "import Uri from \"urijs\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defer from \"./defer.js\";\nimport defined from \"./defined.js\";\nimport Event from \"./Event.js\";\nimport Heap from \"./Heap.js\";\nimport isBlobUri from \"./isBlobUri.js\";\nimport isDataUri from \"./isDataUri.js\";\nimport RequestState from \"./RequestState.js\";\n\nfunction sortRequests(a, b) {\n return a.priority - b.priority;\n}\n\nconst statistics = {\n numberOfAttemptedRequests: 0,\n numberOfActiveRequests: 0,\n numberOfCancelledRequests: 0,\n numberOfCancelledActiveRequests: 0,\n numberOfFailedRequests: 0,\n numberOfActiveRequestsEver: 0,\n lastNumberOfActiveRequests: 0,\n};\n\nlet priorityHeapLength = 20;\nconst requestHeap = new Heap({\n comparator: sortRequests,\n});\nrequestHeap.maximumLength = priorityHeapLength;\nrequestHeap.reserve(priorityHeapLength);\n\nconst activeRequests = [];\nlet numberOfActiveRequestsByServer = {};\n\nconst pageUri =\n typeof document !== \"undefined\" ? new Uri(document.location.href) : new Uri();\n\nconst requestCompletedEvent = new Event();\n\n/**\n * The request scheduler is used to track and constrain the number of active requests in order to prioritize incoming requests. The ability\n * to retain control over the number of requests in CesiumJS is important because due to events such as changes in the camera position,\n * a lot of new requests may be generated and a lot of in-flight requests may become redundant. The request scheduler manually constrains the\n * number of requests so that newer requests wait in a shorter queue and don't have to compete for bandwidth with requests that have expired.\n *\n * @namespace RequestScheduler\n *\n */\nfunction RequestScheduler() {}\n\n/**\n * The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.\n * @type {number}\n * @default 50\n */\nRequestScheduler.maximumRequests = 50;\n\n/**\n * The maximum number of simultaneous active requests per server. Un-throttled requests or servers specifically\n * listed in {@link requestsByServer} do not observe this limit.\n * @type {number}\n * @default 6\n */\nRequestScheduler.maximumRequestsPerServer = 6;\n\n/**\n * A per server key list of overrides to use for throttling instead of maximumRequestsPerServer.\n * Useful when streaming data from a known HTTP/2 or HTTP/3 server.\n * @type {object}\n *\n * @example\n * RequestScheduler.requestsByServer[\"myserver.com:443\"] = 18;\n *\n * @example\n * RequestScheduler.requestsByServer = {\n * \"api.cesium.com:443\": 18,\n * \"assets.cesium.com:443\": 18,\n * };\n */\nRequestScheduler.requestsByServer = {\n \"api.cesium.com:443\": 18,\n \"assets.ion.cesium.com:443\": 18,\n \"ibasemaps-api.arcgis.com:443\": 18,\n \"tile.googleapis.com:443\": 18,\n \"tile.openstreetmap.org:443\": 18,\n};\n\n/**\n * Specifies if the request scheduler should throttle incoming requests, or let the browser queue requests under its control.\n * @type {boolean}\n * @default true\n */\nRequestScheduler.throttleRequests = true;\n\n/**\n * When true, log statistics to the console every frame\n * @type {boolean}\n * @default false\n * @private\n */\nRequestScheduler.debugShowStatistics = false;\n\n/**\n * An event that's raised when a request is completed. Event handlers are passed\n * the error object if the request fails.\n *\n * @type {Event}\n * @default Event()\n * @private\n */\nRequestScheduler.requestCompletedEvent = requestCompletedEvent;\n\nObject.defineProperties(RequestScheduler, {\n /**\n * Returns the statistics used by the request scheduler.\n *\n * @memberof RequestScheduler\n *\n * @type {object}\n * @readonly\n * @private\n */\n statistics: {\n get: function () {\n return statistics;\n },\n },\n\n /**\n * The maximum size of the priority heap. This limits the number of requests that are sorted by priority. Only applies to requests that are not yet active.\n *\n * @memberof RequestScheduler\n *\n * @type {number}\n * @default 20\n * @private\n */\n priorityHeapLength: {\n get: function () {\n return priorityHeapLength;\n },\n set: function (value) {\n // If the new length shrinks the heap, need to cancel some of the requests.\n // Since this value is not intended to be tweaked regularly it is fine to just cancel the high priority requests.\n if (value < priorityHeapLength) {\n while (requestHeap.length > value) {\n const request = requestHeap.pop();\n cancelRequest(request);\n }\n }\n priorityHeapLength = value;\n requestHeap.maximumLength = value;\n requestHeap.reserve(value);\n },\n },\n});\n\nfunction updatePriority(request) {\n if (defined(request.priorityFunction)) {\n request.priority = request.priorityFunction();\n }\n}\n\n/**\n * Check if there are open slots for a particular server key. If desiredRequests is greater than 1, this checks if the queue has room for scheduling multiple requests.\n * @param {string} serverKey The server key returned by {@link RequestScheduler.getServerKey}.\n * @param {number} [desiredRequests=1] How many requests the caller plans to request\n * @return {boolean} True if there are enough open slots for desiredRequests more requests.\n * @private\n */\nRequestScheduler.serverHasOpenSlots = function (serverKey, desiredRequests) {\n desiredRequests = defaultValue(desiredRequests, 1);\n\n const maxRequests = defaultValue(\n RequestScheduler.requestsByServer[serverKey],\n RequestScheduler.maximumRequestsPerServer\n );\n const hasOpenSlotsServer =\n numberOfActiveRequestsByServer[serverKey] + desiredRequests <= maxRequests;\n\n return hasOpenSlotsServer;\n};\n\n/**\n * Check if the priority heap has open slots, regardless of which server they\n * are from. This is used in {@link Multiple3DTileContent} for determining when\n * all requests can be scheduled\n * @param {number} desiredRequests The number of requests the caller intends to make\n * @return {boolean} true if the heap has enough available slots to meet the desiredRequests. false otherwise.\n *\n * @private\n */\nRequestScheduler.heapHasOpenSlots = function (desiredRequests) {\n const hasOpenSlotsHeap =\n requestHeap.length + desiredRequests <= priorityHeapLength;\n return hasOpenSlotsHeap;\n};\n\nfunction issueRequest(request) {\n if (request.state === RequestState.UNISSUED) {\n request.state = RequestState.ISSUED;\n request.deferred = defer();\n }\n return request.deferred.promise;\n}\n\nfunction getRequestReceivedFunction(request) {\n return function (results) {\n if (request.state === RequestState.CANCELLED) {\n // If the data request comes back but the request is cancelled, ignore it.\n return;\n }\n // explicitly set to undefined to ensure GC of request response data. See #8843\n const deferred = request.deferred;\n\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n requestCompletedEvent.raiseEvent();\n request.state = RequestState.RECEIVED;\n request.deferred = undefined;\n\n deferred.resolve(results);\n };\n}\n\nfunction getRequestFailedFunction(request) {\n return function (error) {\n if (request.state === RequestState.CANCELLED) {\n // If the data request comes back but the request is cancelled, ignore it.\n return;\n }\n ++statistics.numberOfFailedRequests;\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n requestCompletedEvent.raiseEvent(error);\n request.state = RequestState.FAILED;\n request.deferred.reject(error);\n };\n}\n\nfunction startRequest(request) {\n const promise = issueRequest(request);\n request.state = RequestState.ACTIVE;\n activeRequests.push(request);\n ++statistics.numberOfActiveRequests;\n ++statistics.numberOfActiveRequestsEver;\n ++numberOfActiveRequestsByServer[request.serverKey];\n request\n .requestFunction()\n .then(getRequestReceivedFunction(request))\n .catch(getRequestFailedFunction(request));\n return promise;\n}\n\nfunction cancelRequest(request) {\n const active = request.state === RequestState.ACTIVE;\n request.state = RequestState.CANCELLED;\n ++statistics.numberOfCancelledRequests;\n // check that deferred has not been cleared since cancelRequest can be called\n // on a finished request, e.g. by clearForSpecs during tests\n if (defined(request.deferred)) {\n const deferred = request.deferred;\n request.deferred = undefined;\n deferred.reject();\n }\n\n if (active) {\n --statistics.numberOfActiveRequests;\n --numberOfActiveRequestsByServer[request.serverKey];\n ++statistics.numberOfCancelledActiveRequests;\n }\n\n if (defined(request.cancelFunction)) {\n request.cancelFunction();\n }\n}\n\n/**\n * Sort requests by priority and start requests.\n * @private\n */\nRequestScheduler.update = function () {\n let i;\n let request;\n\n // Loop over all active requests. Cancelled, failed, or received requests are removed from the array to make room for new requests.\n let removeCount = 0;\n const activeLength = activeRequests.length;\n for (i = 0; i < activeLength; ++i) {\n request = activeRequests[i];\n if (request.cancelled) {\n // Request was explicitly cancelled\n cancelRequest(request);\n }\n if (request.state !== RequestState.ACTIVE) {\n // Request is no longer active, remove from array\n ++removeCount;\n continue;\n }\n if (removeCount > 0) {\n // Shift back to fill in vacated slots from completed requests\n activeRequests[i - removeCount] = request;\n }\n }\n activeRequests.length -= removeCount;\n\n // Update priority of issued requests and resort the heap\n const issuedRequests = requestHeap.internalArray;\n const issuedLength = requestHeap.length;\n for (i = 0; i < issuedLength; ++i) {\n updatePriority(issuedRequests[i]);\n }\n requestHeap.resort();\n\n // Get the number of open slots and fill with the highest priority requests.\n // Un-throttled requests are automatically added to activeRequests, so activeRequests.length may exceed maximumRequests\n const openSlots = Math.max(\n RequestScheduler.maximumRequests - activeRequests.length,\n 0\n );\n let filledSlots = 0;\n while (filledSlots < openSlots && requestHeap.length > 0) {\n // Loop until all open slots are filled or the heap becomes empty\n request = requestHeap.pop();\n if (request.cancelled) {\n // Request was explicitly cancelled\n cancelRequest(request);\n continue;\n }\n\n if (\n request.throttleByServer &&\n !RequestScheduler.serverHasOpenSlots(request.serverKey)\n ) {\n // Open slots are available, but the request is throttled by its server. Cancel and try again later.\n cancelRequest(request);\n continue;\n }\n\n startRequest(request);\n ++filledSlots;\n }\n\n updateStatistics();\n};\n\n/**\n * Get the server key from a given url.\n *\n * @param {string} url The url.\n * @returns {string} The server key.\n * @private\n */\nRequestScheduler.getServerKey = function (url) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"url\", url);\n //>>includeEnd('debug');\n\n let uri = new Uri(url);\n if (uri.scheme() === \"\") {\n uri = uri.absoluteTo(pageUri);\n uri.normalize();\n }\n\n let serverKey = uri.authority();\n if (!/:/.test(serverKey)) {\n // If the authority does not contain a port number, add port 443 for https or port 80 for http\n serverKey = `${serverKey}:${uri.scheme() === \"https\" ? \"443\" : \"80\"}`;\n }\n\n const length = numberOfActiveRequestsByServer[serverKey];\n if (!defined(length)) {\n numberOfActiveRequestsByServer[serverKey] = 0;\n }\n\n return serverKey;\n};\n\n/**\n * Issue a request. If request.throttle is false, the request is sent immediately. Otherwise the request will be\n * queued and sorted by priority before being sent.\n *\n * @param {Request} request The request object.\n *\n * @returns {Promise|undefined} A Promise for the requested data, or undefined if this request does not have high enough priority to be issued.\n *\n * @private\n */\nRequestScheduler.request = function (request) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"request\", request);\n Check.typeOf.string(\"request.url\", request.url);\n Check.typeOf.func(\"request.requestFunction\", request.requestFunction);\n //>>includeEnd('debug');\n\n if (isDataUri(request.url) || isBlobUri(request.url)) {\n requestCompletedEvent.raiseEvent();\n request.state = RequestState.RECEIVED;\n return request.requestFunction();\n }\n\n ++statistics.numberOfAttemptedRequests;\n\n if (!defined(request.serverKey)) {\n request.serverKey = RequestScheduler.getServerKey(request.url);\n }\n\n if (\n RequestScheduler.throttleRequests &&\n request.throttleByServer &&\n !RequestScheduler.serverHasOpenSlots(request.serverKey)\n ) {\n // Server is saturated. Try again later.\n return undefined;\n }\n\n if (!RequestScheduler.throttleRequests || !request.throttle) {\n return startRequest(request);\n }\n\n if (activeRequests.length >= RequestScheduler.maximumRequests) {\n // Active requests are saturated. Try again later.\n return undefined;\n }\n\n // Insert into the priority heap and see if a request was bumped off. If this request is the lowest\n // priority it will be returned.\n updatePriority(request);\n const removedRequest = requestHeap.insert(request);\n\n if (defined(removedRequest)) {\n if (removedRequest === request) {\n // Request does not have high enough priority to be issued\n return undefined;\n }\n // A previously issued request has been bumped off the priority heap, so cancel it\n cancelRequest(removedRequest);\n }\n\n return issueRequest(request);\n};\n\nfunction updateStatistics() {\n if (!RequestScheduler.debugShowStatistics) {\n return;\n }\n\n if (\n statistics.numberOfActiveRequests === 0 &&\n statistics.lastNumberOfActiveRequests > 0\n ) {\n if (statistics.numberOfAttemptedRequests > 0) {\n console.log(\n `Number of attempted requests: ${statistics.numberOfAttemptedRequests}`\n );\n statistics.numberOfAttemptedRequests = 0;\n }\n\n if (statistics.numberOfCancelledRequests > 0) {\n console.log(\n `Number of cancelled requests: ${statistics.numberOfCancelledRequests}`\n );\n statistics.numberOfCancelledRequests = 0;\n }\n\n if (statistics.numberOfCancelledActiveRequests > 0) {\n console.log(\n `Number of cancelled active requests: ${statistics.numberOfCancelledActiveRequests}`\n );\n statistics.numberOfCancelledActiveRequests = 0;\n }\n\n if (statistics.numberOfFailedRequests > 0) {\n console.log(\n `Number of failed requests: ${statistics.numberOfFailedRequests}`\n );\n statistics.numberOfFailedRequests = 0;\n }\n }\n\n statistics.lastNumberOfActiveRequests = statistics.numberOfActiveRequests;\n}\n\n/**\n * For testing only. Clears any requests that may not have completed from previous tests.\n *\n * @private\n */\nRequestScheduler.clearForSpecs = function () {\n while (requestHeap.length > 0) {\n const request = requestHeap.pop();\n cancelRequest(request);\n }\n const length = activeRequests.length;\n for (let i = 0; i < length; ++i) {\n cancelRequest(activeRequests[i]);\n }\n activeRequests.length = 0;\n numberOfActiveRequestsByServer = {};\n\n // Clear stats\n statistics.numberOfAttemptedRequests = 0;\n statistics.numberOfActiveRequests = 0;\n statistics.numberOfCancelledRequests = 0;\n statistics.numberOfCancelledActiveRequests = 0;\n statistics.numberOfFailedRequests = 0;\n statistics.numberOfActiveRequestsEver = 0;\n statistics.lastNumberOfActiveRequests = 0;\n};\n\n/**\n * For testing only.\n *\n * @private\n */\nRequestScheduler.numberOfActiveRequestsByServer = function (serverKey) {\n return numberOfActiveRequestsByServer[serverKey];\n};\n\n/**\n * For testing only.\n *\n * @private\n */\nRequestScheduler.requestHeap = requestHeap;\nexport default RequestScheduler;\n", "import Check from \"./Check.js\";\nimport defined from \"./defined.js\";\n\n/**\n * A generic utility class for managing subscribers for a particular event.\n * This class is usually instantiated inside of a container class and\n * exposed as a property for others to subscribe to.\n *\n * @alias Event\n * @template Listener extends (...args: any[]) => void = (...args: any[]) => void\n * @constructor\n * @example\n * MyObject.prototype.myListener = function(arg1, arg2) {\n * this.myArg1Copy = arg1;\n * this.myArg2Copy = arg2;\n * }\n *\n * const myObjectInstance = new MyObject();\n * const evt = new Cesium.Event();\n * evt.addEventListener(MyObject.prototype.myListener, myObjectInstance);\n * evt.raiseEvent('1', '2');\n * evt.removeEventListener(MyObject.prototype.myListener);\n */\nfunction Event() {\n this._listeners = [];\n this._scopes = [];\n this._toRemove = [];\n this._insideRaiseEvent = false;\n}\n\nObject.defineProperties(Event.prototype, {\n /**\n * The number of listeners currently subscribed to the event.\n * @memberof Event.prototype\n * @type {number}\n * @readonly\n */\n numberOfListeners: {\n get: function () {\n return this._listeners.length - this._toRemove.length;\n },\n },\n});\n\n/**\n * Registers a callback function to be executed whenever the event is raised.\n * An optional scope can be provided to serve as the this pointer\n * in which the function will execute.\n *\n * @param {Listener} listener The function to be executed when the event is raised.\n * @param {object} [scope] An optional object scope to serve as the this\n * pointer in which the listener function will execute.\n * @returns {Event.RemoveCallback} A function that will remove this event listener when invoked.\n *\n * @see Event#raiseEvent\n * @see Event#removeEventListener\n */\nEvent.prototype.addEventListener = function (listener, scope) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"listener\", listener);\n //>>includeEnd('debug');\n\n this._listeners.push(listener);\n this._scopes.push(scope);\n\n const event = this;\n return function () {\n event.removeEventListener(listener, scope);\n };\n};\n\n/**\n * Unregisters a previously registered callback.\n *\n * @param {Listener} listener The function to be unregistered.\n * @param {object} [scope] The scope that was originally passed to addEventListener.\n * @returns {boolean} true if the listener was removed; false if the listener and scope are not registered with the event.\n *\n * @see Event#addEventListener\n * @see Event#raiseEvent\n */\nEvent.prototype.removeEventListener = function (listener, scope) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"listener\", listener);\n //>>includeEnd('debug');\n\n const listeners = this._listeners;\n const scopes = this._scopes;\n\n let index = -1;\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i] === listener && scopes[i] === scope) {\n index = i;\n break;\n }\n }\n\n if (index !== -1) {\n if (this._insideRaiseEvent) {\n //In order to allow removing an event subscription from within\n //a callback, we don't actually remove the items here. Instead\n //remember the index they are at and undefined their value.\n this._toRemove.push(index);\n listeners[index] = undefined;\n scopes[index] = undefined;\n } else {\n listeners.splice(index, 1);\n scopes.splice(index, 1);\n }\n return true;\n }\n\n return false;\n};\n\nfunction compareNumber(a, b) {\n return b - a;\n}\n\n/**\n * Raises the event by calling each registered listener with all supplied arguments.\n *\n * @param {...Parameters} arguments This method takes any number of parameters and passes them through to the listener functions.\n *\n * @see Event#addEventListener\n * @see Event#removeEventListener\n */\nEvent.prototype.raiseEvent = function () {\n this._insideRaiseEvent = true;\n\n let i;\n const listeners = this._listeners;\n const scopes = this._scopes;\n let length = listeners.length;\n\n for (i = 0; i < length; i++) {\n const listener = listeners[i];\n if (defined(listener)) {\n listeners[i].apply(scopes[i], arguments);\n }\n }\n\n //Actually remove items removed in removeEventListener.\n const toRemove = this._toRemove;\n length = toRemove.length;\n if (length > 0) {\n toRemove.sort(compareNumber);\n for (i = 0; i < length; i++) {\n const index = toRemove[i];\n listeners.splice(index, 1);\n scopes.splice(index, 1);\n }\n toRemove.length = 0;\n }\n\n this._insideRaiseEvent = false;\n};\n\n/**\n * A function that removes a listener.\n * @callback Event.RemoveCallback\n */\n\nexport default Event;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Array implementation of a heap.\n *\n * @alias Heap\n * @constructor\n * @private\n *\n * @param {object} options Object with the following properties:\n * @param {Heap.ComparatorCallback} options.comparator The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n */\nfunction Heap(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.defined(\"options.comparator\", options.comparator);\n //>>includeEnd('debug');\n\n this._comparator = options.comparator;\n this._array = [];\n this._length = 0;\n this._maximumLength = undefined;\n}\n\nObject.defineProperties(Heap.prototype, {\n /**\n * Gets the length of the heap.\n *\n * @memberof Heap.prototype\n *\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._length;\n },\n },\n\n /**\n * Gets the internal array.\n *\n * @memberof Heap.prototype\n *\n * @type {Array}\n * @readonly\n */\n internalArray: {\n get: function () {\n return this._array;\n },\n },\n\n /**\n * Gets and sets the maximum length of the heap.\n *\n * @memberof Heap.prototype\n *\n * @type {number}\n */\n maximumLength: {\n get: function () {\n return this._maximumLength;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"maximumLength\", value, 0);\n //>>includeEnd('debug');\n const originalLength = this._length;\n if (value < originalLength) {\n const array = this._array;\n // Remove trailing references\n for (let i = value; i < originalLength; ++i) {\n array[i] = undefined;\n }\n this._length = value;\n array.length = value;\n }\n this._maximumLength = value;\n },\n },\n\n /**\n * The comparator to use for the heap. If comparator(a, b) is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n *\n * @memberof Heap.prototype\n *\n * @type {Heap.ComparatorCallback}\n */\n comparator: {\n get: function () {\n return this._comparator;\n },\n },\n});\n\nfunction swap(array, a, b) {\n const temp = array[a];\n array[a] = array[b];\n array[b] = temp;\n}\n\n/**\n * Resizes the internal array of the heap.\n *\n * @param {number} [length] The length to resize internal array to. Defaults to the current length of the heap.\n */\nHeap.prototype.reserve = function (length) {\n length = defaultValue(length, this._length);\n this._array.length = length;\n};\n\n/**\n * Update the heap so that index and all descendants satisfy the heap property.\n *\n * @param {number} [index=0] The starting index to heapify from.\n */\nHeap.prototype.heapify = function (index) {\n index = defaultValue(index, 0);\n const length = this._length;\n const comparator = this._comparator;\n const array = this._array;\n let candidate = -1;\n let inserting = true;\n\n while (inserting) {\n const right = 2 * (index + 1);\n const left = right - 1;\n\n if (left < length && comparator(array[left], array[index]) < 0) {\n candidate = left;\n } else {\n candidate = index;\n }\n\n if (right < length && comparator(array[right], array[candidate]) < 0) {\n candidate = right;\n }\n if (candidate !== index) {\n swap(array, candidate, index);\n index = candidate;\n } else {\n inserting = false;\n }\n }\n};\n\n/**\n * Resort the heap.\n */\nHeap.prototype.resort = function () {\n const length = this._length;\n for (let i = Math.ceil(length / 2); i >= 0; --i) {\n this.heapify(i);\n }\n};\n\n/**\n * Insert an element into the heap. If the length would grow greater than maximumLength\n * of the heap, extra elements are removed.\n *\n * @param {*} element The element to insert\n *\n * @return {*} The element that was removed from the heap if the heap is at full capacity.\n */\nHeap.prototype.insert = function (element) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"element\", element);\n //>>includeEnd('debug');\n\n const array = this._array;\n const comparator = this._comparator;\n const maximumLength = this._maximumLength;\n\n let index = this._length++;\n if (index < array.length) {\n array[index] = element;\n } else {\n array.push(element);\n }\n\n while (index !== 0) {\n const parent = Math.floor((index - 1) / 2);\n if (comparator(array[index], array[parent]) < 0) {\n swap(array, index, parent);\n index = parent;\n } else {\n break;\n }\n }\n\n let removedElement;\n\n if (defined(maximumLength) && this._length > maximumLength) {\n removedElement = array[maximumLength];\n this._length = maximumLength;\n }\n\n return removedElement;\n};\n\n/**\n * Remove the element specified by index from the heap and return it.\n *\n * @param {number} [index=0] The index to remove.\n * @returns {*} The specified element of the heap.\n */\nHeap.prototype.pop = function (index) {\n index = defaultValue(index, 0);\n if (this._length === 0) {\n return undefined;\n }\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThan(\"index\", index, this._length);\n //>>includeEnd('debug');\n\n const array = this._array;\n const root = array[index];\n swap(array, index, --this._length);\n this.heapify(index);\n array[this._length] = undefined; // Remove trailing reference\n return root;\n};\n\n/**\n * The comparator to use for the heap.\n * @callback Heap.ComparatorCallback\n * @param {*} a An element in the heap.\n * @param {*} b An element in the heap.\n * @returns {number} If the result of the comparison is less than 0, sort a to a lower index than b, otherwise sort to a higher index.\n */\nexport default Heap;\n", "import Uri from \"urijs\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A singleton that contains all of the servers that are trusted. Credentials will be sent with\n * any requests to these servers.\n *\n * @namespace TrustedServers\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n */\nconst TrustedServers = {};\nlet _servers = {};\n\n/**\n * Adds a trusted server to the registry\n *\n * @param {string} host The host to be added.\n * @param {number} port The port used to access the host.\n *\n * @example\n * // Add a trusted server\n * TrustedServers.add('my.server.com', 80);\n */\nTrustedServers.add = function (host, port) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(host)) {\n throw new DeveloperError(\"host is required.\");\n }\n if (!defined(port) || port <= 0) {\n throw new DeveloperError(\"port is required to be greater than 0.\");\n }\n //>>includeEnd('debug');\n\n const authority = `${host.toLowerCase()}:${port}`;\n if (!defined(_servers[authority])) {\n _servers[authority] = true;\n }\n};\n\n/**\n * Removes a trusted server from the registry\n *\n * @param {string} host The host to be removed.\n * @param {number} port The port used to access the host.\n *\n * @example\n * // Remove a trusted server\n * TrustedServers.remove('my.server.com', 80);\n */\nTrustedServers.remove = function (host, port) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(host)) {\n throw new DeveloperError(\"host is required.\");\n }\n if (!defined(port) || port <= 0) {\n throw new DeveloperError(\"port is required to be greater than 0.\");\n }\n //>>includeEnd('debug');\n\n const authority = `${host.toLowerCase()}:${port}`;\n if (defined(_servers[authority])) {\n delete _servers[authority];\n }\n};\n\nfunction getAuthority(url) {\n const uri = new Uri(url);\n uri.normalize();\n\n // Removes username:password@ so we just have host[:port]\n let authority = uri.authority();\n if (authority.length === 0) {\n return undefined; // Relative URL\n }\n uri.authority(authority);\n\n if (authority.indexOf(\"@\") !== -1) {\n const parts = authority.split(\"@\");\n authority = parts[1];\n }\n\n // If the port is missing add one based on the scheme\n if (authority.indexOf(\":\") === -1) {\n let scheme = uri.scheme();\n if (scheme.length === 0) {\n scheme = window.location.protocol;\n scheme = scheme.substring(0, scheme.length - 1);\n }\n if (scheme === \"http\") {\n authority += \":80\";\n } else if (scheme === \"https\") {\n authority += \":443\";\n } else {\n return undefined;\n }\n }\n\n return authority;\n}\n\n/**\n * Tests whether a server is trusted or not. The server must have been added with the port if it is included in the url.\n *\n * @param {string} url The url to be tested against the trusted list\n *\n * @returns {boolean} Returns true if url is trusted, false otherwise.\n *\n * @example\n * // Add server\n * TrustedServers.add('my.server.com', 81);\n *\n * // Check if server is trusted\n * if (TrustedServers.contains('https://my.server.com:81/path/to/file.png')) {\n * // my.server.com:81 is trusted\n * }\n * if (TrustedServers.contains('https://my.server.com/path/to/file.png')) {\n * // my.server.com isn't trusted\n * }\n */\nTrustedServers.contains = function (url) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(url)) {\n throw new DeveloperError(\"url is required.\");\n }\n //>>includeEnd('debug');\n const authority = getAuthority(url);\n if (defined(authority) && defined(_servers[authority])) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Clears the registry\n *\n * @example\n * // Remove a trusted server\n * TrustedServers.clear();\n */\nTrustedServers.clear = function () {\n _servers = {};\n};\nexport default TrustedServers;\n", "import binarySearch from \"./binarySearch.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport EarthOrientationParametersSample from \"./EarthOrientationParametersSample.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport LeapSecond from \"./LeapSecond.js\";\nimport Resource from \"./Resource.js\";\nimport RuntimeError from \"./RuntimeError.js\";\nimport TimeConstants from \"./TimeConstants.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\n/**\n * Specifies Earth polar motion coordinates and the difference between UT1 and UTC.\n * These Earth Orientation Parameters (EOP) are primarily used in the transformation from\n * the International Celestial Reference Frame (ICRF) to the International Terrestrial\n * Reference Frame (ITRF).\n * This object is normally not instantiated directly, use {@link EarthOrientationParameters.fromUrl}.\n *\n * @alias EarthOrientationParameters\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {object} [options.data] The actual EOP data. If neither this\n * parameter nor options.data is specified, all EOP values are assumed\n * to be 0.0.\n * @param {boolean} [options.addNewLeapSeconds=true] True if leap seconds that\n * are specified in the EOP data but not in {@link JulianDate.leapSeconds}\n * should be added to {@link JulianDate.leapSeconds}. False if\n * new leap seconds should be handled correctly in the context\n * of the EOP data but otherwise ignored.\n *\n * @private\n */\nfunction EarthOrientationParameters(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._dates = undefined;\n this._samples = undefined;\n\n this._dateColumn = -1;\n this._xPoleWanderRadiansColumn = -1;\n this._yPoleWanderRadiansColumn = -1;\n this._ut1MinusUtcSecondsColumn = -1;\n this._xCelestialPoleOffsetRadiansColumn = -1;\n this._yCelestialPoleOffsetRadiansColumn = -1;\n this._taiMinusUtcSecondsColumn = -1;\n\n this._columnCount = 0;\n this._lastIndex = -1;\n\n this._addNewLeapSeconds = defaultValue(options.addNewLeapSeconds, true);\n\n if (defined(options.data)) {\n // Use supplied EOP data.\n onDataReady(this, options.data);\n } else {\n // Use all zeros for EOP data.\n onDataReady(this, {\n columnNames: [\n \"dateIso8601\",\n \"modifiedJulianDateUtc\",\n \"xPoleWanderRadians\",\n \"yPoleWanderRadians\",\n \"ut1MinusUtcSeconds\",\n \"lengthOfDayCorrectionSeconds\",\n \"xCelestialPoleOffsetRadians\",\n \"yCelestialPoleOffsetRadians\",\n \"taiMinusUtcSeconds\",\n ],\n samples: [],\n });\n }\n}\n\n/**\n *\n * @param {Resource|string} [url] The URL from which to obtain EOP data. If neither this\n * parameter nor options.data is specified, all EOP values are assumed\n * to be 0.0. If options.data is specified, this parameter is\n * ignored.\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.addNewLeapSeconds=true] True if leap seconds that\n * are specified in the EOP data but not in {@link JulianDate.leapSeconds}\n * should be added to {@link JulianDate.leapSeconds}. False if\n * new leap seconds should be handled correctly in the context\n * of the EOP data but otherwise ignored.\n *\n * @example\n * // An example EOP data file, EOP.json:\n * {\n * \"columnNames\" : [\"dateIso8601\",\"modifiedJulianDateUtc\",\"xPoleWanderRadians\",\"yPoleWanderRadians\",\"ut1MinusUtcSeconds\",\"lengthOfDayCorrectionSeconds\",\"xCelestialPoleOffsetRadians\",\"yCelestialPoleOffsetRadians\",\"taiMinusUtcSeconds\"],\n * \"samples\" : [\n * \"2011-07-01T00:00:00Z\",55743.0,2.117957047295119e-7,2.111518721609984e-6,-0.2908948,-2.956e-4,3.393695767766752e-11,3.3452143996557983e-10,34.0,\n * \"2011-07-02T00:00:00Z\",55744.0,2.193297093339541e-7,2.115460256837405e-6,-0.29065,-1.824e-4,-8.241832578862112e-11,5.623838700870617e-10,34.0,\n * \"2011-07-03T00:00:00Z\",55745.0,2.262286080161428e-7,2.1191157519929706e-6,-0.2905572,1.9e-6,-3.490658503988659e-10,6.981317007977318e-10,34.0\n * ]\n * }\n *\n * @example\n * // Loading the EOP data\n * const eop = await Cesium.EarthOrientationParameters.fromUrl('Data/EOP.json');\n * Cesium.Transforms.earthOrientationParameters = eop;\n */\nEarthOrientationParameters.fromUrl = async function (url, options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"url\", url);\n //>>includeEnd('debug');\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const resource = Resource.createIfNeeded(url);\n\n // Download EOP data.\n let eopData;\n try {\n eopData = await resource.fetchJson();\n } catch (e) {\n throw new RuntimeError(\n `An error occurred while retrieving the EOP data from the URL ${resource.url}.`\n );\n }\n\n return new EarthOrientationParameters({\n addNewLeapSeconds: options.addNewLeapSeconds,\n data: eopData,\n });\n};\n\n/**\n * A default {@link EarthOrientationParameters} instance that returns zero for all EOP values.\n */\nEarthOrientationParameters.NONE = Object.freeze({\n compute: function (date, result) {\n if (!defined(result)) {\n result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);\n } else {\n result.xPoleWander = 0.0;\n result.yPoleWander = 0.0;\n result.xPoleOffset = 0.0;\n result.yPoleOffset = 0.0;\n result.ut1MinusUtc = 0.0;\n }\n return result;\n },\n});\n\n/**\n * Computes the Earth Orientation Parameters (EOP) for a given date by interpolating.\n * If the EOP data has not yet been download, this method returns undefined.\n *\n * @param {JulianDate} date The date for each to evaluate the EOP.\n * @param {EarthOrientationParametersSample} [result] The instance to which to copy the result.\n * If this parameter is undefined, a new instance is created and returned.\n * @returns {EarthOrientationParametersSample} The EOP evaluated at the given date, or\n * undefined if the data necessary to evaluate EOP at the date has not yet been\n * downloaded.\n *\n * @exception {RuntimeError} The loaded EOP data has an error and cannot be used.\n *\n * @see EarthOrientationParameters#fromUrl\n */\nEarthOrientationParameters.prototype.compute = function (date, result) {\n // We cannot compute until the samples are available.\n if (!defined(this._samples)) {\n return undefined;\n }\n\n if (!defined(result)) {\n result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);\n }\n\n if (this._samples.length === 0) {\n result.xPoleWander = 0.0;\n result.yPoleWander = 0.0;\n result.xPoleOffset = 0.0;\n result.yPoleOffset = 0.0;\n result.ut1MinusUtc = 0.0;\n return result;\n }\n\n const dates = this._dates;\n const lastIndex = this._lastIndex;\n\n let before = 0;\n let after = 0;\n if (defined(lastIndex)) {\n const previousIndexDate = dates[lastIndex];\n const nextIndexDate = dates[lastIndex + 1];\n const isAfterPrevious = JulianDate.lessThanOrEquals(\n previousIndexDate,\n date\n );\n const isAfterLastSample = !defined(nextIndexDate);\n const isBeforeNext =\n isAfterLastSample || JulianDate.greaterThanOrEquals(nextIndexDate, date);\n\n if (isAfterPrevious && isBeforeNext) {\n before = lastIndex;\n\n if (!isAfterLastSample && nextIndexDate.equals(date)) {\n ++before;\n }\n after = before + 1;\n\n interpolate(this, dates, this._samples, date, before, after, result);\n return result;\n }\n }\n\n let index = binarySearch(dates, date, JulianDate.compare, this._dateColumn);\n if (index >= 0) {\n // If the next entry is the same date, use the later entry. This way, if two entries\n // describe the same moment, one before a leap second and the other after, then we will use\n // the post-leap second data.\n if (index < dates.length - 1 && dates[index + 1].equals(date)) {\n ++index;\n }\n before = index;\n after = index;\n } else {\n after = ~index;\n before = after - 1;\n\n // Use the first entry if the date requested is before the beginning of the data.\n if (before < 0) {\n before = 0;\n }\n }\n\n this._lastIndex = before;\n\n interpolate(this, dates, this._samples, date, before, after, result);\n return result;\n};\n\nfunction compareLeapSecondDates(leapSecond, dateToFind) {\n return JulianDate.compare(leapSecond.julianDate, dateToFind);\n}\n\nfunction onDataReady(eop, eopData) {\n if (!defined(eopData.columnNames)) {\n throw new RuntimeError(\n \"Error in loaded EOP data: The columnNames property is required.\"\n );\n }\n\n if (!defined(eopData.samples)) {\n throw new RuntimeError(\n \"Error in loaded EOP data: The samples property is required.\"\n );\n }\n\n const dateColumn = eopData.columnNames.indexOf(\"modifiedJulianDateUtc\");\n const xPoleWanderRadiansColumn = eopData.columnNames.indexOf(\n \"xPoleWanderRadians\"\n );\n const yPoleWanderRadiansColumn = eopData.columnNames.indexOf(\n \"yPoleWanderRadians\"\n );\n const ut1MinusUtcSecondsColumn = eopData.columnNames.indexOf(\n \"ut1MinusUtcSeconds\"\n );\n const xCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf(\n \"xCelestialPoleOffsetRadians\"\n );\n const yCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf(\n \"yCelestialPoleOffsetRadians\"\n );\n const taiMinusUtcSecondsColumn = eopData.columnNames.indexOf(\n \"taiMinusUtcSeconds\"\n );\n\n if (\n dateColumn < 0 ||\n xPoleWanderRadiansColumn < 0 ||\n yPoleWanderRadiansColumn < 0 ||\n ut1MinusUtcSecondsColumn < 0 ||\n xCelestialPoleOffsetRadiansColumn < 0 ||\n yCelestialPoleOffsetRadiansColumn < 0 ||\n taiMinusUtcSecondsColumn < 0\n ) {\n throw new RuntimeError(\n \"Error in loaded EOP data: The columnNames property must include modifiedJulianDateUtc, xPoleWanderRadians, yPoleWanderRadians, ut1MinusUtcSeconds, xCelestialPoleOffsetRadians, yCelestialPoleOffsetRadians, and taiMinusUtcSeconds columns\"\n );\n }\n\n const samples = (eop._samples = eopData.samples);\n const dates = (eop._dates = []);\n\n eop._dateColumn = dateColumn;\n eop._xPoleWanderRadiansColumn = xPoleWanderRadiansColumn;\n eop._yPoleWanderRadiansColumn = yPoleWanderRadiansColumn;\n eop._ut1MinusUtcSecondsColumn = ut1MinusUtcSecondsColumn;\n eop._xCelestialPoleOffsetRadiansColumn = xCelestialPoleOffsetRadiansColumn;\n eop._yCelestialPoleOffsetRadiansColumn = yCelestialPoleOffsetRadiansColumn;\n eop._taiMinusUtcSecondsColumn = taiMinusUtcSecondsColumn;\n\n eop._columnCount = eopData.columnNames.length;\n eop._lastIndex = undefined;\n\n let lastTaiMinusUtc;\n\n const addNewLeapSeconds = eop._addNewLeapSeconds;\n\n // Convert the ISO8601 dates to JulianDates.\n for (let i = 0, len = samples.length; i < len; i += eop._columnCount) {\n const mjd = samples[i + dateColumn];\n const taiMinusUtc = samples[i + taiMinusUtcSecondsColumn];\n const day = mjd + TimeConstants.MODIFIED_JULIAN_DATE_DIFFERENCE;\n const date = new JulianDate(day, taiMinusUtc, TimeStandard.TAI);\n dates.push(date);\n\n if (addNewLeapSeconds) {\n if (taiMinusUtc !== lastTaiMinusUtc && defined(lastTaiMinusUtc)) {\n // We crossed a leap second boundary, so add the leap second\n // if it does not already exist.\n const leapSeconds = JulianDate.leapSeconds;\n const leapSecondIndex = binarySearch(\n leapSeconds,\n date,\n compareLeapSecondDates\n );\n if (leapSecondIndex < 0) {\n const leapSecond = new LeapSecond(date, taiMinusUtc);\n leapSeconds.splice(~leapSecondIndex, 0, leapSecond);\n }\n }\n lastTaiMinusUtc = taiMinusUtc;\n }\n }\n}\n\nfunction fillResultFromIndex(eop, samples, index, columnCount, result) {\n const start = index * columnCount;\n result.xPoleWander = samples[start + eop._xPoleWanderRadiansColumn];\n result.yPoleWander = samples[start + eop._yPoleWanderRadiansColumn];\n result.xPoleOffset = samples[start + eop._xCelestialPoleOffsetRadiansColumn];\n result.yPoleOffset = samples[start + eop._yCelestialPoleOffsetRadiansColumn];\n result.ut1MinusUtc = samples[start + eop._ut1MinusUtcSecondsColumn];\n}\n\nfunction linearInterp(dx, y1, y2) {\n return y1 + dx * (y2 - y1);\n}\n\nfunction interpolate(eop, dates, samples, date, before, after, result) {\n const columnCount = eop._columnCount;\n\n // First check the bounds on the EOP data\n // If we are after the bounds of the data, return zeros.\n // The 'before' index should never be less than zero.\n if (after > dates.length - 1) {\n result.xPoleWander = 0;\n result.yPoleWander = 0;\n result.xPoleOffset = 0;\n result.yPoleOffset = 0;\n result.ut1MinusUtc = 0;\n return result;\n }\n\n const beforeDate = dates[before];\n const afterDate = dates[after];\n if (beforeDate.equals(afterDate) || date.equals(beforeDate)) {\n fillResultFromIndex(eop, samples, before, columnCount, result);\n return result;\n } else if (date.equals(afterDate)) {\n fillResultFromIndex(eop, samples, after, columnCount, result);\n return result;\n }\n\n const factor =\n JulianDate.secondsDifference(date, beforeDate) /\n JulianDate.secondsDifference(afterDate, beforeDate);\n\n const startBefore = before * columnCount;\n const startAfter = after * columnCount;\n\n // Handle UT1 leap second edge case\n let beforeUt1MinusUtc = samples[startBefore + eop._ut1MinusUtcSecondsColumn];\n let afterUt1MinusUtc = samples[startAfter + eop._ut1MinusUtcSecondsColumn];\n\n const offsetDifference = afterUt1MinusUtc - beforeUt1MinusUtc;\n if (offsetDifference > 0.5 || offsetDifference < -0.5) {\n // The absolute difference between the values is more than 0.5, so we may have\n // crossed a leap second. Check if this is the case and, if so, adjust the\n // afterValue to account for the leap second. This way, our interpolation will\n // produce reasonable results.\n const beforeTaiMinusUtc =\n samples[startBefore + eop._taiMinusUtcSecondsColumn];\n const afterTaiMinusUtc =\n samples[startAfter + eop._taiMinusUtcSecondsColumn];\n if (beforeTaiMinusUtc !== afterTaiMinusUtc) {\n if (afterDate.equals(date)) {\n // If we are at the end of the leap second interval, take the second value\n // Otherwise, the interpolation below will yield the wrong side of the\n // discontinuity\n // At the end of the leap second, we need to start accounting for the jump\n beforeUt1MinusUtc = afterUt1MinusUtc;\n } else {\n // Otherwise, remove the leap second so that the interpolation is correct\n afterUt1MinusUtc -= afterTaiMinusUtc - beforeTaiMinusUtc;\n }\n }\n }\n\n result.xPoleWander = linearInterp(\n factor,\n samples[startBefore + eop._xPoleWanderRadiansColumn],\n samples[startAfter + eop._xPoleWanderRadiansColumn]\n );\n result.yPoleWander = linearInterp(\n factor,\n samples[startBefore + eop._yPoleWanderRadiansColumn],\n samples[startAfter + eop._yPoleWanderRadiansColumn]\n );\n result.xPoleOffset = linearInterp(\n factor,\n samples[startBefore + eop._xCelestialPoleOffsetRadiansColumn],\n samples[startAfter + eop._xCelestialPoleOffsetRadiansColumn]\n );\n result.yPoleOffset = linearInterp(\n factor,\n samples[startBefore + eop._yCelestialPoleOffsetRadiansColumn],\n samples[startAfter + eop._yCelestialPoleOffsetRadiansColumn]\n );\n result.ut1MinusUtc = linearInterp(\n factor,\n beforeUt1MinusUtc,\n afterUt1MinusUtc\n );\n return result;\n}\n\nexport default EarthOrientationParameters;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * A rotation expressed as a heading, pitch, and roll. Heading is the rotation about the\n * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about\n * the positive x axis.\n * @alias HeadingPitchRoll\n * @constructor\n *\n * @param {number} [heading=0.0] The heading component in radians.\n * @param {number} [pitch=0.0] The pitch component in radians.\n * @param {number} [roll=0.0] The roll component in radians.\n */\nfunction HeadingPitchRoll(heading, pitch, roll) {\n /**\n * Gets or sets the heading.\n * @type {number}\n * @default 0.0\n */\n this.heading = defaultValue(heading, 0.0);\n /**\n * Gets or sets the pitch.\n * @type {number}\n * @default 0.0\n */\n this.pitch = defaultValue(pitch, 0.0);\n /**\n * Gets or sets the roll.\n * @type {number}\n * @default 0.0\n */\n this.roll = defaultValue(roll, 0.0);\n}\n\n/**\n * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )\n *\n * @param {Quaternion} quaternion The quaternion from which to retrieve heading, pitch, and roll, all expressed in radians.\n * @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.\n */\nHeadingPitchRoll.fromQuaternion = function (quaternion, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(quaternion)) {\n throw new DeveloperError(\"quaternion is required\");\n }\n //>>includeEnd('debug');\n if (!defined(result)) {\n result = new HeadingPitchRoll();\n }\n const test = 2 * (quaternion.w * quaternion.y - quaternion.z * quaternion.x);\n const denominatorRoll =\n 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);\n const numeratorRoll =\n 2 * (quaternion.w * quaternion.x + quaternion.y * quaternion.z);\n const denominatorHeading =\n 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);\n const numeratorHeading =\n 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);\n result.heading = -Math.atan2(numeratorHeading, denominatorHeading);\n result.roll = Math.atan2(numeratorRoll, denominatorRoll);\n result.pitch = -CesiumMath.asinClamped(test);\n return result;\n};\n\n/**\n * Returns a new HeadingPitchRoll instance from angles given in degrees.\n *\n * @param {number} heading the heading in degrees\n * @param {number} pitch the pitch in degrees\n * @param {number} roll the heading in degrees\n * @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.\n * @returns {HeadingPitchRoll} A new HeadingPitchRoll instance\n */\nHeadingPitchRoll.fromDegrees = function (heading, pitch, roll, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(heading)) {\n throw new DeveloperError(\"heading is required\");\n }\n if (!defined(pitch)) {\n throw new DeveloperError(\"pitch is required\");\n }\n if (!defined(roll)) {\n throw new DeveloperError(\"roll is required\");\n }\n //>>includeEnd('debug');\n if (!defined(result)) {\n result = new HeadingPitchRoll();\n }\n result.heading = heading * CesiumMath.RADIANS_PER_DEGREE;\n result.pitch = pitch * CesiumMath.RADIANS_PER_DEGREE;\n result.roll = roll * CesiumMath.RADIANS_PER_DEGREE;\n return result;\n};\n\n/**\n * Duplicates a HeadingPitchRoll instance.\n *\n * @param {HeadingPitchRoll} headingPitchRoll The HeadingPitchRoll to duplicate.\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. (Returns undefined if headingPitchRoll is undefined)\n */\nHeadingPitchRoll.clone = function (headingPitchRoll, result) {\n if (!defined(headingPitchRoll)) {\n return undefined;\n }\n if (!defined(result)) {\n return new HeadingPitchRoll(\n headingPitchRoll.heading,\n headingPitchRoll.pitch,\n headingPitchRoll.roll\n );\n }\n result.heading = headingPitchRoll.heading;\n result.pitch = headingPitchRoll.pitch;\n result.roll = headingPitchRoll.roll;\n return result;\n};\n\n/**\n * Compares the provided HeadingPitchRolls componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nHeadingPitchRoll.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.heading === right.heading &&\n left.pitch === right.pitch &&\n left.roll === right.roll)\n );\n};\n\n/**\n * Compares the provided HeadingPitchRolls componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.\n * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if left and right are within the provided epsilon, false otherwise.\n */\nHeadingPitchRoll.equalsEpsilon = function (\n left,\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n CesiumMath.equalsEpsilon(\n left.heading,\n right.heading,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.pitch,\n right.pitch,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n left.roll,\n right.roll,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\n\n/**\n * Duplicates this HeadingPitchRoll instance.\n *\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.\n */\nHeadingPitchRoll.prototype.clone = function (result) {\n return HeadingPitchRoll.clone(this, result);\n};\n\n/**\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nHeadingPitchRoll.prototype.equals = function (right) {\n return HeadingPitchRoll.equals(this, right);\n};\n\n/**\n * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.\n * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nHeadingPitchRoll.prototype.equalsEpsilon = function (\n right,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return HeadingPitchRoll.equalsEpsilon(\n this,\n right,\n relativeEpsilon,\n absoluteEpsilon\n );\n};\n\n/**\n * Creates a string representing this HeadingPitchRoll in the format '(heading, pitch, roll)' in radians.\n *\n * @returns {string} A string representing the provided HeadingPitchRoll in the format '(heading, pitch, roll)'.\n */\nHeadingPitchRoll.prototype.toString = function () {\n return `(${this.heading}, ${this.pitch}, ${this.roll})`;\n};\nexport default HeadingPitchRoll;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport getAbsoluteUri from \"./getAbsoluteUri.js\";\nimport Resource from \"./Resource.js\";\n\n/*global CESIUM_BASE_URL,define,require*/\n\nconst cesiumScriptRegex = /((?:.*\\/)|^)Cesium\\.js(?:\\?|\\#|$)/;\nfunction getBaseUrlFromCesiumScript() {\n const scripts = document.getElementsByTagName(\"script\");\n for (let i = 0, len = scripts.length; i < len; ++i) {\n const src = scripts[i].getAttribute(\"src\");\n const result = cesiumScriptRegex.exec(src);\n if (result !== null) {\n return result[1];\n }\n }\n return undefined;\n}\n\nlet a;\nfunction tryMakeAbsolute(url) {\n if (typeof document === \"undefined\") {\n //Node.js and Web Workers. In both cases, the URL will already be absolute.\n return url;\n }\n\n if (!defined(a)) {\n a = document.createElement(\"a\");\n }\n a.href = url;\n\n // IE only absolutizes href on get, not set\n // eslint-disable-next-line no-self-assign\n a.href = a.href;\n return a.href;\n}\n\nlet baseResource;\nfunction getCesiumBaseUrl() {\n if (defined(baseResource)) {\n return baseResource;\n }\n\n let baseUrlString;\n if (typeof CESIUM_BASE_URL !== \"undefined\") {\n baseUrlString = CESIUM_BASE_URL;\n } else if (\n typeof define === \"object\" &&\n defined(define.amd) &&\n !define.amd.toUrlUndefined &&\n defined(require.toUrl)\n ) {\n baseUrlString = getAbsoluteUri(\n \"..\",\n buildModuleUrl(\"Core/buildModuleUrl.js\")\n );\n } else {\n baseUrlString = getBaseUrlFromCesiumScript();\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(baseUrlString)) {\n throw new DeveloperError(\n \"Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.\"\n );\n }\n //>>includeEnd('debug');\n\n baseResource = new Resource({\n url: tryMakeAbsolute(baseUrlString),\n });\n baseResource.appendForwardSlash();\n\n return baseResource;\n}\n\nfunction buildModuleUrlFromRequireToUrl(moduleID) {\n //moduleID will be non-relative, so require it relative to this module, in Core.\n return tryMakeAbsolute(require.toUrl(`../${moduleID}`));\n}\n\nfunction buildModuleUrlFromBaseUrl(moduleID) {\n const resource = getCesiumBaseUrl().getDerivedResource({\n url: moduleID,\n });\n return resource.url;\n}\n\nlet implementation;\n\n/**\n * Given a relative URL under the Cesium base URL, returns an absolute URL.\n * @function\n *\n * @param {string} relativeUrl The relative path.\n * @returns {string} The absolutely URL representation of the provided path.\n *\n * @example\n * const viewer = new Cesium.Viewer(\"cesiumContainer\", {\n * baseLayer: Cesium.ImageryLayer.fromProviderAsync(\n * Cesium.TileMapServiceImageryProvider.fromUrl(\n * Cesium.buildModuleUrl(\"Assets/Textures/NaturalEarthII\"),\n * )),\n * baseLayerPicker: false,\n * });\n */\nfunction buildModuleUrl(relativeUrl) {\n if (!defined(implementation)) {\n //select implementation\n if (\n typeof define === \"object\" &&\n defined(define.amd) &&\n !define.amd.toUrlUndefined &&\n defined(require.toUrl)\n ) {\n implementation = buildModuleUrlFromRequireToUrl;\n } else {\n implementation = buildModuleUrlFromBaseUrl;\n }\n }\n\n const url = implementation(relativeUrl);\n return url;\n}\n\n// exposed for testing\nbuildModuleUrl._cesiumScriptRegex = cesiumScriptRegex;\nbuildModuleUrl._buildModuleUrlFromBaseUrl = buildModuleUrlFromBaseUrl;\nbuildModuleUrl._clearBaseResource = function () {\n baseResource = undefined;\n};\n\n/**\n * Sets the base URL for resolving modules.\n * @param {string} value The new base URL.\n */\nbuildModuleUrl.setBaseUrl = function (value) {\n baseResource = Resource.DEFAULT.getDerivedResource({\n url: value,\n });\n};\n\n/**\n * Gets the base URL for resolving modules.\n *\n * @function\n * @returns {string} The configured base URL\n */\nbuildModuleUrl.getCesiumBaseUrl = getCesiumBaseUrl;\n\nexport default buildModuleUrl;\n", "/**\n * An IAU 2006 XYS value sampled at a particular time.\n *\n * @alias Iau2006XysSample\n * @constructor\n *\n * @param {number} x The X value.\n * @param {number} y The Y value.\n * @param {number} s The S value.\n *\n * @private\n */\nfunction Iau2006XysSample(x, y, s) {\n /**\n * The X value.\n * @type {number}\n */\n this.x = x;\n\n /**\n * The Y value.\n * @type {number}\n */\n this.y = y;\n\n /**\n * The S value.\n * @type {number}\n */\n this.s = s;\n}\nexport default Iau2006XysSample;\n", "import buildModuleUrl from \"./buildModuleUrl.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Iau2006XysSample from \"./Iau2006XysSample.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport Resource from \"./Resource.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\n/**\n * A set of IAU2006 XYS data that is used to evaluate the transformation between the International\n * Celestial Reference Frame (ICRF) and the International Terrestrial Reference Frame (ITRF).\n *\n * @alias Iau2006XysData\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Resource|string} [options.xysFileUrlTemplate='Assets/IAU2006_XYS/IAU2006_XYS_{0}.json'] A template URL for obtaining the XYS data. In the template,\n * `{0}` will be replaced with the file index.\n * @param {number} [options.interpolationOrder=9] The order of interpolation to perform on the XYS data.\n * @param {number} [options.sampleZeroJulianEphemerisDate=2442396.5] The Julian ephemeris date (JED) of the\n * first XYS sample.\n * @param {number} [options.stepSizeDays=1.0] The step size, in days, between successive XYS samples.\n * @param {number} [options.samplesPerXysFile=1000] The number of samples in each XYS file.\n * @param {number} [options.totalSamples=27426] The total number of samples in all XYS files.\n *\n * @private\n */\nfunction Iau2006XysData(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._xysFileUrlTemplate = Resource.createIfNeeded(\n options.xysFileUrlTemplate\n );\n this._interpolationOrder = defaultValue(options.interpolationOrder, 9);\n this._sampleZeroJulianEphemerisDate = defaultValue(\n options.sampleZeroJulianEphemerisDate,\n 2442396.5\n );\n this._sampleZeroDateTT = new JulianDate(\n this._sampleZeroJulianEphemerisDate,\n 0.0,\n TimeStandard.TAI\n );\n this._stepSizeDays = defaultValue(options.stepSizeDays, 1.0);\n this._samplesPerXysFile = defaultValue(options.samplesPerXysFile, 1000);\n this._totalSamples = defaultValue(options.totalSamples, 27426);\n this._samples = new Array(this._totalSamples * 3);\n this._chunkDownloadsInProgress = [];\n\n const order = this._interpolationOrder;\n\n // Compute denominators and X values for interpolation.\n const denom = (this._denominators = new Array(order + 1));\n const xTable = (this._xTable = new Array(order + 1));\n\n const stepN = Math.pow(this._stepSizeDays, order);\n\n for (let i = 0; i <= order; ++i) {\n denom[i] = stepN;\n xTable[i] = i * this._stepSizeDays;\n\n for (let j = 0; j <= order; ++j) {\n if (j !== i) {\n denom[i] *= i - j;\n }\n }\n\n denom[i] = 1.0 / denom[i];\n }\n\n // Allocate scratch arrays for interpolation.\n this._work = new Array(order + 1);\n this._coef = new Array(order + 1);\n}\n\nconst julianDateScratch = new JulianDate(0, 0.0, TimeStandard.TAI);\n\nfunction getDaysSinceEpoch(xys, dayTT, secondTT) {\n const dateTT = julianDateScratch;\n dateTT.dayNumber = dayTT;\n dateTT.secondsOfDay = secondTT;\n return JulianDate.daysDifference(dateTT, xys._sampleZeroDateTT);\n}\n\n/**\n * Preloads XYS data for a specified date range.\n *\n * @param {number} startDayTT The Julian day number of the beginning of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {number} startSecondTT The seconds past noon of the beginning of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {number} stopDayTT The Julian day number of the end of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {number} stopSecondTT The seconds past noon of the end of the interval to preload, expressed in\n * the Terrestrial Time (TT) time standard.\n * @returns {Promise} A promise that, when resolved, indicates that the requested interval has been\n * preloaded.\n */\nIau2006XysData.prototype.preload = function (\n startDayTT,\n startSecondTT,\n stopDayTT,\n stopSecondTT\n) {\n const startDaysSinceEpoch = getDaysSinceEpoch(\n this,\n startDayTT,\n startSecondTT\n );\n const stopDaysSinceEpoch = getDaysSinceEpoch(this, stopDayTT, stopSecondTT);\n\n let startIndex =\n (startDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) |\n 0;\n if (startIndex < 0) {\n startIndex = 0;\n }\n\n let stopIndex =\n (stopDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) |\n (0 + this._interpolationOrder);\n if (stopIndex >= this._totalSamples) {\n stopIndex = this._totalSamples - 1;\n }\n\n const startChunk = (startIndex / this._samplesPerXysFile) | 0;\n const stopChunk = (stopIndex / this._samplesPerXysFile) | 0;\n\n const promises = [];\n for (let i = startChunk; i <= stopChunk; ++i) {\n promises.push(requestXysChunk(this, i));\n }\n\n return Promise.all(promises);\n};\n\n/**\n * Computes the XYS values for a given date by interpolating. If the required data is not yet downloaded,\n * this method will return undefined.\n *\n * @param {number} dayTT The Julian day number for which to compute the XYS value, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {number} secondTT The seconds past noon of the date for which to compute the XYS value, expressed in\n * the Terrestrial Time (TT) time standard.\n * @param {Iau2006XysSample} [result] The instance to which to copy the interpolated result. If this parameter\n * is undefined, a new instance is allocated and returned.\n * @returns {Iau2006XysSample} The interpolated XYS values, or undefined if the required data for this\n * computation has not yet been downloaded.\n *\n * @see Iau2006XysData#preload\n */\nIau2006XysData.prototype.computeXysRadians = function (\n dayTT,\n secondTT,\n result\n) {\n const daysSinceEpoch = getDaysSinceEpoch(this, dayTT, secondTT);\n if (daysSinceEpoch < 0.0) {\n // Can't evaluate prior to the epoch of the data.\n return undefined;\n }\n\n const centerIndex = (daysSinceEpoch / this._stepSizeDays) | 0;\n if (centerIndex >= this._totalSamples) {\n // Can't evaluate after the last sample in the data.\n return undefined;\n }\n\n const degree = this._interpolationOrder;\n\n let firstIndex = centerIndex - ((degree / 2) | 0);\n if (firstIndex < 0) {\n firstIndex = 0;\n }\n let lastIndex = firstIndex + degree;\n if (lastIndex >= this._totalSamples) {\n lastIndex = this._totalSamples - 1;\n firstIndex = lastIndex - degree;\n if (firstIndex < 0) {\n firstIndex = 0;\n }\n }\n\n // Are all the samples we need present?\n // We can assume so if the first and last are present\n let isDataMissing = false;\n const samples = this._samples;\n if (!defined(samples[firstIndex * 3])) {\n requestXysChunk(this, (firstIndex / this._samplesPerXysFile) | 0);\n isDataMissing = true;\n }\n\n if (!defined(samples[lastIndex * 3])) {\n requestXysChunk(this, (lastIndex / this._samplesPerXysFile) | 0);\n isDataMissing = true;\n }\n\n if (isDataMissing) {\n return undefined;\n }\n\n if (!defined(result)) {\n result = new Iau2006XysSample(0.0, 0.0, 0.0);\n } else {\n result.x = 0.0;\n result.y = 0.0;\n result.s = 0.0;\n }\n\n const x = daysSinceEpoch - firstIndex * this._stepSizeDays;\n\n const work = this._work;\n const denom = this._denominators;\n const coef = this._coef;\n const xTable = this._xTable;\n\n let i, j;\n for (i = 0; i <= degree; ++i) {\n work[i] = x - xTable[i];\n }\n\n for (i = 0; i <= degree; ++i) {\n coef[i] = 1.0;\n\n for (j = 0; j <= degree; ++j) {\n if (j !== i) {\n coef[i] *= work[j];\n }\n }\n\n coef[i] *= denom[i];\n\n let sampleIndex = (firstIndex + i) * 3;\n result.x += coef[i] * samples[sampleIndex++];\n result.y += coef[i] * samples[sampleIndex++];\n result.s += coef[i] * samples[sampleIndex];\n }\n\n return result;\n};\n\nfunction requestXysChunk(xysData, chunkIndex) {\n if (xysData._chunkDownloadsInProgress[chunkIndex]) {\n // Chunk has already been requested.\n return xysData._chunkDownloadsInProgress[chunkIndex];\n }\n\n let chunkUrl;\n const xysFileUrlTemplate = xysData._xysFileUrlTemplate;\n if (defined(xysFileUrlTemplate)) {\n chunkUrl = xysFileUrlTemplate.getDerivedResource({\n templateValues: {\n 0: chunkIndex,\n },\n });\n } else {\n chunkUrl = new Resource({\n url: buildModuleUrl(`Assets/IAU2006_XYS/IAU2006_XYS_${chunkIndex}.json`),\n });\n }\n\n const promise = chunkUrl.fetchJson().then(function (chunk) {\n xysData._chunkDownloadsInProgress[chunkIndex] = false;\n\n const samples = xysData._samples;\n const newSamples = chunk.samples;\n const startIndex = chunkIndex * xysData._samplesPerXysFile * 3;\n\n for (let i = 0, len = newSamples.length; i < len; ++i) {\n samples[startIndex + i] = newSamples[i];\n }\n });\n xysData._chunkDownloadsInProgress[chunkIndex] = promise;\n\n return promise;\n}\nexport default Iau2006XysData;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport EarthOrientationParameters from \"./EarthOrientationParameters.js\";\nimport EarthOrientationParametersSample from \"./EarthOrientationParametersSample.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport HeadingPitchRoll from \"./HeadingPitchRoll.js\";\nimport Iau2006XysData from \"./Iau2006XysData.js\";\nimport Iau2006XysSample from \"./Iau2006XysSample.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport TimeConstants from \"./TimeConstants.js\";\n\n/**\n * Contains functions for transforming positions to various reference frames.\n *\n * @namespace Transforms\n */\nconst Transforms = {};\n\nconst vectorProductLocalFrame = {\n up: {\n south: \"east\",\n north: \"west\",\n west: \"south\",\n east: \"north\",\n },\n down: {\n south: \"west\",\n north: \"east\",\n west: \"north\",\n east: \"south\",\n },\n south: {\n up: \"west\",\n down: \"east\",\n west: \"down\",\n east: \"up\",\n },\n north: {\n up: \"east\",\n down: \"west\",\n west: \"up\",\n east: \"down\",\n },\n west: {\n up: \"north\",\n down: \"south\",\n north: \"down\",\n south: \"up\",\n },\n east: {\n up: \"south\",\n down: \"north\",\n north: \"up\",\n south: \"down\",\n },\n};\n\nconst degeneratePositionLocalFrame = {\n north: [-1, 0, 0],\n east: [0, 1, 0],\n up: [0, 0, 1],\n south: [1, 0, 0],\n west: [0, -1, 0],\n down: [0, 0, -1],\n};\n\nconst localFrameToFixedFrameCache = {};\n\nconst scratchCalculateCartesian = {\n east: new Cartesian3(),\n north: new Cartesian3(),\n up: new Cartesian3(),\n west: new Cartesian3(),\n south: new Cartesian3(),\n down: new Cartesian3(),\n};\nlet scratchFirstCartesian = new Cartesian3();\nlet scratchSecondCartesian = new Cartesian3();\nlet scratchThirdCartesian = new Cartesian3();\n/**\n * Generates a function that computes a 4x4 transformation matrix from a reference frame\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * @param {string} firstAxis name of the first axis of the local reference frame. Must be\n * 'east', 'north', 'up', 'west', 'south' or 'down'.\n * @param {string} secondAxis name of the second axis of the local reference frame. Must be\n * 'east', 'north', 'up', 'west', 'south' or 'down'.\n * @return {Transforms.LocalFrameToFixedFrame} The function that will computes a\n * 4x4 transformation matrix from a reference frame, with first axis and second axis compliant with the parameters,\n */\nTransforms.localFrameToFixedFrameGenerator = function (firstAxis, secondAxis) {\n if (\n !vectorProductLocalFrame.hasOwnProperty(firstAxis) ||\n !vectorProductLocalFrame[firstAxis].hasOwnProperty(secondAxis)\n ) {\n throw new DeveloperError(\n \"firstAxis and secondAxis must be east, north, up, west, south or down.\"\n );\n }\n const thirdAxis = vectorProductLocalFrame[firstAxis][secondAxis];\n\n /**\n * Computes a 4x4 transformation matrix from a reference frame\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * @callback Transforms.LocalFrameToFixedFrame\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n */\n let resultat;\n const hashAxis = firstAxis + secondAxis;\n if (defined(localFrameToFixedFrameCache[hashAxis])) {\n resultat = localFrameToFixedFrameCache[hashAxis];\n } else {\n resultat = function (origin, ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(origin)) {\n throw new DeveloperError(\"origin is required.\");\n }\n //>>includeEnd('debug');\n if (!defined(result)) {\n result = new Matrix4();\n }\n if (\n Cartesian3.equalsEpsilon(origin, Cartesian3.ZERO, CesiumMath.EPSILON14)\n ) {\n // If x, y, and z are zero, use the degenerate local frame, which is a special case\n Cartesian3.unpack(\n degeneratePositionLocalFrame[firstAxis],\n 0,\n scratchFirstCartesian\n );\n Cartesian3.unpack(\n degeneratePositionLocalFrame[secondAxis],\n 0,\n scratchSecondCartesian\n );\n Cartesian3.unpack(\n degeneratePositionLocalFrame[thirdAxis],\n 0,\n scratchThirdCartesian\n );\n } else if (\n CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&\n CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)\n ) {\n // If x and y are zero, assume origin is at a pole, which is a special case.\n const sign = CesiumMath.sign(origin.z);\n\n Cartesian3.unpack(\n degeneratePositionLocalFrame[firstAxis],\n 0,\n scratchFirstCartesian\n );\n if (firstAxis !== \"east\" && firstAxis !== \"west\") {\n Cartesian3.multiplyByScalar(\n scratchFirstCartesian,\n sign,\n scratchFirstCartesian\n );\n }\n\n Cartesian3.unpack(\n degeneratePositionLocalFrame[secondAxis],\n 0,\n scratchSecondCartesian\n );\n if (secondAxis !== \"east\" && secondAxis !== \"west\") {\n Cartesian3.multiplyByScalar(\n scratchSecondCartesian,\n sign,\n scratchSecondCartesian\n );\n }\n\n Cartesian3.unpack(\n degeneratePositionLocalFrame[thirdAxis],\n 0,\n scratchThirdCartesian\n );\n if (thirdAxis !== \"east\" && thirdAxis !== \"west\") {\n Cartesian3.multiplyByScalar(\n scratchThirdCartesian,\n sign,\n scratchThirdCartesian\n );\n }\n } else {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n ellipsoid.geodeticSurfaceNormal(origin, scratchCalculateCartesian.up);\n\n const up = scratchCalculateCartesian.up;\n const east = scratchCalculateCartesian.east;\n east.x = -origin.y;\n east.y = origin.x;\n east.z = 0.0;\n Cartesian3.normalize(east, scratchCalculateCartesian.east);\n Cartesian3.cross(up, east, scratchCalculateCartesian.north);\n\n Cartesian3.multiplyByScalar(\n scratchCalculateCartesian.up,\n -1,\n scratchCalculateCartesian.down\n );\n Cartesian3.multiplyByScalar(\n scratchCalculateCartesian.east,\n -1,\n scratchCalculateCartesian.west\n );\n Cartesian3.multiplyByScalar(\n scratchCalculateCartesian.north,\n -1,\n scratchCalculateCartesian.south\n );\n\n scratchFirstCartesian = scratchCalculateCartesian[firstAxis];\n scratchSecondCartesian = scratchCalculateCartesian[secondAxis];\n scratchThirdCartesian = scratchCalculateCartesian[thirdAxis];\n }\n result[0] = scratchFirstCartesian.x;\n result[1] = scratchFirstCartesian.y;\n result[2] = scratchFirstCartesian.z;\n result[3] = 0.0;\n result[4] = scratchSecondCartesian.x;\n result[5] = scratchSecondCartesian.y;\n result[6] = scratchSecondCartesian.z;\n result[7] = 0.0;\n result[8] = scratchThirdCartesian.x;\n result[9] = scratchThirdCartesian.y;\n result[10] = scratchThirdCartesian.z;\n result[11] = 0.0;\n result[12] = origin.x;\n result[13] = origin.y;\n result[14] = origin.z;\n result[15] = 1.0;\n return result;\n };\n localFrameToFixedFrameCache[hashAxis] = resultat;\n }\n return resultat;\n};\n\n/**\n * Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * The local axes are defined as:\n *
    \n *
  • The x axis points in the local east direction.
  • \n *
  • The y axis points in the local north direction.
  • \n *
  • The z axis points in the direction of the ellipsoid surface normal which passes through the position.
  • \n *
\n *\n * @function\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n *\n * @example\n * // Get the transform from local east-north-up at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);\n */\nTransforms.eastNorthUpToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\n \"east\",\n \"north\"\n);\n\n/**\n * Computes a 4x4 transformation matrix from a reference frame with an north-east-down axes\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * The local axes are defined as:\n *
    \n *
  • The x axis points in the local north direction.
  • \n *
  • The y axis points in the local east direction.
  • \n *
  • The z axis points in the opposite direction of the ellipsoid surface normal which passes through the position.
  • \n *
\n *\n * @function\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n *\n * @example\n * // Get the transform from local north-east-down at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const transform = Cesium.Transforms.northEastDownToFixedFrame(center);\n */\nTransforms.northEastDownToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\n \"north\",\n \"east\"\n);\n\n/**\n * Computes a 4x4 transformation matrix from a reference frame with an north-up-east axes\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * The local axes are defined as:\n *
    \n *
  • The x axis points in the local north direction.
  • \n *
  • The y axis points in the direction of the ellipsoid surface normal which passes through the position.
  • \n *
  • The z axis points in the local east direction.
  • \n *
\n *\n * @function\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n *\n * @example\n * // Get the transform from local north-up-east at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const transform = Cesium.Transforms.northUpEastToFixedFrame(center);\n */\nTransforms.northUpEastToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\n \"north\",\n \"up\"\n);\n\n/**\n * Computes a 4x4 transformation matrix from a reference frame with an north-west-up axes\n * centered at the provided origin to the provided ellipsoid's fixed reference frame.\n * The local axes are defined as:\n *
    \n *
  • The x axis points in the local north direction.
  • \n *
  • The y axis points in the local west direction.
  • \n *
  • The z axis points in the direction of the ellipsoid surface normal which passes through the position.
  • \n *
\n *\n * @function\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n *\n * @example\n * // Get the transform from local north-West-Up at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const transform = Cesium.Transforms.northWestUpToFixedFrame(center);\n */\nTransforms.northWestUpToFixedFrame = Transforms.localFrameToFixedFrameGenerator(\n \"north\",\n \"west\"\n);\n\nconst scratchHPRQuaternion = new Quaternion();\nconst scratchScale = new Cartesian3(1.0, 1.0, 1.0);\nconst scratchHPRMatrix4 = new Matrix4();\n\n/**\n * Computes a 4x4 transformation matrix from a reference frame with axes computed from the heading-pitch-roll angles\n * centered at the provided origin to the provided ellipsoid's fixed reference frame. Heading is the rotation from the local north\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\n *\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\n * @param {Matrix4} [result] The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.\n *\n * @example\n * // Get the transform from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const heading = -Cesium.Math.PI_OVER_TWO;\n * const pitch = Cesium.Math.PI_OVER_FOUR;\n * const roll = 0.0;\n * const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);\n * const transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, hpr);\n */\nTransforms.headingPitchRollToFixedFrame = function (\n origin,\n headingPitchRoll,\n ellipsoid,\n fixedFrameTransform,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"HeadingPitchRoll\", headingPitchRoll);\n //>>includeEnd('debug');\n\n fixedFrameTransform = defaultValue(\n fixedFrameTransform,\n Transforms.eastNorthUpToFixedFrame\n );\n const hprQuaternion = Quaternion.fromHeadingPitchRoll(\n headingPitchRoll,\n scratchHPRQuaternion\n );\n const hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(\n Cartesian3.ZERO,\n hprQuaternion,\n scratchScale,\n scratchHPRMatrix4\n );\n result = fixedFrameTransform(origin, ellipsoid, result);\n return Matrix4.multiply(result, hprMatrix, result);\n};\n\nconst scratchENUMatrix4 = new Matrix4();\nconst scratchHPRMatrix3 = new Matrix3();\n\n/**\n * Computes a quaternion from a reference frame with axes computed from the heading-pitch-roll angles\n * centered at the provided origin. Heading is the rotation from the local north\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\n *\n * @param {Cartesian3} origin The center point of the local reference frame.\n * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.\n *\n * @example\n * // Get the quaternion from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.\n * const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const heading = -Cesium.Math.PI_OVER_TWO;\n * const pitch = Cesium.Math.PI_OVER_FOUR;\n * const roll = 0.0;\n * const hpr = new HeadingPitchRoll(heading, pitch, roll);\n * const quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr);\n */\nTransforms.headingPitchRollQuaternion = function (\n origin,\n headingPitchRoll,\n ellipsoid,\n fixedFrameTransform,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"HeadingPitchRoll\", headingPitchRoll);\n //>>includeEnd('debug');\n\n const transform = Transforms.headingPitchRollToFixedFrame(\n origin,\n headingPitchRoll,\n ellipsoid,\n fixedFrameTransform,\n scratchENUMatrix4\n );\n const rotation = Matrix4.getMatrix3(transform, scratchHPRMatrix3);\n return Quaternion.fromRotationMatrix(rotation, result);\n};\n\nconst noScale = new Cartesian3(1.0, 1.0, 1.0);\nconst hprCenterScratch = new Cartesian3();\nconst ffScratch = new Matrix4();\nconst hprTransformScratch = new Matrix4();\nconst hprRotationScratch = new Matrix3();\nconst hprQuaternionScratch = new Quaternion();\n/**\n * Computes heading-pitch-roll angles from a transform in a particular reference frame. Heading is the rotation from the local north\n * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles\n * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.\n *\n * @param {Matrix4} transform The transform\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Transforms.LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation\n * matrix from a reference frame to the provided ellipsoid's fixed reference frame\n * @param {HeadingPitchRoll} [result] The object onto which to store the result.\n * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if none was provided.\n */\nTransforms.fixedFrameToHeadingPitchRoll = function (\n transform,\n ellipsoid,\n fixedFrameTransform,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"transform\", transform);\n //>>includeEnd('debug');\n\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n fixedFrameTransform = defaultValue(\n fixedFrameTransform,\n Transforms.eastNorthUpToFixedFrame\n );\n if (!defined(result)) {\n result = new HeadingPitchRoll();\n }\n\n const center = Matrix4.getTranslation(transform, hprCenterScratch);\n if (Cartesian3.equals(center, Cartesian3.ZERO)) {\n result.heading = 0;\n result.pitch = 0;\n result.roll = 0;\n return result;\n }\n let toFixedFrame = Matrix4.inverseTransformation(\n fixedFrameTransform(center, ellipsoid, ffScratch),\n ffScratch\n );\n let transformCopy = Matrix4.setScale(transform, noScale, hprTransformScratch);\n transformCopy = Matrix4.setTranslation(\n transformCopy,\n Cartesian3.ZERO,\n transformCopy\n );\n\n toFixedFrame = Matrix4.multiply(toFixedFrame, transformCopy, toFixedFrame);\n let quaternionRotation = Quaternion.fromRotationMatrix(\n Matrix4.getMatrix3(toFixedFrame, hprRotationScratch),\n hprQuaternionScratch\n );\n quaternionRotation = Quaternion.normalize(\n quaternionRotation,\n quaternionRotation\n );\n\n return HeadingPitchRoll.fromQuaternion(quaternionRotation, result);\n};\n\nconst gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841;\nconst gmstConstant1 = 8640184.812866;\nconst gmstConstant2 = 0.093104;\nconst gmstConstant3 = -6.2e-6;\nconst rateCoef = 1.1772758384668e-19;\nconst wgs84WRPrecessing = 7.2921158553e-5;\nconst twoPiOverSecondsInDay = CesiumMath.TWO_PI / 86400.0;\nlet dateInUtc = new JulianDate();\n\n/**\n * Computes a rotation matrix to transform a point or vector from True Equator Mean Equinox (TEME) axes to the\n * pseudo-fixed axes at a given time. This method treats the UT1 time standard as equivalent to UTC.\n *\n * @param {JulianDate} date The time at which to compute the rotation matrix.\n * @param {Matrix3} [result] The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided.\n *\n * @example\n * //Set the view to the inertial frame.\n * scene.postUpdate.addEventListener(function(scene, time) {\n * const now = Cesium.JulianDate.now();\n * const offset = Cesium.Matrix4.multiplyByPoint(camera.transform, camera.position, new Cesium.Cartesian3());\n * const transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Transforms.computeTemeToPseudoFixedMatrix(now));\n * const inverseTransform = Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4());\n * Cesium.Matrix4.multiplyByPoint(inverseTransform, offset, offset);\n * camera.lookAtTransform(transform, offset);\n * });\n */\nTransforms.computeTemeToPseudoFixedMatrix = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(\"date is required.\");\n }\n //>>includeEnd('debug');\n\n // GMST is actually computed using UT1. We're using UTC as an approximation of UT1.\n // We do not want to use the function like convertTaiToUtc in JulianDate because\n // we explicitly do not want to fail when inside the leap second.\n\n dateInUtc = JulianDate.addSeconds(\n date,\n -JulianDate.computeTaiMinusUtc(date),\n dateInUtc\n );\n const utcDayNumber = dateInUtc.dayNumber;\n const utcSecondsIntoDay = dateInUtc.secondsOfDay;\n\n let t;\n const diffDays = utcDayNumber - 2451545;\n if (utcSecondsIntoDay >= 43200.0) {\n t = (diffDays + 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;\n } else {\n t = (diffDays - 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;\n }\n\n const gmst0 =\n gmstConstant0 +\n t * (gmstConstant1 + t * (gmstConstant2 + t * gmstConstant3));\n const angle = (gmst0 * twoPiOverSecondsInDay) % CesiumMath.TWO_PI;\n const ratio = wgs84WRPrecessing + rateCoef * (utcDayNumber - 2451545.5);\n const secondsSinceMidnight =\n (utcSecondsIntoDay + TimeConstants.SECONDS_PER_DAY * 0.5) %\n TimeConstants.SECONDS_PER_DAY;\n const gha = angle + ratio * secondsSinceMidnight;\n const cosGha = Math.cos(gha);\n const sinGha = Math.sin(gha);\n\n if (!defined(result)) {\n return new Matrix3(\n cosGha,\n sinGha,\n 0.0,\n -sinGha,\n cosGha,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n );\n }\n result[0] = cosGha;\n result[1] = -sinGha;\n result[2] = 0.0;\n result[3] = sinGha;\n result[4] = cosGha;\n result[5] = 0.0;\n result[6] = 0.0;\n result[7] = 0.0;\n result[8] = 1.0;\n return result;\n};\n\n/**\n * The source of IAU 2006 XYS data, used for computing the transformation between the\n * Fixed and ICRF axes.\n * @type {Iau2006XysData}\n *\n * @see Transforms.computeIcrfToFixedMatrix\n * @see Transforms.computeFixedToIcrfMatrix\n *\n * @private\n */\nTransforms.iau2006XysData = new Iau2006XysData();\n\n/**\n * The source of Earth Orientation Parameters (EOP) data, used for computing the transformation\n * between the Fixed and ICRF axes. By default, zero values are used for all EOP values,\n * yielding a reasonable but not completely accurate representation of the ICRF axes.\n * @type {EarthOrientationParameters}\n *\n * @see Transforms.computeIcrfToFixedMatrix\n * @see Transforms.computeFixedToIcrfMatrix\n *\n * @private\n */\nTransforms.earthOrientationParameters = EarthOrientationParameters.NONE;\n\nconst ttMinusTai = 32.184;\nconst j2000ttDays = 2451545.0;\n\n/**\n * Preloads the data necessary to transform between the ICRF and Fixed axes, in either\n * direction, over a given interval. This function returns a promise that, when resolved,\n * indicates that the preload has completed.\n *\n * @param {TimeInterval} timeInterval The interval to preload.\n * @returns {Promise} A promise that, when resolved, indicates that the preload has completed\n * and evaluation of the transformation between the fixed and ICRF axes will\n * no longer return undefined for a time inside the interval.\n *\n *\n * @example\n * const interval = new Cesium.TimeInterval(...);\n * await Cesium.Transforms.preloadIcrfFixed(interval));\n * // the data is now loaded\n *\n * @see Transforms.computeIcrfToFixedMatrix\n * @see Transforms.computeFixedToIcrfMatrix\n */\nTransforms.preloadIcrfFixed = function (timeInterval) {\n const startDayTT = timeInterval.start.dayNumber;\n const startSecondTT = timeInterval.start.secondsOfDay + ttMinusTai;\n const stopDayTT = timeInterval.stop.dayNumber;\n const stopSecondTT = timeInterval.stop.secondsOfDay + ttMinusTai;\n\n return Transforms.iau2006XysData.preload(\n startDayTT,\n startSecondTT,\n stopDayTT,\n stopSecondTT\n );\n};\n\n/**\n * Computes a rotation matrix to transform a point or vector from the International Celestial\n * Reference Frame (GCRF/ICRF) inertial frame axes to the Earth-Fixed frame axes (ITRF)\n * at a given time. This function may return undefined if the data necessary to\n * do the transformation is not yet loaded.\n *\n * @param {JulianDate} date The time at which to compute the rotation matrix.\n * @param {Matrix3} [result] The object onto which to store the result. If this parameter is\n * not specified, a new instance is created and returned.\n * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the\n * transformation is not yet loaded.\n *\n *\n * @example\n * scene.postUpdate.addEventListener(function(scene, time) {\n * // View in ICRF.\n * const icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);\n * if (Cesium.defined(icrfToFixed)) {\n * const offset = Cesium.Cartesian3.clone(camera.position);\n * const transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed);\n * camera.lookAtTransform(transform, offset);\n * }\n * });\n *\n * @see Transforms.preloadIcrfFixed\n */\nTransforms.computeIcrfToFixedMatrix = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(\"date is required.\");\n }\n //>>includeEnd('debug');\n if (!defined(result)) {\n result = new Matrix3();\n }\n\n const fixedToIcrfMtx = Transforms.computeFixedToIcrfMatrix(date, result);\n if (!defined(fixedToIcrfMtx)) {\n return undefined;\n }\n\n return Matrix3.transpose(fixedToIcrfMtx, result);\n};\n\nconst xysScratch = new Iau2006XysSample(0.0, 0.0, 0.0);\nconst eopScratch = new EarthOrientationParametersSample(\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0\n);\nconst rotation1Scratch = new Matrix3();\nconst rotation2Scratch = new Matrix3();\n\n/**\n * Computes a rotation matrix to transform a point or vector from the Earth-Fixed frame axes (ITRF)\n * to the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes\n * at a given time. This function may return undefined if the data necessary to\n * do the transformation is not yet loaded.\n *\n * @param {JulianDate} date The time at which to compute the rotation matrix.\n * @param {Matrix3} [result] The object onto which to store the result. If this parameter is\n * not specified, a new instance is created and returned.\n * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the\n * transformation is not yet loaded.\n *\n *\n * @example\n * // Transform a point from the ICRF axes to the Fixed axes.\n * const now = Cesium.JulianDate.now();\n * const pointInFixed = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const fixedToIcrf = Cesium.Transforms.computeIcrfToFixedMatrix(now);\n * let pointInInertial = new Cesium.Cartesian3();\n * if (Cesium.defined(fixedToIcrf)) {\n * pointInInertial = Cesium.Matrix3.multiplyByVector(fixedToIcrf, pointInFixed, pointInInertial);\n * }\n *\n * @see Transforms.preloadIcrfFixed\n */\nTransforms.computeFixedToIcrfMatrix = function (date, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(\"date is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Matrix3();\n }\n\n // Compute pole wander\n const eop = Transforms.earthOrientationParameters.compute(date, eopScratch);\n if (!defined(eop)) {\n return undefined;\n }\n\n // There is no external conversion to Terrestrial Time (TT).\n // So use International Atomic Time (TAI) and convert using offsets.\n // Here we are assuming that dayTT and secondTT are positive\n const dayTT = date.dayNumber;\n // It's possible here that secondTT could roll over 86400\n // This does not seem to affect the precision (unit tests check for this)\n const secondTT = date.secondsOfDay + ttMinusTai;\n\n const xys = Transforms.iau2006XysData.computeXysRadians(\n dayTT,\n secondTT,\n xysScratch\n );\n if (!defined(xys)) {\n return undefined;\n }\n\n const x = xys.x + eop.xPoleOffset;\n const y = xys.y + eop.yPoleOffset;\n\n // Compute XYS rotation\n const a = 1.0 / (1.0 + Math.sqrt(1.0 - x * x - y * y));\n\n const rotation1 = rotation1Scratch;\n rotation1[0] = 1.0 - a * x * x;\n rotation1[3] = -a * x * y;\n rotation1[6] = x;\n rotation1[1] = -a * x * y;\n rotation1[4] = 1 - a * y * y;\n rotation1[7] = y;\n rotation1[2] = -x;\n rotation1[5] = -y;\n rotation1[8] = 1 - a * (x * x + y * y);\n\n const rotation2 = Matrix3.fromRotationZ(-xys.s, rotation2Scratch);\n const matrixQ = Matrix3.multiply(rotation1, rotation2, rotation1Scratch);\n\n // Similar to TT conversions above\n // It's possible here that secondTT could roll over 86400\n // This does not seem to affect the precision (unit tests check for this)\n const dateUt1day = date.dayNumber;\n const dateUt1sec =\n date.secondsOfDay - JulianDate.computeTaiMinusUtc(date) + eop.ut1MinusUtc;\n\n // Compute Earth rotation angle\n // The IERS standard for era is\n // era = 0.7790572732640 + 1.00273781191135448 * Tu\n // where\n // Tu = JulianDateInUt1 - 2451545.0\n // However, you get much more precision if you make the following simplification\n // era = a + (1 + b) * (JulianDayNumber + FractionOfDay - 2451545)\n // era = a + (JulianDayNumber - 2451545) + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)\n // era = a + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)\n // since (JulianDayNumber - 2451545) represents an integer number of revolutions which will be discarded anyway.\n const daysSinceJ2000 = dateUt1day - 2451545;\n const fractionOfDay = dateUt1sec / TimeConstants.SECONDS_PER_DAY;\n let era =\n 0.779057273264 +\n fractionOfDay +\n 0.00273781191135448 * (daysSinceJ2000 + fractionOfDay);\n era = (era % 1.0) * CesiumMath.TWO_PI;\n\n const earthRotation = Matrix3.fromRotationZ(era, rotation2Scratch);\n\n // pseudoFixed to ICRF\n const pfToIcrf = Matrix3.multiply(matrixQ, earthRotation, rotation1Scratch);\n\n // Compute pole wander matrix\n const cosxp = Math.cos(eop.xPoleWander);\n const cosyp = Math.cos(eop.yPoleWander);\n const sinxp = Math.sin(eop.xPoleWander);\n const sinyp = Math.sin(eop.yPoleWander);\n\n let ttt = dayTT - j2000ttDays + secondTT / TimeConstants.SECONDS_PER_DAY;\n ttt /= 36525.0;\n\n // approximate sp value in rad\n const sp = (-47.0e-6 * ttt * CesiumMath.RADIANS_PER_DEGREE) / 3600.0;\n const cossp = Math.cos(sp);\n const sinsp = Math.sin(sp);\n\n const fToPfMtx = rotation2Scratch;\n fToPfMtx[0] = cosxp * cossp;\n fToPfMtx[1] = cosxp * sinsp;\n fToPfMtx[2] = sinxp;\n fToPfMtx[3] = -cosyp * sinsp + sinyp * sinxp * cossp;\n fToPfMtx[4] = cosyp * cossp + sinyp * sinxp * sinsp;\n fToPfMtx[5] = -sinyp * cosxp;\n fToPfMtx[6] = -sinyp * sinsp - cosyp * sinxp * cossp;\n fToPfMtx[7] = sinyp * cossp - cosyp * sinxp * sinsp;\n fToPfMtx[8] = cosyp * cosxp;\n\n return Matrix3.multiply(pfToIcrf, fToPfMtx, result);\n};\n\nconst pointToWindowCoordinatesTemp = new Cartesian4();\n\n/**\n * Transform a point from model coordinates to window coordinates.\n *\n * @param {Matrix4} modelViewProjectionMatrix The 4x4 model-view-projection matrix.\n * @param {Matrix4} viewportTransformation The 4x4 viewport transformation.\n * @param {Cartesian3} point The point to transform.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.\n */\nTransforms.pointToWindowCoordinates = function (\n modelViewProjectionMatrix,\n viewportTransformation,\n point,\n result\n) {\n result = Transforms.pointToGLWindowCoordinates(\n modelViewProjectionMatrix,\n viewportTransformation,\n point,\n result\n );\n result.y = 2.0 * viewportTransformation[5] - result.y;\n return result;\n};\n\n/**\n * @private\n */\nTransforms.pointToGLWindowCoordinates = function (\n modelViewProjectionMatrix,\n viewportTransformation,\n point,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(modelViewProjectionMatrix)) {\n throw new DeveloperError(\"modelViewProjectionMatrix is required.\");\n }\n\n if (!defined(viewportTransformation)) {\n throw new DeveloperError(\"viewportTransformation is required.\");\n }\n\n if (!defined(point)) {\n throw new DeveloperError(\"point is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian2();\n }\n\n const tmp = pointToWindowCoordinatesTemp;\n\n Matrix4.multiplyByVector(\n modelViewProjectionMatrix,\n Cartesian4.fromElements(point.x, point.y, point.z, 1, tmp),\n tmp\n );\n Cartesian4.multiplyByScalar(tmp, 1.0 / tmp.w, tmp);\n Matrix4.multiplyByVector(viewportTransformation, tmp, tmp);\n return Cartesian2.fromCartesian4(tmp, result);\n};\n\nconst normalScratch = new Cartesian3();\nconst rightScratch = new Cartesian3();\nconst upScratch = new Cartesian3();\n\n/**\n * Transform a position and velocity to a rotation matrix.\n *\n * @param {Cartesian3} position The position to transform.\n * @param {Cartesian3} velocity The velocity vector to transform.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.\n * @param {Matrix3} [result] The object onto which to store the result.\n * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided.\n */\nTransforms.rotationMatrixFromPositionVelocity = function (\n position,\n velocity,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(position)) {\n throw new DeveloperError(\"position is required.\");\n }\n\n if (!defined(velocity)) {\n throw new DeveloperError(\"velocity is required.\");\n }\n //>>includeEnd('debug');\n\n const normal = defaultValue(ellipsoid, Ellipsoid.WGS84).geodeticSurfaceNormal(\n position,\n normalScratch\n );\n let right = Cartesian3.cross(velocity, normal, rightScratch);\n\n if (Cartesian3.equalsEpsilon(right, Cartesian3.ZERO, CesiumMath.EPSILON6)) {\n right = Cartesian3.clone(Cartesian3.UNIT_X, right);\n }\n\n const up = Cartesian3.cross(right, velocity, upScratch);\n Cartesian3.normalize(up, up);\n Cartesian3.cross(velocity, up, right);\n Cartesian3.negate(right, right);\n Cartesian3.normalize(right, right);\n\n if (!defined(result)) {\n result = new Matrix3();\n }\n\n result[0] = velocity.x;\n result[1] = velocity.y;\n result[2] = velocity.z;\n result[3] = right.x;\n result[4] = right.y;\n result[5] = right.z;\n result[6] = up.x;\n result[7] = up.y;\n result[8] = up.z;\n\n return result;\n};\n\nconst swizzleMatrix = new Matrix4(\n 0.0,\n 0.0,\n 1.0,\n 0.0,\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 0.0,\n 1.0\n);\n\nconst scratchCartographic = new Cartographic();\nconst scratchCartesian3Projection = new Cartesian3();\nconst scratchCenter = new Cartesian3();\nconst scratchRotation = new Matrix3();\nconst scratchFromENU = new Matrix4();\nconst scratchToENU = new Matrix4();\n\n/**\n * @private\n */\nTransforms.basisTo2D = function (projection, matrix, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(projection)) {\n throw new DeveloperError(\"projection is required.\");\n }\n if (!defined(matrix)) {\n throw new DeveloperError(\"matrix is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const rtcCenter = Matrix4.getTranslation(matrix, scratchCenter);\n const ellipsoid = projection.ellipsoid;\n\n // Get the 2D Center\n const cartographic = ellipsoid.cartesianToCartographic(\n rtcCenter,\n scratchCartographic\n );\n const projectedPosition = projection.project(\n cartographic,\n scratchCartesian3Projection\n );\n Cartesian3.fromElements(\n projectedPosition.z,\n projectedPosition.x,\n projectedPosition.y,\n projectedPosition\n );\n\n // Assuming the instance are positioned in WGS84, invert the WGS84 transform to get the local transform and then convert to 2D\n const fromENU = Transforms.eastNorthUpToFixedFrame(\n rtcCenter,\n ellipsoid,\n scratchFromENU\n );\n const toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);\n const rotation = Matrix4.getMatrix3(matrix, scratchRotation);\n const local = Matrix4.multiplyByMatrix3(toENU, rotation, result);\n Matrix4.multiply(swizzleMatrix, local, result); // Swap x, y, z for 2D\n Matrix4.setTranslation(result, projectedPosition, result); // Use the projected center\n\n return result;\n};\n\n/**\n * @private\n */\nTransforms.wgs84To2DModelMatrix = function (projection, center, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(projection)) {\n throw new DeveloperError(\"projection is required.\");\n }\n if (!defined(center)) {\n throw new DeveloperError(\"center is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const ellipsoid = projection.ellipsoid;\n\n const fromENU = Transforms.eastNorthUpToFixedFrame(\n center,\n ellipsoid,\n scratchFromENU\n );\n const toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);\n\n const cartographic = ellipsoid.cartesianToCartographic(\n center,\n scratchCartographic\n );\n const projectedPosition = projection.project(\n cartographic,\n scratchCartesian3Projection\n );\n Cartesian3.fromElements(\n projectedPosition.z,\n projectedPosition.x,\n projectedPosition.y,\n projectedPosition\n );\n\n const translation = Matrix4.fromTranslation(\n projectedPosition,\n scratchFromENU\n );\n Matrix4.multiply(swizzleMatrix, toENU, result);\n Matrix4.multiply(translation, result, result);\n\n return result;\n};\nexport default Transforms;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport GeometryType from \"./GeometryType.js\";\nimport Matrix2 from \"./Matrix2.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport Transforms from \"./Transforms.js\";\n\n/**\n * A geometry representation with attributes forming vertices and optional index data\n * defining primitives. Geometries and an {@link Appearance}, which describes the shading,\n * can be assigned to a {@link Primitive} for visualization. A Primitive can\n * be created from many heterogeneous - in many cases - geometries for performance.\n *

\n * Geometries can be transformed and optimized using functions in {@link GeometryPipeline}.\n *

\n *\n * @alias Geometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {GeometryAttributes} options.attributes Attributes, which make up the geometry's vertices.\n * @param {PrimitiveType} [options.primitiveType=PrimitiveType.TRIANGLES] The type of primitives in the geometry.\n * @param {Uint16Array|Uint32Array} [options.indices] Optional index data that determines the primitives in the geometry.\n * @param {BoundingSphere} [options.boundingSphere] An optional bounding sphere that fully enclosed the geometry.\n *\n * @see PolygonGeometry\n * @see RectangleGeometry\n * @see EllipseGeometry\n * @see CircleGeometry\n * @see WallGeometry\n * @see SimplePolylineGeometry\n * @see BoxGeometry\n * @see EllipsoidGeometry\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}\n *\n * @example\n * // Create geometry with a position attribute and indexed lines.\n * const positions = new Float64Array([\n * 0.0, 0.0, 0.0,\n * 7500000.0, 0.0, 0.0,\n * 0.0, 7500000.0, 0.0\n * ]);\n *\n * const geometry = new Cesium.Geometry({\n * attributes : {\n * position : new Cesium.GeometryAttribute({\n * componentDatatype : Cesium.ComponentDatatype.DOUBLE,\n * componentsPerAttribute : 3,\n * values : positions\n * })\n * },\n * indices : new Uint16Array([0, 1, 1, 2, 2, 0]),\n * primitiveType : Cesium.PrimitiveType.LINES,\n * boundingSphere : Cesium.BoundingSphere.fromVertices(positions)\n * });\n */\nfunction Geometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.attributes\", options.attributes);\n //>>includeEnd('debug');\n\n /**\n * Attributes, which make up the geometry's vertices. Each property in this object corresponds to a\n * {@link GeometryAttribute} containing the attribute's data.\n *

\n * Attributes are always stored non-interleaved in a Geometry.\n *

\n *

\n * There are reserved attribute names with well-known semantics. The following attributes\n * are created by a Geometry (depending on the provided {@link VertexFormat}.\n *

    \n *
  • position - 3D vertex position. 64-bit floating-point (for precision). 3 components per attribute. See {@link VertexFormat#position}.
  • \n *
  • normal - Normal (normalized), commonly used for lighting. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#normal}.
  • \n *
  • st - 2D texture coordinate. 32-bit floating-point. 2 components per attribute. See {@link VertexFormat#st}.
  • \n *
  • bitangent - Bitangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#bitangent}.
  • \n *
  • tangent - Tangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#tangent}.
  • \n *
\n *

\n *

\n * The following attribute names are generally not created by a Geometry, but are added\n * to a Geometry by a {@link Primitive} or {@link GeometryPipeline} functions to prepare\n * the geometry for rendering.\n *

    \n *
  • position3DHigh - High 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.
  • \n *
  • position3DLow - Low 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.
  • \n *
  • position3DHigh - High 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.
  • \n *
  • position2DLow - Low 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.
  • \n *
  • color - RGBA color (normalized) usually from {@link GeometryInstance#color}. 32-bit floating-point. 4 components per attribute.
  • \n *
  • pickColor - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.
  • \n *
\n *

\n *\n * @type GeometryAttributes\n *\n * @default undefined\n *\n *\n * @example\n * geometry.attributes.position = new Cesium.GeometryAttribute({\n * componentDatatype : Cesium.ComponentDatatype.FLOAT,\n * componentsPerAttribute : 3,\n * values : new Float32Array(0)\n * });\n *\n * @see GeometryAttribute\n * @see VertexFormat\n */\n this.attributes = options.attributes;\n\n /**\n * Optional index data that - along with {@link Geometry#primitiveType} -\n * determines the primitives in the geometry.\n *\n * @type {Array}\n *\n * @default undefined\n */\n this.indices = options.indices;\n\n /**\n * The type of primitives in the geometry. This is most often {@link PrimitiveType.TRIANGLES},\n * but can varying based on the specific geometry.\n *\n * @type PrimitiveType\n *\n * @default undefined\n */\n this.primitiveType = defaultValue(\n options.primitiveType,\n PrimitiveType.TRIANGLES\n );\n\n /**\n * An optional bounding sphere that fully encloses the geometry. This is\n * commonly used for culling.\n *\n * @type BoundingSphere\n *\n * @default undefined\n */\n this.boundingSphere = options.boundingSphere;\n\n /**\n * @private\n */\n this.geometryType = defaultValue(options.geometryType, GeometryType.NONE);\n\n /**\n * @private\n */\n this.boundingSphereCV = options.boundingSphereCV;\n\n /**\n * Used for computing the bounding sphere for geometry using the applyOffset vertex attribute\n * @private\n */\n this.offsetAttribute = options.offsetAttribute;\n}\n\n/**\n * Computes the number of vertices in a geometry. The runtime is linear with\n * respect to the number of attributes in a vertex, not the number of vertices.\n *\n * @param {Geometry} geometry The geometry.\n * @returns {number} The number of vertices in the geometry.\n *\n * @example\n * const numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);\n */\nGeometry.computeNumberOfVertices = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"geometry\", geometry);\n //>>includeEnd('debug');\n\n let numberOfVertices = -1;\n for (const property in geometry.attributes) {\n if (\n geometry.attributes.hasOwnProperty(property) &&\n defined(geometry.attributes[property]) &&\n defined(geometry.attributes[property].values)\n ) {\n const attribute = geometry.attributes[property];\n const num = attribute.values.length / attribute.componentsPerAttribute;\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices !== num && numberOfVertices !== -1) {\n throw new DeveloperError(\n \"All attribute lists must have the same number of attributes.\"\n );\n }\n //>>includeEnd('debug');\n numberOfVertices = num;\n }\n }\n\n return numberOfVertices;\n};\n\nconst rectangleCenterScratch = new Cartographic();\nconst enuCenterScratch = new Cartesian3();\nconst fixedFrameToEnuScratch = new Matrix4();\nconst boundingRectanglePointsCartographicScratch = [\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n];\nconst boundingRectanglePointsEnuScratch = [\n new Cartesian2(),\n new Cartesian2(),\n new Cartesian2(),\n];\nconst points2DScratch = [new Cartesian2(), new Cartesian2(), new Cartesian2()];\nconst pointEnuScratch = new Cartesian3();\nconst enuRotationScratch = new Quaternion();\nconst enuRotationMatrixScratch = new Matrix4();\nconst rotation2DScratch = new Matrix2();\n\n/**\n * For remapping texture coordinates when rendering GroundPrimitives with materials.\n * GroundPrimitive texture coordinates are computed to align with the cartographic coordinate system on the globe.\n * However, EllipseGeometry, RectangleGeometry, and PolygonGeometry all bake rotations to per-vertex texture coordinates\n * using different strategies.\n *\n * This method is used by EllipseGeometry and PolygonGeometry to approximate the same visual effect.\n * We encapsulate rotation and scale by computing a \"transformed\" texture coordinate system and computing\n * a set of reference points from which \"cartographic\" texture coordinates can be remapped to the \"transformed\"\n * system using distances to lines in 2D.\n *\n * This approximation becomes less accurate as the covered area increases, especially for GroundPrimitives near the poles,\n * but is generally reasonable for polygons and ellipses around the size of USA states.\n *\n * RectangleGeometry has its own version of this method that computes remapping coordinates using cartographic space\n * as an intermediary instead of local ENU, which is more accurate for large-area rectangles.\n *\n * @param {Cartesian3[]} positions Array of positions outlining the geometry\n * @param {number} stRotation Texture coordinate rotation.\n * @param {Ellipsoid} ellipsoid Ellipsoid for projecting and generating local vectors.\n * @param {Rectangle} boundingRectangle Bounding rectangle around the positions.\n * @returns {number[]} An array of 6 numbers specifying [minimum point, u extent, v extent] as points in the \"cartographic\" system.\n * @private\n */\nGeometry._textureCoordinateRotationPoints = function (\n positions,\n stRotation,\n ellipsoid,\n boundingRectangle\n) {\n let i;\n\n // Create a local east-north-up coordinate system centered on the polygon's bounding rectangle.\n // Project the southwest, northwest, and southeast corners of the bounding rectangle into the plane of ENU as 2D points.\n // These are the equivalents of (0,0), (0,1), and (1,0) in the texture coordinate system computed in ShadowVolumeAppearanceFS,\n // aka \"ENU texture space.\"\n const rectangleCenter = Rectangle.center(\n boundingRectangle,\n rectangleCenterScratch\n );\n const enuCenter = Cartographic.toCartesian(\n rectangleCenter,\n ellipsoid,\n enuCenterScratch\n );\n const enuToFixedFrame = Transforms.eastNorthUpToFixedFrame(\n enuCenter,\n ellipsoid,\n fixedFrameToEnuScratch\n );\n const fixedFrameToEnu = Matrix4.inverse(\n enuToFixedFrame,\n fixedFrameToEnuScratch\n );\n\n const boundingPointsEnu = boundingRectanglePointsEnuScratch;\n const boundingPointsCarto = boundingRectanglePointsCartographicScratch;\n\n boundingPointsCarto[0].longitude = boundingRectangle.west;\n boundingPointsCarto[0].latitude = boundingRectangle.south;\n\n boundingPointsCarto[1].longitude = boundingRectangle.west;\n boundingPointsCarto[1].latitude = boundingRectangle.north;\n\n boundingPointsCarto[2].longitude = boundingRectangle.east;\n boundingPointsCarto[2].latitude = boundingRectangle.south;\n\n let posEnu = pointEnuScratch;\n\n for (i = 0; i < 3; i++) {\n Cartographic.toCartesian(boundingPointsCarto[i], ellipsoid, posEnu);\n posEnu = Matrix4.multiplyByPointAsVector(fixedFrameToEnu, posEnu, posEnu);\n boundingPointsEnu[i].x = posEnu.x;\n boundingPointsEnu[i].y = posEnu.y;\n }\n\n // Rotate each point in the polygon around the up vector in the ENU by -stRotation and project into ENU as 2D.\n // Compute the bounding box of these rotated points in the 2D ENU plane.\n // Rotate the corners back by stRotation, then compute their equivalents in the ENU texture space using the corners computed earlier.\n const rotation = Quaternion.fromAxisAngle(\n Cartesian3.UNIT_Z,\n -stRotation,\n enuRotationScratch\n );\n const textureMatrix = Matrix3.fromQuaternion(\n rotation,\n enuRotationMatrixScratch\n );\n\n const positionsLength = positions.length;\n let enuMinX = Number.POSITIVE_INFINITY;\n let enuMinY = Number.POSITIVE_INFINITY;\n let enuMaxX = Number.NEGATIVE_INFINITY;\n let enuMaxY = Number.NEGATIVE_INFINITY;\n for (i = 0; i < positionsLength; i++) {\n posEnu = Matrix4.multiplyByPointAsVector(\n fixedFrameToEnu,\n positions[i],\n posEnu\n );\n posEnu = Matrix3.multiplyByVector(textureMatrix, posEnu, posEnu);\n\n enuMinX = Math.min(enuMinX, posEnu.x);\n enuMinY = Math.min(enuMinY, posEnu.y);\n enuMaxX = Math.max(enuMaxX, posEnu.x);\n enuMaxY = Math.max(enuMaxY, posEnu.y);\n }\n\n const toDesiredInComputed = Matrix2.fromRotation(\n stRotation,\n rotation2DScratch\n );\n\n const points2D = points2DScratch;\n points2D[0].x = enuMinX;\n points2D[0].y = enuMinY;\n\n points2D[1].x = enuMinX;\n points2D[1].y = enuMaxY;\n\n points2D[2].x = enuMaxX;\n points2D[2].y = enuMinY;\n\n const boundingEnuMin = boundingPointsEnu[0];\n const boundingPointsWidth = boundingPointsEnu[2].x - boundingEnuMin.x;\n const boundingPointsHeight = boundingPointsEnu[1].y - boundingEnuMin.y;\n\n for (i = 0; i < 3; i++) {\n const point2D = points2D[i];\n // rotate back\n Matrix2.multiplyByVector(toDesiredInComputed, point2D, point2D);\n\n // Convert point into east-north texture coordinate space\n point2D.x = (point2D.x - boundingEnuMin.x) / boundingPointsWidth;\n point2D.y = (point2D.y - boundingEnuMin.y) / boundingPointsHeight;\n }\n\n const minXYCorner = points2D[0];\n const maxYCorner = points2D[1];\n const maxXCorner = points2D[2];\n const result = new Array(6);\n Cartesian2.pack(minXYCorner, result);\n Cartesian2.pack(maxYCorner, result, 2);\n Cartesian2.pack(maxXCorner, result, 4);\n\n return result;\n};\nexport default Geometry;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Values and type information for geometry attributes. A {@link Geometry}\n * generally contains one or more attributes. All attributes together form\n * the geometry's vertices.\n *\n * @alias GeometryAttribute\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.\n * @param {number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.\n * @param {boolean} [options.normalize=false] When true and componentDatatype is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n * @param {number[]|Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} [options.values] The values for the attributes stored in a typed array.\n *\n * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.\n *\n *\n * @example\n * const geometry = new Cesium.Geometry({\n * attributes : {\n * position : new Cesium.GeometryAttribute({\n * componentDatatype : Cesium.ComponentDatatype.FLOAT,\n * componentsPerAttribute : 3,\n * values : new Float32Array([\n * 0.0, 0.0, 0.0,\n * 7500000.0, 0.0, 0.0,\n * 0.0, 7500000.0, 0.0\n * ])\n * })\n * },\n * primitiveType : Cesium.PrimitiveType.LINE_LOOP\n * });\n *\n * @see Geometry\n */\nfunction GeometryAttribute(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.componentDatatype)) {\n throw new DeveloperError(\"options.componentDatatype is required.\");\n }\n if (!defined(options.componentsPerAttribute)) {\n throw new DeveloperError(\"options.componentsPerAttribute is required.\");\n }\n if (\n options.componentsPerAttribute < 1 ||\n options.componentsPerAttribute > 4\n ) {\n throw new DeveloperError(\n \"options.componentsPerAttribute must be between 1 and 4.\"\n );\n }\n if (!defined(options.values)) {\n throw new DeveloperError(\"options.values is required.\");\n }\n //>>includeEnd('debug');\n\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link GeometryAttribute#values}.\n *\n * @type {ComponentDatatype}\n *\n * @default undefined\n */\n this.componentDatatype = options.componentDatatype;\n\n /**\n * A number between 1 and 4 that defines the number of components in an attributes.\n * For example, a position attribute with x, y, and z components would have 3 as\n * shown in the code example.\n *\n * @type {number}\n *\n * @default undefined\n *\n * @example\n * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;\n * attribute.componentsPerAttribute = 3;\n * attribute.values = new Float32Array([\n * 0.0, 0.0, 0.0,\n * 7500000.0, 0.0, 0.0,\n * 0.0, 7500000.0, 0.0\n * ]);\n */\n this.componentsPerAttribute = options.componentsPerAttribute;\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *

\n * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.\n *

\n *\n * @type {boolean}\n *\n * @default false\n *\n * @example\n * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;\n * attribute.componentsPerAttribute = 4;\n * attribute.normalize = true;\n * attribute.values = new Uint8Array([\n * Cesium.Color.floatToByte(color.red),\n * Cesium.Color.floatToByte(color.green),\n * Cesium.Color.floatToByte(color.blue),\n * Cesium.Color.floatToByte(color.alpha)\n * ]);\n */\n this.normalize = defaultValue(options.normalize, false);\n\n /**\n * The values for the attributes stored in a typed array. In the code example,\n * every three elements in values defines one attributes since\n * componentsPerAttribute is 3.\n *\n * @type {number[]|Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array}\n *\n * @default undefined\n *\n * @example\n * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;\n * attribute.componentsPerAttribute = 3;\n * attribute.values = new Float32Array([\n * 0.0, 0.0, 0.0,\n * 7500000.0, 0.0, 0.0,\n * 0.0, 7500000.0, 0.0\n * ]);\n */\n this.values = options.values;\n}\nexport default GeometryAttribute;\n", "import defined from \"./defined.js\";\n\n/**\n * Describes a compressed texture and contains a compressed texture buffer.\n * @alias CompressedTextureBuffer\n * @constructor\n *\n * @param {PixelFormat} internalFormat The pixel format of the compressed texture.\n * @param {PixelDatatype} pixelDatatype The pixel datatype of the compressed texture.\n * @param {number} width The width of the texture.\n * @param {number} height The height of the texture.\n * @param {Uint8Array} buffer The compressed texture buffer.\n */\nfunction CompressedTextureBuffer(\n internalFormat,\n pixelDatatype,\n width,\n height,\n buffer\n) {\n this._format = internalFormat;\n this._datatype = pixelDatatype;\n this._width = width;\n this._height = height;\n this._buffer = buffer;\n}\n\nObject.defineProperties(CompressedTextureBuffer.prototype, {\n /**\n * The format of the compressed texture.\n * @type {PixelFormat}\n * @readonly\n * @memberof CompressedTextureBuffer.prototype\n */\n internalFormat: {\n get: function () {\n return this._format;\n },\n },\n /**\n * The datatype of the compressed texture.\n * @type {PixelDatatype}\n * @readonly\n * @memberof CompressedTextureBuffer.prototype\n */\n pixelDatatype: {\n get: function () {\n return this._datatype;\n },\n },\n /**\n * The width of the texture.\n * @type {number}\n * @readonly\n * @memberof CompressedTextureBuffer.prototype\n */\n width: {\n get: function () {\n return this._width;\n },\n },\n /**\n * The height of the texture.\n * @type {number}\n * @readonly\n * @memberof CompressedTextureBuffer.prototype\n */\n height: {\n get: function () {\n return this._height;\n },\n },\n /**\n * The compressed texture buffer.\n * @type {Uint8Array}\n * @readonly\n * @memberof CompressedTextureBuffer.prototype\n */\n bufferView: {\n get: function () {\n return this._buffer;\n },\n },\n});\n\n/**\n * Creates a shallow clone of a compressed texture buffer.\n *\n * @param {CompressedTextureBuffer} object The compressed texture buffer to be cloned.\n * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.\n */\nCompressedTextureBuffer.clone = function (object) {\n if (!defined(object)) {\n return undefined;\n }\n\n return new CompressedTextureBuffer(\n object._format,\n object._datatype,\n object._width,\n object._height,\n object._buffer\n );\n};\n\n/**\n * Creates a shallow clone of this compressed texture buffer.\n *\n * @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.\n */\nCompressedTextureBuffer.prototype.clone = function () {\n return CompressedTextureBuffer.clone(this);\n};\nexport default CompressedTextureBuffer;\n", "import Uri from \"urijs\";\nimport buildModuleUrl from \"./buildModuleUrl.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defer from \"./defer.js\";\nimport defined from \"./defined.js\";\nimport destroyObject from \"./destroyObject.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Event from \"./Event.js\";\nimport FeatureDetection from \"./FeatureDetection.js\";\nimport isCrossOriginUrl from \"./isCrossOriginUrl.js\";\nimport Resource from \"./Resource.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\nfunction canTransferArrayBuffer() {\n if (!defined(TaskProcessor._canTransferArrayBuffer)) {\n const worker = new Worker(\n getWorkerUrl(\"Workers/transferTypedArrayTest.js\")\n );\n worker.postMessage = defaultValue(\n worker.webkitPostMessage,\n worker.postMessage\n );\n\n const value = 99;\n const array = new Int8Array([value]);\n\n try {\n // postMessage might fail with a DataCloneError\n // if transferring array buffers is not supported.\n worker.postMessage(\n {\n array: array,\n },\n [array.buffer]\n );\n } catch (e) {\n TaskProcessor._canTransferArrayBuffer = false;\n return TaskProcessor._canTransferArrayBuffer;\n }\n\n const deferred = defer();\n\n worker.onmessage = function (event) {\n const array = event.data.array;\n\n // some versions of Firefox silently fail to transfer typed arrays.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=841904\n // Check to make sure the value round-trips successfully.\n const result = defined(array) && array[0] === value;\n deferred.resolve(result);\n\n worker.terminate();\n\n TaskProcessor._canTransferArrayBuffer = result;\n };\n\n TaskProcessor._canTransferArrayBuffer = deferred.promise;\n }\n\n return TaskProcessor._canTransferArrayBuffer;\n}\n\nconst taskCompletedEvent = new Event();\n\nfunction completeTask(processor, data) {\n --processor._activeTasks;\n\n const id = data.id;\n if (!defined(id)) {\n // This is not one of ours.\n return;\n }\n\n const deferreds = processor._deferreds;\n const deferred = deferreds[id];\n\n if (defined(data.error)) {\n let error = data.error;\n if (error.name === \"RuntimeError\") {\n error = new RuntimeError(data.error.message);\n error.stack = data.error.stack;\n } else if (error.name === \"DeveloperError\") {\n error = new DeveloperError(data.error.message);\n error.stack = data.error.stack;\n }\n taskCompletedEvent.raiseEvent(error);\n deferred.reject(error);\n } else {\n taskCompletedEvent.raiseEvent();\n deferred.resolve(data.result);\n }\n\n delete deferreds[id];\n}\n\nfunction getWorkerUrl(moduleID) {\n let url = buildModuleUrl(moduleID);\n\n if (isCrossOriginUrl(url)) {\n //to load cross-origin, create a shim worker from a blob URL\n const script = `importScripts(\"${url}\");`;\n\n let blob;\n try {\n blob = new Blob([script], {\n type: \"application/javascript\",\n });\n } catch (e) {\n const BlobBuilder =\n window.BlobBuilder ||\n window.WebKitBlobBuilder ||\n window.MozBlobBuilder ||\n window.MSBlobBuilder;\n const blobBuilder = new BlobBuilder();\n blobBuilder.append(script);\n blob = blobBuilder.getBlob(\"application/javascript\");\n }\n\n const URL = window.URL || window.webkitURL;\n url = URL.createObjectURL(blob);\n }\n\n return url;\n}\n\nlet bootstrapperUrlResult;\nfunction getBootstrapperUrl() {\n if (!defined(bootstrapperUrlResult)) {\n bootstrapperUrlResult = getWorkerUrl(\"Workers/cesiumWorkerBootstrapper.js\");\n }\n return bootstrapperUrlResult;\n}\n\nfunction createWorker(processor) {\n const worker = new Worker(getBootstrapperUrl());\n worker.postMessage = defaultValue(\n worker.webkitPostMessage,\n worker.postMessage\n );\n\n const bootstrapMessage = {\n loaderConfig: {\n paths: {\n Workers: buildModuleUrl(\"Workers\"),\n },\n baseUrl: buildModuleUrl.getCesiumBaseUrl().url,\n },\n workerModule: processor._workerPath,\n };\n\n worker.postMessage(bootstrapMessage);\n worker.onmessage = function (event) {\n completeTask(processor, event.data);\n };\n\n return worker;\n}\n\nfunction getWebAssemblyLoaderConfig(processor, wasmOptions) {\n const config = {\n modulePath: undefined,\n wasmBinaryFile: undefined,\n wasmBinary: undefined,\n };\n\n // Web assembly not supported, use fallback js module if provided\n if (!FeatureDetection.supportsWebAssembly()) {\n if (!defined(wasmOptions.fallbackModulePath)) {\n throw new RuntimeError(\n `This browser does not support Web Assembly, and no backup module was provided for ${processor._workerPath}`\n );\n }\n\n config.modulePath = buildModuleUrl(wasmOptions.fallbackModulePath);\n return Promise.resolve(config);\n }\n\n config.modulePath = buildModuleUrl(wasmOptions.modulePath);\n config.wasmBinaryFile = buildModuleUrl(wasmOptions.wasmBinaryFile);\n\n return Resource.fetchArrayBuffer({\n url: config.wasmBinaryFile,\n }).then(function (arrayBuffer) {\n config.wasmBinary = arrayBuffer;\n return config;\n });\n}\n\n/**\n * A wrapper around a web worker that allows scheduling tasks for a given worker,\n * returning results asynchronously via a promise.\n *\n * The Worker is not constructed until a task is scheduled.\n *\n * @alias TaskProcessor\n * @constructor\n *\n * @param {string} workerPath The Url to the worker. This can either be an absolute path or relative to the Cesium Workers folder.\n * @param {number} [maximumActiveTasks=Number.POSITIVE_INFINITY] The maximum number of active tasks. Once exceeded,\n * scheduleTask will not queue any more tasks, allowing\n * work to be rescheduled in future frames.\n */\nfunction TaskProcessor(workerPath, maximumActiveTasks) {\n const uri = new Uri(workerPath);\n this._workerPath =\n uri.scheme().length !== 0 && uri.fragment().length === 0\n ? workerPath\n : TaskProcessor._workerModulePrefix + workerPath;\n this._maximumActiveTasks = defaultValue(\n maximumActiveTasks,\n Number.POSITIVE_INFINITY\n );\n this._activeTasks = 0;\n this._deferreds = {};\n this._nextID = 0;\n}\n\nconst emptyTransferableObjectArray = [];\n\n/**\n * Schedule a task to be processed by the web worker asynchronously. If there are currently more\n * tasks active than the maximum set by the constructor, will immediately return undefined.\n * Otherwise, returns a promise that will resolve to the result posted back by the worker when\n * finished.\n *\n * @param {object} parameters Any input data that will be posted to the worker.\n * @param {Object[]} [transferableObjects] An array of objects contained in parameters that should be\n * transferred to the worker instead of copied.\n * @returns {Promise|undefined} Either a promise that will resolve to the result when available, or undefined\n * if there are too many active tasks,\n *\n * @example\n * const taskProcessor = new Cesium.TaskProcessor('myWorkerPath');\n * const promise = taskProcessor.scheduleTask({\n * someParameter : true,\n * another : 'hello'\n * });\n * if (!Cesium.defined(promise)) {\n * // too many active tasks - try again later\n * } else {\n * promise.then(function(result) {\n * // use the result of the task\n * });\n * }\n */\nTaskProcessor.prototype.scheduleTask = function (\n parameters,\n transferableObjects\n) {\n if (!defined(this._worker)) {\n this._worker = createWorker(this);\n }\n\n if (this._activeTasks >= this._maximumActiveTasks) {\n return undefined;\n }\n\n ++this._activeTasks;\n\n const processor = this;\n return Promise.resolve(canTransferArrayBuffer()).then(function (\n canTransferArrayBuffer\n ) {\n if (!defined(transferableObjects)) {\n transferableObjects = emptyTransferableObjectArray;\n } else if (!canTransferArrayBuffer) {\n transferableObjects.length = 0;\n }\n\n const id = processor._nextID++;\n const deferred = defer();\n processor._deferreds[id] = deferred;\n\n processor._worker.postMessage(\n {\n id: id,\n parameters: parameters,\n canTransferArrayBuffer: canTransferArrayBuffer,\n },\n transferableObjects\n );\n\n return deferred.promise;\n });\n};\n\n/**\n * Posts a message to a web worker with configuration to initialize loading\n * and compiling a web assembly module asychronously, as well as an optional\n * fallback JavaScript module to use if Web Assembly is not supported.\n *\n * @param {object} [webAssemblyOptions] An object with the following properties:\n * @param {string} [webAssemblyOptions.modulePath] The path of the web assembly JavaScript wrapper module.\n * @param {string} [webAssemblyOptions.wasmBinaryFile] The path of the web assembly binary file.\n * @param {string} [webAssemblyOptions.fallbackModulePath] The path of the fallback JavaScript module to use if web assembly is not supported.\n * @returns {Promise} A promise that resolves to the result when the web worker has loaded and compiled the web assembly module and is ready to process tasks.\n */\nTaskProcessor.prototype.initWebAssemblyModule = function (webAssemblyOptions) {\n if (!defined(this._worker)) {\n this._worker = createWorker(this);\n }\n\n const deferred = defer();\n const processor = this;\n const worker = this._worker;\n getWebAssemblyLoaderConfig(this, webAssemblyOptions).then(function (\n wasmConfig\n ) {\n return Promise.resolve(canTransferArrayBuffer()).then(function (\n canTransferArrayBuffer\n ) {\n let transferableObjects;\n const binary = wasmConfig.wasmBinary;\n if (defined(binary) && canTransferArrayBuffer) {\n transferableObjects = [binary];\n }\n\n worker.onmessage = function (event) {\n worker.onmessage = function (event) {\n completeTask(processor, event.data);\n };\n\n deferred.resolve(event.data);\n };\n\n worker.postMessage(\n { webAssemblyConfig: wasmConfig },\n transferableObjects\n );\n });\n });\n\n return deferred.promise;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see TaskProcessor#destroy\n */\nTaskProcessor.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys this object. This will immediately terminate the Worker.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n */\nTaskProcessor.prototype.destroy = function () {\n if (defined(this._worker)) {\n this._worker.terminate();\n }\n return destroyObject(this);\n};\n\n/**\n * An event that's raised when a task is completed successfully. Event handlers are passed\n * the error object is a task fails.\n *\n * @type {Event}\n *\n * @private\n */\nTaskProcessor.taskCompletedEvent = taskCompletedEvent;\n\n// exposed for testing purposes\nTaskProcessor._defaultWorkerModulePrefix = \"Workers/\";\nTaskProcessor._workerModulePrefix = TaskProcessor._defaultWorkerModulePrefix;\nTaskProcessor._canTransferArrayBuffer = undefined;\nexport default TaskProcessor;\n", "import Check from \"./Check.js\";\nimport CompressedTextureBuffer from \"./CompressedTextureBuffer.js\";\nimport defined from \"./defined.js\";\nimport TaskProcessor from \"./TaskProcessor.js\";\n\n/**\n * Transcodes KTX2 textures using web workers.\n *\n * @private\n */\nfunction KTX2Transcoder() {}\n\nKTX2Transcoder._transcodeTaskProcessor = new TaskProcessor(\n \"transcodeKTX2\",\n Number.POSITIVE_INFINITY // KTX2 transcoding is used in place of Resource.fetchImage, so it can't reject as \"just soooo busy right now\"\n);\n\nKTX2Transcoder._readyPromise = undefined;\n\nfunction makeReadyPromise() {\n const readyPromise = KTX2Transcoder._transcodeTaskProcessor\n .initWebAssemblyModule({\n modulePath: \"ThirdParty/Workers/basis_transcoder.js\",\n wasmBinaryFile: \"ThirdParty/basis_transcoder.wasm\",\n })\n .then(function () {\n return KTX2Transcoder._transcodeTaskProcessor;\n });\n KTX2Transcoder._readyPromise = readyPromise;\n}\n\nKTX2Transcoder.transcode = function (ktx2Buffer, supportedTargetFormats) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"supportedTargetFormats\", supportedTargetFormats);\n //>>includeEnd('debug');\n\n if (!defined(KTX2Transcoder._readyPromise)) {\n makeReadyPromise();\n }\n\n return KTX2Transcoder._readyPromise\n .then(function (taskProcessor) {\n let parameters;\n if (ktx2Buffer instanceof ArrayBuffer) {\n const view = new Uint8Array(ktx2Buffer);\n parameters = {\n supportedTargetFormats: supportedTargetFormats,\n ktx2Buffer: view,\n };\n return taskProcessor.scheduleTask(parameters, [ktx2Buffer]);\n }\n parameters = {\n supportedTargetFormats: supportedTargetFormats,\n ktx2Buffer: ktx2Buffer,\n };\n return taskProcessor.scheduleTask(parameters, [ktx2Buffer.buffer]);\n })\n .then(function (result) {\n const levelsLength = result.length;\n const faceKeys = Object.keys(result[0]);\n const faceKeysLength = faceKeys.length;\n\n let i;\n for (i = 0; i < levelsLength; i++) {\n const faces = result[i];\n for (let j = 0; j < faceKeysLength; j++) {\n const face = faces[faceKeys[j]];\n faces[faceKeys[j]] = new CompressedTextureBuffer(\n face.internalFormat,\n face.datatype,\n face.width,\n face.height,\n face.levelBuffer\n );\n }\n }\n\n // Cleaning up parsed result if it's a single image\n if (faceKeysLength === 1) {\n for (i = 0; i < levelsLength; ++i) {\n result[i] = result[i][faceKeys[0]];\n }\n\n if (levelsLength === 1) {\n result = result[0];\n }\n }\n return result;\n })\n .catch(function (error) {\n throw error;\n });\n};\n\nexport default KTX2Transcoder;\n", "import Check from \"./Check.js\";\nimport Resource from \"./Resource.js\";\nimport KTX2Transcoder from \"./KTX2Transcoder.js\";\n\n/**\n * Stores the supported formats that KTX2 can transcode to. Called during context creation.\n *\n * @param {boolean} s3tc Whether or not S3TC is supported\n * @param {boolean} pvrtc Whether or not PVRTC is supported\n * @param {boolean} astc Whether or not ASTC is supported\n * @param {boolean} etc Whether or not ETC is supported\n * @param {boolean} etc1 Whether or not ETC1 is supported\n * @param {boolean} bc7 Whether or not BC7 is supported\n * @private\n */\nlet supportedTranscoderFormats;\n\nloadKTX2.setKTX2SupportedFormats = function (\n s3tc,\n pvrtc,\n astc,\n etc,\n etc1,\n bc7\n) {\n supportedTranscoderFormats = {\n s3tc: s3tc,\n pvrtc: pvrtc,\n astc: astc,\n etc: etc,\n etc1: etc1,\n bc7: bc7,\n };\n};\n\n/**\n * Asynchronously loads and parses the given URL to a KTX2 file or parses the raw binary data of a KTX2 file.\n * Returns a promise that will resolve to an object containing the image buffer, width, height, and format once loaded,\n * or reject if the URL failed to load or failed to parse the data. The data is loaded\n * using XMLHttpRequest, which means that in order to make requests to another origin,\n * the server must have Cross-Origin Resource sharing (CORS) headers enabled.\n *

\n * The following are part of the KTX2 format specification but are not supported:\n *

    \n *
  • Metadata
  • \n *
  • 3D textures
  • \n *
  • Texture Arrays
  • \n *
  • Video
  • \n *
\n *

\n *\n * @function loadKTX2\n *\n * @param {Resource|string|ArrayBuffer} resourceOrUrlOrBuffer The URL of the binary data or an ArrayBuffer.\n * @returns {Promise|undefined} A promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority.\n *\n * @exception {RuntimeError} Invalid KTX2 file.\n * @exception {RuntimeError} KTX2 texture arrays are not supported.\n * @exception {RuntimeError} KTX2 3D textures are unsupported.\n * @exception {RuntimeError} No transcoding format target available for ETC1S compressed ktx2s.\n * @exception {RuntimeError} No transcoding format target available for UASTC compressed ktx2s.\n * @exception {RuntimeError} startTranscoding() failed.\n * @exception {RuntimeError} transcodeImage() failed.\n *\n * @example\n * // load a single URL asynchronously\n * Cesium.loadKTX2('some/url').then(function (ktx2Data) {\n * const width = ktx2Data.width;\n * const height = ktx2Data.height;\n * const format = ktx2Data.internalFormat;\n * const arrayBufferView = ktx2Data.bufferView;\n * // use the data to create a texture\n * }).catch(function (error) {\n * // an error occurred.\n * });\n *\n * @see {@link https://github.com/KhronosGroup/KTX-Specification|KTX file format}\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n * @private\n */\nfunction loadKTX2(resourceOrUrlOrBuffer) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"resourceOrUrlOrBuffer\", resourceOrUrlOrBuffer);\n //>>includeEnd('debug');\n\n let loadPromise;\n if (\n resourceOrUrlOrBuffer instanceof ArrayBuffer ||\n ArrayBuffer.isView(resourceOrUrlOrBuffer)\n ) {\n loadPromise = Promise.resolve(resourceOrUrlOrBuffer);\n } else {\n const resource = Resource.createIfNeeded(resourceOrUrlOrBuffer);\n loadPromise = resource.fetchArrayBuffer();\n }\n\n // load module then return\n return loadPromise.then(function (data) {\n return KTX2Transcoder.transcode(data, supportedTranscoderFormats);\n });\n}\n\nexport default loadKTX2;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\n\n/**\n * @private\n */\nfunction CubeMapFace(\n context,\n texture,\n textureTarget,\n targetFace,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n) {\n this._context = context;\n this._texture = texture;\n this._textureTarget = textureTarget;\n this._targetFace = targetFace;\n this._pixelDatatype = pixelDatatype;\n this._internalFormat = internalFormat;\n this._pixelFormat = pixelFormat;\n this._size = size;\n this._preMultiplyAlpha = preMultiplyAlpha;\n this._flipY = flipY;\n this._initialized = initialized;\n}\n\nObject.defineProperties(CubeMapFace.prototype, {\n pixelFormat: {\n get: function () {\n return this._pixelFormat;\n },\n },\n pixelDatatype: {\n get: function () {\n return this._pixelDatatype;\n },\n },\n _target: {\n get: function () {\n return this._targetFace;\n },\n },\n});\n\n/**\n * Copies texels from the source to the cubemap's face.\n * @param {object} options Object with the following properties:\n * @param {object} options.source The source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, {@link HTMLVideoElement},\n * or an object with a width, height, and arrayBufferView properties.\n * @param {number} [options.xOffset=0] An offset in the x direction in the cubemap where copying begins.\n * @param {number} [options.yOffset=0] An offset in the y direction in the cubemap where copying begins.\n * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the texture will be ignored.\n * @exception {DeveloperError} xOffset must be greater than or equal to zero.\n * @exception {DeveloperError} yOffset must be greater than or equal to zero.\n * @exception {DeveloperError} xOffset + source.width must be less than or equal to width.\n * @exception {DeveloperError} yOffset + source.height must be less than or equal to height.\n * @exception {DeveloperError} This CubeMap was destroyed, i.e., destroy() was called.\n *\n * @example\n * // Create a cubemap with 1x1 faces, and make the +x face red.\n * const cubeMap = new CubeMap({\n * context : context\n * width : 1,\n * height : 1\n * });\n * cubeMap.positiveX.copyFrom({\n * source: {\n * width : 1,\n * height : 1,\n * arrayBufferView : new Uint8Array([255, 0, 0, 255])\n * }\n * });\n */\nCubeMapFace.prototype.copyFrom = function (options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options\", options);\n //>>includeEnd('debug');\n\n const xOffset = defaultValue(options.xOffset, 0);\n const yOffset = defaultValue(options.yOffset, 0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.source\", options.source);\n Check.typeOf.number.greaterThanOrEquals(\"xOffset\", xOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\"yOffset\", yOffset, 0);\n if (xOffset + options.source.width > this._size) {\n throw new DeveloperError(\n \"xOffset + options.source.width must be less than or equal to width.\"\n );\n }\n if (yOffset + options.source.height > this._size) {\n throw new DeveloperError(\n \"yOffset + options.source.height must be less than or equal to height.\"\n );\n }\n //>>includeEnd('debug');\n\n const source = options.source;\n\n const gl = this._context._gl;\n const target = this._textureTarget;\n const targetFace = this._targetFace;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n\n const width = source.width;\n const height = source.height;\n let arrayBufferView = source.arrayBufferView;\n\n const size = this._size;\n const pixelFormat = this._pixelFormat;\n const internalFormat = this._internalFormat;\n const pixelDatatype = this._pixelDatatype;\n\n const preMultiplyAlpha = this._preMultiplyAlpha;\n const flipY = this._flipY;\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n let unpackAlignment = 4;\n if (defined(arrayBufferView)) {\n unpackAlignment = PixelFormat.alignmentInBytes(\n pixelFormat,\n pixelDatatype,\n width\n );\n }\n\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);\n\n if (skipColorSpaceConversion) {\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n } else {\n gl.pixelStorei(\n gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,\n gl.BROWSER_DEFAULT_WEBGL\n );\n }\n\n let uploaded = false;\n if (!this._initialized) {\n if (xOffset === 0 && yOffset === 0 && width === size && height === size) {\n // initialize the entire texture\n if (defined(arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n size,\n size\n );\n }\n gl.texImage2D(\n targetFace,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, this._context),\n arrayBufferView\n );\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n gl.texImage2D(\n targetFace,\n 0,\n internalFormat,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, this._context),\n source\n );\n }\n uploaded = true;\n } else {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n // initialize the entire texture to zero\n const bufferView = PixelFormat.createTypedArray(\n pixelFormat,\n pixelDatatype,\n size,\n size\n );\n gl.texImage2D(\n targetFace,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, this._context),\n bufferView\n );\n }\n this._initialized = true;\n }\n\n if (!uploaded) {\n if (defined(arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n width,\n height\n );\n }\n gl.texSubImage2D(\n targetFace,\n 0,\n xOffset,\n yOffset,\n width,\n height,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, this._context),\n arrayBufferView\n );\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n // Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement\n gl.texSubImage2D(\n targetFace,\n 0,\n xOffset,\n yOffset,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, this._context),\n source\n );\n }\n }\n\n gl.bindTexture(target, null);\n};\n\n/**\n * Copies texels from the framebuffer to the cubemap's face.\n *\n * @param {number} [xOffset=0] An offset in the x direction in the cubemap where copying begins.\n * @param {number} [yOffset=0] An offset in the y direction in the cubemap where copying begins.\n * @param {number} [framebufferXOffset=0] An offset in the x direction in the framebuffer where copying begins from.\n * @param {number} [framebufferYOffset=0] An offset in the y direction in the framebuffer where copying begins from.\n * @param {number} [width=CubeMap's width] The width of the subimage to copy.\n * @param {number} [height=CubeMap's height] The height of the subimage to copy.\n *\n * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.\n * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.\n * @exception {DeveloperError} This CubeMap was destroyed, i.e., destroy() was called.\n * @exception {DeveloperError} xOffset must be greater than or equal to zero.\n * @exception {DeveloperError} yOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.\n * @exception {DeveloperError} xOffset + source.width must be less than or equal to width.\n * @exception {DeveloperError} yOffset + source.height must be less than or equal to height.\n * @exception {DeveloperError} This CubeMap was destroyed, i.e., destroy() was called.\n *\n * @example\n * // Copy the framebuffer contents to the +x cube map face.\n * cubeMap.positiveX.copyFromFramebuffer();\n */\nCubeMapFace.prototype.copyFromFramebuffer = function (\n xOffset,\n yOffset,\n framebufferXOffset,\n framebufferYOffset,\n width,\n height\n) {\n xOffset = defaultValue(xOffset, 0);\n yOffset = defaultValue(yOffset, 0);\n framebufferXOffset = defaultValue(framebufferXOffset, 0);\n framebufferYOffset = defaultValue(framebufferYOffset, 0);\n width = defaultValue(width, this._size);\n height = defaultValue(height, this._size);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"xOffset\", xOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\"yOffset\", yOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferXOffset\",\n framebufferXOffset,\n 0\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferYOffset\",\n framebufferYOffset,\n 0\n );\n if (xOffset + width > this._size) {\n throw new DeveloperError(\n \"xOffset + source.width must be less than or equal to width.\"\n );\n }\n if (yOffset + height > this._size) {\n throw new DeveloperError(\n \"yOffset + source.height must be less than or equal to height.\"\n );\n }\n if (this._pixelDatatype === PixelDatatype.FLOAT) {\n throw new DeveloperError(\n \"Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.\"\n );\n }\n if (this._pixelDatatype === PixelDatatype.HALF_FLOAT) {\n throw new DeveloperError(\n \"Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.\"\n );\n }\n //>>includeEnd('debug');\n\n const gl = this._context._gl;\n const target = this._textureTarget;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.copyTexSubImage2D(\n this._targetFace,\n 0,\n xOffset,\n yOffset,\n framebufferXOffset,\n framebufferYOffset,\n width,\n height\n );\n gl.bindTexture(target, null);\n this._initialized = true;\n};\nexport default CubeMapFace;\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * @private\n */\nconst MipmapHint = {\n DONT_CARE: WebGLConstants.DONT_CARE,\n FASTEST: WebGLConstants.FASTEST,\n NICEST: WebGLConstants.NICEST,\n\n validate: function (mipmapHint) {\n return (\n mipmapHint === MipmapHint.DONT_CARE ||\n mipmapHint === MipmapHint.FASTEST ||\n mipmapHint === MipmapHint.NICEST\n );\n },\n};\nexport default Object.freeze(MipmapHint);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Enumerates all possible filters used when magnifying WebGL textures.\n *\n * @enum {number}\n *\n * @see TextureMinificationFilter\n */\nconst TextureMagnificationFilter = {\n /**\n * Samples the texture by returning the closest pixel.\n *\n * @type {number}\n * @constant\n */\n NEAREST: WebGLConstants.NEAREST,\n /**\n * Samples the texture through bi-linear interpolation of the four nearest pixels. This produces smoother results than NEAREST filtering.\n *\n * @type {number}\n * @constant\n */\n LINEAR: WebGLConstants.LINEAR,\n};\n\n/**\n * Validates the given textureMinificationFilter with respect to the possible enum values.\n * @param textureMagnificationFilter\n * @returns {boolean} true if textureMagnificationFilter is valid.\n *\n * @private\n */\nTextureMagnificationFilter.validate = function (textureMagnificationFilter) {\n return (\n textureMagnificationFilter === TextureMagnificationFilter.NEAREST ||\n textureMagnificationFilter === TextureMagnificationFilter.LINEAR\n );\n};\n\nexport default Object.freeze(TextureMagnificationFilter);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Enumerates all possible filters used when minifying WebGL textures.\n *\n * @enum {number}\n *\n * @see TextureMagnificationFilter\n */\nconst TextureMinificationFilter = {\n /**\n * Samples the texture by returning the closest pixel.\n *\n * @type {number}\n * @constant\n */\n NEAREST: WebGLConstants.NEAREST,\n /**\n * Samples the texture through bi-linear interpolation of the four nearest pixels. This produces smoother results than NEAREST filtering.\n *\n * @type {number}\n * @constant\n */\n LINEAR: WebGLConstants.LINEAR,\n /**\n * Selects the nearest mip level and applies nearest sampling within that level.\n *

\n * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.\n *

\n *\n * @type {number}\n * @constant\n */\n NEAREST_MIPMAP_NEAREST: WebGLConstants.NEAREST_MIPMAP_NEAREST,\n /**\n * Selects the nearest mip level and applies linear sampling within that level.\n *

\n * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.\n *

\n *\n * @type {number}\n * @constant\n */\n LINEAR_MIPMAP_NEAREST: WebGLConstants.LINEAR_MIPMAP_NEAREST,\n /**\n * Read texture values with nearest sampling from two adjacent mip levels and linearly interpolate the results.\n *

\n * This option provides a good balance of visual quality and speed when sampling from a mipmapped texture.\n *

\n *

\n * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.\n *

\n *\n * @type {number}\n * @constant\n */\n NEAREST_MIPMAP_LINEAR: WebGLConstants.NEAREST_MIPMAP_LINEAR,\n /**\n * Read texture values with linear sampling from two adjacent mip levels and linearly interpolate the results.\n *

\n * This option provides a good balance of visual quality and speed when sampling from a mipmapped texture.\n *

\n *

\n * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.\n *

\n * @type {number}\n * @constant\n */\n LINEAR_MIPMAP_LINEAR: WebGLConstants.LINEAR_MIPMAP_LINEAR,\n};\n\n/**\n * Validates the given textureMinificationFilter with respect to the possible enum values.\n *\n * @private\n *\n * @param textureMinificationFilter\n * @returns {boolean} true if textureMinificationFilter is valid.\n */\nTextureMinificationFilter.validate = function (textureMinificationFilter) {\n return (\n textureMinificationFilter === TextureMinificationFilter.NEAREST ||\n textureMinificationFilter === TextureMinificationFilter.LINEAR ||\n textureMinificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||\n textureMinificationFilter ===\n TextureMinificationFilter.LINEAR_MIPMAP_NEAREST ||\n textureMinificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_LINEAR ||\n textureMinificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR\n );\n};\n\nexport default Object.freeze(TextureMinificationFilter);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * @private\n */\nconst TextureWrap = {\n CLAMP_TO_EDGE: WebGLConstants.CLAMP_TO_EDGE,\n REPEAT: WebGLConstants.REPEAT,\n MIRRORED_REPEAT: WebGLConstants.MIRRORED_REPEAT,\n\n validate: function (textureWrap) {\n return (\n textureWrap === TextureWrap.CLAMP_TO_EDGE ||\n textureWrap === TextureWrap.REPEAT ||\n textureWrap === TextureWrap.MIRRORED_REPEAT\n );\n },\n};\nexport default Object.freeze(TextureWrap);\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport TextureMagnificationFilter from \"./TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"./TextureMinificationFilter.js\";\nimport TextureWrap from \"./TextureWrap.js\";\n\n/**\n * @private\n */\nfunction Sampler(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const wrapS = defaultValue(options.wrapS, TextureWrap.CLAMP_TO_EDGE);\n const wrapT = defaultValue(options.wrapT, TextureWrap.CLAMP_TO_EDGE);\n const minificationFilter = defaultValue(\n options.minificationFilter,\n TextureMinificationFilter.LINEAR\n );\n const magnificationFilter = defaultValue(\n options.magnificationFilter,\n TextureMagnificationFilter.LINEAR\n );\n const maximumAnisotropy = defined(options.maximumAnisotropy)\n ? options.maximumAnisotropy\n : 1.0;\n\n //>>includeStart('debug', pragmas.debug);\n if (!TextureWrap.validate(wrapS)) {\n throw new DeveloperError(\"Invalid sampler.wrapS.\");\n }\n\n if (!TextureWrap.validate(wrapT)) {\n throw new DeveloperError(\"Invalid sampler.wrapT.\");\n }\n\n if (!TextureMinificationFilter.validate(minificationFilter)) {\n throw new DeveloperError(\"Invalid sampler.minificationFilter.\");\n }\n\n if (!TextureMagnificationFilter.validate(magnificationFilter)) {\n throw new DeveloperError(\"Invalid sampler.magnificationFilter.\");\n }\n\n Check.typeOf.number.greaterThanOrEquals(\n \"maximumAnisotropy\",\n maximumAnisotropy,\n 1.0\n );\n //>>includeEnd('debug');\n\n this._wrapS = wrapS;\n this._wrapT = wrapT;\n this._minificationFilter = minificationFilter;\n this._magnificationFilter = magnificationFilter;\n this._maximumAnisotropy = maximumAnisotropy;\n}\n\nObject.defineProperties(Sampler.prototype, {\n wrapS: {\n get: function () {\n return this._wrapS;\n },\n },\n wrapT: {\n get: function () {\n return this._wrapT;\n },\n },\n minificationFilter: {\n get: function () {\n return this._minificationFilter;\n },\n },\n magnificationFilter: {\n get: function () {\n return this._magnificationFilter;\n },\n },\n maximumAnisotropy: {\n get: function () {\n return this._maximumAnisotropy;\n },\n },\n});\n\nSampler.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left._wrapS === right._wrapS &&\n left._wrapT === right._wrapT &&\n left._minificationFilter === right._minificationFilter &&\n left._magnificationFilter === right._magnificationFilter &&\n left._maximumAnisotropy === right._maximumAnisotropy)\n );\n};\n\nSampler.NEAREST = Object.freeze(\n new Sampler({\n wrapS: TextureWrap.CLAMP_TO_EDGE,\n wrapT: TextureWrap.CLAMP_TO_EDGE,\n minificationFilter: TextureMinificationFilter.NEAREST,\n magnificationFilter: TextureMagnificationFilter.NEAREST,\n })\n);\nexport default Sampler;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport CubeMapFace from \"./CubeMapFace.js\";\nimport MipmapHint from \"./MipmapHint.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\nimport Sampler from \"./Sampler.js\";\nimport TextureMagnificationFilter from \"./TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"./TextureMinificationFilter.js\";\n\n/**\n * @private\n */\nfunction CubeMap(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n const context = options.context;\n const source = options.source;\n let width;\n let height;\n\n if (defined(source)) {\n const faces = [\n source.positiveX,\n source.negativeX,\n source.positiveY,\n source.negativeY,\n source.positiveZ,\n source.negativeZ,\n ];\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !faces[0] ||\n !faces[1] ||\n !faces[2] ||\n !faces[3] ||\n !faces[4] ||\n !faces[5]\n ) {\n throw new DeveloperError(\n \"options.source requires positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ faces.\"\n );\n }\n //>>includeEnd('debug');\n\n width = faces[0].width;\n height = faces[0].height;\n\n //>>includeStart('debug', pragmas.debug);\n for (let i = 1; i < 6; ++i) {\n if (\n Number(faces[i].width) !== width ||\n Number(faces[i].height) !== height\n ) {\n throw new DeveloperError(\n \"Each face in options.source must have the same width and height.\"\n );\n }\n }\n //>>includeEnd('debug');\n } else {\n width = options.width;\n height = options.height;\n }\n\n const size = width;\n const pixelDatatype = defaultValue(\n options.pixelDatatype,\n PixelDatatype.UNSIGNED_BYTE\n );\n const pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA);\n const internalFormat = PixelFormat.toInternalFormat(\n pixelFormat,\n pixelDatatype,\n context\n );\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(width) || !defined(height)) {\n throw new DeveloperError(\n \"options requires a source field to create an initialized cube map or width and height fields to create a blank cube map.\"\n );\n }\n\n if (width !== height) {\n throw new DeveloperError(\"Width must equal height.\");\n }\n\n if (size <= 0) {\n throw new DeveloperError(\"Width and height must be greater than zero.\");\n }\n\n if (size > ContextLimits.maximumCubeMapSize) {\n throw new DeveloperError(\n `Width and height must be less than or equal to the maximum cube map size (${ContextLimits.maximumCubeMapSize}). Check maximumCubeMapSize.`\n );\n }\n\n if (!PixelFormat.validate(pixelFormat)) {\n throw new DeveloperError(\"Invalid options.pixelFormat.\");\n }\n\n if (PixelFormat.isDepthFormat(pixelFormat)) {\n throw new DeveloperError(\n \"options.pixelFormat cannot be DEPTH_COMPONENT or DEPTH_STENCIL.\"\n );\n }\n\n if (!PixelDatatype.validate(pixelDatatype)) {\n throw new DeveloperError(\"Invalid options.pixelDatatype.\");\n }\n\n if (pixelDatatype === PixelDatatype.FLOAT && !context.floatingPointTexture) {\n throw new DeveloperError(\n \"When options.pixelDatatype is FLOAT, this WebGL implementation must support the OES_texture_float extension.\"\n );\n }\n\n if (\n pixelDatatype === PixelDatatype.HALF_FLOAT &&\n !context.halfFloatingPointTexture\n ) {\n throw new DeveloperError(\n \"When options.pixelDatatype is HALF_FLOAT, this WebGL implementation must support the OES_texture_half_float extension.\"\n );\n }\n //>>includeEnd('debug');\n\n const sizeInBytes =\n PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, size, size) * 6;\n\n // Use premultiplied alpha for opaque textures should perform better on Chrome:\n // http://media.tojicode.com/webglCamp4/#20\n const preMultiplyAlpha =\n options.preMultiplyAlpha ||\n pixelFormat === PixelFormat.RGB ||\n pixelFormat === PixelFormat.LUMINANCE;\n const flipY = defaultValue(options.flipY, true);\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n const gl = context._gl;\n const textureTarget = gl.TEXTURE_CUBE_MAP;\n const texture = gl.createTexture();\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(textureTarget, texture);\n\n function createFace(\n target,\n sourceFace,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n ) {\n let arrayBufferView = sourceFace.arrayBufferView;\n if (!defined(arrayBufferView)) {\n arrayBufferView = sourceFace.bufferView;\n }\n\n let unpackAlignment = 4;\n if (defined(arrayBufferView)) {\n unpackAlignment = PixelFormat.alignmentInBytes(\n pixelFormat,\n pixelDatatype,\n width\n );\n }\n\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);\n\n if (skipColorSpaceConversion) {\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n } else {\n gl.pixelStorei(\n gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,\n gl.BROWSER_DEFAULT_WEBGL\n );\n }\n\n if (defined(arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n size,\n size\n );\n }\n gl.texImage2D(\n target,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n arrayBufferView\n );\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n // Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement\n gl.texImage2D(\n target,\n 0,\n internalFormat,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n sourceFace\n );\n }\n }\n\n if (defined(source)) {\n createFace(\n gl.TEXTURE_CUBE_MAP_POSITIVE_X,\n source.positiveX,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n createFace(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\n source.negativeX,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n createFace(\n gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\n source.positiveY,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n createFace(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\n source.negativeY,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n createFace(\n gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\n source.positiveZ,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n createFace(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,\n source.negativeZ,\n preMultiplyAlpha,\n flipY,\n skipColorSpaceConversion\n );\n } else {\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_POSITIVE_X,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n gl.texImage2D(\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,\n 0,\n internalFormat,\n size,\n size,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n }\n gl.bindTexture(textureTarget, null);\n\n this._context = context;\n this._textureFilterAnisotropic = context._textureFilterAnisotropic;\n this._textureTarget = textureTarget;\n this._texture = texture;\n this._pixelFormat = pixelFormat;\n this._pixelDatatype = pixelDatatype;\n this._size = size;\n this._hasMipmap = false;\n this._sizeInBytes = sizeInBytes;\n this._preMultiplyAlpha = preMultiplyAlpha;\n this._flipY = flipY;\n this._sampler = undefined;\n\n const initialized = defined(source);\n this._positiveX = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_POSITIVE_X,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n this._negativeX = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_X,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n this._positiveY = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_POSITIVE_Y,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n this._negativeY = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n this._positiveZ = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_POSITIVE_Z,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n this._negativeZ = new CubeMapFace(\n context,\n texture,\n textureTarget,\n gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,\n internalFormat,\n pixelFormat,\n pixelDatatype,\n size,\n preMultiplyAlpha,\n flipY,\n initialized\n );\n\n this.sampler = defined(options.sampler) ? options.sampler : new Sampler();\n}\n\nObject.defineProperties(CubeMap.prototype, {\n positiveX: {\n get: function () {\n return this._positiveX;\n },\n },\n negativeX: {\n get: function () {\n return this._negativeX;\n },\n },\n positiveY: {\n get: function () {\n return this._positiveY;\n },\n },\n negativeY: {\n get: function () {\n return this._negativeY;\n },\n },\n positiveZ: {\n get: function () {\n return this._positiveZ;\n },\n },\n negativeZ: {\n get: function () {\n return this._negativeZ;\n },\n },\n sampler: {\n get: function () {\n return this._sampler;\n },\n set: function (sampler) {\n let minificationFilter = sampler.minificationFilter;\n let magnificationFilter = sampler.magnificationFilter;\n\n const mipmap =\n minificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||\n minificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_LINEAR ||\n minificationFilter ===\n TextureMinificationFilter.LINEAR_MIPMAP_NEAREST ||\n minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR;\n\n const context = this._context;\n const pixelDatatype = this._pixelDatatype;\n\n // float textures only support nearest filtering unless the linear extensions are supported, so override the sampler's settings\n if (\n (pixelDatatype === PixelDatatype.FLOAT &&\n !context.textureFloatLinear) ||\n (pixelDatatype === PixelDatatype.HALF_FLOAT &&\n !context.textureHalfFloatLinear)\n ) {\n minificationFilter = mipmap\n ? TextureMinificationFilter.NEAREST_MIPMAP_NEAREST\n : TextureMinificationFilter.NEAREST;\n magnificationFilter = TextureMagnificationFilter.NEAREST;\n }\n\n const gl = context._gl;\n const target = this._textureTarget;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);\n if (defined(this._textureFilterAnisotropic)) {\n gl.texParameteri(\n target,\n this._textureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,\n sampler.maximumAnisotropy\n );\n }\n gl.bindTexture(target, null);\n\n this._sampler = sampler;\n },\n },\n pixelFormat: {\n get: function () {\n return this._pixelFormat;\n },\n },\n pixelDatatype: {\n get: function () {\n return this._pixelDatatype;\n },\n },\n width: {\n get: function () {\n return this._size;\n },\n },\n height: {\n get: function () {\n return this._size;\n },\n },\n sizeInBytes: {\n get: function () {\n if (this._hasMipmap) {\n return Math.floor((this._sizeInBytes * 4) / 3);\n }\n return this._sizeInBytes;\n },\n },\n preMultiplyAlpha: {\n get: function () {\n return this._preMultiplyAlpha;\n },\n },\n flipY: {\n get: function () {\n return this._flipY;\n },\n },\n\n _target: {\n get: function () {\n return this._textureTarget;\n },\n },\n});\n\n/**\n * Generates a complete mipmap chain for each cubemap face.\n *\n * @param {MipmapHint} [hint=MipmapHint.DONT_CARE] A performance vs. quality hint.\n *\n * @exception {DeveloperError} hint is invalid.\n * @exception {DeveloperError} This CubeMap's width must be a power of two to call generateMipmap().\n * @exception {DeveloperError} This CubeMap's height must be a power of two to call generateMipmap().\n * @exception {DeveloperError} This CubeMap was destroyed, i.e., destroy() was called.\n *\n * @example\n * // Generate mipmaps, and then set the sampler so mipmaps are used for\n * // minification when the cube map is sampled.\n * cubeMap.generateMipmap();\n * cubeMap.sampler = new Sampler({\n * minificationFilter : Cesium.TextureMinificationFilter.NEAREST_MIPMAP_LINEAR\n * });\n */\nCubeMap.prototype.generateMipmap = function (hint) {\n hint = defaultValue(hint, MipmapHint.DONT_CARE);\n\n //>>includeStart('debug', pragmas.debug);\n if (this._size > 1 && !CesiumMath.isPowerOfTwo(this._size)) {\n throw new DeveloperError(\n \"width and height must be a power of two to call generateMipmap().\"\n );\n }\n if (!MipmapHint.validate(hint)) {\n throw new DeveloperError(\"hint is invalid.\");\n }\n //>>includeEnd('debug');\n\n this._hasMipmap = true;\n\n const gl = this._context._gl;\n const target = this._textureTarget;\n gl.hint(gl.GENERATE_MIPMAP_HINT, hint);\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.generateMipmap(target);\n gl.bindTexture(target, null);\n};\n\nCubeMap.prototype.isDestroyed = function () {\n return false;\n};\n\nCubeMap.prototype.destroy = function () {\n this._context._gl.deleteTexture(this._texture);\n this._positiveX = destroyObject(this._positiveX);\n this._negativeX = destroyObject(this._negativeX);\n this._positiveY = destroyObject(this._positiveY);\n this._negativeY = destroyObject(this._negativeY);\n this._positiveZ = destroyObject(this._positiveZ);\n this._negativeZ = destroyObject(this._negativeZ);\n return destroyObject(this);\n};\nexport default CubeMap;\n", "/**\n * The state for a particular rendering pass. This is used to supplement the state\n * in a command being executed.\n *\n * @private\n * @constructor\n */\nfunction PassState(context) {\n /**\n * The context used to execute commands for this pass.\n *\n * @type {Context}\n */\n this.context = context;\n\n /**\n * The framebuffer to render to. This framebuffer is used unless a {@link DrawCommand}\n * or {@link ClearCommand} explicitly define a framebuffer, which is used for off-screen\n * rendering.\n *\n * @type {Framebuffer}\n * @default undefined\n */\n this.framebuffer = undefined;\n\n /**\n * When defined, this overrides the blending property of a {@link DrawCommand}'s render state.\n * This is used to, for example, to allow the renderer to turn off blending during the picking pass.\n *

\n * When this is undefined, the {@link DrawCommand}'s property is used.\n *

\n *\n * @type {boolean}\n * @default undefined\n */\n this.blendingEnabled = undefined;\n\n /**\n * When defined, this overrides the scissor test property of a {@link DrawCommand}'s render state.\n * This is used to, for example, to allow the renderer to scissor out the pick region during the picking pass.\n *

\n * When this is undefined, the {@link DrawCommand}'s property is used.\n *

\n *\n * @type {object}\n * @default undefined\n */\n this.scissorTest = undefined;\n\n /**\n * The viewport used when one is not defined by a {@link DrawCommand}'s render state.\n * @type {BoundingRectangle}\n * @default undefined\n */\n this.viewport = undefined;\n}\nexport default PassState;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for converting radians to degrees.\\n\\\n *\\n\\\n * @alias czm_degreesPerRadian\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.DEGREES_PER_RADIAN\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_degreesPerRadian = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float deg = czm_degreesPerRadian * rad;\\n\\\n */\\n\\\nconst float czm_degreesPerRadian = 57.29577951308232;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL vec2 constant for defining the depth range.\\n\\\n * This is a workaround to a bug where IE11 does not implement gl_DepthRange.\\n\\\n *\\n\\\n * @alias czm_depthRange\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * float depthRangeNear = czm_depthRange.near;\\n\\\n * float depthRangeFar = czm_depthRange.far;\\n\\\n *\\n\\\n */\\n\\\nconst czm_depthRangeStruct czm_depthRange = czm_depthRangeStruct(0.0, 1.0);\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.1\\n\\\n *\\n\\\n * @name czm_epsilon1\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon1 = 0.1;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.01\\n\\\n *\\n\\\n * @name czm_epsilon2\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon2 = 0.01;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.001\\n\\\n *\\n\\\n * @name czm_epsilon3\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon3 = 0.001;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.0001\\n\\\n *\\n\\\n * @name czm_epsilon4\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon4 = 0.0001;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.00001\\n\\\n *\\n\\\n * @name czm_epsilon5\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon5 = 0.00001;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.000001\\n\\\n *\\n\\\n * @name czm_epsilon6\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon6 = 0.000001;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * 0.0000001\\n\\\n *\\n\\\n * @name czm_epsilon7\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_epsilon7 = 0.0000001;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_infinity\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_infinity = 5906376272000.0; // Distance from the Sun to Pluto in meters. TODO: What is best given lowp, mediump, and highp?\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for 1/pi.\\n\\\n *\\n\\\n * @alias czm_oneOverPi\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.ONE_OVER_PI\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_oneOverPi = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 1.0 / czm_oneOverPi;\\n\\\n */\\n\\\nconst float czm_oneOverPi = 0.3183098861837907;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for 1/2pi.\\n\\\n *\\n\\\n * @alias czm_oneOverTwoPi\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.ONE_OVER_TWO_PI\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_oneOverTwoPi = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 2.0 * czm_oneOverTwoPi;\\n\\\n */\\n\\\nconst float czm_oneOverTwoPi = 0.15915494309189535;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE}\\n\\\n *\\n\\\n * @name czm_passCesium3DTile\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passCesium3DTile = 4.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE_CLASSIFICATION}\\n\\\n *\\n\\\n * @name czm_passCesium3DTileClassification\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passCesium3DTileClassification = 5.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW}\\n\\\n *\\n\\\n * @name czm_passCesium3DTileClassificationIgnoreShow\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passCesium3DTileClassificationIgnoreShow = 6.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#CLASSIFICATION}\\n\\\n *\\n\\\n * @name czm_passClassification\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passClassification = 7.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#COMPUTE}\\n\\\n *\\n\\\n * @name czm_passCompute\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passCompute = 1.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#ENVIRONMENT}\\n\\\n *\\n\\\n * @name czm_passEnvironment\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passEnvironment = 0.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#GLOBE}\\n\\\n *\\n\\\n * @name czm_passGlobe\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passGlobe = 2.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#OPAQUE}\\n\\\n *\\n\\\n * @name czm_passOpaque\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passOpaque = 7.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#OVERLAY}\\n\\\n *\\n\\\n * @name czm_passOverlay\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passOverlay = 10.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#TERRAIN_CLASSIFICATION}\\n\\\n *\\n\\\n * @name czm_passTerrainClassification\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passTerrainClassification = 3.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#TRANSLUCENT}\\n\\\n *\\n\\\n * @name czm_passTranslucent\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passTranslucent = 8.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The automatic GLSL constant for {@link Pass#VOXELS}\\n\\\n *\\n\\\n * @name czm_passVoxels\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see czm_pass\\n\\\n */\\n\\\nconst float czm_passVoxels = 9.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for Math.PI.\\n\\\n *\\n\\\n * @alias czm_pi\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.PI\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_pi = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float twoPi = 2.0 * czm_pi;\\n\\\n */\\n\\\nconst float czm_pi = 3.141592653589793;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for pi/4.\\n\\\n *\\n\\\n * @alias czm_piOverFour\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.PI_OVER_FOUR\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_piOverFour = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 4.0 * czm_piOverFour;\\n\\\n */\\n\\\nconst float czm_piOverFour = 0.7853981633974483;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for pi/6.\\n\\\n *\\n\\\n * @alias czm_piOverSix\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.PI_OVER_SIX\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_piOverSix = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 6.0 * czm_piOverSix;\\n\\\n */\\n\\\nconst float czm_piOverSix = 0.5235987755982988;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for pi/3.\\n\\\n *\\n\\\n * @alias czm_piOverThree\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.PI_OVER_THREE\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_piOverThree = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 3.0 * czm_piOverThree;\\n\\\n */\\n\\\nconst float czm_piOverThree = 1.0471975511965976;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for pi/2.\\n\\\n *\\n\\\n * @alias czm_piOverTwo\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.PI_OVER_TWO\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_piOverTwo = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = 2.0 * czm_piOverTwo;\\n\\\n */\\n\\\nconst float czm_piOverTwo = 1.5707963267948966;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for converting degrees to radians.\\n\\\n *\\n\\\n * @alias czm_radiansPerDegree\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.RADIANS_PER_DEGREE\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_radiansPerDegree = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float rad = czm_radiansPerDegree * deg;\\n\\\n */\\n\\\nconst float czm_radiansPerDegree = 0.017453292519943295;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The constant identifier for the 2D {@link SceneMode}\\n\\\n *\\n\\\n * @name czm_sceneMode2D\\n\\\n * @glslConstant\\n\\\n * @see czm_sceneMode\\n\\\n * @see czm_sceneModeColumbusView\\n\\\n * @see czm_sceneMode3D\\n\\\n * @see czm_sceneModeMorphing\\n\\\n */\\n\\\nconst float czm_sceneMode2D = 2.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The constant identifier for the 3D {@link SceneMode}\\n\\\n *\\n\\\n * @name czm_sceneMode3D\\n\\\n * @glslConstant\\n\\\n * @see czm_sceneMode\\n\\\n * @see czm_sceneMode2D\\n\\\n * @see czm_sceneModeColumbusView\\n\\\n * @see czm_sceneModeMorphing\\n\\\n */\\n\\\nconst float czm_sceneMode3D = 3.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The constant identifier for the Columbus View {@link SceneMode}\\n\\\n *\\n\\\n * @name czm_sceneModeColumbusView\\n\\\n * @glslConstant\\n\\\n * @see czm_sceneMode\\n\\\n * @see czm_sceneMode2D\\n\\\n * @see czm_sceneMode3D\\n\\\n * @see czm_sceneModeMorphing\\n\\\n */\\n\\\nconst float czm_sceneModeColumbusView = 1.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The constant identifier for the Morphing {@link SceneMode}\\n\\\n *\\n\\\n * @name czm_sceneModeMorphing\\n\\\n * @glslConstant\\n\\\n * @see czm_sceneMode\\n\\\n * @see czm_sceneMode2D\\n\\\n * @see czm_sceneModeColumbusView\\n\\\n * @see czm_sceneMode3D\\n\\\n */\\n\\\nconst float czm_sceneModeMorphing = 0.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for one solar radius.\\n\\\n *\\n\\\n * @alias czm_solarRadius\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.SOLAR_RADIUS\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_solarRadius = ...;\\n\\\n */\\n\\\nconst float czm_solarRadius = 695500000.0;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for 3pi/2.\\n\\\n *\\n\\\n * @alias czm_threePiOver2\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.THREE_PI_OVER_TWO\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_threePiOver2 = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = (2.0 / 3.0) * czm_threePiOver2;\\n\\\n */\\n\\\nconst float czm_threePiOver2 = 4.71238898038469;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A built-in GLSL floating-point constant for 2pi.\\n\\\n *\\n\\\n * @alias czm_twoPi\\n\\\n * @glslConstant\\n\\\n *\\n\\\n * @see CesiumMath.TWO_PI\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declaration\\n\\\n * const float czm_twoPi = ...;\\n\\\n *\\n\\\n * // Example\\n\\\n * float pi = czm_twoPi / 2.0;\\n\\\n */\\n\\\nconst float czm_twoPi = 6.283185307179586;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * The maximum latitude, in radians, both North and South, supported by a Web Mercator\\n\\\n * (EPSG:3857) projection. Technically, the Mercator projection is defined\\n\\\n * for any latitude up to (but not including) 90 degrees, but it makes sense\\n\\\n * to cut it off sooner because it grows exponentially with increasing latitude.\\n\\\n * The logic behind this particular cutoff value, which is the one used by\\n\\\n * Google Maps, Bing Maps, and Esri, is that it makes the projection\\n\\\n * square. That is, the rectangle is equal in the X and Y directions.\\n\\\n *\\n\\\n * The constant value is computed as follows:\\n\\\n * czm_pi * 0.5 - (2.0 * atan(exp(-czm_pi)))\\n\\\n *\\n\\\n * @name czm_webMercatorMaxLatitude\\n\\\n * @glslConstant\\n\\\n */\\n\\\nconst float czm_webMercatorMaxLatitude = 1.4844222297453324;\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * @name czm_depthRangeStruct\\n\\\n * @glslStruct\\n\\\n */\\n\\\nstruct czm_depthRangeStruct\\n\\\n{\\n\\\n float near;\\n\\\n float far;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Holds material information that can be used for lighting. Returned by all czm_getMaterial functions.\\n\\\n *\\n\\\n * @name czm_material\\n\\\n * @glslStruct\\n\\\n *\\n\\\n * @property {vec3} diffuse Incoming light that scatters evenly in all directions.\\n\\\n * @property {float} specular Intensity of incoming light reflecting in a single direction.\\n\\\n * @property {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.\\n\\\n * @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.\\n\\\n * @property {vec3} emission Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light.\\n\\\n * @property {float} alpha Alpha of this material. 0.0 is completely transparent; 1.0 is completely opaque.\\n\\\n */\\n\\\nstruct czm_material\\n\\\n{\\n\\\n vec3 diffuse;\\n\\\n float specular;\\n\\\n float shininess;\\n\\\n vec3 normal;\\n\\\n vec3 emission;\\n\\\n float alpha;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Used as input to every material's czm_getMaterial function.\\n\\\n *\\n\\\n * @name czm_materialInput\\n\\\n * @glslStruct\\n\\\n *\\n\\\n * @property {float} s 1D texture coordinates.\\n\\\n * @property {vec2} st 2D texture coordinates.\\n\\\n * @property {vec3} str 3D texture coordinates.\\n\\\n * @property {vec3} normalEC Unperturbed surface normal in eye coordinates.\\n\\\n * @property {mat3} tangentToEyeMatrix Matrix for converting a tangent space normal to eye space.\\n\\\n * @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.\\n\\\n * @property {float} height The height of the terrain in meters above or below the WGS84 ellipsoid. Only available for globe materials.\\n\\\n * @property {float} slope The slope of the terrain in radians. 0 is flat; pi/2 is vertical. Only available for globe materials.\\n\\\n * @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.\\n\\\n */\\n\\\nstruct czm_materialInput\\n\\\n{\\n\\\n float s;\\n\\\n vec2 st;\\n\\\n vec3 str;\\n\\\n vec3 normalEC;\\n\\\n mat3 tangentToEyeMatrix;\\n\\\n vec3 positionToEyeEC;\\n\\\n float height;\\n\\\n float slope;\\n\\\n float aspect;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Struct for representing a material for a {@link Model}. The model\\n\\\n * rendering pipeline will pass this struct between material, custom shaders,\\n\\\n * and lighting stages. This is not to be confused with {@link czm_material}\\n\\\n * which is used by the older Fabric materials system, although they are similar.\\n\\\n *

\\n\\\n * All color values (diffuse, specular, emissive) are in linear color space.\\n\\\n *

\\n\\\n *\\n\\\n * @name czm_modelMaterial\\n\\\n * @glslStruct\\n\\\n *\\n\\\n * @property {vec3} diffuse Incoming light that scatters evenly in all directions.\\n\\\n * @property {float} alpha Alpha of this material. 0.0 is completely transparent; 1.0 is completely opaque.\\n\\\n * @property {vec3} specular Color of reflected light at normal incidence in PBR materials. This is sometimes referred to as f0 in the literature.\\n\\\n * @property {float} roughness A number from 0.0 to 1.0 representing how rough the surface is. Values near 0.0 produce glossy surfaces, while values near 1.0 produce rough surfaces.\\n\\\n * @property {vec3} normalEC Surface's normal in eye coordinates. It is used for effects such as normal mapping. The default is the surface's unmodified normal.\\n\\\n * @property {float} occlusion Ambient occlusion recieved at this point on the material. 1.0 means fully lit, 0.0 means fully occluded.\\n\\\n * @property {vec3} emissive Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light.\\n\\\n */\\n\\\nstruct czm_modelMaterial {\\n\\\n vec3 diffuse;\\n\\\n float alpha;\\n\\\n vec3 specular;\\n\\\n float roughness;\\n\\\n vec3 normalEC;\\n\\\n float occlusion;\\n\\\n vec3 emissive;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Struct for representing the output of a custom vertex shader.\\n\\\n * \\n\\\n * @name czm_modelVertexOutput\\n\\\n * @glslStruct\\n\\\n *\\n\\\n * @see {@link CustomShader}\\n\\\n * @see {@link Model}\\n\\\n *\\n\\\n * @property {vec3} positionMC The position of the vertex in model coordinates\\n\\\n * @property {float} pointSize A custom value for gl_PointSize. This is only used for point primitives. \\n\\\n */\\n\\\nstruct czm_modelVertexOutput {\\n\\\n vec3 positionMC;\\n\\\n float pointSize;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Parameters for {@link czm_pbrLighting}\\n\\\n *\\n\\\n * @name czm_material\\n\\\n * @glslStruct\\n\\\n *\\n\\\n * @property {vec3} diffuseColor the diffuse color of the material for the lambert term of the rendering equation\\n\\\n * @property {float} roughness a value from 0.0 to 1.0 that indicates how rough the surface of the material is.\\n\\\n * @property {vec3} f0 The reflectance of the material at normal incidence\\n\\\n */\\n\\\nstruct czm_pbrParameters\\n\\\n{\\n\\\n vec3 diffuseColor;\\n\\\n float roughness;\\n\\\n vec3 f0;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_ray\\n\\\n * @glslStruct\\n\\\n */\\n\\\nstruct czm_ray\\n\\\n{\\n\\\n vec3 origin;\\n\\\n vec3 direction;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_raySegment\\n\\\n * @glslStruct\\n\\\n */\\n\\\nstruct czm_raySegment\\n\\\n{\\n\\\n float start;\\n\\\n float stop;\\n\\\n};\\n\\\n\\n\\\n/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_emptyRaySegment\\n\\\n * @glslConstant \\n\\\n */\\n\\\nconst czm_raySegment czm_emptyRaySegment = czm_raySegment(-czm_infinity, -czm_infinity);\\n\\\n\\n\\\n/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_fullRaySegment\\n\\\n * @glslConstant \\n\\\n */\\n\\\nconst czm_raySegment czm_fullRaySegment = czm_raySegment(0.0, czm_infinity);\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"struct czm_shadowParameters\\n\\\n{\\n\\\n#ifdef USE_CUBE_MAP_SHADOW\\n\\\n vec3 texCoords;\\n\\\n#else\\n\\\n vec2 texCoords;\\n\\\n#endif\\n\\\n\\n\\\n float depthBias;\\n\\\n float depth;\\n\\\n float nDotL;\\n\\\n vec2 texelStepSize;\\n\\\n float normalShadingSmooth;\\n\\\n float darkness;\\n\\\n};\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an HSB color (hue, saturation, brightness) to RGB\\n\\\n * HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}\\n\\\n *\\n\\\n * @name czm_HSBToRGB\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} hsb The color in HSB.\\n\\\n *\\n\\\n * @returns {vec3} The color in RGB.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 hsb = czm_RGBToHSB(rgb);\\n\\\n * hsb.z *= 0.1;\\n\\\n * rgb = czm_HSBToRGB(hsb);\\n\\\n */\\n\\\n\\n\\\nconst vec4 K_HSB2RGB = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\\n\\\n\\n\\\nvec3 czm_HSBToRGB(vec3 hsb)\\n\\\n{\\n\\\n vec3 p = abs(fract(hsb.xxx + K_HSB2RGB.xyz) * 6.0 - K_HSB2RGB.www);\\n\\\n return hsb.z * mix(K_HSB2RGB.xxx, clamp(p - K_HSB2RGB.xxx, 0.0, 1.0), hsb.y);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an HSL color (hue, saturation, lightness) to RGB\\n\\\n * HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}\\n\\\n *\\n\\\n * @name czm_HSLToRGB\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color in HSL.\\n\\\n *\\n\\\n * @returns {vec3} The color in RGB.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 hsl = czm_RGBToHSL(rgb);\\n\\\n * hsl.z *= 0.1;\\n\\\n * rgb = czm_HSLToRGB(hsl);\\n\\\n */\\n\\\n\\n\\\nvec3 hueToRGB(float hue)\\n\\\n{\\n\\\n float r = abs(hue * 6.0 - 3.0) - 1.0;\\n\\\n float g = 2.0 - abs(hue * 6.0 - 2.0);\\n\\\n float b = 2.0 - abs(hue * 6.0 - 4.0);\\n\\\n return clamp(vec3(r, g, b), 0.0, 1.0);\\n\\\n}\\n\\\n\\n\\\nvec3 czm_HSLToRGB(vec3 hsl)\\n\\\n{\\n\\\n vec3 rgb = hueToRGB(hsl.x);\\n\\\n float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;\\n\\\n return (rgb - 0.5) * c + hsl.z;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an RGB color to HSB (hue, saturation, brightness)\\n\\\n * HSB <-> RGB conversion with minimal branching: {@link http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl}\\n\\\n *\\n\\\n * @name czm_RGBToHSB\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color in RGB.\\n\\\n *\\n\\\n * @returns {vec3} The color in HSB.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 hsb = czm_RGBToHSB(rgb);\\n\\\n * hsb.z *= 0.1;\\n\\\n * rgb = czm_HSBToRGB(hsb);\\n\\\n */\\n\\\n\\n\\\nconst vec4 K_RGB2HSB = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\\n\\\n\\n\\\nvec3 czm_RGBToHSB(vec3 rgb)\\n\\\n{\\n\\\n vec4 p = mix(vec4(rgb.bg, K_RGB2HSB.wz), vec4(rgb.gb, K_RGB2HSB.xy), step(rgb.b, rgb.g));\\n\\\n vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));\\n\\\n\\n\\\n float d = q.x - min(q.w, q.y);\\n\\\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + czm_epsilon7)), d / (q.x + czm_epsilon7), q.x);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an RGB color to HSL (hue, saturation, lightness)\\n\\\n * HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}\\n\\\n *\\n\\\n * @name czm_RGBToHSL\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color in RGB.\\n\\\n *\\n\\\n * @returns {vec3} The color in HSL.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 hsl = czm_RGBToHSL(rgb);\\n\\\n * hsl.z *= 0.1;\\n\\\n * rgb = czm_HSLToRGB(hsl);\\n\\\n */\\n\\\n \\n\\\nvec3 RGBtoHCV(vec3 rgb)\\n\\\n{\\n\\\n // Based on work by Sam Hocevar and Emil Persson\\n\\\n vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0);\\n\\\n vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);\\n\\\n float c = q.x - min(q.w, q.y);\\n\\\n float h = abs((q.w - q.y) / (6.0 * c + czm_epsilon7) + q.z);\\n\\\n return vec3(h, c, q.x);\\n\\\n}\\n\\\n\\n\\\nvec3 czm_RGBToHSL(vec3 rgb)\\n\\\n{\\n\\\n vec3 hcv = RGBtoHCV(rgb);\\n\\\n float l = hcv.z - hcv.y * 0.5;\\n\\\n float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + czm_epsilon7);\\n\\\n return vec3(hcv.x, s, l);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an RGB color to CIE Yxy.\\n\\\n *

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

\\n\\\n * \\n\\\n * @name czm_RGBToXYZ\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color in RGB.\\n\\\n *\\n\\\n * @returns {vec3} The color in CIE Yxy.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 xyz = czm_RGBToXYZ(rgb);\\n\\\n * xyz.x = max(xyz.x - luminanceThreshold, 0.0);\\n\\\n * rgb = czm_XYZToRGB(xyz);\\n\\\n */\\n\\\nvec3 czm_RGBToXYZ(vec3 rgb)\\n\\\n{\\n\\\n const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193,\\n\\\n 0.3576, 0.7152, 0.1192,\\n\\\n 0.1805, 0.0722, 0.9505);\\n\\\n vec3 xyz = RGB2XYZ * rgb;\\n\\\n vec3 Yxy;\\n\\\n Yxy.r = xyz.g;\\n\\\n float temp = dot(vec3(1.0), xyz);\\n\\\n Yxy.gb = xyz.rg / temp;\\n\\\n return Yxy;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts a CIE Yxy color to RGB.\\n\\\n *

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

\\n\\\n * \\n\\\n * @name czm_XYZToRGB\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} Yxy The color in CIE Yxy.\\n\\\n *\\n\\\n * @returns {vec3} The color in RGB.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 xyz = czm_RGBToXYZ(rgb);\\n\\\n * xyz.x = max(xyz.x - luminanceThreshold, 0.0);\\n\\\n * rgb = czm_XYZToRGB(xyz);\\n\\\n */\\n\\\nvec3 czm_XYZToRGB(vec3 Yxy)\\n\\\n{\\n\\\n const mat3 XYZ2RGB = mat3( 3.2405, -0.9693, 0.0556,\\n\\\n -1.5371, 1.8760, -0.2040,\\n\\\n -0.4985, 0.0416, 1.0572);\\n\\\n vec3 xyz;\\n\\\n xyz.r = Yxy.r * Yxy.g / Yxy.b;\\n\\\n xyz.g = Yxy.r;\\n\\\n xyz.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;\\n\\\n \\n\\\n return XYZ2RGB * xyz;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"// See:\\n\\\n// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/\\n\\\n\\n\\\nvec3 czm_acesTonemapping(vec3 color) {\\n\\\n float g = 0.985;\\n\\\n float a = 0.065;\\n\\\n float b = 0.0001;\\n\\\n float c = 0.433;\\n\\\n float d = 0.238;\\n\\\n\\n\\\n color = (color * (color + a) - b) / (color * (g * color + c) + d);\\n\\\n\\n\\\n color = clamp(color, 0.0, 1.0);\\n\\\n\\n\\\n return color;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * @private\\n\\\n */\\n\\\nfloat czm_alphaWeight(float a)\\n\\\n{\\n\\\n float z = (gl_FragCoord.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\\n\\\n\\n\\\n // See Weighted Blended Order-Independent Transparency for examples of different weighting functions:\\n\\\n // http://jcgt.org/published/0002/02/09/\\n\\\n 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))));\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Procedural anti-aliasing by blurring two colors that meet at a sharp edge.\\n\\\n *\\n\\\n * @name czm_antialias\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} color1 The color on one side of the edge.\\n\\\n * @param {vec4} color2 The color on the other side of the edge.\\n\\\n * @param {vec4} currentcolor The current color, either color1 or color2.\\n\\\n * @param {float} dist The distance to the edge in texture coordinates.\\n\\\n * @param {float} [fuzzFactor=0.1] Controls the blurriness between the two colors.\\n\\\n * @returns {vec4} The anti-aliased color.\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declarations\\n\\\n * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor);\\n\\\n * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist);\\n\\\n *\\n\\\n * // get the color for a material that has a sharp edge at the line y = 0.5 in texture space\\n\\\n * float dist = abs(textureCoordinates.t - 0.5);\\n\\\n * vec4 currentColor = mix(bottomColor, topColor, step(0.5, textureCoordinates.t));\\n\\\n * vec4 color = czm_antialias(bottomColor, topColor, currentColor, dist, 0.1);\\n\\\n */\\n\\\nvec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor)\\n\\\n{\\n\\\n float val1 = clamp(dist / fuzzFactor, 0.0, 1.0);\\n\\\n float val2 = clamp((dist - 0.5) / fuzzFactor, 0.0, 1.0);\\n\\\n val1 = val1 * (1.0 - val2);\\n\\\n val1 = val1 * val1 * (3.0 - (2.0 * val1));\\n\\\n val1 = pow(val1, 0.5); //makes the transition nicer\\n\\\n \\n\\\n vec4 midColor = (color1 + color2) * 0.5;\\n\\\n return mix(midColor, currentColor, val1);\\n\\\n}\\n\\\n\\n\\\nvec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist)\\n\\\n{\\n\\\n return czm_antialias(color1, color2, currentColor, dist, 0.1);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Approximately computes spherical coordinates given a normal.\\n\\\n * Uses approximate inverse trigonometry for speed and consistency,\\n\\\n * since inverse trigonometry can differ from vendor-to-vendor and when compared with the CPU.\\n\\\n *\\n\\\n * @name czm_approximateSphericalCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} normal arbitrary-length normal.\\n\\\n *\\n\\\n * @returns {vec2} Approximate latitude and longitude spherical coordinates.\\n\\\n */\\n\\\nvec2 czm_approximateSphericalCoordinates(vec3 normal) {\\n\\\n // Project into plane with vertical for latitude\\n\\\n float latitudeApproximation = czm_fastApproximateAtan(sqrt(normal.x * normal.x + normal.y * normal.y), normal.z);\\n\\\n float longitudeApproximation = czm_fastApproximateAtan(normal.x, normal.y);\\n\\\n return vec2(latitudeApproximation, longitudeApproximation);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Determines if the fragment is back facing\\n\\\n *\\n\\\n * @name czm_backFacing\\n\\\n * @glslFunction \\n\\\n * \\n\\\n * @returns {bool} true if the fragment is back facing; otherwise, false.\\n\\\n */\\n\\\nbool czm_backFacing()\\n\\\n{\\n\\\n // !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.\\n\\\n return gl_FrontFacing == false;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Branchless ternary operator to be used when it's inexpensive to explicitly\\n\\\n * evaluate both possibilities for a float expression.\\n\\\n *\\n\\\n * @name czm_branchFreeTernary\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {bool} comparison A comparison statement\\n\\\n * @param {float} a Value to return if the comparison is true.\\n\\\n * @param {float} b Value to return if the comparison is false.\\n\\\n *\\n\\\n * @returns {float} equivalent of comparison ? a : b\\n\\\n */\\n\\\nfloat czm_branchFreeTernary(bool comparison, float a, float b) {\\n\\\n float useA = float(comparison);\\n\\\n return a * useA + b * (1.0 - useA);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Branchless ternary operator to be used when it's inexpensive to explicitly\\n\\\n * evaluate both possibilities for a vec2 expression.\\n\\\n *\\n\\\n * @name czm_branchFreeTernary\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {bool} comparison A comparison statement\\n\\\n * @param {vec2} a Value to return if the comparison is true.\\n\\\n * @param {vec2} b Value to return if the comparison is false.\\n\\\n *\\n\\\n * @returns {vec2} equivalent of comparison ? a : b\\n\\\n */\\n\\\nvec2 czm_branchFreeTernary(bool comparison, vec2 a, vec2 b) {\\n\\\n float useA = float(comparison);\\n\\\n return a * useA + b * (1.0 - useA);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Branchless ternary operator to be used when it's inexpensive to explicitly\\n\\\n * evaluate both possibilities for a vec3 expression.\\n\\\n *\\n\\\n * @name czm_branchFreeTernary\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {bool} comparison A comparison statement\\n\\\n * @param {vec3} a Value to return if the comparison is true.\\n\\\n * @param {vec3} b Value to return if the comparison is false.\\n\\\n *\\n\\\n * @returns {vec3} equivalent of comparison ? a : b\\n\\\n */\\n\\\nvec3 czm_branchFreeTernary(bool comparison, vec3 a, vec3 b) {\\n\\\n float useA = float(comparison);\\n\\\n return a * useA + b * (1.0 - useA);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Branchless ternary operator to be used when it's inexpensive to explicitly\\n\\\n * evaluate both possibilities for a vec4 expression.\\n\\\n *\\n\\\n * @name czm_branchFreeTernary\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {bool} comparison A comparison statement\\n\\\n * @param {vec3} a Value to return if the comparison is true.\\n\\\n * @param {vec3} b Value to return if the comparison is false.\\n\\\n *\\n\\\n * @returns {vec3} equivalent of comparison ? a : b\\n\\\n */\\n\\\nvec4 czm_branchFreeTernary(bool comparison, vec4 a, vec4 b) {\\n\\\n float useA = float(comparison);\\n\\\n return a * useA + b * (1.0 - useA);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nvec4 czm_cascadeColor(vec4 weights)\\n\\\n{\\n\\\n return vec4(1.0, 0.0, 0.0, 1.0) * weights.x +\\n\\\n vec4(0.0, 1.0, 0.0, 1.0) * weights.y +\\n\\\n vec4(0.0, 0.0, 1.0, 1.0) * weights.z +\\n\\\n vec4(1.0, 0.0, 1.0, 1.0) * weights.w;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nuniform vec4 shadowMap_cascadeDistances;\\n\\\n\\n\\\nfloat czm_cascadeDistance(vec4 weights)\\n\\\n{\\n\\\n return dot(shadowMap_cascadeDistances, weights);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nuniform mat4 shadowMap_cascadeMatrices[4];\\n\\\n\\n\\\nmat4 czm_cascadeMatrix(vec4 weights)\\n\\\n{\\n\\\n return shadowMap_cascadeMatrices[0] * weights.x +\\n\\\n shadowMap_cascadeMatrices[1] * weights.y +\\n\\\n shadowMap_cascadeMatrices[2] * weights.z +\\n\\\n shadowMap_cascadeMatrices[3] * weights.w;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nuniform vec4 shadowMap_cascadeSplits[2];\\n\\\n\\n\\\nvec4 czm_cascadeWeights(float depthEye)\\n\\\n{\\n\\\n // One component is set to 1.0 and all others set to 0.0.\\n\\\n vec4 near = step(shadowMap_cascadeSplits[0], vec4(depthEye));\\n\\\n vec4 far = step(depthEye, shadowMap_cascadeSplits[1]);\\n\\\n return near * far;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_columbusViewMorph\\n\\\n * @glslFunction\\n\\\n */\\n\\\nvec4 czm_columbusViewMorph(vec4 position2D, vec4 position3D, float time)\\n\\\n{\\n\\\n // Just linear for now.\\n\\\n vec3 p = mix(position2D.xyz, position3D.xyz, time);\\n\\\n return vec4(p, 1.0);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Returns a position in model coordinates relative to eye taking into\\n\\\n * account the current scene mode: 3D, 2D, or Columbus view.\\n\\\n *

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

\\n\\\n *\\n\\\n * @name czm_computePosition\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @returns {vec4} The position relative to eye.\\n\\\n *\\n\\\n * @example\\n\\\n * vec4 p = czm_computePosition();\\n\\\n * v_positionEC = (czm_modelViewRelativeToEye * p).xyz;\\n\\\n * gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n *\\n\\\n * @see czm_translateRelativeToEye\\n\\\n */\\n\\\nvec4 czm_computePosition();\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * @private\\n\\\n */\\n\\\nvec2 cordic(float angle)\\n\\\n{\\n\\\n// Scale the vector by the appropriate factor for the 24 iterations to follow.\\n\\\n vec2 vector = vec2(6.0725293500888267e-1, 0.0);\\n\\\n// Iteration 1\\n\\\n float sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n // float factor = sense * 1.0; // 2^-0\\n\\\n mat2 rotation = mat2(1.0, sense, -sense, 1.0);\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 7.8539816339744828e-1; // atan(2^-0)\\n\\\n// Iteration 2\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n float factor = sense * 5.0e-1; // 2^-1\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 4.6364760900080609e-1; // atan(2^-1)\\n\\\n// Iteration 3\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 2.5e-1; // 2^-2\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 2.4497866312686414e-1; // atan(2^-2)\\n\\\n// Iteration 4\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.25e-1; // 2^-3\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.2435499454676144e-1; // atan(2^-3)\\n\\\n// Iteration 5\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 6.25e-2; // 2^-4\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 6.2418809995957350e-2; // atan(2^-4)\\n\\\n// Iteration 6\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 3.125e-2; // 2^-5\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 3.1239833430268277e-2; // atan(2^-5)\\n\\\n// Iteration 7\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.5625e-2; // 2^-6\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.5623728620476831e-2; // atan(2^-6)\\n\\\n// Iteration 8\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 7.8125e-3; // 2^-7\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 7.8123410601011111e-3; // atan(2^-7)\\n\\\n// Iteration 9\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 3.90625e-3; // 2^-8\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 3.9062301319669718e-3; // atan(2^-8)\\n\\\n// Iteration 10\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.953125e-3; // 2^-9\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.9531225164788188e-3; // atan(2^-9)\\n\\\n// Iteration 11\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 9.765625e-4; // 2^-10\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 9.7656218955931946e-4; // atan(2^-10)\\n\\\n// Iteration 12\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 4.8828125e-4; // 2^-11\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 4.8828121119489829e-4; // atan(2^-11)\\n\\\n// Iteration 13\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 2.44140625e-4; // 2^-12\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 2.4414062014936177e-4; // atan(2^-12)\\n\\\n// Iteration 14\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.220703125e-4; // 2^-13\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.2207031189367021e-4; // atan(2^-13)\\n\\\n// Iteration 15\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 6.103515625e-5; // 2^-14\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 6.1035156174208773e-5; // atan(2^-14)\\n\\\n// Iteration 16\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 3.0517578125e-5; // 2^-15\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 3.0517578115526096e-5; // atan(2^-15)\\n\\\n// Iteration 17\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.52587890625e-5; // 2^-16\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.5258789061315762e-5; // atan(2^-16)\\n\\\n// Iteration 18\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 7.62939453125e-6; // 2^-17\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 7.6293945311019700e-6; // atan(2^-17)\\n\\\n// Iteration 19\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 3.814697265625e-6; // 2^-18\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 3.8146972656064961e-6; // atan(2^-18)\\n\\\n// Iteration 20\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.9073486328125e-6; // 2^-19\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 1.9073486328101870e-6; // atan(2^-19)\\n\\\n// Iteration 21\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 9.5367431640625e-7; // 2^-20\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 9.5367431640596084e-7; // atan(2^-20)\\n\\\n// Iteration 22\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 4.76837158203125e-7; // 2^-21\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 4.7683715820308884e-7; // atan(2^-21)\\n\\\n// Iteration 23\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 2.384185791015625e-7; // 2^-22\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n angle -= sense * 2.3841857910155797e-7; // atan(2^-22)\\n\\\n// Iteration 24\\n\\\n sense = (angle < 0.0) ? -1.0 : 1.0;\\n\\\n factor = sense * 1.1920928955078125e-7; // 2^-23\\n\\\n rotation[0][1] = factor;\\n\\\n rotation[1][0] = -factor;\\n\\\n vector = rotation * vector;\\n\\\n// angle -= sense * 1.1920928955078068e-7; // atan(2^-23)\\n\\\n\\n\\\n return vector;\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Computes the cosine and sine of the provided angle using the CORDIC algorithm.\\n\\\n *\\n\\\n * @name czm_cosineAndSine\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} angle The angle in radians.\\n\\\n *\\n\\\n * @returns {vec2} The resulting cosine of the angle (as the x coordinate) and sine of the angle (as the y coordinate).\\n\\\n *\\n\\\n * @example\\n\\\n * vec2 v = czm_cosineAndSine(czm_piOverSix);\\n\\\n * float cosine = v.x;\\n\\\n * float sine = v.y;\\n\\\n */\\n\\\nvec2 czm_cosineAndSine(float angle)\\n\\\n{\\n\\\n if (angle < -czm_piOverTwo || angle > czm_piOverTwo)\\n\\\n {\\n\\\n if (angle < 0.0)\\n\\\n {\\n\\\n return -cordic(angle + czm_pi);\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n return -cordic(angle - czm_pi);\\n\\\n }\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n return cordic(angle);\\n\\\n }\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Decompresses texture coordinates that were packed into a single float.\\n\\\n *\\n\\\n * @name czm_decompressTextureCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} encoded The compressed texture coordinates.\\n\\\n * @returns {vec2} The decompressed texture coordinates.\\n\\\n */\\n\\\n vec2 czm_decompressTextureCoordinates(float encoded)\\n\\\n {\\n\\\n float temp = encoded / 4096.0;\\n\\\n float xZeroTo4095 = floor(temp);\\n\\\n float stx = xZeroTo4095 / 4095.0;\\n\\\n float sty = (encoded - xZeroTo4095 * 4096.0) / 4095.0;\\n\\\n return vec2(stx, sty);\\n\\\n }\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Get default parameters for physically based rendering. These defaults\\n\\\n * describe a rough dielectric (non-metal) surface (e.g. rough plastic).\\n\\\n *\\n\\\n * @return {czm_pbrParameters} Default parameters for {@link czm_pbrLighting}\\n\\\n */\\n\\\nczm_pbrParameters czm_defaultPbrMaterial()\\n\\\n{\\n\\\n czm_pbrParameters results;\\n\\\n results.diffuseColor = vec3(1.0);\\n\\\n results.roughness = 1.0;\\n\\\n\\n\\\n const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);\\n\\\n results.f0 = REFLECTANCE_DIELECTRIC;\\n\\\n return results;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"// emulated noperspective\\n\\\n#if (__VERSION__ == 300 || defined(GL_EXT_frag_depth)) && !defined(LOG_DEPTH)\\n\\\nout float v_WindowZ;\\n\\\n#endif\\n\\\n\\n\\\n/**\\n\\\n * Emulates GL_DEPTH_CLAMP, which is not available in WebGL 1 or 2.\\n\\\n * GL_DEPTH_CLAMP clamps geometry that is outside the near and far planes, \\n\\\n * capping the shadow volume. More information here: \\n\\\n * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_depth_clamp.txt.\\n\\\n *\\n\\\n * When GL_EXT_frag_depth is available we emulate GL_DEPTH_CLAMP by ensuring \\n\\\n * no geometry gets clipped by setting the clip space z value to 0.0 and then\\n\\\n * sending the unaltered screen space z value (using emulated noperspective\\n\\\n * interpolation) to the frag shader where it is clamped to [0,1] and then\\n\\\n * written with gl_FragDepth (see czm_writeDepthClamp). This technique is based on:\\n\\\n * https://stackoverflow.com/questions/5960757/how-to-emulate-gl-depth-clamp-nv.\\n\\\n *\\n\\\n * When GL_EXT_frag_depth is not available, which is the case on some mobile \\n\\\n * devices, we must attempt to fix this only in the vertex shader. \\n\\\n * The approach is to clamp the z value to the far plane, which closes the \\n\\\n * shadow volume but also distorts the geometry, so there can still be artifacts\\n\\\n * on frustum seams.\\n\\\n *\\n\\\n * @name czm_depthClamp\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} coords The vertex in clip coordinates.\\n\\\n * @returns {vec4} The modified vertex.\\n\\\n *\\n\\\n * @example\\n\\\n * gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));\\n\\\n *\\n\\\n * @see czm_writeDepthClamp\\n\\\n */\\n\\\nvec4 czm_depthClamp(vec4 coords)\\n\\\n{\\n\\\n#ifndef LOG_DEPTH\\n\\\n#if __VERSION__ == 300 || defined(GL_EXT_frag_depth)\\n\\\n v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;\\n\\\n coords.z = 0.0;\\n\\\n#else\\n\\\n coords.z = min(coords.z, coords.w);\\n\\\n#endif\\n\\\n#endif\\n\\\n return coords;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes a 3x3 rotation matrix that transforms vectors from an ellipsoid's east-north-up coordinate system \\n\\\n * to eye coordinates. In east-north-up coordinates, x points east, y points north, and z points along the \\n\\\n * surface normal. East-north-up can be used as an ellipsoid's tangent space for operations such as bump mapping.\\n\\\n *

\\n\\\n * The ellipsoid is assumed to be centered at the model coordinate's origin.\\n\\\n *\\n\\\n * @name czm_eastNorthUpToEyeCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} positionMC The position on the ellipsoid in model coordinates.\\n\\\n * @param {vec3} normalEC The normalized ellipsoid surface normal, at positionMC, in eye coordinates.\\n\\\n *\\n\\\n * @returns {mat3} A 3x3 rotation matrix that transforms vectors from the east-north-up coordinate system to eye coordinates.\\n\\\n *\\n\\\n * @example\\n\\\n * // Transform a vector defined in the east-north-up coordinate \\n\\\n * // system, (0, 0, 1) which is the surface normal, to eye \\n\\\n * // coordinates.\\n\\\n * mat3 m = czm_eastNorthUpToEyeCoordinates(positionMC, normalEC);\\n\\\n * vec3 normalEC = m * vec3(0.0, 0.0, 1.0);\\n\\\n */\\n\\\nmat3 czm_eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)\\n\\\n{\\n\\\n vec3 tangentMC = normalize(vec3(-positionMC.y, positionMC.x, 0.0)); // normalized surface tangent in model coordinates\\n\\\n vec3 tangentEC = normalize(czm_normal3D * tangentMC); // normalized surface tangent in eye coordinates\\n\\\n vec3 bitangentEC = normalize(cross(normalEC, tangentEC)); // normalized surface bitangent in eye coordinates\\n\\\n\\n\\\n return mat3(\\n\\\n tangentEC.x, tangentEC.y, tangentEC.z,\\n\\\n bitangentEC.x, bitangentEC.y, bitangentEC.z,\\n\\\n normalEC.x, normalEC.y, normalEC.z);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_ellipsoidContainsPoint\\n\\\n * @glslFunction\\n\\\n *\\n\\\n */\\n\\\nbool czm_ellipsoidContainsPoint(vec3 ellipsoid_inverseRadii, vec3 point)\\n\\\n{\\n\\\n vec3 scaled = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(point, 1.0)).xyz;\\n\\\n return (dot(scaled, scaled) <= 1.0);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_ellipsoidWgs84TextureCoordinates\\n\\\n * @glslFunction\\n\\\n */\\n\\\nvec2 czm_ellipsoidWgs84TextureCoordinates(vec3 normal)\\n\\\n{\\n\\\n return vec2(atan(normal.y, normal.x) * czm_oneOverTwoPi + 0.5, asin(normal.z) * czm_oneOverPi + 0.5);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Compares left and right componentwise. Returns true\\n\\\n * if they are within epsilon and false otherwise. The inputs\\n\\\n * left and right can be floats, vec2s,\\n\\\n * vec3s, or vec4s.\\n\\\n *\\n\\\n * @name czm_equalsEpsilon\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {} left The first vector.\\n\\\n * @param {} right The second vector.\\n\\\n * @param {float} epsilon The epsilon to use for equality testing.\\n\\\n * @returns {bool} true if the components are within epsilon and false otherwise.\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declarations\\n\\\n * bool czm_equalsEpsilon(float left, float right, float epsilon);\\n\\\n * bool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon);\\n\\\n * bool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon);\\n\\\n * bool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon);\\n\\\n */\\n\\\nbool czm_equalsEpsilon(vec4 left, vec4 right, float epsilon) {\\n\\\n return all(lessThanEqual(abs(left - right), vec4(epsilon)));\\n\\\n}\\n\\\n\\n\\\nbool czm_equalsEpsilon(vec3 left, vec3 right, float epsilon) {\\n\\\n return all(lessThanEqual(abs(left - right), vec3(epsilon)));\\n\\\n}\\n\\\n\\n\\\nbool czm_equalsEpsilon(vec2 left, vec2 right, float epsilon) {\\n\\\n return all(lessThanEqual(abs(left - right), vec2(epsilon)));\\n\\\n}\\n\\\n\\n\\\nbool czm_equalsEpsilon(float left, float right, float epsilon) {\\n\\\n return (abs(left - right) <= epsilon);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_eyeOffset\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} positionEC DOC_TBA.\\n\\\n * @param {vec3} eyeOffset DOC_TBA.\\n\\\n *\\n\\\n * @returns {vec4} DOC_TBA.\\n\\\n */\\n\\\nvec4 czm_eyeOffset(vec4 positionEC, vec3 eyeOffset)\\n\\\n{\\n\\\n // This equation is approximate in x and y.\\n\\\n vec4 p = positionEC;\\n\\\n vec4 zEyeOffset = normalize(p) * eyeOffset.z;\\n\\\n p.xy += eyeOffset.xy + zEyeOffset.xy;\\n\\\n p.z += zEyeOffset.z;\\n\\\n return p;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Transforms a position from eye to window coordinates. The transformation\\n\\\n * from eye to clip coordinates is done using {@link czm_projection}.\\n\\\n * The transform from normalized device coordinates to window coordinates is\\n\\\n * done using {@link czm_viewportTransformation}, which assumes a depth range\\n\\\n * of near = 0 and far = 1.\\n\\\n *

\\n\\\n * This transform is useful when there is a need to manipulate window coordinates\\n\\\n * in a vertex shader as done by {@link BillboardCollection}.\\n\\\n *\\n\\\n * @name czm_eyeToWindowCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} position The position in eye coordinates to transform.\\n\\\n *\\n\\\n * @returns {vec4} The transformed position in window coordinates.\\n\\\n *\\n\\\n * @see czm_modelToWindowCoordinates\\n\\\n * @see czm_projection\\n\\\n * @see czm_viewportTransformation\\n\\\n * @see BillboardCollection\\n\\\n *\\n\\\n * @example\\n\\\n * vec4 positionWC = czm_eyeToWindowCoordinates(positionEC);\\n\\\n */\\n\\\nvec4 czm_eyeToWindowCoordinates(vec4 positionEC)\\n\\\n{\\n\\\n vec4 q = czm_projection * positionEC; // clip coordinates\\n\\\n q.xyz /= q.w; // normalized device coordinates\\n\\\n q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates\\n\\\n return q;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Approxiamtes atan over the range [0, 1]. Safe to flip output for negative input.\\n\\\n *\\n\\\n * Based on Michal Drobot's approximation from ShaderFastLibs, which in turn is based on\\n\\\n * \\\"Efficient approximations for the arctangent function,\\\" Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.\\n\\\n * Adapted from ShaderFastLibs under MIT License.\\n\\\n *\\n\\\n * Chosen for the following characteristics over range [0, 1]:\\n\\\n * - basically no error at 0 and 1, important for getting around range limit (naive atan2 via atan requires infinite range atan)\\n\\\n * - no visible artifacts from first-derivative discontinuities, unlike latitude via range-reduced sqrt asin approximations (at equator)\\n\\\n *\\n\\\n * The original code is x * (-0.1784 * abs(x) - 0.0663 * x * x + 1.0301);\\n\\\n * Removed the abs() in here because it isn't needed, the input range is guaranteed as [0, 1] by how we're approximating atan2.\\n\\\n *\\n\\\n * @name czm_fastApproximateAtan\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} x Value between 0 and 1 inclusive.\\n\\\n *\\n\\\n * @returns {float} Approximation of atan(x)\\n\\\n */\\n\\\nfloat czm_fastApproximateAtan(float x) {\\n\\\n return x * (-0.1784 * x - 0.0663 * x * x + 1.0301);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Approximation of atan2.\\n\\\n *\\n\\\n * Range reduction math based on nvidia's cg reference implementation for atan2: http://developer.download.nvidia.com/cg/atan2.html\\n\\\n * However, we replaced their atan curve with Michael Drobot's (see above).\\n\\\n *\\n\\\n * @name czm_fastApproximateAtan\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} x Value between -1 and 1 inclusive.\\n\\\n * @param {float} y Value between -1 and 1 inclusive.\\n\\\n *\\n\\\n * @returns {float} Approximation of atan2(x, y)\\n\\\n */\\n\\\nfloat czm_fastApproximateAtan(float x, float y) {\\n\\\n // atan approximations are usually only reliable over [-1, 1], or, in our case, [0, 1] due to modifications.\\n\\\n // So range-reduce using abs and by flipping whether x or y is on top.\\n\\\n float t = abs(x); // t used as swap and atan result.\\n\\\n float opposite = abs(y);\\n\\\n float adjacent = max(t, opposite);\\n\\\n opposite = min(t, opposite);\\n\\\n\\n\\\n t = czm_fastApproximateAtan(opposite / adjacent);\\n\\\n\\n\\\n // Undo range reduction\\n\\\n t = czm_branchFreeTernary(abs(y) > abs(x), czm_piOverTwo - t, t);\\n\\\n t = czm_branchFreeTernary(x < 0.0, czm_pi - t, t);\\n\\\n t = czm_branchFreeTernary(y < 0.0, -t, t);\\n\\\n return t;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Gets the color with fog at a distance from the camera.\\n\\\n *\\n\\\n * @name czm_fog\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} distanceToCamera The distance to the camera in meters.\\n\\\n * @param {vec3} color The original color.\\n\\\n * @param {vec3} fogColor The color of the fog.\\n\\\n *\\n\\\n * @returns {vec3} The color adjusted for fog at the distance from the camera.\\n\\\n */\\n\\\nvec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor)\\n\\\n{\\n\\\n float scalar = distanceToCamera * czm_fogDensity;\\n\\\n float fog = 1.0 - exp(-(scalar * scalar));\\n\\\n return mix(color, fogColor, fog);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Gets the color with fog at a distance from the camera.\\n\\\n *\\n\\\n * @name czm_fog\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} distanceToCamera The distance to the camera in meters.\\n\\\n * @param {vec3} color The original color.\\n\\\n * @param {vec3} fogColor The color of the fog.\\n\\\n * @param {float} fogModifierConstant A constant to modify the appearance of fog.\\n\\\n *\\n\\\n * @returns {vec3} The color adjusted for fog at the distance from the camera.\\n\\\n */\\n\\\nvec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor, float fogModifierConstant)\\n\\\n{\\n\\\n float scalar = distanceToCamera * czm_fogDensity;\\n\\\n float fog = 1.0 - exp(-((fogModifierConstant * scalar + fogModifierConstant) * (scalar * (1.0 + fogModifierConstant))));\\n\\\n return mix(color, fogColor, fog);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts a color from RGB space to linear space.\\n\\\n *\\n\\\n * @name czm_gammaCorrect\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} color The color in RGB space.\\n\\\n * @returns {vec3} The color in linear space.\\n\\\n */\\n\\\nvec3 czm_gammaCorrect(vec3 color) {\\n\\\n#ifdef HDR\\n\\\n color = pow(color, vec3(czm_gamma));\\n\\\n#endif\\n\\\n return color;\\n\\\n}\\n\\\n\\n\\\nvec4 czm_gammaCorrect(vec4 color) {\\n\\\n#ifdef HDR\\n\\\n color.rgb = pow(color.rgb, vec3(czm_gamma));\\n\\\n#endif\\n\\\n return color;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_geodeticSurfaceNormal\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} positionOnEllipsoid DOC_TBA\\n\\\n * @param {vec3} ellipsoidCenter DOC_TBA\\n\\\n * @param {vec3} oneOverEllipsoidRadiiSquared DOC_TBA\\n\\\n * \\n\\\n * @returns {vec3} DOC_TBA.\\n\\\n */\\n\\\nvec3 czm_geodeticSurfaceNormal(vec3 positionOnEllipsoid, vec3 ellipsoidCenter, vec3 oneOverEllipsoidRadiiSquared)\\n\\\n{\\n\\\n return normalize((positionOnEllipsoid - ellipsoidCenter) * oneOverEllipsoidRadiiSquared);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * An czm_material with default values. Every material's czm_getMaterial\\n\\\n * should use this default material as a base for the material it returns.\\n\\\n * The default normal value is given by materialInput.normalEC.\\n\\\n *\\n\\\n * @name czm_getDefaultMaterial\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {czm_materialInput} input The input used to construct the default material.\\n\\\n *\\n\\\n * @returns {czm_material} The default material.\\n\\\n *\\n\\\n * @see czm_materialInput\\n\\\n * @see czm_material\\n\\\n * @see czm_getMaterial\\n\\\n */\\n\\\nczm_material czm_getDefaultMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material;\\n\\\n material.diffuse = vec3(0.0);\\n\\\n material.specular = 0.0;\\n\\\n material.shininess = 1.0;\\n\\\n material.normal = materialInput.normalEC;\\n\\\n material.emission = vec3(0.0);\\n\\\n material.alpha = 1.0;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Calculates the intensity of diffusely reflected light.\\n\\\n *\\n\\\n * @name czm_getLambertDiffuse\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\\n\\\n * @param {vec3} normalEC The surface normal in eye coordinates.\\n\\\n *\\n\\\n * @returns {float} The intensity of the diffuse reflection.\\n\\\n *\\n\\\n * @see czm_phong\\n\\\n *\\n\\\n * @example\\n\\\n * float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);\\n\\\n * float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);\\n\\\n * vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);\\n\\\n */\\n\\\nfloat czm_getLambertDiffuse(vec3 lightDirectionEC, vec3 normalEC)\\n\\\n{\\n\\\n return max(dot(lightDirectionEC, normalEC), 0.0);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Calculates the specular intensity of reflected light.\\n\\\n *\\n\\\n * @name czm_getSpecular\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\\n\\\n * @param {vec3} toEyeEC Unit vector pointing to the eye position in eye coordinates.\\n\\\n * @param {vec3} normalEC The surface normal in eye coordinates.\\n\\\n * @param {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.\\n\\\n *\\n\\\n * @returns {float} The intensity of the specular highlight.\\n\\\n *\\n\\\n * @see czm_phong\\n\\\n *\\n\\\n * @example\\n\\\n * float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);\\n\\\n * float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);\\n\\\n * vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);\\n\\\n */\\n\\\nfloat czm_getSpecular(vec3 lightDirectionEC, vec3 toEyeEC, vec3 normalEC, float shininess)\\n\\\n{\\n\\\n vec3 toReflectedLight = reflect(-lightDirectionEC, normalEC);\\n\\\n float specular = max(dot(toReflectedLight, toEyeEC), 0.0);\\n\\\n\\n\\\n // pow has undefined behavior if both parameters <= 0.\\n\\\n // Prevent this by making sure shininess is at least czm_epsilon2.\\n\\\n return pow(specular, max(shininess, czm_epsilon2));\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * @private\\n\\\n */\\n\\\nvec4 czm_getWaterNoise(sampler2D normalMap, vec2 uv, float time, float angleInRadians)\\n\\\n{\\n\\\n float cosAngle = cos(angleInRadians);\\n\\\n float sinAngle = sin(angleInRadians);\\n\\\n\\n\\\n // time dependent sampling directions\\n\\\n vec2 s0 = vec2(1.0/17.0, 0.0);\\n\\\n vec2 s1 = vec2(-1.0/29.0, 0.0);\\n\\\n vec2 s2 = vec2(1.0/101.0, 1.0/59.0);\\n\\\n vec2 s3 = vec2(-1.0/109.0, -1.0/57.0);\\n\\\n\\n\\\n // rotate sampling direction by specified angle\\n\\\n s0 = vec2((cosAngle * s0.x) - (sinAngle * s0.y), (sinAngle * s0.x) + (cosAngle * s0.y));\\n\\\n s1 = vec2((cosAngle * s1.x) - (sinAngle * s1.y), (sinAngle * s1.x) + (cosAngle * s1.y));\\n\\\n s2 = vec2((cosAngle * s2.x) - (sinAngle * s2.y), (sinAngle * s2.x) + (cosAngle * s2.y));\\n\\\n s3 = vec2((cosAngle * s3.x) - (sinAngle * s3.y), (sinAngle * s3.x) + (cosAngle * s3.y));\\n\\\n\\n\\\n vec2 uv0 = (uv/103.0) + (time * s0);\\n\\\n vec2 uv1 = uv/107.0 + (time * s1) + vec2(0.23);\\n\\\n vec2 uv2 = uv/vec2(897.0, 983.0) + (time * s2) + vec2(0.51);\\n\\\n vec2 uv3 = uv/vec2(991.0, 877.0) + (time * s3) + vec2(0.71);\\n\\\n\\n\\\n uv0 = fract(uv0);\\n\\\n uv1 = fract(uv1);\\n\\\n uv2 = fract(uv2);\\n\\\n uv3 = fract(uv3);\\n\\\n vec4 noise = (texture(normalMap, uv0)) +\\n\\\n (texture(normalMap, uv1)) +\\n\\\n (texture(normalMap, uv2)) +\\n\\\n (texture(normalMap, uv3));\\n\\\n\\n\\\n // average and scale to between -1 and 1\\n\\\n return ((noise / 4.0) - 0.5) * 2.0;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Adjusts the hue of a color.\\n\\\n * \\n\\\n * @name czm_hue\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color.\\n\\\n * @param {float} adjustment The amount to adjust the hue of the color in radians.\\n\\\n *\\n\\\n * @returns {float} The color with the hue adjusted.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 adjustHue = czm_hue(color, czm_pi); // The same as czm_hue(color, -czm_pi)\\n\\\n */\\n\\\nvec3 czm_hue(vec3 rgb, float adjustment)\\n\\\n{\\n\\\n const mat3 toYIQ = mat3(0.299, 0.587, 0.114,\\n\\\n 0.595716, -0.274453, -0.321263,\\n\\\n 0.211456, -0.522591, 0.311135);\\n\\\n const mat3 toRGB = mat3(1.0, 0.9563, 0.6210,\\n\\\n 1.0, -0.2721, -0.6474,\\n\\\n 1.0, -1.107, 1.7046);\\n\\\n \\n\\\n vec3 yiq = toYIQ * rgb;\\n\\\n float hue = atan(yiq.z, yiq.y) + adjustment;\\n\\\n float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);\\n\\\n \\n\\\n vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));\\n\\\n return toRGB * color;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts a color in linear space to RGB space.\\n\\\n *\\n\\\n * @name czm_inverseGamma\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} color The color in linear space.\\n\\\n * @returns {vec3} The color in RGB space.\\n\\\n */\\n\\\nvec3 czm_inverseGamma(vec3 color) {\\n\\\n return pow(color, vec3(1.0 / czm_gamma));\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Determines if a time interval is empty.\\n\\\n *\\n\\\n * @name czm_isEmpty\\n\\\n * @glslFunction \\n\\\n * \\n\\\n * @param {czm_raySegment} interval The interval to test.\\n\\\n * \\n\\\n * @returns {bool} true if the time interval is empty; otherwise, false.\\n\\\n *\\n\\\n * @example\\n\\\n * bool b0 = czm_isEmpty(czm_emptyRaySegment); // true\\n\\\n * bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false\\n\\\n * bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.\\n\\\n */\\n\\\nbool czm_isEmpty(czm_raySegment interval)\\n\\\n{\\n\\\n return (interval.stop < 0.0);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Determines if a time interval is empty.\\n\\\n *\\n\\\n * @name czm_isFull\\n\\\n * @glslFunction \\n\\\n * \\n\\\n * @param {czm_raySegment} interval The interval to test.\\n\\\n * \\n\\\n * @returns {bool} true if the time interval is empty; otherwise, false.\\n\\\n *\\n\\\n * @example\\n\\\n * bool b0 = czm_isEmpty(czm_emptyRaySegment); // true\\n\\\n * bool b1 = czm_isEmpty(czm_raySegment(0.0, 1.0)); // false\\n\\\n * bool b2 = czm_isEmpty(czm_raySegment(1.0, 1.0)); // false, contains 1.0.\\n\\\n */\\n\\\nbool czm_isFull(czm_raySegment interval)\\n\\\n{\\n\\\n return (interval.start == 0.0 && interval.stop == czm_infinity);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes the fraction of a Web Wercator rectangle at which a given geodetic latitude is located.\\n\\\n *\\n\\\n * @name czm_latitudeToWebMercatorFraction\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} latitude The geodetic latitude, in radians.\\n\\\n * @param {float} southMercatorY The Web Mercator coordinate of the southern boundary of the rectangle.\\n\\\n * @param {float} oneOverMercatorHeight The total height of the rectangle in Web Mercator coordinates.\\n\\\n *\\n\\\n * @returns {float} The fraction of the rectangle at which the latitude occurs. If the latitude is the southern\\n\\\n * boundary of the rectangle, the return value will be zero. If it is the northern boundary, the return\\n\\\n * value will be 1.0. Latitudes in between are mapped according to the Web Mercator projection.\\n\\\n */ \\n\\\nfloat czm_latitudeToWebMercatorFraction(float latitude, float southMercatorY, float oneOverMercatorHeight)\\n\\\n{\\n\\\n float sinLatitude = sin(latitude);\\n\\\n float mercatorY = 0.5 * log((1.0 + sinLatitude) / (1.0 - sinLatitude));\\n\\\n \\n\\\n return (mercatorY - southMercatorY) * oneOverMercatorHeight;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes distance from an point in 2D to a line in 2D.\\n\\\n *\\n\\\n * @name czm_lineDistance\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * param {vec2} point1 A point along the line.\\n\\\n * param {vec2} point2 A point along the line.\\n\\\n * param {vec2} point A point that may or may not be on the line.\\n\\\n * returns {float} The distance from the point to the line.\\n\\\n */\\n\\\nfloat czm_lineDistance(vec2 point1, vec2 point2, vec2 point) {\\n\\\n 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);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts a linear RGB color to an sRGB color.\\n\\\n *\\n\\\n * @param {vec3|vec4} linearIn The color in linear color space.\\n\\\n * @returns {vec3|vec4} The color in sRGB color space. The vector type matches the input.\\n\\\n */\\n\\\nvec3 czm_linearToSrgb(vec3 linearIn) \\n\\\n{\\n\\\n return pow(linearIn, vec3(1.0/2.2));\\n\\\n}\\n\\\n\\n\\\nvec4 czm_linearToSrgb(vec4 linearIn) \\n\\\n{\\n\\\n vec3 srgbOut = pow(linearIn.rgb, vec3(1.0/2.2));\\n\\\n return vec4(srgbOut, linearIn.a);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes the luminance of a color. \\n\\\n *\\n\\\n * @name czm_luminance\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} rgb The color.\\n\\\n * \\n\\\n * @returns {float} The luminance.\\n\\\n *\\n\\\n * @example\\n\\\n * float light = czm_luminance(vec3(0.0)); // 0.0\\n\\\n * float dark = czm_luminance(vec3(1.0)); // ~1.0 \\n\\\n */\\n\\\nfloat czm_luminance(vec3 rgb)\\n\\\n{\\n\\\n // Algorithm from Chapter 10 of Graphics Shaders.\\n\\\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\\n\\\n return dot(rgb, W);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes the size of a pixel in meters at a distance from the eye.\\n\\\n *

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

\\n\\\n * @name czm_metersPerPixel\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.\\n\\\n * @param {float} pixelRatio The scaling factor from pixel space to coordinate space\\n\\\n *\\n\\\n * @returns {float} The meters per pixel at positionEC.\\n\\\n */\\n\\\nfloat czm_metersPerPixel(vec4 positionEC, float pixelRatio)\\n\\\n{\\n\\\n float width = czm_viewport.z;\\n\\\n float height = czm_viewport.w;\\n\\\n float pixelWidth;\\n\\\n float pixelHeight;\\n\\\n\\n\\\n float top = czm_frustumPlanes.x;\\n\\\n float bottom = czm_frustumPlanes.y;\\n\\\n float left = czm_frustumPlanes.z;\\n\\\n float right = czm_frustumPlanes.w;\\n\\\n\\n\\\n if (czm_sceneMode == czm_sceneMode2D || czm_orthographicIn3D == 1.0)\\n\\\n {\\n\\\n float frustumWidth = right - left;\\n\\\n float frustumHeight = top - bottom;\\n\\\n pixelWidth = frustumWidth / width;\\n\\\n pixelHeight = frustumHeight / height;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n float distanceToPixel = -positionEC.z;\\n\\\n float inverseNear = 1.0 / czm_currentFrustum.x;\\n\\\n float tanTheta = top * inverseNear;\\n\\\n pixelHeight = 2.0 * distanceToPixel * tanTheta / height;\\n\\\n tanTheta = right * inverseNear;\\n\\\n pixelWidth = 2.0 * distanceToPixel * tanTheta / width;\\n\\\n }\\n\\\n\\n\\\n return max(pixelWidth, pixelHeight) * pixelRatio;\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Computes the size of a pixel in meters at a distance from the eye.\\n\\\n *

\\n\\\n * Use this version when scaling by pixel ratio.\\n\\\n *

\\n\\\n * @name czm_metersPerPixel\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.\\n\\\n *\\n\\\n * @returns {float} The meters per pixel at positionEC.\\n\\\n */\\n\\\nfloat czm_metersPerPixel(vec4 positionEC)\\n\\\n{\\n\\\n return czm_metersPerPixel(positionEC, czm_pixelRatio);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Transforms a position from model to window coordinates. The transformation\\n\\\n * from model to clip coordinates is done using {@link czm_modelViewProjection}.\\n\\\n * The transform from normalized device coordinates to window coordinates is\\n\\\n * done using {@link czm_viewportTransformation}, which assumes a depth range\\n\\\n * of near = 0 and far = 1.\\n\\\n *

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

\\n\\\n * This function should not be confused with {@link czm_viewportOrthographic},\\n\\\n * which is an orthographic projection matrix that transforms from window \\n\\\n * coordinates to clip coordinates.\\n\\\n *\\n\\\n * @name czm_modelToWindowCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} position The position in model coordinates to transform.\\n\\\n *\\n\\\n * @returns {vec4} The transformed position in window coordinates.\\n\\\n *\\n\\\n * @see czm_eyeToWindowCoordinates\\n\\\n * @see czm_modelViewProjection\\n\\\n * @see czm_viewportTransformation\\n\\\n * @see czm_viewportOrthographic\\n\\\n * @see BillboardCollection\\n\\\n *\\n\\\n * @example\\n\\\n * vec4 positionWC = czm_modelToWindowCoordinates(positionMC);\\n\\\n */\\n\\\nvec4 czm_modelToWindowCoordinates(vec4 position)\\n\\\n{\\n\\\n vec4 q = czm_modelViewProjection * position; // clip coordinates\\n\\\n q.xyz /= q.w; // normalized device coordinates\\n\\\n q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates\\n\\\n return q;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_multiplyWithColorBalance\\n\\\n * @glslFunction\\n\\\n */\\n\\\nvec3 czm_multiplyWithColorBalance(vec3 left, vec3 right)\\n\\\n{\\n\\\n // Algorithm from Chapter 10 of Graphics Shaders.\\n\\\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\\n\\\n \\n\\\n vec3 target = left * right;\\n\\\n float leftLuminance = dot(left, W);\\n\\\n float rightLuminance = dot(right, W);\\n\\\n float targetLuminance = dot(target, W);\\n\\\n \\n\\\n return ((leftLuminance + rightLuminance) / (2.0 * targetLuminance)) * target;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes a value that scales with distance. The scaling is clamped at the near and\\n\\\n * far distances, and does not extrapolate. This function works with the\\n\\\n * {@link NearFarScalar} JavaScript class.\\n\\\n *\\n\\\n * @name czm_nearFarScalar\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} nearFarScalar A vector with 4 components: Near distance (x), Near value (y), Far distance (z), Far value (w).\\n\\\n * @param {float} cameraDistSq The square of the current distance from the camera.\\n\\\n *\\n\\\n * @returns {float} The value at this distance.\\n\\\n */\\n\\\nfloat czm_nearFarScalar(vec4 nearFarScalar, float cameraDistSq)\\n\\\n{\\n\\\n float valueAtMin = nearFarScalar.y;\\n\\\n float valueAtMax = nearFarScalar.w;\\n\\\n float nearDistanceSq = nearFarScalar.x * nearFarScalar.x;\\n\\\n float farDistanceSq = nearFarScalar.z * nearFarScalar.z;\\n\\\n\\n\\\n float t = (cameraDistSq - nearDistanceSq) / (farDistanceSq - nearDistanceSq);\\n\\\n\\n\\\n t = pow(clamp(t, 0.0, 1.0), 0.2);\\n\\\n\\n\\\n return mix(valueAtMin, valueAtMax, t);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \" /**\\n\\\n * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector.\\n\\\n * The 'oct' encoding is described in \\\"A Survey of Efficient Representations of Independent Unit Vectors\\\",\\n\\\n * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\\n\\\n *\\n\\\n * @name czm_octDecode\\n\\\n * @param {vec2} encoded The oct-encoded, unit-length vector\\n\\\n * @param {float} range The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\\n\\\n * @returns {vec3} The decoded and normalized vector\\n\\\n */\\n\\\n vec3 czm_octDecode(vec2 encoded, float range)\\n\\\n {\\n\\\n if (encoded.x == 0.0 && encoded.y == 0.0) {\\n\\\n return vec3(0.0, 0.0, 0.0);\\n\\\n }\\n\\\n\\n\\\n encoded = encoded / range * 2.0 - 1.0;\\n\\\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\\n\\\n if (v.z < 0.0)\\n\\\n {\\n\\\n v.xy = (1.0 - abs(v.yx)) * czm_signNotZero(v.xy);\\n\\\n }\\n\\\n\\n\\\n return normalize(v);\\n\\\n }\\n\\\n\\n\\\n/**\\n\\\n * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector.\\n\\\n * The 'oct' encoding is described in \\\"A Survey of Efficient Representations of Independent Unit Vectors\\\",\\n\\\n * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\\n\\\n *\\n\\\n * @name czm_octDecode\\n\\\n * @param {vec2} encoded The oct-encoded, unit-length vector\\n\\\n * @returns {vec3} The decoded and normalized vector\\n\\\n */\\n\\\n vec3 czm_octDecode(vec2 encoded)\\n\\\n {\\n\\\n return czm_octDecode(encoded, 255.0);\\n\\\n }\\n\\\n\\n\\\n /**\\n\\\n * Decodes a unit-length vector in 'oct' encoding packed into a floating-point number to a normalized 3-component Cartesian vector.\\n\\\n * The 'oct' encoding is described in \\\"A Survey of Efficient Representations of Independent Unit Vectors\\\",\\n\\\n * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\\n\\\n *\\n\\\n * @name czm_octDecode\\n\\\n * @param {float} encoded The oct-encoded, unit-length vector\\n\\\n * @returns {vec3} The decoded and normalized vector\\n\\\n */\\n\\\n vec3 czm_octDecode(float encoded)\\n\\\n {\\n\\\n float temp = encoded / 256.0;\\n\\\n float x = floor(temp);\\n\\\n float y = (temp - x) * 256.0;\\n\\\n return czm_octDecode(vec2(x, y));\\n\\\n }\\n\\\n\\n\\\n/**\\n\\\n * Decodes three unit-length vectors in 'oct' encoding packed into two floating-point numbers to normalized 3-component Cartesian vectors.\\n\\\n * The 'oct' encoding is described in \\\"A Survey of Efficient Representations of Independent Unit Vectors\\\",\\n\\\n * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/\\n\\\n *\\n\\\n * @name czm_octDecode\\n\\\n * @param {vec2} encoded The packed oct-encoded, unit-length vectors.\\n\\\n * @param {vec3} vector1 One decoded and normalized vector.\\n\\\n * @param {vec3} vector2 One decoded and normalized vector.\\n\\\n * @param {vec3} vector3 One decoded and normalized vector.\\n\\\n */\\n\\\n void czm_octDecode(vec2 encoded, out vec3 vector1, out vec3 vector2, out vec3 vector3)\\n\\\n {\\n\\\n float temp = encoded.x / 65536.0;\\n\\\n float x = floor(temp);\\n\\\n float encodedFloat1 = (temp - x) * 65536.0;\\n\\\n\\n\\\n temp = encoded.y / 65536.0;\\n\\\n float y = floor(temp);\\n\\\n float encodedFloat2 = (temp - y) * 65536.0;\\n\\\n\\n\\\n vector1 = czm_octDecode(encodedFloat1);\\n\\\n vector2 = czm_octDecode(encodedFloat2);\\n\\\n vector3 = czm_octDecode(vec2(x, y));\\n\\\n }\\n\\\n\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Packs a depth value into a vec3 that can be represented by unsigned bytes.\\n\\\n *\\n\\\n * @name czm_packDepth\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} depth The floating-point depth.\\n\\\n * @returns {vec3} The packed depth.\\n\\\n */\\n\\\nvec4 czm_packDepth(float depth)\\n\\\n{\\n\\\n // See Aras Pranckevi\u010Dius' post Encoding Floats to RGBA\\n\\\n // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/\\n\\\n vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\\n\\\n enc = fract(enc);\\n\\\n enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);\\n\\\n return enc;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"vec3 lambertianDiffuse(vec3 diffuseColor)\\n\\\n{\\n\\\n return diffuseColor / czm_pi;\\n\\\n}\\n\\\n\\n\\\nvec3 fresnelSchlick2(vec3 f0, vec3 f90, float VdotH)\\n\\\n{\\n\\\n return f0 + (f90 - f0) * pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);\\n\\\n}\\n\\\n\\n\\\nfloat smithVisibilityG1(float NdotV, float roughness)\\n\\\n{\\n\\\n // this is the k value for direct lighting.\\n\\\n // for image based lighting it will be roughness^2 / 2\\n\\\n float k = (roughness + 1.0) * (roughness + 1.0) / 8.0;\\n\\\n return NdotV / (NdotV * (1.0 - k) + k);\\n\\\n}\\n\\\n\\n\\\nfloat smithVisibilityGGX(float roughness, float NdotL, float NdotV)\\n\\\n{\\n\\\n return (\\n\\\n smithVisibilityG1(NdotL, roughness) *\\n\\\n smithVisibilityG1(NdotV, roughness)\\n\\\n );\\n\\\n}\\n\\\n\\n\\\nfloat GGX(float roughness, float NdotH)\\n\\\n{\\n\\\n float roughnessSquared = roughness * roughness;\\n\\\n float f = (NdotH * roughnessSquared - NdotH) * NdotH + 1.0;\\n\\\n return roughnessSquared / (czm_pi * f * f);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Compute the diffuse and specular contributions using physically based\\n\\\n * rendering. This function only handles direct lighting.\\n\\\n *

\\n\\\n * This function only handles the lighting calculations. Metallic/roughness\\n\\\n * and specular/glossy must be handled separately. See {@czm_pbrMetallicRoughnessMaterial}, {@czm_pbrSpecularGlossinessMaterial} and {@czm_defaultPbrMaterial}\\n\\\n *

\\n\\\n *\\n\\\n * @name czm_pbrlighting\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} positionEC The position of the fragment in eye coordinates\\n\\\n * @param {vec3} normalEC The surface normal in eye coordinates\\n\\\n * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\\n\\\n * @param {vec3} lightColorHdr radiance of the light source. This is a HDR value.\\n\\\n * @param {czm_pbrParameters} The computed PBR parameters.\\n\\\n * @return {vec3} The computed HDR color\\n\\\n *\\n\\\n * @example\\n\\\n * czm_pbrParameters pbrParameters = czm_pbrMetallicRoughnessMaterial(\\n\\\n * baseColor,\\n\\\n * metallic,\\n\\\n * roughness\\n\\\n * );\\n\\\n * vec3 color = czm_pbrlighting(\\n\\\n * positionEC,\\n\\\n * normalEC,\\n\\\n * lightDirectionEC,\\n\\\n * lightColorHdr,\\n\\\n * pbrParameters);\\n\\\n */\\n\\\nvec3 czm_pbrLighting(\\n\\\n vec3 positionEC,\\n\\\n vec3 normalEC,\\n\\\n vec3 lightDirectionEC,\\n\\\n vec3 lightColorHdr,\\n\\\n czm_pbrParameters pbrParameters\\n\\\n)\\n\\\n{\\n\\\n vec3 v = -normalize(positionEC);\\n\\\n vec3 l = normalize(lightDirectionEC);\\n\\\n vec3 h = normalize(v + l);\\n\\\n vec3 n = normalEC;\\n\\\n float NdotL = clamp(dot(n, l), 0.001, 1.0);\\n\\\n float NdotV = abs(dot(n, v)) + 0.001;\\n\\\n float NdotH = clamp(dot(n, h), 0.0, 1.0);\\n\\\n float LdotH = clamp(dot(l, h), 0.0, 1.0);\\n\\\n float VdotH = clamp(dot(v, h), 0.0, 1.0);\\n\\\n\\n\\\n vec3 f0 = pbrParameters.f0;\\n\\\n float reflectance = max(max(f0.r, f0.g), f0.b);\\n\\\n vec3 f90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));\\n\\\n vec3 F = fresnelSchlick2(f0, f90, VdotH);\\n\\\n\\n\\\n float alpha = pbrParameters.roughness;\\n\\\n float G = smithVisibilityGGX(alpha, NdotL, NdotV);\\n\\\n float D = GGX(alpha, NdotH);\\n\\\n vec3 specularContribution = F * G * D / (4.0 * NdotL * NdotV);\\n\\\n\\n\\\n vec3 diffuseColor = pbrParameters.diffuseColor;\\n\\\n // F here represents the specular contribution\\n\\\n vec3 diffuseContribution = (1.0 - F) * lambertianDiffuse(diffuseColor);\\n\\\n\\n\\\n // Lo = (diffuse + specular) * Li * NdotL\\n\\\n return (diffuseContribution + specularContribution) * NdotL * lightColorHdr;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Compute parameters for physically based rendering using the\\n\\\n * metallic/roughness workflow. All inputs are linear; sRGB texture values must\\n\\\n * be decoded beforehand\\n\\\n *\\n\\\n * @name czm_pbrMetallicRoughnessMaterial\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} baseColor For dielectrics, this is the base color. For metals, this is the f0 value (reflectance at normal incidence)\\n\\\n * @param {float} metallic 0.0 indicates dielectric. 1.0 indicates metal. Values in between are allowed (e.g. to model rust or dirt);\\n\\\n * @param {float} roughness A value between 0.0 and 1.0\\n\\\n * @return {czm_pbrParameters} parameters to pass into {@link czm_pbrLighting}\\n\\\n */\\n\\\nczm_pbrParameters czm_pbrMetallicRoughnessMaterial(\\n\\\n vec3 baseColor,\\n\\\n float metallic,\\n\\\n float roughness\\n\\\n) \\n\\\n{\\n\\\n czm_pbrParameters results;\\n\\\n\\n\\\n // roughness is authored as perceptual roughness\\n\\\n // square it to get material roughness\\n\\\n roughness = clamp(roughness, 0.0, 1.0);\\n\\\n results.roughness = roughness * roughness;\\n\\\n\\n\\\n // dielectrics use f0 = 0.04, metals use albedo as f0\\n\\\n metallic = clamp(metallic, 0.0, 1.0);\\n\\\n const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);\\n\\\n vec3 f0 = mix(REFLECTANCE_DIELECTRIC, baseColor, metallic);\\n\\\n results.f0 = f0;\\n\\\n\\n\\\n // diffuse only applies to dielectrics.\\n\\\n results.diffuseColor = baseColor * (1.0 - f0) * (1.0 - metallic);\\n\\\n\\n\\\n return results;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Compute parameters for physically based rendering using the\\n\\\n * specular/glossy workflow. All inputs are linear; sRGB texture values must\\n\\\n * be decoded beforehand\\n\\\n *\\n\\\n * @name czm_pbrSpecularGlossinessMaterial\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} diffuse The diffuse color for dielectrics (non-metals)\\n\\\n * @param {vec3} specular The reflectance at normal incidence (f0)\\n\\\n * @param {float} glossiness A number from 0.0 to 1.0 indicating how smooth the surface is.\\n\\\n * @return {czm_pbrParameters} parameters to pass into {@link czm_pbrLighting}\\n\\\n */\\n\\\nczm_pbrParameters czm_pbrSpecularGlossinessMaterial(\\n\\\n vec3 diffuse,\\n\\\n vec3 specular,\\n\\\n float glossiness\\n\\\n) \\n\\\n{\\n\\\n czm_pbrParameters results;\\n\\\n\\n\\\n // glossiness is the opposite of roughness, but easier for artists to use.\\n\\\n float roughness = 1.0 - glossiness;\\n\\\n results.roughness = roughness * roughness;\\n\\\n\\n\\\n results.diffuseColor = diffuse * (1.0 - max(max(specular.r, specular.g), specular.b));\\n\\\n results.f0 = specular;\\n\\\n\\n\\\n return results;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"float czm_private_getLambertDiffuseOfMaterial(vec3 lightDirectionEC, czm_material material)\\n\\\n{\\n\\\n return czm_getLambertDiffuse(lightDirectionEC, material.normal);\\n\\\n}\\n\\\n\\n\\\nfloat czm_private_getSpecularOfMaterial(vec3 lightDirectionEC, vec3 toEyeEC, czm_material material)\\n\\\n{\\n\\\n return czm_getSpecular(lightDirectionEC, toEyeEC, material.normal, material.shininess);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Computes a color using the Phong lighting model.\\n\\\n *\\n\\\n * @name czm_phong\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} toEye A normalized vector from the fragment to the eye in eye coordinates.\\n\\\n * @param {czm_material} material The fragment's material.\\n\\\n *\\n\\\n * @returns {vec4} The computed color.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 positionToEyeEC = // ...\\n\\\n * czm_material material = // ...\\n\\\n * vec3 lightDirectionEC = // ...\\n\\\n * out_FragColor = czm_phong(normalize(positionToEyeEC), material, lightDirectionEC);\\n\\\n *\\n\\\n * @see czm_getMaterial\\n\\\n */\\n\\\nvec4 czm_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC)\\n\\\n{\\n\\\n // Diffuse from directional light sources at eye (for top-down)\\n\\\n float diffuse = czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 0.0, 1.0), material);\\n\\\n if (czm_sceneMode == czm_sceneMode3D) {\\n\\\n // (and horizon views in 3D)\\n\\\n diffuse += czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 1.0, 0.0), material);\\n\\\n }\\n\\\n\\n\\\n float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material);\\n\\\n\\n\\\n // Temporary workaround for adding ambient.\\n\\\n vec3 materialDiffuse = material.diffuse * 0.5;\\n\\\n\\n\\\n vec3 ambient = materialDiffuse;\\n\\\n vec3 color = ambient + material.emission;\\n\\\n color += materialDiffuse * diffuse * czm_lightColor;\\n\\\n color += material.specular * specular * czm_lightColor;\\n\\\n\\n\\\n return vec4(color, material.alpha);\\n\\\n}\\n\\\n\\n\\\nvec4 czm_private_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC)\\n\\\n{\\n\\\n float diffuse = czm_private_getLambertDiffuseOfMaterial(lightDirectionEC, material);\\n\\\n float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material);\\n\\\n\\n\\\n vec3 ambient = vec3(0.0);\\n\\\n vec3 color = ambient + material.emission;\\n\\\n color += material.diffuse * diffuse * czm_lightColor;\\n\\\n color += material.specular * specular * czm_lightColor;\\n\\\n\\n\\\n return vec4(color, material.alpha);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes distance from a point to a plane.\\n\\\n *\\n\\\n * @name czm_planeDistance\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * param {vec4} plane A Plane in Hessian Normal Form. See Plane.js\\n\\\n * param {vec3} point A point in the same space as the plane.\\n\\\n * returns {float} The distance from the point to the plane.\\n\\\n */\\n\\\nfloat czm_planeDistance(vec4 plane, vec3 point) {\\n\\\n return (dot(plane.xyz, point) + plane.w);\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Computes distance from a point to a plane.\\n\\\n *\\n\\\n * @name czm_planeDistance\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * param {vec3} planeNormal Normal for a plane in Hessian Normal Form. See Plane.js\\n\\\n * param {float} planeDistance Distance for a plane in Hessian Normal form. See Plane.js\\n\\\n * param {vec3} point A point in the same space as the plane.\\n\\\n * returns {float} The distance from the point to the plane.\\n\\\n */\\n\\\nfloat czm_planeDistance(vec3 planeNormal, float planeDistance, vec3 point) {\\n\\\n return (dot(planeNormal, point) + planeDistance);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes the point along a ray at the given time. time can be positive, negative, or zero.\\n\\\n *\\n\\\n * @name czm_pointAlongRay\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {czm_ray} ray The ray to compute the point along.\\n\\\n * @param {float} time The time along the ray.\\n\\\n * \\n\\\n * @returns {vec3} The point along the ray at the given time.\\n\\\n * \\n\\\n * @example\\n\\\n * czm_ray ray = czm_ray(vec3(0.0), vec3(1.0, 0.0, 0.0)); // origin, direction\\n\\\n * vec3 v = czm_pointAlongRay(ray, 2.0); // (2.0, 0.0, 0.0)\\n\\\n */\\n\\\nvec3 czm_pointAlongRay(czm_ray ray, float time)\\n\\\n{\\n\\\n return ray.origin + (time * ray.direction);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * DOC_TBA\\n\\\n *\\n\\\n * @name czm_rayEllipsoidIntersectionInterval\\n\\\n * @glslFunction\\n\\\n */\\n\\\nczm_raySegment czm_rayEllipsoidIntersectionInterval(czm_ray ray, vec3 ellipsoid_center, vec3 ellipsoid_inverseRadii)\\n\\\n{\\n\\\n // ray and ellipsoid center in eye coordinates. radii in model coordinates.\\n\\\n vec3 q = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.origin, 1.0)).xyz;\\n\\\n vec3 w = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.direction, 0.0)).xyz;\\n\\\n\\n\\\n q = q - ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ellipsoid_center, 1.0)).xyz;\\n\\\n\\n\\\n float q2 = dot(q, q);\\n\\\n float qw = dot(q, w);\\n\\\n\\n\\\n if (q2 > 1.0) // Outside ellipsoid.\\n\\\n {\\n\\\n if (qw >= 0.0) // Looking outward or tangent (0 intersections).\\n\\\n {\\n\\\n return czm_emptyRaySegment;\\n\\\n }\\n\\\n else // qw < 0.0.\\n\\\n {\\n\\\n float qw2 = qw * qw;\\n\\\n float difference = q2 - 1.0; // Positively valued.\\n\\\n float w2 = dot(w, w);\\n\\\n float product = w2 * difference;\\n\\\n\\n\\\n if (qw2 < product) // Imaginary roots (0 intersections).\\n\\\n {\\n\\\n return czm_emptyRaySegment;\\n\\\n }\\n\\\n else if (qw2 > product) // Distinct roots (2 intersections).\\n\\\n {\\n\\\n float discriminant = qw * qw - product;\\n\\\n float temp = -qw + sqrt(discriminant); // Avoid cancellation.\\n\\\n float root0 = temp / w2;\\n\\\n float root1 = difference / temp;\\n\\\n if (root0 < root1)\\n\\\n {\\n\\\n czm_raySegment i = czm_raySegment(root0, root1);\\n\\\n return i;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n czm_raySegment i = czm_raySegment(root1, root0);\\n\\\n return i;\\n\\\n }\\n\\\n }\\n\\\n else // qw2 == product. Repeated roots (2 intersections).\\n\\\n {\\n\\\n float root = sqrt(difference / w2);\\n\\\n czm_raySegment i = czm_raySegment(root, root);\\n\\\n return i;\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n else if (q2 < 1.0) // Inside ellipsoid (2 intersections).\\n\\\n {\\n\\\n float difference = q2 - 1.0; // Negatively valued.\\n\\\n float w2 = dot(w, w);\\n\\\n float product = w2 * difference; // Negatively valued.\\n\\\n float discriminant = qw * qw - product;\\n\\\n float temp = -qw + sqrt(discriminant); // Positively valued.\\n\\\n czm_raySegment i = czm_raySegment(0.0, temp / w2);\\n\\\n return i;\\n\\\n }\\n\\\n else // q2 == 1.0. On ellipsoid.\\n\\\n {\\n\\\n if (qw < 0.0) // Looking inward.\\n\\\n {\\n\\\n float w2 = dot(w, w);\\n\\\n czm_raySegment i = czm_raySegment(0.0, -qw / w2);\\n\\\n return i;\\n\\\n }\\n\\\n else // qw >= 0.0. Looking outward or tangent.\\n\\\n {\\n\\\n return czm_emptyRaySegment;\\n\\\n }\\n\\\n }\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Compute the intersection interval of a ray with a sphere.\\n\\\n *\\n\\\n * @name czm_raySphereIntersectionInterval\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {czm_ray} ray The ray.\\n\\\n * @param {vec3} center The center of the sphere.\\n\\\n * @param {float} radius The radius of the sphere.\\n\\\n * @return {czm_raySegment} The intersection interval of the ray with the sphere.\\n\\\n */\\n\\\nczm_raySegment czm_raySphereIntersectionInterval(czm_ray ray, vec3 center, float radius)\\n\\\n{\\n\\\n vec3 o = ray.origin;\\n\\\n vec3 d = ray.direction;\\n\\\n\\n\\\n vec3 oc = o - center;\\n\\\n\\n\\\n float a = dot(d, d);\\n\\\n float b = 2.0 * dot(d, oc);\\n\\\n float c = dot(oc, oc) - (radius * radius);\\n\\\n\\n\\\n float det = (b * b) - (4.0 * a * c);\\n\\\n\\n\\\n if (det < 0.0) {\\n\\\n return czm_emptyRaySegment;\\n\\\n }\\n\\\n\\n\\\n float sqrtDet = sqrt(det);\\n\\\n\\n\\\n float t0 = (-b - sqrtDet) / (2.0 * a);\\n\\\n float t1 = (-b + sqrtDet) / (2.0 * a);\\n\\\n\\n\\\n czm_raySegment result = czm_raySegment(t0, t1);\\n\\\n return result;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"float czm_readDepth(sampler2D depthTexture, vec2 texCoords)\\n\\\n{\\n\\\n return czm_reverseLogDepth(texture(depthTexture, texCoords).r);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Reads a value previously transformed with {@link czm_writeNonPerspective}\\n\\\n * by dividing it by `w`, the value used in the perspective divide.\\n\\\n * This function is intended to be called in a fragment shader to access a\\n\\\n * `varying` that should not be subject to perspective interpolation.\\n\\\n * For example, screen-space texture coordinates. The value should have been\\n\\\n * previously written in the vertex shader with a call to\\n\\\n * {@link czm_writeNonPerspective}.\\n\\\n *\\n\\\n * @name czm_readNonPerspective\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float|vec2|vec3|vec4} value The non-perspective value to be read.\\n\\\n * @param {float} oneOverW One over the perspective divide value, `w`. Usually this is simply `gl_FragCoord.w`.\\n\\\n * @returns {float|vec2|vec3|vec4} The usable value.\\n\\\n */\\n\\\nfloat czm_readNonPerspective(float value, float oneOverW) {\\n\\\n return value * oneOverW;\\n\\\n}\\n\\\n\\n\\\nvec2 czm_readNonPerspective(vec2 value, float oneOverW) {\\n\\\n return value * oneOverW;\\n\\\n}\\n\\\n\\n\\\nvec3 czm_readNonPerspective(vec3 value, float oneOverW) {\\n\\\n return value * oneOverW;\\n\\\n}\\n\\\n\\n\\\nvec4 czm_readNonPerspective(vec4 value, float oneOverW) {\\n\\\n return value * oneOverW;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"float czm_reverseLogDepth(float logZ)\\n\\\n{\\n\\\n#ifdef LOG_DEPTH\\n\\\n float near = czm_currentFrustum.x;\\n\\\n float far = czm_currentFrustum.y;\\n\\\n float log2Depth = logZ * czm_log2FarDepthFromNearPlusOne;\\n\\\n float depthFromNear = pow(2.0, log2Depth) - 1.0;\\n\\\n return far * (1.0 - near / (depthFromNear + near)) / (far - near);\\n\\\n#endif\\n\\\n return logZ;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Round a floating point value. This function exists because round() doesn't\\n\\\n * exist in GLSL 1.00. \\n\\\n *\\n\\\n * @param {float|vec2|vec3|vec4} value The value to round\\n\\\n * @param {float|vec2|vec3|vec3} The rounded value. The type matches the input.\\n\\\n */\\n\\\nfloat czm_round(float value) {\\n\\\n return floor(value + 0.5);\\n\\\n}\\n\\\n\\n\\\nvec2 czm_round(vec2 value) {\\n\\\n return floor(value + 0.5);\\n\\\n}\\n\\\n\\n\\\nvec3 czm_round(vec3 value) {\\n\\\n return floor(value + 0.5);\\n\\\n}\\n\\\n\\n\\\nvec4 czm_round(vec4 value) {\\n\\\n return floor(value + 0.5);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Samples the 4 neighboring pixels and return the weighted average.\\n\\\n *\\n\\\n * @private\\n\\\n */\\n\\\nvec3 czm_sampleOctahedralProjectionWithFiltering(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod)\\n\\\n{\\n\\\n direction /= dot(vec3(1.0), abs(direction));\\n\\\n vec2 rev = abs(direction.zx) - vec2(1.0);\\n\\\n vec2 neg = vec2(direction.x < 0.0 ? rev.x : -rev.x,\\n\\\n direction.z < 0.0 ? rev.y : -rev.y);\\n\\\n vec2 uv = direction.y < 0.0 ? neg : direction.xz;\\n\\\n vec2 coord = 0.5 * uv + vec2(0.5);\\n\\\n vec2 pixel = 1.0 / textureSize;\\n\\\n\\n\\\n if (lod > 0.0)\\n\\\n {\\n\\\n // Each subseqeuent mip level is half the size\\n\\\n float scale = 1.0 / pow(2.0, lod);\\n\\\n float offset = ((textureSize.y + 1.0) / textureSize.x);\\n\\\n\\n\\\n coord.x *= offset;\\n\\\n coord *= scale;\\n\\\n\\n\\\n coord.x += offset + pixel.x;\\n\\\n coord.y += (1.0 - (1.0 / pow(2.0, lod - 1.0))) + pixel.y * (lod - 1.0) * 2.0;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n coord.x *= (textureSize.y / textureSize.x);\\n\\\n }\\n\\\n\\n\\\n // Do bilinear filtering\\n\\\n #ifndef OES_texture_float_linear\\n\\\n vec3 color1 = texture(projectedMap, coord + vec2(0.0, pixel.y)).rgb;\\n\\\n vec3 color2 = texture(projectedMap, coord + vec2(pixel.x, 0.0)).rgb;\\n\\\n vec3 color3 = texture(projectedMap, coord + pixel).rgb;\\n\\\n vec3 color4 = texture(projectedMap, coord).rgb;\\n\\\n\\n\\\n vec2 texturePosition = coord * textureSize;\\n\\\n\\n\\\n float fu = fract(texturePosition.x);\\n\\\n float fv = fract(texturePosition.y);\\n\\\n\\n\\\n vec3 average1 = mix(color4, color2, fu);\\n\\\n vec3 average2 = mix(color1, color3, fu);\\n\\\n\\n\\\n vec3 color = mix(average1, average2, fv);\\n\\\n #else\\n\\\n vec3 color = texture(projectedMap, coord).rgb;\\n\\\n #endif\\n\\\n\\n\\\n return color;\\n\\\n}\\n\\\n\\n\\\n\\n\\\n/**\\n\\\n * Samples from a cube map that has been projected using an octahedral projection from the given direction.\\n\\\n *\\n\\\n * @name czm_sampleOctahedralProjection\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {sampler2D} projectedMap The texture with the octahedral projected cube map.\\n\\\n * @param {vec2} textureSize The width and height dimensions in pixels of the projected map.\\n\\\n * @param {vec3} direction The normalized direction used to sample the cube map.\\n\\\n * @param {float} lod The level of detail to sample.\\n\\\n * @param {float} maxLod The maximum level of detail.\\n\\\n * @returns {vec3} The color of the cube map at the direction.\\n\\\n */\\n\\\nvec3 czm_sampleOctahedralProjection(sampler2D projectedMap, vec2 textureSize, vec3 direction, float lod, float maxLod) {\\n\\\n float currentLod = floor(lod + 0.5);\\n\\\n float nextLod = min(currentLod + 1.0, maxLod);\\n\\\n\\n\\\n vec3 colorCurrentLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, currentLod);\\n\\\n vec3 colorNextLod = czm_sampleOctahedralProjectionWithFiltering(projectedMap, textureSize, direction, nextLod);\\n\\\n\\n\\\n return mix(colorNextLod, colorCurrentLod, nextLod - lod);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Adjusts the saturation of a color.\\n\\\n * \\n\\\n * @name czm_saturation\\n\\\n * @glslFunction\\n\\\n * \\n\\\n * @param {vec3} rgb The color.\\n\\\n * @param {float} adjustment The amount to adjust the saturation of the color.\\n\\\n *\\n\\\n * @returns {float} The color with the saturation adjusted.\\n\\\n *\\n\\\n * @example\\n\\\n * vec3 greyScale = czm_saturation(color, 0.0);\\n\\\n * vec3 doubleSaturation = czm_saturation(color, 2.0);\\n\\\n */\\n\\\nvec3 czm_saturation(vec3 rgb, float adjustment)\\n\\\n{\\n\\\n // Algorithm from Chapter 16 of OpenGL Shading Language\\n\\\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\\n\\\n vec3 intensity = vec3(dot(rgb, W));\\n\\\n return mix(intensity, rgb, adjustment);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nfloat czm_sampleShadowMap(highp samplerCube shadowMap, vec3 d)\\n\\\n{\\n\\\n return czm_unpackDepth(czm_textureCube(shadowMap, d));\\n\\\n}\\n\\\n\\n\\\nfloat czm_sampleShadowMap(highp sampler2D shadowMap, vec2 uv)\\n\\\n{\\n\\\n#ifdef USE_SHADOW_DEPTH_TEXTURE\\n\\\n return texture(shadowMap, uv).r;\\n\\\n#else\\n\\\n return czm_unpackDepth(texture(shadowMap, uv));\\n\\\n#endif\\n\\\n}\\n\\\n\\n\\\nfloat czm_shadowDepthCompare(samplerCube shadowMap, vec3 uv, float depth)\\n\\\n{\\n\\\n return step(depth, czm_sampleShadowMap(shadowMap, uv));\\n\\\n}\\n\\\n\\n\\\nfloat czm_shadowDepthCompare(sampler2D shadowMap, vec2 uv, float depth)\\n\\\n{\\n\\\n return step(depth, czm_sampleShadowMap(shadowMap, uv));\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"\\n\\\nfloat czm_private_shadowVisibility(float visibility, float nDotL, float normalShadingSmooth, float darkness)\\n\\\n{\\n\\\n#ifdef USE_NORMAL_SHADING\\n\\\n#ifdef USE_NORMAL_SHADING_SMOOTH\\n\\\n float strength = clamp(nDotL / normalShadingSmooth, 0.0, 1.0);\\n\\\n#else\\n\\\n float strength = step(0.0, nDotL);\\n\\\n#endif\\n\\\n visibility *= strength;\\n\\\n#endif\\n\\\n\\n\\\n visibility = max(visibility, darkness);\\n\\\n return visibility;\\n\\\n}\\n\\\n\\n\\\n#ifdef USE_CUBE_MAP_SHADOW\\n\\\nfloat czm_shadowVisibility(samplerCube shadowMap, czm_shadowParameters shadowParameters)\\n\\\n{\\n\\\n float depthBias = shadowParameters.depthBias;\\n\\\n float depth = shadowParameters.depth;\\n\\\n float nDotL = shadowParameters.nDotL;\\n\\\n float normalShadingSmooth = shadowParameters.normalShadingSmooth;\\n\\\n float darkness = shadowParameters.darkness;\\n\\\n vec3 uvw = shadowParameters.texCoords;\\n\\\n\\n\\\n depth -= depthBias;\\n\\\n float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);\\n\\\n return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);\\n\\\n}\\n\\\n#else\\n\\\nfloat czm_shadowVisibility(sampler2D shadowMap, czm_shadowParameters shadowParameters)\\n\\\n{\\n\\\n float depthBias = shadowParameters.depthBias;\\n\\\n float depth = shadowParameters.depth;\\n\\\n float nDotL = shadowParameters.nDotL;\\n\\\n float normalShadingSmooth = shadowParameters.normalShadingSmooth;\\n\\\n float darkness = shadowParameters.darkness;\\n\\\n vec2 uv = shadowParameters.texCoords;\\n\\\n\\n\\\n depth -= depthBias;\\n\\\n#ifdef USE_SOFT_SHADOWS\\n\\\n vec2 texelStepSize = shadowParameters.texelStepSize;\\n\\\n float radius = 1.0;\\n\\\n float dx0 = -texelStepSize.x * radius;\\n\\\n float dy0 = -texelStepSize.y * radius;\\n\\\n float dx1 = texelStepSize.x * radius;\\n\\\n float dy1 = texelStepSize.y * radius;\\n\\\n float visibility = (\\n\\\n czm_shadowDepthCompare(shadowMap, uv, depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy0), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy0), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy0), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, 0.0), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, 0.0), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx0, dy1), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(0.0, dy1), depth) +\\n\\\n czm_shadowDepthCompare(shadowMap, uv + vec2(dx1, dy1), depth)\\n\\\n ) * (1.0 / 9.0);\\n\\\n#else\\n\\\n float visibility = czm_shadowDepthCompare(shadowMap, uv, depth);\\n\\\n#endif\\n\\\n\\n\\\n return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);\\n\\\n}\\n\\\n#endif\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. This is similar to the GLSL\\n\\\n * built-in function sign except that returns 1.0 instead of 0.0 when the input value is 0.0.\\n\\\n * \\n\\\n * @name czm_signNotZero\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {} value The value for which to determine the sign.\\n\\\n * @returns {} 1.0 if the value is positive or zero, -1.0 if the value is negative.\\n\\\n */\\n\\\nfloat czm_signNotZero(float value)\\n\\\n{\\n\\\n return value >= 0.0 ? 1.0 : -1.0;\\n\\\n}\\n\\\n\\n\\\nvec2 czm_signNotZero(vec2 value)\\n\\\n{\\n\\\n return vec2(czm_signNotZero(value.x), czm_signNotZero(value.y));\\n\\\n}\\n\\\n\\n\\\nvec3 czm_signNotZero(vec3 value)\\n\\\n{\\n\\\n return vec3(czm_signNotZero(value.x), czm_signNotZero(value.y), czm_signNotZero(value.z));\\n\\\n}\\n\\\n\\n\\\nvec4 czm_signNotZero(vec4 value)\\n\\\n{\\n\\\n return vec4(czm_signNotZero(value.x), czm_signNotZero(value.y), czm_signNotZero(value.z), czm_signNotZero(value.w));\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Computes a color from the third order spherical harmonic coefficients and a normalized direction vector.\\n\\\n *

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

\\n\\\n *\\n\\\n * @name czm_sphericalHarmonics\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} normal The normalized direction.\\n\\\n * @param {vec3[9]} coefficients The third order spherical harmonic coefficients.\\n\\\n * @returns {vec3} The color at the direction.\\n\\\n *\\n\\\n * @see https://graphics.stanford.edu/papers/envmap/envmap.pdf\\n\\\n */\\n\\\nvec3 czm_sphericalHarmonics(vec3 normal, vec3 coefficients[9])\\n\\\n{\\n\\\n vec3 L00 = coefficients[0];\\n\\\n vec3 L1_1 = coefficients[1];\\n\\\n vec3 L10 = coefficients[2];\\n\\\n vec3 L11 = coefficients[3];\\n\\\n vec3 L2_2 = coefficients[4];\\n\\\n vec3 L2_1 = coefficients[5];\\n\\\n vec3 L20 = coefficients[6];\\n\\\n vec3 L21 = coefficients[7];\\n\\\n vec3 L22 = coefficients[8];\\n\\\n\\n\\\n float x = normal.x;\\n\\\n float y = normal.y;\\n\\\n float z = normal.z;\\n\\\n\\n\\\n return\\n\\\n L00\\n\\\n + L1_1 * y\\n\\\n + L10 * z\\n\\\n + L11 * x\\n\\\n + L2_2 * (y * x)\\n\\\n + L2_1 * (y * z)\\n\\\n + L20 * (3.0 * z * z - 1.0)\\n\\\n + L21 * (z * x)\\n\\\n + L22 * (x * x - y * y);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Converts an sRGB color to a linear RGB color.\\n\\\n *\\n\\\n * @param {vec3|vec4} srgbIn The color in sRGB space\\n\\\n * @returns {vec3|vec4} The color in linear color space. The vector type matches the input.\\n\\\n */\\n\\\nvec3 czm_srgbToLinear(vec3 srgbIn)\\n\\\n{\\n\\\n return pow(srgbIn, vec3(2.2));\\n\\\n}\\n\\\n\\n\\\nvec4 czm_srgbToLinear(vec4 srgbIn) \\n\\\n{\\n\\\n vec3 linearOut = pow(srgbIn.rgb, vec3(2.2));\\n\\\n return vec4(linearOut, srgbIn.a);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Creates a matrix that transforms vectors from tangent space to eye space.\\n\\\n *\\n\\\n * @name czm_tangentToEyeSpaceMatrix\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} normalEC The normal vector in eye coordinates.\\n\\\n * @param {vec3} tangentEC The tangent vector in eye coordinates.\\n\\\n * @param {vec3} bitangentEC The bitangent vector in eye coordinates.\\n\\\n *\\n\\\n * @returns {mat3} The matrix that transforms from tangent space to eye space.\\n\\\n *\\n\\\n * @example\\n\\\n * mat3 tangentToEye = czm_tangentToEyeSpaceMatrix(normalEC, tangentEC, bitangentEC);\\n\\\n * vec3 normal = tangentToEye * texture(normalMap, st).xyz;\\n\\\n */\\n\\\nmat3 czm_tangentToEyeSpaceMatrix(vec3 normalEC, vec3 tangentEC, vec3 bitangentEC)\\n\\\n{\\n\\\n vec3 normal = normalize(normalEC);\\n\\\n vec3 tangent = normalize(tangentEC);\\n\\\n vec3 bitangent = normalize(bitangentEC);\\n\\\n return mat3(tangent.x , tangent.y , tangent.z,\\n\\\n bitangent.x, bitangent.y, bitangent.z,\\n\\\n normal.x , normal.y , normal.z);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * A wrapper around the texture (WebGL2) / textureCube (WebGL1)\\n\\\n * function to allow for WebGL 1 support.\\n\\\n * \\n\\\n * @name czm_textureCube\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {samplerCube} sampler The sampler.\\n\\\n * @param {vec3} p The coordinates to sample the texture at.\\n\\\n */\\n\\\nvec4 czm_textureCube(samplerCube sampler, vec3 p) {\\n\\\n#if __VERSION__ == 300\\n\\\n return texture(sampler, p);\\n\\\n#else \\n\\\n return textureCube(sampler, p);\\n\\\n#endif\\n\\\n}\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Transforms a plane.\\n\\\n * \\n\\\n * @name czm_transformPlane\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} plane The plane in Hessian Normal Form.\\n\\\n * @param {mat4} transform The inverse-transpose of a transformation matrix.\\n\\\n */\\n\\\nvec4 czm_transformPlane(vec4 plane, mat4 transform) {\\n\\\n vec4 transformedPlane = transform * plane;\\n\\\n // Convert the transformed plane to Hessian Normal Form\\n\\\n float normalMagnitude = length(transformedPlane.xyz);\\n\\\n return transformedPlane / normalMagnitude;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Translates a position (or any vec3) that was encoded with {@link EncodedCartesian3},\\n\\\n * and then provided to the shader as separate high and low bits to\\n\\\n * be relative to the eye. As shown in the example, the position can then be transformed in eye\\n\\\n * or clip coordinates using {@link czm_modelViewRelativeToEye} or {@link czm_modelViewProjectionRelativeToEye},\\n\\\n * respectively.\\n\\\n *

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

\\n\\\n *\\n\\\n * @name czm_translateRelativeToEye\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec3} high The position's high bits.\\n\\\n * @param {vec3} low The position's low bits.\\n\\\n * @returns {vec3} The position translated to be relative to the camera's position.\\n\\\n *\\n\\\n * @example\\n\\\n * in vec3 positionHigh;\\n\\\n * in vec3 positionLow;\\n\\\n *\\n\\\n * void main()\\n\\\n * {\\n\\\n * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\\n\\\n * gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n * }\\n\\\n *\\n\\\n * @see czm_modelViewRelativeToEye\\n\\\n * @see czm_modelViewProjectionRelativeToEye\\n\\\n * @see czm_computePosition\\n\\\n * @see EncodedCartesian3\\n\\\n */\\n\\\nvec4 czm_translateRelativeToEye(vec3 high, vec3 low)\\n\\\n{\\n\\\n vec3 highDifference = high - czm_encodedCameraPositionMCHigh;\\n\\\n vec3 lowDifference = low - czm_encodedCameraPositionMCLow;\\n\\\n\\n\\\n return vec4(highDifference + lowDifference, 1.0);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * @private\\n\\\n */\\n\\\nvec4 czm_translucentPhong(vec3 toEye, czm_material material, vec3 lightDirectionEC)\\n\\\n{\\n\\\n // Diffuse from directional light sources at eye (for top-down and horizon views)\\n\\\n float diffuse = czm_getLambertDiffuse(vec3(0.0, 0.0, 1.0), material.normal);\\n\\\n\\n\\\n if (czm_sceneMode == czm_sceneMode3D) {\\n\\\n // (and horizon views in 3D)\\n\\\n diffuse += czm_getLambertDiffuse(vec3(0.0, 1.0, 0.0), material.normal);\\n\\\n }\\n\\\n\\n\\\n diffuse = clamp(diffuse, 0.0, 1.0);\\n\\\n\\n\\\n float specular = czm_getSpecular(lightDirectionEC, toEye, material.normal, material.shininess);\\n\\\n\\n\\\n // Temporary workaround for adding ambient.\\n\\\n vec3 materialDiffuse = material.diffuse * 0.5;\\n\\\n\\n\\\n vec3 ambient = materialDiffuse;\\n\\\n vec3 color = ambient + material.emission;\\n\\\n color += materialDiffuse * diffuse * czm_lightColor;\\n\\\n color += material.specular * specular * czm_lightColor;\\n\\\n\\n\\\n return vec4(color, material.alpha);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Returns the transpose of the matrix. The input matrix can be\\n\\\n * a mat2, mat3, or mat4.\\n\\\n *\\n\\\n * @name czm_transpose\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {} matrix The matrix to transpose.\\n\\\n *\\n\\\n * @returns {} The transposed matrix.\\n\\\n *\\n\\\n * @example\\n\\\n * // GLSL declarations\\n\\\n * mat2 czm_transpose(mat2 matrix);\\n\\\n * mat3 czm_transpose(mat3 matrix);\\n\\\n * mat4 czm_transpose(mat4 matrix);\\n\\\n *\\n\\\n * // Transpose a 3x3 rotation matrix to find its inverse.\\n\\\n * mat3 eastNorthUpToEye = czm_eastNorthUpToEyeCoordinates(\\n\\\n * positionMC, normalEC);\\n\\\n * mat3 eyeToEastNorthUp = czm_transpose(eastNorthUpToEye);\\n\\\n */\\n\\\nmat2 czm_transpose(mat2 matrix)\\n\\\n{\\n\\\n return mat2(\\n\\\n matrix[0][0], matrix[1][0],\\n\\\n matrix[0][1], matrix[1][1]);\\n\\\n}\\n\\\n\\n\\\nmat3 czm_transpose(mat3 matrix)\\n\\\n{\\n\\\n return mat3(\\n\\\n matrix[0][0], matrix[1][0], matrix[2][0],\\n\\\n matrix[0][1], matrix[1][1], matrix[2][1],\\n\\\n matrix[0][2], matrix[1][2], matrix[2][2]);\\n\\\n}\\n\\\n\\n\\\nmat4 czm_transpose(mat4 matrix)\\n\\\n{\\n\\\n return mat4(\\n\\\n matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],\\n\\\n matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1],\\n\\\n matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],\\n\\\n matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Unpacks a vec4 depth value to a float in [0, 1) range.\\n\\\n *\\n\\\n * @name czm_unpackDepth\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} packedDepth The packed depth.\\n\\\n *\\n\\\n * @returns {float} The floating-point depth in [0, 1) range.\\n\\\n */\\n\\\n float czm_unpackDepth(vec4 packedDepth)\\n\\\n {\\n\\\n // See Aras Pranckevi\u010Dius' post Encoding Floats to RGBA\\n\\\n // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/\\n\\\n return dot(packedDepth, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\\n\\\n }\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Unpack an IEEE 754 single-precision float that is packed as a little-endian unsigned normalized vec4.\\n\\\n *\\n\\\n * @name czm_unpackFloat\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} packedFloat The packed float.\\n\\\n *\\n\\\n * @returns {float} The floating-point depth in arbitrary range.\\n\\\n */\\n\\\nfloat czm_unpackFloat(vec4 packedFloat)\\n\\\n{\\n\\\n // Convert to [0.0, 255.0] and round to integer\\n\\\n packedFloat = floor(packedFloat * 255.0 + 0.5);\\n\\\n float sign = 1.0 - step(128.0, packedFloat[3]) * 2.0;\\n\\\n float exponent = 2.0 * mod(packedFloat[3], 128.0) + step(128.0, packedFloat[2]) - 127.0; \\n\\\n if (exponent == -127.0)\\n\\\n {\\n\\\n return 0.0;\\n\\\n }\\n\\\n float mantissa = mod(packedFloat[2], 128.0) * 65536.0 + packedFloat[1] * 256.0 + packedFloat[0] + float(0x800000);\\n\\\n float result = sign * exp2(exponent - 23.0) * mantissa;\\n\\\n return result;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Unpack unsigned integers of 1-4 bytes. in WebGL 1, there is no uint type,\\n\\\n * so the return value is an int.\\n\\\n *

\\n\\\n * There are also precision limitations in WebGL 1. highp int is still limited\\n\\\n * to 24 bits. Above the value of 2^24 = 16777216, precision loss may occur.\\n\\\n *

\\n\\\n *\\n\\\n * @param {float|vec2|vec3|vec4} packed The packed value. For vectors, the components are listed in little-endian order.\\n\\\n *\\n\\\n * @return {int} The unpacked value.\\n\\\n */\\n\\\n int czm_unpackUint(float packedValue) {\\n\\\n float rounded = czm_round(packedValue * 255.0);\\n\\\n return int(rounded);\\n\\\n }\\n\\\n\\n\\\n int czm_unpackUint(vec2 packedValue) {\\n\\\n vec2 rounded = czm_round(packedValue * 255.0);\\n\\\n return int(dot(rounded, vec2(1.0, 256.0)));\\n\\\n }\\n\\\n\\n\\\n int czm_unpackUint(vec3 packedValue) {\\n\\\n vec3 rounded = czm_round(packedValue * 255.0);\\n\\\n return int(dot(rounded, vec3(1.0, 256.0, 65536.0)));\\n\\\n }\\n\\\n\\n\\\n int czm_unpackUint(vec4 packedValue) {\\n\\\n vec4 rounded = czm_round(packedValue * 255.0);\\n\\\n return int(dot(rounded, vec4(1.0, 256.0, 65536.0, 16777216.0)));\\n\\\n }\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Transform metadata values following the EXT_structural_metadata spec\\n\\\n * by multiplying by scale and adding the offset. Operations are always\\n\\\n * performed component-wise, even for matrices.\\n\\\n * \\n\\\n * @param {float|vec2|vec3|vec4|mat2|mat3|mat4} offset The offset to add\\n\\\n * @param {float|vec2|vec3|vec4|mat2|mat3|mat4} scale The scale factor to multiply\\n\\\n * @param {float|vec2|vec3|vec4|mat2|mat3|mat4} value The original value.\\n\\\n *\\n\\\n * @return {float|vec2|vec3|vec4|mat2|mat3|mat4} The transformed value of the same scalar/vector/matrix type as the input.\\n\\\n */\\n\\\nfloat czm_valueTransform(float offset, float scale, float value) {\\n\\\n return scale * value + offset;\\n\\\n}\\n\\\n\\n\\\nvec2 czm_valueTransform(vec2 offset, vec2 scale, vec2 value) {\\n\\\n return scale * value + offset;\\n\\\n}\\n\\\n\\n\\\nvec3 czm_valueTransform(vec3 offset, vec3 scale, vec3 value) {\\n\\\n return scale * value + offset;\\n\\\n}\\n\\\n\\n\\\nvec4 czm_valueTransform(vec4 offset, vec4 scale, vec4 value) {\\n\\\n return scale * value + offset;\\n\\\n}\\n\\\n\\n\\\nmat2 czm_valueTransform(mat2 offset, mat2 scale, mat2 value) {\\n\\\n return matrixCompMult(scale, value) + offset;\\n\\\n}\\n\\\n\\n\\\nmat3 czm_valueTransform(mat3 offset, mat3 scale, mat3 value) {\\n\\\n return matrixCompMult(scale, value) + offset;\\n\\\n}\\n\\\n\\n\\\nmat4 czm_valueTransform(mat4 offset, mat4 scale, mat4 value) {\\n\\\n return matrixCompMult(scale, value) + offset;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef LOG_DEPTH\\n\\\n// 1.0 at the near plane, increasing linearly from there.\\n\\\nout float v_depthFromNearPlusOne;\\n\\\n#ifdef SHADOW_MAP\\n\\\nout vec3 v_logPositionEC;\\n\\\n#endif\\n\\\n#endif\\n\\\n\\n\\\nvec4 czm_updatePositionDepth(vec4 coords) {\\n\\\n#if defined(LOG_DEPTH)\\n\\\n\\n\\\n#ifdef SHADOW_MAP\\n\\\n vec3 logPositionEC = (czm_inverseProjection * coords).xyz;\\n\\\n v_logPositionEC = logPositionEC;\\n\\\n#endif\\n\\\n\\n\\\n // With the very high far/near ratios used with the logarithmic depth\\n\\\n // buffer, floating point rounding errors can cause linear depth values\\n\\\n // to end up on the wrong side of the far plane, even for vertices that\\n\\\n // are really nowhere near it. Since we always write a correct logarithmic\\n\\\n // depth value in the fragment shader anyway, we just need to make sure\\n\\\n // such errors don't cause the primitive to be clipped entirely before\\n\\\n // we even get to the fragment shader.\\n\\\n coords.z = clamp(coords.z / coords.w, -1.0, 1.0) * coords.w;\\n\\\n#endif\\n\\\n\\n\\\n return coords;\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Writes the logarithmic depth to gl_Position using the already computed gl_Position.\\n\\\n *\\n\\\n * @name czm_vertexLogDepth\\n\\\n * @glslFunction\\n\\\n */\\n\\\nvoid czm_vertexLogDepth()\\n\\\n{\\n\\\n#ifdef LOG_DEPTH\\n\\\n v_depthFromNearPlusOne = (gl_Position.w - czm_currentFrustum.x) + 1.0;\\n\\\n gl_Position = czm_updatePositionDepth(gl_Position);\\n\\\n#endif\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Writes the logarithmic depth to gl_Position using the provided clip coordinates.\\n\\\n *

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

\\n\\\n * @name czm_vertexLogDepth\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} clipCoords The vertex in clip coordinates.\\n\\\n *\\n\\\n * @example\\n\\\n * czm_vertexLogDepth(czm_projection * vec4(positionEyeCoordinates, 1.0));\\n\\\n */\\n\\\nvoid czm_vertexLogDepth(vec4 clipCoords)\\n\\\n{\\n\\\n#ifdef LOG_DEPTH\\n\\\n v_depthFromNearPlusOne = (clipCoords.w - czm_currentFrustum.x) + 1.0;\\n\\\n czm_updatePositionDepth(clipCoords);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"vec4 czm_screenToEyeCoordinates(vec4 screenCoordinate)\\n\\\n{\\n\\\n // Reconstruct NDC coordinates\\n\\\n float x = 2.0 * screenCoordinate.x - 1.0;\\n\\\n float y = 2.0 * screenCoordinate.y - 1.0;\\n\\\n float z = (screenCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\\n\\\n vec4 q = vec4(x, y, z, 1.0);\\n\\\n\\n\\\n // Reverse the perspective division to obtain clip coordinates.\\n\\\n q /= screenCoordinate.w;\\n\\\n\\n\\\n // Reverse the projection transformation to obtain eye coordinates.\\n\\\n if (!(czm_inverseProjection == mat4(0.0))) // IE and Edge sometimes do something weird with != between mat4s\\n\\\n {\\n\\\n q = czm_inverseProjection * q;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n float top = czm_frustumPlanes.x;\\n\\\n float bottom = czm_frustumPlanes.y;\\n\\\n float left = czm_frustumPlanes.z;\\n\\\n float right = czm_frustumPlanes.w;\\n\\\n\\n\\\n float near = czm_currentFrustum.x;\\n\\\n float far = czm_currentFrustum.y;\\n\\\n\\n\\\n q.x = (q.x * (right - left) + left + right) * 0.5;\\n\\\n q.y = (q.y * (top - bottom) + bottom + top) * 0.5;\\n\\\n q.z = (q.z * (near - far) - near - far) * 0.5;\\n\\\n q.w = 1.0;\\n\\\n }\\n\\\n\\n\\\n return q;\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Transforms a position from window to eye coordinates.\\n\\\n * The transform from window to normalized device coordinates is done using components\\n\\\n * of (@link czm_viewport} and {@link czm_viewportTransformation} instead of calculating\\n\\\n * the inverse of czm_viewportTransformation. The transformation from\\n\\\n * normalized device coordinates to clip coordinates is done using fragmentCoordinate.w,\\n\\\n * which is expected to be the scalar used in the perspective divide. The transformation\\n\\\n * from clip to eye coordinates is done using {@link czm_inverseProjection}.\\n\\\n *\\n\\\n * @name czm_windowToEyeCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec4} fragmentCoordinate The position in window coordinates to transform.\\n\\\n *\\n\\\n * @returns {vec4} The transformed position in eye coordinates.\\n\\\n *\\n\\\n * @see czm_modelToWindowCoordinates\\n\\\n * @see czm_eyeToWindowCoordinates\\n\\\n * @see czm_inverseProjection\\n\\\n * @see czm_viewport\\n\\\n * @see czm_viewportTransformation\\n\\\n *\\n\\\n * @example\\n\\\n * vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord);\\n\\\n */\\n\\\nvec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\\n\\\n{\\n\\\n vec2 screenCoordXY = (fragmentCoordinate.xy - czm_viewport.xy) / czm_viewport.zw;\\n\\\n return czm_screenToEyeCoordinates(vec4(screenCoordXY, fragmentCoordinate.zw));\\n\\\n}\\n\\\n\\n\\\nvec4 czm_screenToEyeCoordinates(vec2 screenCoordinateXY, float depthOrLogDepth)\\n\\\n{\\n\\\n // See reverseLogDepth.glsl. This is separate to re-use the pow.\\n\\\n#if defined(LOG_DEPTH) || defined(LOG_DEPTH_READ_ONLY)\\n\\\n float near = czm_currentFrustum.x;\\n\\\n float far = czm_currentFrustum.y;\\n\\\n float log2Depth = depthOrLogDepth * czm_log2FarDepthFromNearPlusOne;\\n\\\n float depthFromNear = pow(2.0, log2Depth) - 1.0;\\n\\\n float depthFromCamera = depthFromNear + near;\\n\\\n vec4 screenCoord = vec4(screenCoordinateXY, far * (1.0 - near / depthFromCamera) / (far - near), 1.0);\\n\\\n vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);\\n\\\n eyeCoordinate.w = 1.0 / depthFromCamera; // Better precision\\n\\\n return eyeCoordinate;\\n\\\n#else\\n\\\n vec4 screenCoord = vec4(screenCoordinateXY, depthOrLogDepth, 1.0);\\n\\\n vec4 eyeCoordinate = czm_screenToEyeCoordinates(screenCoord);\\n\\\n#endif\\n\\\n return eyeCoordinate;\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Transforms a position given as window x/y and a depth or a log depth from window to eye coordinates.\\n\\\n * This function produces more accurate results for window positions with log depth than\\n\\\n * conventionally unpacking the log depth using czm_reverseLogDepth and using the standard version\\n\\\n * of czm_windowToEyeCoordinates.\\n\\\n *\\n\\\n * @name czm_windowToEyeCoordinates\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {vec2} fragmentCoordinateXY The XY position in window coordinates to transform.\\n\\\n * @param {float} depthOrLogDepth A depth or log depth for the fragment.\\n\\\n *\\n\\\n * @see czm_modelToWindowCoordinates\\n\\\n * @see czm_eyeToWindowCoordinates\\n\\\n * @see czm_inverseProjection\\n\\\n * @see czm_viewport\\n\\\n * @see czm_viewportTransformation\\n\\\n *\\n\\\n * @returns {vec4} The transformed position in eye coordinates.\\n\\\n */\\n\\\nvec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)\\n\\\n{\\n\\\n vec2 screenCoordXY = (fragmentCoordinateXY.xy - czm_viewport.xy) / czm_viewport.zw;\\n\\\n return czm_screenToEyeCoordinates(screenCoordXY, depthOrLogDepth);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"// emulated noperspective\\n\\\n#if !defined(LOG_DEPTH)\\n\\\nin float v_WindowZ;\\n\\\n#endif\\n\\\n\\n\\\n/**\\n\\\n * Emulates GL_DEPTH_CLAMP. Clamps a fragment to the near and far plane\\n\\\n * by writing the fragment's depth. See czm_depthClamp for more details.\\n\\\n *\\n\\\n * @name czm_writeDepthClamp\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @example\\n\\\n * out_FragColor = color;\\n\\\n * czm_writeDepthClamp();\\n\\\n *\\n\\\n * @see czm_depthClamp\\n\\\n */\\n\\\nvoid czm_writeDepthClamp()\\n\\\n{\\n\\\n#if (!defined(LOG_DEPTH) && (__VERSION__ == 300 || defined(GL_EXT_frag_depth)))\\n\\\n gl_FragDepth = clamp(v_WindowZ * gl_FragCoord.w, 0.0, 1.0);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef LOG_DEPTH\\n\\\nin float v_depthFromNearPlusOne;\\n\\\n\\n\\\n#ifdef POLYGON_OFFSET\\n\\\nuniform vec2 u_polygonOffset;\\n\\\n#endif\\n\\\n\\n\\\n#endif\\n\\\n\\n\\\n/**\\n\\\n * Writes the fragment depth to the logarithmic depth buffer.\\n\\\n *

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

\\n\\\n * @name czm_writeLogDepth\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float} depth The depth coordinate, where 1.0 is on the near plane and\\n\\\n * depth increases in eye-space units from there\\n\\\n *\\n\\\n * @example\\n\\\n * czm_writeLogDepth((czm_projection * v_positionEyeCoordinates).w + 1.0);\\n\\\n */\\n\\\nvoid czm_writeLogDepth(float depth)\\n\\\n{\\n\\\n#if (defined(LOG_DEPTH) && (__VERSION__ == 300 || defined(GL_EXT_frag_depth)))\\n\\\n // Discard the vertex if it's not between the near and far planes.\\n\\\n // We allow a bit of epsilon on the near plane comparison because a 1.0\\n\\\n // from the vertex shader (indicating the vertex should be _on_ the near\\n\\\n // plane) will not necessarily come here as exactly 1.0.\\n\\\n if (depth <= 0.9999999 || depth > czm_farDepthFromNearPlusOne) {\\n\\\n discard;\\n\\\n }\\n\\\n\\n\\\n#ifdef POLYGON_OFFSET\\n\\\n // Polygon offset: m * factor + r * units\\n\\\n float factor = u_polygonOffset[0];\\n\\\n float units = u_polygonOffset[1];\\n\\\n\\n\\\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n // This factor doesn't work in IE 10\\n\\\n if (factor != 0.0) {\\n\\\n // m = sqrt(dZdX^2 + dZdY^2);\\n\\\n float x = dFdx(depth);\\n\\\n float y = dFdy(depth);\\n\\\n float m = sqrt(x * x + y * y);\\n\\\n\\n\\\n // Apply the factor before computing the log depth.\\n\\\n depth += m * factor;\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#endif\\n\\\n\\n\\\n gl_FragDepth = log2(depth) * czm_oneOverLog2FarDepthFromNearPlusOne;\\n\\\n\\n\\\n#ifdef POLYGON_OFFSET\\n\\\n // Apply the units after the log depth.\\n\\\n gl_FragDepth += czm_epsilon7 * units;\\n\\\n#endif\\n\\\n\\n\\\n#endif\\n\\\n}\\n\\\n\\n\\\n/**\\n\\\n * Writes the fragment depth to the logarithmic depth buffer.\\n\\\n *

\\n\\\n * Use this when the vertex shader calls {@link czm_vertexlogDepth}.\\n\\\n *

\\n\\\n *\\n\\\n * @name czm_writeLogDepth\\n\\\n * @glslFunction\\n\\\n */\\n\\\nvoid czm_writeLogDepth() {\\n\\\n#ifdef LOG_DEPTH\\n\\\n czm_writeLogDepth(v_depthFromNearPlusOne);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"/**\\n\\\n * Transforms a value for non-perspective interpolation by multiplying\\n\\\n * it by w, the value used in the perspective divide. This function is\\n\\\n * intended to be called in a vertex shader to compute the value of a\\n\\\n * `varying` that should not be subject to perspective interpolation.\\n\\\n * For example, screen-space texture coordinates. The fragment shader\\n\\\n * must call {@link czm_readNonPerspective} to retrieve the final\\n\\\n * non-perspective value.\\n\\\n *\\n\\\n * @name czm_writeNonPerspective\\n\\\n * @glslFunction\\n\\\n *\\n\\\n * @param {float|vec2|vec3|vec4} value The value to be interpolated without accounting for perspective.\\n\\\n * @param {float} w The perspective divide value. Usually this is the computed `gl_Position.w`.\\n\\\n * @returns {float|vec2|vec3|vec4} The transformed value, intended to be stored in a `varying` and read in the\\n\\\n * fragment shader with {@link czm_readNonPerspective}.\\n\\\n */\\n\\\nfloat czm_writeNonPerspective(float value, float w) {\\n\\\n return value * w;\\n\\\n}\\n\\\n\\n\\\nvec2 czm_writeNonPerspective(vec2 value, float w) {\\n\\\n return value * w;\\n\\\n}\\n\\\n\\n\\\nvec3 czm_writeNonPerspective(vec3 value, float w) {\\n\\\n return value * w;\\n\\\n}\\n\\\n\\n\\\nvec4 czm_writeNonPerspective(vec4 value, float w) {\\n\\\n return value * w;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nimport czm_degreesPerRadian from './Constants/degreesPerRadian.js'\nimport czm_depthRange from './Constants/depthRange.js'\nimport czm_epsilon1 from './Constants/epsilon1.js'\nimport czm_epsilon2 from './Constants/epsilon2.js'\nimport czm_epsilon3 from './Constants/epsilon3.js'\nimport czm_epsilon4 from './Constants/epsilon4.js'\nimport czm_epsilon5 from './Constants/epsilon5.js'\nimport czm_epsilon6 from './Constants/epsilon6.js'\nimport czm_epsilon7 from './Constants/epsilon7.js'\nimport czm_infinity from './Constants/infinity.js'\nimport czm_oneOverPi from './Constants/oneOverPi.js'\nimport czm_oneOverTwoPi from './Constants/oneOverTwoPi.js'\nimport czm_passCesium3DTile from './Constants/passCesium3DTile.js'\nimport czm_passCesium3DTileClassification from './Constants/passCesium3DTileClassification.js'\nimport czm_passCesium3DTileClassificationIgnoreShow from './Constants/passCesium3DTileClassificationIgnoreShow.js'\nimport czm_passClassification from './Constants/passClassification.js'\nimport czm_passCompute from './Constants/passCompute.js'\nimport czm_passEnvironment from './Constants/passEnvironment.js'\nimport czm_passGlobe from './Constants/passGlobe.js'\nimport czm_passOpaque from './Constants/passOpaque.js'\nimport czm_passOverlay from './Constants/passOverlay.js'\nimport czm_passTerrainClassification from './Constants/passTerrainClassification.js'\nimport czm_passTranslucent from './Constants/passTranslucent.js'\nimport czm_passVoxels from './Constants/passVoxels.js'\nimport czm_pi from './Constants/pi.js'\nimport czm_piOverFour from './Constants/piOverFour.js'\nimport czm_piOverSix from './Constants/piOverSix.js'\nimport czm_piOverThree from './Constants/piOverThree.js'\nimport czm_piOverTwo from './Constants/piOverTwo.js'\nimport czm_radiansPerDegree from './Constants/radiansPerDegree.js'\nimport czm_sceneMode2D from './Constants/sceneMode2D.js'\nimport czm_sceneMode3D from './Constants/sceneMode3D.js'\nimport czm_sceneModeColumbusView from './Constants/sceneModeColumbusView.js'\nimport czm_sceneModeMorphing from './Constants/sceneModeMorphing.js'\nimport czm_solarRadius from './Constants/solarRadius.js'\nimport czm_threePiOver2 from './Constants/threePiOver2.js'\nimport czm_twoPi from './Constants/twoPi.js'\nimport czm_webMercatorMaxLatitude from './Constants/webMercatorMaxLatitude.js'\nimport czm_depthRangeStruct from './Structs/depthRangeStruct.js'\nimport czm_material from './Structs/material.js'\nimport czm_materialInput from './Structs/materialInput.js'\nimport czm_modelMaterial from './Structs/modelMaterial.js'\nimport czm_modelVertexOutput from './Structs/modelVertexOutput.js'\nimport czm_pbrParameters from './Structs/pbrParameters.js'\nimport czm_ray from './Structs/ray.js'\nimport czm_raySegment from './Structs/raySegment.js'\nimport czm_shadowParameters from './Structs/shadowParameters.js'\nimport czm_HSBToRGB from './Functions/HSBToRGB.js'\nimport czm_HSLToRGB from './Functions/HSLToRGB.js'\nimport czm_RGBToHSB from './Functions/RGBToHSB.js'\nimport czm_RGBToHSL from './Functions/RGBToHSL.js'\nimport czm_RGBToXYZ from './Functions/RGBToXYZ.js'\nimport czm_XYZToRGB from './Functions/XYZToRGB.js'\nimport czm_acesTonemapping from './Functions/acesTonemapping.js'\nimport czm_alphaWeight from './Functions/alphaWeight.js'\nimport czm_antialias from './Functions/antialias.js'\nimport czm_approximateSphericalCoordinates from './Functions/approximateSphericalCoordinates.js'\nimport czm_backFacing from './Functions/backFacing.js'\nimport czm_branchFreeTernary from './Functions/branchFreeTernary.js'\nimport czm_cascadeColor from './Functions/cascadeColor.js'\nimport czm_cascadeDistance from './Functions/cascadeDistance.js'\nimport czm_cascadeMatrix from './Functions/cascadeMatrix.js'\nimport czm_cascadeWeights from './Functions/cascadeWeights.js'\nimport czm_columbusViewMorph from './Functions/columbusViewMorph.js'\nimport czm_computePosition from './Functions/computePosition.js'\nimport czm_cosineAndSine from './Functions/cosineAndSine.js'\nimport czm_decompressTextureCoordinates from './Functions/decompressTextureCoordinates.js'\nimport czm_defaultPbrMaterial from './Functions/defaultPbrMaterial.js'\nimport czm_depthClamp from './Functions/depthClamp.js'\nimport czm_eastNorthUpToEyeCoordinates from './Functions/eastNorthUpToEyeCoordinates.js'\nimport czm_ellipsoidContainsPoint from './Functions/ellipsoidContainsPoint.js'\nimport czm_ellipsoidWgs84TextureCoordinates from './Functions/ellipsoidWgs84TextureCoordinates.js'\nimport czm_equalsEpsilon from './Functions/equalsEpsilon.js'\nimport czm_eyeOffset from './Functions/eyeOffset.js'\nimport czm_eyeToWindowCoordinates from './Functions/eyeToWindowCoordinates.js'\nimport czm_fastApproximateAtan from './Functions/fastApproximateAtan.js'\nimport czm_fog from './Functions/fog.js'\nimport czm_gammaCorrect from './Functions/gammaCorrect.js'\nimport czm_geodeticSurfaceNormal from './Functions/geodeticSurfaceNormal.js'\nimport czm_getDefaultMaterial from './Functions/getDefaultMaterial.js'\nimport czm_getLambertDiffuse from './Functions/getLambertDiffuse.js'\nimport czm_getSpecular from './Functions/getSpecular.js'\nimport czm_getWaterNoise from './Functions/getWaterNoise.js'\nimport czm_hue from './Functions/hue.js'\nimport czm_inverseGamma from './Functions/inverseGamma.js'\nimport czm_isEmpty from './Functions/isEmpty.js'\nimport czm_isFull from './Functions/isFull.js'\nimport czm_latitudeToWebMercatorFraction from './Functions/latitudeToWebMercatorFraction.js'\nimport czm_lineDistance from './Functions/lineDistance.js'\nimport czm_linearToSrgb from './Functions/linearToSrgb.js'\nimport czm_luminance from './Functions/luminance.js'\nimport czm_metersPerPixel from './Functions/metersPerPixel.js'\nimport czm_modelToWindowCoordinates from './Functions/modelToWindowCoordinates.js'\nimport czm_multiplyWithColorBalance from './Functions/multiplyWithColorBalance.js'\nimport czm_nearFarScalar from './Functions/nearFarScalar.js'\nimport czm_octDecode from './Functions/octDecode.js'\nimport czm_packDepth from './Functions/packDepth.js'\nimport czm_pbrLighting from './Functions/pbrLighting.js'\nimport czm_pbrMetallicRoughnessMaterial from './Functions/pbrMetallicRoughnessMaterial.js'\nimport czm_pbrSpecularGlossinessMaterial from './Functions/pbrSpecularGlossinessMaterial.js'\nimport czm_phong from './Functions/phong.js'\nimport czm_planeDistance from './Functions/planeDistance.js'\nimport czm_pointAlongRay from './Functions/pointAlongRay.js'\nimport czm_rayEllipsoidIntersectionInterval from './Functions/rayEllipsoidIntersectionInterval.js'\nimport czm_raySphereIntersectionInterval from './Functions/raySphereIntersectionInterval.js'\nimport czm_readDepth from './Functions/readDepth.js'\nimport czm_readNonPerspective from './Functions/readNonPerspective.js'\nimport czm_reverseLogDepth from './Functions/reverseLogDepth.js'\nimport czm_round from './Functions/round.js'\nimport czm_sampleOctahedralProjection from './Functions/sampleOctahedralProjection.js'\nimport czm_saturation from './Functions/saturation.js'\nimport czm_shadowDepthCompare from './Functions/shadowDepthCompare.js'\nimport czm_shadowVisibility from './Functions/shadowVisibility.js'\nimport czm_signNotZero from './Functions/signNotZero.js'\nimport czm_sphericalHarmonics from './Functions/sphericalHarmonics.js'\nimport czm_srgbToLinear from './Functions/srgbToLinear.js'\nimport czm_tangentToEyeSpaceMatrix from './Functions/tangentToEyeSpaceMatrix.js'\nimport czm_textureCube from './Functions/textureCube.js'\nimport czm_transformPlane from './Functions/transformPlane.js'\nimport czm_translateRelativeToEye from './Functions/translateRelativeToEye.js'\nimport czm_translucentPhong from './Functions/translucentPhong.js'\nimport czm_transpose from './Functions/transpose.js'\nimport czm_unpackDepth from './Functions/unpackDepth.js'\nimport czm_unpackFloat from './Functions/unpackFloat.js'\nimport czm_unpackUint from './Functions/unpackUint.js'\nimport czm_valueTransform from './Functions/valueTransform.js'\nimport czm_vertexLogDepth from './Functions/vertexLogDepth.js'\nimport czm_windowToEyeCoordinates from './Functions/windowToEyeCoordinates.js'\nimport czm_writeDepthClamp from './Functions/writeDepthClamp.js'\nimport czm_writeLogDepth from './Functions/writeLogDepth.js'\nimport czm_writeNonPerspective from './Functions/writeNonPerspective.js'\n\nexport default {\n czm_degreesPerRadian : czm_degreesPerRadian,\n czm_depthRange : czm_depthRange,\n czm_epsilon1 : czm_epsilon1,\n czm_epsilon2 : czm_epsilon2,\n czm_epsilon3 : czm_epsilon3,\n czm_epsilon4 : czm_epsilon4,\n czm_epsilon5 : czm_epsilon5,\n czm_epsilon6 : czm_epsilon6,\n czm_epsilon7 : czm_epsilon7,\n czm_infinity : czm_infinity,\n czm_oneOverPi : czm_oneOverPi,\n czm_oneOverTwoPi : czm_oneOverTwoPi,\n czm_passCesium3DTile : czm_passCesium3DTile,\n czm_passCesium3DTileClassification : czm_passCesium3DTileClassification,\n czm_passCesium3DTileClassificationIgnoreShow : czm_passCesium3DTileClassificationIgnoreShow,\n czm_passClassification : czm_passClassification,\n czm_passCompute : czm_passCompute,\n czm_passEnvironment : czm_passEnvironment,\n czm_passGlobe : czm_passGlobe,\n czm_passOpaque : czm_passOpaque,\n czm_passOverlay : czm_passOverlay,\n czm_passTerrainClassification : czm_passTerrainClassification,\n czm_passTranslucent : czm_passTranslucent,\n czm_passVoxels : czm_passVoxels,\n czm_pi : czm_pi,\n czm_piOverFour : czm_piOverFour,\n czm_piOverSix : czm_piOverSix,\n czm_piOverThree : czm_piOverThree,\n czm_piOverTwo : czm_piOverTwo,\n czm_radiansPerDegree : czm_radiansPerDegree,\n czm_sceneMode2D : czm_sceneMode2D,\n czm_sceneMode3D : czm_sceneMode3D,\n czm_sceneModeColumbusView : czm_sceneModeColumbusView,\n czm_sceneModeMorphing : czm_sceneModeMorphing,\n czm_solarRadius : czm_solarRadius,\n czm_threePiOver2 : czm_threePiOver2,\n czm_twoPi : czm_twoPi,\n czm_webMercatorMaxLatitude : czm_webMercatorMaxLatitude,\n czm_depthRangeStruct : czm_depthRangeStruct,\n czm_material : czm_material,\n czm_materialInput : czm_materialInput,\n czm_modelMaterial : czm_modelMaterial,\n czm_modelVertexOutput : czm_modelVertexOutput,\n czm_pbrParameters : czm_pbrParameters,\n czm_ray : czm_ray,\n czm_raySegment : czm_raySegment,\n czm_shadowParameters : czm_shadowParameters,\n czm_HSBToRGB : czm_HSBToRGB,\n czm_HSLToRGB : czm_HSLToRGB,\n czm_RGBToHSB : czm_RGBToHSB,\n czm_RGBToHSL : czm_RGBToHSL,\n czm_RGBToXYZ : czm_RGBToXYZ,\n czm_XYZToRGB : czm_XYZToRGB,\n czm_acesTonemapping : czm_acesTonemapping,\n czm_alphaWeight : czm_alphaWeight,\n czm_antialias : czm_antialias,\n czm_approximateSphericalCoordinates : czm_approximateSphericalCoordinates,\n czm_backFacing : czm_backFacing,\n czm_branchFreeTernary : czm_branchFreeTernary,\n czm_cascadeColor : czm_cascadeColor,\n czm_cascadeDistance : czm_cascadeDistance,\n czm_cascadeMatrix : czm_cascadeMatrix,\n czm_cascadeWeights : czm_cascadeWeights,\n czm_columbusViewMorph : czm_columbusViewMorph,\n czm_computePosition : czm_computePosition,\n czm_cosineAndSine : czm_cosineAndSine,\n czm_decompressTextureCoordinates : czm_decompressTextureCoordinates,\n czm_defaultPbrMaterial : czm_defaultPbrMaterial,\n czm_depthClamp : czm_depthClamp,\n czm_eastNorthUpToEyeCoordinates : czm_eastNorthUpToEyeCoordinates,\n czm_ellipsoidContainsPoint : czm_ellipsoidContainsPoint,\n czm_ellipsoidWgs84TextureCoordinates : czm_ellipsoidWgs84TextureCoordinates,\n czm_equalsEpsilon : czm_equalsEpsilon,\n czm_eyeOffset : czm_eyeOffset,\n czm_eyeToWindowCoordinates : czm_eyeToWindowCoordinates,\n czm_fastApproximateAtan : czm_fastApproximateAtan,\n czm_fog : czm_fog,\n czm_gammaCorrect : czm_gammaCorrect,\n czm_geodeticSurfaceNormal : czm_geodeticSurfaceNormal,\n czm_getDefaultMaterial : czm_getDefaultMaterial,\n czm_getLambertDiffuse : czm_getLambertDiffuse,\n czm_getSpecular : czm_getSpecular,\n czm_getWaterNoise : czm_getWaterNoise,\n czm_hue : czm_hue,\n czm_inverseGamma : czm_inverseGamma,\n czm_isEmpty : czm_isEmpty,\n czm_isFull : czm_isFull,\n czm_latitudeToWebMercatorFraction : czm_latitudeToWebMercatorFraction,\n czm_lineDistance : czm_lineDistance,\n czm_linearToSrgb : czm_linearToSrgb,\n czm_luminance : czm_luminance,\n czm_metersPerPixel : czm_metersPerPixel,\n czm_modelToWindowCoordinates : czm_modelToWindowCoordinates,\n czm_multiplyWithColorBalance : czm_multiplyWithColorBalance,\n czm_nearFarScalar : czm_nearFarScalar,\n czm_octDecode : czm_octDecode,\n czm_packDepth : czm_packDepth,\n czm_pbrLighting : czm_pbrLighting,\n czm_pbrMetallicRoughnessMaterial : czm_pbrMetallicRoughnessMaterial,\n czm_pbrSpecularGlossinessMaterial : czm_pbrSpecularGlossinessMaterial,\n czm_phong : czm_phong,\n czm_planeDistance : czm_planeDistance,\n czm_pointAlongRay : czm_pointAlongRay,\n czm_rayEllipsoidIntersectionInterval : czm_rayEllipsoidIntersectionInterval,\n czm_raySphereIntersectionInterval : czm_raySphereIntersectionInterval,\n czm_readDepth : czm_readDepth,\n czm_readNonPerspective : czm_readNonPerspective,\n czm_reverseLogDepth : czm_reverseLogDepth,\n czm_round : czm_round,\n czm_sampleOctahedralProjection : czm_sampleOctahedralProjection,\n czm_saturation : czm_saturation,\n czm_shadowDepthCompare : czm_shadowDepthCompare,\n czm_shadowVisibility : czm_shadowVisibility,\n czm_signNotZero : czm_signNotZero,\n czm_sphericalHarmonics : czm_sphericalHarmonics,\n czm_srgbToLinear : czm_srgbToLinear,\n czm_tangentToEyeSpaceMatrix : czm_tangentToEyeSpaceMatrix,\n czm_textureCube : czm_textureCube,\n czm_transformPlane : czm_transformPlane,\n czm_translateRelativeToEye : czm_translateRelativeToEye,\n czm_translucentPhong : czm_translucentPhong,\n czm_transpose : czm_transpose,\n czm_unpackDepth : czm_unpackDepth,\n czm_unpackFloat : czm_unpackFloat,\n czm_unpackUint : czm_unpackUint,\n czm_valueTransform : czm_valueTransform,\n czm_vertexLogDepth : czm_vertexLogDepth,\n czm_windowToEyeCoordinates : czm_windowToEyeCoordinates,\n czm_writeDepthClamp : czm_writeDepthClamp,\n czm_writeLogDepth : czm_writeLogDepth,\n czm_writeNonPerspective : czm_writeNonPerspective\n};\n", "/**\n * Transpiles a [GLSL 3.00]{@link https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf}\n * shader to a [GLSL 1.00]{@link https://registry.khronos.org/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf} shader.\n *\n * This function does not aim to provide a comprehensive transpilation from GLSL 3.00 to GLSL 1.00; only the functionality\n * used within the CesiumJS shaders is supported.\n *\n * @private\n *\n * @param {string} input The GLSL 3.00 shader.\n * @param {boolean} isFragmentShader True if the shader is a fragment shader.\n *\n * @return {string}\n */\nfunction demodernizeShader(input, isFragmentShader) {\n let output = input;\n\n // Remove version string got GLSL 3.00.\n output = output.replaceAll(`version 300 es`, ``);\n\n // Replace all texture calls with texture2D\n output = output.replaceAll(\n /(texture\\()/g,\n `texture2D(` // Trailing ')' is included in the match group.\n );\n\n if (isFragmentShader) {\n // Replace the in with varying.\n output = output.replaceAll(/(in)\\s+(vec\\d|mat\\d|float)/g, `varying $2`);\n\n if (/out_FragData_(\\d+)/.test(output)) {\n output = `#extension GL_EXT_draw_buffers : enable\\n${output}`;\n\n // Remove all layout declarations for out_FragData.\n output = output.replaceAll(\n /layout\\s+\\(location\\s*=\\s*\\d+\\)\\s*out\\s+vec4\\s+out_FragData_\\d+;/g,\n ``\n );\n\n // Replace out_FragData with gl_FragData.\n output = output.replaceAll(/out_FragData_(\\d+)/g, `gl_FragData[$1]`);\n }\n\n // Remove all layout declarations for out_FragColor.\n output = output.replaceAll(\n /layout\\s+\\(location\\s*=\\s*0\\)\\s*out\\s+vec4\\s+out_FragColor;/g,\n ``\n );\n\n // Replace out_FragColor with gl_FragColor.\n output = output.replaceAll(/out_FragColor/g, `gl_FragColor`);\n output = output.replaceAll(/out_FragColor\\[(\\d+)\\]/g, `gl_FragColor[$1]`);\n\n if (/gl_FragDepth/.test(output)) {\n output = `#extension GL_EXT_frag_depth : enable\\n${output}`;\n // Replace gl_FragDepth with gl_FragDepthEXT.\n output = output.replaceAll(/gl_FragDepth/g, `gl_FragDepthEXT`);\n }\n\n // Enable the OES_standard_derivatives extension\n output = `#ifdef GL_OES_standard_derivatives\\n#extension GL_OES_standard_derivatives : enable\\n#endif\\n${output}`;\n } else {\n // Replace the in with attribute.\n output = output.replaceAll(/(in)\\s+(vec\\d|mat\\d|float)/g, `attribute $2`);\n\n // Replace the out with varying.\n output = output.replaceAll(\n /(out)\\s+(vec\\d|mat\\d|float)\\s+([\\w]+);/g,\n `varying $2 $3;`\n );\n }\n\n // Add version string for GLSL 1.00.\n output = `#version 100\\n${output}`;\n\n return output;\n}\n\nexport default demodernizeShader;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CzmBuiltins from \"../Shaders/Builtin/CzmBuiltins.js\";\nimport AutomaticUniforms from \"./AutomaticUniforms.js\";\nimport demodernizeShader from \"./demodernizeShader.js\";\n\nfunction removeComments(source) {\n // remove inline comments\n source = source.replace(/\\/\\/.*/g, \"\");\n // remove multiline comment block\n return source.replace(/\\/\\*\\*[\\s\\S]*?\\*\\//gm, function (match) {\n // preserve the number of lines in the comment block so the line numbers will be correct when debugging shaders\n const numberOfLines = match.match(/\\n/gm).length;\n let replacement = \"\";\n for (let lineNumber = 0; lineNumber < numberOfLines; ++lineNumber) {\n replacement += \"\\n\";\n }\n return replacement;\n });\n}\n\nfunction getDependencyNode(name, glslSource, nodes) {\n let dependencyNode;\n\n // check if already loaded\n for (let i = 0; i < nodes.length; ++i) {\n if (nodes[i].name === name) {\n dependencyNode = nodes[i];\n }\n }\n\n if (!defined(dependencyNode)) {\n // strip doc comments so we don't accidentally try to determine a dependency for something found\n // in a comment\n glslSource = removeComments(glslSource);\n\n // create new node\n dependencyNode = {\n name: name,\n glslSource: glslSource,\n dependsOn: [],\n requiredBy: [],\n evaluated: false,\n };\n nodes.push(dependencyNode);\n }\n\n return dependencyNode;\n}\n\nfunction generateDependencies(currentNode, dependencyNodes) {\n if (currentNode.evaluated) {\n return;\n }\n\n currentNode.evaluated = true;\n\n // identify all dependencies that are referenced from this glsl source code\n let czmMatches = currentNode.glslSource.match(/\\bczm_[a-zA-Z0-9_]*/g);\n if (defined(czmMatches) && czmMatches !== null) {\n // remove duplicates\n czmMatches = czmMatches.filter(function (elem, pos) {\n return czmMatches.indexOf(elem) === pos;\n });\n\n czmMatches.forEach(function (element) {\n if (\n element !== currentNode.name &&\n ShaderSource._czmBuiltinsAndUniforms.hasOwnProperty(element)\n ) {\n const referencedNode = getDependencyNode(\n element,\n ShaderSource._czmBuiltinsAndUniforms[element],\n dependencyNodes\n );\n currentNode.dependsOn.push(referencedNode);\n referencedNode.requiredBy.push(currentNode);\n\n // recursive call to find any dependencies of the new node\n generateDependencies(referencedNode, dependencyNodes);\n }\n });\n }\n}\n\nfunction sortDependencies(dependencyNodes) {\n const nodesWithoutIncomingEdges = [];\n const allNodes = [];\n\n while (dependencyNodes.length > 0) {\n const node = dependencyNodes.pop();\n allNodes.push(node);\n\n if (node.requiredBy.length === 0) {\n nodesWithoutIncomingEdges.push(node);\n }\n }\n\n while (nodesWithoutIncomingEdges.length > 0) {\n const currentNode = nodesWithoutIncomingEdges.shift();\n\n dependencyNodes.push(currentNode);\n\n for (let i = 0; i < currentNode.dependsOn.length; ++i) {\n // remove the edge from the graph\n const referencedNode = currentNode.dependsOn[i];\n const index = referencedNode.requiredBy.indexOf(currentNode);\n referencedNode.requiredBy.splice(index, 1);\n\n // if referenced node has no more incoming edges, add to list\n if (referencedNode.requiredBy.length === 0) {\n nodesWithoutIncomingEdges.push(referencedNode);\n }\n }\n }\n\n // if there are any nodes left with incoming edges, then there was a circular dependency somewhere in the graph\n const badNodes = [];\n for (let j = 0; j < allNodes.length; ++j) {\n if (allNodes[j].requiredBy.length !== 0) {\n badNodes.push(allNodes[j]);\n }\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (badNodes.length !== 0) {\n let message =\n \"A circular dependency was found in the following built-in functions/structs/constants: \\n\";\n for (let k = 0; k < badNodes.length; ++k) {\n message = `${message + badNodes[k].name}\\n`;\n }\n throw new DeveloperError(message);\n }\n //>>includeEnd('debug');\n}\n\nfunction getBuiltinsAndAutomaticUniforms(shaderSource) {\n // generate a dependency graph for builtin functions\n const dependencyNodes = [];\n const root = getDependencyNode(\"main\", shaderSource, dependencyNodes);\n generateDependencies(root, dependencyNodes);\n sortDependencies(dependencyNodes);\n\n // Concatenate the source code for the function dependencies.\n // Iterate in reverse so that dependent items are declared before they are used.\n let builtinsSource = \"\";\n for (let i = dependencyNodes.length - 1; i >= 0; --i) {\n builtinsSource = `${builtinsSource + dependencyNodes[i].glslSource}\\n`;\n }\n\n return builtinsSource.replace(root.glslSource, \"\");\n}\n\nfunction combineShader(shaderSource, isFragmentShader, context) {\n let i;\n let length;\n\n // Combine shader sources, generally for pseudo-polymorphism, e.g., czm_getMaterial.\n let combinedSources = \"\";\n const sources = shaderSource.sources;\n if (defined(sources)) {\n for (i = 0, length = sources.length; i < length; ++i) {\n // #line needs to be on its own line.\n combinedSources += `\\n#line 0\\n${sources[i]}`;\n }\n }\n\n combinedSources = removeComments(combinedSources);\n\n // Extract existing shader version from sources\n let version;\n combinedSources = combinedSources.replace(/#version\\s+(.*?)\\n/gm, function (\n match,\n group1\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(version) && version !== group1) {\n throw new DeveloperError(\n `inconsistent versions found: ${version} and ${group1}`\n );\n }\n //>>includeEnd('debug');\n\n // Extract #version to put at the top\n version = group1;\n\n // Replace original #version directive with a new line so the line numbers\n // are not off by one. There can be only one #version directive\n // and it must appear at the top of the source, only preceded by\n // whitespace and comments.\n return \"\\n\";\n });\n\n // Extract shader extensions from sources\n const extensions = [];\n combinedSources = combinedSources.replace(/#extension.*\\n/gm, function (\n match\n ) {\n // Extract extension to put at the top\n extensions.push(match);\n\n // Replace original #extension directive with a new line so the line numbers\n // are not off by one.\n return \"\\n\";\n });\n\n // Remove precision qualifier\n combinedSources = combinedSources.replace(\n /precision\\s(lowp|mediump|highp)\\s(float|int);/,\n \"\"\n );\n\n // Replace main() for picked if desired.\n const pickColorQualifier = shaderSource.pickColorQualifier;\n if (defined(pickColorQualifier)) {\n combinedSources = ShaderSource.createPickFragmentShaderSource(\n combinedSources,\n pickColorQualifier\n );\n }\n\n // combine into single string\n let result = \"\";\n\n const extensionsLength = extensions.length;\n for (i = 0; i < extensionsLength; i++) {\n result += extensions[i];\n }\n\n if (isFragmentShader) {\n // If high precision isn't support replace occurrences of highp with mediump\n // The highp keyword is not always available on older mobile devices\n // See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#In_WebGL_1_highp_float_support_is_optional_in_fragment_shaders\n result +=\n \"\\\n#ifdef GL_FRAGMENT_PRECISION_HIGH\\n\\\n precision highp float;\\n\\\n precision highp int;\\n\\\n#else\\n\\\n precision mediump float;\\n\\\n precision mediump int;\\n\\\n #define highp mediump\\n\\\n#endif\\n\\n\";\n }\n\n // Prepend #defines for uber-shaders\n const defines = shaderSource.defines;\n if (defined(defines)) {\n for (i = 0, length = defines.length; i < length; ++i) {\n const define = defines[i];\n if (define.length !== 0) {\n result += `#define ${define}\\n`;\n }\n }\n }\n\n // Define a constant for the OES_texture_float_linear extension since WebGL does not.\n if (context.textureFloatLinear) {\n result += \"#define OES_texture_float_linear\\n\\n\";\n }\n\n // Define a constant for the OES_texture_float extension since WebGL does not.\n if (context.floatingPointTexture) {\n result += \"#define OES_texture_float\\n\\n\";\n }\n\n // append built-ins\n let builtinSources = \"\";\n if (shaderSource.includeBuiltIns) {\n builtinSources = getBuiltinsAndAutomaticUniforms(combinedSources);\n }\n\n // reset line number\n result += \"\\n#line 0\\n\";\n\n // append actual source\n const combinedShader = builtinSources + combinedSources;\n if (\n context.webgl2 &&\n isFragmentShader &&\n !/layout\\s*\\(location\\s*=\\s*0\\)\\s*out\\s+vec4\\s+out_FragColor;/g.test(\n combinedShader\n ) &&\n !/czm_out_FragColor/g.test(combinedShader) &&\n /out_FragColor/g.test(combinedShader)\n ) {\n result += \"layout(location = 0) out vec4 out_FragColor;\\n\\n\";\n }\n\n result += builtinSources;\n result += combinedSources;\n\n // modernize the source\n if (!context.webgl2) {\n result = demodernizeShader(result, isFragmentShader);\n } else {\n result = `#version 300 es\\n${result}`;\n }\n\n return result;\n}\n\n/**\n * An object containing various inputs that will be combined to form a final GLSL shader string.\n *\n * @param {object} [options] Object with the following properties:\n * @param {string[]} [options.sources] An array of strings to combine containing GLSL code for the shader.\n * @param {string[]} [options.defines] An array of strings containing GLSL identifiers to #define.\n * @param {string} [options.pickColorQualifier] The GLSL qualifier, uniform or in, for the input czm_pickColor. When defined, a pick fragment shader is generated.\n * @param {boolean} [options.includeBuiltIns=true] If true, referenced built-in functions will be included with the combined shader. Set to false if this shader will become a source in another shader, to avoid duplicating functions.\n *\n * @exception {DeveloperError} options.pickColorQualifier must be 'uniform' or 'in'.\n *\n * @example\n * // 1. Prepend #defines to a shader\n * const source = new Cesium.ShaderSource({\n * defines : ['WHITE'],\n * sources : ['void main() { \\n#ifdef WHITE\\n out_FragColor = vec4(1.0); \\n#else\\n out_FragColor = vec4(0.0); \\n#endif\\n }']\n * });\n *\n * // 2. Modify a fragment shader for picking\n * const source2 = new Cesium.ShaderSource({\n * sources : ['void main() { out_FragColor = vec4(1.0); }'],\n * pickColorQualifier : 'uniform'\n * });\n *\n * @private\n */\nfunction ShaderSource(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const pickColorQualifier = options.pickColorQualifier;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(pickColorQualifier) &&\n pickColorQualifier !== \"uniform\" &&\n pickColorQualifier !== \"in\"\n ) {\n throw new DeveloperError(\n \"options.pickColorQualifier must be 'uniform' or 'in'.\"\n );\n }\n //>>includeEnd('debug');\n\n this.defines = defined(options.defines) ? options.defines.slice(0) : [];\n this.sources = defined(options.sources) ? options.sources.slice(0) : [];\n this.pickColorQualifier = pickColorQualifier;\n this.includeBuiltIns = defaultValue(options.includeBuiltIns, true);\n}\n\nShaderSource.prototype.clone = function () {\n return new ShaderSource({\n sources: this.sources,\n defines: this.defines,\n pickColorQualifier: this.pickColorQualifier,\n includeBuiltIns: this.includeBuiltIns,\n });\n};\n\nShaderSource.replaceMain = function (source, renamedMain) {\n renamedMain = `void ${renamedMain}()`;\n return source.replace(/void\\s+main\\s*\\(\\s*(?:void)?\\s*\\)/g, renamedMain);\n};\n\n/**\n * Since {@link ShaderSource#createCombinedVertexShader} and\n * {@link ShaderSource#createCombinedFragmentShader} are both expensive to\n * compute, create a simpler string key for lookups in the {@link ShaderCache}.\n *\n * @returns {string} A key for identifying this shader\n *\n * @private\n */\nShaderSource.prototype.getCacheKey = function () {\n // Sort defines to make the key comparison deterministic\n const sortedDefines = this.defines.slice().sort();\n const definesKey = sortedDefines.join(\",\");\n const pickKey = this.pickColorQualifier;\n const builtinsKey = this.includeBuiltIns;\n const sourcesKey = this.sources.join(\"\\n\");\n\n return `${definesKey}:${pickKey}:${builtinsKey}:${sourcesKey}`;\n};\n\n/**\n * Create a single string containing the full, combined vertex shader with all dependencies and defines.\n *\n * @param {Context} context The current rendering context\n *\n * @returns {string} The combined shader string.\n */\nShaderSource.prototype.createCombinedVertexShader = function (context) {\n return combineShader(this, false, context);\n};\n\n/**\n * Create a single string containing the full, combined fragment shader with all dependencies and defines.\n *\n * @param {Context} context The current rendering context\n *\n * @returns {string} The combined shader string.\n */\nShaderSource.prototype.createCombinedFragmentShader = function (context) {\n return combineShader(this, true, context);\n};\n\n/**\n * For ShaderProgram testing\n * @private\n */\nShaderSource._czmBuiltinsAndUniforms = {};\n\n// combine automatic uniforms and Cesium built-ins\nfor (const builtinName in CzmBuiltins) {\n if (CzmBuiltins.hasOwnProperty(builtinName)) {\n ShaderSource._czmBuiltinsAndUniforms[builtinName] =\n CzmBuiltins[builtinName];\n }\n}\nfor (const uniformName in AutomaticUniforms) {\n if (AutomaticUniforms.hasOwnProperty(uniformName)) {\n const uniform = AutomaticUniforms[uniformName];\n if (typeof uniform.getDeclaration === \"function\") {\n ShaderSource._czmBuiltinsAndUniforms[\n uniformName\n ] = uniform.getDeclaration(uniformName);\n }\n }\n}\n\nShaderSource.createPickVertexShaderSource = function (vertexShaderSource) {\n const renamedVS = ShaderSource.replaceMain(\n vertexShaderSource,\n \"czm_old_main\"\n );\n const pickMain =\n \"in vec4 pickColor; \\n\" +\n \"out vec4 czm_pickColor; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" czm_old_main(); \\n\" +\n \" czm_pickColor = pickColor; \\n\" +\n \"}\";\n\n return `${renamedVS}\\n${pickMain}`;\n};\n\nShaderSource.createPickFragmentShaderSource = function (\n fragmentShaderSource,\n pickColorQualifier\n) {\n const renamedFS = ShaderSource.replaceMain(\n fragmentShaderSource,\n \"czm_old_main\"\n );\n const pickMain =\n `${pickColorQualifier} vec4 czm_pickColor; \\n` +\n `void main() \\n` +\n `{ \\n` +\n ` czm_old_main(); \\n` +\n ` if (out_FragColor.a == 0.0) { \\n` +\n ` discard; \\n` +\n ` } \\n` +\n ` out_FragColor = czm_pickColor; \\n` +\n `}`;\n\n return `${renamedFS}\\n${pickMain}`;\n};\n\nfunction containsDefine(shaderSource, define) {\n const defines = shaderSource.defines;\n const definesLength = defines.length;\n for (let i = 0; i < definesLength; ++i) {\n if (defines[i] === define) {\n return true;\n }\n }\n return false;\n}\n\nfunction containsString(shaderSource, string) {\n const sources = shaderSource.sources;\n const sourcesLength = sources.length;\n for (let i = 0; i < sourcesLength; ++i) {\n if (sources[i].indexOf(string) !== -1) {\n return true;\n }\n }\n return false;\n}\n\nfunction findFirstString(shaderSource, strings) {\n const stringsLength = strings.length;\n for (let i = 0; i < stringsLength; ++i) {\n const string = strings[i];\n if (containsString(shaderSource, string)) {\n return string;\n }\n }\n return undefined;\n}\n\nconst normalVaryingNames = [\"v_normalEC\", \"v_normal\"];\n\nShaderSource.findNormalVarying = function (shaderSource) {\n // Fix for Model: the shader text always has the word v_normalEC\n // wrapped in an #ifdef so instead of looking for v_normalEC look for the define\n if (containsString(shaderSource, \"#ifdef HAS_NORMALS\")) {\n if (containsDefine(shaderSource, \"HAS_NORMALS\")) {\n return \"v_normalEC\";\n }\n return undefined;\n }\n\n return findFirstString(shaderSource, normalVaryingNames);\n};\n\nconst positionVaryingNames = [\"v_positionEC\"];\n\nShaderSource.findPositionVarying = function (shaderSource) {\n return findFirstString(shaderSource, positionVaryingNames);\n};\nexport default ShaderSource;\n", "import defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport ShaderProgram from \"./ShaderProgram.js\";\nimport ShaderSource from \"./ShaderSource.js\";\n\n/**\n * @private\n */\nfunction ShaderCache(context) {\n this._context = context;\n this._shaders = {};\n this._numberOfShaders = 0;\n this._shadersToRelease = {};\n}\n\nObject.defineProperties(ShaderCache.prototype, {\n numberOfShaders: {\n get: function () {\n return this._numberOfShaders;\n },\n },\n});\n\n/**\n * Returns a shader program from the cache, or creates and caches a new shader program,\n * given the GLSL vertex and fragment shader source and attribute locations.\n *

\n * The difference between this and {@link ShaderCache#getShaderProgram}, is this is used to\n * replace an existing reference to a shader program, which is passed as the first argument.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {ShaderProgram} [options.shaderProgram] The shader program that is being reassigned.\n * @param {string|ShaderSource} options.vertexShaderSource The GLSL source for the vertex shader.\n * @param {string|ShaderSource} options.fragmentShaderSource The GLSL source for the fragment shader.\n * @param {object} options.attributeLocations Indices for the attribute inputs to the vertex shader.\n\n * @returns {ShaderProgram} The cached or newly created shader program.\n *\n *\n * @example\n * this._shaderProgram = context.shaderCache.replaceShaderProgram({\n * shaderProgram : this._shaderProgram,\n * vertexShaderSource : vs,\n * fragmentShaderSource : fs,\n * attributeLocations : attributeLocations\n * });\n *\n * @see ShaderCache#getShaderProgram\n */\nShaderCache.prototype.replaceShaderProgram = function (options) {\n if (defined(options.shaderProgram)) {\n options.shaderProgram.destroy();\n }\n\n return this.getShaderProgram(options);\n};\n\nfunction toSortedJson(dictionary) {\n const sortedKeys = Object.keys(dictionary).sort();\n return JSON.stringify(dictionary, sortedKeys);\n}\n\n/**\n * Returns a shader program from the cache, or creates and caches a new shader program,\n * given the GLSL vertex and fragment shader source and attribute locations.\n *\n * @param {object} options Object with the following properties:\n * @param {string|ShaderSource} options.vertexShaderSource The GLSL source for the vertex shader.\n * @param {string|ShaderSource} options.fragmentShaderSource The GLSL source for the fragment shader.\n * @param {object} options.attributeLocations Indices for the attribute inputs to the vertex shader.\n *\n * @returns {ShaderProgram} The cached or newly created shader program.\n */\nShaderCache.prototype.getShaderProgram = function (options) {\n // convert shaders which are provided as strings into ShaderSource objects\n // because ShaderSource handles all the automatic including of built-in functions, etc.\n\n let vertexShaderSource = options.vertexShaderSource;\n let fragmentShaderSource = options.fragmentShaderSource;\n const attributeLocations = options.attributeLocations;\n\n if (typeof vertexShaderSource === \"string\") {\n vertexShaderSource = new ShaderSource({\n sources: [vertexShaderSource],\n });\n }\n\n if (typeof fragmentShaderSource === \"string\") {\n fragmentShaderSource = new ShaderSource({\n sources: [fragmentShaderSource],\n });\n }\n\n // Since ShaderSource.createCombinedXxxShader() can be expensive, use a\n // simpler key for caching. This way, the function does not have to be called\n // for each cache lookup.\n const vertexShaderKey = vertexShaderSource.getCacheKey();\n const fragmentShaderKey = fragmentShaderSource.getCacheKey();\n // Sort the keys in the JSON to ensure a consistent order\n const attributeLocationKey = defined(attributeLocations)\n ? toSortedJson(attributeLocations)\n : \"\";\n const keyword = `${vertexShaderKey}:${fragmentShaderKey}:${attributeLocationKey}`;\n\n let cachedShader;\n if (defined(this._shaders[keyword])) {\n cachedShader = this._shaders[keyword];\n\n // No longer want to release this if it was previously released.\n delete this._shadersToRelease[keyword];\n } else {\n const context = this._context;\n\n const vertexShaderText = vertexShaderSource.createCombinedVertexShader(\n context\n );\n const fragmentShaderText = fragmentShaderSource.createCombinedFragmentShader(\n context\n );\n\n const shaderProgram = new ShaderProgram({\n gl: context._gl,\n logShaderCompilation: context.logShaderCompilation,\n debugShaders: context.debugShaders,\n vertexShaderSource: vertexShaderSource,\n vertexShaderText: vertexShaderText,\n fragmentShaderSource: fragmentShaderSource,\n fragmentShaderText: fragmentShaderText,\n attributeLocations: attributeLocations,\n });\n\n cachedShader = {\n cache: this,\n shaderProgram: shaderProgram,\n keyword: keyword,\n derivedKeywords: [],\n count: 0,\n };\n\n // A shader can't be in more than one cache.\n shaderProgram._cachedShader = cachedShader;\n this._shaders[keyword] = cachedShader;\n ++this._numberOfShaders;\n }\n\n ++cachedShader.count;\n return cachedShader.shaderProgram;\n};\n\nShaderCache.prototype.replaceDerivedShaderProgram = function (\n shaderProgram,\n keyword,\n options\n) {\n const cachedShader = shaderProgram._cachedShader;\n const derivedKeyword = keyword + cachedShader.keyword;\n const cachedDerivedShader = this._shaders[derivedKeyword];\n if (defined(cachedDerivedShader)) {\n destroyShader(this, cachedDerivedShader);\n const index = cachedShader.derivedKeywords.indexOf(keyword);\n if (index > -1) {\n cachedShader.derivedKeywords.splice(index, 1);\n }\n }\n\n return this.createDerivedShaderProgram(shaderProgram, keyword, options);\n};\n\nShaderCache.prototype.getDerivedShaderProgram = function (\n shaderProgram,\n keyword\n) {\n const cachedShader = shaderProgram._cachedShader;\n const derivedKeyword = keyword + cachedShader.keyword;\n const cachedDerivedShader = this._shaders[derivedKeyword];\n if (!defined(cachedDerivedShader)) {\n return undefined;\n }\n\n return cachedDerivedShader.shaderProgram;\n};\n\nShaderCache.prototype.createDerivedShaderProgram = function (\n shaderProgram,\n keyword,\n options\n) {\n const cachedShader = shaderProgram._cachedShader;\n const derivedKeyword = keyword + cachedShader.keyword;\n\n let vertexShaderSource = options.vertexShaderSource;\n let fragmentShaderSource = options.fragmentShaderSource;\n const attributeLocations = options.attributeLocations;\n\n if (typeof vertexShaderSource === \"string\") {\n vertexShaderSource = new ShaderSource({\n sources: [vertexShaderSource],\n });\n }\n\n if (typeof fragmentShaderSource === \"string\") {\n fragmentShaderSource = new ShaderSource({\n sources: [fragmentShaderSource],\n });\n }\n\n const context = this._context;\n\n const vertexShaderText = vertexShaderSource.createCombinedVertexShader(\n context\n );\n const fragmentShaderText = fragmentShaderSource.createCombinedFragmentShader(\n context\n );\n\n const derivedShaderProgram = new ShaderProgram({\n gl: context._gl,\n logShaderCompilation: context.logShaderCompilation,\n debugShaders: context.debugShaders,\n vertexShaderSource: vertexShaderSource,\n vertexShaderText: vertexShaderText,\n fragmentShaderSource: fragmentShaderSource,\n fragmentShaderText: fragmentShaderText,\n attributeLocations: attributeLocations,\n });\n\n const derivedCachedShader = {\n cache: this,\n shaderProgram: derivedShaderProgram,\n keyword: derivedKeyword,\n derivedKeywords: [],\n count: 0,\n };\n\n cachedShader.derivedKeywords.push(keyword);\n derivedShaderProgram._cachedShader = derivedCachedShader;\n this._shaders[derivedKeyword] = derivedCachedShader;\n return derivedShaderProgram;\n};\n\nfunction destroyShader(cache, cachedShader) {\n const derivedKeywords = cachedShader.derivedKeywords;\n const length = derivedKeywords.length;\n for (let i = 0; i < length; ++i) {\n const keyword = derivedKeywords[i] + cachedShader.keyword;\n const derivedCachedShader = cache._shaders[keyword];\n destroyShader(cache, derivedCachedShader);\n }\n\n delete cache._shaders[cachedShader.keyword];\n cachedShader.shaderProgram.finalDestroy();\n}\n\nShaderCache.prototype.destroyReleasedShaderPrograms = function () {\n const shadersToRelease = this._shadersToRelease;\n\n for (const keyword in shadersToRelease) {\n if (shadersToRelease.hasOwnProperty(keyword)) {\n const cachedShader = shadersToRelease[keyword];\n destroyShader(this, cachedShader);\n --this._numberOfShaders;\n }\n }\n\n this._shadersToRelease = {};\n};\n\nShaderCache.prototype.releaseShaderProgram = function (shaderProgram) {\n if (defined(shaderProgram)) {\n const cachedShader = shaderProgram._cachedShader;\n if (cachedShader && --cachedShader.count === 0) {\n this._shadersToRelease[cachedShader.keyword] = cachedShader;\n }\n }\n};\n\nShaderCache.prototype.isDestroyed = function () {\n return false;\n};\n\nShaderCache.prototype.destroy = function () {\n const shaders = this._shaders;\n for (const keyword in shaders) {\n if (shaders.hasOwnProperty(keyword)) {\n shaders[keyword].shaderProgram.finalDestroy();\n }\n }\n return destroyObject(this);\n};\nexport default ShaderCache;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Check from \"../Core/Check.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport MipmapHint from \"./MipmapHint.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\nimport Sampler from \"./Sampler.js\";\nimport TextureMagnificationFilter from \"./TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"./TextureMinificationFilter.js\";\n\n/**\n * @private\n */\nfunction Texture(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n const context = options.context;\n let width = options.width;\n let height = options.height;\n const source = options.source;\n\n if (defined(source)) {\n if (!defined(width)) {\n width = defaultValue(source.videoWidth, source.width);\n }\n if (!defined(height)) {\n height = defaultValue(source.videoHeight, source.height);\n }\n }\n\n const pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA);\n const pixelDatatype = defaultValue(\n options.pixelDatatype,\n PixelDatatype.UNSIGNED_BYTE\n );\n const internalFormat = PixelFormat.toInternalFormat(\n pixelFormat,\n pixelDatatype,\n context\n );\n\n const isCompressed = PixelFormat.isCompressedFormat(internalFormat);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(width) || !defined(height)) {\n throw new DeveloperError(\n \"options requires a source field to create an initialized texture or width and height fields to create a blank texture.\"\n );\n }\n\n Check.typeOf.number.greaterThan(\"width\", width, 0);\n\n if (width > ContextLimits.maximumTextureSize) {\n throw new DeveloperError(\n `Width must be less than or equal to the maximum texture size (${ContextLimits.maximumTextureSize}). Check maximumTextureSize.`\n );\n }\n\n Check.typeOf.number.greaterThan(\"height\", height, 0);\n\n if (height > ContextLimits.maximumTextureSize) {\n throw new DeveloperError(\n `Height must be less than or equal to the maximum texture size (${ContextLimits.maximumTextureSize}). Check maximumTextureSize.`\n );\n }\n\n if (!PixelFormat.validate(pixelFormat)) {\n throw new DeveloperError(\"Invalid options.pixelFormat.\");\n }\n\n if (!isCompressed && !PixelDatatype.validate(pixelDatatype)) {\n throw new DeveloperError(\"Invalid options.pixelDatatype.\");\n }\n\n if (\n pixelFormat === PixelFormat.DEPTH_COMPONENT &&\n pixelDatatype !== PixelDatatype.UNSIGNED_SHORT &&\n pixelDatatype !== PixelDatatype.UNSIGNED_INT\n ) {\n throw new DeveloperError(\n \"When options.pixelFormat is DEPTH_COMPONENT, options.pixelDatatype must be UNSIGNED_SHORT or UNSIGNED_INT.\"\n );\n }\n\n if (\n pixelFormat === PixelFormat.DEPTH_STENCIL &&\n pixelDatatype !== PixelDatatype.UNSIGNED_INT_24_8\n ) {\n throw new DeveloperError(\n \"When options.pixelFormat is DEPTH_STENCIL, options.pixelDatatype must be UNSIGNED_INT_24_8.\"\n );\n }\n\n if (pixelDatatype === PixelDatatype.FLOAT && !context.floatingPointTexture) {\n throw new DeveloperError(\n \"When options.pixelDatatype is FLOAT, this WebGL implementation must support the OES_texture_float extension. Check context.floatingPointTexture.\"\n );\n }\n\n if (\n pixelDatatype === PixelDatatype.HALF_FLOAT &&\n !context.halfFloatingPointTexture\n ) {\n throw new DeveloperError(\n \"When options.pixelDatatype is HALF_FLOAT, this WebGL implementation must support the OES_texture_half_float extension. Check context.halfFloatingPointTexture.\"\n );\n }\n\n if (PixelFormat.isDepthFormat(pixelFormat)) {\n if (defined(source)) {\n throw new DeveloperError(\n \"When options.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, source cannot be provided.\"\n );\n }\n\n if (!context.depthTexture) {\n throw new DeveloperError(\n \"When options.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, this WebGL implementation must support WEBGL_depth_texture. Check context.depthTexture.\"\n );\n }\n }\n\n if (isCompressed) {\n if (!defined(source) || !defined(source.arrayBufferView)) {\n throw new DeveloperError(\n \"When options.pixelFormat is compressed, options.source.arrayBufferView must be defined.\"\n );\n }\n\n if (PixelFormat.isDXTFormat(internalFormat) && !context.s3tc) {\n throw new DeveloperError(\n \"When options.pixelFormat is S3TC compressed, this WebGL implementation must support the WEBGL_compressed_texture_s3tc extension. Check context.s3tc.\"\n );\n } else if (PixelFormat.isPVRTCFormat(internalFormat) && !context.pvrtc) {\n throw new DeveloperError(\n \"When options.pixelFormat is PVRTC compressed, this WebGL implementation must support the WEBGL_compressed_texture_pvrtc extension. Check context.pvrtc.\"\n );\n } else if (PixelFormat.isASTCFormat(internalFormat) && !context.astc) {\n throw new DeveloperError(\n \"When options.pixelFormat is ASTC compressed, this WebGL implementation must support the WEBGL_compressed_texture_astc extension. Check context.astc.\"\n );\n } else if (PixelFormat.isETC2Format(internalFormat) && !context.etc) {\n throw new DeveloperError(\n \"When options.pixelFormat is ETC2 compressed, this WebGL implementation must support the WEBGL_compressed_texture_etc extension. Check context.etc.\"\n );\n } else if (PixelFormat.isETC1Format(internalFormat) && !context.etc1) {\n throw new DeveloperError(\n \"When options.pixelFormat is ETC1 compressed, this WebGL implementation must support the WEBGL_compressed_texture_etc1 extension. Check context.etc1.\"\n );\n } else if (PixelFormat.isBC7Format(internalFormat) && !context.bc7) {\n throw new DeveloperError(\n \"When options.pixelFormat is BC7 compressed, this WebGL implementation must support the EXT_texture_compression_bptc extension. Check context.bc7.\"\n );\n }\n\n if (\n PixelFormat.compressedTextureSizeInBytes(\n internalFormat,\n width,\n height\n ) !== source.arrayBufferView.byteLength\n ) {\n throw new DeveloperError(\n \"The byte length of the array buffer is invalid for the compressed texture with the given width and height.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n // Use premultiplied alpha for opaque textures should perform better on Chrome:\n // http://media.tojicode.com/webglCamp4/#20\n const preMultiplyAlpha =\n options.preMultiplyAlpha ||\n pixelFormat === PixelFormat.RGB ||\n pixelFormat === PixelFormat.LUMINANCE;\n const flipY = defaultValue(options.flipY, true);\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n let initialized = true;\n\n const gl = context._gl;\n const textureTarget = gl.TEXTURE_2D;\n const texture = gl.createTexture();\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(textureTarget, texture);\n\n let unpackAlignment = 4;\n if (defined(source) && defined(source.arrayBufferView) && !isCompressed) {\n unpackAlignment = PixelFormat.alignmentInBytes(\n pixelFormat,\n pixelDatatype,\n width\n );\n }\n\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);\n\n if (skipColorSpaceConversion) {\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n } else {\n gl.pixelStorei(\n gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,\n gl.BROWSER_DEFAULT_WEBGL\n );\n }\n\n if (defined(source)) {\n if (defined(source.arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n // Source: typed array\n let arrayBufferView = source.arrayBufferView;\n let i, mipWidth, mipHeight;\n if (isCompressed) {\n gl.compressedTexImage2D(\n textureTarget,\n 0,\n internalFormat,\n width,\n height,\n 0,\n arrayBufferView\n );\n if (defined(source.mipLevels)) {\n mipWidth = width;\n mipHeight = height;\n for (i = 0; i < source.mipLevels.length; ++i) {\n mipWidth = Math.floor(mipWidth / 2) | 0;\n if (mipWidth < 1) {\n mipWidth = 1;\n }\n mipHeight = Math.floor(mipHeight / 2) | 0;\n if (mipHeight < 1) {\n mipHeight = 1;\n }\n gl.compressedTexImage2D(\n textureTarget,\n i + 1,\n internalFormat,\n mipWidth,\n mipHeight,\n 0,\n source.mipLevels[i]\n );\n }\n }\n } else {\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n width,\n height\n );\n }\n gl.texImage2D(\n textureTarget,\n 0,\n internalFormat,\n width,\n height,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n arrayBufferView\n );\n\n if (defined(source.mipLevels)) {\n mipWidth = width;\n mipHeight = height;\n for (i = 0; i < source.mipLevels.length; ++i) {\n mipWidth = Math.floor(mipWidth / 2) | 0;\n if (mipWidth < 1) {\n mipWidth = 1;\n }\n mipHeight = Math.floor(mipHeight / 2) | 0;\n if (mipHeight < 1) {\n mipHeight = 1;\n }\n gl.texImage2D(\n textureTarget,\n i + 1,\n internalFormat,\n mipWidth,\n mipHeight,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n source.mipLevels[i]\n );\n }\n }\n }\n } else if (defined(source.framebuffer)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n // Source: framebuffer\n if (source.framebuffer !== context.defaultFramebuffer) {\n source.framebuffer._bind();\n }\n\n gl.copyTexImage2D(\n textureTarget,\n 0,\n internalFormat,\n source.xOffset,\n source.yOffset,\n width,\n height,\n 0\n );\n\n if (source.framebuffer !== context.defaultFramebuffer) {\n source.framebuffer._unBind();\n }\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n // Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement\n gl.texImage2D(\n textureTarget,\n 0,\n internalFormat,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n source\n );\n }\n } else {\n gl.texImage2D(\n textureTarget,\n 0,\n internalFormat,\n width,\n height,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n null\n );\n initialized = false;\n }\n gl.bindTexture(textureTarget, null);\n\n let sizeInBytes;\n if (isCompressed) {\n sizeInBytes = PixelFormat.compressedTextureSizeInBytes(\n pixelFormat,\n width,\n height\n );\n } else {\n sizeInBytes = PixelFormat.textureSizeInBytes(\n pixelFormat,\n pixelDatatype,\n width,\n height\n );\n }\n\n this._id = createGuid();\n this._context = context;\n this._textureFilterAnisotropic = context._textureFilterAnisotropic;\n this._textureTarget = textureTarget;\n this._texture = texture;\n this._internalFormat = internalFormat;\n this._pixelFormat = pixelFormat;\n this._pixelDatatype = pixelDatatype;\n this._width = width;\n this._height = height;\n this._dimensions = new Cartesian2(width, height);\n this._hasMipmap = false;\n this._sizeInBytes = sizeInBytes;\n this._preMultiplyAlpha = preMultiplyAlpha;\n this._flipY = flipY;\n this._initialized = initialized;\n this._sampler = undefined;\n\n this.sampler = defined(options.sampler) ? options.sampler : new Sampler();\n}\n\n/**\n * This function is identical to using the Texture constructor except that it can be\n * replaced with a mock/spy in tests.\n * @private\n */\nTexture.create = function (options) {\n return new Texture(options);\n};\n\n/**\n * Creates a texture, and copies a subimage of the framebuffer to it. When called without arguments,\n * the texture is the same width and height as the framebuffer and contains its contents.\n *\n * @param {object} options Object with the following properties:\n * @param {Context} options.context The context in which the Texture gets created.\n * @param {PixelFormat} [options.pixelFormat=PixelFormat.RGB] The texture's internal pixel format.\n * @param {number} [options.framebufferXOffset=0] An offset in the x direction in the framebuffer where copying begins from.\n * @param {number} [options.framebufferYOffset=0] An offset in the y direction in the framebuffer where copying begins from.\n * @param {number} [options.width=canvas.clientWidth] The width of the texture in texels.\n * @param {number} [options.height=canvas.clientHeight] The height of the texture in texels.\n * @param {Framebuffer} [options.framebuffer=defaultFramebuffer] The framebuffer from which to create the texture. If this\n * parameter is not specified, the default framebuffer is used.\n * @returns {Texture} A texture with contents from the framebuffer.\n *\n * @exception {DeveloperError} Invalid pixelFormat.\n * @exception {DeveloperError} pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.\n * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferXOffset + width must be less than or equal to canvas.clientWidth.\n * @exception {DeveloperError} framebufferYOffset + height must be less than or equal to canvas.clientHeight.\n *\n *\n * @example\n * // Create a texture with the contents of the framebuffer.\n * const t = Texture.fromFramebuffer({\n * context : context\n * });\n *\n * @see Sampler\n *\n * @private\n */\nTexture.fromFramebuffer = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n const context = options.context;\n const gl = context._gl;\n\n const pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGB);\n const framebufferXOffset = defaultValue(options.framebufferXOffset, 0);\n const framebufferYOffset = defaultValue(options.framebufferYOffset, 0);\n const width = defaultValue(options.width, gl.drawingBufferWidth);\n const height = defaultValue(options.height, gl.drawingBufferHeight);\n const framebuffer = options.framebuffer;\n\n //>>includeStart('debug', pragmas.debug);\n if (!PixelFormat.validate(pixelFormat)) {\n throw new DeveloperError(\"Invalid pixelFormat.\");\n }\n if (\n PixelFormat.isDepthFormat(pixelFormat) ||\n PixelFormat.isCompressedFormat(pixelFormat)\n ) {\n throw new DeveloperError(\n \"pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.\"\n );\n }\n Check.defined(\"options.context\", options.context);\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferXOffset\",\n framebufferXOffset,\n 0\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferYOffset\",\n framebufferYOffset,\n 0\n );\n if (framebufferXOffset + width > gl.drawingBufferWidth) {\n throw new DeveloperError(\n \"framebufferXOffset + width must be less than or equal to drawingBufferWidth\"\n );\n }\n if (framebufferYOffset + height > gl.drawingBufferHeight) {\n throw new DeveloperError(\n \"framebufferYOffset + height must be less than or equal to drawingBufferHeight.\"\n );\n }\n //>>includeEnd('debug');\n\n const texture = new Texture({\n context: context,\n width: width,\n height: height,\n pixelFormat: pixelFormat,\n source: {\n framebuffer: defined(framebuffer)\n ? framebuffer\n : context.defaultFramebuffer,\n xOffset: framebufferXOffset,\n yOffset: framebufferYOffset,\n width: width,\n height: height,\n },\n });\n\n return texture;\n};\n\nObject.defineProperties(Texture.prototype, {\n /**\n * A unique id for the texture\n * @memberof Texture.prototype\n * @type {string}\n * @readonly\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * The sampler to use when sampling this texture.\n * Create a sampler by calling {@link Sampler}. If this\n * parameter is not specified, a default sampler is used. The default sampler clamps texture\n * coordinates in both directions, uses linear filtering for both magnification and minification,\n * and uses a maximum anisotropy of 1.0.\n * @memberof Texture.prototype\n * @type {object}\n */\n sampler: {\n get: function () {\n return this._sampler;\n },\n set: function (sampler) {\n let minificationFilter = sampler.minificationFilter;\n let magnificationFilter = sampler.magnificationFilter;\n const context = this._context;\n const pixelFormat = this._pixelFormat;\n const pixelDatatype = this._pixelDatatype;\n\n const mipmap =\n minificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||\n minificationFilter ===\n TextureMinificationFilter.NEAREST_MIPMAP_LINEAR ||\n minificationFilter ===\n TextureMinificationFilter.LINEAR_MIPMAP_NEAREST ||\n minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR;\n\n // float textures only support nearest filtering unless the linear extensions are supported, so override the sampler's settings\n if (\n (pixelDatatype === PixelDatatype.FLOAT &&\n !context.textureFloatLinear) ||\n (pixelDatatype === PixelDatatype.HALF_FLOAT &&\n !context.textureHalfFloatLinear)\n ) {\n minificationFilter = mipmap\n ? TextureMinificationFilter.NEAREST_MIPMAP_NEAREST\n : TextureMinificationFilter.NEAREST;\n magnificationFilter = TextureMagnificationFilter.NEAREST;\n }\n\n // WebGL 2 depth texture only support nearest filtering. See section 3.8.13 OpenGL ES 3 spec\n if (context.webgl2) {\n if (PixelFormat.isDepthFormat(pixelFormat)) {\n minificationFilter = TextureMinificationFilter.NEAREST;\n magnificationFilter = TextureMagnificationFilter.NEAREST;\n }\n }\n\n const gl = context._gl;\n const target = this._textureTarget;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);\n gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);\n gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);\n gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);\n if (defined(this._textureFilterAnisotropic)) {\n gl.texParameteri(\n target,\n this._textureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,\n sampler.maximumAnisotropy\n );\n }\n gl.bindTexture(target, null);\n\n this._sampler = sampler;\n },\n },\n pixelFormat: {\n get: function () {\n return this._pixelFormat;\n },\n },\n pixelDatatype: {\n get: function () {\n return this._pixelDatatype;\n },\n },\n dimensions: {\n get: function () {\n return this._dimensions;\n },\n },\n preMultiplyAlpha: {\n get: function () {\n return this._preMultiplyAlpha;\n },\n },\n flipY: {\n get: function () {\n return this._flipY;\n },\n },\n width: {\n get: function () {\n return this._width;\n },\n },\n height: {\n get: function () {\n return this._height;\n },\n },\n sizeInBytes: {\n get: function () {\n if (this._hasMipmap) {\n return Math.floor((this._sizeInBytes * 4) / 3);\n }\n return this._sizeInBytes;\n },\n },\n _target: {\n get: function () {\n return this._textureTarget;\n },\n },\n});\n\n/**\n * Copy new image data into this texture, from a source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, or {@link HTMLVideoElement}.\n * or an object with width, height, and arrayBufferView properties.\n * @param {object} options Object with the following properties:\n * @param {object} options.source The source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, or {@link HTMLVideoElement},\n * or an object with width, height, and arrayBufferView properties.\n * @param {number} [options.xOffset=0] The offset in the x direction within the texture to copy into.\n * @param {number} [options.yOffset=0] The offset in the y direction within the texture to copy into.\n * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the texture will be ignored.\n *\n * @exception {DeveloperError} Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\n * @exception {DeveloperError} Cannot call copyFrom with a compressed texture pixel format.\n * @exception {DeveloperError} xOffset must be greater than or equal to zero.\n * @exception {DeveloperError} yOffset must be greater than or equal to zero.\n * @exception {DeveloperError} xOffset + source.width must be less than or equal to width.\n * @exception {DeveloperError} yOffset + source.height must be less than or equal to height.\n * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.\n *\n * @example\n * texture.copyFrom({\n * source: {\n * width : 1,\n * height : 1,\n * arrayBufferView : new Uint8Array([255, 0, 0, 255])\n * }\n * });\n */\nTexture.prototype.copyFrom = function (options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options\", options);\n //>>includeEnd('debug');\n\n const xOffset = defaultValue(options.xOffset, 0);\n const yOffset = defaultValue(options.yOffset, 0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.source\", options.source);\n if (PixelFormat.isDepthFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\"\n );\n }\n if (PixelFormat.isCompressedFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call copyFrom with a compressed texture pixel format.\"\n );\n }\n Check.typeOf.number.greaterThanOrEquals(\"xOffset\", xOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\"yOffset\", yOffset, 0);\n Check.typeOf.number.lessThanOrEquals(\n \"xOffset + options.source.width\",\n xOffset + options.source.width,\n this._width\n );\n Check.typeOf.number.lessThanOrEquals(\n \"yOffset + options.source.height\",\n yOffset + options.source.height,\n this._height\n );\n //>>includeEnd('debug');\n\n const source = options.source;\n\n const context = this._context;\n const gl = context._gl;\n const target = this._textureTarget;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n\n const width = source.width;\n const height = source.height;\n let arrayBufferView = source.arrayBufferView;\n\n const textureWidth = this._width;\n const textureHeight = this._height;\n const internalFormat = this._internalFormat;\n const pixelFormat = this._pixelFormat;\n const pixelDatatype = this._pixelDatatype;\n\n const preMultiplyAlpha = this._preMultiplyAlpha;\n const flipY = this._flipY;\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n\n let unpackAlignment = 4;\n if (defined(arrayBufferView)) {\n unpackAlignment = PixelFormat.alignmentInBytes(\n pixelFormat,\n pixelDatatype,\n width\n );\n }\n\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);\n\n if (skipColorSpaceConversion) {\n gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);\n } else {\n gl.pixelStorei(\n gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,\n gl.BROWSER_DEFAULT_WEBGL\n );\n }\n\n let uploaded = false;\n if (!this._initialized) {\n if (\n xOffset === 0 &&\n yOffset === 0 &&\n width === textureWidth &&\n height === textureHeight\n ) {\n // initialize the entire texture\n if (defined(arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n textureWidth,\n textureHeight\n );\n }\n gl.texImage2D(\n target,\n 0,\n internalFormat,\n textureWidth,\n textureHeight,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n arrayBufferView\n );\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n gl.texImage2D(\n target,\n 0,\n internalFormat,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n source\n );\n }\n uploaded = true;\n } else {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n // initialize the entire texture to zero\n const bufferView = PixelFormat.createTypedArray(\n pixelFormat,\n pixelDatatype,\n textureWidth,\n textureHeight\n );\n gl.texImage2D(\n target,\n 0,\n internalFormat,\n textureWidth,\n textureHeight,\n 0,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n bufferView\n );\n }\n this._initialized = true;\n }\n\n if (!uploaded) {\n if (defined(arrayBufferView)) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n if (flipY) {\n arrayBufferView = PixelFormat.flipY(\n arrayBufferView,\n pixelFormat,\n pixelDatatype,\n width,\n height\n );\n }\n gl.texSubImage2D(\n target,\n 0,\n xOffset,\n yOffset,\n width,\n height,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n arrayBufferView\n );\n } else {\n // Only valid for DOM-Element uploads\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);\n\n gl.texSubImage2D(\n target,\n 0,\n xOffset,\n yOffset,\n pixelFormat,\n PixelDatatype.toWebGLConstant(pixelDatatype, context),\n source\n );\n }\n }\n\n gl.bindTexture(target, null);\n};\n\n/**\n * @param {number} [xOffset=0] The offset in the x direction within the texture to copy into.\n * @param {number} [yOffset=0] The offset in the y direction within the texture to copy into.\n * @param {number} [framebufferXOffset=0] optional\n * @param {number} [framebufferYOffset=0] optional\n * @param {number} [width=width] optional\n * @param {number} [height=height] optional\n *\n * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\n * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.\n * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.\n * @exception {DeveloperError} Cannot call copyFrom with a compressed texture pixel format.\n * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.\n * @exception {DeveloperError} xOffset must be greater than or equal to zero.\n * @exception {DeveloperError} yOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.\n * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.\n * @exception {DeveloperError} xOffset + width must be less than or equal to width.\n * @exception {DeveloperError} yOffset + height must be less than or equal to height.\n */\nTexture.prototype.copyFromFramebuffer = function (\n xOffset,\n yOffset,\n framebufferXOffset,\n framebufferYOffset,\n width,\n height\n) {\n xOffset = defaultValue(xOffset, 0);\n yOffset = defaultValue(yOffset, 0);\n framebufferXOffset = defaultValue(framebufferXOffset, 0);\n framebufferYOffset = defaultValue(framebufferYOffset, 0);\n width = defaultValue(width, this._width);\n height = defaultValue(height, this._height);\n\n //>>includeStart('debug', pragmas.debug);\n if (PixelFormat.isDepthFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call copyFromFramebuffer when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\"\n );\n }\n if (this._pixelDatatype === PixelDatatype.FLOAT) {\n throw new DeveloperError(\n \"Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.\"\n );\n }\n if (this._pixelDatatype === PixelDatatype.HALF_FLOAT) {\n throw new DeveloperError(\n \"Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.\"\n );\n }\n if (PixelFormat.isCompressedFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call copyFrom with a compressed texture pixel format.\"\n );\n }\n\n Check.typeOf.number.greaterThanOrEquals(\"xOffset\", xOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\"yOffset\", yOffset, 0);\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferXOffset\",\n framebufferXOffset,\n 0\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"framebufferYOffset\",\n framebufferYOffset,\n 0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"xOffset + width\",\n xOffset + width,\n this._width\n );\n Check.typeOf.number.lessThanOrEquals(\n \"yOffset + height\",\n yOffset + height,\n this._height\n );\n //>>includeEnd('debug');\n\n const gl = this._context._gl;\n const target = this._textureTarget;\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.copyTexSubImage2D(\n target,\n 0,\n xOffset,\n yOffset,\n framebufferXOffset,\n framebufferYOffset,\n width,\n height\n );\n gl.bindTexture(target, null);\n this._initialized = true;\n};\n\n/**\n * @param {MipmapHint} [hint=MipmapHint.DONT_CARE] optional.\n *\n * @exception {DeveloperError} Cannot call generateMipmap when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\n * @exception {DeveloperError} Cannot call generateMipmap when the texture pixel format is a compressed format.\n * @exception {DeveloperError} hint is invalid.\n * @exception {DeveloperError} This texture's width must be a power of two to call generateMipmap() in a WebGL1 context.\n * @exception {DeveloperError} This texture's height must be a power of two to call generateMipmap() in a WebGL1 context.\n * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.\n */\nTexture.prototype.generateMipmap = function (hint) {\n hint = defaultValue(hint, MipmapHint.DONT_CARE);\n\n //>>includeStart('debug', pragmas.debug);\n if (PixelFormat.isDepthFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call generateMipmap when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.\"\n );\n }\n if (PixelFormat.isCompressedFormat(this._pixelFormat)) {\n throw new DeveloperError(\n \"Cannot call generateMipmap with a compressed pixel format.\"\n );\n }\n if (!this._context.webgl2) {\n if (this._width > 1 && !CesiumMath.isPowerOfTwo(this._width)) {\n throw new DeveloperError(\n \"width must be a power of two to call generateMipmap() in a WebGL1 context.\"\n );\n }\n if (this._height > 1 && !CesiumMath.isPowerOfTwo(this._height)) {\n throw new DeveloperError(\n \"height must be a power of two to call generateMipmap() in a WebGL1 context.\"\n );\n }\n }\n if (!MipmapHint.validate(hint)) {\n throw new DeveloperError(\"hint is invalid.\");\n }\n //>>includeEnd('debug');\n\n this._hasMipmap = true;\n\n const gl = this._context._gl;\n const target = this._textureTarget;\n\n gl.hint(gl.GENERATE_MIPMAP_HINT, hint);\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(target, this._texture);\n gl.generateMipmap(target);\n gl.bindTexture(target, null);\n};\n\nTexture.prototype.isDestroyed = function () {\n return false;\n};\n\nTexture.prototype.destroy = function () {\n this._context._gl.deleteTexture(this._texture);\n return destroyObject(this);\n};\nexport default Texture;\n", "import defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\n\n/**\n * @private\n */\nfunction TextureCache() {\n this._textures = {};\n this._numberOfTextures = 0;\n this._texturesToRelease = {};\n}\n\nObject.defineProperties(TextureCache.prototype, {\n numberOfTextures: {\n get: function () {\n return this._numberOfTextures;\n },\n },\n});\n\nTextureCache.prototype.getTexture = function (keyword) {\n const cachedTexture = this._textures[keyword];\n if (!defined(cachedTexture)) {\n return undefined;\n }\n\n // No longer want to release this if it was previously released.\n delete this._texturesToRelease[keyword];\n\n ++cachedTexture.count;\n return cachedTexture.texture;\n};\n\nTextureCache.prototype.addTexture = function (keyword, texture) {\n const cachedTexture = {\n texture: texture,\n count: 1,\n };\n\n texture.finalDestroy = texture.destroy;\n\n const that = this;\n texture.destroy = function () {\n if (--cachedTexture.count === 0) {\n that._texturesToRelease[keyword] = cachedTexture;\n }\n };\n\n this._textures[keyword] = cachedTexture;\n ++this._numberOfTextures;\n};\n\nTextureCache.prototype.destroyReleasedTextures = function () {\n const texturesToRelease = this._texturesToRelease;\n\n for (const keyword in texturesToRelease) {\n if (texturesToRelease.hasOwnProperty(keyword)) {\n const cachedTexture = texturesToRelease[keyword];\n delete this._textures[keyword];\n cachedTexture.texture.finalDestroy();\n --this._numberOfTextures;\n }\n }\n\n this._texturesToRelease = {};\n};\n\nTextureCache.prototype.isDestroyed = function () {\n return false;\n};\n\nTextureCache.prototype.destroy = function () {\n const textures = this._textures;\n for (const keyword in textures) {\n if (textures.hasOwnProperty(keyword)) {\n textures[keyword].texture.finalDestroy();\n }\n }\n return destroyObject(this);\n};\nexport default TextureCache;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defined from \"./defined.js\";\n\n/**\n * A fixed-point encoding of a {@link Cartesian3} with 64-bit floating-point components, as two {@link Cartesian3}\n * values that, when converted to 32-bit floating-point and added, approximate the original input.\n *

\n * This is used to encode positions in vertex buffers for rendering without jittering artifacts\n * as described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @alias EncodedCartesian3\n * @constructor\n *\n * @private\n */\nfunction EncodedCartesian3() {\n /**\n * The high bits for each component. Bits 0 to 22 store the whole value. Bits 23 to 31 are not used.\n *\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.high = Cartesian3.clone(Cartesian3.ZERO);\n\n /**\n * The low bits for each component. Bits 7 to 22 store the whole value, and bits 0 to 6 store the fraction. Bits 23 to 31 are not used.\n *\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.low = Cartesian3.clone(Cartesian3.ZERO);\n}\n\n/**\n * Encodes a 64-bit floating-point value as two floating-point values that, when converted to\n * 32-bit floating-point and added, approximate the original input. The returned object\n * has high and low properties for the high and low bits, respectively.\n *

\n * The fixed-point encoding follows {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @param {number} value The floating-point value to encode.\n * @param {object} [result] The object onto which to store the result.\n * @returns {object} The modified result parameter or a new instance if one was not provided.\n *\n * @example\n * const value = 1234567.1234567;\n * const splitValue = Cesium.EncodedCartesian3.encode(value);\n */\nEncodedCartesian3.encode = function (value, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = {\n high: 0.0,\n low: 0.0,\n };\n }\n\n let doubleHigh;\n if (value >= 0.0) {\n doubleHigh = Math.floor(value / 65536.0) * 65536.0;\n result.high = doubleHigh;\n result.low = value - doubleHigh;\n } else {\n doubleHigh = Math.floor(-value / 65536.0) * 65536.0;\n result.high = -doubleHigh;\n result.low = value + doubleHigh;\n }\n\n return result;\n};\n\nconst scratchEncode = {\n high: 0.0,\n low: 0.0,\n};\n\n/**\n * Encodes a {@link Cartesian3} with 64-bit floating-point components as two {@link Cartesian3}\n * values that, when converted to 32-bit floating-point and added, approximate the original input.\n *

\n * The fixed-point encoding follows {@link https://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.\n *

\n *\n * @param {Cartesian3} cartesian The cartesian to encode.\n * @param {EncodedCartesian3} [result] The object onto which to store the result.\n * @returns {EncodedCartesian3} The modified result parameter or a new EncodedCartesian3 instance if one was not provided.\n *\n * @example\n * const cart = new Cesium.Cartesian3(-10000000.0, 0.0, 10000000.0);\n * const encoded = Cesium.EncodedCartesian3.fromCartesian(cart);\n */\nEncodedCartesian3.fromCartesian = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new EncodedCartesian3();\n }\n\n const high = result.high;\n const low = result.low;\n\n EncodedCartesian3.encode(cartesian.x, scratchEncode);\n high.x = scratchEncode.high;\n low.x = scratchEncode.low;\n\n EncodedCartesian3.encode(cartesian.y, scratchEncode);\n high.y = scratchEncode.high;\n low.y = scratchEncode.low;\n\n EncodedCartesian3.encode(cartesian.z, scratchEncode);\n high.z = scratchEncode.high;\n low.z = scratchEncode.low;\n\n return result;\n};\n\nconst encodedP = new EncodedCartesian3();\n\n/**\n * Encodes the provided cartesian, and writes it to an array with high\n * components followed by low components, i.e. [high.x, high.y, high.z, low.x, low.y, low.z].\n *

\n * This is used to create interleaved high-precision position vertex attributes.\n *

\n *\n * @param {Cartesian3} cartesian The cartesian to encode.\n * @param {number[]} cartesianArray The array to write to.\n * @param {number} index The index into the array to start writing. Six elements will be written.\n *\n * @exception {DeveloperError} index must be a number greater than or equal to 0.\n *\n * @example\n * const positions = [\n * new Cesium.Cartesian3(),\n * // ...\n * ];\n * const encodedPositions = new Float32Array(2 * 3 * positions.length);\n * let j = 0;\n * for (let i = 0; i < positions.length; ++i) {\n * Cesium.EncodedCartesian3.writeElement(positions[i], encodedPositions, j);\n * j += 6;\n * }\n */\nEncodedCartesian3.writeElements = function (cartesian, cartesianArray, index) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesianArray\", cartesianArray);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.number.greaterThanOrEquals(\"index\", index, 0);\n //>>includeEnd('debug');\n\n EncodedCartesian3.fromCartesian(cartesian, encodedP);\n const high = encodedP.high;\n const low = encodedP.low;\n\n cartesianArray[index] = high.x;\n cartesianArray[index + 1] = high.y;\n cartesianArray[index + 2] = high.z;\n cartesianArray[index + 3] = low.x;\n cartesianArray[index + 4] = low.y;\n cartesianArray[index + 5] = low.z;\n};\nexport default EncodedCartesian3;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Check from \"./Check.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix4 from \"./Matrix4.js\";\n\n/**\n * A plane in Hessian Normal Form defined by\n *
\n * ax + by + cz + d = 0\n * 
\n * where (a, b, c) is the plane's normal, d is the signed\n * distance to the plane, and (x, y, z) is any point on\n * the plane.\n *\n * @alias Plane\n * @constructor\n *\n * @param {Cartesian3} normal The plane's normal (normalized).\n * @param {number} distance The shortest distance from the origin to the plane. The sign of\n * distance determines which side of the plane the origin\n * is on. If distance is positive, the origin is in the half-space\n * in the direction of the normal; if negative, the origin is in the half-space\n * opposite to the normal; if zero, the plane passes through the origin.\n *\n * @example\n * // The plane x=0\n * const plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);\n *\n * @exception {DeveloperError} Normal must be normalized\n */\nfunction Plane(normal, distance) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"normal\", normal);\n if (\n !CesiumMath.equalsEpsilon(\n Cartesian3.magnitude(normal),\n 1.0,\n CesiumMath.EPSILON6\n )\n ) {\n throw new DeveloperError(\"normal must be normalized.\");\n }\n Check.typeOf.number(\"distance\", distance);\n //>>includeEnd('debug');\n\n /**\n * The plane's normal.\n *\n * @type {Cartesian3}\n */\n this.normal = Cartesian3.clone(normal);\n\n /**\n * The shortest distance from the origin to the plane. The sign of\n * distance determines which side of the plane the origin\n * is on. If distance is positive, the origin is in the half-space\n * in the direction of the normal; if negative, the origin is in the half-space\n * opposite to the normal; if zero, the plane passes through the origin.\n *\n * @type {number}\n */\n this.distance = distance;\n}\n\n/**\n * Creates a plane from a normal and a point on the plane.\n *\n * @param {Cartesian3} point The point on the plane.\n * @param {Cartesian3} normal The plane's normal (normalized).\n * @param {Plane} [result] The object onto which to store the result.\n * @returns {Plane} A new plane instance or the modified result parameter.\n *\n * @example\n * const point = Cesium.Cartesian3.fromDegrees(-72.0, 40.0);\n * const normal = ellipsoid.geodeticSurfaceNormal(point);\n * const tangentPlane = Cesium.Plane.fromPointNormal(point, normal);\n *\n * @exception {DeveloperError} Normal must be normalized\n */\nPlane.fromPointNormal = function (point, normal, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"point\", point);\n Check.typeOf.object(\"normal\", normal);\n if (\n !CesiumMath.equalsEpsilon(\n Cartesian3.magnitude(normal),\n 1.0,\n CesiumMath.EPSILON6\n )\n ) {\n throw new DeveloperError(\"normal must be normalized.\");\n }\n //>>includeEnd('debug');\n\n const distance = -Cartesian3.dot(normal, point);\n\n if (!defined(result)) {\n return new Plane(normal, distance);\n }\n\n Cartesian3.clone(normal, result.normal);\n result.distance = distance;\n return result;\n};\n\nconst scratchNormal = new Cartesian3();\n/**\n * Creates a plane from the general equation\n *\n * @param {Cartesian4} coefficients The plane's normal (normalized).\n * @param {Plane} [result] The object onto which to store the result.\n * @returns {Plane} A new plane instance or the modified result parameter.\n *\n * @exception {DeveloperError} Normal must be normalized\n */\nPlane.fromCartesian4 = function (coefficients, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"coefficients\", coefficients);\n //>>includeEnd('debug');\n\n const normal = Cartesian3.fromCartesian4(coefficients, scratchNormal);\n const distance = coefficients.w;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !CesiumMath.equalsEpsilon(\n Cartesian3.magnitude(normal),\n 1.0,\n CesiumMath.EPSILON6\n )\n ) {\n throw new DeveloperError(\"normal must be normalized.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Plane(normal, distance);\n }\n Cartesian3.clone(normal, result.normal);\n result.distance = distance;\n return result;\n};\n\n/**\n * Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point\n * is on. If the distance is positive, the point is in the half-space\n * in the direction of the normal; if negative, the point is in the half-space\n * opposite to the normal; if zero, the plane passes through the point.\n *\n * @param {Plane} plane The plane.\n * @param {Cartesian3} point The point.\n * @returns {number} The signed shortest distance of the point to the plane.\n */\nPlane.getPointDistance = function (plane, point) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"plane\", plane);\n Check.typeOf.object(\"point\", point);\n //>>includeEnd('debug');\n\n return Cartesian3.dot(plane.normal, point) + plane.distance;\n};\n\nconst scratchCartesian = new Cartesian3();\n/**\n * Projects a point onto the plane.\n * @param {Plane} plane The plane to project the point onto\n * @param {Cartesian3} point The point to project onto the plane\n * @param {Cartesian3} [result] The result point. If undefined, a new Cartesian3 will be created.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.\n */\nPlane.projectPointOntoPlane = function (plane, point, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"plane\", plane);\n Check.typeOf.object(\"point\", point);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = Plane.getPointDistance(plane, point);\n const scaledNormal = Cartesian3.multiplyByScalar(\n plane.normal,\n pointDistance,\n scratchCartesian\n );\n\n return Cartesian3.subtract(point, scaledNormal, result);\n};\n\nconst scratchInverseTranspose = new Matrix4();\nconst scratchPlaneCartesian4 = new Cartesian4();\nconst scratchTransformNormal = new Cartesian3();\n/**\n * Transforms the plane by the given transformation matrix.\n *\n * @param {Plane} plane The plane.\n * @param {Matrix4} transform The transformation matrix.\n * @param {Plane} [result] The object into which to store the result.\n * @returns {Plane} The plane transformed by the given transformation matrix.\n */\nPlane.transform = function (plane, transform, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"plane\", plane);\n Check.typeOf.object(\"transform\", transform);\n //>>includeEnd('debug');\n\n const normal = plane.normal;\n const distance = plane.distance;\n const inverseTranspose = Matrix4.inverseTranspose(\n transform,\n scratchInverseTranspose\n );\n let planeAsCartesian4 = Cartesian4.fromElements(\n normal.x,\n normal.y,\n normal.z,\n distance,\n scratchPlaneCartesian4\n );\n planeAsCartesian4 = Matrix4.multiplyByVector(\n inverseTranspose,\n planeAsCartesian4,\n planeAsCartesian4\n );\n\n // Convert the transformed plane to Hessian Normal Form\n const transformedNormal = Cartesian3.fromCartesian4(\n planeAsCartesian4,\n scratchTransformNormal\n );\n\n planeAsCartesian4 = Cartesian4.divideByScalar(\n planeAsCartesian4,\n Cartesian3.magnitude(transformedNormal),\n planeAsCartesian4\n );\n\n return Plane.fromCartesian4(planeAsCartesian4, result);\n};\n\n/**\n * Duplicates a Plane instance.\n *\n * @param {Plane} plane The plane to duplicate.\n * @param {Plane} [result] The object onto which to store the result.\n * @returns {Plane} The modified result parameter or a new Plane instance if one was not provided.\n */\nPlane.clone = function (plane, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"plane\", plane);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Plane(plane.normal, plane.distance);\n }\n\n Cartesian3.clone(plane.normal, result.normal);\n result.distance = plane.distance;\n\n return result;\n};\n\n/**\n * Compares the provided Planes by normal and distance and returns\n * true if they are equal, false otherwise.\n *\n * @param {Plane} left The first plane.\n * @param {Plane} right The second plane.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPlane.equals = function (left, right) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n return (\n left.distance === right.distance &&\n Cartesian3.equals(left.normal, right.normal)\n );\n};\n\n/**\n * A constant initialized to the XY plane passing through the origin, with normal in positive Z.\n *\n * @type {Plane}\n * @constant\n */\nPlane.ORIGIN_XY_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_Z, 0.0));\n\n/**\n * A constant initialized to the YZ plane passing through the origin, with normal in positive X.\n *\n * @type {Plane}\n * @constant\n */\nPlane.ORIGIN_YZ_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_X, 0.0));\n\n/**\n * A constant initialized to the ZX plane passing through the origin, with normal in positive Y.\n *\n * @type {Plane}\n * @constant\n */\nPlane.ORIGIN_ZX_PLANE = Object.freeze(new Plane(Cartesian3.UNIT_Y, 0.0));\nexport default Plane;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Intersect from \"./Intersect.js\";\nimport Plane from \"./Plane.js\";\n\n/**\n * The culling volume defined by planes.\n *\n * @alias CullingVolume\n * @constructor\n *\n * @param {Cartesian4[]} [planes] An array of clipping planes.\n */\nfunction CullingVolume(planes) {\n /**\n * Each plane is represented by a Cartesian4 object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin.\n * @type {Cartesian4[]}\n * @default []\n */\n this.planes = defaultValue(planes, []);\n}\n\nconst faces = [new Cartesian3(), new Cartesian3(), new Cartesian3()];\nCartesian3.clone(Cartesian3.UNIT_X, faces[0]);\nCartesian3.clone(Cartesian3.UNIT_Y, faces[1]);\nCartesian3.clone(Cartesian3.UNIT_Z, faces[2]);\n\nconst scratchPlaneCenter = new Cartesian3();\nconst scratchPlaneNormal = new Cartesian3();\nconst scratchPlane = new Plane(new Cartesian3(1.0, 0.0, 0.0), 0.0);\n\n/**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n *\n * @param {BoundingSphere} boundingSphere The bounding sphere used to create the culling volume.\n * @param {CullingVolume} [result] The object onto which to store the result.\n * @returns {CullingVolume} The culling volume created from the bounding sphere.\n */\nCullingVolume.fromBoundingSphere = function (boundingSphere, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(boundingSphere)) {\n throw new DeveloperError(\"boundingSphere is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new CullingVolume();\n }\n\n const length = faces.length;\n const planes = result.planes;\n planes.length = 2 * length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (let i = 0; i < length; ++i) {\n const faceNormal = faces[i];\n\n let plane0 = planes[planeIndex];\n let plane1 = planes[planeIndex + 1];\n\n if (!defined(plane0)) {\n plane0 = planes[planeIndex] = new Cartesian4();\n }\n if (!defined(plane1)) {\n plane1 = planes[planeIndex + 1] = new Cartesian4();\n }\n\n Cartesian3.multiplyByScalar(faceNormal, -radius, scratchPlaneCenter);\n Cartesian3.add(center, scratchPlaneCenter, scratchPlaneCenter);\n\n plane0.x = faceNormal.x;\n plane0.y = faceNormal.y;\n plane0.z = faceNormal.z;\n plane0.w = -Cartesian3.dot(faceNormal, scratchPlaneCenter);\n\n Cartesian3.multiplyByScalar(faceNormal, radius, scratchPlaneCenter);\n Cartesian3.add(center, scratchPlaneCenter, scratchPlaneCenter);\n\n plane1.x = -faceNormal.x;\n plane1.y = -faceNormal.y;\n plane1.z = -faceNormal.z;\n plane1.w = -Cartesian3.dot(\n Cartesian3.negate(faceNormal, scratchPlaneNormal),\n scratchPlaneCenter\n );\n\n planeIndex += 2;\n }\n\n return result;\n};\n\n/**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param {object} boundingVolume The bounding volume whose intersection with the culling volume is to be tested.\n * @returns {Intersect} Intersect.OUTSIDE, Intersect.INTERSECTING, or Intersect.INSIDE.\n */\nCullingVolume.prototype.computeVisibility = function (boundingVolume) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(boundingVolume)) {\n throw new DeveloperError(\"boundingVolume is required.\");\n }\n //>>includeEnd('debug');\n\n const planes = this.planes;\n let intersecting = false;\n for (let k = 0, len = planes.length; k < len; ++k) {\n const result = boundingVolume.intersectPlane(\n Plane.fromCartesian4(planes[k], scratchPlane)\n );\n if (result === Intersect.OUTSIDE) {\n return Intersect.OUTSIDE;\n } else if (result === Intersect.INTERSECTING) {\n intersecting = true;\n }\n }\n\n return intersecting ? Intersect.INTERSECTING : Intersect.INSIDE;\n};\n\n/**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param {object} boundingVolume The bounding volume whose intersection with the culling volume is to be tested.\n * @param {number} parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n * @returns {number} A plane mask as described above (which can be applied to this boundingVolume's children).\n *\n * @private\n */\nCullingVolume.prototype.computeVisibilityWithPlaneMask = function (\n boundingVolume,\n parentPlaneMask\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(boundingVolume)) {\n throw new DeveloperError(\"boundingVolume is required.\");\n }\n if (!defined(parentPlaneMask)) {\n throw new DeveloperError(\"parentPlaneMask is required.\");\n }\n //>>includeEnd('debug');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0, len = planes.length; k < len; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const result = boundingVolume.intersectPlane(\n Plane.fromCartesian4(planes[k], scratchPlane)\n );\n if (result === Intersect.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === Intersect.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n};\n\n/**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n *\n * @type {number}\n * @private\n */\nCullingVolume.MASK_OUTSIDE = 0xffffffff;\n\n/**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n *\n * @type {number}\n * @private\n */\nCullingVolume.MASK_INSIDE = 0x00000000;\n\n/**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n *\n * @type {number}\n * @private\n */\nCullingVolume.MASK_INDETERMINATE = 0x7fffffff;\nexport default CullingVolume;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport CullingVolume from \"./CullingVolume.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix4 from \"./Matrix4.js\";\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias OrthographicOffCenterFrustum\n * @constructor\n *\n * @param {object} [options] An object with the following properties:\n * @param {number} [options.left] The left clipping plane distance.\n * @param {number} [options.right] The right clipping plane distance.\n * @param {number} [options.top] The top clipping plane distance.\n * @param {number} [options.bottom] The bottom clipping plane distance.\n * @param {number} [options.near=1.0] The near clipping plane distance.\n * @param {number} [options.far=500000000.0] The far clipping plane distance.\n *\n * @example\n * const maxRadii = ellipsoid.maximumRadius;\n *\n * const frustum = new Cesium.OrthographicOffCenterFrustum();\n * frustum.right = maxRadii * Cesium.Math.PI;\n * frustum.left = -c.frustum.right;\n * frustum.top = c.frustum.right * (canvas.clientHeight / canvas.clientWidth);\n * frustum.bottom = -c.frustum.top;\n * frustum.near = 0.01 * maxRadii;\n * frustum.far = 50.0 * maxRadii;\n */\nfunction OrthographicOffCenterFrustum(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The left clipping plane.\n * @type {number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * The right clipping plane.\n * @type {number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * The top clipping plane.\n * @type {number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * The bottom clipping plane.\n * @type {number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {number}\n * @default 1.0\n */\n this.near = defaultValue(options.near, 1.0);\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {number}\n * @default 500000000.0;\n */\n this.far = defaultValue(options.far, 500000000.0);\n this._far = this.far;\n\n this._cullingVolume = new CullingVolume();\n this._orthographicMatrix = new Matrix4();\n}\n\nfunction update(frustum) {\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(frustum.right) ||\n !defined(frustum.left) ||\n !defined(frustum.top) ||\n !defined(frustum.bottom) ||\n !defined(frustum.near) ||\n !defined(frustum.far)\n ) {\n throw new DeveloperError(\n \"right, left, top, bottom, near, or far parameters are not set.\"\n );\n }\n //>>includeEnd('debug');\n\n if (\n frustum.top !== frustum._top ||\n frustum.bottom !== frustum._bottom ||\n frustum.left !== frustum._left ||\n frustum.right !== frustum._right ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (frustum.left > frustum.right) {\n throw new DeveloperError(\"right must be greater than left.\");\n }\n if (frustum.bottom > frustum.top) {\n throw new DeveloperError(\"top must be greater than bottom.\");\n }\n if (frustum.near <= 0 || frustum.near > frustum.far) {\n throw new DeveloperError(\n \"near must be greater than zero and less than far.\"\n );\n }\n //>>includeEnd('debug');\n\n frustum._left = frustum.left;\n frustum._right = frustum.right;\n frustum._top = frustum.top;\n frustum._bottom = frustum.bottom;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._orthographicMatrix = Matrix4.computeOrthographicOffCenter(\n frustum.left,\n frustum.right,\n frustum.bottom,\n frustum.top,\n frustum.near,\n frustum.far,\n frustum._orthographicMatrix\n );\n }\n}\n\nObject.defineProperties(OrthographicOffCenterFrustum.prototype, {\n /**\n * Gets the orthographic projection matrix computed from the view frustum.\n * @memberof OrthographicOffCenterFrustum.prototype\n * @type {Matrix4}\n * @readonly\n */\n projectionMatrix: {\n get: function () {\n update(this);\n return this._orthographicMatrix;\n },\n },\n});\n\nconst getPlanesRight = new Cartesian3();\nconst getPlanesNearCenter = new Cartesian3();\nconst getPlanesPoint = new Cartesian3();\nconst negateScratch = new Cartesian3();\n\n/**\n * Creates a culling volume for this frustum.\n *\n * @param {Cartesian3} position The eye position.\n * @param {Cartesian3} direction The view direction.\n * @param {Cartesian3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\nOrthographicOffCenterFrustum.prototype.computeCullingVolume = function (\n position,\n direction,\n up\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(position)) {\n throw new DeveloperError(\"position is required.\");\n }\n if (!defined(direction)) {\n throw new DeveloperError(\"direction is required.\");\n }\n if (!defined(up)) {\n throw new DeveloperError(\"up is required.\");\n }\n //>>includeEnd('debug');\n\n const planes = this._cullingVolume.planes;\n const t = this.top;\n const b = this.bottom;\n const r = this.right;\n const l = this.left;\n const n = this.near;\n const f = this.far;\n\n const right = Cartesian3.cross(direction, up, getPlanesRight);\n Cartesian3.normalize(right, right);\n const nearCenter = getPlanesNearCenter;\n Cartesian3.multiplyByScalar(direction, n, nearCenter);\n Cartesian3.add(position, nearCenter, nearCenter);\n\n const point = getPlanesPoint;\n\n // Left plane\n Cartesian3.multiplyByScalar(right, l, point);\n Cartesian3.add(nearCenter, point, point);\n\n let plane = planes[0];\n if (!defined(plane)) {\n plane = planes[0] = new Cartesian4();\n }\n plane.x = right.x;\n plane.y = right.y;\n plane.z = right.z;\n plane.w = -Cartesian3.dot(right, point);\n\n // Right plane\n Cartesian3.multiplyByScalar(right, r, point);\n Cartesian3.add(nearCenter, point, point);\n\n plane = planes[1];\n if (!defined(plane)) {\n plane = planes[1] = new Cartesian4();\n }\n plane.x = -right.x;\n plane.y = -right.y;\n plane.z = -right.z;\n plane.w = -Cartesian3.dot(Cartesian3.negate(right, negateScratch), point);\n\n // Bottom plane\n Cartesian3.multiplyByScalar(up, b, point);\n Cartesian3.add(nearCenter, point, point);\n\n plane = planes[2];\n if (!defined(plane)) {\n plane = planes[2] = new Cartesian4();\n }\n plane.x = up.x;\n plane.y = up.y;\n plane.z = up.z;\n plane.w = -Cartesian3.dot(up, point);\n\n // Top plane\n Cartesian3.multiplyByScalar(up, t, point);\n Cartesian3.add(nearCenter, point, point);\n\n plane = planes[3];\n if (!defined(plane)) {\n plane = planes[3] = new Cartesian4();\n }\n plane.x = -up.x;\n plane.y = -up.y;\n plane.z = -up.z;\n plane.w = -Cartesian3.dot(Cartesian3.negate(up, negateScratch), point);\n\n // Near plane\n plane = planes[4];\n if (!defined(plane)) {\n plane = planes[4] = new Cartesian4();\n }\n plane.x = direction.x;\n plane.y = direction.y;\n plane.z = direction.z;\n plane.w = -Cartesian3.dot(direction, nearCenter);\n\n // Far plane\n Cartesian3.multiplyByScalar(direction, f, point);\n Cartesian3.add(position, point, point);\n\n plane = planes[5];\n if (!defined(plane)) {\n plane = planes[5] = new Cartesian4();\n }\n plane.x = -direction.x;\n plane.y = -direction.y;\n plane.z = -direction.z;\n plane.w = -Cartesian3.dot(Cartesian3.negate(direction, negateScratch), point);\n\n return this._cullingVolume;\n};\n\n/**\n * Returns the pixel's width and height in meters.\n *\n * @param {number} drawingBufferWidth The width of the drawing buffer.\n * @param {number} drawingBufferHeight The height of the drawing buffer.\n * @param {number} distance The distance to the near plane in meters.\n * @param {number} pixelRatio The scaling factor from pixel space to coordinate space.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n * @exception {DeveloperError} pixelRatio must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2());\n */\nOrthographicOffCenterFrustum.prototype.getPixelDimensions = function (\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n pixelRatio,\n result\n) {\n update(this);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(drawingBufferWidth) || !defined(drawingBufferHeight)) {\n throw new DeveloperError(\n \"Both drawingBufferWidth and drawingBufferHeight are required.\"\n );\n }\n if (drawingBufferWidth <= 0) {\n throw new DeveloperError(\"drawingBufferWidth must be greater than zero.\");\n }\n if (drawingBufferHeight <= 0) {\n throw new DeveloperError(\"drawingBufferHeight must be greater than zero.\");\n }\n if (!defined(distance)) {\n throw new DeveloperError(\"distance is required.\");\n }\n if (!defined(pixelRatio)) {\n throw new DeveloperError(\"pixelRatio is required.\");\n }\n if (pixelRatio <= 0) {\n throw new DeveloperError(\"pixelRatio must be greater than zero.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"A result object is required.\");\n }\n //>>includeEnd('debug');\n\n const frustumWidth = this.right - this.left;\n const frustumHeight = this.top - this.bottom;\n const pixelWidth = (pixelRatio * frustumWidth) / drawingBufferWidth;\n const pixelHeight = (pixelRatio * frustumHeight) / drawingBufferHeight;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n};\n\n/**\n * Returns a duplicate of a OrthographicOffCenterFrustum instance.\n *\n * @param {OrthographicOffCenterFrustum} [result] The object onto which to store the result.\n * @returns {OrthographicOffCenterFrustum} The modified result parameter or a new OrthographicOffCenterFrustum instance if one was not provided.\n */\nOrthographicOffCenterFrustum.prototype.clone = function (result) {\n if (!defined(result)) {\n result = new OrthographicOffCenterFrustum();\n }\n\n result.left = this.left;\n result.right = this.right;\n result.top = this.top;\n result.bottom = this.bottom;\n result.near = this.near;\n result.far = this.far;\n\n // force update of clone to compute matrices\n result._left = undefined;\n result._right = undefined;\n result._top = undefined;\n result._bottom = undefined;\n result._near = undefined;\n result._far = undefined;\n\n return result;\n};\n\n/**\n * Compares the provided OrthographicOffCenterFrustum componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {OrthographicOffCenterFrustum} [other] The right hand side OrthographicOffCenterFrustum.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nOrthographicOffCenterFrustum.prototype.equals = function (other) {\n return (\n defined(other) &&\n other instanceof OrthographicOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n};\n\n/**\n * Compares the provided OrthographicOffCenterFrustum componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {OrthographicOffCenterFrustum} other The right hand side OrthographicOffCenterFrustum.\n * @param {number} relativeEpsilon The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if this and other are within the provided epsilon, false otherwise.\n */\nOrthographicOffCenterFrustum.prototype.equalsEpsilon = function (\n other,\n relativeEpsilon,\n absoluteEpsilon\n) {\n return (\n other === this ||\n (defined(other) &&\n other instanceof OrthographicOffCenterFrustum &&\n CesiumMath.equalsEpsilon(\n this.right,\n other.right,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.left,\n other.left,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.top,\n other.top,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.bottom,\n other.bottom,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.near,\n other.near,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.far,\n other.far,\n relativeEpsilon,\n absoluteEpsilon\n ))\n );\n};\nexport default OrthographicOffCenterFrustum;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport OrthographicOffCenterFrustum from \"./OrthographicOffCenterFrustum.js\";\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Cartesian4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias OrthographicFrustum\n * @constructor\n *\n * @param {object} [options] An object with the following properties:\n * @param {number} [options.width] The width of the frustum in meters.\n * @param {number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {number} [options.near=1.0] The distance of the near plane.\n * @param {number} [options.far=500000000.0] The distance of the far plane.\n *\n * @example\n * const maxRadii = ellipsoid.maximumRadius;\n *\n * const frustum = new Cesium.OrthographicFrustum();\n * frustum.near = 0.01 * maxRadii;\n * frustum.far = 50.0 * maxRadii;\n */\nfunction OrthographicFrustum(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._offCenterFrustum = new OrthographicOffCenterFrustum();\n\n /**\n * The horizontal width of the frustum in meters.\n * @type {number}\n * @default undefined\n */\n this.width = options.width;\n this._width = undefined;\n\n /**\n * The aspect ratio of the frustum's width to it's height.\n * @type {number}\n * @default undefined\n */\n this.aspectRatio = options.aspectRatio;\n this._aspectRatio = undefined;\n\n /**\n * The distance of the near plane.\n * @type {number}\n * @default 1.0\n */\n this.near = defaultValue(options.near, 1.0);\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {number}\n * @default 500000000.0;\n */\n this.far = defaultValue(options.far, 500000000.0);\n this._far = this.far;\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nOrthographicFrustum.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {OrthographicFrustum} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nOrthographicFrustum.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.width;\n array[startingIndex++] = value.aspectRatio;\n array[startingIndex++] = value.near;\n array[startingIndex] = value.far;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {OrthographicFrustum} [result] The object into which to store the result.\n * @returns {OrthographicFrustum} The modified result parameter or a new OrthographicFrustum instance if one was not provided.\n */\nOrthographicFrustum.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new OrthographicFrustum();\n }\n\n result.width = array[startingIndex++];\n result.aspectRatio = array[startingIndex++];\n result.near = array[startingIndex++];\n result.far = array[startingIndex];\n\n return result;\n};\n\nfunction update(frustum) {\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(frustum.width) ||\n !defined(frustum.aspectRatio) ||\n !defined(frustum.near) ||\n !defined(frustum.far)\n ) {\n throw new DeveloperError(\n \"width, aspectRatio, near, or far parameters are not set.\"\n );\n }\n //>>includeEnd('debug');\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.width !== frustum._width ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (frustum.aspectRatio < 0) {\n throw new DeveloperError(\"aspectRatio must be positive.\");\n }\n if (frustum.near < 0 || frustum.near > frustum.far) {\n throw new DeveloperError(\n \"near must be greater than zero and less than far.\"\n );\n }\n //>>includeEnd('debug');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._width = frustum.width;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n\n const ratio = 1.0 / frustum.aspectRatio;\n f.right = frustum.width * 0.5;\n f.left = -f.right;\n f.top = ratio * f.right;\n f.bottom = -f.top;\n f.near = frustum.near;\n f.far = frustum.far;\n }\n}\n\nObject.defineProperties(OrthographicFrustum.prototype, {\n /**\n * Gets the orthographic projection matrix computed from the view frustum.\n * @memberof OrthographicFrustum.prototype\n * @type {Matrix4}\n * @readonly\n */\n projectionMatrix: {\n get: function () {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n },\n },\n /**\n * Gets the orthographic projection matrix computed from the view frustum.\n * @memberof OrthographicFrustum.prototype\n * @type {OrthographicOffCenterFrustum}\n * @readonly\n * @private\n */\n offCenterFrustum: {\n get: function () {\n update(this);\n return this._offCenterFrustum;\n },\n },\n});\n\n/**\n * Creates a culling volume for this frustum.\n *\n * @param {Cartesian3} position The eye position.\n * @param {Cartesian3} direction The view direction.\n * @param {Cartesian3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\nOrthographicFrustum.prototype.computeCullingVolume = function (\n position,\n direction,\n up\n) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n};\n\n/**\n * Returns the pixel's width and height in meters.\n *\n * @param {number} drawingBufferWidth The width of the drawing buffer.\n * @param {number} drawingBufferHeight The height of the drawing buffer.\n * @param {number} distance The distance to the near plane in meters.\n * @param {number} pixelRatio The scaling factor from pixel space to coordinate space.\n * @param {Cartesian2} result The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new instance of {@link Cartesian2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n * @exception {DeveloperError} pixelRatio must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 0.0, scene.pixelRatio, new Cesium.Cartesian2());\n */\nOrthographicFrustum.prototype.getPixelDimensions = function (\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n pixelRatio,\n result\n) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n pixelRatio,\n result\n );\n};\n\n/**\n * Returns a duplicate of a OrthographicFrustum instance.\n *\n * @param {OrthographicFrustum} [result] The object onto which to store the result.\n * @returns {OrthographicFrustum} The modified result parameter or a new OrthographicFrustum instance if one was not provided.\n */\nOrthographicFrustum.prototype.clone = function (result) {\n if (!defined(result)) {\n result = new OrthographicFrustum();\n }\n\n result.aspectRatio = this.aspectRatio;\n result.width = this.width;\n result.near = this.near;\n result.far = this.far;\n\n // force update of clone to compute matrices\n result._aspectRatio = undefined;\n result._width = undefined;\n result._near = undefined;\n result._far = undefined;\n\n this._offCenterFrustum.clone(result._offCenterFrustum);\n\n return result;\n};\n\n/**\n * Compares the provided OrthographicFrustum componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {OrthographicFrustum} [other] The right hand side OrthographicFrustum.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nOrthographicFrustum.prototype.equals = function (other) {\n if (!defined(other) || !(other instanceof OrthographicFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.width === other.width &&\n this.aspectRatio === other.aspectRatio &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n};\n\n/**\n * Compares the provided OrthographicFrustum componentwise and returns\n * true if they pass an absolute or relative tolerance test,\n * false otherwise.\n *\n * @param {OrthographicFrustum} other The right hand side OrthographicFrustum.\n * @param {number} relativeEpsilon The relative epsilon tolerance to use for equality testing.\n * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.\n * @returns {boolean} true if this and other are within the provided epsilon, false otherwise.\n */\nOrthographicFrustum.prototype.equalsEpsilon = function (\n other,\n relativeEpsilon,\n absoluteEpsilon\n) {\n if (!defined(other) || !(other instanceof OrthographicFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n CesiumMath.equalsEpsilon(\n this.width,\n other.width,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n CesiumMath.equalsEpsilon(\n this.aspectRatio,\n other.aspectRatio,\n relativeEpsilon,\n absoluteEpsilon\n ) &&\n this._offCenterFrustum.equalsEpsilon(\n other._offCenterFrustum,\n relativeEpsilon,\n absoluteEpsilon\n )\n );\n};\nexport default OrthographicFrustum;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport TimeConstants from \"./TimeConstants.js\";\nimport TimeStandard from \"./TimeStandard.js\";\n\n/**\n * Contains functions for finding the Cartesian coordinates of the sun and the moon in the\n * Earth-centered inertial frame.\n *\n * @namespace Simon1994PlanetaryPositions\n */\nconst Simon1994PlanetaryPositions = {};\n\nfunction computeTdbMinusTtSpice(daysSinceJ2000InTerrestrialTime) {\n /* STK Comments ------------------------------------------------------\n * This function uses constants designed to be consistent with\n * the SPICE Toolkit from JPL version N0051 (unitim.c)\n * M0 = 6.239996\n * M0Dot = 1.99096871e-7 rad/s = 0.01720197 rad/d\n * EARTH_ECC = 1.671e-2\n * TDB_AMPL = 1.657e-3 secs\n *--------------------------------------------------------------------*/\n\n //* Values taken as specified in STK Comments except: 0.01720197 rad/day = 1.99096871e-7 rad/sec\n //* Here we use the more precise value taken from the SPICE value 1.99096871e-7 rad/sec converted to rad/day\n //* All other constants are consistent with the SPICE implementation of the TDB conversion\n //* except where we treat the independent time parameter to be in TT instead of TDB.\n //* This is an approximation made to facilitate performance due to the higher prevalance of\n //* the TT2TDB conversion over TDB2TT in order to avoid having to iterate when converting to TDB for the JPL ephemeris.\n //* Days are used instead of seconds to provide a slight improvement in numerical precision.\n\n //* For more information see:\n //* http://www.cv.nrao.edu/~rfisher/Ephemerides/times.html#TDB\n //* ftp://ssd.jpl.nasa.gov/pub/eph/planets/ioms/ExplSupplChap8.pdf\n\n const g = 6.239996 + 0.0172019696544 * daysSinceJ2000InTerrestrialTime;\n return 1.657e-3 * Math.sin(g + 1.671e-2 * Math.sin(g));\n}\n\nconst TdtMinusTai = 32.184;\nconst J2000d = 2451545;\nfunction taiToTdb(date, result) {\n //Converts TAI to TT\n result = JulianDate.addSeconds(date, TdtMinusTai, result);\n\n //Converts TT to TDB\n const days = JulianDate.totalDays(result) - J2000d;\n result = JulianDate.addSeconds(result, computeTdbMinusTtSpice(days), result);\n\n return result;\n}\n\nconst epoch = new JulianDate(2451545, 0, TimeStandard.TAI); //Actually TDB (not TAI)\nconst MetersPerKilometer = 1000.0;\nconst RadiansPerDegree = CesiumMath.RADIANS_PER_DEGREE;\nconst RadiansPerArcSecond = CesiumMath.RADIANS_PER_ARCSECOND;\nconst MetersPerAstronomicalUnit = 1.4959787e11; // IAU 1976 value\n\nconst perifocalToEquatorial = new Matrix3();\nfunction elementsToCartesian(\n semimajorAxis,\n eccentricity,\n inclination,\n longitudeOfPerigee,\n longitudeOfNode,\n meanLongitude,\n result\n) {\n if (inclination < 0.0) {\n inclination = -inclination;\n longitudeOfNode += CesiumMath.PI;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (inclination < 0 || inclination > CesiumMath.PI) {\n throw new DeveloperError(\n \"The inclination is out of range. Inclination must be greater than or equal to zero and less than or equal to Pi radians.\"\n );\n }\n //>>includeEnd('debug')\n\n const radiusOfPeriapsis = semimajorAxis * (1.0 - eccentricity);\n const argumentOfPeriapsis = longitudeOfPerigee - longitudeOfNode;\n const rightAscensionOfAscendingNode = longitudeOfNode;\n const trueAnomaly = meanAnomalyToTrueAnomaly(\n meanLongitude - longitudeOfPerigee,\n eccentricity\n );\n const type = chooseOrbit(eccentricity, 0.0);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n type === \"Hyperbolic\" &&\n Math.abs(CesiumMath.negativePiToPi(trueAnomaly)) >=\n Math.acos(-1.0 / eccentricity)\n ) {\n throw new DeveloperError(\n \"The true anomaly of the hyperbolic orbit lies outside of the bounds of the hyperbola.\"\n );\n }\n //>>includeEnd('debug')\n\n perifocalToCartesianMatrix(\n argumentOfPeriapsis,\n inclination,\n rightAscensionOfAscendingNode,\n perifocalToEquatorial\n );\n const semilatus = radiusOfPeriapsis * (1.0 + eccentricity);\n const costheta = Math.cos(trueAnomaly);\n const sintheta = Math.sin(trueAnomaly);\n\n const denom = 1.0 + eccentricity * costheta;\n\n //>>includeStart('debug', pragmas.debug);\n if (denom <= CesiumMath.Epsilon10) {\n throw new DeveloperError(\"elements cannot be converted to cartesian\");\n }\n //>>includeEnd('debug')\n\n const radius = semilatus / denom;\n if (!defined(result)) {\n result = new Cartesian3(radius * costheta, radius * sintheta, 0.0);\n } else {\n result.x = radius * costheta;\n result.y = radius * sintheta;\n result.z = 0.0;\n }\n\n return Matrix3.multiplyByVector(perifocalToEquatorial, result, result);\n}\n\nfunction chooseOrbit(eccentricity, tolerance) {\n //>>includeStart('debug', pragmas.debug);\n if (eccentricity < 0) {\n throw new DeveloperError(\"eccentricity cannot be negative.\");\n }\n //>>includeEnd('debug')\n\n if (eccentricity <= tolerance) {\n return \"Circular\";\n } else if (eccentricity < 1.0 - tolerance) {\n return \"Elliptical\";\n } else if (eccentricity <= 1.0 + tolerance) {\n return \"Parabolic\";\n }\n return \"Hyperbolic\";\n}\n\n// Calculates the true anomaly given the mean anomaly and the eccentricity.\nfunction meanAnomalyToTrueAnomaly(meanAnomaly, eccentricity) {\n //>>includeStart('debug', pragmas.debug);\n if (eccentricity < 0.0 || eccentricity >= 1.0) {\n throw new DeveloperError(\"eccentricity out of range.\");\n }\n //>>includeEnd('debug')\n\n const eccentricAnomaly = meanAnomalyToEccentricAnomaly(\n meanAnomaly,\n eccentricity\n );\n return eccentricAnomalyToTrueAnomaly(eccentricAnomaly, eccentricity);\n}\n\nconst maxIterationCount = 50;\nconst keplerEqConvergence = CesiumMath.EPSILON8;\n// Calculates the eccentric anomaly given the mean anomaly and the eccentricity.\nfunction meanAnomalyToEccentricAnomaly(meanAnomaly, eccentricity) {\n //>>includeStart('debug', pragmas.debug);\n if (eccentricity < 0.0 || eccentricity >= 1.0) {\n throw new DeveloperError(\"eccentricity out of range.\");\n }\n //>>includeEnd('debug')\n\n const revs = Math.floor(meanAnomaly / CesiumMath.TWO_PI);\n\n // Find angle in current revolution\n meanAnomaly -= revs * CesiumMath.TWO_PI;\n\n // calculate starting value for iteration sequence\n let iterationValue =\n meanAnomaly +\n (eccentricity * Math.sin(meanAnomaly)) /\n (1.0 - Math.sin(meanAnomaly + eccentricity) + Math.sin(meanAnomaly));\n\n // Perform Newton-Raphson iteration on Kepler's equation\n let eccentricAnomaly = Number.MAX_VALUE;\n\n let count;\n for (\n count = 0;\n count < maxIterationCount &&\n Math.abs(eccentricAnomaly - iterationValue) > keplerEqConvergence;\n ++count\n ) {\n eccentricAnomaly = iterationValue;\n const NRfunction =\n eccentricAnomaly -\n eccentricity * Math.sin(eccentricAnomaly) -\n meanAnomaly;\n const dNRfunction = 1 - eccentricity * Math.cos(eccentricAnomaly);\n iterationValue = eccentricAnomaly - NRfunction / dNRfunction;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (count >= maxIterationCount) {\n throw new DeveloperError(\"Kepler equation did not converge\");\n // STK Components uses a numerical method to find the eccentric anomaly in the case that Kepler's\n // equation does not converge. We don't expect that to ever be necessary for the reasonable orbits used here.\n }\n //>>includeEnd('debug')\n\n eccentricAnomaly = iterationValue + revs * CesiumMath.TWO_PI;\n return eccentricAnomaly;\n}\n\n// Calculates the true anomaly given the eccentric anomaly and the eccentricity.\nfunction eccentricAnomalyToTrueAnomaly(eccentricAnomaly, eccentricity) {\n //>>includeStart('debug', pragmas.debug);\n if (eccentricity < 0.0 || eccentricity >= 1.0) {\n throw new DeveloperError(\"eccentricity out of range.\");\n }\n //>>includeEnd('debug')\n\n // Calculate the number of previous revolutions\n const revs = Math.floor(eccentricAnomaly / CesiumMath.TWO_PI);\n\n // Find angle in current revolution\n eccentricAnomaly -= revs * CesiumMath.TWO_PI;\n\n // Calculate true anomaly from eccentric anomaly\n const trueAnomalyX = Math.cos(eccentricAnomaly) - eccentricity;\n const trueAnomalyY =\n Math.sin(eccentricAnomaly) * Math.sqrt(1 - eccentricity * eccentricity);\n\n let trueAnomaly = Math.atan2(trueAnomalyY, trueAnomalyX);\n\n // Ensure the correct quadrant\n trueAnomaly = CesiumMath.zeroToTwoPi(trueAnomaly);\n if (eccentricAnomaly < 0) {\n trueAnomaly -= CesiumMath.TWO_PI;\n }\n\n // Add on previous revolutions\n trueAnomaly += revs * CesiumMath.TWO_PI;\n\n return trueAnomaly;\n}\n\n// Calculates the transformation matrix to convert from the perifocal (PQW) coordinate\n// system to inertial cartesian coordinates.\nfunction perifocalToCartesianMatrix(\n argumentOfPeriapsis,\n inclination,\n rightAscension,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (inclination < 0 || inclination > CesiumMath.PI) {\n throw new DeveloperError(\"inclination out of range\");\n }\n //>>includeEnd('debug')\n\n const cosap = Math.cos(argumentOfPeriapsis);\n const sinap = Math.sin(argumentOfPeriapsis);\n\n const cosi = Math.cos(inclination);\n const sini = Math.sin(inclination);\n\n const cosraan = Math.cos(rightAscension);\n const sinraan = Math.sin(rightAscension);\n if (!defined(result)) {\n result = new Matrix3(\n cosraan * cosap - sinraan * sinap * cosi,\n -cosraan * sinap - sinraan * cosap * cosi,\n sinraan * sini,\n\n sinraan * cosap + cosraan * sinap * cosi,\n -sinraan * sinap + cosraan * cosap * cosi,\n -cosraan * sini,\n\n sinap * sini,\n cosap * sini,\n cosi\n );\n } else {\n result[0] = cosraan * cosap - sinraan * sinap * cosi;\n result[1] = sinraan * cosap + cosraan * sinap * cosi;\n result[2] = sinap * sini;\n result[3] = -cosraan * sinap - sinraan * cosap * cosi;\n result[4] = -sinraan * sinap + cosraan * cosap * cosi;\n result[5] = cosap * sini;\n result[6] = sinraan * sini;\n result[7] = -cosraan * sini;\n result[8] = cosi;\n }\n return result;\n}\n\n// From section 5.8\nconst semiMajorAxis0 = 1.0000010178 * MetersPerAstronomicalUnit;\nconst meanLongitude0 = 100.46645683 * RadiansPerDegree;\nconst meanLongitude1 = 1295977422.83429 * RadiansPerArcSecond;\n\n// From table 6\nconst p1u = 16002;\nconst p2u = 21863;\nconst p3u = 32004;\nconst p4u = 10931;\nconst p5u = 14529;\nconst p6u = 16368;\nconst p7u = 15318;\nconst p8u = 32794;\n\nconst Ca1 = 64 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca2 = -152 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca3 = 62 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca4 = -8 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca5 = 32 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca6 = -41 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca7 = 19 * 1e-7 * MetersPerAstronomicalUnit;\nconst Ca8 = -11 * 1e-7 * MetersPerAstronomicalUnit;\n\nconst Sa1 = -150 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa2 = -46 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa3 = 68 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa4 = 54 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa5 = 14 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa6 = 24 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa7 = -28 * 1e-7 * MetersPerAstronomicalUnit;\nconst Sa8 = 22 * 1e-7 * MetersPerAstronomicalUnit;\n\nconst q1u = 10;\nconst q2u = 16002;\nconst q3u = 21863;\nconst q4u = 10931;\nconst q5u = 1473;\nconst q6u = 32004;\nconst q7u = 4387;\nconst q8u = 73;\n\nconst Cl1 = -325 * 1e-7;\nconst Cl2 = -322 * 1e-7;\nconst Cl3 = -79 * 1e-7;\nconst Cl4 = 232 * 1e-7;\nconst Cl5 = -52 * 1e-7;\nconst Cl6 = 97 * 1e-7;\nconst Cl7 = 55 * 1e-7;\nconst Cl8 = -41 * 1e-7;\n\nconst Sl1 = -105 * 1e-7;\nconst Sl2 = -137 * 1e-7;\nconst Sl3 = 258 * 1e-7;\nconst Sl4 = 35 * 1e-7;\nconst Sl5 = -116 * 1e-7;\nconst Sl6 = -88 * 1e-7;\nconst Sl7 = -112 * 1e-7;\nconst Sl8 = -80 * 1e-7;\n\nconst scratchDate = new JulianDate(0, 0.0, TimeStandard.TAI);\n// Gets a point describing the motion of the Earth-Moon barycenter according to the equations described in section 6.\nfunction computeSimonEarthMoonBarycenter(date, result) {\n // t is thousands of years from J2000 TDB\n taiToTdb(date, scratchDate);\n const x =\n scratchDate.dayNumber -\n epoch.dayNumber +\n (scratchDate.secondsOfDay - epoch.secondsOfDay) /\n TimeConstants.SECONDS_PER_DAY;\n const t = x / (TimeConstants.DAYS_PER_JULIAN_CENTURY * 10.0);\n\n const u = 0.3595362 * t;\n const semimajorAxis =\n semiMajorAxis0 +\n Ca1 * Math.cos(p1u * u) +\n Sa1 * Math.sin(p1u * u) +\n Ca2 * Math.cos(p2u * u) +\n Sa2 * Math.sin(p2u * u) +\n Ca3 * Math.cos(p3u * u) +\n Sa3 * Math.sin(p3u * u) +\n Ca4 * Math.cos(p4u * u) +\n Sa4 * Math.sin(p4u * u) +\n Ca5 * Math.cos(p5u * u) +\n Sa5 * Math.sin(p5u * u) +\n Ca6 * Math.cos(p6u * u) +\n Sa6 * Math.sin(p6u * u) +\n Ca7 * Math.cos(p7u * u) +\n Sa7 * Math.sin(p7u * u) +\n Ca8 * Math.cos(p8u * u) +\n Sa8 * Math.sin(p8u * u);\n const meanLongitude =\n meanLongitude0 +\n meanLongitude1 * t +\n Cl1 * Math.cos(q1u * u) +\n Sl1 * Math.sin(q1u * u) +\n Cl2 * Math.cos(q2u * u) +\n Sl2 * Math.sin(q2u * u) +\n Cl3 * Math.cos(q3u * u) +\n Sl3 * Math.sin(q3u * u) +\n Cl4 * Math.cos(q4u * u) +\n Sl4 * Math.sin(q4u * u) +\n Cl5 * Math.cos(q5u * u) +\n Sl5 * Math.sin(q5u * u) +\n Cl6 * Math.cos(q6u * u) +\n Sl6 * Math.sin(q6u * u) +\n Cl7 * Math.cos(q7u * u) +\n Sl7 * Math.sin(q7u * u) +\n Cl8 * Math.cos(q8u * u) +\n Sl8 * Math.sin(q8u * u);\n\n // All constants in this part are from section 5.8\n const eccentricity = 0.0167086342 - 0.0004203654 * t;\n const longitudeOfPerigee =\n 102.93734808 * RadiansPerDegree + 11612.3529 * RadiansPerArcSecond * t;\n const inclination = 469.97289 * RadiansPerArcSecond * t;\n const longitudeOfNode =\n 174.87317577 * RadiansPerDegree - 8679.27034 * RadiansPerArcSecond * t;\n\n return elementsToCartesian(\n semimajorAxis,\n eccentricity,\n inclination,\n longitudeOfPerigee,\n longitudeOfNode,\n meanLongitude,\n result\n );\n}\n\n// Gets a point describing the position of the moon according to the equations described in section 4.\nfunction computeSimonMoon(date, result) {\n taiToTdb(date, scratchDate);\n const x =\n scratchDate.dayNumber -\n epoch.dayNumber +\n (scratchDate.secondsOfDay - epoch.secondsOfDay) /\n TimeConstants.SECONDS_PER_DAY;\n const t = x / TimeConstants.DAYS_PER_JULIAN_CENTURY;\n const t2 = t * t;\n const t3 = t2 * t;\n const t4 = t3 * t;\n\n // Terms from section 3.4 (b.1)\n let semimajorAxis = 383397.7725 + 0.004 * t;\n let eccentricity = 0.055545526 - 0.000000016 * t;\n const inclinationConstant = 5.15668983 * RadiansPerDegree;\n let inclinationSecPart =\n -0.00008 * t + 0.02966 * t2 - 0.000042 * t3 - 0.00000013 * t4;\n const longitudeOfPerigeeConstant = 83.35324312 * RadiansPerDegree;\n let longitudeOfPerigeeSecPart =\n 14643420.2669 * t - 38.2702 * t2 - 0.045047 * t3 + 0.00021301 * t4;\n const longitudeOfNodeConstant = 125.04455501 * RadiansPerDegree;\n let longitudeOfNodeSecPart =\n -6967919.3631 * t + 6.3602 * t2 + 0.007625 * t3 - 0.00003586 * t4;\n const meanLongitudeConstant = 218.31664563 * RadiansPerDegree;\n let meanLongitudeSecPart =\n 1732559343.4847 * t - 6.391 * t2 + 0.006588 * t3 - 0.00003169 * t4;\n\n // Delaunay arguments from section 3.5 b\n const D =\n 297.85019547 * RadiansPerDegree +\n RadiansPerArcSecond *\n (1602961601.209 * t - 6.3706 * t2 + 0.006593 * t3 - 0.00003169 * t4);\n const F =\n 93.27209062 * RadiansPerDegree +\n RadiansPerArcSecond *\n (1739527262.8478 * t - 12.7512 * t2 - 0.001037 * t3 + 0.00000417 * t4);\n const l =\n 134.96340251 * RadiansPerDegree +\n RadiansPerArcSecond *\n (1717915923.2178 * t + 31.8792 * t2 + 0.051635 * t3 - 0.0002447 * t4);\n const lprime =\n 357.52910918 * RadiansPerDegree +\n RadiansPerArcSecond *\n (129596581.0481 * t - 0.5532 * t2 + 0.000136 * t3 - 0.00001149 * t4);\n const psi =\n 310.17137918 * RadiansPerDegree -\n RadiansPerArcSecond *\n (6967051.436 * t + 6.2068 * t2 + 0.007618 * t3 - 0.00003219 * t4);\n\n // Add terms from Table 4\n const twoD = 2.0 * D;\n const fourD = 4.0 * D;\n const sixD = 6.0 * D;\n const twol = 2.0 * l;\n const threel = 3.0 * l;\n const fourl = 4.0 * l;\n const twoF = 2.0 * F;\n semimajorAxis +=\n 3400.4 * Math.cos(twoD) -\n 635.6 * Math.cos(twoD - l) -\n 235.6 * Math.cos(l) +\n 218.1 * Math.cos(twoD - lprime) +\n 181.0 * Math.cos(twoD + l);\n eccentricity +=\n 0.014216 * Math.cos(twoD - l) +\n 0.008551 * Math.cos(twoD - twol) -\n 0.001383 * Math.cos(l) +\n 0.001356 * Math.cos(twoD + l) -\n 0.001147 * Math.cos(fourD - threel) -\n 0.000914 * Math.cos(fourD - twol) +\n 0.000869 * Math.cos(twoD - lprime - l) -\n 0.000627 * Math.cos(twoD) -\n 0.000394 * Math.cos(fourD - fourl) +\n 0.000282 * Math.cos(twoD - lprime - twol) -\n 0.000279 * Math.cos(D - l) -\n 0.000236 * Math.cos(twol) +\n 0.000231 * Math.cos(fourD) +\n 0.000229 * Math.cos(sixD - fourl) -\n 0.000201 * Math.cos(twol - twoF);\n inclinationSecPart +=\n 486.26 * Math.cos(twoD - twoF) -\n 40.13 * Math.cos(twoD) +\n 37.51 * Math.cos(twoF) +\n 25.73 * Math.cos(twol - twoF) +\n 19.97 * Math.cos(twoD - lprime - twoF);\n longitudeOfPerigeeSecPart +=\n -55609 * Math.sin(twoD - l) -\n 34711 * Math.sin(twoD - twol) -\n 9792 * Math.sin(l) +\n 9385 * Math.sin(fourD - threel) +\n 7505 * Math.sin(fourD - twol) +\n 5318 * Math.sin(twoD + l) +\n 3484 * Math.sin(fourD - fourl) -\n 3417 * Math.sin(twoD - lprime - l) -\n 2530 * Math.sin(sixD - fourl) -\n 2376 * Math.sin(twoD) -\n 2075 * Math.sin(twoD - threel) -\n 1883 * Math.sin(twol) -\n 1736 * Math.sin(sixD - 5.0 * l) +\n 1626 * Math.sin(lprime) -\n 1370 * Math.sin(sixD - threel);\n longitudeOfNodeSecPart +=\n -5392 * Math.sin(twoD - twoF) -\n 540 * Math.sin(lprime) -\n 441 * Math.sin(twoD) +\n 423 * Math.sin(twoF) -\n 288 * Math.sin(twol - twoF);\n meanLongitudeSecPart +=\n -3332.9 * Math.sin(twoD) +\n 1197.4 * Math.sin(twoD - l) -\n 662.5 * Math.sin(lprime) +\n 396.3 * Math.sin(l) -\n 218.0 * Math.sin(twoD - lprime);\n\n // Add terms from Table 5\n const twoPsi = 2.0 * psi;\n const threePsi = 3.0 * psi;\n inclinationSecPart +=\n 46.997 * Math.cos(psi) * t -\n 0.614 * Math.cos(twoD - twoF + psi) * t +\n 0.614 * Math.cos(twoD - twoF - psi) * t -\n 0.0297 * Math.cos(twoPsi) * t2 -\n 0.0335 * Math.cos(psi) * t2 +\n 0.0012 * Math.cos(twoD - twoF + twoPsi) * t2 -\n 0.00016 * Math.cos(psi) * t3 +\n 0.00004 * Math.cos(threePsi) * t3 +\n 0.00004 * Math.cos(twoPsi) * t3;\n const perigeeAndMean =\n 2.116 * Math.sin(psi) * t -\n 0.111 * Math.sin(twoD - twoF - psi) * t -\n 0.0015 * Math.sin(psi) * t2;\n longitudeOfPerigeeSecPart += perigeeAndMean;\n meanLongitudeSecPart += perigeeAndMean;\n longitudeOfNodeSecPart +=\n -520.77 * Math.sin(psi) * t +\n 13.66 * Math.sin(twoD - twoF + psi) * t +\n 1.12 * Math.sin(twoD - psi) * t -\n 1.06 * Math.sin(twoF - psi) * t +\n 0.66 * Math.sin(twoPsi) * t2 +\n 0.371 * Math.sin(psi) * t2 -\n 0.035 * Math.sin(twoD - twoF + twoPsi) * t2 -\n 0.015 * Math.sin(twoD - twoF + psi) * t2 +\n 0.0014 * Math.sin(psi) * t3 -\n 0.0011 * Math.sin(threePsi) * t3 -\n 0.0009 * Math.sin(twoPsi) * t3;\n\n // Add constants and convert units\n semimajorAxis *= MetersPerKilometer;\n const inclination =\n inclinationConstant + inclinationSecPart * RadiansPerArcSecond;\n const longitudeOfPerigee =\n longitudeOfPerigeeConstant +\n longitudeOfPerigeeSecPart * RadiansPerArcSecond;\n const meanLongitude =\n meanLongitudeConstant + meanLongitudeSecPart * RadiansPerArcSecond;\n const longitudeOfNode =\n longitudeOfNodeConstant + longitudeOfNodeSecPart * RadiansPerArcSecond;\n\n return elementsToCartesian(\n semimajorAxis,\n eccentricity,\n inclination,\n longitudeOfPerigee,\n longitudeOfNode,\n meanLongitude,\n result\n );\n}\n\n// Gets a point describing the motion of the Earth. This point uses the Moon point and\n// the 1992 mu value (ratio between Moon and Earth masses) in Table 2 of the paper in order\n// to determine the position of the Earth relative to the Earth-Moon barycenter.\nconst moonEarthMassRatio = 0.012300034; // From 1992 mu value in Table 2\nconst factor = (moonEarthMassRatio / (moonEarthMassRatio + 1.0)) * -1;\nfunction computeSimonEarth(date, result) {\n result = computeSimonMoon(date, result);\n return Cartesian3.multiplyByScalar(result, factor, result);\n}\n\n// Values for the axesTransformation needed for the rotation were found using the STK Components\n// GreographicTransformer on the position of the sun center of mass point and the earth J2000 frame.\n\nconst axesTransformation = new Matrix3(\n 1.0000000000000002,\n 5.619723173785822e-16,\n 4.690511510146299e-19,\n -5.154129427414611e-16,\n 0.9174820620691819,\n -0.39777715593191376,\n -2.23970096136568e-16,\n 0.39777715593191376,\n 0.9174820620691819\n);\nlet translation = new Cartesian3();\n/**\n * Computes the position of the Sun in the Earth-centered inertial frame\n *\n * @param {JulianDate} [julianDate] The time at which to compute the Sun's position, if not provided the current system time is used.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} Calculated sun position\n */\nSimon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame = function (\n julianDate,\n result\n) {\n if (!defined(julianDate)) {\n julianDate = JulianDate.now();\n }\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n //first forward transformation\n translation = computeSimonEarthMoonBarycenter(julianDate, translation);\n result = Cartesian3.negate(translation, result);\n\n //second forward transformation\n computeSimonEarth(julianDate, translation);\n\n Cartesian3.subtract(result, translation, result);\n Matrix3.multiplyByVector(axesTransformation, result, result);\n\n return result;\n};\n\n/**\n * Computes the position of the Moon in the Earth-centered inertial frame\n *\n * @param {JulianDate} [julianDate] The time at which to compute the Sun's position, if not provided the current system time is used.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} Calculated moon position\n */\nSimon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame = function (\n julianDate,\n result\n) {\n if (!defined(julianDate)) {\n julianDate = JulianDate.now();\n }\n\n result = computeSimonMoon(julianDate, result);\n Matrix3.multiplyByVector(axesTransformation, result, result);\n\n return result;\n};\nexport default Simon1994PlanetaryPositions;\n", "/**\n * Indicates if the scene is viewed in 3D, 2D, or 2.5D Columbus view.\n *\n * @enum {number}\n * @see Scene#mode\n */\nconst SceneMode = {\n /**\n * Morphing between mode, e.g., 3D to 2D.\n *\n * @type {number}\n * @constant\n */\n MORPHING: 0,\n\n /**\n * Columbus View mode. A 2.5D perspective view where the map is laid out\n * flat and objects with non-zero height are drawn above it.\n *\n * @type {number}\n * @constant\n */\n COLUMBUS_VIEW: 1,\n\n /**\n * 2D mode. The map is viewed top-down with an orthographic projection.\n *\n * @type {number}\n * @constant\n */\n SCENE2D: 2,\n\n /**\n * 3D mode. A traditional 3D perspective view of the globe.\n *\n * @type {number}\n * @constant\n */\n SCENE3D: 3,\n};\n\n/**\n * Returns the morph time for the given scene mode.\n *\n * @param {SceneMode} value The scene mode\n * @returns {number} The morph time\n */\nSceneMode.getMorphTime = function (value) {\n if (value === SceneMode.SCENE3D) {\n return 1.0;\n } else if (value === SceneMode.MORPHING) {\n return undefined;\n }\n return 0.0;\n};\nexport default Object.freeze(SceneMode);\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * A directional light source that originates from the Sun.\n *\n * @param {object} [options] Object with the following properties:\n * @param {Color} [options.color=Color.WHITE] The light's color.\n * @param {number} [options.intensity=2.0] The light's intensity.\n *\n * @alias SunLight\n * @constructor\n */\nfunction SunLight(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n /**\n * The color of the light.\n * @type {Color}\n * @default Color.WHITE\n */\n this.color = Color.clone(defaultValue(options.color, Color.WHITE));\n\n /**\n * The intensity of the light.\n * @type {number}\n * @default 2.0\n */\n this.intensity = defaultValue(options.intensity, 2.0);\n}\n\nexport default SunLight;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OrthographicFrustum from \"../Core/OrthographicFrustum.js\";\nimport Simon1994PlanetaryPositions from \"../Core/Simon1994PlanetaryPositions.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport SunLight from \"../Scene/SunLight.js\";\n\n/**\n * @private\n * @constructor\n */\nfunction UniformState() {\n /**\n * @type {Texture}\n */\n this.globeDepthTexture = undefined;\n /**\n * @type {number}\n */\n this.gamma = undefined;\n\n this._viewport = new BoundingRectangle();\n this._viewportCartesian4 = new Cartesian4();\n this._viewportDirty = false;\n this._viewportOrthographicMatrix = Matrix4.clone(Matrix4.IDENTITY);\n this._viewportTransformation = Matrix4.clone(Matrix4.IDENTITY);\n\n this._model = Matrix4.clone(Matrix4.IDENTITY);\n this._view = Matrix4.clone(Matrix4.IDENTITY);\n this._inverseView = Matrix4.clone(Matrix4.IDENTITY);\n this._projection = Matrix4.clone(Matrix4.IDENTITY);\n this._infiniteProjection = Matrix4.clone(Matrix4.IDENTITY);\n this._entireFrustum = new Cartesian2();\n this._currentFrustum = new Cartesian2();\n this._frustumPlanes = new Cartesian4();\n this._farDepthFromNearPlusOne = undefined;\n this._log2FarDepthFromNearPlusOne = undefined;\n this._oneOverLog2FarDepthFromNearPlusOne = undefined;\n\n this._frameState = undefined;\n this._temeToPseudoFixed = Matrix3.clone(Matrix4.IDENTITY);\n\n // Derived members\n this._view3DDirty = true;\n this._view3D = new Matrix4();\n\n this._inverseView3DDirty = true;\n this._inverseView3D = new Matrix4();\n\n this._inverseModelDirty = true;\n this._inverseModel = new Matrix4();\n\n this._inverseTransposeModelDirty = true;\n this._inverseTransposeModel = new Matrix3();\n\n this._viewRotation = new Matrix3();\n this._inverseViewRotation = new Matrix3();\n\n this._viewRotation3D = new Matrix3();\n this._inverseViewRotation3D = new Matrix3();\n\n this._inverseProjectionDirty = true;\n this._inverseProjection = new Matrix4();\n\n this._modelViewDirty = true;\n this._modelView = new Matrix4();\n\n this._modelView3DDirty = true;\n this._modelView3D = new Matrix4();\n\n this._modelViewRelativeToEyeDirty = true;\n this._modelViewRelativeToEye = new Matrix4();\n\n this._inverseModelViewDirty = true;\n this._inverseModelView = new Matrix4();\n\n this._inverseModelView3DDirty = true;\n this._inverseModelView3D = new Matrix4();\n\n this._viewProjectionDirty = true;\n this._viewProjection = new Matrix4();\n\n this._inverseViewProjectionDirty = true;\n this._inverseViewProjection = new Matrix4();\n\n this._modelViewProjectionDirty = true;\n this._modelViewProjection = new Matrix4();\n\n this._inverseModelViewProjectionDirty = true;\n this._inverseModelViewProjection = new Matrix4();\n\n this._modelViewProjectionRelativeToEyeDirty = true;\n this._modelViewProjectionRelativeToEye = new Matrix4();\n\n this._modelViewInfiniteProjectionDirty = true;\n this._modelViewInfiniteProjection = new Matrix4();\n\n this._normalDirty = true;\n this._normal = new Matrix3();\n\n this._normal3DDirty = true;\n this._normal3D = new Matrix3();\n\n this._inverseNormalDirty = true;\n this._inverseNormal = new Matrix3();\n\n this._inverseNormal3DDirty = true;\n this._inverseNormal3D = new Matrix3();\n\n this._encodedCameraPositionMCDirty = true;\n this._encodedCameraPositionMC = new EncodedCartesian3();\n this._cameraPosition = new Cartesian3();\n\n this._sunPositionWC = new Cartesian3();\n this._sunPositionColumbusView = new Cartesian3();\n this._sunDirectionWC = new Cartesian3();\n this._sunDirectionEC = new Cartesian3();\n this._moonDirectionEC = new Cartesian3();\n\n this._lightDirectionWC = new Cartesian3();\n this._lightDirectionEC = new Cartesian3();\n this._lightColor = new Cartesian3();\n this._lightColorHdr = new Cartesian3();\n\n this._pass = undefined;\n this._mode = undefined;\n this._mapProjection = undefined;\n this._ellipsoid = undefined;\n this._cameraDirection = new Cartesian3();\n this._cameraRight = new Cartesian3();\n this._cameraUp = new Cartesian3();\n this._frustum2DWidth = 0.0;\n this._eyeHeight = 0.0;\n this._eyeHeight2D = new Cartesian2();\n this._pixelRatio = 1.0;\n this._orthographicIn3D = false;\n this._backgroundColor = new Color();\n\n this._brdfLut = undefined;\n this._environmentMap = undefined;\n\n this._sphericalHarmonicCoefficients = undefined;\n this._specularEnvironmentMaps = undefined;\n this._specularEnvironmentMapsDimensions = new Cartesian2();\n this._specularEnvironmentMapsMaximumLOD = undefined;\n\n this._fogDensity = undefined;\n\n this._invertClassificationColor = undefined;\n\n this._splitPosition = 0.0;\n this._pixelSizePerMeter = undefined;\n this._geometricToleranceOverMeter = undefined;\n\n this._minimumDisableDepthTestDistance = undefined;\n}\n\nObject.defineProperties(UniformState.prototype, {\n /**\n * @memberof UniformState.prototype\n * @type {FrameState}\n * @readonly\n */\n frameState: {\n get: function () {\n return this._frameState;\n },\n },\n /**\n * @memberof UniformState.prototype\n * @type {BoundingRectangle}\n */\n viewport: {\n get: function () {\n return this._viewport;\n },\n set: function (viewport) {\n if (!BoundingRectangle.equals(viewport, this._viewport)) {\n BoundingRectangle.clone(viewport, this._viewport);\n\n const v = this._viewport;\n const vc = this._viewportCartesian4;\n vc.x = v.x;\n vc.y = v.y;\n vc.z = v.width;\n vc.w = v.height;\n\n this._viewportDirty = true;\n }\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @private\n */\n viewportCartesian4: {\n get: function () {\n return this._viewportCartesian4;\n },\n },\n\n viewportOrthographic: {\n get: function () {\n cleanViewport(this);\n return this._viewportOrthographicMatrix;\n },\n },\n\n viewportTransformation: {\n get: function () {\n cleanViewport(this);\n return this._viewportTransformation;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n model: {\n get: function () {\n return this._model;\n },\n set: function (matrix) {\n Matrix4.clone(matrix, this._model);\n\n this._modelView3DDirty = true;\n this._inverseModelView3DDirty = true;\n this._inverseModelDirty = true;\n this._inverseTransposeModelDirty = true;\n this._modelViewDirty = true;\n this._inverseModelViewDirty = true;\n this._modelViewRelativeToEyeDirty = true;\n this._inverseModelViewDirty = true;\n this._modelViewProjectionDirty = true;\n this._inverseModelViewProjectionDirty = true;\n this._modelViewProjectionRelativeToEyeDirty = true;\n this._modelViewInfiniteProjectionDirty = true;\n this._normalDirty = true;\n this._inverseNormalDirty = true;\n this._normal3DDirty = true;\n this._inverseNormal3DDirty = true;\n this._encodedCameraPositionMCDirty = true;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseModel: {\n get: function () {\n if (this._inverseModelDirty) {\n this._inverseModelDirty = false;\n\n Matrix4.inverse(this._model, this._inverseModel);\n }\n\n return this._inverseModel;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @private\n */\n inverseTransposeModel: {\n get: function () {\n const m = this._inverseTransposeModel;\n if (this._inverseTransposeModelDirty) {\n this._inverseTransposeModelDirty = false;\n\n Matrix4.getMatrix3(this.inverseModel, m);\n Matrix3.transpose(m, m);\n }\n\n return m;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n view: {\n get: function () {\n return this._view;\n },\n },\n\n /**\n * The 3D view matrix. In 3D mode, this is identical to {@link UniformState#view},\n * but in 2D and Columbus View it is a synthetic matrix based on the equivalent position\n * of the camera in the 3D world.\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n view3D: {\n get: function () {\n updateView3D(this);\n return this._view3D;\n },\n },\n\n /**\n * The 3x3 rotation matrix of the current view matrix ({@link UniformState#view}).\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n viewRotation: {\n get: function () {\n updateView3D(this);\n return this._viewRotation;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n viewRotation3D: {\n get: function () {\n updateView3D(this);\n return this._viewRotation3D;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseView: {\n get: function () {\n return this._inverseView;\n },\n },\n\n /**\n * the 4x4 inverse-view matrix that transforms from eye to 3D world coordinates. In 3D mode, this is\n * identical to {@link UniformState#inverseView}, but in 2D and Columbus View it is a synthetic matrix\n * based on the equivalent position of the camera in the 3D world.\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseView3D: {\n get: function () {\n updateInverseView3D(this);\n return this._inverseView3D;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n inverseViewRotation: {\n get: function () {\n return this._inverseViewRotation;\n },\n },\n\n /**\n * The 3x3 rotation matrix of the current 3D inverse-view matrix ({@link UniformState#inverseView3D}).\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n inverseViewRotation3D: {\n get: function () {\n updateInverseView3D(this);\n return this._inverseViewRotation3D;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n projection: {\n get: function () {\n return this._projection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseProjection: {\n get: function () {\n cleanInverseProjection(this);\n return this._inverseProjection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n infiniteProjection: {\n get: function () {\n return this._infiniteProjection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelView: {\n get: function () {\n cleanModelView(this);\n return this._modelView;\n },\n },\n\n /**\n * The 3D model-view matrix. In 3D mode, this is equivalent to {@link UniformState#modelView}. In 2D and\n * Columbus View, however, it is a synthetic matrix based on the equivalent position of the camera in the 3D world.\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelView3D: {\n get: function () {\n cleanModelView3D(this);\n return this._modelView3D;\n },\n },\n\n /**\n * Model-view relative to eye matrix.\n *\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelViewRelativeToEye: {\n get: function () {\n cleanModelViewRelativeToEye(this);\n return this._modelViewRelativeToEye;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseModelView: {\n get: function () {\n cleanInverseModelView(this);\n return this._inverseModelView;\n },\n },\n\n /**\n * The inverse of the 3D model-view matrix. In 3D mode, this is equivalent to {@link UniformState#inverseModelView}.\n * In 2D and Columbus View, however, it is a synthetic matrix based on the equivalent position of the camera in the 3D world.\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseModelView3D: {\n get: function () {\n cleanInverseModelView3D(this);\n return this._inverseModelView3D;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n viewProjection: {\n get: function () {\n cleanViewProjection(this);\n return this._viewProjection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseViewProjection: {\n get: function () {\n cleanInverseViewProjection(this);\n return this._inverseViewProjection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelViewProjection: {\n get: function () {\n cleanModelViewProjection(this);\n return this._modelViewProjection;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n inverseModelViewProjection: {\n get: function () {\n cleanInverseModelViewProjection(this);\n return this._inverseModelViewProjection;\n },\n },\n\n /**\n * Model-view-projection relative to eye matrix.\n *\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelViewProjectionRelativeToEye: {\n get: function () {\n cleanModelViewProjectionRelativeToEye(this);\n return this._modelViewProjectionRelativeToEye;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Matrix4}\n */\n modelViewInfiniteProjection: {\n get: function () {\n cleanModelViewInfiniteProjection(this);\n return this._modelViewInfiniteProjection;\n },\n },\n\n /**\n * A 3x3 normal transformation matrix that transforms normal vectors in model coordinates to\n * eye coordinates.\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n normal: {\n get: function () {\n cleanNormal(this);\n return this._normal;\n },\n },\n\n /**\n * A 3x3 normal transformation matrix that transforms normal vectors in 3D model\n * coordinates to eye coordinates. In 3D mode, this is identical to\n * {@link UniformState#normal}, but in 2D and Columbus View it represents the normal transformation\n * matrix as if the camera were at an equivalent location in 3D mode.\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n normal3D: {\n get: function () {\n cleanNormal3D(this);\n return this._normal3D;\n },\n },\n\n /**\n * An inverse 3x3 normal transformation matrix that transforms normal vectors in model coordinates\n * to eye coordinates.\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n inverseNormal: {\n get: function () {\n cleanInverseNormal(this);\n return this._inverseNormal;\n },\n },\n\n /**\n * An inverse 3x3 normal transformation matrix that transforms normal vectors in eye coordinates\n * to 3D model coordinates. In 3D mode, this is identical to\n * {@link UniformState#inverseNormal}, but in 2D and Columbus View it represents the normal transformation\n * matrix as if the camera were at an equivalent location in 3D mode.\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n inverseNormal3D: {\n get: function () {\n cleanInverseNormal3D(this);\n return this._inverseNormal3D;\n },\n },\n\n /**\n * The near distance (x) and the far distance (y) of the frustum defined by the camera.\n * This is the largest possible frustum, not an individual frustum used for multi-frustum rendering.\n * @memberof UniformState.prototype\n * @type {Cartesian2}\n */\n entireFrustum: {\n get: function () {\n return this._entireFrustum;\n },\n },\n\n /**\n * The near distance (x) and the far distance (y) of the frustum defined by the camera.\n * This is the individual frustum used for multi-frustum rendering.\n * @memberof UniformState.prototype\n * @type {Cartesian2}\n */\n currentFrustum: {\n get: function () {\n return this._currentFrustum;\n },\n },\n\n /**\n * The distances to the frustum planes. The top, bottom, left and right distances are\n * the x, y, z, and w components, respectively.\n * @memberof UniformState.prototype\n * @type {Cartesian4}\n */\n frustumPlanes: {\n get: function () {\n return this._frustumPlanes;\n },\n },\n\n /**\n * The far plane's distance from the near plane, plus 1.0.\n *\n * @memberof UniformState.prototype\n * @type {number}\n */\n farDepthFromNearPlusOne: {\n get: function () {\n return this._farDepthFromNearPlusOne;\n },\n },\n\n /**\n * The log2 of {@link UniformState#farDepthFromNearPlusOne}.\n *\n * @memberof UniformState.prototype\n * @type {number}\n */\n log2FarDepthFromNearPlusOne: {\n get: function () {\n return this._log2FarDepthFromNearPlusOne;\n },\n },\n\n /**\n * 1.0 divided by {@link UniformState#log2FarDepthFromNearPlusOne}.\n *\n * @memberof UniformState.prototype\n * @type {number}\n */\n oneOverLog2FarDepthFromNearPlusOne: {\n get: function () {\n return this._oneOverLog2FarDepthFromNearPlusOne;\n },\n },\n\n /**\n * The height in meters of the eye (camera) above or below the ellipsoid.\n * @memberof UniformState.prototype\n * @type {number}\n */\n eyeHeight: {\n get: function () {\n return this._eyeHeight;\n },\n },\n\n /**\n * The height (x) and the height squared (y)\n * in meters of the eye (camera) above the 2D world plane. This uniform is only valid\n * when the {@link SceneMode} is SCENE2D.\n * @memberof UniformState.prototype\n * @type {Cartesian2}\n */\n eyeHeight2D: {\n get: function () {\n return this._eyeHeight2D;\n },\n },\n\n /**\n * The sun position in 3D world coordinates at the current scene time.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n sunPositionWC: {\n get: function () {\n return this._sunPositionWC;\n },\n },\n\n /**\n * The sun position in 2D world coordinates at the current scene time.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n sunPositionColumbusView: {\n get: function () {\n return this._sunPositionColumbusView;\n },\n },\n\n /**\n * A normalized vector to the sun in 3D world coordinates at the current scene time. Even in 2D or\n * Columbus View mode, this returns the direction to the sun in the 3D scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n sunDirectionWC: {\n get: function () {\n return this._sunDirectionWC;\n },\n },\n\n /**\n * A normalized vector to the sun in eye coordinates at the current scene time. In 3D mode, this\n * returns the actual vector from the camera position to the sun position. In 2D and Columbus View, it returns\n * the vector from the equivalent 3D camera position to the position of the sun in the 3D scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n sunDirectionEC: {\n get: function () {\n return this._sunDirectionEC;\n },\n },\n\n /**\n * A normalized vector to the moon in eye coordinates at the current scene time. In 3D mode, this\n * returns the actual vector from the camera position to the moon position. In 2D and Columbus View, it returns\n * the vector from the equivalent 3D camera position to the position of the moon in the 3D scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n moonDirectionEC: {\n get: function () {\n return this._moonDirectionEC;\n },\n },\n\n /**\n * A normalized vector to the scene's light source in 3D world coordinates. Even in 2D or\n * Columbus View mode, this returns the direction to the light in the 3D scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n lightDirectionWC: {\n get: function () {\n return this._lightDirectionWC;\n },\n },\n\n /**\n * A normalized vector to the scene's light source in eye coordinates. In 3D mode, this\n * returns the actual vector from the camera position to the light. In 2D and Columbus View, it returns\n * the vector from the equivalent 3D camera position in the 3D scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n lightDirectionEC: {\n get: function () {\n return this._lightDirectionEC;\n },\n },\n\n /**\n * The color of light emitted by the scene's light source. This is equivalent to the light\n * color multiplied by the light intensity limited to a maximum luminance of 1.0 suitable\n * for non-HDR lighting.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n lightColor: {\n get: function () {\n return this._lightColor;\n },\n },\n\n /**\n * The high dynamic range color of light emitted by the scene's light source. This is equivalent to\n * the light color multiplied by the light intensity suitable for HDR lighting.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n lightColorHdr: {\n get: function () {\n return this._lightColorHdr;\n },\n },\n\n /**\n * The high bits of the camera position.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n encodedCameraPositionMCHigh: {\n get: function () {\n cleanEncodedCameraPositionMC(this);\n return this._encodedCameraPositionMC.high;\n },\n },\n\n /**\n * The low bits of the camera position.\n * @memberof UniformState.prototype\n * @type {Cartesian3}\n */\n encodedCameraPositionMCLow: {\n get: function () {\n cleanEncodedCameraPositionMC(this);\n return this._encodedCameraPositionMC.low;\n },\n },\n\n /**\n * A 3x3 matrix that transforms from True Equator Mean Equinox (TEME) axes to the\n * pseudo-fixed axes at the Scene's current time.\n * @memberof UniformState.prototype\n * @type {Matrix3}\n */\n temeToPseudoFixedMatrix: {\n get: function () {\n return this._temeToPseudoFixed;\n },\n },\n\n /**\n * Gets the scaling factor for transforming from the canvas\n * pixel space to canvas coordinate space.\n * @memberof UniformState.prototype\n * @type {number}\n */\n pixelRatio: {\n get: function () {\n return this._pixelRatio;\n },\n },\n\n /**\n * A scalar used to mix a color with the fog color based on the distance to the camera.\n * @memberof UniformState.prototype\n * @type {number}\n */\n fogDensity: {\n get: function () {\n return this._fogDensity;\n },\n },\n\n /**\n * A scalar that represents the geometric tolerance per meter\n * @memberof UniformState.prototype\n * @type {number}\n */\n geometricToleranceOverMeter: {\n get: function () {\n return this._geometricToleranceOverMeter;\n },\n },\n\n /**\n * @memberof UniformState.prototype\n * @type {Pass}\n */\n pass: {\n get: function () {\n return this._pass;\n },\n },\n\n /**\n * The current background color\n * @memberof UniformState.prototype\n * @type {Color}\n */\n backgroundColor: {\n get: function () {\n return this._backgroundColor;\n },\n },\n\n /**\n * The look up texture used to find the BRDF for a material\n * @memberof UniformState.prototype\n * @type {Texture}\n */\n brdfLut: {\n get: function () {\n return this._brdfLut;\n },\n },\n\n /**\n * The environment map of the scene\n * @memberof UniformState.prototype\n * @type {CubeMap}\n */\n environmentMap: {\n get: function () {\n return this._environmentMap;\n },\n },\n\n /**\n * The spherical harmonic coefficients of the scene.\n * @memberof UniformState.prototype\n * @type {Cartesian3[]}\n */\n sphericalHarmonicCoefficients: {\n get: function () {\n return this._sphericalHarmonicCoefficients;\n },\n },\n\n /**\n * The specular environment map atlas of the scene.\n * @memberof UniformState.prototype\n * @type {Texture}\n */\n specularEnvironmentMaps: {\n get: function () {\n return this._specularEnvironmentMaps;\n },\n },\n\n /**\n * The dimensions of the specular environment map atlas of the scene.\n * @memberof UniformState.prototype\n * @type {Cartesian2}\n */\n specularEnvironmentMapsDimensions: {\n get: function () {\n return this._specularEnvironmentMapsDimensions;\n },\n },\n\n /**\n * The maximum level-of-detail of the specular environment map atlas of the scene.\n * @memberof UniformState.prototype\n * @type {number}\n */\n specularEnvironmentMapsMaximumLOD: {\n get: function () {\n return this._specularEnvironmentMapsMaximumLOD;\n },\n },\n\n /**\n * The splitter position to use when rendering with a splitter. This will be in pixel coordinates relative to the canvas.\n * @memberof UniformState.prototype\n * @type {number}\n */\n splitPosition: {\n get: function () {\n return this._splitPosition;\n },\n },\n\n /**\n * The distance from the camera at which to disable the depth test of billboards, labels and points\n * to, for example, prevent clipping against terrain. When set to zero, the depth test should always\n * be applied. When less than zero, the depth test should never be applied.\n *\n * @memberof UniformState.prototype\n * @type {number}\n */\n minimumDisableDepthTestDistance: {\n get: function () {\n return this._minimumDisableDepthTestDistance;\n },\n },\n\n /**\n * The highlight color of unclassified 3D Tiles.\n *\n * @memberof UniformState.prototype\n * @type {Color}\n */\n invertClassificationColor: {\n get: function () {\n return this._invertClassificationColor;\n },\n },\n\n /**\n * Whether or not the current projection is orthographic in 3D.\n *\n * @memberOf UniformState.prototype\n * @type {boolean}\n */\n orthographicIn3D: {\n get: function () {\n return this._orthographicIn3D;\n },\n },\n\n /**\n * The current ellipsoid.\n *\n * @memberOf UniformState.prototype\n * @type {Ellipsoid}\n */\n ellipsoid: {\n get: function () {\n return defaultValue(this._ellipsoid, Ellipsoid.WGS84);\n },\n },\n});\n\nfunction setView(uniformState, matrix) {\n Matrix4.clone(matrix, uniformState._view);\n Matrix4.getMatrix3(matrix, uniformState._viewRotation);\n\n uniformState._view3DDirty = true;\n uniformState._inverseView3DDirty = true;\n uniformState._modelViewDirty = true;\n uniformState._modelView3DDirty = true;\n uniformState._modelViewRelativeToEyeDirty = true;\n uniformState._inverseModelViewDirty = true;\n uniformState._inverseModelView3DDirty = true;\n uniformState._viewProjectionDirty = true;\n uniformState._inverseViewProjectionDirty = true;\n uniformState._modelViewProjectionDirty = true;\n uniformState._modelViewProjectionRelativeToEyeDirty = true;\n uniformState._modelViewInfiniteProjectionDirty = true;\n uniformState._normalDirty = true;\n uniformState._inverseNormalDirty = true;\n uniformState._normal3DDirty = true;\n uniformState._inverseNormal3DDirty = true;\n}\n\nfunction setInverseView(uniformState, matrix) {\n Matrix4.clone(matrix, uniformState._inverseView);\n Matrix4.getMatrix3(matrix, uniformState._inverseViewRotation);\n}\n\nfunction setProjection(uniformState, matrix) {\n Matrix4.clone(matrix, uniformState._projection);\n\n uniformState._inverseProjectionDirty = true;\n uniformState._viewProjectionDirty = true;\n uniformState._inverseViewProjectionDirty = true;\n uniformState._modelViewProjectionDirty = true;\n uniformState._modelViewProjectionRelativeToEyeDirty = true;\n}\n\nfunction setInfiniteProjection(uniformState, matrix) {\n Matrix4.clone(matrix, uniformState._infiniteProjection);\n\n uniformState._modelViewInfiniteProjectionDirty = true;\n}\n\nfunction setCamera(uniformState, camera) {\n Cartesian3.clone(camera.positionWC, uniformState._cameraPosition);\n Cartesian3.clone(camera.directionWC, uniformState._cameraDirection);\n Cartesian3.clone(camera.rightWC, uniformState._cameraRight);\n Cartesian3.clone(camera.upWC, uniformState._cameraUp);\n\n const positionCartographic = camera.positionCartographic;\n if (!defined(positionCartographic)) {\n uniformState._eyeHeight = -uniformState._ellipsoid.maximumRadius;\n } else {\n uniformState._eyeHeight = positionCartographic.height;\n }\n\n uniformState._encodedCameraPositionMCDirty = true;\n}\n\nlet transformMatrix = new Matrix3();\nconst sunCartographicScratch = new Cartographic();\nfunction setSunAndMoonDirections(uniformState, frameState) {\n if (\n !defined(\n Transforms.computeIcrfToFixedMatrix(frameState.time, transformMatrix)\n )\n ) {\n transformMatrix = Transforms.computeTemeToPseudoFixedMatrix(\n frameState.time,\n transformMatrix\n );\n }\n\n let position = Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(\n frameState.time,\n uniformState._sunPositionWC\n );\n Matrix3.multiplyByVector(transformMatrix, position, position);\n\n Cartesian3.normalize(position, uniformState._sunDirectionWC);\n\n position = Matrix3.multiplyByVector(\n uniformState.viewRotation3D,\n position,\n uniformState._sunDirectionEC\n );\n Cartesian3.normalize(position, position);\n\n position = Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame(\n frameState.time,\n uniformState._moonDirectionEC\n );\n Matrix3.multiplyByVector(transformMatrix, position, position);\n Matrix3.multiplyByVector(uniformState.viewRotation3D, position, position);\n Cartesian3.normalize(position, position);\n\n const projection = frameState.mapProjection;\n const ellipsoid = projection.ellipsoid;\n const sunCartographic = ellipsoid.cartesianToCartographic(\n uniformState._sunPositionWC,\n sunCartographicScratch\n );\n projection.project(sunCartographic, uniformState._sunPositionColumbusView);\n}\n\n/**\n * Synchronizes the frustum's state with the camera state. This is called\n * by the {@link Scene} when rendering to ensure that automatic GLSL uniforms\n * are set to the right value.\n *\n * @param {object} camera The camera to synchronize with.\n */\nUniformState.prototype.updateCamera = function (camera) {\n setView(this, camera.viewMatrix);\n setInverseView(this, camera.inverseViewMatrix);\n setCamera(this, camera);\n\n this._entireFrustum.x = camera.frustum.near;\n this._entireFrustum.y = camera.frustum.far;\n this.updateFrustum(camera.frustum);\n\n this._orthographicIn3D =\n this._mode !== SceneMode.SCENE2D &&\n camera.frustum instanceof OrthographicFrustum;\n};\n\n/**\n * Synchronizes the frustum's state with the uniform state. This is called\n * by the {@link Scene} when rendering to ensure that automatic GLSL uniforms\n * are set to the right value.\n *\n * @param {object} frustum The frustum to synchronize with.\n */\nUniformState.prototype.updateFrustum = function (frustum) {\n setProjection(this, frustum.projectionMatrix);\n if (defined(frustum.infiniteProjectionMatrix)) {\n setInfiniteProjection(this, frustum.infiniteProjectionMatrix);\n }\n this._currentFrustum.x = frustum.near;\n this._currentFrustum.y = frustum.far;\n\n this._farDepthFromNearPlusOne = frustum.far - frustum.near + 1.0;\n this._log2FarDepthFromNearPlusOne = CesiumMath.log2(\n this._farDepthFromNearPlusOne\n );\n this._oneOverLog2FarDepthFromNearPlusOne =\n 1.0 / this._log2FarDepthFromNearPlusOne;\n\n const offCenterFrustum = frustum.offCenterFrustum;\n if (defined(offCenterFrustum)) {\n frustum = offCenterFrustum;\n }\n\n this._frustumPlanes.x = frustum.top;\n this._frustumPlanes.y = frustum.bottom;\n this._frustumPlanes.z = frustum.left;\n this._frustumPlanes.w = frustum.right;\n};\n\nUniformState.prototype.updatePass = function (pass) {\n this._pass = pass;\n};\n\nconst EMPTY_ARRAY = [];\nconst defaultLight = new SunLight();\n\n/**\n * Synchronizes frame state with the uniform state. This is called\n * by the {@link Scene} when rendering to ensure that automatic GLSL uniforms\n * are set to the right value.\n *\n * @param {FrameState} frameState The frameState to synchronize with.\n */\nUniformState.prototype.update = function (frameState) {\n this._mode = frameState.mode;\n this._mapProjection = frameState.mapProjection;\n this._ellipsoid = frameState.mapProjection.ellipsoid;\n this._pixelRatio = frameState.pixelRatio;\n\n const camera = frameState.camera;\n this.updateCamera(camera);\n\n if (frameState.mode === SceneMode.SCENE2D) {\n this._frustum2DWidth = camera.frustum.right - camera.frustum.left;\n this._eyeHeight2D.x = this._frustum2DWidth * 0.5;\n this._eyeHeight2D.y = this._eyeHeight2D.x * this._eyeHeight2D.x;\n } else {\n this._frustum2DWidth = 0.0;\n this._eyeHeight2D.x = 0.0;\n this._eyeHeight2D.y = 0.0;\n }\n\n setSunAndMoonDirections(this, frameState);\n\n const light = defaultValue(frameState.light, defaultLight);\n if (light instanceof SunLight) {\n this._lightDirectionWC = Cartesian3.clone(\n this._sunDirectionWC,\n this._lightDirectionWC\n );\n this._lightDirectionEC = Cartesian3.clone(\n this._sunDirectionEC,\n this._lightDirectionEC\n );\n } else {\n this._lightDirectionWC = Cartesian3.normalize(\n Cartesian3.negate(light.direction, this._lightDirectionWC),\n this._lightDirectionWC\n );\n this._lightDirectionEC = Matrix3.multiplyByVector(\n this.viewRotation3D,\n this._lightDirectionWC,\n this._lightDirectionEC\n );\n }\n\n const lightColor = light.color;\n let lightColorHdr = Cartesian3.fromElements(\n lightColor.red,\n lightColor.green,\n lightColor.blue,\n this._lightColorHdr\n );\n lightColorHdr = Cartesian3.multiplyByScalar(\n lightColorHdr,\n light.intensity,\n lightColorHdr\n );\n const maximumComponent = Cartesian3.maximumComponent(lightColorHdr);\n if (maximumComponent > 1.0) {\n Cartesian3.divideByScalar(\n lightColorHdr,\n maximumComponent,\n this._lightColor\n );\n } else {\n Cartesian3.clone(lightColorHdr, this._lightColor);\n }\n\n const brdfLutGenerator = frameState.brdfLutGenerator;\n const brdfLut = defined(brdfLutGenerator)\n ? brdfLutGenerator.colorTexture\n : undefined;\n this._brdfLut = brdfLut;\n\n this._environmentMap = defaultValue(\n frameState.environmentMap,\n frameState.context.defaultCubeMap\n );\n\n // IE 11 doesn't optimize out uniforms that are #ifdef'd out. So undefined values for the spherical harmonic\n // coefficients and specular environment map atlas dimensions cause a crash.\n this._sphericalHarmonicCoefficients = defaultValue(\n frameState.sphericalHarmonicCoefficients,\n EMPTY_ARRAY\n );\n this._specularEnvironmentMaps = frameState.specularEnvironmentMaps;\n this._specularEnvironmentMapsMaximumLOD =\n frameState.specularEnvironmentMapsMaximumLOD;\n\n if (defined(this._specularEnvironmentMaps)) {\n Cartesian2.clone(\n this._specularEnvironmentMaps.dimensions,\n this._specularEnvironmentMapsDimensions\n );\n }\n\n this._fogDensity = frameState.fog.density;\n\n this._invertClassificationColor = frameState.invertClassificationColor;\n\n this._frameState = frameState;\n this._temeToPseudoFixed = Transforms.computeTemeToPseudoFixedMatrix(\n frameState.time,\n this._temeToPseudoFixed\n );\n\n // Convert the relative splitPosition to absolute pixel coordinates\n this._splitPosition =\n frameState.splitPosition * frameState.context.drawingBufferWidth;\n const fov = camera.frustum.fov;\n const viewport = this._viewport;\n let pixelSizePerMeter;\n if (defined(fov)) {\n if (viewport.height > viewport.width) {\n pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.height;\n } else {\n pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.width;\n }\n } else {\n pixelSizePerMeter = 1.0 / Math.max(viewport.width, viewport.height);\n }\n\n this._geometricToleranceOverMeter =\n pixelSizePerMeter * frameState.maximumScreenSpaceError;\n Color.clone(frameState.backgroundColor, this._backgroundColor);\n\n this._minimumDisableDepthTestDistance =\n frameState.minimumDisableDepthTestDistance;\n this._minimumDisableDepthTestDistance *= this._minimumDisableDepthTestDistance;\n if (this._minimumDisableDepthTestDistance === Number.POSITIVE_INFINITY) {\n this._minimumDisableDepthTestDistance = -1.0;\n }\n};\n\nfunction cleanViewport(uniformState) {\n if (uniformState._viewportDirty) {\n const v = uniformState._viewport;\n Matrix4.computeOrthographicOffCenter(\n v.x,\n v.x + v.width,\n v.y,\n v.y + v.height,\n 0.0,\n 1.0,\n uniformState._viewportOrthographicMatrix\n );\n Matrix4.computeViewportTransformation(\n v,\n 0.0,\n 1.0,\n uniformState._viewportTransformation\n );\n uniformState._viewportDirty = false;\n }\n}\n\nfunction cleanInverseProjection(uniformState) {\n if (uniformState._inverseProjectionDirty) {\n uniformState._inverseProjectionDirty = false;\n\n if (\n uniformState._mode !== SceneMode.SCENE2D &&\n uniformState._mode !== SceneMode.MORPHING &&\n !uniformState._orthographicIn3D\n ) {\n Matrix4.inverse(\n uniformState._projection,\n uniformState._inverseProjection\n );\n } else {\n Matrix4.clone(Matrix4.ZERO, uniformState._inverseProjection);\n }\n }\n}\n\n// Derived\nfunction cleanModelView(uniformState) {\n if (uniformState._modelViewDirty) {\n uniformState._modelViewDirty = false;\n\n Matrix4.multiplyTransformation(\n uniformState._view,\n uniformState._model,\n uniformState._modelView\n );\n }\n}\n\nfunction cleanModelView3D(uniformState) {\n if (uniformState._modelView3DDirty) {\n uniformState._modelView3DDirty = false;\n\n Matrix4.multiplyTransformation(\n uniformState.view3D,\n uniformState._model,\n uniformState._modelView3D\n );\n }\n}\n\nfunction cleanInverseModelView(uniformState) {\n if (uniformState._inverseModelViewDirty) {\n uniformState._inverseModelViewDirty = false;\n\n Matrix4.inverse(uniformState.modelView, uniformState._inverseModelView);\n }\n}\n\nfunction cleanInverseModelView3D(uniformState) {\n if (uniformState._inverseModelView3DDirty) {\n uniformState._inverseModelView3DDirty = false;\n\n Matrix4.inverse(uniformState.modelView3D, uniformState._inverseModelView3D);\n }\n}\n\nfunction cleanViewProjection(uniformState) {\n if (uniformState._viewProjectionDirty) {\n uniformState._viewProjectionDirty = false;\n\n Matrix4.multiply(\n uniformState._projection,\n uniformState._view,\n uniformState._viewProjection\n );\n }\n}\n\nfunction cleanInverseViewProjection(uniformState) {\n if (uniformState._inverseViewProjectionDirty) {\n uniformState._inverseViewProjectionDirty = false;\n\n Matrix4.inverse(\n uniformState.viewProjection,\n uniformState._inverseViewProjection\n );\n }\n}\n\nfunction cleanModelViewProjection(uniformState) {\n if (uniformState._modelViewProjectionDirty) {\n uniformState._modelViewProjectionDirty = false;\n\n Matrix4.multiply(\n uniformState._projection,\n uniformState.modelView,\n uniformState._modelViewProjection\n );\n }\n}\n\nfunction cleanModelViewRelativeToEye(uniformState) {\n if (uniformState._modelViewRelativeToEyeDirty) {\n uniformState._modelViewRelativeToEyeDirty = false;\n\n const mv = uniformState.modelView;\n const mvRte = uniformState._modelViewRelativeToEye;\n mvRte[0] = mv[0];\n mvRte[1] = mv[1];\n mvRte[2] = mv[2];\n mvRte[3] = mv[3];\n mvRte[4] = mv[4];\n mvRte[5] = mv[5];\n mvRte[6] = mv[6];\n mvRte[7] = mv[7];\n mvRte[8] = mv[8];\n mvRte[9] = mv[9];\n mvRte[10] = mv[10];\n mvRte[11] = mv[11];\n mvRte[12] = 0.0;\n mvRte[13] = 0.0;\n mvRte[14] = 0.0;\n mvRte[15] = mv[15];\n }\n}\n\nfunction cleanInverseModelViewProjection(uniformState) {\n if (uniformState._inverseModelViewProjectionDirty) {\n uniformState._inverseModelViewProjectionDirty = false;\n\n Matrix4.inverse(\n uniformState.modelViewProjection,\n uniformState._inverseModelViewProjection\n );\n }\n}\n\nfunction cleanModelViewProjectionRelativeToEye(uniformState) {\n if (uniformState._modelViewProjectionRelativeToEyeDirty) {\n uniformState._modelViewProjectionRelativeToEyeDirty = false;\n\n Matrix4.multiply(\n uniformState._projection,\n uniformState.modelViewRelativeToEye,\n uniformState._modelViewProjectionRelativeToEye\n );\n }\n}\n\nfunction cleanModelViewInfiniteProjection(uniformState) {\n if (uniformState._modelViewInfiniteProjectionDirty) {\n uniformState._modelViewInfiniteProjectionDirty = false;\n\n Matrix4.multiply(\n uniformState._infiniteProjection,\n uniformState.modelView,\n uniformState._modelViewInfiniteProjection\n );\n }\n}\n\nfunction cleanNormal(uniformState) {\n if (uniformState._normalDirty) {\n uniformState._normalDirty = false;\n\n const m = uniformState._normal;\n Matrix4.getMatrix3(uniformState.inverseModelView, m);\n Matrix3.getRotation(m, m);\n Matrix3.transpose(m, m);\n }\n}\n\nfunction cleanNormal3D(uniformState) {\n if (uniformState._normal3DDirty) {\n uniformState._normal3DDirty = false;\n\n const m = uniformState._normal3D;\n Matrix4.getMatrix3(uniformState.inverseModelView3D, m);\n Matrix3.getRotation(m, m);\n Matrix3.transpose(m, m);\n }\n}\n\nfunction cleanInverseNormal(uniformState) {\n if (uniformState._inverseNormalDirty) {\n uniformState._inverseNormalDirty = false;\n Matrix4.getMatrix3(\n uniformState.inverseModelView,\n uniformState._inverseNormal\n );\n Matrix3.getRotation(\n uniformState._inverseNormal,\n uniformState._inverseNormal\n );\n }\n}\n\nfunction cleanInverseNormal3D(uniformState) {\n if (uniformState._inverseNormal3DDirty) {\n uniformState._inverseNormal3DDirty = false;\n Matrix4.getMatrix3(\n uniformState.inverseModelView3D,\n uniformState._inverseNormal3D\n );\n Matrix3.getRotation(\n uniformState._inverseNormal3D,\n uniformState._inverseNormal3D\n );\n }\n}\n\nconst cameraPositionMC = new Cartesian3();\n\nfunction cleanEncodedCameraPositionMC(uniformState) {\n if (uniformState._encodedCameraPositionMCDirty) {\n uniformState._encodedCameraPositionMCDirty = false;\n\n Matrix4.multiplyByPoint(\n uniformState.inverseModel,\n uniformState._cameraPosition,\n cameraPositionMC\n );\n EncodedCartesian3.fromCartesian(\n cameraPositionMC,\n uniformState._encodedCameraPositionMC\n );\n }\n}\n\nconst view2Dto3DPScratch = new Cartesian3();\nconst view2Dto3DRScratch = new Cartesian3();\nconst view2Dto3DUScratch = new Cartesian3();\nconst view2Dto3DDScratch = new Cartesian3();\nconst view2Dto3DCartographicScratch = new Cartographic();\nconst view2Dto3DCartesian3Scratch = new Cartesian3();\nconst view2Dto3DMatrix4Scratch = new Matrix4();\n\nfunction view2Dto3D(\n position2D,\n direction2D,\n right2D,\n up2D,\n frustum2DWidth,\n mode,\n projection,\n result\n) {\n // The camera position and directions are expressed in the 2D coordinate system where the Y axis is to the East,\n // the Z axis is to the North, and the X axis is out of the map. Express them instead in the ENU axes where\n // X is to the East, Y is to the North, and Z is out of the local horizontal plane.\n const p = view2Dto3DPScratch;\n p.x = position2D.y;\n p.y = position2D.z;\n p.z = position2D.x;\n\n const r = view2Dto3DRScratch;\n r.x = right2D.y;\n r.y = right2D.z;\n r.z = right2D.x;\n\n const u = view2Dto3DUScratch;\n u.x = up2D.y;\n u.y = up2D.z;\n u.z = up2D.x;\n\n const d = view2Dto3DDScratch;\n d.x = direction2D.y;\n d.y = direction2D.z;\n d.z = direction2D.x;\n\n // In 2D, the camera height is always 12.7 million meters.\n // The apparent height is equal to half the frustum width.\n if (mode === SceneMode.SCENE2D) {\n p.z = frustum2DWidth * 0.5;\n }\n\n // Compute the equivalent camera position in the real (3D) world.\n // In 2D and Columbus View, the camera can travel outside the projection, and when it does so\n // there's not really any corresponding location in the real world. So clamp the unprojected\n // longitude and latitude to their valid ranges.\n const cartographic = projection.unproject(p, view2Dto3DCartographicScratch);\n cartographic.longitude = CesiumMath.clamp(\n cartographic.longitude,\n -Math.PI,\n Math.PI\n );\n cartographic.latitude = CesiumMath.clamp(\n cartographic.latitude,\n -CesiumMath.PI_OVER_TWO,\n CesiumMath.PI_OVER_TWO\n );\n const ellipsoid = projection.ellipsoid;\n const position3D = ellipsoid.cartographicToCartesian(\n cartographic,\n view2Dto3DCartesian3Scratch\n );\n\n // Compute the rotation from the local ENU at the real world camera position to the fixed axes.\n const enuToFixed = Transforms.eastNorthUpToFixedFrame(\n position3D,\n ellipsoid,\n view2Dto3DMatrix4Scratch\n );\n\n // Transform each camera direction to the fixed axes.\n Matrix4.multiplyByPointAsVector(enuToFixed, r, r);\n Matrix4.multiplyByPointAsVector(enuToFixed, u, u);\n Matrix4.multiplyByPointAsVector(enuToFixed, d, d);\n\n // Compute the view matrix based on the new fixed-frame camera position and directions.\n if (!defined(result)) {\n result = new Matrix4();\n }\n\n result[0] = r.x;\n result[1] = u.x;\n result[2] = -d.x;\n result[3] = 0.0;\n result[4] = r.y;\n result[5] = u.y;\n result[6] = -d.y;\n result[7] = 0.0;\n result[8] = r.z;\n result[9] = u.z;\n result[10] = -d.z;\n result[11] = 0.0;\n result[12] = -Cartesian3.dot(r, position3D);\n result[13] = -Cartesian3.dot(u, position3D);\n result[14] = Cartesian3.dot(d, position3D);\n result[15] = 1.0;\n\n return result;\n}\n\nfunction updateView3D(that) {\n if (that._view3DDirty) {\n if (that._mode === SceneMode.SCENE3D) {\n Matrix4.clone(that._view, that._view3D);\n } else {\n view2Dto3D(\n that._cameraPosition,\n that._cameraDirection,\n that._cameraRight,\n that._cameraUp,\n that._frustum2DWidth,\n that._mode,\n that._mapProjection,\n that._view3D\n );\n }\n Matrix4.getMatrix3(that._view3D, that._viewRotation3D);\n that._view3DDirty = false;\n }\n}\n\nfunction updateInverseView3D(that) {\n if (that._inverseView3DDirty) {\n Matrix4.inverseTransformation(that.view3D, that._inverseView3D);\n Matrix4.getMatrix3(that._inverseView3D, that._inverseViewRotation3D);\n that._inverseView3DDirty = false;\n }\n}\nexport default UniformState;\n", "import Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Geometry from \"../Core/Geometry.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Buffer from \"./Buffer.js\";\nimport BufferUsage from \"./BufferUsage.js\";\nimport ContextLimits from \"./ContextLimits.js\";\n\nfunction addAttribute(attributes, attribute, index, context) {\n const hasVertexBuffer = defined(attribute.vertexBuffer);\n const hasValue = defined(attribute.value);\n const componentsPerAttribute = attribute.value\n ? attribute.value.length\n : attribute.componentsPerAttribute;\n\n //>>includeStart('debug', pragmas.debug);\n if (!hasVertexBuffer && !hasValue) {\n throw new DeveloperError(\"attribute must have a vertexBuffer or a value.\");\n }\n if (hasVertexBuffer && hasValue) {\n throw new DeveloperError(\n \"attribute cannot have both a vertexBuffer and a value. It must have either a vertexBuffer property defining per-vertex data or a value property defining data for all vertices.\"\n );\n }\n if (\n componentsPerAttribute !== 1 &&\n componentsPerAttribute !== 2 &&\n componentsPerAttribute !== 3 &&\n componentsPerAttribute !== 4\n ) {\n if (hasValue) {\n throw new DeveloperError(\n \"attribute.value.length must be in the range [1, 4].\"\n );\n }\n\n throw new DeveloperError(\n \"attribute.componentsPerAttribute must be in the range [1, 4].\"\n );\n }\n if (\n defined(attribute.componentDatatype) &&\n !ComponentDatatype.validate(attribute.componentDatatype)\n ) {\n throw new DeveloperError(\n \"attribute must have a valid componentDatatype or not specify it.\"\n );\n }\n if (defined(attribute.strideInBytes) && attribute.strideInBytes > 255) {\n // WebGL limit. Not in GL ES.\n throw new DeveloperError(\n \"attribute must have a strideInBytes less than or equal to 255 or not specify it.\"\n );\n }\n if (\n defined(attribute.instanceDivisor) &&\n attribute.instanceDivisor > 0 &&\n !context.instancedArrays\n ) {\n throw new DeveloperError(\"instanced arrays is not supported\");\n }\n if (defined(attribute.instanceDivisor) && attribute.instanceDivisor < 0) {\n throw new DeveloperError(\n \"attribute must have an instanceDivisor greater than or equal to zero\"\n );\n }\n if (defined(attribute.instanceDivisor) && hasValue) {\n throw new DeveloperError(\n \"attribute cannot have have an instanceDivisor if it is not backed by a buffer\"\n );\n }\n if (\n defined(attribute.instanceDivisor) &&\n attribute.instanceDivisor > 0 &&\n attribute.index === 0\n ) {\n throw new DeveloperError(\n \"attribute zero cannot have an instanceDivisor greater than 0\"\n );\n }\n //>>includeEnd('debug');\n\n // Shallow copy the attribute; we do not want to copy the vertex buffer.\n const attr = {\n index: defaultValue(attribute.index, index),\n enabled: defaultValue(attribute.enabled, true),\n vertexBuffer: attribute.vertexBuffer,\n value: hasValue ? attribute.value.slice(0) : undefined,\n componentsPerAttribute: componentsPerAttribute,\n componentDatatype: defaultValue(\n attribute.componentDatatype,\n ComponentDatatype.FLOAT\n ),\n normalize: defaultValue(attribute.normalize, false),\n offsetInBytes: defaultValue(attribute.offsetInBytes, 0),\n strideInBytes: defaultValue(attribute.strideInBytes, 0),\n instanceDivisor: defaultValue(attribute.instanceDivisor, 0),\n };\n\n if (hasVertexBuffer) {\n // Common case: vertex buffer for per-vertex data\n attr.vertexAttrib = function (gl) {\n const index = this.index;\n gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer._getBuffer());\n gl.vertexAttribPointer(\n index,\n this.componentsPerAttribute,\n this.componentDatatype,\n this.normalize,\n this.strideInBytes,\n this.offsetInBytes\n );\n gl.enableVertexAttribArray(index);\n if (this.instanceDivisor > 0) {\n context.glVertexAttribDivisor(index, this.instanceDivisor);\n context._vertexAttribDivisors[index] = this.instanceDivisor;\n context._previousDrawInstanced = true;\n }\n };\n\n attr.disableVertexAttribArray = function (gl) {\n gl.disableVertexAttribArray(this.index);\n if (this.instanceDivisor > 0) {\n context.glVertexAttribDivisor(index, 0);\n }\n };\n } else {\n // Less common case: value array for the same data for each vertex\n switch (attr.componentsPerAttribute) {\n case 1:\n attr.vertexAttrib = function (gl) {\n gl.vertexAttrib1fv(this.index, this.value);\n };\n break;\n case 2:\n attr.vertexAttrib = function (gl) {\n gl.vertexAttrib2fv(this.index, this.value);\n };\n break;\n case 3:\n attr.vertexAttrib = function (gl) {\n gl.vertexAttrib3fv(this.index, this.value);\n };\n break;\n case 4:\n attr.vertexAttrib = function (gl) {\n gl.vertexAttrib4fv(this.index, this.value);\n };\n break;\n }\n\n attr.disableVertexAttribArray = function (gl) {};\n }\n\n attributes.push(attr);\n}\n\nfunction bind(gl, attributes, indexBuffer) {\n for (let i = 0; i < attributes.length; ++i) {\n const attribute = attributes[i];\n if (attribute.enabled) {\n attribute.vertexAttrib(gl);\n }\n }\n\n if (defined(indexBuffer)) {\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer._getBuffer());\n }\n}\n\n/**\n * Creates a vertex array, which defines the attributes making up a vertex, and contains an optional index buffer\n * to select vertices for rendering. Attributes are defined using object literals as shown in Example 1 below.\n *\n * @param {object} options Object with the following properties:\n * @param {Context} options.context The context in which the VertexArray gets created.\n * @param {Object[]} options.attributes An array of attributes.\n * @param {IndexBuffer} [options.indexBuffer] An optional index buffer.\n *\n * @returns {VertexArray} The vertex array, ready for use with drawing.\n *\n * @exception {DeveloperError} Attribute must have a vertexBuffer.\n * @exception {DeveloperError} Attribute must have a componentsPerAttribute.\n * @exception {DeveloperError} Attribute must have a valid componentDatatype or not specify it.\n * @exception {DeveloperError} Attribute must have a strideInBytes less than or equal to 255 or not specify it.\n * @exception {DeveloperError} Index n is used by more than one attribute.\n *\n *\n * @example\n * // Example 1. Create a vertex array with vertices made up of three floating point\n * // values, e.g., a position, from a single vertex buffer. No index buffer is used.\n * const positionBuffer = Buffer.createVertexBuffer({\n * context : context,\n * sizeInBytes : 12,\n * usage : BufferUsage.STATIC_DRAW\n * });\n * const attributes = [\n * {\n * index : 0,\n * enabled : true,\n * vertexBuffer : positionBuffer,\n * componentsPerAttribute : 3,\n * componentDatatype : ComponentDatatype.FLOAT,\n * normalize : false,\n * offsetInBytes : 0,\n * strideInBytes : 0 // tightly packed\n * instanceDivisor : 0 // not instanced\n * }\n * ];\n * const va = new VertexArray({\n * context : context,\n * attributes : attributes\n * });\n *\n * @example\n * // Example 2. Create a vertex array with vertices from two different vertex buffers.\n * // Each vertex has a three-component position and three-component normal.\n * const positionBuffer = Buffer.createVertexBuffer({\n * context : context,\n * sizeInBytes : 12,\n * usage : BufferUsage.STATIC_DRAW\n * });\n * const normalBuffer = Buffer.createVertexBuffer({\n * context : context,\n * sizeInBytes : 12,\n * usage : BufferUsage.STATIC_DRAW\n * });\n * const attributes = [\n * {\n * index : 0,\n * vertexBuffer : positionBuffer,\n * componentsPerAttribute : 3,\n * componentDatatype : ComponentDatatype.FLOAT\n * },\n * {\n * index : 1,\n * vertexBuffer : normalBuffer,\n * componentsPerAttribute : 3,\n * componentDatatype : ComponentDatatype.FLOAT\n * }\n * ];\n * const va = new VertexArray({\n * context : context,\n * attributes : attributes\n * });\n *\n * @example\n * // Example 3. Creates the same vertex layout as Example 2 using a single\n * // vertex buffer, instead of two.\n * const buffer = Buffer.createVertexBuffer({\n * context : context,\n * sizeInBytes : 24,\n * usage : BufferUsage.STATIC_DRAW\n * });\n * const attributes = [\n * {\n * vertexBuffer : buffer,\n * componentsPerAttribute : 3,\n * componentDatatype : ComponentDatatype.FLOAT,\n * offsetInBytes : 0,\n * strideInBytes : 24\n * },\n * {\n * vertexBuffer : buffer,\n * componentsPerAttribute : 3,\n * componentDatatype : ComponentDatatype.FLOAT,\n * normalize : true,\n * offsetInBytes : 12,\n * strideInBytes : 24\n * }\n * ];\n * const va = new VertexArray({\n * context : context,\n * attributes : attributes\n * });\n *\n * @see Buffer#createVertexBuffer\n * @see Buffer#createIndexBuffer\n * @see Context#draw\n *\n * @private\n */\nfunction VertexArray(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n Check.defined(\"options.attributes\", options.attributes);\n //>>includeEnd('debug');\n\n const context = options.context;\n const gl = context._gl;\n const attributes = options.attributes;\n const indexBuffer = options.indexBuffer;\n\n let i;\n const vaAttributes = [];\n let numberOfVertices = 1; // if every attribute is backed by a single value\n let hasInstancedAttributes = false;\n let hasConstantAttributes = false;\n\n let length = attributes.length;\n for (i = 0; i < length; ++i) {\n addAttribute(vaAttributes, attributes[i], i, context);\n }\n\n length = vaAttributes.length;\n for (i = 0; i < length; ++i) {\n const attribute = vaAttributes[i];\n\n if (defined(attribute.vertexBuffer) && attribute.instanceDivisor === 0) {\n // This assumes that each vertex buffer in the vertex array has the same number of vertices.\n const bytes =\n attribute.strideInBytes ||\n attribute.componentsPerAttribute *\n ComponentDatatype.getSizeInBytes(attribute.componentDatatype);\n numberOfVertices = attribute.vertexBuffer.sizeInBytes / bytes;\n break;\n }\n }\n\n for (i = 0; i < length; ++i) {\n if (vaAttributes[i].instanceDivisor > 0) {\n hasInstancedAttributes = true;\n }\n if (defined(vaAttributes[i].value)) {\n hasConstantAttributes = true;\n }\n }\n\n //>>includeStart('debug', pragmas.debug);\n // Verify all attribute names are unique\n const uniqueIndices = {};\n for (i = 0; i < length; ++i) {\n const index = vaAttributes[i].index;\n if (uniqueIndices[index]) {\n throw new DeveloperError(\n `Index ${index} is used by more than one attribute.`\n );\n }\n uniqueIndices[index] = true;\n }\n //>>includeEnd('debug');\n\n let vao;\n\n // Setup VAO if supported\n if (context.vertexArrayObject) {\n vao = context.glCreateVertexArray();\n context.glBindVertexArray(vao);\n bind(gl, vaAttributes, indexBuffer);\n context.glBindVertexArray(null);\n }\n\n this._numberOfVertices = numberOfVertices;\n this._hasInstancedAttributes = hasInstancedAttributes;\n this._hasConstantAttributes = hasConstantAttributes;\n this._context = context;\n this._gl = gl;\n this._vao = vao;\n this._attributes = vaAttributes;\n this._indexBuffer = indexBuffer;\n}\n\nfunction computeNumberOfVertices(attribute) {\n return attribute.values.length / attribute.componentsPerAttribute;\n}\n\nfunction computeAttributeSizeInBytes(attribute) {\n return (\n ComponentDatatype.getSizeInBytes(attribute.componentDatatype) *\n attribute.componentsPerAttribute\n );\n}\n\nfunction interleaveAttributes(attributes) {\n let j;\n let name;\n let attribute;\n\n // Extract attribute names.\n const names = [];\n for (name in attributes) {\n // Attribute needs to have per-vertex values; not a constant value for all vertices.\n if (\n attributes.hasOwnProperty(name) &&\n defined(attributes[name]) &&\n defined(attributes[name].values)\n ) {\n names.push(name);\n\n if (attributes[name].componentDatatype === ComponentDatatype.DOUBLE) {\n attributes[name].componentDatatype = ComponentDatatype.FLOAT;\n attributes[name].values = ComponentDatatype.createTypedArray(\n ComponentDatatype.FLOAT,\n attributes[name].values\n );\n }\n }\n }\n\n // Validation. Compute number of vertices.\n let numberOfVertices;\n const namesLength = names.length;\n\n if (namesLength > 0) {\n numberOfVertices = computeNumberOfVertices(attributes[names[0]]);\n\n for (j = 1; j < namesLength; ++j) {\n const currentNumberOfVertices = computeNumberOfVertices(\n attributes[names[j]]\n );\n\n if (currentNumberOfVertices !== numberOfVertices) {\n throw new RuntimeError(\n `${\n \"Each attribute list must have the same number of vertices. \" +\n \"Attribute \"\n }${names[j]} has a different number of vertices ` +\n `(${currentNumberOfVertices.toString()})` +\n ` than attribute ${names[0]} (${numberOfVertices.toString()}).`\n );\n }\n }\n }\n\n // Sort attributes by the size of their components. From left to right, a vertex stores floats, shorts, and then bytes.\n names.sort(function (left, right) {\n return (\n ComponentDatatype.getSizeInBytes(attributes[right].componentDatatype) -\n ComponentDatatype.getSizeInBytes(attributes[left].componentDatatype)\n );\n });\n\n // Compute sizes and strides.\n let vertexSizeInBytes = 0;\n const offsetsInBytes = {};\n\n for (j = 0; j < namesLength; ++j) {\n name = names[j];\n attribute = attributes[name];\n\n offsetsInBytes[name] = vertexSizeInBytes;\n vertexSizeInBytes += computeAttributeSizeInBytes(attribute);\n }\n\n if (vertexSizeInBytes > 0) {\n // Pad each vertex to be a multiple of the largest component datatype so each\n // attribute can be addressed using typed arrays.\n const maxComponentSizeInBytes = ComponentDatatype.getSizeInBytes(\n attributes[names[0]].componentDatatype\n ); // Sorted large to small\n const remainder = vertexSizeInBytes % maxComponentSizeInBytes;\n if (remainder !== 0) {\n vertexSizeInBytes += maxComponentSizeInBytes - remainder;\n }\n\n // Total vertex buffer size in bytes, including per-vertex padding.\n const vertexBufferSizeInBytes = numberOfVertices * vertexSizeInBytes;\n\n // Create array for interleaved vertices. Each attribute has a different view (pointer) into the array.\n const buffer = new ArrayBuffer(vertexBufferSizeInBytes);\n const views = {};\n\n for (j = 0; j < namesLength; ++j) {\n name = names[j];\n const sizeInBytes = ComponentDatatype.getSizeInBytes(\n attributes[name].componentDatatype\n );\n\n views[name] = {\n pointer: ComponentDatatype.createTypedArray(\n attributes[name].componentDatatype,\n buffer\n ),\n index: offsetsInBytes[name] / sizeInBytes, // Offset in ComponentType\n strideInComponentType: vertexSizeInBytes / sizeInBytes,\n };\n }\n\n // Copy attributes into one interleaved array.\n // PERFORMANCE_IDEA: Can we optimize these loops?\n for (j = 0; j < numberOfVertices; ++j) {\n for (let n = 0; n < namesLength; ++n) {\n name = names[n];\n attribute = attributes[name];\n const values = attribute.values;\n const view = views[name];\n const pointer = view.pointer;\n\n const numberOfComponents = attribute.componentsPerAttribute;\n for (let k = 0; k < numberOfComponents; ++k) {\n pointer[view.index + k] = values[j * numberOfComponents + k];\n }\n\n view.index += view.strideInComponentType;\n }\n }\n\n return {\n buffer: buffer,\n offsetsInBytes: offsetsInBytes,\n vertexSizeInBytes: vertexSizeInBytes,\n };\n }\n\n // No attributes to interleave.\n return undefined;\n}\n\n/**\n * Creates a vertex array from a geometry. A geometry contains vertex attributes and optional index data\n * in system memory, whereas a vertex array contains vertex buffers and an optional index buffer in WebGL\n * memory for use with rendering.\n *

\n * The geometry argument should use the standard layout like the geometry returned by {@link BoxGeometry}.\n *

\n * options can have four properties:\n *
    \n *
  • geometry: The source geometry containing data used to create the vertex array.
  • \n *
  • attributeLocations: An object that maps geometry attribute names to vertex shader attribute locations.
  • \n *
  • bufferUsage: The expected usage pattern of the vertex array's buffers. On some WebGL implementations, this can significantly affect performance. See {@link BufferUsage}. Default: BufferUsage.DYNAMIC_DRAW.
  • \n *
  • interleave: Determines if all attributes are interleaved in a single vertex buffer or if each attribute is stored in a separate vertex buffer. Default: false.
  • \n *
\n *
\n * If options is not specified or the geometry contains no data, the returned vertex array is empty.\n *\n * @param {object} options An object defining the geometry, attribute indices, buffer usage, and vertex layout used to create the vertex array.\n *\n * @exception {RuntimeError} Each attribute list must have the same number of vertices.\n * @exception {DeveloperError} The geometry must have zero or one index lists.\n * @exception {DeveloperError} Index n is used by more than one attribute.\n *\n *\n * @example\n * // Example 1. Creates a vertex array for rendering a box. The default dynamic draw\n * // usage is used for the created vertex and index buffer. The attributes are not\n * // interleaved by default.\n * const geometry = new BoxGeometry();\n * const va = VertexArray.fromGeometry({\n * context : context,\n * geometry : geometry,\n * attributeLocations : GeometryPipeline.createAttributeLocations(geometry),\n * });\n *\n * @example\n * // Example 2. Creates a vertex array with interleaved attributes in a\n * // single vertex buffer. The vertex and index buffer have static draw usage.\n * const va = VertexArray.fromGeometry({\n * context : context,\n * geometry : geometry,\n * attributeLocations : GeometryPipeline.createAttributeLocations(geometry),\n * bufferUsage : BufferUsage.STATIC_DRAW,\n * interleave : true\n * });\n *\n * @example\n * // Example 3. When the caller destroys the vertex array, it also destroys the\n * // attached vertex buffer(s) and index buffer.\n * va = va.destroy();\n *\n * @see Buffer#createVertexBuffer\n * @see Buffer#createIndexBuffer\n * @see GeometryPipeline.createAttributeLocations\n * @see ShaderProgram\n */\nVertexArray.fromGeometry = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n const context = options.context;\n const geometry = defaultValue(options.geometry, defaultValue.EMPTY_OBJECT);\n\n const bufferUsage = defaultValue(\n options.bufferUsage,\n BufferUsage.DYNAMIC_DRAW\n );\n\n const attributeLocations = defaultValue(\n options.attributeLocations,\n defaultValue.EMPTY_OBJECT\n );\n const interleave = defaultValue(options.interleave, false);\n const createdVAAttributes = options.vertexArrayAttributes;\n\n let name;\n let attribute;\n let vertexBuffer;\n const vaAttributes = defined(createdVAAttributes) ? createdVAAttributes : [];\n const attributes = geometry.attributes;\n\n if (interleave) {\n // Use a single vertex buffer with interleaved vertices.\n const interleavedAttributes = interleaveAttributes(attributes);\n if (defined(interleavedAttributes)) {\n vertexBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: interleavedAttributes.buffer,\n usage: bufferUsage,\n });\n const offsetsInBytes = interleavedAttributes.offsetsInBytes;\n const strideInBytes = interleavedAttributes.vertexSizeInBytes;\n\n for (name in attributes) {\n if (attributes.hasOwnProperty(name) && defined(attributes[name])) {\n attribute = attributes[name];\n\n if (defined(attribute.values)) {\n // Common case: per-vertex attributes\n vaAttributes.push({\n index: attributeLocations[name],\n vertexBuffer: vertexBuffer,\n componentDatatype: attribute.componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n offsetInBytes: offsetsInBytes[name],\n strideInBytes: strideInBytes,\n });\n } else {\n // Constant attribute for all vertices\n vaAttributes.push({\n index: attributeLocations[name],\n value: attribute.value,\n componentDatatype: attribute.componentDatatype,\n normalize: attribute.normalize,\n });\n }\n }\n }\n }\n } else {\n // One vertex buffer per attribute.\n for (name in attributes) {\n if (attributes.hasOwnProperty(name) && defined(attributes[name])) {\n attribute = attributes[name];\n\n let componentDatatype = attribute.componentDatatype;\n if (componentDatatype === ComponentDatatype.DOUBLE) {\n componentDatatype = ComponentDatatype.FLOAT;\n }\n\n vertexBuffer = undefined;\n if (defined(attribute.values)) {\n vertexBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: ComponentDatatype.createTypedArray(\n componentDatatype,\n attribute.values\n ),\n usage: bufferUsage,\n });\n }\n\n vaAttributes.push({\n index: attributeLocations[name],\n vertexBuffer: vertexBuffer,\n value: attribute.value,\n componentDatatype: componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n });\n }\n }\n }\n\n let indexBuffer;\n const indices = geometry.indices;\n if (defined(indices)) {\n if (\n Geometry.computeNumberOfVertices(geometry) >=\n CesiumMath.SIXTY_FOUR_KILOBYTES &&\n context.elementIndexUint\n ) {\n indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: new Uint32Array(indices),\n usage: bufferUsage,\n indexDatatype: IndexDatatype.UNSIGNED_INT,\n });\n } else {\n indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: new Uint16Array(indices),\n usage: bufferUsage,\n indexDatatype: IndexDatatype.UNSIGNED_SHORT,\n });\n }\n }\n\n return new VertexArray({\n context: context,\n attributes: vaAttributes,\n indexBuffer: indexBuffer,\n });\n};\n\nObject.defineProperties(VertexArray.prototype, {\n numberOfAttributes: {\n get: function () {\n return this._attributes.length;\n },\n },\n numberOfVertices: {\n get: function () {\n return this._numberOfVertices;\n },\n },\n indexBuffer: {\n get: function () {\n return this._indexBuffer;\n },\n },\n});\n\n/**\n * index is the location in the array of attributes, not the index property of an attribute.\n */\nVertexArray.prototype.getAttribute = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"index\", index);\n //>>includeEnd('debug');\n\n return this._attributes[index];\n};\n\n// Workaround for ANGLE, where the attribute divisor seems to be part of the global state instead\n// of the VAO state. This function is called when the vao is bound, and should be removed\n// once the ANGLE issue is resolved. Setting the divisor should normally happen in vertexAttrib and\n// disableVertexAttribArray.\nfunction setVertexAttribDivisor(vertexArray) {\n const context = vertexArray._context;\n const hasInstancedAttributes = vertexArray._hasInstancedAttributes;\n if (!hasInstancedAttributes && !context._previousDrawInstanced) {\n return;\n }\n context._previousDrawInstanced = hasInstancedAttributes;\n\n const divisors = context._vertexAttribDivisors;\n const attributes = vertexArray._attributes;\n const maxAttributes = ContextLimits.maximumVertexAttributes;\n let i;\n\n if (hasInstancedAttributes) {\n const length = attributes.length;\n for (i = 0; i < length; ++i) {\n const attribute = attributes[i];\n if (attribute.enabled) {\n const divisor = attribute.instanceDivisor;\n const index = attribute.index;\n if (divisor !== divisors[index]) {\n context.glVertexAttribDivisor(index, divisor);\n divisors[index] = divisor;\n }\n }\n }\n } else {\n for (i = 0; i < maxAttributes; ++i) {\n if (divisors[i] > 0) {\n context.glVertexAttribDivisor(i, 0);\n divisors[i] = 0;\n }\n }\n }\n}\n\n// Vertex attributes backed by a constant value go through vertexAttrib[1234]f[v]\n// which is part of context state rather than VAO state.\nfunction setConstantAttributes(vertexArray, gl) {\n const attributes = vertexArray._attributes;\n const length = attributes.length;\n for (let i = 0; i < length; ++i) {\n const attribute = attributes[i];\n if (attribute.enabled && defined(attribute.value)) {\n attribute.vertexAttrib(gl);\n }\n }\n}\n\nVertexArray.prototype._bind = function () {\n if (defined(this._vao)) {\n this._context.glBindVertexArray(this._vao);\n if (this._context.instancedArrays) {\n setVertexAttribDivisor(this);\n }\n if (this._hasConstantAttributes) {\n setConstantAttributes(this, this._gl);\n }\n } else {\n bind(this._gl, this._attributes, this._indexBuffer);\n }\n};\n\nVertexArray.prototype._unBind = function () {\n if (defined(this._vao)) {\n this._context.glBindVertexArray(null);\n } else {\n const attributes = this._attributes;\n const gl = this._gl;\n\n for (let i = 0; i < attributes.length; ++i) {\n const attribute = attributes[i];\n if (attribute.enabled) {\n attribute.disableVertexAttribArray(gl);\n }\n }\n if (this._indexBuffer) {\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);\n }\n }\n};\n\nVertexArray.prototype.isDestroyed = function () {\n return false;\n};\n\nVertexArray.prototype.destroy = function () {\n const attributes = this._attributes;\n for (let i = 0; i < attributes.length; ++i) {\n const vertexBuffer = attributes[i].vertexBuffer;\n if (\n defined(vertexBuffer) &&\n !vertexBuffer.isDestroyed() &&\n vertexBuffer.vertexArrayDestroyable\n ) {\n vertexBuffer.destroy();\n }\n }\n\n const indexBuffer = this._indexBuffer;\n if (\n defined(indexBuffer) &&\n !indexBuffer.isDestroyed() &&\n indexBuffer.vertexArrayDestroyable\n ) {\n indexBuffer.destroy();\n }\n\n if (defined(this._vao)) {\n this._context.glDeleteVertexArray(this._vao);\n }\n\n return destroyObject(this);\n};\nexport default VertexArray;\n", "import Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Geometry from \"../Core/Geometry.js\";\nimport GeometryAttribute from \"../Core/GeometryAttribute.js\";\nimport loadKTX2 from \"../Core/loadKTX2.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\nimport ViewportQuadVS from \"../Shaders/ViewportQuadVS.js\";\nimport BufferUsage from \"./BufferUsage.js\";\nimport ClearCommand from \"./ClearCommand.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport CubeMap from \"./CubeMap.js\";\nimport DrawCommand from \"./DrawCommand.js\";\nimport PassState from \"./PassState.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\nimport RenderState from \"./RenderState.js\";\nimport ShaderCache from \"./ShaderCache.js\";\nimport ShaderProgram from \"./ShaderProgram.js\";\nimport Texture from \"./Texture.js\";\nimport TextureCache from \"./TextureCache.js\";\nimport UniformState from \"./UniformState.js\";\nimport VertexArray from \"./VertexArray.js\";\n\n/**\n * @private\n * @constructor\n *\n * @param {HTMLCanvasElement} canvas The canvas element to which the context will be associated\n * @param {ContextOptions} [options] Options to control WebGL settings for the context\n */\nfunction Context(canvas, options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"canvas\", canvas);\n //>>includeEnd('debug');\n\n const {\n getWebGLStub,\n requestWebgl1,\n webgl: webglOptions = {},\n allowTextureFilterAnisotropic = true,\n } = defaultValue(options, {});\n\n // Override select WebGL defaults\n webglOptions.alpha = defaultValue(webglOptions.alpha, false); // WebGL default is true\n webglOptions.stencil = defaultValue(webglOptions.stencil, true); // WebGL default is false\n webglOptions.powerPreference = defaultValue(\n webglOptions.powerPreference,\n \"high-performance\"\n ); // WebGL default is \"default\"\n\n const glContext = defined(getWebGLStub)\n ? getWebGLStub(canvas, webglOptions)\n : getWebGLContext(canvas, webglOptions, requestWebgl1);\n\n // Get context type. instanceof will throw if WebGL2 is not supported\n const webgl2Supported = typeof WebGL2RenderingContext !== \"undefined\";\n const webgl2 = webgl2Supported && glContext instanceof WebGL2RenderingContext;\n\n this._canvas = canvas;\n this._originalGLContext = glContext;\n this._gl = glContext;\n this._webgl2 = webgl2;\n this._id = createGuid();\n\n // Validation and logging disabled by default for speed.\n this.validateFramebuffer = false;\n this.validateShaderProgram = false;\n this.logShaderCompilation = false;\n\n this._throwOnWebGLError = false;\n\n this._shaderCache = new ShaderCache(this);\n this._textureCache = new TextureCache();\n\n const gl = glContext;\n\n this._stencilBits = gl.getParameter(gl.STENCIL_BITS);\n\n ContextLimits._maximumCombinedTextureImageUnits = gl.getParameter(\n gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS\n ); // min: 8\n ContextLimits._maximumCubeMapSize = gl.getParameter(\n gl.MAX_CUBE_MAP_TEXTURE_SIZE\n ); // min: 16\n ContextLimits._maximumFragmentUniformVectors = gl.getParameter(\n gl.MAX_FRAGMENT_UNIFORM_VECTORS\n ); // min: 16\n ContextLimits._maximumTextureImageUnits = gl.getParameter(\n gl.MAX_TEXTURE_IMAGE_UNITS\n ); // min: 8\n ContextLimits._maximumRenderbufferSize = gl.getParameter(\n gl.MAX_RENDERBUFFER_SIZE\n ); // min: 1\n ContextLimits._maximumTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); // min: 64\n ContextLimits._maximumVaryingVectors = gl.getParameter(\n gl.MAX_VARYING_VECTORS\n ); // min: 8\n ContextLimits._maximumVertexAttributes = gl.getParameter(\n gl.MAX_VERTEX_ATTRIBS\n ); // min: 8\n ContextLimits._maximumVertexTextureImageUnits = gl.getParameter(\n gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS\n ); // min: 0\n ContextLimits._maximumVertexUniformVectors = gl.getParameter(\n gl.MAX_VERTEX_UNIFORM_VECTORS\n ); // min: 128\n\n ContextLimits._maximumSamples = this._webgl2\n ? gl.getParameter(gl.MAX_SAMPLES)\n : 0;\n\n const aliasedLineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE); // must include 1\n ContextLimits._minimumAliasedLineWidth = aliasedLineWidthRange[0];\n ContextLimits._maximumAliasedLineWidth = aliasedLineWidthRange[1];\n\n const aliasedPointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE); // must include 1\n ContextLimits._minimumAliasedPointSize = aliasedPointSizeRange[0];\n ContextLimits._maximumAliasedPointSize = aliasedPointSizeRange[1];\n\n const maximumViewportDimensions = gl.getParameter(gl.MAX_VIEWPORT_DIMS);\n ContextLimits._maximumViewportWidth = maximumViewportDimensions[0];\n ContextLimits._maximumViewportHeight = maximumViewportDimensions[1];\n\n const highpFloat = gl.getShaderPrecisionFormat(\n gl.FRAGMENT_SHADER,\n gl.HIGH_FLOAT\n );\n ContextLimits._highpFloatSupported = highpFloat.precision !== 0;\n const highpInt = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_INT);\n ContextLimits._highpIntSupported = highpInt.rangeMax !== 0;\n\n this._antialias = gl.getContextAttributes().antialias;\n\n // Query and initialize extensions\n this._standardDerivatives = !!getExtension(gl, [\"OES_standard_derivatives\"]);\n this._blendMinmax = !!getExtension(gl, [\"EXT_blend_minmax\"]);\n this._elementIndexUint = !!getExtension(gl, [\"OES_element_index_uint\"]);\n this._depthTexture = !!getExtension(gl, [\n \"WEBGL_depth_texture\",\n \"WEBKIT_WEBGL_depth_texture\",\n ]);\n this._fragDepth = !!getExtension(gl, [\"EXT_frag_depth\"]);\n this._debugShaders = getExtension(gl, [\"WEBGL_debug_shaders\"]);\n\n this._textureFloat = !!getExtension(gl, [\"OES_texture_float\"]);\n this._textureHalfFloat = !!getExtension(gl, [\"OES_texture_half_float\"]);\n\n this._textureFloatLinear = !!getExtension(gl, [\"OES_texture_float_linear\"]);\n this._textureHalfFloatLinear = !!getExtension(gl, [\n \"OES_texture_half_float_linear\",\n ]);\n\n this._colorBufferFloat = !!getExtension(gl, [\n \"EXT_color_buffer_float\",\n \"WEBGL_color_buffer_float\",\n ]);\n this._floatBlend = !!getExtension(gl, [\"EXT_float_blend\"]);\n this._colorBufferHalfFloat = !!getExtension(gl, [\n \"EXT_color_buffer_half_float\",\n ]);\n\n this._s3tc = !!getExtension(gl, [\n \"WEBGL_compressed_texture_s3tc\",\n \"MOZ_WEBGL_compressed_texture_s3tc\",\n \"WEBKIT_WEBGL_compressed_texture_s3tc\",\n ]);\n this._pvrtc = !!getExtension(gl, [\n \"WEBGL_compressed_texture_pvrtc\",\n \"WEBKIT_WEBGL_compressed_texture_pvrtc\",\n ]);\n this._astc = !!getExtension(gl, [\"WEBGL_compressed_texture_astc\"]);\n this._etc = !!getExtension(gl, [\"WEBG_compressed_texture_etc\"]);\n this._etc1 = !!getExtension(gl, [\"WEBGL_compressed_texture_etc1\"]);\n this._bc7 = !!getExtension(gl, [\"EXT_texture_compression_bptc\"]);\n\n // It is necessary to pass supported formats to loadKTX2\n // because imagery layers don't have access to the context.\n loadKTX2.setKTX2SupportedFormats(\n this._s3tc,\n this._pvrtc,\n this._astc,\n this._etc,\n this._etc1,\n this._bc7\n );\n\n const textureFilterAnisotropic = allowTextureFilterAnisotropic\n ? getExtension(gl, [\n \"EXT_texture_filter_anisotropic\",\n \"WEBKIT_EXT_texture_filter_anisotropic\",\n ])\n : undefined;\n this._textureFilterAnisotropic = textureFilterAnisotropic;\n ContextLimits._maximumTextureFilterAnisotropy = defined(\n textureFilterAnisotropic\n )\n ? gl.getParameter(textureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT)\n : 1.0;\n\n let glCreateVertexArray;\n let glBindVertexArray;\n let glDeleteVertexArray;\n\n let glDrawElementsInstanced;\n let glDrawArraysInstanced;\n let glVertexAttribDivisor;\n\n let glDrawBuffers;\n\n let vertexArrayObject;\n let instancedArrays;\n let drawBuffers;\n\n if (webgl2) {\n const that = this;\n\n glCreateVertexArray = function () {\n return that._gl.createVertexArray();\n };\n glBindVertexArray = function (vao) {\n that._gl.bindVertexArray(vao);\n };\n glDeleteVertexArray = function (vao) {\n that._gl.deleteVertexArray(vao);\n };\n\n glDrawElementsInstanced = function (\n mode,\n count,\n type,\n offset,\n instanceCount\n ) {\n gl.drawElementsInstanced(mode, count, type, offset, instanceCount);\n };\n glDrawArraysInstanced = function (mode, first, count, instanceCount) {\n gl.drawArraysInstanced(mode, first, count, instanceCount);\n };\n glVertexAttribDivisor = function (index, divisor) {\n gl.vertexAttribDivisor(index, divisor);\n };\n\n glDrawBuffers = function (buffers) {\n gl.drawBuffers(buffers);\n };\n } else {\n vertexArrayObject = getExtension(gl, [\"OES_vertex_array_object\"]);\n if (defined(vertexArrayObject)) {\n glCreateVertexArray = function () {\n return vertexArrayObject.createVertexArrayOES();\n };\n glBindVertexArray = function (vertexArray) {\n vertexArrayObject.bindVertexArrayOES(vertexArray);\n };\n glDeleteVertexArray = function (vertexArray) {\n vertexArrayObject.deleteVertexArrayOES(vertexArray);\n };\n }\n\n instancedArrays = getExtension(gl, [\"ANGLE_instanced_arrays\"]);\n if (defined(instancedArrays)) {\n glDrawElementsInstanced = function (\n mode,\n count,\n type,\n offset,\n instanceCount\n ) {\n instancedArrays.drawElementsInstancedANGLE(\n mode,\n count,\n type,\n offset,\n instanceCount\n );\n };\n glDrawArraysInstanced = function (mode, first, count, instanceCount) {\n instancedArrays.drawArraysInstancedANGLE(\n mode,\n first,\n count,\n instanceCount\n );\n };\n glVertexAttribDivisor = function (index, divisor) {\n instancedArrays.vertexAttribDivisorANGLE(index, divisor);\n };\n }\n\n drawBuffers = getExtension(gl, [\"WEBGL_draw_buffers\"]);\n if (defined(drawBuffers)) {\n glDrawBuffers = function (buffers) {\n drawBuffers.drawBuffersWEBGL(buffers);\n };\n }\n }\n\n this.glCreateVertexArray = glCreateVertexArray;\n this.glBindVertexArray = glBindVertexArray;\n this.glDeleteVertexArray = glDeleteVertexArray;\n\n this.glDrawElementsInstanced = glDrawElementsInstanced;\n this.glDrawArraysInstanced = glDrawArraysInstanced;\n this.glVertexAttribDivisor = glVertexAttribDivisor;\n\n this.glDrawBuffers = glDrawBuffers;\n\n this._vertexArrayObject = !!vertexArrayObject;\n this._instancedArrays = !!instancedArrays;\n this._drawBuffers = !!drawBuffers;\n\n ContextLimits._maximumDrawBuffers = this.drawBuffers\n ? gl.getParameter(WebGLConstants.MAX_DRAW_BUFFERS)\n : 1;\n ContextLimits._maximumColorAttachments = this.drawBuffers\n ? gl.getParameter(WebGLConstants.MAX_COLOR_ATTACHMENTS)\n : 1;\n\n this._clearColor = new Color(0.0, 0.0, 0.0, 0.0);\n this._clearDepth = 1.0;\n this._clearStencil = 0;\n\n const us = new UniformState();\n const ps = new PassState(this);\n const rs = RenderState.fromCache();\n\n this._defaultPassState = ps;\n this._defaultRenderState = rs;\n // default texture has a value of (1, 1, 1)\n // default emissive texture has a value of (0, 0, 0)\n // default normal texture is +z which is encoded as (0.5, 0.5, 1)\n this._defaultTexture = undefined;\n this._defaultEmissiveTexture = undefined;\n this._defaultNormalTexture = undefined;\n this._defaultCubeMap = undefined;\n\n this._us = us;\n this._currentRenderState = rs;\n this._currentPassState = ps;\n this._currentFramebuffer = undefined;\n this._maxFrameTextureUnitIndex = 0;\n\n // Vertex attribute divisor state cache. Workaround for ANGLE (also look at VertexArray.setVertexAttribDivisor)\n this._vertexAttribDivisors = [];\n this._previousDrawInstanced = false;\n for (let i = 0; i < ContextLimits._maximumVertexAttributes; i++) {\n this._vertexAttribDivisors.push(0);\n }\n\n this._pickObjects = {};\n this._nextPickColor = new Uint32Array(1);\n\n /**\n * The options used to construct this context\n *\n * @type {ContextOptions}\n */\n this.options = {\n getWebGLStub: getWebGLStub,\n requestWebgl1: requestWebgl1,\n webgl: webglOptions,\n allowTextureFilterAnisotropic: allowTextureFilterAnisotropic,\n };\n\n /**\n * A cache of objects tied to this context. Just before the Context is destroyed,\n * destroy will be invoked on each object in this object literal that has\n * such a method. This is useful for caching any objects that might otherwise\n * be stored globally, except they're tied to a particular context, and to manage\n * their lifetime.\n *\n * @type {object}\n */\n this.cache = {};\n\n RenderState.apply(gl, rs, ps);\n}\n\n/**\n * @typedef {object} ContextOptions\n *\n * Options to control the setting up of a WebGL Context.\n *

\n * allowTextureFilterAnisotropic defaults to true, which enables\n * anisotropic texture filtering when the WebGL extension is supported.\n * Setting this to false will improve performance, but hurt visual quality,\n * especially for horizon views.\n *

\n *\n * @property {boolean} [requestWebgl1=false] If true and the browser supports it, use a WebGL 1 rendering context\n * @property {boolean} [allowTextureFilterAnisotropic=true] If true, use anisotropic filtering during texture sampling\n * @property {WebGLOptions} [webgl] WebGL options to be passed on to canvas.getContext\n * @property {Function} [getWebGLStub] A function to create a WebGL stub for testing\n */\n\n/**\n * @private\n * @param {HTMLCanvasElement} canvas The canvas element to which the context will be associated\n * @param {WebGLOptions} webglOptions WebGL options to be passed on to HTMLCanvasElement.getContext()\n * @param {boolean} requestWebgl1 Whether to request a WebGLRenderingContext or a WebGL2RenderingContext.\n * @returns {WebGLRenderingContext|WebGL2RenderingContext}\n */\nfunction getWebGLContext(canvas, webglOptions, requestWebgl1) {\n if (typeof WebGLRenderingContext === \"undefined\") {\n throw new RuntimeError(\n \"The browser does not support WebGL. Visit http://get.webgl.org.\"\n );\n }\n\n // Ensure that WebGL 2 is supported when it is requested. Otherwise, fall back to WebGL 1.\n const webgl2Supported = typeof WebGL2RenderingContext !== \"undefined\";\n if (!requestWebgl1 && !webgl2Supported) {\n requestWebgl1 = true;\n }\n\n const contextType = requestWebgl1 ? \"webgl\" : \"webgl2\";\n const glContext = canvas.getContext(contextType, webglOptions);\n\n if (!defined(glContext)) {\n throw new RuntimeError(\n \"The browser supports WebGL, but initialization failed.\"\n );\n }\n\n return glContext;\n}\n\n/**\n * @typedef {object} WebGLOptions\n *\n * WebGL options to be passed on to HTMLCanvasElement.getContext().\n * See {@link https://registry.khronos.org/webgl/specs/latest/1.0/#5.2|WebGLContextAttributes}\n * but note the modified defaults for 'alpha', 'stencil', and 'powerPreference'\n *\n *

\n * alpha defaults to false, which can improve performance\n * compared to the standard WebGL default of true. If an application needs\n * to composite Cesium above other HTML elements using alpha-blending, set\n * alpha to true.\n *

\n *\n * @property {boolean} [alpha=false]\n * @property {boolean} [depth=true]\n * @property {boolean} [stencil=false]\n * @property {boolean} [antialias=true]\n * @property {boolean} [premultipliedAlpha=true]\n * @property {boolean} [preserveDrawingBuffer=false]\n * @property {(\"default\"|\"low-power\"|\"high-performance\")} [powerPreference=\"high-performance\"]\n * @property {boolean} [failIfMajorPerformanceCaveat=false]\n */\n\nfunction errorToString(gl, error) {\n let message = \"WebGL Error: \";\n switch (error) {\n case gl.INVALID_ENUM:\n message += \"INVALID_ENUM\";\n break;\n case gl.INVALID_VALUE:\n message += \"INVALID_VALUE\";\n break;\n case gl.INVALID_OPERATION:\n message += \"INVALID_OPERATION\";\n break;\n case gl.OUT_OF_MEMORY:\n message += \"OUT_OF_MEMORY\";\n break;\n case gl.CONTEXT_LOST_WEBGL:\n message += \"CONTEXT_LOST_WEBGL lost\";\n break;\n default:\n message += `Unknown (${error})`;\n }\n\n return message;\n}\n\nfunction createErrorMessage(gl, glFunc, glFuncArguments, error) {\n let message = `${errorToString(gl, error)}: ${glFunc.name}(`;\n\n for (let i = 0; i < glFuncArguments.length; ++i) {\n if (i !== 0) {\n message += \", \";\n }\n message += glFuncArguments[i];\n }\n message += \");\";\n\n return message;\n}\n\nfunction throwOnError(gl, glFunc, glFuncArguments) {\n const error = gl.getError();\n if (error !== gl.NO_ERROR) {\n throw new RuntimeError(\n createErrorMessage(gl, glFunc, glFuncArguments, error)\n );\n }\n}\n\nfunction makeGetterSetter(gl, propertyName, logFunction) {\n return {\n get: function () {\n const value = gl[propertyName];\n logFunction(gl, `get: ${propertyName}`, value);\n return gl[propertyName];\n },\n set: function (value) {\n gl[propertyName] = value;\n logFunction(gl, `set: ${propertyName}`, value);\n },\n };\n}\n\nfunction wrapGL(gl, logFunction) {\n if (!defined(logFunction)) {\n return gl;\n }\n\n function wrapFunction(property) {\n return function () {\n const result = property.apply(gl, arguments);\n logFunction(gl, property, arguments);\n return result;\n };\n }\n\n const glWrapper = {};\n\n // JavaScript linters normally demand that a for..in loop must directly contain an if,\n // but in our loop below, we actually intend to iterate all properties, including\n // those in the prototype.\n /*eslint-disable guard-for-in*/\n for (const propertyName in gl) {\n const property = gl[propertyName];\n\n // wrap any functions we encounter, otherwise just copy the property to the wrapper.\n if (property instanceof Function) {\n glWrapper[propertyName] = wrapFunction(property);\n } else {\n Object.defineProperty(\n glWrapper,\n propertyName,\n makeGetterSetter(gl, propertyName, logFunction)\n );\n }\n }\n /*eslint-enable guard-for-in*/\n\n return glWrapper;\n}\n\nfunction getExtension(gl, names) {\n const length = names.length;\n for (let i = 0; i < length; ++i) {\n const extension = gl.getExtension(names[i]);\n if (extension) {\n return extension;\n }\n }\n\n return undefined;\n}\n\nconst defaultFramebufferMarker = {};\n\nObject.defineProperties(Context.prototype, {\n id: {\n get: function () {\n return this._id;\n },\n },\n webgl2: {\n get: function () {\n return this._webgl2;\n },\n },\n canvas: {\n get: function () {\n return this._canvas;\n },\n },\n shaderCache: {\n get: function () {\n return this._shaderCache;\n },\n },\n textureCache: {\n get: function () {\n return this._textureCache;\n },\n },\n uniformState: {\n get: function () {\n return this._us;\n },\n },\n\n /**\n * The number of stencil bits per pixel in the default bound framebuffer. The minimum is eight bits.\n * @memberof Context.prototype\n * @type {number}\n * @see {@link https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml|glGet} with STENCIL_BITS.\n */\n stencilBits: {\n get: function () {\n return this._stencilBits;\n },\n },\n\n /**\n * true if the WebGL context supports stencil buffers.\n * Stencil buffers are not supported by all systems.\n * @memberof Context.prototype\n * @type {boolean}\n */\n stencilBuffer: {\n get: function () {\n return this._stencilBits >= 8;\n },\n },\n\n /**\n * true if the WebGL context supports antialiasing. By default\n * antialiasing is requested, but it is not supported by all systems.\n * @memberof Context.prototype\n * @type {boolean}\n */\n antialias: {\n get: function () {\n return this._antialias;\n },\n },\n\n /**\n * true if the WebGL context supports multisample antialiasing. Requires\n * WebGL2.\n * @memberof Context.prototype\n * @type {boolean}\n */\n msaa: {\n get: function () {\n return this._webgl2;\n },\n },\n\n /**\n * true if the OES_standard_derivatives extension is supported. This\n * extension provides access to dFdx, dFdy, and fwidth\n * functions from GLSL. A shader using these functions still needs to explicitly enable the\n * extension with #extension GL_OES_standard_derivatives : enable.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/gles/extensions/OES/OES_standard_derivatives.txt|OES_standard_derivatives}\n */\n standardDerivatives: {\n get: function () {\n return this._standardDerivatives || this._webgl2;\n },\n },\n\n /**\n * true if the EXT_float_blend extension is supported. This\n * extension enables blending with 32-bit float values.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_float_blend/}\n */\n floatBlend: {\n get: function () {\n return this._floatBlend;\n },\n },\n\n /**\n * true if the EXT_blend_minmax extension is supported. This\n * extension extends blending capabilities by adding two new blend equations:\n * the minimum or maximum color components of the source and destination colors.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_blend_minmax/}\n */\n blendMinmax: {\n get: function () {\n return this._blendMinmax || this._webgl2;\n },\n },\n\n /**\n * true if the OES_element_index_uint extension is supported. This\n * extension allows the use of unsigned int indices, which can improve performance by\n * eliminating batch breaking caused by unsigned short indices.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/webgl/extensions/OES_element_index_uint/|OES_element_index_uint}\n */\n elementIndexUint: {\n get: function () {\n return this._elementIndexUint || this._webgl2;\n },\n },\n\n /**\n * true if WEBGL_depth_texture is supported. This extension provides\n * access to depth textures that, for example, can be attached to framebuffers for shadow mapping.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/|WEBGL_depth_texture}\n */\n depthTexture: {\n get: function () {\n return this._depthTexture || this._webgl2;\n },\n },\n\n /**\n * true if OES_texture_float is supported. This extension provides\n * access to floating point textures that, for example, can be attached to framebuffers for high dynamic range.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/OES_texture_float/}\n */\n floatingPointTexture: {\n get: function () {\n return this._webgl2 || this._textureFloat;\n },\n },\n\n /**\n * true if OES_texture_half_float is supported. This extension provides\n * access to floating point textures that, for example, can be attached to framebuffers for high dynamic range.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/OES_texture_half_float/}\n */\n halfFloatingPointTexture: {\n get: function () {\n return this._webgl2 || this._textureHalfFloat;\n },\n },\n\n /**\n * true if OES_texture_float_linear is supported. This extension provides\n * access to linear sampling methods for minification and magnification filters of floating-point textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/OES_texture_float_linear/}\n */\n textureFloatLinear: {\n get: function () {\n return this._textureFloatLinear;\n },\n },\n\n /**\n * true if OES_texture_half_float_linear is supported. This extension provides\n * access to linear sampling methods for minification and magnification filters of half floating-point textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/OES_texture_half_float_linear/}\n */\n textureHalfFloatLinear: {\n get: function () {\n return (\n (this._webgl2 && this._textureFloatLinear) ||\n (!this._webgl2 && this._textureHalfFloatLinear)\n );\n },\n },\n\n /**\n * true if EXT_texture_filter_anisotropic is supported. This extension provides\n * access to anisotropic filtering for textured surfaces at an oblique angle from the viewer.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotropic/}\n */\n textureFilterAnisotropic: {\n get: function () {\n return !!this._textureFilterAnisotropic;\n },\n },\n\n /**\n * true if WEBGL_compressed_texture_s3tc is supported. This extension provides\n * access to DXT compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/}\n */\n s3tc: {\n get: function () {\n return this._s3tc;\n },\n },\n\n /**\n * true if WEBGL_compressed_texture_pvrtc is supported. This extension provides\n * access to PVR compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/}\n */\n pvrtc: {\n get: function () {\n return this._pvrtc;\n },\n },\n\n /**\n * true if WEBGL_compressed_texture_astc is supported. This extension provides\n * access to ASTC compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/}\n */\n astc: {\n get: function () {\n return this._astc;\n },\n },\n\n /**\n * true if WEBGL_compressed_texture_etc is supported. This extension provides\n * access to ETC compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/}\n */\n etc: {\n get: function () {\n return this._etc;\n },\n },\n\n /**\n * true if WEBGL_compressed_texture_etc1 is supported. This extension provides\n * access to ETC1 compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc1/}\n */\n etc1: {\n get: function () {\n return this._etc1;\n },\n },\n\n /**\n * true if EXT_texture_compression_bptc is supported. This extension provides\n * access to BC7 compressed textures.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_texture_compression_bptc/}\n */\n bc7: {\n get: function () {\n return this._bc7;\n },\n },\n\n /**\n * true if S3TC, PVRTC, ASTC, ETC, ETC1, or BC7 compression is supported.\n * @memberof Context.prototype\n * @type {boolean}\n */\n supportsBasis: {\n get: function () {\n return (\n this._s3tc ||\n this._pvrtc ||\n this._astc ||\n this._etc ||\n this._etc1 ||\n this._bc7\n );\n },\n },\n\n /**\n * true if the OES_vertex_array_object extension is supported. This\n * extension can improve performance by reducing the overhead of switching vertex arrays.\n * When enabled, this extension is automatically used by {@link VertexArray}.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/|OES_vertex_array_object}\n */\n vertexArrayObject: {\n get: function () {\n return this._vertexArrayObject || this._webgl2;\n },\n },\n\n /**\n * true if the EXT_frag_depth extension is supported. This\n * extension provides access to the gl_FragDepthEXT built-in output variable\n * from GLSL fragment shaders. A shader using these functions still needs to explicitly enable the\n * extension with #extension GL_EXT_frag_depth : enable.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/webgl/extensions/EXT_frag_depth/|EXT_frag_depth}\n */\n fragmentDepth: {\n get: function () {\n return this._fragDepth || this._webgl2;\n },\n },\n\n /**\n * true if the ANGLE_instanced_arrays extension is supported. This\n * extension provides access to instanced rendering.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays}\n */\n instancedArrays: {\n get: function () {\n return this._instancedArrays || this._webgl2;\n },\n },\n\n /**\n * true if the EXT_color_buffer_float extension is supported. This\n * extension makes the gl.RGBA32F format color renderable.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/WEBGL_color_buffer_float/}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_color_buffer_float/}\n */\n colorBufferFloat: {\n get: function () {\n return this._colorBufferFloat;\n },\n },\n\n /**\n * true if the EXT_color_buffer_half_float extension is supported. This\n * extension makes the format gl.RGBA16F format color renderable.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_color_buffer_half_float/}\n * @see {@link https://www.khronos.org/registry/webgl/extensions/EXT_color_buffer_float/}\n */\n colorBufferHalfFloat: {\n get: function () {\n return (\n (this._webgl2 && this._colorBufferFloat) ||\n (!this._webgl2 && this._colorBufferHalfFloat)\n );\n },\n },\n\n /**\n * true if the WEBGL_draw_buffers extension is supported. This\n * extensions provides support for multiple render targets. The framebuffer object can have mutiple\n * color attachments and the GLSL fragment shader can write to the built-in output array gl_FragData.\n * A shader using this feature needs to explicitly enable the extension with\n * #extension GL_EXT_draw_buffers : enable.\n * @memberof Context.prototype\n * @type {boolean}\n * @see {@link http://www.khronos.org/registry/webgl/extensions/WEBGL_draw_buffers/|WEBGL_draw_buffers}\n */\n drawBuffers: {\n get: function () {\n return this._drawBuffers || this._webgl2;\n },\n },\n\n debugShaders: {\n get: function () {\n return this._debugShaders;\n },\n },\n\n throwOnWebGLError: {\n get: function () {\n return this._throwOnWebGLError;\n },\n set: function (value) {\n this._throwOnWebGLError = value;\n this._gl = wrapGL(\n this._originalGLContext,\n value ? throwOnError : undefined\n );\n },\n },\n\n /**\n * A 1x1 RGBA texture initialized to [255, 255, 255, 255]. This can\n * be used as a placeholder texture while other textures are downloaded.\n * @memberof Context.prototype\n * @type {Texture}\n */\n defaultTexture: {\n get: function () {\n if (this._defaultTexture === undefined) {\n this._defaultTexture = new Texture({\n context: this,\n source: {\n width: 1,\n height: 1,\n arrayBufferView: new Uint8Array([255, 255, 255, 255]),\n },\n flipY: false,\n });\n }\n\n return this._defaultTexture;\n },\n },\n /**\n * A 1x1 RGB texture initialized to [0, 0, 0] representing a material that is\n * not emissive. This can be used as a placeholder texture for emissive\n * textures while other textures are downloaded.\n * @memberof Context.prototype\n * @type {Texture}\n */\n defaultEmissiveTexture: {\n get: function () {\n if (this._defaultEmissiveTexture === undefined) {\n this._defaultEmissiveTexture = new Texture({\n context: this,\n pixelFormat: PixelFormat.RGB,\n source: {\n width: 1,\n height: 1,\n arrayBufferView: new Uint8Array([0, 0, 0]),\n },\n flipY: false,\n });\n }\n\n return this._defaultEmissiveTexture;\n },\n },\n /**\n * A 1x1 RGBA texture initialized to [128, 128, 255] to encode a tangent\n * space normal pointing in the +z direction, i.e. (0, 0, 1). This can\n * be used as a placeholder normal texture while other textures are\n * downloaded.\n * @memberof Context.prototype\n * @type {Texture}\n */\n defaultNormalTexture: {\n get: function () {\n if (this._defaultNormalTexture === undefined) {\n this._defaultNormalTexture = new Texture({\n context: this,\n pixelFormat: PixelFormat.RGB,\n source: {\n width: 1,\n height: 1,\n arrayBufferView: new Uint8Array([128, 128, 255]),\n },\n flipY: false,\n });\n }\n\n return this._defaultNormalTexture;\n },\n },\n\n /**\n * A cube map, where each face is a 1x1 RGBA texture initialized to\n * [255, 255, 255, 255]. This can be used as a placeholder cube map while\n * other cube maps are downloaded.\n * @memberof Context.prototype\n * @type {CubeMap}\n */\n defaultCubeMap: {\n get: function () {\n if (this._defaultCubeMap === undefined) {\n const face = {\n width: 1,\n height: 1,\n arrayBufferView: new Uint8Array([255, 255, 255, 255]),\n };\n\n this._defaultCubeMap = new CubeMap({\n context: this,\n source: {\n positiveX: face,\n negativeX: face,\n positiveY: face,\n negativeY: face,\n positiveZ: face,\n negativeZ: face,\n },\n flipY: false,\n });\n }\n\n return this._defaultCubeMap;\n },\n },\n\n /**\n * The drawingBufferHeight of the underlying GL context.\n * @memberof Context.prototype\n * @type {number}\n * @see {@link https://www.khronos.org/registry/webgl/specs/1.0/#DOM-WebGLRenderingContext-drawingBufferHeight|drawingBufferHeight}\n */\n drawingBufferHeight: {\n get: function () {\n return this._gl.drawingBufferHeight;\n },\n },\n\n /**\n * The drawingBufferWidth of the underlying GL context.\n * @memberof Context.prototype\n * @type {number}\n * @see {@link https://www.khronos.org/registry/webgl/specs/1.0/#DOM-WebGLRenderingContext-drawingBufferWidth|drawingBufferWidth}\n */\n drawingBufferWidth: {\n get: function () {\n return this._gl.drawingBufferWidth;\n },\n },\n\n /**\n * Gets an object representing the currently bound framebuffer. While this instance is not an actual\n * {@link Framebuffer}, it is used to represent the default framebuffer in calls to\n * {@link Texture.fromFramebuffer}.\n * @memberof Context.prototype\n * @type {object}\n */\n defaultFramebuffer: {\n get: function () {\n return defaultFramebufferMarker;\n },\n },\n});\n\n/**\n * Validates a framebuffer.\n * Available in debug builds only.\n * @private\n */\nfunction validateFramebuffer(context) {\n //>>includeStart('debug', pragmas.debug);\n if (context.validateFramebuffer) {\n const gl = context._gl;\n const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n let message;\n\n switch (status) {\n case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n message =\n \"Framebuffer is not complete. Incomplete attachment: at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached. Color-renderable formats include GL_RGBA4, GL_RGB5_A1, and GL_RGB565. GL_DEPTH_COMPONENT16 is the only depth-renderable format. GL_STENCIL_INDEX8 is the only stencil-renderable format.\";\n break;\n case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n message =\n \"Framebuffer is not complete. Incomplete dimensions: not all attached images have the same width and height.\";\n break;\n case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n message =\n \"Framebuffer is not complete. Missing attachment: no images are attached to the framebuffer.\";\n break;\n case gl.FRAMEBUFFER_UNSUPPORTED:\n message =\n \"Framebuffer is not complete. Unsupported: the combination of internal formats of the attached images violates an implementation-dependent set of restrictions.\";\n break;\n }\n\n throw new DeveloperError(message);\n }\n }\n //>>includeEnd('debug');\n}\n\nfunction applyRenderState(context, renderState, passState, clear) {\n const previousRenderState = context._currentRenderState;\n const previousPassState = context._currentPassState;\n context._currentRenderState = renderState;\n context._currentPassState = passState;\n RenderState.partialApply(\n context._gl,\n previousRenderState,\n renderState,\n previousPassState,\n passState,\n clear\n );\n}\n\nlet scratchBackBufferArray;\n// this check must use typeof, not defined, because defined doesn't work with undeclared variables.\nif (typeof WebGLRenderingContext !== \"undefined\") {\n scratchBackBufferArray = [WebGLConstants.BACK];\n}\n\nfunction bindFramebuffer(context, framebuffer) {\n if (framebuffer !== context._currentFramebuffer) {\n context._currentFramebuffer = framebuffer;\n let buffers = scratchBackBufferArray;\n\n if (defined(framebuffer)) {\n framebuffer._bind();\n validateFramebuffer(context);\n\n // TODO: Need a way for a command to give what draw buffers are active.\n buffers = framebuffer._getActiveColorAttachments();\n } else {\n const gl = context._gl;\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n }\n\n if (context.drawBuffers) {\n context.glDrawBuffers(buffers);\n }\n }\n}\n\nconst defaultClearCommand = new ClearCommand();\n\nContext.prototype.clear = function (clearCommand, passState) {\n clearCommand = defaultValue(clearCommand, defaultClearCommand);\n passState = defaultValue(passState, this._defaultPassState);\n\n const gl = this._gl;\n let bitmask = 0;\n\n const c = clearCommand.color;\n const d = clearCommand.depth;\n const s = clearCommand.stencil;\n\n if (defined(c)) {\n if (!Color.equals(this._clearColor, c)) {\n Color.clone(c, this._clearColor);\n gl.clearColor(c.red, c.green, c.blue, c.alpha);\n }\n bitmask |= gl.COLOR_BUFFER_BIT;\n }\n\n if (defined(d)) {\n if (d !== this._clearDepth) {\n this._clearDepth = d;\n gl.clearDepth(d);\n }\n bitmask |= gl.DEPTH_BUFFER_BIT;\n }\n\n if (defined(s)) {\n if (s !== this._clearStencil) {\n this._clearStencil = s;\n gl.clearStencil(s);\n }\n bitmask |= gl.STENCIL_BUFFER_BIT;\n }\n\n const rs = defaultValue(clearCommand.renderState, this._defaultRenderState);\n applyRenderState(this, rs, passState, true);\n\n // The command's framebuffer takes presidence over the pass' framebuffer, e.g., for off-screen rendering.\n const framebuffer = defaultValue(\n clearCommand.framebuffer,\n passState.framebuffer\n );\n bindFramebuffer(this, framebuffer);\n\n gl.clear(bitmask);\n};\n\nfunction beginDraw(\n context,\n framebuffer,\n passState,\n shaderProgram,\n renderState\n) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(framebuffer) && renderState.depthTest) {\n if (renderState.depthTest.enabled && !framebuffer.hasDepthAttachment) {\n throw new DeveloperError(\n \"The depth test can not be enabled (drawCommand.renderState.depthTest.enabled) because the framebuffer (drawCommand.framebuffer) does not have a depth or depth-stencil renderbuffer.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n bindFramebuffer(context, framebuffer);\n applyRenderState(context, renderState, passState, false);\n shaderProgram._bind();\n context._maxFrameTextureUnitIndex = Math.max(\n context._maxFrameTextureUnitIndex,\n shaderProgram.maximumTextureUnitIndex\n );\n}\n\nfunction continueDraw(context, drawCommand, shaderProgram, uniformMap) {\n const primitiveType = drawCommand._primitiveType;\n const va = drawCommand._vertexArray;\n let offset = drawCommand._offset;\n let count = drawCommand._count;\n const instanceCount = drawCommand.instanceCount;\n\n //>>includeStart('debug', pragmas.debug);\n if (!PrimitiveType.validate(primitiveType)) {\n throw new DeveloperError(\n \"drawCommand.primitiveType is required and must be valid.\"\n );\n }\n\n Check.defined(\"drawCommand.vertexArray\", va);\n Check.typeOf.number.greaterThanOrEquals(\"drawCommand.offset\", offset, 0);\n if (defined(count)) {\n Check.typeOf.number.greaterThanOrEquals(\"drawCommand.count\", count, 0);\n }\n Check.typeOf.number.greaterThanOrEquals(\n \"drawCommand.instanceCount\",\n instanceCount,\n 0\n );\n if (instanceCount > 0 && !context.instancedArrays) {\n throw new DeveloperError(\"Instanced arrays extension is not supported\");\n }\n //>>includeEnd('debug');\n\n context._us.model = defaultValue(drawCommand._modelMatrix, Matrix4.IDENTITY);\n shaderProgram._setUniforms(\n uniformMap,\n context._us,\n context.validateShaderProgram\n );\n\n va._bind();\n const indexBuffer = va.indexBuffer;\n\n if (defined(indexBuffer)) {\n offset = offset * indexBuffer.bytesPerIndex; // offset in vertices to offset in bytes\n if (defined(count)) {\n count = Math.min(count, indexBuffer.numberOfIndices);\n } else {\n count = indexBuffer.numberOfIndices;\n }\n if (instanceCount === 0) {\n context._gl.drawElements(\n primitiveType,\n count,\n indexBuffer.indexDatatype,\n offset\n );\n } else {\n context.glDrawElementsInstanced(\n primitiveType,\n count,\n indexBuffer.indexDatatype,\n offset,\n instanceCount\n );\n }\n } else {\n if (defined(count)) {\n count = Math.min(count, va.numberOfVertices);\n } else {\n count = va.numberOfVertices;\n }\n if (instanceCount === 0) {\n context._gl.drawArrays(primitiveType, offset, count);\n } else {\n context.glDrawArraysInstanced(\n primitiveType,\n offset,\n count,\n instanceCount\n );\n }\n }\n\n va._unBind();\n}\n\nContext.prototype.draw = function (\n drawCommand,\n passState,\n shaderProgram,\n uniformMap\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"drawCommand\", drawCommand);\n Check.defined(\"drawCommand.shaderProgram\", drawCommand._shaderProgram);\n //>>includeEnd('debug');\n\n passState = defaultValue(passState, this._defaultPassState);\n // The command's framebuffer takes presidence over the pass' framebuffer, e.g., for off-screen rendering.\n const framebuffer = defaultValue(\n drawCommand._framebuffer,\n passState.framebuffer\n );\n const renderState = defaultValue(\n drawCommand._renderState,\n this._defaultRenderState\n );\n shaderProgram = defaultValue(shaderProgram, drawCommand._shaderProgram);\n uniformMap = defaultValue(uniformMap, drawCommand._uniformMap);\n\n beginDraw(this, framebuffer, passState, shaderProgram, renderState);\n continueDraw(this, drawCommand, shaderProgram, uniformMap);\n};\n\nContext.prototype.endFrame = function () {\n const gl = this._gl;\n gl.useProgram(null);\n\n this._currentFramebuffer = undefined;\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n\n const buffers = scratchBackBufferArray;\n if (this.drawBuffers) {\n this.glDrawBuffers(buffers);\n }\n\n const length = this._maxFrameTextureUnitIndex;\n this._maxFrameTextureUnitIndex = 0;\n\n for (let i = 0; i < length; ++i) {\n gl.activeTexture(gl.TEXTURE0 + i);\n gl.bindTexture(gl.TEXTURE_2D, null);\n gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);\n }\n};\n\nContext.prototype.readPixels = function (readState) {\n const gl = this._gl;\n\n readState = defaultValue(readState, defaultValue.EMPTY_OBJECT);\n const x = Math.max(defaultValue(readState.x, 0), 0);\n const y = Math.max(defaultValue(readState.y, 0), 0);\n const width = defaultValue(readState.width, gl.drawingBufferWidth);\n const height = defaultValue(readState.height, gl.drawingBufferHeight);\n const framebuffer = readState.framebuffer;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"readState.width\", width, 0);\n Check.typeOf.number.greaterThan(\"readState.height\", height, 0);\n //>>includeEnd('debug');\n\n let pixelDatatype = PixelDatatype.UNSIGNED_BYTE;\n if (defined(framebuffer) && framebuffer.numberOfColorAttachments > 0) {\n pixelDatatype = framebuffer.getColorTexture(0).pixelDatatype;\n }\n\n const pixels = PixelFormat.createTypedArray(\n PixelFormat.RGBA,\n pixelDatatype,\n width,\n height\n );\n\n bindFramebuffer(this, framebuffer);\n\n gl.readPixels(\n x,\n y,\n width,\n height,\n PixelFormat.RGBA,\n PixelDatatype.toWebGLConstant(pixelDatatype, this),\n pixels\n );\n\n return pixels;\n};\n\nconst viewportQuadAttributeLocations = {\n position: 0,\n textureCoordinates: 1,\n};\n\nContext.prototype.getViewportQuadVertexArray = function () {\n // Per-context cache for viewport quads\n let vertexArray = this.cache.viewportQuad_vertexArray;\n\n if (!defined(vertexArray)) {\n const geometry = new Geometry({\n attributes: {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: [-1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0],\n }),\n\n textureCoordinates: new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0],\n }),\n },\n // Workaround Internet Explorer 11.0.8 lack of TRIANGLE_FAN\n indices: new Uint16Array([0, 1, 2, 0, 2, 3]),\n primitiveType: PrimitiveType.TRIANGLES,\n });\n\n vertexArray = VertexArray.fromGeometry({\n context: this,\n geometry: geometry,\n attributeLocations: viewportQuadAttributeLocations,\n bufferUsage: BufferUsage.STATIC_DRAW,\n interleave: true,\n });\n\n this.cache.viewportQuad_vertexArray = vertexArray;\n }\n\n return vertexArray;\n};\n\nContext.prototype.createViewportQuadCommand = function (\n fragmentShaderSource,\n overrides\n) {\n overrides = defaultValue(overrides, defaultValue.EMPTY_OBJECT);\n\n return new DrawCommand({\n vertexArray: this.getViewportQuadVertexArray(),\n primitiveType: PrimitiveType.TRIANGLES,\n renderState: overrides.renderState,\n shaderProgram: ShaderProgram.fromCache({\n context: this,\n vertexShaderSource: ViewportQuadVS,\n fragmentShaderSource: fragmentShaderSource,\n attributeLocations: viewportQuadAttributeLocations,\n }),\n uniformMap: overrides.uniformMap,\n owner: overrides.owner,\n framebuffer: overrides.framebuffer,\n pass: overrides.pass,\n });\n};\n\n/**\n * Gets the object associated with a pick color.\n *\n * @param {Color} pickColor The pick color.\n * @returns {object} The object associated with the pick color, or undefined if no object is associated with that color.\n *\n * @example\n * const object = context.getObjectByPickColor(pickColor);\n *\n * @see Context#createPickId\n */\nContext.prototype.getObjectByPickColor = function (pickColor) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"pickColor\", pickColor);\n //>>includeEnd('debug');\n\n return this._pickObjects[pickColor.toRgba()];\n};\n\nfunction PickId(pickObjects, key, color) {\n this._pickObjects = pickObjects;\n this.key = key;\n this.color = color;\n}\n\nObject.defineProperties(PickId.prototype, {\n object: {\n get: function () {\n return this._pickObjects[this.key];\n },\n set: function (value) {\n this._pickObjects[this.key] = value;\n },\n },\n});\n\nPickId.prototype.destroy = function () {\n delete this._pickObjects[this.key];\n return undefined;\n};\n\n/**\n * Creates a unique ID associated with the input object for use with color-buffer picking.\n * The ID has an RGBA color value unique to this context. You must call destroy()\n * on the pick ID when destroying the input object.\n *\n * @param {object} object The object to associate with the pick ID.\n * @returns {object} A PickId object with a color property.\n *\n * @exception {RuntimeError} Out of unique Pick IDs.\n *\n *\n * @example\n * this._pickId = context.createPickId({\n * primitive : this,\n * id : this.id\n * });\n *\n * @see Context#getObjectByPickColor\n */\nContext.prototype.createPickId = function (object) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"object\", object);\n //>>includeEnd('debug');\n\n // the increment and assignment have to be separate statements to\n // actually detect overflow in the Uint32 value\n ++this._nextPickColor[0];\n const key = this._nextPickColor[0];\n if (key === 0) {\n // In case of overflow\n throw new RuntimeError(\"Out of unique Pick IDs.\");\n }\n\n this._pickObjects[key] = object;\n return new PickId(this._pickObjects, key, Color.fromRgba(key));\n};\n\nContext.prototype.isDestroyed = function () {\n return false;\n};\n\nContext.prototype.destroy = function () {\n // Destroy all objects in the cache that have a destroy method.\n const cache = this.cache;\n for (const property in cache) {\n if (cache.hasOwnProperty(property)) {\n const propertyValue = cache[property];\n if (defined(propertyValue.destroy)) {\n propertyValue.destroy();\n }\n }\n }\n\n this._shaderCache = this._shaderCache.destroy();\n this._textureCache = this._textureCache.destroy();\n this._defaultTexture = this._defaultTexture && this._defaultTexture.destroy();\n this._defaultEmissiveTexture =\n this._defaultEmissiveTexture && this._defaultEmissiveTexture.destroy();\n this._defaultNormalTexture =\n this._defaultNormalTexture && this._defaultNormalTexture.destroy();\n this._defaultCubeMap = this._defaultCubeMap && this._defaultCubeMap.destroy();\n\n return destroyObject(this);\n};\n\n// Used for specs.\nContext._deprecationWarning = deprecationWarning;\n\nexport default Context;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Framebuffer from \"./Framebuffer.js\";\n\n/**\n * Creates a multisampling wrapper around two framebuffers with optional initial\n * color and depth-stencil attachments. The first framebuffer has multisampled\n * renderbuffer attachments and is bound to READ_FRAMEBUFFER during the blit. The\n * second is bound to DRAW_FRAMEBUFFER during the blit, and has texture attachments\n * to store the copied pixels.\n *\n * @param {object} options The initial framebuffer attachments. context, width, and height are required. The possible properties are colorTextures, colorRenderbuffers, depthStencilTexture, depthStencilRenderbuffer, and destroyAttachments.\n *\n * @exception {DeveloperError} Both color renderbuffer and texture attachments must be provided.\n * @exception {DeveloperError} Both depth-stencil renderbuffer and texture attachments must be provided.\n *\n * @private\n * @constructor\n */\nfunction MultisampleFramebuffer(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const context = options.context;\n const width = options.width;\n const height = options.height;\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", context);\n Check.defined(\"options.width\", width);\n Check.defined(\"options.height\", height);\n //>>includeEnd('debug');\n this._width = width;\n this._height = height;\n\n const colorRenderbuffers = options.colorRenderbuffers;\n const colorTextures = options.colorTextures;\n if (defined(colorRenderbuffers) !== defined(colorTextures)) {\n throw new DeveloperError(\n \"Both color renderbuffer and texture attachments must be provided.\"\n );\n }\n\n const depthStencilRenderbuffer = options.depthStencilRenderbuffer;\n const depthStencilTexture = options.depthStencilTexture;\n if (defined(depthStencilRenderbuffer) !== defined(depthStencilTexture)) {\n throw new DeveloperError(\n \"Both depth-stencil renderbuffer and texture attachments must be provided.\"\n );\n }\n\n this._renderFramebuffer = new Framebuffer({\n context: context,\n colorRenderbuffers: colorRenderbuffers,\n depthStencilRenderbuffer: depthStencilRenderbuffer,\n destroyAttachments: options.destroyAttachments,\n });\n this._colorFramebuffer = new Framebuffer({\n context: context,\n colorTextures: colorTextures,\n depthStencilTexture: depthStencilTexture,\n destroyAttachments: options.destroyAttachments,\n });\n}\n\nMultisampleFramebuffer.prototype.getRenderFramebuffer = function () {\n return this._renderFramebuffer;\n};\n\nMultisampleFramebuffer.prototype.getColorFramebuffer = function () {\n return this._colorFramebuffer;\n};\n\nMultisampleFramebuffer.prototype.blitFramebuffers = function (\n context,\n blitStencil\n) {\n this._renderFramebuffer.bindRead();\n this._colorFramebuffer.bindDraw();\n const gl = context._gl;\n let mask = 0;\n if (this._colorFramebuffer._colorTextures.length > 0) {\n mask |= gl.COLOR_BUFFER_BIT;\n }\n if (defined(this._colorFramebuffer.depthStencilTexture)) {\n mask |= gl.DEPTH_BUFFER_BIT | (blitStencil ? gl.STENCIL_BUFFER_BIT : 0);\n }\n gl.blitFramebuffer(\n 0,\n 0,\n this._width,\n this._height,\n 0,\n 0,\n this._width,\n this._height,\n mask,\n gl.NEAREST\n );\n gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);\n gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);\n};\n\nMultisampleFramebuffer.prototype.isDestroyed = function () {\n return false;\n};\n\nMultisampleFramebuffer.prototype.destroy = function () {\n this._renderFramebuffer.destroy();\n this._colorFramebuffer.destroy();\n return destroyObject(this);\n};\n\nexport default MultisampleFramebuffer;\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * @private\n */\nconst RenderbufferFormat = {\n RGBA4: WebGLConstants.RGBA4,\n RGBA8: WebGLConstants.RGBA8,\n RGBA16F: WebGLConstants.RGBA16F,\n RGBA32F: WebGLConstants.RGBA32F,\n RGB5_A1: WebGLConstants.RGB5_A1,\n RGB565: WebGLConstants.RGB565,\n DEPTH_COMPONENT16: WebGLConstants.DEPTH_COMPONENT16,\n STENCIL_INDEX8: WebGLConstants.STENCIL_INDEX8,\n DEPTH_STENCIL: WebGLConstants.DEPTH_STENCIL,\n DEPTH24_STENCIL8: WebGLConstants.DEPTH24_STENCIL8,\n\n validate: function (renderbufferFormat) {\n return (\n renderbufferFormat === RenderbufferFormat.RGBA4 ||\n renderbufferFormat === RenderbufferFormat.RGBA8 ||\n renderbufferFormat === RenderbufferFormat.RGBA16F ||\n renderbufferFormat === RenderbufferFormat.RGBA32F ||\n renderbufferFormat === RenderbufferFormat.RGB5_A1 ||\n renderbufferFormat === RenderbufferFormat.RGB565 ||\n renderbufferFormat === RenderbufferFormat.DEPTH_COMPONENT16 ||\n renderbufferFormat === RenderbufferFormat.STENCIL_INDEX8 ||\n renderbufferFormat === RenderbufferFormat.DEPTH_STENCIL ||\n renderbufferFormat === RenderbufferFormat.DEPTH24_STENCIL8\n );\n },\n\n getColorFormat: function (datatype) {\n if (datatype === WebGLConstants.FLOAT) {\n return RenderbufferFormat.RGBA32F;\n } else if (datatype === WebGLConstants.HALF_FLOAT_OES) {\n return RenderbufferFormat.RGBA16F;\n }\n return RenderbufferFormat.RGBA8;\n },\n};\nexport default Object.freeze(RenderbufferFormat);\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport ContextLimits from \"./ContextLimits.js\";\nimport RenderbufferFormat from \"./RenderbufferFormat.js\";\n\n/**\n * @private\n */\nfunction Renderbuffer(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.context\", options.context);\n //>>includeEnd('debug');\n\n const context = options.context;\n const gl = context._gl;\n const maximumRenderbufferSize = ContextLimits.maximumRenderbufferSize;\n\n const format = defaultValue(options.format, RenderbufferFormat.RGBA4);\n const width = defined(options.width) ? options.width : gl.drawingBufferWidth;\n const height = defined(options.height)\n ? options.height\n : gl.drawingBufferHeight;\n const numSamples = defaultValue(options.numSamples, 1);\n\n //>>includeStart('debug', pragmas.debug);\n if (!RenderbufferFormat.validate(format)) {\n throw new DeveloperError(\"Invalid format.\");\n }\n\n Check.typeOf.number.greaterThan(\"width\", width, 0);\n\n if (width > maximumRenderbufferSize) {\n throw new DeveloperError(\n `Width must be less than or equal to the maximum renderbuffer size (${maximumRenderbufferSize}). Check maximumRenderbufferSize.`\n );\n }\n\n Check.typeOf.number.greaterThan(\"height\", height, 0);\n\n if (height > maximumRenderbufferSize) {\n throw new DeveloperError(\n `Height must be less than or equal to the maximum renderbuffer size (${maximumRenderbufferSize}). Check maximumRenderbufferSize.`\n );\n }\n //>>includeEnd('debug');\n\n this._gl = gl;\n this._format = format;\n this._width = width;\n this._height = height;\n this._renderbuffer = this._gl.createRenderbuffer();\n\n gl.bindRenderbuffer(gl.RENDERBUFFER, this._renderbuffer);\n if (numSamples > 1) {\n gl.renderbufferStorageMultisample(\n gl.RENDERBUFFER,\n numSamples,\n format,\n width,\n height\n );\n } else {\n gl.renderbufferStorage(gl.RENDERBUFFER, format, width, height);\n }\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\n}\n\nObject.defineProperties(Renderbuffer.prototype, {\n format: {\n get: function () {\n return this._format;\n },\n },\n width: {\n get: function () {\n return this._width;\n },\n },\n height: {\n get: function () {\n return this._height;\n },\n },\n});\n\nRenderbuffer.prototype._getRenderbuffer = function () {\n return this._renderbuffer;\n};\n\nRenderbuffer.prototype.isDestroyed = function () {\n return false;\n};\n\nRenderbuffer.prototype.destroy = function () {\n this._gl.deleteRenderbuffer(this._renderbuffer);\n return destroyObject(this);\n};\nexport default Renderbuffer;\n", "import Framebuffer from \"./Framebuffer.js\";\nimport MultisampleFramebuffer from \"./MultisampleFramebuffer.js\";\nimport PixelDatatype from \"./PixelDatatype.js\";\nimport Renderbuffer from \"./Renderbuffer.js\";\nimport RenderbufferFormat from \"./RenderbufferFormat.js\";\nimport Sampler from \"./Sampler.js\";\nimport Texture from \"./Texture.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\n\n/**\n * Creates a wrapper object around a framebuffer and its resources.\n *\n * @param {object} options Object with the following properties:\n * @param {number} [options.numSamples=1] The multisampling rate of the render targets. Requires a WebGL2 context.\n * @param {number} [options.colorAttachmentsLength=1] The number of color attachments this FramebufferManager will create.\n * @param {boolean} [options.color=true] Whether the FramebufferManager will use color attachments.\n * @param {boolean} [options.depth=false] Whether the FramebufferManager will use depth attachments.\n * @param {boolean} [options.depthStencil=false] Whether the FramebufferManager will use depth-stencil attachments.\n * @param {boolean} [options.supportsDepthTexture=false] Whether the FramebufferManager will create a depth texture when the extension is supported.\n * @param {boolean} [options.createColorAttachments=true] Whether the FramebufferManager will construct its own color attachments.\n * @param {boolean} [options.createDepthAttachments=true] Whether the FramebufferManager will construct its own depth attachments.\n * @param {PixelDatatype} [options.pixelDatatype=undefined] The default pixel datatype to use when creating color attachments.\n * @param {PixelFormat} [options.pixelFormat=undefined] The default pixel format to use when creating color attachments.\n *\n * @exception {DeveloperError} Must enable at least one type of framebuffer attachment.\n * @exception {DeveloperError} Cannot have both a depth and depth-stencil attachment.\n *\n * @private\n * @constructor\n */\nfunction FramebufferManager(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n this._numSamples = defaultValue(options.numSamples, 1);\n this._colorAttachmentsLength = defaultValue(\n options.colorAttachmentsLength,\n 1\n );\n\n this._color = defaultValue(options.color, true);\n this._depth = defaultValue(options.depth, false);\n this._depthStencil = defaultValue(options.depthStencil, false);\n this._supportsDepthTexture = defaultValue(\n options.supportsDepthTexture,\n false\n );\n //>>includeStart('debug', pragmas.debug);\n if (!this._color && !this._depth && !this._depthStencil) {\n throw new DeveloperError(\n \"Must enable at least one type of framebuffer attachment.\"\n );\n }\n if (this._depth && this._depthStencil) {\n throw new DeveloperError(\n \"Cannot have both a depth and depth-stencil attachment.\"\n );\n }\n //>>includeEnd('debug');\n\n this._createColorAttachments = defaultValue(\n options.createColorAttachments,\n true\n );\n this._createDepthAttachments = defaultValue(\n options.createDepthAttachments,\n true\n );\n\n this._pixelDatatype = options.pixelDatatype;\n this._pixelFormat = options.pixelFormat;\n\n this._width = undefined;\n this._height = undefined;\n\n this._framebuffer = undefined;\n this._multisampleFramebuffer = undefined;\n this._colorTextures = undefined;\n if (this._color) {\n this._colorTextures = new Array(this._colorAttachmentsLength);\n this._colorRenderbuffers = new Array(this._colorAttachmentsLength);\n }\n this._colorRenderbuffer = undefined;\n this._depthStencilRenderbuffer = undefined;\n this._depthStencilTexture = undefined;\n this._depthRenderbuffer = undefined;\n this._depthTexture = undefined;\n\n this._attachmentsDirty = false;\n}\n\nObject.defineProperties(FramebufferManager.prototype, {\n framebuffer: {\n get: function () {\n if (this._numSamples > 1) {\n return this._multisampleFramebuffer.getRenderFramebuffer();\n }\n return this._framebuffer;\n },\n },\n numSamples: {\n get: function () {\n return this._numSamples;\n },\n },\n status: {\n get: function () {\n return this.framebuffer.status;\n },\n },\n});\n\nFramebufferManager.prototype.isDirty = function (\n width,\n height,\n numSamples,\n pixelDatatype,\n pixelFormat\n) {\n numSamples = defaultValue(numSamples, 1);\n const dimensionChanged = this._width !== width || this._height !== height;\n const samplesChanged = this._numSamples !== numSamples;\n const pixelChanged =\n (defined(pixelDatatype) && this._pixelDatatype !== pixelDatatype) ||\n (defined(pixelFormat) && this._pixelFormat !== pixelFormat);\n const framebufferDefined =\n numSamples === 1\n ? defined(this._framebuffer)\n : defined(this._multisampleFramebuffer);\n\n return (\n this._attachmentsDirty ||\n dimensionChanged ||\n samplesChanged ||\n pixelChanged ||\n !framebufferDefined ||\n (this._color && !defined(this._colorTextures[0]))\n );\n};\n\nFramebufferManager.prototype.update = function (\n context,\n width,\n height,\n numSamples,\n pixelDatatype,\n pixelFormat\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(width) || !defined(height)) {\n throw new DeveloperError(\"width and height must be defined.\");\n }\n //>>includeEnd('debug');\n numSamples = context.msaa ? defaultValue(numSamples, 1) : 1;\n pixelDatatype = defaultValue(\n pixelDatatype,\n this._color\n ? defaultValue(this._pixelDatatype, PixelDatatype.UNSIGNED_BYTE)\n : undefined\n );\n pixelFormat = defaultValue(\n pixelFormat,\n this._color ? defaultValue(this._pixelFormat, PixelFormat.RGBA) : undefined\n );\n\n if (this.isDirty(width, height, numSamples, pixelDatatype, pixelFormat)) {\n this.destroy();\n this._width = width;\n this._height = height;\n this._numSamples = numSamples;\n this._pixelDatatype = pixelDatatype;\n this._pixelFormat = pixelFormat;\n this._attachmentsDirty = false;\n\n // Create color texture\n if (this._color && this._createColorAttachments) {\n for (let i = 0; i < this._colorAttachmentsLength; ++i) {\n this._colorTextures[i] = new Texture({\n context: context,\n width: width,\n height: height,\n pixelFormat: pixelFormat,\n pixelDatatype: pixelDatatype,\n sampler: Sampler.NEAREST,\n });\n if (this._numSamples > 1) {\n const format = RenderbufferFormat.getColorFormat(pixelDatatype);\n this._colorRenderbuffers[i] = new Renderbuffer({\n context: context,\n width: width,\n height: height,\n format: format,\n numSamples: this._numSamples,\n });\n }\n }\n }\n\n // Create depth stencil texture or renderbuffer\n if (this._depthStencil && this._createDepthAttachments) {\n if (this._supportsDepthTexture && context.depthTexture) {\n this._depthStencilTexture = new Texture({\n context: context,\n width: width,\n height: height,\n pixelFormat: PixelFormat.DEPTH_STENCIL,\n pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,\n sampler: Sampler.NEAREST,\n });\n if (this._numSamples > 1) {\n this._depthStencilRenderbuffer = new Renderbuffer({\n context: context,\n width: width,\n height: height,\n format: RenderbufferFormat.DEPTH24_STENCIL8,\n numSamples: this._numSamples,\n });\n }\n } else {\n this._depthStencilRenderbuffer = new Renderbuffer({\n context: context,\n width: width,\n height: height,\n format: RenderbufferFormat.DEPTH_STENCIL,\n });\n }\n }\n\n // Create depth texture\n if (this._depth && this._createDepthAttachments) {\n if (this._supportsDepthTexture && context.depthTexture) {\n this._depthTexture = new Texture({\n context: context,\n width: width,\n height: height,\n pixelFormat: PixelFormat.DEPTH_COMPONENT,\n pixelDatatype: PixelDatatype.UNSIGNED_INT,\n sampler: Sampler.NEAREST,\n });\n } else {\n this._depthRenderbuffer = new Renderbuffer({\n context: context,\n width: width,\n height: height,\n format: RenderbufferFormat.DEPTH_COMPONENT16,\n });\n }\n }\n\n if (this._numSamples > 1) {\n this._multisampleFramebuffer = new MultisampleFramebuffer({\n context: context,\n width: this._width,\n height: this._height,\n colorTextures: this._colorTextures,\n colorRenderbuffers: this._colorRenderbuffers,\n depthStencilTexture: this._depthStencilTexture,\n depthStencilRenderbuffer: this._depthStencilRenderbuffer,\n destroyAttachments: false,\n });\n } else {\n this._framebuffer = new Framebuffer({\n context: context,\n colorTextures: this._colorTextures,\n depthTexture: this._depthTexture,\n depthRenderbuffer: this._depthRenderbuffer,\n depthStencilTexture: this._depthStencilTexture,\n depthStencilRenderbuffer: this._depthStencilRenderbuffer,\n destroyAttachments: false,\n });\n }\n }\n};\n\nFramebufferManager.prototype.getColorTexture = function (index) {\n index = defaultValue(index, 0);\n //>>includeStart('debug', pragmas.debug);\n if (index >= this._colorAttachmentsLength) {\n throw new DeveloperError(\n \"index must be smaller than total number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n return this._colorTextures[index];\n};\n\nFramebufferManager.prototype.setColorTexture = function (texture, index) {\n index = defaultValue(index, 0);\n //>>includeStart('debug', pragmas.debug);\n if (this._createColorAttachments) {\n throw new DeveloperError(\n \"createColorAttachments must be false if setColorTexture is called.\"\n );\n }\n if (index >= this._colorAttachmentsLength) {\n throw new DeveloperError(\n \"index must be smaller than total number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = texture !== this._colorTextures[index];\n this._colorTextures[index] = texture;\n};\n\nFramebufferManager.prototype.getColorRenderbuffer = function (index) {\n index = defaultValue(index, 0);\n //>>includeStart('debug', pragmas.debug);\n if (index >= this._colorAttachmentsLength) {\n throw new DeveloperError(\n \"index must be smaller than total number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n return this._colorRenderbuffers[index];\n};\n\nFramebufferManager.prototype.setColorRenderbuffer = function (\n renderbuffer,\n index\n) {\n index = defaultValue(index, 0);\n //>>includeStart('debug', pragmas.debug);\n if (this._createColorAttachments) {\n throw new DeveloperError(\n \"createColorAttachments must be false if setColorRenderbuffer is called.\"\n );\n }\n if (index >= this._colorAttachmentsLength) {\n throw new DeveloperError(\n \"index must be smaller than total number of color attachments.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = renderbuffer !== this._colorRenderbuffers[index];\n this._colorRenderbuffers[index] = renderbuffer;\n};\n\nFramebufferManager.prototype.getDepthRenderbuffer = function () {\n return this._depthRenderbuffer;\n};\n\nFramebufferManager.prototype.setDepthRenderbuffer = function (renderbuffer) {\n //>>includeStart('debug', pragmas.debug);\n if (this._createDepthAttachments) {\n throw new DeveloperError(\n \"createDepthAttachments must be false if setDepthRenderbuffer is called.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = renderbuffer !== this._depthRenderbuffer;\n this._depthRenderbuffer = renderbuffer;\n};\n\nFramebufferManager.prototype.getDepthTexture = function () {\n return this._depthTexture;\n};\n\nFramebufferManager.prototype.setDepthTexture = function (texture) {\n //>>includeStart('debug', pragmas.debug);\n if (this._createDepthAttachments) {\n throw new DeveloperError(\n \"createDepthAttachments must be false if setDepthTexture is called.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = texture !== this._depthTexture;\n this._depthTexture = texture;\n};\n\nFramebufferManager.prototype.getDepthStencilRenderbuffer = function () {\n return this._depthStencilRenderbuffer;\n};\n\nFramebufferManager.prototype.setDepthStencilRenderbuffer = function (\n renderbuffer\n) {\n //>>includeStart('debug', pragmas.debug);\n if (this._createDepthAttachments) {\n throw new DeveloperError(\n \"createDepthAttachments must be false if setDepthStencilRenderbuffer is called.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = renderbuffer !== this._depthStencilRenderbuffer;\n this._depthStencilRenderbuffer = renderbuffer;\n};\n\nFramebufferManager.prototype.getDepthStencilTexture = function () {\n return this._depthStencilTexture;\n};\n\nFramebufferManager.prototype.setDepthStencilTexture = function (texture) {\n //>>includeStart('debug', pragmas.debug);\n if (this._createDepthAttachments) {\n throw new DeveloperError(\n \"createDepthAttachments must be false if setDepthStencilTexture is called.\"\n );\n }\n //>>includeEnd('debug');\n this._attachmentsDirty = texture !== this._depthStencilTexture;\n this._depthStencilTexture = texture;\n};\n\nFramebufferManager.prototype.prepareTextures = function (context, blitStencil) {\n if (this._numSamples > 1) {\n this._multisampleFramebuffer.blitFramebuffers(context, blitStencil);\n }\n};\n\nFramebufferManager.prototype.clear = function (\n context,\n clearCommand,\n passState\n) {\n const framebuffer = clearCommand.framebuffer;\n clearCommand.framebuffer = this.framebuffer;\n clearCommand.execute(context, passState);\n clearCommand.framebuffer = framebuffer;\n};\n\nFramebufferManager.prototype.destroyFramebuffer = function () {\n this._framebuffer = this._framebuffer && this._framebuffer.destroy();\n this._multisampleFramebuffer =\n this._multisampleFramebuffer && this._multisampleFramebuffer.destroy();\n};\n\nFramebufferManager.prototype.destroy = function () {\n if (this._color) {\n let i;\n const length = this._colorTextures.length;\n for (i = 0; i < length; ++i) {\n const texture = this._colorTextures[i];\n if (this._createColorAttachments) {\n if (defined(texture) && !texture.isDestroyed()) {\n this._colorTextures[i].destroy();\n this._colorTextures[i] = undefined;\n }\n }\n if (defined(texture) && texture.isDestroyed()) {\n this._colorTextures[i] = undefined;\n }\n const renderbuffer = this._colorRenderbuffers[i];\n if (this._createColorAttachments) {\n if (defined(renderbuffer) && !renderbuffer.isDestroyed()) {\n this._colorRenderbuffers[i].destroy();\n this._colorRenderbuffers[i] = undefined;\n }\n }\n if (defined(renderbuffer) && renderbuffer.isDestroyed()) {\n this._colorRenderbuffers[i] = undefined;\n }\n }\n }\n\n if (this._depthStencil) {\n if (this._createDepthAttachments) {\n this._depthStencilTexture =\n this._depthStencilTexture && this._depthStencilTexture.destroy();\n this._depthStencilRenderbuffer =\n this._depthStencilRenderbuffer &&\n this._depthStencilRenderbuffer.destroy();\n }\n if (\n defined(this._depthStencilTexture) &&\n this._depthStencilTexture.isDestroyed()\n ) {\n this._depthStencilTexture = undefined;\n }\n if (\n defined(this._depthStencilRenderbuffer) &&\n this._depthStencilRenderbuffer.isDestroyed()\n ) {\n this._depthStencilRenderbuffer = undefined;\n }\n }\n\n if (this._depth) {\n if (this._createDepthAttachments) {\n this._depthTexture = this._depthTexture && this._depthTexture.destroy();\n this._depthRenderbuffer =\n this._depthRenderbuffer && this._depthRenderbuffer.destroy();\n }\n if (defined(this._depthTexture) && this._depthTexture.isDestroyed()) {\n this._depthTexture = undefined;\n }\n if (\n defined(this._depthRenderbuffer) &&\n this._depthRenderbuffer.isDestroyed()\n ) {\n this._depthRenderbuffer = undefined;\n }\n }\n\n this.destroyFramebuffer();\n};\nexport default FramebufferManager;\n", "import Check from \"../Core/Check.js\";\n\n/**\n * An enum describing whether a variable should be added to the\n * vertex shader, the fragment shader, or both.\n *\n * @private\n */\nconst ShaderDestination = {\n VERTEX: 0,\n FRAGMENT: 1,\n BOTH: 2,\n};\n\n/**\n * Check if a variable should be included in the vertex shader.\n *\n * @param {ShaderDestination} destination The ShaderDestination to check\n * @return {boolean} true if the variable appears in the vertex shader, or false otherwise\n * @private\n */\nShaderDestination.includesVertexShader = function (destination) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"destination\", destination);\n //>>includeEnd('debug');\n\n return (\n destination === ShaderDestination.VERTEX ||\n destination === ShaderDestination.BOTH\n );\n};\n\n/**\n * Check if a variable should be included in the vertex shader.\n *\n * @param {ShaderDestination} destination The ShaderDestination to check\n * @return {boolean} true if the variable appears in the vertex shader, or false otherwise\n * @private\n */\nShaderDestination.includesFragmentShader = function (destination) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"destination\", destination);\n //>>includeEnd('debug');\n //\n return (\n destination === ShaderDestination.FRAGMENT ||\n destination === ShaderDestination.BOTH\n );\n};\n\nexport default Object.freeze(ShaderDestination);\n", "/**\n * A utility for dynamically-generating a GLSL struct.\n *\n * @alias ShaderStruct\n * @constructor\n *\n * @see {@link ShaderBuilder}\n * @param {string} name The name of the struct as it will appear in the shader.\n * @example\n * // Generate the struct:\n * //\n * // struct Attributes\n * // {\n * // vec3 position;\n * // vec3 normal;\n * // vec2 texCoord;\n * // };\n * const struct = new ShaderStruct(\"Attributes\");\n * struct.addField(\"vec3\", \"position\");\n * struct.addField(\"vec3\", \"normal\");\n * struct.addField(\"vec2\", \"texCoord\");\n * const generatedLines = struct.generateGlslLines();\n *\n * @private\n */\nfunction ShaderStruct(name) {\n this.name = name;\n this.fields = [];\n}\n\n/**\n * Add a field to the struct\n * @param {string} type The type of the struct field\n * @param {string} identifier The identifier of the struct field\n */\nShaderStruct.prototype.addField = function (type, identifier) {\n const field = ` ${type} ${identifier};`;\n this.fields.push(field);\n};\n\n/**\n * Generate a list of lines of GLSL code for use with {@link ShaderBuilder}\n * @return {string[]} The generated GLSL code.\n */\nShaderStruct.prototype.generateGlslLines = function () {\n let fields = this.fields;\n if (fields.length === 0) {\n // GLSL requires structs to have at least one field\n fields = [\" float _empty;\"];\n }\n\n return [].concat(`struct ${this.name}`, \"{\", fields, \"};\");\n};\n\nexport default ShaderStruct;\n", "import DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * A utility for dynamically-generating a GLSL function\n *\n * @alias ShaderFunction\n * @constructor\n *\n * @see {@link ShaderBuilder}\n * @param {string} signature The full signature of the function as it will appear in the shader. Do not include the curly braces.\n * @example\n * // generate the following function\n * //\n * // void assignVaryings(vec3 position)\n * // {\n * // v_positionEC = (czm_modelView * vec4(a_position, 1.0)).xyz;\n * // v_texCoord = a_texCoord;\n * // }\n * const signature = \"void assignVaryings(vec3 position)\";\n * const func = new ShaderFunction(signature);\n * func.addLine(\"v_positionEC = (czm_modelView * vec4(a_position, 1.0)).xyz;\");\n * func.addLine(\"v_texCoord = a_texCoord;\");\n * const generatedLines = func.generateGlslLines();\n *\n * @private\n */\nfunction ShaderFunction(signature) {\n this.signature = signature;\n this.body = [];\n}\n\n/**\n * Adds one or more lines to the body of the function\n * @param {string|string[]} lines One or more lines of GLSL code to add to the function body. Do not include any preceding or ending whitespace, but do include the semicolon for each line.\n */\nShaderFunction.prototype.addLines = function (lines) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof lines !== \"string\" && !Array.isArray(lines)) {\n throw new DeveloperError(\n `Expected lines to be a string or an array of strings, actual value was ${lines}`\n );\n }\n //>>includeEnd('debug');\n const body = this.body;\n\n // Indent the body of the function by 4 spaces\n if (Array.isArray(lines)) {\n const length = lines.length;\n for (let i = 0; i < length; i++) {\n body.push(` ${lines[i]}`);\n }\n } else {\n // Single string case\n body.push(` ${lines}`);\n }\n};\n\n/**\n * Generate lines of GLSL code for use with {@link ShaderBuilder}\n * @return {string[]}\n */\nShaderFunction.prototype.generateGlslLines = function () {\n return [].concat(this.signature, \"{\", this.body, \"}\");\n};\n\nexport default ShaderFunction;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defined from \"../Core/defined.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport ShaderDestination from \"./ShaderDestination.js\";\nimport ShaderProgram from \"./ShaderProgram.js\";\nimport ShaderSource from \"./ShaderSource.js\";\nimport ShaderStruct from \"./ShaderStruct.js\";\nimport ShaderFunction from \"./ShaderFunction.js\";\n\n/**\n * An object that makes it easier to build the text of a {@link ShaderProgram}. This tracks GLSL code for both the vertex shader and the fragment shader.\n *

\n * For vertex shaders, the shader builder tracks a list of #defines,\n * a list of attributes, a list of uniforms, and a list of shader lines. It also\n * tracks the location of each attribute so the caller can easily build the {@link VertexArray}\n *

\n *

\n * For fragment shaders, the shader builder tracks a list of #defines,\n * a list of attributes, a list of uniforms, and a list of shader lines.\n *

\n *\n * @alias ShaderBuilder\n * @constructor\n *\n * @example\n * const shaderBuilder = new ShaderBuilder();\n * shaderBuilder.addDefine(\"SOLID_COLOR\", undefined, ShaderDestination.FRAGMENT);\n * shaderBuilder.addUniform(\"vec3\", \"u_color\", ShaderDestination.FRAGMENT);\n * shaderBuilder.addVarying(\"vec3\", v_color\");\n * // These locations can be used when creating the VertexArray\n * const positionLocation = shaderBuilder.addPositionAttribute(\"vec3\", \"a_position\");\n * const colorLocation = shaderBuilder.addAttribute(\"vec3\", \"a_color\");\n * shaderBuilder.addVertexLines([\n * \"void main()\",\n * \"{\",\n * \" v_color = a_color;\",\n * \" gl_Position = vec4(a_position, 1.0);\",\n * \"}\"\n * ]);\n * shaderBuilder.addFragmentLines([\n * \"void main()\",\n * \"{\",\n * \" #ifdef SOLID_COLOR\",\n * \" out_FragColor = vec4(u_color, 1.0);\",\n * \" #else\",\n * \" out_FragColor = vec4(v_color, 1.0);\",\n * \" #endif\",\n * \"}\"\n * ]);\n * const shaderProgram = shaderBuilder.build(context);\n *\n * @private\n */\nfunction ShaderBuilder() {\n // Some WebGL implementations require attribute 0 to always\n // be active, so the position attribute is tracked separately\n this._positionAttributeLine = undefined;\n this._nextAttributeLocation = 1;\n this._attributeLocations = {};\n this._attributeLines = [];\n\n // Dynamically-generated structs and functions\n // these are dictionaries of id -> ShaderStruct or ShaderFunction respectively\n this._structs = {};\n this._functions = {};\n\n this._vertexShaderParts = {\n defineLines: [],\n uniformLines: [],\n shaderLines: [],\n varyingLines: [],\n // identifiers of structs/functions to include, listed in insertion order\n structIds: [],\n functionIds: [],\n };\n this._fragmentShaderParts = {\n defineLines: [],\n uniformLines: [],\n shaderLines: [],\n varyingLines: [],\n // identifiers of structs/functions to include, listed in insertion order\n structIds: [],\n functionIds: [],\n };\n}\n\nObject.defineProperties(ShaderBuilder.prototype, {\n /**\n * Get a dictionary of attribute names to the integer location in\n * the vertex shader.\n *\n * @memberof ShaderBuilder.prototype\n * @type {Object}\n * @readonly\n * @private\n */\n attributeLocations: {\n get: function () {\n return this._attributeLocations;\n },\n },\n});\n\n/**\n * Add a #define macro to one or both of the shaders. These lines\n * will appear at the top of the final shader source.\n *\n * @param {string} identifier An identifier for the macro. Identifiers must use uppercase letters with underscores to be consistent with Cesium's style guide.\n * @param {string} [value] The value of the macro. If undefined, the define will not include a value. The value will be converted to GLSL code via toString()\n * @param {ShaderDestination} [destination=ShaderDestination.BOTH] Whether the define appears in the vertex shader, the fragment shader, or both.\n *\n * @example\n * // creates the line \"#define ENABLE_LIGHTING\" in both shaders\n * shaderBuilder.addDefine(\"ENABLE_LIGHTING\");\n * // creates the line \"#define PI 3.141592\" in the fragment shader\n * shaderBuilder.addDefine(\"PI\", 3.141593, ShaderDestination.FRAGMENT);\n */\nShaderBuilder.prototype.addDefine = function (identifier, value, destination) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"identifier\", identifier);\n //>>includeEnd('debug');\n\n destination = defaultValue(destination, ShaderDestination.BOTH);\n\n // The ShaderSource created in build() will add the #define part\n let line = identifier;\n if (defined(value)) {\n line += ` ${value.toString()}`;\n }\n\n if (ShaderDestination.includesVertexShader(destination)) {\n this._vertexShaderParts.defineLines.push(line);\n }\n\n if (ShaderDestination.includesFragmentShader(destination)) {\n this._fragmentShaderParts.defineLines.push(line);\n }\n};\n\n/**\n * Add a new dynamically-generated struct to the shader\n * @param {string} structId A unique ID to identify this struct in {@link ShaderBuilder#addStructField}\n * @param {string} structName The name of the struct as it will appear in the shader.\n * @param {ShaderDestination} destination Whether the struct will appear in the vertex shader, the fragment shader, or both.\n *\n * @example\n * // generates the following struct in the fragment shader\n * // struct TestStruct\n * // {\n * // };\n * shaderBuilder.addStruct(\"testStructId\", \"TestStruct\", ShaderDestination.FRAGMENT);\n */\nShaderBuilder.prototype.addStruct = function (\n structId,\n structName,\n destination\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"structId\", structId);\n Check.typeOf.string(\"structName\", structName);\n Check.typeOf.number(\"destination\", destination);\n //>>includeEnd('debug');\n this._structs[structId] = new ShaderStruct(structName);\n if (ShaderDestination.includesVertexShader(destination)) {\n this._vertexShaderParts.structIds.push(structId);\n }\n\n if (ShaderDestination.includesFragmentShader(destination)) {\n this._fragmentShaderParts.structIds.push(structId);\n }\n};\n\n/**\n * Add a field to a dynamically-generated struct.\n * @param {string} structId The ID of the struct. This must be created first with {@link ShaderBuilder#addStruct}\n * @param {string} type The GLSL type of the field\n * @param {string} identifier The identifier of the field.\n *\n * @example\n * // generates the following struct in the fragment shader\n * // struct TestStruct\n * // {\n * // float minimum;\n * // float maximum;\n * // };\n * shaderBuilder.addStruct(\"testStructId\", \"TestStruct\", ShaderDestination.FRAGMENT);\n * shaderBuilder.addStructField(\"testStructId\", \"float\", \"maximum\");\n * shaderBuilder.addStructField(\"testStructId\", \"float\", \"minimum\");\n */\nShaderBuilder.prototype.addStructField = function (structId, type, identifier) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"structId\", structId);\n Check.typeOf.string(\"type\", type);\n Check.typeOf.string(\"identifier\", identifier);\n //>>includeEnd('debug');\n this._structs[structId].addField(type, identifier);\n};\n\n/**\n * Add a new dynamically-generated function to the shader.\n * @param {string} functionName The name of the function. This will be used to identify the function in {@link ShaderBuilder#addFunctionLines}.\n * @param {string} signature The full signature of the function as it will appear in the shader. Do not include the curly braces.\n * @param {ShaderDestination} destination Whether the struct will appear in the vertex shader, the fragment shader, or both.\n * @example\n * // generates the following function in the vertex shader\n * // vec3 testFunction(float parameter)\n * // {\n * // }\n * shaderBuilder.addStruct(\"testFunction\", \"vec3 testFunction(float parameter)\", ShaderDestination.VERTEX);\n */\nShaderBuilder.prototype.addFunction = function (\n functionName,\n signature,\n destination\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"functionName\", functionName);\n Check.typeOf.string(\"signature\", signature);\n Check.typeOf.number(\"destination\", destination);\n //>>includeEnd('debug');\n this._functions[functionName] = new ShaderFunction(signature);\n\n if (ShaderDestination.includesVertexShader(destination)) {\n this._vertexShaderParts.functionIds.push(functionName);\n }\n\n if (ShaderDestination.includesFragmentShader(destination)) {\n this._fragmentShaderParts.functionIds.push(functionName);\n }\n};\n\n/**\n * Add lines to a dynamically-generated function\n * @param {string} functionName The name of the function. This must be created beforehand using {@link ShaderBuilder#addFunction}\n * @param {string|string[]} lines One or more lines of GLSL code to add to the function body. Do not include any preceding or ending whitespace, but do include the semicolon for each line.\n *\n * @example\n * // generates the following function in the vertex shader\n * // vec3 testFunction(float parameter)\n * // {\n * // float signed = 2.0 * parameter - 1.0;\n * // return vec3(signed, 0.0, 0.0);\n * // }\n * shaderBuilder.addStruct(\"testFunction\", \"vec3 testFunction(float parameter)\", ShaderDestination.VERTEX);\n * shaderBuilder.addFunctionLines(\"testFunction\", [\n * \"float signed = 2.0 * parameter - 1.0;\",\n * \"return vec3(parameter);\"\n * ]);\n */\nShaderBuilder.prototype.addFunctionLines = function (functionName, lines) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"functionName\", functionName);\n if (typeof lines !== \"string\" && !Array.isArray(lines)) {\n throw new DeveloperError(\n `Expected lines to be a string or an array of strings, actual value was ${lines}`\n );\n }\n //>>includeEnd('debug');\n this._functions[functionName].addLines(lines);\n};\n\n/**\n * Add a uniform declaration to one or both of the shaders. These lines\n * will appear grouped near the top of the final shader source.\n *\n * @param {string} type The GLSL type of the uniform.\n * @param {string} identifier An identifier for the uniform. Identifiers must begin with u_ to be consistent with Cesium's style guide.\n * @param {ShaderDestination} [destination=ShaderDestination.BOTH] Whether the uniform appears in the vertex shader, the fragment shader, or both.\n *\n * @example\n * // creates the line \"uniform vec3 u_resolution;\"\n * shaderBuilder.addUniform(\"vec3\", \"u_resolution\", ShaderDestination.FRAGMENT);\n * // creates the line \"uniform float u_time;\" in both shaders\n * shaderBuilder.addUniform(\"float\", \"u_time\", ShaderDestination.BOTH);\n */\nShaderBuilder.prototype.addUniform = function (type, identifier, destination) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n Check.typeOf.string(\"identifier\", identifier);\n //>>includeEnd('debug');\n\n destination = defaultValue(destination, ShaderDestination.BOTH);\n const line = `uniform ${type} ${identifier};`;\n\n if (ShaderDestination.includesVertexShader(destination)) {\n this._vertexShaderParts.uniformLines.push(line);\n }\n\n if (ShaderDestination.includesFragmentShader(destination)) {\n this._fragmentShaderParts.uniformLines.push(line);\n }\n};\n\n/**\n * Add a position attribute declaration to the vertex shader. These lines\n * will appear grouped near the top of the final shader source.\n *

\n * Some WebGL implementations require attribute 0 to be enabled, so this is\n * reserved for the position attribute. For all other attributes, see\n * {@link ShaderBuilder#addAttribute}\n *

\n *\n * @param {string} type The GLSL type of the attribute\n * @param {string} identifier An identifier for the attribute. Identifiers must begin with a_ to be consistent with Cesium's style guide.\n * @return {number} The integer location of the attribute. This location can be used when creating attributes for a {@link VertexArray}. This will always be 0.\n *\n * @example\n * // creates the line \"in vec3 a_position;\"\n * shaderBuilder.setPositionAttribute(\"vec3\", \"a_position\");\n */\nShaderBuilder.prototype.setPositionAttribute = function (type, identifier) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n Check.typeOf.string(\"identifier\", identifier);\n\n if (defined(this._positionAttributeLine)) {\n throw new DeveloperError(\n \"setPositionAttribute() must be called exactly once for the attribute used for gl_Position. For other attributes, use addAttribute()\"\n );\n }\n //>>includeEnd('debug');\n\n this._positionAttributeLine = `in ${type} ${identifier};`;\n\n // Some WebGL implementations require attribute 0 to always be active, so\n // this builder assumes the position will always go in location 0\n this._attributeLocations[identifier] = 0;\n return 0;\n};\n\n/**\n * Add an attribute declaration to the vertex shader. These lines\n * will appear grouped near the top of the final shader source.\n *

\n * Some WebGL implementations require attribute 0 to be enabled, so this is\n * reserved for the position attribute. See {@link ShaderBuilder#setPositionAttribute}\n *

\n *\n * @param {string} type The GLSL type of the attribute\n * @param {string} identifier An identifier for the attribute. Identifiers must begin with a_ to be consistent with Cesium's style guide.\n * @return {number} The integer location of the attribute. This location can be used when creating attributes for a {@link VertexArray}\n *\n * @example\n * // creates the line \"in vec2 a_texCoord0;\" in the vertex shader\n * shaderBuilder.addAttribute(\"vec2\", \"a_texCoord0\");\n */\nShaderBuilder.prototype.addAttribute = function (type, identifier) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n Check.typeOf.string(\"identifier\", identifier);\n //>>includeEnd('debug');\n\n const line = `in ${type} ${identifier};`;\n this._attributeLines.push(line);\n\n const location = this._nextAttributeLocation;\n this._attributeLocations[identifier] = location;\n\n // Most attributes only require a single attribute location, but matrices\n // require more.\n this._nextAttributeLocation += getAttributeLocationCount(type);\n return location;\n};\n\n/**\n * Add a varying declaration to both the vertex and fragment shaders.\n *\n * @param {string} type The GLSL type of the varying\n * @param {string} identifier An identifier for the varying. Identifiers must begin with v_ to be consistent with Cesium's style guide.\n *\n * @example\n * // creates the line \"in vec3 v_color;\" in the vertex shader\n * // creates the line \"out vec3 v_color;\" in the fragment shader\n * shaderBuilder.addVarying(\"vec3\", \"v_color\");\n */\nShaderBuilder.prototype.addVarying = function (type, identifier) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n Check.typeOf.string(\"identifier\", identifier);\n //>>includeEnd('debug');\n\n const line = `${type} ${identifier};`;\n this._vertexShaderParts.varyingLines.push(`out ${line}`);\n this._fragmentShaderParts.varyingLines.push(`in ${line}`);\n};\n\n/**\n * Appends lines of GLSL code to the vertex shader\n *\n * @param {string|string[]} lines One or more lines to add to the end of the vertex shader source\n *\n * @example\n * shaderBuilder.addVertexLines([\n * \"void main()\",\n * \"{\",\n * \" v_color = a_color;\",\n * \" gl_Position = vec4(a_position, 1.0);\",\n * \"}\"\n * ]);\n */\nShaderBuilder.prototype.addVertexLines = function (lines) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof lines !== \"string\" && !Array.isArray(lines)) {\n throw new DeveloperError(\n `Expected lines to be a string or an array of strings, actual value was ${lines}`\n );\n }\n //>>includeEnd('debug');\n\n const vertexLines = this._vertexShaderParts.shaderLines;\n if (Array.isArray(lines)) {\n vertexLines.push.apply(vertexLines, lines);\n } else {\n // Single string case\n vertexLines.push(lines);\n }\n};\n\n/**\n * Appends lines of GLSL code to the fragment shader\n *\n * @param {string[]} lines The lines to add to the end of the fragment shader source\n *\n * @example\n * shaderBuilder.addFragmentLines([\n * \"void main()\",\n * \"{\",\n * \" #ifdef SOLID_COLOR\",\n * \" out_FragColor = vec4(u_color, 1.0);\",\n * \" #else\",\n * \" out_FragColor = vec4(v_color, 1.0);\",\n * \" #endif\",\n * \"}\"\n * ]);\n */\nShaderBuilder.prototype.addFragmentLines = function (lines) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof lines !== \"string\" && !Array.isArray(lines)) {\n throw new DeveloperError(\n `Expected lines to be a string or an array of strings, actual value was ${lines}`\n );\n }\n //>>includeEnd('debug');\n\n const fragmentLines = this._fragmentShaderParts.shaderLines;\n if (Array.isArray(lines)) {\n fragmentLines.push.apply(fragmentLines, lines);\n } else {\n // Single string case\n fragmentLines.push(lines);\n }\n};\n\n/**\n * Builds the {@link ShaderProgram} from the pieces added by the other methods.\n * Call this one time at the end of modifying the shader through the other\n * methods in this class.\n *\n * @param {Context} context The context to use for creating the shader.\n * @return {ShaderProgram} A shader program to use for rendering.\n *\n * @example\n * const shaderProgram = shaderBuilder.buildShaderProgram(context);\n */\nShaderBuilder.prototype.buildShaderProgram = function (context) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"context\", context);\n //>>includeEnd('debug');\n\n const positionAttribute = defined(this._positionAttributeLine)\n ? [this._positionAttributeLine]\n : [];\n\n const structLines = generateStructLines(this);\n const functionLines = generateFunctionLines(this);\n\n // Lines are joined here so the ShaderSource\n // generates a single #line 0 directive\n const vertexLines = positionAttribute\n .concat(\n this._attributeLines,\n this._vertexShaderParts.uniformLines,\n this._vertexShaderParts.varyingLines,\n structLines.vertexLines,\n functionLines.vertexLines,\n this._vertexShaderParts.shaderLines\n )\n .join(\"\\n\");\n const vertexShaderSource = new ShaderSource({\n defines: this._vertexShaderParts.defineLines,\n sources: [vertexLines],\n });\n\n const fragmentLines = this._fragmentShaderParts.uniformLines\n .concat(\n this._fragmentShaderParts.varyingLines,\n structLines.fragmentLines,\n functionLines.fragmentLines,\n this._fragmentShaderParts.shaderLines\n )\n .join(\"\\n\");\n const fragmentShaderSource = new ShaderSource({\n defines: this._fragmentShaderParts.defineLines,\n sources: [fragmentLines],\n });\n\n return ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vertexShaderSource,\n fragmentShaderSource: fragmentShaderSource,\n attributeLocations: this._attributeLocations,\n });\n};\n\nShaderBuilder.prototype.clone = function () {\n return clone(this, true);\n};\n\nfunction generateStructLines(shaderBuilder) {\n const vertexLines = [];\n const fragmentLines = [];\n\n let i;\n let structIds = shaderBuilder._vertexShaderParts.structIds;\n let structId;\n let struct;\n let structLines;\n for (i = 0; i < structIds.length; i++) {\n structId = structIds[i];\n struct = shaderBuilder._structs[structId];\n structLines = struct.generateGlslLines();\n vertexLines.push.apply(vertexLines, structLines);\n }\n\n structIds = shaderBuilder._fragmentShaderParts.structIds;\n for (i = 0; i < structIds.length; i++) {\n structId = structIds[i];\n struct = shaderBuilder._structs[structId];\n structLines = struct.generateGlslLines();\n fragmentLines.push.apply(fragmentLines, structLines);\n }\n\n return {\n vertexLines: vertexLines,\n fragmentLines: fragmentLines,\n };\n}\n\nfunction getAttributeLocationCount(glslType) {\n switch (glslType) {\n case \"mat2\":\n return 2;\n case \"mat3\":\n return 3;\n case \"mat4\":\n return 4;\n default:\n return 1;\n }\n}\n\nfunction generateFunctionLines(shaderBuilder) {\n const vertexLines = [];\n const fragmentLines = [];\n\n let i;\n let functionIds = shaderBuilder._vertexShaderParts.functionIds;\n let functionId;\n let func;\n let functionLines;\n for (i = 0; i < functionIds.length; i++) {\n functionId = functionIds[i];\n func = shaderBuilder._functions[functionId];\n functionLines = func.generateGlslLines();\n vertexLines.push.apply(vertexLines, functionLines);\n }\n\n functionIds = shaderBuilder._fragmentShaderParts.functionIds;\n for (i = 0; i < functionIds.length; i++) {\n functionId = functionIds[i];\n func = shaderBuilder._functions[functionId];\n functionLines = func.generateGlslLines();\n fragmentLines.push.apply(fragmentLines, functionLines);\n }\n\n return {\n vertexLines: vertexLines,\n fragmentLines: fragmentLines,\n };\n}\n\nexport default ShaderBuilder;\n", "import Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Buffer from \"./Buffer.js\";\nimport BufferUsage from \"./BufferUsage.js\";\nimport VertexArray from \"./VertexArray.js\";\n\n/**\n * @private\n */\nfunction VertexArrayFacade(context, attributes, sizeInVertices, instanced) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"context\", context);\n if (!attributes || attributes.length === 0) {\n throw new DeveloperError(\"At least one attribute is required.\");\n }\n //>>includeEnd('debug');\n\n const attrs = VertexArrayFacade._verifyAttributes(attributes);\n sizeInVertices = defaultValue(sizeInVertices, 0);\n const precreatedAttributes = [];\n const attributesByUsage = {};\n let attributesForUsage;\n let usage;\n\n // Bucket the attributes by usage.\n const length = attrs.length;\n for (let i = 0; i < length; ++i) {\n const attribute = attrs[i];\n\n // If the attribute already has a vertex buffer, we do not need\n // to manage a vertex buffer or typed array for it.\n if (attribute.vertexBuffer) {\n precreatedAttributes.push(attribute);\n continue;\n }\n\n usage = attribute.usage;\n attributesForUsage = attributesByUsage[usage];\n if (!defined(attributesForUsage)) {\n attributesForUsage = attributesByUsage[usage] = [];\n }\n\n attributesForUsage.push(attribute);\n }\n\n // A function to sort attributes by the size of their components. From left to right, a vertex\n // stores floats, shorts, and then bytes.\n function compare(left, right) {\n return (\n ComponentDatatype.getSizeInBytes(right.componentDatatype) -\n ComponentDatatype.getSizeInBytes(left.componentDatatype)\n );\n }\n\n this._allBuffers = [];\n\n for (usage in attributesByUsage) {\n if (attributesByUsage.hasOwnProperty(usage)) {\n attributesForUsage = attributesByUsage[usage];\n\n attributesForUsage.sort(compare);\n const vertexSizeInBytes = VertexArrayFacade._vertexSizeInBytes(\n attributesForUsage\n );\n\n const bufferUsage = attributesForUsage[0].usage;\n\n const buffer = {\n vertexSizeInBytes: vertexSizeInBytes,\n vertexBuffer: undefined,\n usage: bufferUsage,\n needsCommit: false,\n arrayBuffer: undefined,\n arrayViews: VertexArrayFacade._createArrayViews(\n attributesForUsage,\n vertexSizeInBytes\n ),\n };\n\n this._allBuffers.push(buffer);\n }\n }\n\n this._size = 0;\n this._instanced = defaultValue(instanced, false);\n\n this._precreated = precreatedAttributes;\n this._context = context;\n\n this.writers = undefined;\n this.va = undefined;\n\n this.resize(sizeInVertices);\n}\nVertexArrayFacade._verifyAttributes = function (attributes) {\n const attrs = [];\n\n for (let i = 0; i < attributes.length; ++i) {\n const attribute = attributes[i];\n\n const attr = {\n index: defaultValue(attribute.index, i),\n enabled: defaultValue(attribute.enabled, true),\n componentsPerAttribute: attribute.componentsPerAttribute,\n componentDatatype: defaultValue(\n attribute.componentDatatype,\n ComponentDatatype.FLOAT\n ),\n normalize: defaultValue(attribute.normalize, false),\n\n // There will be either a vertexBuffer or an [optional] usage.\n vertexBuffer: attribute.vertexBuffer,\n usage: defaultValue(attribute.usage, BufferUsage.STATIC_DRAW),\n };\n attrs.push(attr);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n attr.componentsPerAttribute !== 1 &&\n attr.componentsPerAttribute !== 2 &&\n attr.componentsPerAttribute !== 3 &&\n attr.componentsPerAttribute !== 4\n ) {\n throw new DeveloperError(\n \"attribute.componentsPerAttribute must be in the range [1, 4].\"\n );\n }\n\n const datatype = attr.componentDatatype;\n if (!ComponentDatatype.validate(datatype)) {\n throw new DeveloperError(\n \"Attribute must have a valid componentDatatype or not specify it.\"\n );\n }\n\n if (!BufferUsage.validate(attr.usage)) {\n throw new DeveloperError(\n \"Attribute must have a valid usage or not specify it.\"\n );\n }\n //>>includeEnd('debug');\n }\n\n // Verify all attribute names are unique.\n const uniqueIndices = new Array(attrs.length);\n for (let j = 0; j < attrs.length; ++j) {\n const currentAttr = attrs[j];\n const index = currentAttr.index;\n //>>includeStart('debug', pragmas.debug);\n if (uniqueIndices[index]) {\n throw new DeveloperError(\n `Index ${index} is used by more than one attribute.`\n );\n }\n //>>includeEnd('debug');\n uniqueIndices[index] = true;\n }\n\n return attrs;\n};\n\nVertexArrayFacade._vertexSizeInBytes = function (attributes) {\n let sizeInBytes = 0;\n\n const length = attributes.length;\n for (let i = 0; i < length; ++i) {\n const attribute = attributes[i];\n sizeInBytes +=\n attribute.componentsPerAttribute *\n ComponentDatatype.getSizeInBytes(attribute.componentDatatype);\n }\n\n const maxComponentSizeInBytes =\n length > 0\n ? ComponentDatatype.getSizeInBytes(attributes[0].componentDatatype)\n : 0; // Sorted by size\n const remainder =\n maxComponentSizeInBytes > 0 ? sizeInBytes % maxComponentSizeInBytes : 0;\n const padding = remainder === 0 ? 0 : maxComponentSizeInBytes - remainder;\n sizeInBytes += padding;\n\n return sizeInBytes;\n};\n\nVertexArrayFacade._createArrayViews = function (attributes, vertexSizeInBytes) {\n const views = [];\n let offsetInBytes = 0;\n\n const length = attributes.length;\n for (let i = 0; i < length; ++i) {\n const attribute = attributes[i];\n const componentDatatype = attribute.componentDatatype;\n\n views.push({\n index: attribute.index,\n enabled: attribute.enabled,\n componentsPerAttribute: attribute.componentsPerAttribute,\n componentDatatype: componentDatatype,\n normalize: attribute.normalize,\n\n offsetInBytes: offsetInBytes,\n vertexSizeInComponentType:\n vertexSizeInBytes / ComponentDatatype.getSizeInBytes(componentDatatype),\n\n view: undefined,\n });\n\n offsetInBytes +=\n attribute.componentsPerAttribute *\n ComponentDatatype.getSizeInBytes(componentDatatype);\n }\n\n return views;\n};\n\n/**\n * Invalidates writers. Can't render again until commit is called.\n */\nVertexArrayFacade.prototype.resize = function (sizeInVertices) {\n this._size = sizeInVertices;\n\n const allBuffers = this._allBuffers;\n this.writers = [];\n\n for (let i = 0, len = allBuffers.length; i < len; ++i) {\n const buffer = allBuffers[i];\n\n VertexArrayFacade._resize(buffer, this._size);\n\n // Reserving invalidates the writers, so if client's cache them, they need to invalidate their cache.\n VertexArrayFacade._appendWriters(this.writers, buffer);\n }\n\n // VAs are recreated next time commit is called.\n destroyVA(this);\n};\n\nVertexArrayFacade._resize = function (buffer, size) {\n if (buffer.vertexSizeInBytes > 0) {\n // Create larger array buffer\n const arrayBuffer = new ArrayBuffer(size * buffer.vertexSizeInBytes);\n\n // Copy contents from previous array buffer\n if (defined(buffer.arrayBuffer)) {\n const destView = new Uint8Array(arrayBuffer);\n const sourceView = new Uint8Array(buffer.arrayBuffer);\n const sourceLength = sourceView.length;\n for (let j = 0; j < sourceLength; ++j) {\n destView[j] = sourceView[j];\n }\n }\n\n // Create typed views into the new array buffer\n const views = buffer.arrayViews;\n const length = views.length;\n for (let i = 0; i < length; ++i) {\n const view = views[i];\n view.view = ComponentDatatype.createArrayBufferView(\n view.componentDatatype,\n arrayBuffer,\n view.offsetInBytes\n );\n }\n\n buffer.arrayBuffer = arrayBuffer;\n }\n};\n\nconst createWriters = [\n // 1 component per attribute\n function (buffer, view, vertexSizeInComponentType) {\n return function (index, attribute) {\n view[index * vertexSizeInComponentType] = attribute;\n buffer.needsCommit = true;\n };\n },\n\n // 2 component per attribute\n function (buffer, view, vertexSizeInComponentType) {\n return function (index, component0, component1) {\n const i = index * vertexSizeInComponentType;\n view[i] = component0;\n view[i + 1] = component1;\n buffer.needsCommit = true;\n };\n },\n\n // 3 component per attribute\n function (buffer, view, vertexSizeInComponentType) {\n return function (index, component0, component1, component2) {\n const i = index * vertexSizeInComponentType;\n view[i] = component0;\n view[i + 1] = component1;\n view[i + 2] = component2;\n buffer.needsCommit = true;\n };\n },\n\n // 4 component per attribute\n function (buffer, view, vertexSizeInComponentType) {\n return function (index, component0, component1, component2, component3) {\n const i = index * vertexSizeInComponentType;\n view[i] = component0;\n view[i + 1] = component1;\n view[i + 2] = component2;\n view[i + 3] = component3;\n buffer.needsCommit = true;\n };\n },\n];\n\nVertexArrayFacade._appendWriters = function (writers, buffer) {\n const arrayViews = buffer.arrayViews;\n const length = arrayViews.length;\n for (let i = 0; i < length; ++i) {\n const arrayView = arrayViews[i];\n writers[arrayView.index] = createWriters[\n arrayView.componentsPerAttribute - 1\n ](buffer, arrayView.view, arrayView.vertexSizeInComponentType);\n }\n};\n\nVertexArrayFacade.prototype.commit = function (indexBuffer) {\n let recreateVA = false;\n\n const allBuffers = this._allBuffers;\n let buffer;\n let i;\n let length;\n\n for (i = 0, length = allBuffers.length; i < length; ++i) {\n buffer = allBuffers[i];\n recreateVA = commit(this, buffer) || recreateVA;\n }\n\n ///////////////////////////////////////////////////////////////////////\n\n if (recreateVA || !defined(this.va)) {\n destroyVA(this);\n const va = (this.va = []);\n\n const chunkSize = CesiumMath.SIXTY_FOUR_KILOBYTES - 4; // The 65535 index is reserved for primitive restart. Reserve the last 4 indices so that billboard quads are not broken up.\n const numberOfVertexArrays =\n defined(indexBuffer) && !this._instanced\n ? Math.ceil(this._size / chunkSize)\n : 1;\n for (let k = 0; k < numberOfVertexArrays; ++k) {\n let attributes = [];\n for (i = 0, length = allBuffers.length; i < length; ++i) {\n buffer = allBuffers[i];\n const offset = k * (buffer.vertexSizeInBytes * chunkSize);\n VertexArrayFacade._appendAttributes(\n attributes,\n buffer,\n offset,\n this._instanced\n );\n }\n\n attributes = attributes.concat(this._precreated);\n\n va.push({\n va: new VertexArray({\n context: this._context,\n attributes: attributes,\n indexBuffer: indexBuffer,\n }),\n indicesCount:\n 1.5 *\n (k !== numberOfVertexArrays - 1 ? chunkSize : this._size % chunkSize),\n // TODO: not hardcode 1.5, this assumes 6 indices per 4 vertices (as for Billboard quads).\n });\n }\n }\n};\n\nfunction commit(vertexArrayFacade, buffer) {\n if (buffer.needsCommit && buffer.vertexSizeInBytes > 0) {\n buffer.needsCommit = false;\n\n const vertexBuffer = buffer.vertexBuffer;\n const vertexBufferSizeInBytes =\n vertexArrayFacade._size * buffer.vertexSizeInBytes;\n const vertexBufferDefined = defined(vertexBuffer);\n if (\n !vertexBufferDefined ||\n vertexBuffer.sizeInBytes < vertexBufferSizeInBytes\n ) {\n if (vertexBufferDefined) {\n vertexBuffer.destroy();\n }\n buffer.vertexBuffer = Buffer.createVertexBuffer({\n context: vertexArrayFacade._context,\n typedArray: buffer.arrayBuffer,\n usage: buffer.usage,\n });\n buffer.vertexBuffer.vertexArrayDestroyable = false;\n\n return true; // Created new vertex buffer\n }\n\n buffer.vertexBuffer.copyFromArrayView(buffer.arrayBuffer);\n }\n\n return false; // Did not create new vertex buffer\n}\n\nVertexArrayFacade._appendAttributes = function (\n attributes,\n buffer,\n vertexBufferOffset,\n instanced\n) {\n const arrayViews = buffer.arrayViews;\n const length = arrayViews.length;\n for (let i = 0; i < length; ++i) {\n const view = arrayViews[i];\n\n attributes.push({\n index: view.index,\n enabled: view.enabled,\n componentsPerAttribute: view.componentsPerAttribute,\n componentDatatype: view.componentDatatype,\n normalize: view.normalize,\n vertexBuffer: buffer.vertexBuffer,\n offsetInBytes: vertexBufferOffset + view.offsetInBytes,\n strideInBytes: buffer.vertexSizeInBytes,\n instanceDivisor: instanced ? 1 : 0,\n });\n }\n};\n\nVertexArrayFacade.prototype.subCommit = function (\n offsetInVertices,\n lengthInVertices\n) {\n //>>includeStart('debug', pragmas.debug);\n if (offsetInVertices < 0 || offsetInVertices >= this._size) {\n throw new DeveloperError(\n \"offsetInVertices must be greater than or equal to zero and less than the vertex array size.\"\n );\n }\n if (offsetInVertices + lengthInVertices > this._size) {\n throw new DeveloperError(\n \"offsetInVertices + lengthInVertices cannot exceed the vertex array size.\"\n );\n }\n //>>includeEnd('debug');\n\n const allBuffers = this._allBuffers;\n for (let i = 0, len = allBuffers.length; i < len; ++i) {\n subCommit(allBuffers[i], offsetInVertices, lengthInVertices);\n }\n};\n\nfunction subCommit(buffer, offsetInVertices, lengthInVertices) {\n if (buffer.needsCommit && buffer.vertexSizeInBytes > 0) {\n const byteOffset = buffer.vertexSizeInBytes * offsetInVertices;\n const byteLength = buffer.vertexSizeInBytes * lengthInVertices;\n\n // PERFORMANCE_IDEA: If we want to get really crazy, we could consider updating\n // individual attributes instead of the entire (sub-)vertex.\n //\n // PERFORMANCE_IDEA: Does creating the typed view add too much GC overhead?\n buffer.vertexBuffer.copyFromArrayView(\n new Uint8Array(buffer.arrayBuffer, byteOffset, byteLength),\n byteOffset\n );\n }\n}\n\nVertexArrayFacade.prototype.endSubCommits = function () {\n const allBuffers = this._allBuffers;\n\n for (let i = 0, len = allBuffers.length; i < len; ++i) {\n allBuffers[i].needsCommit = false;\n }\n};\n\nfunction destroyVA(vertexArrayFacade) {\n const va = vertexArrayFacade.va;\n if (!defined(va)) {\n return;\n }\n\n const length = va.length;\n for (let i = 0; i < length; ++i) {\n va[i].va.destroy();\n }\n\n vertexArrayFacade.va = undefined;\n}\n\nVertexArrayFacade.prototype.isDestroyed = function () {\n return false;\n};\n\nVertexArrayFacade.prototype.destroy = function () {\n const allBuffers = this._allBuffers;\n for (let i = 0, len = allBuffers.length; i < len; ++i) {\n const buffer = allBuffers[i];\n buffer.vertexBuffer = buffer.vertexBuffer && buffer.vertexBuffer.destroy();\n }\n\n destroyVA(this);\n\n return destroyObject(this);\n};\nexport default VertexArrayFacade;\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Resource from \"../Core/Resource.js\";\nimport CubeMap from \"./CubeMap.js\";\n\n/**\n * Asynchronously loads six images and creates a cube map. Returns a promise that\n * will resolve to a {@link CubeMap} once loaded, or reject if any image fails to load.\n *\n * @function loadCubeMap\n *\n * @param {Context} context The context to use to create the cube map.\n * @param {object} urls The source URL of each image. See the example below.\n * @param {boolean} [skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the images will be ignored.\n * @returns {Promise} a promise that will resolve to the requested {@link CubeMap} when loaded.\n *\n * @exception {DeveloperError} context is required.\n * @exception {DeveloperError} urls is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.\n *\n *\n * @example\n * Cesium.loadCubeMap(context, {\n * positiveX : 'skybox_px.png',\n * negativeX : 'skybox_nx.png',\n * positiveY : 'skybox_py.png',\n * negativeY : 'skybox_ny.png',\n * positiveZ : 'skybox_pz.png',\n * negativeZ : 'skybox_nz.png'\n * }).then(function(cubeMap) {\n * // use the cubemap\n * }).catch(function(error) {\n * // an error occurred\n * });\n *\n * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}\n * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}\n *\n * @private\n */\nfunction loadCubeMap(context, urls, skipColorSpaceConversion) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"context\", context);\n if (\n !defined(urls) ||\n !defined(urls.positiveX) ||\n !defined(urls.negativeX) ||\n !defined(urls.positiveY) ||\n !defined(urls.negativeY) ||\n !defined(urls.positiveZ) ||\n !defined(urls.negativeZ)\n ) {\n throw new DeveloperError(\n \"urls is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.\"\n );\n }\n //>>includeEnd('debug');\n\n // PERFORMANCE_IDEA: Given the size of some cube maps, we should consider tiling them, which\n // would prevent hiccups when uploading, for example, six 4096x4096 textures to the GPU.\n //\n // Also, it is perhaps acceptable to use the context here in the callbacks, but\n // ideally, we would do it in the primitive's update function.\n const flipOptions = {\n flipY: true,\n skipColorSpaceConversion: skipColorSpaceConversion,\n preferImageBitmap: true,\n };\n\n const facePromises = [\n Resource.createIfNeeded(urls.positiveX).fetchImage(flipOptions),\n Resource.createIfNeeded(urls.negativeX).fetchImage(flipOptions),\n Resource.createIfNeeded(urls.positiveY).fetchImage(flipOptions),\n Resource.createIfNeeded(urls.negativeY).fetchImage(flipOptions),\n Resource.createIfNeeded(urls.positiveZ).fetchImage(flipOptions),\n Resource.createIfNeeded(urls.negativeZ).fetchImage(flipOptions),\n ];\n\n return Promise.all(facePromises).then(function (images) {\n return new CubeMap({\n context: context,\n source: {\n positiveX: images[0],\n negativeX: images[1],\n positiveY: images[2],\n negativeY: images[3],\n positiveZ: images[4],\n negativeZ: images[5],\n },\n });\n });\n}\nexport default loadCubeMap;\n", "import defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\n\n/**\n * A {@link Property} whose value does not change with respect to simulation time.\n *\n * @alias ConstantProperty\n * @constructor\n *\n * @param {*} [value] The property value.\n *\n * @see ConstantPositionProperty\n */\nfunction ConstantProperty(value) {\n this._value = undefined;\n this._hasClone = false;\n this._hasEquals = false;\n this._definitionChanged = new Event();\n this.setValue(value);\n}\n\nObject.defineProperties(ConstantProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * This property always returns true.\n * @memberof ConstantProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n value: true,\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value.\n * @memberof ConstantProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\n/**\n * Gets the value of the property.\n *\n * @param {JulianDate} [time] The time for which to retrieve the value. This parameter is unused since the value does not change with respect to time.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nConstantProperty.prototype.getValue = function (time, result) {\n return this._hasClone ? this._value.clone(result) : this._value;\n};\n\n/**\n * Sets the value of the property.\n *\n * @param {*} value The property value.\n */\nConstantProperty.prototype.setValue = function (value) {\n const oldValue = this._value;\n if (oldValue !== value) {\n const isDefined = defined(value);\n const hasClone = isDefined && typeof value.clone === \"function\";\n const hasEquals = isDefined && typeof value.equals === \"function\";\n\n const changed = !hasEquals || !value.equals(oldValue);\n if (changed) {\n this._hasClone = hasClone;\n this._hasEquals = hasEquals;\n this._value = !hasClone ? value : value.clone(this._value);\n this._definitionChanged.raiseEvent(this);\n }\n }\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nConstantProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof ConstantProperty && //\n ((!this._hasEquals && this._value === other._value) || //\n (this._hasEquals && this._value.equals(other._value))))\n );\n};\n\n/**\n * Gets this property's value.\n *\n * @returns {*} This property's value.\n */\nConstantProperty.prototype.valueOf = function () {\n return this._value;\n};\n\n/**\n * Creates a string representing this property's value.\n *\n * @returns {string} A string representing the property's value.\n */\nConstantProperty.prototype.toString = function () {\n return String(this._value);\n};\nexport default ConstantProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\n\nfunction createProperty(\n name,\n privateName,\n subscriptionName,\n configurable,\n createPropertyCallback\n) {\n return {\n configurable: configurable,\n get: function () {\n return this[privateName];\n },\n set: function (value) {\n const oldValue = this[privateName];\n const subscription = this[subscriptionName];\n if (defined(subscription)) {\n subscription();\n this[subscriptionName] = undefined;\n }\n\n const hasValue = value !== undefined;\n if (\n hasValue &&\n (!defined(value) || !defined(value.getValue)) &&\n defined(createPropertyCallback)\n ) {\n value = createPropertyCallback(value);\n }\n\n if (oldValue !== value) {\n this[privateName] = value;\n this._definitionChanged.raiseEvent(this, name, value, oldValue);\n }\n\n if (defined(value) && defined(value.definitionChanged)) {\n this[subscriptionName] = value.definitionChanged.addEventListener(\n function () {\n this._definitionChanged.raiseEvent(this, name, value, value);\n },\n this\n );\n }\n },\n };\n}\n\nfunction createConstantProperty(value) {\n return new ConstantProperty(value);\n}\n\n/**\n * Used to consistently define all DataSources graphics objects.\n * This is broken into two functions because the Chrome profiler does a better\n * job of optimizing lookups if it notices that the string is constant throughout the function.\n * @private\n */\nfunction createPropertyDescriptor(name, configurable, createPropertyCallback) {\n //Safari 8.0.3 has a JavaScript bug that causes it to confuse two variables and treat them as the same.\n //The two extra toString calls work around the issue.\n return createProperty(\n name,\n `_${name.toString()}`,\n `_${name.toString()}Subscription`,\n defaultValue(configurable, false),\n defaultValue(createPropertyCallback, createConstantProperty)\n );\n}\nexport default createPropertyDescriptor;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} BillboardGraphics.ConstructorOptions\n *\n * Initialization options for the BillboardGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the billboard.\n * @property {Property | string | HTMLCanvasElement} [image] A Property specifying the Image, URI, or Canvas to use for the billboard.\n * @property {Property | number} [scale=1.0] A numeric Property specifying the scale to apply to the image size.\n * @property {Property | Cartesian2} [pixelOffset=Cartesian2.ZERO] A {@link Cartesian2} Property specifying the pixel offset.\n * @property {Property | Cartesian3} [eyeOffset=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the eye offset.\n * @property {Property | HorizontalOrigin} [horizontalOrigin=HorizontalOrigin.CENTER] A Property specifying the {@link HorizontalOrigin}.\n * @property {Property | VerticalOrigin} [verticalOrigin=VerticalOrigin.CENTER] A Property specifying the {@link VerticalOrigin}.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | Color} [color=Color.WHITE] A Property specifying the tint {@link Color} of the image.\n * @property {Property | number} [rotation=0] A numeric Property specifying the rotation about the alignedAxis.\n * @property {Property | Cartesian3} [alignedAxis=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the unit vector axis of rotation.\n * @property {Property | boolean} [sizeInMeters] A boolean Property specifying whether this billboard's size should be measured in meters.\n * @property {Property | number} [width] A numeric Property specifying the width of the billboard in pixels, overriding the native size.\n * @property {Property | number} [height] A numeric Property specifying the height of the billboard in pixels, overriding the native size.\n * @property {Property | NearFarScalar} [scaleByDistance] A {@link NearFarScalar} Property used to scale the point based on distance from the camera.\n * @property {Property | NearFarScalar} [translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.\n * @property {Property | NearFarScalar} [pixelOffsetScaleByDistance] A {@link NearFarScalar} Property used to set pixelOffset based on distance from the camera.\n * @property {Property | BoundingRectangle} [imageSubRegion] A Property specifying a {@link BoundingRectangle} that defines a sub-region of the image to use for the billboard, rather than the entire image, measured in pixels from the bottom-left.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this billboard will be displayed.\n * @property {Property | number} [disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.\n */\n\n/**\n * Describes a two dimensional icon located at the position of the containing {@link Entity}.\n *

\n *

\n *
\n * Example billboards\n *
\n *

\n *\n * @alias BillboardGraphics\n * @constructor\n *\n * @param {BillboardGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo}\n */\nfunction BillboardGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._image = undefined;\n this._imageSubscription = undefined;\n this._scale = undefined;\n this._scaleSubscription = undefined;\n this._pixelOffset = undefined;\n this._pixelOffsetSubscription = undefined;\n this._eyeOffset = undefined;\n this._eyeOffsetSubscription = undefined;\n this._horizontalOrigin = undefined;\n this._horizontalOriginSubscription = undefined;\n this._verticalOrigin = undefined;\n this._verticalOriginSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._color = undefined;\n this._colorSubscription = undefined;\n this._rotation = undefined;\n this._rotationSubscription = undefined;\n this._alignedAxis = undefined;\n this._alignedAxisSubscription = undefined;\n this._sizeInMeters = undefined;\n this._sizeInMetersSubscription = undefined;\n this._width = undefined;\n this._widthSubscription = undefined;\n this._height = undefined;\n this._heightSubscription = undefined;\n this._scaleByDistance = undefined;\n this._scaleByDistanceSubscription = undefined;\n this._translucencyByDistance = undefined;\n this._translucencyByDistanceSubscription = undefined;\n this._pixelOffsetScaleByDistance = undefined;\n this._pixelOffsetScaleByDistanceSubscription = undefined;\n this._imageSubRegion = undefined;\n this._imageSubRegionSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._disableDepthTestDistance = undefined;\n this._disableDepthTestDistanceSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(BillboardGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof BillboardGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the billboard.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the Image, URI, or Canvas to use for the billboard.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n image: createPropertyDescriptor(\"image\"),\n\n /**\n * Gets or sets the numeric Property specifying the uniform scale to apply to the image.\n * A scale greater than 1.0 enlarges the billboard while a scale less than 1.0 shrinks it.\n *

\n *

\n *
\n * From left to right in the above image, the scales are 0.5, 1.0, and 2.0.\n *
\n *

\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n scale: createPropertyDescriptor(\"scale\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the billboard's pixel offset in screen space\n * from the origin of this billboard. This is commonly used to align multiple billboards and labels at\n * the same position, e.g., an image and text. The screen space origin is the top, left corner of the\n * canvas; x increases from left to right, and y increases from top to bottom.\n *

\n *

\n * \n * \n * \n *
default
b.pixeloffset = new Cartesian2(50, 25);
\n * The billboard's origin is indicated by the yellow point.\n *
\n *

\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default Cartesian2.ZERO\n */\n pixelOffset: createPropertyDescriptor(\"pixelOffset\"),\n\n /**\n * Gets or sets the {@link Cartesian3} Property specifying the billboard's offset in eye coordinates.\n * Eye coordinates is a left-handed coordinate system, where x points towards the viewer's\n * right, y points up, and z points into the screen.\n *

\n * An eye offset is commonly used to arrange multiple billboards or objects at the same position, e.g., to\n * arrange a billboard above its corresponding 3D model.\n *

\n * Below, the billboard is positioned at the center of the Earth but an eye offset makes it always\n * appear on top of the Earth regardless of the viewer's or Earth's orientation.\n *

\n *

\n * \n * \n * \n *
\n * b.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);\n *
\n *

\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default Cartesian3.ZERO\n */\n eyeOffset: createPropertyDescriptor(\"eyeOffset\"),\n\n /**\n * Gets or sets the Property specifying the {@link HorizontalOrigin}.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default HorizontalOrigin.CENTER\n */\n horizontalOrigin: createPropertyDescriptor(\"horizontalOrigin\"),\n\n /**\n * Gets or sets the Property specifying the {@link VerticalOrigin}.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default VerticalOrigin.CENTER\n */\n verticalOrigin: createPropertyDescriptor(\"verticalOrigin\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} that is multiplied with the image.\n * This has two common use cases. First, the same white texture may be used by many different billboards,\n * each with a different color, to create colored billboards. Second, the color's alpha component can be\n * used to make the billboard translucent as shown below. An alpha of 0.0 makes the billboard\n * transparent, and 1.0 makes the billboard opaque.\n *

\n *

\n * \n * \n * \n *
default
alpha : 0.5
\n *
\n *

\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the numeric Property specifying the rotation of the image\n * counter clockwise from the alignedAxis.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n rotation: createPropertyDescriptor(\"rotation\"),\n\n /**\n * Gets or sets the {@link Cartesian3} Property specifying the unit vector axis of rotation\n * in the fixed frame. When set to Cartesian3.ZERO the rotation is from the top of the screen.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default Cartesian3.ZERO\n */\n alignedAxis: createPropertyDescriptor(\"alignedAxis\"),\n\n /**\n * Gets or sets the boolean Property specifying if this billboard's size will be measured in meters.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n sizeInMeters: createPropertyDescriptor(\"sizeInMeters\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the billboard in pixels.\n * When undefined, the native width is used.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n width: createPropertyDescriptor(\"width\"),\n\n /**\n * Gets or sets the numeric Property specifying the height of the billboard in pixels.\n * When undefined, the native height is used.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n height: createPropertyDescriptor(\"height\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the scale of the billboard based on the distance from the camera.\n * A billboard's scale will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's scale remains clamped to the nearest bound.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n scaleByDistance: createPropertyDescriptor(\"scaleByDistance\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the translucency of the billboard based on the distance from the camera.\n * A billboard's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's translucency remains clamped to the nearest bound.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n translucencyByDistance: createPropertyDescriptor(\"translucencyByDistance\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the pixel offset of the billboard based on the distance from the camera.\n * A billboard's pixel offset will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's pixel offset remains clamped to the nearest bound.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n pixelOffsetScaleByDistance: createPropertyDescriptor(\n \"pixelOffsetScaleByDistance\"\n ),\n\n /**\n * Gets or sets the Property specifying a {@link BoundingRectangle} that defines a\n * sub-region of the image to use for the billboard, rather than the entire image,\n * measured in pixels from the bottom-left.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n imageSubRegion: createPropertyDescriptor(\"imageSubRegion\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this billboard will be displayed.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof BillboardGraphics.prototype\n * @type {Property|undefined}\n */\n disableDepthTestDistance: createPropertyDescriptor(\n \"disableDepthTestDistance\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {BillboardGraphics} [result] The object onto which to store the result.\n * @returns {BillboardGraphics} The modified result parameter or a new instance if one was not provided.\n */\nBillboardGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new BillboardGraphics(this);\n }\n result.show = this._show;\n result.image = this._image;\n result.scale = this._scale;\n result.pixelOffset = this._pixelOffset;\n result.eyeOffset = this._eyeOffset;\n result.horizontalOrigin = this._horizontalOrigin;\n result.verticalOrigin = this._verticalOrigin;\n result.heightReference = this._heightReference;\n result.color = this._color;\n result.rotation = this._rotation;\n result.alignedAxis = this._alignedAxis;\n result.sizeInMeters = this._sizeInMeters;\n result.width = this._width;\n result.height = this._height;\n result.scaleByDistance = this._scaleByDistance;\n result.translucencyByDistance = this._translucencyByDistance;\n result.pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;\n result.imageSubRegion = this._imageSubRegion;\n result.distanceDisplayCondition = this._distanceDisplayCondition;\n result.disableDepthTestDistance = this._disableDepthTestDistance;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {BillboardGraphics} source The object to be merged into this object.\n */\nBillboardGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this._show, source.show);\n this.image = defaultValue(this._image, source.image);\n this.scale = defaultValue(this._scale, source.scale);\n this.pixelOffset = defaultValue(this._pixelOffset, source.pixelOffset);\n this.eyeOffset = defaultValue(this._eyeOffset, source.eyeOffset);\n this.horizontalOrigin = defaultValue(\n this._horizontalOrigin,\n source.horizontalOrigin\n );\n this.verticalOrigin = defaultValue(\n this._verticalOrigin,\n source.verticalOrigin\n );\n this.heightReference = defaultValue(\n this._heightReference,\n source.heightReference\n );\n this.color = defaultValue(this._color, source.color);\n this.rotation = defaultValue(this._rotation, source.rotation);\n this.alignedAxis = defaultValue(this._alignedAxis, source.alignedAxis);\n this.sizeInMeters = defaultValue(this._sizeInMeters, source.sizeInMeters);\n this.width = defaultValue(this._width, source.width);\n this.height = defaultValue(this._height, source.height);\n this.scaleByDistance = defaultValue(\n this._scaleByDistance,\n source.scaleByDistance\n );\n this.translucencyByDistance = defaultValue(\n this._translucencyByDistance,\n source.translucencyByDistance\n );\n this.pixelOffsetScaleByDistance = defaultValue(\n this._pixelOffsetScaleByDistance,\n source.pixelOffsetScaleByDistance\n );\n this.imageSubRegion = defaultValue(\n this._imageSubRegion,\n source.imageSubRegion\n );\n this.distanceDisplayCondition = defaultValue(\n this._distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.disableDepthTestDistance = defaultValue(\n this._disableDepthTestDistance,\n source.disableDepthTestDistance\n );\n};\nexport default BillboardGraphics;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A collection of key-value pairs that is stored as a hash for easy\n * lookup but also provides an array for fast iteration.\n * @alias AssociativeArray\n * @constructor\n */\nfunction AssociativeArray() {\n this._array = [];\n this._hash = {};\n}\n\nObject.defineProperties(AssociativeArray.prototype, {\n /**\n * Gets the number of items in the collection.\n * @memberof AssociativeArray.prototype\n *\n * @type {number}\n */\n length: {\n get: function () {\n return this._array.length;\n },\n },\n /**\n * Gets an unordered array of all values in the collection.\n * This is a live array that will automatically reflect the values in the collection,\n * it should not be modified directly.\n * @memberof AssociativeArray.prototype\n *\n * @type {Array}\n */\n values: {\n get: function () {\n return this._array;\n },\n },\n});\n\n/**\n * Determines if the provided key is in the array.\n *\n * @param {string|number} key The key to check.\n * @returns {boolean} true if the key is in the array, false otherwise.\n */\nAssociativeArray.prototype.contains = function (key) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof key !== \"string\" && typeof key !== \"number\") {\n throw new DeveloperError(\"key is required to be a string or number.\");\n }\n //>>includeEnd('debug');\n return defined(this._hash[key]);\n};\n\n/**\n * Associates the provided key with the provided value. If the key already\n * exists, it is overwritten with the new value.\n *\n * @param {string|number} key A unique identifier.\n * @param {*} value The value to associate with the provided key.\n */\nAssociativeArray.prototype.set = function (key, value) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof key !== \"string\" && typeof key !== \"number\") {\n throw new DeveloperError(\"key is required to be a string or number.\");\n }\n //>>includeEnd('debug');\n\n const oldValue = this._hash[key];\n if (value !== oldValue) {\n this.remove(key);\n this._hash[key] = value;\n this._array.push(value);\n }\n};\n\n/**\n * Retrieves the value associated with the provided key.\n *\n * @param {string|number} key The key whose value is to be retrieved.\n * @returns {*} The associated value, or undefined if the key does not exist in the collection.\n */\nAssociativeArray.prototype.get = function (key) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof key !== \"string\" && typeof key !== \"number\") {\n throw new DeveloperError(\"key is required to be a string or number.\");\n }\n //>>includeEnd('debug');\n return this._hash[key];\n};\n\n/**\n * Removes a key-value pair from the collection.\n *\n * @param {string|number} key The key to be removed.\n * @returns {boolean} True if it was removed, false if the key was not in the collection.\n */\nAssociativeArray.prototype.remove = function (key) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(key) && typeof key !== \"string\" && typeof key !== \"number\") {\n throw new DeveloperError(\"key is required to be a string or number.\");\n }\n //>>includeEnd('debug');\n\n const value = this._hash[key];\n const hasValue = defined(value);\n if (hasValue) {\n const array = this._array;\n array.splice(array.indexOf(value), 1);\n delete this._hash[key];\n }\n return hasValue;\n};\n\n/**\n * Clears the collection.\n */\nAssociativeArray.prototype.removeAll = function () {\n const array = this._array;\n if (array.length > 0) {\n this._hash = {};\n array.length = 0;\n }\n};\nexport default AssociativeArray;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Determines visibility based on the distance to the camera.\n *\n * @alias DistanceDisplayCondition\n * @constructor\n *\n * @param {number} [near=0.0] The smallest distance in the interval where the object is visible.\n * @param {number} [far=Number.MAX_VALUE] The largest distance in the interval where the object is visible.\n *\n * @example\n * // Make a billboard that is only visible when the distance to the camera is between 10 and 20 meters.\n * billboard.distanceDisplayCondition = new Cesium.DistanceDisplayCondition(10.0, 20.0);\n */\nfunction DistanceDisplayCondition(near, far) {\n near = defaultValue(near, 0.0);\n this._near = near;\n\n far = defaultValue(far, Number.MAX_VALUE);\n this._far = far;\n}\n\nObject.defineProperties(DistanceDisplayCondition.prototype, {\n /**\n * The smallest distance in the interval where the object is visible.\n * @memberof DistanceDisplayCondition.prototype\n * @type {number}\n * @default 0.0\n */\n near: {\n get: function () {\n return this._near;\n },\n set: function (value) {\n this._near = value;\n },\n },\n /**\n * The largest distance in the interval where the object is visible.\n * @memberof DistanceDisplayCondition.prototype\n * @type {number}\n * @default Number.MAX_VALUE\n */\n far: {\n get: function () {\n return this._far;\n },\n set: function (value) {\n this._far = value;\n },\n },\n});\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nDistanceDisplayCondition.packedLength = 2;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {DistanceDisplayCondition} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nDistanceDisplayCondition.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.near;\n array[startingIndex] = value.far;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {DistanceDisplayCondition} [result] The object into which to store the result.\n * @returns {DistanceDisplayCondition} The modified result parameter or a new DistanceDisplayCondition instance if one was not provided.\n */\nDistanceDisplayCondition.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new DistanceDisplayCondition();\n }\n result.near = array[startingIndex++];\n result.far = array[startingIndex];\n return result;\n};\n\n/**\n * Determines if two distance display conditions are equal.\n *\n * @param {DistanceDisplayCondition} left A distance display condition.\n * @param {DistanceDisplayCondition} right Another distance display condition.\n * @return {boolean} Whether the two distance display conditions are equal.\n */\nDistanceDisplayCondition.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.near === right.near &&\n left.far === right.far)\n );\n};\n\n/**\n * Duplicates a distance display condition instance.\n *\n * @param {DistanceDisplayCondition} [value] The distance display condition to duplicate.\n * @param {DistanceDisplayCondition} [result] The result onto which to store the result.\n * @return {DistanceDisplayCondition} The duplicated instance.\n */\nDistanceDisplayCondition.clone = function (value, result) {\n if (!defined(value)) {\n return undefined;\n }\n\n if (!defined(result)) {\n result = new DistanceDisplayCondition();\n }\n\n result.near = value.near;\n result.far = value.far;\n return result;\n};\n\n/**\n * Duplicates this instance.\n *\n * @param {DistanceDisplayCondition} [result] The result onto which to store the result.\n * @return {DistanceDisplayCondition} The duplicated instance.\n */\nDistanceDisplayCondition.prototype.clone = function (result) {\n return DistanceDisplayCondition.clone(this, result);\n};\n\n/**\n * Determines if this distance display condition is equal to another.\n *\n * @param {DistanceDisplayCondition} other Another distance display condition.\n * @return {boolean} Whether this distance display condition is equal to the other.\n */\nDistanceDisplayCondition.prototype.equals = function (other) {\n return DistanceDisplayCondition.equals(this, other);\n};\nexport default DistanceDisplayCondition;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Represents a scalar value's lower and upper bound at a near distance and far distance in eye space.\n * @alias NearFarScalar\n * @constructor\n *\n * @param {number} [near=0.0] The lower bound of the camera range.\n * @param {number} [nearValue=0.0] The value at the lower bound of the camera range.\n * @param {number} [far=1.0] The upper bound of the camera range.\n * @param {number} [farValue=0.0] The value at the upper bound of the camera range.\n *\n * @see Packable\n */\nfunction NearFarScalar(near, nearValue, far, farValue) {\n /**\n * The lower bound of the camera range.\n * @type {number}\n * @default 0.0\n */\n this.near = defaultValue(near, 0.0);\n /**\n * The value at the lower bound of the camera range.\n * @type {number}\n * @default 0.0\n */\n this.nearValue = defaultValue(nearValue, 0.0);\n /**\n * The upper bound of the camera range.\n * @type {number}\n * @default 1.0\n */\n this.far = defaultValue(far, 1.0);\n /**\n * The value at the upper bound of the camera range.\n * @type {number}\n * @default 0.0\n */\n this.farValue = defaultValue(farValue, 0.0);\n}\n\n/**\n * Duplicates a NearFarScalar instance.\n *\n * @param {NearFarScalar} nearFarScalar The NearFarScalar to duplicate.\n * @param {NearFarScalar} [result] The object onto which to store the result.\n * @returns {NearFarScalar} The modified result parameter or a new NearFarScalar instance if one was not provided. (Returns undefined if nearFarScalar is undefined)\n */\nNearFarScalar.clone = function (nearFarScalar, result) {\n if (!defined(nearFarScalar)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new NearFarScalar(\n nearFarScalar.near,\n nearFarScalar.nearValue,\n nearFarScalar.far,\n nearFarScalar.farValue\n );\n }\n\n result.near = nearFarScalar.near;\n result.nearValue = nearFarScalar.nearValue;\n result.far = nearFarScalar.far;\n result.farValue = nearFarScalar.farValue;\n return result;\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nNearFarScalar.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {NearFarScalar} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nNearFarScalar.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.near;\n array[startingIndex++] = value.nearValue;\n array[startingIndex++] = value.far;\n array[startingIndex] = value.farValue;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {NearFarScalar} [result] The object into which to store the result.\n * @returns {NearFarScalar} The modified result parameter or a new NearFarScalar instance if one was not provided.\n */\nNearFarScalar.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new NearFarScalar();\n }\n result.near = array[startingIndex++];\n result.nearValue = array[startingIndex++];\n result.far = array[startingIndex++];\n result.farValue = array[startingIndex];\n return result;\n};\n\n/**\n * Compares the provided NearFarScalar and returns true if they are equal,\n * false otherwise.\n *\n * @param {NearFarScalar} [left] The first NearFarScalar.\n * @param {NearFarScalar} [right] The second NearFarScalar.\n * @returns {boolean} true if left and right are equal; otherwise false.\n */\nNearFarScalar.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.near === right.near &&\n left.nearValue === right.nearValue &&\n left.far === right.far &&\n left.farValue === right.farValue)\n );\n};\n\n/**\n * Duplicates this instance.\n *\n * @param {NearFarScalar} [result] The object onto which to store the result.\n * @returns {NearFarScalar} The modified result parameter or a new NearFarScalar instance if one was not provided.\n */\nNearFarScalar.prototype.clone = function (result) {\n return NearFarScalar.clone(this, result);\n};\n\n/**\n * Compares this instance to the provided NearFarScalar and returns true if they are equal,\n * false otherwise.\n *\n * @param {NearFarScalar} [right] The right hand side NearFarScalar.\n * @returns {boolean} true if left and right are equal; otherwise false.\n */\nNearFarScalar.prototype.equals = function (right) {\n return NearFarScalar.equals(this, right);\n};\nexport default NearFarScalar;\n", "/**\n * Represents the position relative to the terrain.\n *\n * @enum {number}\n */\nconst HeightReference = {\n /**\n * The position is absolute.\n * @type {number}\n * @constant\n */\n NONE: 0,\n\n /**\n * The position is clamped to the terrain.\n * @type {number}\n * @constant\n */\n CLAMP_TO_GROUND: 1,\n\n /**\n * The position height is the height above the terrain.\n * @type {number}\n * @constant\n */\n RELATIVE_TO_GROUND: 2,\n};\nexport default Object.freeze(HeightReference);\n", "/**\n * The horizontal location of an origin relative to an object, e.g., a {@link Billboard}\n * or {@link Label}. For example, setting the horizontal origin to LEFT\n * or RIGHT will display a billboard to the left or right (in screen space)\n * of the anchor position.\n *

\n *
\n *
\n *
\n *\n * @enum {number}\n *\n * @see Billboard#horizontalOrigin\n * @see Label#horizontalOrigin\n */\nconst HorizontalOrigin = {\n /**\n * The origin is at the horizontal center of the object.\n *\n * @type {number}\n * @constant\n */\n CENTER: 0,\n\n /**\n * The origin is on the left side of the object.\n *\n * @type {number}\n * @constant\n */\n LEFT: 1,\n\n /**\n * The origin is on the right side of the object.\n *\n * @type {number}\n * @constant\n */\n RIGHT: -1,\n};\nexport default Object.freeze(HorizontalOrigin);\n", "/**\n * The vertical location of an origin relative to an object, e.g., a {@link Billboard}\n * or {@link Label}. For example, setting the vertical origin to TOP\n * or BOTTOM will display a billboard above or below (in screen space)\n * the anchor position.\n *

\n *
\n *
\n *
\n *\n * @enum {number}\n *\n * @see Billboard#verticalOrigin\n * @see Label#verticalOrigin\n */\nconst VerticalOrigin = {\n /**\n * The origin is at the vertical center between BASELINE and TOP.\n *\n * @type {number}\n * @constant\n */\n CENTER: 0,\n\n /**\n * The origin is at the bottom of the object.\n *\n * @type {number}\n * @constant\n */\n BOTTOM: 1,\n\n /**\n * If the object contains text, the origin is at the baseline of the text, else the origin is at the bottom of the object.\n *\n * @type {number}\n * @constant\n */\n BASELINE: 2,\n\n /**\n * The origin is at the top of the object.\n *\n * @type {number}\n * @constant\n */\n TOP: -1,\n};\nexport default Object.freeze(VerticalOrigin);\n", "/**\n * The state of a BoundingSphere computation being performed by a {@link Visualizer}.\n * @enum {number}\n * @private\n */\nconst BoundingSphereState = {\n /**\n * The BoundingSphere has been computed.\n * @type BoundingSphereState\n * @constant\n */\n DONE: 0,\n /**\n * The BoundingSphere is still being computed.\n * @type BoundingSphereState\n * @constant\n */\n PENDING: 1,\n /**\n * The BoundingSphere does not exist.\n * @type BoundingSphereState\n * @constant\n */\n FAILED: 2,\n};\nexport default Object.freeze(BoundingSphereState);\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * The interface for all properties, which represent a value that can optionally vary over time.\n * This type defines an interface and cannot be instantiated directly.\n *\n * @alias Property\n * @constructor\n * @abstract\n *\n * @see CompositeProperty\n * @see ConstantProperty\n * @see SampledProperty\n * @see TimeIntervalCollectionProperty\n * @see MaterialProperty\n * @see PositionProperty\n * @see ReferenceProperty\n */\nfunction Property() {\n DeveloperError.throwInstantiationError();\n}\n\nObject.defineProperties(Property.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof Property.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof Property.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: DeveloperError.throwInstantiationError,\n },\n});\n\n/**\n * Gets the value of the property at the provided time.\n * @function\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nProperty.prototype.getValue = DeveloperError.throwInstantiationError;\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n * @function\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nProperty.prototype.equals = DeveloperError.throwInstantiationError;\n\n/**\n * @private\n */\nProperty.equals = function (left, right) {\n return left === right || (defined(left) && left.equals(right));\n};\n\n/**\n * @private\n */\nProperty.arrayEquals = function (left, right) {\n if (left === right) {\n return true;\n }\n if (!defined(left) || !defined(right) || left.length !== right.length) {\n return false;\n }\n const length = left.length;\n for (let i = 0; i < length; i++) {\n if (!Property.equals(left[i], right[i])) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * @private\n */\nProperty.isConstant = function (property) {\n return !defined(property) || property.isConstant;\n};\n\n/**\n * @private\n */\nProperty.getValueOrUndefined = function (property, time, result) {\n return defined(property) ? property.getValue(time, result) : undefined;\n};\n\n/**\n * @private\n */\nProperty.getValueOrDefault = function (property, time, valueDefault, result) {\n return defined(property)\n ? defaultValue(property.getValue(time, result), valueDefault)\n : valueDefault;\n};\n\n/**\n * @private\n */\nProperty.getValueOrClonedDefault = function (\n property,\n time,\n valueDefault,\n result\n) {\n let value;\n if (defined(property)) {\n value = property.getValue(time, result);\n }\n if (!defined(value)) {\n value = valueDefault.clone(value);\n }\n return value;\n};\nexport default Property;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultEyeOffset = Cartesian3.ZERO;\nconst defaultHeightReference = HeightReference.NONE;\nconst defaultPixelOffset = Cartesian2.ZERO;\nconst defaultScale = 1.0;\nconst defaultRotation = 0.0;\nconst defaultAlignedAxis = Cartesian3.ZERO;\nconst defaultHorizontalOrigin = HorizontalOrigin.CENTER;\nconst defaultVerticalOrigin = VerticalOrigin.CENTER;\nconst defaultSizeInMeters = false;\n\nconst positionScratch = new Cartesian3();\nconst colorScratch = new Color();\nconst eyeOffsetScratch = new Cartesian3();\nconst pixelOffsetScratch = new Cartesian2();\nconst scaleByDistanceScratch = new NearFarScalar();\nconst translucencyByDistanceScratch = new NearFarScalar();\nconst pixelOffsetScaleByDistanceScratch = new NearFarScalar();\nconst boundingRectangleScratch = new BoundingRectangle();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\n\nfunction EntityData(entity) {\n this.entity = entity;\n this.billboard = undefined;\n this.textureValue = undefined;\n}\n\n/**\n * A {@link Visualizer} which maps {@link Entity#billboard} to a {@link Billboard}.\n * @alias BillboardVisualizer\n * @constructor\n *\n * @param {EntityCluster} entityCluster The entity cluster to manage the collection of billboards and optionally cluster with other entities.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction BillboardVisualizer(entityCluster, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entityCluster)) {\n throw new DeveloperError(\"entityCluster is required.\");\n }\n if (!defined(entityCollection)) {\n throw new DeveloperError(\"entityCollection is required.\");\n }\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n BillboardVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._cluster = entityCluster;\n this._entityCollection = entityCollection;\n this._items = new AssociativeArray();\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\n/**\n * Updates the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nBillboardVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const items = this._items.values;\n const cluster = this._cluster;\n\n for (let i = 0, len = items.length; i < len; i++) {\n const item = items[i];\n const entity = item.entity;\n const billboardGraphics = entity._billboard;\n let textureValue;\n let billboard = item.billboard;\n let show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n Property.getValueOrDefault(billboardGraphics._show, time, true);\n let position;\n if (show) {\n position = Property.getValueOrUndefined(\n entity._position,\n time,\n positionScratch\n );\n textureValue = Property.getValueOrUndefined(\n billboardGraphics._image,\n time\n );\n show = defined(position) && defined(textureValue);\n }\n\n if (!show) {\n //don't bother creating or updating anything else\n returnPrimitive(item, entity, cluster);\n continue;\n }\n\n if (!Property.isConstant(entity._position)) {\n cluster._clusterDirty = true;\n }\n\n if (!defined(billboard)) {\n billboard = cluster.getBillboard(entity);\n billboard.id = entity;\n billboard.image = undefined;\n item.billboard = billboard;\n }\n\n billboard.show = show;\n if (!defined(billboard.image) || item.textureValue !== textureValue) {\n billboard.image = textureValue;\n item.textureValue = textureValue;\n }\n billboard.position = position;\n billboard.color = Property.getValueOrDefault(\n billboardGraphics._color,\n time,\n defaultColor,\n colorScratch\n );\n billboard.eyeOffset = Property.getValueOrDefault(\n billboardGraphics._eyeOffset,\n time,\n defaultEyeOffset,\n eyeOffsetScratch\n );\n billboard.heightReference = Property.getValueOrDefault(\n billboardGraphics._heightReference,\n time,\n defaultHeightReference\n );\n billboard.pixelOffset = Property.getValueOrDefault(\n billboardGraphics._pixelOffset,\n time,\n defaultPixelOffset,\n pixelOffsetScratch\n );\n billboard.scale = Property.getValueOrDefault(\n billboardGraphics._scale,\n time,\n defaultScale\n );\n billboard.rotation = Property.getValueOrDefault(\n billboardGraphics._rotation,\n time,\n defaultRotation\n );\n billboard.alignedAxis = Property.getValueOrDefault(\n billboardGraphics._alignedAxis,\n time,\n defaultAlignedAxis\n );\n billboard.horizontalOrigin = Property.getValueOrDefault(\n billboardGraphics._horizontalOrigin,\n time,\n defaultHorizontalOrigin\n );\n billboard.verticalOrigin = Property.getValueOrDefault(\n billboardGraphics._verticalOrigin,\n time,\n defaultVerticalOrigin\n );\n billboard.width = Property.getValueOrUndefined(\n billboardGraphics._width,\n time\n );\n billboard.height = Property.getValueOrUndefined(\n billboardGraphics._height,\n time\n );\n billboard.scaleByDistance = Property.getValueOrUndefined(\n billboardGraphics._scaleByDistance,\n time,\n scaleByDistanceScratch\n );\n billboard.translucencyByDistance = Property.getValueOrUndefined(\n billboardGraphics._translucencyByDistance,\n time,\n translucencyByDistanceScratch\n );\n billboard.pixelOffsetScaleByDistance = Property.getValueOrUndefined(\n billboardGraphics._pixelOffsetScaleByDistance,\n time,\n pixelOffsetScaleByDistanceScratch\n );\n billboard.sizeInMeters = Property.getValueOrDefault(\n billboardGraphics._sizeInMeters,\n time,\n defaultSizeInMeters\n );\n billboard.distanceDisplayCondition = Property.getValueOrUndefined(\n billboardGraphics._distanceDisplayCondition,\n time,\n distanceDisplayConditionScratch\n );\n billboard.disableDepthTestDistance = Property.getValueOrUndefined(\n billboardGraphics._disableDepthTestDistance,\n time\n );\n\n const subRegion = Property.getValueOrUndefined(\n billboardGraphics._imageSubRegion,\n time,\n boundingRectangleScratch\n );\n if (defined(subRegion)) {\n billboard.setImageSubRegion(billboard._imageId, subRegion);\n }\n }\n return true;\n};\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nBillboardVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const item = this._items.get(entity.id);\n if (!defined(item) || !defined(item.billboard)) {\n return BoundingSphereState.FAILED;\n }\n\n const billboard = item.billboard;\n if (billboard.heightReference === HeightReference.NONE) {\n result.center = Cartesian3.clone(billboard.position, result.center);\n } else {\n if (!defined(billboard._clampedPosition)) {\n return BoundingSphereState.PENDING;\n }\n result.center = Cartesian3.clone(billboard._clampedPosition, result.center);\n }\n result.radius = 0;\n return BoundingSphereState.DONE;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nBillboardVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nBillboardVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n BillboardVisualizer.prototype._onCollectionChanged,\n this\n );\n const entities = this._entityCollection.values;\n for (let i = 0; i < entities.length; i++) {\n this._cluster.removeBillboard(entities[i]);\n }\n return destroyObject(this);\n};\n\nBillboardVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n const items = this._items;\n const cluster = this._cluster;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._billboard) && defined(entity._position)) {\n items.set(entity.id, new EntityData(entity));\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._billboard) && defined(entity._position)) {\n if (!items.contains(entity.id)) {\n items.set(entity.id, new EntityData(entity));\n }\n } else {\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n};\n\nfunction returnPrimitive(item, entity, cluster) {\n if (defined(item)) {\n item.billboard = undefined;\n cluster.removeBillboard(entity);\n }\n}\nexport default BillboardVisualizer;\n", "import defaultValue from \"./defaultValue.js\";\n\n/**\n * Represents the closed interval [start, stop].\n * @alias Interval\n * @constructor\n *\n * @param {number} [start=0.0] The beginning of the interval.\n * @param {number} [stop=0.0] The end of the interval.\n */\nfunction Interval(start, stop) {\n /**\n * The beginning of the interval.\n * @type {number}\n * @default 0.0\n */\n this.start = defaultValue(start, 0.0);\n /**\n * The end of the interval.\n * @type {number}\n * @default 0.0\n */\n this.stop = defaultValue(stop, 0.0);\n}\nexport default Interval;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Intersect from \"./Intersect.js\";\nimport Interval from \"./Interval.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * A bounding sphere with a center and a radius.\n * @alias BoundingSphere\n * @constructor\n *\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.\n * @param {number} [radius=0.0] The radius of the bounding sphere.\n *\n * @see AxisAlignedBoundingBox\n * @see BoundingRectangle\n * @see Packable\n */\nfunction BoundingSphere(center, radius) {\n /**\n * The center point of the sphere.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));\n\n /**\n * The radius of the sphere.\n * @type {number}\n * @default 0.0\n */\n this.radius = defaultValue(radius, 0.0);\n}\n\nconst fromPointsXMin = new Cartesian3();\nconst fromPointsYMin = new Cartesian3();\nconst fromPointsZMin = new Cartesian3();\nconst fromPointsXMax = new Cartesian3();\nconst fromPointsYMax = new Cartesian3();\nconst fromPointsZMax = new Cartesian3();\nconst fromPointsCurrentPos = new Cartesian3();\nconst fromPointsScratch = new Cartesian3();\nconst fromPointsRitterCenter = new Cartesian3();\nconst fromPointsMinBoxPt = new Cartesian3();\nconst fromPointsMaxBoxPt = new Cartesian3();\nconst fromPointsNaiveCenterScratch = new Cartesian3();\nconst volumeConstant = (4.0 / 3.0) * CesiumMath.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n *\n * @param {Cartesian3[]} [positions] An array of points that the bounding sphere will enclose. Each point must have x, y, and z properties.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @see {@link http://help.agi.com/AGIComponents/html/BlogBoundingSphere.htm|Bounding Sphere computation article}\n */\nBoundingSphere.fromPoints = function (positions, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const currentPos = Cartesian3.clone(positions[0], fromPointsCurrentPos);\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numPositions = positions.length;\n let i;\n for (i = 1; i < numPositions; i++) {\n Cartesian3.clone(positions[i], currentPos);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numPositions; i++) {\n Cartesian3.clone(positions[i], currentPos);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\nconst defaultProjection = new GeographicProjection();\nconst fromRectangle2DLowerLeft = new Cartesian3();\nconst fromRectangle2DUpperRight = new Cartesian3();\nconst fromRectangle2DSouthwest = new Cartographic();\nconst fromRectangle2DNortheast = new Cartographic();\n\n/**\n * Computes a bounding sphere from a rectangle projected in 2D.\n *\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\n * @param {object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangle2D = function (rectangle, projection, result) {\n return BoundingSphere.fromRectangleWithHeights2D(\n rectangle,\n projection,\n 0.0,\n 0.0,\n result\n );\n};\n\n/**\n * Computes a bounding sphere from a rectangle projected in 2D. The bounding sphere accounts for the\n * object's minimum and maximum heights over the rectangle.\n *\n * @param {Rectangle} [rectangle] The rectangle around which to create a bounding sphere.\n * @param {object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.\n * @param {number} [minimumHeight=0.0] The minimum height over the rectangle.\n * @param {number} [maximumHeight=0.0] The maximum height over the rectangle.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangleWithHeights2D = function (\n rectangle,\n projection,\n minimumHeight,\n maximumHeight,\n result\n) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(rectangle)) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n projection = defaultValue(projection, defaultProjection);\n\n Rectangle.southwest(rectangle, fromRectangle2DSouthwest);\n fromRectangle2DSouthwest.height = minimumHeight;\n Rectangle.northeast(rectangle, fromRectangle2DNortheast);\n fromRectangle2DNortheast.height = maximumHeight;\n\n const lowerLeft = projection.project(\n fromRectangle2DSouthwest,\n fromRectangle2DLowerLeft\n );\n const upperRight = projection.project(\n fromRectangle2DNortheast,\n fromRectangle2DUpperRight\n );\n\n const width = upperRight.x - lowerLeft.x;\n const height = upperRight.y - lowerLeft.y;\n const elevation = upperRight.z - lowerLeft.z;\n\n result.radius =\n Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;\n const center = result.center;\n center.x = lowerLeft.x + width * 0.5;\n center.y = lowerLeft.y + height * 0.5;\n center.z = lowerLeft.z + elevation * 0.5;\n return result;\n};\n\nconst fromRectangle3DScratch = [];\n\n/**\n * Computes a bounding sphere from a rectangle in 3D. The bounding sphere is created using a subsample of points\n * on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.\n *\n * @param {Rectangle} [rectangle] The valid rectangle used to create a bounding sphere.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.\n * @param {number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromRectangle3D = function (\n rectangle,\n ellipsoid,\n surfaceHeight,\n result\n) {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n surfaceHeight = defaultValue(surfaceHeight, 0.0);\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(rectangle)) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const positions = Rectangle.subsample(\n rectangle,\n ellipsoid,\n surfaceHeight,\n fromRectangle3DScratch\n );\n return BoundingSphere.fromPoints(positions, result);\n};\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are\n * stored in a flat array in X, Y, Z, order. The bounding sphere is computed by running two\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\n * ensure a tight fit.\n *\n * @param {number[]} [positions] An array of points that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the\n * origin of the coordinate system. This is useful when the positions are to be used for\n * relative-to-center (RTC) rendering.\n * @param {number} [stride=3] The number of array elements per vertex. It must be at least 3, but it may\n * be higher. Regardless of the value of this parameter, the X coordinate of the first position\n * is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index\n * 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If\n * the stride is 5, however, two array elements are skipped and the next position begins at array\n * index 5.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @example\n * // Compute the bounding sphere from 3 positions, each specified relative to a center.\n * // In addition to the X, Y, and Z coordinates, the points array contains two additional\n * // elements per point which are ignored for the purpose of computing the bounding sphere.\n * const center = new Cesium.Cartesian3(1.0, 2.0, 3.0);\n * const points = [1.0, 2.0, 3.0, 0.1, 0.2,\n * 4.0, 5.0, 6.0, 0.1, 0.2,\n * 7.0, 8.0, 9.0, 0.1, 0.2];\n * const sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);\n *\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\n */\nBoundingSphere.fromVertices = function (positions, center, stride, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n center = defaultValue(center, Cartesian3.ZERO);\n\n stride = defaultValue(stride, 3);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"stride\", stride, 3);\n //>>includeEnd('debug');\n\n const currentPos = fromPointsCurrentPos;\n currentPos.x = positions[0] + center.x;\n currentPos.y = positions[1] + center.y;\n currentPos.z = positions[2] + center.z;\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numElements = positions.length;\n let i;\n for (i = 0; i < numElements; i += stride) {\n const x = positions[i] + center.x;\n const y = positions[i + 1] + center.y;\n const z = positions[i + 2] + center.z;\n\n currentPos.x = x;\n currentPos.y = y;\n currentPos.z = z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numElements; i += stride) {\n currentPos.x = positions[i] + center.x;\n currentPos.y = positions[i + 1] + center.y;\n currentPos.z = positions[i + 2] + center.z;\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of EncodedCartesian3s, where the points are\n * stored in parallel flat arrays in X, Y, Z, order. The bounding sphere is computed by running two\n * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to\n * ensure a tight fit.\n *\n * @param {number[]} [positionsHigh] An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {number[]} [positionsLow] An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point\n * is formed from three elements in the array in the order X, Y, Z.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n *\n * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}\n */\nBoundingSphere.fromEncodedCartesianVertices = function (\n positionsHigh,\n positionsLow,\n result\n) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (\n !defined(positionsHigh) ||\n !defined(positionsLow) ||\n positionsHigh.length !== positionsLow.length ||\n positionsHigh.length === 0\n ) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const currentPos = fromPointsCurrentPos;\n currentPos.x = positionsHigh[0] + positionsLow[0];\n currentPos.y = positionsHigh[1] + positionsLow[1];\n currentPos.z = positionsHigh[2] + positionsLow[2];\n\n const xMin = Cartesian3.clone(currentPos, fromPointsXMin);\n const yMin = Cartesian3.clone(currentPos, fromPointsYMin);\n const zMin = Cartesian3.clone(currentPos, fromPointsZMin);\n\n const xMax = Cartesian3.clone(currentPos, fromPointsXMax);\n const yMax = Cartesian3.clone(currentPos, fromPointsYMax);\n const zMax = Cartesian3.clone(currentPos, fromPointsZMax);\n\n const numElements = positionsHigh.length;\n let i;\n for (i = 0; i < numElements; i += 3) {\n const x = positionsHigh[i] + positionsLow[i];\n const y = positionsHigh[i + 1] + positionsLow[i + 1];\n const z = positionsHigh[i + 2] + positionsLow[i + 2];\n\n currentPos.x = x;\n currentPos.y = y;\n currentPos.z = z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n Cartesian3.clone(currentPos, xMin);\n }\n\n if (x > xMax.x) {\n Cartesian3.clone(currentPos, xMax);\n }\n\n if (y < yMin.y) {\n Cartesian3.clone(currentPos, yMin);\n }\n\n if (y > yMax.y) {\n Cartesian3.clone(currentPos, yMax);\n }\n\n if (z < zMin.z) {\n Cartesian3.clone(currentPos, zMin);\n }\n\n if (z > zMax.z) {\n Cartesian3.clone(currentPos, zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(xMax, xMin, fromPointsScratch)\n );\n const ySpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(yMax, yMin, fromPointsScratch)\n );\n const zSpan = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(zMax, zMin, fromPointsScratch)\n );\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch)\n );\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = Cartesian3.midpoint(\n minBoxPt,\n maxBoxPt,\n fromPointsNaiveCenterScratch\n );\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (i = 0; i < numElements; i += 3) {\n currentPos.x = positionsHigh[i] + positionsLow[i];\n currentPos.y = positionsHigh[i + 1] + positionsLow[i + 1];\n currentPos.z = positionsHigh[i + 2] + positionsLow[i + 2];\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = Cartesian3.magnitude(\n Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch)\n );\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch)\n );\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x =\n (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) /\n oldCenterToPoint;\n ritterCenter.y =\n (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) /\n oldCenterToPoint;\n ritterCenter.z =\n (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) /\n oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n Cartesian3.clone(ritterCenter, result.center);\n result.radius = ritterRadius;\n } else {\n Cartesian3.clone(naiveCenter, result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n};\n\n/**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n *\n * @param {Cartesian3} [corner] The minimum height over the rectangle.\n * @param {Cartesian3} [oppositeCorner] The maximum height over the rectangle.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * // Create a bounding sphere around the unit cube\n * const sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));\n */\nBoundingSphere.fromCornerPoints = function (corner, oppositeCorner, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"corner\", corner);\n Check.typeOf.object(\"oppositeCorner\", oppositeCorner);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = Cartesian3.midpoint(corner, oppositeCorner, result.center);\n result.radius = Cartesian3.distance(center, oppositeCorner);\n return result;\n};\n\n/**\n * Creates a bounding sphere encompassing an ellipsoid.\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid around which to create a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * const boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);\n */\nBoundingSphere.fromEllipsoid = function (ellipsoid, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = ellipsoid.maximumRadius;\n return result;\n};\n\nconst fromBoundingSpheresScratch = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.\n *\n * @param {BoundingSphere[]} [boundingSpheres] The array of bounding spheres.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromBoundingSpheres = function (boundingSpheres, result) {\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n if (!defined(boundingSpheres) || boundingSpheres.length === 0) {\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n result.radius = 0.0;\n return result;\n }\n\n const length = boundingSpheres.length;\n if (length === 1) {\n return BoundingSphere.clone(boundingSpheres[0], result);\n }\n\n if (length === 2) {\n return BoundingSphere.union(boundingSpheres[0], boundingSpheres[1], result);\n }\n\n const positions = [];\n let i;\n for (i = 0; i < length; i++) {\n positions.push(boundingSpheres[i].center);\n }\n\n result = BoundingSphere.fromPoints(positions, result);\n\n const center = result.center;\n let radius = result.radius;\n for (i = 0; i < length; i++) {\n const tmp = boundingSpheres[i];\n radius = Math.max(\n radius,\n Cartesian3.distance(center, tmp.center, fromBoundingSpheresScratch) +\n tmp.radius\n );\n }\n result.radius = radius;\n\n return result;\n};\n\nconst fromOrientedBoundingBoxScratchU = new Cartesian3();\nconst fromOrientedBoundingBoxScratchV = new Cartesian3();\nconst fromOrientedBoundingBoxScratchW = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.\n *\n * @param {OrientedBoundingBox} orientedBoundingBox The oriented bounding box.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromOrientedBoundingBox = function (\n orientedBoundingBox,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"orientedBoundingBox\", orientedBoundingBox);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const halfAxes = orientedBoundingBox.halfAxes;\n const u = Matrix3.getColumn(halfAxes, 0, fromOrientedBoundingBoxScratchU);\n const v = Matrix3.getColumn(halfAxes, 1, fromOrientedBoundingBoxScratchV);\n const w = Matrix3.getColumn(halfAxes, 2, fromOrientedBoundingBoxScratchW);\n\n Cartesian3.add(u, v, u);\n Cartesian3.add(u, w, u);\n\n result.center = Cartesian3.clone(orientedBoundingBox.center, result.center);\n result.radius = Cartesian3.magnitude(u);\n\n return result;\n};\n\nconst scratchFromTransformationCenter = new Cartesian3();\nconst scratchFromTransformationScale = new Cartesian3();\n\n/**\n * Computes a tight-fitting bounding sphere enclosing the provided affine transformation.\n *\n * @param {Matrix4} transformation The affine transformation.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.fromTransformation = function (transformation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"transformation\", transformation);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = Matrix4.getTranslation(\n transformation,\n scratchFromTransformationCenter\n );\n const scale = Matrix4.getScale(\n transformation,\n scratchFromTransformationScale\n );\n const radius = 0.5 * Cartesian3.magnitude(scale);\n result.center = Cartesian3.clone(center, result.center);\n result.radius = radius;\n\n return result;\n};\n\n/**\n * Duplicates a BoundingSphere instance.\n *\n * @param {BoundingSphere} sphere The bounding sphere to duplicate.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)\n */\nBoundingSphere.clone = function (sphere, result) {\n if (!defined(sphere)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new BoundingSphere(sphere.center, sphere.radius);\n }\n\n result.center = Cartesian3.clone(sphere.center, result.center);\n result.radius = sphere.radius;\n return result;\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nBoundingSphere.packedLength = 4;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {BoundingSphere} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nBoundingSphere.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const center = value.center;\n array[startingIndex++] = center.x;\n array[startingIndex++] = center.y;\n array[startingIndex++] = center.z;\n array[startingIndex] = value.radius;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {BoundingSphere} [result] The object into which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.\n */\nBoundingSphere.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const center = result.center;\n center.x = array[startingIndex++];\n center.y = array[startingIndex++];\n center.z = array[startingIndex++];\n result.radius = array[startingIndex];\n return result;\n};\n\nconst unionScratch = new Cartesian3();\nconst unionScratchCenter = new Cartesian3();\n/**\n * Computes a bounding sphere that contains both the left and right bounding spheres.\n *\n * @param {BoundingSphere} left A sphere to enclose in a bounding sphere.\n * @param {BoundingSphere} right A sphere to enclose in a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.union = function (left, right, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n Check.typeOf.object(\"right\", right);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n const leftCenter = left.center;\n const leftRadius = left.radius;\n const rightCenter = right.center;\n const rightRadius = right.radius;\n\n const toRightCenter = Cartesian3.subtract(\n rightCenter,\n leftCenter,\n unionScratch\n );\n const centerSeparation = Cartesian3.magnitude(toRightCenter);\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n left.clone(result);\n return result;\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n right.clone(result);\n return result;\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints =\n (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n const center = Cartesian3.multiplyByScalar(\n toRightCenter,\n (-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation,\n unionScratchCenter\n );\n Cartesian3.add(center, leftCenter, center);\n Cartesian3.clone(center, result.center);\n result.radius = halfDistanceBetweenTangentPoints;\n\n return result;\n};\n\nconst expandScratch = new Cartesian3();\n/**\n * Computes a bounding sphere by enlarging the provided sphere to contain the provided point.\n *\n * @param {BoundingSphere} sphere A sphere to expand.\n * @param {Cartesian3} point A point to enclose in a bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.expand = function (sphere, point, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"point\", point);\n //>>includeEnd('debug');\n\n result = BoundingSphere.clone(sphere, result);\n\n const radius = Cartesian3.magnitude(\n Cartesian3.subtract(point, result.center, expandScratch)\n );\n if (radius > result.radius) {\n result.radius = radius;\n }\n\n return result;\n};\n\n/**\n * Determines which side of a plane a sphere is located.\n *\n * @param {BoundingSphere} sphere The bounding sphere to test.\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\n * intersects the plane.\n */\nBoundingSphere.intersectPlane = function (sphere, plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"plane\", plane);\n //>>includeEnd('debug');\n\n const center = sphere.center;\n const radius = sphere.radius;\n const normal = plane.normal;\n const distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;\n\n if (distanceToPlane < -radius) {\n // The center point is negative side of the plane normal\n return Intersect.OUTSIDE;\n } else if (distanceToPlane < radius) {\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n return Intersect.INTERSECTING;\n }\n return Intersect.INSIDE;\n};\n\n/**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n *\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.transform = function (sphere, transform, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"transform\", transform);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n result.center = Matrix4.multiplyByPoint(\n transform,\n sphere.center,\n result.center\n );\n result.radius = Matrix4.getMaximumScale(transform) * sphere.radius;\n\n return result;\n};\n\nconst distanceSquaredToScratch = new Cartesian3();\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\n *\n * @param {BoundingSphere} sphere The sphere.\n * @param {Cartesian3} cartesian The point\n * @returns {number} The distance squared from the bounding sphere to the point. Returns 0 if the point is inside the sphere.\n *\n * @example\n * // Sort bounding spheres from back to front\n * spheres.sort(function(a, b) {\n * return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);\n * });\n */\nBoundingSphere.distanceSquaredTo = function (sphere, cartesian) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n const diff = Cartesian3.subtract(\n sphere.center,\n cartesian,\n distanceSquaredToScratch\n );\n\n const distance = Cartesian3.magnitude(diff) - sphere.radius;\n if (distance <= 0.0) {\n return 0.0;\n }\n\n return distance * distance;\n};\n\n/**\n * Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale\n * The transformation matrix is not verified to have a uniform scale of 1.\n * This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.\n *\n * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.\n * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n *\n * @example\n * const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);\n * const boundingSphere = new Cesium.BoundingSphere();\n * const newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);\n */\nBoundingSphere.transformWithoutScale = function (sphere, transform, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"transform\", transform);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new BoundingSphere();\n }\n\n result.center = Matrix4.multiplyByPoint(\n transform,\n sphere.center,\n result.center\n );\n result.radius = sphere.radius;\n\n return result;\n};\n\nconst scratchCartesian3 = new Cartesian3();\n/**\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\n * plus/minus the radius of the bounding sphere.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding sphere.\n *\n * @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\n */\nBoundingSphere.computePlaneDistances = function (\n sphere,\n position,\n direction,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"position\", position);\n Check.typeOf.object(\"direction\", direction);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Interval();\n }\n\n const toCenter = Cartesian3.subtract(\n sphere.center,\n position,\n scratchCartesian3\n );\n const mag = Cartesian3.dot(direction, toCenter);\n\n result.start = mag - sphere.radius;\n result.stop = mag + sphere.radius;\n return result;\n};\n\nconst projectTo2DNormalScratch = new Cartesian3();\nconst projectTo2DEastScratch = new Cartesian3();\nconst projectTo2DNorthScratch = new Cartesian3();\nconst projectTo2DWestScratch = new Cartesian3();\nconst projectTo2DSouthScratch = new Cartesian3();\nconst projectTo2DCartographicScratch = new Cartographic();\nconst projectTo2DPositionsScratch = new Array(8);\nfor (let n = 0; n < 8; ++n) {\n projectTo2DPositionsScratch[n] = new Cartesian3();\n}\n\nconst projectTo2DProjection = new GeographicProjection();\n/**\n * Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.\n *\n * @param {BoundingSphere} sphere The bounding sphere to transform to 2D.\n * @param {object} [projection=GeographicProjection] The projection to 2D.\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.projectTo2D = function (sphere, projection, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n //>>includeEnd('debug');\n\n projection = defaultValue(projection, projectTo2DProjection);\n\n const ellipsoid = projection.ellipsoid;\n let center = sphere.center;\n const radius = sphere.radius;\n\n let normal;\n if (Cartesian3.equals(center, Cartesian3.ZERO)) {\n // Bounding sphere is at the center. The geodetic surface normal is not\n // defined here so pick the x-axis as a fallback.\n normal = Cartesian3.clone(Cartesian3.UNIT_X, projectTo2DNormalScratch);\n } else {\n normal = ellipsoid.geodeticSurfaceNormal(center, projectTo2DNormalScratch);\n }\n const east = Cartesian3.cross(\n Cartesian3.UNIT_Z,\n normal,\n projectTo2DEastScratch\n );\n Cartesian3.normalize(east, east);\n const north = Cartesian3.cross(normal, east, projectTo2DNorthScratch);\n Cartesian3.normalize(north, north);\n\n Cartesian3.multiplyByScalar(normal, radius, normal);\n Cartesian3.multiplyByScalar(north, radius, north);\n Cartesian3.multiplyByScalar(east, radius, east);\n\n const south = Cartesian3.negate(north, projectTo2DSouthScratch);\n const west = Cartesian3.negate(east, projectTo2DWestScratch);\n\n const positions = projectTo2DPositionsScratch;\n\n // top NE corner\n let corner = positions[0];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, east, corner);\n\n // top NW corner\n corner = positions[1];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, west, corner);\n\n // top SW corner\n corner = positions[2];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, west, corner);\n\n // top SE corner\n corner = positions[3];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, east, corner);\n\n Cartesian3.negate(normal, normal);\n\n // bottom NE corner\n corner = positions[4];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, east, corner);\n\n // bottom NW corner\n corner = positions[5];\n Cartesian3.add(normal, north, corner);\n Cartesian3.add(corner, west, corner);\n\n // bottom SW corner\n corner = positions[6];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, west, corner);\n\n // bottom SE corner\n corner = positions[7];\n Cartesian3.add(normal, south, corner);\n Cartesian3.add(corner, east, corner);\n\n const length = positions.length;\n for (let i = 0; i < length; ++i) {\n const position = positions[i];\n Cartesian3.add(center, position, position);\n const cartographic = ellipsoid.cartesianToCartographic(\n position,\n projectTo2DCartographicScratch\n );\n projection.project(cartographic, position);\n }\n\n result = BoundingSphere.fromPoints(positions, result);\n\n // swizzle center components\n center = result.center;\n const x = center.x;\n const y = center.y;\n const z = center.z;\n center.x = z;\n center.y = x;\n center.z = y;\n\n return result;\n};\n\n/**\n * Determines whether or not a sphere is hidden from view by the occluder.\n *\n * @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.\n * @param {Occluder} occluder The occluder.\n * @returns {boolean} true if the sphere is not visible; otherwise false.\n */\nBoundingSphere.isOccluded = function (sphere, occluder) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"sphere\", sphere);\n Check.typeOf.object(\"occluder\", occluder);\n //>>includeEnd('debug');\n return !occluder.isBoundingSphereVisible(sphere);\n};\n\n/**\n * Compares the provided BoundingSphere componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {BoundingSphere} [left] The first BoundingSphere.\n * @param {BoundingSphere} [right] The second BoundingSphere.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nBoundingSphere.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Cartesian3.equals(left.center, right.center) &&\n left.radius === right.radius)\n );\n};\n\n/**\n * Determines which side of a plane the sphere is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\n * intersects the plane.\n */\nBoundingSphere.prototype.intersectPlane = function (plane) {\n return BoundingSphere.intersectPlane(this, plane);\n};\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding sphere to a point.\n *\n * @param {Cartesian3} cartesian The point\n * @returns {number} The estimated distance squared from the bounding sphere to the point.\n *\n * @example\n * // Sort bounding spheres from back to front\n * spheres.sort(function(a, b) {\n * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);\n * });\n */\nBoundingSphere.prototype.distanceSquaredTo = function (cartesian) {\n return BoundingSphere.distanceSquaredTo(this, cartesian);\n};\n\n/**\n * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction\n * plus/minus the radius of the bounding sphere.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding sphere.\n *\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.\n */\nBoundingSphere.prototype.computePlaneDistances = function (\n position,\n direction,\n result\n) {\n return BoundingSphere.computePlaneDistances(\n this,\n position,\n direction,\n result\n );\n};\n\n/**\n * Determines whether or not a sphere is hidden from view by the occluder.\n *\n * @param {Occluder} occluder The occluder.\n * @returns {boolean} true if the sphere is not visible; otherwise false.\n */\nBoundingSphere.prototype.isOccluded = function (occluder) {\n return BoundingSphere.isOccluded(this, occluder);\n};\n\n/**\n * Compares this BoundingSphere against the provided BoundingSphere componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {BoundingSphere} [right] The right hand side BoundingSphere.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nBoundingSphere.prototype.equals = function (right) {\n return BoundingSphere.equals(this, right);\n};\n\n/**\n * Duplicates this BoundingSphere instance.\n *\n * @param {BoundingSphere} [result] The object onto which to store the result.\n * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.\n */\nBoundingSphere.prototype.clone = function (result) {\n return BoundingSphere.clone(this, result);\n};\n\n/**\n * Computes the radius of the BoundingSphere.\n * @returns {number} The radius of the BoundingSphere.\n */\nBoundingSphere.prototype.volume = function () {\n const radius = this.radius;\n return volumeConstant * radius * radius * radius;\n};\nexport default BoundingSphere;\n", "import defaultValue from \"./defaultValue.js\";\n\n/**\n * Attributes, which make up a geometry's vertices. Each property in this object corresponds to a\n * {@link GeometryAttribute} containing the attribute's data.\n *

\n * Attributes are always stored non-interleaved in a Geometry.\n *

\n *\n * @alias GeometryAttributes\n * @constructor\n */\nfunction GeometryAttributes(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The 3D position attribute.\n *

\n * 64-bit floating-point (for precision). 3 components per attribute.\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.position = options.position;\n\n /**\n * The normal attribute (normalized), which is commonly used for lighting.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.normal = options.normal;\n\n /**\n * The 2D texture coordinate attribute.\n *

\n * 32-bit floating-point. 2 components per attribute\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.st = options.st;\n\n /**\n * The bitangent attribute (normalized), which is used for tangent-space effects like bump mapping.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.bitangent = options.bitangent;\n\n /**\n * The tangent attribute (normalized), which is used for tangent-space effects like bump mapping.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.tangent = options.tangent;\n\n /**\n * The color attribute.\n *

\n * 8-bit unsigned integer. 4 components per attribute.\n *

\n *\n * @type GeometryAttribute\n *\n * @default undefined\n */\n this.color = options.color;\n}\nexport default GeometryAttributes;\n", "/**\n * Represents which vertices should have a value of `true` for the `applyOffset` attribute\n * @private\n */\nconst GeometryOffsetAttribute = {\n NONE: 0,\n TOP: 1,\n ALL: 2,\n};\nexport default Object.freeze(GeometryOffsetAttribute);\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A vertex format defines what attributes make up a vertex. A VertexFormat can be provided\n * to a {@link Geometry} to request that certain properties be computed, e.g., just position,\n * position and normal, etc.\n *\n * @param {object} [options] An object with boolean properties corresponding to VertexFormat properties as shown in the code example.\n *\n * @alias VertexFormat\n * @constructor\n *\n * @example\n * // Create a vertex format with position and 2D texture coordinate attributes.\n * const format = new Cesium.VertexFormat({\n * position : true,\n * st : true\n * });\n *\n * @see Geometry#attributes\n * @see Packable\n */\nfunction VertexFormat(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * When true, the vertex has a 3D position attribute.\n *

\n * 64-bit floating-point (for precision). 3 components per attribute.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.position = defaultValue(options.position, false);\n\n /**\n * When true, the vertex has a normal attribute (normalized), which is commonly used for lighting.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.normal = defaultValue(options.normal, false);\n\n /**\n * When true, the vertex has a 2D texture coordinate attribute.\n *

\n * 32-bit floating-point. 2 components per attribute\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.st = defaultValue(options.st, false);\n\n /**\n * When true, the vertex has a bitangent attribute (normalized), which is used for tangent-space effects like bump mapping.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.bitangent = defaultValue(options.bitangent, false);\n\n /**\n * When true, the vertex has a tangent attribute (normalized), which is used for tangent-space effects like bump mapping.\n *

\n * 32-bit floating-point. 3 components per attribute.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.tangent = defaultValue(options.tangent, false);\n\n /**\n * When true, the vertex has an RGB color attribute.\n *

\n * 8-bit unsigned byte. 3 components per attribute.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.color = defaultValue(options.color, false);\n}\n\n/**\n * An immutable vertex format with only a position attribute.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n */\nVertexFormat.POSITION_ONLY = Object.freeze(\n new VertexFormat({\n position: true,\n })\n);\n\n/**\n * An immutable vertex format with position and normal attributes.\n * This is compatible with per-instance color appearances like {@link PerInstanceColorAppearance}.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#normal\n */\nVertexFormat.POSITION_AND_NORMAL = Object.freeze(\n new VertexFormat({\n position: true,\n normal: true,\n })\n);\n\n/**\n * An immutable vertex format with position, normal, and st attributes.\n * This is compatible with {@link MaterialAppearance} when {@link MaterialAppearance#materialSupport}\n * is TEXTURED/code>.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#normal\n * @see VertexFormat#st\n */\nVertexFormat.POSITION_NORMAL_AND_ST = Object.freeze(\n new VertexFormat({\n position: true,\n normal: true,\n st: true,\n })\n);\n\n/**\n * An immutable vertex format with position and st attributes.\n * This is compatible with {@link EllipsoidSurfaceAppearance}.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#st\n */\nVertexFormat.POSITION_AND_ST = Object.freeze(\n new VertexFormat({\n position: true,\n st: true,\n })\n);\n\n/**\n * An immutable vertex format with position and color attributes.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#color\n */\nVertexFormat.POSITION_AND_COLOR = Object.freeze(\n new VertexFormat({\n position: true,\n color: true,\n })\n);\n\n/**\n * An immutable vertex format with well-known attributes: position, normal, st, tangent, and bitangent.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#normal\n * @see VertexFormat#st\n * @see VertexFormat#tangent\n * @see VertexFormat#bitangent\n */\nVertexFormat.ALL = Object.freeze(\n new VertexFormat({\n position: true,\n normal: true,\n st: true,\n tangent: true,\n bitangent: true,\n })\n);\n\n/**\n * An immutable vertex format with position, normal, and st attributes.\n * This is compatible with most appearances and materials; however\n * normal and st attributes are not always required. When this is\n * known in advance, another VertexFormat should be used.\n *\n * @type {VertexFormat}\n * @constant\n *\n * @see VertexFormat#position\n * @see VertexFormat#normal\n */\nVertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST;\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nVertexFormat.packedLength = 6;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {VertexFormat} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nVertexFormat.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value.position ? 1.0 : 0.0;\n array[startingIndex++] = value.normal ? 1.0 : 0.0;\n array[startingIndex++] = value.st ? 1.0 : 0.0;\n array[startingIndex++] = value.tangent ? 1.0 : 0.0;\n array[startingIndex++] = value.bitangent ? 1.0 : 0.0;\n array[startingIndex] = value.color ? 1.0 : 0.0;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {VertexFormat} [result] The object into which to store the result.\n * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided.\n */\nVertexFormat.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new VertexFormat();\n }\n\n result.position = array[startingIndex++] === 1.0;\n result.normal = array[startingIndex++] === 1.0;\n result.st = array[startingIndex++] === 1.0;\n result.tangent = array[startingIndex++] === 1.0;\n result.bitangent = array[startingIndex++] === 1.0;\n result.color = array[startingIndex] === 1.0;\n return result;\n};\n\n/**\n * Duplicates a VertexFormat instance.\n *\n * @param {VertexFormat} vertexFormat The vertex format to duplicate.\n * @param {VertexFormat} [result] The object onto which to store the result.\n * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined)\n */\nVertexFormat.clone = function (vertexFormat, result) {\n if (!defined(vertexFormat)) {\n return undefined;\n }\n if (!defined(result)) {\n result = new VertexFormat();\n }\n\n result.position = vertexFormat.position;\n result.normal = vertexFormat.normal;\n result.st = vertexFormat.st;\n result.tangent = vertexFormat.tangent;\n result.bitangent = vertexFormat.bitangent;\n result.color = vertexFormat.color;\n return result;\n};\nexport default VertexFormat;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst diffScratch = new Cartesian3();\n\n/**\n * Describes a cube centered at the origin.\n *\n * @alias BoxGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.minimum The minimum x, y, and z coordinates of the box.\n * @param {Cartesian3} options.maximum The maximum x, y, and z coordinates of the box.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @see BoxGeometry.fromDimensions\n * @see BoxGeometry.createGeometry\n * @see Packable\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Box.html|Cesium Sandcastle Box Demo}\n *\n * @example\n * const box = new Cesium.BoxGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,\n * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),\n * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)\n * });\n * const geometry = Cesium.BoxGeometry.createGeometry(box);\n */\nfunction BoxGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const min = options.minimum;\n const max = options.maximum;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"min\", min);\n Check.typeOf.object(\"max\", max);\n if (\n defined(options.offsetAttribute) &&\n options.offsetAttribute === GeometryOffsetAttribute.TOP\n ) {\n throw new DeveloperError(\n \"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n\n this._minimum = Cartesian3.clone(min);\n this._maximum = Cartesian3.clone(max);\n this._vertexFormat = vertexFormat;\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createBoxGeometry\";\n}\n\n/**\n * Creates a cube centered at the origin given its dimensions.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.dimensions The width, depth, and height of the box stored in the x, y, and z coordinates of the Cartesian3, respectively.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @returns {BoxGeometry}\n *\n * @exception {DeveloperError} All dimensions components must be greater than or equal to zero.\n *\n *\n * @example\n * const box = Cesium.BoxGeometry.fromDimensions({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,\n * dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)\n * });\n * const geometry = Cesium.BoxGeometry.createGeometry(box);\n *\n * @see BoxGeometry.createGeometry\n */\nBoxGeometry.fromDimensions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const dimensions = options.dimensions;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"dimensions\", dimensions);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.x\", dimensions.x, 0);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.y\", dimensions.y, 0);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.z\", dimensions.z, 0);\n //>>includeEnd('debug');\n\n const corner = Cartesian3.multiplyByScalar(dimensions, 0.5, new Cartesian3());\n\n return new BoxGeometry({\n minimum: Cartesian3.negate(corner, new Cartesian3()),\n maximum: corner,\n vertexFormat: options.vertexFormat,\n offsetAttribute: options.offsetAttribute,\n });\n};\n\n/**\n * Creates a cube from the dimensions of an AxisAlignedBoundingBox.\n *\n * @param {AxisAlignedBoundingBox} boundingBox A description of the AxisAlignedBoundingBox.\n * @returns {BoxGeometry}\n *\n *\n *\n * @example\n * const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ]));\n * const box = Cesium.BoxGeometry.fromAxisAlignedBoundingBox(aabb);\n *\n * @see BoxGeometry.createGeometry\n */\nBoxGeometry.fromAxisAlignedBoundingBox = function (boundingBox) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"boundingBox\", boundingBox);\n //>>includeEnd('debug');\n\n return new BoxGeometry({\n minimum: boundingBox.minimum,\n maximum: boundingBox.maximum,\n });\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nBoxGeometry.packedLength =\n 2 * Cartesian3.packedLength + VertexFormat.packedLength + 1;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {BoxGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nBoxGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._minimum, array, startingIndex);\n Cartesian3.pack(\n value._maximum,\n array,\n startingIndex + Cartesian3.packedLength\n );\n VertexFormat.pack(\n value._vertexFormat,\n array,\n startingIndex + 2 * Cartesian3.packedLength\n );\n array[\n startingIndex + 2 * Cartesian3.packedLength + VertexFormat.packedLength\n ] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchMin = new Cartesian3();\nconst scratchMax = new Cartesian3();\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n minimum: scratchMin,\n maximum: scratchMax,\n vertexFormat: scratchVertexFormat,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {BoxGeometry} [result] The object into which to store the result.\n * @returns {BoxGeometry} The modified result parameter or a new BoxGeometry instance if one was not provided.\n */\nBoxGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const min = Cartesian3.unpack(array, startingIndex, scratchMin);\n const max = Cartesian3.unpack(\n array,\n startingIndex + Cartesian3.packedLength,\n scratchMax\n );\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex + 2 * Cartesian3.packedLength,\n scratchVertexFormat\n );\n const offsetAttribute =\n array[\n startingIndex + 2 * Cartesian3.packedLength + VertexFormat.packedLength\n ];\n\n if (!defined(result)) {\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new BoxGeometry(scratchOptions);\n }\n\n result._minimum = Cartesian3.clone(min, result._minimum);\n result._maximum = Cartesian3.clone(max, result._maximum);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of a box, including its vertices, indices, and a bounding sphere.\n *\n * @param {BoxGeometry} boxGeometry A description of the box.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nBoxGeometry.createGeometry = function (boxGeometry) {\n const min = boxGeometry._minimum;\n const max = boxGeometry._maximum;\n const vertexFormat = boxGeometry._vertexFormat;\n\n if (Cartesian3.equals(min, max)) {\n return;\n }\n\n const attributes = new GeometryAttributes();\n let indices;\n let positions;\n\n if (\n vertexFormat.position &&\n (vertexFormat.st ||\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent)\n ) {\n if (vertexFormat.position) {\n // 8 corner points. Duplicated 3 times each for each incident edge/face.\n positions = new Float64Array(6 * 4 * 3);\n\n // +z face\n positions[0] = min.x;\n positions[1] = min.y;\n positions[2] = max.z;\n positions[3] = max.x;\n positions[4] = min.y;\n positions[5] = max.z;\n positions[6] = max.x;\n positions[7] = max.y;\n positions[8] = max.z;\n positions[9] = min.x;\n positions[10] = max.y;\n positions[11] = max.z;\n\n // -z face\n positions[12] = min.x;\n positions[13] = min.y;\n positions[14] = min.z;\n positions[15] = max.x;\n positions[16] = min.y;\n positions[17] = min.z;\n positions[18] = max.x;\n positions[19] = max.y;\n positions[20] = min.z;\n positions[21] = min.x;\n positions[22] = max.y;\n positions[23] = min.z;\n\n // +x face\n positions[24] = max.x;\n positions[25] = min.y;\n positions[26] = min.z;\n positions[27] = max.x;\n positions[28] = max.y;\n positions[29] = min.z;\n positions[30] = max.x;\n positions[31] = max.y;\n positions[32] = max.z;\n positions[33] = max.x;\n positions[34] = min.y;\n positions[35] = max.z;\n\n // -x face\n positions[36] = min.x;\n positions[37] = min.y;\n positions[38] = min.z;\n positions[39] = min.x;\n positions[40] = max.y;\n positions[41] = min.z;\n positions[42] = min.x;\n positions[43] = max.y;\n positions[44] = max.z;\n positions[45] = min.x;\n positions[46] = min.y;\n positions[47] = max.z;\n\n // +y face\n positions[48] = min.x;\n positions[49] = max.y;\n positions[50] = min.z;\n positions[51] = max.x;\n positions[52] = max.y;\n positions[53] = min.z;\n positions[54] = max.x;\n positions[55] = max.y;\n positions[56] = max.z;\n positions[57] = min.x;\n positions[58] = max.y;\n positions[59] = max.z;\n\n // -y face\n positions[60] = min.x;\n positions[61] = min.y;\n positions[62] = min.z;\n positions[63] = max.x;\n positions[64] = min.y;\n positions[65] = min.z;\n positions[66] = max.x;\n positions[67] = min.y;\n positions[68] = max.z;\n positions[69] = min.x;\n positions[70] = min.y;\n positions[71] = max.z;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n }\n\n if (vertexFormat.normal) {\n const normals = new Float32Array(6 * 4 * 3);\n\n // +z face\n normals[0] = 0.0;\n normals[1] = 0.0;\n normals[2] = 1.0;\n normals[3] = 0.0;\n normals[4] = 0.0;\n normals[5] = 1.0;\n normals[6] = 0.0;\n normals[7] = 0.0;\n normals[8] = 1.0;\n normals[9] = 0.0;\n normals[10] = 0.0;\n normals[11] = 1.0;\n\n // -z face\n normals[12] = 0.0;\n normals[13] = 0.0;\n normals[14] = -1.0;\n normals[15] = 0.0;\n normals[16] = 0.0;\n normals[17] = -1.0;\n normals[18] = 0.0;\n normals[19] = 0.0;\n normals[20] = -1.0;\n normals[21] = 0.0;\n normals[22] = 0.0;\n normals[23] = -1.0;\n\n // +x face\n normals[24] = 1.0;\n normals[25] = 0.0;\n normals[26] = 0.0;\n normals[27] = 1.0;\n normals[28] = 0.0;\n normals[29] = 0.0;\n normals[30] = 1.0;\n normals[31] = 0.0;\n normals[32] = 0.0;\n normals[33] = 1.0;\n normals[34] = 0.0;\n normals[35] = 0.0;\n\n // -x face\n normals[36] = -1.0;\n normals[37] = 0.0;\n normals[38] = 0.0;\n normals[39] = -1.0;\n normals[40] = 0.0;\n normals[41] = 0.0;\n normals[42] = -1.0;\n normals[43] = 0.0;\n normals[44] = 0.0;\n normals[45] = -1.0;\n normals[46] = 0.0;\n normals[47] = 0.0;\n\n // +y face\n normals[48] = 0.0;\n normals[49] = 1.0;\n normals[50] = 0.0;\n normals[51] = 0.0;\n normals[52] = 1.0;\n normals[53] = 0.0;\n normals[54] = 0.0;\n normals[55] = 1.0;\n normals[56] = 0.0;\n normals[57] = 0.0;\n normals[58] = 1.0;\n normals[59] = 0.0;\n\n // -y face\n normals[60] = 0.0;\n normals[61] = -1.0;\n normals[62] = 0.0;\n normals[63] = 0.0;\n normals[64] = -1.0;\n normals[65] = 0.0;\n normals[66] = 0.0;\n normals[67] = -1.0;\n normals[68] = 0.0;\n normals[69] = 0.0;\n normals[70] = -1.0;\n normals[71] = 0.0;\n\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.st) {\n const texCoords = new Float32Array(6 * 4 * 2);\n\n // +z face\n texCoords[0] = 0.0;\n texCoords[1] = 0.0;\n texCoords[2] = 1.0;\n texCoords[3] = 0.0;\n texCoords[4] = 1.0;\n texCoords[5] = 1.0;\n texCoords[6] = 0.0;\n texCoords[7] = 1.0;\n\n // -z face\n texCoords[8] = 1.0;\n texCoords[9] = 0.0;\n texCoords[10] = 0.0;\n texCoords[11] = 0.0;\n texCoords[12] = 0.0;\n texCoords[13] = 1.0;\n texCoords[14] = 1.0;\n texCoords[15] = 1.0;\n\n //+x face\n texCoords[16] = 0.0;\n texCoords[17] = 0.0;\n texCoords[18] = 1.0;\n texCoords[19] = 0.0;\n texCoords[20] = 1.0;\n texCoords[21] = 1.0;\n texCoords[22] = 0.0;\n texCoords[23] = 1.0;\n\n // -x face\n texCoords[24] = 1.0;\n texCoords[25] = 0.0;\n texCoords[26] = 0.0;\n texCoords[27] = 0.0;\n texCoords[28] = 0.0;\n texCoords[29] = 1.0;\n texCoords[30] = 1.0;\n texCoords[31] = 1.0;\n\n // +y face\n texCoords[32] = 1.0;\n texCoords[33] = 0.0;\n texCoords[34] = 0.0;\n texCoords[35] = 0.0;\n texCoords[36] = 0.0;\n texCoords[37] = 1.0;\n texCoords[38] = 1.0;\n texCoords[39] = 1.0;\n\n // -y face\n texCoords[40] = 0.0;\n texCoords[41] = 0.0;\n texCoords[42] = 1.0;\n texCoords[43] = 0.0;\n texCoords[44] = 1.0;\n texCoords[45] = 1.0;\n texCoords[46] = 0.0;\n texCoords[47] = 1.0;\n\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: texCoords,\n });\n }\n\n if (vertexFormat.tangent) {\n const tangents = new Float32Array(6 * 4 * 3);\n\n // +z face\n tangents[0] = 1.0;\n tangents[1] = 0.0;\n tangents[2] = 0.0;\n tangents[3] = 1.0;\n tangents[4] = 0.0;\n tangents[5] = 0.0;\n tangents[6] = 1.0;\n tangents[7] = 0.0;\n tangents[8] = 0.0;\n tangents[9] = 1.0;\n tangents[10] = 0.0;\n tangents[11] = 0.0;\n\n // -z face\n tangents[12] = -1.0;\n tangents[13] = 0.0;\n tangents[14] = 0.0;\n tangents[15] = -1.0;\n tangents[16] = 0.0;\n tangents[17] = 0.0;\n tangents[18] = -1.0;\n tangents[19] = 0.0;\n tangents[20] = 0.0;\n tangents[21] = -1.0;\n tangents[22] = 0.0;\n tangents[23] = 0.0;\n\n // +x face\n tangents[24] = 0.0;\n tangents[25] = 1.0;\n tangents[26] = 0.0;\n tangents[27] = 0.0;\n tangents[28] = 1.0;\n tangents[29] = 0.0;\n tangents[30] = 0.0;\n tangents[31] = 1.0;\n tangents[32] = 0.0;\n tangents[33] = 0.0;\n tangents[34] = 1.0;\n tangents[35] = 0.0;\n\n // -x face\n tangents[36] = 0.0;\n tangents[37] = -1.0;\n tangents[38] = 0.0;\n tangents[39] = 0.0;\n tangents[40] = -1.0;\n tangents[41] = 0.0;\n tangents[42] = 0.0;\n tangents[43] = -1.0;\n tangents[44] = 0.0;\n tangents[45] = 0.0;\n tangents[46] = -1.0;\n tangents[47] = 0.0;\n\n // +y face\n tangents[48] = -1.0;\n tangents[49] = 0.0;\n tangents[50] = 0.0;\n tangents[51] = -1.0;\n tangents[52] = 0.0;\n tangents[53] = 0.0;\n tangents[54] = -1.0;\n tangents[55] = 0.0;\n tangents[56] = 0.0;\n tangents[57] = -1.0;\n tangents[58] = 0.0;\n tangents[59] = 0.0;\n\n // -y face\n tangents[60] = 1.0;\n tangents[61] = 0.0;\n tangents[62] = 0.0;\n tangents[63] = 1.0;\n tangents[64] = 0.0;\n tangents[65] = 0.0;\n tangents[66] = 1.0;\n tangents[67] = 0.0;\n tangents[68] = 0.0;\n tangents[69] = 1.0;\n tangents[70] = 0.0;\n tangents[71] = 0.0;\n\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n const bitangents = new Float32Array(6 * 4 * 3);\n\n // +z face\n bitangents[0] = 0.0;\n bitangents[1] = 1.0;\n bitangents[2] = 0.0;\n bitangents[3] = 0.0;\n bitangents[4] = 1.0;\n bitangents[5] = 0.0;\n bitangents[6] = 0.0;\n bitangents[7] = 1.0;\n bitangents[8] = 0.0;\n bitangents[9] = 0.0;\n bitangents[10] = 1.0;\n bitangents[11] = 0.0;\n\n // -z face\n bitangents[12] = 0.0;\n bitangents[13] = 1.0;\n bitangents[14] = 0.0;\n bitangents[15] = 0.0;\n bitangents[16] = 1.0;\n bitangents[17] = 0.0;\n bitangents[18] = 0.0;\n bitangents[19] = 1.0;\n bitangents[20] = 0.0;\n bitangents[21] = 0.0;\n bitangents[22] = 1.0;\n bitangents[23] = 0.0;\n\n // +x face\n bitangents[24] = 0.0;\n bitangents[25] = 0.0;\n bitangents[26] = 1.0;\n bitangents[27] = 0.0;\n bitangents[28] = 0.0;\n bitangents[29] = 1.0;\n bitangents[30] = 0.0;\n bitangents[31] = 0.0;\n bitangents[32] = 1.0;\n bitangents[33] = 0.0;\n bitangents[34] = 0.0;\n bitangents[35] = 1.0;\n\n // -x face\n bitangents[36] = 0.0;\n bitangents[37] = 0.0;\n bitangents[38] = 1.0;\n bitangents[39] = 0.0;\n bitangents[40] = 0.0;\n bitangents[41] = 1.0;\n bitangents[42] = 0.0;\n bitangents[43] = 0.0;\n bitangents[44] = 1.0;\n bitangents[45] = 0.0;\n bitangents[46] = 0.0;\n bitangents[47] = 1.0;\n\n // +y face\n bitangents[48] = 0.0;\n bitangents[49] = 0.0;\n bitangents[50] = 1.0;\n bitangents[51] = 0.0;\n bitangents[52] = 0.0;\n bitangents[53] = 1.0;\n bitangents[54] = 0.0;\n bitangents[55] = 0.0;\n bitangents[56] = 1.0;\n bitangents[57] = 0.0;\n bitangents[58] = 0.0;\n bitangents[59] = 1.0;\n\n // -y face\n bitangents[60] = 0.0;\n bitangents[61] = 0.0;\n bitangents[62] = 1.0;\n bitangents[63] = 0.0;\n bitangents[64] = 0.0;\n bitangents[65] = 1.0;\n bitangents[66] = 0.0;\n bitangents[67] = 0.0;\n bitangents[68] = 1.0;\n bitangents[69] = 0.0;\n bitangents[70] = 0.0;\n bitangents[71] = 1.0;\n\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n // 12 triangles: 6 faces, 2 triangles each.\n indices = new Uint16Array(6 * 2 * 3);\n\n // +z face\n indices[0] = 0;\n indices[1] = 1;\n indices[2] = 2;\n indices[3] = 0;\n indices[4] = 2;\n indices[5] = 3;\n\n // -z face\n indices[6] = 4 + 2;\n indices[7] = 4 + 1;\n indices[8] = 4 + 0;\n indices[9] = 4 + 3;\n indices[10] = 4 + 2;\n indices[11] = 4 + 0;\n\n // +x face\n indices[12] = 8 + 0;\n indices[13] = 8 + 1;\n indices[14] = 8 + 2;\n indices[15] = 8 + 0;\n indices[16] = 8 + 2;\n indices[17] = 8 + 3;\n\n // -x face\n indices[18] = 12 + 2;\n indices[19] = 12 + 1;\n indices[20] = 12 + 0;\n indices[21] = 12 + 3;\n indices[22] = 12 + 2;\n indices[23] = 12 + 0;\n\n // +y face\n indices[24] = 16 + 2;\n indices[25] = 16 + 1;\n indices[26] = 16 + 0;\n indices[27] = 16 + 3;\n indices[28] = 16 + 2;\n indices[29] = 16 + 0;\n\n // -y face\n indices[30] = 20 + 0;\n indices[31] = 20 + 1;\n indices[32] = 20 + 2;\n indices[33] = 20 + 0;\n indices[34] = 20 + 2;\n indices[35] = 20 + 3;\n } else {\n // Positions only - no need to duplicate corner points\n positions = new Float64Array(8 * 3);\n\n positions[0] = min.x;\n positions[1] = min.y;\n positions[2] = min.z;\n positions[3] = max.x;\n positions[4] = min.y;\n positions[5] = min.z;\n positions[6] = max.x;\n positions[7] = max.y;\n positions[8] = min.z;\n positions[9] = min.x;\n positions[10] = max.y;\n positions[11] = min.z;\n positions[12] = min.x;\n positions[13] = min.y;\n positions[14] = max.z;\n positions[15] = max.x;\n positions[16] = min.y;\n positions[17] = max.z;\n positions[18] = max.x;\n positions[19] = max.y;\n positions[20] = max.z;\n positions[21] = min.x;\n positions[22] = max.y;\n positions[23] = max.z;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n // 12 triangles: 6 faces, 2 triangles each.\n indices = new Uint16Array(6 * 2 * 3);\n\n // plane z = corner.Z\n indices[0] = 4;\n indices[1] = 5;\n indices[2] = 6;\n indices[3] = 4;\n indices[4] = 6;\n indices[5] = 7;\n\n // plane z = -corner.Z\n indices[6] = 1;\n indices[7] = 0;\n indices[8] = 3;\n indices[9] = 1;\n indices[10] = 3;\n indices[11] = 2;\n\n // plane x = corner.X\n indices[12] = 1;\n indices[13] = 6;\n indices[14] = 5;\n indices[15] = 1;\n indices[16] = 2;\n indices[17] = 6;\n\n // plane y = corner.Y\n indices[18] = 2;\n indices[19] = 3;\n indices[20] = 7;\n indices[21] = 2;\n indices[22] = 7;\n indices[23] = 6;\n\n // plane x = -corner.X\n indices[24] = 3;\n indices[25] = 0;\n indices[26] = 4;\n indices[27] = 3;\n indices[28] = 4;\n indices[29] = 7;\n\n // plane y = -corner.Y\n indices[30] = 0;\n indices[31] = 1;\n indices[32] = 5;\n indices[33] = 0;\n indices[34] = 5;\n indices[35] = 4;\n }\n\n const diff = Cartesian3.subtract(max, min, diffScratch);\n const radius = Cartesian3.magnitude(diff) * 0.5;\n\n if (defined(boxGeometry._offsetAttribute)) {\n const length = positions.length;\n const offsetValue =\n boxGeometry._offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: new BoundingSphere(Cartesian3.ZERO, radius),\n offsetAttribute: boxGeometry._offsetAttribute,\n });\n};\n\nlet unitBoxGeometry;\n\n/**\n * Returns the geometric representation of a unit box, including its vertices, indices, and a bounding sphere.\n * @returns {Geometry} The computed vertices and indices.\n *\n * @private\n */\nBoxGeometry.getUnitBox = function () {\n if (!defined(unitBoxGeometry)) {\n unitBoxGeometry = BoxGeometry.createGeometry(\n BoxGeometry.fromDimensions({\n dimensions: new Cartesian3(1.0, 1.0, 1.0),\n vertexFormat: VertexFormat.POSITION_ONLY,\n })\n );\n }\n return unitBoxGeometry;\n};\nexport default BoxGeometry;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nconst diffScratch = new Cartesian3();\n\n/**\n * A description of the outline of a cube centered at the origin.\n *\n * @alias BoxOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.minimum The minimum x, y, and z coordinates of the box.\n * @param {Cartesian3} options.maximum The maximum x, y, and z coordinates of the box.\n *\n * @see BoxOutlineGeometry.fromDimensions\n * @see BoxOutlineGeometry.createGeometry\n * @see Packable\n *\n * @example\n * const box = new Cesium.BoxOutlineGeometry({\n * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),\n * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)\n * });\n * const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);\n */\nfunction BoxOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const min = options.minimum;\n const max = options.maximum;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"min\", min);\n Check.typeOf.object(\"max\", max);\n if (\n defined(options.offsetAttribute) &&\n options.offsetAttribute === GeometryOffsetAttribute.TOP\n ) {\n throw new DeveloperError(\n \"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n this._min = Cartesian3.clone(min);\n this._max = Cartesian3.clone(max);\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createBoxOutlineGeometry\";\n}\n\n/**\n * Creates an outline of a cube centered at the origin given its dimensions.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.dimensions The width, depth, and height of the box stored in the x, y, and z coordinates of the Cartesian3, respectively.\n * @returns {BoxOutlineGeometry}\n *\n * @exception {DeveloperError} All dimensions components must be greater than or equal to zero.\n *\n *\n * @example\n * const box = Cesium.BoxOutlineGeometry.fromDimensions({\n * dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)\n * });\n * const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);\n *\n * @see BoxOutlineGeometry.createGeometry\n */\nBoxOutlineGeometry.fromDimensions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const dimensions = options.dimensions;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"dimensions\", dimensions);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.x\", dimensions.x, 0);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.y\", dimensions.y, 0);\n Check.typeOf.number.greaterThanOrEquals(\"dimensions.z\", dimensions.z, 0);\n //>>includeEnd('debug');\n\n const corner = Cartesian3.multiplyByScalar(dimensions, 0.5, new Cartesian3());\n\n return new BoxOutlineGeometry({\n minimum: Cartesian3.negate(corner, new Cartesian3()),\n maximum: corner,\n offsetAttribute: options.offsetAttribute,\n });\n};\n\n/**\n * Creates an outline of a cube from the dimensions of an AxisAlignedBoundingBox.\n *\n * @param {AxisAlignedBoundingBox} boundingBox A description of the AxisAlignedBoundingBox.\n * @returns {BoxOutlineGeometry}\n *\n *\n *\n * @example\n * const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ]));\n * const box = Cesium.BoxOutlineGeometry.fromAxisAlignedBoundingBox(aabb);\n *\n * @see BoxOutlineGeometry.createGeometry\n */\nBoxOutlineGeometry.fromAxisAlignedBoundingBox = function (boundingBox) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"boundindBox\", boundingBox);\n //>>includeEnd('debug');\n\n return new BoxOutlineGeometry({\n minimum: boundingBox.minimum,\n maximum: boundingBox.maximum,\n });\n};\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nBoxOutlineGeometry.packedLength = 2 * Cartesian3.packedLength + 1;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {BoxOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nBoxOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._min, array, startingIndex);\n Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength);\n array[startingIndex + Cartesian3.packedLength * 2] = defaultValue(\n value._offsetAttribute,\n -1\n );\n\n return array;\n};\n\nconst scratchMin = new Cartesian3();\nconst scratchMax = new Cartesian3();\nconst scratchOptions = {\n minimum: scratchMin,\n maximum: scratchMax,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {BoxOutlineGeometry} [result] The object into which to store the result.\n * @returns {BoxOutlineGeometry} The modified result parameter or a new BoxOutlineGeometry instance if one was not provided.\n */\nBoxOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const min = Cartesian3.unpack(array, startingIndex, scratchMin);\n const max = Cartesian3.unpack(\n array,\n startingIndex + Cartesian3.packedLength,\n scratchMax\n );\n const offsetAttribute = array[startingIndex + Cartesian3.packedLength * 2];\n\n if (!defined(result)) {\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new BoxOutlineGeometry(scratchOptions);\n }\n\n result._min = Cartesian3.clone(min, result._min);\n result._max = Cartesian3.clone(max, result._max);\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an outline of a box, including its vertices, indices, and a bounding sphere.\n *\n * @param {BoxOutlineGeometry} boxGeometry A description of the box outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nBoxOutlineGeometry.createGeometry = function (boxGeometry) {\n const min = boxGeometry._min;\n const max = boxGeometry._max;\n\n if (Cartesian3.equals(min, max)) {\n return;\n }\n\n const attributes = new GeometryAttributes();\n const indices = new Uint16Array(12 * 2);\n const positions = new Float64Array(8 * 3);\n\n positions[0] = min.x;\n positions[1] = min.y;\n positions[2] = min.z;\n positions[3] = max.x;\n positions[4] = min.y;\n positions[5] = min.z;\n positions[6] = max.x;\n positions[7] = max.y;\n positions[8] = min.z;\n positions[9] = min.x;\n positions[10] = max.y;\n positions[11] = min.z;\n\n positions[12] = min.x;\n positions[13] = min.y;\n positions[14] = max.z;\n positions[15] = max.x;\n positions[16] = min.y;\n positions[17] = max.z;\n positions[18] = max.x;\n positions[19] = max.y;\n positions[20] = max.z;\n positions[21] = min.x;\n positions[22] = max.y;\n positions[23] = max.z;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n // top\n indices[0] = 4;\n indices[1] = 5;\n indices[2] = 5;\n indices[3] = 6;\n indices[4] = 6;\n indices[5] = 7;\n indices[6] = 7;\n indices[7] = 4;\n\n // bottom\n indices[8] = 0;\n indices[9] = 1;\n indices[10] = 1;\n indices[11] = 2;\n indices[12] = 2;\n indices[13] = 3;\n indices[14] = 3;\n indices[15] = 0;\n\n // left\n indices[16] = 0;\n indices[17] = 4;\n indices[18] = 1;\n indices[19] = 5;\n\n //right\n indices[20] = 2;\n indices[21] = 6;\n indices[22] = 3;\n indices[23] = 7;\n\n const diff = Cartesian3.subtract(max, min, diffScratch);\n const radius = Cartesian3.magnitude(diff) * 0.5;\n\n if (defined(boxGeometry._offsetAttribute)) {\n const length = positions.length;\n const offsetValue =\n boxGeometry._offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: new BoundingSphere(Cartesian3.ZERO, radius),\n offsetAttribute: boxGeometry._offsetAttribute,\n });\n};\nexport default BoxOutlineGeometry;\n", "import Color from \"./Color.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Value and type information for per-instance geometry color.\n *\n * @alias ColorGeometryInstanceAttribute\n * @constructor\n *\n * @param {number} [red=1.0] The red component.\n * @param {number} [green=1.0] The green component.\n * @param {number} [blue=1.0] The blue component.\n * @param {number} [alpha=1.0] The alpha component.\n *\n *\n * @example\n * const instance = new Cesium.GeometryInstance({\n * geometry : Cesium.BoxGeometry.fromDimensions({\n * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)\n * }),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(0.0, 0.0)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),\n * id : 'box',\n * attributes : {\n * color : new Cesium.ColorGeometryInstanceAttribute(red, green, blue, alpha)\n * }\n * });\n *\n * @see GeometryInstance\n * @see GeometryInstanceAttribute\n */\nfunction ColorGeometryInstanceAttribute(red, green, blue, alpha) {\n red = defaultValue(red, 1.0);\n green = defaultValue(green, 1.0);\n blue = defaultValue(blue, 1.0);\n alpha = defaultValue(alpha, 1.0);\n\n /**\n * The values for the attributes stored in a typed array.\n *\n * @type Uint8Array\n *\n * @default [255, 255, 255, 255]\n */\n this.value = new Uint8Array([\n Color.floatToByte(red),\n Color.floatToByte(green),\n Color.floatToByte(blue),\n Color.floatToByte(alpha),\n ]);\n}\n\nObject.defineProperties(ColorGeometryInstanceAttribute.prototype, {\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link ColorGeometryInstanceAttribute#value}.\n *\n * @memberof ColorGeometryInstanceAttribute.prototype\n *\n * @type {ComponentDatatype}\n * @readonly\n *\n * @default {@link ComponentDatatype.UNSIGNED_BYTE}\n */\n componentDatatype: {\n get: function () {\n return ComponentDatatype.UNSIGNED_BYTE;\n },\n },\n\n /**\n * The number of components in the attributes, i.e., {@link ColorGeometryInstanceAttribute#value}.\n *\n * @memberof ColorGeometryInstanceAttribute.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default 4\n */\n componentsPerAttribute: {\n get: function () {\n return 4;\n },\n },\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *\n * @memberof ColorGeometryInstanceAttribute.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n normalize: {\n get: function () {\n return true;\n },\n },\n});\n\n/**\n * Creates a new {@link ColorGeometryInstanceAttribute} instance given the provided {@link Color}.\n *\n * @param {Color} color The color.\n * @returns {ColorGeometryInstanceAttribute} The new {@link ColorGeometryInstanceAttribute} instance.\n *\n * @example\n * const instance = new Cesium.GeometryInstance({\n * geometry : geometry,\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.CORNFLOWERBLUE),\n * }\n * });\n */\nColorGeometryInstanceAttribute.fromColor = function (color) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(color)) {\n throw new DeveloperError(\"color is required.\");\n }\n //>>includeEnd('debug');\n\n return new ColorGeometryInstanceAttribute(\n color.red,\n color.green,\n color.blue,\n color.alpha\n );\n};\n\n/**\n * Converts a color to a typed array that can be used to assign a color attribute.\n *\n * @param {Color} color The color.\n * @param {Uint8Array} [result] The array to store the result in, if undefined a new instance will be created.\n *\n * @returns {Uint8Array} The modified result parameter or a new instance if result was undefined.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA, attributes.color);\n */\nColorGeometryInstanceAttribute.toValue = function (color, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(color)) {\n throw new DeveloperError(\"color is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Uint8Array(color.toBytes());\n }\n return color.toBytes(result);\n};\n\n/**\n * Compares the provided ColorGeometryInstanceAttributes and returns\n * true if they are equal, false otherwise.\n *\n * @param {ColorGeometryInstanceAttribute} [left] The first ColorGeometryInstanceAttribute.\n * @param {ColorGeometryInstanceAttribute} [right] The second ColorGeometryInstanceAttribute.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nColorGeometryInstanceAttribute.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.value[0] === right.value[0] &&\n left.value[1] === right.value[1] &&\n left.value[2] === right.value[2] &&\n left.value[3] === right.value[3])\n );\n};\nexport default ColorGeometryInstanceAttribute;\n", "import ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Value and type information for per-instance geometry attribute that determines if the geometry instance has a distance display condition.\n *\n * @alias DistanceDisplayConditionGeometryInstanceAttribute\n * @constructor\n *\n * @param {number} [near=0.0] The near distance.\n * @param {number} [far=Number.MAX_VALUE] The far distance.\n *\n * @exception {DeveloperError} far must be greater than near.\n *\n * @example\n * const instance = new Cesium.GeometryInstance({\n * geometry : new Cesium.BoxGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,\n * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),\n * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)\n * }),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),\n * id : 'box',\n * attributes : {\n * distanceDisplayCondition : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(100.0, 10000.0)\n * }\n * });\n *\n * @see GeometryInstance\n * @see GeometryInstanceAttribute\n */\nfunction DistanceDisplayConditionGeometryInstanceAttribute(near, far) {\n near = defaultValue(near, 0.0);\n far = defaultValue(far, Number.MAX_VALUE);\n\n //>>includeStart('debug', pragmas.debug);\n if (far <= near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n /**\n * The values for the attributes stored in a typed array.\n *\n * @type {Float32Array}\n *\n * @default [0.0, 0.0, Number.MAX_VALUE]\n */\n this.value = new Float32Array([near, far]);\n}\n\nObject.defineProperties(\n DistanceDisplayConditionGeometryInstanceAttribute.prototype,\n {\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.\n *\n * @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype\n *\n * @type {ComponentDatatype}\n * @readonly\n *\n * @default {@link ComponentDatatype.FLOAT}\n */\n componentDatatype: {\n get: function () {\n return ComponentDatatype.FLOAT;\n },\n },\n\n /**\n * The number of components in the attributes, i.e., {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.\n *\n * @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default 3\n */\n componentsPerAttribute: {\n get: function () {\n return 2;\n },\n },\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *\n * @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n normalize: {\n get: function () {\n return false;\n },\n },\n }\n);\n\n/**\n * Creates a new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance given the provided an enabled flag and {@link DistanceDisplayCondition}.\n *\n * @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition.\n * @returns {DistanceDisplayConditionGeometryInstanceAttribute} The new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance.\n *\n * @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near\n *\n * @example\n * const distanceDisplayCondition = new Cesium.DistanceDisplayCondition(100.0, 10000.0);\n * const instance = new Cesium.GeometryInstance({\n * geometry : geometry,\n * attributes : {\n * distanceDisplayCondition : Cesium.DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition)\n * }\n * });\n */\nDistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition = function (\n distanceDisplayCondition\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(distanceDisplayCondition)) {\n throw new DeveloperError(\"distanceDisplayCondition is required.\");\n }\n if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {\n throw new DeveloperError(\n \"distanceDisplayCondition.far distance must be greater than distanceDisplayCondition.near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n return new DistanceDisplayConditionGeometryInstanceAttribute(\n distanceDisplayCondition.near,\n distanceDisplayCondition.far\n );\n};\n\n/**\n * Converts a distance display condition to a typed array that can be used to assign a distance display condition attribute.\n *\n * @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition value.\n * @param {Float32Array} [result] The array to store the result in, if undefined a new instance will be created.\n * @returns {Float32Array} The modified result parameter or a new instance if result was undefined.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition);\n */\nDistanceDisplayConditionGeometryInstanceAttribute.toValue = function (\n distanceDisplayCondition,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(distanceDisplayCondition)) {\n throw new DeveloperError(\"distanceDisplayCondition is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Float32Array([\n distanceDisplayCondition.near,\n distanceDisplayCondition.far,\n ]);\n }\n result[0] = distanceDisplayCondition.near;\n result[1] = distanceDisplayCondition.far;\n return result;\n};\nexport default DistanceDisplayConditionGeometryInstanceAttribute;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Matrix4 from \"./Matrix4.js\";\n\n/**\n * Geometry instancing allows one {@link Geometry} object to be positions in several\n * different locations and colored uniquely. For example, one {@link BoxGeometry} can\n * be instanced several times, each with a different modelMatrix to change\n * its position, rotation, and scale.\n *\n * @alias GeometryInstance\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Geometry|GeometryFactory} options.geometry The geometry to instance.\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The model matrix that transforms to transform the geometry from model to world coordinates.\n * @param {object} [options.id] A user-defined object to return when the instance is picked with {@link Scene#pick} or get/set per-instance attributes with {@link Primitive#getGeometryInstanceAttributes}.\n * @param {object} [options.attributes] Per-instance attributes like a show or color attribute shown in the example below.\n *\n *\n * @example\n * // Create geometry for a box, and two instances that refer to it.\n * // One instance positions the box on the bottom and colored aqua.\n * // The other instance positions the box on the top and color white.\n * const geometry = Cesium.BoxGeometry.fromDimensions({\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,\n * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)\n * });\n * const instanceBottom = new Cesium.GeometryInstance({\n * geometry : geometry,\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)\n * },\n * id : 'bottom'\n * });\n * const instanceTop = new Cesium.GeometryInstance({\n * geometry : geometry,\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 3000000.0), new Cesium.Matrix4()),\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)\n * },\n * id : 'top'\n * });\n *\n * @see Geometry\n */\nfunction GeometryInstance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.geometry)) {\n throw new DeveloperError(\"options.geometry is required.\");\n }\n //>>includeEnd('debug');\n\n /**\n * The geometry being instanced.\n *\n * @type Geometry\n *\n * @default undefined\n */\n this.geometry = options.geometry;\n\n /**\n * The 4x4 transformation matrix that transforms the geometry from model to world coordinates.\n * When this is the identity matrix, the geometry is drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n * @type Matrix4\n *\n * @default Matrix4.IDENTITY\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n\n /**\n * User-defined object returned when the instance is picked or used to get/set per-instance attributes.\n *\n * @type {object}\n *\n * @default undefined\n *\n * @see Scene#pick\n * @see Primitive#getGeometryInstanceAttributes\n */\n this.id = options.id;\n\n /**\n * Used for picking primitives that wrap geometry instances.\n *\n * @private\n */\n this.pickPrimitive = options.pickPrimitive;\n\n /**\n * Per-instance attributes like {@link ColorGeometryInstanceAttribute} or {@link ShowGeometryInstanceAttribute}.\n * {@link Geometry} attributes varying per vertex; these attributes are constant for the entire instance.\n *\n * @type {object}\n *\n * @default undefined\n */\n this.attributes = defaultValue(options.attributes, {});\n\n /**\n * @private\n */\n this.westHemisphereGeometry = undefined;\n /**\n * @private\n */\n this.eastHemisphereGeometry = undefined;\n}\nexport default GeometryInstance;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport JulianDate from \"./JulianDate.js\";\n\n/**\n * An interval defined by a start and a stop time; optionally including those times as part of the interval.\n * Arbitrary data can optionally be associated with each instance for used with {@link TimeIntervalCollection}.\n *\n * @alias TimeInterval\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {JulianDate} [options.start=new JulianDate()] The start time of the interval.\n * @param {JulianDate} [options.stop=new JulianDate()] The stop time of the interval.\n * @param {boolean} [options.isStartIncluded=true] true if options.start is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if options.stop is included in the interval, false otherwise.\n * @param {object} [options.data] Arbitrary data associated with this interval.\n *\n * @example\n * // Create an instance that spans August 1st, 1980 and is associated\n * // with a Cartesian position.\n * const timeInterval = new Cesium.TimeInterval({\n * start : Cesium.JulianDate.fromIso8601('1980-08-01T00:00:00Z'),\n * stop : Cesium.JulianDate.fromIso8601('1980-08-02T00:00:00Z'),\n * isStartIncluded : true,\n * isStopIncluded : false,\n * data : Cesium.Cartesian3.fromDegrees(39.921037, -75.170082)\n * });\n *\n * @example\n * // Create two instances from ISO 8601 intervals with associated numeric data\n * // then compute their intersection, summing the data they contain.\n * const left = Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2000/2010',\n * data : 2\n * });\n *\n * const right = Cesium.TimeInterval.fromIso8601({\n * iso8601 : '1995/2005',\n * data : 3\n * });\n *\n * //The result of the below intersection will be an interval equivalent to\n * //const intersection = Cesium.TimeInterval.fromIso8601({\n * // iso8601 : '2000/2005',\n * // data : 5\n * //});\n * const intersection = new Cesium.TimeInterval();\n * Cesium.TimeInterval.intersect(left, right, intersection, function(leftData, rightData) {\n * return leftData + rightData;\n * });\n *\n * @example\n * // Check if an interval contains a specific time.\n * const dateToCheck = Cesium.JulianDate.fromIso8601('1982-09-08T11:30:00Z');\n * const containsDate = Cesium.TimeInterval.contains(timeInterval, dateToCheck);\n */\nfunction TimeInterval(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n /**\n * Gets or sets the start time of this interval.\n * @type {JulianDate}\n */\n this.start = defined(options.start)\n ? JulianDate.clone(options.start)\n : new JulianDate();\n\n /**\n * Gets or sets the stop time of this interval.\n * @type {JulianDate}\n */\n this.stop = defined(options.stop)\n ? JulianDate.clone(options.stop)\n : new JulianDate();\n\n /**\n * Gets or sets the data associated with this interval.\n * @type {*}\n */\n this.data = options.data;\n\n /**\n * Gets or sets whether or not the start time is included in this interval.\n * @type {boolean}\n * @default true\n */\n this.isStartIncluded = defaultValue(options.isStartIncluded, true);\n\n /**\n * Gets or sets whether or not the stop time is included in this interval.\n * @type {boolean}\n * @default true\n */\n this.isStopIncluded = defaultValue(options.isStopIncluded, true);\n}\n\nObject.defineProperties(TimeInterval.prototype, {\n /**\n * Gets whether or not this interval is empty.\n * @memberof TimeInterval.prototype\n * @type {boolean}\n * @readonly\n */\n isEmpty: {\n get: function () {\n const stopComparedToStart = JulianDate.compare(this.stop, this.start);\n return (\n stopComparedToStart < 0 ||\n (stopComparedToStart === 0 &&\n (!this.isStartIncluded || !this.isStopIncluded))\n );\n },\n },\n});\n\nconst scratchInterval = {\n start: undefined,\n stop: undefined,\n isStartIncluded: undefined,\n isStopIncluded: undefined,\n data: undefined,\n};\n\n/**\n * Creates a new instance from a {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} interval.\n *\n * @throws DeveloperError if options.iso8601 does not match proper formatting.\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.iso8601 An ISO 8601 interval.\n * @param {boolean} [options.isStartIncluded=true] true if options.start is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if options.stop is included in the interval, false otherwise.\n * @param {object} [options.data] Arbitrary data associated with this interval.\n * @param {TimeInterval} [result] An existing instance to use for the result.\n * @returns {TimeInterval} The modified result parameter or a new instance if none was provided.\n */\nTimeInterval.fromIso8601 = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.string(\"options.iso8601\", options.iso8601);\n //>>includeEnd('debug');\n\n const dates = options.iso8601.split(\"/\");\n if (dates.length !== 2) {\n throw new DeveloperError(\n \"options.iso8601 is an invalid ISO 8601 interval.\"\n );\n }\n const start = JulianDate.fromIso8601(dates[0]);\n const stop = JulianDate.fromIso8601(dates[1]);\n const isStartIncluded = defaultValue(options.isStartIncluded, true);\n const isStopIncluded = defaultValue(options.isStopIncluded, true);\n const data = options.data;\n\n if (!defined(result)) {\n scratchInterval.start = start;\n scratchInterval.stop = stop;\n scratchInterval.isStartIncluded = isStartIncluded;\n scratchInterval.isStopIncluded = isStopIncluded;\n scratchInterval.data = data;\n return new TimeInterval(scratchInterval);\n }\n\n result.start = start;\n result.stop = stop;\n result.isStartIncluded = isStartIncluded;\n result.isStopIncluded = isStopIncluded;\n result.data = data;\n return result;\n};\n\n/**\n * Creates an ISO8601 representation of the provided interval.\n *\n * @param {TimeInterval} timeInterval The interval to be converted.\n * @param {number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.\n * @returns {string} The ISO8601 representation of the provided interval.\n */\nTimeInterval.toIso8601 = function (timeInterval, precision) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"timeInterval\", timeInterval);\n //>>includeEnd('debug');\n\n return `${JulianDate.toIso8601(\n timeInterval.start,\n precision\n )}/${JulianDate.toIso8601(timeInterval.stop, precision)}`;\n};\n\n/**\n * Duplicates the provided instance.\n *\n * @param {TimeInterval} [timeInterval] The instance to clone.\n * @param {TimeInterval} [result] An existing instance to use for the result.\n * @returns {TimeInterval} The modified result parameter or a new instance if none was provided.\n */\nTimeInterval.clone = function (timeInterval, result) {\n if (!defined(timeInterval)) {\n return undefined;\n }\n if (!defined(result)) {\n return new TimeInterval(timeInterval);\n }\n result.start = timeInterval.start;\n result.stop = timeInterval.stop;\n result.isStartIncluded = timeInterval.isStartIncluded;\n result.isStopIncluded = timeInterval.isStopIncluded;\n result.data = timeInterval.data;\n return result;\n};\n\n/**\n * Compares two instances and returns true if they are equal, false otherwise.\n *\n * @param {TimeInterval} [left] The first instance.\n * @param {TimeInterval} [right] The second instance.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @returns {boolean} true if the dates are equal; otherwise, false.\n */\nTimeInterval.equals = function (left, right, dataComparer) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n ((left.isEmpty && right.isEmpty) ||\n (left.isStartIncluded === right.isStartIncluded &&\n left.isStopIncluded === right.isStopIncluded &&\n JulianDate.equals(left.start, right.start) &&\n JulianDate.equals(left.stop, right.stop) &&\n (left.data === right.data ||\n (defined(dataComparer) && dataComparer(left.data, right.data))))))\n );\n};\n\n/**\n * Compares two instances and returns true if they are within epsilon seconds of\n * each other. That is, in order for the dates to be considered equal (and for\n * this function to return true), the absolute value of the difference between them, in\n * seconds, must be less than epsilon.\n *\n * @param {TimeInterval} [left] The first instance.\n * @param {TimeInterval} [right] The second instance.\n * @param {number} [epsilon=0] The maximum number of seconds that should separate the two instances.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @returns {boolean} true if the two dates are within epsilon seconds of each other; otherwise false.\n */\nTimeInterval.equalsEpsilon = function (left, right, epsilon, dataComparer) {\n epsilon = defaultValue(epsilon, 0);\n\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n ((left.isEmpty && right.isEmpty) ||\n (left.isStartIncluded === right.isStartIncluded &&\n left.isStopIncluded === right.isStopIncluded &&\n JulianDate.equalsEpsilon(left.start, right.start, epsilon) &&\n JulianDate.equalsEpsilon(left.stop, right.stop, epsilon) &&\n (left.data === right.data ||\n (defined(dataComparer) && dataComparer(left.data, right.data))))))\n );\n};\n\n/**\n * Computes the intersection of two intervals, optionally merging their data.\n *\n * @param {TimeInterval} left The first interval.\n * @param {TimeInterval} [right] The second interval.\n * @param {TimeInterval} [result] An existing instance to use for the result.\n * @param {TimeInterval.MergeCallback} [mergeCallback] A function which merges the data of the two intervals. If omitted, the data from the left interval will be used.\n * @returns {TimeInterval} The modified result parameter.\n */\nTimeInterval.intersect = function (left, right, result, mergeCallback) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"left\", left);\n //>>includeEnd('debug');\n\n if (!defined(right)) {\n return TimeInterval.clone(TimeInterval.EMPTY, result);\n }\n\n const leftStart = left.start;\n const leftStop = left.stop;\n\n const rightStart = right.start;\n const rightStop = right.stop;\n\n const intersectsStartRight =\n JulianDate.greaterThanOrEquals(rightStart, leftStart) &&\n JulianDate.greaterThanOrEquals(leftStop, rightStart);\n const intersectsStartLeft =\n !intersectsStartRight &&\n JulianDate.lessThanOrEquals(rightStart, leftStart) &&\n JulianDate.lessThanOrEquals(leftStart, rightStop);\n\n if (!intersectsStartRight && !intersectsStartLeft) {\n return TimeInterval.clone(TimeInterval.EMPTY, result);\n }\n\n const leftIsStartIncluded = left.isStartIncluded;\n const leftIsStopIncluded = left.isStopIncluded;\n const rightIsStartIncluded = right.isStartIncluded;\n const rightIsStopIncluded = right.isStopIncluded;\n const leftLessThanRight = JulianDate.lessThan(leftStop, rightStop);\n\n if (!defined(result)) {\n result = new TimeInterval();\n }\n\n result.start = intersectsStartRight ? rightStart : leftStart;\n result.isStartIncluded =\n (leftIsStartIncluded && rightIsStartIncluded) ||\n (!JulianDate.equals(rightStart, leftStart) &&\n ((intersectsStartRight && rightIsStartIncluded) ||\n (intersectsStartLeft && leftIsStartIncluded)));\n result.stop = leftLessThanRight ? leftStop : rightStop;\n result.isStopIncluded = leftLessThanRight\n ? leftIsStopIncluded\n : (leftIsStopIncluded && rightIsStopIncluded) ||\n (!JulianDate.equals(rightStop, leftStop) && rightIsStopIncluded);\n result.data = defined(mergeCallback)\n ? mergeCallback(left.data, right.data)\n : left.data;\n return result;\n};\n\n/**\n * Checks if the specified date is inside the provided interval.\n *\n * @param {TimeInterval} timeInterval The interval.\n * @param {JulianDate} julianDate The date to check.\n * @returns {boolean} true if the interval contains the specified date, false otherwise.\n */\nTimeInterval.contains = function (timeInterval, julianDate) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"timeInterval\", timeInterval);\n Check.typeOf.object(\"julianDate\", julianDate);\n //>>includeEnd('debug');\n\n if (timeInterval.isEmpty) {\n return false;\n }\n\n const startComparedToDate = JulianDate.compare(\n timeInterval.start,\n julianDate\n );\n if (startComparedToDate === 0) {\n return timeInterval.isStartIncluded;\n }\n\n const dateComparedToStop = JulianDate.compare(julianDate, timeInterval.stop);\n if (dateComparedToStop === 0) {\n return timeInterval.isStopIncluded;\n }\n\n return startComparedToDate < 0 && dateComparedToStop < 0;\n};\n\n/**\n * Duplicates this instance.\n *\n * @param {TimeInterval} [result] An existing instance to use for the result.\n * @returns {TimeInterval} The modified result parameter or a new instance if none was provided.\n */\nTimeInterval.prototype.clone = function (result) {\n return TimeInterval.clone(this, result);\n};\n\n/**\n * Compares this instance against the provided instance componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {TimeInterval} [right] The right hand side interval.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nTimeInterval.prototype.equals = function (right, dataComparer) {\n return TimeInterval.equals(this, right, dataComparer);\n};\n\n/**\n * Compares this instance against the provided instance componentwise and returns\n * true if they are within the provided epsilon,\n * false otherwise.\n *\n * @param {TimeInterval} [right] The right hand side interval.\n * @param {number} [epsilon=0] The epsilon to use for equality testing.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @returns {boolean} true if they are within the provided epsilon, false otherwise.\n */\nTimeInterval.prototype.equalsEpsilon = function (right, epsilon, dataComparer) {\n return TimeInterval.equalsEpsilon(this, right, epsilon, dataComparer);\n};\n\n/**\n * Creates a string representing this TimeInterval in ISO8601 format.\n *\n * @returns {string} A string representing this TimeInterval in ISO8601 format.\n */\nTimeInterval.prototype.toString = function () {\n return TimeInterval.toIso8601(this);\n};\n\n/**\n * An immutable empty interval.\n *\n * @type {TimeInterval}\n * @constant\n */\nTimeInterval.EMPTY = Object.freeze(\n new TimeInterval({\n start: new JulianDate(),\n stop: new JulianDate(),\n isStartIncluded: false,\n isStopIncluded: false,\n })\n);\n\n/**\n * Function interface for merging interval data.\n * @callback TimeInterval.MergeCallback\n *\n * @param {*} leftData The first data instance.\n * @param {*} rightData The second data instance.\n * @returns {*} The result of merging the two data instances.\n */\n\n/**\n * Function interface for comparing interval data.\n * @callback TimeInterval.DataComparer\n * @param {*} leftData The first data instance.\n * @param {*} rightData The second data instance.\n * @returns {boolean} true if the provided instances are equal, false otherwise.\n */\nexport default TimeInterval;\n", "import JulianDate from \"./JulianDate.js\";\nimport TimeInterval from \"./TimeInterval.js\";\n\nconst MINIMUM_VALUE = Object.freeze(\n JulianDate.fromIso8601(\"0000-01-01T00:00:00Z\")\n);\nconst MAXIMUM_VALUE = Object.freeze(\n JulianDate.fromIso8601(\"9999-12-31T24:00:00Z\")\n);\nconst MAXIMUM_INTERVAL = Object.freeze(\n new TimeInterval({\n start: MINIMUM_VALUE,\n stop: MAXIMUM_VALUE,\n })\n);\n\n/**\n * Constants related to ISO8601 support.\n *\n * @namespace\n *\n * @see {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601 on Wikipedia}\n * @see JulianDate\n * @see TimeInterval\n */\nconst Iso8601 = {\n /**\n * A {@link JulianDate} representing the earliest time representable by an ISO8601 date.\n * This is equivalent to the date string '0000-01-01T00:00:00Z'\n *\n * @type {JulianDate}\n * @constant\n */\n MINIMUM_VALUE: MINIMUM_VALUE,\n\n /**\n * A {@link JulianDate} representing the latest time representable by an ISO8601 date.\n * This is equivalent to the date string '9999-12-31T24:00:00Z'\n *\n * @type {JulianDate}\n * @constant\n */\n MAXIMUM_VALUE: MAXIMUM_VALUE,\n\n /**\n * A {@link TimeInterval} representing the largest interval representable by an ISO8601 interval.\n * This is equivalent to the interval string '0000-01-01T00:00:00Z/9999-12-31T24:00:00Z'\n *\n * @type {TimeInterval}\n * @constant\n */\n MAXIMUM_INTERVAL: MAXIMUM_INTERVAL,\n};\nexport default Iso8601;\n", "import Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Value and type information for per-instance geometry attribute that determines the geometry instance offset\n *\n * @alias OffsetGeometryInstanceAttribute\n * @constructor\n *\n * @param {number} [x=0] The x translation\n * @param {number} [y=0] The y translation\n * @param {number} [z=0] The z translation\n *\n * @private\n *\n * @see GeometryInstance\n * @see GeometryInstanceAttribute\n */\nfunction OffsetGeometryInstanceAttribute(x, y, z) {\n x = defaultValue(x, 0);\n y = defaultValue(y, 0);\n z = defaultValue(z, 0);\n\n /**\n * The values for the attributes stored in a typed array.\n *\n * @type Float32Array\n */\n this.value = new Float32Array([x, y, z]);\n}\n\nObject.defineProperties(OffsetGeometryInstanceAttribute.prototype, {\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link OffsetGeometryInstanceAttribute#value}.\n *\n * @memberof OffsetGeometryInstanceAttribute.prototype\n *\n * @type {ComponentDatatype}\n * @readonly\n *\n * @default {@link ComponentDatatype.FLOAT}\n */\n componentDatatype: {\n get: function () {\n return ComponentDatatype.FLOAT;\n },\n },\n\n /**\n * The number of components in the attributes, i.e., {@link OffsetGeometryInstanceAttribute#value}.\n *\n * @memberof OffsetGeometryInstanceAttribute.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default 3\n */\n componentsPerAttribute: {\n get: function () {\n return 3;\n },\n },\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *\n * @memberof OffsetGeometryInstanceAttribute.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n normalize: {\n get: function () {\n return false;\n },\n },\n});\n\n/**\n * Creates a new {@link OffsetGeometryInstanceAttribute} instance given the provided an enabled flag and {@link DistanceDisplayCondition}.\n *\n * @param {Cartesian3} offset The cartesian offset\n * @returns {OffsetGeometryInstanceAttribute} The new {@link OffsetGeometryInstanceAttribute} instance.\n */\nOffsetGeometryInstanceAttribute.fromCartesian3 = function (offset) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"offset\", offset);\n //>>includeEnd('debug');\n\n return new OffsetGeometryInstanceAttribute(offset.x, offset.y, offset.z);\n};\n\n/**\n * Converts a distance display condition to a typed array that can be used to assign a distance display condition attribute.\n *\n * @param {Cartesian3} offset The cartesian offset\n * @param {Float32Array} [result] The array to store the result in, if undefined a new instance will be created.\n * @returns {Float32Array} The modified result parameter or a new instance if result was undefined.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.modelMatrix = Cesium.OffsetGeometryInstanceAttribute.toValue(modelMatrix, attributes.modelMatrix);\n */\nOffsetGeometryInstanceAttribute.toValue = function (offset, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"offset\", offset);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Float32Array([offset.x, offset.y, offset.z]);\n }\n\n result[0] = offset.x;\n result[1] = offset.y;\n result[2] = offset.z;\n return result;\n};\nexport default OffsetGeometryInstanceAttribute;\n", "import ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Value and type information for per-instance geometry attribute that determines if the geometry instance will be shown.\n *\n * @alias ShowGeometryInstanceAttribute\n * @constructor\n *\n * @param {boolean} [show=true] Determines if the geometry instance will be shown.\n *\n *\n * @example\n * const instance = new Cesium.GeometryInstance({\n * geometry : new Cesium.BoxGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,\n * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),\n * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)\n * }),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),\n * id : 'box',\n * attributes : {\n * show : new Cesium.ShowGeometryInstanceAttribute(false)\n * }\n * });\n *\n * @see GeometryInstance\n * @see GeometryInstanceAttribute\n */\nfunction ShowGeometryInstanceAttribute(show) {\n show = defaultValue(show, true);\n\n /**\n * The values for the attributes stored in a typed array.\n *\n * @type Uint8Array\n *\n * @default [1.0]\n */\n this.value = ShowGeometryInstanceAttribute.toValue(show);\n}\n\nObject.defineProperties(ShowGeometryInstanceAttribute.prototype, {\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link ColorGeometryInstanceAttribute#value}.\n *\n * @memberof ShowGeometryInstanceAttribute.prototype\n *\n * @type {ComponentDatatype}\n * @readonly\n *\n * @default {@link ComponentDatatype.UNSIGNED_BYTE}\n */\n componentDatatype: {\n get: function () {\n return ComponentDatatype.UNSIGNED_BYTE;\n },\n },\n\n /**\n * The number of components in the attributes, i.e., {@link ColorGeometryInstanceAttribute#value}.\n *\n * @memberof ShowGeometryInstanceAttribute.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default 1\n */\n componentsPerAttribute: {\n get: function () {\n return 1;\n },\n },\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *\n * @memberof ShowGeometryInstanceAttribute.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n normalize: {\n get: function () {\n return false;\n },\n },\n});\n\n/**\n * Converts a boolean show to a typed array that can be used to assign a show attribute.\n *\n * @param {boolean} show The show value.\n * @param {Uint8Array} [result] The array to store the result in, if undefined a new instance will be created.\n * @returns {Uint8Array} The modified result parameter or a new instance if result was undefined.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true, attributes.show);\n */\nShowGeometryInstanceAttribute.toValue = function (show, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(show)) {\n throw new DeveloperError(\"show is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Uint8Array([show]);\n }\n result[0] = show;\n return result;\n};\nexport default ShowGeometryInstanceAttribute;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_positionEC;\\n\\\nin vec3 v_normalEC;\\n\\\nin vec3 v_tangentEC;\\n\\\nin vec3 v_bitangentEC;\\n\\\nin vec2 v_st;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec3 positionToEyeEC = -v_positionEC;\\n\\\n mat3 tangentToEyeMatrix = czm_tangentToEyeSpaceMatrix(v_normalEC, v_tangentEC, v_bitangentEC);\\n\\\n\\n\\\n vec3 normalEC = normalize(v_normalEC);\\n\\\n#ifdef FACE_FORWARD\\n\\\n normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\\n\\\n#endif\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n materialInput.normalEC = normalEC;\\n\\\n materialInput.tangentToEyeMatrix = tangentToEyeMatrix;\\n\\\n materialInput.positionToEyeEC = positionToEyeEC;\\n\\\n materialInput.st = v_st;\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n\\n\\\n#ifdef FLAT\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#else\\n\\\n out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 normal;\\n\\\nin vec3 tangent;\\n\\\nin vec3 bitangent;\\n\\\nin vec2 st;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec3 v_positionEC;\\n\\\nout vec3 v_normalEC;\\n\\\nout vec3 v_tangentEC;\\n\\\nout vec3 v_bitangentEC;\\n\\\nout vec2 v_st;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 p = czm_computePosition();\\n\\\n\\n\\\n v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates\\n\\\n v_normalEC = czm_normal * normal; // normal in eye coordinates\\n\\\n v_tangentEC = czm_normal * tangent; // tangent in eye coordinates\\n\\\n v_bitangentEC = czm_normal * bitangent; // bitangent in eye coordinates\\n\\\n v_st = st;\\n\\\n\\n\\\n gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_positionEC;\\n\\\nin vec3 v_normalEC;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec3 positionToEyeEC = -v_positionEC;\\n\\\n\\n\\\n vec3 normalEC = normalize(v_normalEC);\\n\\\n#ifdef FACE_FORWARD\\n\\\n normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\\n\\\n#endif\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n materialInput.normalEC = normalEC;\\n\\\n materialInput.positionToEyeEC = positionToEyeEC;\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n\\n\\\n#ifdef FLAT\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#else\\n\\\n out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 normal;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec3 v_positionEC;\\n\\\nout vec3 v_normalEC;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 p = czm_computePosition();\\n\\\n\\n\\\n v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates\\n\\\n v_normalEC = czm_normal * normal; // normal in eye coordinates\\n\\\n\\n\\\n gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_positionEC;\\n\\\nin vec3 v_normalEC;\\n\\\nin vec2 v_st;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec3 positionToEyeEC = -v_positionEC;\\n\\\n\\n\\\n vec3 normalEC = normalize(v_normalEC);\\n\\\n#ifdef FACE_FORWARD\\n\\\n normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\\n\\\n#endif\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n materialInput.normalEC = normalEC;\\n\\\n materialInput.positionToEyeEC = positionToEyeEC;\\n\\\n materialInput.st = v_st;\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n\\n\\\n#ifdef FLAT\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#else\\n\\\n out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 normal;\\n\\\nin vec2 st;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec3 v_positionEC;\\n\\\nout vec3 v_normalEC;\\n\\\nout vec2 v_st;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 p = czm_computePosition();\\n\\\n\\n\\\n v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates\\n\\\n v_normalEC = czm_normal * normal; // normal in eye coordinates\\n\\\n v_st = st;\\n\\\n\\n\\\n gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n}\\n\\\n\";\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines how two pixels' values are combined.\n *\n * @enum {number}\n */\nconst BlendEquation = {\n /**\n * Pixel values are added componentwise. This is used in additive blending for translucency.\n *\n * @type {number}\n * @constant\n */\n ADD: WebGLConstants.FUNC_ADD,\n\n /**\n * Pixel values are subtracted componentwise (source - destination). This is used in alpha blending for translucency.\n *\n * @type {number}\n * @constant\n */\n SUBTRACT: WebGLConstants.FUNC_SUBTRACT,\n\n /**\n * Pixel values are subtracted componentwise (destination - source).\n *\n * @type {number}\n * @constant\n */\n REVERSE_SUBTRACT: WebGLConstants.FUNC_REVERSE_SUBTRACT,\n\n /**\n * Pixel values are given to the minimum function (min(source, destination)).\n *\n * This equation operates on each pixel color component.\n *\n * @type {number}\n * @constant\n */\n MIN: WebGLConstants.MIN,\n\n /**\n * Pixel values are given to the maximum function (max(source, destination)).\n *\n * This equation operates on each pixel color component.\n *\n * @type {number}\n * @constant\n */\n MAX: WebGLConstants.MAX,\n};\nexport default Object.freeze(BlendEquation);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines how blending factors are computed.\n *\n * @enum {number}\n */\nconst BlendFunction = {\n /**\n * The blend factor is zero.\n *\n * @type {number}\n * @constant\n */\n ZERO: WebGLConstants.ZERO,\n\n /**\n * The blend factor is one.\n *\n * @type {number}\n * @constant\n */\n ONE: WebGLConstants.ONE,\n\n /**\n * The blend factor is the source color.\n *\n * @type {number}\n * @constant\n */\n SOURCE_COLOR: WebGLConstants.SRC_COLOR,\n\n /**\n * The blend factor is one minus the source color.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_SOURCE_COLOR: WebGLConstants.ONE_MINUS_SRC_COLOR,\n\n /**\n * The blend factor is the destination color.\n *\n * @type {number}\n * @constant\n */\n DESTINATION_COLOR: WebGLConstants.DST_COLOR,\n\n /**\n * The blend factor is one minus the destination color.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_DESTINATION_COLOR: WebGLConstants.ONE_MINUS_DST_COLOR,\n\n /**\n * The blend factor is the source alpha.\n *\n * @type {number}\n * @constant\n */\n SOURCE_ALPHA: WebGLConstants.SRC_ALPHA,\n\n /**\n * The blend factor is one minus the source alpha.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_SOURCE_ALPHA: WebGLConstants.ONE_MINUS_SRC_ALPHA,\n\n /**\n * The blend factor is the destination alpha.\n *\n * @type {number}\n * @constant\n */\n DESTINATION_ALPHA: WebGLConstants.DST_ALPHA,\n\n /**\n * The blend factor is one minus the destination alpha.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_DESTINATION_ALPHA: WebGLConstants.ONE_MINUS_DST_ALPHA,\n\n /**\n * The blend factor is the constant color.\n *\n * @type {number}\n * @constant\n */\n CONSTANT_COLOR: WebGLConstants.CONSTANT_COLOR,\n\n /**\n * The blend factor is one minus the constant color.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_CONSTANT_COLOR: WebGLConstants.ONE_MINUS_CONSTANT_COLOR,\n\n /**\n * The blend factor is the constant alpha.\n *\n * @type {number}\n * @constant\n */\n CONSTANT_ALPHA: WebGLConstants.CONSTANT_ALPHA,\n\n /**\n * The blend factor is one minus the constant alpha.\n *\n * @type {number}\n * @constant\n */\n ONE_MINUS_CONSTANT_ALPHA: WebGLConstants.ONE_MINUS_CONSTANT_ALPHA,\n\n /**\n * The blend factor is the saturated source alpha.\n *\n * @type {number}\n * @constant\n */\n SOURCE_ALPHA_SATURATE: WebGLConstants.SRC_ALPHA_SATURATE,\n};\nexport default Object.freeze(BlendFunction);\n", "import BlendEquation from \"./BlendEquation.js\";\nimport BlendFunction from \"./BlendFunction.js\";\n\n/**\n * The blending state combines {@link BlendEquation} and {@link BlendFunction} and the\n * enabled flag to define the full blending state for combining source and\n * destination fragments when rendering.\n *

\n * This is a helper when using custom render states with {@link Appearance#renderState}.\n *

\n *\n * @namespace\n */\nconst BlendingState = {\n /**\n * Blending is disabled.\n *\n * @type {object}\n * @constant\n */\n DISABLED: Object.freeze({\n enabled: false,\n }),\n\n /**\n * Blending is enabled using alpha blending, source(source.alpha) + destination(1 - source.alpha).\n *\n * @type {object}\n * @constant\n */\n ALPHA_BLEND: Object.freeze({\n enabled: true,\n equationRgb: BlendEquation.ADD,\n equationAlpha: BlendEquation.ADD,\n functionSourceRgb: BlendFunction.SOURCE_ALPHA,\n functionSourceAlpha: BlendFunction.ONE,\n functionDestinationRgb: BlendFunction.ONE_MINUS_SOURCE_ALPHA,\n functionDestinationAlpha: BlendFunction.ONE_MINUS_SOURCE_ALPHA,\n }),\n\n /**\n * Blending is enabled using alpha blending with premultiplied alpha, source + destination(1 - source.alpha).\n *\n * @type {object}\n * @constant\n */\n PRE_MULTIPLIED_ALPHA_BLEND: Object.freeze({\n enabled: true,\n equationRgb: BlendEquation.ADD,\n equationAlpha: BlendEquation.ADD,\n functionSourceRgb: BlendFunction.ONE,\n functionSourceAlpha: BlendFunction.ONE,\n functionDestinationRgb: BlendFunction.ONE_MINUS_SOURCE_ALPHA,\n functionDestinationAlpha: BlendFunction.ONE_MINUS_SOURCE_ALPHA,\n }),\n\n /**\n * Blending is enabled using additive blending, source(source.alpha) + destination.\n *\n * @type {object}\n * @constant\n */\n ADDITIVE_BLEND: Object.freeze({\n enabled: true,\n equationRgb: BlendEquation.ADD,\n equationAlpha: BlendEquation.ADD,\n functionSourceRgb: BlendFunction.SOURCE_ALPHA,\n functionSourceAlpha: BlendFunction.ONE,\n functionDestinationRgb: BlendFunction.ONE,\n functionDestinationAlpha: BlendFunction.ONE,\n }),\n};\nexport default Object.freeze(BlendingState);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines which triangles, if any, are culled.\n *\n * @enum {number}\n */\nconst CullFace = {\n /**\n * Front-facing triangles are culled.\n *\n * @type {number}\n * @constant\n */\n FRONT: WebGLConstants.FRONT,\n\n /**\n * Back-facing triangles are culled.\n *\n * @type {number}\n * @constant\n */\n BACK: WebGLConstants.BACK,\n\n /**\n * Both front-facing and back-facing triangles are culled.\n *\n * @type {number}\n * @constant\n */\n FRONT_AND_BACK: WebGLConstants.FRONT_AND_BACK,\n};\nexport default Object.freeze(CullFace);\n", "import clone from \"../Core/clone.js\";\nimport combine from \"../Core/combine.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport CullFace from \"./CullFace.js\";\n\n/**\n * An appearance defines the full GLSL vertex and fragment shaders and the\n * render state used to draw a {@link Primitive}. All appearances implement\n * this base Appearance interface.\n *\n * @alias Appearance\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so {@link Appearance#renderState} has alpha blending enabled.\n * @param {boolean} [options.closed=false] When true, the geometry is expected to be closed so {@link Appearance#renderState} has backface culling enabled.\n * @param {Material} [options.material=Material.ColorType] The material used to determine the fragment color.\n * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.\n * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.\n * @param {object} [options.renderState] Optional render state to override the default render state.\n *\n * @see MaterialAppearance\n * @see EllipsoidSurfaceAppearance\n * @see PerInstanceColorAppearance\n * @see DebugAppearance\n * @see PolylineColorAppearance\n * @see PolylineMaterialAppearance\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}\n */\nfunction Appearance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The material used to determine the fragment color. Unlike other {@link Appearance}\n * properties, this is not read-only, so an appearance's material can change on the fly.\n *\n * @type Material\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}\n */\n this.material = options.material;\n\n /**\n * When true, the geometry is expected to appear translucent.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.translucent = defaultValue(options.translucent, true);\n\n this._vertexShaderSource = options.vertexShaderSource;\n this._fragmentShaderSource = options.fragmentShaderSource;\n this._renderState = options.renderState;\n this._closed = defaultValue(options.closed, false);\n}\n\nObject.defineProperties(Appearance.prototype, {\n /**\n * The GLSL source code for the vertex shader.\n *\n * @memberof Appearance.prototype\n *\n * @type {string}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n return this._vertexShaderSource;\n },\n },\n\n /**\n * The GLSL source code for the fragment shader. The full fragment shader\n * source is built procedurally taking into account the {@link Appearance#material}.\n * Use {@link Appearance#getFragmentShaderSource} to get the full source.\n *\n * @memberof Appearance.prototype\n *\n * @type {string}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n\n /**\n * The WebGL fixed-function state to use when rendering the geometry.\n *\n * @memberof Appearance.prototype\n *\n * @type {object}\n * @readonly\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n },\n\n /**\n * When true, the geometry is expected to be closed.\n *\n * @memberof Appearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n closed: {\n get: function () {\n return this._closed;\n },\n },\n});\n\n/**\n * Procedurally creates the full GLSL fragment shader source for this appearance\n * taking into account {@link Appearance#fragmentShaderSource} and {@link Appearance#material}.\n *\n * @returns {string} The full GLSL fragment shader source.\n */\nAppearance.prototype.getFragmentShaderSource = function () {\n const parts = [];\n if (this.flat) {\n parts.push(\"#define FLAT\");\n }\n if (this.faceForward) {\n parts.push(\"#define FACE_FORWARD\");\n }\n if (defined(this.material)) {\n parts.push(this.material.shaderSource);\n }\n parts.push(this.fragmentShaderSource);\n\n return parts.join(\"\\n\");\n};\n\n/**\n * Determines if the geometry is translucent based on {@link Appearance#translucent} and {@link Material#isTranslucent}.\n *\n * @returns {boolean} true if the appearance is translucent.\n */\nAppearance.prototype.isTranslucent = function () {\n return (\n (defined(this.material) && this.material.isTranslucent()) ||\n (!defined(this.material) && this.translucent)\n );\n};\n\n/**\n * Creates a render state. This is not the final render state instance; instead,\n * it can contain a subset of render state properties identical to the render state\n * created in the context.\n *\n * @returns {object} The render state.\n */\nAppearance.prototype.getRenderState = function () {\n const translucent = this.isTranslucent();\n const rs = clone(this.renderState, false);\n if (translucent) {\n rs.depthMask = false;\n rs.blending = BlendingState.ALPHA_BLEND;\n } else {\n rs.depthMask = true;\n }\n return rs;\n};\n\n/**\n * @private\n */\nAppearance.getDefaultRenderState = function (translucent, closed, existing) {\n let rs = {\n depthTest: {\n enabled: true,\n },\n };\n\n if (translucent) {\n rs.depthMask = false;\n rs.blending = BlendingState.ALPHA_BLEND;\n }\n\n if (closed) {\n rs.cull = {\n enabled: true,\n face: CullFace.BACK,\n };\n }\n\n if (defined(existing)) {\n rs = combine(existing, rs, true);\n }\n\n return rs;\n};\nexport default Appearance;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D image;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n vec4 rampColor = texture(image, vec2(materialInput.aspect / (2.0 * czm_pi), 0.5));\\n\\\n rampColor = czm_gammaCorrect(rampColor);\\n\\\n material.diffuse = rampColor.rgb;\\n\\\n material.alpha = rampColor.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D image;\\n\\\nuniform float strength;\\n\\\nuniform vec2 repeat;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n\\n\\\n vec2 centerPixel = fract(repeat * st);\\n\\\n float centerBump = texture(image, centerPixel).channel;\\n\\\n\\n\\\n float imageWidth = float(imageDimensions.x);\\n\\\n vec2 rightPixel = fract(repeat * (st + vec2(1.0 / imageWidth, 0.0)));\\n\\\n float rightBump = texture(image, rightPixel).channel;\\n\\\n\\n\\\n float imageHeight = float(imageDimensions.y);\\n\\\n vec2 leftPixel = fract(repeat * (st + vec2(0.0, 1.0 / imageHeight)));\\n\\\n float topBump = texture(image, leftPixel).channel;\\n\\\n\\n\\\n vec3 normalTangentSpace = normalize(vec3(centerBump - rightBump, centerBump - topBump, clamp(1.0 - strength, 0.1, 1.0)));\\n\\\n vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace;\\n\\\n\\n\\\n material.normal = normalEC;\\n\\\n material.diffuse = vec3(0.01);\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 lightColor;\\n\\\nuniform vec4 darkColor;\\n\\\nuniform vec2 repeat;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n\\n\\\n // From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights\\n\\\n float b = mod(floor(repeat.s * st.s) + floor(repeat.t * st.t), 2.0); // 0.0 or 1.0\\n\\\n\\n\\\n // Find the distance from the closest separator (region between two colors)\\n\\\n float scaledWidth = fract(repeat.s * st.s);\\n\\\n scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));\\n\\\n float scaledHeight = fract(repeat.t * st.t);\\n\\\n scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));\\n\\\n float value = min(scaledWidth, scaledHeight);\\n\\\n\\n\\\n vec4 currentColor = mix(lightColor, darkColor, b);\\n\\\n vec4 color = czm_antialias(lightColor, darkColor, currentColor, value, 0.03);\\n\\\n\\n\\\n color = czm_gammaCorrect(color);\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 lightColor;\\n\\\nuniform vec4 darkColor;\\n\\\nuniform vec2 repeat;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n // From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights\\n\\\n float b = smoothstep(0.3, 0.32, length(fract(repeat * materialInput.st) - 0.5)); // 0.0 or 1.0\\n\\\n\\n\\\n vec4 color = mix(lightColor, darkColor, b);\\n\\\n color = czm_gammaCorrect(color);\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D heights;\\n\\\nuniform sampler2D colors;\\n\\\n\\n\\\n// This material expects heights to be sorted from lowest to highest.\\n\\\n\\n\\\nfloat getHeight(int idx, float invTexSize)\\n\\\n{\\n\\\n vec2 uv = vec2((float(idx) + 0.5) * invTexSize, 0.5);\\n\\\n#ifdef OES_texture_float\\n\\\n return texture(heights, uv).x;\\n\\\n#else\\n\\\n return czm_unpackFloat(texture(heights, uv));\\n\\\n#endif\\n\\\n}\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n float height = materialInput.height;\\n\\\n float invTexSize = 1.0 / float(heightsDimensions.x);\\n\\\n\\n\\\n float minHeight = getHeight(0, invTexSize);\\n\\\n float maxHeight = getHeight(heightsDimensions.x - 1, invTexSize);\\n\\\n\\n\\\n // early-out when outside the height range\\n\\\n if (height < minHeight || height > maxHeight) {\\n\\\n material.diffuse = vec3(0.0);\\n\\\n material.alpha = 0.0;\\n\\\n return material;\\n\\\n }\\n\\\n\\n\\\n // Binary search to find heights above and below.\\n\\\n int idxBelow = 0;\\n\\\n int idxAbove = heightsDimensions.x;\\n\\\n float heightBelow = minHeight;\\n\\\n float heightAbove = maxHeight;\\n\\\n\\n\\\n // while loop not allowed, so use for loop with max iterations.\\n\\\n // maxIterations of 16 supports a texture size up to 65536 (2^16).\\n\\\n const int maxIterations = 16;\\n\\\n for (int i = 0; i < maxIterations; i++) {\\n\\\n if (idxBelow >= idxAbove - 1) {\\n\\\n break;\\n\\\n }\\n\\\n\\n\\\n int idxMid = (idxBelow + idxAbove) / 2;\\n\\\n float heightTex = getHeight(idxMid, invTexSize);\\n\\\n\\n\\\n if (height > heightTex) {\\n\\\n idxBelow = idxMid;\\n\\\n heightBelow = heightTex;\\n\\\n } else {\\n\\\n idxAbove = idxMid;\\n\\\n heightAbove = heightTex;\\n\\\n }\\n\\\n }\\n\\\n\\n\\\n float lerper = heightBelow == heightAbove ? 1.0 : (height - heightBelow) / (heightAbove - heightBelow);\\n\\\n vec2 colorUv = vec2(invTexSize * (float(idxBelow) + 0.5 + lerper), 0.5);\\n\\\n vec4 color = texture(colors, colorUv);\\n\\\n\\n\\\n // undo preumultiplied alpha\\n\\\n if (color.a > 0.0) \\n\\\n {\\n\\\n color.rgb /= color.a;\\n\\\n }\\n\\\n \\n\\\n color.rgb = czm_gammaCorrect(color.rgb);\\n\\\n\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform float spacing;\\n\\\nuniform float width;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n float distanceToContour = mod(materialInput.height, spacing);\\n\\\n\\n\\\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n float dxc = abs(dFdx(materialInput.height));\\n\\\n float dyc = abs(dFdy(materialInput.height));\\n\\\n float dF = max(dxc, dyc) * czm_pixelRatio * width;\\n\\\n float alpha = (distanceToContour < dF) ? 1.0 : 0.0;\\n\\\n#else\\n\\\n // If no derivatives available (IE 10?), use pixel ratio\\n\\\n float alpha = (distanceToContour < (czm_pixelRatio * width)) ? 1.0 : 0.0;\\n\\\n#endif\\n\\\n\\n\\\n vec4 outColor = czm_gammaCorrect(vec4(color.rgb, alpha * color.a));\\n\\\n material.diffuse = outColor.rgb;\\n\\\n material.alpha = outColor.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D image;\\n\\\nuniform float minimumHeight;\\n\\\nuniform float maximumHeight;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n float scaledHeight = clamp((materialInput.height - minimumHeight) / (maximumHeight - minimumHeight), 0.0, 1.0);\\n\\\n vec4 rampColor = texture(image, vec2(scaledHeight, 0.5));\\n\\\n rampColor = czm_gammaCorrect(rampColor);\\n\\\n material.diffuse = rampColor.rgb;\\n\\\n material.alpha = rampColor.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 fadeInColor;\\n\\\nuniform vec4 fadeOutColor;\\n\\\nuniform float maximumDistance;\\n\\\nuniform bool repeat;\\n\\\nuniform vec2 fadeDirection;\\n\\\nuniform vec2 time;\\n\\\n\\n\\\nfloat getTime(float t, float coord)\\n\\\n{\\n\\\n float scalar = 1.0 / maximumDistance;\\n\\\n float q = distance(t, coord) * scalar;\\n\\\n if (repeat)\\n\\\n {\\n\\\n float r = distance(t, coord + 1.0) * scalar;\\n\\\n float s = distance(t, coord - 1.0) * scalar;\\n\\\n q = min(min(r, s), q);\\n\\\n }\\n\\\n return clamp(q, 0.0, 1.0);\\n\\\n}\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n float s = getTime(time.x, st.s) * fadeDirection.s;\\n\\\n float t = getTime(time.y, st.t) * fadeDirection.t;\\n\\\n\\n\\\n float u = length(vec2(s, t));\\n\\\n vec4 color = mix(fadeInColor, fadeOutColor, u);\\n\\\n\\n\\\n color = czm_gammaCorrect(color);\\n\\\n material.emission = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform float cellAlpha;\\n\\\nuniform vec2 lineCount;\\n\\\nuniform vec2 lineThickness;\\n\\\nuniform vec2 lineOffset;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n\\n\\\n float scaledWidth = fract(lineCount.s * st.s - lineOffset.s);\\n\\\n scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));\\n\\\n float scaledHeight = fract(lineCount.t * st.t - lineOffset.t);\\n\\\n scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));\\n\\\n\\n\\\n float value;\\n\\\n\\n\\\n // Fuzz Factor - Controls blurriness of lines\\n\\\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n const float fuzz = 1.2;\\n\\\n vec2 thickness = (lineThickness * czm_pixelRatio) - 1.0;\\n\\\n\\n\\\n // From \\\"3D Engine Design for Virtual Globes\\\" by Cozzi and Ring, Listing 4.13.\\n\\\n vec2 dx = abs(dFdx(st));\\n\\\n vec2 dy = abs(dFdy(st));\\n\\\n vec2 dF = vec2(max(dx.s, dy.s), max(dx.t, dy.t)) * lineCount;\\n\\\n value = min(\\n\\\n smoothstep(dF.s * thickness.s, dF.s * (fuzz + thickness.s), scaledWidth),\\n\\\n smoothstep(dF.t * thickness.t, dF.t * (fuzz + thickness.t), scaledHeight));\\n\\\n#else\\n\\\n // If no derivatives available (IE 10?), revert to view-dependent fuzz\\n\\\n const float fuzz = 0.05;\\n\\\n\\n\\\n vec2 range = 0.5 - (lineThickness * 0.05);\\n\\\n value = min(\\n\\\n 1.0 - smoothstep(range.s, range.s + fuzz, scaledWidth),\\n\\\n 1.0 - smoothstep(range.t, range.t + fuzz, scaledHeight));\\n\\\n#endif\\n\\\n\\n\\\n // Edges taken from RimLightingMaterial.glsl\\n\\\n // See http://www.fundza.com/rman_shaders/surface/fake_rim/fake_rim1.html\\n\\\n float dRim = 1.0 - abs(dot(materialInput.normalEC, normalize(materialInput.positionToEyeEC)));\\n\\\n float sRim = smoothstep(0.8, 1.0, dRim);\\n\\\n value *= (1.0 - sRim);\\n\\\n\\n\\\n vec4 halfColor;\\n\\\n halfColor.rgb = color.rgb * 0.5;\\n\\\n halfColor.a = color.a * (1.0 - ((1.0 - cellAlpha) * value));\\n\\\n halfColor = czm_gammaCorrect(halfColor);\\n\\\n material.diffuse = halfColor.rgb;\\n\\\n material.emission = halfColor.rgb;\\n\\\n material.alpha = halfColor.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D image;\\n\\\nuniform float strength;\\n\\\nuniform vec2 repeat;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n \\n\\\n vec4 textureValue = texture(image, fract(repeat * materialInput.st));\\n\\\n vec3 normalTangentSpace = textureValue.channels;\\n\\\n normalTangentSpace.xy = normalTangentSpace.xy * 2.0 - 1.0;\\n\\\n normalTangentSpace.z = clamp(1.0 - strength, 0.1, 1.0);\\n\\\n normalTangentSpace = normalize(normalTangentSpace);\\n\\\n vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace;\\n\\\n \\n\\\n material.normal = normalEC;\\n\\\n \\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\n\\n\\\nfloat getPointOnLine(vec2 p0, vec2 p1, float x)\\n\\\n{\\n\\\n float slope = (p0.y - p1.y) / (p0.x - p1.x);\\n\\\n return slope * (x - p0.x) + p0.y;\\n\\\n}\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n\\n\\\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n float base = 1.0 - abs(fwidth(st.s)) * 10.0 * czm_pixelRatio;\\n\\\n#else\\n\\\n // If no derivatives available (IE 10?), 2.5% of the line will be the arrow head\\n\\\n float base = 0.975;\\n\\\n#endif\\n\\\n\\n\\\n vec2 center = vec2(1.0, 0.5);\\n\\\n float ptOnUpperLine = getPointOnLine(vec2(base, 1.0), center, st.s);\\n\\\n float ptOnLowerLine = getPointOnLine(vec2(base, 0.0), center, st.s);\\n\\\n\\n\\\n float halfWidth = 0.15;\\n\\\n float s = step(0.5 - halfWidth, st.t);\\n\\\n s *= 1.0 - step(0.5 + halfWidth, st.t);\\n\\\n s *= 1.0 - step(base, st.s);\\n\\\n\\n\\\n float t = step(base, materialInput.st.s);\\n\\\n t *= 1.0 - step(ptOnUpperLine, st.t);\\n\\\n t *= step(ptOnLowerLine, st.t);\\n\\\n\\n\\\n // Find the distance from the closest separator (region between two colors)\\n\\\n float dist;\\n\\\n if (st.s < base)\\n\\\n {\\n\\\n float d1 = abs(st.t - (0.5 - halfWidth));\\n\\\n float d2 = abs(st.t - (0.5 + halfWidth));\\n\\\n dist = min(d1, d2);\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n float d1 = czm_infinity;\\n\\\n if (st.t < 0.5 - halfWidth && st.t > 0.5 + halfWidth)\\n\\\n {\\n\\\n d1 = abs(st.s - base);\\n\\\n }\\n\\\n float d2 = abs(st.t - ptOnUpperLine);\\n\\\n float d3 = abs(st.t - ptOnLowerLine);\\n\\\n dist = min(min(d1, d2), d3);\\n\\\n }\\n\\\n\\n\\\n vec4 outsideColor = vec4(0.0);\\n\\\n vec4 currentColor = mix(outsideColor, color, clamp(s + t, 0.0, 1.0));\\n\\\n vec4 outColor = czm_antialias(outsideColor, color, currentColor, dist);\\n\\\n\\n\\\n outColor = czm_gammaCorrect(outColor);\\n\\\n material.diffuse = outColor.rgb;\\n\\\n material.alpha = outColor.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform vec4 gapColor;\\n\\\nuniform float dashLength;\\n\\\nuniform float dashPattern;\\n\\\nin float v_polylineAngle;\\n\\\n\\n\\\nconst float maskLength = 16.0;\\n\\\n\\n\\\nmat2 rotate(float rad) {\\n\\\n float c = cos(rad);\\n\\\n float s = sin(rad);\\n\\\n return mat2(\\n\\\n c, s,\\n\\\n -s, c\\n\\\n );\\n\\\n}\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 pos = rotate(v_polylineAngle) * gl_FragCoord.xy;\\n\\\n\\n\\\n // Get the relative position within the dash from 0 to 1\\n\\\n float dashPosition = fract(pos.x / (dashLength * czm_pixelRatio));\\n\\\n // Figure out the mask index.\\n\\\n float maskIndex = floor(dashPosition * maskLength);\\n\\\n // Test the bit mask.\\n\\\n float maskTest = floor(dashPattern / pow(2.0, maskIndex));\\n\\\n vec4 fragColor = (mod(maskTest, 2.0) < 1.0) ? gapColor : color;\\n\\\n if (fragColor.a < 0.005) { // matches 0/255 and 1/255\\n\\\n discard;\\n\\\n }\\n\\\n\\n\\\n fragColor = czm_gammaCorrect(fragColor);\\n\\\n material.emission = fragColor.rgb;\\n\\\n material.alpha = fragColor.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform float glowPower;\\n\\\nuniform float taperPower;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n float glow = glowPower / abs(st.t - 0.5) - (glowPower / 0.5);\\n\\\n\\n\\\n if (taperPower <= 0.99999) {\\n\\\n glow *= min(1.0, taperPower / (0.5 - st.s * 0.5) - (taperPower / 0.5));\\n\\\n }\\n\\\n\\n\\\n vec4 fragColor;\\n\\\n fragColor.rgb = max(vec3(glow - 1.0 + color.rgb), color.rgb);\\n\\\n fragColor.a = clamp(0.0, 1.0, glow) * color.a;\\n\\\n fragColor = czm_gammaCorrect(fragColor);\\n\\\n\\n\\\n material.emission = fragColor.rgb;\\n\\\n material.alpha = fragColor.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform vec4 outlineColor;\\n\\\nuniform float outlineWidth;\\n\\\n\\n\\\nin float v_width;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n vec2 st = materialInput.st;\\n\\\n float halfInteriorWidth = 0.5 * (v_width - outlineWidth) / v_width;\\n\\\n float b = step(0.5 - halfInteriorWidth, st.t);\\n\\\n b *= 1.0 - step(0.5 + halfInteriorWidth, st.t);\\n\\\n\\n\\\n // Find the distance from the closest separator (region between two colors)\\n\\\n float d1 = abs(st.t - (0.5 - halfInteriorWidth));\\n\\\n float d2 = abs(st.t - (0.5 + halfInteriorWidth));\\n\\\n float dist = min(d1, d2);\\n\\\n\\n\\\n vec4 currentColor = mix(outlineColor, color, b);\\n\\\n vec4 outColor = czm_antialias(outlineColor, color, currentColor, dist);\\n\\\n outColor = czm_gammaCorrect(outColor);\\n\\\n\\n\\\n material.diffuse = outColor.rgb;\\n\\\n material.alpha = outColor.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 color;\\n\\\nuniform vec4 rimColor;\\n\\\nuniform float width;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n // See http://www.fundza.com/rman_shaders/surface/fake_rim/fake_rim1.html\\n\\\n float d = 1.0 - dot(materialInput.normalEC, normalize(materialInput.positionToEyeEC));\\n\\\n float s = smoothstep(1.0 - width, 1.0, d);\\n\\\n\\n\\\n vec4 outColor = czm_gammaCorrect(color);\\n\\\n vec4 outRimColor = czm_gammaCorrect(rimColor);\\n\\\n\\n\\\n material.diffuse = outColor.rgb;\\n\\\n material.emission = outRimColor.rgb * s;\\n\\\n material.alpha = mix(outColor.a, outRimColor.a, s);\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D image;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n vec4 rampColor = texture(image, vec2(materialInput.slope / (czm_pi / 2.0), 0.5));\\n\\\n rampColor = czm_gammaCorrect(rampColor);\\n\\\n material.diffuse = rampColor.rgb;\\n\\\n material.alpha = rampColor.a;\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform vec4 evenColor;\\n\\\nuniform vec4 oddColor;\\n\\\nuniform float offset;\\n\\\nuniform float repeat;\\n\\\nuniform bool horizontal;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n // Based on the Stripes Fragment Shader in the Orange Book (11.1.2)\\n\\\n float coord = mix(materialInput.st.s, materialInput.st.t, float(horizontal));\\n\\\n float value = fract((coord - offset) * (repeat * 0.5));\\n\\\n float dist = min(value, min(abs(value - 0.5), 1.0 - value));\\n\\\n\\n\\\n vec4 currentColor = mix(evenColor, oddColor, step(0.5, value));\\n\\\n vec4 color = czm_antialias(evenColor, oddColor, currentColor, dist);\\n\\\n color = czm_gammaCorrect(color);\\n\\\n\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"// Thanks for the contribution Jonas\\n\\\n// http://29a.ch/2012/7/19/webgl-terrain-rendering-water-fog\\n\\\n\\n\\\nuniform sampler2D specularMap;\\n\\\nuniform sampler2D normalMap;\\n\\\nuniform vec4 baseWaterColor;\\n\\\nuniform vec4 blendColor;\\n\\\nuniform float frequency;\\n\\\nuniform float animationSpeed;\\n\\\nuniform float amplitude;\\n\\\nuniform float specularIntensity;\\n\\\nuniform float fadeFactor;\\n\\\n\\n\\\nczm_material czm_getMaterial(czm_materialInput materialInput)\\n\\\n{\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n\\n\\\n float time = czm_frameNumber * animationSpeed;\\n\\\n\\n\\\n // fade is a function of the distance from the fragment and the frequency of the waves\\n\\\n float fade = max(1.0, (length(materialInput.positionToEyeEC) / 10000000000.0) * frequency * fadeFactor);\\n\\\n\\n\\\n float specularMapValue = texture(specularMap, materialInput.st).r;\\n\\\n\\n\\\n // note: not using directional motion at this time, just set the angle to 0.0;\\n\\\n vec4 noise = czm_getWaterNoise(normalMap, materialInput.st * frequency, time, 0.0);\\n\\\n vec3 normalTangentSpace = noise.xyz * vec3(1.0, 1.0, (1.0 / amplitude));\\n\\\n\\n\\\n // fade out the normal perturbation as we move further from the water surface\\n\\\n normalTangentSpace.xy /= fade;\\n\\\n\\n\\\n // attempt to fade out the normal perturbation as we approach non water areas (low specular map value)\\n\\\n normalTangentSpace = mix(vec3(0.0, 0.0, 50.0), normalTangentSpace, specularMapValue);\\n\\\n\\n\\\n normalTangentSpace = normalize(normalTangentSpace);\\n\\\n\\n\\\n // get ratios for alignment of the new normal vector with a vector perpendicular to the tangent plane\\n\\\n float tsPerturbationRatio = clamp(dot(normalTangentSpace, vec3(0.0, 0.0, 1.0)), 0.0, 1.0);\\n\\\n\\n\\\n // fade out water effect as specular map value decreases\\n\\\n material.alpha = mix(blendColor.a, baseWaterColor.a, specularMapValue) * specularMapValue;\\n\\\n\\n\\\n // base color is a blend of the water and non-water color based on the value from the specular map\\n\\\n // may need a uniform blend factor to better control this\\n\\\n material.diffuse = mix(blendColor.rgb, baseWaterColor.rgb, specularMapValue);\\n\\\n\\n\\\n // diffuse highlights are based on how perturbed the normal is\\n\\\n material.diffuse += (0.1 * tsPerturbationRatio);\\n\\\n\\n\\\n material.diffuse = material.diffuse;\\n\\\n\\n\\\n material.normal = normalize(materialInput.tangentToEyeMatrix * normalTangentSpace);\\n\\\n\\n\\\n material.specular = specularIntensity;\\n\\\n material.shininess = 10.0;\\n\\\n\\n\\\n return material;\\n\\\n}\\n\\\n\";\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport clone from \"../Core/clone.js\";\nimport Color from \"../Core/Color.js\";\nimport combine from \"../Core/combine.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport loadKTX2 from \"../Core/loadKTX2.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Resource from \"../Core/Resource.js\";\nimport CubeMap from \"../Renderer/CubeMap.js\";\nimport Texture from \"../Renderer/Texture.js\";\nimport AspectRampMaterial from \"../Shaders/Materials/AspectRampMaterial.js\";\nimport BumpMapMaterial from \"../Shaders/Materials/BumpMapMaterial.js\";\nimport CheckerboardMaterial from \"../Shaders/Materials/CheckerboardMaterial.js\";\nimport DotMaterial from \"../Shaders/Materials/DotMaterial.js\";\nimport ElevationBandMaterial from \"../Shaders/Materials/ElevationBandMaterial.js\";\nimport ElevationContourMaterial from \"../Shaders/Materials/ElevationContourMaterial.js\";\nimport ElevationRampMaterial from \"../Shaders/Materials/ElevationRampMaterial.js\";\nimport FadeMaterial from \"../Shaders/Materials/FadeMaterial.js\";\nimport GridMaterial from \"../Shaders/Materials/GridMaterial.js\";\nimport NormalMapMaterial from \"../Shaders/Materials/NormalMapMaterial.js\";\nimport PolylineArrowMaterial from \"../Shaders/Materials/PolylineArrowMaterial.js\";\nimport PolylineDashMaterial from \"../Shaders/Materials/PolylineDashMaterial.js\";\nimport PolylineGlowMaterial from \"../Shaders/Materials/PolylineGlowMaterial.js\";\nimport PolylineOutlineMaterial from \"../Shaders/Materials/PolylineOutlineMaterial.js\";\nimport RimLightingMaterial from \"../Shaders/Materials/RimLightingMaterial.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport SlopeRampMaterial from \"../Shaders/Materials/SlopeRampMaterial.js\";\nimport StripeMaterial from \"../Shaders/Materials/StripeMaterial.js\";\nimport TextureMagnificationFilter from \"../Renderer/TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"../Renderer/TextureMinificationFilter.js\";\nimport WaterMaterial from \"../Shaders/Materials/Water.js\";\n\n/**\n * A Material defines surface appearance through a combination of diffuse, specular,\n * normal, emission, and alpha components. These values are specified using a\n * JSON schema called Fabric which gets parsed and assembled into glsl shader code\n * behind-the-scenes. Check out the {@link https://github.com/CesiumGS/cesium/wiki/Fabric|wiki page}\n * for more details on Fabric.\n *

\n * \n *\n * Base material types and their uniforms:\n *
\n *
    \n *
  • Color
  • \n *
      \n *
    • color: rgba color object.
    • \n *
    \n *
  • Image
  • \n *
      \n *
    • image: path to image.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    \n *
  • DiffuseMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channels: Three character string containing any combination of r, g, b, and a for selecting the desired image channels.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    \n *
  • AlphaMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channel: One character string containing r, g, b, or a for selecting the desired image channel.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    \n *
  • SpecularMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channel: One character string containing r, g, b, or a for selecting the desired image channel.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    \n *
  • EmissionMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channels: Three character string containing any combination of r, g, b, and a for selecting the desired image channels.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    \n *
  • BumpMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channel: One character string containing r, g, b, or a for selecting the desired image channel.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    • strength: Bump strength value between 0.0 and 1.0 where 0.0 is small bumps and 1.0 is large bumps.
    • \n *
    \n *
  • NormalMap
  • \n *
      \n *
    • image: path to image.
    • \n *
    • channels: Three character string containing any combination of r, g, b, and a for selecting the desired image channels.
    • \n *
    • repeat: Object with x and y values specifying the number of times to repeat the image.
    • \n *
    • strength: Bump strength value between 0.0 and 1.0 where 0.0 is small bumps and 1.0 is large bumps.
    • \n *
    \n *
  • Grid
  • \n *
      \n *
    • color: rgba color object for the whole material.
    • \n *
    • cellAlpha: Alpha value for the cells between grid lines. This will be combined with color.alpha.
    • \n *
    • lineCount: Object with x and y values specifying the number of columns and rows respectively.
    • \n *
    • lineThickness: Object with x and y values specifying the thickness of grid lines (in pixels where available).
    • \n *
    • lineOffset: Object with x and y values specifying the offset of grid lines (range is 0 to 1).
    • \n *
    \n *
  • Stripe
  • \n *
      \n *
    • horizontal: Boolean that determines if the stripes are horizontal or vertical.
    • \n *
    • evenColor: rgba color object for the stripe's first color.
    • \n *
    • oddColor: rgba color object for the stripe's second color.
    • \n *
    • offset: Number that controls at which point into the pattern to begin drawing; with 0.0 being the beginning of the even color, 1.0 the beginning of the odd color, 2.0 being the even color again, and any multiple or fractional values being in between.
    • \n *
    • repeat: Number that controls the total number of stripes, half light and half dark.
    • \n *
    \n *
  • Checkerboard
  • \n *
      \n *
    • lightColor: rgba color object for the checkerboard's light alternating color.
    • \n *
    • darkColor: rgba color object for the checkerboard's dark alternating color.
    • \n *
    • repeat: Object with x and y values specifying the number of columns and rows respectively.
    • \n *
    \n *
  • Dot
  • \n *
      \n *
    • lightColor: rgba color object for the dot color.
    • \n *
    • darkColor: rgba color object for the background color.
    • \n *
    • repeat: Object with x and y values specifying the number of columns and rows of dots respectively.
    • \n *
    \n *
  • Water
  • \n *
      \n *
    • baseWaterColor: rgba color object base color of the water.
    • \n *
    • blendColor: rgba color object used when blending from water to non-water areas.
    • \n *
    • specularMap: Single channel texture used to indicate areas of water.
    • \n *
    • normalMap: Normal map for water normal perturbation.
    • \n *
    • frequency: Number that controls the number of waves.
    • \n *
    • animationSpeed: Number that controls the animations speed of the water.
    • \n *
    • amplitude: Number that controls the amplitude of water waves.
    • \n *
    • specularIntensity: Number that controls the intensity of specular reflections.
    • \n *
    \n *
  • RimLighting
  • \n *
      \n *
    • color: diffuse color and alpha.
    • \n *
    • rimColor: diffuse color and alpha of the rim.
    • \n *
    • width: Number that determines the rim's width.
    • \n *
    \n *
  • Fade
  • \n *
      \n *
    • fadeInColor: diffuse color and alpha at time
    • \n *
    • fadeOutColor: diffuse color and alpha at maximumDistance from time
    • \n *
    • maximumDistance: Number between 0.0 and 1.0 where the fadeInColor becomes the fadeOutColor. A value of 0.0 gives the entire material a color of fadeOutColor and a value of 1.0 gives the the entire material a color of fadeInColor
    • \n *
    • repeat: true if the fade should wrap around the texture coodinates.
    • \n *
    • fadeDirection: Object with x and y values specifying if the fade should be in the x and y directions.
    • \n *
    • time: Object with x and y values between 0.0 and 1.0 of the fadeInColor position
    • \n *
    \n *
  • PolylineArrow
  • \n *
      \n *
    • color: diffuse color and alpha.
    • \n *
    \n *
  • PolylineDash
  • \n *
      \n *
    • color: color for the line.
    • \n *
    • gapColor: color for the gaps in the line.
    • \n *
    • dashLength: Dash length in pixels.
    • \n *
    • dashPattern: The 16 bit stipple pattern for the line..
    • \n *
    \n *
  • PolylineGlow
  • \n *
      \n *
    • color: color and maximum alpha for the glow on the line.
    • \n *
    • glowPower: strength of the glow, as a percentage of the total line width (less than 1.0).
    • \n *
    • taperPower: strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.
    • \n *
    \n *
  • PolylineOutline
  • \n *
      \n *
    • color: diffuse color and alpha for the interior of the line.
    • \n *
    • outlineColor: diffuse color and alpha for the outline.
    • \n *
    • outlineWidth: width of the outline in pixels.
    • \n *
    \n *
  • ElevationContour
  • \n *
      \n *
    • color: color and alpha for the contour line.
    • \n *
    • spacing: spacing for contour lines in meters.
    • \n *
    • width: Number specifying the width of the grid lines in pixels.
    • \n *
    \n *
  • ElevationRamp
  • \n *
      \n *
    • image: color ramp image to use for coloring the terrain.
    • \n *
    • minimumHeight: minimum height for the ramp.
    • \n *
    • maximumHeight: maximum height for the ramp.
    • \n *
    \n *
  • SlopeRamp
  • \n *
      \n *
    • image: color ramp image to use for coloring the terrain by slope.
    • \n *
    \n *
  • AspectRamp
  • \n *
      \n *
    • image: color ramp image to use for color the terrain by aspect.
    • \n *
    \n *
  • ElevationBand
  • \n *
      \n *
    • heights: image of heights sorted from lowest to highest.
    • \n *
    • colors: image of colors at the corresponding heights.
    • \n *
    \n *
\n * \n *
\n *\n * @alias Material\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.strict=false] Throws errors for issues that would normally be ignored, including unused uniforms or materials.\n * @param {boolean|Function} [options.translucent=true] When true or a function that returns true, the geometry\n * with this material is expected to appear translucent.\n * @param {TextureMinificationFilter} [options.minificationFilter=TextureMinificationFilter.LINEAR] The {@link TextureMinificationFilter} to apply to this material's textures.\n * @param {TextureMagnificationFilter} [options.magnificationFilter=TextureMagnificationFilter.LINEAR] The {@link TextureMagnificationFilter} to apply to this material's textures.\n * @param {object} options.fabric The fabric JSON used to generate the material.\n *ructor\n *\n * @exception {DeveloperError} fabric: uniform has invalid type.\n * @exception {DeveloperError} fabric: uniforms and materials cannot share the same property.\n * @exception {DeveloperError} fabric: cannot have source and components in the same section.\n * @exception {DeveloperError} fabric: property name is not valid. It should be 'type', 'materials', 'uniforms', 'components', or 'source'.\n * @exception {DeveloperError} fabric: property name is not valid. It should be 'diffuse', 'specular', 'shininess', 'normal', 'emission', or 'alpha'.\n * @exception {DeveloperError} strict: shader source does not use string.\n * @exception {DeveloperError} strict: shader source does not use uniform.\n * @exception {DeveloperError} strict: shader source does not use material.\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric wiki page} for a more detailed options of Fabric.\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Materials.html|Cesium Sandcastle Materials Demo}\n *\n * @example\n * // Create a color material with fromType:\n * polygon.material = Cesium.Material.fromType('Color');\n * polygon.material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);\n *\n * // Create the default material:\n * polygon.material = new Cesium.Material();\n *\n * // Create a color material with full Fabric notation:\n * polygon.material = new Cesium.Material({\n * fabric: {\n * type: 'Color',\n * uniforms: {\n * color: new Cesium.Color(1.0, 1.0, 0.0, 1.0)\n * }\n * }\n * });\n */\nfunction Material(options) {\n /**\n * The material type. Can be an existing type or a new type. If no type is specified in fabric, type is a GUID.\n * @type {string}\n * @default undefined\n */\n this.type = undefined;\n\n /**\n * The glsl shader source for this material.\n * @type {string}\n * @default undefined\n */\n this.shaderSource = undefined;\n\n /**\n * Maps sub-material names to Material objects.\n * @type {object}\n * @default undefined\n */\n this.materials = undefined;\n\n /**\n * Maps uniform names to their values.\n * @type {object}\n * @default undefined\n */\n this.uniforms = undefined;\n this._uniforms = undefined;\n\n /**\n * When true or a function that returns true,\n * the geometry is expected to appear translucent.\n * @type {boolean|Function}\n * @default undefined\n */\n this.translucent = undefined;\n\n this._minificationFilter = defaultValue(\n options.minificationFilter,\n TextureMinificationFilter.LINEAR\n );\n this._magnificationFilter = defaultValue(\n options.magnificationFilter,\n TextureMagnificationFilter.LINEAR\n );\n\n this._strict = undefined;\n this._template = undefined;\n this._count = undefined;\n\n this._texturePaths = {};\n this._loadedImages = [];\n this._loadedCubeMaps = [];\n\n this._textures = {};\n\n this._updateFunctions = [];\n\n this._defaultTexture = undefined;\n\n initializeMaterial(options, this);\n Object.defineProperties(this, {\n type: {\n value: this.type,\n writable: false,\n },\n });\n\n if (!defined(Material._uniformList[this.type])) {\n Material._uniformList[this.type] = Object.keys(this._uniforms);\n }\n}\n\n// Cached list of combined uniform names indexed by type.\n// Used to get the list of uniforms in the same order.\nMaterial._uniformList = {};\n\n/**\n * Creates a new material using an existing material type.\n *

\n * Shorthand for: new Material({fabric : {type : type}});\n *\n * @param {string} type The base material type.\n * @param {object} [uniforms] Overrides for the default uniforms.\n * @returns {Material} New material object.\n *\n * @exception {DeveloperError} material with that type does not exist.\n *\n * @example\n * const material = Cesium.Material.fromType('Color', {\n * color: new Cesium.Color(1.0, 0.0, 0.0, 1.0)\n * });\n */\nMaterial.fromType = function (type, uniforms) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(Material._materialCache.getMaterial(type))) {\n throw new DeveloperError(`material with type '${type}' does not exist.`);\n }\n //>>includeEnd('debug');\n\n const material = new Material({\n fabric: {\n type: type,\n },\n });\n\n if (defined(uniforms)) {\n for (const name in uniforms) {\n if (uniforms.hasOwnProperty(name)) {\n material.uniforms[name] = uniforms[name];\n }\n }\n }\n\n return material;\n};\n\n/**\n * Gets whether or not this material is translucent.\n * @returns {boolean} true if this material is translucent, false otherwise.\n */\nMaterial.prototype.isTranslucent = function () {\n if (defined(this.translucent)) {\n if (typeof this.translucent === \"function\") {\n return this.translucent();\n }\n\n return this.translucent;\n }\n\n let translucent = true;\n const funcs = this._translucentFunctions;\n const length = funcs.length;\n for (let i = 0; i < length; ++i) {\n const func = funcs[i];\n if (typeof func === \"function\") {\n translucent = translucent && func();\n } else {\n translucent = translucent && func;\n }\n\n if (!translucent) {\n break;\n }\n }\n return translucent;\n};\n\n/**\n * @private\n */\nMaterial.prototype.update = function (context) {\n this._defaultTexture = context.defaultTexture;\n\n let i;\n let uniformId;\n\n const loadedImages = this._loadedImages;\n let length = loadedImages.length;\n for (i = 0; i < length; ++i) {\n const loadedImage = loadedImages[i];\n uniformId = loadedImage.id;\n let image = loadedImage.image;\n\n // Images transcoded from KTX2 can contain multiple mip levels:\n // https://github.khronos.org/KTX-Specification/#_mip_level_array\n let mipLevels;\n if (Array.isArray(image)) {\n // highest detail mip should be level 0\n mipLevels = image.slice(1, image.length).map(function (mipLevel) {\n return mipLevel.bufferView;\n });\n image = image[0];\n }\n\n const sampler = new Sampler({\n minificationFilter: this._minificationFilter,\n magnificationFilter: this._magnificationFilter,\n });\n\n let texture;\n if (defined(image.internalFormat)) {\n texture = new Texture({\n context: context,\n pixelFormat: image.internalFormat,\n width: image.width,\n height: image.height,\n source: {\n arrayBufferView: image.bufferView,\n mipLevels: mipLevels,\n },\n sampler: sampler,\n });\n } else {\n texture = new Texture({\n context: context,\n source: image,\n sampler: sampler,\n });\n }\n\n // The material destroys its old texture only after the new one has been loaded.\n // This will ensure a smooth swap of textures and prevent the default texture\n // from appearing for a few frames.\n const oldTexture = this._textures[uniformId];\n if (defined(oldTexture) && oldTexture !== this._defaultTexture) {\n oldTexture.destroy();\n }\n\n this._textures[uniformId] = texture;\n\n const uniformDimensionsName = `${uniformId}Dimensions`;\n if (this.uniforms.hasOwnProperty(uniformDimensionsName)) {\n const uniformDimensions = this.uniforms[uniformDimensionsName];\n uniformDimensions.x = texture._width;\n uniformDimensions.y = texture._height;\n }\n }\n\n loadedImages.length = 0;\n\n const loadedCubeMaps = this._loadedCubeMaps;\n length = loadedCubeMaps.length;\n\n for (i = 0; i < length; ++i) {\n const loadedCubeMap = loadedCubeMaps[i];\n uniformId = loadedCubeMap.id;\n const images = loadedCubeMap.images;\n\n const cubeMap = new CubeMap({\n context: context,\n source: {\n positiveX: images[0],\n negativeX: images[1],\n positiveY: images[2],\n negativeY: images[3],\n positiveZ: images[4],\n negativeZ: images[5],\n },\n sampler: new Sampler({\n minificationFilter: this._minificationFilter,\n magnificationFilter: this._magnificationFilter,\n }),\n });\n\n this._textures[uniformId] = cubeMap;\n }\n\n loadedCubeMaps.length = 0;\n\n const updateFunctions = this._updateFunctions;\n length = updateFunctions.length;\n for (i = 0; i < length; ++i) {\n updateFunctions[i](this, context);\n }\n\n const subMaterials = this.materials;\n for (const name in subMaterials) {\n if (subMaterials.hasOwnProperty(name)) {\n subMaterials[name].update(context);\n }\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see Material#destroy\n */\nMaterial.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * material = material && material.destroy();\n *\n * @see Material#isDestroyed\n */\nMaterial.prototype.destroy = function () {\n const textures = this._textures;\n for (const texture in textures) {\n if (textures.hasOwnProperty(texture)) {\n const instance = textures[texture];\n if (instance !== this._defaultTexture) {\n instance.destroy();\n }\n }\n }\n\n const materials = this.materials;\n for (const material in materials) {\n if (materials.hasOwnProperty(material)) {\n materials[material].destroy();\n }\n }\n return destroyObject(this);\n};\n\nfunction initializeMaterial(options, result) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n result._strict = defaultValue(options.strict, false);\n result._count = defaultValue(options.count, 0);\n result._template = clone(\n defaultValue(options.fabric, defaultValue.EMPTY_OBJECT)\n );\n result._template.uniforms = clone(\n defaultValue(result._template.uniforms, defaultValue.EMPTY_OBJECT)\n );\n result._template.materials = clone(\n defaultValue(result._template.materials, defaultValue.EMPTY_OBJECT)\n );\n\n result.type = defined(result._template.type)\n ? result._template.type\n : createGuid();\n\n result.shaderSource = \"\";\n result.materials = {};\n result.uniforms = {};\n result._uniforms = {};\n result._translucentFunctions = [];\n\n let translucent;\n\n // If the cache contains this material type, build the material template off of the stored template.\n const cachedMaterial = Material._materialCache.getMaterial(result.type);\n if (defined(cachedMaterial)) {\n const template = clone(cachedMaterial.fabric, true);\n result._template = combine(result._template, template, true);\n translucent = cachedMaterial.translucent;\n }\n\n // Make sure the template has no obvious errors. More error checking happens later.\n checkForTemplateErrors(result);\n\n // If the material has a new type, add it to the cache.\n if (!defined(cachedMaterial)) {\n Material._materialCache.addMaterial(result.type, result);\n }\n\n createMethodDefinition(result);\n createUniforms(result);\n createSubMaterials(result);\n\n const defaultTranslucent =\n result._translucentFunctions.length === 0 ? true : undefined;\n translucent = defaultValue(translucent, defaultTranslucent);\n translucent = defaultValue(options.translucent, translucent);\n\n if (defined(translucent)) {\n if (typeof translucent === \"function\") {\n const wrappedTranslucent = function () {\n return translucent(result);\n };\n result._translucentFunctions.push(wrappedTranslucent);\n } else {\n result._translucentFunctions.push(translucent);\n }\n }\n}\n\nfunction checkForValidProperties(object, properties, result, throwNotFound) {\n if (defined(object)) {\n for (const property in object) {\n if (object.hasOwnProperty(property)) {\n const hasProperty = properties.indexOf(property) !== -1;\n if (\n (throwNotFound && !hasProperty) ||\n (!throwNotFound && hasProperty)\n ) {\n result(property, properties);\n }\n }\n }\n }\n}\n\nfunction invalidNameError(property, properties) {\n //>>includeStart('debug', pragmas.debug);\n let errorString = `fabric: property name '${property}' is not valid. It should be `;\n for (let i = 0; i < properties.length; i++) {\n const propertyName = `'${properties[i]}'`;\n errorString +=\n i === properties.length - 1 ? `or ${propertyName}.` : `${propertyName}, `;\n }\n throw new DeveloperError(errorString);\n //>>includeEnd('debug');\n}\n\nfunction duplicateNameError(property, properties) {\n //>>includeStart('debug', pragmas.debug);\n const errorString = `fabric: uniforms and materials cannot share the same property '${property}'`;\n throw new DeveloperError(errorString);\n //>>includeEnd('debug');\n}\n\nconst templateProperties = [\n \"type\",\n \"materials\",\n \"uniforms\",\n \"components\",\n \"source\",\n];\nconst componentProperties = [\n \"diffuse\",\n \"specular\",\n \"shininess\",\n \"normal\",\n \"emission\",\n \"alpha\",\n];\n\nfunction checkForTemplateErrors(material) {\n const template = material._template;\n const uniforms = template.uniforms;\n const materials = template.materials;\n const components = template.components;\n\n // Make sure source and components do not exist in the same template.\n //>>includeStart('debug', pragmas.debug);\n if (defined(components) && defined(template.source)) {\n throw new DeveloperError(\n \"fabric: cannot have source and components in the same template.\"\n );\n }\n //>>includeEnd('debug');\n\n // Make sure all template and components properties are valid.\n checkForValidProperties(template, templateProperties, invalidNameError, true);\n checkForValidProperties(\n components,\n componentProperties,\n invalidNameError,\n true\n );\n\n // Make sure uniforms and materials do not share any of the same names.\n const materialNames = [];\n for (const property in materials) {\n if (materials.hasOwnProperty(property)) {\n materialNames.push(property);\n }\n }\n checkForValidProperties(uniforms, materialNames, duplicateNameError, false);\n}\n\nfunction isMaterialFused(shaderComponent, material) {\n const materials = material._template.materials;\n for (const subMaterialId in materials) {\n if (materials.hasOwnProperty(subMaterialId)) {\n if (shaderComponent.indexOf(subMaterialId) > -1) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// Create the czm_getMaterial method body using source or components.\nfunction createMethodDefinition(material) {\n const components = material._template.components;\n const source = material._template.source;\n if (defined(source)) {\n material.shaderSource += `${source}\\n`;\n } else {\n material.shaderSource +=\n \"czm_material czm_getMaterial(czm_materialInput materialInput)\\n{\\n\";\n material.shaderSource +=\n \"czm_material material = czm_getDefaultMaterial(materialInput);\\n\";\n if (defined(components)) {\n const isMultiMaterial =\n Object.keys(material._template.materials).length > 0;\n for (const component in components) {\n if (components.hasOwnProperty(component)) {\n if (component === \"diffuse\" || component === \"emission\") {\n const isFusion =\n isMultiMaterial &&\n isMaterialFused(components[component], material);\n const componentSource = isFusion\n ? components[component]\n : `czm_gammaCorrect(${components[component]})`;\n material.shaderSource += `material.${component} = ${componentSource}; \\n`;\n } else if (component === \"alpha\") {\n material.shaderSource += `material.alpha = ${components.alpha}; \\n`;\n } else {\n material.shaderSource += `material.${component} = ${components[component]};\\n`;\n }\n }\n }\n }\n material.shaderSource += \"return material;\\n}\\n\";\n }\n}\n\nconst matrixMap = {\n mat2: Matrix2,\n mat3: Matrix3,\n mat4: Matrix4,\n};\n\nconst ktx2Regex = /\\.ktx2$/i;\n\nfunction createTexture2DUpdateFunction(uniformId) {\n let oldUniformValue;\n return function (material, context) {\n const uniforms = material.uniforms;\n const uniformValue = uniforms[uniformId];\n const uniformChanged = oldUniformValue !== uniformValue;\n const uniformValueIsDefaultImage =\n !defined(uniformValue) || uniformValue === Material.DefaultImageId;\n oldUniformValue = uniformValue;\n\n let texture = material._textures[uniformId];\n let uniformDimensionsName;\n let uniformDimensions;\n\n if (uniformValue instanceof HTMLVideoElement) {\n // HTMLVideoElement.readyState >=2 means we have enough data for the current frame.\n // See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/readyState\n if (uniformValue.readyState >= 2) {\n if (uniformChanged && defined(texture)) {\n if (texture !== context.defaultTexture) {\n texture.destroy();\n }\n texture = undefined;\n }\n\n if (!defined(texture) || texture === context.defaultTexture) {\n const sampler = new Sampler({\n minificationFilter: material._minificationFilter,\n magnificationFilter: material._magnificationFilter,\n });\n texture = new Texture({\n context: context,\n source: uniformValue,\n sampler: sampler,\n });\n material._textures[uniformId] = texture;\n return;\n }\n\n texture.copyFrom({\n source: uniformValue,\n });\n } else if (!defined(texture)) {\n material._textures[uniformId] = context.defaultTexture;\n }\n return;\n }\n\n if (uniformValue instanceof Texture && uniformValue !== texture) {\n material._texturePaths[uniformId] = undefined;\n const tmp = material._textures[uniformId];\n if (defined(tmp) && tmp !== material._defaultTexture) {\n tmp.destroy();\n }\n material._textures[uniformId] = uniformValue;\n\n uniformDimensionsName = `${uniformId}Dimensions`;\n if (uniforms.hasOwnProperty(uniformDimensionsName)) {\n uniformDimensions = uniforms[uniformDimensionsName];\n uniformDimensions.x = uniformValue._width;\n uniformDimensions.y = uniformValue._height;\n }\n\n return;\n }\n\n if (uniformChanged && defined(texture) && uniformValueIsDefaultImage) {\n // If the newly-assigned texture is the default texture,\n // we don't need to wait for a new image to load before destroying\n // the old texture.\n if (texture !== material._defaultTexture) {\n texture.destroy();\n }\n texture = undefined;\n }\n\n if (!defined(texture)) {\n material._texturePaths[uniformId] = undefined;\n texture = material._textures[uniformId] = material._defaultTexture;\n\n uniformDimensionsName = `${uniformId}Dimensions`;\n if (uniforms.hasOwnProperty(uniformDimensionsName)) {\n uniformDimensions = uniforms[uniformDimensionsName];\n uniformDimensions.x = texture._width;\n uniformDimensions.y = texture._height;\n }\n }\n\n if (uniformValueIsDefaultImage) {\n return;\n }\n\n // When using the entity layer, the Resource objects get recreated on getValue because\n // they are clonable. That's why we check the url property for Resources\n // because the instances aren't the same and we keep trying to load the same\n // image if it fails to load.\n const isResource = uniformValue instanceof Resource;\n if (\n !defined(material._texturePaths[uniformId]) ||\n (isResource &&\n uniformValue.url !== material._texturePaths[uniformId].url) ||\n (!isResource && uniformValue !== material._texturePaths[uniformId])\n ) {\n if (typeof uniformValue === \"string\" || isResource) {\n const resource = isResource\n ? uniformValue\n : Resource.createIfNeeded(uniformValue);\n\n let promise;\n if (ktx2Regex.test(resource.url)) {\n promise = loadKTX2(resource.url);\n } else {\n promise = resource.fetchImage();\n }\n\n Promise.resolve(promise)\n .then(function (image) {\n material._loadedImages.push({\n id: uniformId,\n image: image,\n });\n })\n .catch(function () {\n if (defined(texture) && texture !== material._defaultTexture) {\n texture.destroy();\n }\n material._textures[uniformId] = material._defaultTexture;\n });\n } else if (\n uniformValue instanceof HTMLCanvasElement ||\n uniformValue instanceof HTMLImageElement\n ) {\n material._loadedImages.push({\n id: uniformId,\n image: uniformValue,\n });\n }\n\n material._texturePaths[uniformId] = uniformValue;\n }\n };\n}\n\nfunction createCubeMapUpdateFunction(uniformId) {\n return function (material, context) {\n const uniformValue = material.uniforms[uniformId];\n\n if (uniformValue instanceof CubeMap) {\n const tmp = material._textures[uniformId];\n if (tmp !== material._defaultTexture) {\n tmp.destroy();\n }\n material._texturePaths[uniformId] = undefined;\n material._textures[uniformId] = uniformValue;\n return;\n }\n\n if (!defined(material._textures[uniformId])) {\n material._texturePaths[uniformId] = undefined;\n material._textures[uniformId] = context.defaultCubeMap;\n }\n\n if (uniformValue === Material.DefaultCubeMapId) {\n return;\n }\n\n const path =\n uniformValue.positiveX +\n uniformValue.negativeX +\n uniformValue.positiveY +\n uniformValue.negativeY +\n uniformValue.positiveZ +\n uniformValue.negativeZ;\n\n if (path !== material._texturePaths[uniformId]) {\n const promises = [\n Resource.createIfNeeded(uniformValue.positiveX).fetchImage(),\n Resource.createIfNeeded(uniformValue.negativeX).fetchImage(),\n Resource.createIfNeeded(uniformValue.positiveY).fetchImage(),\n Resource.createIfNeeded(uniformValue.negativeY).fetchImage(),\n Resource.createIfNeeded(uniformValue.positiveZ).fetchImage(),\n Resource.createIfNeeded(uniformValue.negativeZ).fetchImage(),\n ];\n\n Promise.all(promises).then(function (images) {\n material._loadedCubeMaps.push({\n id: uniformId,\n images: images,\n });\n });\n\n material._texturePaths[uniformId] = path;\n }\n };\n}\n\nfunction createUniforms(material) {\n const uniforms = material._template.uniforms;\n for (const uniformId in uniforms) {\n if (uniforms.hasOwnProperty(uniformId)) {\n createUniform(material, uniformId);\n }\n }\n}\n\n// Writes uniform declarations to the shader file and connects uniform values with\n// corresponding material properties through the returnUniforms function.\nfunction createUniform(material, uniformId) {\n const strict = material._strict;\n const materialUniforms = material._template.uniforms;\n const uniformValue = materialUniforms[uniformId];\n const uniformType = getUniformType(uniformValue);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(uniformType)) {\n throw new DeveloperError(\n `fabric: uniform '${uniformId}' has invalid type.`\n );\n }\n //>>includeEnd('debug');\n\n let replacedTokenCount;\n if (uniformType === \"channels\") {\n replacedTokenCount = replaceToken(material, uniformId, uniformValue, false);\n //>>includeStart('debug', pragmas.debug);\n if (replacedTokenCount === 0 && strict) {\n throw new DeveloperError(\n `strict: shader source does not use channels '${uniformId}'.`\n );\n }\n //>>includeEnd('debug');\n } else {\n // Since webgl doesn't allow texture dimension queries in glsl, create a uniform to do it.\n // Check if the shader source actually uses texture dimensions before creating the uniform.\n if (uniformType === \"sampler2D\") {\n const imageDimensionsUniformName = `${uniformId}Dimensions`;\n if (getNumberOfTokens(material, imageDimensionsUniformName) > 0) {\n materialUniforms[imageDimensionsUniformName] = {\n type: \"ivec3\",\n x: 1,\n y: 1,\n };\n createUniform(material, imageDimensionsUniformName);\n }\n }\n\n // Add uniform declaration to source code.\n const uniformDeclarationRegex = new RegExp(\n `uniform\\\\s+${uniformType}\\\\s+${uniformId}\\\\s*;`\n );\n if (!uniformDeclarationRegex.test(material.shaderSource)) {\n const uniformDeclaration = `uniform ${uniformType} ${uniformId};`;\n material.shaderSource = uniformDeclaration + material.shaderSource;\n }\n\n const newUniformId = `${uniformId}_${material._count++}`;\n replacedTokenCount = replaceToken(material, uniformId, newUniformId);\n //>>includeStart('debug', pragmas.debug);\n if (replacedTokenCount === 1 && strict) {\n throw new DeveloperError(\n `strict: shader source does not use uniform '${uniformId}'.`\n );\n }\n //>>includeEnd('debug');\n\n // Set uniform value\n material.uniforms[uniformId] = uniformValue;\n\n if (uniformType === \"sampler2D\") {\n material._uniforms[newUniformId] = function () {\n return material._textures[uniformId];\n };\n material._updateFunctions.push(createTexture2DUpdateFunction(uniformId));\n } else if (uniformType === \"samplerCube\") {\n material._uniforms[newUniformId] = function () {\n return material._textures[uniformId];\n };\n material._updateFunctions.push(createCubeMapUpdateFunction(uniformId));\n } else if (uniformType.indexOf(\"mat\") !== -1) {\n const scratchMatrix = new matrixMap[uniformType]();\n material._uniforms[newUniformId] = function () {\n return matrixMap[uniformType].fromColumnMajorArray(\n material.uniforms[uniformId],\n scratchMatrix\n );\n };\n } else {\n material._uniforms[newUniformId] = function () {\n return material.uniforms[uniformId];\n };\n }\n }\n}\n\n// Determines the uniform type based on the uniform in the template.\nfunction getUniformType(uniformValue) {\n let uniformType = uniformValue.type;\n if (!defined(uniformType)) {\n const type = typeof uniformValue;\n if (type === \"number\") {\n uniformType = \"float\";\n } else if (type === \"boolean\") {\n uniformType = \"bool\";\n } else if (\n type === \"string\" ||\n uniformValue instanceof Resource ||\n uniformValue instanceof HTMLCanvasElement ||\n uniformValue instanceof HTMLImageElement\n ) {\n if (/^([rgba]){1,4}$/i.test(uniformValue)) {\n uniformType = \"channels\";\n } else if (uniformValue === Material.DefaultCubeMapId) {\n uniformType = \"samplerCube\";\n } else {\n uniformType = \"sampler2D\";\n }\n } else if (type === \"object\") {\n if (Array.isArray(uniformValue)) {\n if (\n uniformValue.length === 4 ||\n uniformValue.length === 9 ||\n uniformValue.length === 16\n ) {\n uniformType = `mat${Math.sqrt(uniformValue.length)}`;\n }\n } else {\n let numAttributes = 0;\n for (const attribute in uniformValue) {\n if (uniformValue.hasOwnProperty(attribute)) {\n numAttributes += 1;\n }\n }\n if (numAttributes >= 2 && numAttributes <= 4) {\n uniformType = `vec${numAttributes}`;\n } else if (numAttributes === 6) {\n uniformType = \"samplerCube\";\n }\n }\n }\n }\n return uniformType;\n}\n\n// Create all sub-materials by combining source and uniforms together.\nfunction createSubMaterials(material) {\n const strict = material._strict;\n const subMaterialTemplates = material._template.materials;\n for (const subMaterialId in subMaterialTemplates) {\n if (subMaterialTemplates.hasOwnProperty(subMaterialId)) {\n // Construct the sub-material.\n const subMaterial = new Material({\n strict: strict,\n fabric: subMaterialTemplates[subMaterialId],\n count: material._count,\n });\n\n material._count = subMaterial._count;\n material._uniforms = combine(\n material._uniforms,\n subMaterial._uniforms,\n true\n );\n material.materials[subMaterialId] = subMaterial;\n material._translucentFunctions = material._translucentFunctions.concat(\n subMaterial._translucentFunctions\n );\n\n // Make the material's czm_getMaterial unique by appending the sub-material type.\n const originalMethodName = \"czm_getMaterial\";\n const newMethodName = `${originalMethodName}_${material._count++}`;\n replaceToken(subMaterial, originalMethodName, newMethodName);\n material.shaderSource = subMaterial.shaderSource + material.shaderSource;\n\n // Replace each material id with an czm_getMaterial method call.\n const materialMethodCall = `${newMethodName}(materialInput)`;\n const tokensReplacedCount = replaceToken(\n material,\n subMaterialId,\n materialMethodCall\n );\n //>>includeStart('debug', pragmas.debug);\n if (tokensReplacedCount === 0 && strict) {\n throw new DeveloperError(\n `strict: shader source does not use material '${subMaterialId}'.`\n );\n }\n //>>includeEnd('debug');\n }\n }\n}\n\n// Used for searching or replacing a token in a material's shader source with something else.\n// If excludePeriod is true, do not accept tokens that are preceded by periods.\n// http://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent\nfunction replaceToken(material, token, newToken, excludePeriod) {\n excludePeriod = defaultValue(excludePeriod, true);\n let count = 0;\n const suffixChars = \"([\\\\w])?\";\n const prefixChars = `([\\\\w${excludePeriod ? \".\" : \"\"}])?`;\n const regExp = new RegExp(prefixChars + token + suffixChars, \"g\");\n material.shaderSource = material.shaderSource.replace(regExp, function (\n $0,\n $1,\n $2\n ) {\n if ($1 || $2) {\n return $0;\n }\n count += 1;\n return newToken;\n });\n return count;\n}\n\nfunction getNumberOfTokens(material, token, excludePeriod) {\n return replaceToken(material, token, token, excludePeriod);\n}\n\nMaterial._materialCache = {\n _materials: {},\n addMaterial: function (type, materialTemplate) {\n this._materials[type] = materialTemplate;\n },\n getMaterial: function (type) {\n return this._materials[type];\n },\n};\n\n/**\n * Gets or sets the default texture uniform value.\n * @type {string}\n */\nMaterial.DefaultImageId = \"czm_defaultImage\";\n\n/**\n * Gets or sets the default cube map texture uniform value.\n * @type {string}\n */\nMaterial.DefaultCubeMapId = \"czm_defaultCubeMap\";\n\n/**\n * Gets the name of the color material.\n * @type {string}\n * @readonly\n */\nMaterial.ColorType = \"Color\";\nMaterial._materialCache.addMaterial(Material.ColorType, {\n fabric: {\n type: Material.ColorType,\n uniforms: {\n color: new Color(1.0, 0.0, 0.0, 0.5),\n },\n components: {\n diffuse: \"color.rgb\",\n alpha: \"color.a\",\n },\n },\n translucent: function (material) {\n return material.uniforms.color.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the image material.\n * @type {string}\n * @readonly\n */\nMaterial.ImageType = \"Image\";\nMaterial._materialCache.addMaterial(Material.ImageType, {\n fabric: {\n type: Material.ImageType,\n uniforms: {\n image: Material.DefaultImageId,\n repeat: new Cartesian2(1.0, 1.0),\n color: new Color(1.0, 1.0, 1.0, 1.0),\n },\n components: {\n diffuse:\n \"texture(image, fract(repeat * materialInput.st)).rgb * color.rgb\",\n alpha: \"texture(image, fract(repeat * materialInput.st)).a * color.a\",\n },\n },\n translucent: function (material) {\n return material.uniforms.color.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the diffuce map material.\n * @type {string}\n * @readonly\n */\nMaterial.DiffuseMapType = \"DiffuseMap\";\nMaterial._materialCache.addMaterial(Material.DiffuseMapType, {\n fabric: {\n type: Material.DiffuseMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channels: \"rgb\",\n repeat: new Cartesian2(1.0, 1.0),\n },\n components: {\n diffuse: \"texture(image, fract(repeat * materialInput.st)).channels\",\n },\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the alpha map material.\n * @type {string}\n * @readonly\n */\nMaterial.AlphaMapType = \"AlphaMap\";\nMaterial._materialCache.addMaterial(Material.AlphaMapType, {\n fabric: {\n type: Material.AlphaMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channel: \"a\",\n repeat: new Cartesian2(1.0, 1.0),\n },\n components: {\n alpha: \"texture(image, fract(repeat * materialInput.st)).channel\",\n },\n },\n translucent: true,\n});\n\n/**\n * Gets the name of the specular map material.\n * @type {string}\n * @readonly\n */\nMaterial.SpecularMapType = \"SpecularMap\";\nMaterial._materialCache.addMaterial(Material.SpecularMapType, {\n fabric: {\n type: Material.SpecularMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channel: \"r\",\n repeat: new Cartesian2(1.0, 1.0),\n },\n components: {\n specular: \"texture(image, fract(repeat * materialInput.st)).channel\",\n },\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the emmision map material.\n * @type {string}\n * @readonly\n */\nMaterial.EmissionMapType = \"EmissionMap\";\nMaterial._materialCache.addMaterial(Material.EmissionMapType, {\n fabric: {\n type: Material.EmissionMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channels: \"rgb\",\n repeat: new Cartesian2(1.0, 1.0),\n },\n components: {\n emission: \"texture(image, fract(repeat * materialInput.st)).channels\",\n },\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the bump map material.\n * @type {string}\n * @readonly\n */\nMaterial.BumpMapType = \"BumpMap\";\nMaterial._materialCache.addMaterial(Material.BumpMapType, {\n fabric: {\n type: Material.BumpMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channel: \"r\",\n strength: 0.8,\n repeat: new Cartesian2(1.0, 1.0),\n },\n source: BumpMapMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the normal map material.\n * @type {string}\n * @readonly\n */\nMaterial.NormalMapType = \"NormalMap\";\nMaterial._materialCache.addMaterial(Material.NormalMapType, {\n fabric: {\n type: Material.NormalMapType,\n uniforms: {\n image: Material.DefaultImageId,\n channels: \"rgb\",\n strength: 0.8,\n repeat: new Cartesian2(1.0, 1.0),\n },\n source: NormalMapMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the grid material.\n * @type {string}\n * @readonly\n */\nMaterial.GridType = \"Grid\";\nMaterial._materialCache.addMaterial(Material.GridType, {\n fabric: {\n type: Material.GridType,\n uniforms: {\n color: new Color(0.0, 1.0, 0.0, 1.0),\n cellAlpha: 0.1,\n lineCount: new Cartesian2(8.0, 8.0),\n lineThickness: new Cartesian2(1.0, 1.0),\n lineOffset: new Cartesian2(0.0, 0.0),\n },\n source: GridMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.color.alpha < 1.0 || uniforms.cellAlpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the stripe material.\n * @type {string}\n * @readonly\n */\nMaterial.StripeType = \"Stripe\";\nMaterial._materialCache.addMaterial(Material.StripeType, {\n fabric: {\n type: Material.StripeType,\n uniforms: {\n horizontal: true,\n evenColor: new Color(1.0, 1.0, 1.0, 0.5),\n oddColor: new Color(0.0, 0.0, 1.0, 0.5),\n offset: 0.0,\n repeat: 5.0,\n },\n source: StripeMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.evenColor.alpha < 1.0 || uniforms.oddColor.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the checkerboard material.\n * @type {string}\n * @readonly\n */\nMaterial.CheckerboardType = \"Checkerboard\";\nMaterial._materialCache.addMaterial(Material.CheckerboardType, {\n fabric: {\n type: Material.CheckerboardType,\n uniforms: {\n lightColor: new Color(1.0, 1.0, 1.0, 0.5),\n darkColor: new Color(0.0, 0.0, 0.0, 0.5),\n repeat: new Cartesian2(5.0, 5.0),\n },\n source: CheckerboardMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.lightColor.alpha < 1.0 || uniforms.darkColor.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the dot material.\n * @type {string}\n * @readonly\n */\nMaterial.DotType = \"Dot\";\nMaterial._materialCache.addMaterial(Material.DotType, {\n fabric: {\n type: Material.DotType,\n uniforms: {\n lightColor: new Color(1.0, 1.0, 0.0, 0.75),\n darkColor: new Color(0.0, 1.0, 1.0, 0.75),\n repeat: new Cartesian2(5.0, 5.0),\n },\n source: DotMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.lightColor.alpha < 1.0 || uniforms.darkColor.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the water material.\n * @type {string}\n * @readonly\n */\nMaterial.WaterType = \"Water\";\nMaterial._materialCache.addMaterial(Material.WaterType, {\n fabric: {\n type: Material.WaterType,\n uniforms: {\n baseWaterColor: new Color(0.2, 0.3, 0.6, 1.0),\n blendColor: new Color(0.0, 1.0, 0.699, 1.0),\n specularMap: Material.DefaultImageId,\n normalMap: Material.DefaultImageId,\n frequency: 10.0,\n animationSpeed: 0.01,\n amplitude: 1.0,\n specularIntensity: 0.5,\n fadeFactor: 1.0,\n },\n source: WaterMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return (\n uniforms.baseWaterColor.alpha < 1.0 || uniforms.blendColor.alpha < 1.0\n );\n },\n});\n\n/**\n * Gets the name of the rim lighting material.\n * @type {string}\n * @readonly\n */\nMaterial.RimLightingType = \"RimLighting\";\nMaterial._materialCache.addMaterial(Material.RimLightingType, {\n fabric: {\n type: Material.RimLightingType,\n uniforms: {\n color: new Color(1.0, 0.0, 0.0, 0.7),\n rimColor: new Color(1.0, 1.0, 1.0, 0.4),\n width: 0.3,\n },\n source: RimLightingMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.color.alpha < 1.0 || uniforms.rimColor.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the fade material.\n * @type {string}\n * @readonly\n */\nMaterial.FadeType = \"Fade\";\nMaterial._materialCache.addMaterial(Material.FadeType, {\n fabric: {\n type: Material.FadeType,\n uniforms: {\n fadeInColor: new Color(1.0, 0.0, 0.0, 1.0),\n fadeOutColor: new Color(0.0, 0.0, 0.0, 0.0),\n maximumDistance: 0.5,\n repeat: true,\n fadeDirection: {\n x: true,\n y: true,\n },\n time: new Cartesian2(0.5, 0.5),\n },\n source: FadeMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return (\n uniforms.fadeInColor.alpha < 1.0 || uniforms.fadeOutColor.alpha < 1.0\n );\n },\n});\n\n/**\n * Gets the name of the polyline arrow material.\n * @type {string}\n * @readonly\n */\nMaterial.PolylineArrowType = \"PolylineArrow\";\nMaterial._materialCache.addMaterial(Material.PolylineArrowType, {\n fabric: {\n type: Material.PolylineArrowType,\n uniforms: {\n color: new Color(1.0, 1.0, 1.0, 1.0),\n },\n source: PolylineArrowMaterial,\n },\n translucent: true,\n});\n\n/**\n * Gets the name of the polyline glow material.\n * @type {string}\n * @readonly\n */\nMaterial.PolylineDashType = \"PolylineDash\";\nMaterial._materialCache.addMaterial(Material.PolylineDashType, {\n fabric: {\n type: Material.PolylineDashType,\n uniforms: {\n color: new Color(1.0, 0.0, 1.0, 1.0),\n gapColor: new Color(0.0, 0.0, 0.0, 0.0),\n dashLength: 16.0,\n dashPattern: 255.0,\n },\n source: PolylineDashMaterial,\n },\n translucent: true,\n});\n\n/**\n * Gets the name of the polyline glow material.\n * @type {string}\n * @readonly\n */\nMaterial.PolylineGlowType = \"PolylineGlow\";\nMaterial._materialCache.addMaterial(Material.PolylineGlowType, {\n fabric: {\n type: Material.PolylineGlowType,\n uniforms: {\n color: new Color(0.0, 0.5, 1.0, 1.0),\n glowPower: 0.25,\n taperPower: 1.0,\n },\n source: PolylineGlowMaterial,\n },\n translucent: true,\n});\n\n/**\n * Gets the name of the polyline outline material.\n * @type {string}\n * @readonly\n */\nMaterial.PolylineOutlineType = \"PolylineOutline\";\nMaterial._materialCache.addMaterial(Material.PolylineOutlineType, {\n fabric: {\n type: Material.PolylineOutlineType,\n uniforms: {\n color: new Color(1.0, 1.0, 1.0, 1.0),\n outlineColor: new Color(1.0, 0.0, 0.0, 1.0),\n outlineWidth: 1.0,\n },\n source: PolylineOutlineMaterial,\n },\n translucent: function (material) {\n const uniforms = material.uniforms;\n return uniforms.color.alpha < 1.0 || uniforms.outlineColor.alpha < 1.0;\n },\n});\n\n/**\n * Gets the name of the elevation contour material.\n * @type {string}\n * @readonly\n */\nMaterial.ElevationContourType = \"ElevationContour\";\nMaterial._materialCache.addMaterial(Material.ElevationContourType, {\n fabric: {\n type: Material.ElevationContourType,\n uniforms: {\n spacing: 100.0,\n color: new Color(1.0, 0.0, 0.0, 1.0),\n width: 1.0,\n },\n source: ElevationContourMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the elevation contour material.\n * @type {string}\n * @readonly\n */\nMaterial.ElevationRampType = \"ElevationRamp\";\nMaterial._materialCache.addMaterial(Material.ElevationRampType, {\n fabric: {\n type: Material.ElevationRampType,\n uniforms: {\n image: Material.DefaultImageId,\n minimumHeight: 0.0,\n maximumHeight: 10000.0,\n },\n source: ElevationRampMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the slope ramp material.\n * @type {string}\n * @readonly\n */\nMaterial.SlopeRampMaterialType = \"SlopeRamp\";\nMaterial._materialCache.addMaterial(Material.SlopeRampMaterialType, {\n fabric: {\n type: Material.SlopeRampMaterialType,\n uniforms: {\n image: Material.DefaultImageId,\n },\n source: SlopeRampMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the aspect ramp material.\n * @type {string}\n * @readonly\n */\nMaterial.AspectRampMaterialType = \"AspectRamp\";\nMaterial._materialCache.addMaterial(Material.AspectRampMaterialType, {\n fabric: {\n type: Material.AspectRampMaterialType,\n uniforms: {\n image: Material.DefaultImageId,\n },\n source: AspectRampMaterial,\n },\n translucent: false,\n});\n\n/**\n * Gets the name of the elevation band material.\n * @type {string}\n * @readonly\n */\nMaterial.ElevationBandType = \"ElevationBand\";\nMaterial._materialCache.addMaterial(Material.ElevationBandType, {\n fabric: {\n type: Material.ElevationBandType,\n uniforms: {\n heights: Material.DefaultImageId,\n colors: Material.DefaultImageId,\n },\n source: ElevationBandMaterial,\n },\n translucent: true,\n});\n\nexport default Material;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport VertexFormat from \"../Core/VertexFormat.js\";\nimport AllMaterialAppearanceFS from \"../Shaders/Appearances/AllMaterialAppearanceFS.js\";\nimport AllMaterialAppearanceVS from \"../Shaders/Appearances/AllMaterialAppearanceVS.js\";\nimport BasicMaterialAppearanceFS from \"../Shaders/Appearances/BasicMaterialAppearanceFS.js\";\nimport BasicMaterialAppearanceVS from \"../Shaders/Appearances/BasicMaterialAppearanceVS.js\";\nimport TexturedMaterialAppearanceFS from \"../Shaders/Appearances/TexturedMaterialAppearanceFS.js\";\nimport TexturedMaterialAppearanceVS from \"../Shaders/Appearances/TexturedMaterialAppearanceVS.js\";\nimport Appearance from \"./Appearance.js\";\nimport Material from \"./Material.js\";\n\n/**\n * An appearance for arbitrary geometry (as opposed to {@link EllipsoidSurfaceAppearance}, for example)\n * that supports shading with materials.\n *\n * @alias MaterialAppearance\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.flat=false] When true, flat shading is used in the fragment shader, which means lighting is not taking into account.\n * @param {boolean} [options.faceForward=!options.closed] When true, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like {@link WallGeometry}.\n * @param {boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so {@link MaterialAppearance#renderState} has alpha blending enabled.\n * @param {boolean} [options.closed=false] When true, the geometry is expected to be closed so {@link MaterialAppearance#renderState} has backface culling enabled.\n * @param {MaterialAppearance.MaterialSupportType} [options.materialSupport=MaterialAppearance.MaterialSupport.TEXTURED] The type of materials that will be supported.\n * @param {Material} [options.material=Material.ColorType] The material used to determine the fragment color.\n * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.\n * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.\n * @param {object} [options.renderState] Optional render state to override the default render state.\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Materials.html|Cesium Sandcastle Material Appearance Demo}\n *\n * @example\n * const primitive = new Cesium.Primitive({\n * geometryInstances : new Cesium.GeometryInstance({\n * geometry : new Cesium.WallGeometry({\n materialSupport : Cesium.MaterialAppearance.MaterialSupport.BASIC.vertexFormat,\n * // ...\n * })\n * }),\n * appearance : new Cesium.MaterialAppearance({\n * material : Cesium.Material.fromType('Color'),\n * faceForward : true\n * })\n *\n * });\n */\nfunction MaterialAppearance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const translucent = defaultValue(options.translucent, true);\n const closed = defaultValue(options.closed, false);\n const materialSupport = defaultValue(\n options.materialSupport,\n MaterialAppearance.MaterialSupport.TEXTURED\n );\n\n /**\n * The material used to determine the fragment color. Unlike other {@link MaterialAppearance}\n * properties, this is not read-only, so an appearance's material can change on the fly.\n *\n * @type Material\n *\n * @default {@link Material.ColorType}\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}\n */\n this.material = defined(options.material)\n ? options.material\n : Material.fromType(Material.ColorType);\n\n /**\n * When true, the geometry is expected to appear translucent.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.translucent = translucent;\n\n this._vertexShaderSource = defaultValue(\n options.vertexShaderSource,\n materialSupport.vertexShaderSource\n );\n this._fragmentShaderSource = defaultValue(\n options.fragmentShaderSource,\n materialSupport.fragmentShaderSource\n );\n this._renderState = Appearance.getDefaultRenderState(\n translucent,\n closed,\n options.renderState\n );\n this._closed = closed;\n\n // Non-derived members\n\n this._materialSupport = materialSupport;\n this._vertexFormat = materialSupport.vertexFormat;\n this._flat = defaultValue(options.flat, false);\n this._faceForward = defaultValue(options.faceForward, !closed);\n}\n\nObject.defineProperties(MaterialAppearance.prototype, {\n /**\n * The GLSL source code for the vertex shader.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n return this._vertexShaderSource;\n },\n },\n\n /**\n * The GLSL source code for the fragment shader. The full fragment shader\n * source is built procedurally taking into account {@link MaterialAppearance#material},\n * {@link MaterialAppearance#flat}, and {@link MaterialAppearance#faceForward}.\n * Use {@link MaterialAppearance#getFragmentShaderSource} to get the full source.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n\n /**\n * The WebGL fixed-function state to use when rendering the geometry.\n *

\n * The render state can be explicitly defined when constructing a {@link MaterialAppearance}\n * instance, or it is set implicitly via {@link MaterialAppearance#translucent}\n * and {@link MaterialAppearance#closed}.\n *

\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {object}\n * @readonly\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n },\n\n /**\n * When true, the geometry is expected to be closed so\n * {@link MaterialAppearance#renderState} has backface culling enabled.\n * If the viewer enters the geometry, it will not be visible.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n closed: {\n get: function () {\n return this._closed;\n },\n },\n\n /**\n * The type of materials supported by this instance. This impacts the required\n * {@link VertexFormat} and the complexity of the vertex and fragment shaders.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {MaterialAppearance.MaterialSupportType}\n * @readonly\n *\n * @default {@link MaterialAppearance.MaterialSupport.TEXTURED}\n */\n materialSupport: {\n get: function () {\n return this._materialSupport;\n },\n },\n\n /**\n * The {@link VertexFormat} that this appearance instance is compatible with.\n * A geometry can have more vertex attributes and still be compatible - at a\n * potential performance cost - but it can't have less.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type VertexFormat\n * @readonly\n *\n * @default {@link MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat}\n */\n vertexFormat: {\n get: function () {\n return this._vertexFormat;\n },\n },\n\n /**\n * When true, flat shading is used in the fragment shader,\n * which means lighting is not taking into account.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n flat: {\n get: function () {\n return this._flat;\n },\n },\n\n /**\n * When true, the fragment shader flips the surface normal\n * as needed to ensure that the normal faces the viewer to avoid\n * dark spots. This is useful when both sides of a geometry should be\n * shaded like {@link WallGeometry}.\n *\n * @memberof MaterialAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n faceForward: {\n get: function () {\n return this._faceForward;\n },\n },\n});\n\n/**\n * Procedurally creates the full GLSL fragment shader source. For {@link MaterialAppearance},\n * this is derived from {@link MaterialAppearance#fragmentShaderSource}, {@link MaterialAppearance#material},\n * {@link MaterialAppearance#flat}, and {@link MaterialAppearance#faceForward}.\n *\n * @function\n *\n * @returns {string} The full GLSL fragment shader source.\n */\nMaterialAppearance.prototype.getFragmentShaderSource =\n Appearance.prototype.getFragmentShaderSource;\n\n/**\n * Determines if the geometry is translucent based on {@link MaterialAppearance#translucent} and {@link Material#isTranslucent}.\n *\n * @function\n *\n * @returns {boolean} true if the appearance is translucent.\n */\nMaterialAppearance.prototype.isTranslucent = Appearance.prototype.isTranslucent;\n\n/**\n * Creates a render state. This is not the final render state instance; instead,\n * it can contain a subset of render state properties identical to the render state\n * created in the context.\n *\n * @function\n *\n * @returns {object} The render state.\n */\nMaterialAppearance.prototype.getRenderState =\n Appearance.prototype.getRenderState;\n\n/**\n * @typedef MaterialAppearance.MaterialSupportType\n * @type {object}\n * @property {VertexFormat} vertexFormat\n * @property {string} vertexShaderSource\n * @property {string} fragmentShaderSource\n */\n\n/**\n * Determines the type of {@link Material} that is supported by a\n * {@link MaterialAppearance} instance. This is a trade-off between\n * flexibility (a wide array of materials) and memory/performance\n * (required vertex format and GLSL shader complexity.\n * @namespace\n */\nMaterialAppearance.MaterialSupport = {\n /**\n * Only basic materials, which require just position and\n * normal vertex attributes, are supported.\n *\n * @type {MaterialAppearance.MaterialSupportType}\n * @constant\n */\n BASIC: Object.freeze({\n vertexFormat: VertexFormat.POSITION_AND_NORMAL,\n vertexShaderSource: BasicMaterialAppearanceVS,\n fragmentShaderSource: BasicMaterialAppearanceFS,\n }),\n /**\n * Materials with textures, which require position,\n * normal, and st vertex attributes,\n * are supported. The vast majority of materials fall into this category.\n *\n * @type {MaterialAppearance.MaterialSupportType}\n * @constant\n */\n TEXTURED: Object.freeze({\n vertexFormat: VertexFormat.POSITION_NORMAL_AND_ST,\n vertexShaderSource: TexturedMaterialAppearanceVS,\n fragmentShaderSource: TexturedMaterialAppearanceFS,\n }),\n /**\n * All materials, including those that work in tangent space, are supported.\n * This requires position, normal, st,\n * tangent, and bitangent vertex attributes.\n *\n * @type {MaterialAppearance.MaterialSupportType}\n * @constant\n */\n ALL: Object.freeze({\n vertexFormat: VertexFormat.ALL,\n vertexShaderSource: AllMaterialAppearanceVS,\n fragmentShaderSource: AllMaterialAppearanceFS,\n }),\n};\nexport default MaterialAppearance;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_positionEC;\\n\\\nin vec3 v_normalEC;\\n\\\nin vec4 v_color;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec3 positionToEyeEC = -v_positionEC;\\n\\\n\\n\\\n vec3 normalEC = normalize(v_normalEC);\\n\\\n#ifdef FACE_FORWARD\\n\\\n normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\\n\\\n#endif\\n\\\n\\n\\\n vec4 color = czm_gammaCorrect(v_color);\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n materialInput.normalEC = normalEC;\\n\\\n materialInput.positionToEyeEC = positionToEyeEC;\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n out_FragColor = czm_phong(normalize(positionToEyeEC), material, czm_lightDirectionEC);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 normal;\\n\\\nin vec4 color;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec3 v_positionEC;\\n\\\nout vec3 v_normalEC;\\n\\\nout vec4 v_color;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 p = czm_computePosition();\\n\\\n\\n\\\n v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates\\n\\\n v_normalEC = czm_normal * normal; // normal in eye coordinates\\n\\\n v_color = color;\\n\\\n\\n\\\n gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 v_color;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n out_FragColor = czm_gammaCorrect(v_color);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec4 color;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec4 v_color;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 p = czm_computePosition();\\n\\\n\\n\\\n v_color = color;\\n\\\n\\n\\\n gl_Position = czm_modelViewProjectionRelativeToEye * p;\\n\\\n}\\n\\\n\";\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport VertexFormat from \"../Core/VertexFormat.js\";\nimport PerInstanceColorAppearanceFS from \"../Shaders/Appearances/PerInstanceColorAppearanceFS.js\";\nimport PerInstanceColorAppearanceVS from \"../Shaders/Appearances/PerInstanceColorAppearanceVS.js\";\nimport PerInstanceFlatColorAppearanceFS from \"../Shaders/Appearances/PerInstanceFlatColorAppearanceFS.js\";\nimport PerInstanceFlatColorAppearanceVS from \"../Shaders/Appearances/PerInstanceFlatColorAppearanceVS.js\";\nimport Appearance from \"./Appearance.js\";\n\n/**\n * An appearance for {@link GeometryInstance} instances with color attributes.\n * This allows several geometry instances, each with a different color, to\n * be drawn with the same {@link Primitive} as shown in the second example below.\n *\n * @alias PerInstanceColorAppearance\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.flat=false] When true, flat shading is used in the fragment shader, which means lighting is not taking into account.\n * @param {boolean} [options.faceForward=!options.closed] When true, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like {@link WallGeometry}.\n * @param {boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so {@link PerInstanceColorAppearance#renderState} has alpha blending enabled.\n * @param {boolean} [options.closed=false] When true, the geometry is expected to be closed so {@link PerInstanceColorAppearance#renderState} has backface culling enabled.\n * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.\n * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.\n * @param {object} [options.renderState] Optional render state to override the default render state.\n *\n * @example\n * // A solid white line segment\n * const primitive = new Cesium.Primitive({\n * geometryInstances : new Cesium.GeometryInstance({\n * geometry : new Cesium.SimplePolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 0.0, 0.0,\n * 5.0, 0.0\n * ])\n * }),\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0))\n * }\n * }),\n * appearance : new Cesium.PerInstanceColorAppearance({\n * flat : true,\n * translucent : false\n * })\n * });\n *\n * // Two rectangles in a primitive, each with a different color\n * const instance = new Cesium.GeometryInstance({\n * geometry : new Cesium.RectangleGeometry({\n * rectangle : Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0)\n * }),\n * attributes : {\n * color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0.0, 0.0, 0.5)\n * }\n * });\n *\n * const anotherInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.RectangleGeometry({\n * rectangle : Cesium.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0)\n * }),\n * attributes : {\n * color : new Cesium.ColorGeometryInstanceAttribute(0.0, 0.0, 1.0, 0.5)\n * }\n * });\n *\n * const rectanglePrimitive = new Cesium.Primitive({\n * geometryInstances : [instance, anotherInstance],\n * appearance : new Cesium.PerInstanceColorAppearance()\n * });\n */\nfunction PerInstanceColorAppearance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const translucent = defaultValue(options.translucent, true);\n const closed = defaultValue(options.closed, false);\n const flat = defaultValue(options.flat, false);\n const vs = flat\n ? PerInstanceFlatColorAppearanceVS\n : PerInstanceColorAppearanceVS;\n const fs = flat\n ? PerInstanceFlatColorAppearanceFS\n : PerInstanceColorAppearanceFS;\n const vertexFormat = flat\n ? PerInstanceColorAppearance.FLAT_VERTEX_FORMAT\n : PerInstanceColorAppearance.VERTEX_FORMAT;\n\n /**\n * This property is part of the {@link Appearance} interface, but is not\n * used by {@link PerInstanceColorAppearance} since a fully custom fragment shader is used.\n *\n * @type Material\n *\n * @default undefined\n */\n this.material = undefined;\n\n /**\n * When true, the geometry is expected to appear translucent so\n * {@link PerInstanceColorAppearance#renderState} has alpha blending enabled.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.translucent = translucent;\n\n this._vertexShaderSource = defaultValue(options.vertexShaderSource, vs);\n this._fragmentShaderSource = defaultValue(options.fragmentShaderSource, fs);\n this._renderState = Appearance.getDefaultRenderState(\n translucent,\n closed,\n options.renderState\n );\n this._closed = closed;\n\n // Non-derived members\n\n this._vertexFormat = vertexFormat;\n this._flat = flat;\n this._faceForward = defaultValue(options.faceForward, !closed);\n}\n\nObject.defineProperties(PerInstanceColorAppearance.prototype, {\n /**\n * The GLSL source code for the vertex shader.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n return this._vertexShaderSource;\n },\n },\n\n /**\n * The GLSL source code for the fragment shader.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n\n /**\n * The WebGL fixed-function state to use when rendering the geometry.\n *

\n * The render state can be explicitly defined when constructing a {@link PerInstanceColorAppearance}\n * instance, or it is set implicitly via {@link PerInstanceColorAppearance#translucent}\n * and {@link PerInstanceColorAppearance#closed}.\n *

\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {object}\n * @readonly\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n },\n\n /**\n * When true, the geometry is expected to be closed so\n * {@link PerInstanceColorAppearance#renderState} has backface culling enabled.\n * If the viewer enters the geometry, it will not be visible.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n closed: {\n get: function () {\n return this._closed;\n },\n },\n\n /**\n * The {@link VertexFormat} that this appearance instance is compatible with.\n * A geometry can have more vertex attributes and still be compatible - at a\n * potential performance cost - but it can't have less.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type VertexFormat\n * @readonly\n */\n vertexFormat: {\n get: function () {\n return this._vertexFormat;\n },\n },\n\n /**\n * When true, flat shading is used in the fragment shader,\n * which means lighting is not taking into account.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n flat: {\n get: function () {\n return this._flat;\n },\n },\n\n /**\n * When true, the fragment shader flips the surface normal\n * as needed to ensure that the normal faces the viewer to avoid\n * dark spots. This is useful when both sides of a geometry should be\n * shaded like {@link WallGeometry}.\n *\n * @memberof PerInstanceColorAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n faceForward: {\n get: function () {\n return this._faceForward;\n },\n },\n});\n\n/**\n * The {@link VertexFormat} that all {@link PerInstanceColorAppearance} instances\n * are compatible with. This requires only position and normal\n * attributes.\n *\n * @type VertexFormat\n *\n * @constant\n */\nPerInstanceColorAppearance.VERTEX_FORMAT = VertexFormat.POSITION_AND_NORMAL;\n\n/**\n * The {@link VertexFormat} that all {@link PerInstanceColorAppearance} instances\n * are compatible with when {@link PerInstanceColorAppearance#flat} is true.\n * This requires only a position attribute.\n *\n * @type VertexFormat\n *\n * @constant\n */\nPerInstanceColorAppearance.FLAT_VERTEX_FORMAT = VertexFormat.POSITION_ONLY;\n\n/**\n * Procedurally creates the full GLSL fragment shader source. For {@link PerInstanceColorAppearance},\n * this is derived from {@link PerInstanceColorAppearance#fragmentShaderSource}, {@link PerInstanceColorAppearance#flat},\n * and {@link PerInstanceColorAppearance#faceForward}.\n *\n * @function\n *\n * @returns {string} The full GLSL fragment shader source.\n */\nPerInstanceColorAppearance.prototype.getFragmentShaderSource =\n Appearance.prototype.getFragmentShaderSource;\n\n/**\n * Determines if the geometry is translucent based on {@link PerInstanceColorAppearance#translucent}.\n *\n * @function\n *\n * @returns {boolean} true if the appearance is translucent.\n */\nPerInstanceColorAppearance.prototype.isTranslucent =\n Appearance.prototype.isTranslucent;\n\n/**\n * Creates a render state. This is not the final render state instance; instead,\n * it can contain a subset of render state properties identical to the render state\n * created in the context.\n *\n * @function\n *\n * @returns {object} The render state.\n */\nPerInstanceColorAppearance.prototype.getRenderState =\n Appearance.prototype.getRenderState;\nexport default PerInstanceColorAppearance;\n", "import Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link MaterialProperty} that maps to solid color {@link Material} uniforms.\n *\n * @param {Property|Color} [color=Color.WHITE] The {@link Color} Property to be used.\n *\n * @alias ColorMaterialProperty\n * @constructor\n */\nfunction ColorMaterialProperty(color) {\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n\n this.color = color;\n}\n\nObject.defineProperties(ColorMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof ColorMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return Property.isConstant(this._color);\n },\n },\n\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof ColorMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the {@link Color} {@link Property}.\n * @memberof ColorMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nColorMaterialProperty.prototype.getType = function (time) {\n return \"Color\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nColorMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n Color.WHITE,\n result.color\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nColorMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof ColorMaterialProperty && //\n Property.equals(this._color, other._color))\n );\n};\nexport default ColorMaterialProperty;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport CesiumMath from \"./Math.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * A tiling scheme for geometry referenced to a simple {@link GeographicProjection} where\n * longitude and latitude are directly mapped to X and Y. This projection is commonly\n * known as geographic, equirectangular, equidistant cylindrical, or plate carr\u00E9e.\n *\n * @alias GeographicTilingScheme\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid whose surface is being tiled. Defaults to\n * the WGS84 ellipsoid.\n * @param {Rectangle} [options.rectangle=Rectangle.MAX_VALUE] The rectangle, in radians, covered by the tiling scheme.\n * @param {number} [options.numberOfLevelZeroTilesX=2] The number of tiles in the X direction at level zero of\n * the tile tree.\n * @param {number} [options.numberOfLevelZeroTilesY=1] The number of tiles in the Y direction at level zero of\n * the tile tree.\n */\nfunction GeographicTilingScheme(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n this._rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE);\n this._projection = new GeographicProjection(this._ellipsoid);\n this._numberOfLevelZeroTilesX = defaultValue(\n options.numberOfLevelZeroTilesX,\n 2\n );\n this._numberOfLevelZeroTilesY = defaultValue(\n options.numberOfLevelZeroTilesY,\n 1\n );\n}\n\nObject.defineProperties(GeographicTilingScheme.prototype, {\n /**\n * Gets the ellipsoid that is tiled by this tiling scheme.\n * @memberof GeographicTilingScheme.prototype\n * @type {Ellipsoid}\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n\n /**\n * Gets the rectangle, in radians, covered by this tiling scheme.\n * @memberof GeographicTilingScheme.prototype\n * @type {Rectangle}\n */\n rectangle: {\n get: function () {\n return this._rectangle;\n },\n },\n\n /**\n * Gets the map projection used by this tiling scheme.\n * @memberof GeographicTilingScheme.prototype\n * @type {MapProjection}\n */\n projection: {\n get: function () {\n return this._projection;\n },\n },\n});\n\n/**\n * Gets the total number of tiles in the X direction at a specified level-of-detail.\n *\n * @param {number} level The level-of-detail.\n * @returns {number} The number of tiles in the X direction at the given level.\n */\nGeographicTilingScheme.prototype.getNumberOfXTilesAtLevel = function (level) {\n return this._numberOfLevelZeroTilesX << level;\n};\n\n/**\n * Gets the total number of tiles in the Y direction at a specified level-of-detail.\n *\n * @param {number} level The level-of-detail.\n * @returns {number} The number of tiles in the Y direction at the given level.\n */\nGeographicTilingScheme.prototype.getNumberOfYTilesAtLevel = function (level) {\n return this._numberOfLevelZeroTilesY << level;\n};\n\n/**\n * Transforms a rectangle specified in geodetic radians to the native coordinate system\n * of this tiling scheme.\n *\n * @param {Rectangle} rectangle The rectangle to transform.\n * @param {Rectangle} [result] The instance to which to copy the result, or undefined if a new instance\n * should be created.\n * @returns {Rectangle} The specified 'result', or a new object containing the native rectangle if 'result'\n * is undefined.\n */\nGeographicTilingScheme.prototype.rectangleToNativeRectangle = function (\n rectangle,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n const west = CesiumMath.toDegrees(rectangle.west);\n const south = CesiumMath.toDegrees(rectangle.south);\n const east = CesiumMath.toDegrees(rectangle.east);\n const north = CesiumMath.toDegrees(rectangle.north);\n\n if (!defined(result)) {\n return new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Converts tile x, y coordinates and level to a rectangle expressed in the native coordinates\n * of the tiling scheme.\n *\n * @param {number} x The integer x coordinate of the tile.\n * @param {number} y The integer y coordinate of the tile.\n * @param {number} level The tile level-of-detail. Zero is the least detailed.\n * @param {object} [result] The instance to which to copy the result, or undefined if a new instance\n * should be created.\n * @returns {Rectangle} The specified 'result', or a new object containing the rectangle\n * if 'result' is undefined.\n */\nGeographicTilingScheme.prototype.tileXYToNativeRectangle = function (\n x,\n y,\n level,\n result\n) {\n const rectangleRadians = this.tileXYToRectangle(x, y, level, result);\n rectangleRadians.west = CesiumMath.toDegrees(rectangleRadians.west);\n rectangleRadians.south = CesiumMath.toDegrees(rectangleRadians.south);\n rectangleRadians.east = CesiumMath.toDegrees(rectangleRadians.east);\n rectangleRadians.north = CesiumMath.toDegrees(rectangleRadians.north);\n return rectangleRadians;\n};\n\n/**\n * Converts tile x, y coordinates and level to a cartographic rectangle in radians.\n *\n * @param {number} x The integer x coordinate of the tile.\n * @param {number} y The integer y coordinate of the tile.\n * @param {number} level The tile level-of-detail. Zero is the least detailed.\n * @param {object} [result] The instance to which to copy the result, or undefined if a new instance\n * should be created.\n * @returns {Rectangle} The specified 'result', or a new object containing the rectangle\n * if 'result' is undefined.\n */\nGeographicTilingScheme.prototype.tileXYToRectangle = function (\n x,\n y,\n level,\n result\n) {\n const rectangle = this._rectangle;\n\n const xTiles = this.getNumberOfXTilesAtLevel(level);\n const yTiles = this.getNumberOfYTilesAtLevel(level);\n\n const xTileWidth = rectangle.width / xTiles;\n const west = x * xTileWidth + rectangle.west;\n const east = (x + 1) * xTileWidth + rectangle.west;\n\n const yTileHeight = rectangle.height / yTiles;\n const north = rectangle.north - y * yTileHeight;\n const south = rectangle.north - (y + 1) * yTileHeight;\n\n if (!defined(result)) {\n result = new Rectangle(west, south, east, north);\n }\n\n result.west = west;\n result.south = south;\n result.east = east;\n result.north = north;\n return result;\n};\n\n/**\n * Calculates the tile x, y coordinates of the tile containing\n * a given cartographic position.\n *\n * @param {Cartographic} position The position.\n * @param {number} level The tile level-of-detail. Zero is the least detailed.\n * @param {Cartesian2} [result] The instance to which to copy the result, or undefined if a new instance\n * should be created.\n * @returns {Cartesian2} The specified 'result', or a new object containing the tile x, y coordinates\n * if 'result' is undefined.\n */\nGeographicTilingScheme.prototype.positionToTileXY = function (\n position,\n level,\n result\n) {\n const rectangle = this._rectangle;\n if (!Rectangle.contains(rectangle, position)) {\n // outside the bounds of the tiling scheme\n return undefined;\n }\n\n const xTiles = this.getNumberOfXTilesAtLevel(level);\n const yTiles = this.getNumberOfYTilesAtLevel(level);\n\n const xTileWidth = rectangle.width / xTiles;\n const yTileHeight = rectangle.height / yTiles;\n\n let longitude = position.longitude;\n if (rectangle.east < rectangle.west) {\n longitude += CesiumMath.TWO_PI;\n }\n\n let xTileCoordinate = ((longitude - rectangle.west) / xTileWidth) | 0;\n if (xTileCoordinate >= xTiles) {\n xTileCoordinate = xTiles - 1;\n }\n\n let yTileCoordinate =\n ((rectangle.north - position.latitude) / yTileHeight) | 0;\n if (yTileCoordinate >= yTiles) {\n yTileCoordinate = yTiles - 1;\n }\n\n if (!defined(result)) {\n return new Cartesian2(xTileCoordinate, yTileCoordinate);\n }\n\n result.x = xTileCoordinate;\n result.y = yTileCoordinate;\n return result;\n};\nexport default GeographicTilingScheme;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport buildModuleUrl from \"./buildModuleUrl.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport GeographicTilingScheme from \"./GeographicTilingScheme.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport Resource from \"./Resource.js\";\n\nconst scratchDiagonalCartesianNE = new Cartesian3();\nconst scratchDiagonalCartesianSW = new Cartesian3();\nconst scratchDiagonalCartographic = new Cartographic();\nconst scratchCenterCartesian = new Cartesian3();\nconst scratchSurfaceCartesian = new Cartesian3();\n\nconst scratchBoundingSphere = new BoundingSphere();\nconst tilingScheme = new GeographicTilingScheme();\nconst scratchCorners = [\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n];\nconst scratchTileXY = new Cartesian2();\n\n/**\n * A collection of functions for approximating terrain height\n * @private\n */\nconst ApproximateTerrainHeights = {};\n\n/**\n * Initializes the minimum and maximum terrain heights\n * @return {Promise}\n */\nApproximateTerrainHeights.initialize = function () {\n let initPromise = ApproximateTerrainHeights._initPromise;\n if (defined(initPromise)) {\n return initPromise;\n }\n initPromise = Resource.fetchJson(\n buildModuleUrl(\"Assets/approximateTerrainHeights.json\")\n ).then(function (json) {\n ApproximateTerrainHeights._terrainHeights = json;\n });\n ApproximateTerrainHeights._initPromise = initPromise;\n\n return initPromise;\n};\n\n/**\n * Computes the minimum and maximum terrain heights for a given rectangle\n * @param {Rectangle} rectangle The bounding rectangle\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid\n * @return {{minimumTerrainHeight: number, maximumTerrainHeight: number}}\n */\nApproximateTerrainHeights.getMinimumMaximumHeights = function (\n rectangle,\n ellipsoid\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"rectangle\", rectangle);\n if (!defined(ApproximateTerrainHeights._terrainHeights)) {\n throw new DeveloperError(\n \"You must call ApproximateTerrainHeights.initialize and wait for the promise to resolve before using this function\"\n );\n }\n //>>includeEnd('debug');\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n const xyLevel = getTileXYLevel(rectangle);\n\n // Get the terrain min/max for that tile\n let minTerrainHeight = ApproximateTerrainHeights._defaultMinTerrainHeight;\n let maxTerrainHeight = ApproximateTerrainHeights._defaultMaxTerrainHeight;\n if (defined(xyLevel)) {\n const key = `${xyLevel.level}-${xyLevel.x}-${xyLevel.y}`;\n const heights = ApproximateTerrainHeights._terrainHeights[key];\n if (defined(heights)) {\n minTerrainHeight = heights[0];\n maxTerrainHeight = heights[1];\n }\n\n // Compute min by taking the center of the NE->SW diagonal and finding distance to the surface\n ellipsoid.cartographicToCartesian(\n Rectangle.northeast(rectangle, scratchDiagonalCartographic),\n scratchDiagonalCartesianNE\n );\n ellipsoid.cartographicToCartesian(\n Rectangle.southwest(rectangle, scratchDiagonalCartographic),\n scratchDiagonalCartesianSW\n );\n\n Cartesian3.midpoint(\n scratchDiagonalCartesianSW,\n scratchDiagonalCartesianNE,\n scratchCenterCartesian\n );\n const surfacePosition = ellipsoid.scaleToGeodeticSurface(\n scratchCenterCartesian,\n scratchSurfaceCartesian\n );\n if (defined(surfacePosition)) {\n const distance = Cartesian3.distance(\n scratchCenterCartesian,\n surfacePosition\n );\n minTerrainHeight = Math.min(minTerrainHeight, -distance);\n } else {\n minTerrainHeight = ApproximateTerrainHeights._defaultMinTerrainHeight;\n }\n }\n\n minTerrainHeight = Math.max(\n ApproximateTerrainHeights._defaultMinTerrainHeight,\n minTerrainHeight\n );\n\n return {\n minimumTerrainHeight: minTerrainHeight,\n maximumTerrainHeight: maxTerrainHeight,\n };\n};\n\n/**\n * Computes the bounding sphere based on the tile heights in the rectangle\n * @param {Rectangle} rectangle The bounding rectangle\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid\n * @return {BoundingSphere} The result bounding sphere\n */\nApproximateTerrainHeights.getBoundingSphere = function (rectangle, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"rectangle\", rectangle);\n if (!defined(ApproximateTerrainHeights._terrainHeights)) {\n throw new DeveloperError(\n \"You must call ApproximateTerrainHeights.initialize and wait for the promise to resolve before using this function\"\n );\n }\n //>>includeEnd('debug');\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n const xyLevel = getTileXYLevel(rectangle);\n\n // Get the terrain max for that tile\n let maxTerrainHeight = ApproximateTerrainHeights._defaultMaxTerrainHeight;\n if (defined(xyLevel)) {\n const key = `${xyLevel.level}-${xyLevel.x}-${xyLevel.y}`;\n const heights = ApproximateTerrainHeights._terrainHeights[key];\n if (defined(heights)) {\n maxTerrainHeight = heights[1];\n }\n }\n\n const result = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, 0.0);\n BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n maxTerrainHeight,\n scratchBoundingSphere\n );\n\n return BoundingSphere.union(result, scratchBoundingSphere, result);\n};\n\nfunction getTileXYLevel(rectangle) {\n Cartographic.fromRadians(\n rectangle.east,\n rectangle.north,\n 0.0,\n scratchCorners[0]\n );\n Cartographic.fromRadians(\n rectangle.west,\n rectangle.north,\n 0.0,\n scratchCorners[1]\n );\n Cartographic.fromRadians(\n rectangle.east,\n rectangle.south,\n 0.0,\n scratchCorners[2]\n );\n Cartographic.fromRadians(\n rectangle.west,\n rectangle.south,\n 0.0,\n scratchCorners[3]\n );\n\n // Determine which tile the bounding rectangle is in\n let lastLevelX = 0,\n lastLevelY = 0;\n let currentX = 0,\n currentY = 0;\n const maxLevel = ApproximateTerrainHeights._terrainHeightsMaxLevel;\n let i;\n for (i = 0; i <= maxLevel; ++i) {\n let failed = false;\n for (let j = 0; j < 4; ++j) {\n const corner = scratchCorners[j];\n tilingScheme.positionToTileXY(corner, i, scratchTileXY);\n if (j === 0) {\n currentX = scratchTileXY.x;\n currentY = scratchTileXY.y;\n } else if (currentX !== scratchTileXY.x || currentY !== scratchTileXY.y) {\n failed = true;\n break;\n }\n }\n\n if (failed) {\n break;\n }\n\n lastLevelX = currentX;\n lastLevelY = currentY;\n }\n\n if (i === 0) {\n return undefined;\n }\n\n return {\n x: lastLevelX,\n y: lastLevelY,\n level: i > maxLevel ? maxLevel : i - 1,\n };\n}\n\nApproximateTerrainHeights._terrainHeightsMaxLevel = 6;\nApproximateTerrainHeights._defaultMaxTerrainHeight = 9000.0;\nApproximateTerrainHeights._defaultMinTerrainHeight = -100000.0;\nApproximateTerrainHeights._terrainHeights = undefined;\nApproximateTerrainHeights._initPromise = undefined;\n\nObject.defineProperties(ApproximateTerrainHeights, {\n /**\n * Determines if the terrain heights are initialized and ready to use. To initialize the terrain heights,\n * call {@link ApproximateTerrainHeights#initialize} and wait for the returned promise to resolve.\n * @type {boolean}\n * @readonly\n * @memberof ApproximateTerrainHeights\n */\n initialized: {\n get: function () {\n return defined(ApproximateTerrainHeights._terrainHeights);\n },\n },\n});\nexport default ApproximateTerrainHeights;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Intersect from \"./Intersect.js\";\n\n/**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @alias AxisAlignedBoundingBox\n * @constructor\n *\n * @param {Cartesian3} [minimum=Cartesian3.ZERO] The minimum point along the x, y, and z axes.\n * @param {Cartesian3} [maximum=Cartesian3.ZERO] The maximum point along the x, y, and z axes.\n * @param {Cartesian3} [center] The center of the box; automatically computed if not supplied.\n *\n * @see BoundingSphere\n * @see BoundingRectangle\n */\nfunction AxisAlignedBoundingBox(minimum, maximum, center) {\n /**\n * The minimum point defining the bounding box.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.minimum = Cartesian3.clone(defaultValue(minimum, Cartesian3.ZERO));\n\n /**\n * The maximum point defining the bounding box.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.maximum = Cartesian3.clone(defaultValue(maximum, Cartesian3.ZERO));\n\n // If center was not defined, compute it.\n if (!defined(center)) {\n center = Cartesian3.midpoint(this.minimum, this.maximum, new Cartesian3());\n } else {\n center = Cartesian3.clone(center);\n }\n\n /**\n * The center point of the bounding box.\n * @type {Cartesian3}\n */\n this.center = center;\n}\n\n/**\n * Creates an instance of an AxisAlignedBoundingBox from its corners.\n *\n * @param {Cartesian3} minimum The minimum point along the x, y, and z axes.\n * @param {Cartesian3} maximum The maximum point along the x, y, and z axes.\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.\n *\n * @example\n * // Compute an axis aligned bounding box from the two corners.\n * const box = Cesium.AxisAlignedBoundingBox.fromCorners(new Cesium.Cartesian3(-1, -1, -1), new Cesium.Cartesian3(1, 1, 1));\n */\nAxisAlignedBoundingBox.fromCorners = function (minimum, maximum, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"minimum\", minimum);\n Check.defined(\"maximum\", maximum);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new AxisAlignedBoundingBox();\n }\n\n result.minimum = Cartesian3.clone(minimum, result.minimum);\n result.maximum = Cartesian3.clone(maximum, result.maximum);\n result.center = Cartesian3.midpoint(minimum, maximum, result.center);\n\n return result;\n};\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n *\n * @param {Cartesian3[]} positions List of points that the bounding box will enclose. Each point must have a x, y, and z properties.\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.\n *\n * @example\n * // Compute an axis aligned bounding box enclosing two points.\n * const box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);\n */\nAxisAlignedBoundingBox.fromPoints = function (positions, result) {\n if (!defined(result)) {\n result = new AxisAlignedBoundingBox();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.minimum = Cartesian3.clone(Cartesian3.ZERO, result.minimum);\n result.maximum = Cartesian3.clone(Cartesian3.ZERO, result.maximum);\n result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);\n return result;\n }\n\n let minimumX = positions[0].x;\n let minimumY = positions[0].y;\n let minimumZ = positions[0].z;\n\n let maximumX = positions[0].x;\n let maximumY = positions[0].y;\n let maximumZ = positions[0].z;\n\n const length = positions.length;\n for (let i = 1; i < length; i++) {\n const p = positions[i];\n const x = p.x;\n const y = p.y;\n const z = p.z;\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n const minimum = result.minimum;\n minimum.x = minimumX;\n minimum.y = minimumY;\n minimum.z = minimumZ;\n\n const maximum = result.maximum;\n maximum.x = maximumX;\n maximum.y = maximumY;\n maximum.z = maximumZ;\n\n result.center = Cartesian3.midpoint(minimum, maximum, result.center);\n\n return result;\n};\n\n/**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @param {AxisAlignedBoundingBox} box The bounding box to duplicate.\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if none was provided. (Returns undefined if box is undefined)\n */\nAxisAlignedBoundingBox.clone = function (box, result) {\n if (!defined(box)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new AxisAlignedBoundingBox(box.minimum, box.maximum, box.center);\n }\n\n result.minimum = Cartesian3.clone(box.minimum, result.minimum);\n result.maximum = Cartesian3.clone(box.maximum, result.maximum);\n result.center = Cartesian3.clone(box.center, result.center);\n return result;\n};\n\n/**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {AxisAlignedBoundingBox} [left] The first AxisAlignedBoundingBox.\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nAxisAlignedBoundingBox.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Cartesian3.equals(left.center, right.center) &&\n Cartesian3.equals(left.minimum, right.minimum) &&\n Cartesian3.equals(left.maximum, right.maximum))\n );\n};\n\nlet intersectScratch = new Cartesian3();\n/**\n * Determines which side of a plane a box is located.\n *\n * @param {AxisAlignedBoundingBox} box The bounding box to test.\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nAxisAlignedBoundingBox.intersectPlane = function (box, plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"box\", box);\n Check.defined(\"plane\", plane);\n //>>includeEnd('debug');\n\n intersectScratch = Cartesian3.subtract(\n box.maximum,\n box.minimum,\n intersectScratch\n );\n const h = Cartesian3.multiplyByScalar(\n intersectScratch,\n 0.5,\n intersectScratch\n ); //The positive half diagonal\n const normal = plane.normal;\n const e =\n h.x * Math.abs(normal.x) +\n h.y * Math.abs(normal.y) +\n h.z * Math.abs(normal.z);\n const s = Cartesian3.dot(box.center, normal) + plane.distance; //signed distance from center\n\n if (s - e > 0) {\n return Intersect.INSIDE;\n }\n\n if (s + e < 0) {\n //Not in front because normals point inward\n return Intersect.OUTSIDE;\n }\n\n return Intersect.INTERSECTING;\n};\n\n/**\n * Duplicates this AxisAlignedBoundingBox instance.\n *\n * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.\n * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.\n */\nAxisAlignedBoundingBox.prototype.clone = function (result) {\n return AxisAlignedBoundingBox.clone(this, result);\n};\n\n/**\n * Determines which side of a plane this box is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nAxisAlignedBoundingBox.prototype.intersectPlane = function (plane) {\n return AxisAlignedBoundingBox.intersectPlane(this, plane);\n};\n\n/**\n * Compares this AxisAlignedBoundingBox against the provided AxisAlignedBoundingBox componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The right hand side AxisAlignedBoundingBox.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nAxisAlignedBoundingBox.prototype.equals = function (right) {\n return AxisAlignedBoundingBox.equals(this, right);\n};\nexport default AxisAlignedBoundingBox;\n", "import DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * Defines functions for 2nd order polynomial functions of one variable with only real coefficients.\n *\n * @namespace QuadraticRealPolynomial\n */\nconst QuadraticRealPolynomial = {};\n\n/**\n * Provides the discriminant of the quadratic equation from the supplied coefficients.\n *\n * @param {number} a The coefficient of the 2nd order monomial.\n * @param {number} b The coefficient of the 1st order monomial.\n * @param {number} c The coefficient of the 0th order monomial.\n * @returns {number} The value of the discriminant.\n */\nQuadraticRealPolynomial.computeDiscriminant = function (a, b, c) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n //>>includeEnd('debug');\n\n const discriminant = b * b - 4.0 * a * c;\n return discriminant;\n};\n\nfunction addWithCancellationCheck(left, right, tolerance) {\n const difference = left + right;\n if (\n CesiumMath.sign(left) !== CesiumMath.sign(right) &&\n Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance\n ) {\n return 0.0;\n }\n\n return difference;\n}\n\n/**\n * Provides the real valued roots of the quadratic polynomial with the provided coefficients.\n *\n * @param {number} a The coefficient of the 2nd order monomial.\n * @param {number} b The coefficient of the 1st order monomial.\n * @param {number} c The coefficient of the 0th order monomial.\n * @returns {number[]} The real valued roots.\n */\nQuadraticRealPolynomial.computeRealRoots = function (a, b, c) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n //>>includeEnd('debug');\n\n let ratio;\n if (a === 0.0) {\n if (b === 0.0) {\n // Constant function: c = 0.\n return [];\n }\n\n // Linear function: b * x + c = 0.\n return [-c / b];\n } else if (b === 0.0) {\n if (c === 0.0) {\n // 2nd order monomial: a * x^2 = 0.\n return [0.0, 0.0];\n }\n\n const cMagnitude = Math.abs(c);\n const aMagnitude = Math.abs(a);\n\n if (\n cMagnitude < aMagnitude &&\n cMagnitude / aMagnitude < CesiumMath.EPSILON14\n ) {\n // c ~= 0.0.\n // 2nd order monomial: a * x^2 = 0.\n return [0.0, 0.0];\n } else if (\n cMagnitude > aMagnitude &&\n aMagnitude / cMagnitude < CesiumMath.EPSILON14\n ) {\n // a ~= 0.0.\n // Constant function: c = 0.\n return [];\n }\n\n // a * x^2 + c = 0\n ratio = -c / a;\n\n if (ratio < 0.0) {\n // Both roots are complex.\n return [];\n }\n\n // Both roots are real.\n const root = Math.sqrt(ratio);\n return [-root, root];\n } else if (c === 0.0) {\n // a * x^2 + b * x = 0\n ratio = -b / a;\n if (ratio < 0.0) {\n return [ratio, 0.0];\n }\n\n return [0.0, ratio];\n }\n\n // a * x^2 + b * x + c = 0\n const b2 = b * b;\n const four_ac = 4.0 * a * c;\n const radicand = addWithCancellationCheck(b2, -four_ac, CesiumMath.EPSILON14);\n\n if (radicand < 0.0) {\n // Both roots are complex.\n return [];\n }\n\n const q =\n -0.5 *\n addWithCancellationCheck(\n b,\n CesiumMath.sign(b) * Math.sqrt(radicand),\n CesiumMath.EPSILON14\n );\n if (b > 0.0) {\n return [q / a, c / q];\n }\n\n return [c / q, q / a];\n};\nexport default QuadraticRealPolynomial;\n", "import DeveloperError from \"./DeveloperError.js\";\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\n\n/**\n * Defines functions for 3rd order polynomial functions of one variable with only real coefficients.\n *\n * @namespace CubicRealPolynomial\n */\nconst CubicRealPolynomial = {};\n\n/**\n * Provides the discriminant of the cubic equation from the supplied coefficients.\n *\n * @param {number} a The coefficient of the 3rd order monomial.\n * @param {number} b The coefficient of the 2nd order monomial.\n * @param {number} c The coefficient of the 1st order monomial.\n * @param {number} d The coefficient of the 0th order monomial.\n * @returns {number} The value of the discriminant.\n */\nCubicRealPolynomial.computeDiscriminant = function (a, b, c, d) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n if (typeof d !== \"number\") {\n throw new DeveloperError(\"d is a required number.\");\n }\n //>>includeEnd('debug');\n\n const a2 = a * a;\n const b2 = b * b;\n const c2 = c * c;\n const d2 = d * d;\n\n const discriminant =\n 18.0 * a * b * c * d +\n b2 * c2 -\n 27.0 * a2 * d2 -\n 4.0 * (a * c2 * c + b2 * b * d);\n return discriminant;\n};\n\nfunction computeRealRoots(a, b, c, d) {\n const A = a;\n const B = b / 3.0;\n const C = c / 3.0;\n const D = d;\n\n const AC = A * C;\n const BD = B * D;\n const B2 = B * B;\n const C2 = C * C;\n const delta1 = A * C - B2;\n const delta2 = A * D - B * C;\n const delta3 = B * D - C2;\n\n const discriminant = 4.0 * delta1 * delta3 - delta2 * delta2;\n let temp;\n let temp1;\n\n if (discriminant < 0.0) {\n let ABar;\n let CBar;\n let DBar;\n\n if (B2 * BD >= AC * C2) {\n ABar = A;\n CBar = delta1;\n DBar = -2.0 * B * delta1 + A * delta2;\n } else {\n ABar = D;\n CBar = delta3;\n DBar = -D * delta2 + 2.0 * C * delta3;\n }\n\n const s = DBar < 0.0 ? -1.0 : 1.0; // This is not Math.Sign()!\n const temp0 = -s * Math.abs(ABar) * Math.sqrt(-discriminant);\n temp1 = -DBar + temp0;\n\n const x = temp1 / 2.0;\n const p = x < 0.0 ? -Math.pow(-x, 1.0 / 3.0) : Math.pow(x, 1.0 / 3.0);\n const q = temp1 === temp0 ? -p : -CBar / p;\n\n temp = CBar <= 0.0 ? p + q : -DBar / (p * p + q * q + CBar);\n\n if (B2 * BD >= AC * C2) {\n return [(temp - B) / A];\n }\n\n return [-D / (temp + C)];\n }\n\n const CBarA = delta1;\n const DBarA = -2.0 * B * delta1 + A * delta2;\n\n const CBarD = delta3;\n const DBarD = -D * delta2 + 2.0 * C * delta3;\n\n const squareRootOfDiscriminant = Math.sqrt(discriminant);\n const halfSquareRootOf3 = Math.sqrt(3.0) / 2.0;\n\n let theta = Math.abs(Math.atan2(A * squareRootOfDiscriminant, -DBarA) / 3.0);\n temp = 2.0 * Math.sqrt(-CBarA);\n let cosine = Math.cos(theta);\n temp1 = temp * cosine;\n let temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));\n\n const numeratorLarge = temp1 + temp3 > 2.0 * B ? temp1 - B : temp3 - B;\n const denominatorLarge = A;\n\n const root1 = numeratorLarge / denominatorLarge;\n\n theta = Math.abs(Math.atan2(D * squareRootOfDiscriminant, -DBarD) / 3.0);\n temp = 2.0 * Math.sqrt(-CBarD);\n cosine = Math.cos(theta);\n temp1 = temp * cosine;\n temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));\n\n const numeratorSmall = -D;\n const denominatorSmall = temp1 + temp3 < 2.0 * C ? temp1 + C : temp3 + C;\n\n const root3 = numeratorSmall / denominatorSmall;\n\n const E = denominatorLarge * denominatorSmall;\n const F =\n -numeratorLarge * denominatorSmall - denominatorLarge * numeratorSmall;\n const G = numeratorLarge * numeratorSmall;\n\n const root2 = (C * F - B * G) / (-B * F + C * E);\n\n if (root1 <= root2) {\n if (root1 <= root3) {\n if (root2 <= root3) {\n return [root1, root2, root3];\n }\n return [root1, root3, root2];\n }\n return [root3, root1, root2];\n }\n if (root1 <= root3) {\n return [root2, root1, root3];\n }\n if (root2 <= root3) {\n return [root2, root3, root1];\n }\n return [root3, root2, root1];\n}\n\n/**\n * Provides the real valued roots of the cubic polynomial with the provided coefficients.\n *\n * @param {number} a The coefficient of the 3rd order monomial.\n * @param {number} b The coefficient of the 2nd order monomial.\n * @param {number} c The coefficient of the 1st order monomial.\n * @param {number} d The coefficient of the 0th order monomial.\n * @returns {number[]} The real valued roots.\n */\nCubicRealPolynomial.computeRealRoots = function (a, b, c, d) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n if (typeof d !== \"number\") {\n throw new DeveloperError(\"d is a required number.\");\n }\n //>>includeEnd('debug');\n\n let roots;\n let ratio;\n if (a === 0.0) {\n // Quadratic function: b * x^2 + c * x + d = 0.\n return QuadraticRealPolynomial.computeRealRoots(b, c, d);\n } else if (b === 0.0) {\n if (c === 0.0) {\n if (d === 0.0) {\n // 3rd order monomial: a * x^3 = 0.\n return [0.0, 0.0, 0.0];\n }\n\n // a * x^3 + d = 0\n ratio = -d / a;\n const root =\n ratio < 0.0 ? -Math.pow(-ratio, 1.0 / 3.0) : Math.pow(ratio, 1.0 / 3.0);\n return [root, root, root];\n } else if (d === 0.0) {\n // x * (a * x^2 + c) = 0.\n roots = QuadraticRealPolynomial.computeRealRoots(a, 0, c);\n\n // Return the roots in ascending order.\n if (roots.Length === 0) {\n return [0.0];\n }\n return [roots[0], 0.0, roots[1]];\n }\n\n // Deflated cubic polynomial: a * x^3 + c * x + d= 0.\n return computeRealRoots(a, 0, c, d);\n } else if (c === 0.0) {\n if (d === 0.0) {\n // x^2 * (a * x + b) = 0.\n ratio = -b / a;\n if (ratio < 0.0) {\n return [ratio, 0.0, 0.0];\n }\n return [0.0, 0.0, ratio];\n }\n // a * x^3 + b * x^2 + d = 0.\n return computeRealRoots(a, b, 0, d);\n } else if (d === 0.0) {\n // x * (a * x^2 + b * x + c) = 0\n roots = QuadraticRealPolynomial.computeRealRoots(a, b, c);\n\n // Return the roots in ascending order.\n if (roots.length === 0) {\n return [0.0];\n } else if (roots[1] <= 0.0) {\n return [roots[0], roots[1], 0.0];\n } else if (roots[0] >= 0.0) {\n return [0.0, roots[0], roots[1]];\n }\n return [roots[0], 0.0, roots[1]];\n }\n\n return computeRealRoots(a, b, c, d);\n};\nexport default CubicRealPolynomial;\n", "import CubicRealPolynomial from \"./CubicRealPolynomial.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\n\n/**\n * Defines functions for 4th order polynomial functions of one variable with only real coefficients.\n *\n * @namespace QuarticRealPolynomial\n */\nconst QuarticRealPolynomial = {};\n\n/**\n * Provides the discriminant of the quartic equation from the supplied coefficients.\n *\n * @param {number} a The coefficient of the 4th order monomial.\n * @param {number} b The coefficient of the 3rd order monomial.\n * @param {number} c The coefficient of the 2nd order monomial.\n * @param {number} d The coefficient of the 1st order monomial.\n * @param {number} e The coefficient of the 0th order monomial.\n * @returns {number} The value of the discriminant.\n */\nQuarticRealPolynomial.computeDiscriminant = function (a, b, c, d, e) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n if (typeof d !== \"number\") {\n throw new DeveloperError(\"d is a required number.\");\n }\n if (typeof e !== \"number\") {\n throw new DeveloperError(\"e is a required number.\");\n }\n //>>includeEnd('debug');\n\n const a2 = a * a;\n const a3 = a2 * a;\n const b2 = b * b;\n const b3 = b2 * b;\n const c2 = c * c;\n const c3 = c2 * c;\n const d2 = d * d;\n const d3 = d2 * d;\n const e2 = e * e;\n const e3 = e2 * e;\n\n const discriminant =\n b2 * c2 * d2 -\n 4.0 * b3 * d3 -\n 4.0 * a * c3 * d2 +\n 18 * a * b * c * d3 -\n 27.0 * a2 * d2 * d2 +\n 256.0 * a3 * e3 +\n e *\n (18.0 * b3 * c * d -\n 4.0 * b2 * c3 +\n 16.0 * a * c2 * c2 -\n 80.0 * a * b * c2 * d -\n 6.0 * a * b2 * d2 +\n 144.0 * a2 * c * d2) +\n e2 *\n (144.0 * a * b2 * c -\n 27.0 * b2 * b2 -\n 128.0 * a2 * c2 -\n 192.0 * a2 * b * d);\n return discriminant;\n};\n\nfunction original(a3, a2, a1, a0) {\n const a3Squared = a3 * a3;\n\n const p = a2 - (3.0 * a3Squared) / 8.0;\n const q = a1 - (a2 * a3) / 2.0 + (a3Squared * a3) / 8.0;\n const r =\n a0 -\n (a1 * a3) / 4.0 +\n (a2 * a3Squared) / 16.0 -\n (3.0 * a3Squared * a3Squared) / 256.0;\n\n // Find the roots of the cubic equations: h^6 + 2 p h^4 + (p^2 - 4 r) h^2 - q^2 = 0.\n const cubicRoots = CubicRealPolynomial.computeRealRoots(\n 1.0,\n 2.0 * p,\n p * p - 4.0 * r,\n -q * q\n );\n\n if (cubicRoots.length > 0) {\n const temp = -a3 / 4.0;\n\n // Use the largest positive root.\n const hSquared = cubicRoots[cubicRoots.length - 1];\n\n if (Math.abs(hSquared) < CesiumMath.EPSILON14) {\n // y^4 + p y^2 + r = 0.\n const roots = QuadraticRealPolynomial.computeRealRoots(1.0, p, r);\n\n if (roots.length === 2) {\n const root0 = roots[0];\n const root1 = roots[1];\n\n let y;\n if (root0 >= 0.0 && root1 >= 0.0) {\n const y0 = Math.sqrt(root0);\n const y1 = Math.sqrt(root1);\n\n return [temp - y1, temp - y0, temp + y0, temp + y1];\n } else if (root0 >= 0.0 && root1 < 0.0) {\n y = Math.sqrt(root0);\n return [temp - y, temp + y];\n } else if (root0 < 0.0 && root1 >= 0.0) {\n y = Math.sqrt(root1);\n return [temp - y, temp + y];\n }\n }\n return [];\n } else if (hSquared > 0.0) {\n const h = Math.sqrt(hSquared);\n\n const m = (p + hSquared - q / h) / 2.0;\n const n = (p + hSquared + q / h) / 2.0;\n\n // Now solve the two quadratic factors: (y^2 + h y + m)(y^2 - h y + n);\n const roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, h, m);\n const roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, -h, n);\n\n if (roots1.length !== 0) {\n roots1[0] += temp;\n roots1[1] += temp;\n\n if (roots2.length !== 0) {\n roots2[0] += temp;\n roots2[1] += temp;\n\n if (roots1[1] <= roots2[0]) {\n return [roots1[0], roots1[1], roots2[0], roots2[1]];\n } else if (roots2[1] <= roots1[0]) {\n return [roots2[0], roots2[1], roots1[0], roots1[1]];\n } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {\n return [roots2[0], roots1[0], roots1[1], roots2[1]];\n } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {\n return [roots1[0], roots2[0], roots2[1], roots1[1]];\n } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {\n return [roots2[0], roots1[0], roots2[1], roots1[1]];\n }\n return [roots1[0], roots2[0], roots1[1], roots2[1]];\n }\n return roots1;\n }\n\n if (roots2.length !== 0) {\n roots2[0] += temp;\n roots2[1] += temp;\n\n return roots2;\n }\n return [];\n }\n }\n return [];\n}\n\nfunction neumark(a3, a2, a1, a0) {\n const a1Squared = a1 * a1;\n const a2Squared = a2 * a2;\n const a3Squared = a3 * a3;\n\n const p = -2.0 * a2;\n const q = a1 * a3 + a2Squared - 4.0 * a0;\n const r = a3Squared * a0 - a1 * a2 * a3 + a1Squared;\n\n const cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, p, q, r);\n\n if (cubicRoots.length > 0) {\n // Use the most positive root\n const y = cubicRoots[0];\n\n const temp = a2 - y;\n const tempSquared = temp * temp;\n\n const g1 = a3 / 2.0;\n const h1 = temp / 2.0;\n\n const m = tempSquared - 4.0 * a0;\n const mError = tempSquared + 4.0 * Math.abs(a0);\n\n const n = a3Squared - 4.0 * y;\n const nError = a3Squared + 4.0 * Math.abs(y);\n\n let g2;\n let h2;\n\n if (y < 0.0 || m * nError < n * mError) {\n const squareRootOfN = Math.sqrt(n);\n g2 = squareRootOfN / 2.0;\n h2 = squareRootOfN === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfN;\n } else {\n const squareRootOfM = Math.sqrt(m);\n g2 = squareRootOfM === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfM;\n h2 = squareRootOfM / 2.0;\n }\n\n let G;\n let g;\n if (g1 === 0.0 && g2 === 0.0) {\n G = 0.0;\n g = 0.0;\n } else if (CesiumMath.sign(g1) === CesiumMath.sign(g2)) {\n G = g1 + g2;\n g = y / G;\n } else {\n g = g1 - g2;\n G = y / g;\n }\n\n let H;\n let h;\n if (h1 === 0.0 && h2 === 0.0) {\n H = 0.0;\n h = 0.0;\n } else if (CesiumMath.sign(h1) === CesiumMath.sign(h2)) {\n H = h1 + h2;\n h = a0 / H;\n } else {\n h = h1 - h2;\n H = a0 / h;\n }\n\n // Now solve the two quadratic factors: (y^2 + G y + H)(y^2 + g y + h);\n const roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, G, H);\n const roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, g, h);\n\n if (roots1.length !== 0) {\n if (roots2.length !== 0) {\n if (roots1[1] <= roots2[0]) {\n return [roots1[0], roots1[1], roots2[0], roots2[1]];\n } else if (roots2[1] <= roots1[0]) {\n return [roots2[0], roots2[1], roots1[0], roots1[1]];\n } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {\n return [roots2[0], roots1[0], roots1[1], roots2[1]];\n } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {\n return [roots1[0], roots2[0], roots2[1], roots1[1]];\n } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {\n return [roots2[0], roots1[0], roots2[1], roots1[1]];\n }\n return [roots1[0], roots2[0], roots1[1], roots2[1]];\n }\n return roots1;\n }\n if (roots2.length !== 0) {\n return roots2;\n }\n }\n return [];\n}\n\n/**\n * Provides the real valued roots of the quartic polynomial with the provided coefficients.\n *\n * @param {number} a The coefficient of the 4th order monomial.\n * @param {number} b The coefficient of the 3rd order monomial.\n * @param {number} c The coefficient of the 2nd order monomial.\n * @param {number} d The coefficient of the 1st order monomial.\n * @param {number} e The coefficient of the 0th order monomial.\n * @returns {number[]} The real valued roots.\n */\nQuarticRealPolynomial.computeRealRoots = function (a, b, c, d, e) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n if (typeof d !== \"number\") {\n throw new DeveloperError(\"d is a required number.\");\n }\n if (typeof e !== \"number\") {\n throw new DeveloperError(\"e is a required number.\");\n }\n //>>includeEnd('debug');\n\n if (Math.abs(a) < CesiumMath.EPSILON15) {\n return CubicRealPolynomial.computeRealRoots(b, c, d, e);\n }\n const a3 = b / a;\n const a2 = c / a;\n const a1 = d / a;\n const a0 = e / a;\n\n let k = a3 < 0.0 ? 1 : 0;\n k += a2 < 0.0 ? k + 1 : k;\n k += a1 < 0.0 ? k + 1 : k;\n k += a0 < 0.0 ? k + 1 : k;\n\n switch (k) {\n case 0:\n return original(a3, a2, a1, a0);\n case 1:\n return neumark(a3, a2, a1, a0);\n case 2:\n return neumark(a3, a2, a1, a0);\n case 3:\n return original(a3, a2, a1, a0);\n case 4:\n return original(a3, a2, a1, a0);\n case 5:\n return neumark(a3, a2, a1, a0);\n case 6:\n return original(a3, a2, a1, a0);\n case 7:\n return original(a3, a2, a1, a0);\n case 8:\n return neumark(a3, a2, a1, a0);\n case 9:\n return original(a3, a2, a1, a0);\n case 10:\n return original(a3, a2, a1, a0);\n case 11:\n return neumark(a3, a2, a1, a0);\n case 12:\n return original(a3, a2, a1, a0);\n case 13:\n return original(a3, a2, a1, a0);\n case 14:\n return original(a3, a2, a1, a0);\n case 15:\n return original(a3, a2, a1, a0);\n default:\n return undefined;\n }\n};\nexport default QuarticRealPolynomial;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Represents a ray that extends infinitely from the provided origin in the provided direction.\n * @alias Ray\n * @constructor\n *\n * @param {Cartesian3} [origin=Cartesian3.ZERO] The origin of the ray.\n * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray.\n */\nfunction Ray(origin, direction) {\n direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO));\n if (!Cartesian3.equals(direction, Cartesian3.ZERO)) {\n Cartesian3.normalize(direction, direction);\n }\n\n /**\n * The origin of the ray.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO));\n\n /**\n * The direction of the ray.\n * @type {Cartesian3}\n */\n this.direction = direction;\n}\n\n/**\n * Duplicates a Ray instance.\n *\n * @param {Ray} ray The ray to duplicate.\n * @param {Ray} [result] The object onto which to store the result.\n * @returns {Ray} The modified result parameter or a new Ray instance if one was not provided. (Returns undefined if ray is undefined)\n */\nRay.clone = function (ray, result) {\n if (!defined(ray)) {\n return undefined;\n }\n if (!defined(result)) {\n return new Ray(ray.origin, ray.direction);\n }\n result.origin = Cartesian3.clone(ray.origin);\n result.direction = Cartesian3.clone(ray.direction);\n return result;\n};\n\n/**\n * Computes the point along the ray given by r(t) = o + t*d,\n * where o is the origin of the ray and d is the direction.\n *\n * @param {Ray} ray The ray.\n * @param {number} t A scalar value.\n * @param {Cartesian3} [result] The object in which the result will be stored.\n * @returns {Cartesian3} The modified result parameter, or a new instance if none was provided.\n *\n * @example\n * //Get the first intersection point of a ray and an ellipsoid.\n * const intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);\n * const point = Cesium.Ray.getPoint(ray, intersection.start);\n */\nRay.getPoint = function (ray, t, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ray\", ray);\n Check.typeOf.number(\"t\", t);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n result = Cartesian3.multiplyByScalar(ray.direction, t, result);\n return Cartesian3.add(ray.origin, result, result);\n};\nexport default Ray;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Interval from \"./Interval.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport QuadraticRealPolynomial from \"./QuadraticRealPolynomial.js\";\nimport QuarticRealPolynomial from \"./QuarticRealPolynomial.js\";\nimport Ray from \"./Ray.js\";\n\n/**\n * Functions for computing the intersection between geometries such as rays, planes, triangles, and ellipsoids.\n *\n * @namespace IntersectionTests\n */\nconst IntersectionTests = {};\n\n/**\n * Computes the intersection of a ray and a plane.\n *\n * @param {Ray} ray The ray.\n * @param {Plane} plane The plane.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\n */\nIntersectionTests.rayPlane = function (ray, plane, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(ray)) {\n throw new DeveloperError(\"ray is required.\");\n }\n if (!defined(plane)) {\n throw new DeveloperError(\"plane is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const origin = ray.origin;\n const direction = ray.direction;\n const normal = plane.normal;\n const denominator = Cartesian3.dot(normal, direction);\n\n if (Math.abs(denominator) < CesiumMath.EPSILON15) {\n // Ray is parallel to plane. The ray may be in the polygon's plane.\n return undefined;\n }\n\n const t = (-plane.distance - Cartesian3.dot(normal, origin)) / denominator;\n\n if (t < 0) {\n return undefined;\n }\n\n result = Cartesian3.multiplyByScalar(direction, t, result);\n return Cartesian3.add(origin, result, result);\n};\n\nconst scratchEdge0 = new Cartesian3();\nconst scratchEdge1 = new Cartesian3();\nconst scratchPVec = new Cartesian3();\nconst scratchTVec = new Cartesian3();\nconst scratchQVec = new Cartesian3();\n\n/**\n * Computes the intersection of a ray and a triangle as a parametric distance along the input ray. The result is negative when the triangle is behind the ray.\n *\n * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|\n * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.\n *\n * @memberof IntersectionTests\n *\n * @param {Ray} ray The ray.\n * @param {Cartesian3} p0 The first vertex of the triangle.\n * @param {Cartesian3} p1 The second vertex of the triangle.\n * @param {Cartesian3} p2 The third vertex of the triangle.\n * @param {boolean} [cullBackFaces=false] If true, will only compute an intersection with the front face of the triangle\n * and return undefined for intersections with the back face.\n * @returns {number} The intersection as a parametric distance along the ray, or undefined if there is no intersection.\n */\nIntersectionTests.rayTriangleParametric = function (\n ray,\n p0,\n p1,\n p2,\n cullBackFaces\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(ray)) {\n throw new DeveloperError(\"ray is required.\");\n }\n if (!defined(p0)) {\n throw new DeveloperError(\"p0 is required.\");\n }\n if (!defined(p1)) {\n throw new DeveloperError(\"p1 is required.\");\n }\n if (!defined(p2)) {\n throw new DeveloperError(\"p2 is required.\");\n }\n //>>includeEnd('debug');\n\n cullBackFaces = defaultValue(cullBackFaces, false);\n\n const origin = ray.origin;\n const direction = ray.direction;\n\n const edge0 = Cartesian3.subtract(p1, p0, scratchEdge0);\n const edge1 = Cartesian3.subtract(p2, p0, scratchEdge1);\n\n const p = Cartesian3.cross(direction, edge1, scratchPVec);\n const det = Cartesian3.dot(edge0, p);\n\n let tvec;\n let q;\n\n let u;\n let v;\n let t;\n\n if (cullBackFaces) {\n if (det < CesiumMath.EPSILON6) {\n return undefined;\n }\n\n tvec = Cartesian3.subtract(origin, p0, scratchTVec);\n u = Cartesian3.dot(tvec, p);\n if (u < 0.0 || u > det) {\n return undefined;\n }\n\n q = Cartesian3.cross(tvec, edge0, scratchQVec);\n\n v = Cartesian3.dot(direction, q);\n if (v < 0.0 || u + v > det) {\n return undefined;\n }\n\n t = Cartesian3.dot(edge1, q) / det;\n } else {\n if (Math.abs(det) < CesiumMath.EPSILON6) {\n return undefined;\n }\n const invDet = 1.0 / det;\n\n tvec = Cartesian3.subtract(origin, p0, scratchTVec);\n u = Cartesian3.dot(tvec, p) * invDet;\n if (u < 0.0 || u > 1.0) {\n return undefined;\n }\n\n q = Cartesian3.cross(tvec, edge0, scratchQVec);\n\n v = Cartesian3.dot(direction, q) * invDet;\n if (v < 0.0 || u + v > 1.0) {\n return undefined;\n }\n\n t = Cartesian3.dot(edge1, q) * invDet;\n }\n\n return t;\n};\n\n/**\n * Computes the intersection of a ray and a triangle as a Cartesian3 coordinate.\n *\n * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|\n * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.\n *\n * @memberof IntersectionTests\n *\n * @param {Ray} ray The ray.\n * @param {Cartesian3} p0 The first vertex of the triangle.\n * @param {Cartesian3} p1 The second vertex of the triangle.\n * @param {Cartesian3} p2 The third vertex of the triangle.\n * @param {boolean} [cullBackFaces=false] If true, will only compute an intersection with the front face of the triangle\n * and return undefined for intersections with the back face.\n * @param {Cartesian3} [result] The Cartesian3 onto which to store the result.\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\n */\nIntersectionTests.rayTriangle = function (\n ray,\n p0,\n p1,\n p2,\n cullBackFaces,\n result\n) {\n const t = IntersectionTests.rayTriangleParametric(\n ray,\n p0,\n p1,\n p2,\n cullBackFaces\n );\n if (!defined(t) || t < 0.0) {\n return undefined;\n }\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n Cartesian3.multiplyByScalar(ray.direction, t, result);\n return Cartesian3.add(ray.origin, result, result);\n};\n\nconst scratchLineSegmentTriangleRay = new Ray();\n\n/**\n * Computes the intersection of a line segment and a triangle.\n * @memberof IntersectionTests\n *\n * @param {Cartesian3} v0 The an end point of the line segment.\n * @param {Cartesian3} v1 The other end point of the line segment.\n * @param {Cartesian3} p0 The first vertex of the triangle.\n * @param {Cartesian3} p1 The second vertex of the triangle.\n * @param {Cartesian3} p2 The third vertex of the triangle.\n * @param {boolean} [cullBackFaces=false] If true, will only compute an intersection with the front face of the triangle\n * and return undefined for intersections with the back face.\n * @param {Cartesian3} [result] The Cartesian3 onto which to store the result.\n * @returns {Cartesian3} The intersection point or undefined if there is no intersections.\n */\nIntersectionTests.lineSegmentTriangle = function (\n v0,\n v1,\n p0,\n p1,\n p2,\n cullBackFaces,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(v0)) {\n throw new DeveloperError(\"v0 is required.\");\n }\n if (!defined(v1)) {\n throw new DeveloperError(\"v1 is required.\");\n }\n if (!defined(p0)) {\n throw new DeveloperError(\"p0 is required.\");\n }\n if (!defined(p1)) {\n throw new DeveloperError(\"p1 is required.\");\n }\n if (!defined(p2)) {\n throw new DeveloperError(\"p2 is required.\");\n }\n //>>includeEnd('debug');\n\n const ray = scratchLineSegmentTriangleRay;\n Cartesian3.clone(v0, ray.origin);\n Cartesian3.subtract(v1, v0, ray.direction);\n Cartesian3.normalize(ray.direction, ray.direction);\n\n const t = IntersectionTests.rayTriangleParametric(\n ray,\n p0,\n p1,\n p2,\n cullBackFaces\n );\n if (!defined(t) || t < 0.0 || t > Cartesian3.distance(v0, v1)) {\n return undefined;\n }\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n Cartesian3.multiplyByScalar(ray.direction, t, result);\n return Cartesian3.add(ray.origin, result, result);\n};\n\nfunction solveQuadratic(a, b, c, result) {\n const det = b * b - 4.0 * a * c;\n if (det < 0.0) {\n return undefined;\n } else if (det > 0.0) {\n const denom = 1.0 / (2.0 * a);\n const disc = Math.sqrt(det);\n const root0 = (-b + disc) * denom;\n const root1 = (-b - disc) * denom;\n\n if (root0 < root1) {\n result.root0 = root0;\n result.root1 = root1;\n } else {\n result.root0 = root1;\n result.root1 = root0;\n }\n\n return result;\n }\n\n const root = -b / (2.0 * a);\n if (root === 0.0) {\n return undefined;\n }\n\n result.root0 = result.root1 = root;\n return result;\n}\n\nconst raySphereRoots = {\n root0: 0.0,\n root1: 0.0,\n};\n\nfunction raySphere(ray, sphere, result) {\n if (!defined(result)) {\n result = new Interval();\n }\n\n const origin = ray.origin;\n const direction = ray.direction;\n\n const center = sphere.center;\n const radiusSquared = sphere.radius * sphere.radius;\n\n const diff = Cartesian3.subtract(origin, center, scratchPVec);\n\n const a = Cartesian3.dot(direction, direction);\n const b = 2.0 * Cartesian3.dot(direction, diff);\n const c = Cartesian3.magnitudeSquared(diff) - radiusSquared;\n\n const roots = solveQuadratic(a, b, c, raySphereRoots);\n if (!defined(roots)) {\n return undefined;\n }\n\n result.start = roots.root0;\n result.stop = roots.root1;\n return result;\n}\n\n/**\n * Computes the intersection points of a ray with a sphere.\n * @memberof IntersectionTests\n *\n * @param {Ray} ray The ray.\n * @param {BoundingSphere} sphere The sphere.\n * @param {Interval} [result] The result onto which to store the result.\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\n */\nIntersectionTests.raySphere = function (ray, sphere, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(ray)) {\n throw new DeveloperError(\"ray is required.\");\n }\n if (!defined(sphere)) {\n throw new DeveloperError(\"sphere is required.\");\n }\n //>>includeEnd('debug');\n\n result = raySphere(ray, sphere, result);\n if (!defined(result) || result.stop < 0.0) {\n return undefined;\n }\n\n result.start = Math.max(result.start, 0.0);\n return result;\n};\n\nconst scratchLineSegmentRay = new Ray();\n\n/**\n * Computes the intersection points of a line segment with a sphere.\n * @memberof IntersectionTests\n *\n * @param {Cartesian3} p0 An end point of the line segment.\n * @param {Cartesian3} p1 The other end point of the line segment.\n * @param {BoundingSphere} sphere The sphere.\n * @param {Interval} [result] The result onto which to store the result.\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\n */\nIntersectionTests.lineSegmentSphere = function (p0, p1, sphere, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(p0)) {\n throw new DeveloperError(\"p0 is required.\");\n }\n if (!defined(p1)) {\n throw new DeveloperError(\"p1 is required.\");\n }\n if (!defined(sphere)) {\n throw new DeveloperError(\"sphere is required.\");\n }\n //>>includeEnd('debug');\n\n const ray = scratchLineSegmentRay;\n Cartesian3.clone(p0, ray.origin);\n const direction = Cartesian3.subtract(p1, p0, ray.direction);\n\n const maxT = Cartesian3.magnitude(direction);\n Cartesian3.normalize(direction, direction);\n\n result = raySphere(ray, sphere, result);\n if (!defined(result) || result.stop < 0.0 || result.start > maxT) {\n return undefined;\n }\n\n result.start = Math.max(result.start, 0.0);\n result.stop = Math.min(result.stop, maxT);\n return result;\n};\n\nconst scratchQ = new Cartesian3();\nconst scratchW = new Cartesian3();\n\n/**\n * Computes the intersection points of a ray with an ellipsoid.\n *\n * @param {Ray} ray The ray.\n * @param {Ellipsoid} ellipsoid The ellipsoid.\n * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections.\n */\nIntersectionTests.rayEllipsoid = function (ray, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(ray)) {\n throw new DeveloperError(\"ray is required.\");\n }\n if (!defined(ellipsoid)) {\n throw new DeveloperError(\"ellipsoid is required.\");\n }\n //>>includeEnd('debug');\n\n const inverseRadii = ellipsoid.oneOverRadii;\n const q = Cartesian3.multiplyComponents(inverseRadii, ray.origin, scratchQ);\n const w = Cartesian3.multiplyComponents(\n inverseRadii,\n ray.direction,\n scratchW\n );\n\n const q2 = Cartesian3.magnitudeSquared(q);\n const qw = Cartesian3.dot(q, w);\n\n let difference, w2, product, discriminant, temp;\n\n if (q2 > 1.0) {\n // Outside ellipsoid.\n if (qw >= 0.0) {\n // Looking outward or tangent (0 intersections).\n return undefined;\n }\n\n // qw < 0.0.\n const qw2 = qw * qw;\n difference = q2 - 1.0; // Positively valued.\n w2 = Cartesian3.magnitudeSquared(w);\n product = w2 * difference;\n\n if (qw2 < product) {\n // Imaginary roots (0 intersections).\n return undefined;\n } else if (qw2 > product) {\n // Distinct roots (2 intersections).\n discriminant = qw * qw - product;\n temp = -qw + Math.sqrt(discriminant); // Avoid cancellation.\n const root0 = temp / w2;\n const root1 = difference / temp;\n if (root0 < root1) {\n return new Interval(root0, root1);\n }\n\n return {\n start: root1,\n stop: root0,\n };\n }\n // qw2 == product. Repeated roots (2 intersections).\n const root = Math.sqrt(difference / w2);\n return new Interval(root, root);\n } else if (q2 < 1.0) {\n // Inside ellipsoid (2 intersections).\n difference = q2 - 1.0; // Negatively valued.\n w2 = Cartesian3.magnitudeSquared(w);\n product = w2 * difference; // Negatively valued.\n\n discriminant = qw * qw - product;\n temp = -qw + Math.sqrt(discriminant); // Positively valued.\n return new Interval(0.0, temp / w2);\n }\n // q2 == 1.0. On ellipsoid.\n if (qw < 0.0) {\n // Looking inward.\n w2 = Cartesian3.magnitudeSquared(w);\n return new Interval(0.0, -qw / w2);\n }\n\n // qw >= 0.0. Looking outward or tangent.\n return undefined;\n};\n\nfunction addWithCancellationCheck(left, right, tolerance) {\n const difference = left + right;\n if (\n CesiumMath.sign(left) !== CesiumMath.sign(right) &&\n Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance\n ) {\n return 0.0;\n }\n\n return difference;\n}\n\nfunction quadraticVectorExpression(A, b, c, x, w) {\n const xSquared = x * x;\n const wSquared = w * w;\n\n const l2 = (A[Matrix3.COLUMN1ROW1] - A[Matrix3.COLUMN2ROW2]) * wSquared;\n const l1 =\n w *\n (x *\n addWithCancellationCheck(\n A[Matrix3.COLUMN1ROW0],\n A[Matrix3.COLUMN0ROW1],\n CesiumMath.EPSILON15\n ) +\n b.y);\n const l0 =\n A[Matrix3.COLUMN0ROW0] * xSquared +\n A[Matrix3.COLUMN2ROW2] * wSquared +\n x * b.x +\n c;\n\n const r1 =\n wSquared *\n addWithCancellationCheck(\n A[Matrix3.COLUMN2ROW1],\n A[Matrix3.COLUMN1ROW2],\n CesiumMath.EPSILON15\n );\n const r0 =\n w *\n (x *\n addWithCancellationCheck(A[Matrix3.COLUMN2ROW0], A[Matrix3.COLUMN0ROW2]) +\n b.z);\n\n let cosines;\n const solutions = [];\n if (r0 === 0.0 && r1 === 0.0) {\n cosines = QuadraticRealPolynomial.computeRealRoots(l2, l1, l0);\n if (cosines.length === 0) {\n return solutions;\n }\n\n const cosine0 = cosines[0];\n const sine0 = Math.sqrt(Math.max(1.0 - cosine0 * cosine0, 0.0));\n solutions.push(new Cartesian3(x, w * cosine0, w * -sine0));\n solutions.push(new Cartesian3(x, w * cosine0, w * sine0));\n\n if (cosines.length === 2) {\n const cosine1 = cosines[1];\n const sine1 = Math.sqrt(Math.max(1.0 - cosine1 * cosine1, 0.0));\n solutions.push(new Cartesian3(x, w * cosine1, w * -sine1));\n solutions.push(new Cartesian3(x, w * cosine1, w * sine1));\n }\n\n return solutions;\n }\n\n const r0Squared = r0 * r0;\n const r1Squared = r1 * r1;\n const l2Squared = l2 * l2;\n const r0r1 = r0 * r1;\n\n const c4 = l2Squared + r1Squared;\n const c3 = 2.0 * (l1 * l2 + r0r1);\n const c2 = 2.0 * l0 * l2 + l1 * l1 - r1Squared + r0Squared;\n const c1 = 2.0 * (l0 * l1 - r0r1);\n const c0 = l0 * l0 - r0Squared;\n\n if (c4 === 0.0 && c3 === 0.0 && c2 === 0.0 && c1 === 0.0) {\n return solutions;\n }\n\n cosines = QuarticRealPolynomial.computeRealRoots(c4, c3, c2, c1, c0);\n const length = cosines.length;\n if (length === 0) {\n return solutions;\n }\n\n for (let i = 0; i < length; ++i) {\n const cosine = cosines[i];\n const cosineSquared = cosine * cosine;\n const sineSquared = Math.max(1.0 - cosineSquared, 0.0);\n const sine = Math.sqrt(sineSquared);\n\n //const left = l2 * cosineSquared + l1 * cosine + l0;\n let left;\n if (CesiumMath.sign(l2) === CesiumMath.sign(l0)) {\n left = addWithCancellationCheck(\n l2 * cosineSquared + l0,\n l1 * cosine,\n CesiumMath.EPSILON12\n );\n } else if (CesiumMath.sign(l0) === CesiumMath.sign(l1 * cosine)) {\n left = addWithCancellationCheck(\n l2 * cosineSquared,\n l1 * cosine + l0,\n CesiumMath.EPSILON12\n );\n } else {\n left = addWithCancellationCheck(\n l2 * cosineSquared + l1 * cosine,\n l0,\n CesiumMath.EPSILON12\n );\n }\n\n const right = addWithCancellationCheck(\n r1 * cosine,\n r0,\n CesiumMath.EPSILON15\n );\n const product = left * right;\n\n if (product < 0.0) {\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\n } else if (product > 0.0) {\n solutions.push(new Cartesian3(x, w * cosine, w * -sine));\n } else if (sine !== 0.0) {\n solutions.push(new Cartesian3(x, w * cosine, w * -sine));\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\n ++i;\n } else {\n solutions.push(new Cartesian3(x, w * cosine, w * sine));\n }\n }\n\n return solutions;\n}\n\nconst firstAxisScratch = new Cartesian3();\nconst secondAxisScratch = new Cartesian3();\nconst thirdAxisScratch = new Cartesian3();\nconst referenceScratch = new Cartesian3();\nconst bCart = new Cartesian3();\nconst bScratch = new Matrix3();\nconst btScratch = new Matrix3();\nconst diScratch = new Matrix3();\nconst dScratch = new Matrix3();\nconst cScratch = new Matrix3();\nconst tempMatrix = new Matrix3();\nconst aScratch = new Matrix3();\nconst sScratch = new Cartesian3();\nconst closestScratch = new Cartesian3();\nconst surfPointScratch = new Cartographic();\n\n/**\n * Provides the point along the ray which is nearest to the ellipsoid.\n *\n * @param {Ray} ray The ray.\n * @param {Ellipsoid} ellipsoid The ellipsoid.\n * @returns {Cartesian3} The nearest planetodetic point on the ray.\n */\nIntersectionTests.grazingAltitudeLocation = function (ray, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(ray)) {\n throw new DeveloperError(\"ray is required.\");\n }\n if (!defined(ellipsoid)) {\n throw new DeveloperError(\"ellipsoid is required.\");\n }\n //>>includeEnd('debug');\n\n const position = ray.origin;\n const direction = ray.direction;\n\n if (!Cartesian3.equals(position, Cartesian3.ZERO)) {\n const normal = ellipsoid.geodeticSurfaceNormal(position, firstAxisScratch);\n if (Cartesian3.dot(direction, normal) >= 0.0) {\n // The location provided is the closest point in altitude\n return position;\n }\n }\n\n const intersects = defined(this.rayEllipsoid(ray, ellipsoid));\n\n // Compute the scaled direction vector.\n const f = ellipsoid.transformPositionToScaledSpace(\n direction,\n firstAxisScratch\n );\n\n // Constructs a basis from the unit scaled direction vector. Construct its rotation and transpose.\n const firstAxis = Cartesian3.normalize(f, f);\n const reference = Cartesian3.mostOrthogonalAxis(f, referenceScratch);\n const secondAxis = Cartesian3.normalize(\n Cartesian3.cross(reference, firstAxis, secondAxisScratch),\n secondAxisScratch\n );\n const thirdAxis = Cartesian3.normalize(\n Cartesian3.cross(firstAxis, secondAxis, thirdAxisScratch),\n thirdAxisScratch\n );\n const B = bScratch;\n B[0] = firstAxis.x;\n B[1] = firstAxis.y;\n B[2] = firstAxis.z;\n B[3] = secondAxis.x;\n B[4] = secondAxis.y;\n B[5] = secondAxis.z;\n B[6] = thirdAxis.x;\n B[7] = thirdAxis.y;\n B[8] = thirdAxis.z;\n\n const B_T = Matrix3.transpose(B, btScratch);\n\n // Get the scaling matrix and its inverse.\n const D_I = Matrix3.fromScale(ellipsoid.radii, diScratch);\n const D = Matrix3.fromScale(ellipsoid.oneOverRadii, dScratch);\n\n const C = cScratch;\n C[0] = 0.0;\n C[1] = -direction.z;\n C[2] = direction.y;\n C[3] = direction.z;\n C[4] = 0.0;\n C[5] = -direction.x;\n C[6] = -direction.y;\n C[7] = direction.x;\n C[8] = 0.0;\n\n const temp = Matrix3.multiply(\n Matrix3.multiply(B_T, D, tempMatrix),\n C,\n tempMatrix\n );\n const A = Matrix3.multiply(\n Matrix3.multiply(temp, D_I, aScratch),\n B,\n aScratch\n );\n const b = Matrix3.multiplyByVector(temp, position, bCart);\n\n // Solve for the solutions to the expression in standard form:\n const solutions = quadraticVectorExpression(\n A,\n Cartesian3.negate(b, firstAxisScratch),\n 0.0,\n 0.0,\n 1.0\n );\n\n let s;\n let altitude;\n const length = solutions.length;\n if (length > 0) {\n let closest = Cartesian3.clone(Cartesian3.ZERO, closestScratch);\n let maximumValue = Number.NEGATIVE_INFINITY;\n\n for (let i = 0; i < length; ++i) {\n s = Matrix3.multiplyByVector(\n D_I,\n Matrix3.multiplyByVector(B, solutions[i], sScratch),\n sScratch\n );\n const v = Cartesian3.normalize(\n Cartesian3.subtract(s, position, referenceScratch),\n referenceScratch\n );\n const dotProduct = Cartesian3.dot(v, direction);\n\n if (dotProduct > maximumValue) {\n maximumValue = dotProduct;\n closest = Cartesian3.clone(s, closest);\n }\n }\n\n const surfacePoint = ellipsoid.cartesianToCartographic(\n closest,\n surfPointScratch\n );\n maximumValue = CesiumMath.clamp(maximumValue, 0.0, 1.0);\n altitude =\n Cartesian3.magnitude(\n Cartesian3.subtract(closest, position, referenceScratch)\n ) * Math.sqrt(1.0 - maximumValue * maximumValue);\n altitude = intersects ? -altitude : altitude;\n surfacePoint.height = altitude;\n return ellipsoid.cartographicToCartesian(surfacePoint, new Cartesian3());\n }\n\n return undefined;\n};\n\nconst lineSegmentPlaneDifference = new Cartesian3();\n\n/**\n * Computes the intersection of a line segment and a plane.\n *\n * @param {Cartesian3} endPoint0 An end point of the line segment.\n * @param {Cartesian3} endPoint1 The other end point of the line segment.\n * @param {Plane} plane The plane.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The intersection point or undefined if there is no intersection.\n *\n * @example\n * const origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\n * const normal = ellipsoid.geodeticSurfaceNormal(origin);\n * const plane = Cesium.Plane.fromPointNormal(origin, normal);\n *\n * const p0 = new Cesium.Cartesian3(...);\n * const p1 = new Cesium.Cartesian3(...);\n *\n * // find the intersection of the line segment from p0 to p1 and the tangent plane at origin.\n * const intersection = Cesium.IntersectionTests.lineSegmentPlane(p0, p1, plane);\n */\nIntersectionTests.lineSegmentPlane = function (\n endPoint0,\n endPoint1,\n plane,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(endPoint0)) {\n throw new DeveloperError(\"endPoint0 is required.\");\n }\n if (!defined(endPoint1)) {\n throw new DeveloperError(\"endPoint1 is required.\");\n }\n if (!defined(plane)) {\n throw new DeveloperError(\"plane is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const difference = Cartesian3.subtract(\n endPoint1,\n endPoint0,\n lineSegmentPlaneDifference\n );\n const normal = plane.normal;\n const nDotDiff = Cartesian3.dot(normal, difference);\n\n // check if the segment and plane are parallel\n if (Math.abs(nDotDiff) < CesiumMath.EPSILON6) {\n return undefined;\n }\n\n const nDotP0 = Cartesian3.dot(normal, endPoint0);\n const t = -(plane.distance + nDotP0) / nDotDiff;\n\n // intersection only if t is in [0, 1]\n if (t < 0.0 || t > 1.0) {\n return undefined;\n }\n\n // intersection is endPoint0 + t * (endPoint1 - endPoint0)\n Cartesian3.multiplyByScalar(difference, t, result);\n Cartesian3.add(endPoint0, result, result);\n return result;\n};\n\n/**\n * Computes the intersection of a triangle and a plane\n *\n * @param {Cartesian3} p0 First point of the triangle\n * @param {Cartesian3} p1 Second point of the triangle\n * @param {Cartesian3} p2 Third point of the triangle\n * @param {Plane} plane Intersection plane\n * @returns {object} An object with properties positions and indices, which are arrays that represent three triangles that do not cross the plane. (Undefined if no intersection exists)\n *\n * @example\n * const origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\n * const normal = ellipsoid.geodeticSurfaceNormal(origin);\n * const plane = Cesium.Plane.fromPointNormal(origin, normal);\n *\n * const p0 = new Cesium.Cartesian3(...);\n * const p1 = new Cesium.Cartesian3(...);\n * const p2 = new Cesium.Cartesian3(...);\n *\n * // convert the triangle composed of points (p0, p1, p2) to three triangles that don't cross the plane\n * const triangles = Cesium.IntersectionTests.trianglePlaneIntersection(p0, p1, p2, plane);\n */\nIntersectionTests.trianglePlaneIntersection = function (p0, p1, p2, plane) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(p0) || !defined(p1) || !defined(p2) || !defined(plane)) {\n throw new DeveloperError(\"p0, p1, p2, and plane are required.\");\n }\n //>>includeEnd('debug');\n\n const planeNormal = plane.normal;\n const planeD = plane.distance;\n const p0Behind = Cartesian3.dot(planeNormal, p0) + planeD < 0.0;\n const p1Behind = Cartesian3.dot(planeNormal, p1) + planeD < 0.0;\n const p2Behind = Cartesian3.dot(planeNormal, p2) + planeD < 0.0;\n // Given these dots products, the calls to lineSegmentPlaneIntersection\n // always have defined results.\n\n let numBehind = 0;\n numBehind += p0Behind ? 1 : 0;\n numBehind += p1Behind ? 1 : 0;\n numBehind += p2Behind ? 1 : 0;\n\n let u1, u2;\n if (numBehind === 1 || numBehind === 2) {\n u1 = new Cartesian3();\n u2 = new Cartesian3();\n }\n\n if (numBehind === 1) {\n if (p0Behind) {\n IntersectionTests.lineSegmentPlane(p0, p1, plane, u1);\n IntersectionTests.lineSegmentPlane(p0, p2, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 0,\n 3,\n 4,\n\n // In front\n 1,\n 2,\n 4,\n 1,\n 4,\n 3,\n ],\n };\n } else if (p1Behind) {\n IntersectionTests.lineSegmentPlane(p1, p2, plane, u1);\n IntersectionTests.lineSegmentPlane(p1, p0, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 1,\n 3,\n 4,\n\n // In front\n 2,\n 0,\n 4,\n 2,\n 4,\n 3,\n ],\n };\n } else if (p2Behind) {\n IntersectionTests.lineSegmentPlane(p2, p0, plane, u1);\n IntersectionTests.lineSegmentPlane(p2, p1, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 2,\n 3,\n 4,\n\n // In front\n 0,\n 1,\n 4,\n 0,\n 4,\n 3,\n ],\n };\n }\n } else if (numBehind === 2) {\n if (!p0Behind) {\n IntersectionTests.lineSegmentPlane(p1, p0, plane, u1);\n IntersectionTests.lineSegmentPlane(p2, p0, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 1,\n 2,\n 4,\n 1,\n 4,\n 3,\n\n // In front\n 0,\n 3,\n 4,\n ],\n };\n } else if (!p1Behind) {\n IntersectionTests.lineSegmentPlane(p2, p1, plane, u1);\n IntersectionTests.lineSegmentPlane(p0, p1, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 2,\n 0,\n 4,\n 2,\n 4,\n 3,\n\n // In front\n 1,\n 3,\n 4,\n ],\n };\n } else if (!p2Behind) {\n IntersectionTests.lineSegmentPlane(p0, p2, plane, u1);\n IntersectionTests.lineSegmentPlane(p1, p2, plane, u2);\n\n return {\n positions: [p0, p1, p2, u1, u2],\n indices: [\n // Behind\n 0,\n 1,\n 4,\n 0,\n 4,\n 3,\n\n // In front\n 2,\n 3,\n 4,\n ],\n };\n }\n }\n\n // if numBehind is 3, the triangle is completely behind the plane;\n // otherwise, it is completely in front (numBehind is 0).\n return undefined;\n};\nexport default IntersectionTests;\n", "import AxisAlignedBoundingBox from \"./AxisAlignedBoundingBox.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport IntersectionTests from \"./IntersectionTests.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Plane from \"./Plane.js\";\nimport Ray from \"./Ray.js\";\nimport Transforms from \"./Transforms.js\";\n\nconst scratchCart4 = new Cartesian4();\n/**\n * A plane tangent to the provided ellipsoid at the provided origin.\n * If origin is not on the surface of the ellipsoid, it's surface projection will be used.\n * If origin is at the center of the ellipsoid, an exception will be thrown.\n * @alias EllipsoidTangentPlane\n * @constructor\n *\n * @param {Cartesian3} origin The point on the surface of the ellipsoid where the tangent plane touches.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\n *\n * @exception {DeveloperError} origin must not be at the center of the ellipsoid.\n */\nfunction EllipsoidTangentPlane(origin, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"origin\", origin);\n //>>includeEnd('debug');\n\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n origin = ellipsoid.scaleToGeodeticSurface(origin);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(origin)) {\n throw new DeveloperError(\n \"origin must not be at the center of the ellipsoid.\"\n );\n }\n //>>includeEnd('debug');\n\n const eastNorthUp = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);\n this._ellipsoid = ellipsoid;\n this._origin = origin;\n this._xAxis = Cartesian3.fromCartesian4(\n Matrix4.getColumn(eastNorthUp, 0, scratchCart4)\n );\n this._yAxis = Cartesian3.fromCartesian4(\n Matrix4.getColumn(eastNorthUp, 1, scratchCart4)\n );\n\n const normal = Cartesian3.fromCartesian4(\n Matrix4.getColumn(eastNorthUp, 2, scratchCart4)\n );\n this._plane = Plane.fromPointNormal(origin, normal);\n}\n\nObject.defineProperties(EllipsoidTangentPlane.prototype, {\n /**\n * Gets the ellipsoid.\n * @memberof EllipsoidTangentPlane.prototype\n * @type {Ellipsoid}\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n\n /**\n * Gets the origin.\n * @memberof EllipsoidTangentPlane.prototype\n * @type {Cartesian3}\n */\n origin: {\n get: function () {\n return this._origin;\n },\n },\n\n /**\n * Gets the plane which is tangent to the ellipsoid.\n * @memberof EllipsoidTangentPlane.prototype\n * @readonly\n * @type {Plane}\n */\n plane: {\n get: function () {\n return this._plane;\n },\n },\n\n /**\n * Gets the local X-axis (east) of the tangent plane.\n * @memberof EllipsoidTangentPlane.prototype\n * @readonly\n * @type {Cartesian3}\n */\n xAxis: {\n get: function () {\n return this._xAxis;\n },\n },\n\n /**\n * Gets the local Y-axis (north) of the tangent plane.\n * @memberof EllipsoidTangentPlane.prototype\n * @readonly\n * @type {Cartesian3}\n */\n yAxis: {\n get: function () {\n return this._yAxis;\n },\n },\n\n /**\n * Gets the local Z-axis (up) of the tangent plane.\n * @memberof EllipsoidTangentPlane.prototype\n * @readonly\n * @type {Cartesian3}\n */\n zAxis: {\n get: function () {\n return this._plane.normal;\n },\n },\n});\n\nconst tmp = new AxisAlignedBoundingBox();\n/**\n * Creates a new instance from the provided ellipsoid and the center\n * point of the provided Cartesians.\n *\n * @param {Cartesian3[]} cartesians The list of positions surrounding the center point.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.\n * @returns {EllipsoidTangentPlane} The new instance of EllipsoidTangentPlane.\n */\nEllipsoidTangentPlane.fromPoints = function (cartesians, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n\n const box = AxisAlignedBoundingBox.fromPoints(cartesians, tmp);\n return new EllipsoidTangentPlane(box.center, ellipsoid);\n};\n\nconst scratchProjectPointOntoPlaneRay = new Ray();\nconst scratchProjectPointOntoPlaneCartesian3 = new Cartesian3();\n\n/**\n * Computes the projection of the provided 3D position onto the 2D plane, radially outward from the {@link EllipsoidTangentPlane.ellipsoid} coordinate system origin.\n *\n * @param {Cartesian3} cartesian The point to project.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided. Undefined if there is no intersection point\n */\nEllipsoidTangentPlane.prototype.projectPointOntoPlane = function (\n cartesian,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n const ray = scratchProjectPointOntoPlaneRay;\n ray.origin = cartesian;\n Cartesian3.normalize(cartesian, ray.direction);\n\n let intersectionPoint = IntersectionTests.rayPlane(\n ray,\n this._plane,\n scratchProjectPointOntoPlaneCartesian3\n );\n if (!defined(intersectionPoint)) {\n Cartesian3.negate(ray.direction, ray.direction);\n intersectionPoint = IntersectionTests.rayPlane(\n ray,\n this._plane,\n scratchProjectPointOntoPlaneCartesian3\n );\n }\n\n if (defined(intersectionPoint)) {\n const v = Cartesian3.subtract(\n intersectionPoint,\n this._origin,\n intersectionPoint\n );\n const x = Cartesian3.dot(this._xAxis, v);\n const y = Cartesian3.dot(this._yAxis, v);\n\n if (!defined(result)) {\n return new Cartesian2(x, y);\n }\n result.x = x;\n result.y = y;\n return result;\n }\n return undefined;\n};\n\n/**\n * Computes the projection of the provided 3D positions onto the 2D plane (where possible), radially outward from the global origin.\n * The resulting array may be shorter than the input array - if a single projection is impossible it will not be included.\n *\n * @see EllipsoidTangentPlane.projectPointOntoPlane\n *\n * @param {Cartesian3[]} cartesians The array of points to project.\n * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.\n * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided.\n */\nEllipsoidTangentPlane.prototype.projectPointsOntoPlane = function (\n cartesians,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = [];\n }\n\n let count = 0;\n const length = cartesians.length;\n for (let i = 0; i < length; i++) {\n const p = this.projectPointOntoPlane(cartesians[i], result[count]);\n if (defined(p)) {\n result[count] = p;\n count++;\n }\n }\n result.length = count;\n return result;\n};\n\n/**\n * Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.\n *\n * @param {Cartesian3} cartesian The point to project.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.\n */\nEllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function (\n cartesian,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian2();\n }\n\n const ray = scratchProjectPointOntoPlaneRay;\n ray.origin = cartesian;\n Cartesian3.clone(this._plane.normal, ray.direction);\n\n let intersectionPoint = IntersectionTests.rayPlane(\n ray,\n this._plane,\n scratchProjectPointOntoPlaneCartesian3\n );\n if (!defined(intersectionPoint)) {\n Cartesian3.negate(ray.direction, ray.direction);\n intersectionPoint = IntersectionTests.rayPlane(\n ray,\n this._plane,\n scratchProjectPointOntoPlaneCartesian3\n );\n }\n\n const v = Cartesian3.subtract(\n intersectionPoint,\n this._origin,\n intersectionPoint\n );\n const x = Cartesian3.dot(this._xAxis, v);\n const y = Cartesian3.dot(this._yAxis, v);\n\n result.x = x;\n result.y = y;\n return result;\n};\n\n/**\n * Computes the projection of the provided 3D positions onto the 2D plane, along the plane normal.\n *\n * @see EllipsoidTangentPlane.projectPointToNearestOnPlane\n *\n * @param {Cartesian3[]} cartesians The array of points to project.\n * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.\n * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided. This will have the same length as cartesians.\n */\nEllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function (\n cartesians,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = [];\n }\n\n const length = cartesians.length;\n result.length = length;\n for (let i = 0; i < length; i++) {\n result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);\n }\n return result;\n};\n\nconst projectPointsOntoEllipsoidScratch = new Cartesian3();\n/**\n * Computes the projection of the provided 2D position onto the 3D ellipsoid.\n *\n * @param {Cartesian2} cartesian The points to project.\n * @param {Cartesian3} [result] The Cartesian3 instance to store result.\n * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.\n */\nEllipsoidTangentPlane.prototype.projectPointOntoEllipsoid = function (\n cartesian,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesian\", cartesian);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const ellipsoid = this._ellipsoid;\n const origin = this._origin;\n const xAxis = this._xAxis;\n const yAxis = this._yAxis;\n const tmp = projectPointsOntoEllipsoidScratch;\n\n Cartesian3.multiplyByScalar(xAxis, cartesian.x, tmp);\n result = Cartesian3.add(origin, tmp, result);\n Cartesian3.multiplyByScalar(yAxis, cartesian.y, tmp);\n Cartesian3.add(result, tmp, result);\n ellipsoid.scaleToGeocentricSurface(result, result);\n\n return result;\n};\n\n/**\n * Computes the projection of the provided 2D positions onto the 3D ellipsoid.\n *\n * @param {Cartesian2[]} cartesians The array of points to project.\n * @param {Cartesian3[]} [result] The array of Cartesian3 instances onto which to store results.\n * @returns {Cartesian3[]} The modified result parameter or a new array of Cartesian3 instances if none was provided.\n */\nEllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function (\n cartesians,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"cartesians\", cartesians);\n //>>includeEnd('debug');\n\n const length = cartesians.length;\n if (!defined(result)) {\n result = new Array(length);\n } else {\n result.length = length;\n }\n\n for (let i = 0; i < length; ++i) {\n result[i] = this.projectPointOntoEllipsoid(cartesians[i], result[i]);\n }\n\n return result;\n};\nexport default EllipsoidTangentPlane;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidTangentPlane from \"./EllipsoidTangentPlane.js\";\nimport Intersect from \"./Intersect.js\";\nimport Interval from \"./Interval.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Plane from \"./Plane.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * Creates an instance of an OrientedBoundingBox.\n * An OrientedBoundingBox of some object is a closed and convex rectangular cuboid. It can provide a tighter bounding volume than {@link BoundingSphere} or {@link AxisAlignedBoundingBox} in many cases.\n * @alias OrientedBoundingBox\n * @constructor\n *\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the box.\n * @param {Matrix3} [halfAxes=Matrix3.ZERO] The three orthogonal half-axes of the bounding box.\n * Equivalently, the transformation matrix, to rotate and scale a 2x2x2\n * cube centered at the origin.\n *\n *\n * @example\n * // Create an OrientedBoundingBox using a transformation matrix, a position where the box will be translated, and a scale.\n * const center = new Cesium.Cartesian3(1.0, 0.0, 0.0);\n * const halfAxes = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(1.0, 3.0, 2.0), new Cesium.Matrix3());\n *\n * const obb = new Cesium.OrientedBoundingBox(center, halfAxes);\n *\n * @see BoundingSphere\n * @see BoundingRectangle\n */\nfunction OrientedBoundingBox(center, halfAxes) {\n /**\n * The center of the box.\n * @type {Cartesian3}\n * @default {@link Cartesian3.ZERO}\n */\n this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));\n /**\n * The three orthogonal half-axes of the bounding box. Equivalently, the\n * transformation matrix, to rotate and scale a 2x2x2 cube centered at the\n * origin.\n * @type {Matrix3}\n * @default {@link Matrix3.ZERO}\n */\n this.halfAxes = Matrix3.clone(defaultValue(halfAxes, Matrix3.ZERO));\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nOrientedBoundingBox.packedLength =\n Cartesian3.packedLength + Matrix3.packedLength;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {OrientedBoundingBox} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nOrientedBoundingBox.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value.center, array, startingIndex);\n Matrix3.pack(value.halfAxes, array, startingIndex + Cartesian3.packedLength);\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {OrientedBoundingBox} [result] The object into which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\n */\nOrientedBoundingBox.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n if (!defined(result)) {\n result = new OrientedBoundingBox();\n }\n\n Cartesian3.unpack(array, startingIndex, result.center);\n Matrix3.unpack(\n array,\n startingIndex + Cartesian3.packedLength,\n result.halfAxes\n );\n return result;\n};\n\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartesian3 = new Cartesian3();\nconst scratchCartesian4 = new Cartesian3();\nconst scratchCartesian5 = new Cartesian3();\nconst scratchCartesian6 = new Cartesian3();\nconst scratchCovarianceResult = new Matrix3();\nconst scratchEigenResult = {\n unitary: new Matrix3(),\n diagonal: new Matrix3(),\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n *\n * @param {Cartesian3[]} [positions] List of {@link Cartesian3} points that the bounding box will enclose.\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\n *\n * @example\n * // Compute an object oriented bounding box enclosing two points.\n * const box = Cesium.OrientedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);\n */\nOrientedBoundingBox.fromPoints = function (positions, result) {\n if (!defined(result)) {\n result = new OrientedBoundingBox();\n }\n\n if (!defined(positions) || positions.length === 0) {\n result.halfAxes = Matrix3.ZERO;\n result.center = Cartesian3.ZERO;\n return result;\n }\n\n let i;\n const length = positions.length;\n\n const meanPoint = Cartesian3.clone(positions[0], scratchCartesian1);\n for (i = 1; i < length; i++) {\n Cartesian3.add(meanPoint, positions[i], meanPoint);\n }\n const invLength = 1.0 / length;\n Cartesian3.multiplyByScalar(meanPoint, invLength, meanPoint);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n let p;\n\n for (i = 0; i < length; i++) {\n p = Cartesian3.subtract(positions[i], meanPoint, scratchCartesian2);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const eigenDecomposition = Matrix3.computeEigenDecomposition(\n covarianceMatrix,\n scratchEigenResult\n );\n const rotation = Matrix3.clone(eigenDecomposition.unitary, result.halfAxes);\n\n let v1 = Matrix3.getColumn(rotation, 0, scratchCartesian4);\n let v2 = Matrix3.getColumn(rotation, 1, scratchCartesian5);\n let v3 = Matrix3.getColumn(rotation, 2, scratchCartesian6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (i = 0; i < length; i++) {\n p = positions[i];\n u1 = Math.max(Cartesian3.dot(v1, p), u1);\n u2 = Math.max(Cartesian3.dot(v2, p), u2);\n u3 = Math.max(Cartesian3.dot(v3, p), u3);\n\n l1 = Math.min(Cartesian3.dot(v1, p), l1);\n l2 = Math.min(Cartesian3.dot(v2, p), l2);\n l3 = Math.min(Cartesian3.dot(v3, p), l3);\n }\n\n v1 = Cartesian3.multiplyByScalar(v1, 0.5 * (l1 + u1), v1);\n v2 = Cartesian3.multiplyByScalar(v2, 0.5 * (l2 + u2), v2);\n v3 = Cartesian3.multiplyByScalar(v3, 0.5 * (l3 + u3), v3);\n\n const center = Cartesian3.add(v1, v2, result.center);\n Cartesian3.add(center, v3, center);\n\n const scale = scratchCartesian3;\n scale.x = u1 - l1;\n scale.y = u2 - l2;\n scale.z = u3 - l3;\n Cartesian3.multiplyByScalar(scale, 0.5, scale);\n Matrix3.multiplyByScale(result.halfAxes, scale, result.halfAxes);\n\n return result;\n};\n\nconst scratchOffset = new Cartesian3();\nconst scratchScale = new Cartesian3();\nfunction fromPlaneExtents(\n planeOrigin,\n planeXAxis,\n planeYAxis,\n planeZAxis,\n minimumX,\n maximumX,\n minimumY,\n maximumY,\n minimumZ,\n maximumZ,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(minimumX) ||\n !defined(maximumX) ||\n !defined(minimumY) ||\n !defined(maximumY) ||\n !defined(minimumZ) ||\n !defined(maximumZ)\n ) {\n throw new DeveloperError(\n \"all extents (minimum/maximum X/Y/Z) are required.\"\n );\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new OrientedBoundingBox();\n }\n\n const halfAxes = result.halfAxes;\n Matrix3.setColumn(halfAxes, 0, planeXAxis, halfAxes);\n Matrix3.setColumn(halfAxes, 1, planeYAxis, halfAxes);\n Matrix3.setColumn(halfAxes, 2, planeZAxis, halfAxes);\n\n let centerOffset = scratchOffset;\n centerOffset.x = (minimumX + maximumX) / 2.0;\n centerOffset.y = (minimumY + maximumY) / 2.0;\n centerOffset.z = (minimumZ + maximumZ) / 2.0;\n\n const scale = scratchScale;\n scale.x = (maximumX - minimumX) / 2.0;\n scale.y = (maximumY - minimumY) / 2.0;\n scale.z = (maximumZ - minimumZ) / 2.0;\n\n const center = result.center;\n centerOffset = Matrix3.multiplyByVector(halfAxes, centerOffset, centerOffset);\n Cartesian3.add(planeOrigin, centerOffset, center);\n Matrix3.multiplyByScale(halfAxes, scale, halfAxes);\n\n return result;\n}\n\nconst scratchRectangleCenterCartographic = new Cartographic();\nconst scratchRectangleCenter = new Cartesian3();\nconst scratchPerimeterCartographicNC = new Cartographic();\nconst scratchPerimeterCartographicNW = new Cartographic();\nconst scratchPerimeterCartographicCW = new Cartographic();\nconst scratchPerimeterCartographicSW = new Cartographic();\nconst scratchPerimeterCartographicSC = new Cartographic();\nconst scratchPerimeterCartesianNC = new Cartesian3();\nconst scratchPerimeterCartesianNW = new Cartesian3();\nconst scratchPerimeterCartesianCW = new Cartesian3();\nconst scratchPerimeterCartesianSW = new Cartesian3();\nconst scratchPerimeterCartesianSC = new Cartesian3();\nconst scratchPerimeterProjectedNC = new Cartesian2();\nconst scratchPerimeterProjectedNW = new Cartesian2();\nconst scratchPerimeterProjectedCW = new Cartesian2();\nconst scratchPerimeterProjectedSW = new Cartesian2();\nconst scratchPerimeterProjectedSC = new Cartesian2();\n\nconst scratchPlaneOrigin = new Cartesian3();\nconst scratchPlaneNormal = new Cartesian3();\nconst scratchPlaneXAxis = new Cartesian3();\nconst scratchHorizonCartesian = new Cartesian3();\nconst scratchHorizonProjected = new Cartesian2();\nconst scratchMaxY = new Cartesian3();\nconst scratchMinY = new Cartesian3();\nconst scratchZ = new Cartesian3();\nconst scratchPlane = new Plane(Cartesian3.UNIT_X, 0.0);\n\n/**\n * Computes an OrientedBoundingBox that bounds a {@link Rectangle} on the surface of an {@link Ellipsoid}.\n * There are no guarantees about the orientation of the bounding box.\n *\n * @param {Rectangle} rectangle The cartographic rectangle on the surface of the ellipsoid.\n * @param {number} [minimumHeight=0.0] The minimum height (elevation) within the tile.\n * @param {number} [maximumHeight=0.0] The maximum height (elevation) within the tile.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle is defined.\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if none was provided.\n *\n * @exception {DeveloperError} rectangle.width must be between 0 and 2 * pi.\n * @exception {DeveloperError} rectangle.height must be between 0 and pi.\n * @exception {DeveloperError} ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n */\nOrientedBoundingBox.fromRectangle = function (\n rectangle,\n minimumHeight,\n maximumHeight,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(rectangle)) {\n throw new DeveloperError(\"rectangle is required\");\n }\n if (rectangle.width < 0.0 || rectangle.width > CesiumMath.TWO_PI) {\n throw new DeveloperError(\"Rectangle width must be between 0 and 2 * pi\");\n }\n if (rectangle.height < 0.0 || rectangle.height > CesiumMath.PI) {\n throw new DeveloperError(\"Rectangle height must be between 0 and pi\");\n }\n if (\n defined(ellipsoid) &&\n !CesiumMath.equalsEpsilon(\n ellipsoid.radii.x,\n ellipsoid.radii.y,\n CesiumMath.EPSILON15\n )\n ) {\n throw new DeveloperError(\n \"Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\"\n );\n }\n //>>includeEnd('debug');\n\n minimumHeight = defaultValue(minimumHeight, 0.0);\n maximumHeight = defaultValue(maximumHeight, 0.0);\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n let minX, maxX, minY, maxY, minZ, maxZ, plane;\n\n if (rectangle.width <= CesiumMath.PI) {\n // The bounding box will be aligned with the tangent plane at the center of the rectangle.\n const tangentPointCartographic = Rectangle.center(\n rectangle,\n scratchRectangleCenterCartographic\n );\n const tangentPoint = ellipsoid.cartographicToCartesian(\n tangentPointCartographic,\n scratchRectangleCenter\n );\n const tangentPlane = new EllipsoidTangentPlane(tangentPoint, ellipsoid);\n plane = tangentPlane.plane;\n\n // If the rectangle spans the equator, CW is instead aligned with the equator (because it sticks out the farthest at the equator).\n const lonCenter = tangentPointCartographic.longitude;\n const latCenter =\n rectangle.south < 0.0 && rectangle.north > 0.0\n ? 0.0\n : tangentPointCartographic.latitude;\n\n // Compute XY extents using the rectangle at maximum height\n const perimeterCartographicNC = Cartographic.fromRadians(\n lonCenter,\n rectangle.north,\n maximumHeight,\n scratchPerimeterCartographicNC\n );\n const perimeterCartographicNW = Cartographic.fromRadians(\n rectangle.west,\n rectangle.north,\n maximumHeight,\n scratchPerimeterCartographicNW\n );\n const perimeterCartographicCW = Cartographic.fromRadians(\n rectangle.west,\n latCenter,\n maximumHeight,\n scratchPerimeterCartographicCW\n );\n const perimeterCartographicSW = Cartographic.fromRadians(\n rectangle.west,\n rectangle.south,\n maximumHeight,\n scratchPerimeterCartographicSW\n );\n const perimeterCartographicSC = Cartographic.fromRadians(\n lonCenter,\n rectangle.south,\n maximumHeight,\n scratchPerimeterCartographicSC\n );\n\n const perimeterCartesianNC = ellipsoid.cartographicToCartesian(\n perimeterCartographicNC,\n scratchPerimeterCartesianNC\n );\n let perimeterCartesianNW = ellipsoid.cartographicToCartesian(\n perimeterCartographicNW,\n scratchPerimeterCartesianNW\n );\n const perimeterCartesianCW = ellipsoid.cartographicToCartesian(\n perimeterCartographicCW,\n scratchPerimeterCartesianCW\n );\n let perimeterCartesianSW = ellipsoid.cartographicToCartesian(\n perimeterCartographicSW,\n scratchPerimeterCartesianSW\n );\n const perimeterCartesianSC = ellipsoid.cartographicToCartesian(\n perimeterCartographicSC,\n scratchPerimeterCartesianSC\n );\n\n const perimeterProjectedNC = tangentPlane.projectPointToNearestOnPlane(\n perimeterCartesianNC,\n scratchPerimeterProjectedNC\n );\n const perimeterProjectedNW = tangentPlane.projectPointToNearestOnPlane(\n perimeterCartesianNW,\n scratchPerimeterProjectedNW\n );\n const perimeterProjectedCW = tangentPlane.projectPointToNearestOnPlane(\n perimeterCartesianCW,\n scratchPerimeterProjectedCW\n );\n const perimeterProjectedSW = tangentPlane.projectPointToNearestOnPlane(\n perimeterCartesianSW,\n scratchPerimeterProjectedSW\n );\n const perimeterProjectedSC = tangentPlane.projectPointToNearestOnPlane(\n perimeterCartesianSC,\n scratchPerimeterProjectedSC\n );\n\n minX = Math.min(\n perimeterProjectedNW.x,\n perimeterProjectedCW.x,\n perimeterProjectedSW.x\n );\n maxX = -minX; // symmetrical\n\n maxY = Math.max(perimeterProjectedNW.y, perimeterProjectedNC.y);\n minY = Math.min(perimeterProjectedSW.y, perimeterProjectedSC.y);\n\n // Compute minimum Z using the rectangle at minimum height, since it will be deeper than the maximum height\n perimeterCartographicNW.height = perimeterCartographicSW.height = minimumHeight;\n perimeterCartesianNW = ellipsoid.cartographicToCartesian(\n perimeterCartographicNW,\n scratchPerimeterCartesianNW\n );\n perimeterCartesianSW = ellipsoid.cartographicToCartesian(\n perimeterCartographicSW,\n scratchPerimeterCartesianSW\n );\n\n minZ = Math.min(\n Plane.getPointDistance(plane, perimeterCartesianNW),\n Plane.getPointDistance(plane, perimeterCartesianSW)\n );\n maxZ = maximumHeight; // Since the tangent plane touches the surface at height = 0, this is okay\n\n return fromPlaneExtents(\n tangentPlane.origin,\n tangentPlane.xAxis,\n tangentPlane.yAxis,\n tangentPlane.zAxis,\n minX,\n maxX,\n minY,\n maxY,\n minZ,\n maxZ,\n result\n );\n }\n\n // Handle the case where rectangle width is greater than PI (wraps around more than half the ellipsoid).\n const fullyAboveEquator = rectangle.south > 0.0;\n const fullyBelowEquator = rectangle.north < 0.0;\n const latitudeNearestToEquator = fullyAboveEquator\n ? rectangle.south\n : fullyBelowEquator\n ? rectangle.north\n : 0.0;\n const centerLongitude = Rectangle.center(\n rectangle,\n scratchRectangleCenterCartographic\n ).longitude;\n\n // Plane is located at the rectangle's center longitude and the rectangle's latitude that is closest to the equator. It rotates around the Z axis.\n // This results in a better fit than the obb approach for smaller rectangles, which orients with the rectangle's center normal.\n const planeOrigin = Cartesian3.fromRadians(\n centerLongitude,\n latitudeNearestToEquator,\n maximumHeight,\n ellipsoid,\n scratchPlaneOrigin\n );\n planeOrigin.z = 0.0; // center the plane on the equator to simpify plane normal calculation\n const isPole =\n Math.abs(planeOrigin.x) < CesiumMath.EPSILON10 &&\n Math.abs(planeOrigin.y) < CesiumMath.EPSILON10;\n const planeNormal = !isPole\n ? Cartesian3.normalize(planeOrigin, scratchPlaneNormal)\n : Cartesian3.UNIT_X;\n const planeYAxis = Cartesian3.UNIT_Z;\n const planeXAxis = Cartesian3.cross(\n planeNormal,\n planeYAxis,\n scratchPlaneXAxis\n );\n plane = Plane.fromPointNormal(planeOrigin, planeNormal, scratchPlane);\n\n // Get the horizon point relative to the center. This will be the farthest extent in the plane's X dimension.\n const horizonCartesian = Cartesian3.fromRadians(\n centerLongitude + CesiumMath.PI_OVER_TWO,\n latitudeNearestToEquator,\n maximumHeight,\n ellipsoid,\n scratchHorizonCartesian\n );\n maxX = Cartesian3.dot(\n Plane.projectPointOntoPlane(\n plane,\n horizonCartesian,\n scratchHorizonProjected\n ),\n planeXAxis\n );\n minX = -maxX; // symmetrical\n\n // Get the min and max Y, using the height that will give the largest extent\n maxY = Cartesian3.fromRadians(\n 0.0,\n rectangle.north,\n fullyBelowEquator ? minimumHeight : maximumHeight,\n ellipsoid,\n scratchMaxY\n ).z;\n minY = Cartesian3.fromRadians(\n 0.0,\n rectangle.south,\n fullyAboveEquator ? minimumHeight : maximumHeight,\n ellipsoid,\n scratchMinY\n ).z;\n\n const farZ = Cartesian3.fromRadians(\n rectangle.east,\n latitudeNearestToEquator,\n maximumHeight,\n ellipsoid,\n scratchZ\n );\n minZ = Plane.getPointDistance(plane, farZ);\n maxZ = 0.0; // plane origin starts at maxZ already\n\n // min and max are local to the plane axes\n return fromPlaneExtents(\n planeOrigin,\n planeXAxis,\n planeYAxis,\n planeNormal,\n minX,\n maxX,\n minY,\n maxY,\n minZ,\n maxZ,\n result\n );\n};\n\n/**\n * Computes an OrientedBoundingBox that bounds an affine transformation.\n *\n * @param {Matrix4} transformation The affine transformation.\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if none was provided.\n */\nOrientedBoundingBox.fromTransformation = function (transformation, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"transformation\", transformation);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new OrientedBoundingBox();\n }\n\n result.center = Matrix4.getTranslation(transformation, result.center);\n result.halfAxes = Matrix4.getMatrix3(transformation, result.halfAxes);\n result.halfAxes = Matrix3.multiplyByScalar(\n result.halfAxes,\n 0.5,\n result.halfAxes\n );\n return result;\n};\n\n/**\n * Duplicates a OrientedBoundingBox instance.\n *\n * @param {OrientedBoundingBox} box The bounding box to duplicate.\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if none was provided. (Returns undefined if box is undefined)\n */\nOrientedBoundingBox.clone = function (box, result) {\n if (!defined(box)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new OrientedBoundingBox(box.center, box.halfAxes);\n }\n\n Cartesian3.clone(box.center, result.center);\n Matrix3.clone(box.halfAxes, result.halfAxes);\n\n return result;\n};\n\n/**\n * Determines which side of a plane the oriented bounding box is located.\n *\n * @param {OrientedBoundingBox} box The oriented bounding box to test.\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nOrientedBoundingBox.intersectPlane = function (box, plane) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(box)) {\n throw new DeveloperError(\"box is required.\");\n }\n\n if (!defined(plane)) {\n throw new DeveloperError(\"plane is required.\");\n }\n //>>includeEnd('debug');\n\n const center = box.center;\n const normal = plane.normal;\n const halfAxes = box.halfAxes;\n const normalX = normal.x,\n normalY = normal.y,\n normalZ = normal.z;\n // plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[Matrix3.COLUMN0ROW0] +\n normalY * halfAxes[Matrix3.COLUMN0ROW1] +\n normalZ * halfAxes[Matrix3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[Matrix3.COLUMN1ROW0] +\n normalY * halfAxes[Matrix3.COLUMN1ROW1] +\n normalZ * halfAxes[Matrix3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[Matrix3.COLUMN2ROW0] +\n normalY * halfAxes[Matrix3.COLUMN2ROW1] +\n normalZ * halfAxes[Matrix3.COLUMN2ROW2]\n );\n const distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return Intersect.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return Intersect.INSIDE;\n }\n return Intersect.INTERSECTING;\n};\n\nconst scratchCartesianU = new Cartesian3();\nconst scratchCartesianV = new Cartesian3();\nconst scratchCartesianW = new Cartesian3();\nconst scratchValidAxis2 = new Cartesian3();\nconst scratchValidAxis3 = new Cartesian3();\nconst scratchPPrime = new Cartesian3();\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding box to a point.\n *\n * @param {OrientedBoundingBox} box The box.\n * @param {Cartesian3} cartesian The point\n * @returns {number} The distance squared from the oriented bounding box to the point. Returns 0 if the point is inside the box.\n *\n * @example\n * // Sort bounding boxes from back to front\n * boxes.sort(function(a, b) {\n * return Cesium.OrientedBoundingBox.distanceSquaredTo(b, camera.positionWC) - Cesium.OrientedBoundingBox.distanceSquaredTo(a, camera.positionWC);\n * });\n */\nOrientedBoundingBox.distanceSquaredTo = function (box, cartesian) {\n // See Geometric Tools for Computer Graphics 10.4.2\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(box)) {\n throw new DeveloperError(\"box is required.\");\n }\n if (!defined(cartesian)) {\n throw new DeveloperError(\"cartesian is required.\");\n }\n //>>includeEnd('debug');\n\n const offset = Cartesian3.subtract(cartesian, box.center, scratchOffset);\n\n const halfAxes = box.halfAxes;\n let u = Matrix3.getColumn(halfAxes, 0, scratchCartesianU);\n let v = Matrix3.getColumn(halfAxes, 1, scratchCartesianV);\n let w = Matrix3.getColumn(halfAxes, 2, scratchCartesianW);\n\n const uHalf = Cartesian3.magnitude(u);\n const vHalf = Cartesian3.magnitude(v);\n const wHalf = Cartesian3.magnitude(w);\n\n let uValid = true;\n let vValid = true;\n let wValid = true;\n\n if (uHalf > 0) {\n Cartesian3.divideByScalar(u, uHalf, u);\n } else {\n uValid = false;\n }\n\n if (vHalf > 0) {\n Cartesian3.divideByScalar(v, vHalf, v);\n } else {\n vValid = false;\n }\n\n if (wHalf > 0) {\n Cartesian3.divideByScalar(w, wHalf, w);\n } else {\n wValid = false;\n }\n\n const numberOfDegenerateAxes = !uValid + !vValid + !wValid;\n let validAxis1;\n let validAxis2;\n let validAxis3;\n\n if (numberOfDegenerateAxes === 1) {\n let degenerateAxis = u;\n validAxis1 = v;\n validAxis2 = w;\n if (!vValid) {\n degenerateAxis = v;\n validAxis1 = u;\n } else if (!wValid) {\n degenerateAxis = w;\n validAxis2 = u;\n }\n\n validAxis3 = Cartesian3.cross(validAxis1, validAxis2, scratchValidAxis3);\n\n if (degenerateAxis === u) {\n u = validAxis3;\n } else if (degenerateAxis === v) {\n v = validAxis3;\n } else if (degenerateAxis === w) {\n w = validAxis3;\n }\n } else if (numberOfDegenerateAxes === 2) {\n validAxis1 = u;\n if (vValid) {\n validAxis1 = v;\n } else if (wValid) {\n validAxis1 = w;\n }\n\n let crossVector = Cartesian3.UNIT_Y;\n if (crossVector.equalsEpsilon(validAxis1, CesiumMath.EPSILON3)) {\n crossVector = Cartesian3.UNIT_X;\n }\n\n validAxis2 = Cartesian3.cross(validAxis1, crossVector, scratchValidAxis2);\n Cartesian3.normalize(validAxis2, validAxis2);\n validAxis3 = Cartesian3.cross(validAxis1, validAxis2, scratchValidAxis3);\n Cartesian3.normalize(validAxis3, validAxis3);\n\n if (validAxis1 === u) {\n v = validAxis2;\n w = validAxis3;\n } else if (validAxis1 === v) {\n w = validAxis2;\n u = validAxis3;\n } else if (validAxis1 === w) {\n u = validAxis2;\n v = validAxis3;\n }\n } else if (numberOfDegenerateAxes === 3) {\n u = Cartesian3.UNIT_X;\n v = Cartesian3.UNIT_Y;\n w = Cartesian3.UNIT_Z;\n }\n\n const pPrime = scratchPPrime;\n pPrime.x = Cartesian3.dot(offset, u);\n pPrime.y = Cartesian3.dot(offset, v);\n pPrime.z = Cartesian3.dot(offset, w);\n\n let distanceSquared = 0.0;\n let d;\n\n if (pPrime.x < -uHalf) {\n d = pPrime.x + uHalf;\n distanceSquared += d * d;\n } else if (pPrime.x > uHalf) {\n d = pPrime.x - uHalf;\n distanceSquared += d * d;\n }\n\n if (pPrime.y < -vHalf) {\n d = pPrime.y + vHalf;\n distanceSquared += d * d;\n } else if (pPrime.y > vHalf) {\n d = pPrime.y - vHalf;\n distanceSquared += d * d;\n }\n\n if (pPrime.z < -wHalf) {\n d = pPrime.z + wHalf;\n distanceSquared += d * d;\n } else if (pPrime.z > wHalf) {\n d = pPrime.z - wHalf;\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n};\n\nconst scratchCorner = new Cartesian3();\nconst scratchToCenter = new Cartesian3();\n\n/**\n * The distances calculated by the vector from the center of the bounding box to position projected onto direction.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding box.\n *\n * @param {OrientedBoundingBox} box The bounding box to calculate the distance to.\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding box from position in direction.\n */\nOrientedBoundingBox.computePlaneDistances = function (\n box,\n position,\n direction,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(box)) {\n throw new DeveloperError(\"box is required.\");\n }\n\n if (!defined(position)) {\n throw new DeveloperError(\"position is required.\");\n }\n\n if (!defined(direction)) {\n throw new DeveloperError(\"direction is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Interval();\n }\n\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = box.center;\n const halfAxes = box.halfAxes;\n\n const u = Matrix3.getColumn(halfAxes, 0, scratchCartesianU);\n const v = Matrix3.getColumn(halfAxes, 1, scratchCartesianV);\n const w = Matrix3.getColumn(halfAxes, 2, scratchCartesianW);\n\n // project first corner\n const corner = Cartesian3.add(u, v, scratchCorner);\n Cartesian3.add(corner, w, corner);\n Cartesian3.add(corner, center, corner);\n\n const toCenter = Cartesian3.subtract(corner, position, scratchToCenter);\n let mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n Cartesian3.add(center, u, corner);\n Cartesian3.add(corner, v, corner);\n Cartesian3.subtract(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n Cartesian3.add(center, u, corner);\n Cartesian3.subtract(corner, v, corner);\n Cartesian3.add(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n Cartesian3.add(center, u, corner);\n Cartesian3.subtract(corner, v, corner);\n Cartesian3.subtract(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n Cartesian3.subtract(center, u, corner);\n Cartesian3.add(corner, v, corner);\n Cartesian3.add(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n Cartesian3.subtract(center, u, corner);\n Cartesian3.add(corner, v, corner);\n Cartesian3.subtract(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n Cartesian3.subtract(center, u, corner);\n Cartesian3.subtract(corner, v, corner);\n Cartesian3.add(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n Cartesian3.subtract(center, u, corner);\n Cartesian3.subtract(corner, v, corner);\n Cartesian3.subtract(corner, w, corner);\n\n Cartesian3.subtract(corner, position, toCenter);\n mag = Cartesian3.dot(direction, toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result.start = minDist;\n result.stop = maxDist;\n return result;\n};\n\nconst scratchXAxis = new Cartesian3();\nconst scratchYAxis = new Cartesian3();\nconst scratchZAxis = new Cartesian3();\n\n/**\n * Computes the eight corners of an oriented bounding box. The corners are ordered by (-X, -Y, -Z), (-X, -Y, +Z), (-X, +Y, -Z), (-X, +Y, +Z), (+X, -Y, -Z), (+X, -Y, +Z), (+X, +Y, -Z), (+X, +Y, +Z).\n *\n * @param {OrientedBoundingBox} box The oriented bounding box.\n * @param {Cartesian3[]} [result] An array of eight {@link Cartesian3} instances onto which to store the corners.\n * @returns {Cartesian3[]} The modified result parameter or a new array if none was provided.\n */\nOrientedBoundingBox.computeCorners = function (box, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"box\", box);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = [\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n ];\n }\n\n const center = box.center;\n const halfAxes = box.halfAxes;\n const xAxis = Matrix3.getColumn(halfAxes, 0, scratchXAxis);\n const yAxis = Matrix3.getColumn(halfAxes, 1, scratchYAxis);\n const zAxis = Matrix3.getColumn(halfAxes, 2, scratchZAxis);\n\n Cartesian3.clone(center, result[0]);\n Cartesian3.subtract(result[0], xAxis, result[0]);\n Cartesian3.subtract(result[0], yAxis, result[0]);\n Cartesian3.subtract(result[0], zAxis, result[0]);\n\n Cartesian3.clone(center, result[1]);\n Cartesian3.subtract(result[1], xAxis, result[1]);\n Cartesian3.subtract(result[1], yAxis, result[1]);\n Cartesian3.add(result[1], zAxis, result[1]);\n\n Cartesian3.clone(center, result[2]);\n Cartesian3.subtract(result[2], xAxis, result[2]);\n Cartesian3.add(result[2], yAxis, result[2]);\n Cartesian3.subtract(result[2], zAxis, result[2]);\n\n Cartesian3.clone(center, result[3]);\n Cartesian3.subtract(result[3], xAxis, result[3]);\n Cartesian3.add(result[3], yAxis, result[3]);\n Cartesian3.add(result[3], zAxis, result[3]);\n\n Cartesian3.clone(center, result[4]);\n Cartesian3.add(result[4], xAxis, result[4]);\n Cartesian3.subtract(result[4], yAxis, result[4]);\n Cartesian3.subtract(result[4], zAxis, result[4]);\n\n Cartesian3.clone(center, result[5]);\n Cartesian3.add(result[5], xAxis, result[5]);\n Cartesian3.subtract(result[5], yAxis, result[5]);\n Cartesian3.add(result[5], zAxis, result[5]);\n\n Cartesian3.clone(center, result[6]);\n Cartesian3.add(result[6], xAxis, result[6]);\n Cartesian3.add(result[6], yAxis, result[6]);\n Cartesian3.subtract(result[6], zAxis, result[6]);\n\n Cartesian3.clone(center, result[7]);\n Cartesian3.add(result[7], xAxis, result[7]);\n Cartesian3.add(result[7], yAxis, result[7]);\n Cartesian3.add(result[7], zAxis, result[7]);\n\n return result;\n};\n\nconst scratchRotationScale = new Matrix3();\n\n/**\n * Computes a transformation matrix from an oriented bounding box.\n *\n * @param {OrientedBoundingBox} box The oriented bounding box.\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new {@link Matrix4} instance if none was provided.\n */\nOrientedBoundingBox.computeTransformation = function (box, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"box\", box);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Matrix4();\n }\n\n const translation = box.center;\n const rotationScale = Matrix3.multiplyByUniformScale(\n box.halfAxes,\n 2.0,\n scratchRotationScale\n );\n return Matrix4.fromRotationTranslation(rotationScale, translation, result);\n};\n\nconst scratchBoundingSphere = new BoundingSphere();\n\n/**\n * Determines whether or not a bounding box is hidden from view by the occluder.\n *\n * @param {OrientedBoundingBox} box The bounding box surrounding the occludee object.\n * @param {Occluder} occluder The occluder.\n * @returns {boolean} true if the box is not visible; otherwise false.\n */\nOrientedBoundingBox.isOccluded = function (box, occluder) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(box)) {\n throw new DeveloperError(\"box is required.\");\n }\n if (!defined(occluder)) {\n throw new DeveloperError(\"occluder is required.\");\n }\n //>>includeEnd('debug');\n\n const sphere = BoundingSphere.fromOrientedBoundingBox(\n box,\n scratchBoundingSphere\n );\n\n return !occluder.isBoundingSphereVisible(sphere);\n};\n\n/**\n * Determines which side of a plane the oriented bounding box is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nOrientedBoundingBox.prototype.intersectPlane = function (plane) {\n return OrientedBoundingBox.intersectPlane(this, plane);\n};\n\n/**\n * Computes the estimated distance squared from the closest point on a bounding box to a point.\n *\n * @param {Cartesian3} cartesian The point\n * @returns {number} The estimated distance squared from the bounding sphere to the point.\n *\n * @example\n * // Sort bounding boxes from back to front\n * boxes.sort(function(a, b) {\n * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);\n * });\n */\nOrientedBoundingBox.prototype.distanceSquaredTo = function (cartesian) {\n return OrientedBoundingBox.distanceSquaredTo(this, cartesian);\n};\n\n/**\n * The distances calculated by the vector from the center of the bounding box to position projected onto direction.\n *
\n * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the\n * closest and farthest planes from position that intersect the bounding box.\n *\n * @param {Cartesian3} position The position to calculate the distance from.\n * @param {Cartesian3} direction The direction from position.\n * @param {Interval} [result] A Interval to store the nearest and farthest distances.\n * @returns {Interval} The nearest and farthest distances on the bounding box from position in direction.\n */\nOrientedBoundingBox.prototype.computePlaneDistances = function (\n position,\n direction,\n result\n) {\n return OrientedBoundingBox.computePlaneDistances(\n this,\n position,\n direction,\n result\n );\n};\n\n/**\n * Computes the eight corners of an oriented bounding box. The corners are ordered by (-X, -Y, -Z), (-X, -Y, +Z), (-X, +Y, -Z), (-X, +Y, +Z), (+X, -Y, -Z), (+X, -Y, +Z), (+X, +Y, -Z), (+X, +Y, +Z).\n *\n * @param {Cartesian3[]} [result] An array of eight {@link Cartesian3} instances onto which to store the corners.\n * @returns {Cartesian3[]} The modified result parameter or a new array if none was provided.\n */\nOrientedBoundingBox.prototype.computeCorners = function (result) {\n return OrientedBoundingBox.computeCorners(this, result);\n};\n\n/**\n * Computes a transformation matrix from an oriented bounding box.\n *\n * @param {Matrix4} result The object onto which to store the result.\n * @returns {Matrix4} The modified result parameter or a new {@link Matrix4} instance if none was provided.\n */\nOrientedBoundingBox.prototype.computeTransformation = function (result) {\n return OrientedBoundingBox.computeTransformation(this, result);\n};\n\n/**\n * Determines whether or not a bounding box is hidden from view by the occluder.\n *\n * @param {Occluder} occluder The occluder.\n * @returns {boolean} true if the sphere is not visible; otherwise false.\n */\nOrientedBoundingBox.prototype.isOccluded = function (occluder) {\n return OrientedBoundingBox.isOccluded(this, occluder);\n};\n\n/**\n * Compares the provided OrientedBoundingBox componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {OrientedBoundingBox} left The first OrientedBoundingBox.\n * @param {OrientedBoundingBox} right The second OrientedBoundingBox.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nOrientedBoundingBox.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Cartesian3.equals(left.center, right.center) &&\n Matrix3.equals(left.halfAxes, right.halfAxes))\n );\n};\n\n/**\n * Duplicates this OrientedBoundingBox instance.\n *\n * @param {OrientedBoundingBox} [result] The object onto which to store the result.\n * @returns {OrientedBoundingBox} The modified result parameter or a new OrientedBoundingBox instance if one was not provided.\n */\nOrientedBoundingBox.prototype.clone = function (result) {\n return OrientedBoundingBox.clone(this, result);\n};\n\n/**\n * Compares this OrientedBoundingBox against the provided OrientedBoundingBox componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {OrientedBoundingBox} [right] The right hand side OrientedBoundingBox.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nOrientedBoundingBox.prototype.equals = function (right) {\n return OrientedBoundingBox.equals(this, right);\n};\nexport default OrientedBoundingBox;\n", "import Cartesian3 from \"./Cartesian3.js\";\n\n/**\n * @private\n */\nconst TerrainExaggeration = {};\n\n/**\n * Scales a height relative to an offset.\n *\n * @param {number} height The height.\n * @param {number} scale A scalar used to exaggerate the terrain. If the value is 1.0 there will be no effect.\n * @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.\n */\nTerrainExaggeration.getHeight = function (height, scale, relativeHeight) {\n return (height - relativeHeight) * scale + relativeHeight;\n};\n\nconst scratchCartographic = new Cartesian3();\n\n/**\n * Scales a position by exaggeration.\n */\nTerrainExaggeration.getPosition = function (\n position,\n ellipsoid,\n terrainExaggeration,\n terrainExaggerationRelativeHeight,\n result\n) {\n const cartographic = ellipsoid.cartesianToCartographic(\n position,\n scratchCartographic\n );\n const newHeight = TerrainExaggeration.getHeight(\n cartographic.height,\n terrainExaggeration,\n terrainExaggerationRelativeHeight\n );\n return Cartesian3.fromRadians(\n cartographic.longitude,\n cartographic.latitude,\n newHeight,\n ellipsoid,\n result\n );\n};\n\nexport default TerrainExaggeration;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin float batchId;\\n\\\n\\n\\\n#ifdef EXTRUDED_GEOMETRY\\n\\\nin vec3 extrudeDirection;\\n\\\n\\n\\\nuniform float u_globeMinimumAltitude;\\n\\\n#endif // EXTRUDED_GEOMETRY\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nout vec4 v_color;\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n\\n\\\n#ifdef TEXTURE_COORDINATES\\n\\\n#ifdef SPHERICAL\\n\\\nout vec4 v_sphericalExtents;\\n\\\n#else // SPHERICAL\\n\\\nout vec2 v_inversePlaneExtents;\\n\\\nout vec4 v_westPlane;\\n\\\nout vec4 v_southPlane;\\n\\\n#endif // SPHERICAL\\n\\\nout vec3 v_uvMinAndSphericalLongitudeRotation;\\n\\\nout vec3 v_uMaxAndInverseDistance;\\n\\\nout vec3 v_vMaxAndInverseDistance;\\n\\\n#endif // TEXTURE_COORDINATES\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 position = czm_computePosition();\\n\\\n\\n\\\n#ifdef EXTRUDED_GEOMETRY\\n\\\n float delta = min(u_globeMinimumAltitude, czm_geometricToleranceOverMeter * length(position.xyz));\\n\\\n delta *= czm_sceneMode == czm_sceneMode3D ? 1.0 : 0.0;\\n\\\n\\n\\\n //extrudeDirection is zero for the top layer\\n\\\n position = position + vec4(extrudeDirection * delta, 0.0);\\n\\\n#endif\\n\\\n\\n\\\n#ifdef TEXTURE_COORDINATES\\n\\\n#ifdef SPHERICAL\\n\\\n v_sphericalExtents = czm_batchTable_sphericalExtents(batchId);\\n\\\n v_uvMinAndSphericalLongitudeRotation.z = czm_batchTable_longitudeRotation(batchId);\\n\\\n#else // SPHERICAL\\n\\\n#ifdef COLUMBUS_VIEW_2D\\n\\\n vec4 planes2D_high = czm_batchTable_planes2D_HIGH(batchId);\\n\\\n vec4 planes2D_low = czm_batchTable_planes2D_LOW(batchId);\\n\\\n\\n\\\n // If the primitive is split across the IDL (planes2D_high.x > planes2D_high.w):\\n\\\n // - If this vertex is on the east side of the IDL (position3DLow.y > 0.0, comparison with position3DHigh may produce artifacts)\\n\\\n // - existing \\\"east\\\" is on the wrong side of the world, far away (planes2D_high/low.w)\\n\\\n // - so set \\\"east\\\" as beyond the eastmost extent of the projection (idlSplitNewPlaneHiLow)\\n\\\n vec2 idlSplitNewPlaneHiLow = vec2(EAST_MOST_X_HIGH - (WEST_MOST_X_HIGH - planes2D_high.w), EAST_MOST_X_LOW - (WEST_MOST_X_LOW - planes2D_low.w));\\n\\\n bool idlSplit = planes2D_high.x > planes2D_high.w && position3DLow.y > 0.0;\\n\\\n planes2D_high.w = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.x, planes2D_high.w);\\n\\\n planes2D_low.w = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.y, planes2D_low.w);\\n\\\n\\n\\\n // - else, if this vertex is on the west side of the IDL (position3DLow.y < 0.0)\\n\\\n // - existing \\\"west\\\" is on the wrong side of the world, far away (planes2D_high/low.x)\\n\\\n // - so set \\\"west\\\" as beyond the westmost extent of the projection (idlSplitNewPlaneHiLow)\\n\\\n idlSplit = planes2D_high.x > planes2D_high.w && position3DLow.y < 0.0;\\n\\\n idlSplitNewPlaneHiLow = vec2(WEST_MOST_X_HIGH - (EAST_MOST_X_HIGH - planes2D_high.x), WEST_MOST_X_LOW - (EAST_MOST_X_LOW - planes2D_low.x));\\n\\\n planes2D_high.x = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.x, planes2D_high.x);\\n\\\n planes2D_low.x = czm_branchFreeTernary(idlSplit, idlSplitNewPlaneHiLow.y, planes2D_low.x);\\n\\\n\\n\\\n vec3 southWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.xy), vec3(0.0, planes2D_low.xy))).xyz;\\n\\\n vec3 northWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.x, planes2D_high.z), vec3(0.0, planes2D_low.x, planes2D_low.z))).xyz;\\n\\\n vec3 southEastCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, planes2D_high.w, planes2D_high.y), vec3(0.0, planes2D_low.w, planes2D_low.y))).xyz;\\n\\\n#else // COLUMBUS_VIEW_2D\\n\\\n // 3D case has smaller \\\"plane extents,\\\" so planes encoded as a 64 bit position and 2 vec3s for distances/direction\\n\\\n vec3 southWestCorner = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(czm_batchTable_southWest_HIGH(batchId), czm_batchTable_southWest_LOW(batchId))).xyz;\\n\\\n vec3 northWestCorner = czm_normal * czm_batchTable_northward(batchId) + southWestCorner;\\n\\\n vec3 southEastCorner = czm_normal * czm_batchTable_eastward(batchId) + southWestCorner;\\n\\\n#endif // COLUMBUS_VIEW_2D\\n\\\n\\n\\\n vec3 eastWard = southEastCorner - southWestCorner;\\n\\\n float eastExtent = length(eastWard);\\n\\\n eastWard /= eastExtent;\\n\\\n\\n\\\n vec3 northWard = northWestCorner - southWestCorner;\\n\\\n float northExtent = length(northWard);\\n\\\n northWard /= northExtent;\\n\\\n\\n\\\n v_westPlane = vec4(eastWard, -dot(eastWard, southWestCorner));\\n\\\n v_southPlane = vec4(northWard, -dot(northWard, southWestCorner));\\n\\\n v_inversePlaneExtents = vec2(1.0 / eastExtent, 1.0 / northExtent);\\n\\\n#endif // SPHERICAL\\n\\\n vec4 uvMinAndExtents = czm_batchTable_uvMinAndExtents(batchId);\\n\\\n vec4 uMaxVmax = czm_batchTable_uMaxVmax(batchId);\\n\\\n\\n\\\n v_uMaxAndInverseDistance = vec3(uMaxVmax.xy, uvMinAndExtents.z);\\n\\\n v_vMaxAndInverseDistance = vec3(uMaxVmax.zw, uvMinAndExtents.w);\\n\\\n v_uvMinAndSphericalLongitudeRotation.xy = uvMinAndExtents.xy;\\n\\\n#endif // TEXTURE_COORDINATES\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n v_color = czm_batchTable_color(batchId);\\n\\\n#endif\\n\\\n\\n\\\n gl_Position = czm_depthClamp(czm_modelViewProjectionRelativeToEye * position);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef VECTOR_TILE\\n\\\nuniform vec4 u_highlightColor;\\n\\\n#endif\\n\\\n\\n\\\nvoid main(void)\\n\\\n{\\n\\\n#ifdef VECTOR_TILE\\n\\\n out_FragColor = czm_gammaCorrect(u_highlightColor);\\n\\\n#else\\n\\\n out_FragColor = vec4(1.0);\\n\\\n#endif\\n\\\n czm_writeDepthClamp();\\n\\\n}\\n\\\n\";\n", "/**\n * Whether a classification affects terrain, 3D Tiles or both.\n *\n * @enum {number}\n */\nconst ClassificationType = {\n /**\n * Only terrain will be classified.\n *\n * @type {number}\n * @constant\n */\n TERRAIN: 0,\n /**\n * Only 3D Tiles will be classified.\n *\n * @type {number}\n * @constant\n */\n CESIUM_3D_TILE: 1,\n /**\n * Both terrain and 3D Tiles will be classified.\n *\n * @type {number}\n * @constant\n */\n BOTH: 2,\n};\n\n/**\n * @private\n */\nClassificationType.NUMBER_OF_CLASSIFICATION_TYPES = 3;\n\nexport default Object.freeze(ClassificationType);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines the function used to compare two depths for the depth test.\n *\n * @enum {number}\n */\nconst DepthFunction = {\n /**\n * The depth test never passes.\n *\n * @type {number}\n * @constant\n */\n NEVER: WebGLConstants.NEVER,\n\n /**\n * The depth test passes if the incoming depth is less than the stored depth.\n *\n * @type {number}\n * @constant\n */\n LESS: WebGLConstants.LESS,\n\n /**\n * The depth test passes if the incoming depth is equal to the stored depth.\n *\n * @type {number}\n * @constant\n */\n EQUAL: WebGLConstants.EQUAL,\n\n /**\n * The depth test passes if the incoming depth is less than or equal to the stored depth.\n *\n * @type {number}\n * @constant\n */\n LESS_OR_EQUAL: WebGLConstants.LEQUAL,\n\n /**\n * The depth test passes if the incoming depth is greater than the stored depth.\n *\n * @type {number}\n * @constant\n */\n GREATER: WebGLConstants.GREATER,\n\n /**\n * The depth test passes if the incoming depth is not equal to the stored depth.\n *\n * @type {number}\n * @constant\n */\n NOT_EQUAL: WebGLConstants.NOTEQUAL,\n\n /**\n * The depth test passes if the incoming depth is greater than or equal to the stored depth.\n *\n * @type {number}\n * @constant\n */\n GREATER_OR_EQUAL: WebGLConstants.GEQUAL,\n\n /**\n * The depth test always passes.\n *\n * @type {number}\n * @constant\n */\n ALWAYS: WebGLConstants.ALWAYS,\n};\nexport default Object.freeze(DepthFunction);\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Subdivides an array into a number of smaller, equal sized arrays.\n *\n * @function subdivideArray\n *\n * @param {Array} array The array to divide.\n * @param {number} numberOfArrays The number of arrays to divide the provided array into.\n *\n * @exception {DeveloperError} numberOfArrays must be greater than 0.\n */\nfunction subdivideArray(array, numberOfArrays) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required.\");\n }\n\n if (!defined(numberOfArrays) || numberOfArrays < 1) {\n throw new DeveloperError(\"numberOfArrays must be greater than 0.\");\n }\n //>>includeEnd('debug');\n\n const result = [];\n const len = array.length;\n let i = 0;\n while (i < len) {\n const size = Math.ceil((len - i) / numberOfArrays--);\n result.push(array.slice(i, i + size));\n i += size;\n }\n return result;\n}\nexport default subdivideArray;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport combine from \"../Core/combine.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport PixelDatatype from \"../Renderer/PixelDatatype.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport Texture from \"../Renderer/Texture.js\";\n\n/**\n * Creates a texture to look up per instance attributes for batched primitives. For example, store each primitive's pick color in the texture.\n *\n * @alias BatchTable\n * @constructor\n * @private\n *\n * @param {Context} context The context in which the batch table is created.\n * @param {Object[]} attributes An array of objects describing a per instance attribute. Each object contains a datatype, components per attributes, whether it is normalized and a function name\n * to retrieve the value in the vertex shader.\n * @param {number} numberOfInstances The number of instances in a batch table.\n *\n * @example\n * // create the batch table\n * const attributes = [{\n * functionName : 'getShow',\n * componentDatatype : ComponentDatatype.UNSIGNED_BYTE,\n * componentsPerAttribute : 1\n * }, {\n * functionName : 'getPickColor',\n * componentDatatype : ComponentDatatype.UNSIGNED_BYTE,\n * componentsPerAttribute : 4,\n * normalize : true\n * }];\n * const batchTable = new BatchTable(context, attributes, 5);\n *\n * // when creating the draw commands, update the uniform map and the vertex shader\n * vertexShaderSource = batchTable.getVertexShaderCallback()(vertexShaderSource);\n * const shaderProgram = ShaderProgram.fromCache({\n * // ...\n * vertexShaderSource : vertexShaderSource,\n * });\n *\n * drawCommand.shaderProgram = shaderProgram;\n * drawCommand.uniformMap = batchTable.getUniformMapCallback()(uniformMap);\n *\n * // use the attribute function names in the shader to retrieve the instance values\n * // ...\n * attribute float batchId;\n *\n * void main() {\n * // ...\n * float show = getShow(batchId);\n * vec3 pickColor = getPickColor(batchId);\n * // ...\n * }\n */\nfunction BatchTable(context, attributes, numberOfInstances) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(context)) {\n throw new DeveloperError(\"context is required\");\n }\n if (!defined(attributes)) {\n throw new DeveloperError(\"attributes is required\");\n }\n if (!defined(numberOfInstances)) {\n throw new DeveloperError(\"numberOfInstances is required\");\n }\n //>>includeEnd('debug');\n\n this._attributes = attributes;\n this._numberOfInstances = numberOfInstances;\n\n if (attributes.length === 0) {\n return;\n }\n\n // PERFORMANCE_IDEA: We may be able to arrange the attributes so they can be packing into fewer texels.\n // Right now, an attribute with one component uses an entire texel when 4 single component attributes can\n // be packed into a texel.\n //\n // Packing floats into unsigned byte textures makes the problem worse. A single component float attribute\n // will be packed into a single texel leaving 3 texels unused. 4 texels are reserved for each float attribute\n // regardless of how many components it has.\n const pixelDatatype = getDatatype(attributes);\n const textureFloatSupported = context.floatingPointTexture;\n const packFloats =\n pixelDatatype === PixelDatatype.FLOAT && !textureFloatSupported;\n const offsets = createOffsets(attributes, packFloats);\n\n const stride = getStride(offsets, attributes, packFloats);\n const maxNumberOfInstancesPerRow = Math.floor(\n ContextLimits.maximumTextureSize / stride\n );\n\n const instancesPerWidth = Math.min(\n numberOfInstances,\n maxNumberOfInstancesPerRow\n );\n const width = stride * instancesPerWidth;\n const height = Math.ceil(numberOfInstances / instancesPerWidth);\n\n const stepX = 1.0 / width;\n const centerX = stepX * 0.5;\n const stepY = 1.0 / height;\n const centerY = stepY * 0.5;\n\n this._textureDimensions = new Cartesian2(width, height);\n this._textureStep = new Cartesian4(stepX, centerX, stepY, centerY);\n this._pixelDatatype = !packFloats\n ? pixelDatatype\n : PixelDatatype.UNSIGNED_BYTE;\n this._packFloats = packFloats;\n this._offsets = offsets;\n this._stride = stride;\n this._texture = undefined;\n\n const batchLength = 4 * width * height;\n this._batchValues =\n pixelDatatype === PixelDatatype.FLOAT && !packFloats\n ? new Float32Array(batchLength)\n : new Uint8Array(batchLength);\n this._batchValuesDirty = false;\n}\n\nObject.defineProperties(BatchTable.prototype, {\n /**\n * The attribute descriptions.\n * @memberOf BatchTable.prototype\n * @type {Object[]}\n * @readonly\n */\n attributes: {\n get: function () {\n return this._attributes;\n },\n },\n /**\n * The number of instances.\n * @memberOf BatchTable.prototype\n * @type {number}\n * @readonly\n */\n numberOfInstances: {\n get: function () {\n return this._numberOfInstances;\n },\n },\n});\n\nfunction getDatatype(attributes) {\n let foundFloatDatatype = false;\n const length = attributes.length;\n for (let i = 0; i < length; ++i) {\n if (attributes[i].componentDatatype !== ComponentDatatype.UNSIGNED_BYTE) {\n foundFloatDatatype = true;\n break;\n }\n }\n return foundFloatDatatype ? PixelDatatype.FLOAT : PixelDatatype.UNSIGNED_BYTE;\n}\n\nfunction getAttributeType(attributes, attributeIndex) {\n const componentsPerAttribute =\n attributes[attributeIndex].componentsPerAttribute;\n if (componentsPerAttribute === 2) {\n return Cartesian2;\n } else if (componentsPerAttribute === 3) {\n return Cartesian3;\n } else if (componentsPerAttribute === 4) {\n return Cartesian4;\n }\n return Number;\n}\n\nfunction createOffsets(attributes, packFloats) {\n const offsets = new Array(attributes.length);\n\n let currentOffset = 0;\n const attributesLength = attributes.length;\n for (let i = 0; i < attributesLength; ++i) {\n const attribute = attributes[i];\n const componentDatatype = attribute.componentDatatype;\n\n offsets[i] = currentOffset;\n\n if (componentDatatype !== ComponentDatatype.UNSIGNED_BYTE && packFloats) {\n currentOffset += 4;\n } else {\n ++currentOffset;\n }\n }\n\n return offsets;\n}\n\nfunction getStride(offsets, attributes, packFloats) {\n const length = offsets.length;\n const lastOffset = offsets[length - 1];\n const lastAttribute = attributes[length - 1];\n const componentDatatype = lastAttribute.componentDatatype;\n\n if (componentDatatype !== ComponentDatatype.UNSIGNED_BYTE && packFloats) {\n return lastOffset + 4;\n }\n return lastOffset + 1;\n}\n\nconst scratchPackedFloatCartesian4 = new Cartesian4();\n\nfunction getPackedFloat(array, index, result) {\n let packed = Cartesian4.unpack(array, index, scratchPackedFloatCartesian4);\n const x = Cartesian4.unpackFloat(packed);\n\n packed = Cartesian4.unpack(array, index + 4, scratchPackedFloatCartesian4);\n const y = Cartesian4.unpackFloat(packed);\n\n packed = Cartesian4.unpack(array, index + 8, scratchPackedFloatCartesian4);\n const z = Cartesian4.unpackFloat(packed);\n\n packed = Cartesian4.unpack(array, index + 12, scratchPackedFloatCartesian4);\n const w = Cartesian4.unpackFloat(packed);\n\n return Cartesian4.fromElements(x, y, z, w, result);\n}\n\nfunction setPackedAttribute(value, array, index) {\n let packed = Cartesian4.packFloat(value.x, scratchPackedFloatCartesian4);\n Cartesian4.pack(packed, array, index);\n\n packed = Cartesian4.packFloat(value.y, packed);\n Cartesian4.pack(packed, array, index + 4);\n\n packed = Cartesian4.packFloat(value.z, packed);\n Cartesian4.pack(packed, array, index + 8);\n\n packed = Cartesian4.packFloat(value.w, packed);\n Cartesian4.pack(packed, array, index + 12);\n}\n\nconst scratchGetAttributeCartesian4 = new Cartesian4();\n\n/**\n * Gets the value of an attribute in the table.\n *\n * @param {number} instanceIndex The index of the instance.\n * @param {number} attributeIndex The index of the attribute.\n * @param {undefined|Cartesian2|Cartesian3|Cartesian4} [result] The object onto which to store the result. The type is dependent on the attribute's number of components.\n * @returns {number|Cartesian2|Cartesian3|Cartesian4} The attribute value stored for the instance.\n *\n * @exception {DeveloperError} instanceIndex is out of range.\n * @exception {DeveloperError} attributeIndex is out of range.\n */\nBatchTable.prototype.getBatchedAttribute = function (\n instanceIndex,\n attributeIndex,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (instanceIndex < 0 || instanceIndex >= this._numberOfInstances) {\n throw new DeveloperError(\"instanceIndex is out of range.\");\n }\n if (attributeIndex < 0 || attributeIndex >= this._attributes.length) {\n throw new DeveloperError(\"attributeIndex is out of range\");\n }\n //>>includeEnd('debug');\n\n const attributes = this._attributes;\n const offset = this._offsets[attributeIndex];\n const stride = this._stride;\n\n const index = 4 * stride * instanceIndex + 4 * offset;\n let value;\n\n if (\n this._packFloats &&\n attributes[attributeIndex].componentDatatype !== PixelDatatype.UNSIGNED_BYTE\n ) {\n value = getPackedFloat(\n this._batchValues,\n index,\n scratchGetAttributeCartesian4\n );\n } else {\n value = Cartesian4.unpack(\n this._batchValues,\n index,\n scratchGetAttributeCartesian4\n );\n }\n\n const attributeType = getAttributeType(attributes, attributeIndex);\n if (defined(attributeType.fromCartesian4)) {\n return attributeType.fromCartesian4(value, result);\n } else if (defined(attributeType.clone)) {\n return attributeType.clone(value, result);\n }\n\n return value.x;\n};\n\nconst setAttributeScratchValues = [\n undefined,\n undefined,\n new Cartesian2(),\n new Cartesian3(),\n new Cartesian4(),\n];\nconst setAttributeScratchCartesian4 = new Cartesian4();\n\n/**\n * Sets the value of an attribute in the table.\n *\n * @param {number} instanceIndex The index of the instance.\n * @param {number} attributeIndex The index of the attribute.\n * @param {number|Cartesian2|Cartesian3|Cartesian4} value The value to be stored in the table. The type of value will depend on the number of components of the attribute.\n *\n * @exception {DeveloperError} instanceIndex is out of range.\n * @exception {DeveloperError} attributeIndex is out of range.\n */\nBatchTable.prototype.setBatchedAttribute = function (\n instanceIndex,\n attributeIndex,\n value\n) {\n //>>includeStart('debug', pragmas.debug);\n if (instanceIndex < 0 || instanceIndex >= this._numberOfInstances) {\n throw new DeveloperError(\"instanceIndex is out of range.\");\n }\n if (attributeIndex < 0 || attributeIndex >= this._attributes.length) {\n throw new DeveloperError(\"attributeIndex is out of range\");\n }\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const attributes = this._attributes;\n const result =\n setAttributeScratchValues[\n attributes[attributeIndex].componentsPerAttribute\n ];\n const currentAttribute = this.getBatchedAttribute(\n instanceIndex,\n attributeIndex,\n result\n );\n const attributeType = getAttributeType(this._attributes, attributeIndex);\n const entriesEqual = defined(attributeType.equals)\n ? attributeType.equals(currentAttribute, value)\n : currentAttribute === value;\n if (entriesEqual) {\n return;\n }\n\n const attributeValue = setAttributeScratchCartesian4;\n attributeValue.x = defined(value.x) ? value.x : value;\n attributeValue.y = defined(value.y) ? value.y : 0.0;\n attributeValue.z = defined(value.z) ? value.z : 0.0;\n attributeValue.w = defined(value.w) ? value.w : 0.0;\n\n const offset = this._offsets[attributeIndex];\n const stride = this._stride;\n const index = 4 * stride * instanceIndex + 4 * offset;\n\n if (\n this._packFloats &&\n attributes[attributeIndex].componentDatatype !== PixelDatatype.UNSIGNED_BYTE\n ) {\n setPackedAttribute(attributeValue, this._batchValues, index);\n } else {\n Cartesian4.pack(attributeValue, this._batchValues, index);\n }\n\n this._batchValuesDirty = true;\n};\n\nfunction createTexture(batchTable, context) {\n const dimensions = batchTable._textureDimensions;\n batchTable._texture = new Texture({\n context: context,\n pixelFormat: PixelFormat.RGBA,\n pixelDatatype: batchTable._pixelDatatype,\n width: dimensions.x,\n height: dimensions.y,\n sampler: Sampler.NEAREST,\n flipY: false,\n });\n}\n\nfunction updateTexture(batchTable) {\n const dimensions = batchTable._textureDimensions;\n batchTable._texture.copyFrom({\n source: {\n width: dimensions.x,\n height: dimensions.y,\n arrayBufferView: batchTable._batchValues,\n },\n });\n}\n\n/**\n * Creates/updates the batch table texture.\n * @param {FrameState} frameState The frame state.\n *\n * @exception {RuntimeError} The floating point texture extension is required but not supported.\n */\nBatchTable.prototype.update = function (frameState) {\n if (\n (defined(this._texture) && !this._batchValuesDirty) ||\n this._attributes.length === 0\n ) {\n return;\n }\n\n this._batchValuesDirty = false;\n\n if (!defined(this._texture)) {\n createTexture(this, frameState.context);\n }\n updateTexture(this);\n};\n\n/**\n * Gets a function that will update a uniform map to contain values for looking up values in the batch table.\n *\n * @returns {BatchTable.updateUniformMapCallback} A callback for updating uniform maps.\n */\nBatchTable.prototype.getUniformMapCallback = function () {\n const that = this;\n return function (uniformMap) {\n if (that._attributes.length === 0) {\n return uniformMap;\n }\n\n const batchUniformMap = {\n batchTexture: function () {\n return that._texture;\n },\n batchTextureDimensions: function () {\n return that._textureDimensions;\n },\n batchTextureStep: function () {\n return that._textureStep;\n },\n };\n return combine(uniformMap, batchUniformMap);\n };\n};\n\nfunction getGlslComputeSt(batchTable) {\n const stride = batchTable._stride;\n\n // GLSL batchId is zero-based: [0, numberOfInstances - 1]\n if (batchTable._textureDimensions.y === 1) {\n return (\n `${\n \"uniform vec4 batchTextureStep; \\n\" +\n \"vec2 computeSt(float batchId) \\n\" +\n \"{ \\n\" +\n \" float stepX = batchTextureStep.x; \\n\" +\n \" float centerX = batchTextureStep.y; \\n\" +\n \" float numberOfAttributes = float(\"\n }${stride}); \\n` +\n ` return vec2(centerX + (batchId * numberOfAttributes * stepX), 0.5); \\n` +\n `} \\n`\n );\n }\n\n return (\n `${\n \"uniform vec4 batchTextureStep; \\n\" +\n \"uniform vec2 batchTextureDimensions; \\n\" +\n \"vec2 computeSt(float batchId) \\n\" +\n \"{ \\n\" +\n \" float stepX = batchTextureStep.x; \\n\" +\n \" float centerX = batchTextureStep.y; \\n\" +\n \" float stepY = batchTextureStep.z; \\n\" +\n \" float centerY = batchTextureStep.w; \\n\" +\n \" float numberOfAttributes = float(\"\n }${stride}); \\n` +\n ` float xId = mod(batchId * numberOfAttributes, batchTextureDimensions.x); \\n` +\n ` float yId = floor(batchId * numberOfAttributes / batchTextureDimensions.x); \\n` +\n ` return vec2(centerX + (xId * stepX), centerY + (yId * stepY)); \\n` +\n `} \\n`\n );\n}\n\nfunction getComponentType(componentsPerAttribute) {\n if (componentsPerAttribute === 1) {\n return \"float\";\n }\n return `vec${componentsPerAttribute}`;\n}\n\nfunction getComponentSwizzle(componentsPerAttribute) {\n if (componentsPerAttribute === 1) {\n return \".x\";\n } else if (componentsPerAttribute === 2) {\n return \".xy\";\n } else if (componentsPerAttribute === 3) {\n return \".xyz\";\n }\n return \"\";\n}\n\nfunction getGlslAttributeFunction(batchTable, attributeIndex) {\n const attributes = batchTable._attributes;\n const attribute = attributes[attributeIndex];\n const componentsPerAttribute = attribute.componentsPerAttribute;\n const functionName = attribute.functionName;\n const functionReturnType = getComponentType(componentsPerAttribute);\n const functionReturnValue = getComponentSwizzle(componentsPerAttribute);\n\n const offset = batchTable._offsets[attributeIndex];\n\n let glslFunction =\n `${functionReturnType} ${functionName}(float batchId) \\n` +\n `{ \\n` +\n ` vec2 st = computeSt(batchId); \\n` +\n ` st.x += batchTextureStep.x * float(${offset}); \\n`;\n\n if (\n batchTable._packFloats &&\n attribute.componentDatatype !== PixelDatatype.UNSIGNED_BYTE\n ) {\n glslFunction +=\n \"vec4 textureValue; \\n\" +\n \"textureValue.x = czm_unpackFloat(texture(batchTexture, st)); \\n\" +\n \"textureValue.y = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x, 0.0))); \\n\" +\n \"textureValue.z = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x * 2.0, 0.0))); \\n\" +\n \"textureValue.w = czm_unpackFloat(texture(batchTexture, st + vec2(batchTextureStep.x * 3.0, 0.0))); \\n\";\n } else {\n glslFunction += \" vec4 textureValue = texture(batchTexture, st); \\n\";\n }\n\n glslFunction += ` ${functionReturnType} value = textureValue${functionReturnValue}; \\n`;\n\n if (\n batchTable._pixelDatatype === PixelDatatype.UNSIGNED_BYTE &&\n attribute.componentDatatype === ComponentDatatype.UNSIGNED_BYTE &&\n !attribute.normalize\n ) {\n glslFunction += \"value *= 255.0; \\n\";\n } else if (\n batchTable._pixelDatatype === PixelDatatype.FLOAT &&\n attribute.componentDatatype === ComponentDatatype.UNSIGNED_BYTE &&\n attribute.normalize\n ) {\n glslFunction += \"value /= 255.0; \\n\";\n }\n\n glslFunction += \" return value; \\n\" + \"} \\n\";\n return glslFunction;\n}\n\n/**\n * Gets a function that will update a vertex shader to contain functions for looking up values in the batch table.\n *\n * @returns {BatchTable.updateVertexShaderSourceCallback} A callback for updating a vertex shader source.\n */\nBatchTable.prototype.getVertexShaderCallback = function () {\n const attributes = this._attributes;\n if (attributes.length === 0) {\n return function (source) {\n return source;\n };\n }\n\n let batchTableShader = \"uniform highp sampler2D batchTexture; \\n\";\n batchTableShader += `${getGlslComputeSt(this)}\\n`;\n\n const length = attributes.length;\n for (let i = 0; i < length; ++i) {\n batchTableShader += getGlslAttributeFunction(this, i);\n }\n\n return function (source) {\n const mainIndex = source.indexOf(\"void main\");\n const beforeMain = source.substring(0, mainIndex);\n const afterMain = source.substring(mainIndex);\n return `${beforeMain}\\n${batchTableShader}\\n${afterMain}`;\n };\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see BatchTable#destroy\n */\nBatchTable.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see BatchTable#isDestroyed\n */\nBatchTable.prototype.destroy = function () {\n this._texture = this._texture && this._texture.destroy();\n return destroyObject(this);\n};\n\n/**\n * A callback for updating uniform maps.\n * @callback BatchTable.updateUniformMapCallback\n *\n * @param {object} uniformMap The uniform map.\n * @returns {object} The new uniform map with properties for retrieving values from the batch table.\n */\n\n/**\n * A callback for updating a vertex shader source.\n * @callback BatchTable.updateVertexShaderSourceCallback\n *\n * @param {string} vertexShaderSource The vertex shader source.\n * @returns {string} The new vertex shader source with the functions for retrieving batch table values injected.\n */\nexport default BatchTable;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\n\n/**\n * An enum describing the attribute type for glTF and 3D Tiles.\n *\n * @enum {string}\n *\n * @private\n */\nconst AttributeType = {\n /**\n * The attribute is a single component.\n *\n * @type {string}\n * @constant\n */\n SCALAR: \"SCALAR\",\n\n /**\n * The attribute is a two-component vector.\n *\n * @type {string}\n * @constant\n */\n VEC2: \"VEC2\",\n\n /**\n * The attribute is a three-component vector.\n *\n * @type {string}\n * @constant\n */\n VEC3: \"VEC3\",\n\n /**\n * The attribute is a four-component vector.\n *\n * @type {string}\n * @constant\n */\n VEC4: \"VEC4\",\n\n /**\n * The attribute is a 2x2 matrix.\n *\n * @type {string}\n * @constant\n */\n MAT2: \"MAT2\",\n\n /**\n * The attribute is a 3x3 matrix.\n *\n * @type {string}\n * @constant\n */\n MAT3: \"MAT3\",\n\n /**\n * The attribute is a 4x4 matrix.\n *\n * @type {string}\n * @constant\n */\n MAT4: \"MAT4\",\n};\n\n/**\n * Gets the scalar, vector, or matrix type for the attribute type.\n *\n * @param {AttributeType} attributeType The attribute type.\n * @returns {*} The math type.\n *\n * @private\n */\nAttributeType.getMathType = function (attributeType) {\n switch (attributeType) {\n case AttributeType.SCALAR:\n return Number;\n case AttributeType.VEC2:\n return Cartesian2;\n case AttributeType.VEC3:\n return Cartesian3;\n case AttributeType.VEC4:\n return Cartesian4;\n case AttributeType.MAT2:\n return Matrix2;\n case AttributeType.MAT3:\n return Matrix3;\n case AttributeType.MAT4:\n return Matrix4;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"attributeType is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the number of components per attribute.\n *\n * @param {AttributeType} attributeType The attribute type.\n * @returns {number} The number of components.\n *\n * @private\n */\nAttributeType.getNumberOfComponents = function (attributeType) {\n switch (attributeType) {\n case AttributeType.SCALAR:\n return 1;\n case AttributeType.VEC2:\n return 2;\n case AttributeType.VEC3:\n return 3;\n case AttributeType.VEC4:\n case AttributeType.MAT2:\n return 4;\n case AttributeType.MAT3:\n return 9;\n case AttributeType.MAT4:\n return 16;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"attributeType is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Get the number of attribute locations needed to fit this attribute. Most\n * types require one, but matrices require multiple attribute locations.\n *\n * @param {AttributeType} attributeType The attribute type.\n * @returns {number} The number of attribute locations needed in the shader\n *\n * @private\n */\nAttributeType.getAttributeLocationCount = function (attributeType) {\n switch (attributeType) {\n case AttributeType.SCALAR:\n case AttributeType.VEC2:\n case AttributeType.VEC3:\n case AttributeType.VEC4:\n return 1;\n case AttributeType.MAT2:\n return 2;\n case AttributeType.MAT3:\n return 3;\n case AttributeType.MAT4:\n return 4;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"attributeType is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the GLSL type for the attribute type.\n *\n * @param {AttributeType} attributeType The attribute type.\n * @returns {string} The GLSL type for the attribute type.\n *\n * @private\n */\nAttributeType.getGlslType = function (attributeType) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"attributeType\", attributeType);\n //>>includeEnd('debug');\n\n switch (attributeType) {\n case AttributeType.SCALAR:\n return \"float\";\n case AttributeType.VEC2:\n return \"vec2\";\n case AttributeType.VEC3:\n return \"vec3\";\n case AttributeType.VEC4:\n return \"vec4\";\n case AttributeType.MAT2:\n return \"mat2\";\n case AttributeType.MAT3:\n return \"mat3\";\n case AttributeType.MAT4:\n return \"mat4\";\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"attributeType is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\nexport default Object.freeze(AttributeType);\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport Check from \"./Check.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\nimport AttributeType from \"../Scene/AttributeType.js\";\n\nconst RIGHT_SHIFT = 1.0 / 256.0;\nconst LEFT_SHIFT = 256.0;\n\n/**\n * Attribute compression and decompression functions.\n *\n * @namespace AttributeCompression\n *\n * @private\n */\nconst AttributeCompression = {};\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.\n *\n * Oct encoding is a compact representation of unit length vectors.\n * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n * Cigolle et al 2014: {@link http://jcgt.org/published/0003/02/01/}\n *\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 component 'oct' encoding.\n * @param {Cartesian2} result The 2 component oct-encoded unit length vector.\n * @param {number} rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\n * @returns {Cartesian2} The 2 component oct-encoded unit length vector.\n *\n * @exception {DeveloperError} vector must be normalized.\n *\n * @see AttributeCompression.octDecodeInRange\n */\nAttributeCompression.octEncodeInRange = function (vector, rangeMax, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"vector\", vector);\n Check.defined(\"result\", result);\n const magSquared = Cartesian3.magnitudeSquared(vector);\n if (Math.abs(magSquared - 1.0) > CesiumMath.EPSILON6) {\n throw new DeveloperError(\"vector must be normalized.\");\n }\n //>>includeEnd('debug');\n\n result.x =\n vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\n result.y =\n vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\n if (vector.z < 0) {\n const x = result.x;\n const y = result.y;\n result.x = (1.0 - Math.abs(y)) * CesiumMath.signNotZero(x);\n result.y = (1.0 - Math.abs(x)) * CesiumMath.signNotZero(y);\n }\n\n result.x = CesiumMath.toSNorm(result.x, rangeMax);\n result.y = CesiumMath.toSNorm(result.y, rangeMax);\n\n return result;\n};\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding.\n *\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 byte 'oct' encoding.\n * @param {Cartesian2} result The 2 byte oct-encoded unit length vector.\n * @returns {Cartesian2} The 2 byte oct-encoded unit length vector.\n *\n * @exception {DeveloperError} vector must be normalized.\n *\n * @see AttributeCompression.octEncodeInRange\n * @see AttributeCompression.octDecode\n */\nAttributeCompression.octEncode = function (vector, result) {\n return AttributeCompression.octEncodeInRange(vector, 255, result);\n};\n\nconst octEncodeScratch = new Cartesian2();\nconst uint8ForceArray = new Uint8Array(1);\nfunction forceUint8(value) {\n uint8ForceArray[0] = value;\n return uint8ForceArray[0];\n}\n/**\n * @param {Cartesian3} vector The normalized vector to be compressed into 4 byte 'oct' encoding.\n * @param {Cartesian4} result The 4 byte oct-encoded unit length vector.\n * @returns {Cartesian4} The 4 byte oct-encoded unit length vector.\n *\n * @exception {DeveloperError} vector must be normalized.\n *\n * @see AttributeCompression.octEncodeInRange\n * @see AttributeCompression.octDecodeFromCartesian4\n */\nAttributeCompression.octEncodeToCartesian4 = function (vector, result) {\n AttributeCompression.octEncodeInRange(vector, 65535, octEncodeScratch);\n result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);\n result.y = forceUint8(octEncodeScratch.x);\n result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);\n result.w = forceUint8(octEncodeScratch.y);\n return result;\n};\n\n/**\n * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component vector.\n *\n * @param {number} x The x component of the oct-encoded unit length vector.\n * @param {number} y The y component of the oct-encoded unit length vector.\n * @param {number} rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\n * @param {Cartesian3} result The decoded and normalized vector\n * @returns {Cartesian3} The decoded and normalized vector.\n *\n * @exception {DeveloperError} x and y must be unsigned normalized integers between 0 and rangeMax.\n *\n * @see AttributeCompression.octEncodeInRange\n */\nAttributeCompression.octDecodeInRange = function (x, y, rangeMax, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"result\", result);\n if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {\n throw new DeveloperError(\n `x and y must be unsigned normalized integers between 0 and ${rangeMax}`\n );\n }\n //>>includeEnd('debug');\n\n result.x = CesiumMath.fromSNorm(x, rangeMax);\n result.y = CesiumMath.fromSNorm(y, rangeMax);\n result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));\n\n if (result.z < 0.0) {\n const oldVX = result.x;\n result.x = (1.0 - Math.abs(result.y)) * CesiumMath.signNotZero(oldVX);\n result.y = (1.0 - Math.abs(oldVX)) * CesiumMath.signNotZero(result.y);\n }\n\n return Cartesian3.normalize(result, result);\n};\n\n/**\n * Decodes a unit-length vector in 2 byte 'oct' encoding to a normalized 3-component vector.\n *\n * @param {number} x The x component of the oct-encoded unit length vector.\n * @param {number} y The y component of the oct-encoded unit length vector.\n * @param {Cartesian3} result The decoded and normalized vector.\n * @returns {Cartesian3} The decoded and normalized vector.\n *\n * @exception {DeveloperError} x and y must be an unsigned normalized integer between 0 and 255.\n *\n * @see AttributeCompression.octDecodeInRange\n */\nAttributeCompression.octDecode = function (x, y, result) {\n return AttributeCompression.octDecodeInRange(x, y, 255, result);\n};\n\n/**\n * Decodes a unit-length vector in 4 byte 'oct' encoding to a normalized 3-component vector.\n *\n * @param {Cartesian4} encoded The oct-encoded unit length vector.\n * @param {Cartesian3} result The decoded and normalized vector.\n * @returns {Cartesian3} The decoded and normalized vector.\n *\n * @exception {DeveloperError} x, y, z, and w must be unsigned normalized integers between 0 and 255.\n *\n * @see AttributeCompression.octDecodeInRange\n * @see AttributeCompression.octEncodeToCartesian4\n */\nAttributeCompression.octDecodeFromCartesian4 = function (encoded, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"encoded\", encoded);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n const x = encoded.x;\n const y = encoded.y;\n const z = encoded.z;\n const w = encoded.w;\n //>>includeStart('debug', pragmas.debug);\n if (\n x < 0 ||\n x > 255 ||\n y < 0 ||\n y > 255 ||\n z < 0 ||\n z > 255 ||\n w < 0 ||\n w > 255\n ) {\n throw new DeveloperError(\n \"x, y, z, and w must be unsigned normalized integers between 0 and 255\"\n );\n }\n //>>includeEnd('debug');\n\n const xOct16 = x * LEFT_SHIFT + y;\n const yOct16 = z * LEFT_SHIFT + w;\n return AttributeCompression.octDecodeInRange(xOct16, yOct16, 65535, result);\n};\n\n/**\n * Packs an oct encoded vector into a single floating-point number.\n *\n * @param {Cartesian2} encoded The oct encoded vector.\n * @returns {number} The oct encoded vector packed into a single float.\n *\n */\nAttributeCompression.octPackFloat = function (encoded) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"encoded\", encoded);\n //>>includeEnd('debug');\n return 256.0 * encoded.x + encoded.y;\n};\n\nconst scratchEncodeCart2 = new Cartesian2();\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding and\n * stores those values in a single float-point number.\n *\n * @param {Cartesian3} vector The normalized vector to be compressed into 2 byte 'oct' encoding.\n * @returns {number} The 2 byte oct-encoded unit length vector.\n *\n * @exception {DeveloperError} vector must be normalized.\n */\nAttributeCompression.octEncodeFloat = function (vector) {\n AttributeCompression.octEncode(vector, scratchEncodeCart2);\n return AttributeCompression.octPackFloat(scratchEncodeCart2);\n};\n\n/**\n * Decodes a unit-length vector in 'oct' encoding packed in a floating-point number to a normalized 3-component vector.\n *\n * @param {number} value The oct-encoded unit length vector stored as a single floating-point number.\n * @param {Cartesian3} result The decoded and normalized vector\n * @returns {Cartesian3} The decoded and normalized vector.\n *\n */\nAttributeCompression.octDecodeFloat = function (value, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"value\", value);\n //>>includeEnd('debug');\n\n const temp = value / 256.0;\n const x = Math.floor(temp);\n const y = (temp - x) * 256.0;\n\n return AttributeCompression.octDecode(x, y, result);\n};\n\n/**\n * Encodes three normalized vectors into 6 SNORM values in the range of [0-255] following the 'oct' encoding and\n * packs those into two floating-point numbers.\n *\n * @param {Cartesian3} v1 A normalized vector to be compressed.\n * @param {Cartesian3} v2 A normalized vector to be compressed.\n * @param {Cartesian3} v3 A normalized vector to be compressed.\n * @param {Cartesian2} result The 'oct' encoded vectors packed into two floating-point numbers.\n * @returns {Cartesian2} The 'oct' encoded vectors packed into two floating-point numbers.\n *\n */\nAttributeCompression.octPack = function (v1, v2, v3, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"v1\", v1);\n Check.defined(\"v2\", v2);\n Check.defined(\"v3\", v3);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n const encoded1 = AttributeCompression.octEncodeFloat(v1);\n const encoded2 = AttributeCompression.octEncodeFloat(v2);\n\n const encoded3 = AttributeCompression.octEncode(v3, scratchEncodeCart2);\n result.x = 65536.0 * encoded3.x + encoded1;\n result.y = 65536.0 * encoded3.y + encoded2;\n return result;\n};\n\n/**\n * Decodes three unit-length vectors in 'oct' encoding packed into a floating-point number to a normalized 3-component vector.\n *\n * @param {Cartesian2} packed The three oct-encoded unit length vectors stored as two floating-point number.\n * @param {Cartesian3} v1 One decoded and normalized vector.\n * @param {Cartesian3} v2 One decoded and normalized vector.\n * @param {Cartesian3} v3 One decoded and normalized vector.\n */\nAttributeCompression.octUnpack = function (packed, v1, v2, v3) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"packed\", packed);\n Check.defined(\"v1\", v1);\n Check.defined(\"v2\", v2);\n Check.defined(\"v3\", v3);\n //>>includeEnd('debug');\n\n let temp = packed.x / 65536.0;\n const x = Math.floor(temp);\n const encodedFloat1 = (temp - x) * 65536.0;\n\n temp = packed.y / 65536.0;\n const y = Math.floor(temp);\n const encodedFloat2 = (temp - y) * 65536.0;\n\n AttributeCompression.octDecodeFloat(encodedFloat1, v1);\n AttributeCompression.octDecodeFloat(encodedFloat2, v2);\n AttributeCompression.octDecode(x, y, v3);\n};\n\n/**\n * Pack texture coordinates into a single float. The texture coordinates will only preserve 12 bits of precision.\n *\n * @param {Cartesian2} textureCoordinates The texture coordinates to compress. Both coordinates must be in the range 0.0-1.0.\n * @returns {number} The packed texture coordinates.\n *\n */\nAttributeCompression.compressTextureCoordinates = function (\n textureCoordinates\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"textureCoordinates\", textureCoordinates);\n //>>includeEnd('debug');\n\n // Move x and y to the range 0-4095;\n const x = (textureCoordinates.x * 4095.0) | 0;\n const y = (textureCoordinates.y * 4095.0) | 0;\n return 4096.0 * x + y;\n};\n\n/**\n * Decompresses texture coordinates that were packed into a single float.\n *\n * @param {number} compressed The compressed texture coordinates.\n * @param {Cartesian2} result The decompressed texture coordinates.\n * @returns {Cartesian2} The modified result parameter.\n *\n */\nAttributeCompression.decompressTextureCoordinates = function (\n compressed,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"compressed\", compressed);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n const temp = compressed / 4096.0;\n const xZeroTo4095 = Math.floor(temp);\n result.x = xZeroTo4095 / 4095.0;\n result.y = (compressed - xZeroTo4095 * 4096) / 4095;\n return result;\n};\n\nfunction zigZagDecode(value) {\n return (value >> 1) ^ -(value & 1);\n}\n\n/**\n * Decodes delta and ZigZag encoded vertices. This modifies the buffers in place.\n *\n * @param {Uint16Array} uBuffer The buffer view of u values.\n * @param {Uint16Array} vBuffer The buffer view of v values.\n * @param {Uint16Array} [heightBuffer] The buffer view of height values.\n *\n * @see {@link https://github.com/CesiumGS/quantized-mesh|quantized-mesh-1.0 terrain format}\n */\nAttributeCompression.zigZagDeltaDecode = function (\n uBuffer,\n vBuffer,\n heightBuffer\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"uBuffer\", uBuffer);\n Check.defined(\"vBuffer\", vBuffer);\n Check.typeOf.number.equals(\n \"uBuffer.length\",\n \"vBuffer.length\",\n uBuffer.length,\n vBuffer.length\n );\n if (defined(heightBuffer)) {\n Check.typeOf.number.equals(\n \"uBuffer.length\",\n \"heightBuffer.length\",\n uBuffer.length,\n heightBuffer.length\n );\n }\n //>>includeEnd('debug');\n\n const count = uBuffer.length;\n\n let u = 0;\n let v = 0;\n let height = 0;\n\n for (let i = 0; i < count; ++i) {\n u += zigZagDecode(uBuffer[i]);\n v += zigZagDecode(vBuffer[i]);\n\n uBuffer[i] = u;\n vBuffer[i] = v;\n\n if (defined(heightBuffer)) {\n height += zigZagDecode(heightBuffer[i]);\n heightBuffer[i] = height;\n }\n }\n};\n\n/**\n * Dequantizes a quantized typed array into a floating point typed array.\n *\n * @see {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data}\n *\n * @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array} typedArray The typed array for the quantized data.\n * @param {ComponentDatatype} componentDatatype The component datatype of the quantized data.\n * @param {AttributeType} type The attribute type of the quantized data.\n * @param {number} count The number of attributes referenced in the dequantized array.\n *\n * @returns {Float32Array} The dequantized array.\n */\nAttributeCompression.dequantize = function (\n typedArray,\n componentDatatype,\n type,\n count\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"typedArray\", typedArray);\n Check.defined(\"componentDatatype\", componentDatatype);\n Check.defined(\"type\", type);\n Check.defined(\"count\", count);\n //>>includeEnd('debug');\n\n const componentsPerAttribute = AttributeType.getNumberOfComponents(type);\n\n let divisor;\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n divisor = 127.0;\n break;\n case ComponentDatatype.UNSIGNED_BYTE:\n divisor = 255.0;\n break;\n case ComponentDatatype.SHORT:\n divisor = 32767.0;\n break;\n case ComponentDatatype.UNSIGNED_SHORT:\n divisor = 65535.0;\n break;\n case ComponentDatatype.INT:\n divisor = 2147483647.0;\n break;\n case ComponentDatatype.UNSIGNED_INT:\n divisor = 4294967295.0;\n break;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\n `Cannot dequantize component datatype: ${componentDatatype}`\n );\n //>>includeEnd('debug');\n }\n\n const dequantizedTypedArray = new Float32Array(\n count * componentsPerAttribute\n );\n\n for (let i = 0; i < count; i++) {\n for (let j = 0; j < componentsPerAttribute; j++) {\n const index = i * componentsPerAttribute + j;\n dequantizedTypedArray[index] = Math.max(\n typedArray[index] / divisor,\n -1.0\n );\n }\n }\n\n return dequantizedTypedArray;\n};\n\n/**\n * Decode RGB565-encoded colors into a floating point typed array containing\n * normalized RGB values.\n *\n * @param {Uint16Array} typedArray Array of RGB565 values\n * @param {Float32Array} [result] Array to store the normalized VEC3 result\n */\nAttributeCompression.decodeRGB565 = function (typedArray, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"typedArray\", typedArray);\n\n const expectedLength = typedArray.length * 3;\n if (defined(result)) {\n Check.typeOf.number.equals(\n \"result.length\",\n \"typedArray.length * 3\",\n result.length,\n expectedLength\n );\n }\n //>>includeEnd('debug');\n\n const count = typedArray.length;\n if (!defined(result)) {\n result = new Float32Array(count * 3);\n }\n\n const mask5 = (1 << 5) - 1;\n const mask6 = (1 << 6) - 1;\n const normalize5 = 1.0 / 31.0;\n const normalize6 = 1.0 / 63.0;\n for (let i = 0; i < count; i++) {\n const value = typedArray[i];\n const red = value >> 11;\n const green = (value >> 5) & mask6;\n const blue = value & mask5;\n\n const offset = 3 * i;\n result[offset] = red * normalize5;\n result[offset + 1] = green * normalize6;\n result[offset + 2] = blue * normalize5;\n }\n\n return result;\n};\n\nexport default AttributeCompression;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartesian3 = new Cartesian3();\n\n/**\n * Computes the barycentric coordinates for a point with respect to a triangle.\n *\n * @function\n *\n * @param {Cartesian2|Cartesian3} point The point to test.\n * @param {Cartesian2|Cartesian3} p0 The first point of the triangle, corresponding to the barycentric x-axis.\n * @param {Cartesian2|Cartesian3} p1 The second point of the triangle, corresponding to the barycentric y-axis.\n * @param {Cartesian2|Cartesian3} p2 The third point of the triangle, corresponding to the barycentric z-axis.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3|undefined} The modified result parameter or a new Cartesian3 instance if one was not provided. If the triangle is degenerate the function will return undefined.\n *\n * @example\n * // Returns Cartesian3.UNIT_X\n * const p = new Cesium.Cartesian3(-1.0, 0.0, 0.0);\n * const b = Cesium.barycentricCoordinates(p,\n * new Cesium.Cartesian3(-1.0, 0.0, 0.0),\n * new Cesium.Cartesian3( 1.0, 0.0, 0.0),\n * new Cesium.Cartesian3( 0.0, 1.0, 1.0));\n */\nfunction barycentricCoordinates(point, p0, p1, p2, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"point\", point);\n Check.defined(\"p0\", p0);\n Check.defined(\"p1\", p1);\n Check.defined(\"p2\", p2);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n // Implementation based on http://www.blackpawn.com/texts/pointinpoly/default.html.\n let v0;\n let v1;\n let v2;\n let dot00;\n let dot01;\n let dot02;\n let dot11;\n let dot12;\n\n if (!defined(p0.z)) {\n if (Cartesian2.equalsEpsilon(point, p0, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_X, result);\n }\n if (Cartesian2.equalsEpsilon(point, p1, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_Y, result);\n }\n if (Cartesian2.equalsEpsilon(point, p2, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_Z, result);\n }\n\n v0 = Cartesian2.subtract(p1, p0, scratchCartesian1);\n v1 = Cartesian2.subtract(p2, p0, scratchCartesian2);\n v2 = Cartesian2.subtract(point, p0, scratchCartesian3);\n\n dot00 = Cartesian2.dot(v0, v0);\n dot01 = Cartesian2.dot(v0, v1);\n dot02 = Cartesian2.dot(v0, v2);\n dot11 = Cartesian2.dot(v1, v1);\n dot12 = Cartesian2.dot(v1, v2);\n } else {\n if (Cartesian3.equalsEpsilon(point, p0, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_X, result);\n }\n if (Cartesian3.equalsEpsilon(point, p1, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_Y, result);\n }\n if (Cartesian3.equalsEpsilon(point, p2, CesiumMath.EPSILON14)) {\n return Cartesian3.clone(Cartesian3.UNIT_Z, result);\n }\n\n v0 = Cartesian3.subtract(p1, p0, scratchCartesian1);\n v1 = Cartesian3.subtract(p2, p0, scratchCartesian2);\n v2 = Cartesian3.subtract(point, p0, scratchCartesian3);\n\n dot00 = Cartesian3.dot(v0, v0);\n dot01 = Cartesian3.dot(v0, v1);\n dot02 = Cartesian3.dot(v0, v2);\n dot11 = Cartesian3.dot(v1, v1);\n dot12 = Cartesian3.dot(v1, v2);\n }\n\n result.y = dot11 * dot02 - dot01 * dot12;\n result.z = dot00 * dot12 - dot01 * dot02;\n const q = dot00 * dot11 - dot01 * dot01;\n\n // Triangle is degenerate\n if (q === 0) {\n return undefined;\n }\n\n result.y /= q;\n result.z /= q;\n result.x = 1.0 - result.y - result.z;\n return result;\n}\nexport default barycentricCoordinates;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Encapsulates an algorithm to optimize triangles for the post\n * vertex-shader cache. This is based on the 2007 SIGGRAPH paper\n * 'Fast Triangle Reordering for Vertex Locality and Reduced Overdraw.'\n * The runtime is linear but several passes are made.\n *\n * @namespace Tipsify\n *\n * @see \n * Fast Triangle Reordering for Vertex Locality and Reduced Overdraw\n * by Sander, Nehab, and Barczak\n *\n * @private\n */\nconst Tipsify = {};\n\n/**\n * Calculates the average cache miss ratio (ACMR) for a given set of indices.\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.indices Lists triads of numbers corresponding to the indices of the vertices\n * in the vertex buffer that define the geometry's triangles.\n * @param {number} [options.maximumIndex] The maximum value of the elements in args.indices.\n * If not supplied, this value will be computed.\n * @param {number} [options.cacheSize=24] The number of vertices that can be stored in the cache at any one time.\n * @returns {number} The average cache miss ratio (ACMR).\n *\n * @exception {DeveloperError} indices length must be a multiple of three.\n * @exception {DeveloperError} cacheSize must be greater than two.\n *\n * @example\n * const indices = [0, 1, 2, 3, 4, 5];\n * const maxIndex = 5;\n * const cacheSize = 3;\n * const acmr = Cesium.Tipsify.calculateACMR({indices : indices, maxIndex : maxIndex, cacheSize : cacheSize});\n */\nTipsify.calculateACMR = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const indices = options.indices;\n let maximumIndex = options.maximumIndex;\n const cacheSize = defaultValue(options.cacheSize, 24);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(indices)) {\n throw new DeveloperError(\"indices is required.\");\n }\n //>>includeEnd('debug');\n\n const numIndices = indices.length;\n\n //>>includeStart('debug', pragmas.debug);\n if (numIndices < 3 || numIndices % 3 !== 0) {\n throw new DeveloperError(\"indices length must be a multiple of three.\");\n }\n if (maximumIndex <= 0) {\n throw new DeveloperError(\"maximumIndex must be greater than zero.\");\n }\n if (cacheSize < 3) {\n throw new DeveloperError(\"cacheSize must be greater than two.\");\n }\n //>>includeEnd('debug');\n\n // Compute the maximumIndex if not given\n if (!defined(maximumIndex)) {\n maximumIndex = 0;\n let currentIndex = 0;\n let intoIndices = indices[currentIndex];\n while (currentIndex < numIndices) {\n if (intoIndices > maximumIndex) {\n maximumIndex = intoIndices;\n }\n ++currentIndex;\n intoIndices = indices[currentIndex];\n }\n }\n\n // Vertex time stamps\n const vertexTimeStamps = [];\n for (let i = 0; i < maximumIndex + 1; i++) {\n vertexTimeStamps[i] = 0;\n }\n\n // Cache processing\n let s = cacheSize + 1;\n for (let j = 0; j < numIndices; ++j) {\n if (s - vertexTimeStamps[indices[j]] > cacheSize) {\n vertexTimeStamps[indices[j]] = s;\n ++s;\n }\n }\n\n return (s - cacheSize + 1) / (numIndices / 3);\n};\n\n/**\n * Optimizes triangles for the post-vertex shader cache.\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.indices Lists triads of numbers corresponding to the indices of the vertices\n * in the vertex buffer that define the geometry's triangles.\n * @param {number} [options.maximumIndex] The maximum value of the elements in args.indices.\n * If not supplied, this value will be computed.\n * @param {number} [options.cacheSize=24] The number of vertices that can be stored in the cache at any one time.\n * @returns {number[]} A list of the input indices in an optimized order.\n *\n * @exception {DeveloperError} indices length must be a multiple of three.\n * @exception {DeveloperError} cacheSize must be greater than two.\n *\n * @example\n * const indices = [0, 1, 2, 3, 4, 5];\n * const maxIndex = 5;\n * const cacheSize = 3;\n * const reorderedIndices = Cesium.Tipsify.tipsify({indices : indices, maxIndex : maxIndex, cacheSize : cacheSize});\n */\nTipsify.tipsify = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const indices = options.indices;\n const maximumIndex = options.maximumIndex;\n const cacheSize = defaultValue(options.cacheSize, 24);\n\n let cursor;\n\n function skipDeadEnd(vertices, deadEnd, indices, maximumIndexPlusOne) {\n while (deadEnd.length >= 1) {\n // while the stack is not empty\n const d = deadEnd[deadEnd.length - 1]; // top of the stack\n deadEnd.splice(deadEnd.length - 1, 1); // pop the stack\n\n if (vertices[d].numLiveTriangles > 0) {\n return d;\n }\n }\n\n while (cursor < maximumIndexPlusOne) {\n if (vertices[cursor].numLiveTriangles > 0) {\n ++cursor;\n return cursor - 1;\n }\n ++cursor;\n }\n return -1;\n }\n\n function getNextVertex(\n indices,\n cacheSize,\n oneRing,\n vertices,\n s,\n deadEnd,\n maximumIndexPlusOne\n ) {\n let n = -1;\n let p;\n let m = -1;\n let itOneRing = 0;\n while (itOneRing < oneRing.length) {\n const index = oneRing[itOneRing];\n if (vertices[index].numLiveTriangles) {\n p = 0;\n if (\n s -\n vertices[index].timeStamp +\n 2 * vertices[index].numLiveTriangles <=\n cacheSize\n ) {\n p = s - vertices[index].timeStamp;\n }\n if (p > m || m === -1) {\n m = p;\n n = index;\n }\n }\n ++itOneRing;\n }\n if (n === -1) {\n return skipDeadEnd(vertices, deadEnd, indices, maximumIndexPlusOne);\n }\n return n;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(indices)) {\n throw new DeveloperError(\"indices is required.\");\n }\n //>>includeEnd('debug');\n\n const numIndices = indices.length;\n\n //>>includeStart('debug', pragmas.debug);\n if (numIndices < 3 || numIndices % 3 !== 0) {\n throw new DeveloperError(\"indices length must be a multiple of three.\");\n }\n if (maximumIndex <= 0) {\n throw new DeveloperError(\"maximumIndex must be greater than zero.\");\n }\n if (cacheSize < 3) {\n throw new DeveloperError(\"cacheSize must be greater than two.\");\n }\n //>>includeEnd('debug');\n\n // Determine maximum index\n let maximumIndexPlusOne = 0;\n let currentIndex = 0;\n let intoIndices = indices[currentIndex];\n const endIndex = numIndices;\n if (defined(maximumIndex)) {\n maximumIndexPlusOne = maximumIndex + 1;\n } else {\n while (currentIndex < endIndex) {\n if (intoIndices > maximumIndexPlusOne) {\n maximumIndexPlusOne = intoIndices;\n }\n ++currentIndex;\n intoIndices = indices[currentIndex];\n }\n if (maximumIndexPlusOne === -1) {\n return 0;\n }\n ++maximumIndexPlusOne;\n }\n\n // Vertices\n const vertices = [];\n let i;\n for (i = 0; i < maximumIndexPlusOne; i++) {\n vertices[i] = {\n numLiveTriangles: 0,\n timeStamp: 0,\n vertexTriangles: [],\n };\n }\n currentIndex = 0;\n let triangle = 0;\n while (currentIndex < endIndex) {\n vertices[indices[currentIndex]].vertexTriangles.push(triangle);\n ++vertices[indices[currentIndex]].numLiveTriangles;\n vertices[indices[currentIndex + 1]].vertexTriangles.push(triangle);\n ++vertices[indices[currentIndex + 1]].numLiveTriangles;\n vertices[indices[currentIndex + 2]].vertexTriangles.push(triangle);\n ++vertices[indices[currentIndex + 2]].numLiveTriangles;\n ++triangle;\n currentIndex += 3;\n }\n\n // Starting index\n let f = 0;\n\n // Time Stamp\n let s = cacheSize + 1;\n cursor = 1;\n\n // Process\n let oneRing = [];\n const deadEnd = []; //Stack\n let vertex;\n let intoVertices;\n let currentOutputIndex = 0;\n const outputIndices = [];\n const numTriangles = numIndices / 3;\n const triangleEmitted = [];\n for (i = 0; i < numTriangles; i++) {\n triangleEmitted[i] = false;\n }\n let index;\n let limit;\n while (f !== -1) {\n oneRing = [];\n intoVertices = vertices[f];\n limit = intoVertices.vertexTriangles.length;\n for (let k = 0; k < limit; ++k) {\n triangle = intoVertices.vertexTriangles[k];\n if (!triangleEmitted[triangle]) {\n triangleEmitted[triangle] = true;\n currentIndex = triangle + triangle + triangle;\n for (let j = 0; j < 3; ++j) {\n // Set this index as a possible next index\n index = indices[currentIndex];\n oneRing.push(index);\n deadEnd.push(index);\n\n // Output index\n outputIndices[currentOutputIndex] = index;\n ++currentOutputIndex;\n\n // Cache processing\n vertex = vertices[index];\n --vertex.numLiveTriangles;\n if (s - vertex.timeStamp > cacheSize) {\n vertex.timeStamp = s;\n ++s;\n }\n ++currentIndex;\n }\n }\n }\n f = getNextVertex(\n indices,\n cacheSize,\n oneRing,\n vertices,\n s,\n deadEnd,\n maximumIndexPlusOne\n );\n }\n\n return outputIndices;\n};\nexport default Tipsify;\n", "import AttributeCompression from \"./AttributeCompression.js\";\nimport barycentricCoordinates from \"./barycentricCoordinates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport EncodedCartesian3 from \"./EncodedCartesian3.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryType from \"./GeometryType.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport Intersect from \"./Intersect.js\";\nimport IntersectionTests from \"./IntersectionTests.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Plane from \"./Plane.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Tipsify from \"./Tipsify.js\";\n\n/**\n * Content pipeline functions for geometries.\n *\n * @namespace GeometryPipeline\n *\n * @see Geometry\n */\nconst GeometryPipeline = {};\n\nfunction addTriangle(lines, index, i0, i1, i2) {\n lines[index++] = i0;\n lines[index++] = i1;\n\n lines[index++] = i1;\n lines[index++] = i2;\n\n lines[index++] = i2;\n lines[index] = i0;\n}\n\nfunction trianglesToLines(triangles) {\n const count = triangles.length;\n const size = (count / 3) * 6;\n const lines = IndexDatatype.createTypedArray(count, size);\n\n let index = 0;\n for (let i = 0; i < count; i += 3, index += 6) {\n addTriangle(lines, index, triangles[i], triangles[i + 1], triangles[i + 2]);\n }\n\n return lines;\n}\n\nfunction triangleStripToLines(triangles) {\n const count = triangles.length;\n if (count >= 3) {\n const size = (count - 2) * 6;\n const lines = IndexDatatype.createTypedArray(count, size);\n\n addTriangle(lines, 0, triangles[0], triangles[1], triangles[2]);\n let index = 6;\n\n for (let i = 3; i < count; ++i, index += 6) {\n addTriangle(\n lines,\n index,\n triangles[i - 1],\n triangles[i],\n triangles[i - 2]\n );\n }\n\n return lines;\n }\n\n return new Uint16Array();\n}\n\nfunction triangleFanToLines(triangles) {\n if (triangles.length > 0) {\n const count = triangles.length - 1;\n const size = (count - 1) * 6;\n const lines = IndexDatatype.createTypedArray(count, size);\n\n const base = triangles[0];\n let index = 0;\n for (let i = 1; i < count; ++i, index += 6) {\n addTriangle(lines, index, base, triangles[i], triangles[i + 1]);\n }\n\n return lines;\n }\n\n return new Uint16Array();\n}\n\n/**\n * Converts a geometry's triangle indices to line indices. If the geometry has an indices\n * and its primitiveType is TRIANGLES, TRIANGLE_STRIP,\n * TRIANGLE_FAN, it is converted to LINES; otherwise, the geometry is not changed.\n *

\n * This is commonly used to create a wireframe geometry for visual debugging.\n *

\n *\n * @param {Geometry} geometry The geometry to modify.\n * @returns {Geometry} The modified geometry argument, with its triangle indices converted to lines.\n *\n * @exception {DeveloperError} geometry.primitiveType must be TRIANGLES, TRIANGLE_STRIP, or TRIANGLE_FAN.\n *\n * @example\n * geometry = Cesium.GeometryPipeline.toWireframe(geometry);\n */\nGeometryPipeline.toWireframe = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug');\n\n const indices = geometry.indices;\n if (defined(indices)) {\n switch (geometry.primitiveType) {\n case PrimitiveType.TRIANGLES:\n geometry.indices = trianglesToLines(indices);\n break;\n case PrimitiveType.TRIANGLE_STRIP:\n geometry.indices = triangleStripToLines(indices);\n break;\n case PrimitiveType.TRIANGLE_FAN:\n geometry.indices = triangleFanToLines(indices);\n break;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\n \"geometry.primitiveType must be TRIANGLES, TRIANGLE_STRIP, or TRIANGLE_FAN.\"\n );\n //>>includeEnd('debug');\n }\n\n geometry.primitiveType = PrimitiveType.LINES;\n }\n\n return geometry;\n};\n\n/**\n * Creates a new {@link Geometry} with LINES representing the provided\n * attribute (attributeName) for the provided geometry. This is used to\n * visualize vector attributes like normals, tangents, and bitangents.\n *\n * @param {Geometry} geometry The Geometry instance with the attribute.\n * @param {string} [attributeName='normal'] The name of the attribute.\n * @param {number} [length=10000.0] The length of each line segment in meters. This can be negative to point the vector in the opposite direction.\n * @returns {Geometry} A new Geometry instance with line segments for the vector.\n *\n * @exception {DeveloperError} geometry.attributes must have an attribute with the same name as the attributeName parameter.\n *\n * @example\n * const geometry = Cesium.GeometryPipeline.createLineSegmentsForVectors(instance.geometry, 'bitangent', 100000.0);\n */\nGeometryPipeline.createLineSegmentsForVectors = function (\n geometry,\n attributeName,\n length\n) {\n attributeName = defaultValue(attributeName, \"normal\");\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n if (!defined(geometry.attributes.position)) {\n throw new DeveloperError(\"geometry.attributes.position is required.\");\n }\n if (!defined(geometry.attributes[attributeName])) {\n throw new DeveloperError(\n `geometry.attributes must have an attribute with the same name as the attributeName parameter, ${attributeName}.`\n );\n }\n //>>includeEnd('debug');\n\n length = defaultValue(length, 10000.0);\n\n const positions = geometry.attributes.position.values;\n const vectors = geometry.attributes[attributeName].values;\n const positionsLength = positions.length;\n\n const newPositions = new Float64Array(2 * positionsLength);\n\n let j = 0;\n for (let i = 0; i < positionsLength; i += 3) {\n newPositions[j++] = positions[i];\n newPositions[j++] = positions[i + 1];\n newPositions[j++] = positions[i + 2];\n\n newPositions[j++] = positions[i] + vectors[i] * length;\n newPositions[j++] = positions[i + 1] + vectors[i + 1] * length;\n newPositions[j++] = positions[i + 2] + vectors[i + 2] * length;\n }\n\n let newBoundingSphere;\n const bs = geometry.boundingSphere;\n if (defined(bs)) {\n newBoundingSphere = new BoundingSphere(bs.center, bs.radius + length);\n }\n\n return new Geometry({\n attributes: {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: newPositions,\n }),\n },\n primitiveType: PrimitiveType.LINES,\n boundingSphere: newBoundingSphere,\n });\n};\n\n/**\n * Creates an object that maps attribute names to unique locations (indices)\n * for matching vertex attributes and shader programs.\n *\n * @param {Geometry} geometry The geometry, which is not modified, to create the object for.\n * @returns {object} An object with attribute name / index pairs.\n *\n * @example\n * const attributeLocations = Cesium.GeometryPipeline.createAttributeLocations(geometry);\n * // Example output\n * // {\n * // 'position' : 0,\n * // 'normal' : 1\n * // }\n */\nGeometryPipeline.createAttributeLocations = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug')\n\n // There can be a WebGL performance hit when attribute 0 is disabled, so\n // assign attribute locations to well-known attributes.\n const semantics = [\n \"position\",\n \"positionHigh\",\n \"positionLow\",\n\n // From VertexFormat.position - after 2D projection and high-precision encoding\n \"position3DHigh\",\n \"position3DLow\",\n \"position2DHigh\",\n \"position2DLow\",\n\n // From Primitive\n \"pickColor\",\n\n // From VertexFormat\n \"normal\",\n \"st\",\n \"tangent\",\n \"bitangent\",\n\n // For shadow volumes\n \"extrudeDirection\",\n\n // From compressing texture coordinates and normals\n \"compressedAttributes\",\n ];\n\n const attributes = geometry.attributes;\n const indices = {};\n let j = 0;\n let i;\n const len = semantics.length;\n\n // Attribute locations for well-known attributes\n for (i = 0; i < len; ++i) {\n const semantic = semantics[i];\n\n if (defined(attributes[semantic])) {\n indices[semantic] = j++;\n }\n }\n\n // Locations for custom attributes\n for (const name in attributes) {\n if (attributes.hasOwnProperty(name) && !defined(indices[name])) {\n indices[name] = j++;\n }\n }\n\n return indices;\n};\n\n/**\n * Reorders a geometry's attributes and indices to achieve better performance from the GPU's pre-vertex-shader cache.\n *\n * @param {Geometry} geometry The geometry to modify.\n * @returns {Geometry} The modified geometry argument, with its attributes and indices reordered for the GPU's pre-vertex-shader cache.\n *\n * @exception {DeveloperError} Each attribute array in geometry.attributes must have the same number of attributes.\n *\n *\n * @example\n * geometry = Cesium.GeometryPipeline.reorderForPreVertexCache(geometry);\n *\n * @see GeometryPipeline.reorderForPostVertexCache\n */\nGeometryPipeline.reorderForPreVertexCache = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug');\n\n const numVertices = Geometry.computeNumberOfVertices(geometry);\n\n const indices = geometry.indices;\n if (defined(indices)) {\n const indexCrossReferenceOldToNew = new Int32Array(numVertices);\n for (let i = 0; i < numVertices; i++) {\n indexCrossReferenceOldToNew[i] = -1;\n }\n\n // Construct cross reference and reorder indices\n const indicesIn = indices;\n const numIndices = indicesIn.length;\n const indicesOut = IndexDatatype.createTypedArray(numVertices, numIndices);\n\n let intoIndicesIn = 0;\n let intoIndicesOut = 0;\n let nextIndex = 0;\n let tempIndex;\n while (intoIndicesIn < numIndices) {\n tempIndex = indexCrossReferenceOldToNew[indicesIn[intoIndicesIn]];\n if (tempIndex !== -1) {\n indicesOut[intoIndicesOut] = tempIndex;\n } else {\n tempIndex = indicesIn[intoIndicesIn];\n indexCrossReferenceOldToNew[tempIndex] = nextIndex;\n\n indicesOut[intoIndicesOut] = nextIndex;\n ++nextIndex;\n }\n ++intoIndicesIn;\n ++intoIndicesOut;\n }\n geometry.indices = indicesOut;\n\n // Reorder attributes\n const attributes = geometry.attributes;\n for (const property in attributes) {\n if (\n attributes.hasOwnProperty(property) &&\n defined(attributes[property]) &&\n defined(attributes[property].values)\n ) {\n const attribute = attributes[property];\n const elementsIn = attribute.values;\n let intoElementsIn = 0;\n const numComponents = attribute.componentsPerAttribute;\n const elementsOut = ComponentDatatype.createTypedArray(\n attribute.componentDatatype,\n nextIndex * numComponents\n );\n while (intoElementsIn < numVertices) {\n const temp = indexCrossReferenceOldToNew[intoElementsIn];\n if (temp !== -1) {\n for (let j = 0; j < numComponents; j++) {\n elementsOut[numComponents * temp + j] =\n elementsIn[numComponents * intoElementsIn + j];\n }\n }\n ++intoElementsIn;\n }\n attribute.values = elementsOut;\n }\n }\n }\n\n return geometry;\n};\n\n/**\n * Reorders a geometry's indices to achieve better performance from the GPU's\n * post vertex-shader cache by using the Tipsify algorithm. If the geometry primitiveType\n * is not TRIANGLES or the geometry does not have an indices, this function has no effect.\n *\n * @param {Geometry} geometry The geometry to modify.\n * @param {number} [cacheCapacity=24] The number of vertices that can be held in the GPU's vertex cache.\n * @returns {Geometry} The modified geometry argument, with its indices reordered for the post-vertex-shader cache.\n *\n * @exception {DeveloperError} cacheCapacity must be greater than two.\n *\n *\n * @example\n * geometry = Cesium.GeometryPipeline.reorderForPostVertexCache(geometry);\n *\n * @see GeometryPipeline.reorderForPreVertexCache\n * @see {@link http://gfx.cs.princ0eton.edu/pubs/Sander_2007_%3ETR/tipsy.pdf|Fast Triangle Reordering for Vertex Locality and Reduced Overdraw}\n * by Sander, Nehab, and Barczak\n */\nGeometryPipeline.reorderForPostVertexCache = function (\n geometry,\n cacheCapacity\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug');\n\n const indices = geometry.indices;\n if (geometry.primitiveType === PrimitiveType.TRIANGLES && defined(indices)) {\n const numIndices = indices.length;\n let maximumIndex = 0;\n for (let j = 0; j < numIndices; j++) {\n if (indices[j] > maximumIndex) {\n maximumIndex = indices[j];\n }\n }\n geometry.indices = Tipsify.tipsify({\n indices: indices,\n maximumIndex: maximumIndex,\n cacheSize: cacheCapacity,\n });\n }\n\n return geometry;\n};\n\nfunction copyAttributesDescriptions(attributes) {\n const newAttributes = {};\n\n for (const attribute in attributes) {\n if (\n attributes.hasOwnProperty(attribute) &&\n defined(attributes[attribute]) &&\n defined(attributes[attribute].values)\n ) {\n const attr = attributes[attribute];\n newAttributes[attribute] = new GeometryAttribute({\n componentDatatype: attr.componentDatatype,\n componentsPerAttribute: attr.componentsPerAttribute,\n normalize: attr.normalize,\n values: [],\n });\n }\n }\n\n return newAttributes;\n}\n\nfunction copyVertex(destinationAttributes, sourceAttributes, index) {\n for (const attribute in sourceAttributes) {\n if (\n sourceAttributes.hasOwnProperty(attribute) &&\n defined(sourceAttributes[attribute]) &&\n defined(sourceAttributes[attribute].values)\n ) {\n const attr = sourceAttributes[attribute];\n\n for (let k = 0; k < attr.componentsPerAttribute; ++k) {\n destinationAttributes[attribute].values.push(\n attr.values[index * attr.componentsPerAttribute + k]\n );\n }\n }\n }\n}\n\n/**\n * Splits a geometry into multiple geometries, if necessary, to ensure that indices in the\n * indices fit into unsigned shorts. This is used to meet the WebGL requirements\n * when unsigned int indices are not supported.\n *

\n * If the geometry does not have any indices, this function has no effect.\n *

\n *\n * @param {Geometry} geometry The geometry to be split into multiple geometries.\n * @returns {Geometry[]} An array of geometries, each with indices that fit into unsigned shorts.\n *\n * @exception {DeveloperError} geometry.primitiveType must equal to PrimitiveType.TRIANGLES, PrimitiveType.LINES, or PrimitiveType.POINTS\n * @exception {DeveloperError} All geometry attribute lists must have the same number of attributes.\n *\n * @example\n * const geometries = Cesium.GeometryPipeline.fitToUnsignedShortIndices(geometry);\n */\nGeometryPipeline.fitToUnsignedShortIndices = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n if (\n defined(geometry.indices) &&\n geometry.primitiveType !== PrimitiveType.TRIANGLES &&\n geometry.primitiveType !== PrimitiveType.LINES &&\n geometry.primitiveType !== PrimitiveType.POINTS\n ) {\n throw new DeveloperError(\n \"geometry.primitiveType must equal to PrimitiveType.TRIANGLES, PrimitiveType.LINES, or PrimitiveType.POINTS.\"\n );\n }\n //>>includeEnd('debug');\n\n const geometries = [];\n\n // If there's an index list and more than 64K attributes, it is possible that\n // some indices are outside the range of unsigned short [0, 64K - 1]\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n if (\n defined(geometry.indices) &&\n numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES\n ) {\n let oldToNewIndex = [];\n let newIndices = [];\n let currentIndex = 0;\n let newAttributes = copyAttributesDescriptions(geometry.attributes);\n\n const originalIndices = geometry.indices;\n const numberOfIndices = originalIndices.length;\n\n let indicesPerPrimitive;\n\n if (geometry.primitiveType === PrimitiveType.TRIANGLES) {\n indicesPerPrimitive = 3;\n } else if (geometry.primitiveType === PrimitiveType.LINES) {\n indicesPerPrimitive = 2;\n } else if (geometry.primitiveType === PrimitiveType.POINTS) {\n indicesPerPrimitive = 1;\n }\n\n for (let j = 0; j < numberOfIndices; j += indicesPerPrimitive) {\n for (let k = 0; k < indicesPerPrimitive; ++k) {\n const x = originalIndices[j + k];\n let i = oldToNewIndex[x];\n if (!defined(i)) {\n i = currentIndex++;\n oldToNewIndex[x] = i;\n copyVertex(newAttributes, geometry.attributes, x);\n }\n newIndices.push(i);\n }\n\n if (\n currentIndex + indicesPerPrimitive >=\n CesiumMath.SIXTY_FOUR_KILOBYTES\n ) {\n geometries.push(\n new Geometry({\n attributes: newAttributes,\n indices: newIndices,\n primitiveType: geometry.primitiveType,\n boundingSphere: geometry.boundingSphere,\n boundingSphereCV: geometry.boundingSphereCV,\n })\n );\n\n // Reset for next vertex-array\n oldToNewIndex = [];\n newIndices = [];\n currentIndex = 0;\n newAttributes = copyAttributesDescriptions(geometry.attributes);\n }\n }\n\n if (newIndices.length !== 0) {\n geometries.push(\n new Geometry({\n attributes: newAttributes,\n indices: newIndices,\n primitiveType: geometry.primitiveType,\n boundingSphere: geometry.boundingSphere,\n boundingSphereCV: geometry.boundingSphereCV,\n })\n );\n }\n } else {\n // No need to split into multiple geometries\n geometries.push(geometry);\n }\n\n return geometries;\n};\n\nconst scratchProjectTo2DCartesian3 = new Cartesian3();\nconst scratchProjectTo2DCartographic = new Cartographic();\n\n/**\n * Projects a geometry's 3D position attribute to 2D, replacing the position\n * attribute with separate position3D and position2D attributes.\n *

\n * If the geometry does not have a position, this function has no effect.\n *

\n *\n * @param {Geometry} geometry The geometry to modify.\n * @param {string} attributeName The name of the attribute.\n * @param {string} attributeName3D The name of the attribute in 3D.\n * @param {string} attributeName2D The name of the attribute in 2D.\n * @param {object} [projection=new GeographicProjection()] The projection to use.\n * @returns {Geometry} The modified geometry argument with position3D and position2D attributes.\n *\n * @exception {DeveloperError} geometry must have attribute matching the attributeName argument.\n * @exception {DeveloperError} The attribute componentDatatype must be ComponentDatatype.DOUBLE.\n * @exception {DeveloperError} Could not project a point to 2D.\n *\n * @example\n * geometry = Cesium.GeometryPipeline.projectTo2D(geometry, 'position', 'position3D', 'position2D');\n */\nGeometryPipeline.projectTo2D = function (\n geometry,\n attributeName,\n attributeName3D,\n attributeName2D,\n projection\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n if (!defined(attributeName)) {\n throw new DeveloperError(\"attributeName is required.\");\n }\n if (!defined(attributeName3D)) {\n throw new DeveloperError(\"attributeName3D is required.\");\n }\n if (!defined(attributeName2D)) {\n throw new DeveloperError(\"attributeName2D is required.\");\n }\n if (!defined(geometry.attributes[attributeName])) {\n throw new DeveloperError(\n `geometry must have attribute matching the attributeName argument: ${attributeName}.`\n );\n }\n if (\n geometry.attributes[attributeName].componentDatatype !==\n ComponentDatatype.DOUBLE\n ) {\n throw new DeveloperError(\n \"The attribute componentDatatype must be ComponentDatatype.DOUBLE.\"\n );\n }\n //>>includeEnd('debug');\n\n const attribute = geometry.attributes[attributeName];\n projection = defined(projection) ? projection : new GeographicProjection();\n const ellipsoid = projection.ellipsoid;\n\n // Project original values to 2D.\n const values3D = attribute.values;\n const projectedValues = new Float64Array(values3D.length);\n let index = 0;\n\n for (let i = 0; i < values3D.length; i += 3) {\n const value = Cartesian3.fromArray(\n values3D,\n i,\n scratchProjectTo2DCartesian3\n );\n\n const lonLat = ellipsoid.cartesianToCartographic(\n value,\n scratchProjectTo2DCartographic\n );\n //>>includeStart('debug', pragmas.debug);\n if (!defined(lonLat)) {\n throw new DeveloperError(\n `Could not project point (${value.x}, ${value.y}, ${value.z}) to 2D.`\n );\n }\n //>>includeEnd('debug');\n\n const projectedLonLat = projection.project(\n lonLat,\n scratchProjectTo2DCartesian3\n );\n\n projectedValues[index++] = projectedLonLat.x;\n projectedValues[index++] = projectedLonLat.y;\n projectedValues[index++] = projectedLonLat.z;\n }\n\n // Rename original cartesians to WGS84 cartesians.\n geometry.attributes[attributeName3D] = attribute;\n\n // Replace original cartesians with 2D projected cartesians\n geometry.attributes[attributeName2D] = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: projectedValues,\n });\n delete geometry.attributes[attributeName];\n\n return geometry;\n};\n\nconst encodedResult = {\n high: 0.0,\n low: 0.0,\n};\n\n/**\n * Encodes floating-point geometry attribute values as two separate attributes to improve\n * rendering precision.\n *

\n * This is commonly used to create high-precision position vertex attributes.\n *

\n *\n * @param {Geometry} geometry The geometry to modify.\n * @param {string} attributeName The name of the attribute.\n * @param {string} attributeHighName The name of the attribute for the encoded high bits.\n * @param {string} attributeLowName The name of the attribute for the encoded low bits.\n * @returns {Geometry} The modified geometry argument, with its encoded attribute.\n *\n * @exception {DeveloperError} geometry must have attribute matching the attributeName argument.\n * @exception {DeveloperError} The attribute componentDatatype must be ComponentDatatype.DOUBLE.\n *\n * @example\n * geometry = Cesium.GeometryPipeline.encodeAttribute(geometry, 'position3D', 'position3DHigh', 'position3DLow');\n */\nGeometryPipeline.encodeAttribute = function (\n geometry,\n attributeName,\n attributeHighName,\n attributeLowName\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n if (!defined(attributeName)) {\n throw new DeveloperError(\"attributeName is required.\");\n }\n if (!defined(attributeHighName)) {\n throw new DeveloperError(\"attributeHighName is required.\");\n }\n if (!defined(attributeLowName)) {\n throw new DeveloperError(\"attributeLowName is required.\");\n }\n if (!defined(geometry.attributes[attributeName])) {\n throw new DeveloperError(\n `geometry must have attribute matching the attributeName argument: ${attributeName}.`\n );\n }\n if (\n geometry.attributes[attributeName].componentDatatype !==\n ComponentDatatype.DOUBLE\n ) {\n throw new DeveloperError(\n \"The attribute componentDatatype must be ComponentDatatype.DOUBLE.\"\n );\n }\n //>>includeEnd('debug');\n\n const attribute = geometry.attributes[attributeName];\n const values = attribute.values;\n const length = values.length;\n const highValues = new Float32Array(length);\n const lowValues = new Float32Array(length);\n\n for (let i = 0; i < length; ++i) {\n EncodedCartesian3.encode(values[i], encodedResult);\n highValues[i] = encodedResult.high;\n lowValues[i] = encodedResult.low;\n }\n\n const componentsPerAttribute = attribute.componentsPerAttribute;\n\n geometry.attributes[attributeHighName] = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: componentsPerAttribute,\n values: highValues,\n });\n geometry.attributes[attributeLowName] = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: componentsPerAttribute,\n values: lowValues,\n });\n delete geometry.attributes[attributeName];\n\n return geometry;\n};\n\nlet scratchCartesian3 = new Cartesian3();\n\nfunction transformPoint(matrix, attribute) {\n if (defined(attribute)) {\n const values = attribute.values;\n const length = values.length;\n for (let i = 0; i < length; i += 3) {\n Cartesian3.unpack(values, i, scratchCartesian3);\n Matrix4.multiplyByPoint(matrix, scratchCartesian3, scratchCartesian3);\n Cartesian3.pack(scratchCartesian3, values, i);\n }\n }\n}\n\nfunction transformVector(matrix, attribute) {\n if (defined(attribute)) {\n const values = attribute.values;\n const length = values.length;\n for (let i = 0; i < length; i += 3) {\n Cartesian3.unpack(values, i, scratchCartesian3);\n Matrix3.multiplyByVector(matrix, scratchCartesian3, scratchCartesian3);\n scratchCartesian3 = Cartesian3.normalize(\n scratchCartesian3,\n scratchCartesian3\n );\n Cartesian3.pack(scratchCartesian3, values, i);\n }\n }\n}\n\nconst inverseTranspose = new Matrix4();\nconst normalMatrix = new Matrix3();\n\n/**\n * Transforms a geometry instance to world coordinates. This changes\n * the instance's modelMatrix to {@link Matrix4.IDENTITY} and transforms the\n * following attributes if they are present: position, normal,\n * tangent, and bitangent.\n *\n * @param {GeometryInstance} instance The geometry instance to modify.\n * @returns {GeometryInstance} The modified instance argument, with its attributes transforms to world coordinates.\n *\n * @example\n * Cesium.GeometryPipeline.transformToWorldCoordinates(instance);\n */\nGeometryPipeline.transformToWorldCoordinates = function (instance) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(instance)) {\n throw new DeveloperError(\"instance is required.\");\n }\n //>>includeEnd('debug');\n\n const modelMatrix = instance.modelMatrix;\n\n if (Matrix4.equals(modelMatrix, Matrix4.IDENTITY)) {\n // Already in world coordinates\n return instance;\n }\n\n const attributes = instance.geometry.attributes;\n\n // Transform attributes in known vertex formats\n transformPoint(modelMatrix, attributes.position);\n transformPoint(modelMatrix, attributes.prevPosition);\n transformPoint(modelMatrix, attributes.nextPosition);\n\n if (\n defined(attributes.normal) ||\n defined(attributes.tangent) ||\n defined(attributes.bitangent)\n ) {\n Matrix4.inverse(modelMatrix, inverseTranspose);\n Matrix4.transpose(inverseTranspose, inverseTranspose);\n Matrix4.getMatrix3(inverseTranspose, normalMatrix);\n\n transformVector(normalMatrix, attributes.normal);\n transformVector(normalMatrix, attributes.tangent);\n transformVector(normalMatrix, attributes.bitangent);\n }\n\n const boundingSphere = instance.geometry.boundingSphere;\n if (defined(boundingSphere)) {\n instance.geometry.boundingSphere = BoundingSphere.transform(\n boundingSphere,\n modelMatrix,\n boundingSphere\n );\n }\n\n instance.modelMatrix = Matrix4.clone(Matrix4.IDENTITY);\n\n return instance;\n};\n\nfunction findAttributesInAllGeometries(instances, propertyName) {\n const length = instances.length;\n\n const attributesInAllGeometries = {};\n\n const attributes0 = instances[0][propertyName].attributes;\n let name;\n\n for (name in attributes0) {\n if (\n attributes0.hasOwnProperty(name) &&\n defined(attributes0[name]) &&\n defined(attributes0[name].values)\n ) {\n const attribute = attributes0[name];\n let numberOfComponents = attribute.values.length;\n let inAllGeometries = true;\n\n // Does this same attribute exist in all geometries?\n for (let i = 1; i < length; ++i) {\n const otherAttribute = instances[i][propertyName].attributes[name];\n\n if (\n !defined(otherAttribute) ||\n attribute.componentDatatype !== otherAttribute.componentDatatype ||\n attribute.componentsPerAttribute !==\n otherAttribute.componentsPerAttribute ||\n attribute.normalize !== otherAttribute.normalize\n ) {\n inAllGeometries = false;\n break;\n }\n\n numberOfComponents += otherAttribute.values.length;\n }\n\n if (inAllGeometries) {\n attributesInAllGeometries[name] = new GeometryAttribute({\n componentDatatype: attribute.componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n values: ComponentDatatype.createTypedArray(\n attribute.componentDatatype,\n numberOfComponents\n ),\n });\n }\n }\n }\n\n return attributesInAllGeometries;\n}\n\nconst tempScratch = new Cartesian3();\n\nfunction combineGeometries(instances, propertyName) {\n const length = instances.length;\n\n let name;\n let i;\n let j;\n let k;\n\n const m = instances[0].modelMatrix;\n const haveIndices = defined(instances[0][propertyName].indices);\n const primitiveType = instances[0][propertyName].primitiveType;\n\n //>>includeStart('debug', pragmas.debug);\n for (i = 1; i < length; ++i) {\n if (!Matrix4.equals(instances[i].modelMatrix, m)) {\n throw new DeveloperError(\"All instances must have the same modelMatrix.\");\n }\n if (defined(instances[i][propertyName].indices) !== haveIndices) {\n throw new DeveloperError(\n \"All instance geometries must have an indices or not have one.\"\n );\n }\n if (instances[i][propertyName].primitiveType !== primitiveType) {\n throw new DeveloperError(\n \"All instance geometries must have the same primitiveType.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n // Find subset of attributes in all geometries\n const attributes = findAttributesInAllGeometries(instances, propertyName);\n let values;\n let sourceValues;\n let sourceValuesLength;\n\n // Combine attributes from each geometry into a single typed array\n for (name in attributes) {\n if (attributes.hasOwnProperty(name)) {\n values = attributes[name].values;\n\n k = 0;\n for (i = 0; i < length; ++i) {\n sourceValues = instances[i][propertyName].attributes[name].values;\n sourceValuesLength = sourceValues.length;\n\n for (j = 0; j < sourceValuesLength; ++j) {\n values[k++] = sourceValues[j];\n }\n }\n }\n }\n\n // Combine index lists\n let indices;\n\n if (haveIndices) {\n let numberOfIndices = 0;\n for (i = 0; i < length; ++i) {\n numberOfIndices += instances[i][propertyName].indices.length;\n }\n\n const numberOfVertices = Geometry.computeNumberOfVertices(\n new Geometry({\n attributes: attributes,\n primitiveType: PrimitiveType.POINTS,\n })\n );\n const destIndices = IndexDatatype.createTypedArray(\n numberOfVertices,\n numberOfIndices\n );\n\n let destOffset = 0;\n let offset = 0;\n\n for (i = 0; i < length; ++i) {\n const sourceIndices = instances[i][propertyName].indices;\n const sourceIndicesLen = sourceIndices.length;\n\n for (k = 0; k < sourceIndicesLen; ++k) {\n destIndices[destOffset++] = offset + sourceIndices[k];\n }\n\n offset += Geometry.computeNumberOfVertices(instances[i][propertyName]);\n }\n\n indices = destIndices;\n }\n\n // Create bounding sphere that includes all instances\n let center = new Cartesian3();\n let radius = 0.0;\n let bs;\n\n for (i = 0; i < length; ++i) {\n bs = instances[i][propertyName].boundingSphere;\n if (!defined(bs)) {\n // If any geometries have an undefined bounding sphere, then so does the combined geometry\n center = undefined;\n break;\n }\n\n Cartesian3.add(bs.center, center, center);\n }\n\n if (defined(center)) {\n Cartesian3.divideByScalar(center, length, center);\n\n for (i = 0; i < length; ++i) {\n bs = instances[i][propertyName].boundingSphere;\n const tempRadius =\n Cartesian3.magnitude(\n Cartesian3.subtract(bs.center, center, tempScratch)\n ) + bs.radius;\n\n if (tempRadius > radius) {\n radius = tempRadius;\n }\n }\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: primitiveType,\n boundingSphere: defined(center)\n ? new BoundingSphere(center, radius)\n : undefined,\n });\n}\n\n/**\n * Combines geometry from several {@link GeometryInstance} objects into one geometry.\n * This concatenates the attributes, concatenates and adjusts the indices, and creates\n * a bounding sphere encompassing all instances.\n *

\n * If the instances do not have the same attributes, a subset of attributes common\n * to all instances is used, and the others are ignored.\n *

\n *

\n * This is used by {@link Primitive} to efficiently render a large amount of static data.\n *

\n *\n * @private\n *\n * @param {GeometryInstance[]} [instances] The array of {@link GeometryInstance} objects whose geometry will be combined.\n * @returns {Geometry} A single geometry created from the provided geometry instances.\n *\n * @exception {DeveloperError} All instances must have the same modelMatrix.\n * @exception {DeveloperError} All instance geometries must have an indices or not have one.\n * @exception {DeveloperError} All instance geometries must have the same primitiveType.\n *\n *\n * @example\n * for (let i = 0; i < instances.length; ++i) {\n * Cesium.GeometryPipeline.transformToWorldCoordinates(instances[i]);\n * }\n * const geometries = Cesium.GeometryPipeline.combineInstances(instances);\n *\n * @see GeometryPipeline.transformToWorldCoordinates\n */\nGeometryPipeline.combineInstances = function (instances) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(instances) || instances.length < 1) {\n throw new DeveloperError(\n \"instances is required and must have length greater than zero.\"\n );\n }\n //>>includeEnd('debug');\n\n const instanceGeometry = [];\n const instanceSplitGeometry = [];\n const length = instances.length;\n for (let i = 0; i < length; ++i) {\n const instance = instances[i];\n\n if (defined(instance.geometry)) {\n instanceGeometry.push(instance);\n } else if (\n defined(instance.westHemisphereGeometry) &&\n defined(instance.eastHemisphereGeometry)\n ) {\n instanceSplitGeometry.push(instance);\n }\n }\n\n const geometries = [];\n if (instanceGeometry.length > 0) {\n geometries.push(combineGeometries(instanceGeometry, \"geometry\"));\n }\n\n if (instanceSplitGeometry.length > 0) {\n geometries.push(\n combineGeometries(instanceSplitGeometry, \"westHemisphereGeometry\")\n );\n geometries.push(\n combineGeometries(instanceSplitGeometry, \"eastHemisphereGeometry\")\n );\n }\n\n return geometries;\n};\n\nconst normal = new Cartesian3();\nconst v0 = new Cartesian3();\nconst v1 = new Cartesian3();\nconst v2 = new Cartesian3();\n\n/**\n * Computes per-vertex normals for a geometry containing TRIANGLES by averaging the normals of\n * all triangles incident to the vertex. The result is a new normal attribute added to the geometry.\n * This assumes a counter-clockwise winding order.\n *\n * @param {Geometry} geometry The geometry to modify.\n * @returns {Geometry} The modified geometry argument with the computed normal attribute.\n *\n * @exception {DeveloperError} geometry.indices length must be greater than 0 and be a multiple of 3.\n * @exception {DeveloperError} geometry.primitiveType must be {@link PrimitiveType.TRIANGLES}.\n *\n * @example\n * Cesium.GeometryPipeline.computeNormal(geometry);\n */\nGeometryPipeline.computeNormal = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n if (\n !defined(geometry.attributes.position) ||\n !defined(geometry.attributes.position.values)\n ) {\n throw new DeveloperError(\n \"geometry.attributes.position.values is required.\"\n );\n }\n if (!defined(geometry.indices)) {\n throw new DeveloperError(\"geometry.indices is required.\");\n }\n if (geometry.indices.length < 2 || geometry.indices.length % 3 !== 0) {\n throw new DeveloperError(\n \"geometry.indices length must be greater than 0 and be a multiple of 3.\"\n );\n }\n if (geometry.primitiveType !== PrimitiveType.TRIANGLES) {\n throw new DeveloperError(\n \"geometry.primitiveType must be PrimitiveType.TRIANGLES.\"\n );\n }\n //>>includeEnd('debug');\n\n const indices = geometry.indices;\n const attributes = geometry.attributes;\n const vertices = attributes.position.values;\n const numVertices = attributes.position.values.length / 3;\n const numIndices = indices.length;\n const normalsPerVertex = new Array(numVertices);\n const normalsPerTriangle = new Array(numIndices / 3);\n const normalIndices = new Array(numIndices);\n let i;\n for (i = 0; i < numVertices; i++) {\n normalsPerVertex[i] = {\n indexOffset: 0,\n count: 0,\n currentCount: 0,\n };\n }\n\n let j = 0;\n for (i = 0; i < numIndices; i += 3) {\n const i0 = indices[i];\n const i1 = indices[i + 1];\n const i2 = indices[i + 2];\n const i03 = i0 * 3;\n const i13 = i1 * 3;\n const i23 = i2 * 3;\n\n v0.x = vertices[i03];\n v0.y = vertices[i03 + 1];\n v0.z = vertices[i03 + 2];\n v1.x = vertices[i13];\n v1.y = vertices[i13 + 1];\n v1.z = vertices[i13 + 2];\n v2.x = vertices[i23];\n v2.y = vertices[i23 + 1];\n v2.z = vertices[i23 + 2];\n\n normalsPerVertex[i0].count++;\n normalsPerVertex[i1].count++;\n normalsPerVertex[i2].count++;\n\n Cartesian3.subtract(v1, v0, v1);\n Cartesian3.subtract(v2, v0, v2);\n normalsPerTriangle[j] = Cartesian3.cross(v1, v2, new Cartesian3());\n j++;\n }\n\n let indexOffset = 0;\n for (i = 0; i < numVertices; i++) {\n normalsPerVertex[i].indexOffset += indexOffset;\n indexOffset += normalsPerVertex[i].count;\n }\n\n j = 0;\n let vertexNormalData;\n for (i = 0; i < numIndices; i += 3) {\n vertexNormalData = normalsPerVertex[indices[i]];\n let index = vertexNormalData.indexOffset + vertexNormalData.currentCount;\n normalIndices[index] = j;\n vertexNormalData.currentCount++;\n\n vertexNormalData = normalsPerVertex[indices[i + 1]];\n index = vertexNormalData.indexOffset + vertexNormalData.currentCount;\n normalIndices[index] = j;\n vertexNormalData.currentCount++;\n\n vertexNormalData = normalsPerVertex[indices[i + 2]];\n index = vertexNormalData.indexOffset + vertexNormalData.currentCount;\n normalIndices[index] = j;\n vertexNormalData.currentCount++;\n\n j++;\n }\n\n const normalValues = new Float32Array(numVertices * 3);\n for (i = 0; i < numVertices; i++) {\n const i3 = i * 3;\n vertexNormalData = normalsPerVertex[i];\n Cartesian3.clone(Cartesian3.ZERO, normal);\n if (vertexNormalData.count > 0) {\n for (j = 0; j < vertexNormalData.count; j++) {\n Cartesian3.add(\n normal,\n normalsPerTriangle[normalIndices[vertexNormalData.indexOffset + j]],\n normal\n );\n }\n\n // We can run into an issue where a vertex is used with 2 primitives that have opposite winding order.\n if (\n Cartesian3.equalsEpsilon(Cartesian3.ZERO, normal, CesiumMath.EPSILON10)\n ) {\n Cartesian3.clone(\n normalsPerTriangle[normalIndices[vertexNormalData.indexOffset]],\n normal\n );\n }\n }\n\n // We end up with a zero vector probably because of a degenerate triangle\n if (\n Cartesian3.equalsEpsilon(Cartesian3.ZERO, normal, CesiumMath.EPSILON10)\n ) {\n // Default to (0,0,1)\n normal.z = 1.0;\n }\n\n Cartesian3.normalize(normal, normal);\n normalValues[i3] = normal.x;\n normalValues[i3 + 1] = normal.y;\n normalValues[i3 + 2] = normal.z;\n }\n\n geometry.attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normalValues,\n });\n\n return geometry;\n};\n\nconst normalScratch = new Cartesian3();\nconst normalScale = new Cartesian3();\nconst tScratch = new Cartesian3();\n\n/**\n * Computes per-vertex tangents and bitangents for a geometry containing TRIANGLES.\n * The result is new tangent and bitangent attributes added to the geometry.\n * This assumes a counter-clockwise winding order.\n *

\n * Based on Computing Tangent Space Basis Vectors\n * for an Arbitrary Mesh by Eric Lengyel.\n *

\n *\n * @param {Geometry} geometry The geometry to modify.\n * @returns {Geometry} The modified geometry argument with the computed tangent and bitangent attributes.\n *\n * @exception {DeveloperError} geometry.indices length must be greater than 0 and be a multiple of 3.\n * @exception {DeveloperError} geometry.primitiveType must be {@link PrimitiveType.TRIANGLES}.\n *\n * @example\n * Cesium.GeometryPipeline.computeTangentAndBiTangent(geometry);\n */\nGeometryPipeline.computeTangentAndBitangent = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug');\n\n const attributes = geometry.attributes;\n const indices = geometry.indices;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(attributes.position) || !defined(attributes.position.values)) {\n throw new DeveloperError(\n \"geometry.attributes.position.values is required.\"\n );\n }\n if (!defined(attributes.normal) || !defined(attributes.normal.values)) {\n throw new DeveloperError(\"geometry.attributes.normal.values is required.\");\n }\n if (!defined(attributes.st) || !defined(attributes.st.values)) {\n throw new DeveloperError(\"geometry.attributes.st.values is required.\");\n }\n if (!defined(indices)) {\n throw new DeveloperError(\"geometry.indices is required.\");\n }\n if (indices.length < 2 || indices.length % 3 !== 0) {\n throw new DeveloperError(\n \"geometry.indices length must be greater than 0 and be a multiple of 3.\"\n );\n }\n if (geometry.primitiveType !== PrimitiveType.TRIANGLES) {\n throw new DeveloperError(\n \"geometry.primitiveType must be PrimitiveType.TRIANGLES.\"\n );\n }\n //>>includeEnd('debug');\n\n const vertices = geometry.attributes.position.values;\n const normals = geometry.attributes.normal.values;\n const st = geometry.attributes.st.values;\n\n const numVertices = geometry.attributes.position.values.length / 3;\n const numIndices = indices.length;\n const tan1 = new Array(numVertices * 3);\n\n let i;\n for (i = 0; i < tan1.length; i++) {\n tan1[i] = 0;\n }\n\n let i03;\n let i13;\n let i23;\n for (i = 0; i < numIndices; i += 3) {\n const i0 = indices[i];\n const i1 = indices[i + 1];\n const i2 = indices[i + 2];\n i03 = i0 * 3;\n i13 = i1 * 3;\n i23 = i2 * 3;\n const i02 = i0 * 2;\n const i12 = i1 * 2;\n const i22 = i2 * 2;\n\n const ux = vertices[i03];\n const uy = vertices[i03 + 1];\n const uz = vertices[i03 + 2];\n\n const wx = st[i02];\n const wy = st[i02 + 1];\n const t1 = st[i12 + 1] - wy;\n const t2 = st[i22 + 1] - wy;\n\n const r = 1.0 / ((st[i12] - wx) * t2 - (st[i22] - wx) * t1);\n const sdirx = (t2 * (vertices[i13] - ux) - t1 * (vertices[i23] - ux)) * r;\n const sdiry =\n (t2 * (vertices[i13 + 1] - uy) - t1 * (vertices[i23 + 1] - uy)) * r;\n const sdirz =\n (t2 * (vertices[i13 + 2] - uz) - t1 * (vertices[i23 + 2] - uz)) * r;\n\n tan1[i03] += sdirx;\n tan1[i03 + 1] += sdiry;\n tan1[i03 + 2] += sdirz;\n\n tan1[i13] += sdirx;\n tan1[i13 + 1] += sdiry;\n tan1[i13 + 2] += sdirz;\n\n tan1[i23] += sdirx;\n tan1[i23 + 1] += sdiry;\n tan1[i23 + 2] += sdirz;\n }\n\n const tangentValues = new Float32Array(numVertices * 3);\n const bitangentValues = new Float32Array(numVertices * 3);\n\n for (i = 0; i < numVertices; i++) {\n i03 = i * 3;\n i13 = i03 + 1;\n i23 = i03 + 2;\n\n const n = Cartesian3.fromArray(normals, i03, normalScratch);\n const t = Cartesian3.fromArray(tan1, i03, tScratch);\n const scalar = Cartesian3.dot(n, t);\n Cartesian3.multiplyByScalar(n, scalar, normalScale);\n Cartesian3.normalize(Cartesian3.subtract(t, normalScale, t), t);\n\n tangentValues[i03] = t.x;\n tangentValues[i13] = t.y;\n tangentValues[i23] = t.z;\n\n Cartesian3.normalize(Cartesian3.cross(n, t, t), t);\n\n bitangentValues[i03] = t.x;\n bitangentValues[i13] = t.y;\n bitangentValues[i23] = t.z;\n }\n\n geometry.attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangentValues,\n });\n\n geometry.attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangentValues,\n });\n\n return geometry;\n};\n\nconst scratchCartesian2 = new Cartesian2();\nconst toEncode1 = new Cartesian3();\nconst toEncode2 = new Cartesian3();\nconst toEncode3 = new Cartesian3();\nlet encodeResult2 = new Cartesian2();\n/**\n * Compresses and packs geometry normal attribute values to save memory.\n *\n * @param {Geometry} geometry The geometry to modify.\n * @returns {Geometry} The modified geometry argument, with its normals compressed and packed.\n *\n * @example\n * geometry = Cesium.GeometryPipeline.compressVertices(geometry);\n */\nGeometryPipeline.compressVertices = function (geometry) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry)) {\n throw new DeveloperError(\"geometry is required.\");\n }\n //>>includeEnd('debug');\n\n const extrudeAttribute = geometry.attributes.extrudeDirection;\n let i;\n let numVertices;\n if (defined(extrudeAttribute)) {\n //only shadow volumes use extrudeDirection, and shadow volumes use vertexFormat: POSITION_ONLY so we don't need to check other attributes\n const extrudeDirections = extrudeAttribute.values;\n numVertices = extrudeDirections.length / 3.0;\n const compressedDirections = new Float32Array(numVertices * 2);\n\n let i2 = 0;\n for (i = 0; i < numVertices; ++i) {\n Cartesian3.fromArray(extrudeDirections, i * 3.0, toEncode1);\n if (Cartesian3.equals(toEncode1, Cartesian3.ZERO)) {\n i2 += 2;\n continue;\n }\n encodeResult2 = AttributeCompression.octEncodeInRange(\n toEncode1,\n 65535,\n encodeResult2\n );\n compressedDirections[i2++] = encodeResult2.x;\n compressedDirections[i2++] = encodeResult2.y;\n }\n\n geometry.attributes.compressedAttributes = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: compressedDirections,\n });\n delete geometry.attributes.extrudeDirection;\n return geometry;\n }\n\n const normalAttribute = geometry.attributes.normal;\n const stAttribute = geometry.attributes.st;\n\n const hasNormal = defined(normalAttribute);\n const hasSt = defined(stAttribute);\n if (!hasNormal && !hasSt) {\n return geometry;\n }\n\n const tangentAttribute = geometry.attributes.tangent;\n const bitangentAttribute = geometry.attributes.bitangent;\n\n const hasTangent = defined(tangentAttribute);\n const hasBitangent = defined(bitangentAttribute);\n\n let normals;\n let st;\n let tangents;\n let bitangents;\n\n if (hasNormal) {\n normals = normalAttribute.values;\n }\n if (hasSt) {\n st = stAttribute.values;\n }\n if (hasTangent) {\n tangents = tangentAttribute.values;\n }\n if (hasBitangent) {\n bitangents = bitangentAttribute.values;\n }\n\n const length = hasNormal ? normals.length : st.length;\n const numComponents = hasNormal ? 3.0 : 2.0;\n numVertices = length / numComponents;\n\n let compressedLength = numVertices;\n let numCompressedComponents = hasSt && hasNormal ? 2.0 : 1.0;\n numCompressedComponents += hasTangent || hasBitangent ? 1.0 : 0.0;\n compressedLength *= numCompressedComponents;\n\n const compressedAttributes = new Float32Array(compressedLength);\n\n let normalIndex = 0;\n for (i = 0; i < numVertices; ++i) {\n if (hasSt) {\n Cartesian2.fromArray(st, i * 2.0, scratchCartesian2);\n compressedAttributes[\n normalIndex++\n ] = AttributeCompression.compressTextureCoordinates(scratchCartesian2);\n }\n\n const index = i * 3.0;\n if (hasNormal && defined(tangents) && defined(bitangents)) {\n Cartesian3.fromArray(normals, index, toEncode1);\n Cartesian3.fromArray(tangents, index, toEncode2);\n Cartesian3.fromArray(bitangents, index, toEncode3);\n\n AttributeCompression.octPack(\n toEncode1,\n toEncode2,\n toEncode3,\n scratchCartesian2\n );\n compressedAttributes[normalIndex++] = scratchCartesian2.x;\n compressedAttributes[normalIndex++] = scratchCartesian2.y;\n } else {\n if (hasNormal) {\n Cartesian3.fromArray(normals, index, toEncode1);\n compressedAttributes[\n normalIndex++\n ] = AttributeCompression.octEncodeFloat(toEncode1);\n }\n\n if (hasTangent) {\n Cartesian3.fromArray(tangents, index, toEncode1);\n compressedAttributes[\n normalIndex++\n ] = AttributeCompression.octEncodeFloat(toEncode1);\n }\n\n if (hasBitangent) {\n Cartesian3.fromArray(bitangents, index, toEncode1);\n compressedAttributes[\n normalIndex++\n ] = AttributeCompression.octEncodeFloat(toEncode1);\n }\n }\n }\n\n geometry.attributes.compressedAttributes = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: numCompressedComponents,\n values: compressedAttributes,\n });\n\n if (hasNormal) {\n delete geometry.attributes.normal;\n }\n if (hasSt) {\n delete geometry.attributes.st;\n }\n if (hasBitangent) {\n delete geometry.attributes.bitangent;\n }\n if (hasTangent) {\n delete geometry.attributes.tangent;\n }\n\n return geometry;\n};\n\nfunction indexTriangles(geometry) {\n if (defined(geometry.indices)) {\n return geometry;\n }\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 3) {\n throw new DeveloperError(\"The number of vertices must be at least three.\");\n }\n if (numberOfVertices % 3 !== 0) {\n throw new DeveloperError(\n \"The number of vertices must be a multiple of three.\"\n );\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n numberOfVertices\n );\n for (let i = 0; i < numberOfVertices; ++i) {\n indices[i] = i;\n }\n\n geometry.indices = indices;\n return geometry;\n}\n\nfunction indexTriangleFan(geometry) {\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 3) {\n throw new DeveloperError(\"The number of vertices must be at least three.\");\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n (numberOfVertices - 2) * 3\n );\n indices[0] = 1;\n indices[1] = 0;\n indices[2] = 2;\n\n let indicesIndex = 3;\n for (let i = 3; i < numberOfVertices; ++i) {\n indices[indicesIndex++] = i - 1;\n indices[indicesIndex++] = 0;\n indices[indicesIndex++] = i;\n }\n\n geometry.indices = indices;\n geometry.primitiveType = PrimitiveType.TRIANGLES;\n return geometry;\n}\n\nfunction indexTriangleStrip(geometry) {\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 3) {\n throw new DeveloperError(\"The number of vertices must be at least 3.\");\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n (numberOfVertices - 2) * 3\n );\n indices[0] = 0;\n indices[1] = 1;\n indices[2] = 2;\n\n if (numberOfVertices > 3) {\n indices[3] = 0;\n indices[4] = 2;\n indices[5] = 3;\n }\n\n let indicesIndex = 6;\n for (let i = 3; i < numberOfVertices - 1; i += 2) {\n indices[indicesIndex++] = i;\n indices[indicesIndex++] = i - 1;\n indices[indicesIndex++] = i + 1;\n\n if (i + 2 < numberOfVertices) {\n indices[indicesIndex++] = i;\n indices[indicesIndex++] = i + 1;\n indices[indicesIndex++] = i + 2;\n }\n }\n\n geometry.indices = indices;\n geometry.primitiveType = PrimitiveType.TRIANGLES;\n return geometry;\n}\n\nfunction indexLines(geometry) {\n if (defined(geometry.indices)) {\n return geometry;\n }\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 2) {\n throw new DeveloperError(\"The number of vertices must be at least two.\");\n }\n if (numberOfVertices % 2 !== 0) {\n throw new DeveloperError(\"The number of vertices must be a multiple of 2.\");\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n numberOfVertices\n );\n for (let i = 0; i < numberOfVertices; ++i) {\n indices[i] = i;\n }\n\n geometry.indices = indices;\n return geometry;\n}\n\nfunction indexLineStrip(geometry) {\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 2) {\n throw new DeveloperError(\"The number of vertices must be at least two.\");\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n (numberOfVertices - 1) * 2\n );\n indices[0] = 0;\n indices[1] = 1;\n let indicesIndex = 2;\n for (let i = 2; i < numberOfVertices; ++i) {\n indices[indicesIndex++] = i - 1;\n indices[indicesIndex++] = i;\n }\n\n geometry.indices = indices;\n geometry.primitiveType = PrimitiveType.LINES;\n return geometry;\n}\n\nfunction indexLineLoop(geometry) {\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n\n //>>includeStart('debug', pragmas.debug);\n if (numberOfVertices < 2) {\n throw new DeveloperError(\"The number of vertices must be at least two.\");\n }\n //>>includeEnd('debug');\n\n const indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n numberOfVertices * 2\n );\n\n indices[0] = 0;\n indices[1] = 1;\n\n let indicesIndex = 2;\n for (let i = 2; i < numberOfVertices; ++i) {\n indices[indicesIndex++] = i - 1;\n indices[indicesIndex++] = i;\n }\n\n indices[indicesIndex++] = numberOfVertices - 1;\n indices[indicesIndex] = 0;\n\n geometry.indices = indices;\n geometry.primitiveType = PrimitiveType.LINES;\n return geometry;\n}\n\nfunction indexPrimitive(geometry) {\n switch (geometry.primitiveType) {\n case PrimitiveType.TRIANGLE_FAN:\n return indexTriangleFan(geometry);\n case PrimitiveType.TRIANGLE_STRIP:\n return indexTriangleStrip(geometry);\n case PrimitiveType.TRIANGLES:\n return indexTriangles(geometry);\n case PrimitiveType.LINE_STRIP:\n return indexLineStrip(geometry);\n case PrimitiveType.LINE_LOOP:\n return indexLineLoop(geometry);\n case PrimitiveType.LINES:\n return indexLines(geometry);\n }\n\n return geometry;\n}\n\nfunction offsetPointFromXZPlane(p, isBehind) {\n if (Math.abs(p.y) < CesiumMath.EPSILON6) {\n if (isBehind) {\n p.y = -CesiumMath.EPSILON6;\n } else {\n p.y = CesiumMath.EPSILON6;\n }\n }\n}\n\nfunction offsetTriangleFromXZPlane(p0, p1, p2) {\n if (p0.y !== 0.0 && p1.y !== 0.0 && p2.y !== 0.0) {\n offsetPointFromXZPlane(p0, p0.y < 0.0);\n offsetPointFromXZPlane(p1, p1.y < 0.0);\n offsetPointFromXZPlane(p2, p2.y < 0.0);\n return;\n }\n\n const p0y = Math.abs(p0.y);\n const p1y = Math.abs(p1.y);\n const p2y = Math.abs(p2.y);\n\n let sign;\n if (p0y > p1y) {\n if (p0y > p2y) {\n sign = CesiumMath.sign(p0.y);\n } else {\n sign = CesiumMath.sign(p2.y);\n }\n } else if (p1y > p2y) {\n sign = CesiumMath.sign(p1.y);\n } else {\n sign = CesiumMath.sign(p2.y);\n }\n\n const isBehind = sign < 0.0;\n offsetPointFromXZPlane(p0, isBehind);\n offsetPointFromXZPlane(p1, isBehind);\n offsetPointFromXZPlane(p2, isBehind);\n}\n\nconst c3 = new Cartesian3();\nfunction getXZIntersectionOffsetPoints(p, p1, u1, v1) {\n Cartesian3.add(\n p,\n Cartesian3.multiplyByScalar(\n Cartesian3.subtract(p1, p, c3),\n p.y / (p.y - p1.y),\n c3\n ),\n u1\n );\n Cartesian3.clone(u1, v1);\n offsetPointFromXZPlane(u1, true);\n offsetPointFromXZPlane(v1, false);\n}\n\nconst u1 = new Cartesian3();\nconst u2 = new Cartesian3();\nconst q1 = new Cartesian3();\nconst q2 = new Cartesian3();\n\nconst splitTriangleResult = {\n positions: new Array(7),\n indices: new Array(3 * 3),\n};\n\nfunction splitTriangle(p0, p1, p2) {\n // In WGS84 coordinates, for a triangle approximately on the\n // ellipsoid to cross the IDL, first it needs to be on the\n // negative side of the plane x = 0.\n if (p0.x >= 0.0 || p1.x >= 0.0 || p2.x >= 0.0) {\n return undefined;\n }\n\n offsetTriangleFromXZPlane(p0, p1, p2);\n\n const p0Behind = p0.y < 0.0;\n const p1Behind = p1.y < 0.0;\n const p2Behind = p2.y < 0.0;\n\n let numBehind = 0;\n numBehind += p0Behind ? 1 : 0;\n numBehind += p1Behind ? 1 : 0;\n numBehind += p2Behind ? 1 : 0;\n\n const indices = splitTriangleResult.indices;\n\n if (numBehind === 1) {\n indices[1] = 3;\n indices[2] = 4;\n indices[5] = 6;\n indices[7] = 6;\n indices[8] = 5;\n\n if (p0Behind) {\n getXZIntersectionOffsetPoints(p0, p1, u1, q1);\n getXZIntersectionOffsetPoints(p0, p2, u2, q2);\n\n indices[0] = 0;\n indices[3] = 1;\n indices[4] = 2;\n indices[6] = 1;\n } else if (p1Behind) {\n getXZIntersectionOffsetPoints(p1, p2, u1, q1);\n getXZIntersectionOffsetPoints(p1, p0, u2, q2);\n\n indices[0] = 1;\n indices[3] = 2;\n indices[4] = 0;\n indices[6] = 2;\n } else if (p2Behind) {\n getXZIntersectionOffsetPoints(p2, p0, u1, q1);\n getXZIntersectionOffsetPoints(p2, p1, u2, q2);\n\n indices[0] = 2;\n indices[3] = 0;\n indices[4] = 1;\n indices[6] = 0;\n }\n } else if (numBehind === 2) {\n indices[2] = 4;\n indices[4] = 4;\n indices[5] = 3;\n indices[7] = 5;\n indices[8] = 6;\n\n if (!p0Behind) {\n getXZIntersectionOffsetPoints(p0, p1, u1, q1);\n getXZIntersectionOffsetPoints(p0, p2, u2, q2);\n\n indices[0] = 1;\n indices[1] = 2;\n indices[3] = 1;\n indices[6] = 0;\n } else if (!p1Behind) {\n getXZIntersectionOffsetPoints(p1, p2, u1, q1);\n getXZIntersectionOffsetPoints(p1, p0, u2, q2);\n\n indices[0] = 2;\n indices[1] = 0;\n indices[3] = 2;\n indices[6] = 1;\n } else if (!p2Behind) {\n getXZIntersectionOffsetPoints(p2, p0, u1, q1);\n getXZIntersectionOffsetPoints(p2, p1, u2, q2);\n\n indices[0] = 0;\n indices[1] = 1;\n indices[3] = 0;\n indices[6] = 2;\n }\n }\n\n const positions = splitTriangleResult.positions;\n positions[0] = p0;\n positions[1] = p1;\n positions[2] = p2;\n positions.length = 3;\n\n if (numBehind === 1 || numBehind === 2) {\n positions[3] = u1;\n positions[4] = u2;\n positions[5] = q1;\n positions[6] = q2;\n positions.length = 7;\n }\n\n return splitTriangleResult;\n}\n\nfunction updateGeometryAfterSplit(geometry, computeBoundingSphere) {\n const attributes = geometry.attributes;\n\n if (attributes.position.values.length === 0) {\n return undefined;\n }\n\n for (const property in attributes) {\n if (\n attributes.hasOwnProperty(property) &&\n defined(attributes[property]) &&\n defined(attributes[property].values)\n ) {\n const attribute = attributes[property];\n attribute.values = ComponentDatatype.createTypedArray(\n attribute.componentDatatype,\n attribute.values\n );\n }\n }\n\n const numberOfVertices = Geometry.computeNumberOfVertices(geometry);\n geometry.indices = IndexDatatype.createTypedArray(\n numberOfVertices,\n geometry.indices\n );\n\n if (computeBoundingSphere) {\n geometry.boundingSphere = BoundingSphere.fromVertices(\n attributes.position.values\n );\n }\n\n return geometry;\n}\n\nfunction copyGeometryForSplit(geometry) {\n const attributes = geometry.attributes;\n const copiedAttributes = {};\n\n for (const property in attributes) {\n if (\n attributes.hasOwnProperty(property) &&\n defined(attributes[property]) &&\n defined(attributes[property].values)\n ) {\n const attribute = attributes[property];\n copiedAttributes[property] = new GeometryAttribute({\n componentDatatype: attribute.componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n values: [],\n });\n }\n }\n\n return new Geometry({\n attributes: copiedAttributes,\n indices: [],\n primitiveType: geometry.primitiveType,\n });\n}\n\nfunction updateInstanceAfterSplit(instance, westGeometry, eastGeometry) {\n const computeBoundingSphere = defined(instance.geometry.boundingSphere);\n\n westGeometry = updateGeometryAfterSplit(westGeometry, computeBoundingSphere);\n eastGeometry = updateGeometryAfterSplit(eastGeometry, computeBoundingSphere);\n\n if (defined(eastGeometry) && !defined(westGeometry)) {\n instance.geometry = eastGeometry;\n } else if (!defined(eastGeometry) && defined(westGeometry)) {\n instance.geometry = westGeometry;\n } else {\n instance.westHemisphereGeometry = westGeometry;\n instance.eastHemisphereGeometry = eastGeometry;\n instance.geometry = undefined;\n }\n}\n\nfunction generateBarycentricInterpolateFunction(\n CartesianType,\n numberOfComponents\n) {\n const v0Scratch = new CartesianType();\n const v1Scratch = new CartesianType();\n const v2Scratch = new CartesianType();\n\n return function (\n i0,\n i1,\n i2,\n coords,\n sourceValues,\n currentValues,\n insertedIndex,\n normalize\n ) {\n const v0 = CartesianType.fromArray(\n sourceValues,\n i0 * numberOfComponents,\n v0Scratch\n );\n const v1 = CartesianType.fromArray(\n sourceValues,\n i1 * numberOfComponents,\n v1Scratch\n );\n const v2 = CartesianType.fromArray(\n sourceValues,\n i2 * numberOfComponents,\n v2Scratch\n );\n\n CartesianType.multiplyByScalar(v0, coords.x, v0);\n CartesianType.multiplyByScalar(v1, coords.y, v1);\n CartesianType.multiplyByScalar(v2, coords.z, v2);\n\n const value = CartesianType.add(v0, v1, v0);\n CartesianType.add(value, v2, value);\n\n if (normalize) {\n CartesianType.normalize(value, value);\n }\n\n CartesianType.pack(\n value,\n currentValues,\n insertedIndex * numberOfComponents\n );\n };\n}\n\nconst interpolateAndPackCartesian4 = generateBarycentricInterpolateFunction(\n Cartesian4,\n 4\n);\nconst interpolateAndPackCartesian3 = generateBarycentricInterpolateFunction(\n Cartesian3,\n 3\n);\nconst interpolateAndPackCartesian2 = generateBarycentricInterpolateFunction(\n Cartesian2,\n 2\n);\nconst interpolateAndPackBoolean = function (\n i0,\n i1,\n i2,\n coords,\n sourceValues,\n currentValues,\n insertedIndex\n) {\n const v1 = sourceValues[i0] * coords.x;\n const v2 = sourceValues[i1] * coords.y;\n const v3 = sourceValues[i2] * coords.z;\n currentValues[insertedIndex] = v1 + v2 + v3 > CesiumMath.EPSILON6 ? 1 : 0;\n};\n\nconst p0Scratch = new Cartesian3();\nconst p1Scratch = new Cartesian3();\nconst p2Scratch = new Cartesian3();\nconst barycentricScratch = new Cartesian3();\n\nfunction computeTriangleAttributes(\n i0,\n i1,\n i2,\n point,\n positions,\n normals,\n tangents,\n bitangents,\n texCoords,\n extrudeDirections,\n applyOffset,\n currentAttributes,\n customAttributeNames,\n customAttributesLength,\n allAttributes,\n insertedIndex\n) {\n if (\n !defined(normals) &&\n !defined(tangents) &&\n !defined(bitangents) &&\n !defined(texCoords) &&\n !defined(extrudeDirections) &&\n customAttributesLength === 0\n ) {\n return;\n }\n\n const p0 = Cartesian3.fromArray(positions, i0 * 3, p0Scratch);\n const p1 = Cartesian3.fromArray(positions, i1 * 3, p1Scratch);\n const p2 = Cartesian3.fromArray(positions, i2 * 3, p2Scratch);\n const coords = barycentricCoordinates(point, p0, p1, p2, barycentricScratch);\n if (!defined(coords)) {\n return;\n }\n\n if (defined(normals)) {\n interpolateAndPackCartesian3(\n i0,\n i1,\n i2,\n coords,\n normals,\n currentAttributes.normal.values,\n insertedIndex,\n true\n );\n }\n\n if (defined(extrudeDirections)) {\n const d0 = Cartesian3.fromArray(extrudeDirections, i0 * 3, p0Scratch);\n const d1 = Cartesian3.fromArray(extrudeDirections, i1 * 3, p1Scratch);\n const d2 = Cartesian3.fromArray(extrudeDirections, i2 * 3, p2Scratch);\n\n Cartesian3.multiplyByScalar(d0, coords.x, d0);\n Cartesian3.multiplyByScalar(d1, coords.y, d1);\n Cartesian3.multiplyByScalar(d2, coords.z, d2);\n\n let direction;\n if (\n !Cartesian3.equals(d0, Cartesian3.ZERO) ||\n !Cartesian3.equals(d1, Cartesian3.ZERO) ||\n !Cartesian3.equals(d2, Cartesian3.ZERO)\n ) {\n direction = Cartesian3.add(d0, d1, d0);\n Cartesian3.add(direction, d2, direction);\n Cartesian3.normalize(direction, direction);\n } else {\n direction = p0Scratch;\n direction.x = 0;\n direction.y = 0;\n direction.z = 0;\n }\n Cartesian3.pack(\n direction,\n currentAttributes.extrudeDirection.values,\n insertedIndex * 3\n );\n }\n\n if (defined(applyOffset)) {\n interpolateAndPackBoolean(\n i0,\n i1,\n i2,\n coords,\n applyOffset,\n currentAttributes.applyOffset.values,\n insertedIndex\n );\n }\n\n if (defined(tangents)) {\n interpolateAndPackCartesian3(\n i0,\n i1,\n i2,\n coords,\n tangents,\n currentAttributes.tangent.values,\n insertedIndex,\n true\n );\n }\n\n if (defined(bitangents)) {\n interpolateAndPackCartesian3(\n i0,\n i1,\n i2,\n coords,\n bitangents,\n currentAttributes.bitangent.values,\n insertedIndex,\n true\n );\n }\n\n if (defined(texCoords)) {\n interpolateAndPackCartesian2(\n i0,\n i1,\n i2,\n coords,\n texCoords,\n currentAttributes.st.values,\n insertedIndex\n );\n }\n\n if (customAttributesLength > 0) {\n for (let i = 0; i < customAttributesLength; i++) {\n const attributeName = customAttributeNames[i];\n genericInterpolate(\n i0,\n i1,\n i2,\n coords,\n insertedIndex,\n allAttributes[attributeName],\n currentAttributes[attributeName]\n );\n }\n }\n}\n\nfunction genericInterpolate(\n i0,\n i1,\n i2,\n coords,\n insertedIndex,\n sourceAttribute,\n currentAttribute\n) {\n const componentsPerAttribute = sourceAttribute.componentsPerAttribute;\n const sourceValues = sourceAttribute.values;\n const currentValues = currentAttribute.values;\n switch (componentsPerAttribute) {\n case 4:\n interpolateAndPackCartesian4(\n i0,\n i1,\n i2,\n coords,\n sourceValues,\n currentValues,\n insertedIndex,\n false\n );\n break;\n case 3:\n interpolateAndPackCartesian3(\n i0,\n i1,\n i2,\n coords,\n sourceValues,\n currentValues,\n insertedIndex,\n false\n );\n break;\n case 2:\n interpolateAndPackCartesian2(\n i0,\n i1,\n i2,\n coords,\n sourceValues,\n currentValues,\n insertedIndex,\n false\n );\n break;\n default:\n currentValues[insertedIndex] =\n sourceValues[i0] * coords.x +\n sourceValues[i1] * coords.y +\n sourceValues[i2] * coords.z;\n }\n}\n\nfunction insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n currentIndex,\n point\n) {\n const insertIndex = currentAttributes.position.values.length / 3;\n\n if (currentIndex !== -1) {\n const prevIndex = indices[currentIndex];\n const newIndex = currentIndexMap[prevIndex];\n\n if (newIndex === -1) {\n currentIndexMap[prevIndex] = insertIndex;\n currentAttributes.position.values.push(point.x, point.y, point.z);\n currentIndices.push(insertIndex);\n return insertIndex;\n }\n\n currentIndices.push(newIndex);\n return newIndex;\n }\n\n currentAttributes.position.values.push(point.x, point.y, point.z);\n currentIndices.push(insertIndex);\n return insertIndex;\n}\n\nconst NAMED_ATTRIBUTES = {\n position: true,\n normal: true,\n bitangent: true,\n tangent: true,\n st: true,\n extrudeDirection: true,\n applyOffset: true,\n};\nfunction splitLongitudeTriangles(instance) {\n const geometry = instance.geometry;\n const attributes = geometry.attributes;\n const positions = attributes.position.values;\n const normals = defined(attributes.normal)\n ? attributes.normal.values\n : undefined;\n const bitangents = defined(attributes.bitangent)\n ? attributes.bitangent.values\n : undefined;\n const tangents = defined(attributes.tangent)\n ? attributes.tangent.values\n : undefined;\n const texCoords = defined(attributes.st) ? attributes.st.values : undefined;\n const extrudeDirections = defined(attributes.extrudeDirection)\n ? attributes.extrudeDirection.values\n : undefined;\n const applyOffset = defined(attributes.applyOffset)\n ? attributes.applyOffset.values\n : undefined;\n const indices = geometry.indices;\n\n const customAttributeNames = [];\n for (const attributeName in attributes) {\n if (\n attributes.hasOwnProperty(attributeName) &&\n !NAMED_ATTRIBUTES[attributeName] &&\n defined(attributes[attributeName])\n ) {\n customAttributeNames.push(attributeName);\n }\n }\n const customAttributesLength = customAttributeNames.length;\n\n const eastGeometry = copyGeometryForSplit(geometry);\n const westGeometry = copyGeometryForSplit(geometry);\n\n let currentAttributes;\n let currentIndices;\n let currentIndexMap;\n let insertedIndex;\n let i;\n\n const westGeometryIndexMap = [];\n westGeometryIndexMap.length = positions.length / 3;\n\n const eastGeometryIndexMap = [];\n eastGeometryIndexMap.length = positions.length / 3;\n\n for (i = 0; i < westGeometryIndexMap.length; ++i) {\n westGeometryIndexMap[i] = -1;\n eastGeometryIndexMap[i] = -1;\n }\n\n const len = indices.length;\n for (i = 0; i < len; i += 3) {\n const i0 = indices[i];\n const i1 = indices[i + 1];\n const i2 = indices[i + 2];\n\n let p0 = Cartesian3.fromArray(positions, i0 * 3);\n let p1 = Cartesian3.fromArray(positions, i1 * 3);\n let p2 = Cartesian3.fromArray(positions, i2 * 3);\n\n const result = splitTriangle(p0, p1, p2);\n if (defined(result) && result.positions.length > 3) {\n const resultPositions = result.positions;\n const resultIndices = result.indices;\n const resultLength = resultIndices.length;\n\n for (let j = 0; j < resultLength; ++j) {\n const resultIndex = resultIndices[j];\n const point = resultPositions[resultIndex];\n\n if (point.y < 0.0) {\n currentAttributes = westGeometry.attributes;\n currentIndices = westGeometry.indices;\n currentIndexMap = westGeometryIndexMap;\n } else {\n currentAttributes = eastGeometry.attributes;\n currentIndices = eastGeometry.indices;\n currentIndexMap = eastGeometryIndexMap;\n }\n\n insertedIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n resultIndex < 3 ? i + resultIndex : -1,\n point\n );\n computeTriangleAttributes(\n i0,\n i1,\n i2,\n point,\n positions,\n normals,\n tangents,\n bitangents,\n texCoords,\n extrudeDirections,\n applyOffset,\n currentAttributes,\n customAttributeNames,\n customAttributesLength,\n attributes,\n insertedIndex\n );\n }\n } else {\n if (defined(result)) {\n p0 = result.positions[0];\n p1 = result.positions[1];\n p2 = result.positions[2];\n }\n\n if (p0.y < 0.0) {\n currentAttributes = westGeometry.attributes;\n currentIndices = westGeometry.indices;\n currentIndexMap = westGeometryIndexMap;\n } else {\n currentAttributes = eastGeometry.attributes;\n currentIndices = eastGeometry.indices;\n currentIndexMap = eastGeometryIndexMap;\n }\n\n insertedIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n i,\n p0\n );\n computeTriangleAttributes(\n i0,\n i1,\n i2,\n p0,\n positions,\n normals,\n tangents,\n bitangents,\n texCoords,\n extrudeDirections,\n applyOffset,\n currentAttributes,\n customAttributeNames,\n customAttributesLength,\n attributes,\n insertedIndex\n );\n\n insertedIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n i + 1,\n p1\n );\n computeTriangleAttributes(\n i0,\n i1,\n i2,\n p1,\n positions,\n normals,\n tangents,\n bitangents,\n texCoords,\n extrudeDirections,\n applyOffset,\n currentAttributes,\n customAttributeNames,\n customAttributesLength,\n attributes,\n insertedIndex\n );\n\n insertedIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n i + 2,\n p2\n );\n computeTriangleAttributes(\n i0,\n i1,\n i2,\n p2,\n positions,\n normals,\n tangents,\n bitangents,\n texCoords,\n extrudeDirections,\n applyOffset,\n currentAttributes,\n customAttributeNames,\n customAttributesLength,\n attributes,\n insertedIndex\n );\n }\n }\n\n updateInstanceAfterSplit(instance, westGeometry, eastGeometry);\n}\n\nconst xzPlane = Plane.fromPointNormal(Cartesian3.ZERO, Cartesian3.UNIT_Y);\n\nconst offsetScratch = new Cartesian3();\nconst offsetPointScratch = new Cartesian3();\n\nfunction computeLineAttributes(\n i0,\n i1,\n point,\n positions,\n insertIndex,\n currentAttributes,\n applyOffset\n) {\n if (!defined(applyOffset)) {\n return;\n }\n\n const p0 = Cartesian3.fromArray(positions, i0 * 3, p0Scratch);\n if (Cartesian3.equalsEpsilon(p0, point, CesiumMath.EPSILON10)) {\n currentAttributes.applyOffset.values[insertIndex] = applyOffset[i0];\n } else {\n currentAttributes.applyOffset.values[insertIndex] = applyOffset[i1];\n }\n}\n\nfunction splitLongitudeLines(instance) {\n const geometry = instance.geometry;\n const attributes = geometry.attributes;\n const positions = attributes.position.values;\n const applyOffset = defined(attributes.applyOffset)\n ? attributes.applyOffset.values\n : undefined;\n const indices = geometry.indices;\n\n const eastGeometry = copyGeometryForSplit(geometry);\n const westGeometry = copyGeometryForSplit(geometry);\n\n let i;\n const length = indices.length;\n\n const westGeometryIndexMap = [];\n westGeometryIndexMap.length = positions.length / 3;\n\n const eastGeometryIndexMap = [];\n eastGeometryIndexMap.length = positions.length / 3;\n\n for (i = 0; i < westGeometryIndexMap.length; ++i) {\n westGeometryIndexMap[i] = -1;\n eastGeometryIndexMap[i] = -1;\n }\n\n for (i = 0; i < length; i += 2) {\n const i0 = indices[i];\n const i1 = indices[i + 1];\n\n const p0 = Cartesian3.fromArray(positions, i0 * 3, p0Scratch);\n const p1 = Cartesian3.fromArray(positions, i1 * 3, p1Scratch);\n let insertIndex;\n\n if (Math.abs(p0.y) < CesiumMath.EPSILON6) {\n if (p0.y < 0.0) {\n p0.y = -CesiumMath.EPSILON6;\n } else {\n p0.y = CesiumMath.EPSILON6;\n }\n }\n\n if (Math.abs(p1.y) < CesiumMath.EPSILON6) {\n if (p1.y < 0.0) {\n p1.y = -CesiumMath.EPSILON6;\n } else {\n p1.y = CesiumMath.EPSILON6;\n }\n }\n\n let p0Attributes = eastGeometry.attributes;\n let p0Indices = eastGeometry.indices;\n let p0IndexMap = eastGeometryIndexMap;\n let p1Attributes = westGeometry.attributes;\n let p1Indices = westGeometry.indices;\n let p1IndexMap = westGeometryIndexMap;\n\n const intersection = IntersectionTests.lineSegmentPlane(\n p0,\n p1,\n xzPlane,\n p2Scratch\n );\n if (defined(intersection)) {\n // move point on the xz-plane slightly away from the plane\n const offset = Cartesian3.multiplyByScalar(\n Cartesian3.UNIT_Y,\n 5.0 * CesiumMath.EPSILON9,\n offsetScratch\n );\n if (p0.y < 0.0) {\n Cartesian3.negate(offset, offset);\n\n p0Attributes = westGeometry.attributes;\n p0Indices = westGeometry.indices;\n p0IndexMap = westGeometryIndexMap;\n p1Attributes = eastGeometry.attributes;\n p1Indices = eastGeometry.indices;\n p1IndexMap = eastGeometryIndexMap;\n }\n\n const offsetPoint = Cartesian3.add(\n intersection,\n offset,\n offsetPointScratch\n );\n\n insertIndex = insertSplitPoint(\n p0Attributes,\n p0Indices,\n p0IndexMap,\n indices,\n i,\n p0\n );\n computeLineAttributes(\n i0,\n i1,\n p0,\n positions,\n insertIndex,\n p0Attributes,\n applyOffset\n );\n\n insertIndex = insertSplitPoint(\n p0Attributes,\n p0Indices,\n p0IndexMap,\n indices,\n -1,\n offsetPoint\n );\n computeLineAttributes(\n i0,\n i1,\n offsetPoint,\n positions,\n insertIndex,\n p0Attributes,\n applyOffset\n );\n\n Cartesian3.negate(offset, offset);\n Cartesian3.add(intersection, offset, offsetPoint);\n insertIndex = insertSplitPoint(\n p1Attributes,\n p1Indices,\n p1IndexMap,\n indices,\n -1,\n offsetPoint\n );\n computeLineAttributes(\n i0,\n i1,\n offsetPoint,\n positions,\n insertIndex,\n p1Attributes,\n applyOffset\n );\n\n insertIndex = insertSplitPoint(\n p1Attributes,\n p1Indices,\n p1IndexMap,\n indices,\n i + 1,\n p1\n );\n computeLineAttributes(\n i0,\n i1,\n p1,\n positions,\n insertIndex,\n p1Attributes,\n applyOffset\n );\n } else {\n let currentAttributes;\n let currentIndices;\n let currentIndexMap;\n\n if (p0.y < 0.0) {\n currentAttributes = westGeometry.attributes;\n currentIndices = westGeometry.indices;\n currentIndexMap = westGeometryIndexMap;\n } else {\n currentAttributes = eastGeometry.attributes;\n currentIndices = eastGeometry.indices;\n currentIndexMap = eastGeometryIndexMap;\n }\n\n insertIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n i,\n p0\n );\n computeLineAttributes(\n i0,\n i1,\n p0,\n positions,\n insertIndex,\n currentAttributes,\n applyOffset\n );\n\n insertIndex = insertSplitPoint(\n currentAttributes,\n currentIndices,\n currentIndexMap,\n indices,\n i + 1,\n p1\n );\n computeLineAttributes(\n i0,\n i1,\n p1,\n positions,\n insertIndex,\n currentAttributes,\n applyOffset\n );\n }\n }\n\n updateInstanceAfterSplit(instance, westGeometry, eastGeometry);\n}\n\nconst cartesian2Scratch0 = new Cartesian2();\nconst cartesian2Scratch1 = new Cartesian2();\n\nconst cartesian3Scratch0 = new Cartesian3();\nconst cartesian3Scratch2 = new Cartesian3();\nconst cartesian3Scratch3 = new Cartesian3();\nconst cartesian3Scratch4 = new Cartesian3();\nconst cartesian3Scratch5 = new Cartesian3();\nconst cartesian3Scratch6 = new Cartesian3();\n\nconst cartesian4Scratch0 = new Cartesian4();\n\nfunction updateAdjacencyAfterSplit(geometry) {\n const attributes = geometry.attributes;\n const positions = attributes.position.values;\n const prevPositions = attributes.prevPosition.values;\n const nextPositions = attributes.nextPosition.values;\n\n const length = positions.length;\n for (let j = 0; j < length; j += 3) {\n const position = Cartesian3.unpack(positions, j, cartesian3Scratch0);\n if (position.x > 0.0) {\n continue;\n }\n\n const prevPosition = Cartesian3.unpack(\n prevPositions,\n j,\n cartesian3Scratch2\n );\n if (\n (position.y < 0.0 && prevPosition.y > 0.0) ||\n (position.y > 0.0 && prevPosition.y < 0.0)\n ) {\n if (j - 3 > 0) {\n prevPositions[j] = positions[j - 3];\n prevPositions[j + 1] = positions[j - 2];\n prevPositions[j + 2] = positions[j - 1];\n } else {\n Cartesian3.pack(position, prevPositions, j);\n }\n }\n\n const nextPosition = Cartesian3.unpack(\n nextPositions,\n j,\n cartesian3Scratch3\n );\n if (\n (position.y < 0.0 && nextPosition.y > 0.0) ||\n (position.y > 0.0 && nextPosition.y < 0.0)\n ) {\n if (j + 3 < length) {\n nextPositions[j] = positions[j + 3];\n nextPositions[j + 1] = positions[j + 4];\n nextPositions[j + 2] = positions[j + 5];\n } else {\n Cartesian3.pack(position, nextPositions, j);\n }\n }\n }\n}\n\nconst offsetScalar = 5.0 * CesiumMath.EPSILON9;\nconst coplanarOffset = CesiumMath.EPSILON6;\n\nfunction splitLongitudePolyline(instance) {\n const geometry = instance.geometry;\n const attributes = geometry.attributes;\n const positions = attributes.position.values;\n const prevPositions = attributes.prevPosition.values;\n const nextPositions = attributes.nextPosition.values;\n const expandAndWidths = attributes.expandAndWidth.values;\n\n const texCoords = defined(attributes.st) ? attributes.st.values : undefined;\n const colors = defined(attributes.color)\n ? attributes.color.values\n : undefined;\n\n const eastGeometry = copyGeometryForSplit(geometry);\n const westGeometry = copyGeometryForSplit(geometry);\n\n let i;\n let j;\n let index;\n\n let intersectionFound = false;\n\n const length = positions.length / 3;\n for (i = 0; i < length; i += 4) {\n const i0 = i;\n const i2 = i + 2;\n\n const p0 = Cartesian3.fromArray(positions, i0 * 3, cartesian3Scratch0);\n const p2 = Cartesian3.fromArray(positions, i2 * 3, cartesian3Scratch2);\n\n // Offset points that are close to the 180 longitude and change the previous/next point\n // to be the same offset point so it can be projected to 2D. There is special handling in the\n // shader for when position == prevPosition || position == nextPosition.\n if (Math.abs(p0.y) < coplanarOffset) {\n p0.y = coplanarOffset * (p2.y < 0.0 ? -1.0 : 1.0);\n positions[i * 3 + 1] = p0.y;\n positions[(i + 1) * 3 + 1] = p0.y;\n\n for (j = i0 * 3; j < i0 * 3 + 4 * 3; j += 3) {\n prevPositions[j] = positions[i * 3];\n prevPositions[j + 1] = positions[i * 3 + 1];\n prevPositions[j + 2] = positions[i * 3 + 2];\n }\n }\n\n // Do the same but for when the line crosses 180 longitude in the opposite direction.\n if (Math.abs(p2.y) < coplanarOffset) {\n p2.y = coplanarOffset * (p0.y < 0.0 ? -1.0 : 1.0);\n positions[(i + 2) * 3 + 1] = p2.y;\n positions[(i + 3) * 3 + 1] = p2.y;\n\n for (j = i0 * 3; j < i0 * 3 + 4 * 3; j += 3) {\n nextPositions[j] = positions[(i + 2) * 3];\n nextPositions[j + 1] = positions[(i + 2) * 3 + 1];\n nextPositions[j + 2] = positions[(i + 2) * 3 + 2];\n }\n }\n\n let p0Attributes = eastGeometry.attributes;\n let p0Indices = eastGeometry.indices;\n let p2Attributes = westGeometry.attributes;\n let p2Indices = westGeometry.indices;\n\n const intersection = IntersectionTests.lineSegmentPlane(\n p0,\n p2,\n xzPlane,\n cartesian3Scratch4\n );\n if (defined(intersection)) {\n intersectionFound = true;\n\n // move point on the xz-plane slightly away from the plane\n const offset = Cartesian3.multiplyByScalar(\n Cartesian3.UNIT_Y,\n offsetScalar,\n cartesian3Scratch5\n );\n if (p0.y < 0.0) {\n Cartesian3.negate(offset, offset);\n p0Attributes = westGeometry.attributes;\n p0Indices = westGeometry.indices;\n p2Attributes = eastGeometry.attributes;\n p2Indices = eastGeometry.indices;\n }\n\n const offsetPoint = Cartesian3.add(\n intersection,\n offset,\n cartesian3Scratch6\n );\n p0Attributes.position.values.push(p0.x, p0.y, p0.z, p0.x, p0.y, p0.z);\n p0Attributes.position.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p0Attributes.position.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n\n p0Attributes.prevPosition.values.push(\n prevPositions[i0 * 3],\n prevPositions[i0 * 3 + 1],\n prevPositions[i0 * 3 + 2]\n );\n p0Attributes.prevPosition.values.push(\n prevPositions[i0 * 3 + 3],\n prevPositions[i0 * 3 + 4],\n prevPositions[i0 * 3 + 5]\n );\n p0Attributes.prevPosition.values.push(p0.x, p0.y, p0.z, p0.x, p0.y, p0.z);\n\n p0Attributes.nextPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p0Attributes.nextPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p0Attributes.nextPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p0Attributes.nextPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n\n Cartesian3.negate(offset, offset);\n Cartesian3.add(intersection, offset, offsetPoint);\n p2Attributes.position.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p2Attributes.position.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p2Attributes.position.values.push(p2.x, p2.y, p2.z, p2.x, p2.y, p2.z);\n\n p2Attributes.prevPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p2Attributes.prevPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p2Attributes.prevPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n p2Attributes.prevPosition.values.push(\n offsetPoint.x,\n offsetPoint.y,\n offsetPoint.z\n );\n\n p2Attributes.nextPosition.values.push(p2.x, p2.y, p2.z, p2.x, p2.y, p2.z);\n p2Attributes.nextPosition.values.push(\n nextPositions[i2 * 3],\n nextPositions[i2 * 3 + 1],\n nextPositions[i2 * 3 + 2]\n );\n p2Attributes.nextPosition.values.push(\n nextPositions[i2 * 3 + 3],\n nextPositions[i2 * 3 + 4],\n nextPositions[i2 * 3 + 5]\n );\n\n const ew0 = Cartesian2.fromArray(\n expandAndWidths,\n i0 * 2,\n cartesian2Scratch0\n );\n const width = Math.abs(ew0.y);\n\n p0Attributes.expandAndWidth.values.push(-1, width, 1, width);\n p0Attributes.expandAndWidth.values.push(-1, -width, 1, -width);\n p2Attributes.expandAndWidth.values.push(-1, width, 1, width);\n p2Attributes.expandAndWidth.values.push(-1, -width, 1, -width);\n\n let t = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(intersection, p0, cartesian3Scratch3)\n );\n t /= Cartesian3.magnitudeSquared(\n Cartesian3.subtract(p2, p0, cartesian3Scratch3)\n );\n\n if (defined(colors)) {\n const c0 = Cartesian4.fromArray(colors, i0 * 4, cartesian4Scratch0);\n const c2 = Cartesian4.fromArray(colors, i2 * 4, cartesian4Scratch0);\n\n const r = CesiumMath.lerp(c0.x, c2.x, t);\n const g = CesiumMath.lerp(c0.y, c2.y, t);\n const b = CesiumMath.lerp(c0.z, c2.z, t);\n const a = CesiumMath.lerp(c0.w, c2.w, t);\n\n for (j = i0 * 4; j < i0 * 4 + 2 * 4; ++j) {\n p0Attributes.color.values.push(colors[j]);\n }\n p0Attributes.color.values.push(r, g, b, a);\n p0Attributes.color.values.push(r, g, b, a);\n p2Attributes.color.values.push(r, g, b, a);\n p2Attributes.color.values.push(r, g, b, a);\n for (j = i2 * 4; j < i2 * 4 + 2 * 4; ++j) {\n p2Attributes.color.values.push(colors[j]);\n }\n }\n\n if (defined(texCoords)) {\n const s0 = Cartesian2.fromArray(texCoords, i0 * 2, cartesian2Scratch0);\n const s3 = Cartesian2.fromArray(\n texCoords,\n (i + 3) * 2,\n cartesian2Scratch1\n );\n\n const sx = CesiumMath.lerp(s0.x, s3.x, t);\n\n for (j = i0 * 2; j < i0 * 2 + 2 * 2; ++j) {\n p0Attributes.st.values.push(texCoords[j]);\n }\n p0Attributes.st.values.push(sx, s0.y);\n p0Attributes.st.values.push(sx, s3.y);\n p2Attributes.st.values.push(sx, s0.y);\n p2Attributes.st.values.push(sx, s3.y);\n for (j = i2 * 2; j < i2 * 2 + 2 * 2; ++j) {\n p2Attributes.st.values.push(texCoords[j]);\n }\n }\n\n index = p0Attributes.position.values.length / 3 - 4;\n p0Indices.push(index, index + 2, index + 1);\n p0Indices.push(index + 1, index + 2, index + 3);\n\n index = p2Attributes.position.values.length / 3 - 4;\n p2Indices.push(index, index + 2, index + 1);\n p2Indices.push(index + 1, index + 2, index + 3);\n } else {\n let currentAttributes;\n let currentIndices;\n\n if (p0.y < 0.0) {\n currentAttributes = westGeometry.attributes;\n currentIndices = westGeometry.indices;\n } else {\n currentAttributes = eastGeometry.attributes;\n currentIndices = eastGeometry.indices;\n }\n\n currentAttributes.position.values.push(p0.x, p0.y, p0.z);\n currentAttributes.position.values.push(p0.x, p0.y, p0.z);\n currentAttributes.position.values.push(p2.x, p2.y, p2.z);\n currentAttributes.position.values.push(p2.x, p2.y, p2.z);\n\n for (j = i * 3; j < i * 3 + 4 * 3; ++j) {\n currentAttributes.prevPosition.values.push(prevPositions[j]);\n currentAttributes.nextPosition.values.push(nextPositions[j]);\n }\n\n for (j = i * 2; j < i * 2 + 4 * 2; ++j) {\n currentAttributes.expandAndWidth.values.push(expandAndWidths[j]);\n if (defined(texCoords)) {\n currentAttributes.st.values.push(texCoords[j]);\n }\n }\n\n if (defined(colors)) {\n for (j = i * 4; j < i * 4 + 4 * 4; ++j) {\n currentAttributes.color.values.push(colors[j]);\n }\n }\n\n index = currentAttributes.position.values.length / 3 - 4;\n currentIndices.push(index, index + 2, index + 1);\n currentIndices.push(index + 1, index + 2, index + 3);\n }\n }\n\n if (intersectionFound) {\n updateAdjacencyAfterSplit(westGeometry);\n updateAdjacencyAfterSplit(eastGeometry);\n }\n\n updateInstanceAfterSplit(instance, westGeometry, eastGeometry);\n}\n\n/**\n * Splits the instances's geometry, by introducing new vertices and indices,that\n * intersect the International Date Line and Prime Meridian so that no primitives cross longitude\n * -180/180 degrees. This is not required for 3D drawing, but is required for\n * correcting drawing in 2D and Columbus view.\n *\n * @private\n *\n * @param {GeometryInstance} instance The instance to modify.\n * @returns {GeometryInstance} The modified instance argument, with it's geometry split at the International Date Line.\n *\n * @example\n * instance = Cesium.GeometryPipeline.splitLongitude(instance);\n */\nGeometryPipeline.splitLongitude = function (instance) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(instance)) {\n throw new DeveloperError(\"instance is required.\");\n }\n //>>includeEnd('debug');\n\n const geometry = instance.geometry;\n const boundingSphere = geometry.boundingSphere;\n if (defined(boundingSphere)) {\n const minX = boundingSphere.center.x - boundingSphere.radius;\n if (\n minX > 0 ||\n BoundingSphere.intersectPlane(boundingSphere, Plane.ORIGIN_ZX_PLANE) !==\n Intersect.INTERSECTING\n ) {\n return instance;\n }\n }\n\n if (geometry.geometryType !== GeometryType.NONE) {\n switch (geometry.geometryType) {\n case GeometryType.POLYLINES:\n splitLongitudePolyline(instance);\n break;\n case GeometryType.TRIANGLES:\n splitLongitudeTriangles(instance);\n break;\n case GeometryType.LINES:\n splitLongitudeLines(instance);\n break;\n }\n } else {\n indexPrimitive(geometry);\n if (geometry.primitiveType === PrimitiveType.TRIANGLES) {\n splitLongitudeTriangles(instance);\n } else if (geometry.primitiveType === PrimitiveType.LINES) {\n splitLongitudeLines(instance);\n }\n }\n\n return instance;\n};\nexport default GeometryPipeline;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * The map projection used by Google Maps, Bing Maps, and most of ArcGIS Online, EPSG:3857. This\n * projection use longitude and latitude expressed with the WGS84 and transforms them to Mercator using\n * the spherical (rather than ellipsoidal) equations.\n *\n * @alias WebMercatorProjection\n * @constructor\n *\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n *\n * @see GeographicProjection\n */\nfunction WebMercatorProjection(ellipsoid) {\n this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._semimajorAxis = this._ellipsoid.maximumRadius;\n this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;\n}\n\nObject.defineProperties(WebMercatorProjection.prototype, {\n /**\n * Gets the {@link Ellipsoid}.\n *\n * @memberof WebMercatorProjection.prototype\n *\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n});\n\n/**\n * Converts a Mercator angle, in the range -PI to PI, to a geodetic latitude\n * in the range -PI/2 to PI/2.\n *\n * @param {number} mercatorAngle The angle to convert.\n * @returns {number} The geodetic latitude in radians.\n */\nWebMercatorProjection.mercatorAngleToGeodeticLatitude = function (\n mercatorAngle\n) {\n return CesiumMath.PI_OVER_TWO - 2.0 * Math.atan(Math.exp(-mercatorAngle));\n};\n\n/**\n * Converts a geodetic latitude in radians, in the range -PI/2 to PI/2, to a Mercator\n * angle in the range -PI to PI.\n *\n * @param {number} latitude The geodetic latitude in radians.\n * @returns {number} The Mercator angle.\n */\nWebMercatorProjection.geodeticLatitudeToMercatorAngle = function (latitude) {\n // Clamp the latitude coordinate to the valid Mercator bounds.\n if (latitude > WebMercatorProjection.MaximumLatitude) {\n latitude = WebMercatorProjection.MaximumLatitude;\n } else if (latitude < -WebMercatorProjection.MaximumLatitude) {\n latitude = -WebMercatorProjection.MaximumLatitude;\n }\n const sinLatitude = Math.sin(latitude);\n return 0.5 * Math.log((1.0 + sinLatitude) / (1.0 - sinLatitude));\n};\n\n/**\n * The maximum latitude (both North and South) supported by a Web Mercator\n * (EPSG:3857) projection. Technically, the Mercator projection is defined\n * for any latitude up to (but not including) 90 degrees, but it makes sense\n * to cut it off sooner because it grows exponentially with increasing latitude.\n * The logic behind this particular cutoff value, which is the one used by\n * Google Maps, Bing Maps, and Esri, is that it makes the projection\n * square. That is, the rectangle is equal in the X and Y directions.\n *\n * The constant value is computed by calling:\n * WebMercatorProjection.mercatorAngleToGeodeticLatitude(Math.PI)\n *\n * @type {number}\n */\nWebMercatorProjection.MaximumLatitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(\n Math.PI\n);\n\n/**\n * Converts geodetic ellipsoid coordinates, in radians, to the equivalent Web Mercator\n * X, Y, Z coordinates expressed in meters and returned in a {@link Cartesian3}. The height\n * is copied unmodified to the Z coordinate.\n *\n * @param {Cartographic} cartographic The cartographic coordinates in radians.\n * @param {Cartesian3} [result] The instance to which to copy the result, or undefined if a\n * new instance should be created.\n * @returns {Cartesian3} The equivalent web mercator X, Y, Z coordinates, in meters.\n */\nWebMercatorProjection.prototype.project = function (cartographic, result) {\n const semimajorAxis = this._semimajorAxis;\n const x = cartographic.longitude * semimajorAxis;\n const y =\n WebMercatorProjection.geodeticLatitudeToMercatorAngle(\n cartographic.latitude\n ) * semimajorAxis;\n const z = cartographic.height;\n\n if (!defined(result)) {\n return new Cartesian3(x, y, z);\n }\n\n result.x = x;\n result.y = y;\n result.z = z;\n return result;\n};\n\n/**\n * Converts Web Mercator X, Y coordinates, expressed in meters, to a {@link Cartographic}\n * containing geodetic ellipsoid coordinates. The Z coordinate is copied unmodified to the\n * height.\n *\n * @param {Cartesian3} cartesian The web mercator Cartesian position to unrproject with height (z) in meters.\n * @param {Cartographic} [result] The instance to which to copy the result, or undefined if a\n * new instance should be created.\n * @returns {Cartographic} The equivalent cartographic coordinates.\n */\nWebMercatorProjection.prototype.unproject = function (cartesian, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cartesian)) {\n throw new DeveloperError(\"cartesian is required\");\n }\n //>>includeEnd('debug');\n\n const oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;\n const longitude = cartesian.x * oneOverEarthSemimajorAxis;\n const latitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(\n cartesian.y * oneOverEarthSemimajorAxis\n );\n const height = cartesian.z;\n\n if (!defined(result)) {\n return new Cartographic(longitude, latitude, height);\n }\n\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = height;\n return result;\n};\nexport default WebMercatorProjection;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport GeographicProjection from \"../Core/GeographicProjection.js\";\nimport Geometry from \"../Core/Geometry.js\";\nimport GeometryAttribute from \"../Core/GeometryAttribute.js\";\nimport GeometryAttributes from \"../Core/GeometryAttributes.js\";\nimport GeometryPipeline from \"../Core/GeometryPipeline.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport WebMercatorProjection from \"../Core/WebMercatorProjection.js\";\n\nfunction transformToWorldCoordinates(\n instances,\n primitiveModelMatrix,\n scene3DOnly\n) {\n let toWorld = !scene3DOnly;\n const length = instances.length;\n let i;\n\n if (!toWorld && length > 1) {\n const modelMatrix = instances[0].modelMatrix;\n\n for (i = 1; i < length; ++i) {\n if (!Matrix4.equals(modelMatrix, instances[i].modelMatrix)) {\n toWorld = true;\n break;\n }\n }\n }\n\n if (toWorld) {\n for (i = 0; i < length; ++i) {\n if (defined(instances[i].geometry)) {\n GeometryPipeline.transformToWorldCoordinates(instances[i]);\n }\n }\n } else {\n // Leave geometry in local coordinate system; auto update model-matrix.\n Matrix4.multiplyTransformation(\n primitiveModelMatrix,\n instances[0].modelMatrix,\n primitiveModelMatrix\n );\n }\n}\n\nfunction addGeometryBatchId(geometry, batchId) {\n const attributes = geometry.attributes;\n const positionAttr = attributes.position;\n const numberOfComponents =\n positionAttr.values.length / positionAttr.componentsPerAttribute;\n\n attributes.batchId = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 1,\n values: new Float32Array(numberOfComponents),\n });\n\n const values = attributes.batchId.values;\n for (let j = 0; j < numberOfComponents; ++j) {\n values[j] = batchId;\n }\n}\n\nfunction addBatchIds(instances) {\n const length = instances.length;\n\n for (let i = 0; i < length; ++i) {\n const instance = instances[i];\n if (defined(instance.geometry)) {\n addGeometryBatchId(instance.geometry, i);\n } else if (\n defined(instance.westHemisphereGeometry) &&\n defined(instance.eastHemisphereGeometry)\n ) {\n addGeometryBatchId(instance.westHemisphereGeometry, i);\n addGeometryBatchId(instance.eastHemisphereGeometry, i);\n }\n }\n}\n\nfunction geometryPipeline(parameters) {\n const instances = parameters.instances;\n const projection = parameters.projection;\n const uintIndexSupport = parameters.elementIndexUintSupported;\n const scene3DOnly = parameters.scene3DOnly;\n const vertexCacheOptimize = parameters.vertexCacheOptimize;\n const compressVertices = parameters.compressVertices;\n const modelMatrix = parameters.modelMatrix;\n\n let i;\n let geometry;\n let primitiveType;\n let length = instances.length;\n\n for (i = 0; i < length; ++i) {\n if (defined(instances[i].geometry)) {\n primitiveType = instances[i].geometry.primitiveType;\n break;\n }\n }\n\n //>>includeStart('debug', pragmas.debug);\n for (i = 1; i < length; ++i) {\n if (\n defined(instances[i].geometry) &&\n instances[i].geometry.primitiveType !== primitiveType\n ) {\n throw new DeveloperError(\n \"All instance geometries must have the same primitiveType.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n // Unify to world coordinates before combining.\n transformToWorldCoordinates(instances, modelMatrix, scene3DOnly);\n\n // Clip to IDL\n if (!scene3DOnly) {\n for (i = 0; i < length; ++i) {\n if (defined(instances[i].geometry)) {\n GeometryPipeline.splitLongitude(instances[i]);\n }\n }\n }\n\n addBatchIds(instances);\n\n // Optimize for vertex shader caches\n if (vertexCacheOptimize) {\n for (i = 0; i < length; ++i) {\n const instance = instances[i];\n if (defined(instance.geometry)) {\n GeometryPipeline.reorderForPostVertexCache(instance.geometry);\n GeometryPipeline.reorderForPreVertexCache(instance.geometry);\n } else if (\n defined(instance.westHemisphereGeometry) &&\n defined(instance.eastHemisphereGeometry)\n ) {\n GeometryPipeline.reorderForPostVertexCache(\n instance.westHemisphereGeometry\n );\n GeometryPipeline.reorderForPreVertexCache(\n instance.westHemisphereGeometry\n );\n\n GeometryPipeline.reorderForPostVertexCache(\n instance.eastHemisphereGeometry\n );\n GeometryPipeline.reorderForPreVertexCache(\n instance.eastHemisphereGeometry\n );\n }\n }\n }\n\n // Combine into single geometry for better rendering performance.\n let geometries = GeometryPipeline.combineInstances(instances);\n\n length = geometries.length;\n for (i = 0; i < length; ++i) {\n geometry = geometries[i];\n\n // Split positions for GPU RTE\n const attributes = geometry.attributes;\n if (!scene3DOnly) {\n for (const name in attributes) {\n if (\n attributes.hasOwnProperty(name) &&\n attributes[name].componentDatatype === ComponentDatatype.DOUBLE\n ) {\n const name3D = `${name}3D`;\n const name2D = `${name}2D`;\n\n // Compute 2D positions\n GeometryPipeline.projectTo2D(\n geometry,\n name,\n name3D,\n name2D,\n projection\n );\n if (defined(geometry.boundingSphere) && name === \"position\") {\n geometry.boundingSphereCV = BoundingSphere.fromVertices(\n geometry.attributes.position2D.values\n );\n }\n\n GeometryPipeline.encodeAttribute(\n geometry,\n name3D,\n `${name3D}High`,\n `${name3D}Low`\n );\n GeometryPipeline.encodeAttribute(\n geometry,\n name2D,\n `${name2D}High`,\n `${name2D}Low`\n );\n }\n }\n } else {\n for (const name in attributes) {\n if (\n attributes.hasOwnProperty(name) &&\n attributes[name].componentDatatype === ComponentDatatype.DOUBLE\n ) {\n GeometryPipeline.encodeAttribute(\n geometry,\n name,\n `${name}3DHigh`,\n `${name}3DLow`\n );\n }\n }\n }\n\n // oct encode and pack normals, compress texture coordinates\n if (compressVertices) {\n GeometryPipeline.compressVertices(geometry);\n }\n }\n\n if (!uintIndexSupport) {\n // Break into multiple geometries to fit within unsigned short indices if needed\n let splitGeometries = [];\n length = geometries.length;\n for (i = 0; i < length; ++i) {\n geometry = geometries[i];\n splitGeometries = splitGeometries.concat(\n GeometryPipeline.fitToUnsignedShortIndices(geometry)\n );\n }\n\n geometries = splitGeometries;\n }\n\n return geometries;\n}\n\nfunction createPickOffsets(instances, geometryName, geometries, pickOffsets) {\n let offset;\n let indexCount;\n let geometryIndex;\n\n const offsetIndex = pickOffsets.length - 1;\n if (offsetIndex >= 0) {\n const pickOffset = pickOffsets[offsetIndex];\n offset = pickOffset.offset + pickOffset.count;\n geometryIndex = pickOffset.index;\n indexCount = geometries[geometryIndex].indices.length;\n } else {\n offset = 0;\n geometryIndex = 0;\n indexCount = geometries[geometryIndex].indices.length;\n }\n\n const length = instances.length;\n for (let i = 0; i < length; ++i) {\n const instance = instances[i];\n const geometry = instance[geometryName];\n if (!defined(geometry)) {\n continue;\n }\n\n const count = geometry.indices.length;\n\n if (offset + count > indexCount) {\n offset = 0;\n indexCount = geometries[++geometryIndex].indices.length;\n }\n\n pickOffsets.push({\n index: geometryIndex,\n offset: offset,\n count: count,\n });\n offset += count;\n }\n}\n\nfunction createInstancePickOffsets(instances, geometries) {\n const pickOffsets = [];\n createPickOffsets(instances, \"geometry\", geometries, pickOffsets);\n createPickOffsets(\n instances,\n \"westHemisphereGeometry\",\n geometries,\n pickOffsets\n );\n createPickOffsets(\n instances,\n \"eastHemisphereGeometry\",\n geometries,\n pickOffsets\n );\n return pickOffsets;\n}\n\n/**\n * @private\n */\nconst PrimitivePipeline = {};\n\n/**\n * @private\n */\nPrimitivePipeline.combineGeometry = function (parameters) {\n let geometries;\n let attributeLocations;\n const instances = parameters.instances;\n const length = instances.length;\n let pickOffsets;\n\n let offsetInstanceExtend;\n let hasOffset = false;\n if (length > 0) {\n geometries = geometryPipeline(parameters);\n if (geometries.length > 0) {\n attributeLocations = GeometryPipeline.createAttributeLocations(\n geometries[0]\n );\n if (parameters.createPickOffsets) {\n pickOffsets = createInstancePickOffsets(instances, geometries);\n }\n }\n if (\n defined(instances[0].attributes) &&\n defined(instances[0].attributes.offset)\n ) {\n offsetInstanceExtend = new Array(length);\n hasOffset = true;\n }\n }\n\n const boundingSpheres = new Array(length);\n const boundingSpheresCV = new Array(length);\n for (let i = 0; i < length; ++i) {\n const instance = instances[i];\n const geometry = instance.geometry;\n if (defined(geometry)) {\n boundingSpheres[i] = geometry.boundingSphere;\n boundingSpheresCV[i] = geometry.boundingSphereCV;\n if (hasOffset) {\n offsetInstanceExtend[i] = instance.geometry.offsetAttribute;\n }\n }\n\n const eastHemisphereGeometry = instance.eastHemisphereGeometry;\n const westHemisphereGeometry = instance.westHemisphereGeometry;\n if (defined(eastHemisphereGeometry) && defined(westHemisphereGeometry)) {\n if (\n defined(eastHemisphereGeometry.boundingSphere) &&\n defined(westHemisphereGeometry.boundingSphere)\n ) {\n boundingSpheres[i] = BoundingSphere.union(\n eastHemisphereGeometry.boundingSphere,\n westHemisphereGeometry.boundingSphere\n );\n }\n if (\n defined(eastHemisphereGeometry.boundingSphereCV) &&\n defined(westHemisphereGeometry.boundingSphereCV)\n ) {\n boundingSpheresCV[i] = BoundingSphere.union(\n eastHemisphereGeometry.boundingSphereCV,\n westHemisphereGeometry.boundingSphereCV\n );\n }\n }\n }\n\n return {\n geometries: geometries,\n modelMatrix: parameters.modelMatrix,\n attributeLocations: attributeLocations,\n pickOffsets: pickOffsets,\n offsetInstanceExtend: offsetInstanceExtend,\n boundingSpheres: boundingSpheres,\n boundingSpheresCV: boundingSpheresCV,\n };\n};\n\nfunction transferGeometry(geometry, transferableObjects) {\n const attributes = geometry.attributes;\n for (const name in attributes) {\n if (attributes.hasOwnProperty(name)) {\n const attribute = attributes[name];\n\n if (defined(attribute) && defined(attribute.values)) {\n transferableObjects.push(attribute.values.buffer);\n }\n }\n }\n\n if (defined(geometry.indices)) {\n transferableObjects.push(geometry.indices.buffer);\n }\n}\n\nfunction transferGeometries(geometries, transferableObjects) {\n const length = geometries.length;\n for (let i = 0; i < length; ++i) {\n transferGeometry(geometries[i], transferableObjects);\n }\n}\n\n// This function was created by simplifying packCreateGeometryResults into a count-only operation.\nfunction countCreateGeometryResults(items) {\n let count = 1;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const geometry = items[i];\n ++count;\n\n if (!defined(geometry)) {\n continue;\n }\n\n const attributes = geometry.attributes;\n\n count +=\n 7 +\n 2 * BoundingSphere.packedLength +\n (defined(geometry.indices) ? geometry.indices.length : 0);\n\n for (const property in attributes) {\n if (\n attributes.hasOwnProperty(property) &&\n defined(attributes[property])\n ) {\n const attribute = attributes[property];\n count += 5 + attribute.values.length;\n }\n }\n }\n\n return count;\n}\n\n/**\n * @private\n */\nPrimitivePipeline.packCreateGeometryResults = function (\n items,\n transferableObjects\n) {\n const packedData = new Float64Array(countCreateGeometryResults(items));\n const stringTable = [];\n const stringHash = {};\n\n const length = items.length;\n let count = 0;\n packedData[count++] = length;\n for (let i = 0; i < length; i++) {\n const geometry = items[i];\n\n const validGeometry = defined(geometry);\n packedData[count++] = validGeometry ? 1.0 : 0.0;\n\n if (!validGeometry) {\n continue;\n }\n\n packedData[count++] = geometry.primitiveType;\n packedData[count++] = geometry.geometryType;\n packedData[count++] = defaultValue(geometry.offsetAttribute, -1);\n\n const validBoundingSphere = defined(geometry.boundingSphere) ? 1.0 : 0.0;\n packedData[count++] = validBoundingSphere;\n if (validBoundingSphere) {\n BoundingSphere.pack(geometry.boundingSphere, packedData, count);\n }\n\n count += BoundingSphere.packedLength;\n\n const validBoundingSphereCV = defined(geometry.boundingSphereCV)\n ? 1.0\n : 0.0;\n packedData[count++] = validBoundingSphereCV;\n if (validBoundingSphereCV) {\n BoundingSphere.pack(geometry.boundingSphereCV, packedData, count);\n }\n\n count += BoundingSphere.packedLength;\n\n const attributes = geometry.attributes;\n const attributesToWrite = [];\n for (const property in attributes) {\n if (\n attributes.hasOwnProperty(property) &&\n defined(attributes[property])\n ) {\n attributesToWrite.push(property);\n if (!defined(stringHash[property])) {\n stringHash[property] = stringTable.length;\n stringTable.push(property);\n }\n }\n }\n\n packedData[count++] = attributesToWrite.length;\n for (let q = 0; q < attributesToWrite.length; q++) {\n const name = attributesToWrite[q];\n const attribute = attributes[name];\n packedData[count++] = stringHash[name];\n packedData[count++] = attribute.componentDatatype;\n packedData[count++] = attribute.componentsPerAttribute;\n packedData[count++] = attribute.normalize ? 1 : 0;\n packedData[count++] = attribute.values.length;\n packedData.set(attribute.values, count);\n count += attribute.values.length;\n }\n\n const indicesLength = defined(geometry.indices)\n ? geometry.indices.length\n : 0;\n packedData[count++] = indicesLength;\n\n if (indicesLength > 0) {\n packedData.set(geometry.indices, count);\n count += indicesLength;\n }\n }\n\n transferableObjects.push(packedData.buffer);\n\n return {\n stringTable: stringTable,\n packedData: packedData,\n };\n};\n\n/**\n * @private\n */\nPrimitivePipeline.unpackCreateGeometryResults = function (\n createGeometryResult\n) {\n const stringTable = createGeometryResult.stringTable;\n const packedGeometry = createGeometryResult.packedData;\n\n let i;\n const result = new Array(packedGeometry[0]);\n let resultIndex = 0;\n\n let packedGeometryIndex = 1;\n while (packedGeometryIndex < packedGeometry.length) {\n const valid = packedGeometry[packedGeometryIndex++] === 1.0;\n if (!valid) {\n result[resultIndex++] = undefined;\n continue;\n }\n\n const primitiveType = packedGeometry[packedGeometryIndex++];\n const geometryType = packedGeometry[packedGeometryIndex++];\n let offsetAttribute = packedGeometry[packedGeometryIndex++];\n if (offsetAttribute === -1) {\n offsetAttribute = undefined;\n }\n\n let boundingSphere;\n let boundingSphereCV;\n\n const validBoundingSphere = packedGeometry[packedGeometryIndex++] === 1.0;\n if (validBoundingSphere) {\n boundingSphere = BoundingSphere.unpack(\n packedGeometry,\n packedGeometryIndex\n );\n }\n\n packedGeometryIndex += BoundingSphere.packedLength;\n\n const validBoundingSphereCV = packedGeometry[packedGeometryIndex++] === 1.0;\n if (validBoundingSphereCV) {\n boundingSphereCV = BoundingSphere.unpack(\n packedGeometry,\n packedGeometryIndex\n );\n }\n\n packedGeometryIndex += BoundingSphere.packedLength;\n\n let length;\n let values;\n let componentsPerAttribute;\n const attributes = new GeometryAttributes();\n const numAttributes = packedGeometry[packedGeometryIndex++];\n for (i = 0; i < numAttributes; i++) {\n const name = stringTable[packedGeometry[packedGeometryIndex++]];\n const componentDatatype = packedGeometry[packedGeometryIndex++];\n componentsPerAttribute = packedGeometry[packedGeometryIndex++];\n const normalize = packedGeometry[packedGeometryIndex++] !== 0;\n\n length = packedGeometry[packedGeometryIndex++];\n values = ComponentDatatype.createTypedArray(componentDatatype, length);\n for (let valuesIndex = 0; valuesIndex < length; valuesIndex++) {\n values[valuesIndex] = packedGeometry[packedGeometryIndex++];\n }\n\n attributes[name] = new GeometryAttribute({\n componentDatatype: componentDatatype,\n componentsPerAttribute: componentsPerAttribute,\n normalize: normalize,\n values: values,\n });\n }\n\n let indices;\n length = packedGeometry[packedGeometryIndex++];\n\n if (length > 0) {\n const numberOfVertices = values.length / componentsPerAttribute;\n indices = IndexDatatype.createTypedArray(numberOfVertices, length);\n for (i = 0; i < length; i++) {\n indices[i] = packedGeometry[packedGeometryIndex++];\n }\n }\n\n result[resultIndex++] = new Geometry({\n primitiveType: primitiveType,\n geometryType: geometryType,\n boundingSphere: boundingSphere,\n boundingSphereCV: boundingSphereCV,\n indices: indices,\n attributes: attributes,\n offsetAttribute: offsetAttribute,\n });\n }\n\n return result;\n};\n\nfunction packInstancesForCombine(instances, transferableObjects) {\n const length = instances.length;\n const packedData = new Float64Array(1 + length * 19);\n let count = 0;\n packedData[count++] = length;\n for (let i = 0; i < length; i++) {\n const instance = instances[i];\n Matrix4.pack(instance.modelMatrix, packedData, count);\n count += Matrix4.packedLength;\n if (defined(instance.attributes) && defined(instance.attributes.offset)) {\n const values = instance.attributes.offset.value;\n packedData[count] = values[0];\n packedData[count + 1] = values[1];\n packedData[count + 2] = values[2];\n }\n count += 3;\n }\n transferableObjects.push(packedData.buffer);\n\n return packedData;\n}\n\nfunction unpackInstancesForCombine(data) {\n const packedInstances = data;\n const result = new Array(packedInstances[0]);\n let count = 0;\n\n let i = 1;\n while (i < packedInstances.length) {\n const modelMatrix = Matrix4.unpack(packedInstances, i);\n let attributes;\n i += Matrix4.packedLength;\n if (defined(packedInstances[i])) {\n attributes = {\n offset: new OffsetGeometryInstanceAttribute(\n packedInstances[i],\n packedInstances[i + 1],\n packedInstances[i + 2]\n ),\n };\n }\n i += 3;\n\n result[count++] = {\n modelMatrix: modelMatrix,\n attributes: attributes,\n };\n }\n\n return result;\n}\n\n/**\n * @private\n */\nPrimitivePipeline.packCombineGeometryParameters = function (\n parameters,\n transferableObjects\n) {\n const createGeometryResults = parameters.createGeometryResults;\n const length = createGeometryResults.length;\n\n for (let i = 0; i < length; i++) {\n transferableObjects.push(createGeometryResults[i].packedData.buffer);\n }\n\n return {\n createGeometryResults: parameters.createGeometryResults,\n packedInstances: packInstancesForCombine(\n parameters.instances,\n transferableObjects\n ),\n ellipsoid: parameters.ellipsoid,\n isGeographic: parameters.projection instanceof GeographicProjection,\n elementIndexUintSupported: parameters.elementIndexUintSupported,\n scene3DOnly: parameters.scene3DOnly,\n vertexCacheOptimize: parameters.vertexCacheOptimize,\n compressVertices: parameters.compressVertices,\n modelMatrix: parameters.modelMatrix,\n createPickOffsets: parameters.createPickOffsets,\n };\n};\n\n/**\n * @private\n */\nPrimitivePipeline.unpackCombineGeometryParameters = function (\n packedParameters\n) {\n const instances = unpackInstancesForCombine(packedParameters.packedInstances);\n const createGeometryResults = packedParameters.createGeometryResults;\n const length = createGeometryResults.length;\n let instanceIndex = 0;\n\n for (let resultIndex = 0; resultIndex < length; resultIndex++) {\n const geometries = PrimitivePipeline.unpackCreateGeometryResults(\n createGeometryResults[resultIndex]\n );\n const geometriesLength = geometries.length;\n for (\n let geometryIndex = 0;\n geometryIndex < geometriesLength;\n geometryIndex++\n ) {\n const geometry = geometries[geometryIndex];\n const instance = instances[instanceIndex];\n instance.geometry = geometry;\n ++instanceIndex;\n }\n }\n\n const ellipsoid = Ellipsoid.clone(packedParameters.ellipsoid);\n const projection = packedParameters.isGeographic\n ? new GeographicProjection(ellipsoid)\n : new WebMercatorProjection(ellipsoid);\n\n return {\n instances: instances,\n ellipsoid: ellipsoid,\n projection: projection,\n elementIndexUintSupported: packedParameters.elementIndexUintSupported,\n scene3DOnly: packedParameters.scene3DOnly,\n vertexCacheOptimize: packedParameters.vertexCacheOptimize,\n compressVertices: packedParameters.compressVertices,\n modelMatrix: Matrix4.clone(packedParameters.modelMatrix),\n createPickOffsets: packedParameters.createPickOffsets,\n };\n};\n\nfunction packBoundingSpheres(boundingSpheres) {\n const length = boundingSpheres.length;\n const bufferLength = 1 + (BoundingSphere.packedLength + 1) * length;\n const buffer = new Float32Array(bufferLength);\n\n let bufferIndex = 0;\n buffer[bufferIndex++] = length;\n\n for (let i = 0; i < length; ++i) {\n const bs = boundingSpheres[i];\n if (!defined(bs)) {\n buffer[bufferIndex++] = 0.0;\n } else {\n buffer[bufferIndex++] = 1.0;\n BoundingSphere.pack(boundingSpheres[i], buffer, bufferIndex);\n }\n bufferIndex += BoundingSphere.packedLength;\n }\n\n return buffer;\n}\n\nfunction unpackBoundingSpheres(buffer) {\n const result = new Array(buffer[0]);\n let count = 0;\n\n let i = 1;\n while (i < buffer.length) {\n if (buffer[i++] === 1.0) {\n result[count] = BoundingSphere.unpack(buffer, i);\n }\n ++count;\n i += BoundingSphere.packedLength;\n }\n\n return result;\n}\n\n/**\n * @private\n */\nPrimitivePipeline.packCombineGeometryResults = function (\n results,\n transferableObjects\n) {\n if (defined(results.geometries)) {\n transferGeometries(results.geometries, transferableObjects);\n }\n\n const packedBoundingSpheres = packBoundingSpheres(results.boundingSpheres);\n const packedBoundingSpheresCV = packBoundingSpheres(\n results.boundingSpheresCV\n );\n transferableObjects.push(\n packedBoundingSpheres.buffer,\n packedBoundingSpheresCV.buffer\n );\n\n return {\n geometries: results.geometries,\n attributeLocations: results.attributeLocations,\n modelMatrix: results.modelMatrix,\n pickOffsets: results.pickOffsets,\n offsetInstanceExtend: results.offsetInstanceExtend,\n boundingSpheres: packedBoundingSpheres,\n boundingSpheresCV: packedBoundingSpheresCV,\n };\n};\n\n/**\n * @private\n */\nPrimitivePipeline.unpackCombineGeometryResults = function (packedResult) {\n return {\n geometries: packedResult.geometries,\n attributeLocations: packedResult.attributeLocations,\n modelMatrix: packedResult.modelMatrix,\n pickOffsets: packedResult.pickOffsets,\n offsetInstanceExtend: packedResult.offsetInstanceExtend,\n boundingSpheres: unpackBoundingSpheres(packedResult.boundingSpheres),\n boundingSpheresCV: unpackBoundingSpheres(packedResult.boundingSpheresCV),\n };\n};\nexport default PrimitivePipeline;\n", "/**\n * @private\n */\nconst PrimitiveState = {\n READY: 0,\n CREATING: 1,\n CREATED: 2,\n COMBINING: 3,\n COMBINED: 4,\n COMPLETE: 5,\n FAILED: 6,\n};\nexport default Object.freeze(PrimitiveState);\n", "/**\n * Specifies whether the object casts or receives shadows from light sources when\n * shadows are enabled.\n *\n * @enum {number}\n */\nconst ShadowMode = {\n /**\n * The object does not cast or receive shadows.\n *\n * @type {number}\n * @constant\n */\n DISABLED: 0,\n\n /**\n * The object casts and receives shadows.\n *\n * @type {number}\n * @constant\n */\n ENABLED: 1,\n\n /**\n * The object casts shadows only.\n *\n * @type {number}\n * @constant\n */\n CAST_ONLY: 2,\n\n /**\n * The object receives shadows only.\n *\n * @type {number}\n * @constant\n */\n RECEIVE_ONLY: 3,\n};\n\n/**\n * @private\n */\nShadowMode.NUMBER_OF_SHADOW_MODES = 4;\n\n/**\n * @private\n */\nShadowMode.castShadows = function (shadowMode) {\n return (\n shadowMode === ShadowMode.ENABLED || shadowMode === ShadowMode.CAST_ONLY\n );\n};\n\n/**\n * @private\n */\nShadowMode.receiveShadows = function (shadowMode) {\n return (\n shadowMode === ShadowMode.ENABLED || shadowMode === ShadowMode.RECEIVE_ONLY\n );\n};\n\n/**\n * @private\n */\nShadowMode.fromCastReceive = function (castShadows, receiveShadows) {\n if (castShadows && receiveShadows) {\n return ShadowMode.ENABLED;\n } else if (castShadows) {\n return ShadowMode.CAST_ONLY;\n } else if (receiveShadows) {\n return ShadowMode.RECEIVE_ONLY;\n }\n return ShadowMode.DISABLED;\n};\n\nexport default Object.freeze(ShadowMode);\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport clone from \"../Core/clone.js\";\nimport Color from \"../Core/Color.js\";\nimport combine from \"../Core/combine.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport Geometry from \"../Core/Geometry.js\";\nimport GeometryAttribute from \"../Core/GeometryAttribute.js\";\nimport GeometryAttributes from \"../Core/GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"../Core/GeometryOffsetAttribute.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Plane from \"../Core/Plane.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport subdivideArray from \"../Core/subdivideArray.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport BatchTable from \"./BatchTable.js\";\nimport CullFace from \"./CullFace.js\";\nimport DepthFunction from \"./DepthFunction.js\";\nimport PrimitivePipeline from \"./PrimitivePipeline.js\";\nimport PrimitiveState from \"./PrimitiveState.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport ShadowMode from \"./ShadowMode.js\";\n\n/**\n * A primitive represents geometry in the {@link Scene}. The geometry can be from a single {@link GeometryInstance}\n * as shown in example 1 below, or from an array of instances, even if the geometry is from different\n * geometry types, e.g., an {@link RectangleGeometry} and an {@link EllipsoidGeometry} as shown in Code Example 2.\n *

\n * A primitive combines geometry instances with an {@link Appearance} that describes the full shading, including\n * {@link Material} and {@link RenderState}. Roughly, the geometry instance defines the structure and placement,\n * and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix\n * and match most of them and add a new geometry or appearance independently of each other.\n *

\n *

\n * Combining multiple instances into one primitive is called batching, and significantly improves performance for static data.\n * Instances can be individually picked; {@link Scene#pick} returns their {@link GeometryInstance#id}. Using\n * per-instance appearances like {@link PerInstanceColorAppearance}, each instance can also have a unique color.\n *

\n *

\n * {@link Geometry} can either be created and batched on a web worker or the main thread. The first two examples\n * show geometry that will be created on a web worker by using the descriptions of the geometry. The third example\n * shows how to create the geometry on the main thread by explicitly calling the createGeometry method.\n *

\n *\n * @alias Primitive\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {GeometryInstance[]|GeometryInstance} [options.geometryInstances] The geometry instances - or a single geometry instance - to render.\n * @param {Appearance} [options.appearance] The appearance used to render the primitive.\n * @param {Appearance} [options.depthFailAppearance] The appearance used to shade this primitive when it fails the depth test.\n * @param {boolean} [options.show=true] Determines if this primitive will be shown.\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the primitive (all geometry instances) from model to world coordinates.\n * @param {boolean} [options.vertexCacheOptimize=false] When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n * @param {boolean} [options.interleave=false] When true, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.\n * @param {boolean} [options.compressVertices=true] When true, the geometry vertices are compressed, which will save memory.\n * @param {boolean} [options.releaseGeometryInstances=true] When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n * @param {boolean} [options.allowPicking=true] When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n * @param {boolean} [options.cull=true] When true, the renderer frustum culls and horizon culls the primitive's commands based on their bounding volume. Set this to false for a small performance gain if you are manually culling the primitive.\n * @param {boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {ShadowMode} [options.shadows=ShadowMode.DISABLED] Determines whether this primitive casts or receives shadows from light sources.\n *\n * @example\n * // 1. Draw a translucent ellipse on the surface with a checkerboard pattern\n * const instance = new Cesium.GeometryInstance({\n * geometry : new Cesium.EllipseGeometry({\n * center : Cesium.Cartesian3.fromDegrees(-100.0, 20.0),\n * semiMinorAxis : 500000.0,\n * semiMajorAxis : 1000000.0,\n * rotation : Cesium.Math.PI_OVER_FOUR,\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_ST\n * }),\n * id : 'object returned when this instance is picked and to get/set per-instance attributes'\n * });\n * scene.primitives.add(new Cesium.Primitive({\n * geometryInstances : instance,\n * appearance : new Cesium.EllipsoidSurfaceAppearance({\n * material : Cesium.Material.fromType('Checkerboard')\n * })\n * }));\n *\n * @example\n * // 2. Draw different instances each with a unique color\n * const rectangleInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.RectangleGeometry({\n * rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),\n * vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT\n * }),\n * id : 'rectangle',\n * attributes : {\n * color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)\n * }\n * });\n * const ellipsoidInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.EllipsoidGeometry({\n * radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL\n * }),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),\n * id : 'ellipsoid',\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)\n * }\n * });\n * scene.primitives.add(new Cesium.Primitive({\n * geometryInstances : [rectangleInstance, ellipsoidInstance],\n * appearance : new Cesium.PerInstanceColorAppearance()\n * }));\n *\n * @example\n * // 3. Create the geometry on the main thread.\n * scene.primitives.add(new Cesium.Primitive({\n * geometryInstances : new Cesium.GeometryInstance({\n * geometry : Cesium.EllipsoidGeometry.createGeometry(new Cesium.EllipsoidGeometry({\n * radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),\n * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL\n * })),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),\n * id : 'ellipsoid',\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)\n * }\n * }),\n * appearance : new Cesium.PerInstanceColorAppearance(),\n * asynchronous : false\n * }));\n *\n * @see GeometryInstance\n * @see Appearance\n * @see ClassificationPrimitive\n * @see GroundPrimitive\n */\nfunction Primitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The geometry instances rendered with this primitive. This may\n * be undefined if options.releaseGeometryInstances\n * is true when the primitive is constructed.\n *

\n * Changing this property after the primitive is rendered has no effect.\n *

\n *\n * @readonly\n * @type GeometryInstance[]|GeometryInstance\n *\n * @default undefined\n */\n this.geometryInstances = options.geometryInstances;\n\n /**\n * The {@link Appearance} used to shade this primitive. Each geometry\n * instance is shaded with the same appearance. Some appearances, like\n * {@link PerInstanceColorAppearance} allow giving each instance unique\n * properties.\n *\n * @type Appearance\n *\n * @default undefined\n */\n this.appearance = options.appearance;\n this._appearance = undefined;\n this._material = undefined;\n\n /**\n * The {@link Appearance} used to shade this primitive when it fails the depth test. Each geometry\n * instance is shaded with the same appearance. Some appearances, like\n * {@link PerInstanceColorAppearance} allow giving each instance unique\n * properties.\n *\n *

\n * When using an appearance that requires a color attribute, like PerInstanceColorAppearance,\n * add a depthFailColor per-instance attribute instead.\n *

\n *\n *

\n * Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported,\n * there may be artifacts.\n *

\n * @type Appearance\n *\n * @default undefined\n */\n this.depthFailAppearance = options.depthFailAppearance;\n this._depthFailAppearance = undefined;\n this._depthFailMaterial = undefined;\n\n /**\n * The 4x4 transformation matrix that transforms the primitive (all geometry instances) from model to world coordinates.\n * When this is the identity matrix, the primitive is drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n *

\n * This property is only supported in 3D mode.\n *

\n *\n * @type Matrix4\n *\n * @default Matrix4.IDENTITY\n *\n * @example\n * const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);\n * p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n this._modelMatrix = new Matrix4();\n\n /**\n * Determines if the primitive will be shown. This affects all geometry\n * instances in the primitive.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n this._vertexCacheOptimize = defaultValue(options.vertexCacheOptimize, false);\n this._interleave = defaultValue(options.interleave, false);\n this._releaseGeometryInstances = defaultValue(\n options.releaseGeometryInstances,\n true\n );\n this._allowPicking = defaultValue(options.allowPicking, true);\n this._asynchronous = defaultValue(options.asynchronous, true);\n this._compressVertices = defaultValue(options.compressVertices, true);\n\n /**\n * When true, the renderer frustum culls and horizon culls the primitive's commands\n * based on their bounding volume. Set this to false for a small performance gain\n * if you are manually culling the primitive.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.cull = defaultValue(options.cull, true);\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * @private\n */\n this.rtcCenter = options.rtcCenter;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(this.rtcCenter) &&\n (!defined(this.geometryInstances) ||\n (Array.isArray(this.geometryInstances) &&\n this.geometryInstances.length !== 1))\n ) {\n throw new DeveloperError(\n \"Relative-to-center rendering only supports one geometry instance.\"\n );\n }\n //>>includeEnd('debug');\n\n /**\n * Determines whether this primitive casts or receives shadows from light sources.\n *\n * @type {ShadowMode}\n *\n * @default ShadowMode.DISABLED\n */\n this.shadows = defaultValue(options.shadows, ShadowMode.DISABLED);\n\n this._translucent = undefined;\n\n this._state = PrimitiveState.READY;\n this._geometries = [];\n this._error = undefined;\n this._numberOfInstances = 0;\n\n this._boundingSpheres = [];\n this._boundingSphereWC = [];\n this._boundingSphereCV = [];\n this._boundingSphere2D = [];\n this._boundingSphereMorph = [];\n this._perInstanceAttributeCache = new Map();\n this._instanceIds = [];\n this._lastPerInstanceAttributeIndex = 0;\n\n this._va = [];\n this._attributeLocations = undefined;\n this._primitiveType = undefined;\n\n this._frontFaceRS = undefined;\n this._backFaceRS = undefined;\n this._sp = undefined;\n\n this._depthFailAppearance = undefined;\n this._spDepthFail = undefined;\n this._frontFaceDepthFailRS = undefined;\n this._backFaceDepthFailRS = undefined;\n\n this._pickIds = [];\n\n this._colorCommands = [];\n this._pickCommands = [];\n\n this._createBoundingVolumeFunction = options._createBoundingVolumeFunction;\n this._createRenderStatesFunction = options._createRenderStatesFunction;\n this._createShaderProgramFunction = options._createShaderProgramFunction;\n this._createCommandsFunction = options._createCommandsFunction;\n this._updateAndQueueCommandsFunction =\n options._updateAndQueueCommandsFunction;\n\n this._createPickOffsets = options._createPickOffsets;\n this._pickOffsets = undefined;\n\n this._createGeometryResults = undefined;\n this._ready = false;\n\n this._batchTable = undefined;\n this._batchTableAttributeIndices = undefined;\n this._offsetInstanceExtend = undefined;\n this._batchTableOffsetAttribute2DIndex = undefined;\n this._batchTableOffsetsUpdated = false;\n this._instanceBoundingSpheres = undefined;\n this._instanceBoundingSpheresCV = undefined;\n this._tempBoundingSpheres = undefined;\n this._recomputeBoundingSpheres = false;\n this._batchTableBoundingSpheresUpdated = false;\n this._batchTableBoundingSphereAttributeIndices = undefined;\n}\n\nObject.defineProperties(Primitive.prototype, {\n /**\n * When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n vertexCacheOptimize: {\n get: function () {\n return this._vertexCacheOptimize;\n },\n },\n\n /**\n * Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n interleave: {\n get: function () {\n return this._interleave;\n },\n },\n\n /**\n * When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n releaseGeometryInstances: {\n get: function () {\n return this._releaseGeometryInstances;\n },\n },\n\n /**\n * When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved. *\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n allowPicking: {\n get: function () {\n return this._allowPicking;\n },\n },\n\n /**\n * Determines if the geometry instances will be created and batched on a web worker.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n asynchronous: {\n get: function () {\n return this._asynchronous;\n },\n },\n\n /**\n * When true, geometry vertices are compressed, which will save memory.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n compressVertices: {\n get: function () {\n return this._compressVertices;\n },\n },\n\n /**\n * Determines if the primitive is complete and ready to render. If this property is\n * true, the primitive will be rendered the next time that {@link Primitive#update}\n * is called.\n *\n * @memberof Primitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @example\n * // Wait for a primitive to become ready before accessing attributes\n * const removeListener = scene.postRender.addEventListener(() => {\n * if (!frustumPrimitive.ready) {\n * return;\n * }\n *\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);\n *\n * removeListener();\n * });\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nfunction getCommonPerInstanceAttributeNames(instances) {\n const length = instances.length;\n\n const attributesInAllInstances = [];\n const attributes0 = instances[0].attributes;\n let name;\n\n for (name in attributes0) {\n if (attributes0.hasOwnProperty(name) && defined(attributes0[name])) {\n const attribute = attributes0[name];\n let inAllInstances = true;\n\n // Does this same attribute exist in all instances?\n for (let i = 1; i < length; ++i) {\n const otherAttribute = instances[i].attributes[name];\n\n if (\n !defined(otherAttribute) ||\n attribute.componentDatatype !== otherAttribute.componentDatatype ||\n attribute.componentsPerAttribute !==\n otherAttribute.componentsPerAttribute ||\n attribute.normalize !== otherAttribute.normalize\n ) {\n inAllInstances = false;\n break;\n }\n }\n\n if (inAllInstances) {\n attributesInAllInstances.push(name);\n }\n }\n }\n\n return attributesInAllInstances;\n}\n\nconst scratchGetAttributeCartesian2 = new Cartesian2();\nconst scratchGetAttributeCartesian3 = new Cartesian3();\nconst scratchGetAttributeCartesian4 = new Cartesian4();\n\nfunction getAttributeValue(value) {\n const componentsPerAttribute = value.length;\n if (componentsPerAttribute === 1) {\n return value[0];\n } else if (componentsPerAttribute === 2) {\n return Cartesian2.unpack(value, 0, scratchGetAttributeCartesian2);\n } else if (componentsPerAttribute === 3) {\n return Cartesian3.unpack(value, 0, scratchGetAttributeCartesian3);\n } else if (componentsPerAttribute === 4) {\n return Cartesian4.unpack(value, 0, scratchGetAttributeCartesian4);\n }\n}\n\nfunction createBatchTable(primitive, context) {\n const geometryInstances = primitive.geometryInstances;\n const instances = Array.isArray(geometryInstances)\n ? geometryInstances\n : [geometryInstances];\n const numberOfInstances = instances.length;\n if (numberOfInstances === 0) {\n return;\n }\n\n const names = getCommonPerInstanceAttributeNames(instances);\n const length = names.length;\n\n const attributes = [];\n const attributeIndices = {};\n const boundingSphereAttributeIndices = {};\n let offset2DIndex;\n\n const firstInstance = instances[0];\n let instanceAttributes = firstInstance.attributes;\n\n let i;\n let name;\n let attribute;\n\n for (i = 0; i < length; ++i) {\n name = names[i];\n attribute = instanceAttributes[name];\n\n attributeIndices[name] = i;\n attributes.push({\n functionName: `czm_batchTable_${name}`,\n componentDatatype: attribute.componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n });\n }\n\n if (names.indexOf(\"distanceDisplayCondition\") !== -1) {\n attributes.push(\n {\n functionName: \"czm_batchTable_boundingSphereCenter3DHigh\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n functionName: \"czm_batchTable_boundingSphereCenter3DLow\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n functionName: \"czm_batchTable_boundingSphereCenter2DHigh\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n functionName: \"czm_batchTable_boundingSphereCenter2DLow\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n functionName: \"czm_batchTable_boundingSphereRadius\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 1,\n }\n );\n boundingSphereAttributeIndices.center3DHigh = attributes.length - 5;\n boundingSphereAttributeIndices.center3DLow = attributes.length - 4;\n boundingSphereAttributeIndices.center2DHigh = attributes.length - 3;\n boundingSphereAttributeIndices.center2DLow = attributes.length - 2;\n boundingSphereAttributeIndices.radius = attributes.length - 1;\n }\n\n if (names.indexOf(\"offset\") !== -1) {\n attributes.push({\n functionName: \"czm_batchTable_offset2D\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n });\n offset2DIndex = attributes.length - 1;\n }\n\n attributes.push({\n functionName: \"czm_batchTable_pickColor\",\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 4,\n normalize: true,\n });\n\n const attributesLength = attributes.length;\n const batchTable = new BatchTable(context, attributes, numberOfInstances);\n\n for (i = 0; i < numberOfInstances; ++i) {\n const instance = instances[i];\n instanceAttributes = instance.attributes;\n\n for (let j = 0; j < length; ++j) {\n name = names[j];\n attribute = instanceAttributes[name];\n const value = getAttributeValue(attribute.value);\n const attributeIndex = attributeIndices[name];\n batchTable.setBatchedAttribute(i, attributeIndex, value);\n }\n\n const pickObject = {\n primitive: defaultValue(instance.pickPrimitive, primitive),\n };\n\n if (defined(instance.id)) {\n pickObject.id = instance.id;\n }\n\n const pickId = context.createPickId(pickObject);\n primitive._pickIds.push(pickId);\n\n const pickColor = pickId.color;\n const color = scratchGetAttributeCartesian4;\n color.x = Color.floatToByte(pickColor.red);\n color.y = Color.floatToByte(pickColor.green);\n color.z = Color.floatToByte(pickColor.blue);\n color.w = Color.floatToByte(pickColor.alpha);\n\n batchTable.setBatchedAttribute(i, attributesLength - 1, color);\n }\n\n primitive._batchTable = batchTable;\n primitive._batchTableAttributeIndices = attributeIndices;\n primitive._batchTableBoundingSphereAttributeIndices = boundingSphereAttributeIndices;\n primitive._batchTableOffsetAttribute2DIndex = offset2DIndex;\n}\n\nfunction cloneAttribute(attribute) {\n let clonedValues;\n if (Array.isArray(attribute.values)) {\n clonedValues = attribute.values.slice(0);\n } else {\n clonedValues = new attribute.values.constructor(attribute.values);\n }\n return new GeometryAttribute({\n componentDatatype: attribute.componentDatatype,\n componentsPerAttribute: attribute.componentsPerAttribute,\n normalize: attribute.normalize,\n values: clonedValues,\n });\n}\n\nfunction cloneGeometry(geometry) {\n const attributes = geometry.attributes;\n const newAttributes = new GeometryAttributes();\n for (const property in attributes) {\n if (attributes.hasOwnProperty(property) && defined(attributes[property])) {\n newAttributes[property] = cloneAttribute(attributes[property]);\n }\n }\n\n let indices;\n if (defined(geometry.indices)) {\n const sourceValues = geometry.indices;\n if (Array.isArray(sourceValues)) {\n indices = sourceValues.slice(0);\n } else {\n indices = new sourceValues.constructor(sourceValues);\n }\n }\n\n return new Geometry({\n attributes: newAttributes,\n indices: indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: BoundingSphere.clone(geometry.boundingSphere),\n });\n}\n\nfunction cloneInstance(instance, geometry) {\n return {\n geometry: geometry,\n attributes: instance.attributes,\n modelMatrix: Matrix4.clone(instance.modelMatrix),\n pickPrimitive: instance.pickPrimitive,\n id: instance.id,\n };\n}\n\nconst positionRegex = /in\\s+vec(?:3|4)\\s+(.*)3DHigh;/g;\n\nPrimitive._modifyShaderPosition = function (\n primitive,\n vertexShaderSource,\n scene3DOnly\n) {\n let match;\n\n let forwardDecl = \"\";\n let attributes = \"\";\n let computeFunctions = \"\";\n\n while ((match = positionRegex.exec(vertexShaderSource)) !== null) {\n const name = match[1];\n\n const functionName = `vec4 czm_compute${name[0].toUpperCase()}${name.substr(\n 1\n )}()`;\n\n // Don't forward-declare czm_computePosition because computePosition.glsl already does.\n if (functionName !== \"vec4 czm_computePosition()\") {\n forwardDecl += `${functionName};\\n`;\n }\n\n if (!defined(primitive.rtcCenter)) {\n // Use GPU RTE\n if (!scene3DOnly) {\n attributes += `in vec3 ${name}2DHigh;\\nin vec3 ${name}2DLow;\\n`;\n\n computeFunctions +=\n `${functionName}\\n` +\n `{\\n` +\n ` vec4 p;\\n` +\n ` if (czm_morphTime == 1.0)\\n` +\n ` {\\n` +\n ` p = czm_translateRelativeToEye(${name}3DHigh, ${name}3DLow);\\n` +\n ` }\\n` +\n ` else if (czm_morphTime == 0.0)\\n` +\n ` {\\n` +\n ` p = czm_translateRelativeToEye(${name}2DHigh.zxy, ${name}2DLow.zxy);\\n` +\n ` }\\n` +\n ` else\\n` +\n ` {\\n` +\n ` p = czm_columbusViewMorph(\\n` +\n ` czm_translateRelativeToEye(${name}2DHigh.zxy, ${name}2DLow.zxy),\\n` +\n ` czm_translateRelativeToEye(${name}3DHigh, ${name}3DLow),\\n` +\n ` czm_morphTime);\\n` +\n ` }\\n` +\n ` return p;\\n` +\n `}\\n\\n`;\n } else {\n computeFunctions +=\n `${functionName}\\n` +\n `{\\n` +\n ` return czm_translateRelativeToEye(${name}3DHigh, ${name}3DLow);\\n` +\n `}\\n\\n`;\n }\n } else {\n // Use RTC\n vertexShaderSource = vertexShaderSource.replace(\n /in\\s+vec(?:3|4)\\s+position3DHigh;/g,\n \"\"\n );\n vertexShaderSource = vertexShaderSource.replace(\n /in\\s+vec(?:3|4)\\s+position3DLow;/g,\n \"\"\n );\n\n forwardDecl += \"uniform mat4 u_modifiedModelView;\\n\";\n attributes += \"in vec4 position;\\n\";\n\n computeFunctions +=\n `${functionName}\\n` +\n `{\\n` +\n ` return u_modifiedModelView * position;\\n` +\n `}\\n\\n`;\n\n vertexShaderSource = vertexShaderSource.replace(\n /czm_modelViewRelativeToEye\\s+\\*\\s+/g,\n \"\"\n );\n vertexShaderSource = vertexShaderSource.replace(\n /czm_modelViewProjectionRelativeToEye/g,\n \"czm_projection\"\n );\n }\n }\n\n return [forwardDecl, attributes, vertexShaderSource, computeFunctions].join(\n \"\\n\"\n );\n};\n\nPrimitive._appendShowToShader = function (primitive, vertexShaderSource) {\n if (!defined(primitive._batchTableAttributeIndices.show)) {\n return vertexShaderSource;\n }\n\n const renamedVS = ShaderSource.replaceMain(\n vertexShaderSource,\n \"czm_non_show_main\"\n );\n const showMain =\n \"void main() \\n\" +\n \"{ \\n\" +\n \" czm_non_show_main(); \\n\" +\n \" gl_Position *= czm_batchTable_show(batchId); \\n\" +\n \"}\";\n\n return `${renamedVS}\\n${showMain}`;\n};\n\nPrimitive._updateColorAttribute = function (\n primitive,\n vertexShaderSource,\n isDepthFail\n) {\n // some appearances have a color attribute for per vertex color.\n // only remove if color is a per instance attribute.\n if (\n !defined(primitive._batchTableAttributeIndices.color) &&\n !defined(primitive._batchTableAttributeIndices.depthFailColor)\n ) {\n return vertexShaderSource;\n }\n\n if (vertexShaderSource.search(/in\\s+vec4\\s+color;/g) === -1) {\n return vertexShaderSource;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (\n isDepthFail &&\n !defined(primitive._batchTableAttributeIndices.depthFailColor)\n ) {\n throw new DeveloperError(\n \"A depthFailColor per-instance attribute is required when using a depth fail appearance that uses a color attribute.\"\n );\n }\n //>>includeEnd('debug');\n\n let modifiedVS = vertexShaderSource;\n modifiedVS = modifiedVS.replace(/in\\s+vec4\\s+color;/g, \"\");\n if (!isDepthFail) {\n modifiedVS = modifiedVS.replace(\n /(\\b)color(\\b)/g,\n \"$1czm_batchTable_color(batchId)$2\"\n );\n } else {\n modifiedVS = modifiedVS.replace(\n /(\\b)color(\\b)/g,\n \"$1czm_batchTable_depthFailColor(batchId)$2\"\n );\n }\n return modifiedVS;\n};\n\nfunction appendPickToVertexShader(source) {\n const renamedVS = ShaderSource.replaceMain(source, \"czm_non_pick_main\");\n const pickMain =\n \"out vec4 v_pickColor; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" czm_non_pick_main(); \\n\" +\n \" v_pickColor = czm_batchTable_pickColor(batchId); \\n\" +\n \"}\";\n\n return `${renamedVS}\\n${pickMain}`;\n}\n\nfunction appendPickToFragmentShader(source) {\n return `in vec4 v_pickColor;\\n${source}`;\n}\n\nPrimitive._updatePickColorAttribute = function (source) {\n let vsPick = source.replace(/in\\s+vec4\\s+pickColor;/g, \"\");\n vsPick = vsPick.replace(\n /(\\b)pickColor(\\b)/g,\n \"$1czm_batchTable_pickColor(batchId)$2\"\n );\n return vsPick;\n};\n\nPrimitive._appendOffsetToShader = function (primitive, vertexShaderSource) {\n if (!defined(primitive._batchTableAttributeIndices.offset)) {\n return vertexShaderSource;\n }\n\n let attr = \"in float batchId;\\n\";\n attr += \"in float applyOffset;\";\n let modifiedShader = vertexShaderSource.replace(\n /in\\s+float\\s+batchId;/g,\n attr\n );\n\n let str = \"vec4 $1 = czm_computePosition();\\n\";\n str += \" if (czm_sceneMode == czm_sceneMode3D)\\n\";\n str += \" {\\n\";\n str +=\n \" $1 = $1 + vec4(czm_batchTable_offset(batchId) * applyOffset, 0.0);\";\n str += \" }\\n\";\n str += \" else\\n\";\n str += \" {\\n\";\n str +=\n \" $1 = $1 + vec4(czm_batchTable_offset2D(batchId) * applyOffset, 0.0);\";\n str += \" }\\n\";\n modifiedShader = modifiedShader.replace(\n /vec4\\s+([A-Za-z0-9_]+)\\s+=\\s+czm_computePosition\\(\\);/g,\n str\n );\n return modifiedShader;\n};\n\nPrimitive._appendDistanceDisplayConditionToShader = function (\n primitive,\n vertexShaderSource,\n scene3DOnly\n) {\n if (\n !defined(primitive._batchTableAttributeIndices.distanceDisplayCondition)\n ) {\n return vertexShaderSource;\n }\n\n const renamedVS = ShaderSource.replaceMain(\n vertexShaderSource,\n \"czm_non_distanceDisplayCondition_main\"\n );\n let distanceDisplayConditionMain =\n \"void main() \\n\" +\n \"{ \\n\" +\n \" czm_non_distanceDisplayCondition_main(); \\n\" +\n \" vec2 distanceDisplayCondition = czm_batchTable_distanceDisplayCondition(batchId);\\n\" +\n \" vec3 boundingSphereCenter3DHigh = czm_batchTable_boundingSphereCenter3DHigh(batchId);\\n\" +\n \" vec3 boundingSphereCenter3DLow = czm_batchTable_boundingSphereCenter3DLow(batchId);\\n\" +\n \" float boundingSphereRadius = czm_batchTable_boundingSphereRadius(batchId);\\n\";\n\n if (!scene3DOnly) {\n distanceDisplayConditionMain +=\n \" vec3 boundingSphereCenter2DHigh = czm_batchTable_boundingSphereCenter2DHigh(batchId);\\n\" +\n \" vec3 boundingSphereCenter2DLow = czm_batchTable_boundingSphereCenter2DLow(batchId);\\n\" +\n \" vec4 centerRTE;\\n\" +\n \" if (czm_morphTime == 1.0)\\n\" +\n \" {\\n\" +\n \" centerRTE = czm_translateRelativeToEye(boundingSphereCenter3DHigh, boundingSphereCenter3DLow);\\n\" +\n \" }\\n\" +\n \" else if (czm_morphTime == 0.0)\\n\" +\n \" {\\n\" +\n \" centerRTE = czm_translateRelativeToEye(boundingSphereCenter2DHigh.zxy, boundingSphereCenter2DLow.zxy);\\n\" +\n \" }\\n\" +\n \" else\\n\" +\n \" {\\n\" +\n \" centerRTE = czm_columbusViewMorph(\\n\" +\n \" czm_translateRelativeToEye(boundingSphereCenter2DHigh.zxy, boundingSphereCenter2DLow.zxy),\\n\" +\n \" czm_translateRelativeToEye(boundingSphereCenter3DHigh, boundingSphereCenter3DLow),\\n\" +\n \" czm_morphTime);\\n\" +\n \" }\\n\";\n } else {\n distanceDisplayConditionMain +=\n \" vec4 centerRTE = czm_translateRelativeToEye(boundingSphereCenter3DHigh, boundingSphereCenter3DLow);\\n\";\n }\n\n distanceDisplayConditionMain +=\n \" float radiusSq = boundingSphereRadius * boundingSphereRadius; \\n\" +\n \" float distanceSq; \\n\" +\n \" if (czm_sceneMode == czm_sceneMode2D) \\n\" +\n \" { \\n\" +\n \" distanceSq = czm_eyeHeight2D.y - radiusSq; \\n\" +\n \" } \\n\" +\n \" else \\n\" +\n \" { \\n\" +\n \" distanceSq = dot(centerRTE.xyz, centerRTE.xyz) - radiusSq; \\n\" +\n \" } \\n\" +\n \" distanceSq = max(distanceSq, 0.0); \\n\" +\n \" float nearSq = distanceDisplayCondition.x * distanceDisplayCondition.x; \\n\" +\n \" float farSq = distanceDisplayCondition.y * distanceDisplayCondition.y; \\n\" +\n \" float show = (distanceSq >= nearSq && distanceSq <= farSq) ? 1.0 : 0.0; \\n\" +\n \" gl_Position *= show; \\n\" +\n \"}\";\n return `${renamedVS}\\n${distanceDisplayConditionMain}`;\n};\n\nfunction modifyForEncodedNormals(primitive, vertexShaderSource) {\n if (!primitive.compressVertices) {\n return vertexShaderSource;\n }\n\n const containsNormal =\n vertexShaderSource.search(/in\\s+vec3\\s+normal;/g) !== -1;\n const containsSt = vertexShaderSource.search(/in\\s+vec2\\s+st;/g) !== -1;\n if (!containsNormal && !containsSt) {\n return vertexShaderSource;\n }\n\n const containsTangent =\n vertexShaderSource.search(/in\\s+vec3\\s+tangent;/g) !== -1;\n const containsBitangent =\n vertexShaderSource.search(/in\\s+vec3\\s+bitangent;/g) !== -1;\n\n let numComponents = containsSt && containsNormal ? 2.0 : 1.0;\n numComponents += containsTangent || containsBitangent ? 1 : 0;\n\n const type = numComponents > 1 ? `vec${numComponents}` : \"float\";\n\n const attributeName = \"compressedAttributes\";\n const attributeDecl = `in ${type} ${attributeName};`;\n\n let globalDecl = \"\";\n let decode = \"\";\n\n if (containsSt) {\n globalDecl += \"vec2 st;\\n\";\n const stComponent =\n numComponents > 1 ? `${attributeName}.x` : attributeName;\n decode += ` st = czm_decompressTextureCoordinates(${stComponent});\\n`;\n }\n\n if (containsNormal && containsTangent && containsBitangent) {\n globalDecl += \"vec3 normal;\\n\" + \"vec3 tangent;\\n\" + \"vec3 bitangent;\\n\";\n decode += ` czm_octDecode(${attributeName}.${\n containsSt ? \"yz\" : \"xy\"\n }, normal, tangent, bitangent);\\n`;\n } else {\n if (containsNormal) {\n globalDecl += \"vec3 normal;\\n\";\n decode += ` normal = czm_octDecode(${attributeName}${\n numComponents > 1 ? `.${containsSt ? \"y\" : \"x\"}` : \"\"\n });\\n`;\n }\n\n if (containsTangent) {\n globalDecl += \"vec3 tangent;\\n\";\n decode += ` tangent = czm_octDecode(${attributeName}.${\n containsSt && containsNormal ? \"z\" : \"y\"\n });\\n`;\n }\n\n if (containsBitangent) {\n globalDecl += \"vec3 bitangent;\\n\";\n decode += ` bitangent = czm_octDecode(${attributeName}.${\n containsSt && containsNormal ? \"z\" : \"y\"\n });\\n`;\n }\n }\n\n let modifiedVS = vertexShaderSource;\n modifiedVS = modifiedVS.replace(/in\\s+vec3\\s+normal;/g, \"\");\n modifiedVS = modifiedVS.replace(/in\\s+vec2\\s+st;/g, \"\");\n modifiedVS = modifiedVS.replace(/in\\s+vec3\\s+tangent;/g, \"\");\n modifiedVS = modifiedVS.replace(/in\\s+vec3\\s+bitangent;/g, \"\");\n modifiedVS = ShaderSource.replaceMain(modifiedVS, \"czm_non_compressed_main\");\n const compressedMain =\n `${\"void main() \\n\" + \"{ \\n\"}${decode} czm_non_compressed_main(); \\n` +\n `}`;\n\n return [attributeDecl, globalDecl, modifiedVS, compressedMain].join(\"\\n\");\n}\n\nfunction depthClampVS(vertexShaderSource) {\n let modifiedVS = ShaderSource.replaceMain(\n vertexShaderSource,\n \"czm_non_depth_clamp_main\"\n );\n modifiedVS +=\n \"void main() {\\n\" +\n \" czm_non_depth_clamp_main();\\n\" +\n \" gl_Position = czm_depthClamp(gl_Position);\" +\n \"}\\n\";\n return modifiedVS;\n}\n\nfunction depthClampFS(fragmentShaderSource) {\n let modifiedFS = ShaderSource.replaceMain(\n fragmentShaderSource,\n \"czm_non_depth_clamp_main\"\n );\n modifiedFS +=\n \"void main() {\\n\" +\n \" czm_non_depth_clamp_main();\\n\" +\n \" #if defined(LOG_DEPTH)\\n\" +\n \" czm_writeLogDepth();\\n\" +\n \" #else\\n\" +\n \" czm_writeDepthClamp();\\n\" +\n \" #endif\\n\" +\n \"}\\n\";\n return modifiedFS;\n}\n\nfunction validateShaderMatching(shaderProgram, attributeLocations) {\n // For a VAO and shader program to be compatible, the VAO must have\n // all active attribute in the shader program. The VAO may have\n // extra attributes with the only concern being a potential\n // performance hit due to extra memory bandwidth and cache pollution.\n // The shader source could have extra attributes that are not used,\n // but there is no guarantee they will be optimized out.\n //\n // Here, we validate that the VAO has all attributes required\n // to match the shader program.\n const shaderAttributes = shaderProgram.vertexAttributes;\n\n //>>includeStart('debug', pragmas.debug);\n for (const name in shaderAttributes) {\n if (shaderAttributes.hasOwnProperty(name)) {\n if (!defined(attributeLocations[name])) {\n throw new DeveloperError(\n `Appearance/Geometry mismatch. The appearance requires vertex shader attribute input '${name}', which was not computed as part of the Geometry. Use the appearance's vertexFormat property when constructing the geometry.`\n );\n }\n }\n }\n //>>includeEnd('debug');\n}\n\nfunction getUniformFunction(uniforms, name) {\n return function () {\n return uniforms[name];\n };\n}\n\nconst numberOfCreationWorkers = Math.max(\n FeatureDetection.hardwareConcurrency - 1,\n 1\n);\nlet createGeometryTaskProcessors;\nconst combineGeometryTaskProcessor = new TaskProcessor(\"combineGeometry\");\n\nfunction loadAsynchronous(primitive, frameState) {\n let instances;\n let geometry;\n let i;\n let j;\n\n const instanceIds = primitive._instanceIds;\n\n if (primitive._state === PrimitiveState.READY) {\n instances = Array.isArray(primitive.geometryInstances)\n ? primitive.geometryInstances\n : [primitive.geometryInstances];\n const length = (primitive._numberOfInstances = instances.length);\n\n const promises = [];\n let subTasks = [];\n for (i = 0; i < length; ++i) {\n geometry = instances[i].geometry;\n instanceIds.push(instances[i].id);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(geometry._workerName)) {\n throw new DeveloperError(\n \"_workerName must be defined for asynchronous geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n subTasks.push({\n moduleName: geometry._workerName,\n geometry: geometry,\n });\n }\n\n if (!defined(createGeometryTaskProcessors)) {\n createGeometryTaskProcessors = new Array(numberOfCreationWorkers);\n for (i = 0; i < numberOfCreationWorkers; i++) {\n createGeometryTaskProcessors[i] = new TaskProcessor(\"createGeometry\");\n }\n }\n\n let subTask;\n subTasks = subdivideArray(subTasks, numberOfCreationWorkers);\n\n for (i = 0; i < subTasks.length; i++) {\n let packedLength = 0;\n const workerSubTasks = subTasks[i];\n const workerSubTasksLength = workerSubTasks.length;\n for (j = 0; j < workerSubTasksLength; ++j) {\n subTask = workerSubTasks[j];\n geometry = subTask.geometry;\n if (defined(geometry.constructor.pack)) {\n subTask.offset = packedLength;\n packedLength += defaultValue(\n geometry.constructor.packedLength,\n geometry.packedLength\n );\n }\n }\n\n let subTaskTransferableObjects;\n\n if (packedLength > 0) {\n const array = new Float64Array(packedLength);\n subTaskTransferableObjects = [array.buffer];\n\n for (j = 0; j < workerSubTasksLength; ++j) {\n subTask = workerSubTasks[j];\n geometry = subTask.geometry;\n if (defined(geometry.constructor.pack)) {\n geometry.constructor.pack(geometry, array, subTask.offset);\n subTask.geometry = array;\n }\n }\n }\n\n promises.push(\n createGeometryTaskProcessors[i].scheduleTask(\n {\n subTasks: subTasks[i],\n },\n subTaskTransferableObjects\n )\n );\n }\n\n primitive._state = PrimitiveState.CREATING;\n\n Promise.all(promises)\n .then(function (results) {\n primitive._createGeometryResults = results;\n primitive._state = PrimitiveState.CREATED;\n })\n .catch(function (error) {\n setReady(primitive, frameState, PrimitiveState.FAILED, error);\n });\n } else if (primitive._state === PrimitiveState.CREATED) {\n const transferableObjects = [];\n instances = Array.isArray(primitive.geometryInstances)\n ? primitive.geometryInstances\n : [primitive.geometryInstances];\n\n const scene3DOnly = frameState.scene3DOnly;\n const projection = frameState.mapProjection;\n\n const promise = combineGeometryTaskProcessor.scheduleTask(\n PrimitivePipeline.packCombineGeometryParameters(\n {\n createGeometryResults: primitive._createGeometryResults,\n instances: instances,\n ellipsoid: projection.ellipsoid,\n projection: projection,\n elementIndexUintSupported: frameState.context.elementIndexUint,\n scene3DOnly: scene3DOnly,\n vertexCacheOptimize: primitive.vertexCacheOptimize,\n compressVertices: primitive.compressVertices,\n modelMatrix: primitive.modelMatrix,\n createPickOffsets: primitive._createPickOffsets,\n },\n transferableObjects\n ),\n transferableObjects\n );\n\n primitive._createGeometryResults = undefined;\n primitive._state = PrimitiveState.COMBINING;\n\n Promise.resolve(promise)\n .then(function (packedResult) {\n const result = PrimitivePipeline.unpackCombineGeometryResults(\n packedResult\n );\n primitive._geometries = result.geometries;\n primitive._attributeLocations = result.attributeLocations;\n primitive.modelMatrix = Matrix4.clone(\n result.modelMatrix,\n primitive.modelMatrix\n );\n primitive._pickOffsets = result.pickOffsets;\n primitive._offsetInstanceExtend = result.offsetInstanceExtend;\n primitive._instanceBoundingSpheres = result.boundingSpheres;\n primitive._instanceBoundingSpheresCV = result.boundingSpheresCV;\n\n if (\n defined(primitive._geometries) &&\n primitive._geometries.length > 0\n ) {\n primitive._recomputeBoundingSpheres = true;\n primitive._state = PrimitiveState.COMBINED;\n } else {\n setReady(primitive, frameState, PrimitiveState.FAILED, undefined);\n }\n })\n .catch(function (error) {\n setReady(primitive, frameState, PrimitiveState.FAILED, error);\n });\n }\n}\n\nfunction loadSynchronous(primitive, frameState) {\n const instances = Array.isArray(primitive.geometryInstances)\n ? primitive.geometryInstances\n : [primitive.geometryInstances];\n const length = (primitive._numberOfInstances = instances.length);\n const clonedInstances = new Array(length);\n const instanceIds = primitive._instanceIds;\n\n let instance;\n let i;\n\n let geometryIndex = 0;\n for (i = 0; i < length; i++) {\n instance = instances[i];\n const geometry = instance.geometry;\n\n let createdGeometry;\n if (defined(geometry.attributes) && defined(geometry.primitiveType)) {\n createdGeometry = cloneGeometry(geometry);\n } else {\n createdGeometry = geometry.constructor.createGeometry(geometry);\n }\n\n clonedInstances[geometryIndex++] = cloneInstance(instance, createdGeometry);\n instanceIds.push(instance.id);\n }\n\n clonedInstances.length = geometryIndex;\n\n const scene3DOnly = frameState.scene3DOnly;\n const projection = frameState.mapProjection;\n\n const result = PrimitivePipeline.combineGeometry({\n instances: clonedInstances,\n ellipsoid: projection.ellipsoid,\n projection: projection,\n elementIndexUintSupported: frameState.context.elementIndexUint,\n scene3DOnly: scene3DOnly,\n vertexCacheOptimize: primitive.vertexCacheOptimize,\n compressVertices: primitive.compressVertices,\n modelMatrix: primitive.modelMatrix,\n createPickOffsets: primitive._createPickOffsets,\n });\n\n primitive._geometries = result.geometries;\n primitive._attributeLocations = result.attributeLocations;\n primitive.modelMatrix = Matrix4.clone(\n result.modelMatrix,\n primitive.modelMatrix\n );\n primitive._pickOffsets = result.pickOffsets;\n primitive._offsetInstanceExtend = result.offsetInstanceExtend;\n primitive._instanceBoundingSpheres = result.boundingSpheres;\n primitive._instanceBoundingSpheresCV = result.boundingSpheresCV;\n\n if (defined(primitive._geometries) && primitive._geometries.length > 0) {\n primitive._recomputeBoundingSpheres = true;\n primitive._state = PrimitiveState.COMBINED;\n } else {\n setReady(primitive, frameState, PrimitiveState.FAILED, undefined);\n }\n}\n\nfunction recomputeBoundingSpheres(primitive, frameState) {\n const offsetIndex = primitive._batchTableAttributeIndices.offset;\n if (!primitive._recomputeBoundingSpheres || !defined(offsetIndex)) {\n primitive._recomputeBoundingSpheres = false;\n return;\n }\n\n let i;\n const offsetInstanceExtend = primitive._offsetInstanceExtend;\n const boundingSpheres = primitive._instanceBoundingSpheres;\n const length = boundingSpheres.length;\n let newBoundingSpheres = primitive._tempBoundingSpheres;\n if (!defined(newBoundingSpheres)) {\n newBoundingSpheres = new Array(length);\n for (i = 0; i < length; i++) {\n newBoundingSpheres[i] = new BoundingSphere();\n }\n primitive._tempBoundingSpheres = newBoundingSpheres;\n }\n for (i = 0; i < length; ++i) {\n let newBS = newBoundingSpheres[i];\n const offset = primitive._batchTable.getBatchedAttribute(\n i,\n offsetIndex,\n new Cartesian3()\n );\n newBS = boundingSpheres[i].clone(newBS);\n transformBoundingSphere(newBS, offset, offsetInstanceExtend[i]);\n }\n const combinedBS = [];\n const combinedWestBS = [];\n const combinedEastBS = [];\n\n for (i = 0; i < length; ++i) {\n const bs = newBoundingSpheres[i];\n\n const minX = bs.center.x - bs.radius;\n if (\n minX > 0 ||\n BoundingSphere.intersectPlane(bs, Plane.ORIGIN_ZX_PLANE) !==\n Intersect.INTERSECTING\n ) {\n combinedBS.push(bs);\n } else {\n combinedWestBS.push(bs);\n combinedEastBS.push(bs);\n }\n }\n\n let resultBS1 = combinedBS[0];\n let resultBS2 = combinedEastBS[0];\n let resultBS3 = combinedWestBS[0];\n\n for (i = 1; i < combinedBS.length; i++) {\n resultBS1 = BoundingSphere.union(resultBS1, combinedBS[i]);\n }\n for (i = 1; i < combinedEastBS.length; i++) {\n resultBS2 = BoundingSphere.union(resultBS2, combinedEastBS[i]);\n }\n for (i = 1; i < combinedWestBS.length; i++) {\n resultBS3 = BoundingSphere.union(resultBS3, combinedWestBS[i]);\n }\n const result = [];\n if (defined(resultBS1)) {\n result.push(resultBS1);\n }\n if (defined(resultBS2)) {\n result.push(resultBS2);\n }\n if (defined(resultBS3)) {\n result.push(resultBS3);\n }\n\n for (i = 0; i < result.length; i++) {\n const boundingSphere = result[i].clone(primitive._boundingSpheres[i]);\n primitive._boundingSpheres[i] = boundingSphere;\n primitive._boundingSphereCV[i] = BoundingSphere.projectTo2D(\n boundingSphere,\n frameState.mapProjection,\n primitive._boundingSphereCV[i]\n );\n }\n\n Primitive._updateBoundingVolumes(\n primitive,\n frameState,\n primitive.modelMatrix,\n true\n );\n primitive._recomputeBoundingSpheres = false;\n}\n\nconst scratchBoundingSphereCenterEncoded = new EncodedCartesian3();\nconst scratchBoundingSphereCartographic = new Cartographic();\nconst scratchBoundingSphereCenter2D = new Cartesian3();\nconst scratchBoundingSphere = new BoundingSphere();\n\nfunction updateBatchTableBoundingSpheres(primitive, frameState) {\n const hasDistanceDisplayCondition = defined(\n primitive._batchTableAttributeIndices.distanceDisplayCondition\n );\n if (\n !hasDistanceDisplayCondition ||\n primitive._batchTableBoundingSpheresUpdated\n ) {\n return;\n }\n\n const indices = primitive._batchTableBoundingSphereAttributeIndices;\n const center3DHighIndex = indices.center3DHigh;\n const center3DLowIndex = indices.center3DLow;\n const center2DHighIndex = indices.center2DHigh;\n const center2DLowIndex = indices.center2DLow;\n const radiusIndex = indices.radius;\n\n const projection = frameState.mapProjection;\n const ellipsoid = projection.ellipsoid;\n\n const batchTable = primitive._batchTable;\n const boundingSpheres = primitive._instanceBoundingSpheres;\n const length = boundingSpheres.length;\n\n for (let i = 0; i < length; ++i) {\n let boundingSphere = boundingSpheres[i];\n if (!defined(boundingSphere)) {\n continue;\n }\n\n const modelMatrix = primitive.modelMatrix;\n if (defined(modelMatrix)) {\n boundingSphere = BoundingSphere.transform(\n boundingSphere,\n modelMatrix,\n scratchBoundingSphere\n );\n }\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let encodedCenter = EncodedCartesian3.fromCartesian(\n center,\n scratchBoundingSphereCenterEncoded\n );\n batchTable.setBatchedAttribute(i, center3DHighIndex, encodedCenter.high);\n batchTable.setBatchedAttribute(i, center3DLowIndex, encodedCenter.low);\n\n if (!frameState.scene3DOnly) {\n const cartographic = ellipsoid.cartesianToCartographic(\n center,\n scratchBoundingSphereCartographic\n );\n const center2D = projection.project(\n cartographic,\n scratchBoundingSphereCenter2D\n );\n encodedCenter = EncodedCartesian3.fromCartesian(\n center2D,\n scratchBoundingSphereCenterEncoded\n );\n batchTable.setBatchedAttribute(i, center2DHighIndex, encodedCenter.high);\n batchTable.setBatchedAttribute(i, center2DLowIndex, encodedCenter.low);\n }\n\n batchTable.setBatchedAttribute(i, radiusIndex, radius);\n }\n\n primitive._batchTableBoundingSpheresUpdated = true;\n}\n\nconst offsetScratchCartesian = new Cartesian3();\nconst offsetCenterScratch = new Cartesian3();\nfunction updateBatchTableOffsets(primitive, frameState) {\n const hasOffset = defined(primitive._batchTableAttributeIndices.offset);\n if (\n !hasOffset ||\n primitive._batchTableOffsetsUpdated ||\n frameState.scene3DOnly\n ) {\n return;\n }\n\n const index2D = primitive._batchTableOffsetAttribute2DIndex;\n\n const projection = frameState.mapProjection;\n const ellipsoid = projection.ellipsoid;\n\n const batchTable = primitive._batchTable;\n const boundingSpheres = primitive._instanceBoundingSpheres;\n const length = boundingSpheres.length;\n\n for (let i = 0; i < length; ++i) {\n let boundingSphere = boundingSpheres[i];\n if (!defined(boundingSphere)) {\n continue;\n }\n const offset = batchTable.getBatchedAttribute(\n i,\n primitive._batchTableAttributeIndices.offset\n );\n if (Cartesian3.equals(offset, Cartesian3.ZERO)) {\n batchTable.setBatchedAttribute(i, index2D, Cartesian3.ZERO);\n continue;\n }\n\n const modelMatrix = primitive.modelMatrix;\n if (defined(modelMatrix)) {\n boundingSphere = BoundingSphere.transform(\n boundingSphere,\n modelMatrix,\n scratchBoundingSphere\n );\n }\n\n let center = boundingSphere.center;\n center = ellipsoid.scaleToGeodeticSurface(center, offsetCenterScratch);\n let cartographic = ellipsoid.cartesianToCartographic(\n center,\n scratchBoundingSphereCartographic\n );\n const center2D = projection.project(\n cartographic,\n scratchBoundingSphereCenter2D\n );\n\n const newPoint = Cartesian3.add(offset, center, offsetScratchCartesian);\n cartographic = ellipsoid.cartesianToCartographic(newPoint, cartographic);\n\n const newPointProjected = projection.project(\n cartographic,\n offsetScratchCartesian\n );\n\n const newVector = Cartesian3.subtract(\n newPointProjected,\n center2D,\n offsetScratchCartesian\n );\n\n const x = newVector.x;\n newVector.x = newVector.z;\n newVector.z = newVector.y;\n newVector.y = x;\n\n batchTable.setBatchedAttribute(i, index2D, newVector);\n }\n\n primitive._batchTableOffsetsUpdated = true;\n}\n\nfunction createVertexArray(primitive, frameState) {\n const attributeLocations = primitive._attributeLocations;\n const geometries = primitive._geometries;\n const scene3DOnly = frameState.scene3DOnly;\n const context = frameState.context;\n\n const va = [];\n const length = geometries.length;\n for (let i = 0; i < length; ++i) {\n const geometry = geometries[i];\n\n va.push(\n VertexArray.fromGeometry({\n context: context,\n geometry: geometry,\n attributeLocations: attributeLocations,\n bufferUsage: BufferUsage.STATIC_DRAW,\n interleave: primitive._interleave,\n })\n );\n\n if (defined(primitive._createBoundingVolumeFunction)) {\n primitive._createBoundingVolumeFunction(frameState, geometry);\n } else {\n primitive._boundingSpheres.push(\n BoundingSphere.clone(geometry.boundingSphere)\n );\n primitive._boundingSphereWC.push(new BoundingSphere());\n\n if (!scene3DOnly) {\n const center = geometry.boundingSphereCV.center;\n const x = center.x;\n const y = center.y;\n const z = center.z;\n center.x = z;\n center.y = x;\n center.z = y;\n\n primitive._boundingSphereCV.push(\n BoundingSphere.clone(geometry.boundingSphereCV)\n );\n primitive._boundingSphere2D.push(new BoundingSphere());\n primitive._boundingSphereMorph.push(new BoundingSphere());\n }\n }\n }\n\n primitive._va = va;\n primitive._primitiveType = geometries[0].primitiveType;\n\n if (primitive.releaseGeometryInstances) {\n primitive.geometryInstances = undefined;\n }\n\n primitive._geometries = undefined;\n setReady(primitive, frameState, PrimitiveState.COMPLETE, undefined);\n}\n\nfunction createRenderStates(primitive, context, appearance, twoPasses) {\n let renderState = appearance.getRenderState();\n let rs;\n\n if (twoPasses) {\n rs = clone(renderState, false);\n rs.cull = {\n enabled: true,\n face: CullFace.BACK,\n };\n primitive._frontFaceRS = RenderState.fromCache(rs);\n\n rs.cull.face = CullFace.FRONT;\n primitive._backFaceRS = RenderState.fromCache(rs);\n } else {\n primitive._frontFaceRS = RenderState.fromCache(renderState);\n primitive._backFaceRS = primitive._frontFaceRS;\n }\n\n rs = clone(renderState, false);\n if (defined(primitive._depthFailAppearance)) {\n rs.depthTest.enabled = false;\n }\n\n if (defined(primitive._depthFailAppearance)) {\n renderState = primitive._depthFailAppearance.getRenderState();\n rs = clone(renderState, false);\n rs.depthTest.func = DepthFunction.GREATER;\n if (twoPasses) {\n rs.cull = {\n enabled: true,\n face: CullFace.BACK,\n };\n primitive._frontFaceDepthFailRS = RenderState.fromCache(rs);\n\n rs.cull.face = CullFace.FRONT;\n primitive._backFaceDepthFailRS = RenderState.fromCache(rs);\n } else {\n primitive._frontFaceDepthFailRS = RenderState.fromCache(rs);\n primitive._backFaceDepthFailRS = primitive._frontFaceRS;\n }\n }\n}\n\nfunction createShaderProgram(primitive, frameState, appearance) {\n const context = frameState.context;\n\n const attributeLocations = primitive._attributeLocations;\n\n let vs = primitive._batchTable.getVertexShaderCallback()(\n appearance.vertexShaderSource\n );\n vs = Primitive._appendOffsetToShader(primitive, vs);\n vs = Primitive._appendShowToShader(primitive, vs);\n vs = Primitive._appendDistanceDisplayConditionToShader(\n primitive,\n vs,\n frameState.scene3DOnly\n );\n vs = appendPickToVertexShader(vs);\n vs = Primitive._updateColorAttribute(primitive, vs, false);\n vs = modifyForEncodedNormals(primitive, vs);\n vs = Primitive._modifyShaderPosition(primitive, vs, frameState.scene3DOnly);\n let fs = appearance.getFragmentShaderSource();\n fs = appendPickToFragmentShader(fs);\n\n primitive._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: primitive._sp,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n validateShaderMatching(primitive._sp, attributeLocations);\n\n if (defined(primitive._depthFailAppearance)) {\n vs = primitive._batchTable.getVertexShaderCallback()(\n primitive._depthFailAppearance.vertexShaderSource\n );\n vs = Primitive._appendShowToShader(primitive, vs);\n vs = Primitive._appendDistanceDisplayConditionToShader(\n primitive,\n vs,\n frameState.scene3DOnly\n );\n vs = appendPickToVertexShader(vs);\n vs = Primitive._updateColorAttribute(primitive, vs, true);\n vs = modifyForEncodedNormals(primitive, vs);\n vs = Primitive._modifyShaderPosition(primitive, vs, frameState.scene3DOnly);\n vs = depthClampVS(vs);\n\n fs = primitive._depthFailAppearance.getFragmentShaderSource();\n fs = appendPickToFragmentShader(fs);\n fs = depthClampFS(fs);\n\n primitive._spDepthFail = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: primitive._spDepthFail,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n validateShaderMatching(primitive._spDepthFail, attributeLocations);\n }\n}\n\nconst modifiedModelViewScratch = new Matrix4();\nconst rtcScratch = new Cartesian3();\n\nfunction getUniforms(primitive, appearance, material, frameState) {\n // Create uniform map by combining uniforms from the appearance and material if either have uniforms.\n const materialUniformMap = defined(material) ? material._uniforms : undefined;\n const appearanceUniformMap = {};\n const appearanceUniforms = appearance.uniforms;\n if (defined(appearanceUniforms)) {\n // Convert to uniform map of functions for the renderer\n for (const name in appearanceUniforms) {\n if (appearanceUniforms.hasOwnProperty(name)) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(materialUniformMap) && defined(materialUniformMap[name])) {\n // Later, we could rename uniforms behind-the-scenes if needed.\n throw new DeveloperError(\n `Appearance and material have a uniform with the same name: ${name}`\n );\n }\n //>>includeEnd('debug');\n\n appearanceUniformMap[name] = getUniformFunction(\n appearanceUniforms,\n name\n );\n }\n }\n }\n let uniforms = combine(appearanceUniformMap, materialUniformMap);\n uniforms = primitive._batchTable.getUniformMapCallback()(uniforms);\n\n if (defined(primitive.rtcCenter)) {\n uniforms.u_modifiedModelView = function () {\n const viewMatrix = frameState.context.uniformState.view;\n Matrix4.multiply(\n viewMatrix,\n primitive._modelMatrix,\n modifiedModelViewScratch\n );\n Matrix4.multiplyByPoint(\n modifiedModelViewScratch,\n primitive.rtcCenter,\n rtcScratch\n );\n Matrix4.setTranslation(\n modifiedModelViewScratch,\n rtcScratch,\n modifiedModelViewScratch\n );\n return modifiedModelViewScratch;\n };\n }\n\n return uniforms;\n}\n\nfunction createCommands(\n primitive,\n appearance,\n material,\n translucent,\n twoPasses,\n colorCommands,\n pickCommands,\n frameState\n) {\n const uniforms = getUniforms(primitive, appearance, material, frameState);\n\n let depthFailUniforms;\n if (defined(primitive._depthFailAppearance)) {\n depthFailUniforms = getUniforms(\n primitive,\n primitive._depthFailAppearance,\n primitive._depthFailAppearance.material,\n frameState\n );\n }\n\n const pass = translucent ? Pass.TRANSLUCENT : Pass.OPAQUE;\n\n let multiplier = twoPasses ? 2 : 1;\n multiplier *= defined(primitive._depthFailAppearance) ? 2 : 1;\n colorCommands.length = primitive._va.length * multiplier;\n\n const length = colorCommands.length;\n let vaIndex = 0;\n for (let i = 0; i < length; ++i) {\n let colorCommand;\n\n if (twoPasses) {\n colorCommand = colorCommands[i];\n if (!defined(colorCommand)) {\n colorCommand = colorCommands[i] = new DrawCommand({\n owner: primitive,\n primitiveType: primitive._primitiveType,\n });\n }\n colorCommand.vertexArray = primitive._va[vaIndex];\n colorCommand.renderState = primitive._backFaceRS;\n colorCommand.shaderProgram = primitive._sp;\n colorCommand.uniformMap = uniforms;\n colorCommand.pass = pass;\n\n ++i;\n }\n\n colorCommand = colorCommands[i];\n if (!defined(colorCommand)) {\n colorCommand = colorCommands[i] = new DrawCommand({\n owner: primitive,\n primitiveType: primitive._primitiveType,\n });\n }\n colorCommand.vertexArray = primitive._va[vaIndex];\n colorCommand.renderState = primitive._frontFaceRS;\n colorCommand.shaderProgram = primitive._sp;\n colorCommand.uniformMap = uniforms;\n colorCommand.pass = pass;\n\n if (defined(primitive._depthFailAppearance)) {\n if (twoPasses) {\n ++i;\n\n colorCommand = colorCommands[i];\n if (!defined(colorCommand)) {\n colorCommand = colorCommands[i] = new DrawCommand({\n owner: primitive,\n primitiveType: primitive._primitiveType,\n });\n }\n colorCommand.vertexArray = primitive._va[vaIndex];\n colorCommand.renderState = primitive._backFaceDepthFailRS;\n colorCommand.shaderProgram = primitive._spDepthFail;\n colorCommand.uniformMap = depthFailUniforms;\n colorCommand.pass = pass;\n }\n\n ++i;\n\n colorCommand = colorCommands[i];\n if (!defined(colorCommand)) {\n colorCommand = colorCommands[i] = new DrawCommand({\n owner: primitive,\n primitiveType: primitive._primitiveType,\n });\n }\n colorCommand.vertexArray = primitive._va[vaIndex];\n colorCommand.renderState = primitive._frontFaceDepthFailRS;\n colorCommand.shaderProgram = primitive._spDepthFail;\n colorCommand.uniformMap = depthFailUniforms;\n colorCommand.pass = pass;\n }\n\n ++vaIndex;\n }\n}\n\nPrimitive._updateBoundingVolumes = function (\n primitive,\n frameState,\n modelMatrix,\n forceUpdate\n) {\n let i;\n let length;\n let boundingSphere;\n\n if (forceUpdate || !Matrix4.equals(modelMatrix, primitive._modelMatrix)) {\n Matrix4.clone(modelMatrix, primitive._modelMatrix);\n length = primitive._boundingSpheres.length;\n for (i = 0; i < length; ++i) {\n boundingSphere = primitive._boundingSpheres[i];\n if (defined(boundingSphere)) {\n primitive._boundingSphereWC[i] = BoundingSphere.transform(\n boundingSphere,\n modelMatrix,\n primitive._boundingSphereWC[i]\n );\n if (!frameState.scene3DOnly) {\n primitive._boundingSphere2D[i] = BoundingSphere.clone(\n primitive._boundingSphereCV[i],\n primitive._boundingSphere2D[i]\n );\n primitive._boundingSphere2D[i].center.x = 0.0;\n primitive._boundingSphereMorph[i] = BoundingSphere.union(\n primitive._boundingSphereWC[i],\n primitive._boundingSphereCV[i]\n );\n }\n }\n }\n }\n\n // Update bounding volumes for primitives that are sized in pixels.\n // The pixel size in meters varies based on the distance from the camera.\n const pixelSize = primitive.appearance.pixelSize;\n if (defined(pixelSize)) {\n length = primitive._boundingSpheres.length;\n for (i = 0; i < length; ++i) {\n boundingSphere = primitive._boundingSpheres[i];\n const boundingSphereWC = primitive._boundingSphereWC[i];\n const pixelSizeInMeters = frameState.camera.getPixelSize(\n boundingSphere,\n frameState.context.drawingBufferWidth,\n frameState.context.drawingBufferHeight\n );\n const sizeInMeters = pixelSizeInMeters * pixelSize;\n boundingSphereWC.radius = boundingSphere.radius + sizeInMeters;\n }\n }\n};\n\nfunction updateAndQueueCommands(\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n) {\n //>>includeStart('debug', pragmas.debug);\n if (\n frameState.mode !== SceneMode.SCENE3D &&\n !Matrix4.equals(modelMatrix, Matrix4.IDENTITY)\n ) {\n throw new DeveloperError(\n \"Primitive.modelMatrix is only supported in 3D mode.\"\n );\n }\n //>>includeEnd('debug');\n\n Primitive._updateBoundingVolumes(primitive, frameState, modelMatrix);\n\n let boundingSpheres;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingSpheres = primitive._boundingSphereWC;\n } else if (frameState.mode === SceneMode.COLUMBUS_VIEW) {\n boundingSpheres = primitive._boundingSphereCV;\n } else if (\n frameState.mode === SceneMode.SCENE2D &&\n defined(primitive._boundingSphere2D)\n ) {\n boundingSpheres = primitive._boundingSphere2D;\n } else if (defined(primitive._boundingSphereMorph)) {\n boundingSpheres = primitive._boundingSphereMorph;\n }\n\n const commandList = frameState.commandList;\n const passes = frameState.passes;\n if (passes.render || passes.pick) {\n const allowPicking = primitive.allowPicking;\n const castShadows = ShadowMode.castShadows(primitive.shadows);\n const receiveShadows = ShadowMode.receiveShadows(primitive.shadows);\n const colorLength = colorCommands.length;\n\n let factor = twoPasses ? 2 : 1;\n factor *= defined(primitive._depthFailAppearance) ? 2 : 1;\n\n for (let j = 0; j < colorLength; ++j) {\n const sphereIndex = Math.floor(j / factor);\n const colorCommand = colorCommands[j];\n colorCommand.modelMatrix = modelMatrix;\n colorCommand.boundingVolume = boundingSpheres[sphereIndex];\n colorCommand.cull = cull;\n colorCommand.debugShowBoundingVolume = debugShowBoundingVolume;\n colorCommand.castShadows = castShadows;\n colorCommand.receiveShadows = receiveShadows;\n\n if (allowPicking) {\n colorCommand.pickId = \"v_pickColor\";\n } else {\n colorCommand.pickId = undefined;\n }\n\n commandList.push(colorCommand);\n }\n }\n}\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {DeveloperError} All instance geometries must have the same primitiveType.\n * @exception {DeveloperError} Appearance and material have a uniform with the same name.\n * @exception {DeveloperError} Primitive.modelMatrix is only supported in 3D mode.\n * @exception {RuntimeError} Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.\n */\nPrimitive.prototype.update = function (frameState) {\n if (\n (!defined(this.geometryInstances) && this._va.length === 0) ||\n (defined(this.geometryInstances) &&\n Array.isArray(this.geometryInstances) &&\n this.geometryInstances.length === 0) ||\n !defined(this.appearance) ||\n (frameState.mode !== SceneMode.SCENE3D && frameState.scene3DOnly) ||\n (!frameState.passes.render && !frameState.passes.pick)\n ) {\n return;\n }\n\n if (defined(this._error)) {\n throw this._error;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(this.rtcCenter) && !frameState.scene3DOnly) {\n throw new DeveloperError(\n \"RTC rendering is only available for 3D only scenes.\"\n );\n }\n //>>includeEnd('debug');\n\n if (this._state === PrimitiveState.FAILED) {\n return;\n }\n\n const context = frameState.context;\n if (!defined(this._batchTable)) {\n createBatchTable(this, context);\n }\n if (this._batchTable.attributes.length > 0) {\n if (ContextLimits.maximumVertexTextureImageUnits === 0) {\n throw new RuntimeError(\n \"Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.\"\n );\n }\n this._batchTable.update(frameState);\n }\n\n if (\n this._state !== PrimitiveState.COMPLETE &&\n this._state !== PrimitiveState.COMBINED\n ) {\n if (this.asynchronous) {\n loadAsynchronous(this, frameState);\n } else {\n loadSynchronous(this, frameState);\n }\n }\n\n if (this._state === PrimitiveState.COMBINED) {\n updateBatchTableBoundingSpheres(this, frameState);\n updateBatchTableOffsets(this, frameState);\n createVertexArray(this, frameState);\n }\n\n if (!this.show || this._state !== PrimitiveState.COMPLETE) {\n return;\n }\n\n if (!this._batchTableOffsetsUpdated) {\n updateBatchTableOffsets(this, frameState);\n }\n if (this._recomputeBoundingSpheres) {\n recomputeBoundingSpheres(this, frameState);\n }\n\n // Create or recreate render state and shader program if appearance/material changed\n const appearance = this.appearance;\n const material = appearance.material;\n let createRS = false;\n let createSP = false;\n\n if (this._appearance !== appearance) {\n this._appearance = appearance;\n this._material = material;\n createRS = true;\n createSP = true;\n } else if (this._material !== material) {\n this._material = material;\n createSP = true;\n }\n\n const depthFailAppearance = this.depthFailAppearance;\n const depthFailMaterial = defined(depthFailAppearance)\n ? depthFailAppearance.material\n : undefined;\n\n if (this._depthFailAppearance !== depthFailAppearance) {\n this._depthFailAppearance = depthFailAppearance;\n this._depthFailMaterial = depthFailMaterial;\n createRS = true;\n createSP = true;\n } else if (this._depthFailMaterial !== depthFailMaterial) {\n this._depthFailMaterial = depthFailMaterial;\n createSP = true;\n }\n\n const translucent = this._appearance.isTranslucent();\n if (this._translucent !== translucent) {\n this._translucent = translucent;\n createRS = true;\n }\n\n if (defined(this._material)) {\n this._material.update(context);\n }\n\n const twoPasses = appearance.closed && translucent;\n\n if (createRS) {\n const rsFunc = defaultValue(\n this._createRenderStatesFunction,\n createRenderStates\n );\n rsFunc(this, context, appearance, twoPasses);\n }\n\n if (createSP) {\n const spFunc = defaultValue(\n this._createShaderProgramFunction,\n createShaderProgram\n );\n spFunc(this, frameState, appearance);\n }\n\n if (createRS || createSP) {\n const commandFunc = defaultValue(\n this._createCommandsFunction,\n createCommands\n );\n commandFunc(\n this,\n appearance,\n material,\n translucent,\n twoPasses,\n this._colorCommands,\n this._pickCommands,\n frameState\n );\n }\n\n const updateAndQueueCommandsFunc = defaultValue(\n this._updateAndQueueCommandsFunction,\n updateAndQueueCommands\n );\n updateAndQueueCommandsFunc(\n this,\n frameState,\n this._colorCommands,\n this._pickCommands,\n this.modelMatrix,\n this.cull,\n this.debugShowBoundingVolume,\n twoPasses\n );\n};\n\nconst offsetBoundingSphereScratch1 = new BoundingSphere();\nconst offsetBoundingSphereScratch2 = new BoundingSphere();\nfunction transformBoundingSphere(boundingSphere, offset, offsetAttribute) {\n if (offsetAttribute === GeometryOffsetAttribute.TOP) {\n const origBS = BoundingSphere.clone(\n boundingSphere,\n offsetBoundingSphereScratch1\n );\n const offsetBS = BoundingSphere.clone(\n boundingSphere,\n offsetBoundingSphereScratch2\n );\n offsetBS.center = Cartesian3.add(offsetBS.center, offset, offsetBS.center);\n boundingSphere = BoundingSphere.union(origBS, offsetBS, boundingSphere);\n } else if (offsetAttribute === GeometryOffsetAttribute.ALL) {\n boundingSphere.center = Cartesian3.add(\n boundingSphere.center,\n offset,\n boundingSphere.center\n );\n }\n\n return boundingSphere;\n}\n\nfunction createGetFunction(batchTable, instanceIndex, attributeIndex) {\n return function () {\n const attributeValue = batchTable.getBatchedAttribute(\n instanceIndex,\n attributeIndex\n );\n const attribute = batchTable.attributes[attributeIndex];\n const componentsPerAttribute = attribute.componentsPerAttribute;\n const value = ComponentDatatype.createTypedArray(\n attribute.componentDatatype,\n componentsPerAttribute\n );\n if (defined(attributeValue.constructor.pack)) {\n attributeValue.constructor.pack(attributeValue, value, 0);\n } else {\n value[0] = attributeValue;\n }\n return value;\n };\n}\n\nfunction createSetFunction(\n batchTable,\n instanceIndex,\n attributeIndex,\n primitive,\n name\n) {\n return function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(value) ||\n !defined(value.length) ||\n value.length < 1 ||\n value.length > 4\n ) {\n throw new DeveloperError(\n \"value must be and array with length between 1 and 4.\"\n );\n }\n //>>includeEnd('debug');\n const attributeValue = getAttributeValue(value);\n batchTable.setBatchedAttribute(\n instanceIndex,\n attributeIndex,\n attributeValue\n );\n if (name === \"offset\") {\n primitive._recomputeBoundingSpheres = true;\n primitive._batchTableOffsetsUpdated = false;\n }\n };\n}\n\nconst offsetScratch = new Cartesian3();\n\nfunction createBoundingSphereProperties(primitive, properties, index) {\n properties.boundingSphere = {\n get: function () {\n let boundingSphere = primitive._instanceBoundingSpheres[index];\n if (defined(boundingSphere)) {\n boundingSphere = boundingSphere.clone();\n const modelMatrix = primitive.modelMatrix;\n const offset = properties.offset;\n if (defined(offset)) {\n transformBoundingSphere(\n boundingSphere,\n Cartesian3.fromArray(offset.get(), 0, offsetScratch),\n primitive._offsetInstanceExtend[index]\n );\n }\n if (defined(modelMatrix)) {\n boundingSphere = BoundingSphere.transform(\n boundingSphere,\n modelMatrix\n );\n }\n }\n\n return boundingSphere;\n },\n };\n properties.boundingSphereCV = {\n get: function () {\n return primitive._instanceBoundingSpheresCV[index];\n },\n };\n}\n\nfunction createPickIdProperty(primitive, properties, index) {\n properties.pickId = {\n get: function () {\n return primitive._pickIds[index];\n },\n };\n}\n\n/**\n * Returns the modifiable per-instance attributes for a {@link GeometryInstance}.\n *\n * @param {*} id The id of the {@link GeometryInstance}.\n * @returns {object} The typed array in the attribute's format or undefined if the is no instance with id.\n *\n * @exception {DeveloperError} must call update before calling getGeometryInstanceAttributes.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);\n * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);\n * attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0);\n * attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(Cartesian3.IDENTITY);\n */\nPrimitive.prototype.getGeometryInstanceAttributes = function (id) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required\");\n }\n if (!defined(this._batchTable)) {\n throw new DeveloperError(\n \"must call update before calling getGeometryInstanceAttributes\"\n );\n }\n //>>includeEnd('debug');\n\n let attributes = this._perInstanceAttributeCache.get(id);\n if (defined(attributes)) {\n return attributes;\n }\n\n let index = -1;\n const lastIndex = this._lastPerInstanceAttributeIndex;\n const ids = this._instanceIds;\n const length = ids.length;\n for (let i = 0; i < length; ++i) {\n const curIndex = (lastIndex + i) % length;\n if (id === ids[curIndex]) {\n index = curIndex;\n break;\n }\n }\n\n if (index === -1) {\n return undefined;\n }\n\n const batchTable = this._batchTable;\n const perInstanceAttributeIndices = this._batchTableAttributeIndices;\n attributes = {};\n const properties = {};\n\n for (const name in perInstanceAttributeIndices) {\n if (perInstanceAttributeIndices.hasOwnProperty(name)) {\n const attributeIndex = perInstanceAttributeIndices[name];\n properties[name] = {\n get: createGetFunction(batchTable, index, attributeIndex),\n set: createSetFunction(batchTable, index, attributeIndex, this, name),\n };\n }\n }\n\n createBoundingSphereProperties(this, properties, index);\n createPickIdProperty(this, properties, index);\n Object.defineProperties(attributes, properties);\n\n this._lastPerInstanceAttributeIndex = index;\n this._perInstanceAttributeCache.set(id, attributes);\n return attributes;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see Primitive#destroy\n */\nPrimitive.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * e = e && e.destroy();\n *\n * @see Primitive#isDestroyed\n */\nPrimitive.prototype.destroy = function () {\n let length;\n let i;\n\n this._sp = this._sp && this._sp.destroy();\n this._spDepthFail = this._spDepthFail && this._spDepthFail.destroy();\n\n const va = this._va;\n length = va.length;\n for (i = 0; i < length; ++i) {\n va[i].destroy();\n }\n this._va = undefined;\n\n const pickIds = this._pickIds;\n length = pickIds.length;\n for (i = 0; i < length; ++i) {\n pickIds[i].destroy();\n }\n this._pickIds = undefined;\n\n this._batchTable = this._batchTable && this._batchTable.destroy();\n\n //These objects may be fairly large and reference other large objects (like Entities)\n //We explicitly set them to undefined here so that the memory can be freed\n //even if a reference to the destroyed Primitive has been kept around.\n this._instanceIds = undefined;\n this._perInstanceAttributeCache = undefined;\n this._attributeLocations = undefined;\n\n return destroyObject(this);\n};\n\nfunction setReady(primitive, frameState, state, error) {\n primitive._error = error;\n primitive._state = state;\n frameState.afterRender.push(function () {\n primitive._ready =\n primitive._state === PrimitiveState.COMPLETE ||\n primitive._state === PrimitiveState.FAILED;\n if (!defined(error)) {\n return true;\n }\n });\n}\nexport default Primitive;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Values and type information for per-instance geometry attributes.\n *\n * @alias GeometryInstanceAttribute\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {ComponentDatatype} options.componentDatatype The datatype of each component in the attribute, e.g., individual elements in values.\n * @param {number} options.componentsPerAttribute A number between 1 and 4 that defines the number of components in an attributes.\n * @param {boolean} [options.normalize=false] When true and componentDatatype is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n * @param {number[]} options.value The value for the attribute.\n *\n * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.\n *\n *\n * @example\n * const instance = new Cesium.GeometryInstance({\n * geometry : Cesium.BoxGeometry.fromDimensions({\n * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)\n * }),\n * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(\n * Cesium.Cartesian3.fromDegrees(0.0, 0.0)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),\n * id : 'box',\n * attributes : {\n * color : new Cesium.GeometryInstanceAttribute({\n * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,\n * componentsPerAttribute : 4,\n * normalize : true,\n * value : [255, 255, 0, 255]\n * })\n * }\n * });\n *\n * @see ColorGeometryInstanceAttribute\n * @see ShowGeometryInstanceAttribute\n * @see DistanceDisplayConditionGeometryInstanceAttribute\n */\nfunction GeometryInstanceAttribute(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.componentDatatype)) {\n throw new DeveloperError(\"options.componentDatatype is required.\");\n }\n if (!defined(options.componentsPerAttribute)) {\n throw new DeveloperError(\"options.componentsPerAttribute is required.\");\n }\n if (\n options.componentsPerAttribute < 1 ||\n options.componentsPerAttribute > 4\n ) {\n throw new DeveloperError(\n \"options.componentsPerAttribute must be between 1 and 4.\"\n );\n }\n if (!defined(options.value)) {\n throw new DeveloperError(\"options.value is required.\");\n }\n //>>includeEnd('debug');\n\n /**\n * The datatype of each component in the attribute, e.g., individual elements in\n * {@link GeometryInstanceAttribute#value}.\n *\n * @type ComponentDatatype\n *\n * @default undefined\n */\n this.componentDatatype = options.componentDatatype;\n\n /**\n * A number between 1 and 4 that defines the number of components in an attributes.\n * For example, a position attribute with x, y, and z components would have 3 as\n * shown in the code example.\n *\n * @type {number}\n *\n * @default undefined\n *\n * @example\n * show : new Cesium.GeometryInstanceAttribute({\n * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,\n * componentsPerAttribute : 1,\n * normalize : true,\n * value : [1.0]\n * })\n */\n this.componentsPerAttribute = options.componentsPerAttribute;\n\n /**\n * When true and componentDatatype is an integer format,\n * indicate that the components should be mapped to the range [0, 1] (unsigned)\n * or [-1, 1] (signed) when they are accessed as floating-point for rendering.\n *

\n * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.\n *

\n *\n * @type {boolean}\n *\n * @default false\n *\n * @example\n * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;\n * attribute.componentsPerAttribute = 4;\n * attribute.normalize = true;\n * attribute.value = [\n * Cesium.Color.floatToByte(color.red),\n * Cesium.Color.floatToByte(color.green),\n * Cesium.Color.floatToByte(color.blue),\n * Cesium.Color.floatToByte(color.alpha)\n * ];\n */\n this.normalize = defaultValue(options.normalize, false);\n\n /**\n * The values for the attributes stored in a typed array. In the code example,\n * every three elements in values defines one attributes since\n * componentsPerAttribute is 3.\n *\n * @type {number[]}\n *\n * @default undefined\n *\n * @example\n * show : new Cesium.GeometryInstanceAttribute({\n * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,\n * componentsPerAttribute : 1,\n * normalize : true,\n * value : [1.0]\n * })\n */\n this.value = options.value;\n}\nexport default GeometryInstanceAttribute;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef TEXTURE_COORDINATES\\n\\\n#ifdef SPHERICAL\\n\\\nin vec4 v_sphericalExtents;\\n\\\n#else // SPHERICAL\\n\\\nin vec2 v_inversePlaneExtents;\\n\\\nin vec4 v_westPlane;\\n\\\nin vec4 v_southPlane;\\n\\\n#endif // SPHERICAL\\n\\\nin vec3 v_uvMinAndSphericalLongitudeRotation;\\n\\\nin vec3 v_uMaxAndInverseDistance;\\n\\\nin vec3 v_vMaxAndInverseDistance;\\n\\\n#endif // TEXTURE_COORDINATES\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nin vec4 v_color;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef NORMAL_EC\\n\\\nvec3 getEyeCoordinate3FromWindowCoordinate(vec2 fragCoord, float logDepthOrDepth) {\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(fragCoord, logDepthOrDepth);\\n\\\n return eyeCoordinate.xyz / eyeCoordinate.w;\\n\\\n}\\n\\\n\\n\\\nvec3 vectorFromOffset(vec4 eyeCoordinate, vec2 positiveOffset) {\\n\\\n vec2 glFragCoordXY = gl_FragCoord.xy;\\n\\\n // Sample depths at both offset and negative offset\\n\\\n float upOrRightLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY + positiveOffset) / czm_viewport.zw));\\n\\\n float downOrLeftLogDepth = czm_unpackDepth(texture(czm_globeDepthTexture, (glFragCoordXY - positiveOffset) / czm_viewport.zw));\\n\\\n // Explicitly evaluate both paths\\n\\\n // Necessary for multifrustum and for edges of the screen\\n\\\n bvec2 upOrRightInBounds = lessThan(glFragCoordXY + positiveOffset, czm_viewport.zw);\\n\\\n float useUpOrRight = float(upOrRightLogDepth > 0.0 && upOrRightInBounds.x && upOrRightInBounds.y);\\n\\\n float useDownOrLeft = float(useUpOrRight == 0.0);\\n\\\n vec3 upOrRightEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY + positiveOffset, upOrRightLogDepth);\\n\\\n vec3 downOrLeftEC = getEyeCoordinate3FromWindowCoordinate(glFragCoordXY - positiveOffset, downOrLeftLogDepth);\\n\\\n return (upOrRightEC - (eyeCoordinate.xyz / eyeCoordinate.w)) * useUpOrRight + ((eyeCoordinate.xyz / eyeCoordinate.w) - downOrLeftEC) * useDownOrLeft;\\n\\\n}\\n\\\n#endif // NORMAL_EC\\n\\\n\\n\\\nvoid main(void)\\n\\\n{\\n\\\n#ifdef REQUIRES_EC\\n\\\n float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw));\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\\n\\\n#endif\\n\\\n\\n\\\n#ifdef REQUIRES_WC\\n\\\n vec4 worldCoordinate4 = czm_inverseView * eyeCoordinate;\\n\\\n vec3 worldCoordinate = worldCoordinate4.xyz / worldCoordinate4.w;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef TEXTURE_COORDINATES\\n\\\n vec2 uv;\\n\\\n#ifdef SPHERICAL\\n\\\n // Treat world coords as a sphere normal for spherical coordinates\\n\\\n vec2 sphericalLatLong = czm_approximateSphericalCoordinates(worldCoordinate);\\n\\\n sphericalLatLong.y += v_uvMinAndSphericalLongitudeRotation.z;\\n\\\n sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);\\n\\\n uv.x = (sphericalLatLong.y - v_sphericalExtents.y) * v_sphericalExtents.w;\\n\\\n uv.y = (sphericalLatLong.x - v_sphericalExtents.x) * v_sphericalExtents.z;\\n\\\n#else // SPHERICAL\\n\\\n // Unpack planes and transform to eye space\\n\\\n uv.x = czm_planeDistance(v_westPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.x;\\n\\\n uv.y = czm_planeDistance(v_southPlane, eyeCoordinate.xyz / eyeCoordinate.w) * v_inversePlaneExtents.y;\\n\\\n#endif // SPHERICAL\\n\\\n#endif // TEXTURE_COORDINATES\\n\\\n\\n\\\n#ifdef PICK\\n\\\n#ifdef CULL_FRAGMENTS\\n\\\n // When classifying translucent geometry, logDepthOrDepth == 0.0\\n\\\n // indicates a region that should not be classified, possibly due to there\\n\\\n // being opaque pixels there in another buffer.\\n\\\n // Check for logDepthOrDepth != 0.0 to make sure this should be classified.\\n\\\n if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0 || logDepthOrDepth != 0.0) {\\n\\\n out_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource\\n\\\n czm_writeDepthClamp();\\n\\\n }\\n\\\n#else // CULL_FRAGMENTS\\n\\\n out_FragColor.a = 1.0;\\n\\\n#endif // CULL_FRAGMENTS\\n\\\n#else // PICK\\n\\\n\\n\\\n#ifdef CULL_FRAGMENTS\\n\\\n // When classifying translucent geometry, logDepthOrDepth == 0.0\\n\\\n // indicates a region that should not be classified, possibly due to there\\n\\\n // being opaque pixels there in another buffer.\\n\\\n if (uv.x <= 0.0 || 1.0 <= uv.x || uv.y <= 0.0 || 1.0 <= uv.y || logDepthOrDepth == 0.0) {\\n\\\n discard;\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef NORMAL_EC\\n\\\n // Compute normal by sampling adjacent pixels in 2x2 block in screen space\\n\\\n vec3 downUp = vectorFromOffset(eyeCoordinate, vec2(0.0, 1.0));\\n\\\n vec3 leftRight = vectorFromOffset(eyeCoordinate, vec2(1.0, 0.0));\\n\\\n vec3 normalEC = normalize(cross(leftRight, downUp));\\n\\\n#endif\\n\\\n\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n\\n\\\n vec4 color = czm_gammaCorrect(v_color);\\n\\\n#ifdef FLAT\\n\\\n out_FragColor = color;\\n\\\n#else // FLAT\\n\\\n czm_materialInput materialInput;\\n\\\n materialInput.normalEC = normalEC;\\n\\\n materialInput.positionToEyeEC = -eyeCoordinate.xyz;\\n\\\n czm_material material = czm_getDefaultMaterial(materialInput);\\n\\\n material.diffuse = color.rgb;\\n\\\n material.alpha = color.a;\\n\\\n\\n\\\n out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC);\\n\\\n#endif // FLAT\\n\\\n\\n\\\n // Premultiply alpha. Required for classification primitives on translucent globe.\\n\\\n out_FragColor.rgb *= out_FragColor.a;\\n\\\n\\n\\\n#else // PER_INSTANCE_COLOR\\n\\\n\\n\\\n // Material support.\\n\\\n // USES_ is distinct from REQUIRES_, because some things are dependencies of each other or\\n\\\n // dependencies for culling but might not actually be used by the material.\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n\\n\\\n#ifdef USES_NORMAL_EC\\n\\\n materialInput.normalEC = normalEC;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef USES_POSITION_TO_EYE_EC\\n\\\n materialInput.positionToEyeEC = -eyeCoordinate.xyz;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef USES_TANGENT_TO_EYE\\n\\\n materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(worldCoordinate, normalEC);\\n\\\n#endif\\n\\\n\\n\\\n#ifdef USES_ST\\n\\\n // Remap texture coordinates from computed (approximately aligned with cartographic space) to the desired\\n\\\n // texture coordinate system, which typically forms a tight oriented bounding box around the geometry.\\n\\\n // Shader is provided a set of reference points for remapping.\\n\\\n materialInput.st.x = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_uMaxAndInverseDistance.xy, uv) * v_uMaxAndInverseDistance.z;\\n\\\n materialInput.st.y = czm_lineDistance(v_uvMinAndSphericalLongitudeRotation.xy, v_vMaxAndInverseDistance.xy, uv) * v_vMaxAndInverseDistance.z;\\n\\\n#endif\\n\\\n\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n\\n\\\n#ifdef FLAT\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#else // FLAT\\n\\\n out_FragColor = czm_phong(normalize(-eyeCoordinate.xyz), material, czm_lightDirectionEC);\\n\\\n#endif // FLAT\\n\\\n\\n\\\n // Premultiply alpha. Required for classification primitives on translucent globe.\\n\\\n out_FragColor.rgb *= out_FragColor.a;\\n\\\n\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n czm_writeDepthClamp();\\n\\\n#endif // PICK\\n\\\n}\\n\\\n\";\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport GeometryInstanceAttribute from \"../Core/GeometryInstanceAttribute.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ShadowVolumeAppearanceFS from \"../Shaders/ShadowVolumeAppearanceFS.js\";\n\n/**\n * Creates shaders for a ClassificationPrimitive to use a given Appearance, as well as for picking.\n *\n * @param {boolean} extentsCulling Discard fragments outside the instance's texture coordinate extents.\n * @param {boolean} planarExtents If true, texture coordinates will be computed using planes instead of spherical coordinates.\n * @param {Appearance} appearance An Appearance to be used with a ClassificationPrimitive via GroundPrimitive.\n * @private\n */\nfunction ShadowVolumeAppearance(extentsCulling, planarExtents, appearance) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"extentsCulling\", extentsCulling);\n Check.typeOf.bool(\"planarExtents\", planarExtents);\n Check.typeOf.object(\"appearance\", appearance);\n //>>includeEnd('debug');\n\n this._projectionExtentDefines = {\n eastMostYhighDefine: \"\",\n eastMostYlowDefine: \"\",\n westMostYhighDefine: \"\",\n westMostYlowDefine: \"\",\n };\n\n // Compute shader dependencies\n const colorShaderDependencies = new ShaderDependencies();\n colorShaderDependencies.requiresTextureCoordinates = extentsCulling;\n colorShaderDependencies.requiresEC = !appearance.flat;\n\n const pickShaderDependencies = new ShaderDependencies();\n pickShaderDependencies.requiresTextureCoordinates = extentsCulling;\n\n if (appearance instanceof PerInstanceColorAppearance) {\n // PerInstanceColorAppearance doesn't have material.shaderSource, instead it has its own vertex and fragment shaders\n colorShaderDependencies.requiresNormalEC = !appearance.flat;\n } else {\n // Scan material source for what hookups are needed. Assume czm_materialInput materialInput.\n const materialShaderSource = `${appearance.material.shaderSource}\\n${appearance.fragmentShaderSource}`;\n\n colorShaderDependencies.normalEC =\n materialShaderSource.indexOf(\"materialInput.normalEC\") !== -1 ||\n materialShaderSource.indexOf(\"czm_getDefaultMaterial\") !== -1;\n colorShaderDependencies.positionToEyeEC =\n materialShaderSource.indexOf(\"materialInput.positionToEyeEC\") !== -1;\n colorShaderDependencies.tangentToEyeMatrix =\n materialShaderSource.indexOf(\"materialInput.tangentToEyeMatrix\") !== -1;\n colorShaderDependencies.st =\n materialShaderSource.indexOf(\"materialInput.st\") !== -1;\n }\n\n this._colorShaderDependencies = colorShaderDependencies;\n this._pickShaderDependencies = pickShaderDependencies;\n this._appearance = appearance;\n this._extentsCulling = extentsCulling;\n this._planarExtents = planarExtents;\n}\n\n/**\n * Create the fragment shader for a ClassificationPrimitive's color pass when rendering for color.\n *\n * @param {boolean} columbusView2D Whether the shader will be used for Columbus View or 2D.\n * @returns {ShaderSource} Shader source for the fragment shader.\n */\nShadowVolumeAppearance.prototype.createFragmentShader = function (\n columbusView2D\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"columbusView2D\", columbusView2D);\n //>>includeEnd('debug');\n\n const appearance = this._appearance;\n const dependencies = this._colorShaderDependencies;\n\n const defines = [];\n if (!columbusView2D && !this._planarExtents) {\n defines.push(\"SPHERICAL\");\n }\n if (dependencies.requiresEC) {\n defines.push(\"REQUIRES_EC\");\n }\n if (dependencies.requiresWC) {\n defines.push(\"REQUIRES_WC\");\n }\n if (dependencies.requiresTextureCoordinates) {\n defines.push(\"TEXTURE_COORDINATES\");\n }\n if (this._extentsCulling) {\n defines.push(\"CULL_FRAGMENTS\");\n }\n if (dependencies.requiresNormalEC) {\n defines.push(\"NORMAL_EC\");\n }\n if (appearance instanceof PerInstanceColorAppearance) {\n defines.push(\"PER_INSTANCE_COLOR\");\n }\n\n // Material inputs. Use of parameters in the material is different\n // from requirement of the parameters in the overall shader, for example,\n // texture coordinates may be used for fragment culling but not for the material itself.\n if (dependencies.normalEC) {\n defines.push(\"USES_NORMAL_EC\");\n }\n if (dependencies.positionToEyeEC) {\n defines.push(\"USES_POSITION_TO_EYE_EC\");\n }\n if (dependencies.tangentToEyeMatrix) {\n defines.push(\"USES_TANGENT_TO_EYE\");\n }\n if (dependencies.st) {\n defines.push(\"USES_ST\");\n }\n\n if (appearance.flat) {\n defines.push(\"FLAT\");\n }\n\n let materialSource = \"\";\n if (!(appearance instanceof PerInstanceColorAppearance)) {\n materialSource = appearance.material.shaderSource;\n }\n\n return new ShaderSource({\n defines: defines,\n sources: [materialSource, ShadowVolumeAppearanceFS],\n });\n};\n\nShadowVolumeAppearance.prototype.createPickFragmentShader = function (\n columbusView2D\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"columbusView2D\", columbusView2D);\n //>>includeEnd('debug');\n\n const dependencies = this._pickShaderDependencies;\n\n const defines = [\"PICK\"];\n if (!columbusView2D && !this._planarExtents) {\n defines.push(\"SPHERICAL\");\n }\n if (dependencies.requiresEC) {\n defines.push(\"REQUIRES_EC\");\n }\n if (dependencies.requiresWC) {\n defines.push(\"REQUIRES_WC\");\n }\n if (dependencies.requiresTextureCoordinates) {\n defines.push(\"TEXTURE_COORDINATES\");\n }\n if (this._extentsCulling) {\n defines.push(\"CULL_FRAGMENTS\");\n }\n return new ShaderSource({\n defines: defines,\n sources: [ShadowVolumeAppearanceFS],\n pickColorQualifier: \"in\",\n });\n};\n\n/**\n * Create the vertex shader for a ClassificationPrimitive's color pass on the final of 3 shadow volume passes\n *\n * @param {string[]} defines External defines to pass to the vertex shader.\n * @param {string} vertexShaderSource ShadowVolumeAppearanceVS with any required modifications for computing position.\n * @param {boolean} columbusView2D Whether the shader will be used for Columbus View or 2D.\n * @param {MapProjection} mapProjection Current scene's map projection.\n * @returns {string} Shader source for the vertex shader.\n */\nShadowVolumeAppearance.prototype.createVertexShader = function (\n defines,\n vertexShaderSource,\n columbusView2D,\n mapProjection\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"defines\", defines);\n Check.typeOf.string(\"vertexShaderSource\", vertexShaderSource);\n Check.typeOf.bool(\"columbusView2D\", columbusView2D);\n Check.defined(\"mapProjection\", mapProjection);\n //>>includeEnd('debug');\n return createShadowVolumeAppearanceVS(\n this._colorShaderDependencies,\n this._planarExtents,\n columbusView2D,\n defines,\n vertexShaderSource,\n this._appearance,\n mapProjection,\n this._projectionExtentDefines\n );\n};\n\n/**\n * Create the vertex shader for a ClassificationPrimitive's pick pass on the final of 3 shadow volume passes\n *\n * @param {string[]} defines External defines to pass to the vertex shader.\n * @param {string} vertexShaderSource ShadowVolumeAppearanceVS with any required modifications for computing position and picking.\n * @param {boolean} columbusView2D Whether the shader will be used for Columbus View or 2D.\n * @param {MapProjection} mapProjection Current scene's map projection.\n * @returns {string} Shader source for the vertex shader.\n */\nShadowVolumeAppearance.prototype.createPickVertexShader = function (\n defines,\n vertexShaderSource,\n columbusView2D,\n mapProjection\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"defines\", defines);\n Check.typeOf.string(\"vertexShaderSource\", vertexShaderSource);\n Check.typeOf.bool(\"columbusView2D\", columbusView2D);\n Check.defined(\"mapProjection\", mapProjection);\n //>>includeEnd('debug');\n return createShadowVolumeAppearanceVS(\n this._pickShaderDependencies,\n this._planarExtents,\n columbusView2D,\n defines,\n vertexShaderSource,\n undefined,\n mapProjection,\n this._projectionExtentDefines\n );\n};\n\nconst longitudeExtentsCartesianScratch = new Cartesian3();\nconst longitudeExtentsCartographicScratch = new Cartographic();\nconst longitudeExtentsEncodeScratch = {\n high: 0.0,\n low: 0.0,\n};\nfunction createShadowVolumeAppearanceVS(\n shaderDependencies,\n planarExtents,\n columbusView2D,\n defines,\n vertexShaderSource,\n appearance,\n mapProjection,\n projectionExtentDefines\n) {\n const allDefines = defines.slice();\n\n if (projectionExtentDefines.eastMostYhighDefine === \"\") {\n const eastMostCartographic = longitudeExtentsCartographicScratch;\n eastMostCartographic.longitude = CesiumMath.PI;\n eastMostCartographic.latitude = 0.0;\n eastMostCartographic.height = 0.0;\n const eastMostCartesian = mapProjection.project(\n eastMostCartographic,\n longitudeExtentsCartesianScratch\n );\n let encoded = EncodedCartesian3.encode(\n eastMostCartesian.x,\n longitudeExtentsEncodeScratch\n );\n projectionExtentDefines.eastMostYhighDefine = `EAST_MOST_X_HIGH ${encoded.high.toFixed(\n `${encoded.high}`.length + 1\n )}`;\n projectionExtentDefines.eastMostYlowDefine = `EAST_MOST_X_LOW ${encoded.low.toFixed(\n `${encoded.low}`.length + 1\n )}`;\n\n const westMostCartographic = longitudeExtentsCartographicScratch;\n westMostCartographic.longitude = -CesiumMath.PI;\n westMostCartographic.latitude = 0.0;\n westMostCartographic.height = 0.0;\n const westMostCartesian = mapProjection.project(\n westMostCartographic,\n longitudeExtentsCartesianScratch\n );\n encoded = EncodedCartesian3.encode(\n westMostCartesian.x,\n longitudeExtentsEncodeScratch\n );\n projectionExtentDefines.westMostYhighDefine = `WEST_MOST_X_HIGH ${encoded.high.toFixed(\n `${encoded.high}`.length + 1\n )}`;\n projectionExtentDefines.westMostYlowDefine = `WEST_MOST_X_LOW ${encoded.low.toFixed(\n `${encoded.low}`.length + 1\n )}`;\n }\n\n if (columbusView2D) {\n allDefines.push(projectionExtentDefines.eastMostYhighDefine);\n allDefines.push(projectionExtentDefines.eastMostYlowDefine);\n allDefines.push(projectionExtentDefines.westMostYhighDefine);\n allDefines.push(projectionExtentDefines.westMostYlowDefine);\n }\n\n if (defined(appearance) && appearance instanceof PerInstanceColorAppearance) {\n allDefines.push(\"PER_INSTANCE_COLOR\");\n }\n if (shaderDependencies.requiresTextureCoordinates) {\n allDefines.push(\"TEXTURE_COORDINATES\");\n if (!(planarExtents || columbusView2D)) {\n allDefines.push(\"SPHERICAL\");\n }\n if (columbusView2D) {\n allDefines.push(\"COLUMBUS_VIEW_2D\");\n }\n }\n\n return new ShaderSource({\n defines: allDefines,\n sources: [vertexShaderSource],\n });\n}\n\n/**\n * Tracks shader dependencies.\n * @private\n */\nfunction ShaderDependencies() {\n this._requiresEC = false;\n this._requiresWC = false; // depends on eye coordinates, needed for material and for phong\n this._requiresNormalEC = false; // depends on eye coordinates, needed for material\n this._requiresTextureCoordinates = false; // depends on world coordinates, needed for material and for culling\n\n this._usesNormalEC = false;\n this._usesPositionToEyeEC = false;\n this._usesTangentToEyeMat = false;\n this._usesSt = false;\n}\n\nObject.defineProperties(ShaderDependencies.prototype, {\n // Set when assessing final shading (flat vs. phong) and culling using computed texture coordinates\n requiresEC: {\n get: function () {\n return this._requiresEC;\n },\n set: function (value) {\n this._requiresEC = value || this._requiresEC;\n },\n },\n requiresWC: {\n get: function () {\n return this._requiresWC;\n },\n set: function (value) {\n this._requiresWC = value || this._requiresWC;\n this.requiresEC = this._requiresWC;\n },\n },\n requiresNormalEC: {\n get: function () {\n return this._requiresNormalEC;\n },\n set: function (value) {\n this._requiresNormalEC = value || this._requiresNormalEC;\n this.requiresEC = this._requiresNormalEC;\n },\n },\n requiresTextureCoordinates: {\n get: function () {\n return this._requiresTextureCoordinates;\n },\n set: function (value) {\n this._requiresTextureCoordinates =\n value || this._requiresTextureCoordinates;\n this.requiresWC = this._requiresTextureCoordinates;\n },\n },\n // Get/Set when assessing material hookups\n normalEC: {\n set: function (value) {\n this.requiresNormalEC = value;\n this._usesNormalEC = value;\n },\n get: function () {\n return this._usesNormalEC;\n },\n },\n tangentToEyeMatrix: {\n set: function (value) {\n this.requiresWC = value;\n this.requiresNormalEC = value;\n this._usesTangentToEyeMat = value;\n },\n get: function () {\n return this._usesTangentToEyeMat;\n },\n },\n positionToEyeEC: {\n set: function (value) {\n this.requiresEC = value;\n this._usesPositionToEyeEC = value;\n },\n get: function () {\n return this._usesPositionToEyeEC;\n },\n },\n st: {\n set: function (value) {\n this.requiresTextureCoordinates = value;\n this._usesSt = value;\n },\n get: function () {\n return this._usesSt;\n },\n },\n});\n\nfunction pointLineDistance(point1, point2, point) {\n return (\n Math.abs(\n (point2.y - point1.y) * point.x -\n (point2.x - point1.x) * point.y +\n point2.x * point1.y -\n point2.y * point1.x\n ) / Cartesian2.distance(point2, point1)\n );\n}\n\nconst points2DScratch = [\n new Cartesian2(),\n new Cartesian2(),\n new Cartesian2(),\n new Cartesian2(),\n];\n\n// textureCoordinateRotationPoints form 2 lines in the computed UV space that remap to desired texture coordinates.\n// This allows simulation of baked texture coordinates for EllipseGeometry, RectangleGeometry, and PolygonGeometry.\nfunction addTextureCoordinateRotationAttributes(\n attributes,\n textureCoordinateRotationPoints\n) {\n const points2D = points2DScratch;\n\n const minXYCorner = Cartesian2.unpack(\n textureCoordinateRotationPoints,\n 0,\n points2D[0]\n );\n const maxYCorner = Cartesian2.unpack(\n textureCoordinateRotationPoints,\n 2,\n points2D[1]\n );\n const maxXCorner = Cartesian2.unpack(\n textureCoordinateRotationPoints,\n 4,\n points2D[2]\n );\n\n attributes.uMaxVmax = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n value: [maxYCorner.x, maxYCorner.y, maxXCorner.x, maxXCorner.y],\n });\n\n const inverseExtentX =\n 1.0 / pointLineDistance(minXYCorner, maxYCorner, maxXCorner);\n const inverseExtentY =\n 1.0 / pointLineDistance(minXYCorner, maxXCorner, maxYCorner);\n\n attributes.uvMinAndExtents = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n value: [minXYCorner.x, minXYCorner.y, inverseExtentX, inverseExtentY],\n });\n}\n\nconst cartographicScratch = new Cartographic();\nconst cornerScratch = new Cartesian3();\nconst northWestScratch = new Cartesian3();\nconst southEastScratch = new Cartesian3();\nconst highLowScratch = { high: 0.0, low: 0.0 };\nfunction add2DTextureCoordinateAttributes(rectangle, projection, attributes) {\n // Compute corner positions in double precision\n const carto = cartographicScratch;\n carto.height = 0.0;\n\n carto.longitude = rectangle.west;\n carto.latitude = rectangle.south;\n\n const southWestCorner = projection.project(carto, cornerScratch);\n\n carto.latitude = rectangle.north;\n const northWest = projection.project(carto, northWestScratch);\n\n carto.longitude = rectangle.east;\n carto.latitude = rectangle.south;\n const southEast = projection.project(carto, southEastScratch);\n\n // Since these positions are all in the 2D plane, there's a lot of zeros\n // and a lot of repetition. So we only need to encode 4 values.\n // Encode:\n // x: x value for southWestCorner\n // y: y value for southWestCorner\n // z: y value for northWest\n // w: x value for southEast\n\n const valuesHigh = [0, 0, 0, 0];\n const valuesLow = [0, 0, 0, 0];\n let encoded = EncodedCartesian3.encode(southWestCorner.x, highLowScratch);\n valuesHigh[0] = encoded.high;\n valuesLow[0] = encoded.low;\n\n encoded = EncodedCartesian3.encode(southWestCorner.y, highLowScratch);\n valuesHigh[1] = encoded.high;\n valuesLow[1] = encoded.low;\n\n encoded = EncodedCartesian3.encode(northWest.y, highLowScratch);\n valuesHigh[2] = encoded.high;\n valuesLow[2] = encoded.low;\n\n encoded = EncodedCartesian3.encode(southEast.x, highLowScratch);\n valuesHigh[3] = encoded.high;\n valuesLow[3] = encoded.low;\n\n attributes.planes2D_HIGH = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n value: valuesHigh,\n });\n\n attributes.planes2D_LOW = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n value: valuesLow,\n });\n}\n\nconst enuMatrixScratch = new Matrix4();\nconst inverseEnuScratch = new Matrix4();\nconst rectanglePointCartesianScratch = new Cartesian3();\nconst rectangleCenterScratch = new Cartographic();\nconst pointsCartographicScratch = [\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n new Cartographic(),\n];\n/**\n * When computing planes to bound the rectangle,\n * need to factor in \"bulge\" and other distortion.\n * Flatten the ellipsoid-centered corners and edge-centers of the rectangle\n * into the plane of the local ENU system, compute bounds in 2D, and\n * project back to ellipsoid-centered.\n *\n * @private\n */\nfunction computeRectangleBounds(\n rectangle,\n ellipsoid,\n height,\n southWestCornerResult,\n eastVectorResult,\n northVectorResult\n) {\n // Compute center of rectangle\n const centerCartographic = Rectangle.center(\n rectangle,\n rectangleCenterScratch\n );\n centerCartographic.height = height;\n const centerCartesian = Cartographic.toCartesian(\n centerCartographic,\n ellipsoid,\n rectanglePointCartesianScratch\n );\n const enuMatrix = Transforms.eastNorthUpToFixedFrame(\n centerCartesian,\n ellipsoid,\n enuMatrixScratch\n );\n const inverseEnu = Matrix4.inverse(enuMatrix, inverseEnuScratch);\n\n const west = rectangle.west;\n const east = rectangle.east;\n const north = rectangle.north;\n const south = rectangle.south;\n\n const cartographics = pointsCartographicScratch;\n cartographics[0].latitude = south;\n cartographics[0].longitude = west;\n cartographics[1].latitude = north;\n cartographics[1].longitude = west;\n cartographics[2].latitude = north;\n cartographics[2].longitude = east;\n cartographics[3].latitude = south;\n cartographics[3].longitude = east;\n\n const longitudeCenter = (west + east) * 0.5;\n const latitudeCenter = (north + south) * 0.5;\n\n cartographics[4].latitude = south;\n cartographics[4].longitude = longitudeCenter;\n cartographics[5].latitude = north;\n cartographics[5].longitude = longitudeCenter;\n cartographics[6].latitude = latitudeCenter;\n cartographics[6].longitude = west;\n cartographics[7].latitude = latitudeCenter;\n cartographics[7].longitude = east;\n\n let minX = Number.POSITIVE_INFINITY;\n let maxX = Number.NEGATIVE_INFINITY;\n let minY = Number.POSITIVE_INFINITY;\n let maxY = Number.NEGATIVE_INFINITY;\n for (let i = 0; i < 8; i++) {\n cartographics[i].height = height;\n const pointCartesian = Cartographic.toCartesian(\n cartographics[i],\n ellipsoid,\n rectanglePointCartesianScratch\n );\n Matrix4.multiplyByPoint(inverseEnu, pointCartesian, pointCartesian);\n pointCartesian.z = 0.0; // flatten into XY plane of ENU coordinate system\n minX = Math.min(minX, pointCartesian.x);\n maxX = Math.max(maxX, pointCartesian.x);\n minY = Math.min(minY, pointCartesian.y);\n maxY = Math.max(maxY, pointCartesian.y);\n }\n\n const southWestCorner = southWestCornerResult;\n southWestCorner.x = minX;\n southWestCorner.y = minY;\n southWestCorner.z = 0.0;\n Matrix4.multiplyByPoint(enuMatrix, southWestCorner, southWestCorner);\n\n const southEastCorner = eastVectorResult;\n southEastCorner.x = maxX;\n southEastCorner.y = minY;\n southEastCorner.z = 0.0;\n Matrix4.multiplyByPoint(enuMatrix, southEastCorner, southEastCorner);\n // make eastward vector\n Cartesian3.subtract(southEastCorner, southWestCorner, eastVectorResult);\n\n const northWestCorner = northVectorResult;\n northWestCorner.x = minX;\n northWestCorner.y = maxY;\n northWestCorner.z = 0.0;\n Matrix4.multiplyByPoint(enuMatrix, northWestCorner, northWestCorner);\n // make eastward vector\n Cartesian3.subtract(northWestCorner, southWestCorner, northVectorResult);\n}\n\nconst eastwardScratch = new Cartesian3();\nconst northwardScratch = new Cartesian3();\nconst encodeScratch = new EncodedCartesian3();\n/**\n * Gets an attributes object containing:\n * - 3 high-precision points as 6 GeometryInstanceAttributes. These points are used to compute eye-space planes.\n * - 1 texture coordinate rotation GeometryInstanceAttributes\n * - 2 GeometryInstanceAttributes used to compute high-precision points in 2D and Columbus View.\n * These points are used to compute eye-space planes like above.\n *\n * Used to compute texture coordinates for small-area ClassificationPrimitives with materials or multiple non-overlapping instances.\n *\n * @see ShadowVolumeAppearance\n * @private\n *\n * @param {Rectangle} boundingRectangle Rectangle object that the points will approximately bound\n * @param {number[]} textureCoordinateRotationPoints Points in the computed texture coordinate system for remapping texture coordinates\n * @param {Ellipsoid} ellipsoid Ellipsoid for converting Rectangle points to world coordinates\n * @param {MapProjection} projection The MapProjection used for 2D and Columbus View.\n * @param {number} [height=0] The maximum height for the shadow volume.\n * @returns {object} An attributes dictionary containing planar texture coordinate attributes.\n */\nShadowVolumeAppearance.getPlanarTextureCoordinateAttributes = function (\n boundingRectangle,\n textureCoordinateRotationPoints,\n ellipsoid,\n projection,\n height\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"boundingRectangle\", boundingRectangle);\n Check.defined(\n \"textureCoordinateRotationPoints\",\n textureCoordinateRotationPoints\n );\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n Check.typeOf.object(\"projection\", projection);\n //>>includeEnd('debug');\n\n const corner = cornerScratch;\n const eastward = eastwardScratch;\n const northward = northwardScratch;\n computeRectangleBounds(\n boundingRectangle,\n ellipsoid,\n defaultValue(height, 0.0),\n corner,\n eastward,\n northward\n );\n\n const attributes = {};\n addTextureCoordinateRotationAttributes(\n attributes,\n textureCoordinateRotationPoints\n );\n\n const encoded = EncodedCartesian3.fromCartesian(corner, encodeScratch);\n\n attributes.southWest_HIGH = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n normalize: false,\n value: Cartesian3.pack(encoded.high, [0, 0, 0]),\n });\n attributes.southWest_LOW = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n normalize: false,\n value: Cartesian3.pack(encoded.low, [0, 0, 0]),\n });\n attributes.eastward = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n normalize: false,\n value: Cartesian3.pack(eastward, [0, 0, 0]),\n });\n attributes.northward = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n normalize: false,\n value: Cartesian3.pack(northward, [0, 0, 0]),\n });\n\n add2DTextureCoordinateAttributes(boundingRectangle, projection, attributes);\n return attributes;\n};\n\nconst spherePointScratch = new Cartesian3();\nfunction latLongToSpherical(latitude, longitude, ellipsoid, result) {\n const cartographic = cartographicScratch;\n cartographic.latitude = latitude;\n cartographic.longitude = longitude;\n cartographic.height = 0.0;\n\n const spherePoint = Cartographic.toCartesian(\n cartographic,\n ellipsoid,\n spherePointScratch\n );\n\n // Project into plane with vertical for latitude\n const magXY = Math.sqrt(\n spherePoint.x * spherePoint.x + spherePoint.y * spherePoint.y\n );\n\n // Use fastApproximateAtan2 for alignment with shader\n const sphereLatitude = CesiumMath.fastApproximateAtan2(magXY, spherePoint.z);\n const sphereLongitude = CesiumMath.fastApproximateAtan2(\n spherePoint.x,\n spherePoint.y\n );\n\n result.x = sphereLatitude;\n result.y = sphereLongitude;\n\n return result;\n}\n\nconst sphericalScratch = new Cartesian2();\n/**\n * Gets an attributes object containing:\n * - the southwest corner of a rectangular area in spherical coordinates, as well as the inverse of the latitude/longitude range.\n * These are computed using the same atan2 approximation used in the shader.\n * - 1 texture coordinate rotation GeometryInstanceAttributes\n * - 2 GeometryInstanceAttributes used to compute high-precision points in 2D and Columbus View.\n * These points are used to compute eye-space planes like above.\n *\n * Used when computing texture coordinates for large-area ClassificationPrimitives with materials or\n * multiple non-overlapping instances.\n * @see ShadowVolumeAppearance\n * @private\n *\n * @param {Rectangle} boundingRectangle Rectangle object that the spherical extents will approximately bound\n * @param {number[]} textureCoordinateRotationPoints Points in the computed texture coordinate system for remapping texture coordinates\n * @param {Ellipsoid} ellipsoid Ellipsoid for converting Rectangle points to world coordinates\n * @param {MapProjection} projection The MapProjection used for 2D and Columbus View.\n * @returns {object} An attributes dictionary containing spherical texture coordinate attributes.\n */\nShadowVolumeAppearance.getSphericalExtentGeometryInstanceAttributes = function (\n boundingRectangle,\n textureCoordinateRotationPoints,\n ellipsoid,\n projection\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"boundingRectangle\", boundingRectangle);\n Check.defined(\n \"textureCoordinateRotationPoints\",\n textureCoordinateRotationPoints\n );\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n Check.typeOf.object(\"projection\", projection);\n //>>includeEnd('debug');\n\n // rectangle cartographic coords !== spherical because it's on an ellipsoid\n const southWestExtents = latLongToSpherical(\n boundingRectangle.south,\n boundingRectangle.west,\n ellipsoid,\n sphericalScratch\n );\n\n let south = southWestExtents.x;\n let west = southWestExtents.y;\n\n const northEastExtents = latLongToSpherical(\n boundingRectangle.north,\n boundingRectangle.east,\n ellipsoid,\n sphericalScratch\n );\n let north = northEastExtents.x;\n let east = northEastExtents.y;\n\n // If the bounding rectangle crosses the IDL, rotate the spherical extents so the cross no longer happens.\n // This rotation must happen in the shader too.\n let rotationRadians = 0.0;\n if (west > east) {\n rotationRadians = CesiumMath.PI - west;\n west = -CesiumMath.PI;\n east += rotationRadians;\n }\n\n // Slightly pad extents to avoid floating point error when fragment culling at edges.\n south -= CesiumMath.EPSILON5;\n west -= CesiumMath.EPSILON5;\n north += CesiumMath.EPSILON5;\n east += CesiumMath.EPSILON5;\n\n const longitudeRangeInverse = 1.0 / (east - west);\n const latitudeRangeInverse = 1.0 / (north - south);\n\n const attributes = {\n sphericalExtents: new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n value: [south, west, latitudeRangeInverse, longitudeRangeInverse],\n }),\n longitudeRotation: new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 1,\n normalize: false,\n value: [rotationRadians],\n }),\n };\n\n addTextureCoordinateRotationAttributes(\n attributes,\n textureCoordinateRotationPoints\n );\n add2DTextureCoordinateAttributes(boundingRectangle, projection, attributes);\n return attributes;\n};\n\nShadowVolumeAppearance.hasAttributesForTextureCoordinatePlanes = function (\n attributes\n) {\n return (\n defined(attributes.southWest_HIGH) &&\n defined(attributes.southWest_LOW) &&\n defined(attributes.northward) &&\n defined(attributes.eastward) &&\n defined(attributes.planes2D_HIGH) &&\n defined(attributes.planes2D_LOW) &&\n defined(attributes.uMaxVmax) &&\n defined(attributes.uvMinAndExtents)\n );\n};\n\nShadowVolumeAppearance.hasAttributesForSphericalExtents = function (\n attributes\n) {\n return (\n defined(attributes.sphericalExtents) &&\n defined(attributes.longitudeRotation) &&\n defined(attributes.planes2D_HIGH) &&\n defined(attributes.planes2D_LOW) &&\n defined(attributes.uMaxVmax) &&\n defined(attributes.uvMinAndExtents)\n );\n};\n\nfunction shouldUseSpherical(rectangle) {\n return (\n Math.max(rectangle.width, rectangle.height) >\n ShadowVolumeAppearance.MAX_WIDTH_FOR_PLANAR_EXTENTS\n );\n}\n\n/**\n * Computes whether the given rectangle is wide enough that texture coordinates\n * over its area should be computed using spherical extents instead of distance to planes.\n *\n * @param {Rectangle} rectangle A rectangle\n * @private\n */\nShadowVolumeAppearance.shouldUseSphericalCoordinates = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n return shouldUseSpherical(rectangle);\n};\n\n/**\n * Texture coordinates for ground primitives are computed either using spherical coordinates for large areas or\n * using distance from planes for small areas.\n *\n * @type {number}\n * @constant\n * @private\n */\nShadowVolumeAppearance.MAX_WIDTH_FOR_PLANAR_EXTENTS = CesiumMath.toRadians(1.0);\nexport default ShadowVolumeAppearance;\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines the function used to compare stencil values for the stencil test.\n *\n * @enum {number}\n */\nconst StencilFunction = {\n /**\n * The stencil test never passes.\n *\n * @type {number}\n * @constant\n */\n NEVER: WebGLConstants.NEVER,\n\n /**\n * The stencil test passes when the masked reference value is less than the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n LESS: WebGLConstants.LESS,\n\n /**\n * The stencil test passes when the masked reference value is equal to the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n EQUAL: WebGLConstants.EQUAL,\n\n /**\n * The stencil test passes when the masked reference value is less than or equal to the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n LESS_OR_EQUAL: WebGLConstants.LEQUAL,\n\n /**\n * The stencil test passes when the masked reference value is greater than the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n GREATER: WebGLConstants.GREATER,\n\n /**\n * The stencil test passes when the masked reference value is not equal to the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n NOT_EQUAL: WebGLConstants.NOTEQUAL,\n\n /**\n * The stencil test passes when the masked reference value is greater than or equal to the masked stencil value.\n *\n * @type {number}\n * @constant\n */\n GREATER_OR_EQUAL: WebGLConstants.GEQUAL,\n\n /**\n * The stencil test always passes.\n *\n * @type {number}\n * @constant\n */\n ALWAYS: WebGLConstants.ALWAYS,\n};\nexport default Object.freeze(StencilFunction);\n", "import WebGLConstants from \"../Core/WebGLConstants.js\";\n\n/**\n * Determines the action taken based on the result of the stencil test.\n *\n * @enum {number}\n */\nconst StencilOperation = {\n /**\n * Sets the stencil buffer value to zero.\n *\n * @type {number}\n * @constant\n */\n ZERO: WebGLConstants.ZERO,\n\n /**\n * Does not change the stencil buffer.\n *\n * @type {number}\n * @constant\n */\n KEEP: WebGLConstants.KEEP,\n\n /**\n * Replaces the stencil buffer value with the reference value.\n *\n * @type {number}\n * @constant\n */\n REPLACE: WebGLConstants.REPLACE,\n\n /**\n * Increments the stencil buffer value, clamping to unsigned byte.\n *\n * @type {number}\n * @constant\n */\n INCREMENT: WebGLConstants.INCR,\n\n /**\n * Decrements the stencil buffer value, clamping to zero.\n *\n * @type {number}\n * @constant\n */\n DECREMENT: WebGLConstants.DECR,\n\n /**\n * Bitwise inverts the existing stencil buffer value.\n *\n * @type {number}\n * @constant\n */\n INVERT: WebGLConstants.INVERT,\n\n /**\n * Increments the stencil buffer value, wrapping to zero when exceeding the unsigned byte range.\n *\n * @type {number}\n * @constant\n */\n INCREMENT_WRAP: WebGLConstants.INCR_WRAP,\n\n /**\n * Decrements the stencil buffer value, wrapping to the maximum unsigned byte instead of going below zero.\n *\n * @type {number}\n * @constant\n */\n DECREMENT_WRAP: WebGLConstants.DECR_WRAP,\n};\nexport default Object.freeze(StencilOperation);\n", "import StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\n\n/**\n * The most significant bit is used to identify whether the pixel is 3D Tiles.\n * The next three bits store selection depth for the skip LODs optimization.\n * The last four bits are for increment/decrement shadow volume operations for classification.\n *\n * @private\n */\nconst StencilConstants = {\n CESIUM_3D_TILE_MASK: 0x80,\n SKIP_LOD_MASK: 0x70,\n SKIP_LOD_BIT_SHIFT: 4,\n CLASSIFICATION_MASK: 0x0f,\n};\n\nStencilConstants.setCesium3DTileBit = function () {\n return {\n enabled: true,\n frontFunction: StencilFunction.ALWAYS,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.REPLACE,\n },\n backFunction: StencilFunction.ALWAYS,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.REPLACE,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n };\n};\nexport default Object.freeze(StencilConstants);\n", "import ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport combine from \"../Core/combine.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport ShadowVolumeAppearanceVS from \"../Shaders/ShadowVolumeAppearanceVS.js\";\nimport ShadowVolumeFS from \"../Shaders/ShadowVolumeFS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport DepthFunction from \"./DepthFunction.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport Primitive from \"./Primitive.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport ShadowVolumeAppearance from \"./ShadowVolumeAppearance.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\n\n/**\n * A classification primitive represents a volume enclosing geometry in the {@link Scene} to be highlighted.\n *

\n * A primitive combines geometry instances with an {@link Appearance} that describes the full shading, including\n * {@link Material} and {@link RenderState}. Roughly, the geometry instance defines the structure and placement,\n * and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix\n * and match most of them and add a new geometry or appearance independently of each other.\n * Only {@link PerInstanceColorAppearance} with the same color across all instances is supported at this time when using\n * ClassificationPrimitive directly.\n * For full {@link Appearance} support when classifying terrain or 3D Tiles use {@link GroundPrimitive} instead.\n *

\n *

\n * For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there\n * will be rendering artifacts for some viewing angles.\n *

\n *

\n * Valid geometries are {@link BoxGeometry}, {@link CylinderGeometry}, {@link EllipsoidGeometry}, {@link PolylineVolumeGeometry}, and {@link SphereGeometry}.\n *

\n *

\n * Geometries that follow the surface of the ellipsoid, such as {@link CircleGeometry}, {@link CorridorGeometry}, {@link EllipseGeometry}, {@link PolygonGeometry}, and {@link RectangleGeometry},\n * are also valid if they are extruded volumes; otherwise, they will not be rendered.\n *

\n *\n * @alias ClassificationPrimitive\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Array|GeometryInstance} [options.geometryInstances] The geometry instances to render. This can either be a single instance or an array of length one.\n * @param {Appearance} [options.appearance] The appearance used to render the primitive. Defaults to PerInstanceColorAppearance when GeometryInstances have a color attribute.\n * @param {boolean} [options.show=true] Determines if this primitive will be shown.\n * @param {boolean} [options.vertexCacheOptimize=false] When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n * @param {boolean} [options.interleave=false] When true, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.\n * @param {boolean} [options.compressVertices=true] When true, the geometry vertices are compressed, which will save memory.\n * @param {boolean} [options.releaseGeometryInstances=true] When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n * @param {boolean} [options.allowPicking=true] When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n * @param {boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first.\n * @param {ClassificationType} [options.classificationType=ClassificationType.BOTH] Determines whether terrain, 3D Tiles or both will be classified.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {boolean} [options.debugShowShadowVolume=false] For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be true on\n * creation for the volumes to be created before the geometry is released or options.releaseGeometryInstance must be false.\n *\n * @see Primitive\n * @see GroundPrimitive\n * @see GeometryInstance\n * @see Appearance\n */\nfunction ClassificationPrimitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const geometryInstances = options.geometryInstances;\n\n /**\n * The geometry instance rendered with this primitive. This may\n * be undefined if options.releaseGeometryInstances\n * is true when the primitive is constructed.\n *

\n * Changing this property after the primitive is rendered has no effect.\n *

\n *

\n * Because of the rendering technique used, all geometry instances must be the same color.\n * If there is an instance with a differing color, a DeveloperError will be thrown\n * on the first attempt to render.\n *

\n *\n * @readonly\n * @type {Array|GeometryInstance}\n *\n * @default undefined\n */\n this.geometryInstances = geometryInstances;\n /**\n * Determines if the primitive will be shown. This affects all geometry\n * instances in the primitive.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.show = defaultValue(options.show, true);\n /**\n * Determines whether terrain, 3D Tiles or both will be classified.\n *\n * @type {ClassificationType}\n *\n * @default ClassificationType.BOTH\n */\n this.classificationType = defaultValue(\n options.classificationType,\n ClassificationType.BOTH\n );\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the shadow volume for each geometry in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowShadowVolume = defaultValue(\n options.debugShowShadowVolume,\n false\n );\n this._debugShowShadowVolume = false;\n\n // These are used by GroundPrimitive to augment the shader and uniform map.\n this._extruded = defaultValue(options._extruded, false);\n this._uniformMap = options._uniformMap;\n\n this._sp = undefined;\n this._spStencil = undefined;\n this._spPick = undefined;\n this._spColor = undefined;\n\n this._spPick2D = undefined; // only derived if necessary\n this._spColor2D = undefined; // only derived if necessary\n\n this._rsStencilDepthPass = undefined;\n this._rsStencilDepthPass3DTiles = undefined;\n this._rsColorPass = undefined;\n this._rsPickPass = undefined;\n\n this._commandsIgnoreShow = [];\n\n this._ready = false;\n this._primitive = undefined;\n this._pickPrimitive = options._pickPrimitive;\n\n // Set in update\n this._hasSphericalExtentsAttribute = false;\n this._hasPlanarExtentsAttributes = false;\n this._hasPerColorAttribute = false;\n\n this.appearance = options.appearance;\n\n this._createBoundingVolumeFunction = options._createBoundingVolumeFunction;\n this._updateAndQueueCommandsFunction =\n options._updateAndQueueCommandsFunction;\n\n this._usePickOffsets = false;\n\n this._primitiveOptions = {\n geometryInstances: undefined,\n appearance: undefined,\n vertexCacheOptimize: defaultValue(options.vertexCacheOptimize, false),\n interleave: defaultValue(options.interleave, false),\n releaseGeometryInstances: defaultValue(\n options.releaseGeometryInstances,\n true\n ),\n allowPicking: defaultValue(options.allowPicking, true),\n asynchronous: defaultValue(options.asynchronous, true),\n compressVertices: defaultValue(options.compressVertices, true),\n _createBoundingVolumeFunction: undefined,\n _createRenderStatesFunction: undefined,\n _createShaderProgramFunction: undefined,\n _createCommandsFunction: undefined,\n _updateAndQueueCommandsFunction: undefined,\n _createPickOffsets: true,\n };\n}\n\nObject.defineProperties(ClassificationPrimitive.prototype, {\n /**\n * When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n vertexCacheOptimize: {\n get: function () {\n return this._primitiveOptions.vertexCacheOptimize;\n },\n },\n\n /**\n * Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n interleave: {\n get: function () {\n return this._primitiveOptions.interleave;\n },\n },\n\n /**\n * When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n releaseGeometryInstances: {\n get: function () {\n return this._primitiveOptions.releaseGeometryInstances;\n },\n },\n\n /**\n * When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n allowPicking: {\n get: function () {\n return this._primitiveOptions.allowPicking;\n },\n },\n\n /**\n * Determines if the geometry instances will be created and batched on a web worker.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n asynchronous: {\n get: function () {\n return this._primitiveOptions.asynchronous;\n },\n },\n\n /**\n * When true, geometry vertices are compressed, which will save memory.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n compressVertices: {\n get: function () {\n return this._primitiveOptions.compressVertices;\n },\n },\n\n /**\n * Determines if the primitive is complete and ready to render. If this property is\n * true, the primitive will be rendered the next time that {@link ClassificationPrimitive#update}\n * is called.\n *\n * @memberof ClassificationPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n /**\n * Returns true if the ClassificationPrimitive needs a separate shader and commands for 2D.\n * This is because texture coordinates on ClassificationPrimitives are computed differently,\n * and are used for culling when multiple GeometryInstances are batched in one ClassificationPrimitive.\n * @memberof ClassificationPrimitive.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n _needs2DShader: {\n get: function () {\n return (\n this._hasPlanarExtentsAttributes || this._hasSphericalExtentsAttribute\n );\n },\n },\n});\n\n/**\n * Determines if ClassificationPrimitive rendering is supported.\n *\n * @param {Scene} scene The scene.\n * @returns {boolean} true if ClassificationPrimitives are supported; otherwise, returns false\n */\nClassificationPrimitive.isSupported = function (scene) {\n return scene.context.stencilBuffer;\n};\n\nfunction getStencilDepthRenderState(enableStencil, mask3DTiles) {\n const stencilFunction = mask3DTiles\n ? StencilFunction.EQUAL\n : StencilFunction.ALWAYS;\n return {\n colorMask: {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n },\n stencilTest: {\n enabled: enableStencil,\n frontFunction: stencilFunction,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.DECREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n backFunction: stencilFunction,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.INCREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: true,\n func: DepthFunction.LESS_OR_EQUAL,\n },\n depthMask: false,\n };\n}\n\nfunction getColorRenderState(enableStencil) {\n return {\n stencilTest: {\n enabled: enableStencil,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n };\n}\n\nconst pickRenderState = {\n stencilTest: {\n enabled: true,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n};\n\nfunction createRenderStates(\n classificationPrimitive,\n context,\n appearance,\n twoPasses\n) {\n if (defined(classificationPrimitive._rsStencilDepthPass)) {\n return;\n }\n const stencilEnabled = !classificationPrimitive.debugShowShadowVolume;\n\n classificationPrimitive._rsStencilDepthPass = RenderState.fromCache(\n getStencilDepthRenderState(stencilEnabled, false)\n );\n classificationPrimitive._rsStencilDepthPass3DTiles = RenderState.fromCache(\n getStencilDepthRenderState(stencilEnabled, true)\n );\n classificationPrimitive._rsColorPass = RenderState.fromCache(\n getColorRenderState(stencilEnabled, false)\n );\n classificationPrimitive._rsPickPass = RenderState.fromCache(pickRenderState);\n}\n\nfunction modifyForEncodedNormals(primitive, vertexShaderSource) {\n if (!primitive.compressVertices) {\n return vertexShaderSource;\n }\n\n if (vertexShaderSource.search(/in\\s+vec3\\s+extrudeDirection;/g) !== -1) {\n const attributeName = \"compressedAttributes\";\n\n //only shadow volumes use extrudeDirection, and shadow volumes use vertexFormat: POSITION_ONLY so we don't need to check other attributes\n const attributeDecl = `in vec2 ${attributeName};`;\n\n const globalDecl = \"vec3 extrudeDirection;\\n\";\n const decode = ` extrudeDirection = czm_octDecode(${attributeName}, 65535.0);\\n`;\n\n let modifiedVS = vertexShaderSource;\n modifiedVS = modifiedVS.replace(/in\\s+vec3\\s+extrudeDirection;/g, \"\");\n modifiedVS = ShaderSource.replaceMain(\n modifiedVS,\n \"czm_non_compressed_main\"\n );\n const compressedMain =\n `${\"void main() \\n\" + \"{ \\n\"}${decode} czm_non_compressed_main(); \\n` +\n `}`;\n\n return [attributeDecl, globalDecl, modifiedVS, compressedMain].join(\"\\n\");\n }\n}\n\nfunction createShaderProgram(classificationPrimitive, frameState) {\n const context = frameState.context;\n const primitive = classificationPrimitive._primitive;\n let vs = ShadowVolumeAppearanceVS;\n vs = classificationPrimitive._primitive._batchTable.getVertexShaderCallback()(\n vs\n );\n vs = Primitive._appendDistanceDisplayConditionToShader(primitive, vs);\n vs = Primitive._modifyShaderPosition(\n classificationPrimitive,\n vs,\n frameState.scene3DOnly\n );\n vs = Primitive._updateColorAttribute(primitive, vs);\n\n const planarExtents = classificationPrimitive._hasPlanarExtentsAttributes;\n const cullFragmentsUsingExtents =\n planarExtents || classificationPrimitive._hasSphericalExtentsAttribute;\n\n if (classificationPrimitive._extruded) {\n vs = modifyForEncodedNormals(primitive, vs);\n }\n\n const extrudedDefine = classificationPrimitive._extruded\n ? \"EXTRUDED_GEOMETRY\"\n : \"\";\n\n let vsSource = new ShaderSource({\n defines: [extrudedDefine],\n sources: [vs],\n });\n const fsSource = new ShaderSource({\n sources: [ShadowVolumeFS],\n });\n const attributeLocations =\n classificationPrimitive._primitive._attributeLocations;\n\n const shadowVolumeAppearance = new ShadowVolumeAppearance(\n cullFragmentsUsingExtents,\n planarExtents,\n classificationPrimitive.appearance\n );\n\n classificationPrimitive._spStencil = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: classificationPrimitive._spStencil,\n vertexShaderSource: vsSource,\n fragmentShaderSource: fsSource,\n attributeLocations: attributeLocations,\n });\n\n if (classificationPrimitive._primitive.allowPicking) {\n let vsPick = ShaderSource.createPickVertexShaderSource(vs);\n vsPick = Primitive._appendShowToShader(primitive, vsPick);\n vsPick = Primitive._updatePickColorAttribute(vsPick);\n\n const pickFS3D = shadowVolumeAppearance.createPickFragmentShader(false);\n const pickVS3D = shadowVolumeAppearance.createPickVertexShader(\n [extrudedDefine],\n vsPick,\n false,\n frameState.mapProjection\n );\n\n classificationPrimitive._spPick = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: classificationPrimitive._spPick,\n vertexShaderSource: pickVS3D,\n fragmentShaderSource: pickFS3D,\n attributeLocations: attributeLocations,\n });\n\n // Derive a 2D pick shader if the primitive uses texture coordinate-based fragment culling,\n // since texture coordinates are computed differently in 2D.\n if (cullFragmentsUsingExtents) {\n let pickProgram2D = context.shaderCache.getDerivedShaderProgram(\n classificationPrimitive._spPick,\n \"2dPick\"\n );\n if (!defined(pickProgram2D)) {\n const pickFS2D = shadowVolumeAppearance.createPickFragmentShader(true);\n const pickVS2D = shadowVolumeAppearance.createPickVertexShader(\n [extrudedDefine],\n vsPick,\n true,\n frameState.mapProjection\n );\n\n pickProgram2D = context.shaderCache.createDerivedShaderProgram(\n classificationPrimitive._spPick,\n \"2dPick\",\n {\n vertexShaderSource: pickVS2D,\n fragmentShaderSource: pickFS2D,\n attributeLocations: attributeLocations,\n }\n );\n }\n classificationPrimitive._spPick2D = pickProgram2D;\n }\n } else {\n classificationPrimitive._spPick = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vsSource,\n fragmentShaderSource: fsSource,\n attributeLocations: attributeLocations,\n });\n }\n\n vs = Primitive._appendShowToShader(primitive, vs);\n vsSource = new ShaderSource({\n defines: [extrudedDefine],\n sources: [vs],\n });\n\n classificationPrimitive._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: classificationPrimitive._sp,\n vertexShaderSource: vsSource,\n fragmentShaderSource: fsSource,\n attributeLocations: attributeLocations,\n });\n\n // Create a fragment shader that computes only required material hookups using screen space techniques\n const fsColorSource = shadowVolumeAppearance.createFragmentShader(false);\n const vsColorSource = shadowVolumeAppearance.createVertexShader(\n [extrudedDefine],\n vs,\n false,\n frameState.mapProjection\n );\n\n classificationPrimitive._spColor = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: classificationPrimitive._spColor,\n vertexShaderSource: vsColorSource,\n fragmentShaderSource: fsColorSource,\n attributeLocations: attributeLocations,\n });\n\n // Derive a 2D shader if the primitive uses texture coordinate-based fragment culling,\n // since texture coordinates are computed differently in 2D.\n // Any material that uses texture coordinates will also equip texture coordinate-based fragment culling.\n if (cullFragmentsUsingExtents) {\n let colorProgram2D = context.shaderCache.getDerivedShaderProgram(\n classificationPrimitive._spColor,\n \"2dColor\"\n );\n if (!defined(colorProgram2D)) {\n const fsColorSource2D = shadowVolumeAppearance.createFragmentShader(true);\n const vsColorSource2D = shadowVolumeAppearance.createVertexShader(\n [extrudedDefine],\n vs,\n true,\n frameState.mapProjection\n );\n\n colorProgram2D = context.shaderCache.createDerivedShaderProgram(\n classificationPrimitive._spColor,\n \"2dColor\",\n {\n vertexShaderSource: vsColorSource2D,\n fragmentShaderSource: fsColorSource2D,\n attributeLocations: attributeLocations,\n }\n );\n }\n classificationPrimitive._spColor2D = colorProgram2D;\n }\n}\n\nfunction createColorCommands(classificationPrimitive, colorCommands) {\n const primitive = classificationPrimitive._primitive;\n let length = primitive._va.length * 2; // each geometry (pack of vertex attributes) needs 2 commands: front/back stencils and fill\n colorCommands.length = length;\n\n let i;\n let command;\n let derivedCommand;\n let vaIndex = 0;\n let uniformMap = primitive._batchTable.getUniformMapCallback()(\n classificationPrimitive._uniformMap\n );\n\n const needs2DShader = classificationPrimitive._needs2DShader;\n\n for (i = 0; i < length; i += 2) {\n const vertexArray = primitive._va[vaIndex++];\n\n // Stencil depth command\n command = colorCommands[i];\n if (!defined(command)) {\n command = colorCommands[i] = new DrawCommand({\n owner: classificationPrimitive,\n primitiveType: primitive._primitiveType,\n });\n }\n\n command.vertexArray = vertexArray;\n command.renderState = classificationPrimitive._rsStencilDepthPass;\n command.shaderProgram = classificationPrimitive._sp;\n command.uniformMap = uniformMap;\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n\n derivedCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedCommand.renderState =\n classificationPrimitive._rsStencilDepthPass3DTiles;\n derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedCommand;\n\n // Color command\n command = colorCommands[i + 1];\n if (!defined(command)) {\n command = colorCommands[i + 1] = new DrawCommand({\n owner: classificationPrimitive,\n primitiveType: primitive._primitiveType,\n });\n }\n\n command.vertexArray = vertexArray;\n command.renderState = classificationPrimitive._rsColorPass;\n command.shaderProgram = classificationPrimitive._spColor;\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n\n const appearance = classificationPrimitive.appearance;\n const material = appearance.material;\n if (defined(material)) {\n uniformMap = combine(uniformMap, material._uniforms);\n }\n\n command.uniformMap = uniformMap;\n\n derivedCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedCommand;\n\n // Derive for 2D if texture coordinates are ever computed\n if (needs2DShader) {\n // First derive from the terrain command\n let derived2DCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.appearance2D\n );\n derived2DCommand.shaderProgram = classificationPrimitive._spColor2D;\n command.derivedCommands.appearance2D = derived2DCommand;\n\n // Then derive from the 3D Tiles command\n derived2DCommand = DrawCommand.shallowClone(\n derivedCommand,\n derivedCommand.derivedCommands.appearance2D\n );\n derived2DCommand.shaderProgram = classificationPrimitive._spColor2D;\n derivedCommand.derivedCommands.appearance2D = derived2DCommand;\n }\n }\n\n const commandsIgnoreShow = classificationPrimitive._commandsIgnoreShow;\n const spStencil = classificationPrimitive._spStencil;\n\n let commandIndex = 0;\n length = commandsIgnoreShow.length = length / 2;\n\n for (let j = 0; j < length; ++j) {\n const commandIgnoreShow = (commandsIgnoreShow[j] = DrawCommand.shallowClone(\n colorCommands[commandIndex],\n commandsIgnoreShow[j]\n ));\n commandIgnoreShow.shaderProgram = spStencil;\n commandIgnoreShow.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW;\n\n commandIndex += 2;\n }\n}\n\nfunction createPickCommands(classificationPrimitive, pickCommands) {\n const usePickOffsets = classificationPrimitive._usePickOffsets;\n\n const primitive = classificationPrimitive._primitive;\n let length = primitive._va.length * 2; // each geometry (pack of vertex attributes) needs 2 commands: front/back stencils and fill\n\n // Fallback for batching same-color geometry instances\n let pickOffsets;\n let pickIndex = 0;\n let pickOffset;\n if (usePickOffsets) {\n pickOffsets = primitive._pickOffsets;\n length = pickOffsets.length * 2;\n }\n\n pickCommands.length = length;\n\n let j;\n let command;\n let derivedCommand;\n let vaIndex = 0;\n const uniformMap = primitive._batchTable.getUniformMapCallback()(\n classificationPrimitive._uniformMap\n );\n\n const needs2DShader = classificationPrimitive._needs2DShader;\n\n for (j = 0; j < length; j += 2) {\n let vertexArray = primitive._va[vaIndex++];\n if (usePickOffsets) {\n pickOffset = pickOffsets[pickIndex++];\n vertexArray = primitive._va[pickOffset.index];\n }\n\n // Stencil depth command\n command = pickCommands[j];\n if (!defined(command)) {\n command = pickCommands[j] = new DrawCommand({\n owner: classificationPrimitive,\n primitiveType: primitive._primitiveType,\n pickOnly: true,\n });\n }\n\n command.vertexArray = vertexArray;\n command.renderState = classificationPrimitive._rsStencilDepthPass;\n command.shaderProgram = classificationPrimitive._sp;\n command.uniformMap = uniformMap;\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n if (usePickOffsets) {\n command.offset = pickOffset.offset;\n command.count = pickOffset.count;\n }\n\n // Derive for 3D Tiles classification\n derivedCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedCommand.renderState =\n classificationPrimitive._rsStencilDepthPass3DTiles;\n derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedCommand;\n\n // Pick color command\n command = pickCommands[j + 1];\n if (!defined(command)) {\n command = pickCommands[j + 1] = new DrawCommand({\n owner: classificationPrimitive,\n primitiveType: primitive._primitiveType,\n pickOnly: true,\n });\n }\n\n command.vertexArray = vertexArray;\n command.renderState = classificationPrimitive._rsPickPass;\n command.shaderProgram = classificationPrimitive._spPick;\n command.uniformMap = uniformMap;\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n if (usePickOffsets) {\n command.offset = pickOffset.offset;\n command.count = pickOffset.count;\n }\n\n derivedCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedCommand;\n\n // Derive for 2D if texture coordinates are ever computed\n if (needs2DShader) {\n // First derive from the terrain command\n let derived2DCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.pick2D\n );\n derived2DCommand.shaderProgram = classificationPrimitive._spPick2D;\n command.derivedCommands.pick2D = derived2DCommand;\n\n // Then derive from the 3D Tiles command\n derived2DCommand = DrawCommand.shallowClone(\n derivedCommand,\n derivedCommand.derivedCommands.pick2D\n );\n derived2DCommand.shaderProgram = classificationPrimitive._spPick2D;\n derivedCommand.derivedCommands.pick2D = derived2DCommand;\n }\n }\n}\n\nfunction createCommands(\n classificationPrimitive,\n appearance,\n material,\n translucent,\n twoPasses,\n colorCommands,\n pickCommands\n) {\n createColorCommands(classificationPrimitive, colorCommands);\n createPickCommands(classificationPrimitive, pickCommands);\n}\n\nfunction boundingVolumeIndex(commandIndex, length) {\n return Math.floor((commandIndex % length) / 2);\n}\n\nfunction updateAndQueueRenderCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n) {\n command.modelMatrix = modelMatrix;\n command.boundingVolume = boundingVolume;\n command.cull = cull;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n\n frameState.commandList.push(command);\n}\n\nfunction updateAndQueuePickCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n) {\n command.modelMatrix = modelMatrix;\n command.boundingVolume = boundingVolume;\n command.cull = cull;\n\n frameState.commandList.push(command);\n}\n\nfunction updateAndQueueCommands(\n classificationPrimitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n) {\n const primitive = classificationPrimitive._primitive;\n Primitive._updateBoundingVolumes(primitive, frameState, modelMatrix);\n\n let boundingVolumes;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingVolumes = primitive._boundingSphereWC;\n } else if (frameState.mode === SceneMode.COLUMBUS_VIEW) {\n boundingVolumes = primitive._boundingSphereCV;\n } else if (\n frameState.mode === SceneMode.SCENE2D &&\n defined(primitive._boundingSphere2D)\n ) {\n boundingVolumes = primitive._boundingSphere2D;\n } else if (defined(primitive._boundingSphereMorph)) {\n boundingVolumes = primitive._boundingSphereMorph;\n }\n\n const classificationType = classificationPrimitive.classificationType;\n const queueTerrainCommands =\n classificationType !== ClassificationType.CESIUM_3D_TILE;\n const queue3DTilesCommands =\n classificationType !== ClassificationType.TERRAIN;\n\n const passes = frameState.passes;\n\n let i;\n let boundingVolume;\n let command;\n\n if (passes.render) {\n const colorLength = colorCommands.length;\n for (i = 0; i < colorLength; ++i) {\n boundingVolume = boundingVolumes[boundingVolumeIndex(i, colorLength)];\n if (queueTerrainCommands) {\n command = colorCommands[i];\n updateAndQueueRenderCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n if (queue3DTilesCommands) {\n command = colorCommands[i].derivedCommands.tileset;\n updateAndQueueRenderCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n }\n\n if (frameState.invertClassification) {\n const ignoreShowCommands = classificationPrimitive._commandsIgnoreShow;\n const ignoreShowCommandsLength = ignoreShowCommands.length;\n for (i = 0; i < ignoreShowCommandsLength; ++i) {\n boundingVolume = boundingVolumes[i];\n command = ignoreShowCommands[i];\n updateAndQueueRenderCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n }\n }\n\n if (passes.pick) {\n const pickLength = pickCommands.length;\n const pickOffsets = primitive._pickOffsets;\n for (i = 0; i < pickLength; ++i) {\n const pickOffset = pickOffsets[boundingVolumeIndex(i, pickLength)];\n boundingVolume = boundingVolumes[pickOffset.index];\n if (queueTerrainCommands) {\n command = pickCommands[i];\n updateAndQueuePickCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n );\n }\n if (queue3DTilesCommands) {\n command = pickCommands[i].derivedCommands.tileset;\n updateAndQueuePickCommand(\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n );\n }\n }\n }\n}\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {DeveloperError} All instance geometries must have the same primitiveType.\n * @exception {DeveloperError} Appearance and material have a uniform with the same name.\n * @exception {DeveloperError} Not all of the geometry instances have the same color attribute.\n */\nClassificationPrimitive.prototype.update = function (frameState) {\n if (!defined(this._primitive) && !defined(this.geometryInstances)) {\n return;\n }\n\n let appearance = this.appearance;\n if (defined(appearance) && defined(appearance.material)) {\n appearance.material.update(frameState.context);\n }\n\n const that = this;\n const primitiveOptions = this._primitiveOptions;\n\n if (!defined(this._primitive)) {\n const instances = Array.isArray(this.geometryInstances)\n ? this.geometryInstances\n : [this.geometryInstances];\n const length = instances.length;\n\n let i;\n let instance;\n let attributes;\n\n let hasPerColorAttribute = false;\n let allColorsSame = true;\n let firstColor;\n let hasSphericalExtentsAttribute = false;\n let hasPlanarExtentsAttributes = false;\n\n if (length > 0) {\n attributes = instances[0].attributes;\n // Not expecting these to be set by users, should only be set via GroundPrimitive.\n // So don't check for mismatch.\n hasSphericalExtentsAttribute = ShadowVolumeAppearance.hasAttributesForSphericalExtents(\n attributes\n );\n hasPlanarExtentsAttributes = ShadowVolumeAppearance.hasAttributesForTextureCoordinatePlanes(\n attributes\n );\n firstColor = attributes.color;\n }\n\n for (i = 0; i < length; i++) {\n instance = instances[i];\n const color = instance.attributes.color;\n if (defined(color)) {\n hasPerColorAttribute = true;\n }\n //>>includeStart('debug', pragmas.debug);\n else if (hasPerColorAttribute) {\n throw new DeveloperError(\n \"All GeometryInstances must have color attributes to use per-instance color.\"\n );\n }\n //>>includeEnd('debug');\n\n allColorsSame =\n allColorsSame &&\n defined(color) &&\n ColorGeometryInstanceAttribute.equals(firstColor, color);\n }\n\n // If no attributes exist for computing spherical extents or fragment culling,\n // throw if the colors aren't all the same.\n if (\n !allColorsSame &&\n !hasSphericalExtentsAttribute &&\n !hasPlanarExtentsAttributes\n ) {\n throw new DeveloperError(\n \"All GeometryInstances must have the same color attribute except via GroundPrimitives\"\n );\n }\n\n // default to a color appearance\n if (hasPerColorAttribute && !defined(appearance)) {\n appearance = new PerInstanceColorAppearance({\n flat: true,\n });\n this.appearance = appearance;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !hasPerColorAttribute &&\n appearance instanceof PerInstanceColorAppearance\n ) {\n throw new DeveloperError(\n \"PerInstanceColorAppearance requires color GeometryInstanceAttributes on all GeometryInstances\"\n );\n }\n if (\n defined(appearance.material) &&\n !hasSphericalExtentsAttribute &&\n !hasPlanarExtentsAttributes\n ) {\n throw new DeveloperError(\n \"Materials on ClassificationPrimitives are not supported except via GroundPrimitives\"\n );\n }\n //>>includeEnd('debug');\n\n this._usePickOffsets =\n !hasSphericalExtentsAttribute && !hasPlanarExtentsAttributes;\n this._hasSphericalExtentsAttribute = hasSphericalExtentsAttribute;\n this._hasPlanarExtentsAttributes = hasPlanarExtentsAttributes;\n this._hasPerColorAttribute = hasPerColorAttribute;\n\n const geometryInstances = new Array(length);\n for (i = 0; i < length; ++i) {\n instance = instances[i];\n geometryInstances[i] = new GeometryInstance({\n geometry: instance.geometry,\n attributes: instance.attributes,\n modelMatrix: instance.modelMatrix,\n id: instance.id,\n pickPrimitive: defaultValue(this._pickPrimitive, that),\n });\n }\n\n primitiveOptions.appearance = appearance;\n primitiveOptions.geometryInstances = geometryInstances;\n\n if (defined(this._createBoundingVolumeFunction)) {\n primitiveOptions._createBoundingVolumeFunction = function (\n frameState,\n geometry\n ) {\n that._createBoundingVolumeFunction(frameState, geometry);\n };\n }\n\n primitiveOptions._createRenderStatesFunction = function (\n primitive,\n context,\n appearance,\n twoPasses\n ) {\n createRenderStates(that, context);\n };\n primitiveOptions._createShaderProgramFunction = function (\n primitive,\n frameState,\n appearance\n ) {\n createShaderProgram(that, frameState);\n };\n primitiveOptions._createCommandsFunction = function (\n primitive,\n appearance,\n material,\n translucent,\n twoPasses,\n colorCommands,\n pickCommands\n ) {\n createCommands(\n that,\n undefined,\n undefined,\n true,\n false,\n colorCommands,\n pickCommands\n );\n };\n\n if (defined(this._updateAndQueueCommandsFunction)) {\n primitiveOptions._updateAndQueueCommandsFunction = function (\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n ) {\n that._updateAndQueueCommandsFunction(\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n );\n };\n } else {\n primitiveOptions._updateAndQueueCommandsFunction = function (\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n ) {\n updateAndQueueCommands(\n that,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n );\n };\n }\n\n this._primitive = new Primitive(primitiveOptions);\n }\n\n if (\n this.debugShowShadowVolume &&\n !this._debugShowShadowVolume &&\n this._ready\n ) {\n this._debugShowShadowVolume = true;\n this._rsStencilDepthPass = RenderState.fromCache(\n getStencilDepthRenderState(false, false)\n );\n this._rsStencilDepthPass3DTiles = RenderState.fromCache(\n getStencilDepthRenderState(false, true)\n );\n this._rsColorPass = RenderState.fromCache(getColorRenderState(false));\n } else if (!this.debugShowShadowVolume && this._debugShowShadowVolume) {\n this._debugShowShadowVolume = false;\n this._rsStencilDepthPass = RenderState.fromCache(\n getStencilDepthRenderState(true, false)\n );\n this._rsStencilDepthPass3DTiles = RenderState.fromCache(\n getStencilDepthRenderState(true, true)\n );\n this._rsColorPass = RenderState.fromCache(getColorRenderState(true));\n }\n // Update primitive appearance\n if (this._primitive.appearance !== appearance) {\n //>>includeStart('debug', pragmas.debug);\n // Check if the appearance is supported by the geometry attributes\n if (\n !this._hasSphericalExtentsAttribute &&\n !this._hasPlanarExtentsAttributes &&\n defined(appearance.material)\n ) {\n throw new DeveloperError(\n \"Materials on ClassificationPrimitives are not supported except via GroundPrimitive\"\n );\n }\n if (\n !this._hasPerColorAttribute &&\n appearance instanceof PerInstanceColorAppearance\n ) {\n throw new DeveloperError(\n \"PerInstanceColorAppearance requires color GeometryInstanceAttribute\"\n );\n }\n //>>includeEnd('debug');\n this._primitive.appearance = appearance;\n }\n\n this._primitive.show = this.show;\n this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume;\n this._primitive.update(frameState);\n\n frameState.afterRender.push(() => {\n if (defined(this._primitive) && this._primitive.ready) {\n this._ready = true;\n\n if (this.releaseGeometryInstances) {\n this.geometryInstances = undefined;\n }\n }\n });\n};\n\n/**\n * Returns the modifiable per-instance attributes for a {@link GeometryInstance}.\n *\n * @param {*} id The id of the {@link GeometryInstance}.\n * @returns {object} The typed array in the attribute's format or undefined if the is no instance with id.\n *\n * @exception {DeveloperError} must call update before calling getGeometryInstanceAttributes.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);\n * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);\n */\nClassificationPrimitive.prototype.getGeometryInstanceAttributes = function (\n id\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(this._primitive)) {\n throw new DeveloperError(\n \"must call update before calling getGeometryInstanceAttributes\"\n );\n }\n //>>includeEnd('debug');\n return this._primitive.getGeometryInstanceAttributes(id);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see ClassificationPrimitive#destroy\n */\nClassificationPrimitive.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * e = e && e.destroy();\n *\n * @see ClassificationPrimitive#isDestroyed\n */\nClassificationPrimitive.prototype.destroy = function () {\n this._primitive = this._primitive && this._primitive.destroy();\n this._sp = this._sp && this._sp.destroy();\n this._spPick = this._spPick && this._spPick.destroy();\n this._spColor = this._spColor && this._spColor.destroy();\n\n // Derived programs, destroyed above if they existed.\n this._spPick2D = undefined;\n this._spColor2D = undefined;\n return destroyObject(this);\n};\nexport default ClassificationPrimitive;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport TerrainExaggeration from \"../Core/TerrainExaggeration.js\";\nimport ClassificationPrimitive from \"./ClassificationPrimitive.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport ShadowVolumeAppearance from \"./ShadowVolumeAppearance.js\";\n\nconst GroundPrimitiveUniformMap = {\n u_globeMinimumAltitude: function () {\n return 55000.0;\n },\n};\n\n/**\n * A ground primitive represents geometry draped over terrain or 3D Tiles in the {@link Scene}.\n *

\n * A primitive combines geometry instances with an {@link Appearance} that describes the full shading, including\n * {@link Material} and {@link RenderState}. Roughly, the geometry instance defines the structure and placement,\n * and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix\n * and match most of them and add a new geometry or appearance independently of each other.\n *

\n *

\n * Support for the WEBGL_depth_texture extension is required to use GeometryInstances with different PerInstanceColors\n * or materials besides PerInstanceColorAppearance.\n *

\n *

\n * Textured GroundPrimitives were designed for notional patterns and are not meant for precisely mapping\n * textures to terrain - for that use case, use {@link SingleTileImageryProvider}.\n *

\n *

\n * For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there\n * will be rendering artifacts for some viewing angles.\n *

\n *

\n * Valid geometries are {@link CircleGeometry}, {@link CorridorGeometry}, {@link EllipseGeometry}, {@link PolygonGeometry}, and {@link RectangleGeometry}.\n *

\n *\n * @alias GroundPrimitive\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Array|GeometryInstance} [options.geometryInstances] The geometry instances to render.\n * @param {Appearance} [options.appearance] The appearance used to render the primitive. Defaults to a flat PerInstanceColorAppearance when GeometryInstances have a color attribute.\n * @param {boolean} [options.show=true] Determines if this primitive will be shown.\n * @param {boolean} [options.vertexCacheOptimize=false] When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n * @param {boolean} [options.interleave=false] When true, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.\n * @param {boolean} [options.compressVertices=true] When true, the geometry vertices are compressed, which will save memory.\n * @param {boolean} [options.releaseGeometryInstances=true] When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n * @param {boolean} [options.allowPicking=true] When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n * @param {boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first.\n * @param {ClassificationType} [options.classificationType=ClassificationType.BOTH] Determines whether terrain, 3D Tiles or both will be classified.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {boolean} [options.debugShowShadowVolume=false] For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be true on\n * creation for the volumes to be created before the geometry is released or options.releaseGeometryInstance must be false.\n *\n * @example\n * // Example 1: Create primitive with a single instance\n * const rectangleInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.RectangleGeometry({\n * rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0)\n * }),\n * id : 'rectangle',\n * attributes : {\n * color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)\n * }\n * });\n * scene.primitives.add(new Cesium.GroundPrimitive({\n * geometryInstances : rectangleInstance\n * }));\n *\n * // Example 2: Batch instances\n * const color = new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5); // Both instances must have the same color.\n * const rectangleInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.RectangleGeometry({\n * rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0)\n * }),\n * id : 'rectangle',\n * attributes : {\n * color : color\n * }\n * });\n * const ellipseInstance = new Cesium.GeometryInstance({\n * geometry : new Cesium.EllipseGeometry({\n * center : Cesium.Cartesian3.fromDegrees(-105.0, 40.0),\n * semiMinorAxis : 300000.0,\n * semiMajorAxis : 400000.0\n * }),\n * id : 'ellipse',\n * attributes : {\n * color : color\n * }\n * });\n * scene.primitives.add(new Cesium.GroundPrimitive({\n * geometryInstances : [rectangleInstance, ellipseInstance]\n * }));\n *\n * @see Primitive\n * @see ClassificationPrimitive\n * @see GeometryInstance\n * @see Appearance\n */\nfunction GroundPrimitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n let appearance = options.appearance;\n const geometryInstances = options.geometryInstances;\n if (!defined(appearance) && defined(geometryInstances)) {\n const geometryInstancesArray = Array.isArray(geometryInstances)\n ? geometryInstances\n : [geometryInstances];\n const geometryInstanceCount = geometryInstancesArray.length;\n for (let i = 0; i < geometryInstanceCount; i++) {\n const attributes = geometryInstancesArray[i].attributes;\n if (defined(attributes) && defined(attributes.color)) {\n appearance = new PerInstanceColorAppearance({\n flat: true,\n });\n break;\n }\n }\n }\n /**\n * The {@link Appearance} used to shade this primitive. Each geometry\n * instance is shaded with the same appearance. Some appearances, like\n * {@link PerInstanceColorAppearance} allow giving each instance unique\n * properties.\n *\n * @type Appearance\n *\n * @default undefined\n */\n this.appearance = appearance;\n\n /**\n * The geometry instances rendered with this primitive. This may\n * be undefined if options.releaseGeometryInstances\n * is true when the primitive is constructed.\n *

\n * Changing this property after the primitive is rendered has no effect.\n *

\n *\n * @readonly\n * @type {Array|GeometryInstance}\n *\n * @default undefined\n */\n this.geometryInstances = options.geometryInstances;\n /**\n * Determines if the primitive will be shown. This affects all geometry\n * instances in the primitive.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.show = defaultValue(options.show, true);\n /**\n * Determines whether terrain, 3D Tiles or both will be classified.\n *\n * @type {ClassificationType}\n *\n * @default ClassificationType.BOTH\n */\n this.classificationType = defaultValue(\n options.classificationType,\n ClassificationType.BOTH\n );\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the shadow volume for each geometry in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowShadowVolume = defaultValue(\n options.debugShowShadowVolume,\n false\n );\n\n this._boundingVolumes = [];\n this._boundingVolumes2D = [];\n\n this._ready = false;\n this._primitive = undefined;\n\n this._maxHeight = undefined;\n this._minHeight = undefined;\n\n this._maxTerrainHeight = ApproximateTerrainHeights._defaultMaxTerrainHeight;\n this._minTerrainHeight = ApproximateTerrainHeights._defaultMinTerrainHeight;\n\n this._boundingSpheresKeys = [];\n this._boundingSpheres = [];\n\n this._useFragmentCulling = false;\n // Used when inserting in an OrderedPrimitiveCollection\n this._zIndex = undefined;\n\n const that = this;\n this._classificationPrimitiveOptions = {\n geometryInstances: undefined,\n appearance: undefined,\n vertexCacheOptimize: defaultValue(options.vertexCacheOptimize, false),\n interleave: defaultValue(options.interleave, false),\n releaseGeometryInstances: defaultValue(\n options.releaseGeometryInstances,\n true\n ),\n allowPicking: defaultValue(options.allowPicking, true),\n asynchronous: defaultValue(options.asynchronous, true),\n compressVertices: defaultValue(options.compressVertices, true),\n _createBoundingVolumeFunction: undefined,\n _updateAndQueueCommandsFunction: undefined,\n _pickPrimitive: that,\n _extruded: true,\n _uniformMap: GroundPrimitiveUniformMap,\n };\n}\n\nObject.defineProperties(GroundPrimitive.prototype, {\n /**\n * When true, geometry vertices are optimized for the pre and post-vertex-shader caches.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n vertexCacheOptimize: {\n get: function () {\n return this._classificationPrimitiveOptions.vertexCacheOptimize;\n },\n },\n\n /**\n * Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n interleave: {\n get: function () {\n return this._classificationPrimitiveOptions.interleave;\n },\n },\n\n /**\n * When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n releaseGeometryInstances: {\n get: function () {\n return this._classificationPrimitiveOptions.releaseGeometryInstances;\n },\n },\n\n /**\n * When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n allowPicking: {\n get: function () {\n return this._classificationPrimitiveOptions.allowPicking;\n },\n },\n\n /**\n * Determines if the geometry instances will be created and batched on a web worker.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n asynchronous: {\n get: function () {\n return this._classificationPrimitiveOptions.asynchronous;\n },\n },\n\n /**\n * When true, geometry vertices are compressed, which will save memory.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n compressVertices: {\n get: function () {\n return this._classificationPrimitiveOptions.compressVertices;\n },\n },\n\n /**\n * Determines if the primitive is complete and ready to render. If this property is\n * true, the primitive will be rendered the next time that {@link GroundPrimitive#update}\n * is called.\n *\n * @memberof GroundPrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\n/**\n * Determines if GroundPrimitive rendering is supported.\n *\n * @function\n * @param {Scene} scene The scene.\n * @returns {boolean} true if GroundPrimitives are supported; otherwise, returns false\n */\nGroundPrimitive.isSupported = ClassificationPrimitive.isSupported;\n\nfunction getComputeMaximumHeightFunction(primitive) {\n return function (granularity, ellipsoid) {\n const r = ellipsoid.maximumRadius;\n const delta = r / Math.cos(granularity * 0.5) - r;\n return primitive._maxHeight + delta;\n };\n}\n\nfunction getComputeMinimumHeightFunction(primitive) {\n return function (granularity, ellipsoid) {\n return primitive._minHeight;\n };\n}\n\nconst scratchBVCartesianHigh = new Cartesian3();\nconst scratchBVCartesianLow = new Cartesian3();\nconst scratchBVCartesian = new Cartesian3();\nconst scratchBVCartographic = new Cartographic();\nconst scratchBVRectangle = new Rectangle();\n\nfunction getRectangle(frameState, geometry) {\n const ellipsoid = frameState.mapProjection.ellipsoid;\n\n if (\n !defined(geometry.attributes) ||\n !defined(geometry.attributes.position3DHigh)\n ) {\n if (defined(geometry.rectangle)) {\n return geometry.rectangle;\n }\n\n return undefined;\n }\n\n const highPositions = geometry.attributes.position3DHigh.values;\n const lowPositions = geometry.attributes.position3DLow.values;\n const length = highPositions.length;\n\n let minLat = Number.POSITIVE_INFINITY;\n let minLon = Number.POSITIVE_INFINITY;\n let maxLat = Number.NEGATIVE_INFINITY;\n let maxLon = Number.NEGATIVE_INFINITY;\n\n for (let i = 0; i < length; i += 3) {\n const highPosition = Cartesian3.unpack(\n highPositions,\n i,\n scratchBVCartesianHigh\n );\n const lowPosition = Cartesian3.unpack(\n lowPositions,\n i,\n scratchBVCartesianLow\n );\n\n const position = Cartesian3.add(\n highPosition,\n lowPosition,\n scratchBVCartesian\n );\n const cartographic = ellipsoid.cartesianToCartographic(\n position,\n scratchBVCartographic\n );\n\n const latitude = cartographic.latitude;\n const longitude = cartographic.longitude;\n\n minLat = Math.min(minLat, latitude);\n minLon = Math.min(minLon, longitude);\n maxLat = Math.max(maxLat, latitude);\n maxLon = Math.max(maxLon, longitude);\n }\n\n const rectangle = scratchBVRectangle;\n rectangle.north = maxLat;\n rectangle.south = minLat;\n rectangle.east = maxLon;\n rectangle.west = minLon;\n\n return rectangle;\n}\n\nfunction setMinMaxTerrainHeights(primitive, rectangle, ellipsoid) {\n const result = ApproximateTerrainHeights.getMinimumMaximumHeights(\n rectangle,\n ellipsoid\n );\n\n primitive._minTerrainHeight = result.minimumTerrainHeight;\n primitive._maxTerrainHeight = result.maximumTerrainHeight;\n}\n\nfunction createBoundingVolume(groundPrimitive, frameState, geometry) {\n const ellipsoid = frameState.mapProjection.ellipsoid;\n const rectangle = getRectangle(frameState, geometry);\n\n const obb = OrientedBoundingBox.fromRectangle(\n rectangle,\n groundPrimitive._minHeight,\n groundPrimitive._maxHeight,\n ellipsoid\n );\n groundPrimitive._boundingVolumes.push(obb);\n\n if (!frameState.scene3DOnly) {\n const projection = frameState.mapProjection;\n const boundingVolume = BoundingSphere.fromRectangleWithHeights2D(\n rectangle,\n projection,\n groundPrimitive._maxHeight,\n groundPrimitive._minHeight\n );\n Cartesian3.fromElements(\n boundingVolume.center.z,\n boundingVolume.center.x,\n boundingVolume.center.y,\n boundingVolume.center\n );\n\n groundPrimitive._boundingVolumes2D.push(boundingVolume);\n }\n}\n\nfunction boundingVolumeIndex(commandIndex, length) {\n return Math.floor((commandIndex % length) / 2);\n}\n\nfunction updateAndQueueRenderCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n) {\n // Use derived appearance command for 2D if needed\n const classificationPrimitive = groundPrimitive._primitive;\n if (\n frameState.mode !== SceneMode.SCENE3D &&\n command.shaderProgram === classificationPrimitive._spColor &&\n classificationPrimitive._needs2DShader\n ) {\n command = command.derivedCommands.appearance2D;\n }\n\n command.owner = groundPrimitive;\n command.modelMatrix = modelMatrix;\n command.boundingVolume = boundingVolume;\n command.cull = cull;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n\n frameState.commandList.push(command);\n}\n\nfunction updateAndQueuePickCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n) {\n // Use derived pick command for 2D if needed\n const classificationPrimitive = groundPrimitive._primitive;\n if (\n frameState.mode !== SceneMode.SCENE3D &&\n command.shaderProgram === classificationPrimitive._spPick &&\n classificationPrimitive._needs2DShader\n ) {\n command = command.derivedCommands.pick2D;\n }\n\n command.owner = groundPrimitive;\n command.modelMatrix = modelMatrix;\n command.boundingVolume = boundingVolume;\n command.cull = cull;\n\n frameState.commandList.push(command);\n}\n\nfunction updateAndQueueCommands(\n groundPrimitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n) {\n let boundingVolumes;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingVolumes = groundPrimitive._boundingVolumes;\n } else {\n boundingVolumes = groundPrimitive._boundingVolumes2D;\n }\n\n const classificationType = groundPrimitive.classificationType;\n const queueTerrainCommands =\n classificationType !== ClassificationType.CESIUM_3D_TILE;\n const queue3DTilesCommands =\n classificationType !== ClassificationType.TERRAIN;\n\n const passes = frameState.passes;\n const classificationPrimitive = groundPrimitive._primitive;\n\n let i;\n let boundingVolume;\n let command;\n\n if (passes.render) {\n const colorLength = colorCommands.length;\n\n for (i = 0; i < colorLength; ++i) {\n boundingVolume = boundingVolumes[boundingVolumeIndex(i, colorLength)];\n if (queueTerrainCommands) {\n command = colorCommands[i];\n updateAndQueueRenderCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n if (queue3DTilesCommands) {\n command = colorCommands[i].derivedCommands.tileset;\n updateAndQueueRenderCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n }\n\n if (frameState.invertClassification) {\n const ignoreShowCommands = classificationPrimitive._commandsIgnoreShow;\n const ignoreShowCommandsLength = ignoreShowCommands.length;\n for (i = 0; i < ignoreShowCommandsLength; ++i) {\n boundingVolume = boundingVolumes[i];\n command = ignoreShowCommands[i];\n updateAndQueueRenderCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n }\n }\n\n if (passes.pick) {\n const pickLength = pickCommands.length;\n\n let pickOffsets;\n if (!groundPrimitive._useFragmentCulling) {\n // Must be using pick offsets\n pickOffsets = classificationPrimitive._primitive._pickOffsets;\n }\n for (i = 0; i < pickLength; ++i) {\n boundingVolume = boundingVolumes[boundingVolumeIndex(i, pickLength)];\n if (!groundPrimitive._useFragmentCulling) {\n const pickOffset = pickOffsets[boundingVolumeIndex(i, pickLength)];\n boundingVolume = boundingVolumes[pickOffset.index];\n }\n if (queueTerrainCommands) {\n command = pickCommands[i];\n updateAndQueuePickCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n );\n }\n if (queue3DTilesCommands) {\n command = pickCommands[i].derivedCommands.tileset;\n updateAndQueuePickCommand(\n groundPrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume\n );\n }\n }\n }\n}\n\n/**\n * Initializes the minimum and maximum terrain heights. This only needs to be called if you are creating the\n * GroundPrimitive synchronously.\n *\n * @returns {Promise} A promise that will resolve once the terrain heights have been loaded.\n *\n */\nGroundPrimitive.initializeTerrainHeights = function () {\n return ApproximateTerrainHeights.initialize();\n};\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {DeveloperError} For synchronous GroundPrimitive, you must call GroundPrimitive.initializeTerrainHeights() and wait for the returned promise to resolve.\n * @exception {DeveloperError} All instance geometries must have the same primitiveType.\n * @exception {DeveloperError} Appearance and material have a uniform with the same name.\n */\nGroundPrimitive.prototype.update = function (frameState) {\n if (!defined(this._primitive) && !defined(this.geometryInstances)) {\n return;\n }\n\n if (!ApproximateTerrainHeights.initialized) {\n //>>includeStart('debug', pragmas.debug);\n if (!this.asynchronous) {\n throw new DeveloperError(\n \"For synchronous GroundPrimitives, you must call GroundPrimitive.initializeTerrainHeights() and wait for the returned promise to resolve.\"\n );\n }\n //>>includeEnd('debug');\n\n GroundPrimitive.initializeTerrainHeights();\n return;\n }\n\n const that = this;\n const primitiveOptions = this._classificationPrimitiveOptions;\n\n if (!defined(this._primitive)) {\n const ellipsoid = frameState.mapProjection.ellipsoid;\n\n let instance;\n let geometry;\n let instanceType;\n\n const instances = Array.isArray(this.geometryInstances)\n ? this.geometryInstances\n : [this.geometryInstances];\n const length = instances.length;\n const groundInstances = new Array(length);\n\n let i;\n let rectangle;\n for (i = 0; i < length; ++i) {\n instance = instances[i];\n geometry = instance.geometry;\n const instanceRectangle = getRectangle(frameState, geometry);\n if (!defined(rectangle)) {\n rectangle = Rectangle.clone(instanceRectangle);\n } else if (defined(instanceRectangle)) {\n Rectangle.union(rectangle, instanceRectangle, rectangle);\n }\n\n const id = instance.id;\n if (defined(id) && defined(instanceRectangle)) {\n const boundingSphere = ApproximateTerrainHeights.getBoundingSphere(\n instanceRectangle,\n ellipsoid\n );\n this._boundingSpheresKeys.push(id);\n this._boundingSpheres.push(boundingSphere);\n }\n\n instanceType = geometry.constructor;\n if (!defined(instanceType) || !defined(instanceType.createShadowVolume)) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"Not all of the geometry instances have GroundPrimitive support.\"\n );\n //>>includeEnd('debug');\n }\n }\n\n // Now compute the min/max heights for the primitive\n setMinMaxTerrainHeights(this, rectangle, ellipsoid);\n const exaggeration = frameState.terrainExaggeration;\n const exaggerationRelativeHeight =\n frameState.terrainExaggerationRelativeHeight;\n this._minHeight = TerrainExaggeration.getHeight(\n this._minTerrainHeight,\n exaggeration,\n exaggerationRelativeHeight\n );\n this._maxHeight = TerrainExaggeration.getHeight(\n this._maxTerrainHeight,\n exaggeration,\n exaggerationRelativeHeight\n );\n\n const useFragmentCulling = GroundPrimitive._supportsMaterials(\n frameState.context\n );\n this._useFragmentCulling = useFragmentCulling;\n\n if (useFragmentCulling) {\n // Determine whether to add spherical or planar extent attributes for computing texture coordinates.\n // This depends on the size of the GeometryInstances.\n let attributes;\n let usePlanarExtents = true;\n for (i = 0; i < length; ++i) {\n instance = instances[i];\n geometry = instance.geometry;\n rectangle = getRectangle(frameState, geometry);\n if (ShadowVolumeAppearance.shouldUseSphericalCoordinates(rectangle)) {\n usePlanarExtents = false;\n break;\n }\n }\n\n for (i = 0; i < length; ++i) {\n instance = instances[i];\n geometry = instance.geometry;\n instanceType = geometry.constructor;\n\n const boundingRectangle = getRectangle(frameState, geometry);\n const textureCoordinateRotationPoints =\n geometry.textureCoordinateRotationPoints;\n\n if (usePlanarExtents) {\n attributes = ShadowVolumeAppearance.getPlanarTextureCoordinateAttributes(\n boundingRectangle,\n textureCoordinateRotationPoints,\n ellipsoid,\n frameState.mapProjection,\n this._maxHeight\n );\n } else {\n attributes = ShadowVolumeAppearance.getSphericalExtentGeometryInstanceAttributes(\n boundingRectangle,\n textureCoordinateRotationPoints,\n ellipsoid,\n frameState.mapProjection\n );\n }\n\n const instanceAttributes = instance.attributes;\n for (const attributeKey in instanceAttributes) {\n if (instanceAttributes.hasOwnProperty(attributeKey)) {\n attributes[attributeKey] = instanceAttributes[attributeKey];\n }\n }\n\n groundInstances[i] = new GeometryInstance({\n geometry: instanceType.createShadowVolume(\n geometry,\n getComputeMinimumHeightFunction(this),\n getComputeMaximumHeightFunction(this)\n ),\n attributes: attributes,\n id: instance.id,\n });\n }\n } else {\n // ClassificationPrimitive will check if the colors are all the same if it detects lack of fragment culling attributes\n for (i = 0; i < length; ++i) {\n instance = instances[i];\n geometry = instance.geometry;\n instanceType = geometry.constructor;\n groundInstances[i] = new GeometryInstance({\n geometry: instanceType.createShadowVolume(\n geometry,\n getComputeMinimumHeightFunction(this),\n getComputeMaximumHeightFunction(this)\n ),\n attributes: instance.attributes,\n id: instance.id,\n });\n }\n }\n\n primitiveOptions.geometryInstances = groundInstances;\n primitiveOptions.appearance = this.appearance;\n\n primitiveOptions._createBoundingVolumeFunction = function (\n frameState,\n geometry\n ) {\n createBoundingVolume(that, frameState, geometry);\n };\n primitiveOptions._updateAndQueueCommandsFunction = function (\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n ) {\n updateAndQueueCommands(\n that,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n );\n };\n\n this._primitive = new ClassificationPrimitive(primitiveOptions);\n }\n\n this._primitive.appearance = this.appearance;\n this._primitive.show = this.show;\n this._primitive.debugShowShadowVolume = this.debugShowShadowVolume;\n this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume;\n this._primitive.update(frameState);\n\n frameState.afterRender.push(() => {\n if (!this._ready && defined(this._primitive) && this._primitive.ready) {\n this._ready = true;\n\n if (this.releaseGeometryInstances) {\n this.geometryInstances = undefined;\n }\n }\n });\n};\n\n/**\n * @private\n */\nGroundPrimitive.prototype.getBoundingSphere = function (id) {\n const index = this._boundingSpheresKeys.indexOf(id);\n if (index !== -1) {\n return this._boundingSpheres[index];\n }\n\n return undefined;\n};\n\n/**\n * Returns the modifiable per-instance attributes for a {@link GeometryInstance}.\n *\n * @param {*} id The id of the {@link GeometryInstance}.\n * @returns {object} The typed array in the attribute's format or undefined if the is no instance with id.\n *\n * @exception {DeveloperError} must call update before calling getGeometryInstanceAttributes.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);\n * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);\n */\nGroundPrimitive.prototype.getGeometryInstanceAttributes = function (id) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(this._primitive)) {\n throw new DeveloperError(\n \"must call update before calling getGeometryInstanceAttributes\"\n );\n }\n //>>includeEnd('debug');\n return this._primitive.getGeometryInstanceAttributes(id);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see GroundPrimitive#destroy\n */\nGroundPrimitive.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * e = e && e.destroy();\n *\n * @see GroundPrimitive#isDestroyed\n */\nGroundPrimitive.prototype.destroy = function () {\n this._primitive = this._primitive && this._primitive.destroy();\n return destroyObject(this);\n};\n\n/**\n * Exposed for testing.\n *\n * @param {Context} context Rendering context\n * @returns {boolean} Whether or not the current context supports materials on GroundPrimitives.\n * @private\n */\nGroundPrimitive._supportsMaterials = function (context) {\n return context.depthTexture;\n};\n\n/**\n * Checks if the given Scene supports materials on GroundPrimitives.\n * Materials on GroundPrimitives require support for the WEBGL_depth_texture extension.\n *\n * @param {Scene} scene The current scene.\n * @returns {boolean} Whether or not the current scene supports materials on GroundPrimitives.\n */\nGroundPrimitive.supportsMaterials = function (scene) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"scene\", scene);\n //>>includeEnd('debug');\n\n return GroundPrimitive._supportsMaterials(scene.frameState.context);\n};\nexport default GroundPrimitive;\n", "import Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Material from \"../Scene/Material.js\";\n\n/**\n * The interface for all {@link Property} objects that represent {@link Material} uniforms.\n * This type defines an interface and cannot be instantiated directly.\n *\n * @alias MaterialProperty\n * @constructor\n * @abstract\n *\n * @see ColorMaterialProperty\n * @see CompositeMaterialProperty\n * @see GridMaterialProperty\n * @see ImageMaterialProperty\n * @see PolylineGlowMaterialProperty\n * @see PolylineOutlineMaterialProperty\n * @see StripeMaterialProperty\n */\nfunction MaterialProperty() {\n DeveloperError.throwInstantiationError();\n}\n\nObject.defineProperties(MaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof MaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof MaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: DeveloperError.throwInstantiationError,\n },\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n * @function\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nMaterialProperty.prototype.getType = DeveloperError.throwInstantiationError;\n\n/**\n * Gets the value of the property at the provided time.\n * @function\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nMaterialProperty.prototype.getValue = DeveloperError.throwInstantiationError;\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n * @function\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nMaterialProperty.prototype.equals = DeveloperError.throwInstantiationError;\n\n/**\n * @private\n */\nMaterialProperty.getValue = function (time, materialProperty, material) {\n let type;\n\n if (defined(materialProperty)) {\n type = materialProperty.getType(time);\n if (defined(type)) {\n if (!defined(material) || material.type !== type) {\n material = Material.fromType(type);\n }\n materialProperty.getValue(time, material.uniforms);\n return material;\n }\n }\n\n if (!defined(material) || material.type !== Material.ColorType) {\n material = Material.fromType(Material.ColorType);\n }\n Color.clone(Color.WHITE, material.uniforms.color);\n\n return material;\n};\nexport default MaterialProperty;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport Primitive from \"../Scene/Primitive.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\n/**\n * Defines the interface for a dynamic geometry updater. A DynamicGeometryUpdater\n * is responsible for handling visualization of a specific type of geometry\n * that needs to be recomputed based on simulation time.\n * This object is never used directly by client code, but is instead created by\n * {@link GeometryUpdater} implementations which contain dynamic geometry.\n *\n * This type defines an interface and cannot be instantiated directly.\n *\n * @alias DynamicGeometryUpdater\n * @constructor\n * @private\n * @abstract\n */\nfunction DynamicGeometryUpdater(\n geometryUpdater,\n primitives,\n orderedGroundPrimitives\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"geometryUpdater\", geometryUpdater);\n Check.defined(\"primitives\", primitives);\n Check.defined(\"orderedGroundPrimitives\", orderedGroundPrimitives);\n //>>includeEnd('debug');\n\n this._primitives = primitives;\n this._orderedGroundPrimitives = orderedGroundPrimitives;\n this._primitive = undefined;\n this._outlinePrimitive = undefined;\n this._geometryUpdater = geometryUpdater;\n this._options = geometryUpdater._options;\n this._entity = geometryUpdater._entity;\n this._material = undefined;\n}\n\nDynamicGeometryUpdater.prototype._isHidden = function (entity, geometry, time) {\n return (\n !entity.isShowing ||\n !entity.isAvailable(time) ||\n !Property.getValueOrDefault(geometry.show, time, true)\n );\n};\n\nDynamicGeometryUpdater.prototype._setOptions =\n DeveloperError.throwInstantiationError;\n\n/**\n * Updates the geometry to the specified time.\n * @memberof DynamicGeometryUpdater\n * @function\n *\n * @param {JulianDate} time The current time.\n */\nDynamicGeometryUpdater.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const geometryUpdater = this._geometryUpdater;\n const onTerrain = geometryUpdater._onTerrain;\n\n const primitives = this._primitives;\n const orderedGroundPrimitives = this._orderedGroundPrimitives;\n if (onTerrain) {\n orderedGroundPrimitives.remove(this._primitive);\n } else {\n primitives.removeAndDestroy(this._primitive);\n primitives.removeAndDestroy(this._outlinePrimitive);\n this._outlinePrimitive = undefined;\n }\n this._primitive = undefined;\n\n const entity = this._entity;\n const geometry = entity[this._geometryUpdater._geometryPropertyName];\n this._setOptions(entity, geometry, time);\n if (this._isHidden(entity, geometry, time)) {\n return;\n }\n\n const shadows = this._geometryUpdater.shadowsProperty.getValue(time);\n const options = this._options;\n if (!defined(geometry.fill) || geometry.fill.getValue(time)) {\n const fillMaterialProperty = geometryUpdater.fillMaterialProperty;\n const isColorAppearance =\n fillMaterialProperty instanceof ColorMaterialProperty;\n let appearance;\n const closed = geometryUpdater._getIsClosed(options);\n if (isColorAppearance) {\n appearance = new PerInstanceColorAppearance({\n closed: closed,\n flat:\n onTerrain && !geometryUpdater._supportsMaterialsforEntitiesOnTerrain,\n });\n } else {\n const material = MaterialProperty.getValue(\n time,\n fillMaterialProperty,\n this._material\n );\n this._material = material;\n appearance = new MaterialAppearance({\n material: material,\n translucent: material.isTranslucent(),\n closed: closed,\n });\n }\n\n if (onTerrain) {\n options.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT;\n this._primitive = orderedGroundPrimitives.add(\n new GroundPrimitive({\n geometryInstances: this._geometryUpdater.createFillGeometryInstance(\n time\n ),\n appearance: appearance,\n asynchronous: false,\n shadows: shadows,\n classificationType: this._geometryUpdater.classificationTypeProperty.getValue(\n time\n ),\n }),\n Property.getValueOrUndefined(this._geometryUpdater.zIndex, time)\n );\n } else {\n options.vertexFormat = appearance.vertexFormat;\n\n const fillInstance = this._geometryUpdater.createFillGeometryInstance(\n time\n );\n\n if (isColorAppearance) {\n appearance.translucent = fillInstance.attributes.color.value[3] !== 255;\n }\n\n this._primitive = primitives.add(\n new Primitive({\n geometryInstances: fillInstance,\n appearance: appearance,\n asynchronous: false,\n shadows: shadows,\n })\n );\n }\n }\n\n if (\n !onTerrain &&\n defined(geometry.outline) &&\n geometry.outline.getValue(time)\n ) {\n const outlineInstance = this._geometryUpdater.createOutlineGeometryInstance(\n time\n );\n const outlineWidth = Property.getValueOrDefault(\n geometry.outlineWidth,\n time,\n 1.0\n );\n\n this._outlinePrimitive = primitives.add(\n new Primitive({\n geometryInstances: outlineInstance,\n appearance: new PerInstanceColorAppearance({\n flat: true,\n translucent: outlineInstance.attributes.color.value[3] !== 255,\n renderState: {\n lineWidth: geometryUpdater._scene.clampLineWidth(outlineWidth),\n },\n }),\n asynchronous: false,\n shadows: shadows,\n })\n );\n }\n};\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n * @function\n *\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nDynamicGeometryUpdater.prototype.getBoundingSphere = function (result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n const entity = this._entity;\n const primitive = this._primitive;\n const outlinePrimitive = this._outlinePrimitive;\n\n let attributes;\n\n //Outline and Fill geometries have the same bounding sphere, so just use whichever one is defined and ready\n if (defined(primitive) && primitive.show && primitive.ready) {\n attributes = primitive.getGeometryInstanceAttributes(entity);\n if (defined(attributes) && defined(attributes.boundingSphere)) {\n BoundingSphere.clone(attributes.boundingSphere, result);\n return BoundingSphereState.DONE;\n }\n }\n\n if (\n defined(outlinePrimitive) &&\n outlinePrimitive.show &&\n outlinePrimitive.ready\n ) {\n attributes = outlinePrimitive.getGeometryInstanceAttributes(entity);\n if (defined(attributes) && defined(attributes.boundingSphere)) {\n BoundingSphere.clone(attributes.boundingSphere, result);\n return BoundingSphereState.DONE;\n }\n }\n\n if (\n (defined(primitive) && !primitive.ready) ||\n (defined(outlinePrimitive) && !outlinePrimitive.ready)\n ) {\n return BoundingSphereState.PENDING;\n }\n\n return BoundingSphereState.FAILED;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n * @memberof DynamicGeometryUpdater\n * @function\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nDynamicGeometryUpdater.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys and resources used by the object. Once an object is destroyed, it should not be used.\n * @memberof DynamicGeometryUpdater\n * @function\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nDynamicGeometryUpdater.prototype.destroy = function () {\n const primitives = this._primitives;\n const orderedGroundPrimitives = this._orderedGroundPrimitives;\n if (this._geometryUpdater._onTerrain) {\n orderedGroundPrimitives.remove(this._primitive);\n } else {\n primitives.removeAndDestroy(this._primitive);\n }\n primitives.removeAndDestroy(this._outlinePrimitive);\n destroyObject(this);\n};\nexport default DynamicGeometryUpdater;\n", "/**\n * ArcType defines the path that should be taken connecting vertices.\n *\n * @enum {number}\n */\nconst ArcType = {\n /**\n * Straight line that does not conform to the surface of the ellipsoid.\n *\n * @type {number}\n * @constant\n */\n NONE: 0,\n\n /**\n * Follow geodesic path.\n *\n * @type {number}\n * @constant\n */\n GEODESIC: 1,\n\n /**\n * Follow rhumb or loxodrome path.\n *\n * @type {number}\n * @constant\n */\n RHUMB: 2,\n};\nexport default Object.freeze(ArcType);\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst removeDuplicatesEpsilon = CesiumMath.EPSILON10;\n\n/**\n * Removes adjacent duplicate values in an array of values.\n *\n * @param {any[]} [values] The array of values.\n * @param {Function} equalsEpsilon Function to compare values with an epsilon. Boolean equalsEpsilon(left, right, epsilon).\n * @param {boolean} [wrapAround=false] Compare the last value in the array against the first value. If they are equal, the last value is removed.\n * @param {number[]} [removedIndices=undefined] Store the indices that correspond to the duplicate items removed from the array, if there were any.\n * @returns {any[]|undefined} A new array of values with no adjacent duplicate values or the input array if no duplicates were found.\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0), (1.0, 1.0, 1.0)]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon);\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);\n *\n * @example\n * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]\n * // removedIndices will be equal to [1, 3, 5]\n * const values = [\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(2.0, 2.0, 2.0),\n * new Cesium.Cartesian3(3.0, 3.0, 3.0),\n * new Cesium.Cartesian3(1.0, 1.0, 1.0)];\n * const nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);\n * @private\n */\nfunction arrayRemoveDuplicates(\n values,\n equalsEpsilon,\n wrapAround,\n removedIndices\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"equalsEpsilon\", equalsEpsilon);\n //>>includeEnd('debug');\n\n if (!defined(values)) {\n return undefined;\n }\n\n wrapAround = defaultValue(wrapAround, false);\n const storeRemovedIndices = defined(removedIndices);\n\n const length = values.length;\n if (length < 2) {\n return values;\n }\n\n let i;\n let v0 = values[0];\n let v1;\n\n // We only want to create a new array if there are duplicates in the array.\n // As such, cleanedValues is undefined until it encounters the first duplicate, if it exists.\n let cleanedValues;\n let lastCleanIndex = 0;\n\n // removedIndexLCI keeps track of where lastCleanIndex would be if it were sorted into the removedIndices array.\n // In case of arrays such as [A, B, C, ..., A, A, A], removedIndices will not be sorted properly without this.\n let removedIndexLCI = -1;\n\n for (i = 1; i < length; ++i) {\n v1 = values[i];\n if (equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {\n if (!defined(cleanedValues)) {\n cleanedValues = values.slice(0, i);\n lastCleanIndex = i - 1;\n removedIndexLCI = 0;\n }\n if (storeRemovedIndices) {\n removedIndices.push(i);\n }\n } else {\n if (defined(cleanedValues)) {\n cleanedValues.push(v1);\n lastCleanIndex = i;\n if (storeRemovedIndices) {\n removedIndexLCI = removedIndices.length;\n }\n }\n v0 = v1;\n }\n }\n\n if (\n wrapAround &&\n equalsEpsilon(values[0], values[length - 1], removeDuplicatesEpsilon)\n ) {\n if (storeRemovedIndices) {\n if (defined(cleanedValues)) {\n removedIndices.splice(removedIndexLCI, 0, lastCleanIndex);\n } else {\n removedIndices.push(length - 1);\n }\n }\n\n if (defined(cleanedValues)) {\n cleanedValues.length -= 1;\n } else {\n cleanedValues = values.slice(0, -1);\n }\n }\n\n return defined(cleanedValues) ? cleanedValues : values;\n}\n\nexport default arrayRemoveDuplicates;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport CesiumMath from \"./Math.js\";\n\nfunction setConstants(ellipsoidGeodesic) {\n const uSquared = ellipsoidGeodesic._uSquared;\n const a = ellipsoidGeodesic._ellipsoid.maximumRadius;\n const b = ellipsoidGeodesic._ellipsoid.minimumRadius;\n const f = (a - b) / a;\n\n const cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);\n const sineHeading = Math.sin(ellipsoidGeodesic._startHeading);\n\n const tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);\n\n const cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);\n const sineU = cosineU * tanU;\n\n const sigma = Math.atan2(tanU, cosineHeading);\n\n const sineAlpha = cosineU * sineHeading;\n const sineSquaredAlpha = sineAlpha * sineAlpha;\n\n const cosineSquaredAlpha = 1.0 - sineSquaredAlpha;\n const cosineAlpha = Math.sqrt(cosineSquaredAlpha);\n\n const u2Over4 = uSquared / 4.0;\n const u4Over16 = u2Over4 * u2Over4;\n const u6Over64 = u4Over16 * u2Over4;\n const u8Over256 = u4Over16 * u4Over16;\n\n const a0 =\n 1.0 +\n u2Over4 -\n (3.0 * u4Over16) / 4.0 +\n (5.0 * u6Over64) / 4.0 -\n (175.0 * u8Over256) / 64.0;\n const a1 = 1.0 - u2Over4 + (15.0 * u4Over16) / 8.0 - (35.0 * u6Over64) / 8.0;\n const a2 = 1.0 - 3.0 * u2Over4 + (35.0 * u4Over16) / 4.0;\n const a3 = 1.0 - 5.0 * u2Over4;\n\n const distanceRatio =\n a0 * sigma -\n (a1 * Math.sin(2.0 * sigma) * u2Over4) / 2.0 -\n (a2 * Math.sin(4.0 * sigma) * u4Over16) / 16.0 -\n (a3 * Math.sin(6.0 * sigma) * u6Over64) / 48.0 -\n (Math.sin(8.0 * sigma) * 5.0 * u8Over256) / 512;\n\n const constants = ellipsoidGeodesic._constants;\n\n constants.a = a;\n constants.b = b;\n constants.f = f;\n constants.cosineHeading = cosineHeading;\n constants.sineHeading = sineHeading;\n constants.tanU = tanU;\n constants.cosineU = cosineU;\n constants.sineU = sineU;\n constants.sigma = sigma;\n constants.sineAlpha = sineAlpha;\n constants.sineSquaredAlpha = sineSquaredAlpha;\n constants.cosineSquaredAlpha = cosineSquaredAlpha;\n constants.cosineAlpha = cosineAlpha;\n constants.u2Over4 = u2Over4;\n constants.u4Over16 = u4Over16;\n constants.u6Over64 = u6Over64;\n constants.u8Over256 = u8Over256;\n constants.a0 = a0;\n constants.a1 = a1;\n constants.a2 = a2;\n constants.a3 = a3;\n constants.distanceRatio = distanceRatio;\n}\n\nfunction computeC(f, cosineSquaredAlpha) {\n return (\n (f * cosineSquaredAlpha * (4.0 + f * (4.0 - 3.0 * cosineSquaredAlpha))) /\n 16.0\n );\n}\n\nfunction computeDeltaLambda(\n f,\n sineAlpha,\n cosineSquaredAlpha,\n sigma,\n sineSigma,\n cosineSigma,\n cosineTwiceSigmaMidpoint\n) {\n const C = computeC(f, cosineSquaredAlpha);\n\n return (\n (1.0 - C) *\n f *\n sineAlpha *\n (sigma +\n C *\n sineSigma *\n (cosineTwiceSigmaMidpoint +\n C *\n cosineSigma *\n (2.0 * cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint - 1.0)))\n );\n}\n\nfunction vincentyInverseFormula(\n ellipsoidGeodesic,\n major,\n minor,\n firstLongitude,\n firstLatitude,\n secondLongitude,\n secondLatitude\n) {\n const eff = (major - minor) / major;\n const l = secondLongitude - firstLongitude;\n\n const u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));\n const u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));\n\n const cosineU1 = Math.cos(u1);\n const sineU1 = Math.sin(u1);\n const cosineU2 = Math.cos(u2);\n const sineU2 = Math.sin(u2);\n\n const cc = cosineU1 * cosineU2;\n const cs = cosineU1 * sineU2;\n const ss = sineU1 * sineU2;\n const sc = sineU1 * cosineU2;\n\n let lambda = l;\n let lambdaDot = CesiumMath.TWO_PI;\n\n let cosineLambda = Math.cos(lambda);\n let sineLambda = Math.sin(lambda);\n\n let sigma;\n let cosineSigma;\n let sineSigma;\n let cosineSquaredAlpha;\n let cosineTwiceSigmaMidpoint;\n\n do {\n cosineLambda = Math.cos(lambda);\n sineLambda = Math.sin(lambda);\n\n const temp = cs - sc * cosineLambda;\n sineSigma = Math.sqrt(\n cosineU2 * cosineU2 * sineLambda * sineLambda + temp * temp\n );\n cosineSigma = ss + cc * cosineLambda;\n\n sigma = Math.atan2(sineSigma, cosineSigma);\n\n let sineAlpha;\n\n if (sineSigma === 0.0) {\n sineAlpha = 0.0;\n cosineSquaredAlpha = 1.0;\n } else {\n sineAlpha = (cc * sineLambda) / sineSigma;\n cosineSquaredAlpha = 1.0 - sineAlpha * sineAlpha;\n }\n\n lambdaDot = lambda;\n\n cosineTwiceSigmaMidpoint = cosineSigma - (2.0 * ss) / cosineSquaredAlpha;\n\n if (!isFinite(cosineTwiceSigmaMidpoint)) {\n cosineTwiceSigmaMidpoint = 0.0;\n }\n\n lambda =\n l +\n computeDeltaLambda(\n eff,\n sineAlpha,\n cosineSquaredAlpha,\n sigma,\n sineSigma,\n cosineSigma,\n cosineTwiceSigmaMidpoint\n );\n } while (Math.abs(lambda - lambdaDot) > CesiumMath.EPSILON12);\n\n const uSquared =\n (cosineSquaredAlpha * (major * major - minor * minor)) / (minor * minor);\n const A =\n 1.0 +\n (uSquared *\n (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0))) /\n 16384.0;\n const B =\n (uSquared *\n (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0))) /\n 1024.0;\n\n const cosineSquaredTwiceSigmaMidpoint =\n cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;\n const deltaSigma =\n B *\n sineSigma *\n (cosineTwiceSigmaMidpoint +\n (B *\n (cosineSigma * (2.0 * cosineSquaredTwiceSigmaMidpoint - 1.0) -\n (B *\n cosineTwiceSigmaMidpoint *\n (4.0 * sineSigma * sineSigma - 3.0) *\n (4.0 * cosineSquaredTwiceSigmaMidpoint - 3.0)) /\n 6.0)) /\n 4.0);\n\n const distance = minor * A * (sigma - deltaSigma);\n\n const startHeading = Math.atan2(\n cosineU2 * sineLambda,\n cs - sc * cosineLambda\n );\n const endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);\n\n ellipsoidGeodesic._distance = distance;\n ellipsoidGeodesic._startHeading = startHeading;\n ellipsoidGeodesic._endHeading = endHeading;\n ellipsoidGeodesic._uSquared = uSquared;\n}\n\nconst scratchCart1 = new Cartesian3();\nconst scratchCart2 = new Cartesian3();\nfunction computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {\n const firstCartesian = Cartesian3.normalize(\n ellipsoid.cartographicToCartesian(start, scratchCart2),\n scratchCart1\n );\n const lastCartesian = Cartesian3.normalize(\n ellipsoid.cartographicToCartesian(end, scratchCart2),\n scratchCart2\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\n \"value\",\n Math.abs(\n Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI\n ),\n 0.0125\n );\n //>>includeEnd('debug');\n\n vincentyInverseFormula(\n ellipsoidGeodesic,\n ellipsoid.maximumRadius,\n ellipsoid.minimumRadius,\n start.longitude,\n start.latitude,\n end.longitude,\n end.latitude\n );\n\n ellipsoidGeodesic._start = Cartographic.clone(\n start,\n ellipsoidGeodesic._start\n );\n ellipsoidGeodesic._end = Cartographic.clone(end, ellipsoidGeodesic._end);\n ellipsoidGeodesic._start.height = 0;\n ellipsoidGeodesic._end.height = 0;\n\n setConstants(ellipsoidGeodesic);\n}\n\n/**\n * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.\n *\n * @alias EllipsoidGeodesic\n * @constructor\n *\n * @param {Cartographic} [start] The initial planetodetic point on the path.\n * @param {Cartographic} [end] The final planetodetic point on the path.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.\n */\nfunction EllipsoidGeodesic(start, end, ellipsoid) {\n const e = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._ellipsoid = e;\n this._start = new Cartographic();\n this._end = new Cartographic();\n\n this._constants = {};\n this._startHeading = undefined;\n this._endHeading = undefined;\n this._distance = undefined;\n this._uSquared = undefined;\n\n if (defined(start) && defined(end)) {\n computeProperties(this, start, end, e);\n }\n}\n\nObject.defineProperties(EllipsoidGeodesic.prototype, {\n /**\n * Gets the ellipsoid.\n * @memberof EllipsoidGeodesic.prototype\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n\n /**\n * Gets the surface distance between the start and end point\n * @memberof EllipsoidGeodesic.prototype\n * @type {number}\n * @readonly\n */\n surfaceDistance: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n return this._distance;\n },\n },\n\n /**\n * Gets the initial planetodetic point on the path.\n * @memberof EllipsoidGeodesic.prototype\n * @type {Cartographic}\n * @readonly\n */\n start: {\n get: function () {\n return this._start;\n },\n },\n\n /**\n * Gets the final planetodetic point on the path.\n * @memberof EllipsoidGeodesic.prototype\n * @type {Cartographic}\n * @readonly\n */\n end: {\n get: function () {\n return this._end;\n },\n },\n\n /**\n * Gets the heading at the initial point.\n * @memberof EllipsoidGeodesic.prototype\n * @type {number}\n * @readonly\n */\n startHeading: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n return this._startHeading;\n },\n },\n\n /**\n * Gets the heading at the final point.\n * @memberof EllipsoidGeodesic.prototype\n * @type {number}\n * @readonly\n */\n endHeading: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n return this._endHeading;\n },\n },\n});\n\n/**\n * Sets the start and end points of the geodesic\n *\n * @param {Cartographic} start The initial planetodetic point on the path.\n * @param {Cartographic} end The final planetodetic point on the path.\n */\nEllipsoidGeodesic.prototype.setEndPoints = function (start, end) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"start\", start);\n Check.defined(\"end\", end);\n //>>includeEnd('debug');\n\n computeProperties(this, start, end, this._ellipsoid);\n};\n\n/**\n * Provides the location of a point at the indicated portion along the geodesic.\n *\n * @param {number} fraction The portion of the distance between the initial and final points.\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the point along the geodesic.\n */\nEllipsoidGeodesic.prototype.interpolateUsingFraction = function (\n fraction,\n result\n) {\n return this.interpolateUsingSurfaceDistance(\n this._distance * fraction,\n result\n );\n};\n\n/**\n * Provides the location of a point at the indicated distance along the geodesic.\n *\n * @param {number} distance The distance from the inital point to the point of interest along the geodesic\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the point along the geodesic.\n *\n * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance\n */\nEllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function (\n distance,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n const constants = this._constants;\n\n const s = constants.distanceRatio + distance / constants.b;\n\n const cosine2S = Math.cos(2.0 * s);\n const cosine4S = Math.cos(4.0 * s);\n const cosine6S = Math.cos(6.0 * s);\n const sine2S = Math.sin(2.0 * s);\n const sine4S = Math.sin(4.0 * s);\n const sine6S = Math.sin(6.0 * s);\n const sine8S = Math.sin(8.0 * s);\n\n const s2 = s * s;\n const s3 = s * s2;\n\n const u8Over256 = constants.u8Over256;\n const u2Over4 = constants.u2Over4;\n const u6Over64 = constants.u6Over64;\n const u4Over16 = constants.u4Over16;\n let sigma =\n (2.0 * s3 * u8Over256 * cosine2S) / 3.0 +\n s *\n (1.0 -\n u2Over4 +\n (7.0 * u4Over16) / 4.0 -\n (15.0 * u6Over64) / 4.0 +\n (579.0 * u8Over256) / 64.0 -\n (u4Over16 - (15.0 * u6Over64) / 4.0 + (187.0 * u8Over256) / 16.0) *\n cosine2S -\n ((5.0 * u6Over64) / 4.0 - (115.0 * u8Over256) / 16.0) * cosine4S -\n (29.0 * u8Over256 * cosine6S) / 16.0) +\n (u2Over4 / 2.0 -\n u4Over16 +\n (71.0 * u6Over64) / 32.0 -\n (85.0 * u8Over256) / 16.0) *\n sine2S +\n ((5.0 * u4Over16) / 16.0 -\n (5.0 * u6Over64) / 4.0 +\n (383.0 * u8Over256) / 96.0) *\n sine4S -\n s2 *\n ((u6Over64 - (11.0 * u8Over256) / 2.0) * sine2S +\n (5.0 * u8Over256 * sine4S) / 2.0) +\n ((29.0 * u6Over64) / 96.0 - (29.0 * u8Over256) / 16.0) * sine6S +\n (539.0 * u8Over256 * sine8S) / 1536.0;\n\n const theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);\n const latitude = Math.atan((constants.a / constants.b) * Math.tan(theta));\n\n // Redefine in terms of relative argument of latitude.\n sigma = sigma - constants.sigma;\n\n const cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);\n\n const sineSigma = Math.sin(sigma);\n const cosineSigma = Math.cos(sigma);\n\n const cc = constants.cosineU * cosineSigma;\n const ss = constants.sineU * sineSigma;\n\n const lambda = Math.atan2(\n sineSigma * constants.sineHeading,\n cc - ss * constants.cosineHeading\n );\n\n const l =\n lambda -\n computeDeltaLambda(\n constants.f,\n constants.sineAlpha,\n constants.cosineSquaredAlpha,\n sigma,\n sineSigma,\n cosineSigma,\n cosineTwiceSigmaMidpoint\n );\n\n if (defined(result)) {\n result.longitude = this._start.longitude + l;\n result.latitude = latitude;\n result.height = 0.0;\n return result;\n }\n\n return new Cartographic(this._start.longitude + l, latitude, 0.0);\n};\nexport default EllipsoidGeodesic;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport CesiumMath from \"./Math.js\";\n\nfunction calculateM(ellipticity, major, latitude) {\n if (ellipticity === 0.0) {\n // sphere\n return major * latitude;\n }\n\n const e2 = ellipticity * ellipticity;\n const e4 = e2 * e2;\n const e6 = e4 * e2;\n const e8 = e6 * e2;\n const e10 = e8 * e2;\n const e12 = e10 * e2;\n const phi = latitude;\n const sin2Phi = Math.sin(2 * phi);\n const sin4Phi = Math.sin(4 * phi);\n const sin6Phi = Math.sin(6 * phi);\n const sin8Phi = Math.sin(8 * phi);\n const sin10Phi = Math.sin(10 * phi);\n const sin12Phi = Math.sin(12 * phi);\n\n return (\n major *\n ((1 -\n e2 / 4 -\n (3 * e4) / 64 -\n (5 * e6) / 256 -\n (175 * e8) / 16384 -\n (441 * e10) / 65536 -\n (4851 * e12) / 1048576) *\n phi -\n ((3 * e2) / 8 +\n (3 * e4) / 32 +\n (45 * e6) / 1024 +\n (105 * e8) / 4096 +\n (2205 * e10) / 131072 +\n (6237 * e12) / 524288) *\n sin2Phi +\n ((15 * e4) / 256 +\n (45 * e6) / 1024 +\n (525 * e8) / 16384 +\n (1575 * e10) / 65536 +\n (155925 * e12) / 8388608) *\n sin4Phi -\n ((35 * e6) / 3072 +\n (175 * e8) / 12288 +\n (3675 * e10) / 262144 +\n (13475 * e12) / 1048576) *\n sin6Phi +\n ((315 * e8) / 131072 + (2205 * e10) / 524288 + (43659 * e12) / 8388608) *\n sin8Phi -\n ((693 * e10) / 1310720 + (6237 * e12) / 5242880) * sin10Phi +\n ((1001 * e12) / 8388608) * sin12Phi)\n );\n}\n\nfunction calculateInverseM(M, ellipticity, major) {\n const d = M / major;\n\n if (ellipticity === 0.0) {\n // sphere\n return d;\n }\n\n const d2 = d * d;\n const d3 = d2 * d;\n const d4 = d3 * d;\n const e = ellipticity;\n const e2 = e * e;\n const e4 = e2 * e2;\n const e6 = e4 * e2;\n const e8 = e6 * e2;\n const e10 = e8 * e2;\n const e12 = e10 * e2;\n const sin2D = Math.sin(2 * d);\n const cos2D = Math.cos(2 * d);\n const sin4D = Math.sin(4 * d);\n const cos4D = Math.cos(4 * d);\n const sin6D = Math.sin(6 * d);\n const cos6D = Math.cos(6 * d);\n const sin8D = Math.sin(8 * d);\n const cos8D = Math.cos(8 * d);\n const sin10D = Math.sin(10 * d);\n const cos10D = Math.cos(10 * d);\n const sin12D = Math.sin(12 * d);\n\n return (\n d +\n (d * e2) / 4 +\n (7 * d * e4) / 64 +\n (15 * d * e6) / 256 +\n (579 * d * e8) / 16384 +\n (1515 * d * e10) / 65536 +\n (16837 * d * e12) / 1048576 +\n ((3 * d * e4) / 16 +\n (45 * d * e6) / 256 -\n (d * (32 * d2 - 561) * e8) / 4096 -\n (d * (232 * d2 - 1677) * e10) / 16384 +\n (d * (399985 - 90560 * d2 + 512 * d4) * e12) / 5242880) *\n cos2D +\n ((21 * d * e6) / 256 +\n (483 * d * e8) / 4096 -\n (d * (224 * d2 - 1969) * e10) / 16384 -\n (d * (33152 * d2 - 112599) * e12) / 1048576) *\n cos4D +\n ((151 * d * e8) / 4096 +\n (4681 * d * e10) / 65536 +\n (1479 * d * e12) / 16384 -\n (453 * d3 * e12) / 32768) *\n cos6D +\n ((1097 * d * e10) / 65536 + (42783 * d * e12) / 1048576) * cos8D +\n ((8011 * d * e12) / 1048576) * cos10D +\n ((3 * e2) / 8 +\n (3 * e4) / 16 +\n (213 * e6) / 2048 -\n (3 * d2 * e6) / 64 +\n (255 * e8) / 4096 -\n (33 * d2 * e8) / 512 +\n (20861 * e10) / 524288 -\n (33 * d2 * e10) / 512 +\n (d4 * e10) / 1024 +\n (28273 * e12) / 1048576 -\n (471 * d2 * e12) / 8192 +\n (9 * d4 * e12) / 4096) *\n sin2D +\n ((21 * e4) / 256 +\n (21 * e6) / 256 +\n (533 * e8) / 8192 -\n (21 * d2 * e8) / 512 +\n (197 * e10) / 4096 -\n (315 * d2 * e10) / 4096 +\n (584039 * e12) / 16777216 -\n (12517 * d2 * e12) / 131072 +\n (7 * d4 * e12) / 2048) *\n sin4D +\n ((151 * e6) / 6144 +\n (151 * e8) / 4096 +\n (5019 * e10) / 131072 -\n (453 * d2 * e10) / 16384 +\n (26965 * e12) / 786432 -\n (8607 * d2 * e12) / 131072) *\n sin6D +\n ((1097 * e8) / 131072 +\n (1097 * e10) / 65536 +\n (225797 * e12) / 10485760 -\n (1097 * d2 * e12) / 65536) *\n sin8D +\n ((8011 * e10) / 2621440 + (8011 * e12) / 1048576) * sin10D +\n ((293393 * e12) / 251658240) * sin12D\n );\n}\n\nfunction calculateSigma(ellipticity, latitude) {\n if (ellipticity === 0.0) {\n // sphere\n return Math.log(Math.tan(0.5 * (CesiumMath.PI_OVER_TWO + latitude)));\n }\n\n const eSinL = ellipticity * Math.sin(latitude);\n return (\n Math.log(Math.tan(0.5 * (CesiumMath.PI_OVER_TWO + latitude))) -\n (ellipticity / 2.0) * Math.log((1 + eSinL) / (1 - eSinL))\n );\n}\n\nfunction calculateHeading(\n ellipsoidRhumbLine,\n firstLongitude,\n firstLatitude,\n secondLongitude,\n secondLatitude\n) {\n const sigma1 = calculateSigma(ellipsoidRhumbLine._ellipticity, firstLatitude);\n const sigma2 = calculateSigma(\n ellipsoidRhumbLine._ellipticity,\n secondLatitude\n );\n return Math.atan2(\n CesiumMath.negativePiToPi(secondLongitude - firstLongitude),\n sigma2 - sigma1\n );\n}\n\nfunction calculateArcLength(\n ellipsoidRhumbLine,\n major,\n minor,\n firstLongitude,\n firstLatitude,\n secondLongitude,\n secondLatitude\n) {\n const heading = ellipsoidRhumbLine._heading;\n const deltaLongitude = secondLongitude - firstLongitude;\n\n let distance = 0.0;\n\n //Check to see if the rhumb line has constant latitude\n //This equation will diverge if heading gets close to 90 degrees\n if (\n CesiumMath.equalsEpsilon(\n Math.abs(heading),\n CesiumMath.PI_OVER_TWO,\n CesiumMath.EPSILON8\n )\n ) {\n //If heading is close to 90 degrees\n if (major === minor) {\n distance =\n major *\n Math.cos(firstLatitude) *\n CesiumMath.negativePiToPi(deltaLongitude);\n } else {\n const sinPhi = Math.sin(firstLatitude);\n distance =\n (major *\n Math.cos(firstLatitude) *\n CesiumMath.negativePiToPi(deltaLongitude)) /\n Math.sqrt(1 - ellipsoidRhumbLine._ellipticitySquared * sinPhi * sinPhi);\n }\n } else {\n const M1 = calculateM(\n ellipsoidRhumbLine._ellipticity,\n major,\n firstLatitude\n );\n const M2 = calculateM(\n ellipsoidRhumbLine._ellipticity,\n major,\n secondLatitude\n );\n\n distance = (M2 - M1) / Math.cos(heading);\n }\n return Math.abs(distance);\n}\n\nconst scratchCart1 = new Cartesian3();\nconst scratchCart2 = new Cartesian3();\n\nfunction computeProperties(ellipsoidRhumbLine, start, end, ellipsoid) {\n const firstCartesian = Cartesian3.normalize(\n ellipsoid.cartographicToCartesian(start, scratchCart2),\n scratchCart1\n );\n const lastCartesian = Cartesian3.normalize(\n ellipsoid.cartographicToCartesian(end, scratchCart2),\n scratchCart2\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\n \"value\",\n Math.abs(\n Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI\n ),\n 0.0125\n );\n //>>includeEnd('debug');\n\n const major = ellipsoid.maximumRadius;\n const minor = ellipsoid.minimumRadius;\n const majorSquared = major * major;\n const minorSquared = minor * minor;\n ellipsoidRhumbLine._ellipticitySquared =\n (majorSquared - minorSquared) / majorSquared;\n ellipsoidRhumbLine._ellipticity = Math.sqrt(\n ellipsoidRhumbLine._ellipticitySquared\n );\n\n ellipsoidRhumbLine._start = Cartographic.clone(\n start,\n ellipsoidRhumbLine._start\n );\n ellipsoidRhumbLine._start.height = 0;\n\n ellipsoidRhumbLine._end = Cartographic.clone(end, ellipsoidRhumbLine._end);\n ellipsoidRhumbLine._end.height = 0;\n\n ellipsoidRhumbLine._heading = calculateHeading(\n ellipsoidRhumbLine,\n start.longitude,\n start.latitude,\n end.longitude,\n end.latitude\n );\n ellipsoidRhumbLine._distance = calculateArcLength(\n ellipsoidRhumbLine,\n ellipsoid.maximumRadius,\n ellipsoid.minimumRadius,\n start.longitude,\n start.latitude,\n end.longitude,\n end.latitude\n );\n}\n\nfunction interpolateUsingSurfaceDistance(\n start,\n heading,\n distance,\n major,\n ellipticity,\n result\n) {\n if (distance === 0.0) {\n return Cartographic.clone(start, result);\n }\n\n const ellipticitySquared = ellipticity * ellipticity;\n\n let longitude;\n let latitude;\n let deltaLongitude;\n\n //Check to see if the rhumb line has constant latitude\n //This won't converge if heading is close to 90 degrees\n if (\n Math.abs(CesiumMath.PI_OVER_TWO - Math.abs(heading)) > CesiumMath.EPSILON8\n ) {\n //Calculate latitude of the second point\n const M1 = calculateM(ellipticity, major, start.latitude);\n const deltaM = distance * Math.cos(heading);\n const M2 = M1 + deltaM;\n latitude = calculateInverseM(M2, ellipticity, major);\n\n //Now find the longitude of the second point\n const sigma1 = calculateSigma(ellipticity, start.latitude);\n const sigma2 = calculateSigma(ellipticity, latitude);\n deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);\n longitude = CesiumMath.negativePiToPi(start.longitude + deltaLongitude);\n } else {\n //If heading is close to 90 degrees\n latitude = start.latitude;\n let localRad;\n\n if (ellipticity === 0.0) {\n // sphere\n localRad = major * Math.cos(start.latitude);\n } else {\n const sinPhi = Math.sin(start.latitude);\n localRad =\n (major * Math.cos(start.latitude)) /\n Math.sqrt(1 - ellipticitySquared * sinPhi * sinPhi);\n }\n\n deltaLongitude = distance / localRad;\n if (heading > 0.0) {\n longitude = CesiumMath.negativePiToPi(start.longitude + deltaLongitude);\n } else {\n longitude = CesiumMath.negativePiToPi(start.longitude - deltaLongitude);\n }\n }\n\n if (defined(result)) {\n result.longitude = longitude;\n result.latitude = latitude;\n result.height = 0;\n\n return result;\n }\n\n return new Cartographic(longitude, latitude, 0);\n}\n\n/**\n * Initializes a rhumb line on the ellipsoid connecting the two provided planetodetic points.\n *\n * @alias EllipsoidRhumbLine\n * @constructor\n *\n * @param {Cartographic} [start] The initial planetodetic point on the path.\n * @param {Cartographic} [end] The final planetodetic point on the path.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.\n *\n * @exception {DeveloperError} angle between start and end must be at least 0.0125 radians.\n */\nfunction EllipsoidRhumbLine(start, end, ellipsoid) {\n const e = defaultValue(ellipsoid, Ellipsoid.WGS84);\n this._ellipsoid = e;\n this._start = new Cartographic();\n this._end = new Cartographic();\n\n this._heading = undefined;\n this._distance = undefined;\n this._ellipticity = undefined;\n this._ellipticitySquared = undefined;\n\n if (defined(start) && defined(end)) {\n computeProperties(this, start, end, e);\n }\n}\n\nObject.defineProperties(EllipsoidRhumbLine.prototype, {\n /**\n * Gets the ellipsoid.\n * @memberof EllipsoidRhumbLine.prototype\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n\n /**\n * Gets the surface distance between the start and end point\n * @memberof EllipsoidRhumbLine.prototype\n * @type {number}\n * @readonly\n */\n surfaceDistance: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n return this._distance;\n },\n },\n\n /**\n * Gets the initial planetodetic point on the path.\n * @memberof EllipsoidRhumbLine.prototype\n * @type {Cartographic}\n * @readonly\n */\n start: {\n get: function () {\n return this._start;\n },\n },\n\n /**\n * Gets the final planetodetic point on the path.\n * @memberof EllipsoidRhumbLine.prototype\n * @type {Cartographic}\n * @readonly\n */\n end: {\n get: function () {\n return this._end;\n },\n },\n\n /**\n * Gets the heading from the start point to the end point.\n * @memberof EllipsoidRhumbLine.prototype\n * @type {number}\n * @readonly\n */\n heading: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"distance\", this._distance);\n //>>includeEnd('debug');\n\n return this._heading;\n },\n },\n});\n\n/**\n * Create a rhumb line using an initial position with a heading and distance.\n *\n * @param {Cartographic} start The initial planetodetic point on the path.\n * @param {number} heading The heading in radians.\n * @param {number} distance The rhumb line distance between the start and end point.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rhumb line lies.\n * @param {EllipsoidRhumbLine} [result] The object in which to store the result.\n * @returns {EllipsoidRhumbLine} The EllipsoidRhumbLine object.\n */\nEllipsoidRhumbLine.fromStartHeadingDistance = function (\n start,\n heading,\n distance,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"start\", start);\n Check.defined(\"heading\", heading);\n Check.defined(\"distance\", distance);\n Check.typeOf.number.greaterThan(\"distance\", distance, 0.0);\n //>>includeEnd('debug');\n\n const e = defaultValue(ellipsoid, Ellipsoid.WGS84);\n const major = e.maximumRadius;\n const minor = e.minimumRadius;\n const majorSquared = major * major;\n const minorSquared = minor * minor;\n const ellipticity = Math.sqrt((majorSquared - minorSquared) / majorSquared);\n\n heading = CesiumMath.negativePiToPi(heading);\n const end = interpolateUsingSurfaceDistance(\n start,\n heading,\n distance,\n e.maximumRadius,\n ellipticity\n );\n\n if (\n !defined(result) ||\n (defined(ellipsoid) && !ellipsoid.equals(result.ellipsoid))\n ) {\n return new EllipsoidRhumbLine(start, end, e);\n }\n\n result.setEndPoints(start, end);\n return result;\n};\n\n/**\n * Sets the start and end points of the rhumb line.\n *\n * @param {Cartographic} start The initial planetodetic point on the path.\n * @param {Cartographic} end The final planetodetic point on the path.\n */\nEllipsoidRhumbLine.prototype.setEndPoints = function (start, end) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"start\", start);\n Check.defined(\"end\", end);\n //>>includeEnd('debug');\n\n computeProperties(this, start, end, this._ellipsoid);\n};\n\n/**\n * Provides the location of a point at the indicated portion along the rhumb line.\n *\n * @param {number} fraction The portion of the distance between the initial and final points.\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the point along the rhumb line.\n */\nEllipsoidRhumbLine.prototype.interpolateUsingFraction = function (\n fraction,\n result\n) {\n return this.interpolateUsingSurfaceDistance(\n fraction * this._distance,\n result\n );\n};\n\n/**\n * Provides the location of a point at the indicated distance along the rhumb line.\n *\n * @param {number} distance The distance from the inital point to the point of interest along the rhumbLine.\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the point along the rhumb line.\n *\n * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance\n */\nEllipsoidRhumbLine.prototype.interpolateUsingSurfaceDistance = function (\n distance,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"distance\", distance);\n if (!defined(this._distance) || this._distance === 0.0) {\n throw new DeveloperError(\n \"EllipsoidRhumbLine must have distinct start and end set.\"\n );\n }\n //>>includeEnd('debug');\n\n return interpolateUsingSurfaceDistance(\n this._start,\n this._heading,\n distance,\n this._ellipsoid.maximumRadius,\n this._ellipticity,\n result\n );\n};\n\n/**\n * Provides the location of a point at the indicated longitude along the rhumb line.\n * If the longitude is outside the range of start and end points, the first intersection with the longitude from the start point in the direction of the heading is returned. This follows the spiral property of a rhumb line.\n *\n * @param {number} intersectionLongitude The longitude, in radians, at which to find the intersection point from the starting point using the heading.\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.\n *\n * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.\n */\nEllipsoidRhumbLine.prototype.findIntersectionWithLongitude = function (\n intersectionLongitude,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"intersectionLongitude\", intersectionLongitude);\n if (!defined(this._distance) || this._distance === 0.0) {\n throw new DeveloperError(\n \"EllipsoidRhumbLine must have distinct start and end set.\"\n );\n }\n //>>includeEnd('debug');\n\n const ellipticity = this._ellipticity;\n const heading = this._heading;\n const absHeading = Math.abs(heading);\n const start = this._start;\n\n intersectionLongitude = CesiumMath.negativePiToPi(intersectionLongitude);\n\n if (\n CesiumMath.equalsEpsilon(\n Math.abs(intersectionLongitude),\n Math.PI,\n CesiumMath.EPSILON14\n )\n ) {\n intersectionLongitude = CesiumMath.sign(start.longitude) * Math.PI;\n }\n\n if (!defined(result)) {\n result = new Cartographic();\n }\n\n // If heading is -PI/2 or PI/2, this is an E-W rhumb line\n // If heading is 0 or PI, this is an N-S rhumb line\n if (Math.abs(CesiumMath.PI_OVER_TWO - absHeading) <= CesiumMath.EPSILON8) {\n result.longitude = intersectionLongitude;\n result.latitude = start.latitude;\n result.height = 0;\n return result;\n } else if (\n CesiumMath.equalsEpsilon(\n Math.abs(CesiumMath.PI_OVER_TWO - absHeading),\n CesiumMath.PI_OVER_TWO,\n CesiumMath.EPSILON8\n )\n ) {\n if (\n CesiumMath.equalsEpsilon(\n intersectionLongitude,\n start.longitude,\n CesiumMath.EPSILON12\n )\n ) {\n return undefined;\n }\n\n result.longitude = intersectionLongitude;\n result.latitude =\n CesiumMath.PI_OVER_TWO *\n CesiumMath.sign(CesiumMath.PI_OVER_TWO - heading);\n result.height = 0;\n return result;\n }\n\n // Use iterative solver from Equation 9 from http://edwilliams.org/ellipsoid/ellipsoid.pdf\n const phi1 = start.latitude;\n const eSinPhi1 = ellipticity * Math.sin(phi1);\n const leftComponent =\n Math.tan(0.5 * (CesiumMath.PI_OVER_TWO + phi1)) *\n Math.exp((intersectionLongitude - start.longitude) / Math.tan(heading));\n const denominator = (1 + eSinPhi1) / (1 - eSinPhi1);\n\n let newPhi = start.latitude;\n let phi;\n do {\n phi = newPhi;\n const eSinPhi = ellipticity * Math.sin(phi);\n const numerator = (1 + eSinPhi) / (1 - eSinPhi);\n newPhi =\n 2 *\n Math.atan(\n leftComponent * Math.pow(numerator / denominator, ellipticity / 2)\n ) -\n CesiumMath.PI_OVER_TWO;\n } while (!CesiumMath.equalsEpsilon(newPhi, phi, CesiumMath.EPSILON12));\n\n result.longitude = intersectionLongitude;\n result.latitude = newPhi;\n result.height = 0;\n return result;\n};\n\n/**\n * Provides the location of a point at the indicated latitude along the rhumb line.\n * If the latitude is outside the range of start and end points, the first intersection with the latitude from that start point in the direction of the heading is returned. This follows the spiral property of a rhumb line.\n *\n * @param {number} intersectionLatitude The latitude, in radians, at which to find the intersection point from the starting point using the heading.\n * @param {Cartographic} [result] The object in which to store the result.\n * @returns {Cartographic} The location of the intersection point along the rhumb line, undefined if there is no intersection or infinite intersections.\n *\n * @exception {DeveloperError} start and end must be set before calling function findIntersectionWithLongitude.\n */\nEllipsoidRhumbLine.prototype.findIntersectionWithLatitude = function (\n intersectionLatitude,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"intersectionLatitude\", intersectionLatitude);\n if (!defined(this._distance) || this._distance === 0.0) {\n throw new DeveloperError(\n \"EllipsoidRhumbLine must have distinct start and end set.\"\n );\n }\n //>>includeEnd('debug');\n\n const ellipticity = this._ellipticity;\n const heading = this._heading;\n const start = this._start;\n\n // If start and end have same latitude, return undefined since it's either no intersection or infinite intersections\n if (\n CesiumMath.equalsEpsilon(\n Math.abs(heading),\n CesiumMath.PI_OVER_TWO,\n CesiumMath.EPSILON8\n )\n ) {\n return;\n }\n\n // Can be solved using the same equations from interpolateUsingSurfaceDistance\n const sigma1 = calculateSigma(ellipticity, start.latitude);\n const sigma2 = calculateSigma(ellipticity, intersectionLatitude);\n const deltaLongitude = Math.tan(heading) * (sigma2 - sigma1);\n const longitude = CesiumMath.negativePiToPi(start.longitude + deltaLongitude);\n\n if (defined(result)) {\n result.longitude = longitude;\n result.latitude = intersectionLatitude;\n result.height = 0;\n\n return result;\n }\n\n return new Cartographic(longitude, intersectionLatitude, 0);\n};\nexport default EllipsoidRhumbLine;\n", "import ApproximateTerrainHeights from \"./ApproximateTerrainHeights.js\";\nimport ArcType from \"./ArcType.js\";\nimport arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidGeodesic from \"./EllipsoidGeodesic.js\";\nimport EllipsoidRhumbLine from \"./EllipsoidRhumbLine.js\";\nimport EncodedCartesian3 from \"./EncodedCartesian3.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport IntersectionTests from \"./IntersectionTests.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Plane from \"./Plane.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport WebMercatorProjection from \"./WebMercatorProjection.js\";\n\nconst PROJECTIONS = [GeographicProjection, WebMercatorProjection];\nconst PROJECTION_COUNT = PROJECTIONS.length;\n\nconst MITER_BREAK_SMALL = Math.cos(CesiumMath.toRadians(30.0));\nconst MITER_BREAK_LARGE = Math.cos(CesiumMath.toRadians(150.0));\n\n// Initial heights for constructing the wall.\n// Keeping WALL_INITIAL_MIN_HEIGHT near the ellipsoid surface helps\n// prevent precision problems with planes in the shader.\n// Putting the start point of a plane at ApproximateTerrainHeights._defaultMinTerrainHeight,\n// which is a highly conservative bound, usually puts the plane origin several thousands\n// of meters away from the actual terrain, causing floating point problems when checking\n// fragments on terrain against the plane.\n// Ellipsoid height is generally much closer.\n// The initial max height is arbitrary.\n// Both heights are corrected using ApproximateTerrainHeights for computing the actual volume geometry.\nconst WALL_INITIAL_MIN_HEIGHT = 0.0;\nconst WALL_INITIAL_MAX_HEIGHT = 1000.0;\n\n/**\n * A description of a polyline on terrain or 3D Tiles. Only to be used with {@link GroundPolylinePrimitive}.\n *\n * @alias GroundPolylineGeometry\n * @constructor\n *\n * @param {object} options Options with the following properties:\n * @param {Cartesian3[]} options.positions An array of {@link Cartesian3} defining the polyline's points. Heights above the ellipsoid will be ignored.\n * @param {number} [options.width=1.0] The screen space width in pixels.\n * @param {number} [options.granularity=9999.0] The distance interval in meters used for interpolating options.points. Defaults to 9999.0 meters. Zero indicates no interpolation.\n * @param {boolean} [options.loop=false] Whether during geometry creation a line segment will be added between the last and first line positions to make this Polyline a loop.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polyline segments must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n *\n * @exception {DeveloperError} At least two positions are required.\n *\n * @see GroundPolylinePrimitive\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([\n * -112.1340164450331, 36.05494287836128,\n * -112.08821010582645, 36.097804071380715,\n * -112.13296079730024, 36.168769146801104\n * ]);\n *\n * const geometry = new Cesium.GroundPolylineGeometry({\n * positions : positions\n * });\n */\nfunction GroundPolylineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions) || positions.length < 2) {\n throw new DeveloperError(\"At least two positions are required.\");\n }\n if (\n defined(options.arcType) &&\n options.arcType !== ArcType.GEODESIC &&\n options.arcType !== ArcType.RHUMB\n ) {\n throw new DeveloperError(\n \"Valid options for arcType are ArcType.GEODESIC and ArcType.RHUMB.\"\n );\n }\n //>>includeEnd('debug');\n\n /**\n * The screen space width in pixels.\n * @type {number}\n */\n this.width = defaultValue(options.width, 1.0); // Doesn't get packed, not necessary for computing geometry.\n\n this._positions = positions;\n\n /**\n * The distance interval used for interpolating options.points. Zero indicates no interpolation.\n * Default of 9999.0 allows centimeter accuracy with 32 bit floating point.\n * @type {boolean}\n * @default 9999.0\n */\n this.granularity = defaultValue(options.granularity, 9999.0);\n\n /**\n * Whether during geometry creation a line segment will be added between the last and first line positions to make this Polyline a loop.\n * If the geometry has two positions this parameter will be ignored.\n * @type {boolean}\n * @default false\n */\n this.loop = defaultValue(options.loop, false);\n\n /**\n * The type of path the polyline must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n * @type {ArcType}\n * @default ArcType.GEODESIC\n */\n this.arcType = defaultValue(options.arcType, ArcType.GEODESIC);\n\n this._ellipsoid = Ellipsoid.WGS84;\n\n // MapProjections can't be packed, so store the index to a known MapProjection.\n this._projectionIndex = 0;\n this._workerName = \"createGroundPolylineGeometry\";\n\n // Used by GroundPolylinePrimitive to signal worker that scenemode is 3D only.\n this._scene3DOnly = false;\n}\n\nObject.defineProperties(GroundPolylineGeometry.prototype, {\n /**\n * The number of elements used to pack the object into an array.\n * @memberof GroundPolylineGeometry.prototype\n * @type {number}\n * @readonly\n * @private\n */\n packedLength: {\n get: function () {\n return (\n 1.0 +\n this._positions.length * 3 +\n 1.0 +\n 1.0 +\n 1.0 +\n Ellipsoid.packedLength +\n 1.0 +\n 1.0\n );\n },\n },\n});\n\n/**\n * Set the GroundPolylineGeometry's projection and ellipsoid.\n * Used by GroundPolylinePrimitive to signal scene information to the geometry for generating 2D attributes.\n *\n * @param {GroundPolylineGeometry} groundPolylineGeometry GroundPolylinGeometry describing a polyline on terrain or 3D Tiles.\n * @param {Projection} mapProjection A MapProjection used for projecting cartographic coordinates to 2D.\n * @private\n */\nGroundPolylineGeometry.setProjectionAndEllipsoid = function (\n groundPolylineGeometry,\n mapProjection\n) {\n let projectionIndex = 0;\n for (let i = 0; i < PROJECTION_COUNT; i++) {\n if (mapProjection instanceof PROJECTIONS[i]) {\n projectionIndex = i;\n break;\n }\n }\n\n groundPolylineGeometry._projectionIndex = projectionIndex;\n groundPolylineGeometry._ellipsoid = mapProjection.ellipsoid;\n};\n\nconst cart3Scratch1 = new Cartesian3();\nconst cart3Scratch2 = new Cartesian3();\nconst cart3Scratch3 = new Cartesian3();\nfunction computeRightNormal(start, end, maxHeight, ellipsoid, result) {\n const startBottom = getPosition(ellipsoid, start, 0.0, cart3Scratch1);\n const startTop = getPosition(ellipsoid, start, maxHeight, cart3Scratch2);\n const endBottom = getPosition(ellipsoid, end, 0.0, cart3Scratch3);\n\n const up = direction(startTop, startBottom, cart3Scratch2);\n const forward = direction(endBottom, startBottom, cart3Scratch3);\n\n Cartesian3.cross(forward, up, result);\n return Cartesian3.normalize(result, result);\n}\n\nconst interpolatedCartographicScratch = new Cartographic();\nconst interpolatedBottomScratch = new Cartesian3();\nconst interpolatedTopScratch = new Cartesian3();\nconst interpolatedNormalScratch = new Cartesian3();\nfunction interpolateSegment(\n start,\n end,\n minHeight,\n maxHeight,\n granularity,\n arcType,\n ellipsoid,\n normalsArray,\n bottomPositionsArray,\n topPositionsArray,\n cartographicsArray\n) {\n if (granularity === 0.0) {\n return;\n }\n\n let ellipsoidLine;\n if (arcType === ArcType.GEODESIC) {\n ellipsoidLine = new EllipsoidGeodesic(start, end, ellipsoid);\n } else if (arcType === ArcType.RHUMB) {\n ellipsoidLine = new EllipsoidRhumbLine(start, end, ellipsoid);\n }\n\n const surfaceDistance = ellipsoidLine.surfaceDistance;\n if (surfaceDistance < granularity) {\n return;\n }\n\n // Compute rightwards normal applicable at all interpolated points\n const interpolatedNormal = computeRightNormal(\n start,\n end,\n maxHeight,\n ellipsoid,\n interpolatedNormalScratch\n );\n\n const segments = Math.ceil(surfaceDistance / granularity);\n const interpointDistance = surfaceDistance / segments;\n let distanceFromStart = interpointDistance;\n const pointsToAdd = segments - 1;\n let packIndex = normalsArray.length;\n for (let i = 0; i < pointsToAdd; i++) {\n const interpolatedCartographic = ellipsoidLine.interpolateUsingSurfaceDistance(\n distanceFromStart,\n interpolatedCartographicScratch\n );\n const interpolatedBottom = getPosition(\n ellipsoid,\n interpolatedCartographic,\n minHeight,\n interpolatedBottomScratch\n );\n const interpolatedTop = getPosition(\n ellipsoid,\n interpolatedCartographic,\n maxHeight,\n interpolatedTopScratch\n );\n\n Cartesian3.pack(interpolatedNormal, normalsArray, packIndex);\n Cartesian3.pack(interpolatedBottom, bottomPositionsArray, packIndex);\n Cartesian3.pack(interpolatedTop, topPositionsArray, packIndex);\n cartographicsArray.push(interpolatedCartographic.latitude);\n cartographicsArray.push(interpolatedCartographic.longitude);\n\n packIndex += 3;\n distanceFromStart += interpointDistance;\n }\n}\n\nconst heightlessCartographicScratch = new Cartographic();\nfunction getPosition(ellipsoid, cartographic, height, result) {\n Cartographic.clone(cartographic, heightlessCartographicScratch);\n heightlessCartographicScratch.height = height;\n return Cartographic.toCartesian(\n heightlessCartographicScratch,\n ellipsoid,\n result\n );\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolygonGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nGroundPolylineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n let index = defaultValue(startingIndex, 0);\n\n const positions = value._positions;\n const positionsLength = positions.length;\n\n array[index++] = positionsLength;\n\n for (let i = 0; i < positionsLength; ++i) {\n const cartesian = positions[i];\n Cartesian3.pack(cartesian, array, index);\n index += 3;\n }\n\n array[index++] = value.granularity;\n array[index++] = value.loop ? 1.0 : 0.0;\n array[index++] = value.arcType;\n\n Ellipsoid.pack(value._ellipsoid, array, index);\n index += Ellipsoid.packedLength;\n\n array[index++] = value._projectionIndex;\n array[index++] = value._scene3DOnly ? 1.0 : 0.0;\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolygonGeometry} [result] The object into which to store the result.\n */\nGroundPolylineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n let index = defaultValue(startingIndex, 0);\n const positionsLength = array[index++];\n const positions = new Array(positionsLength);\n\n for (let i = 0; i < positionsLength; i++) {\n positions[i] = Cartesian3.unpack(array, index);\n index += 3;\n }\n\n const granularity = array[index++];\n const loop = array[index++] === 1.0;\n const arcType = array[index++];\n\n const ellipsoid = Ellipsoid.unpack(array, index);\n index += Ellipsoid.packedLength;\n\n const projectionIndex = array[index++];\n const scene3DOnly = array[index++] === 1.0;\n\n if (!defined(result)) {\n result = new GroundPolylineGeometry({\n positions: positions,\n });\n }\n\n result._positions = positions;\n result.granularity = granularity;\n result.loop = loop;\n result.arcType = arcType;\n result._ellipsoid = ellipsoid;\n result._projectionIndex = projectionIndex;\n result._scene3DOnly = scene3DOnly;\n\n return result;\n};\n\nfunction direction(target, origin, result) {\n Cartesian3.subtract(target, origin, result);\n Cartesian3.normalize(result, result);\n return result;\n}\n\nfunction tangentDirection(target, origin, up, result) {\n result = direction(target, origin, result);\n\n // orthogonalize\n result = Cartesian3.cross(result, up, result);\n result = Cartesian3.normalize(result, result);\n result = Cartesian3.cross(up, result, result);\n return result;\n}\n\nconst toPreviousScratch = new Cartesian3();\nconst toNextScratch = new Cartesian3();\nconst forwardScratch = new Cartesian3();\nconst vertexUpScratch = new Cartesian3();\nconst cosine90 = 0.0;\nconst cosine180 = -1.0;\nfunction computeVertexMiterNormal(\n previousBottom,\n vertexBottom,\n vertexTop,\n nextBottom,\n result\n) {\n const up = direction(vertexTop, vertexBottom, vertexUpScratch);\n\n // Compute vectors pointing towards neighboring points but tangent to this point on the ellipsoid\n const toPrevious = tangentDirection(\n previousBottom,\n vertexBottom,\n up,\n toPreviousScratch\n );\n const toNext = tangentDirection(nextBottom, vertexBottom, up, toNextScratch);\n\n // Check if tangents are almost opposite - if so, no need to miter.\n if (\n CesiumMath.equalsEpsilon(\n Cartesian3.dot(toPrevious, toNext),\n cosine180,\n CesiumMath.EPSILON5\n )\n ) {\n result = Cartesian3.cross(up, toPrevious, result);\n result = Cartesian3.normalize(result, result);\n return result;\n }\n\n // Average directions to previous and to next in the plane of Up\n result = Cartesian3.add(toNext, toPrevious, result);\n result = Cartesian3.normalize(result, result);\n\n // Flip the normal if it isn't pointing roughly bound right (aka if forward is pointing more \"backwards\")\n const forward = Cartesian3.cross(up, result, forwardScratch);\n if (Cartesian3.dot(toNext, forward) < cosine90) {\n result = Cartesian3.negate(result, result);\n }\n\n return result;\n}\n\nconst XZ_PLANE = Plane.fromPointNormal(Cartesian3.ZERO, Cartesian3.UNIT_Y);\n\nconst previousBottomScratch = new Cartesian3();\nconst vertexBottomScratch = new Cartesian3();\nconst vertexTopScratch = new Cartesian3();\nconst nextBottomScratch = new Cartesian3();\nconst vertexNormalScratch = new Cartesian3();\nconst intersectionScratch = new Cartesian3();\nconst cartographicScratch0 = new Cartographic();\nconst cartographicScratch1 = new Cartographic();\nconst cartographicIntersectionScratch = new Cartographic();\n/**\n * Computes shadow volumes for the ground polyline, consisting of its vertices, indices, and a bounding sphere.\n * Vertices are \"fat,\" packing all the data needed in each volume to describe a line on terrain or 3D Tiles.\n * Should not be called independent of {@link GroundPolylinePrimitive}.\n *\n * @param {GroundPolylineGeometry} groundPolylineGeometry\n * @private\n */\nGroundPolylineGeometry.createGeometry = function (groundPolylineGeometry) {\n const compute2dAttributes = !groundPolylineGeometry._scene3DOnly;\n let loop = groundPolylineGeometry.loop;\n const ellipsoid = groundPolylineGeometry._ellipsoid;\n const granularity = groundPolylineGeometry.granularity;\n const arcType = groundPolylineGeometry.arcType;\n const projection = new PROJECTIONS[groundPolylineGeometry._projectionIndex](\n ellipsoid\n );\n\n const minHeight = WALL_INITIAL_MIN_HEIGHT;\n const maxHeight = WALL_INITIAL_MAX_HEIGHT;\n\n let index;\n let i;\n\n const positions = groundPolylineGeometry._positions;\n const positionsLength = positions.length;\n\n if (positionsLength === 2) {\n loop = false;\n }\n\n // Split positions across the IDL and the Prime Meridian as well.\n // Split across prime meridian because very large geometries crossing the Prime Meridian but not the IDL\n // may get split by the plane of IDL + Prime Meridian.\n let p0;\n let p1;\n let c0;\n let c1;\n const rhumbLine = new EllipsoidRhumbLine(undefined, undefined, ellipsoid);\n let intersection;\n let intersectionCartographic;\n let intersectionLongitude;\n const splitPositions = [positions[0]];\n for (i = 0; i < positionsLength - 1; i++) {\n p0 = positions[i];\n p1 = positions[i + 1];\n intersection = IntersectionTests.lineSegmentPlane(\n p0,\n p1,\n XZ_PLANE,\n intersectionScratch\n );\n if (\n defined(intersection) &&\n !Cartesian3.equalsEpsilon(intersection, p0, CesiumMath.EPSILON7) &&\n !Cartesian3.equalsEpsilon(intersection, p1, CesiumMath.EPSILON7)\n ) {\n if (groundPolylineGeometry.arcType === ArcType.GEODESIC) {\n splitPositions.push(Cartesian3.clone(intersection));\n } else if (groundPolylineGeometry.arcType === ArcType.RHUMB) {\n intersectionLongitude = ellipsoid.cartesianToCartographic(\n intersection,\n cartographicScratch0\n ).longitude;\n c0 = ellipsoid.cartesianToCartographic(p0, cartographicScratch0);\n c1 = ellipsoid.cartesianToCartographic(p1, cartographicScratch1);\n rhumbLine.setEndPoints(c0, c1);\n intersectionCartographic = rhumbLine.findIntersectionWithLongitude(\n intersectionLongitude,\n cartographicIntersectionScratch\n );\n intersection = ellipsoid.cartographicToCartesian(\n intersectionCartographic,\n intersectionScratch\n );\n if (\n defined(intersection) &&\n !Cartesian3.equalsEpsilon(intersection, p0, CesiumMath.EPSILON7) &&\n !Cartesian3.equalsEpsilon(intersection, p1, CesiumMath.EPSILON7)\n ) {\n splitPositions.push(Cartesian3.clone(intersection));\n }\n }\n }\n splitPositions.push(p1);\n }\n\n if (loop) {\n p0 = positions[positionsLength - 1];\n p1 = positions[0];\n intersection = IntersectionTests.lineSegmentPlane(\n p0,\n p1,\n XZ_PLANE,\n intersectionScratch\n );\n if (\n defined(intersection) &&\n !Cartesian3.equalsEpsilon(intersection, p0, CesiumMath.EPSILON7) &&\n !Cartesian3.equalsEpsilon(intersection, p1, CesiumMath.EPSILON7)\n ) {\n if (groundPolylineGeometry.arcType === ArcType.GEODESIC) {\n splitPositions.push(Cartesian3.clone(intersection));\n } else if (groundPolylineGeometry.arcType === ArcType.RHUMB) {\n intersectionLongitude = ellipsoid.cartesianToCartographic(\n intersection,\n cartographicScratch0\n ).longitude;\n c0 = ellipsoid.cartesianToCartographic(p0, cartographicScratch0);\n c1 = ellipsoid.cartesianToCartographic(p1, cartographicScratch1);\n rhumbLine.setEndPoints(c0, c1);\n intersectionCartographic = rhumbLine.findIntersectionWithLongitude(\n intersectionLongitude,\n cartographicIntersectionScratch\n );\n intersection = ellipsoid.cartographicToCartesian(\n intersectionCartographic,\n intersectionScratch\n );\n if (\n defined(intersection) &&\n !Cartesian3.equalsEpsilon(intersection, p0, CesiumMath.EPSILON7) &&\n !Cartesian3.equalsEpsilon(intersection, p1, CesiumMath.EPSILON7)\n ) {\n splitPositions.push(Cartesian3.clone(intersection));\n }\n }\n }\n }\n let cartographicsLength = splitPositions.length;\n\n let cartographics = new Array(cartographicsLength);\n for (i = 0; i < cartographicsLength; i++) {\n const cartographic = Cartographic.fromCartesian(\n splitPositions[i],\n ellipsoid\n );\n cartographic.height = 0.0;\n cartographics[i] = cartographic;\n }\n\n cartographics = arrayRemoveDuplicates(\n cartographics,\n Cartographic.equalsEpsilon\n );\n cartographicsLength = cartographics.length;\n\n if (cartographicsLength < 2) {\n return undefined;\n }\n\n /**** Build heap-side arrays for positions, interpolated cartographics, and normals from which to compute vertices ****/\n // We build a \"wall\" and then decompose it into separately connected component \"volumes\" because we need a lot\n // of information about the wall. Also, this simplifies interpolation.\n // Convention: \"next\" and \"end\" are locally forward to each segment of the wall,\n // and we are computing normals pointing towards the local right side of the vertices in each segment.\n const cartographicsArray = [];\n const normalsArray = [];\n const bottomPositionsArray = [];\n const topPositionsArray = [];\n\n let previousBottom = previousBottomScratch;\n let vertexBottom = vertexBottomScratch;\n let vertexTop = vertexTopScratch;\n let nextBottom = nextBottomScratch;\n let vertexNormal = vertexNormalScratch;\n\n // First point - either loop or attach a \"perpendicular\" normal\n const startCartographic = cartographics[0];\n const nextCartographic = cartographics[1];\n\n const prestartCartographic = cartographics[cartographicsLength - 1];\n previousBottom = getPosition(\n ellipsoid,\n prestartCartographic,\n minHeight,\n previousBottom\n );\n nextBottom = getPosition(ellipsoid, nextCartographic, minHeight, nextBottom);\n vertexBottom = getPosition(\n ellipsoid,\n startCartographic,\n minHeight,\n vertexBottom\n );\n vertexTop = getPosition(ellipsoid, startCartographic, maxHeight, vertexTop);\n\n if (loop) {\n vertexNormal = computeVertexMiterNormal(\n previousBottom,\n vertexBottom,\n vertexTop,\n nextBottom,\n vertexNormal\n );\n } else {\n vertexNormal = computeRightNormal(\n startCartographic,\n nextCartographic,\n maxHeight,\n ellipsoid,\n vertexNormal\n );\n }\n\n Cartesian3.pack(vertexNormal, normalsArray, 0);\n Cartesian3.pack(vertexBottom, bottomPositionsArray, 0);\n Cartesian3.pack(vertexTop, topPositionsArray, 0);\n cartographicsArray.push(startCartographic.latitude);\n cartographicsArray.push(startCartographic.longitude);\n\n interpolateSegment(\n startCartographic,\n nextCartographic,\n minHeight,\n maxHeight,\n granularity,\n arcType,\n ellipsoid,\n normalsArray,\n bottomPositionsArray,\n topPositionsArray,\n cartographicsArray\n );\n\n // All inbetween points\n for (i = 1; i < cartographicsLength - 1; ++i) {\n previousBottom = Cartesian3.clone(vertexBottom, previousBottom);\n vertexBottom = Cartesian3.clone(nextBottom, vertexBottom);\n const vertexCartographic = cartographics[i];\n getPosition(ellipsoid, vertexCartographic, maxHeight, vertexTop);\n getPosition(ellipsoid, cartographics[i + 1], minHeight, nextBottom);\n\n computeVertexMiterNormal(\n previousBottom,\n vertexBottom,\n vertexTop,\n nextBottom,\n vertexNormal\n );\n\n index = normalsArray.length;\n Cartesian3.pack(vertexNormal, normalsArray, index);\n Cartesian3.pack(vertexBottom, bottomPositionsArray, index);\n Cartesian3.pack(vertexTop, topPositionsArray, index);\n cartographicsArray.push(vertexCartographic.latitude);\n cartographicsArray.push(vertexCartographic.longitude);\n\n interpolateSegment(\n cartographics[i],\n cartographics[i + 1],\n minHeight,\n maxHeight,\n granularity,\n arcType,\n ellipsoid,\n normalsArray,\n bottomPositionsArray,\n topPositionsArray,\n cartographicsArray\n );\n }\n\n // Last point - either loop or attach a normal \"perpendicular\" to the wall.\n const endCartographic = cartographics[cartographicsLength - 1];\n const preEndCartographic = cartographics[cartographicsLength - 2];\n\n vertexBottom = getPosition(\n ellipsoid,\n endCartographic,\n minHeight,\n vertexBottom\n );\n vertexTop = getPosition(ellipsoid, endCartographic, maxHeight, vertexTop);\n\n if (loop) {\n const postEndCartographic = cartographics[0];\n previousBottom = getPosition(\n ellipsoid,\n preEndCartographic,\n minHeight,\n previousBottom\n );\n nextBottom = getPosition(\n ellipsoid,\n postEndCartographic,\n minHeight,\n nextBottom\n );\n\n vertexNormal = computeVertexMiterNormal(\n previousBottom,\n vertexBottom,\n vertexTop,\n nextBottom,\n vertexNormal\n );\n } else {\n vertexNormal = computeRightNormal(\n preEndCartographic,\n endCartographic,\n maxHeight,\n ellipsoid,\n vertexNormal\n );\n }\n\n index = normalsArray.length;\n Cartesian3.pack(vertexNormal, normalsArray, index);\n Cartesian3.pack(vertexBottom, bottomPositionsArray, index);\n Cartesian3.pack(vertexTop, topPositionsArray, index);\n cartographicsArray.push(endCartographic.latitude);\n cartographicsArray.push(endCartographic.longitude);\n\n if (loop) {\n interpolateSegment(\n endCartographic,\n startCartographic,\n minHeight,\n maxHeight,\n granularity,\n arcType,\n ellipsoid,\n normalsArray,\n bottomPositionsArray,\n topPositionsArray,\n cartographicsArray\n );\n index = normalsArray.length;\n for (i = 0; i < 3; ++i) {\n normalsArray[index + i] = normalsArray[i];\n bottomPositionsArray[index + i] = bottomPositionsArray[i];\n topPositionsArray[index + i] = topPositionsArray[i];\n }\n cartographicsArray.push(startCartographic.latitude);\n cartographicsArray.push(startCartographic.longitude);\n }\n\n return generateGeometryAttributes(\n loop,\n projection,\n bottomPositionsArray,\n topPositionsArray,\n normalsArray,\n cartographicsArray,\n compute2dAttributes\n );\n};\n\n// If the end normal angle is too steep compared to the direction of the line segment,\n// \"break\" the miter by rotating the normal 90 degrees around the \"up\" direction at the point\n// For ultra precision we would want to project into a plane, but in practice this is sufficient.\nconst lineDirectionScratch = new Cartesian3();\nconst matrix3Scratch = new Matrix3();\nconst quaternionScratch = new Quaternion();\nfunction breakMiter(endGeometryNormal, startBottom, endBottom, endTop) {\n const lineDirection = direction(endBottom, startBottom, lineDirectionScratch);\n\n const dot = Cartesian3.dot(lineDirection, endGeometryNormal);\n if (dot > MITER_BREAK_SMALL || dot < MITER_BREAK_LARGE) {\n const vertexUp = direction(endTop, endBottom, vertexUpScratch);\n const angle =\n dot < MITER_BREAK_LARGE\n ? CesiumMath.PI_OVER_TWO\n : -CesiumMath.PI_OVER_TWO;\n const quaternion = Quaternion.fromAxisAngle(\n vertexUp,\n angle,\n quaternionScratch\n );\n const rotationMatrix = Matrix3.fromQuaternion(quaternion, matrix3Scratch);\n Matrix3.multiplyByVector(\n rotationMatrix,\n endGeometryNormal,\n endGeometryNormal\n );\n return true;\n }\n return false;\n}\n\nconst endPosCartographicScratch = new Cartographic();\nconst normalStartpointScratch = new Cartesian3();\nconst normalEndpointScratch = new Cartesian3();\nfunction projectNormal(\n projection,\n cartographic,\n normal,\n projectedPosition,\n result\n) {\n const position = Cartographic.toCartesian(\n cartographic,\n projection._ellipsoid,\n normalStartpointScratch\n );\n let normalEndpoint = Cartesian3.add(position, normal, normalEndpointScratch);\n let flipNormal = false;\n\n const ellipsoid = projection._ellipsoid;\n let normalEndpointCartographic = ellipsoid.cartesianToCartographic(\n normalEndpoint,\n endPosCartographicScratch\n );\n // If normal crosses the IDL, go the other way and flip the result.\n // In practice this almost never happens because the cartographic start\n // and end points of each segment are \"nudged\" to be on the same side\n // of the IDL and slightly away from the IDL.\n if (\n Math.abs(cartographic.longitude - normalEndpointCartographic.longitude) >\n CesiumMath.PI_OVER_TWO\n ) {\n flipNormal = true;\n normalEndpoint = Cartesian3.subtract(\n position,\n normal,\n normalEndpointScratch\n );\n normalEndpointCartographic = ellipsoid.cartesianToCartographic(\n normalEndpoint,\n endPosCartographicScratch\n );\n }\n\n normalEndpointCartographic.height = 0.0;\n const normalEndpointProjected = projection.project(\n normalEndpointCartographic,\n result\n );\n result = Cartesian3.subtract(\n normalEndpointProjected,\n projectedPosition,\n result\n );\n result.z = 0.0;\n result = Cartesian3.normalize(result, result);\n if (flipNormal) {\n Cartesian3.negate(result, result);\n }\n return result;\n}\n\nconst adjustHeightNormalScratch = new Cartesian3();\nconst adjustHeightOffsetScratch = new Cartesian3();\nfunction adjustHeights(\n bottom,\n top,\n minHeight,\n maxHeight,\n adjustHeightBottom,\n adjustHeightTop\n) {\n // bottom and top should be at WALL_INITIAL_MIN_HEIGHT and WALL_INITIAL_MAX_HEIGHT, respectively\n const adjustHeightNormal = Cartesian3.subtract(\n top,\n bottom,\n adjustHeightNormalScratch\n );\n Cartesian3.normalize(adjustHeightNormal, adjustHeightNormal);\n\n const distanceForBottom = minHeight - WALL_INITIAL_MIN_HEIGHT;\n let adjustHeightOffset = Cartesian3.multiplyByScalar(\n adjustHeightNormal,\n distanceForBottom,\n adjustHeightOffsetScratch\n );\n Cartesian3.add(bottom, adjustHeightOffset, adjustHeightBottom);\n\n const distanceForTop = maxHeight - WALL_INITIAL_MAX_HEIGHT;\n adjustHeightOffset = Cartesian3.multiplyByScalar(\n adjustHeightNormal,\n distanceForTop,\n adjustHeightOffsetScratch\n );\n Cartesian3.add(top, adjustHeightOffset, adjustHeightTop);\n}\n\nconst nudgeDirectionScratch = new Cartesian3();\nfunction nudgeXZ(start, end) {\n const startToXZdistance = Plane.getPointDistance(XZ_PLANE, start);\n const endToXZdistance = Plane.getPointDistance(XZ_PLANE, end);\n let offset = nudgeDirectionScratch;\n // Larger epsilon than what's used in GeometryPipeline, a centimeter in world space\n if (CesiumMath.equalsEpsilon(startToXZdistance, 0.0, CesiumMath.EPSILON2)) {\n offset = direction(end, start, offset);\n Cartesian3.multiplyByScalar(offset, CesiumMath.EPSILON2, offset);\n Cartesian3.add(start, offset, start);\n } else if (\n CesiumMath.equalsEpsilon(endToXZdistance, 0.0, CesiumMath.EPSILON2)\n ) {\n offset = direction(start, end, offset);\n Cartesian3.multiplyByScalar(offset, CesiumMath.EPSILON2, offset);\n Cartesian3.add(end, offset, end);\n }\n}\n\n// \"Nudge\" cartographic coordinates so start and end are on the same side of the IDL.\n// Nudge amounts are tiny, basically just an IDL flip.\n// Only used for 2D/CV.\nfunction nudgeCartographic(start, end) {\n const absStartLon = Math.abs(start.longitude);\n const absEndLon = Math.abs(end.longitude);\n if (\n CesiumMath.equalsEpsilon(absStartLon, CesiumMath.PI, CesiumMath.EPSILON11)\n ) {\n const endSign = CesiumMath.sign(end.longitude);\n start.longitude = endSign * (absStartLon - CesiumMath.EPSILON11);\n return 1;\n } else if (\n CesiumMath.equalsEpsilon(absEndLon, CesiumMath.PI, CesiumMath.EPSILON11)\n ) {\n const startSign = CesiumMath.sign(start.longitude);\n end.longitude = startSign * (absEndLon - CesiumMath.EPSILON11);\n return 2;\n }\n return 0;\n}\n\nconst startCartographicScratch = new Cartographic();\nconst endCartographicScratch = new Cartographic();\n\nconst segmentStartTopScratch = new Cartesian3();\nconst segmentEndTopScratch = new Cartesian3();\nconst segmentStartBottomScratch = new Cartesian3();\nconst segmentEndBottomScratch = new Cartesian3();\nconst segmentStartNormalScratch = new Cartesian3();\nconst segmentEndNormalScratch = new Cartesian3();\n\nconst getHeightCartographics = [\n startCartographicScratch,\n endCartographicScratch,\n];\nconst getHeightRectangleScratch = new Rectangle();\n\nconst adjustHeightStartTopScratch = new Cartesian3();\nconst adjustHeightEndTopScratch = new Cartesian3();\nconst adjustHeightStartBottomScratch = new Cartesian3();\nconst adjustHeightEndBottomScratch = new Cartesian3();\n\nconst segmentStart2DScratch = new Cartesian3();\nconst segmentEnd2DScratch = new Cartesian3();\nconst segmentStartNormal2DScratch = new Cartesian3();\nconst segmentEndNormal2DScratch = new Cartesian3();\n\nconst offsetScratch = new Cartesian3();\nconst startUpScratch = new Cartesian3();\nconst endUpScratch = new Cartesian3();\nconst rightScratch = new Cartesian3();\nconst startPlaneNormalScratch = new Cartesian3();\nconst endPlaneNormalScratch = new Cartesian3();\nconst encodeScratch = new EncodedCartesian3();\n\nconst encodeScratch2D = new EncodedCartesian3();\nconst forwardOffset2DScratch = new Cartesian3();\nconst right2DScratch = new Cartesian3();\n\nconst normalNudgeScratch = new Cartesian3();\n\nconst scratchBoundingSpheres = [new BoundingSphere(), new BoundingSphere()];\n\n// Winding order is reversed so each segment's volume is inside-out\nconst REFERENCE_INDICES = [\n 0,\n 2,\n 1,\n 0,\n 3,\n 2, // right\n 0,\n 7,\n 3,\n 0,\n 4,\n 7, // start\n 0,\n 5,\n 4,\n 0,\n 1,\n 5, // bottom\n 5,\n 7,\n 4,\n 5,\n 6,\n 7, // left\n 5,\n 2,\n 6,\n 5,\n 1,\n 2, // end\n 3,\n 6,\n 2,\n 3,\n 7,\n 6, // top\n];\nconst REFERENCE_INDICES_LENGTH = REFERENCE_INDICES.length;\n\n// Decompose the \"wall\" into a series of shadow volumes.\n// Each shadow volume's vertices encode a description of the line it contains,\n// including mitering planes at the end points, a plane along the line itself,\n// and attributes for computing length-wise texture coordinates.\nfunction generateGeometryAttributes(\n loop,\n projection,\n bottomPositionsArray,\n topPositionsArray,\n normalsArray,\n cartographicsArray,\n compute2dAttributes\n) {\n let i;\n let index;\n const ellipsoid = projection._ellipsoid;\n\n // Each segment will have 8 vertices\n const segmentCount = bottomPositionsArray.length / 3 - 1;\n const vertexCount = segmentCount * 8;\n const arraySizeVec4 = vertexCount * 4;\n const indexCount = segmentCount * 36;\n\n const indices =\n vertexCount > 65535\n ? new Uint32Array(indexCount)\n : new Uint16Array(indexCount);\n const positionsArray = new Float64Array(vertexCount * 3);\n\n const startHiAndForwardOffsetX = new Float32Array(arraySizeVec4);\n const startLoAndForwardOffsetY = new Float32Array(arraySizeVec4);\n const startNormalAndForwardOffsetZ = new Float32Array(arraySizeVec4);\n const endNormalAndTextureCoordinateNormalizationX = new Float32Array(\n arraySizeVec4\n );\n const rightNormalAndTextureCoordinateNormalizationY = new Float32Array(\n arraySizeVec4\n );\n\n let startHiLo2D;\n let offsetAndRight2D;\n let startEndNormals2D;\n let texcoordNormalization2D;\n\n if (compute2dAttributes) {\n startHiLo2D = new Float32Array(arraySizeVec4);\n offsetAndRight2D = new Float32Array(arraySizeVec4);\n startEndNormals2D = new Float32Array(arraySizeVec4);\n texcoordNormalization2D = new Float32Array(vertexCount * 2);\n }\n\n /*** Compute total lengths for texture coordinate normalization ***/\n // 2D\n const cartographicsLength = cartographicsArray.length / 2;\n let length2D = 0.0;\n\n const startCartographic = startCartographicScratch;\n startCartographic.height = 0.0;\n const endCartographic = endCartographicScratch;\n endCartographic.height = 0.0;\n\n let segmentStartCartesian = segmentStartTopScratch;\n let segmentEndCartesian = segmentEndTopScratch;\n\n if (compute2dAttributes) {\n index = 0;\n for (i = 1; i < cartographicsLength; i++) {\n // Don't clone anything from previous segment b/c possible IDL touch\n startCartographic.latitude = cartographicsArray[index];\n startCartographic.longitude = cartographicsArray[index + 1];\n endCartographic.latitude = cartographicsArray[index + 2];\n endCartographic.longitude = cartographicsArray[index + 3];\n\n segmentStartCartesian = projection.project(\n startCartographic,\n segmentStartCartesian\n );\n segmentEndCartesian = projection.project(\n endCartographic,\n segmentEndCartesian\n );\n length2D += Cartesian3.distance(\n segmentStartCartesian,\n segmentEndCartesian\n );\n index += 2;\n }\n }\n\n // 3D\n const positionsLength = topPositionsArray.length / 3;\n segmentEndCartesian = Cartesian3.unpack(\n topPositionsArray,\n 0,\n segmentEndCartesian\n );\n let length3D = 0.0;\n\n index = 3;\n for (i = 1; i < positionsLength; i++) {\n segmentStartCartesian = Cartesian3.clone(\n segmentEndCartesian,\n segmentStartCartesian\n );\n segmentEndCartesian = Cartesian3.unpack(\n topPositionsArray,\n index,\n segmentEndCartesian\n );\n length3D += Cartesian3.distance(segmentStartCartesian, segmentEndCartesian);\n index += 3;\n }\n\n /*** Generate segments ***/\n let j;\n index = 3;\n let cartographicsIndex = 0;\n let vec2sWriteIndex = 0;\n let vec3sWriteIndex = 0;\n let vec4sWriteIndex = 0;\n let miterBroken = false;\n\n let endBottom = Cartesian3.unpack(\n bottomPositionsArray,\n 0,\n segmentEndBottomScratch\n );\n let endTop = Cartesian3.unpack(topPositionsArray, 0, segmentEndTopScratch);\n let endGeometryNormal = Cartesian3.unpack(\n normalsArray,\n 0,\n segmentEndNormalScratch\n );\n\n if (loop) {\n const preEndBottom = Cartesian3.unpack(\n bottomPositionsArray,\n bottomPositionsArray.length - 6,\n segmentStartBottomScratch\n );\n if (breakMiter(endGeometryNormal, preEndBottom, endBottom, endTop)) {\n // Miter broken as if for the last point in the loop, needs to be inverted for first point (clone of endBottom)\n endGeometryNormal = Cartesian3.negate(\n endGeometryNormal,\n endGeometryNormal\n );\n }\n }\n\n let lengthSoFar3D = 0.0;\n let lengthSoFar2D = 0.0;\n\n // For translating bounding volume\n let sumHeights = 0.0;\n\n for (i = 0; i < segmentCount; i++) {\n const startBottom = Cartesian3.clone(endBottom, segmentStartBottomScratch);\n const startTop = Cartesian3.clone(endTop, segmentStartTopScratch);\n let startGeometryNormal = Cartesian3.clone(\n endGeometryNormal,\n segmentStartNormalScratch\n );\n\n if (miterBroken) {\n startGeometryNormal = Cartesian3.negate(\n startGeometryNormal,\n startGeometryNormal\n );\n }\n\n endBottom = Cartesian3.unpack(\n bottomPositionsArray,\n index,\n segmentEndBottomScratch\n );\n endTop = Cartesian3.unpack(topPositionsArray, index, segmentEndTopScratch);\n endGeometryNormal = Cartesian3.unpack(\n normalsArray,\n index,\n segmentEndNormalScratch\n );\n\n miterBroken = breakMiter(endGeometryNormal, startBottom, endBottom, endTop);\n\n // 2D - don't clone anything from previous segment b/c possible IDL touch\n startCartographic.latitude = cartographicsArray[cartographicsIndex];\n startCartographic.longitude = cartographicsArray[cartographicsIndex + 1];\n endCartographic.latitude = cartographicsArray[cartographicsIndex + 2];\n endCartographic.longitude = cartographicsArray[cartographicsIndex + 3];\n let start2D;\n let end2D;\n let startGeometryNormal2D;\n let endGeometryNormal2D;\n\n if (compute2dAttributes) {\n const nudgeResult = nudgeCartographic(startCartographic, endCartographic);\n start2D = projection.project(startCartographic, segmentStart2DScratch);\n end2D = projection.project(endCartographic, segmentEnd2DScratch);\n const direction2D = direction(end2D, start2D, forwardOffset2DScratch);\n direction2D.y = Math.abs(direction2D.y);\n\n startGeometryNormal2D = segmentStartNormal2DScratch;\n endGeometryNormal2D = segmentEndNormal2DScratch;\n if (\n nudgeResult === 0 ||\n Cartesian3.dot(direction2D, Cartesian3.UNIT_Y) > MITER_BREAK_SMALL\n ) {\n // No nudge - project the original normal\n // Or, if the line's angle relative to the IDL is very acute,\n // in which case snapping will produce oddly shaped volumes.\n startGeometryNormal2D = projectNormal(\n projection,\n startCartographic,\n startGeometryNormal,\n start2D,\n segmentStartNormal2DScratch\n );\n endGeometryNormal2D = projectNormal(\n projection,\n endCartographic,\n endGeometryNormal,\n end2D,\n segmentEndNormal2DScratch\n );\n } else if (nudgeResult === 1) {\n // Start is close to IDL - snap start normal to align with IDL\n endGeometryNormal2D = projectNormal(\n projection,\n endCartographic,\n endGeometryNormal,\n end2D,\n segmentEndNormal2DScratch\n );\n startGeometryNormal2D.x = 0.0;\n // If start longitude is negative and end longitude is less negative, relative right is unit -Y\n // If start longitude is positive and end longitude is less positive, relative right is unit +Y\n startGeometryNormal2D.y = CesiumMath.sign(\n startCartographic.longitude - Math.abs(endCartographic.longitude)\n );\n startGeometryNormal2D.z = 0.0;\n } else {\n // End is close to IDL - snap end normal to align with IDL\n startGeometryNormal2D = projectNormal(\n projection,\n startCartographic,\n startGeometryNormal,\n start2D,\n segmentStartNormal2DScratch\n );\n endGeometryNormal2D.x = 0.0;\n // If end longitude is negative and start longitude is less negative, relative right is unit Y\n // If end longitude is positive and start longitude is less positive, relative right is unit -Y\n endGeometryNormal2D.y = CesiumMath.sign(\n startCartographic.longitude - endCartographic.longitude\n );\n endGeometryNormal2D.z = 0.0;\n }\n }\n\n /****************************************\n * Geometry descriptors of a \"line on terrain,\"\n * as opposed to the \"shadow volume used to draw\n * the line on terrain\":\n * - position of start + offset to end\n * - start, end, and right-facing planes\n * - encoded texture coordinate offsets\n ****************************************/\n\n /* 3D */\n const segmentLength3D = Cartesian3.distance(startTop, endTop);\n\n const encodedStart = EncodedCartesian3.fromCartesian(\n startBottom,\n encodeScratch\n );\n const forwardOffset = Cartesian3.subtract(\n endBottom,\n startBottom,\n offsetScratch\n );\n const forward = Cartesian3.normalize(forwardOffset, rightScratch);\n\n let startUp = Cartesian3.subtract(startTop, startBottom, startUpScratch);\n startUp = Cartesian3.normalize(startUp, startUp);\n let rightNormal = Cartesian3.cross(forward, startUp, rightScratch);\n rightNormal = Cartesian3.normalize(rightNormal, rightNormal);\n\n let startPlaneNormal = Cartesian3.cross(\n startUp,\n startGeometryNormal,\n startPlaneNormalScratch\n );\n startPlaneNormal = Cartesian3.normalize(startPlaneNormal, startPlaneNormal);\n\n let endUp = Cartesian3.subtract(endTop, endBottom, endUpScratch);\n endUp = Cartesian3.normalize(endUp, endUp);\n let endPlaneNormal = Cartesian3.cross(\n endGeometryNormal,\n endUp,\n endPlaneNormalScratch\n );\n endPlaneNormal = Cartesian3.normalize(endPlaneNormal, endPlaneNormal);\n\n const texcoordNormalization3DX = segmentLength3D / length3D;\n const texcoordNormalization3DY = lengthSoFar3D / length3D;\n\n /* 2D */\n let segmentLength2D = 0.0;\n let encodedStart2D;\n let forwardOffset2D;\n let right2D;\n let texcoordNormalization2DX = 0.0;\n let texcoordNormalization2DY = 0.0;\n if (compute2dAttributes) {\n segmentLength2D = Cartesian3.distance(start2D, end2D);\n\n encodedStart2D = EncodedCartesian3.fromCartesian(\n start2D,\n encodeScratch2D\n );\n forwardOffset2D = Cartesian3.subtract(\n end2D,\n start2D,\n forwardOffset2DScratch\n );\n\n // Right direction is just forward direction rotated by -90 degrees around Z\n // Similarly with plane normals\n right2D = Cartesian3.normalize(forwardOffset2D, right2DScratch);\n const swap = right2D.x;\n right2D.x = right2D.y;\n right2D.y = -swap;\n\n texcoordNormalization2DX = segmentLength2D / length2D;\n texcoordNormalization2DY = lengthSoFar2D / length2D;\n }\n /** Pack **/\n for (j = 0; j < 8; j++) {\n const vec4Index = vec4sWriteIndex + j * 4;\n const vec2Index = vec2sWriteIndex + j * 2;\n const wIndex = vec4Index + 3;\n\n // Encode sidedness of vertex relative to right plane in texture coordinate normalization X,\n // whether vertex is top or bottom of volume in sign/magnitude of normalization Y.\n const rightPlaneSide = j < 4 ? 1.0 : -1.0;\n const topBottomSide =\n j === 2 || j === 3 || j === 6 || j === 7 ? 1.0 : -1.0;\n\n // 3D\n Cartesian3.pack(encodedStart.high, startHiAndForwardOffsetX, vec4Index);\n startHiAndForwardOffsetX[wIndex] = forwardOffset.x;\n\n Cartesian3.pack(encodedStart.low, startLoAndForwardOffsetY, vec4Index);\n startLoAndForwardOffsetY[wIndex] = forwardOffset.y;\n\n Cartesian3.pack(\n startPlaneNormal,\n startNormalAndForwardOffsetZ,\n vec4Index\n );\n startNormalAndForwardOffsetZ[wIndex] = forwardOffset.z;\n\n Cartesian3.pack(\n endPlaneNormal,\n endNormalAndTextureCoordinateNormalizationX,\n vec4Index\n );\n endNormalAndTextureCoordinateNormalizationX[wIndex] =\n texcoordNormalization3DX * rightPlaneSide;\n\n Cartesian3.pack(\n rightNormal,\n rightNormalAndTextureCoordinateNormalizationY,\n vec4Index\n );\n\n let texcoordNormalization = texcoordNormalization3DY * topBottomSide;\n if (texcoordNormalization === 0.0 && topBottomSide < 0.0) {\n texcoordNormalization = 9.0; // some value greater than 1.0\n }\n rightNormalAndTextureCoordinateNormalizationY[\n wIndex\n ] = texcoordNormalization;\n\n // 2D\n if (compute2dAttributes) {\n startHiLo2D[vec4Index] = encodedStart2D.high.x;\n startHiLo2D[vec4Index + 1] = encodedStart2D.high.y;\n startHiLo2D[vec4Index + 2] = encodedStart2D.low.x;\n startHiLo2D[vec4Index + 3] = encodedStart2D.low.y;\n\n startEndNormals2D[vec4Index] = -startGeometryNormal2D.y;\n startEndNormals2D[vec4Index + 1] = startGeometryNormal2D.x;\n startEndNormals2D[vec4Index + 2] = endGeometryNormal2D.y;\n startEndNormals2D[vec4Index + 3] = -endGeometryNormal2D.x;\n\n offsetAndRight2D[vec4Index] = forwardOffset2D.x;\n offsetAndRight2D[vec4Index + 1] = forwardOffset2D.y;\n offsetAndRight2D[vec4Index + 2] = right2D.x;\n offsetAndRight2D[vec4Index + 3] = right2D.y;\n\n texcoordNormalization2D[vec2Index] =\n texcoordNormalization2DX * rightPlaneSide;\n\n texcoordNormalization = texcoordNormalization2DY * topBottomSide;\n if (texcoordNormalization === 0.0 && topBottomSide < 0.0) {\n texcoordNormalization = 9.0; // some value greater than 1.0\n }\n texcoordNormalization2D[vec2Index + 1] = texcoordNormalization;\n }\n }\n\n // Adjust height of volume in 3D\n const adjustHeightStartBottom = adjustHeightStartBottomScratch;\n const adjustHeightEndBottom = adjustHeightEndBottomScratch;\n const adjustHeightStartTop = adjustHeightStartTopScratch;\n const adjustHeightEndTop = adjustHeightEndTopScratch;\n\n const getHeightsRectangle = Rectangle.fromCartographicArray(\n getHeightCartographics,\n getHeightRectangleScratch\n );\n const minMaxHeights = ApproximateTerrainHeights.getMinimumMaximumHeights(\n getHeightsRectangle,\n ellipsoid\n );\n const minHeight = minMaxHeights.minimumTerrainHeight;\n const maxHeight = minMaxHeights.maximumTerrainHeight;\n\n // Sum using abs() to properly account for negative eleavtions in calculating bounding sphere radius\n sumHeights += Math.abs(minHeight);\n sumHeights += Math.abs(maxHeight);\n\n adjustHeights(\n startBottom,\n startTop,\n minHeight,\n maxHeight,\n adjustHeightStartBottom,\n adjustHeightStartTop\n );\n adjustHeights(\n endBottom,\n endTop,\n minHeight,\n maxHeight,\n adjustHeightEndBottom,\n adjustHeightEndTop\n );\n\n // Nudge the positions away from the \"polyline\" a little bit to prevent errors in GeometryPipeline\n let normalNudge = Cartesian3.multiplyByScalar(\n rightNormal,\n CesiumMath.EPSILON5,\n normalNudgeScratch\n );\n Cartesian3.add(\n adjustHeightStartBottom,\n normalNudge,\n adjustHeightStartBottom\n );\n Cartesian3.add(adjustHeightEndBottom, normalNudge, adjustHeightEndBottom);\n Cartesian3.add(adjustHeightStartTop, normalNudge, adjustHeightStartTop);\n Cartesian3.add(adjustHeightEndTop, normalNudge, adjustHeightEndTop);\n\n // If the segment is very close to the XZ plane, nudge the vertices slightly to avoid touching it.\n nudgeXZ(adjustHeightStartBottom, adjustHeightEndBottom);\n nudgeXZ(adjustHeightStartTop, adjustHeightEndTop);\n\n Cartesian3.pack(adjustHeightStartBottom, positionsArray, vec3sWriteIndex);\n Cartesian3.pack(adjustHeightEndBottom, positionsArray, vec3sWriteIndex + 3);\n Cartesian3.pack(adjustHeightEndTop, positionsArray, vec3sWriteIndex + 6);\n Cartesian3.pack(adjustHeightStartTop, positionsArray, vec3sWriteIndex + 9);\n\n normalNudge = Cartesian3.multiplyByScalar(\n rightNormal,\n -2.0 * CesiumMath.EPSILON5,\n normalNudgeScratch\n );\n Cartesian3.add(\n adjustHeightStartBottom,\n normalNudge,\n adjustHeightStartBottom\n );\n Cartesian3.add(adjustHeightEndBottom, normalNudge, adjustHeightEndBottom);\n Cartesian3.add(adjustHeightStartTop, normalNudge, adjustHeightStartTop);\n Cartesian3.add(adjustHeightEndTop, normalNudge, adjustHeightEndTop);\n\n nudgeXZ(adjustHeightStartBottom, adjustHeightEndBottom);\n nudgeXZ(adjustHeightStartTop, adjustHeightEndTop);\n\n Cartesian3.pack(\n adjustHeightStartBottom,\n positionsArray,\n vec3sWriteIndex + 12\n );\n Cartesian3.pack(\n adjustHeightEndBottom,\n positionsArray,\n vec3sWriteIndex + 15\n );\n Cartesian3.pack(adjustHeightEndTop, positionsArray, vec3sWriteIndex + 18);\n Cartesian3.pack(adjustHeightStartTop, positionsArray, vec3sWriteIndex + 21);\n\n cartographicsIndex += 2;\n index += 3;\n\n vec2sWriteIndex += 16;\n vec3sWriteIndex += 24;\n vec4sWriteIndex += 32;\n\n lengthSoFar3D += segmentLength3D;\n lengthSoFar2D += segmentLength2D;\n }\n\n index = 0;\n let indexOffset = 0;\n for (i = 0; i < segmentCount; i++) {\n for (j = 0; j < REFERENCE_INDICES_LENGTH; j++) {\n indices[index + j] = REFERENCE_INDICES[j] + indexOffset;\n }\n indexOffset += 8;\n index += REFERENCE_INDICES_LENGTH;\n }\n\n const boundingSpheres = scratchBoundingSpheres;\n BoundingSphere.fromVertices(\n bottomPositionsArray,\n Cartesian3.ZERO,\n 3,\n boundingSpheres[0]\n );\n BoundingSphere.fromVertices(\n topPositionsArray,\n Cartesian3.ZERO,\n 3,\n boundingSpheres[1]\n );\n const boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres);\n\n // Adjust bounding sphere height and radius to cover more of the volume\n boundingSphere.radius += sumHeights / (segmentCount * 2.0);\n\n const attributes = {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n normalize: false,\n values: positionsArray,\n }),\n startHiAndForwardOffsetX: getVec4GeometryAttribute(\n startHiAndForwardOffsetX\n ),\n startLoAndForwardOffsetY: getVec4GeometryAttribute(\n startLoAndForwardOffsetY\n ),\n startNormalAndForwardOffsetZ: getVec4GeometryAttribute(\n startNormalAndForwardOffsetZ\n ),\n endNormalAndTextureCoordinateNormalizationX: getVec4GeometryAttribute(\n endNormalAndTextureCoordinateNormalizationX\n ),\n rightNormalAndTextureCoordinateNormalizationY: getVec4GeometryAttribute(\n rightNormalAndTextureCoordinateNormalizationY\n ),\n };\n\n if (compute2dAttributes) {\n attributes.startHiLo2D = getVec4GeometryAttribute(startHiLo2D);\n attributes.offsetAndRight2D = getVec4GeometryAttribute(offsetAndRight2D);\n attributes.startEndNormals2D = getVec4GeometryAttribute(startEndNormals2D);\n attributes.texcoordNormalization2D = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n normalize: false,\n values: texcoordNormalization2D,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n boundingSphere: boundingSphere,\n });\n}\n\nfunction getVec4GeometryAttribute(typedArray) {\n return new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n normalize: false,\n values: typedArray,\n });\n}\n\n/**\n * Approximates an ellipsoid-tangent vector in 2D by projecting the end point into 2D.\n * Exposed for testing.\n *\n * @param {MapProjection} projection Map Projection for projecting coordinates to 2D.\n * @param {Cartographic} cartographic The cartographic origin point of the normal.\n * Used to check if the normal crosses the IDL during projection.\n * @param {Cartesian3} normal The normal in 3D.\n * @param {Cartesian3} projectedPosition The projected origin point of the normal in 2D.\n * @param {Cartesian3} result Result parameter on which to store the projected normal.\n * @private\n */\nGroundPolylineGeometry._projectNormal = projectNormal;\nexport default GroundPolylineGeometry;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 v_startPlaneNormalEcAndHalfWidth;\\n\\\nin vec4 v_endPlaneNormalEcAndBatchId;\\n\\\nin vec4 v_rightPlaneEC; // Technically can compute distance for this here\\n\\\nin vec4 v_endEcAndStartEcX;\\n\\\nin vec4 v_texcoordNormalizationAndStartEcYZ;\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nin vec4 v_color;\\n\\\n#endif\\n\\\n\\n\\\nvoid main(void)\\n\\\n{\\n\\\n float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw)));\\n\\\n vec3 ecStart = vec3(v_endEcAndStartEcX.w, v_texcoordNormalizationAndStartEcYZ.zw);\\n\\\n\\n\\\n // Discard for sky\\n\\\n if (logDepthOrDepth == 0.0) {\\n\\\n#ifdef DEBUG_SHOW_VOLUME\\n\\\n out_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\\n\\\n return;\\n\\\n#else // DEBUG_SHOW_VOLUME\\n\\\n discard;\\n\\\n#endif // DEBUG_SHOW_VOLUME\\n\\\n }\\n\\\n\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\\n\\\n eyeCoordinate /= eyeCoordinate.w;\\n\\\n\\n\\\n float halfMaxWidth = v_startPlaneNormalEcAndHalfWidth.w * czm_metersPerPixel(eyeCoordinate);\\n\\\n // Check distance of the eye coordinate against the right-facing plane\\n\\\n float widthwiseDistance = czm_planeDistance(v_rightPlaneEC, eyeCoordinate.xyz);\\n\\\n\\n\\\n // Check eye coordinate against the mitering planes\\n\\\n float distanceFromStart = czm_planeDistance(v_startPlaneNormalEcAndHalfWidth.xyz, -dot(ecStart, v_startPlaneNormalEcAndHalfWidth.xyz), eyeCoordinate.xyz);\\n\\\n float distanceFromEnd = czm_planeDistance(v_endPlaneNormalEcAndBatchId.xyz, -dot(v_endEcAndStartEcX.xyz, v_endPlaneNormalEcAndBatchId.xyz), eyeCoordinate.xyz);\\n\\\n\\n\\\n if (abs(widthwiseDistance) > halfMaxWidth || distanceFromStart < 0.0 || distanceFromEnd < 0.0) {\\n\\\n#ifdef DEBUG_SHOW_VOLUME\\n\\\n out_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\\n\\\n return;\\n\\\n#else // DEBUG_SHOW_VOLUME\\n\\\n discard;\\n\\\n#endif // DEBUG_SHOW_VOLUME\\n\\\n }\\n\\\n\\n\\\n // Check distance of the eye coordinate against start and end planes with normals in the right plane.\\n\\\n // For computing unskewed lengthwise texture coordinate.\\n\\\n // Can also be used for clipping extremely pointy miters, but in practice unnecessary because of miter breaking.\\n\\\n\\n\\\n // aligned plane: cross the right plane normal with miter plane normal, then cross the result with right again to point it more \\\"forward\\\"\\n\\\n vec3 alignedPlaneNormal;\\n\\\n\\n\\\n // start aligned plane\\n\\\n alignedPlaneNormal = cross(v_rightPlaneEC.xyz, v_startPlaneNormalEcAndHalfWidth.xyz);\\n\\\n alignedPlaneNormal = normalize(cross(alignedPlaneNormal, v_rightPlaneEC.xyz));\\n\\\n distanceFromStart = czm_planeDistance(alignedPlaneNormal, -dot(alignedPlaneNormal, ecStart), eyeCoordinate.xyz);\\n\\\n\\n\\\n // end aligned plane\\n\\\n alignedPlaneNormal = cross(v_rightPlaneEC.xyz, v_endPlaneNormalEcAndBatchId.xyz);\\n\\\n alignedPlaneNormal = normalize(cross(alignedPlaneNormal, v_rightPlaneEC.xyz));\\n\\\n distanceFromEnd = czm_planeDistance(alignedPlaneNormal, -dot(alignedPlaneNormal, v_endEcAndStartEcX.xyz), eyeCoordinate.xyz);\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n out_FragColor = czm_gammaCorrect(v_color);\\n\\\n#else // PER_INSTANCE_COLOR\\n\\\n // Clamp - distance to aligned planes may be negative due to mitering,\\n\\\n // so fragment texture coordinate might be out-of-bounds.\\n\\\n float s = clamp(distanceFromStart / (distanceFromStart + distanceFromEnd), 0.0, 1.0);\\n\\\n s = (s * v_texcoordNormalizationAndStartEcYZ.x) + v_texcoordNormalizationAndStartEcYZ.y;\\n\\\n float t = (widthwiseDistance + halfMaxWidth) / (2.0 * halfMaxWidth);\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n\\n\\\n materialInput.s = s;\\n\\\n materialInput.st = vec2(s, t);\\n\\\n materialInput.str = vec3(s, t, 0.0);\\n\\\n\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n\\n\\\n // Premultiply alpha. Required for classification primitives on translucent globe.\\n\\\n out_FragColor.rgb *= out_FragColor.a;\\n\\\n\\n\\\n czm_writeDepthClamp();\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_forwardDirectionEC;\\n\\\nin vec3 v_texcoordNormalizationAndHalfWidth;\\n\\\nin float v_batchId;\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nin vec4 v_color;\\n\\\n#else\\n\\\nin vec2 v_alignedPlaneDistances;\\n\\\nin float v_texcoordT;\\n\\\n#endif\\n\\\n\\n\\\nfloat rayPlaneDistanceUnsafe(vec3 origin, vec3 direction, vec3 planeNormal, float planeDistance) {\\n\\\n // We don't expect the ray to ever be parallel to the plane\\n\\\n return (-planeDistance - dot(planeNormal, origin)) / dot(planeNormal, direction);\\n\\\n}\\n\\\n\\n\\\nvoid main(void)\\n\\\n{\\n\\\n vec4 eyeCoordinate = gl_FragCoord;\\n\\\n eyeCoordinate /= eyeCoordinate.w;\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n out_FragColor = czm_gammaCorrect(v_color);\\n\\\n#else // PER_INSTANCE_COLOR\\n\\\n // Use distances for planes aligned with segment to prevent skew in dashing\\n\\\n float distanceFromStart = rayPlaneDistanceUnsafe(eyeCoordinate.xyz, -v_forwardDirectionEC, v_forwardDirectionEC.xyz, v_alignedPlaneDistances.x);\\n\\\n float distanceFromEnd = rayPlaneDistanceUnsafe(eyeCoordinate.xyz, v_forwardDirectionEC, -v_forwardDirectionEC.xyz, v_alignedPlaneDistances.y);\\n\\\n\\n\\\n // Clamp - distance to aligned planes may be negative due to mitering\\n\\\n distanceFromStart = max(0.0, distanceFromStart);\\n\\\n distanceFromEnd = max(0.0, distanceFromEnd);\\n\\\n\\n\\\n float s = distanceFromStart / (distanceFromStart + distanceFromEnd);\\n\\\n s = (s * v_texcoordNormalizationAndHalfWidth.x) + v_texcoordNormalizationAndHalfWidth.y;\\n\\\n\\n\\\n czm_materialInput materialInput;\\n\\\n\\n\\\n materialInput.s = s;\\n\\\n materialInput.st = vec2(s, v_texcoordT);\\n\\\n materialInput.str = vec3(s, v_texcoordT, 0.0);\\n\\\n\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\n\\n\\\nin vec4 startHiAndForwardOffsetX;\\n\\\nin vec4 startLoAndForwardOffsetY;\\n\\\nin vec4 startNormalAndForwardOffsetZ;\\n\\\nin vec4 endNormalAndTextureCoordinateNormalizationX;\\n\\\nin vec4 rightNormalAndTextureCoordinateNormalizationY;\\n\\\nin vec4 startHiLo2D;\\n\\\nin vec4 offsetAndRight2D;\\n\\\nin vec4 startEndNormals2D;\\n\\\nin vec2 texcoordNormalization2D;\\n\\\n\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec3 v_forwardDirectionEC;\\n\\\nout vec3 v_texcoordNormalizationAndHalfWidth;\\n\\\nout float v_batchId;\\n\\\n\\n\\\n// For materials\\n\\\n#ifdef WIDTH_VARYING\\n\\\nout float v_width;\\n\\\n#endif\\n\\\n#ifdef ANGLE_VARYING\\n\\\nout float v_polylineAngle;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nout vec4 v_color;\\n\\\n#else\\n\\\nout vec2 v_alignedPlaneDistances;\\n\\\nout float v_texcoordT;\\n\\\n#endif\\n\\\n\\n\\\n// Morphing planes using SLERP or NLERP doesn't seem to work, so instead draw the material directly on the shadow volume.\\n\\\n// Morph views are from very far away and aren't meant to be used precisely, so this should be sufficient.\\n\\\nvoid main()\\n\\\n{\\n\\\n v_batchId = batchId;\\n\\\n\\n\\\n // Start position\\n\\\n vec4 posRelativeToEye2D = czm_translateRelativeToEye(vec3(0.0, startHiLo2D.xy), vec3(0.0, startHiLo2D.zw));\\n\\\n vec4 posRelativeToEye3D = czm_translateRelativeToEye(startHiAndForwardOffsetX.xyz, startLoAndForwardOffsetY.xyz);\\n\\\n vec4 posRelativeToEye = czm_columbusViewMorph(posRelativeToEye2D, posRelativeToEye3D, czm_morphTime);\\n\\\n vec3 posEc2D = (czm_modelViewRelativeToEye * posRelativeToEye2D).xyz;\\n\\\n vec3 posEc3D = (czm_modelViewRelativeToEye * posRelativeToEye3D).xyz;\\n\\\n vec3 startEC = (czm_modelViewRelativeToEye * posRelativeToEye).xyz;\\n\\\n\\n\\\n // Start plane\\n\\\n vec4 startPlane2D;\\n\\\n vec4 startPlane3D;\\n\\\n startPlane2D.xyz = czm_normal * vec3(0.0, startEndNormals2D.xy);\\n\\\n startPlane3D.xyz = czm_normal * startNormalAndForwardOffsetZ.xyz;\\n\\\n startPlane2D.w = -dot(startPlane2D.xyz, posEc2D);\\n\\\n startPlane3D.w = -dot(startPlane3D.xyz, posEc3D);\\n\\\n\\n\\\n // Right plane\\n\\\n vec4 rightPlane2D;\\n\\\n vec4 rightPlane3D;\\n\\\n rightPlane2D.xyz = czm_normal * vec3(0.0, offsetAndRight2D.zw);\\n\\\n rightPlane3D.xyz = czm_normal * rightNormalAndTextureCoordinateNormalizationY.xyz;\\n\\\n rightPlane2D.w = -dot(rightPlane2D.xyz, posEc2D);\\n\\\n rightPlane3D.w = -dot(rightPlane3D.xyz, posEc3D);\\n\\\n\\n\\\n // End position\\n\\\n posRelativeToEye2D = posRelativeToEye2D + vec4(0.0, offsetAndRight2D.xy, 0.0);\\n\\\n posRelativeToEye3D = posRelativeToEye3D + vec4(startHiAndForwardOffsetX.w, startLoAndForwardOffsetY.w, startNormalAndForwardOffsetZ.w, 0.0);\\n\\\n posRelativeToEye = czm_columbusViewMorph(posRelativeToEye2D, posRelativeToEye3D, czm_morphTime);\\n\\\n posEc2D = (czm_modelViewRelativeToEye * posRelativeToEye2D).xyz;\\n\\\n posEc3D = (czm_modelViewRelativeToEye * posRelativeToEye3D).xyz;\\n\\\n vec3 endEC = (czm_modelViewRelativeToEye * posRelativeToEye).xyz;\\n\\\n vec3 forwardEc3D = czm_normal * normalize(vec3(startHiAndForwardOffsetX.w, startLoAndForwardOffsetY.w, startNormalAndForwardOffsetZ.w));\\n\\\n vec3 forwardEc2D = czm_normal * normalize(vec3(0.0, offsetAndRight2D.xy));\\n\\\n\\n\\\n // End plane\\n\\\n vec4 endPlane2D;\\n\\\n vec4 endPlane3D;\\n\\\n endPlane2D.xyz = czm_normal * vec3(0.0, startEndNormals2D.zw);\\n\\\n endPlane3D.xyz = czm_normal * endNormalAndTextureCoordinateNormalizationX.xyz;\\n\\\n endPlane2D.w = -dot(endPlane2D.xyz, posEc2D);\\n\\\n endPlane3D.w = -dot(endPlane3D.xyz, posEc3D);\\n\\\n\\n\\\n // Forward direction\\n\\\n v_forwardDirectionEC = normalize(endEC - startEC);\\n\\\n\\n\\\n vec2 cleanTexcoordNormalization2D;\\n\\\n cleanTexcoordNormalization2D.x = abs(texcoordNormalization2D.x);\\n\\\n cleanTexcoordNormalization2D.y = czm_branchFreeTernary(texcoordNormalization2D.y > 1.0, 0.0, abs(texcoordNormalization2D.y));\\n\\\n vec2 cleanTexcoordNormalization3D;\\n\\\n cleanTexcoordNormalization3D.x = abs(endNormalAndTextureCoordinateNormalizationX.w);\\n\\\n cleanTexcoordNormalization3D.y = rightNormalAndTextureCoordinateNormalizationY.w;\\n\\\n cleanTexcoordNormalization3D.y = czm_branchFreeTernary(cleanTexcoordNormalization3D.y > 1.0, 0.0, abs(cleanTexcoordNormalization3D.y));\\n\\\n\\n\\\n v_texcoordNormalizationAndHalfWidth.xy = mix(cleanTexcoordNormalization2D, cleanTexcoordNormalization3D, czm_morphTime);\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n v_color = czm_batchTable_color(batchId);\\n\\\n#else // PER_INSTANCE_COLOR\\n\\\n // For computing texture coordinates\\n\\\n\\n\\\n v_alignedPlaneDistances.x = -dot(v_forwardDirectionEC, startEC);\\n\\\n v_alignedPlaneDistances.y = -dot(-v_forwardDirectionEC, endEC);\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n\\n\\\n#ifdef WIDTH_VARYING\\n\\\n float width = czm_batchTable_width(batchId);\\n\\\n float halfWidth = width * 0.5;\\n\\\n v_width = width;\\n\\\n v_texcoordNormalizationAndHalfWidth.z = halfWidth;\\n\\\n#else\\n\\\n float halfWidth = 0.5 * czm_batchTable_width(batchId);\\n\\\n v_texcoordNormalizationAndHalfWidth.z = halfWidth;\\n\\\n#endif\\n\\\n\\n\\\n // Compute a normal along which to \\\"push\\\" the position out, extending the miter depending on view distance.\\n\\\n // Position has already been \\\"pushed\\\" by unit length along miter normal, and miter normals are encoded in the planes.\\n\\\n // Decode the normal to use at this specific vertex, push the position back, and then push to where it needs to be.\\n\\\n // Since this is morphing, compute both 3D and 2D positions and then blend.\\n\\\n\\n\\\n // ****** 3D ******\\n\\\n // Check distance to the end plane and start plane, pick the plane that is closer\\n\\\n vec4 positionEc3D = czm_modelViewRelativeToEye * czm_translateRelativeToEye(position3DHigh, position3DLow); // w = 1.0, see czm_computePosition\\n\\\n float absStartPlaneDistance = abs(czm_planeDistance(startPlane3D, positionEc3D.xyz));\\n\\\n float absEndPlaneDistance = abs(czm_planeDistance(endPlane3D, positionEc3D.xyz));\\n\\\n vec3 planeDirection = czm_branchFreeTernary(absStartPlaneDistance < absEndPlaneDistance, startPlane3D.xyz, endPlane3D.xyz);\\n\\\n vec3 upOrDown = normalize(cross(rightPlane3D.xyz, planeDirection)); // Points \\\"up\\\" for start plane, \\\"down\\\" at end plane.\\n\\\n vec3 normalEC = normalize(cross(planeDirection, upOrDown)); // In practice, the opposite seems to work too.\\n\\\n\\n\\\n // Nudge the top vertex upwards to prevent flickering\\n\\\n vec3 geodeticSurfaceNormal = normalize(cross(normalEC, forwardEc3D));\\n\\\n geodeticSurfaceNormal *= float(0.0 <= rightNormalAndTextureCoordinateNormalizationY.w && rightNormalAndTextureCoordinateNormalizationY.w <= 1.0);\\n\\\n geodeticSurfaceNormal *= MAX_TERRAIN_HEIGHT;\\n\\\n positionEc3D.xyz += geodeticSurfaceNormal;\\n\\\n\\n\\\n // Determine if this vertex is on the \\\"left\\\" or \\\"right\\\"\\n\\\n normalEC *= sign(endNormalAndTextureCoordinateNormalizationX.w);\\n\\\n\\n\\\n // A \\\"perfect\\\" implementation would push along normals according to the angle against forward.\\n\\\n // In practice, just pushing the normal out by halfWidth is sufficient for morph views.\\n\\\n positionEc3D.xyz += halfWidth * max(0.0, czm_metersPerPixel(positionEc3D)) * normalEC; // prevent artifacts when czm_metersPerPixel is negative (behind camera)\\n\\\n\\n\\\n // ****** 2D ******\\n\\\n // Check distance to the end plane and start plane, pick the plane that is closer\\n\\\n vec4 positionEc2D = czm_modelViewRelativeToEye * czm_translateRelativeToEye(position2DHigh.zxy, position2DLow.zxy); // w = 1.0, see czm_computePosition\\n\\\n absStartPlaneDistance = abs(czm_planeDistance(startPlane2D, positionEc2D.xyz));\\n\\\n absEndPlaneDistance = abs(czm_planeDistance(endPlane2D, positionEc2D.xyz));\\n\\\n planeDirection = czm_branchFreeTernary(absStartPlaneDistance < absEndPlaneDistance, startPlane2D.xyz, endPlane2D.xyz);\\n\\\n upOrDown = normalize(cross(rightPlane2D.xyz, planeDirection)); // Points \\\"up\\\" for start plane, \\\"down\\\" at end plane.\\n\\\n normalEC = normalize(cross(planeDirection, upOrDown)); // In practice, the opposite seems to work too.\\n\\\n\\n\\\n // Nudge the top vertex upwards to prevent flickering\\n\\\n geodeticSurfaceNormal = normalize(cross(normalEC, forwardEc2D));\\n\\\n geodeticSurfaceNormal *= float(0.0 <= texcoordNormalization2D.y && texcoordNormalization2D.y <= 1.0);\\n\\\n geodeticSurfaceNormal *= MAX_TERRAIN_HEIGHT;\\n\\\n positionEc2D.xyz += geodeticSurfaceNormal;\\n\\\n\\n\\\n // Determine if this vertex is on the \\\"left\\\" or \\\"right\\\"\\n\\\n normalEC *= sign(texcoordNormalization2D.x);\\n\\\n#ifndef PER_INSTANCE_COLOR\\n\\\n // Use vertex's sidedness to compute its texture coordinate.\\n\\\n v_texcoordT = clamp(sign(texcoordNormalization2D.x), 0.0, 1.0);\\n\\\n#endif\\n\\\n\\n\\\n // A \\\"perfect\\\" implementation would push along normals according to the angle against forward.\\n\\\n // In practice, just pushing the normal out by halfWidth is sufficient for morph views.\\n\\\n positionEc2D.xyz += halfWidth * max(0.0, czm_metersPerPixel(positionEc2D)) * normalEC; // prevent artifacts when czm_metersPerPixel is negative (behind camera)\\n\\\n\\n\\\n // Blend for actual position\\n\\\n gl_Position = czm_projection * mix(positionEc2D, positionEc3D, czm_morphTime);\\n\\\n\\n\\\n#ifdef ANGLE_VARYING\\n\\\n // Approximate relative screen space direction of the line.\\n\\\n vec2 approxLineDirection = normalize(vec2(v_forwardDirectionEC.x, -v_forwardDirectionEC.y));\\n\\\n approxLineDirection.y = czm_branchFreeTernary(approxLineDirection.x == 0.0 && approxLineDirection.y == 0.0, -1.0, approxLineDirection.y);\\n\\\n v_polylineAngle = czm_fastApproximateAtan(approxLineDirection.x, approxLineDirection.y);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\n\\n\\\n// In 2D and in 3D, texture coordinate normalization component signs encodes:\\n\\\n// * X sign - sidedness relative to right plane\\n\\\n// * Y sign - is negative OR magnitude is greater than 1.0 if vertex is on bottom of volume\\n\\\n#ifndef COLUMBUS_VIEW_2D\\n\\\nin vec4 startHiAndForwardOffsetX;\\n\\\nin vec4 startLoAndForwardOffsetY;\\n\\\nin vec4 startNormalAndForwardOffsetZ;\\n\\\nin vec4 endNormalAndTextureCoordinateNormalizationX;\\n\\\nin vec4 rightNormalAndTextureCoordinateNormalizationY;\\n\\\n#else\\n\\\nin vec4 startHiLo2D;\\n\\\nin vec4 offsetAndRight2D;\\n\\\nin vec4 startEndNormals2D;\\n\\\nin vec2 texcoordNormalization2D;\\n\\\n#endif\\n\\\n\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec4 v_startPlaneNormalEcAndHalfWidth;\\n\\\nout vec4 v_endPlaneNormalEcAndBatchId;\\n\\\nout vec4 v_rightPlaneEC;\\n\\\nout vec4 v_endEcAndStartEcX;\\n\\\nout vec4 v_texcoordNormalizationAndStartEcYZ;\\n\\\n\\n\\\n// For materials\\n\\\n#ifdef WIDTH_VARYING\\n\\\nout float v_width;\\n\\\n#endif\\n\\\n#ifdef ANGLE_VARYING\\n\\\nout float v_polylineAngle;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\nout vec4 v_color;\\n\\\n#endif\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n#ifdef COLUMBUS_VIEW_2D\\n\\\n vec3 ecStart = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(vec3(0.0, startHiLo2D.xy), vec3(0.0, startHiLo2D.zw))).xyz;\\n\\\n\\n\\\n vec3 forwardDirectionEC = czm_normal * vec3(0.0, offsetAndRight2D.xy);\\n\\\n vec3 ecEnd = forwardDirectionEC + ecStart;\\n\\\n forwardDirectionEC = normalize(forwardDirectionEC);\\n\\\n\\n\\\n // Right plane\\n\\\n v_rightPlaneEC.xyz = czm_normal * vec3(0.0, offsetAndRight2D.zw);\\n\\\n v_rightPlaneEC.w = -dot(v_rightPlaneEC.xyz, ecStart);\\n\\\n\\n\\\n // start plane\\n\\\n vec4 startPlaneEC;\\n\\\n startPlaneEC.xyz = czm_normal * vec3(0.0, startEndNormals2D.xy);\\n\\\n startPlaneEC.w = -dot(startPlaneEC.xyz, ecStart);\\n\\\n\\n\\\n // end plane\\n\\\n vec4 endPlaneEC;\\n\\\n endPlaneEC.xyz = czm_normal * vec3(0.0, startEndNormals2D.zw);\\n\\\n endPlaneEC.w = -dot(endPlaneEC.xyz, ecEnd);\\n\\\n\\n\\\n v_texcoordNormalizationAndStartEcYZ.x = abs(texcoordNormalization2D.x);\\n\\\n v_texcoordNormalizationAndStartEcYZ.y = texcoordNormalization2D.y;\\n\\\n\\n\\\n#else // COLUMBUS_VIEW_2D\\n\\\n vec3 ecStart = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(startHiAndForwardOffsetX.xyz, startLoAndForwardOffsetY.xyz)).xyz;\\n\\\n vec3 offset = czm_normal * vec3(startHiAndForwardOffsetX.w, startLoAndForwardOffsetY.w, startNormalAndForwardOffsetZ.w);\\n\\\n vec3 ecEnd = ecStart + offset;\\n\\\n\\n\\\n vec3 forwardDirectionEC = normalize(offset);\\n\\\n\\n\\\n // start plane\\n\\\n vec4 startPlaneEC;\\n\\\n startPlaneEC.xyz = czm_normal * startNormalAndForwardOffsetZ.xyz;\\n\\\n startPlaneEC.w = -dot(startPlaneEC.xyz, ecStart);\\n\\\n\\n\\\n // end plane\\n\\\n vec4 endPlaneEC;\\n\\\n endPlaneEC.xyz = czm_normal * endNormalAndTextureCoordinateNormalizationX.xyz;\\n\\\n endPlaneEC.w = -dot(endPlaneEC.xyz, ecEnd);\\n\\\n\\n\\\n // Right plane\\n\\\n v_rightPlaneEC.xyz = czm_normal * rightNormalAndTextureCoordinateNormalizationY.xyz;\\n\\\n v_rightPlaneEC.w = -dot(v_rightPlaneEC.xyz, ecStart);\\n\\\n\\n\\\n v_texcoordNormalizationAndStartEcYZ.x = abs(endNormalAndTextureCoordinateNormalizationX.w);\\n\\\n v_texcoordNormalizationAndStartEcYZ.y = rightNormalAndTextureCoordinateNormalizationY.w;\\n\\\n\\n\\\n#endif // COLUMBUS_VIEW_2D\\n\\\n\\n\\\n v_endEcAndStartEcX.xyz = ecEnd;\\n\\\n v_endEcAndStartEcX.w = ecStart.x;\\n\\\n v_texcoordNormalizationAndStartEcYZ.zw = ecStart.yz;\\n\\\n\\n\\\n#ifdef PER_INSTANCE_COLOR\\n\\\n v_color = czm_batchTable_color(batchId);\\n\\\n#endif // PER_INSTANCE_COLOR\\n\\\n\\n\\\n // Compute a normal along which to \\\"push\\\" the position out, extending the miter depending on view distance.\\n\\\n // Position has already been \\\"pushed\\\" by unit length along miter normal, and miter normals are encoded in the planes.\\n\\\n // Decode the normal to use at this specific vertex, push the position back, and then push to where it needs to be.\\n\\\n vec4 positionRelativeToEye = czm_computePosition();\\n\\\n\\n\\\n // Check distance to the end plane and start plane, pick the plane that is closer\\n\\\n vec4 positionEC = czm_modelViewRelativeToEye * positionRelativeToEye; // w = 1.0, see czm_computePosition\\n\\\n float absStartPlaneDistance = abs(czm_planeDistance(startPlaneEC, positionEC.xyz));\\n\\\n float absEndPlaneDistance = abs(czm_planeDistance(endPlaneEC, positionEC.xyz));\\n\\\n vec3 planeDirection = czm_branchFreeTernary(absStartPlaneDistance < absEndPlaneDistance, startPlaneEC.xyz, endPlaneEC.xyz);\\n\\\n vec3 upOrDown = normalize(cross(v_rightPlaneEC.xyz, planeDirection)); // Points \\\"up\\\" for start plane, \\\"down\\\" at end plane.\\n\\\n vec3 normalEC = normalize(cross(planeDirection, upOrDown)); // In practice, the opposite seems to work too.\\n\\\n\\n\\\n // Extrude bottom vertices downward for far view distances, like for GroundPrimitives\\n\\\n upOrDown = cross(forwardDirectionEC, normalEC);\\n\\\n upOrDown = float(czm_sceneMode == czm_sceneMode3D) * upOrDown;\\n\\\n upOrDown = float(v_texcoordNormalizationAndStartEcYZ.y > 1.0 || v_texcoordNormalizationAndStartEcYZ.y < 0.0) * upOrDown;\\n\\\n upOrDown = min(GLOBE_MINIMUM_ALTITUDE, czm_geometricToleranceOverMeter * length(positionRelativeToEye.xyz)) * upOrDown;\\n\\\n positionEC.xyz += upOrDown;\\n\\\n\\n\\\n v_texcoordNormalizationAndStartEcYZ.y = czm_branchFreeTernary(v_texcoordNormalizationAndStartEcYZ.y > 1.0, 0.0, abs(v_texcoordNormalizationAndStartEcYZ.y));\\n\\\n\\n\\\n // Determine distance along normalEC to push for a volume of appropriate width.\\n\\\n // Make volumes about double pixel width for a conservative fit - in practice the\\n\\\n // extra cost here is minimal compared to the loose volume heights.\\n\\\n //\\n\\\n // N = normalEC (guaranteed \\\"right-facing\\\")\\n\\\n // R = rightEC\\n\\\n // p = angle between N and R\\n\\\n // w = distance to push along R if R == N\\n\\\n // d = distance to push along N\\n\\\n //\\n\\\n // N R\\n\\\n // { \\ p| } * cos(p) = dot(N, R) = w / d\\n\\\n // d\\ \\ | |w * d = w / dot(N, R)\\n\\\n // { \\| }\\n\\\n // o---------- polyline segment ---->\\n\\\n //\\n\\\n float width = czm_batchTable_width(batchId);\\n\\\n#ifdef WIDTH_VARYING\\n\\\n v_width = width;\\n\\\n#endif\\n\\\n\\n\\\n v_startPlaneNormalEcAndHalfWidth.xyz = startPlaneEC.xyz;\\n\\\n v_startPlaneNormalEcAndHalfWidth.w = width * 0.5;\\n\\\n\\n\\\n v_endPlaneNormalEcAndBatchId.xyz = endPlaneEC.xyz;\\n\\\n v_endPlaneNormalEcAndBatchId.w = batchId;\\n\\\n\\n\\\n width = width * max(0.0, czm_metersPerPixel(positionEC)); // width = distance to push along R\\n\\\n width = width / dot(normalEC, v_rightPlaneEC.xyz); // width = distance to push along N\\n\\\n\\n\\\n // Determine if this vertex is on the \\\"left\\\" or \\\"right\\\"\\n\\\n#ifdef COLUMBUS_VIEW_2D\\n\\\n normalEC *= sign(texcoordNormalization2D.x);\\n\\\n#else\\n\\\n normalEC *= sign(endNormalAndTextureCoordinateNormalizationX.w);\\n\\\n#endif\\n\\\n\\n\\\n positionEC.xyz += width * normalEC;\\n\\\n gl_Position = czm_depthClamp(czm_projection * positionEC);\\n\\\n\\n\\\n#ifdef ANGLE_VARYING\\n\\\n // Approximate relative screen space direction of the line.\\n\\\n vec2 approxLineDirection = normalize(vec2(forwardDirectionEC.x, -forwardDirectionEC.y));\\n\\\n approxLineDirection.y = czm_branchFreeTernary(approxLineDirection.x == 0.0 && approxLineDirection.y == 0.0, -1.0, approxLineDirection.y);\\n\\\n v_polylineAngle = czm_fastApproximateAtan(approxLineDirection.x, approxLineDirection.y);\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 prevPosition3DHigh;\\n\\\nin vec3 prevPosition3DLow;\\n\\\nin vec3 nextPosition3DHigh;\\n\\\nin vec3 nextPosition3DLow;\\n\\\nin vec2 expandAndWidth;\\n\\\nin vec4 color;\\n\\\nin float batchId;\\n\\\n\\n\\\nout vec4 v_color;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n float expandDir = expandAndWidth.x;\\n\\\n float width = abs(expandAndWidth.y) + 0.5;\\n\\\n bool usePrev = expandAndWidth.y < 0.0;\\n\\\n\\n\\\n vec4 p = czm_computePosition();\\n\\\n vec4 prev = czm_computePrevPosition();\\n\\\n vec4 next = czm_computeNextPosition();\\n\\\n\\n\\\n float angle;\\n\\\n vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);\\n\\\n gl_Position = czm_viewportOrthographic * positionWC;\\n\\\n\\n\\\n v_color = color;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void clipLineSegmentToNearPlane(\\n\\\n vec3 p0,\\n\\\n vec3 p1,\\n\\\n out vec4 positionWC,\\n\\\n out bool clipped,\\n\\\n out bool culledByNearPlane,\\n\\\n out vec4 clippedPositionEC)\\n\\\n{\\n\\\n culledByNearPlane = false;\\n\\\n clipped = false;\\n\\\n\\n\\\n vec3 p0ToP1 = p1 - p0;\\n\\\n float magnitude = length(p0ToP1);\\n\\\n vec3 direction = normalize(p0ToP1);\\n\\\n\\n\\\n // Distance that p0 is behind the near plane. Negative means p0 is\\n\\\n // in front of the near plane.\\n\\\n float endPoint0Distance = czm_currentFrustum.x + p0.z;\\n\\\n\\n\\\n // Camera looks down -Z.\\n\\\n // When moving a point along +Z: LESS VISIBLE\\n\\\n // * Points in front of the camera move closer to the camera.\\n\\\n // * Points behind the camrea move farther away from the camera.\\n\\\n // When moving a point along -Z: MORE VISIBLE\\n\\\n // * Points in front of the camera move farther away from the camera.\\n\\\n // * Points behind the camera move closer to the camera.\\n\\\n\\n\\\n // Positive denominator: -Z, becoming more visible\\n\\\n // Negative denominator: +Z, becoming less visible\\n\\\n // Nearly zero: parallel to near plane\\n\\\n float denominator = -direction.z;\\n\\\n\\n\\\n if (endPoint0Distance > 0.0 && abs(denominator) < czm_epsilon7)\\n\\\n {\\n\\\n // p0 is behind the near plane and the line to p1 is nearly parallel to\\n\\\n // the near plane, so cull the segment completely.\\n\\\n culledByNearPlane = true;\\n\\\n }\\n\\\n else if (endPoint0Distance > 0.0)\\n\\\n {\\n\\\n // p0 is behind the near plane, and the line to p1 is moving distinctly\\n\\\n // toward or away from it.\\n\\\n\\n\\\n // t = (-plane distance - dot(plane normal, ray origin)) / dot(plane normal, ray direction)\\n\\\n float t = endPoint0Distance / denominator;\\n\\\n if (t < 0.0 || t > magnitude)\\n\\\n {\\n\\\n // Near plane intersection is not between the two points.\\n\\\n // We already confirmed p0 is behind the naer plane, so now\\n\\\n // we know the entire segment is behind it.\\n\\\n culledByNearPlane = true;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n // Segment crosses the near plane, update p0 to lie exactly on it.\\n\\\n p0 = p0 + t * direction;\\n\\\n\\n\\\n // Numerical noise might put us a bit on the wrong side of the near plane.\\n\\\n // Don't let that happen.\\n\\\n p0.z = min(p0.z, -czm_currentFrustum.x);\\n\\\n\\n\\\n clipped = true;\\n\\\n }\\n\\\n }\\n\\\n\\n\\\n clippedPositionEC = vec4(p0, 1.0);\\n\\\n positionWC = czm_eyeToWindowCoordinates(clippedPositionEC);\\n\\\n}\\n\\\n\\n\\\nvec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)\\n\\\n{\\n\\\n // expandDirection +1 is to the _left_ when looking from positionEC toward nextEC.\\n\\\n\\n\\\n#ifdef POLYLINE_DASH\\n\\\n // Compute the window coordinates of the points.\\n\\\n vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);\\n\\\n vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);\\n\\\n vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);\\n\\\n\\n\\\n // Determine the relative screen space direction of the line.\\n\\\n vec2 lineDir;\\n\\\n if (usePrevious) {\\n\\\n lineDir = normalize(positionWindow.xy - previousWindow.xy);\\n\\\n }\\n\\\n else {\\n\\\n lineDir = normalize(nextWindow.xy - positionWindow.xy);\\n\\\n }\\n\\\n angle = atan(lineDir.x, lineDir.y) - 1.570796327; // precomputed atan(1,0)\\n\\\n\\n\\\n // Quantize the angle so it doesn't change rapidly between segments.\\n\\\n angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;\\n\\\n#endif\\n\\\n\\n\\\n vec4 clippedPrevWC, clippedPrevEC;\\n\\\n bool prevSegmentClipped, prevSegmentCulled;\\n\\\n clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, clippedPrevWC, prevSegmentClipped, prevSegmentCulled, clippedPrevEC);\\n\\\n\\n\\\n vec4 clippedNextWC, clippedNextEC;\\n\\\n bool nextSegmentClipped, nextSegmentCulled;\\n\\\n clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, clippedNextWC, nextSegmentClipped, nextSegmentCulled, clippedNextEC);\\n\\\n\\n\\\n bool segmentClipped, segmentCulled;\\n\\\n vec4 clippedPositionWC, clippedPositionEC;\\n\\\n clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, clippedPositionWC, segmentClipped, segmentCulled, clippedPositionEC);\\n\\\n\\n\\\n if (segmentCulled)\\n\\\n {\\n\\\n return vec4(0.0, 0.0, 0.0, 1.0);\\n\\\n }\\n\\\n\\n\\\n vec2 directionToPrevWC = normalize(clippedPrevWC.xy - clippedPositionWC.xy);\\n\\\n vec2 directionToNextWC = normalize(clippedNextWC.xy - clippedPositionWC.xy);\\n\\\n\\n\\\n // If a segment was culled, we can't use the corresponding direction\\n\\\n // computed above. We should never see both of these be true without\\n\\\n // `segmentCulled` above also being true.\\n\\\n if (prevSegmentCulled)\\n\\\n {\\n\\\n directionToPrevWC = -directionToNextWC;\\n\\\n }\\n\\\n else if (nextSegmentCulled)\\n\\\n {\\n\\\n directionToNextWC = -directionToPrevWC;\\n\\\n }\\n\\\n\\n\\\n vec2 thisSegmentForwardWC, otherSegmentForwardWC;\\n\\\n if (usePrevious)\\n\\\n {\\n\\\n thisSegmentForwardWC = -directionToPrevWC;\\n\\\n otherSegmentForwardWC = directionToNextWC;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n thisSegmentForwardWC = directionToNextWC;\\n\\\n otherSegmentForwardWC = -directionToPrevWC;\\n\\\n }\\n\\\n\\n\\\n vec2 thisSegmentLeftWC = vec2(-thisSegmentForwardWC.y, thisSegmentForwardWC.x);\\n\\\n\\n\\\n vec2 leftWC = thisSegmentLeftWC;\\n\\\n float expandWidth = width * 0.5;\\n\\\n\\n\\\n // When lines are split at the anti-meridian, the position may be at the\\n\\\n // same location as the next or previous position, and we need to handle\\n\\\n // that to avoid producing NaNs.\\n\\\n if (!czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) && !czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))\\n\\\n {\\n\\\n vec2 otherSegmentLeftWC = vec2(-otherSegmentForwardWC.y, otherSegmentForwardWC.x);\\n\\\n\\n\\\n vec2 leftSumWC = thisSegmentLeftWC + otherSegmentLeftWC;\\n\\\n float leftSumLength = length(leftSumWC);\\n\\\n leftWC = leftSumLength < czm_epsilon6 ? thisSegmentLeftWC : (leftSumWC / leftSumLength);\\n\\\n\\n\\\n // The sine of the angle between the two vectors is given by the formula\\n\\\n // |a x b| = |a||b|sin(theta)\\n\\\n // which is\\n\\\n // float sinAngle = length(cross(vec3(leftWC, 0.0), vec3(-thisSegmentForwardWC, 0.0)));\\n\\\n // Because the z components of both vectors are zero, the x and y coordinate will be zero.\\n\\\n // Therefore, the sine of the angle is just the z component of the cross product.\\n\\\n vec2 u = -thisSegmentForwardWC;\\n\\\n vec2 v = leftWC;\\n\\\n float sinAngle = abs(u.x * v.y - u.y * v.x);\\n\\\n expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);\\n\\\n }\\n\\\n\\n\\\n vec2 offset = leftWC * expandDirection * expandWidth * czm_pixelRatio;\\n\\\n return vec4(clippedPositionWC.xy + offset, -clippedPositionWC.z, 1.0) * (czm_projection * clippedPositionEC).w;\\n\\\n}\\n\\\n\\n\\\nvec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)\\n\\\n{\\n\\\n vec4 positionEC = czm_modelViewRelativeToEye * position;\\n\\\n vec4 prevEC = czm_modelViewRelativeToEye * previous;\\n\\\n vec4 nextEC = czm_modelViewRelativeToEye * next;\\n\\\n return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);\\n\\\n}\\n\\\n\";\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport VertexFormat from \"../Core/VertexFormat.js\";\nimport PerInstanceFlatColorAppearanceFS from \"../Shaders/Appearances/PerInstanceFlatColorAppearanceFS.js\";\nimport PolylineColorAppearanceVS from \"../Shaders/Appearances/PolylineColorAppearanceVS.js\";\nimport PolylineCommon from \"../Shaders/PolylineCommon.js\";\nimport Appearance from \"./Appearance.js\";\n\nlet defaultVertexShaderSource = `${PolylineCommon}\\n${PolylineColorAppearanceVS}`;\nconst defaultFragmentShaderSource = PerInstanceFlatColorAppearanceFS;\n\nif (!FeatureDetection.isInternetExplorer()) {\n defaultVertexShaderSource = `#define CLIP_POLYLINE \\n${defaultVertexShaderSource}`;\n}\n\n/**\n * An appearance for {@link GeometryInstance} instances with color attributes and\n * {@link PolylineGeometry} or {@link GroundPolylineGeometry}.\n * This allows several geometry instances, each with a different color, to\n * be drawn with the same {@link Primitive}.\n *\n * @alias PolylineColorAppearance\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so {@link PolylineColorAppearance#renderState} has alpha blending enabled.\n * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.\n * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.\n * @param {object} [options.renderState] Optional render state to override the default render state.\n *\n * @example\n * // A solid white line segment\n * const primitive = new Cesium.Primitive({\n * geometryInstances : new Cesium.GeometryInstance({\n * geometry : new Cesium.PolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 0.0, 0.0,\n * 5.0, 0.0\n * ]),\n * width : 10.0,\n * vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT\n * }),\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0))\n * }\n * }),\n * appearance : new Cesium.PolylineColorAppearance({\n * translucent : false\n * })\n * });\n */\nfunction PolylineColorAppearance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const translucent = defaultValue(options.translucent, true);\n const closed = false;\n const vertexFormat = PolylineColorAppearance.VERTEX_FORMAT;\n\n /**\n * This property is part of the {@link Appearance} interface, but is not\n * used by {@link PolylineColorAppearance} since a fully custom fragment shader is used.\n *\n * @type Material\n *\n * @default undefined\n */\n this.material = undefined;\n\n /**\n * When true, the geometry is expected to appear translucent so\n * {@link PolylineColorAppearance#renderState} has alpha blending enabled.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.translucent = translucent;\n\n this._vertexShaderSource = defaultValue(\n options.vertexShaderSource,\n defaultVertexShaderSource\n );\n this._fragmentShaderSource = defaultValue(\n options.fragmentShaderSource,\n defaultFragmentShaderSource\n );\n this._renderState = Appearance.getDefaultRenderState(\n translucent,\n closed,\n options.renderState\n );\n this._closed = closed;\n\n // Non-derived members\n\n this._vertexFormat = vertexFormat;\n}\n\nObject.defineProperties(PolylineColorAppearance.prototype, {\n /**\n * The GLSL source code for the vertex shader.\n *\n * @memberof PolylineColorAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n return this._vertexShaderSource;\n },\n },\n\n /**\n * The GLSL source code for the fragment shader.\n *\n * @memberof PolylineColorAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n\n /**\n * The WebGL fixed-function state to use when rendering the geometry.\n *

\n * The render state can be explicitly defined when constructing a {@link PolylineColorAppearance}\n * instance, or it is set implicitly via {@link PolylineColorAppearance#translucent}.\n *

\n *\n * @memberof PolylineColorAppearance.prototype\n *\n * @type {object}\n * @readonly\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n },\n\n /**\n * When true, the geometry is expected to be closed so\n * {@link PolylineColorAppearance#renderState} has backface culling enabled.\n * This is always false for PolylineColorAppearance.\n *\n * @memberof PolylineColorAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n closed: {\n get: function () {\n return this._closed;\n },\n },\n\n /**\n * The {@link VertexFormat} that this appearance instance is compatible with.\n * A geometry can have more vertex attributes and still be compatible - at a\n * potential performance cost - but it can't have less.\n *\n * @memberof PolylineColorAppearance.prototype\n *\n * @type VertexFormat\n * @readonly\n *\n * @default {@link PolylineColorAppearance.VERTEX_FORMAT}\n */\n vertexFormat: {\n get: function () {\n return this._vertexFormat;\n },\n },\n});\n\n/**\n * The {@link VertexFormat} that all {@link PolylineColorAppearance} instances\n * are compatible with. This requires only a position attribute.\n *\n * @type VertexFormat\n *\n * @constant\n */\nPolylineColorAppearance.VERTEX_FORMAT = VertexFormat.POSITION_ONLY;\n\n/**\n * Procedurally creates the full GLSL fragment shader source.\n *\n * @function\n *\n * @returns {string} The full GLSL fragment shader source.\n */\nPolylineColorAppearance.prototype.getFragmentShaderSource =\n Appearance.prototype.getFragmentShaderSource;\n\n/**\n * Determines if the geometry is translucent based on {@link PolylineColorAppearance#translucent}.\n *\n * @function\n *\n * @returns {boolean} true if the appearance is translucent.\n */\nPolylineColorAppearance.prototype.isTranslucent =\n Appearance.prototype.isTranslucent;\n\n/**\n * Creates a render state. This is not the final render state instance; instead,\n * it can contain a subset of render state properties identical to the render state\n * created in the context.\n *\n * @function\n *\n * @returns {object} The render state.\n */\nPolylineColorAppearance.prototype.getRenderState =\n Appearance.prototype.getRenderState;\nexport default PolylineColorAppearance;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 prevPosition3DHigh;\\n\\\nin vec3 prevPosition3DLow;\\n\\\nin vec3 nextPosition3DHigh;\\n\\\nin vec3 nextPosition3DLow;\\n\\\nin vec2 expandAndWidth;\\n\\\nin vec2 st;\\n\\\nin float batchId;\\n\\\n\\n\\\nout float v_width;\\n\\\nout vec2 v_st;\\n\\\nout float v_polylineAngle;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n float expandDir = expandAndWidth.x;\\n\\\n float width = abs(expandAndWidth.y) + 0.5;\\n\\\n bool usePrev = expandAndWidth.y < 0.0;\\n\\\n\\n\\\n vec4 p = czm_computePosition();\\n\\\n vec4 prev = czm_computePrevPosition();\\n\\\n vec4 next = czm_computeNextPosition();\\n\\\n\\n\\\n float angle;\\n\\\n vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);\\n\\\n gl_Position = czm_viewportOrthographic * positionWC;\\n\\\n\\n\\\n v_width = width;\\n\\\n v_st.s = st.s;\\n\\\n v_st.t = czm_writeNonPerspective(st.t, gl_Position.w);\\n\\\n v_polylineAngle = angle;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef VECTOR_TILE\\n\\\nuniform vec4 u_highlightColor;\\n\\\n#endif\\n\\\n\\n\\\nin vec2 v_st;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n czm_materialInput materialInput;\\n\\\n\\n\\\n vec2 st = v_st;\\n\\\n st.t = czm_readNonPerspective(st.t, gl_FragCoord.w);\\n\\\n\\n\\\n materialInput.s = st.s;\\n\\\n materialInput.st = st;\\n\\\n materialInput.str = vec3(st, 0.0);\\n\\\n\\n\\\n czm_material material = czm_getMaterial(materialInput);\\n\\\n out_FragColor = vec4(material.diffuse + material.emission, material.alpha);\\n\\\n#ifdef VECTOR_TILE\\n\\\n out_FragColor *= u_highlightColor;\\n\\\n#endif\\n\\\n\\n\\\n czm_writeLogDepth();\\n\\\n}\\n\\\n\";\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport VertexFormat from \"../Core/VertexFormat.js\";\nimport PolylineMaterialAppearanceVS from \"../Shaders/Appearances/PolylineMaterialAppearanceVS.js\";\nimport PolylineCommon from \"../Shaders/PolylineCommon.js\";\nimport PolylineFS from \"../Shaders/PolylineFS.js\";\nimport Appearance from \"./Appearance.js\";\nimport Material from \"./Material.js\";\n\nlet defaultVertexShaderSource = `${PolylineCommon}\\n${PolylineMaterialAppearanceVS}`;\nconst defaultFragmentShaderSource = PolylineFS;\n\nif (!FeatureDetection.isInternetExplorer()) {\n defaultVertexShaderSource = `#define CLIP_POLYLINE \\n${defaultVertexShaderSource}`;\n}\n\n/**\n * An appearance for {@link PolylineGeometry} that supports shading with materials.\n *\n * @alias PolylineMaterialAppearance\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so {@link PolylineMaterialAppearance#renderState} has alpha blending enabled.\n * @param {Material} [options.material=Material.ColorType] The material used to determine the fragment color.\n * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.\n * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.\n * @param {object} [options.renderState] Optional render state to override the default render state.\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}\n *\n * @example\n * const primitive = new Cesium.Primitive({\n * geometryInstances : new Cesium.GeometryInstance({\n * geometry : new Cesium.PolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 0.0, 0.0,\n * 5.0, 0.0\n * ]),\n * width : 10.0,\n * vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT\n * })\n * }),\n * appearance : new Cesium.PolylineMaterialAppearance({\n * material : Cesium.Material.fromType('Color')\n * })\n * });\n */\nfunction PolylineMaterialAppearance(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const translucent = defaultValue(options.translucent, true);\n const closed = false;\n const vertexFormat = PolylineMaterialAppearance.VERTEX_FORMAT;\n\n /**\n * The material used to determine the fragment color. Unlike other {@link PolylineMaterialAppearance}\n * properties, this is not read-only, so an appearance's material can change on the fly.\n *\n * @type Material\n *\n * @default {@link Material.ColorType}\n *\n * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}\n */\n this.material = defined(options.material)\n ? options.material\n : Material.fromType(Material.ColorType);\n\n /**\n * When true, the geometry is expected to appear translucent so\n * {@link PolylineMaterialAppearance#renderState} has alpha blending enabled.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.translucent = translucent;\n\n this._vertexShaderSource = defaultValue(\n options.vertexShaderSource,\n defaultVertexShaderSource\n );\n this._fragmentShaderSource = defaultValue(\n options.fragmentShaderSource,\n defaultFragmentShaderSource\n );\n this._renderState = Appearance.getDefaultRenderState(\n translucent,\n closed,\n options.renderState\n );\n this._closed = closed;\n\n // Non-derived members\n\n this._vertexFormat = vertexFormat;\n}\n\nObject.defineProperties(PolylineMaterialAppearance.prototype, {\n /**\n * The GLSL source code for the vertex shader.\n *\n * @memberof PolylineMaterialAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n vertexShaderSource: {\n get: function () {\n let vs = this._vertexShaderSource;\n if (\n this.material.shaderSource.search(/in\\s+float\\s+v_polylineAngle;/g) !==\n -1\n ) {\n vs = `#define POLYLINE_DASH\\n${vs}`;\n }\n return vs;\n },\n },\n\n /**\n * The GLSL source code for the fragment shader.\n *\n * @memberof PolylineMaterialAppearance.prototype\n *\n * @type {string}\n * @readonly\n */\n fragmentShaderSource: {\n get: function () {\n return this._fragmentShaderSource;\n },\n },\n\n /**\n * The WebGL fixed-function state to use when rendering the geometry.\n *

\n * The render state can be explicitly defined when constructing a {@link PolylineMaterialAppearance}\n * instance, or it is set implicitly via {@link PolylineMaterialAppearance#translucent}\n * and {@link PolylineMaterialAppearance#closed}.\n *

\n *\n * @memberof PolylineMaterialAppearance.prototype\n *\n * @type {object}\n * @readonly\n */\n renderState: {\n get: function () {\n return this._renderState;\n },\n },\n\n /**\n * When true, the geometry is expected to be closed so\n * {@link PolylineMaterialAppearance#renderState} has backface culling enabled.\n * This is always false for PolylineMaterialAppearance.\n *\n * @memberof PolylineMaterialAppearance.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n closed: {\n get: function () {\n return this._closed;\n },\n },\n\n /**\n * The {@link VertexFormat} that this appearance instance is compatible with.\n * A geometry can have more vertex attributes and still be compatible - at a\n * potential performance cost - but it can't have less.\n *\n * @memberof PolylineMaterialAppearance.prototype\n *\n * @type VertexFormat\n * @readonly\n *\n * @default {@link PolylineMaterialAppearance.VERTEX_FORMAT}\n */\n vertexFormat: {\n get: function () {\n return this._vertexFormat;\n },\n },\n});\n\n/**\n * The {@link VertexFormat} that all {@link PolylineMaterialAppearance} instances\n * are compatible with. This requires position and st attributes.\n *\n * @type VertexFormat\n *\n * @constant\n */\nPolylineMaterialAppearance.VERTEX_FORMAT = VertexFormat.POSITION_AND_ST;\n\n/**\n * Procedurally creates the full GLSL fragment shader source. For {@link PolylineMaterialAppearance},\n * this is derived from {@link PolylineMaterialAppearance#fragmentShaderSource} and {@link PolylineMaterialAppearance#material}.\n *\n * @function\n *\n * @returns {string} The full GLSL fragment shader source.\n */\nPolylineMaterialAppearance.prototype.getFragmentShaderSource =\n Appearance.prototype.getFragmentShaderSource;\n\n/**\n * Determines if the geometry is translucent based on {@link PolylineMaterialAppearance#translucent} and {@link Material#isTranslucent}.\n *\n * @function\n *\n * @returns {boolean} true if the appearance is translucent.\n */\nPolylineMaterialAppearance.prototype.isTranslucent =\n Appearance.prototype.isTranslucent;\n\n/**\n * Creates a render state. This is not the final render state instance; instead,\n * it can contain a subset of render state properties identical to the render state\n * created in the context.\n *\n * @function\n *\n * @returns {object} The render state.\n */\nPolylineMaterialAppearance.prototype.getRenderState =\n Appearance.prototype.getRenderState;\nexport default PolylineMaterialAppearance;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport GeometryInstanceAttribute from \"../Core/GeometryInstanceAttribute.js\";\nimport GroundPolylineGeometry from \"../Core/GroundPolylineGeometry.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport PolylineShadowVolumeFS from \"../Shaders/PolylineShadowVolumeFS.js\";\nimport PolylineShadowVolumeMorphFS from \"../Shaders/PolylineShadowVolumeMorphFS.js\";\nimport PolylineShadowVolumeMorphVS from \"../Shaders/PolylineShadowVolumeMorphVS.js\";\nimport PolylineShadowVolumeVS from \"../Shaders/PolylineShadowVolumeVS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport CullFace from \"./CullFace.js\";\nimport PolylineColorAppearance from \"./PolylineColorAppearance.js\";\nimport PolylineMaterialAppearance from \"./PolylineMaterialAppearance.js\";\nimport Primitive from \"./Primitive.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\n\n/**\n * A GroundPolylinePrimitive represents a polyline draped over the terrain or 3D Tiles in the {@link Scene}.\n *

\n * Only to be used with GeometryInstances containing {@link GroundPolylineGeometry}.\n *

\n *\n * @alias GroundPolylinePrimitive\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Array|GeometryInstance} [options.geometryInstances] GeometryInstances containing GroundPolylineGeometry\n * @param {Appearance} [options.appearance] The Appearance used to render the polyline. Defaults to a white color {@link Material} on a {@link PolylineMaterialAppearance}.\n * @param {boolean} [options.show=true] Determines if this primitive will be shown.\n * @param {boolean} [options.interleave=false] When true, geometry vertex attributes are interleaved, which can slightly improve rendering performance but increases load time.\n * @param {boolean} [options.releaseGeometryInstances=true] When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n * @param {boolean} [options.allowPicking=true] When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n * @param {boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready. If false initializeTerrainHeights() must be called first.\n * @param {ClassificationType} [options.classificationType=ClassificationType.BOTH] Determines whether terrain, 3D Tiles or both will be classified.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {boolean} [options.debugShowShadowVolume=false] For debugging only. Determines if the shadow volume for each geometry in the primitive is drawn. Must be true on creation to have effect.\n *\n * @example\n * // 1. Draw a polyline on terrain with a basic color material\n *\n * const instance = new Cesium.GeometryInstance({\n * geometry : new Cesium.GroundPolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -112.1340164450331, 36.05494287836128,\n * -112.08821010582645, 36.097804071380715\n * ]),\n * width : 4.0\n * }),\n * id : 'object returned when this instance is picked and to get/set per-instance attributes'\n * });\n *\n * scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({\n * geometryInstances : instance,\n * appearance : new Cesium.PolylineMaterialAppearance()\n * }));\n *\n * // 2. Draw a looped polyline on terrain with per-instance color and a distance display condition.\n * // Distance display conditions for polylines on terrain are based on an approximate terrain height\n * // instead of true terrain height.\n *\n * const instance2 = new Cesium.GeometryInstance({\n * geometry : new Cesium.GroundPolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -112.1340164450331, 36.05494287836128,\n * -112.08821010582645, 36.097804071380715,\n * -112.13296079730024, 36.168769146801104\n * ]),\n * loop : true,\n * width : 4.0\n * }),\n * attributes : {\n * color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('green').withAlpha(0.7)),\n * distanceDisplayCondition : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(1000, 30000)\n * },\n * id : 'object returned when this instance is picked and to get/set per-instance attributes'\n * });\n *\n * scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({\n * geometryInstances : instance2,\n * appearance : new Cesium.PolylineColorAppearance()\n * }));\n */\nfunction GroundPolylinePrimitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The geometry instances rendered with this primitive. This may\n * be undefined if options.releaseGeometryInstances\n * is true when the primitive is constructed.\n *

\n * Changing this property after the primitive is rendered has no effect.\n *

\n *\n * @readonly\n * @type {Array|GeometryInstance}\n *\n * @default undefined\n */\n this.geometryInstances = options.geometryInstances;\n this._hasPerInstanceColors = true;\n\n let appearance = options.appearance;\n if (!defined(appearance)) {\n appearance = new PolylineMaterialAppearance();\n }\n /**\n * The {@link Appearance} used to shade this primitive. Each geometry\n * instance is shaded with the same appearance. Some appearances, like\n * {@link PolylineColorAppearance} allow giving each instance unique\n * properties.\n *\n * @type Appearance\n *\n * @default undefined\n */\n this.appearance = appearance;\n\n /**\n * Determines if the primitive will be shown. This affects all geometry\n * instances in the primitive.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * Determines whether terrain, 3D Tiles or both will be classified.\n *\n * @type {ClassificationType}\n *\n * @default ClassificationType.BOTH\n */\n this.classificationType = defaultValue(\n options.classificationType,\n ClassificationType.BOTH\n );\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n // Shadow volume is shown by removing a discard in the shader, so this isn't toggleable.\n this._debugShowShadowVolume = defaultValue(\n options.debugShowShadowVolume,\n false\n );\n\n this._primitiveOptions = {\n geometryInstances: undefined,\n appearance: undefined,\n vertexCacheOptimize: false,\n interleave: defaultValue(options.interleave, false),\n releaseGeometryInstances: defaultValue(\n options.releaseGeometryInstances,\n true\n ),\n allowPicking: defaultValue(options.allowPicking, true),\n asynchronous: defaultValue(options.asynchronous, true),\n compressVertices: false,\n _createShaderProgramFunction: undefined,\n _createCommandsFunction: undefined,\n _updateAndQueueCommandsFunction: undefined,\n };\n\n // Used when inserting in an OrderedPrimitiveCollection\n this._zIndex = undefined;\n\n this._ready = false;\n this._primitive = undefined;\n\n this._sp = undefined;\n this._sp2D = undefined;\n this._spMorph = undefined;\n\n this._renderState = getRenderState(false);\n this._renderState3DTiles = getRenderState(true);\n\n this._renderStateMorph = RenderState.fromCache({\n cull: {\n enabled: true,\n face: CullFace.FRONT, // Geometry is \"inverted,\" so cull front when materials on volume instead of on terrain (morph)\n },\n depthTest: {\n enabled: true,\n },\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n depthMask: false,\n });\n}\n\nObject.defineProperties(GroundPolylinePrimitive.prototype, {\n /**\n * Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n interleave: {\n get: function () {\n return this._primitiveOptions.interleave;\n },\n },\n\n /**\n * When true, the primitive does not keep a reference to the input geometryInstances to save memory.\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n releaseGeometryInstances: {\n get: function () {\n return this._primitiveOptions.releaseGeometryInstances;\n },\n },\n\n /**\n * When true, each geometry instance will only be pickable with {@link Scene#pick}. When false, GPU memory is saved.\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n allowPicking: {\n get: function () {\n return this._primitiveOptions.allowPicking;\n },\n },\n\n /**\n * Determines if the geometry instances will be created and batched on a web worker.\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default true\n */\n asynchronous: {\n get: function () {\n return this._primitiveOptions.asynchronous;\n },\n },\n\n /**\n * Determines if the primitive is complete and ready to render. If this property is\n * true, the primitive will be rendered the next time that {@link GroundPolylinePrimitive#update}\n * is called.\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * If true, draws the shadow volume for each geometry in the primitive.\n *

\n *\n * @memberof GroundPolylinePrimitive.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n debugShowShadowVolume: {\n get: function () {\n return this._debugShowShadowVolume;\n },\n },\n});\n\n/**\n * Initializes the minimum and maximum terrain heights. This only needs to be called if you are creating the\n * GroundPolylinePrimitive synchronously.\n *\n * @returns {Promise} A promise that will resolve once the terrain heights have been loaded.\n */\nGroundPolylinePrimitive.initializeTerrainHeights = function () {\n return ApproximateTerrainHeights.initialize();\n};\n\nfunction createShaderProgram(groundPolylinePrimitive, frameState, appearance) {\n const context = frameState.context;\n const primitive = groundPolylinePrimitive._primitive;\n const attributeLocations = primitive._attributeLocations;\n\n let vs = primitive._batchTable.getVertexShaderCallback()(\n PolylineShadowVolumeVS\n );\n vs = Primitive._appendShowToShader(primitive, vs);\n vs = Primitive._appendDistanceDisplayConditionToShader(primitive, vs);\n vs = Primitive._modifyShaderPosition(\n groundPolylinePrimitive,\n vs,\n frameState.scene3DOnly\n );\n\n let vsMorph = primitive._batchTable.getVertexShaderCallback()(\n PolylineShadowVolumeMorphVS\n );\n vsMorph = Primitive._appendShowToShader(primitive, vsMorph);\n vsMorph = Primitive._appendDistanceDisplayConditionToShader(\n primitive,\n vsMorph\n );\n vsMorph = Primitive._modifyShaderPosition(\n groundPolylinePrimitive,\n vsMorph,\n frameState.scene3DOnly\n );\n\n // Access pick color from fragment shader.\n // Helps with varying budget.\n let fs = primitive._batchTable.getVertexShaderCallback()(\n PolylineShadowVolumeFS\n );\n\n const vsDefines = [\n `GLOBE_MINIMUM_ALTITUDE ${frameState.mapProjection.ellipsoid.minimumRadius.toFixed(\n 1\n )}`,\n ];\n let colorDefine = \"\";\n let materialShaderSource = \"\";\n if (defined(appearance.material)) {\n materialShaderSource = defined(appearance.material)\n ? appearance.material.shaderSource\n : \"\";\n\n // Check for use of v_width and v_polylineAngle in material shader\n // to determine whether these varyings should be active in the vertex shader.\n if (materialShaderSource.search(/in\\s+float\\s+v_polylineAngle;/g) !== -1) {\n vsDefines.push(\"ANGLE_VARYING\");\n }\n if (materialShaderSource.search(/in\\s+float\\s+v_width;/g) !== -1) {\n vsDefines.push(\"WIDTH_VARYING\");\n }\n } else {\n colorDefine = \"PER_INSTANCE_COLOR\";\n }\n\n vsDefines.push(colorDefine);\n const fsDefines = groundPolylinePrimitive.debugShowShadowVolume\n ? [\"DEBUG_SHOW_VOLUME\", colorDefine]\n : [colorDefine];\n\n const vsColor3D = new ShaderSource({\n defines: vsDefines,\n sources: [vs],\n });\n const fsColor3D = new ShaderSource({\n defines: fsDefines,\n sources: [materialShaderSource, fs],\n });\n groundPolylinePrimitive._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: primitive._sp,\n vertexShaderSource: vsColor3D,\n fragmentShaderSource: fsColor3D,\n attributeLocations: attributeLocations,\n });\n\n // Derive 2D/CV\n let colorProgram2D = context.shaderCache.getDerivedShaderProgram(\n groundPolylinePrimitive._sp,\n \"2dColor\"\n );\n if (!defined(colorProgram2D)) {\n const vsColor2D = new ShaderSource({\n defines: vsDefines.concat([\"COLUMBUS_VIEW_2D\"]),\n sources: [vs],\n });\n colorProgram2D = context.shaderCache.createDerivedShaderProgram(\n groundPolylinePrimitive._sp,\n \"2dColor\",\n {\n context: context,\n shaderProgram: groundPolylinePrimitive._sp2D,\n vertexShaderSource: vsColor2D,\n fragmentShaderSource: fsColor3D,\n attributeLocations: attributeLocations,\n }\n );\n }\n groundPolylinePrimitive._sp2D = colorProgram2D;\n\n // Derive Morph\n let colorProgramMorph = context.shaderCache.getDerivedShaderProgram(\n groundPolylinePrimitive._sp,\n \"MorphColor\"\n );\n if (!defined(colorProgramMorph)) {\n const vsColorMorph = new ShaderSource({\n defines: vsDefines.concat([\n `MAX_TERRAIN_HEIGHT ${ApproximateTerrainHeights._defaultMaxTerrainHeight.toFixed(\n 1\n )}`,\n ]),\n sources: [vsMorph],\n });\n\n fs = primitive._batchTable.getVertexShaderCallback()(\n PolylineShadowVolumeMorphFS\n );\n const fsColorMorph = new ShaderSource({\n defines: fsDefines,\n sources: [materialShaderSource, fs],\n });\n colorProgramMorph = context.shaderCache.createDerivedShaderProgram(\n groundPolylinePrimitive._sp,\n \"MorphColor\",\n {\n context: context,\n shaderProgram: groundPolylinePrimitive._spMorph,\n vertexShaderSource: vsColorMorph,\n fragmentShaderSource: fsColorMorph,\n attributeLocations: attributeLocations,\n }\n );\n }\n groundPolylinePrimitive._spMorph = colorProgramMorph;\n}\n\nfunction getRenderState(mask3DTiles) {\n return RenderState.fromCache({\n cull: {\n enabled: true, // prevent double-draw. Geometry is \"inverted\" (reversed winding order) so we're drawing backfaces.\n },\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n depthMask: false,\n stencilTest: {\n enabled: mask3DTiles,\n frontFunction: StencilFunction.EQUAL,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.KEEP,\n },\n backFunction: StencilFunction.EQUAL,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.KEEP,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n },\n });\n}\n\nfunction createCommands(\n groundPolylinePrimitive,\n appearance,\n material,\n translucent,\n colorCommands,\n pickCommands\n) {\n const primitive = groundPolylinePrimitive._primitive;\n const length = primitive._va.length;\n colorCommands.length = length;\n pickCommands.length = length;\n\n const isPolylineColorAppearance =\n appearance instanceof PolylineColorAppearance;\n\n const materialUniforms = isPolylineColorAppearance ? {} : material._uniforms;\n const uniformMap = primitive._batchTable.getUniformMapCallback()(\n materialUniforms\n );\n\n for (let i = 0; i < length; i++) {\n const vertexArray = primitive._va[i];\n\n let command = colorCommands[i];\n if (!defined(command)) {\n command = colorCommands[i] = new DrawCommand({\n owner: groundPolylinePrimitive,\n primitiveType: primitive._primitiveType,\n });\n }\n\n command.vertexArray = vertexArray;\n command.renderState = groundPolylinePrimitive._renderState;\n command.shaderProgram = groundPolylinePrimitive._sp;\n command.uniformMap = uniformMap;\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n command.pickId = \"czm_batchTable_pickColor(v_endPlaneNormalEcAndBatchId.w)\";\n\n const derivedTilesetCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedTilesetCommand.renderState =\n groundPolylinePrimitive._renderState3DTiles;\n derivedTilesetCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedTilesetCommand;\n\n // derive for 2D\n const derived2DCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.color2D\n );\n derived2DCommand.shaderProgram = groundPolylinePrimitive._sp2D;\n command.derivedCommands.color2D = derived2DCommand;\n\n const derived2DTilesetCommand = DrawCommand.shallowClone(\n derivedTilesetCommand,\n derivedTilesetCommand.derivedCommands.color2D\n );\n derived2DTilesetCommand.shaderProgram = groundPolylinePrimitive._sp2D;\n derivedTilesetCommand.derivedCommands.color2D = derived2DTilesetCommand;\n\n // derive for Morph\n const derivedMorphCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.colorMorph\n );\n derivedMorphCommand.renderState = groundPolylinePrimitive._renderStateMorph;\n derivedMorphCommand.shaderProgram = groundPolylinePrimitive._spMorph;\n derivedMorphCommand.pickId = \"czm_batchTable_pickColor(v_batchId)\";\n command.derivedCommands.colorMorph = derivedMorphCommand;\n }\n}\n\nfunction updateAndQueueCommand(\n groundPolylinePrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n) {\n // Use derived appearance command for morph and 2D\n if (frameState.mode === SceneMode.MORPHING) {\n command = command.derivedCommands.colorMorph;\n } else if (frameState.mode !== SceneMode.SCENE3D) {\n command = command.derivedCommands.color2D;\n }\n command.modelMatrix = modelMatrix;\n command.boundingVolume = boundingVolume;\n command.cull = cull;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n\n frameState.commandList.push(command);\n}\n\nfunction updateAndQueueCommands(\n groundPolylinePrimitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume\n) {\n const primitive = groundPolylinePrimitive._primitive;\n\n Primitive._updateBoundingVolumes(primitive, frameState, modelMatrix); // Expected to be identity - GroundPrimitives don't support other model matrices\n\n let boundingSpheres;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingSpheres = primitive._boundingSphereWC;\n } else if (frameState.mode === SceneMode.COLUMBUS_VIEW) {\n boundingSpheres = primitive._boundingSphereCV;\n } else if (\n frameState.mode === SceneMode.SCENE2D &&\n defined(primitive._boundingSphere2D)\n ) {\n boundingSpheres = primitive._boundingSphere2D;\n } else if (defined(primitive._boundingSphereMorph)) {\n boundingSpheres = primitive._boundingSphereMorph;\n }\n\n const morphing = frameState.mode === SceneMode.MORPHING;\n const classificationType = groundPolylinePrimitive.classificationType;\n const queueTerrainCommands =\n classificationType !== ClassificationType.CESIUM_3D_TILE;\n const queue3DTilesCommands =\n classificationType !== ClassificationType.TERRAIN && !morphing;\n\n let command;\n const passes = frameState.passes;\n if (passes.render || (passes.pick && primitive.allowPicking)) {\n const colorLength = colorCommands.length;\n for (let j = 0; j < colorLength; ++j) {\n const boundingVolume = boundingSpheres[j];\n if (queueTerrainCommands) {\n command = colorCommands[j];\n updateAndQueueCommand(\n groundPolylinePrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n if (queue3DTilesCommands) {\n command = colorCommands[j].derivedCommands.tileset;\n updateAndQueueCommand(\n groundPolylinePrimitive,\n command,\n frameState,\n modelMatrix,\n cull,\n boundingVolume,\n debugShowBoundingVolume\n );\n }\n }\n }\n}\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {DeveloperError} For synchronous GroundPolylinePrimitives, you must call GroundPolylinePrimitives.initializeTerrainHeights() and wait for the returned promise to resolve.\n * @exception {DeveloperError} All GeometryInstances must have color attributes to use PolylineColorAppearance with GroundPolylinePrimitive.\n */\nGroundPolylinePrimitive.prototype.update = function (frameState) {\n if (!defined(this._primitive) && !defined(this.geometryInstances)) {\n return;\n }\n\n if (!ApproximateTerrainHeights.initialized) {\n //>>includeStart('debug', pragmas.debug);\n if (!this.asynchronous) {\n throw new DeveloperError(\n \"For synchronous GroundPolylinePrimitives, you must call GroundPolylinePrimitives.initializeTerrainHeights() and wait for the returned promise to resolve.\"\n );\n }\n //>>includeEnd('debug');\n\n GroundPolylinePrimitive.initializeTerrainHeights();\n return;\n }\n\n let i;\n\n const that = this;\n const primitiveOptions = this._primitiveOptions;\n if (!defined(this._primitive)) {\n const geometryInstances = Array.isArray(this.geometryInstances)\n ? this.geometryInstances\n : [this.geometryInstances];\n const geometryInstancesLength = geometryInstances.length;\n const groundInstances = new Array(geometryInstancesLength);\n\n let attributes;\n\n // Check if each instance has a color attribute.\n for (i = 0; i < geometryInstancesLength; ++i) {\n attributes = geometryInstances[i].attributes;\n if (!defined(attributes) || !defined(attributes.color)) {\n this._hasPerInstanceColors = false;\n break;\n }\n }\n\n for (i = 0; i < geometryInstancesLength; ++i) {\n const geometryInstance = geometryInstances[i];\n attributes = {};\n const instanceAttributes = geometryInstance.attributes;\n for (const attributeKey in instanceAttributes) {\n if (instanceAttributes.hasOwnProperty(attributeKey)) {\n attributes[attributeKey] = instanceAttributes[attributeKey];\n }\n }\n\n // Automatically create line width attribute if not already given\n if (!defined(attributes.width)) {\n attributes.width = new GeometryInstanceAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1.0,\n value: [geometryInstance.geometry.width],\n });\n }\n\n // Update each geometry for framestate.scene3DOnly = true and projection\n geometryInstance.geometry._scene3DOnly = frameState.scene3DOnly;\n GroundPolylineGeometry.setProjectionAndEllipsoid(\n geometryInstance.geometry,\n frameState.mapProjection\n );\n\n groundInstances[i] = new GeometryInstance({\n geometry: geometryInstance.geometry,\n attributes: attributes,\n id: geometryInstance.id,\n pickPrimitive: that,\n });\n }\n\n primitiveOptions.geometryInstances = groundInstances;\n primitiveOptions.appearance = this.appearance;\n\n primitiveOptions._createShaderProgramFunction = function (\n primitive,\n frameState,\n appearance\n ) {\n createShaderProgram(that, frameState, appearance);\n };\n primitiveOptions._createCommandsFunction = function (\n primitive,\n appearance,\n material,\n translucent,\n twoPasses,\n colorCommands,\n pickCommands\n ) {\n createCommands(\n that,\n appearance,\n material,\n translucent,\n colorCommands,\n pickCommands\n );\n };\n primitiveOptions._updateAndQueueCommandsFunction = function (\n primitive,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume,\n twoPasses\n ) {\n updateAndQueueCommands(\n that,\n frameState,\n colorCommands,\n pickCommands,\n modelMatrix,\n cull,\n debugShowBoundingVolume\n );\n };\n\n this._primitive = new Primitive(primitiveOptions);\n }\n\n if (\n this.appearance instanceof PolylineColorAppearance &&\n !this._hasPerInstanceColors\n ) {\n throw new DeveloperError(\n \"All GeometryInstances must have color attributes to use PolylineColorAppearance with GroundPolylinePrimitive.\"\n );\n }\n\n this._primitive.appearance = this.appearance;\n this._primitive.show = this.show;\n this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume;\n this._primitive.update(frameState);\n frameState.afterRender.push(() => {\n if (!this._ready && defined(this._primitive) && this._primitive.ready) {\n this._ready = true;\n\n if (this.releaseGeometryInstances) {\n this.geometryInstances = undefined;\n }\n }\n });\n};\n\n/**\n * Returns the modifiable per-instance attributes for a {@link GeometryInstance}.\n *\n * @param {*} id The id of the {@link GeometryInstance}.\n * @returns {object} The typed array in the attribute's format or undefined if the is no instance with id.\n *\n * @exception {DeveloperError} must call update before calling getGeometryInstanceAttributes.\n *\n * @example\n * const attributes = primitive.getGeometryInstanceAttributes('an id');\n * attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);\n * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);\n */\nGroundPolylinePrimitive.prototype.getGeometryInstanceAttributes = function (\n id\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(this._primitive)) {\n throw new DeveloperError(\n \"must call update before calling getGeometryInstanceAttributes\"\n );\n }\n //>>includeEnd('debug');\n return this._primitive.getGeometryInstanceAttributes(id);\n};\n\n/**\n * Checks if the given Scene supports GroundPolylinePrimitives.\n * GroundPolylinePrimitives require support for the WEBGL_depth_texture extension.\n *\n * @param {Scene} scene The current scene.\n * @returns {boolean} Whether or not the current scene supports GroundPolylinePrimitives.\n */\nGroundPolylinePrimitive.isSupported = function (scene) {\n return scene.frameState.context.depthTexture;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see GroundPolylinePrimitive#destroy\n */\nGroundPolylinePrimitive.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * e = e && e.destroy();\n *\n * @see GroundPolylinePrimitive#isDestroyed\n */\nGroundPolylinePrimitive.prototype.destroy = function () {\n this._primitive = this._primitive && this._primitive.destroy();\n this._sp = this._sp && this._sp.destroy();\n\n // Derived programs, destroyed above if they existed.\n this._sp2D = undefined;\n this._spMorph = undefined;\n\n return destroyObject(this);\n};\nexport default GroundPolylinePrimitive;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultRepeat = new Cartesian2(1, 1);\nconst defaultTransparent = false;\nconst defaultColor = Color.WHITE;\n\n/**\n * A {@link MaterialProperty} that maps to image {@link Material} uniforms.\n * @alias ImageMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|string|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} [options.image] A Property specifying the Image, URL, Canvas, or Video.\n * @param {Property|Cartesian2} [options.repeat=new Cartesian2(1.0, 1.0)] A {@link Cartesian2} Property specifying the number of times the image repeats in each direction.\n * @param {Property|Color} [options.color=Color.WHITE] The color applied to the image\n * @param {Property|boolean} [options.transparent=false] Set to true when the image has transparency (for example, when a png has transparent sections)\n */\nfunction ImageMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._image = undefined;\n this._imageSubscription = undefined;\n this._repeat = undefined;\n this._repeatSubscription = undefined;\n this._color = undefined;\n this._colorSubscription = undefined;\n this._transparent = undefined;\n this._transparentSubscription = undefined;\n\n this.image = options.image;\n this.repeat = options.repeat;\n this.color = options.color;\n this.transparent = options.transparent;\n}\n\nObject.defineProperties(ImageMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof ImageMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._image) && Property.isConstant(this._repeat)\n );\n },\n },\n\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof ImageMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the Property specifying Image, URL, Canvas, or Video to use.\n * @memberof ImageMaterialProperty.prototype\n * @type {Property|undefined}\n */\n image: createPropertyDescriptor(\"image\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the number of times the image repeats in each direction.\n * @memberof ImageMaterialProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(1, 1)\n */\n repeat: createPropertyDescriptor(\"repeat\"),\n\n /**\n * Gets or sets the Color Property specifying the desired color applied to the image.\n * @memberof ImageMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the Boolean Property specifying whether the image has transparency\n * @memberof ImageMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n transparent: createPropertyDescriptor(\"transparent\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nImageMaterialProperty.prototype.getType = function (time) {\n return \"Image\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nImageMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n\n result.image = Property.getValueOrUndefined(this._image, time);\n result.repeat = Property.getValueOrClonedDefault(\n this._repeat,\n time,\n defaultRepeat,\n result.repeat\n );\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n defaultColor,\n result.color\n );\n if (Property.getValueOrDefault(this._transparent, time, defaultTransparent)) {\n result.color.alpha = Math.min(0.99, result.color.alpha);\n }\n\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nImageMaterialProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof ImageMaterialProperty &&\n Property.equals(this._image, other._image) &&\n Property.equals(this._repeat, other._repeat) &&\n Property.equals(this._color, other._color) &&\n Property.equals(this._transparent, other._transparent))\n );\n};\nexport default ImageMaterialProperty;\n", "import Color from \"../Core/Color.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Resource from \"../Core/Resource.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport ImageMaterialProperty from \"./ImageMaterialProperty.js\";\n\nfunction createMaterialProperty(value) {\n if (value instanceof Color) {\n return new ColorMaterialProperty(value);\n }\n\n if (\n typeof value === \"string\" ||\n value instanceof Resource ||\n value instanceof HTMLCanvasElement ||\n value instanceof HTMLVideoElement\n ) {\n const result = new ImageMaterialProperty();\n result.image = value;\n return result;\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Unable to infer material type: ${value}`);\n //>>includeEnd('debug');\n}\n\n/**\n * @private\n */\nfunction createMaterialPropertyDescriptor(name, configurable) {\n return createPropertyDescriptor(name, configurable, createMaterialProperty);\n}\nexport default createMaterialPropertyDescriptor;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} BoxGraphics.ConstructorOptions\n *\n * Initialization options for the BoxGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the box.\n * @property {Property | Cartesian3} [dimensions] A {@link Cartesian3} Property specifying the length, width, and height of the box.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the box is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the box.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the box is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the box casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this box will be displayed.\n *\n */\n\n/**\n * Describes a box. The center position and orientation are determined by the containing {@link Entity}.\n *\n * @alias BoxGraphics\n * @constructor\n *\n * @param {BoxGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Box.html|Cesium Sandcastle Box Demo}\n */\nfunction BoxGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._dimensions = undefined;\n this._dimensionsSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(BoxGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof BoxGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the box.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets {@link Cartesian3} Property property specifying the length, width, and height of the box.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n */\n dimensions: createPropertyDescriptor(\"dimensions\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the box is filled with the provided material.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the material used to fill the box.\n * @memberof BoxGraphics.prototype\n * @type {MaterialProperty|undefined}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the box is outlined.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the box\n * casts or receives shadows from light sources.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this box will be displayed.\n * @memberof BoxGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {BoxGraphics} [result] The object onto which to store the result.\n * @returns {BoxGraphics} The modified result parameter or a new instance if one was not provided.\n */\nBoxGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new BoxGraphics(this);\n }\n result.show = this.show;\n result.dimensions = this.dimensions;\n result.heightReference = this.heightReference;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {BoxGraphics} source The object to be merged into this object.\n */\nBoxGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.dimensions = defaultValue(this.dimensions, source.dimensions);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default BoxGraphics;\n", "/**\n * Constants for identifying well-known reference frames.\n *\n * @enum {number}\n */\nconst ReferenceFrame = {\n /**\n * The fixed frame.\n *\n * @type {number}\n * @constant\n */\n FIXED: 0,\n\n /**\n * The inertial frame.\n *\n * @type {number}\n * @constant\n */\n INERTIAL: 1,\n};\nexport default Object.freeze(ReferenceFrame);\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport Transforms from \"../Core/Transforms.js\";\n\n/**\n * The interface for all {@link Property} objects that define a world\n * location as a {@link Cartesian3} with an associated {@link ReferenceFrame}.\n * This type defines an interface and cannot be instantiated directly.\n *\n * @alias PositionProperty\n * @constructor\n * @abstract\n *\n * @see CompositePositionProperty\n * @see ConstantPositionProperty\n * @see SampledPositionProperty\n * @see TimeIntervalCollectionPositionProperty\n */\nfunction PositionProperty() {\n DeveloperError.throwInstantiationError();\n}\n\nObject.defineProperties(PositionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof PositionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof PositionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the reference frame that the position is defined in.\n * @memberof PositionProperty.prototype\n * @type {ReferenceFrame}\n */\n referenceFrame: {\n get: DeveloperError.throwInstantiationError,\n },\n});\n\n/**\n * Gets the value of the property at the provided time in the fixed frame.\n * @function\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPositionProperty.prototype.getValue = DeveloperError.throwInstantiationError;\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n * @function\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPositionProperty.prototype.getValueInReferenceFrame =\n DeveloperError.throwInstantiationError;\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n * @function\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPositionProperty.prototype.equals = DeveloperError.throwInstantiationError;\n\nconst scratchMatrix3 = new Matrix3();\n\n/**\n * @private\n */\nPositionProperty.convertToReferenceFrame = function (\n time,\n value,\n inputFrame,\n outputFrame,\n result\n) {\n if (!defined(value)) {\n return value;\n }\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n if (inputFrame === outputFrame) {\n return Cartesian3.clone(value, result);\n }\n\n let icrfToFixed = Transforms.computeIcrfToFixedMatrix(time, scratchMatrix3);\n if (!defined(icrfToFixed)) {\n icrfToFixed = Transforms.computeTemeToPseudoFixedMatrix(\n time,\n scratchMatrix3\n );\n }\n if (inputFrame === ReferenceFrame.INERTIAL) {\n return Matrix3.multiplyByVector(icrfToFixed, value, result);\n }\n if (inputFrame === ReferenceFrame.FIXED) {\n return Matrix3.multiplyByVector(\n Matrix3.transpose(icrfToFixed, scratchMatrix3),\n value,\n result\n );\n }\n};\nexport default PositionProperty;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport PositionProperty from \"./PositionProperty.js\";\n\n/**\n * A {@link PositionProperty} whose value does not change in respect to the\n * {@link ReferenceFrame} in which is it defined.\n *\n * @alias ConstantPositionProperty\n * @constructor\n *\n * @param {Cartesian3} [value] The property value.\n * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.\n */\nfunction ConstantPositionProperty(value, referenceFrame) {\n this._definitionChanged = new Event();\n this._value = Cartesian3.clone(value);\n this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n}\n\nObject.defineProperties(ConstantPositionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof ConstantPositionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n !defined(this._value) || this._referenceFrame === ReferenceFrame.FIXED\n );\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof ConstantPositionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the reference frame in which the position is defined.\n * @memberof ConstantPositionProperty.prototype\n * @type {ReferenceFrame}\n * @default ReferenceFrame.FIXED;\n */\n referenceFrame: {\n get: function () {\n return this._referenceFrame;\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time in the fixed frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nConstantPositionProperty.prototype.getValue = function (time, result) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\n/**\n * Sets the value of the property.\n *\n * @param {Cartesian3} value The property value.\n * @param {ReferenceFrame} [referenceFrame=this.referenceFrame] The reference frame in which the position is defined.\n */\nConstantPositionProperty.prototype.setValue = function (value, referenceFrame) {\n let definitionChanged = false;\n if (!Cartesian3.equals(this._value, value)) {\n definitionChanged = true;\n this._value = Cartesian3.clone(value);\n }\n if (defined(referenceFrame) && this._referenceFrame !== referenceFrame) {\n definitionChanged = true;\n this._referenceFrame = referenceFrame;\n }\n if (definitionChanged) {\n this._definitionChanged.raiseEvent(this);\n }\n};\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nConstantPositionProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n if (!defined(referenceFrame)) {\n throw new DeveloperError(\"referenceFrame is required.\");\n }\n //>>includeEnd('debug');\n\n return PositionProperty.convertToReferenceFrame(\n time,\n this._value,\n this._referenceFrame,\n referenceFrame,\n result\n );\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nConstantPositionProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof ConstantPositionProperty &&\n Cartesian3.equals(this._value, other._value) &&\n this._referenceFrame === other._referenceFrame)\n );\n};\nexport default ConstantPositionProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} CorridorGraphics.ConstructorOptions\n *\n * Initialization options for the CorridorGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the corridor.\n * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions that define the centerline of the corridor.\n * @property {Property | number} [width] A numeric Property specifying the distance between the edges of the corridor.\n * @property {Property | number} [height=0] A numeric Property specifying the altitude of the corridor relative to the ellipsoid surface.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | number} [extrudedHeight] A numeric Property specifying the altitude of the corridor's extruded face relative to the ellipsoid surface.\n * @property {Property | HeightReference} [extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.\n * @property {Property | CornerType} [cornerType=CornerType.ROUNDED] A {@link CornerType} Property specifying the style of the corners.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the corridor is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the corridor.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the corridor is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the corridor casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this corridor will be displayed.\n * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.\n * @property {ConstantProperty | number} [zIndex] A Property specifying the zIndex of the corridor, used for ordering. Only has an effect if height and extrudedHeight are undefined, and if the corridor is static.\n */\n\n/**\n * Describes a corridor, which is a shape defined by a centerline and width that\n * conforms to the curvature of the globe. It can be placed on the surface or at altitude\n * and can optionally be extruded into a volume.\n *\n * @alias CorridorGraphics\n * @constructor\n *\n * @param {CorridorGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}\n */\nfunction CorridorGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._positions = undefined;\n this._positionsSubscription = undefined;\n this._width = undefined;\n this._widthSubscription = undefined;\n this._height = undefined;\n this._heightSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._extrudedHeight = undefined;\n this._extrudedHeightSubscription = undefined;\n this._extrudedHeightReference = undefined;\n this._extrudedHeightReferenceSubscription = undefined;\n this._cornerType = undefined;\n this._cornerTypeSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._classificationType = undefined;\n this._classificationTypeSubscription = undefined;\n this._zIndex = undefined;\n this._zIndexSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(CorridorGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof CorridorGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the corridor.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets a Property specifying the array of {@link Cartesian3} positions that define the centerline of the corridor.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n */\n positions: createPropertyDescriptor(\"positions\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n */\n width: createPropertyDescriptor(\"width\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the corridor.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n height: createPropertyDescriptor(\"height\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the corridor extrusion.\n * Setting this property creates a corridor shaped volume starting at height and ending\n * at this altitude.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n */\n extrudedHeight: createPropertyDescriptor(\"extrudedHeight\"),\n\n /**\n * Gets or sets the Property specifying the extruded {@link HeightReference}.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n extrudedHeightReference: createPropertyDescriptor(\"extrudedHeightReference\"),\n\n /**\n * Gets or sets the {@link CornerType} Property specifying how corners are styled.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default CornerType.ROUNDED\n */\n cornerType: createPropertyDescriptor(\"cornerType\"),\n\n /**\n * Gets or sets the numeric Property specifying the sampling distance between each latitude and longitude point.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the corridor is filled with the provided material.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the corridor.\n * @memberof CorridorGraphics.prototype\n * @type {MaterialProperty|undefined}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the corridor is outlined.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the corridor\n * casts or receives shadows from light sources.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this corridor will be displayed.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the {@link ClassificationType} Property specifying whether this corridor will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof CorridorGraphics.prototype\n * @type {Property|undefined}\n * @default ClassificationType.BOTH\n */\n classificationType: createPropertyDescriptor(\"classificationType\"),\n\n /**\n * Gets or sets the zIndex Property specifying the ordering of the corridor. Only has an effect if the coridor is static and neither height or exturdedHeight are specified.\n * @memberof CorridorGraphics.prototype\n * @type {ConstantProperty|undefined}\n * @default 0\n */\n zIndex: createPropertyDescriptor(\"zIndex\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {CorridorGraphics} [result] The object onto which to store the result.\n * @returns {CorridorGraphics} The modified result parameter or a new instance if one was not provided.\n */\nCorridorGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new CorridorGraphics(this);\n }\n result.show = this.show;\n result.positions = this.positions;\n result.width = this.width;\n result.height = this.height;\n result.heightReference = this.heightReference;\n result.extrudedHeight = this.extrudedHeight;\n result.extrudedHeightReference = this.extrudedHeightReference;\n result.cornerType = this.cornerType;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.classificationType = this.classificationType;\n result.zIndex = this.zIndex;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {CorridorGraphics} source The object to be merged into this object.\n */\nCorridorGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.positions = defaultValue(this.positions, source.positions);\n this.width = defaultValue(this.width, source.width);\n this.height = defaultValue(this.height, source.height);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.extrudedHeight = defaultValue(\n this.extrudedHeight,\n source.extrudedHeight\n );\n this.extrudedHeightReference = defaultValue(\n this.extrudedHeightReference,\n source.extrudedHeightReference\n );\n this.cornerType = defaultValue(this.cornerType, source.cornerType);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.classificationType = defaultValue(\n this.classificationType,\n source.classificationType\n );\n this.zIndex = defaultValue(this.zIndex, source.zIndex);\n};\nexport default CorridorGraphics;\n", "import createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\nfunction createRawProperty(value) {\n return value;\n}\n\n/**\n * @private\n */\nfunction createRawPropertyDescriptor(name, configurable) {\n return createPropertyDescriptor(name, configurable, createRawProperty);\n}\nexport default createRawPropertyDescriptor;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} CylinderGraphics.ConstructorOptions\n *\n * Initialization options for the CylinderGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the cylinder.\n * @property {Property | number} [length] A numeric Property specifying the length of the cylinder.\n * @property {Property | number} [topRadius] A numeric Property specifying the radius of the top of the cylinder.\n * @property {Property | number} [bottomRadius] A numeric Property specifying the radius of the bottom of the cylinder.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the cylinder is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the cylinder.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the cylinder is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | number} [numberOfVerticalLines=16] A numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.\n * @property {Property | number} [slices=128] The number of edges around the perimeter of the cylinder.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the cylinder casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this cylinder will be displayed.\n */\n\n/**\n * Describes a cylinder, truncated cone, or cone defined by a length, top radius, and bottom radius.\n * The center position and orientation are determined by the containing {@link Entity}.\n *\n * @alias CylinderGraphics\n * @constructor\n *\n * @param {CylinderGraphics.ConstructorOptions} [options] Object describing initialization options\n */\nfunction CylinderGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._length = undefined;\n this._lengthSubscription = undefined;\n this._topRadius = undefined;\n this._topRadiusSubscription = undefined;\n this._bottomRadius = undefined;\n this._bottomRadiusSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._numberOfVerticalLines = undefined;\n this._numberOfVerticalLinesSubscription = undefined;\n this._slices = undefined;\n this._slicesSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(CylinderGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof CylinderGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the numeric Property specifying the length of the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n */\n length: createPropertyDescriptor(\"length\"),\n\n /**\n * Gets or sets the numeric Property specifying the radius of the top of the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n */\n topRadius: createPropertyDescriptor(\"topRadius\"),\n\n /**\n * Gets or sets the numeric Property specifying the radius of the bottom of the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n */\n bottomRadius: createPropertyDescriptor(\"bottomRadius\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the cylinder is filled with the provided material.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {MaterialProperty|undefined}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the cylinder is outlined.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets the Property specifying the number of vertical lines to draw along the perimeter for the outline.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default 16\n */\n numberOfVerticalLines: createPropertyDescriptor(\"numberOfVerticalLines\"),\n\n /**\n * Gets or sets the Property specifying the number of edges around the perimeter of the cylinder.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default 128\n */\n slices: createPropertyDescriptor(\"slices\"),\n\n /**\n * Get or sets the enum Property specifying whether the cylinder\n * casts or receives shadows from light sources.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this cylinder will be displayed.\n * @memberof CylinderGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {CylinderGraphics} [result] The object onto which to store the result.\n * @returns {CylinderGraphics} The modified result parameter or a new instance if one was not provided.\n */\nCylinderGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new CylinderGraphics(this);\n }\n result.show = this.show;\n result.length = this.length;\n result.topRadius = this.topRadius;\n result.bottomRadius = this.bottomRadius;\n result.heightReference = this.heightReference;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.numberOfVerticalLines = this.numberOfVerticalLines;\n result.slices = this.slices;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {CylinderGraphics} source The object to be merged into this object.\n */\nCylinderGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.length = defaultValue(this.length, source.length);\n this.topRadius = defaultValue(this.topRadius, source.topRadius);\n this.bottomRadius = defaultValue(this.bottomRadius, source.bottomRadius);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.numberOfVerticalLines = defaultValue(\n this.numberOfVerticalLines,\n source.numberOfVerticalLines\n );\n this.slices = defaultValue(this.slices, source.slices);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default CylinderGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} EllipseGraphics.ConstructorOptions\n *\n * Initialization options for the EllipseGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the ellipse.\n * @property {Property | number} [semiMajorAxis] The numeric Property specifying the semi-major axis.\n * @property {Property | number} [semiMinorAxis] The numeric Property specifying the semi-minor axis.\n * @property {Property | number} [height=0] A numeric Property specifying the altitude of the ellipse relative to the ellipsoid surface.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | number} [extrudedHeight] A numeric Property specifying the altitude of the ellipse's extruded face relative to the ellipsoid surface.\n * @property {Property | HeightReference} [extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.\n * @property {Property | number} [rotation=0.0] A numeric property specifying the rotation of the ellipse counter-clockwise from north.\n * @property {Property | number} [stRotation=0.0] A numeric property specifying the rotation of the ellipse texture counter-clockwise from north.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between points on the ellipse.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the ellipse is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the ellipse.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the ellipse is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | number} [numberOfVerticalLines=16] A numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the ellipse casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this ellipse will be displayed.\n * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this ellipse will classify terrain, 3D Tiles, or both when on the ground.\n * @property {ConstantProperty | number} [zIndex=0] A property specifying the zIndex of the Ellipse. Used for ordering ground geometry. Only has an effect if the ellipse is constant and neither height or exturdedHeight are specified.\n */\n\n/**\n * Describes an ellipse defined by a center point and semi-major and semi-minor axes.\n * The ellipse conforms to the curvature of the globe and can be placed on the surface or\n * at altitude and can optionally be extruded into a volume.\n * The center point is determined by the containing {@link Entity}.\n *\n * @alias EllipseGraphics\n * @constructor\n *\n * @param {EllipseGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Circles and Ellipses.html|Cesium Sandcastle Circles and Ellipses Demo}\n */\nfunction EllipseGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._semiMajorAxis = undefined;\n this._semiMajorAxisSubscription = undefined;\n this._semiMinorAxis = undefined;\n this._semiMinorAxisSubscription = undefined;\n this._height = undefined;\n this._heightSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._extrudedHeight = undefined;\n this._extrudedHeightSubscription = undefined;\n this._extrudedHeightReference = undefined;\n this._extrudedHeightReferenceSubscription = undefined;\n this._rotation = undefined;\n this._rotationSubscription = undefined;\n this._stRotation = undefined;\n this._stRotationSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._numberOfVerticalLines = undefined;\n this._numberOfVerticalLinesSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._classificationType = undefined;\n this._classificationTypeSubscription = undefined;\n this._zIndex = undefined;\n this._zIndexSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(EllipseGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof EllipseGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the ellipse.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the numeric Property specifying the semi-major axis.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n */\n semiMajorAxis: createPropertyDescriptor(\"semiMajorAxis\"),\n\n /**\n * Gets or sets the numeric Property specifying the semi-minor axis.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n */\n semiMinorAxis: createPropertyDescriptor(\"semiMinorAxis\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the ellipse.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n height: createPropertyDescriptor(\"height\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the ellipse extrusion.\n * Setting this property creates volume starting at height and ending at this altitude.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n */\n extrudedHeight: createPropertyDescriptor(\"extrudedHeight\"),\n\n /**\n * Gets or sets the Property specifying the extruded {@link HeightReference}.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n extrudedHeightReference: createPropertyDescriptor(\"extrudedHeightReference\"),\n\n /**\n * Gets or sets the numeric property specifying the rotation of the ellipse counter-clockwise from north.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n rotation: createPropertyDescriptor(\"rotation\"),\n\n /**\n * Gets or sets the numeric property specifying the rotation of the ellipse texture counter-clockwise from north.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n stRotation: createPropertyDescriptor(\"stRotation\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between points on the ellipse.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the ellipse is filled with the provided material.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the ellipse.\n * @memberof EllipseGraphics.prototype\n * @type {MaterialProperty|undefined}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the ellipse is outlined.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets the numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default 16\n */\n numberOfVerticalLines: createPropertyDescriptor(\"numberOfVerticalLines\"),\n\n /**\n * Get or sets the enum Property specifying whether the ellipse\n * casts or receives shadows from light sources.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this ellipse will be displayed.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the {@link ClassificationType} Property specifying whether this ellipse will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof EllipseGraphics.prototype\n * @type {Property|undefined}\n * @default ClassificationType.BOTH\n */\n classificationType: createPropertyDescriptor(\"classificationType\"),\n\n /**\n * Gets or sets the zIndex Property specifying the ellipse ordering. Only has an effect if the ellipse is constant and neither height or extrudedHeight are specified\n * @memberof EllipseGraphics.prototype\n * @type {ConstantProperty|undefined}\n * @default 0\n */\n zIndex: createPropertyDescriptor(\"zIndex\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {EllipseGraphics} [result] The object onto which to store the result.\n * @returns {EllipseGraphics} The modified result parameter or a new instance if one was not provided.\n */\nEllipseGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new EllipseGraphics(this);\n }\n result.show = this.show;\n result.semiMajorAxis = this.semiMajorAxis;\n result.semiMinorAxis = this.semiMinorAxis;\n result.height = this.height;\n result.heightReference = this.heightReference;\n result.extrudedHeight = this.extrudedHeight;\n result.extrudedHeightReference = this.extrudedHeightReference;\n result.rotation = this.rotation;\n result.stRotation = this.stRotation;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.numberOfVerticalLines = this.numberOfVerticalLines;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.classificationType = this.classificationType;\n result.zIndex = this.zIndex;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {EllipseGraphics} source The object to be merged into this object.\n */\nEllipseGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.semiMajorAxis = defaultValue(this.semiMajorAxis, source.semiMajorAxis);\n this.semiMinorAxis = defaultValue(this.semiMinorAxis, source.semiMinorAxis);\n this.height = defaultValue(this.height, source.height);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.extrudedHeight = defaultValue(\n this.extrudedHeight,\n source.extrudedHeight\n );\n this.extrudedHeightReference = defaultValue(\n this.extrudedHeightReference,\n source.extrudedHeightReference\n );\n this.rotation = defaultValue(this.rotation, source.rotation);\n this.stRotation = defaultValue(this.stRotation, source.stRotation);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.numberOfVerticalLines = defaultValue(\n this.numberOfVerticalLines,\n source.numberOfVerticalLines\n );\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.classificationType = defaultValue(\n this.classificationType,\n source.classificationType\n );\n this.zIndex = defaultValue(this.zIndex, source.zIndex);\n};\nexport default EllipseGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} EllipsoidGraphics.ConstructorOptions\n *\n * Initialization options for the EllipsoidGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the ellipsoid.\n * @property {Property | Cartesian3} [radii] A {@link Cartesian3} Property specifying the radii of the ellipsoid.\n * @property {Property | Cartesian3} [innerRadii] A {@link Cartesian3} Property specifying the inner radii of the ellipsoid.\n * @property {Property | number} [minimumClock=0.0] A Property specifying the minimum clock angle of the ellipsoid.\n * @property {Property | number} [maximumClock=2*PI] A Property specifying the maximum clock angle of the ellipsoid.\n * @property {Property | number} [minimumCone=0.0] A Property specifying the minimum cone angle of the ellipsoid.\n * @property {Property | number} [maximumCone=PI] A Property specifying the maximum cone angle of the ellipsoid.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the ellipsoid is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the ellipsoid.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the ellipsoid is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | number} [stackPartitions=64] A Property specifying the number of stacks.\n * @property {Property | number} [slicePartitions=64] A Property specifying the number of radial slices.\n * @property {Property | number} [subdivisions=128] A Property specifying the number of samples per outline ring, determining the granularity of the curvature.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the ellipsoid casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this ellipsoid will be displayed.\n */\n\n/**\n * Describe an ellipsoid or sphere. The center position and orientation are determined by the containing {@link Entity}.\n *\n * @alias EllipsoidGraphics\n * @constructor\n *\n * @param {EllipsoidGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Spheres%20and%20Ellipsoids.html|Cesium Sandcastle Spheres and Ellipsoids Demo}\n */\nfunction EllipsoidGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._radii = undefined;\n this._radiiSubscription = undefined;\n this._innerRadii = undefined;\n this._innerRadiiSubscription = undefined;\n this._minimumClock = undefined;\n this._minimumClockSubscription = undefined;\n this._maximumClock = undefined;\n this._maximumClockSubscription = undefined;\n this._minimumCone = undefined;\n this._minimumConeSubscription = undefined;\n this._maximumCone = undefined;\n this._maximumConeSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._stackPartitions = undefined;\n this._stackPartitionsSubscription = undefined;\n this._slicePartitions = undefined;\n this._slicePartitionsSubscription = undefined;\n this._subdivisions = undefined;\n this._subdivisionsSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(EllipsoidGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof EllipsoidGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the {@link Cartesian3} {@link Property} specifying the radii of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n */\n radii: createPropertyDescriptor(\"radii\"),\n\n /**\n * Gets or sets the {@link Cartesian3} {@link Property} specifying the inner radii of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default radii\n */\n innerRadii: createPropertyDescriptor(\"innerRadii\"),\n\n /**\n * Gets or sets the Property specifying the minimum clock angle of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n minimumClock: createPropertyDescriptor(\"minimumClock\"),\n\n /**\n * Gets or sets the Property specifying the maximum clock angle of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 2*PI\n */\n maximumClock: createPropertyDescriptor(\"maximumClock\"),\n\n /**\n * Gets or sets the Property specifying the minimum cone angle of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n minimumCone: createPropertyDescriptor(\"minimumCone\"),\n\n /**\n * Gets or sets the Property specifying the maximum cone angle of the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default PI\n */\n maximumCone: createPropertyDescriptor(\"maximumCone\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the ellipsoid is filled with the provided material.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the ellipsoid.\n * @memberof EllipsoidGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the ellipsoid is outlined.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets the Property specifying the number of stacks.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 64\n */\n stackPartitions: createPropertyDescriptor(\"stackPartitions\"),\n\n /**\n * Gets or sets the Property specifying the number of radial slices per 360 degrees.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 64\n */\n slicePartitions: createPropertyDescriptor(\"slicePartitions\"),\n\n /**\n * Gets or sets the Property specifying the number of samples per outline ring, determining the granularity of the curvature.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default 128\n */\n subdivisions: createPropertyDescriptor(\"subdivisions\"),\n\n /**\n * Get or sets the enum Property specifying whether the ellipsoid\n * casts or receives shadows from light sources.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this ellipsoid will be displayed.\n * @memberof EllipsoidGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {EllipsoidGraphics} [result] The object onto which to store the result.\n * @returns {EllipsoidGraphics} The modified result parameter or a new instance if one was not provided.\n */\nEllipsoidGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new EllipsoidGraphics(this);\n }\n result.show = this.show;\n result.radii = this.radii;\n result.innerRadii = this.innerRadii;\n result.minimumClock = this.minimumClock;\n result.maximumClock = this.maximumClock;\n result.minimumCone = this.minimumCone;\n result.maximumCone = this.maximumCone;\n result.heightReference = this.heightReference;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.stackPartitions = this.stackPartitions;\n result.slicePartitions = this.slicePartitions;\n result.subdivisions = this.subdivisions;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {EllipsoidGraphics} source The object to be merged into this object.\n */\nEllipsoidGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.radii = defaultValue(this.radii, source.radii);\n this.innerRadii = defaultValue(this.innerRadii, source.innerRadii);\n this.minimumClock = defaultValue(this.minimumClock, source.minimumClock);\n this.maximumClock = defaultValue(this.maximumClock, source.maximumClock);\n this.minimumCone = defaultValue(this.minimumCone, source.minimumCone);\n this.maximumCone = defaultValue(this.maximumCone, source.maximumCone);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.stackPartitions = defaultValue(\n this.stackPartitions,\n source.stackPartitions\n );\n this.slicePartitions = defaultValue(\n this.slicePartitions,\n source.slicePartitions\n );\n this.subdivisions = defaultValue(this.subdivisions, source.subdivisions);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default EllipsoidGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} LabelGraphics.ConstructorOptions\n *\n * Initialization options for the LabelGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the label.\n * @property {Property | string} [text] A Property specifying the text. Explicit newlines '\\n' are supported.\n * @property {Property | string} [font='30px sans-serif'] A Property specifying the CSS font.\n * @property {Property | LabelStyle} [style=LabelStyle.FILL] A Property specifying the {@link LabelStyle}.\n * @property {Property | number} [scale=1.0] A numeric Property specifying the scale to apply to the text.\n * @property {Property | boolean} [showBackground=false] A boolean Property specifying the visibility of the background behind the label.\n * @property {Property | Color} [backgroundColor=new Color(0.165, 0.165, 0.165, 0.8)] A Property specifying the background {@link Color}.\n * @property {Property | Cartesian2} [backgroundPadding=new Cartesian2(7, 5)] A {@link Cartesian2} Property specifying the horizontal and vertical background padding in pixels.\n * @property {Property | Cartesian2} [pixelOffset=Cartesian2.ZERO] A {@link Cartesian2} Property specifying the pixel offset.\n * @property {Property | Cartesian3} [eyeOffset=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the eye offset.\n * @property {Property | HorizontalOrigin} [horizontalOrigin=HorizontalOrigin.CENTER] A Property specifying the {@link HorizontalOrigin}.\n * @property {Property | VerticalOrigin} [verticalOrigin=VerticalOrigin.CENTER] A Property specifying the {@link VerticalOrigin}.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | Color} [fillColor=Color.WHITE] A Property specifying the fill {@link Color}.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the outline {@link Color}.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the outline width.\n * @property {Property | NearFarScalar} [translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.\n * @property {Property | NearFarScalar} [pixelOffsetScaleByDistance] A {@link NearFarScalar} Property used to set pixelOffset based on distance from the camera.\n * @property {Property | NearFarScalar} [scaleByDistance] A {@link NearFarScalar} Property used to set scale based on distance from the camera.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this label will be displayed.\n * @property {Property | number} [disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.\n */\n\n/**\n * Describes a two dimensional label located at the position of the containing {@link Entity}.\n *

\n *

\n *
\n * Example labels\n *
\n *

\n *\n * @alias LabelGraphics\n * @constructor\n *\n * @param {LabelGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Labels.html|Cesium Sandcastle Labels Demo}\n */\nfunction LabelGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._text = undefined;\n this._textSubscription = undefined;\n this._font = undefined;\n this._fontSubscription = undefined;\n this._style = undefined;\n this._styleSubscription = undefined;\n this._scale = undefined;\n this._scaleSubscription = undefined;\n this._showBackground = undefined;\n this._showBackgroundSubscription = undefined;\n this._backgroundColor = undefined;\n this._backgroundColorSubscription = undefined;\n this._backgroundPadding = undefined;\n this._backgroundPaddingSubscription = undefined;\n this._pixelOffset = undefined;\n this._pixelOffsetSubscription = undefined;\n this._eyeOffset = undefined;\n this._eyeOffsetSubscription = undefined;\n this._horizontalOrigin = undefined;\n this._horizontalOriginSubscription = undefined;\n this._verticalOrigin = undefined;\n this._verticalOriginSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._fillColor = undefined;\n this._fillColorSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._translucencyByDistance = undefined;\n this._translucencyByDistanceSubscription = undefined;\n this._pixelOffsetScaleByDistance = undefined;\n this._pixelOffsetScaleByDistanceSubscription = undefined;\n this._scaleByDistance = undefined;\n this._scaleByDistanceSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._disableDepthTestDistance = undefined;\n this._disableDepthTestDistanceSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(LabelGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof LabelGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the label.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the string Property specifying the text of the label.\n * Explicit newlines '\\n' are supported.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n text: createPropertyDescriptor(\"text\"),\n\n /**\n * Gets or sets the string Property specifying the font in CSS syntax.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/font|CSS font on MDN}\n */\n font: createPropertyDescriptor(\"font\"),\n\n /**\n * Gets or sets the Property specifying the {@link LabelStyle}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n style: createPropertyDescriptor(\"style\"),\n\n /**\n * Gets or sets the numeric Property specifying the uniform scale to apply to the image.\n * A scale greater than 1.0 enlarges the label while a scale less than 1.0 shrinks it.\n *

\n *

\n *
\n * From left to right in the above image, the scales are 0.5, 1.0,\n * and 2.0.\n *
\n *

\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n scale: createPropertyDescriptor(\"scale\"),\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the background behind the label.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n showBackground: createPropertyDescriptor(\"showBackground\"),\n\n /**\n * Gets or sets the Property specifying the background {@link Color}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default new Color(0.165, 0.165, 0.165, 0.8)\n */\n backgroundColor: createPropertyDescriptor(\"backgroundColor\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the label's horizontal and vertical\n * background padding in pixels.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(7, 5)\n */\n backgroundPadding: createPropertyDescriptor(\"backgroundPadding\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the label's pixel offset in screen space\n * from the origin of this label. This is commonly used to align multiple labels and labels at\n * the same position, e.g., an image and text. The screen space origin is the top, left corner of the\n * canvas; x increases from left to right, and y increases from top to bottom.\n *

\n *

\n * \n * \n * \n *
default
l.pixeloffset = new Cartesian2(25, 75);
\n * The label's origin is indicated by the yellow point.\n *
\n *

\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default Cartesian2.ZERO\n */\n pixelOffset: createPropertyDescriptor(\"pixelOffset\"),\n\n /**\n * Gets or sets the {@link Cartesian3} Property specifying the label's offset in eye coordinates.\n * Eye coordinates is a left-handed coordinate system, where x points towards the viewer's\n * right, y points up, and z points into the screen.\n *

\n * An eye offset is commonly used to arrange multiple labels or objects at the same position, e.g., to\n * arrange a label above its corresponding 3D model.\n *

\n * Below, the label is positioned at the center of the Earth but an eye offset makes it always\n * appear on top of the Earth regardless of the viewer's or Earth's orientation.\n *

\n *

\n * \n * \n * \n *
\n * l.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);

\n *
\n *

\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default Cartesian3.ZERO\n */\n eyeOffset: createPropertyDescriptor(\"eyeOffset\"),\n\n /**\n * Gets or sets the Property specifying the {@link HorizontalOrigin}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n horizontalOrigin: createPropertyDescriptor(\"horizontalOrigin\"),\n\n /**\n * Gets or sets the Property specifying the {@link VerticalOrigin}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n verticalOrigin: createPropertyDescriptor(\"verticalOrigin\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the Property specifying the fill {@link Color}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n fillColor: createPropertyDescriptor(\"fillColor\"),\n\n /**\n * Gets or sets the Property specifying the outline {@link Color}.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the outline width.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the translucency of the label based on the distance from the camera.\n * A label's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's translucency remains clamped to the nearest bound.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n translucencyByDistance: createPropertyDescriptor(\"translucencyByDistance\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the pixel offset of the label based on the distance from the camera.\n * A label's pixel offset will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's pixel offset remains clamped to the nearest bound.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n pixelOffsetScaleByDistance: createPropertyDescriptor(\n \"pixelOffsetScaleByDistance\"\n ),\n\n /**\n * Gets or sets near and far scaling properties of a Label based on the label's distance from the camera.\n * A label's scale will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's scale remains clamped to the nearest bound. If undefined,\n * scaleByDistance will be disabled.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n scaleByDistance: createPropertyDescriptor(\"scaleByDistance\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this label will be displayed.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof LabelGraphics.prototype\n * @type {Property|undefined}\n */\n disableDepthTestDistance: createPropertyDescriptor(\n \"disableDepthTestDistance\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {LabelGraphics} [result] The object onto which to store the result.\n * @returns {LabelGraphics} The modified result parameter or a new instance if one was not provided.\n */\nLabelGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new LabelGraphics(this);\n }\n result.show = this.show;\n result.text = this.text;\n result.font = this.font;\n result.style = this.style;\n result.scale = this.scale;\n result.showBackground = this.showBackground;\n result.backgroundColor = this.backgroundColor;\n result.backgroundPadding = this.backgroundPadding;\n result.pixelOffset = this.pixelOffset;\n result.eyeOffset = this.eyeOffset;\n result.horizontalOrigin = this.horizontalOrigin;\n result.verticalOrigin = this.verticalOrigin;\n result.heightReference = this.heightReference;\n result.fillColor = this.fillColor;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.translucencyByDistance = this.translucencyByDistance;\n result.pixelOffsetScaleByDistance = this.pixelOffsetScaleByDistance;\n result.scaleByDistance = this.scaleByDistance;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.disableDepthTestDistance = this.disableDepthTestDistance;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {LabelGraphics} source The object to be merged into this object.\n */\nLabelGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.text = defaultValue(this.text, source.text);\n this.font = defaultValue(this.font, source.font);\n this.style = defaultValue(this.style, source.style);\n this.scale = defaultValue(this.scale, source.scale);\n this.showBackground = defaultValue(\n this.showBackground,\n source.showBackground\n );\n this.backgroundColor = defaultValue(\n this.backgroundColor,\n source.backgroundColor\n );\n this.backgroundPadding = defaultValue(\n this.backgroundPadding,\n source.backgroundPadding\n );\n this.pixelOffset = defaultValue(this.pixelOffset, source.pixelOffset);\n this.eyeOffset = defaultValue(this.eyeOffset, source.eyeOffset);\n this.horizontalOrigin = defaultValue(\n this.horizontalOrigin,\n source.horizontalOrigin\n );\n this.verticalOrigin = defaultValue(\n this.verticalOrigin,\n source.verticalOrigin\n );\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.fillColor = defaultValue(this.fillColor, source.fillColor);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.translucencyByDistance = defaultValue(\n this.translucencyByDistance,\n source.translucencyByDistance\n );\n this.pixelOffsetScaleByDistance = defaultValue(\n this.pixelOffsetScaleByDistance,\n source.pixelOffsetScaleByDistance\n );\n this.scaleByDistance = defaultValue(\n this.scaleByDistance,\n source.scaleByDistance\n );\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.disableDepthTestDistance = defaultValue(\n this.disableDepthTestDistance,\n source.disableDepthTestDistance\n );\n};\nexport default LabelGraphics;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Quaternion from \"./Quaternion.js\";\n\nconst defaultScale = new Cartesian3(1.0, 1.0, 1.0);\nconst defaultTranslation = Cartesian3.ZERO;\nconst defaultRotation = Quaternion.IDENTITY;\n\n/**\n * An affine transformation defined by a translation, rotation, and scale.\n * @alias TranslationRotationScale\n * @constructor\n *\n * @param {Cartesian3} [translation=Cartesian3.ZERO] A {@link Cartesian3} specifying the (x, y, z) translation to apply to the node.\n * @param {Quaternion} [rotation=Quaternion.IDENTITY] A {@link Quaternion} specifying the (x, y, z, w) rotation to apply to the node.\n * @param {Cartesian3} [scale=new Cartesian3(1.0, 1.0, 1.0)] A {@link Cartesian3} specifying the (x, y, z) scaling to apply to the node.\n */\nfunction TranslationRotationScale(translation, rotation, scale) {\n /**\n * Gets or sets the (x, y, z) translation to apply to the node.\n * @type {Cartesian3}\n * @default Cartesian3.ZERO\n */\n this.translation = Cartesian3.clone(\n defaultValue(translation, defaultTranslation)\n );\n\n /**\n * Gets or sets the (x, y, z, w) rotation to apply to the node.\n * @type {Quaternion}\n * @default Quaternion.IDENTITY\n */\n this.rotation = Quaternion.clone(defaultValue(rotation, defaultRotation));\n\n /**\n * Gets or sets the (x, y, z) scaling to apply to the node.\n * @type {Cartesian3}\n * @default new Cartesian3(1.0, 1.0, 1.0)\n */\n this.scale = Cartesian3.clone(defaultValue(scale, defaultScale));\n}\n\n/**\n * Compares this instance against the provided instance and returns\n * true if they are equal, false otherwise.\n *\n * @param {TranslationRotationScale} [right] The right hand side TranslationRotationScale.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nTranslationRotationScale.prototype.equals = function (right) {\n return (\n this === right ||\n (defined(right) &&\n Cartesian3.equals(this.translation, right.translation) &&\n Quaternion.equals(this.rotation, right.rotation) &&\n Cartesian3.equals(this.scale, right.scale))\n );\n};\nexport default TranslationRotationScale;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport TranslationRotationScale from \"../Core/TranslationRotationScale.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultNodeTransformation = new TranslationRotationScale();\n\n/**\n * A {@link Property} that produces {@link TranslationRotationScale} data.\n * @alias NodeTransformationProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Cartesian3} [options.translation=Cartesian3.ZERO] A {@link Cartesian3} Property specifying the (x, y, z) translation to apply to the node.\n * @param {Property|Quaternion} [options.rotation=Quaternion.IDENTITY] A {@link Quaternion} Property specifying the (x, y, z, w) rotation to apply to the node.\n * @param {Property|Cartesian3} [options.scale=new Cartesian3(1.0, 1.0, 1.0)] A {@link Cartesian3} Property specifying the (x, y, z) scaling to apply to the node.\n */\nfunction NodeTransformationProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._translation = undefined;\n this._translationSubscription = undefined;\n this._rotation = undefined;\n this._rotationSubscription = undefined;\n this._scale = undefined;\n this._scaleSubscription = undefined;\n\n this.translation = options.translation;\n this.rotation = options.rotation;\n this.scale = options.scale;\n}\n\nObject.defineProperties(NodeTransformationProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof NodeTransformationProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._translation) &&\n Property.isConstant(this._rotation) &&\n Property.isConstant(this._scale)\n );\n },\n },\n\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof NodeTransformationProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the {@link Cartesian3} Property specifying the (x, y, z) translation to apply to the node.\n * @memberof NodeTransformationProperty.prototype\n * @type {Property|undefined}\n * @default Cartesian3.ZERO\n */\n translation: createPropertyDescriptor(\"translation\"),\n\n /**\n * Gets or sets the {@link Quaternion} Property specifying the (x, y, z, w) rotation to apply to the node.\n * @memberof NodeTransformationProperty.prototype\n * @type {Property|undefined}\n * @default Quaternion.IDENTITY\n */\n rotation: createPropertyDescriptor(\"rotation\"),\n\n /**\n * Gets or sets the {@link Cartesian3} Property specifying the (x, y, z) scaling to apply to the node.\n * @memberof NodeTransformationProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian3(1.0, 1.0, 1.0)\n */\n scale: createPropertyDescriptor(\"scale\"),\n});\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {TranslationRotationScale} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {TranslationRotationScale} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nNodeTransformationProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = new TranslationRotationScale();\n }\n\n result.translation = Property.getValueOrClonedDefault(\n this._translation,\n time,\n defaultNodeTransformation.translation,\n result.translation\n );\n result.rotation = Property.getValueOrClonedDefault(\n this._rotation,\n time,\n defaultNodeTransformation.rotation,\n result.rotation\n );\n result.scale = Property.getValueOrClonedDefault(\n this._scale,\n time,\n defaultNodeTransformation.scale,\n result.scale\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nNodeTransformationProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof NodeTransformationProperty &&\n Property.equals(this._translation, other._translation) &&\n Property.equals(this._rotation, other._rotation) &&\n Property.equals(this._scale, other._scale))\n );\n};\nexport default NodeTransformationProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link Property} whose value is a key-value mapping of property names to the computed value of other properties.\n *\n * @alias PropertyBag\n * @implements Record\n * @constructor\n *\n * @param {object} [value] An object, containing key-value mapping of property names to properties.\n * @param {Function} [createPropertyCallback] A function that will be called when the value of any of the properties in value are not a Property.\n */\nfunction PropertyBag(value, createPropertyCallback) {\n this._propertyNames = [];\n this._definitionChanged = new Event();\n\n if (defined(value)) {\n this.merge(value, createPropertyCallback);\n }\n}\n\nObject.defineProperties(PropertyBag.prototype, {\n /**\n * Gets the names of all properties registered on this instance.\n * @memberof PropertyBag.prototype\n * @type {Array}\n */\n propertyNames: {\n get: function () {\n return this._propertyNames;\n },\n },\n /**\n * Gets a value indicating if this property is constant. This property\n * is considered constant if all property items in this object are constant.\n * @memberof PropertyBag.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n const propertyNames = this._propertyNames;\n for (let i = 0, len = propertyNames.length; i < len; i++) {\n if (!Property.isConstant(this[propertyNames[i]])) {\n return false;\n }\n }\n return true;\n },\n },\n /**\n * Gets the event that is raised whenever the set of properties contained in this\n * object changes, or one of the properties itself changes.\n *\n * @memberof PropertyBag.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\n/**\n * Determines if this object has defined a property with the given name.\n *\n * @param {string} propertyName The name of the property to check for.\n *\n * @returns {boolean} True if this object has defined a property with the given name, false otherwise.\n */\nPropertyBag.prototype.hasProperty = function (propertyName) {\n return this._propertyNames.indexOf(propertyName) !== -1;\n};\n\nfunction createConstantProperty(value) {\n return new ConstantProperty(value);\n}\n\n/**\n * Adds a property to this object.\n *\n * @param {string} propertyName The name of the property to add.\n * @param {*} [value] The value of the new property, if provided.\n * @param {Function} [createPropertyCallback] A function that will be called when the value of this new property is set to a value that is not a Property.\n *\n * @exception {DeveloperError} \"propertyName\" is already a registered property.\n */\nPropertyBag.prototype.addProperty = function (\n propertyName,\n value,\n createPropertyCallback\n) {\n const propertyNames = this._propertyNames;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(propertyName)) {\n throw new DeveloperError(\"propertyName is required.\");\n }\n if (propertyNames.indexOf(propertyName) !== -1) {\n throw new DeveloperError(\n `${propertyName} is already a registered property.`\n );\n }\n //>>includeEnd('debug');\n\n propertyNames.push(propertyName);\n Object.defineProperty(\n this,\n propertyName,\n createPropertyDescriptor(\n propertyName,\n true,\n defaultValue(createPropertyCallback, createConstantProperty)\n )\n );\n\n if (defined(value)) {\n this[propertyName] = value;\n }\n\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Removed a property previously added with addProperty.\n *\n * @param {string} propertyName The name of the property to remove.\n *\n * @exception {DeveloperError} \"propertyName\" is not a registered property.\n */\nPropertyBag.prototype.removeProperty = function (propertyName) {\n const propertyNames = this._propertyNames;\n const index = propertyNames.indexOf(propertyName);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(propertyName)) {\n throw new DeveloperError(\"propertyName is required.\");\n }\n if (index === -1) {\n throw new DeveloperError(`${propertyName} is not a registered property.`);\n }\n //>>includeEnd('debug');\n\n this._propertyNames.splice(index, 1);\n delete this[propertyName];\n\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Gets the value of this property. Each contained property will be evaluated at the given time, and the overall\n * result will be an object, mapping property names to those values.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * Note that any properties in result which are not part of this PropertyBag will be left as-is.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPropertyBag.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = {};\n }\n\n const propertyNames = this._propertyNames;\n for (let i = 0, len = propertyNames.length; i < len; i++) {\n const propertyName = propertyNames[i];\n result[propertyName] = Property.getValueOrUndefined(\n this[propertyName],\n time,\n result[propertyName]\n );\n }\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {object} source The object to be merged into this object.\n * @param {Function} [createPropertyCallback] A function that will be called when the value of any of the properties in value are not a Property.\n */\nPropertyBag.prototype.merge = function (source, createPropertyCallback) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n const propertyNames = this._propertyNames;\n const sourcePropertyNames = defined(source._propertyNames)\n ? source._propertyNames\n : Object.keys(source);\n for (let i = 0, len = sourcePropertyNames.length; i < len; i++) {\n const name = sourcePropertyNames[i];\n\n const targetProperty = this[name];\n const sourceProperty = source[name];\n\n //Custom properties that are registered on the source must also be added to this.\n if (targetProperty === undefined && propertyNames.indexOf(name) === -1) {\n this.addProperty(name, undefined, createPropertyCallback);\n }\n\n if (sourceProperty !== undefined) {\n if (targetProperty !== undefined) {\n if (defined(targetProperty) && defined(targetProperty.merge)) {\n targetProperty.merge(sourceProperty);\n }\n } else if (\n defined(sourceProperty) &&\n defined(sourceProperty.merge) &&\n defined(sourceProperty.clone)\n ) {\n this[name] = sourceProperty.clone();\n } else {\n this[name] = sourceProperty;\n }\n }\n }\n};\n\nfunction propertiesEqual(a, b) {\n const aPropertyNames = a._propertyNames;\n const bPropertyNames = b._propertyNames;\n\n const len = aPropertyNames.length;\n if (len !== bPropertyNames.length) {\n return false;\n }\n\n for (let aIndex = 0; aIndex < len; ++aIndex) {\n const name = aPropertyNames[aIndex];\n const bIndex = bPropertyNames.indexOf(name);\n if (bIndex === -1) {\n return false;\n }\n if (!Property.equals(a[name], b[name])) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPropertyBag.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PropertyBag && //\n propertiesEqual(this, other))\n );\n};\nexport default PropertyBag;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport NodeTransformationProperty from \"./NodeTransformationProperty.js\";\nimport PropertyBag from \"./PropertyBag.js\";\n\nfunction createNodeTransformationProperty(value) {\n return new NodeTransformationProperty(value);\n}\n\nfunction createNodeTransformationPropertyBag(value) {\n return new PropertyBag(value, createNodeTransformationProperty);\n}\n\nfunction createArticulationStagePropertyBag(value) {\n return new PropertyBag(value);\n}\n\n/**\n * @typedef {object} ModelGraphics.ConstructorOptions\n *\n * Initialization options for the ModelGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the model.\n * @property {Property | string | Resource} [uri] A string or Resource Property specifying the URI of the glTF asset.\n * @property {Property | number} [scale=1.0] A numeric Property specifying a uniform linear scale.\n * @property {Property | number} [minimumPixelSize=0.0] A numeric Property specifying the approximate minimum pixel size of the model regardless of zoom.\n * @property {Property | number} [maximumScale] The maximum scale size of a model. An upper limit for minimumPixelSize.\n * @property {Property | boolean} [incrementallyLoadTextures=true] Determine if textures may continue to stream in after the model is loaded.\n * @property {Property | boolean} [runAnimations=true] A boolean Property specifying if glTF animations specified in the model should be started.\n * @property {Property | boolean} [clampAnimations=true] A boolean Property specifying if glTF animations should hold the last pose for time durations with no keyframes.\n * @property {Property | ShadowMode} [shadows=ShadowMode.ENABLED] An enum Property specifying whether the model casts or receives shadows from light sources.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | Color} [silhouetteColor=Color.RED] A Property specifying the {@link Color} of the silhouette.\n * @property {Property | number} [silhouetteSize=0.0] A numeric Property specifying the size of the silhouette in pixels.\n * @property {Property | Color} [color=Color.WHITE] A Property specifying the {@link Color} that blends with the model's rendered color.\n * @property {Property | ColorBlendMode} [colorBlendMode=ColorBlendMode.HIGHLIGHT] An enum Property specifying how the color blends with the model.\n * @property {Property | number} [colorBlendAmount=0.5] A numeric Property specifying the color strength when the colorBlendMode is MIX. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.\n * @property {Property | Cartesian2} [imageBasedLightingFactor=new Cartesian2(1.0, 1.0)] A property specifying the contribution from diffuse and specular image-based lighting.\n * @property {Property | Color} [lightColor] A property specifying the light color when shading the model. When undefined the scene's light color is used instead.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this model will be displayed.\n * @property {PropertyBag | Object} [nodeTransformations] An object, where keys are names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node. The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.\n * @property {PropertyBag | Object} [articulations] An object, where keys are composed of an articulation name, a single space, and a stage name, and the values are numeric properties.\n * @property {Property | ClippingPlaneCollection} [clippingPlanes] A property specifying the {@link ClippingPlaneCollection} used to selectively disable rendering the model.\n * @property {Property | CustomShader} [customShader] A property specifying the {@link CustomShader} to apply to this model.\n */\n\n/**\n * A 3D model based on {@link https://github.com/KhronosGroup/glTF|glTF}, the runtime asset format for WebGL, OpenGL ES, and OpenGL.\n * The position and orientation of the model is determined by the containing {@link Entity}.\n *

\n * Cesium includes support for glTF geometry, materials, animations, and skinning.\n * Cameras and lights are not currently supported.\n *

\n *\n * @alias ModelGraphics\n * @constructor\n *\n * @param {ModelGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=3D%20Models.html|Cesium Sandcastle 3D Models Demo}\n */\nfunction ModelGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._uri = undefined;\n this._uriSubscription = undefined;\n this._scale = undefined;\n this._scaleSubscription = undefined;\n this._minimumPixelSize = undefined;\n this._minimumPixelSizeSubscription = undefined;\n this._maximumScale = undefined;\n this._maximumScaleSubscription = undefined;\n this._incrementallyLoadTextures = undefined;\n this._incrementallyLoadTexturesSubscription = undefined;\n this._runAnimations = undefined;\n this._runAnimationsSubscription = undefined;\n this._clampAnimations = undefined;\n this._clampAnimationsSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._silhouetteColor = undefined;\n this._silhouetteColorSubscription = undefined;\n this._silhouetteSize = undefined;\n this._silhouetteSizeSubscription = undefined;\n this._color = undefined;\n this._colorSubscription = undefined;\n this._colorBlendMode = undefined;\n this._colorBlendModeSubscription = undefined;\n this._colorBlendAmount = undefined;\n this._colorBlendAmountSubscription = undefined;\n this._imageBasedLightingFactor = undefined;\n this._imageBasedLightingFactorSubscription = undefined;\n this._lightColor = undefined;\n this._lightColorSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._nodeTransformations = undefined;\n this._nodeTransformationsSubscription = undefined;\n this._articulations = undefined;\n this._articulationsSubscription = undefined;\n this._clippingPlanes = undefined;\n this._clippingPlanesSubscription = undefined;\n this._customShader = undefined;\n this._customShaderSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(ModelGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof ModelGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the model.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the string Property specifying the URI of the glTF asset.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n uri: createPropertyDescriptor(\"uri\"),\n\n /**\n * Gets or sets the numeric Property specifying a uniform linear scale\n * for this model. Values greater than 1.0 increase the size of the model while\n * values less than 1.0 decrease it.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n scale: createPropertyDescriptor(\"scale\"),\n\n /**\n * Gets or sets the numeric Property specifying the approximate minimum\n * pixel size of the model regardless of zoom. This can be used to ensure that\n * a model is visible even when the viewer zooms out. When 0.0,\n * no minimum size is enforced.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n minimumPixelSize: createPropertyDescriptor(\"minimumPixelSize\"),\n\n /**\n * Gets or sets the numeric Property specifying the maximum scale\n * size of a model. This property is used as an upper limit for\n * {@link ModelGraphics#minimumPixelSize}.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n maximumScale: createPropertyDescriptor(\"maximumScale\"),\n\n /**\n * Get or sets the boolean Property specifying whether textures\n * may continue to stream in after the model is loaded.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n incrementallyLoadTextures: createPropertyDescriptor(\n \"incrementallyLoadTextures\"\n ),\n\n /**\n * Gets or sets the boolean Property specifying if glTF animations should be run.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n runAnimations: createPropertyDescriptor(\"runAnimations\"),\n\n /**\n * Gets or sets the boolean Property specifying if glTF animations should hold the last pose for time durations with no keyframes.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n clampAnimations: createPropertyDescriptor(\"clampAnimations\"),\n\n /**\n * Get or sets the enum Property specifying whether the model\n * casts or receives shadows from light sources.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.ENABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the silhouette.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default Color.RED\n */\n silhouetteColor: createPropertyDescriptor(\"silhouetteColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the size of the silhouette in pixels.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n silhouetteSize: createPropertyDescriptor(\"silhouetteSize\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} that blends with the model's rendered color.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the enum Property specifying how the color blends with the model.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default ColorBlendMode.HIGHLIGHT\n */\n colorBlendMode: createPropertyDescriptor(\"colorBlendMode\"),\n\n /**\n * A numeric Property specifying the color strength when the colorBlendMode is MIX.\n * A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with\n * any value in-between resulting in a mix of the two.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n * @default 0.5\n */\n colorBlendAmount: createPropertyDescriptor(\"colorBlendAmount\"),\n\n /**\n * A property specifying the {@link Cartesian2} used to scale the diffuse and specular image-based lighting contribution to the final color.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n imageBasedLightingFactor: createPropertyDescriptor(\n \"imageBasedLightingFactor\"\n ),\n\n /**\n * A property specifying the {@link Cartesian3} light color when shading the model. When undefined the scene's light color is used instead.\n * @memberOf ModelGraphics.prototype\n * @type {Property|undefined}\n */\n lightColor: createPropertyDescriptor(\"lightColor\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this model will be displayed.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the set of node transformations to apply to this model. This is represented as an {@link PropertyBag}, where keys are\n * names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node.\n * The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.\n * @memberof ModelGraphics.prototype\n * @type {PropertyBag}\n */\n nodeTransformations: createPropertyDescriptor(\n \"nodeTransformations\",\n undefined,\n createNodeTransformationPropertyBag\n ),\n\n /**\n * Gets or sets the set of articulation values to apply to this model. This is represented as an {@link PropertyBag}, where keys are\n * composed as the name of the articulation, a single space, and the name of the stage.\n * @memberof ModelGraphics.prototype\n * @type {PropertyBag}\n */\n articulations: createPropertyDescriptor(\n \"articulations\",\n undefined,\n createArticulationStagePropertyBag\n ),\n\n /**\n * A property specifying the {@link ClippingPlaneCollection} used to selectively disable rendering the model.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n clippingPlanes: createPropertyDescriptor(\"clippingPlanes\"),\n\n /**\n * Gets or sets the {@link CustomShader} to apply to this model. When undefined, no custom shader code is used.\n * @memberof ModelGraphics.prototype\n * @type {Property|undefined}\n */\n customShader: createPropertyDescriptor(\"customShader\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {ModelGraphics} [result] The object onto which to store the result.\n * @returns {ModelGraphics} The modified result parameter or a new instance if one was not provided.\n */\nModelGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new ModelGraphics(this);\n }\n result.show = this.show;\n result.uri = this.uri;\n result.scale = this.scale;\n result.minimumPixelSize = this.minimumPixelSize;\n result.maximumScale = this.maximumScale;\n result.incrementallyLoadTextures = this.incrementallyLoadTextures;\n result.runAnimations = this.runAnimations;\n result.clampAnimations = this.clampAnimations;\n result.heightReference = this._heightReference;\n result.silhouetteColor = this.silhouetteColor;\n result.silhouetteSize = this.silhouetteSize;\n result.color = this.color;\n result.colorBlendMode = this.colorBlendMode;\n result.colorBlendAmount = this.colorBlendAmount;\n result.imageBasedLightingFactor = this.imageBasedLightingFactor;\n result.lightColor = this.lightColor;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.nodeTransformations = this.nodeTransformations;\n result.articulations = this.articulations;\n result.clippingPlanes = this.clippingPlanes;\n result.customShader = this.customShader;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {ModelGraphics} source The object to be merged into this object.\n */\nModelGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.uri = defaultValue(this.uri, source.uri);\n this.scale = defaultValue(this.scale, source.scale);\n this.minimumPixelSize = defaultValue(\n this.minimumPixelSize,\n source.minimumPixelSize\n );\n this.maximumScale = defaultValue(this.maximumScale, source.maximumScale);\n this.incrementallyLoadTextures = defaultValue(\n this.incrementallyLoadTextures,\n source.incrementallyLoadTextures\n );\n this.runAnimations = defaultValue(this.runAnimations, source.runAnimations);\n this.clampAnimations = defaultValue(\n this.clampAnimations,\n source.clampAnimations\n );\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.silhouetteColor = defaultValue(\n this.silhouetteColor,\n source.silhouetteColor\n );\n this.silhouetteSize = defaultValue(\n this.silhouetteSize,\n source.silhouetteSize\n );\n this.color = defaultValue(this.color, source.color);\n this.colorBlendMode = defaultValue(\n this.colorBlendMode,\n source.colorBlendMode\n );\n this.colorBlendAmount = defaultValue(\n this.colorBlendAmount,\n source.colorBlendAmount\n );\n this.imageBasedLightingFactor = defaultValue(\n this.imageBasedLightingFactor,\n source.imageBasedLightingFactor\n );\n this.lightColor = defaultValue(this.lightColor, source.lightColor);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.clippingPlanes = defaultValue(\n this.clippingPlanes,\n source.clippingPlanes\n );\n this.customShader = defaultValue(this.customShader, source.customShader);\n\n const sourceNodeTransformations = source.nodeTransformations;\n if (defined(sourceNodeTransformations)) {\n const targetNodeTransformations = this.nodeTransformations;\n if (defined(targetNodeTransformations)) {\n targetNodeTransformations.merge(sourceNodeTransformations);\n } else {\n this.nodeTransformations = new PropertyBag(\n sourceNodeTransformations,\n createNodeTransformationProperty\n );\n }\n }\n\n const sourceArticulations = source.articulations;\n if (defined(sourceArticulations)) {\n const targetArticulations = this.articulations;\n if (defined(targetArticulations)) {\n targetArticulations.merge(sourceArticulations);\n } else {\n this.articulations = new PropertyBag(sourceArticulations);\n }\n }\n};\nexport default ModelGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} Cesium3DTilesetGraphics.ConstructorOptions\n *\n * Initialization options for the Cesium3DTilesetGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the tileset.\n * @property {Property | string | Resource} [uri] A string or Resource Property specifying the URI of the tileset.\n * @property {Property | number} [maximumScreenSpaceError] A number or Property specifying the maximum screen space error used to drive level of detail refinement.\n */\n\n/**\n * A 3D Tiles tileset represented by an {@link Entity}.\n * The tileset modelMatrix is determined by the containing Entity position and orientation\n * or is left unset if position is undefined.\n *\n * @alias Cesium3DTilesetGraphics\n * @constructor\n *\n * @param {Cesium3DTilesetGraphics.ConstructorOptions} [options] Object describing initialization options\n */\nfunction Cesium3DTilesetGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._uri = undefined;\n this._uriSubscription = undefined;\n this._maximumScreenSpaceError = undefined;\n this._maximumScreenSpaceErrorSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(Cesium3DTilesetGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof Cesium3DTilesetGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the model.\n * @memberof Cesium3DTilesetGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the string Property specifying the URI of the glTF asset.\n * @memberof Cesium3DTilesetGraphics.prototype\n * @type {Property|undefined}\n */\n uri: createPropertyDescriptor(\"uri\"),\n\n /**\n * Gets or sets the maximum screen space error used to drive level of detail refinement.\n * @memberof Cesium3DTilesetGraphics.prototype\n * @type {Property|undefined}\n */\n maximumScreenSpaceError: createPropertyDescriptor(\"maximumScreenSpaceError\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {Cesium3DTilesetGraphics} [result] The object onto which to store the result.\n * @returns {Cesium3DTilesetGraphics} The modified result parameter or a new instance if one was not provided.\n */\nCesium3DTilesetGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new Cesium3DTilesetGraphics(this);\n }\n result.show = this.show;\n result.uri = this.uri;\n result.maximumScreenSpaceError = this.maximumScreenSpaceError;\n\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {Cesium3DTilesetGraphics} source The object to be merged into this object.\n */\nCesium3DTilesetGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.uri = defaultValue(this.uri, source.uri);\n this.maximumScreenSpaceError = defaultValue(\n this.maximumScreenSpaceError,\n source.maximumScreenSpaceError\n );\n};\n\nexport default Cesium3DTilesetGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} PathGraphics.ConstructorOptions\n *\n * Initialization options for the PathGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the path.\n * @property {Property | number} [leadTime] A Property specifying the number of seconds in front the object to show.\n * @property {Property | number} [trailTime] A Property specifying the number of seconds behind of the object to show.\n * @property {Property | number} [width=1.0] A numeric Property specifying the width in pixels.\n * @property {Property | number} [resolution=60] A numeric Property specifying the maximum number of seconds to step when sampling the position.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to draw the path.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this path will be displayed.\n */\n\n/**\n * Describes a polyline defined as the path made by an {@link Entity} as it moves over time.\n *\n * @alias PathGraphics\n * @constructor\n *\n * @param {PathGraphics.ConstructorOptions} [options] Object describing initialization options\n */\nfunction PathGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._leadTime = undefined;\n this._leadTimeSubscription = undefined;\n this._trailTime = undefined;\n this._trailTimeSubscription = undefined;\n this._width = undefined;\n this._widthSubscription = undefined;\n this._resolution = undefined;\n this._resolutionSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PathGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PathGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the path.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the number of seconds in front of the object to show.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n */\n leadTime: createPropertyDescriptor(\"leadTime\"),\n\n /**\n * Gets or sets the Property specifying the number of seconds behind the object to show.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n */\n trailTime: createPropertyDescriptor(\"trailTime\"),\n\n /**\n * Gets or sets the numeric Property specifying the width in pixels.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n width: createPropertyDescriptor(\"width\"),\n\n /**\n * Gets or sets the Property specifying the maximum number of seconds to step when sampling the position.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n * @default 60\n */\n resolution: createPropertyDescriptor(\"resolution\"),\n\n /**\n * Gets or sets the Property specifying the material used to draw the path.\n * @memberof PathGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this path will be displayed.\n * @memberof PathGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PathGraphics} [result] The object onto which to store the result.\n * @returns {PathGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPathGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PathGraphics(this);\n }\n result.show = this.show;\n result.leadTime = this.leadTime;\n result.trailTime = this.trailTime;\n result.width = this.width;\n result.resolution = this.resolution;\n result.material = this.material;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PathGraphics} source The object to be merged into this object.\n */\nPathGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.leadTime = defaultValue(this.leadTime, source.leadTime);\n this.trailTime = defaultValue(this.trailTime, source.trailTime);\n this.width = defaultValue(this.width, source.width);\n this.resolution = defaultValue(this.resolution, source.resolution);\n this.material = defaultValue(this.material, source.material);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default PathGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} PlaneGraphics.ConstructorOptions\n *\n * Initialization options for the PlaneGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the plane.\n * @property {Property | Plane} [plane] A {@link Plane} Property specifying the normal and distance for the plane.\n * @property {Property | Cartesian2} [dimensions] A {@link Cartesian2} Property specifying the width and height of the plane.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the plane is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the plane.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the plane is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the plane casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this plane will be displayed.\n */\n\n/**\n * Describes a plane. The center position and orientation are determined by the containing {@link Entity}.\n *\n * @alias PlaneGraphics\n * @constructor\n *\n * @param {PlaneGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Plane.html|Cesium Sandcastle Plane Demo}\n */\nfunction PlaneGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._plane = undefined;\n this._planeSubscription = undefined;\n this._dimensions = undefined;\n this._dimensionsSubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PlaneGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PlaneGraphics.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the plane.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the {@link Plane} Property specifying the normal and distance of the plane.\n *\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n */\n plane: createPropertyDescriptor(\"plane\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the width and height of the plane.\n *\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n */\n dimensions: createPropertyDescriptor(\"dimensions\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the plane is filled with the provided material.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the material used to fill the plane.\n * @memberof PlaneGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the plane is outlined.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the plane\n * casts or receives shadows from light sources.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this plane will be displayed.\n * @memberof PlaneGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PlaneGraphics} [result] The object onto which to store the result.\n * @returns {PlaneGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPlaneGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PlaneGraphics(this);\n }\n result.show = this.show;\n result.plane = this.plane;\n result.dimensions = this.dimensions;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PlaneGraphics} source The object to be merged into this object.\n */\nPlaneGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.plane = defaultValue(this.plane, source.plane);\n this.dimensions = defaultValue(this.dimensions, source.dimensions);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default PlaneGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} PointGraphics.ConstructorOptions\n *\n * Initialization options for the PointGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the point.\n * @property {Property | number} [pixelSize=1] A numeric Property specifying the size in pixels.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | Color} [color=Color.WHITE] A Property specifying the {@link Color} of the point.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=0] A numeric Property specifying the the outline width in pixels.\n * @property {Property | NearFarScalar} [scaleByDistance] A {@link NearFarScalar} Property used to scale the point based on distance.\n * @property {Property | NearFarScalar} [translucencyByDistance] A {@link NearFarScalar} Property used to set translucency based on distance from the camera.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this point will be displayed.\n * @property {Property | number} [disableDepthTestDistance] A Property specifying the distance from the camera at which to disable the depth test to.\n */\n\n/**\n * Describes a graphical point located at the position of the containing {@link Entity}.\n *\n * @alias PointGraphics\n * @constructor\n *\n * @param {PointGraphics.ConstructorOptions} [options] Object describing initialization options\n */\nfunction PointGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._pixelSize = undefined;\n this._pixelSizeSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._color = undefined;\n this._colorSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._scaleByDistance = undefined;\n this._scaleByDistanceSubscription = undefined;\n this._translucencyByDistance = undefined;\n this._translucencyByDistanceSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._disableDepthTestDistance = undefined;\n this._disableDepthTestDistanceSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PointGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PointGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the point.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the numeric Property specifying the size in pixels.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default 1\n */\n pixelSize: createPropertyDescriptor(\"pixelSize\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the point.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the the outline width in pixels.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets the {@link NearFarScalar} Property used to scale the point based on distance.\n * If undefined, a constant size is used.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n */\n scaleByDistance: createPropertyDescriptor(\"scaleByDistance\"),\n\n /**\n * Gets or sets {@link NearFarScalar} Property specifying the translucency of the point based on the distance from the camera.\n * A point's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the points's translucency remains clamped to the nearest bound.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n */\n translucencyByDistance: createPropertyDescriptor(\"translucencyByDistance\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this point will be displayed.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof PointGraphics.prototype\n * @type {Property|undefined}\n */\n disableDepthTestDistance: createPropertyDescriptor(\n \"disableDepthTestDistance\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PointGraphics} [result] The object onto which to store the result.\n * @returns {PointGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPointGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PointGraphics(this);\n }\n result.show = this.show;\n result.pixelSize = this.pixelSize;\n result.heightReference = this.heightReference;\n result.color = this.color;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.scaleByDistance = this.scaleByDistance;\n result.translucencyByDistance = this._translucencyByDistance;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.disableDepthTestDistance = this.disableDepthTestDistance;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PointGraphics} source The object to be merged into this object.\n */\nPointGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.pixelSize = defaultValue(this.pixelSize, source.pixelSize);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.color = defaultValue(this.color, source.color);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.scaleByDistance = defaultValue(\n this.scaleByDistance,\n source.scaleByDistance\n );\n this.translucencyByDistance = defaultValue(\n this._translucencyByDistance,\n source.translucencyByDistance\n );\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.disableDepthTestDistance = defaultValue(\n this.disableDepthTestDistance,\n source.disableDepthTestDistance\n );\n};\nexport default PointGraphics;\n", "import defined from \"./defined.js\";\n\n/**\n * An hierarchy of linear rings which define a polygon and its holes.\n * The holes themselves may also have holes which nest inner polygons.\n * @alias PolygonHierarchy\n * @constructor\n *\n * @param {Cartesian3[]} [positions] A linear ring defining the outer boundary of the polygon or hole.\n * @param {PolygonHierarchy[]} [holes] An array of polygon hierarchies defining holes in the polygon.\n */\nfunction PolygonHierarchy(positions, holes) {\n /**\n * A linear ring defining the outer boundary of the polygon or hole.\n * @type {Cartesian3[]}\n */\n this.positions = defined(positions) ? positions : [];\n\n /**\n * An array of polygon hierarchies defining holes in the polygon.\n * @type {PolygonHierarchy[]}\n */\n this.holes = defined(holes) ? holes : [];\n}\nexport default PolygonHierarchy;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport PolygonHierarchy from \"../Core/PolygonHierarchy.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\nfunction createPolygonHierarchyProperty(value) {\n if (Array.isArray(value)) {\n // convert array of positions to PolygonHierarchy object\n value = new PolygonHierarchy(value);\n }\n return new ConstantProperty(value);\n}\n\n/**\n * @typedef {object} PolygonGraphics.ConstructorOptions\n *\n * Initialization options for the PolygonGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the polygon.\n * @property {Property | PolygonHierarchy | Cartesian3[]} [hierarchy] A Property specifying the {@link PolygonHierarchy}.\n * @property {Property | number} [height=0] A numeric Property specifying the altitude of the polygon relative to the ellipsoid surface.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | number} [extrudedHeight] A numeric Property specifying the altitude of the polygon's extruded face relative to the ellipsoid surface.\n * @property {Property | HeightReference} [extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.\n * @property {Property | number} [stRotation=0.0] A numeric property specifying the rotation of the polygon texture counter-clockwise from north. Only has an effect if textureCoordinates is not defined.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the polygon is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the polygon.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the polygon is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | boolean} [perPositionHeight=false] A boolean specifying whether or not the height of each position is used.\n * @property {boolean | boolean} [closeTop=true] When false, leaves off the top of an extruded polygon open.\n * @property {boolean | boolean} [closeBottom=true] When false, leaves off the bottom of an extruded polygon open.\n * @property {Property | ArcType} [arcType=ArcType.GEODESIC] The type of line the polygon edges must follow.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the polygon casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this polygon will be displayed.\n * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this polygon will classify terrain, 3D Tiles, or both when on the ground.\n * @property {ConstantProperty | number} [zIndex=0] A property specifying the zIndex used for ordering ground geometry. Only has an effect if the polygon is constant and neither height or extrudedHeight are specified.\n * @property {Property | PolygonHierarchy} [textureCoordinates] A Property specifying texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points. Has no effect for ground primitives.\n */\n\n/**\n * Describes a polygon defined by an hierarchy of linear rings which make up the outer shape and any nested holes.\n * The polygon conforms to the curvature of the globe and can be placed on the surface or\n * at altitude and can optionally be extruded into a volume.\n *\n * @alias PolygonGraphics\n * @constructor\n *\n * @param {PolygonGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polygon.html|Cesium Sandcastle Polygon Demo}\n */\nfunction PolygonGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._hierarchy = undefined;\n this._hierarchySubscription = undefined;\n this._height = undefined;\n this._heightSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._extrudedHeight = undefined;\n this._extrudedHeightSubscription = undefined;\n this._extrudedHeightReference = undefined;\n this._extrudedHeightReferenceSubscription = undefined;\n this._stRotation = undefined;\n this._stRotationSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._perPositionHeight = undefined;\n this._perPositionHeightSubscription = undefined;\n this._closeTop = undefined;\n this._closeTopSubscription = undefined;\n this._closeBottom = undefined;\n this._closeBottomSubscription = undefined;\n this._arcType = undefined;\n this._arcTypeSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._classificationType = undefined;\n this._classificationTypeSubscription = undefined;\n this._zIndex = undefined;\n this._zIndexSubscription = undefined;\n this._textureCoordinates = undefined;\n this._textureCoordinatesSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PolygonGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PolygonGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the polygon.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the {@link PolygonHierarchy}.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n hierarchy: createPropertyDescriptor(\n \"hierarchy\",\n undefined,\n createPolygonHierarchyProperty\n ),\n\n /**\n * Gets or sets the numeric Property specifying the constant altitude of the polygon.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n height: createPropertyDescriptor(\"height\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the polygon extrusion.\n * If {@link PolygonGraphics#perPositionHeight} is false, the volume starts at {@link PolygonGraphics#height} and ends at this altitude.\n * If {@link PolygonGraphics#perPositionHeight} is true, the volume starts at the height of each {@link PolygonGraphics#hierarchy} position and ends at this altitude.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n extrudedHeight: createPropertyDescriptor(\"extrudedHeight\"),\n\n /**\n * Gets or sets the Property specifying the extruded {@link HeightReference}.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n extrudedHeightReference: createPropertyDescriptor(\"extrudedHeightReference\"),\n\n /**\n * Gets or sets the numeric property specifying the rotation of the polygon texture counter-clockwise from north. Only has an effect if textureCoordinates is not defined.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n stRotation: createPropertyDescriptor(\"stRotation\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between points on the polygon.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the polygon is filled with the provided material.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the polygon.\n * @memberof PolygonGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the polygon is outlined.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Gets or sets the boolean specifying whether or not the the height of each position is used.\n * If true, the shape will have non-uniform altitude defined by the height of each {@link PolygonGraphics#hierarchy} position.\n * If false, the shape will have a constant altitude as specified by {@link PolygonGraphics#height}.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n perPositionHeight: createPropertyDescriptor(\"perPositionHeight\"),\n\n /**\n * Gets or sets a boolean specifying whether or not the top of an extruded polygon is included.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n closeTop: createPropertyDescriptor(\"closeTop\"),\n\n /**\n * Gets or sets a boolean specifying whether or not the bottom of an extruded polygon is included.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n closeBottom: createPropertyDescriptor(\"closeBottom\"),\n\n /**\n * Gets or sets the {@link ArcType} Property specifying the type of lines the polygon edges use.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default ArcType.GEODESIC\n */\n arcType: createPropertyDescriptor(\"arcType\"),\n\n /**\n * Get or sets the enum Property specifying whether the polygon\n * casts or receives shadows from light sources.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this polygon will be displayed.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the {@link ClassificationType} Property specifying whether this polygon will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n * @default ClassificationType.BOTH\n */\n classificationType: createPropertyDescriptor(\"classificationType\"),\n\n /**\n * Gets or sets the zIndex Prperty specifying the ordering of ground geometry. Only has an effect if the polygon is constant and neither height or extrudedHeight are specified.\n * @memberof PolygonGraphics.prototype\n * @type {ConstantProperty|undefined}\n * @default 0\n */\n zIndex: createPropertyDescriptor(\"zIndex\"),\n\n /**\n * A Property specifying texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points. Has no effect for ground primitives.\n * @memberof PolygonGraphics.prototype\n * @type {Property|undefined}\n */\n textureCoordinates: createPropertyDescriptor(\"textureCoordinates\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PolygonGraphics} [result] The object onto which to store the result.\n * @returns {PolygonGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPolygonGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PolygonGraphics(this);\n }\n result.show = this.show;\n result.hierarchy = this.hierarchy;\n result.height = this.height;\n result.heightReference = this.heightReference;\n result.extrudedHeight = this.extrudedHeight;\n result.extrudedHeightReference = this.extrudedHeightReference;\n result.stRotation = this.stRotation;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.perPositionHeight = this.perPositionHeight;\n result.closeTop = this.closeTop;\n result.closeBottom = this.closeBottom;\n result.arcType = this.arcType;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.classificationType = this.classificationType;\n result.zIndex = this.zIndex;\n result.textureCoordinates = this.textureCoordinates;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PolygonGraphics} source The object to be merged into this object.\n */\nPolygonGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.hierarchy = defaultValue(this.hierarchy, source.hierarchy);\n this.height = defaultValue(this.height, source.height);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.extrudedHeight = defaultValue(\n this.extrudedHeight,\n source.extrudedHeight\n );\n this.extrudedHeightReference = defaultValue(\n this.extrudedHeightReference,\n source.extrudedHeightReference\n );\n this.stRotation = defaultValue(this.stRotation, source.stRotation);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.perPositionHeight = defaultValue(\n this.perPositionHeight,\n source.perPositionHeight\n );\n this.closeTop = defaultValue(this.closeTop, source.closeTop);\n this.closeBottom = defaultValue(this.closeBottom, source.closeBottom);\n this.arcType = defaultValue(this.arcType, source.arcType);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.classificationType = defaultValue(\n this.classificationType,\n source.classificationType\n );\n this.zIndex = defaultValue(this.zIndex, source.zIndex);\n this.textureCoordinates = defaultValue(\n this.textureCoordinates,\n source.textureCoordinates\n );\n};\nexport default PolygonGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} PolylineGraphics.ConstructorOptions\n *\n * Initialization options for the PolylineGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the polyline.\n * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions that define the line strip.\n * @property {Property | number} [width=1.0] A numeric Property specifying the width in pixels.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude if arcType is not ArcType.NONE.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to draw the polyline.\n * @property {MaterialProperty | Color} [depthFailMaterial] A property specifying the material used to draw the polyline when it is below the terrain.\n * @property {Property | ArcType} [arcType=ArcType.GEODESIC] The type of line the polyline segments must follow.\n * @property {Property | boolean} [clampToGround=false] A boolean Property specifying whether the Polyline should be clamped to the ground.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the polyline casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this polyline will be displayed.\n * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.\n * @property {Property | number} [zIndex=0] A Property specifying the zIndex used for ordering ground geometry. Only has an effect if `clampToGround` is true and polylines on terrain is supported.\n */\n\n/**\n * Describes a polyline. The first two positions define a line segment,\n * and each additional position defines a line segment from the previous position. The segments\n * can be linear connected points, great arcs, or clamped to terrain.\n *\n * @alias PolylineGraphics\n * @constructor\n *\n * @param {PolylineGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}\n */\nfunction PolylineGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._positions = undefined;\n this._positionsSubscription = undefined;\n this._width = undefined;\n this._widthSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._depthFailMaterial = undefined;\n this._depthFailMaterialSubscription = undefined;\n this._arcType = undefined;\n this._arcTypeSubscription = undefined;\n this._clampToGround = undefined;\n this._clampToGroundSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n this._classificationType = undefined;\n this._classificationTypeSubscription = undefined;\n this._zIndex = undefined;\n this._zIndexSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PolylineGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PolylineGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the polyline.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the array of {@link Cartesian3}\n * positions that define the line strip.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n */\n positions: createPropertyDescriptor(\"positions\"),\n\n /**\n * Gets or sets the numeric Property specifying the width in pixels.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n width: createPropertyDescriptor(\"width\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between each latitude and longitude if arcType is not ArcType.NONE and clampToGround is false.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default Cesium.Math.RADIANS_PER_DEGREE\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the Property specifying the material used to draw the polyline.\n * @memberof PolylineGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying the material used to draw the polyline when it fails the depth test.\n *

\n * Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported,\n * there may be artifacts.\n *

\n * @memberof PolylineGraphics.prototype\n * @type {MaterialProperty}\n * @default undefined\n */\n depthFailMaterial: createMaterialPropertyDescriptor(\"depthFailMaterial\"),\n\n /**\n * Gets or sets the {@link ArcType} Property specifying whether the line segments should be great arcs, rhumb lines or linearly connected.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default ArcType.GEODESIC\n */\n arcType: createPropertyDescriptor(\"arcType\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the polyline\n * should be clamped to the ground.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n clampToGround: createPropertyDescriptor(\"clampToGround\"),\n\n /**\n * Get or sets the enum Property specifying whether the polyline\n * casts or receives shadows from light sources.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this polyline will be displayed.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the {@link ClassificationType} Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof PolylineGraphics.prototype\n * @type {Property|undefined}\n * @default ClassificationType.BOTH\n */\n classificationType: createPropertyDescriptor(\"classificationType\"),\n\n /**\n * Gets or sets the zIndex Property specifying the ordering of the polyline. Only has an effect if `clampToGround` is true and polylines on terrain is supported.\n * @memberof PolylineGraphics.prototype\n * @type {ConstantProperty|undefined}\n * @default 0\n */\n zIndex: createPropertyDescriptor(\"zIndex\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PolylineGraphics} [result] The object onto which to store the result.\n * @returns {PolylineGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPolylineGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PolylineGraphics(this);\n }\n result.show = this.show;\n result.positions = this.positions;\n result.width = this.width;\n result.granularity = this.granularity;\n result.material = this.material;\n result.depthFailMaterial = this.depthFailMaterial;\n result.arcType = this.arcType;\n result.clampToGround = this.clampToGround;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.classificationType = this.classificationType;\n result.zIndex = this.zIndex;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PolylineGraphics} source The object to be merged into this object.\n */\nPolylineGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.positions = defaultValue(this.positions, source.positions);\n this.width = defaultValue(this.width, source.width);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.material = defaultValue(this.material, source.material);\n this.depthFailMaterial = defaultValue(\n this.depthFailMaterial,\n source.depthFailMaterial\n );\n this.arcType = defaultValue(this.arcType, source.arcType);\n this.clampToGround = defaultValue(this.clampToGround, source.clampToGround);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.classificationType = defaultValue(\n this.classificationType,\n source.classificationType\n );\n this.zIndex = defaultValue(this.zIndex, source.zIndex);\n};\nexport default PolylineGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} PolylineVolumeGraphics.ConstructorOptions\n *\n * Initialization options for the PolylineVolumeGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the volume.\n * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions which define the line strip.\n * @property {Property | Cartesian2[]} [shape] A Property specifying the array of {@link Cartesian2} positions which define the shape to be extruded.\n * @property {Property | CornerType} [cornerType=CornerType.ROUNDED] A {@link CornerType} Property specifying the style of the corners.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the volume is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the volume.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the volume is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the volume casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this volume will be displayed.\n */\n\n/**\n * Describes a polyline volume defined as a line strip and corresponding two dimensional shape which is extruded along it.\n * The resulting volume conforms to the curvature of the globe.\n *\n * @alias PolylineVolumeGraphics\n * @constructor\n *\n * @param {PolylineVolumeGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline%20Volume.html|Cesium Sandcastle Polyline Volume Demo}\n */\nfunction PolylineVolumeGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._positions = undefined;\n this._positionsSubscription = undefined;\n this._shape = undefined;\n this._shapeSubscription = undefined;\n this._cornerType = undefined;\n this._cornerTypeSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubsription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(PolylineVolumeGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof PolylineVolumeGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the volume.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the array of {@link Cartesian3} positions which define the line strip.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n */\n positions: createPropertyDescriptor(\"positions\"),\n\n /**\n * Gets or sets the Property specifying the array of {@link Cartesian2} positions which define the shape to be extruded.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n */\n shape: createPropertyDescriptor(\"shape\"),\n\n /**\n * Gets or sets the {@link CornerType} Property specifying the style of the corners.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default CornerType.ROUNDED\n */\n cornerType: createPropertyDescriptor(\"cornerType\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between points on the volume.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the volume is filled with the provided material.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the volume.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the volume is outlined.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the volume\n * casts or receives shadows from light sources.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this volume will be displayed.\n * @memberof PolylineVolumeGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {PolylineVolumeGraphics} [result] The object onto which to store the result.\n * @returns {PolylineVolumeGraphics} The modified result parameter or a new instance if one was not provided.\n */\nPolylineVolumeGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new PolylineVolumeGraphics(this);\n }\n result.show = this.show;\n result.positions = this.positions;\n result.shape = this.shape;\n result.cornerType = this.cornerType;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {PolylineVolumeGraphics} source The object to be merged into this object.\n */\nPolylineVolumeGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.positions = defaultValue(this.positions, source.positions);\n this.shape = defaultValue(this.shape, source.shape);\n this.cornerType = defaultValue(this.cornerType, source.cornerType);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default PolylineVolumeGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} RectangleGraphics.ConstructorOptions\n *\n * Initialization options for the RectangleGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the rectangle.\n * @property {Property | Rectangle} [coordinates] The Property specifying the {@link Rectangle}.\n * @property {Property | number} [height=0] A numeric Property specifying the altitude of the rectangle relative to the ellipsoid surface.\n * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.\n * @property {Property | number} [extrudedHeight] A numeric Property specifying the altitude of the rectangle's extruded face relative to the ellipsoid surface.\n * @property {Property | HeightReference} [extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.\n * @property {Property | number} [rotation=0.0] A numeric property specifying the rotation of the rectangle clockwise from north.\n * @property {Property | number} [stRotation=0.0] A numeric property specifying the rotation of the rectangle texture counter-clockwise from north.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between points on the rectangle.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the rectangle is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the rectangle.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the rectangle is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the rectangle casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this rectangle will be displayed.\n * @property {Property | ClassificationType} [classificationType=ClassificationType.BOTH] An enum Property specifying whether this rectangle will classify terrain, 3D Tiles, or both when on the ground.\n * @property {Property | number} [zIndex=0] A Property specifying the zIndex used for ordering ground geometry. Only has an effect if the rectangle is constant and neither height or extrudedHeight are specified.\n */\n\n/**\n * Describes graphics for a {@link Rectangle}.\n * The rectangle conforms to the curvature of the globe and can be placed on the surface or\n * at altitude and can optionally be extruded into a volume.\n *\n * @alias RectangleGraphics\n * @constructor\n *\n * @param {RectangleGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Rectangle.html|Cesium Sandcastle Rectangle Demo}\n */\nfunction RectangleGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._coordinates = undefined;\n this._coordinatesSubscription = undefined;\n this._height = undefined;\n this._heightSubscription = undefined;\n this._heightReference = undefined;\n this._heightReferenceSubscription = undefined;\n this._extrudedHeight = undefined;\n this._extrudedHeightSubscription = undefined;\n this._extrudedHeightReference = undefined;\n this._extrudedHeightReferenceSubscription = undefined;\n this._rotation = undefined;\n this._rotationSubscription = undefined;\n this._stRotation = undefined;\n this._stRotationSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distancedisplayConditionSubscription = undefined;\n this._classificationType = undefined;\n this._classificationTypeSubscription = undefined;\n this._zIndex = undefined;\n this._zIndexSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(RectangleGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof RectangleGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the rectangle.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the {@link Rectangle}.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n */\n coordinates: createPropertyDescriptor(\"coordinates\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the rectangle.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n height: createPropertyDescriptor(\"height\"),\n\n /**\n * Gets or sets the Property specifying the {@link HeightReference}.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n heightReference: createPropertyDescriptor(\"heightReference\"),\n\n /**\n * Gets or sets the numeric Property specifying the altitude of the rectangle extrusion.\n * Setting this property creates volume starting at height and ending at this altitude.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n */\n extrudedHeight: createPropertyDescriptor(\"extrudedHeight\"),\n\n /**\n * Gets or sets the Property specifying the extruded {@link HeightReference}.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default HeightReference.NONE\n */\n extrudedHeightReference: createPropertyDescriptor(\"extrudedHeightReference\"),\n\n /**\n * Gets or sets the numeric property specifying the rotation of the rectangle clockwise from north.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n rotation: createPropertyDescriptor(\"rotation\"),\n\n /**\n * Gets or sets the numeric property specifying the rotation of the rectangle texture counter-clockwise from north.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default 0\n */\n stRotation: createPropertyDescriptor(\"stRotation\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between points on the rectangle.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the rectangle is filled with the provided material.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the rectangle.\n * @memberof RectangleGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the rectangle is outlined.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the rectangle\n * casts or receives shadows from light sources.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this rectangle will be displayed.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n\n /**\n * Gets or sets the {@link ClassificationType} Property specifying whether this rectangle will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof RectangleGraphics.prototype\n * @type {Property|undefined}\n * @default ClassificationType.BOTH\n */\n classificationType: createPropertyDescriptor(\"classificationType\"),\n\n /**\n * Gets or sets the zIndex Property specifying the ordering of the rectangle. Only has an effect if the rectangle is constant and neither height or extrudedHeight are specified.\n * @memberof RectangleGraphics.prototype\n * @type {ConstantProperty|undefined}\n * @default 0\n */\n zIndex: createPropertyDescriptor(\"zIndex\"),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {RectangleGraphics} [result] The object onto which to store the result.\n * @returns {RectangleGraphics} The modified result parameter or a new instance if one was not provided.\n */\nRectangleGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new RectangleGraphics(this);\n }\n result.show = this.show;\n result.coordinates = this.coordinates;\n result.height = this.height;\n result.heightReference = this.heightReference;\n result.extrudedHeight = this.extrudedHeight;\n result.extrudedHeightReference = this.extrudedHeightReference;\n result.rotation = this.rotation;\n result.stRotation = this.stRotation;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n result.classificationType = this.classificationType;\n result.zIndex = this.zIndex;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {RectangleGraphics} source The object to be merged into this object.\n */\nRectangleGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.coordinates = defaultValue(this.coordinates, source.coordinates);\n this.height = defaultValue(this.height, source.height);\n this.heightReference = defaultValue(\n this.heightReference,\n source.heightReference\n );\n this.extrudedHeight = defaultValue(\n this.extrudedHeight,\n source.extrudedHeight\n );\n this.extrudedHeightReference = defaultValue(\n this.extrudedHeightReference,\n source.extrudedHeightReference\n );\n this.rotation = defaultValue(this.rotation, source.rotation);\n this.stRotation = defaultValue(this.stRotation, source.stRotation);\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n this.classificationType = defaultValue(\n this.classificationType,\n source.classificationType\n );\n this.zIndex = defaultValue(this.zIndex, source.zIndex);\n};\nexport default RectangleGraphics;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport createMaterialPropertyDescriptor from \"./createMaterialPropertyDescriptor.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\n\n/**\n * @typedef {object} WallGraphics.ConstructorOptions\n *\n * Initialization options for the WallGraphics constructor\n *\n * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the wall.\n * @property {Property | Cartesian3[]} [positions] A Property specifying the array of {@link Cartesian3} positions which define the top of the wall.\n * @property {Property | number[]} [minimumHeights] A Property specifying an array of heights to be used for the bottom of the wall instead of the globe surface.\n * @property {Property | number[]} [maximumHeights] A Property specifying an array of heights to be used for the top of the wall instead of the height of each position.\n * @property {Property | number} [granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.\n * @property {Property | boolean} [fill=true] A boolean Property specifying whether the wall is filled with the provided material.\n * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the wall.\n * @property {Property | boolean} [outline=false] A boolean Property specifying whether the wall is outlined.\n * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.\n * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the wall casts or receives shadows from light sources.\n * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this wall will be displayed.\n */\n\n/**\n * Describes a two dimensional wall defined as a line strip and optional maximum and minimum heights.\n * The wall conforms to the curvature of the globe and can be placed along the surface or at altitude.\n *\n * @alias WallGraphics\n * @constructor\n *\n * @param {WallGraphics.ConstructorOptions} [options] Object describing initialization options\n *\n * @see Entity\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Wall.html|Cesium Sandcastle Wall Demo}\n */\nfunction WallGraphics(options) {\n this._definitionChanged = new Event();\n this._show = undefined;\n this._showSubscription = undefined;\n this._positions = undefined;\n this._positionsSubscription = undefined;\n this._minimumHeights = undefined;\n this._minimumHeightsSubscription = undefined;\n this._maximumHeights = undefined;\n this._maximumHeightsSubscription = undefined;\n this._granularity = undefined;\n this._granularitySubscription = undefined;\n this._fill = undefined;\n this._fillSubscription = undefined;\n this._material = undefined;\n this._materialSubscription = undefined;\n this._outline = undefined;\n this._outlineSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n this._shadows = undefined;\n this._shadowsSubscription = undefined;\n this._distanceDisplayCondition = undefined;\n this._distanceDisplayConditionSubscription = undefined;\n\n this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));\n}\n\nObject.defineProperties(WallGraphics.prototype, {\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof WallGraphics.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the boolean Property specifying the visibility of the wall.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n show: createPropertyDescriptor(\"show\"),\n\n /**\n * Gets or sets the Property specifying the array of {@link Cartesian3} positions which define the top of the wall.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n */\n positions: createPropertyDescriptor(\"positions\"),\n\n /**\n * Gets or sets the Property specifying an array of heights to be used for the bottom of the wall instead of the surface of the globe.\n * If defined, the array must be the same length as {@link Wall#positions}.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n */\n minimumHeights: createPropertyDescriptor(\"minimumHeights\"),\n\n /**\n * Gets or sets the Property specifying an array of heights to be used for the top of the wall instead of the height of each position.\n * If defined, the array must be the same length as {@link Wall#positions}.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n */\n maximumHeights: createPropertyDescriptor(\"maximumHeights\"),\n\n /**\n * Gets or sets the numeric Property specifying the angular distance between points on the wall.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default {CesiumMath.RADIANS_PER_DEGREE}\n */\n granularity: createPropertyDescriptor(\"granularity\"),\n\n /**\n * Gets or sets the boolean Property specifying whether the wall is filled with the provided material.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default true\n */\n fill: createPropertyDescriptor(\"fill\"),\n\n /**\n * Gets or sets the Property specifying the material used to fill the wall.\n * @memberof WallGraphics.prototype\n * @type {MaterialProperty}\n * @default Color.WHITE\n */\n material: createMaterialPropertyDescriptor(\"material\"),\n\n /**\n * Gets or sets the Property specifying whether the wall is outlined.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default false\n */\n outline: createPropertyDescriptor(\"outline\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n *

\n * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.\n *

\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n\n /**\n * Get or sets the enum Property specifying whether the wall\n * casts or receives shadows from light sources.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n * @default ShadowMode.DISABLED\n */\n shadows: createPropertyDescriptor(\"shadows\"),\n\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this wall will be displayed.\n * @memberof WallGraphics.prototype\n * @type {Property|undefined}\n */\n distanceDisplayCondition: createPropertyDescriptor(\n \"distanceDisplayCondition\"\n ),\n});\n\n/**\n * Duplicates this instance.\n *\n * @param {WallGraphics} [result] The object onto which to store the result.\n * @returns {WallGraphics} The modified result parameter or a new instance if one was not provided.\n */\nWallGraphics.prototype.clone = function (result) {\n if (!defined(result)) {\n return new WallGraphics(this);\n }\n result.show = this.show;\n result.positions = this.positions;\n result.minimumHeights = this.minimumHeights;\n result.maximumHeights = this.maximumHeights;\n result.granularity = this.granularity;\n result.fill = this.fill;\n result.material = this.material;\n result.outline = this.outline;\n result.outlineColor = this.outlineColor;\n result.outlineWidth = this.outlineWidth;\n result.shadows = this.shadows;\n result.distanceDisplayCondition = this.distanceDisplayCondition;\n return result;\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {WallGraphics} source The object to be merged into this object.\n */\nWallGraphics.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.show = defaultValue(this.show, source.show);\n this.positions = defaultValue(this.positions, source.positions);\n this.minimumHeights = defaultValue(\n this.minimumHeights,\n source.minimumHeights\n );\n this.maximumHeights = defaultValue(\n this.maximumHeights,\n source.maximumHeights\n );\n this.granularity = defaultValue(this.granularity, source.granularity);\n this.fill = defaultValue(this.fill, source.fill);\n this.material = defaultValue(this.material, source.material);\n this.outline = defaultValue(this.outline, source.outline);\n this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);\n this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);\n this.shadows = defaultValue(this.shadows, source.shadows);\n this.distanceDisplayCondition = defaultValue(\n this.distanceDisplayCondition,\n source.distanceDisplayCondition\n );\n};\nexport default WallGraphics;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Quaternion from \"../Core/Quaternion.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport GroundPolylinePrimitive from \"../Scene/GroundPolylinePrimitive.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport BoxGraphics from \"./BoxGraphics.js\";\nimport ConstantPositionProperty from \"./ConstantPositionProperty.js\";\nimport CorridorGraphics from \"./CorridorGraphics.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport createRawPropertyDescriptor from \"./createRawPropertyDescriptor.js\";\nimport CylinderGraphics from \"./CylinderGraphics.js\";\nimport EllipseGraphics from \"./EllipseGraphics.js\";\nimport EllipsoidGraphics from \"./EllipsoidGraphics.js\";\nimport LabelGraphics from \"./LabelGraphics.js\";\nimport ModelGraphics from \"./ModelGraphics.js\";\nimport Cesium3DTilesetGraphics from \"./Cesium3DTilesetGraphics.js\";\nimport PathGraphics from \"./PathGraphics.js\";\nimport PlaneGraphics from \"./PlaneGraphics.js\";\nimport PointGraphics from \"./PointGraphics.js\";\nimport PolygonGraphics from \"./PolygonGraphics.js\";\nimport PolylineGraphics from \"./PolylineGraphics.js\";\nimport PolylineVolumeGraphics from \"./PolylineVolumeGraphics.js\";\nimport Property from \"./Property.js\";\nimport PropertyBag from \"./PropertyBag.js\";\nimport RectangleGraphics from \"./RectangleGraphics.js\";\nimport WallGraphics from \"./WallGraphics.js\";\n\nconst cartoScratch = new Cartographic();\n\nfunction createConstantPositionProperty(value) {\n return new ConstantPositionProperty(value);\n}\n\nfunction createPositionPropertyDescriptor(name) {\n return createPropertyDescriptor(\n name,\n undefined,\n createConstantPositionProperty\n );\n}\n\nfunction createPropertyTypeDescriptor(name, Type) {\n return createPropertyDescriptor(name, undefined, function (value) {\n if (value instanceof Type) {\n return value;\n }\n return new Type(value);\n });\n}\n\n/**\n * @typedef {object} Entity.ConstructorOptions\n *\n * Initialization options for the Entity constructor\n *\n * @property {string} [id] A unique identifier for this object. If none is provided, a GUID is generated.\n * @property {string} [name] A human readable name to display to users. It does not have to be unique.\n * @property {TimeIntervalCollection} [availability] The availability, if any, associated with this object.\n * @property {boolean} [show] A boolean value indicating if the entity and its children are displayed.\n * @property {Property | string} [description] A string Property specifying an HTML description for this entity.\n * @property {PositionProperty | Cartesian3} [position] A Property specifying the entity position.\n * @property {Property} [orientation] A Property specifying the entity orientation.\n * @property {Property} [viewFrom] A suggested initial offset for viewing this object.\n * @property {Entity} [parent] A parent entity to associate with this entity.\n * @property {BillboardGraphics | BillboardGraphics.ConstructorOptions} [billboard] A billboard to associate with this entity.\n * @property {BoxGraphics | BoxGraphics.ConstructorOptions} [box] A box to associate with this entity.\n * @property {CorridorGraphics | CorridorGraphics.ConstructorOptions} [corridor] A corridor to associate with this entity.\n * @property {CylinderGraphics | CylinderGraphics.ConstructorOptions} [cylinder] A cylinder to associate with this entity.\n * @property {EllipseGraphics | EllipseGraphics.ConstructorOptions} [ellipse] A ellipse to associate with this entity.\n * @property {EllipsoidGraphics | EllipsoidGraphics.ConstructorOptions} [ellipsoid] A ellipsoid to associate with this entity.\n * @property {LabelGraphics | LabelGraphics.ConstructorOptions} [label] A options.label to associate with this entity.\n * @property {ModelGraphics | ModelGraphics.ConstructorOptions} [model] A model to associate with this entity.\n * @property {Cesium3DTilesetGraphics | Cesium3DTilesetGraphics.ConstructorOptions} [tileset] A 3D Tiles tileset to associate with this entity.\n * @property {PathGraphics | PathGraphics.ConstructorOptions} [path] A path to associate with this entity.\n * @property {PlaneGraphics | PlaneGraphics.ConstructorOptions} [plane] A plane to associate with this entity.\n * @property {PointGraphics | PointGraphics.ConstructorOptions} [point] A point to associate with this entity.\n * @property {PolygonGraphics | PolygonGraphics.ConstructorOptions} [polygon] A polygon to associate with this entity.\n * @property {PolylineGraphics | PolylineGraphics.ConstructorOptions} [polyline] A polyline to associate with this entity.\n * @property {PropertyBag | Object} [properties] Arbitrary properties to associate with this entity.\n * @property {PolylineVolumeGraphics | PolylineVolumeGraphics.ConstructorOptions} [polylineVolume] A polylineVolume to associate with this entity.\n * @property {RectangleGraphics | RectangleGraphics.ConstructorOptions} [rectangle] A rectangle to associate with this entity.\n * @property {WallGraphics | WallGraphics.ConstructorOptions} [wall] A wall to associate with this entity.\n */\n\n/**\n * Entity instances aggregate multiple forms of visualization into a single high-level object.\n * They can be created manually and added to {@link Viewer#entities} or be produced by\n * data sources, such as {@link CzmlDataSource} and {@link GeoJsonDataSource}.\n * @alias Entity\n * @constructor\n *\n * @param {Entity.ConstructorOptions} [options] Object describing initialization options\n *\n * @see {@link https://cesium.com/learn/cesiumjs-learn/cesiumjs-creating-entities/|Creating Entities}\n */\nfunction Entity(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n let id = options.id;\n if (!defined(id)) {\n id = createGuid();\n }\n\n this._availability = undefined;\n this._id = id;\n this._definitionChanged = new Event();\n this._name = options.name;\n this._show = defaultValue(options.show, true);\n this._parent = undefined;\n this._propertyNames = [\n \"billboard\",\n \"box\",\n \"corridor\",\n \"cylinder\",\n \"description\",\n \"ellipse\", //\n \"ellipsoid\",\n \"label\",\n \"model\",\n \"tileset\",\n \"orientation\",\n \"path\",\n \"plane\",\n \"point\",\n \"polygon\", //\n \"polyline\",\n \"polylineVolume\",\n \"position\",\n \"properties\",\n \"rectangle\",\n \"viewFrom\",\n \"wall\",\n ];\n\n this._billboard = undefined;\n this._billboardSubscription = undefined;\n this._box = undefined;\n this._boxSubscription = undefined;\n this._corridor = undefined;\n this._corridorSubscription = undefined;\n this._cylinder = undefined;\n this._cylinderSubscription = undefined;\n this._description = undefined;\n this._descriptionSubscription = undefined;\n this._ellipse = undefined;\n this._ellipseSubscription = undefined;\n this._ellipsoid = undefined;\n this._ellipsoidSubscription = undefined;\n this._label = undefined;\n this._labelSubscription = undefined;\n this._model = undefined;\n this._modelSubscription = undefined;\n this._tileset = undefined;\n this._tilesetSubscription = undefined;\n this._orientation = undefined;\n this._orientationSubscription = undefined;\n this._path = undefined;\n this._pathSubscription = undefined;\n this._plane = undefined;\n this._planeSubscription = undefined;\n this._point = undefined;\n this._pointSubscription = undefined;\n this._polygon = undefined;\n this._polygonSubscription = undefined;\n this._polyline = undefined;\n this._polylineSubscription = undefined;\n this._polylineVolume = undefined;\n this._polylineVolumeSubscription = undefined;\n this._position = undefined;\n this._positionSubscription = undefined;\n this._properties = undefined;\n this._propertiesSubscription = undefined;\n this._rectangle = undefined;\n this._rectangleSubscription = undefined;\n this._viewFrom = undefined;\n this._viewFromSubscription = undefined;\n this._wall = undefined;\n this._wallSubscription = undefined;\n this._children = [];\n\n /**\n * Gets or sets the entity collection that this entity belongs to.\n * @type {EntityCollection}\n */\n this.entityCollection = undefined;\n\n this.parent = options.parent;\n this.merge(options);\n}\n\nfunction updateShow(entity, children, isShowing) {\n const length = children.length;\n for (let i = 0; i < length; i++) {\n const child = children[i];\n const childShow = child._show;\n const oldValue = !isShowing && childShow;\n const newValue = isShowing && childShow;\n if (oldValue !== newValue) {\n updateShow(child, child._children, isShowing);\n }\n }\n entity._definitionChanged.raiseEvent(\n entity,\n \"isShowing\",\n isShowing,\n !isShowing\n );\n}\n\nObject.defineProperties(Entity.prototype, {\n /**\n * The availability, if any, associated with this object.\n * If availability is undefined, it is assumed that this object's\n * other properties will return valid data for any provided time.\n * If availability exists, the objects other properties will only\n * provide valid data if queried within the given interval.\n * @memberof Entity.prototype\n * @type {TimeIntervalCollection|undefined}\n */\n availability: createRawPropertyDescriptor(\"availability\"),\n /**\n * Gets the unique ID associated with this object.\n * @memberof Entity.prototype\n * @type {string}\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * Gets the event that is raised whenever a property or sub-property is changed or modified.\n * @memberof Entity.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the name of the object. The name is intended for end-user\n * consumption and does not need to be unique.\n * @memberof Entity.prototype\n * @type {string|undefined}\n */\n name: createRawPropertyDescriptor(\"name\"),\n /**\n * Gets or sets whether this entity should be displayed. When set to true,\n * the entity is only displayed if the parent entity's show property is also true.\n * @memberof Entity.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (value === this._show) {\n return;\n }\n\n const wasShowing = this.isShowing;\n this._show = value;\n const isShowing = this.isShowing;\n\n if (wasShowing !== isShowing) {\n updateShow(this, this._children, isShowing);\n }\n\n this._definitionChanged.raiseEvent(this, \"show\", value, !value);\n },\n },\n /**\n * Gets whether this entity is being displayed, taking into account\n * the visibility of any ancestor entities.\n * @memberof Entity.prototype\n * @type {boolean}\n */\n isShowing: {\n get: function () {\n return (\n this._show &&\n (!defined(this.entityCollection) || this.entityCollection.show) &&\n (!defined(this._parent) || this._parent.isShowing)\n );\n },\n },\n /**\n * Gets or sets the parent object.\n * @memberof Entity.prototype\n * @type {Entity|undefined}\n */\n parent: {\n get: function () {\n return this._parent;\n },\n set: function (value) {\n const oldValue = this._parent;\n\n if (oldValue === value) {\n return;\n }\n\n const wasShowing = this.isShowing;\n if (defined(oldValue)) {\n const index = oldValue._children.indexOf(this);\n oldValue._children.splice(index, 1);\n }\n\n this._parent = value;\n if (defined(value)) {\n value._children.push(this);\n }\n\n const isShowing = this.isShowing;\n\n if (wasShowing !== isShowing) {\n updateShow(this, this._children, isShowing);\n }\n\n this._definitionChanged.raiseEvent(this, \"parent\", value, oldValue);\n },\n },\n /**\n * Gets the names of all properties registered on this instance.\n * @memberof Entity.prototype\n * @type {string[]}\n */\n propertyNames: {\n get: function () {\n return this._propertyNames;\n },\n },\n /**\n * Gets or sets the billboard.\n * @memberof Entity.prototype\n * @type {BillboardGraphics|undefined}\n */\n billboard: createPropertyTypeDescriptor(\"billboard\", BillboardGraphics),\n /**\n * Gets or sets the box.\n * @memberof Entity.prototype\n * @type {BoxGraphics|undefined}\n */\n box: createPropertyTypeDescriptor(\"box\", BoxGraphics),\n /**\n * Gets or sets the corridor.\n * @memberof Entity.prototype\n * @type {CorridorGraphics|undefined}\n */\n corridor: createPropertyTypeDescriptor(\"corridor\", CorridorGraphics),\n /**\n * Gets or sets the cylinder.\n * @memberof Entity.prototype\n * @type {CylinderGraphics|undefined}\n */\n cylinder: createPropertyTypeDescriptor(\"cylinder\", CylinderGraphics),\n /**\n * Gets or sets the description.\n * @memberof Entity.prototype\n * @type {Property|undefined}\n */\n description: createPropertyDescriptor(\"description\"),\n /**\n * Gets or sets the ellipse.\n * @memberof Entity.prototype\n * @type {EllipseGraphics|undefined}\n */\n ellipse: createPropertyTypeDescriptor(\"ellipse\", EllipseGraphics),\n /**\n * Gets or sets the ellipsoid.\n * @memberof Entity.prototype\n * @type {EllipsoidGraphics|undefined}\n */\n ellipsoid: createPropertyTypeDescriptor(\"ellipsoid\", EllipsoidGraphics),\n /**\n * Gets or sets the label.\n * @memberof Entity.prototype\n * @type {LabelGraphics|undefined}\n */\n label: createPropertyTypeDescriptor(\"label\", LabelGraphics),\n /**\n * Gets or sets the model.\n * @memberof Entity.prototype\n * @type {ModelGraphics|undefined}\n */\n model: createPropertyTypeDescriptor(\"model\", ModelGraphics),\n /**\n * Gets or sets the tileset.\n * @memberof Entity.prototype\n * @type {Cesium3DTilesetGraphics|undefined}\n */\n tileset: createPropertyTypeDescriptor(\"tileset\", Cesium3DTilesetGraphics),\n /**\n * Gets or sets the orientation.\n * @memberof Entity.prototype\n * @type {Property|undefined}\n */\n orientation: createPropertyDescriptor(\"orientation\"),\n /**\n * Gets or sets the path.\n * @memberof Entity.prototype\n * @type {PathGraphics|undefined}\n */\n path: createPropertyTypeDescriptor(\"path\", PathGraphics),\n /**\n * Gets or sets the plane.\n * @memberof Entity.prototype\n * @type {PlaneGraphics|undefined}\n */\n plane: createPropertyTypeDescriptor(\"plane\", PlaneGraphics),\n /**\n * Gets or sets the point graphic.\n * @memberof Entity.prototype\n * @type {PointGraphics|undefined}\n */\n point: createPropertyTypeDescriptor(\"point\", PointGraphics),\n /**\n * Gets or sets the polygon.\n * @memberof Entity.prototype\n * @type {PolygonGraphics|undefined}\n */\n polygon: createPropertyTypeDescriptor(\"polygon\", PolygonGraphics),\n /**\n * Gets or sets the polyline.\n * @memberof Entity.prototype\n * @type {PolylineGraphics|undefined}\n */\n polyline: createPropertyTypeDescriptor(\"polyline\", PolylineGraphics),\n /**\n * Gets or sets the polyline volume.\n * @memberof Entity.prototype\n * @type {PolylineVolumeGraphics|undefined}\n */\n polylineVolume: createPropertyTypeDescriptor(\n \"polylineVolume\",\n PolylineVolumeGraphics\n ),\n /**\n * Gets or sets the bag of arbitrary properties associated with this entity.\n * @memberof Entity.prototype\n * @type {PropertyBag|undefined}\n */\n properties: createPropertyTypeDescriptor(\"properties\", PropertyBag),\n /**\n * Gets or sets the position.\n * @memberof Entity.prototype\n * @type {PositionProperty|undefined}\n */\n position: createPositionPropertyDescriptor(\"position\"),\n /**\n * Gets or sets the rectangle.\n * @memberof Entity.prototype\n * @type {RectangleGraphics|undefined}\n */\n rectangle: createPropertyTypeDescriptor(\"rectangle\", RectangleGraphics),\n /**\n * Gets or sets the suggested initial offset when tracking this object.\n * The offset is typically defined in the east-north-up reference frame,\n * but may be another frame depending on the object's velocity.\n * @memberof Entity.prototype\n * @type {Property|undefined}\n */\n viewFrom: createPropertyDescriptor(\"viewFrom\"),\n /**\n * Gets or sets the wall.\n * @memberof Entity.prototype\n * @type {WallGraphics|undefined}\n */\n wall: createPropertyTypeDescriptor(\"wall\", WallGraphics),\n});\n\n/**\n * Given a time, returns true if this object should have data during that time.\n *\n * @param {JulianDate} time The time to check availability for.\n * @returns {boolean} true if the object should have data during the provided time, false otherwise.\n */\nEntity.prototype.isAvailable = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const availability = this._availability;\n return !defined(availability) || availability.contains(time);\n};\n\n/**\n * Adds a property to this object. Once a property is added, it can be\n * observed with {@link Entity#definitionChanged} and composited\n * with {@link CompositeEntityCollection}\n *\n * @param {string} propertyName The name of the property to add.\n *\n * @exception {DeveloperError} \"propertyName\" is a reserved property name.\n * @exception {DeveloperError} \"propertyName\" is already a registered property.\n */\nEntity.prototype.addProperty = function (propertyName) {\n const propertyNames = this._propertyNames;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(propertyName)) {\n throw new DeveloperError(\"propertyName is required.\");\n }\n if (propertyNames.indexOf(propertyName) !== -1) {\n throw new DeveloperError(\n `${propertyName} is already a registered property.`\n );\n }\n if (propertyName in this) {\n throw new DeveloperError(`${propertyName} is a reserved property name.`);\n }\n //>>includeEnd('debug');\n\n propertyNames.push(propertyName);\n Object.defineProperty(\n this,\n propertyName,\n createRawPropertyDescriptor(propertyName, true)\n );\n};\n\n/**\n * Removed a property previously added with addProperty.\n *\n * @param {string} propertyName The name of the property to remove.\n *\n * @exception {DeveloperError} \"propertyName\" is a reserved property name.\n * @exception {DeveloperError} \"propertyName\" is not a registered property.\n */\nEntity.prototype.removeProperty = function (propertyName) {\n const propertyNames = this._propertyNames;\n const index = propertyNames.indexOf(propertyName);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(propertyName)) {\n throw new DeveloperError(\"propertyName is required.\");\n }\n if (index === -1) {\n throw new DeveloperError(`${propertyName} is not a registered property.`);\n }\n //>>includeEnd('debug');\n\n this._propertyNames.splice(index, 1);\n delete this[propertyName];\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {Entity} source The object to be merged into this object.\n */\nEntity.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n //Name, show, and availability are not Property objects and are currently handled differently.\n //source.show is intentionally ignored because this.show always has a value.\n this.name = defaultValue(this.name, source.name);\n this.availability = defaultValue(this.availability, source.availability);\n\n const propertyNames = this._propertyNames;\n const sourcePropertyNames = defined(source._propertyNames)\n ? source._propertyNames\n : Object.keys(source);\n const propertyNamesLength = sourcePropertyNames.length;\n for (let i = 0; i < propertyNamesLength; i++) {\n const name = sourcePropertyNames[i];\n\n //While source is required by the API to be an Entity, we internally call this method from the\n //constructor with an options object to configure initial custom properties.\n //So we need to ignore reserved-non-property.\n if (\n name === \"parent\" ||\n name === \"name\" ||\n name === \"availability\" ||\n name === \"children\"\n ) {\n continue;\n }\n\n const targetProperty = this[name];\n const sourceProperty = source[name];\n\n //Custom properties that are registered on the source entity must also\n //get registered on this entity.\n if (!defined(targetProperty) && propertyNames.indexOf(name) === -1) {\n this.addProperty(name);\n }\n\n if (defined(sourceProperty)) {\n if (defined(targetProperty)) {\n if (defined(targetProperty.merge)) {\n targetProperty.merge(sourceProperty);\n }\n } else if (\n defined(sourceProperty.merge) &&\n defined(sourceProperty.clone)\n ) {\n this[name] = sourceProperty.clone();\n } else {\n this[name] = sourceProperty;\n }\n }\n }\n};\n\nconst matrix3Scratch = new Matrix3();\nconst positionScratch = new Cartesian3();\nconst orientationScratch = new Quaternion();\n\n/**\n * Computes the model matrix for the entity's transform at specified time. Returns undefined if position is undefined\n *\n * @param {JulianDate} time The time to retrieve model matrix for.\n * @param {Matrix4} [result] The object onto which to store the result.\n *\n * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. Result is undefined if position is undefined.\n */\nEntity.prototype.computeModelMatrix = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"time\", time);\n //>>includeEnd('debug');\n const position = Property.getValueOrUndefined(\n this._position,\n time,\n positionScratch\n );\n if (!defined(position)) {\n return undefined;\n }\n\n const orientation = Property.getValueOrUndefined(\n this._orientation,\n time,\n orientationScratch\n );\n if (!defined(orientation)) {\n result = Transforms.eastNorthUpToFixedFrame(position, undefined, result);\n } else {\n result = Matrix4.fromRotationTranslation(\n Matrix3.fromQuaternion(orientation, matrix3Scratch),\n position,\n result\n );\n }\n return result;\n};\n\n/**\n * @private\n */\nEntity.prototype.computeModelMatrixForHeightReference = function (\n time,\n heightReferenceProperty,\n heightOffset,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"time\", time);\n //>>includeEnd('debug');\n const heightReference = Property.getValueOrDefault(\n heightReferenceProperty,\n time,\n HeightReference.NONE\n );\n let position = Property.getValueOrUndefined(\n this._position,\n time,\n positionScratch\n );\n if (\n heightReference === HeightReference.NONE ||\n !defined(position) ||\n Cartesian3.equalsEpsilon(position, Cartesian3.ZERO, CesiumMath.EPSILON8)\n ) {\n return this.computeModelMatrix(time, result);\n }\n\n const carto = ellipsoid.cartesianToCartographic(position, cartoScratch);\n if (heightReference === HeightReference.CLAMP_TO_GROUND) {\n carto.height = heightOffset;\n } else {\n carto.height += heightOffset;\n }\n position = ellipsoid.cartographicToCartesian(carto, position);\n\n const orientation = Property.getValueOrUndefined(\n this._orientation,\n time,\n orientationScratch\n );\n if (!defined(orientation)) {\n result = Transforms.eastNorthUpToFixedFrame(position, undefined, result);\n } else {\n result = Matrix4.fromRotationTranslation(\n Matrix3.fromQuaternion(orientation, matrix3Scratch),\n position,\n result\n );\n }\n return result;\n};\n\n/**\n * Checks if the given Scene supports materials besides Color on Entities draped on terrain or 3D Tiles.\n * If this feature is not supported, Entities with non-color materials but no `height` will\n * instead be rendered as if height is 0.\n *\n * @param {Scene} scene The current scene.\n * @returns {boolean} Whether or not the current scene supports materials for entities on terrain.\n */\nEntity.supportsMaterialsforEntitiesOnTerrain = function (scene) {\n return GroundPrimitive.supportsMaterials(scene);\n};\n\n/**\n * Checks if the given Scene supports polylines clamped to terrain or 3D Tiles.\n * If this feature is not supported, Entities with PolylineGraphics will be rendered with vertices at\n * the provided heights and using the `arcType` parameter instead of clamped to the ground.\n *\n * @param {Scene} scene The current scene.\n * @returns {boolean} Whether or not the current scene supports polylines on terrain or 3D TIles.\n */\nEntity.supportsPolylinesOnTerrain = function (scene) {\n return GroundPolylinePrimitive.isSupported(scene);\n};\nexport default Entity;\n", "import Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Event from \"../Core/Event.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport ClassificationType from \"../Scene/ClassificationType.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport Entity from \"./Entity.js\";\nimport Property from \"./Property.js\";\n\nconst defaultMaterial = new ColorMaterialProperty(Color.WHITE);\nconst defaultShow = new ConstantProperty(true);\nconst defaultFill = new ConstantProperty(true);\nconst defaultOutline = new ConstantProperty(false);\nconst defaultOutlineColor = new ConstantProperty(Color.BLACK);\nconst defaultShadows = new ConstantProperty(ShadowMode.DISABLED);\nconst defaultDistanceDisplayCondition = new ConstantProperty(\n new DistanceDisplayCondition()\n);\nconst defaultClassificationType = new ConstantProperty(ClassificationType.BOTH);\n\n/**\n * An abstract class for updating geometry entities.\n * @alias GeometryUpdater\n * @constructor\n *\n * @param {object} options An object with the following properties:\n * @param {Entity} options.entity The entity containing the geometry to be visualized.\n * @param {Scene} options.scene The scene where visualization is taking place.\n * @param {object} options.geometryOptions Options for the geometry\n * @param {string} options.geometryPropertyName The geometry property name\n * @param {string[]} options.observedPropertyNames The entity properties this geometry cares about\n */\nfunction GeometryUpdater(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.entity\", options.entity);\n Check.defined(\"options.scene\", options.scene);\n Check.defined(\"options.geometryOptions\", options.geometryOptions);\n Check.defined(\"options.geometryPropertyName\", options.geometryPropertyName);\n Check.defined(\"options.observedPropertyNames\", options.observedPropertyNames);\n //>>includeEnd('debug');\n\n const entity = options.entity;\n const geometryPropertyName = options.geometryPropertyName;\n\n this._entity = entity;\n this._scene = options.scene;\n this._fillEnabled = false;\n this._isClosed = false;\n this._onTerrain = false;\n this._dynamic = false;\n this._outlineEnabled = false;\n this._geometryChanged = new Event();\n this._showProperty = undefined;\n this._materialProperty = undefined;\n this._showOutlineProperty = undefined;\n this._outlineColorProperty = undefined;\n this._outlineWidth = 1.0;\n this._shadowsProperty = undefined;\n this._distanceDisplayConditionProperty = undefined;\n this._classificationTypeProperty = undefined;\n this._options = options.geometryOptions;\n this._geometryPropertyName = geometryPropertyName;\n this._id = `${geometryPropertyName}-${entity.id}`;\n this._observedPropertyNames = options.observedPropertyNames;\n this._supportsMaterialsforEntitiesOnTerrain = Entity.supportsMaterialsforEntitiesOnTerrain(\n options.scene\n );\n}\n\nObject.defineProperties(GeometryUpdater.prototype, {\n /**\n * Gets the unique ID associated with this updater\n * @memberof GeometryUpdater.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * Gets the entity associated with this geometry.\n * @memberof GeometryUpdater.prototype\n *\n * @type {Entity}\n * @readonly\n */\n entity: {\n get: function () {\n return this._entity;\n },\n },\n /**\n * Gets a value indicating if the geometry has a fill component.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n fillEnabled: {\n get: function () {\n return this._fillEnabled;\n },\n },\n /**\n * Gets a value indicating if fill visibility varies with simulation time.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n hasConstantFill: {\n get: function () {\n return (\n !this._fillEnabled ||\n (!defined(this._entity.availability) &&\n Property.isConstant(this._showProperty) &&\n Property.isConstant(this._fillProperty))\n );\n },\n },\n /**\n * Gets the material property used to fill the geometry.\n * @memberof GeometryUpdater.prototype\n *\n * @type {MaterialProperty}\n * @readonly\n */\n fillMaterialProperty: {\n get: function () {\n return this._materialProperty;\n },\n },\n /**\n * Gets a value indicating if the geometry has an outline component.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n outlineEnabled: {\n get: function () {\n return this._outlineEnabled;\n },\n },\n /**\n * Gets a value indicating if the geometry has an outline component.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n hasConstantOutline: {\n get: function () {\n return (\n !this._outlineEnabled ||\n (!defined(this._entity.availability) &&\n Property.isConstant(this._showProperty) &&\n Property.isConstant(this._showOutlineProperty))\n );\n },\n },\n /**\n * Gets the {@link Color} property for the geometry outline.\n * @memberof GeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n outlineColorProperty: {\n get: function () {\n return this._outlineColorProperty;\n },\n },\n /**\n * Gets the constant with of the geometry outline, in pixels.\n * This value is only valid if isDynamic is false.\n * @memberof GeometryUpdater.prototype\n *\n * @type {number}\n * @readonly\n */\n outlineWidth: {\n get: function () {\n return this._outlineWidth;\n },\n },\n /**\n * Gets the property specifying whether the geometry\n * casts or receives shadows from light sources.\n * @memberof GeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n shadowsProperty: {\n get: function () {\n return this._shadowsProperty;\n },\n },\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this geometry will be displayed.\n * @memberof GeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n distanceDisplayConditionProperty: {\n get: function () {\n return this._distanceDisplayConditionProperty;\n },\n },\n /**\n * Gets or sets the {@link ClassificationType} Property specifying if this geometry will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof GeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n classificationTypeProperty: {\n get: function () {\n return this._classificationTypeProperty;\n },\n },\n /**\n * Gets a value indicating if the geometry is time-varying.\n * If true, all visualization is delegated to a DynamicGeometryUpdater\n * returned by GeometryUpdater#createDynamicUpdater.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isDynamic: {\n get: function () {\n return this._dynamic;\n },\n },\n /**\n * Gets a value indicating if the geometry is closed.\n * This property is only valid for static geometry.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isClosed: {\n get: function () {\n return this._isClosed;\n },\n },\n /**\n * Gets a value indicating if the geometry should be drawn on terrain.\n * @memberof EllipseGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n onTerrain: {\n get: function () {\n return this._onTerrain;\n },\n },\n /**\n * Gets an event that is raised whenever the public properties\n * of this updater change.\n * @memberof GeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n geometryChanged: {\n get: function () {\n return this._geometryChanged;\n },\n },\n});\n\n/**\n * Checks if the geometry is outlined at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve visibility.\n * @returns {boolean} true if geometry is outlined at the provided time, false otherwise.\n */\nGeometryUpdater.prototype.isOutlineVisible = function (time) {\n const entity = this._entity;\n const visible =\n this._outlineEnabled &&\n entity.isAvailable(time) &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time);\n return defaultValue(visible, false);\n};\n\n/**\n * Checks if the geometry is filled at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve visibility.\n * @returns {boolean} true if geometry is filled at the provided time, false otherwise.\n */\nGeometryUpdater.prototype.isFilled = function (time) {\n const entity = this._entity;\n const visible =\n this._fillEnabled &&\n entity.isAvailable(time) &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time);\n return defaultValue(visible, false);\n};\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @function\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nGeometryUpdater.prototype.createFillGeometryInstance =\n DeveloperError.throwInstantiationError;\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @function\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nGeometryUpdater.prototype.createOutlineGeometryInstance =\n DeveloperError.throwInstantiationError;\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nGeometryUpdater.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys and resources used by the object. Once an object is destroyed, it should not be used.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nGeometryUpdater.prototype.destroy = function () {\n destroyObject(this);\n};\n/**\n * @param {Entity} entity\n * @param {object} geometry\n * @private\n */\nGeometryUpdater.prototype._isHidden = function (entity, geometry) {\n const show = geometry.show;\n return (\n defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)\n );\n};\n\n/**\n * @param {Entity} entity\n * @param {object} geometry\n * @private\n */\nGeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {\n return false;\n};\n\n/**\n * @param {GeometryOptions} options\n * @private\n */\nGeometryUpdater.prototype._getIsClosed = function (options) {\n return true;\n};\n\n/**\n * @param {Entity} entity\n * @param {object} geometry\n * @private\n */\nGeometryUpdater.prototype._isDynamic = DeveloperError.throwInstantiationError;\n\n/**\n * @param {Entity} entity\n * @param {object} geometry\n * @private\n */\nGeometryUpdater.prototype._setStaticOptions =\n DeveloperError.throwInstantiationError;\n\n/**\n * @param {Entity} entity\n * @param {string} propertyName\n * @param {*} newValue\n * @param {*} oldValue\n * @private\n */\nGeometryUpdater.prototype._onEntityPropertyChanged = function (\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n if (this._observedPropertyNames.indexOf(propertyName) === -1) {\n return;\n }\n\n const geometry = this._entity[this._geometryPropertyName];\n\n if (!defined(geometry)) {\n if (this._fillEnabled || this._outlineEnabled) {\n this._fillEnabled = false;\n this._outlineEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n const fillProperty = geometry.fill;\n const fillEnabled =\n defined(fillProperty) && fillProperty.isConstant\n ? fillProperty.getValue(Iso8601.MINIMUM_VALUE)\n : true;\n\n const outlineProperty = geometry.outline;\n let outlineEnabled = defined(outlineProperty);\n if (outlineEnabled && outlineProperty.isConstant) {\n outlineEnabled = outlineProperty.getValue(Iso8601.MINIMUM_VALUE);\n }\n\n if (!fillEnabled && !outlineEnabled) {\n if (this._fillEnabled || this._outlineEnabled) {\n this._fillEnabled = false;\n this._outlineEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n const show = geometry.show;\n if (this._isHidden(entity, geometry)) {\n if (this._fillEnabled || this._outlineEnabled) {\n this._fillEnabled = false;\n this._outlineEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n this._materialProperty = defaultValue(geometry.material, defaultMaterial);\n this._fillProperty = defaultValue(fillProperty, defaultFill);\n this._showProperty = defaultValue(show, defaultShow);\n this._showOutlineProperty = defaultValue(geometry.outline, defaultOutline);\n this._outlineColorProperty = outlineEnabled\n ? defaultValue(geometry.outlineColor, defaultOutlineColor)\n : undefined;\n this._shadowsProperty = defaultValue(geometry.shadows, defaultShadows);\n this._distanceDisplayConditionProperty = defaultValue(\n geometry.distanceDisplayCondition,\n defaultDistanceDisplayCondition\n );\n this._classificationTypeProperty = defaultValue(\n geometry.classificationType,\n defaultClassificationType\n );\n\n this._fillEnabled = fillEnabled;\n\n const onTerrain =\n this._isOnTerrain(entity, geometry) &&\n (this._supportsMaterialsforEntitiesOnTerrain ||\n this._materialProperty instanceof ColorMaterialProperty);\n\n if (outlineEnabled && onTerrain) {\n oneTimeWarning(oneTimeWarning.geometryOutlines);\n outlineEnabled = false;\n }\n\n this._onTerrain = onTerrain;\n this._outlineEnabled = outlineEnabled;\n\n if (this._isDynamic(entity, geometry)) {\n if (!this._dynamic) {\n this._dynamic = true;\n this._geometryChanged.raiseEvent(this);\n }\n } else {\n this._setStaticOptions(entity, geometry);\n this._isClosed = this._getIsClosed(this._options);\n const outlineWidth = geometry.outlineWidth;\n this._outlineWidth = defined(outlineWidth)\n ? outlineWidth.getValue(Iso8601.MINIMUM_VALUE)\n : 1.0;\n this._dynamic = false;\n this._geometryChanged.raiseEvent(this);\n }\n};\n\n/**\n * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true.\n *\n * @param {PrimitiveCollection} primitives The primitive collection to use.\n * @param {PrimitiveCollection} [groundPrimitives] The primitive collection to use for ground primitives.\n *\n * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame.\n *\n * @exception {DeveloperError} This instance does not represent dynamic geometry.\n * @private\n */\nGeometryUpdater.prototype.createDynamicUpdater = function (\n primitives,\n groundPrimitives\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"primitives\", primitives);\n Check.defined(\"groundPrimitives\", groundPrimitives);\n\n if (!this._dynamic) {\n throw new DeveloperError(\n \"This instance does not represent dynamic geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n return new this.constructor.DynamicGeometryUpdater(\n this,\n primitives,\n groundPrimitives\n );\n};\nexport default GeometryUpdater;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\n\n/**\n * A {@link Property} whose value is lazily evaluated by a callback function.\n *\n * @alias CallbackProperty\n * @constructor\n *\n * @param {CallbackProperty.Callback} callback The function to be called when the property is evaluated.\n * @param {boolean} isConstant true when the callback function returns the same value every time, false if the value will change.\n */\nfunction CallbackProperty(callback, isConstant) {\n this._callback = undefined;\n this._isConstant = undefined;\n this._definitionChanged = new Event();\n this.setCallback(callback, isConstant);\n}\n\nObject.defineProperties(CallbackProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * @memberof CallbackProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._isConstant;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setCallback is called.\n * @memberof CallbackProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\n/**\n * Gets the value of the property.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied or is unsupported.\n */\nCallbackProperty.prototype.getValue = function (time, result) {\n return this._callback(time, result);\n};\n\n/**\n * Sets the callback to be used.\n *\n * @param {CallbackProperty.Callback} callback The function to be called when the property is evaluated.\n * @param {boolean} isConstant true when the callback function returns the same value every time, false if the value will change.\n */\nCallbackProperty.prototype.setCallback = function (callback, isConstant) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(callback)) {\n throw new DeveloperError(\"callback is required.\");\n }\n if (!defined(isConstant)) {\n throw new DeveloperError(\"isConstant is required.\");\n }\n //>>includeEnd('debug');\n\n const changed =\n this._callback !== callback || this._isConstant !== isConstant;\n\n this._callback = callback;\n this._isConstant = isConstant;\n\n if (changed) {\n this._definitionChanged.raiseEvent(this);\n }\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCallbackProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof CallbackProperty &&\n this._callback === other._callback &&\n this._isConstant === other._isConstant)\n );\n};\n\n/**\n * A function that returns the value of the property.\n * @callback CallbackProperty.Callback\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into. If omitted, the function must create and return a new instance.\n * @returns {object} The modified result parameter, or a new instance if the result parameter was not supplied or is unsupported.\n */\nexport default CallbackProperty;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Event from \"../Core/Event.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport Property from \"./Property.js\";\n\nconst scratchPosition = new Cartesian3();\nconst scratchCarto = new Cartographic();\n\n/**\n * @private\n */\nfunction TerrainOffsetProperty(\n scene,\n positionProperty,\n heightReferenceProperty,\n extrudedHeightReferenceProperty\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"scene\", scene);\n Check.defined(\"positionProperty\", positionProperty);\n //>>includeEnd('debug');\n\n this._scene = scene;\n this._heightReference = heightReferenceProperty;\n this._extrudedHeightReference = extrudedHeightReferenceProperty;\n this._positionProperty = positionProperty;\n\n this._position = new Cartesian3();\n this._cartographicPosition = new Cartographic();\n this._normal = new Cartesian3();\n\n this._definitionChanged = new Event();\n this._terrainHeight = 0;\n this._removeCallbackFunc = undefined;\n this._removeEventListener = undefined;\n this._removeModeListener = undefined;\n\n const that = this;\n if (defined(scene.globe)) {\n this._removeEventListener = scene.terrainProviderChanged.addEventListener(\n function () {\n that._updateClamping();\n }\n );\n this._removeModeListener = scene.morphComplete.addEventListener(\n function () {\n that._updateClamping();\n }\n );\n }\n\n if (positionProperty.isConstant) {\n const position = positionProperty.getValue(\n Iso8601.MINIMUM_VALUE,\n scratchPosition\n );\n if (\n !defined(position) ||\n Cartesian3.equals(position, Cartesian3.ZERO) ||\n !defined(scene.globe)\n ) {\n return;\n }\n this._position = Cartesian3.clone(position, this._position);\n\n this._updateClamping();\n\n this._normal = scene.globe.ellipsoid.geodeticSurfaceNormal(\n position,\n this._normal\n );\n }\n}\n\nObject.defineProperties(TerrainOffsetProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * @memberof TerrainOffsetProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return false;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * @memberof TerrainOffsetProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\n/**\n * @private\n */\nTerrainOffsetProperty.prototype._updateClamping = function () {\n if (defined(this._removeCallbackFunc)) {\n this._removeCallbackFunc();\n }\n\n const scene = this._scene;\n const globe = scene.globe;\n const position = this._position;\n\n if (!defined(globe) || Cartesian3.equals(position, Cartesian3.ZERO)) {\n this._terrainHeight = 0;\n return;\n }\n const ellipsoid = globe.ellipsoid;\n const surface = globe._surface;\n\n const that = this;\n const cartographicPosition = ellipsoid.cartesianToCartographic(\n position,\n this._cartographicPosition\n );\n const height = globe.getHeight(cartographicPosition);\n if (defined(height)) {\n this._terrainHeight = height;\n } else {\n this._terrainHeight = 0;\n }\n\n function updateFunction(clampedPosition) {\n if (scene.mode === SceneMode.SCENE3D) {\n const carto = ellipsoid.cartesianToCartographic(\n clampedPosition,\n scratchCarto\n );\n that._terrainHeight = carto.height;\n } else {\n that._terrainHeight = clampedPosition.x;\n }\n that.definitionChanged.raiseEvent();\n }\n this._removeCallbackFunc = surface.updateHeight(\n cartographicPosition,\n updateFunction\n );\n};\n\n/**\n * Gets the height relative to the terrain based on the positions.\n *\n * @returns {Cartesian3} The offset\n */\nTerrainOffsetProperty.prototype.getValue = function (time, result) {\n const heightReference = Property.getValueOrDefault(\n this._heightReference,\n time,\n HeightReference.NONE\n );\n const extrudedHeightReference = Property.getValueOrDefault(\n this._extrudedHeightReference,\n time,\n HeightReference.NONE\n );\n\n if (\n heightReference === HeightReference.NONE &&\n extrudedHeightReference !== HeightReference.RELATIVE_TO_GROUND\n ) {\n this._position = Cartesian3.clone(Cartesian3.ZERO, this._position);\n return Cartesian3.clone(Cartesian3.ZERO, result);\n }\n\n if (this._positionProperty.isConstant) {\n return Cartesian3.multiplyByScalar(\n this._normal,\n this._terrainHeight,\n result\n );\n }\n\n const scene = this._scene;\n const position = this._positionProperty.getValue(time, scratchPosition);\n if (\n !defined(position) ||\n Cartesian3.equals(position, Cartesian3.ZERO) ||\n !defined(scene.globe)\n ) {\n return Cartesian3.clone(Cartesian3.ZERO, result);\n }\n\n if (\n Cartesian3.equalsEpsilon(this._position, position, CesiumMath.EPSILON10)\n ) {\n return Cartesian3.multiplyByScalar(\n this._normal,\n this._terrainHeight,\n result\n );\n }\n\n this._position = Cartesian3.clone(position, this._position);\n\n this._updateClamping();\n\n const normal = scene.globe.ellipsoid.geodeticSurfaceNormal(\n position,\n this._normal\n );\n return Cartesian3.multiplyByScalar(normal, this._terrainHeight, result);\n};\n\nTerrainOffsetProperty.prototype.isDestroyed = function () {\n return false;\n};\n\nTerrainOffsetProperty.prototype.destroy = function () {\n if (defined(this._removeEventListener)) {\n this._removeEventListener();\n }\n if (defined(this._removeModeListener)) {\n this._removeModeListener();\n }\n if (defined(this._removeCallbackFunc)) {\n this._removeCallbackFunc();\n }\n return destroyObject(this);\n};\n\n/**\n * A function which creates one or more providers.\n * @callback TerrainOffsetProperty.PositionFunction\n * @param {JulianDate} time The clock time at which to retrieve the position\n * @param {Cartesian3} result The result position\n * @returns {Cartesian3} The position at which to do the terrain height check\n */\nexport default TerrainOffsetProperty;\n", "import defined from \"../Core/defined.js\";\nimport CallbackProperty from \"./CallbackProperty.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport TerrainOffsetProperty from \"./TerrainOffsetProperty.js\";\n\nfunction heightReferenceOnEntityPropertyChanged(\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n GeometryUpdater.prototype._onEntityPropertyChanged.call(\n this,\n entity,\n propertyName,\n newValue,\n oldValue\n );\n if (this._observedPropertyNames.indexOf(propertyName) === -1) {\n return;\n }\n\n const geometry = this._entity[this._geometryPropertyName];\n if (!defined(geometry)) {\n return;\n }\n\n if (defined(this._terrainOffsetProperty)) {\n this._terrainOffsetProperty.destroy();\n this._terrainOffsetProperty = undefined;\n }\n\n const heightReferenceProperty = geometry.heightReference;\n\n if (defined(heightReferenceProperty)) {\n const centerPosition = new CallbackProperty(\n this._computeCenter.bind(this),\n !this._dynamic\n );\n this._terrainOffsetProperty = new TerrainOffsetProperty(\n this._scene,\n centerPosition,\n heightReferenceProperty\n );\n }\n}\nexport default heightReferenceOnEntityPropertyChanged;\n", "import BoxGeometry from \"../Core/BoxGeometry.js\";\nimport BoxOutlineGeometry from \"../Core/BoxOutlineGeometry.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"../Core/GeometryOffsetAttribute.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport heightReferenceOnEntityPropertyChanged from \"./heightReferenceOnEntityPropertyChanged.js\";\nimport Property from \"./Property.js\";\n\nconst defaultOffset = Cartesian3.ZERO;\n\nconst offsetScratch = new Cartesian3();\nconst positionScratch = new Cartesian3();\nconst scratchColor = new Color();\n\nfunction BoxGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.dimensions = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for boxes.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias BoxGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction BoxGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new BoxGeometryOptions(entity),\n geometryPropertyName: \"box\",\n observedPropertyNames: [\"availability\", \"position\", \"orientation\", \"box\"],\n });\n\n this._onEntityPropertyChanged(entity, \"box\", entity.box, undefined);\n}\n\nif (defined(Object.create)) {\n BoxGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n BoxGeometryUpdater.prototype.constructor = BoxGeometryUpdater;\n}\n\nObject.defineProperties(BoxGeometryUpdater.prototype, {\n /**\n * Gets the terrain offset property\n * @type {TerrainOffsetProperty}\n * @memberof BoxGeometryUpdater.prototype\n * @readonly\n * @private\n */\n terrainOffsetProperty: {\n get: function () {\n return this._terrainOffsetProperty;\n },\n },\n});\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nBoxGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n\n const attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: undefined,\n offset: undefined,\n };\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: BoxGeometry.fromDimensions(this._options),\n modelMatrix: entity.computeModelMatrixForHeightReference(\n time,\n entity.box.heightReference,\n this._options.dimensions.z * 0.5,\n this._scene.mapProjection.ellipsoid\n ),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nBoxGeometryUpdater.prototype.createOutlineGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: BoxOutlineGeometry.fromDimensions(this._options),\n modelMatrix: entity.computeModelMatrixForHeightReference(\n time,\n entity.box.heightReference,\n this._options.dimensions.z * 0.5,\n this._scene.mapProjection.ellipsoid\n ),\n attributes: attributes,\n });\n};\n\nBoxGeometryUpdater.prototype._computeCenter = function (time, result) {\n return Property.getValueOrUndefined(this._entity.position, time, result);\n};\n\nBoxGeometryUpdater.prototype._isHidden = function (entity, box) {\n return (\n !defined(box.dimensions) ||\n !defined(entity.position) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, box)\n );\n};\n\nBoxGeometryUpdater.prototype._isDynamic = function (entity, box) {\n return (\n !entity.position.isConstant ||\n !Property.isConstant(entity.orientation) ||\n !box.dimensions.isConstant ||\n !Property.isConstant(box.outlineWidth)\n );\n};\n\nBoxGeometryUpdater.prototype._setStaticOptions = function (entity, box) {\n const heightReference = Property.getValueOrDefault(\n box.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n\n const options = this._options;\n options.vertexFormat =\n this._materialProperty instanceof ColorMaterialProperty\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.dimensions = box.dimensions.getValue(\n Iso8601.MINIMUM_VALUE,\n options.dimensions\n );\n options.offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n};\n\nBoxGeometryUpdater.prototype._onEntityPropertyChanged = heightReferenceOnEntityPropertyChanged;\n\nBoxGeometryUpdater.DynamicGeometryUpdater = DynamicBoxGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicBoxGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicBoxGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicBoxGeometryUpdater.prototype.constructor = DynamicBoxGeometryUpdater;\n}\n\nDynamicBoxGeometryUpdater.prototype._isHidden = function (entity, box, time) {\n const position = Property.getValueOrUndefined(\n entity.position,\n time,\n positionScratch\n );\n const dimensions = this._options.dimensions;\n return (\n !defined(position) ||\n !defined(dimensions) ||\n DynamicGeometryUpdater.prototype._isHidden.call(this, entity, box, time)\n );\n};\n\nDynamicBoxGeometryUpdater.prototype._setOptions = function (entity, box, time) {\n const heightReference = Property.getValueOrDefault(\n box.heightReference,\n time,\n HeightReference.NONE\n );\n const options = this._options;\n options.dimensions = Property.getValueOrUndefined(\n box.dimensions,\n time,\n options.dimensions\n );\n options.offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n};\nexport default BoxGeometryUpdater;\n", "import DOMPurify from \"dompurify\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\nlet nextCreditId = 0;\nconst creditToId = {};\n\n/**\n * A credit contains data pertaining to how to display attributions/credits for certain content on the screen.\n * @param {string} html An string representing an html code snippet\n * @param {boolean} [showOnScreen=false] If true, the credit will be visible in the main credit container. Otherwise, it will appear in a popover\n *\n * @alias Credit\n * @constructor\n *\n * @exception {DeveloperError} html is required.\n *\n * @example\n * // Create a credit with a tooltip, image and link\n * const credit = new Cesium.Credit('');\n */\nfunction Credit(html, showOnScreen) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"html\", html);\n //>>includeEnd('debug');\n let id;\n const key = html;\n\n if (defined(creditToId[key])) {\n id = creditToId[key];\n } else {\n id = nextCreditId++;\n creditToId[key] = id;\n }\n\n showOnScreen = defaultValue(showOnScreen, false);\n\n // Credits are immutable so generate an id to use to optimize equal()\n this._id = id;\n this._html = html;\n this._showOnScreen = showOnScreen;\n this._element = undefined;\n}\n\nObject.defineProperties(Credit.prototype, {\n /**\n * The credit content\n * @memberof Credit.prototype\n * @type {string}\n * @readonly\n */\n html: {\n get: function () {\n return this._html;\n },\n },\n\n /**\n * @memberof Credit.prototype\n * @type {number}\n * @readonly\n *\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * Whether the credit should be displayed on screen or in a lightbox\n * @memberof Credit.prototype\n * @type {boolean}\n */\n showOnScreen: {\n get: function () {\n return this._showOnScreen;\n },\n set: function (value) {\n this._showOnScreen = value;\n },\n },\n\n /**\n * Gets the credit element\n * @memberof Credit.prototype\n * @type {HTMLElement}\n * @readonly\n */\n element: {\n get: function () {\n if (!defined(this._element)) {\n const html = DOMPurify.sanitize(this._html);\n\n const div = document.createElement(\"div\");\n div._creditId = this._id;\n div.style.display = \"inline\";\n div.innerHTML = html;\n\n const links = div.querySelectorAll(\"a\");\n for (let i = 0; i < links.length; i++) {\n links[i].setAttribute(\"target\", \"_blank\");\n }\n\n this._element = div;\n }\n return this._element;\n },\n },\n});\n\n/**\n * Returns true if the credits are equal\n *\n * @param {Credit} left The first credit\n * @param {Credit} right The second credit\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCredit.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left._id === right._id &&\n left._showOnScreen === right._showOnScreen)\n );\n};\n\n/**\n * Returns true if the credits are equal\n *\n * @param {Credit} credit The credit to compare to.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCredit.prototype.equals = function (credit) {\n return Credit.equals(this, credit);\n};\n\n/**\n * @private\n * @param attribution\n * @return {Credit}\n */\nCredit.getIonCredit = function (attribution) {\n const showOnScreen =\n defined(attribution.collapsible) && !attribution.collapsible;\n const credit = new Credit(attribution.html, showOnScreen);\n\n credit._isIon = credit.html.indexOf(\"ion-credit.png\") !== -1;\n return credit;\n};\n\n/**\n * Duplicates a Credit instance.\n *\n * @param {Credit} [credit] The Credit to duplicate.\n * @returns {Credit} A new Credit instance that is a duplicate of the one provided. (Returns undefined if the credit is undefined)\n */\nCredit.clone = function (credit) {\n if (defined(credit)) {\n return new Credit(credit.html, credit.showOnScreen);\n }\n};\nexport default Credit;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec2 v_textureCoordinates;\\n\\\n\\n\\\nuniform float originalSize;\\n\\\nuniform sampler2D texture0;\\n\\\nuniform sampler2D texture1;\\n\\\nuniform sampler2D texture2;\\n\\\nuniform sampler2D texture3;\\n\\\nuniform sampler2D texture4;\\n\\\nuniform sampler2D texture5;\\n\\\n\\n\\\nconst float yMipLevel1 = 1.0 - (1.0 / pow(2.0, 1.0));\\n\\\nconst float yMipLevel2 = 1.0 - (1.0 / pow(2.0, 2.0));\\n\\\nconst float yMipLevel3 = 1.0 - (1.0 / pow(2.0, 3.0));\\n\\\nconst float yMipLevel4 = 1.0 - (1.0 / pow(2.0, 4.0));\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec2 uv = v_textureCoordinates;\\n\\\n vec2 textureSize = vec2(originalSize * 1.5 + 2.0, originalSize);\\n\\\n vec2 pixel = 1.0 / textureSize;\\n\\\n\\n\\\n float mipLevel = 0.0;\\n\\\n\\n\\\n if (uv.x - pixel.x > (textureSize.y / textureSize.x))\\n\\\n {\\n\\\n mipLevel = 1.0;\\n\\\n if (uv.y - pixel.y > yMipLevel1)\\n\\\n {\\n\\\n mipLevel = 2.0;\\n\\\n if (uv.y - pixel.y * 3.0 > yMipLevel2)\\n\\\n {\\n\\\n mipLevel = 3.0;\\n\\\n if (uv.y - pixel.y * 5.0 > yMipLevel3)\\n\\\n {\\n\\\n mipLevel = 4.0;\\n\\\n if (uv.y - pixel.y * 7.0 > yMipLevel4)\\n\\\n {\\n\\\n mipLevel = 5.0;\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n\\n\\\n if (mipLevel > 0.0)\\n\\\n {\\n\\\n float scale = pow(2.0, mipLevel);\\n\\\n\\n\\\n uv.y -= (pixel.y * (mipLevel - 1.0) * 2.0);\\n\\\n uv.x *= ((textureSize.x - 2.0) / textureSize.y);\\n\\\n\\n\\\n uv.x -= 1.0 + pixel.x;\\n\\\n uv.y -= (1.0 - (1.0 / pow(2.0, mipLevel - 1.0)));\\n\\\n uv *= scale;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n uv.x *= (textureSize.x / textureSize.y);\\n\\\n }\\n\\\n\\n\\\n if(mipLevel == 0.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture0, uv);\\n\\\n }\\n\\\n else if(mipLevel == 1.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture1, uv);\\n\\\n }\\n\\\n else if(mipLevel == 2.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture2, uv);\\n\\\n }\\n\\\n else if(mipLevel == 3.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture3, uv);\\n\\\n }\\n\\\n else if(mipLevel == 4.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture4, uv);\\n\\\n }\\n\\\n else if(mipLevel == 5.0)\\n\\\n {\\n\\\n out_FragColor = texture(texture5, uv);\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n out_FragColor = vec4(0.0);\\n\\\n }\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 v_cubeMapCoordinates;\\n\\\nuniform samplerCube cubeMap;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 rgba = czm_textureCube(cubeMap, v_cubeMapCoordinates);\\n\\\n #ifdef RGBA_NORMALIZED\\n\\\n out_FragColor = vec4(rgba.rgb, 1.0);\\n\\\n #else\\n\\\n float m = rgba.a * 16.0;\\n\\\n vec3 r = rgba.rgb * m;\\n\\\n out_FragColor = vec4(r * r, 1.0);\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 position;\\n\\\nin vec3 cubeMapCoordinates;\\n\\\n\\n\\\nout vec3 v_cubeMapCoordinates;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n gl_Position = position;\\n\\\n v_cubeMapCoordinates = cubeMapCoordinates;\\n\\\n}\\n\\\n\";\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Event from \"../Core/Event.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport loadKTX2 from \"../Core/loadKTX2.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport ComputeCommand from \"../Renderer/ComputeCommand.js\";\nimport CubeMap from \"../Renderer/CubeMap.js\";\nimport PixelDatatype from \"../Renderer/PixelDatatype.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport Texture from \"../Renderer/Texture.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport OctahedralProjectionAtlasFS from \"../Shaders/OctahedralProjectionAtlasFS.js\";\nimport OctahedralProjectionFS from \"../Shaders/OctahedralProjectionFS.js\";\nimport OctahedralProjectionVS from \"../Shaders/OctahedralProjectionVS.js\";\n\n/**\n * Packs all mip levels of a cube map into a 2D texture atlas.\n *\n * Octahedral projection is a way of putting the cube maps onto a 2D texture\n * with minimal distortion and easy look up.\n * See Chapter 16 of WebGL Insights \"HDR Image-Based Lighting on the Web\" by Jeff Russell\n * and \"Octahedron Environment Maps\" for reference.\n *\n * @private\n */\nfunction OctahedralProjectedCubeMap(url) {\n this._url = url;\n\n this._cubeMapBuffers = undefined;\n this._cubeMaps = undefined;\n this._texture = undefined;\n this._mipTextures = undefined;\n this._va = undefined;\n this._sp = undefined;\n\n this._maximumMipmapLevel = undefined;\n\n this._loading = false;\n this._ready = false;\n\n this._errorEvent = new Event();\n}\n\nObject.defineProperties(OctahedralProjectedCubeMap.prototype, {\n /**\n * The url to the KTX2 file containing the specular environment map and convoluted mipmaps.\n * @memberof OctahedralProjectedCubeMap.prototype\n * @type {string}\n * @readonly\n */\n url: {\n get: function () {\n return this._url;\n },\n },\n /**\n * Gets an event that is raised when encountering an asynchronous error. By subscribing\n * to the event, you will be notified of the error and can potentially recover from it.\n * @memberof OctahedralProjectedCubeMap.prototype\n * @type {Event}\n * @readonly\n */\n errorEvent: {\n get: function () {\n return this._errorEvent;\n },\n },\n /**\n * A texture containing all the packed convolutions.\n * @memberof OctahedralProjectedCubeMap.prototype\n * @type {Texture}\n * @readonly\n */\n texture: {\n get: function () {\n return this._texture;\n },\n },\n /**\n * The maximum number of mip levels.\n * @memberOf OctahedralProjectedCubeMap.prototype\n * @type {number}\n * @readonly\n */\n maximumMipmapLevel: {\n get: function () {\n return this._maximumMipmapLevel;\n },\n },\n /**\n * Determines if the texture atlas is complete and ready to use.\n * @memberof OctahedralProjectedCubeMap.prototype\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nOctahedralProjectedCubeMap.isSupported = function (context) {\n return (\n (context.colorBufferHalfFloat && context.halfFloatingPointTexture) ||\n (context.floatingPointTexture && context.colorBufferFloat)\n );\n};\n\n// These vertices are based on figure 1 from \"Octahedron Environment Maps\".\nconst v1 = new Cartesian3(1.0, 0.0, 0.0);\nconst v2 = new Cartesian3(0.0, 0.0, 1.0);\nconst v3 = new Cartesian3(-1.0, 0.0, 0.0);\nconst v4 = new Cartesian3(0.0, 0.0, -1.0);\nconst v5 = new Cartesian3(0.0, 1.0, 0.0);\nconst v6 = new Cartesian3(0.0, -1.0, 0.0);\n\n// top left, left, top, center, right, top right, bottom, bottom left, bottom right\nconst cubeMapCoordinates = [v5, v3, v2, v6, v1, v5, v4, v5, v5];\nconst length = cubeMapCoordinates.length;\nconst flatCubeMapCoordinates = new Float32Array(length * 3);\n\nlet offset = 0;\nfor (let i = 0; i < length; ++i, offset += 3) {\n Cartesian3.pack(cubeMapCoordinates[i], flatCubeMapCoordinates, offset);\n}\n\nconst flatPositions = new Float32Array([\n -1.0,\n 1.0, // top left\n -1.0,\n 0.0, // left\n 0.0,\n 1.0, // top\n 0.0,\n 0.0, // center\n 1.0,\n 0.0, // right\n 1.0,\n 1.0, // top right\n 0.0,\n -1.0, // bottom\n -1.0,\n -1.0, // bottom left\n 1.0,\n -1.0, // bottom right\n]);\nconst indices = new Uint16Array([\n 0,\n 1,\n 2, // top left, left, top,\n 2,\n 3,\n 1, // top, center, left,\n 7,\n 6,\n 1, // bottom left, bottom, left,\n 3,\n 6,\n 1, // center, bottom, left,\n 2,\n 5,\n 4, // top, top right, right,\n 3,\n 4,\n 2, // center, right, top,\n 4,\n 8,\n 6, // right, bottom right, bottom,\n 3,\n 4,\n 6, //center, right, bottom\n]);\n\nfunction createVertexArray(context) {\n const positionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: flatPositions,\n usage: BufferUsage.STATIC_DRAW,\n });\n const cubeMapCoordinatesBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: flatCubeMapCoordinates,\n usage: BufferUsage.STATIC_DRAW,\n });\n const indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: indices,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: IndexDatatype.UNSIGNED_SHORT,\n });\n\n const attributes = [\n {\n index: 0,\n vertexBuffer: positionBuffer,\n componentsPerAttribute: 2,\n componentDatatype: ComponentDatatype.FLOAT,\n },\n {\n index: 1,\n vertexBuffer: cubeMapCoordinatesBuffer,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n },\n ];\n return new VertexArray({\n context: context,\n attributes: attributes,\n indexBuffer: indexBuffer,\n });\n}\n\nfunction createUniformTexture(texture) {\n return function () {\n return texture;\n };\n}\n\nfunction cleanupResources(map) {\n map._va = map._va && map._va.destroy();\n map._sp = map._sp && map._sp.destroy();\n\n let i;\n let length;\n\n const cubeMaps = map._cubeMaps;\n if (defined(cubeMaps)) {\n length = cubeMaps.length;\n for (i = 0; i < length; ++i) {\n cubeMaps[i].destroy();\n }\n }\n const mipTextures = map._mipTextures;\n if (defined(mipTextures)) {\n length = mipTextures.length;\n for (i = 0; i < length; ++i) {\n mipTextures[i].destroy();\n }\n }\n\n map._va = undefined;\n map._sp = undefined;\n map._cubeMaps = undefined;\n map._cubeMapBuffers = undefined;\n map._mipTextures = undefined;\n}\n\n/**\n * Creates compute commands to generate octahedral projections of each cube map\n * and then renders them to an atlas.\n *

\n * Only needs to be called twice. The first call queues the compute commands to generate the atlas.\n * The second call cleans up unused resources. Every call afterwards is a no-op.\n *

\n *\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nOctahedralProjectedCubeMap.prototype.update = function (frameState) {\n const context = frameState.context;\n\n if (!OctahedralProjectedCubeMap.isSupported(context)) {\n return;\n }\n\n if (defined(this._texture) && defined(this._va)) {\n cleanupResources(this);\n }\n if (defined(this._texture)) {\n return;\n }\n\n if (!defined(this._texture) && !this._loading) {\n const cachedTexture = frameState.context.textureCache.getTexture(this._url);\n if (defined(cachedTexture)) {\n cleanupResources(this);\n this._texture = cachedTexture;\n this._maximumMipmapLevel = this._texture.maximumMipmapLevel;\n this._ready = true;\n }\n }\n\n const cubeMapBuffers = this._cubeMapBuffers;\n if (!defined(cubeMapBuffers) && !this._loading) {\n const that = this;\n loadKTX2(this._url)\n .then(function (buffers) {\n that._cubeMapBuffers = buffers;\n that._loading = false;\n })\n .catch(function (error) {\n if (that.isDestroyed()) {\n return;\n }\n that._errorEvent.raiseEvent(error);\n });\n this._loading = true;\n }\n\n if (!defined(this._cubeMapBuffers)) {\n return;\n }\n\n const defines = [];\n // Datatype is defined if it is a normalized type (i.e. ..._UNORM, ..._SFLOAT)\n let pixelDatatype = cubeMapBuffers[0].positiveX.pixelDatatype;\n if (!defined(pixelDatatype)) {\n pixelDatatype = context.halfFloatingPointTexture\n ? PixelDatatype.HALF_FLOAT\n : PixelDatatype.FLOAT;\n } else {\n defines.push(\"RGBA_NORMALIZED\");\n }\n const pixelFormat = PixelFormat.RGBA;\n\n const fs = new ShaderSource({\n defines: defines,\n sources: [OctahedralProjectionFS],\n });\n\n this._va = createVertexArray(context);\n this._sp = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: OctahedralProjectionVS,\n fragmentShaderSource: fs,\n attributeLocations: {\n position: 0,\n cubeMapCoordinates: 1,\n },\n });\n\n // We only need up to 6 mip levels to avoid artifacts.\n const length = Math.min(cubeMapBuffers.length, 6);\n this._maximumMipmapLevel = length - 1;\n const cubeMaps = (this._cubeMaps = new Array(length));\n const mipTextures = (this._mipTextures = new Array(length));\n const originalSize = cubeMapBuffers[0].positiveX.width * 2.0;\n const uniformMap = {\n originalSize: function () {\n return originalSize;\n },\n };\n\n // First we project each cubemap onto a flat octahedron, and write that to a texture.\n for (let i = 0; i < length; ++i) {\n // Swap +Y/-Y faces since the octahedral projection expects this order.\n const positiveY = cubeMapBuffers[i].positiveY;\n cubeMapBuffers[i].positiveY = cubeMapBuffers[i].negativeY;\n cubeMapBuffers[i].negativeY = positiveY;\n\n const cubeMap = (cubeMaps[i] = new CubeMap({\n context: context,\n source: cubeMapBuffers[i],\n pixelDatatype: pixelDatatype,\n }));\n const size = cubeMaps[i].width * 2;\n\n const mipTexture = (mipTextures[i] = new Texture({\n context: context,\n width: size,\n height: size,\n pixelDatatype: pixelDatatype,\n pixelFormat: pixelFormat,\n }));\n\n const command = new ComputeCommand({\n vertexArray: this._va,\n shaderProgram: this._sp,\n uniformMap: {\n cubeMap: createUniformTexture(cubeMap),\n },\n outputTexture: mipTexture,\n persists: true,\n owner: this,\n });\n frameState.commandList.push(command);\n\n uniformMap[`texture${i}`] = createUniformTexture(mipTexture);\n }\n\n this._texture = new Texture({\n context: context,\n width: originalSize * 1.5 + 2.0, // We add a 1 pixel border to avoid linear sampling artifacts.\n height: originalSize,\n pixelDatatype: pixelDatatype,\n pixelFormat: pixelFormat,\n });\n\n this._texture.maximumMipmapLevel = this._maximumMipmapLevel;\n context.textureCache.addTexture(this._url, this._texture);\n\n const atlasCommand = new ComputeCommand({\n fragmentShaderSource: OctahedralProjectionAtlasFS,\n uniformMap: uniformMap,\n outputTexture: this._texture,\n persists: false,\n owner: this,\n });\n frameState.commandList.push(atlasCommand);\n\n this._ready = true;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see OctahedralProjectedCubeMap#destroy\n */\nOctahedralProjectedCubeMap.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see OctahedralProjectedCubeMap#isDestroyed\n */\nOctahedralProjectedCubeMap.prototype.destroy = function () {\n cleanupResources(this);\n this._texture = this._texture && this._texture.destroy();\n return destroyObject(this);\n};\nexport default OctahedralProjectedCubeMap;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport OctahedralProjectedCubeMap from \"./OctahedralProjectedCubeMap.js\";\n\n/**\n * Properties for managing image-based lighting on tilesets and models.\n * Also manages the necessary resources and textures.\n *

\n * If specular environment maps are used, {@link ImageBasedLighting#destroy} must be called\n * when the image-based lighting is no longer needed to clean up GPU resources properly.\n * If a model or tileset creates an instance of ImageBasedLighting, it will handle this.\n * Otherwise, the application is responsible for calling destroy().\n *

\n *\n * @alias ImageBasedLighting\n * @constructor\n *\n * @param {Cartesian2} [options.imageBasedLightingFactor=Cartesian2(1.0, 1.0)] Scales diffuse and specular image-based lighting from the earth, sky, atmosphere and star skybox.\n * @param {number} [options.luminanceAtZenith=0.2] The sun's luminance at the zenith in kilo candela per meter squared to use for this model's procedural environment map.\n * @param {Cartesian3[]} [options.sphericalHarmonicCoefficients] The third order spherical harmonic coefficients used for the diffuse color of image-based lighting.\n * @param {string} [options.specularEnvironmentMaps] A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps.\n */\nfunction ImageBasedLighting(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const imageBasedLightingFactor = defined(options.imageBasedLightingFactor)\n ? Cartesian2.clone(options.imageBasedLightingFactor)\n : new Cartesian2(1.0, 1.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\n \"options.imageBasedLightingFactor\",\n imageBasedLightingFactor\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"options.imageBasedLightingFactor.x\",\n imageBasedLightingFactor.x,\n 0.0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"options.imageBasedLightingFactor.x\",\n imageBasedLightingFactor.x,\n 1.0\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"options.imageBasedLightingFactor.y\",\n imageBasedLightingFactor.y,\n 0.0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"options.imageBasedLightingFactor.y\",\n imageBasedLightingFactor.y,\n 1.0\n );\n //>>includeEnd('debug');\n\n this._imageBasedLightingFactor = imageBasedLightingFactor;\n\n const luminanceAtZenith = defaultValue(options.luminanceAtZenith, 0.2);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.luminanceAtZenith\", luminanceAtZenith);\n //>>includeEnd('debug');\n\n this._luminanceAtZenith = luminanceAtZenith;\n\n const sphericalHarmonicCoefficients = options.sphericalHarmonicCoefficients;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(sphericalHarmonicCoefficients) &&\n (!Array.isArray(sphericalHarmonicCoefficients) ||\n sphericalHarmonicCoefficients.length !== 9)\n ) {\n throw new DeveloperError(\n \"options.sphericalHarmonicCoefficients must be an array of 9 Cartesian3 values.\"\n );\n }\n //>>includeEnd('debug');\n this._sphericalHarmonicCoefficients = sphericalHarmonicCoefficients;\n\n // The specular environment map texture is created in update();\n this._specularEnvironmentMaps = options.specularEnvironmentMaps;\n this._specularEnvironmentMapAtlas = undefined;\n this._specularEnvironmentMapAtlasDirty = true;\n this._specularEnvironmentMapLoaded = false;\n this._previousSpecularEnvironmentMapLoaded = false;\n\n this._useDefaultSpecularMaps = false;\n this._useDefaultSphericalHarmonics = false;\n this._shouldRegenerateShaders = false;\n\n // Store the previous frame number to prevent redundant update calls\n this._previousFrameNumber = undefined;\n\n // Keeps track of the last values for use during update logic\n this._previousImageBasedLightingFactor = Cartesian2.clone(\n imageBasedLightingFactor\n );\n this._previousLuminanceAtZenith = luminanceAtZenith;\n this._previousSphericalHarmonicCoefficients = sphericalHarmonicCoefficients;\n this._removeErrorListener = undefined;\n}\n\nObject.defineProperties(ImageBasedLighting.prototype, {\n /**\n * Cesium adds lighting from the earth, sky, atmosphere, and star skybox.\n * This cartesian is used to scale the final diffuse and specular lighting\n * contribution from those sources to the final color. A value of 0.0 will\n * disable those light sources.\n *\n * @memberof ImageBasedLighting.prototype\n *\n * @type {Cartesian2}\n * @default Cartesian2(1.0, 1.0)\n */\n imageBasedLightingFactor: {\n get: function () {\n return this._imageBasedLightingFactor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"imageBasedLightingFactor\", value);\n Check.typeOf.number.greaterThanOrEquals(\n \"imageBasedLightingFactor.x\",\n value.x,\n 0.0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"imageBasedLightingFactor.x\",\n value.x,\n 1.0\n );\n Check.typeOf.number.greaterThanOrEquals(\n \"imageBasedLightingFactor.y\",\n value.y,\n 0.0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"imageBasedLightingFactor.y\",\n value.y,\n 1.0\n );\n //>>includeEnd('debug');\n this._previousImageBasedLightingFactor = Cartesian2.clone(\n this._imageBasedLightingFactor,\n this._previousImageBasedLightingFactor\n );\n this._imageBasedLightingFactor = Cartesian2.clone(\n value,\n this._imageBasedLightingFactor\n );\n },\n },\n\n /**\n * The sun's luminance at the zenith in kilo candela per meter squared\n * to use for this model's procedural environment map. This is used when\n * {@link ImageBasedLighting#specularEnvironmentMaps} and {@link ImageBasedLighting#sphericalHarmonicCoefficients}\n * are not defined.\n *\n * @memberof ImageBasedLighting.prototype\n *\n * @type {number}\n * @default 0.2\n */\n luminanceAtZenith: {\n get: function () {\n return this._luminanceAtZenith;\n },\n set: function (value) {\n this._previousLuminanceAtZenith = this._luminanceAtZenith;\n this._luminanceAtZenith = value;\n },\n },\n\n /**\n * The third order spherical harmonic coefficients used for the diffuse color of image-based lighting. When undefined, a diffuse irradiance\n * computed from the atmosphere color is used.\n *

\n * There are nine Cartesian3 coefficients.\n * The order of the coefficients is: L0,0, L1,-1, L1,0, L1,1, L2,-2, L2,-1, L2,0, L2,1, L2,2\n *

\n *\n * These values can be obtained by preprocessing the environment map using the cmgen tool of\n * {@link https://github.com/google/filament/releases|Google's Filament project}. This will also generate a KTX file that can be\n * supplied to {@link Model#specularEnvironmentMaps}.\n *\n * @memberof ImageBasedLighting.prototype\n *\n * @type {Cartesian3[]}\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Image-Based Lighting.html|Sandcastle Image Based Lighting Demo}\n * @see {@link https://graphics.stanford.edu/papers/envmap/envmap.pdf|An Efficient Representation for Irradiance Environment Maps}\n */\n sphericalHarmonicCoefficients: {\n get: function () {\n return this._sphericalHarmonicCoefficients;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && (!Array.isArray(value) || value.length !== 9)) {\n throw new DeveloperError(\n \"sphericalHarmonicCoefficients must be an array of 9 Cartesian3 values.\"\n );\n }\n //>>includeEnd('debug');\n this._previousSphericalHarmonicCoefficients = this._sphericalHarmonicCoefficients;\n this._sphericalHarmonicCoefficients = value;\n },\n },\n\n /**\n * A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps.\n *\n * @memberof ImageBasedLighting.prototype\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Image-Based Lighting.html|Sandcastle Image Based Lighting Demo}\n * @type {string}\n * @see ImageBasedLighting#sphericalHarmonicCoefficients\n */\n specularEnvironmentMaps: {\n get: function () {\n return this._specularEnvironmentMaps;\n },\n set: function (value) {\n if (value !== this._specularEnvironmentMaps) {\n this._specularEnvironmentMapAtlasDirty =\n this._specularEnvironmentMapAtlasDirty ||\n value !== this._specularEnvironmentMaps;\n this._specularEnvironmentMapLoaded = false;\n }\n this._specularEnvironmentMaps = value;\n },\n },\n\n /**\n * Whether or not image-based lighting is enabled.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n enabled: {\n get: function () {\n return (\n this._imageBasedLightingFactor.x > 0.0 ||\n this._imageBasedLightingFactor.y > 0.0\n );\n },\n },\n\n /**\n * Whether or not the models that use this lighting should regenerate their shaders,\n * based on the properties and resources have changed.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n shouldRegenerateShaders: {\n get: function () {\n return this._shouldRegenerateShaders;\n },\n },\n\n /**\n * Whether or not to use the default spherical harmonic coefficients.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n useDefaultSphericalHarmonics: {\n get: function () {\n return this._useDefaultSphericalHarmonics;\n },\n },\n\n /**\n * Whether or not the image-based lighting settings use spherical harmonic coefficients.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n useSphericalHarmonicCoefficients: {\n get: function () {\n return (\n defined(this._sphericalHarmonicCoefficients) ||\n this._useDefaultSphericalHarmonics\n );\n },\n },\n\n /**\n * The texture atlas for the specular environment maps.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {OctahedralProjectedCubeMap}\n *\n * @private\n */\n specularEnvironmentMapAtlas: {\n get: function () {\n return this._specularEnvironmentMapAtlas;\n },\n },\n\n /**\n * Whether or not to use the default specular environment maps.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n useDefaultSpecularMaps: {\n get: function () {\n return this._useDefaultSpecularMaps;\n },\n },\n\n /**\n * Whether or not the image-based lighting settings use specular environment maps.\n *\n * @memberof ImageBasedLighting.prototype\n * @type {boolean}\n *\n * @private\n */\n useSpecularEnvironmentMaps: {\n get: function () {\n return (\n (defined(this._specularEnvironmentMapAtlas) &&\n this._specularEnvironmentMapAtlas.ready) ||\n this._useDefaultSpecularMaps\n );\n },\n },\n});\n\nfunction createSpecularEnvironmentMapAtlas(imageBasedLighting, context) {\n if (!OctahedralProjectedCubeMap.isSupported(context)) {\n return;\n }\n\n imageBasedLighting._specularEnvironmentMapAtlas =\n imageBasedLighting._specularEnvironmentMapAtlas &&\n imageBasedLighting._specularEnvironmentMapAtlas.destroy();\n\n if (defined(imageBasedLighting._specularEnvironmentMaps)) {\n const atlas = new OctahedralProjectedCubeMap(\n imageBasedLighting._specularEnvironmentMaps\n );\n imageBasedLighting._specularEnvironmentMapAtlas = atlas;\n\n imageBasedLighting._removeErrorListener = atlas.errorEvent.addEventListener(\n (error) => {\n console.error(`Error loading specularEnvironmentMaps: ${error}`);\n }\n );\n }\n\n // Regenerate shaders so they do not use an environment map.\n // Will be set to true again if there was a new environment map and it is ready.\n imageBasedLighting._shouldRegenerateShaders = true;\n}\n\nImageBasedLighting.prototype.update = function (frameState) {\n if (frameState.frameNumber === this._previousFrameNumber) {\n return;\n }\n\n this._previousFrameNumber = frameState.frameNumber;\n const context = frameState.context;\n\n frameState.brdfLutGenerator.update(frameState);\n this._shouldRegenerateShaders = false;\n\n const iblFactor = this._imageBasedLightingFactor;\n const previousIBLFactor = this._previousImageBasedLightingFactor;\n if (!Cartesian2.equals(iblFactor, previousIBLFactor)) {\n this._shouldRegenerateShaders =\n (iblFactor.x > 0.0 && previousIBLFactor.x === 0.0) ||\n (iblFactor.x === 0.0 && previousIBLFactor.x > 0.0);\n this._shouldRegenerateShaders =\n this._shouldRegenerateShaders ||\n (iblFactor.y > 0.0 && previousIBLFactor.y === 0.0) ||\n (iblFactor.y === 0.0 && previousIBLFactor.y > 0.0);\n\n this._previousImageBasedLightingFactor = Cartesian2.clone(\n this._imageBasedLightingFactor,\n this._previousImageBasedLightingFactor\n );\n }\n\n if (this._luminanceAtZenith !== this._previousLuminanceAtZenith) {\n this._shouldRegenerateShaders =\n this._shouldRegenerateShaders ||\n defined(this._luminanceAtZenith) !==\n defined(this._previousLuminanceAtZenith);\n\n this._previousLuminanceAtZenith = this._luminanceAtZenith;\n }\n\n if (\n this._previousSphericalHarmonicCoefficients !==\n this._sphericalHarmonicCoefficients\n ) {\n this._shouldRegenerateShaders =\n this._shouldRegenerateShaders ||\n defined(this._previousSphericalHarmonicCoefficients) !==\n defined(this._sphericalHarmonicCoefficients);\n\n this._previousSphericalHarmonicCoefficients = this._sphericalHarmonicCoefficients;\n }\n\n this._shouldRegenerateShaders =\n this._shouldRegenerateShaders ||\n this._previousSpecularEnvironmentMapLoaded !==\n this._specularEnvironmentMapLoaded;\n\n this._previousSpecularEnvironmentMapLoaded = this._specularEnvironmentMapLoaded;\n\n if (this._specularEnvironmentMapAtlasDirty) {\n createSpecularEnvironmentMapAtlas(this, context);\n this._specularEnvironmentMapAtlasDirty = false;\n }\n\n if (defined(this._specularEnvironmentMapAtlas)) {\n this._specularEnvironmentMapAtlas.update(frameState);\n if (this._specularEnvironmentMapAtlas.ready) {\n this._specularEnvironmentMapLoaded = true;\n }\n }\n\n const recompileWithDefaultAtlas =\n !defined(this._specularEnvironmentMapAtlas) &&\n defined(frameState.specularEnvironmentMaps) &&\n !this._useDefaultSpecularMaps;\n const recompileWithoutDefaultAtlas =\n !defined(frameState.specularEnvironmentMaps) &&\n this._useDefaultSpecularMaps;\n\n const recompileWithDefaultSHCoeffs =\n !defined(this._sphericalHarmonicCoefficients) &&\n defined(frameState.sphericalHarmonicCoefficients) &&\n !this._useDefaultSphericalHarmonics;\n const recompileWithoutDefaultSHCoeffs =\n !defined(frameState.sphericalHarmonicCoefficients) &&\n this._useDefaultSphericalHarmonics;\n\n this._shouldRegenerateShaders =\n this._shouldRegenerateShaders ||\n recompileWithDefaultAtlas ||\n recompileWithoutDefaultAtlas ||\n recompileWithDefaultSHCoeffs ||\n recompileWithoutDefaultSHCoeffs;\n\n this._useDefaultSpecularMaps =\n !defined(this._specularEnvironmentMapAtlas) &&\n defined(frameState.specularEnvironmentMaps);\n this._useDefaultSphericalHarmonics =\n !defined(this._sphericalHarmonicCoefficients) &&\n defined(frameState.sphericalHarmonicCoefficients);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see ImageBasedLighting#destroy\n * @private\n */\nImageBasedLighting.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * imageBasedLighting = imageBasedLighting && imageBasedLighting.destroy();\n *\n * @see ImageBasedLighting#isDestroyed\n * @private\n */\nImageBasedLighting.prototype.destroy = function () {\n this._specularEnvironmentMapAtlas =\n this._specularEnvironmentMapAtlas &&\n this._specularEnvironmentMapAtlas.destroy();\n this._removeErrorListener =\n this._removeErrorListener && this._removeErrorListener();\n return destroyObject(this);\n};\n\nexport default ImageBasedLighting;\n", "import Uri from \"urijs\";\nimport Check from \"./Check.js\";\nimport Credit from \"./Credit.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ion from \"./Ion.js\";\nimport Resource from \"./Resource.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\n/**\n * A {@link Resource} instance that encapsulates Cesium ion asset access.\n * This object is normally not instantiated directly, use {@link IonResource.fromAssetId}.\n *\n * @alias IonResource\n * @constructor\n * @augments Resource\n *\n * @param {object} endpoint The result of the Cesium ion asset endpoint service.\n * @param {Resource} endpointResource The resource used to retrieve the endpoint.\n *\n * @see Ion\n * @see IonImageryProvider\n * @see createWorldTerrain\n * @see https://cesium.com\n */\nfunction IonResource(endpoint, endpointResource) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"endpoint\", endpoint);\n Check.defined(\"endpointResource\", endpointResource);\n //>>includeEnd('debug');\n\n let options;\n const externalType = endpoint.externalType;\n const isExternal = defined(externalType);\n\n if (!isExternal) {\n options = {\n url: endpoint.url,\n retryAttempts: 1,\n retryCallback: retryCallback,\n };\n } else if (\n externalType === \"3DTILES\" ||\n externalType === \"STK_TERRAIN_SERVER\"\n ) {\n // 3D Tiles and STK Terrain Server external assets can still be represented as an IonResource\n options = { url: endpoint.options.url };\n } else {\n //External imagery assets have additional configuration that can't be represented as a Resource\n throw new RuntimeError(\n \"Ion.createResource does not support external imagery assets; use IonImageryProvider instead.\"\n );\n }\n\n Resource.call(this, options);\n\n // The asset endpoint data returned from ion.\n this._ionEndpoint = endpoint;\n this._ionEndpointDomain = isExternal\n ? undefined\n : new Uri(endpoint.url).authority();\n\n // The endpoint resource to fetch when a new token is needed\n this._ionEndpointResource = endpointResource;\n\n // The primary IonResource from which an instance is derived\n this._ionRoot = undefined;\n\n // Shared promise for endpooint requests amd credits (only ever set on the root request)\n this._pendingPromise = undefined;\n this._credits = undefined;\n this._isExternal = isExternal;\n}\n\nif (defined(Object.create)) {\n IonResource.prototype = Object.create(Resource.prototype);\n IonResource.prototype.constructor = IonResource;\n}\n\n/**\n * Asynchronously creates an instance.\n *\n * @param {number} assetId The Cesium ion asset id.\n * @param {object} [options] An object with the following properties:\n * @param {string} [options.accessToken=Ion.defaultAccessToken] The access token to use.\n * @param {string|Resource} [options.server=Ion.defaultServer] The resource to the Cesium ion API server.\n * @returns {Promise} A Promise to am instance representing the Cesium ion Asset.\n *\n * @example\n * // Load a Cesium3DTileset with asset ID of 124624234\n * try {\n * const resource = await Cesium.IonResource.fromAssetId(124624234);\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(resource);\n * scene.primitives.add(tileset);\n * } catch (error) {\n * console.error(`Error creating tileset: ${error}`);\n * }\n *\n * @example\n * //Load a CZML file with asset ID of 10890\n * Cesium.IonResource.fromAssetId(10890)\n * .then(function (resource) {\n * viewer.dataSources.add(Cesium.CzmlDataSource.load(resource));\n * });\n */\nIonResource.fromAssetId = function (assetId, options) {\n const endpointResource = IonResource._createEndpointResource(\n assetId,\n options\n );\n\n return endpointResource.fetchJson().then(function (endpoint) {\n return new IonResource(endpoint, endpointResource);\n });\n};\n\nObject.defineProperties(IonResource.prototype, {\n /**\n * Gets the credits required for attribution of the asset.\n *\n * @memberof IonResource.prototype\n * @type {Credit[]}\n * @readonly\n */\n credits: {\n get: function () {\n // Only we're not the root, return its credits;\n if (defined(this._ionRoot)) {\n return this._ionRoot.credits;\n }\n\n // We are the root\n if (defined(this._credits)) {\n return this._credits;\n }\n\n this._credits = IonResource.getCreditsFromEndpoint(\n this._ionEndpoint,\n this._ionEndpointResource\n );\n\n return this._credits;\n },\n },\n});\n\n/** @private */\nIonResource.getCreditsFromEndpoint = function (endpoint, endpointResource) {\n const credits = endpoint.attributions.map(Credit.getIonCredit);\n const defaultTokenCredit = Ion.getDefaultTokenCredit(\n endpointResource.queryParameters.access_token\n );\n if (defined(defaultTokenCredit)) {\n credits.push(Credit.clone(defaultTokenCredit));\n }\n return credits;\n};\n\n/** @inheritdoc */\nIonResource.prototype.clone = function (result) {\n // We always want to use the root's information because it's the most up-to-date\n const ionRoot = defaultValue(this._ionRoot, this);\n\n if (!defined(result)) {\n result = new IonResource(\n ionRoot._ionEndpoint,\n ionRoot._ionEndpointResource\n );\n }\n\n result = Resource.prototype.clone.call(this, result);\n result._ionRoot = ionRoot;\n result._isExternal = this._isExternal;\n\n return result;\n};\n\nIonResource.prototype.fetchImage = function (options) {\n if (!this._isExternal) {\n const userOptions = options;\n options = {\n preferBlob: true,\n };\n if (defined(userOptions)) {\n options.flipY = userOptions.flipY;\n options.preferImageBitmap = userOptions.preferImageBitmap;\n }\n }\n\n return Resource.prototype.fetchImage.call(this, options);\n};\n\nIonResource.prototype._makeRequest = function (options) {\n // Don't send ion access token to non-ion servers.\n if (\n this._isExternal ||\n new Uri(this.url).authority() !== this._ionEndpointDomain\n ) {\n return Resource.prototype._makeRequest.call(this, options);\n }\n\n if (!defined(options.headers)) {\n options.headers = {};\n }\n options.headers.Authorization = `Bearer ${this._ionEndpoint.accessToken}`;\n options.headers[\"X-Cesium-Client\"] = \"CesiumJS\";\n /* global CESIUM_VERSION */\n if (typeof CESIUM_VERSION !== \"undefined\") {\n options.headers[\"X-Cesium-Client-Version\"] = CESIUM_VERSION;\n }\n\n return Resource.prototype._makeRequest.call(this, options);\n};\n\n/**\n * @private\n */\nIonResource._createEndpointResource = function (assetId, options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"assetId\", assetId);\n //>>includeEnd('debug');\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n let server = defaultValue(options.server, Ion.defaultServer);\n const accessToken = defaultValue(options.accessToken, Ion.defaultAccessToken);\n server = Resource.createIfNeeded(server);\n\n const resourceOptions = {\n url: `v1/assets/${assetId}/endpoint`,\n };\n\n if (defined(accessToken)) {\n resourceOptions.queryParameters = { access_token: accessToken };\n }\n\n return server.getDerivedResource(resourceOptions);\n};\n\nfunction retryCallback(that, error) {\n const ionRoot = defaultValue(that._ionRoot, that);\n const endpointResource = ionRoot._ionEndpointResource;\n\n // Image is not available in worker threads, so this avoids\n // a ReferenceError\n const imageDefined = typeof Image !== \"undefined\";\n\n // We only want to retry in the case of invalid credentials (401) or image\n // requests(since Image failures can not provide a status code)\n if (\n !defined(error) ||\n (error.statusCode !== 401 &&\n !(imageDefined && error.target instanceof Image))\n ) {\n return Promise.resolve(false);\n }\n\n // We use a shared pending promise for all derived assets, since they share\n // a common access_token. If we're already requesting a new token for this\n // asset, we wait on the same promise.\n if (!defined(ionRoot._pendingPromise)) {\n ionRoot._pendingPromise = endpointResource\n .fetchJson()\n .then(function (newEndpoint) {\n //Set the token for root resource so new derived resources automatically pick it up\n ionRoot._ionEndpoint = newEndpoint;\n return newEndpoint;\n })\n .finally(function (newEndpoint) {\n // Pass or fail, we're done with this promise, the next failure should use a new one.\n ionRoot._pendingPromise = undefined;\n return newEndpoint;\n });\n }\n\n return ionRoot._pendingPromise.then(function (newEndpoint) {\n // Set the new token and endpoint for this resource\n that._ionEndpoint = newEndpoint;\n return true;\n });\n}\nexport default IonResource;\n", "import Credit from \"./Credit.js\";\nimport defined from \"./defined.js\";\nimport Resource from \"./Resource.js\";\n\nlet defaultTokenCredit;\nconst defaultAccessToken =\n \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkNDE4MTdhNy0yYjYzLTQwNjktODJiMy0xMWU2MjI4MTA4ODQiLCJpZCI6MjU5LCJpYXQiOjE2OTA5MDkwMjZ9.G-iUU-kiQeQx74_iQdhyc5IUrVbIIFDhFx7RFn94LaQ\";\n/**\n * Default settings for accessing the Cesium ion API.\n *\n * An ion access token is only required if you are using any ion related APIs.\n * A default access token is provided for evaluation purposes only.\n * Sign up for a free ion account and get your own access token at {@link https://cesium.com}\n *\n * @see IonResource\n * @see IonImageryProvider\n * @see IonGeocoderService\n * @see createWorldImagery\n * @see createWorldTerrain\n * @namespace Ion\n */\nconst Ion = {};\n\n/**\n * Gets or sets the default Cesium ion access token.\n *\n * @type {string}\n */\nIon.defaultAccessToken = defaultAccessToken;\n\n/**\n * Gets or sets the default Cesium ion server.\n *\n * @type {string|Resource}\n * @default https://api.cesium.com\n */\nIon.defaultServer = new Resource({ url: \"https://api.cesium.com/\" });\n\nIon.getDefaultTokenCredit = function (providedKey) {\n if (providedKey !== defaultAccessToken) {\n return undefined;\n }\n\n if (!defined(defaultTokenCredit)) {\n const defaultTokenMessage =\n ' \\\n This application is using Cesium\\'s default ion access token. Please assign Cesium.Ion.defaultAccessToken \\\n with an access token from your ion account before making any Cesium API calls. \\\n You can sign up for a free ion account at https://cesium.com.';\n\n defaultTokenCredit = new Credit(defaultTokenMessage, true);\n defaultTokenCredit._isDefaultToken = true;\n }\n\n return defaultTokenCredit;\n};\nexport default Ion;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\n\n/**\n * A wrapper around arrays so that the internal length of the array can be manually managed.\n *\n * @alias ManagedArray\n * @constructor\n * @private\n *\n * @param {number} [length=0] The initial length of the array.\n */\nfunction ManagedArray(length) {\n length = defaultValue(length, 0);\n this._array = new Array(length);\n this._length = length;\n}\n\nObject.defineProperties(ManagedArray.prototype, {\n /**\n * Gets or sets the length of the array.\n * If the set length is greater than the length of the internal array, the internal array is resized.\n *\n * @memberof ManagedArray.prototype\n * @type {number}\n */\n length: {\n get: function () {\n return this._length;\n },\n set: function (length) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"length\", length, 0);\n //>>includeEnd('debug');\n const array = this._array;\n const originalLength = this._length;\n if (length < originalLength) {\n // Remove trailing references\n for (let i = length; i < originalLength; ++i) {\n array[i] = undefined;\n }\n } else if (length > array.length) {\n array.length = length;\n }\n this._length = length;\n },\n },\n\n /**\n * Gets the internal array.\n *\n * @memberof ManagedArray.prototype\n * @type {Array}\n * @readonly\n */\n values: {\n get: function () {\n return this._array;\n },\n },\n});\n\n/**\n * Gets the element at an index.\n *\n * @param {number} index The index to get.\n */\nManagedArray.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.lessThan(\"index\", index, this._array.length);\n //>>includeEnd('debug');\n\n return this._array[index];\n};\n\n/**\n * Sets the element at an index. Resizes the array if index is greater than the length of the array.\n *\n * @param {number} index The index to set.\n * @param {*} element The element to set at index.\n */\nManagedArray.prototype.set = function (index, element) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n //>>includeEnd('debug');\n\n if (index >= this._length) {\n this.length = index + 1;\n }\n this._array[index] = element;\n};\n\n/**\n * Returns the last element in the array without modifying the array.\n *\n * @returns {*} The last element in the array.\n */\nManagedArray.prototype.peek = function () {\n return this._array[this._length - 1];\n};\n\n/**\n * Push an element into the array.\n *\n * @param {*} element The element to push.\n */\nManagedArray.prototype.push = function (element) {\n const index = this.length++;\n this._array[index] = element;\n};\n\n/**\n * Pop an element from the array.\n *\n * @returns {*} The last element in the array.\n */\nManagedArray.prototype.pop = function () {\n if (this._length === 0) {\n return undefined;\n }\n const element = this._array[this._length - 1];\n --this.length;\n return element;\n};\n\n/**\n * Resize the internal array if length > _array.length.\n *\n * @param {number} length The length.\n */\nManagedArray.prototype.reserve = function (length) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"length\", length, 0);\n //>>includeEnd('debug');\n\n if (length > this._array.length) {\n this._array.length = length;\n }\n};\n\n/**\n * Resize the array.\n *\n * @param {number} length The length.\n */\nManagedArray.prototype.resize = function (length) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"length\", length, 0);\n //>>includeEnd('debug');\n\n this.length = length;\n};\n\n/**\n * Trim the internal array to the specified length. Defaults to the current length.\n *\n * @param {number} [length] The length.\n */\nManagedArray.prototype.trim = function (length) {\n length = defaultValue(length, this._length);\n this._array.length = length;\n};\nexport default ManagedArray;\n", "import Check from \"../Core/Check.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\n\n/**\n * An enum describing the x, y, and z axes and helper conversion functions.\n *\n * @enum {number}\n */\nconst Axis = {\n /**\n * Denotes the x-axis.\n *\n * @type {number}\n * @constant\n */\n X: 0,\n\n /**\n * Denotes the y-axis.\n *\n * @type {number}\n * @constant\n */\n Y: 1,\n\n /**\n * Denotes the z-axis.\n *\n * @type {number}\n * @constant\n */\n Z: 2,\n};\n\n/**\n * Matrix used to convert from y-up to z-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.Y_UP_TO_Z_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Matrix used to convert from z-up to y-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.Z_UP_TO_Y_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationX(-CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Matrix used to convert from x-up to z-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.X_UP_TO_Z_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationY(-CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Matrix used to convert from z-up to x-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.Z_UP_TO_X_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Matrix used to convert from x-up to y-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.X_UP_TO_Y_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationZ(CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Matrix used to convert from y-up to x-up\n *\n * @type {Matrix4}\n * @constant\n */\nAxis.Y_UP_TO_X_UP = Matrix4.fromRotationTranslation(\n Matrix3.fromRotationZ(-CesiumMath.PI_OVER_TWO)\n);\n\n/**\n * Gets the axis by name\n *\n * @param {string} name The name of the axis.\n * @returns {number} The axis enum.\n */\nAxis.fromName = function (name) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"name\", name);\n //>>includeEnd('debug');\n\n return Axis[name];\n};\n\nexport default Object.freeze(Axis);\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * Simple abstraction for a group. This class exists to make the metadata API\n * more consistent, i.e. metadata can be accessed via\n * content.group.metadata much like tile metadata is accessed as\n * tile.metadata.\n *\n * @param {object} options Object with the following properties:\n * @param {GroupMetadata} options.metadata The metadata associated with this group.\n *\n * @alias Cesium3DContentGroup\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction Cesium3DContentGroup(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.metadata\", options.metadata);\n //>>includeEnd('debug');\n\n this._metadata = options.metadata;\n}\n\nObject.defineProperties(Cesium3DContentGroup.prototype, {\n /**\n * Get the metadata for this group\n *\n * @memberof Cesium3DContentGroup.prototype\n *\n * @type {GroupMetadata}\n *\n * @readonly\n */\n metadata: {\n get: function () {\n return this._metadata;\n },\n },\n});\n\nexport default Cesium3DContentGroup;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\n/**\n * Reads a string from a Uint8Array.\n *\n * @function\n *\n * @param {Uint8Array} uint8Array The Uint8Array to read from.\n * @param {number} [byteOffset=0] The byte offset to start reading from.\n * @param {number} [byteLength] The byte length to read. If byteLength is omitted the remainder of the buffer is read.\n * @returns {string} The string.\n *\n * @private\n */\nfunction getStringFromTypedArray(uint8Array, byteOffset, byteLength) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(uint8Array)) {\n throw new DeveloperError(\"uint8Array is required.\");\n }\n if (byteOffset < 0) {\n throw new DeveloperError(\"byteOffset cannot be negative.\");\n }\n if (byteLength < 0) {\n throw new DeveloperError(\"byteLength cannot be negative.\");\n }\n if (byteOffset + byteLength > uint8Array.byteLength) {\n throw new DeveloperError(\"sub-region exceeds array bounds.\");\n }\n //>>includeEnd('debug');\n\n byteOffset = defaultValue(byteOffset, 0);\n byteLength = defaultValue(byteLength, uint8Array.byteLength - byteOffset);\n\n uint8Array = uint8Array.subarray(byteOffset, byteOffset + byteLength);\n\n return getStringFromTypedArray.decode(uint8Array);\n}\n\n// Exposed functions for testing\ngetStringFromTypedArray.decodeWithTextDecoder = function (view) {\n const decoder = new TextDecoder(\"utf-8\");\n return decoder.decode(view);\n};\n\ngetStringFromTypedArray.decodeWithFromCharCode = function (view) {\n let result = \"\";\n const codePoints = utf8Handler(view);\n const length = codePoints.length;\n for (let i = 0; i < length; ++i) {\n let cp = codePoints[i];\n if (cp <= 0xffff) {\n result += String.fromCharCode(cp);\n } else {\n cp -= 0x10000;\n result += String.fromCharCode((cp >> 10) + 0xd800, (cp & 0x3ff) + 0xdc00);\n }\n }\n return result;\n};\n\nfunction inRange(a, min, max) {\n return min <= a && a <= max;\n}\n\n// This code is inspired by public domain code found here: https://github.com/inexorabletash/text-encoding\nfunction utf8Handler(utfBytes) {\n let codePoint = 0;\n let bytesSeen = 0;\n let bytesNeeded = 0;\n let lowerBoundary = 0x80;\n let upperBoundary = 0xbf;\n\n const codePoints = [];\n const length = utfBytes.length;\n for (let i = 0; i < length; ++i) {\n const currentByte = utfBytes[i];\n\n // If bytesNeeded = 0, then we are starting a new character\n if (bytesNeeded === 0) {\n // 1 Byte Ascii character\n if (inRange(currentByte, 0x00, 0x7f)) {\n // Return a code point whose value is byte.\n codePoints.push(currentByte);\n continue;\n }\n\n // 2 Byte character\n if (inRange(currentByte, 0xc2, 0xdf)) {\n bytesNeeded = 1;\n codePoint = currentByte & 0x1f;\n continue;\n }\n\n // 3 Byte character\n if (inRange(currentByte, 0xe0, 0xef)) {\n // If byte is 0xE0, set utf-8 lower boundary to 0xA0.\n if (currentByte === 0xe0) {\n lowerBoundary = 0xa0;\n }\n // If byte is 0xED, set utf-8 upper boundary to 0x9F.\n if (currentByte === 0xed) {\n upperBoundary = 0x9f;\n }\n\n bytesNeeded = 2;\n codePoint = currentByte & 0xf;\n continue;\n }\n\n // 4 Byte character\n if (inRange(currentByte, 0xf0, 0xf4)) {\n // If byte is 0xF0, set utf-8 lower boundary to 0x90.\n if (currentByte === 0xf0) {\n lowerBoundary = 0x90;\n }\n // If byte is 0xF4, set utf-8 upper boundary to 0x8F.\n if (currentByte === 0xf4) {\n upperBoundary = 0x8f;\n }\n\n bytesNeeded = 3;\n codePoint = currentByte & 0x7;\n continue;\n }\n\n throw new RuntimeError(\"String decoding failed.\");\n }\n\n // Out of range, so ignore the first part(s) of the character and continue with this byte on its own\n if (!inRange(currentByte, lowerBoundary, upperBoundary)) {\n codePoint = bytesNeeded = bytesSeen = 0;\n lowerBoundary = 0x80;\n upperBoundary = 0xbf;\n --i;\n continue;\n }\n\n // Set appropriate boundaries, since we've now checked byte 2 of a potential longer character\n lowerBoundary = 0x80;\n upperBoundary = 0xbf;\n\n // Add byte to code point\n codePoint = (codePoint << 6) | (currentByte & 0x3f);\n\n // We have the correct number of bytes, so push and reset for next character\n ++bytesSeen;\n if (bytesSeen === bytesNeeded) {\n codePoints.push(codePoint);\n codePoint = bytesNeeded = bytesSeen = 0;\n }\n }\n\n return codePoints;\n}\n\nif (typeof TextDecoder !== \"undefined\") {\n getStringFromTypedArray.decode =\n getStringFromTypedArray.decodeWithTextDecoder;\n} else {\n getStringFromTypedArray.decode =\n getStringFromTypedArray.decodeWithFromCharCode;\n}\nexport default getStringFromTypedArray;\n", "import defaultValue from \"./defaultValue.js\";\nimport getStringFromTypedArray from \"./getStringFromTypedArray.js\";\n\n/**\n * @private\n */\nfunction getMagic(uint8Array, byteOffset) {\n byteOffset = defaultValue(byteOffset, 0);\n return getStringFromTypedArray(\n uint8Array,\n byteOffset,\n Math.min(4, uint8Array.length)\n );\n}\nexport default getMagic;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport getMagic from \"../Core/getMagic.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * Represents the contents of a\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Composite|Composite}\n * tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @alias Composite3DTileContent\n * @constructor\n *\n * @private\n */\nfunction Composite3DTileContent(tileset, tile, resource, contents) {\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n\n if (!defined(contents)) {\n contents = [];\n }\n this._contents = contents;\n\n this._metadata = undefined;\n this._group = undefined;\n this._ready = false;\n}\n\nObject.defineProperties(Composite3DTileContent.prototype, {\n featurePropertiesDirty: {\n get: function () {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n if (contents[i].featurePropertiesDirty) {\n return true;\n }\n }\n\n return false;\n },\n set: function (value) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].featurePropertiesDirty = value;\n }\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call featuresLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n featuresLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call pointsLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call trianglesLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n trianglesLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call geometryByteLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n geometryByteLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call texturesByteLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns 0. Instead call batchTableByteLength for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n batchTableByteLength: {\n get: function () {\n return 0;\n },\n },\n\n innerContents: {\n get: function () {\n return this._contents;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Composite3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._resource.getUrlComponent(true);\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * both stores the content metadata and propagates the content metadata to all of its children.\n * @memberof Composite3DTileContent.prototype\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n metadata: {\n get: function () {\n return this._metadata;\n },\n set: function (value) {\n this._metadata = value;\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].metadata = value;\n }\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns undefined. Instead call batchTable for a tile in the composite.\n * @memberof Composite3DTileContent.prototype\n */\n batchTable: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * both stores the group metadata and propagates the group metadata to all of its children.\n * @memberof Composite3DTileContent.prototype\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].group = value;\n }\n },\n },\n});\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\nComposite3DTileContent.fromTileType = async function (\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset,\n factory\n) {\n byteOffset = defaultValue(byteOffset, 0);\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Composite Tile version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n // Skip byteLength\n byteOffset += sizeOfUint32;\n\n const tilesLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n // For caching purposes, models within the composite tile must be\n // distinguished. To do this, add a query parameter ?compositeIndex=i.\n // Since composite tiles may contain other composite tiles, check for an\n // existing prefix and separate them with underscores. e.g.\n // ?compositeIndex=0_1_1\n let prefix = resource.queryParameters.compositeIndex;\n if (defined(prefix)) {\n // We'll be adding another value at the end, so add an underscore.\n prefix = `${prefix}_`;\n } else {\n // no prefix\n prefix = \"\";\n }\n\n const promises = [];\n promises.length = tilesLength;\n for (let i = 0; i < tilesLength; ++i) {\n const tileType = getMagic(uint8Array, byteOffset);\n\n // Tile byte length is stored after magic and version\n const tileByteLength = view.getUint32(byteOffset + sizeOfUint32 * 2, true);\n\n const contentFactory = factory[tileType];\n\n // Label which content within the composite this is\n const compositeIndex = `${prefix}${i}`;\n const childResource = resource.getDerivedResource({\n queryParameters: {\n compositeIndex: compositeIndex,\n },\n });\n\n if (defined(contentFactory)) {\n promises[i] = Promise.resolve(\n contentFactory(tileset, tile, childResource, arrayBuffer, byteOffset)\n );\n } else {\n throw new RuntimeError(\n `Unknown tile content type, ${tileType}, inside Composite tile`\n );\n }\n\n byteOffset += tileByteLength;\n }\n\n const innerContents = await Promise.all(promises);\n const content = new Composite3DTileContent(\n tileset,\n tile,\n resource,\n innerContents\n );\n return content;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns false. Instead call hasProperty for a tile in the composite.\n */\nComposite3DTileContent.prototype.hasProperty = function (batchId, name) {\n return false;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Composite3DTileContent\n * always returns undefined. Instead call getFeature for a tile in the composite.\n */\nComposite3DTileContent.prototype.getFeature = function (batchId) {\n return undefined;\n};\n\nComposite3DTileContent.prototype.applyDebugSettings = function (\n enabled,\n color\n) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].applyDebugSettings(enabled, color);\n }\n};\n\nComposite3DTileContent.prototype.applyStyle = function (style) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].applyStyle(style);\n }\n};\n\nComposite3DTileContent.prototype.update = function (tileset, frameState) {\n const contents = this._contents;\n const length = contents.length;\n let ready = true;\n for (let i = 0; i < length; ++i) {\n contents[i].update(tileset, frameState);\n ready = ready && contents[i].ready;\n }\n\n if (!this._ready && ready) {\n this._ready = true;\n }\n};\n\nComposite3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nComposite3DTileContent.prototype.destroy = function () {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].destroy();\n }\n return destroyObject(this);\n};\nexport default Composite3DTileContent;\n", "import getStringFromTypedArray from \"./getStringFromTypedArray.js\";\n\n/**\n * Parses JSON from a Uint8Array.\n *\n * @function\n *\n * @param {Uint8Array} uint8Array The Uint8Array to read from.\n * @param {number} [byteOffset=0] The byte offset to start reading from.\n * @param {number} [byteLength] The byte length to read. If byteLength is omitted the remainder of the buffer is read.\n * @returns {object} An object containing the parsed JSON.\n *\n * @private\n */\nfunction getJsonFromTypedArray(uint8Array, byteOffset, byteLength) {\n return JSON.parse(\n getStringFromTypedArray(uint8Array, byteOffset, byteLength)\n );\n}\n\nexport default getJsonFromTypedArray;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport PixelDatatype from \"../Renderer/PixelDatatype.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport Texture from \"../Renderer/Texture.js\";\n\n/**\n * An object that manages color, show/hide and picking textures for a batch\n * table or feature table.\n *\n * @param {object} options Object with the following properties:\n * @param {number} featuresLength The number of features in the batch table or feature table\n * @param {Cesium3DTileContent|ModelFeatureTable} owner The owner of this batch texture. For 3D Tiles, this will be a {@link Cesium3DTileContent}. For glTF models, this will be a {@link ModelFeatureTable}.\n * @param {object} [statistics] The statistics object to update with information about the batch texture.\n * @param {Function} [colorChangedCallback] A callback function that is called whenever the color of a feature changes.\n *\n * @alias BatchTexture\n * @constructor\n *\n * @private\n */\nfunction BatchTexture(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.featuresLength\", options.featuresLength);\n Check.typeOf.object(\"options.owner\", options.owner);\n //>>includeEnd('debug');\n\n this._id = createGuid();\n\n const featuresLength = options.featuresLength;\n\n // PERFORMANCE_IDEA: These parallel arrays probably generate cache misses in get/set color/show\n // and use A LOT of memory. How can we use less memory?\n this._showAlphaProperties = undefined; // [Show (0 or 255), Alpha (0 to 255)] property for each feature\n this._batchValues = undefined; // Per-feature RGBA (A is based on the color's alpha and feature's show property)\n\n this._batchValuesDirty = false;\n this._batchTexture = undefined;\n this._defaultTexture = undefined;\n\n this._pickTexture = undefined;\n this._pickIds = [];\n\n // Dimensions for batch and pick textures\n let textureDimensions;\n let textureStep;\n\n if (featuresLength > 0) {\n // PERFORMANCE_IDEA: this can waste memory in the last row in the uncommon case\n // when more than one row is needed (e.g., > 16K features in one tile)\n const width = Math.min(featuresLength, ContextLimits.maximumTextureSize);\n const height = Math.ceil(featuresLength / ContextLimits.maximumTextureSize);\n const stepX = 1.0 / width;\n const centerX = stepX * 0.5;\n const stepY = 1.0 / height;\n const centerY = stepY * 0.5;\n\n textureDimensions = new Cartesian2(width, height);\n textureStep = new Cartesian4(stepX, centerX, stepY, centerY);\n }\n\n this._translucentFeaturesLength = 0;\n this._featuresLength = featuresLength;\n this._textureDimensions = textureDimensions;\n this._textureStep = textureStep;\n this._owner = options.owner;\n this._statistics = options.statistics;\n this._colorChangedCallback = options.colorChangedCallback;\n}\n\nObject.defineProperties(BatchTexture.prototype, {\n /**\n * Number of features that are translucent\n *\n * @memberof BatchTexture.prototype\n * @type {number}\n * @readonly\n * @private\n */\n translucentFeaturesLength: {\n get: function () {\n return this._translucentFeaturesLength;\n },\n },\n\n /**\n * Total size of all GPU resources used by this batch texture.\n *\n * @memberof BatchTexture.prototype\n * @type {number}\n * @readonly\n * @private\n */\n byteLength: {\n get: function () {\n let memory = 0;\n if (defined(this._pickTexture)) {\n memory += this._pickTexture.sizeInBytes;\n }\n if (defined(this._batchTexture)) {\n memory += this._batchTexture.sizeInBytes;\n }\n return memory;\n },\n },\n\n /**\n * Dimensions of the underlying batch texture.\n *\n * @memberof BatchTexture.prototype\n * @type {Cartesian2}\n * @readonly\n * @private\n */\n textureDimensions: {\n get: function () {\n return this._textureDimensions;\n },\n },\n\n /**\n * Size of each texture and distance from side to center of a texel in\n * each direction. Stored as (stepX, centerX, stepY, centerY)\n *\n * @memberof BatchTexture.prototype\n * @type {Cartesian4}\n * @readonly\n * @private\n */\n textureStep: {\n get: function () {\n return this._textureStep;\n },\n },\n\n /**\n * The underlying texture used for styling. The texels are accessed\n * by batch ID, and the value is the color of this feature after accounting\n * for show/hide settings.\n *\n * @memberof BatchTexture.prototype\n * @type {Texture}\n * @readonly\n * @private\n */\n batchTexture: {\n get: function () {\n return this._batchTexture;\n },\n },\n\n /**\n * The default texture to use when there are no batch values\n *\n * @memberof BatchTexture.prototype\n * @type {Texture}\n * @readonly\n * @private\n */\n defaultTexture: {\n get: function () {\n return this._defaultTexture;\n },\n },\n\n /**\n * The underlying texture used for picking. The texels are accessed by\n * batch ID, and the value is the pick color.\n *\n * @memberof BatchTexture.prototype\n * @type {Texture}\n * @readonly\n * @private\n */\n pickTexture: {\n get: function () {\n return this._pickTexture;\n },\n },\n});\n\nBatchTexture.DEFAULT_COLOR_VALUE = Color.WHITE;\nBatchTexture.DEFAULT_SHOW_VALUE = true;\n\nfunction getByteLength(batchTexture) {\n const dimensions = batchTexture._textureDimensions;\n return dimensions.x * dimensions.y * 4;\n}\n\nfunction getBatchValues(batchTexture) {\n if (!defined(batchTexture._batchValues)) {\n // Default batch texture to RGBA = 255: white highlight (RGB) and show/alpha = true/255 (A).\n const byteLength = getByteLength(batchTexture);\n const bytes = new Uint8Array(byteLength).fill(255);\n batchTexture._batchValues = bytes;\n }\n\n return batchTexture._batchValues;\n}\n\nfunction getShowAlphaProperties(batchTexture) {\n if (!defined(batchTexture._showAlphaProperties)) {\n const byteLength = 2 * batchTexture._featuresLength;\n const bytes = new Uint8Array(byteLength).fill(255);\n // [Show = true, Alpha = 255]\n batchTexture._showAlphaProperties = bytes;\n }\n return batchTexture._showAlphaProperties;\n}\n\nfunction checkBatchId(batchId, featuresLength) {\n if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {\n throw new DeveloperError(\n `batchId is required and between zero and featuresLength - 1 (${featuresLength}` -\n +\").\"\n );\n }\n}\n\n/**\n * Set whether a feature is visible.\n *\n * @param {number} batchId the ID of the feature\n * @param {boolean} show true if the feature should be shown, false otherwise\n * @private\n */\nBatchTexture.prototype.setShow = function (batchId, show) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this._featuresLength);\n Check.typeOf.bool(\"show\", show);\n //>>includeEnd('debug');\n\n if (show && !defined(this._showAlphaProperties)) {\n // Avoid allocating since the default is show = true\n return;\n }\n\n const showAlphaProperties = getShowAlphaProperties(this);\n const propertyOffset = batchId * 2;\n\n const newShow = show ? 255 : 0;\n if (showAlphaProperties[propertyOffset] !== newShow) {\n showAlphaProperties[propertyOffset] = newShow;\n\n const batchValues = getBatchValues(this);\n\n // Compute alpha used in the shader based on show and color.alpha properties\n const offset = batchId * 4 + 3;\n batchValues[offset] = show ? showAlphaProperties[propertyOffset + 1] : 0;\n\n this._batchValuesDirty = true;\n }\n};\n\n/**\n * Set the show for all features at once.\n *\n * @param {boolean} show true if the feature should be shown, false otherwise\n * @private\n */\nBatchTexture.prototype.setAllShow = function (show) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"show\", show);\n //>>includeEnd('debug');\n\n const featuresLength = this._featuresLength;\n for (let i = 0; i < featuresLength; ++i) {\n this.setShow(i, show);\n }\n};\n\n/**\n * Check the current show value for a feature\n *\n * @param {number} batchId the ID of the feature\n * @return {boolean} true if the feature is shown, or false otherwise\n * @private\n */\nBatchTexture.prototype.getShow = function (batchId) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this._featuresLength);\n //>>includeEnd('debug');\n\n if (!defined(this._showAlphaProperties)) {\n // Avoid allocating since the default is show = true\n return true;\n }\n\n const offset = batchId * 2;\n return this._showAlphaProperties[offset] === 255;\n};\n\nconst scratchColorBytes = new Array(4);\n\n/**\n * Set the styling color of a feature\n *\n * @param {number} batchId the ID of the feature\n * @param {Color} color the color to assign to this feature.\n *\n * @private\n */\nBatchTexture.prototype.setColor = function (batchId, color) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this._featuresLength);\n Check.typeOf.object(\"color\", color);\n //>>includeEnd('debug');\n\n if (\n Color.equals(color, BatchTexture.DEFAULT_COLOR_VALUE) &&\n !defined(this._batchValues)\n ) {\n // Avoid allocating since the default is white\n return;\n }\n\n const newColor = color.toBytes(scratchColorBytes);\n const newAlpha = newColor[3];\n\n const batchValues = getBatchValues(this);\n const offset = batchId * 4;\n\n const showAlphaProperties = getShowAlphaProperties(this);\n const propertyOffset = batchId * 2;\n\n if (\n batchValues[offset] !== newColor[0] ||\n batchValues[offset + 1] !== newColor[1] ||\n batchValues[offset + 2] !== newColor[2] ||\n showAlphaProperties[propertyOffset + 1] !== newAlpha\n ) {\n batchValues[offset] = newColor[0];\n batchValues[offset + 1] = newColor[1];\n batchValues[offset + 2] = newColor[2];\n\n const wasTranslucent = showAlphaProperties[propertyOffset + 1] !== 255;\n\n // Compute alpha used in the shader based on show and color.alpha properties\n const show = showAlphaProperties[propertyOffset] !== 0;\n batchValues[offset + 3] = show ? newAlpha : 0;\n showAlphaProperties[propertyOffset + 1] = newAlpha;\n\n // Track number of translucent features so we know if this tile needs\n // opaque commands, translucent commands, or both for rendering.\n const isTranslucent = newAlpha !== 255;\n if (isTranslucent && !wasTranslucent) {\n ++this._translucentFeaturesLength;\n } else if (!isTranslucent && wasTranslucent) {\n --this._translucentFeaturesLength;\n }\n\n this._batchValuesDirty = true;\n\n if (defined(this._colorChangedCallback)) {\n this._colorChangedCallback(batchId, color);\n }\n }\n};\n\n/**\n * Set the styling color for all features at once\n *\n * @param {Color} color the color to assign to all features.\n *\n * @private\n */\nBatchTexture.prototype.setAllColor = function (color) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"color\", color);\n //>>includeEnd('debug');\n\n const featuresLength = this._featuresLength;\n for (let i = 0; i < featuresLength; ++i) {\n this.setColor(i, color);\n }\n};\n\n/**\n * Get the current color of a feature\n *\n * @param {number} batchId The ID of the feature\n * @param {Color} result A color object where the result will be stored.\n * @return {Color} The color assigned to the selected feature\n *\n * @private\n */\nBatchTexture.prototype.getColor = function (batchId, result) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this._featuresLength);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n if (!defined(this._batchValues)) {\n return Color.clone(BatchTexture.DEFAULT_COLOR_VALUE, result);\n }\n\n const batchValues = this._batchValues;\n const offset = batchId * 4;\n\n const showAlphaProperties = this._showAlphaProperties;\n const propertyOffset = batchId * 2;\n\n return Color.fromBytes(\n batchValues[offset],\n batchValues[offset + 1],\n batchValues[offset + 2],\n showAlphaProperties[propertyOffset + 1],\n result\n );\n};\n\n/**\n * Get the pick color of a feature. This feature is an RGBA encoding of the\n * pick ID.\n *\n * @param {number} batchId The ID of the feature\n * @return {PickId} The picking color assigned to this feature\n *\n * @private\n */\nBatchTexture.prototype.getPickColor = function (batchId) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this._featuresLength);\n //>>includeEnd('debug');\n return this._pickIds[batchId];\n};\n\nfunction createTexture(batchTexture, context, bytes) {\n const dimensions = batchTexture._textureDimensions;\n return new Texture({\n context: context,\n pixelFormat: PixelFormat.RGBA,\n pixelDatatype: PixelDatatype.UNSIGNED_BYTE,\n source: {\n width: dimensions.x,\n height: dimensions.y,\n arrayBufferView: bytes,\n },\n flipY: false,\n sampler: Sampler.NEAREST,\n });\n}\n\nfunction createPickTexture(batchTexture, context) {\n const featuresLength = batchTexture._featuresLength;\n if (!defined(batchTexture._pickTexture) && featuresLength > 0) {\n const pickIds = batchTexture._pickIds;\n const byteLength = getByteLength(batchTexture);\n const bytes = new Uint8Array(byteLength);\n const owner = batchTexture._owner;\n const statistics = batchTexture._statistics;\n\n // PERFORMANCE_IDEA: we could skip the pick texture completely by allocating\n // a continuous range of pickIds and then converting the base pickId + batchId\n // to RGBA in the shader. The only consider is precision issues, which might\n // not be an issue in WebGL 2.\n for (let i = 0; i < featuresLength; ++i) {\n const pickId = context.createPickId(owner.getFeature(i));\n pickIds.push(pickId);\n\n const pickColor = pickId.color;\n const offset = i * 4;\n bytes[offset] = Color.floatToByte(pickColor.red);\n bytes[offset + 1] = Color.floatToByte(pickColor.green);\n bytes[offset + 2] = Color.floatToByte(pickColor.blue);\n bytes[offset + 3] = Color.floatToByte(pickColor.alpha);\n }\n\n batchTexture._pickTexture = createTexture(batchTexture, context, bytes);\n\n // Make sure the tileset statistics are updated the frame when the pick\n // texture is created.\n if (defined(statistics)) {\n statistics.batchTableByteLength += batchTexture._pickTexture.sizeInBytes;\n }\n }\n}\n\nfunction updateBatchTexture(batchTexture) {\n const dimensions = batchTexture._textureDimensions;\n // PERFORMANCE_IDEA: Instead of rewriting the entire texture, use fine-grained\n // texture updates when less than, for example, 10%, of the values changed. Or\n // even just optimize the common case when one feature show/color changed.\n batchTexture._batchTexture.copyFrom({\n source: {\n width: dimensions.x,\n height: dimensions.y,\n arrayBufferView: batchTexture._batchValues,\n },\n });\n}\n\nBatchTexture.prototype.update = function (tileset, frameState) {\n const context = frameState.context;\n this._defaultTexture = context.defaultTexture;\n\n const passes = frameState.passes;\n if (passes.pick || passes.postProcess) {\n createPickTexture(this, context);\n }\n\n if (this._batchValuesDirty) {\n this._batchValuesDirty = false;\n\n // Create batch texture on-demand\n if (!defined(this._batchTexture)) {\n this._batchTexture = createTexture(this, context, this._batchValues);\n\n // Make sure the tileset statistics are updated the frame when the\n // batch texture is created.\n if (defined(this._statistics)) {\n this._statistics.batchTableByteLength += this._batchTexture.sizeInBytes;\n }\n }\n\n updateBatchTexture(this); // Apply per-feature show/color updates\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see BatchTexture#destroy\n * @private\n */\nBatchTexture.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * e = e && e.destroy();\n *\n * @see BatchTexture#isDestroyed\n * @private\n */\nBatchTexture.prototype.destroy = function () {\n this._batchTexture = this._batchTexture && this._batchTexture.destroy();\n this._pickTexture = this._pickTexture && this._pickTexture.destroy();\n\n const pickIds = this._pickIds;\n const length = pickIds.length;\n for (let i = 0; i < length; ++i) {\n pickIds[i].destroy();\n }\n\n return destroyObject(this);\n};\n\nexport default BatchTexture;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\n\nconst ComponentsPerAttribute = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16,\n};\n\nconst ClassPerType = {\n SCALAR: undefined,\n VEC2: Cartesian2,\n VEC3: Cartesian3,\n VEC4: Cartesian4,\n MAT2: Matrix2,\n MAT3: Matrix3,\n MAT4: Matrix4,\n};\n\n/**\n * @private\n */\nfunction getBinaryAccessor(accessor) {\n const componentType = accessor.componentType;\n let componentDatatype;\n if (typeof componentType === \"string\") {\n componentDatatype = ComponentDatatype.fromName(componentType);\n } else {\n componentDatatype = componentType;\n }\n\n const componentsPerAttribute = ComponentsPerAttribute[accessor.type];\n const classType = ClassPerType[accessor.type];\n return {\n componentsPerAttribute: componentsPerAttribute,\n classType: classType,\n createArrayBufferView: function (buffer, byteOffset, length) {\n return ComponentDatatype.createArrayBufferView(\n componentDatatype,\n buffer,\n byteOffset,\n componentsPerAttribute * length\n );\n },\n };\n}\nexport default getBinaryAccessor;\n", "import AttributeType from \"./AttributeType.js\";\nimport Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport combine from \"../Core/combine.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport getBinaryAccessor from \"./getBinaryAccessor.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * Object for handling the 3DTILES_batch_table_hierarchy extension\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.extension The 3DTILES_batch_table_hierarchy extension object.\n * @param {Uint8Array} [options.binaryBody] The binary body of the batch table\n *\n * @alias BatchTableHierarchy\n * @constructor\n *\n * @private\n */\nfunction BatchTableHierarchy(options) {\n this._classes = undefined;\n this._classIds = undefined;\n this._classIndexes = undefined;\n this._parentCounts = undefined;\n this._parentIndexes = undefined;\n this._parentIds = undefined;\n\n // Total memory used by the typed arrays\n this._byteLength = 0;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.extension\", options.extension);\n //>>includeEnd('debug');\n\n initialize(this, options.extension, options.binaryBody);\n\n //>>includeStart('debug', pragmas.debug);\n validateHierarchy(this);\n //>>includeEnd('debug');\n}\n\nObject.defineProperties(BatchTableHierarchy.prototype, {\n byteLength: {\n get: function () {\n return this._byteLength;\n },\n },\n});\n\n/**\n * Parse the batch table hierarchy from the\n * 3DTILES_batch_table_hierarchy extension.\n *\n * @param {BatchTableHierarchy} hierarchy The hierarchy instance\n * @param {object} hierarchyJson The JSON of the extension\n * @param {Uint8Array} [binaryBody] The binary body of the batch table for accessing binary properties\n * @private\n */\nfunction initialize(hierarchy, hierarchyJson, binaryBody) {\n let i;\n let classId;\n let binaryAccessor;\n\n const instancesLength = hierarchyJson.instancesLength;\n const classes = hierarchyJson.classes;\n let classIds = hierarchyJson.classIds;\n let parentCounts = hierarchyJson.parentCounts;\n let parentIds = hierarchyJson.parentIds;\n let parentIdsLength = instancesLength;\n let byteLength = 0;\n\n if (defined(classIds.byteOffset)) {\n classIds.componentType = defaultValue(\n classIds.componentType,\n ComponentDatatype.UNSIGNED_SHORT\n );\n classIds.type = AttributeType.SCALAR;\n binaryAccessor = getBinaryAccessor(classIds);\n classIds = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + classIds.byteOffset,\n instancesLength\n );\n byteLength += classIds.byteLength;\n }\n\n let parentIndexes;\n if (defined(parentCounts)) {\n if (defined(parentCounts.byteOffset)) {\n parentCounts.componentType = defaultValue(\n parentCounts.componentType,\n ComponentDatatype.UNSIGNED_SHORT\n );\n parentCounts.type = AttributeType.SCALAR;\n binaryAccessor = getBinaryAccessor(parentCounts);\n parentCounts = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + parentCounts.byteOffset,\n instancesLength\n );\n byteLength += parentCounts.byteLength;\n }\n parentIndexes = new Uint16Array(instancesLength);\n parentIdsLength = 0;\n for (i = 0; i < instancesLength; ++i) {\n parentIndexes[i] = parentIdsLength;\n parentIdsLength += parentCounts[i];\n }\n\n byteLength += parentIndexes.byteLength;\n }\n\n if (defined(parentIds) && defined(parentIds.byteOffset)) {\n parentIds.componentType = defaultValue(\n parentIds.componentType,\n ComponentDatatype.UNSIGNED_SHORT\n );\n parentIds.type = AttributeType.SCALAR;\n binaryAccessor = getBinaryAccessor(parentIds);\n parentIds = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + parentIds.byteOffset,\n parentIdsLength\n );\n\n byteLength += parentIds.byteLength;\n }\n\n const classesLength = classes.length;\n for (i = 0; i < classesLength; ++i) {\n const classInstancesLength = classes[i].length;\n const properties = classes[i].instances;\n const binaryProperties = getBinaryProperties(\n classInstancesLength,\n properties,\n binaryBody\n );\n byteLength += countBinaryPropertyMemory(binaryProperties);\n classes[i].instances = combine(binaryProperties, properties);\n }\n\n const classCounts = new Array(classesLength).fill(0);\n const classIndexes = new Uint16Array(instancesLength);\n for (i = 0; i < instancesLength; ++i) {\n classId = classIds[i];\n classIndexes[i] = classCounts[classId];\n ++classCounts[classId];\n }\n byteLength += classIndexes.byteLength;\n\n hierarchy._classes = classes;\n hierarchy._classIds = classIds;\n hierarchy._classIndexes = classIndexes;\n hierarchy._parentCounts = parentCounts;\n hierarchy._parentIndexes = parentIndexes;\n hierarchy._parentIds = parentIds;\n hierarchy._byteLength = byteLength;\n}\n\nfunction getBinaryProperties(featuresLength, properties, binaryBody) {\n let binaryProperties;\n for (const name in properties) {\n if (properties.hasOwnProperty(name)) {\n const property = properties[name];\n const byteOffset = property.byteOffset;\n if (defined(byteOffset)) {\n // This is a binary property\n const componentType = property.componentType;\n const type = property.type;\n if (!defined(componentType)) {\n throw new RuntimeError(\"componentType is required.\");\n }\n if (!defined(type)) {\n throw new RuntimeError(\"type is required.\");\n }\n if (!defined(binaryBody)) {\n throw new RuntimeError(\n `Property ${name} requires a batch table binary.`\n );\n }\n\n const binaryAccessor = getBinaryAccessor(property);\n const componentCount = binaryAccessor.componentsPerAttribute;\n const classType = binaryAccessor.classType;\n const typedArray = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + byteOffset,\n featuresLength\n );\n\n if (!defined(binaryProperties)) {\n binaryProperties = {};\n }\n\n // Store any information needed to access the binary data, including the typed array,\n // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).\n binaryProperties[name] = {\n typedArray: typedArray,\n componentCount: componentCount,\n type: classType,\n };\n }\n }\n }\n return binaryProperties;\n}\n\nfunction countBinaryPropertyMemory(binaryProperties) {\n let byteLength = 0;\n for (const name in binaryProperties) {\n if (binaryProperties.hasOwnProperty(name)) {\n byteLength += binaryProperties[name].typedArray.byteLength;\n }\n }\n return byteLength;\n}\n\n//>>includeStart('debug', pragmas.debug);\nconst scratchValidateStack = [];\nfunction validateHierarchy(hierarchy) {\n const stack = scratchValidateStack;\n stack.length = 0;\n\n const classIds = hierarchy._classIds;\n const instancesLength = classIds.length;\n\n for (let i = 0; i < instancesLength; ++i) {\n validateInstance(hierarchy, i, stack);\n }\n}\n\nfunction validateInstance(hierarchy, instanceIndex, stack) {\n const parentCounts = hierarchy._parentCounts;\n const parentIds = hierarchy._parentIds;\n const parentIndexes = hierarchy._parentIndexes;\n const classIds = hierarchy._classIds;\n const instancesLength = classIds.length;\n\n if (!defined(parentIds)) {\n // No need to validate if there are no parents\n return;\n }\n\n if (instanceIndex >= instancesLength) {\n throw new DeveloperError(\n `Parent index ${instanceIndex} exceeds the total number of instances: ${instancesLength}`\n );\n }\n if (stack.indexOf(instanceIndex) > -1) {\n throw new DeveloperError(\n \"Circular dependency detected in the batch table hierarchy.\"\n );\n }\n\n stack.push(instanceIndex);\n const parentCount = defined(parentCounts) ? parentCounts[instanceIndex] : 1;\n const parentIndex = defined(parentCounts)\n ? parentIndexes[instanceIndex]\n : instanceIndex;\n for (let i = 0; i < parentCount; ++i) {\n const parentId = parentIds[parentIndex + i];\n // Stop the traversal when the instance has no parent (its parentId equals itself), else continue the traversal.\n if (parentId !== instanceIndex) {\n validateInstance(hierarchy, parentId, stack);\n }\n }\n stack.pop(instanceIndex);\n}\n//>>includeEnd('debug');\n\n// The size of this array equals the maximum instance count among all loaded tiles, which has the potential to be large.\nconst scratchVisited = [];\nconst scratchStack = [];\nlet marker = 0;\nfunction traverseHierarchyMultipleParents(\n hierarchy,\n instanceIndex,\n endConditionCallback\n) {\n const classIds = hierarchy._classIds;\n const parentCounts = hierarchy._parentCounts;\n const parentIds = hierarchy._parentIds;\n const parentIndexes = hierarchy._parentIndexes;\n const instancesLength = classIds.length;\n\n // Ignore instances that have already been visited. This occurs in diamond inheritance situations.\n // Use a marker value to indicate that an instance has been visited, which increments with each run.\n // This is more efficient than clearing the visited array every time.\n const visited = scratchVisited;\n visited.length = Math.max(visited.length, instancesLength);\n const visitedMarker = ++marker;\n\n const stack = scratchStack;\n stack.length = 0;\n stack.push(instanceIndex);\n\n while (stack.length > 0) {\n instanceIndex = stack.pop();\n if (visited[instanceIndex] === visitedMarker) {\n // This instance has already been visited, stop traversal\n continue;\n }\n visited[instanceIndex] = visitedMarker;\n const result = endConditionCallback(hierarchy, instanceIndex);\n if (defined(result)) {\n // The end condition was met, stop the traversal and return the result\n return result;\n }\n const parentCount = parentCounts[instanceIndex];\n const parentIndex = parentIndexes[instanceIndex];\n for (let i = 0; i < parentCount; ++i) {\n const parentId = parentIds[parentIndex + i];\n // Stop the traversal when the instance has no parent (its parentId equals itself)\n // else add the parent to the stack to continue the traversal.\n if (parentId !== instanceIndex) {\n stack.push(parentId);\n }\n }\n }\n}\n\nfunction traverseHierarchySingleParent(\n hierarchy,\n instanceIndex,\n endConditionCallback\n) {\n let hasParent = true;\n while (hasParent) {\n const result = endConditionCallback(hierarchy, instanceIndex);\n if (defined(result)) {\n // The end condition was met, stop the traversal and return the result\n return result;\n }\n const parentId = hierarchy._parentIds[instanceIndex];\n hasParent = parentId !== instanceIndex;\n instanceIndex = parentId;\n }\n}\n\nfunction traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {\n // Traverse over the hierarchy and process each instance with the endConditionCallback.\n // When the endConditionCallback returns a value, the traversal stops and that value is returned.\n const parentCounts = hierarchy._parentCounts;\n const parentIds = hierarchy._parentIds;\n if (!defined(parentIds)) {\n return endConditionCallback(hierarchy, instanceIndex);\n } else if (defined(parentCounts)) {\n return traverseHierarchyMultipleParents(\n hierarchy,\n instanceIndex,\n endConditionCallback\n );\n }\n return traverseHierarchySingleParent(\n hierarchy,\n instanceIndex,\n endConditionCallback\n );\n}\n\n/**\n * Returns whether the feature has this property.\n *\n * @param {number} batchId the batch ID of the feature\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the feature has this property.\n * @private\n */\nBatchTableHierarchy.prototype.hasProperty = function (batchId, propertyId) {\n const result = traverseHierarchy(this, batchId, function (\n hierarchy,\n instanceIndex\n ) {\n const classId = hierarchy._classIds[instanceIndex];\n const instances = hierarchy._classes[classId].instances;\n if (defined(instances[propertyId])) {\n return true;\n }\n });\n return defined(result);\n};\n\n/**\n * Returns whether any feature has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether any feature has this property.\n * @private\n */\nBatchTableHierarchy.prototype.propertyExists = function (propertyId) {\n const classes = this._classes;\n const classesLength = classes.length;\n for (let i = 0; i < classesLength; ++i) {\n const instances = classes[i].instances;\n if (defined(instances[propertyId])) {\n return true;\n }\n }\n return false;\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {number} batchId the batch ID of the feature\n * @param {number} index The index of the entity.\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nBatchTableHierarchy.prototype.getPropertyIds = function (batchId, results) {\n results = defined(results) ? results : [];\n results.length = 0;\n\n traverseHierarchy(this, batchId, function (hierarchy, instanceIndex) {\n const classId = hierarchy._classIds[instanceIndex];\n const instances = hierarchy._classes[classId].instances;\n for (const name in instances) {\n if (instances.hasOwnProperty(name)) {\n if (results.indexOf(name) === -1) {\n results.push(name);\n }\n }\n }\n });\n\n return results;\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *\n * @param {number} batchId the batch ID of the feature\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n * @private\n */\nBatchTableHierarchy.prototype.getProperty = function (batchId, propertyId) {\n return traverseHierarchy(this, batchId, function (hierarchy, instanceIndex) {\n const classId = hierarchy._classIds[instanceIndex];\n const instanceClass = hierarchy._classes[classId];\n const indexInClass = hierarchy._classIndexes[instanceIndex];\n const propertyValues = instanceClass.instances[propertyId];\n if (defined(propertyValues)) {\n if (defined(propertyValues.typedArray)) {\n return getBinaryProperty(propertyValues, indexInClass);\n }\n return clone(propertyValues[indexInClass], true);\n }\n });\n};\n\nfunction getBinaryProperty(binaryProperty, index) {\n const typedArray = binaryProperty.typedArray;\n const componentCount = binaryProperty.componentCount;\n if (componentCount === 1) {\n return typedArray[index];\n }\n return binaryProperty.type.unpack(typedArray, index * componentCount);\n}\n\n/**\n * Sets the value of the property with the given ID. Only properties of the\n * instance may be set; parent properties may not be set.\n *\n * @param {number} batchId The batchId of the feature\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n *\n * @exception {DeveloperError} when setting an inherited property\n * @private\n */\nBatchTableHierarchy.prototype.setProperty = function (\n batchId,\n propertyId,\n value\n) {\n const result = traverseHierarchy(this, batchId, function (\n hierarchy,\n instanceIndex\n ) {\n const classId = hierarchy._classIds[instanceIndex];\n const instanceClass = hierarchy._classes[classId];\n const indexInClass = hierarchy._classIndexes[instanceIndex];\n const propertyValues = instanceClass.instances[propertyId];\n if (defined(propertyValues)) {\n //>>includeStart('debug', pragmas.debug);\n if (instanceIndex !== batchId) {\n throw new DeveloperError(\n `Inherited property \"${propertyId}\" is read-only.`\n );\n }\n //>>includeEnd('debug');\n if (defined(propertyValues.typedArray)) {\n setBinaryProperty(propertyValues, indexInClass, value);\n } else {\n propertyValues[indexInClass] = clone(value, true);\n }\n return true;\n }\n });\n return defined(result);\n};\n\nfunction setBinaryProperty(binaryProperty, index, value) {\n const typedArray = binaryProperty.typedArray;\n const componentCount = binaryProperty.componentCount;\n if (componentCount === 1) {\n typedArray[index] = value;\n } else {\n binaryProperty.type.pack(value, typedArray, index * componentCount);\n }\n}\n\n/**\n * Check if a feature belongs to a class with the given name\n *\n * @param {number} batchId The batch ID of the feature\n * @param {string} className The name of the class\n * @return {boolean} true if the feature belongs to the class given by className, or false otherwise\n * @private\n */\nBatchTableHierarchy.prototype.isClass = function (batchId, className) {\n // PERFORMANCE_IDEA : cache results in the ancestor classes to speed up this check if this area becomes a hotspot\n // PERFORMANCE_IDEA : treat class names as integers for faster comparisons\n const result = traverseHierarchy(this, batchId, function (\n hierarchy,\n instanceIndex\n ) {\n const classId = hierarchy._classIds[instanceIndex];\n const instanceClass = hierarchy._classes[classId];\n if (instanceClass.name === className) {\n return true;\n }\n });\n return defined(result);\n};\n\n/**\n * Get the name of the class a given feature belongs to\n *\n * @param {number} batchId The batch ID of the feature\n * @return {string} The name of the class this feature belongs to\n */\nBatchTableHierarchy.prototype.getClassName = function (batchId) {\n const classId = this._classIds[batchId];\n const instanceClass = this._classes[classId];\n return instanceClass.name;\n};\n\nexport default BatchTableHierarchy;\n", "/**\n * Defines how per-feature colors set from the Cesium API or declarative styling blend with the source colors from\n * the original feature, e.g. glTF material or per-point color in the tile.\n *

\n * When REPLACE or MIX are used and the source color is a glTF material, the technique must assign the\n * _3DTILESDIFFUSE semantic to the diffuse color parameter. Otherwise only HIGHLIGHT is supported.\n *

\n *

\n * A feature whose color evaluates to white (1.0, 1.0, 1.0) is always rendered without color blending, regardless of the\n * tileset's color blend mode.\n *

\n *
\n * \"techniques\": {\n *   \"technique0\": {\n *     \"parameters\": {\n *       \"diffuse\": {\n *         \"semantic\": \"_3DTILESDIFFUSE\",\n *         \"type\": 35666\n *       }\n *     }\n *   }\n * }\n * 
\n *\n * @enum {number}\n */\nconst Cesium3DTileColorBlendMode = {\n /**\n * Multiplies the source color by the feature color.\n *\n * @type {number}\n * @constant\n */\n HIGHLIGHT: 0,\n\n /**\n * Replaces the source color with the feature color.\n *\n * @type {number}\n * @constant\n */\n REPLACE: 1,\n\n /**\n * Blends the source color and feature color together.\n *\n * @type {number}\n * @constant\n */\n MIX: 2,\n};\nexport default Object.freeze(Cesium3DTileColorBlendMode);\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport Color from \"../Core/Color.js\";\nimport combine from \"../Core/combine.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport BatchTexture from \"./BatchTexture.js\";\nimport BatchTableHierarchy from \"./BatchTableHierarchy.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport Cesium3DTileColorBlendMode from \"./Cesium3DTileColorBlendMode.js\";\nimport CullFace from \"./CullFace.js\";\nimport getBinaryAccessor from \"./getBinaryAccessor.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\n\nconst DEFAULT_COLOR_VALUE = BatchTexture.DEFAULT_COLOR_VALUE;\nconst DEFAULT_SHOW_VALUE = BatchTexture.DEFAULT_SHOW_VALUE;\n\n/**\n * @private\n * @constructor\n */\nfunction Cesium3DTileBatchTable(\n content,\n featuresLength,\n batchTableJson,\n batchTableBinary,\n colorChangedCallback\n) {\n /**\n * @readonly\n */\n this.featuresLength = featuresLength;\n\n let extensions;\n if (defined(batchTableJson)) {\n extensions = batchTableJson.extensions;\n }\n this._extensions = defaultValue(extensions, {});\n\n const properties = initializeProperties(batchTableJson);\n this._properties = properties;\n\n this._batchTableHierarchy = initializeHierarchy(\n this,\n batchTableJson,\n batchTableBinary\n );\n\n const binaryProperties = getBinaryProperties(\n featuresLength,\n properties,\n batchTableBinary\n );\n this._binaryPropertiesByteLength = countBinaryPropertyMemory(\n binaryProperties\n );\n this._batchTableBinaryProperties = binaryProperties;\n\n this._content = content;\n\n this._batchTexture = new BatchTexture({\n featuresLength: featuresLength,\n colorChangedCallback: colorChangedCallback,\n owner: content,\n statistics: content.tileset.statistics,\n });\n}\n\n// This can be overridden for testing purposes\nCesium3DTileBatchTable._deprecationWarning = deprecationWarning;\n\nObject.defineProperties(Cesium3DTileBatchTable.prototype, {\n /**\n * Size of the batch table, including the batch table hierarchy's binary\n * buffers and any binary properties. JSON data is not counted.\n *\n * @memberof Cesium3DTileBatchTable.prototype\n * @type {number}\n * @readonly\n * @private\n */\n batchTableByteLength: {\n get: function () {\n let totalByteLength = this._binaryPropertiesByteLength;\n\n if (defined(this._batchTableHierarchy)) {\n totalByteLength += this._batchTableHierarchy.byteLength;\n }\n\n totalByteLength += this._batchTexture.byteLength;\n\n return totalByteLength;\n },\n },\n});\n\nfunction initializeProperties(jsonHeader) {\n const properties = {};\n\n if (!defined(jsonHeader)) {\n return properties;\n }\n\n for (const propertyName in jsonHeader) {\n if (\n jsonHeader.hasOwnProperty(propertyName) &&\n propertyName !== \"HIERARCHY\" && // Deprecated HIERARCHY property\n propertyName !== \"extensions\" &&\n propertyName !== \"extras\"\n ) {\n properties[propertyName] = clone(jsonHeader[propertyName], true);\n }\n }\n\n return properties;\n}\n\nfunction initializeHierarchy(batchTable, jsonHeader, binaryBody) {\n if (!defined(jsonHeader)) {\n return;\n }\n\n let hierarchy = batchTable._extensions[\"3DTILES_batch_table_hierarchy\"];\n\n const legacyHierarchy = jsonHeader.HIERARCHY;\n if (defined(legacyHierarchy)) {\n Cesium3DTileBatchTable._deprecationWarning(\n \"batchTableHierarchyExtension\",\n \"The batch table HIERARCHY property has been moved to an extension. Use extensions.3DTILES_batch_table_hierarchy instead.\"\n );\n batchTable._extensions[\"3DTILES_batch_table_hierarchy\"] = legacyHierarchy;\n hierarchy = legacyHierarchy;\n }\n\n if (!defined(hierarchy)) {\n return;\n }\n\n return new BatchTableHierarchy({\n extension: hierarchy,\n binaryBody: binaryBody,\n });\n}\n\nfunction getBinaryProperties(featuresLength, properties, binaryBody) {\n let binaryProperties;\n for (const name in properties) {\n if (properties.hasOwnProperty(name)) {\n const property = properties[name];\n const byteOffset = property.byteOffset;\n if (defined(byteOffset)) {\n // This is a binary property\n const componentType = property.componentType;\n const type = property.type;\n if (!defined(componentType)) {\n throw new RuntimeError(\"componentType is required.\");\n }\n if (!defined(type)) {\n throw new RuntimeError(\"type is required.\");\n }\n if (!defined(binaryBody)) {\n throw new RuntimeError(\n `Property ${name} requires a batch table binary.`\n );\n }\n\n const binaryAccessor = getBinaryAccessor(property);\n const componentCount = binaryAccessor.componentsPerAttribute;\n const classType = binaryAccessor.classType;\n const typedArray = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + byteOffset,\n featuresLength\n );\n\n if (!defined(binaryProperties)) {\n binaryProperties = {};\n }\n\n // Store any information needed to access the binary data, including the typed array,\n // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).\n binaryProperties[name] = {\n typedArray: typedArray,\n componentCount: componentCount,\n type: classType,\n };\n }\n }\n }\n return binaryProperties;\n}\n\nfunction countBinaryPropertyMemory(binaryProperties) {\n if (!defined(binaryProperties)) {\n return 0;\n }\n\n let byteLength = 0;\n for (const name in binaryProperties) {\n if (binaryProperties.hasOwnProperty(name)) {\n byteLength += binaryProperties[name].typedArray.byteLength;\n }\n }\n return byteLength;\n}\n\nCesium3DTileBatchTable.getBinaryProperties = function (\n featuresLength,\n batchTableJson,\n batchTableBinary\n) {\n return getBinaryProperties(featuresLength, batchTableJson, batchTableBinary);\n};\n\nCesium3DTileBatchTable.prototype.setShow = function (batchId, show) {\n this._batchTexture.setShow(batchId, show);\n};\n\nCesium3DTileBatchTable.prototype.setAllShow = function (show) {\n this._batchTexture.setAllShow(show);\n};\n\nCesium3DTileBatchTable.prototype.getShow = function (batchId) {\n return this._batchTexture.getShow(batchId);\n};\n\nCesium3DTileBatchTable.prototype.setColor = function (batchId, color) {\n this._batchTexture.setColor(batchId, color);\n};\n\nCesium3DTileBatchTable.prototype.setAllColor = function (color) {\n this._batchTexture.setAllColor(color);\n};\n\nCesium3DTileBatchTable.prototype.getColor = function (batchId, result) {\n return this._batchTexture.getColor(batchId, result);\n};\n\nCesium3DTileBatchTable.prototype.getPickColor = function (batchId) {\n return this._batchTexture.getPickColor(batchId);\n};\n\nconst scratchColor = new Color();\n\nCesium3DTileBatchTable.prototype.applyStyle = function (style) {\n if (!defined(style)) {\n this.setAllColor(DEFAULT_COLOR_VALUE);\n this.setAllShow(DEFAULT_SHOW_VALUE);\n return;\n }\n\n const content = this._content;\n const length = this.featuresLength;\n for (let i = 0; i < length; ++i) {\n const feature = content.getFeature(i);\n const color = defined(style.color)\n ? defaultValue(\n style.color.evaluateColor(feature, scratchColor),\n DEFAULT_COLOR_VALUE\n )\n : DEFAULT_COLOR_VALUE;\n const show = defined(style.show)\n ? defaultValue(style.show.evaluate(feature), DEFAULT_SHOW_VALUE)\n : DEFAULT_SHOW_VALUE;\n this.setColor(i, color);\n this.setShow(i, show);\n }\n};\n\nfunction getBinaryProperty(binaryProperty, index) {\n const typedArray = binaryProperty.typedArray;\n const componentCount = binaryProperty.componentCount;\n if (componentCount === 1) {\n return typedArray[index];\n }\n return binaryProperty.type.unpack(typedArray, index * componentCount);\n}\n\nfunction setBinaryProperty(binaryProperty, index, value) {\n const typedArray = binaryProperty.typedArray;\n const componentCount = binaryProperty.componentCount;\n if (componentCount === 1) {\n typedArray[index] = value;\n } else {\n binaryProperty.type.pack(value, typedArray, index * componentCount);\n }\n}\n\nfunction checkBatchId(batchId, featuresLength) {\n if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {\n throw new DeveloperError(\n `batchId is required and must be between zero and featuresLength - 1 (${featuresLength}` -\n +\").\"\n );\n }\n}\n\nCesium3DTileBatchTable.prototype.isClass = function (batchId, className) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this.featuresLength);\n Check.typeOf.string(\"className\", className);\n //>>includeEnd('debug');\n\n const hierarchy = this._batchTableHierarchy;\n if (!defined(hierarchy)) {\n return false;\n }\n\n return hierarchy.isClass(batchId, className);\n};\n\nCesium3DTileBatchTable.prototype.isExactClass = function (batchId, className) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"className\", className);\n //>>includeEnd('debug');\n\n return this.getExactClassName(batchId) === className;\n};\n\nCesium3DTileBatchTable.prototype.getExactClassName = function (batchId) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this.featuresLength);\n //>>includeEnd('debug');\n\n const hierarchy = this._batchTableHierarchy;\n if (!defined(hierarchy)) {\n return undefined;\n }\n\n return hierarchy.getClassName(batchId);\n};\n\nCesium3DTileBatchTable.prototype.hasProperty = function (batchId, name) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this.featuresLength);\n Check.typeOf.string(\"name\", name);\n //>>includeEnd('debug');\n\n return (\n defined(this._properties[name]) ||\n (defined(this._batchTableHierarchy) &&\n this._batchTableHierarchy.hasProperty(batchId, name))\n );\n};\n\n/**\n * @private\n */\nCesium3DTileBatchTable.prototype.hasPropertyBySemantic = function () {\n // Cesium 3D Tiles 1.0 formats do not have semantics\n return false;\n};\n\nCesium3DTileBatchTable.prototype.getPropertyIds = function (batchId, results) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this.featuresLength);\n //>>includeEnd('debug');\n\n results = defined(results) ? results : [];\n results.length = 0;\n\n const scratchPropertyIds = Object.keys(this._properties);\n results.push.apply(results, scratchPropertyIds);\n\n if (defined(this._batchTableHierarchy)) {\n results.push.apply(\n results,\n this._batchTableHierarchy.getPropertyIds(batchId, scratchPropertyIds)\n );\n }\n\n return results;\n};\n\n/**\n * @private\n */\nCesium3DTileBatchTable.prototype.getPropertyBySemantic = function (\n batchId,\n name\n) {\n // Cesium 3D Tiles 1.0 formats do not have semantics\n return undefined;\n};\n\nCesium3DTileBatchTable.prototype.getProperty = function (batchId, name) {\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, this.featuresLength);\n Check.typeOf.string(\"name\", name);\n //>>includeEnd('debug');\n\n if (defined(this._batchTableBinaryProperties)) {\n const binaryProperty = this._batchTableBinaryProperties[name];\n if (defined(binaryProperty)) {\n return getBinaryProperty(binaryProperty, batchId);\n }\n }\n\n const propertyValues = this._properties[name];\n if (defined(propertyValues)) {\n return clone(propertyValues[batchId], true);\n }\n\n if (defined(this._batchTableHierarchy)) {\n const hierarchyProperty = this._batchTableHierarchy.getProperty(\n batchId,\n name\n );\n if (defined(hierarchyProperty)) {\n return hierarchyProperty;\n }\n }\n\n return undefined;\n};\n\nCesium3DTileBatchTable.prototype.setProperty = function (batchId, name, value) {\n const featuresLength = this.featuresLength;\n //>>includeStart('debug', pragmas.debug);\n checkBatchId(batchId, featuresLength);\n Check.typeOf.string(\"name\", name);\n //>>includeEnd('debug');\n\n if (defined(this._batchTableBinaryProperties)) {\n const binaryProperty = this._batchTableBinaryProperties[name];\n if (defined(binaryProperty)) {\n setBinaryProperty(binaryProperty, batchId, value);\n return;\n }\n }\n\n if (defined(this._batchTableHierarchy)) {\n if (this._batchTableHierarchy.setProperty(batchId, name, value)) {\n return;\n }\n }\n\n let propertyValues = this._properties[name];\n if (!defined(propertyValues)) {\n // Property does not exist. Create it.\n this._properties[name] = new Array(featuresLength);\n propertyValues = this._properties[name];\n }\n\n propertyValues[batchId] = clone(value, true);\n};\n\nfunction getGlslComputeSt(batchTable) {\n // GLSL batchId is zero-based: [0, featuresLength - 1]\n if (batchTable._batchTexture.textureDimensions.y === 1) {\n return (\n \"uniform vec4 tile_textureStep; \\n\" +\n \"vec2 computeSt(float batchId) \\n\" +\n \"{ \\n\" +\n \" float stepX = tile_textureStep.x; \\n\" +\n \" float centerX = tile_textureStep.y; \\n\" +\n \" return vec2(centerX + (batchId * stepX), 0.5); \\n\" +\n \"} \\n\"\n );\n }\n\n return (\n \"uniform vec4 tile_textureStep; \\n\" +\n \"uniform vec2 tile_textureDimensions; \\n\" +\n \"vec2 computeSt(float batchId) \\n\" +\n \"{ \\n\" +\n \" float stepX = tile_textureStep.x; \\n\" +\n \" float centerX = tile_textureStep.y; \\n\" +\n \" float stepY = tile_textureStep.z; \\n\" +\n \" float centerY = tile_textureStep.w; \\n\" +\n \" float xId = mod(batchId, tile_textureDimensions.x); \\n\" +\n \" float yId = floor(batchId / tile_textureDimensions.x); \\n\" +\n \" return vec2(centerX + (xId * stepX), centerY + (yId * stepY)); \\n\" +\n \"} \\n\"\n );\n}\n\nCesium3DTileBatchTable.prototype.getVertexShaderCallback = function (\n handleTranslucent,\n batchIdAttributeName,\n diffuseAttributeOrUniformName\n) {\n if (this.featuresLength === 0) {\n return;\n }\n\n const that = this;\n return function (source) {\n // If the color blend mode is HIGHLIGHT, the highlight color will always be applied in the fragment shader.\n // No need to apply the highlight color in the vertex shader as well.\n const renamedSource = modifyDiffuse(\n source,\n diffuseAttributeOrUniformName,\n false\n );\n let newMain;\n\n if (ContextLimits.maximumVertexTextureImageUnits > 0) {\n // When VTF is supported, perform per-feature show/hide in the vertex shader\n newMain = \"\";\n if (handleTranslucent) {\n newMain += \"uniform bool tile_translucentCommand; \\n\";\n }\n newMain +=\n `${\n \"uniform sampler2D tile_batchTexture; \\n\" +\n \"out vec4 tile_featureColor; \\n\" +\n \"out vec2 tile_featureSt; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" vec2 st = computeSt(\"\n }${batchIdAttributeName}); \\n` +\n ` vec4 featureProperties = texture(tile_batchTexture, st); \\n` +\n ` tile_color(featureProperties); \\n` +\n ` float show = ceil(featureProperties.a); \\n` + // 0 - false, non-zero - true\n ` gl_Position *= show; \\n`; // Per-feature show/hide\n if (handleTranslucent) {\n newMain +=\n \" bool isStyleTranslucent = (featureProperties.a != 1.0); \\n\" +\n \" if (czm_pass == czm_passTranslucent) \\n\" +\n \" { \\n\" +\n \" if (!isStyleTranslucent && !tile_translucentCommand) \\n\" + // Do not render opaque features in the translucent pass\n \" { \\n\" +\n \" gl_Position *= 0.0; \\n\" +\n \" } \\n\" +\n \" } \\n\" +\n \" else \\n\" +\n \" { \\n\" +\n \" if (isStyleTranslucent) \\n\" + // Do not render translucent features in the opaque pass\n \" { \\n\" +\n \" gl_Position *= 0.0; \\n\" +\n \" } \\n\" +\n \" } \\n\";\n }\n newMain +=\n \" tile_featureColor = featureProperties; \\n\" +\n \" tile_featureSt = st; \\n\" +\n \"}\";\n } else {\n // When VTF is not supported, color blend mode MIX will look incorrect due to the feature's color not being available in the vertex shader\n newMain =\n `${\n \"out vec2 tile_featureSt; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" tile_color(vec4(1.0)); \\n\" +\n \" tile_featureSt = computeSt(\"\n }${batchIdAttributeName}); \\n` + `}`;\n }\n\n return `${renamedSource}\\n${getGlslComputeSt(that)}${newMain}`;\n };\n};\n\nfunction getDefaultShader(source, applyHighlight) {\n source = ShaderSource.replaceMain(source, \"tile_main\");\n\n if (!applyHighlight) {\n return (\n `${source}void tile_color(vec4 tile_featureColor) \\n` +\n `{ \\n` +\n ` tile_main(); \\n` +\n `} \\n`\n );\n }\n\n // The color blend mode is intended for the RGB channels so alpha is always just multiplied.\n // out_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight)\n return (\n `${source}uniform float tile_colorBlend; \\n` +\n `void tile_color(vec4 tile_featureColor) \\n` +\n `{ \\n` +\n ` tile_main(); \\n` +\n ` tile_featureColor = czm_gammaCorrect(tile_featureColor); \\n` +\n ` out_FragColor.a *= tile_featureColor.a; \\n` +\n ` float highlight = ceil(tile_colorBlend); \\n` +\n ` out_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \\n` +\n `} \\n`\n );\n}\n\nfunction replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName) {\n const functionCall = `texture(${diffuseAttributeOrUniformName}`;\n\n let fromIndex = 0;\n let startIndex = source.indexOf(functionCall, fromIndex);\n let endIndex;\n\n while (startIndex > -1) {\n let nestedLevel = 0;\n for (let i = startIndex; i < source.length; ++i) {\n const character = source.charAt(i);\n if (character === \"(\") {\n ++nestedLevel;\n } else if (character === \")\") {\n --nestedLevel;\n if (nestedLevel === 0) {\n endIndex = i + 1;\n break;\n }\n }\n }\n const extractedFunction = source.slice(startIndex, endIndex);\n const replacedFunction = `tile_diffuse_final(${extractedFunction}, tile_diffuse)`;\n\n source =\n source.slice(0, startIndex) + replacedFunction + source.slice(endIndex);\n fromIndex = startIndex + replacedFunction.length;\n startIndex = source.indexOf(functionCall, fromIndex);\n }\n\n return source;\n}\n\nfunction modifyDiffuse(source, diffuseAttributeOrUniformName, applyHighlight) {\n // If the glTF does not specify the _3DTILESDIFFUSE semantic, return the default shader.\n // Otherwise if _3DTILESDIFFUSE is defined prefer the shader below that can switch the color mode at runtime.\n if (!defined(diffuseAttributeOrUniformName)) {\n return getDefaultShader(source, applyHighlight);\n }\n\n // Find the diffuse uniform. Examples matches:\n // uniform vec3 u_diffuseColor;\n // uniform sampler2D diffuseTexture;\n let regex = new RegExp(\n `(uniform|attribute|in)\\\\s+(vec[34]|sampler2D)\\\\s+${diffuseAttributeOrUniformName};`\n );\n const uniformMatch = source.match(regex);\n\n if (!defined(uniformMatch)) {\n // Could not find uniform declaration of type vec3, vec4, or sampler2D\n return getDefaultShader(source, applyHighlight);\n }\n\n const declaration = uniformMatch[0];\n const type = uniformMatch[2];\n\n source = ShaderSource.replaceMain(source, \"tile_main\");\n source = source.replace(declaration, \"\"); // Remove uniform declaration for now so the replace below doesn't affect it\n\n // If the tile color is white, use the source color. This implies the feature has not been styled.\n // Highlight: tile_colorBlend is 0.0 and the source color is used\n // Replace: tile_colorBlend is 1.0 and the tile color is used\n // Mix: tile_colorBlend is between 0.0 and 1.0, causing the source color and tile color to mix\n const finalDiffuseFunction =\n \"bool isWhite(vec3 color) \\n\" +\n \"{ \\n\" +\n \" return all(greaterThan(color, vec3(1.0 - czm_epsilon3))); \\n\" +\n \"} \\n\" +\n \"vec4 tile_diffuse_final(vec4 sourceDiffuse, vec4 tileDiffuse) \\n\" +\n \"{ \\n\" +\n \" vec4 blendDiffuse = mix(sourceDiffuse, tileDiffuse, tile_colorBlend); \\n\" +\n \" vec4 diffuse = isWhite(tileDiffuse.rgb) ? sourceDiffuse : blendDiffuse; \\n\" +\n \" return vec4(diffuse.rgb, sourceDiffuse.a); \\n\" +\n \"} \\n\";\n\n // The color blend mode is intended for the RGB channels so alpha is always just multiplied.\n // out_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight)\n const highlight =\n \" tile_featureColor = czm_gammaCorrect(tile_featureColor); \\n\" +\n \" out_FragColor.a *= tile_featureColor.a; \\n\" +\n \" float highlight = ceil(tile_colorBlend); \\n\" +\n \" out_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \\n\";\n\n let setColor;\n if (type === \"vec3\" || type === \"vec4\") {\n const sourceDiffuse =\n type === \"vec3\"\n ? `vec4(${diffuseAttributeOrUniformName}, 1.0)`\n : diffuseAttributeOrUniformName;\n const replaceDiffuse =\n type === \"vec3\" ? \"tile_diffuse.xyz\" : \"tile_diffuse\";\n regex = new RegExp(diffuseAttributeOrUniformName, \"g\");\n source = source.replace(regex, replaceDiffuse);\n setColor =\n ` vec4 source = ${sourceDiffuse}; \\n` +\n ` tile_diffuse = tile_diffuse_final(source, tile_featureColor); \\n` +\n ` tile_main(); \\n`;\n } else if (type === \"sampler2D\") {\n // Handles any number of nested parentheses\n // E.g. texture(u_diffuse, uv)\n // E.g. texture(u_diffuse, computeUV(index))\n source = replaceDiffuseTextureCalls(source, diffuseAttributeOrUniformName);\n setColor =\n \" tile_diffuse = tile_featureColor; \\n\" + \" tile_main(); \\n\";\n }\n\n source =\n `${\n \"uniform float tile_colorBlend; \\n\" + \"vec4 tile_diffuse = vec4(1.0); \\n\"\n }${finalDiffuseFunction}${declaration}\\n${source}\\n` +\n `void tile_color(vec4 tile_featureColor) \\n` +\n `{ \\n${setColor}`;\n\n if (applyHighlight) {\n source += highlight;\n }\n\n source += \"} \\n\";\n return source;\n}\n\nCesium3DTileBatchTable.prototype.getFragmentShaderCallback = function (\n handleTranslucent,\n diffuseAttributeOrUniformName,\n hasPremultipliedAlpha\n) {\n if (this.featuresLength === 0) {\n return;\n }\n return function (source) {\n source = modifyDiffuse(source, diffuseAttributeOrUniformName, true);\n if (ContextLimits.maximumVertexTextureImageUnits > 0) {\n // When VTF is supported, per-feature show/hide already happened in the fragment shader\n source +=\n \"uniform sampler2D tile_pickTexture; \\n\" +\n \"in vec2 tile_featureSt; \\n\" +\n \"in vec4 tile_featureColor; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" tile_color(tile_featureColor); \\n\";\n\n if (hasPremultipliedAlpha) {\n source += \" out_FragColor.rgb *= out_FragColor.a; \\n\";\n }\n\n source += \"}\";\n } else {\n if (handleTranslucent) {\n source += \"uniform bool tile_translucentCommand; \\n\";\n }\n source +=\n \"uniform sampler2D tile_pickTexture; \\n\" +\n \"uniform sampler2D tile_batchTexture; \\n\" +\n \"in vec2 tile_featureSt; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" vec4 featureProperties = texture(tile_batchTexture, tile_featureSt); \\n\" +\n \" if (featureProperties.a == 0.0) { \\n\" + // show: alpha == 0 - false, non-zeo - true\n \" discard; \\n\" +\n \" } \\n\";\n\n if (handleTranslucent) {\n source +=\n \" bool isStyleTranslucent = (featureProperties.a != 1.0); \\n\" +\n \" if (czm_pass == czm_passTranslucent) \\n\" +\n \" { \\n\" +\n \" if (!isStyleTranslucent && !tile_translucentCommand) \\n\" + // Do not render opaque features in the translucent pass\n \" { \\n\" +\n \" discard; \\n\" +\n \" } \\n\" +\n \" } \\n\" +\n \" else \\n\" +\n \" { \\n\" +\n \" if (isStyleTranslucent) \\n\" + // Do not render translucent features in the opaque pass\n \" { \\n\" +\n \" discard; \\n\" +\n \" } \\n\" +\n \" } \\n\";\n }\n\n source += \" tile_color(featureProperties); \\n\";\n\n if (hasPremultipliedAlpha) {\n source += \" out_FragColor.rgb *= out_FragColor.a; \\n\";\n }\n\n source += \"} \\n\";\n }\n return source;\n };\n};\n\nCesium3DTileBatchTable.prototype.getClassificationFragmentShaderCallback = function () {\n if (this.featuresLength === 0) {\n return;\n }\n return function (source) {\n source = ShaderSource.replaceMain(source, \"tile_main\");\n if (ContextLimits.maximumVertexTextureImageUnits > 0) {\n // When VTF is supported, per-feature show/hide already happened in the fragment shader\n source +=\n \"uniform sampler2D tile_pickTexture;\\n\" +\n \"in vec2 tile_featureSt; \\n\" +\n \"in vec4 tile_featureColor; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" tile_main(); \\n\" +\n \" out_FragColor = tile_featureColor; \\n\" +\n \" out_FragColor.rgb *= out_FragColor.a; \\n\" +\n \"}\";\n } else {\n source +=\n \"uniform sampler2D tile_batchTexture; \\n\" +\n \"uniform sampler2D tile_pickTexture;\\n\" +\n \"in vec2 tile_featureSt; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" tile_main(); \\n\" +\n \" vec4 featureProperties = texture(tile_batchTexture, tile_featureSt); \\n\" +\n \" if (featureProperties.a == 0.0) { \\n\" + // show: alpha == 0 - false, non-zero - true\n \" discard; \\n\" +\n \" } \\n\" +\n \" out_FragColor = featureProperties; \\n\" +\n \" out_FragColor.rgb *= out_FragColor.a; \\n\" +\n \"} \\n\";\n }\n return source;\n };\n};\n\nfunction getColorBlend(batchTable) {\n const tileset = batchTable._content.tileset;\n const colorBlendMode = tileset.colorBlendMode;\n const colorBlendAmount = tileset.colorBlendAmount;\n if (colorBlendMode === Cesium3DTileColorBlendMode.HIGHLIGHT) {\n return 0.0;\n }\n if (colorBlendMode === Cesium3DTileColorBlendMode.REPLACE) {\n return 1.0;\n }\n if (colorBlendMode === Cesium3DTileColorBlendMode.MIX) {\n // The value 0.0 is reserved for highlight, so clamp to just above 0.0.\n return CesiumMath.clamp(colorBlendAmount, CesiumMath.EPSILON4, 1.0);\n }\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(`Invalid color blend mode \"${colorBlendMode}\".`);\n //>>includeEnd('debug');\n}\n\nCesium3DTileBatchTable.prototype.getUniformMapCallback = function () {\n if (this.featuresLength === 0) {\n return;\n }\n\n const that = this;\n return function (uniformMap) {\n const batchUniformMap = {\n tile_batchTexture: function () {\n // PERFORMANCE_IDEA: we could also use a custom shader that avoids the texture read.\n return defaultValue(\n that._batchTexture.batchTexture,\n that._batchTexture.defaultTexture\n );\n },\n tile_textureDimensions: function () {\n return that._batchTexture.textureDimensions;\n },\n tile_textureStep: function () {\n return that._batchTexture.textureStep;\n },\n tile_colorBlend: function () {\n return getColorBlend(that);\n },\n tile_pickTexture: function () {\n return that._batchTexture.pickTexture;\n },\n };\n\n return combine(uniformMap, batchUniformMap);\n };\n};\n\nCesium3DTileBatchTable.prototype.getPickId = function () {\n return \"texture(tile_pickTexture, tile_featureSt)\";\n};\n\n///////////////////////////////////////////////////////////////////////////\n\nconst StyleCommandsNeeded = {\n ALL_OPAQUE: 0,\n ALL_TRANSLUCENT: 1,\n OPAQUE_AND_TRANSLUCENT: 2,\n};\n\nCesium3DTileBatchTable.prototype.addDerivedCommands = function (\n frameState,\n commandStart\n) {\n const commandList = frameState.commandList;\n const commandEnd = commandList.length;\n const tile = this._content._tile;\n const finalResolution = tile._finalResolution;\n const tileset = tile.tileset;\n const bivariateVisibilityTest =\n tileset.isSkippingLevelOfDetail &&\n tileset.hasMixedContent &&\n frameState.context.stencilBuffer;\n const styleCommandsNeeded = getStyleCommandsNeeded(this);\n\n for (let i = commandStart; i < commandEnd; ++i) {\n const command = commandList[i];\n if (command.pass === Pass.COMPUTE) {\n continue;\n }\n\n let derivedCommands = command.derivedCommands.tileset;\n if (!defined(derivedCommands) || command.dirty) {\n derivedCommands = {};\n command.derivedCommands.tileset = derivedCommands;\n derivedCommands.originalCommand = deriveCommand(command);\n command.dirty = false;\n }\n const originalCommand = derivedCommands.originalCommand;\n\n if (\n styleCommandsNeeded !== StyleCommandsNeeded.ALL_OPAQUE &&\n command.pass !== Pass.TRANSLUCENT\n ) {\n if (!defined(derivedCommands.translucent)) {\n derivedCommands.translucent = deriveTranslucentCommand(originalCommand);\n }\n }\n\n if (\n styleCommandsNeeded !== StyleCommandsNeeded.ALL_TRANSLUCENT &&\n command.pass !== Pass.TRANSLUCENT\n ) {\n if (!defined(derivedCommands.opaque)) {\n derivedCommands.opaque = deriveOpaqueCommand(originalCommand);\n }\n\n if (bivariateVisibilityTest) {\n if (!finalResolution) {\n if (!defined(derivedCommands.zback)) {\n derivedCommands.zback = deriveZBackfaceCommand(\n frameState.context,\n originalCommand\n );\n }\n tileset._backfaceCommands.push(derivedCommands.zback);\n }\n if (\n !defined(derivedCommands.stencil) ||\n tile._selectionDepth !==\n getLastSelectionDepth(derivedCommands.stencil)\n ) {\n if (command.renderState.depthMask) {\n derivedCommands.stencil = deriveStencilCommand(\n originalCommand,\n tile._selectionDepth\n );\n } else {\n // Ignore if tile does not write depth\n derivedCommands.stencil = derivedCommands.opaque;\n }\n }\n }\n }\n\n const opaqueCommand = bivariateVisibilityTest\n ? derivedCommands.stencil\n : derivedCommands.opaque;\n const translucentCommand = derivedCommands.translucent;\n\n // If the command was originally opaque:\n // * If the styling applied to the tile is all opaque, use the opaque command\n // (with one additional uniform needed for the shader).\n // * If the styling is all translucent, use new (cached) derived commands (front\n // and back faces) with a translucent render state.\n // * If the styling causes both opaque and translucent features in this tile,\n // then use both sets of commands.\n if (command.pass !== Pass.TRANSLUCENT) {\n if (styleCommandsNeeded === StyleCommandsNeeded.ALL_OPAQUE) {\n commandList[i] = opaqueCommand;\n }\n if (styleCommandsNeeded === StyleCommandsNeeded.ALL_TRANSLUCENT) {\n commandList[i] = translucentCommand;\n }\n if (styleCommandsNeeded === StyleCommandsNeeded.OPAQUE_AND_TRANSLUCENT) {\n // PERFORMANCE_IDEA: if the tile has multiple commands, we do not know what features are in what\n // commands so this case may be overkill.\n commandList[i] = opaqueCommand;\n commandList.push(translucentCommand);\n }\n } else {\n // Command was originally translucent so no need to derive new commands;\n // as of now, a style can't change an originally translucent feature to\n // opaque since the style's alpha is modulated, not a replacement. When\n // this changes, we need to derive new opaque commands here.\n commandList[i] = originalCommand;\n }\n }\n};\n\nfunction getStyleCommandsNeeded(batchTable) {\n const translucentFeaturesLength =\n batchTable._batchTexture.translucentFeaturesLength;\n\n if (translucentFeaturesLength === 0) {\n return StyleCommandsNeeded.ALL_OPAQUE;\n } else if (translucentFeaturesLength === batchTable.featuresLength) {\n return StyleCommandsNeeded.ALL_TRANSLUCENT;\n }\n\n return StyleCommandsNeeded.OPAQUE_AND_TRANSLUCENT;\n}\n\nfunction deriveCommand(command) {\n const derivedCommand = DrawCommand.shallowClone(command);\n\n // Add a uniform to indicate if the original command was translucent so\n // the shader knows not to cull vertices that were originally transparent\n // even though their style is opaque.\n const translucentCommand = derivedCommand.pass === Pass.TRANSLUCENT;\n\n derivedCommand.uniformMap = defined(derivedCommand.uniformMap)\n ? derivedCommand.uniformMap\n : {};\n derivedCommand.uniformMap.tile_translucentCommand = function () {\n return translucentCommand;\n };\n\n return derivedCommand;\n}\n\nfunction deriveTranslucentCommand(command) {\n const derivedCommand = DrawCommand.shallowClone(command);\n derivedCommand.pass = Pass.TRANSLUCENT;\n derivedCommand.renderState = getTranslucentRenderState(command.renderState);\n return derivedCommand;\n}\n\nfunction deriveOpaqueCommand(command) {\n const derivedCommand = DrawCommand.shallowClone(command);\n derivedCommand.renderState = getOpaqueRenderState(command.renderState);\n return derivedCommand;\n}\n\nfunction getLogDepthPolygonOffsetFragmentShaderProgram(context, shaderProgram) {\n let shader = context.shaderCache.getDerivedShaderProgram(\n shaderProgram,\n \"zBackfaceLogDepth\"\n );\n if (!defined(shader)) {\n const fs = shaderProgram.fragmentShaderSource.clone();\n fs.defines = defined(fs.defines) ? fs.defines.slice(0) : [];\n fs.defines.push(\"POLYGON_OFFSET\");\n\n shader = context.shaderCache.createDerivedShaderProgram(\n shaderProgram,\n \"zBackfaceLogDepth\",\n {\n vertexShaderSource: shaderProgram.vertexShaderSource,\n fragmentShaderSource: fs,\n attributeLocations: shaderProgram._attributeLocations,\n }\n );\n }\n\n return shader;\n}\n\nfunction deriveZBackfaceCommand(context, command) {\n // Write just backface depth of unresolved tiles so resolved stenciled tiles do not appear in front\n const derivedCommand = DrawCommand.shallowClone(command);\n const rs = clone(derivedCommand.renderState, true);\n rs.cull.enabled = true;\n rs.cull.face = CullFace.FRONT;\n // Back faces do not need to write color.\n rs.colorMask = {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n };\n // Push back face depth away from the camera so it is less likely that back faces and front faces of the same tile\n // intersect and overlap. This helps avoid flickering for very thin double-sided walls.\n rs.polygonOffset = {\n enabled: true,\n factor: 5.0,\n units: 5.0,\n };\n // Set the 3D Tiles bit\n rs.stencilTest = StencilConstants.setCesium3DTileBit();\n rs.stencilMask = StencilConstants.CESIUM_3D_TILE_MASK;\n\n derivedCommand.renderState = RenderState.fromCache(rs);\n derivedCommand.castShadows = false;\n derivedCommand.receiveShadows = false;\n derivedCommand.uniformMap = clone(command.uniformMap);\n\n const polygonOffset = new Cartesian2(5.0, 5.0);\n derivedCommand.uniformMap.u_polygonOffset = function () {\n return polygonOffset;\n };\n\n // Make the log depth depth fragment write account for the polygon offset, too.\n // Otherwise, the back face commands will cause the higher resolution\n // tiles to disappear.\n derivedCommand.shaderProgram = getLogDepthPolygonOffsetFragmentShaderProgram(\n context,\n command.shaderProgram\n );\n return derivedCommand;\n}\n\nfunction deriveStencilCommand(command, reference) {\n // Tiles only draw if their selection depth is >= the tile drawn already. They write their\n // selection depth to the stencil buffer to prevent ancestor tiles from drawing on top\n const derivedCommand = DrawCommand.shallowClone(command);\n const rs = clone(derivedCommand.renderState, true);\n // Stencil test is masked to the most significant 3 bits so the reference is shifted. Writes 0 for the terrain bit\n rs.stencilTest.enabled = true;\n rs.stencilTest.mask = StencilConstants.SKIP_LOD_MASK;\n rs.stencilTest.reference =\n StencilConstants.CESIUM_3D_TILE_MASK |\n (reference << StencilConstants.SKIP_LOD_BIT_SHIFT);\n rs.stencilTest.frontFunction = StencilFunction.GREATER_OR_EQUAL;\n rs.stencilTest.frontOperation.zPass = StencilOperation.REPLACE;\n rs.stencilTest.backFunction = StencilFunction.GREATER_OR_EQUAL;\n rs.stencilTest.backOperation.zPass = StencilOperation.REPLACE;\n rs.stencilMask =\n StencilConstants.CESIUM_3D_TILE_MASK | StencilConstants.SKIP_LOD_MASK;\n derivedCommand.renderState = RenderState.fromCache(rs);\n return derivedCommand;\n}\n\nfunction getLastSelectionDepth(stencilCommand) {\n // Isolate the selection depth from the stencil reference.\n const reference = stencilCommand.renderState.stencilTest.reference;\n return (\n (reference & StencilConstants.SKIP_LOD_MASK) >>>\n StencilConstants.SKIP_LOD_BIT_SHIFT\n );\n}\n\nfunction getTranslucentRenderState(renderState) {\n const rs = clone(renderState, true);\n rs.cull.enabled = false;\n rs.depthTest.enabled = true;\n rs.depthMask = false;\n rs.blending = BlendingState.ALPHA_BLEND;\n rs.stencilTest = StencilConstants.setCesium3DTileBit();\n rs.stencilMask = StencilConstants.CESIUM_3D_TILE_MASK;\n\n return RenderState.fromCache(rs);\n}\n\nfunction getOpaqueRenderState(renderState) {\n const rs = clone(renderState, true);\n rs.stencilTest = StencilConstants.setCesium3DTileBit();\n rs.stencilMask = StencilConstants.CESIUM_3D_TILE_MASK;\n\n return RenderState.fromCache(rs);\n}\n\nCesium3DTileBatchTable.prototype.update = function (tileset, frameState) {\n this._batchTexture.update(tileset, frameState);\n};\n\nCesium3DTileBatchTable.prototype.isDestroyed = function () {\n return false;\n};\n\nCesium3DTileBatchTable.prototype.destroy = function () {\n this._batchTexture = this._batchTexture && this._batchTexture.destroy();\n return destroyObject(this);\n};\nexport default Cesium3DTileBatchTable;\n", "/**\n * Describes a renderable batch of geometry.\n *\n * @alias Vector3DTileBatch\n * @constructor\n *\n * @param {object} options An object with the following properties:\n * @param {number} options.offset The offset of the batch into the indices buffer.\n * @param {number} options.count The number of indices in the batch.\n * @param {Color} options.color The color of the geometry in the batch.\n * @param {number[]} options.batchIds An array where each element is the batch id of the geometry in the batch.\n *\n * @private\n */\nfunction Vector3DTileBatch(options) {\n /**\n * The offset of the batch into the indices buffer.\n * @type {number}\n */\n this.offset = options.offset;\n /**\n * The number of indices in the batch.\n * @type {number}\n */\n this.count = options.count;\n /**\n * The color of the geometry in the batch.\n * @type {Color}\n */\n this.color = options.color;\n /**\n * An array where each element is the batch id of the geometry in the batch.\n * @type {number[]}\n */\n this.batchIds = options.batchIds;\n}\nexport default Vector3DTileBatch;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position;\\n\\\nin float a_batchId;\\n\\\n\\n\\\nuniform mat4 u_modifiedModelViewProjection;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n gl_Position = czm_depthClamp(u_modifiedModelViewProjection * vec4(position, 1.0));\\n\\\n}\\n\\\n\";\n", "import Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * A feature of a {@link Cesium3DTileset}.\n *

\n * Provides access to a feature's properties stored in the tile's batch table, as well\n * as the ability to show/hide a feature and change its highlight color via\n * {@link Cesium3DTileFeature#show} and {@link Cesium3DTileFeature#color}, respectively.\n *

\n *

\n * Modifications to a Cesium3DTileFeature object have the lifetime of the tile's\n * content. If the tile's content is unloaded, e.g., due to it going out of view and needing\n * to free space in the cache for visible tiles, listen to the {@link Cesium3DTileset#tileUnload} event to save any\n * modifications. Also listen to the {@link Cesium3DTileset#tileVisible} event to reapply any modifications.\n *

\n *

\n * Do not construct this directly. Access it through {@link Cesium3DTileContent#getFeature}\n * or picking using {@link Scene#pick}.\n *

\n *\n * @alias Cesium3DTileFeature\n * @constructor\n *\n * @example\n * // On mouse over, display all the properties for a feature in the console log.\n * handler.setInputAction(function(movement) {\n * const feature = scene.pick(movement.endPosition);\n * if (feature instanceof Cesium.Cesium3DTileFeature) {\n * const propertyIds = feature.getPropertyIds();\n * const length = propertyIds.length;\n * for (let i = 0; i < length; ++i) {\n * const propertyId = propertyIds[i];\n * console.log(`{propertyId}: ${feature.getProperty(propertyId)}`);\n * }\n * }\n * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);\n */\nfunction Cesium3DTileFeature(content, batchId) {\n this._content = content;\n this._batchId = batchId;\n this._color = undefined; // for calling getColor\n}\n\nObject.defineProperties(Cesium3DTileFeature.prototype, {\n /**\n * Gets or sets if the feature will be shown. This is set for all features\n * when a style's show is evaluated.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {boolean}\n *\n * @default true\n */\n show: {\n get: function () {\n return this._content.batchTable.getShow(this._batchId);\n },\n set: function (value) {\n this._content.batchTable.setShow(this._batchId, value);\n },\n },\n\n /**\n * Gets or sets the highlight color multiplied with the feature's color. When\n * this is white, the feature's color is not changed. This is set for all features\n * when a style's color is evaluated.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {Color}\n *\n * @default {@link Color.WHITE}\n */\n color: {\n get: function () {\n if (!defined(this._color)) {\n this._color = new Color();\n }\n return this._content.batchTable.getColor(this._batchId, this._color);\n },\n set: function (value) {\n this._content.batchTable.setColor(this._batchId, value);\n },\n },\n\n /**\n * Gets a typed array containing the ECEF positions of the polyline.\n * Returns undefined if {@link Cesium3DTileset#vectorKeepDecodedPositions} is false\n * or the feature is not a polyline in a vector tile.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n *\n * @type {Float64Array}\n */\n polylinePositions: {\n get: function () {\n if (!defined(this._content.getPolylinePositions)) {\n return undefined;\n }\n\n return this._content.getPolylinePositions(this._batchId);\n },\n },\n\n /**\n * Gets the content of the tile containing the feature.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {Cesium3DTileContent}\n *\n * @readonly\n * @private\n */\n content: {\n get: function () {\n return this._content;\n },\n },\n\n /**\n * Gets the tileset containing the feature.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {Cesium3DTileset}\n *\n * @readonly\n */\n tileset: {\n get: function () {\n return this._content.tileset;\n },\n },\n\n /**\n * All objects returned by {@link Scene#pick} have a primitive property. This returns\n * the tileset containing the feature.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {Cesium3DTileset}\n *\n * @readonly\n */\n primitive: {\n get: function () {\n return this._content.tileset;\n },\n },\n\n /**\n * Get the feature ID associated with this feature. For 3D Tiles 1.0, the\n * batch ID is returned. For EXT_mesh_features, this is the feature ID from\n * the selected feature ID set.\n *\n * @memberof Cesium3DTileFeature.prototype\n *\n * @type {number}\n *\n * @readonly\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n featureId: {\n get: function () {\n return this._batchId;\n },\n },\n\n /**\n * @private\n */\n pickId: {\n get: function () {\n return this._content.batchTable.getPickColor(this._batchId);\n },\n },\n});\n\n/**\n * Returns whether the feature contains this property. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {boolean} Whether the feature contains this property.\n */\nCesium3DTileFeature.prototype.hasProperty = function (name) {\n return this._content.batchTable.hasProperty(this._batchId, name);\n};\n\n/**\n * Returns an array of property IDs for the feature. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The IDs of the feature's properties.\n */\nCesium3DTileFeature.prototype.getPropertyIds = function (results) {\n return this._content.batchTable.getPropertyIds(this._batchId, results);\n};\n\n/**\n * Returns a copy of the value of the feature's property with the given name. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n *\n * @example\n * // Display all the properties for a feature in the console log.\n * const propertyIds = feature.getPropertyIds();\n * const length = propertyIds.length;\n * for (let i = 0; i < length; ++i) {\n * const propertyId = propertyIds[i];\n * console.log(`{propertyId}: ${feature.getProperty(propertyId)}`);\n * }\n */\nCesium3DTileFeature.prototype.getProperty = function (name) {\n return this._content.batchTable.getProperty(this._batchId, name);\n};\n\n/**\n * Returns a copy of the feature's property with the given name, examining all\n * the metadata from 3D Tiles 1.0 formats, the EXT_structural_metadata and legacy\n * EXT_feature_metadata glTF extensions, and the metadata present either in the\n * tileset JSON (3D Tiles 1.1) or in the 3DTILES_metadata 3D Tiles extension.\n * Metadata is checked against name from most specific to most general and the\n * first match is returned. Metadata is checked in this order:\n *\n *
    \n *
  1. Batch table (structural metadata) property by semantic
  2. \n *
  3. Batch table (structural metadata) property by property ID
  4. \n *
  5. Content metadata property by semantic
  6. \n *
  7. Content metadata property by property
  8. \n *
  9. Tile metadata property by semantic
  10. \n *
  11. Tile metadata property by property ID
  12. \n *
  13. Subtree metadata property by semantic
  14. \n *
  15. Subtree metadata property by property ID
  16. \n *
  17. Group metadata property by semantic
  18. \n *
  19. Group metadata property by property ID
  20. \n *
  21. Tileset metadata property by semantic
  22. \n *
  23. Tileset metadata property by property ID
  24. \n *
  25. Otherwise, return undefined
  26. \n *
\n *

\n * For 3D Tiles Next details, see the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension}\n * for 3D Tiles, as well as the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension}\n * for glTF. For the legacy glTF extension, see {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension}\n *

\n *\n * @param {Cesium3DTileContent} content The content for accessing the metadata\n * @param {number} batchId The batch ID (or feature ID) of the feature to get a property for\n * @param {string} name The semantic or property ID of the feature. Semantics are checked before property IDs in each granularity of metadata.\n * @return {*} The value of the property or undefined if the feature does not have this property.\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nCesium3DTileFeature.getPropertyInherited = function (content, batchId, name) {\n const batchTable = content.batchTable;\n if (defined(batchTable)) {\n if (batchTable.hasPropertyBySemantic(batchId, name)) {\n return batchTable.getPropertyBySemantic(batchId, name);\n }\n\n if (batchTable.hasProperty(batchId, name)) {\n return batchTable.getProperty(batchId, name);\n }\n }\n\n const contentMetadata = content.metadata;\n if (defined(contentMetadata)) {\n if (contentMetadata.hasPropertyBySemantic(name)) {\n return contentMetadata.getPropertyBySemantic(name);\n }\n\n if (contentMetadata.hasProperty(name)) {\n return contentMetadata.getProperty(name);\n }\n }\n\n const tile = content.tile;\n const tileMetadata = tile.metadata;\n if (defined(tileMetadata)) {\n if (tileMetadata.hasPropertyBySemantic(name)) {\n return tileMetadata.getPropertyBySemantic(name);\n }\n\n if (tileMetadata.hasProperty(name)) {\n return tileMetadata.getProperty(name);\n }\n }\n\n let subtreeMetadata;\n if (defined(tile.implicitSubtree)) {\n subtreeMetadata = tile.implicitSubtree.metadata;\n }\n\n if (defined(subtreeMetadata)) {\n if (subtreeMetadata.hasPropertyBySemantic(name)) {\n return subtreeMetadata.getPropertyBySemantic(name);\n }\n\n if (subtreeMetadata.hasProperty(name)) {\n return subtreeMetadata.getProperty(name);\n }\n }\n\n const groupMetadata = defined(content.group)\n ? content.group.metadata\n : undefined;\n if (defined(groupMetadata)) {\n if (groupMetadata.hasPropertyBySemantic(name)) {\n return groupMetadata.getPropertyBySemantic(name);\n }\n\n if (groupMetadata.hasProperty(name)) {\n return groupMetadata.getProperty(name);\n }\n }\n\n const tilesetMetadata = content.tileset.metadata;\n if (defined(tilesetMetadata)) {\n if (tilesetMetadata.hasPropertyBySemantic(name)) {\n return tilesetMetadata.getPropertyBySemantic(name);\n }\n\n if (tilesetMetadata.hasProperty(name)) {\n return tilesetMetadata.getProperty(name);\n }\n }\n\n return undefined;\n};\n\n/**\n * Returns a copy of the value of the feature's property with the given name.\n * If the feature is contained within a tileset that has metadata (3D Tiles 1.1)\n * or uses the 3DTILES_metadata extension, tileset, group and tile\n * metadata is inherited.\n *

\n * To resolve name conflicts, this method resolves names from most specific to\n * least specific by metadata granularity in the order: feature, tile, group,\n * tileset. Within each granularity, semantics are resolved first, then other\n * properties.\n *

\n * @param {string} name The case-sensitive name of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n * @private\n */\nCesium3DTileFeature.prototype.getPropertyInherited = function (name) {\n return Cesium3DTileFeature.getPropertyInherited(\n this._content,\n this._batchId,\n name\n );\n};\n\n/**\n * Sets the value of the feature's property with the given name.\n *

\n * If a property with the given name doesn't exist, it is created.\n *

\n *\n * @param {string} name The case-sensitive name of the property.\n * @param {*} value The value of the property that will be copied.\n *\n * @exception {DeveloperError} Inherited batch table hierarchy property is read only.\n *\n * @example\n * const height = feature.getProperty('Height'); // e.g., the height of a building\n *\n * @example\n * const name = 'clicked';\n * if (feature.getProperty(name)) {\n * console.log('already clicked');\n * } else {\n * feature.setProperty(name, true);\n * console.log('first click');\n * }\n */\nCesium3DTileFeature.prototype.setProperty = function (name, value) {\n this._content.batchTable.setProperty(this._batchId, name, value);\n\n // PERFORMANCE_IDEA: Probably overkill, but maybe only mark the tile dirty if the\n // property is in one of the style's expressions or - if it can be done quickly -\n // if the new property value changed the result of an expression.\n this._content.featurePropertiesDirty = true;\n};\n\n/**\n * Returns whether the feature's class name equals className. Unlike {@link Cesium3DTileFeature#isClass}\n * this function only checks the feature's exact class and not inherited classes.\n *

\n * This function returns false if no batch table hierarchy is present.\n *

\n *\n * @param {string} className The name to check against.\n * @returns {boolean} Whether the feature's class name equals className\n *\n * @private\n */\nCesium3DTileFeature.prototype.isExactClass = function (className) {\n return this._content.batchTable.isExactClass(this._batchId, className);\n};\n\n/**\n * Returns whether the feature's class or any inherited classes are named className.\n *

\n * This function returns false if no batch table hierarchy is present.\n *

\n *\n * @param {string} className The name to check against.\n * @returns {boolean} Whether the feature's class or inherited classes are named className\n *\n * @private\n */\nCesium3DTileFeature.prototype.isClass = function (className) {\n return this._content.batchTable.isClass(this._batchId, className);\n};\n\n/**\n * Returns the feature's class name.\n *

\n * This function returns undefined if no batch table hierarchy is present.\n *

\n *\n * @returns {string} The feature's class name.\n *\n * @private\n */\nCesium3DTileFeature.prototype.getExactClassName = function () {\n return this._content.batchTable.getExactClassName(this._batchId);\n};\nexport default Cesium3DTileFeature;\n", "/**\n * @implements {IHooks}\n */\nclass Hooks {\n\t/**\n\t * @callback HookCallback\n\t * @this {*|Jsep} this\n\t * @param {Jsep} env\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given callback to the list of callbacks for the given hook.\n\t *\n\t * The callback will be invoked when the hook it is registered for is run.\n\t *\n\t * One callback function can be registered to multiple hooks and the same hook multiple times.\n\t *\n\t * @param {string|object} name The name of the hook, or an object of callbacks keyed by name\n\t * @param {HookCallback|boolean} callback The callback function which is given environment variables.\n\t * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)\n\t * @public\n\t */\n\tadd(name, callback, first) {\n\t\tif (typeof arguments[0] != 'string') {\n\t\t\t// Multiple hook callbacks, keyed by name\n\t\t\tfor (let name in arguments[0]) {\n\t\t\t\tthis.add(name, arguments[0][name], arguments[1]);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t(Array.isArray(name) ? name : [name]).forEach(function (name) {\n\t\t\t\tthis[name] = this[name] || [];\n\n\t\t\t\tif (callback) {\n\t\t\t\t\tthis[name][first ? 'unshift' : 'push'](callback);\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\t}\n\n\t/**\n\t * Runs a hook invoking all registered callbacks with the given environment variables.\n\t *\n\t * Callbacks will be invoked synchronously and in the order in which they were registered.\n\t *\n\t * @param {string} name The name of the hook.\n\t * @param {Object} env The environment variables of the hook passed to all callbacks registered.\n\t * @public\n\t */\n\trun(name, env) {\n\t\tthis[name] = this[name] || [];\n\t\tthis[name].forEach(function (callback) {\n\t\t\tcallback.call(env && env.context ? env.context : env, env);\n\t\t});\n\t}\n}\n\n/**\n * @implements {IPlugins}\n */\nclass Plugins {\n\tconstructor(jsep) {\n\t\tthis.jsep = jsep;\n\t\tthis.registered = {};\n\t}\n\n\t/**\n\t * @callback PluginSetup\n\t * @this {Jsep} jsep\n\t * @returns: void\n\t */\n\t/**\n\t * Adds the given plugin(s) to the registry\n\t *\n\t * @param {object} plugins\n\t * @param {string} plugins.name The name of the plugin\n\t * @param {PluginSetup} plugins.init The init function\n\t * @public\n\t */\n\tregister(...plugins) {\n\t\tplugins.forEach((plugin) => {\n\t\t\tif (typeof plugin !== 'object' || !plugin.name || !plugin.init) {\n\t\t\t\tthrow new Error('Invalid JSEP plugin format');\n\t\t\t}\n\t\t\tif (this.registered[plugin.name]) {\n\t\t\t\t// already registered. Ignore.\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tplugin.init(this.jsep);\n\t\t\tthis.registered[plugin.name] = plugin;\n\t\t});\n\t}\n}\n\n// JavaScript Expression Parser (JSEP) 1.3.8\n\nclass Jsep {\n\t/**\n\t * @returns {string}\n\t */\n\tstatic get version() {\n\t\t// To be filled in by the template\n\t\treturn '1.3.8';\n\t}\n\n\t/**\n\t * @returns {string}\n\t */\n\tstatic toString() {\n\t\treturn 'JavaScript Expression Parser (JSEP) v' + Jsep.version;\n\t};\n\n\t// ==================== CONFIG ================================\n\t/**\n\t * @method addUnaryOp\n\t * @param {string} op_name The name of the unary op to add\n\t * @returns {Jsep}\n\t */\n\tstatic addUnaryOp(op_name) {\n\t\tJsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);\n\t\tJsep.unary_ops[op_name] = 1;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method jsep.addBinaryOp\n\t * @param {string} op_name The name of the binary op to add\n\t * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence\n\t * @param {boolean} [isRightAssociative=false] whether operator is right-associative\n\t * @returns {Jsep}\n\t */\n\tstatic addBinaryOp(op_name, precedence, isRightAssociative) {\n\t\tJsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);\n\t\tJsep.binary_ops[op_name] = precedence;\n\t\tif (isRightAssociative) {\n\t\t\tJsep.right_associative.add(op_name);\n\t\t}\n\t\telse {\n\t\t\tJsep.right_associative.delete(op_name);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addIdentifierChar\n\t * @param {string} char The additional character to treat as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic addIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.add(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method addLiteral\n\t * @param {string} literal_name The name of the literal to add\n\t * @param {*} literal_value The value of the literal\n\t * @returns {Jsep}\n\t */\n\tstatic addLiteral(literal_name, literal_value) {\n\t\tJsep.literals[literal_name] = literal_value;\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeUnaryOp\n\t * @param {string} op_name The name of the unary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeUnaryOp(op_name) {\n\t\tdelete Jsep.unary_ops[op_name];\n\t\tif (op_name.length === Jsep.max_unop_len) {\n\t\t\tJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\n\t\t}\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllUnaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllUnaryOps() {\n\t\tJsep.unary_ops = {};\n\t\tJsep.max_unop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeIdentifierChar\n\t * @param {string} char The additional character to stop treating as a valid part of an identifier\n\t * @returns {Jsep}\n\t */\n\tstatic removeIdentifierChar(char) {\n\t\tJsep.additional_identifier_chars.delete(char);\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeBinaryOp\n\t * @param {string} op_name The name of the binary op to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeBinaryOp(op_name) {\n\t\tdelete Jsep.binary_ops[op_name];\n\n\t\tif (op_name.length === Jsep.max_binop_len) {\n\t\t\tJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\t\t}\n\t\tJsep.right_associative.delete(op_name);\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllBinaryOps\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllBinaryOps() {\n\t\tJsep.binary_ops = {};\n\t\tJsep.max_binop_len = 0;\n\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeLiteral\n\t * @param {string} literal_name The name of the literal to remove\n\t * @returns {Jsep}\n\t */\n\tstatic removeLiteral(literal_name) {\n\t\tdelete Jsep.literals[literal_name];\n\t\treturn Jsep;\n\t}\n\n\t/**\n\t * @method removeAllLiterals\n\t * @returns {Jsep}\n\t */\n\tstatic removeAllLiterals() {\n\t\tJsep.literals = {};\n\n\t\treturn Jsep;\n\t}\n\t// ==================== END CONFIG ============================\n\n\n\t/**\n\t * @returns {string}\n\t */\n\tget char() {\n\t\treturn this.expr.charAt(this.index);\n\t}\n\n\t/**\n\t * @returns {number}\n\t */\n\tget code() {\n\t\treturn this.expr.charCodeAt(this.index);\n\t};\n\n\n\t/**\n\t * @param {string} expr a string with the passed in express\n\t * @returns Jsep\n\t */\n\tconstructor(expr) {\n\t\t// `index` stores the character number we are currently at\n\t\t// All of the gobbles below will modify `index` as we move along\n\t\tthis.expr = expr;\n\t\tthis.index = 0;\n\t}\n\n\t/**\n\t * static top-level parser\n\t * @returns {jsep.Expression}\n\t */\n\tstatic parse(expr) {\n\t\treturn (new Jsep(expr)).parse();\n\t}\n\n\t/**\n\t * Get the longest key length of any object\n\t * @param {object} obj\n\t * @returns {number}\n\t */\n\tstatic getMaxKeyLen(obj) {\n\t\treturn Math.max(0, ...Object.keys(obj).map(k => k.length));\n\t}\n\n\t/**\n\t * `ch` is a character code in the next three functions\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isDecimalDigit(ch) {\n\t\treturn (ch >= 48 && ch <= 57); // 0...9\n\t}\n\n\t/**\n\t * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.\n\t * @param {string} op_val\n\t * @returns {number}\n\t */\n\tstatic binaryPrecedence(op_val) {\n\t\treturn Jsep.binary_ops[op_val] || 0;\n\t}\n\n\t/**\n\t * Looks for start of identifier\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierStart(ch) {\n\t\treturn (ch >= 65 && ch <= 90) || // A...Z\n\t\t\t(ch >= 97 && ch <= 122) || // a...z\n\t\t\t(ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)]) || // any non-ASCII that is not an operator\n\t\t\t(Jsep.additional_identifier_chars.has(String.fromCharCode(ch))); // additional characters\n\t}\n\n\t/**\n\t * @param {number} ch\n\t * @returns {boolean}\n\t */\n\tstatic isIdentifierPart(ch) {\n\t\treturn Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);\n\t}\n\n\t/**\n\t * throw error at index of the expression\n\t * @param {string} message\n\t * @throws\n\t */\n\tthrowError(message) {\n\t\tconst error = new Error(message + ' at character ' + this.index);\n\t\terror.index = this.index;\n\t\terror.description = message;\n\t\tthrow error;\n\t}\n\n\t/**\n\t * Run a given hook\n\t * @param {string} name\n\t * @param {jsep.Expression|false} [node]\n\t * @returns {?jsep.Expression}\n\t */\n\trunHook(name, node) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this, node };\n\t\t\tJsep.hooks.run(name, env);\n\t\t\treturn env.node;\n\t\t}\n\t\treturn node;\n\t}\n\n\t/**\n\t * Runs a given hook until one returns a node\n\t * @param {string} name\n\t * @returns {?jsep.Expression}\n\t */\n\tsearchHook(name) {\n\t\tif (Jsep.hooks[name]) {\n\t\t\tconst env = { context: this };\n\t\t\tJsep.hooks[name].find(function (callback) {\n\t\t\t\tcallback.call(env.context, env);\n\t\t\t\treturn env.node;\n\t\t\t});\n\t\t\treturn env.node;\n\t\t}\n\t}\n\n\t/**\n\t * Push `index` up to the next non-space character\n\t */\n\tgobbleSpaces() {\n\t\tlet ch = this.code;\n\t\t// Whitespace\n\t\twhile (ch === Jsep.SPACE_CODE\n\t\t|| ch === Jsep.TAB_CODE\n\t\t|| ch === Jsep.LF_CODE\n\t\t|| ch === Jsep.CR_CODE) {\n\t\t\tch = this.expr.charCodeAt(++this.index);\n\t\t}\n\t\tthis.runHook('gobble-spaces');\n\t}\n\n\t/**\n\t * Top-level method to parse all expressions and returns compound or single node\n\t * @returns {jsep.Expression}\n\t */\n\tparse() {\n\t\tthis.runHook('before-all');\n\t\tconst nodes = this.gobbleExpressions();\n\n\t\t// If there's only one expression just try returning the expression\n\t\tconst node = nodes.length === 1\n\t\t ? nodes[0]\n\t\t\t: {\n\t\t\t\ttype: Jsep.COMPOUND,\n\t\t\t\tbody: nodes\n\t\t\t};\n\t\treturn this.runHook('after-all', node);\n\t}\n\n\t/**\n\t * top-level parser (but can be reused within as well)\n\t * @param {number} [untilICode]\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleExpressions(untilICode) {\n\t\tlet nodes = [], ch_i, node;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch_i = this.code;\n\n\t\t\t// Expressions can be separated by semicolons, commas, or just inferred without any\n\t\t\t// separators\n\t\t\tif (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {\n\t\t\t\tthis.index++; // ignore separators\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Try to gobble each expression individually\n\t\t\t\tif (node = this.gobbleExpression()) {\n\t\t\t\t\tnodes.push(node);\n\t\t\t\t\t// If we weren't able to find a binary expression and are out of room, then\n\t\t\t\t\t// the expression passed in probably has too much\n\t\t\t\t}\n\t\t\t\telse if (this.index < this.expr.length) {\n\t\t\t\t\tif (ch_i === untilICode) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthis.throwError('Unexpected \"' + this.char + '\"');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * The main parsing function.\n\t * @returns {?jsep.Expression}\n\t */\n\tgobbleExpression() {\n\t\tconst node = this.searchHook('gobble-expression') || this.gobbleBinaryExpression();\n\t\tthis.gobbleSpaces();\n\n\t\treturn this.runHook('after-expression', node);\n\t}\n\n\t/**\n\t * Search for the operation portion of the string (e.g. `+`, `===`)\n\t * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)\n\t * and move down from 3 to 2 to 1 character until a matching binary operation is found\n\t * then, return that binary operation\n\t * @returns {string|boolean}\n\t */\n\tgobbleBinaryOp() {\n\t\tthis.gobbleSpaces();\n\t\tlet to_check = this.expr.substr(this.index, Jsep.max_binop_len);\n\t\tlet tc_len = to_check.length;\n\n\t\twhile (tc_len > 0) {\n\t\t\t// Don't accept a binary op when it is an identifier.\n\t\t\t// Binary ops that start with a identifier-valid character must be followed\n\t\t\t// by a non identifier-part valid character\n\t\t\tif (Jsep.binary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t)) {\n\t\t\t\tthis.index += tc_len;\n\t\t\t\treturn to_check;\n\t\t\t}\n\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This function is responsible for gobbling an individual expression,\n\t * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`\n\t * @returns {?jsep.BinaryExpression}\n\t */\n\tgobbleBinaryExpression() {\n\t\tlet node, biop, prec, stack, biop_info, left, right, i, cur_biop;\n\n\t\t// First, try to get the leftmost thing\n\t\t// Then, check to see if there's a binary operator operating on that leftmost thing\n\t\t// Don't gobbleBinaryOp without a left-hand-side\n\t\tleft = this.gobbleToken();\n\t\tif (!left) {\n\t\t\treturn left;\n\t\t}\n\t\tbiop = this.gobbleBinaryOp();\n\n\t\t// If there wasn't a binary operator, just return the leftmost node\n\t\tif (!biop) {\n\t\t\treturn left;\n\t\t}\n\n\t\t// Otherwise, we need to start a stack to properly place the binary operations in their\n\t\t// precedence structure\n\t\tbiop_info = { value: biop, prec: Jsep.binaryPrecedence(biop), right_a: Jsep.right_associative.has(biop) };\n\n\t\tright = this.gobbleToken();\n\n\t\tif (!right) {\n\t\t\tthis.throwError(\"Expected expression after \" + biop);\n\t\t}\n\n\t\tstack = [left, biop_info, right];\n\n\t\t// Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)\n\t\twhile ((biop = this.gobbleBinaryOp())) {\n\t\t\tprec = Jsep.binaryPrecedence(biop);\n\n\t\t\tif (prec === 0) {\n\t\t\t\tthis.index -= biop.length;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbiop_info = { value: biop, prec, right_a: Jsep.right_associative.has(biop) };\n\n\t\t\tcur_biop = biop;\n\n\t\t\t// Reduce: make a binary expression from the three topmost entries.\n\t\t\tconst comparePrev = prev => biop_info.right_a && prev.right_a\n\t\t\t\t? prec > prev.prec\n\t\t\t\t: prec <= prev.prec;\n\t\t\twhile ((stack.length > 2) && comparePrev(stack[stack.length - 2])) {\n\t\t\t\tright = stack.pop();\n\t\t\t\tbiop = stack.pop().value;\n\t\t\t\tleft = stack.pop();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\t\toperator: biop,\n\t\t\t\t\tleft,\n\t\t\t\t\tright\n\t\t\t\t};\n\t\t\t\tstack.push(node);\n\t\t\t}\n\n\t\t\tnode = this.gobbleToken();\n\n\t\t\tif (!node) {\n\t\t\t\tthis.throwError(\"Expected expression after \" + cur_biop);\n\t\t\t}\n\n\t\t\tstack.push(biop_info, node);\n\t\t}\n\n\t\ti = stack.length - 1;\n\t\tnode = stack[i];\n\n\t\twhile (i > 1) {\n\t\t\tnode = {\n\t\t\t\ttype: Jsep.BINARY_EXP,\n\t\t\t\toperator: stack[i - 1].value,\n\t\t\t\tleft: stack[i - 2],\n\t\t\t\tright: node\n\t\t\t};\n\t\t\ti -= 2;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * An individual part of a binary expression:\n\t * e.g. `foo.bar(baz)`, `1`, `\"abc\"`, `(a % 2)` (because it's in parenthesis)\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleToken() {\n\t\tlet ch, to_check, tc_len, node;\n\n\t\tthis.gobbleSpaces();\n\t\tnode = this.searchHook('gobble-token');\n\t\tif (node) {\n\t\t\treturn this.runHook('after-token', node);\n\t\t}\n\n\t\tch = this.code;\n\n\t\tif (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {\n\t\t\t// Char code 46 is a dot `.` which can start off a numeric literal\n\t\t\treturn this.gobbleNumericLiteral();\n\t\t}\n\n\t\tif (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {\n\t\t\t// Single or double quotes\n\t\t\tnode = this.gobbleStringLiteral();\n\t\t}\n\t\telse if (ch === Jsep.OBRACK_CODE) {\n\t\t\tnode = this.gobbleArray();\n\t\t}\n\t\telse {\n\t\t\tto_check = this.expr.substr(this.index, Jsep.max_unop_len);\n\t\t\ttc_len = to_check.length;\n\n\t\t\twhile (tc_len > 0) {\n\t\t\t\t// Don't accept an unary op when it is an identifier.\n\t\t\t\t// Unary ops that start with a identifier-valid character must be followed\n\t\t\t\t// by a non identifier-part valid character\n\t\t\t\tif (Jsep.unary_ops.hasOwnProperty(to_check) && (\n\t\t\t\t\t!Jsep.isIdentifierStart(this.code) ||\n\t\t\t\t\t(this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))\n\t\t\t\t)) {\n\t\t\t\t\tthis.index += tc_len;\n\t\t\t\t\tconst argument = this.gobbleToken();\n\t\t\t\t\tif (!argument) {\n\t\t\t\t\t\tthis.throwError('missing unaryOp argument');\n\t\t\t\t\t}\n\t\t\t\t\treturn this.runHook('after-token', {\n\t\t\t\t\t\ttype: Jsep.UNARY_EXP,\n\t\t\t\t\t\toperator: to_check,\n\t\t\t\t\t\targument,\n\t\t\t\t\t\tprefix: true\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tto_check = to_check.substr(0, --tc_len);\n\t\t\t}\n\n\t\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\t\tnode = this.gobbleIdentifier();\n\t\t\t\tif (Jsep.literals.hasOwnProperty(node.name)) {\n\t\t\t\t\tnode = {\n\t\t\t\t\t\ttype: Jsep.LITERAL,\n\t\t\t\t\t\tvalue: Jsep.literals[node.name],\n\t\t\t\t\t\traw: node.name,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (node.name === Jsep.this_str) {\n\t\t\t\t\tnode = { type: Jsep.THIS_EXP };\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) { // open parenthesis\n\t\t\t\tnode = this.gobbleGroup();\n\t\t\t}\n\t\t}\n\n\t\tif (!node) {\n\t\t\treturn this.runHook('after-token', false);\n\t\t}\n\n\t\tnode = this.gobbleTokenProperty(node);\n\t\treturn this.runHook('after-token', node);\n\t}\n\n\t/**\n\t * Gobble properties of of identifiers/strings/arrays/groups.\n\t * e.g. `foo`, `bar.baz`, `foo['bar'].baz`\n\t * It also gobbles function calls:\n\t * e.g. `Math.acos(obj.angle)`\n\t * @param {jsep.Expression} node\n\t * @returns {jsep.Expression}\n\t */\n\tgobbleTokenProperty(node) {\n\t\tthis.gobbleSpaces();\n\n\t\tlet ch = this.code;\n\t\twhile (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {\n\t\t\tlet optional;\n\t\t\tif (ch === Jsep.QUMARK_CODE) {\n\t\t\t\tif (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\toptional = true;\n\t\t\t\tthis.index += 2;\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t}\n\t\t\tthis.index++;\n\n\t\t\tif (ch === Jsep.OBRACK_CODE) {\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: true,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleExpression()\n\t\t\t\t};\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tch = this.code;\n\t\t\t\tif (ch !== Jsep.CBRACK_CODE) {\n\t\t\t\t\tthis.throwError('Unclosed [');\n\t\t\t\t}\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse if (ch === Jsep.OPAREN_CODE) {\n\t\t\t\t// A function call is being made; gobble all the arguments\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.CALL_EXP,\n\t\t\t\t\t'arguments': this.gobbleArguments(Jsep.CPAREN_CODE),\n\t\t\t\t\tcallee: node\n\t\t\t\t};\n\t\t\t}\n\t\t\telse if (ch === Jsep.PERIOD_CODE || optional) {\n\t\t\t\tif (optional) {\n\t\t\t\t\tthis.index--;\n\t\t\t\t}\n\t\t\t\tthis.gobbleSpaces();\n\t\t\t\tnode = {\n\t\t\t\t\ttype: Jsep.MEMBER_EXP,\n\t\t\t\t\tcomputed: false,\n\t\t\t\t\tobject: node,\n\t\t\t\t\tproperty: this.gobbleIdentifier(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (optional) {\n\t\t\t\tnode.optional = true;\n\t\t\t} // else leave undefined for compatibility with esprima\n\n\t\t\tthis.gobbleSpaces();\n\t\t\tch = this.code;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to\n\t * keep track of everything in the numeric literal and then calling `parseFloat` on that string\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleNumericLiteral() {\n\t\tlet number = '', ch, chCode;\n\n\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t}\n\n\t\tif (this.code === Jsep.PERIOD_CODE) { // can start with a decimal marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) {\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\t\t}\n\n\t\tch = this.char;\n\n\t\tif (ch === 'e' || ch === 'E') { // exponent marker\n\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\tch = this.char;\n\n\t\t\tif (ch === '+' || ch === '-') { // exponent sign\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\twhile (Jsep.isDecimalDigit(this.code)) { // exponent itself\n\t\t\t\tnumber += this.expr.charAt(this.index++);\n\t\t\t}\n\n\t\t\tif (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1)) ) {\n\t\t\t\tthis.throwError('Expected exponent (' + number + this.char + ')');\n\t\t\t}\n\t\t}\n\n\t\tchCode = this.code;\n\n\t\t// Check to make sure this isn't a variable name that start with a number (123abc)\n\t\tif (Jsep.isIdentifierStart(chCode)) {\n\t\t\tthis.throwError('Variable names cannot start with a number (' +\n\t\t\t\tnumber + this.char + ')');\n\t\t}\n\t\telse if (chCode === Jsep.PERIOD_CODE || (number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE)) {\n\t\t\tthis.throwError('Unexpected period');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: parseFloat(number),\n\t\t\traw: number\n\t\t};\n\t}\n\n\t/**\n\t * Parses a string literal, staring with single or double quotes with basic support for escape codes\n\t * e.g. `\"hello world\"`, `'this is\\nJSEP'`\n\t * @returns {jsep.Literal}\n\t */\n\tgobbleStringLiteral() {\n\t\tlet str = '';\n\t\tconst startIndex = this.index;\n\t\tconst quote = this.expr.charAt(this.index++);\n\t\tlet closed = false;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tlet ch = this.expr.charAt(this.index++);\n\n\t\t\tif (ch === quote) {\n\t\t\t\tclosed = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch === '\\\\') {\n\t\t\t\t// Check for all of the common escape codes\n\t\t\t\tch = this.expr.charAt(this.index++);\n\n\t\t\t\tswitch (ch) {\n\t\t\t\t\tcase 'n': str += '\\n'; break;\n\t\t\t\t\tcase 'r': str += '\\r'; break;\n\t\t\t\t\tcase 't': str += '\\t'; break;\n\t\t\t\t\tcase 'b': str += '\\b'; break;\n\t\t\t\t\tcase 'f': str += '\\f'; break;\n\t\t\t\t\tcase 'v': str += '\\x0B'; break;\n\t\t\t\t\tdefault : str += ch;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tstr += ch;\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Unclosed quote after \"' + str + '\"');\n\t\t}\n\n\t\treturn {\n\t\t\ttype: Jsep.LITERAL,\n\t\t\tvalue: str,\n\t\t\traw: this.expr.substring(startIndex, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles only identifiers\n\t * e.g.: `foo`, `_value`, `$x1`\n\t * Also, this function checks if that identifier is a literal:\n\t * (e.g. `true`, `false`, `null`) or `this`\n\t * @returns {jsep.Identifier}\n\t */\n\tgobbleIdentifier() {\n\t\tlet ch = this.code, start = this.index;\n\n\t\tif (Jsep.isIdentifierStart(ch)) {\n\t\t\tthis.index++;\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unexpected ' + this.char);\n\t\t}\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tch = this.code;\n\n\t\t\tif (Jsep.isIdentifierPart(ch)) {\n\t\t\t\tthis.index++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: Jsep.IDENTIFIER,\n\t\t\tname: this.expr.slice(start, this.index),\n\t\t};\n\t}\n\n\t/**\n\t * Gobbles a list of arguments within the context of a function call\n\t * or array literal. This function also assumes that the opening character\n\t * `(` or `[` has already been gobbled, and gobbles expressions and commas\n\t * until the terminator character `)` or `]` is encountered.\n\t * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`\n\t * @param {number} termination\n\t * @returns {jsep.Expression[]}\n\t */\n\tgobbleArguments(termination) {\n\t\tconst args = [];\n\t\tlet closed = false;\n\t\tlet separator_count = 0;\n\n\t\twhile (this.index < this.expr.length) {\n\t\t\tthis.gobbleSpaces();\n\t\t\tlet ch_i = this.code;\n\n\t\t\tif (ch_i === termination) { // done parsing\n\t\t\t\tclosed = true;\n\t\t\t\tthis.index++;\n\n\t\t\t\tif (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length){\n\t\t\t\t\tthis.throwError('Unexpected token ' + String.fromCharCode(termination));\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (ch_i === Jsep.COMMA_CODE) { // between expressions\n\t\t\t\tthis.index++;\n\t\t\t\tseparator_count++;\n\n\t\t\t\tif (separator_count !== args.length) { // missing argument\n\t\t\t\t\tif (termination === Jsep.CPAREN_CODE) {\n\t\t\t\t\t\tthis.throwError('Unexpected token ,');\n\t\t\t\t\t}\n\t\t\t\t\telse if (termination === Jsep.CBRACK_CODE) {\n\t\t\t\t\t\tfor (let arg = args.length; arg < separator_count; arg++) {\n\t\t\t\t\t\t\targs.push(null);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (args.length !== separator_count && separator_count !== 0) {\n\t\t\t\t// NOTE: `&& separator_count !== 0` allows for either all commas, or all spaces as arguments\n\t\t\t\tthis.throwError('Expected comma');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tconst node = this.gobbleExpression();\n\n\t\t\t\tif (!node || node.type === Jsep.COMPOUND) {\n\t\t\t\t\tthis.throwError('Expected comma');\n\t\t\t\t}\n\n\t\t\t\targs.push(node);\n\t\t\t}\n\t\t}\n\n\t\tif (!closed) {\n\t\t\tthis.throwError('Expected ' + String.fromCharCode(termination));\n\t\t}\n\n\t\treturn args;\n\t}\n\n\t/**\n\t * Responsible for parsing a group of things within parentheses `()`\n\t * that have no identifier in front (so not a function call)\n\t * This function assumes that it needs to gobble the opening parenthesis\n\t * and then tries to gobble everything within that parenthesis, assuming\n\t * that the next thing it should see is the close parenthesis. If not,\n\t * then the expression probably doesn't have a `)`\n\t * @returns {boolean|jsep.Expression}\n\t */\n\tgobbleGroup() {\n\t\tthis.index++;\n\t\tlet nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);\n\t\tif (this.code === Jsep.CPAREN_CODE) {\n\t\t\tthis.index++;\n\t\t\tif (nodes.length === 1) {\n\t\t\t\treturn nodes[0];\n\t\t\t}\n\t\t\telse if (!nodes.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn {\n\t\t\t\t\ttype: Jsep.SEQUENCE_EXP,\n\t\t\t\t\texpressions: nodes,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthis.throwError('Unclosed (');\n\t\t}\n\t}\n\n\t/**\n\t * Responsible for parsing Array literals `[1, 2, 3]`\n\t * This function assumes that it needs to gobble the opening bracket\n\t * and then tries to gobble the expressions as arguments.\n\t * @returns {jsep.ArrayExpression}\n\t */\n\tgobbleArray() {\n\t\tthis.index++;\n\n\t\treturn {\n\t\t\ttype: Jsep.ARRAY_EXP,\n\t\t\telements: this.gobbleArguments(Jsep.CBRACK_CODE)\n\t\t};\n\t}\n}\n\n// Static fields:\nconst hooks = new Hooks();\nObject.assign(Jsep, {\n\thooks,\n\tplugins: new Plugins(Jsep),\n\n\t// Node Types\n\t// ----------\n\t// This is the full set of types that any JSEP node can be.\n\t// Store them here to save space when minified\n\tCOMPOUND: 'Compound',\n\tSEQUENCE_EXP: 'SequenceExpression',\n\tIDENTIFIER: 'Identifier',\n\tMEMBER_EXP: 'MemberExpression',\n\tLITERAL: 'Literal',\n\tTHIS_EXP: 'ThisExpression',\n\tCALL_EXP: 'CallExpression',\n\tUNARY_EXP: 'UnaryExpression',\n\tBINARY_EXP: 'BinaryExpression',\n\tARRAY_EXP: 'ArrayExpression',\n\n\tTAB_CODE: 9,\n\tLF_CODE: 10,\n\tCR_CODE: 13,\n\tSPACE_CODE: 32,\n\tPERIOD_CODE: 46, // '.'\n\tCOMMA_CODE: 44, // ','\n\tSQUOTE_CODE: 39, // single quote\n\tDQUOTE_CODE: 34, // double quotes\n\tOPAREN_CODE: 40, // (\n\tCPAREN_CODE: 41, // )\n\tOBRACK_CODE: 91, // [\n\tCBRACK_CODE: 93, // ]\n\tQUMARK_CODE: 63, // ?\n\tSEMCOL_CODE: 59, // ;\n\tCOLON_CODE: 58, // :\n\n\n\t// Operations\n\t// ----------\n\t// Use a quickly-accessible map to store all of the unary operators\n\t// Values are set to `1` (it really doesn't matter)\n\tunary_ops: {\n\t\t'-': 1,\n\t\t'!': 1,\n\t\t'~': 1,\n\t\t'+': 1\n\t},\n\n\t// Also use a map for the binary operations but set their values to their\n\t// binary precedence for quick reference (higher number = higher precedence)\n\t// see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)\n\tbinary_ops: {\n\t\t'||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,\n\t\t'==': 6, '!=': 6, '===': 6, '!==': 6,\n\t\t'<': 7, '>': 7, '<=': 7, '>=': 7,\n\t\t'<<': 8, '>>': 8, '>>>': 8,\n\t\t'+': 9, '-': 9,\n\t\t'*': 10, '/': 10, '%': 10\n\t},\n\n\t// sets specific binary_ops as right-associative\n\tright_associative: new Set(),\n\n\t// Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)\n\tadditional_identifier_chars: new Set(['$', '_']),\n\n\t// Literals\n\t// ----------\n\t// Store the values to return for the various literals we may encounter\n\tliterals: {\n\t\t'true': true,\n\t\t'false': false,\n\t\t'null': null\n\t},\n\n\t// Except for `this`, which is special. This could be changed to something like `'self'` as well\n\tthis_str: 'this',\n});\nJsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);\nJsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);\n\n// Backward Compatibility:\nconst jsep = expr => (new Jsep(expr)).parse();\nconst staticMethods = Object.getOwnPropertyNames(Jsep);\nstaticMethods\n\t.forEach((m) => {\n\t\tif (jsep[m] === undefined && m !== 'prototype') {\n\t\t\tjsep[m] = Jsep[m];\n\t\t}\n\t});\njsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep');\n\nconst CONDITIONAL_EXP = 'ConditionalExpression';\n\nvar ternary = {\n\tname: 'ternary',\n\n\tinit(jsep) {\n\t\t// Ternary expression: test ? consequent : alternate\n\t\tjsep.hooks.add('after-expression', function gobbleTernary(env) {\n\t\t\tif (env.node && this.code === jsep.QUMARK_CODE) {\n\t\t\t\tthis.index++;\n\t\t\t\tconst test = env.node;\n\t\t\t\tconst consequent = this.gobbleExpression();\n\n\t\t\t\tif (!consequent) {\n\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t}\n\n\t\t\t\tthis.gobbleSpaces();\n\n\t\t\t\tif (this.code === jsep.COLON_CODE) {\n\t\t\t\t\tthis.index++;\n\t\t\t\t\tconst alternate = this.gobbleExpression();\n\n\t\t\t\t\tif (!alternate) {\n\t\t\t\t\t\tthis.throwError('Expected expression');\n\t\t\t\t\t}\n\t\t\t\t\tenv.node = {\n\t\t\t\t\t\ttype: CONDITIONAL_EXP,\n\t\t\t\t\t\ttest,\n\t\t\t\t\t\tconsequent,\n\t\t\t\t\t\talternate,\n\t\t\t\t\t};\n\n\t\t\t\t\t// check for operators of higher priority than ternary (i.e. assignment)\n\t\t\t\t\t// jsep sets || at 1, and assignment at 0.9, and conditional should be between them\n\t\t\t\t\tif (test.operator && jsep.binary_ops[test.operator] <= 0.9) {\n\t\t\t\t\t\tlet newTest = test;\n\t\t\t\t\t\twhile (newTest.right.operator && jsep.binary_ops[newTest.right.operator] <= 0.9) {\n\t\t\t\t\t\t\tnewTest = newTest.right;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tenv.node.test = newTest.right;\n\t\t\t\t\t\tnewTest.right = env.node;\n\t\t\t\t\t\tenv.node = test;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.throwError('Expected :');\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t},\n};\n\n// Add default plugins:\n\njsep.plugins.register(ternary);\n\nexport { Jsep, jsep as default };\n", "/**\n * @private\n */\nconst ExpressionNodeType = {\n VARIABLE: 0,\n UNARY: 1,\n BINARY: 2,\n TERNARY: 3,\n CONDITIONAL: 4,\n MEMBER: 5,\n FUNCTION_CALL: 6,\n ARRAY: 7,\n REGEX: 8,\n VARIABLE_IN_STRING: 9,\n LITERAL_NULL: 10,\n LITERAL_BOOLEAN: 11,\n LITERAL_NUMBER: 12,\n LITERAL_STRING: 13,\n LITERAL_COLOR: 14,\n LITERAL_VECTOR: 15,\n LITERAL_REGEX: 16,\n LITERAL_UNDEFINED: 17,\n BUILTIN_VARIABLE: 18,\n};\nexport default Object.freeze(ExpressionNodeType);\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport jsep from \"jsep\";\nimport ExpressionNodeType from \"./ExpressionNodeType.js\";\n\n/**\n * An expression for a style applied to a {@link Cesium3DTileset}.\n *

\n * Evaluates an expression defined using the\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}.\n *

\n *

\n * Implements the {@link StyleExpression} interface.\n *

\n *\n * @alias Expression\n * @constructor\n *\n * @param {string} [expression] The expression defined using the 3D Tiles Styling language.\n * @param {object} [defines] Defines in the style.\n *\n * @example\n * const expression = new Cesium.Expression('(regExp(\"^Chest\").test(${County})) && (${YearBuilt} >= 1970)');\n * expression.evaluate(feature); // returns true or false depending on the feature's properties\n *\n * @example\n * const expression = new Cesium.Expression('(${Temperature} > 90) ? color(\"red\") : color(\"white\")');\n * expression.evaluateColor(feature, result); // returns a Cesium.Color object\n */\nfunction Expression(expression, defines) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"expression\", expression);\n //>>includeEnd('debug');\n\n this._expression = expression;\n expression = replaceDefines(expression, defines);\n expression = replaceVariables(removeBackslashes(expression));\n\n // customize jsep operators\n jsep.addBinaryOp(\"=~\", 0);\n jsep.addBinaryOp(\"!~\", 0);\n\n let ast;\n try {\n ast = jsep(expression);\n } catch (e) {\n throw new RuntimeError(e);\n }\n\n this._runtimeAst = createRuntimeAst(this, ast);\n}\n\nObject.defineProperties(Expression.prototype, {\n /**\n * Gets the expression defined in the 3D Tiles Styling language.\n *\n * @memberof Expression.prototype\n *\n * @type {string}\n * @readonly\n *\n * @default undefined\n */\n expression: {\n get: function () {\n return this._expression;\n },\n },\n});\n\n// Scratch storage manager while evaluating deep expressions.\n// For example, an expression like dot(vec4(${red}), vec4(${green}) * vec4(${blue}) requires 3 scratch Cartesian4's\nconst scratchStorage = {\n arrayIndex: 0,\n arrayArray: [[]],\n cartesian2Index: 0,\n cartesian3Index: 0,\n cartesian4Index: 0,\n cartesian2Array: [new Cartesian2()],\n cartesian3Array: [new Cartesian3()],\n cartesian4Array: [new Cartesian4()],\n reset: function () {\n this.arrayIndex = 0;\n this.cartesian2Index = 0;\n this.cartesian3Index = 0;\n this.cartesian4Index = 0;\n },\n getArray: function () {\n if (this.arrayIndex >= this.arrayArray.length) {\n this.arrayArray.push([]);\n }\n const array = this.arrayArray[this.arrayIndex++];\n array.length = 0;\n return array;\n },\n getCartesian2: function () {\n if (this.cartesian2Index >= this.cartesian2Array.length) {\n this.cartesian2Array.push(new Cartesian2());\n }\n return this.cartesian2Array[this.cartesian2Index++];\n },\n getCartesian3: function () {\n if (this.cartesian3Index >= this.cartesian3Array.length) {\n this.cartesian3Array.push(new Cartesian3());\n }\n return this.cartesian3Array[this.cartesian3Index++];\n },\n getCartesian4: function () {\n if (this.cartesian4Index >= this.cartesian4Array.length) {\n this.cartesian4Array.push(new Cartesian4());\n }\n return this.cartesian4Array[this.cartesian4Index++];\n },\n};\n\n/**\n * Evaluates the result of an expression, optionally using the provided feature's properties. If the result of\n * the expression in the\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}\n * is of type Boolean, Number, or String, the corresponding JavaScript\n * primitive type will be returned. If the result is a RegExp, a Javascript RegExp\n * object will be returned. If the result is a Cartesian2, Cartesian3, or Cartesian4,\n * a {@link Cartesian2}, {@link Cartesian3}, or {@link Cartesian4} object will be returned. If the result argument is\n * a {@link Color}, the {@link Cartesian4} value is converted to a {@link Color} and then returned.\n *\n * @param {Cesium3DTileFeature} feature The feature whose properties may be used as variables in the expression.\n * @param {object} [result] The object onto which to store the result.\n * @returns {boolean|number|string|RegExp|Cartesian2|Cartesian3|Cartesian4|Color} The result of evaluating the expression.\n */\nExpression.prototype.evaluate = function (feature, result) {\n scratchStorage.reset();\n const value = this._runtimeAst.evaluate(feature);\n if (result instanceof Color && value instanceof Cartesian4) {\n return Color.fromCartesian4(value, result);\n }\n if (\n value instanceof Cartesian2 ||\n value instanceof Cartesian3 ||\n value instanceof Cartesian4\n ) {\n return value.clone(result);\n }\n return value;\n};\n\n/**\n * Evaluates the result of a Color expression, optionally using the provided feature's properties.\n *

\n * This is equivalent to {@link Expression#evaluate} but always returns a {@link Color} object.\n *

\n *\n * @param {Cesium3DTileFeature} feature The feature whose properties may be used as variables in the expression.\n * @param {Color} [result] The object in which to store the result\n * @returns {Color} The modified result parameter or a new Color instance if one was not provided.\n */\nExpression.prototype.evaluateColor = function (feature, result) {\n scratchStorage.reset();\n const color = this._runtimeAst.evaluate(feature);\n return Color.fromCartesian4(color, result);\n};\n\n/**\n * Gets the shader function for this expression.\n * Returns undefined if the shader function can't be generated from this expression.\n *\n * @param {string} functionSignature Signature of the generated function.\n * @param {object} variableSubstitutionMap Maps variable names to shader variable names.\n * @param {object} shaderState Stores information about the generated shader function, including whether it is translucent.\n * @param {string} returnType The return type of the generated function.\n *\n * @returns {string} The shader function.\n *\n * @private\n */\nExpression.prototype.getShaderFunction = function (\n functionSignature,\n variableSubstitutionMap,\n shaderState,\n returnType\n) {\n let shaderExpression = this.getShaderExpression(\n variableSubstitutionMap,\n shaderState\n );\n\n shaderExpression =\n `${returnType} ${functionSignature}\\n` +\n `{\\n` +\n ` return ${shaderExpression};\\n` +\n `}\\n`;\n\n return shaderExpression;\n};\n\n/**\n * Gets the shader expression for this expression.\n * Returns undefined if the shader expression can't be generated from this expression.\n *\n * @param {object} variableSubstitutionMap Maps variable names to shader variable names.\n * @param {object} shaderState Stores information about the generated shader function, including whether it is translucent.\n *\n * @returns {string} The shader expression.\n *\n * @private\n */\nExpression.prototype.getShaderExpression = function (\n variableSubstitutionMap,\n shaderState\n) {\n return this._runtimeAst.getShaderExpression(\n variableSubstitutionMap,\n shaderState\n );\n};\n\n/**\n * Gets the variables used by the expression.\n *\n * @returns {string[]} The variables used by the expression.\n *\n * @private\n */\nExpression.prototype.getVariables = function () {\n let variables = [];\n\n this._runtimeAst.getVariables(variables);\n\n // Remove duplicates\n variables = variables.filter(function (variable, index, variables) {\n return variables.indexOf(variable) === index;\n });\n\n return variables;\n};\n\nconst unaryOperators = [\"!\", \"-\", \"+\"];\nconst binaryOperators = [\n \"+\",\n \"-\",\n \"*\",\n \"/\",\n \"%\",\n \"===\",\n \"!==\",\n \">\",\n \">=\",\n \"<\",\n \"<=\",\n \"&&\",\n \"||\",\n \"!~\",\n \"=~\",\n];\n\nconst variableRegex = /\\${(.*?)}/g; // Matches ${variable_name}\nconst backslashRegex = /\\\\/g;\nconst backslashReplacement = \"@#%\";\nconst replacementRegex = /@#%/g;\n\nconst scratchColor = new Color();\n\nconst unaryFunctions = {\n abs: getEvaluateUnaryComponentwise(Math.abs),\n sqrt: getEvaluateUnaryComponentwise(Math.sqrt),\n cos: getEvaluateUnaryComponentwise(Math.cos),\n sin: getEvaluateUnaryComponentwise(Math.sin),\n tan: getEvaluateUnaryComponentwise(Math.tan),\n acos: getEvaluateUnaryComponentwise(Math.acos),\n asin: getEvaluateUnaryComponentwise(Math.asin),\n atan: getEvaluateUnaryComponentwise(Math.atan),\n radians: getEvaluateUnaryComponentwise(CesiumMath.toRadians),\n degrees: getEvaluateUnaryComponentwise(CesiumMath.toDegrees),\n sign: getEvaluateUnaryComponentwise(CesiumMath.sign),\n floor: getEvaluateUnaryComponentwise(Math.floor),\n ceil: getEvaluateUnaryComponentwise(Math.ceil),\n round: getEvaluateUnaryComponentwise(Math.round),\n exp: getEvaluateUnaryComponentwise(Math.exp),\n exp2: getEvaluateUnaryComponentwise(exp2),\n log: getEvaluateUnaryComponentwise(Math.log),\n log2: getEvaluateUnaryComponentwise(log2),\n fract: getEvaluateUnaryComponentwise(fract),\n length: length,\n normalize: normalize,\n};\n\nconst binaryFunctions = {\n atan2: getEvaluateBinaryComponentwise(Math.atan2, false),\n pow: getEvaluateBinaryComponentwise(Math.pow, false),\n min: getEvaluateBinaryComponentwise(Math.min, true),\n max: getEvaluateBinaryComponentwise(Math.max, true),\n distance: distance,\n dot: dot,\n cross: cross,\n};\n\nconst ternaryFunctions = {\n clamp: getEvaluateTernaryComponentwise(CesiumMath.clamp, true),\n mix: getEvaluateTernaryComponentwise(CesiumMath.lerp, true),\n};\n\nfunction fract(number) {\n return number - Math.floor(number);\n}\n\nfunction exp2(exponent) {\n return Math.pow(2.0, exponent);\n}\n\nfunction log2(number) {\n return CesiumMath.log2(number);\n}\n\nfunction getEvaluateUnaryComponentwise(operation) {\n return function (call, left) {\n if (typeof left === \"number\") {\n return operation(left);\n } else if (left instanceof Cartesian2) {\n return Cartesian2.fromElements(\n operation(left.x),\n operation(left.y),\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian3) {\n return Cartesian3.fromElements(\n operation(left.x),\n operation(left.y),\n operation(left.z),\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian4) {\n return Cartesian4.fromElements(\n operation(left.x),\n operation(left.y),\n operation(left.z),\n operation(left.w),\n scratchStorage.getCartesian4()\n );\n }\n throw new RuntimeError(\n `Function \"${call}\" requires a vector or number argument. Argument is ${left}.`\n );\n };\n}\n\nfunction getEvaluateBinaryComponentwise(operation, allowScalar) {\n return function (call, left, right) {\n if (allowScalar && typeof right === \"number\") {\n if (typeof left === \"number\") {\n return operation(left, right);\n } else if (left instanceof Cartesian2) {\n return Cartesian2.fromElements(\n operation(left.x, right),\n operation(left.y, right),\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian3) {\n return Cartesian3.fromElements(\n operation(left.x, right),\n operation(left.y, right),\n operation(left.z, right),\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian4) {\n return Cartesian4.fromElements(\n operation(left.x, right),\n operation(left.y, right),\n operation(left.z, right),\n operation(left.w, right),\n scratchStorage.getCartesian4()\n );\n }\n }\n\n if (typeof left === \"number\" && typeof right === \"number\") {\n return operation(left, right);\n } else if (left instanceof Cartesian2 && right instanceof Cartesian2) {\n return Cartesian2.fromElements(\n operation(left.x, right.x),\n operation(left.y, right.y),\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian3 && right instanceof Cartesian3) {\n return Cartesian3.fromElements(\n operation(left.x, right.x),\n operation(left.y, right.y),\n operation(left.z, right.z),\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian4 && right instanceof Cartesian4) {\n return Cartesian4.fromElements(\n operation(left.x, right.x),\n operation(left.y, right.y),\n operation(left.z, right.z),\n operation(left.w, right.w),\n scratchStorage.getCartesian4()\n );\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires vector or number arguments of matching types. Arguments are ${left} and ${right}.`\n );\n };\n}\n\nfunction getEvaluateTernaryComponentwise(operation, allowScalar) {\n return function (call, left, right, test) {\n if (allowScalar && typeof test === \"number\") {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return operation(left, right, test);\n } else if (left instanceof Cartesian2 && right instanceof Cartesian2) {\n return Cartesian2.fromElements(\n operation(left.x, right.x, test),\n operation(left.y, right.y, test),\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian3 && right instanceof Cartesian3) {\n return Cartesian3.fromElements(\n operation(left.x, right.x, test),\n operation(left.y, right.y, test),\n operation(left.z, right.z, test),\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian4 && right instanceof Cartesian4) {\n return Cartesian4.fromElements(\n operation(left.x, right.x, test),\n operation(left.y, right.y, test),\n operation(left.z, right.z, test),\n operation(left.w, right.w, test),\n scratchStorage.getCartesian4()\n );\n }\n }\n\n if (\n typeof left === \"number\" &&\n typeof right === \"number\" &&\n typeof test === \"number\"\n ) {\n return operation(left, right, test);\n } else if (\n left instanceof Cartesian2 &&\n right instanceof Cartesian2 &&\n test instanceof Cartesian2\n ) {\n return Cartesian2.fromElements(\n operation(left.x, right.x, test.x),\n operation(left.y, right.y, test.y),\n scratchStorage.getCartesian2()\n );\n } else if (\n left instanceof Cartesian3 &&\n right instanceof Cartesian3 &&\n test instanceof Cartesian3\n ) {\n return Cartesian3.fromElements(\n operation(left.x, right.x, test.x),\n operation(left.y, right.y, test.y),\n operation(left.z, right.z, test.z),\n scratchStorage.getCartesian3()\n );\n } else if (\n left instanceof Cartesian4 &&\n right instanceof Cartesian4 &&\n test instanceof Cartesian4\n ) {\n return Cartesian4.fromElements(\n operation(left.x, right.x, test.x),\n operation(left.y, right.y, test.y),\n operation(left.z, right.z, test.z),\n operation(left.w, right.w, test.w),\n scratchStorage.getCartesian4()\n );\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires vector or number arguments of matching types. Arguments are ${left}, ${right}, and ${test}.`\n );\n };\n}\n\nfunction length(call, left) {\n if (typeof left === \"number\") {\n return Math.abs(left);\n } else if (left instanceof Cartesian2) {\n return Cartesian2.magnitude(left);\n } else if (left instanceof Cartesian3) {\n return Cartesian3.magnitude(left);\n } else if (left instanceof Cartesian4) {\n return Cartesian4.magnitude(left);\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires a vector or number argument. Argument is ${left}.`\n );\n}\n\nfunction normalize(call, left) {\n if (typeof left === \"number\") {\n return 1.0;\n } else if (left instanceof Cartesian2) {\n return Cartesian2.normalize(left, scratchStorage.getCartesian2());\n } else if (left instanceof Cartesian3) {\n return Cartesian3.normalize(left, scratchStorage.getCartesian3());\n } else if (left instanceof Cartesian4) {\n return Cartesian4.normalize(left, scratchStorage.getCartesian4());\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires a vector or number argument. Argument is ${left}.`\n );\n}\n\nfunction distance(call, left, right) {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return Math.abs(left - right);\n } else if (left instanceof Cartesian2 && right instanceof Cartesian2) {\n return Cartesian2.distance(left, right);\n } else if (left instanceof Cartesian3 && right instanceof Cartesian3) {\n return Cartesian3.distance(left, right);\n } else if (left instanceof Cartesian4 && right instanceof Cartesian4) {\n return Cartesian4.distance(left, right);\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires vector or number arguments of matching types. Arguments are ${left} and ${right}.`\n );\n}\n\nfunction dot(call, left, right) {\n if (typeof left === \"number\" && typeof right === \"number\") {\n return left * right;\n } else if (left instanceof Cartesian2 && right instanceof Cartesian2) {\n return Cartesian2.dot(left, right);\n } else if (left instanceof Cartesian3 && right instanceof Cartesian3) {\n return Cartesian3.dot(left, right);\n } else if (left instanceof Cartesian4 && right instanceof Cartesian4) {\n return Cartesian4.dot(left, right);\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires vector or number arguments of matching types. Arguments are ${left} and ${right}.`\n );\n}\n\nfunction cross(call, left, right) {\n if (left instanceof Cartesian3 && right instanceof Cartesian3) {\n return Cartesian3.cross(left, right, scratchStorage.getCartesian3());\n }\n\n throw new RuntimeError(\n `Function \"${call}\" requires vec3 arguments. Arguments are ${left} and ${right}.`\n );\n}\n\nfunction Node(type, value, left, right, test) {\n this._type = type;\n this._value = value;\n this._left = left;\n this._right = right;\n this._test = test;\n this.evaluate = undefined;\n\n setEvaluateFunction(this);\n}\n\nfunction replaceDefines(expression, defines) {\n if (!defined(defines)) {\n return expression;\n }\n for (const key in defines) {\n if (defines.hasOwnProperty(key)) {\n const definePlaceholder = new RegExp(`\\\\$\\\\{${key}\\\\}`, \"g\");\n const defineReplace = `(${defines[key]})`;\n if (defined(defineReplace)) {\n expression = expression.replace(definePlaceholder, defineReplace);\n }\n }\n }\n return expression;\n}\n\nfunction removeBackslashes(expression) {\n return expression.replace(backslashRegex, backslashReplacement);\n}\n\nfunction replaceBackslashes(expression) {\n return expression.replace(replacementRegex, \"\\\\\");\n}\n\nfunction replaceVariables(expression) {\n let exp = expression;\n let result = \"\";\n let i = exp.indexOf(\"${\");\n while (i >= 0) {\n // Check if string is inside quotes\n const openSingleQuote = exp.indexOf(\"'\");\n const openDoubleQuote = exp.indexOf('\"');\n let closeQuote;\n if (openSingleQuote >= 0 && openSingleQuote < i) {\n closeQuote = exp.indexOf(\"'\", openSingleQuote + 1);\n result += exp.substr(0, closeQuote + 1);\n exp = exp.substr(closeQuote + 1);\n i = exp.indexOf(\"${\");\n } else if (openDoubleQuote >= 0 && openDoubleQuote < i) {\n closeQuote = exp.indexOf('\"', openDoubleQuote + 1);\n result += exp.substr(0, closeQuote + 1);\n exp = exp.substr(closeQuote + 1);\n i = exp.indexOf(\"${\");\n } else {\n result += exp.substr(0, i);\n const j = exp.indexOf(\"}\");\n if (j < 0) {\n throw new RuntimeError(\"Unmatched {.\");\n }\n result += `czm_${exp.substr(i + 2, j - (i + 2))}`;\n exp = exp.substr(j + 1);\n i = exp.indexOf(\"${\");\n }\n }\n result += exp;\n return result;\n}\n\nfunction parseLiteral(ast) {\n const type = typeof ast.value;\n if (ast.value === null) {\n return new Node(ExpressionNodeType.LITERAL_NULL, null);\n } else if (type === \"boolean\") {\n return new Node(ExpressionNodeType.LITERAL_BOOLEAN, ast.value);\n } else if (type === \"number\") {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, ast.value);\n } else if (type === \"string\") {\n if (ast.value.indexOf(\"${\") >= 0) {\n return new Node(ExpressionNodeType.VARIABLE_IN_STRING, ast.value);\n }\n return new Node(\n ExpressionNodeType.LITERAL_STRING,\n replaceBackslashes(ast.value)\n );\n }\n}\n\nfunction parseCall(expression, ast) {\n const args = ast.arguments;\n const argsLength = args.length;\n let call;\n let val, left, right;\n\n // Member function calls\n if (ast.callee.type === \"MemberExpression\") {\n call = ast.callee.property.name;\n const object = ast.callee.object;\n if (call === \"test\" || call === \"exec\") {\n // Make sure this is called on a valid type\n if (!defined(object.callee) || object.callee.name !== \"regExp\") {\n throw new RuntimeError(`${call} is not a function.`);\n }\n if (argsLength === 0) {\n if (call === \"test\") {\n return new Node(ExpressionNodeType.LITERAL_BOOLEAN, false);\n }\n return new Node(ExpressionNodeType.LITERAL_NULL, null);\n }\n left = createRuntimeAst(expression, object);\n right = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.FUNCTION_CALL, call, left, right);\n } else if (call === \"toString\") {\n val = createRuntimeAst(expression, object);\n return new Node(ExpressionNodeType.FUNCTION_CALL, call, val);\n }\n\n throw new RuntimeError(`Unexpected function call \"${call}\".`);\n }\n\n // Non-member function calls\n call = ast.callee.name;\n if (call === \"color\") {\n if (argsLength === 0) {\n return new Node(ExpressionNodeType.LITERAL_COLOR, call);\n }\n val = createRuntimeAst(expression, args[0]);\n if (defined(args[1])) {\n const alpha = createRuntimeAst(expression, args[1]);\n return new Node(ExpressionNodeType.LITERAL_COLOR, call, [val, alpha]);\n }\n return new Node(ExpressionNodeType.LITERAL_COLOR, call, [val]);\n } else if (call === \"rgb\" || call === \"hsl\") {\n if (argsLength < 3) {\n throw new RuntimeError(`${call} requires three arguments.`);\n }\n val = [\n createRuntimeAst(expression, args[0]),\n createRuntimeAst(expression, args[1]),\n createRuntimeAst(expression, args[2]),\n ];\n return new Node(ExpressionNodeType.LITERAL_COLOR, call, val);\n } else if (call === \"rgba\" || call === \"hsla\") {\n if (argsLength < 4) {\n throw new RuntimeError(`${call} requires four arguments.`);\n }\n val = [\n createRuntimeAst(expression, args[0]),\n createRuntimeAst(expression, args[1]),\n createRuntimeAst(expression, args[2]),\n createRuntimeAst(expression, args[3]),\n ];\n return new Node(ExpressionNodeType.LITERAL_COLOR, call, val);\n } else if (call === \"vec2\" || call === \"vec3\" || call === \"vec4\") {\n // Check for invalid constructors at evaluation time\n val = new Array(argsLength);\n for (let i = 0; i < argsLength; ++i) {\n val[i] = createRuntimeAst(expression, args[i]);\n }\n return new Node(ExpressionNodeType.LITERAL_VECTOR, call, val);\n } else if (call === \"isNaN\" || call === \"isFinite\") {\n if (argsLength === 0) {\n if (call === \"isNaN\") {\n return new Node(ExpressionNodeType.LITERAL_BOOLEAN, true);\n }\n return new Node(ExpressionNodeType.LITERAL_BOOLEAN, false);\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (call === \"isExactClass\" || call === \"isClass\") {\n if (argsLength < 1 || argsLength > 1) {\n throw new RuntimeError(`${call} requires exactly one argument.`);\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (call === \"getExactClassName\") {\n if (argsLength > 0) {\n throw new RuntimeError(`${call} does not take any argument.`);\n }\n return new Node(ExpressionNodeType.UNARY, call);\n } else if (defined(unaryFunctions[call])) {\n if (argsLength !== 1) {\n throw new RuntimeError(`${call} requires exactly one argument.`);\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (defined(binaryFunctions[call])) {\n if (argsLength !== 2) {\n throw new RuntimeError(`${call} requires exactly two arguments.`);\n }\n left = createRuntimeAst(expression, args[0]);\n right = createRuntimeAst(expression, args[1]);\n return new Node(ExpressionNodeType.BINARY, call, left, right);\n } else if (defined(ternaryFunctions[call])) {\n if (argsLength !== 3) {\n throw new RuntimeError(`${call} requires exactly three arguments.`);\n }\n left = createRuntimeAst(expression, args[0]);\n right = createRuntimeAst(expression, args[1]);\n const test = createRuntimeAst(expression, args[2]);\n return new Node(ExpressionNodeType.TERNARY, call, left, right, test);\n } else if (call === \"Boolean\") {\n if (argsLength === 0) {\n return new Node(ExpressionNodeType.LITERAL_BOOLEAN, false);\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (call === \"Number\") {\n if (argsLength === 0) {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, 0);\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (call === \"String\") {\n if (argsLength === 0) {\n return new Node(ExpressionNodeType.LITERAL_STRING, \"\");\n }\n val = createRuntimeAst(expression, args[0]);\n return new Node(ExpressionNodeType.UNARY, call, val);\n } else if (call === \"regExp\") {\n return parseRegex(expression, ast);\n }\n\n throw new RuntimeError(`Unexpected function call \"${call}\".`);\n}\n\nfunction parseRegex(expression, ast) {\n const args = ast.arguments;\n // no arguments, return default regex\n if (args.length === 0) {\n return new Node(ExpressionNodeType.LITERAL_REGEX, new RegExp());\n }\n\n const pattern = createRuntimeAst(expression, args[0]);\n let exp;\n\n // optional flag argument supplied\n if (args.length > 1) {\n const flags = createRuntimeAst(expression, args[1]);\n if (isLiteralType(pattern) && isLiteralType(flags)) {\n try {\n exp = new RegExp(\n replaceBackslashes(String(pattern._value)),\n flags._value\n );\n } catch (e) {\n throw new RuntimeError(e);\n }\n return new Node(ExpressionNodeType.LITERAL_REGEX, exp);\n }\n return new Node(ExpressionNodeType.REGEX, pattern, flags);\n }\n\n // only pattern argument supplied\n if (isLiteralType(pattern)) {\n try {\n exp = new RegExp(replaceBackslashes(String(pattern._value)));\n } catch (e) {\n throw new RuntimeError(e);\n }\n return new Node(ExpressionNodeType.LITERAL_REGEX, exp);\n }\n return new Node(ExpressionNodeType.REGEX, pattern);\n}\n\nfunction parseKeywordsAndVariables(ast) {\n if (isVariable(ast.name)) {\n const name = getPropertyName(ast.name);\n if (name.substr(0, 8) === \"tiles3d_\") {\n return new Node(ExpressionNodeType.BUILTIN_VARIABLE, name);\n }\n return new Node(ExpressionNodeType.VARIABLE, name);\n } else if (ast.name === \"NaN\") {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, NaN);\n } else if (ast.name === \"Infinity\") {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, Infinity);\n } else if (ast.name === \"undefined\") {\n return new Node(ExpressionNodeType.LITERAL_UNDEFINED, undefined);\n }\n\n throw new RuntimeError(`${ast.name} is not defined.`);\n}\n\nfunction parseMathConstant(ast) {\n const name = ast.property.name;\n if (name === \"PI\") {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, Math.PI);\n } else if (name === \"E\") {\n return new Node(ExpressionNodeType.LITERAL_NUMBER, Math.E);\n }\n}\n\nfunction parseNumberConstant(ast) {\n const name = ast.property.name;\n if (name === \"POSITIVE_INFINITY\") {\n return new Node(\n ExpressionNodeType.LITERAL_NUMBER,\n Number.POSITIVE_INFINITY\n );\n }\n}\n\nfunction parseMemberExpression(expression, ast) {\n if (ast.object.name === \"Math\") {\n return parseMathConstant(ast);\n } else if (ast.object.name === \"Number\") {\n return parseNumberConstant(ast);\n }\n\n let val;\n const obj = createRuntimeAst(expression, ast.object);\n if (ast.computed) {\n val = createRuntimeAst(expression, ast.property);\n return new Node(ExpressionNodeType.MEMBER, \"brackets\", obj, val);\n }\n\n val = new Node(ExpressionNodeType.LITERAL_STRING, ast.property.name);\n return new Node(ExpressionNodeType.MEMBER, \"dot\", obj, val);\n}\n\nfunction isLiteralType(node) {\n return node._type >= ExpressionNodeType.LITERAL_NULL;\n}\n\nfunction isVariable(name) {\n return name.substr(0, 4) === \"czm_\";\n}\n\nfunction getPropertyName(variable) {\n return variable.substr(4);\n}\n\nfunction createRuntimeAst(expression, ast) {\n let node;\n let op;\n let left;\n let right;\n\n if (ast.type === \"Literal\") {\n node = parseLiteral(ast);\n } else if (ast.type === \"CallExpression\") {\n node = parseCall(expression, ast);\n } else if (ast.type === \"Identifier\") {\n node = parseKeywordsAndVariables(ast);\n } else if (ast.type === \"UnaryExpression\") {\n op = ast.operator;\n const child = createRuntimeAst(expression, ast.argument);\n if (unaryOperators.indexOf(op) > -1) {\n node = new Node(ExpressionNodeType.UNARY, op, child);\n } else {\n throw new RuntimeError(`Unexpected operator \"${op}\".`);\n }\n } else if (ast.type === \"BinaryExpression\") {\n op = ast.operator;\n left = createRuntimeAst(expression, ast.left);\n right = createRuntimeAst(expression, ast.right);\n if (binaryOperators.indexOf(op) > -1) {\n node = new Node(ExpressionNodeType.BINARY, op, left, right);\n } else {\n throw new RuntimeError(`Unexpected operator \"${op}\".`);\n }\n } else if (ast.type === \"LogicalExpression\") {\n op = ast.operator;\n left = createRuntimeAst(expression, ast.left);\n right = createRuntimeAst(expression, ast.right);\n if (binaryOperators.indexOf(op) > -1) {\n node = new Node(ExpressionNodeType.BINARY, op, left, right);\n }\n } else if (ast.type === \"ConditionalExpression\") {\n const test = createRuntimeAst(expression, ast.test);\n left = createRuntimeAst(expression, ast.consequent);\n right = createRuntimeAst(expression, ast.alternate);\n node = new Node(ExpressionNodeType.CONDITIONAL, \"?\", left, right, test);\n } else if (ast.type === \"MemberExpression\") {\n node = parseMemberExpression(expression, ast);\n } else if (ast.type === \"ArrayExpression\") {\n const val = [];\n for (let i = 0; i < ast.elements.length; i++) {\n val[i] = createRuntimeAst(expression, ast.elements[i]);\n }\n node = new Node(ExpressionNodeType.ARRAY, val);\n } else if (ast.type === \"Compound\") {\n // empty expression or multiple expressions\n throw new RuntimeError(\"Provide exactly one expression.\");\n } else {\n throw new RuntimeError(\"Cannot parse expression.\");\n }\n\n return node;\n}\n\nfunction setEvaluateFunction(node) {\n if (node._type === ExpressionNodeType.CONDITIONAL) {\n node.evaluate = node._evaluateConditional;\n } else if (node._type === ExpressionNodeType.FUNCTION_CALL) {\n if (node._value === \"test\") {\n node.evaluate = node._evaluateRegExpTest;\n } else if (node._value === \"exec\") {\n node.evaluate = node._evaluateRegExpExec;\n } else if (node._value === \"toString\") {\n node.evaluate = node._evaluateToString;\n }\n } else if (node._type === ExpressionNodeType.UNARY) {\n if (node._value === \"!\") {\n node.evaluate = node._evaluateNot;\n } else if (node._value === \"-\") {\n node.evaluate = node._evaluateNegative;\n } else if (node._value === \"+\") {\n node.evaluate = node._evaluatePositive;\n } else if (node._value === \"isNaN\") {\n node.evaluate = node._evaluateNaN;\n } else if (node._value === \"isFinite\") {\n node.evaluate = node._evaluateIsFinite;\n } else if (node._value === \"isExactClass\") {\n node.evaluate = node._evaluateIsExactClass;\n } else if (node._value === \"isClass\") {\n node.evaluate = node._evaluateIsClass;\n } else if (node._value === \"getExactClassName\") {\n node.evaluate = node._evaluateGetExactClassName;\n } else if (node._value === \"Boolean\") {\n node.evaluate = node._evaluateBooleanConversion;\n } else if (node._value === \"Number\") {\n node.evaluate = node._evaluateNumberConversion;\n } else if (node._value === \"String\") {\n node.evaluate = node._evaluateStringConversion;\n } else if (defined(unaryFunctions[node._value])) {\n node.evaluate = getEvaluateUnaryFunction(node._value);\n }\n } else if (node._type === ExpressionNodeType.BINARY) {\n if (node._value === \"+\") {\n node.evaluate = node._evaluatePlus;\n } else if (node._value === \"-\") {\n node.evaluate = node._evaluateMinus;\n } else if (node._value === \"*\") {\n node.evaluate = node._evaluateTimes;\n } else if (node._value === \"/\") {\n node.evaluate = node._evaluateDivide;\n } else if (node._value === \"%\") {\n node.evaluate = node._evaluateMod;\n } else if (node._value === \"===\") {\n node.evaluate = node._evaluateEqualsStrict;\n } else if (node._value === \"!==\") {\n node.evaluate = node._evaluateNotEqualsStrict;\n } else if (node._value === \"<\") {\n node.evaluate = node._evaluateLessThan;\n } else if (node._value === \"<=\") {\n node.evaluate = node._evaluateLessThanOrEquals;\n } else if (node._value === \">\") {\n node.evaluate = node._evaluateGreaterThan;\n } else if (node._value === \">=\") {\n node.evaluate = node._evaluateGreaterThanOrEquals;\n } else if (node._value === \"&&\") {\n node.evaluate = node._evaluateAnd;\n } else if (node._value === \"||\") {\n node.evaluate = node._evaluateOr;\n } else if (node._value === \"=~\") {\n node.evaluate = node._evaluateRegExpMatch;\n } else if (node._value === \"!~\") {\n node.evaluate = node._evaluateRegExpNotMatch;\n } else if (defined(binaryFunctions[node._value])) {\n node.evaluate = getEvaluateBinaryFunction(node._value);\n }\n } else if (node._type === ExpressionNodeType.TERNARY) {\n node.evaluate = getEvaluateTernaryFunction(node._value);\n } else if (node._type === ExpressionNodeType.MEMBER) {\n if (node._value === \"brackets\") {\n node.evaluate = node._evaluateMemberBrackets;\n } else {\n node.evaluate = node._evaluateMemberDot;\n }\n } else if (node._type === ExpressionNodeType.ARRAY) {\n node.evaluate = node._evaluateArray;\n } else if (node._type === ExpressionNodeType.VARIABLE) {\n node.evaluate = node._evaluateVariable;\n } else if (node._type === ExpressionNodeType.VARIABLE_IN_STRING) {\n node.evaluate = node._evaluateVariableString;\n } else if (node._type === ExpressionNodeType.LITERAL_COLOR) {\n node.evaluate = node._evaluateLiteralColor;\n } else if (node._type === ExpressionNodeType.LITERAL_VECTOR) {\n node.evaluate = node._evaluateLiteralVector;\n } else if (node._type === ExpressionNodeType.LITERAL_STRING) {\n node.evaluate = node._evaluateLiteralString;\n } else if (node._type === ExpressionNodeType.REGEX) {\n node.evaluate = node._evaluateRegExp;\n } else if (node._type === ExpressionNodeType.BUILTIN_VARIABLE) {\n if (node._value === \"tiles3d_tileset_time\") {\n node.evaluate = evaluateTilesetTime;\n }\n } else {\n node.evaluate = node._evaluateLiteral;\n }\n}\n\nfunction evaluateTilesetTime(feature) {\n if (!defined(feature)) {\n return 0.0;\n }\n return feature.content.tileset.timeSinceLoad;\n}\n\nfunction getEvaluateUnaryFunction(call) {\n const evaluate = unaryFunctions[call];\n return function (feature) {\n const left = this._left.evaluate(feature);\n return evaluate(call, left);\n };\n}\n\nfunction getEvaluateBinaryFunction(call) {\n const evaluate = binaryFunctions[call];\n return function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n return evaluate(call, left, right);\n };\n}\n\nfunction getEvaluateTernaryFunction(call) {\n const evaluate = ternaryFunctions[call];\n return function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n const test = this._test.evaluate(feature);\n return evaluate(call, left, right, test);\n };\n}\n\nfunction getFeatureProperty(feature, name) {\n // Returns undefined if the feature is not defined or the property name is not defined for that feature\n if (defined(feature)) {\n return feature.getPropertyInherited(name);\n }\n}\n\nNode.prototype._evaluateLiteral = function () {\n return this._value;\n};\n\nNode.prototype._evaluateLiteralColor = function (feature) {\n const color = scratchColor;\n const args = this._left;\n if (this._value === \"color\") {\n if (!defined(args)) {\n Color.fromBytes(255, 255, 255, 255, color);\n } else if (args.length > 1) {\n Color.fromCssColorString(args[0].evaluate(feature), color);\n color.alpha = args[1].evaluate(feature);\n } else {\n Color.fromCssColorString(args[0].evaluate(feature), color);\n }\n } else if (this._value === \"rgb\") {\n Color.fromBytes(\n args[0].evaluate(feature),\n args[1].evaluate(feature),\n args[2].evaluate(feature),\n 255,\n color\n );\n } else if (this._value === \"rgba\") {\n // convert between css alpha (0 to 1) and cesium alpha (0 to 255)\n const a = args[3].evaluate(feature) * 255;\n Color.fromBytes(\n args[0].evaluate(feature),\n args[1].evaluate(feature),\n args[2].evaluate(feature),\n a,\n color\n );\n } else if (this._value === \"hsl\") {\n Color.fromHsl(\n args[0].evaluate(feature),\n args[1].evaluate(feature),\n args[2].evaluate(feature),\n 1.0,\n color\n );\n } else if (this._value === \"hsla\") {\n Color.fromHsl(\n args[0].evaluate(feature),\n args[1].evaluate(feature),\n args[2].evaluate(feature),\n args[3].evaluate(feature),\n color\n );\n }\n return Cartesian4.fromColor(color, scratchStorage.getCartesian4());\n};\n\nNode.prototype._evaluateLiteralVector = function (feature) {\n // Gather the components that make up the vector, which includes components from interior vectors.\n // For example vec3(1, 2, 3) or vec3(vec2(1, 2), 3) are both valid.\n //\n // If the number of components does not equal the vector's size, then a RuntimeError is thrown - with two exceptions:\n // 1. A vector may be constructed from a larger vector and drop the extra components.\n // 2. A vector may be constructed from a single component - vec3(1) will become vec3(1, 1, 1).\n //\n // Examples of invalid constructors include:\n // vec4(1, 2) // not enough components\n // vec3(vec2(1, 2)) // not enough components\n // vec3(1, 2, 3, 4) // too many components\n // vec2(vec4(1), 1) // too many components\n\n const components = scratchStorage.getArray();\n const call = this._value;\n const args = this._left;\n const argsLength = args.length;\n for (let i = 0; i < argsLength; ++i) {\n const value = args[i].evaluate(feature);\n if (typeof value === \"number\") {\n components.push(value);\n } else if (value instanceof Cartesian2) {\n components.push(value.x, value.y);\n } else if (value instanceof Cartesian3) {\n components.push(value.x, value.y, value.z);\n } else if (value instanceof Cartesian4) {\n components.push(value.x, value.y, value.z, value.w);\n } else {\n throw new RuntimeError(\n `${call} argument must be a vector or number. Argument is ${value}.`\n );\n }\n }\n\n const componentsLength = components.length;\n const vectorLength = parseInt(call.charAt(3));\n\n if (componentsLength === 0) {\n throw new RuntimeError(`Invalid ${call} constructor. No valid arguments.`);\n } else if (componentsLength < vectorLength && componentsLength > 1) {\n throw new RuntimeError(\n `Invalid ${call} constructor. Not enough arguments.`\n );\n } else if (componentsLength > vectorLength && argsLength > 1) {\n throw new RuntimeError(`Invalid ${call} constructor. Too many arguments.`);\n }\n\n if (componentsLength === 1) {\n // Add the same component 3 more times\n const component = components[0];\n components.push(component, component, component);\n }\n\n if (call === \"vec2\") {\n return Cartesian2.fromArray(components, 0, scratchStorage.getCartesian2());\n } else if (call === \"vec3\") {\n return Cartesian3.fromArray(components, 0, scratchStorage.getCartesian3());\n } else if (call === \"vec4\") {\n return Cartesian4.fromArray(components, 0, scratchStorage.getCartesian4());\n }\n};\n\nNode.prototype._evaluateLiteralString = function () {\n return this._value;\n};\n\nNode.prototype._evaluateVariableString = function (feature) {\n let result = this._value;\n let match = variableRegex.exec(result);\n while (match !== null) {\n const placeholder = match[0];\n const variableName = match[1];\n let property = getFeatureProperty(feature, variableName);\n if (!defined(property)) {\n property = \"\";\n }\n result = result.replace(placeholder, property);\n match = variableRegex.exec(result);\n }\n return result;\n};\n\nNode.prototype._evaluateVariable = function (feature) {\n // evaluates to undefined if the property name is not defined for that feature\n return getFeatureProperty(feature, this._value);\n};\n\nfunction checkFeature(ast) {\n return ast._value === \"feature\";\n}\n\n// PERFORMANCE_IDEA: Determine if parent property needs to be computed before runtime\nNode.prototype._evaluateMemberDot = function (feature) {\n if (checkFeature(this._left)) {\n return getFeatureProperty(feature, this._right.evaluate(feature));\n }\n const property = this._left.evaluate(feature);\n if (!defined(property)) {\n return undefined;\n }\n\n const member = this._right.evaluate(feature);\n if (\n property instanceof Cartesian2 ||\n property instanceof Cartesian3 ||\n property instanceof Cartesian4\n ) {\n // Vector components may be accessed with .r, .g, .b, .a and implicitly with .x, .y, .z, .w\n if (member === \"r\") {\n return property.x;\n } else if (member === \"g\") {\n return property.y;\n } else if (member === \"b\") {\n return property.z;\n } else if (member === \"a\") {\n return property.w;\n }\n }\n return property[member];\n};\n\nNode.prototype._evaluateMemberBrackets = function (feature) {\n if (checkFeature(this._left)) {\n return getFeatureProperty(feature, this._right.evaluate(feature));\n }\n const property = this._left.evaluate(feature);\n if (!defined(property)) {\n return undefined;\n }\n\n const member = this._right.evaluate(feature);\n if (\n property instanceof Cartesian2 ||\n property instanceof Cartesian3 ||\n property instanceof Cartesian4\n ) {\n // Vector components may be accessed with [0][1][2][3], ['r']['g']['b']['a'] and implicitly with ['x']['y']['z']['w']\n // For Cartesian2 and Cartesian3 out-of-range components will just return undefined\n if (member === 0 || member === \"r\") {\n return property.x;\n } else if (member === 1 || member === \"g\") {\n return property.y;\n } else if (member === 2 || member === \"b\") {\n return property.z;\n } else if (member === 3 || member === \"a\") {\n return property.w;\n }\n }\n return property[member];\n};\n\nNode.prototype._evaluateArray = function (feature) {\n const array = [];\n for (let i = 0; i < this._value.length; i++) {\n array[i] = this._value[i].evaluate(feature);\n }\n return array;\n};\n\n// PERFORMANCE_IDEA: Have \"fast path\" functions that deal only with specific types\n// that we can assign if we know the types before runtime\n\nNode.prototype._evaluateNot = function (feature) {\n const left = this._left.evaluate(feature);\n if (typeof left !== \"boolean\") {\n throw new RuntimeError(\n `Operator \"!\" requires a boolean argument. Argument is ${left}.`\n );\n }\n return !left;\n};\n\nNode.prototype._evaluateNegative = function (feature) {\n const left = this._left.evaluate(feature);\n if (left instanceof Cartesian2) {\n return Cartesian2.negate(left, scratchStorage.getCartesian2());\n } else if (left instanceof Cartesian3) {\n return Cartesian3.negate(left, scratchStorage.getCartesian3());\n } else if (left instanceof Cartesian4) {\n return Cartesian4.negate(left, scratchStorage.getCartesian4());\n } else if (typeof left === \"number\") {\n return -left;\n }\n\n throw new RuntimeError(\n `Operator \"-\" requires a vector or number argument. Argument is ${left}.`\n );\n};\n\nNode.prototype._evaluatePositive = function (feature) {\n const left = this._left.evaluate(feature);\n\n if (\n !(\n left instanceof Cartesian2 ||\n left instanceof Cartesian3 ||\n left instanceof Cartesian4 ||\n typeof left === \"number\"\n )\n ) {\n throw new RuntimeError(\n `Operator \"+\" requires a vector or number argument. Argument is ${left}.`\n );\n }\n\n return left;\n};\n\nNode.prototype._evaluateLessThan = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (typeof left !== \"number\" || typeof right !== \"number\") {\n throw new RuntimeError(\n `Operator \"<\" requires number arguments. Arguments are ${left} and ${right}.`\n );\n }\n\n return left < right;\n};\n\nNode.prototype._evaluateLessThanOrEquals = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (typeof left !== \"number\" || typeof right !== \"number\") {\n throw new RuntimeError(\n `Operator \"<=\" requires number arguments. Arguments are ${left} and ${right}.`\n );\n }\n\n return left <= right;\n};\n\nNode.prototype._evaluateGreaterThan = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (typeof left !== \"number\" || typeof right !== \"number\") {\n throw new RuntimeError(\n `Operator \">\" requires number arguments. Arguments are ${left} and ${right}.`\n );\n }\n\n return left > right;\n};\n\nNode.prototype._evaluateGreaterThanOrEquals = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (typeof left !== \"number\" || typeof right !== \"number\") {\n throw new RuntimeError(\n `Operator \">=\" requires number arguments. Arguments are ${left} and ${right}.`\n );\n }\n\n return left >= right;\n};\n\nNode.prototype._evaluateOr = function (feature) {\n const left = this._left.evaluate(feature);\n if (typeof left !== \"boolean\") {\n throw new RuntimeError(\n `Operator \"||\" requires boolean arguments. First argument is ${left}.`\n );\n }\n\n // short circuit the expression\n if (left) {\n return true;\n }\n\n const right = this._right.evaluate(feature);\n if (typeof right !== \"boolean\") {\n throw new RuntimeError(\n `Operator \"||\" requires boolean arguments. Second argument is ${right}.`\n );\n }\n\n return left || right;\n};\n\nNode.prototype._evaluateAnd = function (feature) {\n const left = this._left.evaluate(feature);\n if (typeof left !== \"boolean\") {\n throw new RuntimeError(\n `Operator \"&&\" requires boolean arguments. First argument is ${left}.`\n );\n }\n\n // short circuit the expression\n if (!left) {\n return false;\n }\n\n const right = this._right.evaluate(feature);\n if (typeof right !== \"boolean\") {\n throw new RuntimeError(\n `Operator \"&&\" requires boolean arguments. Second argument is ${right}.`\n );\n }\n\n return left && right;\n};\n\nNode.prototype._evaluatePlus = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (right instanceof Cartesian2 && left instanceof Cartesian2) {\n return Cartesian2.add(left, right, scratchStorage.getCartesian2());\n } else if (right instanceof Cartesian3 && left instanceof Cartesian3) {\n return Cartesian3.add(left, right, scratchStorage.getCartesian3());\n } else if (right instanceof Cartesian4 && left instanceof Cartesian4) {\n return Cartesian4.add(left, right, scratchStorage.getCartesian4());\n } else if (typeof left === \"string\" || typeof right === \"string\") {\n // If only one argument is a string the other argument calls its toString function.\n return left + right;\n } else if (typeof left === \"number\" && typeof right === \"number\") {\n return left + right;\n }\n\n throw new RuntimeError(\n `Operator \"+\" requires vector or number arguments of matching types, or at least one string argument. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateMinus = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (right instanceof Cartesian2 && left instanceof Cartesian2) {\n return Cartesian2.subtract(left, right, scratchStorage.getCartesian2());\n } else if (right instanceof Cartesian3 && left instanceof Cartesian3) {\n return Cartesian3.subtract(left, right, scratchStorage.getCartesian3());\n } else if (right instanceof Cartesian4 && left instanceof Cartesian4) {\n return Cartesian4.subtract(left, right, scratchStorage.getCartesian4());\n } else if (typeof left === \"number\" && typeof right === \"number\") {\n return left - right;\n }\n\n throw new RuntimeError(\n `Operator \"-\" requires vector or number arguments of matching types. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateTimes = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (right instanceof Cartesian2 && left instanceof Cartesian2) {\n return Cartesian2.multiplyComponents(\n left,\n right,\n scratchStorage.getCartesian2()\n );\n } else if (right instanceof Cartesian2 && typeof left === \"number\") {\n return Cartesian2.multiplyByScalar(\n right,\n left,\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian2 && typeof right === \"number\") {\n return Cartesian2.multiplyByScalar(\n left,\n right,\n scratchStorage.getCartesian2()\n );\n } else if (right instanceof Cartesian3 && left instanceof Cartesian3) {\n return Cartesian3.multiplyComponents(\n left,\n right,\n scratchStorage.getCartesian3()\n );\n } else if (right instanceof Cartesian3 && typeof left === \"number\") {\n return Cartesian3.multiplyByScalar(\n right,\n left,\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian3 && typeof right === \"number\") {\n return Cartesian3.multiplyByScalar(\n left,\n right,\n scratchStorage.getCartesian3()\n );\n } else if (right instanceof Cartesian4 && left instanceof Cartesian4) {\n return Cartesian4.multiplyComponents(\n left,\n right,\n scratchStorage.getCartesian4()\n );\n } else if (right instanceof Cartesian4 && typeof left === \"number\") {\n return Cartesian4.multiplyByScalar(\n right,\n left,\n scratchStorage.getCartesian4()\n );\n } else if (left instanceof Cartesian4 && typeof right === \"number\") {\n return Cartesian4.multiplyByScalar(\n left,\n right,\n scratchStorage.getCartesian4()\n );\n } else if (typeof left === \"number\" && typeof right === \"number\") {\n return left * right;\n }\n\n throw new RuntimeError(\n `Operator \"*\" requires vector or number arguments. If both arguments are vectors they must be matching types. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateDivide = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (right instanceof Cartesian2 && left instanceof Cartesian2) {\n return Cartesian2.divideComponents(\n left,\n right,\n scratchStorage.getCartesian2()\n );\n } else if (left instanceof Cartesian2 && typeof right === \"number\") {\n return Cartesian2.divideByScalar(\n left,\n right,\n scratchStorage.getCartesian2()\n );\n } else if (right instanceof Cartesian3 && left instanceof Cartesian3) {\n return Cartesian3.divideComponents(\n left,\n right,\n scratchStorage.getCartesian3()\n );\n } else if (left instanceof Cartesian3 && typeof right === \"number\") {\n return Cartesian3.divideByScalar(\n left,\n right,\n scratchStorage.getCartesian3()\n );\n } else if (right instanceof Cartesian4 && left instanceof Cartesian4) {\n return Cartesian4.divideComponents(\n left,\n right,\n scratchStorage.getCartesian4()\n );\n } else if (left instanceof Cartesian4 && typeof right === \"number\") {\n return Cartesian4.divideByScalar(\n left,\n right,\n scratchStorage.getCartesian4()\n );\n } else if (typeof left === \"number\" && typeof right === \"number\") {\n return left / right;\n }\n\n throw new RuntimeError(\n `Operator \"/\" requires vector or number arguments of matching types, or a number as the second argument. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateMod = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (right instanceof Cartesian2 && left instanceof Cartesian2) {\n return Cartesian2.fromElements(\n left.x % right.x,\n left.y % right.y,\n scratchStorage.getCartesian2()\n );\n } else if (right instanceof Cartesian3 && left instanceof Cartesian3) {\n return Cartesian3.fromElements(\n left.x % right.x,\n left.y % right.y,\n left.z % right.z,\n scratchStorage.getCartesian3()\n );\n } else if (right instanceof Cartesian4 && left instanceof Cartesian4) {\n return Cartesian4.fromElements(\n left.x % right.x,\n left.y % right.y,\n left.z % right.z,\n left.w % right.w,\n scratchStorage.getCartesian4()\n );\n } else if (typeof left === \"number\" && typeof right === \"number\") {\n return left % right;\n }\n\n throw new RuntimeError(\n `Operator \"%\" requires vector or number arguments of matching types. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateEqualsStrict = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (\n (right instanceof Cartesian2 && left instanceof Cartesian2) ||\n (right instanceof Cartesian3 && left instanceof Cartesian3) ||\n (right instanceof Cartesian4 && left instanceof Cartesian4)\n ) {\n return left.equals(right);\n }\n return left === right;\n};\n\nNode.prototype._evaluateNotEqualsStrict = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n if (\n (right instanceof Cartesian2 && left instanceof Cartesian2) ||\n (right instanceof Cartesian3 && left instanceof Cartesian3) ||\n (right instanceof Cartesian4 && left instanceof Cartesian4)\n ) {\n return !left.equals(right);\n }\n return left !== right;\n};\n\nNode.prototype._evaluateConditional = function (feature) {\n const test = this._test.evaluate(feature);\n\n if (typeof test !== \"boolean\") {\n throw new RuntimeError(\n `Conditional argument of conditional expression must be a boolean. Argument is ${test}.`\n );\n }\n\n if (test) {\n return this._left.evaluate(feature);\n }\n return this._right.evaluate(feature);\n};\n\nNode.prototype._evaluateNaN = function (feature) {\n return isNaN(this._left.evaluate(feature));\n};\n\nNode.prototype._evaluateIsFinite = function (feature) {\n return isFinite(this._left.evaluate(feature));\n};\n\nNode.prototype._evaluateIsExactClass = function (feature) {\n if (defined(feature)) {\n return feature.isExactClass(this._left.evaluate(feature));\n }\n return false;\n};\n\nNode.prototype._evaluateIsClass = function (feature) {\n if (defined(feature)) {\n return feature.isClass(this._left.evaluate(feature));\n }\n return false;\n};\n\nNode.prototype._evaluateGetExactClassName = function (feature) {\n if (defined(feature)) {\n return feature.getExactClassName();\n }\n};\n\nNode.prototype._evaluateBooleanConversion = function (feature) {\n return Boolean(this._left.evaluate(feature));\n};\n\nNode.prototype._evaluateNumberConversion = function (feature) {\n return Number(this._left.evaluate(feature));\n};\n\nNode.prototype._evaluateStringConversion = function (feature) {\n return String(this._left.evaluate(feature));\n};\n\nNode.prototype._evaluateRegExp = function (feature) {\n const pattern = this._value.evaluate(feature);\n let flags = \"\";\n\n if (defined(this._left)) {\n flags = this._left.evaluate(feature);\n }\n\n let exp;\n try {\n exp = new RegExp(pattern, flags);\n } catch (e) {\n throw new RuntimeError(e);\n }\n return exp;\n};\n\nNode.prototype._evaluateRegExpTest = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (!(left instanceof RegExp && typeof right === \"string\")) {\n throw new RuntimeError(\n `RegExp.test requires the first argument to be a RegExp and the second argument to be a string. Arguments are ${left} and ${right}.`\n );\n }\n\n return left.test(right);\n};\n\nNode.prototype._evaluateRegExpMatch = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (left instanceof RegExp && typeof right === \"string\") {\n return left.test(right);\n } else if (right instanceof RegExp && typeof left === \"string\") {\n return right.test(left);\n }\n\n throw new RuntimeError(\n `Operator \"=~\" requires one RegExp argument and one string argument. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateRegExpNotMatch = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (left instanceof RegExp && typeof right === \"string\") {\n return !left.test(right);\n } else if (right instanceof RegExp && typeof left === \"string\") {\n return !right.test(left);\n }\n\n throw new RuntimeError(\n `Operator \"!~\" requires one RegExp argument and one string argument. Arguments are ${left} and ${right}.`\n );\n};\n\nNode.prototype._evaluateRegExpExec = function (feature) {\n const left = this._left.evaluate(feature);\n const right = this._right.evaluate(feature);\n\n if (!(left instanceof RegExp && typeof right === \"string\")) {\n throw new RuntimeError(\n `RegExp.exec requires the first argument to be a RegExp and the second argument to be a string. Arguments are ${left} and ${right}.`\n );\n }\n\n const exec = left.exec(right);\n if (!defined(exec)) {\n return null;\n }\n return exec[1];\n};\n\nNode.prototype._evaluateToString = function (feature) {\n const left = this._left.evaluate(feature);\n if (\n left instanceof RegExp ||\n left instanceof Cartesian2 ||\n left instanceof Cartesian3 ||\n left instanceof Cartesian4\n ) {\n return String(left);\n }\n\n throw new RuntimeError(`Unexpected function call \"${this._value}\".`);\n};\n\nfunction convertHSLToRGB(ast) {\n // Check if the color contains any nested expressions to see if the color can be converted here.\n // E.g. \"hsl(0.9, 0.6, 0.7)\" is able to convert directly to rgb, \"hsl(0.9, 0.6, ${Height})\" is not.\n const channels = ast._left;\n const length = channels.length;\n for (let i = 0; i < length; ++i) {\n if (channels[i]._type !== ExpressionNodeType.LITERAL_NUMBER) {\n return undefined;\n }\n }\n const h = channels[0]._value;\n const s = channels[1]._value;\n const l = channels[2]._value;\n const a = length === 4 ? channels[3]._value : 1.0;\n return Color.fromHsl(h, s, l, a, scratchColor);\n}\n\nfunction convertRGBToColor(ast) {\n // Check if the color contains any nested expressions to see if the color can be converted here.\n // E.g. \"rgb(255, 255, 255)\" is able to convert directly to Color, \"rgb(255, 255, ${Height})\" is not.\n const channels = ast._left;\n const length = channels.length;\n for (let i = 0; i < length; ++i) {\n if (channels[i]._type !== ExpressionNodeType.LITERAL_NUMBER) {\n return undefined;\n }\n }\n const color = scratchColor;\n color.red = channels[0]._value / 255.0;\n color.green = channels[1]._value / 255.0;\n color.blue = channels[2]._value / 255.0;\n color.alpha = length === 4 ? channels[3]._value : 1.0;\n return color;\n}\n\nfunction numberToString(number) {\n if (number % 1 === 0) {\n // Add a .0 to whole numbers\n return number.toFixed(1);\n }\n\n return number.toString();\n}\n\nfunction colorToVec3(color) {\n const r = numberToString(color.red);\n const g = numberToString(color.green);\n const b = numberToString(color.blue);\n return `vec3(${r}, ${g}, ${b})`;\n}\n\nfunction colorToVec4(color) {\n const r = numberToString(color.red);\n const g = numberToString(color.green);\n const b = numberToString(color.blue);\n const a = numberToString(color.alpha);\n return `vec4(${r}, ${g}, ${b}, ${a})`;\n}\n\nfunction getExpressionArray(\n array,\n variableSubstitutionMap,\n shaderState,\n parent\n) {\n const length = array.length;\n const expressions = new Array(length);\n for (let i = 0; i < length; ++i) {\n expressions[i] = array[i].getShaderExpression(\n variableSubstitutionMap,\n shaderState,\n parent\n );\n }\n return expressions;\n}\n\nfunction getVariableName(variableName, variableSubstitutionMap) {\n if (!defined(variableSubstitutionMap[variableName])) {\n return Expression.NULL_SENTINEL;\n }\n\n return variableSubstitutionMap[variableName];\n}\n\n/**\n * @private\n */\nExpression.NULL_SENTINEL = \"czm_infinity\"; // null just needs to be some sentinel value that will cause \"[expression] === null\" to be false in nearly all cases. GLSL doesn't have a NaN constant so use czm_infinity.\n\nNode.prototype.getShaderExpression = function (\n variableSubstitutionMap,\n shaderState,\n parent\n) {\n let color;\n let left;\n let right;\n let test;\n\n const type = this._type;\n let value = this._value;\n\n if (defined(this._left)) {\n if (Array.isArray(this._left)) {\n // Left can be an array if the type is LITERAL_COLOR or LITERAL_VECTOR\n left = getExpressionArray(\n this._left,\n variableSubstitutionMap,\n shaderState,\n this\n );\n } else {\n left = this._left.getShaderExpression(\n variableSubstitutionMap,\n shaderState,\n this\n );\n }\n }\n\n if (defined(this._right)) {\n right = this._right.getShaderExpression(\n variableSubstitutionMap,\n shaderState,\n this\n );\n }\n\n if (defined(this._test)) {\n test = this._test.getShaderExpression(\n variableSubstitutionMap,\n shaderState,\n this\n );\n }\n\n if (Array.isArray(this._value)) {\n // For ARRAY type\n value = getExpressionArray(\n this._value,\n variableSubstitutionMap,\n shaderState,\n this\n );\n }\n\n let args;\n let length;\n let vectorExpression;\n switch (type) {\n case ExpressionNodeType.VARIABLE:\n if (checkFeature(this)) {\n return undefined;\n }\n return getVariableName(value, variableSubstitutionMap);\n case ExpressionNodeType.UNARY:\n // Supported types: +, -, !, Boolean, Number\n if (value === \"Boolean\") {\n return `bool(${left})`;\n } else if (value === \"Number\") {\n return `float(${left})`;\n } else if (value === \"round\") {\n return `floor(${left} + 0.5)`;\n } else if (defined(unaryFunctions[value])) {\n return `${value}(${left})`;\n } else if (value === \"isNaN\") {\n // In GLSL 2.0 use isnan instead\n return `(${left} != ${left})`;\n } else if (value === \"isFinite\") {\n // In GLSL 2.0 use isinf instead. GLSL doesn't have an infinity constant so use czm_infinity which is an arbitrarily big enough number.\n return `(abs(${left}) < czm_infinity)`;\n } else if (\n value === \"String\" ||\n value === \"isExactClass\" ||\n value === \"isClass\" ||\n value === \"getExactClassName\"\n ) {\n throw new RuntimeError(\n `Error generating style shader: \"${value}\" is not supported.`\n );\n }\n return value + left;\n case ExpressionNodeType.BINARY:\n // Supported types: ||, &&, ===, !==, <, >, <=, >=, +, -, *, /, %\n if (value === \"%\") {\n return `mod(${left}, ${right})`;\n } else if (value === \"===\") {\n return `(${left} == ${right})`;\n } else if (value === \"!==\") {\n return `(${left} != ${right})`;\n } else if (value === \"atan2\") {\n return `atan(${left}, ${right})`;\n } else if (defined(binaryFunctions[value])) {\n return `${value}(${left}, ${right})`;\n }\n return `(${left} ${value} ${right})`;\n case ExpressionNodeType.TERNARY:\n if (defined(ternaryFunctions[value])) {\n return `${value}(${left}, ${right}, ${test})`;\n }\n break;\n case ExpressionNodeType.CONDITIONAL:\n return `(${test} ? ${left} : ${right})`;\n case ExpressionNodeType.MEMBER:\n if (checkFeature(this._left)) {\n return getVariableName(right, variableSubstitutionMap);\n }\n // This is intended for accessing the components of vector properties. String members aren't supported.\n // Check for 0.0 rather than 0 because all numbers are previously converted to decimals.\n if (right === \"r\" || right === \"x\" || right === \"0.0\") {\n return `${left}[0]`;\n } else if (right === \"g\" || right === \"y\" || right === \"1.0\") {\n return `${left}[1]`;\n } else if (right === \"b\" || right === \"z\" || right === \"2.0\") {\n return `${left}[2]`;\n } else if (right === \"a\" || right === \"w\" || right === \"3.0\") {\n return `${left}[3]`;\n }\n return `${left}[int(${right})]`;\n case ExpressionNodeType.FUNCTION_CALL:\n throw new RuntimeError(\n `Error generating style shader: \"${value}\" is not supported.`\n );\n case ExpressionNodeType.ARRAY:\n if (value.length === 4) {\n return `vec4(${value[0]}, ${value[1]}, ${value[2]}, ${value[3]})`;\n } else if (value.length === 3) {\n return `vec3(${value[0]}, ${value[1]}, ${value[2]})`;\n } else if (value.length === 2) {\n return `vec2(${value[0]}, ${value[1]})`;\n }\n throw new RuntimeError(\n \"Error generating style shader: Invalid array length. Array length should be 2, 3, or 4.\"\n );\n case ExpressionNodeType.REGEX:\n throw new RuntimeError(\n \"Error generating style shader: Regular expressions are not supported.\"\n );\n case ExpressionNodeType.VARIABLE_IN_STRING:\n throw new RuntimeError(\n \"Error generating style shader: Converting a variable to a string is not supported.\"\n );\n case ExpressionNodeType.LITERAL_NULL:\n return Expression.NULL_SENTINEL;\n case ExpressionNodeType.LITERAL_BOOLEAN:\n return value ? \"true\" : \"false\";\n case ExpressionNodeType.LITERAL_NUMBER:\n return numberToString(value);\n case ExpressionNodeType.LITERAL_STRING:\n if (defined(parent) && parent._type === ExpressionNodeType.MEMBER) {\n if (\n value === \"r\" ||\n value === \"g\" ||\n value === \"b\" ||\n value === \"a\" ||\n value === \"x\" ||\n value === \"y\" ||\n value === \"z\" ||\n value === \"w\" ||\n checkFeature(parent._left)\n ) {\n return value;\n }\n }\n // Check for css color strings\n color = Color.fromCssColorString(value, scratchColor);\n if (defined(color)) {\n return colorToVec3(color);\n }\n throw new RuntimeError(\n \"Error generating style shader: String literals are not supported.\"\n );\n case ExpressionNodeType.LITERAL_COLOR:\n args = left;\n if (value === \"color\") {\n if (!defined(args)) {\n return \"vec4(1.0)\";\n } else if (args.length > 1) {\n const rgb = args[0];\n const alpha = args[1];\n if (alpha !== \"1.0\") {\n shaderState.translucent = true;\n }\n return `vec4(${rgb}, ${alpha})`;\n }\n return `vec4(${args[0]}, 1.0)`;\n } else if (value === \"rgb\") {\n color = convertRGBToColor(this);\n if (defined(color)) {\n return colorToVec4(color);\n }\n return `vec4(${args[0]} / 255.0, ${args[1]} / 255.0, ${args[2]} / 255.0, 1.0)`;\n } else if (value === \"rgba\") {\n if (args[3] !== \"1.0\") {\n shaderState.translucent = true;\n }\n color = convertRGBToColor(this);\n if (defined(color)) {\n return colorToVec4(color);\n }\n return `vec4(${args[0]} / 255.0, ${args[1]} / 255.0, ${args[2]} / 255.0, ${args[3]})`;\n } else if (value === \"hsl\") {\n color = convertHSLToRGB(this);\n if (defined(color)) {\n return colorToVec4(color);\n }\n return `vec4(czm_HSLToRGB(vec3(${args[0]}, ${args[1]}, ${args[2]})), 1.0)`;\n } else if (value === \"hsla\") {\n color = convertHSLToRGB(this);\n if (defined(color)) {\n if (color.alpha !== 1.0) {\n shaderState.translucent = true;\n }\n return colorToVec4(color);\n }\n if (args[3] !== \"1.0\") {\n shaderState.translucent = true;\n }\n return `vec4(czm_HSLToRGB(vec3(${args[0]}, ${args[1]}, ${args[2]})), ${args[3]})`;\n }\n break;\n case ExpressionNodeType.LITERAL_VECTOR:\n //>>includeStart('debug', pragmas.debug);\n if (!defined(left)) {\n throw new DeveloperError(\n \"left should always be defined for type ExpressionNodeType.LITERAL_VECTOR\"\n );\n }\n //>>includeEnd('debug');\n length = left.length;\n vectorExpression = `${value}(`;\n for (let i = 0; i < length; ++i) {\n vectorExpression += left[i];\n if (i < length - 1) {\n vectorExpression += \", \";\n }\n }\n vectorExpression += \")\";\n return vectorExpression;\n case ExpressionNodeType.LITERAL_REGEX:\n throw new RuntimeError(\n \"Error generating style shader: Regular expressions are not supported.\"\n );\n case ExpressionNodeType.LITERAL_UNDEFINED:\n return Expression.NULL_SENTINEL;\n case ExpressionNodeType.BUILTIN_VARIABLE:\n if (value === \"tiles3d_tileset_time\") {\n return value;\n }\n }\n};\n\nNode.prototype.getVariables = function (variables, parent) {\n let array;\n let length;\n let i;\n\n const type = this._type;\n const value = this._value;\n\n if (defined(this._left)) {\n if (Array.isArray(this._left)) {\n // Left can be an array if the type is LITERAL_COLOR or LITERAL_VECTOR\n array = this._left;\n length = array.length;\n for (i = 0; i < length; ++i) {\n array[i].getVariables(variables, this);\n }\n } else {\n this._left.getVariables(variables, this);\n }\n }\n\n if (defined(this._right)) {\n this._right.getVariables(variables, this);\n }\n\n if (defined(this._test)) {\n this._test.getVariables(variables, this);\n }\n\n if (Array.isArray(this._value)) {\n // For ARRAY type\n array = this._value;\n length = array.length;\n for (i = 0; i < length; ++i) {\n array[i].getVariables(variables, this);\n }\n }\n\n let match;\n switch (type) {\n case ExpressionNodeType.VARIABLE:\n if (!checkFeature(this)) {\n variables.push(value);\n }\n break;\n case ExpressionNodeType.VARIABLE_IN_STRING:\n match = variableRegex.exec(value);\n while (match !== null) {\n variables.push(match[1]);\n match = variableRegex.exec(value);\n }\n break;\n case ExpressionNodeType.LITERAL_STRING:\n if (\n defined(parent) &&\n parent._type === ExpressionNodeType.MEMBER &&\n checkFeature(parent._left)\n ) {\n variables.push(value);\n }\n break;\n }\n};\n\nexport default Expression;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport ShadowVolumeFS from \"../Shaders/ShadowVolumeFS.js\";\nimport VectorTileVS from \"../Shaders/VectorTileVS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport Cesium3DTileFeature from \"./Cesium3DTileFeature.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport DepthFunction from \"./DepthFunction.js\";\nimport Expression from \"./Expression.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\nimport Vector3DTileBatch from \"./Vector3DTileBatch.js\";\n\n/**\n * Creates a batch of classification meshes.\n *\n * @alias Vector3DTilePrimitive\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Float32Array} options.positions The positions of the meshes.\n * @param {Uint16Array|Uint32Array} options.indices The indices of the triangulated meshes. The indices must be contiguous so that\n * the indices for mesh n are in [i, i + indexCounts[n]] where i = sum{indexCounts[0], indexCounts[n - 1]}.\n * @param {Uint32Array} options.indexCounts The number of indices for each mesh.\n * @param {Uint32Array} options.indexOffsets The offset into the index buffer for each mesh.\n * @param {Vector3DTileBatch[]} options.batchedIndices The index offset and count for each batch with the same color.\n * @param {Cartesian3} [options.center=Cartesian3.ZERO] The RTC center.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table for the tile containing the batched meshes.\n * @param {Uint16Array} options.batchIds The batch ids for each mesh.\n * @param {Uint16Array} options.vertexBatchIds The batch id for each vertex.\n * @param {BoundingSphere} options.boundingVolume The bounding volume for the entire batch of meshes.\n * @param {BoundingSphere[]} options.boundingVolumes The bounding volume for each mesh.\n * @param {ClassificationType} [options.classificationType] What this tile will classify.\n *\n * @private\n */\nfunction Vector3DTilePrimitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._batchTable = options.batchTable;\n this._batchIds = options.batchIds;\n\n // These arrays are released after VAO creation.\n this._positions = options.positions;\n this._vertexBatchIds = options.vertexBatchIds;\n\n // These arrays are kept for re-batching indices based on colors.\n // If WebGL 2 is supported, indices will be released and re-batching uses buffer-to-buffer copies.\n this._indices = options.indices;\n this._indexCounts = options.indexCounts;\n this._indexOffsets = options.indexOffsets;\n this._batchedIndices = options.batchedIndices;\n\n this._boundingVolume = options.boundingVolume;\n this._boundingVolumes = options.boundingVolumes;\n\n this._center = defaultValue(options.center, Cartesian3.ZERO);\n\n this._va = undefined;\n this._sp = undefined;\n this._spStencil = undefined;\n this._spPick = undefined;\n this._uniformMap = undefined;\n\n // Only used with WebGL 2 to ping-pong ibos after copy.\n this._vaSwap = undefined;\n\n this._rsStencilDepthPass = undefined;\n this._rsStencilDepthPass3DTiles = undefined;\n this._rsColorPass = undefined;\n this._rsPickPass = undefined;\n this._rsWireframe = undefined;\n\n this._commands = [];\n this._commandsIgnoreShow = [];\n this._pickCommands = [];\n\n this._constantColor = Color.clone(Color.WHITE);\n this._highlightColor = this._constantColor;\n\n this._batchDirty = true;\n this._pickCommandsDirty = true;\n this._framesSinceLastRebatch = 0;\n\n this._updatingAllCommands = false;\n\n this._trianglesLength = this._indices.length / 3;\n this._geometryByteLength =\n this._indices.byteLength +\n this._positions.byteLength +\n this._vertexBatchIds.byteLength;\n\n /**\n * Draw the wireframe of the classification meshes.\n * @type {boolean}\n * @default false\n */\n this.debugWireframe = false;\n this._debugWireframe = this.debugWireframe;\n this._wireframeDirty = false;\n\n /**\n * Forces a re-batch instead of waiting after a number of frames have been rendered. For testing only.\n * @type {boolean}\n * @default false\n */\n this.forceRebatch = false;\n\n /**\n * What this tile will classify.\n * @type {ClassificationType}\n * @default ClassificationType.BOTH\n */\n this.classificationType = defaultValue(\n options.classificationType,\n ClassificationType.BOTH\n );\n\n // Hidden options\n this._vertexShaderSource = options._vertexShaderSource;\n this._fragmentShaderSource = options._fragmentShaderSource;\n this._attributeLocations = options._attributeLocations;\n this._uniformMap = options._uniformMap;\n this._pickId = options._pickId;\n this._modelMatrix = options._modelMatrix;\n this._boundingSphere = options._boundingSphere;\n\n this._batchIdLookUp = {};\n\n const length = this._batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = this._batchIds[i];\n this._batchIdLookUp[batchId] = i;\n }\n}\n\nObject.defineProperties(Vector3DTilePrimitive.prototype, {\n /**\n * Gets the number of triangles.\n *\n * @memberof Vector3DTilePrimitive.prototype\n *\n * @type {number}\n * @readonly\n */\n trianglesLength: {\n get: function () {\n return this._trianglesLength;\n },\n },\n\n /**\n * Gets the geometry memory in bytes.\n *\n * @memberof Vector3DTilePrimitive.prototype\n *\n * @type {number}\n * @readonly\n */\n geometryByteLength: {\n get: function () {\n return this._geometryByteLength;\n },\n },\n});\n\nconst defaultAttributeLocations = {\n position: 0,\n a_batchId: 1,\n};\n\nfunction createVertexArray(primitive, context) {\n if (defined(primitive._va)) {\n return;\n }\n\n const positionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: primitive._positions,\n usage: BufferUsage.STATIC_DRAW,\n });\n const idBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: primitive._vertexBatchIds,\n usage: BufferUsage.STATIC_DRAW,\n });\n const indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: primitive._indices,\n usage: BufferUsage.DYNAMIC_DRAW,\n indexDatatype:\n primitive._indices.BYTES_PER_ELEMENT === 2\n ? IndexDatatype.UNSIGNED_SHORT\n : IndexDatatype.UNSIGNED_INT,\n });\n\n const vertexAttributes = [\n {\n index: 0,\n vertexBuffer: positionBuffer,\n componentDatatype: ComponentDatatype.fromTypedArray(primitive._positions),\n componentsPerAttribute: 3,\n },\n {\n index: 1,\n vertexBuffer: idBuffer,\n componentDatatype: ComponentDatatype.fromTypedArray(\n primitive._vertexBatchIds\n ),\n componentsPerAttribute: 1,\n },\n ];\n\n primitive._va = new VertexArray({\n context: context,\n attributes: vertexAttributes,\n indexBuffer: indexBuffer,\n });\n\n if (context.webgl2) {\n primitive._vaSwap = new VertexArray({\n context: context,\n attributes: vertexAttributes,\n indexBuffer: Buffer.createIndexBuffer({\n context: context,\n sizeInBytes: indexBuffer.sizeInBytes,\n usage: BufferUsage.DYNAMIC_DRAW,\n indexDatatype: indexBuffer.indexDatatype,\n }),\n });\n }\n\n primitive._batchedPositions = undefined;\n primitive._transferrableBatchIds = undefined;\n primitive._vertexBatchIds = undefined;\n}\n\nfunction createShaders(primitive, context) {\n if (defined(primitive._sp)) {\n return;\n }\n\n const batchTable = primitive._batchTable;\n const attributeLocations = defaultValue(\n primitive._attributeLocations,\n defaultAttributeLocations\n );\n\n let pickId = primitive._pickId;\n const vertexShaderSource = primitive._vertexShaderSource;\n let fragmentShaderSource = primitive._fragmentShaderSource;\n if (defined(vertexShaderSource)) {\n primitive._sp = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vertexShaderSource,\n fragmentShaderSource: fragmentShaderSource,\n attributeLocations: attributeLocations,\n });\n primitive._spStencil = primitive._sp;\n\n fragmentShaderSource = ShaderSource.replaceMain(\n fragmentShaderSource,\n \"czm_non_pick_main\"\n );\n fragmentShaderSource =\n `${fragmentShaderSource}void main() \\n` +\n `{ \\n` +\n ` czm_non_pick_main(); \\n` +\n ` out_FragColor = ${pickId}; \\n` +\n `} \\n`;\n primitive._spPick = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vertexShaderSource,\n fragmentShaderSource: fragmentShaderSource,\n attributeLocations: attributeLocations,\n });\n return;\n }\n\n const vsSource = batchTable.getVertexShaderCallback(\n false,\n \"a_batchId\",\n undefined\n )(VectorTileVS);\n let fsSource = batchTable.getFragmentShaderCallback(\n false,\n undefined,\n true\n )(ShadowVolumeFS);\n\n pickId = batchTable.getPickId();\n\n let vs = new ShaderSource({\n sources: [vsSource],\n });\n let fs = new ShaderSource({\n defines: [\"VECTOR_TILE\"],\n sources: [fsSource],\n });\n\n primitive._sp = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n\n vs = new ShaderSource({\n sources: [VectorTileVS],\n });\n fs = new ShaderSource({\n defines: [\"VECTOR_TILE\"],\n sources: [ShadowVolumeFS],\n });\n\n primitive._spStencil = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n\n fsSource = ShaderSource.replaceMain(fsSource, \"czm_non_pick_main\");\n fsSource =\n `${fsSource}\\n` +\n `void main() \\n` +\n `{ \\n` +\n ` czm_non_pick_main(); \\n` +\n ` out_FragColor = ${pickId}; \\n` +\n `} \\n`;\n\n const pickVS = new ShaderSource({\n sources: [vsSource],\n });\n const pickFS = new ShaderSource({\n defines: [\"VECTOR_TILE\"],\n sources: [fsSource],\n });\n primitive._spPick = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: pickVS,\n fragmentShaderSource: pickFS,\n attributeLocations: attributeLocations,\n });\n}\n\nfunction getStencilDepthRenderState(mask3DTiles) {\n const stencilFunction = mask3DTiles\n ? StencilFunction.EQUAL\n : StencilFunction.ALWAYS;\n return {\n colorMask: {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n },\n stencilTest: {\n enabled: true,\n frontFunction: stencilFunction,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.DECREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n backFunction: stencilFunction,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.INCREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: true,\n func: DepthFunction.LESS_OR_EQUAL,\n },\n depthMask: false,\n };\n}\n\nconst colorRenderState = {\n stencilTest: {\n enabled: true,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n};\n\nconst pickRenderState = {\n stencilTest: {\n enabled: true,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n};\n\nfunction createRenderStates(primitive) {\n if (defined(primitive._rsStencilDepthPass)) {\n return;\n }\n\n primitive._rsStencilDepthPass = RenderState.fromCache(\n getStencilDepthRenderState(false)\n );\n primitive._rsStencilDepthPass3DTiles = RenderState.fromCache(\n getStencilDepthRenderState(true)\n );\n primitive._rsColorPass = RenderState.fromCache(colorRenderState);\n primitive._rsPickPass = RenderState.fromCache(pickRenderState);\n}\n\nconst modifiedModelViewScratch = new Matrix4();\nconst rtcScratch = new Cartesian3();\n\nfunction createUniformMap(primitive, context) {\n if (defined(primitive._uniformMap)) {\n return;\n }\n\n const uniformMap = {\n u_modifiedModelViewProjection: function () {\n const viewMatrix = context.uniformState.view;\n const projectionMatrix = context.uniformState.projection;\n Matrix4.clone(viewMatrix, modifiedModelViewScratch);\n Matrix4.multiplyByPoint(\n modifiedModelViewScratch,\n primitive._center,\n rtcScratch\n );\n Matrix4.setTranslation(\n modifiedModelViewScratch,\n rtcScratch,\n modifiedModelViewScratch\n );\n Matrix4.multiply(\n projectionMatrix,\n modifiedModelViewScratch,\n modifiedModelViewScratch\n );\n return modifiedModelViewScratch;\n },\n u_highlightColor: function () {\n return primitive._highlightColor;\n },\n };\n\n primitive._uniformMap = primitive._batchTable.getUniformMapCallback()(\n uniformMap\n );\n}\n\nfunction copyIndicesCPU(\n indices,\n newIndices,\n currentOffset,\n offsets,\n counts,\n batchIds,\n batchIdLookUp\n) {\n const sizeInBytes = indices.constructor.BYTES_PER_ELEMENT;\n\n const batchedIdsLength = batchIds.length;\n for (let j = 0; j < batchedIdsLength; ++j) {\n const batchedId = batchIds[j];\n const index = batchIdLookUp[batchedId];\n const offset = offsets[index];\n const count = counts[index];\n\n const subarray = new indices.constructor(\n indices.buffer,\n sizeInBytes * offset,\n count\n );\n newIndices.set(subarray, currentOffset);\n\n offsets[index] = currentOffset;\n currentOffset += count;\n }\n\n return currentOffset;\n}\n\nfunction rebatchCPU(primitive, batchedIndices) {\n const indices = primitive._indices;\n const indexOffsets = primitive._indexOffsets;\n const indexCounts = primitive._indexCounts;\n const batchIdLookUp = primitive._batchIdLookUp;\n\n const newIndices = new indices.constructor(indices.length);\n\n let current = batchedIndices.pop();\n const newBatchedIndices = [current];\n\n let currentOffset = copyIndicesCPU(\n indices,\n newIndices,\n 0,\n indexOffsets,\n indexCounts,\n current.batchIds,\n batchIdLookUp\n );\n\n current.offset = 0;\n current.count = currentOffset;\n\n while (batchedIndices.length > 0) {\n const next = batchedIndices.pop();\n if (Color.equals(next.color, current.color)) {\n currentOffset = copyIndicesCPU(\n indices,\n newIndices,\n currentOffset,\n indexOffsets,\n indexCounts,\n next.batchIds,\n batchIdLookUp\n );\n current.batchIds = current.batchIds.concat(next.batchIds);\n current.count = currentOffset - current.offset;\n } else {\n const offset = currentOffset;\n currentOffset = copyIndicesCPU(\n indices,\n newIndices,\n currentOffset,\n indexOffsets,\n indexCounts,\n next.batchIds,\n batchIdLookUp\n );\n\n next.offset = offset;\n next.count = currentOffset - offset;\n newBatchedIndices.push(next);\n current = next;\n }\n }\n\n primitive._va.indexBuffer.copyFromArrayView(newIndices);\n\n primitive._indices = newIndices;\n primitive._batchedIndices = newBatchedIndices;\n}\n\nfunction copyIndicesGPU(\n readBuffer,\n writeBuffer,\n currentOffset,\n offsets,\n counts,\n batchIds,\n batchIdLookUp\n) {\n const sizeInBytes = readBuffer.bytesPerIndex;\n\n const batchedIdsLength = batchIds.length;\n for (let j = 0; j < batchedIdsLength; ++j) {\n const batchedId = batchIds[j];\n const index = batchIdLookUp[batchedId];\n const offset = offsets[index];\n const count = counts[index];\n\n writeBuffer.copyFromBuffer(\n readBuffer,\n offset * sizeInBytes,\n currentOffset * sizeInBytes,\n count * sizeInBytes\n );\n\n offsets[index] = currentOffset;\n currentOffset += count;\n }\n\n return currentOffset;\n}\n\nfunction rebatchGPU(primitive, batchedIndices) {\n const indexOffsets = primitive._indexOffsets;\n const indexCounts = primitive._indexCounts;\n const batchIdLookUp = primitive._batchIdLookUp;\n\n let current = batchedIndices.pop();\n const newBatchedIndices = [current];\n\n const readBuffer = primitive._va.indexBuffer;\n const writeBuffer = primitive._vaSwap.indexBuffer;\n\n let currentOffset = copyIndicesGPU(\n readBuffer,\n writeBuffer,\n 0,\n indexOffsets,\n indexCounts,\n current.batchIds,\n batchIdLookUp\n );\n\n current.offset = 0;\n current.count = currentOffset;\n\n while (batchedIndices.length > 0) {\n const next = batchedIndices.pop();\n if (Color.equals(next.color, current.color)) {\n currentOffset = copyIndicesGPU(\n readBuffer,\n writeBuffer,\n currentOffset,\n indexOffsets,\n indexCounts,\n next.batchIds,\n batchIdLookUp\n );\n current.batchIds = current.batchIds.concat(next.batchIds);\n current.count = currentOffset - current.offset;\n } else {\n const offset = currentOffset;\n currentOffset = copyIndicesGPU(\n readBuffer,\n writeBuffer,\n currentOffset,\n indexOffsets,\n indexCounts,\n next.batchIds,\n batchIdLookUp\n );\n next.offset = offset;\n next.count = currentOffset - offset;\n newBatchedIndices.push(next);\n current = next;\n }\n }\n\n const temp = primitive._va;\n primitive._va = primitive._vaSwap;\n primitive._vaSwap = temp;\n\n primitive._batchedIndices = newBatchedIndices;\n}\n\nfunction compareColors(a, b) {\n return b.color.toRgba() - a.color.toRgba();\n}\n\n// PERFORMANCE_IDEA: For WebGL 2, we can use copyBufferSubData for buffer-to-buffer copies.\n// PERFORMANCE_IDEA: Not supported, but we could use glMultiDrawElements here.\nfunction rebatchCommands(primitive, context) {\n if (!primitive._batchDirty) {\n return false;\n }\n\n const batchedIndices = primitive._batchedIndices;\n const length = batchedIndices.length;\n\n let needToRebatch = false;\n const colorCounts = {};\n\n for (let i = 0; i < length; ++i) {\n const color = batchedIndices[i].color;\n const rgba = color.toRgba();\n if (defined(colorCounts[rgba])) {\n needToRebatch = true;\n break;\n } else {\n colorCounts[rgba] = true;\n }\n }\n\n if (!needToRebatch) {\n primitive._batchDirty = false;\n return false;\n }\n\n if (\n needToRebatch &&\n !primitive.forceRebatch &&\n primitive._framesSinceLastRebatch < 120\n ) {\n ++primitive._framesSinceLastRebatch;\n return;\n }\n\n batchedIndices.sort(compareColors);\n\n if (context.webgl2) {\n rebatchGPU(primitive, batchedIndices);\n } else {\n rebatchCPU(primitive, batchedIndices);\n }\n\n primitive._framesSinceLastRebatch = 0;\n primitive._batchDirty = false;\n primitive._pickCommandsDirty = true;\n primitive._wireframeDirty = true;\n return true;\n}\n\nfunction createColorCommands(primitive, context) {\n const needsRebatch = rebatchCommands(primitive, context);\n\n const commands = primitive._commands;\n const batchedIndices = primitive._batchedIndices;\n const length = batchedIndices.length;\n const commandsLength = length * 2;\n\n if (\n defined(commands) &&\n !needsRebatch &&\n commands.length === commandsLength\n ) {\n return;\n }\n\n commands.length = commandsLength;\n\n const vertexArray = primitive._va;\n const sp = primitive._sp;\n const modelMatrix = defaultValue(primitive._modelMatrix, Matrix4.IDENTITY);\n const uniformMap = primitive._uniformMap;\n const bv = primitive._boundingVolume;\n\n for (let j = 0; j < length; ++j) {\n const offset = batchedIndices[j].offset;\n const count = batchedIndices[j].count;\n\n let stencilDepthCommand = commands[j * 2];\n if (!defined(stencilDepthCommand)) {\n stencilDepthCommand = commands[j * 2] = new DrawCommand({\n owner: primitive,\n });\n }\n\n stencilDepthCommand.vertexArray = vertexArray;\n stencilDepthCommand.modelMatrix = modelMatrix;\n stencilDepthCommand.offset = offset;\n stencilDepthCommand.count = count;\n stencilDepthCommand.renderState = primitive._rsStencilDepthPass;\n stencilDepthCommand.shaderProgram = sp;\n stencilDepthCommand.uniformMap = uniformMap;\n stencilDepthCommand.boundingVolume = bv;\n stencilDepthCommand.cull = false;\n stencilDepthCommand.pass = Pass.TERRAIN_CLASSIFICATION;\n\n const stencilDepthDerivedCommand = DrawCommand.shallowClone(\n stencilDepthCommand,\n stencilDepthCommand.derivedCommands.tileset\n );\n stencilDepthDerivedCommand.renderState =\n primitive._rsStencilDepthPass3DTiles;\n stencilDepthDerivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n stencilDepthCommand.derivedCommands.tileset = stencilDepthDerivedCommand;\n\n let colorCommand = commands[j * 2 + 1];\n if (!defined(colorCommand)) {\n colorCommand = commands[j * 2 + 1] = new DrawCommand({\n owner: primitive,\n });\n }\n\n colorCommand.vertexArray = vertexArray;\n colorCommand.modelMatrix = modelMatrix;\n colorCommand.offset = offset;\n colorCommand.count = count;\n colorCommand.renderState = primitive._rsColorPass;\n colorCommand.shaderProgram = sp;\n colorCommand.uniformMap = uniformMap;\n colorCommand.boundingVolume = bv;\n colorCommand.cull = false;\n colorCommand.pass = Pass.TERRAIN_CLASSIFICATION;\n\n const colorDerivedCommand = DrawCommand.shallowClone(\n colorCommand,\n colorCommand.derivedCommands.tileset\n );\n colorDerivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n colorCommand.derivedCommands.tileset = colorDerivedCommand;\n }\n\n primitive._commandsDirty = true;\n}\n\nfunction createColorCommandsIgnoreShow(primitive, frameState) {\n if (\n primitive.classificationType === ClassificationType.TERRAIN ||\n !frameState.invertClassification ||\n (defined(primitive._commandsIgnoreShow) && !primitive._commandsDirty)\n ) {\n return;\n }\n\n const commands = primitive._commands;\n const commandsIgnoreShow = primitive._commandsIgnoreShow;\n const spStencil = primitive._spStencil;\n\n const commandsLength = commands.length;\n const length = (commandsIgnoreShow.length = commandsLength / 2);\n\n let commandIndex = 0;\n for (let j = 0; j < length; ++j) {\n const commandIgnoreShow = (commandsIgnoreShow[j] = DrawCommand.shallowClone(\n commands[commandIndex],\n commandsIgnoreShow[j]\n ));\n commandIgnoreShow.shaderProgram = spStencil;\n commandIgnoreShow.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW;\n\n commandIndex += 2;\n }\n\n primitive._commandsDirty = false;\n}\n\nfunction createPickCommands(primitive) {\n if (!primitive._pickCommandsDirty) {\n return;\n }\n\n const length = primitive._indexOffsets.length;\n const pickCommands = primitive._pickCommands;\n pickCommands.length = length * 2;\n\n const vertexArray = primitive._va;\n const spStencil = primitive._spStencil;\n const spPick = primitive._spPick;\n const modelMatrix = defaultValue(primitive._modelMatrix, Matrix4.IDENTITY);\n const uniformMap = primitive._uniformMap;\n\n for (let j = 0; j < length; ++j) {\n const offset = primitive._indexOffsets[j];\n const count = primitive._indexCounts[j];\n const bv = defined(primitive._boundingVolumes)\n ? primitive._boundingVolumes[j]\n : primitive.boundingVolume;\n\n let stencilDepthCommand = pickCommands[j * 2];\n if (!defined(stencilDepthCommand)) {\n stencilDepthCommand = pickCommands[j * 2] = new DrawCommand({\n owner: primitive,\n pickOnly: true,\n });\n }\n\n stencilDepthCommand.vertexArray = vertexArray;\n stencilDepthCommand.modelMatrix = modelMatrix;\n stencilDepthCommand.offset = offset;\n stencilDepthCommand.count = count;\n stencilDepthCommand.renderState = primitive._rsStencilDepthPass;\n stencilDepthCommand.shaderProgram = spStencil;\n stencilDepthCommand.uniformMap = uniformMap;\n stencilDepthCommand.boundingVolume = bv;\n stencilDepthCommand.pass = Pass.TERRAIN_CLASSIFICATION;\n\n const stencilDepthDerivedCommand = DrawCommand.shallowClone(\n stencilDepthCommand,\n stencilDepthCommand.derivedCommands.tileset\n );\n stencilDepthDerivedCommand.renderState =\n primitive._rsStencilDepthPass3DTiles;\n stencilDepthDerivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n stencilDepthCommand.derivedCommands.tileset = stencilDepthDerivedCommand;\n\n let colorCommand = pickCommands[j * 2 + 1];\n if (!defined(colorCommand)) {\n colorCommand = pickCommands[j * 2 + 1] = new DrawCommand({\n owner: primitive,\n pickOnly: true,\n });\n }\n\n colorCommand.vertexArray = vertexArray;\n colorCommand.modelMatrix = modelMatrix;\n colorCommand.offset = offset;\n colorCommand.count = count;\n colorCommand.renderState = primitive._rsPickPass;\n colorCommand.shaderProgram = spPick;\n colorCommand.uniformMap = uniformMap;\n colorCommand.boundingVolume = bv;\n colorCommand.pass = Pass.TERRAIN_CLASSIFICATION;\n\n const colorDerivedCommand = DrawCommand.shallowClone(\n colorCommand,\n colorCommand.derivedCommands.tileset\n );\n colorDerivedCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n colorCommand.derivedCommands.tileset = colorDerivedCommand;\n }\n\n primitive._pickCommandsDirty = false;\n}\n\n/**\n * Creates features for each mesh and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the polygon features will be placed.\n */\nVector3DTilePrimitive.prototype.createFeatures = function (content, features) {\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n features[batchId] = new Cesium3DTileFeature(content, batchId);\n }\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (mesh batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTilePrimitive.prototype.applyDebugSettings = function (enabled, color) {\n this._highlightColor = enabled ? color : this._constantColor;\n};\n\nfunction clearStyle(polygons, features) {\n polygons._updatingAllCommands = true;\n\n const batchIds = polygons._batchIds;\n let length = batchIds.length;\n let i;\n\n for (i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.show = true;\n feature.color = Color.WHITE;\n }\n\n const batchedIndices = polygons._batchedIndices;\n length = batchedIndices.length;\n\n for (i = 0; i < length; ++i) {\n batchedIndices[i].color = Color.clone(Color.WHITE);\n }\n\n polygons._updatingAllCommands = false;\n polygons._batchDirty = true;\n}\n\nconst scratchColor = new Color();\n\nconst DEFAULT_COLOR_VALUE = Color.WHITE;\nconst DEFAULT_SHOW_VALUE = true;\n\nconst complexExpressionReg = /\\$/;\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The array of features.\n */\nVector3DTilePrimitive.prototype.applyStyle = function (style, features) {\n if (!defined(style)) {\n clearStyle(this, features);\n return;\n }\n\n const colorExpression = style.color;\n const isSimpleStyle =\n colorExpression instanceof Expression &&\n !complexExpressionReg.test(colorExpression.expression);\n this._updatingAllCommands = isSimpleStyle;\n\n const batchIds = this._batchIds;\n let length = batchIds.length;\n let i;\n\n for (i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.color = defined(style.color)\n ? style.color.evaluateColor(feature, scratchColor)\n : DEFAULT_COLOR_VALUE;\n feature.show = defined(style.show)\n ? style.show.evaluate(feature)\n : DEFAULT_SHOW_VALUE;\n }\n\n if (isSimpleStyle) {\n const batchedIndices = this._batchedIndices;\n length = batchedIndices.length;\n\n for (i = 0; i < length; ++i) {\n batchedIndices[i].color = Color.clone(Color.WHITE);\n }\n\n this._updatingAllCommands = false;\n this._batchDirty = true;\n }\n};\n\n/**\n * Call when updating the color of a mesh with batchId changes color. The meshes will need to be re-batched\n * on the next update.\n *\n * @param {number} batchId The batch id of the meshes whose color has changed.\n * @param {Color} color The new polygon color.\n */\nVector3DTilePrimitive.prototype.updateCommands = function (batchId, color) {\n if (this._updatingAllCommands) {\n return;\n }\n\n const batchIdLookUp = this._batchIdLookUp;\n const index = batchIdLookUp[batchId];\n if (!defined(index)) {\n return;\n }\n\n const indexOffsets = this._indexOffsets;\n const indexCounts = this._indexCounts;\n\n const offset = indexOffsets[index];\n const count = indexCounts[index];\n\n const batchedIndices = this._batchedIndices;\n const length = batchedIndices.length;\n\n let i;\n for (i = 0; i < length; ++i) {\n const batchedOffset = batchedIndices[i].offset;\n const batchedCount = batchedIndices[i].count;\n\n if (offset >= batchedOffset && offset < batchedOffset + batchedCount) {\n break;\n }\n }\n\n batchedIndices.push(\n new Vector3DTileBatch({\n color: Color.clone(color),\n offset: offset,\n count: count,\n batchIds: [batchId],\n })\n );\n\n const startIds = [];\n const endIds = [];\n\n const batchIds = batchedIndices[i].batchIds;\n const batchIdsLength = batchIds.length;\n\n for (let j = 0; j < batchIdsLength; ++j) {\n const id = batchIds[j];\n if (id === batchId) {\n continue;\n }\n\n const offsetIndex = batchIdLookUp[id];\n if (indexOffsets[offsetIndex] < offset) {\n startIds.push(id);\n } else {\n endIds.push(id);\n }\n }\n\n if (endIds.length !== 0) {\n batchedIndices.push(\n new Vector3DTileBatch({\n color: Color.clone(batchedIndices[i].color),\n offset: offset + count,\n count:\n batchedIndices[i].offset + batchedIndices[i].count - (offset + count),\n batchIds: endIds,\n })\n );\n }\n\n if (startIds.length !== 0) {\n batchedIndices[i].count = offset - batchedIndices[i].offset;\n batchedIndices[i].batchIds = startIds;\n } else {\n batchedIndices.splice(i, 1);\n }\n\n this._batchDirty = true;\n};\n\nfunction queueCommands(primitive, frameState, commands, commandsIgnoreShow) {\n const classificationType = primitive.classificationType;\n const queueTerrainCommands =\n classificationType !== ClassificationType.CESIUM_3D_TILE;\n const queue3DTilesCommands =\n classificationType !== ClassificationType.TERRAIN;\n\n const commandList = frameState.commandList;\n let commandLength = commands.length;\n let command;\n let i;\n for (i = 0; i < commandLength; ++i) {\n if (queueTerrainCommands) {\n command = commands[i];\n command.pass = Pass.TERRAIN_CLASSIFICATION;\n commandList.push(command);\n }\n if (queue3DTilesCommands) {\n command = commands[i].derivedCommands.tileset;\n command.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n commandList.push(command);\n }\n }\n\n if (!frameState.invertClassification || !defined(commandsIgnoreShow)) {\n return;\n }\n\n commandLength = commandsIgnoreShow.length;\n for (i = 0; i < commandLength; ++i) {\n commandList.push(commandsIgnoreShow[i]);\n }\n}\n\nfunction queueWireframeCommands(frameState, commands) {\n const commandList = frameState.commandList;\n const commandLength = commands.length;\n for (let i = 0; i < commandLength; i += 2) {\n const command = commands[i + 1];\n command.pass = Pass.OPAQUE;\n commandList.push(command);\n }\n}\n\nfunction updateWireframe(primitive) {\n let earlyExit = primitive.debugWireframe === primitive._debugWireframe;\n earlyExit =\n earlyExit && !(primitive.debugWireframe && primitive._wireframeDirty);\n if (earlyExit) {\n return;\n }\n\n if (!defined(primitive._rsWireframe)) {\n primitive._rsWireframe = RenderState.fromCache({});\n }\n\n let rs;\n let type;\n\n if (primitive.debugWireframe) {\n rs = primitive._rsWireframe;\n type = PrimitiveType.LINES;\n } else {\n rs = primitive._rsColorPass;\n type = PrimitiveType.TRIANGLES;\n }\n\n const commands = primitive._commands;\n const commandLength = commands.length;\n for (let i = 0; i < commandLength; i += 2) {\n const command = commands[i + 1];\n command.renderState = rs;\n command.primitiveType = type;\n }\n\n primitive._debugWireframe = primitive.debugWireframe;\n primitive._wireframeDirty = false;\n}\n\n/**\n * Updates the batches and queues the commands for rendering.\n *\n * @param {FrameState} frameState The current frame state.\n */\nVector3DTilePrimitive.prototype.update = function (frameState) {\n const context = frameState.context;\n\n createVertexArray(this, context);\n createShaders(this, context);\n createRenderStates(this);\n createUniformMap(this, context);\n\n const passes = frameState.passes;\n if (passes.render) {\n createColorCommands(this, context);\n createColorCommandsIgnoreShow(this, frameState);\n updateWireframe(this);\n\n if (this._debugWireframe) {\n queueWireframeCommands(frameState, this._commands);\n } else {\n queueCommands(this, frameState, this._commands, this._commandsIgnoreShow);\n }\n }\n\n if (passes.pick) {\n createPickCommands(this);\n queueCommands(this, frameState, this._pickCommands);\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTilePrimitive.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTilePrimitive.prototype.destroy = function () {\n this._va = this._va && this._va.destroy();\n this._sp = this._sp && this._sp.destroy();\n this._spPick = this._spPick && this._spPick.destroy();\n this._vaSwap = this._vaSwap && this._vaSwap.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTilePrimitive;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport Vector3DTileBatch from \"./Vector3DTileBatch.js\";\nimport Vector3DTilePrimitive from \"./Vector3DTilePrimitive.js\";\n\n/**\n * Creates a batch of box, cylinder, ellipsoid and/or sphere geometries intersecting terrain or 3D Tiles.\n *\n * @alias Vector3DTileGeometry\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Float32Array} [options.boxes] The boxes in the tile.\n * @param {Uint16Array} [options.boxBatchIds] The batch ids for each box.\n * @param {Float32Array} [options.cylinders] The cylinders in the tile.\n * @param {Uint16Array} [options.cylinderBatchIds] The batch ids for each cylinder.\n * @param {Float32Array} [options.ellipsoids] The ellipsoids in the tile.\n * @param {Uint16Array} [options.ellipsoidBatchIds] The batch ids for each ellipsoid.\n * @param {Float32Array} [options.spheres] The spheres in the tile.\n * @param {Uint16Array} [options.sphereBatchIds] The batch ids for each sphere.\n * @param {Cartesian3} options.center The RTC center of all geometries.\n * @param {Matrix4} options.modelMatrix The model matrix of all geometries. Applied after the individual geometry model matrices.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table.\n * @param {BoundingSphere} options.boundingVolume The bounding volume containing all of the geometry in the tile.\n *\n * @private\n */\nfunction Vector3DTileGeometry(options) {\n // these will all be released after the primitive is created\n this._boxes = options.boxes;\n this._boxBatchIds = options.boxBatchIds;\n this._cylinders = options.cylinders;\n this._cylinderBatchIds = options.cylinderBatchIds;\n this._ellipsoids = options.ellipsoids;\n this._ellipsoidBatchIds = options.ellipsoidBatchIds;\n this._spheres = options.spheres;\n this._sphereBatchIds = options.sphereBatchIds;\n this._modelMatrix = options.modelMatrix;\n this._batchTable = options.batchTable;\n this._boundingVolume = options.boundingVolume;\n\n this._center = options.center;\n if (!defined(this._center)) {\n if (defined(this._boundingVolume)) {\n this._center = Cartesian3.clone(this._boundingVolume.center);\n } else {\n this._center = Cartesian3.clone(Cartesian3.ZERO);\n }\n }\n\n this._boundingVolumes = undefined;\n this._batchedIndices = undefined;\n\n this._indices = undefined;\n this._indexOffsets = undefined;\n this._indexCounts = undefined;\n\n this._positions = undefined;\n this._vertexBatchIds = undefined;\n\n this._batchIds = undefined;\n\n this._batchTableColors = undefined;\n this._packedBuffer = undefined;\n\n this._ready = false;\n this._promise = undefined;\n this._error = undefined;\n\n this._verticesPromise = undefined;\n\n this._primitive = undefined;\n\n /**\n * Draws the wireframe of the classification geometries.\n * @type {boolean}\n * @default false\n */\n this.debugWireframe = false;\n\n /**\n * Forces a re-batch instead of waiting after a number of frames have been rendered. For testing only.\n * @type {boolean}\n * @default false\n */\n this.forceRebatch = false;\n\n /**\n * What this tile will classify.\n * @type {ClassificationType}\n * @default ClassificationType.BOTH\n */\n this.classificationType = ClassificationType.BOTH;\n}\n\nObject.defineProperties(Vector3DTileGeometry.prototype, {\n /**\n * Gets the number of triangles.\n *\n * @memberof Vector3DTileGeometry.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n trianglesLength: {\n get: function () {\n if (defined(this._primitive)) {\n return this._primitive.trianglesLength;\n }\n return 0;\n },\n },\n\n /**\n * Gets the geometry memory in bytes.\n *\n * @memberof Vector3DTileGeometry.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n geometryByteLength: {\n get: function () {\n if (defined(this._primitive)) {\n return this._primitive.geometryByteLength;\n }\n return 0;\n },\n },\n\n /**\n * Return true when the primitive is ready to render.\n * @memberof Vector3DTileGeometry.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nVector3DTileGeometry.packedBoxLength =\n Matrix4.packedLength + Cartesian3.packedLength;\nVector3DTileGeometry.packedCylinderLength = Matrix4.packedLength + 2;\nVector3DTileGeometry.packedEllipsoidLength =\n Matrix4.packedLength + Cartesian3.packedLength;\nVector3DTileGeometry.packedSphereLength = Cartesian3.packedLength + 1;\n\nfunction packBuffer(geometries) {\n const packedBuffer = new Float64Array(\n Matrix4.packedLength + Cartesian3.packedLength\n );\n\n let offset = 0;\n Cartesian3.pack(geometries._center, packedBuffer, offset);\n offset += Cartesian3.packedLength;\n Matrix4.pack(geometries._modelMatrix, packedBuffer, offset);\n\n return packedBuffer;\n}\n\nfunction unpackBuffer(geometries, packedBuffer) {\n let offset = 0;\n\n const indicesBytesPerElement = packedBuffer[offset++];\n const numBVS = packedBuffer[offset++];\n const bvs = (geometries._boundingVolumes = new Array(numBVS));\n\n for (let i = 0; i < numBVS; ++i) {\n bvs[i] = BoundingSphere.unpack(packedBuffer, offset);\n offset += BoundingSphere.packedLength;\n }\n\n const numBatchedIndices = packedBuffer[offset++];\n const bis = (geometries._batchedIndices = new Array(numBatchedIndices));\n\n for (let j = 0; j < numBatchedIndices; ++j) {\n const color = Color.unpack(packedBuffer, offset);\n offset += Color.packedLength;\n\n const indexOffset = packedBuffer[offset++];\n const count = packedBuffer[offset++];\n\n const length = packedBuffer[offset++];\n const batchIds = new Array(length);\n\n for (let k = 0; k < length; ++k) {\n batchIds[k] = packedBuffer[offset++];\n }\n\n bis[j] = new Vector3DTileBatch({\n color: color,\n offset: indexOffset,\n count: count,\n batchIds: batchIds,\n });\n }\n\n return indicesBytesPerElement;\n}\n\nconst createVerticesTaskProcessor = new TaskProcessor(\n \"createVectorTileGeometries\",\n 5\n);\nconst scratchColor = new Color();\n\nfunction createPrimitive(geometries) {\n if (defined(geometries._primitive)) {\n return;\n }\n\n if (!defined(geometries._verticesPromise)) {\n let boxes = geometries._boxes;\n let boxBatchIds = geometries._boxBatchIds;\n let cylinders = geometries._cylinders;\n let cylinderBatchIds = geometries._cylinderBatchIds;\n let ellipsoids = geometries._ellipsoids;\n let ellipsoidBatchIds = geometries._ellipsoidBatchIds;\n let spheres = geometries._spheres;\n let sphereBatchIds = geometries._sphereBatchIds;\n\n let batchTableColors = geometries._batchTableColors;\n let packedBuffer = geometries._packedBuffer;\n\n if (!defined(batchTableColors)) {\n // Copy because they may be the views on the same buffer.\n let length = 0;\n if (defined(geometries._boxes)) {\n boxes = geometries._boxes = boxes.slice();\n boxBatchIds = geometries._boxBatchIds = boxBatchIds.slice();\n length += boxBatchIds.length;\n }\n if (defined(geometries._cylinders)) {\n cylinders = geometries._cylinders = cylinders.slice();\n cylinderBatchIds = geometries._cylinderBatchIds = cylinderBatchIds.slice();\n length += cylinderBatchIds.length;\n }\n if (defined(geometries._ellipsoids)) {\n ellipsoids = geometries._ellipsoids = ellipsoids.slice();\n ellipsoidBatchIds = geometries._ellipsoidBatchIds = ellipsoidBatchIds.slice();\n length += ellipsoidBatchIds.length;\n }\n if (defined(geometries._spheres)) {\n spheres = geometries._sphere = spheres.slice();\n sphereBatchIds = geometries._sphereBatchIds = sphereBatchIds.slice();\n length += sphereBatchIds.length;\n }\n\n batchTableColors = geometries._batchTableColors = new Uint32Array(length);\n const batchTable = geometries._batchTable;\n\n for (let i = 0; i < length; ++i) {\n const color = batchTable.getColor(i, scratchColor);\n batchTableColors[i] = color.toRgba();\n }\n\n packedBuffer = geometries._packedBuffer = packBuffer(geometries);\n }\n\n const transferrableObjects = [];\n if (defined(boxes)) {\n transferrableObjects.push(boxes.buffer, boxBatchIds.buffer);\n }\n if (defined(cylinders)) {\n transferrableObjects.push(cylinders.buffer, cylinderBatchIds.buffer);\n }\n if (defined(ellipsoids)) {\n transferrableObjects.push(ellipsoids.buffer, ellipsoidBatchIds.buffer);\n }\n if (defined(spheres)) {\n transferrableObjects.push(spheres.buffer, sphereBatchIds.buffer);\n }\n transferrableObjects.push(batchTableColors.buffer, packedBuffer.buffer);\n\n const parameters = {\n boxes: defined(boxes) ? boxes.buffer : undefined,\n boxBatchIds: defined(boxes) ? boxBatchIds.buffer : undefined,\n cylinders: defined(cylinders) ? cylinders.buffer : undefined,\n cylinderBatchIds: defined(cylinders)\n ? cylinderBatchIds.buffer\n : undefined,\n ellipsoids: defined(ellipsoids) ? ellipsoids.buffer : undefined,\n ellipsoidBatchIds: defined(ellipsoids)\n ? ellipsoidBatchIds.buffer\n : undefined,\n spheres: defined(spheres) ? spheres.buffer : undefined,\n sphereBatchIds: defined(spheres) ? sphereBatchIds.buffer : undefined,\n batchTableColors: batchTableColors.buffer,\n packedBuffer: packedBuffer.buffer,\n };\n\n const verticesPromise = (geometries._verticesPromise = createVerticesTaskProcessor.scheduleTask(\n parameters,\n transferrableObjects\n ));\n if (!defined(verticesPromise)) {\n // Postponed\n return;\n }\n\n return verticesPromise\n .then(function (result) {\n if (geometries.isDestroyed()) {\n return;\n }\n\n const packedBuffer = new Float64Array(result.packedBuffer);\n const indicesBytesPerElement = unpackBuffer(geometries, packedBuffer);\n\n if (indicesBytesPerElement === 2) {\n geometries._indices = new Uint16Array(result.indices);\n } else {\n geometries._indices = new Uint32Array(result.indices);\n }\n\n geometries._indexOffsets = new Uint32Array(result.indexOffsets);\n geometries._indexCounts = new Uint32Array(result.indexCounts);\n\n geometries._positions = new Float32Array(result.positions);\n geometries._vertexBatchIds = new Uint16Array(result.vertexBatchIds);\n\n geometries._batchIds = new Uint16Array(result.batchIds);\n\n finishPrimitive(geometries);\n\n geometries._ready = true;\n })\n .catch((error) => {\n if (geometries.isDestroyed()) {\n return;\n }\n\n geometries._error = error;\n });\n }\n}\n\nfunction finishPrimitive(geometries) {\n if (!defined(geometries._primitive)) {\n geometries._primitive = new Vector3DTilePrimitive({\n batchTable: geometries._batchTable,\n positions: geometries._positions,\n batchIds: geometries._batchIds,\n vertexBatchIds: geometries._vertexBatchIds,\n indices: geometries._indices,\n indexOffsets: geometries._indexOffsets,\n indexCounts: geometries._indexCounts,\n batchedIndices: geometries._batchedIndices,\n boundingVolume: geometries._boundingVolume,\n boundingVolumes: geometries._boundingVolumes,\n center: geometries._center,\n pickObject: defaultValue(geometries._pickObject, geometries),\n });\n\n geometries._boxes = undefined;\n geometries._boxBatchIds = undefined;\n geometries._cylinders = undefined;\n geometries._cylinderBatchIds = undefined;\n geometries._ellipsoids = undefined;\n geometries._ellipsoidBatchIds = undefined;\n geometries._spheres = undefined;\n geometries._sphereBatchIds = undefined;\n geometries._center = undefined;\n geometries._modelMatrix = undefined;\n geometries._batchTable = undefined;\n geometries._boundingVolume = undefined;\n\n geometries._boundingVolumes = undefined;\n geometries._batchedIndices = undefined;\n\n geometries._indices = undefined;\n geometries._indexOffsets = undefined;\n geometries._indexCounts = undefined;\n\n geometries._positions = undefined;\n geometries._vertexBatchIds = undefined;\n\n geometries._batchIds = undefined;\n\n geometries._batchTableColors = undefined;\n geometries._packedBuffer = undefined;\n\n geometries._verticesPromise = undefined;\n }\n}\n\n/**\n * Creates features for each geometry and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the polygon features will be placed.\n */\nVector3DTileGeometry.prototype.createFeatures = function (content, features) {\n this._primitive.createFeatures(content, features);\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (geometry batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTileGeometry.prototype.applyDebugSettings = function (enabled, color) {\n this._primitive.applyDebugSettings(enabled, color);\n};\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The array of features.\n */\nVector3DTileGeometry.prototype.applyStyle = function (style, features) {\n this._primitive.applyStyle(style, features);\n};\n\n/**\n * Call when updating the color of a geometry with batchId changes color. The geometries will need to be re-batched\n * on the next update.\n *\n * @param {number} batchId The batch id of the geometries whose color has changed.\n * @param {Color} color The new polygon color.\n */\nVector3DTileGeometry.prototype.updateCommands = function (batchId, color) {\n this._primitive.updateCommands(batchId, color);\n};\n\n/**\n * Updates the batches and queues the commands for rendering.\n *\n * @param {FrameState} frameState The current frame state.\n */\nVector3DTileGeometry.prototype.update = function (frameState) {\n if (!this._ready) {\n if (!defined(this._promise)) {\n this._promise = createPrimitive(this);\n }\n\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n return;\n }\n\n this._primitive.debugWireframe = this.debugWireframe;\n this._primitive.forceRebatch = this.forceRebatch;\n this._primitive.classificationType = this.classificationType;\n this._primitive.update(frameState);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTileGeometry.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTileGeometry.prototype.destroy = function () {\n this._primitive = this._primitive && this._primitive.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTileGeometry;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Cesium3DTileBatchTable from \"./Cesium3DTileBatchTable.js\";\nimport Vector3DTileGeometry from \"./Vector3DTileGeometry.js\";\n\n/**\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @alias Geometry3DTileContent\n * @constructor\n *\n * @private\n */\nfunction Geometry3DTileContent(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n) {\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n this._geometries = undefined;\n\n this._metadata = undefined;\n\n this._batchTable = undefined;\n this._features = undefined;\n\n /**\n * Part of the {@link Cesium3DTileContent} interface.\n */\n this.featurePropertiesDirty = false;\n this._group = undefined;\n\n this._ready = false;\n\n initialize(this, arrayBuffer, byteOffset);\n}\n\nObject.defineProperties(Geometry3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n return defined(this._batchTable) ? this._batchTable.featuresLength : 0;\n },\n },\n\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n trianglesLength: {\n get: function () {\n if (defined(this._geometries)) {\n return this._geometries.trianglesLength;\n }\n return 0;\n },\n },\n\n geometryByteLength: {\n get: function () {\n if (defined(this._geometries)) {\n return this._geometries.geometryByteLength;\n }\n return 0;\n },\n },\n\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n return defined(this._batchTable)\n ? this._batchTable.batchTableByteLength\n : 0;\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Geometry3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._resource.getUrlComponent(true);\n },\n },\n\n metadata: {\n get: function () {\n return this._metadata;\n },\n set: function (value) {\n this._metadata = value;\n },\n },\n\n batchTable: {\n get: function () {\n return this._batchTable;\n },\n },\n\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n },\n },\n});\n\nfunction createColorChangedCallback(content) {\n return function (batchId, color) {\n if (defined(content._geometries)) {\n content._geometries.updateCommands(batchId, color);\n }\n };\n}\n\nfunction getBatchIds(featureTableJson, featureTableBinary) {\n let boxBatchIds;\n let cylinderBatchIds;\n let ellipsoidBatchIds;\n let sphereBatchIds;\n let i;\n\n const numberOfBoxes = defaultValue(featureTableJson.BOXES_LENGTH, 0);\n const numberOfCylinders = defaultValue(featureTableJson.CYLINDERS_LENGTH, 0);\n const numberOfEllipsoids = defaultValue(\n featureTableJson.ELLIPSOIDS_LENGTH,\n 0\n );\n const numberOfSpheres = defaultValue(featureTableJson.SPHERES_LENGTH, 0);\n\n if (numberOfBoxes > 0 && defined(featureTableJson.BOX_BATCH_IDS)) {\n const boxBatchIdsByteOffset =\n featureTableBinary.byteOffset + featureTableJson.BOX_BATCH_IDS.byteOffset;\n boxBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n boxBatchIdsByteOffset,\n numberOfBoxes\n );\n }\n\n if (numberOfCylinders > 0 && defined(featureTableJson.CYLINDER_BATCH_IDS)) {\n const cylinderBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.CYLINDER_BATCH_IDS.byteOffset;\n cylinderBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n cylinderBatchIdsByteOffset,\n numberOfCylinders\n );\n }\n\n if (numberOfEllipsoids > 0 && defined(featureTableJson.ELLIPSOID_BATCH_IDS)) {\n const ellipsoidBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.ELLIPSOID_BATCH_IDS.byteOffset;\n ellipsoidBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n ellipsoidBatchIdsByteOffset,\n numberOfEllipsoids\n );\n }\n\n if (numberOfSpheres > 0 && defined(featureTableJson.SPHERE_BATCH_IDS)) {\n const sphereBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.SPHERE_BATCH_IDS.byteOffset;\n sphereBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n sphereBatchIdsByteOffset,\n numberOfSpheres\n );\n }\n\n const atLeastOneDefined =\n defined(boxBatchIds) ||\n defined(cylinderBatchIds) ||\n defined(ellipsoidBatchIds) ||\n defined(sphereBatchIds);\n const atLeastOneUndefined =\n (numberOfBoxes > 0 && !defined(boxBatchIds)) ||\n (numberOfCylinders > 0 && !defined(cylinderBatchIds)) ||\n (numberOfEllipsoids > 0 && !defined(ellipsoidBatchIds)) ||\n (numberOfSpheres > 0 && !defined(sphereBatchIds));\n\n if (atLeastOneDefined && atLeastOneUndefined) {\n throw new RuntimeError(\n \"If one group of batch ids is defined, then all batch ids must be defined\"\n );\n }\n\n const allUndefinedBatchIds =\n !defined(boxBatchIds) &&\n !defined(cylinderBatchIds) &&\n !defined(ellipsoidBatchIds) &&\n !defined(sphereBatchIds);\n if (allUndefinedBatchIds) {\n let id = 0;\n if (!defined(boxBatchIds) && numberOfBoxes > 0) {\n boxBatchIds = new Uint16Array(numberOfBoxes);\n for (i = 0; i < numberOfBoxes; ++i) {\n boxBatchIds[i] = id++;\n }\n }\n if (!defined(cylinderBatchIds) && numberOfCylinders > 0) {\n cylinderBatchIds = new Uint16Array(numberOfCylinders);\n for (i = 0; i < numberOfCylinders; ++i) {\n cylinderBatchIds[i] = id++;\n }\n }\n if (!defined(ellipsoidBatchIds) && numberOfEllipsoids > 0) {\n ellipsoidBatchIds = new Uint16Array(numberOfEllipsoids);\n for (i = 0; i < numberOfEllipsoids; ++i) {\n ellipsoidBatchIds[i] = id++;\n }\n }\n if (!defined(sphereBatchIds) && numberOfSpheres > 0) {\n sphereBatchIds = new Uint16Array(numberOfSpheres);\n for (i = 0; i < numberOfSpheres; ++i) {\n sphereBatchIds[i] = id++;\n }\n }\n }\n\n return {\n boxes: boxBatchIds,\n cylinders: cylinderBatchIds,\n ellipsoids: ellipsoidBatchIds,\n spheres: sphereBatchIds,\n };\n}\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\nfunction initialize(content, arrayBuffer, byteOffset) {\n byteOffset = defaultValue(byteOffset, 0);\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic number\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Geometry tile version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n const byteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n if (byteLength === 0) {\n content._ready = true;\n return;\n }\n\n const featureTableJSONByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n if (featureTableJSONByteLength === 0) {\n throw new RuntimeError(\n \"Feature table must have a byte length greater than zero\"\n );\n }\n\n const featureTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const batchTableJSONByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const batchTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const featureTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n featureTableJSONByteLength\n );\n byteOffset += featureTableJSONByteLength;\n\n const featureTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n featureTableBinaryByteLength\n );\n byteOffset += featureTableBinaryByteLength;\n\n let batchTableJson;\n let batchTableBinary;\n if (batchTableJSONByteLength > 0) {\n // PERFORMANCE_IDEA: is it possible to allocate this on-demand? Perhaps keep the\n // arraybuffer/string compressed in memory and then decompress it when it is first accessed.\n //\n // We could also make another request for it, but that would make the property set/get\n // API async, and would double the number of numbers in some cases.\n batchTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n batchTableJSONByteLength\n );\n byteOffset += batchTableJSONByteLength;\n\n if (batchTableBinaryByteLength > 0) {\n // Has a batch table binary\n batchTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n batchTableBinaryByteLength\n );\n // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed\n batchTableBinary = new Uint8Array(batchTableBinary);\n }\n }\n\n const numberOfBoxes = defaultValue(featureTableJson.BOXES_LENGTH, 0);\n const numberOfCylinders = defaultValue(featureTableJson.CYLINDERS_LENGTH, 0);\n const numberOfEllipsoids = defaultValue(\n featureTableJson.ELLIPSOIDS_LENGTH,\n 0\n );\n const numberOfSpheres = defaultValue(featureTableJson.SPHERES_LENGTH, 0);\n\n const totalPrimitives =\n numberOfBoxes + numberOfCylinders + numberOfEllipsoids + numberOfSpheres;\n\n const batchTable = new Cesium3DTileBatchTable(\n content,\n totalPrimitives,\n batchTableJson,\n batchTableBinary,\n createColorChangedCallback(content)\n );\n content._batchTable = batchTable;\n\n if (totalPrimitives === 0) {\n return;\n }\n\n const modelMatrix = content.tile.computedTransform;\n\n let center;\n if (defined(featureTableJson.RTC_CENTER)) {\n center = Cartesian3.unpack(featureTableJson.RTC_CENTER);\n Matrix4.multiplyByPoint(modelMatrix, center, center);\n }\n\n const batchIds = getBatchIds(featureTableJson, featureTableBinary);\n\n if (\n numberOfBoxes > 0 ||\n numberOfCylinders > 0 ||\n numberOfEllipsoids > 0 ||\n numberOfSpheres > 0\n ) {\n let boxes;\n let cylinders;\n let ellipsoids;\n let spheres;\n\n if (numberOfBoxes > 0) {\n const boxesByteOffset =\n featureTableBinary.byteOffset + featureTableJson.BOXES.byteOffset;\n boxes = new Float32Array(\n featureTableBinary.buffer,\n boxesByteOffset,\n Vector3DTileGeometry.packedBoxLength * numberOfBoxes\n );\n }\n\n if (numberOfCylinders > 0) {\n const cylindersByteOffset =\n featureTableBinary.byteOffset + featureTableJson.CYLINDERS.byteOffset;\n cylinders = new Float32Array(\n featureTableBinary.buffer,\n cylindersByteOffset,\n Vector3DTileGeometry.packedCylinderLength * numberOfCylinders\n );\n }\n\n if (numberOfEllipsoids > 0) {\n const ellipsoidsByteOffset =\n featureTableBinary.byteOffset + featureTableJson.ELLIPSOIDS.byteOffset;\n ellipsoids = new Float32Array(\n featureTableBinary.buffer,\n ellipsoidsByteOffset,\n Vector3DTileGeometry.packedEllipsoidLength * numberOfEllipsoids\n );\n }\n\n if (numberOfSpheres > 0) {\n const spheresByteOffset =\n featureTableBinary.byteOffset + featureTableJson.SPHERES.byteOffset;\n spheres = new Float32Array(\n featureTableBinary.buffer,\n spheresByteOffset,\n Vector3DTileGeometry.packedSphereLength * numberOfSpheres\n );\n }\n\n content._geometries = new Vector3DTileGeometry({\n boxes: boxes,\n boxBatchIds: batchIds.boxes,\n cylinders: cylinders,\n cylinderBatchIds: batchIds.cylinders,\n ellipsoids: ellipsoids,\n ellipsoidBatchIds: batchIds.ellipsoids,\n spheres: spheres,\n sphereBatchIds: batchIds.spheres,\n center: center,\n modelMatrix: modelMatrix,\n batchTable: batchTable,\n boundingVolume: content.tile.boundingVolume.boundingVolume,\n });\n\n return content;\n }\n\n return Promise.resolve(content);\n}\n\nfunction createFeatures(content) {\n const featuresLength = content.featuresLength;\n if (!defined(content._features) && featuresLength > 0) {\n const features = new Array(featuresLength);\n if (defined(content._geometries)) {\n content._geometries.createFeatures(content, features);\n }\n content._features = features;\n }\n}\n\nGeometry3DTileContent.prototype.hasProperty = function (batchId, name) {\n return this._batchTable.hasProperty(batchId, name);\n};\n\nGeometry3DTileContent.prototype.getFeature = function (batchId) {\n //>>includeStart('debug', pragmas.debug);\n const featuresLength = this.featuresLength;\n if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {\n throw new DeveloperError(\n `batchId is required and between zero and featuresLength - 1 (${\n featuresLength - 1\n }).`\n );\n }\n //>>includeEnd('debug');\n\n createFeatures(this);\n return this._features[batchId];\n};\n\nGeometry3DTileContent.prototype.applyDebugSettings = function (enabled, color) {\n if (defined(this._geometries)) {\n this._geometries.applyDebugSettings(enabled, color);\n }\n};\n\nGeometry3DTileContent.prototype.applyStyle = function (style) {\n createFeatures(this);\n if (defined(this._geometries)) {\n this._geometries.applyStyle(style, this._features);\n }\n};\n\nGeometry3DTileContent.prototype.update = function (tileset, frameState) {\n if (defined(this._geometries)) {\n this._geometries.classificationType = this._tileset.classificationType;\n this._geometries.debugWireframe = this._tileset.debugWireframe;\n this._geometries.update(frameState);\n }\n\n if (defined(this._batchTable) && this._geometries.ready) {\n this._batchTable.update(tileset, frameState);\n this._ready = true;\n }\n};\n\nGeometry3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nGeometry3DTileContent.prototype.destroy = function () {\n this._geometries = this._geometries && this._geometries.destroy();\n this._batchTable = this._batchTable && this._batchTable.destroy();\n return destroyObject(this);\n};\nexport default Geometry3DTileContent;\n", "import Check from \"./Check.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Hilbert Order helper functions.\n *\n * @namespace HilbertOrder\n */\nconst HilbertOrder = {};\n\n/**\n * Computes the Hilbert index at the given level from 2D coordinates.\n *\n * @param {number} level The level of the curve\n * @param {number} x The X coordinate\n * @param {number} y The Y coordinate\n * @returns {number} The Hilbert index.\n * @private\n */\nHilbertOrder.encode2D = function (level, x, y) {\n const n = Math.pow(2, level);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"level\", level);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n if (level < 1) {\n throw new DeveloperError(\"Hilbert level cannot be less than 1.\");\n }\n if (x < 0 || x >= n || y < 0 || y >= n) {\n throw new DeveloperError(\"Invalid coordinates for given level.\");\n }\n //>>includeEnd('debug');\n\n const p = {\n x: x,\n y: y,\n };\n let rx,\n ry,\n s,\n // eslint-disable-next-line no-undef\n index = BigInt(0);\n\n for (s = n / 2; s > 0; s /= 2) {\n rx = (p.x & s) > 0 ? 1 : 0;\n ry = (p.y & s) > 0 ? 1 : 0;\n // eslint-disable-next-line no-undef\n index += BigInt(((3 * rx) ^ ry) * s * s);\n rotate(n, p, rx, ry);\n }\n\n return index;\n};\n\n/**\n * Computes the 2D coordinates from the Hilbert index at the given level.\n *\n * @param {number} level The level of the curve\n * @param {bigint} index The Hilbert index\n * @returns {number[]} An array containing the 2D coordinates ([x, y]) corresponding to the Morton index.\n * @private\n */\nHilbertOrder.decode2D = function (level, index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"level\", level);\n Check.typeOf.bigint(\"index\", index);\n if (level < 1) {\n throw new DeveloperError(\"Hilbert level cannot be less than 1.\");\n }\n // eslint-disable-next-line no-undef\n if (index < BigInt(0) || index >= BigInt(Math.pow(4, level))) {\n throw new DeveloperError(\n \"Hilbert index exceeds valid maximum for given level.\"\n );\n }\n //>>includeEnd('debug');\n\n const n = Math.pow(2, level);\n const p = {\n x: 0,\n y: 0,\n };\n let rx, ry, s, t;\n\n for (s = 1, t = index; s < n; s *= 2) {\n // eslint-disable-next-line no-undef\n rx = 1 & Number(t / BigInt(2));\n // eslint-disable-next-line no-undef\n ry = 1 & Number(t ^ BigInt(rx));\n rotate(s, p, rx, ry);\n p.x += s * rx;\n p.y += s * ry;\n // eslint-disable-next-line no-undef\n t /= BigInt(4);\n }\n\n return [p.x, p.y];\n};\n\n/**\n * @private\n */\nfunction rotate(n, p, rx, ry) {\n if (ry !== 0) {\n return;\n }\n\n if (rx === 1) {\n p.x = n - 1 - p.x;\n p.y = n - 1 - p.y;\n }\n\n const t = p.x;\n p.x = p.y;\n p.y = t;\n}\n\nexport default HilbertOrder;\n", "/* eslint-disable new-cap */\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport FeatureDetection from \"./FeatureDetection.js\";\nimport RuntimeError from \"./RuntimeError.js\";\n\n/**\n * S2\n * --\n *\n * This implementation is based on the S2 C++ reference implementation: https://github.com/google/s2geometry\n *\n *\n * Overview:\n * ---------\n * The S2 library decomposes the unit sphere into a hierarchy of cells. A cell is a quadrilateral bounded by 4 geodesics.\n * The 6 root cells are obtained by projecting the six faces of a cube on a unit sphere. Each root cell follows a quadtree\n * subdivision scheme, i.e. each cell subdivides into 4 smaller cells that cover the same area as the parent cell. The S2 cell\n * hierarchy extends from level 0 (root cells) to level 30 (leaf cells). The root cells are rotated to enable a continuous Hilbert\n * curve to map all 6 faces of the cube.\n *\n *\n * Cell ID:\n * --------\n * Each cell in S2 can be uniquely identified using a 64-bit unsigned integer, its cell ID. The first 3 bits of the cell ID are the face bits, i.e.\n * they indicate which of the 6 faces of the cube a cell lies on. After the face bits are the position bits, i.e. they indicate the position\n * of the cell along the Hilbert curve. After the positions bits is the sentinel bit, which is always set to 1, and it indicates the level of the\n * cell. Again, the level can be between 0 and 30 in S2.\n *\n * Note: In the illustration below, the face bits are marked with 'f', the position bits are marked with 'p', the zero bits are marked with '-'.\n *\n * Cell ID (base 10): 3170534137668829184\n * Cell ID (base 2) : 0010110000000000000000000000000000000000000000000000000000000000\n *\n * 001 0110000000000000000000000000000000000000000000000000000000000\n * fff pps----------------------------------------------------------\n *\n * For the cell above, we can see that it lies on face 1 (01), with a Hilbert index of 1 (1).\n *\n *\n * Cell Subdivision:\n * ------------------\n * Cells in S2 subdivide recursively using quadtree subdivision. For each cell, you can get a child of index [0-3]. To compute the child at index i,\n * insert the base 2 representation of i to the right of the parent's position bits. Ensure that the sentinel bit is also shifted two places to the right.\n *\n * Parent Cell ID (base 10) : 3170534137668829184\n * Parent Cell ID (base 2) : 0010110000000000000000000000000000000000000000000000000000000000\n *\n * 001 0110000000000000000000000000000000000000000000000000000000000\n * fff pps----------------------------------------------------------\n *\n * To get the 3rd child of the cell above, we insert the binary representation of 3 to the right of the parent's position bits:\n *\n * Note: In the illustration below, the bits to be added are highlighted with '^'.\n *\n * 001 0111100000000000000000000000000000000000000000000000000000000\n * fff pppps--------------------------------------------------------\n * ^^\n *\n * Child(3) Cell ID (base 10) : 3386706919782612992\n * Child(3) Cell ID (base 2) : 0010111100000000000000000000000000000000000000000000000000000000\n *\n * Cell Token:\n * -----------\n * To provide a more concise representation of the S2 cell ID, we can use their hexadecimal representation.\n *\n * Cell ID (base 10): 3170534137668829184\n * Cell ID (base 2) : 0010110000000000000000000000000000000000000000000000000000000000\n *\n * We remove all trailing zero bits, until we reach the nybble (4 bits) that contains the sentinel bit.\n *\n * Note: In the illustration below, the bits to be removed are highlighted with 'X'.\n *\n * 0010110000000000000000000000000000000000000000000000000000000000\n * fffpps--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n *\n * We convert the remaining bits to their hexadecimal representation.\n *\n * Base 2: 0010 1100\n * Base 16: \"2\" \"c\"\n *\n * Cell Token: \"2c\"\n *\n * To compute the cell ID from the token, we simply add enough zeros to the right to make the ID span 64 bits.\n *\n * Coordinate Transforms:\n * ----------------------\n *\n * To go from a cell in S2 to a point on the ellipsoid, the following order of transforms is applied:\n *\n * 1. (Cell ID): S2 cell ID\n * 2. (Face, I, J): Leaf cell coordinates, where i and j are in range [0, 2^30 - 1]\n * 3. (Face, S, T): Cell space coordinates, where s and t are in range [0, 1].\n * 4. (Face, Si, Ti): Discrete cell space coordinates, where si and ti are in range [0, 2^31]\n * 5. (Face, U, V): Cube space coordinates, where u and v are in range [-1, 1]. We apply the non-linear quadratic transform here.\n * 6. (X, Y, Z): Direction vector, where vector may not be unit length. Can be normalized to obtain point on unit sphere\n * 7. (Latitude, Longitude): Direction vector, where latitude is in range [-90, 90] and longitude is in range [-180, 180]\n *\n * @ignore\n */\n\n// The maximum level supported within an S2 cell ID. Each level is represented by two bits in the final cell ID\nconst S2_MAX_LEVEL = 30;\n\n// The maximum index of a valid leaf cell plus one. The range of valid leaf cell indices is [0..S2_LIMIT_IJ-1].\nconst S2_LIMIT_IJ = 1 << S2_MAX_LEVEL;\n\n// The maximum value of an si- or ti-coordinate. The range of valid (si,ti) values is [0..S2_MAX_SITI]. Use `>>>` to convert to unsigned.\nconst S2_MAX_SITI = (1 << (S2_MAX_LEVEL + 1)) >>> 0;\n\n// The number of bits in a S2 cell ID used for specifying the position along the Hilbert curve\nconst S2_POSITION_BITS = 2 * S2_MAX_LEVEL + 1;\n\n// The number of bits per I and J in the lookup tables\nconst S2_LOOKUP_BITS = 4;\n\n// Lookup table for mapping 10 bits of IJ + orientation to 10 bits of Hilbert curve position + orientation.\nconst S2_LOOKUP_POSITIONS = [];\n\n// Lookup table for mapping 10 bits of IJ + orientation to 10 bits of Hilbert curve position + orientation.\nconst S2_LOOKUP_IJ = [];\n\n// Lookup table of two bits of IJ from two bits of curve position, based also on the current curve orientation from the swap and invert bits\nconst S2_POSITION_TO_IJ = [\n [0, 1, 3, 2], // 0: Normal order, no swap or invert\n [0, 2, 3, 1], // 1: Swap bit set, swap I and J bits\n [3, 2, 0, 1], // 2: Invert bit set, invert bits\n [3, 1, 0, 2], // 3: Swap and invert bits set\n];\n\n// Mask that specifies the swap orientation bit for the Hilbert curve\nconst S2_SWAP_MASK = 1;\n\n// Mask that specifies the invert orientation bit for the Hilbert curve\nconst S2_INVERT_MASK = 2;\n\n// Lookup for the orientation update mask of one of the four sub-cells within a higher level cell.\n// This mask is XOR'ed with the current orientation to get the sub-cell orientation.\nconst S2_POSITION_TO_ORIENTATION_MASK = [\n S2_SWAP_MASK,\n 0,\n 0,\n S2_SWAP_MASK | S2_INVERT_MASK,\n];\n\n/**\n * Represents a cell in the S2 geometry library.\n *\n * @alias S2Cell\n * @constructor\n *\n * @param {bigint} [cellId] The 64-bit S2CellId.\n * @private\n */\nfunction S2Cell(cellId) {\n if (!FeatureDetection.supportsBigInt()) {\n throw new RuntimeError(\"S2 required BigInt support\");\n }\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cellId)) {\n throw new DeveloperError(\"cell ID is required.\");\n }\n if (!S2Cell.isValidId(cellId)) {\n throw new DeveloperError(\"cell ID is invalid.\");\n }\n //>>includeEnd('debug');\n\n this._cellId = cellId;\n this._level = S2Cell.getLevel(cellId);\n}\n\n/**\n * Creates a new S2Cell from a token. A token is a hexadecimal representation of the 64-bit S2CellId.\n *\n * @param {string} token The token for the S2 Cell.\n * @returns {S2Cell} Returns a new S2Cell.\n * @private\n */\nS2Cell.fromToken = function (token) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"token\", token);\n if (!S2Cell.isValidToken(token)) {\n throw new DeveloperError(\"token is invalid.\");\n }\n //>>includeEnd('debug');\n\n return new S2Cell(S2Cell.getIdFromToken(token));\n};\n\n/**\n * Validates an S2 cell ID.\n *\n * @param {bigint} [cellId] The S2CellId.\n * @returns {boolean} Returns true if the cell ID is valid, returns false otherwise.\n * @private\n */\nS2Cell.isValidId = function (cellId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bigint(\"cellId\", cellId);\n //>>includeEnd('debug');\n\n // Check if sentinel bit is missing.\n if (cellId <= 0) {\n return false;\n }\n\n // Check if face bits indicate a valid value, in range [0-5].\n // eslint-disable-next-line\n if (cellId >> BigInt(S2_POSITION_BITS) > 5) {\n return false;\n }\n\n // Check trailing 1 bit is in one of the even bit positions allowed for the 30 levels, using a bitmask.\n // eslint-disable-next-line no-undef\n const lowestSetBit = cellId & (~cellId + BigInt(1));\n // eslint-disable-next-line\n if (!(lowestSetBit & BigInt(\"0x1555555555555555\"))) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Validates an S2 cell token.\n *\n * @param {string} [token] The hexadecimal representation of an S2CellId.\n * @returns {boolean} Returns true if the token is valid, returns false otherwise.\n * @private\n */\nS2Cell.isValidToken = function (token) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"token\", token);\n //>>includeEnd('debug');\n\n if (!/^[0-9a-fA-F]{1,16}$/.test(token)) {\n return false;\n }\n\n return S2Cell.isValidId(S2Cell.getIdFromToken(token));\n};\n\n/**\n * Converts an S2 cell token to a 64-bit S2 cell ID.\n *\n * @param {string} [token] The hexadecimal representation of an S2CellId. Expected to be a valid S2 token.\n * @returns {bigint} Returns the S2 cell ID.\n * @private\n */\nS2Cell.getIdFromToken = function (token) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"token\", token);\n //>>includeEnd('debug');\n\n return BigInt(\"0x\" + token + \"0\".repeat(16 - token.length)); // eslint-disable-line\n};\n\n/**\n * Converts a 64-bit S2 cell ID to an S2 cell token.\n *\n * @param {bigint} [cellId] The S2 cell ID.\n * @returns {string} Returns hexadecimal representation of an S2CellId.\n * @private\n */\nS2Cell.getTokenFromId = function (cellId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bigint(\"cellId\", cellId);\n //>>includeEnd('debug');\n\n const trailingZeroHexChars = Math.floor(countTrailingZeroBits(cellId) / 4);\n const hexString = cellId.toString(16).replace(/0*$/, \"\");\n\n const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join(\n \"0\"\n );\n return zeroString + hexString;\n};\n\n/**\n * Gets the level of the cell from the cell ID.\n *\n * @param {bigint} [cellId] The S2 cell ID.\n * @returns {number} Returns the level of the cell.\n * @private\n */\nS2Cell.getLevel = function (cellId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bigint(\"cellId\", cellId);\n if (!S2Cell.isValidId(cellId)) {\n throw new DeveloperError();\n }\n //>>includeEnd('debug');\n\n let lsbPosition = 0;\n // eslint-disable-next-line\n while (cellId !== BigInt(0)) {\n // eslint-disable-next-line\n if (cellId & BigInt(1)) {\n break;\n }\n lsbPosition++;\n cellId = cellId >> BigInt(1); // eslint-disable-line\n }\n\n // We use (>> 1) because there are 2 bits per level.\n return S2_MAX_LEVEL - (lsbPosition >> 1);\n};\n\n/**\n * Gets the child cell of the cell at the given index.\n *\n * @param {number} index An integer index of the child.\n * @returns {S2Cell} The child of the S2Cell.\n * @private\n */\nS2Cell.prototype.getChild = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n if (index < 0 || index > 3) {\n throw new DeveloperError(\"child index must be in the range [0-3].\");\n }\n if (this._level === 30) {\n throw new DeveloperError(\"cannot get child of leaf cell.\");\n }\n //>>includeEnd('debug');\n\n // Shift sentinel bit 2 positions to the right.\n // eslint-disable-next-line no-undef\n const newLsb = lsb(this._cellId) >> BigInt(2);\n // Insert child index before the sentinel bit.\n // eslint-disable-next-line no-undef\n const childCellId = this._cellId + BigInt(2 * index + 1 - 4) * newLsb;\n return new S2Cell(childCellId);\n};\n\n/**\n * Gets the parent cell of an S2Cell.\n *\n * @returns {S2Cell} Returns the parent of the S2Cell.\n * @private\n */\nS2Cell.prototype.getParent = function () {\n //>>includeStart('debug', pragmas.debug);\n if (this._level === 0) {\n throw new DeveloperError(\"cannot get parent of root cell.\");\n }\n //>>includeEnd('debug');\n // Shift the sentinel bit 2 positions to the left.\n // eslint-disable-next-line no-undef\n const newLsb = lsb(this._cellId) << BigInt(2);\n // Erase the left over bits to the right of the sentinel bit.\n // eslint-disable-next-line no-undef\n return new S2Cell((this._cellId & (~newLsb + BigInt(1))) | newLsb);\n};\n\n/**\n * Gets the parent cell at the given level.\n *\n * @returns {S2Cell} Returns the parent of the S2Cell.\n * @private\n */\nS2Cell.prototype.getParentAtLevel = function (level) {\n //>>includeStart('debug', pragmas.debug);\n if (this._level === 0 || level < 0 || this._level < level) {\n throw new DeveloperError(\"cannot get parent at invalid level.\");\n }\n //>>includeEnd('debug');\n const newLsb = lsbForLevel(level);\n return new S2Cell((this._cellId & -newLsb) | newLsb);\n};\n\n/**\n * Get center of the S2 cell.\n *\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n * @returns {Cartesian3} The position of center of the S2 cell.\n * @private\n */\nS2Cell.prototype.getCenter = function (ellipsoid) {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n let center = getS2Center(this._cellId, this._level);\n // Normalize XYZ.\n center = Cartesian3.normalize(center, center);\n const cartographic = new Cartographic.fromCartesian(\n center,\n Ellipsoid.UNIT_SPHERE\n );\n // Interpret as geodetic coordinates on the ellipsoid.\n return Cartographic.toCartesian(cartographic, ellipsoid, new Cartesian3());\n};\n\n/**\n * Get vertex of the S2 cell. Vertices are indexed in CCW order.\n *\n * @param {number} index An integer index of the vertex. Must be in the range [0-3].\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n * @returns {Cartesian3} The position of the vertex of the S2 cell.\n * @private\n */\nS2Cell.prototype.getVertex = function (index, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n if (index < 0 || index > 3) {\n throw new DeveloperError(\"vertex index must be in the range [0-3].\");\n }\n //>>includeEnd('debug');\n\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n let vertex = getS2Vertex(this._cellId, this._level, index);\n // Normalize XYZ.\n vertex = Cartesian3.normalize(vertex, vertex);\n const cartographic = new Cartographic.fromCartesian(\n vertex,\n Ellipsoid.UNIT_SPHERE\n );\n // Interpret as geodetic coordinates on the ellipsoid.\n return Cartographic.toCartesian(cartographic, ellipsoid, new Cartesian3());\n};\n\n/**\n * Creates an S2Cell from its face, position along the Hilbert curve for a given level.\n *\n * @param {number} face The root face of S2 this cell is on. Must be in the range [0-5].\n * @param {bigint} position The position along the Hilbert curve. Must be in the range [0-4**level).\n * @param {number} level The level of the S2 curve. Must be in the range [0-30].\n * @returns {S2Cell} A new S2Cell from the given parameters.\n * @private\n */\nS2Cell.fromFacePositionLevel = function (face, position, level) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bigint(\"position\", position);\n if (face < 0 || face > 5) {\n throw new DeveloperError(\"Invalid S2 Face (must be within 0-5)\");\n }\n\n if (level < 0 || level > S2_MAX_LEVEL) {\n throw new DeveloperError(\"Invalid level (must be within 0-30)\");\n }\n if (position < 0 || position >= Math.pow(4, level)) {\n throw new DeveloperError(\"Invalid Hilbert position for level\");\n }\n //>>includeEnd('debug');\n\n const faceBitString =\n (face < 4 ? \"0\" : \"\") + (face < 2 ? \"0\" : \"\") + face.toString(2);\n const positionBitString = position.toString(2);\n const positionPrefixPadding = Array(\n 2 * level - positionBitString.length + 1\n ).join(\"0\");\n const positionSuffixPadding = Array(S2_POSITION_BITS - 2 * level).join(\"0\");\n\n // eslint-disable-next-line no-undef\n const cellId = BigInt(\n `0b${faceBitString}${positionPrefixPadding}${positionBitString}1${\n // Adding the sentinel bit that always follows the position bits.\n positionSuffixPadding\n }`\n );\n return new S2Cell(cellId);\n};\n\n/**\n * @private\n */\nfunction getS2Center(cellId, level) {\n const faceSiTi = convertCellIdToFaceSiTi(cellId, level);\n return convertFaceSiTitoXYZ(faceSiTi[0], faceSiTi[1], faceSiTi[2]);\n}\n/**\n * @private\n */\nfunction getS2Vertex(cellId, level, index) {\n const faceIJ = convertCellIdToFaceIJ(cellId, level);\n const uv = convertIJLeveltoBoundUV([faceIJ[1], faceIJ[2]], level);\n // Handles CCW ordering of the vertices.\n const y = (index >> 1) & 1;\n return convertFaceUVtoXYZ(faceIJ[0], uv[0][y ^ (index & 1)], uv[1][y]);\n}\n\n// S2 Coordinate Conversions\n\n/**\n * @private\n */\nfunction convertCellIdToFaceSiTi(cellId, level) {\n const faceIJ = convertCellIdToFaceIJ(cellId);\n const face = faceIJ[0];\n const i = faceIJ[1];\n const j = faceIJ[2];\n\n // We're resolving the center when we do the coordinate transform here. For the leaf cells, we're adding half the cell size\n // (remember that this space has 31 levels - which allows us to pick center and edges of the leaf cells). For non leaf cells,\n // we get one of either two cells diagonal to the cell center. The correction is used to make sure we pick the leaf cell edges\n // that represent the parent cell center.\n const isLeaf = level === 30;\n const shouldCorrect =\n !isLeaf && (BigInt(i) ^ (cellId >> BigInt(2))) & BigInt(1); // eslint-disable-line\n const correction = isLeaf ? 1 : shouldCorrect ? 2 : 0;\n const si = (i << 1) + correction;\n const ti = (j << 1) + correction;\n return [face, si, ti];\n}\n\n/**\n * @private\n */\nfunction convertCellIdToFaceIJ(cellId) {\n if (S2_LOOKUP_POSITIONS.length === 0) {\n generateLookupTable();\n }\n\n // eslint-disable-next-line no-undef\n const face = Number(cellId >> BigInt(S2_POSITION_BITS));\n let bits = face & S2_SWAP_MASK;\n const lookupMask = (1 << S2_LOOKUP_BITS) - 1;\n\n let i = 0;\n let j = 0;\n\n for (let k = 7; k >= 0; k--) {\n const numberOfBits =\n k === 7 ? S2_MAX_LEVEL - 7 * S2_LOOKUP_BITS : S2_LOOKUP_BITS;\n const extractMask = (1 << (2 * numberOfBits)) - 1;\n bits +=\n Number(\n (cellId >> BigInt(k * 2 * S2_LOOKUP_BITS + 1)) & BigInt(extractMask) // eslint-disable-line\n ) << 2;\n\n bits = S2_LOOKUP_IJ[bits];\n\n const offset = k * S2_LOOKUP_BITS;\n i += (bits >> (S2_LOOKUP_BITS + 2)) << offset;\n j += ((bits >> 2) & lookupMask) << offset;\n\n bits &= S2_SWAP_MASK | S2_INVERT_MASK;\n }\n\n return [face, i, j];\n}\n\n/**\n * @private\n */\nfunction convertFaceSiTitoXYZ(face, si, ti) {\n const s = convertSiTitoST(si);\n const t = convertSiTitoST(ti);\n\n const u = convertSTtoUV(s);\n const v = convertSTtoUV(t);\n return convertFaceUVtoXYZ(face, u, v);\n}\n\n/**\n * @private\n */\nfunction convertFaceUVtoXYZ(face, u, v) {\n switch (face) {\n case 0:\n return new Cartesian3(1, u, v);\n case 1:\n return new Cartesian3(-u, 1, v);\n case 2:\n return new Cartesian3(-u, -v, 1);\n case 3:\n return new Cartesian3(-1, -v, -u);\n case 4:\n return new Cartesian3(v, -1, -u);\n default:\n return new Cartesian3(v, u, -1);\n }\n}\n\n/**\n * S2 provides 3 methods for the non-linear transform: linear, quadratic and tangential.\n * This implementation uses the quadratic method because it provides a good balance of\n * accuracy and speed.\n *\n * For a more detailed comparison of these transform methods, see\n * {@link https://github.com/google/s2geometry/blob/0c4c460bdfe696da303641771f9def900b3e440f/src/s2/s2metrics.cc}\n * @private\n */\nfunction convertSTtoUV(s) {\n if (s >= 0.5) {\n return (1 / 3) * (4 * s * s - 1);\n }\n return (1 / 3) * (1 - 4 * (1 - s) * (1 - s));\n}\n\n/**\n * @private\n */\nfunction convertSiTitoST(si) {\n return (1.0 / S2_MAX_SITI) * si;\n}\n\n/**\n * @private\n */\nfunction convertIJLeveltoBoundUV(ij, level) {\n const result = [[], []];\n const cellSize = getSizeIJ(level);\n for (let d = 0; d < 2; ++d) {\n const ijLow = ij[d] & -cellSize;\n const ijHigh = ijLow + cellSize;\n result[d][0] = convertSTtoUV(convertIJtoSTMinimum(ijLow));\n result[d][1] = convertSTtoUV(convertIJtoSTMinimum(ijHigh));\n }\n return result;\n}\n\n/**\n * @private\n */\nfunction getSizeIJ(level) {\n return (1 << (S2_MAX_LEVEL - level)) >>> 0;\n}\n\n/**\n * @private\n */\nfunction convertIJtoSTMinimum(i) {\n return (1.0 / S2_LIMIT_IJ) * i;\n}\n\n// Utility Functions\n\n/**\n * This function generates 4 variations of a Hilbert curve of level 4, based on the S2_POSITION_TO_IJ table, for fast lookups of (i, j)\n * to position along Hilbert curve. The reference C++ implementation uses an iterative approach, however, this function is implemented\n * recursively.\n *\n * See {@link https://github.com/google/s2geometry/blob/c59d0ca01ae3976db7f8abdc83fcc871a3a95186/src/s2/s2cell_id.cc#L75-L109}\n * @private\n */\nfunction generateLookupCell(\n level,\n i,\n j,\n originalOrientation,\n position,\n orientation\n) {\n if (level === S2_LOOKUP_BITS) {\n const ij = (i << S2_LOOKUP_BITS) + j;\n S2_LOOKUP_POSITIONS[(ij << 2) + originalOrientation] =\n (position << 2) + orientation;\n S2_LOOKUP_IJ[(position << 2) + originalOrientation] =\n (ij << 2) + orientation;\n } else {\n level++;\n i <<= 1;\n j <<= 1;\n position <<= 2;\n const r = S2_POSITION_TO_IJ[orientation];\n generateLookupCell(\n level,\n i + (r[0] >> 1),\n j + (r[0] & 1),\n originalOrientation,\n position,\n orientation ^ S2_POSITION_TO_ORIENTATION_MASK[0]\n );\n generateLookupCell(\n level,\n i + (r[1] >> 1),\n j + (r[1] & 1),\n originalOrientation,\n position + 1,\n orientation ^ S2_POSITION_TO_ORIENTATION_MASK[1]\n );\n generateLookupCell(\n level,\n i + (r[2] >> 1),\n j + (r[2] & 1),\n originalOrientation,\n position + 2,\n orientation ^ S2_POSITION_TO_ORIENTATION_MASK[2]\n );\n generateLookupCell(\n level,\n i + (r[3] >> 1),\n j + (r[3] & 1),\n originalOrientation,\n position + 3,\n orientation ^ S2_POSITION_TO_ORIENTATION_MASK[3]\n );\n }\n}\n\n/**\n * @private\n */\nfunction generateLookupTable() {\n generateLookupCell(0, 0, 0, 0, 0, 0);\n generateLookupCell(0, 0, 0, S2_SWAP_MASK, 0, S2_SWAP_MASK);\n generateLookupCell(0, 0, 0, S2_INVERT_MASK, 0, S2_INVERT_MASK);\n generateLookupCell(\n 0,\n 0,\n 0,\n S2_SWAP_MASK | S2_INVERT_MASK,\n 0,\n S2_SWAP_MASK | S2_INVERT_MASK\n );\n}\n\n/**\n * Return the lowest-numbered bit that is on for this cell id\n * @private\n */\nfunction lsb(cellId) {\n return cellId & (~cellId + BigInt(1)); // eslint-disable-line\n}\n\n/**\n * Return the lowest-numbered bit that is on for cells at the given level.\n * @private\n */\nfunction lsbForLevel(level) {\n return BigInt(1) << BigInt(2 * (S2_MAX_LEVEL - level)); // eslint-disable-line\n}\n\n// Lookup table for getting trailing zero bits.\n// https://graphics.stanford.edu/~seander/bithacks.html\nconst Mod67BitPosition = [\n 64,\n 0,\n 1,\n 39,\n 2,\n 15,\n 40,\n 23,\n 3,\n 12,\n 16,\n 59,\n 41,\n 19,\n 24,\n 54,\n 4,\n 64,\n 13,\n 10,\n 17,\n 62,\n 60,\n 28,\n 42,\n 30,\n 20,\n 51,\n 25,\n 44,\n 55,\n 47,\n 5,\n 32,\n 65,\n 38,\n 14,\n 22,\n 11,\n 58,\n 18,\n 53,\n 63,\n 9,\n 61,\n 27,\n 29,\n 50,\n 43,\n 46,\n 31,\n 37,\n 21,\n 57,\n 52,\n 8,\n 26,\n 49,\n 45,\n 36,\n 56,\n 7,\n 48,\n 35,\n 6,\n 34,\n 33,\n 0,\n];\n\n/**\n * Return the number of trailing zeros in number.\n * @private\n */\nfunction countTrailingZeroBits(x) {\n return Mod67BitPosition[(-x & x) % BigInt(67)]; // eslint-disable-line\n}\n\nexport default S2Cell;\n", "import defined from \"../Core/defined.js\";\n\n/**\n * Check if a specific extension is present on a JSON object. This can be used\n * for either 3D Tiles extensions or glTF extensions\n * @param {object} json The JSON object\n * @param {string} extensionName The name of the extension, e.g. '3DTILES_implicit_tiling'\n * @returns {boolean} True if the extension is present\n * @private\n */\nfunction hasExtension(json, extensionName) {\n return (\n defined(json) &&\n defined(json.extensions) &&\n defined(json.extensions[extensionName])\n );\n}\n\nexport default hasExtension;\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * An availability bitstream for use in an {@link ImplicitSubtree}. This handles\n * both Uint8Array bitstreams and constant values.\n *\n * @alias ImplicitAvailabilityBitstream\n * @constructor\n *\n * @param {object} options An object with the following properties:\n * @param {number} options.lengthBits The length of the bitstream in bits\n * @param {boolean} [options.constant] A single boolean value indicating the value of all the bits in the bitstream if they are all the same\n * @param {Uint8Array} [options.bitstream] An array of bytes storing the bitstream in binary\n * @param {number} [options.availableCount] A number indicating how many 1 bits are found in the bitstream\n * @param {boolean} [options.computeAvailableCountEnabled=false] If true, and options.availableCount is undefined, the availableCount will be computed from the bitstream.\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitAvailabilityBitstream(options) {\n const lengthBits = options.lengthBits;\n let availableCount = options.availableCount;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.lengthBits\", lengthBits);\n //>>includeEnd('debug');\n\n const constant = options.constant;\n const bitstream = options.bitstream;\n\n if (defined(constant)) {\n // if defined, constant must be 1 which means all tiles are available\n availableCount = lengthBits;\n } else {\n const expectedLength = Math.ceil(lengthBits / 8);\n if (bitstream.length !== expectedLength) {\n throw new RuntimeError(\n `Availability bitstream must be exactly ${expectedLength} bytes long to store ${lengthBits} bits. Actual bitstream was ${bitstream.length} bytes long.`\n );\n }\n\n // Only compute the available count if requested, as this involves looping\n // over the bitstream.\n const computeAvailableCountEnabled = defaultValue(\n options.computeAvailableCountEnabled,\n false\n );\n if (!defined(availableCount) && computeAvailableCountEnabled) {\n availableCount = count1Bits(bitstream, lengthBits);\n }\n }\n\n this._lengthBits = lengthBits;\n this._availableCount = availableCount;\n this._constant = constant;\n this._bitstream = bitstream;\n}\n\n/**\n * Count the number of bits with value 1 in the bitstream. This is used for\n * computing availableCount if not precomputed\n *\n * @param {Uint8Array} bitstream The bitstream typed array\n * @param {number} lengthBits How many bits are in the bitstream\n * @private\n */\nfunction count1Bits(bitstream, lengthBits) {\n let count = 0;\n for (let i = 0; i < lengthBits; i++) {\n const byteIndex = i >> 3;\n const bitIndex = i % 8;\n count += (bitstream[byteIndex] >> bitIndex) & 1;\n }\n return count;\n}\n\nObject.defineProperties(ImplicitAvailabilityBitstream.prototype, {\n /**\n * The length of the bitstream in bits.\n *\n * @memberof ImplicitAvailabilityBitstream.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n lengthBits: {\n get: function () {\n return this._lengthBits;\n },\n },\n /**\n * The number of bits in the bitstream with value 1.\n *\n * @memberof ImplicitAvailabilityBitstream.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n availableCount: {\n get: function () {\n return this._availableCount;\n },\n },\n});\n\n/**\n * Get a bit from the availability bitstream as a Boolean. If the bitstream\n * is a constant, the constant value is returned instead.\n *\n * @param {number} index The integer index of the bit.\n * @returns {boolean} The value of the bit\n * @private\n */\nImplicitAvailabilityBitstream.prototype.getBit = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (index < 0 || index >= this._lengthBits) {\n throw new DeveloperError(\"Bit index out of bounds.\");\n }\n //>>includeEnd('debug');\n\n if (defined(this._constant)) {\n return this._constant;\n }\n\n // byteIndex is floor(index / 8)\n const byteIndex = index >> 3;\n const bitIndex = index % 8;\n\n return ((this._bitstream[byteIndex] >> bitIndex) & 1) === 1;\n};\n\nexport default ImplicitAvailabilityBitstream;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * This class represents a single entity in the MetadataTable owned by an implicit subtree. The entity is specified by the entityId.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {MetadataTable} options.metadataTable The metadata table.\n * @param {MetadataClass} options.class The class that the metadata conforms to.\n * @param {number} options.entityId The ID of the entity the metadata belongs to.\n * @param {object} options.propertyTableJson The JSON that contains the property table of the entity.\n *\n * @alias ImplicitMetadataView\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitMetadataView(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const metadataTable = options.metadataTable;\n const metadataClass = options.class;\n const entityId = options.entityId;\n const propertyTableJson = options.propertyTableJson;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.metadataTable\", metadataTable);\n Check.typeOf.object(\"options.class\", metadataClass);\n Check.typeOf.number(\"options.entityId\", entityId);\n Check.typeOf.object(\"options.propertyTableJson\", propertyTableJson);\n\n //>>includeEnd('debug');\n\n this._class = metadataClass;\n this._metadataTable = metadataTable;\n this._entityId = entityId;\n\n this._extensions = propertyTableJson.extensions;\n this._extras = propertyTableJson.extras;\n}\n\nObject.defineProperties(ImplicitMetadataView.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof ImplicitMetadataView.prototype\n * @type {MetadataClass}\n * @readonly\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof ImplicitMetadataView.prototype\n * @type {object}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof ImplicitMetadataView.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the metadata contains this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the tile has this property.\n * @private\n */\nImplicitMetadataView.prototype.hasProperty = function (propertyId) {\n return this._metadataTable.hasProperty(propertyId);\n};\n\n/**\n * Returns whether the metadata contains a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the tile has a property with the given semantic.\n * @private\n */\nImplicitMetadataView.prototype.hasPropertyBySemantic = function (semantic) {\n return this._metadataTable.hasPropertyBySemantic(semantic);\n};\n\n/**\n * Returns an array of property IDs in the metadata table.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nImplicitMetadataView.prototype.getPropertyIds = function (results) {\n return this._metadataTable.getPropertyIds(results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the tile does not have this property.\n * @private\n */\nImplicitMetadataView.prototype.getProperty = function (propertyId) {\n return this._metadataTable.getProperty(this._entityId, propertyId);\n};\n\n/**\n * Sets the value of the property with the given ID in the metadata table.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nImplicitMetadataView.prototype.setProperty = function (propertyId, value) {\n return this._metadataTable.setProperty(this._entityId, propertyId, value);\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic in the metadata table.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the tile does not have this semantic.\n * @private\n */\nImplicitMetadataView.prototype.getPropertyBySemantic = function (semantic) {\n return this._metadataTable.getPropertyBySemantic(this._entityId, semantic);\n};\n\n/**\n * Sets the value of the property with the given semantic in the metadata table.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\n\nImplicitMetadataView.prototype.setPropertyBySemantic = function (\n semantic,\n value\n) {\n return this._metadataTable.setPropertyBySemantic(\n this._entityId,\n semantic,\n value\n );\n};\n\nexport default ImplicitMetadataView;\n", "import DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * The subdivision scheme for an implicit tileset.\n *\n * @enum {string}\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst ImplicitSubdivisionScheme = {\n /**\n * A quadtree divides a parent tile into four children, split at the midpoint\n * of the x and y dimensions of the bounding box\n * @type {string}\n * @constant\n * @private\n */\n QUADTREE: \"QUADTREE\",\n /**\n * An octree divides a parent tile into eight children, split at the midpoint\n * of the x, y, and z dimensions of the bounding box.\n * @type {string}\n * @constant\n * @private\n */\n OCTREE: \"OCTREE\",\n};\n\n/**\n * Get the branching factor for the given subdivision scheme\n * @param {ImplicitSubdivisionScheme} subdivisionScheme The subdivision scheme\n * @returns {number} The branching factor, either 4 for QUADTREE or 8 for OCTREE\n * @private\n */\nImplicitSubdivisionScheme.getBranchingFactor = function (subdivisionScheme) {\n switch (subdivisionScheme) {\n case ImplicitSubdivisionScheme.OCTREE:\n return 8;\n case ImplicitSubdivisionScheme.QUADTREE:\n return 4;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"subdivisionScheme is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\nexport default Object.freeze(ImplicitSubdivisionScheme);\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * An entity containing metadata.\n *

\n * This type describes an interface and is not intended to be instantiated directly.\n *

\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @alias MetadataEntity\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataEntity() {}\n\nObject.defineProperties(MetadataEntity.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof MetadataEntity.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n // eslint-disable-next-line getter-return\n get: function () {\n DeveloperError.throwInstantiationError();\n },\n },\n});\n\n/**\n * Returns whether the entity has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the entity has this property.\n * @private\n */\nMetadataEntity.prototype.hasProperty = function (propertyId) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Returns whether the entity has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the entity has a property with the given semantic.\n * @private\n */\nMetadataEntity.prototype.hasPropertyBySemantic = function (semantic) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nMetadataEntity.prototype.getPropertyIds = function (results) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n * @private\n */\nMetadataEntity.prototype.getProperty = function (propertyId) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nMetadataEntity.prototype.setProperty = function (propertyId, value) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n * @private\n */\nMetadataEntity.prototype.getPropertyBySemantic = function (semantic) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nMetadataEntity.prototype.setPropertyBySemantic = function (semantic, value) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Returns whether the entity has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {boolean} Whether the entity has this property.\n *\n * @private\n */\nMetadataEntity.hasProperty = function (\n propertyId,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n if (defined(properties[propertyId])) {\n return true;\n }\n\n const classProperties = classDefinition.properties;\n if (!defined(classProperties)) {\n return false;\n }\n\n const classProperty = classProperties[propertyId];\n if (defined(classProperty) && defined(classProperty.default)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Returns whether the entity has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {boolean} Whether the entity has a property with the given semantic.\n *\n * @private\n */\nMetadataEntity.hasPropertyBySemantic = function (\n semantic,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n const propertiesBySemantic = classDefinition.propertiesBySemantic;\n if (!defined(propertiesBySemantic)) {\n return false;\n }\n\n const property = propertiesBySemantic[semantic];\n return defined(property);\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n *\n * @private\n */\nMetadataEntity.getPropertyIds = function (\n properties,\n classDefinition,\n results\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n results = defined(results) ? results : [];\n results.length = 0;\n\n // Add entity properties\n for (const propertyId in properties) {\n if (\n properties.hasOwnProperty(propertyId) &&\n defined(properties[propertyId])\n ) {\n results.push(propertyId);\n }\n }\n\n // Add default properties\n const classProperties = classDefinition.properties;\n if (defined(classProperties)) {\n for (const classPropertyId in classProperties) {\n if (\n classProperties.hasOwnProperty(classPropertyId) &&\n !defined(properties[classPropertyId]) &&\n defined(classProperties[classPropertyId].default)\n ) {\n results.push(classPropertyId);\n }\n }\n }\n\n return results;\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n *\n * @private\n */\nMetadataEntity.getProperty = function (\n propertyId,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n\n if (!defined(classDefinition.properties[propertyId])) {\n throw new DeveloperError(`Class definition missing property ${propertyId}`);\n }\n //>>includeEnd('debug');\n\n const classProperty = classDefinition.properties[propertyId];\n let value = properties[propertyId];\n\n // Clone array values\n if (Array.isArray(value)) {\n value = value.slice();\n }\n\n // Arrays of vectors are represented as nested arrays in JSON\n const enableNestedArrays = true;\n\n // Handle noData and default\n value = classProperty.handleNoData(value);\n if (!defined(value) && defined(classProperty.default)) {\n value = clone(classProperty.default, true);\n return classProperty.unpackVectorAndMatrixTypes(value, enableNestedArrays);\n }\n\n if (!defined(value)) {\n return undefined;\n }\n\n value = classProperty.normalize(value);\n value = classProperty.applyValueTransform(value);\n return classProperty.unpackVectorAndMatrixTypes(value, enableNestedArrays);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {boolean} true if the property was set, false otherwise.\n *\n * @private\n */\nMetadataEntity.setProperty = function (\n propertyId,\n value,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n Check.defined(\"value\", value);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n if (!defined(properties[propertyId])) {\n return false;\n }\n\n if (Array.isArray(value)) {\n value = value.slice(); // clone\n }\n\n let classProperty;\n const classProperties = classDefinition.properties;\n if (defined(classProperties)) {\n classProperty = classProperties[propertyId];\n }\n\n // arrays of vectors are represented as nested arrays in JSON\n const enableNestedArrays = true;\n if (defined(classProperty)) {\n value = classProperty.packVectorAndMatrixTypes(value, enableNestedArrays);\n value = classProperty.unapplyValueTransform(value);\n value = classProperty.unnormalize(value);\n }\n\n properties[propertyId] = value;\n return true;\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n *\n * @private\n */\nMetadataEntity.getPropertyBySemantic = function (\n semantic,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n const propertiesBySemantic = classDefinition.propertiesBySemantic;\n if (!defined(propertiesBySemantic)) {\n return undefined;\n }\n\n const property = propertiesBySemantic[semantic];\n if (defined(property)) {\n return MetadataEntity.getProperty(property.id, properties, classDefinition);\n }\n return undefined;\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @param {object} properties The dictionary containing properties.\n * @param {MetadataClass} classDefinition The class.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nMetadataEntity.setPropertyBySemantic = function (\n semantic,\n value,\n properties,\n classDefinition\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n Check.defined(\"value\", value);\n Check.typeOf.object(\"properties\", properties);\n Check.typeOf.object(\"classDefinition\", classDefinition);\n //>>includeEnd('debug');\n\n const propertiesBySemantic = classDefinition.propertiesBySemantic;\n if (!defined(propertiesBySemantic)) {\n return false;\n }\n\n const property = classDefinition.propertiesBySemantic[semantic];\n if (defined(property)) {\n return MetadataEntity.setProperty(\n property.id,\n value,\n properties,\n classDefinition\n );\n }\n\n return false;\n};\n\nexport default MetadataEntity;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * Metadata about an implicit subtree.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.subtreeMetadata The subtree metadata JSON object.\n * @param {MetadataClass} options.class The class that subtree metadata conforms to.\n *\n * @alias ImplicitSubtreeMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitSubtreeMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const subtreeMetadata = options.subtreeMetadata;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.subtreeMetadata\", subtreeMetadata);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n const properties = defined(subtreeMetadata.properties)\n ? subtreeMetadata.properties\n : {};\n\n this._class = metadataClass;\n this._properties = properties;\n this._extras = subtreeMetadata.extras;\n this._extensions = subtreeMetadata.extensions;\n}\n\nObject.defineProperties(ImplicitSubtreeMetadata.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof ImplicitSubtreeMetadata.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof ImplicitSubtreeMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof ImplicitSubtreeMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the subtree has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the subtree has this property.\n * @private\n */\nImplicitSubtreeMetadata.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the subtree has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the subtree has a property with the given semantic.\n * @private\n */\nImplicitSubtreeMetadata.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nImplicitSubtreeMetadata.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the subtree does not have this property.\n * @private\n */\nImplicitSubtreeMetadata.prototype.getProperty = function (propertyId) {\n return MetadataEntity.getProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nImplicitSubtreeMetadata.prototype.setProperty = function (propertyId, value) {\n return MetadataEntity.setProperty(\n propertyId,\n value,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the subtree does not have this semantic.\n * @private\n */\nImplicitSubtreeMetadata.prototype.getPropertyBySemantic = function (semantic) {\n return MetadataEntity.getPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nImplicitSubtreeMetadata.prototype.setPropertyBySemantic = function (\n semantic,\n value\n) {\n return MetadataEntity.setPropertyBySemantic(\n semantic,\n value,\n this._properties,\n this._class\n );\n};\n\nexport default ImplicitSubtreeMetadata;\n", "import CesiumMath from \"../Core/Math.js\";\nimport Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\n\n/**\n * An enum of metadata component types.\n *\n * @enum {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst MetadataComponentType = {\n /**\n * An 8-bit signed integer\n *\n * @type {string}\n * @constant\n */\n INT8: \"INT8\",\n /**\n * An 8-bit unsigned integer\n *\n * @type {string}\n * @constant\n */\n UINT8: \"UINT8\",\n /**\n * A 16-bit signed integer\n *\n * @type {string}\n * @constant\n */\n INT16: \"INT16\",\n /**\n * A 16-bit unsigned integer\n *\n * @type {string}\n * @constant\n */\n UINT16: \"UINT16\",\n /**\n * A 32-bit signed integer\n *\n * @type {string}\n * @constant\n */\n INT32: \"INT32\",\n /**\n * A 32-bit unsigned integer\n *\n * @type {string}\n * @constant\n */\n UINT32: \"UINT32\",\n /**\n * A 64-bit signed integer. This type requires BigInt support.\n *\n * @see FeatureDetection.supportsBigInt\n *\n * @type {string}\n * @constant\n */\n INT64: \"INT64\",\n /**\n * A 64-bit signed integer. This type requires BigInt support\n *\n * @see FeatureDetection.supportsBigInt\n *\n * @type {string}\n * @constant\n */\n UINT64: \"UINT64\",\n /**\n * A 32-bit (single precision) floating point number\n *\n * @type {string}\n * @constant\n */\n FLOAT32: \"FLOAT32\",\n /**\n * A 64-bit (double precision) floating point number\n *\n * @type {string}\n * @constant\n */\n FLOAT64: \"FLOAT64\",\n};\n\n/**\n * Gets the minimum value for the numeric type.\n *

\n * Returns a BigInt for the INT64 and UINT64 types if BigInt is supported on this platform.\n * Otherwise an approximate number is returned.\n *

\n *\n * @param {MetadataComponentType} type The type.\n * @returns {number|bigint} The minimum value.\n *\n * @private\n */\nMetadataComponentType.getMinimum = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n return -128;\n case MetadataComponentType.UINT8:\n return 0;\n case MetadataComponentType.INT16:\n return -32768;\n case MetadataComponentType.UINT16:\n return 0;\n case MetadataComponentType.INT32:\n return -2147483648;\n case MetadataComponentType.UINT32:\n return 0;\n case MetadataComponentType.INT64:\n if (FeatureDetection.supportsBigInt()) {\n return BigInt(\"-9223372036854775808\"); // eslint-disable-line\n }\n return -Math.pow(2, 63);\n case MetadataComponentType.UINT64:\n if (FeatureDetection.supportsBigInt()) {\n return BigInt(0); // eslint-disable-line\n }\n return 0;\n case MetadataComponentType.FLOAT32:\n // Maximum 32-bit floating point number. This value will be converted to the nearest 64-bit Number\n return -340282346638528859811704183484516925440.0;\n case MetadataComponentType.FLOAT64:\n return -Number.MAX_VALUE;\n }\n};\n\n/**\n * Gets the maximum value for the numeric type.\n *

\n * Returns a BigInt for the INT64 and UINT64 types if BigInt is supported on this platform.\n * Otherwise an approximate number is returned.\n *

\n *\n * @param {MetadataComponentType} type The type.\n * @returns {number|bigint} The maximum value.\n *\n * @private\n */\nMetadataComponentType.getMaximum = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n return 127;\n case MetadataComponentType.UINT8:\n return 255;\n case MetadataComponentType.INT16:\n return 32767;\n case MetadataComponentType.UINT16:\n return 65535;\n case MetadataComponentType.INT32:\n return 2147483647;\n case MetadataComponentType.UINT32:\n return 4294967295;\n case MetadataComponentType.INT64:\n if (FeatureDetection.supportsBigInt()) {\n // Need to initialize with a string otherwise the value will be 9223372036854775808\n return BigInt(\"9223372036854775807\"); // eslint-disable-line\n }\n return Math.pow(2, 63) - 1;\n case MetadataComponentType.UINT64:\n if (FeatureDetection.supportsBigInt()) {\n // Need to initialize with a string otherwise the value will be 18446744073709551616\n return BigInt(\"18446744073709551615\"); // eslint-disable-line\n }\n return Math.pow(2, 64) - 1;\n case MetadataComponentType.FLOAT32:\n // Maximum 32-bit floating point number\n return 340282346638528859811704183484516925440.0;\n case MetadataComponentType.FLOAT64:\n return Number.MAX_VALUE;\n }\n};\n\n/**\n * Returns whether the type is an integer type.\n *\n * @param {MetadataComponentType} type The type.\n * @returns {boolean} Whether the type is an integer type.\n *\n * @private\n */\nMetadataComponentType.isIntegerType = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n case MetadataComponentType.UINT8:\n case MetadataComponentType.INT16:\n case MetadataComponentType.UINT16:\n case MetadataComponentType.INT32:\n case MetadataComponentType.UINT32:\n case MetadataComponentType.INT64:\n case MetadataComponentType.UINT64:\n return true;\n default:\n return false;\n }\n};\n\n/**\n * Returns whether the type is an unsigned integer type.\n *\n * @param {MetadataComponentType} type The type.\n * @returns {boolean} Whether the type is an unsigned integer type.\n *\n * @private\n */\nMetadataComponentType.isUnsignedIntegerType = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.UINT8:\n case MetadataComponentType.UINT16:\n case MetadataComponentType.UINT32:\n case MetadataComponentType.UINT64:\n return true;\n default:\n return false;\n }\n};\n\n/**\n * Returns whether a type can be used in a vector, i.e. the {@link Cartesian2},\n * {@link Cartesian3}, or {@link Cartesian4} classes. This includes all numeric\n * types except for types requiring 64-bit integers\n * @param {MetadataComponentType} type The type to check\n * @return {boolean} true if the type can be encoded as a vector type, or false otherwise\n * @private\n */\nMetadataComponentType.isVectorCompatible = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n case MetadataComponentType.UINT8:\n case MetadataComponentType.INT16:\n case MetadataComponentType.UINT16:\n case MetadataComponentType.INT32:\n case MetadataComponentType.UINT32:\n case MetadataComponentType.FLOAT32:\n case MetadataComponentType.FLOAT64:\n return true;\n default:\n return false;\n }\n};\n\n/**\n * Normalizes signed integers to the range [-1.0, 1.0] and unsigned integers to\n * the range [0.0, 1.0].\n *

\n * The value may be a BigInt for the INT64 and UINT64 types. The value is converted\n * to a 64-bit floating point number during normalization which may result in\n * small precision differences.\n *

\n *\n * @param {number|bigint} value The integer value.\n * @param {MetadataComponentType} type The type.\n * @returns {number} The normalized value.\n *\n * @exception {DeveloperError} value must be a number or a BigInt\n * @exception {DeveloperError} type must be an integer type\n *\n * @private\n */\nMetadataComponentType.normalize = function (value, type) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof value !== \"number\" && typeof value !== \"bigint\") {\n throw new DeveloperError(\"value must be a number or a BigInt\");\n }\n if (!MetadataComponentType.isIntegerType(type)) {\n throw new DeveloperError(\"type must be an integer type\");\n }\n //>>includeEnd('debug');\n\n return Math.max(\n Number(value) / Number(MetadataComponentType.getMaximum(type)),\n -1.0\n );\n};\n\n/**\n * Unnormalizes signed numbers in the range [-1.0, 1.0] to signed integers and\n * unsigned numbers in the range [0.0, 1.0] to unsigned integers. Values outside\n * the range are clamped to the range.\n *

\n * Returns a BigInt for the INT64 and UINT64 types if BigInt is supported on this platform.\n *

\n *\n * @param {number} value The normalized value.\n * @param {MetadataComponentType} type The type.\n * @returns {number|bigint} The integer value.\n *\n * @exception {DeveloperError} type must be an integer type\n *\n * @private\n */\nMetadataComponentType.unnormalize = function (value, type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n if (!MetadataComponentType.isIntegerType(type)) {\n throw new DeveloperError(\"type must be an integer type\");\n }\n //>>includeEnd('debug');\n\n const max = MetadataComponentType.getMaximum(type);\n const min = MetadataComponentType.isUnsignedIntegerType(type) ? 0 : -max;\n\n value = CesiumMath.sign(value) * Math.round(Math.abs(value) * Number(max));\n\n if (\n (type === MetadataComponentType.INT64 ||\n type === MetadataComponentType.UINT64) &&\n FeatureDetection.supportsBigInt()\n ) {\n value = BigInt(value); // eslint-disable-line\n }\n\n if (value > max) {\n return max;\n }\n\n if (value < min) {\n return min;\n }\n\n return value;\n};\n\n/**\n * @private\n */\nMetadataComponentType.applyValueTransform = function (value, offset, scale) {\n return scale * value + offset;\n};\n\n/**\n * @private\n */\nMetadataComponentType.unapplyValueTransform = function (value, offset, scale) {\n // if the scale is 0, avoid a divide by zero error. The result can be any\n // finite number, so 0.0 will do nicely.\n if (scale === 0) {\n return 0.0;\n }\n\n return (value - offset) / scale;\n};\n\n/**\n * Gets the size in bytes for the numeric type.\n *\n * @param {MetadataComponentType} type The type.\n * @returns {number} The size in bytes.\n *\n * @private\n */\nMetadataComponentType.getSizeInBytes = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n case MetadataComponentType.UINT8:\n return 1;\n case MetadataComponentType.INT16:\n case MetadataComponentType.UINT16:\n return 2;\n case MetadataComponentType.INT32:\n case MetadataComponentType.UINT32:\n return 4;\n case MetadataComponentType.INT64:\n case MetadataComponentType.UINT64:\n return 8;\n case MetadataComponentType.FLOAT32:\n return 4;\n case MetadataComponentType.FLOAT64:\n return 8;\n }\n};\n\n/**\n * Gets the {@link MetadataComponentType} from a {@link ComponentDatatype}.\n *\n * @param {ComponentDatatype} componentDatatype The component datatype.\n * @returns {MetadataComponentType} The type.\n *\n * @private\n */\nMetadataComponentType.fromComponentDatatype = function (componentDatatype) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"componentDatatype\", componentDatatype);\n //>>includeEnd('debug');\n\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n return MetadataComponentType.INT8;\n case ComponentDatatype.UNSIGNED_BYTE:\n return MetadataComponentType.UINT8;\n case ComponentDatatype.SHORT:\n return MetadataComponentType.INT16;\n case ComponentDatatype.UNSIGNED_SHORT:\n return MetadataComponentType.UINT16;\n case ComponentDatatype.INT:\n return MetadataComponentType.INT32;\n case ComponentDatatype.UNSIGNED_INT:\n return MetadataComponentType.UINT32;\n case ComponentDatatype.FLOAT:\n return MetadataComponentType.FLOAT32;\n case ComponentDatatype.DOUBLE:\n return MetadataComponentType.FLOAT64;\n }\n};\n\n/**\n * Gets the {@link ComponentDatatype} from a {@link MetadataComponentType}.\n *\n * @param {MetadataComponentType} type The type.\n * @returns {ComponentDatatype} The component datatype.\n *\n * @private\n */\nMetadataComponentType.toComponentDatatype = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataComponentType.INT8:\n return ComponentDatatype.BYTE;\n case MetadataComponentType.UINT8:\n return ComponentDatatype.UNSIGNED_BYTE;\n case MetadataComponentType.INT16:\n return ComponentDatatype.SHORT;\n case MetadataComponentType.UINT16:\n return ComponentDatatype.UNSIGNED_SHORT;\n case MetadataComponentType.INT32:\n return ComponentDatatype.INT;\n case MetadataComponentType.UINT32:\n return ComponentDatatype.UNSIGNED_INT;\n case MetadataComponentType.FLOAT32:\n return ComponentDatatype.FLOAT;\n case MetadataComponentType.FLOAT64:\n return ComponentDatatype.DOUBLE;\n }\n};\n\nexport default Object.freeze(MetadataComponentType);\n", "import Check from \"../Core/Check.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\n\n/**\n * An enum of metadata types. These metadata types are containers containing\n * one or more components of type {@link MetadataComponentType}\n *\n * @enum {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst MetadataType = {\n /**\n * A single component\n *\n * @type {string}\n * @constant\n */\n SCALAR: \"SCALAR\",\n /**\n * A vector with two components\n *\n * @type {string}\n * @constant\n */\n VEC2: \"VEC2\",\n /**\n * A vector with three components\n *\n * @type {string}\n * @constant\n */\n VEC3: \"VEC3\",\n /**\n * A vector with four components\n *\n * @type {string}\n * @constant\n */\n VEC4: \"VEC4\",\n /**\n * A 2x2 matrix, stored in column-major format.\n *\n * @type {string}\n * @constant\n */\n MAT2: \"MAT2\",\n /**\n * A 3x3 matrix, stored in column-major format.\n *\n * @type {string}\n * @constant\n */\n MAT3: \"MAT3\",\n /**\n * A 4x4 matrix, stored in column-major format.\n *\n * @type {string}\n * @constant\n */\n MAT4: \"MAT4\",\n /**\n * A boolean (true/false) value\n *\n * @type {string}\n * @constant\n */\n BOOLEAN: \"BOOLEAN\",\n /**\n * A UTF-8 encoded string value\n *\n * @type {string}\n * @constant\n */\n STRING: \"STRING\",\n /**\n * An enumerated value. This type is used in conjunction with a {@link MetadataEnum} to describe the valid values.\n *\n * @see MetadataEnum\n *\n * @type {string}\n * @constant\n */\n ENUM: \"ENUM\",\n};\n\n/**\n * Check if a type is VEC2, VEC3 or VEC4\n *\n * @param {MetadataType} type The type\n * @return {boolean} true if the type is a vector, false otherwise\n * @private\n */\nMetadataType.isVectorType = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataType.VEC2:\n case MetadataType.VEC3:\n case MetadataType.VEC4:\n return true;\n default:\n return false;\n }\n};\n\n/**\n * Check if a type is MAT2, MAT3 or MAT4\n *\n * @param {MetadataType} type The type\n * @return {boolean} true if the type is a matrix, false otherwise\n * @private\n */\nMetadataType.isMatrixType = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataType.MAT2:\n case MetadataType.MAT3:\n case MetadataType.MAT4:\n return true;\n default:\n return false;\n }\n};\n\n/**\n * Get the number of components for a vector or matrix type. e.g.\n * a VECN returns N, and a MATN returns N*N. All other types return 1.\n *\n * @param {MetadataType} type The type to get the component count for\n * @return {number} The number of components\n * @private\n */\nMetadataType.getComponentCount = function (type) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"type\", type);\n //>>includeEnd('debug');\n\n switch (type) {\n case MetadataType.SCALAR:\n case MetadataType.STRING:\n case MetadataType.ENUM:\n case MetadataType.BOOLEAN:\n return 1;\n case MetadataType.VEC2:\n return 2;\n case MetadataType.VEC3:\n return 3;\n case MetadataType.VEC4:\n return 4;\n case MetadataType.MAT2:\n return 4;\n case MetadataType.MAT3:\n return 9;\n case MetadataType.MAT4:\n return 16;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(`Invalid metadata type ${type}`);\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Get the corresponding vector or matrix class. This is used to simplify\n * packing and unpacking code.\n * @param {MetadataType} type The metadata type\n * @return {object} The appropriate CartesianN class for vector types, MatrixN class for matrix types, or undefined otherwise.\n * @private\n */\nMetadataType.getMathType = function (type) {\n switch (type) {\n case MetadataType.VEC2:\n return Cartesian2;\n case MetadataType.VEC3:\n return Cartesian3;\n case MetadataType.VEC4:\n return Cartesian4;\n case MetadataType.MAT2:\n return Matrix2;\n case MetadataType.MAT3:\n return Matrix3;\n case MetadataType.MAT4:\n return Matrix4;\n default:\n return undefined;\n }\n};\n\nexport default Object.freeze(MetadataType);\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix2 from \"../Core/Matrix2.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport MetadataType from \"./MetadataType.js\";\nimport MetadataComponentType from \"./MetadataComponentType.js\";\n\n/**\n * A metadata property, as part of a {@link MetadataClass}.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the property.\n * @param {MetadataType} options.type The type of the property such as SCALAR, VEC2, VEC3.\n * @param {MetadataComponentType} [options.componentType] The component type of the property. This includes integer (e.g. INT8 or UINT16), and floating point (FLOAT32 and FLOAT64) values.\n * @param {MetadataEnum} [options.enumType] The enum type of the property. Only defined when type is ENUM.\n * @param {boolean} [options.isArray=false] True if a property is an array (either fixed length or variable length), false otherwise.\n * @param {boolean} [options.isVariableLengthArray=false] True if a property is a variable length array, false otherwise.\n * @param {number} [options.arrayLength] The number of array elements. Only defined for fixed length arrays.\n * @param {boolean} [options.normalized=false] Whether the property is normalized.\n * @param {number|number[]|number[][]} [options.min] A number or an array of numbers storing the minimum allowable value of this property. Only defined when type is a numeric type.\n * @param {number|number[]|number[][]} [options.max] A number or an array of numbers storing the maximum allowable value of this property. Only defined when type is a numeric type.\n * @param {number|number[]|number[][]} [options.offset] The offset to be added to property values as part of the value transform.\n * @param {number|number[]|number[][]} [options.scale] The scale to be multiplied to property values as part of the value transform.\n * @param {boolean|number|string|Array} [options.noData] The no-data sentinel value that represents null values.\n * @param {boolean|number|string|Array} [options.default] A default value to use when an entity's property value is not defined.\n * @param {boolean} [options.required=false] Whether the property is required.\n * @param {string} [options.name] The name of the property.\n * @param {string} [options.description] The description of the property.\n * @param {string} [options.semantic] An identifier that describes how this property should be interpreted.\n * @param {*} [options.extras] Extra user-defined properties.\n * @param {object} [options.extensions] An object containing extensions.\n *\n * @alias MetadataClassProperty\n * @constructor\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataClassProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const type = options.type;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n Check.typeOf.string(\"options.type\", type);\n //>>includeEnd('debug');\n\n const componentType = options.componentType;\n const enumType = options.enumType;\n\n const normalized =\n defined(componentType) &&\n MetadataComponentType.isIntegerType(componentType) &&\n defaultValue(options.normalized, false);\n\n // Basic information about this property\n this._id = id;\n this._name = options.name;\n this._description = options.description;\n this._semantic = options.semantic;\n\n // Only for unit testing purposes, not documented in the API\n this._isLegacyExtension = options.isLegacyExtension;\n\n // Details about basic types\n this._type = type;\n this._componentType = componentType;\n this._enumType = enumType;\n this._valueType = defined(enumType) ? enumType.valueType : componentType;\n\n // Details about arrays\n this._isArray = defaultValue(options.isArray, false);\n this._isVariableLengthArray = defaultValue(\n options.isVariableLengthArray,\n false\n );\n this._arrayLength = options.arrayLength;\n\n // min and max allowed values\n this._min = clone(options.min, true);\n this._max = clone(options.max, true);\n\n // properties that adjust the range of metadata values\n this._normalized = normalized;\n\n let offset = clone(options.offset, true);\n let scale = clone(options.scale, true);\n const hasValueTransform = defined(offset) || defined(scale);\n\n const enableNestedArrays = true;\n if (!defined(offset)) {\n offset = this.expandConstant(0, enableNestedArrays);\n }\n\n if (!defined(scale)) {\n scale = this.expandConstant(1, enableNestedArrays);\n }\n\n this._offset = offset;\n this._scale = scale;\n this._hasValueTransform = hasValueTransform;\n\n // sentinel value for missing data, and a default value to use\n // in its place if needed.\n this._noData = clone(options.noData, true);\n // For vector and array types, this is stored as an array of values.\n this._default = clone(options.default, true);\n\n this._required = defaultValue(options.required, true);\n\n // extras and extensions\n this._extras = clone(options.extras, true);\n this._extensions = clone(options.extensions, true);\n}\n\n/**\n * Creates a {@link MetadataClassProperty} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the property.\n * @param {object} options.property The property JSON object.\n * @param {Object} [options.enums] A dictionary of enums.\n *\n * @returns {MetadataClassProperty} The newly created metadata class property.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nMetadataClassProperty.fromJson = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const property = options.property;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n Check.typeOf.object(\"options.property\", property);\n Check.typeOf.string(\"options.property.type\", property.type);\n //>>includeEnd('debug');\n\n // Try to determine if this is the legacy extension. This is not\n // always possible, as there are some types that are valid in both\n // extensions.\n const isLegacyExtension = isLegacy(property);\n const parsedType = parseType(property, options.enums);\n\n // EXT_feature_metadata had an optional flag, while EXT_structural_metadata\n // has a required flag. The defaults are not the same, and there's some cases\n // like {type: BOOLEAN} that are ambiguous. Coalesce this into a single\n // required flag\n let required;\n if (!defined(isLegacyExtension)) {\n // Impossible to tell which extension was used, so don't require\n // the property\n required = false;\n } else if (isLegacyExtension) {\n required = defined(property.optional) ? !property.optional : true;\n } else {\n required = defaultValue(property.required, false);\n }\n\n return new MetadataClassProperty({\n id: id,\n type: parsedType.type,\n componentType: parsedType.componentType,\n enumType: parsedType.enumType,\n isArray: parsedType.isArray,\n isVariableLengthArray: parsedType.isVariableLengthArray,\n arrayLength: parsedType.arrayLength,\n normalized: property.normalized,\n min: property.min,\n max: property.max,\n offset: property.offset,\n scale: property.scale,\n noData: property.noData,\n default: property.default,\n required: required,\n name: property.name,\n description: property.description,\n semantic: property.semantic,\n extras: property.extras,\n extensions: property.extensions,\n isLegacyExtension: isLegacyExtension,\n });\n};\n\nObject.defineProperties(MetadataClassProperty.prototype, {\n /**\n * The ID of the property.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * The name of the property.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The description of the property.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {string}\n * @readonly\n */\n description: {\n get: function () {\n return this._description;\n },\n },\n\n /**\n * The type of the property such as SCALAR, VEC2, VEC3\n *\n * @memberof MetadataClassProperty.prototype\n * @type {MetadataType}\n * @readonly\n */\n type: {\n get: function () {\n return this._type;\n },\n },\n\n /**\n * The enum type of the property. Only defined when type is ENUM.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {MetadataEnum}\n * @readonly\n */\n enumType: {\n get: function () {\n return this._enumType;\n },\n },\n\n /**\n * The component type of the property. This includes integer\n * (e.g. INT8 or UINT16), and floating point (FLOAT32 and FLOAT64) values\n *\n * @memberof MetadataClassProperty.prototype\n * @type {MetadataComponentType}\n * @readonly\n */\n componentType: {\n get: function () {\n return this._componentType;\n },\n },\n\n /**\n * The datatype used for storing each component of the property. This\n * is usually the same as componentType except for ENUM, where this\n * returns an integer type\n *\n * @memberof MetadataClassProperty.prototype\n * @type {MetadataComponentType}\n * @readonly\n * @private\n */\n valueType: {\n get: function () {\n return this._valueType;\n },\n },\n\n /**\n * True if a property is an array (either fixed length or variable length),\n * false otherwise.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n */\n isArray: {\n get: function () {\n return this._isArray;\n },\n },\n\n /**\n * True if a property is a variable length array, false otherwise.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n */\n isVariableLengthArray: {\n get: function () {\n return this._isVariableLengthArray;\n },\n },\n\n /**\n * The number of array elements. Only defined for fixed-size\n * arrays.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number}\n * @readonly\n */\n arrayLength: {\n get: function () {\n return this._arrayLength;\n },\n },\n\n /**\n * Whether the property is normalized.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n */\n normalized: {\n get: function () {\n return this._normalized;\n },\n },\n\n /**\n * A number or an array of numbers storing the maximum allowable value of this property. Only defined when type is a numeric type.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n */\n max: {\n get: function () {\n return this._max;\n },\n },\n\n /**\n * A number or an array of numbers storing the minimum allowable value of this property. Only defined when type is a numeric type.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n */\n min: {\n get: function () {\n return this._min;\n },\n },\n\n /**\n * The no-data sentinel value that represents null values\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean|number|string|Array}\n * @readonly\n */\n noData: {\n get: function () {\n return this._noData;\n },\n },\n\n /**\n * A default value to use when an entity's property value is not defined.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean|number|string|Array}\n * @readonly\n */\n default: {\n get: function () {\n return this._default;\n },\n },\n\n /**\n * Whether the property is required.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n */\n required: {\n get: function () {\n return this._required;\n },\n },\n\n /**\n * An identifier that describes how this property should be interpreted.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {string}\n * @readonly\n */\n semantic: {\n get: function () {\n return this._semantic;\n },\n },\n\n /**\n * True if offset/scale should be applied. If both offset/scale were\n * undefined, they default to identity so this property is set false\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n hasValueTransform: {\n get: function () {\n return this._hasValueTransform;\n },\n },\n\n /**\n * The offset to be added to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n */\n offset: {\n get: function () {\n return this._offset;\n },\n },\n\n /**\n * The scale to be multiplied to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n */\n scale: {\n get: function () {\n return this._scale;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {*}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nfunction isLegacy(property) {\n if (property.type === \"ARRAY\") {\n return true;\n }\n\n // New property types in EXT_structural_metadata\n const type = property.type;\n if (\n type === MetadataType.SCALAR ||\n MetadataType.isMatrixType(type) ||\n MetadataType.isVectorType(type)\n ) {\n return false;\n }\n\n // EXT_feature_metadata allowed numeric types as a type. Now they are\n // represented as {type: SINGLE, componentType: type}\n if (defined(MetadataComponentType[type])) {\n return true;\n }\n\n // New properties in EXT_structural_metadata\n if (\n defined(property.noData) ||\n defined(property.scale) ||\n defined(property.offset) ||\n defined(property.required) ||\n defined(property.count) ||\n defined(property.array)\n ) {\n return false;\n }\n\n // Properties that only exist in EXT_feature_metadata\n if (defined(property.optional)) {\n return false;\n }\n\n // impossible to tell, give up.\n return undefined;\n}\n\nfunction parseType(property, enums) {\n const type = property.type;\n const componentType = property.componentType;\n\n // EXT_feature_metadata had an ARRAY type. This is now handled\n // with array + count, so some details need to be transcoded\n const isLegacyArray = type === \"ARRAY\";\n let isArray;\n let arrayLength;\n let isVariableLengthArray;\n if (isLegacyArray) {\n // definitely EXT_feature_metadata\n isArray = true;\n arrayLength = property.componentCount;\n isVariableLengthArray = !defined(arrayLength);\n } else if (property.array) {\n isArray = true;\n arrayLength = property.count;\n isVariableLengthArray = !defined(property.count);\n } else {\n // Could be either extension. Some cases are impossible to distinguish\n // Default to a single value\n isArray = false;\n arrayLength = undefined;\n isVariableLengthArray = false;\n }\n\n let enumType;\n if (defined(property.enumType)) {\n enumType = enums[property.enumType];\n }\n\n // In both EXT_feature_metadata and EXT_structural_metadata, ENUM appears\n // as a type.\n if (type === MetadataType.ENUM) {\n return {\n type: type,\n componentType: undefined,\n enumType: enumType,\n valueType: enumType.valueType,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // In EXT_feature_metadata, ENUM also appears as an ARRAY componentType\n if (isLegacyArray && componentType === MetadataType.ENUM) {\n return {\n type: componentType,\n componentType: undefined,\n enumType: enumType,\n valueType: enumType.valueType,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // EXT_structural_metadata only: SCALAR, VECN and MATN\n if (\n type === MetadataType.SCALAR ||\n MetadataType.isMatrixType(type) ||\n MetadataType.isVectorType(type)\n ) {\n return {\n type: type,\n componentType: componentType,\n enumType: undefined,\n valueType: componentType,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // In both EXT_structural_metadata and EXT_feature_metadata,\n // BOOLEAN and STRING appear as types\n if (type === MetadataType.BOOLEAN || type === MetadataType.STRING) {\n return {\n type: type,\n componentType: undefined,\n enumType: undefined,\n valueType: undefined,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // EXT_feature_metadata also allows BOOLEAN and STRING as an ARRAY\n // componentType\n if (\n isLegacyArray &&\n (componentType === MetadataType.BOOLEAN ||\n componentType === MetadataType.STRING)\n ) {\n return {\n type: componentType,\n componentType: undefined,\n enumType: undefined,\n valueType: undefined,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // Both EXT_feature_metadata and EXT_structural_metadata allow numeric types like\n // INT32 or FLOAT64 as a componentType.\n if (defined(componentType) && defined(MetadataComponentType[componentType])) {\n return {\n type: MetadataType.SCALAR,\n componentType: componentType,\n enumType: undefined,\n valueType: componentType,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n // EXT_feature_metadata: integer and float types were allowed as types,\n // but now these are expressed as {type: SCALAR, componentType: type}\n if (defined(MetadataComponentType[type])) {\n return {\n type: MetadataType.SCALAR,\n componentType: type,\n enumType: undefined,\n valueType: type,\n isArray: isArray,\n isVariableLengthArray: isVariableLengthArray,\n arrayLength: arrayLength,\n };\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n `unknown metadata type {type: ${type}, componentType: ${componentType})`\n );\n //>>includeEnd('debug');\n}\n\n/**\n * Normalizes integer property values. If the property is not normalized\n * the value is returned unmodified.\n *

\n * Given the way normalization is defined in {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#normalized-values|the 3D Metadata Specification},\n * normalize and unnormalize are almost, but not quite inverses. In particular,\n * the smallest signed integer value will be off by one after normalizing and\n * unnormalizing. See\n * {@link https://www.desmos.com/calculator/nledg1evut|this Desmos graph} for\n * an example using INT8.\n *

\n *

\n * Furthermore, for 64-bit integer types, there may be a loss of precision\n * due to conversion to Number\n *

\n *\n * @param {*} value The integer value or array of integer values.\n * @returns {*} The normalized value or array of normalized values.\n *\n * @private\n */\nMetadataClassProperty.prototype.normalize = function (value) {\n if (!this._normalized) {\n return value;\n }\n\n return normalizeInPlace(\n value,\n this._valueType,\n MetadataComponentType.normalize\n );\n};\n\n/**\n * Unnormalizes integer property values. If the property is not normalized\n * the value is returned unmodified.\n *

\n * Given the way normalization is defined in {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#normalized-values|the 3D Metadata Specification},\n * normalize and unnormalize are almost, but not quite inverses. In particular,\n * the smallest signed integer value will be off by one after normalizing and\n * unnormalizing. See\n * {@link https://www.desmos.com/calculator/nledg1evut|this Desmos graph} for\n * an example using INT8.\n *

\n *

\n * Furthermore, for 64-bit integer types, there may be a loss of precision\n * due to conversion to Number\n *

\n *\n * @param {*} value The normalized value or array of normalized values.\n * @returns {*} The integer value or array of integer values.\n *\n * @private\n */\nMetadataClassProperty.prototype.unnormalize = function (value) {\n if (!this._normalized) {\n return value;\n }\n\n return normalizeInPlace(\n value,\n this._valueType,\n MetadataComponentType.unnormalize\n );\n};\n\n/**\n * @private\n */\nMetadataClassProperty.prototype.applyValueTransform = function (value) {\n // variable length arrays do not have a well-defined offset/scale so this\n // is forbidden by the spec\n if (!this._hasValueTransform || this._isVariableLengthArray) {\n return value;\n }\n\n return MetadataClassProperty.valueTransformInPlace(\n value,\n this._offset,\n this._scale,\n MetadataComponentType.applyValueTransform\n );\n};\n\n/**\n * @private\n */\nMetadataClassProperty.prototype.unapplyValueTransform = function (value) {\n // variable length arrays do not have a well-defined offset/scale so this\n // is forbidden by the spec\n if (!this._hasValueTransform || this._isVariableLengthArray) {\n return value;\n }\n\n return MetadataClassProperty.valueTransformInPlace(\n value,\n this._offset,\n this._scale,\n MetadataComponentType.unapplyValueTransform\n );\n};\n\n/**\n * @private\n */\nMetadataClassProperty.prototype.expandConstant = function (\n constant,\n enableNestedArrays\n) {\n enableNestedArrays = defaultValue(enableNestedArrays, false);\n const isArray = this._isArray;\n const arrayLength = this._arrayLength;\n const componentCount = MetadataType.getComponentCount(this._type);\n const isNested = isArray && componentCount > 1;\n\n // scalar values can be returned directly\n if (!isArray && componentCount === 1) {\n return constant;\n }\n\n // vector and matrix values\n if (!isArray) {\n return new Array(componentCount).fill(constant);\n }\n\n // arrays of scalars\n if (!isNested) {\n return new Array(arrayLength).fill(constant);\n }\n\n // arrays of vectors/matrices: flattened\n if (!enableNestedArrays) {\n return new Array(this._arrayLength * componentCount).fill(constant);\n }\n\n // array of vectors/matrices: nested\n const innerConstant = new Array(componentCount).fill(constant);\n // This array fill duplicates the pointer to the inner arrays. Since this is\n // intended for use with constants, no need to clone the array.\n return new Array(this._arrayLength).fill(innerConstant);\n};\n\n/**\n * If the value is the noData sentinel, return undefined. Otherwise, return\n * the value.\n * @param {*} value The raw value\n * @returns {*} Either the value or undefined if the value was a no data value.\n *\n * @private\n */\nMetadataClassProperty.prototype.handleNoData = function (value) {\n const sentinel = this._noData;\n if (!defined(sentinel)) {\n return value;\n }\n\n if (arrayEquals(value, sentinel)) {\n return undefined;\n }\n\n return value;\n};\n\nfunction arrayEquals(left, right) {\n if (!Array.isArray(left)) {\n return left === right;\n }\n\n if (!Array.isArray(right)) {\n return false;\n }\n\n if (left.length !== right.length) {\n return false;\n }\n\n for (let i = 0; i < left.length; i++) {\n if (!arrayEquals(left[i], right[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Unpack VECN values into {@link Cartesian2}, {@link Cartesian3}, or\n * {@link Cartesian4} and MATN values into {@link Matrix2}, {@link Matrix3}, or\n * {@link Matrix4} depending on N. All other values (including arrays of\n * other sizes) are passed through unaltered.\n *\n * @param {*} value the original, normalized values.\n * @param {boolean} [enableNestedArrays=false] If true, arrays of vectors are represented as nested arrays. This is used for JSON encoding but not binary encoding\n * @returns {*} The appropriate vector or matrix type if the value is a vector or matrix type, respectively. If the property is an array of vectors or matrices, an array of the appropriate vector or matrix type is returned. Otherwise, the value is returned unaltered.\n * @private\n */\nMetadataClassProperty.prototype.unpackVectorAndMatrixTypes = function (\n value,\n enableNestedArrays\n) {\n enableNestedArrays = defaultValue(enableNestedArrays, false);\n const MathType = MetadataType.getMathType(this._type);\n const isArray = this._isArray;\n const componentCount = MetadataType.getComponentCount(this._type);\n const isNested = isArray && componentCount > 1;\n\n if (!defined(MathType)) {\n return value;\n }\n\n if (enableNestedArrays && isNested) {\n return value.map(function (x) {\n return MathType.unpack(x);\n });\n }\n\n if (isArray) {\n return MathType.unpackArray(value);\n }\n\n return MathType.unpack(value);\n};\n\n/**\n * Pack a {@link Cartesian2}, {@link Cartesian3}, or {@link Cartesian4} into an\n * array if this property is an VECN.\n * Pack a {@link Matrix2}, {@link Matrix3}, or {@link Matrix4} into an\n * array if this property is an MATN.\n * All other values (including arrays of other sizes) are passed through unaltered.\n *\n * @param {*} value The value of this property\n * @param {boolean} [enableNestedArrays=false] If true, arrays of vectors are represented as nested arrays. This is used for JSON encoding but not binary encoding\n * @returns {*} An array of the appropriate length if the property is a vector or matrix type. Otherwise, the value is returned unaltered.\n * @private\n */\nMetadataClassProperty.prototype.packVectorAndMatrixTypes = function (\n value,\n enableNestedArrays\n) {\n enableNestedArrays = defaultValue(enableNestedArrays, false);\n const MathType = MetadataType.getMathType(this._type);\n const isArray = this._isArray;\n const componentCount = MetadataType.getComponentCount(this._type);\n const isNested = isArray && componentCount > 1;\n\n if (!defined(MathType)) {\n return value;\n }\n\n if (enableNestedArrays && isNested) {\n return value.map(function (x) {\n return MathType.pack(x, []);\n });\n }\n\n if (isArray) {\n return MathType.packArray(value, []);\n }\n\n return MathType.pack(value, []);\n};\n\n/**\n * Validates whether the given value conforms to the property.\n *\n * @param {*} value The value.\n * @returns {string|undefined} An error message if the value does not conform to the property, otherwise undefined.\n * @private\n */\nMetadataClassProperty.prototype.validate = function (value) {\n if (!defined(value) && defined(this._default)) {\n // no value, but we have a default to use.\n return undefined;\n }\n\n if (this._required && !defined(value)) {\n return `required property must have a value`;\n }\n\n if (this._isArray) {\n return validateArray(this, value);\n }\n\n return validateSingleValue(this, value);\n};\n\nfunction validateArray(classProperty, value) {\n if (!Array.isArray(value)) {\n return `value ${value} must be an array`;\n }\n\n const length = value.length;\n if (\n !classProperty._isVariableLengthArray &&\n length !== classProperty._arrayLength\n ) {\n return \"Array length does not match property.arrayLength\";\n }\n\n for (let i = 0; i < length; i++) {\n const message = validateSingleValue(classProperty, value[i]);\n if (defined(message)) {\n return message;\n }\n }\n}\n\nfunction validateSingleValue(classProperty, value) {\n const type = classProperty._type;\n const componentType = classProperty._componentType;\n const enumType = classProperty._enumType;\n const normalized = classProperty._normalized;\n\n if (MetadataType.isVectorType(type)) {\n return validateVector(value, type, componentType);\n } else if (MetadataType.isMatrixType(type)) {\n return validateMatrix(value, type, componentType);\n } else if (type === MetadataType.STRING) {\n return validateString(value);\n } else if (type === MetadataType.BOOLEAN) {\n return validateBoolean(value);\n } else if (type === MetadataType.ENUM) {\n return validateEnum(value, enumType);\n }\n\n return validateScalar(value, componentType, normalized);\n}\n\nfunction validateVector(value, type, componentType) {\n if (!MetadataComponentType.isVectorCompatible(componentType)) {\n return `componentType ${componentType} is incompatible with vector type ${type}`;\n }\n\n if (type === MetadataType.VEC2 && !(value instanceof Cartesian2)) {\n return `vector value ${value} must be a Cartesian2`;\n }\n\n if (type === MetadataType.VEC3 && !(value instanceof Cartesian3)) {\n return `vector value ${value} must be a Cartesian3`;\n }\n\n if (type === MetadataType.VEC4 && !(value instanceof Cartesian4)) {\n return `vector value ${value} must be a Cartesian4`;\n }\n}\n\nfunction validateMatrix(value, type, componentType) {\n if (!MetadataComponentType.isVectorCompatible(componentType)) {\n return `componentType ${componentType} is incompatible with matrix type ${type}`;\n }\n\n if (type === MetadataType.MAT2 && !(value instanceof Matrix2)) {\n return `matrix value ${value} must be a Matrix2`;\n }\n\n if (type === MetadataType.MAT3 && !(value instanceof Matrix3)) {\n return `matrix value ${value} must be a Matrix3`;\n }\n\n if (type === MetadataType.MAT4 && !(value instanceof Matrix4)) {\n return `matrix value ${value} must be a Matrix4`;\n }\n}\n\nfunction validateString(value) {\n if (typeof value !== \"string\") {\n return getTypeErrorMessage(value, MetadataType.STRING);\n }\n}\n\nfunction validateBoolean(value) {\n if (typeof value !== \"boolean\") {\n return getTypeErrorMessage(value, MetadataType.BOOLEAN);\n }\n}\n\nfunction validateEnum(value, enumType) {\n const javascriptType = typeof value;\n if (defined(enumType)) {\n if (javascriptType !== \"string\" || !defined(enumType.valuesByName[value])) {\n return `value ${value} is not a valid enum name for ${enumType.id}`;\n }\n return;\n }\n}\n\nfunction validateScalar(value, componentType, normalized) {\n const javascriptType = typeof value;\n\n switch (componentType) {\n case MetadataComponentType.INT8:\n case MetadataComponentType.UINT8:\n case MetadataComponentType.INT16:\n case MetadataComponentType.UINT16:\n case MetadataComponentType.INT32:\n case MetadataComponentType.UINT32:\n case MetadataComponentType.FLOAT32:\n case MetadataComponentType.FLOAT64:\n if (javascriptType !== \"number\") {\n return getTypeErrorMessage(value, componentType);\n }\n if (!isFinite(value)) {\n return getNonFiniteErrorMessage(value, componentType);\n }\n return checkInRange(value, componentType, normalized);\n case MetadataComponentType.INT64:\n case MetadataComponentType.UINT64:\n if (javascriptType !== \"number\" && javascriptType !== \"bigint\") {\n return getTypeErrorMessage(value, componentType);\n }\n if (javascriptType === \"number\" && !isFinite(value)) {\n return getNonFiniteErrorMessage(value, componentType);\n }\n return checkInRange(value, componentType, normalized);\n }\n}\n\nfunction getTypeErrorMessage(value, type) {\n return `value ${value} does not match type ${type}`;\n}\n\nfunction getOutOfRangeErrorMessage(value, type, normalized) {\n let errorMessage = `value ${value} is out of range for type ${type}`;\n if (normalized) {\n errorMessage += \" (normalized)\";\n }\n return errorMessage;\n}\n\nfunction checkInRange(value, componentType, normalized) {\n if (normalized) {\n const min = MetadataComponentType.isUnsignedIntegerType(componentType)\n ? 0.0\n : -1.0;\n const max = 1.0;\n if (value < min || value > max) {\n return getOutOfRangeErrorMessage(value, componentType, normalized);\n }\n return;\n }\n\n if (\n value < MetadataComponentType.getMinimum(componentType) ||\n value > MetadataComponentType.getMaximum(componentType)\n ) {\n return getOutOfRangeErrorMessage(value, componentType, normalized);\n }\n}\n\nfunction getNonFiniteErrorMessage(value, type) {\n return `value ${value} of type ${type} must be finite`;\n}\n\nfunction normalizeInPlace(values, valueType, normalizeFunction) {\n if (!Array.isArray(values)) {\n return normalizeFunction(values, valueType);\n }\n\n for (let i = 0; i < values.length; i++) {\n values[i] = normalizeInPlace(values[i], valueType, normalizeFunction);\n }\n\n return values;\n}\n\n/**\n * @private\n */\nMetadataClassProperty.valueTransformInPlace = function (\n values,\n offsets,\n scales,\n transformationFunction\n) {\n if (!Array.isArray(values)) {\n // transform a single value\n return transformationFunction(values, offsets, scales);\n }\n\n for (let i = 0; i < values.length; i++) {\n // offsets and scales must be the same array shape as values.\n values[i] = MetadataClassProperty.valueTransformInPlace(\n values[i],\n offsets[i],\n scales[i],\n transformationFunction\n );\n }\n\n return values;\n};\n\nexport default MetadataClassProperty;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport getStringFromTypedArray from \"../Core/getStringFromTypedArray.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport MetadataComponentType from \"./MetadataComponentType.js\";\nimport MetadataClassProperty from \"./MetadataClassProperty.js\";\nimport MetadataType from \"./MetadataType.js\";\n\n/**\n * A binary property in a {@MetadataTable}\n *

\n * For 3D Tiles Next details, see the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension}\n * for 3D Tiles, as well as the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension}\n * for glTF. For the legacy glTF extension, see {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension}\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.count The number of elements in each property array.\n * @param {object} options.property The property JSON object.\n * @param {MetadataClassProperty} options.classProperty The class property.\n * @param {Object} options.bufferViews An object mapping bufferView IDs to Uint8Array objects.\n *\n * @alias MetadataTableProperty\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataTableProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const count = options.count;\n const property = options.property;\n const classProperty = options.classProperty;\n const bufferViews = options.bufferViews;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"options.count\", count, 0);\n Check.typeOf.object(\"options.property\", property);\n Check.typeOf.object(\"options.classProperty\", classProperty);\n Check.typeOf.object(\"options.bufferViews\", bufferViews);\n //>>includeEnd('debug');\n\n const type = classProperty.type;\n const isArray = classProperty.isArray;\n const isVariableLengthArray = classProperty.isVariableLengthArray;\n\n let valueType = classProperty.valueType;\n const enumType = classProperty.enumType;\n\n const hasStrings = type === MetadataType.STRING;\n const hasBooleans = type === MetadataType.BOOLEAN;\n\n let byteLength = 0;\n\n let arrayOffsets;\n if (isVariableLengthArray) {\n // EXT_structural_metadata uses arrayOffsetType.\n // EXT_feature_metadata uses offsetType for both arrays and strings\n let arrayOffsetType = defaultValue(\n property.arrayOffsetType,\n property.offsetType\n );\n arrayOffsetType = defaultValue(\n MetadataComponentType[arrayOffsetType],\n MetadataComponentType.UINT32\n );\n\n // EXT_structural_metadata uses arrayOffsets.\n // EXT_feature_metadata uses arrayOffsetBufferView\n const arrayOffsetBufferView = defaultValue(\n property.arrayOffsets,\n property.arrayOffsetBufferView\n );\n arrayOffsets = new BufferView(\n bufferViews[arrayOffsetBufferView],\n arrayOffsetType,\n count + 1\n );\n\n byteLength += arrayOffsets.typedArray.byteLength;\n }\n\n const vectorComponentCount = MetadataType.getComponentCount(type);\n\n let arrayComponentCount;\n if (isVariableLengthArray) {\n arrayComponentCount = arrayOffsets.get(count) - arrayOffsets.get(0);\n } else if (isArray) {\n arrayComponentCount = count * classProperty.arrayLength;\n } else {\n arrayComponentCount = count;\n }\n\n const componentCount = vectorComponentCount * arrayComponentCount;\n\n let stringOffsets;\n if (hasStrings) {\n // EXT_structural_metadata uses stringOffsetType, EXT_feature_metadata uses offsetType for both arrays and strings\n let stringOffsetType = defaultValue(\n property.stringOffsetType,\n property.offsetType\n );\n stringOffsetType = defaultValue(\n MetadataComponentType[stringOffsetType],\n MetadataComponentType.UINT32\n );\n\n // EXT_structural_metadata uses stringOffsets.\n // EXT_feature_metadata uses stringOffsetBufferView\n const stringOffsetBufferView = defaultValue(\n property.stringOffsets,\n property.stringOffsetBufferView\n );\n stringOffsets = new BufferView(\n bufferViews[stringOffsetBufferView],\n stringOffsetType,\n componentCount + 1\n );\n\n byteLength += stringOffsets.typedArray.byteLength;\n }\n\n if (hasStrings || hasBooleans) {\n // STRING and BOOLEAN types need to be parsed differently than other types\n valueType = MetadataComponentType.UINT8;\n }\n\n let valueCount;\n if (hasStrings) {\n valueCount = stringOffsets.get(componentCount) - stringOffsets.get(0);\n } else if (hasBooleans) {\n valueCount = Math.ceil(componentCount / 8);\n } else {\n valueCount = componentCount;\n }\n\n // EXT_structural_metadata uses values\n // EXT_feature_metadata uses bufferView\n const valuesBufferView = defaultValue(property.values, property.bufferView);\n const values = new BufferView(\n bufferViews[valuesBufferView],\n valueType,\n valueCount\n );\n byteLength += values.typedArray.byteLength;\n\n let offset = property.offset;\n let scale = property.scale;\n\n // This needs to be set before handling default values\n const hasValueTransform =\n classProperty.hasValueTransform || defined(offset) || defined(scale);\n\n // If the table does not define an offset/scale, it inherits from the\n // class property. The class property handles setting the default of identity:\n // (offset 0, scale 1) with the same array shape as the property's type\n // information.\n offset = defaultValue(offset, classProperty.offset);\n scale = defaultValue(scale, classProperty.scale);\n\n // Since metadata table properties are stored as packed typed\n // arrays, flatten the offset/scale to make it easier to apply the\n // transformation by iteration.\n offset = flatten(offset);\n scale = flatten(scale);\n\n let getValueFunction;\n let setValueFunction;\n const that = this;\n if (hasStrings) {\n getValueFunction = function (index) {\n return getString(index, that._values, that._stringOffsets);\n };\n } else if (hasBooleans) {\n getValueFunction = function (index) {\n return getBoolean(index, that._values);\n };\n setValueFunction = function (index, value) {\n setBoolean(index, that._values, value);\n };\n } else if (defined(enumType)) {\n getValueFunction = function (index) {\n const integer = that._values.get(index);\n return enumType.namesByValue[integer];\n };\n setValueFunction = function (index, value) {\n const integer = enumType.valuesByName[value];\n that._values.set(index, integer);\n };\n } else {\n getValueFunction = function (index) {\n return that._values.get(index);\n };\n setValueFunction = function (index, value) {\n that._values.set(index, value);\n };\n }\n\n this._arrayOffsets = arrayOffsets;\n this._stringOffsets = stringOffsets;\n this._values = values;\n this._classProperty = classProperty;\n this._count = count;\n this._vectorComponentCount = vectorComponentCount;\n this._min = property.min;\n this._max = property.max;\n this._offset = offset;\n this._scale = scale;\n this._hasValueTransform = hasValueTransform;\n this._getValue = getValueFunction;\n this._setValue = setValueFunction;\n this._unpackedValues = undefined;\n this._extras = property.extras;\n this._extensions = property.extensions;\n this._byteLength = byteLength;\n}\n\nObject.defineProperties(MetadataTableProperty.prototype, {\n /**\n * True if offset/scale should be applied. If both offset/scale were\n * undefined, they default to identity so this property is set false\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n hasValueTransform: {\n get: function () {\n return this._hasValueTransform;\n },\n },\n\n /**\n * The offset to be added to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n * @private\n */\n offset: {\n get: function () {\n return this._offset;\n },\n },\n\n /**\n * The scale to be multiplied to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|number[]|number[][]}\n * @readonly\n * @private\n */\n scale: {\n get: function () {\n return this._scale;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataTableProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataTableProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n\n /**\n * Size of all typed arrays used by this table property\n *\n * @memberof MetadataTableProperty.prototype\n * @type {Normal}\n * @readonly\n * @private\n */\n byteLength: {\n get: function () {\n return this._byteLength;\n },\n },\n});\n\n/**\n * Returns a copy of the value at the given index.\n *\n * @param {number} index The index.\n * @returns {*} The value of the property.\n *\n * @private\n */\nMetadataTableProperty.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n checkIndex(this, index);\n //>>includeEnd('debug');\n\n let value = get(this, index);\n\n // handle noData and default\n value = this._classProperty.handleNoData(value);\n if (!defined(value)) {\n value = this._classProperty.default;\n return this._classProperty.unpackVectorAndMatrixTypes(value);\n }\n\n value = this._classProperty.normalize(value);\n value = applyValueTransform(this, value);\n return this._classProperty.unpackVectorAndMatrixTypes(value);\n};\n\n/**\n * Sets the value at the given index.\n *\n * @param {number} index The index.\n * @param {*} value The value of the property.\n *\n * @private\n */\nMetadataTableProperty.prototype.set = function (index, value) {\n const classProperty = this._classProperty;\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"value\", value);\n checkIndex(this, index);\n const errorMessage = classProperty.validate(value);\n if (defined(errorMessage)) {\n throw new DeveloperError(errorMessage);\n }\n //>>includeEnd('debug');\n\n value = classProperty.packVectorAndMatrixTypes(value);\n value = unapplyValueTransform(this, value);\n value = classProperty.unnormalize(value);\n\n set(this, index, value);\n};\n\n/**\n * Returns a typed array containing the property values.\n *\n * @returns {*} The typed array containing the property values or undefined if the property values are not stored in a typed array.\n *\n * @private\n */\nMetadataTableProperty.prototype.getTypedArray = function () {\n // Note: depending on the class definition some properties are unpacked to\n // JS arrays when first accessed and values will be undefined. Generally not\n // a concern for fixed-length arrays of numbers.\n if (defined(this._values)) {\n return this._values.typedArray;\n }\n\n return undefined;\n};\n\nfunction flatten(values) {\n if (!Array.isArray(values)) {\n return values;\n }\n\n const result = [];\n for (let i = 0; i < values.length; i++) {\n const value = values[i];\n if (Array.isArray(value)) {\n result.push.apply(result, value);\n } else {\n result.push(value);\n }\n }\n\n return result;\n}\n\nfunction checkIndex(table, index) {\n const count = table._count;\n if (!defined(index) || index < 0 || index >= count) {\n const maximumIndex = count - 1;\n throw new DeveloperError(\n `index is required and between zero and count - 1. Actual value: ${maximumIndex}`\n );\n }\n}\n\nfunction get(property, index) {\n if (requiresUnpackForGet(property)) {\n unpackProperty(property);\n }\n\n const classProperty = property._classProperty;\n const isArray = classProperty.isArray;\n const type = classProperty.type;\n const componentCount = MetadataType.getComponentCount(type);\n\n if (defined(property._unpackedValues)) {\n const value = property._unpackedValues[index];\n if (isArray) {\n return clone(value, true);\n }\n return value;\n }\n\n // handle single values\n if (!isArray && componentCount === 1) {\n return property._getValue(index);\n }\n\n return getArrayValues(property, classProperty, index);\n}\n\nfunction getArrayValues(property, classProperty, index) {\n let offset;\n let length;\n if (classProperty.isVariableLengthArray) {\n offset = property._arrayOffsets.get(index);\n length = property._arrayOffsets.get(index + 1) - offset;\n\n // for vectors and matrices, the offset and length need to be multiplied\n // by the component count\n const componentCount = MetadataType.getComponentCount(classProperty.type);\n offset *= componentCount;\n length *= componentCount;\n } else {\n const arrayLength = defaultValue(classProperty.arrayLength, 1);\n const componentCount = arrayLength * property._vectorComponentCount;\n offset = index * componentCount;\n length = componentCount;\n }\n\n const values = new Array(length);\n for (let i = 0; i < length; i++) {\n values[i] = property._getValue(offset + i);\n }\n\n return values;\n}\n\nfunction set(property, index, value) {\n if (requiresUnpackForSet(property, index, value)) {\n unpackProperty(property);\n }\n\n const classProperty = property._classProperty;\n const isArray = classProperty.isArray;\n const type = classProperty.type;\n const componentCount = MetadataType.getComponentCount(type);\n\n if (defined(property._unpackedValues)) {\n if (classProperty.isArray) {\n value = clone(value, true);\n }\n property._unpackedValues[index] = value;\n return;\n }\n\n // Values are unpacked if the length of a variable-size array changes or the\n // property has strings. No need to handle these cases below.\n\n // Handle single values\n if (!isArray && componentCount === 1) {\n property._setValue(index, value);\n return;\n }\n\n let offset;\n let length;\n if (classProperty.isVariableLengthArray) {\n offset = property._arrayOffsets.get(index);\n length = property._arrayOffsets.get(index + 1) - offset;\n } else {\n const arrayLength = defaultValue(classProperty.arrayLength, 1);\n const componentCount = arrayLength * property._vectorComponentCount;\n offset = index * componentCount;\n length = componentCount;\n }\n\n for (let i = 0; i < length; ++i) {\n property._setValue(offset + i, value[i]);\n }\n}\n\nfunction getString(index, values, stringOffsets) {\n const stringByteOffset = stringOffsets.get(index);\n const stringByteLength = stringOffsets.get(index + 1) - stringByteOffset;\n return getStringFromTypedArray(\n values.typedArray,\n stringByteOffset,\n stringByteLength\n );\n}\n\nfunction getBoolean(index, values) {\n // byteIndex is floor(index / 8)\n const byteIndex = index >> 3;\n const bitIndex = index % 8;\n return ((values.typedArray[byteIndex] >> bitIndex) & 1) === 1;\n}\n\nfunction setBoolean(index, values, value) {\n // byteIndex is floor(index / 8)\n const byteIndex = index >> 3;\n const bitIndex = index % 8;\n\n if (value) {\n values.typedArray[byteIndex] |= 1 << bitIndex;\n } else {\n values.typedArray[byteIndex] &= ~(1 << bitIndex);\n }\n}\n\nfunction getInt64NumberFallback(index, values) {\n const dataView = values.dataView;\n const byteOffset = index * 8;\n let value = 0;\n const isNegative = (dataView.getUint8(byteOffset + 7) & 0x80) > 0;\n let carrying = true;\n for (let i = 0; i < 8; ++i) {\n let byte = dataView.getUint8(byteOffset + i);\n if (isNegative) {\n if (carrying) {\n if (byte !== 0x00) {\n byte = ~(byte - 1) & 0xff;\n carrying = false;\n }\n } else {\n byte = ~byte & 0xff;\n }\n }\n value += byte * Math.pow(256, i);\n }\n if (isNegative) {\n value = -value;\n }\n return value;\n}\n\nfunction getInt64BigIntFallback(index, values) {\n const dataView = values.dataView;\n const byteOffset = index * 8;\n // eslint-disable-next-line no-undef\n let value = BigInt(0);\n const isNegative = (dataView.getUint8(byteOffset + 7) & 0x80) > 0;\n let carrying = true;\n for (let i = 0; i < 8; ++i) {\n let byte = dataView.getUint8(byteOffset + i);\n if (isNegative) {\n if (carrying) {\n if (byte !== 0x00) {\n byte = ~(byte - 1) & 0xff;\n carrying = false;\n }\n } else {\n byte = ~byte & 0xff;\n }\n }\n value += BigInt(byte) * (BigInt(1) << BigInt(i * 8)); // eslint-disable-line\n }\n if (isNegative) {\n value = -value;\n }\n return value;\n}\n\nfunction getUint64NumberFallback(index, values) {\n const dataView = values.dataView;\n const byteOffset = index * 8;\n\n // Split 64-bit number into two 32-bit (4-byte) parts\n const left = dataView.getUint32(byteOffset, true);\n const right = dataView.getUint32(byteOffset + 4, true);\n\n // Combine the two 32-bit values\n const value = left + 4294967296 * right;\n\n return value;\n}\n\nfunction getUint64BigIntFallback(index, values) {\n const dataView = values.dataView;\n const byteOffset = index * 8;\n\n // Split 64-bit number into two 32-bit (4-byte) parts\n // eslint-disable-next-line no-undef\n const left = BigInt(dataView.getUint32(byteOffset, true));\n\n // eslint-disable-next-line no-undef\n const right = BigInt(dataView.getUint32(byteOffset + 4, true));\n\n // Combine the two 32-bit values\n // eslint-disable-next-line no-undef\n const value = left + BigInt(4294967296) * right;\n\n return value;\n}\n\nfunction getComponentDatatype(componentType) {\n switch (componentType) {\n case MetadataComponentType.INT8:\n return ComponentDatatype.BYTE;\n case MetadataComponentType.UINT8:\n return ComponentDatatype.UNSIGNED_BYTE;\n case MetadataComponentType.INT16:\n return ComponentDatatype.SHORT;\n case MetadataComponentType.UINT16:\n return ComponentDatatype.UNSIGNED_SHORT;\n case MetadataComponentType.INT32:\n return ComponentDatatype.INT;\n case MetadataComponentType.UINT32:\n return ComponentDatatype.UNSIGNED_INT;\n case MetadataComponentType.FLOAT32:\n return ComponentDatatype.FLOAT;\n case MetadataComponentType.FLOAT64:\n return ComponentDatatype.DOUBLE;\n }\n}\n\nfunction requiresUnpackForGet(property) {\n if (defined(property._unpackedValues)) {\n return false;\n }\n\n const classProperty = property._classProperty;\n const type = classProperty.type;\n const valueType = classProperty.valueType;\n\n if (type === MetadataType.STRING) {\n // Unpack since UTF-8 decoding is expensive\n return true;\n }\n\n if (\n valueType === MetadataComponentType.INT64 &&\n !FeatureDetection.supportsBigInt64Array()\n ) {\n // Unpack since the fallback INT64 getters are expensive\n return true;\n }\n\n if (\n valueType === MetadataComponentType.UINT64 &&\n !FeatureDetection.supportsBigUint64Array()\n ) {\n // Unpack since the fallback UINT64 getters are expensive\n return true;\n }\n\n return false;\n}\n\nfunction requiresUnpackForSet(property, index, value) {\n if (requiresUnpackForGet(property)) {\n return true;\n }\n\n const arrayOffsets = property._arrayOffsets;\n if (defined(arrayOffsets)) {\n // Unpacking is required if a variable-size array changes length since it\n // would be expensive to repack the binary data\n const oldLength = arrayOffsets.get(index + 1) - arrayOffsets.get(index);\n const newLength = value.length;\n if (oldLength !== newLength) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction unpackProperty(property) {\n property._unpackedValues = unpackValues(property);\n\n // Free memory\n property._arrayOffsets = undefined;\n property._stringOffsets = undefined;\n property._values = undefined;\n}\n\nfunction unpackValues(property) {\n const count = property._count;\n const unpackedValues = new Array(count);\n\n const classProperty = property._classProperty;\n const isArray = classProperty.isArray;\n const type = classProperty.type;\n const componentCount = MetadataType.getComponentCount(type);\n\n // Handle single values\n if (!isArray && componentCount === 1) {\n for (let i = 0; i < count; ++i) {\n unpackedValues[i] = property._getValue(i);\n }\n return unpackedValues;\n }\n\n for (let i = 0; i < count; i++) {\n unpackedValues[i] = getArrayValues(property, classProperty, i);\n }\n return unpackedValues;\n}\n\nfunction applyValueTransform(property, value) {\n const classProperty = property._classProperty;\n const isVariableLengthArray = classProperty.isVariableLengthArray;\n if (!property._hasValueTransform || isVariableLengthArray) {\n return value;\n }\n\n return MetadataClassProperty.valueTransformInPlace(\n value,\n property._offset,\n property._scale,\n MetadataComponentType.applyValueTransform\n );\n}\n\nfunction unapplyValueTransform(property, value) {\n const classProperty = property._classProperty;\n const isVariableLengthArray = classProperty.isVariableLengthArray;\n if (!property._hasValueTransform || isVariableLengthArray) {\n return value;\n }\n\n return MetadataClassProperty.valueTransformInPlace(\n value,\n property._offset,\n property._scale,\n MetadataComponentType.unapplyValueTransform\n );\n}\n\nfunction BufferView(bufferView, componentType, length) {\n const that = this;\n\n let typedArray;\n let getFunction;\n let setFunction;\n\n if (componentType === MetadataComponentType.INT64) {\n if (!FeatureDetection.supportsBigInt()) {\n oneTimeWarning(\n \"INT64 type is not fully supported on this platform. Values greater than 2^53 - 1 or less than -(2^53 - 1) may lose precision when read.\"\n );\n typedArray = new Uint8Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length * 8\n );\n getFunction = function (index) {\n return getInt64NumberFallback(index, that);\n };\n } else if (!FeatureDetection.supportsBigInt64Array()) {\n typedArray = new Uint8Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length * 8\n );\n getFunction = function (index) {\n return getInt64BigIntFallback(index, that);\n };\n } else {\n // eslint-disable-next-line\n typedArray = new BigInt64Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length\n );\n setFunction = function (index, value) {\n // Convert the number to a BigInt before setting the value in the typed array\n that.typedArray[index] = BigInt(value); // eslint-disable-line\n };\n }\n } else if (componentType === MetadataComponentType.UINT64) {\n if (!FeatureDetection.supportsBigInt()) {\n oneTimeWarning(\n \"UINT64 type is not fully supported on this platform. Values greater than 2^53 - 1 may lose precision when read.\"\n );\n typedArray = new Uint8Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length * 8\n );\n getFunction = function (index) {\n return getUint64NumberFallback(index, that);\n };\n } else if (!FeatureDetection.supportsBigUint64Array()) {\n typedArray = new Uint8Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length * 8\n );\n getFunction = function (index) {\n return getUint64BigIntFallback(index, that);\n };\n } else {\n // eslint-disable-next-line\n typedArray = new BigUint64Array(\n bufferView.buffer,\n bufferView.byteOffset,\n length\n );\n setFunction = function (index, value) {\n // Convert the number to a BigInt before setting the value in the typed array\n that.typedArray[index] = BigInt(value); // eslint-disable-line\n };\n }\n } else {\n const componentDatatype = getComponentDatatype(componentType);\n typedArray = ComponentDatatype.createArrayBufferView(\n componentDatatype,\n bufferView.buffer,\n bufferView.byteOffset,\n length\n );\n setFunction = function (index, value) {\n that.typedArray[index] = value;\n };\n }\n\n if (!defined(getFunction)) {\n getFunction = function (index) {\n return that.typedArray[index];\n };\n }\n\n this.typedArray = typedArray;\n this.dataView = new DataView(typedArray.buffer, typedArray.byteOffset);\n this.get = getFunction;\n this.set = setFunction;\n\n // for unit testing\n this._componentType = componentType;\n}\n\nexport default MetadataTableProperty;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\nimport MetadataTableProperty from \"./MetadataTableProperty.js\";\n\n/**\n * A table containing binary metadata for a collection of entities. This is\n * used for representing binary properties of a batch table, as well as binary\n * metadata in 3D Tiles next extensions.\n *

\n * For 3D Tiles Next details, see the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles, as well as the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.count The number of entities in the table.\n * @param {object} [options.properties] A dictionary containing properties.\n * @param {MetadataClass} options.class The class that properties conform to.\n * @param {Object} [options.bufferViews] An object mapping bufferView IDs to Uint8Array objects.\n *\n * @alias MetadataTable\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataTable(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const count = options.count;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"options.count\", count, 0);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n let byteLength = 0;\n const properties = {};\n if (defined(options.properties)) {\n for (const propertyId in options.properties) {\n if (options.properties.hasOwnProperty(propertyId)) {\n const property = new MetadataTableProperty({\n count: count,\n property: options.properties[propertyId],\n classProperty: metadataClass.properties[propertyId],\n bufferViews: options.bufferViews,\n });\n properties[propertyId] = property;\n byteLength += property.byteLength;\n }\n }\n }\n\n this._count = count;\n this._class = metadataClass;\n this._properties = properties;\n this._byteLength = byteLength;\n}\n\nObject.defineProperties(MetadataTable.prototype, {\n /**\n * The number of entities in the table.\n *\n * @memberof MetadataTable.prototype\n * @type {number}\n * @readonly\n * @private\n */\n count: {\n get: function () {\n return this._count;\n },\n },\n\n /**\n * The class that properties conform to.\n *\n * @memberof MetadataTable.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * The size of all typed arrays used in this table.\n *\n * @memberof MetadataTable.prototype\n * @type {number}\n * @readonly\n * @private\n */\n byteLength: {\n get: function () {\n return this._byteLength;\n },\n },\n});\n\n/**\n * Returns whether the table has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the table has this property.\n * @private\n */\nMetadataTable.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the table has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the table has a property with the given semantic.\n * @private\n */\nMetadataTable.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nMetadataTable.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is an enum the name of the enum is returned.\n *

\n *

\n * If the property is normalized the normalized value is returned. The value is\n * in the range [-1.0, 1.0] for signed integer types and [0.0, 1.0] for unsigned\n * integer types.\n *

\n *

\n * If the property is not normalized and type or componentType is INT64 or\n * UINT64 a BigInt will be returned. On platforms that don't support BigInt a\n * number will be returned instead. Note that numbers only support up to 52 bits\n * of integer precision. Values greater than 2^53 - 1 or less than -(2^53 - 1)\n * may lose precision when read.\n *

\n *\n * @param {number} index The index of the entity.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n *\n * @exception {DeveloperError} index is required and between zero and count - 1\n * @private\n */\nMetadataTable.prototype.getProperty = function (index, propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n const property = this._properties[propertyId];\n\n let value;\n if (defined(property)) {\n value = property.get(index);\n } else {\n value = getDefault(this._class, propertyId);\n }\n\n return value;\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is an enum the name of the enum must be provided, not the\n * integer value.\n *

\n *

\n * If the property is normalized a normalized value must be provided to this\n * function. The value must be in the range [-1.0, 1.0] for signed integer\n * types and [0.0, 1.0] for unsigned integer types.\n *

\n *

\n * If the property is not normalized and type or componentType is INT64 or\n * UINT64 a BigInt may be provided. On platforms that don't support BigInt a\n * number may be provided instead. Note that numbers only support up to 52 bits\n * of integer precision. Values greater than 2^53 - 1 or less than -(2^53 - 1)\n * may lose precision when set.\"\n *

\n *\n * @param {number} index The index of the entity.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n *\n * @exception {DeveloperError} index is required and between zero and count - 1\n * @exception {DeveloperError} value does not match type\n * @exception {DeveloperError} value is out of range for type\n * @exception {DeveloperError} Array length does not match componentCount\n * @private\n */\nMetadataTable.prototype.setProperty = function (index, propertyId, value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n const property = this._properties[propertyId];\n if (defined(property)) {\n property.set(index, value);\n return true;\n }\n\n return false;\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {number} index The index of the entity.\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the entity does not have this semantic.\n *\n * @exception {DeveloperError} index is required and between zero and count - 1\n * @private\n */\nMetadataTable.prototype.getPropertyBySemantic = function (index, semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n let property;\n const propertiesBySemantic = this._class.propertiesBySemantic;\n if (defined(propertiesBySemantic)) {\n property = propertiesBySemantic[semantic];\n }\n\n if (defined(property)) {\n return this.getProperty(index, property.id);\n }\n\n return undefined;\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {number} index The index of the entity.\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n *\n * @exception {DeveloperError} index is required and between zero and count - 1\n * @exception {DeveloperError} value does not match type\n * @exception {DeveloperError} value is out of range for type\n * @exception {DeveloperError} Array length does not match componentCount\n * @private\n */\nMetadataTable.prototype.setPropertyBySemantic = function (\n index,\n semantic,\n value\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n let property;\n const propertiesBySemantic = this._class.propertiesBySemantic;\n if (defined(propertiesBySemantic)) {\n property = propertiesBySemantic[semantic];\n }\n\n if (defined(property)) {\n return this.setProperty(index, property.id, value);\n }\n\n return false;\n};\n\n/**\n * Returns a typed array containing the property values for a given propertyId.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The typed array containing the property values or undefined if the property values are not stored in a typed array.\n *\n * @private\n */\nMetadataTable.prototype.getPropertyTypedArray = function (propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n const property = this._properties[propertyId];\n\n if (defined(property)) {\n return property.getTypedArray();\n }\n\n return undefined;\n};\n\n/**\n * Returns a typed array containing the property values for the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The typed array containing the property values or undefined if the property values are not stored in a typed array.\n *\n * @private\n */\nMetadataTable.prototype.getPropertyTypedArrayBySemantic = function (semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n let property;\n const propertiesBySemantic = this._class.propertiesBySemantic;\n if (defined(propertiesBySemantic)) {\n property = propertiesBySemantic[semantic];\n }\n\n if (defined(property)) {\n return this.getPropertyTypedArray(property.id);\n }\n\n return undefined;\n};\n\nfunction getDefault(classDefinition, propertyId) {\n const classProperties = classDefinition.properties;\n if (!defined(classProperties)) {\n return undefined;\n }\n\n const classProperty = classProperties[propertyId];\n if (defined(classProperty) && defined(classProperty.default)) {\n let value = classProperty.default;\n if (classProperty.isArray) {\n value = clone(value, true);\n }\n value = classProperty.normalize(value);\n return classProperty.unpackVectorAndMatrixTypes(value);\n }\n}\n\nexport default MetadataTable;\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * A cache resource.\n *

\n * This type describes an interface and is not intended to be instantiated directly.\n *

\n *\n * @alias ResourceLoader\n * @constructor\n *\n * @see ResourceCache\n *\n * @private\n */\nfunction ResourceLoader() {}\n\nObject.defineProperties(ResourceLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof ResourceLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n // eslint-disable-next-line getter-return\n get: function () {\n DeveloperError.throwInstantiationError();\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nResourceLoader.prototype.load = function () {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nResourceLoader.prototype.unload = function () {};\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {boolean} true once all resourced are ready.\n * @private\n */\nResourceLoader.prototype.process = function (frameState) {\n return false;\n};\n\n/**\n * Constructs a {@link RuntimeError} from an errorMessage and an error.\n *\n * @param {string} errorMessage The error message.\n * @param {Error} [error] The error.\n *\n * @returns {RuntimeError} The runtime error.\n * @private\n */\nResourceLoader.prototype.getError = function (errorMessage, error) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"errorMessage\", errorMessage);\n //>>includeEnd('debug');\n\n if (defined(error) && defined(error.message)) {\n errorMessage += `\\n${error.message}`;\n }\n\n const runtimeError = new RuntimeError(errorMessage);\n if (defined(error)) {\n runtimeError.stack = `Original stack:\\n${error.stack}\\nHandler stack:\\n${runtimeError.stack}`;\n }\n\n return runtimeError;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see ResourceLoader#destroy\n * @private\n */\nResourceLoader.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the loaded resource.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * resourceLoader = resourceLoader && resourceLoader.destroy();\n *\n * @see ResourceLoader#isDestroyed\n * @private\n */\nResourceLoader.prototype.destroy = function () {\n this.unload();\n return destroyObject(this);\n};\n\nexport default ResourceLoader;\n", "/**\n * The {@link ResourceLoader} state.\n *\n * @private\n */\nconst ResourceLoaderState = {\n /**\n * The resource has not yet been loaded.\n *\n * @type {number}\n * @constant\n * @private\n */\n UNLOADED: 0,\n /**\n * The resource is loading. In this state, external resources are fetched as needed.\n *\n * @type {number}\n * @constant\n * @private\n */\n LOADING: 1,\n /**\n * The resource has finished loading, but requires further processing.\n *\n * @type {number}\n * @constant\n * @private\n */\n LOADED: 2,\n /**\n * The resource is processing. GPU resources are allocated in this state as needed.\n *\n * @type {Number}\n * @constant\n * @private\n */\n PROCESSING: 3,\n /**\n * The resource has finished loading and processing; the results are ready to be used.\n *\n * @type {number}\n * @constant\n * @private\n */\n READY: 4,\n /**\n * The resource loading or processing has failed due to an error.\n *\n * @type {number}\n * @constant\n * @private\n */\n FAILED: 5,\n};\nexport default Object.freeze(ResourceLoaderState);\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads an embedded or external buffer.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias BufferLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {Uint8Array} [options.typedArray] The typed array containing the embedded buffer contents. Mutually exclusive with options.resource.\n * @param {Resource} [options.resource] The {@link Resource} pointing to the external buffer. Mutually exclusive with options.typedArray.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @exception {DeveloperError} One of options.typedArray and options.resource must be defined.\n *\n * @private\n */\nfunction BufferLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const typedArray = options.typedArray;\n const resource = options.resource;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(typedArray) === defined(resource)) {\n throw new DeveloperError(\n \"One of options.typedArray and options.resource must be defined.\"\n );\n }\n //>>includeEnd('debug');\n\n this._typedArray = typedArray;\n this._resource = resource;\n this._cacheKey = cacheKey;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n BufferLoader.prototype = Object.create(ResourceLoader.prototype);\n BufferLoader.prototype.constructor = BufferLoader;\n}\n\nObject.defineProperties(BufferLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof BufferLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The typed array containing the embedded buffer contents.\n *\n * @memberof BufferLoader.prototype\n *\n * @type {Uint8Array}\n * @readonly\n * @private\n */\n typedArray: {\n get: function () {\n return this._typedArray;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nBufferLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n if (defined(this._typedArray)) {\n this._promise = Promise.resolve(this);\n return this._promise;\n }\n\n this._promise = loadExternalBuffer(this);\n return this._promise;\n};\n\nasync function loadExternalBuffer(bufferLoader) {\n const resource = bufferLoader._resource;\n bufferLoader._state = ResourceLoaderState.LOADING;\n try {\n const arrayBuffer = await BufferLoader._fetchArrayBuffer(resource);\n if (bufferLoader.isDestroyed()) {\n return;\n }\n\n bufferLoader._typedArray = new Uint8Array(arrayBuffer);\n bufferLoader._state = ResourceLoaderState.READY;\n return bufferLoader;\n } catch (error) {\n if (bufferLoader.isDestroyed()) {\n return;\n }\n\n bufferLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = `Failed to load external buffer: ${resource.url}`;\n throw bufferLoader.getError(errorMessage, error);\n }\n}\n\n/**\n * Exposed for testing\n * @private\n */\nBufferLoader._fetchArrayBuffer = function (resource) {\n return resource.fetchArrayBuffer();\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nBufferLoader.prototype.unload = function () {\n this._typedArray = undefined;\n};\n\nexport default BufferLoader;\n", "// This file is part of meshoptimizer library and is distributed under the terms of MIT License.\n// Copyright (C) 2016-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)\nvar MeshoptEncoder = (function() {\n\t\"use strict\";\n\n\t// Built with clang version 15.0.6\n\t// Built from meshoptimizer 0.19\n\tvar wasm = \"b9H79TebbbeJq9Geueu9Geub9Gbb9Gvuuuuueu9Gduueu9Gluuuueu9Gvuuuuub9Gouuuuuub9Gluuuub9GiuuueuiLQdilevlevlooroowwvbDDbelve9Weiiviebeoweuec:G;kekr;qiHo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9FW9U9J9V9KW9wWVtW949c919M9MWVbe8F9TW79O9V9Wt9FW9U9J9V9KW9wWVtW949c919M9MWV9c9V919U9KbdE9TW79O9V9Wt9FW9U9J9V9KW9wWVtW949wWV79P9V9UbiY9TW79O9V9Wt9FW9U9J9V9KW69U9KW949c919M9MWVbl8E9TW79O9V9Wt9FW9U9J9V9KW69U9KW949c919M9MWV9c9V919U9Kbv8A9TW79O9V9Wt9FW9U9J9V9KW69U9KW949wWV79P9V9UboE9TW79O9V9Wt9FW9U9J9V9KW69U9KW949tWG91W9U9JWbra9TW79O9V9Wt9FW9U9J9V9KW69U9KW949tWG91W9U9JW9c9V919U9KbwL9TW79O9V9Wt9FW9U9J9V9KWS9P2tWV9p9JtbDK9TW79O9V9Wt9FW9U9J9V9KWS9P2tWV9r919HtbqL9TW79O9V9Wt9FW9U9J9V9KWS9P2tWVT949WbkE9TW79O9V9Wt9F9V9Wt9P9T9P96W9wWVtW94J9H9J9OWbPa9TW79O9V9Wt9F9V9Wt9P9T9P96W9wWVtW94J9H9J9OW9ttV9P9Wbsa9TW79O9V9Wt9F9V9Wt9P9T9P96W9wWVtW94SWt9J9O9sW9T9H9Wbzl79IV9RbHDwebcekdXCq:fSQdbk:fxeYu8Jjjjjbcjo9Rgv8Kjjjjbcbhodnalcefae0mbabcbRb:q:kjjbc:GeV86bbavcjdfcbcjdz:tjjjb8AdnaiTmbavcjdfadalzMjjjb8Akabaefhrabcefhwavalfcbcbcjdal9RalcFe0Ez:tjjjb8AavavcjdfalzMjjjbhDcj;abal9UhodndndndndnalTmbaoc;WFbGgecjdaecjd6Ehqcbhkdninakai9pmiaDcjlfcbcjdz:tjjjb8Aaqaiak9Rakaqfai6Egxcsfgecl4cifcd4hmadakal2fhPdndndndndnaec9WGgsTmbcbhzcehHaPhOawhAxekdnaxTmbcbhAcehHaPhCinaDaAfRbbhXaDcjlfheaChoaxhQinaeaoRbbgLaX9RgXcetaXcKtcK91cr4786bbaoalfhoaecefheaLhXaQcufgQmbkaraw9Ram6miawcbamz:tjjjbgeTmiaCcefhCaeamfhwaAcefgAal6hHaAal9hmbxvkkaraw9Ram6mvawcbamz:tjjjb8AceheinawgXamfhwalaegoSmldnaraw9Ram6mbaocefheawcbamz:tjjjb8AaXmekkcbhwaoal6mvxikindnaxTmbaDazfRbbhXaDcjlfheaOhoaxhQinaeaoRbbgLaX9RgXcetaXcKtcK91cr4786bbaoalfhoaecefheaLhXaQcufgQmbkkaraA9Ram6mearaAcbamz:tjjjbgKamfgw9RcK6mdcbhYaDcjlfhAinaDcjlfaYfh8AcwhCczhLcehQindndnaQce9hmbcuhoa8ARbbmecbhodninaogecsSmeaecefhoaAaefcefRbbTmbkkcucbaecs6EhoxekaQcetc;:FFFeGhocuaQtcu7cFeGhXcbheinaoaXaAaefRbb9nfhoaecefgecz9hmbkkaoaLaoaL6geEhLaQaCaeEhCaQcetgQcw6mbkdndndndnaCcufPdiebkaKaYco4fgeaeRbbcdciaCclSEaYci4coGtV86bbaCcw9hmeawa8A8Pbb83bbawcwfa8Acwf8Pbb83bbawczfhwxdkaKaYco4fgeaeRbbceaYci4coGtV86bbkdncwaC9TgEmbinawcb86bbawcefhwxbkkcuaCtcu7h8Acbh3aAh5ina5heaEhQcbhoinaeRbbgLa8AcFeGgXaLaX6EaoaCtVhoaecefheaQcufgQmbkawao86bba5aEfh5awcefhwa3aEfg3cz6mbkcbheindnaAaefRbbgoaX6mbawao86bbawcefhwkaecefgecz9hmbkkdnaYczfgYas9pmbaAczfhAaraw9RcL0mekkaYas6meawTmeaOcefhOazcefgzal6hHawhAazalSmixbkkcbhwaHceGTmexikcbhwaHceGmdkaDaPaxcufal2falzMjjjb8AaxakfhkawmbkcbhoxokcbhoxvkaiTmekcbhoaraw9Ralcaalca0E6mialc8F9nmexdkcbhoaecufca6mdkawcbcaal9Rgez:tjjjbaefhwkawaDcjdfalzMjjjbalfab9Rhokavcjof8Kjjjjbaok9heeuaecaaeca0Eabcj;abae9Uc;WFbGgdcjdadcjd6Egdfcufad9Uae2adcl4cifcd4adV2fcefkmbcbabBd:q:kjjbk;use3u8Jjjjjbc;ae9Rgl8Kjjjjbcbhvdnaici9UgocHfae0mbabcbydN:kjjbgrc;GeV86bbalc;abfcFecjez:tjjjb8AalcUfgw9cu83ibalc8WfgD9cu83ibalcyfgq9cu83ibalcafgk9cu83ibalcKfgx9cu83ibalczfgm9cu83ibal9cu83iwal9cu83ibabaefc9WfhPabcefgsaofhednaiTmbcmcsarcb9kgzEhHcbhOcbhAcbhCcbhXcbhQindnaeaP9nmbcbhvxikaQcufhvadaCcdtfgoydbhLaocwfydbhKaoclfydbhYcbh8Adndninalc;abfavcsGcitfgoydlhEdndndnaoydbgoaL9hmbaEaYSmekdnaoaY9hmbaEaK9hmba8Acefh8AxekaoaK9hmeaEaL9hmea8Acdfh8Aka8Ac870mdaXcufhvada8AciGcx2goc:y1jjbfydbaCfcdtfydbhEadaocN1jjbfydbaCfcdtfydbhKadaoc:q1jjbfydbaCfcdtfydbhLcbhodnindnalavcsGcdtfydbaE9hmbaohYxdkcuhYavcufhvaocefgocz9hmbkkaEaOSgvaYcb9kaYaH9iGgoce7Gh3dndndndndnaYcbcsavEaoEgvcs9hmbarce9imbaEaEaAaEcefaASgvEgAcefSmecmcsavEhvkasava8Acdtc;WeGV86bbavcs9hmeaEaA9Rgvcetavc8F917hvinaeavcFb0crtavcFbGV86bbaecefheavcje6hoavcr4hvaoTmbkaEhAxdkcPhvasa8AcdtcPV86bbaEhAkavTmbavaH9imekalaXcdtfaEBdbaXcefcsGhXkaOa3fhOalc;abfaQcitfgvaKBdlavaEBdbalc;abfaQcefcsGgvcitfgoaEBdlaoaLBdbavcefhoxikavcufhva8Aclfg8Ac;ab9hmbkkdnadceaKaOScetaYaOSEcx2gvc:q1jjbfydbaCfcdtfydbgLTadavcN1jjbfydbaCfcdtfydbg8AceSGadavc:y1jjbfydbaCfcdtfydbgYcdSGaOcb9hGazGg5ce9hmbaw9cu83ibaD9cu83ibaq9cu83ibak9cu83ibax9cu83ibam9cu83ibal9cu83iwal9cu83ibcbhOkcbhEaXcufgvhodnindnalaocsGcdtfydba8A9hmbaEhKxdkcuhKaocufhoaEcefgEcz9hmbkkcbhodnindnalavcsGcdtfydbaY9hmbaohExdkcuhEavcufhvaocefgocz9hmbkkaOaLaOSg8Efh3dndnaKcm0mbaKcefhKxekcbcsa8Aa3SgvEhKa3avfh3kdndnaEcm0mbaEcefhExekcbcsaYa3SgvEhEa3avfh3kc9:cua8EEh8FaEaKcltVhocbhvdndndninavcj1jjbfRbbaocFeGSmeavcefgvcz9hmbxdkkaLaO9havcm0Va5Vmbasavc;WeV86bbxekasa8F86bbaeao86bbaecefhekdna8EmbaLaA9Rgvcetavc8F917hvinaeavcFb0gocrtavcFbGV86bbavcr4hvaecefheaombkaLhAkdnaKcs9hmba8AaA9Rgvcetavc8F917hvinaeavcFb0gocrtavcFbGV86bbavcr4hvaecefheaombka8AhAkdnaEcs9hmbaYaA9Rgvcetavc8F917hvinaeavcFb0gocrtavcFbGV86bbavcr4hvaecefheaombkaYhAkalaXcdtfaLBdbaXcefcsGhvdndnaKPzbeeeeeeeeeeeeeebekalavcdtfa8ABdbaXcdfcsGhvkdndnaEPzbeeeeeeeeeeeeeebekalavcdtfaYBdbavcefcsGhvkalc;abfaQcitfgoaLBdlaoa8ABdbalc;abfaQcefcsGcitfgoa8ABdlaoaYBdbalc;abfaQcdfcsGcitfgoaYBdlaoaLBdbaQcifhoavhXa3hOkascefhsaocsGhQaCcifgCai6mbkkcbhvaeaP0mbcbhvinaeavfavcj1jjbfRbb86bbavcefgvcz9hmbkaeab9Ravfhvkalc;aef8KjjjjbavkZeeucbhddninadcefgdc8F0meceadtae6mbkkadcrfcFeGcr9Uci2cdfabci9U2cHfkmbcbabBdN:kjjbk:ydewu8Jjjjjbcz9Rhlcbhvdnaicvfae0mbcbhvabcbRbN:kjjbc;qeV86bbal9cb83iwabcefhoabaefc98fhrdnaiTmbcbhwcbhDindnaoar6mbcbskadaDcdtfydbgqalcwfawaqav9Rgvavc8F91gv7av9Rc507gwcdtfgkydb9Rgvc8E91c9:Gavcdt7awVhvinaoavcFb0gecrtavcFbGV86bbavcr4hvaocefhoaembkakaqBdbaqhvaDcefgDai9hmbkkcbhvaoar0mbaocbBbbaoab9RclfhvkavkBeeucbhddninadcefgdc8F0meceadtae6mbkkadcwfcFeGcr9Uab2cvfk:dvli99dui99ludnaeTmbcuadcetcuftcu7:Yhvdndncuaicuftcu7:YgoJbbbZMgr:lJbbb9p9DTmbar:Ohwxekcjjjj94hwkcbhicbhDinalclfIdbgrJbbbbJbbjZalIdbgq:lar:lMalcwfIdbgk:lMgr:varJbbbb9BEgrNhxaqarNhralcxfIdbhqdndnakJbbbb9GTmbaxhkxekJbbjZar:l:tgkak:maxJbbbb9GEhkJbbjZax:l:tgxax:marJbbbb9GEhrkdndnaqJbbj:;aqJbbj:;9GEgxJbbjZaxJbbjZ9FEavNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohmxekcjjjj94hmkdndnakJbbj:;akJbbj:;9GEgqJbbjZaqJbbjZ9FEaoNJbbbZJbbb:;akJbbbb9GEMgq:lJbbb9p9DTmbaq:OhPxekcjjjj94hPkdndnarJbbj:;arJbbj:;9GEgqJbbjZaqJbbjZ9FEaoNJbbbZJbbb:;arJbbbb9GEMgr:lJbbb9p9DTmbar:Ohsxekcjjjj94hskdndnadcl9hmbabaDfgzas86bbazcifam86bbazcdfaw86bbazcefaP86bbxekabaifgzas87ebazcofam87ebazclfaw87ebazcdfaP87ebkalczfhlaicwfhiaDclfhDaecufgembkkk;klld99eud99eudnaeTmbdndncuaicuftcu7:YgvJbbbZMgo:lJbbb9p9DTmbao:Ohixekcjjjj94hikaic;8FiGhrinabcofcicdalclfIdb:lalIdb:l9EgialcwfIdb:lalaicdtfIdb:l9EEgialcxfIdb:lalaicdtfIdb:l9EEgiarV87ebdndnalaicefciGcdtfIdbJ;Zl:1ZNJbbj:;JbbjZalaicdtfIdbJbbbb9DEgoNgwJbbj:;awJbbj:;9GEgDJbbjZaDJbbjZ9FEavNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohqxekcjjjj94hqkabaq87ebdndnaoalaicdfciGcdtfIdbJ;Zl:1ZNNgwJbbj:;awJbbj:;9GEgDJbbjZaDJbbjZ9FEavNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohqxekcjjjj94hqkabcdfaq87ebdndnaoalaicufciGcdtfIdbJ;Zl:1ZNNgoJbbj:;aoJbbj:;9GEgwJbbjZawJbbjZ9FEavNJbbbZJbbb:;aoJbbbb9GEMgo:lJbbb9p9DTmbao:Ohixekcjjjj94hikabclfai87ebabcwfhbalczfhlaecufgembkkk:Hvdxue998Jjjjjbcjd9Rgo8Kjjjjbadcd4hrdndndndnavcd9hmbadcl6mearcearce0EhwaohDinaDc:CuBdbaDclfhDawcufgwmbkaeTmiadcl6mdarcearce0EhqarcdthkalhxcbhminaohDaxhwaqhPinaDaDydbgsawydbgzcL4cFeGc:cufcbazEgzasaz9kEBdbawclfhwaDclfhDaPcufgPmbkaxakfhxamcefgmae9hmbkkaeTmdxekaeTmekavcb9hadcl6gqVhHarcearce0Ehkarcdthrceai9Rhmcbhdindndndnavce9hmbaqmdc:CuhwalhDakhPinawaDydbgscL4cFeGc:cufcbasEgsawas9kEhwaDclfhDaPcufgPmbxdkkc:CuhwaHmbaohDalhPakhsinaDaPydbgzcL4cFeGgxc8Aaxc8A9kEc:cufcbazEBdbaPclfhPaDclfhDascufgsmbkkaqmbcbhDakhsinawhPdnavceSmbaoaDfydbhPkdndnalaDfIdbgOcjjj;8iamaPfgPcLt9R::NJbbbZJbbb:;aOJbbbb9GEMgO:lJbbb9p9DTmbaO:Ohzxekcjjjj94hzkabaDfazcFFFrGaPcKtVBdbaDclfhDascufgsmbkkabarfhbalarfhladcefgdae9hmbkkaocjdf8Kjjjjbk;TkdCui998Jjjjjbc:qd9Rgv8Kjjjjbavc:Oefcbc;Kbz:tjjjb8AcbhodnadTmbcbhoaiTmbdnabae9hmbavcuadcdtgoadcFFFFi0Ecbyd1:kjjbHjjjjbbgeBd:OeavceBd1daeabaozMjjjb8Akavc:yefcwfcbBdbav9cb83i:yeavc:yefaeadaiavc:Oefz:njjjbcuaicdtgraicFFFFi0Egwcbyd1:kjjbHjjjjbbhoavc:Oefavyd1dgDcdtfaoBdbavaDcefgqBd1daoavyd:yegkarzMjjjbhxavc:Oefaqcdtfadci9Ugmcbyd1:kjjbHjjjjbbgoBdbavaDcdfgrBd1daocbamz:tjjjbhPavc:Oefarcdtfawcbyd1:kjjbHjjjjbbgsBdbavaDcifgqBd1daxhoashrinaralIdbalaoydbgwcwawcw6Ecdtfc;ebfIdbMUdbaoclfhoarclfhraicufgimbkavc:OefaqcdtfcuamcdtadcFFFF970Ecbyd1:kjjbHjjjjbbgqBdbavaDclfBd1ddnadci6mbamceamce0EhiaehoaqhrinarasaoydbcdtfIdbasaoclfydbcdtfIdbMasaocwfydbcdtfIdbMUdbaocxfhoarclfhraicufgimbkkavc;mbfhzavhoavyd:CehHavyd:GehOcbhwcbhrcbhAcehCinaohXcihQaearci2gLcdtfgocwfydbhKaoydbhdabaAcx2fgiclfaoclfydbgDBdbaiadBdbaicwfaKBdbaParfce86bbazaKBdwazaDBdlazadBdbaqarcdtfcbBdbdnawTmbcihQaXhiindnaiydbgoadSmbaoaDSmbaoaKSmbazaQcdtfaoBdbaQcefhQkaiclfhiawcufgwmbkkaAcefhAaxadcdtfgoaoydbcufBdbaxaDcdtfgoaoydbcufBdbaxaKcdtfgoaoydbcufBdbcbhwinaOaHaeawaLfcdtfydbcdtgifydbcdtfgKhoakaifgDydbgdhidnadTmbdninaoydbarSmeaoclfhoaicufgiTmdxbkkaoadcdtaKfc98fydbBdbaDaDydbcufBdbkawcefgwci9hmbkdndndnaQTmbcuhrJbbbbhYcbhoinasazaocdtfydbcdtgifgwIdbh8AawalcbaocefgDaocs0EcdtfIdbalaxaifydbgocwaocw6Ecdtfc;ebfIdbMgEUdbdnakaifydbgwTmbaEa8A:thEaOaHaifydbcdtfhoawcdthiinaqaoydbgwcdtfgdaEadIdbMg8AUdba8AaYaYa8A9DgdEhYawaradEhraoclfhoaic98fgimbkkaDhoaDaQ9hmbkarcu9hmekaCam9pmeindnaPaCfRbbmbaChrxdkamaCcefgC9hmbxdkkaQczaQcz6EhwazhoaXhzarcu9hmekkavyd1dhokaocdtavc:Oeffc98fhrdninaoTmearydbcbyd:e:kjjbH:bjjjbbarc98fhraocufhoxbkkavc:qdf8Kjjjjbk;UlevucuaicdtgvaicFFFFi0Egocbyd1:kjjbHjjjjbbhralalyd9GgwcdtfarBdbalawcefBd9GabarBdbaocbyd1:kjjbHjjjjbbhralalyd9GgocdtfarBdbalaocefBd9GabarBdlcuadcdtadcFFFFi0Ecbyd1:kjjbHjjjjbbhralalyd9GgocdtfarBdbalaocefBd9GabarBdwabydbcbavz:tjjjb8Aadci9UhwdnadTmbabydbhoaehladhrinaoalydbcdtfgvavydbcefBdbalclfhlarcufgrmbkkdnaiTmbabydbhlabydlhrcbhvaihoinaravBdbarclfhralydbavfhvalclfhlaocufgombkkdnadci6mbawceawce0EhDabydlhrabydwhvcbhlinaecwfydbhoaeclfydbhdaraeydbcdtfgwawydbgwcefBdbavawcdtfalBdbaradcdtfgdadydbgdcefBdbavadcdtfalBdbaraocdtfgoaoydbgocefBdbavaocdtfalBdbaecxfheaDalcefgl9hmbkkdnaiTmbabydlheabydbhlinaeaeydbalydb9RBdbalclfhlaeclfheaicufgimbkkkQbabaeadaic:01jjbz:mjjjbkQbabaeadaic:C:jjjbz:mjjjbk9DeeuabcFeaicdtz:tjjjbhlcbhbdnadTmbindnalaeydbcdtfgiydbcu9hmbaiabBdbabcefhbkaeclfheadcufgdmbkkabk9teiucbcbyd:m:kjjbgeabcifc98GfgbBd:m:kjjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabk9teiucbcbyd:m:kjjbgeabcrfc94GfgbBd:m:kjjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik9:eiuZbhedndncbyd:m:kjjbgdaecztgi9nmbcuheadai9RcFFifcz4nbcuSmekadhekcbabae9Rcifc98Gcbyd:m:kjjbfgdBd:m:kjjbdnadZbcztge9nmbadae9RcFFifcz4nb8Akkk:Eddbcjwk:edb4:h9w9N94:P:gW:j9O:ye9Pbbbbbbebbbdbbbebbbdbbbbbbbdbbbbbbbebbbbbbb:l29hZ;69:9kZ;N;76Z;rg97Z;z;o9xZ8J;B85Z;:;u9yZ;b;k9HZ:2;Z9DZ9e:l9mZ59A8KZ:r;T3Z:A:zYZ79OHZ;j4::8::Y:D9V8:bbbb9s:49:Z8R:hBZ9M9M;M8:L;z;o8:;8:PG89q;x:J878R:hQ8::M:B;e87bbbbbbjZbbjZbbjZ:E;V;N8::Y:DsZ9i;H;68:xd;R8:;h0838:;W:NoZbbbb:WV9O8:uf888:9i;H;68:9c9G;L89;n;m9m89;D8Ko8:bbbbf:8tZ9m836ZS:2AZL;zPZZ818EZ9e:lxZ;U98F8:819E;68:bc:eqkxebbbdbbbaWbb\";\n\n\tvar wasmpack = new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);\n\n\tif (typeof WebAssembly !== 'object') {\n\t\treturn {\n\t\t\tsupported: false,\n\t\t};\n\t}\n\n\tvar instance;\n\n\tvar ready =\n\t\tWebAssembly.instantiate(unpack(wasm), {})\n\t\t.then(function(result) {\n\t\t\tinstance = result.instance;\n\t\t\tinstance.exports.__wasm_call_ctors();\n\t\t\tinstance.exports.meshopt_encodeVertexVersion(0);\n\t\t\tinstance.exports.meshopt_encodeIndexVersion(1);\n\t\t});\n\n\tfunction unpack(data) {\n\t\tvar result = new Uint8Array(data.length);\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tvar ch = data.charCodeAt(i);\n\t\t\tresult[i] = ch > 96 ? ch - 97 : ch > 64 ? ch - 39 : ch + 4;\n\t\t}\n\t\tvar write = 0;\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tresult[write++] = (result[i] < 60) ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];\n\t\t}\n\t\treturn result.buffer.slice(0, write);\n\t}\n\n\tfunction assert(cond) {\n\t\tif (!cond) {\n\t\t\tthrow new Error(\"Assertion failed\");\n\t\t}\n\t}\n\n\tfunction bytes(view) {\n\t\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n\t}\n\n\tfunction reorder(indices, vertices, optf) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar ip = sbrk(indices.length * 4);\n\t\tvar rp = sbrk(vertices * 4);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\tvar indices8 = bytes(indices);\n\t\theap.set(indices8, ip);\n\t\tif (optf) {\n\t\t\toptf(ip, ip, indices.length, vertices);\n\t\t}\n\t\tvar unique = instance.exports.meshopt_optimizeVertexFetchRemap(rp, ip, indices.length, vertices);\n\t\t// heap may have grown\n\t\theap = new Uint8Array(instance.exports.memory.buffer);\n\t\tvar remap = new Uint32Array(vertices);\n\t\tnew Uint8Array(remap.buffer).set(heap.subarray(rp, rp + vertices * 4));\n\t\tindices8.set(heap.subarray(ip, ip + indices.length * 4));\n\t\tsbrk(ip - sbrk(0));\n\n\t\tfor (var i = 0; i < indices.length; ++i)\n\t\t\tindices[i] = remap[indices[i]];\n\n\t\treturn [remap, unique];\n\t}\n\n\tfunction encode(fun, bound, source, count, size) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar tp = sbrk(bound);\n\t\tvar sp = sbrk(count * size);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\theap.set(bytes(source), sp);\n\t\tvar res = fun(tp, bound, sp, count, size);\n\t\tvar target = new Uint8Array(res);\n\t\ttarget.set(heap.subarray(tp, tp + res));\n\t\tsbrk(tp - sbrk(0));\n\t\treturn target;\n\t}\n\n\tfunction maxindex(source) {\n\t\tvar result = 0;\n\t\tfor (var i = 0; i < source.length; ++i) {\n\t\t\tvar index = source[i];\n\t\t\tresult = result < index ? index : result;\n\t\t}\n\t\treturn result;\n\t}\n\n\tfunction index32(source, size) {\n\t\tassert(size == 2 || size == 4);\n\t\tif (size == 4) {\n\t\t\treturn new Uint32Array(source.buffer, source.byteOffset, source.byteLength / 4);\n\t\t} else {\n\t\t\tvar view = new Uint16Array(source.buffer, source.byteOffset, source.byteLength / 2);\n\t\t\treturn new Uint32Array(view); // copies each element\n\t\t}\n\t}\n\n\tfunction filter(fun, source, count, stride, bits, insize, mode) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar tp = sbrk(count * stride);\n\t\tvar sp = sbrk(count * insize);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\theap.set(bytes(source), sp);\n\t\tfun(tp, count, stride, bits, sp, mode);\n\t\tvar target = new Uint8Array(count * stride);\n\t\ttarget.set(heap.subarray(tp, tp + count * stride));\n\t\tsbrk(tp - sbrk(0));\n\t\treturn target;\n\t}\n\n\treturn {\n\t\tready: ready,\n\t\tsupported: true,\n\t\treorderMesh: function(indices, triangles, optsize) {\n\t\t\tvar optf = triangles ? (optsize ? instance.exports.meshopt_optimizeVertexCacheStrip : instance.exports.meshopt_optimizeVertexCache) : undefined;\n\t\t\treturn reorder(indices, maxindex(indices) + 1, optf);\n\t\t},\n\t\tencodeVertexBuffer: function(source, count, size) {\n\t\t\tassert(size > 0 && size <= 256);\n\t\t\tassert(size % 4 == 0);\n\t\t\tvar bound = instance.exports.meshopt_encodeVertexBufferBound(count, size);\n\t\t\treturn encode(instance.exports.meshopt_encodeVertexBuffer, bound, source, count, size);\n\t\t},\n\t\tencodeIndexBuffer: function(source, count, size) {\n\t\t\tassert(size == 2 || size == 4);\n\t\t\tassert(count % 3 == 0);\n\t\t\tvar indices = index32(source, size);\n\t\t\tvar bound = instance.exports.meshopt_encodeIndexBufferBound(count, maxindex(indices) + 1);\n\t\t\treturn encode(instance.exports.meshopt_encodeIndexBuffer, bound, indices, count, 4);\n\t\t},\n\t\tencodeIndexSequence: function(source, count, size) {\n\t\t\tassert(size == 2 || size == 4);\n\t\t\tvar indices = index32(source, size);\n\t\t\tvar bound = instance.exports.meshopt_encodeIndexSequenceBound(count, maxindex(indices) + 1);\n\t\t\treturn encode(instance.exports.meshopt_encodeIndexSequence, bound, indices, count, 4);\n\t\t},\n\t\tencodeGltfBuffer: function(source, count, size, mode) {\n\t\t\tvar table = {\n\t\t\t\tATTRIBUTES: this.encodeVertexBuffer,\n\t\t\t\tTRIANGLES: this.encodeIndexBuffer,\n\t\t\t\tINDICES: this.encodeIndexSequence,\n\t\t\t};\n\t\t\tassert(table[mode]);\n\t\t\treturn table[mode](source, count, size);\n\t\t},\n\t\tencodeFilterOct: function(source, count, stride, bits) {\n\t\t\tassert(stride == 4 || stride == 8);\n\t\t\tassert(bits >= 1 && bits <= 16);\n\t\t\treturn filter(instance.exports.meshopt_encodeFilterOct, source, count, stride, bits, 16);\n\t\t},\n\t\tencodeFilterQuat: function(source, count, stride, bits) {\n\t\t\tassert(stride == 8);\n\t\t\tassert(bits >= 4 && bits <= 16);\n\t\t\treturn filter(instance.exports.meshopt_encodeFilterQuat, source, count, stride, bits, 16);\n\t\t},\n\t\tencodeFilterExp: function(source, count, stride, bits, mode) {\n\t\t\tassert(stride > 0 && stride % 4 == 0);\n\t\t\tassert(bits >= 1 && bits <= 24);\n\t\t\tvar table = {\n\t\t\t\tSeparate: 0,\n\t\t\t\tSharedVector: 1,\n\t\t\t\tSharedComponent: 2,\n\t\t\t};\n\t\t\treturn filter(instance.exports.meshopt_encodeFilterExp, source, count, stride, bits, stride, mode ? table[mode] : 1);\n\t\t},\n\t};\n})();\n\nexport { MeshoptEncoder };\n", "// This file is part of meshoptimizer library and is distributed under the terms of MIT License.\n// Copyright (C) 2016-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)\nvar MeshoptDecoder = (function() {\n\t\"use strict\";\n\n\t// Built with clang version 15.0.6\n\t// Built from meshoptimizer 0.19\n\tvar wasm_base = \"b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq:78Yqdbk:qzezu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhlaicefhodnadTmbalc;WFbGglcjdalcjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfglcl4cifcd4hxdndndndnalc9WGgmTmbcbhPcehsawcjdfhzaohHinaraH9Rax6midnaraHaxfgo9RcK6mbczhlinalgic9Wfglawcj;cbffhOdndndndndnaHalco4fRbbalci4coG4ciGPlbedibkaO9cb83ibaOcwf9cb83ibxikaOaoRblaoRbbgAco4glalciSgCE86bbawcj;cbfaifglcGfaoclfaCfgORbbaAcl4ciGgCaCciSgCE86bbalcVfaOaCfgORbbaAcd4ciGgCaCciSgCE86bbalc7faOaCfgORbbaAciGgAaAciSgAE86bbalctfaOaAfgARbbaoRbegOco4gCaCciSgCE86bbalc91faAaCfgARbbaOcl4ciGgCaCciSgCE86bbalc4faAaCfgARbbaOcd4ciGgCaCciSgCE86bbalc93faAaCfgARbbaOciGgOaOciSgOE86bbalc94faAaOfgARbbaoRbdgOco4gCaCciSgCE86bbalc95faAaCfgARbbaOcl4ciGgCaCciSgCE86bbalc96faAaCfgARbbaOcd4ciGgCaCciSgCE86bbalc97faAaCfgARbbaOciGgOaOciSgOE86bbalc98faAaOfgORbbaoRbigoco4gAaAciSgAE86bbalc99faOaAfgORbbaocl4ciGgAaAciSgAE86bbalc9:faOaAfgORbbaocd4ciGgAaAciSgAE86bbalcufaOaAfglRbbaociGgoaociSgoE86bbalaofhoxdkaOaoRbwaoRbbgAcl4glalcsSgCE86bbawcj;cbfaifglcGfaocwfaCfgORbbaAcsGgAaAcsSgAE86bbalcVfaOaAfgORbbaoRbegAcl4gCaCcsSgCE86bbalc7faOaCfgORbbaAcsGgAaAcsSgAE86bbalctfaOaAfgORbbaoRbdgAcl4gCaCcsSgCE86bbalc91faOaCfgORbbaAcsGgAaAcsSgAE86bbalc4faOaAfgORbbaoRbigAcl4gCaCcsSgCE86bbalc93faOaCfgORbbaAcsGgAaAcsSgAE86bbalc94faOaAfgORbbaoRblgAcl4gCaCcsSgCE86bbalc95faOaCfgORbbaAcsGgAaAcsSgAE86bbalc96faOaAfgORbbaoRbvgAcl4gCaCcsSgCE86bbalc97faOaCfgORbbaAcsGgAaAcsSgAE86bbalc98faOaAfgORbbaoRbogAcl4gCaCcsSgCE86bbalc99faOaCfgORbbaAcsGgAaAcsSgAE86bbalc9:faOaAfgORbbaoRbrgocl4gAaAcsSgAE86bbalcufaOaAfglRbbaocsGgoaocsSgoE86bbalaofhoxekaOao8Pbb83bbaOcwfaocwf8Pbb83bbaoczfhokdnaiam9pmbaiczfhlarao9RcL0mekkaiam6miaoTmidnakTmbawaPfRbbhOawcj;cbfhlazhiakhHinaialRbbgAce4cbaAceG9R7aOfgO86bbaiadfhialcefhlaHcufgHmbkkazcefhzaPcefgPad6hsaohHaPad9hmexvkkcbhoasceGmdxikaoaxad2fhPdnakTmbcbhmcehsawcjdfhCinarao9Rax6miaoTmdaoaxfhoawamfRbbhOawcj;cbfhlaChiakhHinaialRbbgAce4cbaAceG9R7aOfgO86bbaiadfhialcefhlaHcufgHmbkaCcefhCamcefgmad6hsamad9hmbkaPhoxikcbhlcehsinarao9Rax6mdaoTmeaoaxfhoalcefglad6hsadal9hmbkaPhoxdkcbhoasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqaombkc9:hoxekcbc99arao9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;xzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfalaDcu7gPcl4fcsGcitfgsydlhzasydbhHdnaDcsGgDak9pmbavaiaPfcsGcdtfydbaxaDEhsaDThDdndnadcd9hmbabarcetfgPaH87ebaPcdfaz87ebaPclfas87ebxekabarcdtfgPaHBdbaPclfazBdbaPcwfasBdbkaxaDfhxavc;abfalcitfgPasBdbaPazBdlavaicdtfasBdbavc;abfalcefcsGglcitfgPaHBdbaPasBdlaiaDfhialcefhlxdkdndnaDcsSmbamaDfaDc987fcefhmxekaocefhDao8SbbgscFeGhPdndnascu9mmbaDhoxekaocvfhoaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhokaPce4cbaPceG9R7amfhmkdndnadcd9hmbabarcetfgDaH87ebaDcdfaz87ebaDclfam87ebxekabarcdtfgDaHBdbaDclfazBdbaDcwfamBdbkavc;abfalcitfgDamBdbaDazBdlavaicdtfamBdbavc;abfalcefcsGglcitfgDaHBdbaDamBdlaicefhialcefhlxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHcdfaD87ebaHclfas87ebxekabarcdtfgHaxBdbaHclfaDBdbaHcwfasBdbkavaicdtfaxBdbavc;abfalcitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfalcefcsGcitfgHasBdbaHaDBdlavaiaPfcsGgicdtfasBdbavc;abfalcdfcsGglcitfgDaxBdbaDasBdlalcefhlaiaOfhiazaOfhxxekaxcbaoRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbaocefhDxekaocdfhDao8SbegPcFeGhsdnaPcu9kmbaocofhAascFbGhscrhodninaD8SbbgPcFbGaotasVhsaPcu9kmeaDcefhDaocrfgoc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbgocFeGhPdnaocu9kmbaDcvfhzaPcFbGhPcrhodninas8SbbgDcFbGaotaPVhPaDcu9kmeascefhsaocrfgoc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashoxekascefhoas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninao8SbbgscFbGaDtaPVhPascu9kmeaocefhoaDcrfgDc8J9hmbkaOhoxekaocefhokaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDcdfaz87ebaDclfaO87ebxekabarcdtfgDaABdbaDclfazBdbaDcwfaOBdbkavc;abfalcitfgDazBdbaDaABdlavaicdtfaABdbavc;abfalcefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfalcdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiarcifgrae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:flevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabavcefciGaiVcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabavcdfciGaiVcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabavcufciGaiVcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabavciGaiVcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2gdTmbinababydbgecwtcw91:Yaece91cjjj;8ifcjjj98G::NUdbabclfhbadcufgdmbkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb\";\n\tvar wasm_simd = \"b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;a9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;d8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincehHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAci6hHalhOaAcefgAclSmdxekkcbhlaHceGmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblbg8Acep9Ta8AaQp9op9Hp9rg8ApmbzeHdOiAlCvXoQrLgEaoamfpblbg3cep9Ta3aQp9op9Hp9rg3aoaxfpblbg5cep9Ta5aQp9op9Hp9rg5pmbzeHdOiAlCvXoQrLg8EpmbezHdiOAlvCXorQLgQaQpmbedibedibedibediaYp9UgYp9AdbbaiadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaEa8EpmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwKDYq8AkEx3m5P8Es8FgLa3a5pmwKDYq8AkEx3m5P8Es8Fg8ApmbezHdiOAlvCXorQLgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfhiaXczfgXak6mbkkazclfgzad6mbkasavcjdfaqad2;8qbbavavcjdfaqcufad2fad;8qbbaqaDfhDc9:hoalmexikkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;kbf8Kjjjjbaokwbz:bjjjbk;tzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfalaDcu7gPcl4fcsGcitfgsydlhzasydbhHdnaDcsGgDak9pmbavaiaPfcsGcdtfydbaxaDEhsaDThDdndnadcd9hmbabarcetfgPaH87ebaPcdfaz87ebaPclfas87ebxekabarcdtfgPaHBdbaPclfazBdbaPcwfasBdbkaxaDfhxavc;abfalcitfgPasBdbaPazBdlavaicdtfasBdbavc;abfalcefcsGglcitfgPaHBdbaPasBdlaiaDfhialcefhlxdkdndnaDcsSmbamaDfaDc987fcefhmxekaocefhDao8SbbgscFeGhPdndnascu9mmbaDhoxekaocvfhoaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhokaPce4cbaPceG9R7amfhmkdndnadcd9hmbabarcetfgDaH87ebaDcdfaz87ebaDclfam87ebxekabarcdtfgDaHBdbaDclfazBdbaDcwfamBdbkavc;abfalcitfgDamBdbaDazBdlavaicdtfamBdbavc;abfalcefcsGglcitfgDaHBdbaDamBdlaicefhialcefhlxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHcdfaD87ebaHclfas87ebxekabarcdtfgHaxBdbaHclfaDBdbaHcwfasBdbkavaicdtfaxBdbavc;abfalcitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfalcefcsGcitfgHasBdbaHaDBdlavaiaPfcsGgicdtfasBdbavc;abfalcdfcsGglcitfgDaxBdbaDasBdlalcefhlaiaOfhiazaOfhxxekaxcbaoRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbaocefhDxekaocdfhDao8SbegPcFeGhsdnaPcu9kmbaocofhAascFbGhscrhodninaD8SbbgPcFbGaotasVhsaPcu9kmeaDcefhDaocrfgoc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbgocFeGhPdnaocu9kmbaDcvfhzaPcFbGhPcrhodninas8SbbgDcFbGaotaPVhPaDcu9kmeascefhsaocrfgoc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashoxekascefhoas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninao8SbbgscFbGaDtaPVhPascu9kmeaocefhoaDcrfgDc8J9hmbkaOhoxekaocefhokaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDcdfaz87ebaDclfaO87ebxekabarcdtfgDaABdbaDclfazBdbaDcwfaOBdbkavc;abfalcitfgDazBdbaDaABdlavaicdtfaABdbavc;abfalcefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfalcdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiarcifgrae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:flevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaic8Etc8F91aicd47avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:wPliuo97eue978Jjjjjbca9Rhiaec98Ghldndnadcl9hmbdnalTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaipxbbbbbbbbbbbbbbbbgqpklbaiabalcdtfgdaeciGglcdtgv;8qbbdnalTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDaqp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkadaiav;8qbbskdnalTmbcbhvabhdinadczfgxaxpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgval6mbkkalae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabalcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbheabhdinadadpbbbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepkbbadczfhdaeclfgeav6mbkkdnaval9pmbaialciGgecdtgdVcbc;abad9R;8kbaiabavcdtfgvad;8qbbdnaeTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepklbkavaiad;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb\";\n\n\tvar detector = new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]);\n\tvar wasmpack = new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);\n\n\tif (typeof WebAssembly !== 'object') {\n\t\treturn {\n\t\t\tsupported: false,\n\t\t};\n\t}\n\n\tvar wasm = WebAssembly.validate(detector) ? wasm_simd : wasm_base;\n\n\tvar instance;\n\n\tvar ready =\n\t\tWebAssembly.instantiate(unpack(wasm), {})\n\t\t.then(function(result) {\n\t\t\tinstance = result.instance;\n\t\t\tinstance.exports.__wasm_call_ctors();\n\t\t});\n\n\tfunction unpack(data) {\n\t\tvar result = new Uint8Array(data.length);\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tvar ch = data.charCodeAt(i);\n\t\t\tresult[i] = ch > 96 ? ch - 97 : ch > 64 ? ch - 39 : ch + 4;\n\t\t}\n\t\tvar write = 0;\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tresult[write++] = (result[i] < 60) ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];\n\t\t}\n\t\treturn result.buffer.slice(0, write);\n\t}\n\n\tfunction decode(fun, target, count, size, source, filter) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar count4 = (count + 3) & ~3;\n\t\tvar tp = sbrk(count4 * size);\n\t\tvar sp = sbrk(source.length);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\theap.set(source, sp);\n\t\tvar res = fun(tp, count, size, sp, source.length);\n\t\tif (res == 0 && filter) {\n\t\t\tfilter(tp, count4, size);\n\t\t}\n\t\ttarget.set(heap.subarray(tp, tp + count * size));\n\t\tsbrk(tp - sbrk(0));\n\t\tif (res != 0) {\n\t\t\tthrow new Error(\"Malformed buffer data: \" + res);\n\t\t}\n\t}\n\n\tvar filters = {\n\t\tNONE: \"\",\n\t\tOCTAHEDRAL: \"meshopt_decodeFilterOct\",\n\t\tQUATERNION: \"meshopt_decodeFilterQuat\",\n\t\tEXPONENTIAL: \"meshopt_decodeFilterExp\",\n\t};\n\n\tvar decoders = {\n\t\tATTRIBUTES: \"meshopt_decodeVertexBuffer\",\n\t\tTRIANGLES: \"meshopt_decodeIndexBuffer\",\n\t\tINDICES: \"meshopt_decodeIndexSequence\",\n\t};\n\n\tvar workers = [];\n\tvar requestId = 0;\n\n\tfunction createWorker(url) {\n\t\tvar worker = {\n\t\t\tobject: new Worker(url),\n\t\t\tpending: 0,\n\t\t\trequests: {}\n\t\t};\n\n\t\tworker.object.onmessage = function(event) {\n\t\t\tvar data = event.data;\n\n\t\t\tworker.pending -= data.count;\n\t\t\tworker.requests[data.id][data.action](data.value);\n\n\t\t\tdelete worker.requests[data.id];\n\t\t};\n\n\t\treturn worker;\n\t}\n\n\tfunction initWorkers(count) {\n\t\tvar source =\n\t\t\t\"var instance; var ready = WebAssembly.instantiate(new Uint8Array([\" + new Uint8Array(unpack(wasm)) + \"]), {})\" +\n\t\t\t\".then(function(result) { instance = result.instance; instance.exports.__wasm_call_ctors(); });\" +\n\t\t\t\"self.onmessage = workerProcess;\" +\n\t\t\tdecode.toString() + workerProcess.toString();\n\n\t\tvar blob = new Blob([source], {type: 'text/javascript'});\n\t\tvar url = URL.createObjectURL(blob);\n\n\t\tfor (var i = 0; i < count; ++i) {\n\t\t\tworkers[i] = createWorker(url);\n\t\t}\n\n\t\tURL.revokeObjectURL(url);\n\t}\n\n\tfunction decodeWorker(count, size, source, mode, filter) {\n\t\tvar worker = workers[0];\n\n\t\tfor (var i = 1; i < workers.length; ++i) {\n\t\t\tif (workers[i].pending < worker.pending) {\n\t\t\t\tworker = workers[i];\n\t\t\t}\n\t\t}\n\n\t\treturn new Promise(function (resolve, reject) {\n\t\t\tvar data = new Uint8Array(source);\n\t\t\tvar id = requestId++;\n\n\t\t\tworker.pending += count;\n\t\t\tworker.requests[id] = { resolve: resolve, reject: reject };\n\t\t\tworker.object.postMessage({ id: id, count: count, size: size, source: data, mode: mode, filter: filter }, [ data.buffer ]);\n\t\t});\n\t}\n\n\tfunction workerProcess(event) {\n\t\tready.then(function() {\n\t\t\tvar data = event.data;\n\t\t\ttry {\n\t\t\t\tvar target = new Uint8Array(data.count * data.size);\n\t\t\t\tdecode(instance.exports[data.mode], target, data.count, data.size, data.source, instance.exports[data.filter]);\n\t\t\t\tself.postMessage({ id: data.id, count: data.count, action: \"resolve\", value: target }, [ target.buffer ]);\n\t\t\t} catch (error) {\n\t\t\t\tself.postMessage({ id: data.id, count: data.count, action: \"reject\", value: error });\n\t\t\t}\n\t\t});\n\t}\n\n\treturn {\n\t\tready: ready,\n\t\tsupported: true,\n\t\tuseWorkers: function(count) {\n\t\t\tinitWorkers(count);\n\t\t},\n\t\tdecodeVertexBuffer: function(target, count, size, source, filter) {\n\t\t\tdecode(instance.exports.meshopt_decodeVertexBuffer, target, count, size, source, instance.exports[filters[filter]]);\n\t\t},\n\t\tdecodeIndexBuffer: function(target, count, size, source) {\n\t\t\tdecode(instance.exports.meshopt_decodeIndexBuffer, target, count, size, source);\n\t\t},\n\t\tdecodeIndexSequence: function(target, count, size, source) {\n\t\t\tdecode(instance.exports.meshopt_decodeIndexSequence, target, count, size, source);\n\t\t},\n\t\tdecodeGltfBuffer: function(target, count, size, source, mode, filter) {\n\t\t\tdecode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]);\n\t\t},\n\t\tdecodeGltfBufferAsync: function(count, size, source, mode, filter) {\n\t\t\tif (workers.length > 0) {\n\t\t\t\treturn decodeWorker(count, size, source, decoders[mode], filters[filter]);\n\t\t\t}\n\n\t\t\treturn ready.then(function() {\n\t\t\t\tvar target = new Uint8Array(count * size);\n\t\t\t\tdecode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]);\n\t\t\t\treturn target;\n\t\t\t});\n\t\t}\n\t};\n})();\n\nexport { MeshoptDecoder };\n", "// This file is part of meshoptimizer library and is distributed under the terms of MIT License.\n// Copyright (C) 2016-2023, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)\nvar MeshoptSimplifier = (function() {\n\t\"use strict\";\n\n\t// Built with clang version 15.0.6\n\t// Built from meshoptimizer 0.19\n\tvar wasm = \"b9H79TebbbecD9Geueu9Geub9Gbb9Gquuuuuuu99uueu9Gvuuuuub9Gluuuue999Giuuue999Gluuuueu9Giuuueuimxdilvorbwwbewlve9Weiiviebeoweuecj;jekr7oo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bbz9TW79O9V9Wt9F79P9T9W29P9M95beX9TW79O9V9Wt9F79P9T9W29P9M959t9J9H2Wbla9TW79O9V9Wt9F9V9Wt9P9T9P96W9wWVtW94SWt9J9O9sW9T9H9Wbvl79IV9RboDwebcekdDqq:XJxdbkp8WiKuP99Hu8Jjjjjbcj;bb9Rgq8KjjjjbaqcKfcbc;Kbz1jjjb8AaqcualcdtgkalcFFFFi0Egxcbyd;S1jjbHjjjjbbgmBdKaqceBd94aqamBdwaqaxcbyd;S1jjbHjjjjbbgPBd3aqcdBd94aqaPBdxaqcuadcitadcFFFFe0Ecbyd;S1jjbHjjjjbbgsBdaaqciBd94aqasBdzaqcwfaeadalcbz:cjjjbaqaxcbyd;S1jjbHjjjjbbgzBd8KaqclBd94aqaxcbyd;S1jjbHjjjjbbgHBdyaqcvBd94alcd4alfhOcehAinaAgCcethAaCaO6mbkcbhXaqcuaCcdtgAaCcFFFFi0Ecbyd;S1jjbHjjjjbbgOBd8SaqcoBd94aOcFeaAz1jjjbhQdnalTmbavcd4hLaCcufhKinaiaXaL2cdtfgYydlgCcH4aC7c:F:b:DD2aYydbgCcH4aC7c;D;O:B8J27aYydwgCcH4aC7c:3F;N8N27hOcbhCdndninaQaOaKGgOcdtfg8AydbgAcuSmeaiaAaL2cdtfaYcxz:ljjjbTmdaCcefgCaOfhOaCaK9nmbxdkka8AaXBdbaXhAkazaXcdtfaABdbaXcefgXal9hmbkcbhCaHhAinaAaCBdbaAclfhAalaCcefgC9hmbkcbhCazhAaHhOindnaCaAydbgKSmbaOaHaKcdtfgKydbBdbaKaCBdbkaAclfhAaOclfhOalaCcefgC9hmbkkcbhOaqalcbyd;S1jjbHjjjjbbgYBd8WaqcrBd94aqaxcbyd;S1jjbHjjjjbbgCBd80aqcwBd94aqaxcbyd;S1jjbHjjjjbbgABdUaqcDBd94aCcFeakz1jjjbhEaAcFeakz1jjjbh3dnalTmbascwfh5indnamaOcdtgCfydbg8ETmbasaPaCfydbcitfh8Fa3aCfhaaEaCfhXcbhLindndna8FaLcitfydbgQaO9hmbaXaOBdbaaaOBdbxekdnamaQcdtgkfydbghTmbasaPakfydbcitgCfydbaOSmeahcufh8Aa5aCfhAcbhCina8AaCSmeaCcefhCaAydbhKaAcwfhAaKaO9hmbkaCah6meka3akfgCaOaQaCydbcuSEBdbaXaQaOaXydbcuSEBdbkaLcefgLa8E9hmbkkaOcefgOal9hmbkazhAaHhOa3hKaEhLcbhCindndnaCaAydbg8A9hmbdnaCaOydbg8A9hmbaLydbh8AdnaKydbgQcu9hmba8Acu9hmbaYaCfcb86bbxikaYaCfhXdnaCaQSmbaCa8ASmbaXce86bbxikaXcl86bbxdkdnaCaHa8AcdtgQfydb9hmbdnaKydbgXcuSmbaCaXSmbaLydbgkcuSmbaCakSmba3aQfydbg8EcuSmba8Ea8ASmbaEaQfydbgQcuSmbaQa8ASmbdnazaXcdtfydbazaQcdtfydb9hmbazakcdtfydbaza8Ecdtfydb9hmbaYaCfcd86bbxlkaYaCfcl86bbxikaYaCfcl86bbxdkaYaCfcl86bbxekaYaCfaYa8AfRbb86bbkaAclfhAaOclfhOaKclfhKaLclfhLalaCcefgC9hmbkawceGTmbaYhCalhAindnaCRbbce9hmbaCcl86bbkaCcefhCaAcufgAmbkkcbhLcualcx2alc;v:Q;v:Qe0Ecbyd;S1jjbHjjjjbbhmaqcKfaqyd94gCcdtfamBdbaqaCcefgABd94amaialavz:djjjb8AaqcKfaAcdtfcualc8S2gAalc;D;O;f8U0Ecbyd;S1jjbHjjjjbbgOBdbaqaCcdfBd94aOcbaAz1jjjbhsdnadTmbaehAindnamaAclfydbg8Acx2fgCIdbamaAydbgQcx2fgOIdbgg:tg8JamaAcwfydbgXcx2fgKIdlaOIdlg8K:tg8LNaKIdbag:tg8MaCIdla8K:tg8NN:tgyayNa8NaKIdwaOIdwg8P:tgINa8LaCIdwa8P:tg8NN:tg8La8LNa8Na8MNaIa8JN:tg8Ja8JNMM:rg8MJbbbb9ETmbaya8M:vhya8Ja8M:vh8Ja8La8M:vh8LkasazaQcdtfydbc8S2fgCa8La8M:rg8Ma8LNNg8NaCIdbMUdbaCa8Ja8Ma8JNg8RNgIaCIdlMUdlaCaya8MayNg8SNgRaCIdwMUdwaCa8Ra8LNg8RaCIdxMUdxaCa8Sa8LNg8UaCIdzMUdzaCa8Sa8JNg8SaCIdCMUdCaCa8La8Maya8PNa8LagNa8Ka8JNMM:mg8KNggNg8LaCIdKMUdKaCa8JagNg8JaCId3MUd3aCayagNgyaCIdaMUdaaCaga8KNggaCId8KMUd8KaCa8MaCIdyMUdyasaza8Acdtfydbc8S2fgCa8NaCIdbMUdbaCaIaCIdlMUdlaCaRaCIdwMUdwaCa8RaCIdxMUdxaCa8UaCIdzMUdzaCa8SaCIdCMUdCaCa8LaCIdKMUdKaCa8JaCId3MUd3aCayaCIdaMUdaaCagaCId8KMUd8KaCa8MaCIdyMUdyasazaXcdtfydbc8S2fgCa8NaCIdbMUdbaCaIaCIdlMUdlaCaRaCIdwMUdwaCa8RaCIdxMUdxaCa8UaCIdzMUdzaCa8SaCIdCMUdCaCa8LaCIdKMUdKaCa8JaCId3MUd3aCayaCIdaMUdaaCagaCId8KMUd8KaCa8MaCIdyMUdyaAcxfhAaLcifgLad6mbkcbh8AaehXincbhAinaYaeaAc:81jjbfydbgQa8AfcdtfydbgOfRbbhCdndnaYaXaAfydbgKfRbbgLc99fcFeGcpe0mbaCceSmbaCcd9hmekdnaLcufcFeGce0mbaEaKcdtfydbaO9hmekdnaCcufcFeGce0mba3aOcdtfydbaK9hmekdnaLcv2aCfc:G1jjbfRbbTmbazaOcdtfydbazaKcdtfydb0mekJbbacJbbjZaCceSEh8MaLceShkamaeaQcdtc:81jjbfydba8Afcdtfydbcx2fhCdnamaOcx2fgLIdwamaKcx2fgQIdwg8K:tg8La8LNaLIdbaQIdbg8P:tg8Ja8JNaLIdlaQIdlg8N:tgyayNMM:rggJbbbb9ETmba8Lag:vh8Layag:vhya8Jag:vh8JkJbbaca8MakEh8SdnaCIdwa8K:tg8Ma8La8Ma8LNaCIdba8P:tgRa8JNayaCIdla8N:tg8RNMMgIN:tg8Ma8MNaRa8JaIN:tg8La8LNa8RayaIN:tg8Ja8JNMM:rgyJbbbb9ETmba8May:vh8Ma8Jay:vh8Ja8Lay:vh8LkasazaKcdtfydbc8S2fgCa8La8SagNgya8LNNgIaCIdbMUdbaCa8Jaya8JNg8SNgRaCIdlMUdlaCa8Maya8MNggNg8RaCIdwMUdwaCa8Sa8LNg8SaCIdxMUdxaCaga8LNg8UaCIdzMUdzaCaga8JNg8VaCIdCMUdCaCa8Laya8Ma8KNa8La8PNa8Na8JNMM:mg8KNggNg8LaCIdKMUdKaCa8JagNg8JaCId3MUd3aCa8MagNg8MaCIdaMUdaaCaga8KNggaCId8KMUd8KaCayaCIdyMUdyasazaOcdtfydbc8S2fgCaIaCIdbMUdbaCaRaCIdlMUdlaCa8RaCIdwMUdwaCa8SaCIdxMUdxaCa8UaCIdzMUdzaCa8VaCIdCMUdCaCa8LaCIdKMUdKaCa8JaCId3MUd3aCa8MaCIdaMUdaaCagaCId8KMUd8KaCayaCIdyMUdykaAclfgAcx9hmbkaXcxfhXa8Acifg8Aad6mbkkdnabaeSmbabaeadcdtz:hjjjb8Akcuadcx2adc;v:Q;v:Qe0Ecbyd;S1jjbHjjjjbbhaaqcKfaqyd94gCcdtfaaBdbaqaCcefgABd94aqcKfaAcdtfcuadcdtadcFFFFi0Ecbyd;S1jjbHjjjjbbg5BdbaqaCcdfgABd94aqcKfaAcdtfaxcbyd;S1jjbHjjjjbbgiBdbaqaCcifgABd94aqcKfaAcdtfalcbyd;S1jjbHjjjjbbg8WBdbaqaCclfBd94JbbbbhRdnadao9nmbararNh8Saacwfh8Xaqydwh8Yaqydxh8Zaqydzh80JbbbbhRinaqcwfabadgPalazz:cjjjbcbhhabhXcbhkincbhCindnazaXaCfydbgOcdtgefydbgLazabaCc:81jjbfydbakfcdtfydbgAcdtfydbg8ASmbaYaAfRbbgQcv2aYaOfRbbgKfc;q1jjbfRbbg8FaKcv2aQfg8Ec;q1jjbfRbbgdVcFeGTmbdna8Ec:G1jjbfRbbTmba8AaL0mekdnaKaQ9hmbaKcufcFeGce0mbaEaefydbaA9hmekaaahcx2fgKaAaOadcFeGgLEBdlaKaOaAaLEBdbaKaLa8FGcb9hBdwahcefhhkaCclfgCcx9hmbkaXcxfhXakcifgkaP6mbkdndnahTmbaahAahh8AinaAcwfgQJbbbbJbbjZasazaAydbgOcdtfydbc8S2fgCIdyg8L:va8LJbbbb9BEaCIdwamaAclfgeydbgKcx2fgLIdwg8LNaCIdzaLIdbg8JNaCIdaMg8Ma8MMMa8LNaCIdlaLIdlg8MNaCIdCa8LNaCId3Mg8La8LMMa8MNaCIdba8JNaCIdxa8MNaCIdKMg8La8LMMa8JNaCId8KMMM:lNgyJbbbbJbbjZasazaKaOaQydbgLEgQcdtfydbc8S2fgCIdyg8L:va8LJbbbb9BEaCIdwamaOaKaLEgXcx2fgLIdwg8LNaCIdzaLIdbg8JNaCIdaMg8Ma8MMMa8LNaCIdlaLIdlg8MNaCIdCa8LNaCId3Mg8La8LMMa8MNaCIdba8JNaCIdxa8MNaCIdKMg8La8LMMa8JNaCId8KMMM:lNg8Laya8L9FgCEUdbaeaKaXaCEBdbaAaOaQaCEBdbaAcxfhAa8Acufg8Ambkaqcjefcbcj;abz1jjjb8Aa8XhCahhAinaqcjefaCydbcO4c;8ZGfgOaOydbcefBdbaCcxfhCaAcufgAmbkcbhCcbhAinaqcjefaCfgOydbhKaOaABdbaKaAfhAaCclfgCcj;ab9hmbkcbhCa8XhAinaqcjefaAydbcO4c;8ZGfgOaOydbgOcefBdba5aOcdtfaCBdbaAcxfhAahaCcefgC9hmbkaPao9RgOci9Uh81dnalTmbcbhCaihAinaAaCBdbaAclfhAalaCcefgC9hmbkkcbhBa8Wcbalz1jjjbh83aOcO9UhUa81ce4h85cbh86cbhkdninaaa5akcdtfydbcx2fgXIdwg8Ja8S9Emea86a819pmeJFFuuh8Ldna85ah9pmbaaa5a85cdtfydbcx2fIdwJbb;aZNh8Lkdna8Ja8L9ETmba86aU0mdkdna83azaXydlg87cdtg88fydbgOfg89Rbba83azaXydbgecdtg8:fydbgZfgnRbbVmbdna8YaZcdtgCfydbgKTmba80a8ZaCfydbcitfhCamaOcx2fg8Ecwfhda8EclfhxamaZcx2fg8Fcwfhva8FclfhwcbhAcehQdnindnaiaCydbcdtfydbgLaOSmbaiaCclfydbcdtfydbg8AaOSmbama8Acx2fg8AIdbamaLcx2fgLIdbg8M:tg8LawIdbaLIdlgy:tggNa8FIdba8M:tg8Ka8AIdlay:tg8JN:ta8LaxIdbay:tg8PNa8EIdba8M:tg8Na8JN:tNa8JavIdbaLIdwgy:tgINaga8AIdway:tg8MN:ta8JadIdbay:tgyNa8Pa8MN:tNa8Ma8KNaIa8LN:ta8Ma8NNaya8LN:tNMMJbbbb9DmdkaCcwfhCaAcefgAaK6hQaKaA9hmbkkaQceGTmba85cefh85xekaXcwfhKasaOc8S2fgCasaZc8S2fgAIdbaCIdbMUdbaCaAIdlaCIdlMUdlaCaAIdwaCIdwMUdwaCaAIdxaCIdxMUdxaCaAIdzaCIdzMUdzaCaAIdCaCIdCMUdCaCaAIdKaCIdKMUdKaCaAId3aCId3MUd3aCaAIdaaCIdaMUdaaCaAId8KaCId8KMUd8KaCaAIdyaCIdyMUdydndndndnaYaefgARbbc9:fPdebdkaehCinaiaCcdtgCfaOBdbaHaCfydbgCae9hmbxikkaHa88fydbhCaHa8:fydbheaia8:fa87BdbaCh87kaiaecdtfa87Bdbkance86bba89ce86bbaKIdbg8LaRaRa8L9DEhRaBcefhBcecdaARbbceSEa86fh86kakcefgkah9hmbkkaBTmbdnalTmbcbhAaEhCindnaCydbgOcuSmbdnaAaiaOcdtgKfydbgO9hmbaEaKfydbhOkaCaOBdbkaCclfhCalaAcefgA9hmbkcbhAa3hCindnaCydbgOcuSmbdnaAaiaOcdtgKfydbgO9hmba3aKfydbhOkaCaOBdbkaCclfhCalaAcefgA9hmbkkcbhdabhCcbhLindnaiaCydbcdtfydbgAaiaCclfydbcdtfydbgOSmbaAaiaCcwfydbcdtfydbgKSmbaOaKSmbabadcdtfg8AaABdba8AclfaOBdba8AcwfaKBdbadcifhdkaCcxfhCaLcifgLaP9pmdxbkkaPhdxdkadao0mbkkdnaDTmbaDaR:rUdbkaqyd94gCcdtaqcKffc98fhzdninaCTmeazydbcbyd;W1jjbH:bjjjbbazc98fhzaCcufhCxbkkaqcj;bbf8Kjjjjbadk;pleouabydbcbaicdtz1jjjb8Aadci9UhvdnadTmbabydbhodnalTmbaehradhwinaoalarydbcdtfydbcdtfgDaDydbcefBdbarclfhrawcufgwmbxdkkaehradhwinaoarydbcdtfgDaDydbcefBdbarclfhrawcufgwmbkkdnaiTmbabydbhrabydlhwcbhDaihoinawaDBdbawclfhwarydbaDfhDarclfhraocufgombkkdnadci6mbavceavce0EhqabydlhvabydwhrinaecwfydbhwaeclfydbhDaeydbhodnalTmbalawcdtfydbhwalaDcdtfydbhDalaocdtfydbhokaravaocdtfgdydbcitfaDBdbaradydbcitfawBdladadydbcefBdbaravaDcdtfgdydbcitfawBdbaradydbcitfaoBdladadydbcefBdbaravawcdtfgwydbcitfaoBdbarawydbcitfaDBdlawawydbcefBdbaecxfheaqcufgqmbkkdnaiTmbabydlhrabydbhwinararydbawydb9RBdbawclfhwarclfhraicufgimbkkk:3ldouv998Jjjjjbca9Rglczfcwfcbyd11jjbBdbalcb8Pdj1jjb83izalcwfcbydN1jjbBdbalcb8Pd:m1jjb83ibdnadTmbaicd4hvdnabTmbavcdthocbhraehwinabarcx2fgiaearav2cdtfgDIdbUdbaiaDIdlUdlaiaDIdwUdwcbhiinalczfaifgDawaifIdbgqaDIdbgkakaq9EEUdbalaifgDaqaDIdbgkakaq9DEUdbaiclfgicx9hmbkawaofhwarcefgrad9hmbxdkkavcdthrcbhwincbhiinalczfaifgDaeaifIdbgqaDIdbgkakaq9EEUdbalaifgDaqaDIdbgkakaq9DEUdbaiclfgicx9hmbkaearfheawcefgwad9hmbkkalIdbalIdzgk:tJbbbb:xgqalIdlalIdCgx:tgmamaq9DEgqalIdwalIdKgm:tgPaPaq9DEhPdnabTmbadTmbJbbbbJbbjZaP:vaPJbbbb9BEhqinabaqabIdbak:tNUdbabclfgiaqaiIdbax:tNUdbabcwfgiaqaiIdbam:tNUdbabcxfhbadcufgdmbkkaPk:Qdidui99ducbhi8Jjjjjbca9Rglczfcwfcbyd11jjbBdbalcb8Pdj1jjb83izalcwfcbydN1jjbBdbalcb8Pd:m1jjb83ibdndnaembJbbjFhvJbbjFhoJbbjFhrxekadcd4cdthwincbhdinalczfadfgDabadfIdbgoaDIdbgrarao9EEUdbaladfgDaoaDIdbgrarao9DEUdbadclfgdcx9hmbkabawfhbaicefgiae9hmbkalIdwalIdK:thralIdlalIdC:thoalIdbalIdz:thvkavJbbbb:xgvaoaoav9DEgoararao9DEk9DeeuabcFeaicdtz1jjjbhlcbhbdnadTmbindnalaeydbcdtfgiydbcu9hmbaiabBdbabcefhbkaeclfheadcufgdmbkkabk9teiucbcbyd;01jjbgeabcifc98GfgbBd;01jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabk9teiucbcbyd;01jjbgeabcrfc94GfgbBd;01jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik9:eiuZbhedndncbyd;01jjbgdaecztgi9nmbcuheadai9RcFFifcz4nbcuSmekadhekcbabae9Rcifc98Gcbyd;01jjbfgdBd;01jjbdnadZbcztge9nmbadae9RcFFifcz4nb8Akk6eiucbhidnadTmbdninabRbbglaeRbbgv9hmeaecefheabcefhbadcufgdmbxdkkalav9Rhikaikk:cedbcjwk9PFFuuFFuuFFuuFFuFFFuFFFuFbbbbbbbbeeebeebebbeeebebbbbbebebbbbbebbbdbbbbbbbbbbbbbbbeeeeebebbbbbebbbbbeebbbbbbc;Swkxebbbdbbbj9Kbb\";\n\n\tvar wasmpack = new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);\n\n\tif (typeof WebAssembly !== 'object') {\n\t\treturn {\n\t\t\tsupported: false,\n\t\t};\n\t}\n\n\tvar instance;\n\n\tvar ready =\n\t\tWebAssembly.instantiate(unpack(wasm), {})\n\t\t.then(function(result) {\n\t\t\tinstance = result.instance;\n\t\t\tinstance.exports.__wasm_call_ctors();\n\t\t});\n\n\tfunction unpack(data) {\n\t\tvar result = new Uint8Array(data.length);\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tvar ch = data.charCodeAt(i);\n\t\t\tresult[i] = ch > 96 ? ch - 97 : ch > 64 ? ch - 39 : ch + 4;\n\t\t}\n\t\tvar write = 0;\n\t\tfor (var i = 0; i < data.length; ++i) {\n\t\t\tresult[write++] = (result[i] < 60) ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];\n\t\t}\n\t\treturn result.buffer.slice(0, write);\n\t}\n\n\tfunction assert(cond) {\n\t\tif (!cond) {\n\t\t\tthrow new Error(\"Assertion failed\");\n\t\t}\n\t}\n\n\tfunction bytes(view) {\n\t\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n\t}\n\n\tfunction reorder(indices, vertices) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar ip = sbrk(indices.length * 4);\n\t\tvar rp = sbrk(vertices * 4);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\tvar indices8 = bytes(indices);\n\t\theap.set(indices8, ip);\n\t\tvar unique = instance.exports.meshopt_optimizeVertexFetchRemap(rp, ip, indices.length, vertices);\n\t\t// heap may have grown\n\t\theap = new Uint8Array(instance.exports.memory.buffer);\n\t\tvar remap = new Uint32Array(vertices);\n\t\tnew Uint8Array(remap.buffer).set(heap.subarray(rp, rp + vertices * 4));\n\t\tindices8.set(heap.subarray(ip, ip + indices.length * 4));\n\t\tsbrk(ip - sbrk(0));\n\n\t\tfor (var i = 0; i < indices.length; ++i)\n\t\t\tindices[i] = remap[indices[i]];\n\n\t\treturn [remap, unique];\n\t}\n\n\tfunction maxindex(source) {\n\t\tvar result = 0;\n\t\tfor (var i = 0; i < source.length; ++i) {\n\t\t\tvar index = source[i];\n\t\t\tresult = result < index ? index : result;\n\t\t}\n\t\treturn result;\n\t}\n\n\tfunction simplify(fun, indices, index_count, vertex_positions, vertex_count, vertex_positions_stride, target_index_count, target_error, options) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar te = sbrk(4);\n\t\tvar ti = sbrk(index_count * 4);\n\t\tvar sp = sbrk(vertex_count * vertex_positions_stride);\n\t\tvar si = sbrk(index_count * 4);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\theap.set(bytes(vertex_positions), sp);\n\t\theap.set(bytes(indices), si);\n\t\tvar result = fun(ti, si, index_count, sp, vertex_count, vertex_positions_stride, target_index_count, target_error, options, te);\n\t\t// heap may have grown\n\t\theap = new Uint8Array(instance.exports.memory.buffer);\n\t\tvar target = new Uint32Array(result);\n\t\tbytes(target).set(heap.subarray(ti, ti + result * 4));\n\t\tvar error = new Float32Array(1);\n\t\tbytes(error).set(heap.subarray(te, te + 4));\n\t\tsbrk(te - sbrk(0));\n\t\treturn [target, error[0]];\n\t}\n\n\tfunction simplifyScale(fun, vertex_positions, vertex_count, vertex_positions_stride) {\n\t\tvar sbrk = instance.exports.sbrk;\n\t\tvar sp = sbrk(vertex_count * vertex_positions_stride);\n\t\tvar heap = new Uint8Array(instance.exports.memory.buffer);\n\t\theap.set(bytes(vertex_positions), sp);\n\t\tvar result = fun(sp, vertex_count, vertex_positions_stride);\n\t\tsbrk(sp - sbrk(0));\n\t\treturn result;\n\t}\n\n\tvar simplifyOptions = {\n\t\tLockBorder: 1,\n\t};\n\n\treturn {\n\t\tready: ready,\n\t\tsupported: true,\n\n\t\tcompactMesh: function(indices) {\n\t\t\tassert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);\n\t\t\tassert(indices.length % 3 == 0);\n\n\t\t\tvar indices32 = indices.BYTES_PER_ELEMENT == 4 ? indices : new Uint32Array(indices);\n\t\t\treturn reorder(indices32, maxindex(indices) + 1);\n\t\t},\n\n\t\tsimplify: function(indices, vertex_positions, vertex_positions_stride, target_index_count, target_error, flags) {\n\t\t\tassert(indices instanceof Uint32Array || indices instanceof Int32Array || indices instanceof Uint16Array || indices instanceof Int16Array);\n\t\t\tassert(indices.length % 3 == 0);\n\t\t\tassert(vertex_positions instanceof Float32Array);\n\t\t\tassert(vertex_positions.length % vertex_positions_stride == 0);\n\t\t\tassert(vertex_positions_stride >= 3);\n\t\t\tassert(target_index_count % 3 == 0);\n\t\t\tassert(target_error >= 0 && target_error <= 1);\n\n\t\t\tvar options = 0;\n\t\t\tfor (var i = 0; i < (flags ? flags.length : 0); ++i) {\n\t\t\t\toptions |= simplifyOptions[flags[i]];\n\t\t\t}\n\n\t\t\tvar indices32 = indices.BYTES_PER_ELEMENT == 4 ? indices : new Uint32Array(indices);\n\t\t\tvar result = simplify(instance.exports.meshopt_simplify, indices32, indices.length, vertex_positions, vertex_positions.length / vertex_positions_stride, vertex_positions_stride * 4, target_index_count, target_error, options);\n\t\t\tresult[0] = (indices instanceof Uint32Array) ? result[0] : new indices.constructor(result[0]);\n\n\t\t\treturn result;\n\t\t},\n\n\t\tgetScale: function(vertex_positions, vertex_positions_stride) {\n\t\t\tassert(vertex_positions instanceof Float32Array);\n\t\t\tassert(vertex_positions.length % vertex_positions_stride == 0);\n\n\t\t\treturn simplifyScale(instance.exports.meshopt_simplifyScale, vertex_positions, vertex_positions.length / vertex_positions_stride, vertex_positions_stride * 4);\n\t\t},\n\t};\n})();\n\nexport { MeshoptSimplifier };\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport { MeshoptDecoder } from \"meshoptimizer\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads a glTF buffer view.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfBufferViewLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.bufferViewId The buffer view ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @private\n */\nfunction GltfBufferViewLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const bufferViewId = options.bufferViewId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.bufferViewId\", bufferViewId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const bufferView = gltf.bufferViews[bufferViewId];\n let bufferId = bufferView.buffer;\n let byteOffset = bufferView.byteOffset;\n let byteLength = bufferView.byteLength;\n\n let hasMeshopt = false;\n let meshoptByteStride;\n let meshoptCount;\n let meshoptMode;\n let meshoptFilter;\n\n if (hasExtension(bufferView, \"EXT_meshopt_compression\")) {\n const meshopt = bufferView.extensions.EXT_meshopt_compression;\n bufferId = meshopt.buffer;\n byteOffset = defaultValue(meshopt.byteOffset, 0);\n byteLength = meshopt.byteLength;\n\n hasMeshopt = true;\n meshoptByteStride = meshopt.byteStride;\n meshoptCount = meshopt.count;\n meshoptMode = meshopt.mode;\n meshoptFilter = defaultValue(meshopt.filter, \"NONE\");\n }\n\n const buffer = gltf.buffers[bufferId];\n\n this._hasMeshopt = hasMeshopt;\n this._meshoptByteStride = meshoptByteStride;\n this._meshoptCount = meshoptCount;\n this._meshoptMode = meshoptMode;\n this._meshoptFilter = meshoptFilter;\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._buffer = buffer;\n this._bufferId = bufferId;\n this._byteOffset = byteOffset;\n this._byteLength = byteLength;\n this._cacheKey = cacheKey;\n this._bufferLoader = undefined;\n this._typedArray = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfBufferViewLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfBufferViewLoader.prototype.constructor = GltfBufferViewLoader;\n}\n\nObject.defineProperties(GltfBufferViewLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfBufferViewLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The typed array containing buffer view data.\n *\n * @memberof GltfBufferViewLoader.prototype\n *\n * @type {Uint8Array}\n * @readonly\n * @private\n */\n typedArray: {\n get: function () {\n return this._typedArray;\n },\n },\n});\n\nasync function loadResources(loader) {\n try {\n const bufferLoader = getBufferLoader(loader);\n loader._bufferLoader = bufferLoader;\n await bufferLoader.load();\n\n if (loader.isDestroyed()) {\n return;\n }\n\n const bufferTypedArray = bufferLoader.typedArray;\n const bufferViewTypedArray = new Uint8Array(\n bufferTypedArray.buffer,\n bufferTypedArray.byteOffset + loader._byteOffset,\n loader._byteLength\n );\n\n // Unload the buffer\n loader.unload();\n\n loader._typedArray = bufferViewTypedArray;\n if (loader._hasMeshopt) {\n const count = loader._meshoptCount;\n const byteStride = loader._meshoptByteStride;\n const result = new Uint8Array(count * byteStride);\n MeshoptDecoder.decodeGltfBuffer(\n result,\n count,\n byteStride,\n loader._typedArray,\n loader._meshoptMode,\n loader._meshoptFilter\n );\n loader._typedArray = result;\n }\n\n loader._state = ResourceLoaderState.READY;\n return loader;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n loader.unload();\n loader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load buffer view\";\n throw loader.getError(errorMessage, error);\n }\n}\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfBufferViewLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._state = ResourceLoaderState.LOADING;\n this._promise = loadResources(this);\n return this._promise;\n};\n\nfunction getBufferLoader(bufferViewLoader) {\n const resourceCache = bufferViewLoader._resourceCache;\n const buffer = bufferViewLoader._buffer;\n if (defined(buffer.uri)) {\n const baseResource = bufferViewLoader._baseResource;\n const resource = baseResource.getDerivedResource({\n url: buffer.uri,\n });\n return resourceCache.getExternalBufferLoader({\n resource: resource,\n });\n }\n return resourceCache.getEmbeddedBufferLoader({\n parentResource: bufferViewLoader._gltfResource,\n bufferId: bufferViewLoader._bufferId,\n });\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfBufferViewLoader.prototype.unload = function () {\n if (defined(this._bufferLoader) && !this._bufferLoader.isDestroyed()) {\n this._resourceCache.unload(this._bufferLoader);\n }\n\n this._bufferLoader = undefined;\n this._typedArray = undefined;\n};\n\nexport default GltfBufferViewLoader;\n", "import defined from \"../Core/defined.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\n\n/**\n * @private\n */\nfunction DracoLoader() {}\n\n// Maximum concurrency to use when decoding draco models\nDracoLoader._maxDecodingConcurrency = Math.max(\n FeatureDetection.hardwareConcurrency - 1,\n 1\n);\n\n// Exposed for testing purposes\nDracoLoader._decoderTaskProcessor = undefined;\nDracoLoader._taskProcessorReady = false;\nDracoLoader._getDecoderTaskProcessor = function () {\n if (!defined(DracoLoader._decoderTaskProcessor)) {\n const processor = new TaskProcessor(\n \"decodeDraco\",\n DracoLoader._maxDecodingConcurrency\n );\n processor\n .initWebAssemblyModule({\n modulePath: \"ThirdParty/Workers/draco_decoder_nodejs.js\",\n wasmBinaryFile: \"ThirdParty/draco_decoder.wasm\",\n })\n .then(function () {\n DracoLoader._taskProcessorReady = true;\n });\n DracoLoader._decoderTaskProcessor = processor;\n }\n\n return DracoLoader._decoderTaskProcessor;\n};\n\n/**\n * Decodes a compressed point cloud. Returns undefined if the task cannot be scheduled.\n * @private\n */\nDracoLoader.decodePointCloud = function (parameters) {\n const decoderTaskProcessor = DracoLoader._getDecoderTaskProcessor();\n if (!DracoLoader._taskProcessorReady) {\n // The task processor is not ready to schedule tasks\n return;\n }\n return decoderTaskProcessor.scheduleTask(parameters, [\n parameters.buffer.buffer,\n ]);\n};\n\n/**\n * Decodes a buffer view. Returns undefined if the task cannot be scheduled.\n *\n * @param {object} options Object with the following properties:\n * @param {Uint8Array} options.array The typed array containing the buffer view data.\n * @param {object} options.bufferView The glTF buffer view object.\n * @param {Object} options.compressedAttributes The compressed attributes.\n * @param {boolean} options.dequantizeInShader Whether POSITION and NORMAL attributes should be dequantized on the GPU.\n *\n * @returns {Promise} A promise that resolves to the decoded indices and attributes.\n * @private\n */\nDracoLoader.decodeBufferView = function (options) {\n const decoderTaskProcessor = DracoLoader._getDecoderTaskProcessor();\n if (!DracoLoader._taskProcessorReady) {\n // The task processor is not ready to schedule tasks\n return;\n }\n\n return decoderTaskProcessor.scheduleTask(options, [options.array.buffer]);\n};\n\nexport default DracoLoader;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DracoLoader from \"./DracoLoader.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Load a draco buffer from a glTF.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfDracoLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.draco The Draco extension object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @private\n */\nfunction GltfDracoLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const draco = options.draco;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._gltf = gltf;\n this._draco = draco;\n this._cacheKey = cacheKey;\n this._bufferViewLoader = undefined;\n this._bufferViewTypedArray = undefined;\n this._decodePromise = undefined;\n this._decodedData = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n this._dracoError = undefined;\n}\n\nif (defined(Object.create)) {\n GltfDracoLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfDracoLoader.prototype.constructor = GltfDracoLoader;\n}\n\nObject.defineProperties(GltfDracoLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfDracoLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The decoded data.\n *\n * @memberof GltfDracoLoader.prototype\n *\n * @type {object}\n * @readonly\n * @private\n */\n decodedData: {\n get: function () {\n return this._decodedData;\n },\n },\n});\n\nasync function loadResources(loader) {\n const resourceCache = loader._resourceCache;\n try {\n const bufferViewLoader = resourceCache.getBufferViewLoader({\n gltf: loader._gltf,\n bufferViewId: loader._draco.bufferView,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n });\n loader._bufferViewLoader = bufferViewLoader;\n await bufferViewLoader.load();\n\n if (loader.isDestroyed()) {\n return;\n }\n\n loader._bufferViewTypedArray = bufferViewLoader.typedArray;\n loader._state = ResourceLoaderState.PROCESSING;\n return loader;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n handleError(loader, error);\n }\n}\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfDracoLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._state = ResourceLoaderState.LOADING;\n this._promise = loadResources(this);\n return this._promise;\n};\n\nfunction handleError(dracoLoader, error) {\n dracoLoader.unload();\n dracoLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load Draco\";\n throw dracoLoader.getError(errorMessage, error);\n}\n\nasync function processDecode(loader, decodePromise) {\n try {\n const results = await decodePromise;\n if (loader.isDestroyed()) {\n return;\n }\n\n // Unload everything except the decoded data\n loader.unload();\n\n loader._decodedData = {\n indices: results.indexArray,\n vertexAttributes: results.attributeData,\n };\n loader._state = ResourceLoaderState.READY;\n return loader._baseResource;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n // Capture this error so it can be thrown on the next `process` call\n loader._dracoError = error;\n }\n}\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGltfDracoLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (this._state !== ResourceLoaderState.PROCESSING) {\n return false;\n }\n\n if (defined(this._dracoError)) {\n handleError(this, this._dracoError);\n }\n\n if (!defined(this._bufferViewTypedArray)) {\n // Not ready to decode the Draco buffer\n return false;\n }\n\n if (defined(this._decodePromise)) {\n // Currently decoding\n return false;\n }\n\n const draco = this._draco;\n const gltf = this._gltf;\n const bufferViews = gltf.bufferViews;\n const bufferViewId = draco.bufferView;\n const bufferView = bufferViews[bufferViewId];\n const compressedAttributes = draco.attributes;\n\n const decodeOptions = {\n // Need to make a copy of the typed array otherwise the underlying\n // ArrayBuffer may be accessed on both the worker and the main thread. This\n // leads to errors such as \"ArrayBuffer at index 0 is already detached\".\n // PERFORMANCE_IDEA: Look into SharedArrayBuffer to get around this.\n array: new Uint8Array(this._bufferViewTypedArray),\n bufferView: bufferView,\n compressedAttributes: compressedAttributes,\n dequantizeInShader: true,\n };\n\n const decodePromise = DracoLoader.decodeBufferView(decodeOptions);\n\n if (!defined(decodePromise)) {\n // Cannot schedule task this frame\n return false;\n }\n\n this._decodePromise = processDecode(this, decodePromise);\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfDracoLoader.prototype.unload = function () {\n if (defined(this._bufferViewLoader)) {\n this._resourceCache.unload(this._bufferViewLoader);\n }\n\n this._bufferViewLoader = undefined;\n this._bufferViewTypedArray = undefined;\n this._decodedData = undefined;\n this._gltf = undefined;\n};\n\nexport default GltfDracoLoader;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Resource from \"./Resource.js\";\n\n/**\n * @private\n */\nfunction loadImageFromTypedArray(options) {\n const uint8Array = options.uint8Array;\n const format = options.format;\n const request = options.request;\n const flipY = defaultValue(options.flipY, false);\n const skipColorSpaceConversion = defaultValue(\n options.skipColorSpaceConversion,\n false\n );\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"uint8Array\", uint8Array);\n Check.typeOf.string(\"format\", format);\n //>>includeEnd('debug');\n\n const blob = new Blob([uint8Array], {\n type: format,\n });\n\n let blobUrl;\n return Resource.supportsImageBitmapOptions()\n .then(function (result) {\n if (result) {\n return Promise.resolve(\n Resource.createImageBitmapFromBlob(blob, {\n flipY: flipY,\n premultiplyAlpha: false,\n skipColorSpaceConversion: skipColorSpaceConversion,\n })\n );\n }\n\n blobUrl = window.URL.createObjectURL(blob);\n const resource = new Resource({\n url: blobUrl,\n request: request,\n });\n\n return resource.fetchImage({\n flipY: flipY,\n skipColorSpaceConversion: skipColorSpaceConversion,\n });\n })\n .then(function (result) {\n if (defined(blobUrl)) {\n window.URL.revokeObjectURL(blobUrl);\n }\n return result;\n })\n .catch(function (error) {\n if (defined(blobUrl)) {\n window.URL.revokeObjectURL(blobUrl);\n }\n return Promise.reject(error);\n });\n}\nexport default loadImageFromTypedArray;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport loadImageFromTypedArray from \"../Core/loadImageFromTypedArray.js\";\nimport loadKTX2 from \"../Core/loadKTX2.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads a glTF image.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfImageLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.imageId The image ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @private\n */\nfunction GltfImageLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const imageId = options.imageId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.imageId\", imageId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const image = gltf.images[imageId];\n const bufferViewId = image.bufferView;\n const uri = image.uri;\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._gltf = gltf;\n this._bufferViewId = bufferViewId;\n this._uri = uri;\n this._cacheKey = cacheKey;\n this._bufferViewLoader = undefined;\n this._image = undefined;\n this._mipLevels = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfImageLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfImageLoader.prototype.constructor = GltfImageLoader;\n}\n\nObject.defineProperties(GltfImageLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfImageLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The image.\n *\n * @memberof GltfImageLoader.prototype\n *\n * @type {Image|ImageBitmap|CompressedTextureBuffer}\n * @readonly\n * @private\n */\n image: {\n get: function () {\n return this._image;\n },\n },\n /**\n * The mip levels. Only defined for KTX2 files containing mip levels.\n *\n * @memberof GltfImageLoader.prototype\n *\n * @type {Uint8Array[]}\n * @readonly\n * @private\n */\n mipLevels: {\n get: function () {\n return this._mipLevels;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfImageLoader.prototype.load = function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n if (defined(this._bufferViewId)) {\n this._promise = loadFromBufferView(this);\n return this._promise;\n }\n\n this._promise = loadFromUri(this);\n return this._promise;\n};\n\nfunction getImageAndMipLevels(image) {\n // Images transcoded from KTX2 can contain multiple mip levels:\n // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu\n let mipLevels;\n if (Array.isArray(image)) {\n // highest detail mip should be level 0\n mipLevels = image.slice(1, image.length).map(function (mipLevel) {\n return mipLevel.bufferView;\n });\n image = image[0];\n }\n return {\n image: image,\n mipLevels: mipLevels,\n };\n}\n\nasync function loadFromBufferView(imageLoader) {\n imageLoader._state = ResourceLoaderState.LOADING;\n const resourceCache = imageLoader._resourceCache;\n try {\n const bufferViewLoader = resourceCache.getBufferViewLoader({\n gltf: imageLoader._gltf,\n bufferViewId: imageLoader._bufferViewId,\n gltfResource: imageLoader._gltfResource,\n baseResource: imageLoader._baseResource,\n });\n imageLoader._bufferViewLoader = bufferViewLoader;\n await bufferViewLoader.load();\n\n if (imageLoader.isDestroyed()) {\n return;\n }\n\n const typedArray = bufferViewLoader.typedArray;\n const image = await loadImageFromBufferTypedArray(typedArray);\n if (imageLoader.isDestroyed()) {\n return;\n }\n\n const imageAndMipLevels = getImageAndMipLevels(image);\n\n // Unload everything except the image\n imageLoader.unload();\n\n imageLoader._image = imageAndMipLevels.image;\n imageLoader._mipLevels = imageAndMipLevels.mipLevels;\n imageLoader._state = ResourceLoaderState.READY;\n\n return imageLoader;\n } catch (error) {\n if (imageLoader.isDestroyed()) {\n return;\n }\n\n return handleError(imageLoader, error, \"Failed to load embedded image\");\n }\n}\n\nasync function loadFromUri(imageLoader) {\n imageLoader._state = ResourceLoaderState.LOADING;\n const baseResource = imageLoader._baseResource;\n const uri = imageLoader._uri;\n const resource = baseResource.getDerivedResource({\n url: uri,\n });\n\n try {\n const image = await loadImageFromUri(resource);\n if (imageLoader.isDestroyed()) {\n return;\n }\n\n const imageAndMipLevels = getImageAndMipLevels(image);\n\n // Unload everything except the image\n imageLoader.unload();\n\n imageLoader._image = imageAndMipLevels.image;\n imageLoader._mipLevels = imageAndMipLevels.mipLevels;\n imageLoader._state = ResourceLoaderState.READY;\n\n return imageLoader;\n } catch (error) {\n if (imageLoader.isDestroyed()) {\n return;\n }\n return handleError(imageLoader, error, `Failed to load image: ${uri}`);\n }\n}\n\nfunction handleError(imageLoader, error, errorMessage) {\n imageLoader.unload();\n imageLoader._state = ResourceLoaderState.FAILED;\n return Promise.reject(imageLoader.getError(errorMessage, error));\n}\n\nfunction getMimeTypeFromTypedArray(typedArray) {\n const header = typedArray.subarray(0, 2);\n const webpHeaderRIFFChars = typedArray.subarray(0, 4);\n const webpHeaderWEBPChars = typedArray.subarray(8, 12);\n\n if (header[0] === 0xff && header[1] === 0xd8) {\n // See https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format\n return \"image/jpeg\";\n } else if (header[0] === 0x89 && header[1] === 0x50) {\n // See http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html\n return \"image/png\";\n } else if (header[0] === 0xab && header[1] === 0x4b) {\n // See http://github.khronos.org/KTX-Specification/#_identifier\n return \"image/ktx2\";\n } else if (\n // See https://developers.google.com/speed/webp/docs/riff_container#webp_file_header\n webpHeaderRIFFChars[0] === 0x52 &&\n webpHeaderRIFFChars[1] === 0x49 &&\n webpHeaderRIFFChars[2] === 0x46 &&\n webpHeaderRIFFChars[3] === 0x46 &&\n webpHeaderWEBPChars[0] === 0x57 &&\n webpHeaderWEBPChars[1] === 0x45 &&\n webpHeaderWEBPChars[2] === 0x42 &&\n webpHeaderWEBPChars[3] === 0x50\n ) {\n return \"image/webp\";\n }\n\n throw new RuntimeError(\"Image format is not recognized\");\n}\n\nasync function loadImageFromBufferTypedArray(typedArray) {\n const mimeType = getMimeTypeFromTypedArray(typedArray);\n if (mimeType === \"image/ktx2\") {\n // Need to make a copy of the embedded KTX2 buffer otherwise the underlying\n // ArrayBuffer may be accessed on both the worker and the main thread and\n // throw an error like \"Cannot perform Construct on a detached ArrayBuffer\".\n // Look into SharedArrayBuffer at some point to get around this.\n const ktxBuffer = new Uint8Array(typedArray);\n\n // Resolves to a CompressedTextureBuffer\n return loadKTX2(ktxBuffer);\n }\n // Resolves to an Image or ImageBitmap\n return GltfImageLoader._loadImageFromTypedArray({\n uint8Array: typedArray,\n format: mimeType,\n flipY: false,\n skipColorSpaceConversion: true,\n });\n}\n\nconst ktx2Regex = /(^data:image\\/ktx2)|(\\.ktx2$)/i;\n\nfunction loadImageFromUri(resource) {\n const uri = resource.getUrlComponent(false, true);\n if (ktx2Regex.test(uri)) {\n // Resolves to a CompressedTextureBuffer\n return loadKTX2(resource);\n }\n // Resolves to an ImageBitmap or Image\n return resource.fetchImage({\n skipColorSpaceConversion: true,\n preferImageBitmap: true,\n });\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfImageLoader.prototype.unload = function () {\n if (\n defined(this._bufferViewLoader) &&\n !this._bufferViewLoader.isDestroyed()\n ) {\n this._resourceCache.unload(this._bufferViewLoader);\n }\n\n this._bufferViewLoader = undefined;\n this._uri = undefined; // Free in case the uri is a data uri\n this._image = undefined;\n this._mipLevels = undefined;\n this._gltf = undefined;\n};\n\n// Exposed for testing\nGltfImageLoader._loadImageFromTypedArray = loadImageFromTypedArray;\n\nexport default GltfImageLoader;\n", "/**\n * @private\n */\nconst JobType = {\n TEXTURE: 0,\n PROGRAM: 1,\n BUFFER: 2,\n NUMBER_OF_JOB_TYPES: 3,\n};\nexport default Object.freeze(JobType);\n", "import Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport JobType from \"./JobType.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads an index buffer from a glTF accessor.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfIndexBufferLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.accessorId The accessor ID corresponding to the index buffer.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {object} [options.draco] The Draco extension object.\n * @param {string} [options.cacheKey] The cache key of the resource.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.loadBuffer=false] Load the index buffer as a GPU index buffer.\n * @param {boolean} [options.loadTypedArray=false] Load the index buffer as a typed array.\n * @private\n */\nfunction GltfIndexBufferLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const accessorId = options.accessorId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const draco = options.draco;\n const cacheKey = options.cacheKey;\n const asynchronous = defaultValue(options.asynchronous, true);\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.accessorId\", accessorId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n //>>includeEnd('debug');\n\n const indexDatatype = gltf.accessors[accessorId].componentType;\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._gltf = gltf;\n this._accessorId = accessorId;\n this._indexDatatype = indexDatatype;\n this._draco = draco;\n this._cacheKey = cacheKey;\n this._asynchronous = asynchronous;\n this._loadBuffer = loadBuffer;\n this._loadTypedArray = loadTypedArray;\n this._bufferViewLoader = undefined;\n this._dracoLoader = undefined;\n this._typedArray = undefined;\n this._buffer = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfIndexBufferLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfIndexBufferLoader.prototype.constructor = GltfIndexBufferLoader;\n}\n\nObject.defineProperties(GltfIndexBufferLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfIndexBufferLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The index buffer. This is only defined when loadBuffer is true.\n *\n * @memberof GltfIndexBufferLoader.prototype\n *\n * @type {Buffer}\n * @readonly\n * @private\n */\n buffer: {\n get: function () {\n return this._buffer;\n },\n },\n /**\n * The typed array containing indices. This is only defined when loadTypedArray is true.\n *\n * @memberof GltfIndexBufferLoader.prototype\n *\n * @type {Uint8Array|Uint16Array|Uint32Array}\n * @readonly\n * @private\n */\n typedArray: {\n get: function () {\n return this._typedArray;\n },\n },\n\n /**\n * The index datatype after decode.\n *\n * @memberof GltfIndexBufferLoader.prototype\n *\n * @type {IndexDatatype}\n * @readonly\n * @private\n */\n indexDatatype: {\n get: function () {\n return this._indexDatatype;\n },\n },\n});\n\nconst scratchIndexBufferJob = new CreateIndexBufferJob();\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfIndexBufferLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n if (defined(this._draco)) {\n this._promise = loadFromDraco(this);\n return this._promise;\n }\n\n this._promise = loadFromBufferView(this);\n return this._promise;\n};\n\nasync function loadFromDraco(indexBufferLoader) {\n indexBufferLoader._state = ResourceLoaderState.LOADING;\n const resourceCache = indexBufferLoader._resourceCache;\n\n try {\n const dracoLoader = resourceCache.getDracoLoader({\n gltf: indexBufferLoader._gltf,\n draco: indexBufferLoader._draco,\n gltfResource: indexBufferLoader._gltfResource,\n baseResource: indexBufferLoader._baseResource,\n });\n indexBufferLoader._dracoLoader = dracoLoader;\n await dracoLoader.load();\n\n if (indexBufferLoader.isDestroyed()) {\n return;\n }\n\n // Now wait for process() to run to finish loading\n indexBufferLoader._state = ResourceLoaderState.LOADED;\n return indexBufferLoader;\n } catch (error) {\n if (indexBufferLoader.isDestroyed()) {\n return;\n }\n\n handleError(indexBufferLoader, error);\n }\n}\n\nasync function loadFromBufferView(indexBufferLoader) {\n const gltf = indexBufferLoader._gltf;\n const accessorId = indexBufferLoader._accessorId;\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n\n indexBufferLoader._state = ResourceLoaderState.LOADING;\n const resourceCache = indexBufferLoader._resourceCache;\n try {\n const bufferViewLoader = resourceCache.getBufferViewLoader({\n gltf: gltf,\n bufferViewId: bufferViewId,\n gltfResource: indexBufferLoader._gltfResource,\n baseResource: indexBufferLoader._baseResource,\n });\n indexBufferLoader._bufferViewLoader = bufferViewLoader;\n\n await bufferViewLoader.load();\n if (indexBufferLoader.isDestroyed()) {\n return;\n }\n\n const bufferViewTypedArray = bufferViewLoader.typedArray;\n indexBufferLoader._typedArray = createIndicesTypedArray(\n indexBufferLoader,\n bufferViewTypedArray\n );\n indexBufferLoader._state = ResourceLoaderState.PROCESSING;\n return indexBufferLoader;\n } catch (error) {\n if (indexBufferLoader.isDestroyed()) {\n return;\n }\n\n handleError(indexBufferLoader, error);\n }\n}\n\nfunction createIndicesTypedArray(indexBufferLoader, bufferViewTypedArray) {\n const gltf = indexBufferLoader._gltf;\n const accessorId = indexBufferLoader._accessorId;\n const accessor = gltf.accessors[accessorId];\n const count = accessor.count;\n const indexDatatype = accessor.componentType;\n const indexSize = IndexDatatype.getSizeInBytes(indexDatatype);\n\n let arrayBuffer = bufferViewTypedArray.buffer;\n let byteOffset = bufferViewTypedArray.byteOffset + accessor.byteOffset;\n\n if (byteOffset % indexSize !== 0) {\n const byteLength = count * indexSize;\n const view = new Uint8Array(arrayBuffer, byteOffset, byteLength);\n const copy = new Uint8Array(view);\n arrayBuffer = copy.buffer;\n byteOffset = 0;\n deprecationWarning(\n \"index-buffer-unaligned\",\n `The index array is not aligned to a ${indexSize}-byte boundary.`\n );\n }\n\n let typedArray;\n if (indexDatatype === IndexDatatype.UNSIGNED_BYTE) {\n typedArray = new Uint8Array(arrayBuffer, byteOffset, count);\n } else if (indexDatatype === IndexDatatype.UNSIGNED_SHORT) {\n typedArray = new Uint16Array(arrayBuffer, byteOffset, count);\n } else if (indexDatatype === IndexDatatype.UNSIGNED_INT) {\n typedArray = new Uint32Array(arrayBuffer, byteOffset, count);\n }\n\n return typedArray;\n}\n\nfunction handleError(indexBufferLoader, error) {\n indexBufferLoader.unload();\n indexBufferLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load index buffer\";\n throw indexBufferLoader.getError(errorMessage, error);\n}\n\nfunction CreateIndexBufferJob() {\n this.typedArray = undefined;\n this.indexDatatype = undefined;\n this.context = undefined;\n this.buffer = undefined;\n}\n\nCreateIndexBufferJob.prototype.set = function (\n typedArray,\n indexDatatype,\n context\n) {\n this.typedArray = typedArray;\n this.indexDatatype = indexDatatype;\n this.context = context;\n};\n\nCreateIndexBufferJob.prototype.execute = function () {\n this.buffer = createIndexBuffer(\n this.typedArray,\n this.indexDatatype,\n this.context\n );\n};\n\nfunction createIndexBuffer(typedArray, indexDatatype, context) {\n const buffer = Buffer.createIndexBuffer({\n typedArray: typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: indexDatatype,\n });\n buffer.vertexArrayDestroyable = false;\n return buffer;\n}\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGltfIndexBufferLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (\n this._state !== ResourceLoaderState.LOADED &&\n this._state !== ResourceLoaderState.PROCESSING\n ) {\n return false;\n }\n\n let typedArray = this._typedArray;\n let indexDatatype = this._indexDatatype;\n\n if (defined(this._dracoLoader)) {\n try {\n const ready = this._dracoLoader.process(frameState);\n if (ready) {\n const dracoLoader = this._dracoLoader;\n typedArray = dracoLoader.decodedData.indices.typedArray;\n this._typedArray = typedArray;\n // The index datatype may be a smaller datatype after draco decode\n indexDatatype = ComponentDatatype.fromTypedArray(typedArray);\n this._indexDatatype = indexDatatype;\n }\n } catch (error) {\n handleError(this, error);\n }\n }\n\n if (!defined(typedArray)) {\n // Buffer view hasn't been loaded yet\n return false;\n }\n\n let buffer;\n if (this._loadBuffer && this._asynchronous) {\n const indexBufferJob = scratchIndexBufferJob;\n indexBufferJob.set(typedArray, indexDatatype, frameState.context);\n const jobScheduler = frameState.jobScheduler;\n if (!jobScheduler.execute(indexBufferJob, JobType.BUFFER)) {\n // Job scheduler is full. Try again next frame.\n return false;\n }\n buffer = indexBufferJob.buffer;\n } else if (this._loadBuffer) {\n buffer = createIndexBuffer(typedArray, indexDatatype, frameState.context);\n }\n\n // Unload everything except the index buffer and/or typed array.\n this.unload();\n\n this._buffer = buffer;\n this._typedArray = this._loadTypedArray ? typedArray : undefined;\n this._state = ResourceLoaderState.READY;\n\n this._resourceCache.statistics.addGeometryLoader(this);\n return true;\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfIndexBufferLoader.prototype.unload = function () {\n if (defined(this._buffer)) {\n this._buffer.destroy();\n }\n\n const resourceCache = this._resourceCache;\n\n if (\n defined(this._bufferViewLoader) &&\n !this._bufferViewLoader.isDestroyed()\n ) {\n resourceCache.unload(this._bufferViewLoader);\n }\n\n if (defined(this._dracoLoader)) {\n resourceCache.unload(this._dracoLoader);\n }\n\n this._bufferViewLoader = undefined;\n this._dracoLoader = undefined;\n this._typedArray = undefined;\n this._buffer = undefined;\n this._gltf = undefined;\n};\n\nexport default GltfIndexBufferLoader;\n", "import defaultValue from \"../../Core/defaultValue.js\";\n\n/**\n * Adds an element to an array and returns the element's index.\n *\n * @param {Array} array The array to add to.\n * @param {object} element The element to add.\n * @param {boolean} [checkDuplicates=false] When true, if a duplicate element is found its index is returned and element is not added to the array.\n *\n * @private\n */\nfunction addToArray(array, element, checkDuplicates) {\n checkDuplicates = defaultValue(checkDuplicates, false);\n if (checkDuplicates) {\n const index = array.indexOf(element);\n if (index > -1) {\n return index;\n }\n }\n\n array.push(element);\n return array.length - 1;\n}\n\nexport default addToArray;\n", "import defined from \"../../Core/defined.js\";\n\n/**\n * Checks whether the glTF uses the given extension.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The name of the extension.\n * @returns {boolean} Whether the glTF uses the given extension.\n *\n * @private\n */\nfunction usesExtension(gltf, extension) {\n return (\n defined(gltf.extensionsUsed) && gltf.extensionsUsed.indexOf(extension) >= 0\n );\n}\n\nexport default usesExtension;\n", "import usesExtension from \"./usesExtension.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Contains traversal functions for processing elements of the glTF hierarchy.\n * @constructor\n *\n * @private\n */\nfunction ForEach() {}\n\n/**\n * Fallback for glTF 1.0\n * @private\n */\nForEach.objectLegacy = function (objects, handler) {\n if (defined(objects)) {\n for (const objectId in objects) {\n if (Object.prototype.hasOwnProperty.call(objects, objectId)) {\n const object = objects[objectId];\n const value = handler(object, objectId);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n }\n};\n\n/**\n * @private\n */\nForEach.object = function (arrayOfObjects, handler) {\n if (defined(arrayOfObjects)) {\n const length = arrayOfObjects.length;\n for (let i = 0; i < length; i++) {\n const object = arrayOfObjects[i];\n const value = handler(object, i);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\n/**\n * Supports glTF 1.0 and 2.0\n * @private\n */\nForEach.topLevel = function (gltf, name, handler) {\n const gltfProperty = gltf[name];\n if (defined(gltfProperty) && !Array.isArray(gltfProperty)) {\n return ForEach.objectLegacy(gltfProperty, handler);\n }\n\n return ForEach.object(gltfProperty, handler);\n};\n\nForEach.accessor = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"accessors\", handler);\n};\n\nForEach.accessorWithSemantic = function (gltf, semantic, handler) {\n const visited = {};\n return ForEach.mesh(gltf, function (mesh) {\n return ForEach.meshPrimitive(mesh, function (primitive) {\n const valueForEach = ForEach.meshPrimitiveAttribute(\n primitive,\n function (accessorId, attributeSemantic) {\n if (\n attributeSemantic.indexOf(semantic) === 0 &&\n !defined(visited[accessorId])\n ) {\n visited[accessorId] = true;\n const value = handler(accessorId);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n );\n\n if (defined(valueForEach)) {\n return valueForEach;\n }\n\n return ForEach.meshPrimitiveTarget(primitive, function (target) {\n return ForEach.meshPrimitiveTargetAttribute(\n target,\n function (accessorId, attributeSemantic) {\n if (\n attributeSemantic.indexOf(semantic) === 0 &&\n !defined(visited[accessorId])\n ) {\n visited[accessorId] = true;\n const value = handler(accessorId);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n );\n });\n });\n });\n};\n\nForEach.accessorContainingVertexAttributeData = function (gltf, handler) {\n const visited = {};\n return ForEach.mesh(gltf, function (mesh) {\n return ForEach.meshPrimitive(mesh, function (primitive) {\n const valueForEach = ForEach.meshPrimitiveAttribute(\n primitive,\n function (accessorId) {\n if (!defined(visited[accessorId])) {\n visited[accessorId] = true;\n const value = handler(accessorId);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n );\n\n if (defined(valueForEach)) {\n return valueForEach;\n }\n\n return ForEach.meshPrimitiveTarget(primitive, function (target) {\n return ForEach.meshPrimitiveTargetAttribute(\n target,\n function (accessorId) {\n if (!defined(visited[accessorId])) {\n visited[accessorId] = true;\n const value = handler(accessorId);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n );\n });\n });\n });\n};\n\nForEach.accessorContainingIndexData = function (gltf, handler) {\n const visited = {};\n return ForEach.mesh(gltf, function (mesh) {\n return ForEach.meshPrimitive(mesh, function (primitive) {\n const indices = primitive.indices;\n if (defined(indices) && !defined(visited[indices])) {\n visited[indices] = true;\n const value = handler(indices);\n\n if (defined(value)) {\n return value;\n }\n }\n });\n });\n};\n\nForEach.animation = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"animations\", handler);\n};\n\nForEach.animationChannel = function (animation, handler) {\n const channels = animation.channels;\n return ForEach.object(channels, handler);\n};\n\nForEach.animationSampler = function (animation, handler) {\n const samplers = animation.samplers;\n return ForEach.object(samplers, handler);\n};\n\nForEach.buffer = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"buffers\", handler);\n};\n\nForEach.bufferView = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"bufferViews\", handler);\n};\n\nForEach.camera = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"cameras\", handler);\n};\n\nForEach.image = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"images\", handler);\n};\n\nForEach.material = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"materials\", handler);\n};\n\nForEach.materialValue = function (material, handler) {\n let values = material.values;\n if (\n defined(material.extensions) &&\n defined(material.extensions.KHR_techniques_webgl)\n ) {\n values = material.extensions.KHR_techniques_webgl.values;\n }\n\n for (const name in values) {\n if (Object.prototype.hasOwnProperty.call(values, name)) {\n const value = handler(values[name], name);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.mesh = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"meshes\", handler);\n};\n\nForEach.meshPrimitive = function (mesh, handler) {\n const primitives = mesh.primitives;\n if (defined(primitives)) {\n const primitivesLength = primitives.length;\n for (let i = 0; i < primitivesLength; i++) {\n const primitive = primitives[i];\n const value = handler(primitive, i);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.meshPrimitiveAttribute = function (primitive, handler) {\n const attributes = primitive.attributes;\n for (const semantic in attributes) {\n if (Object.prototype.hasOwnProperty.call(attributes, semantic)) {\n const value = handler(attributes[semantic], semantic);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.meshPrimitiveTarget = function (primitive, handler) {\n const targets = primitive.targets;\n if (defined(targets)) {\n const length = targets.length;\n for (let i = 0; i < length; ++i) {\n const value = handler(targets[i], i);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.meshPrimitiveTargetAttribute = function (target, handler) {\n for (const semantic in target) {\n if (Object.prototype.hasOwnProperty.call(target, semantic)) {\n const accessorId = target[semantic];\n const value = handler(accessorId, semantic);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.node = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"nodes\", handler);\n};\n\nForEach.nodeInTree = function (gltf, nodeIds, handler) {\n const nodes = gltf.nodes;\n if (defined(nodes)) {\n const length = nodeIds.length;\n for (let i = 0; i < length; i++) {\n const nodeId = nodeIds[i];\n const node = nodes[nodeId];\n if (defined(node)) {\n let value = handler(node, nodeId);\n\n if (defined(value)) {\n return value;\n }\n\n const children = node.children;\n if (defined(children)) {\n value = ForEach.nodeInTree(gltf, children, handler);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n }\n }\n};\n\nForEach.nodeInScene = function (gltf, scene, handler) {\n const sceneNodeIds = scene.nodes;\n if (defined(sceneNodeIds)) {\n return ForEach.nodeInTree(gltf, sceneNodeIds, handler);\n }\n};\n\nForEach.program = function (gltf, handler) {\n if (usesExtension(gltf, \"KHR_techniques_webgl\")) {\n return ForEach.object(\n gltf.extensions.KHR_techniques_webgl.programs,\n handler\n );\n }\n\n return ForEach.topLevel(gltf, \"programs\", handler);\n};\n\nForEach.sampler = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"samplers\", handler);\n};\n\nForEach.scene = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"scenes\", handler);\n};\n\nForEach.shader = function (gltf, handler) {\n if (usesExtension(gltf, \"KHR_techniques_webgl\")) {\n return ForEach.object(\n gltf.extensions.KHR_techniques_webgl.shaders,\n handler\n );\n }\n\n return ForEach.topLevel(gltf, \"shaders\", handler);\n};\n\nForEach.skin = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"skins\", handler);\n};\n\nForEach.skinJoint = function (skin, handler) {\n const joints = skin.joints;\n if (defined(joints)) {\n const jointsLength = joints.length;\n for (let i = 0; i < jointsLength; i++) {\n const joint = joints[i];\n const value = handler(joint);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.techniqueAttribute = function (technique, handler) {\n const attributes = technique.attributes;\n for (const attributeName in attributes) {\n if (Object.prototype.hasOwnProperty.call(attributes, attributeName)) {\n const value = handler(attributes[attributeName], attributeName);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.techniqueUniform = function (technique, handler) {\n const uniforms = technique.uniforms;\n for (const uniformName in uniforms) {\n if (Object.prototype.hasOwnProperty.call(uniforms, uniformName)) {\n const value = handler(uniforms[uniformName], uniformName);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.techniqueParameter = function (technique, handler) {\n const parameters = technique.parameters;\n for (const parameterName in parameters) {\n if (Object.prototype.hasOwnProperty.call(parameters, parameterName)) {\n const value = handler(parameters[parameterName], parameterName);\n\n if (defined(value)) {\n return value;\n }\n }\n }\n};\n\nForEach.technique = function (gltf, handler) {\n if (usesExtension(gltf, \"KHR_techniques_webgl\")) {\n return ForEach.object(\n gltf.extensions.KHR_techniques_webgl.techniques,\n handler\n );\n }\n\n return ForEach.topLevel(gltf, \"techniques\", handler);\n};\n\nForEach.texture = function (gltf, handler) {\n return ForEach.topLevel(gltf, \"textures\", handler);\n};\n\nexport default ForEach;\n", "\n\n/**\n * Utility function for retrieving the number of components in a given type.\n *\n * @param {string} type glTF type\n * @returns {number} The number of components in that type.\n *\n * @private\n */\nfunction numberOfComponentsForType(type) {\n switch (type) {\n case \"SCALAR\":\n return 1;\n case \"VEC2\":\n return 2;\n case \"VEC3\":\n return 3;\n case \"VEC4\":\n case \"MAT2\":\n return 4;\n case \"MAT3\":\n return 9;\n case \"MAT4\":\n return 16;\n }\n}\n\nexport default numberOfComponentsForType;\n", "import numberOfComponentsForType from \"./numberOfComponentsForType.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Returns the byte stride of the provided accessor.\n * If the byteStride is 0, it is calculated based on type and componentType\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {object} accessor The accessor.\n * @returns {number} The byte stride of the accessor.\n *\n * @private\n */\nfunction getAccessorByteStride(gltf, accessor) {\n const bufferViewId = accessor.bufferView;\n if (defined(bufferViewId)) {\n const bufferView = gltf.bufferViews[bufferViewId];\n if (defined(bufferView.byteStride) && bufferView.byteStride > 0) {\n return bufferView.byteStride;\n }\n }\n return (\n ComponentDatatype.getSizeInBytes(accessor.componentType) *\n numberOfComponentsForType(accessor.type)\n );\n}\n\nexport default getAccessorByteStride;\n", "import addToArray from \"./addToArray.js\";\nimport ForEach from \"./ForEach.js\";\nimport getAccessorByteStride from \"./getAccessorByteStride.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\n\n/**\n * Adds default glTF values if they don't exist.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} The modified glTF.\n *\n * @private\n */\nfunction addDefaults(gltf) {\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.bufferView)) {\n accessor.byteOffset = defaultValue(accessor.byteOffset, 0);\n }\n });\n\n ForEach.bufferView(gltf, function (bufferView) {\n if (defined(bufferView.buffer)) {\n bufferView.byteOffset = defaultValue(bufferView.byteOffset, 0);\n }\n });\n\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n primitive.mode = defaultValue(primitive.mode, WebGLConstants.TRIANGLES);\n if (!defined(primitive.material)) {\n if (!defined(gltf.materials)) {\n gltf.materials = [];\n }\n const defaultMaterial = {\n name: \"default\",\n };\n primitive.material = addToArray(gltf.materials, defaultMaterial);\n }\n });\n });\n\n ForEach.accessorContainingVertexAttributeData(gltf, function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n accessor.normalized = defaultValue(accessor.normalized, false);\n if (defined(bufferViewId)) {\n const bufferView = gltf.bufferViews[bufferViewId];\n bufferView.byteStride = getAccessorByteStride(gltf, accessor);\n bufferView.target = WebGLConstants.ARRAY_BUFFER;\n }\n });\n\n ForEach.accessorContainingIndexData(gltf, function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n if (defined(bufferViewId)) {\n const bufferView = gltf.bufferViews[bufferViewId];\n bufferView.target = WebGLConstants.ELEMENT_ARRAY_BUFFER;\n }\n });\n\n ForEach.material(gltf, function (material) {\n const extensions = defaultValue(\n material.extensions,\n defaultValue.EMPTY_OBJECT\n );\n const materialsCommon = extensions.KHR_materials_common;\n if (defined(materialsCommon)) {\n const technique = materialsCommon.technique;\n const values = defined(materialsCommon.values)\n ? materialsCommon.values\n : {};\n materialsCommon.values = values;\n\n values.ambient = defined(values.ambient)\n ? values.ambient\n : [0.0, 0.0, 0.0, 1.0];\n values.emission = defined(values.emission)\n ? values.emission\n : [0.0, 0.0, 0.0, 1.0];\n\n values.transparency = defaultValue(values.transparency, 1.0);\n\n if (technique !== \"CONSTANT\") {\n values.diffuse = defined(values.diffuse)\n ? values.diffuse\n : [0.0, 0.0, 0.0, 1.0];\n if (technique !== \"LAMBERT\") {\n values.specular = defined(values.specular)\n ? values.specular\n : [0.0, 0.0, 0.0, 1.0];\n values.shininess = defaultValue(values.shininess, 0.0);\n }\n }\n\n // These actually exist on the extension object, not the values object despite what's shown in the spec\n materialsCommon.transparent = defaultValue(\n materialsCommon.transparent,\n false\n );\n materialsCommon.doubleSided = defaultValue(\n materialsCommon.doubleSided,\n false\n );\n\n return;\n }\n\n material.emissiveFactor = defaultValue(\n material.emissiveFactor,\n [0.0, 0.0, 0.0]\n );\n material.alphaMode = defaultValue(material.alphaMode, \"OPAQUE\");\n material.doubleSided = defaultValue(material.doubleSided, false);\n\n if (material.alphaMode === \"MASK\") {\n material.alphaCutoff = defaultValue(material.alphaCutoff, 0.5);\n }\n\n const techniquesExtension = extensions.KHR_techniques_webgl;\n if (defined(techniquesExtension)) {\n ForEach.materialValue(material, function (materialValue) {\n // Check if material value is a TextureInfo object\n if (defined(materialValue.index)) {\n addTextureDefaults(materialValue);\n }\n });\n }\n\n addTextureDefaults(material.emissiveTexture);\n addTextureDefaults(material.normalTexture);\n addTextureDefaults(material.occlusionTexture);\n\n const pbrMetallicRoughness = material.pbrMetallicRoughness;\n if (defined(pbrMetallicRoughness)) {\n pbrMetallicRoughness.baseColorFactor = defaultValue(\n pbrMetallicRoughness.baseColorFactor,\n [1.0, 1.0, 1.0, 1.0]\n );\n pbrMetallicRoughness.metallicFactor = defaultValue(\n pbrMetallicRoughness.metallicFactor,\n 1.0\n );\n pbrMetallicRoughness.roughnessFactor = defaultValue(\n pbrMetallicRoughness.roughnessFactor,\n 1.0\n );\n addTextureDefaults(pbrMetallicRoughness.baseColorTexture);\n addTextureDefaults(pbrMetallicRoughness.metallicRoughnessTexture);\n }\n\n const pbrSpecularGlossiness =\n extensions.KHR_materials_pbrSpecularGlossiness;\n if (defined(pbrSpecularGlossiness)) {\n pbrSpecularGlossiness.diffuseFactor = defaultValue(\n pbrSpecularGlossiness.diffuseFactor,\n [1.0, 1.0, 1.0, 1.0]\n );\n pbrSpecularGlossiness.specularFactor = defaultValue(\n pbrSpecularGlossiness.specularFactor,\n [1.0, 1.0, 1.0]\n );\n pbrSpecularGlossiness.glossinessFactor = defaultValue(\n pbrSpecularGlossiness.glossinessFactor,\n 1.0\n );\n addTextureDefaults(pbrSpecularGlossiness.specularGlossinessTexture);\n }\n });\n\n ForEach.animation(gltf, function (animation) {\n ForEach.animationSampler(animation, function (sampler) {\n sampler.interpolation = defaultValue(sampler.interpolation, \"LINEAR\");\n });\n });\n\n const animatedNodes = getAnimatedNodes(gltf);\n ForEach.node(gltf, function (node, id) {\n const animated = defined(animatedNodes[id]);\n if (\n animated ||\n defined(node.translation) ||\n defined(node.rotation) ||\n defined(node.scale)\n ) {\n node.translation = defaultValue(node.translation, [0.0, 0.0, 0.0]);\n node.rotation = defaultValue(node.rotation, [0.0, 0.0, 0.0, 1.0]);\n node.scale = defaultValue(node.scale, [1.0, 1.0, 1.0]);\n } else {\n node.matrix = defaultValue(\n node.matrix,\n [\n 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,\n 0.0, 1.0,\n ]\n );\n }\n });\n\n ForEach.sampler(gltf, function (sampler) {\n sampler.wrapS = defaultValue(sampler.wrapS, WebGLConstants.REPEAT);\n sampler.wrapT = defaultValue(sampler.wrapT, WebGLConstants.REPEAT);\n });\n\n if (defined(gltf.scenes) && !defined(gltf.scene)) {\n gltf.scene = 0;\n }\n\n return gltf;\n}\n\nfunction getAnimatedNodes(gltf) {\n const nodes = {};\n ForEach.animation(gltf, function (animation) {\n ForEach.animationChannel(animation, function (channel) {\n const target = channel.target;\n const nodeId = target.node;\n const path = target.path;\n // Ignore animations that target 'weights'\n if (path === \"translation\" || path === \"rotation\" || path === \"scale\") {\n nodes[nodeId] = true;\n }\n });\n });\n return nodes;\n}\n\nfunction addTextureDefaults(texture) {\n if (defined(texture)) {\n texture.texCoord = defaultValue(texture.texCoord, 0);\n }\n}\n\nexport default addDefaults;\n", "import ForEach from \"./ForEach.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Adds extras._pipeline to each object that can have extras in the glTF asset.\n * This stage runs before updateVersion and handles both glTF 1.0 and glTF 2.0 assets.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} The glTF asset with the added pipeline extras.\n *\n * @private\n */\nfunction addPipelineExtras(gltf) {\n ForEach.shader(gltf, function (shader) {\n addExtras(shader);\n });\n ForEach.buffer(gltf, function (buffer) {\n addExtras(buffer);\n });\n ForEach.image(gltf, function (image) {\n addExtras(image);\n });\n\n addExtras(gltf);\n\n return gltf;\n}\n\nfunction addExtras(object) {\n object.extras = defined(object.extras) ? object.extras : {};\n object.extras._pipeline = defined(object.extras._pipeline)\n ? object.extras._pipeline\n : {};\n}\n\nexport default addPipelineExtras;\n", "import defined from \"../../Core/defined.js\";\n\n/**\n * Removes an extension from gltf.extensionsRequired if it is present.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The extension to remove.\n *\n * @private\n */\nfunction removeExtensionsRequired(gltf, extension) {\n const extensionsRequired = gltf.extensionsRequired;\n if (defined(extensionsRequired)) {\n const index = extensionsRequired.indexOf(extension);\n if (index >= 0) {\n extensionsRequired.splice(index, 1);\n }\n if (extensionsRequired.length === 0) {\n delete gltf.extensionsRequired;\n }\n }\n}\n\nexport default removeExtensionsRequired;\n", "import removeExtensionsRequired from \"./removeExtensionsRequired.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Removes an extension from gltf.extensionsUsed and gltf.extensionsRequired if it is present.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The extension to remove.\n *\n * @private\n */\nfunction removeExtensionsUsed(gltf, extension) {\n const extensionsUsed = gltf.extensionsUsed;\n if (defined(extensionsUsed)) {\n const index = extensionsUsed.indexOf(extension);\n if (index >= 0) {\n extensionsUsed.splice(index, 1);\n }\n removeExtensionsRequired(gltf, extension);\n if (extensionsUsed.length === 0) {\n delete gltf.extensionsUsed;\n }\n }\n}\n\nexport default removeExtensionsUsed;\n", "import addPipelineExtras from \"./addPipelineExtras.js\";\nimport removeExtensionsUsed from \"./removeExtensionsUsed.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport getMagic from \"../../Core/getMagic.js\";\nimport getStringFromTypedArray from \"../../Core/getStringFromTypedArray.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\n\nconst sizeOfUint32 = 4;\n\n/**\n * Convert a binary glTF to glTF.\n *\n * The returned glTF has pipeline extras included. The embedded binary data is stored in gltf.buffers[0].extras._pipeline.source.\n *\n * @param {Buffer} glb The glb data to parse.\n * @returns {object} A javascript object containing a glTF asset with pipeline extras included.\n *\n * @private\n */\nfunction parseGlb(glb) {\n // Check that the magic string is present\n const magic = getMagic(glb);\n if (magic !== \"glTF\") {\n throw new RuntimeError(\"File is not valid binary glTF\");\n }\n\n const header = readHeader(glb, 0, 5);\n const version = header[1];\n if (version !== 1 && version !== 2) {\n throw new RuntimeError(\"Binary glTF version is not 1 or 2\");\n }\n\n if (version === 1) {\n return parseGlbVersion1(glb, header);\n }\n\n return parseGlbVersion2(glb, header);\n}\n\nfunction readHeader(glb, byteOffset, count) {\n const dataView = new DataView(glb.buffer);\n const header = new Array(count);\n for (let i = 0; i < count; ++i) {\n header[i] = dataView.getUint32(\n glb.byteOffset + byteOffset + i * sizeOfUint32,\n true\n );\n }\n return header;\n}\n\nfunction parseGlbVersion1(glb, header) {\n const length = header[2];\n const contentLength = header[3];\n const contentFormat = header[4];\n\n // Check that the content format is 0, indicating that it is JSON\n if (contentFormat !== 0) {\n throw new RuntimeError(\"Binary glTF scene format is not JSON\");\n }\n\n const jsonStart = 20;\n const binaryStart = jsonStart + contentLength;\n\n const contentString = getStringFromTypedArray(glb, jsonStart, contentLength);\n const gltf = JSON.parse(contentString);\n addPipelineExtras(gltf);\n\n const binaryBuffer = glb.subarray(binaryStart, length);\n\n const buffers = gltf.buffers;\n if (defined(buffers) && Object.keys(buffers).length > 0) {\n // In some older models, the binary glTF buffer is named KHR_binary_glTF\n const binaryGltfBuffer = defaultValue(\n buffers.binary_glTF,\n buffers.KHR_binary_glTF\n );\n if (defined(binaryGltfBuffer)) {\n binaryGltfBuffer.extras._pipeline.source = binaryBuffer;\n delete binaryGltfBuffer.uri;\n }\n }\n // Remove the KHR_binary_glTF extension\n removeExtensionsUsed(gltf, \"KHR_binary_glTF\");\n return gltf;\n}\n\nfunction parseGlbVersion2(glb, header) {\n const length = header[2];\n let byteOffset = 12;\n let gltf;\n let binaryBuffer;\n while (byteOffset < length) {\n const chunkHeader = readHeader(glb, byteOffset, 2);\n const chunkLength = chunkHeader[0];\n const chunkType = chunkHeader[1];\n byteOffset += 8;\n const chunkBuffer = glb.subarray(byteOffset, byteOffset + chunkLength);\n byteOffset += chunkLength;\n // Load JSON chunk\n if (chunkType === 0x4e4f534a) {\n const jsonString = getStringFromTypedArray(chunkBuffer);\n gltf = JSON.parse(jsonString);\n addPipelineExtras(gltf);\n }\n // Load Binary chunk\n else if (chunkType === 0x004e4942) {\n binaryBuffer = chunkBuffer;\n }\n }\n if (defined(gltf) && defined(binaryBuffer)) {\n const buffers = gltf.buffers;\n if (defined(buffers) && buffers.length > 0) {\n const buffer = buffers[0];\n buffer.extras._pipeline.source = binaryBuffer;\n }\n }\n return gltf;\n}\n\nexport default parseGlb;\n", "import ForEach from \"./ForEach.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Iterate through the objects within the glTF and delete their pipeline extras object.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} glTF with no pipeline extras.\n *\n * @private\n */\nfunction removePipelineExtras(gltf) {\n ForEach.shader(gltf, function (shader) {\n removeExtras(shader);\n });\n ForEach.buffer(gltf, function (buffer) {\n removeExtras(buffer);\n });\n ForEach.image(gltf, function (image) {\n removeExtras(image);\n });\n\n removeExtras(gltf);\n\n return gltf;\n}\n\nfunction removeExtras(object) {\n if (!defined(object.extras)) {\n return;\n }\n\n if (defined(object.extras._pipeline)) {\n delete object.extras._pipeline;\n }\n\n if (Object.keys(object.extras).length === 0) {\n delete object.extras;\n }\n}\n\nexport default removePipelineExtras;\n", "import addToArray from \"./addToArray.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Adds an extension to gltf.extensionsUsed if it does not already exist.\n * Initializes extensionsUsed if it is not defined.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The extension to add.\n *\n * @private\n */\nfunction addExtensionsUsed(gltf, extension) {\n let extensionsUsed = gltf.extensionsUsed;\n if (!defined(extensionsUsed)) {\n extensionsUsed = [];\n gltf.extensionsUsed = extensionsUsed;\n }\n addToArray(extensionsUsed, extension, true);\n}\n\nexport default addExtensionsUsed;\n", "import ComponentDatatype from \"../../Core/ComponentDatatype.js\";\n\n/**\n * Returns a function to read and convert data from a DataView into an array.\n *\n * @param {number} componentType Type to convert the data to.\n * @returns {ComponentReader} Function that reads and converts data.\n *\n * @private\n */\nfunction getComponentReader(componentType) {\n switch (componentType) {\n case ComponentDatatype.BYTE:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getInt8(\n byteOffset + i * componentTypeByteLength\n );\n }\n };\n case ComponentDatatype.UNSIGNED_BYTE:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getUint8(\n byteOffset + i * componentTypeByteLength\n );\n }\n };\n case ComponentDatatype.SHORT:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getInt16(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n case ComponentDatatype.UNSIGNED_SHORT:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getUint16(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n case ComponentDatatype.INT:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getInt32(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n case ComponentDatatype.UNSIGNED_INT:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getUint32(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n case ComponentDatatype.FLOAT:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getFloat32(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n case ComponentDatatype.DOUBLE:\n return function (\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n result\n ) {\n for (let i = 0; i < numberOfComponents; ++i) {\n result[i] = dataView.getFloat64(\n byteOffset + i * componentTypeByteLength,\n true\n );\n }\n };\n }\n}\n\n/**\n * A callback function that logs messages.\n * @callback ComponentReader\n *\n * @param {DataView} dataView The data view to read from.\n * @param {number} byteOffset The byte offset applied when reading from the data view.\n * @param {number} numberOfComponents The number of components to read.\n * @param {number} componentTypeByteLength The byte length of each component.\n * @param {number} result An array storing the components that are read.\n *\n * @private\n */\n\nexport default getComponentReader;\n", "import getAccessorByteStride from \"./getAccessorByteStride.js\";\nimport getComponentReader from \"./getComponentReader.js\";\nimport numberOfComponentsForType from \"./numberOfComponentsForType.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Finds the min and max values of the accessor.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {object} accessor The accessor object from the glTF asset to read.\n * @returns {{min: Array, max: Array}} min holding the array of minimum values and max holding the array of maximum values.\n *\n * @private\n */\nfunction findAccessorMinMax(gltf, accessor) {\n const bufferViews = gltf.bufferViews;\n const buffers = gltf.buffers;\n const bufferViewId = accessor.bufferView;\n const numberOfComponents = numberOfComponentsForType(accessor.type);\n\n // According to the spec, when bufferView is not defined, accessor must be initialized with zeros\n if (!defined(accessor.bufferView)) {\n return {\n min: new Array(numberOfComponents).fill(0.0),\n max: new Array(numberOfComponents).fill(0.0),\n };\n }\n\n const min = new Array(numberOfComponents).fill(Number.POSITIVE_INFINITY);\n const max = new Array(numberOfComponents).fill(Number.NEGATIVE_INFINITY);\n\n const bufferView = bufferViews[bufferViewId];\n const bufferId = bufferView.buffer;\n const buffer = buffers[bufferId];\n const source = buffer.extras._pipeline.source;\n\n const count = accessor.count;\n const byteStride = getAccessorByteStride(gltf, accessor);\n let byteOffset =\n accessor.byteOffset + bufferView.byteOffset + source.byteOffset;\n const componentType = accessor.componentType;\n const componentTypeByteLength =\n ComponentDatatype.getSizeInBytes(componentType);\n const dataView = new DataView(source.buffer);\n const components = new Array(numberOfComponents);\n const componentReader = getComponentReader(componentType);\n\n for (let i = 0; i < count; i++) {\n componentReader(\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n components\n );\n for (let j = 0; j < numberOfComponents; j++) {\n const value = components[j];\n min[j] = Math.min(min[j], value);\n max[j] = Math.max(max[j], value);\n }\n byteOffset += byteStride;\n }\n\n return {\n min: min,\n max: max,\n };\n}\n\nexport default findAccessorMinMax;\n", "import addExtensionsUsed from \"./addExtensionsUsed.js\";\nimport ForEach from \"./ForEach.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\n\nconst defaultBlendEquation = [WebGLConstants.FUNC_ADD, WebGLConstants.FUNC_ADD];\n\nconst defaultBlendFactors = [\n WebGLConstants.ONE,\n WebGLConstants.ZERO,\n WebGLConstants.ONE,\n WebGLConstants.ZERO,\n];\n\nfunction isStateEnabled(renderStates, state) {\n const enabled = renderStates.enable;\n if (!defined(enabled)) {\n return false;\n }\n\n return enabled.indexOf(state) > -1;\n}\n\nconst supportedBlendFactors = [\n WebGLConstants.ZERO,\n WebGLConstants.ONE,\n WebGLConstants.SRC_COLOR,\n WebGLConstants.ONE_MINUS_SRC_COLOR,\n WebGLConstants.SRC_ALPHA,\n WebGLConstants.ONE_MINUS_SRC_ALPHA,\n WebGLConstants.DST_ALPHA,\n WebGLConstants.ONE_MINUS_DST_ALPHA,\n WebGLConstants.DST_COLOR,\n WebGLConstants.ONE_MINUS_DST_COLOR,\n];\n\n// If any of the blend factors are not supported, return the default\nfunction getSupportedBlendFactors(value, defaultValue) {\n if (!defined(value)) {\n return defaultValue;\n }\n\n for (let i = 0; i < 4; i++) {\n if (supportedBlendFactors.indexOf(value[i]) === -1) {\n return defaultValue;\n }\n }\n\n return value;\n}\n\n/**\n * Move glTF 1.0 technique render states to glTF 2.0 materials properties and KHR_blend extension.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} The updated glTF asset.\n *\n * @private\n */\nfunction moveTechniqueRenderStates(gltf) {\n const blendingForTechnique = {};\n const materialPropertiesForTechnique = {};\n const techniquesLegacy = gltf.techniques;\n if (!defined(techniquesLegacy)) {\n return gltf;\n }\n\n ForEach.technique(gltf, function (techniqueLegacy, techniqueIndex) {\n const renderStates = techniqueLegacy.states;\n if (defined(renderStates)) {\n const materialProperties = (materialPropertiesForTechnique[\n techniqueIndex\n ] = {});\n\n // If BLEND is enabled, the material should have alpha mode BLEND\n if (isStateEnabled(renderStates, WebGLConstants.BLEND)) {\n materialProperties.alphaMode = \"BLEND\";\n\n const blendFunctions = renderStates.functions;\n if (\n defined(blendFunctions) &&\n (defined(blendFunctions.blendEquationSeparate) ||\n defined(blendFunctions.blendFuncSeparate))\n ) {\n blendingForTechnique[techniqueIndex] = {\n blendEquation: defaultValue(\n blendFunctions.blendEquationSeparate,\n defaultBlendEquation\n ),\n blendFactors: getSupportedBlendFactors(\n blendFunctions.blendFuncSeparate,\n defaultBlendFactors\n ),\n };\n }\n }\n\n // If CULL_FACE is not enabled, the material should be doubleSided\n if (!isStateEnabled(renderStates, WebGLConstants.CULL_FACE)) {\n materialProperties.doubleSided = true;\n }\n\n delete techniqueLegacy.states;\n }\n });\n\n if (Object.keys(blendingForTechnique).length > 0) {\n if (!defined(gltf.extensions)) {\n gltf.extensions = {};\n }\n\n addExtensionsUsed(gltf, \"KHR_blend\");\n }\n\n ForEach.material(gltf, function (material) {\n if (defined(material.technique)) {\n const materialProperties =\n materialPropertiesForTechnique[material.technique];\n ForEach.objectLegacy(materialProperties, function (value, property) {\n material[property] = value;\n });\n\n const blending = blendingForTechnique[material.technique];\n if (defined(blending)) {\n if (!defined(material.extensions)) {\n material.extensions = {};\n }\n\n material.extensions.KHR_blend = blending;\n }\n }\n });\n\n return gltf;\n}\n\nexport default moveTechniqueRenderStates;\n", "import addExtensionsUsed from \"./addExtensionsUsed.js\";\nimport addToArray from \"./addToArray.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Adds an extension to gltf.extensionsRequired if it does not already exist.\n * Initializes extensionsRequired if it is not defined.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The extension to add.\n *\n * @private\n */\nfunction addExtensionsRequired(gltf, extension) {\n let extensionsRequired = gltf.extensionsRequired;\n if (!defined(extensionsRequired)) {\n extensionsRequired = [];\n gltf.extensionsRequired = extensionsRequired;\n }\n addToArray(extensionsRequired, extension, true);\n addExtensionsUsed(gltf, extension);\n}\n\nexport default addExtensionsRequired;\n", "import addExtensionsUsed from \"./addExtensionsUsed.js\";\nimport addExtensionsRequired from \"./addExtensionsRequired.js\";\nimport addToArray from \"./addToArray.js\";\nimport ForEach from \"./ForEach.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Move glTF 1.0 material techniques to glTF 2.0 KHR_techniques_webgl extension.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} The updated glTF asset.\n *\n * @private\n */\nfunction moveTechniquesToExtension(gltf) {\n const techniquesLegacy = gltf.techniques;\n const mappedUniforms = {};\n const updatedTechniqueIndices = {};\n const seenPrograms = {};\n if (defined(techniquesLegacy)) {\n const extension = {\n programs: [],\n shaders: [],\n techniques: [],\n };\n\n // Some 1.1 models have a glExtensionsUsed property that can be transferred to program.glExtensions\n const glExtensions = gltf.glExtensionsUsed;\n delete gltf.glExtensionsUsed;\n\n ForEach.technique(gltf, function (techniqueLegacy, techniqueId) {\n const technique = {\n name: techniqueLegacy.name,\n program: undefined,\n attributes: {},\n uniforms: {},\n };\n\n let parameterLegacy;\n ForEach.techniqueAttribute(\n techniqueLegacy,\n function (parameterName, attributeName) {\n parameterLegacy = techniqueLegacy.parameters[parameterName];\n technique.attributes[attributeName] = {\n semantic: parameterLegacy.semantic,\n };\n }\n );\n\n ForEach.techniqueUniform(\n techniqueLegacy,\n function (parameterName, uniformName) {\n parameterLegacy = techniqueLegacy.parameters[parameterName];\n technique.uniforms[uniformName] = {\n count: parameterLegacy.count,\n node: parameterLegacy.node,\n type: parameterLegacy.type,\n semantic: parameterLegacy.semantic,\n value: parameterLegacy.value,\n };\n\n // Store the name of the uniform to update material values.\n if (!defined(mappedUniforms[techniqueId])) {\n mappedUniforms[techniqueId] = {};\n }\n mappedUniforms[techniqueId][parameterName] = uniformName;\n }\n );\n\n if (!defined(seenPrograms[techniqueLegacy.program])) {\n const programLegacy = gltf.programs[techniqueLegacy.program];\n\n const program = {\n name: programLegacy.name,\n fragmentShader: undefined,\n vertexShader: undefined,\n glExtensions: glExtensions,\n };\n\n const fs = gltf.shaders[programLegacy.fragmentShader];\n program.fragmentShader = addToArray(extension.shaders, fs, true);\n\n const vs = gltf.shaders[programLegacy.vertexShader];\n program.vertexShader = addToArray(extension.shaders, vs, true);\n\n technique.program = addToArray(extension.programs, program);\n seenPrograms[techniqueLegacy.program] = technique.program;\n } else {\n technique.program = seenPrograms[techniqueLegacy.program];\n }\n\n // Store the index of the new technique to reference instead.\n updatedTechniqueIndices[techniqueId] = addToArray(\n extension.techniques,\n technique\n );\n });\n\n if (extension.techniques.length > 0) {\n if (!defined(gltf.extensions)) {\n gltf.extensions = {};\n }\n\n gltf.extensions.KHR_techniques_webgl = extension;\n addExtensionsUsed(gltf, \"KHR_techniques_webgl\");\n addExtensionsRequired(gltf, \"KHR_techniques_webgl\");\n }\n }\n\n ForEach.material(gltf, function (material) {\n if (defined(material.technique)) {\n const materialExtension = {\n technique: updatedTechniqueIndices[material.technique],\n };\n\n ForEach.objectLegacy(material.values, function (value, parameterName) {\n if (!defined(materialExtension.values)) {\n materialExtension.values = {};\n }\n\n const uniformName = mappedUniforms[material.technique][parameterName];\n if (defined(uniformName)) {\n materialExtension.values[uniformName] = value;\n }\n });\n\n if (!defined(material.extensions)) {\n material.extensions = {};\n }\n\n material.extensions.KHR_techniques_webgl = materialExtension;\n }\n\n delete material.technique;\n delete material.values;\n });\n\n delete gltf.techniques;\n delete gltf.programs;\n delete gltf.shaders;\n\n return gltf;\n}\n\nexport default moveTechniquesToExtension;\n", "import ForEach from \"./ForEach.js\";\nimport Check from \"../../Core/Check.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Calls the provider handler function on each texture used by the material.\n * Mimics the behavior of functions in gltf-pipeline ForEach.\n * @param {object} material The glTF material.\n * @param {forEachTextureInMaterial~handler} handler Function that is called for each texture in the material.\n *\n * @private\n */\nfunction forEachTextureInMaterial(material, handler) {\n Check.typeOf.object(\"material\", material);\n Check.defined(\"handler\", handler);\n\n // Metallic roughness\n const pbrMetallicRoughness = material.pbrMetallicRoughness;\n if (defined(pbrMetallicRoughness)) {\n if (defined(pbrMetallicRoughness.baseColorTexture)) {\n const textureInfo = pbrMetallicRoughness.baseColorTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n if (defined(pbrMetallicRoughness.metallicRoughnessTexture)) {\n const textureInfo = pbrMetallicRoughness.metallicRoughnessTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n }\n\n if (defined(material.extensions)) {\n // Spec gloss extension\n const pbrSpecularGlossiness =\n material.extensions.KHR_materials_pbrSpecularGlossiness;\n if (defined(pbrSpecularGlossiness)) {\n if (defined(pbrSpecularGlossiness.diffuseTexture)) {\n const textureInfo = pbrSpecularGlossiness.diffuseTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {\n const textureInfo = pbrSpecularGlossiness.specularGlossinessTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n }\n\n // Materials common extension (may be present in models converted from glTF 1.0)\n const materialsCommon = material.extensions.KHR_materials_common;\n if (defined(materialsCommon) && defined(materialsCommon.values)) {\n const diffuse = materialsCommon.values.diffuse;\n const ambient = materialsCommon.values.ambient;\n const emission = materialsCommon.values.emission;\n const specular = materialsCommon.values.specular;\n if (defined(diffuse) && defined(diffuse.index)) {\n const value = handler(diffuse.index, diffuse);\n if (defined(value)) {\n return value;\n }\n }\n if (defined(ambient) && defined(ambient.index)) {\n const value = handler(ambient.index, ambient);\n if (defined(value)) {\n return value;\n }\n }\n if (defined(emission) && defined(emission.index)) {\n const value = handler(emission.index, emission);\n if (defined(value)) {\n return value;\n }\n }\n if (defined(specular) && defined(specular.index)) {\n const value = handler(specular.index, specular);\n if (defined(value)) {\n return value;\n }\n }\n }\n }\n\n // KHR_techniques_webgl extension\n const value = ForEach.materialValue(material, function (materialValue) {\n if (defined(materialValue.index)) {\n const value = handler(materialValue.index, materialValue);\n if (defined(value)) {\n return value;\n }\n }\n });\n if (defined(value)) {\n return value;\n }\n\n // Top level textures\n if (defined(material.emissiveTexture)) {\n const textureInfo = material.emissiveTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n\n if (defined(material.normalTexture)) {\n const textureInfo = material.normalTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n\n if (defined(material.occlusionTexture)) {\n const textureInfo = material.occlusionTexture;\n const value = handler(textureInfo.index, textureInfo);\n if (defined(value)) {\n return value;\n }\n }\n}\n\n/**\n * Function that is called for each texture in the material. If this function returns a value the for each stops and returns that value.\n * @callback forEachTextureInMaterial~handler\n * @param {number} The texture index.\n * @param {object} The texture info object.\n *\n * @private\n */\n\nexport default forEachTextureInMaterial;\n", "import ForEach from \"./ForEach.js\";\nimport forEachTextureInMaterial from \"./forEachTextureInMaterial.js\";\nimport usesExtension from \"./usesExtension.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\n\nconst allElementTypes = [\n \"mesh\",\n \"node\",\n \"material\",\n \"accessor\",\n \"bufferView\",\n \"buffer\",\n \"texture\",\n \"sampler\",\n \"image\",\n];\n\n/**\n * Removes unused elements from gltf.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string[]} [elementTypes=['mesh', 'node', 'material', 'accessor', 'bufferView', 'buffer']] Element types to be removed. Needs to be a subset of ['mesh', 'node', 'material', 'accessor', 'bufferView', 'buffer'], other items will be ignored.\n *\n * @private\n */\nfunction removeUnusedElements(gltf, elementTypes) {\n elementTypes = defaultValue(elementTypes, allElementTypes);\n allElementTypes.forEach(function (type) {\n if (elementTypes.indexOf(type) > -1) {\n removeUnusedElementsByType(gltf, type);\n }\n });\n return gltf;\n}\n\nconst TypeToGltfElementName = {\n accessor: \"accessors\",\n buffer: \"buffers\",\n bufferView: \"bufferViews\",\n image: \"images\",\n node: \"nodes\",\n material: \"materials\",\n mesh: \"meshes\",\n sampler: \"samplers\",\n texture: \"textures\",\n};\n\nfunction removeUnusedElementsByType(gltf, type) {\n const name = TypeToGltfElementName[type];\n const arrayOfObjects = gltf[name];\n\n if (defined(arrayOfObjects)) {\n let removed = 0;\n const usedIds = getListOfElementsIdsInUse[type](gltf);\n const length = arrayOfObjects.length;\n\n for (let i = 0; i < length; ++i) {\n if (!usedIds[i]) {\n Remove[type](gltf, i - removed);\n removed++;\n }\n }\n }\n}\n\n/**\n * Contains functions for removing elements from a glTF hierarchy.\n * Since top-level glTF elements are arrays, when something is removed, referring\n * indices need to be updated.\n * @constructor\n *\n * @private\n */\nfunction Remove() {}\n\nRemove.accessor = function (gltf, accessorId) {\n const accessors = gltf.accessors;\n\n accessors.splice(accessorId, 1);\n\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n // Update accessor ids for the primitives.\n ForEach.meshPrimitiveAttribute(\n primitive,\n function (attributeAccessorId, semantic) {\n if (attributeAccessorId > accessorId) {\n primitive.attributes[semantic]--;\n }\n }\n );\n\n // Update accessor ids for the targets.\n ForEach.meshPrimitiveTarget(primitive, function (target) {\n ForEach.meshPrimitiveTargetAttribute(\n target,\n function (attributeAccessorId, semantic) {\n if (attributeAccessorId > accessorId) {\n target[semantic]--;\n }\n }\n );\n });\n const indices = primitive.indices;\n if (defined(indices) && indices > accessorId) {\n primitive.indices--;\n }\n\n const ext = primitive.extensions;\n if (\n defined(ext) &&\n defined(ext.CESIUM_primitive_outline) &&\n ext.CESIUM_primitive_outline.indices > accessorId\n ) {\n --ext.CESIUM_primitive_outline.indices;\n }\n });\n });\n\n ForEach.skin(gltf, function (skin) {\n if (\n defined(skin.inverseBindMatrices) &&\n skin.inverseBindMatrices > accessorId\n ) {\n skin.inverseBindMatrices--;\n }\n });\n\n ForEach.animation(gltf, function (animation) {\n ForEach.animationSampler(animation, function (sampler) {\n if (defined(sampler.input) && sampler.input > accessorId) {\n sampler.input--;\n }\n if (defined(sampler.output) && sampler.output > accessorId) {\n sampler.output--;\n }\n });\n });\n};\n\nRemove.buffer = function (gltf, bufferId) {\n const buffers = gltf.buffers;\n\n buffers.splice(bufferId, 1);\n\n ForEach.bufferView(gltf, function (bufferView) {\n if (defined(bufferView.buffer) && bufferView.buffer > bufferId) {\n bufferView.buffer--;\n }\n\n if (\n defined(bufferView.extensions) &&\n defined(bufferView.extensions.EXT_meshopt_compression)\n ) {\n bufferView.extensions.EXT_meshopt_compression.buffer--;\n }\n });\n};\n\nRemove.bufferView = function (gltf, bufferViewId) {\n const bufferViews = gltf.bufferViews;\n\n bufferViews.splice(bufferViewId, 1);\n\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.bufferView) && accessor.bufferView > bufferViewId) {\n accessor.bufferView--;\n }\n });\n\n ForEach.shader(gltf, function (shader) {\n if (defined(shader.bufferView) && shader.bufferView > bufferViewId) {\n shader.bufferView--;\n }\n });\n\n ForEach.image(gltf, function (image) {\n if (defined(image.bufferView) && image.bufferView > bufferViewId) {\n image.bufferView--;\n }\n });\n\n if (usesExtension(gltf, \"KHR_draco_mesh_compression\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n if (\n defined(primitive.extensions) &&\n defined(primitive.extensions.KHR_draco_mesh_compression)\n ) {\n if (\n primitive.extensions.KHR_draco_mesh_compression.bufferView >\n bufferViewId\n ) {\n primitive.extensions.KHR_draco_mesh_compression.bufferView--;\n }\n }\n });\n });\n }\n\n if (usesExtension(gltf, \"EXT_feature_metadata\")) {\n const extension = gltf.extensions.EXT_feature_metadata;\n const featureTables = extension.featureTables;\n for (const featureTableId in featureTables) {\n if (featureTables.hasOwnProperty(featureTableId)) {\n const featureTable = featureTables[featureTableId];\n const properties = featureTable.properties;\n if (defined(properties)) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (\n defined(property.bufferView) &&\n property.bufferView > bufferViewId\n ) {\n property.bufferView--;\n }\n if (\n defined(property.arrayOffsetBufferView) &&\n property.arrayOffsetBufferView > bufferViewId\n ) {\n property.arrayOffsetBufferView--;\n }\n if (\n defined(property.stringOffsetBufferView) &&\n property.stringOffsetBufferView > bufferViewId\n ) {\n property.stringOffsetBufferView--;\n }\n }\n }\n }\n }\n }\n }\n\n if (usesExtension(gltf, \"EXT_structural_metadata\")) {\n const extension = gltf.extensions.EXT_structural_metadata;\n const propertyTables = extension.propertyTables;\n if (defined(propertyTables)) {\n const propertyTablesLength = propertyTables.length;\n for (let i = 0; i < propertyTablesLength; ++i) {\n const propertyTable = propertyTables[i];\n const properties = propertyTable.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (defined(property.values) && property.values > bufferViewId) {\n property.values--;\n }\n if (\n defined(property.arrayOffsets) &&\n property.arrayOffsets > bufferViewId\n ) {\n property.arrayOffsets--;\n }\n if (\n defined(property.stringOffsets) &&\n property.stringOffsets > bufferViewId\n ) {\n property.stringOffsets--;\n }\n }\n }\n }\n }\n }\n};\n\nRemove.image = function (gltf, imageId) {\n const images = gltf.images;\n images.splice(imageId, 1);\n\n ForEach.texture(gltf, function (texture) {\n if (defined(texture.source)) {\n if (texture.source > imageId) {\n --texture.source;\n }\n }\n const ext = texture.extensions;\n if (\n defined(ext) &&\n defined(ext.EXT_texture_webp) &&\n ext.EXT_texture_webp.source > imageId\n ) {\n --texture.extensions.EXT_texture_webp.source;\n } else if (\n defined(ext) &&\n defined(ext.KHR_texture_basisu) &&\n ext.KHR_texture_basisu.source > imageId\n ) {\n --texture.extensions.KHR_texture_basisu.source;\n }\n });\n};\n\nRemove.mesh = function (gltf, meshId) {\n const meshes = gltf.meshes;\n meshes.splice(meshId, 1);\n\n ForEach.node(gltf, function (node) {\n if (defined(node.mesh)) {\n if (node.mesh > meshId) {\n node.mesh--;\n } else if (node.mesh === meshId) {\n // Remove reference to deleted mesh\n delete node.mesh;\n }\n }\n });\n};\n\nRemove.node = function (gltf, nodeId) {\n const nodes = gltf.nodes;\n nodes.splice(nodeId, 1);\n\n // Shift all node references\n ForEach.skin(gltf, function (skin) {\n if (defined(skin.skeleton) && skin.skeleton > nodeId) {\n skin.skeleton--;\n }\n\n skin.joints = skin.joints.map(function (x) {\n return x > nodeId ? x - 1 : x;\n });\n });\n ForEach.animation(gltf, function (animation) {\n ForEach.animationChannel(animation, function (channel) {\n if (\n defined(channel.target) &&\n defined(channel.target.node) &&\n channel.target.node > nodeId\n ) {\n channel.target.node--;\n }\n });\n });\n ForEach.technique(gltf, function (technique) {\n ForEach.techniqueUniform(technique, function (uniform) {\n if (defined(uniform.node) && uniform.node > nodeId) {\n uniform.node--;\n }\n });\n });\n ForEach.node(gltf, function (node) {\n if (!defined(node.children)) {\n return;\n }\n\n node.children = node.children\n .filter(function (x) {\n return x !== nodeId; // Remove\n })\n .map(function (x) {\n return x > nodeId ? x - 1 : x; // Shift indices\n });\n });\n ForEach.scene(gltf, function (scene) {\n scene.nodes = scene.nodes\n .filter(function (x) {\n return x !== nodeId; // Remove\n })\n .map(function (x) {\n return x > nodeId ? x - 1 : x; // Shift indices\n });\n });\n};\n\nRemove.material = function (gltf, materialId) {\n const materials = gltf.materials;\n materials.splice(materialId, 1);\n\n // Shift other material ids\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n if (defined(primitive.material) && primitive.material > materialId) {\n primitive.material--;\n }\n });\n });\n};\n\nRemove.sampler = function (gltf, samplerId) {\n const samplers = gltf.samplers;\n samplers.splice(samplerId, 1);\n\n ForEach.texture(gltf, function (texture) {\n if (defined(texture.sampler)) {\n if (texture.sampler > samplerId) {\n --texture.sampler;\n }\n }\n });\n};\n\nRemove.texture = function (gltf, textureId) {\n const textures = gltf.textures;\n textures.splice(textureId, 1);\n\n ForEach.material(gltf, function (material) {\n forEachTextureInMaterial(material, function (textureIndex, textureInfo) {\n if (textureInfo.index > textureId) {\n --textureInfo.index;\n }\n });\n });\n\n if (usesExtension(gltf, \"EXT_feature_metadata\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n const extensions = primitive.extensions;\n if (defined(extensions) && defined(extensions.EXT_feature_metadata)) {\n const extension = extensions.EXT_feature_metadata;\n const featureIdTextures = extension.featureIdTextures;\n if (defined(featureIdTextures)) {\n const featureIdTexturesLength = featureIdTextures.length;\n for (let i = 0; i < featureIdTexturesLength; ++i) {\n const featureIdTexture = featureIdTextures[i];\n const textureInfo = featureIdTexture.featureIds.texture;\n if (textureInfo.index > textureId) {\n --textureInfo.index;\n }\n }\n }\n }\n });\n });\n\n const extension = gltf.extensions.EXT_feature_metadata;\n const featureTextures = extension.featureTextures;\n for (const featureTextureId in featureTextures) {\n if (featureTextures.hasOwnProperty(featureTextureId)) {\n const featureTexture = featureTextures[featureTextureId];\n const properties = featureTexture.properties;\n if (defined(properties)) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const textureInfo = property.texture;\n if (textureInfo.index > textureId) {\n --textureInfo.index;\n }\n }\n }\n }\n }\n }\n }\n\n if (usesExtension(gltf, \"EXT_mesh_features\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n const extensions = primitive.extensions;\n if (defined(extensions) && defined(extensions.EXT_mesh_features)) {\n const extension = extensions.EXT_mesh_features;\n const featureIds = extension.featureIds;\n if (defined(featureIds)) {\n const featureIdsLength = featureIds.length;\n for (let i = 0; i < featureIdsLength; ++i) {\n const featureId = featureIds[i];\n if (defined(featureId.texture)) {\n if (featureId.texture.index > textureId) {\n --featureId.texture.index;\n }\n }\n }\n }\n }\n });\n });\n }\n\n if (usesExtension(gltf, \"EXT_structural_metadata\")) {\n const extension = gltf.extensions.EXT_structural_metadata;\n const propertyTextures = extension.propertyTextures;\n if (defined(propertyTextures)) {\n const propertyTexturesLength = propertyTextures.length;\n for (let i = 0; i < propertyTexturesLength; ++i) {\n const propertyTexture = propertyTextures[i];\n const properties = propertyTexture.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (property.index > textureId) {\n --property.index;\n }\n }\n }\n }\n }\n }\n};\n\n/**\n * Contains functions for getting a list of element ids in use by the glTF asset.\n * @constructor\n *\n * @private\n */\nfunction getListOfElementsIdsInUse() {}\n\ngetListOfElementsIdsInUse.accessor = function (gltf) {\n // Calculate accessor's that are currently in use.\n const usedAccessorIds = {};\n\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n ForEach.meshPrimitiveAttribute(primitive, function (accessorId) {\n usedAccessorIds[accessorId] = true;\n });\n ForEach.meshPrimitiveTarget(primitive, function (target) {\n ForEach.meshPrimitiveTargetAttribute(target, function (accessorId) {\n usedAccessorIds[accessorId] = true;\n });\n });\n const indices = primitive.indices;\n if (defined(indices)) {\n usedAccessorIds[indices] = true;\n }\n });\n });\n\n ForEach.skin(gltf, function (skin) {\n if (defined(skin.inverseBindMatrices)) {\n usedAccessorIds[skin.inverseBindMatrices] = true;\n }\n });\n\n ForEach.animation(gltf, function (animation) {\n ForEach.animationSampler(animation, function (sampler) {\n if (defined(sampler.input)) {\n usedAccessorIds[sampler.input] = true;\n }\n if (defined(sampler.output)) {\n usedAccessorIds[sampler.output] = true;\n }\n });\n });\n\n if (usesExtension(gltf, \"EXT_mesh_gpu_instancing\")) {\n ForEach.node(gltf, function (node) {\n if (\n defined(node.extensions) &&\n defined(node.extensions.EXT_mesh_gpu_instancing)\n ) {\n Object.keys(node.extensions.EXT_mesh_gpu_instancing.attributes).forEach(\n function (key) {\n const attributeAccessorId =\n node.extensions.EXT_mesh_gpu_instancing.attributes[key];\n usedAccessorIds[attributeAccessorId] = true;\n }\n );\n }\n });\n }\n\n if (usesExtension(gltf, \"CESIUM_primitive_outline\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n const extensions = primitive.extensions;\n if (\n defined(extensions) &&\n defined(extensions.CESIUM_primitive_outline)\n ) {\n const extension = extensions.CESIUM_primitive_outline;\n const indicesAccessorId = extension.indices;\n if (defined(indicesAccessorId)) {\n usedAccessorIds[indicesAccessorId] = true;\n }\n }\n });\n });\n }\n\n return usedAccessorIds;\n};\n\ngetListOfElementsIdsInUse.buffer = function (gltf) {\n // Calculate buffer's that are currently in use.\n const usedBufferIds = {};\n\n ForEach.bufferView(gltf, function (bufferView) {\n if (defined(bufferView.buffer)) {\n usedBufferIds[bufferView.buffer] = true;\n }\n if (\n defined(bufferView.extensions) &&\n defined(bufferView.extensions.EXT_meshopt_compression)\n ) {\n usedBufferIds[\n bufferView.extensions.EXT_meshopt_compression.buffer\n ] = true;\n }\n });\n\n return usedBufferIds;\n};\n\ngetListOfElementsIdsInUse.bufferView = function (gltf) {\n // Calculate bufferView's that are currently in use.\n const usedBufferViewIds = {};\n\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.bufferView)) {\n usedBufferViewIds[accessor.bufferView] = true;\n }\n });\n\n ForEach.shader(gltf, function (shader) {\n if (defined(shader.bufferView)) {\n usedBufferViewIds[shader.bufferView] = true;\n }\n });\n\n ForEach.image(gltf, function (image) {\n if (defined(image.bufferView)) {\n usedBufferViewIds[image.bufferView] = true;\n }\n });\n\n if (usesExtension(gltf, \"KHR_draco_mesh_compression\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n if (\n defined(primitive.extensions) &&\n defined(primitive.extensions.KHR_draco_mesh_compression)\n ) {\n usedBufferViewIds[\n primitive.extensions.KHR_draco_mesh_compression.bufferView\n ] = true;\n }\n });\n });\n }\n\n if (usesExtension(gltf, \"EXT_feature_metadata\")) {\n const extension = gltf.extensions.EXT_feature_metadata;\n const featureTables = extension.featureTables;\n for (const featureTableId in featureTables) {\n if (featureTables.hasOwnProperty(featureTableId)) {\n const featureTable = featureTables[featureTableId];\n const properties = featureTable.properties;\n if (defined(properties)) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (defined(property.bufferView)) {\n usedBufferViewIds[property.bufferView] = true;\n }\n if (defined(property.arrayOffsetBufferView)) {\n usedBufferViewIds[property.arrayOffsetBufferView] = true;\n }\n if (defined(property.stringOffsetBufferView)) {\n usedBufferViewIds[property.stringOffsetBufferView] = true;\n }\n }\n }\n }\n }\n }\n }\n\n if (usesExtension(gltf, \"EXT_structural_metadata\")) {\n const extension = gltf.extensions.EXT_structural_metadata;\n const propertyTables = extension.propertyTables;\n if (defined(propertyTables)) {\n const propertyTablesLength = propertyTables.length;\n for (let i = 0; i < propertyTablesLength; ++i) {\n const propertyTable = propertyTables[i];\n const properties = propertyTable.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (defined(property.values)) {\n usedBufferViewIds[property.values] = true;\n }\n if (defined(property.arrayOffsets)) {\n usedBufferViewIds[property.arrayOffsets] = true;\n }\n if (defined(property.stringOffsets)) {\n usedBufferViewIds[property.stringOffsets] = true;\n }\n }\n }\n }\n }\n }\n\n return usedBufferViewIds;\n};\n\ngetListOfElementsIdsInUse.image = function (gltf) {\n const usedImageIds = {};\n\n ForEach.texture(gltf, function (texture) {\n if (defined(texture.source)) {\n usedImageIds[texture.source] = true;\n }\n\n if (\n defined(texture.extensions) &&\n defined(texture.extensions.EXT_texture_webp)\n ) {\n usedImageIds[texture.extensions.EXT_texture_webp.source] = true;\n } else if (\n defined(texture.extensions) &&\n defined(texture.extensions.KHR_texture_basisu)\n ) {\n usedImageIds[texture.extensions.KHR_texture_basisu.source] = true;\n }\n });\n return usedImageIds;\n};\n\ngetListOfElementsIdsInUse.mesh = function (gltf) {\n const usedMeshIds = {};\n ForEach.node(gltf, function (node) {\n if (defined(node.mesh && defined(gltf.meshes))) {\n const mesh = gltf.meshes[node.mesh];\n if (\n defined(mesh) &&\n defined(mesh.primitives) &&\n mesh.primitives.length > 0\n ) {\n usedMeshIds[node.mesh] = true;\n }\n }\n });\n\n return usedMeshIds;\n};\n\n// Check if node is empty. It is considered empty if neither referencing\n// mesh, camera, extensions and has no children\nfunction nodeIsEmpty(gltf, nodeId, usedNodeIds) {\n const node = gltf.nodes[nodeId];\n if (\n defined(node.mesh) ||\n defined(node.camera) ||\n defined(node.skin) ||\n defined(node.weights) ||\n defined(node.extras) ||\n (defined(node.extensions) && Object.keys(node.extensions).length !== 0) ||\n defined(usedNodeIds[nodeId])\n ) {\n return false;\n }\n\n // Empty if no children or children are all empty nodes\n return (\n !defined(node.children) ||\n node.children.filter(function (n) {\n return !nodeIsEmpty(gltf, n, usedNodeIds);\n }).length === 0\n );\n}\n\ngetListOfElementsIdsInUse.node = function (gltf) {\n const usedNodeIds = {};\n ForEach.skin(gltf, function (skin) {\n if (defined(skin.skeleton)) {\n usedNodeIds[skin.skeleton] = true;\n }\n\n ForEach.skinJoint(skin, function (joint) {\n usedNodeIds[joint] = true;\n });\n });\n ForEach.animation(gltf, function (animation) {\n ForEach.animationChannel(animation, function (channel) {\n if (defined(channel.target) && defined(channel.target.node)) {\n usedNodeIds[channel.target.node] = true;\n }\n });\n });\n ForEach.technique(gltf, function (technique) {\n ForEach.techniqueUniform(technique, function (uniform) {\n if (defined(uniform.node)) {\n usedNodeIds[uniform.node] = true;\n }\n });\n });\n ForEach.node(gltf, function (node, nodeId) {\n if (!nodeIsEmpty(gltf, nodeId, usedNodeIds)) {\n usedNodeIds[nodeId] = true;\n }\n });\n\n return usedNodeIds;\n};\n\ngetListOfElementsIdsInUse.material = function (gltf) {\n const usedMaterialIds = {};\n\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n if (defined(primitive.material)) {\n usedMaterialIds[primitive.material] = true;\n }\n });\n });\n\n return usedMaterialIds;\n};\n\ngetListOfElementsIdsInUse.texture = function (gltf) {\n const usedTextureIds = {};\n\n ForEach.material(gltf, function (material) {\n forEachTextureInMaterial(material, function (textureId) {\n usedTextureIds[textureId] = true;\n });\n });\n\n if (usesExtension(gltf, \"EXT_feature_metadata\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n const extensions = primitive.extensions;\n if (defined(extensions) && defined(extensions.EXT_feature_metadata)) {\n const extension = extensions.EXT_feature_metadata;\n const featureIdTextures = extension.featureIdTextures;\n if (defined(featureIdTextures)) {\n const featureIdTexturesLength = featureIdTextures.length;\n for (let i = 0; i < featureIdTexturesLength; ++i) {\n const featureIdTexture = featureIdTextures[i];\n const textureInfo = featureIdTexture.featureIds.texture;\n usedTextureIds[textureInfo.index] = true;\n }\n }\n }\n });\n });\n\n const extension = gltf.extensions.EXT_feature_metadata;\n const featureTextures = extension.featureTextures;\n for (const featureTextureId in featureTextures) {\n if (featureTextures.hasOwnProperty(featureTextureId)) {\n const featureTexture = featureTextures[featureTextureId];\n const properties = featureTexture.properties;\n if (defined(properties)) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const textureInfo = property.texture;\n usedTextureIds[textureInfo.index] = true;\n }\n }\n }\n }\n }\n }\n\n if (usesExtension(gltf, \"EXT_mesh_features\")) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n const extensions = primitive.extensions;\n if (defined(extensions) && defined(extensions.EXT_mesh_features)) {\n const extension = extensions.EXT_mesh_features;\n const featureIds = extension.featureIds;\n if (defined(featureIds)) {\n const featureIdsLength = featureIds.length;\n for (let i = 0; i < featureIdsLength; ++i) {\n const featureId = featureIds[i];\n if (defined(featureId.texture)) {\n usedTextureIds[featureId.texture.index] = true;\n }\n }\n }\n }\n });\n });\n }\n\n if (usesExtension(gltf, \"EXT_structural_metadata\")) {\n const extension = gltf.extensions.EXT_structural_metadata;\n const propertyTextures = extension.propertyTextures;\n if (defined(propertyTextures)) {\n const propertyTexturesLength = propertyTextures.length;\n for (let i = 0; i < propertyTexturesLength; ++i) {\n const propertyTexture = propertyTextures[i];\n const properties = propertyTexture.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n usedTextureIds[property.index] = true;\n }\n }\n }\n }\n }\n\n return usedTextureIds;\n};\n\ngetListOfElementsIdsInUse.sampler = function (gltf) {\n const usedSamplerIds = {};\n\n ForEach.texture(gltf, function (texture) {\n if (defined(texture.sampler)) {\n usedSamplerIds[texture.sampler] = true;\n }\n });\n\n return usedSamplerIds;\n};\n\nexport default removeUnusedElements;\n", "import addToArray from \"./addToArray.js\";\n\n/**\n * Adds buffer to gltf.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {Buffer} buffer A Buffer object which will be added to gltf.buffers.\n * @returns {number} The bufferView id of the newly added bufferView.\n *\n * @private\n */\nfunction addBuffer(gltf, buffer) {\n const newBuffer = {\n byteLength: buffer.length,\n extras: {\n _pipeline: {\n source: buffer,\n },\n },\n };\n const bufferId = addToArray(gltf.buffers, newBuffer);\n const bufferView = {\n buffer: bufferId,\n byteOffset: 0,\n byteLength: buffer.length,\n };\n return addToArray(gltf.bufferViews, bufferView);\n}\n\nexport default addBuffer;\n", "import getAccessorByteStride from \"./getAccessorByteStride.js\";\nimport getComponentReader from \"./getComponentReader.js\";\nimport numberOfComponentsForType from \"./numberOfComponentsForType.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Returns the accessor data in a contiguous array.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {object} accessor The accessor.\n * @returns {Array} The accessor values in a contiguous array.\n *\n * @private\n */\nfunction readAccessorPacked(gltf, accessor) {\n const byteStride = getAccessorByteStride(gltf, accessor);\n const componentTypeByteLength = ComponentDatatype.getSizeInBytes(\n accessor.componentType\n );\n const numberOfComponents = numberOfComponentsForType(accessor.type);\n const count = accessor.count;\n const values = new Array(numberOfComponents * count);\n\n if (!defined(accessor.bufferView)) {\n return values.fill(0);\n }\n\n const bufferView = gltf.bufferViews[accessor.bufferView];\n const source = gltf.buffers[bufferView.buffer].extras._pipeline.source;\n let byteOffset =\n accessor.byteOffset + bufferView.byteOffset + source.byteOffset;\n\n const dataView = new DataView(source.buffer);\n const components = new Array(numberOfComponents);\n const componentReader = getComponentReader(accessor.componentType);\n\n for (let i = 0; i < count; ++i) {\n componentReader(\n dataView,\n byteOffset,\n numberOfComponents,\n componentTypeByteLength,\n components\n );\n for (let j = 0; j < numberOfComponents; ++j) {\n values[i * numberOfComponents + j] = components[j];\n }\n byteOffset += byteStride;\n }\n return values;\n}\n\nexport default readAccessorPacked;\n", "import addBuffer from \"./addBuffer.js\";\nimport ForEach from \"./ForEach.js\";\nimport readAccessorPacked from \"./readAccessorPacked.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\n\n/**\n * Update accessors referenced by JOINTS_0 and WEIGHTS_0 attributes to use correct component types.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @returns {object} The glTF asset with compressed meshes.\n *\n * @private\n */\nfunction updateAccessorComponentTypes(gltf) {\n let componentType;\n ForEach.accessorWithSemantic(gltf, \"JOINTS_0\", function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n componentType = accessor.componentType;\n if (componentType === WebGLConstants.BYTE) {\n convertType(gltf, accessor, ComponentDatatype.UNSIGNED_BYTE);\n } else if (\n componentType !== WebGLConstants.UNSIGNED_BYTE &&\n componentType !== WebGLConstants.UNSIGNED_SHORT\n ) {\n convertType(gltf, accessor, ComponentDatatype.UNSIGNED_SHORT);\n }\n });\n ForEach.accessorWithSemantic(gltf, \"WEIGHTS_0\", function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n componentType = accessor.componentType;\n if (componentType === WebGLConstants.BYTE) {\n convertType(gltf, accessor, ComponentDatatype.UNSIGNED_BYTE);\n } else if (componentType === WebGLConstants.SHORT) {\n convertType(gltf, accessor, ComponentDatatype.UNSIGNED_SHORT);\n }\n });\n\n return gltf;\n}\n\nfunction convertType(gltf, accessor, updatedComponentType) {\n const typedArray = ComponentDatatype.createTypedArray(\n updatedComponentType,\n readAccessorPacked(gltf, accessor)\n );\n const newBuffer = new Uint8Array(typedArray.buffer);\n accessor.bufferView = addBuffer(gltf, newBuffer);\n accessor.componentType = updatedComponentType;\n accessor.byteOffset = 0;\n}\n\nexport default updateAccessorComponentTypes;\n", "import ForEach from \"./ForEach.js\";\nimport removeExtensionsUsed from \"./removeExtensionsUsed.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * Removes an extension from gltf.extensions, gltf.extensionsUsed, gltf.extensionsRequired, and any other objects in the glTF if it is present.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {string} extension The extension to remove.\n *\n * @returns {*} The extension data removed from gltf.extensions.\n */\nfunction removeExtension(gltf, extension) {\n removeExtensionsUsed(gltf, extension); // Also removes from extensionsRequired\n\n if (extension === \"CESIUM_RTC\") {\n removeCesiumRTC(gltf);\n }\n\n return removeExtensionAndTraverse(gltf, extension);\n}\n\nfunction removeCesiumRTC(gltf) {\n ForEach.technique(gltf, function (technique) {\n ForEach.techniqueUniform(technique, function (uniform) {\n if (uniform.semantic === \"CESIUM_RTC_MODELVIEW\") {\n uniform.semantic = \"MODELVIEW\";\n }\n });\n });\n}\n\nfunction removeExtensionAndTraverse(object, extension) {\n if (Array.isArray(object)) {\n const length = object.length;\n for (let i = 0; i < length; ++i) {\n removeExtensionAndTraverse(object[i], extension);\n }\n } else if (\n object !== null &&\n typeof object === \"object\" &&\n object.constructor === Object\n ) {\n const extensions = object.extensions;\n let extensionData;\n if (defined(extensions)) {\n extensionData = extensions[extension];\n if (defined(extensionData)) {\n delete extensions[extension];\n if (Object.keys(extensions).length === 0) {\n delete object.extensions;\n }\n }\n }\n for (const key in object) {\n if (Object.prototype.hasOwnProperty.call(object, key)) {\n removeExtensionAndTraverse(object[key], extension);\n }\n }\n return extensionData;\n }\n}\n\nexport default removeExtension;\n", "import addExtensionsUsed from \"./addExtensionsUsed.js\";\nimport addToArray from \"./addToArray.js\";\nimport findAccessorMinMax from \"./findAccessorMinMax.js\";\nimport ForEach from \"./ForEach.js\";\nimport getAccessorByteStride from \"./getAccessorByteStride.js\";\nimport numberOfComponentsForType from \"./numberOfComponentsForType.js\";\nimport moveTechniqueRenderStates from \"./moveTechniqueRenderStates.js\";\nimport moveTechniquesToExtension from \"./moveTechniquesToExtension.js\";\nimport removeUnusedElements from \"./removeUnusedElements.js\";\nimport updateAccessorComponentTypes from \"./updateAccessorComponentTypes.js\";\nimport removeExtension from \"./removeExtension.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Cartesian4 from \"../../Core/Cartesian4.js\";\nimport clone from \"../../Core/clone.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\n\nconst updateFunctions = {\n 0.8: glTF08to10,\n \"1.0\": glTF10to20,\n \"2.0\": undefined,\n};\n\n/**\n * Update the glTF version to the latest version (2.0), or targetVersion if specified.\n * Applies changes made to the glTF spec between revisions so that the core library\n * only has to handle the latest version.\n *\n * @param {object} gltf A javascript object containing a glTF asset.\n * @param {object} [options] Options for updating the glTF.\n * @param {string} [options.targetVersion] The glTF will be upgraded until it hits the specified version.\n * @param {string[]} [options.baseColorTextureNames] Names of uniforms that indicate base color textures.\n * @param {string[]} [options.baseColorFactorNames] Names of uniforms that indicate base color factors.\n * @returns {object} The updated glTF asset.\n *\n * @private\n */\nfunction updateVersion(gltf, options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const targetVersion = options.targetVersion;\n let version = gltf.version;\n\n gltf.asset = defaultValue(gltf.asset, {\n version: \"1.0\",\n });\n\n gltf.asset.version = defaultValue(gltf.asset.version, \"1.0\");\n version = defaultValue(version, gltf.asset.version).toString();\n\n // Invalid version\n if (!Object.prototype.hasOwnProperty.call(updateFunctions, version)) {\n // Try truncating trailing version numbers, could be a number as well if it is 0.8\n if (defined(version)) {\n version = version.substring(0, 3);\n }\n // Default to 1.0 if it cannot be determined\n if (!Object.prototype.hasOwnProperty.call(updateFunctions, version)) {\n version = \"1.0\";\n }\n }\n\n let updateFunction = updateFunctions[version];\n\n while (defined(updateFunction)) {\n if (version === targetVersion) {\n break;\n }\n updateFunction(gltf, options);\n version = gltf.asset.version;\n updateFunction = updateFunctions[version];\n }\n\n if (!options.keepLegacyExtensions) {\n convertTechniquesToPbr(gltf, options);\n convertMaterialsCommonToPbr(gltf);\n }\n\n return gltf;\n}\n\nfunction updateInstanceTechniques(gltf) {\n const materials = gltf.materials;\n for (const materialId in materials) {\n if (Object.prototype.hasOwnProperty.call(materials, materialId)) {\n const material = materials[materialId];\n const instanceTechnique = material.instanceTechnique;\n if (defined(instanceTechnique)) {\n material.technique = instanceTechnique.technique;\n material.values = instanceTechnique.values;\n delete material.instanceTechnique;\n }\n }\n }\n}\n\nfunction setPrimitiveModes(gltf) {\n const meshes = gltf.meshes;\n for (const meshId in meshes) {\n if (Object.prototype.hasOwnProperty.call(meshes, meshId)) {\n const mesh = meshes[meshId];\n const primitives = mesh.primitives;\n if (defined(primitives)) {\n const primitivesLength = primitives.length;\n for (let i = 0; i < primitivesLength; ++i) {\n const primitive = primitives[i];\n const defaultMode = defaultValue(\n primitive.primitive,\n WebGLConstants.TRIANGLES\n );\n primitive.mode = defaultValue(primitive.mode, defaultMode);\n delete primitive.primitive;\n }\n }\n }\n }\n}\n\nfunction updateNodes(gltf) {\n const nodes = gltf.nodes;\n const axis = new Cartesian3();\n const quat = new Quaternion();\n for (const nodeId in nodes) {\n if (Object.prototype.hasOwnProperty.call(nodes, nodeId)) {\n const node = nodes[nodeId];\n if (defined(node.rotation)) {\n const rotation = node.rotation;\n Cartesian3.fromArray(rotation, 0, axis);\n Quaternion.fromAxisAngle(axis, rotation[3], quat);\n node.rotation = [quat.x, quat.y, quat.z, quat.w];\n }\n const instanceSkin = node.instanceSkin;\n if (defined(instanceSkin)) {\n node.skeletons = instanceSkin.skeletons;\n node.skin = instanceSkin.skin;\n node.meshes = instanceSkin.meshes;\n delete node.instanceSkin;\n }\n }\n }\n}\n\nfunction updateAnimations(gltf) {\n const animations = gltf.animations;\n const accessors = gltf.accessors;\n const bufferViews = gltf.bufferViews;\n const buffers = gltf.buffers;\n const updatedAccessors = {};\n const axis = new Cartesian3();\n const quat = new Quaternion();\n for (const animationId in animations) {\n if (Object.prototype.hasOwnProperty.call(animations, animationId)) {\n const animation = animations[animationId];\n const channels = animation.channels;\n const parameters = animation.parameters;\n const samplers = animation.samplers;\n if (defined(channels)) {\n const channelsLength = channels.length;\n for (let i = 0; i < channelsLength; ++i) {\n const channel = channels[i];\n if (channel.target.path === \"rotation\") {\n const accessorId = parameters[samplers[channel.sampler].output];\n if (defined(updatedAccessors[accessorId])) {\n continue;\n }\n updatedAccessors[accessorId] = true;\n const accessor = accessors[accessorId];\n const bufferView = bufferViews[accessor.bufferView];\n const buffer = buffers[bufferView.buffer];\n const source = buffer.extras._pipeline.source;\n const byteOffset =\n source.byteOffset + bufferView.byteOffset + accessor.byteOffset;\n const componentType = accessor.componentType;\n const count = accessor.count;\n const componentsLength = numberOfComponentsForType(accessor.type);\n const length = accessor.count * componentsLength;\n const typedArray = ComponentDatatype.createArrayBufferView(\n componentType,\n source.buffer,\n byteOffset,\n length\n );\n\n for (let j = 0; j < count; j++) {\n const offset = j * componentsLength;\n Cartesian3.unpack(typedArray, offset, axis);\n const angle = typedArray[offset + 3];\n Quaternion.fromAxisAngle(axis, angle, quat);\n Quaternion.pack(quat, typedArray, offset);\n }\n }\n }\n }\n }\n }\n}\n\nfunction removeTechniquePasses(gltf) {\n const techniques = gltf.techniques;\n for (const techniqueId in techniques) {\n if (Object.prototype.hasOwnProperty.call(techniques, techniqueId)) {\n const technique = techniques[techniqueId];\n const passes = technique.passes;\n if (defined(passes)) {\n const passName = defaultValue(technique.pass, \"defaultPass\");\n if (Object.prototype.hasOwnProperty.call(passes, passName)) {\n const pass = passes[passName];\n const instanceProgram = pass.instanceProgram;\n technique.attributes = defaultValue(\n technique.attributes,\n instanceProgram.attributes\n );\n technique.program = defaultValue(\n technique.program,\n instanceProgram.program\n );\n technique.uniforms = defaultValue(\n technique.uniforms,\n instanceProgram.uniforms\n );\n technique.states = defaultValue(technique.states, pass.states);\n }\n delete technique.passes;\n delete technique.pass;\n }\n }\n }\n}\n\nfunction glTF08to10(gltf) {\n if (!defined(gltf.asset)) {\n gltf.asset = {};\n }\n const asset = gltf.asset;\n asset.version = \"1.0\";\n // Profile should be an object, not a string\n if (typeof asset.profile === \"string\") {\n const split = asset.profile.split(\" \");\n asset.profile = {\n api: split[0],\n version: split[1],\n };\n } else {\n asset.profile = {};\n }\n\n // Version property should be in asset, not on the root element\n if (defined(gltf.version)) {\n delete gltf.version;\n }\n // material.instanceTechnique properties should be directly on the material\n updateInstanceTechniques(gltf);\n // primitive.primitive should be primitive.mode\n setPrimitiveModes(gltf);\n // Node rotation should be quaternion, not axis-angle\n // node.instanceSkin is deprecated\n updateNodes(gltf);\n // Animations that target rotations should be quaternion, not axis-angle\n updateAnimations(gltf);\n // technique.pass and techniques.passes are deprecated\n removeTechniquePasses(gltf);\n // gltf.allExtensions -> extensionsUsed\n if (defined(gltf.allExtensions)) {\n gltf.extensionsUsed = gltf.allExtensions;\n delete gltf.allExtensions;\n }\n // gltf.lights -> khrMaterialsCommon.lights\n if (defined(gltf.lights)) {\n const extensions = defaultValue(gltf.extensions, {});\n gltf.extensions = extensions;\n const materialsCommon = defaultValue(extensions.KHR_materials_common, {});\n extensions.KHR_materials_common = materialsCommon;\n materialsCommon.lights = gltf.lights;\n delete gltf.lights;\n addExtensionsUsed(gltf, \"KHR_materials_common\");\n }\n}\n\nfunction removeAnimationSamplersIndirection(gltf) {\n const animations = gltf.animations;\n for (const animationId in animations) {\n if (Object.prototype.hasOwnProperty.call(animations, animationId)) {\n const animation = animations[animationId];\n const parameters = animation.parameters;\n if (defined(parameters)) {\n const samplers = animation.samplers;\n for (const samplerId in samplers) {\n if (Object.prototype.hasOwnProperty.call(samplers, samplerId)) {\n const sampler = samplers[samplerId];\n sampler.input = parameters[sampler.input];\n sampler.output = parameters[sampler.output];\n }\n }\n delete animation.parameters;\n }\n }\n }\n}\n\nfunction objectToArray(object, mapping) {\n const array = [];\n for (const id in object) {\n if (Object.prototype.hasOwnProperty.call(object, id)) {\n const value = object[id];\n mapping[id] = array.length;\n array.push(value);\n if (!defined(value.name)) {\n value.name = id;\n }\n }\n }\n return array;\n}\n\nfunction objectsToArrays(gltf) {\n let i;\n const globalMapping = {\n accessors: {},\n animations: {},\n buffers: {},\n bufferViews: {},\n cameras: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n programs: {},\n samplers: {},\n scenes: {},\n shaders: {},\n skins: {},\n textures: {},\n techniques: {},\n };\n\n // Map joint names to id names\n let jointName;\n const jointNameToId = {};\n const nodes = gltf.nodes;\n for (const id in nodes) {\n if (Object.prototype.hasOwnProperty.call(nodes, id)) {\n jointName = nodes[id].jointName;\n if (defined(jointName)) {\n jointNameToId[jointName] = id;\n }\n }\n }\n\n // Convert top level objects to arrays\n for (const topLevelId in gltf) {\n if (\n Object.prototype.hasOwnProperty.call(gltf, topLevelId) &&\n defined(globalMapping[topLevelId])\n ) {\n const objectMapping = {};\n const object = gltf[topLevelId];\n gltf[topLevelId] = objectToArray(object, objectMapping);\n globalMapping[topLevelId] = objectMapping;\n }\n }\n\n // Remap joint names to array indexes\n for (jointName in jointNameToId) {\n if (Object.prototype.hasOwnProperty.call(jointNameToId, jointName)) {\n jointNameToId[jointName] = globalMapping.nodes[jointNameToId[jointName]];\n }\n }\n\n // Fix references\n if (defined(gltf.scene)) {\n gltf.scene = globalMapping.scenes[gltf.scene];\n }\n ForEach.bufferView(gltf, function (bufferView) {\n if (defined(bufferView.buffer)) {\n bufferView.buffer = globalMapping.buffers[bufferView.buffer];\n }\n });\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.bufferView)) {\n accessor.bufferView = globalMapping.bufferViews[accessor.bufferView];\n }\n });\n ForEach.shader(gltf, function (shader) {\n const extensions = shader.extensions;\n if (defined(extensions)) {\n const binaryGltf = extensions.KHR_binary_glTF;\n if (defined(binaryGltf)) {\n shader.bufferView = globalMapping.bufferViews[binaryGltf.bufferView];\n delete extensions.KHR_binary_glTF;\n }\n if (Object.keys(extensions).length === 0) {\n delete shader.extensions;\n }\n }\n });\n ForEach.program(gltf, function (program) {\n if (defined(program.vertexShader)) {\n program.vertexShader = globalMapping.shaders[program.vertexShader];\n }\n if (defined(program.fragmentShader)) {\n program.fragmentShader = globalMapping.shaders[program.fragmentShader];\n }\n });\n ForEach.technique(gltf, function (technique) {\n if (defined(technique.program)) {\n technique.program = globalMapping.programs[technique.program];\n }\n ForEach.techniqueParameter(technique, function (parameter) {\n if (defined(parameter.node)) {\n parameter.node = globalMapping.nodes[parameter.node];\n }\n const value = parameter.value;\n if (typeof value === \"string\") {\n parameter.value = {\n index: globalMapping.textures[value],\n };\n }\n });\n });\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n if (defined(primitive.indices)) {\n primitive.indices = globalMapping.accessors[primitive.indices];\n }\n ForEach.meshPrimitiveAttribute(\n primitive,\n function (accessorId, semantic) {\n primitive.attributes[semantic] = globalMapping.accessors[accessorId];\n }\n );\n if (defined(primitive.material)) {\n primitive.material = globalMapping.materials[primitive.material];\n }\n });\n });\n ForEach.node(gltf, function (node) {\n let children = node.children;\n if (defined(children)) {\n const childrenLength = children.length;\n for (i = 0; i < childrenLength; ++i) {\n children[i] = globalMapping.nodes[children[i]];\n }\n }\n if (defined(node.meshes)) {\n // Split out meshes on nodes\n const meshes = node.meshes;\n const meshesLength = meshes.length;\n if (meshesLength > 0) {\n node.mesh = globalMapping.meshes[meshes[0]];\n for (i = 1; i < meshesLength; ++i) {\n const meshNode = {\n mesh: globalMapping.meshes[meshes[i]],\n };\n const meshNodeId = addToArray(gltf.nodes, meshNode);\n if (!defined(children)) {\n children = [];\n node.children = children;\n }\n children.push(meshNodeId);\n }\n }\n delete node.meshes;\n }\n if (defined(node.camera)) {\n node.camera = globalMapping.cameras[node.camera];\n }\n if (defined(node.skin)) {\n node.skin = globalMapping.skins[node.skin];\n }\n if (defined(node.skeletons)) {\n // Assign skeletons to skins\n const skeletons = node.skeletons;\n const skeletonsLength = skeletons.length;\n if (skeletonsLength > 0 && defined(node.skin)) {\n const skin = gltf.skins[node.skin];\n skin.skeleton = globalMapping.nodes[skeletons[0]];\n }\n delete node.skeletons;\n }\n if (defined(node.jointName)) {\n delete node.jointName;\n }\n });\n ForEach.skin(gltf, function (skin) {\n if (defined(skin.inverseBindMatrices)) {\n skin.inverseBindMatrices =\n globalMapping.accessors[skin.inverseBindMatrices];\n }\n const jointNames = skin.jointNames;\n if (defined(jointNames)) {\n const joints = [];\n const jointNamesLength = jointNames.length;\n for (i = 0; i < jointNamesLength; ++i) {\n joints[i] = jointNameToId[jointNames[i]];\n }\n skin.joints = joints;\n delete skin.jointNames;\n }\n });\n ForEach.scene(gltf, function (scene) {\n const sceneNodes = scene.nodes;\n if (defined(sceneNodes)) {\n const sceneNodesLength = sceneNodes.length;\n for (i = 0; i < sceneNodesLength; ++i) {\n sceneNodes[i] = globalMapping.nodes[sceneNodes[i]];\n }\n }\n });\n ForEach.animation(gltf, function (animation) {\n const samplerMapping = {};\n animation.samplers = objectToArray(animation.samplers, samplerMapping);\n ForEach.animationSampler(animation, function (sampler) {\n sampler.input = globalMapping.accessors[sampler.input];\n sampler.output = globalMapping.accessors[sampler.output];\n });\n ForEach.animationChannel(animation, function (channel) {\n channel.sampler = samplerMapping[channel.sampler];\n const target = channel.target;\n if (defined(target)) {\n target.node = globalMapping.nodes[target.id];\n delete target.id;\n }\n });\n });\n ForEach.material(gltf, function (material) {\n if (defined(material.technique)) {\n material.technique = globalMapping.techniques[material.technique];\n }\n ForEach.materialValue(material, function (value, name) {\n if (typeof value === \"string\") {\n material.values[name] = {\n index: globalMapping.textures[value],\n };\n }\n });\n const extensions = material.extensions;\n if (defined(extensions)) {\n const materialsCommon = extensions.KHR_materials_common;\n if (defined(materialsCommon) && defined(materialsCommon.values)) {\n ForEach.materialValue(materialsCommon, function (value, name) {\n if (typeof value === \"string\") {\n materialsCommon.values[name] = {\n index: globalMapping.textures[value],\n };\n }\n });\n }\n }\n });\n ForEach.image(gltf, function (image) {\n const extensions = image.extensions;\n if (defined(extensions)) {\n const binaryGltf = extensions.KHR_binary_glTF;\n if (defined(binaryGltf)) {\n image.bufferView = globalMapping.bufferViews[binaryGltf.bufferView];\n image.mimeType = binaryGltf.mimeType;\n delete extensions.KHR_binary_glTF;\n }\n if (Object.keys(extensions).length === 0) {\n delete image.extensions;\n }\n }\n });\n ForEach.texture(gltf, function (texture) {\n if (defined(texture.sampler)) {\n texture.sampler = globalMapping.samplers[texture.sampler];\n }\n if (defined(texture.source)) {\n texture.source = globalMapping.images[texture.source];\n }\n });\n}\n\nfunction removeAnimationSamplerNames(gltf) {\n ForEach.animation(gltf, function (animation) {\n ForEach.animationSampler(animation, function (sampler) {\n delete sampler.name;\n });\n });\n}\n\nfunction removeEmptyArrays(gltf) {\n for (const topLevelId in gltf) {\n if (Object.prototype.hasOwnProperty.call(gltf, topLevelId)) {\n const array = gltf[topLevelId];\n if (Array.isArray(array) && array.length === 0) {\n delete gltf[topLevelId];\n }\n }\n }\n ForEach.node(gltf, function (node) {\n if (defined(node.children) && node.children.length === 0) {\n delete node.children;\n }\n });\n}\n\nfunction stripAsset(gltf) {\n const asset = gltf.asset;\n delete asset.profile;\n delete asset.premultipliedAlpha;\n}\n\nconst knownExtensions = {\n CESIUM_RTC: true,\n KHR_materials_common: true,\n WEB3D_quantized_attributes: true,\n};\nfunction requireKnownExtensions(gltf) {\n const extensionsUsed = gltf.extensionsUsed;\n gltf.extensionsRequired = defaultValue(gltf.extensionsRequired, []);\n if (defined(extensionsUsed)) {\n const extensionsUsedLength = extensionsUsed.length;\n for (let i = 0; i < extensionsUsedLength; ++i) {\n const extension = extensionsUsed[i];\n if (defined(knownExtensions[extension])) {\n gltf.extensionsRequired.push(extension);\n }\n }\n }\n}\n\nfunction removeBufferType(gltf) {\n ForEach.buffer(gltf, function (buffer) {\n delete buffer.type;\n });\n}\n\nfunction removeTextureProperties(gltf) {\n ForEach.texture(gltf, function (texture) {\n delete texture.format;\n delete texture.internalFormat;\n delete texture.target;\n delete texture.type;\n });\n}\n\nfunction requireAttributeSetIndex(gltf) {\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n ForEach.meshPrimitiveAttribute(\n primitive,\n function (accessorId, semantic) {\n if (semantic === \"TEXCOORD\") {\n primitive.attributes.TEXCOORD_0 = accessorId;\n } else if (semantic === \"COLOR\") {\n primitive.attributes.COLOR_0 = accessorId;\n }\n }\n );\n delete primitive.attributes.TEXCOORD;\n delete primitive.attributes.COLOR;\n });\n });\n ForEach.technique(gltf, function (technique) {\n ForEach.techniqueParameter(technique, function (parameter) {\n const semantic = parameter.semantic;\n if (defined(semantic)) {\n if (semantic === \"TEXCOORD\") {\n parameter.semantic = \"TEXCOORD_0\";\n } else if (semantic === \"COLOR\") {\n parameter.semantic = \"COLOR_0\";\n }\n }\n });\n });\n}\n\nconst knownSemantics = {\n POSITION: true,\n NORMAL: true,\n TANGENT: true,\n};\nconst indexedSemantics = {\n COLOR: \"COLOR\",\n JOINT: \"JOINTS\",\n JOINTS: \"JOINTS\",\n TEXCOORD: \"TEXCOORD\",\n WEIGHT: \"WEIGHTS\",\n WEIGHTS: \"WEIGHTS\",\n};\nfunction underscoreApplicationSpecificSemantics(gltf) {\n const mappedSemantics = {};\n ForEach.mesh(gltf, function (mesh) {\n ForEach.meshPrimitive(mesh, function (primitive) {\n /*eslint-disable no-unused-vars*/\n ForEach.meshPrimitiveAttribute(\n primitive,\n function (accessorId, semantic) {\n if (semantic.charAt(0) !== \"_\") {\n const setIndex = semantic.search(/_[0-9]+/g);\n let strippedSemantic = semantic;\n let suffix = \"_0\";\n if (setIndex >= 0) {\n strippedSemantic = semantic.substring(0, setIndex);\n suffix = semantic.substring(setIndex);\n }\n let newSemantic;\n const indexedSemantic = indexedSemantics[strippedSemantic];\n if (defined(indexedSemantic)) {\n newSemantic = indexedSemantic + suffix;\n mappedSemantics[semantic] = newSemantic;\n } else if (!defined(knownSemantics[strippedSemantic])) {\n newSemantic = `_${semantic}`;\n mappedSemantics[semantic] = newSemantic;\n }\n }\n }\n );\n for (const semantic in mappedSemantics) {\n if (Object.prototype.hasOwnProperty.call(mappedSemantics, semantic)) {\n const mappedSemantic = mappedSemantics[semantic];\n const accessorId = primitive.attributes[semantic];\n if (defined(accessorId)) {\n delete primitive.attributes[semantic];\n primitive.attributes[mappedSemantic] = accessorId;\n }\n }\n }\n });\n });\n ForEach.technique(gltf, function (technique) {\n ForEach.techniqueParameter(technique, function (parameter) {\n const mappedSemantic = mappedSemantics[parameter.semantic];\n if (defined(mappedSemantic)) {\n parameter.semantic = mappedSemantic;\n }\n });\n });\n}\n\nfunction clampCameraParameters(gltf) {\n ForEach.camera(gltf, function (camera) {\n const perspective = camera.perspective;\n if (defined(perspective)) {\n const aspectRatio = perspective.aspectRatio;\n if (defined(aspectRatio) && aspectRatio === 0.0) {\n delete perspective.aspectRatio;\n }\n const yfov = perspective.yfov;\n if (defined(yfov) && yfov === 0.0) {\n perspective.yfov = 1.0;\n }\n }\n });\n}\n\nfunction computeAccessorByteStride(gltf, accessor) {\n return defined(accessor.byteStride) && accessor.byteStride !== 0\n ? accessor.byteStride\n : getAccessorByteStride(gltf, accessor);\n}\n\nfunction requireByteLength(gltf) {\n ForEach.buffer(gltf, function (buffer) {\n if (!defined(buffer.byteLength)) {\n buffer.byteLength = buffer.extras._pipeline.source.length;\n }\n });\n ForEach.accessor(gltf, function (accessor) {\n const bufferViewId = accessor.bufferView;\n if (defined(bufferViewId)) {\n const bufferView = gltf.bufferViews[bufferViewId];\n const accessorByteStride = computeAccessorByteStride(gltf, accessor);\n const accessorByteEnd =\n accessor.byteOffset + accessor.count * accessorByteStride;\n bufferView.byteLength = Math.max(\n defaultValue(bufferView.byteLength, 0),\n accessorByteEnd\n );\n }\n });\n}\n\nfunction moveByteStrideToBufferView(gltf) {\n let i;\n let j;\n let bufferView;\n const bufferViews = gltf.bufferViews;\n\n const bufferViewHasVertexAttributes = {};\n ForEach.accessorContainingVertexAttributeData(gltf, function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n if (defined(accessor.bufferView)) {\n bufferViewHasVertexAttributes[accessor.bufferView] = true;\n }\n });\n\n // Map buffer views to a list of accessors\n const bufferViewMap = {};\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.bufferView)) {\n bufferViewMap[accessor.bufferView] = defaultValue(\n bufferViewMap[accessor.bufferView],\n []\n );\n bufferViewMap[accessor.bufferView].push(accessor);\n }\n });\n\n // Split accessors with different byte strides\n for (const bufferViewId in bufferViewMap) {\n if (Object.prototype.hasOwnProperty.call(bufferViewMap, bufferViewId)) {\n bufferView = bufferViews[bufferViewId];\n const accessors = bufferViewMap[bufferViewId];\n accessors.sort(function (a, b) {\n return a.byteOffset - b.byteOffset;\n });\n let currentByteOffset = 0;\n let currentIndex = 0;\n const accessorsLength = accessors.length;\n for (i = 0; i < accessorsLength; ++i) {\n let accessor = accessors[i];\n const accessorByteStride = computeAccessorByteStride(gltf, accessor);\n const accessorByteOffset = accessor.byteOffset;\n const accessorByteLength = accessor.count * accessorByteStride;\n delete accessor.byteStride;\n\n const hasNextAccessor = i < accessorsLength - 1;\n const nextAccessorByteStride = hasNextAccessor\n ? computeAccessorByteStride(gltf, accessors[i + 1])\n : undefined;\n if (accessorByteStride !== nextAccessorByteStride) {\n const newBufferView = clone(bufferView, true);\n if (bufferViewHasVertexAttributes[bufferViewId]) {\n newBufferView.byteStride = accessorByteStride;\n }\n newBufferView.byteOffset += currentByteOffset;\n newBufferView.byteLength =\n accessorByteOffset + accessorByteLength - currentByteOffset;\n const newBufferViewId = addToArray(bufferViews, newBufferView);\n for (j = currentIndex; j <= i; ++j) {\n accessor = accessors[j];\n accessor.bufferView = newBufferViewId;\n accessor.byteOffset = accessor.byteOffset - currentByteOffset;\n }\n // Set current byte offset to next accessor's byte offset\n currentByteOffset = hasNextAccessor\n ? accessors[i + 1].byteOffset\n : undefined;\n currentIndex = i + 1;\n }\n }\n }\n }\n\n // Remove unused buffer views\n removeUnusedElements(gltf, [\"accessor\", \"bufferView\", \"buffer\"]);\n}\n\nfunction requirePositionAccessorMinMax(gltf) {\n ForEach.accessorWithSemantic(gltf, \"POSITION\", function (accessorId) {\n const accessor = gltf.accessors[accessorId];\n if (!defined(accessor.min) || !defined(accessor.max)) {\n const minMax = findAccessorMinMax(gltf, accessor);\n accessor.min = minMax.min;\n accessor.max = minMax.max;\n }\n });\n}\n\nfunction isNodeEmpty(node) {\n return (\n (!defined(node.children) || node.children.length === 0) &&\n (!defined(node.meshes) || node.meshes.length === 0) &&\n !defined(node.camera) &&\n !defined(node.skin) &&\n !defined(node.skeletons) &&\n !defined(node.jointName) &&\n (!defined(node.translation) ||\n Cartesian3.fromArray(node.translation).equals(Cartesian3.ZERO)) &&\n (!defined(node.scale) ||\n Cartesian3.fromArray(node.scale).equals(new Cartesian3(1.0, 1.0, 1.0))) &&\n (!defined(node.rotation) ||\n Cartesian4.fromArray(node.rotation).equals(\n new Cartesian4(0.0, 0.0, 0.0, 1.0)\n )) &&\n (!defined(node.matrix) ||\n Matrix4.fromColumnMajorArray(node.matrix).equals(Matrix4.IDENTITY)) &&\n !defined(node.extensions) &&\n !defined(node.extras)\n );\n}\n\nfunction deleteNode(gltf, nodeId) {\n // Remove from list of nodes in scene\n ForEach.scene(gltf, function (scene) {\n const sceneNodes = scene.nodes;\n if (defined(sceneNodes)) {\n const sceneNodesLength = sceneNodes.length;\n for (let i = sceneNodesLength; i >= 0; --i) {\n if (sceneNodes[i] === nodeId) {\n sceneNodes.splice(i, 1);\n return;\n }\n }\n }\n });\n\n // Remove parent node's reference to this node, and delete the parent if also empty\n ForEach.node(gltf, function (parentNode, parentNodeId) {\n if (defined(parentNode.children)) {\n const index = parentNode.children.indexOf(nodeId);\n if (index > -1) {\n parentNode.children.splice(index, 1);\n\n if (isNodeEmpty(parentNode)) {\n deleteNode(gltf, parentNodeId);\n }\n }\n }\n });\n\n delete gltf.nodes[nodeId];\n}\n\nfunction removeEmptyNodes(gltf) {\n ForEach.node(gltf, function (node, nodeId) {\n if (isNodeEmpty(node)) {\n deleteNode(gltf, nodeId);\n }\n });\n\n return gltf;\n}\n\nfunction requireAnimationAccessorMinMax(gltf) {\n ForEach.animation(gltf, function (animation) {\n ForEach.animationSampler(animation, function (sampler) {\n const accessor = gltf.accessors[sampler.input];\n if (!defined(accessor.min) || !defined(accessor.max)) {\n const minMax = findAccessorMinMax(gltf, accessor);\n accessor.min = minMax.min;\n accessor.max = minMax.max;\n }\n });\n });\n}\n\nfunction validatePresentAccessorMinMax(gltf) {\n ForEach.accessor(gltf, function (accessor) {\n if (defined(accessor.min) || defined(accessor.max)) {\n const minMax = findAccessorMinMax(gltf, accessor);\n if (defined(accessor.min)) {\n accessor.min = minMax.min;\n }\n if (defined(accessor.max)) {\n accessor.max = minMax.max;\n }\n }\n });\n}\n\nfunction glTF10to20(gltf) {\n gltf.asset = defaultValue(gltf.asset, {});\n gltf.asset.version = \"2.0\";\n // material.instanceTechnique properties should be directly on the material. instanceTechnique is a gltf 0.8 property but is seen in some 1.0 models.\n updateInstanceTechniques(gltf);\n // animation.samplers now refers directly to accessors and animation.parameters should be removed\n removeAnimationSamplersIndirection(gltf);\n // Remove empty nodes and re-assign referencing indices\n removeEmptyNodes(gltf);\n // Top-level objects are now arrays referenced by index instead of id\n objectsToArrays(gltf);\n // Animation.sampler objects cannot have names\n removeAnimationSamplerNames(gltf);\n // asset.profile no longer exists\n stripAsset(gltf);\n // Move known extensions from extensionsUsed to extensionsRequired\n requireKnownExtensions(gltf);\n // bufferView.byteLength and buffer.byteLength are required\n requireByteLength(gltf);\n // byteStride moved from accessor to bufferView\n moveByteStrideToBufferView(gltf);\n // accessor.min and accessor.max must be defined for accessors containing POSITION attributes\n requirePositionAccessorMinMax(gltf);\n // An animation sampler's input accessor must have min and max properties defined\n requireAnimationAccessorMinMax(gltf);\n // When an acccessor has a min- or max, then it is recomputed, to capture the actual\n // value, and not use the (possibly imprecise) value from the input\n validatePresentAccessorMinMax(gltf);\n // buffer.type is unnecessary and should be removed\n removeBufferType(gltf);\n // Remove format, internalFormat, target, and type\n removeTextureProperties(gltf);\n // TEXCOORD and COLOR attributes must be written with a set index (TEXCOORD_#)\n requireAttributeSetIndex(gltf);\n // Add underscores to application-specific parameters\n underscoreApplicationSpecificSemantics(gltf);\n // Accessors referenced by JOINTS_0 and WEIGHTS_0 attributes must have correct component types\n updateAccessorComponentTypes(gltf);\n // Clamp camera parameters\n clampCameraParameters(gltf);\n // Move legacy technique render states to material properties and add KHR_blend extension blending functions\n moveTechniqueRenderStates(gltf);\n // Add material techniques to KHR_techniques_webgl extension, removing shaders, programs, and techniques\n moveTechniquesToExtension(gltf);\n // Remove empty arrays\n removeEmptyArrays(gltf);\n}\n\n// It's not possible to upgrade glTF 1.0 shaders to 2.0 PBR materials in a generic way,\n// but we can look for certain uniform names that are commonly found in glTF 1.0 assets\n// and create PBR materials out of those.\nconst defaultBaseColorTextureNames = [\n \"u_tex\",\n \"u_diffuse\",\n \"u_emission\",\n \"u_diffuse_tex\",\n];\nconst defaultBaseColorFactorNames = [\"u_diffuse\", \"u_diffuse_mat\"];\n\nfunction initializePbrMaterial(material) {\n material.pbrMetallicRoughness = defined(material.pbrMetallicRoughness)\n ? material.pbrMetallicRoughness\n : {};\n\n material.pbrMetallicRoughness.roughnessFactor = 1.0;\n material.pbrMetallicRoughness.metallicFactor = 0.0;\n}\n\nfunction isTexture(value) {\n return defined(value.index);\n}\n\nfunction isVec4(value) {\n return Array.isArray(value) && value.length === 4;\n}\n\nfunction srgbToLinear(srgb) {\n const linear = new Array(4);\n linear[3] = srgb[3];\n\n for (let i = 0; i < 3; i++) {\n const c = srgb[i];\n if (c <= 0.04045) {\n // eslint-disable-next-line no-loss-of-precision\n linear[i] = srgb[i] * 0.07739938080495356037151702786378;\n } else {\n linear[i] = Math.pow(\n // eslint-disable-next-line no-loss-of-precision\n (c + 0.055) * 0.94786729857819905213270142180095,\n 2.4\n );\n }\n }\n\n return linear;\n}\n\nfunction convertTechniquesToPbr(gltf, options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const baseColorTextureNames = defaultValue(\n options.baseColorTextureNames,\n defaultBaseColorTextureNames\n );\n const baseColorFactorNames = defaultValue(\n options.baseColorFactorNames,\n defaultBaseColorFactorNames\n );\n\n // Future work: convert other values like emissive, specular, etc. Only handling diffuse right now.\n ForEach.material(gltf, function (material) {\n ForEach.materialValue(material, function (value, name) {\n if (baseColorTextureNames.indexOf(name) !== -1 && isTexture(value)) {\n initializePbrMaterial(material);\n material.pbrMetallicRoughness.baseColorTexture = value;\n } else if (baseColorFactorNames.indexOf(name) !== -1 && isVec4(value)) {\n initializePbrMaterial(material);\n material.pbrMetallicRoughness.baseColorFactor = srgbToLinear(value);\n }\n });\n });\n\n removeExtension(gltf, \"KHR_techniques_webgl\");\n removeExtension(gltf, \"KHR_blend\");\n}\n\nfunction convertMaterialsCommonToPbr(gltf) {\n // Future work: convert KHR_materials_common lights to KHR_lights_punctual\n ForEach.material(gltf, function (material) {\n const materialsCommon = defaultValue(\n material.extensions,\n defaultValue.EMPTY_OBJECT\n ).KHR_materials_common;\n\n if (defined(materialsCommon)) {\n const technique = materialsCommon.technique;\n if (technique === \"CONSTANT\") {\n // Add the KHR_materials_unlit extension\n addExtensionsUsed(gltf, \"KHR_materials_unlit\");\n material.extensions = defined(material.extensions)\n ? material.extensions\n : {};\n material.extensions[\"KHR_materials_unlit\"] = {};\n }\n\n const values = defined(materialsCommon.values)\n ? materialsCommon.values\n : {};\n\n const ambient = values.ambient;\n const diffuse = values.diffuse;\n const emission = values.emission;\n const transparency = values.transparency;\n\n // These actually exist on the extension object, not the values object despite what's shown in the spec\n const doubleSided = materialsCommon.doubleSided;\n const transparent = materialsCommon.transparent;\n\n // Ignore specular and shininess for now because the conversion to PBR\n // isn't straightforward and depends on the technique\n initializePbrMaterial(material);\n\n if (defined(ambient)) {\n if (isVec4(ambient)) {\n material.emissiveFactor = ambient.slice(0, 3);\n } else if (isTexture(ambient)) {\n material.emissiveTexture = ambient;\n }\n }\n\n if (defined(diffuse)) {\n if (isVec4(diffuse)) {\n material.pbrMetallicRoughness.baseColorFactor = srgbToLinear(diffuse);\n } else if (isTexture(diffuse)) {\n material.pbrMetallicRoughness.baseColorTexture = diffuse;\n }\n }\n\n if (defined(doubleSided)) {\n material.doubleSided = doubleSided;\n }\n\n if (defined(emission)) {\n if (isVec4(emission)) {\n material.emissiveFactor = emission.slice(0, 3);\n } else if (isTexture(emission)) {\n material.emissiveTexture = emission;\n }\n }\n\n if (defined(transparency)) {\n if (defined(material.pbrMetallicRoughness.baseColorFactor)) {\n material.pbrMetallicRoughness.baseColorFactor[3] *= transparency;\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [\n 1,\n 1,\n 1,\n transparency,\n ];\n }\n }\n\n if (defined(transparent)) {\n material.alphaMode = transparent ? \"BLEND\" : \"OPAQUE\";\n }\n }\n });\n\n removeExtension(gltf, \"KHR_materials_common\");\n}\n\nexport default updateVersion;\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * An enum describing the built-in vertex attribute semantics.\n *\n * @enum {string}\n *\n * @private\n */\nconst VertexAttributeSemantic = {\n /**\n * Per-vertex position.\n *\n * @type {string}\n * @constant\n */\n POSITION: \"POSITION\",\n\n /**\n * Per-vertex normal.\n *\n * @type {string}\n * @constant\n */\n NORMAL: \"NORMAL\",\n\n /**\n * Per-vertex tangent.\n *\n * @type {string}\n * @constant\n */\n TANGENT: \"TANGENT\",\n\n /**\n * Per-vertex texture coordinates.\n *\n * @type {string}\n * @constant\n */\n TEXCOORD: \"TEXCOORD\",\n\n /**\n * Per-vertex color.\n *\n * @type {string}\n * @constant\n */\n COLOR: \"COLOR\",\n\n /**\n * Per-vertex joint IDs for skinning.\n *\n * @type {string}\n * @constant\n */\n JOINTS: \"JOINTS\",\n\n /**\n * Per-vertex joint weights for skinning.\n *\n * @type {string}\n * @constant\n */\n WEIGHTS: \"WEIGHTS\",\n\n /**\n * Per-vertex feature ID.\n *\n * @type {string}\n * @constant\n */\n FEATURE_ID: \"_FEATURE_ID\",\n};\n\nfunction semanticToVariableName(semantic) {\n switch (semantic) {\n case VertexAttributeSemantic.POSITION:\n return \"positionMC\";\n case VertexAttributeSemantic.NORMAL:\n return \"normalMC\";\n case VertexAttributeSemantic.TANGENT:\n return \"tangentMC\";\n case VertexAttributeSemantic.TEXCOORD:\n return \"texCoord\";\n case VertexAttributeSemantic.COLOR:\n return \"color\";\n case VertexAttributeSemantic.JOINTS:\n return \"joints\";\n case VertexAttributeSemantic.WEIGHTS:\n return \"weights\";\n case VertexAttributeSemantic.FEATURE_ID:\n return \"featureId\";\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"semantic is not a valid value.\");\n //>>includeEnd('debug');\n }\n}\n\n/**\n * Returns whether the vertex attribute semantic can have a set index.\n *\n * @param {VertexAttributeSemantic} semantic The semantic.\n *\n * @returns {boolean} Whether the semantic can have a set index.\n *\n * @private\n */\nVertexAttributeSemantic.hasSetIndex = function (semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n switch (semantic) {\n case VertexAttributeSemantic.POSITION:\n case VertexAttributeSemantic.NORMAL:\n case VertexAttributeSemantic.TANGENT:\n return false;\n case VertexAttributeSemantic.TEXCOORD:\n case VertexAttributeSemantic.COLOR:\n case VertexAttributeSemantic.JOINTS:\n case VertexAttributeSemantic.WEIGHTS:\n case VertexAttributeSemantic.FEATURE_ID:\n return true;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"semantic is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the vertex attribute semantic matching the glTF semantic.\n *\n * @param {string} gltfSemantic The glTF semantic.\n *\n * @returns {VertexAttributeSemantic|undefined} The vertex attribute semantic, or undefined if there is no match.\n *\n * @private\n */\nVertexAttributeSemantic.fromGltfSemantic = function (gltfSemantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"gltfSemantic\", gltfSemantic);\n //>>includeEnd('debug');\n\n let semantic = gltfSemantic;\n\n // Strip the set index from the semantic\n const setIndexRegex = /^(\\w+)_\\d+$/;\n const setIndexMatch = setIndexRegex.exec(gltfSemantic);\n if (setIndexMatch !== null) {\n semantic = setIndexMatch[1];\n }\n\n switch (semantic) {\n case \"POSITION\":\n return VertexAttributeSemantic.POSITION;\n case \"NORMAL\":\n return VertexAttributeSemantic.NORMAL;\n case \"TANGENT\":\n return VertexAttributeSemantic.TANGENT;\n case \"TEXCOORD\":\n return VertexAttributeSemantic.TEXCOORD;\n case \"COLOR\":\n return VertexAttributeSemantic.COLOR;\n case \"JOINTS\":\n return VertexAttributeSemantic.JOINTS;\n case \"WEIGHTS\":\n return VertexAttributeSemantic.WEIGHTS;\n case \"_FEATURE_ID\":\n return VertexAttributeSemantic.FEATURE_ID;\n }\n\n return undefined;\n};\n\n/**\n * Gets the vertex attribute semantic matching the pnts semantic.\n *\n * @param {string} pntsSemantic The pnts semantic.\n *\n * @returns {VertexAttributeSemantic|undefined} The vertex attribute semantic, or undefined if there is no match.\n *\n * @private\n */\nVertexAttributeSemantic.fromPntsSemantic = function (pntsSemantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"pntsSemantic\", pntsSemantic);\n //>>includeEnd('debug');\n\n switch (pntsSemantic) {\n case \"POSITION\":\n case \"POSITION_QUANTIZED\":\n return VertexAttributeSemantic.POSITION;\n case \"RGBA\":\n case \"RGB\":\n case \"RGB565\":\n return VertexAttributeSemantic.COLOR;\n case \"NORMAL\":\n case \"NORMAL_OCT16P\":\n return VertexAttributeSemantic.NORMAL;\n case \"BATCH_ID\":\n return VertexAttributeSemantic.FEATURE_ID;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"pntsSemantic is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the GLSL type (such as vec3 or int) for the\n * given vertex attribute.\n *\n * @param {VertexAttributeSemantic} semantic The semantic.\n *\n * @returns {string} The shader type.\n *\n * @private\n */\nVertexAttributeSemantic.getGlslType = function (semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n switch (semantic) {\n case VertexAttributeSemantic.POSITION:\n case VertexAttributeSemantic.NORMAL:\n case VertexAttributeSemantic.TANGENT:\n return \"vec3\";\n case VertexAttributeSemantic.TEXCOORD:\n return \"vec2\";\n case VertexAttributeSemantic.COLOR:\n return \"vec4\";\n case VertexAttributeSemantic.JOINTS:\n return \"ivec4\";\n case VertexAttributeSemantic.WEIGHTS:\n return \"vec4\";\n case VertexAttributeSemantic.FEATURE_ID:\n return \"int\";\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"semantic is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\n/**\n * Gets the variable name for the given semantic and set index.\n *\n * @param {VertexAttributeSemantic} semantic The semantic.\n * @param {number} [setIndex] The set index.\n *\n * @returns {string} The variable name.\n *\n * @private\n */\nVertexAttributeSemantic.getVariableName = function (semantic, setIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n let variableName = semanticToVariableName(semantic);\n if (defined(setIndex)) {\n variableName += `_${setIndex}`;\n }\n return variableName;\n};\n\nexport default Object.freeze(VertexAttributeSemantic);\n", "import Cartesian3 from \"../../Core/Cartesian3.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport Axis from \"../Axis.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport CullFace from \"../CullFace.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport Matrix3 from \"../../Core/Matrix3.js\";\n\n/**\n * Utility functions for {@link Model}.\n *\n * @private\n */\nfunction ModelUtility() {}\n\n/**\n * Create a function for reporting when a model fails to load\n *\n * @param {string} type The type of object to report about\n * @param {string} path The URI of the model file\n * @param {Error} [error] The error which caused the failure\n * @returns {RuntimeError} An error for the failed model\n *\n * @private\n */\nModelUtility.getError = function (type, path, error) {\n let message = `Failed to load ${type}: ${path}`;\n if (defined(error) && defined(error.message)) {\n message += `\\n${error.message}`;\n }\n\n const runtimeError = new RuntimeError(message);\n if (defined(error)) {\n // the original call stack is often more useful than the new error's stack,\n // so add the information here\n runtimeError.stack = `Original stack:\\n${error.stack}\\nHandler stack:\\n${runtimeError.stack}`;\n }\n\n return runtimeError;\n};\n\n/**\n * Get a transformation matrix from a node in the model.\n *\n * @param {ModelComponents.Node} node The node components\n * @returns {Matrix4} The computed transformation matrix. If no transformation matrix or parameters are specified, this will be the identity matrix.\n *\n * @private\n */\nModelUtility.getNodeTransform = function (node) {\n if (defined(node.matrix)) {\n return node.matrix;\n }\n\n return Matrix4.fromTranslationQuaternionRotationScale(\n defined(node.translation) ? node.translation : Cartesian3.ZERO,\n defined(node.rotation) ? node.rotation : Quaternion.IDENTITY,\n defined(node.scale) ? node.scale : Cartesian3.ONE\n );\n};\n\n/**\n * Find an attribute by semantic such as POSITION or TANGENT.\n *\n * @param {ModelComponents.Primitive|ModelComponents.Instances} object The primitive components or instances object\n * @param {VertexAttributeSemantic|InstanceAttributeSemantic} semantic The semantic to search for\n * @param {number} [setIndex] The set index of the semantic. May be undefined for some semantics (POSITION, NORMAL, TRANSLATION, ROTATION, for example)\n * @return {ModelComponents.Attribute} The selected attribute, or undefined if not found.\n *\n * @private\n */\nModelUtility.getAttributeBySemantic = function (object, semantic, setIndex) {\n const attributes = object.attributes;\n const attributesLength = attributes.length;\n for (let i = 0; i < attributesLength; ++i) {\n const attribute = attributes[i];\n const matchesSetIndex = defined(setIndex)\n ? attribute.setIndex === setIndex\n : true;\n if (attribute.semantic === semantic && matchesSetIndex) {\n return attribute;\n }\n }\n\n return undefined;\n};\n\n/**\n * Similar to getAttributeBySemantic, but search using the name field only,\n * as custom attributes do not have a semantic.\n *\n * @param {ModelComponents.Primitive|ModelComponents.Instances} object The primitive components or instances object\n * @param {string} name The name of the attribute as it appears in the model file.\n * @return {ModelComponents.Attribute} The selected attribute, or undefined if not found.\n *\n * @private\n */\nModelUtility.getAttributeByName = function (object, name) {\n const attributes = object.attributes;\n const attributesLength = attributes.length;\n for (let i = 0; i < attributesLength; ++i) {\n const attribute = attributes[i];\n if (attribute.name === name) {\n return attribute;\n }\n }\n\n return undefined;\n};\n\n/**\n * Find a feature ID from an array with label or positionalLabel matching the\n * given label\n * @param {ModelComponents.FeatureIdAttribute[]|ModelComponents.FeatureIdImplicitRange[]|ModelComponents.FeatureIdTexture[]} featureIds\n * @param {string} label the label to search for\n * @returns {ModelComponents.FeatureIdAttribute|ModelComponents.FeatureIdImplicitRange|ModelComponents.FeatureIdTexture} The feature ID set if found, otherwise undefined\n *\n * @private\n */\nModelUtility.getFeatureIdsByLabel = function (featureIds, label) {\n for (let i = 0; i < featureIds.length; i++) {\n const featureIdSet = featureIds[i];\n if (\n featureIdSet.positionalLabel === label ||\n featureIdSet.label === label\n ) {\n return featureIdSet;\n }\n }\n\n return undefined;\n};\n\nModelUtility.hasQuantizedAttributes = function (attributes) {\n if (!defined(attributes)) {\n return false;\n }\n\n for (let i = 0; i < attributes.length; i++) {\n const attribute = attributes[i];\n if (defined(attribute.quantization)) {\n return true;\n }\n }\n return false;\n};\n\n/**\n * @param {ModelComponents.Attribute} attribute\n *\n * @private\n */\nModelUtility.getAttributeInfo = function (attribute) {\n const semantic = attribute.semantic;\n const setIndex = attribute.setIndex;\n\n let variableName;\n let hasSemantic = false;\n if (defined(semantic)) {\n variableName = VertexAttributeSemantic.getVariableName(semantic, setIndex);\n hasSemantic = true;\n } else {\n variableName = attribute.name;\n // According to the glTF 2.0 spec, custom attributes must be prepended with\n // an underscore.\n variableName = variableName.replace(/^_/, \"\");\n variableName = variableName.toLowerCase();\n }\n\n const isVertexColor = /^color_\\d+$/.test(variableName);\n const attributeType = attribute.type;\n let glslType = AttributeType.getGlslType(attributeType);\n\n // color_n can be either a vec3 or a vec4. But in GLSL we can always use\n // attribute vec4 since GLSL promotes vec3 attribute data to vec4 with\n // the .a channel set to 1.0.\n if (isVertexColor) {\n glslType = \"vec4\";\n }\n\n const isQuantized = defined(attribute.quantization);\n let quantizedGlslType;\n if (isQuantized) {\n // The quantized color_n attribute also is promoted to a vec4 in the shader\n quantizedGlslType = isVertexColor\n ? \"vec4\"\n : AttributeType.getGlslType(attribute.quantization.type);\n }\n\n return {\n attribute: attribute,\n isQuantized: isQuantized,\n variableName: variableName,\n hasSemantic: hasSemantic,\n glslType: glslType,\n quantizedGlslType: quantizedGlslType,\n };\n};\n\nconst cartesianMaxScratch = new Cartesian3();\nconst cartesianMinScratch = new Cartesian3();\n\n/**\n * Get the minimum and maximum values for a primitive's POSITION attribute.\n * This is used to compute the bounding sphere of the primitive, as well as\n * the bounding sphere of the whole model.\n *\n * @param {ModelComponents.Primitive} primitive The primitive components.\n * @param {Cartesian3} [instancingTranslationMin] The component-wise minimum value of the instancing translation attribute.\n * @param {Cartesian3} [instancingTranslationMax] The component-wise maximum value of the instancing translation attribute.\n *\n * @returns {object} An object containing the minimum and maximum position values.\n *\n * @private\n */\nModelUtility.getPositionMinMax = function (\n primitive,\n instancingTranslationMin,\n instancingTranslationMax\n) {\n const positionGltfAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n \"POSITION\"\n );\n\n let positionMax = positionGltfAttribute.max;\n let positionMin = positionGltfAttribute.min;\n\n if (defined(instancingTranslationMax) && defined(instancingTranslationMin)) {\n positionMin = Cartesian3.add(\n positionMin,\n instancingTranslationMin,\n cartesianMinScratch\n );\n positionMax = Cartesian3.add(\n positionMax,\n instancingTranslationMax,\n cartesianMaxScratch\n );\n }\n\n return {\n min: positionMin,\n max: positionMax,\n };\n};\n\n/**\n * Model matrices in a model file (e.g. glTF) are typically in a different\n * coordinate system, such as with y-up instead of z-up in 3D Tiles.\n * This function returns a matrix that will correct this such that z is up,\n * and x is forward.\n *\n * @param {Axis} upAxis The original up direction\n * @param {Axis} forwardAxis The original forward direction\n * @param {Matrix4} result The matrix in which to store the result.\n * @returns {Matrix4} The axis correction matrix\n *\n * @private\n */\nModelUtility.getAxisCorrectionMatrix = function (upAxis, forwardAxis, result) {\n result = Matrix4.clone(Matrix4.IDENTITY, result);\n\n if (upAxis === Axis.Y) {\n result = Matrix4.clone(Axis.Y_UP_TO_Z_UP, result);\n } else if (upAxis === Axis.X) {\n result = Matrix4.clone(Axis.X_UP_TO_Z_UP, result);\n }\n\n if (forwardAxis === Axis.Z) {\n // glTF 2.0 has a Z-forward convention that must be adapted here to X-forward.\n result = Matrix4.multiplyTransformation(result, Axis.Z_UP_TO_X_UP, result);\n }\n\n return result;\n};\n\nconst scratchMatrix3 = new Matrix3();\n\n/**\n * Get the cull face to use in the command's render state.\n *

\n * From the glTF spec section 3.7.4:\n * When a mesh primitive uses any triangle-based topology (i.e., triangles,\n * triangle strip, or triangle fan), the determinant of the node\u2019s global\n * transform defines the winding order of that primitive. If the determinant\n * is a positive value, the winding order triangle faces is counterclockwise;\n * in the opposite case, the winding order is clockwise.\n *

\n *\n * @param {Matrix4} modelMatrix The model matrix\n * @param {PrimitiveType} primitiveType The primitive type\n * @returns {CullFace} The cull face\n *\n * @private\n */\nModelUtility.getCullFace = function (modelMatrix, primitiveType) {\n if (!PrimitiveType.isTriangles(primitiveType)) {\n return CullFace.BACK;\n }\n\n const matrix3 = Matrix4.getMatrix3(modelMatrix, scratchMatrix3);\n return Matrix3.determinant(matrix3) < 0.0 ? CullFace.FRONT : CullFace.BACK;\n};\n\n/**\n * Sanitize the identifier to be used in a GLSL shader. The identifier\n * is sanitized as follows:\n * - Replace all sequences of non-alphanumeric characters with a single `_`.\n * - If the gl_ prefix is present, remove it. The prefix is reserved in GLSL.\n * - If the identifier starts with a digit, prefix it with an underscore.\n *\n * @example\n * // Returns \"customProperty\"\n * ModelUtility.sanitizeGlslIdentifier(\"gl_customProperty\");\n *\n * @example\n * // Returns \"_1234\"\n * ModelUtility.sanitizeGlslIdentifier(\"1234\");\n *\n * @param {string} identifier The original identifier.\n *\n * @returns {string} The sanitized version of the identifier.\n */\nModelUtility.sanitizeGlslIdentifier = function (identifier) {\n // Remove non-alphanumeric characters and replace with a single underscore.\n // This regex is designed so that the result won't have multiple underscores\n // in a row.\n let sanitizedIdentifier = identifier.replaceAll(/[^A-Za-z0-9]+/g, \"_\");\n // Remove the gl_ prefix if present.\n sanitizedIdentifier = sanitizedIdentifier.replace(/^gl_/, \"\");\n // Add an underscore if first character is a digit.\n if (/^\\d/.test(sanitizedIdentifier)) {\n sanitizedIdentifier = `_${sanitizedIdentifier}`;\n }\n\n return sanitizedIdentifier;\n};\n\nModelUtility.supportedExtensions = {\n AGI_articulations: true,\n CESIUM_primitive_outline: true,\n CESIUM_RTC: true,\n EXT_feature_metadata: true,\n EXT_instance_features: true,\n EXT_mesh_features: true,\n EXT_mesh_gpu_instancing: true,\n EXT_meshopt_compression: true,\n EXT_structural_metadata: true,\n EXT_texture_webp: true,\n KHR_blend: true,\n KHR_draco_mesh_compression: true,\n KHR_techniques_webgl: true,\n KHR_materials_common: true,\n KHR_materials_pbrSpecularGlossiness: true,\n KHR_materials_unlit: true,\n KHR_mesh_quantization: true,\n KHR_texture_basisu: true,\n KHR_texture_transform: true,\n WEB3D_quantized_attributes: true,\n};\n\n/**\n * Checks whether or not the extensions required by the glTF are\n * supported. If an unsupported extension is found, this throws\n * a {@link RuntimeError} with the extension name.\n *\n * @param {string[]} extensionsRequired The extensionsRequired array in the glTF.\n *\n * @exception {RuntimeError} Unsupported glTF Extension\n */\nModelUtility.checkSupportedExtensions = function (extensionsRequired) {\n const length = extensionsRequired.length;\n for (let i = 0; i < length; i++) {\n const extension = extensionsRequired[i];\n if (!ModelUtility.supportedExtensions[extension]) {\n throw new RuntimeError(`Unsupported glTF Extension: ${extension}`);\n }\n }\n};\n\nexport default ModelUtility;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport getMagic from \"../Core/getMagic.js\";\nimport isDataUri from \"../Core/isDataUri.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport addDefaults from \"./GltfPipeline/addDefaults.js\";\nimport addPipelineExtras from \"./GltfPipeline/addPipelineExtras.js\";\nimport ForEach from \"./GltfPipeline/ForEach.js\";\nimport parseGlb from \"./GltfPipeline/parseGlb.js\";\nimport removePipelineExtras from \"./GltfPipeline/removePipelineExtras.js\";\nimport updateVersion from \"./GltfPipeline/updateVersion.js\";\nimport usesExtension from \"./GltfPipeline/usesExtension.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\nimport ModelUtility from \"./Model/ModelUtility.js\";\n\n/**\n * Loads a glTF JSON from a glTF or glb.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfJsonLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {Uint8Array} [options.typedArray] The typed array containing the glTF contents.\n * @param {object} [options.gltfJson] The parsed glTF JSON contents.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @private\n */\nfunction GltfJsonLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const typedArray = options.typedArray;\n const gltfJson = options.gltfJson;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._typedArray = typedArray;\n this._gltfJson = gltfJson;\n this._cacheKey = cacheKey;\n this._gltf = undefined;\n this._bufferLoaders = [];\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfJsonLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfJsonLoader.prototype.constructor = GltfJsonLoader;\n}\n\nObject.defineProperties(GltfJsonLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfJsonLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The glTF JSON.\n *\n * @memberof GltfJsonLoader.prototype\n *\n * @type {object}\n * @readonly\n * @private\n */\n gltf: {\n get: function () {\n return this._gltf;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfJsonLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._state = ResourceLoaderState.LOADING;\n\n if (defined(this._gltfJson)) {\n this._promise = processGltfJson(this, this._gltfJson);\n return this._promise;\n }\n\n if (defined(this._typedArray)) {\n this._promise = processGltfTypedArray(this, this._typedArray);\n return this._promise;\n }\n\n this._promise = loadFromUri(this);\n return this._promise;\n};\n\nasync function loadFromUri(gltfJsonLoader) {\n let typedArray;\n try {\n const arrayBuffer = await gltfJsonLoader._fetchGltf();\n if (gltfJsonLoader.isDestroyed()) {\n return;\n }\n\n typedArray = new Uint8Array(arrayBuffer);\n } catch (error) {\n if (gltfJsonLoader.isDestroyed()) {\n return;\n }\n\n handleError(gltfJsonLoader, error);\n }\n\n return processGltfTypedArray(gltfJsonLoader, typedArray);\n}\n\nfunction handleError(gltfJsonLoader, error) {\n gltfJsonLoader.unload();\n gltfJsonLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = `Failed to load glTF: ${gltfJsonLoader._gltfResource.url}`;\n throw gltfJsonLoader.getError(errorMessage, error);\n}\n\nasync function upgradeVersion(gltfJsonLoader, gltf) {\n if (\n defined(gltf.asset) &&\n gltf.asset.version === \"2.0\" &&\n !usesExtension(gltf, \"KHR_techniques_webgl\") &&\n !usesExtension(gltf, \"KHR_materials_common\")\n ) {\n return Promise.resolve();\n }\n\n // Load all buffers into memory. updateVersion will read and in some cases modify\n // the buffer data, which it accesses from buffer.extras._pipeline.source\n const promises = [];\n ForEach.buffer(gltf, function (buffer) {\n if (\n !defined(buffer.extras._pipeline.source) && // Ignore uri if this buffer uses the glTF 1.0 KHR_binary_glTF extension\n defined(buffer.uri)\n ) {\n const resource = gltfJsonLoader._baseResource.getDerivedResource({\n url: buffer.uri,\n });\n const resourceCache = gltfJsonLoader._resourceCache;\n const bufferLoader = resourceCache.getExternalBufferLoader({\n resource: resource,\n });\n gltfJsonLoader._bufferLoaders.push(bufferLoader);\n\n promises.push(\n bufferLoader.load().then(function () {\n if (bufferLoader.isDestroyed()) {\n return;\n }\n\n buffer.extras._pipeline.source = bufferLoader.typedArray;\n })\n );\n }\n });\n\n await Promise.all(promises);\n updateVersion(gltf);\n}\n\nfunction decodeDataUris(gltf) {\n const promises = [];\n ForEach.buffer(gltf, function (buffer) {\n const bufferUri = buffer.uri;\n if (\n !defined(buffer.extras._pipeline.source) && // Ignore uri if this buffer uses the glTF 1.0 KHR_binary_glTF extension\n defined(bufferUri) &&\n isDataUri(bufferUri)\n ) {\n delete buffer.uri; // Delete the data URI to keep the cached glTF JSON small\n promises.push(\n Resource.fetchArrayBuffer(bufferUri).then(function (arrayBuffer) {\n buffer.extras._pipeline.source = new Uint8Array(arrayBuffer);\n })\n );\n }\n });\n return Promise.all(promises);\n}\n\nfunction loadEmbeddedBuffers(gltfJsonLoader, gltf) {\n const promises = [];\n ForEach.buffer(gltf, function (buffer, bufferId) {\n const source = buffer.extras._pipeline.source;\n if (defined(source) && !defined(buffer.uri)) {\n const resourceCache = gltfJsonLoader._resourceCache;\n const bufferLoader = resourceCache.getEmbeddedBufferLoader({\n parentResource: gltfJsonLoader._gltfResource,\n bufferId: bufferId,\n typedArray: source,\n });\n gltfJsonLoader._bufferLoaders.push(bufferLoader);\n promises.push(bufferLoader.load());\n }\n });\n return Promise.all(promises);\n}\n\nasync function processGltfJson(gltfJsonLoader, gltf) {\n try {\n addPipelineExtras(gltf);\n\n await decodeDataUris(gltf);\n await upgradeVersion(gltfJsonLoader, gltf);\n addDefaults(gltf);\n await loadEmbeddedBuffers(gltfJsonLoader, gltf);\n removePipelineExtras(gltf);\n\n const version = gltf.asset.version;\n if (version !== \"1.0\" && version !== \"2.0\") {\n throw new RuntimeError(`Unsupported glTF version: ${version}`);\n }\n\n const extensionsRequired = gltf.extensionsRequired;\n if (defined(extensionsRequired)) {\n ModelUtility.checkSupportedExtensions(extensionsRequired);\n }\n\n gltfJsonLoader._gltf = gltf;\n gltfJsonLoader._state = ResourceLoaderState.READY;\n return gltfJsonLoader;\n } catch (error) {\n if (gltfJsonLoader.isDestroyed()) {\n return;\n }\n\n handleError(gltfJsonLoader, error);\n }\n}\n\nasync function processGltfTypedArray(gltfJsonLoader, typedArray) {\n let gltf;\n try {\n if (getMagic(typedArray) === \"glTF\") {\n gltf = parseGlb(typedArray);\n } else {\n gltf = getJsonFromTypedArray(typedArray);\n }\n } catch (error) {\n if (gltfJsonLoader.isDestroyed()) {\n return;\n }\n\n handleError(gltfJsonLoader, error);\n }\n\n return processGltfJson(gltfJsonLoader, gltf);\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfJsonLoader.prototype.unload = function () {\n const bufferLoaders = this._bufferLoaders;\n const bufferLoadersLength = bufferLoaders.length;\n for (let i = 0; i < bufferLoadersLength; ++i) {\n bufferLoaders[i] =\n !bufferLoaders[i].isDestroyed() &&\n this._resourceCache.unload(bufferLoaders[i]);\n }\n this._bufferLoaders.length = 0;\n\n this._gltf = undefined;\n};\n\n/**\n * Exposed for testing\n *\n * @private\n */\nGltfJsonLoader.prototype._fetchGltf = function () {\n return this._gltfResource.fetchArrayBuffer();\n};\n\nexport default GltfJsonLoader;\n", "/**\n * The alpha rendering mode of the material.\n *\n * @enum {string}\n * @private\n */\nconst AlphaMode = {\n /**\n * The alpha value is ignored and the rendered output is fully opaque.\n *\n * @type {string}\n * @constant\n */\n OPAQUE: \"OPAQUE\",\n\n /**\n * The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value.\n *\n * @type {string}\n * @constant\n */\n MASK: \"MASK\",\n\n /**\n * The rendered output is composited onto the destination with alpha blending.\n *\n * @type {string}\n * @constant\n */\n BLEND: \"BLEND\",\n};\n\nexport default Object.freeze(AlphaMode);\n", "import AlphaMode from \"./AlphaMode.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\n\n/**\n * Components for building models.\n *\n * @namespace ModelComponents\n *\n * @private\n */\nconst ModelComponents = {};\n\n/**\n * Information about the quantized attribute.\n *\n * @alias ModelComponents.Quantization\n * @constructor\n *\n * @private\n */\nfunction Quantization() {\n /**\n * Whether the quantized attribute is oct-encoded.\n *\n * @type {boolean}\n * @private\n */\n this.octEncoded = false;\n\n /**\n * Whether the oct-encoded values are stored as ZXY instead of XYZ. This is true when decoding from Draco.\n *\n * @type {boolean}\n * @private\n */\n this.octEncodedZXY = false;\n\n /**\n * The range used to convert buffer values to normalized values [0.0, 1.0]\n * This is typically computed as (1 << quantizationBits) - 1.\n * For oct-encoded values this value is a single Number.\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.normalizationRange = undefined;\n\n /**\n * The bottom-left corner of the quantization volume. Not applicable for oct encoded attributes.\n * The type should match the attribute type - e.g. if the attribute type\n * is AttributeType.VEC4 the offset should be a Cartesian4.\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.quantizedVolumeOffset = undefined;\n\n /**\n * The dimensions of the quantization volume. Not applicable for oct encoded attributes.\n * The type should match the attribute type - e.g. if the attribute type\n * is AttributeType.VEC4 the dimensions should be a Cartesian4.\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.quantizedVolumeDimensions = undefined;\n\n /**\n * The step size of the quantization volume, equal to\n * quantizedVolumeDimensions / normalizationRange (component-wise).\n * Not applicable for oct encoded attributes.\n * The type should match the attribute type - e.g. if the attribute type\n * is AttributeType.VEC4 the dimensions should be a Cartesian4.\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.quantizedVolumeStepSize = undefined;\n\n /**\n * The component data type of the quantized attribute, e.g. ComponentDatatype.UNSIGNED_SHORT.\n *\n *

\n * The following component datatypes are not supported:\n *

    \n *
  • ComponentDatatype.INT
  • \n *
  • ComponentDatatype.UNSIGNED_INT
  • \n *
  • ComponentDatatype.DOUBLE
  • \n *
\n *

\n *\n * @type {ComponentDatatype}\n * @private\n */\n this.componentDatatype = undefined;\n\n /**\n * The type of the quantized attribute, e.g. AttributeType.VEC2 for oct-encoded normals.\n *\n * @type {AttributeType}\n * @private\n */\n this.type = undefined;\n}\n\n/**\n * A per-vertex or per-instance attribute.\n *\n * @alias ModelComponents.Attribute\n * @constructor\n *\n * @private\n */\nfunction Attribute() {\n /**\n * The attribute name. Must be unique within the attributes array.\n *\n * @type {string}\n * @private\n */\n this.name = undefined;\n\n /**\n * The attribute semantic. The combination of semantic and setIndex must be\n * unique within the attributes array.\n *\n * @type {VertexAttributeSemantic|InstanceAttributeSemantic}\n * @private\n */\n this.semantic = undefined;\n\n /**\n * The set index of the attribute. Only applicable when the attribute has one\n * of the following semantics:\n *\n *
    \n *
  • {@link VertexAttributeSemantic.TEXCOORD}
  • \n *
  • {@link VertexAttributeSemantic.COLOR}
  • \n *
  • {@link VertexAttributeSemantic.JOINTS}
  • \n *
  • {@link VertexAttributeSemantic.WEIGHTS}
  • \n *
  • {@link VertexAttributeSemantic.FEATURE_ID}
  • \n *
  • {@link InstanceAttributeSemantic.FEATURE_ID}
  • \n *
\n */\n this.setIndex = undefined;\n\n /**\n * The component data type of the attribute.\n *

\n * When the data is quantized the componentDatatype should match the\n * dequantized data, which is typically ComponentDatatype.FLOAT.\n *

\n *

\n * The following component datatypes are not supported:\n *

    \n *
  • ComponentDatatype.INT
  • \n *
  • ComponentDatatype.UNSIGNED_INT
  • \n *
  • ComponentDatatype.DOUBLE
  • \n *
\n *

\n *\n * @type {ComponentDatatype}\n * @private\n */\n this.componentDatatype = undefined;\n\n /**\n * The type of the attribute.\n *

\n * When the data is oct-encoded the type should match the decoded data, which\n * is typically AttributeType.VEC3.\n *

\n *\n * @type {AttributeType}\n * @private\n */\n this.type = undefined;\n\n /**\n * Whether the attribute is normalized.\n *\n * @type {boolean}\n * @default false\n * @private\n */\n this.normalized = false;\n\n /**\n * The number of elements.\n *\n * @type {number}\n * @private\n */\n this.count = undefined;\n\n /**\n * Minimum value of each component in the attribute.\n *

\n * When the data is quantized the min should match the dequantized data.\n * The normalized property has no effect on these values.\n *

\n *

\n * Must be defined for POSITION attributes.\n *

\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.min = undefined;\n\n /**\n * Maximum value of each component in the attribute.\n *

\n * When the data is quantized the max should match the dequantized data.\n * The normalized property has no effect on these values.\n *

\n *

\n * Must be defined for POSITION attributes.\n *

\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.max = undefined;\n\n /**\n * A constant value used for all elements when typed array and buffer are undefined.\n *\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @private\n */\n this.constant = undefined;\n\n /**\n * Information about the quantized attribute.\n *\n * @type {ModelComponents.Quantization}\n * @private\n */\n this.quantization = undefined;\n\n /**\n * A typed array containing tightly-packed attribute values, as they appear\n * in the model file.\n *\n * @type {Uint8Array|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array}\n * @private\n */\n this.typedArray = undefined;\n\n /**\n * A vertex buffer. Attribute values are accessed using byteOffset and byteStride.\n *\n * @type {Buffer}\n * @private\n */\n this.buffer = undefined;\n\n /**\n * The byte offset of elements in the buffer.\n *\n * @type {number}\n * @default 0\n * @private\n */\n this.byteOffset = 0;\n\n /**\n * The byte stride of elements in the buffer. When undefined the elements are tightly packed.\n *\n * @type {number}\n * @private\n */\n this.byteStride = undefined;\n}\n\n/**\n * Indices used to select vertices for rendering.\n *\n * @alias ModelComponents.Indices\n * @constructor\n *\n * @private\n */\nfunction Indices() {\n /**\n * The index data type of the attribute, e.g. IndexDatatype.UNSIGNED_SHORT.\n *\n * @type {IndexDatatype}\n * @private\n */\n this.indexDatatype = undefined;\n\n /**\n * The number of indices.\n *\n * @type {number}\n * @private\n */\n this.count = undefined;\n\n /**\n * An index buffer containing indices.\n *\n * @type {Buffer}\n * @private\n */\n this.buffer = undefined;\n\n /**\n * A typed array containing indices.\n *\n * @type {Uint8Array|Uint16Array|Uint32Array}\n * @private\n */\n this.typedArray = undefined;\n}\n\n/**\n * Maps per-vertex or per-instance feature IDs to a property table. Feature\n * IDs are stored in an accessor.\n *\n * @alias ModelComponents.FeatureIdAttribute\n * @constructor\n *\n * @private\n */\nfunction FeatureIdAttribute() {\n /**\n * How many unique features are defined in this set of feature IDs\n *\n * @type {number}\n * @private\n */\n this.featureCount = undefined;\n\n /**\n * This value indicates that no feature is indicated with this vertex\n *\n * @type {number}\n * @private\n */\n this.nullFeatureId = undefined;\n\n /**\n * The ID of the property table that feature IDs index into. If undefined,\n * feature IDs are used for classification, but no metadata is associated.\n *\n *\n * @type {number}\n * @private\n */\n this.propertyTableId = undefined;\n\n /**\n * The set index of feature ID attribute containing feature IDs.\n *\n * @type {number}\n * @private\n */\n this.setIndex = undefined;\n\n /**\n * The label to identify this set of feature IDs. This is used in picking,\n * styling and shaders.\n *\n * @type {string}\n * @private\n */\n this.label = undefined;\n\n /**\n * Label to identify this set of feature IDs by its position in the array.\n * This will always be either \"featureId_N\" for primitives or\n * \"instanceFeatureId_N\" for instances.\n *\n * @type {string}\n * @private\n */\n this.positionalLabel = undefined;\n}\n\n/**\n * Defines a range of implicitly-defined feature IDs, one for each vertex or\n * instance. Such feature IDs may optionally be associated with a property table\n * storing metadata\n *\n * @alias ModelComponents.FeatureIdImplicitRange\n * @constructor\n *\n * @private\n */\nfunction FeatureIdImplicitRange() {\n /**\n * How many unique features are defined in this set of feature IDs\n *\n * @type {number}\n * @private\n */\n this.featureCount = undefined;\n\n /**\n * This value indicates that no feature is indicated with this vertex\n *\n * @type {number}\n * @private\n */\n this.nullFeatureId = undefined;\n\n /**\n * The ID of the property table that feature IDs index into. If undefined,\n * feature IDs are used for classification, but no metadata is associated.\n *\n * @type {number}\n * @private\n */\n this.propertyTableId = undefined;\n\n /**\n * The first feature ID to use when setIndex is undefined\n *\n * @type {number}\n * @default 0\n * @private\n */\n this.offset = 0;\n\n /**\n * Number of times each feature ID is repeated before being incremented.\n *\n * @type {number}\n * @private\n */\n this.repeat = undefined;\n\n /**\n * The label to identify this set of feature IDs. This is used in picking,\n * styling and shaders.\n *\n * @type {string}\n * @private\n */\n this.label = undefined;\n\n /**\n * Label to identify this set of feature IDs by its position in the array.\n * This will always be either \"featureId_N\" for primitives or\n * \"instanceFeatureId_N\" for instances.\n *\n * @type {string}\n * @private\n */\n this.positionalLabel = undefined;\n}\n\n/**\n * A texture that contains per-texel feature IDs that index into a property table.\n *\n * @alias ModelComponents.FeatureIdTexture\n * @constructor\n *\n * @private\n */\nfunction FeatureIdTexture() {\n /**\n * How many unique features are defined in this set of feature IDs\n *\n * @type {number}\n * @private\n */\n this.featureCount = undefined;\n\n /**\n * This value indicates that no feature is indicated with this texel\n *\n * @type {number}\n * @private\n */\n this.nullFeatureId = undefined;\n\n /**\n * The ID of the property table that feature IDs index into. If undefined,\n * feature IDs are used for classification, but no metadata is associated.\n *\n * @type {string}\n * @private\n */\n this.propertyTableId = undefined;\n\n /**\n * The texture reader containing feature IDs.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.textureReader = undefined;\n\n /**\n * The label to identify this set of feature IDs. This is used in picking,\n * styling and shaders.\n *\n * @type {string}\n * @private\n */\n this.label = undefined;\n\n /**\n * Label to identify this set of feature IDs by its position in the array.\n * This will always be either \"featureId_N\" for primitives or\n * \"instanceFeatureId_N\" for instances.\n *\n * @type {string}\n * @private\n */\n this.positionalLabel = undefined;\n}\n\n/**\n * A morph target where each attribute contains attribute displacement data.\n *\n * @alias ModelComponents.MorphTarget\n * @constructor\n *\n * @private\n */\nfunction MorphTarget() {\n /**\n * Attributes that are part of the morph target, e.g. positions, normals, and tangents.\n *\n * @type {ModelComponents.Attribute[]}\n * @private\n */\n this.attributes = [];\n}\n\n/**\n * Geometry to be rendered with a material.\n *\n * @alias ModelComponents.Primitive\n * @constructor\n *\n * @private\n */\nfunction Primitive() {\n /**\n * The vertex attributes, e.g. positions, normals, etc.\n *\n * @type {ModelComponents.Attribute[]}\n * @private\n */\n this.attributes = [];\n\n /**\n * The morph targets.\n *\n * @type {ModelComponents.MorphTarget[]}\n * @private\n */\n this.morphTargets = [];\n\n /**\n * The indices.\n *\n * @type {ModelComponents.Indices}\n * @private\n */\n this.indices = undefined;\n\n /**\n * The material.\n *\n * @type {ModelComponents.Material}\n * @private\n */\n this.material = undefined;\n\n /**\n * The primitive type, e.g. PrimitiveType.TRIANGLES.\n *\n * @type {PrimitiveType}\n * @private\n */\n this.primitiveType = undefined;\n\n /**\n * The feature IDs associated with this primitive. Feature ID types may\n * be interleaved\n *\n * @type {Array}\n * @private\n */\n this.featureIds = [];\n\n /**\n * The property texture IDs. These indices correspond to the array of\n * property textures.\n *\n * @type {number[]}\n * @private\n */\n this.propertyTextureIds = [];\n\n /**\n * The property attribute IDs. These indices correspond to the array of\n * property attributes in the EXT_structural_metadata extension.\n *\n * @type {number[]}\n * @private\n */\n this.propertyAttributeIds = [];\n\n /**\n * If the CESIUM_primitive_outline glTF extension is used, this property\n * stores an additional attribute storing outline coordinates.\n *\n * @type {Attribute}\n * @private\n */\n this.outlineCoordinates = undefined;\n}\n\n/**\n * Position and metadata information for instances of a node.\n *\n * @alias ModelComponents.Instances\n * @constructor\n *\n * @private\n */\nfunction Instances() {\n /**\n * The instance attributes, e.g. translation, rotation, scale, feature id, etc.\n *\n * @type {ModelComponents.Attribute[]}\n * @private\n */\n this.attributes = [];\n\n /**\n * The feature ID attributes associated with this set of instances.\n * Feature ID attribute types may be interleaved.\n *\n * @type {Array}\n * @private\n */\n this.featureIds = [];\n\n /**\n * Whether the instancing transforms are applied in world space. For glTF models that\n * use EXT_mesh_gpu_instancing, the transform is applied in object space. For i3dm files,\n * the instance transform is in world space.\n *\n * @type {boolean}\n * @private\n */\n this.transformInWorldSpace = false;\n}\n\n/**\n * Joints and matrices defining a skin.\n *\n * @alias ModelComponents.Skin\n * @constructor\n *\n * @private\n */\nfunction Skin() {\n /**\n * The index of the skin in the glTF. This is useful for finding the skin\n * that applies to a node after the skin is instantiated at runtime.\n *\n * @type {number}\n * @private\n */\n this.index = undefined;\n\n /**\n * The joints.\n *\n * @type {ModelComponents.Node[]}\n * @private\n */\n this.joints = [];\n\n /**\n * The inverse bind matrices of the joints.\n *\n * @type {Matrix4[]}\n * @private\n */\n this.inverseBindMatrices = [];\n}\n\n/**\n * A node in the node hierarchy.\n *\n * @alias ModelComponents.Node\n * @constructor\n *\n * @private\n */\nfunction Node() {\n /**\n * The name of the node.\n *\n * @type {string}\n * @private\n */\n this.name = undefined;\n\n /**\n * The index of the node in the glTF. This is useful for finding the nodes\n * that belong to a skin after they have been instantiated at runtime.\n *\n * @type {number}\n * @private\n */\n this.index = undefined;\n\n /**\n * The children nodes.\n *\n * @type {ModelComponents.Node[]}\n * @private\n */\n this.children = [];\n\n /**\n * The mesh primitives.\n *\n * @type {ModelComponents.Primitive[]}\n * @private\n */\n this.primitives = [];\n\n /**\n * Instances of this node.\n *\n * @type {ModelComponents.Instances}\n * @private\n */\n this.instances = undefined;\n\n /**\n * The skin.\n *\n * @type {ModelComponents.Skin}\n * @private\n */\n this.skin = undefined;\n\n /**\n * The local transformation matrix. When matrix is defined translation,\n * rotation, and scale must be undefined. When matrix is undefined\n * translation, rotation, and scale must all be defined.\n *\n * @type {Matrix4}\n * @private\n */\n this.matrix = undefined;\n\n /**\n * The local translation.\n *\n * @type {Cartesian3}\n * @private\n */\n this.translation = undefined;\n\n /**\n * The local rotation.\n *\n * @type {Quaternion}\n * @private\n */\n this.rotation = undefined;\n\n /**\n * The local scale.\n *\n * @type {Cartesian3}\n * @private\n */\n this.scale = undefined;\n\n /**\n * An array of weights to be applied to the primitives' morph targets.\n * These are supplied by either the node or its mesh.\n *\n * @type {number[]}\n * @private\n */\n this.morphWeights = [];\n\n /**\n * The name of the articulation affecting this node, as defined by the\n * AGI_articulations extension.\n *\n * @type {string}\n * @private\n */\n this.articulationName = undefined;\n}\n\n/**\n * A scene containing nodes.\n *\n * @alias ModelComponents.Scene\n * @constructor\n *\n * @private\n */\nfunction Scene() {\n /**\n * The nodes belonging to the scene.\n *\n * @type {ModelComponents.Node[]}\n * @private\n */\n this.nodes = [];\n}\n\n/**\n * The property of the node that is targeted by an animation. The values of\n * this enum are used to look up the appropriate property on the runtime node.\n *\n * @alias {ModelComponents.AnimatedPropertyType}\n * @enum {string}\n *\n * @private\n */\nconst AnimatedPropertyType = {\n TRANSLATION: \"translation\",\n ROTATION: \"rotation\",\n SCALE: \"scale\",\n WEIGHTS: \"weights\",\n};\n\n/**\n * An animation sampler that describes the sources of animated keyframe data\n * and their interpolation.\n *\n * @alias {ModelComponents.AnimationSampler}\n * @constructor\n *\n * @private\n */\nfunction AnimationSampler() {\n /**\n * The timesteps of the animation.\n *\n * @type {number[]}\n * @private\n */\n this.input = [];\n\n /**\n * The method used to interpolate between the animation's keyframe data.\n *\n * @type {InterpolationType}\n * @private\n */\n this.interpolation = undefined;\n\n /**\n * The keyframe data of the animation.\n *\n * @type {number[]|Cartesian3[]|Quaternion[]}\n * @private\n */\n this.output = [];\n}\n\n/**\n * An animation target, which specifies the node and property to animate.\n *\n * @alias {ModelComponents.AnimationTarget}\n * @constructor\n *\n * @private\n */\nfunction AnimationTarget() {\n /**\n * The node that will be affected by the animation.\n *\n * @type {ModelComponents.Node}\n * @private\n */\n this.node = undefined;\n\n /**\n * The property of the node to be animated.\n *\n * @type {ModelComponents.AnimatedPropertyType}\n * @private\n */\n this.path = undefined;\n}\n\n/**\n * An animation channel linking an animation sampler and the target it animates.\n *\n * @alias {ModelComponents.AnimationChannel}\n * @constructor\n *\n * @private\n */\nfunction AnimationChannel() {\n /**\n * The sampler used as the source of the animation data.\n *\n * @type {ModelComponents.AnimationSampler}\n * @private\n */\n this.sampler = undefined;\n\n /**\n * The target of the animation.\n *\n * @type {ModelComponents.AnimationTarget}\n * @private\n */\n this.target = undefined;\n}\n\n/**\n * An animation in the model.\n *\n * @alias {ModelComponents.Animation}\n * @constructor\n *\n * @private\n */\nfunction Animation() {\n /**\n * The name of the animation.\n *\n * @type {string}\n * @private\n */\n this.name = undefined;\n\n /**\n * The samplers used in this animation.\n *\n * @type {ModelComponents.AnimationSampler[]}\n * @private\n */\n this.samplers = [];\n\n /**\n * The channels used in this animation.\n *\n * @type {ModelComponents.AnimationChannel[]}\n * @private\n */\n this.channels = [];\n}\n\n/**\n * An articulation stage belonging to an articulation from the\n * AGI_articulations extension.\n *\n * @alias {ModelComponents.ArticulationStage}\n * @constructor\n *\n * @private\n */\nfunction ArticulationStage() {\n /**\n * The name of the articulation stage.\n *\n * @type {string}\n * @private\n */\n this.name = undefined;\n\n /**\n * The type of the articulation stage, defined by the type of motion it modifies.\n *\n * @type {ArticulationStageType}\n * @private\n */\n this.type = undefined;\n\n /**\n * The minimum value for the range of motion of this articulation stage.\n *\n * @type {number}\n * @private\n */\n this.minimumValue = undefined;\n\n /**\n * The maximum value for the range of motion of this articulation stage.\n *\n * @type {number}\n * @private\n */\n this.maximumValue = undefined;\n\n /**\n * The initial value for this articulation stage.\n *\n * @type {number}\n * @private\n */\n this.initialValue = undefined;\n}\n\n/**\n * An articulation for the model, as defined by the AGI_articulations extension.\n *\n * @alias {ModelComponents.Articulation}\n * @constructor\n *\n * @private\n */\nfunction Articulation() {\n /**\n * The name of the articulation.\n *\n * @type {string}\n * @private\n */\n this.name = undefined;\n\n /**\n * The stages belonging to this articulation. The stages are applied to\n * the model in order of appearance.\n *\n * @type {ModelComponents.ArticulationStage[]}\n * @private\n */\n this.stages = [];\n}\n\n/**\n * The asset of the model.\n *\n * @alias {ModelComponents.Asset}\n * @constructor\n *\n * @private\n */\nfunction Asset() {\n /**\n * The credits of the model.\n *\n * @type {Credit[]}\n * @private\n */\n this.credits = [];\n}\n\n/**\n * The components that make up a model.\n *\n * @alias ModelComponents.Components\n * @constructor\n *\n * @private\n */\nfunction Components() {\n /**\n * The asset of the model.\n *\n * @type {ModelComponents.Asset}\n * @private\n */\n this.asset = new Asset();\n\n /**\n * The default scene.\n *\n * @type {ModelComponents.Scene}\n * @private\n */\n this.scene = undefined;\n\n /**\n * All nodes in the model.\n *\n * @type {ModelComponents.Node[]}\n */\n this.nodes = [];\n\n /**\n * All skins in the model.\n *\n * @type {ModelComponents.Skin[]}\n */\n this.skins = [];\n\n /**\n * All animations in the model.\n *\n * @type {ModelComponents.Animation[]}\n */\n this.animations = [];\n\n /**\n * All articulations in the model as defined by the AGI_articulations extension.\n *\n * @type {ModelComponents.Articulation[]}\n */\n this.articulations = [];\n\n /**\n * Structural metadata containing the schema, property tables, property\n * textures and property mappings\n *\n * @type {StructuralMetadata}\n * @private\n */\n this.structuralMetadata = undefined;\n\n /**\n * The model's up axis.\n *\n * @type {Axis}\n * @private\n */\n this.upAxis = undefined;\n\n /**\n * The model's forward axis.\n *\n * @type {Axis}\n * @private\n */\n this.forwardAxis = undefined;\n\n /**\n * A world-space transform to apply to the primitives.\n *\n * @type {Matrix4}\n * @private\n */\n this.transform = Matrix4.clone(Matrix4.IDENTITY);\n}\n\n/**\n * Information about a GPU texture, including the texture itself\n *\n * @alias ModelComponents.TextureReader\n * @constructor\n *\n * @private\n */\nfunction TextureReader() {\n /**\n * The underlying GPU texture. The {@link Texture} contains the sampler.\n *\n * @type {Texture}\n * @private\n */\n this.texture = undefined;\n\n /**\n * The index of the texture in the glTF. This is useful for determining\n * when textures are shared to avoid attaching a texture in multiple uniform\n * slots in the shader.\n *\n * @type {number}\n * @private\n */\n this.index = undefined;\n\n /**\n * The texture coordinate set.\n *\n * @type {number}\n * @default 0\n * @private\n */\n this.texCoord = 0;\n\n /**\n * Transformation matrix to apply to texture coordinates.\n *\n * @type {Matrix3}\n * @default Matrix3.IDENTITY\n */\n this.transform = Matrix3.clone(Matrix3.IDENTITY);\n\n /**\n * The texture channels to read from. When undefined all channels are read.\n *\n * @type {string}\n */\n this.channels = undefined;\n}\n\n/**\n * Material properties for the PBR metallic roughness shading model.\n *\n * @alias ModelComponents.MetallicRoughness\n * @constructor\n *\n * @private\n */\nfunction MetallicRoughness() {\n /**\n * The base color texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.baseColorTexture = undefined;\n\n /**\n * The metallic roughness texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.metallicRoughnessTexture = undefined;\n\n /**\n * The base color factor.\n *\n * @type {Cartesian4}\n * @default new Cartesian4(1.0, 1.0, 1.0, 1.0)\n * @private\n */\n this.baseColorFactor = Cartesian4.clone(\n MetallicRoughness.DEFAULT_BASE_COLOR_FACTOR\n );\n\n /**\n * The metallic factor.\n *\n * @type {number}\n * @default 1.0\n * @private\n */\n this.metallicFactor = MetallicRoughness.DEFAULT_METALLIC_FACTOR;\n\n /**\n * The roughness factor.\n *\n * @type {number}\n * @default 1.0\n * @private\n */\n this.roughnessFactor = MetallicRoughness.DEFAULT_ROUGHNESS_FACTOR;\n}\n\n/**\n * @private\n */\nMetallicRoughness.DEFAULT_BASE_COLOR_FACTOR = Cartesian4.ONE;\n\n/**\n * @private\n */\nMetallicRoughness.DEFAULT_METALLIC_FACTOR = 1.0;\n\n/**\n * @private\n */\nMetallicRoughness.DEFAULT_ROUGHNESS_FACTOR = 1.0;\n\n/**\n * Material properties for the PBR specular glossiness shading model.\n *\n * @alias ModelComponents.SpecularGlossiness\n * @constructor\n *\n * @private\n */\nfunction SpecularGlossiness() {\n /**\n * The diffuse texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.diffuseTexture = undefined;\n\n /**\n * The specular glossiness texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.specularGlossinessTexture = undefined;\n\n /**\n * The diffuse factor.\n *\n * @type {Cartesian4}\n * @default new Cartesian4(1.0, 1.0, 1.0, 1.0)\n * @private\n */\n this.diffuseFactor = Cartesian4.clone(\n SpecularGlossiness.DEFAULT_DIFFUSE_FACTOR\n );\n\n /**\n * The specular factor.\n *\n * @type {Cartesian3}\n * @default new Cartesian3(1.0, 1.0, 1.0)\n * @private\n */\n this.specularFactor = Cartesian3.clone(\n SpecularGlossiness.DEFAULT_SPECULAR_FACTOR\n );\n\n /**\n * The glossiness factor.\n *\n * @type {number}\n * @default 1.0\n * @private\n */\n this.glossinessFactor = SpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR;\n}\n\n/**\n * @private\n */\nSpecularGlossiness.DEFAULT_DIFFUSE_FACTOR = Cartesian4.ONE;\n\n/**\n * @private\n */\nSpecularGlossiness.DEFAULT_SPECULAR_FACTOR = Cartesian3.ONE;\n\n/**\n * @private\n */\nSpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR = 1.0;\n\n/**\n * The material appearance of a primitive.\n *\n * @alias ModelComponent.Material\n * @constructor\n *\n * @private\n */\nfunction Material() {\n /**\n * Material properties for the PBR metallic roughness shading model.\n *\n * @type {ModelComponents.MetallicRoughness}\n * @private\n */\n this.metallicRoughness = new MetallicRoughness();\n\n /**\n * Material properties for the PBR specular glossiness shading model.\n *\n * @type {ModelComponents.SpecularGlossiness}\n * @private\n */\n this.specularGlossiness = undefined;\n\n /**\n * The emissive texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.emissiveTexture = undefined;\n\n /**\n * The normal texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.normalTexture = undefined;\n\n /**\n * The occlusion texture reader.\n *\n * @type {ModelComponents.TextureReader}\n * @private\n */\n this.occlusionTexture = undefined;\n\n /**\n * The emissive factor.\n *\n * @type {Cartesian3}\n * @default Cartesian3.ZERO\n * @private\n */\n this.emissiveFactor = Cartesian3.clone(Material.DEFAULT_EMISSIVE_FACTOR);\n\n /**\n * The alpha mode.\n *\n * @type {AlphaMode}\n * @default AlphaMode.OPAQUE\n * @private\n */\n this.alphaMode = AlphaMode.OPAQUE;\n\n /**\n * The alpha cutoff value of the material for the MASK alpha mode.\n *\n * @type {number}\n * @default 0.5\n * @private\n */\n this.alphaCutoff = 0.5;\n\n /**\n * Specifies whether the material is double sided.\n *\n * @type {boolean}\n * @default false\n * @private\n */\n this.doubleSided = false;\n\n /**\n * Specifies whether the material is unlit.\n *\n * @type {boolean}\n * @default false\n * @private\n */\n this.unlit = false;\n}\n\n/**\n * @private\n */\nMaterial.DEFAULT_EMISSIVE_FACTOR = Cartesian3.ZERO;\n\nModelComponents.Quantization = Quantization;\nModelComponents.Attribute = Attribute;\nModelComponents.Indices = Indices;\nModelComponents.FeatureIdAttribute = FeatureIdAttribute;\nModelComponents.FeatureIdTexture = FeatureIdTexture;\nModelComponents.FeatureIdImplicitRange = FeatureIdImplicitRange;\nModelComponents.MorphTarget = MorphTarget;\nModelComponents.Primitive = Primitive;\nModelComponents.Instances = Instances;\nModelComponents.Skin = Skin;\nModelComponents.Node = Node;\nModelComponents.Scene = Scene;\nModelComponents.AnimatedPropertyType = Object.freeze(AnimatedPropertyType);\nModelComponents.AnimationSampler = AnimationSampler;\nModelComponents.AnimationTarget = AnimationTarget;\nModelComponents.AnimationChannel = AnimationChannel;\nModelComponents.Animation = Animation;\nModelComponents.ArticulationStage = ArticulationStage;\nModelComponents.Articulation = Articulation;\nModelComponents.Asset = Asset;\nModelComponents.Components = Components;\nModelComponents.TextureReader = TextureReader;\nModelComponents.MetallicRoughness = MetallicRoughness;\nModelComponents.SpecularGlossiness = SpecularGlossiness;\nModelComponents.Material = Material;\n\nexport default ModelComponents;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport TextureMagnificationFilter from \"../Renderer/TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"../Renderer/TextureMinificationFilter.js\";\nimport TextureWrap from \"../Renderer/TextureWrap.js\";\nimport ModelComponents from \"./ModelComponents.js\";\n\n/**\n * glTF loading utilities.\n *\n * @namespace GltfLoaderUtil\n *\n * @private\n */\nconst GltfLoaderUtil = {};\n\n/**\n * Get the image ID referenced by a texture.\n *

\n * When the texture has the EXT_texture_webp extension and the browser supports\n * WebP images the WebP image ID is returned.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.textureId The texture ID.\n * @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.\n *\n * @returns {number} The image ID.\n * @private\n */\nGltfLoaderUtil.getImageIdFromTexture = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const textureId = options.textureId;\n const supportedImageFormats = options.supportedImageFormats;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.textureId\", textureId);\n Check.typeOf.object(\"options.supportedImageFormats\", supportedImageFormats);\n //>>includeEnd('debug');\n\n const texture = gltf.textures[textureId];\n const extensions = texture.extensions;\n if (defined(extensions)) {\n if (supportedImageFormats.webp && defined(extensions.EXT_texture_webp)) {\n return extensions.EXT_texture_webp.source;\n } else if (\n supportedImageFormats.basis &&\n defined(extensions.KHR_texture_basisu)\n ) {\n return extensions.KHR_texture_basisu.source;\n }\n }\n return texture.source;\n};\n\n/**\n * Create a sampler for a texture.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.textureInfo The texture info object.\n * @param {boolean} [options.compressedTextureNoMipmap=false] True when the texture is compressed and does not have an embedded mipmap.\n *\n * @returns {Sampler} The sampler.\n * @private\n */\nGltfLoaderUtil.createSampler = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const textureInfo = options.textureInfo;\n const compressedTextureNoMipmap = defaultValue(\n options.compressedTextureNoMipmap,\n false\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.textureInfo\", textureInfo);\n //>>includeEnd('debug');\n\n // Default sampler properties\n let wrapS = TextureWrap.REPEAT;\n let wrapT = TextureWrap.REPEAT;\n let minFilter = TextureMinificationFilter.LINEAR;\n let magFilter = TextureMagnificationFilter.LINEAR;\n\n const textureId = textureInfo.index;\n const texture = gltf.textures[textureId];\n const samplerId = texture.sampler;\n\n if (defined(samplerId)) {\n const sampler = gltf.samplers[samplerId];\n wrapS = defaultValue(sampler.wrapS, wrapS);\n wrapT = defaultValue(sampler.wrapT, wrapT);\n minFilter = defaultValue(sampler.minFilter, minFilter);\n magFilter = defaultValue(sampler.magFilter, magFilter);\n }\n\n if (\n compressedTextureNoMipmap &&\n minFilter !== TextureMinificationFilter.LINEAR &&\n minFilter !== TextureMinificationFilter.NEAREST\n ) {\n if (\n minFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||\n minFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR\n ) {\n minFilter = TextureMinificationFilter.NEAREST;\n } else {\n minFilter = TextureMinificationFilter.LINEAR;\n }\n }\n\n return new Sampler({\n wrapS: wrapS,\n wrapT: wrapT,\n minificationFilter: minFilter,\n magnificationFilter: magFilter,\n });\n};\n\nconst defaultScale = new Cartesian2(1.0, 1.0);\n\n/**\n * Create a model texture reader.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.textureInfo The texture info JSON.\n * @param {string} [options.channels] The texture channels to read from.\n * @param {Texture} [options.texture] The texture object.\n *\n * @returns {ModelComponents.TextureReader} The texture reader for this model.\n */\nGltfLoaderUtil.createModelTextureReader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const textureInfo = options.textureInfo;\n const channels = options.channels;\n const texture = options.texture;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.textureInfo\", textureInfo);\n //>>includeEnd('debug');\n\n let texCoord = defaultValue(textureInfo.texCoord, 0);\n let transform;\n\n const textureTransform = defaultValue(\n textureInfo.extensions,\n defaultValue.EMPTY_OBJECT\n ).KHR_texture_transform;\n\n if (defined(textureTransform)) {\n texCoord = defaultValue(textureTransform.texCoord, texCoord);\n\n const offset = defined(textureTransform.offset)\n ? Cartesian2.unpack(textureTransform.offset)\n : Cartesian2.ZERO;\n let rotation = defaultValue(textureTransform.rotation, 0.0);\n const scale = defined(textureTransform.scale)\n ? Cartesian2.unpack(textureTransform.scale)\n : defaultScale;\n\n // glTF assumes UV coordinates start with (0, 0) in the top left corner\n // (y-down) unlike WebGL which puts (0, 0) in the bottom left corner (y-up).\n // This means rotations are reversed since the angle from x to y is now\n // clockwise instead of CCW. Translations and scales are not impacted by\n // this.\n rotation = -rotation;\n\n // prettier-ignore\n transform = new Matrix3(\n Math.cos(rotation) * scale.x, -Math.sin(rotation) * scale.y, offset.x,\n Math.sin(rotation) * scale.x, Math.cos(rotation) * scale.y, offset.y,\n 0.0, 0.0, 1.0\n );\n }\n\n const modelTextureReader = new ModelComponents.TextureReader();\n modelTextureReader.index = textureInfo.index;\n modelTextureReader.texture = texture;\n modelTextureReader.texCoord = texCoord;\n modelTextureReader.transform = transform;\n modelTextureReader.channels = channels;\n\n return modelTextureReader;\n};\n\nexport default GltfLoaderUtil;\n", "import CesiumMath from \"./Math.js\";\n\n/**\n * Resizes an image to ensure both width and height are powers of 2.\n * NOTE: The input image is resampled larger, rather than padded.\n * The aspect ratio of the image may change.\n *\n * @param {HTMLImageElement|HTMLCanvasElement} image The image to be resized\n * @returns {HTMLCanvasElement} A new canvas with the resized image drawn to it\n *\n * @private\n */\nfunction resizeImageToNextPowerOfTwo(image) {\n const canvas = document.createElement(\"canvas\");\n canvas.width = CesiumMath.nextPowerOfTwo(image.width);\n canvas.height = CesiumMath.nextPowerOfTwo(image.height);\n const canvasContext = canvas.getContext(\"2d\");\n canvasContext.drawImage(\n image,\n 0,\n 0,\n image.width,\n image.height,\n 0,\n 0,\n canvas.width,\n canvas.height\n );\n return canvas;\n}\nexport default resizeImageToNextPowerOfTwo;\n", "import Check from \"../Core/Check.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport Texture from \"../Renderer/Texture.js\";\nimport TextureMinificationFilter from \"../Renderer/TextureMinificationFilter.js\";\nimport TextureWrap from \"../Renderer/TextureWrap.js\";\nimport GltfLoaderUtil from \"./GltfLoaderUtil.js\";\nimport JobType from \"./JobType.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\nimport resizeImageToNextPowerOfTwo from \"../Core/resizeImageToNextPowerOfTwo.js\";\n\n/**\n * Loads a glTF texture.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfTextureLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.textureInfo The texture info object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.\n * @param {string} [options.cacheKey] The cache key of the resource.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n *\n * @private\n */\nfunction GltfTextureLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const textureInfo = options.textureInfo;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const supportedImageFormats = options.supportedImageFormats;\n const cacheKey = options.cacheKey;\n const asynchronous = defaultValue(options.asynchronous, true);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.textureInfo\", textureInfo);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.supportedImageFormats\", supportedImageFormats);\n //>>includeEnd('debug');\n\n const textureId = textureInfo.index;\n\n // imageId is guaranteed to be defined otherwise the GltfTextureLoader\n // wouldn't have been created\n const imageId = GltfLoaderUtil.getImageIdFromTexture({\n gltf: gltf,\n textureId: textureId,\n supportedImageFormats: supportedImageFormats,\n });\n\n this._resourceCache = resourceCache;\n this._gltf = gltf;\n this._textureInfo = textureInfo;\n this._imageId = imageId;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._cacheKey = cacheKey;\n this._asynchronous = asynchronous;\n this._imageLoader = undefined;\n this._image = undefined;\n this._mipLevels = undefined;\n this._texture = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfTextureLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfTextureLoader.prototype.constructor = GltfTextureLoader;\n}\n\nObject.defineProperties(GltfTextureLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfTextureLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The texture.\n *\n * @memberof GltfTextureLoader.prototype\n *\n * @type {Texture}\n * @readonly\n * @private\n */\n texture: {\n get: function () {\n return this._texture;\n },\n },\n});\n\nconst scratchTextureJob = new CreateTextureJob();\n\nasync function loadResources(loader) {\n const resourceCache = loader._resourceCache;\n try {\n const imageLoader = resourceCache.getImageLoader({\n gltf: loader._gltf,\n imageId: loader._imageId,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n });\n loader._imageLoader = imageLoader;\n await imageLoader.load();\n\n if (loader.isDestroyed()) {\n return;\n }\n\n // Now wait for process() to run to finish loading\n loader._image = imageLoader.image;\n loader._mipLevels = imageLoader.mipLevels;\n loader._state = ResourceLoaderState.LOADED;\n\n return loader;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n loader.unload();\n loader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load texture\";\n throw loader.getError(errorMessage, error);\n }\n}\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfTextureLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._state = ResourceLoaderState.LOADING;\n this._promise = loadResources(this);\n return this._promise;\n};\n\nfunction CreateTextureJob() {\n this.gltf = undefined;\n this.textureInfo = undefined;\n this.image = undefined;\n this.context = undefined;\n this.texture = undefined;\n}\n\nCreateTextureJob.prototype.set = function (\n gltf,\n textureInfo,\n image,\n mipLevels,\n context\n) {\n this.gltf = gltf;\n this.textureInfo = textureInfo;\n this.image = image;\n this.mipLevels = mipLevels;\n this.context = context;\n};\n\nCreateTextureJob.prototype.execute = function () {\n this.texture = createTexture(\n this.gltf,\n this.textureInfo,\n this.image,\n this.mipLevels,\n this.context\n );\n};\n\nfunction createTexture(gltf, textureInfo, image, mipLevels, context) {\n // internalFormat is only defined for CompressedTextureBuffer\n const internalFormat = image.internalFormat;\n\n let compressedTextureNoMipmap = false;\n if (PixelFormat.isCompressedFormat(internalFormat) && !defined(mipLevels)) {\n compressedTextureNoMipmap = true;\n }\n\n const sampler = GltfLoaderUtil.createSampler({\n gltf: gltf,\n textureInfo: textureInfo,\n compressedTextureNoMipmap: compressedTextureNoMipmap,\n });\n\n const minFilter = sampler.minificationFilter;\n const wrapS = sampler.wrapS;\n const wrapT = sampler.wrapT;\n\n const samplerRequiresMipmap =\n minFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||\n minFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR ||\n minFilter === TextureMinificationFilter.LINEAR_MIPMAP_NEAREST ||\n minFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR;\n\n // generateMipmap is disallowed for compressed textures. Compressed textures\n // can have mipmaps but they must come with the KTX2 instead of generated by\n // WebGL. Also note from the KHR_texture_basisu spec:\n //\n // When a texture refers to a sampler with mipmap minification or when the\n // sampler is undefined, the KTX2 image SHOULD contain a full mip pyramid.\n //\n const generateMipmap = !defined(internalFormat) && samplerRequiresMipmap;\n\n // WebGL 1 requires power-of-two texture dimensions for mipmapping and REPEAT/MIRRORED_REPEAT wrap modes.\n const requiresPowerOfTwo =\n generateMipmap ||\n wrapS === TextureWrap.REPEAT ||\n wrapS === TextureWrap.MIRRORED_REPEAT ||\n wrapT === TextureWrap.REPEAT ||\n wrapT === TextureWrap.MIRRORED_REPEAT;\n\n const nonPowerOfTwo =\n !CesiumMath.isPowerOfTwo(image.width) ||\n !CesiumMath.isPowerOfTwo(image.height);\n\n const requiresResize = requiresPowerOfTwo && nonPowerOfTwo;\n\n let texture;\n if (defined(internalFormat)) {\n if (\n !context.webgl2 &&\n PixelFormat.isCompressedFormat(internalFormat) &&\n nonPowerOfTwo &&\n requiresPowerOfTwo\n ) {\n console.warn(\n \"Compressed texture uses REPEAT or MIRRORED_REPEAT texture wrap mode and dimensions are not powers of two. The texture may be rendered incorrectly.\"\n );\n }\n\n texture = Texture.create({\n context: context,\n source: {\n arrayBufferView: image.bufferView, // Only defined for CompressedTextureBuffer\n mipLevels: mipLevels,\n },\n width: image.width,\n height: image.height,\n pixelFormat: image.internalFormat, // Only defined for CompressedTextureBuffer\n sampler: sampler,\n });\n } else {\n if (requiresResize) {\n image = resizeImageToNextPowerOfTwo(image);\n }\n texture = Texture.create({\n context: context,\n source: image,\n sampler: sampler,\n flipY: false,\n skipColorSpaceConversion: true,\n });\n }\n\n if (generateMipmap) {\n texture.generateMipmap();\n }\n\n return texture;\n}\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {boolean} true once all resourced are ready.\n * @private\n */\nGltfTextureLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (\n this._state !== ResourceLoaderState.LOADED &&\n this._state !== ResourceLoaderState.PROCESSING\n ) {\n return false;\n }\n\n if (defined(this._texture)) {\n // Already created texture\n return false;\n }\n\n if (!defined(this._image)) {\n // Not ready to create texture\n return false;\n }\n\n this._state = ResourceLoaderState.PROCESSING;\n\n let texture;\n if (this._asynchronous) {\n const textureJob = scratchTextureJob;\n textureJob.set(\n this._gltf,\n this._textureInfo,\n this._image,\n this._mipLevels,\n frameState.context\n );\n const jobScheduler = frameState.jobScheduler;\n if (!jobScheduler.execute(textureJob, JobType.TEXTURE)) {\n // Job scheduler is full. Try again next frame.\n return;\n }\n texture = textureJob.texture;\n } else {\n texture = createTexture(\n this._gltf,\n this._textureInfo,\n this._image,\n this._mipLevels,\n frameState.context\n );\n }\n\n // Unload everything except the texture\n this.unload();\n\n this._texture = texture;\n this._state = ResourceLoaderState.READY;\n this._resourceCache.statistics.addTextureLoader(this);\n return true;\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfTextureLoader.prototype.unload = function () {\n if (defined(this._texture)) {\n this._texture.destroy();\n }\n\n if (defined(this._imageLoader) && !this._imageLoader.isDestroyed()) {\n this._resourceCache.unload(this._imageLoader);\n }\n\n this._imageLoader = undefined;\n this._image = undefined;\n this._mipLevels = undefined;\n this._texture = undefined;\n this._gltf = undefined;\n};\n\nexport default GltfTextureLoader;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport AttributeType from \"./AttributeType.js\";\nimport JobType from \"./JobType.js\";\nimport ModelComponents from \"./ModelComponents.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads a vertex buffer from a glTF buffer view.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfVertexBufferLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {ResourceCache} options.resourceCache The {@link ResourceCache} (to avoid circular dependencies).\n * @param {object} options.gltf The glTF JSON.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {number} [options.bufferViewId] The bufferView ID corresponding to the vertex buffer.\n * @param {object} [options.draco] The Draco extension object.\n * @param {string} [options.attributeSemantic] The attribute semantic, e.g. POSITION or NORMAL.\n * @param {number} [options.accessorId] The accessor id.\n * @param {string} [options.cacheKey] The cache key of the resource.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.loadBuffer=false] Load vertex buffer as a GPU vertex buffer.\n * @param {boolean} [options.loadTypedArray=false] Load vertex buffer as a typed array.\n *\n * @exception {DeveloperError} One of options.bufferViewId and options.draco must be defined.\n * @exception {DeveloperError} When options.draco is defined options.attributeSemantic must also be defined.\n * @exception {DeveloperError} When options.draco is defined options.accessorId must also be defined.\n *\n * @private\n */\nfunction GltfVertexBufferLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resourceCache = options.resourceCache;\n const gltf = options.gltf;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const bufferViewId = options.bufferViewId;\n const draco = options.draco;\n const attributeSemantic = options.attributeSemantic;\n const accessorId = options.accessorId;\n const cacheKey = options.cacheKey;\n const asynchronous = defaultValue(options.asynchronous, true);\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.resourceCache\", resourceCache);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n\n const hasBufferViewId = defined(bufferViewId);\n const hasDraco = hasDracoCompression(draco, attributeSemantic);\n const hasAttributeSemantic = defined(attributeSemantic);\n const hasAccessorId = defined(accessorId);\n\n if (hasBufferViewId === hasDraco) {\n throw new DeveloperError(\n \"One of options.bufferViewId and options.draco must be defined.\"\n );\n }\n\n if (hasDraco && !hasAttributeSemantic) {\n throw new DeveloperError(\n \"When options.draco is defined options.attributeSemantic must also be defined.\"\n );\n }\n\n if (hasDraco && !hasAccessorId) {\n throw new DeveloperError(\n \"When options.draco is defined options.accessorId must also be defined.\"\n );\n }\n\n if (hasDraco) {\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.string(\"options.attributeSemantic\", attributeSemantic);\n Check.typeOf.number(\"options.accessorId\", accessorId);\n }\n //>>includeEnd('debug');\n\n this._resourceCache = resourceCache;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._gltf = gltf;\n this._bufferViewId = bufferViewId;\n this._draco = draco;\n this._attributeSemantic = attributeSemantic;\n this._accessorId = accessorId;\n this._cacheKey = cacheKey;\n this._asynchronous = asynchronous;\n this._loadBuffer = loadBuffer;\n this._loadTypedArray = loadTypedArray;\n this._bufferViewLoader = undefined;\n this._dracoLoader = undefined;\n this._quantization = undefined;\n this._typedArray = undefined;\n this._buffer = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfVertexBufferLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfVertexBufferLoader.prototype.constructor = GltfVertexBufferLoader;\n}\n\nObject.defineProperties(GltfVertexBufferLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfVertexBufferLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The vertex buffer. This is only defined when loadAsTypedArray is false.\n *\n * @memberof GltfVertexBufferLoader.prototype\n *\n * @type {Buffer}\n * @readonly\n * @private\n */\n buffer: {\n get: function () {\n return this._buffer;\n },\n },\n /**\n * The typed array containing vertex buffer data. This is only defined when loadAsTypedArray is true.\n *\n * @memberof GltfVertexBufferLoader.prototype\n *\n * @type {Uint8Array}\n * @readonly\n * @private\n */\n typedArray: {\n get: function () {\n return this._typedArray;\n },\n },\n /**\n * Information about the quantized vertex attribute after Draco decode.\n *\n * @memberof GltfVertexBufferLoader.prototype\n *\n * @type {ModelComponents.Quantization}\n * @readonly\n * @private\n */\n quantization: {\n get: function () {\n return this._quantization;\n },\n },\n});\n\nfunction hasDracoCompression(draco, semantic) {\n return (\n defined(draco) &&\n defined(draco.attributes) &&\n defined(draco.attributes[semantic])\n );\n}\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfVertexBufferLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n if (hasDracoCompression(this._draco, this._attributeSemantic)) {\n this._promise = loadFromDraco(this);\n return this._promise;\n }\n\n this._promise = loadFromBufferView(this);\n return this._promise;\n};\n\nfunction getQuantizationInformation(\n dracoQuantization,\n componentDatatype,\n componentCount,\n type\n) {\n const quantizationBits = dracoQuantization.quantizationBits;\n const normalizationRange = (1 << quantizationBits) - 1;\n const normalizationDivisor = 1.0 / normalizationRange;\n\n const quantization = new ModelComponents.Quantization();\n quantization.componentDatatype = componentDatatype;\n quantization.octEncoded = dracoQuantization.octEncoded;\n quantization.octEncodedZXY = true;\n quantization.type = type;\n\n if (quantization.octEncoded) {\n quantization.type = AttributeType.VEC2;\n quantization.normalizationRange = normalizationRange;\n } else {\n const MathType = AttributeType.getMathType(type);\n if (MathType === Number) {\n const dimensions = dracoQuantization.range;\n quantization.quantizedVolumeOffset = dracoQuantization.minValues[0];\n quantization.quantizedVolumeDimensions = dimensions;\n quantization.normalizationRange = normalizationRange;\n quantization.quantizedVolumeStepSize = dimensions * normalizationDivisor;\n } else {\n quantization.quantizedVolumeOffset = MathType.unpack(\n dracoQuantization.minValues\n );\n quantization.normalizationRange = MathType.unpack(\n new Array(componentCount).fill(normalizationRange)\n );\n const packedDimensions = new Array(componentCount).fill(\n dracoQuantization.range\n );\n quantization.quantizedVolumeDimensions = MathType.unpack(\n packedDimensions\n );\n\n // Computing the step size\n const packedSteps = packedDimensions.map(function (dimension) {\n return dimension * normalizationDivisor;\n });\n quantization.quantizedVolumeStepSize = MathType.unpack(packedSteps);\n }\n }\n\n return quantization;\n}\n\nasync function loadFromDraco(vertexBufferLoader) {\n vertexBufferLoader._state = ResourceLoaderState.LOADING;\n const resourceCache = vertexBufferLoader._resourceCache;\n try {\n const dracoLoader = resourceCache.getDracoLoader({\n gltf: vertexBufferLoader._gltf,\n draco: vertexBufferLoader._draco,\n gltfResource: vertexBufferLoader._gltfResource,\n baseResource: vertexBufferLoader._baseResource,\n });\n vertexBufferLoader._dracoLoader = dracoLoader;\n await dracoLoader.load();\n\n if (vertexBufferLoader.isDestroyed()) {\n return;\n }\n\n // Now wait for process() to run to finish loading\n vertexBufferLoader._state = ResourceLoaderState.LOADED;\n return vertexBufferLoader;\n } catch {\n if (vertexBufferLoader.isDestroyed()) {\n return;\n }\n\n handleError(vertexBufferLoader);\n }\n}\n\nfunction processDraco(vertexBufferLoader) {\n vertexBufferLoader._state = ResourceLoaderState.PROCESSING;\n const dracoLoader = vertexBufferLoader._dracoLoader;\n\n // Get the typed array and quantization information\n const decodedVertexAttributes = dracoLoader.decodedData.vertexAttributes;\n const attributeSemantic = vertexBufferLoader._attributeSemantic;\n const dracoAttribute = decodedVertexAttributes[attributeSemantic];\n const accessorId = vertexBufferLoader._accessorId;\n const accessor = vertexBufferLoader._gltf.accessors[accessorId];\n const type = accessor.type;\n const typedArray = dracoAttribute.array;\n const dracoQuantization = dracoAttribute.data.quantization;\n if (defined(dracoQuantization)) {\n vertexBufferLoader._quantization = getQuantizationInformation(\n dracoQuantization,\n dracoAttribute.data.componentDatatype,\n dracoAttribute.data.componentsPerAttribute,\n type\n );\n }\n\n vertexBufferLoader._typedArray = new Uint8Array(\n typedArray.buffer,\n typedArray.byteOffset,\n typedArray.byteLength\n );\n}\n\nasync function loadFromBufferView(vertexBufferLoader) {\n vertexBufferLoader._state = ResourceLoaderState.LOADING;\n const resourceCache = vertexBufferLoader._resourceCache;\n try {\n const bufferViewLoader = resourceCache.getBufferViewLoader({\n gltf: vertexBufferLoader._gltf,\n bufferViewId: vertexBufferLoader._bufferViewId,\n gltfResource: vertexBufferLoader._gltfResource,\n baseResource: vertexBufferLoader._baseResource,\n });\n vertexBufferLoader._bufferViewLoader = bufferViewLoader;\n await bufferViewLoader.load();\n\n if (vertexBufferLoader.isDestroyed()) {\n return;\n }\n\n vertexBufferLoader._typedArray = bufferViewLoader.typedArray;\n vertexBufferLoader._state = ResourceLoaderState.PROCESSING;\n return vertexBufferLoader;\n } catch (error) {\n if (vertexBufferLoader.isDestroyed()) {\n return;\n }\n\n handleError(vertexBufferLoader, error);\n }\n}\n\nfunction handleError(vertexBufferLoader, error) {\n vertexBufferLoader.unload();\n vertexBufferLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load vertex buffer\";\n throw vertexBufferLoader.getError(errorMessage, error);\n}\n\nfunction CreateVertexBufferJob() {\n this.typedArray = undefined;\n this.context = undefined;\n this.buffer = undefined;\n}\n\nCreateVertexBufferJob.prototype.set = function (typedArray, context) {\n this.typedArray = typedArray;\n this.context = context;\n};\n\nCreateVertexBufferJob.prototype.execute = function () {\n this.buffer = createVertexBuffer(this.typedArray, this.context);\n};\n\nfunction createVertexBuffer(typedArray, context) {\n const buffer = Buffer.createVertexBuffer({\n typedArray: typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n });\n buffer.vertexArrayDestroyable = false;\n return buffer;\n}\n\nconst scratchVertexBufferJob = new CreateVertexBufferJob();\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGltfVertexBufferLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (\n this._state !== ResourceLoaderState.LOADED &&\n this._state !== ResourceLoaderState.PROCESSING\n ) {\n return false;\n }\n\n if (defined(this._dracoLoader)) {\n try {\n const ready = this._dracoLoader.process(frameState);\n if (!ready) {\n return false;\n }\n } catch (error) {\n handleError(this, error);\n }\n\n processDraco(this);\n }\n\n let buffer;\n const typedArray = this._typedArray;\n if (this._loadBuffer && this._asynchronous) {\n const vertexBufferJob = scratchVertexBufferJob;\n vertexBufferJob.set(typedArray, frameState.context);\n const jobScheduler = frameState.jobScheduler;\n if (!jobScheduler.execute(vertexBufferJob, JobType.BUFFER)) {\n // Job scheduler is full. Try again next frame.\n return false;\n }\n buffer = vertexBufferJob.buffer;\n } else if (this._loadBuffer) {\n buffer = createVertexBuffer(typedArray, frameState.context);\n }\n\n // Unload everything except the vertex buffer\n this.unload();\n\n this._buffer = buffer;\n this._typedArray = this._loadTypedArray ? typedArray : undefined;\n this._state = ResourceLoaderState.READY;\n this._resourceCache.statistics.addGeometryLoader(this);\n return true;\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfVertexBufferLoader.prototype.unload = function () {\n if (defined(this._buffer)) {\n this._buffer.destroy();\n }\n\n const resourceCache = this._resourceCache;\n\n if (\n defined(this._bufferViewLoader) &&\n !this._bufferViewLoader.isDestroyed()\n ) {\n resourceCache.unload(this._bufferViewLoader);\n }\n\n if (defined(this._dracoLoader)) {\n resourceCache.unload(this._dracoLoader);\n }\n\n this._bufferViewLoader = undefined;\n this._dracoLoader = undefined;\n this._typedArray = undefined;\n this._buffer = undefined;\n this._gltf = undefined;\n};\n\nexport default GltfVertexBufferLoader;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataClassProperty from \"./MetadataClassProperty.js\";\n\n/**\n * A metadata class.\n *\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the class.\n * @param {string} [options.name] The name of the class.\n * @param {string} [options.description] The description of the class.\n * @param {Object} [options.properties] The class properties, where each key is the property ID.\n * @param {*} [options.extras] Extra user-defined properties.\n * @param {object} [options.extensions] An object containing extensions.\n *\n * @alias MetadataClass\n * @constructor\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataClass(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n //>>includeEnd('debug');\n\n const properties = defaultValue(options.properties, {});\n const propertiesBySemantic = {};\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n if (defined(property.semantic)) {\n propertiesBySemantic[property.semantic] = property;\n }\n }\n }\n\n this._id = id;\n this._name = options.name;\n this._description = options.description;\n this._properties = properties;\n this._propertiesBySemantic = propertiesBySemantic;\n this._extras = clone(options.extras, true);\n this._extensions = clone(options.extensions, true);\n}\n\n/**\n * Creates a {@link MetadataClass} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the class.\n * @param {object} options.class The class JSON object.\n * @param {Object} [options.enums] A dictionary of enums.\n *\n * @returns {MetadataClass} The newly created metadata class.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nMetadataClass.fromJson = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const classDefinition = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n Check.typeOf.object(\"options.class\", classDefinition);\n //>>includeEnd('debug');\n\n const properties = {};\n for (const propertyId in classDefinition.properties) {\n if (classDefinition.properties.hasOwnProperty(propertyId)) {\n const property = MetadataClassProperty.fromJson({\n id: propertyId,\n property: classDefinition.properties[propertyId],\n enums: options.enums,\n });\n properties[propertyId] = property;\n }\n }\n\n return new MetadataClass({\n id: id,\n name: classDefinition.name,\n description: classDefinition.description,\n properties: properties,\n extras: classDefinition.extras,\n extensions: classDefinition.extensions,\n });\n};\n\nObject.defineProperties(MetadataClass.prototype, {\n /**\n * The class properties.\n *\n * @memberof MetadataClass.prototype\n * @type {Object}\n * @readonly\n */\n properties: {\n get: function () {\n return this._properties;\n },\n },\n\n /**\n * A dictionary mapping semantics to class properties.\n *\n * @memberof MetadataClass.prototype\n * @type {Object}\n * @readonly\n *\n * @private\n */\n propertiesBySemantic: {\n get: function () {\n return this._propertiesBySemantic;\n },\n },\n\n /**\n * The ID of the class.\n *\n * @memberof MetadataClass.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * The name of the class.\n *\n * @memberof MetadataClass.prototype\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The description of the class.\n *\n * @memberof MetadataClass.prototype\n * @type {string}\n * @readonly\n */\n description: {\n get: function () {\n return this._description;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataClass.prototype\n * @type {*}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataClass.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * The class name given to the metadata class when a batch\n * table is loaded from 3D Tiles 1.0 formats.\n *\n * @private\n */\nMetadataClass.BATCH_TABLE_CLASS_NAME = \"_batchTable\";\n\nexport default MetadataClass;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * A metadata enum value.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.value The integer value.\n * @param {string} options.name The name of the enum value.\n * @param {string} [options.description] The description of the enum value.\n * @param {*} [options.extras] Extra user-defined properties.\n * @param {object} [options.extensions] An object containing extensions.\n *\n * @alias MetadataEnumValue\n * @constructor\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataEnumValue(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const value = options.value;\n const name = options.name;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.value\", value);\n Check.typeOf.string(\"options.name\", name);\n\n //>>includeEnd('debug');\n\n this._value = value;\n this._name = name;\n this._description = options.description;\n this._extras = clone(options.extras, true);\n this._extensions = clone(options.extensions, true);\n}\n\n/**\n * Creates a {@link MetadataEnumValue} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.\n *\n * @param {object} value The enum value JSON object.\n *\n * @returns {MetadataEnumValue} The newly created metadata enum value.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nMetadataEnumValue.fromJson = function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n return new MetadataEnumValue({\n value: value.value,\n name: value.name,\n description: value.description,\n extras: value.extras,\n extensions: value.extensions,\n });\n};\n\nObject.defineProperties(MetadataEnumValue.prototype, {\n /**\n * The integer value.\n *\n * @memberof MetadataEnumValue.prototype\n * @type {number}\n * @readonly\n */\n value: {\n get: function () {\n return this._value;\n },\n },\n\n /**\n * The name of the enum value.\n *\n * @memberof MetadataEnumValue.prototype\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The description of the enum value.\n *\n * @memberof MetadataEnumValue.prototype\n * @type {string}\n * @readonly\n */\n description: {\n get: function () {\n return this._description;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataEnumValue.prototype\n * @type {*}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataEnumValue.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nexport default MetadataEnumValue;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport MetadataEnumValue from \"./MetadataEnumValue.js\";\nimport MetadataComponentType from \"./MetadataComponentType.js\";\n\n/**\n * A metadata enum.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the enum.\n * @param {MetadataEnumValue[]} options.values The enum values.\n * @param {MetadataComponentType} [options.valueType=MetadataComponentType.UINT16] The enum value type.\n * @param {string} [options.name] The name of the enum.\n * @param {string} [options.description] The description of the enum.\n * @param {*} [options.extras] Extra user-defined properties.\n * @param {object} [options.extensions] An object containing extensions.\n *\n * @alias MetadataEnum\n * @constructor\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataEnum(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const values = options.values;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n Check.defined(\"options.values\", values);\n //>>includeEnd('debug');\n\n const namesByValue = {};\n const valuesByName = {};\n\n const valuesLength = values.length;\n for (let i = 0; i < valuesLength; ++i) {\n const value = values[i];\n namesByValue[value.value] = value.name;\n valuesByName[value.name] = value.value;\n }\n\n const valueType = defaultValue(\n options.valueType,\n MetadataComponentType.UINT16\n );\n\n this._values = values;\n this._namesByValue = namesByValue;\n this._valuesByName = valuesByName;\n this._valueType = valueType;\n this._id = id;\n this._name = options.name;\n this._description = options.description;\n this._extras = clone(options.extras, true);\n this._extensions = clone(options.extensions, true);\n}\n\n/**\n * Creates a {@link MetadataEnum} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the enum.\n * @param {object} options.enum The enum JSON object.\n *\n * @returns {MetadataEnum} The newly created metadata enum.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nMetadataEnum.fromJson = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const enumDefinition = options.enum;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.id\", id);\n Check.typeOf.object(\"options.enum\", enumDefinition);\n //>>includeEnd('debug');\n\n const values = enumDefinition.values.map(function (value) {\n return MetadataEnumValue.fromJson(value);\n });\n\n return new MetadataEnum({\n id: id,\n values: values,\n valueType: MetadataComponentType[enumDefinition.valueType],\n name: enumDefinition.name,\n description: enumDefinition.description,\n extras: enumDefinition.extras,\n extensions: enumDefinition.extensions,\n });\n};\n\nObject.defineProperties(MetadataEnum.prototype, {\n /**\n * The enum values.\n *\n * @memberof MetadataEnum.prototype\n * @type {MetadataEnumValue[]}\n * @readonly\n */\n values: {\n get: function () {\n return this._values;\n },\n },\n\n /**\n * A dictionary mapping enum integer values to names.\n *\n * @memberof MetadataEnum.prototype\n * @type {Object}\n * @readonly\n *\n * @private\n */\n namesByValue: {\n get: function () {\n return this._namesByValue;\n },\n },\n\n /**\n * A dictionary mapping enum names to integer values.\n *\n * @memberof MetadataEnum.prototype\n * @type {Object}\n * @readonly\n *\n * @private\n */\n valuesByName: {\n get: function () {\n return this._valuesByName;\n },\n },\n\n /**\n * The enum value type.\n *\n * @memberof MetadataEnum.prototype\n * @type {MetadataComponentType}\n * @readonly\n */\n valueType: {\n get: function () {\n return this._valueType;\n },\n },\n\n /**\n * The ID of the enum.\n *\n * @memberof MetadataEnum.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * The name of the enum.\n *\n * @memberof MetadataEnum.prototype\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The description of the enum.\n *\n * @memberof MetadataEnum.prototype\n * @type {string}\n * @readonly\n */\n description: {\n get: function () {\n return this._description;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataEnum.prototype\n * @type {*}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataEnum.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nexport default MetadataEnum;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataClass from \"./MetadataClass.js\";\nimport MetadataEnum from \"./MetadataEnum.js\";\n\n/**\n * A schema containing classes and enums.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} [options.id] The ID of the schema\n * @param {string} [options.name] The name of the schema.\n * @param {string} [options.description] The description of the schema.\n * @param {string} [options.version] The application-specific version of the schema.\n * @param {Object} [options.classes] Classes defined in the schema, where each key is the class ID.\n * @param {Object} [options.enums] Enums defined in the schema, where each key is the enum ID.\n * @param {*} [options.extras] Extra user-defined properties.\n * @param {object} [options.extensions] An object containing extensions.\n *\n * @alias MetadataSchema\n * @constructor\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataSchema(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const classes = defaultValue(options.classes, {});\n const enums = defaultValue(options.enums, {});\n\n this._classes = classes;\n this._enums = enums;\n this._id = options.id;\n this._name = options.name;\n this._description = options.description;\n this._version = options.version;\n this._extras = clone(options.extras, true);\n this._extensions = clone(options.extensions, true);\n}\n\n/**\n * Creates a {@link MetadataSchema} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.\n *\n * @param {object} schema The schema JSON object.\n *\n * @returns {MetadataSchema} The newly created metadata schema\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nMetadataSchema.fromJson = function (schema) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"schema\", schema);\n //>>includeEnd('debug');\n\n const enums = {};\n if (defined(schema.enums)) {\n for (const enumId in schema.enums) {\n if (schema.enums.hasOwnProperty(enumId)) {\n enums[enumId] = MetadataEnum.fromJson({\n id: enumId,\n enum: schema.enums[enumId],\n });\n }\n }\n }\n\n const classes = {};\n if (defined(schema.classes)) {\n for (const classId in schema.classes) {\n if (schema.classes.hasOwnProperty(classId)) {\n classes[classId] = MetadataClass.fromJson({\n id: classId,\n class: schema.classes[classId],\n enums: enums,\n });\n }\n }\n }\n\n return new MetadataSchema({\n id: schema.id,\n name: schema.name,\n description: schema.description,\n version: schema.version,\n classes: classes,\n enums: enums,\n extras: schema.extras,\n extensions: schema.extensions,\n });\n};\n\nObject.defineProperties(MetadataSchema.prototype, {\n /**\n * Classes defined in the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {Object}\n * @readonly\n */\n classes: {\n get: function () {\n return this._classes;\n },\n },\n\n /**\n * Enums defined in the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {Object}\n * @readonly\n */\n enums: {\n get: function () {\n return this._enums;\n },\n },\n\n /**\n * The ID of the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * The name of the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The description of the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {string}\n * @readonly\n */\n description: {\n get: function () {\n return this._description;\n },\n },\n\n /**\n * The application-specific version of the schema.\n *\n * @memberof MetadataSchema.prototype\n * @type {string}\n * @readonly\n */\n version: {\n get: function () {\n return this._version;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof MetadataSchema.prototype\n * @type {*}\n * @readonly\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof MetadataSchema.prototype\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nexport default MetadataSchema;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport MetadataSchema from \"./MetadataSchema.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * A {@link MetadataSchema} loader.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias MetadataSchemaLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {object} [options.schema] An object that explicitly defines a schema JSON. Mutually exclusive with options.resource.\n * @param {Resource} [options.resource] The {@link Resource} pointing to the schema JSON. Mutually exclusive with options.schema.\n * @param {string} [options.cacheKey] The cache key of the resource.\n *\n * @exception {DeveloperError} One of options.schema and options.resource must be defined.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction MetadataSchemaLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const schema = options.schema;\n const resource = options.resource;\n const cacheKey = options.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(schema) === defined(resource)) {\n throw new DeveloperError(\n \"One of options.schema and options.resource must be defined.\"\n );\n }\n //>>includeEnd('debug');\n\n this._schema = defined(schema) ? MetadataSchema.fromJson(schema) : undefined;\n this._resource = resource;\n this._cacheKey = cacheKey;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n MetadataSchemaLoader.prototype = Object.create(ResourceLoader.prototype);\n MetadataSchemaLoader.prototype.constructor = MetadataSchemaLoader;\n}\n\nObject.defineProperties(MetadataSchemaLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof MetadataSchemaLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The metadata schema object.\n *\n * @memberof MetadataSchemaLoader.prototype\n *\n * @type {MetadataSchema}\n * @readonly\n * @private\n */\n schema: {\n get: function () {\n return this._schema;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nMetadataSchemaLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n if (defined(this._schema)) {\n this._promise = Promise.resolve(this);\n return this._promise;\n }\n\n this._promise = loadExternalSchema(this);\n return this._promise;\n};\n\nasync function loadExternalSchema(schemaLoader) {\n const resource = schemaLoader._resource;\n schemaLoader._state = ResourceLoaderState.LOADING;\n try {\n const json = await resource.fetchJson();\n if (schemaLoader.isDestroyed()) {\n return;\n }\n\n schemaLoader._schema = MetadataSchema.fromJson(json);\n schemaLoader._state = ResourceLoaderState.READY;\n return schemaLoader;\n } catch (error) {\n if (schemaLoader.isDestroyed()) {\n return;\n }\n\n schemaLoader._state = ResourceLoaderState.FAILED;\n const errorMessage = `Failed to load schema: ${resource.url}`;\n throw schemaLoader.getError(errorMessage, error);\n }\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nMetadataSchemaLoader.prototype.unload = function () {\n this._schema = undefined;\n};\n\nexport default MetadataSchemaLoader;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport getAbsoluteUri from \"../Core/getAbsoluteUri.js\";\nimport GltfLoaderUtil from \"./GltfLoaderUtil.js\";\nimport hasExtension from \"./hasExtension.js\";\n\n/**\n * Compute cache keys for resources in {@link ResourceCache}.\n *\n * @namespace ResourceCacheKey\n *\n * @private\n */\nconst ResourceCacheKey = {};\n\nfunction getExternalResourceCacheKey(resource) {\n return getAbsoluteUri(resource.url);\n}\n\nfunction getBufferViewCacheKey(bufferView) {\n let byteOffset = bufferView.byteOffset;\n let byteLength = bufferView.byteLength;\n\n if (hasExtension(bufferView, \"EXT_meshopt_compression\")) {\n const meshopt = bufferView.extensions.EXT_meshopt_compression;\n byteOffset = defaultValue(meshopt.byteOffset, 0);\n byteLength = meshopt.byteLength;\n }\n\n return `${byteOffset}-${byteOffset + byteLength}`;\n}\n\nfunction getAccessorCacheKey(accessor, bufferView) {\n const byteOffset = bufferView.byteOffset + accessor.byteOffset;\n const componentType = accessor.componentType;\n const type = accessor.type;\n const count = accessor.count;\n return `${byteOffset}-${componentType}-${type}-${count}`;\n}\n\nfunction getExternalBufferCacheKey(resource) {\n return getExternalResourceCacheKey(resource);\n}\n\nfunction getEmbeddedBufferCacheKey(parentResource, bufferId) {\n const parentCacheKey = getExternalResourceCacheKey(parentResource);\n return `${parentCacheKey}-buffer-id-${bufferId}`;\n}\n\nfunction getBufferCacheKey(buffer, bufferId, gltfResource, baseResource) {\n if (defined(buffer.uri)) {\n const resource = baseResource.getDerivedResource({\n url: buffer.uri,\n });\n return getExternalBufferCacheKey(resource);\n }\n\n return getEmbeddedBufferCacheKey(gltfResource, bufferId);\n}\n\nfunction getDracoCacheKey(gltf, draco, gltfResource, baseResource) {\n const bufferViewId = draco.bufferView;\n const bufferView = gltf.bufferViews[bufferViewId];\n const bufferId = bufferView.buffer;\n const buffer = gltf.buffers[bufferId];\n\n const bufferCacheKey = getBufferCacheKey(\n buffer,\n bufferId,\n gltfResource,\n baseResource\n );\n\n const bufferViewCacheKey = getBufferViewCacheKey(bufferView);\n\n return `${bufferCacheKey}-range-${bufferViewCacheKey}`;\n}\n\nfunction getImageCacheKey(gltf, imageId, gltfResource, baseResource) {\n const image = gltf.images[imageId];\n const bufferViewId = image.bufferView;\n const uri = image.uri;\n\n if (defined(uri)) {\n const resource = baseResource.getDerivedResource({\n url: uri,\n });\n return getExternalResourceCacheKey(resource);\n }\n\n const bufferView = gltf.bufferViews[bufferViewId];\n const bufferId = bufferView.buffer;\n const buffer = gltf.buffers[bufferId];\n\n const bufferCacheKey = getBufferCacheKey(\n buffer,\n bufferId,\n gltfResource,\n baseResource\n );\n\n const bufferViewCacheKey = getBufferViewCacheKey(bufferView);\n\n return `${bufferCacheKey}-range-${bufferViewCacheKey}`;\n}\n\nfunction getSamplerCacheKey(gltf, textureInfo) {\n const sampler = GltfLoaderUtil.createSampler({\n gltf: gltf,\n textureInfo: textureInfo,\n });\n\n return `${sampler.wrapS}-${sampler.wrapT}-${sampler.minificationFilter}-${sampler.magnificationFilter}`;\n}\n\n/**\n * Gets the schema cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} [options.schema] An object that explicitly defines a schema JSON. Mutually exclusive with options.resource.\n * @param {Resource} [options.resource] The {@link Resource} pointing to the schema JSON. Mutually exclusive with options.schema.\n *\n * @returns {string} The schema cache key.\n *\n * @exception {DeveloperError} One of options.schema and options.resource must be defined.\n * @private\n */\nResourceCacheKey.getSchemaCacheKey = function (options) {\n const schema = options.schema;\n const resource = options.resource;\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(schema) === defined(resource)) {\n throw new DeveloperError(\n \"One of options.schema and options.resource must be defined.\"\n );\n }\n //>>includeEnd('debug');\n\n if (defined(schema)) {\n return `embedded-schema:${JSON.stringify(schema)}`;\n }\n\n return `external-schema:${getExternalResourceCacheKey(resource)}`;\n};\n\n/**\n * Gets the external buffer cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.resource The {@link Resource} pointing to the external buffer.\n *\n * @returns {string} The external buffer cache key.\n * @private\n */\nResourceCacheKey.getExternalBufferCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resource = options.resource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.resource\", resource);\n //>>includeEnd('debug');\n\n return `external-buffer:${getExternalBufferCacheKey(resource)}`;\n};\n\n/**\n * Gets the embedded buffer cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.parentResource The {@link Resource} containing the embedded buffer.\n * @param {number} options.bufferId A unique identifier of the embedded buffer within the parent resource.\n *\n * @returns {string} The embedded buffer cache key.\n * @private\n */\nResourceCacheKey.getEmbeddedBufferCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const parentResource = options.parentResource;\n const bufferId = options.bufferId;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.parentResource\", parentResource);\n Check.typeOf.number(\"options.bufferId\", bufferId);\n //>>includeEnd('debug');\n\n return `embedded-buffer:${getEmbeddedBufferCacheKey(\n parentResource,\n bufferId\n )}`;\n};\n\n/**\n * Gets the glTF cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n *\n * @returns {string} The glTF cache key.\n * @private\n */\nResourceCacheKey.getGltfCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltfResource = options.gltfResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n //>>includeEnd('debug');\n\n return `gltf:${getExternalResourceCacheKey(gltfResource)}`;\n};\n\n/**\n * Gets the buffer view cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.bufferViewId The bufferView ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {string} The buffer view cache key.\n * @private\n */\nResourceCacheKey.getBufferViewCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const bufferViewId = options.bufferViewId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.bufferViewId\", bufferViewId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const bufferView = gltf.bufferViews[bufferViewId];\n let bufferId = bufferView.buffer;\n const buffer = gltf.buffers[bufferId];\n if (hasExtension(bufferView, \"EXT_meshopt_compression\")) {\n const meshopt = bufferView.extensions.EXT_meshopt_compression;\n bufferId = meshopt.buffer;\n }\n\n const bufferCacheKey = getBufferCacheKey(\n buffer,\n bufferId,\n gltfResource,\n baseResource\n );\n\n const bufferViewCacheKey = getBufferViewCacheKey(bufferView);\n\n return `buffer-view:${bufferCacheKey}-range-${bufferViewCacheKey}`;\n};\n\n/**\n * Gets the Draco cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.draco The Draco extension object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {string} The Draco cache key.\n * @private\n */\nResourceCacheKey.getDracoCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const draco = options.draco;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n return `draco:${getDracoCacheKey(gltf, draco, gltfResource, baseResource)}`;\n};\n\n/**\n * Gets the vertex buffer cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {FrameState} options.frameState The frame state.\n * @param {number} [options.bufferViewId] The bufferView ID corresponding to the vertex buffer.\n * @param {object} [options.draco] The Draco extension object.\n * @param {string} [options.attributeSemantic] The attribute semantic, e.g. POSITION or NORMAL.\n * @param {boolean} [options.dequantize=false] Determines whether or not the vertex buffer will be dequantized on the CPU.\n * @param {boolean} [options.loadBuffer=false] Load vertex buffer as a GPU vertex buffer.\n * @param {boolean} [options.loadTypedArray=false] Load vertex buffer as a typed array.\n * @exception {DeveloperError} One of options.bufferViewId and options.draco must be defined.\n * @exception {DeveloperError} When options.draco is defined options.attributeSemantic must also be defined.\n *\n * @returns {string} The vertex buffer cache key.\n * @private\n */\nResourceCacheKey.getVertexBufferCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const frameState = options.frameState;\n const bufferViewId = options.bufferViewId;\n const draco = options.draco;\n const attributeSemantic = options.attributeSemantic;\n const dequantize = defaultValue(options.dequantize, false);\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.frameState\", frameState);\n\n const hasBufferViewId = defined(bufferViewId);\n const hasDraco = hasDracoCompression(draco, attributeSemantic);\n const hasAttributeSemantic = defined(attributeSemantic);\n\n if (hasBufferViewId === hasDraco) {\n throw new DeveloperError(\n \"One of options.bufferViewId and options.draco must be defined.\"\n );\n }\n\n if (hasDraco && !hasAttributeSemantic) {\n throw new DeveloperError(\n \"When options.draco is defined options.attributeSemantic must also be defined.\"\n );\n }\n\n if (hasDraco) {\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.string(\"options.attributeSemantic\", attributeSemantic);\n }\n\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n //>>includeEnd('debug');\n\n let cacheKeySuffix = \"\";\n if (dequantize) {\n cacheKeySuffix += \"-dequantize\";\n }\n\n if (loadBuffer) {\n cacheKeySuffix += \"-buffer\";\n cacheKeySuffix += `-context-${frameState.context.id}`;\n }\n\n if (loadTypedArray) {\n cacheKeySuffix += \"-typed-array\";\n }\n\n if (defined(draco)) {\n const dracoCacheKey = getDracoCacheKey(\n gltf,\n draco,\n gltfResource,\n baseResource\n );\n return `vertex-buffer:${dracoCacheKey}-draco-${attributeSemantic}${cacheKeySuffix}`;\n }\n\n const bufferView = gltf.bufferViews[bufferViewId];\n const bufferId = bufferView.buffer;\n const buffer = gltf.buffers[bufferId];\n\n const bufferCacheKey = getBufferCacheKey(\n buffer,\n bufferId,\n gltfResource,\n baseResource\n );\n\n const bufferViewCacheKey = getBufferViewCacheKey(bufferView);\n\n return `vertex-buffer:${bufferCacheKey}-range-${bufferViewCacheKey}${cacheKeySuffix}`;\n};\n\nfunction hasDracoCompression(draco, semantic) {\n return (\n defined(draco) &&\n defined(draco.attributes) &&\n defined(draco.attributes[semantic])\n );\n}\n\n/**\n * Gets the index buffer cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.accessorId The accessor ID corresponding to the index buffer.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {FrameState} options.frameState The frame state.\n * @param {object} [options.draco] The Draco extension object.\n * @param {boolean} [options.loadBuffer=false] Load index buffer as a GPU index buffer.\n * @param {boolean} [options.loadTypedArray=false] Load index buffer as a typed array.\n *\n * @returns {string} The index buffer cache key.\n * @private\n */\nResourceCacheKey.getIndexBufferCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const accessorId = options.accessorId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const frameState = options.frameState;\n const draco = options.draco;\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.accessorId\", accessorId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.frameState\", frameState);\n\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n //>>includeEnd('debug');\n\n let cacheKeySuffix = \"\";\n if (loadBuffer) {\n cacheKeySuffix += \"-buffer\";\n cacheKeySuffix += `-context-${frameState.context.id}`;\n }\n\n if (loadTypedArray) {\n cacheKeySuffix += \"-typed-array\";\n }\n\n if (defined(draco)) {\n const dracoCacheKey = getDracoCacheKey(\n gltf,\n draco,\n gltfResource,\n baseResource\n );\n return `index-buffer:${dracoCacheKey}-draco${cacheKeySuffix}`;\n }\n\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n const bufferView = gltf.bufferViews[bufferViewId];\n const bufferId = bufferView.buffer;\n const buffer = gltf.buffers[bufferId];\n\n const bufferCacheKey = getBufferCacheKey(\n buffer,\n bufferId,\n gltfResource,\n baseResource\n );\n\n const accessorCacheKey = getAccessorCacheKey(accessor, bufferView);\n\n return `index-buffer:${bufferCacheKey}-accessor-${accessorCacheKey}${cacheKeySuffix}`;\n};\n\n/**\n * Gets the image cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.imageId The image ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {string} The image cache key.\n * @private\n */\nResourceCacheKey.getImageCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const imageId = options.imageId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.imageId\", imageId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const imageCacheKey = getImageCacheKey(\n gltf,\n imageId,\n gltfResource,\n baseResource\n );\n\n return `image:${imageCacheKey}`;\n};\n\n/**\n * Gets the texture cache key.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.textureInfo The texture info object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.\n * @param {FrameState} options.frameState The frame state.\n *\n * @returns {string} The texture cache key.\n * @private\n */\nResourceCacheKey.getTextureCacheKey = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const textureInfo = options.textureInfo;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const supportedImageFormats = options.supportedImageFormats;\n const frameState = options.frameState;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.textureInfo\", textureInfo);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.supportedImageFormats\", supportedImageFormats);\n Check.typeOf.object(\"options.frameState\", frameState);\n //>>includeEnd('debug');\n\n const textureId = textureInfo.index;\n\n const imageId = GltfLoaderUtil.getImageIdFromTexture({\n gltf: gltf,\n textureId: textureId,\n supportedImageFormats: supportedImageFormats,\n });\n\n const imageCacheKey = getImageCacheKey(\n gltf,\n imageId,\n gltfResource,\n baseResource\n );\n\n // Include the sampler cache key in the texture cache key since textures and\n // samplers are coupled in WebGL 1. When upgrading to WebGL 2 consider\n // removing the sampleCacheKey here.\n const samplerCacheKey = getSamplerCacheKey(gltf, textureInfo);\n\n return `texture:${imageCacheKey}-sampler-${samplerCacheKey}-context-${frameState.context.id}`;\n};\n\nexport default ResourceCacheKey;\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * Statistics for the GPU and CPU memory used by the models loaded through the\n * {@link ResourceCache}.\n *\n * @alias ResourceCacheStatistics\n * @constructor\n *\n * @private\n */\nfunction ResourceCacheStatistics() {\n /**\n * The size of vertex buffers and index buffers loaded in the cache in bytes.\n *\n * @type {number}\n * @private\n */\n this.geometryByteLength = 0;\n\n /**\n * The size of all textures loaded in the cache in bytes\n *\n * @type {number}\n * @private\n */\n this.texturesByteLength = 0;\n\n // Track the sizes of resources by cache key. This is important so\n // removeLoader() can decrement the counts correctly.\n this._geometrySizes = {};\n this._textureSizes = {};\n}\n\n/**\n * Reset the memory counts\n *\n * @private\n */\nResourceCacheStatistics.prototype.clear = function () {\n this.geometryByteLength = 0;\n this.texturesByteLength = 0;\n\n this._geometrySizes = {};\n this._textureSizes = {};\n};\n\n/**\n * Track the resources for a vertex or index buffer loader. This should be called after a loader is ready; that\n * is it has been loaded and processed.\n * This method handles the following cases gracefully:\n *
    \n *
  • If the loader is added twice, its resources will not be double-counted
  • \n *
  • If the geometry has a CPU copy of the GPU buffer, it will be added to the count
  • \n *
\n * @param {GltfVertexBufferLoader|GltfIndexBufferLoader} loader The geometry buffer with resources to track\n *\n * @private\n */\nResourceCacheStatistics.prototype.addGeometryLoader = function (loader) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"loader\", loader);\n //>>includeEnd('debug');\n\n const cacheKey = loader.cacheKey;\n\n // Don't double count the same resource.\n if (this._geometrySizes.hasOwnProperty(cacheKey)) {\n return;\n }\n\n this._geometrySizes[cacheKey] = 0;\n\n const buffer = loader.buffer;\n const typedArray = loader.typedArray;\n\n let totalSize = 0;\n\n if (defined(buffer)) {\n totalSize += buffer.sizeInBytes;\n }\n\n if (defined(typedArray)) {\n totalSize += typedArray.byteLength;\n }\n\n this.geometryByteLength += totalSize;\n this._geometrySizes[cacheKey] = totalSize;\n};\n\n/**\n * Track the resources for a texture loader. This should be called after a loader is ready; that\n * is it has been loaded and processed.\n * If the loader is added twice, its resources will not be double-counted.\n *\n * @param {GltfTextureLoader} loader The texture loader with resources to track\n *\n * @private\n */\nResourceCacheStatistics.prototype.addTextureLoader = function (loader) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"loader\", loader);\n //>>includeEnd('debug');\n\n const cacheKey = loader.cacheKey;\n\n // Don't double count the same resource.\n if (this._textureSizes.hasOwnProperty(cacheKey)) {\n return;\n }\n\n this._textureSizes[cacheKey] = 0;\n const totalSize = loader.texture.sizeInBytes;\n this.texturesByteLength += loader.texture.sizeInBytes;\n this._textureSizes[cacheKey] = totalSize;\n};\n\n/**\n * Remove a loader's resources from the memory count. The loader's cache key\n * is used to determine information about the resource, so this method can\n * be used both for geometry and textures. If the loader does not have any\n * tracked resources, this is a no-op.\n * @param {ResourceLoader} loader The resource loader to remove from the cache\n *\n * @private\n */\nResourceCacheStatistics.prototype.removeLoader = function (loader) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"loader\", loader);\n //>>includeEnd('debug');\n\n const cacheKey = loader.cacheKey;\n const geometrySize = this._geometrySizes[cacheKey];\n delete this._geometrySizes[cacheKey];\n\n if (defined(geometrySize)) {\n this.geometryByteLength -= geometrySize;\n }\n\n const textureSize = this._textureSizes[cacheKey];\n delete this._textureSizes[cacheKey];\n\n if (defined(textureSize)) {\n this.texturesByteLength -= textureSize;\n }\n};\n\nexport default ResourceCacheStatistics;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport BufferLoader from \"./BufferLoader.js\";\nimport GltfBufferViewLoader from \"./GltfBufferViewLoader.js\";\nimport GltfDracoLoader from \"./GltfDracoLoader.js\";\nimport GltfImageLoader from \"./GltfImageLoader.js\";\nimport GltfIndexBufferLoader from \"./GltfIndexBufferLoader.js\";\nimport GltfJsonLoader from \"./GltfJsonLoader.js\";\nimport GltfTextureLoader from \"./GltfTextureLoader.js\";\nimport GltfVertexBufferLoader from \"./GltfVertexBufferLoader.js\";\nimport MetadataSchemaLoader from \"./MetadataSchemaLoader.js\";\nimport ResourceCacheKey from \"./ResourceCacheKey.js\";\nimport ResourceCacheStatistics from \"./ResourceCacheStatistics.js\";\n\n/**\n * Cache for resources shared across 3D Tiles and glTF.\n *\n * @namespace ResourceCache\n *\n * @private\n */\nfunction ResourceCache() {}\n\nResourceCache.cacheEntries = {};\n\n// Statistics about binary data stored in the resource cache\nResourceCache.statistics = new ResourceCacheStatistics();\n\n/**\n * A reference-counted cache entry.\n *\n * @param {ResourceLoader} resourceLoader The resource.\n *\n * @alias CacheEntry\n * @constructor\n *\n * @private\n */\nfunction CacheEntry(resourceLoader) {\n this.referenceCount = 1;\n this.resourceLoader = resourceLoader;\n\n // For unit testing only\n this._statisticsPromise = undefined;\n}\n\n/**\n * Gets a resource from the cache. If the resource exists its reference count is\n * incremented. Otherwise, if no resource loader exists, undefined is returned.\n *\n * @param {string} cacheKey The cache key of the resource.\n *\n * @returns {ResourceLoader|undefined} The resource.\n * @private\n */\nResourceCache.get = function (cacheKey) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"cacheKey\", cacheKey);\n //>>includeEnd('debug');\n\n const cacheEntry = ResourceCache.cacheEntries[cacheKey];\n if (defined(cacheEntry)) {\n ++cacheEntry.referenceCount;\n return cacheEntry.resourceLoader;\n }\n return undefined;\n};\n\n/**\n * Adds it to the cache.\n *\n * @param {ResourceLoader} resourceLoader The resource.\n * @returns {ResourceLoader} The resource.\n *\n * @exception {DeveloperError} Resource with this cacheKey is already in the cache\n * @private\n */\nResourceCache.add = function (resourceLoader) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"resourceLoader\", resourceLoader);\n //>>includeEnd('debug');\n\n const cacheKey = resourceLoader.cacheKey;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.resourceLoader.cacheKey\", cacheKey);\n\n if (defined(ResourceCache.cacheEntries[cacheKey])) {\n throw new DeveloperError(\n `Resource with this cacheKey is already in the cache: ${cacheKey}`\n );\n }\n //>>includeEnd('debug');\n\n ResourceCache.cacheEntries[cacheKey] = new CacheEntry(resourceLoader);\n\n return resourceLoader;\n};\n\n/**\n * Unloads a resource from the cache. When the reference count hits zero the\n * resource is destroyed.\n *\n * @param {ResourceLoader} resourceLoader The resource.\n *\n * @exception {DeveloperError} Resource is not in the cache.\n * @exception {DeveloperError} Cannot unload resource that has no references.\n * @private\n */\nResourceCache.unload = function (resourceLoader) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"resourceLoader\", resourceLoader);\n //>>includeEnd('debug');\n\n const cacheKey = resourceLoader.cacheKey;\n const cacheEntry = ResourceCache.cacheEntries[cacheKey];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(cacheEntry)) {\n throw new DeveloperError(`Resource is not in the cache: ${cacheKey}`);\n }\n //>>includeEnd('debug');\n\n --cacheEntry.referenceCount;\n\n if (cacheEntry.referenceCount === 0) {\n ResourceCache.statistics.removeLoader(resourceLoader);\n resourceLoader.destroy();\n delete ResourceCache.cacheEntries[cacheKey];\n }\n};\n\n/**\n * Gets an existing schema loader from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} [options.schema] An object that explicitly defines a schema JSON. Mutually exclusive with options.resource.\n * @param {Resource} [options.resource] The {@link Resource} pointing to the schema JSON. Mutually exclusive with options.schema.\n *\n * @returns {MetadataSchemaLoader} The cached schema resource.\n *\n * @exception {DeveloperError} One of options.schema and options.resource must be defined.\n * @private\n */\nResourceCache.getSchemaLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const schema = options.schema;\n const resource = options.resource;\n\n //>>includeStart('debug', pragmas.debug);\n if (defined(schema) === defined(resource)) {\n throw new DeveloperError(\n \"One of options.schema and options.resource must be defined.\"\n );\n }\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getSchemaCacheKey({\n schema: schema,\n resource: resource,\n });\n\n let schemaLoader = ResourceCache.get(cacheKey);\n if (defined(schemaLoader)) {\n return schemaLoader;\n }\n\n schemaLoader = new MetadataSchemaLoader({\n schema: schema,\n resource: resource,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(schemaLoader);\n};\n\n/**\n * Gets an existing embedded buffer loader from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.parentResource The {@link Resource} containing the embedded buffer.\n * @param {number} options.bufferId A unique identifier of the embedded buffer within the parent resource.\n * @param {Uint8Array} [options.typedArray] The typed array containing the embedded buffer contents.\n *\n * @returns {BufferLoader} The cached buffer loader.\n * @private\n */\nResourceCache.getEmbeddedBufferLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const parentResource = options.parentResource;\n const bufferId = options.bufferId;\n const typedArray = options.typedArray;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.parentResource\", parentResource);\n Check.typeOf.number(\"options.bufferId\", bufferId);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getEmbeddedBufferCacheKey({\n parentResource: parentResource,\n bufferId: bufferId,\n });\n\n let bufferLoader = ResourceCache.get(cacheKey);\n if (defined(bufferLoader)) {\n return bufferLoader;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.typedArray\", typedArray);\n //>>includeEnd('debug');\n\n bufferLoader = new BufferLoader({\n typedArray: typedArray,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(bufferLoader);\n};\n\n/**\n * Gets an existing external buffer from loader the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.resource The {@link Resource} pointing to the external buffer.\n *\n * @returns {BufferLoader} The cached buffer loader.\n * @private\n */\nResourceCache.getExternalBufferLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const resource = options.resource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.resource\", resource);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getExternalBufferCacheKey({\n resource: resource,\n });\n\n let bufferLoader = ResourceCache.get(cacheKey);\n if (defined(bufferLoader)) {\n return bufferLoader;\n }\n\n bufferLoader = new BufferLoader({\n resource: resource,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(bufferLoader);\n};\n\n/**\n * Gets an existing glTF JSON loader from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {Uint8Array} [options.typedArray] The typed array containing the glTF contents.\n * @param {object} [options.gltfJson] The parsed glTF JSON contents.\n *\n * @returns {GltfJsonLoader} The cached glTF JSON loader.\n * @private\n */\nResourceCache.getGltfJsonLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const typedArray = options.typedArray;\n const gltfJson = options.gltfJson;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getGltfCacheKey({\n gltfResource: gltfResource,\n });\n\n let gltfJsonLoader = ResourceCache.get(cacheKey);\n if (defined(gltfJsonLoader)) {\n return gltfJsonLoader;\n }\n\n gltfJsonLoader = new GltfJsonLoader({\n resourceCache: ResourceCache,\n gltfResource: gltfResource,\n baseResource: baseResource,\n typedArray: typedArray,\n gltfJson: gltfJson,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(gltfJsonLoader);\n};\n\n/**\n * Gets an existing glTF buffer view from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.bufferViewId The bufferView ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {GltfBufferViewLoader} The cached buffer view loader.\n * @private\n */\nResourceCache.getBufferViewLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const bufferViewId = options.bufferViewId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.bufferViewId\", bufferViewId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getBufferViewCacheKey({\n gltf: gltf,\n bufferViewId: bufferViewId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n });\n\n let bufferViewLoader = ResourceCache.get(cacheKey);\n if (defined(bufferViewLoader)) {\n return bufferViewLoader;\n }\n\n bufferViewLoader = new GltfBufferViewLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n bufferViewId: bufferViewId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(bufferViewLoader);\n};\n\n/**\n * Gets an existing Draco data from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.draco The Draco extension object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {GltfDracoLoader} The cached Draco loader.\n * @private\n */\nResourceCache.getDracoLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const draco = options.draco;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getDracoCacheKey({\n gltf: gltf,\n draco: draco,\n gltfResource: gltfResource,\n baseResource: baseResource,\n });\n\n let dracoLoader = ResourceCache.get(cacheKey);\n if (defined(dracoLoader)) {\n return dracoLoader;\n }\n\n dracoLoader = new GltfDracoLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n draco: draco,\n gltfResource: gltfResource,\n baseResource: baseResource,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(dracoLoader);\n};\n\n/**\n * Gets an existing glTF vertex buffer from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {FrameState} options.frameState The frame state.\n * @param {number} [options.bufferViewId] The bufferView ID corresponding to the vertex buffer.\n * @param {object} [options.draco] The Draco extension object.\n * @param {string} [options.attributeSemantic] The attribute semantic, e.g. POSITION or NORMAL.\n * @param {number} [options.accessorId] The accessor ID.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.dequantize=false] Determines whether or not the vertex buffer will be dequantized on the CPU.\n * @param {boolean} [options.loadBuffer=false] Load vertex buffer as a GPU vertex buffer.\n * @param {boolean} [options.loadTypedArray=false] Load vertex buffer as a typed array.\n * @exception {DeveloperError} One of options.bufferViewId and options.draco must be defined.\n * @exception {DeveloperError} When options.draco is defined options.attributeSemantic must also be defined.\n * @exception {DeveloperError} When options.draco is defined options.accessorId must also be defined.\n *\n * @returns {GltfVertexBufferLoader} The cached vertex buffer loader.\n * @private\n */\nResourceCache.getVertexBufferLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const frameState = options.frameState;\n const bufferViewId = options.bufferViewId;\n const draco = options.draco;\n const attributeSemantic = options.attributeSemantic;\n const accessorId = options.accessorId;\n const asynchronous = defaultValue(options.asynchronous, true);\n const dequantize = defaultValue(options.dequantize, false);\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.frameState\", frameState);\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n\n const hasBufferViewId = defined(bufferViewId);\n const hasDraco = hasDracoCompression(draco, attributeSemantic);\n const hasAttributeSemantic = defined(attributeSemantic);\n const hasAccessorId = defined(accessorId);\n\n if (hasBufferViewId === hasDraco) {\n throw new DeveloperError(\n \"One of options.bufferViewId and options.draco must be defined.\"\n );\n }\n\n if (hasDraco && !hasAttributeSemantic) {\n throw new DeveloperError(\n \"When options.draco is defined options.attributeSemantic must also be defined.\"\n );\n }\n\n if (hasDraco && !hasAccessorId) {\n throw new DeveloperError(\n \"When options.draco is defined options.haAccessorId must also be defined.\"\n );\n }\n\n if (hasDraco) {\n Check.typeOf.object(\"options.draco\", draco);\n Check.typeOf.string(\"options.attributeSemantic\", attributeSemantic);\n Check.typeOf.number(\"options.accessorId\", accessorId);\n }\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getVertexBufferCacheKey({\n gltf: gltf,\n gltfResource: gltfResource,\n baseResource: baseResource,\n frameState: frameState,\n bufferViewId: bufferViewId,\n draco: draco,\n attributeSemantic: attributeSemantic,\n dequantize: dequantize,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n let vertexBufferLoader = ResourceCache.get(cacheKey);\n if (defined(vertexBufferLoader)) {\n return vertexBufferLoader;\n }\n\n vertexBufferLoader = new GltfVertexBufferLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n gltfResource: gltfResource,\n baseResource: baseResource,\n bufferViewId: bufferViewId,\n draco: draco,\n attributeSemantic: attributeSemantic,\n accessorId: accessorId,\n cacheKey: cacheKey,\n asynchronous: asynchronous,\n dequantize: dequantize,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n return ResourceCache.add(vertexBufferLoader);\n};\n\nfunction hasDracoCompression(draco, semantic) {\n return (\n defined(draco) &&\n defined(draco.attributes) &&\n defined(draco.attributes[semantic])\n );\n}\n\n/**\n * Gets an existing glTF index buffer from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.accessorId The accessor ID corresponding to the index buffer.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {FrameState} options.frameState The frame state.\n * @param {object} [options.draco] The Draco extension object.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.loadBuffer=false] Load index buffer as a GPU index buffer.\n * @param {boolean} [options.loadTypedArray=false] Load index buffer as a typed array.\n * @returns {GltfIndexBufferLoader} The cached index buffer loader.\n * @private\n */\nResourceCache.getIndexBufferLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const accessorId = options.accessorId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const frameState = options.frameState;\n const draco = options.draco;\n const asynchronous = defaultValue(options.asynchronous, true);\n const loadBuffer = defaultValue(options.loadBuffer, false);\n const loadTypedArray = defaultValue(options.loadTypedArray, false);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.accessorId\", accessorId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.frameState\", frameState);\n if (!loadBuffer && !loadTypedArray) {\n throw new DeveloperError(\n \"At least one of loadBuffer and loadTypedArray must be true.\"\n );\n }\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getIndexBufferCacheKey({\n gltf: gltf,\n accessorId: accessorId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n frameState: frameState,\n draco: draco,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n let indexBufferLoader = ResourceCache.get(cacheKey);\n if (defined(indexBufferLoader)) {\n return indexBufferLoader;\n }\n\n indexBufferLoader = new GltfIndexBufferLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n accessorId: accessorId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n draco: draco,\n cacheKey: cacheKey,\n asynchronous: asynchronous,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n return ResourceCache.add(indexBufferLoader);\n};\n\n/**\n * Gets an existing glTF image from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {number} options.imageId The image ID.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n *\n * @returns {GltfImageLoader} The cached image loader.\n * @private\n */\nResourceCache.getImageLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const imageId = options.imageId;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.number(\"options.imageId\", imageId);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getImageCacheKey({\n gltf: gltf,\n imageId: imageId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n });\n\n let imageLoader = ResourceCache.get(cacheKey);\n if (defined(imageLoader)) {\n return imageLoader;\n }\n\n imageLoader = new GltfImageLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n imageId: imageId,\n gltfResource: gltfResource,\n baseResource: baseResource,\n cacheKey: cacheKey,\n });\n\n return ResourceCache.add(imageLoader);\n};\n\n/**\n * Gets an existing glTF texture from the cache, or creates a new loader if one does not already exist.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {object} options.textureInfo The texture info object.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.\n * @param {FrameState} options.frameState The frame state.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n *\n * @returns {GltfTextureLoader} The cached texture loader.\n * @private\n */\nResourceCache.getTextureLoader = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const textureInfo = options.textureInfo;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const supportedImageFormats = options.supportedImageFormats;\n const frameState = options.frameState;\n const asynchronous = defaultValue(options.asynchronous, true);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.textureInfo\", textureInfo);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.supportedImageFormats\", supportedImageFormats);\n Check.typeOf.object(\"options.frameState\", frameState);\n //>>includeEnd('debug');\n\n const cacheKey = ResourceCacheKey.getTextureCacheKey({\n gltf: gltf,\n textureInfo: textureInfo,\n gltfResource: gltfResource,\n baseResource: baseResource,\n supportedImageFormats: supportedImageFormats,\n frameState: frameState,\n });\n\n let textureLoader = ResourceCache.get(cacheKey);\n if (defined(textureLoader)) {\n return textureLoader;\n }\n\n textureLoader = new GltfTextureLoader({\n resourceCache: ResourceCache,\n gltf: gltf,\n textureInfo: textureInfo,\n gltfResource: gltfResource,\n baseResource: baseResource,\n supportedImageFormats: supportedImageFormats,\n cacheKey: cacheKey,\n asynchronous: asynchronous,\n });\n\n return ResourceCache.add(textureLoader);\n};\n\n/**\n * Unload everything from the cache. This is used for unit testing.\n *\n * @private\n */\nResourceCache.clearForSpecs = function () {\n // Unload in the order below. This prevents an unload function from unloading\n // a resource that has already been unloaded.\n const precedence = [\n GltfVertexBufferLoader,\n GltfIndexBufferLoader,\n GltfDracoLoader,\n GltfTextureLoader,\n GltfImageLoader,\n GltfBufferViewLoader,\n BufferLoader,\n MetadataSchemaLoader,\n GltfJsonLoader,\n ];\n\n let cacheKey;\n const cacheEntries = ResourceCache.cacheEntries;\n\n const cacheEntriesSorted = [];\n for (cacheKey in cacheEntries) {\n if (cacheEntries.hasOwnProperty(cacheKey)) {\n cacheEntriesSorted.push(cacheEntries[cacheKey]);\n }\n }\n\n cacheEntriesSorted.sort(function (a, b) {\n const indexA = precedence.indexOf(a.resourceLoader.constructor);\n const indexB = precedence.indexOf(b.resourceLoader.constructor);\n return indexA - indexB;\n });\n\n const cacheEntriesLength = cacheEntriesSorted.length;\n for (let i = 0; i < cacheEntriesLength; ++i) {\n const cacheEntry = cacheEntriesSorted[i];\n cacheKey = cacheEntry.resourceLoader.cacheKey;\n if (defined(cacheEntries[cacheKey])) {\n cacheEntry.resourceLoader.destroy();\n delete cacheEntries[cacheKey];\n }\n }\n\n ResourceCache.statistics.clear();\n};\n\nexport default ResourceCache;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport ImplicitAvailabilityBitstream from \"./ImplicitAvailabilityBitstream.js\";\nimport ImplicitMetadataView from \"./ImplicitMetadataView.js\";\nimport ImplicitSubdivisionScheme from \"./ImplicitSubdivisionScheme.js\";\nimport ImplicitSubtreeMetadata from \"./ImplicitSubtreeMetadata.js\";\nimport MetadataTable from \"./MetadataTable.js\";\nimport ResourceCache from \"./ResourceCache.js\";\n\n/**\n * An object representing a single subtree in an implicit tileset\n * including availability.\n *

\n * Subtrees handle tile metadata, defined in the subtree JSON in either\n * tileMetadata (3D Tiles 1.1) or the 3DTILES_metadata extension.\n * Subtrees also handle content metadata and metadata about the subtree itself.\n *

\n *\n * This object is normally not instantiated directly, use {@link ImplicitSubtree.fromSubtreeJson}.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata#implicit-tile-properties|Implicit Tile Properties in the 3DTILES_metadata specification}\n * @see ImplicitSubtree.fromSubtreeJson\n *\n * @alias ImplicitSubtree\n * @constructor\n *\n * @param {Resource} resource The resource for this subtree. This is used for fetching external buffers as needed.\n * @param {ImplicitTileset} implicitTileset The implicit tileset. This includes information about the size of subtrees\n * @param {ImplicitTileCoordinates} implicitCoordinates The coordinates of the subtree's root tile.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitSubtree(resource, implicitTileset, implicitCoordinates) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"resource\", resource);\n Check.typeOf.object(\"implicitTileset\", implicitTileset);\n Check.typeOf.object(\"implicitCoordinates\", implicitCoordinates);\n //>>includeEnd('debug');\n\n this._resource = resource;\n this._subtreeJson = undefined;\n this._bufferLoader = undefined;\n this._tileAvailability = undefined;\n this._contentAvailabilityBitstreams = [];\n this._childSubtreeAvailability = undefined;\n this._implicitCoordinates = implicitCoordinates;\n this._subtreeLevels = implicitTileset.subtreeLevels;\n this._subdivisionScheme = implicitTileset.subdivisionScheme;\n this._branchingFactor = implicitTileset.branchingFactor;\n\n // properties for metadata\n this._metadata = undefined;\n this._tileMetadataTable = undefined;\n this._tilePropertyTableJson = undefined;\n\n this._contentMetadataTables = [];\n this._contentPropertyTableJsons = [];\n\n // Jump buffers are maps of availability bit index to entity ID\n this._tileJumpBuffer = undefined;\n this._contentJumpBuffers = [];\n\n this._ready = false;\n}\n\nObject.defineProperties(ImplicitSubtree.prototype, {\n /**\n * Returns true once all necessary availability buffers\n * are loaded.\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n /**\n * When subtree metadata is present (3D Tiles 1.1), this property stores an {@link ImplicitSubtreeMetadata} instance\n *\n * @type {ImplicitSubtreeMetadata}\n * @readonly\n * @private\n */\n metadata: {\n get: function () {\n return this._metadata;\n },\n },\n\n /**\n * When tile metadata is present (3D Tiles 1.1) or the 3DTILES_metadata extension is used,\n * this property stores a {@link MetadataTable} instance for the tiles in the subtree.\n *\n * @type {MetadataTable}\n * @readonly\n * @private\n */\n tileMetadataTable: {\n get: function () {\n return this._tileMetadataTable;\n },\n },\n\n /**\n * When tile metadata is present (3D Tiles 1.1) or the 3DTILES_metadata extension is used,\n * this property stores the JSON from the extension. This is used by {@link TileMetadata}\n * to get the extras and extensions for the tiles in the subtree.\n *\n * @type {object}\n * @readonly\n * @private\n */\n tilePropertyTableJson: {\n get: function () {\n return this._tilePropertyTableJson;\n },\n },\n\n /**\n * When content metadata is present (3D Tiles 1.1), this property stores\n * an array of {@link MetadataTable} instances for the contents in the subtree.\n *\n * @type {Array}\n * @readonly\n * @private\n */\n contentMetadataTables: {\n get: function () {\n return this._contentMetadataTables;\n },\n },\n\n /**\n * When content metadata is present (3D Tiles 1.1), this property\n * an array of the JSONs from the extension. This is used to get the extras\n * and extensions for the contents in the subtree.\n *\n * @type {Array}\n * @readonly\n * @private\n */\n contentPropertyTableJsons: {\n get: function () {\n return this._contentPropertyTableJsons;\n },\n },\n\n /**\n * Gets the implicit tile coordinates for the root of the subtree.\n *\n * @type {ImplicitTileCoordinates}\n * @readonly\n * @private\n */\n implicitCoordinates: {\n get: function () {\n return this._implicitCoordinates;\n },\n },\n});\n\n/**\n * Check if a specific tile is available at an index of the tile availability bitstream\n *\n * @param {number} index The index of the desired tile\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.tileIsAvailableAtIndex = function (index) {\n return this._tileAvailability.getBit(index);\n};\n\n/**\n * Check if a specific tile is available at an implicit tile coordinate\n *\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a tile\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.tileIsAvailableAtCoordinates = function (\n implicitCoordinates\n) {\n const index = this.getTileIndex(implicitCoordinates);\n return this.tileIsAvailableAtIndex(index);\n};\n\n/**\n * Check if a specific tile's content is available at an index of the content availability bitstream\n *\n * @param {number} index The index of the desired tile\n * @param {number} [contentIndex=0] The index of the desired content when multiple contents are used.\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.contentIsAvailableAtIndex = function (\n index,\n contentIndex\n) {\n contentIndex = defaultValue(contentIndex, 0);\n //>>includeStart('debug', pragmas.debug);\n if (\n contentIndex < 0 ||\n contentIndex >= this._contentAvailabilityBitstreams.length\n ) {\n throw new DeveloperError(\"contentIndex out of bounds.\");\n }\n //>>includeEnd('debug');\n\n return this._contentAvailabilityBitstreams[contentIndex].getBit(index);\n};\n\n/**\n * Check if a specific tile's content is available at an implicit tile coordinate\n *\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a tile\n * @param {number} [contentIndex=0] The index of the desired content when the 3DTILES_multiple_contents extension is used.\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.contentIsAvailableAtCoordinates = function (\n implicitCoordinates,\n contentIndex\n) {\n const index = this.getTileIndex(implicitCoordinates);\n return this.contentIsAvailableAtIndex(index, contentIndex);\n};\n\n/**\n * Check if a child subtree is available at an index of the child subtree availability bitstream\n *\n * @param {number} index The index of the desired child subtree\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.childSubtreeIsAvailableAtIndex = function (index) {\n return this._childSubtreeAvailability.getBit(index);\n};\n\n/**\n * Check if a specific child subtree is available at an implicit tile coordinate\n *\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a child subtree\n * @returns {boolean} The value of the i-th bit\n * @private\n */\nImplicitSubtree.prototype.childSubtreeIsAvailableAtCoordinates = function (\n implicitCoordinates\n) {\n const index = this.getChildSubtreeIndex(implicitCoordinates);\n return this.childSubtreeIsAvailableAtIndex(index);\n};\n\n/**\n * Get the index of the first node at the given level within this subtree.\n * e.g. for a quadtree:\n *
    \n *
  • Level 0 starts at index 0
  • \n *
  • Level 1 starts at index 1
  • \n *
  • Level 2 starts at index 5
  • \n *
\n *\n * @param {number} level The 0-indexed level number relative to the root of the subtree\n * @returns {number} The first index at the desired level\n * @private\n */\nImplicitSubtree.prototype.getLevelOffset = function (level) {\n const branchingFactor = this._branchingFactor;\n return (Math.pow(branchingFactor, level) - 1) / (branchingFactor - 1);\n};\n\n/**\n * Get the morton index of a tile's parent. This is equivalent to\n * chopping off the last 2 (quadtree) or 3 (octree) bits of the morton\n * index.\n *\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @returns {number} The index of the child's parent node\n * @private\n */\nImplicitSubtree.prototype.getParentMortonIndex = function (mortonIndex) {\n let bitsPerLevel = 2;\n if (this._subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n bitsPerLevel = 3;\n }\n\n return mortonIndex >> bitsPerLevel;\n};\n\n/**\n * Parse all relevant information out of the subtree. This fetches any\n * external buffers that are used by the implicit tileset.\n *\n * @param {Resource} resource The resource for this subtree. This is used for fetching external buffers as needed.\n * @param {object} [json] The JSON object for this subtree. If parsing from a binary subtree file, this will be undefined.\n * @param {Uint8Array} [subtreeView] The contents of the subtree binary\n * @param {ImplicitTileset} implicitTileset The implicit tileset this subtree belongs to.\n * @param {ImplicitTileCoordinates} implicitCoordinates The coordinates of the subtree's root tile.\n * @return {Promise} The created subtree\n * @private\n *\n * @exception {DeveloperError} One of json and subtreeView must be defined.\n */\nImplicitSubtree.fromSubtreeJson = async function (\n resource,\n json,\n subtreeView,\n implicitTileset,\n implicitCoordinates\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"resource\", resource);\n if (defined(json) === defined(subtreeView)) {\n throw new DeveloperError(\"One of json and subtreeView must be defined.\");\n }\n Check.typeOf.object(\"implicitTileset\", implicitTileset);\n Check.typeOf.object(\"implicitCoordinates\", implicitCoordinates);\n //>>includeEnd('debug');\n\n const subtree = new ImplicitSubtree(\n resource,\n implicitTileset,\n implicitCoordinates\n );\n\n let chunks;\n if (defined(json)) {\n chunks = {\n json: json,\n binary: undefined,\n };\n } else {\n chunks = parseSubtreeChunks(subtreeView);\n }\n\n const subtreeJson = chunks.json;\n subtree._subtreeJson = subtreeJson;\n\n let tilePropertyTableJson;\n if (hasExtension(subtreeJson, \"3DTILES_metadata\")) {\n tilePropertyTableJson = subtreeJson.extensions[\"3DTILES_metadata\"];\n } else if (defined(subtreeJson.tileMetadata)) {\n const propertyTableIndex = subtreeJson.tileMetadata;\n tilePropertyTableJson = subtreeJson.propertyTables[propertyTableIndex];\n }\n\n const contentPropertyTableJsons = [];\n if (defined(subtreeJson.contentMetadata)) {\n const length = subtreeJson.contentMetadata.length;\n for (let i = 0; i < length; i++) {\n const propertyTableIndex = subtreeJson.contentMetadata[i];\n contentPropertyTableJsons.push(\n subtreeJson.propertyTables[propertyTableIndex]\n );\n }\n }\n\n let metadata;\n const schema = implicitTileset.metadataSchema;\n const subtreeMetadata = subtreeJson.subtreeMetadata;\n if (defined(subtreeMetadata)) {\n const metadataClass = subtreeMetadata.class;\n const subtreeMetadataClass = schema.classes[metadataClass];\n metadata = new ImplicitSubtreeMetadata({\n subtreeMetadata: subtreeMetadata,\n class: subtreeMetadataClass,\n });\n }\n\n subtree._metadata = metadata;\n subtree._tilePropertyTableJson = tilePropertyTableJson;\n subtree._contentPropertyTableJsons = contentPropertyTableJsons;\n\n // if no contentAvailability is specified, no tile in the subtree has\n // content\n const defaultContentAvailability = {\n constant: 0,\n };\n\n // In 3D Tiles 1.1, content availability is provided in an array in the subtree JSON\n // regardless of whether or not it contains multiple contents. This differs from previous\n // schemas, where content availability is either a single object in the subtree JSON or\n // as an array in the 3DTILES_multiple_contents extension.\n //\n // After identifying how availability is stored, put the results in this new array for consistent processing later\n subtreeJson.contentAvailabilityHeaders = [];\n if (hasExtension(subtreeJson, \"3DTILES_multiple_contents\")) {\n subtreeJson.contentAvailabilityHeaders =\n subtreeJson.extensions[\"3DTILES_multiple_contents\"].contentAvailability;\n } else if (Array.isArray(subtreeJson.contentAvailability)) {\n subtreeJson.contentAvailabilityHeaders = subtreeJson.contentAvailability;\n } else {\n subtreeJson.contentAvailabilityHeaders.push(\n defaultValue(subtreeJson.contentAvailability, defaultContentAvailability)\n );\n }\n\n const bufferHeaders = preprocessBuffers(subtreeJson.buffers);\n const bufferViewHeaders = preprocessBufferViews(\n subtreeJson.bufferViews,\n bufferHeaders\n );\n\n // Buffers and buffer views are inactive until explicitly marked active.\n // This way we can avoid fetching buffers that will not be used.\n markActiveBufferViews(subtreeJson, bufferViewHeaders);\n if (defined(tilePropertyTableJson)) {\n markActiveMetadataBufferViews(tilePropertyTableJson, bufferViewHeaders);\n }\n\n for (let i = 0; i < contentPropertyTableJsons.length; i++) {\n const contentPropertyTableJson = contentPropertyTableJsons[i];\n markActiveMetadataBufferViews(contentPropertyTableJson, bufferViewHeaders);\n }\n\n const buffersU8 = await requestActiveBuffers(\n subtree,\n bufferHeaders,\n chunks.binary\n );\n const bufferViewsU8 = parseActiveBufferViews(bufferViewHeaders, buffersU8);\n parseAvailability(subtree, subtreeJson, implicitTileset, bufferViewsU8);\n\n if (defined(tilePropertyTableJson)) {\n parseTileMetadataTable(subtree, implicitTileset, bufferViewsU8);\n makeTileJumpBuffer(subtree);\n }\n\n parseContentMetadataTables(subtree, implicitTileset, bufferViewsU8);\n makeContentJumpBuffers(subtree);\n\n subtree._ready = true;\n return subtree;\n};\n\n/**\n * A helper object for storing the two parts of the subtree binary\n *\n * @typedef {object} SubtreeChunks\n * @property {object} json The json chunk of the subtree\n * @property {Uint8Array} binary The binary chunk of the subtree. This represents the internal buffer.\n * @private\n */\n\n/**\n * Given the binary contents of a subtree, split into JSON and binary chunks\n *\n * @param {Uint8Array} subtreeView The subtree binary\n * @returns {SubtreeChunks} An object containing the JSON and binary chunks.\n * @private\n */\nfunction parseSubtreeChunks(subtreeView) {\n // Parse the header\n const littleEndian = true;\n const subtreeReader = new DataView(\n subtreeView.buffer,\n subtreeView.byteOffset\n );\n // Skip to the chunk lengths\n let byteOffset = 8;\n\n // Read the bottom 32 bits of the 64-bit byte length. This is ok for now because:\n // 1) not all browsers have native 64-bit operations\n // 2) the data is well under 4GB\n const jsonByteLength = subtreeReader.getUint32(byteOffset, littleEndian);\n byteOffset += 8;\n const binaryByteLength = subtreeReader.getUint32(byteOffset, littleEndian);\n byteOffset += 8;\n\n const subtreeJson = getJsonFromTypedArray(\n subtreeView,\n byteOffset,\n jsonByteLength\n );\n byteOffset += jsonByteLength;\n const subtreeBinary = subtreeView.subarray(\n byteOffset,\n byteOffset + binaryByteLength\n );\n\n return {\n json: subtreeJson,\n binary: subtreeBinary,\n };\n}\n\n/**\n * A buffer header is the JSON header from the subtree JSON chunk plus\n * a couple extra boolean flags for easy reference.\n *\n * Buffers are assumed inactive until explicitly marked active. This is used\n * to avoid fetching unneeded buffers.\n *\n * @typedef {object} BufferHeader\n * @property {boolean} isExternal True if this is an external buffer\n * @property {boolean} isActive Whether this buffer is currently used.\n * @property {string} [uri] The URI of the buffer (external buffers only)\n * @property {number} byteLength The byte length of the buffer, including any padding contained within.\n * @private\n */\n\n/**\n * Iterate over the list of buffers from the subtree JSON and add the\n * isExternal and isActive fields for easier parsing later. This modifies\n * the objects in place.\n *\n * @param {Object[]} [bufferHeaders=[]] The JSON from subtreeJson.buffers.\n * @returns {BufferHeader[]} The same array of headers with additional fields.\n * @private\n */\nfunction preprocessBuffers(bufferHeaders) {\n bufferHeaders = defined(bufferHeaders) ? bufferHeaders : [];\n for (let i = 0; i < bufferHeaders.length; i++) {\n const bufferHeader = bufferHeaders[i];\n bufferHeader.isExternal = defined(bufferHeader.uri);\n bufferHeader.isActive = false;\n }\n\n return bufferHeaders;\n}\n\n/**\n * A buffer header is the JSON header from the subtree JSON chunk plus\n * the isActive flag and a reference to the header for the underlying buffer\n *\n * @typedef {object} BufferViewHeader\n * @property {BufferHeader} bufferHeader A reference to the header for the underlying buffer\n * @property {boolean} isActive Whether this bufferView is currently used.\n * @property {number} buffer The index of the underlying buffer.\n * @property {number} byteOffset The start byte of the bufferView within the buffer.\n * @property {number} byteLength The length of the bufferView. No padding is included in this length.\n * @private\n */\n\n/**\n * Iterate the list of buffer views from the subtree JSON and add the\n * isActive flag. Also save a reference to the bufferHeader\n *\n * @param {Object[]} [bufferViewHeaders=[]] The JSON from subtree.bufferViews\n * @param {BufferHeader[]} bufferHeaders The preprocessed buffer headers\n * @returns {BufferViewHeader[]} The same array of bufferView headers with additional fields\n * @private\n */\nfunction preprocessBufferViews(bufferViewHeaders, bufferHeaders) {\n bufferViewHeaders = defined(bufferViewHeaders) ? bufferViewHeaders : [];\n for (let i = 0; i < bufferViewHeaders.length; i++) {\n const bufferViewHeader = bufferViewHeaders[i];\n const bufferHeader = bufferHeaders[bufferViewHeader.buffer];\n bufferViewHeader.bufferHeader = bufferHeader;\n bufferViewHeader.isActive = false;\n }\n return bufferViewHeaders;\n}\n\n/**\n * Determine which buffer views need to be loaded into memory. This includes:\n *\n *
    \n *
  • The tile availability bitstream (if a bitstream is defined)
  • \n *
  • The content availability bitstream(s) (if a bitstream is defined)
  • \n *
  • The child subtree availability bitstream (if a bitstream is defined)
  • \n *
\n *\n *

\n * This function modifies the buffer view headers' isActive flags in place.\n *

\n *\n * @param {Object[]} subtreeJson The JSON chunk from the subtree\n * @param {BufferViewHeader[]} bufferViewHeaders The preprocessed buffer view headers\n * @private\n */\nfunction markActiveBufferViews(subtreeJson, bufferViewHeaders) {\n let header;\n const tileAvailabilityHeader = subtreeJson.tileAvailability;\n\n // Check for bitstream first, which is part of the current schema.\n // bufferView is the name of the bitstream from an older schema.\n if (defined(tileAvailabilityHeader.bitstream)) {\n header = bufferViewHeaders[tileAvailabilityHeader.bitstream];\n } else if (defined(tileAvailabilityHeader.bufferView)) {\n header = bufferViewHeaders[tileAvailabilityHeader.bufferView];\n }\n\n if (defined(header)) {\n header.isActive = true;\n header.bufferHeader.isActive = true;\n }\n\n const contentAvailabilityHeaders = subtreeJson.contentAvailabilityHeaders;\n for (let i = 0; i < contentAvailabilityHeaders.length; i++) {\n header = undefined;\n if (defined(contentAvailabilityHeaders[i].bitstream)) {\n header = bufferViewHeaders[contentAvailabilityHeaders[i].bitstream];\n } else if (defined(contentAvailabilityHeaders[i].bufferView)) {\n header = bufferViewHeaders[contentAvailabilityHeaders[i].bufferView];\n }\n\n if (defined(header)) {\n header.isActive = true;\n header.bufferHeader.isActive = true;\n }\n }\n\n header = undefined;\n const childSubtreeAvailabilityHeader = subtreeJson.childSubtreeAvailability;\n if (defined(childSubtreeAvailabilityHeader.bitstream)) {\n header = bufferViewHeaders[childSubtreeAvailabilityHeader.bitstream];\n } else if (defined(childSubtreeAvailabilityHeader.bufferView)) {\n header = bufferViewHeaders[childSubtreeAvailabilityHeader.bufferView];\n }\n\n if (defined(header)) {\n header.isActive = true;\n header.bufferHeader.isActive = true;\n }\n}\n\n/**\n * For handling metadata, look over the tile and content metadata buffers\n *

\n * This always loads all of the metadata immediately. Future iterations may\n * allow filtering this to avoid downloading unneeded buffers.\n *

\n *\n * @param {object} propertyTableJson The property table JSON for either a tile or some content\n * @param {BufferViewHeader[]} bufferViewHeaders The preprocessed buffer view headers\n * @private\n */\nfunction markActiveMetadataBufferViews(propertyTableJson, bufferViewHeaders) {\n const properties = propertyTableJson.properties;\n let header;\n for (const key in properties) {\n if (properties.hasOwnProperty(key)) {\n const metadataHeader = properties[key];\n\n // An older spec used bufferView\n const valuesBufferView = defaultValue(\n metadataHeader.values,\n metadataHeader.bufferView\n );\n header = bufferViewHeaders[valuesBufferView];\n header.isActive = true;\n header.bufferHeader.isActive = true;\n\n // An older spec used stringOffsetBufferView\n const stringOffsetBufferView = defaultValue(\n metadataHeader.stringOffsets,\n metadataHeader.stringOffsetBufferView\n );\n if (defined(stringOffsetBufferView)) {\n header = bufferViewHeaders[stringOffsetBufferView];\n header.isActive = true;\n header.bufferHeader.isActive = true;\n }\n\n // an older spec used arrayOffsetBufferView\n const arrayOffsetBufferView = defaultValue(\n metadataHeader.arrayOffsets,\n metadataHeader.arrayOffsetBufferView\n );\n if (defined(arrayOffsetBufferView)) {\n header = bufferViewHeaders[arrayOffsetBufferView];\n header.isActive = true;\n header.bufferHeader.isActive = true;\n }\n }\n }\n}\n\n/**\n * Go through the list of buffers and gather all the active ones into a\n * a dictionary. Since external buffers are allowed, this sometimes involves\n * fetching separate binary files. Consequently, this method returns a promise.\n *

\n * The results are put into a dictionary object. The keys are indices of\n * buffers, and the values are Uint8Arrays of the contents. Only buffers\n * marked with the isActive flag are fetched.\n *

\n *

\n * The internal buffer (the subtree's binary chunk) is also stored in this\n * dictionary if it is marked active.\n *

\n * @param {ImplicitSubtree} subtree The subtree\n * @param {BufferHeader[]} bufferHeaders The preprocessed buffer headers\n * @param {Uint8Array} internalBuffer The binary chunk of the subtree file\n * @returns {Promise} A promise resolving to the dictionary of active buffers\n * @private\n */\nfunction requestActiveBuffers(subtree, bufferHeaders, internalBuffer) {\n const promises = [];\n for (let i = 0; i < bufferHeaders.length; i++) {\n const bufferHeader = bufferHeaders[i];\n if (!bufferHeader.isActive) {\n promises.push(Promise.resolve(undefined));\n } else if (bufferHeader.isExternal) {\n const promise = requestExternalBuffer(subtree, bufferHeader);\n promises.push(promise);\n } else {\n promises.push(Promise.resolve(internalBuffer));\n }\n }\n return Promise.all(promises).then(function (bufferResults) {\n const buffersU8 = {};\n for (let i = 0; i < bufferResults.length; i++) {\n const result = bufferResults[i];\n if (defined(result)) {\n buffersU8[i] = result;\n }\n }\n return buffersU8;\n });\n}\n\nasync function requestExternalBuffer(subtree, bufferHeader) {\n const baseResource = subtree._resource;\n const bufferResource = baseResource.getDerivedResource({\n url: bufferHeader.uri,\n });\n\n const bufferLoader = ResourceCache.getExternalBufferLoader({\n resource: bufferResource,\n });\n subtree._bufferLoader = bufferLoader;\n\n try {\n await bufferLoader.load();\n } catch (error) {\n if (bufferLoader.isDestroyed()) {\n return;\n }\n\n throw error;\n }\n\n return bufferLoader.typedArray;\n}\n\n/**\n * Go through the list of buffer views, and if they are marked as active,\n * extract a subarray from one of the active buffers.\n *\n * @param {BufferViewHeader[]} bufferViewHeaders\n * @param {object} buffersU8 A dictionary of buffer index to a Uint8Array of its contents.\n * @returns {object} A dictionary of buffer view index to a Uint8Array of its contents.\n * @private\n */\nfunction parseActiveBufferViews(bufferViewHeaders, buffersU8) {\n const bufferViewsU8 = {};\n for (let i = 0; i < bufferViewHeaders.length; i++) {\n const bufferViewHeader = bufferViewHeaders[i];\n\n if (!bufferViewHeader.isActive) {\n continue;\n }\n\n const start = bufferViewHeader.byteOffset;\n const end = start + bufferViewHeader.byteLength;\n const buffer = buffersU8[bufferViewHeader.buffer];\n const bufferView = buffer.subarray(start, end);\n bufferViewsU8[i] = bufferView;\n }\n return bufferViewsU8;\n}\n\n/**\n * Parse the three availability bitstreams and store them in the subtree\n *\n * @param {ImplicitSubtree} subtree The subtree to modify\n * @param {object} subtreeJson The subtree JSON\n * @param {ImplicitTileset} implicitTileset The implicit tileset this subtree belongs to\n * @param {object} bufferViewsU8 A dictionary of buffer view index to a Uint8Array of its contents.\n * @private\n */\nfunction parseAvailability(\n subtree,\n subtreeJson,\n implicitTileset,\n bufferViewsU8\n) {\n const branchingFactor = implicitTileset.branchingFactor;\n const subtreeLevels = implicitTileset.subtreeLevels;\n const tileAvailabilityBits =\n (Math.pow(branchingFactor, subtreeLevels) - 1) / (branchingFactor - 1);\n const childSubtreeBits = Math.pow(branchingFactor, subtreeLevels);\n\n // availableCount is only needed for the metadata jump buffer, which\n // corresponds to the tile availability bitstream.\n const hasMetadataExtension = hasExtension(subtreeJson, \"3DTILES_metadata\");\n const hasTileMetadata = defined(subtree._tilePropertyTableJson);\n let computeAvailableCountEnabled = hasMetadataExtension || hasTileMetadata;\n\n subtree._tileAvailability = parseAvailabilityBitstream(\n subtreeJson.tileAvailability,\n bufferViewsU8,\n tileAvailabilityBits,\n computeAvailableCountEnabled\n );\n\n const hasContentMetadata = subtree._contentPropertyTableJsons.length > 0;\n computeAvailableCountEnabled =\n computeAvailableCountEnabled || hasContentMetadata;\n\n for (let i = 0; i < subtreeJson.contentAvailabilityHeaders.length; i++) {\n const bitstream = parseAvailabilityBitstream(\n subtreeJson.contentAvailabilityHeaders[i],\n bufferViewsU8,\n // content availability has the same length as tile availability.\n tileAvailabilityBits,\n computeAvailableCountEnabled\n );\n subtree._contentAvailabilityBitstreams.push(bitstream);\n }\n\n subtree._childSubtreeAvailability = parseAvailabilityBitstream(\n subtreeJson.childSubtreeAvailability,\n bufferViewsU8,\n childSubtreeBits\n );\n}\n\n/**\n * Given the JSON describing an availability bitstream, turn it into an\n * in-memory representation using an {@link ImplicitAvailabilityBitstream}\n * object. This handles both constants and bitstreams from a bufferView.\n *\n * @param {object} availabilityJson A JSON object representing the availability\n * @param {object} bufferViewsU8 A dictionary of bufferView index to its Uint8Array contents.\n * @param {number} lengthBits The length of the availability bitstream in bits\n * @param {boolean} [computeAvailableCountEnabled] If true and availabilityJson.availableCount is undefined, the availableCount will be computed.\n * @returns {ImplicitAvailabilityBitstream} The parsed bitstream object\n * @private\n */\nfunction parseAvailabilityBitstream(\n availabilityJson,\n bufferViewsU8,\n lengthBits,\n computeAvailableCountEnabled\n) {\n if (defined(availabilityJson.constant)) {\n return new ImplicitAvailabilityBitstream({\n constant: Boolean(availabilityJson.constant),\n lengthBits: lengthBits,\n availableCount: availabilityJson.availableCount,\n });\n }\n\n let bufferView;\n\n // Check for bitstream first, which is part of the current schema.\n // bufferView is the name of the bitstream from an older schema.\n if (defined(availabilityJson.bitstream)) {\n bufferView = bufferViewsU8[availabilityJson.bitstream];\n } else if (defined(availabilityJson.bufferView)) {\n bufferView = bufferViewsU8[availabilityJson.bufferView];\n }\n\n return new ImplicitAvailabilityBitstream({\n bitstream: bufferView,\n lengthBits: lengthBits,\n availableCount: availabilityJson.availableCount,\n computeAvailableCountEnabled: computeAvailableCountEnabled,\n });\n}\n\n/**\n * Parse the metadata table for the tile metadata, storing a {@link MetadataTable}\n * in the subtree.\n *\n * @param {ImplicitSubtree} subtree The subtree\n * @param {ImplicitTileset} implicitTileset The implicit tileset this subtree belongs to.\n * @param {object} bufferViewsU8 A dictionary of bufferView index to its Uint8Array contents.\n * @private\n */\nfunction parseTileMetadataTable(subtree, implicitTileset, bufferViewsU8) {\n const tilePropertyTableJson = subtree._tilePropertyTableJson;\n const tileCount = subtree._tileAvailability.availableCount;\n const metadataSchema = implicitTileset.metadataSchema;\n\n const tileMetadataClassName = tilePropertyTableJson.class;\n const tileMetadataClass = metadataSchema.classes[tileMetadataClassName];\n\n subtree._tileMetadataTable = new MetadataTable({\n class: tileMetadataClass,\n count: tileCount,\n properties: tilePropertyTableJson.properties,\n bufferViews: bufferViewsU8,\n });\n}\n\n/**\n * Parse the metadata tables for the content metadata, storing an array of\n * {@link MetadataTable}s in the subtree.\n *\n * @param {ImplicitSubtree} subtree The subtree\n * @param {ImplicitTileset} implicitTileset The implicit tileset this subtree belongs to.\n * @param {object} bufferViewsU8 A dictionary of bufferView index to its Uint8Array contents.\n * @private\n */\nfunction parseContentMetadataTables(subtree, implicitTileset, bufferViewsU8) {\n const contentPropertyTableJsons = subtree._contentPropertyTableJsons;\n const contentAvailabilityBitstreams = subtree._contentAvailabilityBitstreams;\n const metadataSchema = implicitTileset.metadataSchema;\n\n const contentMetadataTables = subtree._contentMetadataTables;\n for (let i = 0; i < contentPropertyTableJsons.length; i++) {\n const contentPropertyTableJson = contentPropertyTableJsons[i];\n const contentAvailabilityBitsteam = contentAvailabilityBitstreams[i];\n\n const contentCount = contentAvailabilityBitsteam.availableCount;\n const contentMetadataClassName = contentPropertyTableJson.class;\n const contentMetadataClass =\n metadataSchema.classes[contentMetadataClassName];\n\n const metadataTable = new MetadataTable({\n class: contentMetadataClass,\n count: contentCount,\n properties: contentPropertyTableJson.properties,\n bufferViews: bufferViewsU8,\n });\n\n contentMetadataTables.push(metadataTable);\n }\n}\n\n/**\n * Make a jump buffer, i.e. a map of a bit index to the metadata entity ID.\n *

\n * For unavailable tiles and content, the jump buffer entries will be uninitialized.\n * Use the tile and content availability to determine whether a jump buffer value is valid.\n *

\n *\n * @param {ImplicitAvailabilityBitstream} availability The availability bitstream to create the jump buffer from.\n * @returns {Array} The resulting jump buffer.\n * @private\n */\nfunction makeJumpBuffer(availability) {\n let entityId = 0;\n const bufferLength = availability.lengthBits;\n const availableCount = availability.availableCount;\n\n let jumpBuffer;\n if (availableCount < 256) {\n jumpBuffer = new Uint8Array(bufferLength);\n } else if (availableCount < 65536) {\n jumpBuffer = new Uint16Array(bufferLength);\n } else {\n jumpBuffer = new Uint32Array(bufferLength);\n }\n\n for (let i = 0; i < availability.lengthBits; i++) {\n if (availability.getBit(i)) {\n jumpBuffer[i] = entityId;\n entityId++;\n }\n }\n\n return jumpBuffer;\n}\n\n/**\n * Make the jump buffer, i.e. a map of a bit index to the metadata entity ID,\n * for the content metadata. This is stored in the subtree.\n *\n * @param {ImplicitSubtree} subtree The subtree\n * @private\n */\nfunction makeTileJumpBuffer(subtree) {\n const tileJumpBuffer = makeJumpBuffer(subtree._tileAvailability);\n subtree._tileJumpBuffer = tileJumpBuffer;\n}\n\n/**\n * Make the jump buffers, i.e. maps of bit indices to the metadata entity IDs,\n * for the content metadata. This is stored in the subtree.\n *\n * @param {ImplicitSubtree} subtree The subtree\n * @private\n */\nfunction makeContentJumpBuffers(subtree) {\n const contentJumpBuffers = subtree._contentJumpBuffers;\n const contentAvailabilityBitstreams = subtree._contentAvailabilityBitstreams;\n for (let i = 0; i < contentAvailabilityBitstreams.length; i++) {\n const contentAvailability = contentAvailabilityBitstreams[i];\n const contentJumpBuffer = makeJumpBuffer(contentAvailability);\n contentJumpBuffers.push(contentJumpBuffer);\n }\n}\n\n/**\n * Given the implicit tiling coordinates for a tile, get the index within the\n * subtree's tile availability bitstream.\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a tile\n * @return {number} The tile's index within the subtree.\n * @private\n */\nImplicitSubtree.prototype.getTileIndex = function (implicitCoordinates) {\n const localLevel =\n implicitCoordinates.level - this._implicitCoordinates.level;\n if (localLevel < 0 || this._subtreeLevels <= localLevel) {\n throw new RuntimeError(\"level is out of bounds for this subtree\");\n }\n\n const subtreeCoordinates = implicitCoordinates.getSubtreeCoordinates();\n const offsetCoordinates = subtreeCoordinates.getOffsetCoordinates(\n implicitCoordinates\n );\n const index = offsetCoordinates.tileIndex;\n return index;\n};\n\n/**\n * Given the implicit tiling coordinates for a child subtree, get the index within the\n * subtree's child subtree availability bitstream.\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a child subtree\n * @return {number} The child subtree's index within the subtree's child subtree availability bitstream.\n * @private\n */\nImplicitSubtree.prototype.getChildSubtreeIndex = function (\n implicitCoordinates\n) {\n const localLevel =\n implicitCoordinates.level - this._implicitCoordinates.level;\n if (localLevel !== this._implicitCoordinates.subtreeLevels) {\n throw new RuntimeError(\"level is out of bounds for this subtree\");\n }\n\n // Call getParentSubtreeCoordinates instead of getSubtreeCoordinates because the\n // child subtree is by definition the root of its own subtree, so we need to find\n // the parent subtree.\n const parentSubtreeCoordinates = implicitCoordinates.getParentSubtreeCoordinates();\n const offsetCoordinates = parentSubtreeCoordinates.getOffsetCoordinates(\n implicitCoordinates\n );\n const index = offsetCoordinates.mortonIndex;\n return index;\n};\n\n/**\n * Get the entity ID for a tile within this subtree.\n * @param {ImplicitSubtree} subtree The subtree\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a tile\n * @return {number} The entity ID for this tile for accessing tile metadata, or undefined if not applicable.\n *\n * @private\n */\nfunction getTileEntityId(subtree, implicitCoordinates) {\n if (!defined(subtree._tileMetadataTable)) {\n return undefined;\n }\n\n const tileIndex = subtree.getTileIndex(implicitCoordinates);\n if (subtree._tileAvailability.getBit(tileIndex)) {\n return subtree._tileJumpBuffer[tileIndex];\n }\n\n return undefined;\n}\n\n/**\n * Get the entity ID for a content within this subtree.\n * @param {ImplicitSubtree} subtree The subtree\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a content\n * @param {number} contentIndex The content index, for distinguishing between multiple contents.\n * @return {number} The entity ID for this content for accessing content metadata, or undefined if not applicable.\n *\n * @private\n */\nfunction getContentEntityId(subtree, implicitCoordinates, contentIndex) {\n const metadataTables = subtree._contentMetadataTables;\n if (!defined(metadataTables)) {\n return undefined;\n }\n\n const metadataTable = metadataTables[contentIndex];\n if (!defined(metadataTable)) {\n return undefined;\n }\n\n const availability = subtree._contentAvailabilityBitstreams[contentIndex];\n const tileIndex = subtree.getTileIndex(implicitCoordinates);\n if (availability.getBit(tileIndex)) {\n const contentJumpBuffer = subtree._contentJumpBuffers[contentIndex];\n return contentJumpBuffer[tileIndex];\n }\n\n return undefined;\n}\n\n/**\n * Create and return a metadata table view for a tile within this subtree.\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a tile\n * @return {ImplicitMetadataView} The metadata view for this tile, or undefined if not applicable.\n *\n * @private\n */\nImplicitSubtree.prototype.getTileMetadataView = function (implicitCoordinates) {\n const entityId = getTileEntityId(this, implicitCoordinates);\n if (!defined(entityId)) {\n return undefined;\n }\n\n const metadataTable = this._tileMetadataTable;\n return new ImplicitMetadataView({\n class: metadataTable.class,\n metadataTable: metadataTable,\n entityId: entityId,\n propertyTableJson: this._tilePropertyTableJson,\n });\n};\n\n/**\n * Create and return a metadata table view for a content within this subtree.\n * @param {ImplicitTileCoordinates} implicitCoordinates The global coordinates of a content\n * @param {number} contentIndex The index of the content used to distinguish between multiple contents\n * @return {ImplicitMetadataView} The metadata view for this content, or undefined if not applicable.\n *\n * @private\n */\nImplicitSubtree.prototype.getContentMetadataView = function (\n implicitCoordinates,\n contentIndex\n) {\n const entityId = getContentEntityId(this, implicitCoordinates, contentIndex);\n if (!defined(entityId)) {\n return undefined;\n }\n\n const metadataTable = this._contentMetadataTables[contentIndex];\n const propertyTableJson = this._contentPropertyTableJsons[contentIndex];\n return new ImplicitMetadataView({\n class: metadataTable.class,\n metadataTable: metadataTable,\n entityId: entityId,\n contentIndex: contentIndex,\n propertyTableJson: propertyTableJson,\n });\n};\n\n/**\n * @private\n */\nImplicitSubtree.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * @private\n */\nImplicitSubtree.prototype.destroy = function () {\n if (defined(this._bufferLoader)) {\n ResourceCache.unload(this._bufferLoader);\n }\n\n return destroyObject(this);\n};\n\nexport default ImplicitSubtree;\n", "/**\n * An enum of built-in semantics.\n *\n * @enum MetadataSemantic\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata/Semantics|3D Metadata Semantic Reference}\n */\nconst MetadataSemantic = {\n /**\n * A unique identifier, stored as a STRING.\n *\n * @type {string}\n * @constant\n * @private\n */\n ID: \"ID\",\n /**\n * A name, stored as a STRING. This does not have to be unique.\n *\n * @type {string}\n * @constant\n * @private\n */\n NAME: \"NAME\",\n /**\n * A description, stored as a STRING.\n *\n * @type {string}\n * @constant\n * @private\n */\n DESCRIPTION: \"DESCRIPTION\",\n /**\n * The number of tiles in a tileset, stored as a UINT64.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILESET_TILE_COUNT: \"TILESET_TILE_COUNT\",\n /**\n * A bounding box for a tile, stored as an array of 12 FLOAT32 or FLOAT64 components. The components are the same format as for boundingVolume.box in 3D Tiles 1.0. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_BOUNDING_BOX: \"TILE_BOUNDING_BOX\",\n /**\n * A bounding region for a tile, stored as an array of 6 FLOAT64 components. The components are [west, south, east, north, minimumHeight, maximumHeight]. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_BOUNDING_REGION: \"TILE_BOUNDING_REGION\",\n /**\n * A bounding sphere for a tile, stored as an array of 4 FLOAT32 or FLOAT64 components. The components are [centerX, centerY, centerZ, radius]. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_BOUNDING_SPHERE: \"TILE_BOUNDING_SPHERE\",\n /**\n * The minimum height of a tile above (or below) the WGS84 ellipsoid, stored as a FLOAT32 or a FLOAT64. This semantic is used to tighten bounding regions implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_MINIMUM_HEIGHT: \"TILE_MINIMUM_HEIGHT\",\n /**\n * The maximum height of a tile above (or below) the WGS84 ellipsoid, stored as a FLOAT32 or a FLOAT64. This semantic is used to tighten bounding regions implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_MAXIMUM_HEIGHT: \"TILE_MAXIMUM_HEIGHT\",\n /**\n * The horizon occlusion point for a tile, stored as an VEC3 of FLOAT32 or FLOAT64 components.\n *\n * @see {@link https://cesium.com/blog/2013/04/25/horizon-culling/|Horizon Culling}\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_HORIZON_OCCLUSION_POINT: \"TILE_HORIZON_OCCLUSION_POINT\",\n /**\n * The geometric error for a tile, stored as a FLOAT32 or a FLOAT64. This semantic is used to override the geometric error implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n TILE_GEOMETRIC_ERROR: \"TILE_GEOMETRIC_ERROR\",\n /**\n * A bounding box for the content of a tile, stored as an array of 12 FLOAT32 or FLOAT64 components. The components are the same format as for boundingVolume.box in 3D Tiles 1.0. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_BOUNDING_BOX: \"CONTENT_BOUNDING_BOX\",\n /**\n * A bounding region for the content of a tile, stored as an array of 6 FLOAT64 components. The components are [west, south, east, north, minimumHeight, maximumHeight]. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_BOUNDING_REGION: \"CONTENT_BOUNDING_REGION\",\n /**\n * A bounding sphere for the content of a tile, stored as an array of 4 FLOAT32 or FLOAT64 components. The components are [centerX, centerY, centerZ, radius]. This semantic is used to provide a tighter bounding volume than the one implicitly calculated in implicit tiling.\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_BOUNDING_SPHERE: \"CONTENT_BOUNDING_SPHERE\",\n /**\n * The minimum height of the content of a tile above (or below) the WGS84 ellipsoid, stored as a FLOAT32 or a FLOAT64\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_MINIMUM_HEIGHT: \"CONTENT_MINIMUM_HEIGHT\",\n /**\n * The maximum height of the content of a tile above (or below) the WGS84 ellipsoid, stored as a FLOAT32 or a FLOAT64\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_MAXIMUM_HEIGHT: \"CONTENT_MAXIMUM_HEIGHT\",\n /**\n * The horizon occlusion point for the content of a tile, stored as an VEC3 of FLOAT32 or FLOAT64 components.\n *\n * @see {@link https://cesium.com/blog/2013/04/25/horizon-culling/|Horizon Culling}\n *\n * @type {string}\n * @constant\n * @private\n */\n CONTENT_HORIZON_OCCLUSION_POINT: \"CONTENT_HORIZON_OCCLUSION_POINT\",\n};\n\nexport default Object.freeze(MetadataSemantic);\n", "import Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * Utilities for parsing bounding volume semantics from 3D Tiles 1.1 metadata.\n *\n * @namespace BoundingVolumeSemantics\n * @private\n */\nconst BoundingVolumeSemantics = {};\n\n/**\n * Parse the bounding volume-related semantics such as\n * TILE_BOUNDING_BOX and CONTENT_BOUNDING_REGION from\n * implicit tile metadata. Results are returned as a JSON object for use when\n * transcoding tiles (see {@link Implicit3DTileContent}).\n *

\n * Bounding volumes are checked in the order box, region, then sphere. Only\n * the first valid bounding volume is returned.\n *

\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata/Semantics|3D Metadata Semantic Reference} for the various bounding volumes and minimum/maximum heights.\n *\n * @param {TileMetadata} tileMetadata The metadata object for looking up values by semantic. In practice, this will typically be a {@link ImplicitMetadataView}\n * @return {object} An object containing a tile property and a content property. These contain the bounding volume, and any minimum or maximum height.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nBoundingVolumeSemantics.parseAllBoundingVolumeSemantics = function (\n tileMetadata\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"tileMetadata\", tileMetadata);\n //>>includeEnd('debug');\n\n return {\n tile: {\n boundingVolume: BoundingVolumeSemantics.parseBoundingVolumeSemantic(\n \"TILE\",\n tileMetadata\n ),\n minimumHeight: BoundingVolumeSemantics._parseMinimumHeight(\n \"TILE\",\n tileMetadata\n ),\n maximumHeight: BoundingVolumeSemantics._parseMaximumHeight(\n \"TILE\",\n tileMetadata\n ),\n },\n content: {\n boundingVolume: BoundingVolumeSemantics.parseBoundingVolumeSemantic(\n \"CONTENT\",\n tileMetadata\n ),\n minimumHeight: BoundingVolumeSemantics._parseMinimumHeight(\n \"CONTENT\",\n tileMetadata\n ),\n maximumHeight: BoundingVolumeSemantics._parseMaximumHeight(\n \"CONTENT\",\n tileMetadata\n ),\n },\n };\n};\n\n/**\n * Parse the bounding volume from a tile metadata. If the metadata specify\n * multiple bounding volumes, only the first one is returned. Bounding volumes\n * are checked in the order box, region, then sphere.\n *\n * This handles both tile and content bounding volumes, as the only difference\n * is the prefix. e.g. TILE_BOUNDING_BOX and\n * CONTENT_BOUNDING_BOX have the same memory layout.\n *\n * @param {string} prefix Either \"TILE\" or \"CONTENT\"\n * @param {TileMetadata} tileMetadata The tileMetadata for looking up values\n * @return {object} An object representing the JSON description of the tile metadata\n * @private\n */\nBoundingVolumeSemantics.parseBoundingVolumeSemantic = function (\n prefix,\n tileMetadata\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"prefix\", prefix);\n if (prefix !== \"TILE\" && prefix !== \"CONTENT\") {\n throw new DeveloperError(\"prefix must be either 'TILE' or 'CONTENT'\");\n }\n Check.typeOf.object(\"tileMetadata\", tileMetadata);\n //>>includeEnd('debug');\n\n const boundingBoxSemantic = `${prefix}_BOUNDING_BOX`;\n const boundingBox = tileMetadata.getPropertyBySemantic(boundingBoxSemantic);\n\n if (defined(boundingBox)) {\n return {\n box: boundingBox,\n };\n }\n\n const boundingRegionSemantic = `${prefix}_BOUNDING_REGION`;\n const boundingRegion = tileMetadata.getPropertyBySemantic(\n boundingRegionSemantic\n );\n\n if (defined(boundingRegion)) {\n return {\n region: boundingRegion,\n };\n }\n\n const boundingSphereSemantic = `${prefix}_BOUNDING_SPHERE`;\n const boundingSphere = tileMetadata.getPropertyBySemantic(\n boundingSphereSemantic\n );\n\n if (defined(boundingSphere)) {\n // ARRAY with 4 elements is automatically converted to a Cartesian4\n return {\n sphere: boundingSphere,\n };\n }\n\n return undefined;\n};\n\n/**\n * Parse the minimum height from tile metadata. This is used for making tighter\n * quadtree bounds for implicit tiling. This works for both\n * TILE_MINIMUM_HEIGHT and CONTENT_MINIMUM_HEIGHT\n *\n * @param {string} prefix Either \"TILE\" or \"CONTENT\"\n * @param {TileMetadata} tileMetadata The tileMetadata for looking up values\n * @return {number} The minimum height\n * @private\n */\nBoundingVolumeSemantics._parseMinimumHeight = function (prefix, tileMetadata) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"prefix\", prefix);\n if (prefix !== \"TILE\" && prefix !== \"CONTENT\") {\n throw new DeveloperError(\"prefix must be either 'TILE' or 'CONTENT'\");\n }\n Check.typeOf.object(\"tileMetadata\", tileMetadata);\n //>>includeEnd('debug');\n\n const minimumHeightSemantic = `${prefix}_MINIMUM_HEIGHT`;\n return tileMetadata.getPropertyBySemantic(minimumHeightSemantic);\n};\n\n/**\n * Parse the maximum height from tile metadata. This is used for making tighter\n * quadtree bounds for implicit tiling. This works for both\n * TILE_MAXIMUM_HEIGHT and CONTENT_MAXIMUM_HEIGHT\n *\n * @param {string} prefix Either \"TILE\" or \"CONTENT\"\n * @param {TileMetadata} tileMetadata The tileMetadata for looking up values\n * @return {number} The maximum height\n * @private\n */\nBoundingVolumeSemantics._parseMaximumHeight = function (prefix, tileMetadata) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"prefix\", prefix);\n if (prefix !== \"TILE\" && prefix !== \"CONTENT\") {\n throw new DeveloperError(\"prefix must be either 'TILE' or 'CONTENT'\");\n }\n Check.typeOf.object(\"tileMetadata\", tileMetadata);\n //>>includeEnd('debug');\n\n const maximumHeightSemantic = `${prefix}_MAXIMUM_HEIGHT`;\n return tileMetadata.getPropertyBySemantic(maximumHeightSemantic);\n};\n\nexport default BoundingVolumeSemantics;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport combine from \"../Core/combine.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport HilbertOrder from \"../Core/HilbertOrder.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport S2Cell from \"../Core/S2Cell.js\";\nimport ImplicitSubtree from \"./ImplicitSubtree.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport MetadataSemantic from \"./MetadataSemantic.js\";\nimport BoundingVolumeSemantics from \"./BoundingVolumeSemantics.js\";\n\n/**\n * A specialized {@link Cesium3DTileContent} that lazily evaluates an implicit\n * tileset. It is somewhat similar in operation to a\n * {@link Tileset3DTileContent} in that once the content is constructed, it\n * updates the tileset tree with more tiles. However, unlike external tilesets,\n * child subtrees are represented as additional placeholder nodes with\n * Implicit3DTileContent.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n * This object is normally not instantiated directly, use {@link Implicit3DTileContent.fromSubtreeJson}.\n *\n * @alias Implicit3DTileContent\n * @constructor\n *\n * @param {Cesium3DTileset} tileset The tileset this content belongs to\n * @param {Cesium3DTile} tile The tile this content belongs to.\n * @param {Resource} resource The resource for the tileset\n * @param {object} [json] The JSON object containing the subtree. Mutually exclusive with arrayBuffer.\n * @param {ArrayBuffer} [arrayBuffer] The array buffer that stores the content payload. Mutually exclusive with json.\n * @param {number} [byteOffset=0] The offset into the array buffer, if one was provided\n *\n * @exception {DeveloperError} One of json and arrayBuffer must be defined.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction Implicit3DTileContent(tileset, tile, resource) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"tile.implicitTileset\", tile.implicitTileset);\n Check.defined(\"tile.implicitCoordinates\", tile.implicitCoordinates);\n //>>includeEnd('debug');\n\n const implicitTileset = tile.implicitTileset;\n const implicitCoordinates = tile.implicitCoordinates;\n\n this._implicitTileset = implicitTileset;\n this._implicitCoordinates = implicitCoordinates;\n this._implicitSubtree = undefined;\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n\n this._metadata = undefined;\n\n this.featurePropertiesDirty = false;\n this._group = undefined;\n\n const templateValues = implicitCoordinates.getTemplateValues();\n const subtreeResource = implicitTileset.subtreeUriTemplate.getDerivedResource(\n {\n templateValues: templateValues,\n }\n );\n this._url = subtreeResource.getUrlComponent(true);\n\n this._ready = false;\n}\n\nObject.defineProperties(Implicit3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n return 0;\n },\n },\n\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n trianglesLength: {\n get: function () {\n return 0;\n },\n },\n\n geometryByteLength: {\n get: function () {\n return 0;\n },\n },\n\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n return 0;\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Implicit3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._url;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Implicit3DTileContent\n * always returns undefined. Only transcoded tiles have content metadata.\n * @memberof Implicit3DTileContent.prototype\n * @private\n */\n metadata: {\n get: function () {\n return undefined;\n },\n set: function () {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\"Implicit3DTileContent cannot have metadata\");\n //>>includeEnd('debug');\n },\n },\n\n batchTable: {\n get: function () {\n return undefined;\n },\n },\n\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n },\n },\n});\n\n/**\n * Initialize the implicit content by parsing the subtree resource and setting\n * up a promise chain to expand the immediate subtree.\n *\n * @param {Cesium3DTileset} tileset The tileset this content belongs to\n * @param {Cesium3DTile} tile The tile this content belongs to.\n * @param {Resource} resource The resource for the tileset\n * @param {object} [json] The JSON containing the subtree. Mutually exclusive with arrayBuffer.\n * @param {ArrayBuffer} [arrayBuffer] The ArrayBuffer containing a subtree binary. Mutually exclusive with json.\n * @param {number} [byteOffset=0] The byte offset into the arrayBuffer\n * @return {Promise}\n *\n * @exception {DeveloperError} One of json and arrayBuffer must be defined.\n *\n * @private\n */\nImplicit3DTileContent.fromSubtreeJson = async function (\n tileset,\n tile,\n resource,\n json,\n arrayBuffer,\n byteOffset\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"tile.implicitTileset\", tile.implicitTileset);\n Check.defined(\"tile.implicitCoordinates\", tile.implicitCoordinates);\n if (defined(json) === defined(arrayBuffer)) {\n throw new DeveloperError(\"One of json and arrayBuffer must be defined.\");\n }\n //>>includeEnd('debug');\n\n byteOffset = defaultValue(byteOffset, 0);\n let uint8Array;\n if (defined(arrayBuffer)) {\n uint8Array = new Uint8Array(arrayBuffer, byteOffset);\n }\n\n const implicitTileset = tile.implicitTileset;\n const implicitCoordinates = tile.implicitCoordinates;\n\n const subtree = await ImplicitSubtree.fromSubtreeJson(\n resource,\n json,\n uint8Array,\n implicitTileset,\n implicitCoordinates\n );\n\n const content = new Implicit3DTileContent(tileset, tile, resource);\n\n content._implicitSubtree = subtree;\n expandSubtree(content, subtree);\n content._ready = true;\n\n return content;\n};\n\n/**\n * Expand a single subtree placeholder tile. This transcodes the subtree into\n * a tree of {@link Cesium3DTile}. The root of this tree is stored in\n * the placeholder tile's children array. This method also creates placeholder\n * tiles for the child subtrees to be lazily expanded as needed.\n *\n * @param {Implicit3DTileContent} content The content\n * @param {ImplicitSubtree} subtree The parsed subtree\n * @private\n */\nfunction expandSubtree(content, subtree) {\n const placeholderTile = content._tile;\n\n // Parse the tiles inside this immediate subtree\n const childIndex = content._implicitCoordinates.childIndex;\n const results = transcodeSubtreeTiles(\n content,\n subtree,\n placeholderTile,\n childIndex\n );\n\n const statistics = content._tileset.statistics;\n\n // Link the new subtree to the existing placeholder tile.\n placeholderTile.children.push(results.rootTile);\n statistics.numberOfTilesTotal++;\n\n // for each child subtree, make new placeholder tiles\n const childSubtrees = listChildSubtrees(content, subtree, results.bottomRow);\n for (let i = 0; i < childSubtrees.length; i++) {\n const subtreeLocator = childSubtrees[i];\n const leafTile = subtreeLocator.tile;\n const implicitChildTile = makePlaceholderChildSubtree(\n content,\n leafTile,\n subtreeLocator.childIndex\n );\n leafTile.children.push(implicitChildTile);\n statistics.numberOfTilesTotal++;\n }\n}\n\n/**\n * A pair of (tile, childIndex) used for finding child subtrees.\n *\n * @typedef {object} ChildSubtreeLocator\n * @property {Cesium3DTile} tile One of the tiles in the bottommost row of the subtree.\n * @property {number} childIndex The morton index of the child tile relative to its parent\n * @private\n */\n\n/**\n * Determine what child subtrees exist and return a list of information\n *\n * @param {Implicit3DTileContent} content The implicit content\n * @param {ImplicitSubtree} subtree The subtree for looking up availability\n * @param {Array} bottomRow The bottom row of tiles in a transcoded subtree\n * @returns {ChildSubtreeLocator[]} A list of identifiers for the child subtrees.\n * @private\n */\nfunction listChildSubtrees(content, subtree, bottomRow) {\n const results = [];\n const branchingFactor = content._implicitTileset.branchingFactor;\n for (let i = 0; i < bottomRow.length; i++) {\n const leafTile = bottomRow[i];\n if (!defined(leafTile)) {\n continue;\n }\n\n for (let j = 0; j < branchingFactor; j++) {\n const index = i * branchingFactor + j;\n if (subtree.childSubtreeIsAvailableAtIndex(index)) {\n results.push({\n tile: leafTile,\n childIndex: j,\n });\n }\n }\n }\n return results;\n}\n\n/**\n * Results of transcodeSubtreeTiles, containing the root tile of the\n * subtree and the bottom row of nodes for further processing.\n *\n * @typedef {object} TranscodedSubtree\n * @property {Cesium3DTile} rootTile The transcoded root tile of the subtree\n * @property {Array} bottomRow The bottom row of transcoded tiles. This is helpful for processing child subtrees\n * @private\n */\n\n/**\n * Transcode the implicitly-defined tiles within this subtree and generate\n * explicit {@link Cesium3DTile} objects. This function only transcode tiles,\n * child subtrees are handled separately.\n *\n * @param {Implicit3DTileContent} content The implicit content\n * @param {ImplicitSubtree} subtree The subtree to get availability information\n * @param {Cesium3DTile} placeholderTile The placeholder tile, used for constructing the subtree root tile\n * @param {number} childIndex The Morton index of the root tile relative to parentOfRootTile\n * @returns {TranscodedSubtree} The newly created subtree of tiles\n * @private\n */\nfunction transcodeSubtreeTiles(content, subtree, placeholderTile, childIndex) {\n const rootBitIndex = 0;\n const rootParentIsPlaceholder = true;\n const rootTile = deriveChildTile(\n content,\n subtree,\n placeholderTile,\n childIndex,\n rootBitIndex,\n rootParentIsPlaceholder\n );\n\n const statistics = content._tileset.statistics;\n\n // Sliding window over the levels of the tree.\n // Each row is branchingFactor * length of previous row\n // Tiles within a row are ordered by Morton index.\n let parentRow = [rootTile];\n let currentRow = [];\n\n const implicitTileset = content._implicitTileset;\n for (let level = 1; level < implicitTileset.subtreeLevels; level++) {\n const levelOffset = subtree.getLevelOffset(level);\n const numberOfChildren = implicitTileset.branchingFactor * parentRow.length;\n for (\n let childMortonIndex = 0;\n childMortonIndex < numberOfChildren;\n childMortonIndex++\n ) {\n const childBitIndex = levelOffset + childMortonIndex;\n\n if (!subtree.tileIsAvailableAtIndex(childBitIndex)) {\n currentRow.push(undefined);\n continue;\n }\n\n const parentMortonIndex = subtree.getParentMortonIndex(childMortonIndex);\n const parentTile = parentRow[parentMortonIndex];\n const childChildIndex =\n childMortonIndex % implicitTileset.branchingFactor;\n const childTile = deriveChildTile(\n content,\n subtree,\n parentTile,\n childChildIndex,\n childBitIndex\n );\n parentTile.children.push(childTile);\n statistics.numberOfTilesTotal++;\n currentRow.push(childTile);\n }\n\n parentRow = currentRow;\n currentRow = [];\n }\n\n return {\n rootTile: rootTile,\n // At the end of the last loop, bottomRow was moved to parentRow\n bottomRow: parentRow,\n };\n}\n\nfunction getGeometricError(tileMetadata, implicitTileset, implicitCoordinates) {\n const semantic = MetadataSemantic.TILE_GEOMETRIC_ERROR;\n\n if (defined(tileMetadata) && tileMetadata.hasPropertyBySemantic(semantic)) {\n return tileMetadata.getPropertyBySemantic(semantic);\n }\n\n return (\n implicitTileset.geometricError / Math.pow(2, implicitCoordinates.level)\n );\n}\n\n/**\n * Given a parent tile and information about which child to create, derive\n * the properties of the child tile implicitly.\n *

\n * This creates a real tile for rendering, not a placeholder tile like some of\n * the other methods of ImplicitTileset.\n *

\n *\n * @param {Implicit3DTileContent} implicitContent The implicit content\n * @param {ImplicitSubtree} subtree The subtree the child tile belongs to\n * @param {Cesium3DTile} parentTile The parent of the new child tile\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @param {number} childBitIndex The index of the child tile within the tile's availability information.\n * @param {boolean} [parentIsPlaceholderTile=false] True if parentTile is a placeholder tile. This is true for the root of each subtree.\n * @returns {Cesium3DTile} The new child tile.\n * @private\n */\nfunction deriveChildTile(\n implicitContent,\n subtree,\n parentTile,\n childIndex,\n childBitIndex,\n parentIsPlaceholderTile\n) {\n const implicitTileset = implicitContent._implicitTileset;\n let implicitCoordinates;\n if (defaultValue(parentIsPlaceholderTile, false)) {\n implicitCoordinates = parentTile.implicitCoordinates;\n } else {\n implicitCoordinates = parentTile.implicitCoordinates.getChildCoordinates(\n childIndex\n );\n }\n\n // Parse metadata and bounding volume semantics at the beginning\n // as the bounding volumes are needed below.\n let tileMetadata;\n let tileBounds;\n let contentBounds;\n if (defined(subtree.tilePropertyTableJson)) {\n tileMetadata = subtree.getTileMetadataView(implicitCoordinates);\n\n const boundingVolumeSemantics = BoundingVolumeSemantics.parseAllBoundingVolumeSemantics(\n tileMetadata\n );\n tileBounds = boundingVolumeSemantics.tile;\n contentBounds = boundingVolumeSemantics.content;\n }\n\n // Content is not loaded at this point, so this flag is set for future reference.\n const contentPropertyTableJsons = subtree.contentPropertyTableJsons;\n const length = contentPropertyTableJsons.length;\n let hasImplicitContentMetadata = false;\n for (let i = 0; i < length; i++) {\n if (subtree.contentIsAvailableAtCoordinates(implicitCoordinates, i)) {\n hasImplicitContentMetadata = true;\n break;\n }\n }\n\n const boundingVolume = getTileBoundingVolume(\n implicitTileset,\n implicitCoordinates,\n childIndex,\n parentIsPlaceholderTile,\n parentTile,\n tileBounds\n );\n\n const contentJsons = [];\n for (let i = 0; i < implicitTileset.contentCount; i++) {\n if (!subtree.contentIsAvailableAtIndex(childBitIndex, i)) {\n continue;\n }\n const childContentTemplate = implicitTileset.contentUriTemplates[i];\n const childContentUri = childContentTemplate.getDerivedResource({\n templateValues: implicitCoordinates.getTemplateValues(),\n }).url;\n const contentJson = {\n uri: childContentUri,\n };\n\n const contentBoundingVolume = getContentBoundingVolume(\n boundingVolume,\n contentBounds\n );\n\n if (defined(contentBoundingVolume)) {\n contentJson.boundingVolume = contentBoundingVolume;\n }\n\n // combine() is used to pass through any additional properties the\n // user specified such as extras or extensions\n contentJsons.push(combine(contentJson, implicitTileset.contentHeaders[i]));\n }\n\n const childGeometricError = getGeometricError(\n tileMetadata,\n implicitTileset,\n implicitCoordinates\n );\n\n const tileJson = {\n boundingVolume: boundingVolume,\n geometricError: childGeometricError,\n refine: implicitTileset.refine,\n contents: contentJsons,\n };\n\n // combine() is used to pass through any additional properties the\n // user specified such as extras or extensions.\n const deep = true;\n const rootHeader = clone(implicitTileset.tileHeader, deep);\n delete rootHeader.boundingVolume;\n delete rootHeader.transform;\n const combinedTileJson = combine(tileJson, rootHeader, deep);\n\n const childTile = makeTile(\n implicitContent,\n implicitTileset.baseResource,\n combinedTileJson,\n parentTile\n );\n\n childTile.implicitCoordinates = implicitCoordinates;\n childTile.implicitSubtree = subtree;\n childTile.metadata = tileMetadata;\n childTile.hasImplicitContentMetadata = hasImplicitContentMetadata;\n\n return childTile;\n}\n\n/**\n * Checks whether the bounding volume's heights can be updated.\n * Returns true if the minimumHeight/maximumHeight parameter\n * is defined and the bounding volume is a region or S2 cell.\n *\n * @param {object} [boundingVolume] The bounding volume\n * @param {object} [tileBounds] The tile bounds\n * @param {number} [tileBounds.minimumHeight] The minimum height\n * @param {number} [tileBounds.maximumHeight] The maximum height\n * @returns {boolean} Whether the bounding volume's heights can be updated\n * @private\n */\nfunction canUpdateHeights(boundingVolume, tileBounds) {\n return (\n defined(boundingVolume) &&\n defined(tileBounds) &&\n (defined(tileBounds.minimumHeight) || defined(tileBounds.maximumHeight)) &&\n (hasExtension(boundingVolume, \"3DTILES_bounding_volume_S2\") ||\n defined(boundingVolume.region))\n );\n}\n\n/**\n * Update the minimum and maximum height of the bounding volume.\n * This is typically used to tighten a bounding volume using the\n * TILE_MINIMUM_HEIGHT and TILE_MAXIMUM_HEIGHT\n * semantics. Heights are only updated if the respective\n * minimumHeight/maximumHeight parameter is defined and the\n * bounding volume is a region or S2 cell.\n *\n * @param {object} boundingVolume The bounding volume\n * @param {object} [tileBounds] The tile bounds\n * @param {number} [tileBounds.minimumHeight] The new minimum height\n * @param {number} [tileBounds.maximumHeight] The new maximum height\n * @private\n */\nfunction updateHeights(boundingVolume, tileBounds) {\n if (!defined(tileBounds)) {\n return;\n }\n\n if (hasExtension(boundingVolume, \"3DTILES_bounding_volume_S2\")) {\n updateS2CellHeights(\n boundingVolume.extensions[\"3DTILES_bounding_volume_S2\"],\n tileBounds.minimumHeight,\n tileBounds.maximumHeight\n );\n } else if (defined(boundingVolume.region)) {\n updateRegionHeights(\n boundingVolume.region,\n tileBounds.minimumHeight,\n tileBounds.maximumHeight\n );\n }\n}\n\n/**\n * For a bounding region, update the minimum and maximum height. This\n * is typically used to tighten a bounding volume using the\n * TILE_MINIMUM_HEIGHT and TILE_MAXIMUM_HEIGHT\n * semantics. Heights are only updated if the respective\n * minimumHeight/maximumHeight parameter is defined.\n *\n * @param {Array} region A 6-element array describing the bounding region\n * @param {number} [minimumHeight] The new minimum height\n * @param {number} [maximumHeight] The new maximum height\n * @private\n */\nfunction updateRegionHeights(region, minimumHeight, maximumHeight) {\n if (defined(minimumHeight)) {\n region[4] = minimumHeight;\n }\n\n if (defined(maximumHeight)) {\n region[5] = maximumHeight;\n }\n}\n\n/**\n * For a bounding S2 cell, update the minimum and maximum height. This\n * is typically used to tighten a bounding volume using the\n * TILE_MINIMUM_HEIGHT and TILE_MAXIMUM_HEIGHT\n * semantics. Heights are only updated if the respective\n * minimumHeight/maximumHeight parameter is defined.\n *\n * @param {object} s2CellVolume An object describing the S2 cell\n * @param {number} [minimumHeight] The new minimum height\n * @param {number} [maximumHeight] The new maximum height\n * @private\n */\nfunction updateS2CellHeights(s2CellVolume, minimumHeight, maximumHeight) {\n if (defined(minimumHeight)) {\n s2CellVolume.minimumHeight = minimumHeight;\n }\n\n if (defined(maximumHeight)) {\n s2CellVolume.maximumHeight = maximumHeight;\n }\n}\n\n/**\n * Gets the tile's bounding volume, which may be specified via\n * metadata semantics such as TILE_BOUNDING_BOX or implicitly\n * derived from the implicit root tile's bounding volume.\n *

\n * Priority of bounding volume types:\n *

    \n *
  1. Explicit min/max height\n *
      \n *
    1. With explicit region
    2. \n *
    3. With implicit S2
    4. \n *
    5. With implicit region
    6. \n *
    \n *
  2. \n *
  3. Explicit box
  4. \n *
  5. Explicit region
  6. \n *
  7. Explicit sphere
  8. \n *
  9. Implicit S2
  10. \n *
  11. Implicit box
  12. \n *
  13. Implicit region
  14. \n *
\n *

\n *\n * @param {ImplicitTileset} implicitTileset The implicit tileset struct which holds the root bounding volume\n * @param {ImplicitTileCoordinates} implicitCoordinates The coordinates of the child tile\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @param {boolean} parentIsPlaceholderTile True if parentTile is a placeholder tile. This is true for the root of each subtree.\n * @param {Cesium3DTile} parentTile The parent of the new child tile\n * @param {object} [tileBounds] The tile bounds\n * @returns {object} An object containing the JSON for a bounding volume\n * @private\n */\nfunction getTileBoundingVolume(\n implicitTileset,\n implicitCoordinates,\n childIndex,\n parentIsPlaceholderTile,\n parentTile,\n tileBounds\n) {\n let boundingVolume;\n\n if (\n !defined(tileBounds) ||\n !defined(tileBounds.boundingVolume) ||\n (!canUpdateHeights(tileBounds.boundingVolume, tileBounds) &&\n canUpdateHeights(implicitTileset.boundingVolume, tileBounds))\n ) {\n boundingVolume = deriveBoundingVolume(\n implicitTileset,\n implicitCoordinates,\n childIndex,\n defaultValue(parentIsPlaceholderTile, false),\n parentTile\n );\n } else {\n boundingVolume = tileBounds.boundingVolume;\n }\n\n // The TILE_MINIMUM_HEIGHT and TILE_MAXIMUM_HEIGHT metadata semantics\n // can be used to tighten the bounding volume\n updateHeights(boundingVolume, tileBounds);\n\n return boundingVolume;\n}\n\n/**\n * Gets the content bounding volume, which may be specified via\n * metadata semantics such as CONTENT_BOUNDING_BOX.\n *

\n * Priority of bounding volume types:\n *

    \n *
  1. Explicit min/max height\n *
      \n *
    1. With explicit region
    2. \n *
    3. With tile bounding volume (S2 or region)
    4. \n *
    \n *
  2. \n *
  3. Explicit box
  4. \n *
  5. Explicit region
  6. \n *
  7. Explicit sphere
  8. \n *
  9. Tile bounding volume (when content.boundingVolume is undefined)
  10. \n *
\n *

\n *\n * @param {object} tileBoundingVolume An object containing the JSON for the tile's bounding volume\n * @param {object} [contentBounds] The content bounds\n * @returns {object|undefined} An object containing the JSON for a bounding volume, or undefined if there is no bounding volume\n * @private\n */\nfunction getContentBoundingVolume(tileBoundingVolume, contentBounds) {\n // content bounding volumes can only be specified via\n // metadata semantics such as CONTENT_BOUNDING_BOX\n let contentBoundingVolume;\n if (defined(contentBounds)) {\n contentBoundingVolume = contentBounds.boundingVolume;\n }\n\n // The CONTENT_MINIMUM_HEIGHT and CONTENT_MAXIMUM_HEIGHT metadata semantics\n // can be used to tighten the bounding volume\n if (canUpdateHeights(contentBoundingVolume, contentBounds)) {\n updateHeights(contentBoundingVolume, contentBounds);\n } else if (canUpdateHeights(tileBoundingVolume, contentBounds)) {\n contentBoundingVolume = clone(tileBoundingVolume, true);\n updateHeights(contentBoundingVolume, contentBounds);\n }\n\n return contentBoundingVolume;\n}\n\n/**\n * Given the coordinates of a tile, derive its bounding volume from the root.\n *\n * @param {ImplicitTileset} implicitTileset The implicit tileset struct which holds the root bounding volume\n * @param {ImplicitTileCoordinates} implicitCoordinates The coordinates of the child tile\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @param {boolean} parentIsPlaceholderTile True if parentTile is a placeholder tile. This is true for the root of each subtree.\n * @param {Cesium3DTile} parentTile The parent of the new child tile\n * @returns {object} An object containing the JSON for a bounding volume\n * @private\n */\nfunction deriveBoundingVolume(\n implicitTileset,\n implicitCoordinates,\n childIndex,\n parentIsPlaceholderTile,\n parentTile\n) {\n const rootBoundingVolume = implicitTileset.boundingVolume;\n\n if (hasExtension(rootBoundingVolume, \"3DTILES_bounding_volume_S2\")) {\n return deriveBoundingVolumeS2(\n parentIsPlaceholderTile,\n parentTile,\n childIndex,\n implicitCoordinates.level,\n implicitCoordinates.x,\n implicitCoordinates.y,\n implicitCoordinates.z\n );\n }\n\n if (defined(rootBoundingVolume.region)) {\n const childRegion = deriveBoundingRegion(\n rootBoundingVolume.region,\n implicitCoordinates.level,\n implicitCoordinates.x,\n implicitCoordinates.y,\n implicitCoordinates.z\n );\n\n return {\n region: childRegion,\n };\n }\n\n const childBox = deriveBoundingBox(\n rootBoundingVolume.box,\n implicitCoordinates.level,\n implicitCoordinates.x,\n implicitCoordinates.y,\n implicitCoordinates.z\n );\n\n return {\n box: childBox,\n };\n}\n\n/**\n * Derive a bounding volume for a descendant tile (child, grandchild, etc.),\n * assuming a quadtree or octree implicit tiling scheme. The (level, x, y, [z])\n * coordinates are given to select the descendant tile and compute its position\n * and dimensions.\n *

\n * If z is present, octree subdivision is used. Otherwise, quadtree subdivision\n * is used. Quadtrees are always divided at the midpoint of the the horizontal\n * dimensions, i.e. (x, y), leaving the z axis unchanged.\n *

\n *\n * @param {boolean} parentIsPlaceholderTile True if parentTile is a placeholder tile. This is true for the root of each subtree.\n * @param {Cesium3DTile} parentTile The parent of the new child tile\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @param {number} level The level of the descendant tile relative to the root implicit tile\n * @param {number} x The x coordinate of the descendant tile\n * @param {number} y The y coordinate of the descendant tile\n * @param {number} [z] The z coordinate of the descendant tile (octree only)\n * @returns {object} An object with the 3DTILES_bounding_volume_S2 extension.\n * @private\n */\nfunction deriveBoundingVolumeS2(\n parentIsPlaceholderTile,\n parentTile,\n childIndex,\n level,\n x,\n y,\n z\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"parentIsPlaceholderTile\", parentIsPlaceholderTile);\n Check.typeOf.object(\"parentTile\", parentTile);\n Check.typeOf.number(\"childIndex\", childIndex);\n Check.typeOf.number(\"level\", level);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n if (defined(z)) {\n Check.typeOf.number(\"z\", z);\n }\n //>>includeEnd('debug');\n\n const boundingVolumeS2 = parentTile._boundingVolume;\n\n // Handle the placeholder tile case, where we just duplicate the placeholder's bounding volume.\n if (parentIsPlaceholderTile) {\n return {\n extensions: {\n \"3DTILES_bounding_volume_S2\": {\n token: S2Cell.getTokenFromId(boundingVolumeS2.s2Cell._cellId),\n minimumHeight: boundingVolumeS2.minimumHeight,\n maximumHeight: boundingVolumeS2.maximumHeight,\n },\n },\n };\n }\n\n // Extract the first 3 face bits from the 64-bit S2 cell ID.\n // eslint-disable-next-line no-undef\n const face = Number(parentTile._boundingVolume.s2Cell._cellId >> BigInt(61));\n // The Hilbert curve is rotated for the \"odd\" faces on the S2 Earthcube.\n // See http://s2geometry.io/devguide/img/s2cell_global.jpg\n const position =\n face % 2 === 0\n ? HilbertOrder.encode2D(level, x, y)\n : HilbertOrder.encode2D(level, y, x);\n // eslint-disable-next-line no-undef\n const cell = S2Cell.fromFacePositionLevel(face, BigInt(position), level);\n\n let minHeight, maxHeight;\n if (defined(z)) {\n const midpointHeight =\n (boundingVolumeS2.maximumHeight + boundingVolumeS2.minimumHeight) / 2;\n minHeight =\n childIndex < 4 ? boundingVolumeS2.minimumHeight : midpointHeight;\n maxHeight =\n childIndex < 4 ? midpointHeight : boundingVolumeS2.maximumHeight;\n } else {\n minHeight = boundingVolumeS2.minimumHeight;\n maxHeight = boundingVolumeS2.maximumHeight;\n }\n\n return {\n extensions: {\n \"3DTILES_bounding_volume_S2\": {\n token: S2Cell.getTokenFromId(cell._cellId),\n minimumHeight: minHeight,\n maximumHeight: maxHeight,\n },\n },\n };\n}\n\nconst scratchScaleFactors = new Cartesian3();\nconst scratchRootCenter = new Cartesian3();\nconst scratchCenter = new Cartesian3();\nconst scratchHalfAxes = new Matrix3();\n/**\n * Derive a bounding volume for a descendant tile (child, grandchild, etc.),\n * assuming a quadtree or octree implicit tiling scheme. The (level, x, y, [z])\n * coordinates are given to select the descendant tile and compute its position\n * and dimensions.\n *

\n * If z is present, octree subdivision is used. Otherwise, quadtree subdivision\n * is used. Quadtrees are always divided at the midpoint of the the horizontal\n * dimensions, i.e. (x, y), leaving the z axis unchanged.\n *

\n *

\n * This computes the child volume directly from the root bounding volume rather\n * than recursively subdividing to minimize floating point error.\n *

\n *\n * @param {number[]} rootBox An array of 12 numbers representing the bounding box of the root tile\n * @param {number} level The level of the descendant tile relative to the root implicit tile\n * @param {number} x The x coordinate of the descendant tile\n * @param {number} y The y coordinate of the descendant tile\n * @param {number} [z] The z coordinate of the descendant tile (octree only)\n * @returns {number[]} An array of 12 numbers representing the bounding box of the descendant tile.\n * @private\n */\nfunction deriveBoundingBox(rootBox, level, x, y, z) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rootBox\", rootBox);\n Check.typeOf.number(\"level\", level);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n if (defined(z)) {\n Check.typeOf.number(\"z\", z);\n }\n //>>includeEnd('debug');\n\n if (level === 0) {\n return rootBox;\n }\n\n const rootCenter = Cartesian3.unpack(rootBox, 0, scratchRootCenter);\n const rootHalfAxes = Matrix3.unpack(rootBox, 3, scratchHalfAxes);\n\n const tileScale = Math.pow(2, -level);\n const modelSpaceX = -1 + (2 * x + 1) * tileScale;\n const modelSpaceY = -1 + (2 * y + 1) * tileScale;\n\n let modelSpaceZ = 0;\n const scaleFactors = Cartesian3.fromElements(\n tileScale,\n tileScale,\n 1,\n scratchScaleFactors\n );\n\n if (defined(z)) {\n modelSpaceZ = -1 + (2 * z + 1) * tileScale;\n scaleFactors.z = tileScale;\n }\n\n let center = Cartesian3.fromElements(\n modelSpaceX,\n modelSpaceY,\n modelSpaceZ,\n scratchCenter\n );\n center = Matrix3.multiplyByVector(rootHalfAxes, center, scratchCenter);\n center = Cartesian3.add(center, rootCenter, scratchCenter);\n\n let halfAxes = Matrix3.clone(rootHalfAxes);\n halfAxes = Matrix3.multiplyByScale(halfAxes, scaleFactors, halfAxes);\n\n const childBox = new Array(12);\n Cartesian3.pack(center, childBox);\n Matrix3.pack(halfAxes, childBox, 3);\n return childBox;\n}\n\nconst scratchRectangle = new Rectangle();\n/**\n * Derive a bounding volume for a descendant tile (child, grandchild, etc.),\n * assuming a quadtree or octree implicit tiling scheme. The (level, x, y, [z])\n * coordinates are given to select the descendant tile and compute its position\n * and dimensions.\n *

\n * If z is present, octree subdivision is used. Otherwise, quadtree subdivision\n * is used. Quadtrees are always divided at the midpoint of the the horizontal\n * dimensions, i.e. (mid_longitude, mid_latitude), leaving the height values\n * unchanged.\n *

\n *

\n * This computes the child volume directly from the root bounding volume rather\n * than recursively subdividing to minimize floating point error.\n *

\n * @param {number[]} rootRegion An array of 6 numbers representing the root implicit tile\n * @param {number} level The level of the descendant tile relative to the root implicit tile\n * @param {number} x The x coordinate of the descendant tile\n * @param {number} y The x coordinate of the descendant tile\n * @param {number} [z] The z coordinate of the descendant tile (octree only)\n * @returns {number[]} An array of 6 numbers representing the bounding region of the descendant tile\n * @private\n */\nfunction deriveBoundingRegion(rootRegion, level, x, y, z) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rootRegion\", rootRegion);\n Check.typeOf.number(\"level\", level);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n if (defined(z)) {\n Check.typeOf.number(\"z\", z);\n }\n //>>includeEnd('debug');\n\n if (level === 0) {\n return rootRegion.slice();\n }\n\n const rectangle = Rectangle.unpack(rootRegion, 0, scratchRectangle);\n const rootMinimumHeight = rootRegion[4];\n const rootMaximumHeight = rootRegion[5];\n const tileScale = Math.pow(2, -level);\n\n const childWidth = tileScale * rectangle.width;\n const west = CesiumMath.negativePiToPi(rectangle.west + x * childWidth);\n const east = CesiumMath.negativePiToPi(west + childWidth);\n\n const childHeight = tileScale * rectangle.height;\n const south = CesiumMath.negativePiToPi(rectangle.south + y * childHeight);\n const north = CesiumMath.negativePiToPi(south + childHeight);\n\n // Height is only subdivided for octrees; It remains constant for quadtrees.\n let minimumHeight = rootMinimumHeight;\n let maximumHeight = rootMaximumHeight;\n if (defined(z)) {\n const childThickness = tileScale * (rootMaximumHeight - rootMinimumHeight);\n minimumHeight += z * childThickness;\n maximumHeight = minimumHeight + childThickness;\n }\n\n return [west, south, east, north, minimumHeight, maximumHeight];\n}\n\n/**\n * Create a placeholder 3D Tile whose content will be an Implicit3DTileContent\n * for lazy evaluation of a child subtree.\n *\n * @param {Implicit3DTileContent} content The content object.\n * @param {Cesium3DTile} parentTile The parent of the new child subtree.\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @returns {Cesium3DTile} The new placeholder tile\n * @private\n */\nfunction makePlaceholderChildSubtree(content, parentTile, childIndex) {\n const implicitTileset = content._implicitTileset;\n const implicitCoordinates = parentTile.implicitCoordinates.getChildCoordinates(\n childIndex\n );\n\n const childBoundingVolume = deriveBoundingVolume(\n implicitTileset,\n implicitCoordinates,\n childIndex,\n false,\n parentTile\n );\n\n // Ignore tile metadata when computing geometric error for the placeholder tile\n // since the child subtree's metadata hasn't been loaded yet.\n // The actual geometric error will be computed in deriveChildTile.\n const childGeometricError = getGeometricError(\n undefined,\n implicitTileset,\n implicitCoordinates\n );\n\n const childContentUri = implicitTileset.subtreeUriTemplate.getDerivedResource(\n {\n templateValues: implicitCoordinates.getTemplateValues(),\n }\n ).url;\n const tileJson = {\n boundingVolume: childBoundingVolume,\n geometricError: childGeometricError,\n refine: implicitTileset.refine,\n contents: [\n {\n uri: childContentUri,\n },\n ],\n };\n\n const tile = makeTile(\n content,\n implicitTileset.baseResource,\n tileJson,\n parentTile\n );\n tile.implicitTileset = implicitTileset;\n tile.implicitCoordinates = implicitCoordinates;\n return tile;\n}\n\n/**\n * Make a {@link Cesium3DTile}. This uses the content's tile's constructor instead\n * of importing Cesium3DTile. This is to avoid a circular dependency between\n * this file and Cesium3DTile.js\n * @param {Implicit3DTileContent} content The implicit content\n * @param {Resource} baseResource The base resource for the tileset\n * @param {object} tileJson The JSON header for the tile\n * @param {Cesium3DTile} parentTile The parent of the new tile\n * @returns {Cesium3DTile} The newly created tile.\n * @private\n */\nfunction makeTile(content, baseResource, tileJson, parentTile) {\n const Cesium3DTile = content._tile.constructor;\n return new Cesium3DTile(content._tileset, baseResource, tileJson, parentTile);\n}\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Implicit3DTileContent\n * always returns false since a tile of this type does not have any features.\n * @private\n */\nImplicit3DTileContent.prototype.hasProperty = function (batchId, name) {\n return false;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Implicit3DTileContent\n * always returns undefined since a tile of this type does not have any features.\n * @private\n */\nImplicit3DTileContent.prototype.getFeature = function (batchId) {\n return undefined;\n};\n\nImplicit3DTileContent.prototype.applyDebugSettings = function (\n enabled,\n color\n) {};\n\nImplicit3DTileContent.prototype.applyStyle = function (style) {};\n\nImplicit3DTileContent.prototype.update = function (tileset, frameState) {};\n\nImplicit3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nImplicit3DTileContent.prototype.destroy = function () {\n this._implicitSubtree =\n this._implicitSubtree && this._implicitSubtree.destroy();\n return destroyObject(this);\n};\n\n// Exposed for testing\nImplicit3DTileContent._deriveBoundingBox = deriveBoundingBox;\nImplicit3DTileContent._deriveBoundingRegion = deriveBoundingRegion;\nImplicit3DTileContent._deriveBoundingVolumeS2 = deriveBoundingVolumeS2;\n\nexport default Implicit3DTileContent;\n", "/**\n * Determines if and how a glTF animation is looped.\n *\n * @enum {number}\n *\n * @see ModelAnimationCollection#add\n */\nconst ModelAnimationLoop = {\n /**\n * Play the animation once; do not loop it.\n *\n * @type {number}\n * @constant\n */\n NONE: 0,\n\n /**\n * Loop the animation playing it from the start immediately after it stops.\n *\n * @type {number}\n * @constant\n */\n REPEAT: 1,\n\n /**\n * Loop the animation. First, playing it forward, then in reverse, then forward, and so on.\n *\n * @type {number}\n * @constant\n */\n MIRRORED_REPEAT: 2,\n};\nexport default Object.freeze(ModelAnimationLoop);\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * A Plane in Hessian Normal form to be used with {@link ClippingPlaneCollection}.\n * Compatible with mathematics functions in {@link Plane}\n *\n * @alias ClippingPlane\n * @constructor\n *\n * @param {Cartesian3} normal The plane's normal (normalized).\n * @param {number} distance The shortest distance from the origin to the plane. The sign of\n * distance determines which side of the plane the origin\n * is on. If distance is positive, the origin is in the half-space\n * in the direction of the normal; if negative, the origin is in the half-space\n * opposite to the normal; if zero, the plane passes through the origin.\n */\nfunction ClippingPlane(normal, distance) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"normal\", normal);\n Check.typeOf.number(\"distance\", distance);\n //>>includeEnd('debug');\n\n this._distance = distance;\n this._normal = new UpdateChangedCartesian3(normal, this);\n this.onChangeCallback = undefined;\n this.index = -1; // to be set by ClippingPlaneCollection\n}\n\nObject.defineProperties(ClippingPlane.prototype, {\n /**\n * The shortest distance from the origin to the plane. The sign of\n * distance determines which side of the plane the origin\n * is on. If distance is positive, the origin is in the half-space\n * in the direction of the normal; if negative, the origin is in the half-space\n * opposite to the normal; if zero, the plane passes through the origin.\n *\n * @type {number}\n * @memberof ClippingPlane.prototype\n */\n distance: {\n get: function () {\n return this._distance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n if (defined(this.onChangeCallback) && value !== this._distance) {\n this.onChangeCallback(this.index);\n }\n this._distance = value;\n },\n },\n /**\n * The plane's normal.\n *\n * @type {Cartesian3}\n * @memberof ClippingPlane.prototype\n */\n normal: {\n get: function () {\n return this._normal;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n if (\n defined(this.onChangeCallback) &&\n !Cartesian3.equals(this._normal._cartesian3, value)\n ) {\n this.onChangeCallback(this.index);\n }\n // Set without firing callback again\n Cartesian3.clone(value, this._normal._cartesian3);\n },\n },\n});\n\n/**\n * Create a ClippingPlane from a Plane object.\n *\n * @param {Plane} plane The plane containing parameters to copy\n * @param {ClippingPlane} [result] The object on which to store the result\n * @returns {ClippingPlane} The ClippingPlane generated from the plane's parameters.\n */\nClippingPlane.fromPlane = function (plane, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"plane\", plane);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new ClippingPlane(plane.normal, plane.distance);\n } else {\n result.normal = plane.normal;\n result.distance = plane.distance;\n }\n return result;\n};\n\n/**\n * Clones the ClippingPlane without setting its ownership.\n * @param {ClippingPlane} clippingPlane The ClippingPlane to be cloned\n * @param {ClippingPlane} [result] The object on which to store the cloned parameters.\n * @returns {ClippingPlane} a clone of the input ClippingPlane\n */\nClippingPlane.clone = function (clippingPlane, result) {\n if (!defined(result)) {\n return new ClippingPlane(clippingPlane.normal, clippingPlane.distance);\n }\n result.normal = clippingPlane.normal;\n result.distance = clippingPlane.distance;\n return result;\n};\n\n/**\n * Wrapper on Cartesian3 that allows detection of Plane changes from \"members of members,\" for example:\n *\n * const clippingPlane = new ClippingPlane(...);\n * clippingPlane.normal.z = -1.0;\n *\n * @private\n */\nfunction UpdateChangedCartesian3(normal, clippingPlane) {\n this._clippingPlane = clippingPlane;\n this._cartesian3 = Cartesian3.clone(normal);\n}\n\nObject.defineProperties(UpdateChangedCartesian3.prototype, {\n x: {\n get: function () {\n return this._cartesian3.x;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n if (\n defined(this._clippingPlane.onChangeCallback) &&\n value !== this._cartesian3.x\n ) {\n this._clippingPlane.onChangeCallback(this._clippingPlane.index);\n }\n this._cartesian3.x = value;\n },\n },\n y: {\n get: function () {\n return this._cartesian3.y;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n if (\n defined(this._clippingPlane.onChangeCallback) &&\n value !== this._cartesian3.y\n ) {\n this._clippingPlane.onChangeCallback(this._clippingPlane.index);\n }\n this._cartesian3.y = value;\n },\n },\n z: {\n get: function () {\n return this._cartesian3.z;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n if (\n defined(this._clippingPlane.onChangeCallback) &&\n value !== this._cartesian3.z\n ) {\n this._clippingPlane.onChangeCallback(this._clippingPlane.index);\n }\n this._cartesian3.z = value;\n },\n },\n});\nexport default ClippingPlane;\n", "import AttributeCompression from \"../Core/AttributeCompression.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport Plane from \"../Core/Plane.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport PixelDatatype from \"../Renderer/PixelDatatype.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport Texture from \"../Renderer/Texture.js\";\nimport ClippingPlane from \"./ClippingPlane.js\";\n\n/**\n * Specifies a set of clipping planes. Clipping planes selectively disable rendering in a region on the\n * outside of the specified list of {@link ClippingPlane} objects for a single gltf model, 3D Tileset, or the globe.\n *

\n * In general the clipping planes' coordinates are relative to the object they're attached to, so a plane with distance set to 0 will clip\n * through the center of the object.\n *

\n *

\n * For 3D Tiles, the root tile's transform is used to position the clipping planes. If a transform is not defined, the root tile's {@link Cesium3DTile#boundingSphere} is used instead.\n *

\n *\n * @alias ClippingPlaneCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {ClippingPlane[]} [options.planes=[]] An array of {@link ClippingPlane} objects used to selectively disable rendering on the outside of each plane.\n * @param {boolean} [options.enabled=true] Determines whether the clipping planes are active.\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix specifying an additional transform relative to the clipping planes original coordinate system.\n * @param {boolean} [options.unionClippingRegions=false] If true, a region will be clipped if it is on the outside of any plane in the collection. Otherwise, a region will only be clipped if it is on the outside of every plane.\n * @param {Color} [options.edgeColor=Color.WHITE] The color applied to highlight the edge along which an object is clipped.\n * @param {number} [options.edgeWidth=0.0] The width, in pixels, of the highlight applied to the edge along which an object is clipped.\n *\n * @demo {@link https://sandcastle.cesium.com/?src=3D%20Tiles%20Clipping%20Planes.html|Clipping 3D Tiles and glTF models.}\n * @demo {@link https://sandcastle.cesium.com/?src=Terrain%20Clipping%20Planes.html|Clipping the Globe.}\n *\n * @example\n * // This clipping plane's distance is positive, which means its normal\n * // is facing the origin. This will clip everything that is behind\n * // the plane, which is anything with y coordinate < -5.\n * const clippingPlanes = new Cesium.ClippingPlaneCollection({\n * planes : [\n * new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1.0, 0.0), 5.0)\n * ],\n * });\n * // Create an entity and attach the ClippingPlaneCollection to the model.\n * const entity = viewer.entities.add({\n * position : Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 10000),\n * model : {\n * uri : 'model.gltf',\n * minimumPixelSize : 128,\n * maximumScale : 20000,\n * clippingPlanes : clippingPlanes\n * }\n * });\n * viewer.zoomTo(entity);\n */\nfunction ClippingPlaneCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._planes = [];\n\n // Do partial texture updates if just one plane is dirty.\n // If many planes are dirty, refresh the entire texture.\n this._dirtyIndex = -1;\n this._multipleDirtyPlanes = false;\n\n this._enabled = defaultValue(options.enabled, true);\n\n /**\n * The 4x4 transformation matrix specifying an additional transform relative to the clipping planes\n * original coordinate system.\n *\n * @type {Matrix4}\n * @default Matrix4.IDENTITY\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n\n /**\n * The color applied to highlight the edge along which an object is clipped.\n *\n * @type {Color}\n * @default Color.WHITE\n */\n this.edgeColor = Color.clone(defaultValue(options.edgeColor, Color.WHITE));\n\n /**\n * The width, in pixels, of the highlight applied to the edge along which an object is clipped.\n *\n * @type {number}\n * @default 0.0\n */\n this.edgeWidth = defaultValue(options.edgeWidth, 0.0);\n\n /**\n * An event triggered when a new clipping plane is added to the collection. Event handlers\n * are passed the new plane and the index at which it was added.\n * @type {Event}\n * @default Event()\n */\n this.planeAdded = new Event();\n\n /**\n * An event triggered when a new clipping plane is removed from the collection. Event handlers\n * are passed the new plane and the index from which it was removed.\n * @type {Event}\n * @default Event()\n */\n this.planeRemoved = new Event();\n\n // If this ClippingPlaneCollection has an owner, only its owner should update or destroy it.\n // This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection.\n this._owner = undefined;\n\n const unionClippingRegions = defaultValue(\n options.unionClippingRegions,\n false\n );\n this._unionClippingRegions = unionClippingRegions;\n this._testIntersection = unionClippingRegions\n ? unionIntersectFunction\n : defaultIntersectFunction;\n\n this._uint8View = undefined;\n this._float32View = undefined;\n\n this._clippingPlanesTexture = undefined;\n\n // Add each ClippingPlane object.\n const planes = options.planes;\n if (defined(planes)) {\n const planesLength = planes.length;\n for (let i = 0; i < planesLength; ++i) {\n this.add(planes[i]);\n }\n }\n}\n\nfunction unionIntersectFunction(value) {\n return value === Intersect.OUTSIDE;\n}\n\nfunction defaultIntersectFunction(value) {\n return value === Intersect.INSIDE;\n}\n\nObject.defineProperties(ClippingPlaneCollection.prototype, {\n /**\n * Returns the number of planes in this collection. This is commonly used with\n * {@link ClippingPlaneCollection#get} to iterate over all the planes\n * in the collection.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._planes.length;\n },\n },\n\n /**\n * If true, a region will be clipped if it is on the outside of any plane in the\n * collection. Otherwise, a region will only be clipped if it is on the\n * outside of every plane.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @type {boolean}\n * @default false\n */\n unionClippingRegions: {\n get: function () {\n return this._unionClippingRegions;\n },\n set: function (value) {\n if (this._unionClippingRegions === value) {\n return;\n }\n this._unionClippingRegions = value;\n this._testIntersection = value\n ? unionIntersectFunction\n : defaultIntersectFunction;\n },\n },\n\n /**\n * If true, clipping will be enabled.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @type {boolean}\n * @default true\n */\n enabled: {\n get: function () {\n return this._enabled;\n },\n set: function (value) {\n if (this._enabled === value) {\n return;\n }\n this._enabled = value;\n },\n },\n\n /**\n * Returns a texture containing packed, untransformed clipping planes.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @type {Texture}\n * @readonly\n * @private\n */\n texture: {\n get: function () {\n return this._clippingPlanesTexture;\n },\n },\n\n /**\n * A reference to the ClippingPlaneCollection's owner, if any.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @readonly\n * @private\n */\n owner: {\n get: function () {\n return this._owner;\n },\n },\n\n /**\n * Returns a Number encapsulating the state for this ClippingPlaneCollection.\n *\n * Clipping mode is encoded in the sign of the number, which is just the plane count.\n * If this value changes, then shader regeneration is necessary.\n *\n * @memberof ClippingPlaneCollection.prototype\n * @returns {number} A Number that describes the ClippingPlaneCollection's state.\n * @readonly\n * @private\n */\n clippingPlanesState: {\n get: function () {\n return this._unionClippingRegions\n ? this._planes.length\n : -this._planes.length;\n },\n },\n});\n\nfunction setIndexDirty(collection, index) {\n // If there's already a different _dirtyIndex set, more than one plane has changed since update.\n // Entire texture must be reloaded\n collection._multipleDirtyPlanes =\n collection._multipleDirtyPlanes ||\n (collection._dirtyIndex !== -1 && collection._dirtyIndex !== index);\n collection._dirtyIndex = index;\n}\n\n/**\n * Adds the specified {@link ClippingPlane} to the collection to be used to selectively disable rendering\n * on the outside of each plane. Use {@link ClippingPlaneCollection#unionClippingRegions} to modify\n * how modify the clipping behavior of multiple planes.\n *\n * @param {ClippingPlane} plane The ClippingPlane to add to the collection.\n *\n * @see ClippingPlaneCollection#unionClippingRegions\n * @see ClippingPlaneCollection#remove\n * @see ClippingPlaneCollection#removeAll\n */\nClippingPlaneCollection.prototype.add = function (plane) {\n const newPlaneIndex = this._planes.length;\n\n const that = this;\n plane.onChangeCallback = function (index) {\n setIndexDirty(that, index);\n };\n plane.index = newPlaneIndex;\n\n setIndexDirty(this, newPlaneIndex);\n this._planes.push(plane);\n this.planeAdded.raiseEvent(plane, newPlaneIndex);\n};\n\n/**\n * Returns the plane in the collection at the specified index. Indices are zero-based\n * and increase as planes are added. Removing a plane shifts all planes after\n * it to the left, changing their indices. This function is commonly used with\n * {@link ClippingPlaneCollection#length} to iterate over all the planes\n * in the collection.\n *\n * @param {number} index The zero-based index of the plane.\n * @returns {ClippingPlane} The ClippingPlane at the specified index.\n *\n * @see ClippingPlaneCollection#length\n */\nClippingPlaneCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n //>>includeEnd('debug');\n\n return this._planes[index];\n};\n\nfunction indexOf(planes, plane) {\n const length = planes.length;\n for (let i = 0; i < length; ++i) {\n if (Plane.equals(planes[i], plane)) {\n return i;\n }\n }\n\n return -1;\n}\n\n/**\n * Checks whether this collection contains a ClippingPlane equal to the given ClippingPlane.\n *\n * @param {ClippingPlane} [clippingPlane] The ClippingPlane to check for.\n * @returns {boolean} true if this collection contains the ClippingPlane, false otherwise.\n *\n * @see ClippingPlaneCollection#get\n */\nClippingPlaneCollection.prototype.contains = function (clippingPlane) {\n return indexOf(this._planes, clippingPlane) !== -1;\n};\n\n/**\n * Removes the first occurrence of the given ClippingPlane from the collection.\n *\n * @param {ClippingPlane} clippingPlane\n * @returns {boolean} true if the plane was removed; false if the plane was not found in the collection.\n *\n * @see ClippingPlaneCollection#add\n * @see ClippingPlaneCollection#contains\n * @see ClippingPlaneCollection#removeAll\n */\nClippingPlaneCollection.prototype.remove = function (clippingPlane) {\n const planes = this._planes;\n const index = indexOf(planes, clippingPlane);\n\n if (index === -1) {\n return false;\n }\n\n // Unlink this ClippingPlaneCollection from the ClippingPlane\n if (clippingPlane instanceof ClippingPlane) {\n clippingPlane.onChangeCallback = undefined;\n clippingPlane.index = -1;\n }\n\n // Shift and update indices\n const length = planes.length - 1;\n for (let i = index; i < length; ++i) {\n const planeToKeep = planes[i + 1];\n planes[i] = planeToKeep;\n if (planeToKeep instanceof ClippingPlane) {\n planeToKeep.index = i;\n }\n }\n\n // Indicate planes texture is dirty\n this._multipleDirtyPlanes = true;\n planes.length = length;\n\n this.planeRemoved.raiseEvent(clippingPlane, index);\n\n return true;\n};\n\n/**\n * Removes all planes from the collection.\n *\n * @see ClippingPlaneCollection#add\n * @see ClippingPlaneCollection#remove\n */\nClippingPlaneCollection.prototype.removeAll = function () {\n // Dereference this ClippingPlaneCollection from all ClippingPlanes\n const planes = this._planes;\n const planesCount = planes.length;\n for (let i = 0; i < planesCount; ++i) {\n const plane = planes[i];\n if (plane instanceof ClippingPlane) {\n plane.onChangeCallback = undefined;\n plane.index = -1;\n }\n this.planeRemoved.raiseEvent(plane, i);\n }\n this._multipleDirtyPlanes = true;\n this._planes = [];\n};\n\nconst distanceEncodeScratch = new Cartesian4();\nconst oct32EncodeScratch = new Cartesian4();\nfunction packPlanesAsUint8(clippingPlaneCollection, startIndex, endIndex) {\n const uint8View = clippingPlaneCollection._uint8View;\n const planes = clippingPlaneCollection._planes;\n let byteIndex = 0;\n for (let i = startIndex; i < endIndex; ++i) {\n const plane = planes[i];\n\n const oct32Normal = AttributeCompression.octEncodeToCartesian4(\n plane.normal,\n oct32EncodeScratch\n );\n uint8View[byteIndex] = oct32Normal.x;\n uint8View[byteIndex + 1] = oct32Normal.y;\n uint8View[byteIndex + 2] = oct32Normal.z;\n uint8View[byteIndex + 3] = oct32Normal.w;\n\n const encodedDistance = Cartesian4.packFloat(\n plane.distance,\n distanceEncodeScratch\n );\n uint8View[byteIndex + 4] = encodedDistance.x;\n uint8View[byteIndex + 5] = encodedDistance.y;\n uint8View[byteIndex + 6] = encodedDistance.z;\n uint8View[byteIndex + 7] = encodedDistance.w;\n\n byteIndex += 8;\n }\n}\n\n// Pack starting at the beginning of the buffer to allow partial update\nfunction packPlanesAsFloats(clippingPlaneCollection, startIndex, endIndex) {\n const float32View = clippingPlaneCollection._float32View;\n const planes = clippingPlaneCollection._planes;\n\n let floatIndex = 0;\n for (let i = startIndex; i < endIndex; ++i) {\n const plane = planes[i];\n const normal = plane.normal;\n\n float32View[floatIndex] = normal.x;\n float32View[floatIndex + 1] = normal.y;\n float32View[floatIndex + 2] = normal.z;\n float32View[floatIndex + 3] = plane.distance;\n\n floatIndex += 4; // each plane is 4 floats\n }\n}\n\nfunction computeTextureResolution(pixelsNeeded, result) {\n const maxSize = ContextLimits.maximumTextureSize;\n result.x = Math.min(pixelsNeeded, maxSize);\n result.y = Math.ceil(pixelsNeeded / result.x);\n return result;\n}\n\nconst textureResolutionScratch = new Cartesian2();\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * build the resources for clipping planes.\n *

\n * Do not call this function directly.\n *

\n */\nClippingPlaneCollection.prototype.update = function (frameState) {\n let clippingPlanesTexture = this._clippingPlanesTexture;\n const context = frameState.context;\n const useFloatTexture = ClippingPlaneCollection.useFloatTexture(context);\n\n // Compute texture requirements for current planes\n // In RGBA FLOAT, A plane is 4 floats packed to a RGBA.\n // In RGBA UNSIGNED_BYTE, A plane is a float in [0, 1) packed to RGBA and an Oct32 quantized normal,\n // so 8 bits or 2 pixels in RGBA.\n const pixelsNeeded = useFloatTexture ? this.length : this.length * 2;\n\n if (defined(clippingPlanesTexture)) {\n const currentPixelCount =\n clippingPlanesTexture.width * clippingPlanesTexture.height;\n // Recreate the texture to double current requirement if it isn't big enough or is 4 times larger than it needs to be.\n // Optimization note: this isn't exactly the classic resizeable array algorithm\n // * not necessarily checking for resize after each add/remove operation\n // * random-access deletes instead of just pops\n // * alloc ops likely more expensive than demonstrable via big-O analysis\n if (\n currentPixelCount < pixelsNeeded ||\n pixelsNeeded < 0.25 * currentPixelCount\n ) {\n clippingPlanesTexture.destroy();\n clippingPlanesTexture = undefined;\n this._clippingPlanesTexture = undefined;\n }\n }\n\n // If there are no clipping planes, there's nothing to update.\n if (this.length === 0) {\n return;\n }\n\n if (!defined(clippingPlanesTexture)) {\n const requiredResolution = computeTextureResolution(\n pixelsNeeded,\n textureResolutionScratch\n );\n // Allocate twice as much space as needed to avoid frequent texture reallocation.\n // Allocate in the Y direction, since texture may be as wide as context texture support.\n requiredResolution.y *= 2;\n\n if (useFloatTexture) {\n clippingPlanesTexture = new Texture({\n context: context,\n width: requiredResolution.x,\n height: requiredResolution.y,\n pixelFormat: PixelFormat.RGBA,\n pixelDatatype: PixelDatatype.FLOAT,\n sampler: Sampler.NEAREST,\n flipY: false,\n });\n this._float32View = new Float32Array(\n requiredResolution.x * requiredResolution.y * 4\n );\n } else {\n clippingPlanesTexture = new Texture({\n context: context,\n width: requiredResolution.x,\n height: requiredResolution.y,\n pixelFormat: PixelFormat.RGBA,\n pixelDatatype: PixelDatatype.UNSIGNED_BYTE,\n sampler: Sampler.NEAREST,\n flipY: false,\n });\n this._uint8View = new Uint8Array(\n requiredResolution.x * requiredResolution.y * 4\n );\n }\n\n this._clippingPlanesTexture = clippingPlanesTexture;\n this._multipleDirtyPlanes = true;\n }\n\n const dirtyIndex = this._dirtyIndex;\n if (!this._multipleDirtyPlanes && dirtyIndex === -1) {\n return;\n }\n if (!this._multipleDirtyPlanes) {\n // partial updates possible\n let offsetX = 0;\n let offsetY = 0;\n if (useFloatTexture) {\n offsetY = Math.floor(dirtyIndex / clippingPlanesTexture.width);\n offsetX = Math.floor(dirtyIndex - offsetY * clippingPlanesTexture.width);\n\n packPlanesAsFloats(this, dirtyIndex, dirtyIndex + 1);\n clippingPlanesTexture.copyFrom({\n source: {\n width: 1,\n height: 1,\n arrayBufferView: this._float32View,\n },\n xOffset: offsetX,\n yOffset: offsetY,\n });\n } else {\n offsetY = Math.floor((dirtyIndex * 2) / clippingPlanesTexture.width);\n offsetX = Math.floor(\n dirtyIndex * 2 - offsetY * clippingPlanesTexture.width\n );\n packPlanesAsUint8(this, dirtyIndex, dirtyIndex + 1);\n clippingPlanesTexture.copyFrom({\n source: {\n width: 2,\n height: 1,\n arrayBufferView: this._uint8View,\n },\n xOffset: offsetX,\n yOffset: offsetY,\n });\n }\n } else if (useFloatTexture) {\n packPlanesAsFloats(this, 0, this._planes.length);\n clippingPlanesTexture.copyFrom({\n source: {\n width: clippingPlanesTexture.width,\n height: clippingPlanesTexture.height,\n arrayBufferView: this._float32View,\n },\n });\n } else {\n packPlanesAsUint8(this, 0, this._planes.length);\n clippingPlanesTexture.copyFrom({\n source: {\n width: clippingPlanesTexture.width,\n height: clippingPlanesTexture.height,\n arrayBufferView: this._uint8View,\n },\n });\n }\n\n this._multipleDirtyPlanes = false;\n this._dirtyIndex = -1;\n};\n\nconst scratchMatrix = new Matrix4();\nconst scratchPlane = new Plane(Cartesian3.UNIT_X, 0.0);\n/**\n * Determines the type intersection with the planes of this ClippingPlaneCollection instance and the specified {@link TileBoundingVolume}.\n * @private\n *\n * @param {object} tileBoundingVolume The volume to determine the intersection with the planes.\n * @param {Matrix4} [transform] An optional, additional matrix to transform the plane to world coordinates.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire volume is on the side of the planes\n * the normal is pointing and should be entirely rendered, {@link Intersect.OUTSIDE}\n * if the entire volume is on the opposite side and should be clipped, and\n * {@link Intersect.INTERSECTING} if the volume intersects the planes.\n */\nClippingPlaneCollection.prototype.computeIntersectionWithBoundingVolume = function (\n tileBoundingVolume,\n transform\n) {\n const planes = this._planes;\n const length = planes.length;\n\n let modelMatrix = this.modelMatrix;\n if (defined(transform)) {\n modelMatrix = Matrix4.multiply(transform, modelMatrix, scratchMatrix);\n }\n\n // If the collection is not set to union the clipping regions, the volume must be outside of all planes to be\n // considered completely clipped. If the collection is set to union the clipping regions, if the volume can be\n // outside any the planes, it is considered completely clipped.\n // Lastly, if not completely clipped, if any plane is intersecting, more calculations must be performed.\n let intersection = Intersect.INSIDE;\n if (!this.unionClippingRegions && length > 0) {\n intersection = Intersect.OUTSIDE;\n }\n\n for (let i = 0; i < length; ++i) {\n const plane = planes[i];\n\n Plane.transform(plane, modelMatrix, scratchPlane); // ClippingPlane can be used for Plane math\n\n const value = tileBoundingVolume.intersectPlane(scratchPlane);\n if (value === Intersect.INTERSECTING) {\n intersection = value;\n } else if (this._testIntersection(value)) {\n return value;\n }\n }\n\n return intersection;\n};\n\n/**\n * Sets the owner for the input ClippingPlaneCollection if there wasn't another owner.\n * Destroys the owner's previous ClippingPlaneCollection if setting is successful.\n *\n * @param {ClippingPlaneCollection} [clippingPlaneCollection] A ClippingPlaneCollection (or undefined) being attached to an object\n * @param {object} owner An Object that should receive the new ClippingPlaneCollection\n * @param {string} key The Key for the Object to reference the ClippingPlaneCollection\n * @private\n */\nClippingPlaneCollection.setOwner = function (\n clippingPlaneCollection,\n owner,\n key\n) {\n // Don't destroy the ClippingPlaneCollection if it is already owned by newOwner\n if (clippingPlaneCollection === owner[key]) {\n return;\n }\n // Destroy the existing ClippingPlaneCollection, if any\n owner[key] = owner[key] && owner[key].destroy();\n if (defined(clippingPlaneCollection)) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(clippingPlaneCollection._owner)) {\n throw new DeveloperError(\n \"ClippingPlaneCollection should only be assigned to one object\"\n );\n }\n //>>includeEnd('debug');\n clippingPlaneCollection._owner = owner;\n owner[key] = clippingPlaneCollection;\n }\n};\n\n/**\n * Function for checking if the context will allow clipping planes with floating point textures.\n *\n * @param {Context} context The Context that will contain clipped objects and clipping textures.\n * @returns {boolean} true if floating point textures can be used for clipping planes.\n * @private\n */\nClippingPlaneCollection.useFloatTexture = function (context) {\n return context.floatingPointTexture;\n};\n\n/**\n * Function for getting the clipping plane collection's texture resolution.\n * If the ClippingPlaneCollection hasn't been updated, returns the resolution that will be\n * allocated based on the current plane count.\n *\n * @param {ClippingPlaneCollection} clippingPlaneCollection The clipping plane collection\n * @param {Context} context The rendering context\n * @param {Cartesian2} result A Cartesian2 for the result.\n * @returns {Cartesian2} The required resolution.\n * @private\n */\nClippingPlaneCollection.getTextureResolution = function (\n clippingPlaneCollection,\n context,\n result\n) {\n const texture = clippingPlaneCollection.texture;\n if (defined(texture)) {\n result.x = texture.width;\n result.y = texture.height;\n return result;\n }\n\n const pixelsNeeded = ClippingPlaneCollection.useFloatTexture(context)\n ? clippingPlaneCollection.length\n : clippingPlaneCollection.length * 2;\n const requiredResolution = computeTextureResolution(pixelsNeeded, result);\n\n // Allocate twice as much space as needed to avoid frequent texture reallocation.\n requiredResolution.y *= 2;\n return requiredResolution;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see ClippingPlaneCollection#destroy\n */\nClippingPlaneCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * clippingPlanes = clippingPlanes && clippingPlanes.destroy();\n *\n * @see ClippingPlaneCollection#isDestroyed\n */\nClippingPlaneCollection.prototype.destroy = function () {\n this._clippingPlanesTexture =\n this._clippingPlanesTexture && this._clippingPlanesTexture.destroy();\n return destroyObject(this);\n};\nexport default ClippingPlaneCollection;\n", "import CesiumMath from \"../Core/Math.js\";\n\n/**\n * Defines different modes for blending between a target color and a primitive's source color.\n *\n * HIGHLIGHT multiplies the source color by the target color\n * REPLACE replaces the source color with the target color\n * MIX blends the source color and target color together\n *\n * @enum {number}\n *\n * @see Model.colorBlendMode\n */\nconst ColorBlendMode = {\n HIGHLIGHT: 0,\n REPLACE: 1,\n MIX: 2,\n};\n\n/**\n * @private\n */\nColorBlendMode.getColorBlend = function (colorBlendMode, colorBlendAmount) {\n if (colorBlendMode === ColorBlendMode.HIGHLIGHT) {\n return 0.0;\n } else if (colorBlendMode === ColorBlendMode.REPLACE) {\n return 1.0;\n } else if (colorBlendMode === ColorBlendMode.MIX) {\n // The value 0.0 is reserved for highlight, so clamp to just above 0.0.\n return CesiumMath.clamp(colorBlendAmount, CesiumMath.EPSILON4, 1.0);\n }\n};\nexport default Object.freeze(ColorBlendMode);\n", "/**\n * An enum describing the type of motion that is defined by an articulation stage\n * in the AGI_articulations extension.\n *\n * @alias {ArticulationStageType}\n * @enum {string}\n *\n * @private\n */\nconst ArticulationStageType = {\n XTRANSLATE: \"xTranslate\",\n YTRANSLATE: \"yTranslate\",\n ZTRANSLATE: \"zTranslate\",\n XROTATE: \"xRotate\",\n YROTATE: \"yRotate\",\n ZROTATE: \"zRotate\",\n XSCALE: \"xScale\",\n YSCALE: \"yScale\",\n ZSCALE: \"zScale\",\n UNIFORMSCALE: \"uniformScale\",\n};\n\nexport default Object.freeze(ArticulationStageType);\n", "/**\n * An enum describing the type of interpolation used in a glTF animation.\n *\n * @enum {number}\n *\n * @private\n */\nconst InterpolationType = {\n STEP: 0,\n LINEAR: 1,\n CUBICSPLINE: 2,\n};\n\nexport default Object.freeze(InterpolationType);\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * A table for storing free-form JSON metadata, as in the 3D Tiles batch table.\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.count The number of entities in the table.\n * @param {Object} options.properties The JSON representation of the metadata table. All the arrays must have exactly options.count elements.\n *\n * @alias JsonMetadataTable\n * @constructor\n * @private\n */\n\n// An empty class is used because JsonMetadataTable is an older type of metadata table\n// that does not have a class definition.\nconst emptyClass = {};\n\nfunction JsonMetadataTable(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThan(\"options.count\", options.count, 0);\n Check.typeOf.object(\"options.properties\", options.properties);\n //>>includeEnd('debug');\n\n this._count = options.count;\n this._properties = clone(options.properties, true);\n}\n\n/**\n * Returns whether the table has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the table has this property.\n * @private\n */\nJsonMetadataTable.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, emptyClass);\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nJsonMetadataTable.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, emptyClass, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *\n * @param {number} index The index of the entity.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the entity does not have this property.\n *\n * @exception {DeveloperError} index is out of bounds\n * @private\n */\nJsonMetadataTable.prototype.getProperty = function (index, propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.string(\"propertyId\", propertyId);\n\n if (index < 0 || index >= this._count) {\n throw new DeveloperError(`index must be in the range [0, ${this._count})`);\n }\n //>>includeEnd('debug');\n\n const property = this._properties[propertyId];\n if (defined(property)) {\n return clone(property[index], true);\n }\n\n return undefined;\n};\n\n/**\n * Sets the value of the property with the given ID. If the property did not\n * exist, it will be created.\n *\n * @param {number} index The index of the entity.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n *\n * @exception {DeveloperError} index is out of bounds\n * @private\n */\nJsonMetadataTable.prototype.setProperty = function (index, propertyId, value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.string(\"propertyId\", propertyId);\n\n if (index < 0 || index >= this._count) {\n throw new DeveloperError(`index must be in the range [0, ${this._count})`);\n }\n //>>includeEnd('debug');\n\n let property = this._properties[propertyId];\n if (!defined(property)) {\n // Property does not exist. Create it.\n property = new Array(this._count);\n this._properties[propertyId] = property;\n }\n\n property[index] = clone(value, true);\n};\n\nexport default JsonMetadataTable;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport defined from \"../Core/defined.js\";\nimport JsonMetadataTable from \"./JsonMetadataTable.js\";\n\n/**\n * A property table for use with the EXT_structural_metadata extension or\n * legacy EXT_feature_metadata glTF extension. It also includes some\n * options to be compatible with the 3D Tiles 1.0 batch table.\n *

\n * For batch tables, properties are resolved in the following order:\n *

\n *
    \n *
  1. binary properties from options.metadataTable
  2. \n *
  3. JSON properties from options.jsonMetadataTable
  4. \n *
  5. batch table hierarchy properties from options.batchTableHierarchy
  6. \n *
\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the\n * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} [options.name] Human-readable name to describe the table\n * @param {string|number} [options.id] A unique id to identify the property table, useful for debugging. For EXT_structural_metadata, this is the array index in the property tables array, for EXT_feature_metadata this is the dictionary key in the property tables dictionary.\n * @param {number} options.count The number of features in the table.\n * @param {MetadataTable} [options.metadataTable] A table of binary properties.\n * @param {JsonMetadataTable} [options.jsonMetadataTable] For compatibility with the old batch table, free-form JSON properties can be passed in.\n * @param {BatchTableHierarchy} [options.batchTableHierarchy] For compatibility with the 3DTILES_batch_table_hierarchy extension, a hierarchy can be provided.\n * @param {object} [options.extras] Extra user-defined properties\n * @param {object} [options.extensions] An object containing extensions\n *\n * @alias PropertyTable\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction PropertyTable(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.count\", options.count);\n //>>includeEnd('debug');\n\n this._name = options.name;\n this._id = options.id;\n this._count = options.count;\n this._extras = options.extras;\n this._extensions = options.extensions;\n this._metadataTable = options.metadataTable;\n this._jsonMetadataTable = options.jsonMetadataTable;\n this._batchTableHierarchy = options.batchTableHierarchy;\n}\n\nObject.defineProperties(PropertyTable.prototype, {\n /**\n * A human-readable name for this table\n *\n * @memberof PropertyTable.prototype\n * @type {string}\n * @readonly\n * @private\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n /**\n * An identifier for this table. Useful for debugging.\n *\n * @memberof PropertyTable.prototype\n * @type {string|number}\n * @readonly\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * The number of features in the table.\n *\n * @memberof PropertyTable.prototype\n * @type {number}\n * @readonly\n * @private\n */\n count: {\n get: function () {\n return this._count;\n },\n },\n\n /**\n * The class that properties conform to.\n *\n * @memberof PropertyTable.prototype\n * @type {MetadataClass}\n * @readonly\n */\n class: {\n get: function () {\n if (defined(this._metadataTable)) {\n return this._metadataTable.class;\n }\n\n return undefined;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof PropertyTable.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof PropertyTable.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n\n /**\n * Get the total amount of binary metadata stored in memory. This does\n * not include JSON metadata\n *\n * @memberof PropertyTable.prototype\n * @type {number}\n * @readonly\n * @private\n */\n byteLength: {\n get: function () {\n let totalByteLength = 0;\n if (defined(this._metadataTable)) {\n totalByteLength += this._metadataTable.byteLength;\n }\n\n if (defined(this._batchTableHierarchy)) {\n totalByteLength += this._batchTableHierarchy.byteLength;\n }\n\n return totalByteLength;\n },\n },\n});\n\n/**\n * Returns whether the feature has this property. For compatibility with the 3DTILES_batch_table_hierarchy extension, this is computed for a specific feature.\n *\n * @param {number} index The index of the feature.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the feature has this property.\n * @private\n */\nPropertyTable.prototype.hasProperty = function (index, propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n if (\n defined(this._metadataTable) &&\n this._metadataTable.hasProperty(propertyId)\n ) {\n return true;\n }\n\n if (\n defined(this._batchTableHierarchy) &&\n this._batchTableHierarchy.hasProperty(index, propertyId)\n ) {\n return true;\n }\n\n if (\n defined(this._jsonMetadataTable) &&\n this._jsonMetadataTable.hasProperty(propertyId)\n ) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Returns whether the feature has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the feature has a property with the given semantic.\n * @private\n */\nPropertyTable.prototype.hasPropertyBySemantic = function (index, semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n if (defined(this._metadataTable)) {\n return this._metadataTable.hasPropertyBySemantic(semantic);\n }\n\n return false;\n};\n\n/**\n * Returns whether any feature has this property.\n * This is mainly useful for checking whether a property exists in the class\n * hierarchy when using the 3DTILES_batch_table_hierarchy extension.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether any feature has this property.\n * @private\n */\nPropertyTable.prototype.propertyExists = function (propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n if (\n defined(this._metadataTable) &&\n this._metadataTable.hasProperty(propertyId)\n ) {\n return true;\n }\n\n if (\n defined(this._batchTableHierarchy) &&\n this._batchTableHierarchy.propertyExists(propertyId)\n ) {\n return true;\n }\n\n if (\n defined(this._jsonMetadataTable) &&\n this._jsonMetadataTable.hasProperty(propertyId)\n ) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Returns whether any feature has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether any feature has a property with the given semantic.\n * @private\n */\nPropertyTable.prototype.propertyExistsBySemantic = function (semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n if (defined(this._metadataTable)) {\n return this._metadataTable.hasPropertyBySemantic(semantic);\n }\n\n return false;\n};\n\nconst scratchResults = [];\n\n/**\n * Returns an array of property IDs. For compatibility with the 3DTILES_batch_table_hierarchy extension, this is computed for a specific feature.\n *\n * @param {number} index The index of the feature.\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nPropertyTable.prototype.getPropertyIds = function (index, results) {\n results = defined(results) ? results : [];\n results.length = 0;\n\n if (defined(this._metadataTable)) {\n // concat in place to avoid unnecessary array allocation\n results.push.apply(\n results,\n this._metadataTable.getPropertyIds(scratchResults)\n );\n }\n\n if (defined(this._batchTableHierarchy)) {\n results.push.apply(\n results,\n this._batchTableHierarchy.getPropertyIds(index, scratchResults)\n );\n }\n\n if (defined(this._jsonMetadataTable)) {\n results.push.apply(\n results,\n this._jsonMetadataTable.getPropertyIds(scratchResults)\n );\n }\n\n return results;\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {number} index The index of the feature.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n * @private\n */\nPropertyTable.prototype.getProperty = function (index, propertyId) {\n let result;\n if (defined(this._metadataTable)) {\n result = this._metadataTable.getProperty(index, propertyId);\n if (defined(result)) {\n return result;\n }\n }\n\n if (defined(this._batchTableHierarchy)) {\n result = this._batchTableHierarchy.getProperty(index, propertyId);\n if (defined(result)) {\n return result;\n }\n }\n\n if (defined(this._jsonMetadataTable)) {\n result = this._jsonMetadataTable.getProperty(index, propertyId);\n if (defined(result)) {\n return result;\n }\n }\n\n return undefined;\n};\n\n/**\n * Sets the value of the property with the given ID. If the property did not\n * exist, it will be created as a JSON metadata property\n *\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {number} index The index of the feature.\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @private\n */\nPropertyTable.prototype.setProperty = function (index, propertyId, value) {\n if (\n defined(this._metadataTable) &&\n this._metadataTable.setProperty(index, propertyId, value)\n ) {\n return;\n }\n\n if (\n defined(this._batchTableHierarchy) &&\n this._batchTableHierarchy.setProperty(index, propertyId, value)\n ) {\n return;\n }\n\n // Ensure we have a table for JSON properties\n if (!defined(this._jsonMetadataTable)) {\n this._jsonMetadataTable = new JsonMetadataTable({\n count: this._count,\n properties: {},\n });\n }\n\n // JsonMetadataTable will handle creating a new property at runtime.\n this._jsonMetadataTable.setProperty(index, propertyId, value);\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *

\n * This only operates on the underlying {@link MetadataTable} (if present) as\n * {@link JsonMetadataTable} and {@link BatchTableHierarchy} do not have\n * semantics.\n *

\n *\n * @param {number} index The index of the feature.\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this semantic.\n * @private\n */\nPropertyTable.prototype.getPropertyBySemantic = function (index, semantic) {\n if (defined(this._metadataTable)) {\n return this._metadataTable.getPropertyBySemantic(index, semantic);\n }\n\n return undefined;\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *

\n * This only operates on the underlying {@link MetadataTable} (if present) as\n * {@link JsonMetadataTable} and {@link BatchTableHierarchy} do not have\n * semantics.\n *

\n *\n * @param {number} index The index of the feature.\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nPropertyTable.prototype.setPropertyBySemantic = function (\n index,\n semantic,\n value\n) {\n if (defined(this._metadataTable)) {\n return this._metadataTable.setPropertyBySemantic(index, semantic, value);\n }\n\n return false;\n};\n\n/**\n * Returns a typed array containing the property values for a given propertyId.\n *

\n * This only operates on the underlying {@link MetadataTable} (if present) as\n * {@link JsonMetadataTable} and {@link BatchTableHierarchy} do not store\n * values in typed arrays.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The typed array containing the property values or undefined if the property values are not stored in a typed array.\n *\n * @private\n */\nPropertyTable.prototype.getPropertyTypedArray = function (propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n if (defined(this._metadataTable)) {\n return this._metadataTable.getPropertyTypedArray(propertyId);\n }\n\n return undefined;\n};\n\n/**\n * Returns a typed array containing the property values for the property with the given semantic.\n *

\n * This only operates on the underlying {@link MetadataTable} (if present) as\n * {@link JsonMetadataTable} and {@link BatchTableHierarchy} do not have\n * semantics.\n *

\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The typed array containing the property values or undefined if the property values are not stored in a typed array.\n *\n * @private\n */\nPropertyTable.prototype.getPropertyTypedArrayBySemantic = function (semantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"semantic\", semantic);\n //>>includeEnd('debug');\n\n if (defined(this._metadataTable)) {\n return this._metadataTable.getPropertyTypedArrayBySemantic(semantic);\n }\n\n return undefined;\n};\n\nfunction checkFeatureId(featureId, featuresLength) {\n if (!defined(featureId) || featureId < 0 || featureId >= featuresLength) {\n throw new DeveloperError(\n `featureId is required and must be between zero and featuresLength - 1 (${featuresLength}` -\n +\").\"\n );\n }\n}\n\nPropertyTable.prototype.isClass = function (featureId, className) {\n //>>includeStart('debug', pragmas.debug);\n checkFeatureId(featureId, this.count);\n Check.typeOf.string(\"className\", className);\n //>>includeEnd('debug');\n\n const hierarchy = this._batchTableHierarchy;\n if (!defined(hierarchy)) {\n return false;\n }\n\n return hierarchy.isClass(featureId, className);\n};\n\nPropertyTable.prototype.isExactClass = function (featureId, className) {\n //>>includeStart('debug', pragmas.debug);\n checkFeatureId(featureId, this.count);\n Check.typeOf.string(\"className\", className);\n //>>includeEnd('debug');\n\n return this.getExactClassName(featureId) === className;\n};\n\nPropertyTable.prototype.getExactClassName = function (featureId) {\n //>>includeStart('debug', pragmas.debug);\n checkFeatureId(featureId, this.count);\n //>>includeEnd('debug');\n\n const hierarchy = this._batchTableHierarchy;\n if (!defined(hierarchy)) {\n return undefined;\n }\n\n return hierarchy.getClassName(featureId);\n};\n\nexport default PropertyTable;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport GltfLoaderUtil from \"./GltfLoaderUtil.js\";\nimport MetadataType from \"./MetadataType.js\";\nimport MetadataComponentType from \"./MetadataComponentType.js\";\n\n/**\n * A property in a property texture.\n *\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the\n * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.property The property JSON object.\n * @param {MetadataClassProperty} options.classProperty The class property.\n * @param {Object} options.textures An object mapping texture IDs to {@link Texture} objects.\n *\n * @alias PropertyTextureProperty\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction PropertyTextureProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const property = options.property;\n const classProperty = options.classProperty;\n const textures = options.textures;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.property\", property);\n Check.typeOf.object(\"options.classProperty\", classProperty);\n Check.typeOf.object(\"options.textures\", textures);\n //>>includeEnd('debug');\n\n // in EXT_structural_metadata, the property is a valid glTF textureInfo\n const channels = defined(property.channels) ? property.channels : [0];\n const textureInfo = property;\n const textureReader = GltfLoaderUtil.createModelTextureReader({\n textureInfo: textureInfo,\n channels: reformatChannels(channels),\n texture: textures[textureInfo.index],\n });\n\n this._min = property.min;\n this._max = property.max;\n\n let offset = property.offset;\n let scale = property.scale;\n\n // This needs to be set before handling default values\n const hasValueTransform =\n classProperty.hasValueTransform || defined(offset) || defined(scale);\n\n // If the property attribute does not define an offset/scale, it inherits from\n // the class property. The class property handles setting the default of\n // identity: (offset 0, scale 1) with the same scalar/vector/matrix types.\n // array types are disallowed by the spec.\n offset = defaultValue(offset, classProperty.offset);\n scale = defaultValue(scale, classProperty.scale);\n\n // offset and scale are applied on the GPU, so unpack the values\n // as math types we can use in uniform callbacks.\n offset = classProperty.unpackVectorAndMatrixTypes(offset);\n scale = classProperty.unpackVectorAndMatrixTypes(scale);\n\n this._offset = offset;\n this._scale = scale;\n this._hasValueTransform = hasValueTransform;\n\n this._textureReader = textureReader;\n this._classProperty = classProperty;\n this._extras = property.extras;\n this._extensions = property.extensions;\n}\n\nObject.defineProperties(PropertyTextureProperty.prototype, {\n /**\n * The texture reader.\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {ModelComponents.TextureReader}\n * @readonly\n * @private\n */\n textureReader: {\n get: function () {\n return this._textureReader;\n },\n },\n\n /**\n * True if offset/scale should be applied. If both offset/scale were\n * undefined, they default to identity so this property is set false\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n hasValueTransform: {\n get: function () {\n return this._hasValueTransform;\n },\n },\n\n /**\n * The offset to be added to property values as part of the value transform.\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @readonly\n * @private\n */\n offset: {\n get: function () {\n return this._offset;\n },\n },\n\n /**\n * The scale to be multiplied to property values as part of the value transform.\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @readonly\n * @private\n */\n scale: {\n get: function () {\n return this._scale;\n },\n },\n\n /**\n * The properties inherited from this property's class\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {MetadataClassProperty}\n * @readonly\n * @private\n */\n classProperty: {\n get: function () {\n return this._classProperty;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof PropertyTextureProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nPropertyTextureProperty.prototype.isGpuCompatible = function () {\n const classProperty = this._classProperty;\n const type = classProperty.type;\n const componentType = classProperty.componentType;\n\n if (classProperty.isArray) {\n // only support arrays of 1-4 UINT8 scalars (normalized or unnormalized)\n return (\n !classProperty.isVariableLengthArray &&\n classProperty.arrayLength <= 4 &&\n type === MetadataType.SCALAR &&\n componentType === MetadataComponentType.UINT8\n );\n }\n\n if (MetadataType.isVectorType(type) || type === MetadataType.SCALAR) {\n return componentType === MetadataComponentType.UINT8;\n }\n\n // For this initial implementation, only UINT8-based properties\n // are supported.\n return false;\n};\n\nconst floatTypesByComponentCount = [undefined, \"float\", \"vec2\", \"vec3\", \"vec4\"];\nconst integerTypesByComponentCount = [\n undefined,\n \"int\",\n \"ivec2\",\n \"ivec3\",\n \"ivec4\",\n];\nPropertyTextureProperty.prototype.getGlslType = function () {\n const classProperty = this._classProperty;\n\n let componentCount = MetadataType.getComponentCount(classProperty.type);\n if (classProperty.isArray) {\n // fixed-sized arrays of length 2-4 UINT8s are represented as vectors as the\n // shader since those are more useful in GLSL.\n componentCount = classProperty.arrayLength;\n }\n\n // Normalized UINT8 properties are float types in the shader\n if (classProperty.normalized) {\n return floatTypesByComponentCount[componentCount];\n }\n\n // other UINT8-based properties are represented as integer types.\n return integerTypesByComponentCount[componentCount];\n};\n\nPropertyTextureProperty.prototype.unpackInShader = function (packedValueGlsl) {\n const classProperty = this._classProperty;\n\n // no unpacking needed if for normalized types\n if (classProperty.normalized) {\n return packedValueGlsl;\n }\n\n // integer types are read from the texture as normalized float values.\n // these need to be rescaled to [0, 255] and cast to the appropriate integer\n // type.\n const glslType = this.getGlslType();\n return `${glslType}(255.0 * ${packedValueGlsl})`;\n};\n\n/**\n * Reformat from an array of channel indices like [0, 1] to a\n * string of channels as would be used in GLSL swizzling (e.g. \"rg\")\n *\n * @param {number[]} channels the channel indices\n * @return {string} The channels as a string of \"r\", \"g\", \"b\" or \"a\" characters.\n * @private\n */\nfunction reformatChannels(channels) {\n return channels\n .map(function (channelIndex) {\n return \"rgba\".charAt(channelIndex);\n })\n .join(\"\");\n}\n\nexport default PropertyTextureProperty;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PropertyTextureProperty from \"./PropertyTextureProperty.js\";\n\n/**\n * A property texture.\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the\n * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} [options.name] Optional human-readable name to describe the texture\n * @param {string|number} [options.id] A unique id to identify the property texture, useful for debugging. For EXT_structural_metadata, this is the array index in the property textures array, for EXT_feature_metadata this is the dictionary key in the property textures dictionary.\n * @param {object} options.propertyTexture The property texture JSON, following the EXT_structural_metadata schema.\n * @param {MetadataClass} options.class The class that properties conform to.\n * @param {Object} options.textures An object mapping texture IDs to {@link Texture} objects.\n *\n * @alias PropertyTexture\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction PropertyTexture(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const propertyTexture = options.propertyTexture;\n const classDefinition = options.class;\n const textures = options.textures;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.propertyTexture\", propertyTexture);\n Check.typeOf.object(\"options.class\", classDefinition);\n Check.typeOf.object(\"options.textures\", textures);\n //>>includeEnd('debug');\n\n const extensions = propertyTexture.extensions;\n const extras = propertyTexture.extras;\n\n const properties = {};\n if (defined(propertyTexture.properties)) {\n for (const propertyId in propertyTexture.properties) {\n if (propertyTexture.properties.hasOwnProperty(propertyId)) {\n properties[propertyId] = new PropertyTextureProperty({\n property: propertyTexture.properties[propertyId],\n classProperty: classDefinition.properties[propertyId],\n textures: textures,\n });\n }\n }\n }\n\n this._name = options.name;\n this._id = options.id;\n this._class = classDefinition;\n this._properties = properties;\n this._extras = extras;\n this._extensions = extensions;\n}\n\nObject.defineProperties(PropertyTexture.prototype, {\n /**\n * A human-readable name for this texture\n *\n * @memberof PropertyTexture.prototype\n * @type {string}\n * @readonly\n * @private\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n /**\n * An identifier for this texture. Useful for debugging.\n *\n * @memberof PropertyTexture.prototype\n * @type {string|number}\n * @readonly\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * The class that properties conform to.\n *\n * @memberof PropertyTexture.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * The properties in this property texture.\n *\n * @memberof PropertyTexture.prototype\n *\n * @type {PropertyTextureProperty}\n * @readonly\n * @private\n */\n properties: {\n get: function () {\n return this._properties;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof PropertyTexture.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof PropertyTexture.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Gets the property with the given property ID.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {PropertyTextureProperty|undefined} The property, or undefined if the property does not exist.\n * @private\n */\nPropertyTexture.prototype.getProperty = function (propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n return this._properties[propertyId];\n};\n\nexport default PropertyTexture;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * A property in a property attribute from EXT_structural_metadata.\n *\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension}\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.property The property JSON object.\n * @param {MetadataClassProperty} options.classProperty The class property.\n *\n * @alias PropertyAttributeProperty\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction PropertyAttributeProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const property = options.property;\n const classProperty = options.classProperty;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.property\", property);\n Check.typeOf.object(\"options.classProperty\", classProperty);\n //>>includeEnd('debug');\n\n this._attribute = property.attribute;\n this._classProperty = classProperty;\n this._min = property.min;\n this._max = property.max;\n\n let offset = property.offset;\n let scale = property.scale;\n\n // This needs to be set before handling default values\n const hasValueTransform =\n classProperty.hasValueTransform || defined(offset) || defined(scale);\n\n // If the property attribute does not define an offset/scale, it inherits from\n // the class property. The class property handles setting the default of\n // identity: (offset 0, scale 1) with the same scalar/vector/matrix types.\n // array types are disallowed by the spec.\n offset = defaultValue(offset, classProperty.offset);\n scale = defaultValue(scale, classProperty.scale);\n\n // offset and scale are applied on the GPU, so unpack the values\n // as math types we can use in uniform callbacks.\n offset = classProperty.unpackVectorAndMatrixTypes(offset);\n scale = classProperty.unpackVectorAndMatrixTypes(scale);\n\n this._offset = offset;\n this._scale = scale;\n this._hasValueTransform = hasValueTransform;\n\n this._extras = property.extras;\n this._extensions = property.extensions;\n}\n\nObject.defineProperties(PropertyAttributeProperty.prototype, {\n /**\n * The attribute semantic\n *\n * @memberof PropertyAttributeProperty.prototype\n * @type {string}\n * @readonly\n * @private\n */\n attribute: {\n get: function () {\n return this._attribute;\n },\n },\n\n /**\n * True if offset/scale should be applied. If both offset/scale were\n * undefined, they default to identity so this property is set false\n *\n * @memberof MetadataClassProperty.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n hasValueTransform: {\n get: function () {\n return this._hasValueTransform;\n },\n },\n\n /**\n * The offset to be added to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @readonly\n * @private\n */\n offset: {\n get: function () {\n return this._offset;\n },\n },\n\n /**\n * The scale to be multiplied to property values as part of the value transform.\n *\n * @memberof MetadataClassProperty.prototype\n * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}\n * @readonly\n * @private\n */\n scale: {\n get: function () {\n return this._scale;\n },\n },\n\n /**\n * The properties inherited from this property's class\n *\n * @memberof PropertyAttributeProperty.prototype\n * @type {MetadataClassProperty}\n * @readonly\n * @private\n */\n classProperty: {\n get: function () {\n return this._classProperty;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof PropertyAttributeProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof PropertyAttributeProperty.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nexport default PropertyAttributeProperty;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PropertyAttributeProperty from \"./PropertyAttributeProperty.js\";\n\n/**\n * A property attribute; a collection of per-point properties stored as custom\n * vertex attributes.\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension}\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} [options.name] Optional human-readable name to describe the attribute\n * @param {number} [options.id] A unique id to identify the property attribute, useful for debugging. This is the array index in the property attributes array\n * @param {object} options.propertyAttribute The property attribute JSON, following the EXT_structural_metadata schema.\n * @param {MetadataClass} options.class The class that properties conform to.\n *\n * @alias PropertyAttribute\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction PropertyAttribute(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const propertyAttribute = options.propertyAttribute;\n const classDefinition = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.propertyAttribute\", propertyAttribute);\n Check.typeOf.object(\"options.class\", classDefinition);\n //>>includeEnd('debug');\n\n const properties = {};\n if (defined(propertyAttribute.properties)) {\n for (const propertyId in propertyAttribute.properties) {\n if (propertyAttribute.properties.hasOwnProperty(propertyId)) {\n properties[propertyId] = new PropertyAttributeProperty({\n property: propertyAttribute.properties[propertyId],\n classProperty: classDefinition.properties[propertyId],\n });\n }\n }\n }\n\n this._name = options.name;\n this._id = options.id;\n this._class = classDefinition;\n this._properties = properties;\n this._extras = propertyAttribute.extras;\n this._extensions = propertyAttribute.extensions;\n}\n\nObject.defineProperties(PropertyAttribute.prototype, {\n /**\n * A human-readable name for this attribute\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n /**\n * An identifier for this attribute. Useful for debugging.\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {string|number}\n * @readonly\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * The class that properties conform to.\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * The properties in this property attribute.\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {Object}\n * @readonly\n * @private\n */\n properties: {\n get: function () {\n return this._properties;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof PropertyAttribute.prototype\n *\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Gets the property with the given property ID.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {PropertyAttributeProperty|undefined} The property, or undefined if the property does not exist.\n * @private\n */\nPropertyAttribute.prototype.getProperty = function (propertyId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"propertyId\", propertyId);\n //>>includeEnd('debug');\n\n return this._properties[propertyId];\n};\n\nexport default PropertyAttribute;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * An object containing structural metadata.\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadatas|EXT_structural_metadata Extension} as well as the\n * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {MetadataSchema} options.schema The parsed schema.\n * @param {PropertyTable[]} [options.propertyTables] An array of property table objects. For the legacy EXT_feature_metadata extension, this is sorted by the key in the propertyTables dictionary\n * @param {PropertyTexture[]} [options.propertyTextures] An array of property texture objects. For the legacy EXT_feature_metadata extension, this is sorted by the key in the propertyTextures dictionary\n * @param {PropertyAttribute[]} [options.propertyAttributes] An array of property attribute objects. This is new in EXT_structural_metadata\n * @param {object} [options.statistics] Statistics about metadata\n * @param {object} [options.extras] Extra user-defined properties\n * @param {object} [options.extensions] An object containing extensions\n *\n * @alias StructuralMetadata\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction StructuralMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.schema\", options.schema);\n //>>includeEnd('debug');\n\n this._schema = options.schema;\n const propertyTables = options.propertyTables;\n this._propertyTableCount = defined(propertyTables)\n ? propertyTables.length\n : 0;\n this._propertyTables = propertyTables;\n this._propertyTextures = options.propertyTextures;\n this._propertyAttributes = options.propertyAttributes;\n this._statistics = options.statistics;\n this._extras = options.extras;\n this._extensions = options.extensions;\n}\n\nObject.defineProperties(StructuralMetadata.prototype, {\n /**\n * Schema containing classes and enums.\n *\n * @memberof StructuralMetadata.prototype\n * @type {MetadataSchema}\n * @readonly\n * @private\n */\n schema: {\n get: function () {\n return this._schema;\n },\n },\n\n /**\n * Statistics about the metadata.\n *

\n * See the {@link https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.schema.json|statistics schema reference} for the full set of properties.\n *

\n *\n * @memberof StructuralMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n statistics: {\n get: function () {\n return this._statistics;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof StructuralMetadata.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof StructuralMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n\n /**\n * Number of property tables in the metadata.\n *\n * @memberof StructuralMetadata.prototype\n * @type {number}\n * @readonly\n * @private\n */\n propertyTableCount: {\n get: function () {\n return this._propertyTableCount;\n },\n },\n\n /**\n * The property tables in the metadata.\n *\n * @memberof StructuralMetadata.prototype\n * @type {PropertyTable[]}\n * @readonly\n * @private\n */\n propertyTables: {\n get: function () {\n return this._propertyTables;\n },\n },\n\n /**\n * The property textures in the metadata.\n *\n * @memberof StructuralMetadata.prototype\n * @type {PropertyTexture[]}\n * @readonly\n * @private\n */\n propertyTextures: {\n get: function () {\n return this._propertyTextures;\n },\n },\n\n /**\n * The property attributes from the structural metadata extension\n *\n * @memberof StructuralMetadata.prototype\n * @type {PropertyAttribute[]}\n * @readonly\n * @private\n */\n propertyAttributes: {\n get: function () {\n return this._propertyAttributes;\n },\n },\n\n /**\n * Total size in bytes across all property tables\n *\n * @memberof StructuralMetadata.prototype\n * @type {number}\n * @readonly\n * @private\n */\n propertyTablesByteLength: {\n get: function () {\n if (!defined(this._propertyTables)) {\n return 0;\n }\n\n let totalByteLength = 0;\n const length = this._propertyTables.length;\n for (let i = 0; i < length; i++) {\n totalByteLength += this._propertyTables[i].byteLength;\n }\n\n return totalByteLength;\n },\n },\n});\n\n/**\n * Gets the property table with the given ID.\n *

\n * For the legacy EXT_feature_metadata, textures are stored in an array sorted\n * by the key in the propertyTables dictionary.\n *

\n *\n * @param {number} propertyTableId The property table ID.\n * @returns {PropertyTable} The property table.\n * @private\n */\nStructuralMetadata.prototype.getPropertyTable = function (propertyTableId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"propertyTableId\", propertyTableId);\n //>>includeEnd('debug');\n\n return this._propertyTables[propertyTableId];\n};\n\n/**\n * Gets the property texture with the given ID.\n *

\n * For the legacy EXT_feature_metadata, textures are stored in an array sorted\n * by the key in the propertyTextures dictionary.\n *

\n *\n * @param {number} propertyTextureId The index into the property textures array.\n * @returns {PropertyTexture} The property texture\n * @private\n */\nStructuralMetadata.prototype.getPropertyTexture = function (propertyTextureId) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"propertyTextureId\", propertyTextureId);\n //>>includeEnd('debug');\n\n return this._propertyTextures[propertyTextureId];\n};\n\n/**\n * Gets the property attribute with the given ID. This concept is new in\n * EXT_structural_metadata\n *\n * @param {number} propertyAttributeId The index into the property attributes array.\n * @returns {PropertyAttribute} The property attribute\n * @private\n */\nStructuralMetadata.prototype.getPropertyAttribute = function (\n propertyAttributeId\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"propertyAttributeId\", propertyAttributeId);\n //>>includeEnd('debug');\n\n return this._propertyAttributes[propertyAttributeId];\n};\n\nexport default StructuralMetadata;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PropertyTable from \"./PropertyTable.js\";\nimport PropertyTexture from \"./PropertyTexture.js\";\nimport PropertyAttribute from \"./PropertyAttribute.js\";\nimport StructuralMetadata from \"./StructuralMetadata.js\";\nimport MetadataTable from \"./MetadataTable.js\";\n\n/**\n * Parse the EXT_structural_metadata glTF extension to create a\n * structural metadata object.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.extension The extension JSON object.\n * @param {MetadataSchema} options.schema The parsed schema.\n * @param {Object} [options.bufferViews] An object mapping bufferView IDs to Uint8Array objects.\n * @param {Object} [options.textures] An object mapping texture IDs to {@link Texture} objects.\n * @return {StructuralMetadata} A structural metadata object\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction parseStructuralMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const extension = options.extension;\n\n // The calling code is responsible for loading the schema.\n // This keeps metadata parsing synchronous.\n const schema = options.schema;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.extension\", extension);\n Check.typeOf.object(\"options.schema\", schema);\n //>>includeEnd('debug');\n\n const propertyTables = [];\n if (defined(extension.propertyTables)) {\n for (let i = 0; i < extension.propertyTables.length; i++) {\n const propertyTable = extension.propertyTables[i];\n const classDefinition = schema.classes[propertyTable.class];\n const metadataTable = new MetadataTable({\n count: propertyTable.count,\n properties: propertyTable.properties,\n class: classDefinition,\n bufferViews: options.bufferViews,\n });\n propertyTables.push(\n new PropertyTable({\n id: i,\n name: propertyTable.name,\n count: propertyTable.count,\n metadataTable: metadataTable,\n extras: propertyTable.extras,\n extensions: propertyTable.extensions,\n })\n );\n }\n }\n\n const propertyTextures = [];\n if (defined(extension.propertyTextures)) {\n for (let i = 0; i < extension.propertyTextures.length; i++) {\n const propertyTexture = extension.propertyTextures[i];\n propertyTextures.push(\n new PropertyTexture({\n id: i,\n name: propertyTexture.name,\n propertyTexture: propertyTexture,\n class: schema.classes[propertyTexture.class],\n textures: options.textures,\n })\n );\n }\n }\n\n const propertyAttributes = [];\n if (defined(extension.propertyAttributes)) {\n for (let i = 0; i < extension.propertyAttributes.length; i++) {\n const propertyAttribute = extension.propertyAttributes[i];\n propertyAttributes.push(\n new PropertyAttribute({\n id: i,\n name: propertyAttribute.name,\n class: schema.classes[propertyAttribute.class],\n propertyAttribute: propertyAttribute,\n })\n );\n }\n }\n\n return new StructuralMetadata({\n schema: schema,\n propertyTables: propertyTables,\n propertyTextures: propertyTextures,\n propertyAttributes: propertyAttributes,\n statistics: extension.statistics,\n extras: extension.extras,\n extensions: extension.extensions,\n });\n}\n\nexport default parseStructuralMetadata;\n", "import Check from \"../Core/Check.js\";\nimport combine from \"../Core/combine.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport PropertyTable from \"./PropertyTable.js\";\nimport PropertyTexture from \"./PropertyTexture.js\";\nimport StructuralMetadata from \"./StructuralMetadata.js\";\nimport MetadataTable from \"./MetadataTable.js\";\n\n/**\n * Parse the EXT_feature_metadata glTF extension to create a\n * structural metadata object.\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.extension The extension JSON object.\n * @param {MetadataSchema} options.schema The parsed schema.\n * @param {Object} [options.bufferViews] An object mapping bufferView IDs to Uint8Array objects.\n * @param {Object} [options.textures] An object mapping texture IDs to {@link Texture} objects.\n * @return {StructuralMetadata} A structural metadata object\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction parseFeatureMetadataLegacy(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const extension = options.extension;\n\n // The calling code is responsible for loading the schema.\n // This keeps metadata parsing synchronous.\n const schema = options.schema;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.extension\", extension);\n Check.typeOf.object(\"options.schema\", schema);\n //>>includeEnd('debug');\n\n let i;\n const propertyTables = [];\n let sortedIds;\n if (defined(extension.featureTables)) {\n // Store textures in an array sorted by the dictionary keys. This\n // allows compatibility with the newer EXT_structural_metadata extension\n // which is array-based.\n sortedIds = Object.keys(extension.featureTables).sort();\n for (i = 0; i < sortedIds.length; i++) {\n const featureTableId = sortedIds[i];\n const featureTable = extension.featureTables[featureTableId];\n const classDefinition = schema.classes[featureTable.class];\n\n const metadataTable = new MetadataTable({\n count: featureTable.count,\n properties: featureTable.properties,\n class: classDefinition,\n bufferViews: options.bufferViews,\n });\n\n propertyTables.push(\n new PropertyTable({\n id: featureTableId,\n count: featureTable.count,\n metadataTable: metadataTable,\n extras: featureTable.extras,\n extensions: featureTable.extensions,\n })\n );\n }\n }\n\n const propertyTextures = [];\n if (defined(extension.featureTextures)) {\n // Store textures in an array sorted by the dictionary keys. This\n // allows compatibility with the newer EXT_structural_metadata extension\n // which is array-based.\n sortedIds = Object.keys(extension.featureTextures).sort();\n for (i = 0; i < sortedIds.length; i++) {\n const featureTextureId = sortedIds[i];\n const featureTexture = extension.featureTextures[featureTextureId];\n propertyTextures.push(\n new PropertyTexture({\n id: featureTextureId,\n propertyTexture: transcodeToPropertyTexture(featureTexture),\n class: schema.classes[featureTexture.class],\n textures: options.textures,\n })\n );\n }\n }\n\n return new StructuralMetadata({\n schema: schema,\n propertyTables: propertyTables,\n propertyTextures: propertyTextures,\n statistics: extension.statistics,\n extras: extension.extras,\n extensions: extension.extensions,\n });\n}\n\nfunction transcodeToPropertyTexture(featureTexture) {\n const propertyTexture = {\n class: featureTexture.class,\n properties: {},\n };\n\n const properties = featureTexture.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const oldProperty = properties[propertyId];\n const property = {\n // EXT_structural_metadata uses numeric channel indices instead of\n // a string of channel letters like \"rgba\".\n channels: reformatChannels(oldProperty.channels),\n extras: oldProperty.extras,\n extensions: oldProperty.extensions,\n };\n\n // EXT_feature_metadata puts the textureInfo in property.texture.\n // EXT_structural_metadata flattens this structure; essentially a\n // textureInfo + channels\n propertyTexture.properties[propertyId] = combine(\n oldProperty.texture,\n property,\n true\n );\n }\n }\n\n return propertyTexture;\n}\n\nfunction reformatChannels(channelsString) {\n const length = channelsString.length;\n const result = new Array(length);\n for (let i = 0; i < length; i++) {\n result[i] = \"rgba\".indexOf(channelsString[i]);\n }\n return result;\n}\n\nexport default parseFeatureMetadataLegacy;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport parseStructuralMetadata from \"./parseStructuralMetadata.js\";\nimport parseFeatureMetadataLegacy from \"./parseFeatureMetadataLegacy.js\";\nimport ResourceCache from \"./ResourceCache.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport ResourceLoaderState from \"./ResourceLoaderState.js\";\n\n/**\n * Loads glTF structural metadata\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfStructuralMetadataLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.gltf The glTF JSON.\n * @param {string} [options.extension] The EXT_structural_metadata extension object. If this is undefined, then extensionLegacy must be defined.\n * @param {string} [options.extensionLegacy] The legacy EXT_feature_metadata extension for backwards compatibility.\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF.\n * @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.\n * @param {FrameState} options.frameState The frame state.\n * @param {string} [options.cacheKey] The cache key of the resource.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction GltfStructuralMetadataLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltf = options.gltf;\n const extension = options.extension;\n const extensionLegacy = options.extensionLegacy;\n const gltfResource = options.gltfResource;\n const baseResource = options.baseResource;\n const supportedImageFormats = options.supportedImageFormats;\n const frameState = options.frameState;\n const cacheKey = options.cacheKey;\n const asynchronous = defaultValue(options.asynchronous, true);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltf\", gltf);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n Check.typeOf.object(\"options.baseResource\", baseResource);\n Check.typeOf.object(\"options.supportedImageFormats\", supportedImageFormats);\n Check.typeOf.object(\"options.frameState\", frameState);\n\n if (!defined(options.extension) && !defined(options.extensionLegacy)) {\n throw new DeveloperError(\n \"One of options.extension or options.extensionLegacy must be specified\"\n );\n }\n //>>includeEnd('debug');\n\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._gltf = gltf;\n this._extension = extension;\n this._extensionLegacy = extensionLegacy;\n this._supportedImageFormats = supportedImageFormats;\n this._frameState = frameState;\n this._cacheKey = cacheKey;\n this._asynchronous = asynchronous;\n this._bufferViewLoaders = [];\n this._bufferViewIds = [];\n this._textureLoaders = [];\n this._textureIds = [];\n this._schemaLoader = undefined;\n this._structuralMetadata = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._promise = undefined;\n}\n\nif (defined(Object.create)) {\n GltfStructuralMetadataLoader.prototype = Object.create(\n ResourceLoader.prototype\n );\n GltfStructuralMetadataLoader.prototype.constructor = GltfStructuralMetadataLoader;\n}\n\nObject.defineProperties(GltfStructuralMetadataLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfStructuralMetadataLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return this._cacheKey;\n },\n },\n /**\n * The parsed structural metadata\n *\n * @memberof GltfStructuralMetadataLoader.prototype\n *\n * @type {StructuralMetadata}\n * @readonly\n * @private\n */\n structuralMetadata: {\n get: function () {\n return this._structuralMetadata;\n },\n },\n});\n\nasync function loadResources(loader) {\n try {\n const bufferViewsPromise = loadBufferViews(loader);\n const texturesPromise = loadTextures(loader);\n const schemaPromise = loadSchema(loader);\n\n await Promise.all([bufferViewsPromise, texturesPromise, schemaPromise]);\n\n if (loader.isDestroyed()) {\n return;\n }\n\n loader._gltf = undefined; // No longer need to hold onto the glTF\n\n loader._state = ResourceLoaderState.LOADED;\n return loader;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n loader.unload();\n loader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load structural metadata\";\n throw loader.getError(errorMessage, error);\n }\n}\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGltfStructuralMetadataLoader.prototype.load = function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._state = ResourceLoaderState.LOADING;\n this._promise = loadResources(this);\n return this._promise;\n};\n\nfunction gatherBufferViewIdsFromProperties(properties, bufferViewIdSet) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const values = property.values;\n const arrayOffsets = property.arrayOffsets;\n const stringOffsets = property.stringOffsets;\n\n // Using an object like a mathematical set\n if (defined(values)) {\n bufferViewIdSet[values] = true;\n }\n if (defined(arrayOffsets)) {\n bufferViewIdSet[arrayOffsets] = true;\n }\n if (defined(stringOffsets)) {\n bufferViewIdSet[stringOffsets] = true;\n }\n }\n }\n}\n\nfunction gatherBufferViewIdsFromPropertiesLegacy(properties, bufferViewIdSet) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const bufferView = property.bufferView;\n const arrayOffsetBufferView = property.arrayOffsetBufferView;\n const stringOffsetBufferView = property.stringOffsetBufferView;\n\n // Using an object like a mathematical set\n if (defined(bufferView)) {\n bufferViewIdSet[bufferView] = true;\n }\n if (defined(arrayOffsetBufferView)) {\n bufferViewIdSet[arrayOffsetBufferView] = true;\n }\n if (defined(stringOffsetBufferView)) {\n bufferViewIdSet[stringOffsetBufferView] = true;\n }\n }\n }\n}\n\nfunction gatherUsedBufferViewIds(extension) {\n const propertyTables = extension.propertyTables;\n const bufferViewIdSet = {};\n if (defined(propertyTables)) {\n for (let i = 0; i < propertyTables.length; i++) {\n const propertyTable = propertyTables[i];\n gatherBufferViewIdsFromProperties(\n propertyTable.properties,\n bufferViewIdSet\n );\n }\n }\n return bufferViewIdSet;\n}\n\nfunction gatherUsedBufferViewIdsLegacy(extensionLegacy) {\n const featureTables = extensionLegacy.featureTables;\n\n const bufferViewIdSet = {};\n if (defined(featureTables)) {\n for (const featureTableId in featureTables) {\n if (featureTables.hasOwnProperty(featureTableId)) {\n const featureTable = featureTables[featureTableId];\n const properties = featureTable.properties;\n if (defined(properties)) {\n gatherBufferViewIdsFromPropertiesLegacy(properties, bufferViewIdSet);\n }\n }\n }\n }\n return bufferViewIdSet;\n}\n\nasync function loadBufferViews(structuralMetadataLoader) {\n let bufferViewIds;\n if (defined(structuralMetadataLoader._extension)) {\n bufferViewIds = gatherUsedBufferViewIds(\n structuralMetadataLoader._extension\n );\n } else {\n bufferViewIds = gatherUsedBufferViewIdsLegacy(\n structuralMetadataLoader._extensionLegacy\n );\n }\n\n // Load the buffer views\n const bufferViewPromises = [];\n for (const bufferViewId in bufferViewIds) {\n if (bufferViewIds.hasOwnProperty(bufferViewId)) {\n const bufferViewLoader = ResourceCache.getBufferViewLoader({\n gltf: structuralMetadataLoader._gltf,\n bufferViewId: parseInt(bufferViewId),\n gltfResource: structuralMetadataLoader._gltfResource,\n baseResource: structuralMetadataLoader._baseResource,\n });\n\n structuralMetadataLoader._bufferViewLoaders.push(bufferViewLoader);\n structuralMetadataLoader._bufferViewIds.push(bufferViewId);\n\n bufferViewPromises.push(bufferViewLoader.load());\n }\n }\n\n return Promise.all(bufferViewPromises);\n}\n\nfunction gatherUsedTextureIds(structuralMetadataExtension) {\n // Gather the used textures\n const textureIds = {};\n const propertyTextures = structuralMetadataExtension.propertyTextures;\n if (defined(propertyTextures)) {\n for (let i = 0; i < propertyTextures.length; i++) {\n const propertyTexture = propertyTextures[i];\n const properties = propertyTexture.properties;\n if (defined(properties)) {\n gatherTextureIdsFromProperties(properties, textureIds);\n }\n }\n }\n return textureIds;\n}\n\nfunction gatherTextureIdsFromProperties(properties, textureIds) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n // in EXT_structural_metadata the property is a valid textureInfo.\n const textureInfo = properties[propertyId];\n textureIds[textureInfo.index] = textureInfo;\n }\n }\n}\n\nfunction gatherUsedTextureIdsLegacy(extensionLegacy) {\n // Gather the used textures\n const textureIds = {};\n const featureTextures = extensionLegacy.featureTextures;\n if (defined(featureTextures)) {\n for (const featureTextureId in featureTextures) {\n if (featureTextures.hasOwnProperty(featureTextureId)) {\n const featureTexture = featureTextures[featureTextureId];\n const properties = featureTexture.properties;\n if (defined(properties)) {\n gatherTextureIdsFromPropertiesLegacy(properties, textureIds);\n }\n }\n }\n }\n\n return textureIds;\n}\n\nfunction gatherTextureIdsFromPropertiesLegacy(properties, textureIds) {\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const textureInfo = property.texture;\n textureIds[textureInfo.index] = textureInfo;\n }\n }\n}\n\nfunction loadTextures(structuralMetadataLoader) {\n let textureIds;\n if (defined(structuralMetadataLoader._extension)) {\n textureIds = gatherUsedTextureIds(structuralMetadataLoader._extension);\n } else {\n textureIds = gatherUsedTextureIdsLegacy(\n structuralMetadataLoader._extensionLegacy\n );\n }\n\n const gltf = structuralMetadataLoader._gltf;\n const gltfResource = structuralMetadataLoader._gltfResource;\n const baseResource = structuralMetadataLoader._baseResource;\n const supportedImageFormats = structuralMetadataLoader._supportedImageFormats;\n const frameState = structuralMetadataLoader._frameState;\n const asynchronous = structuralMetadataLoader._asynchronous;\n\n // Load the textures\n const texturePromises = [];\n for (const textureId in textureIds) {\n if (textureIds.hasOwnProperty(textureId)) {\n const textureLoader = ResourceCache.getTextureLoader({\n gltf: gltf,\n textureInfo: textureIds[textureId],\n gltfResource: gltfResource,\n baseResource: baseResource,\n supportedImageFormats: supportedImageFormats,\n frameState: frameState,\n asynchronous: asynchronous,\n });\n structuralMetadataLoader._textureLoaders.push(textureLoader);\n structuralMetadataLoader._textureIds.push(textureId);\n texturePromises.push(textureLoader.load());\n }\n }\n\n return Promise.all(texturePromises);\n}\n\nasync function loadSchema(structuralMetadataLoader) {\n const extension = defaultValue(\n structuralMetadataLoader._extension,\n structuralMetadataLoader._extensionLegacy\n );\n\n let schemaLoader;\n if (defined(extension.schemaUri)) {\n const resource = structuralMetadataLoader._baseResource.getDerivedResource({\n url: extension.schemaUri,\n });\n schemaLoader = ResourceCache.getSchemaLoader({\n resource: resource,\n });\n } else {\n schemaLoader = ResourceCache.getSchemaLoader({\n schema: extension.schema,\n });\n }\n\n structuralMetadataLoader._schemaLoader = schemaLoader;\n await schemaLoader.load();\n if (!schemaLoader.isDestroyed()) {\n return schemaLoader.schema;\n }\n}\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGltfStructuralMetadataLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (this._state !== ResourceLoaderState.LOADED) {\n return false;\n }\n\n const textureLoaders = this._textureLoaders;\n const textureLoadersLength = textureLoaders.length;\n let ready = true;\n for (let i = 0; i < textureLoadersLength; ++i) {\n const textureLoader = textureLoaders[i];\n const textureReady = textureLoader.process(frameState);\n ready = ready && textureReady;\n }\n\n if (!ready) {\n return false;\n }\n\n const schema = this._schemaLoader.schema;\n const bufferViews = {};\n for (let i = 0; i < this._bufferViewIds.length; ++i) {\n const bufferViewId = this._bufferViewIds[i];\n const bufferViewLoader = this._bufferViewLoaders[i];\n if (!bufferViewLoader.isDestroyed()) {\n // Copy the typed array and let the underlying ArrayBuffer be freed\n const bufferViewTypedArray = new Uint8Array(bufferViewLoader.typedArray);\n bufferViews[bufferViewId] = bufferViewTypedArray;\n }\n }\n\n const textures = {};\n for (let i = 0; i < this._textureIds.length; ++i) {\n const textureId = this._textureIds[i];\n const textureLoader = textureLoaders[i];\n if (!textureLoader.isDestroyed()) {\n textures[textureId] = textureLoader.texture;\n }\n }\n if (defined(this._extension)) {\n this._structuralMetadata = parseStructuralMetadata({\n extension: this._extension,\n schema: schema,\n bufferViews: bufferViews,\n textures: textures,\n });\n } else {\n this._structuralMetadata = parseFeatureMetadataLegacy({\n extension: this._extensionLegacy,\n schema: schema,\n bufferViews: bufferViews,\n textures: textures,\n });\n }\n\n // Buffer views can be unloaded after the data has been copied\n unloadBufferViews(this);\n\n this._state = ResourceLoaderState.READY;\n return true;\n};\n\nfunction unloadBufferViews(structuralMetadataLoader) {\n const bufferViewLoaders = structuralMetadataLoader._bufferViewLoaders;\n const bufferViewLoadersLength = bufferViewLoaders.length;\n for (let i = 0; i < bufferViewLoadersLength; ++i) {\n ResourceCache.unload(bufferViewLoaders[i]);\n }\n structuralMetadataLoader._bufferViewLoaders.length = 0;\n structuralMetadataLoader._bufferViewIds.length = 0;\n}\n\nfunction unloadTextures(structuralMetadataLoader) {\n const textureLoaders = structuralMetadataLoader._textureLoaders;\n const textureLoadersLength = textureLoaders.length;\n for (let i = 0; i < textureLoadersLength; ++i) {\n ResourceCache.unload(textureLoaders[i]);\n }\n structuralMetadataLoader._textureLoaders.length = 0;\n structuralMetadataLoader._textureIds.length = 0;\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfStructuralMetadataLoader.prototype.unload = function () {\n unloadBufferViews(this);\n unloadTextures(this);\n\n if (defined(this._schemaLoader)) {\n ResourceCache.unload(this._schemaLoader);\n }\n this._schemaLoader = undefined;\n\n this._structuralMetadata = undefined;\n};\n\nexport default GltfStructuralMetadataLoader;\n", "import Check from \"../Core/Check.js\";\n\n/**\n * An enum describing the built-in instance attribute semantics.\n *\n * @enum {string}\n *\n * @private\n */\nconst InstanceAttributeSemantic = {\n /**\n * Per-instance translation.\n *\n * @type {string}\n * @constant\n */\n TRANSLATION: \"TRANSLATION\",\n\n /**\n * Per-instance rotation.\n *\n * @type {string}\n * @constant\n */\n ROTATION: \"ROTATION\",\n\n /**\n * Per-instance scale.\n *\n * @type {string}\n * @constant\n */\n SCALE: \"SCALE\",\n\n /**\n * Per-instance feature ID.\n *\n * @type {string}\n * @constant\n */\n FEATURE_ID: \"_FEATURE_ID\",\n};\n\n/**\n * Gets the instance attribute semantic matching the glTF attribute semantic.\n *\n * @returns {InstanceAttributeSemantic} The instance attribute semantic, or undefined if there is no match.\n *\n * @private\n */\nInstanceAttributeSemantic.fromGltfSemantic = function (gltfSemantic) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"gltfSemantic\", gltfSemantic);\n //>>includeEnd('debug')\n\n let semantic = gltfSemantic;\n\n // Strip the set index from the semantic\n const setIndexRegex = /^(\\w+)_\\d+$/;\n const setIndexMatch = setIndexRegex.exec(gltfSemantic);\n if (setIndexMatch !== null) {\n semantic = setIndexMatch[1];\n }\n\n switch (semantic) {\n case \"TRANSLATION\":\n return InstanceAttributeSemantic.TRANSLATION;\n case \"ROTATION\":\n return InstanceAttributeSemantic.ROTATION;\n case \"SCALE\":\n return InstanceAttributeSemantic.SCALE;\n case \"_FEATURE_ID\":\n return InstanceAttributeSemantic.FEATURE_ID;\n }\n\n return undefined;\n};\n\nexport default Object.freeze(InstanceAttributeSemantic);\n", "import Check from \"../../Core/Check.js\";\nimport defined from \"../../Core/defined.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport PixelFormat from \"../../Core/PixelFormat.js\";\nimport ContextLimits from \"../../Renderer/ContextLimits.js\";\nimport Sampler from \"../../Renderer/Sampler.js\";\nimport Texture from \"../../Renderer/Texture.js\";\nimport TextureMagnificationFilter from \"../../Renderer/TextureMagnificationFilter.js\";\nimport TextureMinificationFilter from \"../../Renderer/TextureMinificationFilter.js\";\nimport TextureWrap from \"../../Renderer/TextureWrap.js\";\n\n// glTF does not allow an index value of 65535 because this is the primitive\n// restart value in some APIs.\nconst MAX_GLTF_UINT16_INDEX = 65534;\nconst MAX_GLTF_UINT8_INDEX = 255;\n\n/**\n * A class to handle the low-level details of processing indices and vertex\n * attributes for the CESIUM_primitive_outline extension.\n *

\n * To render outlines, a lookup texture is used 3 times, once per edge of a\n * triangle. In order to render correctly, all three vertices must agree on the\n * same ordering of the three edges when computing outline (texture)\n * coordinates. Sometimes this is not possible, as a vertex shared between\n * multiple triangles may become overly constrained. In such cases, vertices are\n * copied and indices are updated until valid outline coordinates can be\n * defined.\n *

\n *\n * @see {@link https://www.researchgate.net/publication/220067637_Fast_and_versatile_texture-based_wireframe_rendering|Fast and versatile texture-based wireframe rendering}\n *\n * @alias PrimitiveOutlineGenerator\n * @constructor\n *\n * @param {number} options Object with the following properties:\n * @param {Uint8Array|Uint16Array|Uint32Array} options.triangleIndices The original triangle indices of the primitive. The constructor takes ownership of this typed array as it will be modified internally. Use the updatedTriangleIndices getter to get the final result.\n * @param {number[]} options.outlineIndices The indices of edges in the triangle from the CESIUM_primitive_outline extension\n * @param {number} options.originalVertexCount The original number of vertices in the primitive\n * @example\n * // The constructor will compute the updated indices and generate outline\n * // coordinates.\n * const outlineGenerator = new PrimitiveOutlineGenerator({\n * triangleIndices: primitive.indices.typedArray,\n * outlineIndices: outlineIndices,\n * originalVertexCount: primitive.attributes[0].count\n * });\n *\n * // Caller must update the indices (the data type may have been upgraded!)\n * primitive.indices.typedArray = outlineGenerator.updatedTriangleIndices;\n * primitive.indices.indexDatatype =\n * IndexDatatype.fromTypedArray(primitive.indices.typedArray);\n *\n * // Create a new attribute for the generated outline coordinates\n * primitive.outlineCoordinates = new ModelComponents.Attribute();\n * // ... initialize as a vec3 attribute\n * primitive.outlineCoordinates.typedArray =\n * outlineGenerator.outlineCoordinates;\n *\n * // Updating an attribute\n * const attribute = primitive.attributes[i];\n * attribute.typedArray = outlineGenerator.updateAttribute(\n * attribute.typedArray\n * );\n *\n * @private\n */\nfunction PrimitiveOutlineGenerator(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const triangleIndices = options.triangleIndices;\n const outlineIndices = options.outlineIndices;\n const originalVertexCount = options.originalVertexCount;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.triangleIndices\", triangleIndices);\n Check.typeOf.object(\"options.outlineIndices\", outlineIndices);\n Check.typeOf.number(\"options.originalVertexCount\", originalVertexCount);\n //>>includeEnd('debug');\n\n /**\n * The triangle indices. It will be modified in place.\n *\n * @type {Uint8Array|Uint16Array|Uint32Array}\n *\n * @private\n */\n this._triangleIndices = triangleIndices;\n\n /**\n * How many vertices were originally in the primitive\n *\n * @type {number}\n *\n * @private\n */\n this._originalVertexCount = originalVertexCount;\n\n /**\n * The outline indices represent edges of the primitive's triangle mesh where\n * outlines must be drawn. This is stored as a hash set for efficient\n * checks of whether an edge is present.\n *\n * @type {EdgeSet}\n *\n * @private\n */\n this._edges = new EdgeSet(outlineIndices, originalVertexCount);\n\n /**\n * The typed array that will store the outline texture coordinates\n * once computed. This typed array should be turned into a vertex attribute\n * when rendering outlines.\n *\n * @type {Float32Array}\n *\n * @private\n */\n this._outlineCoordinatesTypedArray = undefined;\n\n /**\n * Array containing the indices of any vertices that must be copied and\n * appended to the list.\n *\n * @type {number[]}\n *\n * @private\n */\n this._extraVertices = [];\n\n initialize(this);\n}\n\nObject.defineProperties(PrimitiveOutlineGenerator.prototype, {\n /**\n * The updated triangle indices after generating outlines. The caller is for\n * responsible for updating the primitive's indices to use this array.\n *\n * @memberof PrimitiveOutlineGenerator.prototype\n *\n * @type {Uint8Array|Uint16Array|Uint32Array}\n * @readonly\n *\n * @private\n */\n updatedTriangleIndices: {\n get: function () {\n return this._triangleIndices;\n },\n },\n\n /**\n * The computed outline coordinates. The caller is responsible for\n * turning this into a vec3 attribute for rendering.\n *\n * @memberof PrimitiveOutlineGenerator.prototype\n *\n * @type {Float32Array}\n * @readonly\n *\n * @private\n */\n outlineCoordinates: {\n get: function () {\n return this._outlineCoordinatesTypedArray;\n },\n },\n});\n\n/**\n * Initialize the outline generator from the CESIUM_primitive_outline\n * extension data. This updates the triangle indices and generates outline\n * coordinates, but does not update other attributes (see\n * {@link PrimitiveOutlineGenerator#updateAttribute})\n *\n * @param {PrimitiveOutlineGenerator} outlineGenerator The outline generator\n *\n * @private\n */\nfunction initialize(outlineGenerator) {\n // triangle indices may be extended from 16-bits to 32 bits if needed.\n let triangleIndices = outlineGenerator._triangleIndices;\n\n const edges = outlineGenerator._edges;\n const outlineCoordinates = [];\n const extraVertices = outlineGenerator._extraVertices;\n const vertexCount = outlineGenerator._originalVertexCount;\n\n // Dictionary of unmatchable vertex index -> copied vertex index. This is\n // used so we don't copy the same vertex more than necessary.\n const vertexCopies = {};\n\n // For each triangle, adjust vertex data so that the correct edges are outlined.\n for (let i = 0; i < triangleIndices.length; i += 3) {\n let i0 = triangleIndices[i];\n let i1 = triangleIndices[i + 1];\n let i2 = triangleIndices[i + 2];\n\n // Check which edges need to be outlined based on the contents of the\n // outline indices from the extension.\n const all = false; // set this to true to draw a full wireframe.\n const hasEdge01 = all || edges.hasEdge(i0, i1);\n const hasEdge12 = all || edges.hasEdge(i1, i2);\n const hasEdge20 = all || edges.hasEdge(i2, i0);\n\n // Attempt to compute outline coordinates. If no consistent ordering of\n // edges can be computed (due to constraints from adjacent faces), the\n // first attempt may fail. In such cases, make a copy of a vertex and\n // try again. This relaxes the constraints, so the while loop will\n // eventually finish.\n let unmatchableVertexIndex = matchAndStoreCoordinates(\n outlineCoordinates,\n i0,\n i1,\n i2,\n hasEdge01,\n hasEdge12,\n hasEdge20\n );\n while (defined(unmatchableVertexIndex)) {\n // Copy the unmatchable index and try again.\n let copy = vertexCopies[unmatchableVertexIndex];\n\n // Only copy if we haven't already\n if (!defined(copy)) {\n // The new vertex will appear at the end of the vertex list\n copy = vertexCount + extraVertices.length;\n\n // Sometimes the copied vertex will in turn be a copy, so search\n // for the original one\n let original = unmatchableVertexIndex;\n while (original >= vertexCount) {\n original = extraVertices[original - vertexCount];\n }\n\n // Store the original vertex that needs to be copied\n extraVertices.push(original);\n\n // mark that we've seen this unmatchable vertex before so we don't\n // copy it multiple times.\n vertexCopies[unmatchableVertexIndex] = copy;\n }\n\n // Corner case: copying a vertex may overflow the range of an\n // 8- or 16- bit index buffer, so upgrade to a larger data type.\n if (\n copy > MAX_GLTF_UINT16_INDEX &&\n (triangleIndices instanceof Uint16Array ||\n triangleIndices instanceof Uint8Array)\n ) {\n triangleIndices = new Uint32Array(triangleIndices);\n } else if (\n copy > MAX_GLTF_UINT8_INDEX &&\n triangleIndices instanceof Uint8Array\n ) {\n triangleIndices = new Uint16Array(triangleIndices);\n }\n\n // Update the triangle indices buffer to use the copied vertex instead\n // of the original one.\n if (unmatchableVertexIndex === i0) {\n i0 = copy;\n triangleIndices[i] = copy;\n } else if (unmatchableVertexIndex === i1) {\n i1 = copy;\n triangleIndices[i + 1] = copy;\n } else {\n i2 = copy;\n triangleIndices[i + 2] = copy;\n }\n\n // Attempt to generate outline coordinates again. This is more likely\n // to succeed since the copied vertex has no constraints on which order\n // of the 3 edges to use.\n unmatchableVertexIndex = matchAndStoreCoordinates(\n outlineCoordinates,\n i0,\n i1,\n i2,\n hasEdge01,\n hasEdge12,\n hasEdge20\n );\n }\n }\n\n // Store the triangle indices in case we had to expand to 32-bit indices\n outlineGenerator._triangleIndices = triangleIndices;\n outlineGenerator._outlineCoordinatesTypedArray = new Float32Array(\n outlineCoordinates\n );\n}\n\n/**\n * This function attempts to compute a valid ordering of edges for this triangle\n * and if found, computes outline coordinates for the three vertices. If not\n * possible, one of the vertices is returned so it can be copied.\n *\n * @param {number[]} outlineCoordinates An array to store the computed outline coordinates. There are 3 components per vertex. This will be modified in place.\n * @param {number} i0 The index of the first vertex of the triangle.\n * @param {number} i1 The index of the second vertex of the triangle.\n * @param {number} i2 The index of the third vertex of the triangle.\n * @param {boolean} hasEdge01 Whether there is an outline edge between vertices 0 and 1 of the triangle\n * @param {boolean} hasEdge12 Whether there is an outline edge between vertices 1 and 2 of the triangle\n * @param {boolean} hasEdge20 Whether there is an outline edge between vertices 2 and 0 of the triangle\n * @returns {number} If it's not possible to compute consistent outline coordinates for this triangle, the index of the most constrained vertex of i0, i1 and i2 is returned. Otherwise, this function returns undefined to indicate a successful match.\n *\n * @private\n */\nfunction matchAndStoreCoordinates(\n outlineCoordinates,\n i0,\n i1,\n i2,\n hasEdge01,\n hasEdge12,\n hasEdge20\n) {\n const a0 = hasEdge20 ? 1.0 : 0.0;\n const b0 = hasEdge01 ? 1.0 : 0.0;\n const c0 = 0.0;\n\n const i0Mask = computeOrderMask(outlineCoordinates, i0, a0, b0, c0);\n if (i0Mask === 0) {\n return i0;\n }\n\n const a1 = 0.0;\n const b1 = hasEdge01 ? 1.0 : 0.0;\n const c1 = hasEdge12 ? 1.0 : 0.0;\n\n const i1Mask = computeOrderMask(outlineCoordinates, i1, a1, b1, c1);\n if (i1Mask === 0) {\n return i1;\n }\n\n const a2 = hasEdge20 ? 1.0 : 0.0;\n const b2 = 0.0;\n const c2 = hasEdge12 ? 1.0 : 0.0;\n\n const i2Mask = computeOrderMask(outlineCoordinates, i2, a2, b2, c2);\n if (i2Mask === 0) {\n return i2;\n }\n\n const workingOrders = i0Mask & i1Mask & i2Mask;\n\n let a, b, c;\n\n if (workingOrders & (1 << 0)) {\n // 0 - abc\n a = 0;\n b = 1;\n c = 2;\n } else if (workingOrders & (1 << 1)) {\n // 1 - acb\n a = 0;\n c = 1;\n b = 2;\n } else if (workingOrders & (1 << 2)) {\n // 2 - bac\n b = 0;\n a = 1;\n c = 2;\n } else if (workingOrders & (1 << 3)) {\n // 3 - bca\n b = 0;\n c = 1;\n a = 2;\n } else if (workingOrders & (1 << 4)) {\n // 4 - cab\n c = 0;\n a = 1;\n b = 2;\n } else if (workingOrders & (1 << 5)) {\n // 5 - cba\n c = 0;\n b = 1;\n a = 2;\n } else {\n // No ordering works. Report the most constrained vertex (i.e. the one with\n // fewest valid orderings) as unmatched so we copy that one.\n const i0ValidOrderCount = popcount6Bit(i0Mask);\n const i1ValidOrderCount = popcount6Bit(i1Mask);\n const i2ValidOrderCount = popcount6Bit(i2Mask);\n if (\n i0ValidOrderCount < i1ValidOrderCount &&\n i0ValidOrderCount < i2ValidOrderCount\n ) {\n return i0;\n } else if (i1ValidOrderCount < i2ValidOrderCount) {\n return i1;\n }\n return i2;\n }\n\n // We found a valid ordering of the edges, so store the outline coordinates\n // for this triangle.\n const i0Start = i0 * 3;\n outlineCoordinates[i0Start + a] = a0;\n outlineCoordinates[i0Start + b] = b0;\n outlineCoordinates[i0Start + c] = c0;\n\n const i1Start = i1 * 3;\n outlineCoordinates[i1Start + a] = a1;\n outlineCoordinates[i1Start + b] = b1;\n outlineCoordinates[i1Start + c] = c1;\n\n const i2Start = i2 * 3;\n outlineCoordinates[i2Start + a] = a2;\n outlineCoordinates[i2Start + b] = b2;\n outlineCoordinates[i2Start + c] = c2;\n\n // successful match\n return undefined;\n}\n\n/**\n * Each vertex has three coordinates, a, b, and c.\n * a is the coordinate that applies to edge 2-0 for the vertex.\n * b is the coordinate that applies to edge 0-1 for the vertex.\n * c is the coordinate that applies to edge 1-2 for the vertex.\n *\n * A single triangle with all edges highlighted:\n *\n * | a | b | c |\n * | 1 | 1 | 0 |\n * 0\n * / \\\n * / \\\n * edge 0-1 / \\ edge 2-0\n * / \\\n * / \\\n * | a | b | c | 1-----------2 | a | b | c |\n * | 0 | 1 | 1 | edge 1-2 | 1 | 0 | 1 |\n *\n * There are 6 possible orderings of coordinates a, b, and c:\n * 0 - abc\n * 1 - acb\n * 2 - bac\n * 3 - bca\n * 4 - cab\n * 5 - cba\n *\n * All vertices must use the _same ordering_ for the edges to be rendered\n * correctly. So we compute a bitmask for each vertex, where the bit at\n * each position indicates whether that ordering works (i.e. doesn't\n * conflict with already-assigned coordinates) for that vertex.\n *\n * Then we can find an ordering that works for all three vertices with a\n * bitwise AND.\n *\n * @param {number[]} outlineCoordinates The array of outline coordinates\n * @param {number} vertexIndex The index of the vertex to compute the mask for\n * @param {number} a The outline coordinate for edge 2-0\n * @param {number} b The outline coordinate for edge 0-1\n * @param {number} c The outline coordinate for edge 1-2\n * @returns {number} A bitmask with 6 bits where a 1 indicates the corresponding ordering is valid.\n *\n * @private\n */\nfunction computeOrderMask(outlineCoordinates, vertexIndex, a, b, c) {\n const startIndex = vertexIndex * 3;\n const first = outlineCoordinates[startIndex];\n const second = outlineCoordinates[startIndex + 1];\n const third = outlineCoordinates[startIndex + 2];\n\n // If one coordinate is undefined, they all are since matchAndStoreCoordinates sets\n // all 3 components at once. In this case, all orderings are fine.\n if (!defined(first)) {\n return 0b111111;\n }\n\n return (\n ((first === a && second === b && third === c) << 0) |\n ((first === a && second === c && third === b) << 1) |\n ((first === b && second === a && third === c) << 2) |\n ((first === b && second === c && third === a) << 3) |\n ((first === c && second === a && third === b) << 4) |\n ((first === c && second === b && third === a) << 5)\n );\n}\n\n/**\n * Compute the popcount for 6-bit integers (values 0-63). This is the\n * number of 1s in the binary representation of the value.\n *\n * @param {number} value The value to compute the popcount for\n * @returns {number} The number of 1s in the binary representation of value\n *\n * @private\n */\nfunction popcount6Bit(value) {\n return (\n (value & 1) +\n ((value >> 1) & 1) +\n ((value >> 2) & 1) +\n ((value >> 3) & 1) +\n ((value >> 4) & 1) +\n ((value >> 5) & 1)\n );\n}\n\n/**\n * After computing the outline coordinates, some vertices may need to be\n * copied and appended to the end of the list of vertices. This function updates\n * a typed array for a single attribute (e.g. POSITION or NORMAL).\n *\n * @param {Uint8Array|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array} attributeTypedArray The attribute values to update. This function takes ownership of this typed array\n * @returns {Uint8Array|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array} A new typed array that contains the existing attribute values, plus any copied values at the end.\n *\n * @private\n */\nPrimitiveOutlineGenerator.prototype.updateAttribute = function (\n attributeTypedArray\n) {\n const extraVertices = this._extraVertices;\n\n const originalLength = attributeTypedArray.length;\n\n // This is a stride in number of typed elements. For example, a VEC3 would\n // have a stride of 3 (floats)\n const stride = originalLength / this._originalVertexCount;\n\n const extraVerticesLength = extraVertices.length;\n\n // Make a larger typed array of the same type as the input\n const ArrayType = attributeTypedArray.constructor;\n const result = new ArrayType(\n attributeTypedArray.length + extraVerticesLength * stride\n );\n\n // Copy original vertices\n result.set(attributeTypedArray);\n\n // Copy the vertices added for outlining\n for (let i = 0; i < extraVerticesLength; i++) {\n const sourceIndex = extraVertices[i] * stride;\n const resultIndex = originalLength + i * stride;\n for (let j = 0; j < stride; j++) {\n result[resultIndex + j] = result[sourceIndex + j];\n }\n }\n\n return result;\n};\n\n/**\n * Create a mip-mapped lookup texture for rendering outlines. The texture is\n * constant, so it is cached on the context.\n *\n * @param {Context} context The context to use for creating the texture\n * @returns {Texture} The outline lookup texture.\n *\n * @private\n */\nPrimitiveOutlineGenerator.createTexture = function (context) {\n let cache = context.cache.modelOutliningCache;\n if (!defined(cache)) {\n cache = context.cache.modelOutliningCache = {};\n }\n\n if (defined(cache.outlineTexture)) {\n return cache.outlineTexture;\n }\n\n const maxSize = Math.min(4096, ContextLimits.maximumTextureSize);\n\n let size = maxSize;\n const levelZero = createMipLevel(size);\n\n const mipLevels = [];\n\n while (size > 1) {\n size >>= 1;\n mipLevels.push(createMipLevel(size));\n }\n\n const texture = new Texture({\n context: context,\n source: {\n arrayBufferView: levelZero,\n mipLevels: mipLevels,\n },\n width: maxSize,\n height: 1,\n pixelFormat: PixelFormat.LUMINANCE,\n sampler: new Sampler({\n wrapS: TextureWrap.CLAMP_TO_EDGE,\n wrapT: TextureWrap.CLAMP_TO_EDGE,\n minificationFilter: TextureMinificationFilter.LINEAR_MIPMAP_LINEAR,\n magnificationFilter: TextureMagnificationFilter.LINEAR,\n }),\n });\n\n cache.outlineTexture = texture;\n\n return texture;\n};\n\n/**\n * Create an outline lookup texture for a single mip level. This is a texture of\n * mostly 0 values, except for the last value which is brighter to indicate\n * the outline.\n *\n * @param {number} size The width of the texture for this mip level\n * @returns {Uint8Array} A typed array containing the texels of the mip level\n *\n * @private\n */\nfunction createMipLevel(size) {\n const texture = new Uint8Array(size);\n\n // This lookup texture creates an outline with width 0.75 px in screen space.\n texture[size - 1] = 192;\n\n // As we reach the top of the mip pyramid, a single set pixel becomes a\n // significant portion of the texture. This doesn't look great when zoomed\n // out, so attenuate the value by 50% at each level.\n if (size === 8) {\n texture[size - 1] = 96;\n } else if (size === 4) {\n texture[size - 1] = 48;\n } else if (size === 2) {\n texture[size - 1] = 24;\n } else if (size === 1) {\n texture[size - 1] = 12;\n }\n return texture;\n}\n\n/**\n * A hash set that provides quick lookups of whether an edge exists between\n * two vertices.\n *\n * @alias EdgeSet\n * @constructor\n *\n * @param {number[]} edgeIndices An array of vertex indices with an even number of elements where each pair of indices defines an edge.\n * @param {number} originalVertexCount The original number of vertices. This is used for computing a hash function.\n *\n * @private\n */\nfunction EdgeSet(edgeIndices, originalVertexCount) {\n /**\n * Original number of vertices in the primitive. This is used for computing\n * the hash key\n *\n * @type {number}\n *\n * @private\n */\n this._originalVertexCount = originalVertexCount;\n\n /**\n * The internal hash set used to store the edges. Edges are hashed as follows:\n *

\n * smallerVertexIndex * originalVertexCount + biggerVertexIndex\n *

\n * @type {Set}\n *\n * @private\n */\n this._edges = new Set();\n for (let i = 0; i < edgeIndices.length; i += 2) {\n const a = edgeIndices[i];\n const b = edgeIndices[i + 1];\n const small = Math.min(a, b);\n const big = Math.max(a, b);\n const hash = small * this._originalVertexCount + big;\n this._edges.add(hash);\n }\n}\n\n/**\n * Check if an edge exists in the set. The order of the input vertices does\n * not matter.\n * @param {number} a The first index\n * @param {number} b The second index\n * @returns {boolean} true if there is an edge between a and b\n *\n * @private\n */\nEdgeSet.prototype.hasEdge = function (a, b) {\n const small = Math.min(a, b);\n const big = Math.max(a, b);\n const hash = small * this._originalVertexCount + big;\n return this._edges.has(hash);\n};\n\nexport default PrimitiveOutlineGenerator;\n", "import Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport AttributeType from \"./AttributeType.js\";\nimport ModelComponents from \"./ModelComponents.js\";\nimport PrimitiveOutlineGenerator from \"./Model/PrimitiveOutlineGenerator.js\";\n\n/**\n * Simple struct for tracking whether an attribute will be loaded as a buffer\n * or typed array after post-processing.\n *\n * @alias PrimitiveLoadPlan.AttributeLoadPlan\n * @constructor\n *\n * @param {ModelComponents.Attribute} attribute The attribute to be updated\n *\n * @private\n */\nfunction AttributeLoadPlan(attribute) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"attribute\", attribute);\n //>>includeEnd('debug');\n\n /**\n * The attribute to track.\n *\n * @type {ModelComponents.Attribute}\n * @readonly\n * @private\n */\n this.attribute = attribute;\n\n /**\n * Whether the attribute will be loaded as a GPU buffer by the time\n * {@link PrimitiveLoadPlan#postProcess} is finished.\n *\n * @type {boolean}\n * @private\n */\n this.loadBuffer = false;\n\n /**\n * Whether the attribute will be loaded as a packed typed array by the time\n * {@link PrimitiveLoadPlan#postProcess} is finished.\n *\n * @type {boolean}\n * @private\n */\n this.loadTypedArray = false;\n}\n\n/**\n * Simple struct for tracking whether an index buffer will be loaded as a buffer\n * or typed array after post-processing.\n *\n * @alias PrimitiveLoadPlan.IndicesLoadPlan\n * @constructor\n *\n * @param {ModelComponents.Indices} indices The indices to be updated\n *\n * @private\n */\nfunction IndicesLoadPlan(indices) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"indices\", indices);\n //>>includeEnd('debug');\n\n /**\n * The indices to track.\n *\n * @type {ModelComponents.Indices}\n * @readonly\n * @private\n */\n this.indices = indices;\n\n /**\n * Whether the indices will be loaded as a GPU buffer by the time\n * {@link PrimitiveLoadPlan#postProcess} is finished.\n *\n * @type {boolean}\n * @private\n */\n this.loadBuffer = false;\n\n /**\n * Whether the indices will be loaded as a typed array copy of the GPU\n * buffer by the time {@link PrimitiveLoadPlan#postProcess} is finished.\n *\n * @type {boolean}\n * @private\n */\n this.loadTypedArray = false;\n}\n\n/**\n * Primitives may need post-processing steps after their attributes and indices\n * have loaded, such as generating outlines for the CESIUM_primitive_outline glTF\n * extension. This object tracks what indices and attributes need to be\n * post-processed.\n *\n * @alias PrimitiveLoadPlan\n * @constructor\n *\n * @param {ModelComponents.Primitive} primitive The primitive to track\n *\n * @private\n */\nfunction PrimitiveLoadPlan(primitive) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"primitive\", primitive);\n //>>includeEnd('debug');\n\n /**\n * The primitive to track.\n *\n * @type {ModelComponents.Primitive}\n * @readonly\n * @private\n */\n this.primitive = primitive;\n\n /**\n * A flat list of attributes that need to be post-processed. This includes\n * both regular attributes and morph target attributes.\n *\n * @type {PrimitiveLoadPlan.AttributeLoadPlan[]}\n * @private\n */\n this.attributePlans = [];\n\n /**\n * Information about the triangle indices that need to be post-processed,\n * if they exist.\n *\n * @type {PrimitiveLoadPlan.IndicesLoadPlan}\n * @private\n */\n this.indicesPlan = undefined;\n\n /**\n * Set this true to indicate that the primitive has the\n * CESIUM_primitive_outline extension and needs to be post-processed\n *\n * @type {boolean}\n * @private\n */\n this.needsOutlines = false;\n\n /**\n * The outline edge indices from the CESIUM_primitive_outline extension\n *\n * @type {number[]}\n * @private\n */\n this.outlineIndices = undefined;\n}\n\n/**\n * Apply post-processing steps that may modify geometry such as generating\n * outline coordinates. If no post-processing steps are needed, this function\n * is a no-op.\n *\n * @param {Context} context The context for generating buffers on the GPU\n */\nPrimitiveLoadPlan.prototype.postProcess = function (context) {\n // Handle CESIUM_primitive_outline. This modifies indices and attributes and\n // also generates a new attribute for the outline coordinates. These steps\n // are synchronous.\n if (this.needsOutlines) {\n generateOutlines(this);\n generateBuffers(this, context);\n }\n};\n\nfunction generateOutlines(loadPlan) {\n const primitive = loadPlan.primitive;\n const indices = primitive.indices;\n\n const vertexCount = primitive.attributes[0].count;\n\n const generator = new PrimitiveOutlineGenerator({\n triangleIndices: indices.typedArray,\n outlineIndices: loadPlan.outlineIndices,\n originalVertexCount: vertexCount,\n });\n\n // The generator modifies/adds indices. In some uncommon cases it may have\n // to upgrade to 16- or 32-bit indices so the datatype may change.\n indices.typedArray = generator.updatedTriangleIndices;\n indices.indexDatatype = IndexDatatype.fromTypedArray(indices.typedArray);\n\n // The outline generator creates a new attribute for the outline coordinates\n // that are used with a lookup texture.\n const outlineCoordinates = makeOutlineCoordinatesAttribute(\n generator.outlineCoordinates\n );\n const outlineCoordinatesPlan = new AttributeLoadPlan(outlineCoordinates);\n outlineCoordinatesPlan.loadBuffer = true;\n outlineCoordinatesPlan.loadTypedArray = false;\n loadPlan.attributePlans.push(outlineCoordinatesPlan);\n primitive.outlineCoordinates = outlineCoordinatesPlan.attribute;\n\n // Some vertices may be copied due to the addition of the new attribute\n // which may have multiple values at a vertex depending on the face\n const attributePlans = loadPlan.attributePlans;\n const attributesLength = loadPlan.attributePlans.length;\n for (let i = 0; i < attributesLength; i++) {\n const attribute = attributePlans[i].attribute;\n attribute.typedArray = generator.updateAttribute(attribute.typedArray);\n }\n}\n\nfunction makeOutlineCoordinatesAttribute(outlineCoordinatesTypedArray) {\n const attribute = new ModelComponents.Attribute();\n attribute.name = \"_OUTLINE_COORDINATES\";\n attribute.typedArray = outlineCoordinatesTypedArray;\n attribute.componentDatatype = ComponentDatatype.FLOAT;\n attribute.type = AttributeType.VEC3;\n attribute.normalized = false;\n attribute.count = outlineCoordinatesTypedArray.length / 3;\n\n return attribute;\n}\n\nfunction generateBuffers(loadPlan, context) {\n generateAttributeBuffers(loadPlan.attributePlans, context);\n\n if (defined(loadPlan.indicesPlan)) {\n generateIndexBuffers(loadPlan.indicesPlan, context);\n }\n}\n\nfunction generateAttributeBuffers(attributePlans, context) {\n const attributesLength = attributePlans.length;\n for (let i = 0; i < attributesLength; i++) {\n const attributePlan = attributePlans[i];\n const attribute = attributePlan.attribute;\n const typedArray = attribute.typedArray;\n\n if (attributePlan.loadBuffer) {\n const buffer = Buffer.createVertexBuffer({\n typedArray: typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n });\n buffer.vertexArrayDestroyable = false;\n attribute.buffer = buffer;\n }\n\n if (!attributePlan.loadTypedArray) {\n attribute.typedArray = undefined;\n }\n }\n}\n\nfunction generateIndexBuffers(indicesPlan, context) {\n const indices = indicesPlan.indices;\n if (indicesPlan.loadBuffer) {\n const buffer = Buffer.createIndexBuffer({\n typedArray: indices.typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: indices.indexDatatype,\n });\n indices.buffer = buffer;\n buffer.vertexArrayDestroyable = false;\n }\n\n if (!indicesPlan.loadTypedArray) {\n indices.typedArray = undefined;\n }\n}\n\nPrimitiveLoadPlan.AttributeLoadPlan = AttributeLoadPlan;\nPrimitiveLoadPlan.IndicesLoadPlan = IndicesLoadPlan;\nexport default PrimitiveLoadPlan;\n", "import defaultValue from \"../Core/defaultValue.js\";\n\n/**\n * Image formats supported by the browser.\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.webp=false] Whether the browser supports WebP images.\n * @param {boolean} [options.basis=false] Whether the browser supports compressed textures required to view KTX2 + Basis Universal images.\n *\n * @private\n */\nfunction SupportedImageFormats(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n this.webp = defaultValue(options.webp, false);\n this.basis = defaultValue(options.basis, false);\n}\n\nexport default SupportedImageFormats;\n", "import ArticulationStageType from \"../Core/ArticulationStageType.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport Credit from \"../Core/Credit.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport InterpolationType from \"../Core/InterpolationType.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport Quaternion from \"../Core/Quaternion.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Sampler from \"../Renderer/Sampler.js\";\nimport getAccessorByteStride from \"./GltfPipeline/getAccessorByteStride.js\";\nimport getComponentReader from \"./GltfPipeline/getComponentReader.js\";\nimport numberOfComponentsForType from \"./GltfPipeline/numberOfComponentsForType.js\";\nimport GltfStructuralMetadataLoader from \"./GltfStructuralMetadataLoader.js\";\nimport AttributeType from \"./AttributeType.js\";\nimport Axis from \"./Axis.js\";\nimport GltfLoaderUtil from \"./GltfLoaderUtil.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport InstanceAttributeSemantic from \"./InstanceAttributeSemantic.js\";\nimport ModelComponents from \"./ModelComponents.js\";\nimport PrimitiveLoadPlan from \"./PrimitiveLoadPlan.js\";\nimport ResourceCache from \"./ResourceCache.js\";\nimport ResourceLoader from \"./ResourceLoader.js\";\nimport SupportedImageFormats from \"./SupportedImageFormats.js\";\nimport VertexAttributeSemantic from \"./VertexAttributeSemantic.js\";\n\nconst Attribute = ModelComponents.Attribute;\nconst Indices = ModelComponents.Indices;\nconst FeatureIdAttribute = ModelComponents.FeatureIdAttribute;\nconst FeatureIdTexture = ModelComponents.FeatureIdTexture;\nconst FeatureIdImplicitRange = ModelComponents.FeatureIdImplicitRange;\nconst MorphTarget = ModelComponents.MorphTarget;\nconst Primitive = ModelComponents.Primitive;\nconst Instances = ModelComponents.Instances;\nconst Skin = ModelComponents.Skin;\nconst Node = ModelComponents.Node;\nconst AnimatedPropertyType = ModelComponents.AnimatedPropertyType;\nconst AnimationSampler = ModelComponents.AnimationSampler;\nconst AnimationTarget = ModelComponents.AnimationTarget;\nconst AnimationChannel = ModelComponents.AnimationChannel;\nconst Animation = ModelComponents.Animation;\nconst ArticulationStage = ModelComponents.ArticulationStage;\nconst Articulation = ModelComponents.Articulation;\nconst Asset = ModelComponents.Asset;\nconst Scene = ModelComponents.Scene;\nconst Components = ModelComponents.Components;\nconst MetallicRoughness = ModelComponents.MetallicRoughness;\nconst SpecularGlossiness = ModelComponents.SpecularGlossiness;\nconst Material = ModelComponents.Material;\n\n/**\n * States of the glTF loading process. These states also apply to\n * asynchronous texture loading unless otherwise noted\n *\n * @enum {number}\n *\n * @private\n */\nconst GltfLoaderState = {\n /**\n * The initial state of the glTF loader before load() is called.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n NOT_LOADED: 0,\n /**\n * The state of the loader while waiting for the glTF JSON loader promise\n * to resolve.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n LOADING: 1,\n /**\n * The state of the loader once the glTF JSON is loaded but before\n * process() is called.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n LOADED: 2,\n /**\n * The state of the loader while parsing the glTF and creating GPU resources\n * as needed.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n PROCESSING: 3,\n /**\n * For some features like handling CESIUM_primitive_outlines, the geometry\n * must be modified after it is loaded. The post-processing state handles\n * any geometry modification (if needed).\n *

\n * This state is not used for asynchronous texture loading.\n *

\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n POST_PROCESSING: 4,\n /**\n * Once the processing/post-processing states are finished, the loader\n * enters the processed state (sometimes from a promise chain). The next\n * call to process() will advance to the ready state.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n PROCESSED: 5,\n /**\n * When the loader reaches the ready state, the loaders' promise will be\n * resolved.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n READY: 6,\n /**\n * If an error occurs at any point, the loader switches to the failed state.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n FAILED: 7,\n /**\n * If unload() is called, the loader switches to the unloaded state.\n *\n * @type {number}\n * @constant\n *\n * @private\n */\n UNLOADED: 8,\n};\n\n/**\n * Loads a glTF model.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GltfLoader\n * @constructor\n * @augments ResourceLoader\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.gltfResource The {@link Resource} containing the glTF. This is often the path of the .gltf or .glb file, but may also be the path of the .b3dm, .i3dm, or .cmpt file containing the embedded glb. .cmpt resources should have a URI fragment indicating the index of the inner content to which the glb belongs in order to individually identify the glb in the cache, e.g. http://example.com/tile.cmpt#index=2.\n * @param {Resource} [options.baseResource] The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {Uint8Array} [options.typedArray] The typed array containing the glTF contents, e.g. from a .b3dm, .i3dm, or .cmpt file.\n * @param {object} [options.gltfJson] A parsed glTF JSON file instead of passing it in as a typed array.\n * @param {boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the glTF is loaded.\n * @param {Axis} [options.upAxis=Axis.Y] The up-axis of the glTF model.\n * @param {Axis} [options.forwardAxis=Axis.Z] The forward-axis of the glTF model.\n * @param {boolean} [options.loadAttributesAsTypedArray=false] Load all attributes and indices as typed arrays instead of GPU buffers. If the attributes are interleaved in the glTF they will be de-interleaved in the typed array.\n * @param {boolean} [options.loadAttributesFor2D=false] If true, load the positions buffer and any instanced attribute buffers as typed arrays for accurately projecting models to 2D.\n * @param {boolean} [options.loadIndicesForWireframe=false] If true, load the index buffer as both a buffer and typed array. The latter is useful for creating wireframe indices in WebGL1.\n * @param {boolean} [options.loadPrimitiveOutline=true] If true, load outlines from the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time.\n * @param {boolean} [options.loadForClassification=false] If true and if the model has feature IDs, load the feature IDs and indices as typed arrays. This is useful for batching features for classification.\n * @param {boolean} [options.renameBatchIdSemantic=false] If true, rename _BATCHID or BATCHID to _FEATURE_ID_0. This is used for .b3dm models\n * @private\n */\nfunction GltfLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const gltfResource = options.gltfResource;\n let baseResource = options.baseResource;\n const typedArray = options.typedArray;\n const releaseGltfJson = defaultValue(options.releaseGltfJson, false);\n const asynchronous = defaultValue(options.asynchronous, true);\n const incrementallyLoadTextures = defaultValue(\n options.incrementallyLoadTextures,\n true\n );\n const upAxis = defaultValue(options.upAxis, Axis.Y);\n const forwardAxis = defaultValue(options.forwardAxis, Axis.Z);\n const loadAttributesAsTypedArray = defaultValue(\n options.loadAttributesAsTypedArray,\n false\n );\n const loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false);\n const loadIndicesForWireframe = defaultValue(\n options.loadIndicesForWireframe,\n false\n );\n const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true);\n const loadForClassification = defaultValue(\n options.loadForClassification,\n false\n );\n const renameBatchIdSemantic = defaultValue(\n options.renameBatchIdSemantic,\n false\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.gltfResource\", gltfResource);\n //>>includeEnd('debug');\n\n baseResource = defined(baseResource) ? baseResource : gltfResource.clone();\n\n this._gltfJson = options.gltfJson;\n this._gltfResource = gltfResource;\n this._baseResource = baseResource;\n this._typedArray = typedArray;\n this._releaseGltfJson = releaseGltfJson;\n this._asynchronous = asynchronous;\n this._incrementallyLoadTextures = incrementallyLoadTextures;\n this._upAxis = upAxis;\n this._forwardAxis = forwardAxis;\n this._loadAttributesAsTypedArray = loadAttributesAsTypedArray;\n this._loadAttributesFor2D = loadAttributesFor2D;\n this._loadIndicesForWireframe = loadIndicesForWireframe;\n this._loadPrimitiveOutline = loadPrimitiveOutline;\n this._loadForClassification = loadForClassification;\n this._renameBatchIdSemantic = renameBatchIdSemantic;\n\n // When loading EXT_feature_metadata, the feature tables and textures\n // are now stored as arrays like the newer EXT_structural_metadata extension.\n // This requires sorting the dictionary keys for a consistent ordering.\n this._sortedPropertyTableIds = undefined;\n this._sortedFeatureTextureIds = undefined;\n\n this._gltfJsonLoader = undefined;\n this._state = GltfLoaderState.NOT_LOADED;\n this._textureState = GltfLoaderState.NOT_LOADED;\n this._promise = undefined;\n this._processError = undefined;\n this._textureErrors = [];\n\n // Information about whether to load primitives as typed arrays or buffers,\n // and whether post-processing is needed after loading (e.g. for\n // generating outlines)\n this._primitiveLoadPlans = [];\n\n // Loaders that need to be processed before the glTF becomes ready\n this._loaderPromises = [];\n this._textureLoaders = [];\n this._texturesPromises = [];\n this._textureCallbacks = [];\n this._bufferViewLoaders = [];\n this._geometryLoaders = [];\n this._geometryCallbacks = [];\n this._structuralMetadataLoader = undefined;\n this._loadResourcesPromise = undefined;\n this._resourcesLoaded = false;\n this._texturesLoaded = false;\n\n // In some cases where geometry post-processing is needed (like generating\n // outlines) new attributes are added that may have GPU resources attached.\n // The GltfLoader will own the resources and store them here.\n this._postProcessBuffers = [];\n\n // Loaded results\n this._components = undefined;\n}\n\nif (defined(Object.create)) {\n GltfLoader.prototype = Object.create(ResourceLoader.prototype);\n GltfLoader.prototype.constructor = GltfLoader;\n}\n\nObject.defineProperties(GltfLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GltfLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return undefined;\n },\n },\n /**\n * The loaded components.\n *\n * @memberof GltfLoader.prototype\n *\n * @type {ModelComponents.Components}\n * @readonly\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n /**\n * The loaded glTF json.\n *\n * @memberof GltfLoader.prototype\n *\n * @type {object}\n * @readonly\n * @private\n */\n gltfJson: {\n get: function () {\n if (defined(this._gltfJsonLoader)) {\n return this._gltfJsonLoader.gltf;\n }\n return this._gltfJson;\n },\n },\n /**\n * Returns true if textures are loaded separately from the other glTF resources.\n *\n * @memberof GltfLoader.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n incrementallyLoadTextures: {\n get: function () {\n return this._incrementallyLoadTextures;\n },\n },\n /**\n * true if textures are loaded, useful when incrementallyLoadTextures is true\n *\n * @memberof GltfLoader.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n texturesLoaded: {\n get: function () {\n return this._texturesLoaded;\n },\n },\n});\n\n/**\n * Loads the gltf object\n */\nasync function loadGltfJson(loader) {\n loader._state = GltfLoaderState.LOADING;\n loader._textureState = GltfLoaderState.LOADING;\n\n try {\n const gltfJsonLoader = ResourceCache.getGltfJsonLoader({\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n typedArray: loader._typedArray,\n gltfJson: loader._gltfJson,\n });\n loader._gltfJsonLoader = gltfJsonLoader;\n await gltfJsonLoader.load();\n\n if (\n loader.isDestroyed() ||\n loader.isUnloaded() ||\n gltfJsonLoader.isDestroyed()\n ) {\n return;\n }\n\n loader._state = GltfLoaderState.LOADED;\n loader._textureState = GltfLoaderState.LOADED;\n\n return loader;\n } catch (error) {\n if (loader.isDestroyed()) {\n return;\n }\n\n loader._state = GltfLoaderState.FAILED;\n loader._textureState = GltfLoaderState.FAILED;\n handleError(loader, error);\n }\n}\n\nasync function loadResources(loader, frameState) {\n if (!FeatureDetection.supportsWebP.initialized) {\n await FeatureDetection.supportsWebP.initialize();\n }\n\n const supportedImageFormats = new SupportedImageFormats({\n webp: FeatureDetection.supportsWebP(),\n basis: frameState.context.supportsBasis,\n });\n\n // Parse the glTF which populates the loaders arrays. Loading promises will be created, and will\n // resolve once the loaders are ready (i.e. all external resources\n // have been fetched and all GPU resources have been created). Loaders that\n // create GPU resources need to be processed every frame until they become\n // ready since the JobScheduler is not able to execute all jobs in a single\n // frame. Any promise failures are collected, and will be handled synchronously in process(). Also note that it's fine to call process before a loader is ready\n // to process or after it has failed; nothing will happen.\n const gltf = loader.gltfJson;\n const promise = parse(loader, gltf, supportedImageFormats, frameState);\n\n // All resource loaders have been created, so we can begin processing\n loader._state = GltfLoaderState.PROCESSING;\n loader._textureState = GltfLoaderState.PROCESSING;\n\n if (defined(loader._gltfJsonLoader) && loader._releaseGltfJson) {\n // Check that the glTF JSON loader is still defined before trying to unload it.\n // It can be unloaded if the glTF loader is destroyed.\n ResourceCache.unload(loader._gltfJsonLoader);\n loader._gltfJsonLoader = undefined;\n }\n\n return promise;\n}\n\n/**\n * Loads the resource.\n * @returns {Promise.} A promise which resolves to the loader when the resource loading is completed.\n * @exception {RuntimeError} Unsupported glTF version\n * @exception {RuntimeError} Unsupported glTF Extension\n * @private\n */\nGltfLoader.prototype.load = async function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._promise = loadGltfJson(this);\n return this._promise;\n};\n\nfunction handleError(gltfLoader, error) {\n gltfLoader.unload();\n const errorMessage = \"Failed to load glTF\";\n throw gltfLoader.getError(errorMessage, error);\n}\n\nfunction processLoaders(loader, frameState) {\n let i;\n let ready = true;\n const geometryLoaders = loader._geometryLoaders;\n const geometryLoadersLength = geometryLoaders.length;\n for (i = 0; i < geometryLoadersLength; ++i) {\n const geometryReady = geometryLoaders[i].process(frameState);\n if (geometryReady && defined(loader._geometryCallbacks[i])) {\n loader._geometryCallbacks[i]();\n loader._geometryCallbacks[i] = undefined;\n }\n ready = ready && geometryReady;\n }\n\n const structuralMetadataLoader = loader._structuralMetadataLoader;\n if (defined(structuralMetadataLoader)) {\n const metadataReady = structuralMetadataLoader.process(frameState);\n if (metadataReady) {\n loader._components.structuralMetadata =\n structuralMetadataLoader.structuralMetadata;\n }\n ready = ready && metadataReady;\n }\n\n if (ready) {\n // Geometry requires further processing\n loader._state = GltfLoaderState.POST_PROCESSING;\n }\n}\n\nfunction postProcessGeometry(loader, context) {\n // Apply post-processing steps on geometry such as\n // updating attributes for rendering outlines.\n const loadPlans = loader._primitiveLoadPlans;\n const length = loadPlans.length;\n for (let i = 0; i < length; i++) {\n const loadPlan = loadPlans[i];\n loadPlan.postProcess(context);\n\n if (loadPlan.needsOutlines) {\n // The glTF loader takes ownership of any buffers generated in the\n // post-process stage since they were created after the geometry loaders\n // finished. This way they can be destroyed when the loader is destroyed.\n gatherPostProcessBuffers(loader, loadPlan);\n }\n }\n}\n\nfunction gatherPostProcessBuffers(loader, primitiveLoadPlan) {\n const buffers = loader._postProcessBuffers;\n const primitive = primitiveLoadPlan.primitive;\n\n const outlineCoordinates = primitive.outlineCoordinates;\n if (defined(outlineCoordinates)) {\n // outline coordinates are always loaded as a buffer.\n buffers.push(outlineCoordinates.buffer);\n }\n\n // to do post-processing, all the attributes are loaded as typed arrays\n // so if a buffer exists, it was newly generated\n const attributes = primitive.attributes;\n const length = attributes.length;\n for (let i = 0; i < length; i++) {\n const attribute = attributes[i];\n if (defined(attribute.buffer)) {\n buffers.push(attribute.buffer);\n }\n }\n\n // Similarly for the indices.\n const indices = primitive.indices;\n if (defined(indices) && defined(indices.buffer)) {\n buffers.push(indices.buffer);\n }\n}\n\n/**\n * Process loaders other than textures\n * @private\n */\nGltfLoader.prototype._process = function (frameState) {\n if (this._state === GltfLoaderState.READY) {\n return true;\n }\n\n if (this._state === GltfLoaderState.PROCESSING) {\n processLoaders(this, frameState);\n }\n\n if (\n this._resourcesLoaded &&\n this._state === GltfLoaderState.POST_PROCESSING\n ) {\n postProcessGeometry(this, frameState.context);\n this._state = GltfLoaderState.PROCESSED;\n }\n\n if (this._resourcesLoaded && this._state === GltfLoaderState.PROCESSED) {\n // The buffer views can be unloaded once the data is copied.\n unloadBufferViewLoaders(this);\n\n // Similarly, if the glTF was loaded from a typed array, release the memory\n this._typedArray = undefined;\n\n this._state = GltfLoaderState.READY;\n return true;\n }\n\n return false;\n};\n\n/**\n * Process textures other than textures\n * @private\n */\nGltfLoader.prototype._processTextures = function (frameState) {\n if (this._textureState === GltfLoaderState.READY) {\n return true;\n }\n\n if (this._textureState !== GltfLoaderState.PROCESSING) {\n return false;\n }\n\n let i;\n let ready = true;\n const textureLoaders = this._textureLoaders;\n const textureLoadersLength = textureLoaders.length;\n for (i = 0; i < textureLoadersLength; ++i) {\n const textureReady = textureLoaders[i].process(frameState);\n if (textureReady && defined(this._textureCallbacks[i])) {\n this._textureCallbacks[i]();\n this._textureCallbacks[i] = undefined;\n }\n\n ready = ready && textureReady;\n }\n\n if (!ready) {\n return false;\n }\n\n this._textureState = GltfLoaderState.READY;\n this._texturesLoaded = true;\n return true;\n};\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGltfLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (\n this._state === GltfLoaderState.LOADED &&\n !defined(this._loadResourcesPromise)\n ) {\n this._loadResourcesPromise = loadResources(this, frameState)\n .then(() => {\n this._resourcesLoaded = true;\n })\n .catch((error) => {\n this._processError = error;\n });\n }\n\n if (defined(this._processError)) {\n this._state = GltfLoaderState.FAILED;\n const error = this._processError;\n this._processError = undefined;\n handleError(this, error);\n }\n\n // Pop the next error of the list in case there are multiple\n const textureError = this._textureErrors.pop();\n if (defined(textureError)) {\n // There shouldn't be the need to completely unload in this case. Just throw the error.\n const error = this.getError(\"Failed to load glTF texture\", textureError);\n error.name = \"TextureError\";\n throw error;\n }\n\n if (this._state === GltfLoaderState.FAILED) {\n return false;\n }\n\n let ready = false;\n try {\n ready = this._process(frameState);\n } catch (error) {\n this._state = GltfLoaderState.FAILED;\n handleError(this, error);\n }\n\n // Since textures can be loaded independently and are handled through a separate promise, they are processed in their own function\n let texturesReady = false;\n try {\n texturesReady = this._processTextures(frameState);\n } catch (error) {\n this._textureState = GltfLoaderState.FAILED;\n handleError(this, error);\n }\n\n if (this._incrementallyLoadTextures) {\n return ready;\n }\n\n return ready && texturesReady;\n};\n\nfunction getVertexBufferLoader(\n loader,\n gltf,\n accessorId,\n semantic,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n) {\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n\n const vertexBufferLoader = ResourceCache.getVertexBufferLoader({\n gltf: gltf,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n frameState: frameState,\n bufferViewId: bufferViewId,\n draco: draco,\n attributeSemantic: semantic,\n accessorId: accessorId,\n asynchronous: loader._asynchronous,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n return vertexBufferLoader;\n}\n\nfunction getIndexBufferLoader(\n loader,\n gltf,\n accessorId,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n) {\n const indexBufferLoader = ResourceCache.getIndexBufferLoader({\n gltf: gltf,\n accessorId: accessorId,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n frameState: frameState,\n draco: draco,\n asynchronous: loader._asynchronous,\n loadBuffer: loadBuffer,\n loadTypedArray: loadTypedArray,\n });\n\n return indexBufferLoader;\n}\n\nfunction getBufferViewLoader(loader, gltf, bufferViewId) {\n const bufferViewLoader = ResourceCache.getBufferViewLoader({\n gltf: gltf,\n bufferViewId: bufferViewId,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n });\n\n loader._bufferViewLoaders.push(bufferViewLoader);\n\n return bufferViewLoader;\n}\n\nfunction getPackedTypedArray(gltf, accessor, bufferViewTypedArray) {\n let byteOffset = accessor.byteOffset;\n const byteStride = getAccessorByteStride(gltf, accessor);\n const count = accessor.count;\n const componentCount = numberOfComponentsForType(accessor.type);\n const componentType = accessor.componentType;\n const componentByteLength = ComponentDatatype.getSizeInBytes(componentType);\n const defaultByteStride = componentByteLength * componentCount;\n const componentsLength = count * componentCount;\n\n if (byteStride === defaultByteStride) {\n // Copy the typed array and let the underlying ArrayBuffer be freed\n bufferViewTypedArray = new Uint8Array(bufferViewTypedArray);\n return ComponentDatatype.createArrayBufferView(\n componentType,\n bufferViewTypedArray.buffer,\n bufferViewTypedArray.byteOffset + byteOffset,\n componentsLength\n );\n }\n\n const accessorTypedArray = ComponentDatatype.createTypedArray(\n componentType,\n componentsLength\n );\n\n const dataView = new DataView(bufferViewTypedArray.buffer);\n const components = new Array(componentCount);\n const componentReader = getComponentReader(accessor.componentType);\n byteOffset = bufferViewTypedArray.byteOffset + byteOffset;\n\n for (let i = 0; i < count; ++i) {\n componentReader(\n dataView,\n byteOffset,\n componentCount,\n componentByteLength,\n components\n );\n for (let j = 0; j < componentCount; ++j) {\n accessorTypedArray[i * componentCount + j] = components[j];\n }\n byteOffset += byteStride;\n }\n\n return accessorTypedArray;\n}\n\nfunction loadDefaultAccessorValues(accessor, values) {\n const accessorType = accessor.type;\n if (accessorType === AttributeType.SCALAR) {\n return values.fill(0);\n }\n\n const MathType = AttributeType.getMathType(accessorType);\n return values.fill(MathType.clone(MathType.ZERO));\n}\n\nfunction loadAccessorValues(accessor, typedArray, values, useQuaternion) {\n const accessorType = accessor.type;\n const accessorCount = accessor.count;\n\n if (accessorType === AttributeType.SCALAR) {\n for (let i = 0; i < accessorCount; i++) {\n values[i] = typedArray[i];\n }\n } else if (accessorType === AttributeType.VEC4 && useQuaternion) {\n for (let i = 0; i < accessorCount; i++) {\n values[i] = Quaternion.unpack(typedArray, i * 4);\n }\n } else {\n const MathType = AttributeType.getMathType(accessorType);\n const numberOfComponents = AttributeType.getNumberOfComponents(\n accessorType\n );\n\n for (let i = 0; i < accessorCount; i++) {\n values[i] = MathType.unpack(typedArray, i * numberOfComponents);\n }\n }\n\n return values;\n}\n\nasync function loadAccessorBufferView(\n loader,\n bufferViewLoader,\n gltf,\n accessor,\n useQuaternion,\n values\n) {\n await bufferViewLoader.load();\n if (loader.isDestroyed()) {\n return;\n }\n\n const bufferViewTypedArray = bufferViewLoader.typedArray;\n const typedArray = getPackedTypedArray(gltf, accessor, bufferViewTypedArray);\n\n useQuaternion = defaultValue(useQuaternion, false);\n loadAccessorValues(accessor, typedArray, values, useQuaternion);\n}\n\nfunction loadAccessor(loader, gltf, accessorId, useQuaternion) {\n const accessor = gltf.accessors[accessorId];\n const accessorCount = accessor.count;\n const values = new Array(accessorCount);\n\n const bufferViewId = accessor.bufferView;\n if (defined(bufferViewId)) {\n const bufferViewLoader = getBufferViewLoader(loader, gltf, bufferViewId);\n const promise = loadAccessorBufferView(\n loader,\n bufferViewLoader,\n gltf,\n accessor,\n useQuaternion,\n values\n );\n loader._loaderPromises.push(promise);\n\n return values;\n }\n\n return loadDefaultAccessorValues(accessor, values);\n}\n\nfunction fromArray(MathType, values) {\n if (!defined(values)) {\n return undefined;\n }\n\n if (MathType === Number) {\n return values[0];\n }\n\n return MathType.unpack(values);\n}\n\nfunction getDefault(MathType) {\n if (MathType === Number) {\n return 0.0;\n }\n\n return new MathType(); // defaults to 0.0 for all types\n}\n\nfunction getQuantizationDivisor(componentDatatype) {\n switch (componentDatatype) {\n case ComponentDatatype.BYTE:\n return 127;\n case ComponentDatatype.UNSIGNED_BYTE:\n return 255;\n case ComponentDatatype.SHORT:\n return 32767;\n case ComponentDatatype.UNSIGNED_SHORT:\n return 65535;\n default:\n return 1.0;\n }\n}\n\nconst minimumBoundsByType = {\n VEC2: new Cartesian2(-1.0, -1.0),\n VEC3: new Cartesian3(-1.0, -1.0, -1.0),\n VEC4: new Cartesian4(-1.0, -1.0, -1.0, -1.0),\n};\n\nfunction dequantizeMinMax(attribute, VectorType) {\n const divisor = getQuantizationDivisor(attribute.componentDatatype);\n const minimumBound = minimumBoundsByType[attribute.type];\n\n // dequantized = max(quantized / divisor, -1.0)\n let min = attribute.min;\n if (defined(min)) {\n min = VectorType.divideByScalar(min, divisor, min);\n min = VectorType.maximumByComponent(min, minimumBound, min);\n }\n\n let max = attribute.max;\n if (defined(max)) {\n max = VectorType.divideByScalar(max, divisor, max);\n max = VectorType.maximumByComponent(max, minimumBound, max);\n }\n\n attribute.min = min;\n attribute.max = max;\n}\n\nfunction setQuantizationFromWeb3dQuantizedAttributes(\n extension,\n attribute,\n MathType\n) {\n const decodeMatrix = extension.decodeMatrix;\n const decodedMin = fromArray(MathType, extension.decodedMin);\n const decodedMax = fromArray(MathType, extension.decodedMax);\n\n if (defined(decodedMin) && defined(decodedMax)) {\n attribute.min = decodedMin;\n attribute.max = decodedMax;\n }\n\n const quantization = new ModelComponents.Quantization();\n quantization.componentDatatype = attribute.componentDatatype;\n quantization.type = attribute.type;\n\n if (decodeMatrix.length === 4) {\n quantization.quantizedVolumeOffset = decodeMatrix[2];\n quantization.quantizedVolumeStepSize = decodeMatrix[0];\n } else if (decodeMatrix.length === 9) {\n quantization.quantizedVolumeOffset = new Cartesian2(\n decodeMatrix[6],\n decodeMatrix[7]\n );\n quantization.quantizedVolumeStepSize = new Cartesian2(\n decodeMatrix[0],\n decodeMatrix[4]\n );\n } else if (decodeMatrix.length === 16) {\n quantization.quantizedVolumeOffset = new Cartesian3(\n decodeMatrix[12],\n decodeMatrix[13],\n decodeMatrix[14]\n );\n quantization.quantizedVolumeStepSize = new Cartesian3(\n decodeMatrix[0],\n decodeMatrix[5],\n decodeMatrix[10]\n );\n } else if (decodeMatrix.length === 25) {\n quantization.quantizedVolumeOffset = new Cartesian4(\n decodeMatrix[20],\n decodeMatrix[21],\n decodeMatrix[22],\n decodeMatrix[23]\n );\n quantization.quantizedVolumeStepSize = new Cartesian4(\n decodeMatrix[0],\n decodeMatrix[6],\n decodeMatrix[12],\n decodeMatrix[18]\n );\n }\n\n attribute.quantization = quantization;\n}\n\nfunction createAttribute(gltf, accessorId, name, semantic, setIndex) {\n const accessor = gltf.accessors[accessorId];\n const MathType = AttributeType.getMathType(accessor.type);\n const normalized = defaultValue(accessor.normalized, false);\n\n const attribute = new Attribute();\n attribute.name = name;\n attribute.semantic = semantic;\n attribute.setIndex = setIndex;\n attribute.constant = getDefault(MathType);\n attribute.componentDatatype = accessor.componentType;\n attribute.normalized = normalized;\n attribute.count = accessor.count;\n attribute.type = accessor.type;\n attribute.min = fromArray(MathType, accessor.min);\n attribute.max = fromArray(MathType, accessor.max);\n attribute.byteOffset = accessor.byteOffset;\n attribute.byteStride = getAccessorByteStride(gltf, accessor);\n\n if (hasExtension(accessor, \"WEB3D_quantized_attributes\")) {\n setQuantizationFromWeb3dQuantizedAttributes(\n accessor.extensions.WEB3D_quantized_attributes,\n attribute,\n MathType\n );\n }\n\n const isQuantizable =\n attribute.semantic === VertexAttributeSemantic.POSITION ||\n attribute.semantic === VertexAttributeSemantic.NORMAL ||\n attribute.semantic === VertexAttributeSemantic.TANGENT ||\n attribute.semantic === VertexAttributeSemantic.TEXCOORD;\n\n // In the glTF 2.0 spec, min and max are not affected by the normalized flag.\n // However, for KHR_mesh_quantization, min and max must be dequantized for\n // normalized values, else the bounding sphere will be computed incorrectly.\n const hasKhrMeshQuantization = gltf.extensionsRequired?.includes(\n \"KHR_mesh_quantization\"\n );\n\n if (hasKhrMeshQuantization && normalized && isQuantizable) {\n dequantizeMinMax(attribute, MathType);\n }\n\n return attribute;\n}\n\nfunction getSetIndex(gltfSemantic) {\n const setIndexRegex = /^\\w+_(\\d+)$/;\n const setIndexMatch = setIndexRegex.exec(gltfSemantic);\n if (setIndexMatch !== null) {\n return parseInt(setIndexMatch[1]);\n }\n return undefined;\n}\n\nconst scratchSemanticInfo = {\n gltfSemantic: undefined,\n renamedSemantic: undefined,\n modelSemantic: undefined,\n};\n\nfunction getSemanticInfo(loader, semanticType, gltfSemantic) {\n // For .b3dm, rename _BATCHID (or the legacy BATCHID) to _FEATURE_ID_0\n // in the generated model components for compatibility with EXT_mesh_features\n let renamedSemantic = gltfSemantic;\n if (\n loader._renameBatchIdSemantic &&\n (gltfSemantic === \"_BATCHID\" || gltfSemantic === \"BATCHID\")\n ) {\n renamedSemantic = \"_FEATURE_ID_0\";\n }\n\n const modelSemantic = semanticType.fromGltfSemantic(renamedSemantic);\n\n const semanticInfo = scratchSemanticInfo;\n semanticInfo.gltfSemantic = gltfSemantic;\n semanticInfo.renamedSemantic = renamedSemantic;\n semanticInfo.modelSemantic = modelSemantic;\n\n return semanticInfo;\n}\n\nfunction isClassificationAttribute(attributeSemantic) {\n // Classification models only use the position, texcoord, and feature ID attributes.\n const isPositionAttribute =\n attributeSemantic === VertexAttributeSemantic.POSITION;\n const isFeatureIdAttribute =\n attributeSemantic === VertexAttributeSemantic.FEATURE_ID;\n const isTexcoordAttribute =\n attributeSemantic === VertexAttributeSemantic.TEXCOORD;\n\n return isPositionAttribute || isFeatureIdAttribute || isTexcoordAttribute;\n}\n\nfunction finalizeDracoAttribute(\n attribute,\n vertexBufferLoader,\n loadBuffer,\n loadTypedArray\n) {\n // The accessor's byteOffset and byteStride should be ignored for draco.\n // Each attribute is tightly packed in its own buffer after decode.\n attribute.byteOffset = 0;\n attribute.byteStride = undefined;\n attribute.quantization = vertexBufferLoader.quantization;\n\n if (loadBuffer) {\n attribute.buffer = vertexBufferLoader.buffer;\n }\n\n if (loadTypedArray) {\n const componentDatatype = defined(vertexBufferLoader.quantization)\n ? vertexBufferLoader.quantization.componentDatatype\n : attribute.componentDatatype;\n\n attribute.typedArray = ComponentDatatype.createArrayBufferView(\n componentDatatype,\n vertexBufferLoader.typedArray.buffer\n );\n }\n}\n\nfunction finalizeAttribute(\n gltf,\n accessor,\n attribute,\n vertexBufferLoader,\n loadBuffer,\n loadTypedArray\n) {\n if (loadBuffer) {\n attribute.buffer = vertexBufferLoader.buffer;\n }\n\n if (loadTypedArray) {\n const bufferViewTypedArray = vertexBufferLoader.typedArray;\n attribute.typedArray = getPackedTypedArray(\n gltf,\n accessor,\n bufferViewTypedArray\n );\n\n if (!loadBuffer) {\n // If the buffer isn't loaded, then the accessor's byteOffset and\n // byteStride should be ignored, since values are only available in a\n // tightly packed typed array\n attribute.byteOffset = 0;\n attribute.byteStride = undefined;\n }\n }\n}\n\nfunction loadAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n) {\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n\n const gltfSemantic = semanticInfo.gltfSemantic;\n const renamedSemantic = semanticInfo.renamedSemantic;\n const modelSemantic = semanticInfo.modelSemantic;\n\n const setIndex = defined(modelSemantic)\n ? getSetIndex(renamedSemantic)\n : undefined;\n\n const name = gltfSemantic;\n const attribute = createAttribute(\n gltf,\n accessorId,\n name,\n modelSemantic,\n setIndex\n );\n\n if (!defined(draco) && !defined(bufferViewId)) {\n return attribute;\n }\n\n const vertexBufferLoader = getVertexBufferLoader(\n loader,\n gltf,\n accessorId,\n gltfSemantic,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n );\n\n const index = loader._geometryLoaders.length;\n loader._geometryLoaders.push(vertexBufferLoader);\n const promise = vertexBufferLoader.load();\n loader._loaderPromises.push(promise);\n // This can only execute once vertexBufferLoader.process() has run and returns true\n // Save this finish callback by the loader index so it can be called\n // in process().\n loader._geometryCallbacks[index] = () => {\n if (\n defined(draco) &&\n defined(draco.attributes) &&\n defined(draco.attributes[gltfSemantic])\n ) {\n finalizeDracoAttribute(\n attribute,\n vertexBufferLoader,\n loadBuffer,\n loadTypedArray\n );\n } else {\n finalizeAttribute(\n gltf,\n accessor,\n attribute,\n vertexBufferLoader,\n loadBuffer,\n loadTypedArray\n );\n }\n };\n\n return attribute;\n}\n\nfunction loadVertexAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n draco,\n hasInstances,\n needsPostProcessing,\n frameState\n) {\n const modelSemantic = semanticInfo.modelSemantic;\n\n const isPositionAttribute =\n modelSemantic === VertexAttributeSemantic.POSITION;\n const isFeatureIdAttribute =\n modelSemantic === VertexAttributeSemantic.FEATURE_ID;\n\n const loadTypedArrayFor2D =\n isPositionAttribute &&\n !hasInstances &&\n loader._loadAttributesFor2D &&\n !frameState.scene3DOnly;\n\n const loadTypedArrayForClassification =\n loader._loadForClassification && isFeatureIdAttribute;\n\n // Whether the final output should be a buffer or typed array\n // after loading and post-processing.\n const outputTypedArrayOnly = loader._loadAttributesAsTypedArray;\n const outputBuffer = !outputTypedArrayOnly;\n const outputTypedArray =\n outputTypedArrayOnly ||\n loadTypedArrayFor2D ||\n loadTypedArrayForClassification;\n\n // Determine what to load right now:\n //\n // - If post-processing is needed, load a packed typed array for\n // further processing, and defer the buffer loading until later.\n // - On the other hand, if post-processing is not needed,\n // set the load flags directly\n const loadBuffer = needsPostProcessing ? false : outputBuffer;\n const loadTypedArray = needsPostProcessing ? true : outputTypedArray;\n\n const attribute = loadAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n );\n\n const attributePlan = new PrimitiveLoadPlan.AttributeLoadPlan(attribute);\n attributePlan.loadBuffer = outputBuffer;\n attributePlan.loadTypedArray = outputTypedArray;\n\n return attributePlan;\n}\n\nfunction loadInstancedAttribute(\n loader,\n gltf,\n accessorId,\n attributes,\n gltfSemantic,\n frameState\n) {\n const hasRotation = defined(attributes.ROTATION);\n const hasTranslationMinMax =\n defined(attributes.TRANSLATION) &&\n defined(gltf.accessors[attributes.TRANSLATION].min) &&\n defined(gltf.accessors[attributes.TRANSLATION].max);\n\n const semanticInfo = getSemanticInfo(\n loader,\n InstanceAttributeSemantic,\n gltfSemantic\n );\n const modelSemantic = semanticInfo.modelSemantic;\n\n const isTransformAttribute =\n modelSemantic === InstanceAttributeSemantic.TRANSLATION ||\n modelSemantic === InstanceAttributeSemantic.ROTATION ||\n modelSemantic === InstanceAttributeSemantic.SCALE;\n const isTranslationAttribute =\n modelSemantic === InstanceAttributeSemantic.TRANSLATION;\n\n // Load the attributes as typed arrays only if:\n // - loadAttributesAsTypedArray is true\n // - the instances have rotations. This only applies to the transform attributes,\n // since The instance matrices are computed on the CPU. This avoids the\n // expensive quaternion -> rotation matrix conversion in the shader.\n // - GPU instancing is not supported.\n const loadAsTypedArrayOnly =\n loader._loadAttributesAsTypedArray ||\n (hasRotation && isTransformAttribute) ||\n !frameState.context.instancedArrays;\n\n const loadBuffer = !loadAsTypedArrayOnly;\n\n // Load the translations as a typed array in addition to the buffer if\n // - the accessor does not have a min and max. The values will be used\n // for computing an accurate bounding volume.\n // - the model will be projected to 2D.\n const loadFor2D = loader._loadAttributesFor2D && !frameState.scene3DOnly;\n const loadTranslationAsTypedArray =\n isTranslationAttribute && (!hasTranslationMinMax || loadFor2D);\n\n const loadTypedArray = loadAsTypedArrayOnly || loadTranslationAsTypedArray;\n\n // Don't pass in draco object since instanced attributes can't be draco compressed\n return loadAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n undefined,\n loadBuffer,\n loadTypedArray,\n frameState\n );\n}\n\nfunction loadIndices(\n loader,\n gltf,\n accessorId,\n draco,\n hasFeatureIds,\n needsPostProcessing,\n frameState\n) {\n const accessor = gltf.accessors[accessorId];\n const bufferViewId = accessor.bufferView;\n\n if (!defined(draco) && !defined(bufferViewId)) {\n return undefined;\n }\n\n const indices = new Indices();\n indices.count = accessor.count;\n\n const loadAttributesAsTypedArray = loader._loadAttributesAsTypedArray;\n // Load the index buffer as a typed array to generate wireframes in WebGL1.\n const loadForWireframe =\n loader._loadIndicesForWireframe && !frameState.context.webgl2;\n\n // Load the index buffer as a typed array to batch features together for classification.\n const loadForClassification = loader._loadForClassification && hasFeatureIds;\n\n // Whether the final output should be a buffer or typed array\n // after loading and post-processing.\n const outputTypedArrayOnly = loadAttributesAsTypedArray;\n const outputBuffer = !outputTypedArrayOnly;\n const outputTypedArray =\n loadAttributesAsTypedArray || loadForWireframe || loadForClassification;\n\n // Determine what to load right now:\n //\n // - If post-processing is needed, load a packed typed array for\n // further processing, and defer the buffer loading until later.\n // - On the other hand, if post-processing is not needed, set the load\n // flags directly\n const loadBuffer = needsPostProcessing ? false : outputBuffer;\n const loadTypedArray = needsPostProcessing ? true : outputTypedArray;\n\n const indexBufferLoader = getIndexBufferLoader(\n loader,\n gltf,\n accessorId,\n draco,\n loadBuffer,\n loadTypedArray,\n frameState\n );\n\n const index = loader._geometryLoaders.length;\n loader._geometryLoaders.push(indexBufferLoader);\n const promise = indexBufferLoader.load();\n loader._loaderPromises.push(promise);\n // This can only execute once indexBufferLoader.process() has run and returns true\n // Save this finish callback by the loader index so it can be called\n // in process().\n loader._geometryCallbacks[index] = () => {\n indices.indexDatatype = indexBufferLoader.indexDatatype;\n indices.buffer = indexBufferLoader.buffer;\n indices.typedArray = indexBufferLoader.typedArray;\n };\n\n const indicesPlan = new PrimitiveLoadPlan.IndicesLoadPlan(indices);\n indicesPlan.loadBuffer = outputBuffer;\n indicesPlan.loadTypedArray = outputTypedArray;\n\n return indicesPlan;\n}\n\nfunction loadTexture(\n loader,\n gltf,\n textureInfo,\n supportedImageFormats,\n frameState,\n samplerOverride\n) {\n const imageId = GltfLoaderUtil.getImageIdFromTexture({\n gltf: gltf,\n textureId: textureInfo.index,\n supportedImageFormats: supportedImageFormats,\n });\n\n if (!defined(imageId)) {\n return undefined;\n }\n\n const textureLoader = ResourceCache.getTextureLoader({\n gltf: gltf,\n textureInfo: textureInfo,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n supportedImageFormats: supportedImageFormats,\n frameState: frameState,\n asynchronous: loader._asynchronous,\n });\n\n const textureReader = GltfLoaderUtil.createModelTextureReader({\n textureInfo: textureInfo,\n });\n\n const index = loader._textureLoaders.length;\n loader._textureLoaders.push(textureLoader);\n const promise = textureLoader.load().catch((error) => {\n if (loader.isDestroyed()) {\n return;\n }\n\n if (!loader._incrementallyLoadTextures) {\n // If incrementallyLoadTextures is false, throw the error to ensure the loader state\n // immediately is set to have failed\n throw error;\n }\n\n // Otherwise, save the error so it can be thrown next\n loader._textureState = GltfLoaderState.FAILED;\n loader._textureErrors.push(error);\n });\n loader._texturesPromises.push(promise);\n // This can only execute once textureLoader.process() has run and returns true\n // Save this finish callback by the loader index so it can be called\n // in process().\n loader._textureCallbacks[index] = () => {\n textureReader.texture = textureLoader.texture;\n if (defined(samplerOverride)) {\n textureReader.texture.sampler = samplerOverride;\n }\n };\n\n return textureReader;\n}\n\nfunction loadMaterial(\n loader,\n gltf,\n gltfMaterial,\n supportedImageFormats,\n frameState\n) {\n const material = new Material();\n\n const extensions = defaultValue(\n gltfMaterial.extensions,\n defaultValue.EMPTY_OBJECT\n );\n const pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness;\n const pbrMetallicRoughness = gltfMaterial.pbrMetallicRoughness;\n\n material.unlit = defined(extensions.KHR_materials_unlit);\n\n if (defined(pbrSpecularGlossiness)) {\n const specularGlossiness = new SpecularGlossiness();\n material.specularGlossiness = specularGlossiness;\n\n if (defined(pbrSpecularGlossiness.diffuseTexture)) {\n specularGlossiness.diffuseTexture = loadTexture(\n loader,\n gltf,\n pbrSpecularGlossiness.diffuseTexture,\n supportedImageFormats,\n frameState\n );\n }\n if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {\n if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {\n specularGlossiness.specularGlossinessTexture = loadTexture(\n loader,\n gltf,\n pbrSpecularGlossiness.specularGlossinessTexture,\n supportedImageFormats,\n frameState\n );\n }\n }\n specularGlossiness.diffuseFactor = fromArray(\n Cartesian4,\n pbrSpecularGlossiness.diffuseFactor\n );\n specularGlossiness.specularFactor = fromArray(\n Cartesian3,\n pbrSpecularGlossiness.specularFactor\n );\n specularGlossiness.glossinessFactor =\n pbrSpecularGlossiness.glossinessFactor;\n material.pbrSpecularGlossiness = pbrSpecularGlossiness;\n } else if (defined(pbrMetallicRoughness)) {\n const metallicRoughness = new MetallicRoughness();\n\n if (defined(pbrMetallicRoughness.baseColorTexture)) {\n metallicRoughness.baseColorTexture = loadTexture(\n loader,\n gltf,\n pbrMetallicRoughness.baseColorTexture,\n supportedImageFormats,\n frameState\n );\n }\n if (defined(pbrMetallicRoughness.metallicRoughnessTexture)) {\n metallicRoughness.metallicRoughnessTexture = loadTexture(\n loader,\n gltf,\n pbrMetallicRoughness.metallicRoughnessTexture,\n supportedImageFormats,\n frameState\n );\n }\n metallicRoughness.baseColorFactor = fromArray(\n Cartesian4,\n pbrMetallicRoughness.baseColorFactor\n );\n metallicRoughness.metallicFactor = pbrMetallicRoughness.metallicFactor;\n metallicRoughness.roughnessFactor = pbrMetallicRoughness.roughnessFactor;\n material.metallicRoughness = metallicRoughness;\n }\n\n // Top level textures\n if (defined(gltfMaterial.emissiveTexture)) {\n material.emissiveTexture = loadTexture(\n loader,\n gltf,\n gltfMaterial.emissiveTexture,\n supportedImageFormats,\n frameState\n );\n }\n // Normals aren't used for classification, so don't load the normal texture.\n if (defined(gltfMaterial.normalTexture) && !loader._loadForClassification) {\n material.normalTexture = loadTexture(\n loader,\n gltf,\n gltfMaterial.normalTexture,\n supportedImageFormats,\n frameState\n );\n }\n if (defined(gltfMaterial.occlusionTexture)) {\n material.occlusionTexture = loadTexture(\n loader,\n gltf,\n gltfMaterial.occlusionTexture,\n supportedImageFormats,\n frameState\n );\n }\n material.emissiveFactor = fromArray(Cartesian3, gltfMaterial.emissiveFactor);\n material.alphaMode = gltfMaterial.alphaMode;\n material.alphaCutoff = gltfMaterial.alphaCutoff;\n material.doubleSided = gltfMaterial.doubleSided;\n\n return material;\n}\n\n// for EXT_mesh_features\nfunction loadFeatureIdAttribute(featureIds, positionalLabel) {\n const featureIdAttribute = new FeatureIdAttribute();\n featureIdAttribute.featureCount = featureIds.featureCount;\n featureIdAttribute.nullFeatureId = featureIds.nullFeatureId;\n featureIdAttribute.propertyTableId = featureIds.propertyTable;\n featureIdAttribute.setIndex = featureIds.attribute;\n featureIdAttribute.label = featureIds.label;\n featureIdAttribute.positionalLabel = positionalLabel;\n return featureIdAttribute;\n}\n\n// for backwards compatibility with EXT_feature_metadata\nfunction loadFeatureIdAttributeLegacy(\n gltfFeatureIdAttribute,\n featureTableId,\n featureCount,\n positionalLabel\n) {\n const featureIdAttribute = new FeatureIdAttribute();\n const featureIds = gltfFeatureIdAttribute.featureIds;\n featureIdAttribute.featureCount = featureCount;\n featureIdAttribute.propertyTableId = featureTableId;\n featureIdAttribute.setIndex = getSetIndex(featureIds.attribute);\n featureIdAttribute.positionalLabel = positionalLabel;\n return featureIdAttribute;\n}\n\n// implicit ranges do not exist in EXT_mesh_features and EXT_instance_features,\n// but both default to the vertex/instance ID which is like\n// an implicit range of {offset: 0, repeat: 1}\nfunction loadDefaultFeatureIds(featureIds, positionalLabel) {\n const featureIdRange = new FeatureIdImplicitRange();\n featureIdRange.propertyTableId = featureIds.propertyTable;\n featureIdRange.featureCount = featureIds.featureCount;\n featureIdRange.nullFeatureId = featureIds.nullFeatureId;\n featureIdRange.label = featureIds.label;\n featureIdRange.positionalLabel = positionalLabel;\n featureIdRange.offset = 0;\n featureIdRange.repeat = 1;\n return featureIdRange;\n}\n\n// for backwards compatibility with EXT_feature_metadata\nfunction loadFeatureIdImplicitRangeLegacy(\n gltfFeatureIdAttribute,\n featureTableId,\n featureCount,\n positionalLabel\n) {\n const featureIdRange = new FeatureIdImplicitRange();\n const featureIds = gltfFeatureIdAttribute.featureIds;\n featureIdRange.propertyTableId = featureTableId;\n featureIdRange.featureCount = featureCount;\n\n // constant/divisor was renamed to offset/repeat\n featureIdRange.offset = defaultValue(featureIds.constant, 0);\n // The default is now undefined\n const divisor = defaultValue(featureIds.divisor, 0);\n featureIdRange.repeat = divisor === 0 ? undefined : divisor;\n\n featureIdRange.positionalLabel = positionalLabel;\n return featureIdRange;\n}\n\n// for EXT_mesh_features\nfunction loadFeatureIdTexture(\n loader,\n gltf,\n gltfFeatureIdTexture,\n supportedImageFormats,\n frameState,\n positionalLabel\n) {\n const featureIdTexture = new FeatureIdTexture();\n\n featureIdTexture.featureCount = gltfFeatureIdTexture.featureCount;\n featureIdTexture.nullFeatureId = gltfFeatureIdTexture.nullFeatureId;\n featureIdTexture.propertyTableId = gltfFeatureIdTexture.propertyTable;\n featureIdTexture.label = gltfFeatureIdTexture.label;\n featureIdTexture.positionalLabel = positionalLabel;\n\n const textureInfo = gltfFeatureIdTexture.texture;\n featureIdTexture.textureReader = loadTexture(\n loader,\n gltf,\n textureInfo,\n supportedImageFormats,\n frameState,\n Sampler.NEAREST // Feature ID textures require nearest sampling\n );\n\n // Though the new channel index is more future-proof, this implementation\n // only supports RGBA textures. At least for now, the string representation\n // is more useful for generating shader code.\n const channels = defined(textureInfo.channels) ? textureInfo.channels : [0];\n const channelString = channels\n .map(function (channelIndex) {\n return \"rgba\".charAt(channelIndex);\n })\n .join(\"\");\n featureIdTexture.textureReader.channels = channelString;\n\n return featureIdTexture;\n}\n\n// for backwards compatibility with EXT_feature_metadata\nfunction loadFeatureIdTextureLegacy(\n loader,\n gltf,\n gltfFeatureIdTexture,\n featureTableId,\n supportedImageFormats,\n frameState,\n featureCount,\n positionalLabel\n) {\n const featureIdTexture = new FeatureIdTexture();\n const featureIds = gltfFeatureIdTexture.featureIds;\n const textureInfo = featureIds.texture;\n featureIdTexture.featureCount = featureCount;\n featureIdTexture.propertyTableId = featureTableId;\n featureIdTexture.textureReader = loadTexture(\n loader,\n gltf,\n textureInfo,\n supportedImageFormats,\n frameState,\n Sampler.NEAREST // Feature ID textures require nearest sampling\n );\n\n featureIdTexture.textureReader.channels = featureIds.channels;\n featureIdTexture.positionalLabel = positionalLabel;\n\n return featureIdTexture;\n}\n\nfunction loadMorphTarget(\n loader,\n gltf,\n target,\n needsPostProcessing,\n primitiveLoadPlan,\n frameState\n) {\n const morphTarget = new MorphTarget();\n\n // Don't pass in draco object since morph targets can't be draco compressed\n const draco = undefined;\n const hasInstances = false;\n\n for (const semantic in target) {\n if (target.hasOwnProperty(semantic)) {\n const accessorId = target[semantic];\n\n const semanticInfo = getSemanticInfo(\n loader,\n VertexAttributeSemantic,\n semantic\n );\n\n const attributePlan = loadVertexAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n draco,\n hasInstances,\n needsPostProcessing,\n frameState\n );\n morphTarget.attributes.push(attributePlan.attribute);\n\n // The load plan doesn't need to distinguish morph target attributes from\n // regular attributes\n primitiveLoadPlan.attributePlans.push(attributePlan);\n }\n }\n\n return morphTarget;\n}\n\nfunction loadPrimitive(\n loader,\n gltf,\n gltfPrimitive,\n hasInstances,\n supportedImageFormats,\n frameState\n) {\n const primitive = new Primitive();\n const primitivePlan = new PrimitiveLoadPlan(primitive);\n loader._primitiveLoadPlans.push(primitivePlan);\n\n const materialId = gltfPrimitive.material;\n if (defined(materialId)) {\n primitive.material = loadMaterial(\n loader,\n gltf,\n gltf.materials[materialId],\n supportedImageFormats,\n frameState\n );\n }\n\n const extensions = defaultValue(\n gltfPrimitive.extensions,\n defaultValue.EMPTY_OBJECT\n );\n\n let needsPostProcessing = false;\n const outlineExtension = extensions.CESIUM_primitive_outline;\n if (loader._loadPrimitiveOutline && defined(outlineExtension)) {\n needsPostProcessing = true;\n primitivePlan.needsOutlines = true;\n primitivePlan.outlineIndices = loadPrimitiveOutline(\n loader,\n gltf,\n outlineExtension,\n primitivePlan\n );\n }\n\n const loadForClassification = loader._loadForClassification;\n const draco = extensions.KHR_draco_mesh_compression;\n\n let hasFeatureIds = false;\n const attributes = gltfPrimitive.attributes;\n if (defined(attributes)) {\n for (const semantic in attributes) {\n if (attributes.hasOwnProperty(semantic)) {\n const accessorId = attributes[semantic];\n const semanticInfo = getSemanticInfo(\n loader,\n VertexAttributeSemantic,\n semantic\n );\n\n const modelSemantic = semanticInfo.modelSemantic;\n if (\n loadForClassification &&\n !isClassificationAttribute(modelSemantic)\n ) {\n continue;\n }\n\n if (modelSemantic === VertexAttributeSemantic.FEATURE_ID) {\n hasFeatureIds = true;\n }\n\n const attributePlan = loadVertexAttribute(\n loader,\n gltf,\n accessorId,\n semanticInfo,\n draco,\n hasInstances,\n needsPostProcessing,\n frameState\n );\n\n primitivePlan.attributePlans.push(attributePlan);\n primitive.attributes.push(attributePlan.attribute);\n }\n }\n }\n\n const targets = gltfPrimitive.targets;\n // Morph targets are disabled for classification models.\n if (defined(targets) && !loadForClassification) {\n const targetsLength = targets.length;\n for (let i = 0; i < targetsLength; ++i) {\n primitive.morphTargets.push(\n loadMorphTarget(\n loader,\n gltf,\n targets[i],\n needsPostProcessing,\n primitivePlan,\n frameState\n )\n );\n }\n }\n\n const indices = gltfPrimitive.indices;\n if (defined(indices)) {\n const indicesPlan = loadIndices(\n loader,\n gltf,\n indices,\n draco,\n hasFeatureIds,\n needsPostProcessing,\n frameState\n );\n\n if (defined(indicesPlan)) {\n primitivePlan.indicesPlan = indicesPlan;\n primitive.indices = indicesPlan.indices;\n }\n }\n\n // With the latest revision, feature IDs are defined in EXT_mesh_features\n // while EXT_structural_metadata is for defining property textures and\n // property mappings. In the legacy EXT_feature_metadata, these concepts\n // were all in one extension.\n const structuralMetadata = extensions.EXT_structural_metadata;\n const meshFeatures = extensions.EXT_mesh_features;\n const featureMetadataLegacy = extensions.EXT_feature_metadata;\n const hasFeatureMetadataLegacy = defined(featureMetadataLegacy);\n\n // Load feature Ids\n if (defined(meshFeatures)) {\n loadPrimitiveFeatures(\n loader,\n gltf,\n primitive,\n meshFeatures,\n supportedImageFormats,\n frameState\n );\n } else if (hasFeatureMetadataLegacy) {\n loadPrimitiveFeaturesLegacy(\n loader,\n gltf,\n primitive,\n featureMetadataLegacy,\n supportedImageFormats,\n frameState\n );\n }\n\n // Load structural metadata\n if (defined(structuralMetadata)) {\n loadPrimitiveMetadata(primitive, structuralMetadata);\n } else if (hasFeatureMetadataLegacy) {\n loadPrimitiveMetadataLegacy(loader, primitive, featureMetadataLegacy);\n }\n\n const primitiveType = gltfPrimitive.mode;\n if (loadForClassification && primitiveType !== PrimitiveType.TRIANGLES) {\n throw new RuntimeError(\n \"Only triangle meshes can be used for classification.\"\n );\n }\n primitive.primitiveType = primitiveType;\n\n return primitive;\n}\n\nfunction loadPrimitiveOutline(loader, gltf, outlineExtension) {\n const accessorId = outlineExtension.indices;\n const useQuaternion = false;\n return loadAccessor(loader, gltf, accessorId, useQuaternion);\n}\n\n// For EXT_mesh_features\nfunction loadPrimitiveFeatures(\n loader,\n gltf,\n primitive,\n meshFeaturesExtension,\n supportedImageFormats,\n frameState\n) {\n let featureIdsArray;\n if (\n defined(meshFeaturesExtension) &&\n defined(meshFeaturesExtension.featureIds)\n ) {\n featureIdsArray = meshFeaturesExtension.featureIds;\n } else {\n featureIdsArray = [];\n }\n\n for (let i = 0; i < featureIdsArray.length; i++) {\n const featureIds = featureIdsArray[i];\n const label = `featureId_${i}`;\n\n let featureIdComponent;\n if (defined(featureIds.texture)) {\n featureIdComponent = loadFeatureIdTexture(\n loader,\n gltf,\n featureIds,\n supportedImageFormats,\n frameState,\n label\n );\n } else if (defined(featureIds.attribute)) {\n featureIdComponent = loadFeatureIdAttribute(featureIds, label);\n } else {\n // default to vertex ID, in other words an implicit range with\n // offset: 0, repeat: 1\n featureIdComponent = loadDefaultFeatureIds(featureIds, label);\n }\n\n primitive.featureIds.push(featureIdComponent);\n }\n}\n\n// For EXT_feature_metadata\nfunction loadPrimitiveFeaturesLegacy(\n loader,\n gltf,\n primitive,\n metadataExtension,\n supportedImageFormats,\n frameState\n) {\n // For looking up the featureCount for each set of feature IDs\n const featureTables = gltf.extensions.EXT_feature_metadata.featureTables;\n\n let nextFeatureIdIndex = 0;\n\n // Feature ID Attributes\n const featureIdAttributes = metadataExtension.featureIdAttributes;\n if (defined(featureIdAttributes)) {\n const featureIdAttributesLength = featureIdAttributes.length;\n for (let i = 0; i < featureIdAttributesLength; ++i) {\n const featureIdAttribute = featureIdAttributes[i];\n const featureTableId = featureIdAttribute.featureTable;\n const propertyTableId = loader._sortedPropertyTableIds.indexOf(\n featureTableId\n );\n const featureCount = featureTables[featureTableId].count;\n const label = `featureId_${nextFeatureIdIndex}`;\n nextFeatureIdIndex++;\n\n let featureIdComponent;\n if (defined(featureIdAttribute.featureIds.attribute)) {\n featureIdComponent = loadFeatureIdAttributeLegacy(\n featureIdAttribute,\n propertyTableId,\n featureCount,\n label\n );\n } else {\n featureIdComponent = loadFeatureIdImplicitRangeLegacy(\n featureIdAttribute,\n propertyTableId,\n featureCount,\n label\n );\n }\n primitive.featureIds.push(featureIdComponent);\n }\n }\n\n // Feature ID Textures\n const featureIdTextures = metadataExtension.featureIdTextures;\n if (defined(featureIdTextures)) {\n const featureIdTexturesLength = featureIdTextures.length;\n for (let i = 0; i < featureIdTexturesLength; ++i) {\n const featureIdTexture = featureIdTextures[i];\n const featureTableId = featureIdTexture.featureTable;\n const propertyTableId = loader._sortedPropertyTableIds.indexOf(\n featureTableId\n );\n const featureCount = featureTables[featureTableId].count;\n const featureIdLabel = `featureId_${nextFeatureIdIndex}`;\n nextFeatureIdIndex++;\n\n const featureIdComponent = loadFeatureIdTextureLegacy(\n loader,\n gltf,\n featureIdTexture,\n propertyTableId,\n supportedImageFormats,\n frameState,\n featureCount,\n featureIdLabel\n );\n // Feature ID textures are added after feature ID attributes in the list\n primitive.featureIds.push(featureIdComponent);\n }\n }\n}\n\n// For primitive-level EXT_structural_metadata\nfunction loadPrimitiveMetadata(primitive, structuralMetadataExtension) {\n if (!defined(structuralMetadataExtension)) {\n return;\n }\n\n // Property Textures\n if (defined(structuralMetadataExtension.propertyTextures)) {\n primitive.propertyTextureIds = structuralMetadataExtension.propertyTextures;\n }\n\n // Property Attributes\n if (defined(structuralMetadataExtension.propertyAttributes)) {\n primitive.propertyAttributeIds =\n structuralMetadataExtension.propertyAttributes;\n }\n}\n\n// For EXT_feature_metadata\nfunction loadPrimitiveMetadataLegacy(loader, primitive, metadataExtension) {\n // Feature Textures\n if (defined(metadataExtension.featureTextures)) {\n // feature textures are now identified by an integer index. To convert the\n // string IDs to integers, find their place in the sorted list of feature\n // table names\n primitive.propertyTextureIds = metadataExtension.featureTextures.map(\n function (id) {\n return loader._sortedFeatureTextureIds.indexOf(id);\n }\n );\n }\n}\n\nfunction loadInstances(loader, gltf, nodeExtensions, frameState) {\n const instancingExtension = nodeExtensions.EXT_mesh_gpu_instancing;\n\n const instances = new Instances();\n const attributes = instancingExtension.attributes;\n if (defined(attributes)) {\n for (const semantic in attributes) {\n if (attributes.hasOwnProperty(semantic)) {\n const accessorId = attributes[semantic];\n instances.attributes.push(\n loadInstancedAttribute(\n loader,\n gltf,\n accessorId,\n attributes,\n semantic,\n frameState\n )\n );\n }\n }\n }\n\n const instancingExtExtensions = defaultValue(\n instancingExtension.extensions,\n defaultValue.EMPTY_OBJECT\n );\n const instanceFeatures = nodeExtensions.EXT_instance_features;\n const featureMetadataLegacy = instancingExtExtensions.EXT_feature_metadata;\n\n if (defined(instanceFeatures)) {\n loadInstanceFeatures(instances, instanceFeatures);\n } else if (defined(featureMetadataLegacy)) {\n loadInstanceFeaturesLegacy(\n gltf,\n instances,\n featureMetadataLegacy,\n loader._sortedPropertyTableIds\n );\n }\n\n return instances;\n}\n\n// For EXT_mesh_features\nfunction loadInstanceFeatures(instances, instanceFeaturesExtension) {\n // feature IDs are required in EXT_instance_features\n const featureIdsArray = instanceFeaturesExtension.featureIds;\n\n for (let i = 0; i < featureIdsArray.length; i++) {\n const featureIds = featureIdsArray[i];\n const label = `instanceFeatureId_${i}`;\n\n let featureIdComponent;\n if (defined(featureIds.attribute)) {\n featureIdComponent = loadFeatureIdAttribute(featureIds, label);\n } else {\n // in EXT_instance_features, the default is to assign IDs by instance\n // ID. This can be expressed with offset: 0, repeat: 1\n featureIdComponent = loadDefaultFeatureIds(featureIds, label);\n }\n\n instances.featureIds.push(featureIdComponent);\n }\n}\n\n// For backwards-compatibility with EXT_feature_metadata\nfunction loadInstanceFeaturesLegacy(\n gltf,\n instances,\n metadataExtension,\n sortedPropertyTableIds\n) {\n // For looking up the featureCount for each set of feature IDs\n const featureTables = gltf.extensions.EXT_feature_metadata.featureTables;\n\n const featureIdAttributes = metadataExtension.featureIdAttributes;\n if (defined(featureIdAttributes)) {\n const featureIdAttributesLength = featureIdAttributes.length;\n for (let i = 0; i < featureIdAttributesLength; ++i) {\n const featureIdAttribute = featureIdAttributes[i];\n const featureTableId = featureIdAttribute.featureTable;\n const propertyTableId = sortedPropertyTableIds.indexOf(featureTableId);\n const featureCount = featureTables[featureTableId].count;\n const label = `instanceFeatureId_${i}`;\n\n let featureIdComponent;\n if (defined(featureIdAttribute.featureIds.attribute)) {\n featureIdComponent = loadFeatureIdAttributeLegacy(\n featureIdAttribute,\n propertyTableId,\n featureCount,\n label\n );\n } else {\n featureIdComponent = loadFeatureIdImplicitRangeLegacy(\n featureIdAttribute,\n propertyTableId,\n featureCount,\n label\n );\n }\n instances.featureIds.push(featureIdComponent);\n }\n }\n}\n\nfunction loadNode(loader, gltf, gltfNode, supportedImageFormats, frameState) {\n const node = new Node();\n\n node.name = gltfNode.name;\n\n node.matrix = fromArray(Matrix4, gltfNode.matrix);\n node.translation = fromArray(Cartesian3, gltfNode.translation);\n node.rotation = fromArray(Quaternion, gltfNode.rotation);\n node.scale = fromArray(Cartesian3, gltfNode.scale);\n\n const nodeExtensions = defaultValue(\n gltfNode.extensions,\n defaultValue.EMPTY_OBJECT\n );\n const instancingExtension = nodeExtensions.EXT_mesh_gpu_instancing;\n const articulationsExtension = nodeExtensions.AGI_articulations;\n\n if (defined(instancingExtension)) {\n if (loader._loadForClassification) {\n throw new RuntimeError(\n \"Models with the EXT_mesh_gpu_instancing extension cannot be used for classification.\"\n );\n }\n node.instances = loadInstances(loader, gltf, nodeExtensions, frameState);\n }\n\n if (defined(articulationsExtension)) {\n node.articulationName = articulationsExtension.articulationName;\n }\n\n const meshId = gltfNode.mesh;\n if (defined(meshId)) {\n const mesh = gltf.meshes[meshId];\n const primitives = mesh.primitives;\n const primitivesLength = primitives.length;\n for (let i = 0; i < primitivesLength; ++i) {\n node.primitives.push(\n loadPrimitive(\n loader,\n gltf,\n primitives[i],\n defined(node.instances),\n supportedImageFormats,\n frameState\n )\n );\n }\n\n // If the node has no weights array, it will look for the weights array provided\n // by the mesh. If both are undefined, it will default to an array of zero weights.\n const morphWeights = defaultValue(gltfNode.weights, mesh.weights);\n const targets = node.primitives[0].morphTargets;\n const targetsLength = targets.length;\n\n // Since meshes are not stored as separate components, the mesh weights will still\n // be stored at the node level.\n node.morphWeights = defined(morphWeights)\n ? morphWeights.slice()\n : new Array(targetsLength).fill(0.0);\n }\n\n return node;\n}\n\nfunction loadNodes(loader, gltf, supportedImageFormats, frameState) {\n if (!defined(gltf.nodes)) {\n return [];\n }\n\n let i;\n let j;\n\n const nodesLength = gltf.nodes.length;\n const nodes = new Array(nodesLength);\n for (i = 0; i < nodesLength; ++i) {\n const node = loadNode(\n loader,\n gltf,\n gltf.nodes[i],\n supportedImageFormats,\n frameState\n );\n node.index = i;\n nodes[i] = node;\n }\n\n for (i = 0; i < nodesLength; ++i) {\n const childrenNodeIds = gltf.nodes[i].children;\n if (defined(childrenNodeIds)) {\n const childrenLength = childrenNodeIds.length;\n for (j = 0; j < childrenLength; ++j) {\n nodes[i].children.push(nodes[childrenNodeIds[j]]);\n }\n }\n }\n\n return nodes;\n}\n\nfunction loadSkin(loader, gltf, gltfSkin, nodes) {\n const skin = new Skin();\n\n const jointIds = gltfSkin.joints;\n const jointsLength = jointIds.length;\n const joints = new Array(jointsLength);\n for (let i = 0; i < jointsLength; ++i) {\n joints[i] = nodes[jointIds[i]];\n }\n skin.joints = joints;\n\n const inverseBindMatricesAccessorId = gltfSkin.inverseBindMatrices;\n if (defined(inverseBindMatricesAccessorId)) {\n skin.inverseBindMatrices = loadAccessor(\n loader,\n gltf,\n inverseBindMatricesAccessorId\n );\n } else {\n skin.inverseBindMatrices = new Array(jointsLength).fill(Matrix4.IDENTITY);\n }\n\n return skin;\n}\n\nfunction loadSkins(loader, gltf, nodes) {\n const gltfSkins = gltf.skins;\n\n // Skins are disabled for classification models.\n if (loader._loadForClassification || !defined(gltfSkins)) {\n return [];\n }\n\n const skinsLength = gltf.skins.length;\n const skins = new Array(skinsLength);\n for (let i = 0; i < skinsLength; ++i) {\n const skin = loadSkin(loader, gltf, gltf.skins[i], nodes);\n skin.index = i;\n skins[i] = skin;\n }\n\n const nodesLength = nodes.length;\n for (let i = 0; i < nodesLength; ++i) {\n const skinId = gltf.nodes[i].skin;\n if (defined(skinId)) {\n nodes[i].skin = skins[skinId];\n }\n }\n\n return skins;\n}\n\nasync function loadStructuralMetadata(\n loader,\n gltf,\n extension,\n extensionLegacy,\n supportedImageFormats,\n frameState\n) {\n const structuralMetadataLoader = new GltfStructuralMetadataLoader({\n gltf: gltf,\n extension: extension,\n extensionLegacy: extensionLegacy,\n gltfResource: loader._gltfResource,\n baseResource: loader._baseResource,\n supportedImageFormats: supportedImageFormats,\n frameState: frameState,\n asynchronous: loader._asynchronous,\n });\n loader._structuralMetadataLoader = structuralMetadataLoader;\n return structuralMetadataLoader.load();\n}\n\nfunction loadAnimationSampler(loader, gltf, gltfSampler) {\n const animationSampler = new AnimationSampler();\n\n const inputAccessorId = gltfSampler.input;\n animationSampler.input = loadAccessor(loader, gltf, inputAccessorId);\n\n const gltfInterpolation = gltfSampler.interpolation;\n animationSampler.interpolation = defaultValue(\n InterpolationType[gltfInterpolation],\n InterpolationType.LINEAR\n );\n\n const outputAccessorId = gltfSampler.output;\n animationSampler.output = loadAccessor(loader, gltf, outputAccessorId, true);\n\n return animationSampler;\n}\n\nfunction loadAnimationTarget(gltfTarget, nodes) {\n const animationTarget = new AnimationTarget();\n\n const nodeIndex = gltfTarget.node;\n // If the node isn't defined, the animation channel should be ignored.\n // It's easiest to signal this by returning undefined.\n if (!defined(nodeIndex)) {\n return undefined;\n }\n\n animationTarget.node = nodes[nodeIndex];\n\n const path = gltfTarget.path.toUpperCase();\n animationTarget.path = AnimatedPropertyType[path];\n\n return animationTarget;\n}\n\nfunction loadAnimationChannel(gltfChannel, samplers, nodes) {\n const animationChannel = new AnimationChannel();\n\n const samplerIndex = gltfChannel.sampler;\n animationChannel.sampler = samplers[samplerIndex];\n animationChannel.target = loadAnimationTarget(gltfChannel.target, nodes);\n\n return animationChannel;\n}\n\nfunction loadAnimation(loader, gltf, gltfAnimation, nodes) {\n let i;\n\n const animation = new Animation();\n animation.name = gltfAnimation.name;\n\n const gltfSamplers = gltfAnimation.samplers;\n const samplersLength = gltfSamplers.length;\n\n const samplers = new Array(samplersLength);\n for (i = 0; i < samplersLength; i++) {\n const sampler = loadAnimationSampler(loader, gltf, gltfSamplers[i]);\n sampler.index = i;\n samplers[i] = sampler;\n }\n\n const gltfChannels = gltfAnimation.channels;\n const channelsLength = gltfChannels.length;\n\n const channels = new Array(channelsLength);\n for (i = 0; i < channelsLength; i++) {\n channels[i] = loadAnimationChannel(gltfChannels[i], samplers, nodes);\n }\n\n animation.samplers = samplers;\n animation.channels = channels;\n\n return animation;\n}\n\nfunction loadAnimations(loader, gltf, nodes) {\n const gltfAnimations = gltf.animations;\n\n // Animations are disabled for classification models.\n if (loader._loadForClassification || !defined(gltfAnimations)) {\n return [];\n }\n\n const animationsLength = gltf.animations.length;\n const animations = new Array(animationsLength);\n for (let i = 0; i < animationsLength; ++i) {\n const animation = loadAnimation(loader, gltf, gltf.animations[i], nodes);\n animation.index = i;\n animations[i] = animation;\n }\n\n return animations;\n}\n\nfunction loadArticulationStage(gltfStage) {\n const stage = new ArticulationStage();\n stage.name = gltfStage.name;\n\n const type = gltfStage.type.toUpperCase();\n stage.type = ArticulationStageType[type];\n\n stage.minimumValue = gltfStage.minimumValue;\n stage.maximumValue = gltfStage.maximumValue;\n stage.initialValue = gltfStage.initialValue;\n\n return stage;\n}\n\nfunction loadArticulation(gltfArticulation) {\n const articulation = new Articulation();\n articulation.name = gltfArticulation.name;\n\n const gltfStages = gltfArticulation.stages;\n const gltfStagesLength = gltfStages.length;\n\n const stages = new Array(gltfStagesLength);\n for (let i = 0; i < gltfStagesLength; i++) {\n const stage = loadArticulationStage(gltfStages[i]);\n stages[i] = stage;\n }\n\n articulation.stages = stages;\n\n return articulation;\n}\n\nfunction loadArticulations(gltf) {\n const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);\n const articulationsExtension = extensions.AGI_articulations;\n\n if (!defined(articulationsExtension)) {\n return [];\n }\n\n const gltfArticulations = articulationsExtension.articulations;\n if (!defined(gltfArticulations)) {\n return [];\n }\n\n const gltfArticulationsLength = gltfArticulations.length;\n const articulations = new Array(gltfArticulationsLength);\n for (let i = 0; i < gltfArticulationsLength; i++) {\n const articulation = loadArticulation(gltfArticulations[i]);\n articulations[i] = articulation;\n }\n\n return articulations;\n}\n\nfunction getSceneNodeIds(gltf) {\n let nodesIds;\n if (defined(gltf.scenes) && defined(gltf.scene)) {\n nodesIds = gltf.scenes[gltf.scene].nodes;\n }\n nodesIds = defaultValue(nodesIds, gltf.nodes);\n nodesIds = defined(nodesIds) ? nodesIds : [];\n return nodesIds;\n}\n\nfunction loadScene(gltf, nodes) {\n const scene = new Scene();\n const sceneNodeIds = getSceneNodeIds(gltf);\n scene.nodes = sceneNodeIds.map(function (sceneNodeId) {\n return nodes[sceneNodeId];\n });\n return scene;\n}\n\nconst scratchCenter = new Cartesian3();\n\nfunction parse(loader, gltf, supportedImageFormats, frameState) {\n const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);\n const structuralMetadataExtension = extensions.EXT_structural_metadata;\n const featureMetadataExtensionLegacy = extensions.EXT_feature_metadata;\n const cesiumRtcExtension = extensions.CESIUM_RTC;\n\n if (defined(featureMetadataExtensionLegacy)) {\n // If the old EXT_feature_metadata extension is present, sort the IDs of the\n // feature tables and feature textures so we don't have to do this once\n // per primitive.\n //\n // This must run before loadNodes so these IDs are available when\n // attributes are processed.\n const featureTables = featureMetadataExtensionLegacy.featureTables;\n const featureTextures = featureMetadataExtensionLegacy.featureTextures;\n const allPropertyTableIds = defined(featureTables) ? featureTables : [];\n const allFeatureTextureIds = defined(featureTextures)\n ? featureTextures\n : [];\n loader._sortedPropertyTableIds = Object.keys(allPropertyTableIds).sort();\n loader._sortedFeatureTextureIds = Object.keys(allFeatureTextureIds).sort();\n }\n\n const nodes = loadNodes(loader, gltf, supportedImageFormats, frameState);\n const skins = loadSkins(loader, gltf, nodes);\n const animations = loadAnimations(loader, gltf, nodes);\n const articulations = loadArticulations(gltf);\n const scene = loadScene(gltf, nodes);\n\n const components = new Components();\n const asset = new Asset();\n const copyright = gltf.asset.copyright;\n if (defined(copyright)) {\n const credits = copyright.split(\";\").map(function (string) {\n return new Credit(string.trim());\n });\n asset.credits = credits;\n }\n\n components.asset = asset;\n components.scene = scene;\n components.nodes = nodes;\n components.skins = skins;\n components.animations = animations;\n components.articulations = articulations;\n components.upAxis = loader._upAxis;\n components.forwardAxis = loader._forwardAxis;\n\n if (defined(cesiumRtcExtension)) {\n // CESIUM_RTC is almost always WGS84 coordinates so no axis conversion needed\n const center = Cartesian3.fromArray(\n cesiumRtcExtension.center,\n 0,\n scratchCenter\n );\n components.transform = Matrix4.fromTranslation(\n center,\n components.transform\n );\n }\n\n loader._components = components;\n\n // Load structural metadata (property tables and property textures)\n if (\n defined(structuralMetadataExtension) ||\n defined(featureMetadataExtensionLegacy)\n ) {\n const promise = loadStructuralMetadata(\n loader,\n gltf,\n structuralMetadataExtension,\n featureMetadataExtensionLegacy,\n supportedImageFormats,\n frameState\n );\n loader._loaderPromises.push(promise);\n }\n\n // Gather promises and handle any errors\n const readyPromises = [];\n readyPromises.push.apply(readyPromises, loader._loaderPromises);\n\n // When incrementallyLoadTextures is true, the errors are caught and thrown individually\n // since it doesn't affect the overall loader state\n if (!loader._incrementallyLoadTextures) {\n readyPromises.push.apply(readyPromises, loader._texturesPromises);\n }\n\n return Promise.all(readyPromises);\n}\n\nfunction unloadTextures(loader) {\n const textureLoaders = loader._textureLoaders;\n const textureLoadersLength = textureLoaders.length;\n for (let i = 0; i < textureLoadersLength; ++i) {\n textureLoaders[i] =\n !textureLoaders[i].isDestroyed() &&\n ResourceCache.unload(textureLoaders[i]);\n }\n loader._textureLoaders.length = 0;\n}\n\nfunction unloadBufferViewLoaders(loader) {\n const bufferViewLoaders = loader._bufferViewLoaders;\n const bufferViewLoadersLength = bufferViewLoaders.length;\n for (let i = 0; i < bufferViewLoadersLength; ++i) {\n bufferViewLoaders[i] =\n !bufferViewLoaders[i].isDestroyed() &&\n ResourceCache.unload(bufferViewLoaders[i]);\n }\n loader._bufferViewLoaders.length = 0;\n}\n\nfunction unloadGeometry(loader) {\n const geometryLoaders = loader._geometryLoaders;\n const geometryLoadersLength = geometryLoaders.length;\n for (let i = 0; i < geometryLoadersLength; ++i) {\n geometryLoaders[i] =\n !geometryLoaders[i].isDestroyed() &&\n ResourceCache.unload(geometryLoaders[i]);\n }\n loader._geometryLoaders.length = 0;\n}\n\nfunction unloadGeneratedAttributes(loader) {\n const buffers = loader._postProcessBuffers;\n const length = buffers.length;\n for (let i = 0; i < length; i++) {\n const buffer = buffers[i];\n if (!buffer.isDestroyed()) {\n buffer.destroy();\n }\n }\n buffers.length = 0;\n}\n\nfunction unloadStructuralMetadata(loader) {\n if (\n defined(loader._structuralMetadataLoader) &&\n !loader._structuralMetadataLoader.isDestroyed()\n ) {\n loader._structuralMetadataLoader.destroy();\n loader._structuralMetadataLoader = undefined;\n }\n}\n\n/**\n * Returns whether the resource has been unloaded.\n * @private\n */\nGltfLoader.prototype.isUnloaded = function () {\n return this._state === GltfLoaderState.UNLOADED;\n};\n\n/**\n * Unloads the resource.\n * @private\n */\nGltfLoader.prototype.unload = function () {\n if (defined(this._gltfJsonLoader) && !this._gltfJsonLoader.isDestroyed()) {\n ResourceCache.unload(this._gltfJsonLoader);\n }\n this._gltfJsonLoader = undefined;\n\n unloadTextures(this);\n unloadBufferViewLoaders(this);\n unloadGeometry(this);\n unloadGeneratedAttributes(this);\n unloadStructuralMetadata(this);\n\n this._components = undefined;\n this._typedArray = undefined;\n this._state = GltfLoaderState.UNLOADED;\n};\n\nexport default GltfLoader;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D u_pointCloud_colorGBuffer;\\n\\\nuniform sampler2D u_pointCloud_depthGBuffer;\\n\\\nuniform vec2 u_distanceAndEdlStrength;\\n\\\nin vec2 v_textureCoordinates;\\n\\\n\\n\\\nvec2 neighborContribution(float log2Depth, vec2 offset)\\n\\\n{\\n\\\n float dist = u_distanceAndEdlStrength.x;\\n\\\n vec2 texCoordOrig = v_textureCoordinates + offset * dist;\\n\\\n vec2 texCoord0 = v_textureCoordinates + offset * floor(dist);\\n\\\n vec2 texCoord1 = v_textureCoordinates + offset * ceil(dist);\\n\\\n\\n\\\n float depthOrLogDepth0 = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, texCoord0));\\n\\\n float depthOrLogDepth1 = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, texCoord1));\\n\\\n\\n\\\n // ignore depth values that are the clear depth\\n\\\n if (depthOrLogDepth0 == 0.0 || depthOrLogDepth1 == 0.0) {\\n\\\n return vec2(0.0);\\n\\\n }\\n\\\n\\n\\\n // interpolate the two adjacent depth values\\n\\\n float depthMix = mix(depthOrLogDepth0, depthOrLogDepth1, fract(dist));\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(texCoordOrig, depthMix);\\n\\\n return vec2(max(0.0, log2Depth - log2(-eyeCoordinate.z / eyeCoordinate.w)), 1.0);\\n\\\n}\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n float depthOrLogDepth = czm_unpackDepth(texture(u_pointCloud_depthGBuffer, v_textureCoordinates));\\n\\\n\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, depthOrLogDepth);\\n\\\n eyeCoordinate /= eyeCoordinate.w;\\n\\\n\\n\\\n float log2Depth = log2(-eyeCoordinate.z);\\n\\\n\\n\\\n if (depthOrLogDepth == 0.0) // 0.0 is the clear value for the gbuffer\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n\\n\\\n vec4 color = texture(u_pointCloud_colorGBuffer, v_textureCoordinates);\\n\\\n\\n\\\n // sample from neighbors left, right, down, up\\n\\\n vec2 texelSize = 1.0 / czm_viewport.zw;\\n\\\n\\n\\\n vec2 responseAndCount = vec2(0.0);\\n\\\n\\n\\\n responseAndCount += neighborContribution(log2Depth, vec2(-texelSize.x, 0.0));\\n\\\n responseAndCount += neighborContribution(log2Depth, vec2(+texelSize.x, 0.0));\\n\\\n responseAndCount += neighborContribution(log2Depth, vec2(0.0, -texelSize.y));\\n\\\n responseAndCount += neighborContribution(log2Depth, vec2(0.0, +texelSize.y));\\n\\\n\\n\\\n float response = responseAndCount.x / responseAndCount.y;\\n\\\n float strength = u_distanceAndEdlStrength.y;\\n\\\n float shade = exp(-response * 300.0 * strength);\\n\\\n color.rgb *= shade;\\n\\\n out_FragColor = vec4(color);\\n\\\n\\n\\\n // Input and output depth are the same.\\n\\\n gl_FragDepth = depthOrLogDepth;\\n\\\n}\\n\\\n\";\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport ClearCommand from \"../Renderer/ClearCommand.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport FramebufferManager from \"../Renderer/FramebufferManager.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport BlendingState from \"../Scene/BlendingState.js\";\nimport StencilConstants from \"../Scene/StencilConstants.js\";\nimport PointCloudEyeDomeLightingShader from \"../Shaders/PostProcessStages/PointCloudEyeDomeLighting.js\";\n\n/**\n * Eye dome lighting. Does not support points with per-point translucency, but does allow translucent styling against the globe.\n * Requires support for EXT_frag_depth and WEBGL_draw_buffers extensions in WebGL 1.0.\n *\n * @private\n */\nfunction PointCloudEyeDomeLighting() {\n this._framebuffer = new FramebufferManager({\n colorAttachmentsLength: 2,\n depth: true,\n supportsDepthTexture: true,\n });\n\n this._drawCommand = undefined;\n this._clearCommand = undefined;\n\n this._strength = 1.0;\n this._radius = 1.0;\n}\n\nObject.defineProperties(PointCloudEyeDomeLighting.prototype, {\n framebuffer: {\n get: function () {\n return this._framebuffer.framebuffer;\n },\n },\n colorGBuffer: {\n get: function () {\n return this._framebuffer.getColorTexture(0);\n },\n },\n depthGBuffer: {\n get: function () {\n return this._framebuffer.getColorTexture(1);\n },\n },\n});\n\nfunction destroyFramebuffer(processor) {\n processor._framebuffer.destroy();\n processor._drawCommand = undefined;\n processor._clearCommand = undefined;\n}\n\nconst distanceAndEdlStrengthScratch = new Cartesian2();\n\nfunction createCommands(processor, context) {\n const blendFS = new ShaderSource({\n defines: [\"LOG_DEPTH_WRITE\"],\n sources: [PointCloudEyeDomeLightingShader],\n });\n\n const blendUniformMap = {\n u_pointCloud_colorGBuffer: function () {\n return processor.colorGBuffer;\n },\n u_pointCloud_depthGBuffer: function () {\n return processor.depthGBuffer;\n },\n u_distanceAndEdlStrength: function () {\n distanceAndEdlStrengthScratch.x = processor._radius;\n distanceAndEdlStrengthScratch.y = processor._strength;\n return distanceAndEdlStrengthScratch;\n },\n };\n\n const blendRenderState = RenderState.fromCache({\n blending: BlendingState.ALPHA_BLEND,\n depthMask: true,\n depthTest: {\n enabled: true,\n },\n stencilTest: StencilConstants.setCesium3DTileBit(),\n stencilMask: StencilConstants.CESIUM_3D_TILE_MASK,\n });\n\n processor._drawCommand = context.createViewportQuadCommand(blendFS, {\n uniformMap: blendUniformMap,\n renderState: blendRenderState,\n pass: Pass.CESIUM_3D_TILE,\n owner: processor,\n });\n\n processor._clearCommand = new ClearCommand({\n framebuffer: processor.framebuffer,\n color: new Color(0.0, 0.0, 0.0, 0.0),\n depth: 1.0,\n renderState: RenderState.fromCache(),\n pass: Pass.CESIUM_3D_TILE,\n owner: processor,\n });\n}\n\nfunction createResources(processor, context) {\n const width = context.drawingBufferWidth;\n const height = context.drawingBufferHeight;\n processor._framebuffer.update(context, width, height);\n createCommands(processor, context);\n}\n\nfunction isSupported(context) {\n return context.drawBuffers && context.fragmentDepth;\n}\n\nPointCloudEyeDomeLighting.isSupported = isSupported;\n\nfunction getECShaderProgram(context, shaderProgram) {\n let shader = context.shaderCache.getDerivedShaderProgram(shaderProgram, \"EC\");\n if (!defined(shader)) {\n const attributeLocations = shaderProgram._attributeLocations;\n\n const fs = shaderProgram.fragmentShaderSource.clone();\n\n fs.sources.splice(\n 0,\n 0,\n `layout (location = 0) out vec4 out_FragData_0;\\nlayout (location = 1) out vec4 out_FragData_1;`\n );\n\n fs.sources = fs.sources.map(function (source) {\n source = ShaderSource.replaceMain(\n source,\n \"czm_point_cloud_post_process_main\"\n );\n source = source.replaceAll(/out_FragColor/g, \"out_FragData_0\");\n return source;\n });\n\n fs.sources.push(\n \"void main() \\n\" +\n \"{ \\n\" +\n \" czm_point_cloud_post_process_main(); \\n\" +\n \"#ifdef LOG_DEPTH\\n\" +\n \" czm_writeLogDepth();\\n\" +\n \" out_FragData_1 = czm_packDepth(gl_FragDepth); \\n\" +\n \"#else\\n\" +\n \" out_FragData_1 = czm_packDepth(gl_FragCoord.z);\\n\" +\n \"#endif\\n\" +\n \"}\"\n );\n\n shader = context.shaderCache.createDerivedShaderProgram(\n shaderProgram,\n \"EC\",\n {\n vertexShaderSource: shaderProgram.vertexShaderSource,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n }\n );\n }\n\n return shader;\n}\n\nPointCloudEyeDomeLighting.prototype.update = function (\n frameState,\n commandStart,\n pointCloudShading,\n boundingVolume\n) {\n if (!isSupported(frameState.context)) {\n return;\n }\n\n this._strength = pointCloudShading.eyeDomeLightingStrength;\n this._radius =\n pointCloudShading.eyeDomeLightingRadius * frameState.pixelRatio;\n\n createResources(this, frameState.context);\n\n // Hijack existing point commands to render into an offscreen FBO.\n let i;\n const commandList = frameState.commandList;\n const commandEnd = commandList.length;\n\n for (i = commandStart; i < commandEnd; ++i) {\n const command = commandList[i];\n if (\n command.primitiveType !== PrimitiveType.POINTS ||\n command.pass === Pass.TRANSLUCENT\n ) {\n continue;\n }\n\n let derivedCommand;\n let originalShaderProgram;\n\n let derivedCommandObject = command.derivedCommands.pointCloudProcessor;\n if (defined(derivedCommandObject)) {\n derivedCommand = derivedCommandObject.command;\n originalShaderProgram = derivedCommandObject.originalShaderProgram;\n }\n\n if (\n !defined(derivedCommand) ||\n command.dirty ||\n originalShaderProgram !== command.shaderProgram ||\n derivedCommand.framebuffer !== this.framebuffer\n ) {\n // Prevent crash when tiles out-of-view come in-view during context size change or\n // when the underlying shader changes while EDL is disabled\n derivedCommand = DrawCommand.shallowClone(command, derivedCommand);\n derivedCommand.framebuffer = this.framebuffer;\n derivedCommand.shaderProgram = getECShaderProgram(\n frameState.context,\n command.shaderProgram\n );\n derivedCommand.castShadows = false;\n derivedCommand.receiveShadows = false;\n\n if (!defined(derivedCommandObject)) {\n derivedCommandObject = {\n command: derivedCommand,\n originalShaderProgram: command.shaderProgram,\n };\n command.derivedCommands.pointCloudProcessor = derivedCommandObject;\n }\n\n derivedCommandObject.originalShaderProgram = command.shaderProgram;\n }\n\n commandList[i] = derivedCommand;\n }\n\n const clearCommand = this._clearCommand;\n const blendCommand = this._drawCommand;\n\n blendCommand.boundingVolume = boundingVolume;\n\n // Blend EDL into the main FBO\n commandList.push(blendCommand);\n commandList.push(clearCommand);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see PointCloudEyeDomeLighting#destroy\n */\nPointCloudEyeDomeLighting.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * processor = processor && processor.destroy();\n *\n * @see PointCloudEyeDomeLighting#isDestroyed\n */\nPointCloudEyeDomeLighting.prototype.destroy = function () {\n destroyFramebuffer(this);\n return destroyObject(this);\n};\nexport default PointCloudEyeDomeLighting;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport PointCloudEyeDomeLighting from \"./PointCloudEyeDomeLighting.js\";\n\n/**\n * Options for performing point attenuation based on geometric error when rendering\n * point clouds using 3D Tiles.\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.attenuation=false] Perform point attenuation based on geometric error.\n * @param {number} [options.geometricErrorScale=1.0] Scale to be applied to each tile's geometric error.\n * @param {number} [options.maximumAttenuation] Maximum attenuation in pixels. Defaults to the Cesium3DTileset's maximumScreenSpaceError.\n * @param {number} [options.baseResolution] Average base resolution for the dataset in meters. Substitute for Geometric Error when not available.\n * @param {boolean} [options.eyeDomeLighting=true] When true, use eye dome lighting when drawing with point attenuation.\n * @param {number} [options.eyeDomeLightingStrength=1.0] Increasing this value increases contrast on slopes and edges.\n * @param {number} [options.eyeDomeLightingRadius=1.0] Increase the thickness of contours from eye dome lighting.\n * @param {boolean} [options.backFaceCulling=false] Determines whether back-facing points are hidden. This option works only if data has normals included.\n * @param {boolean} [options.normalShading=true] Determines whether a point cloud that contains normals is shaded by the scene's light source.\n *\n * @alias PointCloudShading\n * @constructor\n */\nfunction PointCloudShading(options) {\n const pointCloudShading = defaultValue(options, {});\n\n /**\n * Perform point attenuation based on geometric error.\n * @type {boolean}\n * @default false\n */\n this.attenuation = defaultValue(pointCloudShading.attenuation, false);\n\n /**\n * Scale to be applied to the geometric error before computing attenuation.\n * @type {number}\n * @default 1.0\n */\n this.geometricErrorScale = defaultValue(\n pointCloudShading.geometricErrorScale,\n 1.0\n );\n\n /**\n * Maximum point attenuation in pixels. If undefined, the Cesium3DTileset's maximumScreenSpaceError will be used.\n * @type {number}\n */\n this.maximumAttenuation = pointCloudShading.maximumAttenuation;\n\n /**\n * Average base resolution for the dataset in meters.\n * Used in place of geometric error when geometric error is 0.\n * If undefined, an approximation will be computed for each tile that has geometric error of 0.\n * @type {number}\n */\n this.baseResolution = pointCloudShading.baseResolution;\n\n /**\n * Use eye dome lighting when drawing with point attenuation\n * Requires support for EXT_frag_depth, OES_texture_float, and WEBGL_draw_buffers extensions in WebGL 1.0,\n * otherwise eye dome lighting is ignored.\n *\n * @type {boolean}\n * @default true\n */\n this.eyeDomeLighting = defaultValue(pointCloudShading.eyeDomeLighting, true);\n\n /**\n * Eye dome lighting strength (apparent contrast)\n * @type {number}\n * @default 1.0\n */\n this.eyeDomeLightingStrength = defaultValue(\n pointCloudShading.eyeDomeLightingStrength,\n 1.0\n );\n\n /**\n * Thickness of contours from eye dome lighting\n * @type {number}\n * @default 1.0\n */\n this.eyeDomeLightingRadius = defaultValue(\n pointCloudShading.eyeDomeLightingRadius,\n 1.0\n );\n\n /**\n * Determines whether back-facing points are hidden.\n * This option works only if data has normals included.\n *\n * @type {boolean}\n * @default false\n */\n this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false);\n\n /**\n * Determines whether a point cloud that contains normals is shaded by the scene's light source.\n *\n * @type {boolean}\n * @default true\n */\n this.normalShading = defaultValue(pointCloudShading.normalShading, true);\n}\n\n/**\n * Determines if point cloud shading is supported.\n *\n * @param {Scene} scene The scene.\n * @returns {boolean} true if point cloud shading is supported; otherwise, returns false\n */\nPointCloudShading.isSupported = function (scene) {\n return PointCloudEyeDomeLighting.isSupported(scene.context);\n};\nexport default PointCloudShading;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OrthographicFrustum from \"../Core/OrthographicFrustum.js\";\nimport OrthographicOffCenterFrustum from \"../Core/OrthographicOffCenterFrustum.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport SceneMode from \"./SceneMode.js\";\n\n/**\n * Functions that do scene-dependent transforms between rendering-related coordinate systems.\n *\n * @namespace SceneTransforms\n */\nconst SceneTransforms = {};\n\nconst actualPositionScratch = new Cartesian4(0, 0, 0, 1);\nlet positionCC = new Cartesian4();\nconst scratchViewport = new BoundingRectangle();\n\nconst scratchWindowCoord0 = new Cartesian2();\nconst scratchWindowCoord1 = new Cartesian2();\n\n/**\n * Transforms a position in WGS84 coordinates to window coordinates. This is commonly used to place an\n * HTML element at the same screen position as an object in the scene.\n *\n * @param {Scene} scene The scene.\n * @param {Cartesian3} position The position in WGS84 (world) coordinates.\n * @param {Cartesian2} [result] An optional object to return the input position transformed to window coordinates.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. This may be undefined if the input position is near the center of the ellipsoid.\n *\n * @example\n * // Output the window position of longitude/latitude (0, 0) every time the mouse moves.\n * const scene = widget.scene;\n * const ellipsoid = scene.globe.ellipsoid;\n * const position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);\n * handler.setInputAction(function(movement) {\n * console.log(Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, position));\n * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);\n */\nSceneTransforms.wgs84ToWindowCoordinates = function (scene, position, result) {\n return SceneTransforms.wgs84WithEyeOffsetToWindowCoordinates(\n scene,\n position,\n Cartesian3.ZERO,\n result\n );\n};\n\nconst scratchCartesian4 = new Cartesian4();\nconst scratchEyeOffset = new Cartesian3();\n\nfunction worldToClip(position, eyeOffset, camera, result) {\n const viewMatrix = camera.viewMatrix;\n\n const positionEC = Matrix4.multiplyByVector(\n viewMatrix,\n Cartesian4.fromElements(\n position.x,\n position.y,\n position.z,\n 1,\n scratchCartesian4\n ),\n scratchCartesian4\n );\n\n const zEyeOffset = Cartesian3.multiplyComponents(\n eyeOffset,\n Cartesian3.normalize(positionEC, scratchEyeOffset),\n scratchEyeOffset\n );\n positionEC.x += eyeOffset.x + zEyeOffset.x;\n positionEC.y += eyeOffset.y + zEyeOffset.y;\n positionEC.z += zEyeOffset.z;\n\n return Matrix4.multiplyByVector(\n camera.frustum.projectionMatrix,\n positionEC,\n result\n );\n}\n\nconst scratchMaxCartographic = new Cartographic(\n Math.PI,\n CesiumMath.PI_OVER_TWO\n);\nconst scratchProjectedCartesian = new Cartesian3();\nconst scratchCameraPosition = new Cartesian3();\n\n/**\n * @private\n */\nSceneTransforms.wgs84WithEyeOffsetToWindowCoordinates = function (\n scene,\n position,\n eyeOffset,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n if (!defined(position)) {\n throw new DeveloperError(\"position is required.\");\n }\n //>>includeEnd('debug');\n\n // Transform for 3D, 2D, or Columbus view\n const frameState = scene.frameState;\n const actualPosition = SceneTransforms.computeActualWgs84Position(\n frameState,\n position,\n actualPositionScratch\n );\n\n if (!defined(actualPosition)) {\n return undefined;\n }\n\n // Assuming viewport takes up the entire canvas...\n const canvas = scene.canvas;\n const viewport = scratchViewport;\n viewport.x = 0;\n viewport.y = 0;\n viewport.width = canvas.clientWidth;\n viewport.height = canvas.clientHeight;\n\n const camera = scene.camera;\n let cameraCentered = false;\n\n if (frameState.mode === SceneMode.SCENE2D) {\n const projection = scene.mapProjection;\n const maxCartographic = scratchMaxCartographic;\n const maxCoord = projection.project(\n maxCartographic,\n scratchProjectedCartesian\n );\n\n const cameraPosition = Cartesian3.clone(\n camera.position,\n scratchCameraPosition\n );\n const frustum = camera.frustum.clone();\n\n const viewportTransformation = Matrix4.computeViewportTransformation(\n viewport,\n 0.0,\n 1.0,\n new Matrix4()\n );\n const projectionMatrix = camera.frustum.projectionMatrix;\n\n const x = camera.positionWC.y;\n const eyePoint = Cartesian3.fromElements(\n CesiumMath.sign(x) * maxCoord.x - x,\n 0.0,\n -camera.positionWC.x\n );\n const windowCoordinates = Transforms.pointToGLWindowCoordinates(\n projectionMatrix,\n viewportTransformation,\n eyePoint\n );\n\n if (\n x === 0.0 ||\n windowCoordinates.x <= 0.0 ||\n windowCoordinates.x >= canvas.clientWidth\n ) {\n cameraCentered = true;\n } else {\n if (windowCoordinates.x > canvas.clientWidth * 0.5) {\n viewport.width = windowCoordinates.x;\n\n camera.frustum.right = maxCoord.x - x;\n\n positionCC = worldToClip(actualPosition, eyeOffset, camera, positionCC);\n SceneTransforms.clipToGLWindowCoordinates(\n viewport,\n positionCC,\n scratchWindowCoord0\n );\n\n viewport.x += windowCoordinates.x;\n\n camera.position.x = -camera.position.x;\n\n const right = camera.frustum.right;\n camera.frustum.right = -camera.frustum.left;\n camera.frustum.left = -right;\n\n positionCC = worldToClip(actualPosition, eyeOffset, camera, positionCC);\n SceneTransforms.clipToGLWindowCoordinates(\n viewport,\n positionCC,\n scratchWindowCoord1\n );\n } else {\n viewport.x += windowCoordinates.x;\n viewport.width -= windowCoordinates.x;\n\n camera.frustum.left = -maxCoord.x - x;\n\n positionCC = worldToClip(actualPosition, eyeOffset, camera, positionCC);\n SceneTransforms.clipToGLWindowCoordinates(\n viewport,\n positionCC,\n scratchWindowCoord0\n );\n\n viewport.x = viewport.x - viewport.width;\n\n camera.position.x = -camera.position.x;\n\n const left = camera.frustum.left;\n camera.frustum.left = -camera.frustum.right;\n camera.frustum.right = -left;\n\n positionCC = worldToClip(actualPosition, eyeOffset, camera, positionCC);\n SceneTransforms.clipToGLWindowCoordinates(\n viewport,\n positionCC,\n scratchWindowCoord1\n );\n }\n\n Cartesian3.clone(cameraPosition, camera.position);\n camera.frustum = frustum.clone();\n\n result = Cartesian2.clone(scratchWindowCoord0, result);\n if (result.x < 0.0 || result.x > canvas.clientWidth) {\n result.x = scratchWindowCoord1.x;\n }\n }\n }\n\n if (frameState.mode !== SceneMode.SCENE2D || cameraCentered) {\n // View-projection matrix to transform from world coordinates to clip coordinates\n positionCC = worldToClip(actualPosition, eyeOffset, camera, positionCC);\n if (\n positionCC.z < 0 &&\n !(camera.frustum instanceof OrthographicFrustum) &&\n !(camera.frustum instanceof OrthographicOffCenterFrustum)\n ) {\n return undefined;\n }\n\n result = SceneTransforms.clipToGLWindowCoordinates(\n viewport,\n positionCC,\n result\n );\n }\n\n result.y = canvas.clientHeight - result.y;\n return result;\n};\n\n/**\n * Transforms a position in WGS84 coordinates to drawing buffer coordinates. This may produce different\n * results from SceneTransforms.wgs84ToWindowCoordinates when the browser zoom is not 100%, or on high-DPI displays.\n *\n * @param {Scene} scene The scene.\n * @param {Cartesian3} position The position in WGS84 (world) coordinates.\n * @param {Cartesian2} [result] An optional object to return the input position transformed to window coordinates.\n * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. This may be undefined if the input position is near the center of the ellipsoid.\n *\n * @example\n * // Output the window position of longitude/latitude (0, 0) every time the mouse moves.\n * const scene = widget.scene;\n * const ellipsoid = scene.globe.ellipsoid;\n * const position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);\n * const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);\n * handler.setInputAction(function(movement) {\n * console.log(Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, position));\n * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);\n */\nSceneTransforms.wgs84ToDrawingBufferCoordinates = function (\n scene,\n position,\n result\n) {\n result = SceneTransforms.wgs84ToWindowCoordinates(scene, position, result);\n if (!defined(result)) {\n return undefined;\n }\n\n return SceneTransforms.transformWindowToDrawingBuffer(scene, result, result);\n};\n\nconst projectedPosition = new Cartesian3();\nconst positionInCartographic = new Cartographic();\n\n/**\n * @private\n */\nSceneTransforms.computeActualWgs84Position = function (\n frameState,\n position,\n result\n) {\n const mode = frameState.mode;\n\n if (mode === SceneMode.SCENE3D) {\n return Cartesian3.clone(position, result);\n }\n\n const projection = frameState.mapProjection;\n const cartographic = projection.ellipsoid.cartesianToCartographic(\n position,\n positionInCartographic\n );\n if (!defined(cartographic)) {\n return undefined;\n }\n\n projection.project(cartographic, projectedPosition);\n\n if (mode === SceneMode.COLUMBUS_VIEW) {\n return Cartesian3.fromElements(\n projectedPosition.z,\n projectedPosition.x,\n projectedPosition.y,\n result\n );\n }\n\n if (mode === SceneMode.SCENE2D) {\n return Cartesian3.fromElements(\n 0.0,\n projectedPosition.x,\n projectedPosition.y,\n result\n );\n }\n\n // mode === SceneMode.MORPHING\n const morphTime = frameState.morphTime;\n return Cartesian3.fromElements(\n CesiumMath.lerp(projectedPosition.z, position.x, morphTime),\n CesiumMath.lerp(projectedPosition.x, position.y, morphTime),\n CesiumMath.lerp(projectedPosition.y, position.z, morphTime),\n result\n );\n};\n\nconst positionNDC = new Cartesian3();\nconst positionWC = new Cartesian3();\nconst viewportTransform = new Matrix4();\n\n/**\n * @private\n */\nSceneTransforms.clipToGLWindowCoordinates = function (\n viewport,\n position,\n result\n) {\n // Perspective divide to transform from clip coordinates to normalized device coordinates\n Cartesian3.divideByScalar(position, position.w, positionNDC);\n\n // Viewport transform to transform from clip coordinates to window coordinates\n Matrix4.computeViewportTransformation(viewport, 0.0, 1.0, viewportTransform);\n Matrix4.multiplyByPoint(viewportTransform, positionNDC, positionWC);\n\n return Cartesian2.fromCartesian3(positionWC, result);\n};\n\n/**\n * @private\n */\nSceneTransforms.transformWindowToDrawingBuffer = function (\n scene,\n windowPosition,\n result\n) {\n const canvas = scene.canvas;\n const xScale = scene.drawingBufferWidth / canvas.clientWidth;\n const yScale = scene.drawingBufferHeight / canvas.clientHeight;\n return Cartesian2.fromElements(\n windowPosition.x * xScale,\n windowPosition.y * yScale,\n result\n );\n};\n\nconst scratchNDC = new Cartesian4();\nconst scratchWorldCoords = new Cartesian4();\n\n/**\n * @private\n */\nSceneTransforms.drawingBufferToWgs84Coordinates = function (\n scene,\n drawingBufferPosition,\n depth,\n result\n) {\n const context = scene.context;\n const uniformState = context.uniformState;\n\n const currentFrustum = uniformState.currentFrustum;\n const near = currentFrustum.x;\n const far = currentFrustum.y;\n\n if (scene.frameState.useLogDepth) {\n // transforming logarithmic depth of form\n // log2(z + 1) / log2( far + 1);\n // to perspective form\n // (far - far * near / z) / (far - near)\n const log2Depth = depth * uniformState.log2FarDepthFromNearPlusOne;\n const depthFromNear = Math.pow(2.0, log2Depth) - 1.0;\n depth = (far * (1.0 - near / (depthFromNear + near))) / (far - near);\n }\n\n const viewport = scene.view.passState.viewport;\n const ndc = Cartesian4.clone(Cartesian4.UNIT_W, scratchNDC);\n ndc.x = ((drawingBufferPosition.x - viewport.x) / viewport.width) * 2.0 - 1.0;\n ndc.y =\n ((drawingBufferPosition.y - viewport.y) / viewport.height) * 2.0 - 1.0;\n ndc.z = depth * 2.0 - 1.0;\n ndc.w = 1.0;\n\n let worldCoords;\n let frustum = scene.camera.frustum;\n if (!defined(frustum.fovy)) {\n const offCenterFrustum = frustum.offCenterFrustum;\n if (defined(offCenterFrustum)) {\n frustum = offCenterFrustum;\n }\n worldCoords = scratchWorldCoords;\n worldCoords.x =\n (ndc.x * (frustum.right - frustum.left) + frustum.left + frustum.right) *\n 0.5;\n worldCoords.y =\n (ndc.y * (frustum.top - frustum.bottom) + frustum.bottom + frustum.top) *\n 0.5;\n worldCoords.z = (ndc.z * (near - far) - near - far) * 0.5;\n worldCoords.w = 1.0;\n\n worldCoords = Matrix4.multiplyByVector(\n uniformState.inverseView,\n worldCoords,\n worldCoords\n );\n } else {\n worldCoords = Matrix4.multiplyByVector(\n uniformState.inverseViewProjection,\n ndc,\n scratchWorldCoords\n );\n\n // Reverse perspective divide\n const w = 1.0 / worldCoords.w;\n Cartesian3.multiplyByScalar(worldCoords, w, worldCoords);\n }\n return Cartesian3.fromCartesian4(worldCoords, result);\n};\nexport default SceneTransforms;\n", "/**\n * The direction to display a primitive or ImageryLayer relative to the {@link Scene#splitPosition}.\n *\n * @enum {number}\n *\n * @see ImageryLayer#splitDirection\n * @see Cesium3DTileset#splitDirection\n */\nconst SplitDirection = {\n /**\n * Display the primitive or ImageryLayer to the left of the {@link Scene#splitPosition}.\n *\n * @type {number}\n * @constant\n */\n LEFT: -1.0,\n\n /**\n * Always display the primitive or ImageryLayer.\n *\n * @type {number}\n * @constant\n */\n NONE: 0.0,\n\n /**\n * Display the primitive or ImageryLayer to the right of the {@link Scene#splitPosition}.\n *\n * @type {number}\n * @constant\n */\n RIGHT: 1.0,\n};\nexport default Object.freeze(SplitDirection);\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * Handles parsing of a Batched 3D Model.\n *\n * @namespace B3dmParser\n * @private\n */\nconst B3dmParser = {};\nB3dmParser._deprecationWarning = deprecationWarning;\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\n/**\n * Parses the contents of a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel|Batched 3D Model}.\n *\n * @private\n *\n * @param {ArrayBuffer} arrayBuffer The array buffer containing the b3dm.\n * @param {number} [byteOffset=0] The byte offset of the beginning of the b3dm in the array buffer.\n * @returns {object} Returns an object with the batch length, feature table (binary and json), batch table (binary and json) and glTF parts of the b3dm.\n */\nB3dmParser.parse = function (arrayBuffer, byteOffset) {\n const byteStart = defaultValue(byteOffset, 0);\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n byteOffset = byteStart;\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Batched 3D Model version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n const byteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n let featureTableJsonByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n let featureTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n let batchTableJsonByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n let batchTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n let batchLength;\n\n // Legacy header #1: [batchLength] [batchTableByteLength]\n // Legacy header #2: [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]\n // Current header: [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]\n // If the header is in the first legacy format 'batchTableJsonByteLength' will be the start of the JSON string (a quotation mark) or the glTF magic.\n // Accordingly its first byte will be either 0x22 or 0x67, and so the minimum uint32 expected is 0x22000000 = 570425344 = 570MB. It is unlikely that the feature table JSON will exceed this length.\n // The check for the second legacy format is similar, except it checks 'batchTableBinaryByteLength' instead\n if (batchTableJsonByteLength >= 570425344) {\n // First legacy check\n byteOffset -= sizeOfUint32 * 2;\n batchLength = featureTableJsonByteLength;\n batchTableJsonByteLength = featureTableBinaryByteLength;\n batchTableBinaryByteLength = 0;\n featureTableJsonByteLength = 0;\n featureTableBinaryByteLength = 0;\n B3dmParser._deprecationWarning(\n \"b3dm-legacy-header\",\n \"This b3dm header is using the legacy format [batchLength] [batchTableByteLength]. The new format is [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength] from https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel.\"\n );\n } else if (batchTableBinaryByteLength >= 570425344) {\n // Second legacy check\n byteOffset -= sizeOfUint32;\n batchLength = batchTableJsonByteLength;\n batchTableJsonByteLength = featureTableJsonByteLength;\n batchTableBinaryByteLength = featureTableBinaryByteLength;\n featureTableJsonByteLength = 0;\n featureTableBinaryByteLength = 0;\n B3dmParser._deprecationWarning(\n \"b3dm-legacy-header\",\n \"This b3dm header is using the legacy format [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength]. The new format is [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength] from https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel.\"\n );\n }\n\n let featureTableJson;\n if (featureTableJsonByteLength === 0) {\n featureTableJson = {\n BATCH_LENGTH: defaultValue(batchLength, 0),\n };\n } else {\n featureTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n featureTableJsonByteLength\n );\n byteOffset += featureTableJsonByteLength;\n }\n\n const featureTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n featureTableBinaryByteLength\n );\n byteOffset += featureTableBinaryByteLength;\n\n let batchTableJson;\n let batchTableBinary;\n if (batchTableJsonByteLength > 0) {\n // PERFORMANCE_IDEA: is it possible to allocate this on-demand? Perhaps keep the\n // arraybuffer/string compressed in memory and then decompress it when it is first accessed.\n //\n // We could also make another request for it, but that would make the property set/get\n // API async, and would double the number of numbers in some cases.\n batchTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n batchTableJsonByteLength\n );\n byteOffset += batchTableJsonByteLength;\n\n if (batchTableBinaryByteLength > 0) {\n // Has a batch table binary\n batchTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n batchTableBinaryByteLength\n );\n // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed\n batchTableBinary = new Uint8Array(batchTableBinary);\n byteOffset += batchTableBinaryByteLength;\n }\n }\n\n const gltfByteLength = byteStart + byteLength - byteOffset;\n if (gltfByteLength === 0) {\n throw new RuntimeError(\"glTF byte length must be greater than 0.\");\n }\n\n let gltfView;\n if (byteOffset % 4 === 0) {\n gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength);\n } else {\n // Create a copy of the glb so that it is 4-byte aligned\n B3dmParser._deprecationWarning(\n \"b3dm-glb-unaligned\",\n \"The embedded glb is not aligned to a 4-byte boundary.\"\n );\n gltfView = new Uint8Array(\n uint8Array.subarray(byteOffset, byteOffset + gltfByteLength)\n );\n }\n\n return {\n batchLength: batchLength,\n featureTableJson: featureTableJson,\n featureTableBinary: featureTableBinary,\n batchTableJson: batchTableJson,\n batchTableBinary: batchTableBinary,\n gltf: gltfView,\n };\n};\n\nexport default B3dmParser;\n", "import ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\n\n/**\n * @private\n */\nfunction Cesium3DTileFeatureTable(featureTableJson, featureTableBinary) {\n this.json = featureTableJson;\n this.buffer = featureTableBinary;\n this._cachedTypedArrays = {};\n this.featuresLength = 0;\n}\n\nfunction getTypedArrayFromBinary(\n featureTable,\n semantic,\n componentType,\n componentLength,\n count,\n byteOffset\n) {\n const cachedTypedArrays = featureTable._cachedTypedArrays;\n let typedArray = cachedTypedArrays[semantic];\n if (!defined(typedArray)) {\n typedArray = ComponentDatatype.createArrayBufferView(\n componentType,\n featureTable.buffer.buffer,\n featureTable.buffer.byteOffset + byteOffset,\n count * componentLength\n );\n cachedTypedArrays[semantic] = typedArray;\n }\n return typedArray;\n}\n\nfunction getTypedArrayFromArray(featureTable, semantic, componentType, array) {\n const cachedTypedArrays = featureTable._cachedTypedArrays;\n let typedArray = cachedTypedArrays[semantic];\n if (!defined(typedArray)) {\n typedArray = ComponentDatatype.createTypedArray(componentType, array);\n cachedTypedArrays[semantic] = typedArray;\n }\n return typedArray;\n}\n\nCesium3DTileFeatureTable.prototype.getGlobalProperty = function (\n semantic,\n componentType,\n componentLength\n) {\n const jsonValue = this.json[semantic];\n if (!defined(jsonValue)) {\n return undefined;\n }\n\n if (defined(jsonValue.byteOffset)) {\n componentType = defaultValue(componentType, ComponentDatatype.UNSIGNED_INT);\n componentLength = defaultValue(componentLength, 1);\n return getTypedArrayFromBinary(\n this,\n semantic,\n componentType,\n componentLength,\n 1,\n jsonValue.byteOffset\n );\n }\n\n return jsonValue;\n};\n\nCesium3DTileFeatureTable.prototype.hasProperty = function (semantic) {\n return defined(this.json[semantic]);\n};\n\nCesium3DTileFeatureTable.prototype.getPropertyArray = function (\n semantic,\n componentType,\n componentLength\n) {\n const jsonValue = this.json[semantic];\n if (!defined(jsonValue)) {\n return undefined;\n }\n\n if (defined(jsonValue.byteOffset)) {\n if (defined(jsonValue.componentType)) {\n componentType = ComponentDatatype.fromName(jsonValue.componentType);\n }\n return getTypedArrayFromBinary(\n this,\n semantic,\n componentType,\n componentLength,\n this.featuresLength,\n jsonValue.byteOffset\n );\n }\n\n return getTypedArrayFromArray(this, semantic, componentType, jsonValue);\n};\n\nCesium3DTileFeatureTable.prototype.getProperty = function (\n semantic,\n componentType,\n componentLength,\n featureId,\n result\n) {\n const jsonValue = this.json[semantic];\n if (!defined(jsonValue)) {\n return undefined;\n }\n\n const typedArray = this.getPropertyArray(\n semantic,\n componentType,\n componentLength\n );\n\n if (componentLength === 1) {\n return typedArray[featureId];\n }\n\n for (let i = 0; i < componentLength; ++i) {\n result[i] = typedArray[componentLength * featureId + i];\n }\n\n return result;\n};\nexport default Cesium3DTileFeatureTable;\n", "import Check from \"../Core/Check.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport BatchTableHierarchy from \"./BatchTableHierarchy.js\";\nimport StructuralMetadata from \"./StructuralMetadata.js\";\nimport PropertyAttribute from \"./PropertyAttribute.js\";\nimport PropertyTable from \"./PropertyTable.js\";\nimport getBinaryAccessor from \"./getBinaryAccessor.js\";\nimport JsonMetadataTable from \"./JsonMetadataTable.js\";\nimport MetadataClass from \"./MetadataClass.js\";\nimport MetadataSchema from \"./MetadataSchema.js\";\nimport MetadataTable from \"./MetadataTable.js\";\nimport ModelComponents from \"./ModelComponents.js\";\nimport ModelUtility from \"./Model/ModelUtility.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\n\n/**\n * An object that parses the the 3D Tiles 1.0 batch table and transcodes it to\n * be compatible with structural metadata from the EXT_structural_metadata glTF extension\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} for glTF.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.count The number of features in the batch table.\n * @param {object} options.batchTable The batch table JSON\n * @param {Uint8Array} [options.binaryBody] The batch table binary body\n * @param {boolean} [options.parseAsPropertyAttributes=false] If true, binary properties are parsed as property attributes instead of a property table. This is used for .pnts models for GPU styling.\n * @param {ModelComponents.Attribute[]} [options.customAttributeOutput] Pass in an empty array here and this method will populate it with a list of custom attributes that will store the values of the property attributes. The attributes will be created with typed arrays, the caller is responsible for uploading them to the GPU. This option is required when options.parseAsPropertyAttributes is true.\n * @return {StructuralMetadata} A transcoded structural metadata object\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction parseBatchTable(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.count\", options.count);\n Check.typeOf.object(\"options.batchTable\", options.batchTable);\n //>>includeEnd('debug');\n\n const featureCount = options.count;\n const batchTable = options.batchTable;\n const binaryBody = options.binaryBody;\n const parseAsPropertyAttributes = defaultValue(\n options.parseAsPropertyAttributes,\n false\n );\n const customAttributeOutput = options.customAttributeOutput;\n\n //>>includeStart('debug', pragmas.debug);\n if (parseAsPropertyAttributes && !defined(customAttributeOutput)) {\n throw new DeveloperError(\n \"customAttributeOutput is required when parsing batch table as property attributes\"\n );\n }\n //>>includeEnd('debug');\n\n // divide properties into binary, json and hierarchy\n const partitionResults = partitionProperties(batchTable);\n\n let jsonMetadataTable;\n if (defined(partitionResults.jsonProperties)) {\n jsonMetadataTable = new JsonMetadataTable({\n count: featureCount,\n properties: partitionResults.jsonProperties,\n });\n }\n\n let hierarchy;\n if (defined(partitionResults.hierarchy)) {\n hierarchy = new BatchTableHierarchy({\n extension: partitionResults.hierarchy,\n binaryBody: binaryBody,\n });\n }\n\n const className = MetadataClass.BATCH_TABLE_CLASS_NAME;\n const binaryProperties = partitionResults.binaryProperties;\n\n let metadataTable;\n let propertyAttributes;\n let transcodedSchema;\n if (parseAsPropertyAttributes) {\n const attributeResults = transcodeBinaryPropertiesAsPropertyAttributes(\n featureCount,\n className,\n binaryProperties,\n binaryBody,\n customAttributeOutput\n );\n transcodedSchema = attributeResults.transcodedSchema;\n const propertyAttribute = new PropertyAttribute({\n propertyAttribute: attributeResults.propertyAttributeJson,\n class: attributeResults.transcodedClass,\n });\n\n propertyAttributes = [propertyAttribute];\n } else {\n const binaryResults = transcodeBinaryProperties(\n featureCount,\n className,\n binaryProperties,\n binaryBody\n );\n transcodedSchema = binaryResults.transcodedSchema;\n const featureTableJson = binaryResults.featureTableJson;\n metadataTable = new MetadataTable({\n count: featureTableJson.count,\n properties: featureTableJson.properties,\n class: binaryResults.transcodedClass,\n bufferViews: binaryResults.bufferViewsTypedArrays,\n });\n propertyAttributes = [];\n }\n\n const propertyTables = [];\n if (\n defined(metadataTable) ||\n defined(jsonMetadataTable) ||\n defined(hierarchy)\n ) {\n const propertyTable = new PropertyTable({\n id: 0,\n name: \"Batch Table\",\n count: featureCount,\n metadataTable: metadataTable,\n jsonMetadataTable: jsonMetadataTable,\n batchTableHierarchy: hierarchy,\n });\n propertyTables.push(propertyTable);\n }\n\n const metadataOptions = {\n schema: transcodedSchema,\n propertyTables: propertyTables,\n propertyAttributes: propertyAttributes,\n extensions: partitionResults.extensions,\n extras: partitionResults.extras,\n };\n\n return new StructuralMetadata(metadataOptions);\n}\n\n/**\n * Divide the batch table's properties into binary, JSON and hierarchy\n * extension as each is handled separately\n *\n * @param {object} batchTable The batch table JSON\n * @returns {object} The batch table divided into binary, JSON and hierarchy portions. Extras and extensions are also divided out for ease of processing.\n *\n * @private\n */\nfunction partitionProperties(batchTable) {\n const legacyHierarchy = batchTable.HIERARCHY;\n const extras = batchTable.extras;\n const extensions = batchTable.extensions;\n\n let hierarchyExtension;\n if (defined(legacyHierarchy)) {\n parseBatchTable._deprecationWarning(\n \"batchTableHierarchyExtension\",\n \"The batch table HIERARCHY property has been moved to an extension. Use extensions.3DTILES_batch_table_hierarchy instead.\"\n );\n hierarchyExtension = legacyHierarchy;\n } else if (defined(extensions)) {\n hierarchyExtension = extensions[\"3DTILES_batch_table_hierarchy\"];\n }\n\n // A JsonMetadataTable is only allocated as needed.\n let jsonProperties;\n // A MetadataTable or PropertyAttribute will always be created, even if\n // there are no properties.\n const binaryProperties = {};\n for (const propertyId in batchTable) {\n if (\n !batchTable.hasOwnProperty(propertyId) ||\n // these cases were handled above;\n propertyId === \"HIERARCHY\" ||\n propertyId === \"extensions\" ||\n propertyId === \"extras\"\n ) {\n continue;\n }\n\n const property = batchTable[propertyId];\n if (Array.isArray(property)) {\n jsonProperties = defined(jsonProperties) ? jsonProperties : {};\n jsonProperties[propertyId] = property;\n } else {\n binaryProperties[propertyId] = property;\n }\n }\n\n return {\n binaryProperties: binaryProperties,\n jsonProperties: jsonProperties,\n hierarchy: hierarchyExtension,\n extras: extras,\n extensions: extensions,\n };\n}\n\n/**\n * Transcode the binary properties of the batch table to be compatible with\n * EXT_structural_metadata\n *\n * @param {number} featureCount The number of features in the batch table\n * @param {string} className The name of the metadata class to be created.\n * @param {Object} binaryProperties A dictionary of property ID to property definition\n * @param {Uint8Array} [binaryBody] The binary body of the batch table\n * @return {object} Transcoded data needed for constructing a {@link StructuralMetadata} object.\n *\n * @private\n */\nfunction transcodeBinaryProperties(\n featureCount,\n className,\n binaryProperties,\n binaryBody\n) {\n const classProperties = {};\n const featureTableProperties = {};\n const bufferViewsTypedArrays = {};\n let bufferViewCount = 0;\n for (const propertyId in binaryProperties) {\n if (!binaryProperties.hasOwnProperty(propertyId)) {\n continue;\n }\n\n if (!defined(binaryBody)) {\n throw new RuntimeError(\n `Property ${propertyId} requires a batch table binary.`\n );\n }\n\n const property = binaryProperties[propertyId];\n const binaryAccessor = getBinaryAccessor(property);\n\n featureTableProperties[propertyId] = {\n bufferView: bufferViewCount,\n };\n\n classProperties[propertyId] = transcodePropertyType(property);\n\n bufferViewsTypedArrays[\n bufferViewCount\n ] = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + property.byteOffset,\n featureCount\n );\n\n bufferViewCount++;\n }\n\n const schemaJson = {\n classes: {},\n };\n schemaJson.classes[className] = {\n properties: classProperties,\n };\n\n const transcodedSchema = MetadataSchema.fromJson(schemaJson);\n\n const featureTableJson = {\n class: className,\n count: featureCount,\n properties: featureTableProperties,\n };\n\n return {\n featureTableJson: featureTableJson,\n bufferViewsTypedArrays: bufferViewsTypedArrays,\n transcodedSchema: transcodedSchema,\n transcodedClass: transcodedSchema.classes[className],\n };\n}\n\nfunction transcodeBinaryPropertiesAsPropertyAttributes(\n featureCount,\n className,\n binaryProperties,\n binaryBody,\n customAttributeOutput\n) {\n const classProperties = {};\n const propertyAttributeProperties = {};\n let nextPlaceholderId = 0;\n\n for (const propertyId in binaryProperties) {\n if (!binaryProperties.hasOwnProperty(propertyId)) {\n continue;\n }\n\n // For draco-compressed attributes from .pnts files, the results will be\n // stored in separate typed arrays. These will be used in place of the\n // binary body\n const property = binaryProperties[propertyId];\n if (!defined(binaryBody) && !defined(property.typedArray)) {\n throw new RuntimeError(\n `Property ${propertyId} requires a batch table binary.`\n );\n }\n\n let sanitizedPropertyId = ModelUtility.sanitizeGlslIdentifier(propertyId);\n\n // If the sanitized string is empty or a duplicate, use a placeholder\n // name instead. This will work for styling, but it may lead to undefined\n // behavior in CustomShader, since\n // - different tiles may pick a different placeholder ID due to the\n // collection being unordered\n // - different tiles may have different number of properties.\n if (\n sanitizedPropertyId === \"\" ||\n classProperties.hasOwnProperty(sanitizedPropertyId)\n ) {\n sanitizedPropertyId = `property_${nextPlaceholderId}`;\n nextPlaceholderId++;\n }\n\n const classProperty = transcodePropertyType(property);\n classProperty.name = propertyId;\n classProperties[sanitizedPropertyId] = classProperty;\n\n // Extract the typed array and create a custom attribute as a typed array.\n // The caller must add the results to the ModelComponents, and upload the\n // typed array to the GPU. The attribute name is converted to all capitals\n // and underscores, like a glTF custom attribute.\n //\n // For example, if the original property ID was 'Temperature \u2103', the result\n // is _TEMPERATURE\n let customAttributeName = sanitizedPropertyId.toUpperCase();\n if (!customAttributeName.startsWith(\"_\")) {\n customAttributeName = `_${customAttributeName}`;\n }\n\n // for .pnts with draco compression, property.typedArray is used\n // instead of the binary body.\n let attributeTypedArray = property.typedArray;\n if (!defined(attributeTypedArray)) {\n const binaryAccessor = getBinaryAccessor(property);\n attributeTypedArray = binaryAccessor.createArrayBufferView(\n binaryBody.buffer,\n binaryBody.byteOffset + property.byteOffset,\n featureCount\n );\n }\n\n const attribute = new ModelComponents.Attribute();\n attribute.name = customAttributeName;\n attribute.count = featureCount;\n attribute.type = property.type;\n const componentDatatype = ComponentDatatype.fromTypedArray(\n attributeTypedArray\n );\n if (\n componentDatatype === ComponentDatatype.INT ||\n componentDatatype === ComponentDatatype.UNSIGNED_INT ||\n componentDatatype === ComponentDatatype.DOUBLE\n ) {\n parseBatchTable._oneTimeWarning(\n \"Cast pnts property to floats\",\n `Point cloud property \"${customAttributeName}\" will be cast to a float array because INT, UNSIGNED_INT, and DOUBLE are not valid WebGL vertex attribute types. Some precision may be lost.`\n );\n attributeTypedArray = new Float32Array(attributeTypedArray);\n }\n attribute.componentDatatype = ComponentDatatype.fromTypedArray(\n attributeTypedArray\n );\n attribute.typedArray = attributeTypedArray;\n customAttributeOutput.push(attribute);\n\n // Refer to the custom attribute name from the property attribute\n propertyAttributeProperties[sanitizedPropertyId] = {\n attribute: customAttributeName,\n };\n }\n\n const schemaJson = {\n classes: {},\n };\n schemaJson.classes[className] = {\n properties: classProperties,\n };\n\n const transcodedSchema = MetadataSchema.fromJson(schemaJson);\n\n const propertyAttributeJson = {\n properties: propertyAttributeProperties,\n };\n\n return {\n class: className,\n propertyAttributeJson: propertyAttributeJson,\n transcodedSchema: transcodedSchema,\n transcodedClass: transcodedSchema.classes[className],\n };\n}\n\n/**\n * Given a property definition from the batch table, compute the equivalent\n * EXT_structural_metadata type definition\n *\n * @param {object} property The batch table property definition\n * @return {object} The corresponding structural metadata property definition\n * @private\n */\nfunction transcodePropertyType(property) {\n const componentType = transcodeComponentType(property.componentType);\n\n return {\n type: property.type,\n componentType: componentType,\n };\n}\n\n/**\n * Convert the component type of a batch table property to the corresponding\n * type used with structural metadata\n *\n * @property {string} componentType the batch table's component type\n * @return {string} The corresponding structural metadata data type\n *\n * @private\n */\nfunction transcodeComponentType(componentType) {\n switch (componentType) {\n case \"BYTE\":\n return \"INT8\";\n case \"UNSIGNED_BYTE\":\n return \"UINT8\";\n case \"SHORT\":\n return \"INT16\";\n case \"UNSIGNED_SHORT\":\n return \"UINT16\";\n case \"INT\":\n return \"INT32\";\n case \"UNSIGNED_INT\":\n return \"UINT32\";\n case \"FLOAT\":\n return \"FLOAT32\";\n case \"DOUBLE\":\n return \"FLOAT64\";\n }\n}\n\n// exposed for testing\nparseBatchTable._deprecationWarning = deprecationWarning;\nparseBatchTable._oneTimeWarning = oneTimeWarning;\n\nexport default parseBatchTable;\n", "import Axis from \"../Axis.js\";\nimport B3dmParser from \"../B3dmParser.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Cesium3DTileFeatureTable from \"../Cesium3DTileFeatureTable.js\";\nimport Check from \"../../Core/Check.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport StructuralMetadata from \"../StructuralMetadata.js\";\nimport GltfLoader from \"../GltfLoader.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport MetadataClass from \"../MetadataClass.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport parseBatchTable from \"../parseBatchTable.js\";\nimport PropertyTable from \"../PropertyTable.js\";\nimport ResourceLoader from \"../ResourceLoader.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\nconst B3dmLoaderState = {\n UNLOADED: 0,\n LOADING: 1,\n PROCESSING: 2,\n READY: 3,\n FAILED: 4,\n};\n\nconst FeatureIdAttribute = ModelComponents.FeatureIdAttribute;\n\n/**\n * Loads a Batched 3D Model.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias B3dmLoader\n * @constructor\n * @augments ResourceLoader\n * @private\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.b3dmResource The {@link Resource} containing the b3dm.\n * @param {ArrayBuffer} options.arrayBuffer The array buffer of the b3dm contents.\n * @param {number} [options.byteOffset] The byte offset to the beginning of the b3dm contents in the array buffer.\n * @param {Resource} [options.baseResource] The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the glTF is loaded.\n * @param {Axis} [options.upAxis=Axis.Y] The up-axis of the glTF model.\n * @param {Axis} [options.forwardAxis=Axis.X] The forward-axis of the glTF model.\n * @param {boolean} [options.loadAttributesAsTypedArray=false] If true, load all attributes as typed arrays instead of GPU buffers. If the attributes are interleaved in the glTF they will be de-interleaved in the typed array.\n * @param {boolean} [options.loadAttributesFor2D=false] If true, load the positions buffer and any instanced attribute buffers as typed arrays for accurately projecting models to 2D.\n * @param {boolean} [options.loadIndicesForWireframe=false] If true, load the index buffer as a typed array. This is useful for creating wireframe indices in WebGL1.\n * @param {boolean} [options.loadPrimitiveOutline=true] If true, load outlines from the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time.\n * @param {boolean} [options.loadForClassification=false] If true and if the model has feature IDs, load the feature IDs and indices as typed arrays. This is useful for batching features for classification.\n * */\nfunction B3dmLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const b3dmResource = options.b3dmResource;\n let baseResource = options.baseResource;\n const arrayBuffer = options.arrayBuffer;\n const byteOffset = defaultValue(options.byteOffset, 0);\n const releaseGltfJson = defaultValue(options.releaseGltfJson, false);\n const asynchronous = defaultValue(options.asynchronous, true);\n const incrementallyLoadTextures = defaultValue(\n options.incrementallyLoadTextures,\n true\n );\n const upAxis = defaultValue(options.upAxis, Axis.Y);\n const forwardAxis = defaultValue(options.forwardAxis, Axis.X);\n const loadAttributesAsTypedArray = defaultValue(\n options.loadAttributesAsTypedArray,\n false\n );\n const loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false);\n const loadIndicesForWireframe = defaultValue(\n options.loadIndicesForWireframe,\n false\n );\n const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true);\n const loadForClassification = defaultValue(\n options.loadForClassification,\n false\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.b3dmResource\", b3dmResource);\n Check.typeOf.object(\"options.arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n baseResource = defined(baseResource) ? baseResource : b3dmResource.clone();\n\n this._b3dmResource = b3dmResource;\n this._baseResource = baseResource;\n this._arrayBuffer = arrayBuffer;\n this._byteOffset = byteOffset;\n this._releaseGltfJson = releaseGltfJson;\n this._asynchronous = asynchronous;\n this._incrementallyLoadTextures = incrementallyLoadTextures;\n this._upAxis = upAxis;\n this._forwardAxis = forwardAxis;\n this._loadAttributesAsTypedArray = loadAttributesAsTypedArray;\n this._loadAttributesFor2D = loadAttributesFor2D;\n this._loadIndicesForWireframe = loadIndicesForWireframe;\n this._loadPrimitiveOutline = loadPrimitiveOutline;\n this._loadForClassification = loadForClassification;\n\n this._state = B3dmLoaderState.UNLOADED;\n\n this._promise = undefined;\n\n this._gltfLoader = undefined;\n\n // Loaded results.\n this._batchLength = 0;\n this._propertyTable = undefined;\n\n // The batch table object contains a json and a binary component access using keys of the same name.\n this._batchTable = undefined;\n this._components = undefined;\n this._transform = Matrix4.IDENTITY;\n}\n\nif (defined(Object.create)) {\n B3dmLoader.prototype = Object.create(ResourceLoader.prototype);\n B3dmLoader.prototype.constructor = B3dmLoader;\n}\n\nObject.defineProperties(B3dmLoader.prototype, {\n /**\n * true if textures are loaded, useful when incrementallyLoadTextures is true\n *\n * @memberof B3dmLoader.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n texturesLoaded: {\n get: function () {\n return this._gltfLoader?.texturesLoaded;\n },\n },\n /**\n * The cache key of the resource\n *\n * @memberof B3dmLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * The loaded components.\n *\n * @memberof B3dmLoader.prototype\n *\n * @type {ModelComponents.Components}\n * @readonly\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nB3dmLoader.prototype.load = function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n const b3dm = B3dmParser.parse(this._arrayBuffer, this._byteOffset);\n\n let batchLength = b3dm.batchLength;\n const featureTableJson = b3dm.featureTableJson;\n const featureTableBinary = b3dm.featureTableBinary;\n const batchTableJson = b3dm.batchTableJson;\n const batchTableBinary = b3dm.batchTableBinary;\n\n const featureTable = new Cesium3DTileFeatureTable(\n featureTableJson,\n featureTableBinary\n );\n batchLength = featureTable.getGlobalProperty(\"BATCH_LENGTH\");\n // Set batch length.\n this._batchLength = batchLength;\n // Set the RTC Center transform, if present.\n const rtcCenter = featureTable.getGlobalProperty(\n \"RTC_CENTER\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (defined(rtcCenter)) {\n this._transform = Matrix4.fromTranslation(Cartesian3.fromArray(rtcCenter));\n }\n\n this._batchTable = {\n json: batchTableJson,\n binary: batchTableBinary,\n };\n\n const gltfLoader = new GltfLoader({\n typedArray: b3dm.gltf,\n upAxis: this._upAxis,\n forwardAxis: this._forwardAxis,\n gltfResource: this._b3dmResource,\n baseResource: this._baseResource,\n releaseGltfJson: this._releaseGltfJson,\n incrementallyLoadTextures: this._incrementallyLoadTextures,\n loadAttributesAsTypedArray: this._loadAttributesAsTypedArray,\n loadAttributesFor2D: this._loadAttributesFor2D,\n loadIndicesForWireframe: this._loadIndicesForWireframe,\n loadPrimitiveOutline: this._loadPrimitiveOutline,\n loadForClassification: this._loadForClassification,\n renameBatchIdSemantic: true,\n });\n\n this._gltfLoader = gltfLoader;\n this._state = B3dmLoaderState.LOADING;\n\n const that = this;\n this._promise = gltfLoader\n .load()\n .then(function () {\n if (that.isDestroyed()) {\n return;\n }\n\n that._state = B3dmLoaderState.PROCESSING;\n return that;\n })\n .catch(function (error) {\n if (that.isDestroyed()) {\n return;\n }\n\n return handleError(that, error);\n });\n\n return this._promise;\n};\n\nfunction handleError(b3dmLoader, error) {\n b3dmLoader.unload();\n b3dmLoader._state = B3dmLoaderState.FAILED;\n const errorMessage = \"Failed to load b3dm\";\n error = b3dmLoader.getError(errorMessage, error);\n return Promise.reject(error);\n}\n\nB3dmLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === B3dmLoaderState.READY) {\n return true;\n }\n\n if (this._state !== B3dmLoaderState.PROCESSING) {\n return false;\n }\n\n const ready = this._gltfLoader.process(frameState);\n if (!ready) {\n return false;\n }\n\n const components = this._gltfLoader.components;\n\n // Combine the RTC_CENTER transform from the b3dm and the CESIUM_RTC\n // transform from the glTF. In practice usually only one or the\n // other is supplied. If they don't exist the transforms will\n // be identity matrices.\n components.transform = Matrix4.multiplyTransformation(\n this._transform,\n components.transform,\n components.transform\n );\n createStructuralMetadata(this, components);\n this._components = components;\n\n // Now that we have the parsed components, we can release the array buffer\n this._arrayBuffer = undefined;\n\n this._state = B3dmLoaderState.READY;\n return true;\n};\n\nfunction createStructuralMetadata(loader, components) {\n const batchTable = loader._batchTable;\n const batchLength = loader._batchLength;\n\n if (batchLength === 0) {\n return;\n }\n\n let structuralMetadata;\n if (defined(batchTable.json)) {\n // Add the structural metadata from the batch table to the model components.\n structuralMetadata = parseBatchTable({\n count: batchLength,\n batchTable: batchTable.json,\n binaryBody: batchTable.binary,\n });\n } else {\n // If batch table is not defined, create a property table without any properties.\n const emptyPropertyTable = new PropertyTable({\n name: MetadataClass.BATCH_TABLE_CLASS_NAME,\n count: batchLength,\n });\n structuralMetadata = new StructuralMetadata({\n schema: {},\n propertyTables: [emptyPropertyTable],\n });\n }\n\n // Add the feature ID attribute to the primitives.\n const nodes = components.scene.nodes;\n const length = nodes.length;\n for (let i = 0; i < length; i++) {\n processNode(nodes[i]);\n }\n components.structuralMetadata = structuralMetadata;\n}\n\n// Recursive function to add the feature ID attribute to all primitives that have a feature ID vertex attribute.\nfunction processNode(node) {\n const childrenLength = node.children.length;\n for (let i = 0; i < childrenLength; i++) {\n processNode(node.children[i]);\n }\n\n const primitivesLength = node.primitives.length;\n for (let i = 0; i < primitivesLength; i++) {\n const primitive = node.primitives[i];\n const featureIdVertexAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.FEATURE_ID\n );\n if (defined(featureIdVertexAttribute)) {\n featureIdVertexAttribute.setIndex = 0;\n const featureIdAttribute = new FeatureIdAttribute();\n featureIdAttribute.propertyTableId = 0;\n featureIdAttribute.setIndex = 0;\n featureIdAttribute.positionalLabel = \"featureId_0\";\n primitive.featureIds.push(featureIdAttribute);\n }\n }\n}\n\nB3dmLoader.prototype.unload = function () {\n if (defined(this._gltfLoader) && !this._gltfLoader.isDestroyed()) {\n this._gltfLoader.unload();\n }\n\n this._components = undefined;\n this._arrayBuffer = undefined;\n};\n\nexport default B3dmLoader;\n", "import Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Ellipsoid from \"../../Core/Ellipsoid.js\";\nimport IndexDatatype from \"../../Core/IndexDatatype.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport Transforms from \"../../Core/Transforms.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport JsonMetadataTable from \"../JsonMetadataTable.js\";\nimport MetadataSchema from \"../MetadataSchema.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport PropertyTable from \"../PropertyTable.js\";\nimport ResourceLoader from \"../ResourceLoader.js\";\nimport StructuralMetadata from \"../StructuralMetadata.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\n\n/**\n * Loads a GeoJson model as part of the MAXAR_content_geojson extension with the following constraints:\n *
    \n *
  • The top level GeoJSON type must be FeatureCollection or Feature.
  • \n *
  • The geometry types must be LineString, MultiLineString, MultiPolygon, Polygon, MultiPoint, or Point.
  • \n *
  • Polygon and polyline geometries are converted to geodesic lines.
  • \n *
  • Only WGS84 geographic coordinates are supported.
  • \n *
\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias GeoJsonLoader\n * @constructor\n * @augments ResourceLoader\n * @private\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.geoJson The GeoJson object.\n */\nfunction GeoJsonLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.geoJson\", options.geoJson);\n //>>includeEnd('debug');\n\n this._geoJson = options.geoJson;\n this._components = undefined;\n}\n\nif (defined(Object.create)) {\n GeoJsonLoader.prototype = Object.create(ResourceLoader.prototype);\n GeoJsonLoader.prototype.constructor = GeoJsonLoader;\n}\n\nObject.defineProperties(GeoJsonLoader.prototype, {\n /**\n * The cache key of the resource.\n *\n * @memberof GeoJsonLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return undefined;\n },\n },\n /**\n * The loaded components.\n *\n * @memberof GeoJsonLoader.prototype\n *\n * @type {ModelComponents.Components}\n * @readonly\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nGeoJsonLoader.prototype.load = function () {\n return Promise.resolve(this);\n};\n\n/**\n * Processes the resource until it becomes ready.\n *\n * @param {FrameState} frameState The frame state.\n * @private\n */\nGeoJsonLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (defined(this._components)) {\n return true;\n }\n\n this._components = parse(this._geoJson, frameState);\n this._geoJson = undefined;\n return true;\n};\n\nfunction ParsedFeature() {\n this.lines = undefined;\n this.points = undefined;\n this.properties = undefined;\n}\n\nfunction ParseResult() {\n this.features = [];\n}\n\nfunction parsePosition(position) {\n const x = position[0];\n const y = position[1];\n const z = defaultValue(position[2], 0.0);\n return new Cartesian3(x, y, z);\n}\n\nfunction parseLineString(coordinates) {\n const positionsLength = coordinates.length;\n const line = new Array(positionsLength);\n for (let i = 0; i < positionsLength; i++) {\n line[i] = parsePosition(coordinates[i]);\n }\n const lines = [line];\n return lines;\n}\n\nfunction parseMultiLineString(coordinates) {\n const linesLength = coordinates.length;\n const lines = new Array(linesLength);\n for (let i = 0; i < linesLength; i++) {\n lines[i] = parseLineString(coordinates[i])[0];\n }\n return lines;\n}\n\nfunction parsePolygon(coordinates) {\n // Treat exterior polygon and interior polygons as lines\n const linesLength = coordinates.length;\n const lines = new Array(linesLength);\n for (let i = 0; i < linesLength; i++) {\n lines[i] = parseLineString(coordinates[i])[0];\n }\n return lines;\n}\n\nfunction parseMultiPolygon(coordinates) {\n const polygonsLength = coordinates.length;\n const lines = [];\n for (let i = 0; i < polygonsLength; i++) {\n Array.prototype.push.apply(lines, parsePolygon(coordinates[i]));\n }\n return lines;\n}\n\nfunction parsePoint(coordinates) {\n return [parsePosition(coordinates)];\n}\n\nfunction parseMultiPoint(coordinates) {\n const pointsLength = coordinates.length;\n const points = new Array(pointsLength);\n for (let i = 0; i < pointsLength; i++) {\n points[i] = parsePosition(coordinates[i]);\n }\n return points;\n}\n\nconst geometryTypes = {\n LineString: parseLineString,\n MultiLineString: parseMultiLineString,\n MultiPolygon: parseMultiPolygon,\n Polygon: parsePolygon,\n MultiPoint: parseMultiPoint,\n Point: parsePoint,\n};\n\nconst primitiveTypes = {\n LineString: PrimitiveType.LINES,\n MultiLineString: PrimitiveType.LINES,\n MultiPolygon: PrimitiveType.LINES,\n Polygon: PrimitiveType.LINES,\n MultiPoint: PrimitiveType.POINTS,\n Point: PrimitiveType.POINTS,\n};\n\nfunction parseFeature(feature, result) {\n if (!defined(feature.geometry)) {\n return;\n }\n\n const geometryType = feature.geometry.type;\n const geometryFunction = geometryTypes[geometryType];\n const primitiveType = primitiveTypes[geometryType];\n const coordinates = feature.geometry.coordinates;\n\n if (!defined(geometryFunction)) {\n return;\n }\n\n if (!defined(coordinates)) {\n return;\n }\n\n const parsedFeature = new ParsedFeature();\n\n if (primitiveType === PrimitiveType.LINES) {\n parsedFeature.lines = geometryFunction(coordinates);\n } else if (primitiveType === PrimitiveType.POINTS) {\n parsedFeature.points = geometryFunction(coordinates);\n }\n\n parsedFeature.properties = feature.properties;\n\n result.features.push(parsedFeature);\n}\n\nfunction parseFeatureCollection(featureCollection, result) {\n const features = featureCollection.features;\n const featuresLength = features.length;\n for (let i = 0; i < featuresLength; i++) {\n parseFeature(features[i], result);\n }\n}\n\nconst geoJsonObjectTypes = {\n FeatureCollection: parseFeatureCollection,\n Feature: parseFeature,\n};\n\nconst scratchCartesian = new Cartesian3();\n\nfunction createLinesPrimitive(features, toLocal, frameState) {\n // Count the number of vertices and indices\n let vertexCount = 0;\n let indexCount = 0;\n\n const featureCount = features.length;\n\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n if (defined(feature.lines)) {\n const linesLength = feature.lines.length;\n for (let j = 0; j < linesLength; j++) {\n const line = feature.lines[j];\n vertexCount += line.length;\n indexCount += (line.length - 1) * 2;\n }\n }\n }\n\n // Allocate typed arrays\n const positionsTypedArray = new Float32Array(vertexCount * 3);\n const featureIdsTypedArray = new Float32Array(vertexCount);\n const indicesTypedArray = IndexDatatype.createTypedArray(\n vertexCount,\n indexCount\n );\n const indexDatatype = IndexDatatype.fromTypedArray(indicesTypedArray);\n\n // Process the data. Convert positions to local ENU. Generate indices.\n const localMin = new Cartesian3(\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY\n );\n\n const localMax = new Cartesian3(\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY\n );\n\n let vertexCounter = 0;\n let segmentCounter = 0;\n\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n\n if (!defined(feature.lines)) {\n continue;\n }\n\n const linesLength = feature.lines.length;\n for (let j = 0; j < linesLength; j++) {\n const line = feature.lines[j];\n const positionsLength = line.length;\n for (let k = 0; k < positionsLength; k++) {\n const cartographic = line[k];\n const globalCartesian = Cartesian3.fromDegrees(\n cartographic.x,\n cartographic.y,\n cartographic.z,\n Ellipsoid.WGS84,\n scratchCartesian\n );\n const localCartesian = Matrix4.multiplyByPoint(\n toLocal,\n globalCartesian,\n scratchCartesian\n );\n\n Cartesian3.minimumByComponent(localMin, localCartesian, localMin);\n Cartesian3.maximumByComponent(localMax, localCartesian, localMax);\n\n Cartesian3.pack(localCartesian, positionsTypedArray, vertexCounter * 3);\n\n featureIdsTypedArray[vertexCounter] = i;\n\n if (k < positionsLength - 1) {\n indicesTypedArray[segmentCounter * 2] = vertexCounter;\n indicesTypedArray[segmentCounter * 2 + 1] = vertexCounter + 1;\n segmentCounter++;\n }\n\n vertexCounter++;\n }\n }\n }\n\n // Create GPU buffers\n const positionBuffer = Buffer.createVertexBuffer({\n typedArray: positionsTypedArray,\n context: frameState.context,\n usage: BufferUsage.STATIC_DRAW,\n });\n positionBuffer.vertexArrayDestroyable = false;\n\n const featureIdBuffer = Buffer.createVertexBuffer({\n typedArray: featureIdsTypedArray,\n context: frameState.context,\n usage: BufferUsage.STATIC_DRAW,\n });\n featureIdBuffer.vertexArrayDestroyable = false;\n\n const indexBuffer = Buffer.createIndexBuffer({\n typedArray: indicesTypedArray,\n context: frameState.context,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: indexDatatype,\n });\n indexBuffer.vertexArrayDestroyable = false;\n\n // Create ModelComponents\n const positionAttribute = new ModelComponents.Attribute();\n positionAttribute.semantic = VertexAttributeSemantic.POSITION;\n positionAttribute.componentDatatype = ComponentDatatype.FLOAT;\n positionAttribute.type = AttributeType.VEC3;\n positionAttribute.count = vertexCount;\n positionAttribute.min = localMin;\n positionAttribute.max = localMax;\n positionAttribute.buffer = positionBuffer;\n\n const featureIdAttribute = new ModelComponents.Attribute();\n featureIdAttribute.semantic = VertexAttributeSemantic.FEATURE_ID;\n featureIdAttribute.setIndex = 0;\n featureIdAttribute.componentDatatype = ComponentDatatype.FLOAT;\n featureIdAttribute.type = AttributeType.SCALAR;\n featureIdAttribute.count = vertexCount;\n featureIdAttribute.buffer = featureIdBuffer;\n\n const attributes = [positionAttribute, featureIdAttribute];\n\n const material = new ModelComponents.Material();\n material.unlit = true;\n\n const indices = new ModelComponents.Indices();\n indices.indexDatatype = indexDatatype;\n indices.count = indicesTypedArray.length;\n indices.buffer = indexBuffer;\n\n const featureId = new ModelComponents.FeatureIdAttribute();\n featureId.featureCount = featureCount;\n featureId.propertyTableId = 0;\n featureId.setIndex = 0;\n featureId.positionalLabel = \"featureId_0\";\n\n const featureIds = [featureId];\n\n const primitive = new ModelComponents.Primitive();\n primitive.attributes = attributes;\n primitive.indices = indices;\n primitive.featureIds = featureIds;\n primitive.primitiveType = PrimitiveType.LINES;\n primitive.material = material;\n\n return primitive;\n}\n\nfunction createPointsPrimitive(features, toLocal, frameState) {\n // Count the number of vertices\n let vertexCount = 0;\n\n const featureCount = features.length;\n\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n if (defined(feature.points)) {\n vertexCount += feature.points.length;\n }\n }\n\n // Allocate typed arrays\n const positionsTypedArray = new Float32Array(vertexCount * 3);\n const featureIdsTypedArray = new Float32Array(vertexCount);\n\n // Process the data. Convert positions to local ENU.\n const localMin = new Cartesian3(\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY\n );\n\n const localMax = new Cartesian3(\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY\n );\n\n let vertexCounter = 0;\n\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n\n if (!defined(feature.points)) {\n continue;\n }\n\n const pointsLength = feature.points.length;\n for (let j = 0; j < pointsLength; j++) {\n const cartographic = feature.points[j];\n const globalCartesian = Cartesian3.fromDegrees(\n cartographic.x,\n cartographic.y,\n cartographic.z,\n Ellipsoid.WGS84,\n scratchCartesian\n );\n const localCartesian = Matrix4.multiplyByPoint(\n toLocal,\n globalCartesian,\n scratchCartesian\n );\n\n Cartesian3.minimumByComponent(localMin, localCartesian, localMin);\n Cartesian3.maximumByComponent(localMax, localCartesian, localMax);\n\n Cartesian3.pack(localCartesian, positionsTypedArray, vertexCounter * 3);\n\n featureIdsTypedArray[vertexCounter] = i;\n\n vertexCounter++;\n }\n }\n\n // Create GPU buffers\n const positionBuffer = Buffer.createVertexBuffer({\n typedArray: positionsTypedArray,\n context: frameState.context,\n usage: BufferUsage.STATIC_DRAW,\n });\n positionBuffer.vertexArrayDestroyable = false;\n\n const featureIdBuffer = Buffer.createVertexBuffer({\n typedArray: featureIdsTypedArray,\n context: frameState.context,\n usage: BufferUsage.STATIC_DRAW,\n });\n featureIdBuffer.vertexArrayDestroyable = false;\n\n // Create ModelComponents\n const positionAttribute = new ModelComponents.Attribute();\n positionAttribute.semantic = VertexAttributeSemantic.POSITION;\n positionAttribute.componentDatatype = ComponentDatatype.FLOAT;\n positionAttribute.type = AttributeType.VEC3;\n positionAttribute.count = vertexCount;\n positionAttribute.min = localMin;\n positionAttribute.max = localMax;\n positionAttribute.buffer = positionBuffer;\n\n const featureIdAttribute = new ModelComponents.Attribute();\n featureIdAttribute.semantic = VertexAttributeSemantic.FEATURE_ID;\n featureIdAttribute.setIndex = 0;\n featureIdAttribute.componentDatatype = ComponentDatatype.FLOAT;\n featureIdAttribute.type = AttributeType.SCALAR;\n featureIdAttribute.count = vertexCount;\n featureIdAttribute.buffer = featureIdBuffer;\n\n const attributes = [positionAttribute, featureIdAttribute];\n\n const material = new ModelComponents.Material();\n material.unlit = true;\n\n const featureId = new ModelComponents.FeatureIdAttribute();\n featureId.featureCount = featureCount;\n featureId.propertyTableId = 0;\n featureId.setIndex = 0;\n featureId.positionalLabel = \"featureId_0\";\n\n const featureIds = [featureId];\n\n const primitive = new ModelComponents.Primitive();\n primitive.attributes = attributes;\n primitive.featureIds = featureIds;\n primitive.primitiveType = PrimitiveType.POINTS;\n primitive.material = material;\n\n return primitive;\n}\n\nfunction parse(geoJson, frameState) {\n const result = new ParseResult();\n\n // Parse the GeoJSON\n const parseFunction = geoJsonObjectTypes[geoJson.type];\n if (defined(parseFunction)) {\n parseFunction(geoJson, result);\n }\n\n const features = result.features;\n const featureCount = features.length;\n\n if (featureCount === 0) {\n throw new RuntimeError(\"GeoJSON must have at least one feature\");\n }\n\n // Allocate space for property values\n const properties = {};\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n const featureProperties = defaultValue(\n feature.properties,\n defaultValue.EMPTY_OBJECT\n );\n for (const propertyId in featureProperties) {\n if (featureProperties.hasOwnProperty(propertyId)) {\n if (!defined(properties[propertyId])) {\n properties[propertyId] = new Array(featureCount);\n }\n }\n }\n }\n\n // Fill in the property values. Default to empty string for undefined values.\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const value = defaultValue(feature.properties[propertyId], \"\");\n properties[propertyId][i] = value;\n }\n }\n }\n\n const jsonMetadataTable = new JsonMetadataTable({\n count: featureCount,\n properties: properties,\n });\n\n const propertyTable = new PropertyTable({\n id: 0,\n count: featureCount,\n jsonMetadataTable: jsonMetadataTable,\n });\n const propertyTables = [propertyTable];\n\n const schema = MetadataSchema.fromJson({});\n\n const structuralMetadata = new StructuralMetadata({\n schema: schema,\n propertyTables: propertyTables,\n });\n\n // Find the cartographic bounding box\n const cartographicMin = new Cartesian3(\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY\n );\n\n const cartographicMax = new Cartesian3(\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY\n );\n\n let hasLines = false;\n let hasPoints = false;\n\n for (let i = 0; i < featureCount; i++) {\n const feature = features[i];\n if (defined(feature.lines)) {\n hasLines = true;\n const linesLength = feature.lines.length;\n for (let j = 0; j < linesLength; j++) {\n const line = feature.lines[j];\n const positionsLength = line.length;\n for (let k = 0; k < positionsLength; k++) {\n Cartesian3.minimumByComponent(\n cartographicMin,\n line[k],\n cartographicMin\n );\n Cartesian3.maximumByComponent(\n cartographicMax,\n line[k],\n cartographicMax\n );\n }\n }\n }\n\n if (defined(feature.points)) {\n hasPoints = true;\n const pointsLength = feature.points.length;\n for (let j = 0; j < pointsLength; j++) {\n const point = feature.points[j];\n Cartesian3.minimumByComponent(cartographicMin, point, cartographicMin);\n Cartesian3.maximumByComponent(cartographicMax, point, cartographicMax);\n }\n }\n }\n\n // Compute the ENU matrix\n const cartographicCenter = Cartesian3.midpoint(\n cartographicMin,\n cartographicMax,\n new Cartesian3()\n );\n const ecefCenter = Cartesian3.fromDegrees(\n cartographicCenter.x,\n cartographicCenter.y,\n cartographicCenter.z,\n Ellipsoid.WGS84,\n new Cartesian3()\n );\n const toGlobal = Transforms.eastNorthUpToFixedFrame(\n ecefCenter,\n Ellipsoid.WGS84,\n new Matrix4()\n );\n const toLocal = Matrix4.inverseTransformation(toGlobal, new Matrix4());\n\n const primitives = [];\n\n if (hasLines) {\n primitives.push(createLinesPrimitive(features, toLocal, frameState));\n }\n\n if (hasPoints) {\n primitives.push(createPointsPrimitive(features, toLocal, frameState));\n }\n\n const node = new ModelComponents.Node();\n node.index = 0;\n node.primitives = primitives;\n\n const nodes = [node];\n\n const scene = new ModelComponents.Scene();\n scene.nodes = nodes;\n\n const components = new ModelComponents.Components();\n components.scene = scene;\n components.nodes = nodes;\n components.transform = toGlobal;\n components.structuralMetadata = structuralMetadata;\n\n return components;\n}\n\n/**\n * Unloads the resource.\n * @private\n */\nGeoJsonLoader.prototype.unload = function () {\n this._components = undefined;\n};\n\nexport default GeoJsonLoader;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * Handles parsing of an Instanced 3D Model.\n *\n * @namespace I3dmParser\n * @private\n */\nconst I3dmParser = {};\nI3dmParser._deprecationWarning = deprecationWarning;\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\n/**\n * Parses the contents of a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Instanced3DModel|Instanced 3D Model}.\n *\n * @private\n *\n * @param {ArrayBuffer} arrayBuffer The array buffer containing the i3dm.\n * @param {number} [byteOffset=0] The byte offset of the beginning of the i3dm in the array buffer.\n * @returns {object} Returns an object with the glTF format, feature table (binary and json), batch table (binary and json) and glTF parts of the i3dm.\n */\nI3dmParser.parse = function (arrayBuffer, byteOffset) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n const byteStart = defaultValue(byteOffset, 0);\n byteOffset = byteStart;\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Instanced 3D Model version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n const byteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const featureTableJsonByteLength = view.getUint32(byteOffset, true);\n if (featureTableJsonByteLength === 0) {\n throw new RuntimeError(\n \"featureTableJsonByteLength is zero, the feature table must be defined.\"\n );\n }\n byteOffset += sizeOfUint32;\n\n const featureTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const batchTableJsonByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const batchTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const gltfFormat = view.getUint32(byteOffset, true);\n if (gltfFormat !== 1 && gltfFormat !== 0) {\n throw new RuntimeError(\n `Only glTF format 0 (uri) or 1 (embedded) are supported. Format ${gltfFormat} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n const featureTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n featureTableJsonByteLength\n );\n byteOffset += featureTableJsonByteLength;\n\n const featureTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n featureTableBinaryByteLength\n );\n byteOffset += featureTableBinaryByteLength;\n\n let batchTableJson;\n let batchTableBinary;\n if (batchTableJsonByteLength > 0) {\n batchTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n batchTableJsonByteLength\n );\n byteOffset += batchTableJsonByteLength;\n\n if (batchTableBinaryByteLength > 0) {\n // Has a batch table binary\n batchTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n batchTableBinaryByteLength\n );\n // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed\n batchTableBinary = new Uint8Array(batchTableBinary);\n byteOffset += batchTableBinaryByteLength;\n }\n }\n\n const gltfByteLength = byteStart + byteLength - byteOffset;\n if (gltfByteLength === 0) {\n throw new RuntimeError(\"glTF byte length must be greater than 0.\");\n }\n\n let gltfView;\n if (byteOffset % 4 === 0) {\n gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength);\n } else {\n // Create a copy of the glb so that it is 4-byte aligned\n I3dmParser._deprecationWarning(\n \"i3dm-glb-unaligned\",\n \"The embedded glb is not aligned to a 4-byte boundary.\"\n );\n gltfView = new Uint8Array(\n uint8Array.subarray(byteOffset, byteOffset + gltfByteLength)\n );\n }\n\n return {\n gltfFormat: gltfFormat,\n featureTableJson: featureTableJson,\n featureTableBinary: featureTableBinary,\n batchTableJson: batchTableJson,\n batchTableBinary: batchTableBinary,\n gltf: gltfView,\n };\n};\n\nexport default I3dmParser;\n", "import AttributeCompression from \"../../Core/AttributeCompression.js\";\nimport BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport clone from \"../../Core/clone.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Ellipsoid from \"../../Core/Ellipsoid.js\";\nimport getStringFromTypedArray from \"../../Core/getStringFromTypedArray.js\";\nimport Matrix3 from \"../../Core/Matrix3.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport Transforms from \"../../Core/Transforms.js\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport Axis from \"../Axis.js\";\nimport Cesium3DTileFeatureTable from \"../Cesium3DTileFeatureTable.js\";\nimport GltfLoader from \"../GltfLoader.js\";\nimport InstanceAttributeSemantic from \"../InstanceAttributeSemantic.js\";\nimport I3dmParser from \"../I3dmParser.js\";\nimport MetadataClass from \"../MetadataClass.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport parseBatchTable from \"../parseBatchTable.js\";\nimport PropertyTable from \"../PropertyTable.js\";\nimport ResourceLoader from \"../ResourceLoader.js\";\nimport StructuralMetadata from \"../StructuralMetadata.js\";\n\nconst I3dmLoaderState = {\n NOT_LOADED: 0,\n LOADING: 1,\n PROCESSING: 2,\n POST_PROCESSING: 3,\n READY: 4,\n FAILED: 5,\n UNLOADED: 6,\n};\n\nconst Attribute = ModelComponents.Attribute;\nconst FeatureIdAttribute = ModelComponents.FeatureIdAttribute;\nconst Instances = ModelComponents.Instances;\n\n/**\n * Loads an Instanced 3D Model.\n *

\n * Implements the {@link ResourceLoader} interface.\n *

\n *\n * @alias I3dmLoader\n * @constructor\n * @augments ResourceLoader\n * @private\n *\n * @param {object} options Object with the following properties:\n * @param {Resource} options.i3dmResource The {@link Resource} containing the i3dm.\n * @param {ArrayBuffer} options.arrayBuffer The array buffer of the i3dm contents.\n * @param {number} [options.byteOffset=0] The byte offset to the beginning of the i3dm contents in the array buffer.\n * @param {Resource} [options.baseResource] The {@link Resource} that paths in the glTF JSON are relative to.\n * @param {boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.\n * @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.\n * @param {boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the glTF is loaded.\n * @param {Axis} [options.upAxis=Axis.Y] The up-axis of the glTF model.\n * @param {Axis} [options.forwardAxis=Axis.X] The forward-axis of the glTF model.\n * @param {boolean} [options.loadAttributesAsTypedArray=false] Load all attributes as typed arrays instead of GPU buffers. If the attributes are interleaved in the glTF they will be de-interleaved in the typed array.\n * @param {boolean} [options.loadIndicesForWireframe=false] Load the index buffer as a typed array so wireframe indices can be created for WebGL1.\n * @param {boolean} [options.loadPrimitiveOutline=true] If true, load outlines from the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time.\n */\nfunction I3dmLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const i3dmResource = options.i3dmResource;\n const arrayBuffer = options.arrayBuffer;\n let baseResource = options.baseResource;\n const byteOffset = defaultValue(options.byteOffset, 0);\n const releaseGltfJson = defaultValue(options.releaseGltfJson, false);\n const asynchronous = defaultValue(options.asynchronous, true);\n const incrementallyLoadTextures = defaultValue(\n options.incrementallyLoadTextures,\n true\n );\n const upAxis = defaultValue(options.upAxis, Axis.Y);\n const forwardAxis = defaultValue(options.forwardAxis, Axis.X);\n const loadAttributesAsTypedArray = defaultValue(\n options.loadAttributesAsTypedArray,\n false\n );\n const loadIndicesForWireframe = defaultValue(\n options.loadIndicesForWireframe,\n false\n );\n const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.i3dmResource\", i3dmResource);\n Check.typeOf.object(\"options.arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n baseResource = defined(baseResource) ? baseResource : i3dmResource.clone();\n\n this._i3dmResource = i3dmResource;\n this._baseResource = baseResource;\n this._arrayBuffer = arrayBuffer;\n this._byteOffset = byteOffset;\n this._releaseGltfJson = releaseGltfJson;\n this._asynchronous = asynchronous;\n this._incrementallyLoadTextures = incrementallyLoadTextures;\n this._upAxis = upAxis;\n this._forwardAxis = forwardAxis;\n this._loadAttributesAsTypedArray = loadAttributesAsTypedArray;\n this._loadIndicesForWireframe = loadIndicesForWireframe;\n this._loadPrimitiveOutline = loadPrimitiveOutline;\n\n this._state = I3dmLoaderState.NOT_LOADED;\n this._promise = undefined;\n\n this._gltfLoader = undefined;\n\n // Instanced attributes are initially parsed as typed arrays, but if they\n // do not need to be further processed (e.g. turned into transform matrices),\n // it is more efficient to turn them into buffers. The I3dmLoader will own the\n // resources and store them here.\n this._buffers = [];\n this._components = undefined;\n\n this._transform = Matrix4.IDENTITY;\n this._batchTable = undefined;\n this._featureTable = undefined;\n this._instancesLength = 0;\n}\n\nif (defined(Object.create)) {\n I3dmLoader.prototype = Object.create(ResourceLoader.prototype);\n I3dmLoader.prototype.constructor = I3dmLoader;\n}\n\nObject.defineProperties(I3dmLoader.prototype, {\n /**\n * true if textures are loaded, useful when incrementallyLoadTextures is true\n *\n * @memberof I3dmLoader.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n texturesLoaded: {\n get: function () {\n return this._gltfLoader?.texturesLoaded;\n },\n },\n /**\n * The cache key of the resource\n *\n * @memberof I3dmLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * The loaded components.\n *\n * @memberof I3dmLoader.prototype\n *\n * @type {ModelComponents.Components}\n * @default {@link Matrix4.IDENTITY}\n * @readonly\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nI3dmLoader.prototype.load = function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n // Parse the i3dm into its various sections.\n const i3dm = I3dmParser.parse(this._arrayBuffer, this._byteOffset);\n\n const featureTableJson = i3dm.featureTableJson;\n const featureTableBinary = i3dm.featureTableBinary;\n const batchTableJson = i3dm.batchTableJson;\n const batchTableBinary = i3dm.batchTableBinary;\n const gltfFormat = i3dm.gltfFormat;\n\n // Generate the feature table.\n const featureTable = new Cesium3DTileFeatureTable(\n featureTableJson,\n featureTableBinary\n );\n this._featureTable = featureTable;\n\n // Get the number of instances in the i3dm.\n const instancesLength = featureTable.getGlobalProperty(\"INSTANCES_LENGTH\");\n featureTable.featuresLength = instancesLength;\n if (!defined(instancesLength)) {\n throw new RuntimeError(\n \"Feature table global property: INSTANCES_LENGTH must be defined\"\n );\n }\n this._instancesLength = instancesLength;\n\n // Get the RTC center, if available, and set the loader's transform.\n const rtcCenter = featureTable.getGlobalProperty(\n \"RTC_CENTER\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (defined(rtcCenter)) {\n this._transform = Matrix4.fromTranslation(Cartesian3.fromArray(rtcCenter));\n }\n\n // Save the batch table section to use for StructuralMetadata generation.\n this._batchTable = {\n json: batchTableJson,\n binary: batchTableBinary,\n };\n\n const loaderOptions = {\n upAxis: this._upAxis,\n forwardAxis: this._forwardAxis,\n releaseGltfJson: this._releaseGltfJson,\n incrementallyLoadTextures: this._incrementallyLoadTextures,\n loadAttributesAsTypedArray: this._loadAttributesAsTypedArray,\n loadIndicesForWireframe: this._loadIndicesForWireframe,\n loadPrimitiveOutline: this._loadPrimitiveOutline,\n };\n\n if (gltfFormat === 0) {\n let gltfUrl = getStringFromTypedArray(i3dm.gltf);\n\n // We need to remove padding from the end of the model URL in case this tile was part of a composite tile.\n // This removes all white space and null characters from the end of the string.\n gltfUrl = gltfUrl.replace(/[\\s\\0]+$/, \"\");\n const gltfResource = this._baseResource.getDerivedResource({\n url: gltfUrl,\n });\n loaderOptions.gltfResource = gltfResource;\n loaderOptions.baseResource = gltfResource;\n } else {\n loaderOptions.gltfResource = this._i3dmResource;\n loaderOptions.typedArray = i3dm.gltf;\n }\n\n // Create the GltfLoader, update the state and load the glTF.\n const gltfLoader = new GltfLoader(loaderOptions);\n\n this._gltfLoader = gltfLoader;\n this._state = I3dmLoaderState.LOADING;\n\n this._promise = gltfLoader\n .load()\n .then(() => {\n if (this.isDestroyed()) {\n return;\n }\n\n this._state = I3dmLoaderState.PROCESSING;\n return this;\n })\n .catch((error) => {\n if (this.isDestroyed()) {\n return;\n }\n throw handleError(this, error);\n });\n\n return this._promise;\n};\n\nfunction handleError(i3dmLoader, error) {\n i3dmLoader.unload();\n i3dmLoader._state = I3dmLoaderState.FAILED;\n const errorMessage = \"Failed to load i3dm\";\n return i3dmLoader.getError(errorMessage, error);\n}\n\nI3dmLoader.prototype.process = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n if (this._state === I3dmLoaderState.READY) {\n return true;\n }\n\n const gltfLoader = this._gltfLoader;\n let ready = false;\n if (this._state === I3dmLoaderState.PROCESSING) {\n ready = gltfLoader.process(frameState);\n }\n\n if (!ready) {\n return false;\n }\n\n const components = gltfLoader.components;\n\n // Combine the RTC_CENTER transform from the i3dm and the CESIUM_RTC\n // transform from the glTF. In practice CESIUM_RTC is not set for\n // instanced models but multiply the transforms just in case.\n components.transform = Matrix4.multiplyTransformation(\n this._transform,\n components.transform,\n components.transform\n );\n\n createInstances(this, components, frameState);\n createStructuralMetadata(this, components);\n this._components = components;\n\n // Now that we have the parsed components, we can release the array buffer\n this._arrayBuffer = undefined;\n\n this._state = I3dmLoaderState.READY;\n return true;\n};\n\nfunction createStructuralMetadata(loader, components) {\n const batchTable = loader._batchTable;\n const instancesLength = loader._instancesLength;\n\n if (instancesLength === 0) {\n return;\n }\n\n let structuralMetadata;\n if (defined(batchTable.json)) {\n // Add the structural metadata from the batch table to the model components.\n structuralMetadata = parseBatchTable({\n count: instancesLength,\n batchTable: batchTable.json,\n binaryBody: batchTable.binary,\n });\n } else {\n // If batch table is not defined, create a property table without any properties.\n const emptyPropertyTable = new PropertyTable({\n name: MetadataClass.BATCH_TABLE_CLASS_NAME,\n count: instancesLength,\n });\n structuralMetadata = new StructuralMetadata({\n schema: {},\n propertyTables: [emptyPropertyTable],\n });\n }\n\n components.structuralMetadata = structuralMetadata;\n}\n\nconst positionScratch = new Cartesian3();\nconst propertyScratch1 = new Array(4);\nconst transformScratch = new Matrix4();\n\nfunction createInstances(loader, components, frameState) {\n let i;\n const featureTable = loader._featureTable;\n const instancesLength = loader._instancesLength;\n\n if (instancesLength === 0) {\n return;\n }\n\n const rtcCenter = featureTable.getGlobalProperty(\n \"RTC_CENTER\",\n ComponentDatatype.FLOAT,\n 3\n );\n\n const eastNorthUp = featureTable.getGlobalProperty(\"EAST_NORTH_UP\");\n const hasRotation =\n featureTable.hasProperty(\"NORMAL_UP\") ||\n featureTable.hasProperty(\"NORMAL_UP_OCT32P\") ||\n eastNorthUp;\n\n const hasScale =\n featureTable.hasProperty(\"SCALE\") ||\n featureTable.hasProperty(\"SCALE_NON_UNIFORM\");\n\n const translationTypedArray = getPositions(featureTable, instancesLength);\n let rotationTypedArray;\n if (hasRotation) {\n rotationTypedArray = new Float32Array(4 * instancesLength);\n }\n let scaleTypedArray;\n if (hasScale) {\n scaleTypedArray = new Float32Array(3 * instancesLength);\n }\n const featureIdArray = new Float32Array(instancesLength);\n\n const instancePositions = Cartesian3.unpackArray(translationTypedArray);\n let instancePosition = new Cartesian3();\n\n const instanceNormalRight = new Cartesian3();\n const instanceNormalUp = new Cartesian3();\n const instanceNormalForward = new Cartesian3();\n const instanceRotation = new Matrix3();\n const instanceQuaternion = new Quaternion();\n const instanceQuaternionArray = new Array(4);\n\n const instanceScale = new Cartesian3();\n const instanceScaleArray = new Array(3);\n\n const instanceTransform = new Matrix4();\n\n // For I3DMs that do not define an RTC center, we manually compute a BoundingSphere and store\n // positions relative to the center, to be uploaded to the GPU. This avoids jittering at higher\n // precisions.\n if (!defined(rtcCenter)) {\n const positionBoundingSphere = BoundingSphere.fromPoints(instancePositions);\n\n for (i = 0; i < instancePositions.length; i++) {\n Cartesian3.subtract(\n instancePositions[i],\n positionBoundingSphere.center,\n positionScratch\n );\n\n translationTypedArray[3 * i + 0] = positionScratch.x;\n translationTypedArray[3 * i + 1] = positionScratch.y;\n translationTypedArray[3 * i + 2] = positionScratch.z;\n }\n\n // Set the center of the bounding sphere as the RTC center transform.\n const centerTransform = Matrix4.fromTranslation(\n positionBoundingSphere.center,\n transformScratch\n );\n\n // Combine the center transform and the CESIUM_RTC transform from the glTF.\n // In practice CESIUM_RTC is not set for instanced models but multiply the\n // transforms just in case.\n components.transform = Matrix4.multiplyTransformation(\n centerTransform,\n components.transform,\n components.transform\n );\n }\n\n for (i = 0; i < instancesLength; i++) {\n // Get the instance position\n instancePosition = Cartesian3.clone(instancePositions[i]);\n\n if (defined(rtcCenter)) {\n Cartesian3.add(\n instancePosition,\n Cartesian3.unpack(rtcCenter),\n instancePosition\n );\n }\n\n // Get the instance rotation, if present\n if (hasRotation) {\n processRotation(\n featureTable,\n eastNorthUp,\n i,\n instanceQuaternion,\n instancePosition,\n instanceNormalUp,\n instanceNormalRight,\n instanceNormalForward,\n instanceRotation,\n instanceTransform\n );\n Quaternion.pack(instanceQuaternion, instanceQuaternionArray, 0);\n rotationTypedArray[4 * i + 0] = instanceQuaternionArray[0];\n rotationTypedArray[4 * i + 1] = instanceQuaternionArray[1];\n rotationTypedArray[4 * i + 2] = instanceQuaternionArray[2];\n rotationTypedArray[4 * i + 3] = instanceQuaternionArray[3];\n }\n\n // Get the instance scale, if present\n if (hasScale) {\n processScale(featureTable, i, instanceScale);\n Cartesian3.pack(instanceScale, instanceScaleArray, 0);\n scaleTypedArray[3 * i + 0] = instanceScaleArray[0];\n scaleTypedArray[3 * i + 1] = instanceScaleArray[1];\n scaleTypedArray[3 * i + 2] = instanceScaleArray[2];\n }\n\n // Get the batchId\n let batchId = featureTable.getProperty(\n \"BATCH_ID\",\n ComponentDatatype.UNSIGNED_SHORT,\n 1,\n i\n );\n if (!defined(batchId)) {\n // If BATCH_ID semantic is undefined, batchId is just the instance number\n batchId = i;\n }\n featureIdArray[i] = batchId;\n }\n\n // Create instances.\n const instances = new Instances();\n instances.transformInWorldSpace = true;\n const buffers = loader._buffers;\n\n // Create translation vertex attribute.\n const translationAttribute = new Attribute();\n translationAttribute.name = \"Instance Translation\";\n translationAttribute.semantic = InstanceAttributeSemantic.TRANSLATION;\n translationAttribute.componentDatatype = ComponentDatatype.FLOAT;\n translationAttribute.type = AttributeType.VEC3;\n translationAttribute.count = instancesLength;\n // The min / max values of the translation attribute need to be computed\n // by the model pipeline, so so a pointer to the typed array is stored.\n translationAttribute.typedArray = translationTypedArray;\n // If there is no rotation attribute, however, the translations can also be\n // loaded as a buffer to prevent additional resource creation in the pipeline.\n if (!hasRotation) {\n const buffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: translationTypedArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n // Destruction of resources is handled by I3dmLoader.unload().\n buffer.vertexArrayDestroyable = false;\n buffers.push(buffer);\n\n translationAttribute.buffer = buffer;\n }\n\n instances.attributes.push(translationAttribute);\n\n // Create rotation vertex attribute.\n if (hasRotation) {\n const rotationAttribute = new Attribute();\n rotationAttribute.name = \"Instance Rotation\";\n rotationAttribute.semantic = InstanceAttributeSemantic.ROTATION;\n rotationAttribute.componentDatatype = ComponentDatatype.FLOAT;\n rotationAttribute.type = AttributeType.VEC4;\n rotationAttribute.count = instancesLength;\n rotationAttribute.typedArray = rotationTypedArray;\n instances.attributes.push(rotationAttribute);\n }\n\n // Create scale vertex attribute.\n if (hasScale) {\n const scaleAttribute = new Attribute();\n scaleAttribute.name = \"Instance Scale\";\n scaleAttribute.semantic = InstanceAttributeSemantic.SCALE;\n scaleAttribute.componentDatatype = ComponentDatatype.FLOAT;\n scaleAttribute.type = AttributeType.VEC3;\n scaleAttribute.count = instancesLength;\n if (hasRotation) {\n // If rotations are present, all transform attributes are loaded\n // as typed arrays to compute transform matrices for the model.\n scaleAttribute.typedArray = scaleTypedArray;\n } else {\n const buffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: scaleTypedArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n // Destruction of resources is handled by I3dmLoader.unload().\n buffer.vertexArrayDestroyable = false;\n buffers.push(buffer);\n\n scaleAttribute.buffer = buffer;\n }\n\n instances.attributes.push(scaleAttribute);\n }\n\n // Create feature ID vertex attribute.\n const featureIdAttribute = new Attribute();\n featureIdAttribute.name = \"Instance Feature ID\";\n featureIdAttribute.setIndex = 0;\n featureIdAttribute.semantic = InstanceAttributeSemantic.FEATURE_ID;\n featureIdAttribute.componentDatatype = ComponentDatatype.FLOAT;\n featureIdAttribute.type = AttributeType.SCALAR;\n featureIdAttribute.count = instancesLength;\n const buffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: featureIdArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n // Destruction of resources is handled by I3dmLoader.unload().\n buffer.vertexArrayDestroyable = false;\n buffers.push(buffer);\n featureIdAttribute.buffer = buffer;\n\n instances.attributes.push(featureIdAttribute);\n\n // Create feature ID attribute.\n const featureIdInstanceAttribute = new FeatureIdAttribute();\n featureIdInstanceAttribute.propertyTableId = 0;\n featureIdInstanceAttribute.setIndex = 0;\n featureIdInstanceAttribute.positionalLabel = \"instanceFeatureId_0\";\n instances.featureIds.push(featureIdInstanceAttribute);\n\n // Apply instancing to every node that has at least one primitive.\n const nodes = components.nodes;\n const nodesLength = nodes.length;\n let makeInstancesCopy = false;\n for (i = 0; i < nodesLength; i++) {\n const node = nodes[i];\n if (node.primitives.length > 0) {\n // If the instances have not been assigned to a node already, assign\n // it to the first node encountered. Otherwise, make a copy of them\n // for each subsequent node.\n node.instances = makeInstancesCopy\n ? createInstancesCopy(instances)\n : instances;\n\n makeInstancesCopy = true;\n }\n }\n}\n\n/**\n * Returns a copy of the instances that contains shallow copies of the instanced\n * attributes. That is, the instances and attribute objects will be new copies,\n * but they will point to the same buffers and typed arrays. This is so each\n * node can manage memory separately, such that unloading memory for one\n * node does not unload it for another.\n *\n * @returns {ModelComponents.Instances}\n *\n * @private\n */\nfunction createInstancesCopy(instances) {\n const instancesCopy = new Instances();\n instancesCopy.transformInWorldSpace = instances.transformInWorldSpace;\n\n const attributes = instances.attributes;\n const attributesLength = attributes.length;\n\n for (let i = 0; i < attributesLength; i++) {\n const attributeCopy = clone(attributes[i], false);\n instancesCopy.attributes.push(attributeCopy);\n }\n\n instancesCopy.featureIds = instances.featureIds;\n\n return instancesCopy;\n}\n\n/**\n * Returns a typed array of positions from the i3dm's feature table. The positions\n * returned are dequantized, if dequantization is applied.\n *\n * @private\n */\nfunction getPositions(featureTable, instancesLength) {\n if (featureTable.hasProperty(\"POSITION\")) {\n // Handle positions.\n return featureTable.getPropertyArray(\n \"POSITION\",\n ComponentDatatype.FLOAT,\n 3\n );\n } else if (featureTable.hasProperty(\"POSITION_QUANTIZED\")) {\n // Handle quantized positions.\n const quantizedPositions = featureTable.getPropertyArray(\n \"POSITION_QUANTIZED\",\n ComponentDatatype.UNSIGNED_SHORT,\n 3\n );\n\n const quantizedVolumeOffset = featureTable.getGlobalProperty(\n \"QUANTIZED_VOLUME_OFFSET\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (!defined(quantizedVolumeOffset)) {\n throw new RuntimeError(\n \"Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.\"\n );\n }\n\n const quantizedVolumeScale = featureTable.getGlobalProperty(\n \"QUANTIZED_VOLUME_SCALE\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (!defined(quantizedVolumeScale)) {\n throw new RuntimeError(\n \"Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.\"\n );\n }\n\n const decodedPositions = new Float32Array(quantizedPositions.length);\n for (let i = 0; i < quantizedPositions.length / 3; i++) {\n for (let j = 0; j < 3; j++) {\n const index = 3 * i + j;\n decodedPositions[index] =\n (quantizedPositions[index] / 65535.0) * quantizedVolumeScale[j] +\n quantizedVolumeOffset[j];\n }\n }\n\n return decodedPositions;\n\n // eslint-disable-next-line no-else-return\n } else {\n throw new RuntimeError(\n \"Either POSITION or POSITION_QUANTIZED must be defined for each instance.\"\n );\n }\n}\n\nconst propertyScratch2 = new Array(4);\nfunction processRotation(\n featureTable,\n eastNorthUp,\n i,\n instanceQuaternion,\n instancePosition,\n instanceNormalUp,\n instanceNormalRight,\n instanceNormalForward,\n instanceRotation,\n instanceTransform\n) {\n // Get the instance rotation\n const normalUp = featureTable.getProperty(\n \"NORMAL_UP\",\n ComponentDatatype.FLOAT,\n 3,\n i,\n propertyScratch1\n );\n const normalRight = featureTable.getProperty(\n \"NORMAL_RIGHT\",\n ComponentDatatype.FLOAT,\n 3,\n i,\n propertyScratch2\n );\n let hasCustomOrientation = false;\n if (defined(normalUp)) {\n if (!defined(normalRight)) {\n throw new RuntimeError(\n \"To define a custom orientation, both NORMAL_UP and NORMAL_RIGHT must be defined.\"\n );\n }\n Cartesian3.unpack(normalUp, 0, instanceNormalUp);\n Cartesian3.unpack(normalRight, 0, instanceNormalRight);\n hasCustomOrientation = true;\n } else {\n const octNormalUp = featureTable.getProperty(\n \"NORMAL_UP_OCT32P\",\n ComponentDatatype.UNSIGNED_SHORT,\n 2,\n i,\n propertyScratch1\n );\n const octNormalRight = featureTable.getProperty(\n \"NORMAL_RIGHT_OCT32P\",\n ComponentDatatype.UNSIGNED_SHORT,\n 2,\n i,\n propertyScratch2\n );\n if (defined(octNormalUp)) {\n if (!defined(octNormalRight)) {\n throw new RuntimeError(\n \"To define a custom orientation with oct-encoded vectors, both NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P must be defined.\"\n );\n }\n AttributeCompression.octDecodeInRange(\n octNormalUp[0],\n octNormalUp[1],\n 65535,\n instanceNormalUp\n );\n AttributeCompression.octDecodeInRange(\n octNormalRight[0],\n octNormalRight[1],\n 65535,\n instanceNormalRight\n );\n hasCustomOrientation = true;\n } else if (eastNorthUp) {\n Transforms.eastNorthUpToFixedFrame(\n instancePosition,\n Ellipsoid.WGS84,\n instanceTransform\n );\n Matrix4.getMatrix3(instanceTransform, instanceRotation);\n } else {\n Matrix3.clone(Matrix3.IDENTITY, instanceRotation);\n }\n }\n if (hasCustomOrientation) {\n Cartesian3.cross(\n instanceNormalRight,\n instanceNormalUp,\n instanceNormalForward\n );\n Cartesian3.normalize(instanceNormalForward, instanceNormalForward);\n Matrix3.setColumn(\n instanceRotation,\n 0,\n instanceNormalRight,\n instanceRotation\n );\n Matrix3.setColumn(instanceRotation, 1, instanceNormalUp, instanceRotation);\n Matrix3.setColumn(\n instanceRotation,\n 2,\n instanceNormalForward,\n instanceRotation\n );\n }\n Quaternion.fromRotationMatrix(instanceRotation, instanceQuaternion);\n}\n\nfunction processScale(featureTable, i, instanceScale) {\n instanceScale = Cartesian3.fromElements(1.0, 1.0, 1.0, instanceScale);\n const scale = featureTable.getProperty(\n \"SCALE\",\n ComponentDatatype.FLOAT,\n 1,\n i\n );\n if (defined(scale)) {\n Cartesian3.multiplyByScalar(instanceScale, scale, instanceScale);\n }\n const nonUniformScale = featureTable.getProperty(\n \"SCALE_NON_UNIFORM\",\n ComponentDatatype.FLOAT,\n 3,\n i,\n propertyScratch1\n );\n if (defined(nonUniformScale)) {\n instanceScale.x *= nonUniformScale[0];\n instanceScale.y *= nonUniformScale[1];\n instanceScale.z *= nonUniformScale[2];\n }\n}\n\nfunction unloadBuffers(loader) {\n const buffers = loader._buffers;\n const length = buffers.length;\n for (let i = 0; i < length; i++) {\n const buffer = buffers[i];\n if (!buffer.isDestroyed()) {\n buffer.destroy();\n }\n }\n buffers.length = 0;\n}\n\nI3dmLoader.prototype.isUnloaded = function () {\n return this._state === I3dmLoaderState.UNLOADED;\n};\n\nI3dmLoader.prototype.unload = function () {\n if (defined(this._gltfLoader) && !this._gltfLoader.isDestroyed()) {\n this._gltfLoader.unload();\n }\n\n unloadBuffers(this);\n\n this._components = undefined;\n this._arrayBuffer = undefined;\n this._state = I3dmLoaderState.UNLOADED;\n};\n\nexport default I3dmLoader;\n", "/**\n * @private\n */\nconst ModelAnimationState = {\n STOPPED: 0,\n ANIMATING: 1,\n};\n\nexport default Object.freeze(ModelAnimationState);\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport CesiumMath from \"./Math.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Quaternion from \"./Quaternion.js\";\n\n/**\n * Creates a curve parameterized and evaluated by time. This type describes an interface\n * and is not intended to be instantiated directly.\n *\n * @alias Spline\n * @constructor\n *\n * @see CatmullRomSpline\n * @see LinearSpline\n * @see HermiteSpline\n * @see QuaternionSpline\n * @see MorphWeightSpline\n */\nfunction Spline() {\n /**\n * An array of times for the control points.\n * @type {number[]}\n * @default undefined\n */\n this.times = undefined;\n\n /**\n * An array of control points.\n * @type {Cartesian3[]|Quaternion[]}\n * @default undefined\n */\n this.points = undefined;\n\n DeveloperError.throwInstantiationError();\n}\n\n/**\n * Gets the type of the point. This helps a spline determine how to interpolate\n * and return its values.\n *\n * @param {number|Cartesian3|Quaternion} point\n * @returns {*} The type of the point.\n *\n * @exception {DeveloperError} value must be a Cartesian3, Quaternion, or number.\n *\n * @private\n */\nSpline.getPointType = function (point) {\n if (typeof point === \"number\") {\n return Number;\n }\n if (point instanceof Cartesian3) {\n return Cartesian3;\n }\n if (point instanceof Quaternion) {\n return Quaternion;\n }\n\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"point must be a Cartesian3, Quaternion, or number.\"\n );\n //>>includeEnd('debug');\n};\n\n/**\n * Evaluates the curve at a given time.\n * @function\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Cartesian3|Quaternion|number[]} [result] The object onto which to store the result.\n * @returns {Cartesian3|Quaternion|number[]} The modified result parameter or a new instance of the point on the curve at the given time.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nSpline.prototype.evaluate = DeveloperError.throwInstantiationError;\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n *\n * @param {number} time The time.\n * @param {number} startIndex The index from which to start the search.\n * @returns {number} The index for the element at the start of the interval.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nSpline.prototype.findTimeInterval = function (time, startIndex) {\n const times = this.times;\n const length = times.length;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n if (time < times[0] || time > times[length - 1]) {\n throw new DeveloperError(\"time is out of range.\");\n }\n //>>includeEnd('debug');\n\n // Take advantage of temporal coherence by checking current, next and previous intervals\n // for containment of time.\n startIndex = defaultValue(startIndex, 0);\n\n if (time >= times[startIndex]) {\n if (startIndex + 1 < length && time < times[startIndex + 1]) {\n return startIndex;\n } else if (startIndex + 2 < length && time < times[startIndex + 2]) {\n return startIndex + 1;\n }\n } else if (startIndex - 1 >= 0 && time >= times[startIndex - 1]) {\n return startIndex - 1;\n }\n\n // The above failed so do a linear search. For the use cases so far, the\n // length of the list is less than 10. In the future, if there is a bottle neck,\n // it might be here.\n\n let i;\n if (time > times[startIndex]) {\n for (i = startIndex; i < length - 1; ++i) {\n if (time >= times[i] && time < times[i + 1]) {\n break;\n }\n }\n } else {\n for (i = startIndex - 1; i >= 0; --i) {\n if (time >= times[i] && time < times[i + 1]) {\n break;\n }\n }\n }\n\n if (i === length - 1) {\n i = length - 2;\n }\n\n return i;\n};\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around the animation period.\n */\nSpline.prototype.wrapTime = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n //>>includeEnd('debug');\n\n const times = this.times;\n const timeEnd = times[times.length - 1];\n const timeStart = times[0];\n const timeStretch = timeEnd - timeStart;\n let divs;\n if (time < timeStart) {\n divs = Math.floor((timeStart - time) / timeStretch) + 1;\n time += divs * timeStretch;\n }\n if (time > timeEnd) {\n divs = Math.floor((time - timeEnd) / timeStretch) + 1;\n time -= divs * timeStretch;\n }\n return time;\n};\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nSpline.prototype.clampTime = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n //>>includeEnd('debug');\n\n const times = this.times;\n return CesiumMath.clamp(time, times[0], times[times.length - 1]);\n};\n\nexport default Spline;\n", "import Check from \"./Check.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Spline from \"./Spline.js\";\n\n/**\n * A spline that evaluates to a constant value. Although this follows the {@link Spline} interface,\n * it does not maintain an internal array of times since its value never changes.\n *\n * @alias ConstantSpline\n * @constructor\n *\n * @param {number|Cartesian3|Quaternion} value The constant value that the spline evaluates to.\n *\n * @example\n * const position = new Cesium.Cartesian3(1.0, 2.0, 3.0);\n * const spline = new Cesium.ConstantSpline(position);\n *\n * const p0 = spline.evaluate(0.0);\n *\n * @see LinearSpline\n * @see HermiteSpline\n * @see CatmullRomSpline\n * @see QuaternionSpline\n * @see MorphWeightSpline\n */\nfunction ConstantSpline(value) {\n this._value = value;\n this._valueType = Spline.getPointType(value);\n}\n\nObject.defineProperties(ConstantSpline.prototype, {\n /**\n * The constant value that the spline evaluates to.\n *\n * @memberof ConstantSpline.prototype\n *\n * @type {number|Cartesian3|Quaternion}\n * @readonly\n */\n value: {\n get: function () {\n return this._value;\n },\n },\n});\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n *\n * Since a constant spline has no internal times array, this will throw an error.\n * @function\n *\n * @param {number} time The time.\n *\n * @exception {DeveloperError} findTimeInterval cannot be called on a ConstantSpline.\n */\nConstantSpline.prototype.findTimeInterval = function (time) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"findTimeInterval cannot be called on a ConstantSpline.\"\n );\n //>>includeEnd('debug');\n};\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around to the updated animation.\n */\nConstantSpline.prototype.wrapTime = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n //>>includeEnd('debug');\n\n return 0.0;\n};\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nConstantSpline.prototype.clampTime = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n //>>includeEnd('debug');\n\n return 0.0;\n};\n\n/**\n * Evaluates the curve at a given time.\n * @function\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Cartesian3|Quaternion} [result] The object onto which to store the result.\n * @returns {number|Cartesian3|Quaternion} The modified result parameter or the value that the constant spline represents.\n */\nConstantSpline.prototype.evaluate = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"time\", time);\n //>>includeEnd('debug');\n\n const value = this._value;\n const ValueType = this._valueType;\n\n if (ValueType === Number) {\n return value;\n }\n\n return ValueType.clone(value, result);\n};\n\nexport default ConstantSpline;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Spline from \"./Spline.js\";\n\n/**\n * A spline that uses piecewise linear interpolation to create a curve.\n *\n * @alias LinearSpline\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times An array of strictly increasing, unit-less, floating-point times at each point.\n * The values are in no way connected to the clock time. They are the parameterization for the curve.\n * @param {number[]|Cartesian3[]} options.points The array of control points.\n *\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n *\n *\n * @example\n * const times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];\n * const spline = new Cesium.LinearSpline({\n * times : times,\n * points : [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ]\n * });\n *\n * const p0 = spline.evaluate(times[0]);\n *\n * @see ConstantSpline\n * @see SteppedSpline\n * @see HermiteSpline\n * @see CatmullRomSpline\n * @see QuaternionSpline\n * @see MorphWeightSpline\n */\nfunction LinearSpline(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const points = options.points;\n const times = options.times;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(points) || !defined(times)) {\n throw new DeveloperError(\"points and times are required.\");\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n //>>includeEnd('debug');\n\n this._times = times;\n this._points = points;\n this._pointType = Spline.getPointType(points[0]);\n\n this._lastTimeIndex = 0;\n}\n\nObject.defineProperties(LinearSpline.prototype, {\n /**\n * An array of times for the control points.\n *\n * @memberof LinearSpline.prototype\n *\n * @type {number[]}\n * @readonly\n */\n times: {\n get: function () {\n return this._times;\n },\n },\n\n /**\n * An array of {@link Cartesian3} control points.\n *\n * @memberof LinearSpline.prototype\n *\n * @type {number[]|Cartesian3[]}\n * @readonly\n */\n points: {\n get: function () {\n return this._points;\n },\n },\n});\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n * @function\n *\n * @param {number} time The time.\n * @returns {number} The index for the element at the start of the interval.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nLinearSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around to the updated animation.\n */\nLinearSpline.prototype.wrapTime = Spline.prototype.wrapTime;\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nLinearSpline.prototype.clampTime = Spline.prototype.clampTime;\n\n/**\n * Evaluates the curve at a given time.\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {number|Cartesian3} The modified result parameter or a new instance of the point on the curve at the given time.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nLinearSpline.prototype.evaluate = function (time, result) {\n const points = this.points;\n const times = this.times;\n\n const i = (this._lastTimeIndex = this.findTimeInterval(\n time,\n this._lastTimeIndex\n ));\n const u = (time - times[i]) / (times[i + 1] - times[i]);\n\n const PointType = this._pointType;\n if (PointType === Number) {\n return (1.0 - u) * points[i] + u * points[i + 1];\n }\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n return Cartesian3.lerp(points[i], points[i + 1], u, result);\n};\n\nexport default LinearSpline;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Uses the Tridiagonal Matrix Algorithm, also known as the Thomas Algorithm, to solve\n * a system of linear equations where the coefficient matrix is a tridiagonal matrix.\n *\n * @namespace TridiagonalSystemSolver\n */\nconst TridiagonalSystemSolver = {};\n\n/**\n * Solves a tridiagonal system of linear equations.\n *\n * @param {number[]} diagonal An array with length n that contains the diagonal of the coefficient matrix.\n * @param {number[]} lower An array with length n - 1 that contains the lower diagonal of the coefficient matrix.\n * @param {number[]} upper An array with length n - 1 that contains the upper diagonal of the coefficient matrix.\n * @param {Cartesian3[]} right An array of Cartesians with length n that is the right side of the system of equations.\n *\n * @exception {DeveloperError} diagonal and right must have the same lengths.\n * @exception {DeveloperError} lower and upper must have the same lengths.\n * @exception {DeveloperError} lower and upper must be one less than the length of diagonal.\n *\n * @performance Linear time.\n *\n * @example\n * const lowerDiagonal = [1.0, 1.0, 1.0, 1.0];\n * const diagonal = [2.0, 4.0, 4.0, 4.0, 2.0];\n * const upperDiagonal = [1.0, 1.0, 1.0, 1.0];\n * const rightHandSide = [\n * new Cesium.Cartesian3(410757.0, -1595711.0, 1375302.0),\n * new Cesium.Cartesian3(-5986705.0, -2190640.0, 1099600.0),\n * new Cesium.Cartesian3(-12593180.0, 288588.0, -1755549.0),\n * new Cesium.Cartesian3(-5349898.0, 2457005.0, -2685438.0),\n * new Cesium.Cartesian3(845820.0, 1573488.0, -1205591.0)\n * ];\n *\n * const solution = Cesium.TridiagonalSystemSolver.solve(lowerDiagonal, diagonal, upperDiagonal, rightHandSide);\n *\n * @returns {Cartesian3[]} An array of Cartesians with length n that is the solution to the tridiagonal system of equations.\n */\nTridiagonalSystemSolver.solve = function (lower, diagonal, upper, right) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(lower) || !(lower instanceof Array)) {\n throw new DeveloperError(\"The array lower is required.\");\n }\n if (!defined(diagonal) || !(diagonal instanceof Array)) {\n throw new DeveloperError(\"The array diagonal is required.\");\n }\n if (!defined(upper) || !(upper instanceof Array)) {\n throw new DeveloperError(\"The array upper is required.\");\n }\n if (!defined(right) || !(right instanceof Array)) {\n throw new DeveloperError(\"The array right is required.\");\n }\n if (diagonal.length !== right.length) {\n throw new DeveloperError(\"diagonal and right must have the same lengths.\");\n }\n if (lower.length !== upper.length) {\n throw new DeveloperError(\"lower and upper must have the same lengths.\");\n } else if (lower.length !== diagonal.length - 1) {\n throw new DeveloperError(\n \"lower and upper must be one less than the length of diagonal.\"\n );\n }\n //>>includeEnd('debug');\n\n const c = new Array(upper.length);\n const d = new Array(right.length);\n const x = new Array(right.length);\n\n let i;\n for (i = 0; i < d.length; i++) {\n d[i] = new Cartesian3();\n x[i] = new Cartesian3();\n }\n\n c[0] = upper[0] / diagonal[0];\n d[0] = Cartesian3.multiplyByScalar(right[0], 1.0 / diagonal[0], d[0]);\n\n let scalar;\n for (i = 1; i < c.length; ++i) {\n scalar = 1.0 / (diagonal[i] - c[i - 1] * lower[i - 1]);\n c[i] = upper[i] * scalar;\n d[i] = Cartesian3.subtract(\n right[i],\n Cartesian3.multiplyByScalar(d[i - 1], lower[i - 1], d[i]),\n d[i]\n );\n d[i] = Cartesian3.multiplyByScalar(d[i], scalar, d[i]);\n }\n\n scalar = 1.0 / (diagonal[i] - c[i - 1] * lower[i - 1]);\n d[i] = Cartesian3.subtract(\n right[i],\n Cartesian3.multiplyByScalar(d[i - 1], lower[i - 1], d[i]),\n d[i]\n );\n d[i] = Cartesian3.multiplyByScalar(d[i], scalar, d[i]);\n\n x[x.length - 1] = d[d.length - 1];\n for (i = x.length - 2; i >= 0; --i) {\n x[i] = Cartesian3.subtract(\n d[i],\n Cartesian3.multiplyByScalar(x[i + 1], c[i], x[i]),\n x[i]\n );\n }\n\n return x;\n};\nexport default TridiagonalSystemSolver;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport LinearSpline from \"./LinearSpline.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Spline from \"./Spline.js\";\nimport TridiagonalSystemSolver from \"./TridiagonalSystemSolver.js\";\n\nconst scratchLower = [];\nconst scratchDiagonal = [];\nconst scratchUpper = [];\nconst scratchRight = [];\n\nfunction generateClamped(points, firstTangent, lastTangent) {\n const l = scratchLower;\n const u = scratchUpper;\n const d = scratchDiagonal;\n const r = scratchRight;\n\n l.length = u.length = points.length - 1;\n d.length = r.length = points.length;\n\n let i;\n l[0] = d[0] = 1.0;\n u[0] = 0.0;\n\n let right = r[0];\n if (!defined(right)) {\n right = r[0] = new Cartesian3();\n }\n Cartesian3.clone(firstTangent, right);\n\n for (i = 1; i < l.length - 1; ++i) {\n l[i] = u[i] = 1.0;\n d[i] = 4.0;\n\n right = r[i];\n if (!defined(right)) {\n right = r[i] = new Cartesian3();\n }\n Cartesian3.subtract(points[i + 1], points[i - 1], right);\n Cartesian3.multiplyByScalar(right, 3.0, right);\n }\n\n l[i] = 0.0;\n u[i] = 1.0;\n d[i] = 4.0;\n\n right = r[i];\n if (!defined(right)) {\n right = r[i] = new Cartesian3();\n }\n Cartesian3.subtract(points[i + 1], points[i - 1], right);\n Cartesian3.multiplyByScalar(right, 3.0, right);\n\n d[i + 1] = 1.0;\n right = r[i + 1];\n if (!defined(right)) {\n right = r[i + 1] = new Cartesian3();\n }\n Cartesian3.clone(lastTangent, right);\n\n return TridiagonalSystemSolver.solve(l, d, u, r);\n}\n\nfunction generateNatural(points) {\n const l = scratchLower;\n const u = scratchUpper;\n const d = scratchDiagonal;\n const r = scratchRight;\n\n l.length = u.length = points.length - 1;\n d.length = r.length = points.length;\n\n let i;\n l[0] = u[0] = 1.0;\n d[0] = 2.0;\n\n let right = r[0];\n if (!defined(right)) {\n right = r[0] = new Cartesian3();\n }\n Cartesian3.subtract(points[1], points[0], right);\n Cartesian3.multiplyByScalar(right, 3.0, right);\n\n for (i = 1; i < l.length; ++i) {\n l[i] = u[i] = 1.0;\n d[i] = 4.0;\n\n right = r[i];\n if (!defined(right)) {\n right = r[i] = new Cartesian3();\n }\n Cartesian3.subtract(points[i + 1], points[i - 1], right);\n Cartesian3.multiplyByScalar(right, 3.0, right);\n }\n\n d[i] = 2.0;\n\n right = r[i];\n if (!defined(right)) {\n right = r[i] = new Cartesian3();\n }\n Cartesian3.subtract(points[i], points[i - 1], right);\n Cartesian3.multiplyByScalar(right, 3.0, right);\n\n return TridiagonalSystemSolver.solve(l, d, u, r);\n}\n\n/**\n * A Hermite spline is a cubic interpolating spline. Points, incoming tangents, outgoing tangents, and times\n * must be defined for each control point. The outgoing tangents are defined for points [0, n - 2] and the incoming\n * tangents are defined for points [1, n - 1]. For example, when interpolating a segment of the curve between points[i] and\n * points[i + 1], the tangents at the points will be outTangents[i] and inTangents[i],\n * respectively.\n *\n * @alias HermiteSpline\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times An array of strictly increasing, unit-less, floating-point times at each point.\n * The values are in no way connected to the clock time. They are the parameterization for the curve.\n * @param {Cartesian3[]} options.points The array of control points.\n * @param {Cartesian3[]} options.inTangents The array of incoming tangents at each control point.\n * @param {Cartesian3[]} options.outTangents The array of outgoing tangents at each control point.\n *\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n * @exception {DeveloperError} inTangents and outTangents must have a length equal to points.length - 1.\n * @exception {DeveloperError} inTangents and outTangents must be of the same type as points.\n *\n * @example\n * // Create a G1 continuous Hermite spline\n * const times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];\n * const spline = new Cesium.HermiteSpline({\n * times : times,\n * points : [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ],\n * outTangents : [\n * new Cesium.Cartesian3(1125196, -161816, 270551),\n * new Cesium.Cartesian3(-996690.5, -365906.5, 184028.5),\n * new Cesium.Cartesian3(-2096917, 48379.5, -292683.5),\n * new Cesium.Cartesian3(-890902.5, 408999.5, -447115)\n * ],\n * inTangents : [\n * new Cesium.Cartesian3(-1993381, -731813, 368057),\n * new Cesium.Cartesian3(-4193834, 96759, -585367),\n * new Cesium.Cartesian3(-1781805, 817999, -894230),\n * new Cesium.Cartesian3(1165345, 112641, 47281)\n * ]\n * });\n *\n * const p0 = spline.evaluate(times[0]);\n *\n * @see ConstantSpline\n * @see SteppedSpline\n * @see LinearSpline\n * @see CatmullRomSpline\n * @see QuaternionSpline\n * @see MorphWeightSpline\n */\nfunction HermiteSpline(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const points = options.points;\n const times = options.times;\n const inTangents = options.inTangents;\n const outTangents = options.outTangents;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(points) ||\n !defined(times) ||\n !defined(inTangents) ||\n !defined(outTangents)\n ) {\n throw new DeveloperError(\n \"times, points, inTangents, and outTangents are required.\"\n );\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n if (\n inTangents.length !== outTangents.length ||\n inTangents.length !== points.length - 1\n ) {\n throw new DeveloperError(\n \"inTangents and outTangents must have a length equal to points.length - 1.\"\n );\n }\n //>>includeEnd('debug');\n\n this._times = times;\n this._points = points;\n this._pointType = Spline.getPointType(points[0]);\n //>>includeStart('debug', pragmas.debug);\n if (\n this._pointType !== Spline.getPointType(inTangents[0]) ||\n this._pointType !== Spline.getPointType(outTangents[0])\n ) {\n throw new DeveloperError(\n \"inTangents and outTangents must be of the same type as points.\"\n );\n }\n //>>includeEnd('debug');\n\n this._inTangents = inTangents;\n this._outTangents = outTangents;\n\n this._lastTimeIndex = 0;\n}\n\nObject.defineProperties(HermiteSpline.prototype, {\n /**\n * An array of times for the control points.\n *\n * @memberof HermiteSpline.prototype\n *\n * @type {number[]}\n * @readonly\n */\n times: {\n get: function () {\n return this._times;\n },\n },\n\n /**\n * An array of control points.\n *\n * @memberof HermiteSpline.prototype\n *\n * @type {Cartesian3[]}\n * @readonly\n */\n points: {\n get: function () {\n return this._points;\n },\n },\n\n /**\n * An array of incoming tangents at each control point.\n *\n * @memberof HermiteSpline.prototype\n *\n * @type {Cartesian3[]}\n * @readonly\n */\n inTangents: {\n get: function () {\n return this._inTangents;\n },\n },\n\n /**\n * An array of outgoing tangents at each control point.\n *\n * @memberof HermiteSpline.prototype\n *\n * @type {Cartesian3[]}\n * @readonly\n */\n outTangents: {\n get: function () {\n return this._outTangents;\n },\n },\n});\n\n/**\n * Creates a spline where the tangents at each control point are the same.\n * The curves are guaranteed to be at least in the class C1.\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times The array of control point times.\n * @param {Cartesian3[]} options.points The array of control points.\n * @param {Cartesian3[]} options.tangents The array of tangents at the control points.\n * @returns {HermiteSpline} A hermite spline.\n *\n * @exception {DeveloperError} points, times and tangents are required.\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times, points and tangents must have the same length.\n *\n * @example\n * const points = [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ];\n *\n * // Add tangents\n * const tangents = new Array(points.length);\n * tangents[0] = new Cesium.Cartesian3(1125196, -161816, 270551);\n * const temp = new Cesium.Cartesian3();\n * for (let i = 1; i < tangents.length - 1; ++i) {\n * tangents[i] = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.subtract(points[i + 1], points[i - 1], temp), 0.5, new Cesium.Cartesian3());\n * }\n * tangents[tangents.length - 1] = new Cesium.Cartesian3(1165345, 112641, 47281);\n *\n * const spline = Cesium.HermiteSpline.createC1({\n * times : times,\n * points : points,\n * tangents : tangents\n * });\n */\nHermiteSpline.createC1 = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const times = options.times;\n const points = options.points;\n const tangents = options.tangents;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(points) || !defined(times) || !defined(tangents)) {\n throw new DeveloperError(\"points, times and tangents are required.\");\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length || times.length !== tangents.length) {\n throw new DeveloperError(\n \"times, points and tangents must have the same length.\"\n );\n }\n //>>includeEnd('debug');\n\n const outTangents = tangents.slice(0, tangents.length - 1);\n const inTangents = tangents.slice(1, tangents.length);\n\n return new HermiteSpline({\n times: times,\n points: points,\n inTangents: inTangents,\n outTangents: outTangents,\n });\n};\n\n/**\n * Creates a natural cubic spline. The tangents at the control points are generated\n * to create a curve in the class C2.\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times The array of control point times.\n * @param {Cartesian3[]} options.points The array of control points.\n * @returns {HermiteSpline|LinearSpline} A hermite spline, or a linear spline if less than 3 control points were given.\n *\n * @exception {DeveloperError} points and times are required.\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n *\n * @example\n * // Create a natural cubic spline above the earth from Philadelphia to Los Angeles.\n * const spline = Cesium.HermiteSpline.createNaturalCubic({\n * times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],\n * points : [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ]\n * });\n */\nHermiteSpline.createNaturalCubic = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const times = options.times;\n const points = options.points;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(points) || !defined(times)) {\n throw new DeveloperError(\"points and times are required.\");\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n //>>includeEnd('debug');\n\n if (points.length < 3) {\n return new LinearSpline({\n points: points,\n times: times,\n });\n }\n\n const tangents = generateNatural(points);\n const outTangents = tangents.slice(0, tangents.length - 1);\n const inTangents = tangents.slice(1, tangents.length);\n\n return new HermiteSpline({\n times: times,\n points: points,\n inTangents: inTangents,\n outTangents: outTangents,\n });\n};\n\n/**\n * Creates a clamped cubic spline. The tangents at the interior control points are generated\n * to create a curve in the class C2.\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times The array of control point times.\n * @param {number[]|Cartesian3[]} options.points The array of control points.\n * @param {Cartesian3} options.firstTangent The outgoing tangent of the first control point.\n * @param {Cartesian3} options.lastTangent The incoming tangent of the last control point.\n * @returns {HermiteSpline|LinearSpline} A hermite spline, or a linear spline if less than 3 control points were given.\n *\n * @exception {DeveloperError} points, times, firstTangent and lastTangent are required.\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n * @exception {DeveloperError} firstTangent and lastTangent must be of the same type as points.\n *\n * @example\n * // Create a clamped cubic spline above the earth from Philadelphia to Los Angeles.\n * const spline = Cesium.HermiteSpline.createClampedCubic({\n * times : [ 0.0, 1.5, 3.0, 4.5, 6.0 ],\n * points : [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ],\n * firstTangent : new Cesium.Cartesian3(1125196, -161816, 270551),\n * lastTangent : new Cesium.Cartesian3(1165345, 112641, 47281)\n * });\n */\nHermiteSpline.createClampedCubic = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const times = options.times;\n const points = options.points;\n const firstTangent = options.firstTangent;\n const lastTangent = options.lastTangent;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n !defined(points) ||\n !defined(times) ||\n !defined(firstTangent) ||\n !defined(lastTangent)\n ) {\n throw new DeveloperError(\n \"points, times, firstTangent and lastTangent are required.\"\n );\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n //>>includeEnd('debug');\n\n const PointType = Spline.getPointType(points[0]);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n PointType !== Spline.getPointType(firstTangent) ||\n PointType !== Spline.getPointType(lastTangent)\n ) {\n throw new DeveloperError(\n \"firstTangent and lastTangent must be of the same type as points.\"\n );\n }\n //>>includeEnd('debug');\n\n if (points.length < 3) {\n return new LinearSpline({\n points: points,\n times: times,\n });\n }\n\n const tangents = generateClamped(points, firstTangent, lastTangent);\n const outTangents = tangents.slice(0, tangents.length - 1);\n const inTangents = tangents.slice(1, tangents.length);\n\n return new HermiteSpline({\n times: times,\n points: points,\n inTangents: inTangents,\n outTangents: outTangents,\n });\n};\n\n//prettier-ignore\nHermiteSpline.hermiteCoefficientMatrix = new Matrix4(\n 2.0, -3.0, 0.0, 1.0,\n -2.0, 3.0, 0.0, 0.0,\n 1.0, -2.0, 1.0, 0.0,\n 1.0, -1.0, 0.0, 0.0\n);\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n * @function\n *\n * @param {number} time The time.\n * @returns {number} The index for the element at the start of the interval.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nHermiteSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;\n\nconst scratchTimeVec = new Cartesian4();\nconst scratchTemp = new Cartesian3();\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around to the updated animation.\n */\nHermiteSpline.prototype.wrapTime = Spline.prototype.wrapTime;\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nHermiteSpline.prototype.clampTime = Spline.prototype.clampTime;\n\n/**\n * Evaluates the curve at a given time.\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Cartesian3} [result] The object onto which to store the result.\n * @returns {Cartesian3} The modified result parameter or a new instance of the point on the curve at the given time.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nHermiteSpline.prototype.evaluate = function (time, result) {\n const points = this.points;\n const times = this.times;\n const inTangents = this.inTangents;\n const outTangents = this.outTangents;\n\n this._lastTimeIndex = this.findTimeInterval(time, this._lastTimeIndex);\n const i = this._lastTimeIndex;\n\n const timesDelta = times[i + 1] - times[i];\n const u = (time - times[i]) / timesDelta;\n\n const timeVec = scratchTimeVec;\n timeVec.z = u;\n timeVec.y = u * u;\n timeVec.x = timeVec.y * u;\n timeVec.w = 1.0;\n\n // Coefficients are returned in the following order:\n // start, end, out-tangent, in-tangent\n const coefs = Matrix4.multiplyByVector(\n HermiteSpline.hermiteCoefficientMatrix,\n timeVec,\n timeVec\n );\n\n // Multiply the out-tangent and in-tangent values by the time delta.\n coefs.z *= timesDelta;\n coefs.w *= timesDelta;\n\n const PointType = this._pointType;\n\n if (PointType === Number) {\n return (\n points[i] * coefs.x +\n points[i + 1] * coefs.y +\n outTangents[i] * coefs.z +\n inTangents[i] * coefs.w\n );\n }\n\n if (!defined(result)) {\n result = new PointType();\n }\n\n result = PointType.multiplyByScalar(points[i], coefs.x, result);\n PointType.multiplyByScalar(points[i + 1], coefs.y, scratchTemp);\n PointType.add(result, scratchTemp, result);\n PointType.multiplyByScalar(outTangents[i], coefs.z, scratchTemp);\n PointType.add(result, scratchTemp, result);\n PointType.multiplyByScalar(inTangents[i], coefs.w, scratchTemp);\n return PointType.add(result, scratchTemp, result);\n};\nexport default HermiteSpline;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Spline from \"./Spline.js\";\n\n/**\n * A spline that is composed of piecewise constants representing a step function.\n *\n * @alias SteppedSpline\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times An array of strictly increasing, unit-less, floating-point times at each point. The values are in no way connected to the clock time. They are the parameterization for the curve.\n * @param {number[]|Cartesian3[]|Quaternion[]} options.points The array of control points.\n *\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n *\n * @example\n * const times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];\n * const spline = new Cesium.SteppedSpline({\n * times : times,\n * points : [\n * new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),\n * new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),\n * new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),\n * new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),\n * new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)\n * ]\n * });\n *\n * const p0 = spline.evaluate(times[0]);\n *\n * @see ConstantSpline\n * @see CatmullRomSpline\n * @see HermiteSpline\n * @see LinearSpline\n * @see QuaternionSpline\n * @see MorphWeightSpline\n */\nfunction SteppedSpline(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const points = options.points;\n const times = options.times;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(points) || !defined(times)) {\n throw new DeveloperError(\"points and times are required.\");\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n //>>includeEnd('debug');\n\n this._times = times;\n this._points = points;\n this._pointType = Spline.getPointType(points[0]);\n\n this._lastTimeIndex = 0;\n}\n\nObject.defineProperties(SteppedSpline.prototype, {\n /**\n * An array of times for the control points.\n *\n * @memberof SteppedSpline.prototype\n *\n * @type {number[]}\n * @readonly\n */\n times: {\n get: function () {\n return this._times;\n },\n },\n\n /**\n * An array of control points.\n *\n * @memberof SteppedSpline.prototype\n *\n * @type {number[]|Cartesian3[]|Quaternion[]}\n * @readonly\n */\n points: {\n get: function () {\n return this._points;\n },\n },\n});\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n * @function\n *\n * @param {number} time The time.\n * @param {number} startIndex The index from which to start the search.\n * @returns {number} The index for the element at the start of the interval.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nSteppedSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around to the updated animation.\n */\nSteppedSpline.prototype.wrapTime = Spline.prototype.wrapTime;\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nSteppedSpline.prototype.clampTime = Spline.prototype.clampTime;\n\n/**\n * Evaluates the curve at a given time.\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Cartesian3|Quaternion} [result] The object onto which to store the result.\n * @returns {number|Cartesian3|Quaternion} The modified result parameter or a new instance of the point on the curve at the given time.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nSteppedSpline.prototype.evaluate = function (time, result) {\n const points = this.points;\n\n this._lastTimeIndex = this.findTimeInterval(time, this._lastTimeIndex);\n const i = this._lastTimeIndex;\n\n const PointType = this._pointType;\n if (PointType === Number) {\n return points[i];\n }\n\n if (!defined(result)) {\n result = new PointType();\n }\n\n return PointType.clone(points[i], result);\n};\n\nexport default SteppedSpline;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Spline from \"./Spline.js\";\n\nfunction createEvaluateFunction(spline) {\n const points = spline.points;\n const times = spline.times;\n\n // use slerp interpolation\n return function (time, result) {\n if (!defined(result)) {\n result = new Quaternion();\n }\n const i = (spline._lastTimeIndex = spline.findTimeInterval(\n time,\n spline._lastTimeIndex\n ));\n const u = (time - times[i]) / (times[i + 1] - times[i]);\n\n const q0 = points[i];\n const q1 = points[i + 1];\n\n return Quaternion.fastSlerp(q0, q1, u, result);\n };\n}\n\n/**\n * A spline that uses spherical linear (slerp) interpolation to create a quaternion curve.\n * The generated curve is in the class C1.\n *\n * @alias QuaternionSpline\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number[]} options.times An array of strictly increasing, unit-less, floating-point times at each point.\n * The values are in no way connected to the clock time. They are the parameterization for the curve.\n * @param {Quaternion[]} options.points The array of {@link Quaternion} control points.\n *\n * @exception {DeveloperError} points and times are required\n * @exception {DeveloperError} points.length must be greater than or equal to 2.\n * @exception {DeveloperError} times.length must be equal to points.length.\n\n * @see ConstantSpline\n * @see SteppedSpline\n * @see HermiteSpline\n * @see CatmullRomSpline\n * @see LinearSpline\n * @see MorphWeightSpline\n */\nfunction QuaternionSpline(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const points = options.points;\n const times = options.times;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(points) || !defined(times)) {\n throw new DeveloperError(\"points and times are required.\");\n }\n if (points.length < 2) {\n throw new DeveloperError(\n \"points.length must be greater than or equal to 2.\"\n );\n }\n if (times.length !== points.length) {\n throw new DeveloperError(\"times.length must be equal to points.length.\");\n }\n //>>includeEnd('debug');\n\n this._times = times;\n this._points = points;\n\n this._evaluateFunction = createEvaluateFunction(this);\n this._lastTimeIndex = 0;\n}\n\nObject.defineProperties(QuaternionSpline.prototype, {\n /**\n * An array of times for the control points.\n *\n * @memberof QuaternionSpline.prototype\n *\n * @type {number[]}\n * @readonly\n */\n times: {\n get: function () {\n return this._times;\n },\n },\n\n /**\n * An array of {@link Quaternion} control points.\n *\n * @memberof QuaternionSpline.prototype\n *\n * @type {Quaternion[]}\n * @readonly\n */\n points: {\n get: function () {\n return this._points;\n },\n },\n});\n\n/**\n * Finds an index i in times such that the parameter\n * time is in the interval [times[i], times[i + 1]].\n * @function\n *\n * @param {number} time The time.\n * @returns {number} The index for the element at the start of the interval.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nQuaternionSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;\n\n/**\n * Wraps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, wrapped around to the updated animation.\n */\nQuaternionSpline.prototype.wrapTime = Spline.prototype.wrapTime;\n\n/**\n * Clamps the given time to the period covered by the spline.\n * @function\n *\n * @param {number} time The time.\n * @return {number} The time, clamped to the animation period.\n */\nQuaternionSpline.prototype.clampTime = Spline.prototype.clampTime;\n\n/**\n * Evaluates the curve at a given time.\n *\n * @param {number} time The time at which to evaluate the curve.\n * @param {Quaternion} [result] The object onto which to store the result.\n * @returns {Quaternion} The modified result parameter or a new instance of the point on the curve at the given time.\n *\n * @exception {DeveloperError} time must be in the range [t0, tn], where t0\n * is the first element in the array times and tn is the last element\n * in the array times.\n */\nQuaternionSpline.prototype.evaluate = function (time, result) {\n return this._evaluateFunction(time, result);\n};\nexport default QuaternionSpline;\n", "import Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport ConstantSpline from \"../../Core/ConstantSpline.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport HermiteSpline from \"../../Core/HermiteSpline.js\";\nimport InterpolationType from \"../../Core/InterpolationType.js\";\nimport LinearSpline from \"../../Core/LinearSpline.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport SteppedSpline from \"../../Core/SteppedSpline.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport QuaternionSpline from \"../../Core/QuaternionSpline.js\";\n\nconst AnimatedPropertyType = ModelComponents.AnimatedPropertyType;\n\n/**\n * A runtime animation channel for a {@link ModelAnimation}. An animation\n * channel is responsible for interpolating between the keyframe values of an animated\n * property, then applying the change to the target node.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.AnimationChannel} options.channel The corresponding animation channel components from the 3D model.\n * @param {ModelAnimation} options.runtimeAnimation The runtime animation containing this channel.\n * @param {ModelRuntimeNode} options.runtimeNode The runtime node that this channel will animate.\n *\n * @alias ModelAnimationChannel\n * @constructor\n *\n * @private\n */\nfunction ModelAnimationChannel(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const channel = options.channel;\n const runtimeAnimation = options.runtimeAnimation;\n const runtimeNode = options.runtimeNode;\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.channel\", channel);\n Check.typeOf.object(\"options.runtimeAnimation\", runtimeAnimation);\n Check.typeOf.object(\"options.runtimeNode\", runtimeNode);\n //>>includeEnd('debug');\n\n this._channel = channel;\n this._runtimeAnimation = runtimeAnimation;\n this._runtimeNode = runtimeNode;\n\n // An animation channel can have multiple splines if it animates\n // a node's morph weights, which will involve multiple morph targets.\n this._splines = [];\n this._path = undefined;\n\n initialize(this);\n}\n\nObject.defineProperties(ModelAnimationChannel.prototype, {\n /**\n * The glTF animation channel.\n *\n * @memberof ModelAnimationChannel.prototype\n *\n * @type {ModelComponents.AnimationChannel}\n * @readonly\n *\n * @private\n */\n channel: {\n get: function () {\n return this._channel;\n },\n },\n\n /**\n * The runtime animation that owns this channel.\n *\n * @memberof ModelAnimationChannel.prototype\n *\n * @type {ModelAnimation}\n * @readonly\n *\n * @private\n */\n runtimeAnimation: {\n get: function () {\n return this._runtimeAnimation;\n },\n },\n\n /**\n * The runtime node that this channel animates.\n *\n * @memberof ModelAnimationChannel.prototype\n *\n * @type {ModelRuntimeNode}\n * @readonly\n *\n * @private\n */\n runtimeNode: {\n get: function () {\n return this._runtimeNode;\n },\n },\n\n /**\n * The splines used to evaluate this animation channel.\n *\n * @memberof ModelAnimationChannel.prototype\n *\n * @type {Spline[]}\n * @readonly\n *\n * @private\n */\n splines: {\n get: function () {\n return this._splines;\n },\n },\n});\n\nfunction createCubicSpline(times, points) {\n const cubicPoints = [];\n const inTangents = [];\n const outTangents = [];\n\n const length = points.length;\n for (let i = 0; i < length; i += 3) {\n inTangents.push(points[i]);\n cubicPoints.push(points[i + 1]);\n outTangents.push(points[i + 2]);\n }\n\n // Remove the first in-tangent and last out-tangent, since they\n // are not used in the spline calculations\n inTangents.splice(0, 1);\n outTangents.length = outTangents.length - 1;\n\n return new HermiteSpline({\n times: times,\n points: cubicPoints,\n inTangents: inTangents,\n outTangents: outTangents,\n });\n}\n\nfunction createSpline(times, points, interpolation, path) {\n if (times.length === 1 && points.length === 1) {\n return new ConstantSpline(points[0]);\n }\n\n switch (interpolation) {\n case InterpolationType.STEP:\n return new SteppedSpline({\n times: times,\n points: points,\n });\n case InterpolationType.CUBICSPLINE:\n return createCubicSpline(times, points);\n case InterpolationType.LINEAR:\n if (path === AnimatedPropertyType.ROTATION) {\n return new QuaternionSpline({\n times: times,\n points: points,\n });\n }\n return new LinearSpline({\n times: times,\n points: points,\n });\n }\n}\n\nfunction createSplines(times, points, interpolation, path, count) {\n const splines = [];\n if (path === AnimatedPropertyType.WEIGHTS) {\n const pointsLength = points.length;\n // Get the number of keyframes in each weight's output.\n const outputLength = pointsLength / count;\n\n // Iterate over the array using the number of morph targets in the model.\n let targetIndex, i;\n for (targetIndex = 0; targetIndex < count; targetIndex++) {\n const output = new Array(outputLength);\n\n // Weights are ordered such that they are keyframed in the order in which\n // their targets appear the glTF. For example, the weights of three targets\n // may appear as [w(0,0), w(0,1), w(0,2), w(1,0), w(1,1), w(1,2) ...],\n // where i and j in w(i,j) are the time indices and target indices, respectively.\n\n // However, for morph targets with cubic interpolation, the data is stored per\n // keyframe in the order [a1, a2, ..., an, v1, v2, ... vn, b1, b2, ..., bn],\n // where ai, vi, and bi are the in-tangent, property, and out-tangents of\n // the ith morph target respectively.\n let pointsIndex = targetIndex;\n if (interpolation === InterpolationType.CUBICSPLINE) {\n for (i = 0; i < outputLength; i += 3) {\n output[i] = points[pointsIndex];\n output[i + 1] = points[pointsIndex + count];\n output[i + 2] = points[pointsIndex + 2 * count];\n pointsIndex += count * 3;\n }\n } else {\n for (i = 0; i < outputLength; i++) {\n output[i] = points[pointsIndex];\n pointsIndex += count;\n }\n }\n\n splines.push(createSpline(times, output, interpolation, path));\n }\n } else {\n splines.push(createSpline(times, points, interpolation, path));\n }\n\n return splines;\n}\n\nlet scratchVariable;\n\nfunction initialize(runtimeChannel) {\n const channel = runtimeChannel._channel;\n\n const sampler = channel.sampler;\n const times = sampler.input;\n const points = sampler.output;\n\n const interpolation = sampler.interpolation;\n const target = channel.target;\n const path = target.path;\n\n const runtimeNode = runtimeChannel._runtimeNode;\n const count = defined(runtimeNode.morphWeights)\n ? runtimeNode.morphWeights.length\n : 1;\n const splines = createSplines(times, points, interpolation, path, count);\n\n runtimeChannel._splines = splines;\n runtimeChannel._path = path;\n\n switch (path) {\n case AnimatedPropertyType.TRANSLATION:\n case AnimatedPropertyType.SCALE:\n scratchVariable = new Cartesian3();\n break;\n case AnimatedPropertyType.ROTATION:\n scratchVariable = new Quaternion();\n break;\n case AnimatedPropertyType.WEIGHTS:\n // This is unused when setting a node's morph weights.\n break;\n }\n}\n\n/**\n * Animates the target node property based on its spline.\n *\n * @param {number} time The local animation time.\n *\n * @private\n */\nModelAnimationChannel.prototype.animate = function (time) {\n const splines = this._splines;\n const path = this._path;\n const model = this._runtimeAnimation.model;\n const runtimeNode = this._runtimeNode;\n\n // Weights are handled differently than the other properties because\n // they need to be updated in place.\n if (path === AnimatedPropertyType.WEIGHTS) {\n const morphWeights = runtimeNode.morphWeights;\n const length = morphWeights.length;\n for (let i = 0; i < length; i++) {\n const spline = splines[i];\n const localAnimationTime = model.clampAnimations\n ? spline.clampTime(time)\n : spline.wrapTime(time);\n morphWeights[i] = spline.evaluate(localAnimationTime);\n }\n } else if (runtimeNode.userAnimated) {\n // If the node is being animated externally, ignore the glTF animation.\n return;\n } else {\n const spline = splines[0];\n const localAnimationTime = model.clampAnimations\n ? spline.clampTime(time)\n : spline.wrapTime(time);\n\n // This sets the translate, rotate, and scale properties.\n runtimeNode[path] = spline.evaluate(localAnimationTime, scratchVariable);\n }\n};\n\nexport default ModelAnimationChannel;\n", "import defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Event from \"../../Core/Event.js\";\nimport JulianDate from \"../../Core/JulianDate.js\";\nimport ModelAnimationLoop from \"../ModelAnimationLoop.js\";\nimport ModelAnimationState from \"../ModelAnimationState.js\";\nimport ModelAnimationChannel from \"./ModelAnimationChannel.js\";\n\n/**\n *
\n * Create animations by calling {@link ModelAnimationCollection#add}. Do not call the constructor directly.\n *
\n *\n * An active animation derived from a glTF asset. An active animation is an\n * animation that is either currently playing or scheduled to be played due to\n * being added to a model's {@link ModelAnimationCollection}. An active animation\n * is an instance of an animation; for example, there can be multiple active\n * animations for the same glTF animation, each with a different start time.\n *\n * @alias ModelAnimation\n * @internalConstructor\n * @class\n *\n * @see ModelAnimationCollection#add\n */\nfunction ModelAnimation(model, animation, options) {\n this._animation = animation;\n this._name = animation.name;\n this._runtimeChannels = undefined;\n\n this._startTime = JulianDate.clone(options.startTime);\n this._delay = defaultValue(options.delay, 0.0); // in seconds\n this._stopTime = JulianDate.clone(options.stopTime);\n\n /**\n * When true, the animation is removed after it stops playing.\n * This is slightly more efficient that not removing it, but if, for example,\n * time is reversed, the animation is not played again.\n *\n * @type {boolean}\n * @default false\n */\n this.removeOnStop = defaultValue(options.removeOnStop, false);\n this._multiplier = defaultValue(options.multiplier, 1.0);\n this._reverse = defaultValue(options.reverse, false);\n this._loop = defaultValue(options.loop, ModelAnimationLoop.NONE);\n this._animationTime = options.animationTime;\n this._prevAnimationDelta = undefined;\n\n /**\n * The event fired when this animation is started. This can be used, for\n * example, to play a sound or start a particle system, when the animation starts.\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * animation.start.addEventListener(function(model, animation) {\n * console.log(`Animation started: ${animation.name}`);\n * });\n */\n this.start = new Event();\n\n /**\n * The event fired when on each frame when this animation is updated. The\n * current time of the animation, relative to the glTF animation time span, is\n * passed to the event, which allows, for example, starting new animations at a\n * specific time relative to a playing animation.\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * animation.update.addEventListener(function(model, animation, time) {\n * console.log(`Animation updated: ${animation.name}. glTF animation time: ${time}`);\n * });\n */\n this.update = new Event();\n\n /**\n * The event fired when this animation is stopped. This can be used, for\n * example, to play a sound or start a particle system, when the animation stops.\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * animation.stop.addEventListener(function(model, animation) {\n * console.log(`Animation stopped: ${animation.name}`);\n * });\n */\n this.stop = new Event();\n\n this._state = ModelAnimationState.STOPPED;\n\n // Set during animation update\n this._computedStartTime = undefined;\n this._duration = undefined;\n\n // To avoid allocations in ModelAnimationCollection.update\n const that = this;\n this._raiseStartEvent = function () {\n that.start.raiseEvent(model, that);\n };\n this._updateEventTime = 0.0;\n this._raiseUpdateEvent = function () {\n that.update.raiseEvent(model, that, that._updateEventTime);\n };\n this._raiseStopEvent = function () {\n that.stop.raiseEvent(model, that);\n };\n\n this._model = model;\n\n this._localStartTime = undefined;\n this._localStopTime = undefined;\n\n initialize(this);\n}\n\nObject.defineProperties(ModelAnimation.prototype, {\n /**\n * The glTF animation.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {ModelComponents.Animation}\n * @readonly\n *\n * @private\n */\n animation: {\n get: function () {\n return this._animation;\n },\n },\n\n /**\n * The name that identifies this animation in the model, if it exists.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The runtime animation channels for this animation.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {ModelAnimationChannel[]}\n * @readonly\n *\n * @private\n */\n runtimeChannels: {\n get: function () {\n return this._runtimeChannels;\n },\n },\n\n /**\n * The {@link Model} that owns this animation.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {Model}\n * @readonly\n *\n * @private\n */\n model: {\n get: function () {\n return this._model;\n },\n },\n\n /**\n * The starting point of the animation in local animation time. This is the minimum\n * time value across all of the keyframes belonging to this animation.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n localStartTime: {\n get: function () {\n return this._localStartTime;\n },\n },\n\n /**\n * The stopping point of the animation in local animation time. This is the maximum\n * time value across all of the keyframes belonging to this animation.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n localStopTime: {\n get: function () {\n return this._localStopTime;\n },\n },\n\n /**\n * The scene time to start playing this animation. When this is undefined,\n * the animation starts at the next frame.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {JulianDate}\n * @readonly\n *\n * @default undefined\n */\n startTime: {\n get: function () {\n return this._startTime;\n },\n },\n\n /**\n * The delay, in seconds, from {@link ModelAnimation#startTime} to start playing.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default undefined\n */\n delay: {\n get: function () {\n return this._delay;\n },\n },\n\n /**\n * The scene time to stop playing this animation. When this is undefined,\n * the animation is played for its full duration and perhaps repeated depending on\n * {@link ModelAnimation#loop}.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {JulianDate}\n * @readonly\n *\n * @default undefined\n */\n stopTime: {\n get: function () {\n return this._stopTime;\n },\n },\n\n /**\n * Values greater than 1.0 increase the speed that the animation is played relative\n * to the scene clock speed; values less than 1.0 decrease the speed. A value of\n * 1.0 plays the animation at the speed in the glTF animation mapped to the scene\n * clock speed. For example, if the scene is played at 2x real-time, a two-second glTF animation\n * will play in one second even if multiplier is 1.0.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {number}\n * @readonly\n *\n * @default 1.0\n */\n multiplier: {\n get: function () {\n return this._multiplier;\n },\n },\n\n /**\n * When true, the animation is played in reverse.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n reverse: {\n get: function () {\n return this._reverse;\n },\n },\n\n /**\n * Determines if and how the animation is looped.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {ModelAnimationLoop}\n * @readonly\n *\n * @default {@link ModelAnimationLoop.NONE}\n */\n loop: {\n get: function () {\n return this._loop;\n },\n },\n\n /**\n * If this is defined, it will be used to compute the local animation time\n * instead of the scene's time.\n *\n * @memberof ModelAnimation.prototype\n *\n * @type {ModelAnimation.AnimationTimeCallback}\n * @default undefined\n */\n animationTime: {\n get: function () {\n return this._animationTime;\n },\n },\n});\n\nfunction initialize(runtimeAnimation) {\n let localStartTime = Number.MAX_VALUE;\n let localStopTime = -Number.MAX_VALUE;\n\n const sceneGraph = runtimeAnimation._model.sceneGraph;\n const animation = runtimeAnimation._animation;\n const channels = animation.channels;\n const length = channels.length;\n\n const runtimeChannels = [];\n for (let i = 0; i < length; i++) {\n const channel = channels[i];\n const target = channel.target;\n\n // Ignore this channel if the target is invalid, i.e. if the node\n // it references doesn't exist.\n if (!defined(target)) {\n continue;\n }\n\n const nodeIndex = target.node.index;\n const runtimeNode = sceneGraph._runtimeNodes[nodeIndex];\n\n const runtimeChannel = new ModelAnimationChannel({\n channel: channel,\n runtimeAnimation: runtimeAnimation,\n runtimeNode: runtimeNode,\n });\n\n const times = channel.sampler.input;\n localStartTime = Math.min(localStartTime, times[0]);\n localStopTime = Math.max(localStopTime, times[times.length - 1]);\n\n runtimeChannels.push(runtimeChannel);\n }\n\n runtimeAnimation._runtimeChannels = runtimeChannels;\n runtimeAnimation._localStartTime = localStartTime;\n runtimeAnimation._localStopTime = localStopTime;\n}\n\n/**\n * Evaluate all animation channels to advance this animation.\n *\n * @param {number} time The local animation time.\n *\n * @private\n */\nModelAnimation.prototype.animate = function (time) {\n const runtimeChannels = this._runtimeChannels;\n const length = runtimeChannels.length;\n for (let i = 0; i < length; i++) {\n runtimeChannels[i].animate(time);\n }\n};\n\n/**\n * A function used to compute the local animation time for a ModelAnimation.\n * @callback ModelAnimation.AnimationTimeCallback\n *\n * @param {number} duration The animation's original duration in seconds.\n * @param {number} seconds The seconds since the animation started, in scene time.\n * @returns {number} Returns the local animation time.\n *\n * @example\n * // Use real time for model animation (assuming animateWhilePaused was set to true)\n * function animationTime(duration) {\n * return Date.now() / 1000 / duration;\n * }\n *\n * @example\n * // Offset the phase of the animation, so it starts halfway through its cycle.\n * function animationTime(duration, seconds) {\n * return seconds / duration + 0.5;\n * }\n */\nexport default ModelAnimation;\n", "import defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport Event from \"../../Core/Event.js\";\nimport JulianDate from \"../../Core/JulianDate.js\";\nimport CesiumMath from \"../../Core/Math.js\";\nimport ModelAnimation from \"./ModelAnimation.js\";\nimport ModelAnimationLoop from \".././ModelAnimationLoop.js\";\nimport ModelAnimationState from \".././ModelAnimationState.js\";\n\n/**\n *
\n * Access a model's animations {@link Model#activeAnimations}. Do not call the constructor directly\n *
\n *\n * A collection of active model animations.\n *\n * @alias ModelAnimationCollection\n * @internalConstructor\n * @class\n *\n * @see Model#activeAnimations\n */\nfunction ModelAnimationCollection(model) {\n /**\n * The event fired when an animation is added to the collection. This can be used, for\n * example, to keep a UI in sync.\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * model.activeAnimations.animationAdded.addEventListener(function(model, animation) {\n * console.log(`Animation added: ${animation.name}`);\n * });\n */\n this.animationAdded = new Event();\n\n /**\n * The event fired when an animation is removed from the collection. This can be used, for\n * example, to keep a UI in sync.\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * model.activeAnimations.animationRemoved.addEventListener(function(model, animation) {\n * console.log(`Animation removed: ${animation.name}`);\n * });\n */\n this.animationRemoved = new Event();\n\n /**\n * When true, the animation will play even when the scene time is paused. However,\n * whether animation takes place will depend on the animationTime functions assigned\n * to the model's animations. By default, this is based on scene time, so models using\n * the default will not animate regardless of this setting.\n *\n * @type {boolean}\n * @default false\n */\n this.animateWhilePaused = false;\n\n this._model = model;\n this._runtimeAnimations = [];\n this._previousTime = undefined;\n}\n\nObject.defineProperties(ModelAnimationCollection.prototype, {\n /**\n * The number of animations in the collection.\n *\n * @memberof ModelAnimationCollection.prototype\n *\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._runtimeAnimations.length;\n },\n },\n\n /**\n * The model that owns this animation collection.\n *\n * @memberof ModelAnimationCollection.prototype\n *\n * @type {Model}\n * @readonly\n */\n model: {\n get: function () {\n return this._model;\n },\n },\n});\n\nfunction addAnimation(collection, animation, options) {\n const model = collection._model;\n const runtimeAnimation = new ModelAnimation(model, animation, options);\n collection._runtimeAnimations.push(runtimeAnimation);\n collection.animationAdded.raiseEvent(model, runtimeAnimation);\n return runtimeAnimation;\n}\n\n/**\n * Creates and adds an animation with the specified initial properties to the collection.\n *

\n * This raises the {@link ModelAnimationCollection#animationAdded} event so, for example, a UI can stay in sync.\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} [options.name] The glTF animation name that identifies the animation. Must be defined if options.index is undefined.\n * @param {number} [options.index] The glTF animation index that identifies the animation. Must be defined if options.name is undefined.\n * @param {JulianDate} [options.startTime] The scene time to start playing the animation. When this is undefined, the animation starts at the next frame.\n * @param {number} [options.delay=0.0] The delay, in seconds, from startTime to start playing. This will only affect the animation if options.loop is ModelAnimationLoop.NONE.\n * @param {JulianDate} [options.stopTime] The scene time to stop playing the animation. When this is undefined, the animation is played for its full duration.\n * @param {boolean} [options.removeOnStop=false] When true, the animation is removed after it stops playing. This will only affect the animation if options.loop is ModelAnimationLoop.NONE.\n * @param {number} [options.multiplier=1.0] Values greater than 1.0 increase the speed that the animation is played relative to the scene clock speed; values less than 1.0 decrease the speed.\n * @param {boolean} [options.reverse=false] When true, the animation is played in reverse.\n * @param {ModelAnimationLoop} [options.loop=ModelAnimationLoop.NONE] Determines if and how the animation is looped.\n * @param {ModelAnimation.AnimationTimeCallback} [options.animationTime=undefined] If defined, computes the local animation time for this animation.\n * @returns {ModelAnimation} The animation that was added to the collection.\n *\n * @exception {DeveloperError} Animations are not loaded. Wait for the {@link Model#ready} to return trues.\n * @exception {DeveloperError} options.name must be a valid animation name.\n * @exception {DeveloperError} options.index must be a valid animation index.\n * @exception {DeveloperError} Either options.name or options.index must be defined.\n * @exception {DeveloperError} options.multiplier must be greater than zero.\n *\n * @example\n * // Example 1. Add an animation by name\n * model.activeAnimations.add({\n * name : 'animation name'\n * });\n *\n * @example\n * // Example 2. Add an animation by index\n * model.activeAnimations.add({\n * index : 0\n * });\n *\n * @example\n * // Example 3. Add an animation and provide all properties and events\n * const startTime = Cesium.JulianDate.now();\n *\n * const animation = model.activeAnimations.add({\n * name : 'another animation name',\n * startTime : startTime,\n * delay : 0.0, // Play at startTime (default)\n * stopTime : Cesium.JulianDate.addSeconds(startTime, 4.0, new Cesium.JulianDate()),\n * removeOnStop : false, // Do not remove when animation stops (default)\n * multiplier : 2.0, // Play at double speed\n * reverse : true, // Play in reverse\n * loop : Cesium.ModelAnimationLoop.REPEAT // Loop the animation\n * });\n *\n * animation.start.addEventListener(function(model, animation) {\n * console.log(`Animation started: ${animation.name}`);\n * });\n * animation.update.addEventListener(function(model, animation, time) {\n * console.log(`Animation updated: ${animation.name}. glTF animation time: ${time}`);\n * });\n * animation.stop.addEventListener(function(model, animation) {\n * console.log(`Animation stopped: ${animation.name}`);\n * });\n */\nModelAnimationCollection.prototype.add = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const model = this._model;\n\n //>>includeStart('debug', pragmas.debug);\n if (!model.ready) {\n throw new DeveloperError(\n \"Animations are not loaded. Wait for Model.ready to be true.\"\n );\n }\n //>>includeEnd('debug');\n\n const animations = model.sceneGraph.components.animations;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.name) && !defined(options.index)) {\n throw new DeveloperError(\n \"Either options.name or options.index must be defined.\"\n );\n }\n\n if (defined(options.multiplier) && options.multiplier <= 0.0) {\n throw new DeveloperError(\"options.multiplier must be greater than zero.\");\n }\n\n if (\n defined(options.index) &&\n (options.index >= animations.length || options.index < 0)\n ) {\n throw new DeveloperError(\"options.index must be a valid animation index.\");\n }\n //>>includeEnd('debug');\n\n let index = options.index;\n if (defined(index)) {\n return addAnimation(this, animations[index], options);\n }\n\n // Find the index of the animation with the given name\n const length = animations.length;\n for (let i = 0; i < length; ++i) {\n if (animations[i].name === options.name) {\n index = i;\n break;\n }\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"options.name must be a valid animation name.\");\n }\n //>>includeEnd('debug');\n\n return addAnimation(this, animations[index], options);\n};\n\n/**\n * Creates and adds animations with the specified initial properties to the collection\n * for all animations in the model.\n *

\n * This raises the {@link ModelAnimationCollection#animationAdded} event for each model so, for example, a UI can stay in sync.\n *

\n *\n * @param {object} [options] Object with the following properties:\n * @param {JulianDate} [options.startTime] The scene time to start playing the animations. When this is undefined, the animations starts at the next frame.\n * @param {number} [options.delay=0.0] The delay, in seconds, from startTime to start playing. This will only affect the animation if options.loop is ModelAnimationLoop.NONE.\n * @param {JulianDate} [options.stopTime] The scene time to stop playing the animations. When this is undefined, the animations are played for its full duration.\n * @param {boolean} [options.removeOnStop=false] When true, the animations are removed after they stop playing. This will only affect the animation if options.loop is ModelAnimationLoop.NONE.\n * @param {number} [options.multiplier=1.0] Values greater than 1.0 increase the speed that the animations play relative to the scene clock speed; values less than 1.0 decrease the speed.\n * @param {boolean} [options.reverse=false] When true, the animations are played in reverse.\n * @param {ModelAnimationLoop} [options.loop=ModelAnimationLoop.NONE] Determines if and how the animations are looped.\n * @param {ModelAnimation.AnimationTimeCallback} [options.animationTime=undefined] If defined, computes the local animation time for all of the animations.\n * @returns {ModelAnimation[]} An array of {@link ModelAnimation} objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.\n *\n * @exception {DeveloperError} Animations are not loaded. Wait for the {@link Model#ready} to return true.\n * @exception {DeveloperError} options.multiplier must be greater than zero.\n *\n * @example\n * model.activeAnimations.addAll({\n * multiplier : 0.5, // Play at half-speed\n * loop : Cesium.ModelAnimationLoop.REPEAT // Loop the animations\n * });\n */\nModelAnimationCollection.prototype.addAll = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const model = this._model;\n\n //>>includeStart('debug', pragmas.debug);\n if (!model.ready) {\n throw new DeveloperError(\n \"Animations are not loaded. Wait for Model.ready to be true.\"\n );\n }\n\n if (defined(options.multiplier) && options.multiplier <= 0.0) {\n throw new DeveloperError(\"options.multiplier must be greater than zero.\");\n }\n //>>includeEnd('debug');\n\n const animations = model.sceneGraph.components.animations;\n\n const addedAnimations = [];\n const length = animations.length;\n for (let i = 0; i < length; ++i) {\n const animation = addAnimation(this, animations[i], options);\n addedAnimations.push(animation);\n }\n return addedAnimations;\n};\n\n/**\n * Removes an animation from the collection.\n *

\n * This raises the {@link ModelAnimationCollection#animationRemoved} event so, for example, a UI can stay in sync.\n *

\n *

\n * An animation can also be implicitly removed from the collection by setting {@link ModelAnimationCollection#removeOnStop} to\n * true. The {@link ModelAnimationCollection#animationRemoved} event is still fired when the animation is removed.\n *

\n *\n * @param {ModelAnimation} runtimeAnimation The runtime animation to remove.\n * @returns {boolean} true if the animation was removed; false if the animation was not found in the collection.\n *\n * @example\n * const a = model.activeAnimations.add({\n * name : 'animation name'\n * });\n * model.activeAnimations.remove(a); // Returns true\n */\nModelAnimationCollection.prototype.remove = function (runtimeAnimation) {\n if (!defined(runtimeAnimation)) {\n return false;\n }\n\n const animations = this._runtimeAnimations;\n const i = animations.indexOf(runtimeAnimation);\n if (i !== -1) {\n animations.splice(i, 1);\n this.animationRemoved.raiseEvent(this._model, runtimeAnimation);\n return true;\n }\n\n return false;\n};\n\n/**\n * Removes all animations from the collection.\n *

\n * This raises the {@link ModelAnimationCollection#animationRemoved} event for each\n * animation so, for example, a UI can stay in sync.\n *

\n */\nModelAnimationCollection.prototype.removeAll = function () {\n const model = this._model;\n const animations = this._runtimeAnimations;\n const length = animations.length;\n\n this._runtimeAnimations.length = 0;\n\n for (let i = 0; i < length; ++i) {\n this.animationRemoved.raiseEvent(model, animations[i]);\n }\n};\n\n/**\n * Determines whether this collection contains a given animation.\n *\n * @param {ModelAnimation} runtimeAnimation The runtime animation to check for.\n * @returns {boolean} true if this collection contains the animation, false otherwise.\n */\nModelAnimationCollection.prototype.contains = function (runtimeAnimation) {\n if (defined(runtimeAnimation)) {\n return this._runtimeAnimations.indexOf(runtimeAnimation) !== -1;\n }\n\n return false;\n};\n\n/**\n * Returns the animation in the collection at the specified index. Indices are zero-based\n * and increase as animations are added. Removing an animation shifts all animations after\n * it to the left, changing their indices. This function is commonly used to iterate over\n * all the animations in the collection.\n *\n * @param {number} index The zero-based index of the animation.\n * @returns {ModelAnimation} The runtime animation at the specified index.\n *\n * @example\n * // Output the names of all the animations in the collection.\n * const animations = model.activeAnimations;\n * const length = animations.length;\n * for (let i = 0; i < length; ++i) {\n * console.log(animations.get(i).name);\n * }\n */\nModelAnimationCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n\n if (index >= this._runtimeAnimations.length || index < 0) {\n throw new DeveloperError(\n \"index must be valid within the range of the collection\"\n );\n }\n //>>includeEnd('debug');\n\n return this._runtimeAnimations[index];\n};\n\nconst animationsToRemove = [];\n\nfunction createAnimationRemovedFunction(\n modelAnimationCollection,\n model,\n animation\n) {\n return function () {\n modelAnimationCollection.animationRemoved.raiseEvent(model, animation);\n };\n}\n\n/**\n * Updates the runtime animations in this collection, removing any animations\n * that have stopped.\n *\n * @param {FrameState} frameState The current frame state.\n * @returns {boolean} true if an animation played during this update, false otherwise.\n *\n * @private\n */\nModelAnimationCollection.prototype.update = function (frameState) {\n const runtimeAnimations = this._runtimeAnimations;\n let length = runtimeAnimations.length;\n\n if (length === 0) {\n this._previousTime = undefined;\n return false;\n }\n\n if (\n !this.animateWhilePaused &&\n JulianDate.equals(frameState.time, this._previousTime)\n ) {\n return false;\n }\n this._previousTime = JulianDate.clone(frameState.time, this._previousTime);\n\n let animationOccurred = false;\n const sceneTime = frameState.time;\n const model = this._model;\n\n for (let i = 0; i < length; ++i) {\n const runtimeAnimation = runtimeAnimations[i];\n\n if (!defined(runtimeAnimation._computedStartTime)) {\n runtimeAnimation._computedStartTime = JulianDate.addSeconds(\n defaultValue(runtimeAnimation.startTime, sceneTime),\n runtimeAnimation.delay,\n new JulianDate()\n );\n }\n\n if (!defined(runtimeAnimation._duration)) {\n runtimeAnimation._duration =\n runtimeAnimation.localStopTime * (1.0 / runtimeAnimation.multiplier);\n }\n\n const startTime = runtimeAnimation._computedStartTime;\n const duration = runtimeAnimation._duration;\n const stopTime = runtimeAnimation.stopTime;\n\n const pastStartTime = JulianDate.lessThanOrEquals(startTime, sceneTime);\n const reachedStopTime =\n defined(stopTime) && JulianDate.greaterThan(sceneTime, stopTime);\n\n // [0.0, 1.0] normalized local animation time\n let delta = 0.0;\n if (duration !== 0.0) {\n const seconds = JulianDate.secondsDifference(\n reachedStopTime ? stopTime : sceneTime,\n startTime\n );\n delta = defined(runtimeAnimation._animationTime)\n ? runtimeAnimation._animationTime(duration, seconds)\n : seconds / duration;\n }\n\n // Play animation if\n // * we are after the start time or the animation is being repeated, and\n // * before the end of the animation's duration or the animation is being repeated, and\n // * we did not reach a user-provided stop time.\n\n const repeat =\n runtimeAnimation.loop === ModelAnimationLoop.REPEAT ||\n runtimeAnimation.loop === ModelAnimationLoop.MIRRORED_REPEAT;\n\n const play =\n (pastStartTime || (repeat && !defined(runtimeAnimation.startTime))) &&\n (delta <= 1.0 || repeat) &&\n !reachedStopTime;\n\n if (delta === runtimeAnimation._prevAnimationDelta) {\n const animationStopped =\n runtimeAnimation._state === ModelAnimationState.STOPPED;\n // no change to delta, and no change to the animation state means we can\n // skip the update this time around.\n if (play !== animationStopped) {\n continue;\n }\n }\n runtimeAnimation._prevAnimationDelta = delta;\n\n // If it IS, or WAS, animating...\n if (play || runtimeAnimation._state === ModelAnimationState.ANIMATING) {\n // ...transition from STOPPED to ANIMATING\n if (play && runtimeAnimation._state === ModelAnimationState.STOPPED) {\n runtimeAnimation._state = ModelAnimationState.ANIMATING;\n if (runtimeAnimation.start.numberOfListeners > 0) {\n frameState.afterRender.push(runtimeAnimation._raiseStartEvent);\n }\n }\n\n // Truncate to [0.0, 1.0] for repeating animations\n if (runtimeAnimation.loop === ModelAnimationLoop.REPEAT) {\n delta = delta - Math.floor(delta);\n } else if (runtimeAnimation.loop === ModelAnimationLoop.MIRRORED_REPEAT) {\n const floor = Math.floor(delta);\n const fract = delta - floor;\n // When odd use (1.0 - fract) to mirror repeat\n delta = floor % 2 === 1.0 ? 1.0 - fract : fract;\n }\n\n if (runtimeAnimation.reverse) {\n delta = 1.0 - delta;\n }\n\n let localAnimationTime = delta * duration * runtimeAnimation.multiplier;\n // Clamp in case floating-point roundoff goes outside the animation's first or last keyframe\n localAnimationTime = CesiumMath.clamp(\n localAnimationTime,\n runtimeAnimation.localStartTime,\n runtimeAnimation.localStopTime\n );\n\n runtimeAnimation.animate(localAnimationTime);\n\n if (runtimeAnimation.update.numberOfListeners > 0) {\n runtimeAnimation._updateEventTime = localAnimationTime;\n frameState.afterRender.push(runtimeAnimation._raiseUpdateEvent);\n }\n animationOccurred = true;\n\n if (!play) {\n // transition from ANIMATING to STOPPED\n runtimeAnimation._state = ModelAnimationState.STOPPED;\n if (runtimeAnimation.stop.numberOfListeners > 0) {\n frameState.afterRender.push(runtimeAnimation._raiseStopEvent);\n }\n\n if (runtimeAnimation.removeOnStop) {\n animationsToRemove.push(runtimeAnimation);\n }\n }\n }\n }\n\n // Remove animations that stopped\n length = animationsToRemove.length;\n for (let j = 0; j < length; ++j) {\n const animationToRemove = animationsToRemove[j];\n runtimeAnimations.splice(runtimeAnimations.indexOf(animationToRemove), 1);\n frameState.afterRender.push(\n createAnimationRemovedFunction(this, model, animationToRemove)\n );\n }\n animationsToRemove.length = 0;\n\n return animationOccurred;\n};\n\nexport default ModelAnimationCollection;\n", "import Color from \"../../Core/Color.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n * A feature of a {@link Model}.\n *

\n * Provides access to a feature's properties stored in the model's feature table.\n *

\n *

\n * Modifications to a ModelFeature object have the lifetime of the model.\n *

\n *

\n * Do not construct this directly. Access it through picking using {@link Scene#pick}.\n *

\n *\n * @alias ModelFeature\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Model} options.model The model the feature belongs to.\n * @param {number} options.featureId The unique integral identifier for this feature.\n *\n * @example\n * // On mouse over, display all the properties for a feature in the console log.\n * handler.setInputAction(function(movement) {\n * const feature = scene.pick(movement.endPosition);\n * if (feature instanceof Cesium.ModelFeature) {\n * console.log(feature);\n * }\n * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);\n *\n */\nfunction ModelFeature(options) {\n this._model = options.model;\n\n // This ModelFeatureTable is not documented as an option since it is\n // part of the private API and should not appear in the documentation.\n this._featureTable = options.featureTable;\n\n this._featureId = options.featureId;\n this._color = undefined; // for calling getColor\n}\n\nObject.defineProperties(ModelFeature.prototype, {\n /**\n * Gets or sets if the feature will be shown. This is set for all features\n * when a style's show is evaluated.\n *\n * @memberof ModelFeature.prototype\n *\n * @type {boolean}\n *\n * @default true\n */\n show: {\n get: function () {\n return this._featureTable.getShow(this._featureId);\n },\n set: function (value) {\n this._featureTable.setShow(this._featureId, value);\n },\n },\n\n /**\n * Gets or sets the highlight color multiplied with the feature's color. When\n * this is white, the feature's color is not changed. This is set for all features\n * when a style's color is evaluated.\n *\n * @memberof ModelFeature.prototype\n *\n * @type {Color}\n *\n * @default {@link Color.WHITE}\n */\n color: {\n get: function () {\n if (!defined(this._color)) {\n this._color = new Color();\n }\n return this._featureTable.getColor(this._featureId, this._color);\n },\n set: function (value) {\n this._featureTable.setColor(this._featureId, value);\n },\n },\n /**\n * All objects returned by {@link Scene#pick} have a primitive property. This returns\n * the model containing the feature.\n *\n * @memberof ModelFeature.prototype\n *\n * @type {Model}\n *\n * @readonly\n * @private\n */\n primitive: {\n get: function () {\n return this._model;\n },\n },\n\n /**\n * The {@link ModelFeatureTable} that this feature belongs to.\n *\n * @memberof ModelFeature.prototype\n *\n * @type {ModelFeatureTable}\n *\n * @readonly\n * @private\n */\n featureTable: {\n get: function () {\n return this._featureTable;\n },\n },\n\n /**\n * Get the feature ID associated with this feature. For 3D Tiles 1.0, the\n * batch ID is returned. For EXT_mesh_features, this is the feature ID from\n * the selected feature ID set.\n *\n * @memberof ModelFeature.prototype\n *\n * @type {number}\n *\n * @readonly\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n featureId: {\n get: function () {\n return this._featureId;\n },\n },\n});\n\n/**\n * Returns whether the feature contains this property.\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {boolean} Whether the feature contains this property.\n */\nModelFeature.prototype.hasProperty = function (name) {\n return this._featureTable.hasProperty(this._featureId, name);\n};\n\n/**\n * Returns a copy of the value of the feature's property with the given name.\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n *\n * @example\n * // Display all the properties for a feature in the console log.\n * const propertyIds = feature.getPropertyIds();\n * const length = propertyIds.length;\n * for (let i = 0; i < length; ++i) {\n * const propertyId = propertyIds[i];\n * console.log(propertyId + ': ' + feature.getProperty(propertyId));\n * }\n */\nModelFeature.prototype.getProperty = function (name) {\n return this._featureTable.getProperty(this._featureId, name);\n};\n\n/**\n * Returns a copy of the feature's property with the given name, examining all\n * the metadata from the EXT_structural_metadata and legacy EXT_feature_metadata glTF\n * extensions. Metadata is checked against name from most specific to most\n * general and the first match is returned. Metadata is checked in this order:\n *
    \n *
  1. structural metadata property by semantic
  2. \n *
  3. structural metadata property by property ID
  4. \n *
\n *

\n * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the\n * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.\n *

\n *\n * @param {string} name The semantic or property ID of the feature. Semantics are checked before property IDs in each granularity of metadata.\n * @return {*} The value of the property or undefined if the feature does not have this property.\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nModelFeature.prototype.getPropertyInherited = function (name) {\n if (this._featureTable.hasPropertyBySemantic(this._featureId, name)) {\n return this._featureTable.getPropertyBySemantic(this._featureId, name);\n }\n\n return this._featureTable.getProperty(this._featureId, name);\n};\n\n/**\n * Returns an array of property IDs for the feature.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The IDs of the feature's properties.\n */\nModelFeature.prototype.getPropertyIds = function (results) {\n return this._featureTable.getPropertyIds(results);\n};\n\n/**\n * Sets the value of the feature's property with the given name.\n *\n * @param {string} name The case-sensitive name of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n *\n * @exception {DeveloperError} Inherited batch table hierarchy property is read only.\n *\n * @example\n * const height = feature.getProperty('Height'); // e.g., the height of a building\n *\n * @example\n * const name = 'clicked';\n * if (feature.getProperty(name)) {\n * console.log('already clicked');\n * } else {\n * feature.setProperty(name, true);\n * console.log('first click');\n * }\n */\nModelFeature.prototype.setProperty = function (name, value) {\n return this._featureTable.setProperty(this._featureId, name, value);\n};\n\nexport default ModelFeature;\n", "/**\n * An enum describing what commands (opaque or translucent) are required by\n * a {@link Cesium3DTileStyle}.\n *\n * @enum {number}\n * @private\n */\nconst StyleCommandsNeeded = {\n ALL_OPAQUE: 0,\n ALL_TRANSLUCENT: 1,\n OPAQUE_AND_TRANSLUCENT: 2,\n};\n\n/**\n * @private\n */\nStyleCommandsNeeded.getStyleCommandsNeeded = function (\n featuresLength,\n translucentFeaturesLength\n) {\n if (translucentFeaturesLength === 0) {\n return StyleCommandsNeeded.ALL_OPAQUE;\n } else if (translucentFeaturesLength === featuresLength) {\n return StyleCommandsNeeded.ALL_TRANSLUCENT;\n }\n return StyleCommandsNeeded.OPAQUE_AND_TRANSLUCENT;\n};\n\nexport default Object.freeze(StyleCommandsNeeded);\n", "import Check from \"../../Core/Check.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\n\n/**\n * An enum to distinguish the different uses for {@link Model},\n * which include individual glTF models, and various 3D Tiles formats\n * (including glTF via 3DTILES_content_gltf).\n *\n * @enum {string}\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst ModelType = {\n /**\n * An individual glTF model.\n *

\n * Not to be confused with {@link ModelType.TILE_GLTF}\n * which is for 3D Tiles\n *

\n *\n * @type {string}\n * @constant\n */\n GLTF: \"GLTF\",\n /**\n * A glTF model used as tile content in a 3D Tileset via\n * 3DTILES_content_gltf.\n *

\n * Not to be confused with {@link ModelType.GLTF}\n * which is for individual models\n *

\n *\n * @type {string}\n * @constant\n */\n TILE_GLTF: \"TILE_GLTF\",\n /**\n * A 3D Tiles 1.0 Batched 3D Model\n *\n * @type {string}\n * @constant\n */\n TILE_B3DM: \"B3DM\",\n /**\n * A 3D Tiles 1.0 Instanced 3D Model\n *\n * @type {string}\n * @constant\n */\n TILE_I3DM: \"I3DM\",\n /**\n * A 3D Tiles 1.0 Point Cloud\n *\n * @type {string}\n * @constant\n */\n TILE_PNTS: \"PNTS\",\n\n /**\n * GeoJSON content for MAXAR_content_geojson extension\n *\n * @type {string}\n * @constant\n */\n TILE_GEOJSON: \"TILE_GEOJSON\",\n};\n\n/**\n * Check if a model is used for 3D Tiles.\n * @param {ModelType} modelType The type of model\n * @returns {boolean} true if the model is a 3D Tiles format, false otherwise\n */\nModelType.is3DTiles = function (modelType) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"modelType\", modelType);\n //>>includeEnd('debug');\n\n switch (modelType) {\n case ModelType.TILE_GLTF:\n case ModelType.TILE_B3DM:\n case ModelType.TILE_I3DM:\n case ModelType.TILE_PNTS:\n case ModelType.TILE_GEOJSON:\n return true;\n case ModelType.GLTF:\n return false;\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"modelType is not a valid value.\");\n //>>includeEnd('debug');\n }\n};\n\nexport default Object.freeze(ModelType);\n", "import BatchTexture from \"../BatchTexture.js\";\nimport Cesium3DTileFeature from \"../Cesium3DTileFeature.js\";\nimport Check from \"../../Core/Check.js\";\nimport Color from \"../../Core/Color.js\";\nimport defined from \"../../Core/defined.js\";\nimport destroyObject from \"../../Core/destroyObject.js\";\nimport ModelFeature from \"./ModelFeature.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport StyleCommandsNeeded from \"./StyleCommandsNeeded.js\";\nimport ModelType from \"./ModelType.js\";\n\n/**\n * Manages the {@link ModelFeature}s in a {@link Model}.\n * Extracts the properties from a {@link PropertyTable}.\n *\n * @param {object} options An object containing the following options:\n * @param {Model} options.model The model that owns this feature table.\n * @param {PropertyTable} options.propertyTable The property table from the model used to initialize the model.\n *\n * @alias ModelFeatureTable\n * @constructor\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ModelFeatureTable(options) {\n const model = options.model;\n const propertyTable = options.propertyTable;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"propertyTable\", propertyTable);\n Check.typeOf.object(\"model\", model);\n //>>includeEnd('debug');\n\n this._propertyTable = propertyTable;\n this._model = model;\n\n this._features = undefined;\n this._featuresLength = 0;\n\n this._batchTexture = undefined;\n\n this._styleCommandsNeededDirty = false;\n this._styleCommandsNeeded = StyleCommandsNeeded.ALL_OPAQUE;\n\n initialize(this);\n}\n\nObject.defineProperties(ModelFeatureTable.prototype, {\n /**\n * The batch texture created for the features in this table.\n *\n * @memberof ModelFeatureTable.prototype\n *\n * @type {BatchTexture}\n * @readonly\n *\n * @private\n */\n batchTexture: {\n get: function () {\n return this._batchTexture;\n },\n },\n\n /**\n * The number of features in this table.\n *\n * @memberof ModelFeatureTable.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n featuresLength: {\n get: function () {\n return this._featuresLength;\n },\n },\n\n /**\n * Size of the batch texture. This does not count the property table size\n * as that is counted separately through StructuralMetadata.\n *\n * @memberof ModelFeatureTable.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n batchTextureByteLength: {\n get: function () {\n if (defined(this._batchTexture)) {\n return this._batchTexture.byteLength;\n }\n\n return 0;\n },\n },\n\n /**\n * A flag to indicate whether or not the types of style commands needed by this feature table have changed.\n *\n * @memberof ModelFeatureTable.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n styleCommandsNeededDirty: {\n get: function () {\n return this._styleCommandsNeededDirty;\n },\n },\n});\n\nfunction initialize(modelFeatureTable) {\n const model = modelFeatureTable._model;\n const is3DTiles = ModelType.is3DTiles(model.type);\n\n const featuresLength = modelFeatureTable._propertyTable.count;\n if (featuresLength === 0) {\n return;\n }\n\n let i;\n const features = new Array(featuresLength);\n if (is3DTiles) {\n const content = model.content;\n for (i = 0; i < featuresLength; i++) {\n features[i] = new Cesium3DTileFeature(content, i);\n }\n } else {\n for (i = 0; i < featuresLength; i++) {\n features[i] = new ModelFeature({\n model: model,\n featureId: i,\n featureTable: modelFeatureTable,\n });\n }\n }\n\n modelFeatureTable._features = features;\n modelFeatureTable._featuresLength = featuresLength;\n\n modelFeatureTable._batchTexture = new BatchTexture({\n featuresLength: featuresLength,\n owner: modelFeatureTable,\n statistics: is3DTiles ? model.content.tileset.statistics : undefined,\n });\n}\n\n/**\n * Creates/updates the batch texture.\n *\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nModelFeatureTable.prototype.update = function (frameState) {\n // Assume the number of translucent features has not changed.\n this._styleCommandsNeededDirty = false;\n this._batchTexture.update(undefined, frameState);\n\n const currentStyleCommandsNeeded = StyleCommandsNeeded.getStyleCommandsNeeded(\n this._featuresLength,\n this._batchTexture.translucentFeaturesLength\n );\n\n if (this._styleCommandsNeeded !== currentStyleCommandsNeeded) {\n this._styleCommandsNeededDirty = true;\n this._styleCommandsNeeded = currentStyleCommandsNeeded;\n }\n};\n\nModelFeatureTable.prototype.setShow = function (featureId, show) {\n this._batchTexture.setShow(featureId, show);\n};\n\nModelFeatureTable.prototype.setAllShow = function (show) {\n this._batchTexture.setAllShow(show);\n};\n\nModelFeatureTable.prototype.getShow = function (featureId) {\n return this._batchTexture.getShow(featureId);\n};\n\nModelFeatureTable.prototype.setColor = function (featureId, color) {\n this._batchTexture.setColor(featureId, color);\n};\n\nModelFeatureTable.prototype.setAllColor = function (color) {\n this._batchTexture.setAllColor(color);\n};\n\nModelFeatureTable.prototype.getColor = function (featureId, result) {\n return this._batchTexture.getColor(featureId, result);\n};\n\nModelFeatureTable.prototype.getPickColor = function (featureId) {\n return this._batchTexture.getPickColor(featureId);\n};\n\nModelFeatureTable.prototype.getFeature = function (featureId) {\n return this._features[featureId];\n};\n\nModelFeatureTable.prototype.hasProperty = function (featureId, propertyName) {\n return this._propertyTable.hasProperty(featureId, propertyName);\n};\n\nModelFeatureTable.prototype.hasPropertyBySemantic = function (\n featureId,\n propertyName\n) {\n return this._propertyTable.hasPropertyBySemantic(featureId, propertyName);\n};\n\nModelFeatureTable.prototype.getProperty = function (featureId, name) {\n return this._propertyTable.getProperty(featureId, name);\n};\n\nModelFeatureTable.prototype.getPropertyBySemantic = function (\n featureId,\n semantic\n) {\n return this._propertyTable.getPropertyBySemantic(featureId, semantic);\n};\n\nModelFeatureTable.prototype.getPropertyIds = function (results) {\n return this._propertyTable.getPropertyIds(results);\n};\n\nModelFeatureTable.prototype.setProperty = function (featureId, name, value) {\n return this._propertyTable.setProperty(featureId, name, value);\n};\n\nModelFeatureTable.prototype.isClass = function (featureId, className) {\n return this._propertyTable.isClass(featureId, className);\n};\n\nModelFeatureTable.prototype.isExactClass = function (featureId, className) {\n return this._propertyTable.isExactClass(featureId, className);\n};\n\nModelFeatureTable.prototype.getExactClassName = function (featureId) {\n return this._propertyTable.getExactClassName(featureId);\n};\n\nconst scratchColor = new Color();\n/**\n * @private\n */\nModelFeatureTable.prototype.applyStyle = function (style) {\n if (!defined(style)) {\n this.setAllColor(BatchTexture.DEFAULT_COLOR_VALUE);\n this.setAllShow(BatchTexture.DEFAULT_SHOW_VALUE);\n return;\n }\n\n for (let i = 0; i < this._featuresLength; i++) {\n const feature = this.getFeature(i);\n const color = defined(style.color)\n ? defaultValue(\n style.color.evaluateColor(feature, scratchColor),\n BatchTexture.DEFAULT_COLOR_VALUE\n )\n : BatchTexture.DEFAULT_COLOR_VALUE;\n const show = defined(style.show)\n ? defaultValue(\n style.show.evaluate(feature),\n BatchTexture.DEFAULT_SHOW_VALUE\n )\n : BatchTexture.DEFAULT_SHOW_VALUE;\n\n this.setColor(i, color);\n this.setShow(i, show);\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see ModelFeatureTable#destroy\n * @private\n */\nModelFeatureTable.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * e = e && e.destroy();\n *\n * @see ModelFeatureTable#isDestroyed\n * @private\n */\nModelFeatureTable.prototype.destroy = function (frameState) {\n this._batchTexture = this._batchTexture && this._batchTexture.destroy();\n destroyObject(this);\n};\n\nexport default ModelFeatureTable;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"czm_modelMaterial defaultModelMaterial()\\n\\\n{\\n\\\n czm_modelMaterial material;\\n\\\n material.diffuse = vec3(0.0);\\n\\\n material.specular = vec3(1.0);\\n\\\n material.roughness = 1.0;\\n\\\n material.occlusion = 1.0;\\n\\\n material.normalEC = vec3(0.0, 0.0, 1.0);\\n\\\n material.emissive = vec3(0.0);\\n\\\n material.alpha = 1.0;\\n\\\n return material;\\n\\\n}\\n\\\n\\n\\\nvec4 handleAlpha(vec3 color, float alpha)\\n\\\n{\\n\\\n #ifdef ALPHA_MODE_MASK\\n\\\n if (alpha < u_alphaCutoff) {\\n\\\n discard;\\n\\\n }\\n\\\n #endif\\n\\\n\\n\\\n return vec4(color, alpha);\\n\\\n}\\n\\\n\\n\\\nSelectedFeature selectedFeature;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n #ifdef HAS_MODEL_SPLITTER\\n\\\n modelSplitterStage();\\n\\\n #endif\\n\\\n\\n\\\n czm_modelMaterial material = defaultModelMaterial();\\n\\\n\\n\\\n ProcessedAttributes attributes;\\n\\\n geometryStage(attributes);\\n\\\n\\n\\\n FeatureIds featureIds;\\n\\\n featureIdStage(featureIds, attributes);\\n\\\n\\n\\\n Metadata metadata;\\n\\\n MetadataClass metadataClass;\\n\\\n MetadataStatistics metadataStatistics;\\n\\\n metadataStage(metadata, metadataClass, metadataStatistics, attributes);\\n\\\n\\n\\\n #ifdef HAS_SELECTED_FEATURE_ID\\n\\\n selectedFeatureIdStage(selectedFeature, featureIds);\\n\\\n #endif\\n\\\n\\n\\\n #ifndef CUSTOM_SHADER_REPLACE_MATERIAL\\n\\\n materialStage(material, attributes, selectedFeature);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_CUSTOM_FRAGMENT_SHADER\\n\\\n customShaderStage(material, attributes, featureIds, metadata, metadataClass, metadataStatistics);\\n\\\n #endif\\n\\\n\\n\\\n lightingStage(material, attributes);\\n\\\n\\n\\\n #ifdef HAS_SELECTED_FEATURE_ID\\n\\\n cpuStylingStage(material, selectedFeature);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_MODEL_COLOR\\n\\\n modelColorStage(material);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_PRIMITIVE_OUTLINE\\n\\\n primitiveOutlineStage(material);\\n\\\n #endif\\n\\\n\\n\\\n vec4 color = handleAlpha(material.diffuse, material.alpha);\\n\\\n\\n\\\n #ifdef HAS_CLIPPING_PLANES\\n\\\n modelClippingPlanesStage(color);\\n\\\n #endif\\n\\\n\\n\\\n #if defined(HAS_SILHOUETTE) && defined(HAS_NORMALS)\\n\\\n silhouetteStage(color);\\n\\\n #endif\\n\\\n\\n\\\n out_FragColor = color;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"precision highp float;\\n\\\n\\n\\\nczm_modelVertexOutput defaultVertexOutput(vec3 positionMC) {\\n\\\n czm_modelVertexOutput vsOutput;\\n\\\n vsOutput.positionMC = positionMC;\\n\\\n vsOutput.pointSize = 1.0;\\n\\\n return vsOutput;\\n\\\n}\\n\\\n\\n\\\nvoid main() \\n\\\n{\\n\\\n // Initialize the attributes struct with all\\n\\\n // attributes except quantized ones.\\n\\\n ProcessedAttributes attributes;\\n\\\n initializeAttributes(attributes);\\n\\\n\\n\\\n // Dequantize the quantized ones and add them to the\\n\\\n // attributes struct.\\n\\\n #ifdef USE_DEQUANTIZATION\\n\\\n dequantizationStage(attributes);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_MORPH_TARGETS\\n\\\n morphTargetsStage(attributes);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_SKINNING\\n\\\n skinningStage(attributes);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_PRIMITIVE_OUTLINE\\n\\\n primitiveOutlineStage();\\n\\\n #endif\\n\\\n\\n\\\n // Compute the bitangent according to the formula in the glTF spec.\\n\\\n // Normal and tangents can be affected by morphing and skinning, so\\n\\\n // the bitangent should not be computed until their values are finalized.\\n\\\n #ifdef HAS_BITANGENTS\\n\\\n attributes.bitangentMC = normalize(cross(attributes.normalMC, attributes.tangentMC) * attributes.tangentSignMC);\\n\\\n #endif\\n\\\n\\n\\\n FeatureIds featureIds;\\n\\\n featureIdStage(featureIds, attributes);\\n\\\n\\n\\\n #ifdef HAS_SELECTED_FEATURE_ID\\n\\\n SelectedFeature feature;\\n\\\n selectedFeatureIdStage(feature, featureIds);\\n\\\n // Handle any show properties that come from the style.\\n\\\n cpuStylingStage(attributes.positionMC, feature);\\n\\\n #endif\\n\\\n\\n\\\n #if defined(USE_2D_POSITIONS) || defined(USE_2D_INSTANCING)\\n\\\n // The scene mode 2D pipeline stage and instancing stage add a different\\n\\\n // model view matrix to accurately project the model to 2D. However, the\\n\\\n // output positions and normals should be transformed by the 3D matrices\\n\\\n // to keep the data the same for the fragment shader.\\n\\\n mat4 modelView = czm_modelView3D;\\n\\\n mat3 normal = czm_normal3D;\\n\\\n #else\\n\\\n // These are used for individual model projection because they will\\n\\\n // automatically change based on the scene mode.\\n\\\n mat4 modelView = czm_modelView;\\n\\\n mat3 normal = czm_normal;\\n\\\n #endif\\n\\\n\\n\\\n // Update the position for this instance in place\\n\\\n #ifdef HAS_INSTANCING\\n\\\n\\n\\\n // The legacy instance stage is used when rendering i3dm models that \\n\\\n // encode instances transforms in world space, as opposed to glTF models\\n\\\n // that use EXT_mesh_gpu_instancing, where instance transforms are encoded\\n\\\n // in object space.\\n\\\n #ifdef USE_LEGACY_INSTANCING\\n\\\n mat4 instanceModelView;\\n\\\n mat3 instanceModelViewInverseTranspose;\\n\\\n \\n\\\n legacyInstancingStage(attributes, instanceModelView, instanceModelViewInverseTranspose);\\n\\\n\\n\\\n modelView = instanceModelView;\\n\\\n normal = instanceModelViewInverseTranspose;\\n\\\n #else\\n\\\n instancingStage(attributes);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef USE_PICKING\\n\\\n v_pickColor = a_pickColor;\\n\\\n #endif\\n\\\n\\n\\\n #endif\\n\\\n\\n\\\n Metadata metadata;\\n\\\n MetadataClass metadataClass;\\n\\\n MetadataStatistics metadataStatistics;\\n\\\n metadataStage(metadata, metadataClass, metadataStatistics, attributes);\\n\\\n\\n\\\n #ifdef HAS_CUSTOM_VERTEX_SHADER\\n\\\n czm_modelVertexOutput vsOutput = defaultVertexOutput(attributes.positionMC);\\n\\\n customShaderStage(vsOutput, attributes, featureIds, metadata, metadataClass, metadataStatistics);\\n\\\n #endif\\n\\\n\\n\\\n // Compute the final position in each coordinate system needed.\\n\\\n // This returns the value that will be assigned to gl_Position.\\n\\\n vec4 positionClip = geometryStage(attributes, modelView, normal); \\n\\\n\\n\\\n #ifdef HAS_SILHOUETTE\\n\\\n silhouetteStage(attributes, positionClip);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_POINT_CLOUD_SHOW_STYLE\\n\\\n float show = pointCloudShowStylingStage(attributes, metadata);\\n\\\n #else\\n\\\n float show = 1.0;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_POINT_CLOUD_BACK_FACE_CULLING\\n\\\n show *= pointCloudBackFaceCullingStage();\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_POINT_CLOUD_COLOR_STYLE\\n\\\n v_pointCloudColor = pointCloudColorStylingStage(attributes, metadata);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef PRIMITIVE_TYPE_POINTS\\n\\\n #ifdef HAS_CUSTOM_VERTEX_SHADER\\n\\\n gl_PointSize = vsOutput.pointSize;\\n\\\n #elif defined(HAS_POINT_CLOUD_POINT_SIZE_STYLE) || defined(HAS_POINT_CLOUD_ATTENUATION)\\n\\\n gl_PointSize = pointCloudPointSizeStylingStage(attributes, metadata);\\n\\\n #else\\n\\\n gl_PointSize = 1.0;\\n\\\n #endif\\n\\\n\\n\\\n gl_PointSize *= show;\\n\\\n #endif\\n\\\n\\n\\\n gl_Position = show * positionClip;\\n\\\n}\\n\\\n\";\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport DrawCommand from \"../../Renderer/DrawCommand.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport RenderState from \"../../Renderer/RenderState.js\";\nimport BlendingState from \"../BlendingState.js\";\nimport ClassificationType from \"../ClassificationType.js\";\nimport DepthFunction from \"../DepthFunction.js\";\nimport StencilConstants from \"../StencilConstants.js\";\nimport StencilFunction from \"../StencilFunction.js\";\nimport StencilOperation from \"../StencilOperation.js\";\n\n/**\n * A wrapper around the draw commands used to render a classification model,\n * i.e. a {@link Model} that classifies another asset. This manages the\n * derived commands and returns only the necessary commands depending on the\n * given frame state.\n *\n * @param {object} options An object containing the following options:\n * @param {DrawCommand} options.command The draw command from which to derive other commands from.\n * @param {PrimitiveRenderResources} options.primitiveRenderResources The render resources of the primitive associated with the command.\n *\n * @alias ClassificationModelDrawCommand\n * @constructor\n *\n * @private\n */\nfunction ClassificationModelDrawCommand(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const command = options.command;\n const renderResources = options.primitiveRenderResources;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.command\", command);\n Check.typeOf.object(\"options.primitiveRenderResources\", renderResources);\n //>>includeEnd('debug');\n\n const model = renderResources.model;\n\n this._command = command;\n this._model = model;\n this._runtimePrimitive = renderResources.runtimePrimitive;\n\n // Classification models aren't supported in 2D mode, so there's no need to\n // duplicate the model matrix for each derived command.\n this._modelMatrix = command.modelMatrix;\n this._boundingVolume = command.boundingVolume;\n this._cullFace = command.renderState.cull.face;\n\n const type = model.classificationType;\n this._classificationType = type;\n\n // ClassificationType has three values: terrain only, 3D Tiles only, or both.\n this._classifiesTerrain = type !== ClassificationType.CESIUM_3D_TILE;\n this._classifies3DTiles = type !== ClassificationType.TERRAIN;\n\n this._useDebugWireframe = model._enableDebugWireframe && model.debugWireframe;\n this._pickId = renderResources.pickId;\n\n this._commandListTerrain = [];\n this._commandList3DTiles = [];\n this._commandListIgnoreShow = []; // Used for inverted classification.\n this._commandListDebugWireframe = [];\n\n this._commandListTerrainPicking = [];\n this._commandList3DTilesPicking = [];\n\n initialize(this);\n}\n\nfunction getStencilDepthRenderState(stencilFunction) {\n return {\n colorMask: {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n },\n stencilTest: {\n enabled: true,\n frontFunction: stencilFunction,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.DECREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n backFunction: stencilFunction,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.INCREMENT_WRAP,\n zPass: StencilOperation.KEEP,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: true,\n func: DepthFunction.LESS_OR_EQUAL,\n },\n depthMask: false,\n };\n}\n\nconst colorRenderState = {\n stencilTest: {\n enabled: true,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n};\n\nconst pickRenderState = {\n stencilTest: {\n enabled: true,\n frontFunction: StencilFunction.NOT_EQUAL,\n frontOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n backFunction: StencilFunction.NOT_EQUAL,\n backOperation: {\n fail: StencilOperation.ZERO,\n zFail: StencilOperation.ZERO,\n zPass: StencilOperation.ZERO,\n },\n reference: 0,\n mask: StencilConstants.CLASSIFICATION_MASK,\n },\n stencilMask: StencilConstants.CLASSIFICATION_MASK,\n depthTest: {\n enabled: false,\n },\n depthMask: false,\n};\n\nconst scratchDerivedCommands = [];\n\nfunction initialize(drawCommand) {\n const command = drawCommand._command;\n const derivedCommands = scratchDerivedCommands;\n\n // If debug wireframe is enabled, don't derive any new commands.\n // Render normally in the opaque pass.\n if (drawCommand._useDebugWireframe) {\n command.pass = Pass.OPAQUE;\n\n derivedCommands.length = 0;\n derivedCommands.push(command);\n\n drawCommand._commandListDebugWireframe = createBatchCommands(\n drawCommand,\n derivedCommands,\n drawCommand._commandListDebugWireframe\n );\n\n const commandList = drawCommand._commandListDebugWireframe;\n const length = commandList.length;\n for (let i = 0; i < length; i++) {\n // The lengths / offsets of the batches have to be adjusted for wireframe.\n // Only PrimitiveType.TRIANGLES is allowed for classification, so this\n // just requires doubling the values for the batches.\n const command = commandList[i];\n command.count *= 2;\n command.offset *= 2;\n }\n\n return;\n }\n\n const model = drawCommand.model;\n const allowPicking = model.allowPicking;\n\n if (drawCommand._classifiesTerrain) {\n const pass = Pass.TERRAIN_CLASSIFICATION;\n const stencilDepthCommand = deriveStencilDepthCommand(command, pass);\n const colorCommand = deriveColorCommand(command, pass);\n\n derivedCommands.length = 0;\n derivedCommands.push(stencilDepthCommand, colorCommand);\n\n drawCommand._commandListTerrain = createBatchCommands(\n drawCommand,\n derivedCommands,\n drawCommand._commandListTerrain\n );\n\n if (allowPicking) {\n drawCommand._commandListTerrainPicking = createPickCommands(\n drawCommand,\n derivedCommands,\n drawCommand._commandListTerrainPicking\n );\n }\n }\n\n if (drawCommand._classifies3DTiles) {\n const pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n const stencilDepthCommand = deriveStencilDepthCommand(command, pass);\n const colorCommand = deriveColorCommand(command, pass);\n\n derivedCommands.length = 0;\n derivedCommands.push(stencilDepthCommand, colorCommand);\n\n drawCommand._commandList3DTiles = createBatchCommands(\n drawCommand,\n derivedCommands,\n drawCommand._commandList3DTiles\n );\n\n if (allowPicking) {\n drawCommand._commandList3DTilesPicking = createPickCommands(\n drawCommand,\n derivedCommands,\n drawCommand._commandList3DTilesPicking\n );\n }\n }\n}\n\nfunction createBatchCommands(drawCommand, derivedCommands, result) {\n const runtimePrimitive = drawCommand._runtimePrimitive;\n const batchLengths = runtimePrimitive.batchLengths;\n const batchOffsets = runtimePrimitive.batchOffsets;\n\n const numBatches = batchLengths.length;\n const numDerivedCommands = derivedCommands.length;\n for (let i = 0; i < numBatches; i++) {\n const batchLength = batchLengths[i];\n const batchOffset = batchOffsets[i];\n // For multiple derived commands (e.g. stencil and color commands),\n // they must be added in a certain order even within the batches.\n for (let j = 0; j < numDerivedCommands; j++) {\n const derivedCommand = derivedCommands[j];\n const batchCommand = DrawCommand.shallowClone(derivedCommand);\n batchCommand.count = batchLength;\n batchCommand.offset = batchOffset;\n result.push(batchCommand);\n }\n }\n\n return result;\n}\n\nfunction deriveStencilDepthCommand(command, pass) {\n const stencilDepthCommand = DrawCommand.shallowClone(command);\n stencilDepthCommand.cull = false;\n stencilDepthCommand.pass = pass;\n\n const stencilFunction =\n pass === Pass.TERRAIN_CLASSIFICATION\n ? StencilFunction.ALWAYS\n : StencilFunction.EQUAL;\n const renderState = getStencilDepthRenderState(stencilFunction);\n stencilDepthCommand.renderState = RenderState.fromCache(renderState);\n\n return stencilDepthCommand;\n}\n\nfunction deriveColorCommand(command, pass) {\n const colorCommand = DrawCommand.shallowClone(command);\n colorCommand.cull = false;\n colorCommand.pass = pass;\n\n colorCommand.renderState = RenderState.fromCache(colorRenderState);\n\n return colorCommand;\n}\n\nconst scratchPickCommands = [];\n\nfunction createPickCommands(drawCommand, derivedCommands, commandList) {\n const renderState = RenderState.fromCache(pickRenderState);\n const stencilDepthCommand = derivedCommands[0];\n const colorCommand = derivedCommands[1];\n\n const pickStencilDepthCommand = DrawCommand.shallowClone(stencilDepthCommand);\n pickStencilDepthCommand.cull = true;\n pickStencilDepthCommand.pickOnly = true;\n\n const pickColorCommand = DrawCommand.shallowClone(colorCommand);\n pickColorCommand.cull = true;\n pickColorCommand.pickOnly = true;\n pickColorCommand.renderState = renderState;\n pickColorCommand.pickId = drawCommand._pickId;\n\n const pickCommands = scratchPickCommands;\n pickCommands.length = 0;\n pickCommands.push(pickStencilDepthCommand, pickColorCommand);\n\n return createBatchCommands(drawCommand, pickCommands, commandList);\n}\n\nObject.defineProperties(ClassificationModelDrawCommand.prototype, {\n /**\n * The main draw command that the other commands are derived from.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {DrawCommand}\n *\n * @readonly\n * @private\n */\n command: {\n get: function () {\n return this._command;\n },\n },\n\n /**\n * The runtime primitive that the draw command belongs to.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {ModelRuntimePrimitive}\n *\n * @readonly\n * @private\n */\n runtimePrimitive: {\n get: function () {\n return this._runtimePrimitive;\n },\n },\n\n /**\n * The batch lengths used to generate multiple draw commands.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {number[]}\n *\n * @readonly\n * @private\n */\n batchLengths: {\n get: function () {\n return this._runtimePrimitive.batchLengths;\n },\n },\n\n /**\n * The batch offsets used to generate multiple draw commands.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {number[]}\n *\n * @readonly\n * @private\n */\n batchOffsets: {\n get: function () {\n return this._runtimePrimitive.batchOffsets;\n },\n },\n\n /**\n * The model that the draw command belongs to.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {Model}\n *\n * @readonly\n * @private\n */\n model: {\n get: function () {\n return this._model;\n },\n },\n\n /**\n * The classification type of the model that this draw command belongs to.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {ClassificationType}\n *\n * @readonly\n * @private\n */\n classificationType: {\n get: function () {\n return this._classificationType;\n },\n },\n\n /**\n * The current model matrix applied to the draw commands.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {Matrix4}\n *\n * @readonly\n * @private\n */\n modelMatrix: {\n get: function () {\n return this._modelMatrix;\n },\n set: function (value) {\n this._modelMatrix = Matrix4.clone(value, this._modelMatrix);\n const boundingSphere = this._runtimePrimitive.boundingSphere;\n this._boundingVolume = BoundingSphere.transform(\n boundingSphere,\n this._modelMatrix,\n this._boundingVolume\n );\n },\n },\n\n /**\n * The bounding volume of the main draw command. This is equivalent\n * to the primitive's bounding sphere transformed by the draw\n * command's model matrix.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {BoundingSphere}\n *\n * @readonly\n * @private\n */\n boundingVolume: {\n get: function () {\n return this._boundingVolume;\n },\n },\n\n /**\n * Culling is disabled for classification models, so this has no effect on\n * how the model renders. This only exists to match the interface of\n * {@link ModelDrawCommand}.\n *\n * @memberof ClassificationModelDrawCommand.prototype\n * @type {CullFace}\n *\n * @private\n */\n cullFace: {\n get: function () {\n return this._cullFace;\n },\n set: function (value) {\n this._cullFace = value;\n },\n },\n});\n\n/**\n * Pushes the draw commands necessary to render the primitive.\n *\n * @param {FrameState} frameState The frame state.\n * @param {DrawCommand[]} result The array to push the draw commands to.\n *\n * @returns {DrawCommand[]} The modified result parameter.\n *\n * @private\n */\nClassificationModelDrawCommand.prototype.pushCommands = function (\n frameState,\n result\n) {\n const passes = frameState.passes;\n if (passes.render) {\n if (this._useDebugWireframe) {\n result.push.apply(result, this._commandListDebugWireframe);\n return;\n }\n\n if (this._classifiesTerrain) {\n result.push.apply(result, this._commandListTerrain);\n }\n\n if (this._classifies3DTiles) {\n result.push.apply(result, this._commandList3DTiles);\n }\n\n const useIgnoreShowCommands =\n frameState.invertClassification && this._classifies3DTiles;\n\n if (useIgnoreShowCommands) {\n if (this._commandListIgnoreShow.length === 0) {\n const pass = Pass.CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW;\n const command = deriveStencilDepthCommand(this._command, pass);\n\n const derivedCommands = scratchDerivedCommands;\n derivedCommands.length = 0;\n derivedCommands.push(command);\n\n this._commandListIgnoreShow = createBatchCommands(\n this,\n derivedCommands,\n this._commandListIgnoreShow\n );\n }\n\n result.push.apply(result, this._commandListIgnoreShow);\n }\n }\n\n if (passes.pick) {\n if (this._classifiesTerrain) {\n result.push.apply(result, this._commandListTerrainPicking);\n }\n\n if (this._classifies3DTiles) {\n result.push.apply(result, this._commandList3DTilesPicking);\n }\n }\n\n return result;\n};\n\nexport default ClassificationModelDrawCommand;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Cartesian2 from \"../../Core/Cartesian2.js\";\nimport CesiumMath from \"../../Core/Math.js\";\nimport Check from \"../../Core/Check.js\";\nimport clone from \"../../Core/clone.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\nimport DrawCommand from \"../../Renderer/DrawCommand.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport RenderState from \"../../Renderer/RenderState.js\";\nimport BlendingState from \"../BlendingState.js\";\nimport CullFace from \"../CullFace.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport ShadowMode from \"../ShadowMode.js\";\nimport StencilConstants from \"../StencilConstants.js\";\nimport StencilFunction from \"../StencilFunction.js\";\nimport StencilOperation from \"../StencilOperation.js\";\nimport StyleCommandsNeeded from \"./StyleCommandsNeeded.js\";\n\n/**\n * A wrapper around the draw commands used to render a {@link ModelRuntimePrimitive}.\n * This manages the derived commands and pushes only the necessary commands depending\n * on the given frame state.\n *\n * @param {object} options An object containing the following options:\n * @param {DrawCommand} options.command The draw command from which to derive other commands from.\n * @param {PrimitiveRenderResources} options.primitiveRenderResources The render resources of the primitive associated with the command.\n *\n * @alias ModelDrawCommand\n * @constructor\n *\n * @private\n */\nfunction ModelDrawCommand(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const command = options.command;\n const renderResources = options.primitiveRenderResources;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.command\", command);\n Check.typeOf.object(\"options.primitiveRenderResources\", renderResources);\n //>>includeEnd('debug');\n\n const model = renderResources.model;\n this._model = model;\n\n const runtimePrimitive = renderResources.runtimePrimitive;\n this._runtimePrimitive = runtimePrimitive;\n\n // If the command is translucent, or if the primitive's material is\n // double-sided, then back-face culling is automatically disabled for\n // the command. The user value for back-face culling will be ignored.\n const isTranslucent = command.pass === Pass.TRANSLUCENT;\n const isDoubleSided = runtimePrimitive.primitive.material.doubleSided;\n const usesBackFaceCulling = !isDoubleSided && !isTranslucent;\n const hasSilhouette = renderResources.hasSilhouette;\n\n // If the command was already translucent, there's no need to derive a new\n // translucent command. As of now, a style can't change an originally\n // translucent feature to opaque since the style's alpha is modulated,\n // not replaced. When this changes, we need to derive new opaque commands\n // in initialize().\n //\n // Silhouettes for primitives with both opaque and translucent features\n // are not yet supported.\n const needsTranslucentCommand = !isTranslucent && !hasSilhouette;\n\n const needsSkipLevelOfDetailCommands =\n renderResources.hasSkipLevelOfDetail && !isTranslucent;\n\n const needsSilhouetteCommands = hasSilhouette;\n\n this._command = command;\n\n // None of the derived commands (non-2D) use a different model matrix\n // or bounding volume than the original, so they all point to the\n // ModelDrawCommand's copy to save update time and memory.\n this._modelMatrix = Matrix4.clone(command.modelMatrix);\n this._boundingVolume = BoundingSphere.clone(command.boundingVolume);\n\n // The 2D model matrix depends on the frame state's map projection,\n // so it must be updated when the commands are handled in pushCommands.\n this._modelMatrix2D = new Matrix4();\n this._boundingVolume2D = new BoundingSphere();\n this._modelMatrix2DDirty = false;\n\n this._backFaceCulling = command.renderState.cull.enabled;\n this._cullFace = command.renderState.cull.face;\n this._shadows = model.shadows;\n this._debugShowBoundingVolume = command.debugShowBoundingVolume;\n\n this._usesBackFaceCulling = usesBackFaceCulling;\n this._needsTranslucentCommand = needsTranslucentCommand;\n this._needsSkipLevelOfDetailCommands = needsSkipLevelOfDetailCommands;\n this._needsSilhouetteCommands = needsSilhouetteCommands;\n\n // Derived commands\n this._originalCommand = undefined;\n this._translucentCommand = undefined;\n this._skipLodBackfaceCommand = undefined;\n this._skipLodStencilCommand = undefined;\n this._silhouetteModelCommand = undefined;\n this._silhouetteColorCommand = undefined;\n\n // All derived commands (including 2D commands)\n this._derivedCommands = [];\n this._has2DCommands = false;\n\n initialize(this);\n}\n\nfunction ModelDerivedCommand(options) {\n // The DrawCommand managed by this derived command.\n this.command = options.command;\n\n // These control whether the derived command should update the\n // values of the DrawCommand for the corresponding properties.\n this.updateShadows = options.updateShadows;\n this.updateBackFaceCulling = options.updateBackFaceCulling;\n this.updateCullFace = options.updateCullFace;\n this.updateDebugShowBoundingVolume = options.updateDebugShowBoundingVolume;\n\n // Whether this ModelDerivedCommand is in 2D.\n this.is2D = defaultValue(options.is2D, false);\n\n // A ModelDerivedCommand that is the 2D version of this one.\n this.derivedCommand2D = undefined;\n}\n\nModelDerivedCommand.clone = function (derivedCommand) {\n return new ModelDerivedCommand({\n command: derivedCommand.command,\n updateShadows: derivedCommand.updateShadows,\n updateBackFaceCulling: derivedCommand.updateBackFaceCulling,\n updateCullFace: derivedCommand.updateCullFace,\n updateDebugShowBoundingVolume: derivedCommand.updateDebugShowBoundingVolume,\n is2D: derivedCommand.is2D,\n derivedCommand2D: derivedCommand.derivedCommand2D,\n });\n};\n\nfunction initialize(drawCommand) {\n const command = drawCommand._command;\n command.modelMatrix = drawCommand._modelMatrix;\n command.boundingVolume = drawCommand._boundingVolume;\n\n const model = drawCommand._model;\n const usesBackFaceCulling = drawCommand._usesBackFaceCulling;\n const derivedCommands = drawCommand._derivedCommands;\n\n drawCommand._originalCommand = new ModelDerivedCommand({\n command: command,\n updateShadows: true,\n updateBackFaceCulling: usesBackFaceCulling,\n updateCullFace: usesBackFaceCulling,\n updateDebugShowBoundingVolume: true,\n is2D: false,\n });\n\n derivedCommands.push(drawCommand._originalCommand);\n\n if (drawCommand._needsTranslucentCommand) {\n drawCommand._translucentCommand = new ModelDerivedCommand({\n command: deriveTranslucentCommand(command),\n updateShadows: true,\n updateBackFaceCulling: false,\n updateCullFace: false,\n updateDebugShowBoundingVolume: true,\n });\n\n derivedCommands.push(drawCommand._translucentCommand);\n }\n\n if (drawCommand._needsSkipLevelOfDetailCommands) {\n drawCommand._skipLodBackfaceCommand = new ModelDerivedCommand({\n command: deriveSkipLodBackfaceCommand(command),\n updateShadows: false,\n updateBackFaceCulling: false,\n updateCullFace: usesBackFaceCulling,\n updateDebugShowBoundingVolume: false,\n });\n\n drawCommand._skipLodStencilCommand = new ModelDerivedCommand({\n command: deriveSkipLodStencilCommand(command, model),\n updateShadows: true,\n updateBackFaceCulling: usesBackFaceCulling,\n updateCullFace: usesBackFaceCulling,\n updateDebugShowBoundingVolume: true,\n });\n\n derivedCommands.push(drawCommand._skipLodBackfaceCommand);\n derivedCommands.push(drawCommand._skipLodStencilCommand);\n }\n\n if (drawCommand._needsSilhouetteCommands) {\n drawCommand._silhouetteModelCommand = new ModelDerivedCommand({\n command: deriveSilhouetteModelCommand(command, model),\n updateShadows: true,\n updateBackFaceCulling: usesBackFaceCulling,\n updateCullFace: usesBackFaceCulling,\n updateDebugShowBoundingVolume: true,\n });\n\n drawCommand._silhouetteColorCommand = new ModelDerivedCommand({\n command: deriveSilhouetteColorCommand(command, model),\n updateShadows: false,\n updateBackFaceCulling: false,\n updateCullFace: false,\n updateDebugShowBoundingVolume: false,\n });\n\n derivedCommands.push(drawCommand._silhouetteModelCommand);\n derivedCommands.push(drawCommand._silhouetteColorCommand);\n }\n}\n\nObject.defineProperties(ModelDrawCommand.prototype, {\n /**\n * The main draw command that the other commands are derived from.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {DrawCommand}\n *\n * @readonly\n * @private\n */\n command: {\n get: function () {\n return this._command;\n },\n },\n\n /**\n * The runtime primitive that the draw command belongs to.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {ModelRuntimePrimitive}\n *\n * @readonly\n * @private\n */\n runtimePrimitive: {\n get: function () {\n return this._runtimePrimitive;\n },\n },\n\n /**\n * The model that the draw command belongs to.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {Model}\n *\n * @readonly\n * @private\n */\n model: {\n get: function () {\n return this._model;\n },\n },\n\n /**\n * The primitive type of the draw command.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {PrimitiveType}\n *\n * @readonly\n * @private\n */\n primitiveType: {\n get: function () {\n return this._command.primitiveType;\n },\n },\n\n /**\n * The current model matrix applied to the draw commands. If there are\n * 2D draw commands, their model matrix will be derived from the 3D one.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {Matrix4}\n *\n * @readonly\n * @private\n */\n modelMatrix: {\n get: function () {\n return this._modelMatrix;\n },\n set: function (value) {\n this._modelMatrix = Matrix4.clone(value, this._modelMatrix);\n this._modelMatrix2DDirty = true;\n\n this._boundingVolume = BoundingSphere.transform(\n this.runtimePrimitive.boundingSphere,\n this._modelMatrix,\n this._boundingVolume\n );\n },\n },\n\n /**\n * The bounding volume of the main draw command. This is equivalent\n * to the primitive's bounding sphere transformed by the draw\n * command's model matrix.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {BoundingSphere}\n *\n * @readonly\n * @private\n */\n boundingVolume: {\n get: function () {\n return this._boundingVolume;\n },\n },\n\n /**\n * Whether the geometry casts or receives shadows from light sources.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {ShadowMode}\n *\n * @private\n */\n shadows: {\n get: function () {\n return this._shadows;\n },\n set: function (value) {\n this._shadows = value;\n updateShadows(this);\n },\n },\n\n /**\n * Whether to cull back-facing geometry. When true, back face culling is\n * determined by the material's doubleSided property; when false, back face\n * culling is disabled. Back faces are not culled if the command is\n * translucent.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {boolean}\n *\n * @private\n */\n backFaceCulling: {\n get: function () {\n return this._backFaceCulling;\n },\n set: function (value) {\n if (this._backFaceCulling === value) {\n return;\n }\n\n this._backFaceCulling = value;\n updateBackFaceCulling(this);\n },\n },\n\n /**\n * Determines which faces to cull, if culling is enabled.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {CullFace}\n *\n * @private\n */\n cullFace: {\n get: function () {\n return this._cullFace;\n },\n set: function (value) {\n if (this._cullFace === value) {\n return;\n }\n\n this._cullFace = value;\n updateCullFace(this);\n },\n },\n\n /**\n * Whether to draw the bounding sphere associated with this draw command.\n *\n * @memberof ModelDrawCommand.prototype\n * @type {boolean}\n *\n * @private\n */\n debugShowBoundingVolume: {\n get: function () {\n return this._debugShowBoundingVolume;\n },\n set: function (value) {\n if (this._debugShowBoundingVolume === value) {\n return;\n }\n\n this._debugShowBoundingVolume = value;\n updateDebugShowBoundingVolume(this);\n },\n },\n});\n\nfunction updateModelMatrix2D(drawCommand, frameState) {\n const modelMatrix = drawCommand._modelMatrix;\n drawCommand._modelMatrix2D = Matrix4.clone(\n modelMatrix,\n drawCommand._modelMatrix2D\n );\n\n // Change the translation's y-component so it appears on the opposite side\n // of the map.\n drawCommand._modelMatrix2D[13] -=\n CesiumMath.sign(modelMatrix[13]) *\n 2.0 *\n CesiumMath.PI *\n frameState.mapProjection.ellipsoid.maximumRadius;\n\n drawCommand._boundingVolume2D = BoundingSphere.transform(\n drawCommand.runtimePrimitive.boundingSphere,\n drawCommand._modelMatrix2D,\n drawCommand._boundingVolume2D\n );\n}\n\nfunction updateShadows(drawCommand) {\n const shadows = drawCommand.shadows;\n const castShadows = ShadowMode.castShadows(shadows);\n const receiveShadows = ShadowMode.receiveShadows(shadows);\n\n const derivedCommands = drawCommand._derivedCommands;\n\n for (let i = 0; i < derivedCommands.length; ++i) {\n const derivedCommand = derivedCommands[i];\n if (derivedCommand.updateShadows) {\n const command = derivedCommand.command;\n command.castShadows = castShadows;\n command.receiveShadows = receiveShadows;\n }\n }\n}\n\nfunction updateBackFaceCulling(drawCommand) {\n const backFaceCulling = drawCommand.backFaceCulling;\n const derivedCommands = drawCommand._derivedCommands;\n\n for (let i = 0; i < derivedCommands.length; ++i) {\n const derivedCommand = derivedCommands[i];\n if (derivedCommand.updateBackFaceCulling) {\n const command = derivedCommand.command;\n const renderState = clone(command.renderState, true);\n renderState.cull.enabled = backFaceCulling;\n command.renderState = RenderState.fromCache(renderState);\n }\n }\n}\n\nfunction updateCullFace(drawCommand) {\n const cullFace = drawCommand.cullFace;\n const derivedCommands = drawCommand._derivedCommands;\n\n for (let i = 0; i < derivedCommands.length; ++i) {\n const derivedCommand = derivedCommands[i];\n if (derivedCommand.updateCullFace) {\n const command = derivedCommand.command;\n const renderState = clone(command.renderState, true);\n renderState.cull.face = cullFace;\n command.renderState = RenderState.fromCache(renderState);\n }\n }\n}\n\nfunction updateDebugShowBoundingVolume(drawCommand) {\n const debugShowBoundingVolume = drawCommand.debugShowBoundingVolume;\n const derivedCommands = drawCommand._derivedCommands;\n\n for (let i = 0; i < derivedCommands.length; ++i) {\n const derivedCommand = derivedCommands[i];\n if (derivedCommand.updateDebugShowBoundingVolume) {\n const command = derivedCommand.command;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n }\n }\n}\n\n/**\n * Pushes the draw commands necessary to render the primitive.\n * This does not include the draw commands that render its silhouette.\n *\n * @param {FrameState} frameState The frame state.\n * @param {DrawCommand[]} result The array to push the draw commands to.\n *\n * @returns {DrawCommand[]} The modified result parameter.\n *\n * @private\n */\nModelDrawCommand.prototype.pushCommands = function (frameState, result) {\n const use2D = shouldUse2DCommands(this, frameState);\n\n if (use2D && !this._has2DCommands) {\n derive2DCommands(this);\n this._has2DCommands = true;\n this._modelMatrix2DDirty = true;\n }\n\n if (this._modelMatrix2DDirty) {\n updateModelMatrix2D(this, frameState);\n this._modelMatrix2DDirty = false;\n }\n\n const styleCommandsNeeded = this.model.styleCommandsNeeded;\n if (this._needsTranslucentCommand && defined(styleCommandsNeeded)) {\n // StyleCommandsNeeded has three values: all opaque, all translucent, or both.\n if (styleCommandsNeeded !== StyleCommandsNeeded.ALL_OPAQUE) {\n pushCommand(result, this._translucentCommand, use2D);\n }\n\n // Continue only if opaque commands are needed.\n if (styleCommandsNeeded === StyleCommandsNeeded.ALL_TRANSLUCENT) {\n return;\n }\n }\n\n if (this._needsSkipLevelOfDetailCommands) {\n const { tileset, tile } = this._model.content;\n\n if (tileset.hasMixedContent) {\n if (!tile._finalResolution) {\n pushCommand(\n tileset._backfaceCommands,\n this._skipLodBackfaceCommand,\n use2D\n );\n }\n\n updateSkipLodStencilCommand(this, tile, use2D);\n pushCommand(result, this._skipLodStencilCommand, use2D);\n return;\n }\n }\n\n if (this._needsSilhouetteCommands) {\n pushCommand(result, this._silhouetteModelCommand, use2D);\n return;\n }\n\n pushCommand(result, this._originalCommand, use2D);\n\n return result;\n};\n\n/**\n * Pushes the draw commands necessary to render the silhouette. These should\n * be added to the command list after the draw commands of all primitives\n * in the model have been added. This way, the silhouette won't render on\n * top of the model.\n *

\n * This should only be called after pushCommands() has been invoked for\n * the ModelDrawCommand this frame. Otherwise, the silhouette commands may\n * not have been derived for 2D. The model matrix will also not have been\n * updated for 2D commands.\n *

\n *\n * @param {FrameState} frameState The frame state.\n * @param {DrawCommand[]} result The array to push the silhouette commands to.\n *\n * @returns {DrawCommand[]} The modified result parameter.\n *\n * @private\n */\nModelDrawCommand.prototype.pushSilhouetteCommands = function (\n frameState,\n result\n) {\n const use2D = shouldUse2DCommands(this, frameState);\n pushCommand(result, this._silhouetteColorCommand, use2D);\n\n return result;\n};\n\nfunction pushCommand(commandList, derivedCommand, use2D) {\n commandList.push(derivedCommand.command);\n if (use2D) {\n commandList.push(derivedCommand.derivedCommand2D.command);\n }\n}\n\nfunction shouldUse2DCommands(drawCommand, frameState) {\n if (frameState.mode !== SceneMode.SCENE2D || drawCommand.model._projectTo2D) {\n return false;\n }\n\n // The draw command's bounding sphere might cause primitives not to render\n // over the IDL, even if they are part of the same model. Use the scene graph's\n // bounding sphere instead.\n const model = drawCommand.model;\n const boundingSphere = model.sceneGraph._boundingSphere2D;\n\n const left = boundingSphere.center.y - boundingSphere.radius;\n const right = boundingSphere.center.y + boundingSphere.radius;\n const idl2D =\n frameState.mapProjection.ellipsoid.maximumRadius * CesiumMath.PI;\n\n return (left < idl2D && right > idl2D) || (left < -idl2D && right > -idl2D);\n}\n\nfunction derive2DCommand(drawCommand, derivedCommand) {\n if (!defined(derivedCommand)) {\n return;\n }\n\n // If the model crosses the IDL in 2D, it will be drawn in one viewport but get\n // clipped by the other viewport. We create a second command that translates\n // the model matrix to the opposite side of the map so the part that was clipped\n // in one viewport is drawn in the other.\n const derivedCommand2D = ModelDerivedCommand.clone(derivedCommand);\n\n const command2D = DrawCommand.shallowClone(derivedCommand.command);\n command2D.modelMatrix = drawCommand._modelMatrix2D;\n command2D.boundingVolume = drawCommand._boundingVolume2D;\n\n derivedCommand2D.command = command2D;\n derivedCommand2D.updateShadows = false; // Shadows are disabled for 2D\n derivedCommand2D.is2D = true;\n\n derivedCommand.derivedCommand2D = derivedCommand2D;\n drawCommand._derivedCommands.push(derivedCommand2D);\n\n return derivedCommand2D;\n}\n\nfunction derive2DCommands(drawCommand) {\n derive2DCommand(drawCommand, drawCommand._originalCommand);\n derive2DCommand(drawCommand, drawCommand._translucentCommand);\n derive2DCommand(drawCommand, drawCommand._skipLodBackfaceCommand);\n derive2DCommand(drawCommand, drawCommand._skipLodStencilCommand);\n derive2DCommand(drawCommand, drawCommand._silhouetteModelCommand);\n derive2DCommand(drawCommand, drawCommand._silhouetteColorCommand);\n}\n\nfunction deriveTranslucentCommand(command) {\n const derivedCommand = DrawCommand.shallowClone(command);\n derivedCommand.pass = Pass.TRANSLUCENT;\n const rs = clone(command.renderState, true);\n rs.cull.enabled = false;\n rs.depthMask = false;\n rs.blending = BlendingState.ALPHA_BLEND;\n derivedCommand.renderState = RenderState.fromCache(rs);\n\n return derivedCommand;\n}\n\nfunction deriveSilhouetteModelCommand(command, model) {\n // Wrap around after exceeding the 8-bit stencil limit.\n // The reference is unique to each model until this point.\n const stencilReference = model._silhouetteId % 255;\n const silhouetteModelCommand = DrawCommand.shallowClone(command);\n const renderState = clone(command.renderState, true);\n\n // Write the reference value into the stencil buffer.\n renderState.stencilTest = {\n enabled: true,\n frontFunction: WebGLConstants.ALWAYS,\n backFunction: WebGLConstants.ALWAYS,\n reference: stencilReference,\n mask: ~0,\n frontOperation: {\n fail: WebGLConstants.KEEP,\n zFail: WebGLConstants.KEEP,\n zPass: WebGLConstants.REPLACE,\n },\n backOperation: {\n fail: WebGLConstants.KEEP,\n zFail: WebGLConstants.KEEP,\n zPass: WebGLConstants.REPLACE,\n },\n };\n\n if (model.isInvisible()) {\n renderState.colorMask = {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n };\n }\n\n silhouetteModelCommand.renderState = RenderState.fromCache(renderState);\n\n return silhouetteModelCommand;\n}\n\nfunction deriveSilhouetteColorCommand(command, model) {\n // Wrap around after exceeding the 8-bit stencil limit.\n // The reference is unique to each model until this point.\n const stencilReference = model._silhouetteId % 255;\n const silhouetteColorCommand = DrawCommand.shallowClone(command);\n const renderState = clone(command.renderState, true);\n renderState.cull.enabled = false;\n\n // Render the silhouette in the translucent pass if either the command\n // pass or the silhouette color is translucent. This will account for\n // translucent model color, since ModelColorPipelineStage sets the pass\n // to translucent.\n const silhouetteTranslucent =\n command.pass === Pass.TRANSLUCENT || model.silhouetteColor.alpha < 1.0;\n if (silhouetteTranslucent) {\n silhouetteColorCommand.pass = Pass.TRANSLUCENT;\n renderState.depthMask = false;\n renderState.blending = BlendingState.ALPHA_BLEND;\n }\n\n // Only render the pixels of the silhouette that don't conflict with\n // the stencil buffer. This way, the silhouette doesn't render over\n // the original model.\n renderState.stencilTest = {\n enabled: true,\n frontFunction: WebGLConstants.NOTEQUAL,\n backFunction: WebGLConstants.NOTEQUAL,\n reference: stencilReference,\n mask: ~0,\n frontOperation: {\n fail: WebGLConstants.KEEP,\n zFail: WebGLConstants.KEEP,\n zPass: WebGLConstants.KEEP,\n },\n backOperation: {\n fail: WebGLConstants.KEEP,\n zFail: WebGLConstants.KEEP,\n zPass: WebGLConstants.KEEP,\n },\n };\n\n const uniformMap = clone(command.uniformMap);\n uniformMap.model_silhouettePass = function () {\n return true;\n };\n\n silhouetteColorCommand.renderState = RenderState.fromCache(renderState);\n silhouetteColorCommand.uniformMap = uniformMap;\n silhouetteColorCommand.castShadows = false;\n silhouetteColorCommand.receiveShadows = false;\n\n return silhouetteColorCommand;\n}\n\nfunction updateSkipLodStencilCommand(drawCommand, tile, use2D) {\n const stencilDerivedComand = drawCommand._skipLodStencilCommand;\n const stencilCommand = stencilDerivedComand.command;\n\n const selectionDepth = tile._selectionDepth;\n const lastSelectionDepth = getLastSelectionDepth(stencilCommand);\n\n if (selectionDepth !== lastSelectionDepth) {\n const skipLodStencilReference = getStencilReference(selectionDepth);\n const renderState = clone(stencilCommand.renderState, true);\n renderState.stencilTest.reference = skipLodStencilReference;\n stencilCommand.renderState = RenderState.fromCache(renderState);\n\n if (use2D) {\n stencilDerivedComand.derivedCommand2D.renderState = renderState;\n }\n }\n}\n\nfunction getLastSelectionDepth(stencilCommand) {\n // Isolate the selection depth from the stencil reference.\n const reference = stencilCommand.renderState.stencilTest.reference;\n return (\n (reference & StencilConstants.SKIP_LOD_MASK) >>>\n StencilConstants.SKIP_LOD_BIT_SHIFT\n );\n}\n\nfunction getStencilReference(selectionDepth) {\n // Stencil test is masked to the most significant 3 bits so the reference is shifted.\n // Writes 0 for the terrain bit.\n return (\n StencilConstants.CESIUM_3D_TILE_MASK |\n (selectionDepth << StencilConstants.SKIP_LOD_BIT_SHIFT)\n );\n}\n\nfunction deriveSkipLodBackfaceCommand(command) {\n // Write just backface depth of unresolved tiles so resolved stenciled tiles\n // do not appear in front.\n const backfaceCommand = DrawCommand.shallowClone(command);\n const renderState = clone(command.renderState, true);\n renderState.cull.enabled = true;\n renderState.cull.face = CullFace.FRONT;\n // Back faces do not need to write color.\n renderState.colorMask = {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n };\n // Push back face depth away from the camera so it is less likely that back faces and front faces of the same tile\n // intersect and overlap. This helps avoid flickering for very thin double-sided walls.\n renderState.polygonOffset = {\n enabled: true,\n factor: 5.0,\n units: 5.0,\n };\n\n // The stencil test is set in TilesetPipelineStage.\n\n const uniformMap = clone(backfaceCommand.uniformMap);\n const polygonOffset = new Cartesian2(5.0, 5.0);\n\n uniformMap.u_polygonOffset = function () {\n return polygonOffset;\n };\n\n backfaceCommand.renderState = RenderState.fromCache(renderState);\n backfaceCommand.uniformMap = uniformMap;\n backfaceCommand.castShadows = false;\n backfaceCommand.receiveShadows = false;\n\n return backfaceCommand;\n}\n\nfunction deriveSkipLodStencilCommand(command) {\n // Tiles only draw if their selection depth is >= the tile drawn already. They write their\n // selection depth to the stencil buffer to prevent ancestor tiles from drawing on top\n const stencilCommand = DrawCommand.shallowClone(command);\n const renderState = clone(command.renderState, true);\n // The stencil reference is updated dynamically; see updateSkipLodStencilCommand().\n const { stencilTest } = renderState;\n stencilTest.enabled = true;\n stencilTest.mask = StencilConstants.SKIP_LOD_MASK;\n stencilTest.reference = StencilConstants.CESIUM_3D_TILE_MASK;\n stencilTest.frontFunction = StencilFunction.GREATER_OR_EQUAL;\n stencilTest.frontOperation.zPass = StencilOperation.REPLACE;\n stencilTest.backFunction = StencilFunction.GREATER_OR_EQUAL;\n stencilTest.backOperation.zPass = StencilOperation.REPLACE;\n renderState.stencilMask =\n StencilConstants.CESIUM_3D_TILE_MASK | StencilConstants.SKIP_LOD_MASK;\n\n stencilCommand.renderState = RenderState.fromCache(renderState);\n\n return stencilCommand;\n}\n\nexport default ModelDrawCommand;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport clone from \"../../Core/clone.js\";\nimport defined from \"../../Core/defined.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport DrawCommand from \"../../Renderer/DrawCommand.js\";\nimport RenderState from \"../../Renderer/RenderState.js\";\nimport VertexArray from \"../../Renderer/VertexArray.js\";\nimport ModelFS from \"../../Shaders/Model/ModelFS.js\";\nimport ModelVS from \"../../Shaders/Model/ModelVS.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport ShadowMode from \"../ShadowMode.js\";\nimport ClassificationModelDrawCommand from \"./ClassificationModelDrawCommand.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport ModelDrawCommand from \"./ModelDrawCommand.js\";\n\n/**\n * Builds the {@link ModelDrawCommand} for a {@link ModelRuntimePrimitive}\n * using its render resources. If the model classifies another asset, it\n * builds a {@link ClassificationModelDrawCommand} instead.\n *\n * @param {PrimitiveRenderResources} primitiveRenderResources The render resources for a primitive.\n * @param {FrameState} frameState The frame state for creating GPU resources.\n *\n * @returns {ModelDrawCommand|ClassificationModelDrawCommand} The generated ModelDrawCommand or ClassificationModelDrawCommand.\n *\n * @private\n */\nfunction buildDrawCommand(primitiveRenderResources, frameState) {\n const shaderBuilder = primitiveRenderResources.shaderBuilder;\n shaderBuilder.addVertexLines(ModelVS);\n shaderBuilder.addFragmentLines(ModelFS);\n\n const indexBuffer = getIndexBuffer(primitiveRenderResources);\n\n const vertexArray = new VertexArray({\n context: frameState.context,\n indexBuffer: indexBuffer,\n attributes: primitiveRenderResources.attributes,\n });\n\n const model = primitiveRenderResources.model;\n model._pipelineResources.push(vertexArray);\n\n const shaderProgram = shaderBuilder.buildShaderProgram(frameState.context);\n model._pipelineResources.push(shaderProgram);\n\n const pass = primitiveRenderResources.alphaOptions.pass;\n const sceneGraph = model.sceneGraph;\n\n const is3D = frameState.mode === SceneMode.SCENE3D;\n let modelMatrix, boundingSphere;\n\n if (!is3D && !frameState.scene3DOnly && model._projectTo2D) {\n modelMatrix = Matrix4.multiplyTransformation(\n sceneGraph._computedModelMatrix,\n primitiveRenderResources.runtimeNode.computedTransform,\n new Matrix4()\n );\n\n const runtimePrimitive = primitiveRenderResources.runtimePrimitive;\n boundingSphere = runtimePrimitive.boundingSphere2D;\n } else {\n const computedModelMatrix = is3D\n ? sceneGraph._computedModelMatrix\n : sceneGraph._computedModelMatrix2D;\n\n modelMatrix = Matrix4.multiplyTransformation(\n computedModelMatrix,\n primitiveRenderResources.runtimeNode.computedTransform,\n new Matrix4()\n );\n\n boundingSphere = BoundingSphere.transform(\n primitiveRenderResources.boundingSphere,\n modelMatrix,\n primitiveRenderResources.boundingSphere\n );\n }\n\n // Initialize render state with default values\n let renderState = clone(\n RenderState.fromCache(primitiveRenderResources.renderStateOptions),\n true\n );\n\n renderState.cull.face = ModelUtility.getCullFace(\n modelMatrix,\n primitiveRenderResources.primitiveType\n );\n renderState = RenderState.fromCache(renderState);\n\n const hasClassification = defined(model.classificationType);\n const castShadows = hasClassification\n ? false\n : ShadowMode.castShadows(model.shadows);\n const receiveShadows = hasClassification\n ? false\n : ShadowMode.receiveShadows(model.shadows);\n // Pick IDs are only added to specific draw commands for classification.\n // This behavior is handled by ClassificationModelDrawCommand.\n const pickId = hasClassification\n ? undefined\n : primitiveRenderResources.pickId;\n\n const command = new DrawCommand({\n boundingVolume: boundingSphere,\n modelMatrix: modelMatrix,\n uniformMap: primitiveRenderResources.uniformMap,\n renderState: renderState,\n vertexArray: vertexArray,\n shaderProgram: shaderProgram,\n cull: model.cull,\n pass: pass,\n count: primitiveRenderResources.count,\n owner: model,\n pickId: pickId,\n instanceCount: primitiveRenderResources.instanceCount,\n primitiveType: primitiveRenderResources.primitiveType,\n debugShowBoundingVolume: model.debugShowBoundingVolume,\n castShadows: castShadows,\n receiveShadows: receiveShadows,\n });\n\n if (hasClassification) {\n return new ClassificationModelDrawCommand({\n primitiveRenderResources: primitiveRenderResources,\n command: command,\n });\n }\n\n return new ModelDrawCommand({\n primitiveRenderResources: primitiveRenderResources,\n command: command,\n });\n}\n\n/**\n * @private\n */\nfunction getIndexBuffer(primitiveRenderResources) {\n const wireframeIndexBuffer = primitiveRenderResources.wireframeIndexBuffer;\n if (defined(wireframeIndexBuffer)) {\n return wireframeIndexBuffer;\n }\n\n const indices = primitiveRenderResources.indices;\n if (!defined(indices)) {\n return undefined;\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(indices.buffer)) {\n throw new DeveloperError(\"Indices must be provided as a Buffer\");\n }\n //>>includeEnd('debug');\n\n return indices.buffer;\n}\n\nexport default buildDrawCommand;\n", "import combine from \"../../Core/combine.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport Cartesian2 from \"../../Core/Cartesian2.js\";\nimport StencilConstants from \"../StencilConstants.js\";\n\n/**\n * The tileset pipeline stage is responsible for updating the model with behavior\n * specific to 3D Tiles.\n *\n * @namespace TilesetPipelineStage\n *\n * @private\n */\nconst TilesetPipelineStage = {\n name: \"TilesetPipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a model. This modifies the following parts of the render resources:\n *\n *
    \n *
  • adds a define to the fragment shader to indicate that the model uses polygon offset for the skipLevelOfDetail optimization
  • \n *
  • adds a function to the uniform map to supply polygon offset values for the skipLevelOfDetail optimization
  • \n *
  • sets stencil values that enable classification on 3D Tiles
  • \n *
\n *\n *

\n * See {@link ModelDrawCommand} for the corresponding skipLevelOfDetail derived commands.\n *

\n *\n * @param {ModelRenderResources} renderResources The render resources for this model.\n * @param {ModelExperimental} model The model.\n * @param {FrameState} frameState The frameState.\n *\n * @private\n */\nTilesetPipelineStage.process = function (renderResources, model, frameState) {\n if (model.hasSkipLevelOfDetail(frameState)) {\n // Make the log-depth depth fragment write account for the polygon offset, too.\n // Otherwise, the back face commands will cause the higher resolution\n // tiles to disappear.\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addDefine(\n \"POLYGON_OFFSET\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n // This value will be overriden by the depth-only back face derived command.\n // We just prepare it in advance so we don't have to recompile the shader.\n // We don't add a uniform declaration through ShaderBuilder because\n // this is included in writeLogDepth.glsl\n const uniformMap = {\n u_polygonOffset: function () {\n return Cartesian2.ZERO;\n },\n };\n\n renderResources.uniformMap = combine(\n uniformMap,\n renderResources.uniformMap\n );\n renderResources.hasSkipLevelOfDetail = true;\n }\n\n // Set stencil values for classification on 3D Tiles. This is applied to all\n // of the derived commands, not just the back-face derived command.\n const renderStateOptions = renderResources.renderStateOptions;\n renderStateOptions.stencilTest = StencilConstants.setCesium3DTileBit();\n renderStateOptions.stencilMask = StencilConstants.CESIUM_3D_TILE_MASK;\n};\n\nexport default TilesetPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"vec3 proceduralIBL(\\n\\\n vec3 positionEC,\\n\\\n vec3 normalEC,\\n\\\n vec3 lightDirectionEC,\\n\\\n vec3 lightColorHdr,\\n\\\n czm_pbrParameters pbrParameters\\n\\\n) {\\n\\\n vec3 v = -positionEC;\\n\\\n vec3 positionWC = vec3(czm_inverseView * vec4(positionEC, 1.0));\\n\\\n vec3 vWC = -normalize(positionWC);\\n\\\n vec3 l = normalize(lightDirectionEC);\\n\\\n vec3 n = normalEC;\\n\\\n vec3 r = normalize(czm_inverseViewRotation * normalize(reflect(v, n)));\\n\\\n\\n\\\n float NdotL = clamp(dot(n, l), 0.001, 1.0);\\n\\\n float NdotV = abs(dot(n, v)) + 0.001;\\n\\\n\\n\\\n // Figure out if the reflection vector hits the ellipsoid\\n\\\n float vertexRadius = length(positionWC);\\n\\\n float horizonDotNadir = 1.0 - min(1.0, czm_ellipsoidRadii.x / vertexRadius);\\n\\\n float reflectionDotNadir = dot(r, normalize(positionWC));\\n\\\n // Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.\\n\\\n r.x = -r.x;\\n\\\n r = -normalize(czm_temeToPseudoFixed * r);\\n\\\n r.x = -r.x;\\n\\\n\\n\\\n vec3 diffuseColor = pbrParameters.diffuseColor;\\n\\\n float roughness = pbrParameters.roughness;\\n\\\n vec3 specularColor = pbrParameters.f0;\\n\\\n\\n\\\n float inverseRoughness = 1.04 - roughness;\\n\\\n inverseRoughness *= inverseRoughness;\\n\\\n vec3 sceneSkyBox = czm_textureCube(czm_environmentMap, r).rgb * inverseRoughness;\\n\\\n\\n\\\n float atmosphereHeight = 0.05;\\n\\\n float blendRegionSize = 0.1 * ((1.0 - inverseRoughness) * 8.0 + 1.1 - horizonDotNadir);\\n\\\n float blendRegionOffset = roughness * -1.0;\\n\\\n float farAboveHorizon = clamp(horizonDotNadir - blendRegionSize * 0.5 + blendRegionOffset, 1.0e-10 - blendRegionSize, 0.99999);\\n\\\n float aroundHorizon = clamp(horizonDotNadir + blendRegionSize * 0.5, 1.0e-10 - blendRegionSize, 0.99999);\\n\\\n float farBelowHorizon = clamp(horizonDotNadir + blendRegionSize * 1.5, 1.0e-10 - blendRegionSize, 0.99999);\\n\\\n float smoothstepHeight = smoothstep(0.0, atmosphereHeight, horizonDotNadir);\\n\\\n vec3 belowHorizonColor = mix(vec3(0.1, 0.15, 0.25), vec3(0.4, 0.7, 0.9), smoothstepHeight);\\n\\\n vec3 nadirColor = belowHorizonColor * 0.5;\\n\\\n vec3 aboveHorizonColor = mix(vec3(0.9, 1.0, 1.2), belowHorizonColor, roughness * 0.5);\\n\\\n vec3 blueSkyColor = mix(vec3(0.18, 0.26, 0.48), aboveHorizonColor, reflectionDotNadir * inverseRoughness * 0.5 + 0.75);\\n\\\n vec3 zenithColor = mix(blueSkyColor, sceneSkyBox, smoothstepHeight);\\n\\\n vec3 blueSkyDiffuseColor = vec3(0.7, 0.85, 0.9); \\n\\\n float diffuseIrradianceFromEarth = (1.0 - horizonDotNadir) * (reflectionDotNadir * 0.25 + 0.75) * smoothstepHeight; \\n\\\n float diffuseIrradianceFromSky = (1.0 - smoothstepHeight) * (1.0 - (reflectionDotNadir * 0.25 + 0.25));\\n\\\n vec3 diffuseIrradiance = blueSkyDiffuseColor * clamp(diffuseIrradianceFromEarth + diffuseIrradianceFromSky, 0.0, 1.0);\\n\\\n float notDistantRough = (1.0 - horizonDotNadir * roughness * 0.8);\\n\\\n vec3 specularIrradiance = mix(zenithColor, aboveHorizonColor, smoothstep(farAboveHorizon, aroundHorizon, reflectionDotNadir) * notDistantRough);\\n\\\n specularIrradiance = mix(specularIrradiance, belowHorizonColor, smoothstep(aroundHorizon, farBelowHorizon, reflectionDotNadir) * inverseRoughness);\\n\\\n specularIrradiance = mix(specularIrradiance, nadirColor, smoothstep(farBelowHorizon, 1.0, reflectionDotNadir) * inverseRoughness);\\n\\\n\\n\\\n // Luminance model from page 40 of http://silviojemma.com/public/papers/lighting/spherical-harmonic-lighting.pdf\\n\\\n #ifdef USE_SUN_LUMINANCE \\n\\\n // Angle between sun and zenith\\n\\\n float LdotZenith = clamp(dot(normalize(czm_inverseViewRotation * l), vWC), 0.001, 1.0);\\n\\\n float S = acos(LdotZenith);\\n\\\n // Angle between zenith and current pixel\\n\\\n float NdotZenith = clamp(dot(normalize(czm_inverseViewRotation * n), vWC), 0.001, 1.0);\\n\\\n // Angle between sun and current pixel\\n\\\n float gamma = acos(NdotL);\\n\\\n float numerator = ((0.91 + 10.0 * exp(-3.0 * gamma) + 0.45 * pow(NdotL, 2.0)) * (1.0 - exp(-0.32 / NdotZenith)));\\n\\\n float denominator = (0.91 + 10.0 * exp(-3.0 * S) + 0.45 * pow(LdotZenith,2.0)) * (1.0 - exp(-0.32));\\n\\\n float luminance = model_luminanceAtZenith * (numerator / denominator);\\n\\\n #endif \\n\\\n\\n\\\n vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\\n\\\n vec3 iblColor = (diffuseIrradiance * diffuseColor * model_iblFactor.x) + (specularIrradiance * czm_srgbToLinear(specularColor * brdfLut.x + brdfLut.y) * model_iblFactor.y);\\n\\\n float maximumComponent = max(max(lightColorHdr.x, lightColorHdr.y), lightColorHdr.z);\\n\\\n vec3 lightColor = lightColorHdr / max(maximumComponent, 1.0);\\n\\\n iblColor *= lightColor;\\n\\\n\\n\\\n #ifdef USE_SUN_LUMINANCE \\n\\\n iblColor *= luminance;\\n\\\n #endif\\n\\\n\\n\\\n return iblColor;\\n\\\n}\\n\\\n\\n\\\n#if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)\\n\\\nvec3 textureIBL(\\n\\\n vec3 positionEC,\\n\\\n vec3 normalEC,\\n\\\n vec3 lightDirectionEC,\\n\\\n czm_pbrParameters pbrParameters\\n\\\n) {\\n\\\n vec3 diffuseColor = pbrParameters.diffuseColor;\\n\\\n float roughness = pbrParameters.roughness;\\n\\\n vec3 specularColor = pbrParameters.f0;\\n\\\n\\n\\\n vec3 v = -positionEC;\\n\\\n vec3 n = normalEC;\\n\\\n vec3 l = normalize(lightDirectionEC);\\n\\\n vec3 h = normalize(v + l);\\n\\\n\\n\\\n float NdotV = abs(dot(n, v)) + 0.001;\\n\\\n float VdotH = clamp(dot(v, h), 0.0, 1.0);\\n\\\n\\n\\\n const mat3 yUpToZUp = mat3(\\n\\\n -1.0, 0.0, 0.0,\\n\\\n 0.0, 0.0, -1.0, \\n\\\n 0.0, 1.0, 0.0\\n\\\n ); \\n\\\n vec3 cubeDir = normalize(yUpToZUp * model_iblReferenceFrameMatrix * normalize(reflect(-v, n))); \\n\\\n\\n\\\n #ifdef DIFFUSE_IBL \\n\\\n #ifdef CUSTOM_SPHERICAL_HARMONICS\\n\\\n vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, model_sphericalHarmonicCoefficients); \\n\\\n #else\\n\\\n vec3 diffuseIrradiance = czm_sphericalHarmonics(cubeDir, czm_sphericalHarmonicCoefficients); \\n\\\n #endif \\n\\\n #else \\n\\\n vec3 diffuseIrradiance = vec3(0.0); \\n\\\n #endif \\n\\\n\\n\\\n #ifdef SPECULAR_IBL\\n\\\n vec3 r0 = specularColor.rgb;\\n\\\n float reflectance = max(max(r0.r, r0.g), r0.b);\\n\\\n vec3 r90 = vec3(clamp(reflectance * 25.0, 0.0, 1.0));\\n\\\n vec3 F = fresnelSchlick2(r0, r90, VdotH);\\n\\\n \\n\\\n vec2 brdfLut = texture(czm_brdfLut, vec2(NdotV, roughness)).rg;\\n\\\n #ifdef CUSTOM_SPECULAR_IBL \\n\\\n vec3 specularIBL = czm_sampleOctahedralProjection(model_specularEnvironmentMaps, model_specularEnvironmentMapsSize, cubeDir, roughness * model_specularEnvironmentMapsMaximumLOD, model_specularEnvironmentMapsMaximumLOD);\\n\\\n #else \\n\\\n vec3 specularIBL = czm_sampleOctahedralProjection(czm_specularEnvironmentMaps, czm_specularEnvironmentMapSize, cubeDir, roughness * czm_specularEnvironmentMapsMaximumLOD, czm_specularEnvironmentMapsMaximumLOD);\\n\\\n #endif \\n\\\n specularIBL *= F * brdfLut.x + brdfLut.y;\\n\\\n #else \\n\\\n vec3 specularIBL = vec3(0.0); \\n\\\n #endif\\n\\\n\\n\\\n return diffuseColor * diffuseIrradiance + specularColor * specularIBL;\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\nvec3 imageBasedLightingStage(\\n\\\n vec3 positionEC,\\n\\\n vec3 normalEC,\\n\\\n vec3 lightDirectionEC,\\n\\\n vec3 lightColorHdr,\\n\\\n czm_pbrParameters pbrParameters\\n\\\n) {\\n\\\n #if defined(DIFFUSE_IBL) || defined(SPECULAR_IBL)\\n\\\n // Environment maps were provided, use them for IBL\\n\\\n return textureIBL(\\n\\\n positionEC,\\n\\\n normalEC,\\n\\\n lightDirectionEC,\\n\\\n pbrParameters\\n\\\n );\\n\\\n #else\\n\\\n // Use the procedural IBL if there are no environment maps\\n\\\n return proceduralIBL(\\n\\\n positionEC,\\n\\\n normalEC,\\n\\\n lightDirectionEC,\\n\\\n lightColorHdr,\\n\\\n pbrParameters\\n\\\n );\\n\\\n #endif\\n\\\n}\";\n", "import combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport ImageBasedLightingStageFS from \"../../Shaders/Model/ImageBasedLightingStageFS.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport OctahedralProjectedCubeMap from \"../OctahedralProjectedCubeMap.js\";\n\nconst ImageBasedLightingPipelineStage = {\n name: \"ImageBasedLightingPipelineStage\", // Helps with debugging\n};\n\nImageBasedLightingPipelineStage.process = function (\n renderResources,\n model,\n frameState\n) {\n const imageBasedLighting = model.imageBasedLighting;\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"USE_IBL_LIGHTING\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"vec2\",\n \"model_iblFactor\",\n ShaderDestination.FRAGMENT\n );\n\n if (OctahedralProjectedCubeMap.isSupported(frameState.context)) {\n const addMatrix =\n imageBasedLighting.useSphericalHarmonics ||\n imageBasedLighting.useSpecularEnvironmentMaps ||\n imageBasedLighting.enabled;\n if (addMatrix) {\n shaderBuilder.addUniform(\n \"mat3\",\n \"model_iblReferenceFrameMatrix\",\n ShaderDestination.FRAGMENT\n );\n }\n\n if (defined(imageBasedLighting.sphericalHarmonicCoefficients)) {\n shaderBuilder.addDefine(\n \"DIFFUSE_IBL\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addDefine(\n \"CUSTOM_SPHERICAL_HARMONICS\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"vec3\",\n \"model_sphericalHarmonicCoefficients[9]\",\n ShaderDestination.FRAGMENT\n );\n } else if (imageBasedLighting.useDefaultSphericalHarmonics) {\n shaderBuilder.addDefine(\n \"DIFFUSE_IBL\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n if (\n defined(imageBasedLighting.specularEnvironmentMapAtlas) &&\n imageBasedLighting.specularEnvironmentMapAtlas.ready\n ) {\n shaderBuilder.addDefine(\n \"SPECULAR_IBL\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addDefine(\n \"CUSTOM_SPECULAR_IBL\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"sampler2D\",\n \"model_specularEnvironmentMaps\",\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"vec2\",\n \"model_specularEnvironmentMapsSize\",\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"float\",\n \"model_specularEnvironmentMapsMaximumLOD\",\n ShaderDestination.FRAGMENT\n );\n } else if (model.useDefaultSpecularMaps) {\n shaderBuilder.addDefine(\n \"SPECULAR_IBL\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n }\n\n if (defined(imageBasedLighting.luminanceAtZenith)) {\n shaderBuilder.addDefine(\n \"USE_SUN_LUMINANCE\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"float\",\n \"model_luminanceAtZenith\",\n ShaderDestination.FRAGMENT\n );\n }\n\n shaderBuilder.addFragmentLines(ImageBasedLightingStageFS);\n\n const uniformMap = {\n model_iblFactor: function () {\n return imageBasedLighting.imageBasedLightingFactor;\n },\n model_iblReferenceFrameMatrix: function () {\n return model._iblReferenceFrameMatrix;\n },\n model_luminanceAtZenith: function () {\n return imageBasedLighting.luminanceAtZenith;\n },\n model_sphericalHarmonicCoefficients: function () {\n return imageBasedLighting.sphericalHarmonicCoefficients;\n },\n model_specularEnvironmentMaps: function () {\n return imageBasedLighting.specularEnvironmentMapAtlas.texture;\n },\n model_specularEnvironmentMapsSize: function () {\n return imageBasedLighting.specularEnvironmentMapAtlas.texture.dimensions;\n },\n model_specularEnvironmentMapsMaximumLOD: function () {\n return imageBasedLighting.specularEnvironmentMapAtlas.maximumMipmapLevel;\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n};\n\nexport default ImageBasedLightingPipelineStage;\n", "import ArticulationStageType from \"../../Core/ArticulationStageType.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport CesiumMath from \"../../Core/Math.js\";\nimport Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport Matrix3 from \"../../Core/Matrix3.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\n\nconst articulationEpsilon = CesiumMath.EPSILON16;\n\n/**\n * An in-memory representation of an articulation stage belonging to a\n * {@link ModelArticulation}.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.ArticulationStage} options.stage The articulation stage components from the 3D model.\n * @param {ModelArticulation} options.runtimeArticulation The runtime articulation that this stage belongs to.\n *\n * @alias ModelArticulationStage\n * @constructor\n *\n * @private\n */\nfunction ModelArticulationStage(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const stage = options.stage;\n const runtimeArticulation = options.runtimeArticulation;\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.stage\", stage);\n Check.typeOf.object(\"options.runtimeArticulation\", runtimeArticulation);\n //>>includeEnd('debug');\n\n this._stage = stage;\n this._runtimeArticulation = runtimeArticulation;\n\n this._name = stage.name;\n this._type = stage.type;\n this._minimumValue = stage.minimumValue;\n this._maximumValue = stage.maximumValue;\n this._currentValue = stage.initialValue;\n}\n\nObject.defineProperties(ModelArticulationStage.prototype, {\n /**\n * The internal articulation stage that this runtime stage represents.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {ModelComponents.ArticulationStage}\n * @readonly\n *\n * @private\n */\n stage: {\n get: function () {\n return this._stage;\n },\n },\n\n /**\n * The runtime articulation that this stage belongs to.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {ModelArticulation}\n * @readonly\n *\n * @private\n */\n runtimeArticulation: {\n get: function () {\n return this._runtimeArticulation;\n },\n },\n\n /**\n * The name of this articulation stage.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {string}\n * @readonly\n *\n * @private\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The type of this articulation stage. This specifies which of the\n * node's properties is modified by the stage's value.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {ArticulationStageType}\n * @readonly\n *\n * @private\n */\n type: {\n get: function () {\n return this._type;\n },\n },\n\n /**\n * The minimum value of this articulation stage.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {number}\n * @readonly\n *\n * @private\n */\n minimumValue: {\n get: function () {\n return this._minimumValue;\n },\n },\n\n /**\n * The maximum value of this articulation stage.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {number}\n * @readonly\n *\n * @private\n */\n maximumValue: {\n get: function () {\n return this._maximumValue;\n },\n },\n\n /**\n * The current value of this articulation stage.\n *\n * @memberof ModelArticulationStage.prototype\n * @type {number}\n *\n * @private\n */\n currentValue: {\n get: function () {\n return this._currentValue;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n value = CesiumMath.clamp(value, this.minimumValue, this.maximumValue);\n if (\n !CesiumMath.equalsEpsilon(\n this._currentValue,\n value,\n articulationEpsilon\n )\n ) {\n this._currentValue = value;\n this.runtimeArticulation._dirty = true;\n }\n },\n },\n});\n\nconst scratchArticulationCartesian = new Cartesian3();\nconst scratchArticulationRotation = new Matrix3();\n\n/**\n * Modifies a Matrix4 by applying a transformation for a given value of a stage.\n * Note that the result parameter is not just a container for the\n * returned value. The incoming value of result is part of the\n * computation itself. Various stages of an articulation can be multiplied\n * together, so their transformations are all merged into a composite Matrix4\n * representing them all.\n *\n * @param {Matrix4} result The matrix to be modified.\n * @returns {Matrix4} The transformed matrix as requested by the articulation stage.\n *\n * @private\n */\nModelArticulationStage.prototype.applyStageToMatrix = function (result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"result\", result);\n //>>includeEnd('debug');\n\n const type = this.type;\n const value = this.currentValue;\n const cartesian = scratchArticulationCartesian;\n let rotation;\n switch (type) {\n case ArticulationStageType.XROTATE:\n rotation = Matrix3.fromRotationX(\n CesiumMath.toRadians(value),\n scratchArticulationRotation\n );\n result = Matrix4.multiplyByMatrix3(result, rotation, result);\n break;\n case ArticulationStageType.YROTATE:\n rotation = Matrix3.fromRotationY(\n CesiumMath.toRadians(value),\n scratchArticulationRotation\n );\n result = Matrix4.multiplyByMatrix3(result, rotation, result);\n break;\n case ArticulationStageType.ZROTATE:\n rotation = Matrix3.fromRotationZ(\n CesiumMath.toRadians(value),\n scratchArticulationRotation\n );\n result = Matrix4.multiplyByMatrix3(result, rotation, result);\n break;\n case ArticulationStageType.XTRANSLATE:\n cartesian.x = value;\n cartesian.y = 0.0;\n cartesian.z = 0.0;\n result = Matrix4.multiplyByTranslation(result, cartesian, result);\n break;\n case ArticulationStageType.YTRANSLATE:\n cartesian.x = 0.0;\n cartesian.y = value;\n cartesian.z = 0.0;\n result = Matrix4.multiplyByTranslation(result, cartesian, result);\n break;\n case ArticulationStageType.ZTRANSLATE:\n cartesian.x = 0.0;\n cartesian.y = 0.0;\n cartesian.z = value;\n result = Matrix4.multiplyByTranslation(result, cartesian, result);\n break;\n case ArticulationStageType.XSCALE:\n cartesian.x = value;\n cartesian.y = 1.0;\n cartesian.z = 1.0;\n result = Matrix4.multiplyByScale(result, cartesian, result);\n break;\n case ArticulationStageType.YSCALE:\n cartesian.x = 1.0;\n cartesian.y = value;\n cartesian.z = 1.0;\n result = Matrix4.multiplyByScale(result, cartesian, result);\n break;\n case ArticulationStageType.ZSCALE:\n cartesian.x = 1.0;\n cartesian.y = 1.0;\n cartesian.z = value;\n result = Matrix4.multiplyByScale(result, cartesian, result);\n break;\n case ArticulationStageType.UNIFORMSCALE:\n result = Matrix4.multiplyByUniformScale(result, value, result);\n break;\n default:\n break;\n }\n\n return result;\n};\n\nexport default ModelArticulationStage;\n", "import Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport ModelArticulationStage from \"./ModelArticulationStage.js\";\n\n/**\n * An in-memory representation of an articulation that affects nodes in the\n * {@link ModelSceneGraph}. This is defined in a model by the\n * AGI_articulations extension.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.Articulation} options.articulation The articulation components from the 3D model.\n * @param {ModelSceneGraph} options.sceneGraph The scene graph this articulation belongs to.\n *\n * @alias ModelArticulation\n * @constructor\n *\n * @private\n */\nfunction ModelArticulation(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const articulation = options.articulation;\n const sceneGraph = options.sceneGraph;\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.articulation\", articulation);\n Check.typeOf.object(\"options.sceneGraph\", sceneGraph);\n //>>includeEnd('debug');\n\n this._articulation = articulation;\n this._sceneGraph = sceneGraph;\n\n this._name = articulation.name;\n this._runtimeStages = [];\n this._runtimeStagesByName = {};\n\n // Will be populated as the runtime nodes are created\n this._runtimeNodes = [];\n\n // Set to true so that the first call to\n // ModelSceneGraph.applyArticulations will work.\n this._dirty = true;\n\n initialize(this);\n}\n\nObject.defineProperties(ModelArticulation.prototype, {\n /**\n * The internal articulation that this runtime articulation represents.\n *\n * @memberof ModelArticulation.prototype\n * @type {ModelComponents.Articulation}\n * @readonly\n *\n * @private\n */\n articulation: {\n get: function () {\n return this._articulation;\n },\n },\n\n /**\n * The scene graph that this articulation belongs to.\n *\n * @memberof ModelArticulation.prototype\n * @type {ModelSceneGraph}\n * @readonly\n *\n * @private\n */\n sceneGraph: {\n get: function () {\n return this._sceneGraph;\n },\n },\n\n /**\n * The name of this articulation.\n *\n * @memberof ModelArticulation.prototype\n * @type {string}\n * @readonly\n *\n * @private\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n\n /**\n * The runtime stages that belong to this articulation.\n *\n * @memberof ModelArticulation.prototype\n * @type {ModelArticulationStage[]}\n * @readonly\n *\n * @private\n */\n runtimeStages: {\n get: function () {\n return this._runtimeStages;\n },\n },\n\n /**\n * The runtime nodes that are affected by this articulation.\n *\n * @memberof ModelArticulation.prototype\n * @type {ModelRuntimeNode[]}\n * @readonly\n *\n * @private\n */\n runtimeNodes: {\n get: function () {\n return this._runtimeNodes;\n },\n },\n});\n\nfunction initialize(runtimeArticulation) {\n const articulation = runtimeArticulation.articulation;\n\n const stages = articulation.stages;\n const length = stages.length;\n\n const runtimeStages = runtimeArticulation._runtimeStages;\n const runtimeStagesByName = runtimeArticulation._runtimeStagesByName;\n for (let i = 0; i < length; i++) {\n const stage = stages[i];\n const runtimeStage = new ModelArticulationStage({\n stage: stage,\n runtimeArticulation: runtimeArticulation,\n });\n\n // Store the stages in an array to preserve the order in which\n // they appeared in the 3D model.\n runtimeStages.push(runtimeStage);\n\n // Store the stages in a dictionary for retrieval by name.\n const stageName = stage.name;\n runtimeStagesByName[stageName] = runtimeStage;\n }\n}\n\n/**\n * Sets the current value of an articulation stage.\n *\n * @param {string} stageName The name of the articulation stage.\n * @param {number} value The numeric value of this stage of the articulation.\n *\n * @private\n */\nModelArticulation.prototype.setArticulationStage = function (stageName, value) {\n const stage = this._runtimeStagesByName[stageName];\n if (defined(stage)) {\n stage.currentValue = value;\n }\n};\n\nconst scratchArticulationMatrix = new Matrix4();\nconst scratchNodeMatrix = new Matrix4();\n\n/**\n * Applies the chain of articulation stages to the transform of each node that\n * participates in the articulation. This only recomputes the node transforms\n * if any stage in the articulation has been modified.\n *

\n * Note that this will overwrite any existing transformations on participating\n * nodes.\n *

\n *\n * @private\n */\nModelArticulation.prototype.apply = function () {\n if (!this._dirty) {\n return;\n }\n this._dirty = false;\n\n let articulationMatrix = Matrix4.clone(\n Matrix4.IDENTITY,\n scratchArticulationMatrix\n );\n\n let i;\n const stages = this._runtimeStages;\n const stagesLength = stages.length;\n\n // Compute the result of the articulation stages...\n for (i = 0; i < stagesLength; i++) {\n const stage = stages[i];\n articulationMatrix = stage.applyStageToMatrix(articulationMatrix);\n }\n\n // ...then apply it to the transforms of the affected nodes.\n const nodes = this._runtimeNodes;\n const nodesLength = nodes.length;\n for (i = 0; i < nodesLength; i++) {\n const node = nodes[i];\n const transform = Matrix4.multiplyTransformation(\n node.originalTransform,\n articulationMatrix,\n scratchNodeMatrix\n );\n node.transform = transform;\n }\n};\n\nexport default ModelArticulation;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void modelColorStage(inout czm_modelMaterial material)\\n\\\n{\\n\\\n material.diffuse = mix(material.diffuse, model_color.rgb, model_colorBlend);\\n\\\n float highlight = ceil(model_colorBlend);\\n\\\n material.diffuse *= mix(model_color.rgb, vec3(1.0), highlight);\\n\\\n material.alpha *= model_color.a;\\n\\\n}\";\n", "import ColorBlendMode from \"../ColorBlendMode.js\";\nimport combine from \"../../Core/combine.js\";\nimport ModelColorStageFS from \"../../Shaders/Model/ModelColorStageFS.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\n\n/**\n * The model color pipeline stage is responsible for handling the application of a static color to the model.\n *\n * @namespace ModelColorPipelineStage\n *\n * @private\n */\nconst ModelColorPipelineStage = {\n name: \"ModelColorPipelineStage\", // Helps with debugging\n\n COLOR_UNIFORM_NAME: \"model_color\",\n COLOR_BLEND_UNIFORM_NAME: \"model_colorBlend\",\n};\n\n/**\n * Process a model. This modifies the following parts of the render resources:\n *\n *
    \n *
  • adds a define to the fragment shader to indicate that the model has a color
  • \n *
  • adds a function to the fragment shader to apply the color to the model's base color
  • \n *
  • adds the uniforms for the fragment shader for the model's color and blending properties
  • \n *
  • updates the pass type in the render resources based on translucency of the model's color
  • \n *
\n *\n * @param {ModelRenderResources} renderResources The render resources for this model.\n * @param {Model} model The model.\n * @param {FrameState} frameState The frameState.\n *\n * @private\n */\nModelColorPipelineStage.process = function (\n renderResources,\n model,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"HAS_MODEL_COLOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addFragmentLines(ModelColorStageFS);\n\n const stageUniforms = {};\n\n // Pass the model's color as a uniform. Set the pass type to translucent, if needed.\n const color = model.color;\n\n if (color.alpha === 0.0 && !model.hasSilhouette(frameState)) {\n renderResources.renderStateOptions.colorMask = {\n red: false,\n green: false,\n blue: false,\n alpha: false,\n };\n }\n\n if (color.alpha < 1.0) {\n renderResources.alphaOptions.pass = Pass.TRANSLUCENT;\n }\n\n shaderBuilder.addUniform(\n \"vec4\",\n ModelColorPipelineStage.COLOR_UNIFORM_NAME,\n ShaderDestination.FRAGMENT\n );\n stageUniforms[ModelColorPipelineStage.COLOR_UNIFORM_NAME] = function () {\n return model.color;\n };\n\n // Create a colorBlend from the model's colorBlendMode and colorBlendAmount and pass it as a uniform.\n shaderBuilder.addUniform(\n \"float\",\n ModelColorPipelineStage.COLOR_BLEND_UNIFORM_NAME,\n ShaderDestination.FRAGMENT\n );\n stageUniforms[\n ModelColorPipelineStage.COLOR_BLEND_UNIFORM_NAME\n ] = function () {\n return ColorBlendMode.getColorBlend(\n model.colorBlendMode,\n model.colorBlendAmount\n );\n };\n\n renderResources.uniformMap = combine(\n stageUniforms,\n renderResources.uniformMap\n );\n};\n\nexport default ModelColorPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef USE_CLIPPING_PLANES_FLOAT_TEXTURE\\n\\\nvec4 getClippingPlane(\\n\\\n highp sampler2D packedClippingPlanes,\\n\\\n int clippingPlaneNumber,\\n\\\n mat4 transform\\n\\\n) {\\n\\\n int pixY = clippingPlaneNumber / CLIPPING_PLANES_TEXTURE_WIDTH;\\n\\\n int pixX = clippingPlaneNumber - (pixY * CLIPPING_PLANES_TEXTURE_WIDTH);\\n\\\n float pixelWidth = 1.0 / float(CLIPPING_PLANES_TEXTURE_WIDTH);\\n\\\n float pixelHeight = 1.0 / float(CLIPPING_PLANES_TEXTURE_HEIGHT);\\n\\\n float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel\\n\\\n float v = (float(pixY) + 0.5) * pixelHeight;\\n\\\n vec4 plane = texture(packedClippingPlanes, vec2(u, v));\\n\\\n return czm_transformPlane(plane, transform);\\n\\\n}\\n\\\n#else\\n\\\n// Handle uint8 clipping texture instead\\n\\\nvec4 getClippingPlane(\\n\\\n highp sampler2D packedClippingPlanes,\\n\\\n int clippingPlaneNumber,\\n\\\n mat4 transform\\n\\\n) {\\n\\\n int clippingPlaneStartIndex = clippingPlaneNumber * 2; // clipping planes are two pixels each\\n\\\n int pixY = clippingPlaneStartIndex / CLIPPING_PLANES_TEXTURE_WIDTH;\\n\\\n int pixX = clippingPlaneStartIndex - (pixY * CLIPPING_PLANES_TEXTURE_WIDTH);\\n\\\n float pixelWidth = 1.0 / float(CLIPPING_PLANES_TEXTURE_WIDTH);\\n\\\n float pixelHeight = 1.0 / float(CLIPPING_PLANES_TEXTURE_HEIGHT);\\n\\\n float u = (float(pixX) + 0.5) * pixelWidth; // sample from center of pixel\\n\\\n float v = (float(pixY) + 0.5) * pixelHeight;\\n\\\n vec4 oct32 = texture(packedClippingPlanes, vec2(u, v)) * 255.0;\\n\\\n vec2 oct = vec2(oct32.x * 256.0 + oct32.y, oct32.z * 256.0 + oct32.w);\\n\\\n vec4 plane;\\n\\\n plane.xyz = czm_octDecode(oct, 65535.0);\\n\\\n plane.w = czm_unpackFloat(texture(packedClippingPlanes, vec2(u + pixelWidth, v)));\\n\\\n return czm_transformPlane(plane, transform);\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\nfloat clip(vec4 fragCoord, sampler2D clippingPlanes, mat4 clippingPlanesMatrix) {\\n\\\n vec4 position = czm_windowToEyeCoordinates(fragCoord);\\n\\\n vec3 clipNormal = vec3(0.0);\\n\\\n vec3 clipPosition = vec3(0.0);\\n\\\n float pixelWidth = czm_metersPerPixel(position);\\n\\\n \\n\\\n #ifdef UNION_CLIPPING_REGIONS\\n\\\n float clipAmount; // For union planes, we want to get the min distance. So we set the initial value to the first plane distance in the loop below.\\n\\\n #else\\n\\\n float clipAmount = 0.0;\\n\\\n bool clipped = true;\\n\\\n #endif\\n\\\n\\n\\\n for (int i = 0; i < CLIPPING_PLANES_LENGTH; ++i) {\\n\\\n vec4 clippingPlane = getClippingPlane(clippingPlanes, i, clippingPlanesMatrix);\\n\\\n clipNormal = clippingPlane.xyz;\\n\\\n clipPosition = -clippingPlane.w * clipNormal;\\n\\\n float amount = dot(clipNormal, (position.xyz - clipPosition)) / pixelWidth;\\n\\\n \\n\\\n #ifdef UNION_CLIPPING_REGIONS\\n\\\n clipAmount = czm_branchFreeTernary(i == 0, amount, min(amount, clipAmount));\\n\\\n if (amount <= 0.0) {\\n\\\n discard;\\n\\\n }\\n\\\n #else\\n\\\n clipAmount = max(amount, clipAmount);\\n\\\n clipped = clipped && (amount <= 0.0);\\n\\\n #endif\\n\\\n }\\n\\\n\\n\\\n #ifndef UNION_CLIPPING_REGIONS\\n\\\n if (clipped) {\\n\\\n discard;\\n\\\n }\\n\\\n #endif\\n\\\n \\n\\\n return clipAmount;\\n\\\n}\\n\\\n\\n\\\nvoid modelClippingPlanesStage(inout vec4 color)\\n\\\n{\\n\\\n float clipDistance = clip(gl_FragCoord, model_clippingPlanes, model_clippingPlanesMatrix);\\n\\\n vec4 clippingPlanesEdgeColor = vec4(1.0);\\n\\\n clippingPlanesEdgeColor.rgb = model_clippingPlanesEdgeStyle.rgb;\\n\\\n float clippingPlanesEdgeWidth = model_clippingPlanesEdgeStyle.a;\\n\\\n \\n\\\n if (clipDistance > 0.0 && clipDistance < clippingPlanesEdgeWidth) {\\n\\\n color = clippingPlanesEdgeColor;\\n\\\n }\\n\\\n}\\n\\\n\";\n", "import Cartesian2 from \"../../Core/Cartesian2.js\";\nimport ClippingPlaneCollection from \"../ClippingPlaneCollection.js\";\nimport combine from \"../../Core/combine.js\";\nimport Color from \"../../Core/Color.js\";\nimport ModelClippingPlanesStageFS from \"../../Shaders/Model/ModelClippingPlanesStageFS.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\n\n/**\n * The model clipping planes stage is responsible for applying clipping planes to the model.\n *\n * @namespace ModelClippingPlanesPipelineStage\n *\n * @private\n */\nconst ModelClippingPlanesPipelineStage = {\n name: \"ModelClippingPlanesPipelineStage\", // Helps with debugging\n};\n\nconst textureResolutionScratch = new Cartesian2();\n/**\n * Process a model. This modifies the following parts of the render resources:\n *\n *
    \n *
  • adds a define to the fragment shader to indicate that the model has clipping planes
  • \n *
  • adds the defines to the fragment shader for parameters related to clipping planes, such as the number of planes
  • \n *
  • adds a function to the fragment shader to apply the clipping planes to the model's base color
  • \n *
  • adds the uniforms for the fragment shader for the clipping plane texture and matrix
  • \n *
\n *\n * @param {ModelRenderResources} renderResources The render resources for this model.\n * @param {Model} model The model.\n * @param {FrameState} frameState The frameState.\n *\n * @private\n */\nModelClippingPlanesPipelineStage.process = function (\n renderResources,\n model,\n frameState\n) {\n const clippingPlanes = model.clippingPlanes;\n const context = frameState.context;\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"HAS_CLIPPING_PLANES\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addDefine(\n \"CLIPPING_PLANES_LENGTH\",\n clippingPlanes.length,\n ShaderDestination.FRAGMENT\n );\n\n if (clippingPlanes.unionClippingRegions) {\n shaderBuilder.addDefine(\n \"UNION_CLIPPING_REGIONS\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n if (ClippingPlaneCollection.useFloatTexture(context)) {\n shaderBuilder.addDefine(\n \"USE_CLIPPING_PLANES_FLOAT_TEXTURE\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const textureResolution = ClippingPlaneCollection.getTextureResolution(\n clippingPlanes,\n context,\n textureResolutionScratch\n );\n\n shaderBuilder.addDefine(\n \"CLIPPING_PLANES_TEXTURE_WIDTH\",\n textureResolution.x,\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addDefine(\n \"CLIPPING_PLANES_TEXTURE_HEIGHT\",\n textureResolution.y,\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addUniform(\n \"sampler2D\",\n \"model_clippingPlanes\",\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"vec4\",\n \"model_clippingPlanesEdgeStyle\",\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"mat4\",\n \"model_clippingPlanesMatrix\",\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addFragmentLines(ModelClippingPlanesStageFS);\n\n const uniformMap = {\n model_clippingPlanes: function () {\n return clippingPlanes.texture;\n },\n model_clippingPlanesEdgeStyle: function () {\n const style = Color.clone(clippingPlanes.edgeColor);\n style.alpha = clippingPlanes.edgeWidth;\n return style;\n },\n model_clippingPlanesMatrix: function () {\n return model._clippingPlanesMatrix;\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n};\n\nexport default ModelClippingPlanesPipelineStage;\n", "import Check from \"../../Core/Check.js\";\nimport defined from \"../../Core/defined.js\";\n\n/**\n *
\n * Use {@link Model#getNode} to get a node from a loaded model. Do not call the constructor directly.\n *
\n *\n * A model node with a modifiable transform to allow users to define their\n * own animations. While a model's asset can contain animations that target\n * a node's transform, this class allows users to change a node's transform\n * externally. In this way, animation can be driven by another source, not\n * just by the model's asset.\n *\n * @alias ModelNode\n * @internalConstructor\n * @class\n *\n * @example\n * const node = model.getNode(\"Hand\");\n * node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);\n *\n * @see Model#getNode\n */\nfunction ModelNode(model, runtimeNode) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"model\", model);\n Check.typeOf.object(\"runtimeNode\", runtimeNode);\n //>>includeEnd('debug')\n\n this._model = model;\n this._runtimeNode = runtimeNode;\n}\n\nObject.defineProperties(ModelNode.prototype, {\n /**\n * The value of the name property of this node.\n *\n * @memberof ModelNode.prototype\n *\n * @type {string}\n * @readonly\n */\n name: {\n get: function () {\n return this._runtimeNode._name;\n },\n },\n\n /**\n * The index of the node in the glTF.\n *\n * @memberof ModelNode.prototype\n *\n * @type {number}\n * @readonly\n */\n id: {\n get: function () {\n return this._runtimeNode._id;\n },\n },\n\n /**\n * Determines if this node and its children will be shown.\n *\n * @memberof ModelNode.prototype\n * @type {boolean}\n *\n * @default true\n */\n show: {\n get: function () {\n return this._runtimeNode.show;\n },\n set: function (value) {\n this._runtimeNode.show = value;\n },\n },\n\n /**\n * The node's 4x4 matrix transform from its local coordinates to\n * its parent's. Setting the matrix to undefined will restore the\n * node's original transform, and allow the node to be animated by\n * any animations in the model again.\n *

\n * For changes to take effect, this property must be assigned to;\n * setting individual elements of the matrix will not work.\n *

\n *\n * @memberof ModelNode.prototype\n * @type {Matrix4}\n */\n matrix: {\n get: function () {\n return this._runtimeNode.transform;\n },\n set: function (value) {\n if (defined(value)) {\n this._runtimeNode.transform = value;\n this._runtimeNode.userAnimated = true;\n this._model._userAnimationDirty = true;\n } else {\n this._runtimeNode.transform = this.originalMatrix;\n this._runtimeNode.userAnimated = false;\n }\n },\n },\n\n /**\n * Gets the node's original 4x4 matrix transform from its local\n * coordinates to its parent's, without any node transformations\n * or articulations applied.\n *\n * @memberof ModelNode.prototype\n * @type {Matrix4}\n */\n originalMatrix: {\n get: function () {\n return this._runtimeNode.originalTransform;\n },\n },\n});\n\nexport default ModelNode;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"mat4 getInstancingTransform()\\n\\\n{\\n\\\n mat4 instancingTransform;\\n\\\n\\n\\\n #ifdef HAS_INSTANCE_MATRICES\\n\\\n instancingTransform = mat4(\\n\\\n a_instancingTransformRow0.x, a_instancingTransformRow1.x, a_instancingTransformRow2.x, 0.0, // Column 1\\n\\\n a_instancingTransformRow0.y, a_instancingTransformRow1.y, a_instancingTransformRow2.y, 0.0, // Column 2\\n\\\n a_instancingTransformRow0.z, a_instancingTransformRow1.z, a_instancingTransformRow2.z, 0.0, // Column 3\\n\\\n a_instancingTransformRow0.w, a_instancingTransformRow1.w, a_instancingTransformRow2.w, 1.0 // Column 4\\n\\\n );\\n\\\n #else\\n\\\n vec3 translation = vec3(0.0, 0.0, 0.0);\\n\\\n vec3 scale = vec3(1.0, 1.0, 1.0);\\n\\\n \\n\\\n #ifdef HAS_INSTANCE_TRANSLATION\\n\\\n translation = a_instanceTranslation;\\n\\\n #endif\\n\\\n #ifdef HAS_INSTANCE_SCALE\\n\\\n scale = a_instanceScale;\\n\\\n #endif\\n\\\n\\n\\\n instancingTransform = mat4(\\n\\\n scale.x, 0.0, 0.0, 0.0,\\n\\\n 0.0, scale.y, 0.0, 0.0,\\n\\\n 0.0, 0.0, scale.z, 0.0,\\n\\\n translation.x, translation.y, translation.z, 1.0\\n\\\n ); \\n\\\n #endif\\n\\\n\\n\\\n return instancingTransform;\\n\\\n}\\n\\\n\\n\\\n#ifdef USE_2D_INSTANCING\\n\\\nmat4 getInstancingTransform2D()\\n\\\n{\\n\\\n mat4 instancingTransform2D;\\n\\\n\\n\\\n #ifdef HAS_INSTANCE_MATRICES\\n\\\n instancingTransform2D = mat4(\\n\\\n a_instancingTransform2DRow0.x, a_instancingTransform2DRow1.x, a_instancingTransform2DRow2.x, 0.0, // Column 1\\n\\\n a_instancingTransform2DRow0.y, a_instancingTransform2DRow1.y, a_instancingTransform2DRow2.y, 0.0, // Column 2\\n\\\n a_instancingTransform2DRow0.z, a_instancingTransform2DRow1.z, a_instancingTransform2DRow2.z, 0.0, // Column 3\\n\\\n a_instancingTransform2DRow0.w, a_instancingTransform2DRow1.w, a_instancingTransform2DRow2.w, 1.0 // Column 4\\n\\\n );\\n\\\n #else\\n\\\n vec3 translation2D = vec3(0.0, 0.0, 0.0);\\n\\\n vec3 scale = vec3(1.0, 1.0, 1.0);\\n\\\n \\n\\\n #ifdef HAS_INSTANCE_TRANSLATION\\n\\\n translation2D = a_instanceTranslation2D;\\n\\\n #endif\\n\\\n #ifdef HAS_INSTANCE_SCALE\\n\\\n scale = a_instanceScale;\\n\\\n #endif\\n\\\n\\n\\\n instancingTransform2D = mat4(\\n\\\n scale.x, 0.0, 0.0, 0.0,\\n\\\n 0.0, scale.y, 0.0, 0.0,\\n\\\n 0.0, 0.0, scale.z, 0.0,\\n\\\n translation2D.x, translation2D.y, translation2D.z, 1.0\\n\\\n ); \\n\\\n #endif\\n\\\n\\n\\\n return instancingTransform2D;\\n\\\n}\\n\\\n#endif\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void instancingStage(inout ProcessedAttributes attributes) \\n\\\n{\\n\\\n vec3 positionMC = attributes.positionMC;\\n\\\n \\n\\\n mat4 instancingTransform = getInstancingTransform();\\n\\\n \\n\\\n attributes.positionMC = (instancingTransform * vec4(positionMC, 1.0)).xyz;\\n\\\n\\n\\\n #ifdef HAS_NORMALS\\n\\\n vec3 normalMC = attributes.normalMC;\\n\\\n attributes.normalMC = (instancingTransform * vec4(normalMC, 0.0)).xyz;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef USE_2D_INSTANCING\\n\\\n mat4 instancingTransform2D = getInstancingTransform2D();\\n\\\n attributes.position2D = (instancingTransform2D * vec4(positionMC, 1.0)).xyz;\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void legacyInstancingStage(\\n\\\n inout ProcessedAttributes attributes,\\n\\\n out mat4 instanceModelView,\\n\\\n out mat3 instanceModelViewInverseTranspose)\\n\\\n{\\n\\\n vec3 positionMC = attributes.positionMC;\\n\\\n\\n\\\n mat4 instancingTransform = getInstancingTransform();\\n\\\n \\n\\\n mat4 instanceModel = instancingTransform * u_instance_nodeTransform;\\n\\\n instanceModelView = u_instance_modifiedModelView;\\n\\\n instanceModelViewInverseTranspose = mat3(u_instance_modifiedModelView * instanceModel);\\n\\\n\\n\\\n attributes.positionMC = (instanceModel * vec4(positionMC, 1.0)).xyz;\\n\\\n \\n\\\n #ifdef USE_2D_INSTANCING\\n\\\n mat4 instancingTransform2D = getInstancingTransform2D();\\n\\\n attributes.position2D = (instancingTransform2D * vec4(positionMC, 1.0)).xyz;\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "import AttributeCompression from \"../../Core/AttributeCompression.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport clone from \"../../Core/clone.js\";\nimport combine from \"../../Core/combine.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport Transforms from \"../../Core/Transforms.js\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport InstancingStageCommon from \"../../Shaders/Model/InstancingStageCommon.js\";\nimport InstancingStageVS from \"../../Shaders/Model/InstancingStageVS.js\";\nimport LegacyInstancingStageVS from \"../../Shaders/Model/LegacyInstancingStageVS.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport InstanceAttributeSemantic from \"../InstanceAttributeSemantic.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport SceneTransforms from \"../SceneTransforms.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\nconst modelViewScratch = new Matrix4();\nconst nodeTransformScratch = new Matrix4();\nconst modelView2DScratch = new Matrix4();\n\n/**\n * The instancing pipeline stage is responsible for handling GPU mesh instancing at the node\n * level.\n *\n * @namespace InstancingPipelineStage\n * @private\n */\nconst InstancingPipelineStage = {\n name: \"InstancingPipelineStage\", // Helps with debugging\n\n // Expose some methods for testing\n _getInstanceTransformsAsMatrices: getInstanceTransformsAsMatrices,\n _transformsToTypedArray: transformsToTypedArray,\n};\n\n/**\n * Process a node. This modifies the following parts of the render resources:\n *
    \n *
  • creates buffers for the typed arrays of each attribute, if they do not yet exist\n *
  • adds attribute declarations for the instancing vertex attributes in the vertex shader
  • \n *
  • sets the instancing translation min and max to compute an accurate bounding volume
  • \n *
\n *\n * If the scene is in either 2D or CV mode, this stage also:\n *
    \n *
  • adds additional attributes for the transformation attributes projected to 2D\n *
  • adds a flag to the shader to use the 2D instanced attributes\n *
  • adds a uniform for the view model matrix in 2D\n *
\n *\n * @param {NodeRenderResources} renderResources The render resources for this node.\n * @param {ModelComponents.Node} node The node.\n * @param {FrameState} frameState The frame state.\n */\nInstancingPipelineStage.process = function (renderResources, node, frameState) {\n const instances = node.instances;\n const count = instances.attributes[0].count;\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addDefine(\"HAS_INSTANCING\");\n shaderBuilder.addVertexLines(InstancingStageCommon);\n\n const model = renderResources.model;\n const sceneGraph = model.sceneGraph;\n const runtimeNode = renderResources.runtimeNode;\n\n const use2D =\n frameState.mode !== SceneMode.SCENE3D &&\n !frameState.scene3DOnly &&\n model._projectTo2D;\n\n const instancingVertexAttributes = [];\n\n processTransformAttributes(\n renderResources,\n frameState,\n instances,\n instancingVertexAttributes,\n use2D\n );\n\n processFeatureIdAttributes(\n renderResources,\n frameState,\n instances,\n instancingVertexAttributes\n );\n\n const uniformMap = {};\n\n if (instances.transformInWorldSpace) {\n shaderBuilder.addDefine(\n \"USE_LEGACY_INSTANCING\",\n undefined,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addUniform(\n \"mat4\",\n \"u_instance_modifiedModelView\",\n ShaderDestination.VERTEX\n );\n shaderBuilder.addUniform(\n \"mat4\",\n \"u_instance_nodeTransform\",\n ShaderDestination.VERTEX\n );\n\n // The i3dm format applies the instancing transforms in world space.\n // Instancing matrices come from a vertex attribute rather than a\n // uniform, and they are multiplied in the middle of the modelView matrix\n // product. This means czm_modelView can't be used. Instead, we split the\n // matrix into two parts, modifiedModelView and nodeTransform, and handle\n // this in LegacyInstancingStageVS.glsl. Conceptually the product looks like\n // this:\n //\n // modelView = u_modifiedModelView * a_instanceTransform * u_nodeTransform\n uniformMap.u_instance_modifiedModelView = function () {\n // Model matrix without the node hierarchy or axis correction\n // (see u_instance_nodeTransform).\n let modifiedModelMatrix = Matrix4.multiplyTransformation(\n // For 3D Tiles, model.modelMatrix is the computed tile\n // transform (which includes tileset.modelMatrix). This always applies\n // for i3dm, since such models are always part of a tileset.\n model.modelMatrix,\n // For i3dm models, components.transform contains the RTC_CENTER\n // translation.\n sceneGraph.components.transform,\n modelViewScratch\n );\n\n if (use2D) {\n // If projectTo2D is enabled, the 2D view matrix\n // will be accounted for in the u_modelView2D\n // uniform.\n //\n // modifiedModelView = view3D * modifiedModel\n return Matrix4.multiplyTransformation(\n frameState.context.uniformState.view3D,\n modifiedModelMatrix,\n modelViewScratch\n );\n }\n\n // For projection to 2D without projectTo2D enabled,\n // project the model matrix to 2D.\n if (frameState.mode !== SceneMode.SCENE3D) {\n modifiedModelMatrix = Transforms.basisTo2D(\n frameState.mapProjection,\n modifiedModelMatrix,\n modelViewScratch\n );\n }\n\n // modifiedModelView = view * modifiedModel\n return Matrix4.multiplyTransformation(\n frameState.context.uniformState.view,\n modifiedModelMatrix,\n modelViewScratch\n );\n };\n\n uniformMap.u_instance_nodeTransform = function () {\n // nodeTransform = axisCorrection * nodeHierarchyTransform\n return Matrix4.multiplyTransformation(\n // glTF y-up to 3D Tiles z-up\n sceneGraph.axisCorrectionMatrix,\n // This transforms from the node's coordinate system to the root\n // of the node hierarchy\n runtimeNode.computedTransform,\n nodeTransformScratch\n );\n };\n\n shaderBuilder.addVertexLines(LegacyInstancingStageVS);\n } else {\n shaderBuilder.addVertexLines(InstancingStageVS);\n }\n\n if (use2D) {\n shaderBuilder.addDefine(\n \"USE_2D_INSTANCING\",\n undefined,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addUniform(\"mat4\", \"u_modelView2D\", ShaderDestination.VERTEX);\n\n const context = frameState.context;\n const modelMatrix2D = Matrix4.fromTranslation(\n runtimeNode.instancingReferencePoint2D,\n new Matrix4()\n );\n\n uniformMap.u_modelView2D = function () {\n return Matrix4.multiplyTransformation(\n context.uniformState.view,\n modelMatrix2D,\n modelView2DScratch\n );\n };\n }\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n\n renderResources.instanceCount = count;\n renderResources.attributes.push.apply(\n renderResources.attributes,\n instancingVertexAttributes\n );\n};\n\nconst projectedTransformScratch = new Matrix4();\nconst projectedPositionScratch = new Cartesian3();\n\nfunction projectTransformTo2D(\n transform,\n modelMatrix,\n nodeTransform,\n frameState,\n result\n) {\n let projectedTransform = Matrix4.multiplyTransformation(\n modelMatrix,\n transform,\n projectedTransformScratch\n );\n\n projectedTransform = Matrix4.multiplyTransformation(\n projectedTransform,\n nodeTransform,\n projectedTransformScratch\n );\n\n result = Transforms.basisTo2D(\n frameState.mapProjection,\n projectedTransform,\n result\n );\n\n return result;\n}\n\nfunction projectPositionTo2D(\n position,\n modelMatrix,\n nodeTransform,\n frameState,\n result\n) {\n const translationMatrix = Matrix4.fromTranslation(\n position,\n projectedTransformScratch\n );\n\n let projectedTransform = Matrix4.multiplyTransformation(\n modelMatrix,\n translationMatrix,\n projectedTransformScratch\n );\n\n projectedTransform = Matrix4.multiplyTransformation(\n projectedTransform,\n nodeTransform,\n projectedTransformScratch\n );\n\n const finalPosition = Matrix4.getTranslation(\n projectedTransform,\n projectedPositionScratch\n );\n\n result = SceneTransforms.computeActualWgs84Position(\n frameState,\n finalPosition,\n result\n );\n\n return result;\n}\n\nfunction getModelMatrixAndNodeTransform(\n renderResources,\n modelMatrix,\n nodeComputedTransform\n) {\n const model = renderResources.model;\n const sceneGraph = model.sceneGraph;\n\n const instances = renderResources.runtimeNode.node.instances;\n if (instances.transformInWorldSpace) {\n // Replicate the multiplication order in LegacyInstancingStageVS.\n modelMatrix = Matrix4.multiplyTransformation(\n model.modelMatrix,\n sceneGraph.components.transform,\n modelMatrix\n );\n\n nodeComputedTransform = Matrix4.multiplyTransformation(\n sceneGraph.axisCorrectionMatrix,\n renderResources.runtimeNode.computedTransform,\n nodeComputedTransform\n );\n } else {\n // The node transform should be pre-multiplied with the instancing transform.\n modelMatrix = Matrix4.clone(sceneGraph.computedModelMatrix, modelMatrix);\n modelMatrix = Matrix4.multiplyTransformation(\n modelMatrix,\n renderResources.runtimeNode.computedTransform,\n modelMatrix\n );\n\n nodeComputedTransform = Matrix4.clone(\n Matrix4.IDENTITY,\n nodeComputedTransform\n );\n }\n}\n\nconst modelMatrixScratch = new Matrix4();\nconst nodeComputedTransformScratch = new Matrix4();\nconst transformScratch = new Matrix4();\nconst positionScratch = new Cartesian3();\n\nfunction projectTransformsTo2D(\n transforms,\n renderResources,\n frameState,\n result\n) {\n const modelMatrix = modelMatrixScratch;\n const nodeComputedTransform = nodeComputedTransformScratch;\n\n getModelMatrixAndNodeTransform(\n renderResources,\n modelMatrix,\n nodeComputedTransform\n );\n\n const runtimeNode = renderResources.runtimeNode;\n const referencePoint = runtimeNode.instancingReferencePoint2D;\n\n const count = transforms.length;\n for (let i = 0; i < count; i++) {\n const transform = transforms[i];\n\n const projectedTransform = projectTransformTo2D(\n transform,\n modelMatrix,\n nodeComputedTransform,\n frameState,\n transformScratch\n );\n\n const position = Matrix4.getTranslation(\n projectedTransform,\n positionScratch\n );\n\n const finalTranslation = Cartesian3.subtract(\n position,\n referencePoint,\n position\n );\n\n result[i] = Matrix4.setTranslation(\n projectedTransform,\n finalTranslation,\n result[i]\n );\n }\n\n return result;\n}\n\nfunction projectTranslationsTo2D(\n translations,\n renderResources,\n frameState,\n result\n) {\n const modelMatrix = modelMatrixScratch;\n const nodeComputedTransform = nodeComputedTransformScratch;\n\n getModelMatrixAndNodeTransform(\n renderResources,\n modelMatrix,\n nodeComputedTransform\n );\n\n const runtimeNode = renderResources.runtimeNode;\n const referencePoint = runtimeNode.instancingReferencePoint2D;\n const count = translations.length;\n for (let i = 0; i < count; i++) {\n const translation = translations[i];\n\n const projectedPosition = projectPositionTo2D(\n translation,\n modelMatrix,\n nodeComputedTransform,\n frameState,\n translation\n );\n\n result[i] = Cartesian3.subtract(\n projectedPosition,\n referencePoint,\n result[i]\n );\n }\n\n return result;\n}\n\nconst scratchProjectedMin = new Cartesian3();\nconst scratchProjectedMax = new Cartesian3();\n\nfunction computeReferencePoint2D(renderResources, frameState) {\n // Compute the reference point by averaging the instancing translation\n // min / max values after they are projected to 2D.\n const runtimeNode = renderResources.runtimeNode;\n const modelMatrix = renderResources.model.sceneGraph.computedModelMatrix;\n const transformedPositionMin = Matrix4.multiplyByPoint(\n modelMatrix,\n runtimeNode.instancingTranslationMin,\n scratchProjectedMin\n );\n\n const projectedMin = SceneTransforms.computeActualWgs84Position(\n frameState,\n transformedPositionMin,\n transformedPositionMin\n );\n\n const transformedPositionMax = Matrix4.multiplyByPoint(\n modelMatrix,\n runtimeNode.instancingTranslationMax,\n scratchProjectedMax\n );\n\n const projectedMax = SceneTransforms.computeActualWgs84Position(\n frameState,\n transformedPositionMax,\n transformedPositionMax\n );\n\n runtimeNode.instancingReferencePoint2D = Cartesian3.lerp(\n projectedMin,\n projectedMax,\n 0.5,\n new Cartesian3()\n );\n}\n\nfunction transformsToTypedArray(transforms) {\n const elements = 12;\n const count = transforms.length;\n const transformsTypedArray = new Float32Array(count * elements);\n\n for (let i = 0; i < count; i++) {\n const transform = transforms[i];\n const offset = elements * i;\n\n transformsTypedArray[offset + 0] = transform[0];\n transformsTypedArray[offset + 1] = transform[4];\n transformsTypedArray[offset + 2] = transform[8];\n transformsTypedArray[offset + 3] = transform[12];\n transformsTypedArray[offset + 4] = transform[1];\n transformsTypedArray[offset + 5] = transform[5];\n transformsTypedArray[offset + 6] = transform[9];\n transformsTypedArray[offset + 7] = transform[13];\n transformsTypedArray[offset + 8] = transform[2];\n transformsTypedArray[offset + 9] = transform[6];\n transformsTypedArray[offset + 10] = transform[10];\n transformsTypedArray[offset + 11] = transform[14];\n }\n\n return transformsTypedArray;\n}\n\nfunction translationsToTypedArray(translations) {\n const elements = 3;\n const count = translations.length;\n const transationsTypedArray = new Float32Array(count * elements);\n\n for (let i = 0; i < count; i++) {\n const translation = translations[i];\n const offset = elements * i;\n\n transationsTypedArray[offset + 0] = translation[0];\n transationsTypedArray[offset + 1] = translation[4];\n transationsTypedArray[offset + 2] = translation[8];\n }\n\n return transationsTypedArray;\n}\n\nconst translationScratch = new Cartesian3();\nconst rotationScratch = new Quaternion();\nconst scaleScratch = new Cartesian3();\n\nfunction getInstanceTransformsAsMatrices(instances, count, renderResources) {\n const transforms = new Array(count);\n\n const translationAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.TRANSLATION\n );\n const rotationAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.ROTATION\n );\n const scaleAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.SCALE\n );\n\n const instancingTranslationMax = new Cartesian3(\n -Number.MAX_VALUE,\n -Number.MAX_VALUE,\n -Number.MAX_VALUE\n );\n const instancingTranslationMin = new Cartesian3(\n Number.MAX_VALUE,\n Number.MAX_VALUE,\n Number.MAX_VALUE\n );\n\n const hasTranslation = defined(translationAttribute);\n const hasRotation = defined(rotationAttribute);\n const hasScale = defined(scaleAttribute);\n\n // Translations get initialized to (0, 0, 0).\n const translationTypedArray = hasTranslation\n ? translationAttribute.typedArray\n : new Float32Array(count * 3);\n\n // Rotations get initialized to (0, 0, 0, 0).\n // The w-component is set to 1 in the loop below.\n let rotationTypedArray = hasRotation\n ? rotationAttribute.typedArray\n : new Float32Array(count * 4);\n\n // The rotation attribute may be normalized\n if (hasRotation && rotationAttribute.normalized) {\n rotationTypedArray = AttributeCompression.dequantize(\n rotationTypedArray,\n rotationAttribute.componentDatatype,\n rotationAttribute.type,\n count\n );\n }\n\n // Scales get initialized to (1, 1, 1).\n let scaleTypedArray;\n if (hasScale) {\n scaleTypedArray = scaleAttribute.typedArray;\n } else {\n scaleTypedArray = new Float32Array(count * 3);\n scaleTypedArray.fill(1);\n }\n\n for (let i = 0; i < count; i++) {\n const translation = new Cartesian3(\n translationTypedArray[i * 3],\n translationTypedArray[i * 3 + 1],\n translationTypedArray[i * 3 + 2],\n translationScratch\n );\n\n Cartesian3.maximumByComponent(\n instancingTranslationMax,\n translation,\n instancingTranslationMax\n );\n Cartesian3.minimumByComponent(\n instancingTranslationMin,\n translation,\n instancingTranslationMin\n );\n\n const rotation = new Quaternion(\n rotationTypedArray[i * 4],\n rotationTypedArray[i * 4 + 1],\n rotationTypedArray[i * 4 + 2],\n hasRotation ? rotationTypedArray[i * 4 + 3] : 1,\n rotationScratch\n );\n\n const scale = new Cartesian3(\n scaleTypedArray[i * 3],\n scaleTypedArray[i * 3 + 1],\n scaleTypedArray[i * 3 + 2],\n scaleScratch\n );\n\n const transform = Matrix4.fromTranslationQuaternionRotationScale(\n translation,\n rotation,\n scale,\n new Matrix4()\n );\n\n transforms[i] = transform;\n }\n\n const runtimeNode = renderResources.runtimeNode;\n runtimeNode.instancingTranslationMin = instancingTranslationMin;\n runtimeNode.instancingTranslationMax = instancingTranslationMax;\n\n // Unload the typed arrays. These are just pointers to the arrays\n // in the vertex buffer loader.\n if (hasTranslation) {\n translationAttribute.typedArray = undefined;\n }\n if (hasRotation) {\n rotationAttribute.typedArray = undefined;\n }\n if (hasScale) {\n scaleAttribute.typedArray = undefined;\n }\n\n return transforms;\n}\n\nfunction getInstanceTranslationsAsCartesian3s(\n translationAttribute,\n count,\n renderResources\n) {\n const instancingTranslations = new Array(count);\n const translationTypedArray = translationAttribute.typedArray;\n\n const instancingTranslationMin = new Cartesian3(\n Number.MAX_VALUE,\n Number.MAX_VALUE,\n Number.MAX_VALUE\n );\n const instancingTranslationMax = new Cartesian3(\n -Number.MAX_VALUE,\n -Number.MAX_VALUE,\n -Number.MAX_VALUE\n );\n\n for (let i = 0; i < count; i++) {\n const translation = new Cartesian3(\n translationTypedArray[i * 3],\n translationTypedArray[i * 3 + 1],\n translationTypedArray[i * 3 + 2]\n );\n\n instancingTranslations[i] = translation;\n\n Cartesian3.minimumByComponent(\n instancingTranslationMin,\n translation,\n instancingTranslationMin\n );\n Cartesian3.maximumByComponent(\n instancingTranslationMax,\n translation,\n instancingTranslationMax\n );\n }\n\n const runtimeNode = renderResources.runtimeNode;\n runtimeNode.instancingTranslationMin = instancingTranslationMin;\n runtimeNode.instancingTranslationMax = instancingTranslationMax;\n\n // Unload the typed array. This is just a pointer to the array\n // in the vertex buffer loader.\n translationAttribute.typedArray = undefined;\n\n return instancingTranslations;\n}\n\nfunction createVertexBuffer(typedArray, frameState) {\n const buffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: typedArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n\n // Destruction of resources allocated by the Model\n // is handled by Model.destroy().\n buffer.vertexArrayDestroyable = false;\n\n return buffer;\n}\n\nfunction processTransformAttributes(\n renderResources,\n frameState,\n instances,\n instancingVertexAttributes,\n use2D\n) {\n const rotationAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.ROTATION\n );\n\n // Only use matrices for the transforms if the rotation attribute is defined.\n if (defined(rotationAttribute)) {\n processTransformMatrixAttributes(\n renderResources,\n instances,\n instancingVertexAttributes,\n frameState,\n use2D\n );\n } else {\n processTransformVec3Attributes(\n renderResources,\n instances,\n instancingVertexAttributes,\n frameState,\n use2D\n );\n }\n}\n\nfunction processTransformMatrixAttributes(\n renderResources,\n instances,\n instancingVertexAttributes,\n frameState,\n use2D\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const count = instances.attributes[0].count;\n\n const model = renderResources.model;\n const runtimeNode = renderResources.runtimeNode;\n\n shaderBuilder.addDefine(\"HAS_INSTANCE_MATRICES\");\n const attributeString = \"Transform\";\n\n let transforms;\n let buffer = runtimeNode.instancingTransformsBuffer;\n if (!defined(buffer)) {\n // This function computes the transforms, sets the translation min / max,\n // and unloads the typed arrays associated with the attributes.\n transforms = getInstanceTransformsAsMatrices(\n instances,\n count,\n renderResources\n );\n\n const transformsTypedArray = transformsToTypedArray(transforms);\n buffer = createVertexBuffer(transformsTypedArray, frameState);\n model._modelResources.push(buffer);\n\n runtimeNode.instancingTransformsBuffer = buffer;\n }\n\n processMatrixAttributes(\n renderResources,\n buffer,\n instancingVertexAttributes,\n attributeString\n );\n\n if (!use2D) {\n return;\n }\n\n // Force the scene mode to be CV. In 2D, projected positions will have\n // an x-coordinate of 0, which eliminates the height data that is\n // necessary for rendering in CV mode.\n const frameStateCV = clone(frameState);\n frameStateCV.mode = SceneMode.COLUMBUS_VIEW;\n\n // To prevent jitter, the positions are defined relative to a common\n // reference point. For convenience, this is the center of the instanced\n // translation bounds projected to 2D.\n computeReferencePoint2D(renderResources, frameStateCV);\n\n let buffer2D = runtimeNode.instancingTransformsBuffer2D;\n if (!defined(buffer2D)) {\n const projectedTransforms = projectTransformsTo2D(\n transforms,\n renderResources,\n frameStateCV,\n transforms\n );\n const projectedTypedArray = transformsToTypedArray(projectedTransforms);\n\n // This memory is counted during the statistics stage at the end\n // of the pipeline.\n buffer2D = createVertexBuffer(projectedTypedArray, frameState);\n model._modelResources.push(buffer2D);\n\n runtimeNode.instancingTransformsBuffer2D = buffer2D;\n }\n\n const attributeString2D = \"Transform2D\";\n processMatrixAttributes(\n renderResources,\n buffer2D,\n instancingVertexAttributes,\n attributeString2D\n );\n}\n\nfunction processTransformVec3Attributes(\n renderResources,\n instances,\n instancingVertexAttributes,\n frameState,\n use2D\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const runtimeNode = renderResources.runtimeNode;\n const translationAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.TRANSLATION\n );\n const scaleAttribute = ModelUtility.getAttributeBySemantic(\n instances,\n InstanceAttributeSemantic.SCALE\n );\n\n if (defined(scaleAttribute)) {\n shaderBuilder.addDefine(\"HAS_INSTANCE_SCALE\");\n const attributeString = \"Scale\";\n\n // Instanced scale attributes are loaded as buffers only.\n processVec3Attribute(\n renderResources,\n scaleAttribute.buffer,\n scaleAttribute.byteOffset,\n scaleAttribute.byteStride,\n instancingVertexAttributes,\n attributeString\n );\n }\n\n if (!defined(translationAttribute)) {\n return;\n }\n\n let instancingTranslations;\n const typedArray = translationAttribute.typedArray;\n if (defined(typedArray)) {\n // This function computes and set the translation min / max, and unloads\n // the typed array associated with the attribute.\n // The translations are also returned in case they're used for 2D projection.\n instancingTranslations = getInstanceTranslationsAsCartesian3s(\n translationAttribute,\n translationAttribute.count,\n renderResources\n );\n } else if (!defined(runtimeNode.instancingTranslationMin)) {\n runtimeNode.instancingTranslationMin = translationAttribute.min;\n runtimeNode.instancingTranslationMax = translationAttribute.max;\n }\n\n shaderBuilder.addDefine(\"HAS_INSTANCE_TRANSLATION\");\n const attributeString = \"Translation\";\n\n processVec3Attribute(\n renderResources,\n translationAttribute.buffer,\n translationAttribute.byteOffset,\n translationAttribute.byteStride,\n instancingVertexAttributes,\n attributeString\n );\n\n if (!use2D) {\n return;\n }\n\n // Force the scene mode to be CV. In 2D, projected positions will have\n // an x-coordinate of 0, which eliminates the height data that is\n // necessary for rendering in CV mode.\n const frameStateCV = clone(frameState);\n frameStateCV.mode = SceneMode.COLUMBUS_VIEW;\n\n // To prevent jitter, the positions are defined relative to a common\n // reference point. For convenience, this is the center of the instanced\n // translation bounds projected to 2D.\n computeReferencePoint2D(renderResources, frameStateCV);\n\n let buffer2D = runtimeNode.instancingTranslationBuffer2D;\n\n if (!defined(buffer2D)) {\n const projectedTranslations = projectTranslationsTo2D(\n instancingTranslations,\n renderResources,\n frameStateCV,\n instancingTranslations\n );\n const projectedTypedArray = translationsToTypedArray(projectedTranslations);\n\n // This memory is counted during the statistics stage at the end\n // of the pipeline.\n buffer2D = createVertexBuffer(projectedTypedArray, frameState);\n renderResources.model._modelResources.push(buffer2D);\n\n runtimeNode.instancingTranslationBuffer2D = buffer2D;\n }\n\n const byteOffset = 0;\n const byteStride = undefined;\n\n const attributeString2D = \"Translation2D\";\n processVec3Attribute(\n renderResources,\n buffer2D,\n byteOffset,\n byteStride,\n instancingVertexAttributes,\n attributeString2D\n );\n}\n\nfunction processMatrixAttributes(\n renderResources,\n buffer,\n instancingVertexAttributes,\n attributeString\n) {\n const vertexSizeInFloats = 12;\n const componentByteSize = ComponentDatatype.getSizeInBytes(\n ComponentDatatype.FLOAT\n );\n const strideInBytes = componentByteSize * vertexSizeInFloats;\n\n const matrixAttributes = [\n {\n index: renderResources.attributeIndex++,\n vertexBuffer: buffer,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n normalize: false,\n offsetInBytes: 0,\n strideInBytes: strideInBytes,\n instanceDivisor: 1,\n },\n {\n index: renderResources.attributeIndex++,\n vertexBuffer: buffer,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n normalize: false,\n offsetInBytes: componentByteSize * 4,\n strideInBytes: strideInBytes,\n instanceDivisor: 1,\n },\n {\n index: renderResources.attributeIndex++,\n vertexBuffer: buffer,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n normalize: false,\n offsetInBytes: componentByteSize * 8,\n strideInBytes: strideInBytes,\n instanceDivisor: 1,\n },\n ];\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addAttribute(\"vec4\", `a_instancing${attributeString}Row0`);\n shaderBuilder.addAttribute(\"vec4\", `a_instancing${attributeString}Row1`);\n shaderBuilder.addAttribute(\"vec4\", `a_instancing${attributeString}Row2`);\n\n instancingVertexAttributes.push.apply(\n instancingVertexAttributes,\n matrixAttributes\n );\n}\n\nfunction processVec3Attribute(\n renderResources,\n buffer,\n byteOffset,\n byteStride,\n instancingVertexAttributes,\n attributeString\n) {\n instancingVertexAttributes.push({\n index: renderResources.attributeIndex++,\n vertexBuffer: buffer,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n normalize: false,\n offsetInBytes: byteOffset,\n strideInBytes: byteStride,\n instanceDivisor: 1,\n });\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addAttribute(\"vec3\", `a_instance${attributeString}`);\n}\n\nfunction processFeatureIdAttributes(\n renderResources,\n frameState,\n instances,\n instancingVertexAttributes\n) {\n const attributes = instances.attributes;\n const shaderBuilder = renderResources.shaderBuilder;\n\n for (let i = 0; i < attributes.length; i++) {\n const attribute = attributes[i];\n if (attribute.semantic !== InstanceAttributeSemantic.FEATURE_ID) {\n continue;\n }\n\n if (\n attribute.setIndex >= renderResources.featureIdVertexAttributeSetIndex\n ) {\n renderResources.featureIdVertexAttributeSetIndex = attribute.setIndex + 1;\n }\n\n instancingVertexAttributes.push({\n index: renderResources.attributeIndex++,\n vertexBuffer: attribute.buffer,\n componentsPerAttribute: AttributeType.getNumberOfComponents(\n attribute.type\n ),\n componentDatatype: attribute.componentDatatype,\n normalize: false,\n offsetInBytes: attribute.byteOffset,\n strideInBytes: attribute.byteStride,\n instanceDivisor: 1,\n });\n\n shaderBuilder.addAttribute(\n \"float\",\n `a_instanceFeatureId_${attribute.setIndex}`\n );\n }\n}\n\nexport default InstancingPipelineStage;\n", "import Matrix4 from \"../../Core/Matrix4.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport SceneMode from \"../SceneMode.js\";\n\n/**\n * The model matrix update stage is responsible for updating the model matrices and bounding volumes of the draw commands.\n *\n * @namespace ModelMatrixUpdateStage\n *\n * @private\n */\nconst ModelMatrixUpdateStage = {};\nModelMatrixUpdateStage.name = \"ModelMatrixUpdateStage\"; // Helps with debugging\n\n/**\n * Processes a runtime node. This modifies the following parts of the scene graph and draw commands:\n *
    \n *
  • updates the transforms the children of any nodes with a dirty transform
  • \n *
  • updates the model matrix of each draw command in each primitive of the the dirty nodes and their children
  • \n *
  • updates the bounding volume of each draw command in each primitive of the the dirty nodes and their children
  • \n *
\n *\n * @param {ModelRuntimeNode} runtimeNode\n * @param {ModelSceneGraph} sceneGraph\n * @param {FrameState} frameState\n *\n * @private\n */\nModelMatrixUpdateStage.update = function (runtimeNode, sceneGraph, frameState) {\n // Skip the update stage if the model is being projected to 2D\n const use2D = frameState.mode !== SceneMode.SCENE3D;\n if (use2D && sceneGraph._model._projectTo2D) {\n return;\n }\n\n if (runtimeNode._transformDirty) {\n const modelMatrix = use2D\n ? sceneGraph._computedModelMatrix2D\n : sceneGraph._computedModelMatrix;\n\n updateRuntimeNode(\n runtimeNode,\n sceneGraph,\n modelMatrix,\n runtimeNode.transformToRoot\n );\n runtimeNode._transformDirty = false;\n }\n};\n\n/**\n * Recursively update all child runtime nodes and their runtime primitives.\n *\n * @private\n */\nfunction updateRuntimeNode(\n runtimeNode,\n sceneGraph,\n modelMatrix,\n transformToRoot\n) {\n let i;\n\n // Apply the current node's transform to the end of the chain\n transformToRoot = Matrix4.multiplyTransformation(\n transformToRoot,\n runtimeNode.transform,\n new Matrix4()\n );\n\n runtimeNode.updateComputedTransform();\n\n const primitivesLength = runtimeNode.runtimePrimitives.length;\n for (i = 0; i < primitivesLength; i++) {\n const runtimePrimitive = runtimeNode.runtimePrimitives[i];\n const drawCommand = runtimePrimitive.drawCommand;\n drawCommand.modelMatrix = Matrix4.multiplyTransformation(\n modelMatrix,\n transformToRoot,\n drawCommand.modelMatrix\n );\n drawCommand.cullFace = ModelUtility.getCullFace(\n drawCommand.modelMatrix,\n drawCommand.primitiveType\n );\n }\n\n const childrenLength = runtimeNode.children.length;\n for (i = 0; i < childrenLength; i++) {\n const childRuntimeNode = sceneGraph._runtimeNodes[runtimeNode.children[i]];\n\n // Update transformToRoot to accommodate changes in the transforms of this node and its ancestors\n childRuntimeNode._transformToRoot = Matrix4.clone(\n transformToRoot,\n childRuntimeNode._transformToRoot\n );\n\n updateRuntimeNode(\n childRuntimeNode,\n sceneGraph,\n modelMatrix,\n transformToRoot\n );\n childRuntimeNode._transformDirty = false;\n }\n}\n\nexport default ModelMatrixUpdateStage;\n", "import defined from \"../../Core/defined.js\";\n\n/**\n * The node statistics update stage updates memory usage statistics for a Model\n * on the node level. This counts the binary resources that exist for the\n * lifetime of the Model (e.g. attributes loaded by GltfLoader). It does not\n * count resources that are created every time the pipeline is run.\n * The individual pipeline stages are responsible for keeping track of any\n * additional memory they allocate.\n *\n * @namespace NodeStatisticsPipelineStage\n *\n * @private\n */\nconst NodeStatisticsPipelineStage = {\n name: \"NodeStatisticsPipelineStage\", // Helps with debugging\n\n // Expose some methods for testing\n _countInstancingAttributes: countInstancingAttributes,\n _countGeneratedBuffers: countGeneratedBuffers,\n};\n\nNodeStatisticsPipelineStage.process = function (\n renderResources,\n node,\n frameState\n) {\n const statistics = renderResources.model.statistics;\n const instances = node.instances;\n const runtimeNode = renderResources.runtimeNode;\n\n countInstancingAttributes(statistics, instances);\n countGeneratedBuffers(statistics, runtimeNode);\n};\n\nfunction countInstancingAttributes(statistics, instances) {\n if (!defined(instances)) {\n return;\n }\n\n const attributes = instances.attributes;\n const length = attributes.length;\n for (let i = 0; i < length; i++) {\n const attribute = attributes[i];\n if (defined(attribute.buffer)) {\n // Any typed arrays should have been unloaded before this stage.\n const hasCpuCopy = false;\n statistics.addBuffer(attribute.buffer, hasCpuCopy);\n }\n }\n}\n\nfunction countGeneratedBuffers(statistics, runtimeNode) {\n if (defined(runtimeNode.instancingTransformsBuffer)) {\n // The typed array containing the computed transforms isn't saved\n // after the buffer is created.\n const hasCpuCopy = false;\n statistics.addBuffer(runtimeNode.instancingTransformsBuffer, hasCpuCopy);\n }\n if (defined(runtimeNode.instancingTransformsBuffer2D)) {\n // The typed array containing the computed 2D transforms isn't saved\n // after the buffer is created.\n const hasCpuCopy = false;\n statistics.addBuffer(runtimeNode.instancingTransformsBuffer2D, hasCpuCopy);\n }\n\n if (defined(runtimeNode.instancingTranslationBuffer2D)) {\n // The typed array containing the computed 2D translations isn't saved\n // after the buffer is created.\n const hasCpuCopy = false;\n statistics.addBuffer(runtimeNode.instancingTranslationBuffer2D, hasCpuCopy);\n }\n}\n\nexport default NodeStatisticsPipelineStage;\n", "import Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport TranslationRotationScale from \"../../Core/TranslationRotationScale.js\";\nimport Quaternion from \"../../Core/Quaternion.js\";\nimport InstancingPipelineStage from \"./InstancingPipelineStage.js\";\nimport ModelMatrixUpdateStage from \"./ModelMatrixUpdateStage.js\";\nimport NodeStatisticsPipelineStage from \"./NodeStatisticsPipelineStage.js\";\n\n/**\n * An in-memory representation of a node as part of the {@link ModelSceneGraph}.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.Node} options.node The corresponding node components from the 3D model.\n * @param {Matrix4} options.transform The transform of this node, excluding transforms from the node's ancestors or children.\n * @param {Matrix4} options.transformToRoot The product of the transforms of all the node's ancestors, excluding the node's own transform.\n * @param {ModelSceneGraph} options.sceneGraph The scene graph this node belongs to.\n * @param {number[]} options.children The indices of the children of this node in the runtime nodes array of the scene graph.\n *\n * @alias ModelRuntimeNode\n * @constructor\n *\n * @private\n */\nfunction ModelRuntimeNode(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const node = options.node;\n const transform = options.transform;\n const transformToRoot = options.transformToRoot;\n const sceneGraph = options.sceneGraph;\n const children = options.children;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.node\", node);\n Check.typeOf.object(\"options.transform\", transform);\n Check.typeOf.object(\"options.transformToRoot\", transformToRoot);\n Check.typeOf.object(\"options.sceneGraph\", sceneGraph);\n Check.typeOf.object(\"options.children\", children);\n //>>includeEnd('debug');\n\n this._node = node;\n this._name = node.name;\n this._id = node.index;\n this._sceneGraph = sceneGraph;\n this._children = children;\n\n this._originalTransform = Matrix4.clone(transform, this._originalTransform);\n this._transform = Matrix4.clone(transform, this._transform);\n this._transformToRoot = Matrix4.clone(transformToRoot, this._transformToRoot);\n\n this._computedTransform = new Matrix4(); // Computed in initialize()\n this._transformDirty = false;\n\n // Used for animation\n this._transformParameters = undefined;\n this._morphWeights = [];\n\n // Will be set by the scene graph after the skins have been created\n this._runtimeSkin = undefined;\n this._computedJointMatrices = [];\n\n /**\n * Whether or not to show this node and its children. This can be toggled\n * by the user through {@link ModelNode}.\n *\n * @type {boolean}\n *\n * @default true\n *\n * @private\n */\n this.show = true;\n\n /**\n * Whether or not this node is animated by the user. This is set by the\n * corresponding {@link ModelNode} when the user supplies their\n * own transform. If this is true, the node will ignore animations in the\n * model's asset.\n *\n * @type {boolean}\n *\n * @private\n */\n this.userAnimated = false;\n\n /**\n * Pipeline stages to apply across all the mesh primitives of this node.\n * This is an array of classes, each with a static method called\n * process().\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.pipelineStages = [];\n\n /**\n * The mesh primitives that belong to this node.\n *\n * @type {ModelRuntimePrimitive[]}\n * @readonly\n *\n * @private\n */\n this.runtimePrimitives = [];\n\n /**\n * Update stages to apply to this node.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.updateStages = [];\n\n /**\n * The component-wise minimum value of the translations of the instances.\n * This value is set by InstancingPipelineStage.\n *\n * @type {Cartesian3}\n *\n * @private\n */\n this.instancingTranslationMin = undefined;\n\n /**\n * The component-wise maximum value of the translations of the instances.\n * This value is set by InstancingPipelineStage.\n *\n * @type {Cartesian3}\n *\n * @private\n */\n this.instancingTranslationMax = undefined;\n\n /**\n * A buffer containing the instanced transforms. The memory is managed\n * by Model; this is just a reference.\n *\n * @type {Buffer}\n *\n * @private\n */\n this.instancingTransformsBuffer = undefined;\n\n /**\n * A buffer containing the instanced transforms projected to 2D world\n * coordinates. Used for rendering in 2D / CV mode. The memory is managed\n * by Model; this is just a reference.\n *\n * @type {Buffer}\n *\n * @private\n */\n this.instancingTransformsBuffer2D = undefined;\n\n /**\n * A buffer containing the instanced translation values for the node if\n * it is instanced. Used for rendering in 2D / CV mode. The memory is\n * managed by Model; this is just a reference.\n *\n * @type {Buffer}\n *\n * @private\n */\n this.instancingTranslationBuffer2D = undefined;\n\n /**\n * If the model is instanced and projected to 2D, the reference point is the\n * average of the instancing translation max and min. The 2D translations are\n * defined relative to this point to avoid precision issues on the GPU.\n *

\n * This value is set by InstancingPipelineStage.\n *

\n *\n * @type {Cartesian3}\n *\n * @private\n */\n this.instancingReferencePoint2D = undefined;\n\n initialize(this);\n}\n\nObject.defineProperties(ModelRuntimeNode.prototype, {\n /**\n * The internal node this runtime node represents.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {ModelComponents.Node}\n * @readonly\n *\n * @private\n */\n node: {\n get: function () {\n return this._node;\n },\n },\n /**\n * The scene graph this node belongs to.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {ModelSceneGraph}\n * @readonly\n *\n * @private\n */\n sceneGraph: {\n get: function () {\n return this._sceneGraph;\n },\n },\n\n /**\n * The indices of the children of this node in the scene graph.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {number[]}\n * @readonly\n *\n * @private\n */\n children: {\n get: function () {\n return this._children;\n },\n },\n\n /**\n * The node's local space transform. This can be changed externally via\n * the corresponding {@link ModelNode}, such that animation can be\n * driven by another source, not just an animation in the model's asset.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Matrix4}\n *\n * @private\n */\n transform: {\n get: function () {\n return this._transform;\n },\n set: function (value) {\n this._transformDirty = true;\n this._transform = Matrix4.clone(value, this._transform);\n },\n },\n\n /**\n * The transforms of all the node's ancestors, not including this node's\n * transform.\n *\n * @see ModelRuntimeNode#computedTransform\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Matrix4}\n * @readonly\n *\n * @private\n */\n transformToRoot: {\n get: function () {\n return this._transformToRoot;\n },\n },\n\n /**\n * A transform from the node's local space to the model's scene graph space.\n * This is the product of transformToRoot * transform.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Matrix4}\n * @readonly\n *\n * @private\n */\n computedTransform: {\n get: function () {\n return this._computedTransform;\n },\n },\n\n /**\n * The node's original transform, as specified in the model.\n * Does not include transformations from the node's ancestors.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Matrix4}\n * @readonly\n *\n * @private\n */\n originalTransform: {\n get: function () {\n return this._originalTransform;\n },\n },\n\n /**\n * The node's local space translation. This is used internally to allow\n * animations in the model's asset to affect the node's properties.\n *\n * If the node's transformation was originally described using a matrix\n * in the model, then this will return undefined.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Cartesian3}\n *\n * @exception {DeveloperError} The translation of a node cannot be set if it was defined using a matrix in the model's asset.\n *\n * @private\n */\n translation: {\n get: function () {\n return defined(this._transformParameters)\n ? this._transformParameters.translation\n : undefined;\n },\n set: function (value) {\n const transformParameters = this._transformParameters;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(transformParameters)) {\n throw new DeveloperError(\n \"The translation of a node cannot be set if it was defined using a matrix in the model.\"\n );\n }\n //>>includeEnd('debug');\n\n const currentTranslation = transformParameters.translation;\n if (Cartesian3.equals(currentTranslation, value)) {\n return;\n }\n\n transformParameters.translation = Cartesian3.clone(\n value,\n transformParameters.translation\n );\n\n updateTransformFromParameters(this, transformParameters);\n },\n },\n\n /**\n * The node's local space rotation. This is used internally to allow\n * animations in the model's asset to affect the node's properties.\n *\n * If the node's transformation was originally described using a matrix\n * in the model, then this will return undefined.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Quaternion}\n *\n * @exception {DeveloperError} The rotation of a node cannot be set if it was defined using a matrix in the model's asset.\n *\n * @private\n */\n rotation: {\n get: function () {\n return defined(this._transformParameters)\n ? this._transformParameters.rotation\n : undefined;\n },\n set: function (value) {\n const transformParameters = this._transformParameters;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(transformParameters)) {\n throw new DeveloperError(\n \"The rotation of a node cannot be set if it was defined using a matrix in the model.\"\n );\n }\n //>>includeEnd('debug');\n\n const currentRotation = transformParameters.rotation;\n if (Quaternion.equals(currentRotation, value)) {\n return;\n }\n\n transformParameters.rotation = Quaternion.clone(\n value,\n transformParameters.rotation\n );\n\n updateTransformFromParameters(this, transformParameters);\n },\n },\n\n /**\n * The node's local space scale. This is used internally to allow\n * animations in the model's asset to affect the node's properties.\n *\n * If the node's transformation was originally described using a matrix\n * in the model, then this will return undefined.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Cartesian3}\n *\n * @exception {DeveloperError} The scale of a node cannot be set if it was defined using a matrix in the model's asset.\n * @private\n */\n scale: {\n get: function () {\n return defined(this._transformParameters)\n ? this._transformParameters.scale\n : undefined;\n },\n set: function (value) {\n const transformParameters = this._transformParameters;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(transformParameters)) {\n throw new DeveloperError(\n \"The scale of a node cannot be set if it was defined using a matrix in the model.\"\n );\n }\n //>>includeEnd('debug');\n const currentScale = transformParameters.scale;\n if (Cartesian3.equals(currentScale, value)) {\n return;\n }\n\n transformParameters.scale = Cartesian3.clone(\n value,\n transformParameters.scale\n );\n\n updateTransformFromParameters(this, transformParameters);\n },\n },\n\n /**\n * The node's morph weights. This is used internally to allow animations\n * in the model's asset to affect the node's properties.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {number[]}\n *\n * @private\n */\n morphWeights: {\n get: function () {\n return this._morphWeights;\n },\n set: function (value) {\n const valueLength = value.length;\n //>>includeStart('debug', pragmas.debug);\n if (this._morphWeights.length !== valueLength) {\n throw new DeveloperError(\n \"value must have the same length as the original weights array.\"\n );\n }\n //>>includeEnd('debug');\n for (let i = 0; i < valueLength; i++) {\n this._morphWeights[i] = value[i];\n }\n },\n },\n\n /**\n * The skin applied to this node, if it exists.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {ModelSkin}\n * @readonly\n *\n * @private\n */\n runtimeSkin: {\n get: function () {\n return this._runtimeSkin;\n },\n },\n\n /**\n * The computed joint matrices of this node, derived from its skin.\n *\n * @memberof ModelRuntimeNode.prototype\n * @type {Matrix4[]}\n * @readonly\n *\n * @private\n */\n computedJointMatrices: {\n get: function () {\n return this._computedJointMatrices;\n },\n },\n});\n\nfunction initialize(runtimeNode) {\n const transform = runtimeNode.transform;\n const transformToRoot = runtimeNode.transformToRoot;\n const computedTransform = runtimeNode._computedTransform;\n runtimeNode._computedTransform = Matrix4.multiply(\n transformToRoot,\n transform,\n computedTransform\n );\n\n const node = runtimeNode.node;\n if (!defined(node.matrix)) {\n runtimeNode._transformParameters = new TranslationRotationScale(\n node.translation,\n node.rotation,\n node.scale\n );\n }\n\n if (defined(node.morphWeights)) {\n runtimeNode._morphWeights = node.morphWeights.slice();\n }\n\n // If this node is affected by an articulation from the AGI_articulations\n // extension, add this node to its list of affected nodes.\n const articulationName = node.articulationName;\n if (defined(articulationName)) {\n const sceneGraph = runtimeNode.sceneGraph;\n const runtimeArticulations = sceneGraph._runtimeArticulations;\n\n const runtimeArticulation = runtimeArticulations[articulationName];\n if (defined(runtimeArticulation)) {\n runtimeArticulation.runtimeNodes.push(runtimeNode);\n }\n }\n}\n\nfunction updateTransformFromParameters(runtimeNode, transformParameters) {\n runtimeNode._transformDirty = true;\n\n runtimeNode._transform = Matrix4.fromTranslationRotationScale(\n transformParameters,\n runtimeNode._transform\n );\n}\n\n/**\n * Returns the child with the given index.\n *\n * @param {number} index The index of the child.\n *\n * @returns {ModelRuntimeNode}\n *\n * @example\n * // Iterate through all children of a runtime node.\n * for (let i = 0; i < runtimeNode.children.length; i++)\n * {\n * const childNode = runtimeNode.getChild(i);\n * }\n *\n * @private\n */\nModelRuntimeNode.prototype.getChild = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n if (index < 0 || index >= this.children.length) {\n throw new DeveloperError(\n \"index must be greater than or equal to 0 and less than the number of children.\"\n );\n }\n //>>includeEnd('debug');\n\n return this.sceneGraph._runtimeNodes[this.children[index]];\n};\n\n/**\n * Configure the node pipeline stages. If the pipeline needs to be re-run, call\n * this method again to ensure the correct sequence of pipeline stages are\n * used.\n *\n * @private\n */\nModelRuntimeNode.prototype.configurePipeline = function () {\n const node = this.node;\n const pipelineStages = this.pipelineStages;\n pipelineStages.length = 0;\n const updateStages = this.updateStages;\n updateStages.length = 0;\n\n if (defined(node.instances)) {\n pipelineStages.push(InstancingPipelineStage);\n }\n\n pipelineStages.push(NodeStatisticsPipelineStage);\n\n updateStages.push(ModelMatrixUpdateStage);\n};\n\n/**\n * Updates the computed transform used for rendering and instancing.\n *\n * @private\n */\nModelRuntimeNode.prototype.updateComputedTransform = function () {\n this._computedTransform = Matrix4.multiply(\n this._transformToRoot,\n this._transform,\n this._computedTransform\n );\n};\n\n/**\n * Updates the joint matrices for this node, where each matrix is computed as\n * computedJointMatrix = nodeWorldTransform^(-1) * skinJointMatrix.\n *\n * @private\n */\nModelRuntimeNode.prototype.updateJointMatrices = function () {\n const runtimeSkin = this._runtimeSkin;\n if (!defined(runtimeSkin)) {\n return;\n }\n\n runtimeSkin.updateJointMatrices();\n\n const computedJointMatrices = this._computedJointMatrices;\n const skinJointMatrices = runtimeSkin.jointMatrices;\n const length = skinJointMatrices.length;\n\n for (let i = 0; i < length; i++) {\n if (!defined(computedJointMatrices[i])) {\n computedJointMatrices[i] = new Matrix4();\n }\n\n const nodeWorldTransform = Matrix4.multiplyTransformation(\n this.transformToRoot,\n this.transform,\n computedJointMatrices[i]\n );\n\n const inverseNodeWorldTransform = Matrix4.inverseTransformation(\n nodeWorldTransform,\n computedJointMatrices[i]\n );\n\n computedJointMatrices[i] = Matrix4.multiplyTransformation(\n inverseNodeWorldTransform,\n skinJointMatrices[i],\n computedJointMatrices[i]\n );\n }\n};\n\nexport default ModelRuntimeNode;\n", "import defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport BlendingState from \"../BlendingState.js\";\nimport Pass from \"../../Renderer/Pass.js\";\n\n/**\n * A pipeline stage for configuring the alpha options for handling translucency.\n *\n * @namespace MaterialPipelineStage\n *\n * @private\n */\nconst AlphaPipelineStage = {\n name: \"AlphaPipelineStage\", // Helps with debugging\n};\n\nAlphaPipelineStage.process = function (renderResources, primitive, frameState) {\n const alphaOptions = renderResources.alphaOptions;\n\n // Ensure the pass is defined\n const model = renderResources.model;\n alphaOptions.pass = defaultValue(alphaOptions.pass, model.opaquePass);\n\n const renderStateOptions = renderResources.renderStateOptions;\n if (alphaOptions.pass === Pass.TRANSLUCENT) {\n renderStateOptions.cull.enabled = false;\n renderStateOptions.depthMask = false;\n renderStateOptions.blending = BlendingState.ALPHA_BLEND;\n }\n\n const shaderBuilder = renderResources.shaderBuilder;\n const uniformMap = renderResources.uniformMap;\n\n if (defined(alphaOptions.alphaCutoff)) {\n shaderBuilder.addDefine(\n \"ALPHA_MODE_MASK\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addUniform(\n \"float\",\n \"u_alphaCutoff\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_alphaCutoff = function () {\n return alphaOptions.alphaCutoff;\n };\n }\n};\n\nexport default AlphaPipelineStage;\n", "import combine from \"../../Core/combine.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\n\n/**\n * The batch texture stage is responsible for setting up the batch texture for the primitive.\n *\n * @namespace BatchTexturePipelineStage\n * @private\n */\nconst BatchTexturePipelineStage = {\n name: \"BatchTexturePipelineStage\", // Helps with debugging\n};\n\n/**\n * Processes a primitive. This modifies the following parts of the render resources:\n *
    \n *
  • adds uniforms for the batch texture
  • \n *
  • adds defines for multiline batch textures
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n */\nBatchTexturePipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const batchTextureUniforms = {};\n\n const model = renderResources.model;\n\n const featureTable = model.featureTables[model.featureTableId];\n\n // Number of features in the feature table.\n const featuresLength = featureTable.featuresLength;\n shaderBuilder.addUniform(\"int\", \"model_featuresLength\");\n batchTextureUniforms.model_featuresLength = function () {\n return featuresLength;\n };\n\n // Batch texture\n const batchTexture = featureTable.batchTexture;\n shaderBuilder.addUniform(\"sampler2D\", \"model_batchTexture\");\n batchTextureUniforms.model_batchTexture = function () {\n return defaultValue(batchTexture.batchTexture, batchTexture.defaultTexture);\n };\n\n // Batch texture step size\n shaderBuilder.addUniform(\"vec4\", \"model_textureStep\");\n batchTextureUniforms.model_textureStep = function () {\n return batchTexture.textureStep;\n };\n\n // Batch texture dimensions\n if (batchTexture.textureDimensions.y > 1) {\n shaderBuilder.addDefine(\"MULTILINE_BATCH_TEXTURE\");\n shaderBuilder.addUniform(\"vec2\", \"model_textureDimensions\");\n batchTextureUniforms.model_textureDimensions = function () {\n return batchTexture.textureDimensions;\n };\n }\n\n renderResources.uniformMap = combine(\n batchTextureUniforms,\n renderResources.uniformMap\n );\n};\n\nexport default BatchTexturePipelineStage;\n", "import defined from \"../../Core/defined.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The classification pipeline stage is responsible for batching features\n * together to be rendered by the {@link ClassificationModelDrawCommand}.\n *\n * @namespace ClassificationPipelineStage\n *\n * @private\n */\nconst ClassificationPipelineStage = {\n name: \"ClassificationPipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render resources:\n *\n *
    \n *
  • adds a define to the shader to indicate that the primitive classifies other assets
  • \n *
  • adds arrays containing batch lengths and offsets to the primitive's resources\n *
\n *\n *

\n * See {@link ClassificationModelDrawCommand} for the use of the batch offsets and lengths.\n *

\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nClassificationPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"HAS_CLASSIFICATION\",\n undefined,\n ShaderDestination.BOTH\n );\n\n const runtimePrimitive = renderResources.runtimePrimitive;\n\n if (!defined(runtimePrimitive.batchLengths)) {\n createClassificationBatches(primitive, runtimePrimitive);\n }\n};\n\nfunction createClassificationBatches(primitive, runtimePrimitive) {\n const positionAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.POSITION\n );\n\n if (!defined(positionAttribute)) {\n throw new RuntimeError(\n \"Primitives must have a position attribute to be used for classification.\"\n );\n }\n\n let indicesArray;\n const indices = primitive.indices;\n const hasIndices = defined(indices);\n if (hasIndices) {\n indicesArray = indices.typedArray;\n // Unload the typed array. This is just a pointer to the array in\n // the index buffer loader.\n indices.typedArray = undefined;\n }\n\n const count = hasIndices ? indices.count : positionAttribute.count;\n const featureIdAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.FEATURE_ID,\n 0\n );\n\n // If there are no feature IDs, render the primitive in a single batch.\n if (!defined(featureIdAttribute)) {\n runtimePrimitive.batchLengths = [count];\n runtimePrimitive.batchOffsets = [0];\n\n return;\n }\n\n const featureIds = featureIdAttribute.typedArray;\n // Unload the typed array. This is just a pointer to the array in\n // the vertex buffer loader, so if the typed array is shared by\n // multiple primitives (i.e. multiple instances of the same mesh),\n // this will not affect the other primitives.\n featureIdAttribute.typedArray = undefined;\n\n const batchLengths = [];\n const batchOffsets = [0];\n\n const firstIndex = hasIndices ? indicesArray[0] : 0;\n let currentBatchId = featureIds[firstIndex];\n let currentOffset = 0;\n\n for (let i = 1; i < count; i++) {\n const index = hasIndices ? indicesArray[i] : i;\n const batchId = featureIds[index];\n\n if (batchId !== currentBatchId) {\n // Store the length of this batch and begin counting the next one.\n const batchLength = i - currentOffset;\n const newOffset = i;\n\n batchLengths.push(batchLength);\n batchOffsets.push(newOffset);\n\n currentOffset = newOffset;\n currentBatchId = batchId;\n }\n }\n\n const finalBatchLength = count - currentOffset;\n batchLengths.push(finalBatchLength);\n\n runtimePrimitive.batchLengths = batchLengths;\n runtimePrimitive.batchOffsets = batchOffsets;\n}\n\nexport default ClassificationPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void filterByPassType(inout vec3 positionMC, vec4 featureColor)\\n\\\n{\\n\\\n bool styleTranslucent = (featureColor.a != 1.0);\\n\\\n // Only render translucent features in the translucent pass (if the style or the original command has translucency).\\n\\\n if (czm_pass == czm_passTranslucent && !styleTranslucent && !model_commandTranslucent)\\n\\\n {\\n\\\n // If the model has a translucent silhouette, it needs to render during the silhouette color command,\\n\\\n // (i.e. the command where model_silhouettePass = true), even if the model isn't translucent.\\n\\\n #ifdef HAS_SILHOUETTE\\n\\\n positionMC *= float(model_silhouettePass);\\n\\\n #else\\n\\\n positionMC *= 0.0;\\n\\\n #endif\\n\\\n }\\n\\\n // If the current pass is not the translucent pass and the style is not translucent, don't render the feature.\\n\\\n else if (czm_pass != czm_passTranslucent && styleTranslucent)\\n\\\n {\\n\\\n positionMC *= 0.0;\\n\\\n }\\n\\\n}\\n\\\n\\n\\\nvoid cpuStylingStage(inout vec3 positionMC, inout SelectedFeature feature)\\n\\\n{\\n\\\n float show = ceil(feature.color.a);\\n\\\n positionMC *= show;\\n\\\n\\n\\\n #if defined(HAS_SELECTED_FEATURE_ID_ATTRIBUTE) && !defined(HAS_CLASSIFICATION)\\n\\\n filterByPassType(positionMC, feature.color);\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void filterByPassType(vec4 featureColor)\\n\\\n{\\n\\\n bool styleTranslucent = (featureColor.a != 1.0);\\n\\\n // Only render translucent features in the translucent pass (if the style or the original command has translucency).\\n\\\n if (czm_pass == czm_passTranslucent && !styleTranslucent && !model_commandTranslucent)\\n\\\n { \\n\\\n // If the model has a translucent silhouette, it needs to render during the silhouette color command,\\n\\\n // (i.e. the command where model_silhouettePass = true), even if the model isn't translucent.\\n\\\n #ifdef HAS_SILHOUETTE\\n\\\n if(!model_silhouettePass) {\\n\\\n discard;\\n\\\n }\\n\\\n #else\\n\\\n discard;\\n\\\n #endif\\n\\\n }\\n\\\n // If the current pass is not the translucent pass and the style is not translucent, don't render the feature.\\n\\\n else if (czm_pass != czm_passTranslucent && styleTranslucent)\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n}\\n\\\n\\n\\\nvoid cpuStylingStage(inout czm_modelMaterial material, SelectedFeature feature)\\n\\\n{\\n\\\n vec4 featureColor = feature.color;\\n\\\n if (featureColor.a == 0.0)\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n\\n\\\n // If a feature ID vertex attribute is used, the pass type filter is applied in the vertex shader.\\n\\\n // So, we only apply in in the fragment shader if the feature ID texture is used.\\n\\\n #if defined(HAS_SELECTED_FEATURE_ID_TEXTURE) && !defined(HAS_CLASSIFICATION)\\n\\\n filterByPassType(featureColor);\\n\\\n #endif\\n\\\n\\n\\\n featureColor = czm_gammaCorrect(featureColor);\\n\\\n\\n\\\n // Classification models compute the diffuse differently.\\n\\\n #ifdef HAS_CLASSIFICATION\\n\\\n material.diffuse = featureColor.rgb * featureColor.a;\\n\\\n #else\\n\\\n float highlight = ceil(model_colorBlend);\\n\\\n material.diffuse *= mix(featureColor.rgb, vec3(1.0), highlight);\\n\\\n #endif\\n\\\n \\n\\\n material.alpha *= featureColor.a;\\n\\\n}\\n\\\n\";\n", "import ColorBlendMode from \"../ColorBlendMode.js\";\nimport CPUStylingStageVS from \"../../Shaders/Model/CPUStylingStageVS.js\";\nimport CPUStylingStageFS from \"../../Shaders/Model/CPUStylingStageFS.js\";\nimport defined from \"../../Core/defined.js\";\nimport ModelColorPipelineStage from \"./ModelColorPipelineStage.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\n\n/**\n * The CPU styling stage is responsible for ensuring that the feature's color\n * is applied at runtime.\n *\n * @namespace CPUStylingPipelineStage\n *\n * @private\n */\nconst CPUStylingPipelineStage = {\n name: \"CPUStylingPipelineStage\", // Helps with debugging\n};\n\n/**\n * Processes a primitive. This modifies the following parts of the render resources:\n *
    \n *
  • adds the styling code to both the vertex and fragment shaders
  • \n *
  • adds the define to trigger the stage's shader functions
  • \n *
  • adds a uniform with the model's color blend mode and amount
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nCPUStylingPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const model = renderResources.model;\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addVertexLines(CPUStylingStageVS);\n shaderBuilder.addFragmentLines(CPUStylingStageFS);\n shaderBuilder.addDefine(\"USE_CPU_STYLING\", undefined, ShaderDestination.BOTH);\n\n // These uniforms may have already been added by the ModelColorStage\n // if a static color is applied.\n if (!defined(model.color)) {\n shaderBuilder.addUniform(\n \"float\",\n ModelColorPipelineStage.COLOR_BLEND_UNIFORM_NAME,\n ShaderDestination.FRAGMENT\n );\n renderResources.uniformMap[\n ModelColorPipelineStage.COLOR_BLEND_UNIFORM_NAME\n ] = function () {\n return ColorBlendMode.getColorBlend(\n model.colorBlendMode,\n model.colorBlendAmount\n );\n };\n }\n\n shaderBuilder.addUniform(\n \"bool\",\n \"model_commandTranslucent\",\n ShaderDestination.BOTH\n );\n renderResources.uniformMap.model_commandTranslucent = function () {\n // Always check the current value, because custom shaders may\n // change the value with the translucencyMode parameter\n return renderResources.alphaOptions.pass === Pass.TRANSLUCENT;\n };\n};\n\nexport default CPUStylingPipelineStage;\n", "/**\n * An enum describing how the {@link CustomShader} will be added to the\n * fragment shader. This determines how the shader interacts with the material.\n *\n * @enum {string}\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst CustomShaderMode = {\n /**\n * The custom shader will be used to modify the results of the material stage\n * before lighting is applied.\n *\n * @type {string}\n * @constant\n */\n MODIFY_MATERIAL: \"MODIFY_MATERIAL\",\n /**\n * The custom shader will be used instead of the material stage. This is a hint\n * to optimize out the material processing code.\n *\n * @type {string}\n * @constant\n */\n REPLACE_MATERIAL: \"REPLACE_MATERIAL\",\n};\n\n/**\n * Convert the shader mode to an uppercase identifier for use in GLSL define\n * directives. For example: #define CUSTOM_SHADER_MODIFY_MATERIAL\n * @param {CustomShaderMode} customShaderMode The shader mode\n * @return {string} The name of the GLSL macro to use\n *\n * @private\n */\nCustomShaderMode.getDefineName = function (customShaderMode) {\n return `CUSTOM_SHADER_${customShaderMode}`;\n};\n\nexport default Object.freeze(CustomShaderMode);\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void customShaderStage(\\n\\\n inout czm_modelVertexOutput vsOutput, \\n\\\n inout ProcessedAttributes attributes, \\n\\\n FeatureIds featureIds,\\n\\\n Metadata metadata,\\n\\\n MetadataClass metadataClass,\\n\\\n MetadataStatistics metadataStatistics\\n\\\n) {\\n\\\n // VertexInput and initializeInputStruct() are dynamically generated in JS, \\n\\\n // see CustomShaderPipelineStage.js\\n\\\n VertexInput vsInput;\\n\\\n initializeInputStruct(vsInput, attributes);\\n\\\n vsInput.featureIds = featureIds;\\n\\\n vsInput.metadata = metadata;\\n\\\n vsInput.metadataClass = metadataClass;\\n\\\n vsInput.metadataStatistics = metadataStatistics;\\n\\\n vertexMain(vsInput, vsOutput);\\n\\\n attributes.positionMC = vsOutput.positionMC;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void customShaderStage(\\n\\\n inout czm_modelMaterial material,\\n\\\n ProcessedAttributes attributes,\\n\\\n FeatureIds featureIds,\\n\\\n Metadata metadata,\\n\\\n MetadataClass metadataClass,\\n\\\n MetadataStatistics metadataStatistics\\n\\\n) {\\n\\\n // FragmentInput and initializeInputStruct() are dynamically generated in JS, \\n\\\n // see CustomShaderPipelineStage.js\\n\\\n FragmentInput fsInput;\\n\\\n initializeInputStruct(fsInput, attributes);\\n\\\n fsInput.featureIds = featureIds;\\n\\\n fsInput.metadata = metadata;\\n\\\n fsInput.metadataClass = metadataClass;\\n\\\n fsInput.metadataStatistics = metadataStatistics;\\n\\\n fragmentMain(fsInput, material);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void featureIdStage(out FeatureIds featureIds, ProcessedAttributes attributes) {\\n\\\n initializeFeatureIds(featureIds, attributes);\\n\\\n initializeFeatureIdAliases(featureIds);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void featureIdStage(out FeatureIds featureIds, ProcessedAttributes attributes) \\n\\\n{\\n\\\n initializeFeatureIds(featureIds, attributes);\\n\\\n initializeFeatureIdAliases(featureIds);\\n\\\n setFeatureIdVaryings();\\n\\\n}\\n\\\n\";\n", "import ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport FeatureIdStageFS from \"../../Shaders/Model/FeatureIdStageFS.js\";\nimport FeatureIdStageVS from \"../../Shaders/Model/FeatureIdStageVS.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The feature ID pipeline stage is responsible for processing feature IDs\n * (both attributes and textures), updating the shader in preparation for\n * custom shaders, picking, and/or styling.\n *\n * @namespace FeatureIdPipelineStage\n * @private\n */\nconst FeatureIdPipelineStage = {\n name: \"FeatureIdPipelineStage\", // Helps with debugging\n\n STRUCT_ID_FEATURE_IDS_VS: \"FeatureIdsVS\",\n STRUCT_ID_FEATURE_IDS_FS: \"FeatureIdsFS\",\n STRUCT_NAME_FEATURE_IDS: \"FeatureIds\",\n FUNCTION_ID_INITIALIZE_FEATURE_IDS_VS: \"initializeFeatureIdsVS\",\n FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS: \"initializeFeatureIdsFS\",\n FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_VS: \"initializeFeatureIdAliasesVS\",\n FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_FS: \"initializeFeatureIdAliasesFS\",\n FUNCTION_SIGNATURE_INITIALIZE_FEATURE_IDS:\n \"void initializeFeatureIds(out FeatureIds featureIds, ProcessedAttributes attributes)\",\n FUNCTION_SIGNATURE_INITIALIZE_FEATURE_ID_ALIASES:\n \"void initializeFeatureIdAliases(inout FeatureIds featureIds)\",\n FUNCTION_ID_SET_FEATURE_ID_VARYINGS: \"setFeatureIdVaryings\",\n FUNCTION_SIGNATURE_SET_FEATURE_ID_VARYINGS: \"void setFeatureIdVaryings()\",\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render resources:\n *
    \n *
  • Adds the FeatureIds struct and corresponding initialization functions in the vertex and fragment shader
  • \n *
  • For each feature ID attribute, the attributes were already uploaded in the geometry stage, so just update the shader code
  • \n *
  • For each feature ID implicit range, a new attribute is created and uploaded to the GPU since gl_VertexID is not available in WebGL 1. The shader is updated with an attribute, varying, and initialization code.
  • \n *
  • For each feature ID texture, the texture is added to the uniform map, and shader code is added to perform the texture read.
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n */\nFeatureIdPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n declareStructsAndFunctions(shaderBuilder);\n\n const instances = renderResources.runtimeNode.node.instances;\n if (defined(instances)) {\n processInstanceFeatureIds(renderResources, instances, frameState);\n }\n processPrimitiveFeatureIds(renderResources, primitive, frameState);\n\n shaderBuilder.addVertexLines(FeatureIdStageVS);\n shaderBuilder.addFragmentLines(FeatureIdStageFS);\n};\n\nfunction declareStructsAndFunctions(shaderBuilder) {\n // Declare the FeatureIds struct. The vertex shader will only use\n // feature ID attributes, while the fragment shader will also use\n // feature ID textures.\n shaderBuilder.addStruct(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_VS,\n FeatureIdPipelineStage.STRUCT_NAME_FEATURE_IDS,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStruct(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n FeatureIdPipelineStage.STRUCT_NAME_FEATURE_IDS,\n ShaderDestination.FRAGMENT\n );\n\n // declare the initializeFeatureIds() function. The details may differ\n // between vertex and fragment shader\n shaderBuilder.addFunction(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_VS,\n FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_IDS,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addFunction(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS,\n FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_IDS,\n ShaderDestination.FRAGMENT\n );\n\n // declare the initializeFeatureIdAliases() function. The details may differ\n // between vertex and fragment shader\n shaderBuilder.addFunction(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_VS,\n FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_ID_ALIASES,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addFunction(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_FS,\n FeatureIdPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_FEATURE_ID_ALIASES,\n ShaderDestination.FRAGMENT\n );\n\n // declare the setFeatureIdVaryings() function in the vertex shader only\n shaderBuilder.addFunction(\n FeatureIdPipelineStage.FUNCTION_ID_SET_FEATURE_ID_VARYINGS,\n FeatureIdPipelineStage.FUNCTION_SIGNATURE_SET_FEATURE_ID_VARYINGS,\n ShaderDestination.VERTEX\n );\n}\n\nfunction processInstanceFeatureIds(renderResources, instances, frameState) {\n const featureIdsArray = instances.featureIds;\n const count = instances.attributes[0].count;\n\n for (let i = 0; i < featureIdsArray.length; i++) {\n const featureIds = featureIdsArray[i];\n const variableName = featureIds.positionalLabel;\n\n if (featureIds instanceof ModelComponents.FeatureIdAttribute) {\n processInstanceAttribute(renderResources, featureIds, variableName);\n } else {\n const instanceDivisor = 1;\n processImplicitRange(\n renderResources,\n featureIds,\n variableName,\n count,\n instanceDivisor,\n frameState\n );\n }\n\n const label = featureIds.label;\n if (defined(label)) {\n addAlias(renderResources, variableName, label, ShaderDestination.BOTH);\n }\n }\n}\n\nfunction processPrimitiveFeatureIds(renderResources, primitive, frameState) {\n const featureIdsArray = primitive.featureIds;\n const positionAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.POSITION\n );\n const count = positionAttribute.count;\n\n for (let i = 0; i < featureIdsArray.length; i++) {\n const featureIds = featureIdsArray[i];\n const variableName = featureIds.positionalLabel;\n\n let aliasDestination = ShaderDestination.BOTH;\n if (featureIds instanceof ModelComponents.FeatureIdAttribute) {\n processAttribute(renderResources, featureIds, variableName);\n } else if (featureIds instanceof ModelComponents.FeatureIdImplicitRange) {\n processImplicitRange(\n renderResources,\n featureIds,\n variableName,\n count,\n undefined,\n frameState\n );\n } else {\n processTexture(renderResources, featureIds, variableName, i, frameState);\n aliasDestination = ShaderDestination.FRAGMENT;\n }\n\n const label = featureIds.label;\n if (defined(label)) {\n addAlias(renderResources, variableName, label, aliasDestination);\n }\n }\n}\n\nfunction processInstanceAttribute(\n renderResources,\n featureIdAttribute,\n variableName\n) {\n // Add a field to the FeatureIds struct.\n // Example:\n // struct FeatureIds {\n // ...\n // int instanceFeatureId_n;\n // ...\n // }\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_VS,\n \"int\",\n variableName\n );\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n \"int\",\n variableName\n );\n\n // Initialize the field from the corresponding attribute.\n // Example: featureIds.instanceFeatureId_n = int(czm_round(attributes.instanceFeatureId_0));\n const setIndex = featureIdAttribute.setIndex;\n const prefix = variableName.replace(/_\\d+$/, \"_\");\n\n const attributeName = `a_${prefix}${setIndex}`;\n const varyingName = `v_${prefix}${setIndex}`;\n const vertexLine = `featureIds.${variableName} = int(czm_round(${attributeName}));`;\n const fragmentLine = `featureIds.${variableName} = int(czm_round(${varyingName}));`;\n\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_VS,\n [vertexLine]\n );\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS,\n [fragmentLine]\n );\n\n // Instanced attributes don't normally need varyings, so add one here\n shaderBuilder.addVarying(\"float\", varyingName);\n\n // The varying needs initialization in the vertex shader\n // Example:\n // v_instanceFeatureId_n = a_instanceFeatureId_n;\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_SET_FEATURE_ID_VARYINGS,\n [`${varyingName} = ${attributeName};`]\n );\n}\n\nfunction processAttribute(renderResources, featureIdAttribute, variableName) {\n // Add a field to the FeatureIds struct.\n // Example:\n // struct FeatureIds {\n // ...\n // int featureId_n;\n // ...\n // }\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_VS,\n \"int\",\n variableName\n );\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n \"int\",\n variableName\n );\n\n // Initialize the field from the corresponding attribute.\n // Example: featureIds.featureId_n = attributes.featureId_0;\n // Since this uses the ProcessedAttributes struct, the line is the same\n // for both vertex and fragment shader.\n const setIndex = featureIdAttribute.setIndex;\n const prefix = variableName.replace(/_\\d+$/, \"_\");\n\n const initializationLines = [\n `featureIds.${variableName} = int(czm_round(attributes.${prefix}${setIndex}));`,\n ];\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_VS,\n initializationLines\n );\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS,\n initializationLines\n );\n}\n\nfunction processImplicitRange(\n renderResources,\n implicitFeatureIds,\n variableName,\n count,\n instanceDivisor,\n frameState\n) {\n // Generate a vertex attribute for the implicit IDs since WebGL 1 does not\n // support gl_VertexID\n generateImplicitFeatureIdAttribute(\n renderResources,\n implicitFeatureIds,\n count,\n instanceDivisor,\n frameState\n );\n\n // Declare the vertex attribute in the shader\n // Example: in float a_implicit_feature_id_n;\n const shaderBuilder = renderResources.shaderBuilder;\n const implicitAttributeName = `a_implicit_${variableName}`;\n shaderBuilder.addAttribute(\"float\", implicitAttributeName);\n\n // Also declare the corresponding varyings\n // Example: in float v_implicit_feature_id_n;\n const implicitVaryingName = `v_implicit_${variableName}`;\n shaderBuilder.addVarying(\"float\", implicitVaryingName);\n\n // Add a field to the FeatureIds struct.\n // Example:\n // struct FeatureIds {\n // ...\n // int featureId_n;\n // ...\n // }\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_VS,\n \"int\",\n variableName\n );\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n \"int\",\n variableName\n );\n\n // The varying needs initialization in the vertex shader\n // Example:\n // v_implicit_featureId_n = a_implicit_featureId_n;\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_SET_FEATURE_ID_VARYINGS,\n [`${implicitVaryingName} = ${implicitAttributeName};`]\n );\n\n // Initialize the field from the generated attribute/varying.\n // Example:\n // featureIds.featureId_n = a_implicit_featureId_n; (VS)\n // featureIds.featureId_n = v_implicit_featureId_n; (FS)\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_VS,\n [`featureIds.${variableName} = int(czm_round(${implicitAttributeName}));`]\n );\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS,\n [`featureIds.${variableName} = int(czm_round(${implicitVaryingName}));`]\n );\n}\n\nfunction processTexture(\n renderResources,\n featureIdTexture,\n variableName,\n index,\n frameState\n) {\n // Create the feature ID texture uniform. The index matches the index from\n // the featureIds array, even if this is not consecutive.\n const uniformName = `u_featureIdTexture_${index}`;\n const uniformMap = renderResources.uniformMap;\n const textureReader = featureIdTexture.textureReader;\n uniformMap[uniformName] = function () {\n return defaultValue(\n textureReader.texture,\n frameState.context.defaultTexture\n );\n };\n\n const channels = textureReader.channels;\n\n // Add a field to the FeatureIds struct in the fragment shader only\n // Example:\n // struct FeatureIds {\n // ...\n // int featureId_n;\n // ...\n // }\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n \"int\",\n variableName\n );\n\n // Declare the uniform in the fragment shader\n shaderBuilder.addUniform(\n \"sampler2D\",\n uniformName,\n ShaderDestination.FRAGMENT\n );\n\n // Read one or more channels from the texture\n // example: texture(u_featureIdTexture_0, v_texCoord_1).rg\n const texCoord = `v_texCoord_${textureReader.texCoord}`;\n const textureRead = `texture(${uniformName}, ${texCoord}).${channels}`;\n\n // Finally, assign to the struct field. Example:\n // featureIds.featureId_0 = unpacked;\n const initializationLine = `featureIds.${variableName} = czm_unpackUint(${textureRead});`;\n\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_IDS_FS,\n [initializationLine]\n );\n}\n\nfunction addAlias(renderResources, variableName, alias, shaderDestination) {\n // Add a field to the FeatureIds struct.\n // Example:\n // struct FeatureIds {\n // ...\n // int alias;\n // ...\n // }\n const shaderBuilder = renderResources.shaderBuilder;\n const updateVS = ShaderDestination.includesVertexShader(shaderDestination);\n if (updateVS) {\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_VS,\n \"int\",\n alias\n );\n }\n shaderBuilder.addStructField(\n FeatureIdPipelineStage.STRUCT_ID_FEATURE_IDS_FS,\n \"int\",\n alias\n );\n\n // Initialize the field from the original variable\n // Example: featureIds.alias = featureIds.featureId_n;\n const initializationLines = [\n `featureIds.${alias} = featureIds.${variableName};`,\n ];\n if (updateVS) {\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_VS,\n initializationLines\n );\n }\n shaderBuilder.addFunctionLines(\n FeatureIdPipelineStage.FUNCTION_ID_INITIALIZE_FEATURE_ID_ALIASES_FS,\n initializationLines\n );\n}\n\nfunction generateImplicitFeatureIdAttribute(\n renderResources,\n implicitFeatureIds,\n count,\n instanceDivisor,\n frameState\n) {\n const model = renderResources.model;\n let vertexBuffer;\n let value;\n if (defined(implicitFeatureIds.repeat)) {\n const typedArray = generateImplicitFeatureIdTypedArray(\n implicitFeatureIds,\n count\n );\n vertexBuffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: typedArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n vertexBuffer.vertexArrayDestroyable = false;\n model._pipelineResources.push(vertexBuffer);\n const hasCpuCopy = false;\n model.statistics.addBuffer(vertexBuffer, hasCpuCopy);\n } else {\n value = [implicitFeatureIds.offset];\n }\n\n const generatedFeatureIdAttribute = {\n index: renderResources.attributeIndex++,\n instanceDivisor: instanceDivisor,\n value: value,\n vertexBuffer: vertexBuffer,\n normalize: false,\n componentsPerAttribute: 1,\n componentDatatype: ComponentDatatype.FLOAT,\n strideInBytes: ComponentDatatype.getSizeInBytes(ComponentDatatype.FLOAT),\n offsetInBytes: 0,\n };\n\n renderResources.attributes.push(generatedFeatureIdAttribute);\n}\n\n/**\n * Generates a typed array for implicit feature IDs\n * @private\n */\nfunction generateImplicitFeatureIdTypedArray(implicitFeatureIds, count) {\n const offset = implicitFeatureIds.offset;\n const repeat = implicitFeatureIds.repeat;\n\n const typedArray = new Float32Array(count);\n for (let i = 0; i < count; i++) {\n typedArray[i] = offset + Math.floor(i / repeat);\n }\n\n return typedArray;\n}\n\nexport default FeatureIdPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void metadataStage(\\n\\\n out Metadata metadata,\\n\\\n out MetadataClass metadataClass,\\n\\\n out MetadataStatistics metadataStatistics,\\n\\\n ProcessedAttributes attributes\\n\\\n )\\n\\\n{\\n\\\n initializeMetadata(metadata, metadataClass, metadataStatistics, attributes);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void metadataStage(\\n\\\n out Metadata metadata,\\n\\\n out MetadataClass metadataClass,\\n\\\n out MetadataStatistics metadataStatistics,\\n\\\n ProcessedAttributes attributes\\n\\\n )\\n\\\n{\\n\\\n initializeMetadata(metadata, metadataClass, metadataStatistics, attributes);\\n\\\n setMetadataVaryings();\\n\\\n}\\n\\\n\";\n", "import defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport MetadataStageFS from \"../../Shaders/Model/MetadataStageFS.js\";\nimport MetadataStageVS from \"../../Shaders/Model/MetadataStageVS.js\";\nimport MetadataType from \"../MetadataType.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The metadata pipeline stage processes metadata properties from\n * EXT_structural_metadata and inserts them into a struct in the shader.\n * This struct will be used by {@link CustomShaderPipelineStage} to allow the\n * user to access metadata using {@link CustomShader}\n *\n * @namespace MetadataPipelineStage\n *\n * @private\n */\nconst MetadataPipelineStage = {\n name: \"MetadataPipelineStage\",\n\n STRUCT_ID_METADATA_VS: \"MetadataVS\",\n STRUCT_ID_METADATA_FS: \"MetadataFS\",\n STRUCT_NAME_METADATA: \"Metadata\",\n\n STRUCT_ID_METADATA_CLASS_VS: \"MetadataClassVS\",\n STRUCT_ID_METADATA_CLASS_FS: \"MetadataClassFS\",\n STRUCT_NAME_METADATA_CLASS: \"MetadataClass\",\n\n STRUCT_ID_METADATA_STATISTICS_VS: \"MetadataStatisticsVS\",\n STRUCT_ID_METADATA_STATISTICS_FS: \"MetadataStatisticsFS\",\n STRUCT_NAME_METADATA_STATISTICS: \"MetadataStatistics\",\n\n FUNCTION_ID_INITIALIZE_METADATA_VS: \"initializeMetadataVS\",\n FUNCTION_ID_INITIALIZE_METADATA_FS: \"initializeMetadataFS\",\n FUNCTION_SIGNATURE_INITIALIZE_METADATA:\n \"void initializeMetadata(out Metadata metadata, out MetadataClass metadataClass, out MetadataStatistics metadataStatistics, ProcessedAttributes attributes)\",\n FUNCTION_ID_SET_METADATA_VARYINGS: \"setMetadataVaryings\",\n FUNCTION_SIGNATURE_SET_METADATA_VARYINGS: \"void setMetadataVaryings()\",\n\n // Metadata class and statistics fields:\n // - some must be renamed to avoid reserved words\n // - some always have float/vec values, even for integer/ivec property types\n METADATA_CLASS_FIELDS: [\n { specName: \"noData\", shaderName: \"noData\" },\n { specName: \"default\", shaderName: \"defaultValue\" },\n { specName: \"min\", shaderName: \"minValue\" },\n { specName: \"max\", shaderName: \"maxValue\" },\n ],\n METADATA_STATISTICS_FIELDS: [\n { specName: \"min\", shaderName: \"minValue\" },\n { specName: \"max\", shaderName: \"maxValue\" },\n { specName: \"mean\", shaderName: \"mean\", type: \"float\" },\n { specName: \"median\", shaderName: \"median\" },\n {\n specName: \"standardDeviation\",\n shaderName: \"standardDeviation\",\n type: \"float\",\n },\n { specName: \"variance\", shaderName: \"variance\", type: \"float\" },\n { specName: \"sum\", shaderName: \"sum\" },\n ],\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render\n * resources:\n *
    \n *
  • Adds a Metadata struct to the shader
  • \n *
  • If the primitive has structural metadata, properties are added to the Metadata struct
  • \n *
  • dynamic functions are added to the shader to initialize the metadata properties
  • \n *
  • Adds uniforms for property textures to the uniform map as needed
  • \n *
  • Adds uniforms for offset/scale to the uniform map as needed
  • \n *
\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {FrameState} frameState The frame state\n * @private\n */\nMetadataPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const { shaderBuilder, model } = renderResources;\n const { structuralMetadata = {}, content } = model;\n const statistics = content?.tileset.metadataExtension?.statistics;\n\n const propertyAttributesInfo = getPropertyAttributesInfo(\n structuralMetadata.propertyAttributes,\n primitive,\n statistics\n );\n const propertyTexturesInfo = getPropertyTexturesInfo(\n structuralMetadata.propertyTextures,\n statistics\n );\n\n // Declare MetadataClass and MetadataStatistics structs as needed\n const allPropertyInfos = propertyAttributesInfo.concat(propertyTexturesInfo);\n declareMetadataTypeStructs(shaderBuilder, allPropertyInfos);\n\n // Always declare the Metadata, MetadataClass, and MetadataStatistics structs\n // and the initializeMetadata() function, even if not used\n declareStructsAndFunctions(shaderBuilder);\n shaderBuilder.addVertexLines(MetadataStageVS);\n shaderBuilder.addFragmentLines(MetadataStageFS);\n\n for (let i = 0; i < propertyAttributesInfo.length; i++) {\n const info = propertyAttributesInfo[i];\n processPropertyAttributeProperty(renderResources, info);\n }\n for (let i = 0; i < propertyTexturesInfo.length; i++) {\n const info = propertyTexturesInfo[i];\n processPropertyTextureProperty(renderResources, info);\n }\n};\n\n/**\n * Collect info about all properties of all propertyAttributes, and\n * return as a flattened Array\n * @param {PropertyAttribute[]} propertyAttributes The PropertyAttributes with properties to be described\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {object} [statistics] Statistics about the properties (if the model is from a 3DTiles tileset)\n * @returns {Object[]} An array of objects containing information about each PropertyAttributeProperty\n * @private\n */\nfunction getPropertyAttributesInfo(propertyAttributes, primitive, statistics) {\n if (!defined(propertyAttributes)) {\n return [];\n }\n return propertyAttributes.flatMap((propertyAttribute) =>\n getPropertyAttributeInfo(propertyAttribute, primitive, statistics)\n );\n}\n\n/**\n * Collect info about the properties of a single PropertyAttribute\n * @param {PropertyAttribute} propertyAttribute The PropertyAttribute with properties to be described\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {object} [statistics] Statistics about the properties (if the model is from a 3DTiles tileset)\n * @returns {Object[]} An array of objects containing information about each PropertyAttributeProperty\n * @private\n */\nfunction getPropertyAttributeInfo(propertyAttribute, primitive, statistics) {\n const {\n getAttributeByName,\n getAttributeInfo,\n sanitizeGlslIdentifier,\n } = ModelUtility;\n\n const classId = propertyAttribute.class.id;\n const classStatistics = statistics?.classes[classId];\n\n const propertiesArray = Object.entries(propertyAttribute.properties);\n const infoArray = new Array(propertiesArray.length);\n\n for (let i = 0; i < propertiesArray.length; i++) {\n const [propertyId, property] = propertiesArray[i];\n const modelAttribute = getAttributeByName(primitive, property.attribute);\n const { glslType, variableName } = getAttributeInfo(modelAttribute);\n\n infoArray[i] = {\n metadataVariable: sanitizeGlslIdentifier(propertyId),\n property,\n type: property.classProperty.type,\n glslType,\n variableName,\n propertyStatistics: classStatistics?.properties[propertyId],\n shaderDestination: ShaderDestination.BOTH,\n };\n }\n\n return infoArray;\n}\n\n/**\n * Collect info about all properties of all propertyTextures, and\n * return as a flattened Array\n * @param {PropertyTexture[]} propertyTextures The PropertyTextures with properties to be described\n * @param {object} [statistics] Statistics about the properties (if the model is from a 3DTiles tileset)\n * @returns {Object[]} An array of objects containing information about each PropertyTextureProperty\n * @private\n */\nfunction getPropertyTexturesInfo(propertyTextures, statistics) {\n if (!defined(propertyTextures)) {\n return [];\n }\n return propertyTextures.flatMap((propertyTexture) =>\n getPropertyTextureInfo(propertyTexture, statistics)\n );\n}\n\n/**\n * Collect info about the properties of a single PropertyTexture\n * @param {PropertyTexture} propertyTexture The PropertyTexture with properties to be described\n * @param {object} [statistics] Statistics about the properties (if the model is from a 3DTiles tileset)\n * @returns {Object[]} An array of objects containing information about each PropertyTextureProperty\n * @private\n */\nfunction getPropertyTextureInfo(propertyTexture, statistics) {\n const { sanitizeGlslIdentifier } = ModelUtility;\n\n const classId = propertyTexture.class.id;\n const classStatistics = statistics?.classes[classId];\n\n const propertiesArray = Object.entries(\n propertyTexture.properties\n ).filter(([id, property]) => property.isGpuCompatible());\n const infoArray = new Array(propertiesArray.length);\n\n for (let i = 0; i < propertiesArray.length; i++) {\n const [propertyId, property] = propertiesArray[i];\n\n infoArray[i] = {\n metadataVariable: sanitizeGlslIdentifier(propertyId),\n property,\n type: property.classProperty.type,\n glslType: property.getGlslType(),\n propertyStatistics: classStatistics?.properties[propertyId],\n shaderDestination: ShaderDestination.FRAGMENT,\n };\n }\n\n return infoArray;\n}\n\n/**\n * Declare MetadataClass structs in the shader for each PropertyAttributeProperty and PropertyTextureProperty\n * @param {ShaderBuilder} shaderBuilder The shader builder for the primitive\n * @param {Object[]} propertyInfos Information about the PropertyAttributeProperties and PropertyTextureProperties\n * @private\n */\nfunction declareMetadataTypeStructs(shaderBuilder, propertyInfos) {\n const classTypes = new Set();\n const statisticsTypes = new Set();\n\n for (let i = 0; i < propertyInfos.length; i++) {\n const { type, glslType, propertyStatistics } = propertyInfos[i];\n classTypes.add(glslType);\n if (!defined(propertyStatistics)) {\n continue;\n }\n if (type !== MetadataType.ENUM) {\n statisticsTypes.add(glslType);\n }\n }\n\n const classFields = MetadataPipelineStage.METADATA_CLASS_FIELDS;\n for (const metadataType of classTypes) {\n const classStructName = `${metadataType}MetadataClass`;\n declareTypeStruct(classStructName, metadataType, classFields);\n }\n\n const statisticsFields = MetadataPipelineStage.METADATA_STATISTICS_FIELDS;\n for (const metadataType of statisticsTypes) {\n const statisticsStructName = `${metadataType}MetadataStatistics`;\n declareTypeStruct(statisticsStructName, metadataType, statisticsFields);\n }\n\n function declareTypeStruct(structName, type, fields) {\n shaderBuilder.addStruct(structName, structName, ShaderDestination.BOTH);\n\n for (let i = 0; i < fields.length; i++) {\n const { shaderName } = fields[i];\n const shaderType =\n fields[i].type === \"float\" ? convertToFloatComponents(type) : type;\n shaderBuilder.addStructField(structName, shaderType, shaderName);\n }\n }\n}\n\nconst floatConversions = {\n int: \"float\",\n ivec2: \"vec2\",\n ivec3: \"vec3\",\n ivec4: \"vec4\",\n};\n\n/**\n * For a type with integer components, find a corresponding float-component type\n * @param {string} type The name of a GLSL type with integer components\n * @returns {string} The name of a GLSL type of the same dimension with float components, if available; otherwise the input type\n * @private\n */\nfunction convertToFloatComponents(type) {\n const converted = floatConversions[type];\n return defined(converted) ? converted : type;\n}\n\n/**\n * Declare the main Metadata, MetadataClass, and MetadataStatistics structs\n * and the initializeMetadata() function.\n * @param {ShaderBuilder} shaderBuilder The shader builder for the primitive\n * @private\n */\nfunction declareStructsAndFunctions(shaderBuilder) {\n // Declare the Metadata struct.\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_VS,\n MetadataPipelineStage.STRUCT_NAME_METADATA,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_FS,\n MetadataPipelineStage.STRUCT_NAME_METADATA,\n ShaderDestination.FRAGMENT\n );\n\n // Declare the MetadataClass struct\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_CLASS_VS,\n MetadataPipelineStage.STRUCT_NAME_METADATA_CLASS,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_CLASS_FS,\n MetadataPipelineStage.STRUCT_NAME_METADATA_CLASS,\n ShaderDestination.FRAGMENT\n );\n\n // Declare the MetadataStatistics struct\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_STATISTICS_VS,\n MetadataPipelineStage.STRUCT_NAME_METADATA_STATISTICS,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStruct(\n MetadataPipelineStage.STRUCT_ID_METADATA_STATISTICS_FS,\n MetadataPipelineStage.STRUCT_NAME_METADATA_STATISTICS,\n ShaderDestination.FRAGMENT\n );\n\n // declare the initializeMetadata() function. The details may differ\n // between vertex and fragment shader\n shaderBuilder.addFunction(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_VS,\n MetadataPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_METADATA,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addFunction(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS,\n MetadataPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_METADATA,\n ShaderDestination.FRAGMENT\n );\n\n // declare the setMetadataVaryings() function in the vertex shader only.\n shaderBuilder.addFunction(\n MetadataPipelineStage.FUNCTION_ID_SET_METADATA_VARYINGS,\n MetadataPipelineStage.FUNCTION_SIGNATURE_SET_METADATA_VARYINGS,\n ShaderDestination.VERTEX\n );\n}\n\n/**\n * Update the shader for a single PropertyAttributeProperty\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {object} propertyInfo Info about the PropertyAttributeProperty\n * @private\n */\nfunction processPropertyAttributeProperty(renderResources, propertyInfo) {\n addPropertyAttributePropertyMetadata(renderResources, propertyInfo);\n addPropertyMetadataClass(renderResources.shaderBuilder, propertyInfo);\n addPropertyMetadataStatistics(renderResources.shaderBuilder, propertyInfo);\n}\n\n/**\n * Add fields to the Metadata struct, and metadata value assignments to the\n * initializeMetadata function, for a PropertyAttributeProperty\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {object} propertyInfo Info about the PropertyAttributeProperty\n * @private\n */\nfunction addPropertyAttributePropertyMetadata(renderResources, propertyInfo) {\n const { shaderBuilder } = renderResources;\n const { metadataVariable, property, glslType } = propertyInfo;\n\n const valueExpression = addValueTransformUniforms({\n valueExpression: `attributes.${propertyInfo.variableName}`,\n renderResources: renderResources,\n glslType: glslType,\n metadataVariable: metadataVariable,\n shaderDestination: ShaderDestination.BOTH,\n property: property,\n });\n\n // declare the struct field\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_VS,\n glslType,\n metadataVariable\n );\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_FS,\n glslType,\n metadataVariable\n );\n\n // assign the result to the metadata struct property.\n const initializationLine = `metadata.${metadataVariable} = ${valueExpression};`;\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_VS,\n [initializationLine]\n );\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS,\n [initializationLine]\n );\n}\n\n/**\n * Update the shader for a single PropertyTextureProperty\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {Object[]} propertyInfo Info about the PropertyTextureProperty\n * @private\n */\nfunction processPropertyTextureProperty(renderResources, propertyInfo) {\n addPropertyTexturePropertyMetadata(renderResources, propertyInfo);\n addPropertyMetadataClass(renderResources.shaderBuilder, propertyInfo);\n addPropertyMetadataStatistics(renderResources.shaderBuilder, propertyInfo);\n}\n\n/**\n * Add fields to the Metadata struct, and metadata value expressions to the\n * initializeMetadata function, for a PropertyTextureProperty\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {object} propertyInfo Info about the PropertyTextureProperty\n * @private\n */\nfunction addPropertyTexturePropertyMetadata(renderResources, propertyInfo) {\n const { shaderBuilder, uniformMap } = renderResources;\n const { metadataVariable, glslType, property } = propertyInfo;\n\n const { texCoord, channels, index, texture } = property.textureReader;\n const textureUniformName = `u_propertyTexture_${index}`;\n\n // Property texture properties may share the same physical texture, so only\n // add the texture uniform the first time we encounter it.\n if (!uniformMap.hasOwnProperty(textureUniformName)) {\n shaderBuilder.addUniform(\n \"sampler2D\",\n textureUniformName,\n ShaderDestination.FRAGMENT\n );\n uniformMap[textureUniformName] = () => texture;\n }\n\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_FS,\n glslType,\n metadataVariable\n );\n\n // Get a GLSL expression for the value of the property\n const texCoordVariable = `attributes.texCoord_${texCoord}`;\n const valueExpression = `texture(${textureUniformName}, ${texCoordVariable}).${channels}`;\n\n // Some types need an unpacking step or two. For example, since texture reads\n // are always normalized, UINT8 (not normalized) properties need to be\n // un-normalized in the shader.\n const unpackedValue = property.unpackInShader(valueExpression);\n\n const transformedValue = addValueTransformUniforms({\n valueExpression: unpackedValue,\n renderResources: renderResources,\n glslType: glslType,\n metadataVariable: metadataVariable,\n shaderDestination: ShaderDestination.FRAGMENT,\n property: property,\n });\n\n const initializationLine = `metadata.${metadataVariable} = ${transformedValue};`;\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS,\n [initializationLine]\n );\n}\n\n/**\n * Add fields to the MetadataClass struct, and metadataClass value expressions\n * to the initializeMetadata function, for a PropertyAttributeProperty or\n * PropertyTextureProperty\n * @param {ShaderBuilder} shaderBuilder The shader builder for the primitive\n * @param {object} propertyInfo Info about the PropertyAttributeProperty or PropertyTextureProperty\n * @private\n */\nfunction addPropertyMetadataClass(shaderBuilder, propertyInfo) {\n const { classProperty } = propertyInfo.property;\n const { metadataVariable, glslType, shaderDestination } = propertyInfo;\n\n // Construct assignment statements to set values in the metadataClass struct\n const assignments = getStructAssignments(\n MetadataPipelineStage.METADATA_CLASS_FIELDS,\n classProperty,\n `metadataClass.${metadataVariable}`,\n glslType\n );\n\n // Struct field: Prefix to get the appropriate MetadataClass struct\n const metadataType = `${glslType}MetadataClass`;\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_CLASS_FS,\n metadataType,\n metadataVariable\n );\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS,\n assignments\n );\n if (!ShaderDestination.includesVertexShader(shaderDestination)) {\n return;\n }\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_CLASS_VS,\n metadataType,\n metadataVariable\n );\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_VS,\n assignments\n );\n}\n\n/**\n * Add fields to the MetadataStatistics struct, and metadataStatistics value\n * expressions to the initializeMetadata function, for a\n * PropertyAttributeProperty or PropertyTextureProperty\n * @param {ShaderBuilder} shaderBuilder The shader builder for the primitive\n * @param {object} propertyInfo Info about the PropertyAttributeProperty or PropertyTextureProperty\n * @private\n */\nfunction addPropertyMetadataStatistics(shaderBuilder, propertyInfo) {\n const { propertyStatistics } = propertyInfo;\n if (!defined(propertyStatistics)) {\n return;\n }\n const { metadataVariable, type, glslType } = propertyInfo;\n if (type === MetadataType.ENUM) {\n // enums have an \"occurrences\" statistic which is not implemented yet\n return;\n }\n\n // Construct assignment statements to set values in the metadataStatistics struct\n const fields = MetadataPipelineStage.METADATA_STATISTICS_FIELDS;\n const struct = `metadataStatistics.${metadataVariable}`;\n const assignments = getStructAssignments(\n fields,\n propertyStatistics,\n struct,\n glslType\n );\n\n // Struct field: Prefix to get the appropriate MetadataStatistics struct\n const statisticsType = `${glslType}MetadataStatistics`;\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_STATISTICS_FS,\n statisticsType,\n metadataVariable\n );\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_FS,\n assignments\n );\n if (!ShaderDestination.includesVertexShader(propertyInfo.shaderDestination)) {\n return;\n }\n shaderBuilder.addStructField(\n MetadataPipelineStage.STRUCT_ID_METADATA_STATISTICS_VS,\n statisticsType,\n metadataVariable\n );\n shaderBuilder.addFunctionLines(\n MetadataPipelineStage.FUNCTION_ID_INITIALIZE_METADATA_VS,\n assignments\n );\n}\n\n/**\n * Construct GLSL assignment statements to set metadata spec values in a struct\n * @param {Object[]} fieldNames An object with the following properties:\n * @param {string} fieldNames[].specName The name of the property in the spec\n * @param {string} fieldNames[].shaderName The name of the property in the shader\n * @param {object} values A source of property values, keyed on fieldNames[].specName\n * @param {string} struct The name of the struct to which values will be assigned\n * @param {string} type The type of the values to be assigned\n * @returns {Array<{name: string, value: any}>} Objects containing the property name (in the shader) and a GLSL assignment statement for the property value\n * @private\n */\nfunction getStructAssignments(fieldNames, values, struct, type) {\n function constructAssignment(field) {\n const value = values[field.specName];\n if (defined(value)) {\n return `${struct}.${field.shaderName} = ${type}(${value});`;\n }\n }\n return defined(values)\n ? fieldNames.map(constructAssignment).filter(defined)\n : [];\n}\n\n/**\n * Handle offset/scale transform for a property value\n * This wraps the GLSL value expression with a czm_valueTransform() call\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.valueExpression The GLSL value expression without the transform\n * @param {string} options.metadataVariable The name of the GLSL variable that will contain the property value\n * @param {string} options.glslType The GLSL type of the variable\n * @param {ShaderDestination} options.shaderDestination Which shader(s) use this variable\n * @param {PrimitiveRenderResources} options.renderResources The render resources for this primitive\n * @param {(PropertyAttributeProperty|PropertyTextureProperty)} options.property The property from which the value is derived\n * @returns {string} A wrapped GLSL value expression\n * @private\n */\nfunction addValueTransformUniforms(options) {\n const { valueExpression, property } = options;\n\n if (!property.hasValueTransform) {\n return valueExpression;\n }\n\n const metadataVariable = options.metadataVariable;\n const offsetUniformName = `u_${metadataVariable}_offset`;\n const scaleUniformName = `u_${metadataVariable}_scale`;\n\n const { shaderBuilder, uniformMap } = options.renderResources;\n const { glslType, shaderDestination } = options;\n shaderBuilder.addUniform(glslType, offsetUniformName, shaderDestination);\n shaderBuilder.addUniform(glslType, scaleUniformName, shaderDestination);\n\n const { offset, scale } = property;\n uniformMap[offsetUniformName] = () => offset;\n uniformMap[scaleUniformName] = () => scale;\n\n return `czm_valueTransform(${offsetUniformName}, ${scaleUniformName}, ${valueExpression})`;\n}\n\nexport default MetadataPipelineStage;\n", "/**\n * An enum for controling how {@link CustomShader} handles translucency compared with the original\n * primitive.\n *\n * @enum {number}\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst CustomShaderTranslucencyMode = {\n /**\n * Inherit translucency settings from the primitive's material. If the primitive used a\n * translucent material, the custom shader will also be considered translucent. If the primitive\n * used an opaque material, the custom shader will be considered opaque.\n *\n * @type {number}\n * @constant\n */\n INHERIT: 0,\n /**\n * Force the primitive to render the primitive as opaque, ignoring any material settings.\n *\n * @type {number}\n * @constant\n */\n OPAQUE: 1,\n /**\n * Force the primitive to render the primitive as translucent, ignoring any material settings.\n *\n * @type {number}\n * @constant\n */\n TRANSLUCENT: 2,\n};\n\nexport default Object.freeze(CustomShaderTranslucencyMode);\n", "import combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport oneTimeWarning from \"../../Core/oneTimeWarning.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport CustomShaderStageVS from \"../../Shaders/Model/CustomShaderStageVS.js\";\nimport CustomShaderStageFS from \"../../Shaders/Model/CustomShaderStageFS.js\";\nimport CustomShaderMode from \"./CustomShaderMode.js\";\nimport FeatureIdPipelineStage from \"./FeatureIdPipelineStage.js\";\nimport MetadataPipelineStage from \"./MetadataPipelineStage.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport CustomShaderTranslucencyMode from \"./CustomShaderTranslucencyMode.js\";\n\n/**\n * The custom shader pipeline stage takes GLSL callbacks from the\n * {@link CustomShader} and inserts them into the overall shader code for the\n * {@link Model}. The input to the callback is a struct with many\n * properties that depend on the attributes of the primitive. This shader code\n * is automatically generated by this stage.\n *\n * @namespace CustomShaderPipelineStage\n *\n * @private\n */\nconst CustomShaderPipelineStage = {\n name: \"CustomShaderPipelineStage\", // Helps with debugging\n\n STRUCT_ID_ATTRIBUTES_VS: \"AttributesVS\",\n STRUCT_ID_ATTRIBUTES_FS: \"AttributesFS\",\n STRUCT_NAME_ATTRIBUTES: \"Attributes\",\n STRUCT_ID_VERTEX_INPUT: \"VertexInput\",\n STRUCT_NAME_VERTEX_INPUT: \"VertexInput\",\n STRUCT_ID_FRAGMENT_INPUT: \"FragmentInput\",\n STRUCT_NAME_FRAGMENT_INPUT: \"FragmentInput\",\n FUNCTION_ID_INITIALIZE_INPUT_STRUCT_VS: \"initializeInputStructVS\",\n FUNCTION_SIGNATURE_INITIALIZE_INPUT_STRUCT_VS:\n \"void initializeInputStruct(out VertexInput vsInput, ProcessedAttributes attributes)\",\n FUNCTION_ID_INITIALIZE_INPUT_STRUCT_FS: \"initializeInputStructFS\",\n FUNCTION_SIGNATURE_INITIALIZE_INPUT_STRUCT_FS:\n \"void initializeInputStruct(out FragmentInput fsInput, ProcessedAttributes attributes)\",\n\n // Expose method for testing.\n _oneTimeWarning: oneTimeWarning,\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render\n * resources:\n *
    \n *
  • Modifies the shader to include the custom shader code to the vertex and fragment shaders
  • \n *
  • Modifies the shader to include automatically-generated structs that serve as input to the custom shader callbacks
  • \n *
  • Modifies the shader to include any additional user-defined uniforms
  • \n *
  • Modifies the shader to include any additional user-defined varyings
  • \n *
  • Adds any user-defined uniforms to the uniform map
  • \n *
  • If the user specified a lighting model, the settings are overridden in the render resources
  • \n *
\n *

\n * This pipeline stage is designed to fail gracefully where possible. If the\n * primitive does not have the right attributes to satisfy the shader code,\n * defaults will be inferred (when reasonable to do so). If not, the custom\n * shader will be disabled.\n *

\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {FrameState} frameState The frame state.\n * @private\n */\nCustomShaderPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const { shaderBuilder, model, alphaOptions } = renderResources;\n const { customShader } = model;\n\n // Check the lighting model and translucent options first, as sometimes\n // these are used even if there is no vertex or fragment shader text.\n const { lightingModel, translucencyMode } = customShader;\n\n // if present, the lighting model overrides the material's lighting model.\n if (defined(lightingModel)) {\n renderResources.lightingOptions.lightingModel = lightingModel;\n }\n\n if (translucencyMode === CustomShaderTranslucencyMode.TRANSLUCENT) {\n alphaOptions.pass = Pass.TRANSLUCENT;\n } else if (translucencyMode === CustomShaderTranslucencyMode.OPAQUE) {\n // Use the default opqaue pass (either OPAQUE or 3D_TILES), regardless of whether\n // the material pipeline stage used translucent. The default is configured\n // in AlphaPipelineStage\n alphaOptions.pass = undefined;\n }\n // For CustomShaderTranslucencyMode.INHERIT, do not modify alphaOptions.pass\n\n // Generate lines of code for the shader, but don't add them to the shader\n // yet.\n const generatedCode = generateShaderLines(customShader, primitive);\n\n // In some corner cases, the primitive may not be compatible with the\n // shader. In this case, skip the custom shader.\n if (!generatedCode.customShaderEnabled) {\n return;\n }\n addLinesToShader(shaderBuilder, customShader, generatedCode);\n\n // the input to the fragment shader may include a low-precision ECEF position\n if (generatedCode.shouldComputePositionWC) {\n shaderBuilder.addDefine(\n \"COMPUTE_POSITION_WC_CUSTOM_SHADER\",\n undefined,\n ShaderDestination.BOTH\n );\n }\n\n if (defined(customShader.vertexShaderText)) {\n shaderBuilder.addDefine(\n \"HAS_CUSTOM_VERTEX_SHADER\",\n undefined,\n ShaderDestination.VERTEX\n );\n }\n\n if (defined(customShader.fragmentShaderText)) {\n shaderBuilder.addDefine(\n \"HAS_CUSTOM_FRAGMENT_SHADER\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n // add defines like CUSTOM_SHADER_MODIFY_MATERIAL\n const shaderModeDefine = CustomShaderMode.getDefineName(customShader.mode);\n shaderBuilder.addDefine(\n shaderModeDefine,\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const uniforms = customShader.uniforms;\n for (const uniformName in uniforms) {\n if (uniforms.hasOwnProperty(uniformName)) {\n const uniform = uniforms[uniformName];\n shaderBuilder.addUniform(uniform.type, uniformName);\n }\n }\n\n const varyings = customShader.varyings;\n for (const varyingName in varyings) {\n if (varyings.hasOwnProperty(varyingName)) {\n const varyingType = varyings[varyingName];\n shaderBuilder.addVarying(varyingType, varyingName);\n }\n }\n\n renderResources.uniformMap = combine(\n renderResources.uniformMap,\n customShader.uniformMap\n );\n};\n\n/**\n * @private\n * @param {ModelComponents.Attribute[]} attributes\n * @returns {Object}\n */\nfunction getAttributesByName(attributes) {\n const names = {};\n for (let i = 0; i < attributes.length; i++) {\n const attributeInfo = ModelUtility.getAttributeInfo(attributes[i]);\n names[attributeInfo.variableName] = attributeInfo;\n }\n return names;\n}\n\n// GLSL types of standard attribute types when uniquely defined\nconst attributeTypeLUT = {\n position: \"vec3\",\n normal: \"vec3\",\n tangent: \"vec3\",\n bitangent: \"vec3\",\n texCoord: \"vec2\",\n color: \"vec4\",\n joints: \"ivec4\",\n weights: \"vec4\",\n};\n\n// Corresponding attribute values\nconst attributeDefaultValueLUT = {\n position: \"vec3(0.0)\",\n normal: \"vec3(0.0, 0.0, 1.0)\",\n tangent: \"vec3(1.0, 0.0, 0.0)\",\n bitangent: \"vec3(0.0, 1.0, 0.0)\",\n texCoord: \"vec2(0.0)\",\n color: \"vec4(1.0)\",\n joints: \"ivec4(0)\",\n weights: \"vec4(0.0)\",\n};\n\nfunction inferAttributeDefaults(attributeName) {\n // remove trailing set indices. E.g. \"texCoord_0\" -> \"texCoord\"\n let trimmed = attributeName.replace(/_[0-9]+$/, \"\");\n // also remove the MC/EC since they will have the same default value\n trimmed = trimmed.replace(/(MC|EC)$/, \"\");\n\n const glslType = attributeTypeLUT[trimmed];\n const value = attributeDefaultValueLUT[trimmed];\n\n // - _CUSTOM_ATTRIBUTE has an unknown type.\n if (!defined(glslType)) {\n return undefined;\n }\n\n return {\n attributeField: [glslType, attributeName],\n value: value,\n };\n}\n\n/**\n * @private\n * @param {CustomShader} customShader\n * @param {Object} attributesByName\n * @returns {object}\n */\nfunction generateVertexShaderLines(customShader, attributesByName) {\n if (!defined(customShader.vertexShaderText)) {\n return { enabled: false };\n }\n\n const primitiveAttributes = customShader.usedVariablesVertex.attributeSet;\n const addToShader = getPrimitiveAttributesUsedInShader(\n attributesByName,\n primitiveAttributes,\n false\n );\n const needsDefault = getAttributesNeedingDefaults(\n attributesByName,\n primitiveAttributes,\n false\n );\n\n let vertexInitialization;\n const attributeFields = [];\n const initializationLines = [];\n for (const variableName in addToShader) {\n if (!addToShader.hasOwnProperty(variableName)) {\n continue;\n }\n const attributeInfo = addToShader[variableName];\n const attributeField = [attributeInfo.glslType, variableName];\n attributeFields.push(attributeField);\n\n // Initializing attribute structs are just a matter of copying the\n // attribute or varying: E.g.:\n // \" vsInput.attributes.position = a_position;\"\n vertexInitialization = `vsInput.attributes.${variableName} = attributes.${variableName};`;\n initializationLines.push(vertexInitialization);\n }\n\n for (let i = 0; i < needsDefault.length; i++) {\n const variableName = needsDefault[i];\n const attributeDefaults = inferAttributeDefaults(variableName);\n if (!defined(attributeDefaults)) {\n CustomShaderPipelineStage._oneTimeWarning(\n \"CustomShaderPipelineStage.incompatiblePrimitiveVS\",\n `Primitive is missing attribute ${variableName}, disabling custom vertex shader`\n );\n // This primitive isn't compatible with the shader. Return early\n // to skip the vertex shader\n return { enabled: false };\n }\n\n attributeFields.push(attributeDefaults.attributeField);\n vertexInitialization = `vsInput.attributes.${variableName} = ${attributeDefaults.value};`;\n initializationLines.push(vertexInitialization);\n }\n\n return {\n enabled: true,\n attributeFields: attributeFields,\n initializationLines: initializationLines,\n };\n}\n\nfunction generatePositionBuiltins(customShader) {\n const attributeFields = [];\n const initializationLines = [];\n const usedVariables = customShader.usedVariablesFragment.attributeSet;\n\n // Model space position is the same position as in the glTF accessor,\n // this is already added to the shader with other attributes.\n\n // World coordinates in ECEF coordinates. Note that this is\n // low precision (32-bit floats) on the GPU.\n if (usedVariables.hasOwnProperty(\"positionWC\")) {\n attributeFields.push([\"vec3\", \"positionWC\"]);\n initializationLines.push(\n \"fsInput.attributes.positionWC = attributes.positionWC;\"\n );\n }\n\n // position in eye coordinates\n if (usedVariables.hasOwnProperty(\"positionEC\")) {\n attributeFields.push([\"vec3\", \"positionEC\"]);\n initializationLines.push(\n \"fsInput.attributes.positionEC = attributes.positionEC;\"\n );\n }\n\n return {\n attributeFields: attributeFields,\n initializationLines: initializationLines,\n };\n}\n\n/**\n * @private\n * @param {CustomShader} customShader\n * @param {Object} attributesByName\n * @returns {object}\n */\nfunction generateFragmentShaderLines(customShader, attributesByName) {\n if (!defined(customShader.fragmentShaderText)) {\n return { enabled: false };\n }\n\n const primitiveAttributes = customShader.usedVariablesFragment.attributeSet;\n const addToShader = getPrimitiveAttributesUsedInShader(\n attributesByName,\n primitiveAttributes,\n true\n );\n const needsDefault = getAttributesNeedingDefaults(\n attributesByName,\n primitiveAttributes,\n true\n );\n\n let fragmentInitialization;\n const attributeFields = [];\n const initializationLines = [];\n for (const variableName in addToShader) {\n if (!addToShader.hasOwnProperty(variableName)) {\n continue;\n }\n const attributeInfo = addToShader[variableName];\n\n const attributeField = [attributeInfo.glslType, variableName];\n attributeFields.push(attributeField);\n\n // Initializing attribute structs are just a matter of copying the\n // value from the processed attributes\n // \" fsInput.attributes.positionMC = attributes.positionMC;\"\n fragmentInitialization = `fsInput.attributes.${variableName} = attributes.${variableName};`;\n initializationLines.push(fragmentInitialization);\n }\n\n for (let i = 0; i < needsDefault.length; i++) {\n const variableName = needsDefault[i];\n const attributeDefaults = inferAttributeDefaults(variableName);\n if (!defined(attributeDefaults)) {\n CustomShaderPipelineStage._oneTimeWarning(\n \"CustomShaderPipelineStage.incompatiblePrimitiveFS\",\n `Primitive is missing attribute ${variableName}, disabling custom fragment shader.`\n );\n\n // This primitive isn't compatible with the shader. Return early\n // so the fragment shader is skipped\n return { enabled: false };\n }\n\n attributeFields.push(attributeDefaults.attributeField);\n fragmentInitialization = `fsInput.attributes.${variableName} = ${attributeDefaults.value};`;\n initializationLines.push(fragmentInitialization);\n }\n\n // Built-ins for positions in various coordinate systems.\n const positionBuiltins = generatePositionBuiltins(customShader);\n\n return {\n enabled: true,\n attributeFields: attributeFields.concat(positionBuiltins.attributeFields),\n initializationLines: positionBuiltins.initializationLines.concat(\n initializationLines\n ),\n };\n}\n\n// These attributes are derived from positionMC, and are handled separately\n// from other attributes\nconst builtinAttributes = {\n positionWC: true,\n positionEC: true,\n};\n\n/**\n * Get the primitive attributes that are referenced in the shader\n *\n * @private\n * @param {Object} primitiveAttributes set of all the primitive's attributes\n * @param {Object} shaderAttributeSet set of all attributes used in the shader\n * @param {boolean} isFragmentShader\n * @returns {Object} A dictionary of the primitive attributes used in the shader\n */\nfunction getPrimitiveAttributesUsedInShader(\n primitiveAttributes,\n shaderAttributeSet,\n isFragmentShader\n) {\n const addToShader = {};\n for (const attributeName in primitiveAttributes) {\n if (!primitiveAttributes.hasOwnProperty(attributeName)) {\n continue;\n }\n const attribute = primitiveAttributes[attributeName];\n\n // normals and tangents are in model coordinates in the attributes but\n // in eye coordinates in the fragment shader.\n let renamed = attributeName;\n if (isFragmentShader && attributeName === \"normalMC\") {\n renamed = \"normalEC\";\n } else if (isFragmentShader && attributeName === \"tangentMC\") {\n renamed = \"tangentEC\";\n attribute.glslType = \"vec3\";\n }\n\n if (shaderAttributeSet.hasOwnProperty(renamed)) {\n addToShader[renamed] = attribute;\n }\n }\n return addToShader;\n}\n\n/**\n * Get the attributes that will need to have default values defined.\n * Attributes referenced in the shader which are not already defined\n * for the primitive and are not built-in will need default values.\n *\n * @private\n * @param {Object} primitiveAttributes set of all the primitive's attributes\n * @param {Object} shaderAttributeSet set of all attributes used in the shader\n * @param {boolean} isFragmentShader\n * @returns {string[]} The names of the attributes needing defaults\n */\nfunction getAttributesNeedingDefaults(\n primitiveAttributes,\n shaderAttributeSet,\n isFragmentShader\n) {\n const needDefaults = [];\n for (const attributeName in shaderAttributeSet) {\n if (!shaderAttributeSet.hasOwnProperty(attributeName)) {\n continue;\n }\n if (builtinAttributes.hasOwnProperty(attributeName)) {\n // Builtins are handled separately from attributes, so skip them here\n continue;\n }\n\n // normals and tangents are in model coordinates in the attributes but\n // in eye coordinates in the fragment shader.\n let renamed = attributeName;\n if (isFragmentShader && attributeName === \"normalEC\") {\n renamed = \"normalMC\";\n } else if (isFragmentShader && attributeName === \"tangentEC\") {\n renamed = \"tangentMC\";\n }\n\n if (!primitiveAttributes.hasOwnProperty(renamed)) {\n needDefaults.push(attributeName);\n }\n }\n return needDefaults;\n}\n\n/**\n * @private\n * @param {CustomShader} customShader\n * @param {ModelComponents.Primitive} primitive\n * @returns {object}\n */\nfunction generateShaderLines(customShader, primitive) {\n // Attempt to generate vertex and fragment shader lines before adding any\n // code to the shader.\n const attributesByName = getAttributesByName(primitive.attributes);\n const vertexLines = generateVertexShaderLines(customShader, attributesByName);\n const fragmentLines = generateFragmentShaderLines(\n customShader,\n attributesByName\n );\n\n // positionWC must be computed in the vertex shader\n // for use in the fragmentShader. However, this can be skipped if:\n // - positionWC isn't used in the fragment shader\n // - or the fragment shader is disabled\n const attributeSetFS = customShader.usedVariablesFragment.attributeSet;\n const shouldComputePositionWC =\n attributeSetFS.hasOwnProperty(\"positionWC\") && fragmentLines.enabled;\n\n // Return any generated shader code along with some flags to indicate which\n // defines should be added.\n return {\n vertexLines: vertexLines,\n fragmentLines: fragmentLines,\n customShaderEnabled: vertexLines.enabled || fragmentLines.enabled,\n shouldComputePositionWC: shouldComputePositionWC,\n };\n}\n\nfunction addVertexLinesToShader(shaderBuilder, vertexLines) {\n let structId = CustomShaderPipelineStage.STRUCT_ID_ATTRIBUTES_VS;\n shaderBuilder.addStruct(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_ATTRIBUTES,\n ShaderDestination.VERTEX\n );\n\n const { attributeFields, initializationLines } = vertexLines;\n for (let i = 0; i < attributeFields.length; i++) {\n const [glslType, variableName] = attributeFields[i];\n shaderBuilder.addStructField(structId, glslType, variableName);\n }\n\n // This could be hard-coded, but the symmetry with other structs makes unit\n // tests more convenient\n structId = CustomShaderPipelineStage.STRUCT_ID_VERTEX_INPUT;\n shaderBuilder.addStruct(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_VERTEX_INPUT,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStructField(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_ATTRIBUTES,\n \"attributes\"\n );\n // Add FeatureIds struct from the Feature ID stage\n shaderBuilder.addStructField(\n structId,\n FeatureIdPipelineStage.STRUCT_NAME_FEATURE_IDS,\n \"featureIds\"\n );\n // Add Metadata struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA,\n \"metadata\"\n );\n // Add MetadataClass struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA_CLASS,\n \"metadataClass\"\n );\n // Add MetadataStatistics struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA_STATISTICS,\n \"metadataStatistics\"\n );\n\n const functionId =\n CustomShaderPipelineStage.FUNCTION_ID_INITIALIZE_INPUT_STRUCT_VS;\n shaderBuilder.addFunction(\n functionId,\n CustomShaderPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_INPUT_STRUCT_VS,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addFunctionLines(functionId, initializationLines);\n}\n\nfunction addFragmentLinesToShader(shaderBuilder, fragmentLines) {\n let structId = CustomShaderPipelineStage.STRUCT_ID_ATTRIBUTES_FS;\n shaderBuilder.addStruct(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_ATTRIBUTES,\n ShaderDestination.FRAGMENT\n );\n\n const { attributeFields, initializationLines } = fragmentLines;\n for (let i = 0; i < attributeFields.length; i++) {\n const [glslType, variableName] = attributeFields[i];\n shaderBuilder.addStructField(structId, glslType, variableName);\n }\n\n structId = CustomShaderPipelineStage.STRUCT_ID_FRAGMENT_INPUT;\n shaderBuilder.addStruct(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_FRAGMENT_INPUT,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addStructField(\n structId,\n CustomShaderPipelineStage.STRUCT_NAME_ATTRIBUTES,\n \"attributes\"\n );\n // Add FeatureIds struct from the Feature ID stage\n shaderBuilder.addStructField(\n structId,\n FeatureIdPipelineStage.STRUCT_NAME_FEATURE_IDS,\n \"featureIds\"\n );\n // Add Metadata struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA,\n \"metadata\"\n );\n // Add MetadataClass struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA_CLASS,\n \"metadataClass\"\n );\n // Add MetadataStatistics struct from the metadata stage\n shaderBuilder.addStructField(\n structId,\n MetadataPipelineStage.STRUCT_NAME_METADATA_STATISTICS,\n \"metadataStatistics\"\n );\n\n const functionId =\n CustomShaderPipelineStage.FUNCTION_ID_INITIALIZE_INPUT_STRUCT_FS;\n shaderBuilder.addFunction(\n functionId,\n CustomShaderPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_INPUT_STRUCT_FS,\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addFunctionLines(functionId, initializationLines);\n}\n\nconst scratchShaderLines = [];\n\nfunction addLinesToShader(shaderBuilder, customShader, generatedCode) {\n const { vertexLines, fragmentLines } = generatedCode;\n const shaderLines = scratchShaderLines;\n\n if (vertexLines.enabled) {\n addVertexLinesToShader(shaderBuilder, vertexLines);\n\n shaderLines.length = 0;\n shaderLines.push(\n \"#line 0\",\n customShader.vertexShaderText,\n CustomShaderStageVS\n );\n\n shaderBuilder.addVertexLines(shaderLines);\n }\n\n if (fragmentLines.enabled) {\n addFragmentLinesToShader(shaderBuilder, fragmentLines);\n\n shaderLines.length = 0;\n shaderLines.push(\n \"#line 0\",\n customShader.fragmentShaderText,\n CustomShaderStageFS\n );\n\n shaderBuilder.addFragmentLines(shaderLines);\n }\n}\n\nexport default CustomShaderPipelineStage;\n", "import defined from \"../../Core/defined.js\";\nimport Cartesian4 from \"../../Core/Cartesian4.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\n/**\n * The dequantization stage generates shader code to dequantize attributes\n * in the vertex shader\n *\n * @namespace DequantizationPipelineStage\n *\n * @private\n */\nconst DequantizationPipelineStage = {\n name: \"DequantizationPipelineStage\", // Helps with debugging\n\n FUNCTION_ID_DEQUANTIZATION_STAGE_VS: \"dequantizationStage\",\n FUNCTION_SIGNATURE_DEQUANTIZATION_STAGE_VS:\n \"void dequantizationStage(inout ProcessedAttributes attributes)\",\n};\n\n/**\n * Process a primitive with quantized attributes. This stage modifies the\n * following parts of the render resources:\n *

    \n *
  • generates dequantization function and adds it to the shader
  • \n *
  • adds any uniforms needed for dequantization to the shader and uniform map
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nDequantizationPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const model = renderResources.model;\n const hasClassification = defined(model.classificationType);\n\n shaderBuilder.addDefine(\n \"USE_DEQUANTIZATION\",\n undefined,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addFunction(\n DequantizationPipelineStage.FUNCTION_ID_DEQUANTIZATION_STAGE_VS,\n DequantizationPipelineStage.FUNCTION_SIGNATURE_DEQUANTIZATION_STAGE_VS,\n ShaderDestination.VERTEX\n );\n\n const attributes = primitive.attributes;\n for (let i = 0; i < attributes.length; i++) {\n const attribute = attributes[i];\n const quantization = attribute.quantization;\n if (!defined(quantization)) {\n // Non-quantized attributes were already handled in GeometryPipelineStage\n continue;\n }\n\n // Only the position and texcoord attributes are used for classification models.\n const isPositionAttribute =\n attribute.semantic === VertexAttributeSemantic.POSITION;\n const isTexcoordAttribute =\n attribute.semantic === VertexAttributeSemantic.TEXCOORD;\n if (hasClassification && !isPositionAttribute && !isTexcoordAttribute) {\n continue;\n }\n\n const attributeInfo = ModelUtility.getAttributeInfo(attribute);\n updateDequantizationFunction(shaderBuilder, attributeInfo);\n addDequantizationUniforms(renderResources, attributeInfo);\n }\n};\n\nfunction addDequantizationUniforms(renderResources, attributeInfo) {\n const shaderBuilder = renderResources.shaderBuilder;\n const uniformMap = renderResources.uniformMap;\n const variableName = attributeInfo.variableName;\n const quantization = attributeInfo.attribute.quantization;\n\n if (quantization.octEncoded) {\n const normalizationRange = `model_normalizationRange_${variableName}`;\n shaderBuilder.addUniform(\n \"float\",\n normalizationRange,\n ShaderDestination.VERTEX\n );\n uniformMap[normalizationRange] = function () {\n return quantization.normalizationRange;\n };\n } else {\n const offset = `model_quantizedVolumeOffset_${variableName}`;\n const stepSize = `model_quantizedVolumeStepSize_${variableName}`;\n const glslType = attributeInfo.glslType;\n shaderBuilder.addUniform(glslType, offset, ShaderDestination.VERTEX);\n shaderBuilder.addUniform(glslType, stepSize, ShaderDestination.VERTEX);\n\n let quantizedVolumeOffset = quantization.quantizedVolumeOffset;\n let quantizedVolumeStepSize = quantization.quantizedVolumeStepSize;\n\n // COLOR_n is promoted to a vec4 in the shader, so the alpha value\n // defaults to 1. For correctness, the quantization uniforms must be\n // promoted to vec4s. The alpha values are chosen so the alpha\n // dequantization is the identity, i.e. 0.0 + 1.0 * color.a\n if (/^color_\\d+$/.test(variableName)) {\n quantizedVolumeOffset = promoteToVec4(quantizedVolumeOffset, 0);\n quantizedVolumeStepSize = promoteToVec4(quantizedVolumeStepSize, 1);\n }\n\n uniformMap[offset] = function () {\n return quantizedVolumeOffset;\n };\n\n uniformMap[stepSize] = function () {\n return quantizedVolumeStepSize;\n };\n }\n}\n\nfunction promoteToVec4(value, defaultAlpha) {\n if (value instanceof Cartesian4) {\n return value;\n }\n\n return new Cartesian4(value.x, value.y, value.z, defaultAlpha);\n}\n\nfunction updateDequantizationFunction(shaderBuilder, attributeInfo) {\n const variableName = attributeInfo.variableName;\n const quantization = attributeInfo.attribute.quantization;\n\n let line;\n if (quantization.octEncoded) {\n line = generateOctDecodeLine(variableName, quantization);\n } else {\n line = generateDequantizeLine(variableName);\n }\n\n shaderBuilder.addFunctionLines(\n DequantizationPipelineStage.FUNCTION_ID_DEQUANTIZATION_STAGE_VS,\n [line]\n );\n}\n\nfunction generateOctDecodeLine(variableName, quantization) {\n const structField = `attributes.${variableName}`;\n\n const quantizedAttribute = `a_quantized_${variableName}`;\n const normalizationRange = `model_normalizationRange_${variableName}`;\n\n // Draco stores things as .zxy instead of xyz, so be explicit about the\n // swizzle to avoid confusion\n const swizzle = quantization.octEncodedZXY ? \".zxy\" : \".xyz\";\n\n // This generates lines such as:\n // attributes.normal = czm_octDecode(a_quantized_normal, model_normalizationRange_normal).zxy;\n return `${structField} = czm_octDecode(${quantizedAttribute}, ${normalizationRange})${swizzle};`;\n}\n\nfunction generateDequantizeLine(variableName) {\n const structField = `attributes.${variableName}`;\n const quantizedAttribute = `a_quantized_${variableName}`;\n const offset = `model_quantizedVolumeOffset_${variableName}`;\n const stepSize = `model_quantizedVolumeStepSize_${variableName}`;\n\n // This generates lines such as:\n // attributes.texCoord_0 = model_quantizedVolumeOffset_texCoord_0 + a_quantized_texCoord_0 * model_quantizedVolumeStepSize;\n return `${structField} = ${offset} + ${quantizedAttribute} * ${stepSize};`;\n}\n\nexport default DequantizationPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void geometryStage(out ProcessedAttributes attributes)\\n\\\n{\\n\\\n attributes.positionMC = v_positionMC;\\n\\\n attributes.positionEC = v_positionEC;\\n\\\n\\n\\\n #ifdef COMPUTE_POSITION_WC_CUSTOM_SHADER\\n\\\n attributes.positionWC = v_positionWC;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_NORMALS\\n\\\n // renormalize after interpolation\\n\\\n attributes.normalEC = normalize(v_normalEC);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_TANGENTS\\n\\\n attributes.tangentEC = normalize(v_tangentEC);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_BITANGENTS\\n\\\n attributes.bitangentEC = normalize(v_bitangentEC);\\n\\\n #endif\\n\\\n\\n\\\n // Everything else is dynamically generated in GeometryPipelineStage\\n\\\n setDynamicVaryings(attributes);\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"vec4 geometryStage(inout ProcessedAttributes attributes, mat4 modelView, mat3 normal) \\n\\\n{\\n\\\n vec4 computedPosition;\\n\\\n\\n\\\n // Compute positions in different coordinate systems\\n\\\n vec3 positionMC = attributes.positionMC;\\n\\\n v_positionMC = positionMC;\\n\\\n v_positionEC = (modelView * vec4(positionMC, 1.0)).xyz;\\n\\\n\\n\\\n #if defined(USE_2D_POSITIONS) || defined(USE_2D_INSTANCING)\\n\\\n vec3 position2D = attributes.position2D;\\n\\\n vec3 positionEC = (u_modelView2D * vec4(position2D, 1.0)).xyz;\\n\\\n computedPosition = czm_projection * vec4(positionEC, 1.0);\\n\\\n #else\\n\\\n computedPosition = czm_projection * vec4(v_positionEC, 1.0);\\n\\\n #endif\\n\\\n\\n\\\n // Sometimes the custom shader and/or style needs this\\n\\\n #if defined(COMPUTE_POSITION_WC_CUSTOM_SHADER) || defined(COMPUTE_POSITION_WC_STYLE)\\n\\\n // Note that this is a 32-bit position which may result in jitter on small\\n\\\n // scales.\\n\\\n v_positionWC = (czm_model * vec4(positionMC, 1.0)).xyz;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_NORMALS\\n\\\n v_normalEC = normalize(normal * attributes.normalMC);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_TANGENTS\\n\\\n v_tangentEC = normalize(normal * attributes.tangentMC); \\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_BITANGENTS\\n\\\n v_bitangentEC = normalize(normal * attributes.bitangentMC);\\n\\\n #endif\\n\\\n\\n\\\n // All other varyings need to be dynamically generated in\\n\\\n // GeometryPipelineStage\\n\\\n setDynamicVaryings(attributes);\\n\\\n \\n\\\n return computedPosition;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"vec2 computeSt(float featureId)\\n\\\n{\\n\\\n float stepX = model_textureStep.x;\\n\\\n float centerX = model_textureStep.y;\\n\\\n\\n\\\n #ifdef MULTILINE_BATCH_TEXTURE\\n\\\n float stepY = model_textureStep.z;\\n\\\n float centerY = model_textureStep.w;\\n\\\n\\n\\\n float xId = mod(featureId, model_textureDimensions.x); \\n\\\n float yId = floor(featureId / model_textureDimensions.x);\\n\\\n \\n\\\n return vec2(centerX + (xId * stepX), centerY + (yId * stepY));\\n\\\n #else\\n\\\n return vec2(centerX + (featureId * stepX), 0.5);\\n\\\n #endif\\n\\\n}\\n\\\n\\n\\\nvoid selectedFeatureIdStage(out SelectedFeature feature, FeatureIds featureIds)\\n\\\n{ \\n\\\n int featureId = featureIds.SELECTED_FEATURE_ID;\\n\\\n\\n\\\n\\n\\\n if (featureId < model_featuresLength)\\n\\\n {\\n\\\n vec2 featureSt = computeSt(float(featureId));\\n\\\n\\n\\\n feature.id = featureId;\\n\\\n feature.st = featureSt;\\n\\\n feature.color = texture(model_batchTexture, featureSt);\\n\\\n }\\n\\\n // Floating point comparisons can be unreliable in GLSL, so we\\n\\\n // increment the feature ID to make sure it's always greater\\n\\\n // then the model_featuresLength - a condition we check for in the\\n\\\n // pick ID, to avoid sampling the pick texture if the feature ID is\\n\\\n // greater than the number of features.\\n\\\n else\\n\\\n {\\n\\\n feature.id = model_featuresLength + 1;\\n\\\n feature.st = vec2(0.0);\\n\\\n feature.color = vec4(1.0);\\n\\\n }\\n\\\n\\n\\\n #ifdef HAS_NULL_FEATURE_ID\\n\\\n if (featureId == model_nullFeatureId) {\\n\\\n feature.id = featureId;\\n\\\n feature.st = vec2(0.0);\\n\\\n feature.color = vec4(1.0);\\n\\\n }\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "import defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport SelectedFeatureIdStageCommon from \"../../Shaders/Model/SelectedFeatureIdStageCommon.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The selected feature ID pipeline stage is responsible for handling the\n * set of feature IDs selected for styling/picking.\n *\n * @namespace SelectedFeatureIdPipelineStage\n * @private\n */\nconst SelectedFeatureIdPipelineStage = {\n name: \"SelectedFeatureIdPipelineStage\", // Helps with debugging\n\n STRUCT_ID_SELECTED_FEATURE: \"SelectedFeature\",\n STRUCT_NAME_SELECTED_FEATURE: \"SelectedFeature\",\n FUNCTION_ID_FEATURE_VARYINGS_VS: \"updateFeatureStructVS\",\n FUNCTION_ID_FEATURE_VARYINGS_FS: \"updateFeatureStructFS\",\n FUNCTION_SIGNATURE_UPDATE_FEATURE:\n \"void updateFeatureStruct(inout SelectedFeature feature)\",\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render resources:\n *
    \n *
  • sets the defines for the feature ID attribute to use for styling/picking
  • \n *
  • adds fields to the SelectedFeature struct in the shader
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n */\nSelectedFeatureIdPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n renderResources.hasPropertyTable = true;\n\n const model = renderResources.model;\n const node = renderResources.runtimeNode.node;\n const selectedFeatureIds = getSelectedFeatureIds(model, node, primitive);\n const shaderDestination = selectedFeatureIds.shaderDestination;\n\n shaderBuilder.addDefine(\n \"HAS_SELECTED_FEATURE_ID\",\n undefined,\n shaderDestination\n );\n\n // Add a define to insert the variable to use.\n // Example: #define SELECTED_FEATURE_ID featureId_1\n // This corresponds to featureIds.featureId_1\n shaderBuilder.addDefine(\n \"SELECTED_FEATURE_ID\",\n selectedFeatureIds.variableName,\n shaderDestination\n );\n\n // Add a define to the shader to distinguish feature ID attributes from\n // textures. This is needed for determining where to filter features\n // by pass type.\n shaderBuilder.addDefine(\n selectedFeatureIds.featureIdDefine,\n undefined,\n shaderDestination\n );\n\n updateFeatureStruct(shaderBuilder);\n\n const nullFeatureId = selectedFeatureIds.featureIds.nullFeatureId;\n const uniformMap = renderResources.uniformMap;\n if (defined(nullFeatureId)) {\n shaderBuilder.addDefine(\n \"HAS_NULL_FEATURE_ID\",\n undefined,\n shaderDestination\n );\n shaderBuilder.addUniform(\"int\", \"model_nullFeatureId\", shaderDestination);\n uniformMap.model_nullFeatureId = function () {\n return nullFeatureId;\n };\n }\n\n if (selectedFeatureIds.shaderDestination === ShaderDestination.BOTH) {\n shaderBuilder.addVertexLines(SelectedFeatureIdStageCommon);\n }\n shaderBuilder.addFragmentLines(SelectedFeatureIdStageCommon);\n};\n\nfunction getFeatureIdDefine(featureIds) {\n if (featureIds instanceof ModelComponents.FeatureIdTexture) {\n return \"HAS_SELECTED_FEATURE_ID_TEXTURE\";\n }\n\n return \"HAS_SELECTED_FEATURE_ID_ATTRIBUTE\";\n}\n\nfunction getShaderDestination(featureIds) {\n // Feature ID textures are only supported in the fragment shader.\n if (featureIds instanceof ModelComponents.FeatureIdTexture) {\n return ShaderDestination.FRAGMENT;\n }\n\n return ShaderDestination.BOTH;\n}\n\nfunction getSelectedFeatureIds(model, node, primitive) {\n let variableName;\n let featureIds;\n // Check instances first, as this is the most specific type of\n // feature ID\n if (defined(node.instances)) {\n featureIds = ModelUtility.getFeatureIdsByLabel(\n node.instances.featureIds,\n model.instanceFeatureIdLabel\n );\n\n if (defined(featureIds)) {\n // Either label could be used here, but prefer label as it may be more\n // meaningful when debugging\n variableName = defaultValue(featureIds.label, featureIds.positionalLabel);\n return {\n featureIds: featureIds,\n variableName: variableName,\n shaderDestination: getShaderDestination(featureIds),\n featureIdDefine: getFeatureIdDefine(featureIds),\n };\n }\n }\n\n featureIds = ModelUtility.getFeatureIdsByLabel(\n primitive.featureIds,\n model.featureIdLabel\n );\n // again, prefer label for being more descriptive\n variableName = defaultValue(featureIds.label, featureIds.positionalLabel);\n return {\n featureIds: featureIds,\n variableName: variableName,\n shaderDestination: getShaderDestination(featureIds),\n featureIdDefine: getFeatureIdDefine(featureIds),\n };\n}\n\n/**\n * Populate the \"SelectedFeature\" struct in the shaders that holds information about the \"active\" (used for picking/styling) feature.\n * The struct is always added to the shader by the GeometryPipelineStage (required for compilation). The SelectedFeature struct looks\n * as follows:\n *\n * struct SelectedFeature {\n * int id;\n * vec2 st;\n * vec4 color;\n * }\n *\n * @private\n */\nfunction updateFeatureStruct(shaderBuilder) {\n shaderBuilder.addStructField(\n SelectedFeatureIdPipelineStage.STRUCT_ID_SELECTED_FEATURE,\n \"int\",\n \"id\"\n );\n\n shaderBuilder.addStructField(\n SelectedFeatureIdPipelineStage.STRUCT_ID_SELECTED_FEATURE,\n \"vec2\",\n \"st\"\n );\n\n shaderBuilder.addStructField(\n SelectedFeatureIdPipelineStage.STRUCT_ID_SELECTED_FEATURE,\n \"vec4\",\n \"color\"\n );\n}\n\nexport default SelectedFeatureIdPipelineStage;\n", "import ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defined from \"../../Core/defined.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport GeometryStageFS from \"../../Shaders/Model/GeometryStageFS.js\";\nimport GeometryStageVS from \"../../Shaders/Model/GeometryStageVS.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport ModelType from \"./ModelType.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport SelectedFeatureIdPipelineStage from \"./SelectedFeatureIdPipelineStage.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\n/**\n * The geometry pipeline stage processes the vertex attributes of a primitive.\n *\n * @namespace GeometryPipelineStage\n *\n * @private\n */\nconst GeometryPipelineStage = {\n name: \"GeometryPipelineStage\", // Helps with debugging\n\n STRUCT_ID_PROCESSED_ATTRIBUTES_VS: \"ProcessedAttributesVS\",\n STRUCT_ID_PROCESSED_ATTRIBUTES_FS: \"ProcessedAttributesFS\",\n STRUCT_NAME_PROCESSED_ATTRIBUTES: \"ProcessedAttributes\",\n FUNCTION_ID_INITIALIZE_ATTRIBUTES: \"initializeAttributes\",\n FUNCTION_SIGNATURE_INITIALIZE_ATTRIBUTES:\n \"void initializeAttributes(out ProcessedAttributes attributes)\",\n FUNCTION_ID_SET_DYNAMIC_VARYINGS_VS: \"setDynamicVaryingsVS\",\n FUNCTION_ID_SET_DYNAMIC_VARYINGS_FS: \"setDynamicVaryingsFS\",\n FUNCTION_SIGNATURE_SET_DYNAMIC_VARYINGS:\n \"void setDynamicVaryings(inout ProcessedAttributes attributes)\",\n};\n\n/**\n * This pipeline stage processes the vertex attributes of a primitive,\n * adding attribute declarations to the shaders, adding attribute objects to the\n * render resources, and setting define flags as needed.\n *\n * Processes a primitive. This stage modifies the following parts of the render resources:\n *
    \n *
  • adds attribute and varying declarations for the vertex attributes in the vertex and fragment shaders\n *
  • creates the objects required to create VertexArrays\n *
  • sets the flag for point primitive types\n *
\n *\n * If the scene is in either 2D or CV mode, this stage also:\n *
    \n *
  • adds a struct field for the 2D positions\n *
  • adds an additional attribute object and declaration if the node containing this primitive is not instanced\n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nGeometryPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const model = renderResources.model;\n\n // These structs are similar, though the fragment shader version has a couple\n // additional fields.\n shaderBuilder.addStruct(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_VS,\n \"ProcessedAttributes\",\n ShaderDestination.VERTEX\n );\n shaderBuilder.addStruct(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_FS,\n \"ProcessedAttributes\",\n ShaderDestination.FRAGMENT\n );\n\n // The Feature struct is always added since it's required for compilation.\n // It may be unused if features are not present.\n shaderBuilder.addStruct(\n SelectedFeatureIdPipelineStage.STRUCT_ID_SELECTED_FEATURE,\n SelectedFeatureIdPipelineStage.STRUCT_NAME_SELECTED_FEATURE,\n ShaderDestination.BOTH\n );\n\n // This initialization function is only needed in the vertex shader,\n // it assigns the non-quantized attribute struct fields from the\n // physical attributes\n shaderBuilder.addFunction(\n GeometryPipelineStage.FUNCTION_ID_INITIALIZE_ATTRIBUTES,\n GeometryPipelineStage.FUNCTION_SIGNATURE_INITIALIZE_ATTRIBUTES,\n ShaderDestination.VERTEX\n );\n\n // Positions in other coordinate systems need more variables\n shaderBuilder.addVarying(\"vec3\", \"v_positionWC\");\n shaderBuilder.addVarying(\"vec3\", \"v_positionEC\");\n shaderBuilder.addStructField(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_FS,\n \"vec3\",\n \"positionWC\"\n );\n shaderBuilder.addStructField(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_FS,\n \"vec3\",\n \"positionEC\"\n );\n\n // Though they have identical signatures, the implementation is different\n // between vertex and fragment shaders. The VS stores attributes in\n // varyings, while the FS unpacks the varyings for use by other stages.\n shaderBuilder.addFunction(\n GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_VS,\n GeometryPipelineStage.FUNCTION_SIGNATURE_SET_DYNAMIC_VARYINGS,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addFunction(\n GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_FS,\n GeometryPipelineStage.FUNCTION_SIGNATURE_SET_DYNAMIC_VARYINGS,\n ShaderDestination.FRAGMENT\n );\n\n // .pnts point clouds store sRGB color rather than linear color\n const modelType = model.type;\n if (modelType === ModelType.TILE_PNTS) {\n shaderBuilder.addDefine(\n \"HAS_SRGB_COLOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n // Attributes, structs, and functions will need to be modified for 2D / CV.\n const use2D =\n frameState.mode !== SceneMode.SCENE3D &&\n !frameState.scene3DOnly &&\n model._projectTo2D;\n\n // If the model is instanced, the work for 2D projection will have been done\n // in InstancingPipelineStage. The attribute struct will be updated with\n // position2D, but nothing else should be modified.\n const instanced = defined(renderResources.runtimeNode.node.instances);\n\n // If the scene is in 3D or the model is instanced, the 2D position attribute\n // is not needed, so don't increment attributeIndex.\n const incrementIndexFor2D = use2D && !instanced;\n const length = primitive.attributes.length;\n for (let i = 0; i < length; i++) {\n const attribute = primitive.attributes[i];\n const attributeLocationCount = AttributeType.getAttributeLocationCount(\n attribute.type\n );\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(attribute.buffer) && !defined(attribute.constant)) {\n throw new DeveloperError(\n \"Attributes must be provided as a Buffer or constant value\"\n );\n }\n //>>includeEnd('debug');\n\n const isPositionAttribute =\n attribute.semantic === VertexAttributeSemantic.POSITION;\n\n let index;\n if (attributeLocationCount > 1) {\n index = renderResources.attributeIndex;\n renderResources.attributeIndex += attributeLocationCount;\n } else if (isPositionAttribute && !incrementIndexFor2D) {\n index = 0;\n } else {\n index = renderResources.attributeIndex++;\n }\n\n processAttribute(\n renderResources,\n attribute,\n index,\n attributeLocationCount,\n use2D,\n instanced\n );\n }\n\n handleBitangents(shaderBuilder, primitive.attributes);\n\n if (primitive.primitiveType === PrimitiveType.POINTS) {\n shaderBuilder.addDefine(\"PRIMITIVE_TYPE_POINTS\");\n }\n\n shaderBuilder.addVertexLines(GeometryStageVS);\n shaderBuilder.addFragmentLines(GeometryStageFS);\n};\n\nfunction processAttribute(\n renderResources,\n attribute,\n attributeIndex,\n attributeLocationCount,\n use2D,\n instanced\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const attributeInfo = ModelUtility.getAttributeInfo(attribute);\n\n // This indicates to only modify the resources for 2D if the model is\n // not instanced.\n const modifyFor2D = use2D && !instanced;\n\n if (attributeLocationCount > 1) {\n // Matrices are stored as multiple attributes, one per column vector.\n addMatrixAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex,\n attributeLocationCount\n );\n } else {\n addAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex,\n modifyFor2D\n );\n }\n\n addAttributeDeclaration(shaderBuilder, attributeInfo, modifyFor2D);\n addVaryingDeclaration(shaderBuilder, attributeInfo);\n\n // For common attributes like normals and tangents, the code is\n // already in GeometryStageVS, we just need to enable it.\n if (defined(attribute.semantic)) {\n addSemanticDefine(shaderBuilder, attribute);\n }\n\n // Dynamically generate GLSL code for the current attribute.\n // For 2D projection, the position2D field will always be added\n // to the attributes struct, even if the model is instanced.\n updateAttributesStruct(shaderBuilder, attributeInfo, use2D);\n updateInitializeAttributesFunction(shaderBuilder, attributeInfo, modifyFor2D);\n updateSetDynamicVaryingsFunction(shaderBuilder, attributeInfo);\n}\n\nfunction addSemanticDefine(shaderBuilder, attribute) {\n const semantic = attribute.semantic;\n const setIndex = attribute.setIndex;\n switch (semantic) {\n case VertexAttributeSemantic.NORMAL:\n shaderBuilder.addDefine(\"HAS_NORMALS\");\n break;\n case VertexAttributeSemantic.TANGENT:\n shaderBuilder.addDefine(\"HAS_TANGENTS\");\n break;\n case VertexAttributeSemantic.FEATURE_ID:\n // `_FEATURE_ID starts with an underscore so no need to double the\n // underscore.\n shaderBuilder.addDefine(`HAS${semantic}_${setIndex}`);\n break;\n case VertexAttributeSemantic.TEXCOORD:\n case VertexAttributeSemantic.COLOR:\n shaderBuilder.addDefine(`HAS_${semantic}_${setIndex}`);\n }\n}\n\nfunction addAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex,\n modifyFor2D\n) {\n const quantization = attribute.quantization;\n let type;\n let componentDatatype;\n if (defined(quantization)) {\n type = quantization.type;\n componentDatatype = quantization.componentDatatype;\n } else {\n type = attribute.type;\n componentDatatype = attribute.componentDatatype;\n }\n\n const semantic = attribute.semantic;\n const setIndex = attribute.setIndex;\n if (\n semantic === VertexAttributeSemantic.FEATURE_ID &&\n setIndex >= renderResources.featureIdVertexAttributeSetIndex\n ) {\n renderResources.featureIdVertexAttributeSetIndex = setIndex + 1;\n }\n\n // The position attribute should always be in the first index.\n const isPositionAttribute = semantic === VertexAttributeSemantic.POSITION;\n const index = isPositionAttribute ? 0 : attributeIndex;\n const componentsPerAttribute = AttributeType.getNumberOfComponents(type);\n\n const vertexAttribute = {\n index: index,\n value: defined(attribute.buffer) ? undefined : attribute.constant,\n vertexBuffer: attribute.buffer,\n count: attribute.count,\n componentsPerAttribute: componentsPerAttribute,\n componentDatatype: componentDatatype,\n offsetInBytes: attribute.byteOffset,\n strideInBytes: attribute.byteStride,\n normalize: attribute.normalized,\n };\n\n renderResources.attributes.push(vertexAttribute);\n\n if (!isPositionAttribute || !modifyFor2D) {\n return;\n }\n\n // Add an additional attribute for the projected positions in 2D / CV.\n const buffer2D = renderResources.runtimePrimitive.positionBuffer2D;\n const positionAttribute2D = {\n index: attributeIndex,\n vertexBuffer: buffer2D,\n count: attribute.count,\n componentsPerAttribute: componentsPerAttribute,\n componentDatatype: ComponentDatatype.FLOAT, // Projected positions will always be floats.\n offsetInBytes: 0,\n strideInBytes: undefined,\n normalize: attribute.normalized,\n };\n\n renderResources.attributes.push(positionAttribute2D);\n}\n\nfunction addMatrixAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex,\n columnCount\n) {\n const quantization = attribute.quantization;\n let type;\n let componentDatatype;\n if (defined(quantization)) {\n type = quantization.type;\n componentDatatype = quantization.componentDatatype;\n } else {\n type = attribute.type;\n componentDatatype = attribute.componentDatatype;\n }\n\n const normalized = attribute.normalized;\n\n // componentCount is either 4, 9 or 16\n const componentCount = AttributeType.getNumberOfComponents(type);\n // componentsPerColumn is either 2, 3, or 4\n const componentsPerColumn = componentCount / columnCount;\n\n const componentSizeInBytes = ComponentDatatype.getSizeInBytes(\n componentDatatype\n );\n\n const columnLengthInBytes = componentsPerColumn * componentSizeInBytes;\n\n // The stride between corresponding columns of two matrices is constant\n // regardless of where you start\n const strideInBytes = attribute.byteStride;\n\n for (let i = 0; i < columnCount; i++) {\n const offsetInBytes = attribute.byteOffset + i * columnLengthInBytes;\n\n // upload a single column vector.\n const columnAttribute = {\n index: attributeIndex + i,\n vertexBuffer: attribute.buffer,\n componentsPerAttribute: componentsPerColumn,\n componentDatatype: componentDatatype,\n offsetInBytes: offsetInBytes,\n strideInBytes: strideInBytes,\n normalize: normalized,\n };\n\n renderResources.attributes.push(columnAttribute);\n }\n}\n\nfunction addVaryingDeclaration(shaderBuilder, attributeInfo) {\n const variableName = attributeInfo.variableName;\n let varyingName = `v_${variableName}`;\n\n let glslType;\n if (variableName === \"normalMC\") {\n // though the attribute is in model coordinates, the varying is\n // in eye coordinates.\n varyingName = \"v_normalEC\";\n glslType = attributeInfo.glslType;\n } else if (variableName === \"tangentMC\") {\n // Tangent's glslType is vec4, but in the shader it is split into\n // vec3 tangent and vec3 bitangent\n glslType = \"vec3\";\n // like normalMC, the varying is converted to eye coordinates\n varyingName = \"v_tangentEC\";\n } else {\n glslType = attributeInfo.glslType;\n }\n\n shaderBuilder.addVarying(glslType, varyingName);\n}\n\nfunction addAttributeDeclaration(shaderBuilder, attributeInfo, modifyFor2D) {\n const semantic = attributeInfo.attribute.semantic;\n const variableName = attributeInfo.variableName;\n\n let attributeName;\n let glslType;\n if (attributeInfo.isQuantized) {\n attributeName = `a_quantized_${variableName}`;\n glslType = attributeInfo.quantizedGlslType;\n } else {\n attributeName = `a_${variableName}`;\n glslType = attributeInfo.glslType;\n }\n\n const isPosition = semantic === VertexAttributeSemantic.POSITION;\n if (isPosition) {\n shaderBuilder.setPositionAttribute(glslType, attributeName);\n } else {\n shaderBuilder.addAttribute(glslType, attributeName);\n }\n\n if (isPosition && modifyFor2D) {\n shaderBuilder.addAttribute(\"vec3\", \"a_position2D\");\n }\n}\n\nfunction updateAttributesStruct(shaderBuilder, attributeInfo, use2D) {\n const vsStructId = GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_VS;\n const fsStructId = GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_FS;\n const variableName = attributeInfo.variableName;\n\n if (variableName === \"tangentMC\") {\n // The w component of the tangent is only used for computing the bitangent,\n // so it can be separated from the other tangent components.\n shaderBuilder.addStructField(vsStructId, \"vec3\", \"tangentMC\");\n shaderBuilder.addStructField(vsStructId, \"float\", \"tangentSignMC\");\n // The tangent is in model coordinates in the vertex shader\n // but in eye space in the fragment coordinates\n shaderBuilder.addStructField(fsStructId, \"vec3\", \"tangentEC\");\n } else if (variableName === \"normalMC\") {\n // Normals are in model coordinates in the vertex shader but in eye\n // coordinates in the fragment shader\n shaderBuilder.addStructField(vsStructId, \"vec3\", \"normalMC\");\n shaderBuilder.addStructField(fsStructId, \"vec3\", \"normalEC\");\n } else {\n shaderBuilder.addStructField(\n vsStructId,\n attributeInfo.glslType,\n variableName\n );\n shaderBuilder.addStructField(\n fsStructId,\n attributeInfo.glslType,\n variableName\n );\n }\n\n if (variableName === \"positionMC\" && use2D) {\n shaderBuilder.addStructField(vsStructId, \"vec3\", \"position2D\");\n }\n}\n\nfunction updateInitializeAttributesFunction(\n shaderBuilder,\n attributeInfo,\n use2D\n) {\n const functionId = GeometryPipelineStage.FUNCTION_ID_INITIALIZE_ATTRIBUTES;\n const variableName = attributeInfo.variableName;\n\n // If the scene is in 2D / CV mode, this line should always be added\n // regardless of whether the data is quantized.\n const use2DPosition = variableName === \"positionMC\" && use2D;\n if (use2DPosition) {\n const line = \"attributes.position2D = a_position2D;\";\n shaderBuilder.addFunctionLines(functionId, [line]);\n }\n\n if (attributeInfo.isQuantized) {\n // Skip initialization, it will be handled in the dequantization stage.\n return;\n }\n\n const lines = [];\n if (variableName === \"tangentMC\") {\n lines.push(\"attributes.tangentMC = a_tangentMC.xyz;\");\n lines.push(\"attributes.tangentSignMC = a_tangentMC.w;\");\n } else {\n lines.push(`attributes.${variableName} = a_${variableName};`);\n }\n\n shaderBuilder.addFunctionLines(functionId, lines);\n}\n\nfunction updateSetDynamicVaryingsFunction(shaderBuilder, attributeInfo) {\n const semantic = attributeInfo.attribute.semantic;\n const setIndex = attributeInfo.attribute.setIndex;\n if (defined(semantic) && !defined(setIndex)) {\n // positions, normals, and tangents are handled statically in\n // GeometryStageVS\n return;\n }\n\n // In the vertex shader, we want things like\n // v_texCoord_1 = attributes.texCoord_1;\n let functionId = GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_VS;\n const variableName = attributeInfo.variableName;\n let line = `v_${variableName} = attributes.${variableName};`;\n shaderBuilder.addFunctionLines(functionId, [line]);\n\n // In the fragment shader, we do the opposite:\n // attributes.texCoord_1 = v_texCoord_1;\n functionId = GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_FS;\n line = `attributes.${variableName} = v_${variableName};`;\n shaderBuilder.addFunctionLines(functionId, [line]);\n}\n\nfunction handleBitangents(shaderBuilder, attributes) {\n let hasNormals = false;\n let hasTangents = false;\n for (let i = 0; i < attributes.length; i++) {\n const attribute = attributes[i];\n if (attribute.semantic === VertexAttributeSemantic.NORMAL) {\n hasNormals = true;\n } else if (attribute.semantic === VertexAttributeSemantic.TANGENT) {\n hasTangents = true;\n }\n }\n\n // Bitangents are only defined if we have normals and tangents\n if (!hasNormals || !hasTangents) {\n return;\n }\n\n shaderBuilder.addDefine(\"HAS_BITANGENTS\");\n\n shaderBuilder.addVarying(\"vec3\", \"v_bitangentEC\");\n shaderBuilder.addStructField(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_VS,\n \"vec3\",\n \"bitangentMC\"\n );\n shaderBuilder.addStructField(\n GeometryPipelineStage.STRUCT_ID_PROCESSED_ATTRIBUTES_FS,\n \"vec3\",\n \"bitangentEC\"\n );\n}\n\nexport default GeometryPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef LIGHTING_PBR\\n\\\nvec3 computePbrLighting(czm_modelMaterial inputMaterial, ProcessedAttributes attributes)\\n\\\n{\\n\\\n czm_pbrParameters pbrParameters;\\n\\\n pbrParameters.diffuseColor = inputMaterial.diffuse;\\n\\\n pbrParameters.f0 = inputMaterial.specular;\\n\\\n pbrParameters.roughness = inputMaterial.roughness;\\n\\\n \\n\\\n #ifdef USE_CUSTOM_LIGHT_COLOR\\n\\\n vec3 lightColorHdr = model_lightColorHdr;\\n\\\n #else\\n\\\n vec3 lightColorHdr = czm_lightColorHdr;\\n\\\n #endif\\n\\\n\\n\\\n vec3 color = inputMaterial.diffuse;\\n\\\n #ifdef HAS_NORMALS\\n\\\n color = czm_pbrLighting(\\n\\\n attributes.positionEC,\\n\\\n inputMaterial.normalEC,\\n\\\n czm_lightDirectionEC,\\n\\\n lightColorHdr,\\n\\\n pbrParameters\\n\\\n );\\n\\\n\\n\\\n #ifdef USE_IBL_LIGHTING\\n\\\n color += imageBasedLightingStage(\\n\\\n attributes.positionEC,\\n\\\n inputMaterial.normalEC,\\n\\\n czm_lightDirectionEC,\\n\\\n lightColorHdr,\\n\\\n pbrParameters\\n\\\n );\\n\\\n #endif\\n\\\n #endif\\n\\\n\\n\\\n color *= inputMaterial.occlusion;\\n\\\n color += inputMaterial.emissive;\\n\\\n\\n\\\n // In HDR mode, the frame buffer is in linear color space. The\\n\\\n // post-processing stages (see PostProcessStageCollection) will handle\\n\\\n // tonemapping. However, if HDR is not enabled, we must tonemap else large\\n\\\n // values may be clamped to 1.0\\n\\\n #ifndef HDR \\n\\\n color = czm_acesTonemapping(color);\\n\\\n #endif \\n\\\n\\n\\\n return color;\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\nvoid lightingStage(inout czm_modelMaterial material, ProcessedAttributes attributes)\\n\\\n{\\n\\\n // Even though the lighting will only set the diffuse color,\\n\\\n // pass all other properties so further stages have access to them.\\n\\\n vec3 color = vec3(0.0);\\n\\\n\\n\\\n #ifdef LIGHTING_PBR\\n\\\n color = computePbrLighting(material, attributes);\\n\\\n #else // unlit\\n\\\n color = material.diffuse;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_POINT_CLOUD_COLOR_STYLE\\n\\\n // The colors resulting from point cloud styles are adjusted differently.\\n\\\n color = czm_gammaCorrect(color);\\n\\\n #elif !defined(HDR)\\n\\\n // If HDR is not enabled, the frame buffer stores sRGB colors rather than\\n\\\n // linear colors so the linear value must be converted.\\n\\\n color = czm_linearToSrgb(color);\\n\\\n #endif\\n\\\n\\n\\\n material.diffuse = color;\\n\\\n}\\n\\\n\";\n", "/**\n * The lighting model to use for lighting a {@link Model}.\n *\n * @enum {number}\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nconst LightingModel = {\n /**\n * Use unlit shading, i.e. skip lighting calculations. The model's\n * diffuse color (assumed to be linear RGB, not sRGB) is used directly\n * when computing out_FragColor. The alpha mode is still\n * applied.\n *\n * @type {number}\n * @constant\n */\n UNLIT: 0,\n /**\n * Use physically-based rendering lighting calculations. This includes\n * both PBR metallic roughness and PBR specular glossiness. Image-based\n * lighting is also applied when possible.\n *\n * @type {number}\n * @constant\n */\n PBR: 1,\n};\n\nexport default Object.freeze(LightingModel);\n", "import defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport LightingStageFS from \"../../Shaders/Model/LightingStageFS.js\";\nimport LightingModel from \"./LightingModel.js\";\n\n/**\n * The lighting pipeline stage is responsible for taking a material and rendering\n * it with a lighting model such as physically based rendering (PBR) or unlit\n * shading\n *\n * @namespace LightingPipelineStage\n *\n * @private\n */\nconst LightingPipelineStage = {\n name: \"LightingPipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render\n * resources:\n *
    \n *
  • modifies the shader to include the lighting stage
  • \n *
\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n *\n * @private\n */\nLightingPipelineStage.process = function (renderResources, primitive) {\n const model = renderResources.model;\n const lightingOptions = renderResources.lightingOptions;\n const shaderBuilder = renderResources.shaderBuilder;\n\n if (defined(model.lightColor)) {\n shaderBuilder.addDefine(\n \"USE_CUSTOM_LIGHT_COLOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addUniform(\n \"vec3\",\n \"model_lightColorHdr\",\n ShaderDestination.FRAGMENT\n );\n\n const uniformMap = renderResources.uniformMap;\n uniformMap.model_lightColorHdr = function () {\n return model.lightColor;\n };\n }\n\n // The lighting model is always set by the material. However, custom shaders\n // can override this.\n const lightingModel = lightingOptions.lightingModel;\n\n if (lightingModel === LightingModel.PBR) {\n shaderBuilder.addDefine(\n \"LIGHTING_PBR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n } else {\n shaderBuilder.addDefine(\n \"LIGHTING_UNLIT\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n shaderBuilder.addFragmentLines(LightingStageFS);\n};\n\nexport default LightingPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"// If the style color is white, it implies the feature has not been styled.\\n\\\nbool isDefaultStyleColor(vec3 color)\\n\\\n{\\n\\\n return all(greaterThan(color, vec3(1.0 - czm_epsilon3)));\\n\\\n}\\n\\\n\\n\\\nvec3 blend(vec3 sourceColor, vec3 styleColor, float styleColorBlend)\\n\\\n{\\n\\\n vec3 blendColor = mix(sourceColor, styleColor, styleColorBlend);\\n\\\n vec3 color = isDefaultStyleColor(styleColor.rgb) ? sourceColor : blendColor;\\n\\\n return color;\\n\\\n}\\n\\\n\\n\\\nvec2 computeTextureTransform(vec2 texCoord, mat3 textureTransform)\\n\\\n{\\n\\\n return vec2(textureTransform * vec3(texCoord, 1.0));\\n\\\n}\\n\\\n\\n\\\n#ifdef HAS_NORMALS\\n\\\nvec3 computeNormal(ProcessedAttributes attributes)\\n\\\n{\\n\\\n // Geometry normal. This is already normalized \\n\\\n vec3 ng = attributes.normalEC;\\n\\\n\\n\\\n vec3 normal = ng;\\n\\\n #if defined(HAS_NORMAL_TEXTURE) && !defined(HAS_WIREFRAME)\\n\\\n vec2 normalTexCoords = TEXCOORD_NORMAL;\\n\\\n #ifdef HAS_NORMAL_TEXTURE_TRANSFORM\\n\\\n normalTexCoords = computeTextureTransform(normalTexCoords, u_normalTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n // If HAS_BITANGENTS is set, then HAS_TANGENTS is also set\\n\\\n #ifdef HAS_BITANGENTS\\n\\\n vec3 t = attributes.tangentEC;\\n\\\n vec3 b = attributes.bitangentEC;\\n\\\n mat3 tbn = mat3(t, b, ng);\\n\\\n vec3 n = texture(u_normalTexture, normalTexCoords).rgb;\\n\\\n normal = normalize(tbn * (2.0 * n - 1.0));\\n\\\n #elif (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n // If derivatives are available (not IE 10), compute tangents\\n\\\n vec3 positionEC = attributes.positionEC;\\n\\\n vec3 pos_dx = dFdx(positionEC);\\n\\\n vec3 pos_dy = dFdy(positionEC);\\n\\\n vec3 tex_dx = dFdx(vec3(normalTexCoords,0.0));\\n\\\n vec3 tex_dy = dFdy(vec3(normalTexCoords,0.0));\\n\\\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\\n\\\n t = normalize(t - ng * dot(ng, t));\\n\\\n vec3 b = normalize(cross(ng, t));\\n\\\n mat3 tbn = mat3(t, b, ng);\\n\\\n vec3 n = texture(u_normalTexture, normalTexCoords).rgb;\\n\\\n normal = normalize(tbn * (2.0 * n - 1.0));\\n\\\n #endif\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_DOUBLE_SIDED_MATERIAL\\n\\\n if (czm_backFacing()) {\\n\\\n normal = -normal;\\n\\\n }\\n\\\n #endif\\n\\\n\\n\\\n return normal;\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\nvoid materialStage(inout czm_modelMaterial material, ProcessedAttributes attributes, SelectedFeature feature)\\n\\\n{\\n\\\n #ifdef HAS_NORMALS\\n\\\n material.normalEC = computeNormal(attributes);\\n\\\n #endif\\n\\\n\\n\\\n vec4 baseColorWithAlpha = vec4(1.0);\\n\\\n // Regardless of whether we use PBR, set a base color\\n\\\n #ifdef HAS_BASE_COLOR_TEXTURE\\n\\\n vec2 baseColorTexCoords = TEXCOORD_BASE_COLOR;\\n\\\n\\n\\\n #ifdef HAS_BASE_COLOR_TEXTURE_TRANSFORM\\n\\\n baseColorTexCoords = computeTextureTransform(baseColorTexCoords, u_baseColorTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n baseColorWithAlpha = czm_srgbToLinear(texture(u_baseColorTexture, baseColorTexCoords));\\n\\\n\\n\\\n #ifdef HAS_BASE_COLOR_FACTOR\\n\\\n baseColorWithAlpha *= u_baseColorFactor;\\n\\\n #endif\\n\\\n #elif defined(HAS_BASE_COLOR_FACTOR)\\n\\\n baseColorWithAlpha = u_baseColorFactor;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_POINT_CLOUD_COLOR_STYLE\\n\\\n baseColorWithAlpha = v_pointCloudColor;\\n\\\n #elif defined(HAS_COLOR_0)\\n\\\n vec4 color = attributes.color_0;\\n\\\n // .pnts files store colors in the sRGB color space\\n\\\n #ifdef HAS_SRGB_COLOR\\n\\\n color = czm_srgbToLinear(color);\\n\\\n #endif\\n\\\n baseColorWithAlpha *= color;\\n\\\n #endif\\n\\\n\\n\\\n material.diffuse = baseColorWithAlpha.rgb;\\n\\\n material.alpha = baseColorWithAlpha.a;\\n\\\n\\n\\\n #ifdef USE_CPU_STYLING\\n\\\n material.diffuse = blend(material.diffuse, feature.color.rgb, model_colorBlend);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_OCCLUSION_TEXTURE\\n\\\n vec2 occlusionTexCoords = TEXCOORD_OCCLUSION;\\n\\\n #ifdef HAS_OCCLUSION_TEXTURE_TRANSFORM\\n\\\n occlusionTexCoords = computeTextureTransform(occlusionTexCoords, u_occlusionTextureTransform);\\n\\\n #endif\\n\\\n material.occlusion = texture(u_occlusionTexture, occlusionTexCoords).r;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_EMISSIVE_TEXTURE\\n\\\n vec2 emissiveTexCoords = TEXCOORD_EMISSIVE;\\n\\\n #ifdef HAS_EMISSIVE_TEXTURE_TRANSFORM\\n\\\n emissiveTexCoords = computeTextureTransform(emissiveTexCoords, u_emissiveTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n vec3 emissive = czm_srgbToLinear(texture(u_emissiveTexture, emissiveTexCoords).rgb);\\n\\\n #ifdef HAS_EMISSIVE_FACTOR\\n\\\n emissive *= u_emissiveFactor;\\n\\\n #endif\\n\\\n material.emissive = emissive;\\n\\\n #elif defined(HAS_EMISSIVE_FACTOR)\\n\\\n material.emissive = u_emissiveFactor;\\n\\\n #endif\\n\\\n\\n\\\n #if defined(LIGHTING_PBR) && defined(USE_SPECULAR_GLOSSINESS)\\n\\\n #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE\\n\\\n vec2 specularGlossinessTexCoords = TEXCOORD_SPECULAR_GLOSSINESS;\\n\\\n #ifdef HAS_SPECULAR_GLOSSINESS_TEXTURE_TRANSFORM\\n\\\n specularGlossinessTexCoords = computeTextureTransform(specularGlossinessTexCoords, u_specularGlossinessTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n vec4 specularGlossiness = czm_srgbToLinear(texture(u_specularGlossinessTexture, specularGlossinessTexCoords));\\n\\\n vec3 specular = specularGlossiness.rgb;\\n\\\n float glossiness = specularGlossiness.a;\\n\\\n #ifdef HAS_SPECULAR_FACTOR\\n\\\n specular *= u_specularFactor;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_GLOSSINESS_FACTOR\\n\\\n glossiness *= u_glossinessFactor;\\n\\\n #endif\\n\\\n #else\\n\\\n #ifdef HAS_SPECULAR_FACTOR\\n\\\n vec3 specular = clamp(u_specularFactor, vec3(0.0), vec3(1.0));\\n\\\n #else\\n\\\n vec3 specular = vec3(1.0);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_GLOSSINESS_FACTOR\\n\\\n float glossiness = clamp(u_glossinessFactor, 0.0, 1.0);\\n\\\n #else\\n\\\n float glossiness = 1.0;\\n\\\n #endif\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_DIFFUSE_TEXTURE\\n\\\n vec2 diffuseTexCoords = TEXCOORD_DIFFUSE;\\n\\\n #ifdef HAS_DIFFUSE_TEXTURE_TRANSFORM\\n\\\n diffuseTexCoords = computeTextureTransform(diffuseTexCoords, u_diffuseTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n vec4 diffuse = czm_srgbToLinear(texture(u_diffuseTexture, diffuseTexCoords));\\n\\\n #ifdef HAS_DIFFUSE_FACTOR\\n\\\n diffuse *= u_diffuseFactor;\\n\\\n #endif\\n\\\n #elif defined(HAS_DIFFUSE_FACTOR)\\n\\\n vec4 diffuse = clamp(u_diffuseFactor, vec4(0.0), vec4(1.0));\\n\\\n #else\\n\\\n vec4 diffuse = vec4(1.0);\\n\\\n #endif\\n\\\n czm_pbrParameters parameters = czm_pbrSpecularGlossinessMaterial(\\n\\\n diffuse.rgb,\\n\\\n specular,\\n\\\n glossiness\\n\\\n );\\n\\\n material.diffuse = parameters.diffuseColor;\\n\\\n // the specular glossiness extension's alpha overrides anything set\\n\\\n // by the base material.\\n\\\n material.alpha = diffuse.a;\\n\\\n material.specular = parameters.f0;\\n\\\n material.roughness = parameters.roughness;\\n\\\n #elif defined(LIGHTING_PBR)\\n\\\n #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE\\n\\\n vec2 metallicRoughnessTexCoords = TEXCOORD_METALLIC_ROUGHNESS;\\n\\\n #ifdef HAS_METALLIC_ROUGHNESS_TEXTURE_TRANSFORM\\n\\\n metallicRoughnessTexCoords = computeTextureTransform(metallicRoughnessTexCoords, u_metallicRoughnessTextureTransform);\\n\\\n #endif\\n\\\n\\n\\\n vec3 metallicRoughness = texture(u_metallicRoughnessTexture, metallicRoughnessTexCoords).rgb;\\n\\\n float metalness = clamp(metallicRoughness.b, 0.0, 1.0);\\n\\\n float roughness = clamp(metallicRoughness.g, 0.04, 1.0);\\n\\\n #ifdef HAS_METALLIC_FACTOR\\n\\\n metalness *= u_metallicFactor;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_ROUGHNESS_FACTOR\\n\\\n roughness *= u_roughnessFactor;\\n\\\n #endif\\n\\\n #else\\n\\\n #ifdef HAS_METALLIC_FACTOR\\n\\\n float metalness = clamp(u_metallicFactor, 0.0, 1.0);\\n\\\n #else\\n\\\n float metalness = 1.0;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_ROUGHNESS_FACTOR\\n\\\n float roughness = clamp(u_roughnessFactor, 0.04, 1.0);\\n\\\n #else\\n\\\n float roughness = 1.0;\\n\\\n #endif\\n\\\n #endif\\n\\\n czm_pbrParameters parameters = czm_pbrMetallicRoughnessMaterial(\\n\\\n material.diffuse,\\n\\\n metalness,\\n\\\n roughness\\n\\\n );\\n\\\n material.diffuse = parameters.diffuseColor;\\n\\\n material.specular = parameters.f0;\\n\\\n material.roughness = parameters.roughness;\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "import defined from \"../../Core/defined.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Cartesian4 from \"../../Core/Cartesian4.js\";\nimport Matrix3 from \"../../Core/Matrix3.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport MaterialStageFS from \"../../Shaders/Model/MaterialStageFS.js\";\nimport AlphaMode from \"../AlphaMode.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport LightingModel from \"./LightingModel.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\nconst Material = ModelComponents.Material;\nconst MetallicRoughness = ModelComponents.MetallicRoughness;\nconst SpecularGlossiness = ModelComponents.SpecularGlossiness;\n\n/**\n * The material pipeline stage processes textures and other uniforms needed\n * to render a primitive. This handles the following material types:\n *
    \n *
  • Basic glTF materials (PBR metallic roughness model)
  • \n *
  • The `KHR_materials_pbrSpecularGlossiness` glTF extension
  • \n *
  • The `KHR_materials_unlit` glTF extension
  • \n *
\n *\n * @namespace MaterialPipelineStage\n *\n * @private\n */\nconst MaterialPipelineStage = {\n name: \"MaterialPipelineStage\", // Helps with debugging\n\n // Expose some methods for testing\n _processTexture: processTexture,\n _processTextureTransform: processTextureTransform,\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render\n * resources:\n *
    \n *
  • Modifies the shader to include the material processing stage
  • \n *
  • Modifies the shader to include additional uniforms for textures and other rendering details
  • \n *
  • Modifies the lighting options to set either PBR or unlit lighting
  • \n *
  • Sets the render state for back-face culling
  • \n *
\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {FrameState} frameState The frame state.\n * @private\n */\nMaterialPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n // gltf-pipeline automatically creates a default material so this will always\n // be defined.\n const material = primitive.material;\n const model = renderResources.model;\n\n // Classification models only use position and feature ID attributes,\n // so textures should be disabled to avoid compile errors.\n const hasClassification = defined(model.classificationType);\n const disableTextures = hasClassification;\n\n const uniformMap = renderResources.uniformMap;\n const shaderBuilder = renderResources.shaderBuilder;\n\n // When textures are loaded incrementally, fall back to a default 1x1 texture\n const defaultTexture = frameState.context.defaultTexture;\n const defaultNormalTexture = frameState.context.defaultNormalTexture;\n const defaultEmissiveTexture = frameState.context.defaultEmissiveTexture;\n\n processMaterialUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n defaultNormalTexture,\n defaultEmissiveTexture,\n disableTextures\n );\n\n if (defined(material.specularGlossiness)) {\n processSpecularGlossinessUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n disableTextures\n );\n } else {\n processMetallicRoughnessUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n disableTextures\n );\n }\n\n // If the primitive does not have normals, fall back to unlit lighting.\n const hasNormals = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.NORMAL\n );\n\n // Classification models will be rendered as unlit.\n const lightingOptions = renderResources.lightingOptions;\n if (material.unlit || !hasNormals || hasClassification) {\n lightingOptions.lightingModel = LightingModel.UNLIT;\n } else {\n lightingOptions.lightingModel = LightingModel.PBR;\n }\n\n // Configure back-face culling\n const cull = model.backFaceCulling && !material.doubleSided;\n renderResources.renderStateOptions.cull.enabled = cull;\n\n const alphaOptions = renderResources.alphaOptions;\n if (material.alphaMode === AlphaMode.BLEND) {\n alphaOptions.pass = Pass.TRANSLUCENT;\n } else if (material.alphaMode === AlphaMode.MASK) {\n alphaOptions.alphaCutoff = material.alphaCutoff;\n }\n\n shaderBuilder.addFragmentLines(MaterialStageFS);\n\n if (material.doubleSided) {\n shaderBuilder.addDefine(\n \"HAS_DOUBLE_SIDED_MATERIAL\",\n undefined,\n ShaderDestination.BOTH\n );\n }\n};\n\n/**\n * Process a single texture transformation and add it to the shader and uniform map.\n *\n * @param {ShaderBuilder} shaderBuilder The shader builder to modify\n * @param {Object} uniformMap The uniform map to modify.\n * @param {ModelComponents.TextureReader} textureReader The texture to add to the shader\n * @param {string} uniformName The name of the sampler uniform such as u_baseColorTexture\n * @param {string} defineName The name of the texture for use in the defines, minus any prefix or suffix. For example, \"BASE_COLOR\" or \"EMISSIVE\"\n *\n * @private\n */\nfunction processTextureTransform(\n shaderBuilder,\n uniformMap,\n textureReader,\n uniformName,\n defineName\n) {\n // Add a define to enable the texture transformation code in the shader.\n const transformDefine = `HAS_${defineName}_TEXTURE_TRANSFORM`;\n shaderBuilder.addDefine(\n transformDefine,\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n // Add a uniform for the transformation matrix\n const transformUniformName = `${uniformName}Transform`;\n shaderBuilder.addUniform(\n \"mat3\",\n transformUniformName,\n ShaderDestination.FRAGMENT\n );\n uniformMap[transformUniformName] = function () {\n return textureReader.transform;\n };\n}\n\n/**\n * Process a single texture and add it to the shader and uniform map.\n *\n * @param {ShaderBuilder} shaderBuilder The shader builder to modify\n * @param {Object} uniformMap The uniform map to modify.\n * @param {ModelComponents.TextureReader} textureReader The texture to add to the shader\n * @param {string} uniformName The name of the sampler uniform such as u_baseColorTexture\n * @param {string} defineName The name of the texture for use in the defines, minus any prefix or suffix. For example, \"BASE_COLOR\" or \"EMISSIVE\"\n *\n * @private\n */\nfunction processTexture(\n shaderBuilder,\n uniformMap,\n textureReader,\n uniformName,\n defineName,\n defaultTexture\n) {\n // Add a uniform for the texture itself\n shaderBuilder.addUniform(\n \"sampler2D\",\n uniformName,\n ShaderDestination.FRAGMENT\n );\n uniformMap[uniformName] = function () {\n return defaultValue(textureReader.texture, defaultTexture);\n };\n\n // Add a #define directive to enable using the texture in the shader\n const textureDefine = `HAS_${defineName}_TEXTURE`;\n shaderBuilder.addDefine(textureDefine, undefined, ShaderDestination.FRAGMENT);\n\n // Add a #define to tell the shader which texture coordinates varying to use.\n const texCoordIndex = textureReader.texCoord;\n const texCoordVarying = `v_texCoord_${texCoordIndex}`;\n const texCoordDefine = `TEXCOORD_${defineName}`;\n shaderBuilder.addDefine(\n texCoordDefine,\n texCoordVarying,\n ShaderDestination.FRAGMENT\n );\n\n // Some textures have matrix transforms (e.g. for texture atlases). Add those\n // to the shader if present.\n const textureTransform = textureReader.transform;\n if (\n defined(textureTransform) &&\n !Matrix3.equals(textureTransform, Matrix3.IDENTITY)\n ) {\n processTextureTransform(\n shaderBuilder,\n uniformMap,\n textureReader,\n uniformName,\n defineName\n );\n }\n}\n\nfunction processMaterialUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n defaultNormalTexture,\n defaultEmissiveTexture,\n disableTextures\n) {\n const emissiveFactor = material.emissiveFactor;\n if (\n defined(emissiveFactor) &&\n !Cartesian3.equals(emissiveFactor, Material.DEFAULT_EMISSIVE_FACTOR)\n ) {\n shaderBuilder.addUniform(\n \"vec3\",\n \"u_emissiveFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_emissiveFactor = function () {\n return material.emissiveFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_EMISSIVE_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n const emissiveTexture = material.emissiveTexture;\n if (defined(emissiveTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n emissiveTexture,\n \"u_emissiveTexture\",\n \"EMISSIVE\",\n defaultEmissiveTexture\n );\n }\n }\n\n const normalTexture = material.normalTexture;\n if (defined(normalTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n normalTexture,\n \"u_normalTexture\",\n \"NORMAL\",\n defaultNormalTexture\n );\n }\n\n const occlusionTexture = material.occlusionTexture;\n if (defined(occlusionTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n occlusionTexture,\n \"u_occlusionTexture\",\n \"OCCLUSION\",\n defaultTexture\n );\n }\n}\n\nfunction processSpecularGlossinessUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n disableTextures\n) {\n const specularGlossiness = material.specularGlossiness;\n shaderBuilder.addDefine(\n \"USE_SPECULAR_GLOSSINESS\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n const diffuseTexture = specularGlossiness.diffuseTexture;\n if (defined(diffuseTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n diffuseTexture,\n \"u_diffuseTexture\",\n \"DIFFUSE\",\n defaultTexture\n );\n }\n\n const diffuseFactor = specularGlossiness.diffuseFactor;\n if (\n defined(diffuseFactor) &&\n !Cartesian4.equals(diffuseFactor, SpecularGlossiness.DEFAULT_DIFFUSE_FACTOR)\n ) {\n shaderBuilder.addUniform(\n \"vec4\",\n \"u_diffuseFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_diffuseFactor = function () {\n return specularGlossiness.diffuseFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_DIFFUSE_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const specularGlossinessTexture =\n specularGlossiness.specularGlossinessTexture;\n if (defined(specularGlossinessTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n specularGlossinessTexture,\n \"u_specularGlossinessTexture\",\n \"SPECULAR_GLOSSINESS\",\n defaultTexture\n );\n }\n\n const specularFactor = specularGlossiness.specularFactor;\n if (\n defined(specularFactor) &&\n !Cartesian3.equals(\n specularFactor,\n SpecularGlossiness.DEFAULT_SPECULAR_FACTOR\n )\n ) {\n shaderBuilder.addUniform(\n \"vec3\",\n \"u_specularFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_specularFactor = function () {\n return specularGlossiness.specularFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_SPECULAR_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const glossinessFactor = specularGlossiness.glossinessFactor;\n if (\n defined(glossinessFactor) &&\n glossinessFactor !== SpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR\n ) {\n shaderBuilder.addUniform(\n \"float\",\n \"u_glossinessFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_glossinessFactor = function () {\n return specularGlossiness.glossinessFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_GLOSSINESS_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n}\n\nfunction processMetallicRoughnessUniforms(\n material,\n uniformMap,\n shaderBuilder,\n defaultTexture,\n disableTextures\n) {\n const metallicRoughness = material.metallicRoughness;\n shaderBuilder.addDefine(\n \"USE_METALLIC_ROUGHNESS\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n const baseColorTexture = metallicRoughness.baseColorTexture;\n if (defined(baseColorTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n baseColorTexture,\n \"u_baseColorTexture\",\n \"BASE_COLOR\",\n defaultTexture\n );\n }\n\n const baseColorFactor = metallicRoughness.baseColorFactor;\n if (\n defined(baseColorFactor) &&\n !Cartesian4.equals(\n baseColorFactor,\n MetallicRoughness.DEFAULT_BASE_COLOR_FACTOR\n )\n ) {\n shaderBuilder.addUniform(\n \"vec4\",\n \"u_baseColorFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_baseColorFactor = function () {\n return metallicRoughness.baseColorFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_BASE_COLOR_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const metallicRoughnessTexture = metallicRoughness.metallicRoughnessTexture;\n if (defined(metallicRoughnessTexture) && !disableTextures) {\n processTexture(\n shaderBuilder,\n uniformMap,\n metallicRoughnessTexture,\n \"u_metallicRoughnessTexture\",\n \"METALLIC_ROUGHNESS\",\n defaultTexture\n );\n }\n\n const metallicFactor = metallicRoughness.metallicFactor;\n if (\n defined(metallicFactor) &&\n metallicFactor !== MetallicRoughness.DEFAULT_METALLIC_FACTOR\n ) {\n shaderBuilder.addUniform(\n \"float\",\n \"u_metallicFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_metallicFactor = function () {\n return metallicRoughness.metallicFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_METALLIC_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n\n const roughnessFactor = metallicRoughness.roughnessFactor;\n if (\n defined(roughnessFactor) &&\n roughnessFactor !== MetallicRoughness.DEFAULT_ROUGHNESS_FACTOR\n ) {\n shaderBuilder.addUniform(\n \"float\",\n \"u_roughnessFactor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.u_roughnessFactor = function () {\n return metallicRoughness.roughnessFactor;\n };\n shaderBuilder.addDefine(\n \"HAS_ROUGHNESS_FACTOR\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n }\n}\n\nexport default MaterialPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void morphTargetsStage(inout ProcessedAttributes attributes) \\n\\\n{\\n\\\n vec3 positionMC = attributes.positionMC;\\n\\\n attributes.positionMC = getMorphedPosition(positionMC);\\n\\\n\\n\\\n #ifdef HAS_NORMALS\\n\\\n vec3 normalMC = attributes.normalMC;\\n\\\n attributes.normalMC = getMorphedNormal(normalMC);\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_TANGENTS\\n\\\n vec3 tangentMC = attributes.tangentMC;\\n\\\n attributes.tangentMC = getMorphedTangent(tangentMC);\\n\\\n #endif\\n\\\n}\";\n", "import AttributeType from \"../AttributeType.js\";\nimport combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport MorphTargetsStageVS from \"../../Shaders/Model/MorphTargetsStageVS.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\n/**\n * The morph targets pipeline stage processes the morph targets and weights of a primitive.\n *\n * @namespace MorphTargetsPipelineStage\n *\n * @private\n */\nconst MorphTargetsPipelineStage = {\n name: \"MorphTargetsPipelineStage\", // Helps with debugging\n\n FUNCTION_ID_GET_MORPHED_POSITION: \"getMorphedPosition\",\n FUNCTION_SIGNATURE_GET_MORPHED_POSITION:\n \"vec3 getMorphedPosition(in vec3 position)\",\n FUNCTION_ID_GET_MORPHED_NORMAL: \"getMorphedNormal\",\n FUNCTION_SIGNATURE_GET_MORPHED_NORMAL:\n \"vec3 getMorphedNormal(in vec3 normal)\",\n FUNCTION_ID_GET_MORPHED_TANGENT: \"getMorphedTangent\",\n FUNCTION_SIGNATURE_GET_MORPHED_TANGENT:\n \"vec3 getMorphedTangent(in vec3 tangent)\",\n};\n\n/**\n * This pipeline stage processes the morph targets and weights of a primitive,\n * adding the relevant attribute declarations and functions to the shaders.\n *\n * Processes a primitive. This stage modifies the following parts of the render resources:\n *
    \n *
  • adds attribute declarations for the morph targets in the vertex shader\n *
  • adds the uniform declaration for the morph weights in the vertex shader\n *
  • adds functions to apply the morphs in the vertex shader\n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n *\n * @private\n */\nMorphTargetsPipelineStage.process = function (renderResources, primitive) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"HAS_MORPH_TARGETS\",\n undefined,\n ShaderDestination.VERTEX\n );\n\n addGetMorphedAttributeFunctionDeclarations(shaderBuilder);\n\n const morphTargetsLength = primitive.morphTargets.length;\n for (let i = 0; i < morphTargetsLength; i++) {\n const attributes = primitive.morphTargets[i].attributes;\n\n const attributesLength = attributes.length;\n for (let j = 0; j < attributesLength; j++) {\n const attribute = attributes[j];\n const semantic = attribute.semantic;\n\n // Cesium only supports morph targets for positions, normals, and tangents\n if (\n semantic !== VertexAttributeSemantic.POSITION &&\n semantic !== VertexAttributeSemantic.NORMAL &&\n semantic !== VertexAttributeSemantic.TANGENT\n ) {\n continue;\n }\n\n processMorphTargetAttribute(\n renderResources,\n attribute,\n renderResources.attributeIndex,\n i\n );\n renderResources.attributeIndex++;\n }\n }\n\n addGetMorphedAttributeFunctionReturns(shaderBuilder);\n\n const weights = renderResources.runtimeNode.morphWeights;\n const weightsLength = weights.length;\n shaderBuilder.addUniform(\n \"float\",\n `u_morphWeights[${weightsLength}]`,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addVertexLines(MorphTargetsStageVS);\n\n const uniformMap = {\n u_morphWeights: function () {\n return renderResources.runtimeNode.morphWeights;\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n};\n\nconst scratchAttributeInfo = {\n attributeString: undefined,\n functionId: undefined,\n};\n\nfunction processMorphTargetAttribute(\n renderResources,\n attribute,\n attributeIndex,\n morphTargetIndex\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n addMorphTargetAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex\n );\n\n const attributeInfo = getMorphTargetAttributeInfo(\n attribute,\n scratchAttributeInfo\n );\n\n addMorphTargetAttributeDeclarationAndFunctionLine(\n shaderBuilder,\n attributeInfo,\n morphTargetIndex\n );\n}\n\nfunction addMorphTargetAttributeToRenderResources(\n renderResources,\n attribute,\n attributeIndex\n) {\n const vertexAttribute = {\n index: attributeIndex,\n value: defined(attribute.buffer) ? undefined : attribute.constant,\n vertexBuffer: attribute.buffer,\n componentsPerAttribute: AttributeType.getNumberOfComponents(attribute.type),\n componentDatatype: attribute.componentDatatype,\n offsetInBytes: attribute.byteOffset,\n strideInBytes: attribute.byteStride,\n normalize: attribute.normalized,\n };\n\n renderResources.attributes.push(vertexAttribute);\n}\n\nfunction getMorphTargetAttributeInfo(attribute, result) {\n const semantic = attribute.semantic;\n switch (semantic) {\n case VertexAttributeSemantic.POSITION:\n result.attributeString = \"Position\";\n result.functionId =\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_POSITION;\n break;\n case VertexAttributeSemantic.NORMAL:\n result.attributeString = \"Normal\";\n result.functionId =\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_NORMAL;\n break;\n case VertexAttributeSemantic.TANGENT:\n result.attributeString = \"Tangent\";\n result.functionId =\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_TANGENT;\n break;\n default:\n break;\n }\n return result;\n}\n\nfunction addMorphTargetAttributeDeclarationAndFunctionLine(\n shaderBuilder,\n attributeInfo,\n morphTargetIndex\n) {\n const attributeString = attributeInfo.attributeString;\n const attributeName = `a_target${attributeString}_${morphTargetIndex}`;\n const line = `morphed${attributeString} += u_morphWeights[${morphTargetIndex}] * a_target${attributeString}_${morphTargetIndex};`;\n shaderBuilder.addAttribute(\"vec3\", attributeName);\n shaderBuilder.addFunctionLines(attributeInfo.functionId, [line]);\n}\n\nfunction addGetMorphedAttributeFunctionDeclarations(shaderBuilder) {\n shaderBuilder.addFunction(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_POSITION,\n MorphTargetsPipelineStage.FUNCTION_SIGNATURE_GET_MORPHED_POSITION,\n ShaderDestination.VERTEX\n );\n\n const positionLine = \"vec3 morphedPosition = position;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_POSITION,\n [positionLine]\n );\n\n shaderBuilder.addFunction(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_NORMAL,\n MorphTargetsPipelineStage.FUNCTION_SIGNATURE_GET_MORPHED_NORMAL,\n ShaderDestination.VERTEX\n );\n\n const normalLine = \"vec3 morphedNormal = normal;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_NORMAL,\n [normalLine]\n );\n\n shaderBuilder.addFunction(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_TANGENT,\n MorphTargetsPipelineStage.FUNCTION_SIGNATURE_GET_MORPHED_TANGENT,\n ShaderDestination.VERTEX\n );\n\n const tangentLine = \"vec3 morphedTangent = tangent;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_TANGENT,\n [tangentLine]\n );\n}\n\nfunction addGetMorphedAttributeFunctionReturns(shaderBuilder) {\n const positionLine = \"return morphedPosition;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_POSITION,\n [positionLine]\n );\n\n const normalLine = \"return morphedNormal;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_NORMAL,\n [normalLine]\n );\n\n const tangentLine = \"return morphedTangent;\";\n shaderBuilder.addFunctionLines(\n MorphTargetsPipelineStage.FUNCTION_ID_GET_MORPHED_TANGENT,\n [tangentLine]\n );\n}\n\nexport default MorphTargetsPipelineStage;\n", "import Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport Color from \"../../Core/Color.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport ModelType from \"./ModelType.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The picking pipeline stage is responsible for handling picking of primitives.\n *\n * @namespace PickingPipelineStage\n * @private\n */\nconst PickingPipelineStage = {\n name: \"PickingPipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render resources:\n *
    \n *
  • adds attribute and varying declaration for the pick color vertex attribute in the vertex shader for instanced meshes
  • \n *
  • adds declaration for the pick color uniform for non-instanced meshes
  • \n *
  • adds defines in the shader for when picking is enabled
  • \n *
  • creates the pick ID objects in the context
  • \n *
\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n */\nPickingPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const context = frameState.context;\n const runtimeNode = renderResources.runtimeNode;\n const shaderBuilder = renderResources.shaderBuilder;\n const model = renderResources.model;\n const instances = runtimeNode.node.instances;\n\n if (renderResources.hasPropertyTable) {\n processPickTexture(renderResources, primitive, instances, context);\n } else if (defined(instances)) {\n // For instanced meshes, a pick color vertex attribute is used.\n processInstancedPickIds(renderResources, context);\n } else {\n // For non-instanced meshes, a pick color uniform is used.\n const pickObject = buildPickObject(renderResources);\n\n const pickId = context.createPickId(pickObject);\n model._pipelineResources.push(pickId);\n model._pickIds.push(pickId);\n\n shaderBuilder.addUniform(\n \"vec4\",\n \"czm_pickColor\",\n ShaderDestination.FRAGMENT\n );\n\n const uniformMap = renderResources.uniformMap;\n uniformMap.czm_pickColor = function () {\n return pickId.color;\n };\n\n renderResources.pickId = \"czm_pickColor\";\n }\n};\n\n/**\n * @private\n */\nfunction buildPickObject(renderResources, instanceId) {\n const model = renderResources.model;\n\n // Primitives that wrap Model may define the pickObject differently.\n if (defined(model.pickObject)) {\n return model.pickObject;\n }\n\n const detailPickObject = {\n model: model,\n node: renderResources.runtimeNode,\n primitive: renderResources.runtimePrimitive,\n };\n\n let pickObject;\n\n if (ModelType.is3DTiles(model.type)) {\n // For 3D Tiles, the pick object's content and primitive are set to the Cesium3DTileContent that owns the model\n // and the tileset it belongs to, respectively. The detail pick object is returned under the detail key.\n const content = model.content;\n pickObject = {\n content: content,\n primitive: content.tileset,\n detail: detailPickObject,\n };\n } else {\n // For models, the model itself is returned as the primitive, with the detail pick object under the detail key.\n pickObject = {\n primitive: model,\n detail: detailPickObject,\n };\n }\n\n pickObject.id = model.id;\n\n if (defined(instanceId)) {\n // For instanced models, an instanceId property is added to the pick object.\n pickObject.instanceId = instanceId;\n }\n\n return pickObject;\n}\n\nfunction processPickTexture(renderResources, primitive, instances) {\n const model = renderResources.model;\n let featureTableId;\n let featureIdAttribute;\n const featureIdLabel = model.featureIdLabel;\n const instanceFeatureIdLabel = model.instanceFeatureIdLabel;\n\n if (defined(model.featureTableId)) {\n // Extract the Feature Table ID from the Cesium3DTileContent.\n featureTableId = model.featureTableId;\n } else if (defined(instances)) {\n // Extract the Feature Table ID from the instanced Feature ID attributes.\n featureIdAttribute = ModelUtility.getFeatureIdsByLabel(\n instances.featureIds,\n instanceFeatureIdLabel\n );\n featureTableId = featureIdAttribute.propertyTableId;\n } else {\n // Extract the Feature Table ID from the primitive Feature ID attributes.\n featureIdAttribute = ModelUtility.getFeatureIdsByLabel(\n primitive.featureIds,\n featureIdLabel\n );\n featureTableId = featureIdAttribute.propertyTableId;\n }\n\n const featureTable = model.featureTables[featureTableId];\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addUniform(\n \"sampler2D\",\n \"model_pickTexture\",\n ShaderDestination.FRAGMENT\n );\n\n const batchTexture = featureTable.batchTexture;\n renderResources.uniformMap.model_pickTexture = function () {\n return defaultValue(batchTexture.pickTexture, batchTexture.defaultTexture);\n };\n\n // The feature ID is ignored if it is greater than the number of features.\n renderResources.pickId =\n \"((selectedFeature.id < int(model_featuresLength)) ? texture(model_pickTexture, selectedFeature.st) : vec4(0.0))\";\n}\n\nfunction processInstancedPickIds(renderResources, context) {\n const instanceCount = renderResources.instanceCount;\n const pickIds = new Array(instanceCount);\n const pickIdsTypedArray = new Uint8Array(instanceCount * 4);\n\n const model = renderResources.model;\n\n const pipelineResources = model._pipelineResources;\n for (let i = 0; i < instanceCount; i++) {\n const pickObject = buildPickObject(renderResources, i);\n\n const pickId = context.createPickId(pickObject);\n pipelineResources.push(pickId);\n pickIds[i] = pickId;\n\n const pickColor = pickId.color;\n pickIdsTypedArray[i * 4 + 0] = Color.floatToByte(pickColor.red);\n pickIdsTypedArray[i * 4 + 1] = Color.floatToByte(pickColor.green);\n pickIdsTypedArray[i * 4 + 2] = Color.floatToByte(pickColor.blue);\n pickIdsTypedArray[i * 4 + 3] = Color.floatToByte(pickColor.alpha);\n }\n\n model._pickIds = pickIds;\n\n const pickIdsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: pickIdsTypedArray,\n usage: BufferUsage.STATIC_DRAW,\n });\n // Destruction of resources allocated by the Model\n // is handled by Model.destroyPipelineResources().\n pickIdsBuffer.vertexArrayDestroyable = false;\n const hasCpuCopy = false;\n model.statistics.addBuffer(pickIdsBuffer, hasCpuCopy);\n pipelineResources.push(pickIdsBuffer);\n\n const pickIdsVertexAttribute = {\n index: renderResources.attributeIndex++,\n vertexBuffer: pickIdsBuffer,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n normalize: true,\n offsetInBytes: 0,\n strideInBytes: 0,\n instanceDivisor: 1,\n };\n\n renderResources.attributes.push(pickIdsVertexAttribute);\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addDefine(\"USE_PICKING\", undefined, ShaderDestination.BOTH);\n shaderBuilder.addAttribute(\"vec4\", \"a_pickColor\");\n shaderBuilder.addVarying(\"vec4\", \"v_pickColor\");\n renderResources.pickId = \"v_pickColor\";\n}\n\nexport default PickingPipelineStage;\n", "/**\n * The refinement approach for a tile.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#refinement|Refinement}\n * in the 3D Tiles spec.\n *

\n *\n * @enum {number}\n *\n * @private\n */\nconst Cesium3DTileRefine = {\n /**\n * Render this tile and, if it doesn't meet the screen space error, also refine to its children.\n *\n * @type {number}\n * @constant\n */\n ADD: 0,\n\n /**\n * Render this tile or, if it doesn't meet the screen space error, refine to its descendants instead.\n *\n * @type {number}\n * @constant\n */\n REPLACE: 1,\n};\nexport default Object.freeze(Cesium3DTileRefine);\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"float getPointSizeFromAttenuation(vec3 positionEC) {\\n\\\n // Variables are packed into a single vector to minimize gl.uniformXXX() calls\\n\\\n float pointSize = model_pointCloudParameters.x;\\n\\\n float geometricError = model_pointCloudParameters.y;\\n\\\n float depthMultiplier = model_pointCloudParameters.z;\\n\\\n\\n\\\n float depth = -positionEC.z;\\n\\\n return min((geometricError / depth) * depthMultiplier, pointSize);\\n\\\n}\\n\\\n\\n\\\n#ifdef HAS_POINT_CLOUD_SHOW_STYLE\\n\\\nfloat pointCloudShowStylingStage(in ProcessedAttributes attributes, in Metadata metadata) {\\n\\\n float tiles3d_tileset_time = model_pointCloudParameters.w;\\n\\\n return float(getShowFromStyle(attributes, metadata, tiles3d_tileset_time));\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\n#ifdef HAS_POINT_CLOUD_COLOR_STYLE\\n\\\nvec4 pointCloudColorStylingStage(in ProcessedAttributes attributes, in Metadata metadata) {\\n\\\n float tiles3d_tileset_time = model_pointCloudParameters.w;\\n\\\n return getColorFromStyle(attributes, metadata, tiles3d_tileset_time);\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\n#ifdef HAS_POINT_CLOUD_POINT_SIZE_STYLE\\n\\\nfloat pointCloudPointSizeStylingStage(in ProcessedAttributes attributes, in Metadata metadata) {\\n\\\n float tiles3d_tileset_time = model_pointCloudParameters.w;\\n\\\n return float(getPointSizeFromStyle(attributes, metadata, tiles3d_tileset_time));\\n\\\n}\\n\\\n#elif defined(HAS_POINT_CLOUD_ATTENUATION)\\n\\\nfloat pointCloudPointSizeStylingStage(in ProcessedAttributes attributes, in Metadata metadata) {\\n\\\n return getPointSizeFromAttenuation(v_positionEC);\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\n#ifdef HAS_POINT_CLOUD_BACK_FACE_CULLING\\n\\\nfloat pointCloudBackFaceCullingStage() {\\n\\\n #if defined(HAS_NORMALS) && !defined(HAS_DOUBLE_SIDED_MATERIAL)\\n\\\n // This needs to be computed in eye coordinates so we can't use attributes.normalMC\\n\\\n return step(-v_normalEC.z, 0.0);\\n\\\n #else\\n\\\n return 1.0;\\n\\\n #endif\\n\\\n}\\n\\\n#endif\";\n", "import Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Cartesian4 from \"../../Core/Cartesian4.js\";\nimport CesiumMath from \"../../Core/Math.js\";\nimport Cesium3DTileRefine from \"../Cesium3DTileRefine.js\";\nimport clone from \"../../Core/clone.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport ModelType from \"./ModelType.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport OrthographicFrustum from \"../../Core/OrthographicFrustum.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport PointCloudStylingStageVS from \"../../Shaders/Model/PointCloudStylingStageVS.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\nconst scratchUniform = new Cartesian4();\n\n/**\n * The point cloud styling stage is responsible for applying color,\n * size, and show styles to point clouds at runtime. It also handles\n * point cloud shading provided by either the model or the tileset that\n * owns it. Point cloud shading is only applied if no point size style\n * is provided.\n *\n * @namespace PointCloudStylingPipelineStage\n *\n * @private\n */\nconst PointCloudStylingPipelineStage = {\n name: \"PointCloudStylingPipelineStage\", // Helps with debugging\n};\n\n/**\n * Processes a primitive. If the model that owns it has a style, then\n * this stage modifies the following parts of the render resources:\n *
    \n *
  • adds the styling functions to the vertex shaders
  • \n *
  • adds a define to compute the position in world coordinates
  • \n *
  • adds a varying to compute point cloud color
  • \n *
\n *\n * If the model has point cloud shading, then this stage modifies the following\n * part of the render resources:\n *
    \n *
  • adds vertex shader code to compute attenuation and update gl_PointSize
  • \n *
  • updates the uniform map to pass in point cloud parameters
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nPointCloudStylingPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const model = renderResources.model;\n const style = model.style;\n\n // Point cloud styling will only be applied on the GPU if there is\n // no batch table. If a batch table exists, then:\n // - the property attribute will not be defined\n // - the model will be using a feature table\n\n const structuralMetadata = model.structuralMetadata;\n const propertyAttributes = defined(structuralMetadata)\n ? structuralMetadata.propertyAttributes\n : undefined;\n\n const hasFeatureTable =\n defined(model.featureTableId) &&\n model.featureTables[model.featureTableId].featuresLength > 0;\n\n const hasBatchTable = !defined(propertyAttributes) && hasFeatureTable;\n\n if (defined(style) && !hasBatchTable) {\n const variableSubstitutionMap = getVariableSubstitutionMap(\n propertyAttributes\n );\n const shaderFunctionInfo = getStyleShaderFunctionInfo(\n style,\n variableSubstitutionMap\n );\n addShaderFunctionsAndDefines(shaderBuilder, shaderFunctionInfo);\n\n const propertyNames = getPropertyNames(shaderFunctionInfo);\n\n const usesNormalSemantic = propertyNames.indexOf(\"normalMC\") >= 0;\n const hasNormals = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.NORMAL\n );\n\n if (usesNormalSemantic && !hasNormals) {\n throw new RuntimeError(\n \"Style references the NORMAL semantic but the point cloud does not have normals\"\n );\n }\n\n shaderBuilder.addDefine(\n \"COMPUTE_POSITION_WC_STYLE\",\n undefined,\n ShaderDestination.VERTEX\n );\n\n // If the style is translucent, the alpha options must be adjusted.\n const styleTranslucent = shaderFunctionInfo.styleTranslucent;\n if (styleTranslucent) {\n renderResources.alphaOptions.pass = Pass.TRANSLUCENT;\n }\n }\n\n const pointCloudShading = model.pointCloudShading;\n if (pointCloudShading.attenuation) {\n shaderBuilder.addDefine(\n \"HAS_POINT_CLOUD_ATTENUATION\",\n undefined,\n ShaderDestination.VERTEX\n );\n }\n\n if (pointCloudShading.backFaceCulling) {\n shaderBuilder.addDefine(\n \"HAS_POINT_CLOUD_BACK_FACE_CULLING\",\n undefined,\n ShaderDestination.VERTEX\n );\n }\n\n let content;\n let is3DTiles;\n let usesAddRefinement;\n\n if (ModelType.is3DTiles(model.type)) {\n is3DTiles = true;\n content = model.content;\n usesAddRefinement = content.tile.refine === Cesium3DTileRefine.ADD;\n }\n\n shaderBuilder.addUniform(\n \"vec4\",\n \"model_pointCloudParameters\",\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addVertexLines(PointCloudStylingStageVS);\n\n const uniformMap = renderResources.uniformMap;\n uniformMap.model_pointCloudParameters = function () {\n const vec4 = scratchUniform;\n\n // Point size\n let defaultPointSize = 1.0;\n if (is3DTiles) {\n defaultPointSize = usesAddRefinement\n ? 5.0\n : content.tileset.memoryAdjustedScreenSpaceError;\n }\n vec4.x = defaultValue(\n pointCloudShading.maximumAttenuation,\n defaultPointSize\n );\n vec4.x *= frameState.pixelRatio;\n\n // Geometric error\n const geometricError = getGeometricError(\n renderResources,\n primitive,\n pointCloudShading,\n content\n );\n vec4.y = geometricError * pointCloudShading.geometricErrorScale;\n\n const context = frameState.context;\n const frustum = frameState.camera.frustum;\n let depthMultiplier;\n\n // Attenuation is maximumAttenuation in 2D/ortho\n if (\n frameState.mode === SceneMode.SCENE2D ||\n frustum instanceof OrthographicFrustum\n ) {\n depthMultiplier = Number.POSITIVE_INFINITY;\n } else {\n depthMultiplier =\n context.drawingBufferHeight / frameState.camera.frustum.sseDenominator;\n }\n\n // Depth multiplier\n vec4.z = depthMultiplier;\n\n // Time\n if (is3DTiles) {\n vec4.w = content.tileset.timeSinceLoad;\n }\n\n return vec4;\n };\n};\n\nconst scratchDimensions = new Cartesian3();\nfunction getGeometricError(\n renderResources,\n primitive,\n pointCloudShading,\n content\n) {\n if (defined(content)) {\n const geometricError = content.tile.geometricError;\n\n if (geometricError > 0) {\n return geometricError;\n }\n }\n\n if (defined(pointCloudShading.baseResolution)) {\n return pointCloudShading.baseResolution;\n }\n\n const positionAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.POSITION\n );\n const pointsLength = positionAttribute.count;\n\n // Estimate the geometric error\n const nodeTransform = renderResources.runtimeNode.transform;\n let dimensions = Cartesian3.subtract(\n positionAttribute.max,\n positionAttribute.min,\n scratchDimensions\n );\n // dimensions is a vector, as it is a subtraction between two points\n dimensions = Matrix4.multiplyByPointAsVector(\n nodeTransform,\n dimensions,\n scratchDimensions\n );\n const volume = dimensions.x * dimensions.y * dimensions.z;\n const geometricErrorEstimate = CesiumMath.cbrt(volume / pointsLength);\n return geometricErrorEstimate;\n}\n\nconst scratchShaderFunctionInfo = {\n colorStyleFunction: undefined,\n showStyleFunction: undefined,\n pointSizeStyleFunction: undefined,\n styleTranslucent: false,\n};\n\nconst builtinVariableSubstitutionMap = {\n POSITION: \"attributes.positionMC\",\n POSITION_ABSOLUTE: \"v_positionWC\",\n COLOR: \"attributes.color_0\",\n NORMAL: \"attributes.normalMC\",\n};\n\nfunction getVariableSubstitutionMap(propertyAttributes) {\n const variableSubstitutionMap = clone(builtinVariableSubstitutionMap);\n\n if (!defined(propertyAttributes)) {\n return variableSubstitutionMap;\n }\n\n for (let i = 0; i < propertyAttributes.length; i++) {\n const propertyAttribute = propertyAttributes[i];\n const properties = propertyAttribute.properties;\n for (const propertyId in properties) {\n // The property ID was already sanitized for GLSL by PntsLoader.\n if (properties.hasOwnProperty(propertyId)) {\n variableSubstitutionMap[propertyId] = `metadata.${propertyId}`;\n }\n }\n }\n\n return variableSubstitutionMap;\n}\nconst parameterList =\n \"ProcessedAttributes attributes, \" +\n \"Metadata metadata, \" +\n \"float tiles3d_tileset_time\";\n\nfunction getStyleShaderFunctionInfo(style, variableSubstitutionMap) {\n const info = scratchShaderFunctionInfo;\n const shaderState = {\n translucent: false,\n };\n\n info.colorStyleFunction = style.getColorShaderFunction(\n `getColorFromStyle(${parameterList})`,\n variableSubstitutionMap,\n shaderState\n );\n info.showStyleFunction = style.getShowShaderFunction(\n `getShowFromStyle(${parameterList})`,\n variableSubstitutionMap,\n shaderState\n );\n info.pointSizeStyleFunction = style.getPointSizeShaderFunction(\n `getPointSizeFromStyle(${parameterList})`,\n variableSubstitutionMap,\n shaderState\n );\n info.styleTranslucent =\n defined(info.colorStyleFunction) && shaderState.translucent;\n\n return info;\n}\n\nfunction addShaderFunctionsAndDefines(shaderBuilder, shaderFunctionInfo) {\n const colorStyleFunction = shaderFunctionInfo.colorStyleFunction;\n if (defined(colorStyleFunction)) {\n shaderBuilder.addDefine(\n \"HAS_POINT_CLOUD_COLOR_STYLE\",\n undefined,\n ShaderDestination.BOTH\n );\n shaderBuilder.addVertexLines(colorStyleFunction);\n\n // The point cloud may not necessarily have a color attribute.\n // Use a custom varying to account for this.\n shaderBuilder.addVarying(\"vec4\", \"v_pointCloudColor\");\n }\n\n const showStyleFunction = shaderFunctionInfo.showStyleFunction;\n if (defined(showStyleFunction)) {\n shaderBuilder.addDefine(\n \"HAS_POINT_CLOUD_SHOW_STYLE\",\n undefined,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addVertexLines(showStyleFunction);\n }\n\n const pointSizeStyleFunction = shaderFunctionInfo.pointSizeStyleFunction;\n if (defined(pointSizeStyleFunction)) {\n shaderBuilder.addDefine(\n \"HAS_POINT_CLOUD_POINT_SIZE_STYLE\",\n undefined,\n ShaderDestination.VERTEX\n );\n shaderBuilder.addVertexLines(pointSizeStyleFunction);\n }\n}\n\n/**\n * Gets all the built-in property names used by the given style\n * function.\n *\n * @param {Function} source The style function.\n * @param {string[]} propertyNames The array of property names to add to.\n *\n * @private\n */\nfunction getBuiltinPropertyNames(source, propertyNames) {\n const regex = /attributes\\.(\\w+)/g;\n let matches = regex.exec(source);\n while (matches !== null) {\n const name = matches[1];\n // Add the property name if it isn't already in the array.\n if (propertyNames.indexOf(name) === -1) {\n propertyNames.push(name);\n }\n matches = regex.exec(source);\n }\n}\n\nfunction getPropertyNames(shaderFunctionInfo) {\n const colorStyleFunction = shaderFunctionInfo.colorStyleFunction;\n const showStyleFunction = shaderFunctionInfo.showStyleFunction;\n const pointSizeStyleFunction = shaderFunctionInfo.pointSizeStyleFunction;\n\n // Get the properties in use by the style.\n const builtinPropertyNames = [];\n\n if (defined(colorStyleFunction)) {\n getBuiltinPropertyNames(colorStyleFunction, builtinPropertyNames);\n }\n if (defined(showStyleFunction)) {\n getBuiltinPropertyNames(showStyleFunction, builtinPropertyNames);\n }\n if (defined(pointSizeStyleFunction)) {\n getBuiltinPropertyNames(pointSizeStyleFunction, builtinPropertyNames);\n }\n\n return builtinPropertyNames;\n}\n\nexport default PointCloudStylingPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void primitiveOutlineStage() {\\n\\\n v_outlineCoordinates = a_outlineCoordinates;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void primitiveOutlineStage(inout czm_modelMaterial material) {\\n\\\n if (!model_showOutline) {\\n\\\n return;\\n\\\n }\\n\\\n\\n\\\n float outlineX = \\n\\\n texture(model_outlineTexture, vec2(v_outlineCoordinates.x, 0.5)).r;\\n\\\n float outlineY = \\n\\\n texture(model_outlineTexture, vec2(v_outlineCoordinates.y, 0.5)).r;\\n\\\n float outlineZ = \\n\\\n texture(model_outlineTexture, vec2(v_outlineCoordinates.z, 0.5)).r;\\n\\\n float outlineness = max(outlineX, max(outlineY, outlineZ));\\n\\\n\\n\\\n material.diffuse = mix(material.diffuse, model_outlineColor.rgb, model_outlineColor.a * outlineness);\\n\\\n}\\n\\\n\\n\\\n\";\n", "import AttributeType from \"../AttributeType.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport PrimitiveOutlineGenerator from \"./PrimitiveOutlineGenerator.js\";\nimport PrimitiveOutlineStageVS from \"../../Shaders/Model/PrimitiveOutlineStageVS.js\";\nimport PrimitiveOutlineStageFS from \"../../Shaders/Model/PrimitiveOutlineStageFS.js\";\n\n/**\n * The primitive outline pipeline stage configures the shader to render outlines\n * from the CESIUM_primitive_outline extension.\n *\n * @namespace PrimitiveOutlinePipelineStage\n *\n * @private\n */\nconst PrimitiveOutlinePipelineStage = {\n name: \"PrimitiveOutlinePipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a primitive. This modifies the following parts of the render\n * resources:\n *
    \n *
  • Declares a new attribute for the outline (texture) coordinates
  • \n *
  • Adds shader code to overlay outlines on the primitive after lighting computations
  • \n *
  • Add uniforms for showing the outline and changing its color
  • \n *
\n * @param {PrimitiveRenderResources} renderResources The render resources for the primitive\n * @param {ModelComponents.Primitive} primitive The primitive to be rendered\n * @param {FrameState} frameState The frame state\n * @private\n */\nPrimitiveOutlinePipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n const uniformMap = renderResources.uniformMap;\n\n shaderBuilder.addDefine(\n \"HAS_PRIMITIVE_OUTLINE\",\n undefined,\n ShaderDestination.BOTH\n );\n\n shaderBuilder.addAttribute(\"vec3\", \"a_outlineCoordinates\");\n shaderBuilder.addVarying(\"vec3\", \"v_outlineCoordinates\");\n\n const outlineCoordinates = primitive.outlineCoordinates;\n const vertexAttribute = {\n index: renderResources.attributeIndex++,\n vertexBuffer: outlineCoordinates.buffer,\n componentsPerAttribute: AttributeType.getNumberOfComponents(\n outlineCoordinates.type\n ),\n componentDatatype: outlineCoordinates.componentDatatype,\n offsetInBytes: outlineCoordinates.byteOffset,\n strideInBytes: outlineCoordinates.byteStride,\n normalize: outlineCoordinates.normalized,\n };\n renderResources.attributes.push(vertexAttribute);\n\n shaderBuilder.addUniform(\n \"sampler2D\",\n \"model_outlineTexture\",\n ShaderDestination.FRAGMENT\n );\n\n // This automatically handles caching the texture on the context\n const outlineTexture = PrimitiveOutlineGenerator.createTexture(\n frameState.context\n );\n uniformMap.model_outlineTexture = function () {\n return outlineTexture;\n };\n\n const model = renderResources.model;\n shaderBuilder.addUniform(\n \"vec4\",\n \"model_outlineColor\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.model_outlineColor = function () {\n return model.outlineColor;\n };\n shaderBuilder.addUniform(\n \"bool\",\n \"model_showOutline\",\n ShaderDestination.FRAGMENT\n );\n uniformMap.model_showOutline = function () {\n return model.showOutline;\n };\n\n shaderBuilder.addVertexLines(PrimitiveOutlineStageVS);\n shaderBuilder.addFragmentLines(PrimitiveOutlineStageFS);\n};\n\nexport default PrimitiveOutlinePipelineStage;\n", "import defined from \"../../Core/defined.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport ModelUtility from \"./ModelUtility.js\";\n\n/**\n * The primitive statistics update stage updates memory usage statistics\n * on the primitive level. This counts the binary resources that exist\n * for the lifetime of the Model (e.g. attributes and textures\n * loaded by GltfLoader). It does not count resources that are created\n * every time the pipeline is run. The individual pipeline stages are\n * responsible for tracking the additional memory they allocate.\n *\n * @namespace PrimitiveStatisticsPipelineStage\n *\n * @private\n */\nconst PrimitiveStatisticsPipelineStage = {\n name: \"PrimitiveStatisticsPipelineStage\", // Helps with debugging\n\n // Expose some methods for testing\n _countGeometry: countGeometry,\n _count2DPositions: count2DPositions,\n _countMorphTargetAttributes: countMorphTargetAttributes,\n _countMaterialTextures: countMaterialTextures,\n _countFeatureIdTextures: countFeatureIdTextures,\n _countBinaryMetadata: countBinaryMetadata,\n};\n\nPrimitiveStatisticsPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const model = renderResources.model;\n const statistics = model.statistics;\n\n countGeometry(statistics, primitive);\n count2DPositions(statistics, renderResources.runtimePrimitive);\n countMorphTargetAttributes(statistics, primitive);\n countMaterialTextures(statistics, primitive.material);\n countFeatureIdTextures(statistics, primitive.featureIds);\n countBinaryMetadata(statistics, model);\n\n // The following stages handle their own memory statistics, since all their\n // resources are generated each time draw commands are built:\n //\n // - PickingPipelineStage\n // - WireframePipelineStage\n // - InstancingPipelineStage\n // - FeatureIdPipelineStage (feature ID implicit ranges only)\n};\n\nfunction countGeometry(statistics, primitive) {\n const indicesCount = defined(primitive.indices)\n ? primitive.indices.count\n : ModelUtility.getAttributeBySemantic(primitive, \"POSITION\").count;\n\n const primitiveType = primitive.primitiveType;\n\n if (primitiveType === PrimitiveType.POINTS) {\n statistics.pointsLength += indicesCount;\n } else if (PrimitiveType.isTriangles(primitiveType)) {\n statistics.trianglesLength += countTriangles(primitiveType, indicesCount);\n }\n\n const attributes = primitive.attributes;\n const length = attributes.length;\n for (let i = 0; i < length; i++) {\n const attribute = attributes[i];\n if (defined(attribute.buffer)) {\n const hasCpuCopy = defined(attribute.typedArray);\n statistics.addBuffer(attribute.buffer, hasCpuCopy);\n }\n }\n\n const outlineCoordinates = primitive.outlineCoordinates;\n if (defined(outlineCoordinates) && defined(outlineCoordinates.buffer)) {\n const hasCpuCopy = false;\n statistics.addBuffer(outlineCoordinates.buffer, hasCpuCopy);\n }\n\n const indices = primitive.indices;\n if (defined(indices) && defined(indices.buffer)) {\n // Wireframe mode will have both GPU and CPU copies\n const hasCpuCopy = defined(indices.typedArray);\n statistics.addBuffer(indices.buffer, hasCpuCopy);\n }\n}\n\nfunction countTriangles(primitiveType, indicesCount) {\n switch (primitiveType) {\n case PrimitiveType.TRIANGLES:\n return indicesCount / 3;\n case PrimitiveType.TRIANGLE_STRIP:\n case PrimitiveType.TRIANGLE_FAN:\n return Math.max(indicesCount - 2, 0);\n default:\n return 0;\n }\n}\n\nfunction count2DPositions(statistics, runtimePrimitive) {\n const buffer2D = runtimePrimitive.positionBuffer2D;\n\n // The 2D buffer is only created the first time the scene switches to 2D mode.\n // This means there's two main cases for accounting for 2D positions:\n // 1. The scene was in 3D mode so positions were never generated from\n // positionAttribute.typedArray. In this case, countGeometry() will\n // detect the typed array and set hasCpuCopy = true. No memory is counted\n // here.\n // 2. The scene was in 2D mode so positions were generated as a buffer.\n // Even though the typed array was unlinked from the attribute, it still\n // exists in the loader so we count it here.\n if (defined(buffer2D)) {\n const hasCpuCopy = true;\n statistics.addBuffer(buffer2D, hasCpuCopy);\n }\n}\n\nfunction countMorphTargetAttributes(statistics, primitive) {\n const morphTargets = primitive.morphTargets;\n if (!defined(morphTargets)) {\n return;\n }\n\n const hasCpuCopy = false;\n const morphTargetsLength = morphTargets.length;\n for (let i = 0; i < morphTargetsLength; i++) {\n const attributes = morphTargets[i].attributes;\n\n const attributesLength = attributes.length;\n for (let j = 0; j < attributesLength; j++) {\n const attribute = attributes[j];\n\n if (defined(attribute.buffer)) {\n statistics.addBuffer(attribute.buffer, hasCpuCopy);\n }\n }\n }\n}\n\nfunction countMaterialTextures(statistics, material) {\n // gltf-pipeline provides a default material so material will always be\n // defined.\n const textureReaders = getAllTextureReaders(material);\n const length = textureReaders.length;\n for (let i = 0; i < length; i++) {\n const textureReader = textureReaders[i];\n // If textures were loaded asynchronously, the texture may not be available\n // the first time this is run.\n if (defined(textureReader) && defined(textureReader.texture)) {\n statistics.addTexture(textureReader.texture);\n }\n }\n}\n\nfunction getAllTextureReaders(material) {\n const metallicRoughness = material.metallicRoughness;\n const textureReaders = [\n material.emissiveTexture,\n material.normalTexture,\n material.occlusionTexture,\n metallicRoughness.baseColorTexture,\n metallicRoughness.metallicRoughnessTexture,\n ];\n\n const specularGlossiness = material.specularGlossiness;\n if (defined(specularGlossiness)) {\n textureReaders.push(specularGlossiness.diffuseTexture);\n textureReaders.push(specularGlossiness.specularGlossinessTexture);\n }\n\n return textureReaders;\n}\n\nfunction countFeatureIdTextures(statistics, featureIdSets) {\n // Feature ID attributes are handled by countGeometry()\n\n // Feature ID implicit ranges are handled in the FeatureIdPipelineStage,\n // as they only are created as-needed.\n\n const length = featureIdSets.length;\n for (let i = 0; i < length; i++) {\n const featureIds = featureIdSets[i];\n if (featureIds instanceof ModelComponents.FeatureIdTexture) {\n const textureReader = featureIds.textureReader;\n if (defined(textureReader.texture)) {\n statistics.addTexture(textureReader.texture);\n }\n }\n }\n}\n\nfunction countBinaryMetadata(statistics, model) {\n // Add metadata memory to the statistics. Note that feature ID memory is\n // handled by the Feature ID pipeline stage.\n const structuralMetadata = model.structuralMetadata;\n if (defined(structuralMetadata)) {\n // Property textures are added to the texture memory count. If textures\n // are loaded asynchronously, this may add 0 to the total. The pipeline\n // will be re-run when textures are loaded for an accurate count.\n countPropertyTextures(statistics, structuralMetadata);\n\n // Property tables are accounted for here.\n statistics.propertyTablesByteLength +=\n structuralMetadata.propertyTablesByteLength;\n\n // Skip property attributes since those are handled in countGeometry().\n }\n\n // Model feature tables also have batch and pick textures that need to be\n // counted.\n const featureTables = model.featureTables;\n if (!defined(featureTables)) {\n return;\n }\n\n const length = featureTables.length;\n for (let i = 0; i < length; i++) {\n const featureTable = featureTables[i];\n\n // This does not include the property table memory, since\n // it is counted through the structuralMetadata above.\n statistics.addBatchTexture(featureTable.batchTexture);\n }\n}\n\nfunction countPropertyTextures(statistics, structuralMetadata) {\n const propertyTextures = structuralMetadata.propertyTextures;\n if (!defined(propertyTextures)) {\n return;\n }\n\n // Loop over the property textures from here so we can use\n // statistics.addTexture() which avoids double-counting shared textures.\n const texturesLength = propertyTextures.length;\n for (let i = 0; i < texturesLength; i++) {\n const propertyTexture = propertyTextures[i];\n const properties = propertyTexture.properties;\n for (const propertyId in properties) {\n if (properties.hasOwnProperty(propertyId)) {\n const property = properties[propertyId];\n const textureReader = property.textureReader;\n if (defined(textureReader.texture)) {\n statistics.addTexture(textureReader.texture);\n }\n }\n }\n }\n}\n\nexport default PrimitiveStatisticsPipelineStage;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport clone from \"../../Core/clone.js\";\nimport combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport SceneTransforms from \"../SceneTransforms.js\";\n\nconst scratchModelMatrix = new Matrix4();\nconst scratchModelView2D = new Matrix4();\n\n/**\n * The scene mode 2D stage generates resources for rendering a primitive in 2D / CV mode.\n *\n * @namespace SceneMode2DPipelineStage\n *\n * @private\n */\nconst SceneMode2DPipelineStage = {\n name: \"SceneMode2DPipelineStage\", // Helps with debugging\n};\n\n/**\n * This pipeline stage processes the position attribute of a primitive and adds the relevant\n * define and uniform matrix to the shader. It also generates new resources for the primitive\n * in 2D. These resources persist in the runtime primitive so that the typed array used to\n * store the positional data can be freed.\n *\n * This stage must go before the GeometryPipelineStage in the primitive pipeline.\n *\n * Processes a primitive. This stage modifies the following parts of the render resources:\n *
    \n *
  • creates a vertex buffer for the positions of the primitive projected to 2D\n *
  • creates the bounding sphere for the primitive in 2D\n *
  • adds a flag to the shader to use 2D positions\n *
  • adds a uniform for the view model matrix in 2D\n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\n\nSceneMode2DPipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n const positionAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.POSITION\n );\n\n const shaderBuilder = renderResources.shaderBuilder;\n const model = renderResources.model;\n const modelMatrix = model.sceneGraph.computedModelMatrix;\n const nodeComputedTransform = renderResources.runtimeNode.computedTransform;\n const computedModelMatrix = Matrix4.multiplyTransformation(\n modelMatrix,\n nodeComputedTransform,\n scratchModelMatrix\n );\n\n const boundingSphere2D = computeBoundingSphere2D(\n renderResources,\n computedModelMatrix,\n frameState\n );\n\n const runtimePrimitive = renderResources.runtimePrimitive;\n runtimePrimitive.boundingSphere2D = boundingSphere2D;\n\n // If the model is instanced, 2D projection will be handled in the\n // InstancingPipelineStage.\n const instances = renderResources.runtimeNode.node.instances;\n if (defined(instances)) {\n return;\n }\n\n // If the typed array of the position attribute exists, then\n // the positions haven't been projected to 2D yet.\n if (defined(positionAttribute.typedArray)) {\n const buffer2D = createPositionBufferFor2D(\n positionAttribute,\n computedModelMatrix,\n boundingSphere2D,\n frameState\n );\n\n // Since this buffer will persist even if the pipeline is re-run,\n // its memory will be counted in PrimitiveStatisticsPipelineStage\n runtimePrimitive.positionBuffer2D = buffer2D;\n model._modelResources.push(buffer2D);\n\n // Unload the typed array. This is just a pointer to the array in\n // the vertex buffer loader, so if the typed array is shared by\n // multiple primitives (i.e. multiple instances of the same mesh),\n // this will not affect the other primitives.\n positionAttribute.typedArray = undefined;\n }\n\n shaderBuilder.addDefine(\n \"USE_2D_POSITIONS\",\n undefined,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addUniform(\"mat4\", \"u_modelView2D\", ShaderDestination.VERTEX);\n\n const modelMatrix2D = Matrix4.fromTranslation(\n boundingSphere2D.center,\n new Matrix4()\n );\n\n const context = frameState.context;\n const uniformMap = {\n u_modelView2D: function () {\n return Matrix4.multiplyTransformation(\n context.uniformState.view,\n modelMatrix2D,\n scratchModelView2D\n );\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n};\n\nconst scratchProjectedMin = new Cartesian3();\nconst scratchProjectedMax = new Cartesian3();\n\nfunction computeBoundingSphere2D(renderResources, modelMatrix, frameState) {\n // Compute the bounding sphere in 2D.\n const transformedPositionMin = Matrix4.multiplyByPoint(\n modelMatrix,\n renderResources.positionMin,\n scratchProjectedMin\n );\n\n const projectedMin = SceneTransforms.computeActualWgs84Position(\n frameState,\n transformedPositionMin,\n transformedPositionMin\n );\n\n const transformedPositionMax = Matrix4.multiplyByPoint(\n modelMatrix,\n renderResources.positionMax,\n scratchProjectedMax\n );\n\n const projectedMax = SceneTransforms.computeActualWgs84Position(\n frameState,\n transformedPositionMax,\n transformedPositionMax\n );\n\n return BoundingSphere.fromCornerPoints(\n projectedMin,\n projectedMax,\n new BoundingSphere()\n );\n}\n\nconst scratchPosition = new Cartesian3();\n\nfunction dequantizePositionsTypedArray(typedArray, quantization) {\n // Draco compression is normally handled in the dequantization stage\n // in the shader, but it must be decoded here in order to project\n // the positions to 2D / CV.\n const length = typedArray.length;\n const dequantizedArray = new Float32Array(length);\n const quantizedVolumeOffset = quantization.quantizedVolumeOffset;\n const quantizedVolumeStepSize = quantization.quantizedVolumeStepSize;\n for (let i = 0; i < length; i += 3) {\n const initialPosition = Cartesian3.fromArray(\n typedArray,\n i,\n scratchPosition\n );\n const scaledPosition = Cartesian3.multiplyComponents(\n initialPosition,\n quantizedVolumeStepSize,\n initialPosition\n );\n const dequantizedPosition = Cartesian3.add(\n scaledPosition,\n quantizedVolumeOffset,\n scaledPosition\n );\n\n dequantizedArray[i] = dequantizedPosition.x;\n dequantizedArray[i + 1] = dequantizedPosition.y;\n dequantizedArray[i + 2] = dequantizedPosition.z;\n }\n\n return dequantizedArray;\n}\n\nfunction createPositionsTypedArrayFor2D(\n attribute,\n modelMatrix,\n referencePoint,\n frameState\n) {\n let result;\n if (defined(attribute.quantization)) {\n // Dequantize the positions if necessary.\n result = dequantizePositionsTypedArray(\n attribute.typedArray,\n attribute.quantization\n );\n } else {\n result = attribute.typedArray.slice();\n }\n\n const startIndex = attribute.byteOffset / Float32Array.BYTES_PER_ELEMENT;\n const length = result.length;\n const stride = defined(attribute.byteStride)\n ? attribute.byteStride / Float32Array.BYTES_PER_ELEMENT\n : 3;\n\n for (let i = startIndex; i < length; i += stride) {\n const initialPosition = Cartesian3.fromArray(result, i, scratchPosition);\n if (\n isNaN(initialPosition.x) ||\n isNaN(initialPosition.y) ||\n isNaN(initialPosition.z)\n ) {\n continue;\n }\n\n const transformedPosition = Matrix4.multiplyByPoint(\n modelMatrix,\n initialPosition,\n initialPosition\n );\n\n const projectedPosition = SceneTransforms.computeActualWgs84Position(\n frameState,\n transformedPosition,\n transformedPosition\n );\n\n const relativePosition = Cartesian3.subtract(\n projectedPosition,\n referencePoint,\n projectedPosition\n );\n\n result[i] = relativePosition.x;\n result[i + 1] = relativePosition.y;\n result[i + 2] = relativePosition.z;\n }\n\n return result;\n}\n\nfunction createPositionBufferFor2D(\n positionAttribute,\n modelMatrix,\n boundingSphere2D,\n frameState\n) {\n // Force the scene mode to be CV. In 2D, projected positions will have\n // an x-coordinate of 0, which eliminates the height data that is\n // necessary for rendering in CV mode.\n const frameStateCV = clone(frameState);\n frameStateCV.mode = SceneMode.COLUMBUS_VIEW;\n\n // To prevent jitter, the positions are defined relative to a common\n // reference point. For convenience, this is the center of the\n // primitive's bounding sphere in 2D.\n const referencePoint = boundingSphere2D.center;\n const projectedPositions = createPositionsTypedArrayFor2D(\n positionAttribute,\n modelMatrix,\n referencePoint,\n frameStateCV\n );\n\n // Put the resulting data in a GPU buffer.\n const buffer = Buffer.createVertexBuffer({\n context: frameState.context,\n typedArray: projectedPositions,\n usage: BufferUsage.STATIC_DRAW,\n });\n buffer.vertexArrayDestroyable = false;\n\n return buffer;\n}\n\nexport default SceneMode2DPipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void skinningStage(inout ProcessedAttributes attributes) \\n\\\n{\\n\\\n mat4 skinningMatrix = getSkinningMatrix();\\n\\\n mat3 skinningMatrixMat3 = mat3(skinningMatrix);\\n\\\n\\n\\\n vec4 positionMC = vec4(attributes.positionMC, 1.0);\\n\\\n attributes.positionMC = vec3(skinningMatrix * positionMC);\\n\\\n\\n\\\n #ifdef HAS_NORMALS\\n\\\n vec3 normalMC = attributes.normalMC;\\n\\\n attributes.normalMC = skinningMatrixMat3 * normalMC;\\n\\\n #endif\\n\\\n\\n\\\n #ifdef HAS_TANGENTS\\n\\\n vec3 tangentMC = attributes.tangentMC;\\n\\\n attributes.tangentMC = skinningMatrixMat3 * tangentMC;\\n\\\n #endif\\n\\\n}\";\n", "import combine from \"../../Core/combine.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport SkinningStageVS from \"../../Shaders/Model/SkinningStageVS.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\n/**\n * The skinning pipeline stage processes the joint matrices of a skinned primitive.\n *\n * @namespace SkinningPipelineStage\n *\n * @private\n */\n\nconst SkinningPipelineStage = {\n name: \"SkinningPipelineStage\", // Helps with debugging\n\n FUNCTION_ID_GET_SKINNING_MATRIX: \"getSkinningMatrix\",\n FUNCTION_SIGNATURE_GET_SKINNING_MATRIX: \"mat4 getSkinningMatrix()\",\n};\n\n/**\n * This pipeline stage processes the joint matrices of a skinned primitive, adding\n * the relevant functions and uniforms to the shaders. The joint and weight attributes\n * themselves are processed in the geometry pipeline stage.\n *\n * Processes a primitive. This stage modifies the following parts of the render resources:\n *
    \n *
  • adds the uniform declaration for the joint matrices in the vertex shader
  • \n *
  • adds the function to compute the skinning matrix in the vertex shader
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this primitive.\n * @param {ModelComponents.Primitive} primitive The primitive.\n * @private\n */\nSkinningPipelineStage.process = function (renderResources, primitive) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\"HAS_SKINNING\", undefined, ShaderDestination.VERTEX);\n addGetSkinningMatrixFunction(shaderBuilder, primitive);\n\n const runtimeNode = renderResources.runtimeNode;\n const jointMatrices = runtimeNode.computedJointMatrices;\n\n shaderBuilder.addUniform(\n \"mat4\",\n `u_jointMatrices[${jointMatrices.length}]`,\n ShaderDestination.VERTEX\n );\n\n shaderBuilder.addVertexLines(SkinningStageVS);\n\n const uniformMap = {\n u_jointMatrices: function () {\n return runtimeNode.computedJointMatrices;\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n};\n\nfunction getMaximumAttributeSetIndex(primitive) {\n let setIndex = -1;\n const attributes = primitive.attributes;\n const length = attributes.length;\n for (let i = 0; i < length; i++) {\n const attribute = attributes[i];\n const isJointsOrWeights =\n attribute.semantic === VertexAttributeSemantic.JOINTS ||\n attribute.semantic === VertexAttributeSemantic.WEIGHTS;\n\n if (!isJointsOrWeights) {\n continue;\n }\n\n setIndex = Math.max(setIndex, attribute.setIndex);\n }\n\n return setIndex;\n}\n\nfunction addGetSkinningMatrixFunction(shaderBuilder, primitive) {\n shaderBuilder.addFunction(\n SkinningPipelineStage.FUNCTION_ID_GET_SKINNING_MATRIX,\n SkinningPipelineStage.FUNCTION_SIGNATURE_GET_SKINNING_MATRIX,\n ShaderDestination.VERTEX\n );\n\n const initialLine = \"mat4 skinnedMatrix = mat4(0);\";\n shaderBuilder.addFunctionLines(\n SkinningPipelineStage.FUNCTION_ID_GET_SKINNING_MATRIX,\n [initialLine]\n );\n\n let setIndex;\n let componentIndex;\n const componentStrings = [\"x\", \"y\", \"z\", \"w\"];\n const maximumSetIndex = getMaximumAttributeSetIndex(primitive);\n for (setIndex = 0; setIndex <= maximumSetIndex; setIndex++) {\n for (componentIndex = 0; componentIndex <= 3; componentIndex++) {\n const component = componentStrings[componentIndex];\n // Example: skinnedMatrix += a_weights_0.x * u_jointMatrices[int(a_joints_0.x)];\n const line = `skinnedMatrix += a_weights_${setIndex}.${component} * u_jointMatrices[int(a_joints_${setIndex}.${component})];`;\n shaderBuilder.addFunctionLines(\n SkinningPipelineStage.FUNCTION_ID_GET_SKINNING_MATRIX,\n [line]\n );\n }\n }\n\n const returnLine = \"return skinnedMatrix;\";\n shaderBuilder.addFunctionLines(\n SkinningPipelineStage.FUNCTION_ID_GET_SKINNING_MATRIX,\n [returnLine]\n );\n}\n\nexport default SkinningPipelineStage;\n", "import defined from \"./defined.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\n/**\n * Functions for generating indices for model wireframes. The indices are\n * outputted as typed arrays, which can then be put into buffers for rendering.\n *\n * @namespace WireframeIndexGenerator\n * @private\n */\nconst WireframeIndexGenerator = {};\n\nfunction createWireframeFromTriangles(vertexCount) {\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n vertexCount * 2\n );\n const length = vertexCount;\n let index = 0;\n for (let i = 0; i < length; i += 3) {\n wireframeIndices[index++] = i;\n wireframeIndices[index++] = i + 1;\n wireframeIndices[index++] = i + 1;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = i;\n }\n\n return wireframeIndices;\n}\n\nfunction createWireframeFromTriangleIndices(vertexCount, originalIndices) {\n const originalIndicesCount = originalIndices.length;\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n originalIndicesCount * 2\n );\n let index = 0;\n for (let i = 0; i < originalIndicesCount; i += 3) {\n const point0 = originalIndices[i];\n const point1 = originalIndices[i + 1];\n const point2 = originalIndices[i + 2];\n\n wireframeIndices[index++] = point0;\n wireframeIndices[index++] = point1;\n wireframeIndices[index++] = point1;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = point0;\n }\n\n return wireframeIndices;\n}\n\nfunction createWireframeFromTriangleStrip(vertexCount) {\n const numberOfTriangles = vertexCount - 2;\n const wireframeIndicesCount = 2 + numberOfTriangles * 4;\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n wireframeIndicesCount\n );\n let index = 0;\n\n // Handle the first edge\n wireframeIndices[index++] = 0;\n wireframeIndices[index++] = 1;\n\n // Add two edges for every triangle in the strip\n for (let i = 0; i < numberOfTriangles; i++) {\n wireframeIndices[index++] = i + 1;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = i;\n }\n\n return wireframeIndices;\n}\n\nfunction createWireframeFromTriangleStripIndices(vertexCount, originalIndices) {\n const originalIndicesCount = originalIndices.length;\n const numberOfTriangles = originalIndicesCount - 2;\n const wireframeIndicesCount = 2 + numberOfTriangles * 4;\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n wireframeIndicesCount\n );\n let index = 0;\n\n // Handle the first edge\n wireframeIndices[index++] = originalIndices[0];\n wireframeIndices[index++] = originalIndices[1];\n\n // Add two edges for every triangle in the strip\n for (let i = 0; i < numberOfTriangles; i++) {\n const point0 = originalIndices[i];\n const point1 = originalIndices[i + 1];\n const point2 = originalIndices[i + 2];\n\n wireframeIndices[index++] = point1;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = point0;\n }\n\n return wireframeIndices;\n}\n\nfunction createWireframeFromTriangleFan(vertexCount) {\n const numberOfTriangles = vertexCount - 2;\n const wireframeIndicesCount = 2 + numberOfTriangles * 4;\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n wireframeIndicesCount\n );\n let index = 0;\n\n // Handle the first edge\n wireframeIndices[index++] = 0;\n wireframeIndices[index++] = 1;\n\n // Add two edges for every triangle in the fan\n for (let i = 0; i < numberOfTriangles; i++) {\n wireframeIndices[index++] = i + 1;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = i + 2;\n wireframeIndices[index++] = 0;\n }\n\n return wireframeIndices;\n}\n\nfunction createWireframeFromTriangleFanIndices(vertexCount, originalIndices) {\n const originalIndicesCount = originalIndices.length;\n const numberOfTriangles = originalIndicesCount - 2;\n const wireframeIndicesCount = 2 + numberOfTriangles * 4;\n const wireframeIndices = IndexDatatype.createTypedArray(\n vertexCount,\n wireframeIndicesCount\n );\n let index = 0;\n\n // Handle the first edge\n const firstPoint = originalIndices[0];\n wireframeIndices[index++] = firstPoint;\n wireframeIndices[index++] = originalIndices[1];\n\n // Add two edges for every triangle in the fan\n for (let i = 0; i < numberOfTriangles; i++) {\n const point1 = originalIndices[i + 1];\n const point2 = originalIndices[i + 2];\n\n wireframeIndices[index++] = point1;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = point2;\n wireframeIndices[index++] = firstPoint;\n }\n\n return wireframeIndices;\n}\n\n/**\n * Generates a wireframe index buffer for a primitive, either by reindexing the existing indices\n * or creating them from scratch if the model had none.\n *\n * @param {PrimitiveType} primitiveType The primitive type.\n * @param {number} vertexCount The number of vertices in the primitive.\n * @param {Uint8Array|Uint16Array|Uint32Array} [originalIndices] A typed array containing the original indices of the primitive.\n *\n * @return {Uint16Array|Uint32Array} A typed array with the wireframe indices, or undefined if the primitive type does not use triangles.\n *\n * @private\n */\nWireframeIndexGenerator.createWireframeIndices = function (\n primitiveType,\n vertexCount,\n originalIndices\n) {\n const hasOriginalIndices = defined(originalIndices);\n if (primitiveType === PrimitiveType.TRIANGLES) {\n return hasOriginalIndices\n ? createWireframeFromTriangleIndices(vertexCount, originalIndices)\n : createWireframeFromTriangles(vertexCount);\n }\n\n if (primitiveType === PrimitiveType.TRIANGLE_STRIP) {\n return hasOriginalIndices\n ? createWireframeFromTriangleStripIndices(vertexCount, originalIndices)\n : createWireframeFromTriangleStrip(vertexCount);\n }\n\n if (primitiveType === PrimitiveType.TRIANGLE_FAN) {\n return hasOriginalIndices\n ? createWireframeFromTriangleFanIndices(vertexCount, originalIndices)\n : createWireframeFromTriangleFan(vertexCount);\n }\n\n return undefined;\n};\n\n/**\n * Gets the number of indices in the wireframe index buffer of a primitive type.\n *\n * @param {PrimitiveType} primitiveType The primitive type.\n * @param {number} originalCount The original number of vertices or indices in the primitive.\n * @return {number} The number of indices in the primitive's wireframe.\n *\n * @private\n */\nWireframeIndexGenerator.getWireframeIndicesCount = function (\n primitiveType,\n originalCount\n) {\n // For TRIANGLES, the wireframe takes every triangle (i.e. three of the original\n // indices) and turns it into lines. Each triangle has three lines, and each line\n // requires two indices, so the final count is twice the original.\n if (primitiveType === PrimitiveType.TRIANGLES) {\n return originalCount * 2;\n }\n\n // For TRIANGLE_STRIP and TRIANGLE_FAN, the number of triangles in the primitive\n // is equal to the total number of vertices minus two. This is because after the\n // first edge is specified by the first two indices, every point afterwards\n // contributes two more edges with two of the previous points, forming a new triangle.\n // Each of these edges requires two indices, so each triangle in the primitive\n // results in four indices in addition to the first two.\n if (\n primitiveType === PrimitiveType.TRIANGLE_STRIP ||\n primitiveType === PrimitiveType.TRIANGLE_FAN\n ) {\n const numberOfTriangles = originalCount - 2;\n return 2 + numberOfTriangles * 4;\n }\n\n return originalCount;\n};\n\nexport default WireframeIndexGenerator;\n", "import Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport defined from \"../../Core/defined.js\";\nimport IndexDatatype from \"../../Core/IndexDatatype.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\nimport WireframeIndexGenerator from \"../../Core/WireframeIndexGenerator.js\";\n\n/**\n * The wireframe pipeline stage generates a new index buffer for rendering the\n * structure of the mesh with gl.LINES.\n *\n * @namespace WireframePipelineStage\n * @private\n */\nconst WireframePipelineStage = {\n name: \"WireframePipelineStage\", // Helps with debugging\n};\n\n/**\n * Process a primitive. This modifies the render resources as follows:\n *
    \n *
  • Adds a define to the fragment shader to prevent extra shading of the lines.
  • \n *
  • Adds a separate index buffer for wireframe indices
  • \n *
  • Updates the primitive type and count for rendering with gl.LINES
  • \n *
\n *\n * @param {PrimitiveRenderResources} renderResources The render resources for this node\n * @param {ModelComponents.primitive} primitive The primitive\n * @param {FrameState} frameState The frame state\n */\nWireframePipelineStage.process = function (\n renderResources,\n primitive,\n frameState\n) {\n // Applying normal mapping to the lines will result in rendering\n // errors on Linux. This define is added to disable normal\n // mapping in the shader.\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addDefine(\n \"HAS_WIREFRAME\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n\n const model = renderResources.model;\n const wireframeIndexBuffer = createWireframeIndexBuffer(\n primitive,\n renderResources.indices,\n frameState\n );\n model._pipelineResources.push(wireframeIndexBuffer);\n renderResources.wireframeIndexBuffer = wireframeIndexBuffer;\n\n // We only need to count memory for the generated buffer. In WebGL 1, the CPU\n // copy of the original indices is already counted in the geometry stage,\n // and in WebGL 2, the CPU copy of the original indices (generated from the\n // data of the original buffer) is discarded after generating the wireframe\n // indices.\n const hasCpuCopy = false;\n model.statistics.addBuffer(wireframeIndexBuffer, hasCpuCopy);\n\n // Update render resources so we render LINES with the correct index count\n const originalPrimitiveType = renderResources.primitiveType;\n const originalCount = renderResources.count;\n renderResources.primitiveType = PrimitiveType.LINES;\n renderResources.count = WireframeIndexGenerator.getWireframeIndicesCount(\n originalPrimitiveType,\n originalCount\n );\n};\n\nfunction createWireframeIndexBuffer(primitive, indices, frameState) {\n const positionAttribute = ModelUtility.getAttributeBySemantic(\n primitive,\n VertexAttributeSemantic.POSITION\n );\n const vertexCount = positionAttribute.count;\n const webgl2 = frameState.context.webgl2;\n\n let originalIndices;\n if (defined(indices)) {\n const indicesBuffer = indices.buffer;\n const indicesCount = indices.count;\n if (defined(indicesBuffer) && webgl2) {\n const useUint8Array = indicesBuffer.sizeInBytes === indicesCount;\n originalIndices = useUint8Array\n ? new Uint8Array(indicesCount)\n : IndexDatatype.createTypedArray(vertexCount, indicesCount);\n\n indicesBuffer.getBufferData(originalIndices);\n } else {\n originalIndices = indices.typedArray;\n }\n }\n\n const primitiveType = primitive.primitiveType;\n const wireframeIndices = WireframeIndexGenerator.createWireframeIndices(\n primitiveType,\n vertexCount,\n originalIndices\n );\n const indexDatatype = IndexDatatype.fromSizeInBytes(\n wireframeIndices.BYTES_PER_ELEMENT\n );\n\n return Buffer.createIndexBuffer({\n context: frameState.context,\n typedArray: wireframeIndices,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: indexDatatype,\n });\n}\n\nexport default WireframePipelineStage;\n", "import Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport AlphaPipelineStage from \"./AlphaPipelineStage.js\";\nimport BatchTexturePipelineStage from \"./BatchTexturePipelineStage.js\";\nimport ClassificationPipelineStage from \"./ClassificationPipelineStage.js\";\nimport CPUStylingPipelineStage from \"./CPUStylingPipelineStage.js\";\nimport CustomShaderMode from \"./CustomShaderMode.js\";\nimport CustomShaderPipelineStage from \"./CustomShaderPipelineStage.js\";\nimport DequantizationPipelineStage from \"./DequantizationPipelineStage.js\";\nimport FeatureIdPipelineStage from \"./FeatureIdPipelineStage.js\";\nimport GeometryPipelineStage from \"./GeometryPipelineStage.js\";\nimport LightingPipelineStage from \"./LightingPipelineStage.js\";\nimport MaterialPipelineStage from \"./MaterialPipelineStage.js\";\nimport MetadataPipelineStage from \"./MetadataPipelineStage.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport MorphTargetsPipelineStage from \"./MorphTargetsPipelineStage.js\";\nimport PickingPipelineStage from \"./PickingPipelineStage.js\";\nimport PointCloudStylingPipelineStage from \"./PointCloudStylingPipelineStage.js\";\nimport PrimitiveOutlinePipelineStage from \"./PrimitiveOutlinePipelineStage.js\";\nimport PrimitiveStatisticsPipelineStage from \"./PrimitiveStatisticsPipelineStage.js\";\nimport SceneMode2DPipelineStage from \"./SceneMode2DPipelineStage.js\";\nimport SelectedFeatureIdPipelineStage from \"./SelectedFeatureIdPipelineStage.js\";\nimport SkinningPipelineStage from \"./SkinningPipelineStage.js\";\nimport WireframePipelineStage from \"./WireframePipelineStage.js\";\n\n/**\n * In memory representation of a single primitive, that is, a primitive\n * and its corresponding mesh.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.Primitive} options.primitive The primitive component.\n * @param {ModelComponents.Node} options.node The node that this primitive belongs to.\n * @param {Model} options.model The {@link Model} this primitive belongs to.\n *\n * @alias ModelRuntimePrimitive\n * @constructor\n *\n * @private\n */\nfunction ModelRuntimePrimitive(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const primitive = options.primitive;\n const node = options.node;\n const model = options.model;\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.primitive\", primitive);\n Check.typeOf.object(\"options.node\", node);\n Check.typeOf.object(\"options.model\", model);\n //>>includeEnd('debug');\n\n /**\n * The primitive component associated with this primitive.\n *\n * @type {ModelComponents.Primitive}\n *\n * @private\n */\n this.primitive = primitive;\n\n /**\n * A reference to the node this primitive belongs to.\n *\n * @type {ModelComponents.Node}\n *\n * @private\n */\n this.node = node;\n\n /**\n * A reference to the model\n *\n * @type {Model}\n *\n * @private\n */\n this.model = model;\n\n /**\n * Pipeline stages to apply to this primitive. This\n * is an array of classes, each with a static method called\n * process()\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.pipelineStages = [];\n\n /**\n * The generated {@link ModelDrawCommand} or {@link ClassificationModelDrawCommand}\n * associated with this primitive.\n *\n * @type {ModelDrawCommand|ClassificationModelDrawCommand}\n *\n * @private\n */\n this.drawCommand = undefined;\n\n /**\n * The bounding sphere of this primitive in object-space.\n *\n * @type {BoundingSphere}\n *\n * @private\n */\n this.boundingSphere = undefined;\n\n /**\n * The bounding sphere of this primitive in 2D world space.\n *\n * @type {BoundingSphere}\n *\n * @private\n */\n this.boundingSphere2D = undefined;\n\n /**\n * A buffer containing the primitive's positions projected to 2D world\n * coordinates. This is generated by SceneMode2DPipelineStage and used for\n * rendering in 2D / CV mode. The memory is managed by Model; this is just\n * a reference.\n *\n * @type {Buffer}\n *\n * @private\n */\n this.positionBuffer2D = undefined;\n\n /**\n * An array containing the lengths of the vertex batches for classification.\n * Vertices with the same feature ID are batched together, and each batch is\n * drawn with a different draw command in order to properly classify other\n * assets.\n *

\n * This is generated by ClassificationPipelineStage. The memory is managed by\n * Model; this is just a reference.\n *

\n *\n * @type {number[]}\n *\n * @private\n */\n this.batchLengths = undefined;\n\n /**\n * An array containing the offsets of the vertex batches for classification.\n * Vertices with the same feature ID are batched together, and each batch is\n * drawn with a different draw command in order to properly classify other\n * assets.\n *

\n * This is generated by ClassificationPipelineStage. The memory is managed by\n * Model; this is just a reference.\n *

\n *\n * @type {number[]}\n *\n * @private\n */\n this.batchOffsets = undefined;\n\n /**\n * Update stages to apply to this primitive.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.updateStages = [];\n}\n\n/**\n * Configure the primitive pipeline stages. If the pipeline needs to be re-run,\n * call this method again to ensure the correct sequence of pipeline stages are\n * used.\n *\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nModelRuntimePrimitive.prototype.configurePipeline = function (frameState) {\n const pipelineStages = this.pipelineStages;\n pipelineStages.length = 0;\n\n const primitive = this.primitive;\n const node = this.node;\n const model = this.model;\n\n const customShader = model.customShader;\n const style = model.style;\n\n const useWebgl2 = frameState.context.webgl2;\n const mode = frameState.mode;\n const use2D =\n mode !== SceneMode.SCENE3D && !frameState.scene3DOnly && model._projectTo2D;\n\n const hasMorphTargets =\n defined(primitive.morphTargets) && primitive.morphTargets.length > 0;\n const hasSkinning = defined(node.skin);\n const hasCustomShader = defined(customShader);\n const hasCustomFragmentShader =\n hasCustomShader && defined(customShader.fragmentShaderText);\n const materialsEnabled =\n !hasCustomFragmentShader ||\n customShader.mode !== CustomShaderMode.REPLACE_MATERIAL;\n const hasQuantization = ModelUtility.hasQuantizedAttributes(\n primitive.attributes\n );\n const generateWireframeIndices =\n model.debugWireframe &&\n PrimitiveType.isTriangles(primitive.primitiveType) &&\n // Generating index buffers for wireframes is always possible in WebGL2.\n // However, this will only work in WebGL1 if the model was constructed with\n // enableDebugWireframe set to true.\n (model._enableDebugWireframe || useWebgl2);\n\n const pointCloudShading = model.pointCloudShading;\n const hasAttenuation =\n defined(pointCloudShading) && pointCloudShading.attenuation;\n const hasPointCloudBackFaceCulling =\n defined(pointCloudShading) && pointCloudShading.backFaceCulling;\n const hasPointCloudStyle =\n primitive.primitiveType === PrimitiveType.POINTS &&\n (defined(style) || hasAttenuation || hasPointCloudBackFaceCulling);\n\n const hasOutlines =\n model._enableShowOutline && defined(primitive.outlineCoordinates);\n\n const featureIdFlags = inspectFeatureIds(model, node, primitive);\n\n const hasClassification = defined(model.classificationType);\n\n // Start of pipeline -----------------------------------------------------\n if (use2D) {\n pipelineStages.push(SceneMode2DPipelineStage);\n }\n\n pipelineStages.push(GeometryPipelineStage);\n\n if (generateWireframeIndices) {\n pipelineStages.push(WireframePipelineStage);\n }\n\n if (hasClassification) {\n pipelineStages.push(ClassificationPipelineStage);\n }\n\n if (hasMorphTargets) {\n pipelineStages.push(MorphTargetsPipelineStage);\n }\n\n if (hasSkinning) {\n pipelineStages.push(SkinningPipelineStage);\n }\n\n if (hasPointCloudStyle) {\n pipelineStages.push(PointCloudStylingPipelineStage);\n }\n\n if (hasQuantization) {\n pipelineStages.push(DequantizationPipelineStage);\n }\n\n if (materialsEnabled) {\n pipelineStages.push(MaterialPipelineStage);\n }\n\n // These stages are always run to ensure structs\n // are declared to avoid compilation errors.\n pipelineStages.push(FeatureIdPipelineStage);\n pipelineStages.push(MetadataPipelineStage);\n\n if (featureIdFlags.hasPropertyTable) {\n pipelineStages.push(SelectedFeatureIdPipelineStage);\n pipelineStages.push(BatchTexturePipelineStage);\n pipelineStages.push(CPUStylingPipelineStage);\n }\n\n if (hasCustomShader) {\n pipelineStages.push(CustomShaderPipelineStage);\n }\n\n pipelineStages.push(LightingPipelineStage);\n\n if (model.allowPicking) {\n pipelineStages.push(PickingPipelineStage);\n }\n\n if (hasOutlines) {\n pipelineStages.push(PrimitiveOutlinePipelineStage);\n }\n\n pipelineStages.push(AlphaPipelineStage);\n\n pipelineStages.push(PrimitiveStatisticsPipelineStage);\n\n return;\n};\n\nfunction inspectFeatureIds(model, node, primitive) {\n let featureIds;\n // Check instances first, as this is the most specific type of\n // feature ID\n if (defined(node.instances)) {\n featureIds = ModelUtility.getFeatureIdsByLabel(\n node.instances.featureIds,\n model.instanceFeatureIdLabel\n );\n\n if (defined(featureIds)) {\n return {\n hasFeatureIds: true,\n hasPropertyTable: defined(featureIds.propertyTableId),\n };\n }\n }\n\n featureIds = ModelUtility.getFeatureIdsByLabel(\n primitive.featureIds,\n model.featureIdLabel\n );\n if (defined(featureIds)) {\n return {\n hasFeatureIds: true,\n hasPropertyTable: defined(featureIds.propertyTableId),\n };\n }\n\n return {\n hasFeatureIds: false,\n hasPropertyTable: false,\n };\n}\n\nexport default ModelRuntimePrimitive;\n", "import Matrix4 from \"../../Core/Matrix4.js\";\nimport Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\n\n/**\n * An in-memory representation of a skin that affects nodes in the {@link ModelSceneGraph}.\n * Skins should only be initialized after all of the {@link ModelRuntimeNode}s have been instantiated\n * by the scene graph.\n *\n * @param {object} options An object containing the following options:\n * @param {ModelComponents.Skin} options.skin The corresponding skin components from the 3D model\n * @param {ModelSceneGraph} options.sceneGraph The scene graph this skin belongs to.\n *\n * @alias ModelSkin\n * @constructor\n *\n * @private\n */\nfunction ModelSkin(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.skin\", options.skin);\n Check.typeOf.object(\"options.sceneGraph\", options.sceneGraph);\n //>>includeEnd('debug');\n\n this._sceneGraph = options.sceneGraph;\n const skin = options.skin;\n\n this._skin = skin;\n\n this._inverseBindMatrices = undefined;\n this._joints = [];\n this._jointMatrices = [];\n\n initialize(this);\n}\n\nObject.defineProperties(ModelSkin.prototype, {\n /**\n * The internal skin this runtime skin represents.\n *\n * @memberof ModelSkin.prototype\n * @type {ModelComponents.Skin}\n * @readonly\n *\n * @private\n */\n skin: {\n get: function () {\n return this._skin;\n },\n },\n\n /**\n * The scene graph this skin belongs to.\n *\n * @memberof ModelSkin.prototype\n * @type {ModelSceneGraph}\n * @readonly\n *\n * @private\n */\n sceneGraph: {\n get: function () {\n return this._sceneGraph;\n },\n },\n\n /**\n * The inverse bind matrices of the skin.\n *\n * @memberof ModelSkin.prototype\n * @type {Matrix4[]}\n * @readonly\n *\n * @private\n */\n inverseBindMatrices: {\n get: function () {\n return this._inverseBindMatrices;\n },\n },\n\n /**\n * The joints of the skin.\n *\n * @memberof ModelSkin.prototype\n * @type {ModelRuntimeNode[]}\n * @readonly\n *\n * @private\n */\n joints: {\n get: function () {\n return this._joints;\n },\n },\n\n /**\n * The joint matrices for the skin, where each joint matrix is computed as\n * jointMatrix = jointWorldTransform * inverseBindMatrix.\n *\n * Each node that references this skin is responsible for pre-multiplying its inverse\n * world transform to the joint matrices for its own use.\n *\n * @memberof ModelSkin.prototype\n * @type {Matrix4[]}\n * @readonly\n *\n * @private\n */\n jointMatrices: {\n get: function () {\n return this._jointMatrices;\n },\n },\n});\n\nfunction initialize(runtimeSkin) {\n const skin = runtimeSkin.skin;\n const inverseBindMatrices = skin.inverseBindMatrices;\n runtimeSkin._inverseBindMatrices = inverseBindMatrices;\n\n const joints = skin.joints;\n const length = joints.length;\n\n const runtimeNodes = runtimeSkin.sceneGraph._runtimeNodes;\n const runtimeJoints = runtimeSkin.joints;\n const runtimeJointMatrices = runtimeSkin._jointMatrices;\n for (let i = 0; i < length; i++) {\n const jointIndex = joints[i].index;\n const runtimeNode = runtimeNodes[jointIndex];\n runtimeJoints.push(runtimeNode);\n\n const inverseBindMatrix = inverseBindMatrices[i];\n const jointMatrix = computeJointMatrix(\n runtimeNode,\n inverseBindMatrix,\n new Matrix4()\n );\n runtimeJointMatrices.push(jointMatrix);\n }\n}\n\nfunction computeJointMatrix(joint, inverseBindMatrix, result) {\n const jointWorldTransform = Matrix4.multiplyTransformation(\n joint.transformToRoot,\n joint.transform,\n result\n );\n\n result = Matrix4.multiplyTransformation(\n jointWorldTransform,\n inverseBindMatrix,\n result\n );\n\n return result;\n}\n\n/**\n * Updates the joint matrices for the skin.\n *\n * @private\n */\nModelSkin.prototype.updateJointMatrices = function () {\n const jointMatrices = this._jointMatrices;\n const length = jointMatrices.length;\n for (let i = 0; i < length; i++) {\n const joint = this.joints[i];\n const inverseBindMatrix = this.inverseBindMatrices[i];\n jointMatrices[i] = computeJointMatrix(\n joint,\n inverseBindMatrix,\n jointMatrices[i]\n );\n }\n};\n\nexport default ModelSkin;\n", "/**\n * Options for configuring the {@link AlphaPipelineStage}\n *\n * @alias ModelAlphaOptions\n * @constructor\n *\n * @private\n */\nfunction ModelAlphaOptions() {\n /**\n * Which render pass will render the model.\n *\n * @type {Pass}\n * @private\n */\n this.pass = undefined;\n /**\n * Determines the alpha threshold below which fragments are discarded\n *\n * @type {number}\n * @private\n */\n this.alphaCutoff = undefined;\n}\n\nexport default ModelAlphaOptions;\n", "import Check from \"../../Core/Check.js\";\nimport ModelAlphaOptions from \"./ModelAlphaOptions.js\";\nimport RenderState from \"../../Renderer/RenderState.js\";\nimport ShaderBuilder from \"../../Renderer/ShaderBuilder.js\";\nimport DepthFunction from \"../DepthFunction.js\";\n\n/**\n * Model render resources are for setting details that are consistent across\n * the entire model.\n *\n * @constructor\n * @param {Model} model The model that will be rendered\n *\n * @private\n */\nfunction ModelRenderResources(model) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"model\", model);\n //>>includeEnd('debug');\n\n /**\n * An object used to build a shader incrementally. Each pipeline stage\n * may add lines of shader code to this object.\n *\n * @type {ShaderBuilder}\n * @readonly\n *\n * @private\n */\n this.shaderBuilder = new ShaderBuilder();\n\n /**\n * A reference to the model.\n *\n * @type {Model}\n * @readonly\n *\n * @private\n */\n this.model = model;\n\n /**\n * A dictionary mapping uniform name to functions that return the uniform\n * values.\n *\n * @type {Object}\n * @readonly\n *\n * @private\n */\n this.uniformMap = {};\n\n /**\n * Options for configuring the alpha stage such as pass and alpha cutoff.\n *\n * @type {ModelAlphaOptions}\n * @readonly\n *\n * @private\n */\n this.alphaOptions = new ModelAlphaOptions();\n\n /**\n * An object storing options for creating a {@link RenderState}.\n * The pipeline stages simply set the options, the render state is created\n * when the {@link DrawCommand} is constructed.\n *\n * @type {object}\n * @readonly\n *\n * @private\n */\n this.renderStateOptions = RenderState.getState(\n RenderState.fromCache({\n depthTest: {\n enabled: true,\n func: DepthFunction.LESS_OR_EQUAL,\n },\n })\n );\n\n /**\n * Whether the model has a silhouette. This value indicates what draw commands\n * are needed and is set by ModelSilhouettePipelineStage.\n *\n * @type {boolean}\n * @default false\n *\n * @private\n */\n this.hasSilhouette = false;\n\n /**\n * Whether the model is part of a tileset that uses the skipLevelOfDetail\n * optimization. This value indicates what draw commands are needed and\n * is set by TilesetPipelineStage.\n *\n * @type {boolean}\n * @default false\n *\n * @private\n */\n this.hasSkipLevelOfDetail = false;\n}\n\nexport default ModelRenderResources;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void silhouetteStage(inout vec4 color) {\\n\\\n if(model_silhouettePass) {\\n\\\n color = czm_gammaCorrect(model_silhouetteColor);\\n\\\n }\\n\\\n}\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void silhouetteStage(in ProcessedAttributes attributes, inout vec4 positionClip) {\\n\\\n #ifdef HAS_NORMALS\\n\\\n if(model_silhouettePass) {\\n\\\n vec3 normal = normalize(czm_normal3D * attributes.normalMC);\\n\\\n normal.x *= czm_projection[0][0];\\n\\\n normal.y *= czm_projection[1][1];\\n\\\n positionClip.xy += normal.xy * positionClip.w * model_silhouetteSize * czm_pixelRatio / czm_viewport.z;\\n\\\n }\\n\\\n #endif\\n\\\n}\\n\\\n\";\n", "import combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\nimport ModelSilhouetteStageFS from \"../../Shaders/Model/ModelSilhouetteStageFS.js\";\nimport ModelSilhouetteStageVS from \"../../Shaders/Model/ModelSilhouetteStageVS.js\";\n\n/**\n * The model silhouette pipeline stage is responsible applying silhouettes to the model.\n *\n * @namespace ModelSilhouettePipelineStage\n *\n * @private\n */\nconst ModelSilhouettePipelineStage = {\n name: \"ModelSilhouettePipelineStage\", // Helps with debugging\n};\n\n/**\n * Tracks how many silhouettes have been created. This value is used to\n * assign a reference number to the stencil.\n *\n * @type {number}\n * @private\n */\nModelSilhouettePipelineStage.silhouettesLength = 0;\n\n/**\n * Process a model. This modifies the following parts of the render resources:\n *\n *
    \n *
  • defines the silhouette ID for the model, if it doesn't yet exist\n *
  • adds a define to the shaders to indicate that the model uses silhouettes
  • \n *
  • adds a function to the vertex shader to create the silhouette around the model
  • \n *
  • adds a function to the fragment shader to apply color to the silhouette
  • \n *
  • adds the uniforms to the shaders for the corresponding silhouette properties
  • \n *
  • adds a uniform to distinguish which draw command is used to render the silhouette
  • \n *
  • sets a variable in the render resources denoting whether the model has a silhouette
  • \n *
\n *\n *

\n * Note that the model must have a normal attribute in order to use silhouettes. The flag for this is\n * added to the shader in GeometryPipelineStage.\n *

\n *\n * @param {ModelRenderResources} renderResources The render resources for this model.\n * @param {Model} model The model.\n * @param {FrameState} frameState The frameState.\n *\n * @private\n */\nModelSilhouettePipelineStage.process = function (\n renderResources,\n model,\n frameState\n) {\n if (!defined(model._silhouetteId)) {\n model._silhouetteId = ++ModelSilhouettePipelineStage.silhouettesLength;\n }\n\n const shaderBuilder = renderResources.shaderBuilder;\n shaderBuilder.addDefine(\"HAS_SILHOUETTE\", undefined, ShaderDestination.BOTH);\n\n shaderBuilder.addVertexLines(ModelSilhouetteStageVS);\n shaderBuilder.addFragmentLines(ModelSilhouetteStageFS);\n\n shaderBuilder.addUniform(\n \"vec4\",\n \"model_silhouetteColor\",\n ShaderDestination.FRAGMENT\n );\n\n shaderBuilder.addUniform(\n \"float\",\n \"model_silhouetteSize\",\n ShaderDestination.VERTEX\n );\n\n // Rendering silhouettes requires two draw commands:\n // - First, the model is rendered as normal, writing to the stencil buffer.\n // - Second, the silhouette is drawn, and the stencil buffer is used to cutout\n // the part that overlaps the regular model.\n //\n // To avoid creating a second shader program to handle silhouettes, a uniform\n // is used to distinguish between the two draw commands. The second command will set\n // this uniform true, such that only it applies the silhouette stage.\n shaderBuilder.addUniform(\n \"bool\",\n \"model_silhouettePass\",\n ShaderDestination.BOTH\n );\n\n const uniformMap = {\n model_silhouetteColor: function () {\n return model.silhouetteColor;\n },\n model_silhouetteSize: function () {\n return model.silhouetteSize;\n },\n model_silhouettePass: function () {\n // This will be set to true by the draw command that draws the silhouette.\n return false;\n },\n };\n\n renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);\n renderResources.hasSilhouette = true;\n};\n\nexport default ModelSilhouettePipelineStage;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"void modelSplitterStage()\\n\\\n{\\n\\\n // Don't split when rendering the shadow map, because it is rendered from\\n\\\n // the perspective of a totally different camera.\\n\\\n#ifndef SHADOW_MAP\\n\\\n if (model_splitDirection < 0.0 && gl_FragCoord.x > czm_splitPosition) discard;\\n\\\n if (model_splitDirection > 0.0 && gl_FragCoord.x < czm_splitPosition) discard;\\n\\\n#endif\\n\\\n}\\n\\\n\";\n", "import combine from \"../../Core/combine.js\";\nimport ModelSplitterStageFS from \"../../Shaders/Model/ModelSplitterStageFS.js\";\nimport ShaderDestination from \"../../Renderer/ShaderDestination.js\";\n\n/**\n * The model splitting pipeline stage is responsible for discarding fragments on the wrong side of the splitter.\n *\n * @namespace ModelSplitterPipelineStage\n *\n * @private\n */\nconst ModelSplitterPipelineStage = {\n name: \"ModelSplitterPipelineStage\", // Helps with debugging\n\n SPLIT_DIRECTION_UNIFORM_NAME: \"model_splitDirection\",\n};\n\n/**\n * Process a model. This modifies the following parts of the render resources:\n *\n *
    \n *
  • adds a define to the fragment shader to indicate that the model is split
  • \n *
  • adds a function to the fragment shader to discard the fragment if it's on the wrong side of the splitter.
  • \n *
  • adds a uniform indicating the \"splitDirection\" (side of the screen on which to show the model)\n *
\n *\n * @param {ModelRenderResources} renderResources The render resources for this model.\n * @param {Model} model The model.\n * @param {FrameState} frameState The frameState.\n *\n * @private\n */\nModelSplitterPipelineStage.process = function (\n renderResources,\n model,\n frameState\n) {\n const shaderBuilder = renderResources.shaderBuilder;\n\n shaderBuilder.addDefine(\n \"HAS_MODEL_SPLITTER\",\n undefined,\n ShaderDestination.FRAGMENT\n );\n shaderBuilder.addFragmentLines(ModelSplitterStageFS);\n\n const stageUniforms = {};\n\n shaderBuilder.addUniform(\n \"float\",\n ModelSplitterPipelineStage.SPLIT_DIRECTION_UNIFORM_NAME,\n ShaderDestination.FRAGMENT\n );\n stageUniforms[\n ModelSplitterPipelineStage.SPLIT_DIRECTION_UNIFORM_NAME\n ] = function () {\n return model.splitDirection;\n };\n\n renderResources.uniformMap = combine(\n stageUniforms,\n renderResources.uniformMap\n );\n};\n\nexport default ModelSplitterPipelineStage;\n", "import Check from \"../../Core/Check.js\";\nimport clone from \"../../Core/clone.js\";\n\n/**\n * A model is made up of one or more nodes in the scene graph. Some details\n * such as instancing are computed on a per-node basis. This class provides\n * a place to store such details. It also inherits some properties from\n * the model render resources.\n *\n * @constructor\n *\n * @param {ModelRenderResources} modelRenderResources The model resources to inherit\n * @param {ModelRuntimeNode} runtimeNode The in-memory representation of the scene graph node.\n *\n * @private\n */\nfunction NodeRenderResources(modelRenderResources, runtimeNode) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"modelRenderResources\", modelRenderResources);\n Check.typeOf.object(\"runtimeNode\", runtimeNode);\n //>>includeEnd('debug');\n\n // Properties inherited from the ModelRenderResources.\n /**\n * A reference to the model. Inherited from the model render resources.\n *\n * @type {Model}\n * @readonly\n *\n * @private\n */\n this.model = modelRenderResources.model;\n /**\n * An object used to build a shader incrementally. This is cloned from the\n * model render resources because each node can compute a different shader.\n *\n * @type {ShaderBuilder}\n * @readonly\n *\n * @private\n */\n this.shaderBuilder = modelRenderResources.shaderBuilder.clone();\n\n /**\n * A dictionary mapping uniform name to functions that return the uniform\n * values. Inherited from the model render resources.\n *\n * @type {Object}\n * @readonly\n *\n * @private\n */\n this.uniformMap = clone(modelRenderResources.uniformMap);\n\n /**\n * Options for configuring the alpha stage such as pass and alpha cutoff.\n * Inherited from the model render resources.\n *\n * @type {ModelAlphaOptions}\n * @readonly\n *\n * @private\n */\n this.alphaOptions = clone(modelRenderResources.alphaOptions);\n\n /**\n * An object storing options for creating a {@link RenderState}.\n * The pipeline stages simply set the options, the render state is created\n * when the {@link DrawCommand} is constructed. Inherited from the model\n * render resources.\n *\n * @type {object}\n * @readonly\n *\n * @private\n */\n this.renderStateOptions = clone(\n modelRenderResources.renderStateOptions,\n true\n );\n\n /**\n * Whether the model has a silhouette. This value indicates what draw commands\n * are needed. Inherited from the model render resources.\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasSilhouette = modelRenderResources.hasSilhouette;\n\n /**\n * Whether the model is part of a tileset that uses the skipLevelOfDetail\n * optimization. This value indicates what draw commands are needed.\n * Inherited from the model render resources.\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasSkipLevelOfDetail = modelRenderResources.hasSkipLevelOfDetail;\n\n // Other properties.\n /**\n * A reference to the runtime node\n *\n * @type {ModelRuntimeNode}\n * @readonly\n *\n * @private\n */\n this.runtimeNode = runtimeNode;\n\n /**\n * An array of objects describing vertex attributes that will eventually\n * be used to create a {@link VertexArray} for the draw command. Attributes\n * at the node level may be needed for extensions such as EXT_mesh_gpu_instancing.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.attributes = [];\n\n /**\n * The index to give to the next vertex attribute added to the attributes array.\n * POSITION takes index 0.\n *\n * @type {number}\n *\n * @private\n */\n this.attributeIndex = 1;\n\n /**\n * The set index to assign to feature ID vertex attribute(s) created from the\n * offset/repeat in the feature ID attribute.\n *\n * @type {number}\n * @default 0\n *\n * @private\n */\n this.featureIdVertexAttributeSetIndex = 0;\n\n /**\n * The number of instances. This value is set by InstancingPipelineStage.\n *\n * @type {number}\n * @default 0\n *\n * @private\n */\n this.instanceCount = 0;\n}\n\nexport default NodeRenderResources;\n", "import defaultValue from \"../../Core/defaultValue.js\";\nimport LightingModel from \"./LightingModel.js\";\n\n/**\n * Options for configuring the {@link LightingPipelineStage}\n *\n * @param {object} options An object containing the following options\n * @param {LightingModel} [options.lightingModel=LightingModel.UNLIT] The lighting model to use\n *\n * @alias ModelLightingOptions\n * @constructor\n *\n * @private\n */\nfunction ModelLightingOptions(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * The lighting model to use, such as UNLIT or PBR. This is determined by\n * the primitive's material.\n *\n * @type {LightingModel}\n *\n * @private\n */\n this.lightingModel = defaultValue(options.lightingModel, LightingModel.UNLIT);\n}\n\nexport default ModelLightingOptions;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport clone from \"../../Core/clone.js\";\nimport defined from \"../../Core/defined.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport ModelLightingOptions from \"./ModelLightingOptions.js\";\n\n/**\n * Each node may have many mesh primitives. Most model pipeline stages operate\n * at the primitive level. Again, properties are inherited from the parent.\n *\n * @param {NodeRenderResources} nodeRenderResources The node resources to inherit from\n * @param {ModelRuntimePrimitive} runtimePrimitive The primitive.\n *\n * @private\n */\nfunction PrimitiveRenderResources(nodeRenderResources, runtimePrimitive) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"nodeRenderResources\", nodeRenderResources);\n Check.typeOf.object(\"runtimePrimitive\", runtimePrimitive);\n //>>includeEnd('debug');\n\n // Properties inherited from NodeRenderResources.\n /**\n * A reference to the model. Inherited from the node render resources.\n *\n * @type {Model}\n * @readonly\n *\n * @private\n */\n this.model = nodeRenderResources.model;\n\n /**\n * A reference to the runtime node. Inherited from the node render resources.\n *\n * @type {ModelRuntimeNode}\n * @readonly\n *\n * @private\n */\n this.runtimeNode = nodeRenderResources.runtimeNode;\n\n /**\n * The vertex attributes. This is shallow cloned from the node render\n * resources as the primitive will add additional properties.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.attributes = nodeRenderResources.attributes.slice();\n\n /**\n * The index to give to the next vertex attribute added to the attributes\n * array. POSITION takes index 0. Inherited from the node render resources.\n *\n * @type {number}\n *\n * @private\n */\n this.attributeIndex = nodeRenderResources.attributeIndex;\n\n /**\n * The set index to assign to feature ID vertex attribute(s) created from the\n * offset/repeat in the feature ID attribute. Inherited from the node render\n * resources.\n *\n * @type {number}\n *\n * @private\n */\n this.featureIdVertexAttributeSetIndex =\n nodeRenderResources.featureIdVertexAttributeSetIndex;\n\n /**\n * A dictionary mapping uniform name to functions that return the uniform\n * values. Inherited from the node render resources.\n *\n * @type {Object}\n * @readonly\n *\n * @private\n */\n this.uniformMap = clone(nodeRenderResources.uniformMap);\n\n /**\n * Options for configuring the alpha stage such as pass and alpha cutoff.\n * Inherited from the node render resources.\n *\n * @type {ModelAlphaOptions}\n * @readonly\n *\n * @private\n */\n this.alphaOptions = clone(nodeRenderResources.alphaOptions);\n\n /**\n * An object storing options for creating a {@link RenderState}.\n * The pipeline stages simply set the options; the actual render state\n * is created when the {@link DrawCommand} is constructed. Inherited from\n * the node render resources.\n *\n * @type {object}\n * @readonly\n *\n * @private\n */\n this.renderStateOptions = clone(nodeRenderResources.renderStateOptions, true);\n\n /**\n * Whether the model has a silhouette. This value indicates what draw commands\n * are needed. Inherited from the node render resources.\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasSilhouette = nodeRenderResources.hasSilhouette;\n\n /**\n * Whether the model is part of a tileset that uses the skipLevelOfDetail\n * optimization. This value indicates what draw commands are needed.\n * Inherited from the node render resources.\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasSkipLevelOfDetail = nodeRenderResources.hasSkipLevelOfDetail;\n\n /**\n * An object used to build a shader incrementally. This is cloned from the\n * node render resources because each primitive can compute a different shader.\n *\n * @type {ShaderBuilder}\n * @readonly\n *\n * @private\n */\n this.shaderBuilder = nodeRenderResources.shaderBuilder.clone();\n\n /**\n * The number of instances. Default is 0, if instancing is not used.\n * Inherited from the node render resources.\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n this.instanceCount = nodeRenderResources.instanceCount;\n\n // Other properties\n /**\n * A reference to the runtime primitive.\n *\n * @type {ModelRuntimePrimitive}\n * @readonly\n *\n * @private\n */\n this.runtimePrimitive = runtimePrimitive;\n\n /**\n * The primitive associated with the render resources.\n *\n * @type {ModelComponents.Primitive}\n * @readonly\n *\n * @private\n */\n const primitive = runtimePrimitive.primitive;\n\n /**\n * The number of indices in the primitive. The interpretation of this\n * depends on the primitive type.\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n this.count = defined(primitive.indices)\n ? primitive.indices.count\n : ModelUtility.getAttributeBySemantic(primitive, \"POSITION\").count;\n\n /**\n * Whether or not this primitive has a property table for storing metadata.\n * When present, picking and styling can use this. This value is set by\n * SelectedFeatureIdPipelineStage.\n *\n * @type {boolean}\n * @default false\n *\n * @private\n */\n this.hasPropertyTable = false;\n\n /**\n * The indices for this primitive.\n *\n * @type {ModelComponents.Indices}\n * @readonly\n *\n * @private\n */\n this.indices = primitive.indices;\n\n /**\n * Additional index buffer for wireframe mode (if enabled). This value is set\n * by WireframePipelineStage.\n *\n * @type {Buffer}\n * @readonly\n *\n * @private\n */\n this.wireframeIndexBuffer = undefined;\n\n /**\n * The primitive type such as TRIANGLES or POINTS.\n *\n * @type {PrimitiveType}\n * @readonly\n *\n * @private\n */\n this.primitiveType = primitive.primitiveType;\n\n const positionMinMax = ModelUtility.getPositionMinMax(\n primitive,\n this.runtimeNode.instancingTranslationMin,\n this.runtimeNode.instancingTranslationMax\n );\n\n /**\n * The minimum position value for this primitive.\n *\n * @type {Cartesian3}\n * @readonly\n *\n * @private\n */\n this.positionMin = Cartesian3.clone(positionMinMax.min, new Cartesian3());\n\n /**\n * The maximum position value for this primitive.\n *\n * @type {Cartesian3}\n * @readonly\n *\n * @private\n */\n this.positionMax = Cartesian3.clone(positionMinMax.max, new Cartesian3());\n\n /**\n * The bounding sphere that contains all the vertices in this primitive.\n *\n * @type {BoundingSphere}\n * @readonly\n *\n * @private\n */\n this.boundingSphere = BoundingSphere.fromCornerPoints(\n this.positionMin,\n this.positionMax,\n new BoundingSphere()\n );\n\n /**\n * Options for configuring the lighting stage, such as selecting between\n * unlit and PBR shading.\n *\n * @type {ModelLightingOptions}\n * @readonly\n *\n * @private\n */\n this.lightingOptions = new ModelLightingOptions();\n\n /**\n * The shader variable to use for picking. If picking is enabled, this value\n * is set by PickingPipelineStage.\n *\n * @type {string}\n *\n * @private\n */\n this.pickId = undefined;\n}\n\nexport default PrimitiveRenderResources;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Check from \"../../Core/Check.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Transforms from \"../../Core/Transforms.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport SplitDirection from \"../SplitDirection.js\";\nimport buildDrawCommand from \"./buildDrawCommand.js\";\nimport TilesetPipelineStage from \"./TilesetPipelineStage.js\";\nimport ImageBasedLightingPipelineStage from \"./ImageBasedLightingPipelineStage.js\";\nimport ModelArticulation from \"./ModelArticulation.js\";\nimport ModelColorPipelineStage from \"./ModelColorPipelineStage.js\";\nimport ModelClippingPlanesPipelineStage from \"./ModelClippingPlanesPipelineStage.js\";\nimport ModelNode from \"./ModelNode.js\";\nimport ModelRuntimeNode from \"./ModelRuntimeNode.js\";\nimport ModelRuntimePrimitive from \"./ModelRuntimePrimitive.js\";\nimport ModelSkin from \"./ModelSkin.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport ModelRenderResources from \"./ModelRenderResources.js\";\nimport ModelSilhouettePipelineStage from \"./ModelSilhouettePipelineStage.js\";\nimport ModelSplitterPipelineStage from \"./ModelSplitterPipelineStage.js\";\nimport ModelType from \"./ModelType.js\";\nimport NodeRenderResources from \"./NodeRenderResources.js\";\nimport PrimitiveRenderResources from \"./PrimitiveRenderResources.js\";\n\n/**\n * An in memory representation of the scene graph for a {@link Model}\n *\n * @param {object} options An object containing the following options\n * @param {Model} options.model The model this scene graph belongs to\n * @param {ModelComponents} options.modelComponents The model components describing the model\n *\n * @alias ModelSceneGraph\n * @constructor\n *\n * @private\n */\nfunction ModelSceneGraph(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const components = options.modelComponents;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.model\", options.model);\n Check.typeOf.object(\"options.modelComponents\", components);\n //>>includeEnd('debug');\n\n /**\n * A reference to the {@link Model} that owns this scene graph.\n *\n * @type {Model}\n * @readonly\n *\n * @private\n */\n this._model = options.model;\n\n /**\n * The model components that represent the contents of the 3D model file.\n *\n * @type {ModelComponents}\n * @readonly\n *\n * @private\n */\n this._components = components;\n\n /**\n * Pipeline stages to apply across the model.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this._pipelineStages = [];\n\n /**\n * Update stages to apply across the model.\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this._updateStages = [];\n\n /**\n * The runtime nodes that make up the scene graph\n *\n * @type {ModelRuntimeNode[]}\n * @readonly\n *\n * @private\n */\n this._runtimeNodes = [];\n\n /**\n * The indices of the root nodes in the runtime nodes array.\n *\n * @type {number[]}\n * @readonly\n *\n * @private\n */\n this._rootNodes = [];\n\n /**\n * The indices of the skinned nodes in the runtime nodes array. These refer\n * to the nodes that will be manipulated by their skin, as opposed to the nodes\n * acting as joints for the skin.\n *\n * @type {number[]}\n * @readonly\n *\n * @private\n */\n this._skinnedNodes = [];\n\n /**\n * The runtime skins that affect nodes in the scene graph.\n *\n * @type {ModelSkin[]}\n * @readonly\n *\n * @private\n */\n this._runtimeSkins = [];\n\n /**\n * Pipeline stages to apply to this model. This\n * is an array of classes, each with a static method called\n * process()\n *\n * @type {Object[]}\n * @readonly\n *\n * @private\n */\n this.modelPipelineStages = [];\n\n // The scene graph's bounding sphere is model space, so that\n // the model's bounding sphere can be recomputed when given a\n // new model matrix.\n this._boundingSphere = undefined;\n\n // The 2D bounding sphere is in world space. This is checked\n // by the draw commands to see if the model is over the IDL,\n // and if so, renders the primitives using extra commands.\n this._boundingSphere2D = undefined;\n\n this._computedModelMatrix = Matrix4.clone(Matrix4.IDENTITY);\n this._computedModelMatrix2D = Matrix4.clone(Matrix4.IDENTITY);\n\n this._axisCorrectionMatrix = ModelUtility.getAxisCorrectionMatrix(\n components.upAxis,\n components.forwardAxis,\n new Matrix4()\n );\n\n // Store articulations from the AGI_articulations extension\n // by name in a dictionary for easy retrieval.\n this._runtimeArticulations = {};\n\n initialize(this);\n}\n\nObject.defineProperties(ModelSceneGraph.prototype, {\n /**\n * The model components this scene graph represents.\n *\n * @type {ModelComponents}\n * @readonly\n *\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n\n /**\n * The axis-corrected model matrix.\n *\n * @type {Matrix4}\n * @readonly\n *\n * @private\n */\n computedModelMatrix: {\n get: function () {\n return this._computedModelMatrix;\n },\n },\n\n /**\n * A matrix to correct from y-up in some model formats (e.g. glTF) to the\n * z-up coordinate system Cesium uses.\n *\n * @type {Matrix4}\n * @readonly\n *\n * @private\n */\n axisCorrectionMatrix: {\n get: function () {\n return this._axisCorrectionMatrix;\n },\n },\n\n /**\n * The bounding sphere containing all the primitives in the scene graph\n * in model space.\n *\n * @type {BoundingSphere}\n * @readonly\n *\n * @private\n */\n boundingSphere: {\n get: function () {\n return this._boundingSphere;\n },\n },\n});\n\nfunction initialize(sceneGraph) {\n const components = sceneGraph._components;\n const scene = components.scene;\n const model = sceneGraph._model;\n\n // If the model has a height reference that modifies the model matrix,\n // it will be accounted for in updateModelMatrix.\n const modelMatrix = model.modelMatrix;\n computeModelMatrix(sceneGraph, modelMatrix);\n\n const articulations = components.articulations;\n const articulationsLength = articulations.length;\n\n const runtimeArticulations = sceneGraph._runtimeArticulations;\n for (let i = 0; i < articulationsLength; i++) {\n const articulation = articulations[i];\n const runtimeArticulation = new ModelArticulation({\n articulation: articulation,\n sceneGraph: sceneGraph,\n });\n\n const name = runtimeArticulation.name;\n runtimeArticulations[name] = runtimeArticulation;\n }\n\n const nodes = components.nodes;\n const nodesLength = nodes.length;\n\n // Initialize this array to be the same size as the nodes array in\n // the model file. This is so the node indices remain the same. However,\n // only nodes reachable from the scene's root node will be populated, the\n // rest will be undefined\n sceneGraph._runtimeNodes = new Array(nodesLength);\n\n const rootNodes = scene.nodes;\n const rootNodesLength = rootNodes.length;\n const transformToRoot = Matrix4.IDENTITY;\n for (let i = 0; i < rootNodesLength; i++) {\n const rootNode = scene.nodes[i];\n\n const rootNodeIndex = traverseAndCreateSceneGraph(\n sceneGraph,\n rootNode,\n transformToRoot\n );\n\n sceneGraph._rootNodes.push(rootNodeIndex);\n }\n\n // Handle skins after all runtime nodes are created\n const skins = components.skins;\n const runtimeSkins = sceneGraph._runtimeSkins;\n\n const skinsLength = skins.length;\n for (let i = 0; i < skinsLength; i++) {\n const skin = skins[i];\n runtimeSkins.push(\n new ModelSkin({\n skin: skin,\n sceneGraph: sceneGraph,\n })\n );\n }\n\n const skinnedNodes = sceneGraph._skinnedNodes;\n const skinnedNodesLength = skinnedNodes.length;\n for (let i = 0; i < skinnedNodesLength; i++) {\n const skinnedNodeIndex = skinnedNodes[i];\n const skinnedNode = sceneGraph._runtimeNodes[skinnedNodeIndex];\n\n // Use the index of the skin in the model components to find\n // the corresponding runtime skin.\n const skin = nodes[skinnedNodeIndex].skin;\n const skinIndex = skin.index;\n\n skinnedNode._runtimeSkin = runtimeSkins[skinIndex];\n skinnedNode.updateJointMatrices();\n }\n\n // Ensure articulations are applied with their initial values to their target nodes.\n sceneGraph.applyArticulations();\n}\n\nfunction computeModelMatrix(sceneGraph, modelMatrix) {\n const components = sceneGraph._components;\n const model = sceneGraph._model;\n\n sceneGraph._computedModelMatrix = Matrix4.multiplyTransformation(\n modelMatrix,\n components.transform,\n sceneGraph._computedModelMatrix\n );\n\n sceneGraph._computedModelMatrix = Matrix4.multiplyTransformation(\n sceneGraph._computedModelMatrix,\n sceneGraph._axisCorrectionMatrix,\n sceneGraph._computedModelMatrix\n );\n\n sceneGraph._computedModelMatrix = Matrix4.multiplyByUniformScale(\n sceneGraph._computedModelMatrix,\n model.computedScale,\n sceneGraph._computedModelMatrix\n );\n}\n\nconst scratchComputedTranslation = new Cartesian3();\n\nfunction computeModelMatrix2D(sceneGraph, frameState) {\n const computedModelMatrix = sceneGraph._computedModelMatrix;\n const translation = Matrix4.getTranslation(\n computedModelMatrix,\n scratchComputedTranslation\n );\n\n if (!Cartesian3.equals(translation, Cartesian3.ZERO)) {\n sceneGraph._computedModelMatrix2D = Transforms.basisTo2D(\n frameState.mapProjection,\n computedModelMatrix,\n sceneGraph._computedModelMatrix2D\n );\n } else {\n const center = sceneGraph.boundingSphere.center;\n const to2D = Transforms.wgs84To2DModelMatrix(\n frameState.mapProjection,\n center,\n sceneGraph._computedModelMatrix2D\n );\n sceneGraph._computedModelMatrix2D = Matrix4.multiply(\n to2D,\n computedModelMatrix,\n sceneGraph._computedModelMatrix2D\n );\n }\n\n sceneGraph._boundingSphere2D = BoundingSphere.transform(\n sceneGraph._boundingSphere,\n sceneGraph._computedModelMatrix2D,\n sceneGraph._boundingSphere2D\n );\n}\n\n/**\n * Recursively traverse through the nodes in the scene graph to create\n * their runtime versions, using a post-order depth-first traversal.\n *\n * @param {ModelSceneGraph} sceneGraph The scene graph\n * @param {ModelComponents.Node} node The current node\n * @param {Matrix4} transformToRoot The transforms of this node's ancestors.\n * @returns {number} The index of this node in the runtimeNodes array.\n *\n * @private\n */\nfunction traverseAndCreateSceneGraph(sceneGraph, node, transformToRoot) {\n // The indices of the children of this node in the runtimeNodes array.\n const childrenIndices = [];\n const transform = ModelUtility.getNodeTransform(node);\n\n // Traverse through scene graph.\n const childrenLength = node.children.length;\n for (let i = 0; i < childrenLength; i++) {\n const childNode = node.children[i];\n const childNodeTransformToRoot = Matrix4.multiplyTransformation(\n transformToRoot,\n transform,\n new Matrix4()\n );\n\n const childIndex = traverseAndCreateSceneGraph(\n sceneGraph,\n childNode,\n childNodeTransformToRoot\n );\n childrenIndices.push(childIndex);\n }\n\n // Process node and mesh primitives.\n const runtimeNode = new ModelRuntimeNode({\n node: node,\n transform: transform,\n transformToRoot: transformToRoot,\n children: childrenIndices,\n sceneGraph: sceneGraph,\n });\n\n const primitivesLength = node.primitives.length;\n for (let i = 0; i < primitivesLength; i++) {\n runtimeNode.runtimePrimitives.push(\n new ModelRuntimePrimitive({\n primitive: node.primitives[i],\n node: node,\n model: sceneGraph._model,\n })\n );\n }\n\n const index = node.index;\n sceneGraph._runtimeNodes[index] = runtimeNode;\n if (defined(node.skin)) {\n sceneGraph._skinnedNodes.push(index);\n }\n\n // Create and store the public version of the runtime node.\n const name = node.name;\n if (defined(name)) {\n const model = sceneGraph._model;\n const publicNode = new ModelNode(model, runtimeNode);\n model._nodesByName[name] = publicNode;\n }\n\n return index;\n}\n\nconst scratchModelPositionMin = new Cartesian3();\nconst scratchModelPositionMax = new Cartesian3();\nconst scratchPrimitivePositionMin = new Cartesian3();\nconst scratchPrimitivePositionMax = new Cartesian3();\n/**\n * Generates the {@link ModelDrawCommand} for each primitive in the model.\n * If the model is used for classification, a {@link ClassificationModelDrawCommand}\n * is generated for each primitive instead.\n *\n * @param {FrameState} frameState The current frame state. This is needed to\n * allocate GPU resources as needed.\n *\n * @private\n */\nModelSceneGraph.prototype.buildDrawCommands = function (frameState) {\n const model = this._model;\n const modelRenderResources = new ModelRenderResources(model);\n\n // Reset the memory counts before running the pipeline\n model.statistics.clear();\n\n this.configurePipeline(frameState);\n const modelPipelineStages = this.modelPipelineStages;\n\n let i, j, k;\n for (i = 0; i < modelPipelineStages.length; i++) {\n const modelPipelineStage = modelPipelineStages[i];\n modelPipelineStage.process(modelRenderResources, model, frameState);\n }\n\n const modelPositionMin = Cartesian3.fromElements(\n Number.MAX_VALUE,\n Number.MAX_VALUE,\n Number.MAX_VALUE,\n scratchModelPositionMin\n );\n const modelPositionMax = Cartesian3.fromElements(\n -Number.MAX_VALUE,\n -Number.MAX_VALUE,\n -Number.MAX_VALUE,\n scratchModelPositionMax\n );\n\n for (i = 0; i < this._runtimeNodes.length; i++) {\n const runtimeNode = this._runtimeNodes[i];\n\n // If a node in the model was unreachable from the scene graph, there will\n // be no corresponding runtime node and therefore should be skipped.\n if (!defined(runtimeNode)) {\n continue;\n }\n\n runtimeNode.configurePipeline();\n const nodePipelineStages = runtimeNode.pipelineStages;\n\n const nodeRenderResources = new NodeRenderResources(\n modelRenderResources,\n runtimeNode\n );\n\n for (j = 0; j < nodePipelineStages.length; j++) {\n const nodePipelineStage = nodePipelineStages[j];\n\n nodePipelineStage.process(\n nodeRenderResources,\n runtimeNode.node,\n frameState\n );\n }\n\n const nodeTransform = runtimeNode.computedTransform;\n for (j = 0; j < runtimeNode.runtimePrimitives.length; j++) {\n const runtimePrimitive = runtimeNode.runtimePrimitives[j];\n\n runtimePrimitive.configurePipeline(frameState);\n const primitivePipelineStages = runtimePrimitive.pipelineStages;\n\n const primitiveRenderResources = new PrimitiveRenderResources(\n nodeRenderResources,\n runtimePrimitive\n );\n\n for (k = 0; k < primitivePipelineStages.length; k++) {\n const primitivePipelineStage = primitivePipelineStages[k];\n\n primitivePipelineStage.process(\n primitiveRenderResources,\n runtimePrimitive.primitive,\n frameState\n );\n }\n\n runtimePrimitive.boundingSphere = BoundingSphere.clone(\n primitiveRenderResources.boundingSphere,\n new BoundingSphere()\n );\n\n const primitivePositionMin = Matrix4.multiplyByPoint(\n nodeTransform,\n primitiveRenderResources.positionMin,\n scratchPrimitivePositionMin\n );\n const primitivePositionMax = Matrix4.multiplyByPoint(\n nodeTransform,\n primitiveRenderResources.positionMax,\n scratchPrimitivePositionMax\n );\n\n Cartesian3.minimumByComponent(\n modelPositionMin,\n primitivePositionMin,\n modelPositionMin\n );\n Cartesian3.maximumByComponent(\n modelPositionMax,\n primitivePositionMax,\n modelPositionMax\n );\n\n const drawCommand = buildDrawCommand(\n primitiveRenderResources,\n frameState\n );\n runtimePrimitive.drawCommand = drawCommand;\n }\n }\n\n this._boundingSphere = BoundingSphere.fromCornerPoints(\n modelPositionMin,\n modelPositionMax,\n new BoundingSphere()\n );\n\n this._boundingSphere = BoundingSphere.transformWithoutScale(\n this._boundingSphere,\n this._axisCorrectionMatrix,\n this._boundingSphere\n );\n\n this._boundingSphere = BoundingSphere.transform(\n this._boundingSphere,\n this._components.transform,\n this._boundingSphere\n );\n\n model._boundingSphere = BoundingSphere.transform(\n this._boundingSphere,\n model.modelMatrix,\n model._boundingSphere\n );\n\n model._initialRadius = model._boundingSphere.radius;\n model._boundingSphere.radius *= model._clampedScale;\n};\n\n/**\n * Configure the model pipeline stages. If the pipeline needs to be re-run, call\n * this method again to ensure the correct sequence of pipeline stages are\n * used.\n *\n * @private\n */\nModelSceneGraph.prototype.configurePipeline = function (frameState) {\n const modelPipelineStages = this.modelPipelineStages;\n modelPipelineStages.length = 0;\n\n const model = this._model;\n\n if (defined(model.color)) {\n modelPipelineStages.push(ModelColorPipelineStage);\n }\n\n // Skip these pipeline stages for classification models.\n if (defined(model.classificationType)) {\n return;\n }\n\n if (model.imageBasedLighting.enabled) {\n modelPipelineStages.push(ImageBasedLightingPipelineStage);\n }\n\n if (model.isClippingEnabled()) {\n modelPipelineStages.push(ModelClippingPlanesPipelineStage);\n }\n\n if (model.hasSilhouette(frameState)) {\n modelPipelineStages.push(ModelSilhouettePipelineStage);\n }\n\n if (\n defined(model.splitDirection) &&\n model.splitDirection !== SplitDirection.NONE\n ) {\n modelPipelineStages.push(ModelSplitterPipelineStage);\n }\n\n if (ModelType.is3DTiles(model.type)) {\n modelPipelineStages.push(TilesetPipelineStage);\n }\n};\n\nModelSceneGraph.prototype.update = function (frameState, updateForAnimations) {\n let i, j, k;\n\n for (i = 0; i < this._runtimeNodes.length; i++) {\n const runtimeNode = this._runtimeNodes[i];\n\n // If a node in the model was unreachable from the scene graph, there will\n // be no corresponding runtime node and therefore should be skipped.\n if (!defined(runtimeNode)) {\n continue;\n }\n\n for (j = 0; j < runtimeNode.updateStages.length; j++) {\n const nodeUpdateStage = runtimeNode.updateStages[j];\n nodeUpdateStage.update(runtimeNode, this, frameState);\n }\n\n const disableAnimations =\n frameState.mode !== SceneMode.SCENE3D && this._model._projectTo2D;\n if (updateForAnimations && !disableAnimations) {\n this.updateJointMatrices();\n }\n\n for (j = 0; j < runtimeNode.runtimePrimitives.length; j++) {\n const runtimePrimitive = runtimeNode.runtimePrimitives[j];\n for (k = 0; k < runtimePrimitive.updateStages.length; k++) {\n const stage = runtimePrimitive.updateStages[k];\n stage.update(runtimePrimitive, this);\n }\n }\n }\n};\n\nModelSceneGraph.prototype.updateModelMatrix = function (\n modelMatrix,\n frameState\n) {\n computeModelMatrix(this, modelMatrix);\n if (frameState.mode !== SceneMode.SCENE3D) {\n computeModelMatrix2D(this, frameState);\n }\n\n // Mark all root nodes as dirty. Any and all children will be\n // affected recursively in the update stage.\n const rootNodes = this._rootNodes;\n for (let i = 0; i < rootNodes.length; i++) {\n const node = this._runtimeNodes[rootNodes[i]];\n node._transformDirty = true;\n }\n};\n\n/**\n * Updates the joint matrices for the skins and nodes of the model.\n *\n * @private\n */\nModelSceneGraph.prototype.updateJointMatrices = function () {\n const skinnedNodes = this._skinnedNodes;\n const length = skinnedNodes.length;\n\n for (let i = 0; i < length; i++) {\n const nodeIndex = skinnedNodes[i];\n const runtimeNode = this._runtimeNodes[nodeIndex];\n runtimeNode.updateJointMatrices();\n }\n};\n\n/**\n * A callback to be applied once at each runtime primitive in the\n * scene graph\n * @callback traverseSceneGraphCallback\n *\n * @param {ModelRuntimePrimitive} runtimePrimitive The runtime primitive for the current step of the traversal\n * @param {object} [options] A dictionary of additional options to be passed to the callback, or undefined if the callback does not need any additional information.\n *\n * @private\n */\n\n/**\n * Recursively traverse through the runtime nodes in the scene graph\n * using a post-order depth-first traversal to perform a callback on\n * their runtime primitives.\n *\n * @param {ModelSceneGraph} sceneGraph The scene graph.\n * @param {ModelRuntimeNode} runtimeNode The current runtime node.\n * @param {boolean} visibleNodesOnly Whether to only traverse nodes that are visible.\n * @param {traverseSceneGraphCallback} callback The callback to perform on the runtime primitives of the node.\n * @param {object} [callbackOptions] A dictionary of additional options to be passed to the callback, if needed.\n *\n * @private\n */\nfunction traverseSceneGraph(\n sceneGraph,\n runtimeNode,\n visibleNodesOnly,\n callback,\n callbackOptions\n) {\n if (visibleNodesOnly && !runtimeNode.show) {\n return;\n }\n\n const childrenLength = runtimeNode.children.length;\n for (let i = 0; i < childrenLength; i++) {\n const childRuntimeNode = runtimeNode.getChild(i);\n traverseSceneGraph(\n sceneGraph,\n childRuntimeNode,\n visibleNodesOnly,\n callback,\n callbackOptions\n );\n }\n\n const runtimePrimitives = runtimeNode.runtimePrimitives;\n const runtimePrimitivesLength = runtimePrimitives.length;\n for (let j = 0; j < runtimePrimitivesLength; j++) {\n const runtimePrimitive = runtimePrimitives[j];\n callback(runtimePrimitive, callbackOptions);\n }\n}\n\nfunction forEachRuntimePrimitive(\n sceneGraph,\n visibleNodesOnly,\n callback,\n callbackOptions\n) {\n const rootNodes = sceneGraph._rootNodes;\n const rootNodesLength = rootNodes.length;\n for (let i = 0; i < rootNodesLength; i++) {\n const rootNodeIndex = rootNodes[i];\n const runtimeNode = sceneGraph._runtimeNodes[rootNodeIndex];\n traverseSceneGraph(\n sceneGraph,\n runtimeNode,\n visibleNodesOnly,\n callback,\n callbackOptions\n );\n }\n}\n\nconst scratchBackFaceCullingOptions = {\n backFaceCulling: undefined,\n};\n\n/**\n * Traverses through all draw commands and changes the back-face culling setting.\n *\n * @param {boolean} backFaceCulling The new value for the back-face culling setting.\n *\n * @private\n */\nModelSceneGraph.prototype.updateBackFaceCulling = function (backFaceCulling) {\n const backFaceCullingOptions = scratchBackFaceCullingOptions;\n backFaceCullingOptions.backFaceCulling = backFaceCulling;\n forEachRuntimePrimitive(\n this,\n false,\n updatePrimitiveBackFaceCulling,\n backFaceCullingOptions\n );\n};\n\n// Callback is defined here to avoid allocating a closure in the render loop\nfunction updatePrimitiveBackFaceCulling(runtimePrimitive, options) {\n const drawCommand = runtimePrimitive.drawCommand;\n drawCommand.backFaceCulling = options.backFaceCulling;\n}\n\nconst scratchShadowOptions = {\n shadowMode: undefined,\n};\n\n/**\n * Traverses through all draw commands and changes the shadow settings.\n *\n * @param {ShadowMode} shadowMode The new shadow settings.\n *\n * @private\n */\nModelSceneGraph.prototype.updateShadows = function (shadowMode) {\n const shadowOptions = scratchShadowOptions;\n shadowOptions.shadowMode = shadowMode;\n forEachRuntimePrimitive(this, false, updatePrimitiveShadows, shadowOptions);\n};\n\n// Callback is defined here to avoid allocating a closure in the render loop\nfunction updatePrimitiveShadows(runtimePrimitive, options) {\n const drawCommand = runtimePrimitive.drawCommand;\n drawCommand.shadows = options.shadowMode;\n}\n\nconst scratchShowBoundingVolumeOptions = {\n debugShowBoundingVolume: undefined,\n};\n\n/**\n * Traverses through all draw commands and changes whether to show the debug bounding volume.\n *\n * @param {boolean} debugShowBoundingVolume The new value for showing the debug bounding volume.\n *\n * @private\n */\nModelSceneGraph.prototype.updateShowBoundingVolume = function (\n debugShowBoundingVolume\n) {\n const showBoundingVolumeOptions = scratchShowBoundingVolumeOptions;\n showBoundingVolumeOptions.debugShowBoundingVolume = debugShowBoundingVolume;\n\n forEachRuntimePrimitive(\n this,\n false,\n updatePrimitiveShowBoundingVolume,\n showBoundingVolumeOptions\n );\n};\n\n// Callback is defined here to avoid allocating a closure in the render loop\nfunction updatePrimitiveShowBoundingVolume(runtimePrimitive, options) {\n const drawCommand = runtimePrimitive.drawCommand;\n drawCommand.debugShowBoundingVolume = options.debugShowBoundingVolume;\n}\n\nconst scratchSilhouetteCommands = [];\nconst scratchPushDrawCommandOptions = {\n frameState: undefined,\n hasSilhouette: undefined,\n};\n\n/**\n * Traverses through the scene graph and pushes the draw commands associated\n * with each primitive to the frame state's command list.\n *\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nModelSceneGraph.prototype.pushDrawCommands = function (frameState) {\n // If a model has silhouettes, the commands that draw the silhouettes for\n // each primitive can only be invoked after the entire model has drawn.\n // Otherwise, the silhouette may draw on top of the model. This requires\n // gathering the original commands and the silhouette commands separately.\n const silhouetteCommands = scratchSilhouetteCommands;\n silhouetteCommands.length = 0;\n\n // Since this function is called each frame, the options object is\n // preallocated in a scratch variable\n const pushDrawCommandOptions = scratchPushDrawCommandOptions;\n pushDrawCommandOptions.hasSilhouette = this._model.hasSilhouette(frameState);\n pushDrawCommandOptions.frameState = frameState;\n\n forEachRuntimePrimitive(\n this,\n true,\n pushPrimitiveDrawCommands,\n pushDrawCommandOptions\n );\n\n frameState.commandList.push.apply(frameState.commandList, silhouetteCommands);\n};\n\n// Callback is defined here to avoid allocating a closure in the render loop\nfunction pushPrimitiveDrawCommands(runtimePrimitive, options) {\n const frameState = options.frameState;\n const hasSilhouette = options.hasSilhouette;\n\n const passes = frameState.passes;\n const silhouetteCommands = scratchSilhouetteCommands;\n const primitiveDrawCommand = runtimePrimitive.drawCommand;\n\n primitiveDrawCommand.pushCommands(frameState, frameState.commandList);\n\n // If a model has silhouettes, the commands that draw the silhouettes for\n // each primitive can only be invoked after the entire model has drawn.\n // Otherwise, the silhouette may draw on top of the model. This requires\n // gathering the original commands and the silhouette commands separately.\n if (hasSilhouette && !passes.pick) {\n primitiveDrawCommand.pushSilhouetteCommands(frameState, silhouetteCommands);\n }\n}\n\n/**\n * Sets the current value of an articulation stage.\n *\n * @param {string} articulationStageKey The name of the articulation, a space, and the name of the stage.\n * @param {number} value The numeric value of this stage of the articulation.\n *\n * @private\n */\nModelSceneGraph.prototype.setArticulationStage = function (\n articulationStageKey,\n value\n) {\n const names = articulationStageKey.split(\" \");\n if (names.length !== 2) {\n return;\n }\n\n const articulationName = names[0];\n const stageName = names[1];\n\n const runtimeArticulation = this._runtimeArticulations[articulationName];\n if (defined(runtimeArticulation)) {\n runtimeArticulation.setArticulationStage(stageName, value);\n }\n};\n\n/**\n * Applies any modified articulation stages to the matrix of each node that participates\n * in any articulation. Note that this will overwrite any nodeTransformations on participating nodes.\n *\n * @private\n */\nModelSceneGraph.prototype.applyArticulations = function () {\n const runtimeArticulations = this._runtimeArticulations;\n for (const articulationName in runtimeArticulations) {\n if (runtimeArticulations.hasOwnProperty(articulationName)) {\n const articulation = runtimeArticulations[articulationName];\n articulation.apply();\n }\n }\n};\n\nexport default ModelSceneGraph;\n", "import AssociativeArray from \"../../Core/AssociativeArray.js\";\nimport Check from \"../../Core/Check.js\";\n\n/**\n * Rendering statistics for a single model.\n *\n * @alias ModelStatistics\n * @constructor\n *\n * @see Cesium3DTilesetStatistics\n *\n * @private\n */\nfunction ModelStatistics() {\n /**\n * Total number of points across all POINTS primitives in this model.\n *\n * @type {number}\n * @private\n */\n this.pointsLength = 0;\n\n /**\n * Total number of triangles across all TRIANGLES, TRIANGLE_STRIP or\n * TRIANGLE_FAN primitives in this model.\n *\n * @type {number}\n * @private\n */\n this.trianglesLength = 0;\n\n /**\n * Total size of all geometry buffers in bytes. This accounts for the vertex\n * attributes (which includes feature IDs and property attributes) and index\n * buffers of all the model's primitives. Any attributes generated by the\n * pipeline are included in this total.\n *\n * @type {number}\n * @private\n */\n this.geometryByteLength = 0;\n\n /**\n * Total size of all textures in bytes. This includes materials,\n * feature ID textures, and property textures.\n *\n * @type {number}\n * @private\n */\n this.texturesByteLength = 0;\n\n /**\n * Total size of property tables. This excludes the batch textures used for\n * picking and styling.\n *\n * @type {number}\n * @private\n */\n this.propertyTablesByteLength = 0;\n\n // Sets of buffers and textures that have already been counted.\n // This is to prevent double-counting cached assets.\n this._bufferIdSet = {};\n this._textureIdSet = {};\n\n // Associated array of batch textures that have already been counted.\n // This allows for quick look-up to check if a texture has been counted,\n // while also allowing for dynamic texture counting.\n this._batchTextureIdMap = new AssociativeArray();\n}\n\nObject.defineProperties(ModelStatistics.prototype, {\n /**\n * Total size of the batch textures used for picking and styling.\n * Batch textures are created asynchronously, so this iterates\n * over the textures to ensure their memory values are accurate.\n *\n * @memberof ModelStatistics.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n batchTexturesByteLength: {\n get: function () {\n const length = this._batchTextureIdMap.length;\n const values = this._batchTextureIdMap.values;\n\n let memory = 0;\n for (let i = 0; i < length; i++) {\n memory += values[i].byteLength;\n }\n\n return memory;\n },\n },\n});\n\n/**\n * Reset the memory counts for this model. This should be called each time the\n * draw command pipeline is rebuilt.\n *\n * @private\n */\nModelStatistics.prototype.clear = function () {\n this.pointsLength = 0;\n this.trianglesLength = 0;\n this.geometryByteLength = 0;\n this.texturesByteLength = 0;\n this.propertyTablesByteLength = 0;\n\n this._bufferIdSet = {};\n this._textureIdSet = {};\n this._batchTextureIdMap.removeAll();\n};\n\n/**\n * Counts the given buffer's memory in bytes. If a buffer has\n * already been counted by these statistics, it will not be\n * counted again.\n *\n * @param {Buffer} buffer The GPU buffer associated with the model.\n * @param {boolean} hasCpuCopy Whether the buffer has a copy on the CPU via typed array.\n *\n * @private\n */\nModelStatistics.prototype.addBuffer = function (buffer, hasCpuCopy) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"buffer\", buffer);\n Check.typeOf.bool(\"hasCpuCopy\", hasCpuCopy);\n //>>includeEnd('debug');\n\n if (!this._bufferIdSet.hasOwnProperty(buffer._id)) {\n // If there's a CPU copy, count the memory twice.\n const copies = hasCpuCopy ? 2 : 1;\n this.geometryByteLength += buffer.sizeInBytes * copies;\n }\n\n // Simulate set insertion.\n this._bufferIdSet[buffer._id] = true;\n};\n\n/**\n * Counts the given texture's memory in bytes. If a texture has\n * already been counted by these statistics, it will not be\n * counted again.\n *

\n * This is used to count the materials and property textures of\n * a model. Batch textures function differently and are counted\n * using addBatchTexture instead.\n *

\n *\n * @param {Texture} texture The texture associated with the model.\n *\n * @private\n */\nModelStatistics.prototype.addTexture = function (texture) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"texture\", texture);\n //>>includeEnd('debug');\n\n if (!this._textureIdSet.hasOwnProperty(texture._id)) {\n this.texturesByteLength += texture.sizeInBytes;\n }\n\n // Simulate set insertion.\n this._textureIdSet[texture._id] = true;\n};\n\n/**\n * Counts the batch texture's memory in bytes. If a batch texture\n * has already been counted by these statistics, it will not be\n * counted again.\n *

\n * Batch textures are handled differently than other textures. They\n * include the batch and pick textures for the feature table, which\n * are created dynamically. As such, they may not have both textures\n * loaded by the time they are added to the statistics. Their memory\n * will thus be counted dynamically.\n *

\n *\n * @param {BatchTexture} batchTexture The batch texture associated with the model.\n *\n * @private\n */\nModelStatistics.prototype.addBatchTexture = function (batchTexture) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"batchTexture\", batchTexture);\n //>>includeEnd('debug');\n\n if (!this._batchTextureIdMap.contains(batchTexture._id)) {\n this._batchTextureIdMap.set(batchTexture._id, batchTexture);\n }\n};\n\nexport default ModelStatistics;\n", "import AttributeCompression from \"../../Core/AttributeCompression.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Color from \"../../Core/Color.js\";\nimport Check from \"../../Core/Check.js\";\nimport ComponentDatatype from \"../../Core/ComponentDatatype.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport defined from \"../../Core/defined.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport PrimitiveType from \"../../Core/PrimitiveType.js\";\nimport WebGLConstants from \"../../Core/WebGLConstants.js\";\nimport MersenneTwister from \"mersenne-twister\";\nimport Buffer from \"../../Renderer/Buffer.js\";\nimport BufferUsage from \"../../Renderer/BufferUsage.js\";\nimport AlphaMode from \"../AlphaMode.js\";\nimport AttributeType from \"../AttributeType.js\";\nimport Axis from \"../Axis.js\";\nimport parseBatchTable from \"../parseBatchTable.js\";\nimport DracoLoader from \"../DracoLoader.js\";\nimport StructuralMetadata from \"../StructuralMetadata.js\";\nimport ResourceLoader from \"../ResourceLoader.js\";\nimport ModelComponents from \"../ModelComponents.js\";\nimport PntsParser from \"../PntsParser.js\";\nimport ResourceLoaderState from \"../ResourceLoaderState.js\";\nimport VertexAttributeSemantic from \"../VertexAttributeSemantic.js\";\n\nconst Components = ModelComponents.Components;\nconst Scene = ModelComponents.Scene;\nconst Node = ModelComponents.Node;\nconst Primitive = ModelComponents.Primitive;\nconst Attribute = ModelComponents.Attribute;\nconst Quantization = ModelComponents.Quantization;\nconst FeatureIdAttribute = ModelComponents.FeatureIdAttribute;\nconst Material = ModelComponents.Material;\nconst MetallicRoughness = ModelComponents.MetallicRoughness;\n\n/**\n * Loads a .pnts point cloud and transcodes it into a {@link ModelComponents}\n *\n * @alias PntsLoader\n * @constructor\n * @augments ResourceLoader\n * @private\n *\n * @param {object} options An object containing the following properties\n * @param {ArrayBuffer} options.arrayBuffer The array buffer of the pnts contents\n * @param {number} [options.byteOffset] The byte offset to the beginning of the pnts contents in the array buffer\n * @param {boolean} [options.loadAttributesFor2D=false] If true, load the positions buffer as a typed array for accurately projecting models to 2D.\n */\nfunction PntsLoader(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const arrayBuffer = options.arrayBuffer;\n const byteOffset = defaultValue(options.byteOffset, 0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n this._arrayBuffer = arrayBuffer;\n this._byteOffset = byteOffset;\n this._loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false);\n\n this._parsedContent = undefined;\n this._decodePromise = undefined;\n this._decodedAttributes = undefined;\n\n this._promise = undefined;\n this._error = undefined;\n this._state = ResourceLoaderState.UNLOADED;\n this._buffers = [];\n\n // The batch table object contains a json and a binary component access using keys of the same name.\n this._components = undefined;\n this._transform = Matrix4.IDENTITY;\n}\n\nif (defined(Object.create)) {\n PntsLoader.prototype = Object.create(ResourceLoader.prototype);\n PntsLoader.prototype.constructor = PntsLoader;\n}\n\nObject.defineProperties(PntsLoader.prototype, {\n /**\n * The cache key of the resource\n *\n * @memberof PntsLoader.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n cacheKey: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * The loaded components.\n *\n * @memberof PntsLoader.prototype\n *\n * @type {ModelComponents.Components}\n * @readonly\n * @private\n */\n components: {\n get: function () {\n return this._components;\n },\n },\n\n /**\n * A world-space transform to apply to the primitives.\n * See {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/PointCloud#global-semantics}\n *\n * @memberof PntsLoader.prototype\n *\n * @type {Matrix4}\n * @readonly\n * @private\n */\n transform: {\n get: function () {\n return this._transform;\n },\n },\n});\n\n/**\n * Loads the resource.\n * @returns {Promise} A promise which resolves to the loader when the resource loading is completed.\n * @private\n */\nPntsLoader.prototype.load = function () {\n if (defined(this._promise)) {\n return this._promise;\n }\n\n this._parsedContent = PntsParser.parse(this._arrayBuffer, this._byteOffset);\n this._state = ResourceLoaderState.PROCESSING;\n\n this._promise = Promise.resolve(this);\n};\n\nPntsLoader.prototype.process = function (frameState) {\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n if (this._state === ResourceLoaderState.READY) {\n return true;\n }\n\n if (this._state === ResourceLoaderState.PROCESSING) {\n if (defined(this._decodePromise)) {\n return false;\n }\n\n this._decodePromise = decodeDraco(this, frameState.context);\n }\n\n return false;\n};\n\nfunction decodeDraco(loader, context) {\n const parsedContent = loader._parsedContent;\n const draco = parsedContent.draco;\n\n let decodePromise;\n if (!defined(draco)) {\n // The draco extension wasn't present,\n decodePromise = Promise.resolve();\n } else {\n decodePromise = DracoLoader.decodePointCloud(draco, context);\n }\n\n if (!defined(decodePromise)) {\n // Could not schedule Draco decoding this frame.\n return;\n }\n\n loader._decodePromise = decodePromise;\n return decodePromise\n .then(function (decodeDracoResult) {\n if (loader.isDestroyed()) {\n return;\n }\n\n if (defined(decodeDracoResult)) {\n processDracoAttributes(loader, draco, decodeDracoResult);\n }\n makeComponents(loader, context);\n loader._state = ResourceLoaderState.READY;\n return loader;\n })\n .catch(function (error) {\n loader.unload();\n loader._state = ResourceLoaderState.FAILED;\n const errorMessage = \"Failed to load Draco pnts\";\n // This error will be thrown next time process is called;\n loader._error = loader.getError(errorMessage, error);\n });\n}\n\nfunction processDracoAttributes(loader, draco, result) {\n loader._state = ResourceLoaderState.READY;\n const parsedContent = loader._parsedContent;\n\n let attribute;\n if (defined(result.POSITION)) {\n attribute = {\n name: \"POSITION\",\n semantic: VertexAttributeSemantic.POSITION,\n typedArray: result.POSITION.array,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n isQuantized: false,\n };\n\n if (defined(result.POSITION.data.quantization)) {\n // Draco quantization range == quantized volume scale - size in meters of the quantized volume\n // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc\n const quantization = result.POSITION.data.quantization;\n const range = quantization.range;\n const quantizedVolumeScale = Cartesian3.fromElements(range, range, range);\n const quantizedVolumeOffset = Cartesian3.unpack(quantization.minValues);\n const quantizedRange = (1 << quantization.quantizationBits) - 1.0;\n\n attribute.isQuantized = true;\n attribute.quantizedRange = quantizedRange;\n attribute.quantizedVolumeOffset = quantizedVolumeOffset;\n attribute.quantizedVolumeScale = quantizedVolumeScale;\n attribute.quantizedComponentDatatype =\n quantizedRange <= 255\n ? ComponentDatatype.UNSIGNED_BYTE\n : ComponentDatatype.UNSIGNED_SHORT;\n attribute.quantizedType = AttributeType.VEC3;\n }\n\n parsedContent.positions = attribute;\n }\n\n if (defined(result.NORMAL)) {\n attribute = {\n name: \"NORMAL\",\n semantic: VertexAttributeSemantic.NORMAL,\n typedArray: result.NORMAL.array,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n isQuantized: false,\n octEncoded: false,\n octEncodedZXY: false,\n };\n\n if (defined(result.NORMAL.data.quantization)) {\n const octEncodedRange =\n (1 << result.NORMAL.data.quantization.quantizationBits) - 1.0;\n attribute.quantizedRange = octEncodedRange;\n attribute.octEncoded = true;\n attribute.octEncodedZXY = true;\n attribute.quantizedComponentDatatype = ComponentDatatype.UNSIGNED_BYTE;\n attribute.quantizedType = AttributeType.VEC2;\n }\n\n parsedContent.normals = attribute;\n }\n\n if (defined(result.RGBA)) {\n parsedContent.colors = {\n name: \"COLOR\",\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n typedArray: result.RGBA.array,\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n type: AttributeType.VEC4,\n normalized: true,\n isTranslucent: true,\n };\n } else if (defined(result.RGB)) {\n parsedContent.colors = {\n name: \"COLOR\",\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n typedArray: result.RGB.array,\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n type: AttributeType.VEC3,\n normalized: true,\n isTranslucent: false,\n };\n }\n\n // Transcode Batch ID (3D Tiles 1.0) -> Feature ID (3D Tiles Next)\n if (defined(result.BATCH_ID)) {\n const batchIds = result.BATCH_ID.array;\n parsedContent.batchIds = {\n name: \"_FEATURE_ID\",\n semantic: VertexAttributeSemantic.FEATURE_ID,\n setIndex: 0,\n typedArray: batchIds,\n componentDatatype: ComponentDatatype.fromTypedArray(batchIds),\n type: AttributeType.SCALAR,\n };\n }\n\n let batchTableJson = parsedContent.batchTableJson;\n\n const batchTableProperties = draco.batchTableProperties;\n for (const name in batchTableProperties) {\n if (batchTableProperties.hasOwnProperty(name)) {\n const property = result[name];\n\n if (!defined(batchTableJson)) {\n batchTableJson = {};\n }\n\n parsedContent.hasDracoBatchTable = true;\n\n const data = property.data;\n batchTableJson[name] = {\n byteOffset: data.byteOffset,\n // Draco returns the results like glTF values, but here\n // we want to transcode to a batch table. It's redundant\n // but necessary to use parseBatchTable()\n type: transcodeAttributeType(data.componentsPerAttribute),\n componentType: transcodeComponentType(data.componentDatatype),\n // Each property is stored as a separate typed array, so\n // store it here. parseBatchTable() will check for this\n // instead of the entire binary body.\n typedArray: property.array,\n };\n }\n }\n parsedContent.batchTableJson = batchTableJson;\n}\n\nfunction transcodeAttributeType(componentsPerAttribute) {\n switch (componentsPerAttribute) {\n case 1:\n return \"SCALAR\";\n case 2:\n return \"VEC2\";\n case 3:\n return \"VEC3\";\n case 4:\n return \"VEC4\";\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\n \"componentsPerAttribute must be a number from 1-4\"\n );\n //>>includeEnd('debug');\n }\n}\n\nfunction transcodeComponentType(value) {\n switch (value) {\n case WebGLConstants.BYTE:\n return \"BYTE\";\n case WebGLConstants.UNSIGNED_BYTE:\n return \"UNSIGNED_BYTE\";\n case WebGLConstants.SHORT:\n return \"SHORT\";\n case WebGLConstants.UNSIGNED_SHORT:\n return \"UNSIGNED_SHORT\";\n case WebGLConstants.INT:\n return \"INT\";\n case WebGLConstants.UNSIGNED_INT:\n return \"UNSIGNED_INT\";\n case WebGLConstants.DOUBLE:\n return \"DOUBLE\";\n case WebGLConstants.FLOAT:\n return \"FLOAT\";\n //>>includeStart('debug', pragmas.debug);\n default:\n throw new DeveloperError(\"value is not a valid WebGL constant\");\n //>>includeEnd('debug');\n }\n}\n\nfunction makeAttribute(loader, attributeInfo, context) {\n let typedArray = attributeInfo.typedArray;\n let quantization;\n if (attributeInfo.octEncoded) {\n quantization = new Quantization();\n quantization.octEncoded = attributeInfo.octEncoded;\n quantization.octEncodedZXY = attributeInfo.octEncodedZXY;\n quantization.normalizationRange = attributeInfo.quantizedRange;\n quantization.type = attributeInfo.quantizedType;\n quantization.componentDatatype = attributeInfo.quantizedComponentDatatype;\n }\n if (attributeInfo.isQuantized) {\n quantization = new Quantization();\n const normalizationRange = attributeInfo.quantizedRange;\n quantization.normalizationRange = normalizationRange;\n // volume offset sometimes requires 64-bit precision so this is handled\n // in the components.transform matrix.\n quantization.quantizedVolumeOffset = Cartesian3.ZERO;\n const quantizedVolumeDimensions = attributeInfo.quantizedVolumeScale;\n quantization.quantizedVolumeDimensions = quantizedVolumeDimensions;\n quantization.quantizedVolumeStepSize = Cartesian3.divideByScalar(\n quantizedVolumeDimensions,\n normalizationRange,\n new Cartesian3()\n );\n quantization.componentDatatype = attributeInfo.quantizedComponentDatatype;\n quantization.type = attributeInfo.quantizedType;\n }\n\n const attribute = new Attribute();\n attribute.name = attributeInfo.name;\n attribute.semantic = attributeInfo.semantic;\n attribute.setIndex = attributeInfo.setIndex;\n attribute.componentDatatype = attributeInfo.componentDatatype;\n attribute.type = attributeInfo.type;\n attribute.normalized = defaultValue(attributeInfo.normalized, false);\n attribute.min = attributeInfo.min;\n attribute.max = attributeInfo.max;\n attribute.quantization = quantization;\n\n if (attributeInfo.isRGB565) {\n typedArray = AttributeCompression.decodeRGB565(typedArray);\n }\n\n if (defined(attributeInfo.constantColor)) {\n const packedColor = new Array(4);\n attribute.constant = Color.pack(attributeInfo.constantColor, packedColor);\n } else {\n const buffer = Buffer.createVertexBuffer({\n typedArray: typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n });\n buffer.vertexArrayDestroyable = false;\n loader._buffers.push(buffer);\n attribute.buffer = buffer;\n }\n\n const loadAttributesFor2D = loader._loadAttributesFor2D;\n if (\n attribute.semantic === VertexAttributeSemantic.POSITION &&\n loadAttributesFor2D\n ) {\n attribute.typedArray = typedArray;\n }\n\n return attribute;\n}\n\nlet randomNumberGenerator;\nlet randomValues;\n\nfunction getRandomValues(samplesLength) {\n // Use same random values across all runs\n if (!defined(randomValues)) {\n // Use MersenneTwister directly to avoid interfering with CesiumMath.nextRandomNumber()\n // See https://github.com/CesiumGS/cesium/issues/9730\n randomNumberGenerator = new MersenneTwister(0);\n randomValues = new Array(samplesLength);\n for (let i = 0; i < samplesLength; ++i) {\n randomValues[i] = randomNumberGenerator.random();\n }\n }\n return randomValues;\n}\n\nconst scratchMin = new Cartesian3();\nconst scratchMax = new Cartesian3();\nconst scratchPosition = new Cartesian3();\nfunction computeApproximateExtrema(positions) {\n const positionsArray = positions.typedArray;\n const maximumSamplesLength = 20;\n const pointsLength = positionsArray.length / 3;\n const samplesLength = Math.min(pointsLength, maximumSamplesLength);\n const randomValues = getRandomValues(maximumSamplesLength);\n const maxValue = Number.MAX_VALUE;\n const minValue = -Number.MAX_VALUE;\n let min = Cartesian3.fromElements(maxValue, maxValue, maxValue, scratchMin);\n let max = Cartesian3.fromElements(minValue, minValue, minValue, scratchMax);\n let i;\n let index;\n let position;\n if (positions.isQuantized) {\n // The quantized volume offset is not used here since it will become part of\n // the model matrix.\n min = Cartesian3.ZERO;\n max = positions.quantizedVolumeScale;\n } else {\n for (i = 0; i < samplesLength; ++i) {\n index = Math.floor(randomValues[i] * pointsLength);\n position = Cartesian3.unpack(positionsArray, index * 3, scratchPosition);\n\n Cartesian3.minimumByComponent(min, position, min);\n Cartesian3.maximumByComponent(max, position, max);\n }\n }\n\n positions.min = Cartesian3.clone(min);\n positions.max = Cartesian3.clone(max);\n}\n\n// By default, point clouds are rendered as dark gray.\nconst defaultColorAttribute = {\n name: VertexAttributeSemantic.COLOR,\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n constantColor: Color.DARKGRAY,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC4,\n isQuantized: false,\n isTranslucent: false,\n};\n\nfunction makeAttributes(loader, parsedContent, context) {\n const attributes = [];\n let attribute;\n const positions = parsedContent.positions;\n if (defined(positions)) {\n computeApproximateExtrema(positions);\n attribute = makeAttribute(loader, positions, context);\n attribute.count = parsedContent.pointsLength;\n attributes.push(attribute);\n }\n\n if (defined(parsedContent.normals)) {\n attribute = makeAttribute(loader, parsedContent.normals, context);\n attributes.push(attribute);\n }\n\n if (defined(parsedContent.colors)) {\n attribute = makeAttribute(loader, parsedContent.colors, context);\n attributes.push(attribute);\n } else {\n attribute = makeAttribute(loader, defaultColorAttribute, context);\n attributes.push(attribute);\n }\n\n if (defined(parsedContent.batchIds)) {\n attribute = makeAttribute(loader, parsedContent.batchIds, context);\n attributes.push(attribute);\n }\n\n return attributes;\n}\n\nfunction makeStructuralMetadata(parsedContent, customAttributeOutput) {\n const batchLength = parsedContent.batchLength;\n const pointsLength = parsedContent.pointsLength;\n const batchTableBinary = parsedContent.batchTableBinary;\n\n // If there are batch IDs, parse as a property table. Otherwise, parse\n // as property attributes.\n const parseAsPropertyAttributes = !defined(parsedContent.batchIds);\n\n if (defined(batchTableBinary) || parsedContent.hasDracoBatchTable) {\n const count = defaultValue(batchLength, pointsLength);\n return parseBatchTable({\n count: count,\n batchTable: parsedContent.batchTableJson,\n binaryBody: batchTableBinary,\n parseAsPropertyAttributes: parseAsPropertyAttributes,\n customAttributeOutput: customAttributeOutput,\n });\n }\n\n return new StructuralMetadata({\n schema: {},\n propertyTables: [],\n });\n}\n\nfunction makeComponents(loader, context) {\n const parsedContent = loader._parsedContent;\n\n const metallicRoughness = new MetallicRoughness();\n metallicRoughness.metallicFactor = 0;\n metallicRoughness.roughnessFactor = 0.9;\n\n const material = new Material();\n material.metallicRoughness = metallicRoughness;\n\n const colors = parsedContent.colors;\n if (defined(colors) && colors.isTranslucent) {\n material.alphaMode = AlphaMode.BLEND;\n }\n\n // Render point clouds as unlit, unless normals are present, in which case\n // render as a PBR material.\n const isUnlit = !defined(parsedContent.normals);\n material.unlit = isUnlit;\n\n const primitive = new Primitive();\n primitive.attributes = makeAttributes(loader, parsedContent, context);\n primitive.primitiveType = PrimitiveType.POINTS;\n primitive.material = material;\n\n if (defined(parsedContent.batchIds)) {\n const featureIdAttribute = new FeatureIdAttribute();\n featureIdAttribute.propertyTableId = 0;\n featureIdAttribute.setIndex = 0;\n featureIdAttribute.positionalLabel = \"featureId_0\";\n primitive.featureIds.push(featureIdAttribute);\n }\n\n const node = new Node();\n node.index = 0;\n node.primitives = [primitive];\n\n const scene = new Scene();\n scene.nodes = [node];\n scene.upAxis = Axis.Z;\n scene.forwardAxis = Axis.X;\n\n const components = new Components();\n components.scene = scene;\n components.nodes = [node];\n\n // Per-point features will be parsed as property attributes and handled on\n // the GPU since CPU styling would be too expensive. However, if batch IDs\n // exist, features will be parsed as a property table.\n //\n // Property attributes refer to a custom attribute that will\n // store the values; such attributes will be populated in this array\n // as needed.\n const customAttributeOutput = [];\n components.structuralMetadata = makeStructuralMetadata(\n parsedContent,\n customAttributeOutput\n );\n\n if (customAttributeOutput.length > 0) {\n addPropertyAttributesToPrimitive(\n loader,\n primitive,\n customAttributeOutput,\n context\n );\n }\n\n if (defined(parsedContent.rtcCenter)) {\n components.transform = Matrix4.multiplyByTranslation(\n components.transform,\n parsedContent.rtcCenter,\n components.transform\n );\n }\n\n const positions = parsedContent.positions;\n if (defined(positions) && positions.isQuantized) {\n // The volume offset is sometimes in ECEF, so this is applied here rather\n // than the dequantization shader to avoid jitter\n components.transform = Matrix4.multiplyByTranslation(\n components.transform,\n positions.quantizedVolumeOffset,\n components.transform\n );\n }\n\n loader._components = components;\n\n // Free the parsed content and array buffer so we don't hold onto the large arrays.\n loader._parsedContent = undefined;\n loader._arrayBuffer = undefined;\n}\n\nfunction addPropertyAttributesToPrimitive(\n loader,\n primitive,\n customAttributes,\n context\n) {\n const attributes = primitive.attributes;\n\n const length = customAttributes.length;\n for (let i = 0; i < length; i++) {\n const customAttribute = customAttributes[i];\n\n // Upload the typed array to the GPU and free the CPU copy.\n const buffer = Buffer.createVertexBuffer({\n typedArray: customAttribute.typedArray,\n context: context,\n usage: BufferUsage.STATIC_DRAW,\n });\n buffer.vertexArrayDestroyable = false;\n loader._buffers.push(buffer);\n customAttribute.buffer = buffer;\n customAttribute.typedArray = undefined;\n\n attributes.push(customAttribute);\n }\n\n // The batch table is always transcoded as a single property attribute, so\n // it will always be index 0\n primitive.propertyAttributeIds = [0];\n}\n\nPntsLoader.prototype.unload = function () {\n const buffers = this._buffers;\n for (let i = 0; i < buffers.length; i++) {\n buffers[i].destroy();\n }\n buffers.length = 0;\n\n this._components = undefined;\n this._parsedContent = undefined;\n this._arrayBuffer = undefined;\n};\n\nexport default PntsLoader;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport combine from \"../Core/combine.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport AttributeType from \"./AttributeType.js\";\nimport Cesium3DTileFeatureTable from \"./Cesium3DTileFeatureTable.js\";\nimport VertexAttributeSemantic from \"./VertexAttributeSemantic.js\";\n\n/**\n * Handles parsing of a Point Cloud\n *\n * @namespace PntsParser\n * @private\n */\nconst PntsParser = {};\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\n/**\n * Parses the contents of a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/PointCloud|Point Cloud}.\n *\n * @private\n *\n * @param {*} arrayBuffer The array buffer containing the pnts\n * @param {*} [byteOffset=0] The byte offset of the beginning of the pnts in the array buffer\n * @returns {object} An object containing a parsed representation of the point cloud\n */\nPntsParser.parse = function (arrayBuffer, byteOffset) {\n byteOffset = defaultValue(byteOffset, 0);\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"arrayBuffer\", arrayBuffer);\n //>>includeEnd('debug');\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Point Cloud tile version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n // Skip byteLength\n byteOffset += sizeOfUint32;\n\n const featureTableJsonByteLength = view.getUint32(byteOffset, true);\n if (featureTableJsonByteLength === 0) {\n throw new RuntimeError(\n \"Feature table must have a byte length greater than zero\"\n );\n }\n byteOffset += sizeOfUint32;\n\n const featureTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const batchTableJsonByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const batchTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const featureTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n featureTableJsonByteLength\n );\n byteOffset += featureTableJsonByteLength;\n\n const featureTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n featureTableBinaryByteLength\n );\n byteOffset += featureTableBinaryByteLength;\n\n // Get the batch table JSON and binary\n let batchTableJson;\n let batchTableBinary;\n if (batchTableJsonByteLength > 0) {\n // Has a batch table JSON\n batchTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n batchTableJsonByteLength\n );\n byteOffset += batchTableJsonByteLength;\n\n if (batchTableBinaryByteLength > 0) {\n // Has a batch table binary\n batchTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n batchTableBinaryByteLength\n );\n byteOffset += batchTableBinaryByteLength;\n }\n }\n\n const featureTable = new Cesium3DTileFeatureTable(\n featureTableJson,\n featureTableBinary\n );\n\n const pointsLength = featureTable.getGlobalProperty(\"POINTS_LENGTH\");\n featureTable.featuresLength = pointsLength;\n\n if (!defined(pointsLength)) {\n throw new RuntimeError(\n \"Feature table global property: POINTS_LENGTH must be defined\"\n );\n }\n\n let rtcCenter = featureTable.getGlobalProperty(\n \"RTC_CENTER\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (defined(rtcCenter)) {\n rtcCenter = Cartesian3.unpack(rtcCenter);\n }\n\n // Start with the draco compressed properties and add in uncompressed\n // properties.\n const parsedContent = parseDracoProperties(featureTable, batchTableJson);\n parsedContent.rtcCenter = rtcCenter;\n parsedContent.pointsLength = pointsLength;\n\n if (!parsedContent.hasPositions) {\n const positions = parsePositions(featureTable);\n parsedContent.positions = positions;\n parsedContent.hasPositions =\n parsedContent.hasPositions || defined(positions);\n }\n\n if (!parsedContent.hasPositions) {\n throw new RuntimeError(\n \"Either POSITION or POSITION_QUANTIZED must be defined.\"\n );\n }\n\n if (!parsedContent.hasNormals) {\n const normals = parseNormals(featureTable);\n parsedContent.normals = normals;\n parsedContent.hasNormals = parsedContent.hasNormals || defined(normals);\n }\n\n if (!parsedContent.hasColors) {\n const colors = parseColors(featureTable);\n parsedContent.colors = colors;\n parsedContent.hasColors = parsedContent.hasColors || defined(colors);\n parsedContent.hasConstantColor = defined(parsedContent.constantColor);\n parsedContent.isTranslucent = defined(colors) && colors.isTranslucent;\n }\n\n if (!parsedContent.hasBatchIds) {\n const batchIds = parseBatchIds(featureTable);\n parsedContent.batchIds = batchIds;\n parsedContent.hasBatchIds = parsedContent.hasBatchIds || defined(batchIds);\n }\n\n if (parsedContent.hasBatchIds) {\n const batchLength = featureTable.getGlobalProperty(\"BATCH_LENGTH\");\n if (!defined(batchLength)) {\n throw new RuntimeError(\n \"Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.\"\n );\n }\n parsedContent.batchLength = batchLength;\n }\n\n if (defined(batchTableBinary)) {\n // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed\n batchTableBinary = new Uint8Array(batchTableBinary);\n parsedContent.batchTableJson = batchTableJson;\n parsedContent.batchTableBinary = batchTableBinary;\n }\n\n return parsedContent;\n};\n\nfunction parseDracoProperties(featureTable, batchTableJson) {\n const featureTableJson = featureTable.json;\n let dracoBuffer;\n let dracoFeatureTableProperties;\n let dracoBatchTableProperties;\n\n const featureTableDraco = defined(featureTableJson.extensions)\n ? featureTableJson.extensions[\"3DTILES_draco_point_compression\"]\n : undefined;\n const batchTableDraco =\n defined(batchTableJson) && defined(batchTableJson.extensions)\n ? batchTableJson.extensions[\"3DTILES_draco_point_compression\"]\n : undefined;\n\n if (defined(batchTableDraco)) {\n dracoBatchTableProperties = batchTableDraco.properties;\n }\n\n let hasPositions;\n let hasColors;\n let hasNormals;\n let hasBatchIds;\n let isTranslucent;\n if (defined(featureTableDraco)) {\n dracoFeatureTableProperties = featureTableDraco.properties;\n const dracoByteOffset = featureTableDraco.byteOffset;\n const dracoByteLength = featureTableDraco.byteLength;\n if (\n !defined(dracoFeatureTableProperties) ||\n !defined(dracoByteOffset) ||\n !defined(dracoByteLength)\n ) {\n throw new RuntimeError(\n \"Draco properties, byteOffset, and byteLength must be defined\"\n );\n }\n dracoBuffer = featureTable.buffer.slice(\n dracoByteOffset,\n dracoByteOffset + dracoByteLength\n );\n hasPositions = defined(dracoFeatureTableProperties.POSITION);\n hasColors =\n defined(dracoFeatureTableProperties.RGB) ||\n defined(dracoFeatureTableProperties.RGBA);\n hasNormals = defined(dracoFeatureTableProperties.NORMAL);\n hasBatchIds = defined(dracoFeatureTableProperties.BATCH_ID);\n isTranslucent = defined(dracoFeatureTableProperties.RGBA);\n }\n\n let draco;\n if (defined(dracoBuffer)) {\n draco = {\n buffer: dracoBuffer,\n featureTableProperties: dracoFeatureTableProperties,\n batchTableProperties: dracoBatchTableProperties,\n properties: combine(\n dracoFeatureTableProperties,\n dracoBatchTableProperties\n ),\n dequantizeInShader: true,\n };\n }\n\n return {\n draco: draco,\n hasPositions: hasPositions,\n hasColors: hasColors,\n isTranslucent: isTranslucent,\n hasNormals: hasNormals,\n hasBatchIds: hasBatchIds,\n };\n}\n\nfunction parsePositions(featureTable) {\n const featureTableJson = featureTable.json;\n\n let positions;\n if (defined(featureTableJson.POSITION)) {\n positions = featureTable.getPropertyArray(\n \"POSITION\",\n ComponentDatatype.FLOAT,\n 3\n );\n\n return {\n name: VertexAttributeSemantic.POSITION,\n semantic: VertexAttributeSemantic.POSITION,\n typedArray: positions,\n isQuantized: false,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n };\n } else if (defined(featureTableJson.POSITION_QUANTIZED)) {\n positions = featureTable.getPropertyArray(\n \"POSITION_QUANTIZED\",\n ComponentDatatype.UNSIGNED_SHORT,\n 3\n );\n\n const quantizedVolumeScale = featureTable.getGlobalProperty(\n \"QUANTIZED_VOLUME_SCALE\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (!defined(quantizedVolumeScale)) {\n throw new RuntimeError(\n \"Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.\"\n );\n }\n const quantizedRange = (1 << 16) - 1;\n\n const quantizedVolumeOffset = featureTable.getGlobalProperty(\n \"QUANTIZED_VOLUME_OFFSET\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (!defined(quantizedVolumeOffset)) {\n throw new RuntimeError(\n \"Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.\"\n );\n }\n\n return {\n name: VertexAttributeSemantic.POSITION,\n semantic: VertexAttributeSemantic.POSITION,\n typedArray: positions,\n isQuantized: true,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n quantizedRange: quantizedRange,\n quantizedVolumeOffset: Cartesian3.unpack(quantizedVolumeOffset),\n quantizedVolumeScale: Cartesian3.unpack(quantizedVolumeScale),\n quantizedComponentDatatype: ComponentDatatype.UNSIGNED_SHORT,\n quantizedType: AttributeType.VEC3,\n };\n }\n}\n\nfunction parseColors(featureTable) {\n const featureTableJson = featureTable.json;\n\n let colors;\n if (defined(featureTableJson.RGBA)) {\n colors = featureTable.getPropertyArray(\n \"RGBA\",\n ComponentDatatype.UNSIGNED_BYTE,\n 4\n );\n return {\n name: VertexAttributeSemantic.COLOR,\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n typedArray: colors,\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n type: AttributeType.VEC4,\n normalized: true,\n isRGB565: false,\n isTranslucent: true,\n };\n } else if (defined(featureTableJson.RGB)) {\n colors = featureTable.getPropertyArray(\n \"RGB\",\n ComponentDatatype.UNSIGNED_BYTE,\n 3\n );\n return {\n name: \"COLOR\",\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n typedArray: colors,\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n type: AttributeType.VEC3,\n normalized: true,\n isRGB565: false,\n isTranslucent: false,\n };\n } else if (defined(featureTableJson.RGB565)) {\n colors = featureTable.getPropertyArray(\n \"RGB565\",\n ComponentDatatype.UNSIGNED_SHORT,\n 1\n );\n return {\n name: \"COLOR\",\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n typedArray: colors,\n // These settings are for the Model implementation\n // which decodes on the CPU and uploads a VEC3 of float colors.\n // PointCloud does the decoding on the GPU so uploads a\n // UNSIGNED_SHORT instead.\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n normalized: false,\n isRGB565: true,\n isTranslucent: false,\n };\n } else if (defined(featureTableJson.CONSTANT_RGBA)) {\n const constantRGBA = featureTable.getGlobalProperty(\n \"CONSTANT_RGBA\",\n ComponentDatatype.UNSIGNED_BYTE,\n 4\n );\n\n const alpha = constantRGBA[3];\n const constantColor = Color.fromBytes(\n constantRGBA[0],\n constantRGBA[1],\n constantRGBA[2],\n alpha\n );\n\n const isTranslucent = alpha < 255;\n return {\n name: VertexAttributeSemantic.COLOR,\n semantic: VertexAttributeSemantic.COLOR,\n setIndex: 0,\n constantColor: constantColor,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC4,\n isQuantized: false,\n isTranslucent: isTranslucent,\n };\n }\n\n return undefined;\n}\n\nfunction parseNormals(featureTable) {\n const featureTableJson = featureTable.json;\n let normals;\n if (defined(featureTableJson.NORMAL)) {\n normals = featureTable.getPropertyArray(\n \"NORMAL\",\n ComponentDatatype.FLOAT,\n 3\n );\n return {\n name: VertexAttributeSemantic.NORMAL,\n semantic: VertexAttributeSemantic.NORMAL,\n typedArray: normals,\n octEncoded: false,\n octEncodedZXY: false,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n };\n } else if (defined(featureTableJson.NORMAL_OCT16P)) {\n normals = featureTable.getPropertyArray(\n \"NORMAL_OCT16P\",\n ComponentDatatype.UNSIGNED_BYTE,\n 2\n );\n const quantizationBits = 8;\n return {\n name: VertexAttributeSemantic.NORMAL,\n semantic: VertexAttributeSemantic.NORMAL,\n typedArray: normals,\n octEncoded: true,\n octEncodedZXY: false,\n quantizedRange: (1 << quantizationBits) - 1,\n quantizedType: AttributeType.VEC2,\n quantizedComponentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentDatatype: ComponentDatatype.FLOAT,\n type: AttributeType.VEC3,\n };\n }\n\n return undefined;\n}\n\nfunction parseBatchIds(featureTable) {\n const featureTableJson = featureTable.json;\n if (defined(featureTableJson.BATCH_ID)) {\n const batchIds = featureTable.getPropertyArray(\n \"BATCH_ID\",\n ComponentDatatype.UNSIGNED_SHORT,\n 1\n );\n return {\n name: VertexAttributeSemantic.FEATURE_ID,\n semantic: VertexAttributeSemantic.FEATURE_ID,\n setIndex: 0,\n typedArray: batchIds,\n componentDatatype: ComponentDatatype.fromTypedArray(batchIds),\n type: AttributeType.SCALAR,\n };\n }\n\n return undefined;\n}\n\nexport default PntsParser;\n", "import BoundingSphere from \"../../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../../Core/Cartesian3.js\";\nimport Cartographic from \"../../Core/Cartographic.js\";\nimport Check from \"../../Core/Check.js\";\nimport Credit from \"../../Core/Credit.js\";\nimport Color from \"../../Core/Color.js\";\nimport defined from \"../../Core/defined.js\";\nimport defaultValue from \"../../Core/defaultValue.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport destroyObject from \"../../Core/destroyObject.js\";\nimport DistanceDisplayCondition from \"../../Core/DistanceDisplayCondition.js\";\nimport Event from \"../../Core/Event.js\";\nimport Matrix3 from \"../../Core/Matrix3.js\";\nimport Matrix4 from \"../../Core/Matrix4.js\";\nimport Resource from \"../../Core/Resource.js\";\nimport RuntimeError from \"../../Core/RuntimeError.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport ClippingPlaneCollection from \"../ClippingPlaneCollection.js\";\nimport ColorBlendMode from \"../ColorBlendMode.js\";\nimport GltfLoader from \"../GltfLoader.js\";\nimport HeightReference from \"../HeightReference.js\";\nimport ImageBasedLighting from \"../ImageBasedLighting.js\";\nimport PointCloudShading from \"../PointCloudShading.js\";\nimport SceneMode from \"../SceneMode.js\";\nimport SceneTransforms from \"../SceneTransforms.js\";\nimport ShadowMode from \"../ShadowMode.js\";\nimport SplitDirection from \"../SplitDirection.js\";\nimport B3dmLoader from \"./B3dmLoader.js\";\nimport GeoJsonLoader from \"./GeoJsonLoader.js\";\nimport I3dmLoader from \"./I3dmLoader.js\";\nimport ModelAnimationCollection from \"./ModelAnimationCollection.js\";\nimport ModelFeatureTable from \"./ModelFeatureTable.js\";\nimport ModelSceneGraph from \"./ModelSceneGraph.js\";\nimport ModelStatistics from \"./ModelStatistics.js\";\nimport ModelType from \"./ModelType.js\";\nimport ModelUtility from \"./ModelUtility.js\";\nimport oneTimeWarning from \"../../Core/oneTimeWarning.js\";\nimport PntsLoader from \"./PntsLoader.js\";\nimport StyleCommandsNeeded from \"./StyleCommandsNeeded.js\";\n\n/**\n *
\n * To construct a Model, call {@link Model.fromGltfAsync}. Do not call the constructor directly.\n *
\n * A 3D model based on glTF, the runtime asset format for WebGL, OpenGL ES, and OpenGL.\n *

\n * Cesium supports glTF assets with the following extensions:\n *

    \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/AGI_articulations/README.md|AGI_articulations}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Vendor/CESIUM_RTC/README.md|CESIUM_RTC}\n *
  • \n *
  • \n * {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_instance_features|EXT_instance_features}\n *
  • \n *
  • \n * {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features|EXT_mesh_features}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing|EXT_mesh_gpu_instancing}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_meshopt_compression|EXT_meshopt_compression}\n *
  • \n *
  • \n * {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_texture_webp|EXT_texture_webp}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md|KHR_draco_mesh_compression}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_techniques_webgl/README.md|KHR_techniques_webgl}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/main/extensions/1.0/Khronos/KHR_materials_common/README.md|KHR_materials_common}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness|KHR_materials_pbrSpecularGlossiness}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit/README.md|KHR_materials_unlit}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_mesh_quantization|KHR_mesh_quantization}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_basisu|KHR_texture_basisu}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md|KHR_texture_transform}\n *
  • \n *
  • \n * {@link https://github.com/KhronosGroup/glTF/blob/main/extensions/1.0/Vendor/WEB3D_quantized_attributes/README.md|WEB3D_quantized_attributes}\n *
  • \n *
\n *

\n *

\n * Note: for models with compressed textures using the KHR_texture_basisu extension, we recommend power of 2 textures in both dimensions\n * for maximum compatibility. This is because some samplers require power of 2 textures ({@link https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Using_textures_in_WebGL|Using textures in WebGL})\n * and KHR_texture_basisu requires multiple of 4 dimensions ({@link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_basisu/README.md#additional-requirements|KHR_texture_basisu additional requirements}).\n *

\n *\n * @alias Model\n * @internalConstructor\n *\n * @privateParam {ResourceLoader} options.loader The loader used to load resources for this model.\n * @privateParam {ModelType} options.type Type of this model, to distinguish individual glTF files from 3D Tiles internally. \n * @privateParam {object} options Object with the following properties:\n * @privateParam {Resource} options.resource The Resource to the 3D model.\n * @privateParam {boolean} [options.show=true] Whether or not to render the model.\n * @privateParam {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the model from model to world coordinates.\n * @privateParam {number} [options.scale=1.0] A uniform scale applied to this model.\n * @privateParam {number} [options.minimumPixelSize=0.0] The approximate minimum pixel size of the model regardless of zoom.\n * @privateParam {number} [options.maximumScale] The maximum scale size of a model. An upper limit for minimumPixelSize.\n * @privateParam {object} [options.id] A user-defined object to return when the model is picked with {@link Scene#pick}.\n * @privateParam {boolean} [options.allowPicking=true] When true, each primitive is pickable with {@link Scene#pick}.\n * @privateParam {boolean} [options.clampAnimations=true] Determines if the model's animations should hold a pose over frames where no keyframes are specified.\n * @privateParam {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the model casts or receives shadows from light sources.\n * @privateParam {boolean} [options.debugShowBoundingVolume=false] For debugging only. Draws the bounding sphere for each draw command in the model.\n * @privateParam {boolean} [options.enableDebugWireframe=false] For debugging only. This must be set to true for debugWireframe to work in WebGL1. This cannot be set after the model has loaded.\n * @privateParam {boolean} [options.debugWireframe=false] For debugging only. Draws the model in wireframe. Will only work for WebGL1 if enableDebugWireframe is set to true.\n * @privateParam {boolean} [options.cull=true] Whether or not to cull the model using frustum/horizon culling. If the model is part of a 3D Tiles tileset, this property will always be false, since the 3D Tiles culling system is used.\n * @privateParam {boolean} [options.opaquePass=Pass.OPAQUE] The pass to use in the {@link DrawCommand} for the opaque portions of the model.\n * @privateParam {CustomShader} [options.customShader] A custom shader. This will add user-defined GLSL code to the vertex and fragment shaders. Using custom shaders with a {@link Cesium3DTileStyle} may lead to undefined behavior.\n * @privateParam {Cesium3DTileContent} [options.content] The tile content this model belongs to. This property will be undefined if model is not loaded as part of a tileset.\n * @privateParam {HeightReference} [options.heightReference=HeightReference.NONE] Determines how the model is drawn relative to terrain.\n * @privateParam {Scene} [options.scene] Must be passed in for models that use the height reference property.\n * @privateParam {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this model will be displayed.\n * @privateParam {Color} [options.color] A color that blends with the model's rendered color.\n * @privateParam {ColorBlendMode} [options.colorBlendMode=ColorBlendMode.HIGHLIGHT] Defines how the color blends with the model.\n * @privateParam {number} [options.colorBlendAmount=0.5] Value used to determine the color strength when the colorBlendMode is MIX. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.\n * @privateParam {Color} [options.silhouetteColor=Color.RED] The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.\n * @privateParam {number} [options.silhouetteSize=0.0] The size of the silhouette in pixels.\n * @privateParam {boolean} [options.enableShowOutline=true] Whether to enable outlines for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set to false to avoid the additional processing of geometry at load time. When false, the showOutlines and outlineColor options are ignored.\n * @privateParam {boolean} [options.showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.\n * @privateParam {Color} [options.outlineColor=Color.BLACK] The color to use when rendering outlines.\n * @privateParam {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.\n * @privateParam {Cartesian3} [options.lightColor] The light color when shading the model. When undefined the scene's light color is used instead.\n * @privateParam {ImageBasedLighting} [options.imageBasedLighting] The properties for managing image-based lighting on this model.\n * @privateParam {boolean} [options.backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.\n * @privateParam {Credit|string} [options.credit] A credit for the data source, which is displayed on the canvas.\n * @privateParam {boolean} [options.showCreditsOnScreen=false] Whether to display the credits of this model on screen.\n * @privateParam {SplitDirection} [options.splitDirection=SplitDirection.NONE] The {@link SplitDirection} split to apply to this model.\n * @privateParam {boolean} [options.projectTo2D=false] Whether to accurately project the model's positions in 2D. If this is true, the model will be projected accurately to 2D, but it will use more memory to do so. If this is false, the model will use less memory and will still render in 2D / CV mode, but its positions may be inaccurate. This disables minimumPixelSize and prevents future modification to the model matrix. This also cannot be set after the model has loaded.\n * @privateParam {string|number} [options.featureIdLabel=\"featureId_0\"] Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or \"featureId_N\" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled \"featureId_N\" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string \"featureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @privateParam {string|number} [options.instanceFeatureIdLabel=\"instanceFeatureId_0\"] Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string \"instanceFeatureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @privateParam {object} [options.pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation based on geometric error and lighting.\n * @privateParam {ClassificationType} [options.classificationType] Determines whether terrain, 3D Tiles or both will be classified by this model. This cannot be set after the model has loaded.\n \n *\n * @see Model.fromGltfAsync\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=3D%20Models.html|Cesium Sandcastle Models Demo}\n */\nfunction Model(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.loader\", options.loader);\n Check.typeOf.object(\"options.resource\", options.resource);\n //>>includeEnd('debug');\n\n /**\n * The loader used to load resources for this model.\n *\n * @type {ResourceLoader}\n * @private\n */\n this._loader = options.loader;\n this._resource = options.resource;\n\n /**\n * Type of this model, to distinguish individual glTF files from 3D Tiles\n * internally.\n *\n * @type {ModelType}\n * @readonly\n *\n * @private\n */\n this.type = defaultValue(options.type, ModelType.GLTF);\n\n /**\n * The 4x4 transformation matrix that transforms the model from model to world coordinates.\n * When this is the identity matrix, the model is drawn in world coordinates, i.e., Earth's Cartesian WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n * \n * @type {Matrix4}\n\n * @default {@link Matrix4.IDENTITY}\n *\n * @example\n * const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);\n * m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n this._modelMatrix = Matrix4.clone(this.modelMatrix);\n this._scale = defaultValue(options.scale, 1.0);\n\n this._minimumPixelSize = defaultValue(options.minimumPixelSize, 0.0);\n\n this._maximumScale = options.maximumScale;\n\n /**\n * The scale value after being clamped by the maximum scale parameter.\n * Used to adjust bounding spheres without repeated calculation.\n *\n * @type {number}\n * @private\n */\n this._clampedScale = defined(this._maximumScale)\n ? Math.min(this._scale, this._maximumScale)\n : this._scale;\n\n this._computedScale = this._clampedScale;\n\n /**\n * Whether or not the ModelSceneGraph should call updateModelMatrix.\n * This will be true if any of the model matrix, scale, minimum pixel size, or maximum scale are dirty.\n *\n * @type {number}\n * @private\n */\n this._updateModelMatrix = false;\n\n /**\n * If defined, this matrix is used to transform miscellaneous properties like\n * clipping planes and image-based lighting instead of the modelMatrix. This is\n * so that when models are part of a tileset, these properties get transformed\n * relative to a common reference (such as the root).\n *\n * @type {Matrix4}\n * @private\n */\n this.referenceMatrix = undefined;\n this._iblReferenceFrameMatrix = Matrix3.clone(Matrix3.IDENTITY); // Derived from reference matrix and the current view matrix\n\n this._resourcesLoaded = false;\n this._drawCommandsBuilt = false;\n\n this._ready = false;\n this._customShader = options.customShader;\n this._content = options.content;\n\n this._texturesLoaded = false;\n this._defaultTexture = undefined;\n\n this._activeAnimations = new ModelAnimationCollection(this);\n this._clampAnimations = defaultValue(options.clampAnimations, true);\n\n // This flag is true when the Cesium API, not a glTF animation, changes\n // the transform of a node in the model.\n this._userAnimationDirty = false;\n\n this._id = options.id;\n this._idDirty = false;\n\n this._color = Color.clone(options.color);\n this._colorBlendMode = defaultValue(\n options.colorBlendMode,\n ColorBlendMode.HIGHLIGHT\n );\n this._colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5);\n\n const silhouetteColor = defaultValue(options.silhouetteColor, Color.RED);\n this._silhouetteColor = Color.clone(silhouetteColor);\n this._silhouetteSize = defaultValue(options.silhouetteSize, 0.0);\n this._silhouetteDirty = false;\n\n // If silhouettes are used for the model, this will be set to the number\n // of the stencil buffer used for rendering the silhouette. This is set\n // by ModelSilhouettePipelineStage, not by Model itself.\n this._silhouetteId = undefined;\n\n this._cull = defaultValue(options.cull, true);\n this._opaquePass = defaultValue(options.opaquePass, Pass.OPAQUE);\n this._allowPicking = defaultValue(options.allowPicking, true);\n this._show = defaultValue(options.show, true);\n\n this._style = undefined;\n this._styleDirty = false;\n this._styleCommandsNeeded = undefined;\n\n let featureIdLabel = defaultValue(options.featureIdLabel, \"featureId_0\");\n if (typeof featureIdLabel === \"number\") {\n featureIdLabel = `featureId_${featureIdLabel}`;\n }\n this._featureIdLabel = featureIdLabel;\n\n let instanceFeatureIdLabel = defaultValue(\n options.instanceFeatureIdLabel,\n \"instanceFeatureId_0\"\n );\n if (typeof instanceFeatureIdLabel === \"number\") {\n instanceFeatureIdLabel = `instanceFeatureId_${instanceFeatureIdLabel}`;\n }\n this._instanceFeatureIdLabel = instanceFeatureIdLabel;\n\n this._featureTables = [];\n this._featureTableId = undefined;\n this._featureTableIdDirty = true;\n\n // Keeps track of resources that need to be destroyed when the draw commands are reset.\n this._pipelineResources = [];\n\n // Keeps track of resources that need to be destroyed when the Model is destroyed.\n this._modelResources = [];\n\n // Keeps track of the pick IDs for this model. These are stored and destroyed in the\n // pipeline resources array; the purpose of this array is to separate them from other\n // resources and update their ID objects when necessary.\n this._pickIds = [];\n\n // The model's bounding sphere and its initial radius are computed\n // in ModelSceneGraph.\n this._boundingSphere = new BoundingSphere();\n this._initialRadius = undefined;\n\n this._heightReference = defaultValue(\n options.heightReference,\n HeightReference.NONE\n );\n this._heightDirty = this._heightReference !== HeightReference.NONE;\n this._removeUpdateHeightCallback = undefined;\n\n this._clampedModelMatrix = undefined; // For use with height reference\n\n const scene = options.scene;\n if (defined(scene) && defined(scene.terrainProviderChanged)) {\n this._terrainProviderChangedCallback = scene.terrainProviderChanged.addEventListener(\n function () {\n this._heightDirty = true;\n },\n this\n );\n }\n this._scene = scene;\n\n this._distanceDisplayCondition = options.distanceDisplayCondition;\n\n const pointCloudShading = new PointCloudShading(options.pointCloudShading);\n this._pointCloudShading = pointCloudShading;\n this._attenuation = pointCloudShading.attenuation;\n this._pointCloudBackFaceCulling = pointCloudShading.backFaceCulling;\n\n // If the given clipping planes don't have an owner, make this model its owner.\n // Otherwise, the clipping planes are passed down from a tileset.\n const clippingPlanes = options.clippingPlanes;\n if (defined(clippingPlanes) && clippingPlanes.owner === undefined) {\n ClippingPlaneCollection.setOwner(clippingPlanes, this, \"_clippingPlanes\");\n } else {\n this._clippingPlanes = clippingPlanes;\n }\n this._clippingPlanesState = 0; // If this value changes, the shaders need to be regenerated.\n this._clippingPlanesMatrix = Matrix4.clone(Matrix4.IDENTITY); // Derived from reference matrix and the current view matrix\n\n this._lightColor = Cartesian3.clone(options.lightColor);\n\n this._imageBasedLighting = defined(options.imageBasedLighting)\n ? options.imageBasedLighting\n : new ImageBasedLighting();\n this._shouldDestroyImageBasedLighting = !defined(options.imageBasedLighting);\n\n this._backFaceCulling = defaultValue(options.backFaceCulling, true);\n this._backFaceCullingDirty = false;\n\n this._shadows = defaultValue(options.shadows, ShadowMode.ENABLED);\n this._shadowsDirty = false;\n\n this._debugShowBoundingVolumeDirty = false;\n this._debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n this._enableDebugWireframe = defaultValue(\n options.enableDebugWireframe,\n false\n );\n this._enableShowOutline = defaultValue(options.enableShowOutline, true);\n this._debugWireframe = defaultValue(options.debugWireframe, false);\n\n // Warning for improper setup of debug wireframe\n if (\n this._debugWireframe === true &&\n this._enableDebugWireframe === false &&\n this.type === ModelType.GLTF\n ) {\n oneTimeWarning(\n \"model-debug-wireframe-ignored\",\n \"enableDebugWireframe must be set to true in Model.fromGltf, otherwise debugWireframe will be ignored.\"\n );\n }\n\n // Credit specified by the user.\n let credit = options.credit;\n if (typeof credit === \"string\") {\n credit = new Credit(credit);\n }\n\n this._credit = credit;\n\n // Credits to be added from the Resource (if it is an IonResource)\n this._resourceCredits = [];\n\n // Credits parsed from the glTF by GltfLoader.\n this._gltfCredits = [];\n\n this._showCreditsOnScreen = defaultValue(options.showCreditsOnScreen, false);\n this._showCreditsOnScreenDirty = true;\n\n this._splitDirection = defaultValue(\n options.splitDirection,\n SplitDirection.NONE\n );\n\n this._enableShowOutline = defaultValue(options.enableShowOutline, true);\n\n /**\n * Whether to display the outline for models using the\n * {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension.\n * When true, outlines are displayed. When false, outlines are not displayed.\n *\n * @type {boolean}\n *\n * @default true\n */\n this.showOutline = defaultValue(options.showOutline, true);\n\n /**\n * The color to use when rendering outlines.\n *\n * @type {Color}\n *\n * @default Color.BLACK\n */\n this.outlineColor = defaultValue(options.outlineColor, Color.BLACK);\n\n this._classificationType = options.classificationType;\n\n this._statistics = new ModelStatistics();\n\n this._sceneMode = undefined;\n this._projectTo2D = defaultValue(options.projectTo2D, false);\n\n this._skipLevelOfDetail = false;\n this._ignoreCommands = defaultValue(options.ignoreCommands, false);\n\n this._errorEvent = new Event();\n this._readyEvent = new Event();\n this._texturesReadyEvent = new Event();\n\n this._sceneGraph = undefined;\n this._nodesByName = {}; // Stores the nodes by their names in the glTF.\n\n /**\n * Used for picking primitives that wrap a model.\n *\n * @private\n */\n this.pickObject = options.pickObject;\n}\n\nfunction handleError(model, error) {\n if (model._errorEvent.numberOfListeners > 0) {\n model._errorEvent.raiseEvent(error);\n return;\n }\n\n console.log(error);\n}\n\nfunction createModelFeatureTables(model, structuralMetadata) {\n const featureTables = model._featureTables;\n\n const propertyTables = structuralMetadata.propertyTables;\n const length = propertyTables.length;\n for (let i = 0; i < length; i++) {\n const propertyTable = propertyTables[i];\n const modelFeatureTable = new ModelFeatureTable({\n model: model,\n propertyTable: propertyTable,\n });\n\n featureTables.push(modelFeatureTable);\n }\n\n return featureTables;\n}\n\nfunction selectFeatureTableId(components, model) {\n const featureIdLabel = model._featureIdLabel;\n const instanceFeatureIdLabel = model._instanceFeatureIdLabel;\n\n let i, j;\n let featureIdAttribute;\n\n let node;\n // Scan the nodes till we find one with instances, get the feature table ID\n // if the feature ID attribute of the user-selected index is present.\n for (i = 0; i < components.nodes.length; i++) {\n node = components.nodes[i];\n if (defined(node.instances)) {\n featureIdAttribute = ModelUtility.getFeatureIdsByLabel(\n node.instances.featureIds,\n instanceFeatureIdLabel\n );\n if (\n defined(featureIdAttribute) &&\n defined(featureIdAttribute.propertyTableId)\n ) {\n return featureIdAttribute.propertyTableId;\n }\n }\n }\n\n // Scan the primitives till we find one with textures or attributes, get the feature table ID\n // if the feature ID attribute/texture of the user-selected index is present.\n for (i = 0; i < components.nodes.length; i++) {\n node = components.nodes[i];\n for (j = 0; j < node.primitives.length; j++) {\n const primitive = node.primitives[j];\n const featureIds = ModelUtility.getFeatureIdsByLabel(\n primitive.featureIds,\n featureIdLabel\n );\n\n if (defined(featureIds)) {\n return featureIds.propertyTableId;\n }\n }\n }\n\n // If there's only one feature table, then select it by default. This is\n // to ensure backwards compatibility with the older handling of b3dm models.\n if (model._featureTables.length === 1) {\n return 0;\n }\n}\n\n/**\n * Returns whether the alpha state has changed between invisible,\n * translucent, or opaque.\n *\n * @private\n */\nfunction isColorAlphaDirty(currentColor, previousColor) {\n if (!defined(currentColor) && !defined(previousColor)) {\n return false;\n }\n\n if (defined(currentColor) !== defined(previousColor)) {\n return true;\n }\n\n const currentAlpha = currentColor.alpha;\n const previousAlpha = previousColor.alpha;\n return (\n Math.floor(currentAlpha) !== Math.floor(previousAlpha) ||\n Math.ceil(currentAlpha) !== Math.ceil(previousAlpha)\n );\n}\n\nObject.defineProperties(Model.prototype, {\n /**\n * When true, this model is ready to render, i.e., the external binary, image,\n * and shader files were downloaded and the WebGL resources were created.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n /**\n * Gets an event that is raised when the model encounters an asynchronous rendering error. By subscribing\n * to the event, you will be notified of the error and can potentially recover from it. Event listeners\n * are passed an instance of {@link ModelError}.\n * @memberof Model.prototype\n * @type {Event}\n * @readonly\n */\n errorEvent: {\n get: function () {\n return this._errorEvent;\n },\n },\n\n /**\n * Gets an event that is raised when the model is loaded and ready for rendering, i.e. when the external resources\n * have been downloaded and the WebGL resources are created. Event listeners\n * are passed an instance of the {@link Model}.\n *\n *

\n * If {@link Model.incrementallyLoadTextures} is true, this event will be raised before all textures are loaded and ready for rendering. Subscribe to {@link Model.texturesReadyEvent} to be notified when the textures are ready.\n *

\n *\n * @memberof Model.prototype\n * @type {Event}\n * @readonly\n */\n readyEvent: {\n get: function () {\n return this._readyEvent;\n },\n },\n\n /**\n * Returns true if textures are loaded separately from the other glTF resources.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n incrementallyLoadTextures: {\n get: function () {\n return defaultValue(this._loader.incrementallyLoadTextures, false);\n },\n },\n\n /**\n * Gets an event that, if {@link Model.incrementallyLoadTextures} is true, is raised when the model textures are loaded and ready for rendering, i.e. when the external resources\n * have been downloaded and the WebGL resources are created. Event listeners\n * are passed an instance of the {@link Model}.\n *\n * @memberof Model.prototype\n * @type {Event}\n * @readonly\n */\n texturesReadyEvent: {\n get: function () {\n return this._texturesReadyEvent;\n },\n },\n\n /**\n * @private\n */\n loader: {\n get: function () {\n return this._loader;\n },\n },\n\n /**\n * Get the estimated memory usage statistics for this model.\n *\n * @memberof Model.prototype\n *\n * @type {ModelStatistics}\n * @readonly\n *\n * @private\n */\n statistics: {\n get: function () {\n return this._statistics;\n },\n },\n\n /**\n * The currently playing glTF animations.\n *\n * @memberof Model.prototype\n *\n * @type {ModelAnimationCollection}\n * @readonly\n */\n activeAnimations: {\n get: function () {\n return this._activeAnimations;\n },\n },\n\n /**\n * Determines if the model's animations should hold a pose over frames where no keyframes are specified.\n *\n * @memberof Model.prototype\n * @type {boolean}\n *\n * @default true\n */\n clampAnimations: {\n get: function () {\n return this._clampAnimations;\n },\n set: function (value) {\n this._clampAnimations = value;\n },\n },\n\n /**\n * Whether or not to cull the model using frustum/horizon culling. If the model is part of a 3D Tiles tileset, this property\n * will always be false, since the 3D Tiles culling system is used.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n cull: {\n get: function () {\n return this._cull;\n },\n },\n\n /**\n * The pass to use in the {@link DrawCommand} for the opaque portions of the model.\n *\n * @memberof Model.prototype\n *\n * @type {Pass}\n * @readonly\n *\n * @private\n */\n opaquePass: {\n get: function () {\n return this._opaquePass;\n },\n },\n\n /**\n * Point cloud shading settings for controlling point cloud attenuation\n * and lighting. For 3D Tiles, this is inherited from the\n * {@link Cesium3DTileset}.\n *\n * @memberof Model.prototype\n *\n * @type {PointCloudShading}\n */\n pointCloudShading: {\n get: function () {\n return this._pointCloudShading;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"pointCloudShading\", value);\n //>>includeEnd('debug');\n if (value !== this._pointCloudShading) {\n this.resetDrawCommands();\n }\n this._pointCloudShading = value;\n },\n },\n\n /**\n * The model's custom shader, if it exists. Using custom shaders with a {@link Cesium3DTileStyle}\n * may lead to undefined behavior.\n *\n * @memberof Model.prototype\n *\n * @type {CustomShader}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n customShader: {\n get: function () {\n return this._customShader;\n },\n set: function (value) {\n if (value !== this._customShader) {\n this.resetDrawCommands();\n }\n this._customShader = value;\n },\n },\n\n /**\n * The scene graph of this model.\n *\n * @memberof Model.prototype\n *\n * @type {ModelSceneGraph}\n * @private\n */\n sceneGraph: {\n get: function () {\n return this._sceneGraph;\n },\n },\n\n /**\n * The tile content this model belongs to, if it is loaded as part of a {@link Cesium3DTileset}.\n *\n * @memberof Model.prototype\n *\n * @type {Cesium3DTileContent}\n * @readonly\n *\n * @private\n */\n content: {\n get: function () {\n return this._content;\n },\n },\n\n /**\n * The height reference of the model, which determines how the model is drawn\n * relative to terrain.\n *\n * @memberof Model.prototype\n *\n * @type {HeightReference}\n * @default {HeightReference.NONE}\n *\n */\n heightReference: {\n get: function () {\n return this._heightReference;\n },\n set: function (value) {\n if (value !== this._heightReference) {\n this._heightDirty = true;\n }\n this._heightReference = value;\n },\n },\n\n /**\n * Gets or sets the distance display condition, which specifies at what distance\n * from the camera this model will be displayed.\n *\n * @memberof Model.prototype\n *\n * @type {DistanceDisplayCondition}\n *\n * @default undefined\n *\n */\n distanceDisplayCondition: {\n get: function () {\n return this._distanceDisplayCondition;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\"far must be greater than near\");\n }\n //>>includeEnd('debug');\n this._distanceDisplayCondition = DistanceDisplayCondition.clone(\n value,\n this._distanceDisplayCondition\n );\n },\n },\n\n /**\n * The structural metadata from the EXT_structural_metadata extension\n *\n * @memberof Model.prototype\n *\n * @type {StructuralMetadata}\n * @readonly\n *\n * @private\n */\n structuralMetadata: {\n get: function () {\n return this._sceneGraph.components.structuralMetadata;\n },\n },\n\n /**\n * The ID for the feature table to use for picking and styling in this model.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n *\n * @private\n */\n featureTableId: {\n get: function () {\n return this._featureTableId;\n },\n set: function (value) {\n this._featureTableId = value;\n },\n },\n\n /**\n * The feature tables for this model.\n *\n * @memberof Model.prototype\n *\n * @type {Array}\n * @readonly\n *\n * @private\n */\n featureTables: {\n get: function () {\n return this._featureTables;\n },\n set: function (value) {\n this._featureTables = value;\n },\n },\n\n /**\n * A user-defined object that is returned when the model is picked.\n *\n * @memberof Model.prototype\n *\n * @type {object}\n *\n * @default undefined\n *\n * @see Scene#pick\n */\n id: {\n get: function () {\n return this._id;\n },\n set: function (value) {\n if (value !== this._id) {\n this._idDirty = true;\n }\n\n this._id = value;\n },\n },\n\n /**\n * When true, each primitive is pickable with {@link Scene#pick}. When false, GPU memory is saved.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n allowPicking: {\n get: function () {\n return this._allowPicking;\n },\n },\n\n /**\n * The style to apply to the features in the model. Cannot be applied if a {@link CustomShader} is also applied.\n *\n * @memberof Model.prototype\n *\n * @type {Cesium3DTileStyle}\n */\n style: {\n get: function () {\n return this._style;\n },\n set: function (value) {\n this._style = value;\n this._styleDirty = true;\n },\n },\n\n /**\n * The color to blend with the model's rendered color.\n *\n * @memberof Model.prototype\n *\n * @type {Color}\n *\n * @default undefined\n */\n color: {\n get: function () {\n return this._color;\n },\n set: function (value) {\n if (isColorAlphaDirty(value, this._color)) {\n this.resetDrawCommands();\n }\n this._color = Color.clone(value, this._color);\n },\n },\n\n /**\n * Defines how the color blends with the model.\n *\n * @memberof Model.prototype\n *\n * @type {Cesium3DTileColorBlendMode|ColorBlendMode}\n *\n * @default ColorBlendMode.HIGHLIGHT\n */\n colorBlendMode: {\n get: function () {\n return this._colorBlendMode;\n },\n set: function (value) {\n this._colorBlendMode = value;\n },\n },\n\n /**\n * Value used to determine the color strength when the colorBlendMode is MIX. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n *\n * @default 0.5\n */\n colorBlendAmount: {\n get: function () {\n return this._colorBlendAmount;\n },\n set: function (value) {\n this._colorBlendAmount = value;\n },\n },\n\n /**\n * The silhouette color.\n *\n * @memberof Model.prototype\n *\n * @type {Color}\n *\n * @default Color.RED\n */\n silhouetteColor: {\n get: function () {\n return this._silhouetteColor;\n },\n set: function (value) {\n if (!Color.equals(value, this._silhouetteColor)) {\n const alphaDirty = isColorAlphaDirty(value, this._silhouetteColor);\n this._silhouetteDirty = this._silhouetteDirty || alphaDirty;\n }\n\n this._silhouetteColor = Color.clone(value, this._silhouetteColor);\n },\n },\n\n /**\n * The size of the silhouette in pixels.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n *\n * @default 0.0\n */\n silhouetteSize: {\n get: function () {\n return this._silhouetteSize;\n },\n set: function (value) {\n if (value !== this._silhouetteSize) {\n const currentSize = this._silhouetteSize;\n const sizeDirty =\n (value > 0.0 && currentSize === 0.0) ||\n (value === 0.0 && currentSize > 0.0);\n this._silhouetteDirty = this._silhouetteDirty || sizeDirty;\n\n // Back-face culling needs to be updated in case the silhouette size\n // is greater than zero.\n this._backFaceCullingDirty = this._backFaceCullingDirty || sizeDirty;\n }\n\n this._silhouetteSize = value;\n },\n },\n\n /**\n * Gets the model's bounding sphere in world space. This does not take into account\n * glTF animations, skins, or morph targets. It also does not account for\n * {@link Model#minimumPixelSize}.\n *\n * @memberof Model.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n //>>includeStart('debug', pragmas.debug);\n if (!this._ready) {\n throw new DeveloperError(\n \"The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\"\n );\n }\n //>>includeEnd('debug');\n\n const modelMatrix = defined(this._clampedModelMatrix)\n ? this._clampedModelMatrix\n : this.modelMatrix;\n updateBoundingSphere(this, modelMatrix);\n\n return this._boundingSphere;\n },\n },\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the model.\n *

\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n *\n * @default false\n */\n debugShowBoundingVolume: {\n get: function () {\n return this._debugShowBoundingVolume;\n },\n set: function (value) {\n if (this._debugShowBoundingVolume !== value) {\n this._debugShowBoundingVolumeDirty = true;\n }\n this._debugShowBoundingVolume = value;\n },\n },\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the model in wireframe.\n *

\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n *\n * @default false\n */\n debugWireframe: {\n get: function () {\n return this._debugWireframe;\n },\n set: function (value) {\n if (this._debugWireframe !== value) {\n this.resetDrawCommands();\n }\n this._debugWireframe = value;\n\n // Warning for improper setup of debug wireframe\n if (\n this._debugWireframe === true &&\n this._enableDebugWireframe === false &&\n this.type === ModelType.GLTF\n ) {\n oneTimeWarning(\n \"model-debug-wireframe-ignored\",\n \"enableDebugWireframe must be set to true in Model.fromGltfAsync, otherwise debugWireframe will be ignored.\"\n );\n }\n },\n },\n\n /**\n * Whether or not to render the model.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n *\n * @default true\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n this._show = value;\n },\n },\n\n /**\n * Label of the feature ID set to use for picking and styling.\n *

\n * For EXT_mesh_features, this is the feature ID's label property, or\n * \"featureId_N\" (where N is the index in the featureIds array) when not\n * specified. EXT_feature_metadata did not have a label field, so such\n * feature ID sets are always labeled \"featureId_N\" where N is the index in\n * the list of all feature Ids, where feature ID attributes are listed before\n * feature ID textures.\n *

\n *

\n * If featureIdLabel is set to an integer N, it is converted to\n * the string \"featureId_N\" automatically. If both per-primitive and\n * per-instance feature IDs are present, the instance feature IDs take\n * priority.\n *

\n *\n * @memberof Model.prototype\n *\n * @type {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n featureIdLabel: {\n get: function () {\n return this._featureIdLabel;\n },\n set: function (value) {\n // indices get converted into featureId_N\n if (typeof value === \"number\") {\n value = `featureId_${value}`;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"value\", value);\n //>>includeEnd('debug');\n\n if (value !== this._featureIdLabel) {\n this._featureTableIdDirty = true;\n }\n\n this._featureIdLabel = value;\n },\n },\n\n /**\n * Label of the instance feature ID set used for picking and styling.\n *

\n * If instanceFeatureIdLabel is set to an integer N, it is converted to\n * the string \"instanceFeatureId_N\" automatically.\n * If both per-primitive and per-instance feature IDs are present, the\n * instance feature IDs take priority.\n *

\n *\n * @memberof Model.prototype\n *\n * @type {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n instanceFeatureIdLabel: {\n get: function () {\n return this._instanceFeatureIdLabel;\n },\n set: function (value) {\n // indices get converted into instanceFeatureId_N\n if (typeof value === \"number\") {\n value = `instanceFeatureId_${value}`;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"value\", value);\n //>>includeEnd('debug');\n\n if (value !== this._instanceFeatureIdLabel) {\n this._featureTableIdDirty = true;\n }\n\n this._instanceFeatureIdLabel = value;\n },\n },\n\n /**\n * The {@link ClippingPlaneCollection} used to selectively disable rendering the model.\n *\n * @memberof Model.prototype\n *\n * @type {ClippingPlaneCollection}\n */\n clippingPlanes: {\n get: function () {\n return this._clippingPlanes;\n },\n set: function (value) {\n if (value !== this._clippingPlanes) {\n // Handle destroying old clipping planes, new clipping planes ownership\n ClippingPlaneCollection.setOwner(value, this, \"_clippingPlanes\");\n this.resetDrawCommands();\n }\n },\n },\n\n /**\n * The light color when shading the model. When undefined the scene's light color is used instead.\n *

\n * Disabling additional light sources by setting\n * model.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)\n * will make the model much darker. Here, increasing the intensity of the light source will make the model brighter.\n *

\n * @memberof Model.prototype\n *\n * @type {Cartesian3}\n *\n * @default undefined\n */\n lightColor: {\n get: function () {\n return this._lightColor;\n },\n set: function (value) {\n if (defined(value) !== defined(this._lightColor)) {\n this.resetDrawCommands();\n }\n\n this._lightColor = Cartesian3.clone(value, this._lightColor);\n },\n },\n\n /**\n * The properties for managing image-based lighting on this model.\n *\n * @memberof Model.prototype\n *\n * @type {ImageBasedLighting}\n */\n imageBasedLighting: {\n get: function () {\n return this._imageBasedLighting;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"imageBasedLighting\", this._imageBasedLighting);\n //>>includeEnd('debug');\n\n if (value !== this._imageBasedLighting) {\n if (\n this._shouldDestroyImageBasedLighting &&\n !this._imageBasedLighting.isDestroyed()\n ) {\n this._imageBasedLighting.destroy();\n }\n this._imageBasedLighting = value;\n this._shouldDestroyImageBasedLighting = false;\n this.resetDrawCommands();\n }\n },\n },\n\n /**\n * Whether to cull back-facing geometry. When true, back face culling is\n * determined by the material's doubleSided property; when false, back face\n * culling is disabled. Back faces are not culled if {@link Model#color}\n * is translucent or {@link Model#silhouetteSize} is greater than 0.0.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n *\n * @default true\n */\n backFaceCulling: {\n get: function () {\n return this._backFaceCulling;\n },\n set: function (value) {\n if (value !== this._backFaceCulling) {\n this._backFaceCullingDirty = true;\n }\n\n this._backFaceCulling = value;\n },\n },\n\n /**\n * A uniform scale applied to this model before the {@link Model#modelMatrix}.\n * Values greater than 1.0 increase the size of the model; values\n * less than 1.0 decrease.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n *\n * @default 1.0\n */\n scale: {\n get: function () {\n return this._scale;\n },\n set: function (value) {\n if (value !== this._scale) {\n this._updateModelMatrix = true;\n }\n this._scale = value;\n },\n },\n\n /**\n * The true scale of the model after being affected by the model's scale,\n * minimum pixel size, and maximum scale parameters.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n computedScale: {\n get: function () {\n return this._computedScale;\n },\n },\n\n /**\n * The approximate minimum pixel size of the model regardless of zoom.\n * This can be used to ensure that a model is visible even when the viewer\n * zooms out. When 0.0, no minimum size is enforced.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n *\n * @default 0.0\n */\n minimumPixelSize: {\n get: function () {\n return this._minimumPixelSize;\n },\n set: function (value) {\n if (value !== this._minimumPixelSize) {\n this._updateModelMatrix = true;\n }\n this._minimumPixelSize = value;\n },\n },\n\n /**\n * The maximum scale size for a model. This can be used to give\n * an upper limit to the {@link Model#minimumPixelSize}, ensuring that the model\n * is never an unreasonable scale.\n *\n * @memberof Model.prototype\n *\n * @type {number}\n */\n maximumScale: {\n get: function () {\n return this._maximumScale;\n },\n set: function (value) {\n if (value !== this._maximumScale) {\n this._updateModelMatrix = true;\n }\n this._maximumScale = value;\n },\n },\n\n /**\n * Determines whether the model casts or receives shadows from light sources.\n\n * @memberof Model.prototype\n *\n * @type {ShadowMode}\n *\n * @default ShadowMode.ENABLED\n */\n shadows: {\n get: function () {\n return this._shadows;\n },\n set: function (value) {\n if (value !== this._shadows) {\n this._shadowsDirty = true;\n }\n\n this._shadows = value;\n },\n },\n\n /**\n * Gets the credit that will be displayed for the model.\n *\n * @memberof Model.prototype\n *\n * @type {Credit}\n * @readonly\n */\n credit: {\n get: function () {\n return this._credit;\n },\n },\n\n /**\n * Gets or sets whether the credits of the model will be displayed\n * on the screen.\n *\n * @memberof Model.prototype\n *\n * @type {boolean}\n *\n * @default false\n */\n showCreditsOnScreen: {\n get: function () {\n return this._showCreditsOnScreen;\n },\n set: function (value) {\n if (this._showCreditsOnScreen !== value) {\n this._showCreditsOnScreenDirty = true;\n }\n\n this._showCreditsOnScreen = value;\n },\n },\n\n /**\n * The {@link SplitDirection} to apply to this model.\n *\n * @memberof Model.prototype\n *\n * @type {SplitDirection}\n *\n * @default {@link SplitDirection.NONE}\n */\n splitDirection: {\n get: function () {\n return this._splitDirection;\n },\n set: function (value) {\n if (this._splitDirection !== value) {\n this.resetDrawCommands();\n }\n this._splitDirection = value;\n },\n },\n\n /**\n * Gets the model's classification type. This determines whether terrain,\n * 3D Tiles, or both will be classified by this model.\n *

\n * Additionally, there are a few requirements/limitations:\n *

    \n *
  • The glTF cannot contain morph targets, skins, or animations.
  • \n *
  • The glTF cannot contain the EXT_mesh_gpu_instancing extension.
  • \n *
  • Only meshes with TRIANGLES can be used to classify other assets.
  • \n *
  • The position attribute is required.
  • \n *
  • If feature IDs and an index buffer are both present, all indices with the same feature id must occupy contiguous sections of the index buffer.
  • \n *
  • If feature IDs are present without an index buffer, all positions with the same feature id must occupy contiguous sections of the position buffer.
  • \n *
\n *

\n *\n * @memberof Model.prototype\n *\n * @type {ClassificationType}\n * @default undefined\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n * @readonly\n */\n classificationType: {\n get: function () {\n return this._classificationType;\n },\n },\n\n /**\n * Reference to the pick IDs. This is only used internally, e.g. for\n * per-feature post-processing in {@link PostProcessStage}.\n *\n * @memberof Model.prototype\n *\n * @type {PickId[]}\n * @readonly\n *\n * @private\n */\n pickIds: {\n get: function () {\n return this._pickIds;\n },\n },\n\n /**\n * The {@link StyleCommandsNeeded} for the style currently applied to\n * the features in the model. This is used internally by the {@link ModelDrawCommand}\n * when determining which commands to submit in an update.\n *\n * @memberof Model.prototype\n *\n * @type {StyleCommandsNeeded}\n * @readonly\n *\n * @private\n */\n styleCommandsNeeded: {\n get: function () {\n return this._styleCommandsNeeded;\n },\n },\n});\n\n/**\n * Returns the node with the given name in the glTF. This is used to\n * modify a node's transform for user-defined animation.\n *\n * @param {string} name The name of the node in the glTF.\n * @returns {ModelNode} The node, or undefined if no node with the name exists.\n *\n * @exception {DeveloperError} The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\n *\n * @example\n * // Apply non-uniform scale to node \"Hand\"\n * const node = model.getNode(\"Hand\");\n * node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);\n */\nModel.prototype.getNode = function (name) {\n //>>includeStart('debug', pragmas.debug);\n if (!this._ready) {\n throw new DeveloperError(\n \"The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\"\n );\n }\n Check.typeOf.string(\"name\", name);\n //>>includeEnd('debug');\n\n return this._nodesByName[name];\n};\n\n/**\n * Sets the current value of an articulation stage. After setting one or\n * multiple stage values, call Model.applyArticulations() to\n * cause the node matrices to be recalculated.\n *\n * @param {string} articulationStageKey The name of the articulation, a space, and the name of the stage.\n * @param {number} value The numeric value of this stage of the articulation.\n *\n * @exception {DeveloperError} The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\n *\n * @see Model#applyArticulations\n *\n * @example\n * // Sets the value of the stage named \"MoveX\" belonging to the articulation named \"SampleArticulation\"\n * model.setArticulationStage(\"SampleArticulation MoveX\", 50.0);\n */\nModel.prototype.setArticulationStage = function (articulationStageKey, value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n if (!this._ready) {\n throw new DeveloperError(\n \"The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\"\n );\n }\n //>>includeEnd('debug');\n\n this._sceneGraph.setArticulationStage(articulationStageKey, value);\n};\n\n/**\n * Applies any modified articulation stages to the matrix of each node that\n * participates in any articulation. Note that this will overwrite any node\n * transformations on participating nodes.\n *\n * @exception {DeveloperError} The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\n */\nModel.prototype.applyArticulations = function () {\n //>>includeStart('debug', pragmas.debug);\n if (!this._ready) {\n throw new DeveloperError(\n \"The model is not loaded. Use Model.readyEvent or wait for Model.ready to be true.\"\n );\n }\n //>>includeEnd('debug');\n\n this._sceneGraph.applyArticulations();\n};\n\n/**\n * Marks the model's {@link Model#style} as dirty, which forces all features\n * to re-evaluate the style in the next frame the model is visible.\n */\nModel.prototype.makeStyleDirty = function () {\n this._styleDirty = true;\n};\n\n/**\n * Resets the draw commands for this model.\n *\n * @private\n */\nModel.prototype.resetDrawCommands = function () {\n this._drawCommandsBuilt = false;\n};\n\nconst scratchIBLReferenceFrameMatrix4 = new Matrix4();\nconst scratchIBLReferenceFrameMatrix3 = new Matrix3();\nconst scratchClippingPlanesMatrix = new Matrix4();\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {RuntimeError} Failed to load external reference.\n */\nModel.prototype.update = function (frameState) {\n let finishedProcessing = false;\n try {\n // Keep processing the model every frame until the main resources\n // (buffer views) and textures (which may be loaded asynchronously)\n // are processed.\n finishedProcessing = processLoader(this, frameState);\n } catch (error) {\n if (\n !this._loader.incrementallyLoadTextures &&\n error.name === \"TextureError\"\n ) {\n handleError(this, error);\n } else {\n const runtimeError = ModelUtility.getError(\n \"model\",\n this._resource,\n error\n );\n handleError(this, runtimeError);\n }\n }\n\n // A custom shader may have to load texture uniforms.\n updateCustomShader(this, frameState);\n\n // The image-based lighting may have to load texture uniforms\n // for specular maps.\n updateImageBasedLighting(this, frameState);\n\n if (!this._resourcesLoaded && finishedProcessing) {\n this._resourcesLoaded = true;\n\n const components = this._loader.components;\n if (!defined(components)) {\n if (this._loader.isUnloaded()) {\n return;\n }\n\n const error = ModelUtility.getError(\n \"model\",\n this._resource,\n new RuntimeError(\"Failed to load model.\")\n );\n handleError(error);\n this._rejectLoad = this._rejectLoad && this._rejectLoad(error);\n }\n\n const structuralMetadata = components.structuralMetadata;\n if (\n defined(structuralMetadata) &&\n structuralMetadata.propertyTableCount > 0\n ) {\n createModelFeatureTables(this, structuralMetadata);\n }\n\n const sceneGraph = new ModelSceneGraph({\n model: this,\n modelComponents: components,\n });\n\n this._sceneGraph = sceneGraph;\n this._gltfCredits = sceneGraph.components.asset.credits;\n }\n\n // Short-circuit if the model resources aren't ready or the scene\n // is currently morphing.\n if (!this._resourcesLoaded || frameState.mode === SceneMode.MORPHING) {\n return;\n }\n\n updateFeatureTableId(this);\n updateStyle(this);\n updateFeatureTables(this, frameState);\n updatePointCloudShading(this);\n updateSilhouette(this, frameState);\n updateSkipLevelOfDetail(this, frameState);\n updateClippingPlanes(this, frameState);\n updateSceneMode(this, frameState);\n\n this._defaultTexture = frameState.context.defaultTexture;\n\n buildDrawCommands(this, frameState);\n updateModelMatrix(this, frameState);\n\n // Many features (e.g. image-based lighting, clipping planes) depend on the model\n // matrix being updated for the current height reference, so update it first.\n updateClamping(this);\n\n updateBoundingSphereAndScale(this, frameState);\n updateReferenceMatrices(this, frameState);\n\n // This check occurs after the bounding sphere has been updated so that\n // zooming to the bounding sphere can account for any modifications\n // from the clamp-to-ground setting.\n if (!this._ready) {\n // Set the model as ready after the first frame render since the user might set up events subscribed to\n // the post render event, and the model may not be ready for those past the first frame.\n frameState.afterRender.push(() => {\n this._ready = true;\n this._readyEvent.raiseEvent(this);\n });\n\n // Don't render until the next frame after the ready event has been raised.\n return;\n }\n\n if (\n this._loader.incrementallyLoadTextures &&\n !this._texturesLoaded &&\n this._loader.texturesLoaded\n ) {\n // Re-run the pipeline so texture memory statistics are re-computed\n this.resetDrawCommands();\n\n this._texturesLoaded = true;\n this._texturesReadyEvent.raiseEvent(this);\n }\n\n updatePickIds(this);\n\n // Update the scene graph and draw commands for any changes in model's properties\n // (e.g. model matrix, back-face culling)\n updateSceneGraph(this, frameState);\n updateShowCreditsOnScreen(this);\n submitDrawCommands(this, frameState);\n};\n\nfunction processLoader(model, frameState) {\n if (!model._resourcesLoaded || !model._texturesLoaded) {\n // Ensures frames continue to render in requestRender mode while resources are processing\n frameState.afterRender.push(() => true);\n return model._loader.process(frameState);\n }\n\n return true;\n}\n\nfunction updateCustomShader(model, frameState) {\n if (defined(model._customShader)) {\n model._customShader.update(frameState);\n }\n}\n\nfunction updateImageBasedLighting(model, frameState) {\n model._imageBasedLighting.update(frameState);\n if (model._imageBasedLighting.shouldRegenerateShaders) {\n model.resetDrawCommands();\n }\n}\n\nfunction updateFeatureTableId(model) {\n if (!model._featureTableIdDirty) {\n return;\n }\n model._featureTableIdDirty = false;\n\n const components = model._sceneGraph.components;\n const structuralMetadata = components.structuralMetadata;\n\n if (\n defined(structuralMetadata) &&\n structuralMetadata.propertyTableCount > 0\n ) {\n model.featureTableId = selectFeatureTableId(components, model);\n\n // Mark the style dirty to re-apply it and reflect the new feature ID table.\n model._styleDirty = true;\n\n // Trigger a rebuild of the draw commands.\n model.resetDrawCommands();\n }\n}\n\nfunction updateStyle(model) {\n if (model._styleDirty) {\n model.applyStyle(model._style);\n model._styleDirty = false;\n }\n}\n\nfunction updateFeatureTables(model, frameState) {\n const featureTables = model._featureTables;\n const length = featureTables.length;\n\n let styleCommandsNeededDirty = false;\n for (let i = 0; i < length; i++) {\n featureTables[i].update(frameState);\n // Check if the types of style commands needed have changed and trigger a reset of the draw commands\n // to ensure that translucent and opaque features are handled in the correct passes.\n if (featureTables[i].styleCommandsNeededDirty) {\n styleCommandsNeededDirty = true;\n }\n }\n\n if (styleCommandsNeededDirty) {\n updateStyleCommandsNeeded(model);\n }\n}\n\nfunction updateStyleCommandsNeeded(model) {\n const featureTable = model.featureTables[model.featureTableId];\n model._styleCommandsNeeded = StyleCommandsNeeded.getStyleCommandsNeeded(\n featureTable.featuresLength,\n featureTable.batchTexture.translucentFeaturesLength\n );\n}\n\nfunction updatePointCloudShading(model) {\n const pointCloudShading = model.pointCloudShading;\n\n // Check if the shader needs to be updated for point cloud attenuation\n // settings.\n if (pointCloudShading.attenuation !== model._attenuation) {\n model.resetDrawCommands();\n model._attenuation = pointCloudShading.attenuation;\n }\n\n if (pointCloudShading.backFaceCulling !== model._pointCloudBackFaceCulling) {\n model.resetDrawCommands();\n model._pointCloudBackFaceCulling = pointCloudShading.backFaceCulling;\n }\n}\n\nfunction updateSilhouette(model, frameState) {\n if (model._silhouetteDirty) {\n // Only rebuild draw commands if silhouettes are supported in the first place.\n if (supportsSilhouettes(frameState)) {\n model.resetDrawCommands();\n }\n\n model._silhouetteDirty = false;\n }\n}\n\nfunction updateSkipLevelOfDetail(model, frameState) {\n const skipLevelOfDetail = model.hasSkipLevelOfDetail(frameState);\n if (skipLevelOfDetail !== model._skipLevelOfDetail) {\n model.resetDrawCommands();\n model._skipLevelOfDetail = skipLevelOfDetail;\n }\n}\n\nfunction updateClippingPlanes(model, frameState) {\n // Update the clipping planes collection / state for this model to detect any changes.\n let currentClippingPlanesState = 0;\n if (model.isClippingEnabled()) {\n if (model._clippingPlanes.owner === model) {\n model._clippingPlanes.update(frameState);\n }\n currentClippingPlanesState = model._clippingPlanes.clippingPlanesState;\n }\n\n if (currentClippingPlanesState !== model._clippingPlanesState) {\n model.resetDrawCommands();\n model._clippingPlanesState = currentClippingPlanesState;\n }\n}\n\nfunction updateSceneMode(model, frameState) {\n if (frameState.mode !== model._sceneMode) {\n if (model._projectTo2D) {\n model.resetDrawCommands();\n } else {\n model._updateModelMatrix = true;\n }\n model._sceneMode = frameState.mode;\n }\n}\n\nfunction buildDrawCommands(model, frameState) {\n if (!model._drawCommandsBuilt) {\n model.destroyPipelineResources();\n model._sceneGraph.buildDrawCommands(frameState);\n model._drawCommandsBuilt = true;\n }\n}\n\nfunction updateModelMatrix(model, frameState) {\n // This is done without a dirty flag so that the model matrix can be updated in-place\n // without needing to use a setter.\n if (!Matrix4.equals(model.modelMatrix, model._modelMatrix)) {\n //>>includeStart('debug', pragmas.debug);\n if (frameState.mode !== SceneMode.SCENE3D && model._projectTo2D) {\n throw new DeveloperError(\n \"Model.modelMatrix cannot be changed in 2D or Columbus View if projectTo2D is true.\"\n );\n }\n //>>includeEnd('debug');\n model._updateModelMatrix = true;\n model._modelMatrix = Matrix4.clone(model.modelMatrix, model._modelMatrix);\n }\n}\n\nconst scratchPosition = new Cartesian3();\nconst scratchCartographic = new Cartographic();\n\nfunction updateClamping(model) {\n if (\n !model._updateModelMatrix &&\n !model._heightDirty &&\n model._minimumPixelSize === 0.0\n ) {\n return;\n }\n\n if (defined(model._removeUpdateHeightCallback)) {\n model._removeUpdateHeightCallback();\n model._removeUpdateHeightCallback = undefined;\n }\n\n const scene = model._scene;\n if (\n !defined(scene) ||\n !defined(scene.globe) ||\n model.heightReference === HeightReference.NONE\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (model.heightReference !== HeightReference.NONE) {\n throw new DeveloperError(\n \"Height reference is not supported without a scene and globe.\"\n );\n }\n //>>includeEnd('debug');\n model._clampedModelMatrix = undefined;\n return;\n }\n\n const globe = scene.globe;\n const ellipsoid = globe.ellipsoid;\n\n // Compute cartographic position so we don't recompute every update\n const modelMatrix = model.modelMatrix;\n scratchPosition.x = modelMatrix[12];\n scratchPosition.y = modelMatrix[13];\n scratchPosition.z = modelMatrix[14];\n const cartoPosition = ellipsoid.cartesianToCartographic(scratchPosition);\n\n if (!defined(model._clampedModelMatrix)) {\n model._clampedModelMatrix = Matrix4.clone(modelMatrix, new Matrix4());\n }\n\n // Install callback to handle updating of terrain tiles\n const surface = globe._surface;\n model._removeUpdateHeightCallback = surface.updateHeight(\n cartoPosition,\n getUpdateHeightCallback(model, ellipsoid, cartoPosition)\n );\n\n // Set the correct height now\n const height = globe.getHeight(cartoPosition);\n if (defined(height)) {\n // Get callback with cartoPosition being the non-clamped position\n const callback = getUpdateHeightCallback(model, ellipsoid, cartoPosition);\n\n // Compute the clamped cartesian and call updateHeight callback\n Cartographic.clone(cartoPosition, scratchCartographic);\n scratchCartographic.height = height;\n ellipsoid.cartographicToCartesian(scratchCartographic, scratchPosition);\n callback(scratchPosition);\n }\n\n model._heightDirty = false;\n model._updateModelMatrix = true;\n}\n\nfunction updateBoundingSphereAndScale(model, frameState) {\n if (!model._updateModelMatrix && model._minimumPixelSize === 0.0) {\n return;\n }\n\n const modelMatrix = defined(model._clampedModelMatrix)\n ? model._clampedModelMatrix\n : model.modelMatrix;\n\n updateBoundingSphere(model, modelMatrix);\n updateComputedScale(model, modelMatrix, frameState);\n}\n\nfunction updateBoundingSphere(model, modelMatrix) {\n model._clampedScale = defined(model._maximumScale)\n ? Math.min(model._scale, model._maximumScale)\n : model._scale;\n\n model._boundingSphere.center = Cartesian3.multiplyByScalar(\n model._sceneGraph.boundingSphere.center,\n model._clampedScale,\n model._boundingSphere.center\n );\n model._boundingSphere.radius = model._initialRadius * model._clampedScale;\n\n model._boundingSphere = BoundingSphere.transform(\n model._boundingSphere,\n modelMatrix,\n model._boundingSphere\n );\n}\n\nfunction updateComputedScale(model, modelMatrix, frameState) {\n let scale = model.scale;\n\n if (model.minimumPixelSize !== 0.0 && !model._projectTo2D) {\n // Compute size of bounding sphere in pixels\n const context = frameState.context;\n const maxPixelSize = Math.max(\n context.drawingBufferWidth,\n context.drawingBufferHeight\n );\n\n Matrix4.getTranslation(modelMatrix, scratchPosition);\n\n if (model._sceneMode !== SceneMode.SCENE3D) {\n SceneTransforms.computeActualWgs84Position(\n frameState,\n scratchPosition,\n scratchPosition\n );\n }\n\n const radius = model._boundingSphere.radius;\n const metersPerPixel = scaleInPixels(scratchPosition, radius, frameState);\n\n // metersPerPixel is always > 0.0\n const pixelsPerMeter = 1.0 / metersPerPixel;\n const diameterInPixels = Math.min(\n pixelsPerMeter * (2.0 * radius),\n maxPixelSize\n );\n\n // Maintain model's minimum pixel size\n if (diameterInPixels < model.minimumPixelSize) {\n scale =\n (model.minimumPixelSize * metersPerPixel) /\n (2.0 * model._initialRadius);\n }\n }\n\n model._computedScale = defined(model.maximumScale)\n ? Math.min(model.maximumScale, scale)\n : scale;\n}\n\nfunction updatePickIds(model) {\n if (!model._idDirty) {\n return;\n }\n model._idDirty = false;\n\n const id = model._id;\n const pickIds = model._pickIds;\n const length = pickIds.length;\n for (let i = 0; i < length; ++i) {\n pickIds[i].object.id = id;\n }\n}\n\nfunction updateReferenceMatrices(model, frameState) {\n const modelMatrix = defined(model._clampedModelMatrix)\n ? model._clampedModelMatrix\n : model.modelMatrix;\n const referenceMatrix = defaultValue(model.referenceMatrix, modelMatrix);\n const context = frameState.context;\n\n const ibl = model._imageBasedLighting;\n if (ibl.useSphericalHarmonicCoefficients || ibl.useSpecularEnvironmentMaps) {\n let iblReferenceFrameMatrix3 = scratchIBLReferenceFrameMatrix3;\n let iblReferenceFrameMatrix4 = scratchIBLReferenceFrameMatrix4;\n\n iblReferenceFrameMatrix4 = Matrix4.multiply(\n context.uniformState.view3D,\n referenceMatrix,\n iblReferenceFrameMatrix4\n );\n iblReferenceFrameMatrix3 = Matrix4.getMatrix3(\n iblReferenceFrameMatrix4,\n iblReferenceFrameMatrix3\n );\n iblReferenceFrameMatrix3 = Matrix3.getRotation(\n iblReferenceFrameMatrix3,\n iblReferenceFrameMatrix3\n );\n model._iblReferenceFrameMatrix = Matrix3.transpose(\n iblReferenceFrameMatrix3,\n model._iblReferenceFrameMatrix\n );\n }\n\n if (model.isClippingEnabled()) {\n let clippingPlanesMatrix = scratchClippingPlanesMatrix;\n clippingPlanesMatrix = Matrix4.multiply(\n context.uniformState.view3D,\n referenceMatrix,\n clippingPlanesMatrix\n );\n clippingPlanesMatrix = Matrix4.multiply(\n clippingPlanesMatrix,\n model._clippingPlanes.modelMatrix,\n clippingPlanesMatrix\n );\n model._clippingPlanesMatrix = Matrix4.inverseTranspose(\n clippingPlanesMatrix,\n model._clippingPlanesMatrix\n );\n }\n}\n\nfunction updateSceneGraph(model, frameState) {\n const sceneGraph = model._sceneGraph;\n if (model._updateModelMatrix || model._minimumPixelSize !== 0.0) {\n const modelMatrix = defined(model._clampedModelMatrix)\n ? model._clampedModelMatrix\n : model.modelMatrix;\n sceneGraph.updateModelMatrix(modelMatrix, frameState);\n model._updateModelMatrix = false;\n }\n\n if (model._backFaceCullingDirty) {\n sceneGraph.updateBackFaceCulling(model._backFaceCulling);\n model._backFaceCullingDirty = false;\n }\n\n if (model._shadowsDirty) {\n sceneGraph.updateShadows(model._shadows);\n model._shadowsDirty = false;\n }\n\n if (model._debugShowBoundingVolumeDirty) {\n sceneGraph.updateShowBoundingVolume(model._debugShowBoundingVolume);\n model._debugShowBoundingVolumeDirty = false;\n }\n\n let updateForAnimations = false;\n // Animations are disabled for classification models.\n if (!defined(model.classificationType)) {\n updateForAnimations =\n model._userAnimationDirty || model._activeAnimations.update(frameState);\n }\n sceneGraph.update(frameState, updateForAnimations);\n model._userAnimationDirty = false;\n}\n\nfunction updateShowCreditsOnScreen(model) {\n if (!model._showCreditsOnScreenDirty) {\n return;\n }\n model._showCreditsOnScreenDirty = false;\n\n const showOnScreen = model._showCreditsOnScreen;\n if (defined(model._credit)) {\n model._credit.showOnScreen = showOnScreen || model._credit._isDefaultToken;\n }\n\n const resourceCredits = model._resourceCredits;\n const resourceCreditsLength = resourceCredits.length;\n for (let i = 0; i < resourceCreditsLength; i++) {\n resourceCredits[i].showOnScreen =\n showOnScreen || resourceCredits[i]._isDefaultToken;\n }\n\n const gltfCredits = model._gltfCredits;\n const gltfCreditsLength = gltfCredits.length;\n for (let i = 0; i < gltfCreditsLength; i++) {\n gltfCredits[i].showOnScreen =\n showOnScreen || gltfCredits[i]._isDefaultToken;\n }\n}\n\nfunction submitDrawCommands(model, frameState) {\n // Check that show is true after draw commands are built;\n // we want the user to be able to instantly see the model\n // when show is set to true.\n\n const displayConditionPassed = passesDistanceDisplayCondition(\n model,\n frameState\n );\n\n const invisible = model.isInvisible();\n const silhouette = model.hasSilhouette(frameState);\n\n // If the model is invisible but has a silhouette, it still\n // needs to draw in order to write to the stencil buffer and\n // render the silhouette.\n const showModel =\n model._show &&\n model._computedScale !== 0 &&\n displayConditionPassed &&\n (!invisible || silhouette);\n\n const passes = frameState.passes;\n const submitCommandsForPass =\n passes.render || (passes.pick && model.allowPicking);\n\n if (showModel && !model._ignoreCommands && submitCommandsForPass) {\n addCreditsToCreditDisplay(model, frameState);\n model._sceneGraph.pushDrawCommands(frameState);\n }\n}\n\nconst scratchBoundingSphere = new BoundingSphere();\n\nfunction scaleInPixels(positionWC, radius, frameState) {\n scratchBoundingSphere.center = positionWC;\n scratchBoundingSphere.radius = radius;\n return frameState.camera.getPixelSize(\n scratchBoundingSphere,\n frameState.context.drawingBufferWidth,\n frameState.context.drawingBufferHeight\n );\n}\n\nfunction getUpdateHeightCallback(model, ellipsoid, cartoPosition) {\n return function (clampedPosition) {\n if (model.heightReference === HeightReference.RELATIVE_TO_GROUND) {\n const clampedCart = ellipsoid.cartesianToCartographic(\n clampedPosition,\n scratchCartographic\n );\n clampedCart.height += cartoPosition.height;\n ellipsoid.cartographicToCartesian(clampedCart, clampedPosition);\n }\n\n const clampedModelMatrix = model._clampedModelMatrix;\n\n // Modify clamped model matrix to use new height\n Matrix4.clone(model.modelMatrix, clampedModelMatrix);\n clampedModelMatrix[12] = clampedPosition.x;\n clampedModelMatrix[13] = clampedPosition.y;\n clampedModelMatrix[14] = clampedPosition.z;\n\n model._heightDirty = true;\n };\n}\n\nconst scratchDisplayConditionCartesian = new Cartesian3();\n\nfunction passesDistanceDisplayCondition(model, frameState) {\n const condition = model.distanceDisplayCondition;\n if (!defined(condition)) {\n return true;\n }\n\n const nearSquared = condition.near * condition.near;\n const farSquared = condition.far * condition.far;\n let distanceSquared;\n\n if (frameState.mode === SceneMode.SCENE2D) {\n const frustum2DWidth =\n frameState.camera.frustum.right - frameState.camera.frustum.left;\n const distance = frustum2DWidth * 0.5;\n distanceSquared = distance * distance;\n } else {\n // Distance to center of primitive's reference frame\n const position = Matrix4.getTranslation(\n model.modelMatrix,\n scratchDisplayConditionCartesian\n );\n\n // This will project the position if the scene is in Columbus View,\n // but leave the position as-is in 3D mode.\n SceneTransforms.computeActualWgs84Position(frameState, position, position);\n\n distanceSquared = Cartesian3.distanceSquared(\n position,\n frameState.camera.positionWC\n );\n }\n\n return distanceSquared >= nearSquared && distanceSquared <= farSquared;\n}\n\nfunction addCreditsToCreditDisplay(model, frameState) {\n const creditDisplay = frameState.creditDisplay;\n // Add all credits to the credit display.\n const credit = model._credit;\n if (defined(credit)) {\n creditDisplay.addCreditToNextFrame(credit);\n }\n\n const resourceCredits = model._resourceCredits;\n const resourceCreditsLength = resourceCredits.length;\n for (let c = 0; c < resourceCreditsLength; c++) {\n creditDisplay.addCreditToNextFrame(resourceCredits[c]);\n }\n\n const gltfCredits = model._gltfCredits;\n const gltfCreditsLength = gltfCredits.length;\n for (let c = 0; c < gltfCreditsLength; c++) {\n creditDisplay.addCreditToNextFrame(gltfCredits[c]);\n }\n}\n\n/**\n * Gets whether or not the model is translucent based on its assigned model color.\n * If the model color's alpha is equal to zero, then it is considered invisible,\n * not translucent.\n *\n * @returns {boolean} true if the model is translucent, otherwise false.\n * @private\n */\nModel.prototype.isTranslucent = function () {\n const color = this.color;\n return defined(color) && color.alpha > 0.0 && color.alpha < 1.0;\n};\n\n/**\n * Gets whether or not the model is invisible, i.e. if the model color's alpha\n * is equal to zero.\n *\n * @returns {boolean} true if the model is invisible, otherwise false.\n * @private\n */\nModel.prototype.isInvisible = function () {\n const color = this.color;\n return defined(color) && color.alpha === 0.0;\n};\n\nfunction supportsSilhouettes(frameState) {\n return frameState.context.stencilBuffer;\n}\n\n/**\n * Gets whether or not the model has a silhouette. This accounts for whether\n * silhouettes are supported (i.e. the context supports stencil buffers).\n *

\n * If the model classifies another model, its silhouette will be disabled.\n *

\n *\n * @param {FrameState} The frame state.\n * @returns {boolean} true if the model has silhouettes, otherwise false.\n * @private\n */\nModel.prototype.hasSilhouette = function (frameState) {\n return (\n supportsSilhouettes(frameState) &&\n this._silhouetteSize > 0.0 &&\n this._silhouetteColor.alpha > 0.0 &&\n !defined(this._classificationType)\n );\n};\n\n/**\n * Gets whether or not the model is part of a tileset that uses the\n * skipLevelOfDetail optimization. This accounts for whether skipLevelOfDetail\n * is supported (i.e. the context supports stencil buffers).\n *\n * @param {FrameState} frameState The frame state.\n * @returns {boolean} true if the model is part of a tileset that uses the skipLevelOfDetail optimization, false otherwise.\n * @private\n */\nModel.prototype.hasSkipLevelOfDetail = function (frameState) {\n if (!ModelType.is3DTiles(this.type)) {\n return false;\n }\n\n const supportsSkipLevelOfDetail = frameState.context.stencilBuffer;\n const tileset = this._content.tileset;\n return supportsSkipLevelOfDetail && tileset.isSkippingLevelOfDetail;\n};\n\n/**\n * Gets whether or not clipping planes are enabled for this model.\n *\n * @returns {boolean} true if clipping planes are enabled for this model, false.\n * @private\n */\nModel.prototype.isClippingEnabled = function () {\n const clippingPlanes = this._clippingPlanes;\n return (\n defined(clippingPlanes) &&\n clippingPlanes.enabled &&\n clippingPlanes.length !== 0\n );\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see Model#destroy\n */\nModel.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * model = model && model.destroy();\n *\n * @see Model#isDestroyed\n */\nModel.prototype.destroy = function () {\n const loader = this._loader;\n if (defined(loader)) {\n loader.destroy();\n }\n\n const featureTables = this._featureTables;\n if (defined(featureTables)) {\n const length = featureTables.length;\n for (let i = 0; i < length; i++) {\n featureTables[i].destroy();\n }\n }\n\n this.destroyPipelineResources();\n this.destroyModelResources();\n\n // Remove callbacks for height reference behavior.\n if (defined(this._removeUpdateHeightCallback)) {\n this._removeUpdateHeightCallback();\n this._removeUpdateHeightCallback = undefined;\n }\n\n if (defined(this._terrainProviderChangedCallback)) {\n this._terrainProviderChangedCallback();\n this._terrainProviderChangedCallback = undefined;\n }\n\n // Only destroy the ClippingPlaneCollection if this is the owner.\n const clippingPlaneCollection = this._clippingPlanes;\n if (\n defined(clippingPlaneCollection) &&\n !clippingPlaneCollection.isDestroyed() &&\n clippingPlaneCollection.owner === this\n ) {\n clippingPlaneCollection.destroy();\n }\n this._clippingPlanes = undefined;\n\n // Only destroy the ImageBasedLighting if this is the owner.\n if (\n this._shouldDestroyImageBasedLighting &&\n !this._imageBasedLighting.isDestroyed()\n ) {\n this._imageBasedLighting.destroy();\n }\n this._imageBasedLighting = undefined;\n\n destroyObject(this);\n};\n\n/**\n * Destroys resources generated in the pipeline stages\n * that must be destroyed when draw commands are rebuilt.\n * @private\n */\nModel.prototype.destroyPipelineResources = function () {\n const resources = this._pipelineResources;\n for (let i = 0; i < resources.length; i++) {\n resources[i].destroy();\n }\n this._pipelineResources.length = 0;\n this._pickIds.length = 0;\n};\n\n/**\n * Destroys resources generated in the pipeline stages\n * that exist for the lifetime of the model.\n * @private\n */\nModel.prototype.destroyModelResources = function () {\n const resources = this._modelResources;\n for (let i = 0; i < resources.length; i++) {\n resources[i].destroy();\n }\n this._modelResources.length = 0;\n};\n\n/**\n *

\n * Asynchronously creates a model from a glTF asset. This function returns a promise that resolves when the model is ready to render, i.e., when the external binary, image,\n * and shader files are downloaded and the WebGL resources are created.\n *

\n *

\n * The model can be a traditional glTF asset with a .gltf extension or a Binary glTF using the .glb extension.\n *\n * @param {object} options Object with the following properties:\n * @param {string|Resource} options.url The url to the .gltf or .glb file.\n * @param {string|Resource} [options.basePath=''] The base path that paths in the glTF JSON are relative to.\n * @param {boolean} [options.show=true] Whether or not to render the model.\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms the model from model to world coordinates.\n * @param {number} [options.scale=1.0] A uniform scale applied to this model.\n * @param {number} [options.minimumPixelSize=0.0] The approximate minimum pixel size of the model regardless of zoom.\n * @param {number} [options.maximumScale] The maximum scale size of a model. An upper limit for minimumPixelSize.\n * @param {object} [options.id] A user-defined object to return when the model is picked with {@link Scene#pick}.\n * @param {boolean} [options.allowPicking=true] When true, each primitive is pickable with {@link Scene#pick}.\n * @param {boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the model is loaded.\n * @param {boolean} [options.asynchronous=true] Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded.\n * @param {boolean} [options.clampAnimations=true] Determines if the model's animations should hold a pose over frames where no keyframes are specified.\n * @param {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the model casts or receives shadows from light sources.\n * @param {boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Draws the bounding sphere for each draw command in the model.\n * @param {boolean} [options.enableDebugWireframe=false] For debugging only. This must be set to true for debugWireframe to work in WebGL1. This cannot be set after the model has loaded.\n * @param {boolean} [options.debugWireframe=false] For debugging only. Draws the model in wireframe. Will only work for WebGL1 if enableDebugWireframe is set to true.\n * @param {boolean} [options.cull=true] Whether or not to cull the model using frustum/horizon culling. If the model is part of a 3D Tiles tileset, this property will always be false, since the 3D Tiles culling system is used.\n * @param {boolean} [options.opaquePass=Pass.OPAQUE] The pass to use in the {@link DrawCommand} for the opaque portions of the model.\n * @param {Axis} [options.upAxis=Axis.Y] The up-axis of the glTF model.\n * @param {Axis} [options.forwardAxis=Axis.Z] The forward-axis of the glTF model.\n * @param {CustomShader} [options.customShader] A custom shader. This will add user-defined GLSL code to the vertex and fragment shaders. Using custom shaders with a {@link Cesium3DTileStyle} may lead to undefined behavior.\n * @param {Cesium3DTileContent} [options.content] The tile content this model belongs to. This property will be undefined if model is not loaded as part of a tileset.\n * @param {HeightReference} [options.heightReference=HeightReference.NONE] Determines how the model is drawn relative to terrain.\n * @param {Scene} [options.scene] Must be passed in for models that use the height reference property.\n * @param {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this model will be displayed.\n * @param {Color} [options.color] A color that blends with the model's rendered color.\n * @param {ColorBlendMode} [options.colorBlendMode=ColorBlendMode.HIGHLIGHT] Defines how the color blends with the model.\n * @param {number} [options.colorBlendAmount=0.5] Value used to determine the color strength when the colorBlendMode is MIX. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.\n * @param {Color} [options.silhouetteColor=Color.RED] The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts.\n * @param {number} [options.silhouetteSize=0.0] The size of the silhouette in pixels.\n * @param {boolean} [options.enableShowOutline=true] Whether to enable outlines for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time. When false, the showOutlines and outlineColor options are ignored.\n * @param {boolean} [options.showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.\n * @param {Color} [options.outlineColor=Color.BLACK] The color to use when rendering outlines.\n * @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.\n * @param {Cartesian3} [options.lightColor] The light color when shading the model. When undefined the scene's light color is used instead.\n * @param {ImageBasedLighting} [options.imageBasedLighting] The properties for managing image-based lighting on this model.\n * @param {boolean} [options.backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.\n * @param {Credit|string} [options.credit] A credit for the data source, which is displayed on the canvas.\n * @param {boolean} [options.showCreditsOnScreen=false] Whether to display the credits of this model on screen.\n * @param {SplitDirection} [options.splitDirection=SplitDirection.NONE] The {@link SplitDirection} split to apply to this model.\n * @param {boolean} [options.projectTo2D=false] Whether to accurately project the model's positions in 2D. If this is true, the model will be projected accurately to 2D, but it will use more memory to do so. If this is false, the model will use less memory and will still render in 2D / CV mode, but its positions may be inaccurate. This disables minimumPixelSize and prevents future modification to the model matrix. This also cannot be set after the model has loaded.\n * @param {string|number} [options.featureIdLabel=\"featureId_0\"] Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or \"featureId_N\" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled \"featureId_N\" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string \"featureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @param {string|number} [options.instanceFeatureIdLabel=\"instanceFeatureId_0\"] Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string \"instanceFeatureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @param {object} [options.pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation and lighting.\n * @param {ClassificationType} [options.classificationType] Determines whether terrain, 3D Tiles or both will be classified by this model. This cannot be set after the model has loaded.\n * @param {Model.GltfCallback} [options.gltfCallback] A function that is called with the loaded gltf object once loaded.\n *\n * @returns {Promise} A promise that resolves to the created model when it is ready to render.\n *\n * @exception {RuntimeError} The model failed to load.\n * @exception {RuntimeError} Unsupported glTF version.\n * @exception {RuntimeError} Unsupported glTF Extension\n *\n * @example\n * // Load a model and add it to the scene\n * try {\n * const model = await Cesium.Model.fromGltfAsync({\n * url: \"../../SampleData/models/CesiumMan/Cesium_Man.glb\"\n * });\n * viewer.scene.primitives.add(model);\n * } catch (error) {\n * console.log(`Failed to load model. ${error}`);\n * }\n *\n * @example\n * // Position a model with modelMatrix and display it with a minimum size of 128 pixels\n * const position = Cesium.Cartesian3.fromDegrees(\n * -123.0744619,\n * 44.0503706,\n * 5000.0\n * );\n * const headingPositionRoll = new Cesium.HeadingPitchRoll();\n * const fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator(\n * \"north\",\n * \"west\"\n * );\n * try {\n * const model = await Cesium.Model.fromGltfAsync({\n * url: \"../../SampleData/models/CesiumAir/Cesium_Air.glb\",\n * modelMatrix: Cesium.Transforms.headingPitchRollToFixedFrame(\n * position,\n * headingPositionRoll,\n * Cesium.Ellipsoid.WGS84,\n * fixedFrameTransform\n * ),\n * minimumPixelSize: 128,\n * });\n * viewer.scene.primitives.add(model);\n * } catch (error) {\n * console.log(`Failed to load model. ${error}`);\n * }\n *\n * @example\n * // Load a model and play the last animation at half speed\n * let animations;\n * try {\n * const model = await Cesium.Model.fromGltfAsync({\n * url: \"../../SampleData/models/CesiumMan/Cesium_Man.glb\",\n * gltfCallback: gltf => {\n * animations = gltf.animations\n * }\n * });\n * viewer.scene.primitives.add(model);\n * model.readyEvent.addEventListener(() => {\n * model.activeAnimations.add({\n * index: animations.length - 1,\n * loop: Cesium.ModelAnimationLoop.REPEAT,\n * multiplier: 0.5,\n * });\n * });\n * } catch (error) {\n * console.log(`Failed to load model. ${error}`);\n * }\n */\nModel.fromGltfAsync = async function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.url) && !defined(options.gltf)) {\n throw new DeveloperError(\"options.url is required.\");\n }\n //>>includeEnd('debug');\n\n // options.gltf is used internally for 3D Tiles. It can be a Resource, a URL\n // to a glTF/glb file, a binary glTF buffer, or a JSON object containing the\n // glTF contents.\n const gltf = defaultValue(options.url, options.gltf);\n\n const loaderOptions = {\n releaseGltfJson: options.releaseGltfJson,\n asynchronous: options.asynchronous,\n incrementallyLoadTextures: options.incrementallyLoadTextures,\n upAxis: options.upAxis,\n forwardAxis: options.forwardAxis,\n loadAttributesFor2D: options.projectTo2D,\n loadIndicesForWireframe: options.enableDebugWireframe,\n loadPrimitiveOutline: options.enableShowOutline,\n loadForClassification: defined(options.classificationType),\n };\n\n const basePath = defaultValue(options.basePath, \"\");\n const baseResource = Resource.createIfNeeded(basePath);\n\n if (defined(gltf.asset)) {\n loaderOptions.gltfJson = gltf;\n loaderOptions.baseResource = baseResource;\n loaderOptions.gltfResource = baseResource;\n } else if (gltf instanceof Uint8Array) {\n loaderOptions.typedArray = gltf;\n loaderOptions.baseResource = baseResource;\n loaderOptions.gltfResource = baseResource;\n } else {\n loaderOptions.gltfResource = Resource.createIfNeeded(gltf);\n }\n\n const loader = new GltfLoader(loaderOptions);\n\n const is3DTiles = defined(options.content);\n const type = is3DTiles ? ModelType.TILE_GLTF : ModelType.GLTF;\n\n const resource = loaderOptions.gltfResource;\n\n const modelOptions = makeModelOptions(loader, type, options);\n modelOptions.resource = resource;\n\n try {\n // This load the gltf JSON and ensures the gltf is valid\n // Further resource loading is handled synchronously in loader.process(), and requires\n // hooking into model's update() as the frameState is needed\n await loader.load();\n } catch (error) {\n loader.destroy();\n throw ModelUtility.getError(\"model\", resource, error);\n }\n\n const gltfCallback = options.gltfCallback;\n if (defined(gltfCallback)) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.func(\"options.gltfCallback\", gltfCallback);\n //>>includeEnd('debug');\n\n gltfCallback(loader.gltfJson);\n }\n\n const model = new Model(modelOptions);\n\n const resourceCredits = model._resource.credits;\n if (defined(resourceCredits)) {\n const length = resourceCredits.length;\n for (let i = 0; i < length; i++) {\n model._resourceCredits.push(resourceCredits[i]);\n }\n }\n\n return model;\n};\n\n/*\n * @private\n */\nModel.fromB3dm = async function (options) {\n const loaderOptions = {\n b3dmResource: options.resource,\n arrayBuffer: options.arrayBuffer,\n byteOffset: options.byteOffset,\n releaseGltfJson: options.releaseGltfJson,\n asynchronous: options.asynchronous,\n incrementallyLoadTextures: options.incrementallyLoadTextures,\n upAxis: options.upAxis,\n forwardAxis: options.forwardAxis,\n loadAttributesFor2D: options.projectTo2D,\n loadIndicesForWireframe: options.enableDebugWireframe,\n loadPrimitiveOutline: options.enableShowOutline,\n loadForClassification: defined(options.classificationType),\n };\n\n const loader = new B3dmLoader(loaderOptions);\n\n try {\n await loader.load();\n\n const modelOptions = makeModelOptions(loader, ModelType.TILE_B3DM, options);\n const model = new Model(modelOptions);\n return model;\n } catch (error) {\n loader.destroy();\n throw error;\n }\n};\n\n/**\n * @private\n */\nModel.fromPnts = async function (options) {\n const loaderOptions = {\n arrayBuffer: options.arrayBuffer,\n byteOffset: options.byteOffset,\n loadAttributesFor2D: options.projectTo2D,\n };\n const loader = new PntsLoader(loaderOptions);\n\n try {\n await loader.load();\n const modelOptions = makeModelOptions(loader, ModelType.TILE_PNTS, options);\n const model = new Model(modelOptions);\n return model;\n } catch (error) {\n loader.destroy();\n throw error;\n }\n};\n\n/*\n * @private\n */\nModel.fromI3dm = async function (options) {\n const loaderOptions = {\n i3dmResource: options.resource,\n arrayBuffer: options.arrayBuffer,\n byteOffset: options.byteOffset,\n releaseGltfJson: options.releaseGltfJson,\n asynchronous: options.asynchronous,\n incrementallyLoadTextures: options.incrementallyLoadTextures,\n upAxis: options.upAxis,\n forwardAxis: options.forwardAxis,\n loadAttributesFor2D: options.projectTo2D,\n loadIndicesForWireframe: options.enableDebugWireframe,\n loadPrimitiveOutline: options.enableShowOutline,\n };\n const loader = new I3dmLoader(loaderOptions);\n\n try {\n await loader.load();\n\n const modelOptions = makeModelOptions(loader, ModelType.TILE_I3DM, options);\n const model = new Model(modelOptions);\n return model;\n } catch (error) {\n loader.destroy();\n throw error;\n }\n};\n\n/*\n * @private\n */\nModel.fromGeoJson = async function (options) {\n const loaderOptions = {\n geoJson: options.geoJson,\n };\n const loader = new GeoJsonLoader(loaderOptions);\n const modelOptions = makeModelOptions(\n loader,\n ModelType.TILE_GEOJSON,\n options\n );\n const model = new Model(modelOptions);\n return model;\n};\n\nconst scratchColor = new Color();\n\n/**\n * @private\n */\nModel.prototype.applyColorAndShow = function (style) {\n const previousColor = Color.clone(this._color, scratchColor);\n const hasColorStyle = defined(style) && defined(style.color);\n const hasShowStyle = defined(style) && defined(style.show);\n\n this._color = hasColorStyle\n ? style.color.evaluateColor(undefined, this._color)\n : Color.clone(Color.WHITE, this._color);\n this._show = hasShowStyle ? style.show.evaluate(undefined) : true;\n\n if (isColorAlphaDirty(previousColor, this._color)) {\n this.resetDrawCommands();\n }\n};\n\n/**\n * @private\n */\nModel.prototype.applyStyle = function (style) {\n const isPnts = this.type === ModelType.TILE_PNTS;\n\n const hasFeatureTable =\n defined(this.featureTableId) &&\n this.featureTables[this.featureTableId].featuresLength > 0;\n\n const propertyAttributes = defined(this.structuralMetadata)\n ? this.structuralMetadata.propertyAttributes\n : undefined;\n const hasPropertyAttributes =\n defined(propertyAttributes) && defined(propertyAttributes[0]);\n\n // Point clouds will be styled on the GPU unless they contain a batch table.\n // That is, CPU styling will not be applied if:\n // - points have no metadata at all, or\n // - points have metadata stored as a property attribute\n if (isPnts && (!hasFeatureTable || hasPropertyAttributes)) {\n // Commands are rebuilt for point cloud styling since the new style may\n // contain different shader functions.\n this.resetDrawCommands();\n return;\n }\n\n // The style is only set by the ModelFeatureTable. If there are no features,\n // the color and show from the style are directly applied.\n if (hasFeatureTable) {\n const featureTable = this.featureTables[this.featureTableId];\n featureTable.applyStyle(style);\n updateStyleCommandsNeeded(this, style);\n } else {\n this.applyColorAndShow(style);\n this._styleCommandsNeeded = undefined;\n }\n};\n\nfunction makeModelOptions(loader, modelType, options) {\n return {\n loader: loader,\n type: modelType,\n resource: options.resource,\n show: options.show,\n modelMatrix: options.modelMatrix,\n scale: options.scale,\n minimumPixelSize: options.minimumPixelSize,\n maximumScale: options.maximumScale,\n id: options.id,\n allowPicking: options.allowPicking,\n clampAnimations: options.clampAnimations,\n shadows: options.shadows,\n debugShowBoundingVolume: options.debugShowBoundingVolume,\n enableDebugWireframe: options.enableDebugWireframe,\n debugWireframe: options.debugWireframe,\n cull: options.cull,\n opaquePass: options.opaquePass,\n customShader: options.customShader,\n content: options.content,\n heightReference: options.heightReference,\n scene: options.scene,\n distanceDisplayCondition: options.distanceDisplayCondition,\n color: options.color,\n colorBlendAmount: options.colorBlendAmount,\n colorBlendMode: options.colorBlendMode,\n silhouetteColor: options.silhouetteColor,\n silhouetteSize: options.silhouetteSize,\n enableShowOutline: options.enableShowOutline,\n showOutline: options.showOutline,\n outlineColor: options.outlineColor,\n clippingPlanes: options.clippingPlanes,\n lightColor: options.lightColor,\n imageBasedLighting: options.imageBasedLighting,\n backFaceCulling: options.backFaceCulling,\n credit: options.credit,\n showCreditsOnScreen: options.showCreditsOnScreen,\n splitDirection: options.splitDirection,\n projectTo2D: options.projectTo2D,\n featureIdLabel: options.featureIdLabel,\n instanceFeatureIdLabel: options.instanceFeatureIdLabel,\n pointCloudShading: options.pointCloudShading,\n classificationType: options.classificationType,\n pickObject: options.pickObject,\n };\n}\n\n/**\n * Interface for the function that is called with the loaded gltf object once loaded.\n * @callback Model.GltfCallback\n *\n * @param {object} gltf The gltf object\n */\n\nexport default Model;\n", "import Color from \"../../Core/Color.js\";\nimport combine from \"../../Core/combine.js\";\nimport defined from \"../../Core/defined.js\";\nimport destroyObject from \"../../Core/destroyObject.js\";\nimport DeveloperError from \"../../Core/DeveloperError.js\";\nimport Pass from \"../../Renderer/Pass.js\";\nimport ModelAnimationLoop from \"../ModelAnimationLoop.js\";\nimport Model from \"./Model.js\";\n\n/**\n * Represents the contents of a glTF, glb or\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/TileFormats/Batched3DModel|Batched 3D Model}\n * tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n * This object is normally not instantiated directly, use {@link Model3DTileContent.fromGltf}, {@link Model3DTileContent.fromB3dm}, {@link Model3DTileContent.fromI3dm}, {@link Model3DTileContent.fromPnts}, or {@link Model3DTileContent.fromGeoJson}.\n *\n * @alias Model3DTileContent\n * @constructor\n * @private\n */\nfunction Model3DTileContent(tileset, tile, resource) {\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n\n this._model = undefined;\n this._metadata = undefined;\n this._group = undefined;\n this._ready = false;\n}\n\nObject.defineProperties(Model3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n const model = this._model;\n const featureTables = model.featureTables;\n const featureTableId = model.featureTableId;\n\n if (defined(featureTables) && defined(featureTables[featureTableId])) {\n return featureTables[featureTableId].featuresLength;\n }\n\n return 0;\n },\n },\n\n pointsLength: {\n get: function () {\n return this._model.statistics.pointsLength;\n },\n },\n\n trianglesLength: {\n get: function () {\n return this._model.statistics.trianglesLength;\n },\n },\n\n geometryByteLength: {\n get: function () {\n return this._model.statistics.geometryByteLength;\n },\n },\n\n texturesByteLength: {\n get: function () {\n return this._model.statistics.texturesByteLength;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n const statistics = this._model.statistics;\n return (\n statistics.propertyTablesByteLength + statistics.batchTexturesByteLength\n );\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Model3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._resource.getUrlComponent(true);\n },\n },\n\n batchTable: {\n get: function () {\n const model = this._model;\n const featureTables = model.featureTables;\n const featureTableId = model.featureTableId;\n\n if (defined(featureTables) && defined(featureTables[featureTableId])) {\n return featureTables[featureTableId];\n }\n\n return undefined;\n },\n },\n\n metadata: {\n get: function () {\n return this._metadata;\n },\n set: function (value) {\n this._metadata = value;\n },\n },\n\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n },\n },\n});\n\nModel3DTileContent.prototype.getFeature = function (featureId) {\n const model = this._model;\n const featureTableId = model.featureTableId;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(featureTableId)) {\n throw new DeveloperError(\n \"No feature ID set is selected. Make sure Cesium3DTileset.featureIdLabel or Cesium3DTileset.instanceFeatureIdLabel is defined\"\n );\n }\n //>>includeEnd('debug');\n\n const featureTable = model.featureTables[featureTableId];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(featureTable)) {\n throw new DeveloperError(\n \"No feature table found for the selected feature ID set\"\n );\n }\n //>>includeEnd('debug');\n\n //>>includeStart('debug', pragmas.debug);\n const featuresLength = featureTable.featuresLength;\n if (!defined(featureId) || featureId < 0 || featureId >= featuresLength) {\n throw new DeveloperError(\n `featureId is required and must be between 0 and featuresLength - 1 (${\n featuresLength - 1\n }).`\n );\n }\n //>>includeEnd('debug');\n return featureTable.getFeature(featureId);\n};\n\nModel3DTileContent.prototype.hasProperty = function (featureId, name) {\n const model = this._model;\n const featureTableId = model.featureTableId;\n if (!defined(featureTableId)) {\n return false;\n }\n\n const featureTable = model.featureTables[featureTableId];\n return featureTable.hasProperty(featureId, name);\n};\n\nModel3DTileContent.prototype.applyDebugSettings = function (enabled, color) {\n color = enabled ? color : Color.WHITE;\n if (this.featuresLength === 0) {\n this._model.color = color;\n } else if (defined(this.batchTable)) {\n this.batchTable.setAllColor(color);\n }\n};\n\nModel3DTileContent.prototype.applyStyle = function (style) {\n // the setter will call model.applyStyle()\n this._model.style = style;\n};\n\nModel3DTileContent.prototype.update = function (tileset, frameState) {\n const model = this._model;\n const tile = this._tile;\n\n model.colorBlendAmount = tileset.colorBlendAmount;\n model.colorBlendMode = tileset.colorBlendMode;\n model.modelMatrix = tile.computedTransform;\n model.customShader = tileset.customShader;\n model.featureIdLabel = tileset.featureIdLabel;\n model.instanceFeatureIdLabel = tileset.instanceFeatureIdLabel;\n model.lightColor = tileset.lightColor;\n model.imageBasedLighting = tileset.imageBasedLighting;\n model.backFaceCulling = tileset.backFaceCulling;\n model.shadows = tileset.shadows;\n model.showCreditsOnScreen = tileset.showCreditsOnScreen;\n model.splitDirection = tileset.splitDirection;\n model.debugWireframe = tileset.debugWireframe;\n model.showOutline = tileset.showOutline;\n model.outlineColor = tileset.outlineColor;\n model.pointCloudShading = tileset.pointCloudShading;\n\n // Updating clipping planes requires more effort because of ownership checks\n const tilesetClippingPlanes = tileset.clippingPlanes;\n model.referenceMatrix = tileset.clippingPlanesOriginMatrix;\n if (defined(tilesetClippingPlanes) && tile.clippingPlanesDirty) {\n // Dereference the clipping planes from the model if they are irrelevant.\n model._clippingPlanes =\n tilesetClippingPlanes.enabled && tile._isClipped\n ? tilesetClippingPlanes\n : undefined;\n }\n\n // If the model references a different ClippingPlaneCollection from the tileset,\n // update the model to use the new ClippingPlaneCollection.\n if (\n defined(tilesetClippingPlanes) &&\n defined(model._clippingPlanes) &&\n model._clippingPlanes !== tilesetClippingPlanes\n ) {\n model._clippingPlanes = tilesetClippingPlanes;\n model._clippingPlanesState = 0;\n }\n\n model.update(frameState);\n\n if (!this._ready && model.ready) {\n // Animation can only be added once the model is ready\n model.activeAnimations.addAll({\n loop: ModelAnimationLoop.REPEAT,\n });\n\n this._ready = true;\n }\n};\n\nModel3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nModel3DTileContent.prototype.destroy = function () {\n this._model = this._model && this._model.destroy();\n return destroyObject(this);\n};\n\nModel3DTileContent.fromGltf = async function (tileset, tile, resource, gltf) {\n const content = new Model3DTileContent(tileset, tile, resource);\n\n const additionalOptions = {\n gltf: gltf,\n basePath: resource,\n };\n\n const modelOptions = makeModelOptions(\n tileset,\n tile,\n content,\n additionalOptions\n );\n\n const classificationType = tileset.vectorClassificationOnly\n ? undefined\n : tileset.classificationType;\n\n modelOptions.classificationType = classificationType;\n\n const model = await Model.fromGltfAsync(modelOptions);\n content._model = model;\n\n return content;\n};\n\nModel3DTileContent.fromB3dm = async function (\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n) {\n const content = new Model3DTileContent(tileset, tile, resource);\n\n const additionalOptions = {\n arrayBuffer: arrayBuffer,\n byteOffset: byteOffset,\n resource: resource,\n };\n\n const modelOptions = makeModelOptions(\n tileset,\n tile,\n content,\n additionalOptions\n );\n\n const classificationType = tileset.vectorClassificationOnly\n ? undefined\n : tileset.classificationType;\n\n modelOptions.classificationType = classificationType;\n\n const model = await Model.fromB3dm(modelOptions);\n content._model = model;\n\n return content;\n};\n\nModel3DTileContent.fromI3dm = async function (\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n) {\n const content = new Model3DTileContent(tileset, tile, resource);\n\n const additionalOptions = {\n arrayBuffer: arrayBuffer,\n byteOffset: byteOffset,\n resource: resource,\n };\n\n const modelOptions = makeModelOptions(\n tileset,\n tile,\n content,\n additionalOptions\n );\n\n const model = await Model.fromI3dm(modelOptions);\n content._model = model;\n\n return content;\n};\n\nModel3DTileContent.fromPnts = async function (\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n) {\n const content = new Model3DTileContent(tileset, tile, resource);\n\n const additionalOptions = {\n arrayBuffer: arrayBuffer,\n byteOffset: byteOffset,\n resource: resource,\n };\n\n const modelOptions = makeModelOptions(\n tileset,\n tile,\n content,\n additionalOptions\n );\n const model = await Model.fromPnts(modelOptions);\n content._model = model;\n\n return content;\n};\n\nModel3DTileContent.fromGeoJson = async function (\n tileset,\n tile,\n resource,\n geoJson\n) {\n const content = new Model3DTileContent(tileset, tile, resource);\n\n const additionalOptions = {\n geoJson: geoJson,\n resource: resource,\n };\n\n const modelOptions = makeModelOptions(\n tileset,\n tile,\n content,\n additionalOptions\n );\n const model = await Model.fromGeoJson(modelOptions);\n content._model = model;\n\n return content;\n};\n\nfunction makeModelOptions(tileset, tile, content, additionalOptions) {\n const mainOptions = {\n cull: false, // The model is already culled by 3D Tiles\n releaseGltfJson: true, // Models are unique and will not benefit from caching so save memory\n opaquePass: Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass\n modelMatrix: tile.computedTransform,\n upAxis: tileset._modelUpAxis,\n forwardAxis: tileset._modelForwardAxis,\n incrementallyLoadTextures: false,\n customShader: tileset.customShader,\n content: content,\n colorBlendMode: tileset.colorBlendMode,\n colorBlendAmount: tileset.colorBlendAmount,\n lightColor: tileset.lightColor,\n imageBasedLighting: tileset.imageBasedLighting,\n featureIdLabel: tileset.featureIdLabel,\n instanceFeatureIdLabel: tileset.instanceFeatureIdLabel,\n pointCloudShading: tileset.pointCloudShading,\n clippingPlanes: tileset.clippingPlanes,\n backFaceCulling: tileset.backFaceCulling,\n shadows: tileset.shadows,\n showCreditsOnScreen: tileset.showCreditsOnScreen,\n splitDirection: tileset.splitDirection,\n enableDebugWireframe: tileset._enableDebugWireframe,\n debugWireframe: tileset.debugWireframe,\n projectTo2D: tileset._projectTo2D,\n enableShowOutline: tileset._enableShowOutline,\n showOutline: tileset.showOutline,\n outlineColor: tileset.outlineColor,\n };\n\n return combine(additionalOptions, mainOptions);\n}\n\nexport default Model3DTileContent;\n", "import destroyObject from \"../Core/destroyObject.js\";\n\n/**\n * Represents content for a tile in a\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset whose\n * content points to another 3D Tiles tileset.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @alias Tileset3DTileContent\n * @constructor\n *\n * @private\n */\nfunction Tileset3DTileContent(tileset, tile, resource) {\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n\n this.featurePropertiesDirty = false;\n\n this._metadata = undefined;\n this._group = undefined;\n\n this._ready = false;\n}\n\nObject.defineProperties(Tileset3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n return 0;\n },\n },\n\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n trianglesLength: {\n get: function () {\n return 0;\n },\n },\n\n geometryByteLength: {\n get: function () {\n return 0;\n },\n },\n\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n return 0;\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Tileset3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._resource.getUrlComponent(true);\n },\n },\n\n batchTable: {\n get: function () {\n return undefined;\n },\n },\n\n metadata: {\n get: function () {\n return this._metadata;\n },\n set: function (value) {\n this._metadata = value;\n },\n },\n\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n },\n },\n});\n\n/**\n * Creates an instance of Tileset3DTileContent from a parsed JSON object\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n * @param {Resource} resource\n * @param {object} json\n * @returns {Tileset3DTileContent}\n */\nTileset3DTileContent.fromJson = function (tileset, tile, resource, json) {\n const content = new Tileset3DTileContent(tileset, tile, resource);\n content._tileset.loadTileset(content._resource, json, content._tile);\n content._ready = true;\n\n return content;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Tileset3DTileContent\n * always returns false since a tile of this type does not have any features.\n */\nTileset3DTileContent.prototype.hasProperty = function (batchId, name) {\n return false;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Tileset3DTileContent\n * always returns undefined since a tile of this type does not have any features.\n */\nTileset3DTileContent.prototype.getFeature = function (batchId) {\n return undefined;\n};\n\nTileset3DTileContent.prototype.applyDebugSettings = function (\n enabled,\n color\n) {};\n\nTileset3DTileContent.prototype.applyStyle = function (style) {};\n\nTileset3DTileContent.prototype.update = function (tileset, frameState) {};\n\nTileset3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nTileset3DTileContent.prototype.destroy = function () {\n return destroyObject(this);\n};\nexport default Tileset3DTileContent;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform sampler2D u_atlas;\\n\\\n\\n\\\n#ifdef VECTOR_TILE\\n\\\nuniform vec4 u_highlightColor;\\n\\\n#endif\\n\\\n\\n\\\nin vec2 v_textureCoordinates;\\n\\\nin vec4 v_pickColor;\\n\\\nin vec4 v_color;\\n\\\n\\n\\\n#ifdef SDF\\n\\\nin vec4 v_outlineColor;\\n\\\nin float v_outlineWidth;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\nin vec4 v_textureCoordinateBounds; // the min and max x and y values for the texture coordinates\\n\\\nin vec4 v_originTextureCoordinateAndTranslate; // texture coordinate at the origin, billboard translate (used for label glyphs)\\n\\\nin vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\\n\\\nin mat2 v_rotationMatrix;\\n\\\n\\n\\\nconst float SHIFT_LEFT12 = 4096.0;\\n\\\nconst float SHIFT_LEFT1 = 2.0;\\n\\\n\\n\\\nconst float SHIFT_RIGHT12 = 1.0 / 4096.0;\\n\\\nconst float SHIFT_RIGHT1 = 1.0 / 2.0;\\n\\\n\\n\\\nfloat getGlobeDepth(vec2 adjustedST, vec2 depthLookupST, bool applyTranslate, vec2 dimensions, vec2 imageSize)\\n\\\n{\\n\\\n vec2 lookupVector = imageSize * (depthLookupST - adjustedST);\\n\\\n lookupVector = v_rotationMatrix * lookupVector;\\n\\\n vec2 labelOffset = (dimensions - imageSize) * (depthLookupST - vec2(0.0, v_originTextureCoordinateAndTranslate.y)); // aligns label glyph with bounding rectangle. Will be zero for billboards because dimensions and imageSize will be equal\\n\\\n\\n\\\n vec2 translation = v_originTextureCoordinateAndTranslate.zw;\\n\\\n\\n\\\n if (applyTranslate)\\n\\\n {\\n\\\n // this is only needed for labels where the horizontal origin is not LEFT\\n\\\n // it moves the label back to where the \\\"origin\\\" should be since all label glyphs are set to HorizontalOrigin.LEFT\\n\\\n translation += (dimensions * v_originTextureCoordinateAndTranslate.xy * vec2(1.0, 0.0));\\n\\\n }\\n\\\n\\n\\\n vec2 st = ((lookupVector - translation + labelOffset) + gl_FragCoord.xy) / czm_viewport.zw;\\n\\\n float logDepthOrDepth = czm_unpackDepth(texture(czm_globeDepthTexture, st));\\n\\\n\\n\\\n if (logDepthOrDepth == 0.0)\\n\\\n {\\n\\\n return 0.0; // not on the globe\\n\\\n }\\n\\\n\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\\n\\\n return eyeCoordinate.z / eyeCoordinate.w;\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\n\\n\\\n#ifdef SDF\\n\\\n\\n\\\n// Get the distance from the edge of a glyph at a given position sampling an SDF texture.\\n\\\nfloat getDistance(vec2 position)\\n\\\n{\\n\\\n return texture(u_atlas, position).r;\\n\\\n}\\n\\\n\\n\\\n// Samples the sdf texture at the given position and produces a color based on the fill color and the outline.\\n\\\nvec4 getSDFColor(vec2 position, float outlineWidth, vec4 outlineColor, float smoothing)\\n\\\n{\\n\\\n float distance = getDistance(position);\\n\\\n\\n\\\n if (outlineWidth > 0.0)\\n\\\n {\\n\\\n // Don't get the outline edge exceed the SDF_EDGE\\n\\\n float outlineEdge = clamp(SDF_EDGE - outlineWidth, 0.0, SDF_EDGE);\\n\\\n float outlineFactor = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\\n\\\n vec4 sdfColor = mix(outlineColor, v_color, outlineFactor);\\n\\\n float alpha = smoothstep(outlineEdge - smoothing, outlineEdge + smoothing, distance);\\n\\\n return vec4(sdfColor.rgb, sdfColor.a * alpha);\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n float alpha = smoothstep(SDF_EDGE - smoothing, SDF_EDGE + smoothing, distance);\\n\\\n return vec4(v_color.rgb, v_color.a * alpha);\\n\\\n }\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n vec4 color = texture(u_atlas, v_textureCoordinates);\\n\\\n\\n\\\n#ifdef SDF\\n\\\n float outlineWidth = v_outlineWidth;\\n\\\n vec4 outlineColor = v_outlineColor;\\n\\\n\\n\\\n // Get the current distance\\n\\\n float distance = getDistance(v_textureCoordinates);\\n\\\n\\n\\\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\\n\\\n float smoothing = fwidth(distance);\\n\\\n // Get an offset that is approximately half the distance to the neighbor pixels\\n\\\n // 0.354 is approximately half of 1/sqrt(2)\\n\\\n vec2 sampleOffset = 0.354 * vec2(dFdx(v_textureCoordinates) + dFdy(v_textureCoordinates));\\n\\\n\\n\\\n // Sample the center point\\n\\\n vec4 center = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\\n\\\n\\n\\\n // Sample the 4 neighbors\\n\\\n vec4 color1 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\\n\\\n vec4 color2 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, sampleOffset.y), outlineWidth, outlineColor, smoothing);\\n\\\n vec4 color3 = getSDFColor(v_textureCoordinates + vec2(-sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\\n\\\n vec4 color4 = getSDFColor(v_textureCoordinates + vec2(sampleOffset.x, -sampleOffset.y), outlineWidth, outlineColor, smoothing);\\n\\\n\\n\\\n // Equally weight the center sample and the 4 neighboring samples\\n\\\n color = (center + color1 + color2 + color3 + color4)/5.0;\\n\\\n#else\\n\\\n // If no derivatives available (IE 10?), just do a single sample\\n\\\n float smoothing = 1.0/32.0;\\n\\\n color = getSDFColor(v_textureCoordinates, outlineWidth, outlineColor, smoothing);\\n\\\n#endif\\n\\\n\\n\\\n color = czm_gammaCorrect(color);\\n\\\n#else\\n\\\n color = czm_gammaCorrect(color);\\n\\\n color *= czm_gammaCorrect(v_color);\\n\\\n#endif\\n\\\n\\n\\\n// Fully transparent parts of the billboard are not pickable.\\n\\\n#if !defined(OPAQUE) && !defined(TRANSLUCENT)\\n\\\n if (color.a < 0.005) // matches 0/255 and 1/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#else\\n\\\n// The billboard is rendered twice. The opaque pass discards translucent fragments\\n\\\n// and the translucent pass discards opaque fragments.\\n\\\n#ifdef OPAQUE\\n\\\n if (color.a < 0.995) // matches < 254/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#else\\n\\\n if (color.a >= 0.995) // matches 254/255 and 255/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#endif\\n\\\n#endif\\n\\\n\\n\\\n#ifdef VECTOR_TILE\\n\\\n color *= u_highlightColor;\\n\\\n#endif\\n\\\n out_FragColor = color;\\n\\\n\\n\\\n#ifdef LOG_DEPTH\\n\\\n czm_writeLogDepth();\\n\\\n#endif\\n\\\n\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\n float temp = v_compressed.y;\\n\\\n\\n\\\n temp = temp * SHIFT_RIGHT1;\\n\\\n\\n\\\n float temp2 = (temp - floor(temp)) * SHIFT_LEFT1;\\n\\\n bool enableDepthTest = temp2 != 0.0;\\n\\\n bool applyTranslate = floor(temp) != 0.0;\\n\\\n\\n\\\n if (enableDepthTest) {\\n\\\n temp = v_compressed.z;\\n\\\n temp = temp * SHIFT_RIGHT12;\\n\\\n\\n\\\n vec2 dimensions;\\n\\\n dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\\n\\\n dimensions.x = floor(temp);\\n\\\n\\n\\\n temp = v_compressed.w;\\n\\\n temp = temp * SHIFT_RIGHT12;\\n\\\n\\n\\\n vec2 imageSize;\\n\\\n imageSize.y = (temp - floor(temp)) * SHIFT_LEFT12;\\n\\\n imageSize.x = floor(temp);\\n\\\n\\n\\\n vec2 adjustedST = v_textureCoordinates - v_textureCoordinateBounds.xy;\\n\\\n adjustedST = adjustedST / vec2(v_textureCoordinateBounds.z - v_textureCoordinateBounds.x, v_textureCoordinateBounds.w - v_textureCoordinateBounds.y);\\n\\\n\\n\\\n float epsilonEyeDepth = v_compressed.x + czm_epsilon1;\\n\\\n float globeDepth1 = getGlobeDepth(adjustedST, v_originTextureCoordinateAndTranslate.xy, applyTranslate, dimensions, imageSize);\\n\\\n\\n\\\n // negative values go into the screen\\n\\\n if (globeDepth1 != 0.0 && globeDepth1 > epsilonEyeDepth)\\n\\\n {\\n\\\n float globeDepth2 = getGlobeDepth(adjustedST, vec2(0.0, 1.0), applyTranslate, dimensions, imageSize); // top left corner\\n\\\n if (globeDepth2 != 0.0 && globeDepth2 > epsilonEyeDepth)\\n\\\n {\\n\\\n float globeDepth3 = getGlobeDepth(adjustedST, vec2(1.0, 1.0), applyTranslate, dimensions, imageSize); // top right corner\\n\\\n if (globeDepth3 != 0.0 && globeDepth3 > epsilonEyeDepth)\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"#ifdef INSTANCED\\n\\\nin vec2 direction;\\n\\\n#endif\\n\\\nin vec4 positionHighAndScale;\\n\\\nin vec4 positionLowAndRotation;\\n\\\nin vec4 compressedAttribute0; // pixel offset, translate, horizontal origin, vertical origin, show, direction, texture coordinates (texture offset)\\n\\\nin vec4 compressedAttribute1; // aligned axis, translucency by distance, image width\\n\\\nin vec4 compressedAttribute2; // label horizontal origin, image height, color, pick color, size in meters, valid aligned axis, 13 bits free\\n\\\nin vec4 eyeOffset; // eye offset in meters, 4 bytes free (texture range)\\n\\\nin vec4 scaleByDistance; // near, nearScale, far, farScale\\n\\\nin vec4 pixelOffsetScaleByDistance; // near, nearScale, far, farScale\\n\\\nin vec4 compressedAttribute3; // distance display condition near, far, disableDepthTestDistance, dimensions\\n\\\nin vec2 sdf; // sdf outline color (rgb) and width (w)\\n\\\n#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\\n\\\nin vec4 textureCoordinateBoundsOrLabelTranslate; // the min and max x and y values for the texture coordinates\\n\\\n#endif\\n\\\n#ifdef VECTOR_TILE\\n\\\nin float a_batchId;\\n\\\n#endif\\n\\\n\\n\\\nout vec2 v_textureCoordinates;\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\nout vec4 v_textureCoordinateBounds;\\n\\\nout vec4 v_originTextureCoordinateAndTranslate;\\n\\\nout vec4 v_compressed; // x: eyeDepth, y: applyTranslate & enableDepthCheck, z: dimensions, w: imageSize\\n\\\nout mat2 v_rotationMatrix;\\n\\\n#endif\\n\\\n\\n\\\nout vec4 v_pickColor;\\n\\\nout vec4 v_color;\\n\\\n#ifdef SDF\\n\\\nout vec4 v_outlineColor;\\n\\\nout float v_outlineWidth;\\n\\\n#endif\\n\\\n\\n\\\nconst float UPPER_BOUND = 32768.0;\\n\\\n\\n\\\nconst float SHIFT_LEFT16 = 65536.0;\\n\\\nconst float SHIFT_LEFT12 = 4096.0;\\n\\\nconst float SHIFT_LEFT8 = 256.0;\\n\\\nconst float SHIFT_LEFT7 = 128.0;\\n\\\nconst float SHIFT_LEFT5 = 32.0;\\n\\\nconst float SHIFT_LEFT3 = 8.0;\\n\\\nconst float SHIFT_LEFT2 = 4.0;\\n\\\nconst float SHIFT_LEFT1 = 2.0;\\n\\\n\\n\\\nconst float SHIFT_RIGHT12 = 1.0 / 4096.0;\\n\\\nconst float SHIFT_RIGHT8 = 1.0 / 256.0;\\n\\\nconst float SHIFT_RIGHT7 = 1.0 / 128.0;\\n\\\nconst float SHIFT_RIGHT5 = 1.0 / 32.0;\\n\\\nconst float SHIFT_RIGHT3 = 1.0 / 8.0;\\n\\\nconst float SHIFT_RIGHT2 = 1.0 / 4.0;\\n\\\nconst float SHIFT_RIGHT1 = 1.0 / 2.0;\\n\\\n\\n\\\nvec4 addScreenSpaceOffset(vec4 positionEC, vec2 imageSize, float scale, vec2 direction, vec2 origin, vec2 translate, vec2 pixelOffset, vec3 alignedAxis, bool validAlignedAxis, float rotation, bool sizeInMeters, out mat2 rotationMatrix, out float mpp)\\n\\\n{\\n\\\n // Note the halfSize cannot be computed in JavaScript because it is sent via\\n\\\n // compressed vertex attributes that coerce it to an integer.\\n\\\n vec2 halfSize = imageSize * scale * 0.5;\\n\\\n halfSize *= ((direction * 2.0) - 1.0);\\n\\\n\\n\\\n vec2 originTranslate = origin * abs(halfSize);\\n\\\n\\n\\\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\\n\\\n if (validAlignedAxis || rotation != 0.0)\\n\\\n {\\n\\\n float angle = rotation;\\n\\\n if (validAlignedAxis)\\n\\\n {\\n\\\n vec4 projectedAlignedAxis = czm_modelView3D * vec4(alignedAxis, 0.0);\\n\\\n angle += sign(-projectedAlignedAxis.x) * acos(sign(projectedAlignedAxis.y) * (projectedAlignedAxis.y * projectedAlignedAxis.y) /\\n\\\n (projectedAlignedAxis.x * projectedAlignedAxis.x + projectedAlignedAxis.y * projectedAlignedAxis.y));\\n\\\n }\\n\\\n\\n\\\n float cosTheta = cos(angle);\\n\\\n float sinTheta = sin(angle);\\n\\\n rotationMatrix = mat2(cosTheta, sinTheta, -sinTheta, cosTheta);\\n\\\n halfSize = rotationMatrix * halfSize;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n mpp = czm_metersPerPixel(positionEC);\\n\\\n positionEC.xy += (originTranslate + halfSize) * czm_branchFreeTernary(sizeInMeters, 1.0, mpp);\\n\\\n positionEC.xy += (translate + pixelOffset) * mpp;\\n\\\n\\n\\\n return positionEC;\\n\\\n}\\n\\\n\\n\\\n#ifdef VERTEX_DEPTH_CHECK\\n\\\nfloat getGlobeDepth(vec4 positionEC)\\n\\\n{\\n\\\n vec4 posWC = czm_eyeToWindowCoordinates(positionEC);\\n\\\n\\n\\\n float globeDepth = czm_unpackDepth(texture(czm_globeDepthTexture, posWC.xy / czm_viewport.zw));\\n\\\n\\n\\\n if (globeDepth == 0.0)\\n\\\n {\\n\\\n return 0.0; // not on the globe\\n\\\n }\\n\\\n\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(posWC.xy, globeDepth);\\n\\\n return eyeCoordinate.z / eyeCoordinate.w;\\n\\\n}\\n\\\n#endif\\n\\\nvoid main()\\n\\\n{\\n\\\n // Modifying this shader may also require modifications to Billboard._computeScreenSpacePosition\\n\\\n\\n\\\n // unpack attributes\\n\\\n vec3 positionHigh = positionHighAndScale.xyz;\\n\\\n vec3 positionLow = positionLowAndRotation.xyz;\\n\\\n float scale = positionHighAndScale.w;\\n\\\n\\n\\\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\\n\\\n float rotation = positionLowAndRotation.w;\\n\\\n#else\\n\\\n float rotation = 0.0;\\n\\\n#endif\\n\\\n\\n\\\n float compressed = compressedAttribute0.x;\\n\\\n\\n\\\n vec2 pixelOffset;\\n\\\n pixelOffset.x = floor(compressed * SHIFT_RIGHT7);\\n\\\n compressed -= pixelOffset.x * SHIFT_LEFT7;\\n\\\n pixelOffset.x -= UPPER_BOUND;\\n\\\n\\n\\\n vec2 origin;\\n\\\n origin.x = floor(compressed * SHIFT_RIGHT5);\\n\\\n compressed -= origin.x * SHIFT_LEFT5;\\n\\\n\\n\\\n origin.y = floor(compressed * SHIFT_RIGHT3);\\n\\\n compressed -= origin.y * SHIFT_LEFT3;\\n\\\n\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\n vec2 depthOrigin = origin.xy;\\n\\\n#endif\\n\\\n origin -= vec2(1.0);\\n\\\n\\n\\\n float show = floor(compressed * SHIFT_RIGHT2);\\n\\\n compressed -= show * SHIFT_LEFT2;\\n\\\n\\n\\\n#ifdef INSTANCED\\n\\\n vec2 textureCoordinatesBottomLeft = czm_decompressTextureCoordinates(compressedAttribute0.w);\\n\\\n vec2 textureCoordinatesRange = czm_decompressTextureCoordinates(eyeOffset.w);\\n\\\n vec2 textureCoordinates = textureCoordinatesBottomLeft + direction * textureCoordinatesRange;\\n\\\n#else\\n\\\n vec2 direction;\\n\\\n direction.x = floor(compressed * SHIFT_RIGHT1);\\n\\\n direction.y = compressed - direction.x * SHIFT_LEFT1;\\n\\\n\\n\\\n vec2 textureCoordinates = czm_decompressTextureCoordinates(compressedAttribute0.w);\\n\\\n#endif\\n\\\n\\n\\\n float temp = compressedAttribute0.y * SHIFT_RIGHT8;\\n\\\n pixelOffset.y = -(floor(temp) - UPPER_BOUND);\\n\\\n\\n\\\n vec2 translate;\\n\\\n translate.y = (temp - floor(temp)) * SHIFT_LEFT16;\\n\\\n\\n\\\n temp = compressedAttribute0.z * SHIFT_RIGHT8;\\n\\\n translate.x = floor(temp) - UPPER_BOUND;\\n\\\n\\n\\\n translate.y += (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n translate.y -= UPPER_BOUND;\\n\\\n\\n\\\n temp = compressedAttribute1.x * SHIFT_RIGHT8;\\n\\\n float temp2 = floor(compressedAttribute2.w * SHIFT_RIGHT2);\\n\\\n\\n\\\n vec2 imageSize = vec2(floor(temp), temp2);\\n\\\n\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\n float labelHorizontalOrigin = floor(compressedAttribute2.w - (temp2 * SHIFT_LEFT2));\\n\\\n float applyTranslate = 0.0;\\n\\\n if (labelHorizontalOrigin != 0.0) // is a billboard, so set apply translate to false\\n\\\n {\\n\\\n applyTranslate = 1.0;\\n\\\n labelHorizontalOrigin -= 2.0;\\n\\\n depthOrigin.x = labelHorizontalOrigin + 1.0;\\n\\\n }\\n\\\n\\n\\\n depthOrigin = vec2(1.0) - (depthOrigin * 0.5);\\n\\\n#endif\\n\\\n\\n\\\n#ifdef EYE_DISTANCE_TRANSLUCENCY\\n\\\n vec4 translucencyByDistance;\\n\\\n translucencyByDistance.x = compressedAttribute1.z;\\n\\\n translucencyByDistance.z = compressedAttribute1.w;\\n\\\n\\n\\\n translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\\n\\\n\\n\\\n temp = compressedAttribute1.y * SHIFT_RIGHT8;\\n\\\n translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\\n\\\n#endif\\n\\\n\\n\\\n#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\\n\\\n temp = compressedAttribute3.w;\\n\\\n temp = temp * SHIFT_RIGHT12;\\n\\\n\\n\\\n vec2 dimensions;\\n\\\n dimensions.y = (temp - floor(temp)) * SHIFT_LEFT12;\\n\\\n dimensions.x = floor(temp);\\n\\\n#endif\\n\\\n\\n\\\n#ifdef ALIGNED_AXIS\\n\\\n vec3 alignedAxis = czm_octDecode(floor(compressedAttribute1.y * SHIFT_RIGHT8));\\n\\\n temp = compressedAttribute2.z * SHIFT_RIGHT5;\\n\\\n bool validAlignedAxis = (temp - floor(temp)) * SHIFT_LEFT1 > 0.0;\\n\\\n#else\\n\\\n vec3 alignedAxis = vec3(0.0);\\n\\\n bool validAlignedAxis = false;\\n\\\n#endif\\n\\\n\\n\\\n vec4 pickColor;\\n\\\n vec4 color;\\n\\\n\\n\\\n temp = compressedAttribute2.y;\\n\\\n temp = temp * SHIFT_RIGHT8;\\n\\\n pickColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n pickColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n pickColor.r = floor(temp);\\n\\\n\\n\\\n temp = compressedAttribute2.x;\\n\\\n temp = temp * SHIFT_RIGHT8;\\n\\\n color.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n color.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n color.r = floor(temp);\\n\\\n\\n\\\n temp = compressedAttribute2.z * SHIFT_RIGHT8;\\n\\\n bool sizeInMeters = floor((temp - floor(temp)) * SHIFT_LEFT7) > 0.0;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n\\n\\\n pickColor.a = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n pickColor /= 255.0;\\n\\\n\\n\\\n color.a = floor(temp);\\n\\\n color /= 255.0;\\n\\\n\\n\\\n ///////////////////////////////////////////////////////////////////////////\\n\\\n\\n\\\n vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\\n\\\n vec4 positionEC = czm_modelViewRelativeToEye * p;\\n\\\n\\n\\\n#if defined(FRAGMENT_DEPTH_CHECK) || defined(VERTEX_DEPTH_CHECK)\\n\\\n float eyeDepth = positionEC.z;\\n\\\n#endif\\n\\\n\\n\\\n positionEC = czm_eyeOffset(positionEC, eyeOffset.xyz);\\n\\\n positionEC.xyz *= show;\\n\\\n\\n\\\n ///////////////////////////////////////////////////////////////////////////\\n\\\n\\n\\\n#if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(EYE_DISTANCE_PIXEL_OFFSET) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)\\n\\\n float lengthSq;\\n\\\n if (czm_sceneMode == czm_sceneMode2D)\\n\\\n {\\n\\\n // 2D camera distance is a special case\\n\\\n // treat all billboards as flattened to the z=0.0 plane\\n\\\n lengthSq = czm_eyeHeight2D.y;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n lengthSq = dot(positionEC.xyz, positionEC.xyz);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef EYE_DISTANCE_SCALING\\n\\\n float distanceScale = czm_nearFarScalar(scaleByDistance, lengthSq);\\n\\\n scale *= distanceScale;\\n\\\n translate *= distanceScale;\\n\\\n // push vertex behind near plane for clipping\\n\\\n if (scale == 0.0)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n float translucency = 1.0;\\n\\\n#ifdef EYE_DISTANCE_TRANSLUCENCY\\n\\\n translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);\\n\\\n // push vertex behind near plane for clipping\\n\\\n if (translucency == 0.0)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef EYE_DISTANCE_PIXEL_OFFSET\\n\\\n float pixelOffsetScale = czm_nearFarScalar(pixelOffsetScaleByDistance, lengthSq);\\n\\\n pixelOffset *= pixelOffsetScale;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef DISTANCE_DISPLAY_CONDITION\\n\\\n float nearSq = compressedAttribute3.x;\\n\\\n float farSq = compressedAttribute3.y;\\n\\\n if (lengthSq < nearSq || lengthSq > farSq)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n mat2 rotationMatrix;\\n\\\n float mpp;\\n\\\n\\n\\\n#ifdef DISABLE_DEPTH_DISTANCE\\n\\\n float disableDepthTestDistance = compressedAttribute3.z;\\n\\\n#endif\\n\\\n\\n\\\n#ifdef VERTEX_DEPTH_CHECK\\n\\\nif (lengthSq < disableDepthTestDistance) {\\n\\\n float depthsilon = 10.0;\\n\\\n\\n\\\n vec2 labelTranslate = textureCoordinateBoundsOrLabelTranslate.xy;\\n\\\n vec4 pEC1 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\\n\\\n float globeDepth1 = getGlobeDepth(pEC1);\\n\\\n\\n\\\n if (globeDepth1 != 0.0 && pEC1.z + depthsilon < globeDepth1)\\n\\\n {\\n\\\n vec4 pEC2 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(0.0, 1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\\n\\\n float globeDepth2 = getGlobeDepth(pEC2);\\n\\\n\\n\\\n if (globeDepth2 != 0.0 && pEC2.z + depthsilon < globeDepth2)\\n\\\n {\\n\\\n vec4 pEC3 = addScreenSpaceOffset(positionEC, dimensions, scale, vec2(1.0), origin, labelTranslate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\\n\\\n float globeDepth3 = getGlobeDepth(pEC3);\\n\\\n if (globeDepth3 != 0.0 && pEC3.z + depthsilon < globeDepth3)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n }\\n\\\n }\\n\\\n }\\n\\\n}\\n\\\n#endif\\n\\\n\\n\\\n positionEC = addScreenSpaceOffset(positionEC, imageSize, scale, direction, origin, translate, pixelOffset, alignedAxis, validAlignedAxis, rotation, sizeInMeters, rotationMatrix, mpp);\\n\\\n gl_Position = czm_projection * positionEC;\\n\\\n v_textureCoordinates = textureCoordinates;\\n\\\n\\n\\\n#ifdef LOG_DEPTH\\n\\\n czm_vertexLogDepth();\\n\\\n#endif\\n\\\n\\n\\\n#ifdef DISABLE_DEPTH_DISTANCE\\n\\\n if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)\\n\\\n {\\n\\\n disableDepthTestDistance = czm_minimumDisableDepthTestDistance;\\n\\\n }\\n\\\n\\n\\\n if (disableDepthTestDistance != 0.0)\\n\\\n {\\n\\\n // Don't try to \\\"multiply both sides\\\" by w. Greater/less-than comparisons won't work for negative values of w.\\n\\\n float zclip = gl_Position.z / gl_Position.w;\\n\\\n bool clipped = (zclip < -1.0 || zclip > 1.0);\\n\\\n if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))\\n\\\n {\\n\\\n // Position z on the near plane.\\n\\\n gl_Position.z = -gl_Position.w;\\n\\\n#ifdef LOG_DEPTH\\n\\\n v_depthFromNearPlusOne = 1.0;\\n\\\n#endif\\n\\\n }\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef FRAGMENT_DEPTH_CHECK\\n\\\n if (sizeInMeters) {\\n\\\n translate /= mpp;\\n\\\n dimensions /= mpp;\\n\\\n imageSize /= mpp;\\n\\\n }\\n\\\n\\n\\\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\\n\\\n v_rotationMatrix = rotationMatrix;\\n\\\n#else\\n\\\n v_rotationMatrix = mat2(1.0, 0.0, 0.0, 1.0);\\n\\\n#endif\\n\\\n\\n\\\n float enableDepthCheck = 0.0;\\n\\\n if (lengthSq < disableDepthTestDistance)\\n\\\n {\\n\\\n enableDepthCheck = 1.0;\\n\\\n }\\n\\\n\\n\\\n float dw = floor(clamp(dimensions.x, 0.0, SHIFT_LEFT12));\\n\\\n float dh = floor(clamp(dimensions.y, 0.0, SHIFT_LEFT12));\\n\\\n\\n\\\n float iw = floor(clamp(imageSize.x, 0.0, SHIFT_LEFT12));\\n\\\n float ih = floor(clamp(imageSize.y, 0.0, SHIFT_LEFT12));\\n\\\n\\n\\\n v_compressed.x = eyeDepth;\\n\\\n v_compressed.y = applyTranslate * SHIFT_LEFT1 + enableDepthCheck;\\n\\\n v_compressed.z = dw * SHIFT_LEFT12 + dh;\\n\\\n v_compressed.w = iw * SHIFT_LEFT12 + ih;\\n\\\n v_originTextureCoordinateAndTranslate.xy = depthOrigin;\\n\\\n v_originTextureCoordinateAndTranslate.zw = translate;\\n\\\n v_textureCoordinateBounds = textureCoordinateBoundsOrLabelTranslate;\\n\\\n\\n\\\n#endif\\n\\\n\\n\\\n#ifdef SDF\\n\\\n vec4 outlineColor;\\n\\\n float outlineWidth;\\n\\\n\\n\\\n temp = sdf.x;\\n\\\n temp = temp * SHIFT_RIGHT8;\\n\\\n outlineColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n outlineColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n outlineColor.r = floor(temp);\\n\\\n\\n\\\n temp = sdf.y;\\n\\\n temp = temp * SHIFT_RIGHT8;\\n\\\n float temp3 = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n outlineWidth = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n outlineColor.a = floor(temp);\\n\\\n outlineColor /= 255.0;\\n\\\n\\n\\\n v_outlineWidth = outlineWidth / 255.0;\\n\\\n v_outlineColor = outlineColor;\\n\\\n v_outlineColor.a *= translucency;\\n\\\n#endif\\n\\\n\\n\\\n v_pickColor = pickColor;\\n\\\n\\n\\\n v_color = color;\\n\\\n v_color.a *= translucency;\\n\\\n\\n\\\n}\\n\\\n\";\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport Resource from \"../Core/Resource.js\";\nimport HeightReference from \"./HeightReference.js\";\nimport HorizontalOrigin from \"./HorizontalOrigin.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport SceneTransforms from \"./SceneTransforms.js\";\nimport VerticalOrigin from \"./VerticalOrigin.js\";\n\n/**\n *
\n * A billboard is created and its initial\n * properties are set by calling {@link BillboardCollection#add}. Do not call the constructor directly.\n *
\n * A viewport-aligned image positioned in the 3D scene, that is created\n * and rendered using a {@link BillboardCollection}.\n *

\n *
\n *
\n * Example billboards\n *
\n *\n * @alias Billboard\n *\n * @performance Reading a property, e.g., {@link Billboard#show}, is constant time.\n * Assigning to a property is constant time but results in\n * CPU to GPU traffic when {@link BillboardCollection#update} is called. The per-billboard traffic is\n * the same regardless of how many properties were updated. If most billboards in a collection need to be\n * updated, it may be more efficient to clear the collection with {@link BillboardCollection#removeAll}\n * and add new billboards instead of modifying each one.\n *\n * @exception {DeveloperError} scaleByDistance.far must be greater than scaleByDistance.near\n * @exception {DeveloperError} translucencyByDistance.far must be greater than translucencyByDistance.near\n * @exception {DeveloperError} pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near\n * @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near\n *\n * @see BillboardCollection\n * @see BillboardCollection#add\n * @see Label\n *\n * @internalConstructor\n * @class\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo}\n */\nfunction Billboard(options, billboardCollection) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(options.disableDepthTestDistance) &&\n options.disableDepthTestDistance < 0.0\n ) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than or equal to 0.0.\"\n );\n }\n //>>includeEnd('debug');\n\n let translucencyByDistance = options.translucencyByDistance;\n let pixelOffsetScaleByDistance = options.pixelOffsetScaleByDistance;\n let scaleByDistance = options.scaleByDistance;\n let distanceDisplayCondition = options.distanceDisplayCondition;\n if (defined(translucencyByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (translucencyByDistance.far <= translucencyByDistance.near) {\n throw new DeveloperError(\n \"translucencyByDistance.far must be greater than translucencyByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n translucencyByDistance = NearFarScalar.clone(translucencyByDistance);\n }\n if (defined(pixelOffsetScaleByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (pixelOffsetScaleByDistance.far <= pixelOffsetScaleByDistance.near) {\n throw new DeveloperError(\n \"pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n pixelOffsetScaleByDistance = NearFarScalar.clone(\n pixelOffsetScaleByDistance\n );\n }\n if (defined(scaleByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (scaleByDistance.far <= scaleByDistance.near) {\n throw new DeveloperError(\n \"scaleByDistance.far must be greater than scaleByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n scaleByDistance = NearFarScalar.clone(scaleByDistance);\n }\n if (defined(distanceDisplayCondition)) {\n //>>includeStart('debug', pragmas.debug);\n if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {\n throw new DeveloperError(\n \"distanceDisplayCondition.far must be greater than distanceDisplayCondition.near.\"\n );\n }\n //>>includeEnd('debug');\n distanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition\n );\n }\n\n this._show = defaultValue(options.show, true);\n this._position = Cartesian3.clone(\n defaultValue(options.position, Cartesian3.ZERO)\n );\n this._actualPosition = Cartesian3.clone(this._position); // For columbus view and 2D\n this._pixelOffset = Cartesian2.clone(\n defaultValue(options.pixelOffset, Cartesian2.ZERO)\n );\n this._translate = new Cartesian2(0.0, 0.0); // used by labels for glyph vertex translation\n this._eyeOffset = Cartesian3.clone(\n defaultValue(options.eyeOffset, Cartesian3.ZERO)\n );\n this._heightReference = defaultValue(\n options.heightReference,\n HeightReference.NONE\n );\n this._verticalOrigin = defaultValue(\n options.verticalOrigin,\n VerticalOrigin.CENTER\n );\n this._horizontalOrigin = defaultValue(\n options.horizontalOrigin,\n HorizontalOrigin.CENTER\n );\n this._scale = defaultValue(options.scale, 1.0);\n this._color = Color.clone(defaultValue(options.color, Color.WHITE));\n this._rotation = defaultValue(options.rotation, 0.0);\n this._alignedAxis = Cartesian3.clone(\n defaultValue(options.alignedAxis, Cartesian3.ZERO)\n );\n this._width = options.width;\n this._height = options.height;\n this._scaleByDistance = scaleByDistance;\n this._translucencyByDistance = translucencyByDistance;\n this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;\n this._sizeInMeters = defaultValue(options.sizeInMeters, false);\n this._distanceDisplayCondition = distanceDisplayCondition;\n this._disableDepthTestDistance = options.disableDepthTestDistance;\n this._id = options.id;\n this._collection = defaultValue(options.collection, billboardCollection);\n\n this._pickId = undefined;\n this._pickPrimitive = defaultValue(options._pickPrimitive, this);\n this._billboardCollection = billboardCollection;\n this._dirty = false;\n this._index = -1; //Used only by BillboardCollection\n this._batchIndex = undefined; // Used only by Vector3DTilePoints and BillboardCollection\n\n this._imageIndex = -1;\n this._imageIndexPromise = undefined;\n this._imageId = undefined;\n this._image = undefined;\n this._imageSubRegion = undefined;\n this._imageWidth = undefined;\n this._imageHeight = undefined;\n\n this._labelDimensions = undefined;\n this._labelHorizontalOrigin = undefined;\n this._labelTranslate = undefined;\n\n const image = options.image;\n let imageId = options.imageId;\n if (defined(image)) {\n if (!defined(imageId)) {\n if (typeof image === \"string\") {\n imageId = image;\n } else if (defined(image.src)) {\n imageId = image.src;\n } else {\n imageId = createGuid();\n }\n }\n\n this._imageId = imageId;\n this._image = image;\n }\n\n if (defined(options.imageSubRegion)) {\n this._imageId = imageId;\n this._imageSubRegion = options.imageSubRegion;\n }\n\n if (defined(this._billboardCollection._textureAtlas)) {\n this._loadImage();\n }\n\n this._actualClampedPosition = undefined;\n this._removeCallbackFunc = undefined;\n this._mode = SceneMode.SCENE3D;\n\n this._clusterShow = true;\n this._outlineColor = Color.clone(\n defaultValue(options.outlineColor, Color.BLACK)\n );\n this._outlineWidth = defaultValue(options.outlineWidth, 0.0);\n\n this._updateClamping();\n}\n\nconst SHOW_INDEX = (Billboard.SHOW_INDEX = 0);\nconst POSITION_INDEX = (Billboard.POSITION_INDEX = 1);\nconst PIXEL_OFFSET_INDEX = (Billboard.PIXEL_OFFSET_INDEX = 2);\nconst EYE_OFFSET_INDEX = (Billboard.EYE_OFFSET_INDEX = 3);\nconst HORIZONTAL_ORIGIN_INDEX = (Billboard.HORIZONTAL_ORIGIN_INDEX = 4);\nconst VERTICAL_ORIGIN_INDEX = (Billboard.VERTICAL_ORIGIN_INDEX = 5);\nconst SCALE_INDEX = (Billboard.SCALE_INDEX = 6);\nconst IMAGE_INDEX_INDEX = (Billboard.IMAGE_INDEX_INDEX = 7);\nconst COLOR_INDEX = (Billboard.COLOR_INDEX = 8);\nconst ROTATION_INDEX = (Billboard.ROTATION_INDEX = 9);\nconst ALIGNED_AXIS_INDEX = (Billboard.ALIGNED_AXIS_INDEX = 10);\nconst SCALE_BY_DISTANCE_INDEX = (Billboard.SCALE_BY_DISTANCE_INDEX = 11);\nconst TRANSLUCENCY_BY_DISTANCE_INDEX = (Billboard.TRANSLUCENCY_BY_DISTANCE_INDEX = 12);\nconst PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX = (Billboard.PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX = 13);\nconst DISTANCE_DISPLAY_CONDITION = (Billboard.DISTANCE_DISPLAY_CONDITION = 14);\nconst DISABLE_DEPTH_DISTANCE = (Billboard.DISABLE_DEPTH_DISTANCE = 15);\nBillboard.TEXTURE_COORDINATE_BOUNDS = 16;\nconst SDF_INDEX = (Billboard.SDF_INDEX = 17);\nBillboard.NUMBER_OF_PROPERTIES = 18;\n\nfunction makeDirty(billboard, propertyChanged) {\n const billboardCollection = billboard._billboardCollection;\n if (defined(billboardCollection)) {\n billboardCollection._updateBillboard(billboard, propertyChanged);\n billboard._dirty = true;\n }\n}\n\nObject.defineProperties(Billboard.prototype, {\n /**\n * Determines if this billboard will be shown. Use this to hide or show a billboard, instead\n * of removing it and re-adding it to the collection.\n * @memberof Billboard.prototype\n * @type {boolean}\n * @default true\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"value\", value);\n //>>includeEnd('debug');\n\n if (this._show !== value) {\n this._show = value;\n makeDirty(this, SHOW_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the Cartesian position of this billboard.\n * @memberof Billboard.prototype\n * @type {Cartesian3}\n */\n position: {\n get: function () {\n return this._position;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug)\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n const position = this._position;\n if (!Cartesian3.equals(position, value)) {\n Cartesian3.clone(value, position);\n Cartesian3.clone(value, this._actualPosition);\n this._updateClamping();\n makeDirty(this, POSITION_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the height reference of this billboard.\n * @memberof Billboard.prototype\n * @type {HeightReference}\n * @default HeightReference.NONE\n */\n heightReference: {\n get: function () {\n return this._heightReference;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug)\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n const heightReference = this._heightReference;\n if (value !== heightReference) {\n this._heightReference = value;\n this._updateClamping();\n makeDirty(this, POSITION_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the pixel offset in screen space from the origin of this billboard. This is commonly used\n * to align multiple billboards and labels at the same position, e.g., an image and text. The\n * screen space origin is the top, left corner of the canvas; x increases from\n * left to right, and y increases from top to bottom.\n *

\n *
\n * \n * \n * \n *
default
b.pixeloffset = new Cartesian2(50, 25);
\n * The billboard's origin is indicated by the yellow point.\n *
\n * @memberof Billboard.prototype\n * @type {Cartesian2}\n */\n pixelOffset: {\n get: function () {\n return this._pixelOffset;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n const pixelOffset = this._pixelOffset;\n if (!Cartesian2.equals(pixelOffset, value)) {\n Cartesian2.clone(value, pixelOffset);\n makeDirty(this, PIXEL_OFFSET_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets near and far scaling properties of a Billboard based on the billboard's distance from the camera.\n * A billboard's scale will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's scale remains clamped to the nearest bound. If undefined,\n * scaleByDistance will be disabled.\n * @memberof Billboard.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a billboard's scaleByDistance to scale by 1.5 when the\n * // camera is 1500 meters from the billboard and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * b.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 1.5, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable scaling by distance\n * b.scaleByDistance = undefined;\n */\n scaleByDistance: {\n get: function () {\n return this._scaleByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.object(\"value\", value);\n if (value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n const scaleByDistance = this._scaleByDistance;\n if (!NearFarScalar.equals(scaleByDistance, value)) {\n this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);\n makeDirty(this, SCALE_BY_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets near and far translucency properties of a Billboard based on the billboard's distance from the camera.\n * A billboard's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's translucency remains clamped to the nearest bound. If undefined,\n * translucencyByDistance will be disabled.\n * @memberof Billboard.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a billboard's translucency to 1.0 when the\n * // camera is 1500 meters from the billboard and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * b.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable translucency by distance\n * b.translucencyByDistance = undefined;\n */\n translucencyByDistance: {\n get: function () {\n return this._translucencyByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.object(\"value\", value);\n if (value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n const translucencyByDistance = this._translucencyByDistance;\n if (!NearFarScalar.equals(translucencyByDistance, value)) {\n this._translucencyByDistance = NearFarScalar.clone(\n value,\n translucencyByDistance\n );\n makeDirty(this, TRANSLUCENCY_BY_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets near and far pixel offset scaling properties of a Billboard based on the billboard's distance from the camera.\n * A billboard's pixel offset will be scaled between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the billboard's pixel offset scale remains clamped to the nearest bound. If undefined,\n * pixelOffsetScaleByDistance will be disabled.\n * @memberof Billboard.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a billboard's pixel offset scale to 0.0 when the\n * // camera is 1500 meters from the billboard and scale pixel offset to 10.0 pixels\n * // in the y direction the camera distance approaches 8.0e6 meters.\n * b.pixelOffset = new Cesium.Cartesian2(0.0, 1.0);\n * b.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(1.5e2, 0.0, 8.0e6, 10.0);\n *\n * @example\n * // Example 2.\n * // disable pixel offset by distance\n * b.pixelOffsetScaleByDistance = undefined;\n */\n pixelOffsetScaleByDistance: {\n get: function () {\n return this._pixelOffsetScaleByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.object(\"value\", value);\n if (value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n const pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;\n if (!NearFarScalar.equals(pixelOffsetScaleByDistance, value)) {\n this._pixelOffsetScaleByDistance = NearFarScalar.clone(\n value,\n pixelOffsetScaleByDistance\n );\n makeDirty(this, PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the 3D Cartesian offset applied to this billboard in eye coordinates. Eye coordinates is a left-handed\n * coordinate system, where x points towards the viewer's right, y points up, and\n * z points into the screen. Eye coordinates use the same scale as world and model coordinates,\n * which is typically meters.\n *

\n * An eye offset is commonly used to arrange multiple billboards or objects at the same position, e.g., to\n * arrange a billboard above its corresponding 3D model.\n *

\n * Below, the billboard is positioned at the center of the Earth but an eye offset makes it always\n * appear on top of the Earth regardless of the viewer's or Earth's orientation.\n *

\n *
\n * \n * \n * \n *
\n * b.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);

\n *
\n * @memberof Billboard.prototype\n * @type {Cartesian3}\n */\n eyeOffset: {\n get: function () {\n return this._eyeOffset;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n const eyeOffset = this._eyeOffset;\n if (!Cartesian3.equals(eyeOffset, value)) {\n Cartesian3.clone(value, eyeOffset);\n makeDirty(this, EYE_OFFSET_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the horizontal origin of this billboard, which determines if the billboard is\n * to the left, center, or right of its anchor position.\n *

\n *
\n *
\n *
\n * @memberof Billboard.prototype\n * @type {HorizontalOrigin}\n * @example\n * // Use a bottom, left origin\n * b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;\n * b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;\n */\n horizontalOrigin: {\n get: function () {\n return this._horizontalOrigin;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (this._horizontalOrigin !== value) {\n this._horizontalOrigin = value;\n makeDirty(this, HORIZONTAL_ORIGIN_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the vertical origin of this billboard, which determines if the billboard is\n * to the above, below, or at the center of its anchor position.\n *

\n *
\n *
\n *
\n * @memberof Billboard.prototype\n * @type {VerticalOrigin}\n * @example\n * // Use a bottom, left origin\n * b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;\n * b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;\n */\n verticalOrigin: {\n get: function () {\n return this._verticalOrigin;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (this._verticalOrigin !== value) {\n this._verticalOrigin = value;\n makeDirty(this, VERTICAL_ORIGIN_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the uniform scale that is multiplied with the billboard's image size in pixels.\n * A scale of 1.0 does not change the size of the billboard; a scale greater than\n * 1.0 enlarges the billboard; a positive scale less than 1.0 shrinks\n * the billboard.\n *

\n *
\n *
\n * From left to right in the above image, the scales are 0.5, 1.0,\n * and 2.0.\n *
\n * @memberof Billboard.prototype\n * @type {number}\n */\n scale: {\n get: function () {\n return this._scale;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (this._scale !== value) {\n this._scale = value;\n makeDirty(this, SCALE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the color that is multiplied with the billboard's texture. This has two common use cases. First,\n * the same white texture may be used by many different billboards, each with a different color, to create\n * colored billboards. Second, the color's alpha component can be used to make the billboard translucent as shown below.\n * An alpha of 0.0 makes the billboard transparent, and 1.0 makes the billboard opaque.\n *

\n *
\n * \n * \n * \n *
default
alpha : 0.5
\n *
\n *
\n * The red, green, blue, and alpha values are indicated by value's red, green,\n * blue, and alpha properties as shown in Example 1. These components range from 0.0\n * (no intensity) to 1.0 (full intensity).\n * @memberof Billboard.prototype\n * @type {Color}\n *\n * @example\n * // Example 1. Assign yellow.\n * b.color = Cesium.Color.YELLOW;\n *\n * @example\n * // Example 2. Make a billboard 50% translucent.\n * b.color = new Cesium.Color(1.0, 1.0, 1.0, 0.5);\n */\n color: {\n get: function () {\n return this._color;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n const color = this._color;\n if (!Color.equals(color, value)) {\n Color.clone(value, color);\n makeDirty(this, COLOR_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the rotation angle in radians.\n * @memberof Billboard.prototype\n * @type {number}\n */\n rotation: {\n get: function () {\n return this._rotation;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"value\", value);\n //>>includeEnd('debug');\n\n if (this._rotation !== value) {\n this._rotation = value;\n makeDirty(this, ROTATION_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the aligned axis in world space. The aligned axis is the unit vector that the billboard up vector points towards.\n * The default is the zero vector, which means the billboard is aligned to the screen up vector.\n * @memberof Billboard.prototype\n * @type {Cartesian3}\n * @example\n * // Example 1.\n * // Have the billboard up vector point north\n * billboard.alignedAxis = Cesium.Cartesian3.UNIT_Z;\n *\n * @example\n * // Example 2.\n * // Have the billboard point east.\n * billboard.alignedAxis = Cesium.Cartesian3.UNIT_Z;\n * billboard.rotation = -Cesium.Math.PI_OVER_TWO;\n *\n * @example\n * // Example 3.\n * // Reset the aligned axis\n * billboard.alignedAxis = Cesium.Cartesian3.ZERO;\n */\n alignedAxis: {\n get: function () {\n return this._alignedAxis;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n const alignedAxis = this._alignedAxis;\n if (!Cartesian3.equals(alignedAxis, value)) {\n Cartesian3.clone(value, alignedAxis);\n makeDirty(this, ALIGNED_AXIS_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets a width for the billboard. If undefined, the image width will be used.\n * @memberof Billboard.prototype\n * @type {number}\n */\n width: {\n get: function () {\n return defaultValue(this._width, this._imageWidth);\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.number(\"value\", value);\n }\n //>>includeEnd('debug');\n if (this._width !== value) {\n this._width = value;\n makeDirty(this, IMAGE_INDEX_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets a height for the billboard. If undefined, the image height will be used.\n * @memberof Billboard.prototype\n * @type {number}\n */\n height: {\n get: function () {\n return defaultValue(this._height, this._imageHeight);\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.number(\"value\", value);\n }\n //>>includeEnd('debug');\n if (this._height !== value) {\n this._height = value;\n makeDirty(this, IMAGE_INDEX_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets if the billboard size is in meters or pixels. true to size the billboard in meters;\n * otherwise, the size is in pixels.\n * @memberof Billboard.prototype\n * @type {boolean}\n * @default false\n */\n sizeInMeters: {\n get: function () {\n return this._sizeInMeters;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"value\", value);\n //>>includeEnd('debug');\n if (this._sizeInMeters !== value) {\n this._sizeInMeters = value;\n makeDirty(this, COLOR_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the condition specifying at what distance from the camera that this billboard will be displayed.\n * @memberof Billboard.prototype\n * @type {DistanceDisplayCondition}\n * @default undefined\n */\n distanceDisplayCondition: {\n get: function () {\n return this._distanceDisplayCondition;\n },\n set: function (value) {\n if (\n !DistanceDisplayCondition.equals(value, this._distanceDisplayCondition)\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.object(\"value\", value);\n if (value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n }\n //>>includeEnd('debug');\n this._distanceDisplayCondition = DistanceDisplayCondition.clone(\n value,\n this._distanceDisplayCondition\n );\n makeDirty(this, DISTANCE_DISPLAY_CONDITION);\n }\n },\n },\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof Billboard.prototype\n * @type {number}\n */\n disableDepthTestDistance: {\n get: function () {\n return this._disableDepthTestDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value)) {\n Check.typeOf.number(\"value\", value);\n if (value < 0.0) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than or equal to 0.0.\"\n );\n }\n }\n //>>includeEnd('debug');\n if (this._disableDepthTestDistance !== value) {\n this._disableDepthTestDistance = value;\n makeDirty(this, DISABLE_DEPTH_DISTANCE);\n }\n },\n },\n\n /**\n * Gets or sets the user-defined object returned when the billboard is picked.\n * @memberof Billboard.prototype\n * @type {object}\n */\n id: {\n get: function () {\n return this._id;\n },\n set: function (value) {\n this._id = value;\n if (defined(this._pickId)) {\n this._pickId.object.id = value;\n }\n },\n },\n\n /**\n * The primitive to return when picking this billboard.\n * @memberof Billboard.prototype\n * @private\n */\n pickPrimitive: {\n get: function () {\n return this._pickPrimitive;\n },\n set: function (value) {\n this._pickPrimitive = value;\n if (defined(this._pickId)) {\n this._pickId.object.primitive = value;\n }\n },\n },\n\n /**\n * @private\n */\n pickId: {\n get: function () {\n return this._pickId;\n },\n },\n\n /**\n *

\n * Gets or sets the image to be used for this billboard. If a texture has already been created for the\n * given image, the existing texture is used.\n *

\n *

\n * This property can be set to a loaded Image, a URL which will be loaded as an Image automatically,\n * a canvas, or another billboard's image property (from the same billboard collection).\n *

\n *\n * @memberof Billboard.prototype\n * @type {string}\n * @example\n * // load an image from a URL\n * b.image = 'some/image/url.png';\n *\n * // assuming b1 and b2 are billboards in the same billboard collection,\n * // use the same image for both billboards.\n * b2.image = b1.image;\n */\n image: {\n get: function () {\n return this._imageId;\n },\n set: function (value) {\n if (!defined(value)) {\n this._imageIndex = -1;\n this._imageSubRegion = undefined;\n this._imageId = undefined;\n this._image = undefined;\n this._imageIndexPromise = undefined;\n makeDirty(this, IMAGE_INDEX_INDEX);\n } else if (typeof value === \"string\") {\n this.setImage(value, value);\n } else if (value instanceof Resource) {\n this.setImage(value.url, value);\n } else if (defined(value.src)) {\n this.setImage(value.src, value);\n } else {\n this.setImage(createGuid(), value);\n }\n },\n },\n\n /**\n * When true, this billboard is ready to render, i.e., the image\n * has been downloaded and the WebGL resources are created.\n *\n * @memberof Billboard.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n */\n ready: {\n get: function () {\n return this._imageIndex !== -1;\n },\n },\n\n /**\n * Keeps track of the position of the billboard based on the height reference.\n * @memberof Billboard.prototype\n * @type {Cartesian3}\n * @private\n */\n _clampedPosition: {\n get: function () {\n return this._actualClampedPosition;\n },\n set: function (value) {\n this._actualClampedPosition = Cartesian3.clone(\n value,\n this._actualClampedPosition\n );\n makeDirty(this, POSITION_INDEX);\n },\n },\n\n /**\n * Determines whether or not this billboard will be shown or hidden because it was clustered.\n * @memberof Billboard.prototype\n * @type {boolean}\n * @private\n */\n clusterShow: {\n get: function () {\n return this._clusterShow;\n },\n set: function (value) {\n if (this._clusterShow !== value) {\n this._clusterShow = value;\n makeDirty(this, SHOW_INDEX);\n }\n },\n },\n\n /**\n * The outline color of this Billboard. Effective only for SDF billboards like Label glyphs.\n * @memberof Billboard.prototype\n * @type {Color}\n * @private\n */\n outlineColor: {\n get: function () {\n return this._outlineColor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const outlineColor = this._outlineColor;\n if (!Color.equals(outlineColor, value)) {\n Color.clone(value, outlineColor);\n makeDirty(this, SDF_INDEX);\n }\n },\n },\n\n /**\n * The outline width of this Billboard in pixels. Effective only for SDF billboards like Label glyphs.\n * @memberof Billboard.prototype\n * @type {number}\n * @private\n */\n outlineWidth: {\n get: function () {\n return this._outlineWidth;\n },\n set: function (value) {\n if (this._outlineWidth !== value) {\n this._outlineWidth = value;\n makeDirty(this, SDF_INDEX);\n }\n },\n },\n});\n\nBillboard.prototype.getPickId = function (context) {\n if (!defined(this._pickId)) {\n this._pickId = context.createPickId({\n primitive: this._pickPrimitive,\n collection: this._collection,\n id: this._id,\n });\n }\n\n return this._pickId;\n};\n\nBillboard.prototype._updateClamping = function () {\n Billboard._updateClamping(this._billboardCollection, this);\n};\n\nconst scratchCartographic = new Cartographic();\nconst scratchPosition = new Cartesian3();\n\nBillboard._updateClamping = function (collection, owner) {\n const scene = collection._scene;\n if (!defined(scene) || !defined(scene.globe)) {\n //>>includeStart('debug', pragmas.debug);\n if (owner._heightReference !== HeightReference.NONE) {\n throw new DeveloperError(\n \"Height reference is not supported without a scene and globe.\"\n );\n }\n //>>includeEnd('debug');\n return;\n }\n\n const globe = scene.globe;\n const ellipsoid = globe.ellipsoid;\n const surface = globe._surface;\n\n const mode = scene.frameState.mode;\n\n const modeChanged = mode !== owner._mode;\n owner._mode = mode;\n\n if (\n (owner._heightReference === HeightReference.NONE || modeChanged) &&\n defined(owner._removeCallbackFunc)\n ) {\n owner._removeCallbackFunc();\n owner._removeCallbackFunc = undefined;\n owner._clampedPosition = undefined;\n }\n\n if (\n owner._heightReference === HeightReference.NONE ||\n !defined(owner._position)\n ) {\n return;\n }\n\n const position = ellipsoid.cartesianToCartographic(owner._position);\n if (!defined(position)) {\n owner._actualClampedPosition = undefined;\n return;\n }\n\n if (defined(owner._removeCallbackFunc)) {\n owner._removeCallbackFunc();\n }\n\n function updateFunction(clampedPosition) {\n if (owner._heightReference === HeightReference.RELATIVE_TO_GROUND) {\n if (owner._mode === SceneMode.SCENE3D) {\n const clampedCart = ellipsoid.cartesianToCartographic(\n clampedPosition,\n scratchCartographic\n );\n clampedCart.height += position.height;\n ellipsoid.cartographicToCartesian(clampedCart, clampedPosition);\n } else {\n clampedPosition.x += position.height;\n }\n }\n owner._clampedPosition = Cartesian3.clone(\n clampedPosition,\n owner._clampedPosition\n );\n }\n owner._removeCallbackFunc = surface.updateHeight(position, updateFunction);\n\n Cartographic.clone(position, scratchCartographic);\n const height = globe.getHeight(position);\n if (defined(height)) {\n scratchCartographic.height = height;\n }\n\n ellipsoid.cartographicToCartesian(scratchCartographic, scratchPosition);\n\n updateFunction(scratchPosition);\n};\n\nBillboard.prototype._loadImage = function () {\n const atlas = this._billboardCollection._textureAtlas;\n\n const imageId = this._imageId;\n const image = this._image;\n const imageSubRegion = this._imageSubRegion;\n let imageIndexPromise;\n\n const that = this;\n function completeImageLoad(index) {\n if (\n that._imageId !== imageId ||\n that._image !== image ||\n !BoundingRectangle.equals(that._imageSubRegion, imageSubRegion)\n ) {\n // another load occurred before this one finished, ignore the index\n return;\n }\n\n // fill in imageWidth and imageHeight\n const textureCoordinates = atlas.textureCoordinates[index];\n that._imageWidth = atlas.texture.width * textureCoordinates.width;\n that._imageHeight = atlas.texture.height * textureCoordinates.height;\n\n that._imageIndex = index;\n that._ready = true;\n that._image = undefined;\n that._imageIndexPromise = undefined;\n makeDirty(that, IMAGE_INDEX_INDEX);\n }\n\n if (defined(image)) {\n imageIndexPromise = atlas.addImage(imageId, image);\n }\n if (defined(imageSubRegion)) {\n imageIndexPromise = atlas.addSubRegion(imageId, imageSubRegion);\n }\n\n this._imageIndexPromise = imageIndexPromise;\n\n if (!defined(imageIndexPromise)) {\n return;\n }\n\n // If the promise has already successfully resolved, we can return immediately without waiting a frame\n const index = atlas.getImageIndex(imageId);\n if (defined(index) && !defined(imageSubRegion)) {\n completeImageLoad(index);\n return;\n }\n\n imageIndexPromise.then(completeImageLoad).catch(function (error) {\n console.error(`Error loading image for billboard: ${error}`);\n that._imageIndexPromise = undefined;\n });\n};\n\n/**\n *

\n * Sets the image to be used for this billboard. If a texture has already been created for the\n * given id, the existing texture is used.\n *

\n *

\n * This function is useful for dynamically creating textures that are shared across many billboards.\n * Only the first billboard will actually call the function and create the texture, while subsequent\n * billboards created with the same id will simply re-use the existing texture.\n *

\n *

\n * To load an image from a URL, setting the {@link Billboard#image} property is more convenient.\n *

\n *\n * @param {string} id The id of the image. This can be any string that uniquely identifies the image.\n * @param {HTMLImageElement|HTMLCanvasElement|string|Resource|Billboard.CreateImageCallback} image The image to load. This parameter\n * can either be a loaded Image or Canvas, a URL which will be loaded as an Image automatically,\n * or a function which will be called to create the image if it hasn't been loaded already.\n * @example\n * // create a billboard image dynamically\n * function drawImage(id) {\n * // create and draw an image using a canvas\n * const canvas = document.createElement('canvas');\n * const context2D = canvas.getContext('2d');\n * // ... draw image\n * return canvas;\n * }\n * // drawImage will be called to create the texture\n * b.setImage('myImage', drawImage);\n *\n * // subsequent billboards created in the same collection using the same id will use the existing\n * // texture, without the need to create the canvas or draw the image\n * b2.setImage('myImage', drawImage);\n */\nBillboard.prototype.setImage = function (id, image) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n if (!defined(image)) {\n throw new DeveloperError(\"image is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._imageId === id) {\n return;\n }\n\n this._imageIndex = -1;\n this._imageSubRegion = undefined;\n this._imageId = id;\n this._image = image;\n\n if (defined(this._billboardCollection._textureAtlas)) {\n this._loadImage();\n }\n};\n\n/**\n * Uses a sub-region of the image with the given id as the image for this billboard,\n * measured in pixels from the bottom-left.\n *\n * @param {string} id The id of the image to use.\n * @param {BoundingRectangle} subRegion The sub-region of the image.\n *\n * @exception {RuntimeError} image with id must be in the atlas\n */\nBillboard.prototype.setImageSubRegion = function (id, subRegion) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n if (!defined(subRegion)) {\n throw new DeveloperError(\"subRegion is required.\");\n }\n //>>includeEnd('debug');\n\n if (\n this._imageId === id &&\n BoundingRectangle.equals(this._imageSubRegion, subRegion)\n ) {\n return;\n }\n\n this._imageIndex = -1;\n this._imageId = id;\n this._imageSubRegion = BoundingRectangle.clone(subRegion);\n\n if (defined(this._billboardCollection._textureAtlas)) {\n this._loadImage();\n }\n};\n\nBillboard.prototype._setTranslate = function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const translate = this._translate;\n if (!Cartesian2.equals(translate, value)) {\n Cartesian2.clone(value, translate);\n makeDirty(this, PIXEL_OFFSET_INDEX);\n }\n};\n\nBillboard.prototype._getActualPosition = function () {\n return defined(this._clampedPosition)\n ? this._clampedPosition\n : this._actualPosition;\n};\n\nBillboard.prototype._setActualPosition = function (value) {\n if (!defined(this._clampedPosition)) {\n Cartesian3.clone(value, this._actualPosition);\n }\n makeDirty(this, POSITION_INDEX);\n};\n\nconst tempCartesian3 = new Cartesian4();\nBillboard._computeActualPosition = function (\n billboard,\n position,\n frameState,\n modelMatrix\n) {\n if (defined(billboard._clampedPosition)) {\n if (frameState.mode !== billboard._mode) {\n billboard._updateClamping();\n }\n return billboard._clampedPosition;\n } else if (frameState.mode === SceneMode.SCENE3D) {\n return position;\n }\n\n Matrix4.multiplyByPoint(modelMatrix, position, tempCartesian3);\n return SceneTransforms.computeActualWgs84Position(frameState, tempCartesian3);\n};\n\nconst scratchCartesian3 = new Cartesian3();\n\n// This function is basically a stripped-down JavaScript version of BillboardCollectionVS.glsl\nBillboard._computeScreenSpacePosition = function (\n modelMatrix,\n position,\n eyeOffset,\n pixelOffset,\n scene,\n result\n) {\n // Model to world coordinates\n const positionWorld = Matrix4.multiplyByPoint(\n modelMatrix,\n position,\n scratchCartesian3\n );\n\n // World to window coordinates\n const positionWC = SceneTransforms.wgs84WithEyeOffsetToWindowCoordinates(\n scene,\n positionWorld,\n eyeOffset,\n result\n );\n if (!defined(positionWC)) {\n return undefined;\n }\n\n // Apply pixel offset\n Cartesian2.add(positionWC, pixelOffset, positionWC);\n\n return positionWC;\n};\n\nconst scratchPixelOffset = new Cartesian2(0.0, 0.0);\n\n/**\n * Computes the screen-space position of the billboard's origin, taking into account eye and pixel offsets.\n * The screen space origin is the top, left corner of the canvas; x increases from\n * left to right, and y increases from top to bottom.\n *\n * @param {Scene} scene The scene.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The screen-space position of the billboard.\n *\n * @exception {DeveloperError} Billboard must be in a collection.\n *\n * @example\n * console.log(b.computeScreenSpacePosition(scene).toString());\n *\n * @see Billboard#eyeOffset\n * @see Billboard#pixelOffset\n */\nBillboard.prototype.computeScreenSpacePosition = function (scene, result) {\n const billboardCollection = this._billboardCollection;\n if (!defined(result)) {\n result = new Cartesian2();\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(billboardCollection)) {\n throw new DeveloperError(\n \"Billboard must be in a collection. Was it removed?\"\n );\n }\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n //>>includeEnd('debug');\n\n // pixel offset for screen space computation is the pixelOffset + screen space translate\n Cartesian2.clone(this._pixelOffset, scratchPixelOffset);\n Cartesian2.add(scratchPixelOffset, this._translate, scratchPixelOffset);\n\n let modelMatrix = billboardCollection.modelMatrix;\n let position = this._position;\n if (defined(this._clampedPosition)) {\n position = this._clampedPosition;\n if (scene.mode !== SceneMode.SCENE3D) {\n // position needs to be in world coordinates\n const projection = scene.mapProjection;\n const ellipsoid = projection.ellipsoid;\n const cart = projection.unproject(position, scratchCartographic);\n position = ellipsoid.cartographicToCartesian(cart, scratchCartesian3);\n modelMatrix = Matrix4.IDENTITY;\n }\n }\n\n const windowCoordinates = Billboard._computeScreenSpacePosition(\n modelMatrix,\n position,\n this._eyeOffset,\n scratchPixelOffset,\n scene,\n result\n );\n return windowCoordinates;\n};\n\n/**\n * Gets a billboard's screen space bounding box centered around screenSpacePosition.\n * @param {Billboard} billboard The billboard to get the screen space bounding box for.\n * @param {Cartesian2} screenSpacePosition The screen space center of the label.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The screen space bounding box.\n *\n * @private\n */\nBillboard.getScreenSpaceBoundingBox = function (\n billboard,\n screenSpacePosition,\n result\n) {\n let width = billboard.width;\n let height = billboard.height;\n\n const scale = billboard.scale;\n width *= scale;\n height *= scale;\n\n let x = screenSpacePosition.x;\n if (billboard.horizontalOrigin === HorizontalOrigin.RIGHT) {\n x -= width;\n } else if (billboard.horizontalOrigin === HorizontalOrigin.CENTER) {\n x -= width * 0.5;\n }\n\n let y = screenSpacePosition.y;\n if (\n billboard.verticalOrigin === VerticalOrigin.BOTTOM ||\n billboard.verticalOrigin === VerticalOrigin.BASELINE\n ) {\n y -= height;\n } else if (billboard.verticalOrigin === VerticalOrigin.CENTER) {\n y -= height * 0.5;\n }\n\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n result.x = x;\n result.y = y;\n result.width = width;\n result.height = height;\n\n return result;\n};\n\n/**\n * Determines if this billboard equals another billboard. Billboards are equal if all their properties\n * are equal. Billboards in different collections can be equal.\n *\n * @param {Billboard} other The billboard to compare for equality.\n * @returns {boolean} true if the billboards are equal; otherwise, false.\n */\nBillboard.prototype.equals = function (other) {\n return (\n this === other ||\n (defined(other) &&\n this._id === other._id &&\n Cartesian3.equals(this._position, other._position) &&\n this._imageId === other._imageId &&\n this._show === other._show &&\n this._scale === other._scale &&\n this._verticalOrigin === other._verticalOrigin &&\n this._horizontalOrigin === other._horizontalOrigin &&\n this._heightReference === other._heightReference &&\n BoundingRectangle.equals(this._imageSubRegion, other._imageSubRegion) &&\n Color.equals(this._color, other._color) &&\n Cartesian2.equals(this._pixelOffset, other._pixelOffset) &&\n Cartesian2.equals(this._translate, other._translate) &&\n Cartesian3.equals(this._eyeOffset, other._eyeOffset) &&\n NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&\n NearFarScalar.equals(\n this._translucencyByDistance,\n other._translucencyByDistance\n ) &&\n NearFarScalar.equals(\n this._pixelOffsetScaleByDistance,\n other._pixelOffsetScaleByDistance\n ) &&\n DistanceDisplayCondition.equals(\n this._distanceDisplayCondition,\n other._distanceDisplayCondition\n ) &&\n this._disableDepthTestDistance === other._disableDepthTestDistance)\n );\n};\n\nBillboard.prototype._destroy = function () {\n if (defined(this._customData)) {\n this._billboardCollection._scene.globe._surface.removeTileCustomData(\n this._customData\n );\n this._customData = undefined;\n }\n\n if (defined(this._removeCallbackFunc)) {\n this._removeCallbackFunc();\n this._removeCallbackFunc = undefined;\n }\n\n this.image = undefined;\n this._pickId = this._pickId && this._pickId.destroy();\n this._billboardCollection = undefined;\n};\n\n/**\n * A function that creates an image.\n * @callback Billboard.CreateImageCallback\n * @param {string} id The identifier of the image to load.\n * @returns {HTMLImageElement|HTMLCanvasElement|Promise} The image, or a promise that will resolve to an image.\n */\nexport default Billboard;\n", "/**\n * Determines how opaque and translucent parts of billboards, points, and labels are blended with the scene.\n *\n * @enum {number}\n */\nconst BlendOption = {\n /**\n * The billboards, points, or labels in the collection are completely opaque.\n * @type {number}\n * @constant\n */\n OPAQUE: 0,\n\n /**\n * The billboards, points, or labels in the collection are completely translucent.\n * @type {number}\n * @constant\n */\n TRANSLUCENT: 1,\n\n /**\n * The billboards, points, or labels in the collection are both opaque and translucent.\n * @type {number}\n * @constant\n */\n OPAQUE_AND_TRANSLUCENT: 2,\n};\nexport default Object.freeze(BlendOption);\n", "/**\n * Settings for the generation of signed distance field glyphs\n *\n * @private\n */\nconst SDFSettings = {\n /**\n * The font size in pixels\n *\n * @type {number}\n * @constant\n */\n FONT_SIZE: 48.0,\n\n /**\n * Whitespace padding around glyphs.\n *\n * @type {number}\n * @constant\n */\n PADDING: 10.0,\n\n /**\n * How many pixels around the glyph shape to use for encoding distance\n *\n * @type {number}\n * @constant\n */\n RADIUS: 8.0,\n\n /**\n * How much of the radius (relative) is used for the inside part the glyph.\n *\n * @type {number}\n * @constant\n */\n CUTOFF: 0.25,\n};\nexport default Object.freeze(SDFSettings);\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport PixelFormat from \"../Core/PixelFormat.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Framebuffer from \"../Renderer/Framebuffer.js\";\nimport Texture from \"../Renderer/Texture.js\";\n\n// The atlas is made up of regions of space called nodes that contain images or child nodes.\nfunction TextureAtlasNode(\n bottomLeft,\n topRight,\n childNode1,\n childNode2,\n imageIndex\n) {\n this.bottomLeft = defaultValue(bottomLeft, Cartesian2.ZERO);\n this.topRight = defaultValue(topRight, Cartesian2.ZERO);\n this.childNode1 = childNode1;\n this.childNode2 = childNode2;\n this.imageIndex = imageIndex;\n}\n\nconst defaultInitialSize = new Cartesian2(16.0, 16.0);\n\n/**\n * A TextureAtlas stores multiple images in one square texture and keeps\n * track of the texture coordinates for each image. TextureAtlas is dynamic,\n * meaning new images can be added at any point in time.\n * Texture coordinates are subject to change if the texture atlas resizes, so it is\n * important to check {@link TextureAtlas#getGUID} before using old values.\n *\n * @alias TextureAtlas\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Scene} options.context The context in which the texture gets created.\n * @param {PixelFormat} [options.pixelFormat=PixelFormat.RGBA] The pixel format of the texture.\n * @param {number} [options.borderWidthInPixels=1] The amount of spacing between adjacent images in pixels.\n * @param {Cartesian2} [options.initialSize=new Cartesian2(16.0, 16.0)] The initial side lengths of the texture.\n *\n * @exception {DeveloperError} borderWidthInPixels must be greater than or equal to zero.\n * @exception {DeveloperError} initialSize must be greater than zero.\n *\n * @private\n */\nfunction TextureAtlas(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const borderWidthInPixels = defaultValue(options.borderWidthInPixels, 1.0);\n const initialSize = defaultValue(options.initialSize, defaultInitialSize);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options.context)) {\n throw new DeveloperError(\"context is required.\");\n }\n if (borderWidthInPixels < 0) {\n throw new DeveloperError(\n \"borderWidthInPixels must be greater than or equal to zero.\"\n );\n }\n if (initialSize.x < 1 || initialSize.y < 1) {\n throw new DeveloperError(\"initialSize must be greater than zero.\");\n }\n //>>includeEnd('debug');\n\n this._context = options.context;\n this._pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA);\n this._borderWidthInPixels = borderWidthInPixels;\n this._textureCoordinates = [];\n this._guid = createGuid();\n this._idHash = {};\n this._indexHash = {};\n this._initialSize = initialSize;\n\n this._root = undefined;\n}\n\nObject.defineProperties(TextureAtlas.prototype, {\n /**\n * The amount of spacing between adjacent images in pixels.\n * @memberof TextureAtlas.prototype\n * @type {number}\n */\n borderWidthInPixels: {\n get: function () {\n return this._borderWidthInPixels;\n },\n },\n\n /**\n * An array of {@link BoundingRectangle} texture coordinate regions for all the images in the texture atlas.\n * The x and y values of the rectangle correspond to the bottom-left corner of the texture coordinate.\n * The coordinates are in the order that the corresponding images were added to the atlas.\n * @memberof TextureAtlas.prototype\n * @type {BoundingRectangle[]}\n */\n textureCoordinates: {\n get: function () {\n return this._textureCoordinates;\n },\n },\n\n /**\n * The texture that all of the images are being written to.\n * @memberof TextureAtlas.prototype\n * @type {Texture}\n */\n texture: {\n get: function () {\n if (!defined(this._texture)) {\n this._texture = new Texture({\n context: this._context,\n width: this._initialSize.x,\n height: this._initialSize.y,\n pixelFormat: this._pixelFormat,\n });\n }\n return this._texture;\n },\n },\n\n /**\n * The number of images in the texture atlas. This value increases\n * every time addImage or addImages is called.\n * Texture coordinates are subject to change if the texture atlas resizes, so it is\n * important to check {@link TextureAtlas#getGUID} before using old values.\n * @memberof TextureAtlas.prototype\n * @type {number}\n */\n numberOfImages: {\n get: function () {\n return this._textureCoordinates.length;\n },\n },\n\n /**\n * The atlas' globally unique identifier (GUID).\n * The GUID changes whenever the texture atlas is modified.\n * Classes that use a texture atlas should check if the GUID\n * has changed before processing the atlas data.\n * @memberof TextureAtlas.prototype\n * @type {string}\n */\n guid: {\n get: function () {\n return this._guid;\n },\n },\n});\n\n// Builds a larger texture and copies the old texture into the new one.\nfunction resizeAtlas(textureAtlas, image) {\n const context = textureAtlas._context;\n const numImages = textureAtlas.numberOfImages;\n const scalingFactor = 2.0;\n const borderWidthInPixels = textureAtlas._borderWidthInPixels;\n if (numImages > 0) {\n const oldAtlasWidth = textureAtlas._texture.width;\n const oldAtlasHeight = textureAtlas._texture.height;\n const atlasWidth =\n scalingFactor * (oldAtlasWidth + image.width + borderWidthInPixels);\n const atlasHeight =\n scalingFactor * (oldAtlasHeight + image.height + borderWidthInPixels);\n const widthRatio = oldAtlasWidth / atlasWidth;\n const heightRatio = oldAtlasHeight / atlasHeight;\n\n // Create new node structure, putting the old root node in the bottom left.\n const nodeBottomRight = new TextureAtlasNode(\n new Cartesian2(oldAtlasWidth + borderWidthInPixels, borderWidthInPixels),\n new Cartesian2(atlasWidth, oldAtlasHeight)\n );\n const nodeBottomHalf = new TextureAtlasNode(\n new Cartesian2(),\n new Cartesian2(atlasWidth, oldAtlasHeight),\n textureAtlas._root,\n nodeBottomRight\n );\n const nodeTopHalf = new TextureAtlasNode(\n new Cartesian2(borderWidthInPixels, oldAtlasHeight + borderWidthInPixels),\n new Cartesian2(atlasWidth, atlasHeight)\n );\n const nodeMain = new TextureAtlasNode(\n new Cartesian2(),\n new Cartesian2(atlasWidth, atlasHeight),\n nodeBottomHalf,\n nodeTopHalf\n );\n\n // Resize texture coordinates.\n for (let i = 0; i < textureAtlas._textureCoordinates.length; i++) {\n const texCoord = textureAtlas._textureCoordinates[i];\n if (defined(texCoord)) {\n texCoord.x *= widthRatio;\n texCoord.y *= heightRatio;\n texCoord.width *= widthRatio;\n texCoord.height *= heightRatio;\n }\n }\n\n // Copy larger texture.\n const newTexture = new Texture({\n context: textureAtlas._context,\n width: atlasWidth,\n height: atlasHeight,\n pixelFormat: textureAtlas._pixelFormat,\n });\n\n const framebuffer = new Framebuffer({\n context: context,\n colorTextures: [textureAtlas._texture],\n destroyAttachments: false,\n });\n\n framebuffer._bind();\n newTexture.copyFromFramebuffer(0, 0, 0, 0, atlasWidth, atlasHeight);\n framebuffer._unBind();\n framebuffer.destroy();\n textureAtlas._texture =\n textureAtlas._texture && textureAtlas._texture.destroy();\n textureAtlas._texture = newTexture;\n textureAtlas._root = nodeMain;\n } else {\n // First image exceeds initialSize\n let initialWidth = scalingFactor * (image.width + 2 * borderWidthInPixels);\n let initialHeight =\n scalingFactor * (image.height + 2 * borderWidthInPixels);\n if (initialWidth < textureAtlas._initialSize.x) {\n initialWidth = textureAtlas._initialSize.x;\n }\n if (initialHeight < textureAtlas._initialSize.y) {\n initialHeight = textureAtlas._initialSize.y;\n }\n textureAtlas._texture =\n textureAtlas._texture && textureAtlas._texture.destroy();\n textureAtlas._texture = new Texture({\n context: textureAtlas._context,\n width: initialWidth,\n height: initialHeight,\n pixelFormat: textureAtlas._pixelFormat,\n });\n textureAtlas._root = new TextureAtlasNode(\n new Cartesian2(borderWidthInPixels, borderWidthInPixels),\n new Cartesian2(initialWidth, initialHeight)\n );\n }\n}\n\n// A recursive function that finds the best place to insert\n// a new image based on existing image 'nodes'.\n// Inspired by: http://blackpawn.com/texts/lightmaps/default.html\nfunction findNode(textureAtlas, node, image) {\n if (!defined(node)) {\n return undefined;\n }\n\n // If a leaf node\n if (!defined(node.childNode1) && !defined(node.childNode2)) {\n // Node already contains an image, don't add to it.\n if (defined(node.imageIndex)) {\n return undefined;\n }\n\n const nodeWidth = node.topRight.x - node.bottomLeft.x;\n const nodeHeight = node.topRight.y - node.bottomLeft.y;\n const widthDifference = nodeWidth - image.width;\n const heightDifference = nodeHeight - image.height;\n\n // Node is smaller than the image.\n if (widthDifference < 0 || heightDifference < 0) {\n return undefined;\n }\n\n // If the node is the same size as the image, return the node\n if (widthDifference === 0 && heightDifference === 0) {\n return node;\n }\n\n // Vertical split (childNode1 = left half, childNode2 = right half).\n if (widthDifference > heightDifference) {\n node.childNode1 = new TextureAtlasNode(\n new Cartesian2(node.bottomLeft.x, node.bottomLeft.y),\n new Cartesian2(node.bottomLeft.x + image.width, node.topRight.y)\n );\n // Only make a second child if the border gives enough space.\n const childNode2BottomLeftX =\n node.bottomLeft.x + image.width + textureAtlas._borderWidthInPixels;\n if (childNode2BottomLeftX < node.topRight.x) {\n node.childNode2 = new TextureAtlasNode(\n new Cartesian2(childNode2BottomLeftX, node.bottomLeft.y),\n new Cartesian2(node.topRight.x, node.topRight.y)\n );\n }\n }\n // Horizontal split (childNode1 = bottom half, childNode2 = top half).\n else {\n node.childNode1 = new TextureAtlasNode(\n new Cartesian2(node.bottomLeft.x, node.bottomLeft.y),\n new Cartesian2(node.topRight.x, node.bottomLeft.y + image.height)\n );\n // Only make a second child if the border gives enough space.\n const childNode2BottomLeftY =\n node.bottomLeft.y + image.height + textureAtlas._borderWidthInPixels;\n if (childNode2BottomLeftY < node.topRight.y) {\n node.childNode2 = new TextureAtlasNode(\n new Cartesian2(node.bottomLeft.x, childNode2BottomLeftY),\n new Cartesian2(node.topRight.x, node.topRight.y)\n );\n }\n }\n return findNode(textureAtlas, node.childNode1, image);\n }\n\n // If not a leaf node\n return (\n findNode(textureAtlas, node.childNode1, image) ||\n findNode(textureAtlas, node.childNode2, image)\n );\n}\n\n// Adds image of given index to the texture atlas. Called from addImage and addImages.\nfunction addImage(textureAtlas, image, index) {\n const node = findNode(textureAtlas, textureAtlas._root, image);\n if (defined(node)) {\n // Found a node that can hold the image.\n node.imageIndex = index;\n\n // Add texture coordinate and write to texture\n const atlasWidth = textureAtlas._texture.width;\n const atlasHeight = textureAtlas._texture.height;\n const nodeWidth = node.topRight.x - node.bottomLeft.x;\n const nodeHeight = node.topRight.y - node.bottomLeft.y;\n const x = node.bottomLeft.x / atlasWidth;\n const y = node.bottomLeft.y / atlasHeight;\n const w = nodeWidth / atlasWidth;\n const h = nodeHeight / atlasHeight;\n textureAtlas._textureCoordinates[index] = new BoundingRectangle(x, y, w, h);\n textureAtlas._texture.copyFrom({\n source: image,\n xOffset: node.bottomLeft.x,\n yOffset: node.bottomLeft.y,\n });\n } else {\n // No node found, must resize the texture atlas.\n resizeAtlas(textureAtlas, image);\n addImage(textureAtlas, image, index);\n }\n\n textureAtlas._guid = createGuid();\n}\n\nfunction getIndex(atlas, image) {\n if (!defined(atlas) || atlas.isDestroyed()) {\n return -1;\n }\n\n const index = atlas.numberOfImages;\n\n addImage(atlas, image, index);\n\n return index;\n}\n\n/**\n * If the image is already in the atlas, the existing index is returned. Otherwise, the result is undefined.\n *\n * @param {string} id An identifier to detect whether the image already exists in the atlas.\n * @returns {number|undefined} The image index, or undefined if the image does not exist in the atlas.\n */\nTextureAtlas.prototype.getImageIndex = function (id) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n //>>includeEnd('debug');\n\n return this._indexHash[id];\n};\n\n/**\n * Adds an image to the atlas synchronously. If the image is already in the atlas, the atlas is unchanged and\n * the existing index is used.\n *\n * @param {string} id An identifier to detect whether the image already exists in the atlas.\n * @param {HTMLImageElement|HTMLCanvasElement} image An image or canvas to add to the texture atlas.\n * @returns {number} The image index.\n */\nTextureAtlas.prototype.addImageSync = function (id, image) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n if (!defined(image)) {\n throw new DeveloperError(\"image is required.\");\n }\n //>>includeEnd('debug');\n\n let index = this._indexHash[id];\n if (defined(index)) {\n // we're already aware of this source\n return index;\n }\n\n index = getIndex(this, image);\n // store the promise\n this._idHash[id] = Promise.resolve(index);\n this._indexHash[id] = index;\n // but return the value synchronously\n return index;\n};\n\n/**\n * Adds an image to the atlas. If the image is already in the atlas, the atlas is unchanged and\n * the existing index is used.\n *\n * @param {string} id An identifier to detect whether the image already exists in the atlas.\n * @param {HTMLImageElement|HTMLCanvasElement|string|Resource|Promise|TextureAtlas.CreateImageCallback} image An image or canvas to add to the texture atlas,\n * or a URL to an Image, or a Promise for an image, or a function that creates an image.\n * @returns {Promise} A Promise for the image index.\n */\nTextureAtlas.prototype.addImage = function (id, image) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n if (!defined(image)) {\n throw new DeveloperError(\"image is required.\");\n }\n //>>includeEnd('debug');\n\n let indexPromise = this._idHash[id];\n if (defined(indexPromise)) {\n // we're already aware of this source\n return indexPromise;\n }\n\n // not in atlas, create the promise for the index\n\n if (typeof image === \"function\") {\n // if image is a function, call it\n image = image(id);\n //>>includeStart('debug', pragmas.debug);\n if (!defined(image)) {\n throw new DeveloperError(\"image is required.\");\n }\n //>>includeEnd('debug');\n } else if (typeof image === \"string\" || image instanceof Resource) {\n // Get a resource\n const resource = Resource.createIfNeeded(image);\n image = resource.fetchImage();\n }\n\n const that = this;\n indexPromise = Promise.resolve(image).then(function (image) {\n const index = getIndex(that, image);\n that._indexHash[id] = index;\n return index;\n });\n\n // store the promise\n this._idHash[id] = indexPromise;\n\n return indexPromise;\n};\n\n/**\n * Add a sub-region of an existing atlas image as additional image indices.\n *\n * @param {string} id The identifier of the existing image.\n * @param {BoundingRectangle} subRegion An {@link BoundingRectangle} sub-region measured in pixels from the bottom-left.\n *\n * @returns {Promise} A Promise for the image index.\n */\nTextureAtlas.prototype.addSubRegion = function (id, subRegion) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n if (!defined(subRegion)) {\n throw new DeveloperError(\"subRegion is required.\");\n }\n //>>includeEnd('debug');\n\n const indexPromise = this._idHash[id];\n if (!defined(indexPromise)) {\n throw new RuntimeError(`image with id \"${id}\" not found in the atlas.`);\n }\n\n const that = this;\n return Promise.resolve(indexPromise).then(function (index) {\n if (index === -1) {\n // the atlas is destroyed\n return -1;\n }\n const atlasWidth = that._texture.width;\n const atlasHeight = that._texture.height;\n\n const baseRegion = that._textureCoordinates[index];\n const x = baseRegion.x + subRegion.x / atlasWidth;\n const y = baseRegion.y + subRegion.y / atlasHeight;\n const w = subRegion.width / atlasWidth;\n const h = subRegion.height / atlasHeight;\n const newIndex =\n that._textureCoordinates.push(new BoundingRectangle(x, y, w, h)) - 1;\n that._indexHash[id] = newIndex;\n\n that._guid = createGuid();\n\n return newIndex;\n });\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see TextureAtlas#destroy\n */\nTextureAtlas.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * atlas = atlas && atlas.destroy();\n *\n * @see TextureAtlas#isDestroyed\n */\nTextureAtlas.prototype.destroy = function () {\n this._texture = this._texture && this._texture.destroy();\n return destroyObject(this);\n};\n\n/**\n * A function that creates an image.\n * @callback TextureAtlas.CreateImageCallback\n * @param {string} id The identifier of the image to load.\n * @returns {HTMLImageElement|Promise} The image, or a promise that will resolve to an image.\n */\nexport default TextureAtlas;\n", "import AttributeCompression from \"../Core/AttributeCompression.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArrayFacade from \"../Renderer/VertexArrayFacade.js\";\nimport BillboardCollectionFS from \"../Shaders/BillboardCollectionFS.js\";\nimport BillboardCollectionVS from \"../Shaders/BillboardCollectionVS.js\";\nimport Billboard from \"./Billboard.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport BlendOption from \"./BlendOption.js\";\nimport HeightReference from \"./HeightReference.js\";\nimport HorizontalOrigin from \"./HorizontalOrigin.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport SDFSettings from \"./SDFSettings.js\";\nimport TextureAtlas from \"./TextureAtlas.js\";\nimport VerticalOrigin from \"./VerticalOrigin.js\";\n\nconst SHOW_INDEX = Billboard.SHOW_INDEX;\nconst POSITION_INDEX = Billboard.POSITION_INDEX;\nconst PIXEL_OFFSET_INDEX = Billboard.PIXEL_OFFSET_INDEX;\nconst EYE_OFFSET_INDEX = Billboard.EYE_OFFSET_INDEX;\nconst HORIZONTAL_ORIGIN_INDEX = Billboard.HORIZONTAL_ORIGIN_INDEX;\nconst VERTICAL_ORIGIN_INDEX = Billboard.VERTICAL_ORIGIN_INDEX;\nconst SCALE_INDEX = Billboard.SCALE_INDEX;\nconst IMAGE_INDEX_INDEX = Billboard.IMAGE_INDEX_INDEX;\nconst COLOR_INDEX = Billboard.COLOR_INDEX;\nconst ROTATION_INDEX = Billboard.ROTATION_INDEX;\nconst ALIGNED_AXIS_INDEX = Billboard.ALIGNED_AXIS_INDEX;\nconst SCALE_BY_DISTANCE_INDEX = Billboard.SCALE_BY_DISTANCE_INDEX;\nconst TRANSLUCENCY_BY_DISTANCE_INDEX = Billboard.TRANSLUCENCY_BY_DISTANCE_INDEX;\nconst PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX =\n Billboard.PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX;\nconst DISTANCE_DISPLAY_CONDITION_INDEX = Billboard.DISTANCE_DISPLAY_CONDITION;\nconst DISABLE_DEPTH_DISTANCE = Billboard.DISABLE_DEPTH_DISTANCE;\nconst TEXTURE_COORDINATE_BOUNDS = Billboard.TEXTURE_COORDINATE_BOUNDS;\nconst SDF_INDEX = Billboard.SDF_INDEX;\nconst NUMBER_OF_PROPERTIES = Billboard.NUMBER_OF_PROPERTIES;\n\nlet attributeLocations;\n\nconst attributeLocationsBatched = {\n positionHighAndScale: 0,\n positionLowAndRotation: 1,\n compressedAttribute0: 2, // pixel offset, translate, horizontal origin, vertical origin, show, direction, texture coordinates\n compressedAttribute1: 3, // aligned axis, translucency by distance, image width\n compressedAttribute2: 4, // image height, color, pick color, size in meters, valid aligned axis, 13 bits free\n eyeOffset: 5, // 4 bytes free\n scaleByDistance: 6,\n pixelOffsetScaleByDistance: 7,\n compressedAttribute3: 8,\n textureCoordinateBoundsOrLabelTranslate: 9,\n a_batchId: 10,\n sdf: 11,\n};\n\nconst attributeLocationsInstanced = {\n direction: 0,\n positionHighAndScale: 1,\n positionLowAndRotation: 2, // texture offset in w\n compressedAttribute0: 3,\n compressedAttribute1: 4,\n compressedAttribute2: 5,\n eyeOffset: 6, // texture range in w\n scaleByDistance: 7,\n pixelOffsetScaleByDistance: 8,\n compressedAttribute3: 9,\n textureCoordinateBoundsOrLabelTranslate: 10,\n a_batchId: 11,\n sdf: 12,\n};\n\n/**\n * A renderable collection of billboards. Billboards are viewport-aligned\n * images positioned in the 3D scene.\n *

\n *
\n *
\n * Example billboards\n *
\n *

\n * Billboards are added and removed from the collection using {@link BillboardCollection#add}\n * and {@link BillboardCollection#remove}. Billboards in a collection automatically share textures\n * for images with the same identifier.\n *\n * @alias BillboardCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each billboard from model to world coordinates.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {Scene} [options.scene] Must be passed in for billboards that use the height reference property or will be depth tested against the globe.\n * @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The billboard blending option. The default\n * is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.\n * @param {boolean} [options.show=true] Determines if the billboards in the collection will be shown.\n *\n * @performance For best performance, prefer a few collections, each with many billboards, to\n * many collections with only a few billboards each. Organize collections so that billboards\n * with the same update frequency are in the same collection, i.e., billboards that do not\n * change should be in one collection; billboards that change every frame should be in another\n * collection; and so on.\n *\n * @see BillboardCollection#add\n * @see BillboardCollection#remove\n * @see Billboard\n * @see LabelCollection\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo}\n *\n * @example\n * // Create a billboard collection with two billboards\n * const billboards = scene.primitives.add(new Cesium.BillboardCollection());\n * billboards.add({\n * position : new Cesium.Cartesian3(1.0, 2.0, 3.0),\n * image : 'url/to/image'\n * });\n * billboards.add({\n * position : new Cesium.Cartesian3(4.0, 5.0, 6.0),\n * image : 'url/to/another/image'\n * });\n */\nfunction BillboardCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._scene = options.scene;\n this._batchTable = options.batchTable;\n\n this._textureAtlas = undefined;\n this._textureAtlasGUID = undefined;\n this._destroyTextureAtlas = true;\n this._sp = undefined;\n this._spTranslucent = undefined;\n this._rsOpaque = undefined;\n this._rsTranslucent = undefined;\n this._vaf = undefined;\n\n this._billboards = [];\n this._billboardsToUpdate = [];\n this._billboardsToUpdateIndex = 0;\n this._billboardsRemoved = false;\n this._createVertexArray = false;\n\n this._shaderRotation = false;\n this._compiledShaderRotation = false;\n\n this._shaderAlignedAxis = false;\n this._compiledShaderAlignedAxis = false;\n\n this._shaderScaleByDistance = false;\n this._compiledShaderScaleByDistance = false;\n\n this._shaderTranslucencyByDistance = false;\n this._compiledShaderTranslucencyByDistance = false;\n\n this._shaderPixelOffsetScaleByDistance = false;\n this._compiledShaderPixelOffsetScaleByDistance = false;\n\n this._shaderDistanceDisplayCondition = false;\n this._compiledShaderDistanceDisplayCondition = false;\n\n this._shaderDisableDepthDistance = false;\n this._compiledShaderDisableDepthDistance = false;\n\n this._shaderClampToGround = false;\n this._compiledShaderClampToGround = false;\n\n this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);\n\n this._maxSize = 0.0;\n this._maxEyeOffset = 0.0;\n this._maxScale = 1.0;\n this._maxPixelOffset = 0.0;\n this._allHorizontalCenter = true;\n this._allVerticalCenter = true;\n this._allSizedInMeters = true;\n\n this._baseVolume = new BoundingSphere();\n this._baseVolumeWC = new BoundingSphere();\n this._baseVolume2D = new BoundingSphere();\n this._boundingVolume = new BoundingSphere();\n this._boundingVolumeDirty = false;\n\n this._colorCommands = [];\n\n /**\n * Determines if billboards in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * The 4x4 transformation matrix that transforms each billboard in this collection from model to world coordinates.\n * When this is the identity matrix, the billboards are drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n * @type {Matrix4}\n * @default {@link Matrix4.IDENTITY}\n *\n *\n * @example\n * const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\n * billboards.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);\n * billboards.add({\n * image : 'url/to/image',\n * position : new Cesium.Cartesian3(0.0, 0.0, 0.0) // center\n * });\n * billboards.add({\n * image : 'url/to/image',\n * position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0) // east\n * });\n * billboards.add({\n * image : 'url/to/image',\n * position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0) // north\n * });\n * billboards.add({\n * image : 'url/to/image',\n * position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0) // up\n * });\n *\n * @see Transforms.eastNorthUpToFixedFrame\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the texture atlas for this BillboardCollection as a fullscreen quad.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowTextureAtlas = defaultValue(\n options.debugShowTextureAtlas,\n false\n );\n\n /**\n * The billboard blending option. The default is used for rendering both opaque and translucent billboards.\n * However, if either all of the billboards are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve\n * performance by up to 2x.\n * @type {BlendOption}\n * @default BlendOption.OPAQUE_AND_TRANSLUCENT\n */\n this.blendOption = defaultValue(\n options.blendOption,\n BlendOption.OPAQUE_AND_TRANSLUCENT\n );\n this._blendOption = undefined;\n\n this._mode = SceneMode.SCENE3D;\n\n // The buffer usage for each attribute is determined based on the usage of the attribute over time.\n this._buffersUsage = [\n BufferUsage.STATIC_DRAW, // SHOW_INDEX\n BufferUsage.STATIC_DRAW, // POSITION_INDEX\n BufferUsage.STATIC_DRAW, // PIXEL_OFFSET_INDEX\n BufferUsage.STATIC_DRAW, // EYE_OFFSET_INDEX\n BufferUsage.STATIC_DRAW, // HORIZONTAL_ORIGIN_INDEX\n BufferUsage.STATIC_DRAW, // VERTICAL_ORIGIN_INDEX\n BufferUsage.STATIC_DRAW, // SCALE_INDEX\n BufferUsage.STATIC_DRAW, // IMAGE_INDEX_INDEX\n BufferUsage.STATIC_DRAW, // COLOR_INDEX\n BufferUsage.STATIC_DRAW, // ROTATION_INDEX\n BufferUsage.STATIC_DRAW, // ALIGNED_AXIS_INDEX\n BufferUsage.STATIC_DRAW, // SCALE_BY_DISTANCE_INDEX\n BufferUsage.STATIC_DRAW, // TRANSLUCENCY_BY_DISTANCE_INDEX\n BufferUsage.STATIC_DRAW, // PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX\n BufferUsage.STATIC_DRAW, // DISTANCE_DISPLAY_CONDITION_INDEX\n BufferUsage.STATIC_DRAW, // TEXTURE_COORDINATE_BOUNDS\n ];\n\n this._highlightColor = Color.clone(Color.WHITE); // Only used by Vector3DTilePoints\n\n const that = this;\n this._uniforms = {\n u_atlas: function () {\n return that._textureAtlas.texture;\n },\n u_highlightColor: function () {\n return that._highlightColor;\n },\n };\n\n const scene = this._scene;\n if (defined(scene) && defined(scene.terrainProviderChanged)) {\n this._removeCallbackFunc = scene.terrainProviderChanged.addEventListener(\n function () {\n const billboards = this._billboards;\n const length = billboards.length;\n for (let i = 0; i < length; ++i) {\n if (defined(billboards[i])) {\n billboards[i]._updateClamping();\n }\n }\n },\n this\n );\n }\n}\n\nObject.defineProperties(BillboardCollection.prototype, {\n /**\n * Returns the number of billboards in this collection. This is commonly used with\n * {@link BillboardCollection#get} to iterate over all the billboards\n * in the collection.\n * @memberof BillboardCollection.prototype\n * @type {number}\n */\n length: {\n get: function () {\n removeBillboards(this);\n return this._billboards.length;\n },\n },\n\n /**\n * Gets or sets the textureAtlas.\n * @memberof BillboardCollection.prototype\n * @type {TextureAtlas}\n * @private\n */\n textureAtlas: {\n get: function () {\n return this._textureAtlas;\n },\n set: function (value) {\n if (this._textureAtlas !== value) {\n this._textureAtlas =\n this._destroyTextureAtlas &&\n this._textureAtlas &&\n this._textureAtlas.destroy();\n this._textureAtlas = value;\n this._createVertexArray = true; // New per-billboard texture coordinates\n }\n },\n },\n\n /**\n * Gets or sets a value which determines if the texture atlas is\n * destroyed when the collection is destroyed.\n *\n * If the texture atlas is used by more than one collection, set this to false,\n * and explicitly destroy the atlas to avoid attempting to destroy it multiple times.\n *\n * @memberof BillboardCollection.prototype\n * @type {boolean}\n * @private\n *\n * @example\n * // Set destroyTextureAtlas\n * // Destroy a billboard collection but not its texture atlas.\n *\n * const atlas = new TextureAtlas({\n * scene : scene,\n * images : images\n * });\n * billboards.textureAtlas = atlas;\n * billboards.destroyTextureAtlas = false;\n * billboards = billboards.destroy();\n * console.log(atlas.isDestroyed()); // False\n */\n destroyTextureAtlas: {\n get: function () {\n return this._destroyTextureAtlas;\n },\n set: function (value) {\n this._destroyTextureAtlas = value;\n },\n },\n});\n\nfunction destroyBillboards(billboards) {\n const length = billboards.length;\n for (let i = 0; i < length; ++i) {\n if (billboards[i]) {\n billboards[i]._destroy();\n }\n }\n}\n\n/**\n * Creates and adds a billboard with the specified initial properties to the collection.\n * The added billboard is returned so it can be modified or removed from the collection later.\n *\n * @param {object}[options] A template describing the billboard's properties as shown in Example 1.\n * @returns {Billboard} The billboard that was added to the collection.\n *\n * @performance Calling add is expected constant time. However, the collection's vertex buffer\n * is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For\n * best performance, add as many billboards as possible before calling update.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Example 1: Add a billboard, specifying all the default values.\n * const b = billboards.add({\n * show : true,\n * position : Cesium.Cartesian3.ZERO,\n * pixelOffset : Cesium.Cartesian2.ZERO,\n * eyeOffset : Cesium.Cartesian3.ZERO,\n * heightReference : Cesium.HeightReference.NONE,\n * horizontalOrigin : Cesium.HorizontalOrigin.CENTER,\n * verticalOrigin : Cesium.VerticalOrigin.CENTER,\n * scale : 1.0,\n * image : 'url/to/image',\n * imageSubRegion : undefined,\n * color : Cesium.Color.WHITE,\n * id : undefined,\n * rotation : 0.0,\n * alignedAxis : Cesium.Cartesian3.ZERO,\n * width : undefined,\n * height : undefined,\n * scaleByDistance : undefined,\n * translucencyByDistance : undefined,\n * pixelOffsetScaleByDistance : undefined,\n * sizeInMeters : false,\n * distanceDisplayCondition : undefined\n * });\n *\n * @example\n * // Example 2: Specify only the billboard's cartographic position.\n * const b = billboards.add({\n * position : Cesium.Cartesian3.fromDegrees(longitude, latitude, height)\n * });\n *\n * @see BillboardCollection#remove\n * @see BillboardCollection#removeAll\n */\nBillboardCollection.prototype.add = function (options) {\n const billboard = new Billboard(options, this);\n billboard._index = this._billboards.length;\n\n this._billboards.push(billboard);\n this._createVertexArray = true;\n\n return billboard;\n};\n\n/**\n * Removes a billboard from the collection.\n *\n * @param {Billboard} billboard The billboard to remove.\n * @returns {boolean} true if the billboard was removed; false if the billboard was not found in the collection.\n *\n * @performance Calling remove is expected constant time. However, the collection's vertex buffer\n * is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For\n * best performance, remove as many billboards as possible before calling update.\n * If you intend to temporarily hide a billboard, it is usually more efficient to call\n * {@link Billboard#show} instead of removing and re-adding the billboard.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * const b = billboards.add(...);\n * billboards.remove(b); // Returns true\n *\n * @see BillboardCollection#add\n * @see BillboardCollection#removeAll\n * @see Billboard#show\n */\nBillboardCollection.prototype.remove = function (billboard) {\n if (this.contains(billboard)) {\n this._billboards[billboard._index] = undefined; // Removed later\n this._billboardsRemoved = true;\n this._createVertexArray = true;\n billboard._destroy();\n return true;\n }\n\n return false;\n};\n\n/**\n * Removes all billboards from the collection.\n *\n * @performance O(n). It is more efficient to remove all the billboards\n * from a collection and then add new ones than to create a new collection entirely.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * billboards.add(...);\n * billboards.add(...);\n * billboards.removeAll();\n *\n * @see BillboardCollection#add\n * @see BillboardCollection#remove\n */\nBillboardCollection.prototype.removeAll = function () {\n destroyBillboards(this._billboards);\n this._billboards = [];\n this._billboardsToUpdate = [];\n this._billboardsToUpdateIndex = 0;\n this._billboardsRemoved = false;\n\n this._createVertexArray = true;\n};\n\nfunction removeBillboards(billboardCollection) {\n if (billboardCollection._billboardsRemoved) {\n billboardCollection._billboardsRemoved = false;\n\n const newBillboards = [];\n const billboards = billboardCollection._billboards;\n const length = billboards.length;\n for (let i = 0, j = 0; i < length; ++i) {\n const billboard = billboards[i];\n if (defined(billboard)) {\n billboard._index = j++;\n newBillboards.push(billboard);\n }\n }\n\n billboardCollection._billboards = newBillboards;\n }\n}\n\nBillboardCollection.prototype._updateBillboard = function (\n billboard,\n propertyChanged\n) {\n if (!billboard._dirty) {\n this._billboardsToUpdate[this._billboardsToUpdateIndex++] = billboard;\n }\n\n ++this._propertiesChanged[propertyChanged];\n};\n\n/**\n * Check whether this collection contains a given billboard.\n *\n * @param {Billboard} [billboard] The billboard to check for.\n * @returns {boolean} true if this collection contains the billboard, false otherwise.\n *\n * @see BillboardCollection#get\n */\nBillboardCollection.prototype.contains = function (billboard) {\n return defined(billboard) && billboard._billboardCollection === this;\n};\n\n/**\n * Returns the billboard in the collection at the specified index. Indices are zero-based\n * and increase as billboards are added. Removing a billboard shifts all billboards after\n * it to the left, changing their indices. This function is commonly used with\n * {@link BillboardCollection#length} to iterate over all the billboards\n * in the collection.\n *\n * @param {number} index The zero-based index of the billboard.\n * @returns {Billboard} The billboard at the specified index.\n *\n * @performance Expected constant time. If billboards were removed from the collection and\n * {@link BillboardCollection#update} was not called, an implicit O(n)\n * operation is performed.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Toggle the show property of every billboard in the collection\n * const len = billboards.length;\n * for (let i = 0; i < len; ++i) {\n * const b = billboards.get(i);\n * b.show = !b.show;\n * }\n *\n * @see BillboardCollection#length\n */\nBillboardCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"index\", index);\n //>>includeEnd('debug');\n\n removeBillboards(this);\n return this._billboards[index];\n};\n\nlet getIndexBuffer;\n\nfunction getIndexBufferBatched(context) {\n const sixteenK = 16 * 1024;\n\n let indexBuffer = context.cache.billboardCollection_indexBufferBatched;\n if (defined(indexBuffer)) {\n return indexBuffer;\n }\n\n // Subtract 6 because the last index is reserverd for primitive restart.\n // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.18\n const length = sixteenK * 6 - 6;\n const indices = new Uint16Array(length);\n for (let i = 0, j = 0; i < length; i += 6, j += 4) {\n indices[i] = j;\n indices[i + 1] = j + 1;\n indices[i + 2] = j + 2;\n\n indices[i + 3] = j + 0;\n indices[i + 4] = j + 2;\n indices[i + 5] = j + 3;\n }\n\n // PERFORMANCE_IDEA: Should we reference count billboard collections, and eventually delete this?\n // Is this too much memory to allocate up front? Should we dynamically grow it?\n indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: indices,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: IndexDatatype.UNSIGNED_SHORT,\n });\n indexBuffer.vertexArrayDestroyable = false;\n context.cache.billboardCollection_indexBufferBatched = indexBuffer;\n return indexBuffer;\n}\n\nfunction getIndexBufferInstanced(context) {\n let indexBuffer = context.cache.billboardCollection_indexBufferInstanced;\n if (defined(indexBuffer)) {\n return indexBuffer;\n }\n\n indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: new Uint16Array([0, 1, 2, 0, 2, 3]),\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: IndexDatatype.UNSIGNED_SHORT,\n });\n\n indexBuffer.vertexArrayDestroyable = false;\n context.cache.billboardCollection_indexBufferInstanced = indexBuffer;\n return indexBuffer;\n}\n\nfunction getVertexBufferInstanced(context) {\n let vertexBuffer = context.cache.billboardCollection_vertexBufferInstanced;\n if (defined(vertexBuffer)) {\n return vertexBuffer;\n }\n\n vertexBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: new Float32Array([0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]),\n usage: BufferUsage.STATIC_DRAW,\n });\n\n vertexBuffer.vertexArrayDestroyable = false;\n context.cache.billboardCollection_vertexBufferInstanced = vertexBuffer;\n return vertexBuffer;\n}\n\nBillboardCollection.prototype.computeNewBuffersUsage = function () {\n const buffersUsage = this._buffersUsage;\n let usageChanged = false;\n\n const properties = this._propertiesChanged;\n for (let k = 0; k < NUMBER_OF_PROPERTIES; ++k) {\n const newUsage =\n properties[k] === 0 ? BufferUsage.STATIC_DRAW : BufferUsage.STREAM_DRAW;\n usageChanged = usageChanged || buffersUsage[k] !== newUsage;\n buffersUsage[k] = newUsage;\n }\n\n return usageChanged;\n};\n\nfunction createVAF(\n context,\n numberOfBillboards,\n buffersUsage,\n instanced,\n batchTable,\n sdf\n) {\n const attributes = [\n {\n index: attributeLocations.positionHighAndScale,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[POSITION_INDEX],\n },\n {\n index: attributeLocations.positionLowAndRotation,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[POSITION_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute0,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[PIXEL_OFFSET_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute1,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[TRANSLUCENCY_BY_DISTANCE_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute2,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[COLOR_INDEX],\n },\n {\n index: attributeLocations.eyeOffset,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[EYE_OFFSET_INDEX],\n },\n {\n index: attributeLocations.scaleByDistance,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[SCALE_BY_DISTANCE_INDEX],\n },\n {\n index: attributeLocations.pixelOffsetScaleByDistance,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute3,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[DISTANCE_DISPLAY_CONDITION_INDEX],\n },\n {\n index: attributeLocations.textureCoordinateBoundsOrLabelTranslate,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[TEXTURE_COORDINATE_BOUNDS],\n },\n ];\n\n // Instancing requires one non-instanced attribute.\n if (instanced) {\n attributes.push({\n index: attributeLocations.direction,\n componentsPerAttribute: 2,\n componentDatatype: ComponentDatatype.FLOAT,\n vertexBuffer: getVertexBufferInstanced(context),\n });\n }\n\n if (defined(batchTable)) {\n attributes.push({\n index: attributeLocations.a_batchId,\n componentsPerAttribute: 1,\n componentDatatype: ComponentDatatype.FLOAT,\n bufferUsage: BufferUsage.STATIC_DRAW,\n });\n }\n\n if (sdf) {\n attributes.push({\n index: attributeLocations.sdf,\n componentsPerAttribute: 2,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[SDF_INDEX],\n });\n }\n\n // When instancing is enabled, only one vertex is needed for each billboard.\n const sizeInVertices = instanced\n ? numberOfBillboards\n : 4 * numberOfBillboards;\n return new VertexArrayFacade(context, attributes, sizeInVertices, instanced);\n}\n\n///////////////////////////////////////////////////////////////////////////\n\n// Four vertices per billboard. Each has the same position, etc., but a different screen-space direction vector.\n\n// PERFORMANCE_IDEA: Save memory if a property is the same for all billboards, use a latched attribute state,\n// instead of storing it in a vertex buffer.\n\nconst writePositionScratch = new EncodedCartesian3();\n\nfunction writePositionScaleAndRotation(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const positionHighWriter =\n vafWriters[attributeLocations.positionHighAndScale];\n const positionLowWriter =\n vafWriters[attributeLocations.positionLowAndRotation];\n const position = billboard._getActualPosition();\n\n if (billboardCollection._mode === SceneMode.SCENE3D) {\n BoundingSphere.expand(\n billboardCollection._baseVolume,\n position,\n billboardCollection._baseVolume\n );\n billboardCollection._boundingVolumeDirty = true;\n }\n\n EncodedCartesian3.fromCartesian(position, writePositionScratch);\n const scale = billboard.scale;\n const rotation = billboard.rotation;\n\n if (rotation !== 0.0) {\n billboardCollection._shaderRotation = true;\n }\n\n billboardCollection._maxScale = Math.max(\n billboardCollection._maxScale,\n scale\n );\n\n const high = writePositionScratch.high;\n const low = writePositionScratch.low;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n positionHighWriter(i, high.x, high.y, high.z, scale);\n positionLowWriter(i, low.x, low.y, low.z, rotation);\n } else {\n i = billboard._index * 4;\n positionHighWriter(i + 0, high.x, high.y, high.z, scale);\n positionHighWriter(i + 1, high.x, high.y, high.z, scale);\n positionHighWriter(i + 2, high.x, high.y, high.z, scale);\n positionHighWriter(i + 3, high.x, high.y, high.z, scale);\n\n positionLowWriter(i + 0, low.x, low.y, low.z, rotation);\n positionLowWriter(i + 1, low.x, low.y, low.z, rotation);\n positionLowWriter(i + 2, low.x, low.y, low.z, rotation);\n positionLowWriter(i + 3, low.x, low.y, low.z, rotation);\n }\n}\n\nconst scratchCartesian2 = new Cartesian2();\n\nconst UPPER_BOUND = 32768.0; // 2^15\n\nconst LEFT_SHIFT16 = 65536.0; // 2^16\nconst LEFT_SHIFT12 = 4096.0; // 2^12\nconst LEFT_SHIFT8 = 256.0; // 2^8\nconst LEFT_SHIFT7 = 128.0;\nconst LEFT_SHIFT5 = 32.0;\nconst LEFT_SHIFT3 = 8.0;\nconst LEFT_SHIFT2 = 4.0;\n\nconst RIGHT_SHIFT8 = 1.0 / 256.0;\n\nconst LOWER_LEFT = 0.0;\nconst LOWER_RIGHT = 2.0;\nconst UPPER_RIGHT = 3.0;\nconst UPPER_LEFT = 1.0;\n\nfunction writeCompressedAttrib0(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.compressedAttribute0];\n const pixelOffset = billboard.pixelOffset;\n const pixelOffsetX = pixelOffset.x;\n const pixelOffsetY = pixelOffset.y;\n\n const translate = billboard._translate;\n const translateX = translate.x;\n const translateY = translate.y;\n\n billboardCollection._maxPixelOffset = Math.max(\n billboardCollection._maxPixelOffset,\n Math.abs(pixelOffsetX + translateX),\n Math.abs(-pixelOffsetY + translateY)\n );\n\n const horizontalOrigin = billboard.horizontalOrigin;\n let verticalOrigin = billboard._verticalOrigin;\n let show = billboard.show && billboard.clusterShow;\n\n // If the color alpha is zero, do not show this billboard. This lets us avoid providing\n // color during the pick pass and also eliminates a discard in the fragment shader.\n if (billboard.color.alpha === 0.0) {\n show = false;\n }\n\n // Raw billboards don't distinguish between BASELINE and BOTTOM, only LabelCollection does that.\n if (verticalOrigin === VerticalOrigin.BASELINE) {\n verticalOrigin = VerticalOrigin.BOTTOM;\n }\n\n billboardCollection._allHorizontalCenter =\n billboardCollection._allHorizontalCenter &&\n horizontalOrigin === HorizontalOrigin.CENTER;\n billboardCollection._allVerticalCenter =\n billboardCollection._allVerticalCenter &&\n verticalOrigin === VerticalOrigin.CENTER;\n\n let bottomLeftX = 0;\n let bottomLeftY = 0;\n let width = 0;\n let height = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n bottomLeftX = imageRectangle.x;\n bottomLeftY = imageRectangle.y;\n width = imageRectangle.width;\n height = imageRectangle.height;\n }\n const topRightX = bottomLeftX + width;\n const topRightY = bottomLeftY + height;\n\n let compressed0 =\n Math.floor(\n CesiumMath.clamp(pixelOffsetX, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND\n ) * LEFT_SHIFT7;\n compressed0 += (horizontalOrigin + 1.0) * LEFT_SHIFT5;\n compressed0 += (verticalOrigin + 1.0) * LEFT_SHIFT3;\n compressed0 += (show ? 1.0 : 0.0) * LEFT_SHIFT2;\n\n let compressed1 =\n Math.floor(\n CesiumMath.clamp(pixelOffsetY, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND\n ) * LEFT_SHIFT8;\n let compressed2 =\n Math.floor(\n CesiumMath.clamp(translateX, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND\n ) * LEFT_SHIFT8;\n\n const tempTanslateY =\n (CesiumMath.clamp(translateY, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND) *\n RIGHT_SHIFT8;\n const upperTranslateY = Math.floor(tempTanslateY);\n const lowerTranslateY = Math.floor(\n (tempTanslateY - upperTranslateY) * LEFT_SHIFT8\n );\n\n compressed1 += upperTranslateY;\n compressed2 += lowerTranslateY;\n\n scratchCartesian2.x = bottomLeftX;\n scratchCartesian2.y = bottomLeftY;\n const compressedTexCoordsLL = AttributeCompression.compressTextureCoordinates(\n scratchCartesian2\n );\n scratchCartesian2.x = topRightX;\n const compressedTexCoordsLR = AttributeCompression.compressTextureCoordinates(\n scratchCartesian2\n );\n scratchCartesian2.y = topRightY;\n const compressedTexCoordsUR = AttributeCompression.compressTextureCoordinates(\n scratchCartesian2\n );\n scratchCartesian2.x = bottomLeftX;\n const compressedTexCoordsUL = AttributeCompression.compressTextureCoordinates(\n scratchCartesian2\n );\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, compressed0, compressed1, compressed2, compressedTexCoordsLL);\n } else {\n i = billboard._index * 4;\n writer(\n i + 0,\n compressed0 + LOWER_LEFT,\n compressed1,\n compressed2,\n compressedTexCoordsLL\n );\n writer(\n i + 1,\n compressed0 + LOWER_RIGHT,\n compressed1,\n compressed2,\n compressedTexCoordsLR\n );\n writer(\n i + 2,\n compressed0 + UPPER_RIGHT,\n compressed1,\n compressed2,\n compressedTexCoordsUR\n );\n writer(\n i + 3,\n compressed0 + UPPER_LEFT,\n compressed1,\n compressed2,\n compressedTexCoordsUL\n );\n }\n}\n\nfunction writeCompressedAttrib1(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.compressedAttribute1];\n const alignedAxis = billboard.alignedAxis;\n if (!Cartesian3.equals(alignedAxis, Cartesian3.ZERO)) {\n billboardCollection._shaderAlignedAxis = true;\n }\n\n let near = 0.0;\n let nearValue = 1.0;\n let far = 1.0;\n let farValue = 1.0;\n\n const translucency = billboard.translucencyByDistance;\n if (defined(translucency)) {\n near = translucency.near;\n nearValue = translucency.nearValue;\n far = translucency.far;\n farValue = translucency.farValue;\n\n if (nearValue !== 1.0 || farValue !== 1.0) {\n // translucency by distance calculation in shader need not be enabled\n // until a billboard with near and far !== 1.0 is found\n billboardCollection._shaderTranslucencyByDistance = true;\n }\n }\n\n let width = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n width = imageRectangle.width;\n }\n\n const textureWidth = billboardCollection._textureAtlas.texture.width;\n const imageWidth = Math.round(\n defaultValue(billboard.width, textureWidth * width)\n );\n billboardCollection._maxSize = Math.max(\n billboardCollection._maxSize,\n imageWidth\n );\n\n let compressed0 = CesiumMath.clamp(imageWidth, 0.0, LEFT_SHIFT16);\n let compressed1 = 0.0;\n\n if (\n Math.abs(Cartesian3.magnitudeSquared(alignedAxis) - 1.0) <\n CesiumMath.EPSILON6\n ) {\n compressed1 = AttributeCompression.octEncodeFloat(alignedAxis);\n }\n\n nearValue = CesiumMath.clamp(nearValue, 0.0, 1.0);\n nearValue = nearValue === 1.0 ? 255.0 : (nearValue * 255.0) | 0;\n compressed0 = compressed0 * LEFT_SHIFT8 + nearValue;\n\n farValue = CesiumMath.clamp(farValue, 0.0, 1.0);\n farValue = farValue === 1.0 ? 255.0 : (farValue * 255.0) | 0;\n compressed1 = compressed1 * LEFT_SHIFT8 + farValue;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, compressed0, compressed1, near, far);\n } else {\n i = billboard._index * 4;\n writer(i + 0, compressed0, compressed1, near, far);\n writer(i + 1, compressed0, compressed1, near, far);\n writer(i + 2, compressed0, compressed1, near, far);\n writer(i + 3, compressed0, compressed1, near, far);\n }\n}\n\nfunction writeCompressedAttrib2(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.compressedAttribute2];\n const color = billboard.color;\n const pickColor = !defined(billboardCollection._batchTable)\n ? billboard.getPickId(frameState.context).color\n : Color.WHITE;\n const sizeInMeters = billboard.sizeInMeters ? 1.0 : 0.0;\n const validAlignedAxis =\n Math.abs(Cartesian3.magnitudeSquared(billboard.alignedAxis) - 1.0) <\n CesiumMath.EPSILON6\n ? 1.0\n : 0.0;\n\n billboardCollection._allSizedInMeters =\n billboardCollection._allSizedInMeters && sizeInMeters === 1.0;\n\n let height = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n height = imageRectangle.height;\n }\n\n const dimensions = billboardCollection._textureAtlas.texture.dimensions;\n const imageHeight = Math.round(\n defaultValue(billboard.height, dimensions.y * height)\n );\n billboardCollection._maxSize = Math.max(\n billboardCollection._maxSize,\n imageHeight\n );\n let labelHorizontalOrigin = defaultValue(\n billboard._labelHorizontalOrigin,\n -2\n );\n labelHorizontalOrigin += 2;\n const compressed3 = imageHeight * LEFT_SHIFT2 + labelHorizontalOrigin;\n\n let red = Color.floatToByte(color.red);\n let green = Color.floatToByte(color.green);\n let blue = Color.floatToByte(color.blue);\n const compressed0 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n red = Color.floatToByte(pickColor.red);\n green = Color.floatToByte(pickColor.green);\n blue = Color.floatToByte(pickColor.blue);\n const compressed1 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n let compressed2 =\n Color.floatToByte(color.alpha) * LEFT_SHIFT16 +\n Color.floatToByte(pickColor.alpha) * LEFT_SHIFT8;\n compressed2 += sizeInMeters * 2.0 + validAlignedAxis;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, compressed0, compressed1, compressed2, compressed3);\n } else {\n i = billboard._index * 4;\n writer(i + 0, compressed0, compressed1, compressed2, compressed3);\n writer(i + 1, compressed0, compressed1, compressed2, compressed3);\n writer(i + 2, compressed0, compressed1, compressed2, compressed3);\n writer(i + 3, compressed0, compressed1, compressed2, compressed3);\n }\n}\n\nfunction writeEyeOffset(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.eyeOffset];\n const eyeOffset = billboard.eyeOffset;\n\n // For billboards that are clamped to ground, move it slightly closer to the camera\n let eyeOffsetZ = eyeOffset.z;\n if (billboard._heightReference !== HeightReference.NONE) {\n eyeOffsetZ *= 1.005;\n }\n billboardCollection._maxEyeOffset = Math.max(\n billboardCollection._maxEyeOffset,\n Math.abs(eyeOffset.x),\n Math.abs(eyeOffset.y),\n Math.abs(eyeOffsetZ)\n );\n\n if (billboardCollection._instanced) {\n let width = 0;\n let height = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n width = imageRectangle.width;\n height = imageRectangle.height;\n }\n\n scratchCartesian2.x = width;\n scratchCartesian2.y = height;\n const compressedTexCoordsRange = AttributeCompression.compressTextureCoordinates(\n scratchCartesian2\n );\n\n i = billboard._index;\n writer(i, eyeOffset.x, eyeOffset.y, eyeOffsetZ, compressedTexCoordsRange);\n } else {\n i = billboard._index * 4;\n writer(i + 0, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);\n writer(i + 1, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);\n writer(i + 2, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);\n writer(i + 3, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);\n }\n}\n\nfunction writeScaleByDistance(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.scaleByDistance];\n let near = 0.0;\n let nearValue = 1.0;\n let far = 1.0;\n let farValue = 1.0;\n\n const scale = billboard.scaleByDistance;\n if (defined(scale)) {\n near = scale.near;\n nearValue = scale.nearValue;\n far = scale.far;\n farValue = scale.farValue;\n\n if (nearValue !== 1.0 || farValue !== 1.0) {\n // scale by distance calculation in shader need not be enabled\n // until a billboard with near and far !== 1.0 is found\n billboardCollection._shaderScaleByDistance = true;\n }\n }\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, near, nearValue, far, farValue);\n } else {\n i = billboard._index * 4;\n writer(i + 0, near, nearValue, far, farValue);\n writer(i + 1, near, nearValue, far, farValue);\n writer(i + 2, near, nearValue, far, farValue);\n writer(i + 3, near, nearValue, far, farValue);\n }\n}\n\nfunction writePixelOffsetScaleByDistance(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.pixelOffsetScaleByDistance];\n let near = 0.0;\n let nearValue = 1.0;\n let far = 1.0;\n let farValue = 1.0;\n\n const pixelOffsetScale = billboard.pixelOffsetScaleByDistance;\n if (defined(pixelOffsetScale)) {\n near = pixelOffsetScale.near;\n nearValue = pixelOffsetScale.nearValue;\n far = pixelOffsetScale.far;\n farValue = pixelOffsetScale.farValue;\n\n if (nearValue !== 1.0 || farValue !== 1.0) {\n // pixelOffsetScale by distance calculation in shader need not be enabled\n // until a billboard with near and far !== 1.0 is found\n billboardCollection._shaderPixelOffsetScaleByDistance = true;\n }\n }\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, near, nearValue, far, farValue);\n } else {\n i = billboard._index * 4;\n writer(i + 0, near, nearValue, far, farValue);\n writer(i + 1, near, nearValue, far, farValue);\n writer(i + 2, near, nearValue, far, farValue);\n writer(i + 3, near, nearValue, far, farValue);\n }\n}\n\nfunction writeCompressedAttribute3(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n let i;\n const writer = vafWriters[attributeLocations.compressedAttribute3];\n let near = 0.0;\n let far = Number.MAX_VALUE;\n\n const distanceDisplayCondition = billboard.distanceDisplayCondition;\n if (defined(distanceDisplayCondition)) {\n near = distanceDisplayCondition.near;\n far = distanceDisplayCondition.far;\n\n near *= near;\n far *= far;\n\n billboardCollection._shaderDistanceDisplayCondition = true;\n }\n\n let disableDepthTestDistance = billboard.disableDepthTestDistance;\n const clampToGround =\n billboard.heightReference === HeightReference.CLAMP_TO_GROUND &&\n frameState.context.depthTexture;\n if (!defined(disableDepthTestDistance)) {\n disableDepthTestDistance = clampToGround ? 5000.0 : 0.0;\n }\n\n disableDepthTestDistance *= disableDepthTestDistance;\n if (clampToGround || disableDepthTestDistance > 0.0) {\n billboardCollection._shaderDisableDepthDistance = true;\n if (disableDepthTestDistance === Number.POSITIVE_INFINITY) {\n disableDepthTestDistance = -1.0;\n }\n }\n\n let imageHeight;\n let imageWidth;\n\n if (!defined(billboard._labelDimensions)) {\n let height = 0;\n let width = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n height = imageRectangle.height;\n width = imageRectangle.width;\n }\n\n imageHeight = Math.round(\n defaultValue(\n billboard.height,\n billboardCollection._textureAtlas.texture.dimensions.y * height\n )\n );\n\n const textureWidth = billboardCollection._textureAtlas.texture.width;\n imageWidth = Math.round(\n defaultValue(billboard.width, textureWidth * width)\n );\n } else {\n imageWidth = billboard._labelDimensions.x;\n imageHeight = billboard._labelDimensions.y;\n }\n\n const w = Math.floor(CesiumMath.clamp(imageWidth, 0.0, LEFT_SHIFT12));\n const h = Math.floor(CesiumMath.clamp(imageHeight, 0.0, LEFT_SHIFT12));\n const dimensions = w * LEFT_SHIFT12 + h;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, near, far, disableDepthTestDistance, dimensions);\n } else {\n i = billboard._index * 4;\n writer(i + 0, near, far, disableDepthTestDistance, dimensions);\n writer(i + 1, near, far, disableDepthTestDistance, dimensions);\n writer(i + 2, near, far, disableDepthTestDistance, dimensions);\n writer(i + 3, near, far, disableDepthTestDistance, dimensions);\n }\n}\n\nfunction writeTextureCoordinateBoundsOrLabelTranslate(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n if (billboard.heightReference === HeightReference.CLAMP_TO_GROUND) {\n const scene = billboardCollection._scene;\n const context = frameState.context;\n const globeTranslucent = frameState.globeTranslucencyState.translucent;\n const depthTestAgainstTerrain =\n defined(scene.globe) && scene.globe.depthTestAgainstTerrain;\n\n // Only do manual depth test if the globe is opaque and writes depth\n billboardCollection._shaderClampToGround =\n context.depthTexture && !globeTranslucent && depthTestAgainstTerrain;\n }\n let i;\n const writer =\n vafWriters[attributeLocations.textureCoordinateBoundsOrLabelTranslate];\n\n if (ContextLimits.maximumVertexTextureImageUnits > 0) {\n //write _labelTranslate, used by depth testing in the vertex shader\n let translateX = 0;\n let translateY = 0;\n if (defined(billboard._labelTranslate)) {\n translateX = billboard._labelTranslate.x;\n translateY = billboard._labelTranslate.y;\n }\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, translateX, translateY, 0.0, 0.0);\n } else {\n i = billboard._index * 4;\n writer(i + 0, translateX, translateY, 0.0, 0.0);\n writer(i + 1, translateX, translateY, 0.0, 0.0);\n writer(i + 2, translateX, translateY, 0.0, 0.0);\n writer(i + 3, translateX, translateY, 0.0, 0.0);\n }\n return;\n }\n\n //write texture coordinate bounds, used by depth testing in fragment shader\n let minX = 0;\n let minY = 0;\n let width = 0;\n let height = 0;\n const index = billboard._imageIndex;\n if (index !== -1) {\n const imageRectangle = textureAtlasCoordinates[index];\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(imageRectangle)) {\n throw new DeveloperError(`Invalid billboard image index: ${index}`);\n }\n //>>includeEnd('debug');\n\n minX = imageRectangle.x;\n minY = imageRectangle.y;\n width = imageRectangle.width;\n height = imageRectangle.height;\n }\n const maxX = minX + width;\n const maxY = minY + height;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, minX, minY, maxX, maxY);\n } else {\n i = billboard._index * 4;\n writer(i + 0, minX, minY, maxX, maxY);\n writer(i + 1, minX, minY, maxX, maxY);\n writer(i + 2, minX, minY, maxX, maxY);\n writer(i + 3, minX, minY, maxX, maxY);\n }\n}\n\nfunction writeBatchId(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n if (!defined(billboardCollection._batchTable)) {\n return;\n }\n\n const writer = vafWriters[attributeLocations.a_batchId];\n const id = billboard._batchIndex;\n\n let i;\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, id);\n } else {\n i = billboard._index * 4;\n writer(i + 0, id);\n writer(i + 1, id);\n writer(i + 2, id);\n writer(i + 3, id);\n }\n}\n\nfunction writeSDF(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n if (!billboardCollection._sdf) {\n return;\n }\n\n let i;\n const writer = vafWriters[attributeLocations.sdf];\n\n const outlineColor = billboard.outlineColor;\n const outlineWidth = billboard.outlineWidth;\n\n const red = Color.floatToByte(outlineColor.red);\n const green = Color.floatToByte(outlineColor.green);\n const blue = Color.floatToByte(outlineColor.blue);\n const compressed0 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n // Compute the relative outline distance\n const outlineDistance = outlineWidth / SDFSettings.RADIUS;\n const compressed1 =\n Color.floatToByte(outlineColor.alpha) * LEFT_SHIFT16 +\n Color.floatToByte(outlineDistance) * LEFT_SHIFT8;\n\n if (billboardCollection._instanced) {\n i = billboard._index;\n writer(i, compressed0, compressed1);\n } else {\n i = billboard._index * 4;\n writer(i + 0, compressed0 + LOWER_LEFT, compressed1);\n writer(i + 1, compressed0 + LOWER_RIGHT, compressed1);\n writer(i + 2, compressed0 + UPPER_RIGHT, compressed1);\n writer(i + 3, compressed0 + UPPER_LEFT, compressed1);\n }\n}\n\nfunction writeBillboard(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n) {\n writePositionScaleAndRotation(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeCompressedAttrib0(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeCompressedAttrib1(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeCompressedAttrib2(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeEyeOffset(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeScaleByDistance(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writePixelOffsetScaleByDistance(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeCompressedAttribute3(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeTextureCoordinateBoundsOrLabelTranslate(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeBatchId(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n writeSDF(\n billboardCollection,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n}\n\nfunction recomputeActualPositions(\n billboardCollection,\n billboards,\n length,\n frameState,\n modelMatrix,\n recomputeBoundingVolume\n) {\n let boundingVolume;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingVolume = billboardCollection._baseVolume;\n billboardCollection._boundingVolumeDirty = true;\n } else {\n boundingVolume = billboardCollection._baseVolume2D;\n }\n\n const positions = [];\n for (let i = 0; i < length; ++i) {\n const billboard = billboards[i];\n const position = billboard.position;\n const actualPosition = Billboard._computeActualPosition(\n billboard,\n position,\n frameState,\n modelMatrix\n );\n if (defined(actualPosition)) {\n billboard._setActualPosition(actualPosition);\n\n if (recomputeBoundingVolume) {\n positions.push(actualPosition);\n } else {\n BoundingSphere.expand(boundingVolume, actualPosition, boundingVolume);\n }\n }\n }\n\n if (recomputeBoundingVolume) {\n BoundingSphere.fromPoints(positions, boundingVolume);\n }\n}\n\nfunction updateMode(billboardCollection, frameState) {\n const mode = frameState.mode;\n\n const billboards = billboardCollection._billboards;\n const billboardsToUpdate = billboardCollection._billboardsToUpdate;\n const modelMatrix = billboardCollection._modelMatrix;\n\n if (\n billboardCollection._createVertexArray ||\n billboardCollection._mode !== mode ||\n (mode !== SceneMode.SCENE3D &&\n !Matrix4.equals(modelMatrix, billboardCollection.modelMatrix))\n ) {\n billboardCollection._mode = mode;\n Matrix4.clone(billboardCollection.modelMatrix, modelMatrix);\n billboardCollection._createVertexArray = true;\n\n if (\n mode === SceneMode.SCENE3D ||\n mode === SceneMode.SCENE2D ||\n mode === SceneMode.COLUMBUS_VIEW\n ) {\n recomputeActualPositions(\n billboardCollection,\n billboards,\n billboards.length,\n frameState,\n modelMatrix,\n true\n );\n }\n } else if (mode === SceneMode.MORPHING) {\n recomputeActualPositions(\n billboardCollection,\n billboards,\n billboards.length,\n frameState,\n modelMatrix,\n true\n );\n } else if (mode === SceneMode.SCENE2D || mode === SceneMode.COLUMBUS_VIEW) {\n recomputeActualPositions(\n billboardCollection,\n billboardsToUpdate,\n billboardCollection._billboardsToUpdateIndex,\n frameState,\n modelMatrix,\n false\n );\n }\n}\n\nfunction updateBoundingVolume(collection, frameState, boundingVolume) {\n let pixelScale = 1.0;\n if (!collection._allSizedInMeters || collection._maxPixelOffset !== 0.0) {\n pixelScale = frameState.camera.getPixelSize(\n boundingVolume,\n frameState.context.drawingBufferWidth,\n frameState.context.drawingBufferHeight\n );\n }\n\n let size = pixelScale * collection._maxScale * collection._maxSize * 2.0;\n if (collection._allHorizontalCenter && collection._allVerticalCenter) {\n size *= 0.5;\n }\n\n const offset =\n pixelScale * collection._maxPixelOffset + collection._maxEyeOffset;\n boundingVolume.radius += size + offset;\n}\n\nfunction createDebugCommand(billboardCollection, context) {\n const fs =\n \"uniform sampler2D billboard_texture; \\n\" +\n \"in vec2 v_textureCoordinates; \\n\" +\n \"void main() \\n\" +\n \"{ \\n\" +\n \" out_FragColor = texture(billboard_texture, v_textureCoordinates); \\n\" +\n \"} \\n\";\n\n const drawCommand = context.createViewportQuadCommand(fs, {\n uniformMap: {\n billboard_texture: function () {\n return billboardCollection._textureAtlas.texture;\n },\n },\n });\n drawCommand.pass = Pass.OVERLAY;\n return drawCommand;\n}\n\nconst scratchWriterArray = [];\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {RuntimeError} image with id must be in the atlas.\n */\nBillboardCollection.prototype.update = function (frameState) {\n removeBillboards(this);\n\n if (!this.show) {\n return;\n }\n\n let billboards = this._billboards;\n let billboardsLength = billboards.length;\n\n const context = frameState.context;\n this._instanced = context.instancedArrays;\n attributeLocations = this._instanced\n ? attributeLocationsInstanced\n : attributeLocationsBatched;\n getIndexBuffer = this._instanced\n ? getIndexBufferInstanced\n : getIndexBufferBatched;\n\n let textureAtlas = this._textureAtlas;\n if (!defined(textureAtlas)) {\n textureAtlas = this._textureAtlas = new TextureAtlas({\n context: context,\n });\n\n for (let ii = 0; ii < billboardsLength; ++ii) {\n billboards[ii]._loadImage();\n }\n }\n\n const textureAtlasCoordinates = textureAtlas.textureCoordinates;\n if (textureAtlasCoordinates.length === 0) {\n // Can't write billboard vertices until we have texture coordinates\n // provided by a texture atlas\n return;\n }\n\n updateMode(this, frameState);\n\n billboards = this._billboards;\n billboardsLength = billboards.length;\n const billboardsToUpdate = this._billboardsToUpdate;\n const billboardsToUpdateLength = this._billboardsToUpdateIndex;\n\n const properties = this._propertiesChanged;\n\n const textureAtlasGUID = textureAtlas.guid;\n const createVertexArray =\n this._createVertexArray || this._textureAtlasGUID !== textureAtlasGUID;\n this._textureAtlasGUID = textureAtlasGUID;\n\n let vafWriters;\n const pass = frameState.passes;\n const picking = pass.pick;\n\n // PERFORMANCE_IDEA: Round robin multiple buffers.\n if (createVertexArray || (!picking && this.computeNewBuffersUsage())) {\n this._createVertexArray = false;\n\n for (let k = 0; k < NUMBER_OF_PROPERTIES; ++k) {\n properties[k] = 0;\n }\n\n this._vaf = this._vaf && this._vaf.destroy();\n\n if (billboardsLength > 0) {\n // PERFORMANCE_IDEA: Instead of creating a new one, resize like std::vector.\n this._vaf = createVAF(\n context,\n billboardsLength,\n this._buffersUsage,\n this._instanced,\n this._batchTable,\n this._sdf\n );\n vafWriters = this._vaf.writers;\n\n // Rewrite entire buffer if billboards were added or removed.\n for (let i = 0; i < billboardsLength; ++i) {\n const billboard = this._billboards[i];\n billboard._dirty = false; // In case it needed an update.\n writeBillboard(\n this,\n frameState,\n textureAtlasCoordinates,\n vafWriters,\n billboard\n );\n }\n\n // Different billboard collections share the same index buffer.\n this._vaf.commit(getIndexBuffer(context));\n }\n\n this._billboardsToUpdateIndex = 0;\n } else if (billboardsToUpdateLength > 0) {\n // Billboards were modified, but none were added or removed.\n const writers = scratchWriterArray;\n writers.length = 0;\n\n if (\n properties[POSITION_INDEX] ||\n properties[ROTATION_INDEX] ||\n properties[SCALE_INDEX]\n ) {\n writers.push(writePositionScaleAndRotation);\n }\n\n if (\n properties[IMAGE_INDEX_INDEX] ||\n properties[PIXEL_OFFSET_INDEX] ||\n properties[HORIZONTAL_ORIGIN_INDEX] ||\n properties[VERTICAL_ORIGIN_INDEX] ||\n properties[SHOW_INDEX]\n ) {\n writers.push(writeCompressedAttrib0);\n if (this._instanced) {\n writers.push(writeEyeOffset);\n }\n }\n\n if (\n properties[IMAGE_INDEX_INDEX] ||\n properties[ALIGNED_AXIS_INDEX] ||\n properties[TRANSLUCENCY_BY_DISTANCE_INDEX]\n ) {\n writers.push(writeCompressedAttrib1);\n writers.push(writeCompressedAttrib2);\n }\n\n if (properties[IMAGE_INDEX_INDEX] || properties[COLOR_INDEX]) {\n writers.push(writeCompressedAttrib2);\n }\n\n if (properties[EYE_OFFSET_INDEX]) {\n writers.push(writeEyeOffset);\n }\n\n if (properties[SCALE_BY_DISTANCE_INDEX]) {\n writers.push(writeScaleByDistance);\n }\n\n if (properties[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX]) {\n writers.push(writePixelOffsetScaleByDistance);\n }\n\n if (\n properties[DISTANCE_DISPLAY_CONDITION_INDEX] ||\n properties[DISABLE_DEPTH_DISTANCE] ||\n properties[IMAGE_INDEX_INDEX] ||\n properties[POSITION_INDEX]\n ) {\n writers.push(writeCompressedAttribute3);\n }\n\n if (properties[IMAGE_INDEX_INDEX] || properties[POSITION_INDEX]) {\n writers.push(writeTextureCoordinateBoundsOrLabelTranslate);\n }\n\n if (properties[SDF_INDEX]) {\n writers.push(writeSDF);\n }\n\n const numWriters = writers.length;\n vafWriters = this._vaf.writers;\n\n if (billboardsToUpdateLength / billboardsLength > 0.1) {\n // If more than 10% of billboard change, rewrite the entire buffer.\n\n // PERFORMANCE_IDEA: I totally made up 10% :).\n\n for (let m = 0; m < billboardsToUpdateLength; ++m) {\n const b = billboardsToUpdate[m];\n b._dirty = false;\n\n for (let n = 0; n < numWriters; ++n) {\n writers[n](this, frameState, textureAtlasCoordinates, vafWriters, b);\n }\n }\n this._vaf.commit(getIndexBuffer(context));\n } else {\n for (let h = 0; h < billboardsToUpdateLength; ++h) {\n const bb = billboardsToUpdate[h];\n bb._dirty = false;\n\n for (let o = 0; o < numWriters; ++o) {\n writers[o](this, frameState, textureAtlasCoordinates, vafWriters, bb);\n }\n\n if (this._instanced) {\n this._vaf.subCommit(bb._index, 1);\n } else {\n this._vaf.subCommit(bb._index * 4, 4);\n }\n }\n this._vaf.endSubCommits();\n }\n\n this._billboardsToUpdateIndex = 0;\n }\n\n // If the number of total billboards ever shrinks considerably\n // Truncate billboardsToUpdate so that we free memory that we're\n // not going to be using.\n if (billboardsToUpdateLength > billboardsLength * 1.5) {\n billboardsToUpdate.length = billboardsLength;\n }\n\n if (!defined(this._vaf) || !defined(this._vaf.va)) {\n return;\n }\n\n if (this._boundingVolumeDirty) {\n this._boundingVolumeDirty = false;\n BoundingSphere.transform(\n this._baseVolume,\n this.modelMatrix,\n this._baseVolumeWC\n );\n }\n\n let boundingVolume;\n let modelMatrix = Matrix4.IDENTITY;\n if (frameState.mode === SceneMode.SCENE3D) {\n modelMatrix = this.modelMatrix;\n boundingVolume = BoundingSphere.clone(\n this._baseVolumeWC,\n this._boundingVolume\n );\n } else {\n boundingVolume = BoundingSphere.clone(\n this._baseVolume2D,\n this._boundingVolume\n );\n }\n updateBoundingVolume(this, frameState, boundingVolume);\n\n const blendOptionChanged = this._blendOption !== this.blendOption;\n this._blendOption = this.blendOption;\n\n if (blendOptionChanged) {\n if (\n this._blendOption === BlendOption.OPAQUE ||\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT\n ) {\n this._rsOpaque = RenderState.fromCache({\n depthTest: {\n enabled: true,\n func: WebGLConstants.LESS,\n },\n depthMask: true,\n });\n } else {\n this._rsOpaque = undefined;\n }\n\n // If OPAQUE_AND_TRANSLUCENT is in use, only the opaque pass gets the benefit of the depth buffer,\n // not the translucent pass. Otherwise, if the TRANSLUCENT pass is on its own, it turns on\n // a depthMask in lieu of full depth sorting (because it has opaque-ish fragments that look bad in OIT).\n // When the TRANSLUCENT depth mask is in use, label backgrounds require the depth func to be LEQUAL.\n const useTranslucentDepthMask =\n this._blendOption === BlendOption.TRANSLUCENT;\n\n if (\n this._blendOption === BlendOption.TRANSLUCENT ||\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT\n ) {\n this._rsTranslucent = RenderState.fromCache({\n depthTest: {\n enabled: true,\n func: useTranslucentDepthMask\n ? WebGLConstants.LEQUAL\n : WebGLConstants.LESS,\n },\n depthMask: useTranslucentDepthMask,\n blending: BlendingState.ALPHA_BLEND,\n });\n } else {\n this._rsTranslucent = undefined;\n }\n }\n\n this._shaderDisableDepthDistance =\n this._shaderDisableDepthDistance ||\n frameState.minimumDisableDepthTestDistance !== 0.0;\n\n let vsSource;\n let fsSource;\n let vs;\n let fs;\n let vertDefines;\n\n const supportVSTextureReads =\n ContextLimits.maximumVertexTextureImageUnits > 0;\n\n if (\n blendOptionChanged ||\n this._shaderRotation !== this._compiledShaderRotation ||\n this._shaderAlignedAxis !== this._compiledShaderAlignedAxis ||\n this._shaderScaleByDistance !== this._compiledShaderScaleByDistance ||\n this._shaderTranslucencyByDistance !==\n this._compiledShaderTranslucencyByDistance ||\n this._shaderPixelOffsetScaleByDistance !==\n this._compiledShaderPixelOffsetScaleByDistance ||\n this._shaderDistanceDisplayCondition !==\n this._compiledShaderDistanceDisplayCondition ||\n this._shaderDisableDepthDistance !==\n this._compiledShaderDisableDepthDistance ||\n this._shaderClampToGround !== this._compiledShaderClampToGround ||\n this._sdf !== this._compiledSDF\n ) {\n vsSource = BillboardCollectionVS;\n fsSource = BillboardCollectionFS;\n\n vertDefines = [];\n if (defined(this._batchTable)) {\n vertDefines.push(\"VECTOR_TILE\");\n vsSource = this._batchTable.getVertexShaderCallback(\n false,\n \"a_batchId\",\n undefined\n )(vsSource);\n fsSource = this._batchTable.getFragmentShaderCallback(\n false,\n undefined\n )(fsSource);\n }\n\n vs = new ShaderSource({\n defines: vertDefines,\n sources: [vsSource],\n });\n if (this._instanced) {\n vs.defines.push(\"INSTANCED\");\n }\n if (this._shaderRotation) {\n vs.defines.push(\"ROTATION\");\n }\n if (this._shaderAlignedAxis) {\n vs.defines.push(\"ALIGNED_AXIS\");\n }\n if (this._shaderScaleByDistance) {\n vs.defines.push(\"EYE_DISTANCE_SCALING\");\n }\n if (this._shaderTranslucencyByDistance) {\n vs.defines.push(\"EYE_DISTANCE_TRANSLUCENCY\");\n }\n if (this._shaderPixelOffsetScaleByDistance) {\n vs.defines.push(\"EYE_DISTANCE_PIXEL_OFFSET\");\n }\n if (this._shaderDistanceDisplayCondition) {\n vs.defines.push(\"DISTANCE_DISPLAY_CONDITION\");\n }\n if (this._shaderDisableDepthDistance) {\n vs.defines.push(\"DISABLE_DEPTH_DISTANCE\");\n }\n if (this._shaderClampToGround) {\n if (supportVSTextureReads) {\n vs.defines.push(\"VERTEX_DEPTH_CHECK\");\n } else {\n vs.defines.push(\"FRAGMENT_DEPTH_CHECK\");\n }\n }\n\n const sdfEdge = 1.0 - SDFSettings.CUTOFF;\n\n if (this._sdf) {\n vs.defines.push(\"SDF\");\n }\n\n const vectorFragDefine = defined(this._batchTable) ? \"VECTOR_TILE\" : \"\";\n\n if (this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {\n fs = new ShaderSource({\n defines: [\"OPAQUE\", vectorFragDefine],\n sources: [fsSource],\n });\n if (this._shaderClampToGround) {\n if (supportVSTextureReads) {\n fs.defines.push(\"VERTEX_DEPTH_CHECK\");\n } else {\n fs.defines.push(\"FRAGMENT_DEPTH_CHECK\");\n }\n }\n\n if (this._sdf) {\n fs.defines.push(\"SDF\");\n fs.defines.push(`SDF_EDGE ${sdfEdge}`);\n }\n\n this._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._sp,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n\n fs = new ShaderSource({\n defines: [\"TRANSLUCENT\", vectorFragDefine],\n sources: [fsSource],\n });\n if (this._shaderClampToGround) {\n if (supportVSTextureReads) {\n fs.defines.push(\"VERTEX_DEPTH_CHECK\");\n } else {\n fs.defines.push(\"FRAGMENT_DEPTH_CHECK\");\n }\n }\n if (this._sdf) {\n fs.defines.push(\"SDF\");\n fs.defines.push(`SDF_EDGE ${sdfEdge}`);\n }\n this._spTranslucent = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._spTranslucent,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n if (this._blendOption === BlendOption.OPAQUE) {\n fs = new ShaderSource({\n defines: [vectorFragDefine],\n sources: [fsSource],\n });\n if (this._shaderClampToGround) {\n if (supportVSTextureReads) {\n fs.defines.push(\"VERTEX_DEPTH_CHECK\");\n } else {\n fs.defines.push(\"FRAGMENT_DEPTH_CHECK\");\n }\n }\n if (this._sdf) {\n fs.defines.push(\"SDF\");\n fs.defines.push(`SDF_EDGE ${sdfEdge}`);\n }\n this._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._sp,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n if (this._blendOption === BlendOption.TRANSLUCENT) {\n fs = new ShaderSource({\n defines: [vectorFragDefine],\n sources: [fsSource],\n });\n if (this._shaderClampToGround) {\n if (supportVSTextureReads) {\n fs.defines.push(\"VERTEX_DEPTH_CHECK\");\n } else {\n fs.defines.push(\"FRAGMENT_DEPTH_CHECK\");\n }\n }\n if (this._sdf) {\n fs.defines.push(\"SDF\");\n fs.defines.push(`SDF_EDGE ${sdfEdge}`);\n }\n this._spTranslucent = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._spTranslucent,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n this._compiledShaderRotation = this._shaderRotation;\n this._compiledShaderAlignedAxis = this._shaderAlignedAxis;\n this._compiledShaderScaleByDistance = this._shaderScaleByDistance;\n this._compiledShaderTranslucencyByDistance = this._shaderTranslucencyByDistance;\n this._compiledShaderPixelOffsetScaleByDistance = this._shaderPixelOffsetScaleByDistance;\n this._compiledShaderDistanceDisplayCondition = this._shaderDistanceDisplayCondition;\n this._compiledShaderDisableDepthDistance = this._shaderDisableDepthDistance;\n this._compiledShaderClampToGround = this._shaderClampToGround;\n this._compiledSDF = this._sdf;\n }\n\n const commandList = frameState.commandList;\n\n if (pass.render || pass.pick) {\n const colorList = this._colorCommands;\n\n const opaque = this._blendOption === BlendOption.OPAQUE;\n const opaqueAndTranslucent =\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT;\n\n const va = this._vaf.va;\n const vaLength = va.length;\n\n let uniforms = this._uniforms;\n let pickId;\n if (defined(this._batchTable)) {\n uniforms = this._batchTable.getUniformMapCallback()(uniforms);\n pickId = this._batchTable.getPickId();\n } else {\n pickId = \"v_pickColor\";\n }\n\n colorList.length = vaLength;\n const totalLength = opaqueAndTranslucent ? vaLength * 2 : vaLength;\n for (let j = 0; j < totalLength; ++j) {\n let command = colorList[j];\n if (!defined(command)) {\n command = colorList[j] = new DrawCommand();\n }\n\n const opaqueCommand = opaque || (opaqueAndTranslucent && j % 2 === 0);\n\n command.pass =\n opaqueCommand || !opaqueAndTranslucent ? Pass.OPAQUE : Pass.TRANSLUCENT;\n command.owner = this;\n\n const index = opaqueAndTranslucent ? Math.floor(j / 2.0) : j;\n command.boundingVolume = boundingVolume;\n command.modelMatrix = modelMatrix;\n command.count = va[index].indicesCount;\n command.shaderProgram = opaqueCommand ? this._sp : this._spTranslucent;\n command.uniformMap = uniforms;\n command.vertexArray = va[index].va;\n command.renderState = opaqueCommand\n ? this._rsOpaque\n : this._rsTranslucent;\n command.debugShowBoundingVolume = this.debugShowBoundingVolume;\n command.pickId = pickId;\n\n if (this._instanced) {\n command.count = 6;\n command.instanceCount = billboardsLength;\n }\n\n commandList.push(command);\n }\n\n if (this.debugShowTextureAtlas) {\n if (!defined(this.debugCommand)) {\n this.debugCommand = createDebugCommand(this, frameState.context);\n }\n\n commandList.push(this.debugCommand);\n }\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see BillboardCollection#destroy\n */\nBillboardCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * billboards = billboards && billboards.destroy();\n *\n * @see BillboardCollection#isDestroyed\n */\nBillboardCollection.prototype.destroy = function () {\n if (defined(this._removeCallbackFunc)) {\n this._removeCallbackFunc();\n this._removeCallbackFunc = undefined;\n }\n\n this._textureAtlas =\n this._destroyTextureAtlas &&\n this._textureAtlas &&\n this._textureAtlas.destroy();\n this._sp = this._sp && this._sp.destroy();\n this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy();\n this._vaf = this._vaf && this._vaf.destroy();\n destroyBillboards(this._billboards);\n\n return destroyObject(this);\n};\nexport default BillboardCollection;\n", "/**\n * Creates a {@link createBillboardPointCallback.CanvasFunction} that will create a canvas with a point.\n *\n * @param {number} centerAlpha The alpha of the center of the point. The value must be in the range [0.0, 1.0].\n * @param {string} cssColor The CSS color string.\n * @param {string} cssOutlineColor The CSS color of the point outline.\n * @param {number} cssOutlineWidth The width of the outline in pixels.\n * @param {number} pixelSize The size of the point in pixels.\n * @return {createBillboardPointCallback.CanvasFunction} The function that will return a canvas with the point drawn on it.\n *\n * @private\n */\nfunction createBillboardPointCallback(\n centerAlpha,\n cssColor,\n cssOutlineColor,\n cssOutlineWidth,\n pixelSize\n) {\n return function () {\n const canvas = document.createElement(\"canvas\");\n\n const length = pixelSize + 2 * cssOutlineWidth;\n canvas.height = canvas.width = length;\n\n const context2D = canvas.getContext(\"2d\");\n context2D.clearRect(0, 0, length, length);\n\n if (cssOutlineWidth !== 0) {\n context2D.beginPath();\n context2D.arc(length / 2, length / 2, length / 2, 0, 2 * Math.PI, true);\n context2D.closePath();\n context2D.fillStyle = cssOutlineColor;\n context2D.fill();\n // Punch a hole in the center if needed.\n if (centerAlpha < 1.0) {\n context2D.save();\n context2D.globalCompositeOperation = \"destination-out\";\n context2D.beginPath();\n context2D.arc(\n length / 2,\n length / 2,\n pixelSize / 2,\n 0,\n 2 * Math.PI,\n true\n );\n context2D.closePath();\n context2D.fillStyle = \"black\";\n context2D.fill();\n context2D.restore();\n }\n }\n\n context2D.beginPath();\n context2D.arc(length / 2, length / 2, pixelSize / 2, 0, 2 * Math.PI, true);\n context2D.closePath();\n context2D.fillStyle = cssColor;\n context2D.fill();\n\n return canvas;\n };\n}\n\n/**\n * A function that returns a canvas containing an image of a point.\n * @callback createBillboardPointCallback.CanvasFunction\n * @returns {HTMLCanvasElement} The result of the calculation.\n */\nexport default createBillboardPointCallback;\n", "import Cartographic from \"../Core/Cartographic.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Cesium3DTileFeature from \"./Cesium3DTileFeature.js\";\nimport createBillboardPointCallback from \"./createBillboardPointCallback.js\";\n\n/**\n * A point feature of a {@link Cesium3DTileset}.\n *

\n * Provides access to a feature's properties stored in the tile's batch table, as well\n * as the ability to show/hide a feature and change its point properties\n *

\n *

\n * Modifications to a Cesium3DTilePointFeature object have the lifetime of the tile's\n * content. If the tile's content is unloaded, e.g., due to it going out of view and needing\n * to free space in the cache for visible tiles, listen to the {@link Cesium3DTileset#tileUnload} event to save any\n * modifications. Also listen to the {@link Cesium3DTileset#tileVisible} event to reapply any modifications.\n *

\n *

\n * Do not construct this directly. Access it through {@link Cesium3DTileContent#getFeature}\n * or picking using {@link Scene#pick} and {@link Scene#pickPosition}.\n *

\n *\n * @alias Cesium3DTilePointFeature\n * @constructor\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n *\n * @example\n * // On mouse over, display all the properties for a feature in the console log.\n * handler.setInputAction(function(movement) {\n * const feature = scene.pick(movement.endPosition);\n * if (feature instanceof Cesium.Cesium3DTilePointFeature) {\n * const propertyIds = feature.getPropertyIds();\n * const length = propertyIds.length;\n * for (let i = 0; i < length; ++i) {\n * const propertyId = propertyIds[i];\n * console.log(`{propertyId}: ${feature.getProperty(propertyId)}`);\n * }\n * }\n * }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);\n */\nfunction Cesium3DTilePointFeature(\n content,\n batchId,\n billboard,\n label,\n polyline\n) {\n this._content = content;\n this._billboard = billboard;\n this._label = label;\n this._polyline = polyline;\n\n this._batchId = batchId;\n this._billboardImage = undefined;\n this._billboardColor = undefined;\n this._billboardOutlineColor = undefined;\n this._billboardOutlineWidth = undefined;\n this._billboardSize = undefined;\n this._pointSize = undefined;\n this._color = undefined;\n this._pointSize = undefined;\n this._pointOutlineColor = undefined;\n this._pointOutlineWidth = undefined;\n this._heightOffset = undefined;\n\n this._pickIds = new Array(3);\n\n setBillboardImage(this);\n}\n\nconst scratchCartographic = new Cartographic();\n\nObject.defineProperties(Cesium3DTilePointFeature.prototype, {\n /**\n * Gets or sets if the feature will be shown. This is set for all features\n * when a style's show is evaluated.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {boolean}\n *\n * @default true\n */\n show: {\n get: function () {\n return this._label.show;\n },\n set: function (value) {\n this._label.show = value;\n this._billboard.show = value;\n this._polyline.show = value;\n },\n },\n\n /**\n * Gets or sets the color of the point of this feature.\n *

\n * Only applied when image is undefined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n color: {\n get: function () {\n return this._color;\n },\n set: function (value) {\n this._color = Color.clone(value, this._color);\n setBillboardImage(this);\n },\n },\n\n /**\n * Gets or sets the point size of this feature.\n *

\n * Only applied when image is undefined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {number}\n */\n pointSize: {\n get: function () {\n return this._pointSize;\n },\n set: function (value) {\n this._pointSize = value;\n setBillboardImage(this);\n },\n },\n\n /**\n * Gets or sets the point outline color of this feature.\n *

\n * Only applied when image is undefined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n pointOutlineColor: {\n get: function () {\n return this._pointOutlineColor;\n },\n set: function (value) {\n this._pointOutlineColor = Color.clone(value, this._pointOutlineColor);\n setBillboardImage(this);\n },\n },\n\n /**\n * Gets or sets the point outline width in pixels of this feature.\n *

\n * Only applied when image is undefined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {number}\n */\n pointOutlineWidth: {\n get: function () {\n return this._pointOutlineWidth;\n },\n set: function (value) {\n this._pointOutlineWidth = value;\n setBillboardImage(this);\n },\n },\n\n /**\n * Gets or sets the label color of this feature.\n *

\n * The color will be applied to the label if labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n labelColor: {\n get: function () {\n return this._label.fillColor;\n },\n set: function (value) {\n this._label.fillColor = value;\n this._polyline.show = this._label.show && value.alpha > 0.0;\n },\n },\n\n /**\n * Gets or sets the label outline color of this feature.\n *

\n * The outline color will be applied to the label if labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n labelOutlineColor: {\n get: function () {\n return this._label.outlineColor;\n },\n set: function (value) {\n this._label.outlineColor = value;\n },\n },\n\n /**\n * Gets or sets the outline width in pixels of this feature.\n *

\n * The outline width will be applied to the point if labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {number}\n */\n labelOutlineWidth: {\n get: function () {\n return this._label.outlineWidth;\n },\n set: function (value) {\n this._label.outlineWidth = value;\n },\n },\n\n /**\n * Gets or sets the font of this feature.\n *

\n * Only applied when the labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {string}\n */\n font: {\n get: function () {\n return this._label.font;\n },\n set: function (value) {\n this._label.font = value;\n },\n },\n\n /**\n * Gets or sets the fill and outline style of this feature.\n *

\n * Only applied when labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {LabelStyle}\n */\n labelStyle: {\n get: function () {\n return this._label.style;\n },\n set: function (value) {\n this._label.style = value;\n },\n },\n\n /**\n * Gets or sets the text for this feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {string}\n */\n labelText: {\n get: function () {\n return this._label.text;\n },\n set: function (value) {\n if (!defined(value)) {\n value = \"\";\n }\n this._label.text = value;\n },\n },\n\n /**\n * Gets or sets the background color of the text for this feature.\n *

\n * Only applied when labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n backgroundColor: {\n get: function () {\n return this._label.backgroundColor;\n },\n set: function (value) {\n this._label.backgroundColor = value;\n },\n },\n\n /**\n * Gets or sets the background padding of the text for this feature.\n *

\n * Only applied when labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Cartesian2}\n */\n backgroundPadding: {\n get: function () {\n return this._label.backgroundPadding;\n },\n set: function (value) {\n this._label.backgroundPadding = value;\n },\n },\n\n /**\n * Gets or sets whether to display the background of the text for this feature.\n *

\n * Only applied when labelText is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {boolean}\n */\n backgroundEnabled: {\n get: function () {\n return this._label.showBackground;\n },\n set: function (value) {\n this._label.showBackground = value;\n },\n },\n\n /**\n * Gets or sets the near and far scaling properties for this feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {NearFarScalar}\n */\n scaleByDistance: {\n get: function () {\n return this._label.scaleByDistance;\n },\n set: function (value) {\n this._label.scaleByDistance = value;\n this._billboard.scaleByDistance = value;\n },\n },\n\n /**\n * Gets or sets the near and far translucency properties for this feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {NearFarScalar}\n */\n translucencyByDistance: {\n get: function () {\n return this._label.translucencyByDistance;\n },\n set: function (value) {\n this._label.translucencyByDistance = value;\n this._billboard.translucencyByDistance = value;\n },\n },\n\n /**\n * Gets or sets the condition specifying at what distance from the camera that this feature will be displayed.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {DistanceDisplayCondition}\n */\n distanceDisplayCondition: {\n get: function () {\n return this._label.distanceDisplayCondition;\n },\n set: function (value) {\n this._label.distanceDisplayCondition = value;\n this._polyline.distanceDisplayCondition = value;\n this._billboard.distanceDisplayCondition = value;\n },\n },\n\n /**\n * Gets or sets the height offset in meters of this feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {number}\n */\n heightOffset: {\n get: function () {\n return this._heightOffset;\n },\n set: function (value) {\n const offset = defaultValue(this._heightOffset, 0.0);\n\n const ellipsoid = this._content.tileset.ellipsoid;\n const cart = ellipsoid.cartesianToCartographic(\n this._billboard.position,\n scratchCartographic\n );\n cart.height = cart.height - offset + value;\n const newPosition = ellipsoid.cartographicToCartesian(cart);\n\n this._billboard.position = newPosition;\n this._label.position = this._billboard.position;\n this._polyline.positions = [this._polyline.positions[0], newPosition];\n\n this._heightOffset = value;\n },\n },\n\n /**\n * Gets or sets whether the anchor line is displayed.\n *

\n * Only applied when heightOffset is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {boolean}\n */\n anchorLineEnabled: {\n get: function () {\n return this._polyline.show;\n },\n set: function (value) {\n this._polyline.show = value;\n },\n },\n\n /**\n * Gets or sets the color for the anchor line.\n *

\n * Only applied when heightOffset is defined.\n *

\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Color}\n */\n anchorLineColor: {\n get: function () {\n return this._polyline.material.uniforms.color;\n },\n set: function (value) {\n this._polyline.material.uniforms.color = Color.clone(\n value,\n this._polyline.material.uniforms.color\n );\n },\n },\n\n /**\n * Gets or sets the image of this feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {string}\n */\n image: {\n get: function () {\n return this._billboardImage;\n },\n set: function (value) {\n const imageChanged = this._billboardImage !== value;\n this._billboardImage = value;\n if (imageChanged) {\n setBillboardImage(this);\n }\n },\n },\n\n /**\n * Gets or sets the distance where depth testing will be disabled.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {number}\n */\n disableDepthTestDistance: {\n get: function () {\n return this._label.disableDepthTestDistance;\n },\n set: function (value) {\n this._label.disableDepthTestDistance = value;\n this._billboard.disableDepthTestDistance = value;\n },\n },\n\n /**\n * Gets or sets the horizontal origin of this point, which determines if the point is\n * to the left, center, or right of its anchor position.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {HorizontalOrigin}\n */\n horizontalOrigin: {\n get: function () {\n return this._billboard.horizontalOrigin;\n },\n set: function (value) {\n this._billboard.horizontalOrigin = value;\n },\n },\n\n /**\n * Gets or sets the vertical origin of this point, which determines if the point is\n * to the bottom, center, or top of its anchor position.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {VerticalOrigin}\n */\n verticalOrigin: {\n get: function () {\n return this._billboard.verticalOrigin;\n },\n set: function (value) {\n this._billboard.verticalOrigin = value;\n },\n },\n\n /**\n * Gets or sets the horizontal origin of this point's text, which determines if the point's text is\n * to the left, center, or right of its anchor position.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {HorizontalOrigin}\n */\n labelHorizontalOrigin: {\n get: function () {\n return this._label.horizontalOrigin;\n },\n set: function (value) {\n this._label.horizontalOrigin = value;\n },\n },\n\n /**\n * Get or sets the vertical origin of this point's text, which determines if the point's text is\n * to the bottom, center, top, or baseline of it's anchor point.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {VerticalOrigin}\n */\n labelVerticalOrigin: {\n get: function () {\n return this._label.verticalOrigin;\n },\n set: function (value) {\n this._label.verticalOrigin = value;\n },\n },\n\n /**\n * Gets the content of the tile containing the feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Cesium3DTileContent}\n *\n * @readonly\n * @private\n */\n content: {\n get: function () {\n return this._content;\n },\n },\n\n /**\n * Gets the tileset containing the feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Cesium3DTileset}\n *\n * @readonly\n */\n tileset: {\n get: function () {\n return this._content.tileset;\n },\n },\n\n /**\n * All objects returned by {@link Scene#pick} have a primitive property. This returns\n * the tileset containing the feature.\n *\n * @memberof Cesium3DTilePointFeature.prototype\n *\n * @type {Cesium3DTileset}\n *\n * @readonly\n */\n primitive: {\n get: function () {\n return this._content.tileset;\n },\n },\n\n /**\n * @private\n */\n pickIds: {\n get: function () {\n const ids = this._pickIds;\n ids[0] = this._billboard.pickId;\n ids[1] = this._label.pickId;\n ids[2] = this._polyline.pickId;\n return ids;\n },\n },\n});\n\nCesium3DTilePointFeature.defaultColor = Color.WHITE;\nCesium3DTilePointFeature.defaultPointOutlineColor = Color.BLACK;\nCesium3DTilePointFeature.defaultPointOutlineWidth = 0.0;\nCesium3DTilePointFeature.defaultPointSize = 8.0;\n\nfunction setBillboardImage(feature) {\n const b = feature._billboard;\n if (defined(feature._billboardImage) && feature._billboardImage !== b.image) {\n b.image = feature._billboardImage;\n return;\n }\n\n if (defined(feature._billboardImage)) {\n return;\n }\n\n const newColor = defaultValue(\n feature._color,\n Cesium3DTilePointFeature.defaultColor\n );\n const newOutlineColor = defaultValue(\n feature._pointOutlineColor,\n Cesium3DTilePointFeature.defaultPointOutlineColor\n );\n const newOutlineWidth = defaultValue(\n feature._pointOutlineWidth,\n Cesium3DTilePointFeature.defaultPointOutlineWidth\n );\n const newPointSize = defaultValue(\n feature._pointSize,\n Cesium3DTilePointFeature.defaultPointSize\n );\n\n const currentColor = feature._billboardColor;\n const currentOutlineColor = feature._billboardOutlineColor;\n const currentOutlineWidth = feature._billboardOutlineWidth;\n const currentPointSize = feature._billboardSize;\n\n if (\n Color.equals(newColor, currentColor) &&\n Color.equals(newOutlineColor, currentOutlineColor) &&\n newOutlineWidth === currentOutlineWidth &&\n newPointSize === currentPointSize\n ) {\n return;\n }\n\n feature._billboardColor = Color.clone(newColor, feature._billboardColor);\n feature._billboardOutlineColor = Color.clone(\n newOutlineColor,\n feature._billboardOutlineColor\n );\n feature._billboardOutlineWidth = newOutlineWidth;\n feature._billboardSize = newPointSize;\n\n const centerAlpha = newColor.alpha;\n const cssColor = newColor.toCssColorString();\n const cssOutlineColor = newOutlineColor.toCssColorString();\n const textureId = JSON.stringify([\n cssColor,\n newPointSize,\n cssOutlineColor,\n newOutlineWidth,\n ]);\n\n b.setImage(\n textureId,\n createBillboardPointCallback(\n centerAlpha,\n cssColor,\n cssOutlineColor,\n newOutlineWidth,\n newPointSize\n )\n );\n}\n\n/**\n * Returns whether the feature contains this property. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {boolean} Whether the feature contains this property.\n */\nCesium3DTilePointFeature.prototype.hasProperty = function (name) {\n return this._content.batchTable.hasProperty(this._batchId, name);\n};\n\n/**\n * Returns an array of property IDs for the feature. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The IDs of the feature's properties.\n */\nCesium3DTilePointFeature.prototype.getPropertyIds = function (results) {\n return this._content.batchTable.getPropertyIds(this._batchId, results);\n};\n\n/**\n * Returns a copy of the value of the feature's property with the given name. This includes properties from this feature's\n * class and inherited classes when using a batch table hierarchy.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_batch_table_hierarchy}\n *\n * @param {string} name The case-sensitive name of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n *\n * @example\n * // Display all the properties for a feature in the console log.\n * const propertyIds = feature.getPropertyIds();\n * const length = propertyIds.length;\n * for (let i = 0; i < length; ++i) {\n * const propertyId = propertyIds[i];\n * console.log(`{propertyId} : ${feature.getProperty(propertyId)}`);\n * }\n */\nCesium3DTilePointFeature.prototype.getProperty = function (name) {\n return this._content.batchTable.getProperty(this._batchId, name);\n};\n\n/**\n * Returns a copy of the value of the feature's property with the given name.\n * If the feature is contained within a tileset that has metadata (3D Tiles 1.1)\n * or uses the 3DTILES_metadata extension, tileset, group and tile metadata is\n * inherited.\n *

\n * To resolve name conflicts, this method resolves names from most specific to\n * least specific by metadata granularity in the order: feature, tile, group,\n * tileset. Within each granularity, semantics are resolved first, then other\n * properties.\n *

\n * @param {string} name The case-sensitive name of the property.\n * @returns {*} The value of the property or undefined if the feature does not have this property.\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nCesium3DTilePointFeature.prototype.getPropertyInherited = function (name) {\n return Cesium3DTileFeature.getPropertyInherited(\n this._content,\n this._batchId,\n name\n );\n};\n\n/**\n * Sets the value of the feature's property with the given name.\n *

\n * If a property with the given name doesn't exist, it is created.\n *

\n *\n * @param {string} name The case-sensitive name of the property.\n * @param {*} value The value of the property that will be copied.\n *\n * @exception {DeveloperError} Inherited batch table hierarchy property is read only.\n *\n * @example\n * const height = feature.getProperty('Height'); // e.g., the height of a building\n *\n * @example\n * const name = 'clicked';\n * if (feature.getProperty(name)) {\n * console.log('already clicked');\n * } else {\n * feature.setProperty(name, true);\n * console.log('first click');\n * }\n */\nCesium3DTilePointFeature.prototype.setProperty = function (name, value) {\n this._content.batchTable.setProperty(this._batchId, name, value);\n\n // PERFORMANCE_IDEA: Probably overkill, but maybe only mark the tile dirty if the\n // property is in one of the style's expressions or - if it can be done quickly -\n // if the new property value changed the result of an expression.\n this._content.featurePropertiesDirty = true;\n};\n\n/**\n * Returns whether the feature's class name equals className. Unlike {@link Cesium3DTilePointFeature#isClass}\n * this function only checks the feature's exact class and not inherited classes.\n *

\n * This function returns false if no batch table hierarchy is present.\n *

\n *\n * @param {string} className The name to check against.\n * @returns {boolean} Whether the feature's class name equals className\n *\n * @private\n */\nCesium3DTilePointFeature.prototype.isExactClass = function (className) {\n return this._content.batchTable.isExactClass(this._batchId, className);\n};\n\n/**\n * Returns whether the feature's class or any inherited classes are named className.\n *

\n * This function returns false if no batch table hierarchy is present.\n *

\n *\n * @param {string} className The name to check against.\n * @returns {boolean} Whether the feature's class or inherited classes are named className\n *\n * @private\n */\nCesium3DTilePointFeature.prototype.isClass = function (className) {\n return this._content.batchTable.isClass(this._batchId, className);\n};\n\n/**\n * Returns the feature's class name.\n *

\n * This function returns undefined if no batch table hierarchy is present.\n *

\n *\n * @returns {string} The feature's class name.\n *\n * @private\n */\nCesium3DTilePointFeature.prototype.getExactClassName = function () {\n return this._content.batchTable.getExactClassName(this._batchId);\n};\nexport default Cesium3DTilePointFeature;\n", "import Color from \"./Color.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\nfunction measureText(context2D, textString, font, stroke, fill) {\n const metrics = context2D.measureText(textString);\n const isSpace = !/\\S/.test(textString);\n\n if (!isSpace) {\n const fontSize = document.defaultView\n .getComputedStyle(context2D.canvas)\n .getPropertyValue(\"font-size\")\n .replace(\"px\", \"\");\n const canvas = document.createElement(\"canvas\");\n const padding = 100;\n const width = (metrics.width + padding) | 0;\n const height = 3 * fontSize;\n const baseline = height / 2;\n canvas.width = width;\n canvas.height = height;\n\n const ctx = canvas.getContext(\"2d\");\n ctx.font = font;\n ctx.fillStyle = \"white\";\n ctx.fillRect(0, 0, canvas.width + 1, canvas.height + 1);\n\n if (stroke) {\n ctx.strokeStyle = \"black\";\n ctx.lineWidth = context2D.lineWidth;\n ctx.strokeText(textString, padding / 2, baseline);\n }\n\n if (fill) {\n ctx.fillStyle = \"black\";\n ctx.fillText(textString, padding / 2, baseline);\n }\n\n // Context image data has width * height * 4 elements, because\n // each pixel's R, G, B and A are consecutive values in the array.\n const pixelData = ctx.getImageData(0, 0, width, height).data;\n const length = pixelData.length;\n const width4 = width * 4;\n let i, j;\n\n let ascent, descent;\n // Find the number of rows (from the top) until the first non-white pixel\n for (i = 0; i < length; ++i) {\n if (pixelData[i] !== 255) {\n ascent = (i / width4) | 0;\n break;\n }\n }\n\n // Find the number of rows (from the bottom) until the first non-white pixel\n for (i = length - 1; i >= 0; --i) {\n if (pixelData[i] !== 255) {\n descent = (i / width4) | 0;\n break;\n }\n }\n\n let minx = -1;\n // For each column, for each row, check for first non-white pixel\n for (i = 0; i < width && minx === -1; ++i) {\n for (j = 0; j < height; ++j) {\n const pixelIndex = i * 4 + j * width4;\n if (\n pixelData[pixelIndex] !== 255 ||\n pixelData[pixelIndex + 1] !== 255 ||\n pixelData[pixelIndex + 2] !== 255 ||\n pixelData[pixelIndex + 3] !== 255\n ) {\n minx = i;\n break;\n }\n }\n }\n\n return {\n width: metrics.width,\n height: descent - ascent,\n ascent: baseline - ascent,\n descent: descent - baseline,\n minx: minx - padding / 2,\n };\n }\n\n return {\n width: metrics.width,\n height: 0,\n ascent: 0,\n descent: 0,\n minx: 0,\n };\n}\n\nlet imageSmoothingEnabledName;\n\n/**\n * Writes the given text into a new canvas. The canvas will be sized to fit the text.\n * If text is blank, returns undefined.\n *\n * @param {string} text The text to write.\n * @param {object} [options] Object with the following properties:\n * @param {string} [options.font='10px sans-serif'] The CSS font to use.\n * @param {string} [options.textBaseline='bottom'] The baseline of the text.\n * @param {boolean} [options.fill=true] Whether to fill the text.\n * @param {boolean} [options.stroke=false] Whether to stroke the text.\n * @param {Color} [options.fillColor=Color.WHITE] The fill color.\n * @param {Color} [options.strokeColor=Color.BLACK] The stroke color.\n * @param {number} [options.strokeWidth=1] The stroke width.\n * @param {Color} [options.backgroundColor=Color.TRANSPARENT] The background color of the canvas.\n * @param {number} [options.padding=0] The pixel size of the padding to add around the text.\n * @returns {HTMLCanvasElement|undefined} A new canvas with the given text drawn into it. The dimensions object\n * from measureText will also be added to the returned canvas. If text is\n * blank, returns undefined.\n * @function writeTextToCanvas\n */\nfunction writeTextToCanvas(text, options) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(text)) {\n throw new DeveloperError(\"text is required.\");\n }\n //>>includeEnd('debug');\n if (text === \"\") {\n return undefined;\n }\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const font = defaultValue(options.font, \"10px sans-serif\");\n const stroke = defaultValue(options.stroke, false);\n const fill = defaultValue(options.fill, true);\n const strokeWidth = defaultValue(options.strokeWidth, 1);\n const backgroundColor = defaultValue(\n options.backgroundColor,\n Color.TRANSPARENT\n );\n const padding = defaultValue(options.padding, 0);\n const doublePadding = padding * 2.0;\n\n const canvas = document.createElement(\"canvas\");\n canvas.width = 1;\n canvas.height = 1;\n canvas.style.font = font;\n // Since multiple read-back operations are expected for labels, use the willReadFrequently option \u2013 See https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently\n const context2D = canvas.getContext(\"2d\", { willReadFrequently: true });\n\n if (!defined(imageSmoothingEnabledName)) {\n if (defined(context2D.imageSmoothingEnabled)) {\n imageSmoothingEnabledName = \"imageSmoothingEnabled\";\n } else if (defined(context2D.mozImageSmoothingEnabled)) {\n imageSmoothingEnabledName = \"mozImageSmoothingEnabled\";\n } else if (defined(context2D.webkitImageSmoothingEnabled)) {\n imageSmoothingEnabledName = \"webkitImageSmoothingEnabled\";\n } else if (defined(context2D.msImageSmoothingEnabled)) {\n imageSmoothingEnabledName = \"msImageSmoothingEnabled\";\n }\n }\n\n context2D.font = font;\n context2D.lineJoin = \"round\";\n context2D.lineWidth = strokeWidth;\n context2D[imageSmoothingEnabledName] = false;\n\n // in order for measureText to calculate style, the canvas has to be\n // (temporarily) added to the DOM.\n canvas.style.visibility = \"hidden\";\n document.body.appendChild(canvas);\n\n const dimensions = measureText(context2D, text, font, stroke, fill);\n // Set canvas.dimensions to be accessed in LabelCollection\n canvas.dimensions = dimensions;\n\n document.body.removeChild(canvas);\n canvas.style.visibility = \"\";\n\n // Some characters, such as the letter j, have a non-zero starting position.\n // This value is used for kerning later, but we need to take it into account\n // now in order to draw the text completely on the canvas\n const x = -dimensions.minx;\n\n // Expand the width to include the starting position.\n const width = Math.ceil(dimensions.width) + x + doublePadding;\n\n // While the height of the letter is correct, we need to adjust\n // where we start drawing it so that letters like j and y properly dip\n // below the line.\n\n const height = dimensions.height + doublePadding;\n const baseline = height - dimensions.ascent + padding;\n const y = height - baseline + doublePadding;\n\n canvas.width = width;\n canvas.height = height;\n\n // Properties must be explicitly set again after changing width and height\n context2D.font = font;\n context2D.lineJoin = \"round\";\n context2D.lineWidth = strokeWidth;\n context2D[imageSmoothingEnabledName] = false;\n\n // Draw background\n if (backgroundColor !== Color.TRANSPARENT) {\n context2D.fillStyle = backgroundColor.toCssColorString();\n context2D.fillRect(0, 0, canvas.width, canvas.height);\n }\n\n if (stroke) {\n const strokeColor = defaultValue(options.strokeColor, Color.BLACK);\n context2D.strokeStyle = strokeColor.toCssColorString();\n context2D.strokeText(text, x + padding, y);\n }\n\n if (fill) {\n const fillColor = defaultValue(options.fillColor, Color.WHITE);\n context2D.fillStyle = fillColor.toCssColorString();\n context2D.fillText(text, x + padding, y);\n }\n\n return canvas;\n}\nexport default writeTextToCanvas;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport writeTextToCanvas from \"../Core/writeTextToCanvas.js\";\nimport bitmapSDF from \"bitmap-sdf\";\nimport BillboardCollection from \"./BillboardCollection.js\";\nimport BlendOption from \"./BlendOption.js\";\nimport HeightReference from \"./HeightReference.js\";\nimport HorizontalOrigin from \"./HorizontalOrigin.js\";\nimport Label from \"./Label.js\";\nimport LabelStyle from \"./LabelStyle.js\";\nimport SDFSettings from \"./SDFSettings.js\";\nimport TextureAtlas from \"./TextureAtlas.js\";\nimport VerticalOrigin from \"./VerticalOrigin.js\";\nimport GraphemeSplitter from \"grapheme-splitter\";\n\n// A glyph represents a single character in a particular label. It may or may\n// not have a billboard, depending on whether the texture info has an index into\n// the the label collection's texture atlas. Invisible characters have no texture, and\n// no billboard. However, it always has a valid dimensions object.\nfunction Glyph() {\n this.textureInfo = undefined;\n this.dimensions = undefined;\n this.billboard = undefined;\n}\n\n// GlyphTextureInfo represents a single character, drawn in a particular style,\n// shared and reference counted across all labels. It may or may not have an\n// index into the label collection's texture atlas, depending on whether the character\n// has both width and height, but it always has a valid dimensions object.\nfunction GlyphTextureInfo(labelCollection, index, dimensions) {\n this.labelCollection = labelCollection;\n this.index = index;\n this.dimensions = dimensions;\n}\n\n// Traditionally, leading is %20 of the font size.\nconst defaultLineSpacingPercent = 1.2;\nconst whitePixelCanvasId = \"ID_WHITE_PIXEL\";\nconst whitePixelSize = new Cartesian2(4, 4);\nconst whitePixelBoundingRegion = new BoundingRectangle(1, 1, 1, 1);\n\nfunction addWhitePixelCanvas(textureAtlas) {\n const canvas = document.createElement(\"canvas\");\n canvas.width = whitePixelSize.x;\n canvas.height = whitePixelSize.y;\n\n const context2D = canvas.getContext(\"2d\");\n context2D.fillStyle = \"#fff\";\n context2D.fillRect(0, 0, canvas.width, canvas.height);\n\n // Canvas operations take a frame to draw. Use the asynchronous add function which resolves a promise and allows the draw to complete,\n // but there's no need to wait on the promise before operation can continue\n textureAtlas.addImage(whitePixelCanvasId, canvas);\n}\n\n// reusable object for calling writeTextToCanvas\nconst writeTextToCanvasParameters = {};\nfunction createGlyphCanvas(\n character,\n font,\n fillColor,\n outlineColor,\n outlineWidth,\n style,\n verticalOrigin\n) {\n writeTextToCanvasParameters.font = font;\n writeTextToCanvasParameters.fillColor = fillColor;\n writeTextToCanvasParameters.strokeColor = outlineColor;\n writeTextToCanvasParameters.strokeWidth = outlineWidth;\n // Setting the padding to something bigger is necessary to get enough space for the outlining.\n writeTextToCanvasParameters.padding = SDFSettings.PADDING;\n\n if (verticalOrigin === VerticalOrigin.CENTER) {\n writeTextToCanvasParameters.textBaseline = \"middle\";\n } else if (verticalOrigin === VerticalOrigin.TOP) {\n writeTextToCanvasParameters.textBaseline = \"top\";\n } else {\n // VerticalOrigin.BOTTOM and VerticalOrigin.BASELINE\n writeTextToCanvasParameters.textBaseline = \"bottom\";\n }\n\n writeTextToCanvasParameters.fill =\n style === LabelStyle.FILL || style === LabelStyle.FILL_AND_OUTLINE;\n writeTextToCanvasParameters.stroke =\n style === LabelStyle.OUTLINE || style === LabelStyle.FILL_AND_OUTLINE;\n writeTextToCanvasParameters.backgroundColor = Color.BLACK;\n\n return writeTextToCanvas(character, writeTextToCanvasParameters);\n}\n\nfunction unbindGlyph(labelCollection, glyph) {\n glyph.textureInfo = undefined;\n glyph.dimensions = undefined;\n\n const billboard = glyph.billboard;\n if (defined(billboard)) {\n billboard.show = false;\n billboard.image = undefined;\n if (defined(billboard._removeCallbackFunc)) {\n billboard._removeCallbackFunc();\n billboard._removeCallbackFunc = undefined;\n }\n labelCollection._spareBillboards.push(billboard);\n glyph.billboard = undefined;\n }\n}\n\nfunction addGlyphToTextureAtlas(textureAtlas, id, canvas, glyphTextureInfo) {\n glyphTextureInfo.index = textureAtlas.addImageSync(id, canvas);\n}\n\nconst splitter = new GraphemeSplitter();\n\nfunction rebindAllGlyphs(labelCollection, label) {\n const text = label._renderedText;\n const graphemes = splitter.splitGraphemes(text);\n const textLength = graphemes.length;\n const glyphs = label._glyphs;\n const glyphsLength = glyphs.length;\n\n let glyph;\n let glyphIndex;\n let textIndex;\n\n // Compute a font size scale relative to the sdf font generated size.\n label._relativeSize = label._fontSize / SDFSettings.FONT_SIZE;\n\n // if we have more glyphs than needed, unbind the extras.\n if (textLength < glyphsLength) {\n for (glyphIndex = textLength; glyphIndex < glyphsLength; ++glyphIndex) {\n unbindGlyph(labelCollection, glyphs[glyphIndex]);\n }\n }\n\n // presize glyphs to match the new text length\n glyphs.length = textLength;\n\n const showBackground =\n label._showBackground && text.split(\"\\n\").join(\"\").length > 0;\n let backgroundBillboard = label._backgroundBillboard;\n const backgroundBillboardCollection =\n labelCollection._backgroundBillboardCollection;\n if (!showBackground) {\n if (defined(backgroundBillboard)) {\n backgroundBillboardCollection.remove(backgroundBillboard);\n label._backgroundBillboard = backgroundBillboard = undefined;\n }\n } else {\n if (!defined(backgroundBillboard)) {\n backgroundBillboard = backgroundBillboardCollection.add({\n collection: labelCollection,\n image: whitePixelCanvasId,\n imageSubRegion: whitePixelBoundingRegion,\n });\n label._backgroundBillboard = backgroundBillboard;\n }\n\n backgroundBillboard.color = label._backgroundColor;\n backgroundBillboard.show = label._show;\n backgroundBillboard.position = label._position;\n backgroundBillboard.eyeOffset = label._eyeOffset;\n backgroundBillboard.pixelOffset = label._pixelOffset;\n backgroundBillboard.horizontalOrigin = HorizontalOrigin.LEFT;\n backgroundBillboard.verticalOrigin = label._verticalOrigin;\n backgroundBillboard.heightReference = label._heightReference;\n backgroundBillboard.scale = label.totalScale;\n backgroundBillboard.pickPrimitive = label;\n backgroundBillboard.id = label._id;\n backgroundBillboard.translucencyByDistance = label._translucencyByDistance;\n backgroundBillboard.pixelOffsetScaleByDistance =\n label._pixelOffsetScaleByDistance;\n backgroundBillboard.scaleByDistance = label._scaleByDistance;\n backgroundBillboard.distanceDisplayCondition =\n label._distanceDisplayCondition;\n backgroundBillboard.disableDepthTestDistance =\n label._disableDepthTestDistance;\n }\n\n const glyphTextureCache = labelCollection._glyphTextureCache;\n\n // walk the text looking for new characters (creating new glyphs for each)\n // or changed characters (rebinding existing glyphs)\n for (textIndex = 0; textIndex < textLength; ++textIndex) {\n const character = graphemes[textIndex];\n const verticalOrigin = label._verticalOrigin;\n\n const id = JSON.stringify([\n character,\n label._fontFamily,\n label._fontStyle,\n label._fontWeight,\n +verticalOrigin,\n ]);\n\n let glyphTextureInfo = glyphTextureCache[id];\n if (!defined(glyphTextureInfo)) {\n const glyphFont = `${label._fontStyle} ${label._fontWeight} ${SDFSettings.FONT_SIZE}px ${label._fontFamily}`;\n\n const canvas = createGlyphCanvas(\n character,\n glyphFont,\n Color.WHITE,\n Color.WHITE,\n 0.0,\n LabelStyle.FILL,\n verticalOrigin\n );\n\n glyphTextureInfo = new GlyphTextureInfo(\n labelCollection,\n -1,\n canvas.dimensions\n );\n glyphTextureCache[id] = glyphTextureInfo;\n\n if (canvas.width > 0 && canvas.height > 0) {\n const sdfValues = bitmapSDF(canvas, {\n cutoff: SDFSettings.CUTOFF,\n radius: SDFSettings.RADIUS,\n });\n\n // Context is originally created in writeTextToCanvas()\n const ctx = canvas.getContext(\"2d\");\n const canvasWidth = canvas.width;\n const canvasHeight = canvas.height;\n const imgData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);\n for (let i = 0; i < canvasWidth; i++) {\n for (let j = 0; j < canvasHeight; j++) {\n const baseIndex = j * canvasWidth + i;\n const alpha = sdfValues[baseIndex] * 255;\n const imageIndex = baseIndex * 4;\n imgData.data[imageIndex + 0] = alpha;\n imgData.data[imageIndex + 1] = alpha;\n imgData.data[imageIndex + 2] = alpha;\n imgData.data[imageIndex + 3] = alpha;\n }\n }\n ctx.putImageData(imgData, 0, 0);\n if (character !== \" \") {\n addGlyphToTextureAtlas(\n labelCollection._textureAtlas,\n id,\n canvas,\n glyphTextureInfo\n );\n }\n }\n }\n\n glyph = glyphs[textIndex];\n\n if (defined(glyph)) {\n // clean up leftover information from the previous glyph\n if (glyphTextureInfo.index === -1) {\n // no texture, and therefore no billboard, for this glyph.\n // so, completely unbind glyph.\n unbindGlyph(labelCollection, glyph);\n } else if (defined(glyph.textureInfo)) {\n // we have a texture and billboard. If we had one before, release\n // our reference to that texture info, but reuse the billboard.\n glyph.textureInfo = undefined;\n }\n } else {\n // create a glyph object\n glyph = new Glyph();\n glyphs[textIndex] = glyph;\n }\n\n glyph.textureInfo = glyphTextureInfo;\n glyph.dimensions = glyphTextureInfo.dimensions;\n\n // if we have a texture, configure the existing billboard, or obtain one\n if (glyphTextureInfo.index !== -1) {\n let billboard = glyph.billboard;\n const spareBillboards = labelCollection._spareBillboards;\n if (!defined(billboard)) {\n if (spareBillboards.length > 0) {\n billboard = spareBillboards.pop();\n } else {\n billboard = labelCollection._billboardCollection.add({\n collection: labelCollection,\n });\n billboard._labelDimensions = new Cartesian2();\n billboard._labelTranslate = new Cartesian2();\n }\n glyph.billboard = billboard;\n }\n\n billboard.show = label._show;\n billboard.position = label._position;\n billboard.eyeOffset = label._eyeOffset;\n billboard.pixelOffset = label._pixelOffset;\n billboard.horizontalOrigin = HorizontalOrigin.LEFT;\n billboard.verticalOrigin = label._verticalOrigin;\n billboard.heightReference = label._heightReference;\n billboard.scale = label.totalScale;\n billboard.pickPrimitive = label;\n billboard.id = label._id;\n billboard.image = id;\n billboard.translucencyByDistance = label._translucencyByDistance;\n billboard.pixelOffsetScaleByDistance = label._pixelOffsetScaleByDistance;\n billboard.scaleByDistance = label._scaleByDistance;\n billboard.distanceDisplayCondition = label._distanceDisplayCondition;\n billboard.disableDepthTestDistance = label._disableDepthTestDistance;\n billboard._batchIndex = label._batchIndex;\n billboard.outlineColor = label.outlineColor;\n if (label.style === LabelStyle.FILL_AND_OUTLINE) {\n billboard.color = label._fillColor;\n billboard.outlineWidth = label.outlineWidth;\n } else if (label.style === LabelStyle.FILL) {\n billboard.color = label._fillColor;\n billboard.outlineWidth = 0.0;\n } else if (label.style === LabelStyle.OUTLINE) {\n billboard.color = Color.TRANSPARENT;\n billboard.outlineWidth = label.outlineWidth;\n }\n }\n }\n\n // changing glyphs will cause the position of the\n // glyphs to change, since different characters have different widths\n label._repositionAllGlyphs = true;\n}\n\nfunction calculateWidthOffset(lineWidth, horizontalOrigin, backgroundPadding) {\n if (horizontalOrigin === HorizontalOrigin.CENTER) {\n return -lineWidth / 2;\n } else if (horizontalOrigin === HorizontalOrigin.RIGHT) {\n return -(lineWidth + backgroundPadding.x);\n }\n return backgroundPadding.x;\n}\n\n// reusable Cartesian2 instances\nconst glyphPixelOffset = new Cartesian2();\nconst scratchBackgroundPadding = new Cartesian2();\n\nfunction repositionAllGlyphs(label) {\n const glyphs = label._glyphs;\n const text = label._renderedText;\n let glyph;\n let dimensions;\n let lastLineWidth = 0;\n let maxLineWidth = 0;\n const lineWidths = [];\n let maxGlyphDescent = Number.NEGATIVE_INFINITY;\n let maxGlyphY = 0;\n let numberOfLines = 1;\n let glyphIndex;\n const glyphLength = glyphs.length;\n\n const backgroundBillboard = label._backgroundBillboard;\n const backgroundPadding = Cartesian2.clone(\n defined(backgroundBillboard) ? label._backgroundPadding : Cartesian2.ZERO,\n scratchBackgroundPadding\n );\n\n // We need to scale the background padding, which is specified in pixels by the inverse of the relative size so it is scaled properly.\n backgroundPadding.x /= label._relativeSize;\n backgroundPadding.y /= label._relativeSize;\n\n for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {\n if (text.charAt(glyphIndex) === \"\\n\") {\n lineWidths.push(lastLineWidth);\n ++numberOfLines;\n lastLineWidth = 0;\n } else {\n glyph = glyphs[glyphIndex];\n dimensions = glyph.dimensions;\n maxGlyphY = Math.max(maxGlyphY, dimensions.height - dimensions.descent);\n maxGlyphDescent = Math.max(maxGlyphDescent, dimensions.descent);\n\n //Computing the line width must also account for the kerning that occurs between letters.\n lastLineWidth += dimensions.width - dimensions.minx;\n if (glyphIndex < glyphLength - 1) {\n lastLineWidth += glyphs[glyphIndex + 1].dimensions.minx;\n }\n maxLineWidth = Math.max(maxLineWidth, lastLineWidth);\n }\n }\n lineWidths.push(lastLineWidth);\n const maxLineHeight = maxGlyphY + maxGlyphDescent;\n\n const scale = label.totalScale;\n const horizontalOrigin = label._horizontalOrigin;\n const verticalOrigin = label._verticalOrigin;\n let lineIndex = 0;\n let lineWidth = lineWidths[lineIndex];\n let widthOffset = calculateWidthOffset(\n lineWidth,\n horizontalOrigin,\n backgroundPadding\n );\n const lineSpacing =\n (defined(label._lineHeight)\n ? label._lineHeight\n : defaultLineSpacingPercent * label._fontSize) / label._relativeSize;\n const otherLinesHeight = lineSpacing * (numberOfLines - 1);\n let totalLineWidth = maxLineWidth;\n let totalLineHeight = maxLineHeight + otherLinesHeight;\n\n if (defined(backgroundBillboard)) {\n totalLineWidth += backgroundPadding.x * 2;\n totalLineHeight += backgroundPadding.y * 2;\n backgroundBillboard._labelHorizontalOrigin = horizontalOrigin;\n }\n\n glyphPixelOffset.x = widthOffset * scale;\n glyphPixelOffset.y = 0;\n\n let firstCharOfLine = true;\n\n let lineOffsetY = 0;\n for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {\n if (text.charAt(glyphIndex) === \"\\n\") {\n ++lineIndex;\n lineOffsetY += lineSpacing;\n lineWidth = lineWidths[lineIndex];\n widthOffset = calculateWidthOffset(\n lineWidth,\n horizontalOrigin,\n backgroundPadding\n );\n glyphPixelOffset.x = widthOffset * scale;\n firstCharOfLine = true;\n } else {\n glyph = glyphs[glyphIndex];\n dimensions = glyph.dimensions;\n\n if (verticalOrigin === VerticalOrigin.TOP) {\n glyphPixelOffset.y =\n dimensions.height - maxGlyphY - backgroundPadding.y;\n glyphPixelOffset.y += SDFSettings.PADDING;\n } else if (verticalOrigin === VerticalOrigin.CENTER) {\n glyphPixelOffset.y =\n (otherLinesHeight + dimensions.height - maxGlyphY) / 2;\n } else if (verticalOrigin === VerticalOrigin.BASELINE) {\n glyphPixelOffset.y = otherLinesHeight;\n glyphPixelOffset.y -= SDFSettings.PADDING;\n } else {\n // VerticalOrigin.BOTTOM\n glyphPixelOffset.y =\n otherLinesHeight + maxGlyphDescent + backgroundPadding.y;\n glyphPixelOffset.y -= SDFSettings.PADDING;\n }\n glyphPixelOffset.y =\n (glyphPixelOffset.y - dimensions.descent - lineOffsetY) * scale;\n\n // Handle any offsets for the first character of the line since the bounds might not be right on the bottom left pixel.\n if (firstCharOfLine) {\n glyphPixelOffset.x -= SDFSettings.PADDING * scale;\n firstCharOfLine = false;\n }\n\n if (defined(glyph.billboard)) {\n glyph.billboard._setTranslate(glyphPixelOffset);\n glyph.billboard._labelDimensions.x = totalLineWidth;\n glyph.billboard._labelDimensions.y = totalLineHeight;\n glyph.billboard._labelHorizontalOrigin = horizontalOrigin;\n }\n\n //Compute the next x offset taking into account the kerning performed\n //on both the current letter as well as the next letter to be drawn\n //as well as any applied scale.\n if (glyphIndex < glyphLength - 1) {\n const nextGlyph = glyphs[glyphIndex + 1];\n glyphPixelOffset.x +=\n (dimensions.width - dimensions.minx + nextGlyph.dimensions.minx) *\n scale;\n }\n }\n }\n\n if (defined(backgroundBillboard) && text.split(\"\\n\").join(\"\").length > 0) {\n if (horizontalOrigin === HorizontalOrigin.CENTER) {\n widthOffset = -maxLineWidth / 2 - backgroundPadding.x;\n } else if (horizontalOrigin === HorizontalOrigin.RIGHT) {\n widthOffset = -(maxLineWidth + backgroundPadding.x * 2);\n } else {\n widthOffset = 0;\n }\n glyphPixelOffset.x = widthOffset * scale;\n\n if (verticalOrigin === VerticalOrigin.TOP) {\n glyphPixelOffset.y = maxLineHeight - maxGlyphY - maxGlyphDescent;\n } else if (verticalOrigin === VerticalOrigin.CENTER) {\n glyphPixelOffset.y = (maxLineHeight - maxGlyphY) / 2 - maxGlyphDescent;\n } else if (verticalOrigin === VerticalOrigin.BASELINE) {\n glyphPixelOffset.y = -backgroundPadding.y - maxGlyphDescent;\n } else {\n // VerticalOrigin.BOTTOM\n glyphPixelOffset.y = 0;\n }\n glyphPixelOffset.y = glyphPixelOffset.y * scale;\n\n backgroundBillboard.width = totalLineWidth;\n backgroundBillboard.height = totalLineHeight;\n backgroundBillboard._setTranslate(glyphPixelOffset);\n backgroundBillboard._labelTranslate = Cartesian2.clone(\n glyphPixelOffset,\n backgroundBillboard._labelTranslate\n );\n }\n\n if (label.heightReference === HeightReference.CLAMP_TO_GROUND) {\n for (glyphIndex = 0; glyphIndex < glyphLength; ++glyphIndex) {\n glyph = glyphs[glyphIndex];\n const billboard = glyph.billboard;\n if (defined(billboard)) {\n billboard._labelTranslate = Cartesian2.clone(\n glyphPixelOffset,\n billboard._labelTranslate\n );\n }\n }\n }\n}\n\nfunction destroyLabel(labelCollection, label) {\n const glyphs = label._glyphs;\n for (let i = 0, len = glyphs.length; i < len; ++i) {\n unbindGlyph(labelCollection, glyphs[i]);\n }\n if (defined(label._backgroundBillboard)) {\n labelCollection._backgroundBillboardCollection.remove(\n label._backgroundBillboard\n );\n label._backgroundBillboard = undefined;\n }\n label._labelCollection = undefined;\n\n if (defined(label._removeCallbackFunc)) {\n label._removeCallbackFunc();\n }\n\n destroyObject(label);\n}\n\n/**\n * A renderable collection of labels. Labels are viewport-aligned text positioned in the 3D scene.\n * Each label can have a different font, color, scale, etc.\n *

\n *
\n *
\n * Example labels\n *
\n *

\n * Labels are added and removed from the collection using {@link LabelCollection#add}\n * and {@link LabelCollection#remove}.\n *\n * @alias LabelCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each label from model to world coordinates.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {Scene} [options.scene] Must be passed in for labels that use the height reference property or will be depth tested against the globe.\n * @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The label blending option. The default\n * is used for rendering both opaque and translucent labels. However, if either all of the labels are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.\n * @param {boolean} [options.show=true] Determines if the labels in the collection will be shown.\n *\n * @performance For best performance, prefer a few collections, each with many labels, to\n * many collections with only a few labels each. Avoid having collections where some\n * labels change every frame and others do not; instead, create one or more collections\n * for static labels, and one or more collections for dynamic labels.\n *\n * @see LabelCollection#add\n * @see LabelCollection#remove\n * @see Label\n * @see BillboardCollection\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Labels.html|Cesium Sandcastle Labels Demo}\n *\n * @example\n * // Create a label collection with two labels\n * const labels = scene.primitives.add(new Cesium.LabelCollection());\n * labels.add({\n * position : new Cesium.Cartesian3(1.0, 2.0, 3.0),\n * text : 'A label'\n * });\n * labels.add({\n * position : new Cesium.Cartesian3(4.0, 5.0, 6.0),\n * text : 'Another label'\n * });\n */\nfunction LabelCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._scene = options.scene;\n this._batchTable = options.batchTable;\n\n this._textureAtlas = undefined;\n this._backgroundTextureAtlas = undefined;\n\n this._backgroundBillboardCollection = new BillboardCollection({\n scene: this._scene,\n });\n this._backgroundBillboardCollection.destroyTextureAtlas = false;\n\n this._billboardCollection = new BillboardCollection({\n scene: this._scene,\n batchTable: this._batchTable,\n });\n this._billboardCollection.destroyTextureAtlas = false;\n this._billboardCollection._sdf = true;\n\n this._spareBillboards = [];\n this._glyphTextureCache = {};\n this._labels = [];\n this._labelsToUpdate = [];\n this._totalGlyphCount = 0;\n\n this._highlightColor = Color.clone(Color.WHITE); // Only used by Vector3DTilePoints\n\n /**\n * Determines if labels in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * The 4x4 transformation matrix that transforms each label in this collection from model to world coordinates.\n * When this is the identity matrix, the labels are drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n * @type Matrix4\n * @default {@link Matrix4.IDENTITY}\n *\n * @example\n * const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\n * labels.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);\n * labels.add({\n * position : new Cesium.Cartesian3(0.0, 0.0, 0.0),\n * text : 'Center'\n * });\n * labels.add({\n * position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0),\n * text : 'East'\n * });\n * labels.add({\n * position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0),\n * text : 'North'\n * });\n * labels.add({\n * position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0),\n * text : 'Up'\n * });\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * The label blending option. The default is used for rendering both opaque and translucent labels.\n * However, if either all of the labels are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve\n * performance by up to 2x.\n * @type {BlendOption}\n * @default BlendOption.OPAQUE_AND_TRANSLUCENT\n */\n this.blendOption = defaultValue(\n options.blendOption,\n BlendOption.OPAQUE_AND_TRANSLUCENT\n );\n}\n\nObject.defineProperties(LabelCollection.prototype, {\n /**\n * Returns the number of labels in this collection. This is commonly used with\n * {@link LabelCollection#get} to iterate over all the labels\n * in the collection.\n * @memberof LabelCollection.prototype\n * @type {number}\n */\n length: {\n get: function () {\n return this._labels.length;\n },\n },\n});\n\n/**\n * Creates and adds a label with the specified initial properties to the collection.\n * The added label is returned so it can be modified or removed from the collection later.\n *\n * @param {object} [options] A template describing the label's properties as shown in Example 1.\n * @returns {Label} The label that was added to the collection.\n *\n * @performance Calling add is expected constant time. However, the collection's vertex buffer\n * is rewritten; this operations is O(n) and also incurs\n * CPU to GPU overhead. For best performance, add as many billboards as possible before\n * calling update.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Example 1: Add a label, specifying all the default values.\n * const l = labels.add({\n * show : true,\n * position : Cesium.Cartesian3.ZERO,\n * text : '',\n * font : '30px sans-serif',\n * fillColor : Cesium.Color.WHITE,\n * outlineColor : Cesium.Color.BLACK,\n * outlineWidth : 1.0,\n * showBackground : false,\n * backgroundColor : new Cesium.Color(0.165, 0.165, 0.165, 0.8),\n * backgroundPadding : new Cesium.Cartesian2(7, 5),\n * style : Cesium.LabelStyle.FILL,\n * pixelOffset : Cesium.Cartesian2.ZERO,\n * eyeOffset : Cesium.Cartesian3.ZERO,\n * horizontalOrigin : Cesium.HorizontalOrigin.LEFT,\n * verticalOrigin : Cesium.VerticalOrigin.BASELINE,\n * scale : 1.0,\n * translucencyByDistance : undefined,\n * pixelOffsetScaleByDistance : undefined,\n * heightReference : HeightReference.NONE,\n * distanceDisplayCondition : undefined\n * });\n *\n * @example\n * // Example 2: Specify only the label's cartographic position,\n * // text, and font.\n * const l = labels.add({\n * position : Cesium.Cartesian3.fromRadians(longitude, latitude, height),\n * text : 'Hello World',\n * font : '24px Helvetica',\n * });\n *\n * @see LabelCollection#remove\n * @see LabelCollection#removeAll\n */\nLabelCollection.prototype.add = function (options) {\n const label = new Label(options, this);\n\n this._labels.push(label);\n this._labelsToUpdate.push(label);\n\n return label;\n};\n\n/**\n * Removes a label from the collection. Once removed, a label is no longer usable.\n *\n * @param {Label} label The label to remove.\n * @returns {boolean} true if the label was removed; false if the label was not found in the collection.\n *\n * @performance Calling remove is expected constant time. However, the collection's vertex buffer\n * is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For\n * best performance, remove as many labels as possible before calling update.\n * If you intend to temporarily hide a label, it is usually more efficient to call\n * {@link Label#show} instead of removing and re-adding the label.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * const l = labels.add(...);\n * labels.remove(l); // Returns true\n *\n * @see LabelCollection#add\n * @see LabelCollection#removeAll\n * @see Label#show\n */\nLabelCollection.prototype.remove = function (label) {\n if (defined(label) && label._labelCollection === this) {\n const index = this._labels.indexOf(label);\n if (index !== -1) {\n this._labels.splice(index, 1);\n destroyLabel(this, label);\n return true;\n }\n }\n return false;\n};\n\n/**\n * Removes all labels from the collection.\n *\n * @performance O(n). It is more efficient to remove all the labels\n * from a collection and then add new ones than to create a new collection entirely.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * labels.add(...);\n * labels.add(...);\n * labels.removeAll();\n *\n * @see LabelCollection#add\n * @see LabelCollection#remove\n */\nLabelCollection.prototype.removeAll = function () {\n const labels = this._labels;\n\n for (let i = 0, len = labels.length; i < len; ++i) {\n destroyLabel(this, labels[i]);\n }\n\n labels.length = 0;\n};\n\n/**\n * Check whether this collection contains a given label.\n *\n * @param {Label} label The label to check for.\n * @returns {boolean} true if this collection contains the label, false otherwise.\n *\n * @see LabelCollection#get\n *\n */\nLabelCollection.prototype.contains = function (label) {\n return defined(label) && label._labelCollection === this;\n};\n\n/**\n * Returns the label in the collection at the specified index. Indices are zero-based\n * and increase as labels are added. Removing a label shifts all labels after\n * it to the left, changing their indices. This function is commonly used with\n * {@link LabelCollection#length} to iterate over all the labels\n * in the collection.\n *\n * @param {number} index The zero-based index of the billboard.\n *\n * @returns {Label} The label at the specified index.\n *\n * @performance Expected constant time. If labels were removed from the collection and\n * {@link Scene#render} was not called, an implicit O(n)\n * operation is performed.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Toggle the show property of every label in the collection\n * const len = labels.length;\n * for (let i = 0; i < len; ++i) {\n * const l = billboards.get(i);\n * l.show = !l.show;\n * }\n *\n * @see LabelCollection#length\n */\nLabelCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n return this._labels[index];\n};\n\n/**\n * @private\n *\n */\nLabelCollection.prototype.update = function (frameState) {\n if (!this.show) {\n return;\n }\n\n const billboardCollection = this._billboardCollection;\n const backgroundBillboardCollection = this._backgroundBillboardCollection;\n\n billboardCollection.modelMatrix = this.modelMatrix;\n billboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;\n backgroundBillboardCollection.modelMatrix = this.modelMatrix;\n backgroundBillboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;\n\n const context = frameState.context;\n\n if (!defined(this._textureAtlas)) {\n this._textureAtlas = new TextureAtlas({\n context: context,\n });\n billboardCollection.textureAtlas = this._textureAtlas;\n }\n\n if (!defined(this._backgroundTextureAtlas)) {\n this._backgroundTextureAtlas = new TextureAtlas({\n context: context,\n initialSize: whitePixelSize,\n });\n backgroundBillboardCollection.textureAtlas = this._backgroundTextureAtlas;\n addWhitePixelCanvas(this._backgroundTextureAtlas);\n }\n\n const len = this._labelsToUpdate.length;\n for (let i = 0; i < len; ++i) {\n const label = this._labelsToUpdate[i];\n if (label.isDestroyed()) {\n continue;\n }\n\n const preUpdateGlyphCount = label._glyphs.length;\n\n if (label._rebindAllGlyphs) {\n rebindAllGlyphs(this, label);\n label._rebindAllGlyphs = false;\n }\n\n if (label._repositionAllGlyphs) {\n repositionAllGlyphs(label);\n label._repositionAllGlyphs = false;\n }\n\n const glyphCountDifference = label._glyphs.length - preUpdateGlyphCount;\n this._totalGlyphCount += glyphCountDifference;\n }\n\n const blendOption =\n backgroundBillboardCollection.length > 0\n ? BlendOption.TRANSLUCENT\n : this.blendOption;\n billboardCollection.blendOption = blendOption;\n backgroundBillboardCollection.blendOption = blendOption;\n\n billboardCollection._highlightColor = this._highlightColor;\n backgroundBillboardCollection._highlightColor = this._highlightColor;\n\n this._labelsToUpdate.length = 0;\n backgroundBillboardCollection.update(frameState);\n billboardCollection.update(frameState);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see LabelCollection#destroy\n */\nLabelCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * labels = labels && labels.destroy();\n *\n * @see LabelCollection#isDestroyed\n */\nLabelCollection.prototype.destroy = function () {\n this.removeAll();\n this._billboardCollection = this._billboardCollection.destroy();\n this._textureAtlas = this._textureAtlas && this._textureAtlas.destroy();\n this._backgroundBillboardCollection = this._backgroundBillboardCollection.destroy();\n this._backgroundTextureAtlas =\n this._backgroundTextureAtlas && this._backgroundTextureAtlas.destroy();\n\n return destroyObject(this);\n};\nexport default LabelCollection;\n", "/**\n * Describes how to draw a label.\n *\n * @enum {number}\n *\n * @see Label#style\n */\nconst LabelStyle = {\n /**\n * Fill the text of the label, but do not outline.\n *\n * @type {number}\n * @constant\n */\n FILL: 0,\n\n /**\n * Outline the text of the label, but do not fill.\n *\n * @type {number}\n * @constant\n */\n OUTLINE: 1,\n\n /**\n * Fill and outline the text of the label.\n *\n * @type {number}\n * @constant\n */\n FILL_AND_OUTLINE: 2,\n};\nexport default Object.freeze(LabelStyle);\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport Billboard from \"./Billboard.js\";\nimport HeightReference from \"./HeightReference.js\";\nimport HorizontalOrigin from \"./HorizontalOrigin.js\";\nimport LabelStyle from \"./LabelStyle.js\";\nimport SDFSettings from \"./SDFSettings.js\";\nimport VerticalOrigin from \"./VerticalOrigin.js\";\n\nconst fontInfoCache = {};\nlet fontInfoCacheLength = 0;\nconst fontInfoCacheMaxSize = 256;\nconst defaultBackgroundColor = new Color(0.165, 0.165, 0.165, 0.8);\nconst defaultBackgroundPadding = new Cartesian2(7, 5);\n\nconst textTypes = Object.freeze({\n LTR: 0,\n RTL: 1,\n WEAK: 2,\n BRACKETS: 3,\n});\n\nfunction rebindAllGlyphs(label) {\n if (!label._rebindAllGlyphs && !label._repositionAllGlyphs) {\n // only push label if it's not already been marked dirty\n label._labelCollection._labelsToUpdate.push(label);\n }\n label._rebindAllGlyphs = true;\n}\n\nfunction repositionAllGlyphs(label) {\n if (!label._rebindAllGlyphs && !label._repositionAllGlyphs) {\n // only push label if it's not already been marked dirty\n label._labelCollection._labelsToUpdate.push(label);\n }\n label._repositionAllGlyphs = true;\n}\n\nfunction getCSSValue(element, property) {\n return document.defaultView\n .getComputedStyle(element, null)\n .getPropertyValue(property);\n}\n\nfunction parseFont(label) {\n let fontInfo = fontInfoCache[label._font];\n if (!defined(fontInfo)) {\n const div = document.createElement(\"div\");\n div.style.position = \"absolute\";\n div.style.opacity = 0;\n div.style.font = label._font;\n document.body.appendChild(div);\n\n let lineHeight = parseFloat(getCSSValue(div, \"line-height\"));\n if (isNaN(lineHeight)) {\n // line-height isn't a number, i.e. 'normal'; apply default line-spacing\n lineHeight = undefined;\n }\n\n fontInfo = {\n family: getCSSValue(div, \"font-family\"),\n size: getCSSValue(div, \"font-size\").replace(\"px\", \"\"),\n style: getCSSValue(div, \"font-style\"),\n weight: getCSSValue(div, \"font-weight\"),\n lineHeight: lineHeight,\n };\n\n document.body.removeChild(div);\n if (fontInfoCacheLength < fontInfoCacheMaxSize) {\n fontInfoCache[label._font] = fontInfo;\n fontInfoCacheLength++;\n }\n }\n label._fontFamily = fontInfo.family;\n label._fontSize = fontInfo.size;\n label._fontStyle = fontInfo.style;\n label._fontWeight = fontInfo.weight;\n label._lineHeight = fontInfo.lineHeight;\n}\n\n/**\n *
\n * Create labels by calling {@link LabelCollection#add}. Do not call the constructor directly.\n *
\n *\n * @alias Label\n * @internalConstructor\n * @class\n *\n * @exception {DeveloperError} translucencyByDistance.far must be greater than translucencyByDistance.near\n * @exception {DeveloperError} pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near\n * @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near\n *\n * @see LabelCollection\n * @see LabelCollection#add\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Labels.html|Cesium Sandcastle Labels Demo}\n */\nfunction Label(options, labelCollection) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(options.disableDepthTestDistance) &&\n options.disableDepthTestDistance < 0.0\n ) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than 0.0.\"\n );\n }\n //>>includeEnd('debug');\n\n let translucencyByDistance = options.translucencyByDistance;\n let pixelOffsetScaleByDistance = options.pixelOffsetScaleByDistance;\n let scaleByDistance = options.scaleByDistance;\n let distanceDisplayCondition = options.distanceDisplayCondition;\n if (defined(translucencyByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (translucencyByDistance.far <= translucencyByDistance.near) {\n throw new DeveloperError(\n \"translucencyByDistance.far must be greater than translucencyByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n translucencyByDistance = NearFarScalar.clone(translucencyByDistance);\n }\n if (defined(pixelOffsetScaleByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (pixelOffsetScaleByDistance.far <= pixelOffsetScaleByDistance.near) {\n throw new DeveloperError(\n \"pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n pixelOffsetScaleByDistance = NearFarScalar.clone(\n pixelOffsetScaleByDistance\n );\n }\n if (defined(scaleByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (scaleByDistance.far <= scaleByDistance.near) {\n throw new DeveloperError(\n \"scaleByDistance.far must be greater than scaleByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n scaleByDistance = NearFarScalar.clone(scaleByDistance);\n }\n if (defined(distanceDisplayCondition)) {\n //>>includeStart('debug', pragmas.debug);\n if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {\n throw new DeveloperError(\n \"distanceDisplayCondition.far must be greater than distanceDisplayCondition.near.\"\n );\n }\n //>>includeEnd('debug');\n distanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition\n );\n }\n\n this._renderedText = undefined;\n this._text = undefined;\n this._show = defaultValue(options.show, true);\n this._font = defaultValue(options.font, \"30px sans-serif\");\n this._fillColor = Color.clone(defaultValue(options.fillColor, Color.WHITE));\n this._outlineColor = Color.clone(\n defaultValue(options.outlineColor, Color.BLACK)\n );\n this._outlineWidth = defaultValue(options.outlineWidth, 1.0);\n this._showBackground = defaultValue(options.showBackground, false);\n this._backgroundColor = Color.clone(\n defaultValue(options.backgroundColor, defaultBackgroundColor)\n );\n this._backgroundPadding = Cartesian2.clone(\n defaultValue(options.backgroundPadding, defaultBackgroundPadding)\n );\n this._style = defaultValue(options.style, LabelStyle.FILL);\n this._verticalOrigin = defaultValue(\n options.verticalOrigin,\n VerticalOrigin.BASELINE\n );\n this._horizontalOrigin = defaultValue(\n options.horizontalOrigin,\n HorizontalOrigin.LEFT\n );\n this._pixelOffset = Cartesian2.clone(\n defaultValue(options.pixelOffset, Cartesian2.ZERO)\n );\n this._eyeOffset = Cartesian3.clone(\n defaultValue(options.eyeOffset, Cartesian3.ZERO)\n );\n this._position = Cartesian3.clone(\n defaultValue(options.position, Cartesian3.ZERO)\n );\n this._scale = defaultValue(options.scale, 1.0);\n this._id = options.id;\n this._translucencyByDistance = translucencyByDistance;\n this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance;\n this._scaleByDistance = scaleByDistance;\n this._heightReference = defaultValue(\n options.heightReference,\n HeightReference.NONE\n );\n this._distanceDisplayCondition = distanceDisplayCondition;\n this._disableDepthTestDistance = options.disableDepthTestDistance;\n\n this._labelCollection = labelCollection;\n this._glyphs = [];\n this._backgroundBillboard = undefined;\n this._batchIndex = undefined; // Used only by Vector3DTilePoints and BillboardCollection\n\n this._rebindAllGlyphs = true;\n this._repositionAllGlyphs = true;\n\n this._actualClampedPosition = undefined;\n this._removeCallbackFunc = undefined;\n this._mode = undefined;\n\n this._clusterShow = true;\n\n this.text = defaultValue(options.text, \"\");\n\n this._relativeSize = 1.0;\n\n parseFont(this);\n\n this._updateClamping();\n}\n\nObject.defineProperties(Label.prototype, {\n /**\n * Determines if this label will be shown. Use this to hide or show a label, instead\n * of removing it and re-adding it to the collection.\n * @memberof Label.prototype\n * @type {boolean}\n * @default true\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._show !== value) {\n this._show = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const billboard = glyphs[i].billboard;\n if (defined(billboard)) {\n billboard.show = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.show = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets the Cartesian position of this label.\n * @memberof Label.prototype\n * @type {Cartesian3}\n */\n position: {\n get: function () {\n return this._position;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const position = this._position;\n if (!Cartesian3.equals(position, value)) {\n Cartesian3.clone(value, position);\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const billboard = glyphs[i].billboard;\n if (defined(billboard)) {\n billboard.position = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.position = value;\n }\n\n this._updateClamping();\n }\n },\n },\n\n /**\n * Gets or sets the height reference of this billboard.\n * @memberof Label.prototype\n * @type {HeightReference}\n * @default HeightReference.NONE\n */\n heightReference: {\n get: function () {\n return this._heightReference;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (value !== this._heightReference) {\n this._heightReference = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const billboard = glyphs[i].billboard;\n if (defined(billboard)) {\n billboard.heightReference = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.heightReference = value;\n }\n\n repositionAllGlyphs(this);\n\n this._updateClamping();\n }\n },\n },\n\n /**\n * Gets or sets the text of this label.\n * @memberof Label.prototype\n * @type {string}\n */\n text: {\n get: function () {\n return this._text;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._text !== value) {\n this._text = value;\n\n // Strip soft-hyphen (auto-wrap) characters from input string\n const renderedValue = value.replace(/\\u00ad/g, \"\");\n this._renderedText = Label.enableRightToLeftDetection\n ? reverseRtl(renderedValue)\n : renderedValue;\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the font used to draw this label. Fonts are specified using the same syntax as the CSS 'font' property.\n * @memberof Label.prototype\n * @type {string}\n * @default '30px sans-serif'\n * @see {@link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-styles|HTML canvas 2D context text styles}\n */\n font: {\n get: function () {\n return this._font;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._font !== value) {\n this._font = value;\n rebindAllGlyphs(this);\n parseFont(this);\n }\n },\n },\n\n /**\n * Gets or sets the fill color of this label.\n * @memberof Label.prototype\n * @type {Color}\n * @default Color.WHITE\n * @see {@link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#fill-and-stroke-styles|HTML canvas 2D context fill and stroke styles}\n */\n fillColor: {\n get: function () {\n return this._fillColor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const fillColor = this._fillColor;\n if (!Color.equals(fillColor, value)) {\n Color.clone(value, fillColor);\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the outline color of this label.\n * @memberof Label.prototype\n * @type {Color}\n * @default Color.BLACK\n * @see {@link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#fill-and-stroke-styles|HTML canvas 2D context fill and stroke styles}\n */\n outlineColor: {\n get: function () {\n return this._outlineColor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const outlineColor = this._outlineColor;\n if (!Color.equals(outlineColor, value)) {\n Color.clone(value, outlineColor);\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the outline width of this label.\n * @memberof Label.prototype\n * @type {number}\n * @default 1.0\n * @see {@link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#fill-and-stroke-styles|HTML canvas 2D context fill and stroke styles}\n */\n outlineWidth: {\n get: function () {\n return this._outlineWidth;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._outlineWidth !== value) {\n this._outlineWidth = value;\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Determines if a background behind this label will be shown.\n * @memberof Label.prototype\n * @default false\n * @type {boolean}\n */\n showBackground: {\n get: function () {\n return this._showBackground;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._showBackground !== value) {\n this._showBackground = value;\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the background color of this label.\n * @memberof Label.prototype\n * @type {Color}\n * @default new Color(0.165, 0.165, 0.165, 0.8)\n */\n backgroundColor: {\n get: function () {\n return this._backgroundColor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const backgroundColor = this._backgroundColor;\n if (!Color.equals(backgroundColor, value)) {\n Color.clone(value, backgroundColor);\n\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.color = backgroundColor;\n }\n }\n },\n },\n\n /**\n * Gets or sets the background padding, in pixels, of this label. The x value\n * controls horizontal padding, and the y value controls vertical padding.\n * @memberof Label.prototype\n * @type {Cartesian2}\n * @default new Cartesian2(7, 5)\n */\n backgroundPadding: {\n get: function () {\n return this._backgroundPadding;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const backgroundPadding = this._backgroundPadding;\n if (!Cartesian2.equals(backgroundPadding, value)) {\n Cartesian2.clone(value, backgroundPadding);\n repositionAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the style of this label.\n * @memberof Label.prototype\n * @type {LabelStyle}\n * @default LabelStyle.FILL\n */\n style: {\n get: function () {\n return this._style;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._style !== value) {\n this._style = value;\n rebindAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the pixel offset in screen space from the origin of this label. This is commonly used\n * to align multiple labels and billboards at the same position, e.g., an image and text. The\n * screen space origin is the top, left corner of the canvas; x increases from\n * left to right, and y increases from top to bottom.\n *

\n *
\n * \n * \n * \n *
default
l.pixeloffset = new Cartesian2(25, 75);
\n * The label's origin is indicated by the yellow point.\n *
\n * @memberof Label.prototype\n * @type {Cartesian2}\n * @default Cartesian2.ZERO\n */\n pixelOffset: {\n get: function () {\n return this._pixelOffset;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const pixelOffset = this._pixelOffset;\n if (!Cartesian2.equals(pixelOffset, value)) {\n Cartesian2.clone(value, pixelOffset);\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.pixelOffset = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.pixelOffset = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets near and far translucency properties of a Label based on the Label's distance from the camera.\n * A label's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's translucency remains clamped to the nearest bound. If undefined,\n * translucencyByDistance will be disabled.\n * @memberof Label.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a label's translucencyByDistance to 1.0 when the\n * // camera is 1500 meters from the label and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * text.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable translucency by distance\n * text.translucencyByDistance = undefined;\n */\n translucencyByDistance: {\n get: function () {\n return this._translucencyByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n const translucencyByDistance = this._translucencyByDistance;\n if (!NearFarScalar.equals(translucencyByDistance, value)) {\n this._translucencyByDistance = NearFarScalar.clone(\n value,\n translucencyByDistance\n );\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.translucencyByDistance = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.translucencyByDistance = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets near and far pixel offset scaling properties of a Label based on the Label's distance from the camera.\n * A label's pixel offset will be scaled between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's pixel offset scaling remains clamped to the nearest bound. If undefined,\n * pixelOffsetScaleByDistance will be disabled.\n * @memberof Label.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a label's pixel offset scale to 0.0 when the\n * // camera is 1500 meters from the label and scale pixel offset to 10.0 pixels\n * // in the y direction the camera distance approaches 8.0e6 meters.\n * text.pixelOffset = new Cesium.Cartesian2(0.0, 1.0);\n * text.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(1.5e2, 0.0, 8.0e6, 10.0);\n *\n * @example\n * // Example 2.\n * // disable pixel offset by distance\n * text.pixelOffsetScaleByDistance = undefined;\n */\n pixelOffsetScaleByDistance: {\n get: function () {\n return this._pixelOffsetScaleByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n const pixelOffsetScaleByDistance = this._pixelOffsetScaleByDistance;\n if (!NearFarScalar.equals(pixelOffsetScaleByDistance, value)) {\n this._pixelOffsetScaleByDistance = NearFarScalar.clone(\n value,\n pixelOffsetScaleByDistance\n );\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.pixelOffsetScaleByDistance = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.pixelOffsetScaleByDistance = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets near and far scaling properties of a Label based on the label's distance from the camera.\n * A label's scale will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the label's scale remains clamped to the nearest bound. If undefined,\n * scaleByDistance will be disabled.\n * @memberof Label.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a label's scaleByDistance to scale by 1.5 when the\n * // camera is 1500 meters from the label and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * label.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 1.5, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable scaling by distance\n * label.scaleByDistance = undefined;\n */\n scaleByDistance: {\n get: function () {\n return this._scaleByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n const scaleByDistance = this._scaleByDistance;\n if (!NearFarScalar.equals(scaleByDistance, value)) {\n this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.scaleByDistance = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.scaleByDistance = value;\n }\n }\n },\n },\n\n /**\n * Gets and sets the 3D Cartesian offset applied to this label in eye coordinates. Eye coordinates is a left-handed\n * coordinate system, where x points towards the viewer's right, y points up, and\n * z points into the screen. Eye coordinates use the same scale as world and model coordinates,\n * which is typically meters.\n *

\n * An eye offset is commonly used to arrange multiple label or objects at the same position, e.g., to\n * arrange a label above its corresponding 3D model.\n *

\n * Below, the label is positioned at the center of the Earth but an eye offset makes it always\n * appear on top of the Earth regardless of the viewer's or Earth's orientation.\n *

\n *
\n * \n * \n * \n *
\n * l.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);

\n *
\n * @memberof Label.prototype\n * @type {Cartesian3}\n * @default Cartesian3.ZERO\n */\n eyeOffset: {\n get: function () {\n return this._eyeOffset;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const eyeOffset = this._eyeOffset;\n if (!Cartesian3.equals(eyeOffset, value)) {\n Cartesian3.clone(value, eyeOffset);\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.eyeOffset = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.eyeOffset = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets the horizontal origin of this label, which determines if the label is drawn\n * to the left, center, or right of its anchor position.\n *

\n *
\n *
\n *
\n * @memberof Label.prototype\n * @type {HorizontalOrigin}\n * @default HorizontalOrigin.LEFT\n * @example\n * // Use a top, right origin\n * l.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;\n * l.verticalOrigin = Cesium.VerticalOrigin.TOP;\n */\n horizontalOrigin: {\n get: function () {\n return this._horizontalOrigin;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._horizontalOrigin !== value) {\n this._horizontalOrigin = value;\n repositionAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the vertical origin of this label, which determines if the label is\n * to the above, below, or at the center of its anchor position.\n *

\n *
\n *
\n *
\n * @memberof Label.prototype\n * @type {VerticalOrigin}\n * @default VerticalOrigin.BASELINE\n * @example\n * // Use a top, right origin\n * l.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;\n * l.verticalOrigin = Cesium.VerticalOrigin.TOP;\n */\n verticalOrigin: {\n get: function () {\n return this._verticalOrigin;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._verticalOrigin !== value) {\n this._verticalOrigin = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.verticalOrigin = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.verticalOrigin = value;\n }\n\n repositionAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets or sets the uniform scale that is multiplied with the label's size in pixels.\n * A scale of 1.0 does not change the size of the label; a scale greater than\n * 1.0 enlarges the label; a positive scale less than 1.0 shrinks\n * the label.\n *

\n * Applying a large scale value may pixelate the label. To make text larger without pixelation,\n * use a larger font size when calling {@link Label#font} instead.\n *

\n *
\n *
\n * From left to right in the above image, the scales are 0.5, 1.0,\n * and 2.0.\n *
\n * @memberof Label.prototype\n * @type {number}\n * @default 1.0\n */\n scale: {\n get: function () {\n return this._scale;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._scale !== value) {\n this._scale = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.scale = value * this._relativeSize;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.scale = value * this._relativeSize;\n }\n\n repositionAllGlyphs(this);\n }\n },\n },\n\n /**\n * Gets the total scale of the label, which is the label's scale multiplied by the computed relative size\n * of the desired font compared to the generated glyph size.\n * @memberof Label.prototype\n * @type {number}\n * @default 1.0\n */\n totalScale: {\n get: function () {\n return this._scale * this._relativeSize;\n },\n },\n\n /**\n * Gets or sets the condition specifying at what distance from the camera that this label will be displayed.\n * @memberof Label.prototype\n * @type {DistanceDisplayCondition}\n * @default undefined\n */\n distanceDisplayCondition: {\n get: function () {\n return this._distanceDisplayCondition;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\"far must be greater than near\");\n }\n //>>includeEnd('debug');\n if (\n !DistanceDisplayCondition.equals(value, this._distanceDisplayCondition)\n ) {\n this._distanceDisplayCondition = DistanceDisplayCondition.clone(\n value,\n this._distanceDisplayCondition\n );\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.distanceDisplayCondition = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.distanceDisplayCondition = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof Label.prototype\n * @type {number}\n */\n disableDepthTestDistance: {\n get: function () {\n return this._disableDepthTestDistance;\n },\n set: function (value) {\n if (this._disableDepthTestDistance !== value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value < 0.0) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than 0.0.\"\n );\n }\n //>>includeEnd('debug');\n this._disableDepthTestDistance = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.disableDepthTestDistance = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.disableDepthTestDistance = value;\n }\n }\n },\n },\n\n /**\n * Gets or sets the user-defined value returned when the label is picked.\n * @memberof Label.prototype\n * @type {*}\n */\n id: {\n get: function () {\n return this._id;\n },\n set: function (value) {\n if (this._id !== value) {\n this._id = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.id = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.id = value;\n }\n }\n },\n },\n\n /**\n * @private\n */\n pickId: {\n get: function () {\n if (this._glyphs.length === 0 || !defined(this._glyphs[0].billboard)) {\n return undefined;\n }\n return this._glyphs[0].billboard.pickId;\n },\n },\n\n /**\n * Keeps track of the position of the label based on the height reference.\n * @memberof Label.prototype\n * @type {Cartesian3}\n * @private\n */\n _clampedPosition: {\n get: function () {\n return this._actualClampedPosition;\n },\n set: function (value) {\n this._actualClampedPosition = Cartesian3.clone(\n value,\n this._actualClampedPosition\n );\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n // Set all the private values here, because we already clamped to ground\n // so we don't want to do it again for every glyph\n glyph.billboard._clampedPosition = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard._clampedPosition = value;\n }\n },\n },\n\n /**\n * Determines whether or not this label will be shown or hidden because it was clustered.\n * @memberof Label.prototype\n * @type {boolean}\n * @default true\n * @private\n */\n clusterShow: {\n get: function () {\n return this._clusterShow;\n },\n set: function (value) {\n if (this._clusterShow !== value) {\n this._clusterShow = value;\n\n const glyphs = this._glyphs;\n for (let i = 0, len = glyphs.length; i < len; i++) {\n const glyph = glyphs[i];\n if (defined(glyph.billboard)) {\n glyph.billboard.clusterShow = value;\n }\n }\n const backgroundBillboard = this._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n backgroundBillboard.clusterShow = value;\n }\n }\n },\n },\n});\n\nLabel.prototype._updateClamping = function () {\n Billboard._updateClamping(this._labelCollection, this);\n};\n\n/**\n * Computes the screen-space position of the label's origin, taking into account eye and pixel offsets.\n * The screen space origin is the top, left corner of the canvas; x increases from\n * left to right, and y increases from top to bottom.\n *\n * @param {Scene} scene The scene the label is in.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The screen-space position of the label.\n *\n *\n * @example\n * console.log(l.computeScreenSpacePosition(scene).toString());\n *\n * @see Label#eyeOffset\n * @see Label#pixelOffset\n */\nLabel.prototype.computeScreenSpacePosition = function (scene, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian2();\n }\n\n const labelCollection = this._labelCollection;\n const modelMatrix = labelCollection.modelMatrix;\n const actualPosition = defined(this._actualClampedPosition)\n ? this._actualClampedPosition\n : this._position;\n\n const windowCoordinates = Billboard._computeScreenSpacePosition(\n modelMatrix,\n actualPosition,\n this._eyeOffset,\n this._pixelOffset,\n scene,\n result\n );\n return windowCoordinates;\n};\n\n/**\n * Gets a label's screen space bounding box centered around screenSpacePosition.\n * @param {Label} label The label to get the screen space bounding box for.\n * @param {Cartesian2} screenSpacePosition The screen space center of the label.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The screen space bounding box.\n *\n * @private\n */\nLabel.getScreenSpaceBoundingBox = function (\n label,\n screenSpacePosition,\n result\n) {\n let x = 0;\n let y = 0;\n let width = 0;\n let height = 0;\n const scale = label.totalScale;\n\n const backgroundBillboard = label._backgroundBillboard;\n if (defined(backgroundBillboard)) {\n x = screenSpacePosition.x + backgroundBillboard._translate.x;\n y = screenSpacePosition.y - backgroundBillboard._translate.y;\n width = backgroundBillboard.width * scale;\n height = backgroundBillboard.height * scale;\n\n if (\n label.verticalOrigin === VerticalOrigin.BOTTOM ||\n label.verticalOrigin === VerticalOrigin.BASELINE\n ) {\n y -= height;\n } else if (label.verticalOrigin === VerticalOrigin.CENTER) {\n y -= height * 0.5;\n }\n } else {\n x = Number.POSITIVE_INFINITY;\n y = Number.POSITIVE_INFINITY;\n let maxX = 0;\n let maxY = 0;\n const glyphs = label._glyphs;\n const length = glyphs.length;\n for (let i = 0; i < length; ++i) {\n const glyph = glyphs[i];\n const billboard = glyph.billboard;\n if (!defined(billboard)) {\n continue;\n }\n\n const glyphX = screenSpacePosition.x + billboard._translate.x;\n let glyphY = screenSpacePosition.y - billboard._translate.y;\n const glyphWidth = glyph.dimensions.width * scale;\n const glyphHeight = glyph.dimensions.height * scale;\n\n if (\n label.verticalOrigin === VerticalOrigin.BOTTOM ||\n label.verticalOrigin === VerticalOrigin.BASELINE\n ) {\n glyphY -= glyphHeight;\n } else if (label.verticalOrigin === VerticalOrigin.CENTER) {\n glyphY -= glyphHeight * 0.5;\n }\n\n if (label._verticalOrigin === VerticalOrigin.TOP) {\n glyphY += SDFSettings.PADDING * scale;\n } else if (\n label._verticalOrigin === VerticalOrigin.BOTTOM ||\n label._verticalOrigin === VerticalOrigin.BASELINE\n ) {\n glyphY -= SDFSettings.PADDING * scale;\n }\n\n x = Math.min(x, glyphX);\n y = Math.min(y, glyphY);\n maxX = Math.max(maxX, glyphX + glyphWidth);\n maxY = Math.max(maxY, glyphY + glyphHeight);\n }\n\n width = maxX - x;\n height = maxY - y;\n }\n\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n result.x = x;\n result.y = y;\n result.width = width;\n result.height = height;\n\n return result;\n};\n\n/**\n * Determines if this label equals another label. Labels are equal if all their properties\n * are equal. Labels in different collections can be equal.\n *\n * @param {Label} other The label to compare for equality.\n * @returns {boolean} true if the labels are equal; otherwise, false.\n */\nLabel.prototype.equals = function (other) {\n return (\n this === other ||\n (defined(other) &&\n this._show === other._show &&\n this._scale === other._scale &&\n this._outlineWidth === other._outlineWidth &&\n this._showBackground === other._showBackground &&\n this._style === other._style &&\n this._verticalOrigin === other._verticalOrigin &&\n this._horizontalOrigin === other._horizontalOrigin &&\n this._heightReference === other._heightReference &&\n this._renderedText === other._renderedText &&\n this._font === other._font &&\n Cartesian3.equals(this._position, other._position) &&\n Color.equals(this._fillColor, other._fillColor) &&\n Color.equals(this._outlineColor, other._outlineColor) &&\n Color.equals(this._backgroundColor, other._backgroundColor) &&\n Cartesian2.equals(this._backgroundPadding, other._backgroundPadding) &&\n Cartesian2.equals(this._pixelOffset, other._pixelOffset) &&\n Cartesian3.equals(this._eyeOffset, other._eyeOffset) &&\n NearFarScalar.equals(\n this._translucencyByDistance,\n other._translucencyByDistance\n ) &&\n NearFarScalar.equals(\n this._pixelOffsetScaleByDistance,\n other._pixelOffsetScaleByDistance\n ) &&\n NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&\n DistanceDisplayCondition.equals(\n this._distanceDisplayCondition,\n other._distanceDisplayCondition\n ) &&\n this._disableDepthTestDistance === other._disableDepthTestDistance &&\n this._id === other._id)\n );\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nLabel.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Determines whether or not run the algorithm, that match the text of the label to right-to-left languages\n * @memberof Label\n * @type {boolean}\n * @default false\n *\n * @example\n * // Example 1.\n * // Set a label's rightToLeft before init\n * Cesium.Label.enableRightToLeftDetection = true;\n * const myLabelEntity = viewer.entities.add({\n * label: {\n * id: 'my label',\n * text: '\u05D6\u05D4 \u05D8\u05E7\u05E1\u05D8 \u05D1\u05E2\u05D1\u05E8\u05D9\u05EA \\n \u05D5\u05E2\u05DB\u05E9\u05D9\u05D5 \u05D9\u05D5\u05E8\u05D3\u05D9\u05DD \u05E9\u05D5\u05E8\u05D4',\n * }\n * });\n *\n * @example\n * // Example 2.\n * const myLabelEntity = viewer.entities.add({\n * label: {\n * id: 'my label',\n * text: 'English text'\n * }\n * });\n * // Set a label's rightToLeft after init\n * Cesium.Label.enableRightToLeftDetection = true;\n * myLabelEntity.text = '\u05D8\u05E7\u05E1\u05D8 \u05D7\u05D3\u05E9';\n */\nLabel.enableRightToLeftDetection = false;\n\nfunction convertTextToTypes(text, rtlChars) {\n const ltrChars = /[a-zA-Z0-9]/;\n const bracketsChars = /[()[\\]{}<>]/;\n const parsedText = [];\n let word = \"\";\n let lastType = textTypes.LTR;\n let currentType = \"\";\n const textLength = text.length;\n for (let textIndex = 0; textIndex < textLength; ++textIndex) {\n const character = text.charAt(textIndex);\n if (rtlChars.test(character)) {\n currentType = textTypes.RTL;\n } else if (ltrChars.test(character)) {\n currentType = textTypes.LTR;\n } else if (bracketsChars.test(character)) {\n currentType = textTypes.BRACKETS;\n } else {\n currentType = textTypes.WEAK;\n }\n\n if (textIndex === 0) {\n lastType = currentType;\n }\n\n if (lastType === currentType && currentType !== textTypes.BRACKETS) {\n word += character;\n } else {\n if (word !== \"\") {\n parsedText.push({ Type: lastType, Word: word });\n }\n lastType = currentType;\n word = character;\n }\n }\n parsedText.push({ Type: currentType, Word: word });\n return parsedText;\n}\n\nfunction reverseWord(word) {\n return word.split(\"\").reverse().join(\"\");\n}\n\nfunction spliceWord(result, pointer, word) {\n return result.slice(0, pointer) + word + result.slice(pointer);\n}\n\nfunction reverseBrackets(bracket) {\n switch (bracket) {\n case \"(\":\n return \")\";\n case \")\":\n return \"(\";\n case \"[\":\n return \"]\";\n case \"]\":\n return \"[\";\n case \"{\":\n return \"}\";\n case \"}\":\n return \"{\";\n case \"<\":\n return \">\";\n case \">\":\n return \"<\";\n }\n}\n\n//To add another language, simply add its Unicode block range(s) to the below regex.\nconst hebrew = \"\\u05D0-\\u05EA\";\nconst arabic = \"\\u0600-\\u06FF\\u0750-\\u077F\\u08A0-\\u08FF\";\nconst rtlChars = new RegExp(`[${hebrew}${arabic}]`);\n\n/**\n *\n * @param {string} value the text to parse and reorder\n * @returns {string} the text as rightToLeft direction\n * @private\n */\nfunction reverseRtl(value) {\n const texts = value.split(\"\\n\");\n let result = \"\";\n for (let i = 0; i < texts.length; i++) {\n const text = texts[i];\n // first character of the line is a RTL character, so need to manage different cases\n const rtlDir = rtlChars.test(text.charAt(0));\n const parsedText = convertTextToTypes(text, rtlChars);\n\n let splicePointer = 0;\n let line = \"\";\n for (let wordIndex = 0; wordIndex < parsedText.length; ++wordIndex) {\n const subText = parsedText[wordIndex];\n const reverse =\n subText.Type === textTypes.BRACKETS\n ? reverseBrackets(subText.Word)\n : reverseWord(subText.Word);\n if (rtlDir) {\n if (subText.Type === textTypes.RTL) {\n line = reverse + line;\n splicePointer = 0;\n } else if (subText.Type === textTypes.LTR) {\n line = spliceWord(line, splicePointer, subText.Word);\n splicePointer += subText.Word.length;\n } else if (\n subText.Type === textTypes.WEAK ||\n subText.Type === textTypes.BRACKETS\n ) {\n // current word is weak, last one was bracket\n if (\n subText.Type === textTypes.WEAK &&\n parsedText[wordIndex - 1].Type === textTypes.BRACKETS\n ) {\n line = reverse + line;\n }\n // current word is weak or bracket, last one was rtl\n else if (parsedText[wordIndex - 1].Type === textTypes.RTL) {\n line = reverse + line;\n splicePointer = 0;\n }\n // current word is weak or bracket, there is at least one more word\n else if (parsedText.length > wordIndex + 1) {\n // next word is rtl\n if (parsedText[wordIndex + 1].Type === textTypes.RTL) {\n line = reverse + line;\n splicePointer = 0;\n } else {\n line = spliceWord(line, splicePointer, subText.Word);\n splicePointer += subText.Word.length;\n }\n }\n // current word is weak or bracket, and it the last in this line\n else {\n line = spliceWord(line, 0, reverse);\n }\n }\n }\n // ltr line, rtl word\n else if (subText.Type === textTypes.RTL) {\n line = spliceWord(line, splicePointer, reverse);\n }\n // ltr line, ltr word\n else if (subText.Type === textTypes.LTR) {\n line += subText.Word;\n splicePointer = line.length;\n }\n // ltr line, weak or bracket word\n else if (\n subText.Type === textTypes.WEAK ||\n subText.Type === textTypes.BRACKETS\n ) {\n // not first word in line\n if (wordIndex > 0) {\n // last word was rtl\n if (parsedText[wordIndex - 1].Type === textTypes.RTL) {\n // there is at least one more word\n if (parsedText.length > wordIndex + 1) {\n // next word is rtl\n if (parsedText[wordIndex + 1].Type === textTypes.RTL) {\n line = spliceWord(line, splicePointer, reverse);\n } else {\n line += subText.Word;\n splicePointer = line.length;\n }\n } else {\n line += subText.Word;\n }\n } else {\n line += subText.Word;\n splicePointer = line.length;\n }\n } else {\n line += subText.Word;\n splicePointer = line.length;\n }\n }\n }\n\n result += line;\n if (i < texts.length - 1) {\n result += \"\\n\";\n }\n }\n return result;\n}\nexport default Label;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 position3DHigh;\\n\\\nin vec3 position3DLow;\\n\\\nin vec3 position2DHigh;\\n\\\nin vec3 position2DLow;\\n\\\nin vec3 prevPosition3DHigh;\\n\\\nin vec3 prevPosition3DLow;\\n\\\nin vec3 prevPosition2DHigh;\\n\\\nin vec3 prevPosition2DLow;\\n\\\nin vec3 nextPosition3DHigh;\\n\\\nin vec3 nextPosition3DLow;\\n\\\nin vec3 nextPosition2DHigh;\\n\\\nin vec3 nextPosition2DLow;\\n\\\nin vec4 texCoordExpandAndBatchIndex;\\n\\\n\\n\\\nout vec2 v_st;\\n\\\nout float v_width;\\n\\\nout vec4 v_pickColor;\\n\\\nout float v_polylineAngle;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n float texCoord = texCoordExpandAndBatchIndex.x;\\n\\\n float expandDir = texCoordExpandAndBatchIndex.y;\\n\\\n bool usePrev = texCoordExpandAndBatchIndex.z < 0.0;\\n\\\n float batchTableIndex = texCoordExpandAndBatchIndex.w;\\n\\\n\\n\\\n vec2 widthAndShow = batchTable_getWidthAndShow(batchTableIndex);\\n\\\n float width = widthAndShow.x + 0.5;\\n\\\n float show = widthAndShow.y;\\n\\\n\\n\\\n if (width < 1.0)\\n\\\n {\\n\\\n show = 0.0;\\n\\\n }\\n\\\n\\n\\\n vec4 pickColor = batchTable_getPickColor(batchTableIndex);\\n\\\n\\n\\\n vec4 p, prev, next;\\n\\\n if (czm_morphTime == 1.0)\\n\\\n {\\n\\\n p = czm_translateRelativeToEye(position3DHigh.xyz, position3DLow.xyz);\\n\\\n prev = czm_translateRelativeToEye(prevPosition3DHigh.xyz, prevPosition3DLow.xyz);\\n\\\n next = czm_translateRelativeToEye(nextPosition3DHigh.xyz, nextPosition3DLow.xyz);\\n\\\n }\\n\\\n else if (czm_morphTime == 0.0)\\n\\\n {\\n\\\n p = czm_translateRelativeToEye(position2DHigh.zxy, position2DLow.zxy);\\n\\\n prev = czm_translateRelativeToEye(prevPosition2DHigh.zxy, prevPosition2DLow.zxy);\\n\\\n next = czm_translateRelativeToEye(nextPosition2DHigh.zxy, nextPosition2DLow.zxy);\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n p = czm_columbusViewMorph(\\n\\\n czm_translateRelativeToEye(position2DHigh.zxy, position2DLow.zxy),\\n\\\n czm_translateRelativeToEye(position3DHigh.xyz, position3DLow.xyz),\\n\\\n czm_morphTime);\\n\\\n prev = czm_columbusViewMorph(\\n\\\n czm_translateRelativeToEye(prevPosition2DHigh.zxy, prevPosition2DLow.zxy),\\n\\\n czm_translateRelativeToEye(prevPosition3DHigh.xyz, prevPosition3DLow.xyz),\\n\\\n czm_morphTime);\\n\\\n next = czm_columbusViewMorph(\\n\\\n czm_translateRelativeToEye(nextPosition2DHigh.zxy, nextPosition2DLow.zxy),\\n\\\n czm_translateRelativeToEye(nextPosition3DHigh.xyz, nextPosition3DLow.xyz),\\n\\\n czm_morphTime);\\n\\\n }\\n\\\n\\n\\\n #ifdef DISTANCE_DISPLAY_CONDITION\\n\\\n vec3 centerHigh = batchTable_getCenterHigh(batchTableIndex);\\n\\\n vec4 centerLowAndRadius = batchTable_getCenterLowAndRadius(batchTableIndex);\\n\\\n vec3 centerLow = centerLowAndRadius.xyz;\\n\\\n float radius = centerLowAndRadius.w;\\n\\\n vec2 distanceDisplayCondition = batchTable_getDistanceDisplayCondition(batchTableIndex);\\n\\\n\\n\\\n float lengthSq;\\n\\\n if (czm_sceneMode == czm_sceneMode2D)\\n\\\n {\\n\\\n lengthSq = czm_eyeHeight2D.y;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n vec4 center = czm_translateRelativeToEye(centerHigh.xyz, centerLow.xyz);\\n\\\n lengthSq = max(0.0, dot(center.xyz, center.xyz) - radius * radius);\\n\\\n }\\n\\\n\\n\\\n float nearSq = distanceDisplayCondition.x * distanceDisplayCondition.x;\\n\\\n float farSq = distanceDisplayCondition.y * distanceDisplayCondition.y;\\n\\\n if (lengthSq < nearSq || lengthSq > farSq)\\n\\\n {\\n\\\n show = 0.0;\\n\\\n }\\n\\\n #endif\\n\\\n\\n\\\n float polylineAngle;\\n\\\n vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, polylineAngle);\\n\\\n gl_Position = czm_viewportOrthographic * positionWC * show;\\n\\\n\\n\\\n v_st.s = texCoord;\\n\\\n v_st.t = czm_writeNonPerspective(clamp(expandDir, 0.0, 1.0), gl_Position.w);\\n\\\n\\n\\\n v_width = width;\\n\\\n v_pickColor = pickColor;\\n\\\n v_polylineAngle = polylineAngle;\\n\\\n}\\n\\\n\";\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidGeodesic from \"./EllipsoidGeodesic.js\";\nimport EllipsoidRhumbLine from \"./EllipsoidRhumbLine.js\";\nimport IntersectionTests from \"./IntersectionTests.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport Plane from \"./Plane.js\";\n\n/**\n * @private\n */\nconst PolylinePipeline = {};\n\nPolylinePipeline.numberOfPoints = function (p0, p1, minDistance) {\n const distance = Cartesian3.distance(p0, p1);\n return Math.ceil(distance / minDistance);\n};\n\nPolylinePipeline.numberOfPointsRhumbLine = function (p0, p1, granularity) {\n const radiansDistanceSquared =\n Math.pow(p0.longitude - p1.longitude, 2) +\n Math.pow(p0.latitude - p1.latitude, 2);\n\n return Math.max(\n 1,\n Math.ceil(Math.sqrt(radiansDistanceSquared / (granularity * granularity)))\n );\n};\n\nconst cartoScratch = new Cartographic();\nPolylinePipeline.extractHeights = function (positions, ellipsoid) {\n const length = positions.length;\n const heights = new Array(length);\n for (let i = 0; i < length; i++) {\n const p = positions[i];\n heights[i] = ellipsoid.cartesianToCartographic(p, cartoScratch).height;\n }\n return heights;\n};\n\nconst wrapLongitudeInversMatrix = new Matrix4();\nconst wrapLongitudeOrigin = new Cartesian3();\nconst wrapLongitudeXZNormal = new Cartesian3();\nconst wrapLongitudeXZPlane = new Plane(Cartesian3.UNIT_X, 0.0);\nconst wrapLongitudeYZNormal = new Cartesian3();\nconst wrapLongitudeYZPlane = new Plane(Cartesian3.UNIT_X, 0.0);\nconst wrapLongitudeIntersection = new Cartesian3();\nconst wrapLongitudeOffset = new Cartesian3();\n\nconst subdivideHeightsScratchArray = [];\n\nfunction subdivideHeights(numPoints, h0, h1) {\n const heights = subdivideHeightsScratchArray;\n heights.length = numPoints;\n\n let i;\n if (h0 === h1) {\n for (i = 0; i < numPoints; i++) {\n heights[i] = h0;\n }\n return heights;\n }\n\n const dHeight = h1 - h0;\n const heightPerVertex = dHeight / numPoints;\n\n for (i = 0; i < numPoints; i++) {\n const h = h0 + i * heightPerVertex;\n heights[i] = h;\n }\n\n return heights;\n}\n\nconst carto1 = new Cartographic();\nconst carto2 = new Cartographic();\nconst cartesian = new Cartesian3();\nconst scaleFirst = new Cartesian3();\nconst scaleLast = new Cartesian3();\nconst ellipsoidGeodesic = new EllipsoidGeodesic();\nlet ellipsoidRhumb = new EllipsoidRhumbLine();\n\n//Returns subdivided line scaled to ellipsoid surface starting at p1 and ending at p2.\n//Result includes p1, but not include p2. This function is called for a sequence of line segments,\n//and this prevents duplication of end point.\nfunction generateCartesianArc(\n p0,\n p1,\n minDistance,\n ellipsoid,\n h0,\n h1,\n array,\n offset\n) {\n const first = ellipsoid.scaleToGeodeticSurface(p0, scaleFirst);\n const last = ellipsoid.scaleToGeodeticSurface(p1, scaleLast);\n const numPoints = PolylinePipeline.numberOfPoints(p0, p1, minDistance);\n const start = ellipsoid.cartesianToCartographic(first, carto1);\n const end = ellipsoid.cartesianToCartographic(last, carto2);\n const heights = subdivideHeights(numPoints, h0, h1);\n\n ellipsoidGeodesic.setEndPoints(start, end);\n const surfaceDistanceBetweenPoints =\n ellipsoidGeodesic.surfaceDistance / numPoints;\n\n let index = offset;\n start.height = h0;\n let cart = ellipsoid.cartographicToCartesian(start, cartesian);\n Cartesian3.pack(cart, array, index);\n index += 3;\n\n for (let i = 1; i < numPoints; i++) {\n const carto = ellipsoidGeodesic.interpolateUsingSurfaceDistance(\n i * surfaceDistanceBetweenPoints,\n carto2\n );\n carto.height = heights[i];\n cart = ellipsoid.cartographicToCartesian(carto, cartesian);\n Cartesian3.pack(cart, array, index);\n index += 3;\n }\n\n return index;\n}\n\n//Returns subdivided line scaled to ellipsoid surface starting at p1 and ending at p2.\n//Result includes p1, but not include p2. This function is called for a sequence of line segments,\n//and this prevents duplication of end point.\nfunction generateCartesianRhumbArc(\n p0,\n p1,\n granularity,\n ellipsoid,\n h0,\n h1,\n array,\n offset\n) {\n const start = ellipsoid.cartesianToCartographic(p0, carto1);\n const end = ellipsoid.cartesianToCartographic(p1, carto2);\n const numPoints = PolylinePipeline.numberOfPointsRhumbLine(\n start,\n end,\n granularity\n );\n start.height = 0.0;\n end.height = 0.0;\n const heights = subdivideHeights(numPoints, h0, h1);\n\n if (!ellipsoidRhumb.ellipsoid.equals(ellipsoid)) {\n ellipsoidRhumb = new EllipsoidRhumbLine(undefined, undefined, ellipsoid);\n }\n ellipsoidRhumb.setEndPoints(start, end);\n const surfaceDistanceBetweenPoints =\n ellipsoidRhumb.surfaceDistance / numPoints;\n\n let index = offset;\n start.height = h0;\n let cart = ellipsoid.cartographicToCartesian(start, cartesian);\n Cartesian3.pack(cart, array, index);\n index += 3;\n\n for (let i = 1; i < numPoints; i++) {\n const carto = ellipsoidRhumb.interpolateUsingSurfaceDistance(\n i * surfaceDistanceBetweenPoints,\n carto2\n );\n carto.height = heights[i];\n cart = ellipsoid.cartographicToCartesian(carto, cartesian);\n Cartesian3.pack(cart, array, index);\n index += 3;\n }\n\n return index;\n}\n\n/**\n * Breaks a {@link Polyline} into segments such that it does not cross the ±180 degree meridian of an ellipsoid.\n *\n * @param {Cartesian3[]} positions The polyline's Cartesian positions.\n * @param {Matrix4} [modelMatrix=Matrix4.IDENTITY] The polyline's model matrix. Assumed to be an affine\n * transformation matrix, where the upper left 3x3 elements are a rotation matrix, and\n * the upper three elements in the fourth column are the translation. The bottom row is assumed to be [0, 0, 0, 1].\n * The matrix is not verified to be in the proper form.\n * @returns {object} An object with a positions property that is an array of positions and a\n * segments property.\n *\n *\n * @example\n * const polylines = new Cesium.PolylineCollection();\n * const polyline = polylines.add(...);\n * const positions = polyline.positions;\n * const modelMatrix = polylines.modelMatrix;\n * const segments = Cesium.PolylinePipeline.wrapLongitude(positions, modelMatrix);\n *\n * @see PolygonPipeline.wrapLongitude\n * @see Polyline\n * @see PolylineCollection\n */\nPolylinePipeline.wrapLongitude = function (positions, modelMatrix) {\n const cartesians = [];\n const segments = [];\n\n if (defined(positions) && positions.length > 0) {\n modelMatrix = defaultValue(modelMatrix, Matrix4.IDENTITY);\n const inverseModelMatrix = Matrix4.inverseTransformation(\n modelMatrix,\n wrapLongitudeInversMatrix\n );\n\n const origin = Matrix4.multiplyByPoint(\n inverseModelMatrix,\n Cartesian3.ZERO,\n wrapLongitudeOrigin\n );\n const xzNormal = Cartesian3.normalize(\n Matrix4.multiplyByPointAsVector(\n inverseModelMatrix,\n Cartesian3.UNIT_Y,\n wrapLongitudeXZNormal\n ),\n wrapLongitudeXZNormal\n );\n const xzPlane = Plane.fromPointNormal(\n origin,\n xzNormal,\n wrapLongitudeXZPlane\n );\n const yzNormal = Cartesian3.normalize(\n Matrix4.multiplyByPointAsVector(\n inverseModelMatrix,\n Cartesian3.UNIT_X,\n wrapLongitudeYZNormal\n ),\n wrapLongitudeYZNormal\n );\n const yzPlane = Plane.fromPointNormal(\n origin,\n yzNormal,\n wrapLongitudeYZPlane\n );\n\n let count = 1;\n cartesians.push(Cartesian3.clone(positions[0]));\n let prev = cartesians[0];\n\n const length = positions.length;\n for (let i = 1; i < length; ++i) {\n const cur = positions[i];\n\n // intersects the IDL if either endpoint is on the negative side of the yz-plane\n if (\n Plane.getPointDistance(yzPlane, prev) < 0.0 ||\n Plane.getPointDistance(yzPlane, cur) < 0.0\n ) {\n // and intersects the xz-plane\n const intersection = IntersectionTests.lineSegmentPlane(\n prev,\n cur,\n xzPlane,\n wrapLongitudeIntersection\n );\n if (defined(intersection)) {\n // move point on the xz-plane slightly away from the plane\n const offset = Cartesian3.multiplyByScalar(\n xzNormal,\n 5.0e-9,\n wrapLongitudeOffset\n );\n if (Plane.getPointDistance(xzPlane, prev) < 0.0) {\n Cartesian3.negate(offset, offset);\n }\n\n cartesians.push(\n Cartesian3.add(intersection, offset, new Cartesian3())\n );\n segments.push(count + 1);\n\n Cartesian3.negate(offset, offset);\n cartesians.push(\n Cartesian3.add(intersection, offset, new Cartesian3())\n );\n count = 1;\n }\n }\n\n cartesians.push(Cartesian3.clone(positions[i]));\n count++;\n\n prev = cur;\n }\n\n segments.push(count);\n }\n\n return {\n positions: cartesians,\n lengths: segments,\n };\n};\n\n/**\n * Subdivides polyline and raises all points to the specified height. Returns an array of numbers to represent the positions.\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions.\n * @param {number|number[]} [options.height=0.0] A number or array of numbers representing the heights of each position.\n * @param {number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.\n * @returns {number[]} A new array of positions of type {number} that have been subdivided and raised to the surface of the ellipsoid.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 40.0,\n * -100.0, 38.0,\n * -105.0, 35.0,\n * -100.0, 32.0\n * ]);\n * const surfacePositions = Cesium.PolylinePipeline.generateArc({\n * positons: positions\n * });\n */\nPolylinePipeline.generateArc = function (options) {\n if (!defined(options)) {\n options = {};\n }\n const positions = options.positions;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n //>>includeEnd('debug');\n\n const length = positions.length;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n let height = defaultValue(options.height, 0);\n const hasHeightArray = Array.isArray(height);\n\n if (length < 1) {\n return [];\n } else if (length === 1) {\n const p = ellipsoid.scaleToGeodeticSurface(positions[0], scaleFirst);\n height = hasHeightArray ? height[0] : height;\n if (height !== 0) {\n const n = ellipsoid.geodeticSurfaceNormal(p, cartesian);\n Cartesian3.multiplyByScalar(n, height, n);\n Cartesian3.add(p, n, p);\n }\n\n return [p.x, p.y, p.z];\n }\n\n let minDistance = options.minDistance;\n if (!defined(minDistance)) {\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);\n }\n\n let numPoints = 0;\n let i;\n\n for (i = 0; i < length - 1; i++) {\n numPoints += PolylinePipeline.numberOfPoints(\n positions[i],\n positions[i + 1],\n minDistance\n );\n }\n\n const arrayLength = (numPoints + 1) * 3;\n const newPositions = new Array(arrayLength);\n let offset = 0;\n\n for (i = 0; i < length - 1; i++) {\n const p0 = positions[i];\n const p1 = positions[i + 1];\n\n const h0 = hasHeightArray ? height[i] : height;\n const h1 = hasHeightArray ? height[i + 1] : height;\n\n offset = generateCartesianArc(\n p0,\n p1,\n minDistance,\n ellipsoid,\n h0,\n h1,\n newPositions,\n offset\n );\n }\n\n subdivideHeightsScratchArray.length = 0;\n\n const lastPoint = positions[length - 1];\n const carto = ellipsoid.cartesianToCartographic(lastPoint, carto1);\n carto.height = hasHeightArray ? height[length - 1] : height;\n const cart = ellipsoid.cartographicToCartesian(carto, cartesian);\n Cartesian3.pack(cart, newPositions, arrayLength - 3);\n\n return newPositions;\n};\n\nconst scratchCartographic0 = new Cartographic();\nconst scratchCartographic1 = new Cartographic();\n\n/**\n * Subdivides polyline and raises all points to the specified height using Rhumb lines. Returns an array of numbers to represent the positions.\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions.\n * @param {number|number[]} [options.height=0.0] A number or array of numbers representing the heights of each position.\n * @param {number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.\n * @returns {number[]} A new array of positions of type {number} that have been subdivided and raised to the surface of the ellipsoid.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 40.0,\n * -100.0, 38.0,\n * -105.0, 35.0,\n * -100.0, 32.0\n * ]);\n * const surfacePositions = Cesium.PolylinePipeline.generateRhumbArc({\n * positons: positions\n * });\n */\nPolylinePipeline.generateRhumbArc = function (options) {\n if (!defined(options)) {\n options = {};\n }\n const positions = options.positions;\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n //>>includeEnd('debug');\n\n const length = positions.length;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n let height = defaultValue(options.height, 0);\n const hasHeightArray = Array.isArray(height);\n\n if (length < 1) {\n return [];\n } else if (length === 1) {\n const p = ellipsoid.scaleToGeodeticSurface(positions[0], scaleFirst);\n height = hasHeightArray ? height[0] : height;\n if (height !== 0) {\n const n = ellipsoid.geodeticSurfaceNormal(p, cartesian);\n Cartesian3.multiplyByScalar(n, height, n);\n Cartesian3.add(p, n, p);\n }\n\n return [p.x, p.y, p.z];\n }\n\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n\n let numPoints = 0;\n let i;\n\n let c0 = ellipsoid.cartesianToCartographic(\n positions[0],\n scratchCartographic0\n );\n let c1;\n for (i = 0; i < length - 1; i++) {\n c1 = ellipsoid.cartesianToCartographic(\n positions[i + 1],\n scratchCartographic1\n );\n numPoints += PolylinePipeline.numberOfPointsRhumbLine(c0, c1, granularity);\n c0 = Cartographic.clone(c1, scratchCartographic0);\n }\n\n const arrayLength = (numPoints + 1) * 3;\n const newPositions = new Array(arrayLength);\n let offset = 0;\n\n for (i = 0; i < length - 1; i++) {\n const p0 = positions[i];\n const p1 = positions[i + 1];\n\n const h0 = hasHeightArray ? height[i] : height;\n const h1 = hasHeightArray ? height[i + 1] : height;\n\n offset = generateCartesianRhumbArc(\n p0,\n p1,\n granularity,\n ellipsoid,\n h0,\n h1,\n newPositions,\n offset\n );\n }\n\n subdivideHeightsScratchArray.length = 0;\n\n const lastPoint = positions[length - 1];\n const carto = ellipsoid.cartesianToCartographic(lastPoint, carto1);\n carto.height = hasHeightArray ? height[length - 1] : height;\n const cart = ellipsoid.cartographicToCartesian(carto, cartesian);\n Cartesian3.pack(cart, newPositions, arrayLength - 3);\n\n return newPositions;\n};\n\n/**\n * Subdivides polyline and raises all points to the specified height. Returns an array of new {Cartesian3} positions.\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions.\n * @param {number|number[]} [options.height=0.0] A number or array of numbers representing the heights of each position.\n * @param {number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.\n * @returns {Cartesian3[]} A new array of cartesian3 positions that have been subdivided and raised to the surface of the ellipsoid.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 40.0,\n * -100.0, 38.0,\n * -105.0, 35.0,\n * -100.0, 32.0\n * ]);\n * const surfacePositions = Cesium.PolylinePipeline.generateCartesianArc({\n * positons: positions\n * });\n */\nPolylinePipeline.generateCartesianArc = function (options) {\n const numberArray = PolylinePipeline.generateArc(options);\n const size = numberArray.length / 3;\n const newPositions = new Array(size);\n for (let i = 0; i < size; i++) {\n newPositions[i] = Cartesian3.unpack(numberArray, i * 3);\n }\n return newPositions;\n};\n\n/**\n * Subdivides polyline and raises all points to the specified height using Rhumb Lines. Returns an array of new {Cartesian3} positions.\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions.\n * @param {number|number[]} [options.height=0.0] A number or array of numbers representing the heights of each position.\n * @param {number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.\n * @returns {Cartesian3[]} A new array of cartesian3 positions that have been subdivided and raised to the surface of the ellipsoid.\n *\n * @example\n * const positions = Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 40.0,\n * -100.0, 38.0,\n * -105.0, 35.0,\n * -100.0, 32.0\n * ]);\n * const surfacePositions = Cesium.PolylinePipeline.generateCartesianRhumbArc({\n * positons: positions\n * });\n */\nPolylinePipeline.generateCartesianRhumbArc = function (options) {\n const numberArray = PolylinePipeline.generateRhumbArc(options);\n const size = numberArray.length / 3;\n const newPositions = new Array(size);\n for (let i = 0; i < size; i++) {\n newPositions[i] = Cartesian3.unpack(numberArray, i * 3);\n }\n return newPositions;\n};\nexport default PolylinePipeline;\n", "import arrayRemoveDuplicates from \"../Core/arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PolylinePipeline from \"../Core/PolylinePipeline.js\";\nimport Material from \"./Material.js\";\n\n/**\n *
\n * Create this by calling {@link PolylineCollection#add}. Do not call the constructor directly.\n *
\n *\n * A renderable polyline.\n *\n * @alias Polyline\n * @internalConstructor\n * @class\n *\n * @privateParam {object} options Object with the following properties:\n * @privateParam {boolean} [options.show=true] true if this polyline will be shown; otherwise, false.\n * @privateParam {number} [options.width=1.0] The width of the polyline in pixels.\n * @privateParam {boolean} [options.loop=false] Whether a line segment will be added between the last and first line positions to make this line a loop.\n * @privateParam {Material} [options.material=Material.ColorType] The material.\n * @privateParam {Cartesian3[]} [options.positions] The positions.\n * @privateParam {object} [options.id] The user-defined object to be returned when this polyline is picked.\n * @privateParam {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this polyline will be displayed.\n * @privateParam {PolylineCollection} polylineCollection The renderable polyline collection.\n *\n * @see PolylineCollection\n *\n */\nfunction Polyline(options, polylineCollection) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._show = defaultValue(options.show, true);\n this._width = defaultValue(options.width, 1.0);\n this._loop = defaultValue(options.loop, false);\n this._distanceDisplayCondition = options.distanceDisplayCondition;\n\n this._material = options.material;\n if (!defined(this._material)) {\n this._material = Material.fromType(Material.ColorType, {\n color: new Color(1.0, 1.0, 1.0, 1.0),\n });\n }\n\n let positions = options.positions;\n if (!defined(positions)) {\n positions = [];\n }\n\n this._positions = positions;\n this._actualPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n\n if (this._loop && this._actualPositions.length > 2) {\n if (this._actualPositions === this._positions) {\n this._actualPositions = positions.slice();\n }\n this._actualPositions.push(Cartesian3.clone(this._actualPositions[0]));\n }\n\n this._length = this._actualPositions.length;\n this._id = options.id;\n\n let modelMatrix;\n if (defined(polylineCollection)) {\n modelMatrix = Matrix4.clone(polylineCollection.modelMatrix);\n }\n\n this._modelMatrix = modelMatrix;\n this._segments = PolylinePipeline.wrapLongitude(\n this._actualPositions,\n modelMatrix\n );\n\n this._actualLength = undefined;\n\n // eslint-disable-next-line no-use-before-define\n this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);\n this._polylineCollection = polylineCollection;\n this._dirty = false;\n this._pickId = undefined;\n this._boundingVolume = BoundingSphere.fromPoints(this._actualPositions);\n this._boundingVolumeWC = BoundingSphere.transform(\n this._boundingVolume,\n this._modelMatrix\n );\n this._boundingVolume2D = new BoundingSphere(); // modified in PolylineCollection\n}\n\nconst POSITION_INDEX = (Polyline.POSITION_INDEX = 0);\nconst SHOW_INDEX = (Polyline.SHOW_INDEX = 1);\nconst WIDTH_INDEX = (Polyline.WIDTH_INDEX = 2);\nconst MATERIAL_INDEX = (Polyline.MATERIAL_INDEX = 3);\nconst POSITION_SIZE_INDEX = (Polyline.POSITION_SIZE_INDEX = 4);\nconst DISTANCE_DISPLAY_CONDITION = (Polyline.DISTANCE_DISPLAY_CONDITION = 5);\nconst NUMBER_OF_PROPERTIES = (Polyline.NUMBER_OF_PROPERTIES = 6);\n\nfunction makeDirty(polyline, propertyChanged) {\n ++polyline._propertiesChanged[propertyChanged];\n const polylineCollection = polyline._polylineCollection;\n if (defined(polylineCollection)) {\n polylineCollection._updatePolyline(polyline, propertyChanged);\n polyline._dirty = true;\n }\n}\n\nObject.defineProperties(Polyline.prototype, {\n /**\n * Determines if this polyline will be shown. Use this to hide or show a polyline, instead\n * of removing it and re-adding it to the collection.\n * @memberof Polyline.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (value !== this._show) {\n this._show = value;\n makeDirty(this, SHOW_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the positions of the polyline.\n * @memberof Polyline.prototype\n * @type {Cartesian3[]}\n * @example\n * polyline.positions = Cesium.Cartesian3.fromDegreesArray([\n * 0.0, 0.0,\n * 10.0, 0.0,\n * 0.0, 20.0\n * ]);\n */\n positions: {\n get: function () {\n return this._positions;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n let positions = arrayRemoveDuplicates(value, Cartesian3.equalsEpsilon);\n\n if (this._loop && positions.length > 2) {\n if (positions === value) {\n positions = value.slice();\n }\n positions.push(Cartesian3.clone(positions[0]));\n }\n\n if (\n this._actualPositions.length !== positions.length ||\n this._actualPositions.length !== this._length\n ) {\n makeDirty(this, POSITION_SIZE_INDEX);\n }\n\n this._positions = value;\n this._actualPositions = positions;\n this._length = positions.length;\n this._boundingVolume = BoundingSphere.fromPoints(\n this._actualPositions,\n this._boundingVolume\n );\n this._boundingVolumeWC = BoundingSphere.transform(\n this._boundingVolume,\n this._modelMatrix,\n this._boundingVolumeWC\n );\n makeDirty(this, POSITION_INDEX);\n\n this.update();\n },\n },\n\n /**\n * Gets or sets the surface appearance of the polyline. This can be one of several built-in {@link Material} objects or a custom material, scripted with\n * {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}.\n * @memberof Polyline.prototype\n * @type {Material}\n */\n material: {\n get: function () {\n return this._material;\n },\n set: function (material) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(material)) {\n throw new DeveloperError(\"material is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._material !== material) {\n this._material = material;\n makeDirty(this, MATERIAL_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the width of the polyline.\n * @memberof Polyline.prototype\n * @type {number}\n */\n width: {\n get: function () {\n return this._width;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug)\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const width = this._width;\n if (value !== width) {\n this._width = value;\n makeDirty(this, WIDTH_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets whether a line segment will be added between the first and last polyline positions.\n * @memberof Polyline.prototype\n * @type {boolean}\n */\n loop: {\n get: function () {\n return this._loop;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug)\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (value !== this._loop) {\n let positions = this._actualPositions;\n if (value) {\n if (\n positions.length > 2 &&\n !Cartesian3.equals(positions[0], positions[positions.length - 1])\n ) {\n if (positions.length === this._positions.length) {\n this._actualPositions = positions = this._positions.slice();\n }\n positions.push(Cartesian3.clone(positions[0]));\n }\n } else if (\n positions.length > 2 &&\n Cartesian3.equals(positions[0], positions[positions.length - 1])\n ) {\n if (positions.length - 1 === this._positions.length) {\n this._actualPositions = this._positions;\n } else {\n positions.pop();\n }\n }\n\n this._loop = value;\n makeDirty(this, POSITION_SIZE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the user-defined value returned when the polyline is picked.\n * @memberof Polyline.prototype\n * @type {*}\n */\n id: {\n get: function () {\n return this._id;\n },\n set: function (value) {\n this._id = value;\n if (defined(this._pickId)) {\n this._pickId.object.id = value;\n }\n },\n },\n\n /**\n * @private\n */\n pickId: {\n get: function () {\n return this._pickId;\n },\n },\n\n /**\n * Gets the destruction status of this polyline\n * @memberof Polyline.prototype\n * @type {boolean}\n * @default false\n * @private\n */\n isDestroyed: {\n get: function () {\n return !defined(this._polylineCollection);\n },\n },\n\n /**\n * Gets or sets the condition specifying at what distance from the camera that this polyline will be displayed.\n * @memberof Polyline.prototype\n * @type {DistanceDisplayCondition}\n * @default undefined\n */\n distanceDisplayCondition: {\n get: function () {\n return this._distanceDisplayCondition;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n if (\n !DistanceDisplayCondition.equals(value, this._distanceDisplayCondition)\n ) {\n this._distanceDisplayCondition = DistanceDisplayCondition.clone(\n value,\n this._distanceDisplayCondition\n );\n makeDirty(this, DISTANCE_DISPLAY_CONDITION);\n }\n },\n },\n});\n\n/**\n * @private\n */\nPolyline.prototype.update = function () {\n let modelMatrix = Matrix4.IDENTITY;\n if (defined(this._polylineCollection)) {\n modelMatrix = this._polylineCollection.modelMatrix;\n }\n\n const segmentPositionsLength = this._segments.positions.length;\n const segmentLengths = this._segments.lengths;\n\n const positionsChanged =\n this._propertiesChanged[POSITION_INDEX] > 0 ||\n this._propertiesChanged[POSITION_SIZE_INDEX] > 0;\n if (!Matrix4.equals(modelMatrix, this._modelMatrix) || positionsChanged) {\n this._segments = PolylinePipeline.wrapLongitude(\n this._actualPositions,\n modelMatrix\n );\n this._boundingVolumeWC = BoundingSphere.transform(\n this._boundingVolume,\n modelMatrix,\n this._boundingVolumeWC\n );\n }\n\n this._modelMatrix = Matrix4.clone(modelMatrix, this._modelMatrix);\n\n if (this._segments.positions.length !== segmentPositionsLength) {\n // number of positions changed\n makeDirty(this, POSITION_SIZE_INDEX);\n } else {\n const length = segmentLengths.length;\n for (let i = 0; i < length; ++i) {\n if (segmentLengths[i] !== this._segments.lengths[i]) {\n // indices changed\n makeDirty(this, POSITION_SIZE_INDEX);\n break;\n }\n }\n }\n};\n\n/**\n * @private\n */\nPolyline.prototype.getPickId = function (context) {\n if (!defined(this._pickId)) {\n this._pickId = context.createPickId({\n primitive: this,\n collection: this._polylineCollection,\n id: this._id,\n });\n }\n return this._pickId;\n};\n\nPolyline.prototype._clean = function () {\n this._dirty = false;\n const properties = this._propertiesChanged;\n for (let k = 0; k < NUMBER_OF_PROPERTIES - 1; ++k) {\n properties[k] = 0;\n }\n};\n\nPolyline.prototype._destroy = function () {\n this._pickId = this._pickId && this._pickId.destroy();\n this._material = this._material && this._material.destroy();\n this._polylineCollection = undefined;\n};\nexport default Polyline;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Color from \"../Core/Color.js\";\nimport combine from \"../Core/combine.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Plane from \"../Core/Plane.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport Texture from \"../Renderer/Texture.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport PolylineCommon from \"../Shaders/PolylineCommon.js\";\nimport PolylineFS from \"../Shaders/PolylineFS.js\";\nimport PolylineVS from \"../Shaders/PolylineVS.js\";\nimport BatchTable from \"./BatchTable.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport Material from \"./Material.js\";\nimport Polyline from \"./Polyline.js\";\nimport SceneMode from \"./SceneMode.js\";\n\nconst SHOW_INDEX = Polyline.SHOW_INDEX;\nconst WIDTH_INDEX = Polyline.WIDTH_INDEX;\nconst POSITION_INDEX = Polyline.POSITION_INDEX;\nconst MATERIAL_INDEX = Polyline.MATERIAL_INDEX;\n//POSITION_SIZE_INDEX is needed for when the polyline's position array changes size.\n//When it does, we need to recreate the indicesBuffer.\nconst POSITION_SIZE_INDEX = Polyline.POSITION_SIZE_INDEX;\nconst DISTANCE_DISPLAY_CONDITION = Polyline.DISTANCE_DISPLAY_CONDITION;\nconst NUMBER_OF_PROPERTIES = Polyline.NUMBER_OF_PROPERTIES;\n\nconst attributeLocations = {\n texCoordExpandAndBatchIndex: 0,\n position3DHigh: 1,\n position3DLow: 2,\n position2DHigh: 3,\n position2DLow: 4,\n prevPosition3DHigh: 5,\n prevPosition3DLow: 6,\n prevPosition2DHigh: 7,\n prevPosition2DLow: 8,\n nextPosition3DHigh: 9,\n nextPosition3DLow: 10,\n nextPosition2DHigh: 11,\n nextPosition2DLow: 12,\n};\n\n/**\n * A renderable collection of polylines.\n *

\n *
\n *
\n * Example polylines\n *
\n *

\n * Polylines are added and removed from the collection using {@link PolylineCollection#add}\n * and {@link PolylineCollection#remove}.\n *\n * @alias PolylineCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each polyline from model to world coordinates.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {boolean} [options.show=true] Determines if the polylines in the collection will be shown.\n *\n * @performance For best performance, prefer a few collections, each with many polylines, to\n * many collections with only a few polylines each. Organize collections so that polylines\n * with the same update frequency are in the same collection, i.e., polylines that do not\n * change should be in one collection; polylines that change every frame should be in another\n * collection; and so on.\n *\n * @see PolylineCollection#add\n * @see PolylineCollection#remove\n * @see Polyline\n * @see LabelCollection\n *\n * @example\n * // Create a polyline collection with two polylines\n * const polylines = new Cesium.PolylineCollection();\n * polylines.add({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -75.10, 39.57,\n * -77.02, 38.53,\n * -80.50, 35.14,\n * -80.12, 25.46]),\n * width : 2\n * });\n *\n * polylines.add({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -73.10, 37.57,\n * -75.02, 36.53,\n * -78.50, 33.14,\n * -78.12, 23.46]),\n * width : 4\n * });\n */\nfunction PolylineCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n /**\n * Determines if polylines in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * The 4x4 transformation matrix that transforms each polyline in this collection from model to world coordinates.\n * When this is the identity matrix, the polylines are drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n * @type {Matrix4}\n * @default {@link Matrix4.IDENTITY}\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n this._opaqueRS = undefined;\n this._translucentRS = undefined;\n\n this._colorCommands = [];\n\n this._polylinesUpdated = false;\n this._polylinesRemoved = false;\n this._createVertexArray = false;\n this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);\n this._polylines = [];\n this._polylineBuckets = {};\n\n // The buffer usage is determined based on the usage of the attribute over time.\n this._positionBufferUsage = {\n bufferUsage: BufferUsage.STATIC_DRAW,\n frameCount: 0,\n };\n\n this._mode = undefined;\n\n this._polylinesToUpdate = [];\n this._vertexArrays = [];\n this._positionBuffer = undefined;\n this._texCoordExpandAndBatchIndexBuffer = undefined;\n\n this._batchTable = undefined;\n this._createBatchTable = false;\n\n // Only used by Vector3DTilePoints\n this._useHighlightColor = false;\n this._highlightColor = Color.clone(Color.WHITE);\n\n const that = this;\n this._uniformMap = {\n u_highlightColor: function () {\n return that._highlightColor;\n },\n };\n}\n\nObject.defineProperties(PolylineCollection.prototype, {\n /**\n * Returns the number of polylines in this collection. This is commonly used with\n * {@link PolylineCollection#get} to iterate over all the polylines\n * in the collection.\n * @memberof PolylineCollection.prototype\n * @type {number}\n */\n length: {\n get: function () {\n removePolylines(this);\n return this._polylines.length;\n },\n },\n});\n\n/**\n * Creates and adds a polyline with the specified initial properties to the collection.\n * The added polyline is returned so it can be modified or removed from the collection later.\n *\n * @param {object}[options] A template describing the polyline's properties as shown in Example 1.\n * @returns {Polyline} The polyline that was added to the collection.\n *\n * @performance After calling add, {@link PolylineCollection#update} is called and\n * the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead.\n * For best performance, add as many polylines as possible before calling update.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Example 1: Add a polyline, specifying all the default values.\n * const p = polylines.add({\n * show : true,\n * positions : ellipsoid.cartographicArrayToCartesianArray([\n Cesium.Cartographic.fromDegrees(-75.10, 39.57),\n Cesium.Cartographic.fromDegrees(-77.02, 38.53)]),\n * width : 1\n * });\n *\n * @see PolylineCollection#remove\n * @see PolylineCollection#removeAll\n * @see PolylineCollection#update\n */\nPolylineCollection.prototype.add = function (options) {\n const p = new Polyline(options, this);\n p._index = this._polylines.length;\n this._polylines.push(p);\n this._createVertexArray = true;\n this._createBatchTable = true;\n return p;\n};\n\n/**\n * Removes a polyline from the collection.\n *\n * @param {Polyline} polyline The polyline to remove.\n * @returns {boolean} true if the polyline was removed; false if the polyline was not found in the collection.\n *\n * @performance After calling remove, {@link PolylineCollection#update} is called and\n * the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead.\n * For best performance, remove as many polylines as possible before calling update.\n * If you intend to temporarily hide a polyline, it is usually more efficient to call\n * {@link Polyline#show} instead of removing and re-adding the polyline.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * const p = polylines.add(...);\n * polylines.remove(p); // Returns true\n *\n * @see PolylineCollection#add\n * @see PolylineCollection#removeAll\n * @see PolylineCollection#update\n * @see Polyline#show\n */\nPolylineCollection.prototype.remove = function (polyline) {\n if (this.contains(polyline)) {\n this._polylinesRemoved = true;\n this._createVertexArray = true;\n this._createBatchTable = true;\n if (defined(polyline._bucket)) {\n const bucket = polyline._bucket;\n bucket.shaderProgram =\n bucket.shaderProgram && bucket.shaderProgram.destroy();\n }\n polyline._destroy();\n return true;\n }\n\n return false;\n};\n\n/**\n * Removes all polylines from the collection.\n *\n * @performance O(n). It is more efficient to remove all the polylines\n * from a collection and then add new ones than to create a new collection entirely.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * polylines.add(...);\n * polylines.add(...);\n * polylines.removeAll();\n *\n * @see PolylineCollection#add\n * @see PolylineCollection#remove\n * @see PolylineCollection#update\n */\nPolylineCollection.prototype.removeAll = function () {\n releaseShaders(this);\n destroyPolylines(this);\n this._polylineBuckets = {};\n this._polylinesRemoved = false;\n this._polylines.length = 0;\n this._polylinesToUpdate.length = 0;\n this._createVertexArray = true;\n};\n\n/**\n * Determines if this collection contains the specified polyline.\n *\n * @param {Polyline} polyline The polyline to check for.\n * @returns {boolean} true if this collection contains the polyline, false otherwise.\n *\n * @see PolylineCollection#get\n */\nPolylineCollection.prototype.contains = function (polyline) {\n return defined(polyline) && polyline._polylineCollection === this;\n};\n\n/**\n * Returns the polyline in the collection at the specified index. Indices are zero-based\n * and increase as polylines are added. Removing a polyline shifts all polylines after\n * it to the left, changing their indices. This function is commonly used with\n * {@link PolylineCollection#length} to iterate over all the polylines\n * in the collection.\n *\n * @param {number} index The zero-based index of the polyline.\n * @returns {Polyline} The polyline at the specified index.\n *\n * @performance If polylines were removed from the collection and\n * {@link PolylineCollection#update} was not called, an implicit O(n)\n * operation is performed.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * // Toggle the show property of every polyline in the collection\n * const len = polylines.length;\n * for (let i = 0; i < len; ++i) {\n * const p = polylines.get(i);\n * p.show = !p.show;\n * }\n *\n * @see PolylineCollection#length\n */\nPolylineCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n removePolylines(this);\n return this._polylines[index];\n};\n\nfunction createBatchTable(collection, context) {\n if (defined(collection._batchTable)) {\n collection._batchTable.destroy();\n }\n\n const attributes = [\n {\n functionName: \"batchTable_getWidthAndShow\",\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 2,\n },\n {\n functionName: \"batchTable_getPickColor\",\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 4,\n normalize: true,\n },\n {\n functionName: \"batchTable_getCenterHigh\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n functionName: \"batchTable_getCenterLowAndRadius\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n },\n {\n functionName: \"batchTable_getDistanceDisplayCondition\",\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n },\n ];\n\n collection._batchTable = new BatchTable(\n context,\n attributes,\n collection._polylines.length\n );\n}\n\nconst scratchUpdatePolylineEncodedCartesian = new EncodedCartesian3();\nconst scratchUpdatePolylineCartesian4 = new Cartesian4();\nconst scratchNearFarCartesian2 = new Cartesian2();\n\n/**\n * Called when {@link Viewer} or {@link CesiumWidget} render the scene to\n * get the draw commands needed to render this primitive.\n *

\n * Do not call this function directly. This is documented just to\n * list the exceptions that may be propagated when the scene is rendered:\n *

\n *\n * @exception {RuntimeError} Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.\n */\nPolylineCollection.prototype.update = function (frameState) {\n removePolylines(this);\n\n if (this._polylines.length === 0 || !this.show) {\n return;\n }\n\n updateMode(this, frameState);\n\n const context = frameState.context;\n const projection = frameState.mapProjection;\n let polyline;\n let properties = this._propertiesChanged;\n\n if (this._createBatchTable) {\n if (ContextLimits.maximumVertexTextureImageUnits === 0) {\n throw new RuntimeError(\n \"Vertex texture fetch support is required to render polylines. The maximum number of vertex texture image units must be greater than zero.\"\n );\n }\n createBatchTable(this, context);\n this._createBatchTable = false;\n }\n\n if (this._createVertexArray || computeNewBuffersUsage(this)) {\n createVertexArrays(this, context, projection);\n } else if (this._polylinesUpdated) {\n // Polylines were modified, but no polylines were added or removed.\n const polylinesToUpdate = this._polylinesToUpdate;\n if (this._mode !== SceneMode.SCENE3D) {\n const updateLength = polylinesToUpdate.length;\n for (let i = 0; i < updateLength; ++i) {\n polyline = polylinesToUpdate[i];\n polyline.update();\n }\n }\n\n // if a polyline's positions size changes, we need to recreate the vertex arrays and vertex buffers because the indices will be different.\n // if a polyline's material changes, we need to recreate the VAOs and VBOs because they will be batched differently.\n if (properties[POSITION_SIZE_INDEX] || properties[MATERIAL_INDEX]) {\n createVertexArrays(this, context, projection);\n } else {\n const length = polylinesToUpdate.length;\n const polylineBuckets = this._polylineBuckets;\n for (let ii = 0; ii < length; ++ii) {\n polyline = polylinesToUpdate[ii];\n properties = polyline._propertiesChanged;\n const bucket = polyline._bucket;\n let index = 0;\n for (const x in polylineBuckets) {\n if (polylineBuckets.hasOwnProperty(x)) {\n if (polylineBuckets[x] === bucket) {\n if (properties[POSITION_INDEX]) {\n bucket.writeUpdate(\n index,\n polyline,\n this._positionBuffer,\n projection\n );\n }\n break;\n }\n index += polylineBuckets[x].lengthOfPositions;\n }\n }\n\n if (properties[SHOW_INDEX] || properties[WIDTH_INDEX]) {\n this._batchTable.setBatchedAttribute(\n polyline._index,\n 0,\n new Cartesian2(polyline._width, polyline._show)\n );\n }\n\n if (this._batchTable.attributes.length > 2) {\n if (properties[POSITION_INDEX] || properties[POSITION_SIZE_INDEX]) {\n const boundingSphere =\n frameState.mode === SceneMode.SCENE2D\n ? polyline._boundingVolume2D\n : polyline._boundingVolumeWC;\n const encodedCenter = EncodedCartesian3.fromCartesian(\n boundingSphere.center,\n scratchUpdatePolylineEncodedCartesian\n );\n const low = Cartesian4.fromElements(\n encodedCenter.low.x,\n encodedCenter.low.y,\n encodedCenter.low.z,\n boundingSphere.radius,\n scratchUpdatePolylineCartesian4\n );\n this._batchTable.setBatchedAttribute(\n polyline._index,\n 2,\n encodedCenter.high\n );\n this._batchTable.setBatchedAttribute(polyline._index, 3, low);\n }\n\n if (properties[DISTANCE_DISPLAY_CONDITION]) {\n const nearFarCartesian = scratchNearFarCartesian2;\n nearFarCartesian.x = 0.0;\n nearFarCartesian.y = Number.MAX_VALUE;\n\n const distanceDisplayCondition = polyline.distanceDisplayCondition;\n if (defined(distanceDisplayCondition)) {\n nearFarCartesian.x = distanceDisplayCondition.near;\n nearFarCartesian.y = distanceDisplayCondition.far;\n }\n\n this._batchTable.setBatchedAttribute(\n polyline._index,\n 4,\n nearFarCartesian\n );\n }\n }\n\n polyline._clean();\n }\n }\n polylinesToUpdate.length = 0;\n this._polylinesUpdated = false;\n }\n\n properties = this._propertiesChanged;\n for (let k = 0; k < NUMBER_OF_PROPERTIES; ++k) {\n properties[k] = 0;\n }\n\n let modelMatrix = Matrix4.IDENTITY;\n if (frameState.mode === SceneMode.SCENE3D) {\n modelMatrix = this.modelMatrix;\n }\n\n const pass = frameState.passes;\n const useDepthTest = frameState.morphTime !== 0.0;\n\n if (\n !defined(this._opaqueRS) ||\n this._opaqueRS.depthTest.enabled !== useDepthTest\n ) {\n this._opaqueRS = RenderState.fromCache({\n depthMask: useDepthTest,\n depthTest: {\n enabled: useDepthTest,\n },\n });\n }\n\n if (\n !defined(this._translucentRS) ||\n this._translucentRS.depthTest.enabled !== useDepthTest\n ) {\n this._translucentRS = RenderState.fromCache({\n blending: BlendingState.ALPHA_BLEND,\n depthMask: !useDepthTest,\n depthTest: {\n enabled: useDepthTest,\n },\n });\n }\n\n this._batchTable.update(frameState);\n\n if (pass.render || pass.pick) {\n const colorList = this._colorCommands;\n createCommandLists(this, frameState, colorList, modelMatrix);\n }\n};\n\nconst boundingSphereScratch = new BoundingSphere();\nconst boundingSphereScratch2 = new BoundingSphere();\n\nfunction createCommandLists(\n polylineCollection,\n frameState,\n commands,\n modelMatrix\n) {\n const context = frameState.context;\n const commandList = frameState.commandList;\n\n const commandsLength = commands.length;\n let commandIndex = 0;\n let cloneBoundingSphere = true;\n\n const vertexArrays = polylineCollection._vertexArrays;\n const debugShowBoundingVolume = polylineCollection.debugShowBoundingVolume;\n\n const batchTable = polylineCollection._batchTable;\n const uniformCallback = batchTable.getUniformMapCallback();\n\n const length = vertexArrays.length;\n for (let m = 0; m < length; ++m) {\n const va = vertexArrays[m];\n const buckets = va.buckets;\n const bucketLength = buckets.length;\n\n for (let n = 0; n < bucketLength; ++n) {\n const bucketLocator = buckets[n];\n\n let offset = bucketLocator.offset;\n const sp = bucketLocator.bucket.shaderProgram;\n\n const polylines = bucketLocator.bucket.polylines;\n const polylineLength = polylines.length;\n let currentId;\n let currentMaterial;\n let count = 0;\n let command;\n let uniformMap;\n\n for (let s = 0; s < polylineLength; ++s) {\n const polyline = polylines[s];\n const mId = createMaterialId(polyline._material);\n if (mId !== currentId) {\n if (defined(currentId) && count > 0) {\n const translucent = currentMaterial.isTranslucent();\n\n if (commandIndex >= commandsLength) {\n command = new DrawCommand({\n owner: polylineCollection,\n });\n commands.push(command);\n } else {\n command = commands[commandIndex];\n }\n\n ++commandIndex;\n\n uniformMap = combine(\n uniformCallback(currentMaterial._uniforms),\n polylineCollection._uniformMap\n );\n\n command.boundingVolume = BoundingSphere.clone(\n boundingSphereScratch,\n command.boundingVolume\n );\n command.modelMatrix = modelMatrix;\n command.shaderProgram = sp;\n command.vertexArray = va.va;\n command.renderState = translucent\n ? polylineCollection._translucentRS\n : polylineCollection._opaqueRS;\n command.pass = translucent ? Pass.TRANSLUCENT : Pass.OPAQUE;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n command.pickId = \"v_pickColor\";\n\n command.uniformMap = uniformMap;\n command.count = count;\n command.offset = offset;\n\n offset += count;\n count = 0;\n cloneBoundingSphere = true;\n\n commandList.push(command);\n }\n\n currentMaterial = polyline._material;\n currentMaterial.update(context);\n currentId = mId;\n }\n\n const locators = polyline._locatorBuckets;\n const locatorLength = locators.length;\n for (let t = 0; t < locatorLength; ++t) {\n const locator = locators[t];\n if (locator.locator === bucketLocator) {\n count += locator.count;\n }\n }\n\n let boundingVolume;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingVolume = polyline._boundingVolumeWC;\n } else if (frameState.mode === SceneMode.COLUMBUS_VIEW) {\n boundingVolume = polyline._boundingVolume2D;\n } else if (frameState.mode === SceneMode.SCENE2D) {\n if (defined(polyline._boundingVolume2D)) {\n boundingVolume = BoundingSphere.clone(\n polyline._boundingVolume2D,\n boundingSphereScratch2\n );\n boundingVolume.center.x = 0.0;\n }\n } else if (\n defined(polyline._boundingVolumeWC) &&\n defined(polyline._boundingVolume2D)\n ) {\n boundingVolume = BoundingSphere.union(\n polyline._boundingVolumeWC,\n polyline._boundingVolume2D,\n boundingSphereScratch2\n );\n }\n\n if (cloneBoundingSphere) {\n cloneBoundingSphere = false;\n BoundingSphere.clone(boundingVolume, boundingSphereScratch);\n } else {\n BoundingSphere.union(\n boundingVolume,\n boundingSphereScratch,\n boundingSphereScratch\n );\n }\n }\n\n if (defined(currentId) && count > 0) {\n if (commandIndex >= commandsLength) {\n command = new DrawCommand({\n owner: polylineCollection,\n });\n commands.push(command);\n } else {\n command = commands[commandIndex];\n }\n\n ++commandIndex;\n\n uniformMap = combine(\n uniformCallback(currentMaterial._uniforms),\n polylineCollection._uniformMap\n );\n\n command.boundingVolume = BoundingSphere.clone(\n boundingSphereScratch,\n command.boundingVolume\n );\n command.modelMatrix = modelMatrix;\n command.shaderProgram = sp;\n command.vertexArray = va.va;\n command.renderState = currentMaterial.isTranslucent()\n ? polylineCollection._translucentRS\n : polylineCollection._opaqueRS;\n command.pass = currentMaterial.isTranslucent()\n ? Pass.TRANSLUCENT\n : Pass.OPAQUE;\n command.debugShowBoundingVolume = debugShowBoundingVolume;\n command.pickId = \"v_pickColor\";\n\n command.uniformMap = uniformMap;\n command.count = count;\n command.offset = offset;\n\n cloneBoundingSphere = true;\n\n commandList.push(command);\n }\n\n currentId = undefined;\n }\n }\n\n commands.length = commandIndex;\n}\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see PolylineCollection#destroy\n */\nPolylineCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * polylines = polylines && polylines.destroy();\n *\n * @see PolylineCollection#isDestroyed\n */\nPolylineCollection.prototype.destroy = function () {\n destroyVertexArrays(this);\n releaseShaders(this);\n destroyPolylines(this);\n this._batchTable = this._batchTable && this._batchTable.destroy();\n return destroyObject(this);\n};\n\nfunction computeNewBuffersUsage(collection) {\n let usageChanged = false;\n const properties = collection._propertiesChanged;\n const bufferUsage = collection._positionBufferUsage;\n if (properties[POSITION_INDEX]) {\n if (bufferUsage.bufferUsage !== BufferUsage.STREAM_DRAW) {\n usageChanged = true;\n bufferUsage.bufferUsage = BufferUsage.STREAM_DRAW;\n bufferUsage.frameCount = 100;\n } else {\n bufferUsage.frameCount = 100;\n }\n } else if (bufferUsage.bufferUsage !== BufferUsage.STATIC_DRAW) {\n if (bufferUsage.frameCount === 0) {\n usageChanged = true;\n bufferUsage.bufferUsage = BufferUsage.STATIC_DRAW;\n } else {\n bufferUsage.frameCount--;\n }\n }\n\n return usageChanged;\n}\n\nconst emptyVertexBuffer = [0.0, 0.0, 0.0];\n\nfunction createVertexArrays(collection, context, projection) {\n collection._createVertexArray = false;\n releaseShaders(collection);\n destroyVertexArrays(collection);\n sortPolylinesIntoBuckets(collection);\n\n //stores all of the individual indices arrays.\n const totalIndices = [[]];\n let indices = totalIndices[0];\n\n const batchTable = collection._batchTable;\n const useHighlightColor = collection._useHighlightColor;\n\n //used to determine the vertexBuffer offset if the indicesArray goes over 64k.\n //if it's the same polyline while it goes over 64k, the offset needs to backtrack componentsPerAttribute * componentDatatype bytes\n //so that the polyline looks contiguous.\n //if the polyline ends at the 64k mark, then the offset is just 64k * componentsPerAttribute * componentDatatype\n const vertexBufferOffset = [0];\n let offset = 0;\n const vertexArrayBuckets = [[]];\n let totalLength = 0;\n const polylineBuckets = collection._polylineBuckets;\n let x;\n let bucket;\n for (x in polylineBuckets) {\n if (polylineBuckets.hasOwnProperty(x)) {\n bucket = polylineBuckets[x];\n bucket.updateShader(context, batchTable, useHighlightColor);\n totalLength += bucket.lengthOfPositions;\n }\n }\n\n if (totalLength > 0) {\n const mode = collection._mode;\n\n const positionArray = new Float32Array(6 * totalLength * 3);\n const texCoordExpandAndBatchIndexArray = new Float32Array(totalLength * 4);\n let position3DArray;\n\n let positionIndex = 0;\n let colorIndex = 0;\n let texCoordExpandAndBatchIndexIndex = 0;\n for (x in polylineBuckets) {\n if (polylineBuckets.hasOwnProperty(x)) {\n bucket = polylineBuckets[x];\n bucket.write(\n positionArray,\n texCoordExpandAndBatchIndexArray,\n positionIndex,\n colorIndex,\n texCoordExpandAndBatchIndexIndex,\n batchTable,\n context,\n projection\n );\n\n if (mode === SceneMode.MORPHING) {\n if (!defined(position3DArray)) {\n position3DArray = new Float32Array(6 * totalLength * 3);\n }\n bucket.writeForMorph(position3DArray, positionIndex);\n }\n\n const bucketLength = bucket.lengthOfPositions;\n positionIndex += 6 * bucketLength * 3;\n colorIndex += bucketLength * 4;\n texCoordExpandAndBatchIndexIndex += bucketLength * 4;\n offset = bucket.updateIndices(\n totalIndices,\n vertexBufferOffset,\n vertexArrayBuckets,\n offset\n );\n }\n }\n\n const positionBufferUsage = collection._positionBufferUsage.bufferUsage;\n const texCoordExpandAndBatchIndexBufferUsage = BufferUsage.STATIC_DRAW;\n\n collection._positionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: positionArray,\n usage: positionBufferUsage,\n });\n let position3DBuffer;\n if (defined(position3DArray)) {\n position3DBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: position3DArray,\n usage: positionBufferUsage,\n });\n }\n collection._texCoordExpandAndBatchIndexBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: texCoordExpandAndBatchIndexArray,\n usage: texCoordExpandAndBatchIndexBufferUsage,\n });\n\n const positionSizeInBytes = 3 * Float32Array.BYTES_PER_ELEMENT;\n const texCoordExpandAndBatchIndexSizeInBytes =\n 4 * Float32Array.BYTES_PER_ELEMENT;\n\n let vbo = 0;\n const numberOfIndicesArrays = totalIndices.length;\n for (let k = 0; k < numberOfIndicesArrays; ++k) {\n indices = totalIndices[k];\n\n if (indices.length > 0) {\n const indicesArray = new Uint16Array(indices);\n const indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: indicesArray,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype: IndexDatatype.UNSIGNED_SHORT,\n });\n\n vbo += vertexBufferOffset[k];\n\n const positionHighOffset =\n 6 *\n (k * (positionSizeInBytes * CesiumMath.SIXTY_FOUR_KILOBYTES) -\n vbo * positionSizeInBytes); //componentsPerAttribute(3) * componentDatatype(4)\n const positionLowOffset = positionSizeInBytes + positionHighOffset;\n const prevPositionHighOffset = positionSizeInBytes + positionLowOffset;\n const prevPositionLowOffset =\n positionSizeInBytes + prevPositionHighOffset;\n const nextPositionHighOffset =\n positionSizeInBytes + prevPositionLowOffset;\n const nextPositionLowOffset =\n positionSizeInBytes + nextPositionHighOffset;\n const vertexTexCoordExpandAndBatchIndexBufferOffset =\n k *\n (texCoordExpandAndBatchIndexSizeInBytes *\n CesiumMath.SIXTY_FOUR_KILOBYTES) -\n vbo * texCoordExpandAndBatchIndexSizeInBytes;\n\n const attributes = [\n {\n index: attributeLocations.position3DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: positionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.position3DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: positionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.position2DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: positionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.position2DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: positionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.prevPosition3DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: prevPositionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.prevPosition3DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: prevPositionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.prevPosition2DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: prevPositionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.prevPosition2DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: prevPositionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.nextPosition3DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: nextPositionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.nextPosition3DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: nextPositionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.nextPosition2DHigh,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: nextPositionHighOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.nextPosition2DLow,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n offsetInBytes: nextPositionLowOffset,\n strideInBytes: 6 * positionSizeInBytes,\n },\n {\n index: attributeLocations.texCoordExpandAndBatchIndex,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n vertexBuffer: collection._texCoordExpandAndBatchIndexBuffer,\n offsetInBytes: vertexTexCoordExpandAndBatchIndexBufferOffset,\n },\n ];\n\n let bufferProperty3D;\n let buffer3D;\n let buffer2D;\n let bufferProperty2D;\n\n if (mode === SceneMode.SCENE3D) {\n buffer3D = collection._positionBuffer;\n bufferProperty3D = \"vertexBuffer\";\n buffer2D = emptyVertexBuffer;\n bufferProperty2D = \"value\";\n } else if (\n mode === SceneMode.SCENE2D ||\n mode === SceneMode.COLUMBUS_VIEW\n ) {\n buffer3D = emptyVertexBuffer;\n bufferProperty3D = \"value\";\n buffer2D = collection._positionBuffer;\n bufferProperty2D = \"vertexBuffer\";\n } else {\n buffer3D = position3DBuffer;\n bufferProperty3D = \"vertexBuffer\";\n buffer2D = collection._positionBuffer;\n bufferProperty2D = \"vertexBuffer\";\n }\n\n attributes[0][bufferProperty3D] = buffer3D;\n attributes[1][bufferProperty3D] = buffer3D;\n attributes[2][bufferProperty2D] = buffer2D;\n attributes[3][bufferProperty2D] = buffer2D;\n attributes[4][bufferProperty3D] = buffer3D;\n attributes[5][bufferProperty3D] = buffer3D;\n attributes[6][bufferProperty2D] = buffer2D;\n attributes[7][bufferProperty2D] = buffer2D;\n attributes[8][bufferProperty3D] = buffer3D;\n attributes[9][bufferProperty3D] = buffer3D;\n attributes[10][bufferProperty2D] = buffer2D;\n attributes[11][bufferProperty2D] = buffer2D;\n\n const va = new VertexArray({\n context: context,\n attributes: attributes,\n indexBuffer: indexBuffer,\n });\n collection._vertexArrays.push({\n va: va,\n buckets: vertexArrayBuckets[k],\n });\n }\n }\n }\n}\n\nfunction replacer(key, value) {\n if (value instanceof Texture) {\n return value.id;\n }\n\n return value;\n}\n\nconst scratchUniformArray = [];\nfunction createMaterialId(material) {\n const uniforms = Material._uniformList[material.type];\n const length = uniforms.length;\n scratchUniformArray.length = 2.0 * length;\n\n let index = 0;\n for (let i = 0; i < length; ++i) {\n const uniform = uniforms[i];\n scratchUniformArray[index] = uniform;\n scratchUniformArray[index + 1] = material._uniforms[uniform]();\n index += 2;\n }\n\n return `${material.type}:${JSON.stringify(scratchUniformArray, replacer)}`;\n}\n\nfunction sortPolylinesIntoBuckets(collection) {\n const mode = collection._mode;\n const modelMatrix = collection._modelMatrix;\n\n const polylineBuckets = (collection._polylineBuckets = {});\n const polylines = collection._polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n const p = polylines[i];\n if (p._actualPositions.length > 1) {\n p.update();\n const material = p.material;\n let value = polylineBuckets[material.type];\n if (!defined(value)) {\n value = polylineBuckets[material.type] = new PolylineBucket(\n material,\n mode,\n modelMatrix\n );\n }\n value.addPolyline(p);\n }\n }\n}\n\nfunction updateMode(collection, frameState) {\n const mode = frameState.mode;\n\n if (\n collection._mode !== mode ||\n !Matrix4.equals(collection._modelMatrix, collection.modelMatrix)\n ) {\n collection._mode = mode;\n collection._modelMatrix = Matrix4.clone(collection.modelMatrix);\n collection._createVertexArray = true;\n }\n}\n\nfunction removePolylines(collection) {\n if (collection._polylinesRemoved) {\n collection._polylinesRemoved = false;\n const definedPolylines = [];\n const definedPolylinesToUpdate = [];\n let polyIndex = 0;\n let polyline;\n\n const length = collection._polylines.length;\n for (let i = 0; i < length; ++i) {\n polyline = collection._polylines[i];\n if (!polyline.isDestroyed) {\n polyline._index = polyIndex++;\n definedPolylinesToUpdate.push(polyline);\n definedPolylines.push(polyline);\n }\n }\n\n collection._polylines = definedPolylines;\n collection._polylinesToUpdate = definedPolylinesToUpdate;\n }\n}\n\nfunction releaseShaders(collection) {\n const polylines = collection._polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n if (!polylines[i].isDestroyed) {\n const bucket = polylines[i]._bucket;\n if (defined(bucket)) {\n bucket.shaderProgram =\n bucket.shaderProgram && bucket.shaderProgram.destroy();\n }\n }\n }\n}\n\nfunction destroyVertexArrays(collection) {\n const length = collection._vertexArrays.length;\n for (let t = 0; t < length; ++t) {\n collection._vertexArrays[t].va.destroy();\n }\n collection._vertexArrays.length = 0;\n}\n\nPolylineCollection.prototype._updatePolyline = function (\n polyline,\n propertyChanged\n) {\n this._polylinesUpdated = true;\n if (!polyline._dirty) {\n this._polylinesToUpdate.push(polyline);\n }\n ++this._propertiesChanged[propertyChanged];\n};\n\nfunction destroyPolylines(collection) {\n const polylines = collection._polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n if (!polylines[i].isDestroyed) {\n polylines[i]._destroy();\n }\n }\n}\n\nfunction VertexArrayBucketLocator(count, offset, bucket) {\n this.count = count;\n this.offset = offset;\n this.bucket = bucket;\n}\n\nfunction PolylineBucket(material, mode, modelMatrix) {\n this.polylines = [];\n this.lengthOfPositions = 0;\n this.material = material;\n this.shaderProgram = undefined;\n this.mode = mode;\n this.modelMatrix = modelMatrix;\n}\n\nPolylineBucket.prototype.addPolyline = function (p) {\n const polylines = this.polylines;\n polylines.push(p);\n p._actualLength = this.getPolylinePositionsLength(p);\n this.lengthOfPositions += p._actualLength;\n p._bucket = this;\n};\n\nPolylineBucket.prototype.updateShader = function (\n context,\n batchTable,\n useHighlightColor\n) {\n if (defined(this.shaderProgram)) {\n return;\n }\n\n const defines = [\"DISTANCE_DISPLAY_CONDITION\"];\n if (useHighlightColor) {\n defines.push(\"VECTOR_TILE\");\n }\n\n // Check for use of v_polylineAngle in material shader\n if (\n this.material.shaderSource.search(/in\\s+float\\s+v_polylineAngle;/g) !== -1\n ) {\n defines.push(\"POLYLINE_DASH\");\n }\n\n if (!FeatureDetection.isInternetExplorer()) {\n defines.push(\"CLIP_POLYLINE\");\n }\n\n const fs = new ShaderSource({\n defines: defines,\n sources: [\"in vec4 v_pickColor;\\n\", this.material.shaderSource, PolylineFS],\n });\n\n const vsSource = batchTable.getVertexShaderCallback()(PolylineVS);\n const vs = new ShaderSource({\n defines: defines,\n sources: [PolylineCommon, vsSource],\n });\n\n this.shaderProgram = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n};\n\nfunction intersectsIDL(polyline) {\n return (\n Cartesian3.dot(Cartesian3.UNIT_X, polyline._boundingVolume.center) < 0 ||\n polyline._boundingVolume.intersectPlane(Plane.ORIGIN_ZX_PLANE) ===\n Intersect.INTERSECTING\n );\n}\n\nPolylineBucket.prototype.getPolylinePositionsLength = function (polyline) {\n let length;\n if (this.mode === SceneMode.SCENE3D || !intersectsIDL(polyline)) {\n length = polyline._actualPositions.length;\n return length * 4.0 - 4.0;\n }\n\n let count = 0;\n const segmentLengths = polyline._segments.lengths;\n length = segmentLengths.length;\n for (let i = 0; i < length; ++i) {\n count += segmentLengths[i] * 4.0 - 4.0;\n }\n\n return count;\n};\n\nconst scratchWritePosition = new Cartesian3();\nconst scratchWritePrevPosition = new Cartesian3();\nconst scratchWriteNextPosition = new Cartesian3();\nconst scratchWriteVector = new Cartesian3();\nconst scratchPickColorCartesian = new Cartesian4();\nconst scratchWidthShowCartesian = new Cartesian2();\n\nPolylineBucket.prototype.write = function (\n positionArray,\n texCoordExpandAndBatchIndexArray,\n positionIndex,\n colorIndex,\n texCoordExpandAndBatchIndexIndex,\n batchTable,\n context,\n projection\n) {\n const mode = this.mode;\n const maxLon = projection.ellipsoid.maximumRadius * CesiumMath.PI;\n\n const polylines = this.polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n const polyline = polylines[i];\n const width = polyline.width;\n const show = polyline.show && width > 0.0;\n const polylineBatchIndex = polyline._index;\n const segments = this.getSegments(polyline, projection);\n const positions = segments.positions;\n const lengths = segments.lengths;\n const positionsLength = positions.length;\n\n const pickColor = polyline.getPickId(context).color;\n\n let segmentIndex = 0;\n let count = 0;\n let position;\n\n for (let j = 0; j < positionsLength; ++j) {\n if (j === 0) {\n if (polyline._loop) {\n position = positions[positionsLength - 2];\n } else {\n position = scratchWriteVector;\n Cartesian3.subtract(positions[0], positions[1], position);\n Cartesian3.add(positions[0], position, position);\n }\n } else {\n position = positions[j - 1];\n }\n\n Cartesian3.clone(position, scratchWritePrevPosition);\n Cartesian3.clone(positions[j], scratchWritePosition);\n\n if (j === positionsLength - 1) {\n if (polyline._loop) {\n position = positions[1];\n } else {\n position = scratchWriteVector;\n Cartesian3.subtract(\n positions[positionsLength - 1],\n positions[positionsLength - 2],\n position\n );\n Cartesian3.add(positions[positionsLength - 1], position, position);\n }\n } else {\n position = positions[j + 1];\n }\n\n Cartesian3.clone(position, scratchWriteNextPosition);\n\n const segmentLength = lengths[segmentIndex];\n if (j === count + segmentLength) {\n count += segmentLength;\n ++segmentIndex;\n }\n\n const segmentStart = j - count === 0;\n const segmentEnd = j === count + lengths[segmentIndex] - 1;\n\n if (mode === SceneMode.SCENE2D) {\n scratchWritePrevPosition.z = 0.0;\n scratchWritePosition.z = 0.0;\n scratchWriteNextPosition.z = 0.0;\n }\n\n if (mode === SceneMode.SCENE2D || mode === SceneMode.MORPHING) {\n if (\n (segmentStart || segmentEnd) &&\n maxLon - Math.abs(scratchWritePosition.x) < 1.0\n ) {\n if (\n (scratchWritePosition.x < 0.0 &&\n scratchWritePrevPosition.x > 0.0) ||\n (scratchWritePosition.x > 0.0 && scratchWritePrevPosition.x < 0.0)\n ) {\n Cartesian3.clone(scratchWritePosition, scratchWritePrevPosition);\n }\n\n if (\n (scratchWritePosition.x < 0.0 &&\n scratchWriteNextPosition.x > 0.0) ||\n (scratchWritePosition.x > 0.0 && scratchWriteNextPosition.x < 0.0)\n ) {\n Cartesian3.clone(scratchWritePosition, scratchWriteNextPosition);\n }\n }\n }\n\n const startK = segmentStart ? 2 : 0;\n const endK = segmentEnd ? 2 : 4;\n\n for (let k = startK; k < endK; ++k) {\n EncodedCartesian3.writeElements(\n scratchWritePosition,\n positionArray,\n positionIndex\n );\n EncodedCartesian3.writeElements(\n scratchWritePrevPosition,\n positionArray,\n positionIndex + 6\n );\n EncodedCartesian3.writeElements(\n scratchWriteNextPosition,\n positionArray,\n positionIndex + 12\n );\n\n const direction = k - 2 < 0 ? -1.0 : 1.0;\n texCoordExpandAndBatchIndexArray[texCoordExpandAndBatchIndexIndex] =\n j / (positionsLength - 1); // s tex coord\n texCoordExpandAndBatchIndexArray[texCoordExpandAndBatchIndexIndex + 1] =\n 2 * (k % 2) - 1; // expand direction\n texCoordExpandAndBatchIndexArray[\n texCoordExpandAndBatchIndexIndex + 2\n ] = direction;\n texCoordExpandAndBatchIndexArray[\n texCoordExpandAndBatchIndexIndex + 3\n ] = polylineBatchIndex;\n\n positionIndex += 6 * 3;\n texCoordExpandAndBatchIndexIndex += 4;\n }\n }\n\n const colorCartesian = scratchPickColorCartesian;\n colorCartesian.x = Color.floatToByte(pickColor.red);\n colorCartesian.y = Color.floatToByte(pickColor.green);\n colorCartesian.z = Color.floatToByte(pickColor.blue);\n colorCartesian.w = Color.floatToByte(pickColor.alpha);\n\n const widthShowCartesian = scratchWidthShowCartesian;\n widthShowCartesian.x = width;\n widthShowCartesian.y = show ? 1.0 : 0.0;\n\n const boundingSphere =\n mode === SceneMode.SCENE2D\n ? polyline._boundingVolume2D\n : polyline._boundingVolumeWC;\n const encodedCenter = EncodedCartesian3.fromCartesian(\n boundingSphere.center,\n scratchUpdatePolylineEncodedCartesian\n );\n const high = encodedCenter.high;\n const low = Cartesian4.fromElements(\n encodedCenter.low.x,\n encodedCenter.low.y,\n encodedCenter.low.z,\n boundingSphere.radius,\n scratchUpdatePolylineCartesian4\n );\n\n const nearFarCartesian = scratchNearFarCartesian2;\n nearFarCartesian.x = 0.0;\n nearFarCartesian.y = Number.MAX_VALUE;\n\n const distanceDisplayCondition = polyline.distanceDisplayCondition;\n if (defined(distanceDisplayCondition)) {\n nearFarCartesian.x = distanceDisplayCondition.near;\n nearFarCartesian.y = distanceDisplayCondition.far;\n }\n\n batchTable.setBatchedAttribute(polylineBatchIndex, 0, widthShowCartesian);\n batchTable.setBatchedAttribute(polylineBatchIndex, 1, colorCartesian);\n\n if (batchTable.attributes.length > 2) {\n batchTable.setBatchedAttribute(polylineBatchIndex, 2, high);\n batchTable.setBatchedAttribute(polylineBatchIndex, 3, low);\n batchTable.setBatchedAttribute(polylineBatchIndex, 4, nearFarCartesian);\n }\n }\n};\n\nconst morphPositionScratch = new Cartesian3();\nconst morphPrevPositionScratch = new Cartesian3();\nconst morphNextPositionScratch = new Cartesian3();\nconst morphVectorScratch = new Cartesian3();\n\nPolylineBucket.prototype.writeForMorph = function (\n positionArray,\n positionIndex\n) {\n const modelMatrix = this.modelMatrix;\n const polylines = this.polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n const polyline = polylines[i];\n const positions = polyline._segments.positions;\n const lengths = polyline._segments.lengths;\n const positionsLength = positions.length;\n\n let segmentIndex = 0;\n let count = 0;\n\n for (let j = 0; j < positionsLength; ++j) {\n let prevPosition;\n if (j === 0) {\n if (polyline._loop) {\n prevPosition = positions[positionsLength - 2];\n } else {\n prevPosition = morphVectorScratch;\n Cartesian3.subtract(positions[0], positions[1], prevPosition);\n Cartesian3.add(positions[0], prevPosition, prevPosition);\n }\n } else {\n prevPosition = positions[j - 1];\n }\n\n prevPosition = Matrix4.multiplyByPoint(\n modelMatrix,\n prevPosition,\n morphPrevPositionScratch\n );\n\n const position = Matrix4.multiplyByPoint(\n modelMatrix,\n positions[j],\n morphPositionScratch\n );\n\n let nextPosition;\n if (j === positionsLength - 1) {\n if (polyline._loop) {\n nextPosition = positions[1];\n } else {\n nextPosition = morphVectorScratch;\n Cartesian3.subtract(\n positions[positionsLength - 1],\n positions[positionsLength - 2],\n nextPosition\n );\n Cartesian3.add(\n positions[positionsLength - 1],\n nextPosition,\n nextPosition\n );\n }\n } else {\n nextPosition = positions[j + 1];\n }\n\n nextPosition = Matrix4.multiplyByPoint(\n modelMatrix,\n nextPosition,\n morphNextPositionScratch\n );\n\n const segmentLength = lengths[segmentIndex];\n if (j === count + segmentLength) {\n count += segmentLength;\n ++segmentIndex;\n }\n\n const segmentStart = j - count === 0;\n const segmentEnd = j === count + lengths[segmentIndex] - 1;\n\n const startK = segmentStart ? 2 : 0;\n const endK = segmentEnd ? 2 : 4;\n\n for (let k = startK; k < endK; ++k) {\n EncodedCartesian3.writeElements(position, positionArray, positionIndex);\n EncodedCartesian3.writeElements(\n prevPosition,\n positionArray,\n positionIndex + 6\n );\n EncodedCartesian3.writeElements(\n nextPosition,\n positionArray,\n positionIndex + 12\n );\n\n positionIndex += 6 * 3;\n }\n }\n }\n};\n\nconst scratchSegmentLengths = new Array(1);\n\nPolylineBucket.prototype.updateIndices = function (\n totalIndices,\n vertexBufferOffset,\n vertexArrayBuckets,\n offset\n) {\n let vaCount = vertexArrayBuckets.length - 1;\n let bucketLocator = new VertexArrayBucketLocator(0, offset, this);\n vertexArrayBuckets[vaCount].push(bucketLocator);\n let count = 0;\n let indices = totalIndices[totalIndices.length - 1];\n let indicesCount = 0;\n if (indices.length > 0) {\n indicesCount = indices[indices.length - 1] + 1;\n }\n const polylines = this.polylines;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n const polyline = polylines[i];\n polyline._locatorBuckets = [];\n\n let segments;\n if (this.mode === SceneMode.SCENE3D) {\n segments = scratchSegmentLengths;\n const positionsLength = polyline._actualPositions.length;\n if (positionsLength > 0) {\n segments[0] = positionsLength;\n } else {\n continue;\n }\n } else {\n segments = polyline._segments.lengths;\n }\n\n const numberOfSegments = segments.length;\n if (numberOfSegments > 0) {\n let segmentIndexCount = 0;\n for (let j = 0; j < numberOfSegments; ++j) {\n const segmentLength = segments[j] - 1.0;\n for (let k = 0; k < segmentLength; ++k) {\n if (indicesCount + 4 > CesiumMath.SIXTY_FOUR_KILOBYTES) {\n polyline._locatorBuckets.push({\n locator: bucketLocator,\n count: segmentIndexCount,\n });\n segmentIndexCount = 0;\n vertexBufferOffset.push(4);\n indices = [];\n totalIndices.push(indices);\n indicesCount = 0;\n bucketLocator.count = count;\n count = 0;\n offset = 0;\n bucketLocator = new VertexArrayBucketLocator(0, 0, this);\n vertexArrayBuckets[++vaCount] = [bucketLocator];\n }\n\n indices.push(indicesCount, indicesCount + 2, indicesCount + 1);\n indices.push(indicesCount + 1, indicesCount + 2, indicesCount + 3);\n\n segmentIndexCount += 6;\n count += 6;\n offset += 6;\n indicesCount += 4;\n }\n }\n\n polyline._locatorBuckets.push({\n locator: bucketLocator,\n count: segmentIndexCount,\n });\n\n if (indicesCount + 4 > CesiumMath.SIXTY_FOUR_KILOBYTES) {\n vertexBufferOffset.push(0);\n indices = [];\n totalIndices.push(indices);\n indicesCount = 0;\n bucketLocator.count = count;\n offset = 0;\n count = 0;\n bucketLocator = new VertexArrayBucketLocator(0, 0, this);\n vertexArrayBuckets[++vaCount] = [bucketLocator];\n }\n }\n polyline._clean();\n }\n bucketLocator.count = count;\n return offset;\n};\n\nPolylineBucket.prototype.getPolylineStartIndex = function (polyline) {\n const polylines = this.polylines;\n let positionIndex = 0;\n const length = polylines.length;\n for (let i = 0; i < length; ++i) {\n const p = polylines[i];\n if (p === polyline) {\n break;\n }\n positionIndex += p._actualLength;\n }\n return positionIndex;\n};\n\nconst scratchSegments = {\n positions: undefined,\n lengths: undefined,\n};\nconst scratchLengths = new Array(1);\nconst pscratch = new Cartesian3();\nconst scratchCartographic = new Cartographic();\n\nPolylineBucket.prototype.getSegments = function (polyline, projection) {\n let positions = polyline._actualPositions;\n\n if (this.mode === SceneMode.SCENE3D) {\n scratchLengths[0] = positions.length;\n scratchSegments.positions = positions;\n scratchSegments.lengths = scratchLengths;\n return scratchSegments;\n }\n\n if (intersectsIDL(polyline)) {\n positions = polyline._segments.positions;\n }\n\n const ellipsoid = projection.ellipsoid;\n const newPositions = [];\n const modelMatrix = this.modelMatrix;\n const length = positions.length;\n let position;\n let p = pscratch;\n\n for (let n = 0; n < length; ++n) {\n position = positions[n];\n p = Matrix4.multiplyByPoint(modelMatrix, position, p);\n newPositions.push(\n projection.project(\n ellipsoid.cartesianToCartographic(p, scratchCartographic)\n )\n );\n }\n\n if (newPositions.length > 0) {\n polyline._boundingVolume2D = BoundingSphere.fromPoints(\n newPositions,\n polyline._boundingVolume2D\n );\n const center2D = polyline._boundingVolume2D.center;\n polyline._boundingVolume2D.center = new Cartesian3(\n center2D.z,\n center2D.x,\n center2D.y\n );\n }\n\n scratchSegments.positions = newPositions;\n scratchSegments.lengths = polyline._segments.lengths;\n return scratchSegments;\n};\n\nlet scratchPositionsArray;\n\nPolylineBucket.prototype.writeUpdate = function (\n index,\n polyline,\n positionBuffer,\n projection\n) {\n const mode = this.mode;\n const maxLon = projection.ellipsoid.maximumRadius * CesiumMath.PI;\n\n let positionsLength = polyline._actualLength;\n if (positionsLength) {\n index += this.getPolylineStartIndex(polyline);\n\n let positionArray = scratchPositionsArray;\n const positionsArrayLength = 6 * positionsLength * 3;\n\n if (\n !defined(positionArray) ||\n positionArray.length < positionsArrayLength\n ) {\n positionArray = scratchPositionsArray = new Float32Array(\n positionsArrayLength\n );\n } else if (positionArray.length > positionsArrayLength) {\n positionArray = new Float32Array(\n positionArray.buffer,\n 0,\n positionsArrayLength\n );\n }\n\n const segments = this.getSegments(polyline, projection);\n const positions = segments.positions;\n const lengths = segments.lengths;\n\n let positionIndex = 0;\n let segmentIndex = 0;\n let count = 0;\n let position;\n\n positionsLength = positions.length;\n for (let i = 0; i < positionsLength; ++i) {\n if (i === 0) {\n if (polyline._loop) {\n position = positions[positionsLength - 2];\n } else {\n position = scratchWriteVector;\n Cartesian3.subtract(positions[0], positions[1], position);\n Cartesian3.add(positions[0], position, position);\n }\n } else {\n position = positions[i - 1];\n }\n\n Cartesian3.clone(position, scratchWritePrevPosition);\n Cartesian3.clone(positions[i], scratchWritePosition);\n\n if (i === positionsLength - 1) {\n if (polyline._loop) {\n position = positions[1];\n } else {\n position = scratchWriteVector;\n Cartesian3.subtract(\n positions[positionsLength - 1],\n positions[positionsLength - 2],\n position\n );\n Cartesian3.add(positions[positionsLength - 1], position, position);\n }\n } else {\n position = positions[i + 1];\n }\n\n Cartesian3.clone(position, scratchWriteNextPosition);\n\n const segmentLength = lengths[segmentIndex];\n if (i === count + segmentLength) {\n count += segmentLength;\n ++segmentIndex;\n }\n\n const segmentStart = i - count === 0;\n const segmentEnd = i === count + lengths[segmentIndex] - 1;\n\n if (mode === SceneMode.SCENE2D) {\n scratchWritePrevPosition.z = 0.0;\n scratchWritePosition.z = 0.0;\n scratchWriteNextPosition.z = 0.0;\n }\n\n if (mode === SceneMode.SCENE2D || mode === SceneMode.MORPHING) {\n if (\n (segmentStart || segmentEnd) &&\n maxLon - Math.abs(scratchWritePosition.x) < 1.0\n ) {\n if (\n (scratchWritePosition.x < 0.0 &&\n scratchWritePrevPosition.x > 0.0) ||\n (scratchWritePosition.x > 0.0 && scratchWritePrevPosition.x < 0.0)\n ) {\n Cartesian3.clone(scratchWritePosition, scratchWritePrevPosition);\n }\n\n if (\n (scratchWritePosition.x < 0.0 &&\n scratchWriteNextPosition.x > 0.0) ||\n (scratchWritePosition.x > 0.0 && scratchWriteNextPosition.x < 0.0)\n ) {\n Cartesian3.clone(scratchWritePosition, scratchWriteNextPosition);\n }\n }\n }\n\n const startJ = segmentStart ? 2 : 0;\n const endJ = segmentEnd ? 2 : 4;\n\n for (let j = startJ; j < endJ; ++j) {\n EncodedCartesian3.writeElements(\n scratchWritePosition,\n positionArray,\n positionIndex\n );\n EncodedCartesian3.writeElements(\n scratchWritePrevPosition,\n positionArray,\n positionIndex + 6\n );\n EncodedCartesian3.writeElements(\n scratchWriteNextPosition,\n positionArray,\n positionIndex + 12\n );\n positionIndex += 6 * 3;\n }\n }\n\n positionBuffer.copyFromArrayView(\n positionArray,\n 6 * 3 * Float32Array.BYTES_PER_ELEMENT * index\n );\n }\n};\nexport default PolylineCollection;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport BillboardCollection from \"./BillboardCollection.js\";\nimport Cesium3DTilePointFeature from \"./Cesium3DTilePointFeature.js\";\nimport HorizontalOrigin from \"./HorizontalOrigin.js\";\nimport LabelCollection from \"./LabelCollection.js\";\nimport LabelStyle from \"./LabelStyle.js\";\nimport PolylineCollection from \"./PolylineCollection.js\";\nimport VerticalOrigin from \"./VerticalOrigin.js\";\n\n/**\n * Creates a batch of points or billboards and labels.\n *\n * @alias Vector3DTilePoints\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Uint16Array} options.positions The positions of the polygons.\n * @param {number} options.minimumHeight The minimum height of the terrain covered by the tile.\n * @param {number} options.maximumHeight The maximum height of the terrain covered by the tile.\n * @param {Rectangle} options.rectangle The rectangle containing the tile.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table for the tile containing the batched polygons.\n * @param {Uint16Array} options.batchIds The batch ids for each polygon.\n *\n * @private\n */\nfunction Vector3DTilePoints(options) {\n // released after the first update\n this._positions = options.positions;\n\n this._batchTable = options.batchTable;\n this._batchIds = options.batchIds;\n\n this._rectangle = options.rectangle;\n this._minHeight = options.minimumHeight;\n this._maxHeight = options.maximumHeight;\n\n this._billboardCollection = new BillboardCollection({\n batchTable: options.batchTable,\n });\n this._labelCollection = new LabelCollection({\n batchTable: options.batchTable,\n });\n this._polylineCollection = new PolylineCollection();\n this._polylineCollection._useHighlightColor = true;\n\n this._packedBuffer = undefined;\n\n this._ready = false;\n this._promise = undefined;\n this._error = undefined;\n}\n\nObject.defineProperties(Vector3DTilePoints.prototype, {\n /**\n * Returns true if the points are ready to render\n *\n * @memberof Vector3DTilePoints.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n /**\n * Gets the number of points.\n *\n * @memberof Vector3DTilePoints.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n pointsLength: {\n get: function () {\n return this._billboardCollection.length;\n },\n },\n\n /**\n * Gets the texture atlas memory in bytes.\n *\n * @memberof Vector3DTilePoints.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n texturesByteLength: {\n get: function () {\n const billboardSize = this._billboardCollection.textureAtlas.texture\n .sizeInBytes;\n const labelSize = this._labelCollection._textureAtlas.texture.sizeInBytes;\n return billboardSize + labelSize;\n },\n },\n});\n\nfunction packBuffer(points, ellipsoid) {\n const rectangle = points._rectangle;\n const minimumHeight = points._minHeight;\n const maximumHeight = points._maxHeight;\n\n const packedLength = 2 + Rectangle.packedLength + Ellipsoid.packedLength;\n const packedBuffer = new Float64Array(packedLength);\n\n let offset = 0;\n packedBuffer[offset++] = minimumHeight;\n packedBuffer[offset++] = maximumHeight;\n\n Rectangle.pack(rectangle, packedBuffer, offset);\n offset += Rectangle.packedLength;\n\n Ellipsoid.pack(ellipsoid, packedBuffer, offset);\n\n return packedBuffer;\n}\n\nconst createVerticesTaskProcessor = new TaskProcessor(\n \"createVectorTilePoints\",\n 5\n);\nconst scratchPosition = new Cartesian3();\n\nfunction createPoints(points, ellipsoid) {\n let positions = points._positions;\n let packedBuffer = points._packedBuffer;\n\n if (!defined(packedBuffer)) {\n // Copy because they may be the views on the same buffer.\n positions = points._positions = positions.slice();\n points._batchIds = points._batchIds.slice();\n\n packedBuffer = points._packedBuffer = packBuffer(points, ellipsoid);\n }\n\n const transferrableObjects = [positions.buffer, packedBuffer.buffer];\n const parameters = {\n positions: positions.buffer,\n packedBuffer: packedBuffer.buffer,\n };\n\n const verticesPromise = createVerticesTaskProcessor.scheduleTask(\n parameters,\n transferrableObjects\n );\n if (!defined(verticesPromise)) {\n // Postponed\n return;\n }\n\n return verticesPromise\n .then((result) => {\n if (points.isDestroyed()) {\n return;\n }\n\n points._positions = new Float64Array(result.positions);\n const billboardCollection = points._billboardCollection;\n const labelCollection = points._labelCollection;\n const polylineCollection = points._polylineCollection;\n positions = points._positions;\n const batchIds = points._batchIds;\n const numberOfPoints = positions.length / 3;\n\n for (let i = 0; i < numberOfPoints; ++i) {\n const id = batchIds[i];\n\n const position = Cartesian3.unpack(positions, i * 3, scratchPosition);\n\n const b = billboardCollection.add();\n b.position = position;\n b._batchIndex = id;\n\n const l = labelCollection.add();\n l.text = \" \";\n l.position = position;\n l._batchIndex = id;\n\n const p = polylineCollection.add();\n p.positions = [Cartesian3.clone(position), Cartesian3.clone(position)];\n }\n\n points._positions = undefined;\n points._packedBuffer = undefined;\n points._ready = true;\n })\n .catch((error) => {\n if (points.isDestroyed()) {\n return;\n }\n\n // Throw the error next frame\n points._error = error;\n });\n}\n\n/**\n * Creates features for each point and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the point features will be placed.\n */\nVector3DTilePoints.prototype.createFeatures = function (content, features) {\n const billboardCollection = this._billboardCollection;\n const labelCollection = this._labelCollection;\n const polylineCollection = this._polylineCollection;\n\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n\n const billboard = billboardCollection.get(i);\n const label = labelCollection.get(i);\n const polyline = polylineCollection.get(i);\n\n features[batchId] = new Cesium3DTilePointFeature(\n content,\n batchId,\n billboard,\n label,\n polyline\n );\n }\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTilePoints.prototype.applyDebugSettings = function (enabled, color) {\n if (enabled) {\n Color.clone(color, this._billboardCollection._highlightColor);\n Color.clone(color, this._labelCollection._highlightColor);\n Color.clone(color, this._polylineCollection._highlightColor);\n } else {\n Color.clone(Color.WHITE, this._billboardCollection._highlightColor);\n Color.clone(Color.WHITE, this._labelCollection._highlightColor);\n Color.clone(Color.WHITE, this._polylineCollection._highlightColor);\n }\n};\n\nfunction clearStyle(polygons, features) {\n const batchIds = polygons._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.show = true;\n feature.pointSize = Cesium3DTilePointFeature.defaultPointSize;\n feature.color = Cesium3DTilePointFeature.defaultColor;\n feature.pointOutlineColor =\n Cesium3DTilePointFeature.defaultPointOutlineColor;\n feature.pointOutlineWidth =\n Cesium3DTilePointFeature.defaultPointOutlineWidth;\n feature.labelColor = Color.WHITE;\n feature.labelOutlineColor = Color.WHITE;\n feature.labelOutlineWidth = 1.0;\n feature.font = \"30px sans-serif\";\n feature.labelStyle = LabelStyle.FILL;\n feature.labelText = undefined;\n feature.backgroundColor = new Color(0.165, 0.165, 0.165, 0.8);\n feature.backgroundPadding = new Cartesian2(7, 5);\n feature.backgroundEnabled = false;\n feature.scaleByDistance = undefined;\n feature.translucencyByDistance = undefined;\n feature.distanceDisplayCondition = undefined;\n feature.heightOffset = 0.0;\n feature.anchorLineEnabled = false;\n feature.anchorLineColor = Color.WHITE;\n feature.image = undefined;\n feature.disableDepthTestDistance = 0.0;\n feature.horizontalOrigin = HorizontalOrigin.CENTER;\n feature.verticalOrigin = VerticalOrigin.CENTER;\n feature.labelHorizontalOrigin = HorizontalOrigin.RIGHT;\n feature.labelVerticalOrigin = VerticalOrigin.BASELINE;\n }\n}\n\nconst scratchColor = new Color();\nconst scratchColor2 = new Color();\nconst scratchColor3 = new Color();\nconst scratchColor4 = new Color();\nconst scratchColor5 = new Color();\nconst scratchColor6 = new Color();\nconst scratchScaleByDistance = new NearFarScalar();\nconst scratchTranslucencyByDistance = new NearFarScalar();\nconst scratchDistanceDisplayCondition = new DistanceDisplayCondition();\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The array of features.\n */\nVector3DTilePoints.prototype.applyStyle = function (style, features) {\n if (!defined(style)) {\n clearStyle(this, features);\n return;\n }\n\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n if (defined(style.show)) {\n feature.show = style.show.evaluate(feature);\n }\n\n if (defined(style.pointSize)) {\n feature.pointSize = style.pointSize.evaluate(feature);\n }\n\n if (defined(style.color)) {\n feature.color = style.color.evaluateColor(feature, scratchColor);\n }\n\n if (defined(style.pointOutlineColor)) {\n feature.pointOutlineColor = style.pointOutlineColor.evaluateColor(\n feature,\n scratchColor2\n );\n }\n\n if (defined(style.pointOutlineWidth)) {\n feature.pointOutlineWidth = style.pointOutlineWidth.evaluate(feature);\n }\n\n if (defined(style.labelColor)) {\n feature.labelColor = style.labelColor.evaluateColor(\n feature,\n scratchColor3\n );\n }\n\n if (defined(style.labelOutlineColor)) {\n feature.labelOutlineColor = style.labelOutlineColor.evaluateColor(\n feature,\n scratchColor4\n );\n }\n\n if (defined(style.labelOutlineWidth)) {\n feature.labelOutlineWidth = style.labelOutlineWidth.evaluate(feature);\n }\n\n if (defined(style.font)) {\n feature.font = style.font.evaluate(feature);\n }\n\n if (defined(style.labelStyle)) {\n feature.labelStyle = style.labelStyle.evaluate(feature);\n }\n\n if (defined(style.labelText)) {\n feature.labelText = style.labelText.evaluate(feature);\n } else {\n feature.labelText = undefined;\n }\n\n if (defined(style.backgroundColor)) {\n feature.backgroundColor = style.backgroundColor.evaluateColor(\n feature,\n scratchColor5\n );\n }\n\n if (defined(style.backgroundPadding)) {\n feature.backgroundPadding = style.backgroundPadding.evaluate(feature);\n }\n\n if (defined(style.backgroundEnabled)) {\n feature.backgroundEnabled = style.backgroundEnabled.evaluate(feature);\n }\n\n if (defined(style.scaleByDistance)) {\n const scaleByDistanceCart4 = style.scaleByDistance.evaluate(feature);\n if (defined(scaleByDistanceCart4)) {\n scratchScaleByDistance.near = scaleByDistanceCart4.x;\n scratchScaleByDistance.nearValue = scaleByDistanceCart4.y;\n scratchScaleByDistance.far = scaleByDistanceCart4.z;\n scratchScaleByDistance.farValue = scaleByDistanceCart4.w;\n feature.scaleByDistance = scratchScaleByDistance;\n } else {\n feature.scaleByDistance = undefined;\n }\n } else {\n feature.scaleByDistance = undefined;\n }\n\n if (defined(style.translucencyByDistance)) {\n const translucencyByDistanceCart4 = style.translucencyByDistance.evaluate(\n feature\n );\n if (defined(translucencyByDistanceCart4)) {\n scratchTranslucencyByDistance.near = translucencyByDistanceCart4.x;\n scratchTranslucencyByDistance.nearValue = translucencyByDistanceCart4.y;\n scratchTranslucencyByDistance.far = translucencyByDistanceCart4.z;\n scratchTranslucencyByDistance.farValue = translucencyByDistanceCart4.w;\n feature.translucencyByDistance = scratchTranslucencyByDistance;\n } else {\n feature.translucencyByDistance = undefined;\n }\n } else {\n feature.translucencyByDistance = undefined;\n }\n\n if (defined(style.distanceDisplayCondition)) {\n const distanceDisplayConditionCart2 = style.distanceDisplayCondition.evaluate(\n feature\n );\n if (defined(distanceDisplayConditionCart2)) {\n scratchDistanceDisplayCondition.near = distanceDisplayConditionCart2.x;\n scratchDistanceDisplayCondition.far = distanceDisplayConditionCart2.y;\n feature.distanceDisplayCondition = scratchDistanceDisplayCondition;\n } else {\n feature.distanceDisplayCondition = undefined;\n }\n } else {\n feature.distanceDisplayCondition = undefined;\n }\n\n if (defined(style.heightOffset)) {\n feature.heightOffset = style.heightOffset.evaluate(feature);\n }\n\n if (defined(style.anchorLineEnabled)) {\n feature.anchorLineEnabled = style.anchorLineEnabled.evaluate(feature);\n }\n\n if (defined(style.anchorLineColor)) {\n feature.anchorLineColor = style.anchorLineColor.evaluateColor(\n feature,\n scratchColor6\n );\n }\n\n if (defined(style.image)) {\n feature.image = style.image.evaluate(feature);\n } else {\n feature.image = undefined;\n }\n\n if (defined(style.disableDepthTestDistance)) {\n feature.disableDepthTestDistance = style.disableDepthTestDistance.evaluate(\n feature\n );\n }\n\n if (defined(style.horizontalOrigin)) {\n feature.horizontalOrigin = style.horizontalOrigin.evaluate(feature);\n }\n\n if (defined(style.verticalOrigin)) {\n feature.verticalOrigin = style.verticalOrigin.evaluate(feature);\n }\n\n if (defined(style.labelHorizontalOrigin)) {\n feature.labelHorizontalOrigin = style.labelHorizontalOrigin.evaluate(\n feature\n );\n }\n\n if (defined(style.labelVerticalOrigin)) {\n feature.labelVerticalOrigin = style.labelVerticalOrigin.evaluate(feature);\n }\n }\n};\n\n/**\n * @private\n */\nVector3DTilePoints.prototype.update = function (frameState) {\n if (!this._ready) {\n if (!defined(this._promise)) {\n this._promise = createPoints(this, frameState.mapProjection.ellipsoid);\n }\n\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n return;\n }\n\n this._polylineCollection.update(frameState);\n this._billboardCollection.update(frameState);\n this._labelCollection.update(frameState);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTilePoints.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTilePoints.prototype.destroy = function () {\n this._billboardCollection =\n this._billboardCollection && this._billboardCollection.destroy();\n this._labelCollection =\n this._labelCollection && this._labelCollection.destroy();\n this._polylineCollection =\n this._polylineCollection && this._polylineCollection.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTilePoints;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport Vector3DTileBatch from \"./Vector3DTileBatch.js\";\nimport Vector3DTilePrimitive from \"./Vector3DTilePrimitive.js\";\n\n/**\n * Creates a batch of pre-triangulated polygons draped on terrain and/or 3D Tiles.\n *\n * @alias Vector3DTilePolygons\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Float32Array|Uint16Array} options.positions The positions of the polygons. The positions must be contiguous\n * so that the positions for polygon n are in [c, c + counts[n]] where c = sum{counts[0], counts[n - 1]} and they are the outer ring of\n * the polygon in counter-clockwise order.\n * @param {Uint32Array} options.counts The number of positions in the each polygon.\n * @param {Uint32Array} options.indices The indices of the triangulated polygons. The indices must be contiguous so that\n * the indices for polygon n are in [i, i + indexCounts[n]] where i = sum{indexCounts[0], indexCounts[n - 1]}.\n * @param {Uint32Array} options.indexCounts The number of indices for each polygon.\n * @param {number} options.minimumHeight The minimum height of the terrain covered by the tile.\n * @param {number} options.maximumHeight The maximum height of the terrain covered by the tile.\n * @param {Float32Array} [options.polygonMinimumHeights] An array containing the minimum heights for each polygon.\n * @param {Float32Array} [options.polygonMaximumHeights] An array containing the maximum heights for each polygon.\n * @param {Rectangle} options.rectangle The rectangle containing the tile.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n * @param {Cartesian3} [options.center=Cartesian3.ZERO] The RTC center.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table for the tile containing the batched polygons.\n * @param {Uint16Array} options.batchIds The batch ids for each polygon.\n * @param {BoundingSphere} options.boundingVolume The bounding volume for the entire batch of polygons.\n *\n * @private\n */\nfunction Vector3DTilePolygons(options) {\n // All of the private properties will be released except _primitive after the Vector3DTilePrimitive is created.\n this._batchTable = options.batchTable;\n\n this._batchIds = options.batchIds;\n this._positions = options.positions;\n this._counts = options.counts;\n\n this._indices = options.indices;\n this._indexCounts = options.indexCounts;\n this._indexOffsets = undefined;\n\n this._batchTableColors = undefined;\n this._packedBuffer = undefined;\n\n this._batchedPositions = undefined;\n this._transferrableBatchIds = undefined;\n this._vertexBatchIds = undefined;\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n this._minimumHeight = options.minimumHeight;\n this._maximumHeight = options.maximumHeight;\n this._polygonMinimumHeights = options.polygonMinimumHeights;\n this._polygonMaximumHeights = options.polygonMaximumHeights;\n this._center = defaultValue(options.center, Cartesian3.ZERO);\n this._rectangle = options.rectangle;\n\n this._center = undefined;\n\n this._boundingVolume = options.boundingVolume;\n this._boundingVolumes = undefined;\n\n this._batchedIndices = undefined;\n\n this._ready = false;\n this._promise = undefined;\n this._error = undefined;\n this._primitive = undefined;\n\n /**\n * Draws the wireframe of the classification meshes.\n * @type {boolean}\n * @default false\n */\n this.debugWireframe = false;\n\n /**\n * Forces a re-batch instead of waiting after a number of frames have been rendered. For testing only.\n * @type {boolean}\n * @default false\n */\n this.forceRebatch = false;\n\n /**\n * What this tile will classify.\n * @type {ClassificationType}\n * @default ClassificationType.BOTH\n */\n this.classificationType = ClassificationType.BOTH;\n}\n\nObject.defineProperties(Vector3DTilePolygons.prototype, {\n /**\n * Gets the number of triangles.\n *\n * @memberof Vector3DTilePolygons.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n trianglesLength: {\n get: function () {\n if (defined(this._primitive)) {\n return this._primitive.trianglesLength;\n }\n return 0;\n },\n },\n\n /**\n * Gets the geometry memory in bytes.\n *\n * @memberof Vector3DTilePolygons.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n geometryByteLength: {\n get: function () {\n if (defined(this._primitive)) {\n return this._primitive.geometryByteLength;\n }\n return 0;\n },\n },\n\n /**\n * Returns true when the primitive is ready to render.\n * @memberof Vector3DTilePolygons.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nfunction packBuffer(polygons) {\n const packedBuffer = new Float64Array(\n 3 +\n Cartesian3.packedLength +\n Ellipsoid.packedLength +\n Rectangle.packedLength\n );\n\n let offset = 0;\n packedBuffer[offset++] = polygons._indices.BYTES_PER_ELEMENT;\n\n packedBuffer[offset++] = polygons._minimumHeight;\n packedBuffer[offset++] = polygons._maximumHeight;\n\n Cartesian3.pack(polygons._center, packedBuffer, offset);\n offset += Cartesian3.packedLength;\n\n Ellipsoid.pack(polygons._ellipsoid, packedBuffer, offset);\n offset += Ellipsoid.packedLength;\n\n Rectangle.pack(polygons._rectangle, packedBuffer, offset);\n\n return packedBuffer;\n}\n\nfunction unpackBuffer(polygons, packedBuffer) {\n let offset = 1;\n\n const numBVS = packedBuffer[offset++];\n const bvs = (polygons._boundingVolumes = new Array(numBVS));\n\n for (let i = 0; i < numBVS; ++i) {\n bvs[i] = OrientedBoundingBox.unpack(packedBuffer, offset);\n offset += OrientedBoundingBox.packedLength;\n }\n\n const numBatchedIndices = packedBuffer[offset++];\n const bis = (polygons._batchedIndices = new Array(numBatchedIndices));\n\n for (let j = 0; j < numBatchedIndices; ++j) {\n const color = Color.unpack(packedBuffer, offset);\n offset += Color.packedLength;\n\n const indexOffset = packedBuffer[offset++];\n const count = packedBuffer[offset++];\n\n const length = packedBuffer[offset++];\n const batchIds = new Array(length);\n\n for (let k = 0; k < length; ++k) {\n batchIds[k] = packedBuffer[offset++];\n }\n\n bis[j] = new Vector3DTileBatch({\n color: color,\n offset: indexOffset,\n count: count,\n batchIds: batchIds,\n });\n }\n}\n\nconst createVerticesTaskProcessor = new TaskProcessor(\n \"createVectorTilePolygons\",\n 5\n);\nconst scratchColor = new Color();\n\nfunction createPrimitive(polygons) {\n if (defined(polygons._primitive)) {\n return;\n }\n\n let positions = polygons._positions;\n let counts = polygons._counts;\n let indexCounts = polygons._indexCounts;\n let indices = polygons._indices;\n\n let batchIds = polygons._transferrableBatchIds;\n let batchTableColors = polygons._batchTableColors;\n\n let packedBuffer = polygons._packedBuffer;\n\n if (!defined(batchTableColors)) {\n // Copy because they may be the views on the same buffer.\n positions = polygons._positions = polygons._positions.slice();\n counts = polygons._counts = polygons._counts.slice();\n indexCounts = polygons._indexCounts = polygons._indexCounts.slice();\n indices = polygons._indices = polygons._indices.slice();\n\n polygons._center = polygons._ellipsoid.cartographicToCartesian(\n Rectangle.center(polygons._rectangle)\n );\n\n batchIds = polygons._transferrableBatchIds = new Uint32Array(\n polygons._batchIds\n );\n batchTableColors = polygons._batchTableColors = new Uint32Array(\n batchIds.length\n );\n const batchTable = polygons._batchTable;\n\n const length = batchTableColors.length;\n for (let i = 0; i < length; ++i) {\n const color = batchTable.getColor(i, scratchColor);\n batchTableColors[i] = color.toRgba();\n }\n\n packedBuffer = polygons._packedBuffer = packBuffer(polygons);\n }\n\n const transferrableObjects = [\n positions.buffer,\n counts.buffer,\n indexCounts.buffer,\n indices.buffer,\n batchIds.buffer,\n batchTableColors.buffer,\n packedBuffer.buffer,\n ];\n const parameters = {\n packedBuffer: packedBuffer.buffer,\n positions: positions.buffer,\n counts: counts.buffer,\n indexCounts: indexCounts.buffer,\n indices: indices.buffer,\n batchIds: batchIds.buffer,\n batchTableColors: batchTableColors.buffer,\n };\n\n let minimumHeights = polygons._polygonMinimumHeights;\n let maximumHeights = polygons._polygonMaximumHeights;\n if (defined(minimumHeights) && defined(maximumHeights)) {\n minimumHeights = minimumHeights.slice();\n maximumHeights = maximumHeights.slice();\n\n transferrableObjects.push(minimumHeights.buffer, maximumHeights.buffer);\n parameters.minimumHeights = minimumHeights;\n parameters.maximumHeights = maximumHeights;\n }\n\n const verticesPromise = createVerticesTaskProcessor.scheduleTask(\n parameters,\n transferrableObjects\n );\n if (!defined(verticesPromise)) {\n // Postponed\n return;\n }\n\n return verticesPromise\n .then((result) => {\n if (polygons.isDestroyed()) {\n return;\n }\n\n polygons._positions = undefined;\n polygons._counts = undefined;\n polygons._polygonMinimumHeights = undefined;\n polygons._polygonMaximumHeights = undefined;\n\n const packedBuffer = new Float64Array(result.packedBuffer);\n const indexDatatype = packedBuffer[0];\n unpackBuffer(polygons, packedBuffer);\n\n polygons._indices =\n IndexDatatype.getSizeInBytes(indexDatatype) === 2\n ? new Uint16Array(result.indices)\n : new Uint32Array(result.indices);\n polygons._indexOffsets = new Uint32Array(result.indexOffsets);\n polygons._indexCounts = new Uint32Array(result.indexCounts);\n\n // will be released\n polygons._batchedPositions = new Float32Array(result.positions);\n polygons._vertexBatchIds = new Uint16Array(result.batchIds);\n\n finishPrimitive(polygons);\n\n polygons._ready = true;\n })\n .catch((error) => {\n if (polygons.isDestroyed()) {\n return;\n }\n\n // Throw the error next frame\n polygons._error = error;\n });\n}\n\nfunction finishPrimitive(polygons) {\n if (!defined(polygons._primitive)) {\n polygons._primitive = new Vector3DTilePrimitive({\n batchTable: polygons._batchTable,\n positions: polygons._batchedPositions,\n batchIds: polygons._batchIds,\n vertexBatchIds: polygons._vertexBatchIds,\n indices: polygons._indices,\n indexOffsets: polygons._indexOffsets,\n indexCounts: polygons._indexCounts,\n batchedIndices: polygons._batchedIndices,\n boundingVolume: polygons._boundingVolume,\n boundingVolumes: polygons._boundingVolumes,\n center: polygons._center,\n });\n\n polygons._batchTable = undefined;\n polygons._batchIds = undefined;\n polygons._positions = undefined;\n polygons._counts = undefined;\n polygons._indices = undefined;\n polygons._indexCounts = undefined;\n polygons._indexOffsets = undefined;\n polygons._batchTableColors = undefined;\n polygons._packedBuffer = undefined;\n polygons._batchedPositions = undefined;\n polygons._transferrableBatchIds = undefined;\n polygons._vertexBatchIds = undefined;\n polygons._ellipsoid = undefined;\n polygons._minimumHeight = undefined;\n polygons._maximumHeight = undefined;\n polygons._polygonMinimumHeights = undefined;\n polygons._polygonMaximumHeights = undefined;\n polygons._center = undefined;\n polygons._rectangle = undefined;\n polygons._boundingVolume = undefined;\n polygons._boundingVolumes = undefined;\n polygons._batchedIndices = undefined;\n }\n}\n\n/**\n * Creates features for each polygon and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the polygon features will be placed.\n */\nVector3DTilePolygons.prototype.createFeatures = function (content, features) {\n this._primitive.createFeatures(content, features);\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (polygon batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTilePolygons.prototype.applyDebugSettings = function (enabled, color) {\n this._primitive.applyDebugSettings(enabled, color);\n};\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The array of features.\n */\nVector3DTilePolygons.prototype.applyStyle = function (style, features) {\n this._primitive.applyStyle(style, features);\n};\n\n/**\n * Call when updating the color of a polygon with batchId changes color. The polygons will need to be re-batched\n * on the next update.\n *\n * @param {number} batchId The batch id of the polygon whose color has changed.\n * @param {Color} color The new polygon color.\n */\nVector3DTilePolygons.prototype.updateCommands = function (batchId, color) {\n this._primitive.updateCommands(batchId, color);\n};\n\n/**\n * Updates the batches and queues the commands for rendering.\n *\n * @param {FrameState} frameState The current frame state.\n */\nVector3DTilePolygons.prototype.update = function (frameState) {\n if (!this._ready) {\n if (!defined(this._promise)) {\n this._promise = createPrimitive(this);\n }\n\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n return;\n }\n\n this._primitive.debugWireframe = this.debugWireframe;\n this._primitive.forceRebatch = this.forceRebatch;\n this._primitive.classificationType = this.classificationType;\n this._primitive.update(frameState);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTilePolygons.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTilePolygons.prototype.destroy = function () {\n this._primitive = this._primitive && this._primitive.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTilePolygons;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 currentPosition;\\n\\\nin vec4 previousPosition;\\n\\\nin vec4 nextPosition;\\n\\\nin vec2 expandAndWidth;\\n\\\nin float a_batchId;\\n\\\n\\n\\\nuniform mat4 u_modifiedModelView;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n float expandDir = expandAndWidth.x;\\n\\\n float width = abs(expandAndWidth.y) + 0.5;\\n\\\n bool usePrev = expandAndWidth.y < 0.0;\\n\\\n\\n\\\n vec4 p = u_modifiedModelView * currentPosition;\\n\\\n vec4 prev = u_modifiedModelView * previousPosition;\\n\\\n vec4 next = u_modifiedModelView * nextPosition;\\n\\\n\\n\\\n float angle;\\n\\\n vec4 positionWC = getPolylineWindowCoordinatesEC(p, prev, next, expandDir, width, usePrev, angle);\\n\\\n gl_Position = czm_viewportOrthographic * positionWC;\\n\\\n}\\n\\\n\";\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport PolylineCommon from \"../Shaders/PolylineCommon.js\";\nimport Vector3DTilePolylinesVS from \"../Shaders/Vector3DTilePolylinesVS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport Cesium3DTileFeature from \"./Cesium3DTileFeature.js\";\n\n/**\n * Creates a batch of polylines that have been subdivided to be draped on terrain.\n *\n * @alias Vector3DTilePolylines\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Uint16Array} options.positions The positions of the polylines\n * @param {Uint32Array} options.counts The number or positions in the each polyline.\n * @param {Uint16Array} options.widths The width of each polyline.\n * @param {number} options.minimumHeight The minimum height of the terrain covered by the tile.\n * @param {number} options.maximumHeight The maximum height of the terrain covered by the tile.\n * @param {Rectangle} options.rectangle The rectangle containing the tile.\n * @param {Cartesian3} [options.center=Cartesian3.ZERO] The RTC center.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table for the tile containing the batched polylines.\n * @param {Uint16Array} options.batchIds The batch ids for each polyline.\n * @param {BoundingSphere} options.boundingVolume The bounding volume for the entire batch of polylines.\n * @param {boolean} options.keepDecodedPositions Whether to keep decoded positions in memory.\n *\n * @private\n */\nfunction Vector3DTilePolylines(options) {\n // these arrays are all released after the first update.\n this._positions = options.positions;\n this._widths = options.widths;\n this._counts = options.counts;\n this._batchIds = options.batchIds;\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n this._minimumHeight = options.minimumHeight;\n this._maximumHeight = options.maximumHeight;\n this._center = options.center;\n this._rectangle = options.rectangle;\n\n this._boundingVolume = options.boundingVolume;\n this._batchTable = options.batchTable;\n\n this._va = undefined;\n this._sp = undefined;\n this._rs = undefined;\n this._uniformMap = undefined;\n this._command = undefined;\n\n this._transferrableBatchIds = undefined;\n this._packedBuffer = undefined;\n\n this._keepDecodedPositions = options.keepDecodedPositions;\n this._decodedPositions = undefined;\n this._decodedPositionOffsets = undefined;\n\n this._currentPositions = undefined;\n this._previousPositions = undefined;\n this._nextPositions = undefined;\n this._expandAndWidth = undefined;\n this._vertexBatchIds = undefined;\n this._indices = undefined;\n\n this._constantColor = Color.clone(Color.WHITE);\n this._highlightColor = this._constantColor;\n\n this._trianglesLength = 0;\n this._geometryByteLength = 0;\n\n this._ready = false;\n this._promise = undefined;\n this._error = undefined;\n}\n\nObject.defineProperties(Vector3DTilePolylines.prototype, {\n /**\n * Gets the number of triangles.\n *\n * @memberof Vector3DTilePolylines.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n trianglesLength: {\n get: function () {\n return this._trianglesLength;\n },\n },\n\n /**\n * Gets the geometry memory in bytes.\n *\n * @memberof Vector3DTilePolylines.prototype\n *\n * @type {number}\n * @readonly\n * @private\n */\n geometryByteLength: {\n get: function () {\n return this._geometryByteLength;\n },\n },\n\n /**\n * Returns true when the primitive is ready to render.\n * @memberof Vector3DTilePolylines.prototype\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nfunction packBuffer(polylines) {\n const rectangle = polylines._rectangle;\n const minimumHeight = polylines._minimumHeight;\n const maximumHeight = polylines._maximumHeight;\n const ellipsoid = polylines._ellipsoid;\n const center = polylines._center;\n\n const packedLength =\n 2 +\n Rectangle.packedLength +\n Ellipsoid.packedLength +\n Cartesian3.packedLength;\n const packedBuffer = new Float64Array(packedLength);\n\n let offset = 0;\n packedBuffer[offset++] = minimumHeight;\n packedBuffer[offset++] = maximumHeight;\n\n Rectangle.pack(rectangle, packedBuffer, offset);\n offset += Rectangle.packedLength;\n\n Ellipsoid.pack(ellipsoid, packedBuffer, offset);\n offset += Ellipsoid.packedLength;\n\n Cartesian3.pack(center, packedBuffer, offset);\n\n return packedBuffer;\n}\n\nconst createVerticesTaskProcessor = new TaskProcessor(\n \"createVectorTilePolylines\",\n 5\n);\nconst attributeLocations = {\n previousPosition: 0,\n currentPosition: 1,\n nextPosition: 2,\n expandAndWidth: 3,\n a_batchId: 4,\n};\n\nfunction createVertexArray(polylines, context) {\n if (defined(polylines._va)) {\n return;\n }\n\n let positions = polylines._positions;\n let widths = polylines._widths;\n let counts = polylines._counts;\n let batchIds = polylines._transferrableBatchIds;\n\n let packedBuffer = polylines._packedBuffer;\n\n if (!defined(packedBuffer)) {\n // Copy because they may be the views on the same buffer.\n positions = polylines._positions = positions.slice();\n widths = polylines._widths = widths.slice();\n counts = polylines._counts = counts.slice();\n\n batchIds = polylines._transferrableBatchIds = polylines._batchIds.slice();\n\n packedBuffer = polylines._packedBuffer = packBuffer(polylines);\n }\n\n const transferrableObjects = [\n positions.buffer,\n widths.buffer,\n counts.buffer,\n batchIds.buffer,\n packedBuffer.buffer,\n ];\n const parameters = {\n positions: positions.buffer,\n widths: widths.buffer,\n counts: counts.buffer,\n batchIds: batchIds.buffer,\n packedBuffer: packedBuffer.buffer,\n keepDecodedPositions: polylines._keepDecodedPositions,\n };\n\n const verticesPromise = createVerticesTaskProcessor.scheduleTask(\n parameters,\n transferrableObjects\n );\n if (!defined(verticesPromise)) {\n // Postponed\n return;\n }\n\n return verticesPromise\n .then(function (result) {\n if (polylines.isDestroyed()) {\n return;\n }\n\n if (polylines._keepDecodedPositions) {\n polylines._decodedPositions = new Float64Array(result.decodedPositions);\n polylines._decodedPositionOffsets = new Uint32Array(\n result.decodedPositionOffsets\n );\n }\n\n polylines._currentPositions = new Float32Array(result.currentPositions);\n polylines._previousPositions = new Float32Array(result.previousPositions);\n polylines._nextPositions = new Float32Array(result.nextPositions);\n polylines._expandAndWidth = new Float32Array(result.expandAndWidth);\n polylines._vertexBatchIds = new Uint16Array(result.batchIds);\n\n const indexDatatype = result.indexDatatype;\n polylines._indices =\n indexDatatype === IndexDatatype.UNSIGNED_SHORT\n ? new Uint16Array(result.indices)\n : new Uint32Array(result.indices);\n\n finishVertexArray(polylines, context);\n\n polylines._ready = true;\n })\n .catch((error) => {\n if (polylines.isDestroyed()) {\n return;\n }\n\n // Throw the error next frame\n polylines._error = error;\n });\n}\n\nfunction finishVertexArray(polylines, context) {\n if (!defined(polylines._va)) {\n const curPositions = polylines._currentPositions;\n const prevPositions = polylines._previousPositions;\n const nextPositions = polylines._nextPositions;\n const expandAndWidth = polylines._expandAndWidth;\n const vertexBatchIds = polylines._vertexBatchIds;\n const indices = polylines._indices;\n\n let byteLength =\n prevPositions.byteLength +\n curPositions.byteLength +\n nextPositions.byteLength;\n byteLength +=\n expandAndWidth.byteLength +\n vertexBatchIds.byteLength +\n indices.byteLength;\n polylines._trianglesLength = indices.length / 3;\n polylines._geometryByteLength = byteLength;\n\n const prevPositionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: prevPositions,\n usage: BufferUsage.STATIC_DRAW,\n });\n const curPositionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: curPositions,\n usage: BufferUsage.STATIC_DRAW,\n });\n const nextPositionBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: nextPositions,\n usage: BufferUsage.STATIC_DRAW,\n });\n const expandAndWidthBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: expandAndWidth,\n usage: BufferUsage.STATIC_DRAW,\n });\n const idBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: vertexBatchIds,\n usage: BufferUsage.STATIC_DRAW,\n });\n\n const indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: indices,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype:\n indices.BYTES_PER_ELEMENT === 2\n ? IndexDatatype.UNSIGNED_SHORT\n : IndexDatatype.UNSIGNED_INT,\n });\n\n const vertexAttributes = [\n {\n index: attributeLocations.previousPosition,\n vertexBuffer: prevPositionBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n index: attributeLocations.currentPosition,\n vertexBuffer: curPositionBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n index: attributeLocations.nextPosition,\n vertexBuffer: nextPositionBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n index: attributeLocations.expandAndWidth,\n vertexBuffer: expandAndWidthBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n },\n {\n index: attributeLocations.a_batchId,\n vertexBuffer: idBuffer,\n componentDatatype: ComponentDatatype.UNSIGNED_SHORT,\n componentsPerAttribute: 1,\n },\n ];\n\n polylines._va = new VertexArray({\n context: context,\n attributes: vertexAttributes,\n indexBuffer: indexBuffer,\n });\n\n polylines._positions = undefined;\n polylines._widths = undefined;\n polylines._counts = undefined;\n\n polylines._ellipsoid = undefined;\n polylines._minimumHeight = undefined;\n polylines._maximumHeight = undefined;\n polylines._rectangle = undefined;\n\n polylines._transferrableBatchIds = undefined;\n polylines._packedBuffer = undefined;\n\n polylines._currentPositions = undefined;\n polylines._previousPositions = undefined;\n polylines._nextPositions = undefined;\n polylines._expandAndWidth = undefined;\n polylines._vertexBatchIds = undefined;\n polylines._indices = undefined;\n }\n}\n\nconst modifiedModelViewScratch = new Matrix4();\nconst rtcScratch = new Cartesian3();\n\nfunction createUniformMap(primitive, context) {\n if (defined(primitive._uniformMap)) {\n return;\n }\n\n primitive._uniformMap = {\n u_modifiedModelView: function () {\n const viewMatrix = context.uniformState.view;\n Matrix4.clone(viewMatrix, modifiedModelViewScratch);\n Matrix4.multiplyByPoint(\n modifiedModelViewScratch,\n primitive._center,\n rtcScratch\n );\n Matrix4.setTranslation(\n modifiedModelViewScratch,\n rtcScratch,\n modifiedModelViewScratch\n );\n return modifiedModelViewScratch;\n },\n u_highlightColor: function () {\n return primitive._highlightColor;\n },\n };\n}\n\nfunction createRenderStates(primitive) {\n if (defined(primitive._rs)) {\n return;\n }\n\n const polygonOffset = {\n enabled: true,\n factor: -5.0,\n units: -5.0,\n };\n\n primitive._rs = RenderState.fromCache({\n blending: BlendingState.ALPHA_BLEND,\n depthMask: false,\n depthTest: {\n enabled: true,\n },\n polygonOffset: polygonOffset,\n });\n}\n\nconst PolylineFS =\n \"uniform vec4 u_highlightColor; \\n\" +\n \"void main()\\n\" +\n \"{\\n\" +\n \" out_FragColor = u_highlightColor;\\n\" +\n \"}\\n\";\n\nfunction createShaders(primitive, context) {\n if (defined(primitive._sp)) {\n return;\n }\n\n const batchTable = primitive._batchTable;\n\n const vsSource = batchTable.getVertexShaderCallback(\n false,\n \"a_batchId\",\n undefined\n )(Vector3DTilePolylinesVS);\n const fsSource = batchTable.getFragmentShaderCallback(\n false,\n undefined,\n false\n )(PolylineFS);\n\n const vs = new ShaderSource({\n defines: [\n \"VECTOR_TILE\",\n !FeatureDetection.isInternetExplorer() ? \"CLIP_POLYLINE\" : \"\",\n ],\n sources: [PolylineCommon, vsSource],\n });\n const fs = new ShaderSource({\n defines: [\"VECTOR_TILE\"],\n sources: [fsSource],\n });\n\n primitive._sp = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n}\n\nfunction queueCommands(primitive, frameState) {\n if (!defined(primitive._command)) {\n const uniformMap = primitive._batchTable.getUniformMapCallback()(\n primitive._uniformMap\n );\n primitive._command = new DrawCommand({\n owner: primitive,\n vertexArray: primitive._va,\n renderState: primitive._rs,\n shaderProgram: primitive._sp,\n uniformMap: uniformMap,\n boundingVolume: primitive._boundingVolume,\n pass: Pass.TRANSLUCENT,\n pickId: primitive._batchTable.getPickId(),\n });\n }\n\n frameState.commandList.push(primitive._command);\n}\n\nVector3DTilePolylines.getPolylinePositions = function (polylines, batchId) {\n const batchIds = polylines._batchIds;\n const positions = polylines._decodedPositions;\n const offsets = polylines._decodedPositionOffsets;\n\n if (!defined(batchIds) || !defined(positions)) {\n return undefined;\n }\n\n let i;\n let j;\n const polylinesLength = batchIds.length;\n let positionsLength = 0;\n let resultCounter = 0;\n\n for (i = 0; i < polylinesLength; ++i) {\n if (batchIds[i] === batchId) {\n positionsLength += offsets[i + 1] - offsets[i];\n }\n }\n\n if (positionsLength === 0) {\n return undefined;\n }\n\n const results = new Float64Array(positionsLength * 3);\n\n for (i = 0; i < polylinesLength; ++i) {\n if (batchIds[i] === batchId) {\n const offset = offsets[i];\n const count = offsets[i + 1] - offset;\n for (j = 0; j < count; ++j) {\n const decodedOffset = (offset + j) * 3;\n results[resultCounter++] = positions[decodedOffset];\n results[resultCounter++] = positions[decodedOffset + 1];\n results[resultCounter++] = positions[decodedOffset + 2];\n }\n }\n }\n\n return results;\n};\n\n/**\n * Get the polyline positions for the given feature.\n *\n * @param {number} batchId The batch ID of the feature.\n */\nVector3DTilePolylines.prototype.getPositions = function (batchId) {\n return Vector3DTilePolylines.getPolylinePositions(this, batchId);\n};\n\n/**\n * Creates features for each polyline and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the polygon features will be placed.\n */\nVector3DTilePolylines.prototype.createFeatures = function (content, features) {\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n features[batchId] = new Cesium3DTileFeature(content, batchId);\n }\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (polyline batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTilePolylines.prototype.applyDebugSettings = function (enabled, color) {\n this._highlightColor = enabled ? color : this._constantColor;\n};\n\nfunction clearStyle(polygons, features) {\n const batchIds = polygons._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.show = true;\n feature.color = Color.WHITE;\n }\n}\n\nconst scratchColor = new Color();\n\nconst DEFAULT_COLOR_VALUE = Color.WHITE;\nconst DEFAULT_SHOW_VALUE = true;\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The array of features.\n */\nVector3DTilePolylines.prototype.applyStyle = function (style, features) {\n if (!defined(style)) {\n clearStyle(this, features);\n return;\n }\n\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.color = defined(style.color)\n ? style.color.evaluateColor(feature, scratchColor)\n : DEFAULT_COLOR_VALUE;\n feature.show = defined(style.show)\n ? style.show.evaluate(feature)\n : DEFAULT_SHOW_VALUE;\n }\n};\n\n/**\n * Updates the batches and queues the commands for rendering.\n *\n * @param {FrameState} frameState The current frame state.\n */\nVector3DTilePolylines.prototype.update = function (frameState) {\n const context = frameState.context;\n if (!this._ready) {\n if (!defined(this._promise)) {\n this._promise = createVertexArray(this, context);\n }\n\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n return;\n }\n\n createUniformMap(this, context);\n createShaders(this, context);\n createRenderStates(this);\n\n const passes = frameState.passes;\n if (passes.render || passes.pick) {\n queueCommands(this, frameState);\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTilePolylines.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTilePolylines.prototype.destroy = function () {\n this._va = this._va && this._va.destroy();\n this._sp = this._sp && this._sp.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTilePolylines;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec3 startEllipsoidNormal;\\n\\\nin vec3 endEllipsoidNormal;\\n\\\nin vec4 startPositionAndHeight;\\n\\\nin vec4 endPositionAndHeight;\\n\\\nin vec4 startFaceNormalAndVertexCorner;\\n\\\nin vec4 endFaceNormalAndHalfWidth;\\n\\\nin float a_batchId;\\n\\\n\\n\\\nuniform mat4 u_modifiedModelView;\\n\\\nuniform vec2 u_minimumMaximumVectorHeights;\\n\\\n\\n\\\nout vec4 v_startPlaneEC;\\n\\\nout vec4 v_endPlaneEC;\\n\\\nout vec4 v_rightPlaneEC;\\n\\\nout float v_halfWidth;\\n\\\nout vec3 v_volumeUpEC;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n // vertex corner IDs\\n\\\n // 3-----------7\\n\\\n // /| left /|\\n\\\n // / | 1 / |\\n\\\n // 2-----------6 5 end\\n\\\n // | / | /\\n\\\n // start |/ right |/\\n\\\n // 0-----------4\\n\\\n //\\n\\\n float isEnd = floor(startFaceNormalAndVertexCorner.w * 0.251); // 0 for front, 1 for end\\n\\\n float isTop = floor(startFaceNormalAndVertexCorner.w * mix(0.51, 0.19, isEnd)); // 0 for bottom, 1 for top\\n\\\n\\n\\\n vec3 forward = endPositionAndHeight.xyz - startPositionAndHeight.xyz;\\n\\\n vec3 right = normalize(cross(forward, startEllipsoidNormal));\\n\\\n\\n\\\n vec4 position = vec4(startPositionAndHeight.xyz, 1.0);\\n\\\n position.xyz += forward * isEnd;\\n\\\n\\n\\\n v_volumeUpEC = czm_normal * normalize(cross(right, forward));\\n\\\n\\n\\\n // Push for volume height\\n\\\n float offset;\\n\\\n vec3 ellipsoidNormal = mix(startEllipsoidNormal, endEllipsoidNormal, isEnd);\\n\\\n\\n\\\n // offset height to create volume\\n\\\n offset = mix(startPositionAndHeight.w, endPositionAndHeight.w, isEnd);\\n\\\n offset = mix(u_minimumMaximumVectorHeights.y, u_minimumMaximumVectorHeights.x, isTop) - offset;\\n\\\n position.xyz += offset * ellipsoidNormal;\\n\\\n\\n\\\n // move from RTC to EC\\n\\\n position = u_modifiedModelView * position;\\n\\\n right = czm_normal * right;\\n\\\n\\n\\\n // Push for width in a direction that is in the start or end plane and in a plane with right\\n\\\n // N = normalEC (\\\"right-facing\\\" direction for push)\\n\\\n // R = right\\n\\\n // p = angle between N and R\\n\\\n // w = distance to push along R if R == N\\n\\\n // d = distance to push along N\\n\\\n //\\n\\\n // N R\\n\\\n // { \\ p| } * cos(p) = dot(N, R) = w / d\\n\\\n // d\\ \\ | |w * d = w / dot(N, R)\\n\\\n // { \\| }\\n\\\n // o---------- polyline segment ---->\\n\\\n //\\n\\\n vec3 scratchNormal = mix(-startFaceNormalAndVertexCorner.xyz, endFaceNormalAndHalfWidth.xyz, isEnd);\\n\\\n scratchNormal = cross(scratchNormal, mix(startEllipsoidNormal, endEllipsoidNormal, isEnd));\\n\\\n vec3 miterPushNormal = czm_normal * normalize(scratchNormal);\\n\\\n\\n\\\n offset = 2.0 * endFaceNormalAndHalfWidth.w * max(0.0, czm_metersPerPixel(position)); // offset = widthEC\\n\\\n offset = offset / dot(miterPushNormal, right);\\n\\\n position.xyz += miterPushNormal * (offset * sign(0.5 - mod(startFaceNormalAndVertexCorner.w, 2.0)));\\n\\\n\\n\\\n gl_Position = czm_depthClamp(czm_projection * position);\\n\\\n\\n\\\n position = u_modifiedModelView * vec4(startPositionAndHeight.xyz, 1.0);\\n\\\n vec3 startNormalEC = czm_normal * startFaceNormalAndVertexCorner.xyz;\\n\\\n v_startPlaneEC = vec4(startNormalEC, -dot(startNormalEC, position.xyz));\\n\\\n v_rightPlaneEC = vec4(right, -dot(right, position.xyz));\\n\\\n\\n\\\n position = u_modifiedModelView * vec4(endPositionAndHeight.xyz, 1.0);\\n\\\n vec3 endNormalEC = czm_normal * endFaceNormalAndHalfWidth.xyz;\\n\\\n v_endPlaneEC = vec4(endNormalEC, -dot(endNormalEC, position.xyz));\\n\\\n v_halfWidth = endFaceNormalAndHalfWidth.w;\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 v_startPlaneEC;\\n\\\nin vec4 v_endPlaneEC;\\n\\\nin vec4 v_rightPlaneEC;\\n\\\nin float v_halfWidth;\\n\\\nin vec3 v_volumeUpEC;\\n\\\n\\n\\\nuniform vec4 u_highlightColor;\\n\\\nvoid main()\\n\\\n{\\n\\\n float logDepthOrDepth = czm_branchFreeTernary(czm_sceneMode == czm_sceneMode2D, gl_FragCoord.z, czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw)));\\n\\\n\\n\\\n // Discard for sky\\n\\\n if (logDepthOrDepth == 0.0) {\\n\\\n#ifdef DEBUG_SHOW_VOLUME\\n\\\n out_FragColor = vec4(0.0, 0.0, 1.0, 0.5);\\n\\\n return;\\n\\\n#else // DEBUG_SHOW_VOLUME\\n\\\n discard;\\n\\\n#endif // DEBUG_SHOW_VOLUME\\n\\\n }\\n\\\n\\n\\\n vec4 eyeCoordinate = czm_windowToEyeCoordinates(gl_FragCoord.xy, logDepthOrDepth);\\n\\\n eyeCoordinate /= eyeCoordinate.w;\\n\\\n\\n\\\n float halfMaxWidth = v_halfWidth * czm_metersPerPixel(eyeCoordinate);\\n\\\n\\n\\\n // Expand halfMaxWidth if direction to camera is almost perpendicular with the volume's up direction\\n\\\n halfMaxWidth += halfMaxWidth * (1.0 - dot(-normalize(eyeCoordinate.xyz), v_volumeUpEC));\\n\\\n\\n\\\n // Check distance of the eye coordinate against the right-facing plane\\n\\\n float widthwiseDistance = czm_planeDistance(v_rightPlaneEC, eyeCoordinate.xyz);\\n\\\n\\n\\\n // Check eye coordinate against the mitering planes\\n\\\n float distanceFromStart = czm_planeDistance(v_startPlaneEC, eyeCoordinate.xyz);\\n\\\n float distanceFromEnd = czm_planeDistance(v_endPlaneEC, eyeCoordinate.xyz);\\n\\\n\\n\\\n if (abs(widthwiseDistance) > halfMaxWidth || distanceFromStart < 0.0 || distanceFromEnd < 0.0) {\\n\\\n#ifdef DEBUG_SHOW_VOLUME\\n\\\n out_FragColor = vec4(logDepthOrDepth, 0.0, 0.0, 0.5);\\n\\\n return;\\n\\\n#else // DEBUG_SHOW_VOLUME\\n\\\n discard;\\n\\\n#endif // DEBUG_SHOW_VOLUME\\n\\\n }\\n\\\n out_FragColor = u_highlightColor;\\n\\\n\\n\\\n czm_writeDepthClamp();\\n\\\n}\\n\\\n\";\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport FeatureDetection from \"../Core/FeatureDetection.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport TaskProcessor from \"../Core/TaskProcessor.js\";\nimport Buffer from \"../Renderer/Buffer.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArray from \"../Renderer/VertexArray.js\";\nimport PolylineCommon from \"../Shaders/PolylineCommon.js\";\nimport Vector3DTileClampedPolylinesVS from \"../Shaders/Vector3DTileClampedPolylinesVS.js\";\nimport Vector3DTileClampedPolylinesFS from \"../Shaders/Vector3DTileClampedPolylinesFS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport Cesium3DTileFeature from \"./Cesium3DTileFeature.js\";\nimport ClassificationType from \"./ClassificationType.js\";\nimport CullFace from \"./CullFace.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport StencilFunction from \"./StencilFunction.js\";\nimport StencilOperation from \"./StencilOperation.js\";\nimport Vector3DTilePolylines from \"./Vector3DTilePolylines.js\";\n\n/**\n * Creates a batch of polylines as volumes with shader-adjustable width.\n *\n * @alias Vector3DTileClampedPolylines\n * @constructor\n *\n * @param {object} options An object with following properties:\n * @param {Uint16Array} options.positions The positions of the polylines\n * @param {Uint32Array} options.counts The number or positions in the each polyline.\n * @param {Uint16Array} options.widths The width of each polyline.\n * @param {number} options.minimumHeight The minimum height of the tile's region.\n * @param {number} options.maximumHeight The maximum height of the tile's region.\n * @param {Rectangle} options.rectangle The rectangle containing the tile.\n * @param {Cartesian3} [options.center=Cartesian3.ZERO] The RTC center.\n * @param {Cesium3DTileBatchTable} options.batchTable The batch table for the tile containing the batched polylines.\n * @param {Uint16Array} options.batchIds The batch ids for each polyline.\n * @param {ClassificationType} options.classificationType The classification type.\n * @param {boolean} options.keepDecodedPositions Whether to keep decoded positions in memory.\n *\n * @private\n */\nfunction Vector3DTileClampedPolylines(options) {\n // these arrays hold data from the tile payload\n // and are all released after the first update.\n this._positions = options.positions;\n this._widths = options.widths;\n this._counts = options.counts;\n this._batchIds = options.batchIds;\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n this._minimumHeight = options.minimumHeight;\n this._maximumHeight = options.maximumHeight;\n this._center = options.center;\n this._rectangle = options.rectangle;\n\n this._batchTable = options.batchTable;\n\n this._va = undefined;\n this._sp = undefined;\n this._rs = undefined;\n this._uniformMap = undefined;\n this._command = undefined;\n\n this._transferrableBatchIds = undefined;\n this._packedBuffer = undefined;\n this._minimumMaximumVectorHeights = new Cartesian2(\n ApproximateTerrainHeights._defaultMinTerrainHeight,\n ApproximateTerrainHeights._defaultMaxTerrainHeight\n );\n this._boundingVolume = OrientedBoundingBox.fromRectangle(\n options.rectangle,\n ApproximateTerrainHeights._defaultMinTerrainHeight,\n ApproximateTerrainHeights._defaultMaxTerrainHeight,\n this._ellipsoid\n );\n this._classificationType = options.classificationType;\n\n this._keepDecodedPositions = options.keepDecodedPositions;\n this._decodedPositions = undefined;\n this._decodedPositionOffsets = undefined;\n\n // Fat vertices - all information for each volume packed to a vec3 and 5 vec4s\n this._startEllipsoidNormals = undefined;\n this._endEllipsoidNormals = undefined;\n this._startPositionAndHeights = undefined;\n this._startFaceNormalAndVertexCornerIds = undefined;\n this._endPositionAndHeights = undefined;\n this._endFaceNormalAndHalfWidths = undefined;\n this._vertexBatchIds = undefined;\n\n this._indices = undefined;\n\n this._constantColor = Color.clone(Color.WHITE);\n this._highlightColor = this._constantColor;\n\n this._trianglesLength = 0;\n this._geometryByteLength = 0;\n\n this._ready = false;\n this._promise = undefined;\n this._error = undefined;\n}\n\nObject.defineProperties(Vector3DTileClampedPolylines.prototype, {\n /**\n * Gets the number of triangles.\n *\n * @memberof Vector3DTileClampedPolylines.prototype\n *\n * @type {number}\n * @readonly\n */\n trianglesLength: {\n get: function () {\n return this._trianglesLength;\n },\n },\n\n /**\n * Gets the geometry memory in bytes.\n *\n * @memberof Vector3DTileClampedPolylines.prototype\n *\n * @type {number}\n * @readonly\n */\n geometryByteLength: {\n get: function () {\n return this._geometryByteLength;\n },\n },\n\n /**\n * Returns true when the primitive is ready to render.\n * @memberof Vector3DTileClampedPolylines.prototype\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\nfunction updateMinimumMaximumHeights(polylines, rectangle, ellipsoid) {\n const result = ApproximateTerrainHeights.getMinimumMaximumHeights(\n rectangle,\n ellipsoid\n );\n const min = result.minimumTerrainHeight;\n const max = result.maximumTerrainHeight;\n const minimumMaximumVectorHeights = polylines._minimumMaximumVectorHeights;\n minimumMaximumVectorHeights.x = min;\n minimumMaximumVectorHeights.y = max;\n\n const obb = polylines._boundingVolume;\n const rect = polylines._rectangle;\n OrientedBoundingBox.fromRectangle(rect, min, max, ellipsoid, obb);\n}\n\nfunction packBuffer(polylines) {\n const rectangle = polylines._rectangle;\n const minimumHeight = polylines._minimumHeight;\n const maximumHeight = polylines._maximumHeight;\n const ellipsoid = polylines._ellipsoid;\n const center = polylines._center;\n\n const packedLength =\n 2 +\n Rectangle.packedLength +\n Ellipsoid.packedLength +\n Cartesian3.packedLength;\n const packedBuffer = new Float64Array(packedLength);\n\n let offset = 0;\n packedBuffer[offset++] = minimumHeight;\n packedBuffer[offset++] = maximumHeight;\n\n Rectangle.pack(rectangle, packedBuffer, offset);\n offset += Rectangle.packedLength;\n\n Ellipsoid.pack(ellipsoid, packedBuffer, offset);\n offset += Ellipsoid.packedLength;\n\n Cartesian3.pack(center, packedBuffer, offset);\n\n return packedBuffer;\n}\n\nconst createVerticesTaskProcessor = new TaskProcessor(\n \"createVectorTileClampedPolylines\"\n);\nconst attributeLocations = {\n startEllipsoidNormal: 0,\n endEllipsoidNormal: 1,\n startPositionAndHeight: 2,\n endPositionAndHeight: 3,\n startFaceNormalAndVertexCorner: 4,\n endFaceNormalAndHalfWidth: 5,\n a_batchId: 6,\n};\n\nfunction createVertexArray(polylines, context) {\n if (defined(polylines._va)) {\n return;\n }\n\n let positions = polylines._positions;\n let widths = polylines._widths;\n let counts = polylines._counts;\n let batchIds = polylines._transferrableBatchIds;\n\n let packedBuffer = polylines._packedBuffer;\n\n if (!defined(packedBuffer)) {\n // Copy because they may be the views on the same buffer.\n positions = polylines._positions = positions.slice();\n widths = polylines._widths = widths.slice();\n counts = polylines._counts = counts.slice();\n\n batchIds = polylines._transferrableBatchIds = polylines._batchIds.slice();\n\n packedBuffer = polylines._packedBuffer = packBuffer(polylines);\n }\n\n const transferrableObjects = [\n positions.buffer,\n widths.buffer,\n counts.buffer,\n batchIds.buffer,\n packedBuffer.buffer,\n ];\n const parameters = {\n positions: positions.buffer,\n widths: widths.buffer,\n counts: counts.buffer,\n batchIds: batchIds.buffer,\n packedBuffer: packedBuffer.buffer,\n keepDecodedPositions: polylines._keepDecodedPositions,\n };\n\n const verticesPromise = createVerticesTaskProcessor.scheduleTask(\n parameters,\n transferrableObjects\n );\n if (!defined(verticesPromise)) {\n // Postponed\n return;\n }\n\n return verticesPromise\n .then(function (result) {\n if (polylines.isDestroyed()) {\n return;\n }\n\n if (polylines._keepDecodedPositions) {\n polylines._decodedPositions = new Float64Array(result.decodedPositions);\n polylines._decodedPositionOffsets = new Uint32Array(\n result.decodedPositionOffsets\n );\n }\n\n polylines._startEllipsoidNormals = new Float32Array(\n result.startEllipsoidNormals\n );\n polylines._endEllipsoidNormals = new Float32Array(\n result.endEllipsoidNormals\n );\n polylines._startPositionAndHeights = new Float32Array(\n result.startPositionAndHeights\n );\n polylines._startFaceNormalAndVertexCornerIds = new Float32Array(\n result.startFaceNormalAndVertexCornerIds\n );\n polylines._endPositionAndHeights = new Float32Array(\n result.endPositionAndHeights\n );\n polylines._endFaceNormalAndHalfWidths = new Float32Array(\n result.endFaceNormalAndHalfWidths\n );\n polylines._vertexBatchIds = new Uint16Array(result.vertexBatchIds);\n\n const indexDatatype = result.indexDatatype;\n polylines._indices =\n indexDatatype === IndexDatatype.UNSIGNED_SHORT\n ? new Uint16Array(result.indices)\n : new Uint32Array(result.indices);\n\n finishVertexArray(polylines, context);\n polylines._ready = true;\n })\n .catch((error) => {\n if (polylines.isDestroyed()) {\n return;\n }\n\n // Throw the error next frame\n polylines._error = error;\n });\n}\n\nfunction finishVertexArray(polylines, context) {\n if (!defined(polylines._va)) {\n const startEllipsoidNormals = polylines._startEllipsoidNormals;\n const endEllipsoidNormals = polylines._endEllipsoidNormals;\n const startPositionAndHeights = polylines._startPositionAndHeights;\n const endPositionAndHeights = polylines._endPositionAndHeights;\n const startFaceNormalAndVertexCornerIds =\n polylines._startFaceNormalAndVertexCornerIds;\n const endFaceNormalAndHalfWidths = polylines._endFaceNormalAndHalfWidths;\n const batchIdAttribute = polylines._vertexBatchIds;\n\n const indices = polylines._indices;\n\n let byteLength =\n startEllipsoidNormals.byteLength + endEllipsoidNormals.byteLength;\n byteLength +=\n startPositionAndHeights.byteLength + endPositionAndHeights.byteLength;\n byteLength +=\n startFaceNormalAndVertexCornerIds.byteLength +\n endFaceNormalAndHalfWidths.byteLength;\n byteLength += batchIdAttribute.byteLength + indices.byteLength;\n\n polylines._trianglesLength = indices.length / 3;\n polylines._geometryByteLength = byteLength;\n\n const startEllipsoidNormalsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: startEllipsoidNormals,\n usage: BufferUsage.STATIC_DRAW,\n });\n const endEllipsoidNormalsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: endEllipsoidNormals,\n usage: BufferUsage.STATIC_DRAW,\n });\n const startPositionAndHeightsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: startPositionAndHeights,\n usage: BufferUsage.STATIC_DRAW,\n });\n const endPositionAndHeightsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: endPositionAndHeights,\n usage: BufferUsage.STATIC_DRAW,\n });\n const startFaceNormalAndVertexCornerIdsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: startFaceNormalAndVertexCornerIds,\n usage: BufferUsage.STATIC_DRAW,\n });\n const endFaceNormalAndHalfWidthsBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: endFaceNormalAndHalfWidths,\n usage: BufferUsage.STATIC_DRAW,\n });\n const batchIdAttributeBuffer = Buffer.createVertexBuffer({\n context: context,\n typedArray: batchIdAttribute,\n usage: BufferUsage.STATIC_DRAW,\n });\n\n const indexBuffer = Buffer.createIndexBuffer({\n context: context,\n typedArray: indices,\n usage: BufferUsage.STATIC_DRAW,\n indexDatatype:\n indices.BYTES_PER_ELEMENT === 2\n ? IndexDatatype.UNSIGNED_SHORT\n : IndexDatatype.UNSIGNED_INT,\n });\n\n const vertexAttributes = [\n {\n index: attributeLocations.startEllipsoidNormal,\n vertexBuffer: startEllipsoidNormalsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n index: attributeLocations.endEllipsoidNormal,\n vertexBuffer: endEllipsoidNormalsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n },\n {\n index: attributeLocations.startPositionAndHeight,\n vertexBuffer: startPositionAndHeightsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n },\n {\n index: attributeLocations.endPositionAndHeight,\n vertexBuffer: endPositionAndHeightsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n },\n {\n index: attributeLocations.startFaceNormalAndVertexCorner,\n vertexBuffer: startFaceNormalAndVertexCornerIdsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n },\n {\n index: attributeLocations.endFaceNormalAndHalfWidth,\n vertexBuffer: endFaceNormalAndHalfWidthsBuffer,\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 4,\n },\n {\n index: attributeLocations.a_batchId,\n vertexBuffer: batchIdAttributeBuffer,\n componentDatatype: ComponentDatatype.UNSIGNED_SHORT,\n componentsPerAttribute: 1,\n },\n ];\n\n polylines._va = new VertexArray({\n context: context,\n attributes: vertexAttributes,\n indexBuffer: indexBuffer,\n });\n\n polylines._positions = undefined;\n polylines._widths = undefined;\n polylines._counts = undefined;\n\n polylines._ellipsoid = undefined;\n polylines._minimumHeight = undefined;\n polylines._maximumHeight = undefined;\n polylines._rectangle = undefined;\n\n polylines._transferrableBatchIds = undefined;\n polylines._packedBuffer = undefined;\n\n polylines._startEllipsoidNormals = undefined;\n polylines._endEllipsoidNormals = undefined;\n polylines._startPositionAndHeights = undefined;\n polylines._startFaceNormalAndVertexCornerIds = undefined;\n polylines._endPositionAndHeights = undefined;\n polylines._endFaceNormalAndHalfWidths = undefined;\n polylines._vertexBatchIds = undefined;\n\n polylines._indices = undefined;\n }\n}\n\nconst modifiedModelViewScratch = new Matrix4();\nconst rtcScratch = new Cartesian3();\n\nfunction createUniformMap(primitive, context) {\n if (defined(primitive._uniformMap)) {\n return;\n }\n\n primitive._uniformMap = {\n u_modifiedModelView: function () {\n const viewMatrix = context.uniformState.view;\n Matrix4.clone(viewMatrix, modifiedModelViewScratch);\n Matrix4.multiplyByPoint(\n modifiedModelViewScratch,\n primitive._center,\n rtcScratch\n );\n Matrix4.setTranslation(\n modifiedModelViewScratch,\n rtcScratch,\n modifiedModelViewScratch\n );\n return modifiedModelViewScratch;\n },\n u_highlightColor: function () {\n return primitive._highlightColor;\n },\n u_minimumMaximumVectorHeights: function () {\n return primitive._minimumMaximumVectorHeights;\n },\n };\n}\n\nfunction getRenderState(mask3DTiles) {\n /**\n * Cull front faces of each volume (relative to camera) to prevent\n * classification drawing from both the front and back faces, double-draw.\n * The geometry is \"inverted\" (inside-out winding order for the indices) but\n * the vertex shader seems to re-invert so that the triangles face \"out\" again.\n * So cull FRONT faces.\n */\n return RenderState.fromCache({\n cull: {\n enabled: true,\n face: CullFace.FRONT,\n },\n blending: BlendingState.PRE_MULTIPLIED_ALPHA_BLEND,\n depthMask: false,\n stencilTest: {\n enabled: mask3DTiles,\n frontFunction: StencilFunction.EQUAL,\n frontOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.KEEP,\n },\n backFunction: StencilFunction.EQUAL,\n backOperation: {\n fail: StencilOperation.KEEP,\n zFail: StencilOperation.KEEP,\n zPass: StencilOperation.KEEP,\n },\n reference: StencilConstants.CESIUM_3D_TILE_MASK,\n mask: StencilConstants.CESIUM_3D_TILE_MASK,\n },\n });\n}\n\nfunction createRenderStates(primitive) {\n if (defined(primitive._rs)) {\n return;\n }\n\n primitive._rs = getRenderState(false);\n primitive._rs3DTiles = getRenderState(true);\n}\n\nfunction createShaders(primitive, context) {\n if (defined(primitive._sp)) {\n return;\n }\n\n const batchTable = primitive._batchTable;\n\n const vsSource = batchTable.getVertexShaderCallback(\n false,\n \"a_batchId\",\n undefined\n )(Vector3DTileClampedPolylinesVS);\n const fsSource = batchTable.getFragmentShaderCallback(\n false,\n undefined,\n true\n )(Vector3DTileClampedPolylinesFS);\n\n const vs = new ShaderSource({\n defines: [\n \"VECTOR_TILE\",\n !FeatureDetection.isInternetExplorer() ? \"CLIP_POLYLINE\" : \"\",\n ],\n sources: [PolylineCommon, vsSource],\n });\n const fs = new ShaderSource({\n defines: [\"VECTOR_TILE\"],\n sources: [fsSource],\n });\n\n primitive._sp = ShaderProgram.fromCache({\n context: context,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n}\n\nfunction queueCommands(primitive, frameState) {\n let command = primitive._command;\n if (!defined(primitive._command)) {\n const uniformMap = primitive._batchTable.getUniformMapCallback()(\n primitive._uniformMap\n );\n command = primitive._command = new DrawCommand({\n owner: primitive,\n vertexArray: primitive._va,\n renderState: primitive._rs,\n shaderProgram: primitive._sp,\n uniformMap: uniformMap,\n boundingVolume: primitive._boundingVolume,\n pass: Pass.TERRAIN_CLASSIFICATION,\n pickId: primitive._batchTable.getPickId(),\n });\n\n const derivedTilesetCommand = DrawCommand.shallowClone(\n command,\n command.derivedCommands.tileset\n );\n derivedTilesetCommand.renderState = primitive._rs3DTiles;\n derivedTilesetCommand.pass = Pass.CESIUM_3D_TILE_CLASSIFICATION;\n command.derivedCommands.tileset = derivedTilesetCommand;\n }\n\n const classificationType = primitive._classificationType;\n if (\n classificationType === ClassificationType.TERRAIN ||\n classificationType === ClassificationType.BOTH\n ) {\n frameState.commandList.push(command);\n }\n if (\n classificationType === ClassificationType.CESIUM_3D_TILE ||\n classificationType === ClassificationType.BOTH\n ) {\n frameState.commandList.push(command.derivedCommands.tileset);\n }\n}\n\n/**\n * Get the polyline positions for the given feature.\n *\n * @param {number} batchId The batch ID of the feature.\n */\nVector3DTileClampedPolylines.prototype.getPositions = function (batchId) {\n return Vector3DTilePolylines.getPolylinePositions(this, batchId);\n};\n\n/**\n * Creates features for each polyline and places it at the batch id index of features.\n *\n * @param {Vector3DTileContent} content The vector tile content.\n * @param {Cesium3DTileFeature[]} features An array of features where the polygon features will be placed.\n */\nVector3DTileClampedPolylines.prototype.createFeatures = function (\n content,\n features\n) {\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n features[batchId] = new Cesium3DTileFeature(content, batchId);\n }\n};\n\n/**\n * Colors the entire tile when enabled is true. The resulting color will be (polyline batch table color * color).\n *\n * @param {boolean} enabled Whether to enable debug coloring.\n * @param {Color} color The debug color.\n */\nVector3DTileClampedPolylines.prototype.applyDebugSettings = function (\n enabled,\n color\n) {\n this._highlightColor = enabled ? color : this._constantColor;\n};\n\nfunction clearStyle(polygons, features) {\n const batchIds = polygons._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.show = true;\n feature.color = Color.WHITE;\n }\n}\n\nconst scratchColor = new Color();\n\nconst DEFAULT_COLOR_VALUE = Color.WHITE;\nconst DEFAULT_SHOW_VALUE = true;\n\n/**\n * Apply a style to the content.\n *\n * @param {Cesium3DTileStyle} style The style.\n * @param {Cesium3DTileFeature[]} features The dictionary of features.\n */\nVector3DTileClampedPolylines.prototype.applyStyle = function (style, features) {\n if (!defined(style)) {\n clearStyle(this, features);\n return;\n }\n\n const batchIds = this._batchIds;\n const length = batchIds.length;\n for (let i = 0; i < length; ++i) {\n const batchId = batchIds[i];\n const feature = features[batchId];\n\n feature.color = defined(style.color)\n ? style.color.evaluateColor(feature, scratchColor)\n : DEFAULT_COLOR_VALUE;\n feature.show = defined(style.show)\n ? style.show.evaluate(feature)\n : DEFAULT_SHOW_VALUE;\n }\n};\n\nfunction initialize(polylines) {\n return ApproximateTerrainHeights.initialize()\n .then(function () {\n updateMinimumMaximumHeights(\n polylines,\n polylines._rectangle,\n polylines._ellipsoid\n );\n })\n .catch((error) => {\n if (polylines.isDestroyed()) {\n return;\n }\n\n // Throw the error next frame\n polylines._error = error;\n });\n}\n\n/**\n * Updates the batches and queues the commands for rendering.\n *\n * @param {FrameState} frameState The current frame state.\n */\nVector3DTileClampedPolylines.prototype.update = function (frameState) {\n const context = frameState.context;\n if (!this._ready) {\n if (!defined(this._promise)) {\n this._promise = initialize(this).then(createVertexArray(this, context));\n }\n\n if (defined(this._error)) {\n const error = this._error;\n this._error = undefined;\n throw error;\n }\n\n return;\n }\n\n createUniformMap(this, context);\n createShaders(this, context);\n createRenderStates(this);\n\n const passes = frameState.passes;\n if (passes.render || passes.pick) {\n queueCommands(this, frameState);\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *

\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n */\nVector3DTileClampedPolylines.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *

\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nVector3DTileClampedPolylines.prototype.destroy = function () {\n this._va = this._va && this._va.destroy();\n this._sp = this._sp && this._sp.destroy();\n return destroyObject(this);\n};\nexport default Vector3DTileClampedPolylines;\n", "import AttributeCompression from \"./AttributeCompression.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst maxShort = 32767;\n\nconst scratchBVCartographic = new Cartographic();\nconst scratchEncodedPosition = new Cartesian3();\n\nfunction decodeVectorPolylinePositions(\n positions,\n rectangle,\n minimumHeight,\n maximumHeight,\n ellipsoid\n) {\n const positionsLength = positions.length / 3;\n const uBuffer = positions.subarray(0, positionsLength);\n const vBuffer = positions.subarray(positionsLength, 2 * positionsLength);\n const heightBuffer = positions.subarray(\n 2 * positionsLength,\n 3 * positionsLength\n );\n AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);\n\n const decoded = new Float64Array(positions.length);\n for (let i = 0; i < positionsLength; ++i) {\n const u = uBuffer[i];\n const v = vBuffer[i];\n const h = heightBuffer[i];\n\n const lon = CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);\n const lat = CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);\n const alt = CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);\n\n const cartographic = Cartographic.fromRadians(\n lon,\n lat,\n alt,\n scratchBVCartographic\n );\n const decodedPosition = ellipsoid.cartographicToCartesian(\n cartographic,\n scratchEncodedPosition\n );\n Cartesian3.pack(decodedPosition, decoded, i * 3);\n }\n return decoded;\n}\nexport default decodeVectorPolylinePositions;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Cesium3DTileBatchTable from \"./Cesium3DTileBatchTable.js\";\nimport Cesium3DTileFeatureTable from \"./Cesium3DTileFeatureTable.js\";\nimport Vector3DTilePoints from \"./Vector3DTilePoints.js\";\nimport Vector3DTilePolygons from \"./Vector3DTilePolygons.js\";\nimport Vector3DTilePolylines from \"./Vector3DTilePolylines.js\";\nimport Vector3DTileClampedPolylines from \"./Vector3DTileClampedPolylines.js\";\nimport decodeVectorPolylinePositions from \"../Core/decodeVectorPolylinePositions.js\";\n\n/**\n * Represents the contents of a\n * {@link https://github.com/CesiumGS/3d-tiles/tree/vctr/TileFormats/VectorData|Vector}\n * tile in a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @alias Vector3DTileContent\n * @constructor\n *\n * @private\n */\nfunction Vector3DTileContent(tileset, tile, resource, arrayBuffer, byteOffset) {\n this._tileset = tileset;\n this._tile = tile;\n this._resource = resource;\n\n this._polygons = undefined;\n this._polylines = undefined;\n this._points = undefined;\n\n this._metadata = undefined;\n\n this._batchTable = undefined;\n this._features = undefined;\n\n /**\n * Part of the {@link Cesium3DTileContent} interface.\n */\n this.featurePropertiesDirty = false;\n this._group = undefined;\n\n this._ready = false;\n\n initialize(this, arrayBuffer, byteOffset);\n}\n\nObject.defineProperties(Vector3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n return defined(this._batchTable) ? this._batchTable.featuresLength : 0;\n },\n },\n\n pointsLength: {\n get: function () {\n if (defined(this._points)) {\n return this._points.pointsLength;\n }\n return 0;\n },\n },\n\n trianglesLength: {\n get: function () {\n let trianglesLength = 0;\n if (defined(this._polygons)) {\n trianglesLength += this._polygons.trianglesLength;\n }\n if (defined(this._polylines)) {\n trianglesLength += this._polylines.trianglesLength;\n }\n return trianglesLength;\n },\n },\n\n geometryByteLength: {\n get: function () {\n let geometryByteLength = 0;\n if (defined(this._polygons)) {\n geometryByteLength += this._polygons.geometryByteLength;\n }\n if (defined(this._polylines)) {\n geometryByteLength += this._polylines.geometryByteLength;\n }\n return geometryByteLength;\n },\n },\n\n texturesByteLength: {\n get: function () {\n if (defined(this._points)) {\n return this._points.texturesByteLength;\n }\n return 0;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n return defined(this._batchTable)\n ? this._batchTable.batchTableByteLength\n : 0;\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Vector3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return this._resource.getUrlComponent(true);\n },\n },\n\n metadata: {\n get: function () {\n return this._metadata;\n },\n set: function (value) {\n this._metadata = value;\n },\n },\n\n batchTable: {\n get: function () {\n return this._batchTable;\n },\n },\n\n group: {\n get: function () {\n return this._group;\n },\n set: function (value) {\n this._group = value;\n },\n },\n});\n\nfunction createColorChangedCallback(content) {\n return function (batchId, color) {\n if (defined(content._polygons)) {\n content._polygons.updateCommands(batchId, color);\n }\n };\n}\n\nfunction getBatchIds(featureTableJson, featureTableBinary) {\n let polygonBatchIds;\n let polylineBatchIds;\n let pointBatchIds;\n let i;\n\n const numberOfPolygons = defaultValue(featureTableJson.POLYGONS_LENGTH, 0);\n const numberOfPolylines = defaultValue(featureTableJson.POLYLINES_LENGTH, 0);\n const numberOfPoints = defaultValue(featureTableJson.POINTS_LENGTH, 0);\n\n if (numberOfPolygons > 0 && defined(featureTableJson.POLYGON_BATCH_IDS)) {\n const polygonBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.POLYGON_BATCH_IDS.byteOffset;\n polygonBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n polygonBatchIdsByteOffset,\n numberOfPolygons\n );\n }\n\n if (numberOfPolylines > 0 && defined(featureTableJson.POLYLINE_BATCH_IDS)) {\n const polylineBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.POLYLINE_BATCH_IDS.byteOffset;\n polylineBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n polylineBatchIdsByteOffset,\n numberOfPolylines\n );\n }\n\n if (numberOfPoints > 0 && defined(featureTableJson.POINT_BATCH_IDS)) {\n const pointBatchIdsByteOffset =\n featureTableBinary.byteOffset +\n featureTableJson.POINT_BATCH_IDS.byteOffset;\n pointBatchIds = new Uint16Array(\n featureTableBinary.buffer,\n pointBatchIdsByteOffset,\n numberOfPoints\n );\n }\n\n const atLeastOneDefined =\n defined(polygonBatchIds) ||\n defined(polylineBatchIds) ||\n defined(pointBatchIds);\n const atLeastOneUndefined =\n (numberOfPolygons > 0 && !defined(polygonBatchIds)) ||\n (numberOfPolylines > 0 && !defined(polylineBatchIds)) ||\n (numberOfPoints > 0 && !defined(pointBatchIds));\n\n if (atLeastOneDefined && atLeastOneUndefined) {\n throw new RuntimeError(\n \"If one group of batch ids is defined, then all batch ids must be defined\"\n );\n }\n\n const allUndefinedBatchIds =\n !defined(polygonBatchIds) &&\n !defined(polylineBatchIds) &&\n !defined(pointBatchIds);\n if (allUndefinedBatchIds) {\n let id = 0;\n if (!defined(polygonBatchIds) && numberOfPolygons > 0) {\n polygonBatchIds = new Uint16Array(numberOfPolygons);\n for (i = 0; i < numberOfPolygons; ++i) {\n polygonBatchIds[i] = id++;\n }\n }\n if (!defined(polylineBatchIds) && numberOfPolylines > 0) {\n polylineBatchIds = new Uint16Array(numberOfPolylines);\n for (i = 0; i < numberOfPolylines; ++i) {\n polylineBatchIds[i] = id++;\n }\n }\n if (!defined(pointBatchIds) && numberOfPoints > 0) {\n pointBatchIds = new Uint16Array(numberOfPoints);\n for (i = 0; i < numberOfPoints; ++i) {\n pointBatchIds[i] = id++;\n }\n }\n }\n\n return {\n polygons: polygonBatchIds,\n polylines: polylineBatchIds,\n points: pointBatchIds,\n };\n}\n\nconst sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT;\n\nfunction createFloatingPolylines(options) {\n return new Vector3DTilePolylines(options);\n}\n\nfunction createClampedPolylines(options) {\n return new Vector3DTileClampedPolylines(options);\n}\n\nfunction initialize(content, arrayBuffer, byteOffset) {\n byteOffset = defaultValue(byteOffset, 0);\n\n const uint8Array = new Uint8Array(arrayBuffer);\n const view = new DataView(arrayBuffer);\n byteOffset += sizeOfUint32; // Skip magic number\n\n const version = view.getUint32(byteOffset, true);\n if (version !== 1) {\n throw new RuntimeError(\n `Only Vector tile version 1 is supported. Version ${version} is not.`\n );\n }\n byteOffset += sizeOfUint32;\n\n const byteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n if (byteLength === 0) {\n content._ready = true;\n return;\n }\n\n const featureTableJSONByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n if (featureTableJSONByteLength === 0) {\n throw new RuntimeError(\n \"Feature table must have a byte length greater than zero\"\n );\n }\n\n const featureTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const batchTableJSONByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const batchTableBinaryByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const indicesByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const positionByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const polylinePositionByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n const pointsPositionByteLength = view.getUint32(byteOffset, true);\n byteOffset += sizeOfUint32;\n\n const featureTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n featureTableJSONByteLength\n );\n byteOffset += featureTableJSONByteLength;\n\n const featureTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n featureTableBinaryByteLength\n );\n byteOffset += featureTableBinaryByteLength;\n\n let batchTableJson;\n let batchTableBinary;\n if (batchTableJSONByteLength > 0) {\n // PERFORMANCE_IDEA: is it possible to allocate this on-demand? Perhaps keep the\n // arraybuffer/string compressed in memory and then decompress it when it is first accessed.\n //\n // We could also make another request for it, but that would make the property set/get\n // API async, and would double the number of numbers in some cases.\n batchTableJson = getJsonFromTypedArray(\n uint8Array,\n byteOffset,\n batchTableJSONByteLength\n );\n byteOffset += batchTableJSONByteLength;\n\n if (batchTableBinaryByteLength > 0) {\n // Has a batch table binary\n batchTableBinary = new Uint8Array(\n arrayBuffer,\n byteOffset,\n batchTableBinaryByteLength\n );\n // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed\n batchTableBinary = new Uint8Array(batchTableBinary);\n byteOffset += batchTableBinaryByteLength;\n }\n }\n\n const numberOfPolygons = defaultValue(featureTableJson.POLYGONS_LENGTH, 0);\n const numberOfPolylines = defaultValue(featureTableJson.POLYLINES_LENGTH, 0);\n const numberOfPoints = defaultValue(featureTableJson.POINTS_LENGTH, 0);\n const totalPrimitives = numberOfPolygons + numberOfPolylines + numberOfPoints;\n\n const batchTable = new Cesium3DTileBatchTable(\n content,\n totalPrimitives,\n batchTableJson,\n batchTableBinary,\n createColorChangedCallback(content)\n );\n content._batchTable = batchTable;\n\n if (totalPrimitives === 0) {\n return;\n }\n\n const featureTable = new Cesium3DTileFeatureTable(\n featureTableJson,\n featureTableBinary\n );\n const region = featureTable.getGlobalProperty(\"REGION\");\n if (!defined(region)) {\n throw new RuntimeError(\n \"Feature table global property: REGION must be defined\"\n );\n }\n const rectangle = Rectangle.unpack(region);\n const minHeight = region[4];\n const maxHeight = region[5];\n\n const modelMatrix = content._tile.computedTransform;\n\n let center = featureTable.getGlobalProperty(\n \"RTC_CENTER\",\n ComponentDatatype.FLOAT,\n 3\n );\n if (defined(center)) {\n center = Cartesian3.unpack(center);\n Matrix4.multiplyByPoint(modelMatrix, center, center);\n } else {\n center = Rectangle.center(rectangle);\n center.height = CesiumMath.lerp(minHeight, maxHeight, 0.5);\n center = Ellipsoid.WGS84.cartographicToCartesian(center);\n }\n\n const batchIds = getBatchIds(featureTableJson, featureTableBinary);\n byteOffset += (4 - (byteOffset % 4)) % 4;\n\n if (numberOfPolygons > 0) {\n featureTable.featuresLength = numberOfPolygons;\n\n const polygonCounts = defaultValue(\n featureTable.getPropertyArray(\n \"POLYGON_COUNTS\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ),\n featureTable.getPropertyArray(\n \"POLYGON_COUNT\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ) // Workaround for old vector tilesets using the non-plural name\n );\n\n if (!defined(polygonCounts)) {\n throw new RuntimeError(\n \"Feature table property: POLYGON_COUNTS must be defined when POLYGONS_LENGTH is greater than 0\"\n );\n }\n\n const polygonIndexCounts = defaultValue(\n featureTable.getPropertyArray(\n \"POLYGON_INDEX_COUNTS\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ),\n featureTable.getPropertyArray(\n \"POLYGON_INDEX_COUNT\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ) // Workaround for old vector tilesets using the non-plural name\n );\n\n if (!defined(polygonIndexCounts)) {\n throw new RuntimeError(\n \"Feature table property: POLYGON_INDEX_COUNTS must be defined when POLYGONS_LENGTH is greater than 0\"\n );\n }\n\n // Use the counts array to determine how many position values we want. If we used the byte length then\n // zero padding values would be included and cause the delta zig-zag decoding to fail\n const numPolygonPositions = polygonCounts.reduce(function (total, count) {\n return total + count * 2;\n }, 0);\n\n const numPolygonIndices = polygonIndexCounts.reduce(function (\n total,\n count\n ) {\n return total + count;\n },\n 0);\n\n const indices = new Uint32Array(arrayBuffer, byteOffset, numPolygonIndices);\n byteOffset += indicesByteLength;\n\n const polygonPositions = new Uint16Array(\n arrayBuffer,\n byteOffset,\n numPolygonPositions\n );\n byteOffset += positionByteLength;\n\n let polygonMinimumHeights;\n let polygonMaximumHeights;\n if (\n defined(featureTableJson.POLYGON_MINIMUM_HEIGHTS) &&\n defined(featureTableJson.POLYGON_MAXIMUM_HEIGHTS)\n ) {\n polygonMinimumHeights = featureTable.getPropertyArray(\n \"POLYGON_MINIMUM_HEIGHTS\",\n ComponentDatatype.FLOAT,\n 1\n );\n polygonMaximumHeights = featureTable.getPropertyArray(\n \"POLYGON_MAXIMUM_HEIGHTS\",\n ComponentDatatype.FLOAT,\n 1\n );\n }\n\n content._polygons = new Vector3DTilePolygons({\n positions: polygonPositions,\n counts: polygonCounts,\n indexCounts: polygonIndexCounts,\n indices: indices,\n minimumHeight: minHeight,\n maximumHeight: maxHeight,\n polygonMinimumHeights: polygonMinimumHeights,\n polygonMaximumHeights: polygonMaximumHeights,\n center: center,\n rectangle: rectangle,\n boundingVolume: content.tile.boundingVolume.boundingVolume,\n batchTable: batchTable,\n batchIds: batchIds.polygons,\n modelMatrix: modelMatrix,\n });\n }\n\n if (numberOfPolylines > 0) {\n featureTable.featuresLength = numberOfPolylines;\n\n const polylineCounts = defaultValue(\n featureTable.getPropertyArray(\n \"POLYLINE_COUNTS\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ),\n featureTable.getPropertyArray(\n \"POLYLINE_COUNT\",\n ComponentDatatype.UNSIGNED_INT,\n 1\n ) // Workaround for old vector tilesets using the non-plural name\n );\n\n if (!defined(polylineCounts)) {\n throw new RuntimeError(\n \"Feature table property: POLYLINE_COUNTS must be defined when POLYLINES_LENGTH is greater than 0\"\n );\n }\n\n let widths = featureTable.getPropertyArray(\n \"POLYLINE_WIDTHS\",\n ComponentDatatype.UNSIGNED_SHORT,\n 1\n );\n if (!defined(widths)) {\n widths = new Uint16Array(numberOfPolylines);\n for (let i = 0; i < numberOfPolylines; ++i) {\n widths[i] = 2.0;\n }\n }\n\n // Use the counts array to determine how many position values we want. If we used the byte length then\n // zero padding values would be included and cause the delta zig-zag decoding to fail\n const numPolylinePositions = polylineCounts.reduce(function (total, count) {\n return total + count * 3;\n }, 0);\n const polylinePositions = new Uint16Array(\n arrayBuffer,\n byteOffset,\n numPolylinePositions\n );\n byteOffset += polylinePositionByteLength;\n\n const tileset = content._tileset;\n const examineVectorLinesFunction = tileset.examineVectorLinesFunction;\n if (defined(examineVectorLinesFunction)) {\n const decodedPositions = decodeVectorPolylinePositions(\n new Uint16Array(polylinePositions),\n rectangle,\n minHeight,\n maxHeight,\n Ellipsoid.WGS84\n );\n examineVectorLines(\n decodedPositions,\n polylineCounts,\n batchIds.polylines,\n batchTable,\n content.url,\n examineVectorLinesFunction\n );\n }\n\n let createPolylines = createFloatingPolylines;\n if (defined(tileset.classificationType)) {\n createPolylines = createClampedPolylines;\n }\n\n content._polylines = createPolylines({\n positions: polylinePositions,\n widths: widths,\n counts: polylineCounts,\n batchIds: batchIds.polylines,\n minimumHeight: minHeight,\n maximumHeight: maxHeight,\n center: center,\n rectangle: rectangle,\n boundingVolume: content.tile.boundingVolume.boundingVolume,\n batchTable: batchTable,\n classificationType: tileset.classificationType,\n keepDecodedPositions: tileset.vectorKeepDecodedPositions,\n });\n }\n\n if (numberOfPoints > 0) {\n const pointPositions = new Uint16Array(\n arrayBuffer,\n byteOffset,\n numberOfPoints * 3\n );\n byteOffset += pointsPositionByteLength;\n content._points = new Vector3DTilePoints({\n positions: pointPositions,\n batchIds: batchIds.points,\n minimumHeight: minHeight,\n maximumHeight: maxHeight,\n rectangle: rectangle,\n batchTable: batchTable,\n });\n }\n}\n\nfunction createFeatures(content) {\n const featuresLength = content.featuresLength;\n if (!defined(content._features) && featuresLength > 0) {\n const features = new Array(featuresLength);\n\n if (defined(content._polygons)) {\n content._polygons.createFeatures(content, features);\n }\n if (defined(content._polylines)) {\n content._polylines.createFeatures(content, features);\n }\n if (defined(content._points)) {\n content._points.createFeatures(content, features);\n }\n content._features = features;\n }\n}\n\nVector3DTileContent.prototype.hasProperty = function (batchId, name) {\n return this._batchTable.hasProperty(batchId, name);\n};\n\nVector3DTileContent.prototype.getFeature = function (batchId) {\n //>>includeStart('debug', pragmas.debug);\n const featuresLength = this.featuresLength;\n if (!defined(batchId) || batchId < 0 || batchId >= featuresLength) {\n throw new DeveloperError(\n `batchId is required and between zero and featuresLength - 1 (${\n featuresLength - 1\n }).`\n );\n }\n //>>includeEnd('debug');\n\n if (!defined(this._features)) {\n createFeatures(this);\n }\n\n return this._features[batchId];\n};\n\nVector3DTileContent.prototype.applyDebugSettings = function (enabled, color) {\n if (defined(this._polygons)) {\n this._polygons.applyDebugSettings(enabled, color);\n }\n if (defined(this._polylines)) {\n this._polylines.applyDebugSettings(enabled, color);\n }\n if (defined(this._points)) {\n this._points.applyDebugSettings(enabled, color);\n }\n};\n\nVector3DTileContent.prototype.applyStyle = function (style) {\n if (!defined(this._features)) {\n createFeatures(this);\n }\n if (defined(this._polygons)) {\n this._polygons.applyStyle(style, this._features);\n }\n if (defined(this._polylines)) {\n this._polylines.applyStyle(style, this._features);\n }\n if (defined(this._points)) {\n this._points.applyStyle(style, this._features);\n }\n};\n\nVector3DTileContent.prototype.update = function (tileset, frameState) {\n let ready = true;\n if (defined(this._polygons)) {\n this._polygons.classificationType = this._tileset.classificationType;\n this._polygons.debugWireframe = this._tileset.debugWireframe;\n this._polygons.update(frameState);\n ready = ready && this._polygons.ready;\n }\n if (defined(this._polylines)) {\n this._polylines.update(frameState);\n ready = ready && this._polylines.ready;\n }\n if (defined(this._points)) {\n this._points.update(frameState);\n ready = ready && this._points.ready;\n }\n if (defined(this._batchTable) && ready) {\n if (!defined(this._features)) {\n createFeatures(this);\n }\n this._batchTable.update(tileset, frameState);\n this._ready = true;\n }\n};\n\nVector3DTileContent.prototype.getPolylinePositions = function (batchId) {\n const polylines = this._polylines;\n if (!defined(polylines)) {\n return undefined;\n }\n\n return polylines.getPositions(batchId);\n};\n\nVector3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nVector3DTileContent.prototype.destroy = function () {\n this._polygons = this._polygons && this._polygons.destroy();\n this._polylines = this._polylines && this._polylines.destroy();\n this._points = this._points && this._points.destroy();\n this._batchTable = this._batchTable && this._batchTable.destroy();\n return destroyObject(this);\n};\n\nfunction examineVectorLines(\n positions,\n counts,\n batchIds,\n batchTable,\n url,\n callback\n) {\n const countsLength = counts.length;\n let polylineStart = 0;\n for (let i = 0; i < countsLength; i++) {\n const count = counts[i] * 3;\n const linePositions = positions.slice(polylineStart, polylineStart + count);\n polylineStart += count;\n\n callback(linePositions, batchIds[i], url, batchTable);\n }\n}\n\nexport default Vector3DTileContent;\n", "import Composite3DTileContent from \"./Composite3DTileContent.js\";\nimport Geometry3DTileContent from \"./Geometry3DTileContent.js\";\nimport Implicit3DTileContent from \"./Implicit3DTileContent.js\";\nimport Model3DTileContent from \"./Model/Model3DTileContent.js\";\nimport Tileset3DTileContent from \"./Tileset3DTileContent.js\";\nimport Vector3DTileContent from \"./Vector3DTileContent.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\n\n/**\n * Maps a tile's magic field in its header to a new content object for the tile's payload.\n *\n * @private\n */\nconst Cesium3DTileContentFactory = {\n b3dm: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return Model3DTileContent.fromB3dm(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n );\n },\n pnts: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return Model3DTileContent.fromPnts(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n );\n },\n i3dm: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return Model3DTileContent.fromI3dm(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n );\n },\n cmpt: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n // Send in the factory in order to avoid a cyclical dependency\n return Composite3DTileContent.fromTileType(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset,\n Cesium3DTileContentFactory\n );\n },\n externalTileset: function (tileset, tile, resource, json) {\n return Tileset3DTileContent.fromJson(tileset, tile, resource, json);\n },\n geom: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return new Geometry3DTileContent(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n );\n },\n vctr: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return new Vector3DTileContent(\n tileset,\n tile,\n resource,\n arrayBuffer,\n byteOffset\n );\n },\n subt: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n return Implicit3DTileContent.fromSubtreeJson(\n tileset,\n tile,\n resource,\n undefined,\n arrayBuffer,\n byteOffset\n );\n },\n subtreeJson: function (tileset, tile, resource, json) {\n return Implicit3DTileContent.fromSubtreeJson(tileset, tile, resource, json);\n },\n glb: function (tileset, tile, resource, arrayBuffer, byteOffset) {\n const arrayBufferByteLength = arrayBuffer.byteLength;\n if (arrayBufferByteLength < 12) {\n throw new RuntimeError(\"Invalid glb content\");\n }\n const dataView = new DataView(arrayBuffer, byteOffset);\n const byteLength = dataView.getUint32(8, true);\n const glb = new Uint8Array(arrayBuffer, byteOffset, byteLength);\n return Model3DTileContent.fromGltf(tileset, tile, resource, glb);\n },\n gltf: function (tileset, tile, resource, json) {\n return Model3DTileContent.fromGltf(tileset, tile, resource, json);\n },\n geoJson: function (tileset, tile, resource, json) {\n return Model3DTileContent.fromGeoJson(tileset, tile, resource, json);\n },\n};\nexport default Cesium3DTileContentFactory;\n", "/**\n * @private\n */\nconst Cesium3DTileContentState = {\n UNLOADED: 0, // Has never been requested\n LOADING: 1, // Is waiting on a pending request\n PROCESSING: 2, // Request received. Contents are being processed for rendering. Depending on the content, it might make its own requests for external data.\n READY: 3, // Ready to render.\n EXPIRED: 4, // Is expired and will be unloaded once new content is loaded.\n FAILED: 5, // Request failed.\n};\nexport default Object.freeze(Cesium3DTileContentState);\n", "/**\n * An enum to indicate the different types of {@link Cesium3DTileContent}.\n * For binary files, the enum value is the magic number of the binary file\n * unless otherwise noted. For JSON files, the enum value is a unique name\n * for internal use.\n *\n * @enum {string}\n * @see Cesium3DTileContent\n *\n * @private\n */\nconst Cesium3DTileContentType = {\n /**\n * A Batched 3D Model. This is a binary format with\n * magic number b3dm\n *\n * @type {string}\n * @constant\n * @private\n */\n BATCHED_3D_MODEL: \"b3dm\",\n /**\n * An Instanced 3D Model. This is a binary format with magic number\n * i3dm\n *\n * @type {string}\n * @constant\n * @private\n */\n INSTANCED_3D_MODEL: \"i3dm\",\n /**\n * A Composite model. This is a binary format with magic number\n * cmpt\n *\n * @type {string}\n * @constant\n * @private\n */\n COMPOSITE: \"cmpt\",\n /**\n * A Point Cloud model. This is a binary format with magic number\n * pnts\n *\n * @type {string}\n * @constant\n * @private\n */\n POINT_CLOUD: \"pnts\",\n /**\n * Vector tiles. This is a binary format with magic number\n * vctr\n *\n * @type {string}\n * @constant\n * @private\n */\n VECTOR: \"vctr\",\n /**\n * Geometry tiles. This is a binary format with magic number\n * geom\n *\n * @type {string}\n * @constant\n * @private\n */\n GEOMETRY: \"geom\",\n /**\n * A glTF model in JSON + external BIN form. This is treated\n * as a JSON format.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n GLTF: \"gltf\",\n /**\n * The binary form of a glTF file. Internally, the magic number is\n * changed from glTF to glb to distinguish it from\n * the JSON glTF format.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n GLTF_BINARY: \"glb\",\n /**\n * For implicit tiling, availability bitstreams are stored in binary subtree files.\n * The magic number is subt\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n IMPLICIT_SUBTREE: \"subt\",\n /**\n * For implicit tiling. Subtrees can also be represented as JSON files.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n IMPLICIT_SUBTREE_JSON: \"subtreeJson\",\n /**\n * Contents can reference another tileset.json to use\n * as an external tileset. This is a JSON-based format.\n *\n * @type {string}\n * @constant\n * @private\n */\n EXTERNAL_TILESET: \"externalTileset\",\n /**\n * Multiple contents are handled separately from the other content types\n * due to differences in request scheduling.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n MULTIPLE_CONTENT: \"multipleContent\",\n /**\n * GeoJSON content for MAXAR_content_geojson extension.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n GEOJSON: \"geoJson\",\n /**\n * Binary voxel content for 3DTILES_content_voxels extension.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n VOXEL_BINARY: \"voxl\",\n /**\n * Binary voxel content for 3DTILES_content_voxels extension.\n *\n * @type {string}\n * @constant\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n VOXEL_JSON: \"voxelJson\",\n};\n\n/**\n * Check if a content is one of the supported binary formats. Otherwise,\n * the caller can assume a JSON format.\n * @param {Cesium3DTileContentType} contentType The content type of the content payload.\n * @return {boolean} true if the content type is a binary format, or false if the content type is a JSON format.\n * @private\n */\nCesium3DTileContentType.isBinaryFormat = function (contentType) {\n switch (contentType) {\n case Cesium3DTileContentType.BATCHED_3D_MODEL:\n case Cesium3DTileContentType.INSTANCED_3D_MODEL:\n case Cesium3DTileContentType.COMPOSITE:\n case Cesium3DTileContentType.POINT_CLOUD:\n case Cesium3DTileContentType.VECTOR:\n case Cesium3DTileContentType.GEOMETRY:\n case Cesium3DTileContentType.IMPLICIT_SUBTREE:\n case Cesium3DTileContentType.VOXEL_BINARY:\n case Cesium3DTileContentType.GLTF_BINARY:\n return true;\n default:\n return false;\n }\n};\n\nexport default Object.freeze(Cesium3DTileContentType);\n", "/**\n * Hint defining optimization support for a 3D tile\n *\n * @enum {number}\n *\n * @private\n */\nconst Cesium3DTileOptimizationHint = {\n NOT_COMPUTED: -1,\n USE_OPTIMIZATION: 1,\n SKIP_OPTIMIZATION: 0,\n};\nexport default Object.freeze(Cesium3DTileOptimizationHint);\n", "/**\n * The pass in which a 3D Tileset is updated.\n *\n * @private\n */\nconst Cesium3DTilePass = {\n RENDER: 0,\n PICK: 1,\n SHADOW: 2,\n PRELOAD: 3,\n PRELOAD_FLIGHT: 4,\n REQUEST_RENDER_MODE_DEFER_CHECK: 5,\n MOST_DETAILED_PRELOAD: 6,\n MOST_DETAILED_PICK: 7,\n NUMBER_OF_PASSES: 8,\n};\n\nconst passOptions = new Array(Cesium3DTilePass.NUMBER_OF_PASSES);\n\npassOptions[Cesium3DTilePass.RENDER] = Object.freeze({\n pass: Cesium3DTilePass.RENDER,\n isRender: true,\n requestTiles: true,\n ignoreCommands: false,\n});\n\npassOptions[Cesium3DTilePass.PICK] = Object.freeze({\n pass: Cesium3DTilePass.PICK,\n isRender: false,\n requestTiles: false,\n ignoreCommands: false,\n});\n\npassOptions[Cesium3DTilePass.SHADOW] = Object.freeze({\n pass: Cesium3DTilePass.SHADOW,\n isRender: false,\n requestTiles: true,\n ignoreCommands: false,\n});\n\npassOptions[Cesium3DTilePass.PRELOAD] = Object.freeze({\n pass: Cesium3DTilePass.SHADOW,\n isRender: false,\n requestTiles: true,\n ignoreCommands: true,\n});\n\npassOptions[Cesium3DTilePass.PRELOAD_FLIGHT] = Object.freeze({\n pass: Cesium3DTilePass.PRELOAD_FLIGHT,\n isRender: false,\n requestTiles: true,\n ignoreCommands: true,\n});\n\npassOptions[Cesium3DTilePass.REQUEST_RENDER_MODE_DEFER_CHECK] = Object.freeze({\n pass: Cesium3DTilePass.REQUEST_RENDER_MODE_DEFER_CHECK,\n isRender: false,\n requestTiles: true,\n ignoreCommands: true,\n});\n\npassOptions[Cesium3DTilePass.MOST_DETAILED_PRELOAD] = Object.freeze({\n pass: Cesium3DTilePass.MOST_DETAILED_PRELOAD,\n isRender: false,\n requestTiles: true,\n ignoreCommands: true,\n});\n\npassOptions[Cesium3DTilePass.MOST_DETAILED_PICK] = Object.freeze({\n pass: Cesium3DTilePass.MOST_DETAILED_PICK,\n isRender: false,\n requestTiles: false,\n ignoreCommands: false,\n});\n\nCesium3DTilePass.getPassOptions = function (pass) {\n return passOptions[pass];\n};\nexport default Object.freeze(Cesium3DTilePass);\n", "import destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * Represents empty content for tiles in a\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles} tileset that\n * do not have content, e.g., because they are used to optimize hierarchical culling.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @alias Empty3DTileContent\n * @constructor\n *\n * @private\n */\nfunction Empty3DTileContent(tileset, tile) {\n this._tileset = tileset;\n this._tile = tile;\n\n this.featurePropertiesDirty = false;\n}\n\nObject.defineProperties(Empty3DTileContent.prototype, {\n featuresLength: {\n get: function () {\n return 0;\n },\n },\n\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n trianglesLength: {\n get: function () {\n return 0;\n },\n },\n\n geometryByteLength: {\n get: function () {\n return 0;\n },\n },\n\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n batchTableByteLength: {\n get: function () {\n return 0;\n },\n },\n\n innerContents: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Empty3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n return true;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n url: {\n get: function () {\n return undefined;\n },\n },\n\n metadata: {\n get: function () {\n return undefined;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"Empty3DTileContent cannot have content metadata\"\n );\n //>>includeEnd('debug');\n },\n },\n\n batchTable: {\n get: function () {\n return undefined;\n },\n },\n\n group: {\n get: function () {\n return undefined;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\"Empty3DTileContent cannot have group metadata\");\n //>>includeEnd('debug');\n },\n },\n});\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Empty3DTileContent\n * always returns false since a tile of this type does not have any features.\n */\nEmpty3DTileContent.prototype.hasProperty = function (batchId, name) {\n return false;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Empty3DTileContent\n * always returns undefined since a tile of this type does not have any features.\n */\nEmpty3DTileContent.prototype.getFeature = function (batchId) {\n return undefined;\n};\n\nEmpty3DTileContent.prototype.applyDebugSettings = function (enabled, color) {};\n\nEmpty3DTileContent.prototype.applyStyle = function (style) {};\n\nEmpty3DTileContent.prototype.update = function (tileset, frameState) {};\n\nEmpty3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nEmpty3DTileContent.prototype.destroy = function () {\n return destroyObject(this);\n};\nexport default Empty3DTileContent;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * Metadata about the content of a 3D Tile. This represents the content metadata JSON (3D Tiles 1.1)\n * or the 3DTILES_metadata extension on a single {@link Cesium3DTileContent}\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.content Either the content metadata JSON (3D Tiles 1.1) or the extension JSON attached to the content.\n * @param {MetadataClass} options.class The class that the content metadata conforms to.\n *\n * @alias ContentMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ContentMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const content = options.content;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.content\", content);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n this._class = metadataClass;\n this._properties = content.properties;\n this._extensions = content.extensions;\n this._extras = content.extras;\n}\n\nObject.defineProperties(ContentMetadata.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof ContentMetadata.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof ContentMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof ContentMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the content has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the content has this property.\n * @private\n */\nContentMetadata.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the content has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the content has a property with the given semantic.\n * @private\n */\nContentMetadata.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nContentMetadata.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the content does not have this property.\n * @private\n */\nContentMetadata.prototype.getProperty = function (propertyId) {\n return MetadataEntity.getProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nContentMetadata.prototype.setProperty = function (propertyId, value) {\n return MetadataEntity.setProperty(\n propertyId,\n value,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the content does not have this semantic.\n * @private\n */\nContentMetadata.prototype.getPropertyBySemantic = function (semantic) {\n return MetadataEntity.getPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nContentMetadata.prototype.setPropertyBySemantic = function (semantic, value) {\n return MetadataEntity.setPropertyBySemantic(\n semantic,\n value,\n this._properties,\n this._class\n );\n};\n\nexport default ContentMetadata;\n", "import ContentMetadata from \"./ContentMetadata.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\n\n/**\n * Check if a content has metadata, either defined in its metadata field (3D Tiles 1.1) or in\n * the 3DTILES_metadata extension. If defined, get the content metadata\n * with the corresponding class.\n *\n * @function\n *\n * @param {Cesium3DTileset} tileset The tileset to query for content metadata\n * @param {object} contentHeader the JSON header for a {@link Cesium3DTileContent}\n * @return {ContentMetadata} the content metadata, or undefined if not found\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction findContentMetadata(tileset, contentHeader) {\n const metadataJson = hasExtension(contentHeader, \"3DTILES_metadata\")\n ? contentHeader.extensions[\"3DTILES_metadata\"]\n : contentHeader.metadata;\n\n if (!defined(metadataJson)) {\n return undefined;\n }\n\n if (!defined(tileset.schema)) {\n findContentMetadata._oneTimeWarning(\n \"findContentMetadata-missing-root-schema\",\n \"Could not find a metadata schema for content metadata. For tilesets that contain external tilesets, make sure the schema is added to the root tileset.json.\"\n );\n return undefined;\n }\n\n const classes = defaultValue(\n tileset.schema.classes,\n defaultValue.EMPTY_OBJECT\n );\n if (defined(metadataJson.class)) {\n const contentClass = classes[metadataJson.class];\n return new ContentMetadata({\n content: metadataJson,\n class: contentClass,\n });\n }\n\n return undefined;\n}\n\n// Exposed for testing\nfindContentMetadata._oneTimeWarning = oneTimeWarning;\nexport default findContentMetadata;\n", "import defined from \"../Core/defined.js\";\nimport hasExtension from \"./hasExtension.js\";\n\n/**\n * Check if a content has metadata, either defined in its metadata field (3D Tiles 1.1)\n * or in the 3DTILES_metadata extension. If so, look up the group with the\n * corresponding ID.\n *\n * @function\n *\n * @param {Cesium3DTileset} tileset The tileset to query for group metadata\n * @param {object} contentHeader the JSON header for a {@link Cesium3DTileContent}\n * @return {GroupMetadata} the group metadata, or undefined if not found\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction findGroupMetadata(tileset, contentHeader) {\n const metadataExtension = tileset.metadataExtension;\n if (!defined(metadataExtension)) {\n return undefined;\n }\n const groups = metadataExtension.groups;\n\n const group = hasExtension(contentHeader, \"3DTILES_metadata\")\n ? contentHeader.extensions[\"3DTILES_metadata\"].group\n : contentHeader.group;\n\n if (typeof group === \"number\") {\n return groups[group];\n }\n\n const index = metadataExtension.groupIds.findIndex(function (id) {\n return id === group;\n });\n\n return index >= 0 ? groups[index] : undefined;\n}\n\nexport default findGroupMetadata;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * Metadata about a 3D Tile. This represents the tile metadata JSON (3D Tiles 1.1)\n * or the 3DTILES_metadata extension on a single {@link Cesium3DTile}\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.tile Either the tile metadata JSON (3D Tiles 1.1), or the extension JSON attached to the tile.\n * @param {MetadataClass} options.class The class that the tile metadata conforms to.\n *\n * @alias TileMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction TileMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const tile = options.tile;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.tile\", tile);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n this._class = metadataClass;\n this._properties = tile.properties;\n this._extensions = tile.extensions;\n this._extras = tile.extras;\n}\n\nObject.defineProperties(TileMetadata.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof TileMetadata.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof TileMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof TileMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the tile has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the tile has this property.\n * @private\n */\nTileMetadata.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the tile has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the tile has a property with the given semantic.\n * @private\n */\nTileMetadata.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nTileMetadata.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the tile does not have this property.\n * @private\n */\nTileMetadata.prototype.getProperty = function (propertyId) {\n return MetadataEntity.getProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nTileMetadata.prototype.setProperty = function (propertyId, value) {\n return MetadataEntity.setProperty(\n propertyId,\n value,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the tile does not have this semantic.\n * @private\n */\nTileMetadata.prototype.getPropertyBySemantic = function (semantic) {\n return MetadataEntity.getPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nTileMetadata.prototype.setPropertyBySemantic = function (semantic, value) {\n return MetadataEntity.setPropertyBySemantic(\n semantic,\n value,\n this._properties,\n this._class\n );\n};\n\nexport default TileMetadata;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport TileMetadata from \"./TileMetadata.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\n\n/**\n * Check if a tile has metadata, either defined in its metadata field (3D Tiles 1.1)\n * or in the 3DTILES_metadata extension. If defined, get the tile metadata\n * with the corresponding class.\n *

\n * This assumes that tileset.metadata has been created before any tiles are constructed.\n *

\n * @function\n *\n * @param {Cesium3DTileset} tileset The tileset to query for tile metadata\n * @param {object} tileHeader the JSON header for a {@link Cesium3DTile}\n * @return {TileMetadata} the tile metadata, or undefined if not found\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction findTileMetadata(tileset, tileHeader) {\n const metadataJson = hasExtension(tileHeader, \"3DTILES_metadata\")\n ? tileHeader.extensions[\"3DTILES_metadata\"]\n : tileHeader.metadata;\n\n if (!defined(metadataJson)) {\n return undefined;\n }\n\n if (!defined(tileset.schema)) {\n findTileMetadata._oneTimeWarning(\n \"findTileMetadata-missing-root-schema\",\n \"Could not find a metadata schema for tile metadata. For tilesets that contain external tilesets, make sure the schema is added to the root tileset.json.\"\n );\n return undefined;\n }\n\n const classes = defaultValue(\n tileset.schema.classes,\n defaultValue.EMPTY_OBJECT\n );\n if (defined(metadataJson.class)) {\n const tileClass = classes[metadataJson.class];\n return new TileMetadata({\n tile: metadataJson,\n class: tileClass,\n });\n }\n\n return undefined;\n}\n\n// Exposed for testing\nfindTileMetadata._oneTimeWarning = oneTimeWarning;\nexport default findTileMetadata;\n", "import defined from \"../Core/defined.js\";\nimport getJsonFromTypedArray from \"../Core/getJsonFromTypedArray.js\";\nimport getMagic from \"../Core/getMagic.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Cesium3DTileContentType from \"./Cesium3DTileContentType.js\";\n\n/**\n * Results of the preprocess3DTileContent() function. This includes the\n * {@link Cesium3DTileContentType} and the payload. The payload is either\n * binary or JSON depending on the content type.\n *\n * @typedef {object} PreprocessedContent\n * @property {Cesium3DTileContentType} contentType The type of the content\n * @property {Uint8Array} [binaryPayload] For binary files, the payload is returned as a typed array with byteOffset of 0\n * @property {object} [jsonPayload] For JSON files, the results are returned as a JSON object.\n * @private\n */\n\n/**\n * Preprocess a {@link Cesium3DTileContent}, to determine the type of content\n * and to parse JSON files into objects.\n *\n * @param {ArrayBuffer} arrayBuffer The raw binary payload\n * @return {PreprocessedContent}\n * @private\n */\nfunction preprocess3DTileContent(arrayBuffer) {\n const uint8Array = new Uint8Array(arrayBuffer);\n let contentType = getMagic(uint8Array);\n\n // We use glTF for JSON glTF files. For binary glTF, we rename this\n // to glb to disambiguate\n if (contentType === \"glTF\") {\n contentType = \"glb\";\n }\n\n if (Cesium3DTileContentType.isBinaryFormat(contentType)) {\n return {\n // For binary files, the enum value is the magic number\n contentType: contentType,\n binaryPayload: uint8Array,\n };\n }\n\n const json = getJsonContent(uint8Array);\n if (defined(json.root)) {\n // Most likely a tileset JSON\n return {\n contentType: Cesium3DTileContentType.EXTERNAL_TILESET,\n jsonPayload: json,\n };\n }\n\n if (defined(json.asset)) {\n // Most likely a glTF. Tileset JSON also has an \"asset\" property\n // so this check needs to happen second\n return {\n contentType: Cesium3DTileContentType.GLTF,\n jsonPayload: json,\n };\n }\n\n if (defined(json.tileAvailability)) {\n // Most likely a subtree JSON.\n return {\n contentType: Cesium3DTileContentType.IMPLICIT_SUBTREE_JSON,\n jsonPayload: json,\n };\n }\n\n if (defined(json.type)) {\n // Most likely a GeoJSON\n return {\n contentType: Cesium3DTileContentType.GEOJSON,\n jsonPayload: json,\n };\n }\n\n if (defined(json.voxelTable)) {\n // Most likely a voxel JSON\n return {\n contentType: Cesium3DTileContentType.VOXEL_JSON,\n jsonPayload: json,\n };\n }\n\n throw new RuntimeError(\"Invalid tile content.\");\n}\n\nfunction getJsonContent(uint8Array) {\n let json;\n\n try {\n json = getJsonFromTypedArray(uint8Array);\n } catch (error) {\n throw new RuntimeError(\"Invalid tile content.\");\n }\n\n return json;\n}\n\nexport default preprocess3DTileContent;\n", "import defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Request from \"../Core/Request.js\";\nimport RequestScheduler from \"../Core/RequestScheduler.js\";\nimport RequestState from \"../Core/RequestState.js\";\nimport RequestType from \"../Core/RequestType.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Cesium3DContentGroup from \"./Cesium3DContentGroup.js\";\nimport Cesium3DTileContentType from \"./Cesium3DTileContentType.js\";\nimport Cesium3DTileContentFactory from \"./Cesium3DTileContentFactory.js\";\nimport findContentMetadata from \"./findContentMetadata.js\";\nimport findGroupMetadata from \"./findGroupMetadata.js\";\nimport preprocess3DTileContent from \"./preprocess3DTileContent.js\";\n\n/**\n * A collection of contents for tiles that have multiple contents, either via the tile JSON (3D Tiles 1.1) or the 3DTILES_multiple_contents extension.\n *

\n * Implements the {@link Cesium3DTileContent} interface.\n *

\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_multiple_contents|3DTILES_multiple_contents extension}\n *\n * @alias Multiple3DTileContent\n * @constructor\n *\n * @param {Cesium3DTileset} tileset The tileset this content belongs to\n * @param {Cesium3DTile} tile The content this content belongs to\n * @param {Resource} tilesetResource The resource that points to the tileset. This will be used to derive each inner content's resource.\n * @param {object} contentsJson Either the tile JSON containing the contents array (3D Tiles 1.1), or 3DTILES_multiple_contents extension JSON\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction Multiple3DTileContent(tileset, tile, tilesetResource, contentsJson) {\n this._tileset = tileset;\n this._tile = tile;\n this._tilesetResource = tilesetResource;\n this._contents = [];\n this._contentsCreated = false;\n\n // An older version of 3DTILES_multiple_contents used \"content\" instead of \"contents\"\n const contentHeaders = defined(contentsJson.contents)\n ? contentsJson.contents\n : contentsJson.content;\n\n this._innerContentHeaders = contentHeaders;\n this._requestsInFlight = 0;\n\n // How many times cancelPendingRequests() has been called. This is\n // used to help short-circuit computations after a tile was canceled.\n this._cancelCount = 0;\n\n const contentCount = this._innerContentHeaders.length;\n this._arrayFetchPromises = new Array(contentCount);\n this._requests = new Array(contentCount);\n this._ready = false;\n\n this._innerContentResources = new Array(contentCount);\n this._serverKeys = new Array(contentCount);\n\n for (let i = 0; i < contentCount; i++) {\n const contentResource = tilesetResource.getDerivedResource({\n url: contentHeaders[i].uri,\n });\n\n const serverKey = RequestScheduler.getServerKey(\n contentResource.getUrlComponent()\n );\n\n this._innerContentResources[i] = contentResource;\n this._serverKeys[i] = serverKey;\n }\n}\n\nObject.defineProperties(Multiple3DTileContent.prototype, {\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent checks if any of the inner contents have dirty featurePropertiesDirty.\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {boolean}\n *\n * @private\n */\n featurePropertiesDirty: {\n get: function () {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n if (contents[i].featurePropertiesDirty) {\n return true;\n }\n }\n\n return false;\n },\n set: function (value) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].featurePropertiesDirty = value;\n }\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead call featuresLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n featuresLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead, call pointsLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n pointsLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead call trianglesLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n trianglesLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead call geometryByteLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n geometryByteLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead call texturesByteLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n texturesByteLength: {\n get: function () {\n return 0;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns 0. Instead call batchTableByteLength for a specific inner content.\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n batchTableByteLength: {\n get: function () {\n return 0;\n },\n },\n\n innerContents: {\n get: function () {\n return this._contents;\n },\n },\n\n /**\n * Returns true when the tile's content is ready to render; otherwise false\n *\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {boolean}\n * @readonly\n * @private\n */\n ready: {\n get: function () {\n if (!this._contentsCreated) {\n return false;\n }\n\n return this._ready;\n },\n },\n\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n tile: {\n get: function () {\n return this._tile;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface.\n * Unlike other content types, Multiple3DTileContent does not\n * have a single URL, so this returns undefined.\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {string}\n * @readonly\n * @private\n */\n url: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns undefined. Instead call metadata for a specific inner content.\n * @memberof Multiple3DTileContent.prototype\n * @private\n */\n metadata: {\n get: function () {\n return undefined;\n },\n set: function () {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\"Multiple3DTileContent cannot have metadata\");\n //>>includeEnd('debug');\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns undefined. Instead call batchTable for a specific inner content.\n * @memberof Multiple3DTileContent.prototype\n * @private\n */\n batchTable: {\n get: function () {\n return undefined;\n },\n },\n\n /**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns undefined. Instead call group for a specific inner content.\n * @memberof Multiple3DTileContent.prototype\n * @private\n */\n group: {\n get: function () {\n return undefined;\n },\n set: function () {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"Multiple3DTileContent cannot have group metadata\"\n );\n //>>includeEnd('debug');\n },\n },\n\n /**\n * Get an array of the inner content URLs, regardless of whether they've\n * been fetched or not. This is intended for use with\n * {@link Cesium3DTileset#debugShowUrl}.\n * @memberof Multiple3DTileContent.prototype\n *\n * @type {string[]}\n * @readonly\n * @private\n */\n innerContentUrls: {\n get: function () {\n return this._innerContentHeaders.map(function (contentHeader) {\n return contentHeader.uri;\n });\n },\n },\n});\n\nfunction updatePendingRequests(multipleContents, deltaRequestCount) {\n multipleContents._requestsInFlight += deltaRequestCount;\n multipleContents.tileset.statistics.numberOfPendingRequests += deltaRequestCount;\n}\n\nfunction cancelPendingRequests(multipleContents, originalContentState) {\n multipleContents._cancelCount++;\n\n // reset the tile's content state to try again later.\n multipleContents._tile._contentState = originalContentState;\n\n const statistics = multipleContents.tileset.statistics;\n\n statistics.numberOfPendingRequests -= multipleContents._requestsInFlight;\n statistics.numberOfAttemptedRequests += multipleContents._requestsInFlight;\n multipleContents._requestsInFlight = 0;\n\n // Discard the request promises.\n const contentCount = multipleContents._innerContentHeaders.length;\n multipleContents._arrayFetchPromises = new Array(contentCount);\n}\n\n/**\n * Request the inner contents of this Multiple3DTileContent. This must be called once a frame until\n * {@link Multiple3DTileContent#contentsFetchedPromise} is defined. This promise\n * becomes available as soon as all requests are scheduled.\n *

\n * This method also updates the tile statistics' pending request count if the\n * requests are successfully scheduled.\n *

\n *\n * @return {Promise|undefined} A promise that resolves when the request completes, or undefined if there is no request needed, or the request cannot be scheduled.\n * @private\n */\nMultiple3DTileContent.prototype.requestInnerContents = function () {\n // It's possible for these promises to leak content array buffers if the\n // camera moves before they all are scheduled. To prevent this leak, check\n // if we can schedule all the requests at once. If not, no requests are\n // scheduled\n if (!canScheduleAllRequests(this._serverKeys)) {\n this.tileset.statistics.numberOfAttemptedRequests += this._serverKeys.length;\n return;\n }\n\n const contentHeaders = this._innerContentHeaders;\n updatePendingRequests(this, contentHeaders.length);\n\n const originalCancelCount = this._cancelCount;\n for (let i = 0; i < contentHeaders.length; i++) {\n // The cancel count is needed to avoid a race condition where a content\n // is canceled multiple times.\n this._arrayFetchPromises[i] = requestInnerContent(\n this,\n i,\n originalCancelCount,\n this._tile._contentState\n );\n }\n\n return createInnerContents(this);\n};\n\n/**\n * Check if all requests for inner contents can be scheduled at once. This is slower, but it avoids a potential memory leak.\n * @param {string[]} serverKeys The server keys for all of the inner contents\n * @return {boolean} True if the request scheduler has enough open slots for all inner contents\n * @private\n */\nfunction canScheduleAllRequests(serverKeys) {\n const requestCountsByServer = {};\n for (let i = 0; i < serverKeys.length; i++) {\n const serverKey = serverKeys[i];\n if (defined(requestCountsByServer[serverKey])) {\n requestCountsByServer[serverKey]++;\n } else {\n requestCountsByServer[serverKey] = 1;\n }\n }\n\n for (const key in requestCountsByServer) {\n if (\n requestCountsByServer.hasOwnProperty(key) &&\n !RequestScheduler.serverHasOpenSlots(key, requestCountsByServer[key])\n ) {\n return false;\n }\n }\n return RequestScheduler.heapHasOpenSlots(serverKeys.length);\n}\n\nfunction requestInnerContent(\n multipleContents,\n index,\n originalCancelCount,\n originalContentState\n) {\n // it is important to clone here. The fetchArrayBuffer() below here uses\n // throttling, but other uses of the resources do not.\n const contentResource = multipleContents._innerContentResources[\n index\n ].clone();\n const tile = multipleContents.tile;\n\n // Always create a new request. If the tile gets canceled, this\n // avoids getting stuck in the canceled state.\n const priorityFunction = function () {\n return tile._priority;\n };\n const serverKey = multipleContents._serverKeys[index];\n const request = new Request({\n throttle: true,\n throttleByServer: true,\n type: RequestType.TILES3D,\n priorityFunction: priorityFunction,\n serverKey: serverKey,\n });\n contentResource.request = request;\n multipleContents._requests[index] = request;\n\n const promise = contentResource.fetchArrayBuffer();\n if (!defined(promise)) {\n return;\n }\n\n return promise\n .then(function (arrayBuffer) {\n // Pending requests have already been canceled.\n if (originalCancelCount < multipleContents._cancelCount) {\n return;\n }\n\n if (\n contentResource.request.cancelled ||\n contentResource.request.state === RequestState.CANCELLED\n ) {\n cancelPendingRequests(multipleContents, originalContentState);\n return;\n }\n\n updatePendingRequests(multipleContents, -1);\n return arrayBuffer;\n })\n .catch(function (error) {\n // Pending requests have already been canceled.\n if (originalCancelCount < multipleContents._cancelCount) {\n return;\n }\n\n if (\n contentResource.request.cancelled ||\n contentResource.request.state === RequestState.CANCELLED\n ) {\n cancelPendingRequests(multipleContents, originalContentState);\n return;\n }\n\n updatePendingRequests(multipleContents, -1);\n handleInnerContentFailed(multipleContents, index, error);\n });\n}\n\nasync function createInnerContents(multipleContents) {\n const originalCancelCount = multipleContents._cancelCount;\n const arrayBuffers = await Promise.all(multipleContents._arrayFetchPromises);\n // Request have been cancelled\n if (originalCancelCount < multipleContents._cancelCount) {\n return;\n }\n\n const promises = arrayBuffers.map((arrayBuffer, i) =>\n createInnerContent(multipleContents, arrayBuffer, i)\n );\n\n // Even if we had a partial success (in which case the inner promise will be handled, but the content will not be returned), mark that we finished creating\n // contents\n const contents = await Promise.all(promises);\n multipleContents._contentsCreated = true;\n multipleContents._contents = contents.filter(defined);\n return contents;\n}\n\nasync function createInnerContent(multipleContents, arrayBuffer, index) {\n if (!defined(arrayBuffer)) {\n // Content was not fetched. The error was handled in\n // the fetch promise. Return undefined to indicate partial failure.\n return;\n }\n\n try {\n const preprocessed = preprocess3DTileContent(arrayBuffer);\n\n if (preprocessed.contentType === Cesium3DTileContentType.EXTERNAL_TILESET) {\n throw new RuntimeError(\n \"External tilesets are disallowed inside multiple contents\"\n );\n }\n\n multipleContents._disableSkipLevelOfDetail =\n multipleContents._disableSkipLevelOfDetail ||\n preprocessed.contentType === Cesium3DTileContentType.GEOMETRY ||\n preprocessed.contentType === Cesium3DTileContentType.VECTOR;\n\n const tileset = multipleContents._tileset;\n const resource = multipleContents._innerContentResources[index];\n const tile = multipleContents._tile;\n\n let content;\n const contentFactory = Cesium3DTileContentFactory[preprocessed.contentType];\n if (defined(preprocessed.binaryPayload)) {\n content = await Promise.resolve(\n contentFactory(\n tileset,\n tile,\n resource,\n preprocessed.binaryPayload.buffer,\n 0\n )\n );\n } else {\n // JSON formats\n content = await Promise.resolve(\n contentFactory(tileset, tile, resource, preprocessed.jsonPayload)\n );\n }\n\n const contentHeader = multipleContents._innerContentHeaders[index];\n\n if (tile.hasImplicitContentMetadata) {\n const subtree = tile.implicitSubtree;\n const coordinates = tile.implicitCoordinates;\n content.metadata = subtree.getContentMetadataView(coordinates, index);\n } else if (!tile.hasImplicitContent) {\n content.metadata = findContentMetadata(tileset, contentHeader);\n }\n\n const groupMetadata = findGroupMetadata(tileset, contentHeader);\n if (defined(groupMetadata)) {\n content.group = new Cesium3DContentGroup({\n metadata: groupMetadata,\n });\n }\n return content;\n } catch (error) {\n handleInnerContentFailed(multipleContents, index, error);\n }\n}\n\nfunction handleInnerContentFailed(multipleContents, index, error) {\n const tileset = multipleContents._tileset;\n const url = multipleContents._innerContentResources[index].url;\n const message = defined(error.message) ? error.message : error.toString();\n if (tileset.tileFailed.numberOfListeners > 0) {\n tileset.tileFailed.raiseEvent({\n url: url,\n message: message,\n });\n } else {\n console.log(`A content failed to load: ${url}`);\n console.log(`Error: ${message}`);\n }\n}\n\n/**\n * Cancel all requests for inner contents. This is called by the tile\n * when a tile goes out of view.\n *\n * @private\n */\nMultiple3DTileContent.prototype.cancelRequests = function () {\n for (let i = 0; i < this._requests.length; i++) {\n const request = this._requests[i];\n if (defined(request)) {\n request.cancel();\n }\n }\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns false. Instead call hasProperty for a specific inner content\n * @private\n */\nMultiple3DTileContent.prototype.hasProperty = function (batchId, name) {\n return false;\n};\n\n/**\n * Part of the {@link Cesium3DTileContent} interface. Multiple3DTileContent\n * always returns undefined. Instead call getFeature for a specific inner content\n * @private\n */\nMultiple3DTileContent.prototype.getFeature = function (batchId) {\n return undefined;\n};\n\nMultiple3DTileContent.prototype.applyDebugSettings = function (enabled, color) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].applyDebugSettings(enabled, color);\n }\n};\n\nMultiple3DTileContent.prototype.applyStyle = function (style) {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].applyStyle(style);\n }\n};\n\nMultiple3DTileContent.prototype.update = function (tileset, frameState) {\n const contents = this._contents;\n const length = contents.length;\n let ready = true;\n for (let i = 0; i < length; ++i) {\n contents[i].update(tileset, frameState);\n ready = ready && contents[i].ready;\n }\n\n if (!this._ready && ready) {\n this._ready = true;\n }\n};\n\nMultiple3DTileContent.prototype.isDestroyed = function () {\n return false;\n};\n\nMultiple3DTileContent.prototype.destroy = function () {\n const contents = this._contents;\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n contents[i].destroy();\n }\n return destroyObject(this);\n};\n\nexport default Multiple3DTileContent;\n", "import earcut from \"earcut\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidRhumbLine from \"./EllipsoidRhumbLine.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport WindingOrder from \"./WindingOrder.js\";\n\nconst scaleToGeodeticHeightN = new Cartesian3();\nconst scaleToGeodeticHeightP = new Cartesian3();\n\n/**\n * @private\n */\nconst PolygonPipeline = {};\n\n/**\n * @exception {DeveloperError} At least three positions are required.\n */\nPolygonPipeline.computeArea2D = function (positions) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n Check.typeOf.number.greaterThanOrEquals(\n \"positions.length\",\n positions.length,\n 3\n );\n //>>includeEnd('debug');\n\n const length = positions.length;\n let area = 0.0;\n\n for (let i0 = length - 1, i1 = 0; i1 < length; i0 = i1++) {\n const v0 = positions[i0];\n const v1 = positions[i1];\n\n area += v0.x * v1.y - v1.x * v0.y;\n }\n\n return area * 0.5;\n};\n\n/**\n * @returns {WindingOrder} The winding order.\n *\n * @exception {DeveloperError} At least three positions are required.\n */\nPolygonPipeline.computeWindingOrder2D = function (positions) {\n const area = PolygonPipeline.computeArea2D(positions);\n return area > 0.0 ? WindingOrder.COUNTER_CLOCKWISE : WindingOrder.CLOCKWISE;\n};\n\n/**\n * Triangulate a polygon.\n *\n * @param {Cartesian2[]} positions Cartesian2 array containing the vertices of the polygon\n * @param {number[]} [holes] An array of the staring indices of the holes.\n * @returns {number[]} Index array representing triangles that fill the polygon\n */\nPolygonPipeline.triangulate = function (positions, holes) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n //>>includeEnd('debug');\n\n const flattenedPositions = Cartesian2.packArray(positions);\n return earcut(flattenedPositions, holes, 2);\n};\n\nconst subdivisionV0Scratch = new Cartesian3();\nconst subdivisionV1Scratch = new Cartesian3();\nconst subdivisionV2Scratch = new Cartesian3();\nconst subdivisionS0Scratch = new Cartesian3();\nconst subdivisionS1Scratch = new Cartesian3();\nconst subdivisionS2Scratch = new Cartesian3();\nconst subdivisionMidScratch = new Cartesian3();\nconst subdivisionT0Scratch = new Cartesian2();\nconst subdivisionT1Scratch = new Cartesian2();\nconst subdivisionT2Scratch = new Cartesian2();\nconst subdivisionTexcoordMidScratch = new Cartesian2();\n\n/**\n * Subdivides positions and raises points to the surface of the ellipsoid.\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid the polygon in on.\n * @param {Cartesian3[]} positions An array of {@link Cartesian3} positions of the polygon.\n * @param {number[]} indices An array of indices that determines the triangles in the polygon.\n * @param {Cartesian2[]} texcoords An optional array of {@link Cartesian2} texture coordinates of the polygon.\n * @param {number} [granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n *\n * @exception {DeveloperError} At least three indices are required.\n * @exception {DeveloperError} The number of indices must be divisable by three.\n * @exception {DeveloperError} Granularity must be greater than zero.\n */\nPolygonPipeline.computeSubdivision = function (\n ellipsoid,\n positions,\n indices,\n texcoords,\n granularity\n) {\n granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE);\n\n const hasTexcoords = defined(texcoords);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n Check.defined(\"positions\", positions);\n Check.defined(\"indices\", indices);\n Check.typeOf.number.greaterThanOrEquals(\"indices.length\", indices.length, 3);\n Check.typeOf.number.equals(\"indices.length % 3\", \"0\", indices.length % 3, 0);\n Check.typeOf.number.greaterThan(\"granularity\", granularity, 0.0);\n //>>includeEnd('debug');\n\n // triangles that need (or might need) to be subdivided.\n const triangles = indices.slice(0);\n\n // New positions due to edge splits are appended to the positions list.\n let i;\n const length = positions.length;\n const subdividedPositions = new Array(length * 3);\n const subdividedTexcoords = new Array(length * 2);\n let q = 0;\n let p = 0;\n for (i = 0; i < length; i++) {\n const item = positions[i];\n subdividedPositions[q++] = item.x;\n subdividedPositions[q++] = item.y;\n subdividedPositions[q++] = item.z;\n\n if (hasTexcoords) {\n const texcoordItem = texcoords[i];\n subdividedTexcoords[p++] = texcoordItem.x;\n subdividedTexcoords[p++] = texcoordItem.y;\n }\n }\n\n const subdividedIndices = [];\n\n // Used to make sure shared edges are not split more than once.\n const edges = {};\n\n const radius = ellipsoid.maximumRadius;\n const minDistance = CesiumMath.chordLength(granularity, radius);\n const minDistanceSqrd = minDistance * minDistance;\n\n while (triangles.length > 0) {\n const i2 = triangles.pop();\n const i1 = triangles.pop();\n const i0 = triangles.pop();\n\n const v0 = Cartesian3.fromArray(\n subdividedPositions,\n i0 * 3,\n subdivisionV0Scratch\n );\n const v1 = Cartesian3.fromArray(\n subdividedPositions,\n i1 * 3,\n subdivisionV1Scratch\n );\n const v2 = Cartesian3.fromArray(\n subdividedPositions,\n i2 * 3,\n subdivisionV2Scratch\n );\n\n let t0, t1, t2;\n if (hasTexcoords) {\n t0 = Cartesian2.fromArray(\n subdividedTexcoords,\n i0 * 2,\n subdivisionT0Scratch\n );\n t1 = Cartesian2.fromArray(\n subdividedTexcoords,\n i1 * 2,\n subdivisionT1Scratch\n );\n t2 = Cartesian2.fromArray(\n subdividedTexcoords,\n i2 * 2,\n subdivisionT2Scratch\n );\n }\n\n const s0 = Cartesian3.multiplyByScalar(\n Cartesian3.normalize(v0, subdivisionS0Scratch),\n radius,\n subdivisionS0Scratch\n );\n const s1 = Cartesian3.multiplyByScalar(\n Cartesian3.normalize(v1, subdivisionS1Scratch),\n radius,\n subdivisionS1Scratch\n );\n const s2 = Cartesian3.multiplyByScalar(\n Cartesian3.normalize(v2, subdivisionS2Scratch),\n radius,\n subdivisionS2Scratch\n );\n\n const g0 = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(s0, s1, subdivisionMidScratch)\n );\n const g1 = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(s1, s2, subdivisionMidScratch)\n );\n const g2 = Cartesian3.magnitudeSquared(\n Cartesian3.subtract(s2, s0, subdivisionMidScratch)\n );\n\n const max = Math.max(g0, g1, g2);\n let edge;\n let mid;\n let midTexcoord;\n\n // if the max length squared of a triangle edge is greater than the chord length of squared\n // of the granularity, subdivide the triangle\n if (max > minDistanceSqrd) {\n if (g0 === max) {\n edge = `${Math.min(i0, i1)} ${Math.max(i0, i1)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = Cartesian3.add(v0, v1, subdivisionMidScratch);\n Cartesian3.multiplyByScalar(mid, 0.5, mid);\n subdividedPositions.push(mid.x, mid.y, mid.z);\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t0, t1, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i0, i, i2);\n triangles.push(i, i1, i2);\n } else if (g1 === max) {\n edge = `${Math.min(i1, i2)} ${Math.max(i1, i2)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = Cartesian3.add(v1, v2, subdivisionMidScratch);\n Cartesian3.multiplyByScalar(mid, 0.5, mid);\n subdividedPositions.push(mid.x, mid.y, mid.z);\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t1, t2, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i1, i, i0);\n triangles.push(i, i2, i0);\n } else if (g2 === max) {\n edge = `${Math.min(i2, i0)} ${Math.max(i2, i0)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = Cartesian3.add(v2, v0, subdivisionMidScratch);\n Cartesian3.multiplyByScalar(mid, 0.5, mid);\n subdividedPositions.push(mid.x, mid.y, mid.z);\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t2, t0, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i2, i, i1);\n triangles.push(i, i0, i1);\n }\n } else {\n subdividedIndices.push(i0);\n subdividedIndices.push(i1);\n subdividedIndices.push(i2);\n }\n }\n\n const geometryOptions = {\n attributes: {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: subdividedPositions,\n }),\n },\n indices: subdividedIndices,\n primitiveType: PrimitiveType.TRIANGLES,\n };\n\n if (hasTexcoords) {\n geometryOptions.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: subdividedTexcoords,\n });\n }\n\n return new Geometry(geometryOptions);\n};\n\nconst subdivisionC0Scratch = new Cartographic();\nconst subdivisionC1Scratch = new Cartographic();\nconst subdivisionC2Scratch = new Cartographic();\nconst subdivisionCartographicScratch = new Cartographic();\n\n/**\n * Subdivides positions on rhumb lines and raises points to the surface of the ellipsoid.\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid the polygon in on.\n * @param {Cartesian3[]} positions An array of {@link Cartesian3} positions of the polygon.\n * @param {number[]} indices An array of indices that determines the triangles in the polygon.\n * @param {Cartesian2[]} texcoords An optional array of {@link Cartesian2} texture coordinates of the polygon.\n * @param {number} [granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n *\n * @exception {DeveloperError} At least three indices are required.\n * @exception {DeveloperError} The number of indices must be divisable by three.\n * @exception {DeveloperError} Granularity must be greater than zero.\n */\nPolygonPipeline.computeRhumbLineSubdivision = function (\n ellipsoid,\n positions,\n indices,\n texcoords,\n granularity\n) {\n granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE);\n\n const hasTexcoords = defined(texcoords);\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n Check.defined(\"positions\", positions);\n Check.defined(\"indices\", indices);\n Check.typeOf.number.greaterThanOrEquals(\"indices.length\", indices.length, 3);\n Check.typeOf.number.equals(\"indices.length % 3\", \"0\", indices.length % 3, 0);\n Check.typeOf.number.greaterThan(\"granularity\", granularity, 0.0);\n //>>includeEnd('debug');\n\n // triangles that need (or might need) to be subdivided.\n const triangles = indices.slice(0);\n\n // New positions due to edge splits are appended to the positions list.\n let i;\n const length = positions.length;\n const subdividedPositions = new Array(length * 3);\n const subdividedTexcoords = new Array(length * 2);\n let q = 0;\n let p = 0;\n for (i = 0; i < length; i++) {\n const item = positions[i];\n subdividedPositions[q++] = item.x;\n subdividedPositions[q++] = item.y;\n subdividedPositions[q++] = item.z;\n\n if (hasTexcoords) {\n const texcoordItem = texcoords[i];\n subdividedTexcoords[p++] = texcoordItem.x;\n subdividedTexcoords[p++] = texcoordItem.y;\n }\n }\n\n const subdividedIndices = [];\n\n // Used to make sure shared edges are not split more than once.\n const edges = {};\n\n const radius = ellipsoid.maximumRadius;\n const minDistance = CesiumMath.chordLength(granularity, radius);\n\n const rhumb0 = new EllipsoidRhumbLine(undefined, undefined, ellipsoid);\n const rhumb1 = new EllipsoidRhumbLine(undefined, undefined, ellipsoid);\n const rhumb2 = new EllipsoidRhumbLine(undefined, undefined, ellipsoid);\n\n while (triangles.length > 0) {\n const i2 = triangles.pop();\n const i1 = triangles.pop();\n const i0 = triangles.pop();\n\n const v0 = Cartesian3.fromArray(\n subdividedPositions,\n i0 * 3,\n subdivisionV0Scratch\n );\n const v1 = Cartesian3.fromArray(\n subdividedPositions,\n i1 * 3,\n subdivisionV1Scratch\n );\n const v2 = Cartesian3.fromArray(\n subdividedPositions,\n i2 * 3,\n subdivisionV2Scratch\n );\n\n let t0, t1, t2;\n if (hasTexcoords) {\n t0 = Cartesian2.fromArray(\n subdividedTexcoords,\n i0 * 2,\n subdivisionT0Scratch\n );\n t1 = Cartesian2.fromArray(\n subdividedTexcoords,\n i1 * 2,\n subdivisionT1Scratch\n );\n t2 = Cartesian2.fromArray(\n subdividedTexcoords,\n i2 * 2,\n subdivisionT2Scratch\n );\n }\n\n const c0 = ellipsoid.cartesianToCartographic(v0, subdivisionC0Scratch);\n const c1 = ellipsoid.cartesianToCartographic(v1, subdivisionC1Scratch);\n const c2 = ellipsoid.cartesianToCartographic(v2, subdivisionC2Scratch);\n\n rhumb0.setEndPoints(c0, c1);\n const g0 = rhumb0.surfaceDistance;\n rhumb1.setEndPoints(c1, c2);\n const g1 = rhumb1.surfaceDistance;\n rhumb2.setEndPoints(c2, c0);\n const g2 = rhumb2.surfaceDistance;\n\n const max = Math.max(g0, g1, g2);\n let edge;\n let mid;\n let midHeight;\n let midCartesian3;\n let midTexcoord;\n\n // if the max length squared of a triangle edge is greater than granularity, subdivide the triangle\n if (max > minDistance) {\n if (g0 === max) {\n edge = `${Math.min(i0, i1)} ${Math.max(i0, i1)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = rhumb0.interpolateUsingFraction(\n 0.5,\n subdivisionCartographicScratch\n );\n midHeight = (c0.height + c1.height) * 0.5;\n midCartesian3 = Cartesian3.fromRadians(\n mid.longitude,\n mid.latitude,\n midHeight,\n ellipsoid,\n subdivisionMidScratch\n );\n subdividedPositions.push(\n midCartesian3.x,\n midCartesian3.y,\n midCartesian3.z\n );\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t0, t1, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i0, i, i2);\n triangles.push(i, i1, i2);\n } else if (g1 === max) {\n edge = `${Math.min(i1, i2)} ${Math.max(i1, i2)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = rhumb1.interpolateUsingFraction(\n 0.5,\n subdivisionCartographicScratch\n );\n midHeight = (c1.height + c2.height) * 0.5;\n midCartesian3 = Cartesian3.fromRadians(\n mid.longitude,\n mid.latitude,\n midHeight,\n ellipsoid,\n subdivisionMidScratch\n );\n subdividedPositions.push(\n midCartesian3.x,\n midCartesian3.y,\n midCartesian3.z\n );\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t1, t2, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i1, i, i0);\n triangles.push(i, i2, i0);\n } else if (g2 === max) {\n edge = `${Math.min(i2, i0)} ${Math.max(i2, i0)}`;\n\n i = edges[edge];\n if (!defined(i)) {\n mid = rhumb2.interpolateUsingFraction(\n 0.5,\n subdivisionCartographicScratch\n );\n midHeight = (c2.height + c0.height) * 0.5;\n midCartesian3 = Cartesian3.fromRadians(\n mid.longitude,\n mid.latitude,\n midHeight,\n ellipsoid,\n subdivisionMidScratch\n );\n subdividedPositions.push(\n midCartesian3.x,\n midCartesian3.y,\n midCartesian3.z\n );\n i = subdividedPositions.length / 3 - 1;\n edges[edge] = i;\n\n if (hasTexcoords) {\n midTexcoord = Cartesian2.add(t2, t0, subdivisionTexcoordMidScratch);\n Cartesian2.multiplyByScalar(midTexcoord, 0.5, midTexcoord);\n subdividedTexcoords.push(midTexcoord.x, midTexcoord.y);\n }\n }\n\n triangles.push(i2, i, i1);\n triangles.push(i, i0, i1);\n }\n } else {\n subdividedIndices.push(i0);\n subdividedIndices.push(i1);\n subdividedIndices.push(i2);\n }\n }\n\n const geometryOptions = {\n attributes: {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: subdividedPositions,\n }),\n },\n indices: subdividedIndices,\n primitiveType: PrimitiveType.TRIANGLES,\n };\n\n if (hasTexcoords) {\n geometryOptions.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: subdividedTexcoords,\n });\n }\n\n return new Geometry(geometryOptions);\n};\n\n/**\n * Scales each position of a geometry's position attribute to a height, in place.\n *\n * @param {number[]} positions The array of numbers representing the positions to be scaled\n * @param {number} [height=0.0] The desired height to add to the positions\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.\n * @param {boolean} [scaleToSurface=true] true if the positions need to be scaled to the surface before the height is added.\n * @returns {number[]} The input array of positions, scaled to height\n */\nPolygonPipeline.scaleToGeodeticHeight = function (\n positions,\n height,\n ellipsoid,\n scaleToSurface\n) {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n let n = scaleToGeodeticHeightN;\n let p = scaleToGeodeticHeightP;\n\n height = defaultValue(height, 0.0);\n scaleToSurface = defaultValue(scaleToSurface, true);\n\n if (defined(positions)) {\n const length = positions.length;\n\n for (let i = 0; i < length; i += 3) {\n Cartesian3.fromArray(positions, i, p);\n\n if (scaleToSurface) {\n p = ellipsoid.scaleToGeodeticSurface(p, p);\n }\n\n if (height !== 0) {\n n = ellipsoid.geodeticSurfaceNormal(p, n);\n\n Cartesian3.multiplyByScalar(n, height, n);\n Cartesian3.add(p, n, p);\n }\n\n positions[i] = p.x;\n positions[i + 1] = p.y;\n positions[i + 2] = p.z;\n }\n }\n\n return positions;\n};\nexport default PolygonPipeline;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix2 from \"./Matrix2.js\";\nimport Rectangle from \"./Rectangle.js\";\n\nconst cos = Math.cos;\nconst sin = Math.sin;\nconst sqrt = Math.sqrt;\n\n/**\n * @private\n */\nconst RectangleGeometryLibrary = {};\n\n/**\n * @private\n */\nRectangleGeometryLibrary.computePosition = function (\n computedOptions,\n ellipsoid,\n computeST,\n row,\n col,\n position,\n st\n) {\n const radiiSquared = ellipsoid.radiiSquared;\n const nwCorner = computedOptions.nwCorner;\n const rectangle = computedOptions.boundingRectangle;\n\n let stLatitude =\n nwCorner.latitude -\n computedOptions.granYCos * row +\n col * computedOptions.granXSin;\n const cosLatitude = cos(stLatitude);\n const nZ = sin(stLatitude);\n const kZ = radiiSquared.z * nZ;\n\n let stLongitude =\n nwCorner.longitude +\n row * computedOptions.granYSin +\n col * computedOptions.granXCos;\n const nX = cosLatitude * cos(stLongitude);\n const nY = cosLatitude * sin(stLongitude);\n\n const kX = radiiSquared.x * nX;\n const kY = radiiSquared.y * nY;\n\n const gamma = sqrt(kX * nX + kY * nY + kZ * nZ);\n\n position.x = kX / gamma;\n position.y = kY / gamma;\n position.z = kZ / gamma;\n\n if (computeST) {\n const stNwCorner = computedOptions.stNwCorner;\n if (defined(stNwCorner)) {\n stLatitude =\n stNwCorner.latitude -\n computedOptions.stGranYCos * row +\n col * computedOptions.stGranXSin;\n stLongitude =\n stNwCorner.longitude +\n row * computedOptions.stGranYSin +\n col * computedOptions.stGranXCos;\n\n st.x = (stLongitude - computedOptions.stWest) * computedOptions.lonScalar;\n st.y = (stLatitude - computedOptions.stSouth) * computedOptions.latScalar;\n } else {\n st.x = (stLongitude - rectangle.west) * computedOptions.lonScalar;\n st.y = (stLatitude - rectangle.south) * computedOptions.latScalar;\n }\n }\n};\n\nconst rotationMatrixScratch = new Matrix2();\nlet nwCartesian = new Cartesian3();\nconst centerScratch = new Cartographic();\nlet centerCartesian = new Cartesian3();\nconst proj = new GeographicProjection();\n\nfunction getRotationOptions(\n nwCorner,\n rotation,\n granularityX,\n granularityY,\n center,\n width,\n height\n) {\n const cosRotation = Math.cos(rotation);\n const granYCos = granularityY * cosRotation;\n const granXCos = granularityX * cosRotation;\n\n const sinRotation = Math.sin(rotation);\n const granYSin = granularityY * sinRotation;\n const granXSin = granularityX * sinRotation;\n\n nwCartesian = proj.project(nwCorner, nwCartesian);\n\n nwCartesian = Cartesian3.subtract(nwCartesian, centerCartesian, nwCartesian);\n const rotationMatrix = Matrix2.fromRotation(rotation, rotationMatrixScratch);\n nwCartesian = Matrix2.multiplyByVector(\n rotationMatrix,\n nwCartesian,\n nwCartesian\n );\n nwCartesian = Cartesian3.add(nwCartesian, centerCartesian, nwCartesian);\n nwCorner = proj.unproject(nwCartesian, nwCorner);\n\n width -= 1;\n height -= 1;\n\n const latitude = nwCorner.latitude;\n const latitude0 = latitude + width * granXSin;\n const latitude1 = latitude - granYCos * height;\n const latitude2 = latitude - granYCos * height + width * granXSin;\n\n const north = Math.max(latitude, latitude0, latitude1, latitude2);\n const south = Math.min(latitude, latitude0, latitude1, latitude2);\n\n const longitude = nwCorner.longitude;\n const longitude0 = longitude + width * granXCos;\n const longitude1 = longitude + height * granYSin;\n const longitude2 = longitude + height * granYSin + width * granXCos;\n\n const east = Math.max(longitude, longitude0, longitude1, longitude2);\n const west = Math.min(longitude, longitude0, longitude1, longitude2);\n\n return {\n north: north,\n south: south,\n east: east,\n west: west,\n granYCos: granYCos,\n granYSin: granYSin,\n granXCos: granXCos,\n granXSin: granXSin,\n nwCorner: nwCorner,\n };\n}\n\n/**\n * @private\n */\nRectangleGeometryLibrary.computeOptions = function (\n rectangle,\n granularity,\n rotation,\n stRotation,\n boundingRectangleScratch,\n nwCornerResult,\n stNwCornerResult\n) {\n let east = rectangle.east;\n let west = rectangle.west;\n let north = rectangle.north;\n let south = rectangle.south;\n\n let northCap = false;\n let southCap = false;\n\n if (north === CesiumMath.PI_OVER_TWO) {\n northCap = true;\n }\n if (south === -CesiumMath.PI_OVER_TWO) {\n southCap = true;\n }\n\n let dx;\n const dy = north - south;\n if (west > east) {\n dx = CesiumMath.TWO_PI - west + east;\n } else {\n dx = east - west;\n }\n\n const width = Math.ceil(dx / granularity) + 1;\n const height = Math.ceil(dy / granularity) + 1;\n const granularityX = dx / (width - 1);\n const granularityY = dy / (height - 1);\n\n const nwCorner = Rectangle.northwest(rectangle, nwCornerResult);\n const center = Rectangle.center(rectangle, centerScratch);\n if (rotation !== 0 || stRotation !== 0) {\n if (center.longitude < nwCorner.longitude) {\n center.longitude += CesiumMath.TWO_PI;\n }\n centerCartesian = proj.project(center, centerCartesian);\n }\n\n const granYCos = granularityY;\n const granXCos = granularityX;\n const granYSin = 0.0;\n const granXSin = 0.0;\n\n const boundingRectangle = Rectangle.clone(\n rectangle,\n boundingRectangleScratch\n );\n\n const computedOptions = {\n granYCos: granYCos,\n granYSin: granYSin,\n granXCos: granXCos,\n granXSin: granXSin,\n nwCorner: nwCorner,\n boundingRectangle: boundingRectangle,\n width: width,\n height: height,\n northCap: northCap,\n southCap: southCap,\n };\n\n if (rotation !== 0) {\n const rotationOptions = getRotationOptions(\n nwCorner,\n rotation,\n granularityX,\n granularityY,\n center,\n width,\n height\n );\n north = rotationOptions.north;\n south = rotationOptions.south;\n east = rotationOptions.east;\n west = rotationOptions.west;\n\n //>>includeStart('debug', pragmas.debug);\n if (\n north < -CesiumMath.PI_OVER_TWO ||\n north > CesiumMath.PI_OVER_TWO ||\n south < -CesiumMath.PI_OVER_TWO ||\n south > CesiumMath.PI_OVER_TWO\n ) {\n throw new DeveloperError(\n \"Rotated rectangle is invalid. It crosses over either the north or south pole.\"\n );\n }\n //>>includeEnd('debug')\n\n computedOptions.granYCos = rotationOptions.granYCos;\n computedOptions.granYSin = rotationOptions.granYSin;\n computedOptions.granXCos = rotationOptions.granXCos;\n computedOptions.granXSin = rotationOptions.granXSin;\n\n boundingRectangle.north = north;\n boundingRectangle.south = south;\n boundingRectangle.east = east;\n boundingRectangle.west = west;\n }\n\n if (stRotation !== 0) {\n rotation = rotation - stRotation;\n const stNwCorner = Rectangle.northwest(boundingRectangle, stNwCornerResult);\n\n const stRotationOptions = getRotationOptions(\n stNwCorner,\n rotation,\n granularityX,\n granularityY,\n center,\n width,\n height\n );\n\n computedOptions.stGranYCos = stRotationOptions.granYCos;\n computedOptions.stGranXCos = stRotationOptions.granXCos;\n computedOptions.stGranYSin = stRotationOptions.granYSin;\n computedOptions.stGranXSin = stRotationOptions.granXSin;\n computedOptions.stNwCorner = stNwCorner;\n computedOptions.stWest = stRotationOptions.west;\n computedOptions.stSouth = stRotationOptions.south;\n }\n\n return computedOptions;\n};\nexport default RectangleGeometryLibrary;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport RectangleGeometryLibrary from \"./RectangleGeometryLibrary.js\";\n\nconst bottomBoundingSphere = new BoundingSphere();\nconst topBoundingSphere = new BoundingSphere();\nconst positionScratch = new Cartesian3();\nconst rectangleScratch = new Rectangle();\n\nfunction constructRectangle(geometry, computedOptions) {\n const ellipsoid = geometry._ellipsoid;\n const height = computedOptions.height;\n const width = computedOptions.width;\n const northCap = computedOptions.northCap;\n const southCap = computedOptions.southCap;\n\n let rowHeight = height;\n let widthMultiplier = 2;\n let size = 0;\n let corners = 4;\n if (northCap) {\n widthMultiplier -= 1;\n rowHeight -= 1;\n size += 1;\n corners -= 2;\n }\n if (southCap) {\n widthMultiplier -= 1;\n rowHeight -= 1;\n size += 1;\n corners -= 2;\n }\n size += widthMultiplier * width + 2 * rowHeight - corners;\n\n const positions = new Float64Array(size * 3);\n\n let posIndex = 0;\n let row = 0;\n let col;\n const position = positionScratch;\n if (northCap) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n row,\n 0,\n position\n );\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n } else {\n for (col = 0; col < width; col++) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n row,\n col,\n position\n );\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n }\n }\n\n col = width - 1;\n for (row = 1; row < height; row++) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n row,\n col,\n position\n );\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n }\n\n row = height - 1;\n if (!southCap) {\n // if southCap is true, we dont need to add any more points because the south pole point was added by the iteration above\n for (col = width - 2; col >= 0; col--) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n row,\n col,\n position\n );\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n }\n }\n\n col = 0;\n for (row = height - 2; row > 0; row--) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n row,\n col,\n position\n );\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n }\n\n const indicesSize = (positions.length / 3) * 2;\n const indices = IndexDatatype.createTypedArray(\n positions.length / 3,\n indicesSize\n );\n\n let index = 0;\n for (let i = 0; i < positions.length / 3 - 1; i++) {\n indices[index++] = i;\n indices[index++] = i + 1;\n }\n indices[index++] = positions.length / 3 - 1;\n indices[index++] = 0;\n\n const geo = new Geometry({\n attributes: new GeometryAttributes(),\n primitiveType: PrimitiveType.LINES,\n });\n\n geo.attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n geo.indices = indices;\n\n return geo;\n}\n\nfunction constructExtrudedRectangle(rectangleGeometry, computedOptions) {\n const surfaceHeight = rectangleGeometry._surfaceHeight;\n const extrudedHeight = rectangleGeometry._extrudedHeight;\n const ellipsoid = rectangleGeometry._ellipsoid;\n const minHeight = extrudedHeight;\n const maxHeight = surfaceHeight;\n const geo = constructRectangle(rectangleGeometry, computedOptions);\n\n const height = computedOptions.height;\n const width = computedOptions.width;\n\n const topPositions = PolygonPipeline.scaleToGeodeticHeight(\n geo.attributes.position.values,\n maxHeight,\n ellipsoid,\n false\n );\n let length = topPositions.length;\n const positions = new Float64Array(length * 2);\n positions.set(topPositions);\n const bottomPositions = PolygonPipeline.scaleToGeodeticHeight(\n geo.attributes.position.values,\n minHeight,\n ellipsoid\n );\n positions.set(bottomPositions, length);\n geo.attributes.position.values = positions;\n\n const northCap = computedOptions.northCap;\n const southCap = computedOptions.southCap;\n let corners = 4;\n if (northCap) {\n corners -= 1;\n }\n if (southCap) {\n corners -= 1;\n }\n\n const indicesSize = (positions.length / 3 + corners) * 2;\n const indices = IndexDatatype.createTypedArray(\n positions.length / 3,\n indicesSize\n );\n length = positions.length / 6;\n let index = 0;\n for (let i = 0; i < length - 1; i++) {\n indices[index++] = i;\n indices[index++] = i + 1;\n indices[index++] = i + length;\n indices[index++] = i + length + 1;\n }\n indices[index++] = length - 1;\n indices[index++] = 0;\n indices[index++] = length + length - 1;\n indices[index++] = length;\n\n indices[index++] = 0;\n indices[index++] = length;\n\n let bottomCorner;\n if (northCap) {\n bottomCorner = height - 1;\n } else {\n const topRightCorner = width - 1;\n indices[index++] = topRightCorner;\n indices[index++] = topRightCorner + length;\n bottomCorner = width + height - 2;\n }\n\n indices[index++] = bottomCorner;\n indices[index++] = bottomCorner + length;\n\n if (!southCap) {\n const bottomLeftCorner = width + bottomCorner - 1;\n indices[index++] = bottomLeftCorner;\n indices[index] = bottomLeftCorner + length;\n }\n\n geo.indices = indices;\n\n return geo;\n}\n\n/**\n * A description of the outline of a a cartographic rectangle on an ellipsoid centered at the origin.\n *\n * @alias RectangleOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Rectangle} options.rectangle A cartographic rectangle with north, south, east and west properties in radians.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle lies.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number} [options.height=0.0] The distance in meters between the rectangle and the ellipsoid surface.\n * @param {number} [options.rotation=0.0] The rotation of the rectangle, in radians. A positive rotation is counter-clockwise.\n * @param {number} [options.extrudedHeight] The distance in meters between the rectangle's extruded face and the ellipsoid surface.\n *\n * @exception {DeveloperError} options.rectangle.north must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} options.rectangle.south must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} options.rectangle.east must be in the interval [-Pi, Pi].\n * @exception {DeveloperError} options.rectangle.west must be in the interval [-Pi, Pi].\n * @exception {DeveloperError} options.rectangle.north must be greater than rectangle.south.\n *\n * @see RectangleOutlineGeometry#createGeometry\n *\n * @example\n * const rectangle = new Cesium.RectangleOutlineGeometry({\n * ellipsoid : Cesium.Ellipsoid.WGS84,\n * rectangle : Cesium.Rectangle.fromDegrees(-80.0, 39.0, -74.0, 42.0),\n * height : 10000.0\n * });\n * const geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle);\n */\nfunction RectangleOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const rectangle = options.rectangle;\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const rotation = defaultValue(options.rotation, 0.0);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(rectangle)) {\n throw new DeveloperError(\"rectangle is required.\");\n }\n Rectangle.validate(rectangle);\n if (rectangle.north < rectangle.south) {\n throw new DeveloperError(\n \"options.rectangle.north must be greater than options.rectangle.south\"\n );\n }\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._rectangle = Rectangle.clone(rectangle);\n this._granularity = granularity;\n this._ellipsoid = ellipsoid;\n this._surfaceHeight = Math.max(height, extrudedHeight);\n this._rotation = rotation;\n this._extrudedHeight = Math.min(height, extrudedHeight);\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createRectangleOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nRectangleOutlineGeometry.packedLength =\n Rectangle.packedLength + Ellipsoid.packedLength + 5;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {RectangleOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nRectangleOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Rectangle.pack(value._rectangle, array, startingIndex);\n startingIndex += Rectangle.packedLength;\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._surfaceHeight;\n array[startingIndex++] = value._rotation;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchRectangle = new Rectangle();\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchOptions = {\n rectangle: scratchRectangle,\n ellipsoid: scratchEllipsoid,\n granularity: undefined,\n height: undefined,\n rotation: undefined,\n extrudedHeight: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {RectangleOutlineGeometry} [result] The object into which to store the result.\n * @returns {RectangleOutlineGeometry} The modified result parameter or a new Quaternion instance if one was not provided.\n */\nRectangleOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);\n startingIndex += Rectangle.packedLength;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const granularity = array[startingIndex++];\n const height = array[startingIndex++];\n const rotation = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.granularity = granularity;\n scratchOptions.height = height;\n scratchOptions.rotation = rotation;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return new RectangleOutlineGeometry(scratchOptions);\n }\n\n result._rectangle = Rectangle.clone(rectangle, result._rectangle);\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._surfaceHeight = height;\n result._rotation = rotation;\n result._extrudedHeight = extrudedHeight;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\nconst nwScratch = new Cartographic();\n/**\n * Computes the geometric representation of an outline of a rectangle, including its vertices, indices, and a bounding sphere.\n *\n * @param {RectangleOutlineGeometry} rectangleGeometry A description of the rectangle outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n *\n * @exception {DeveloperError} Rotated rectangle is invalid.\n */\nRectangleOutlineGeometry.createGeometry = function (rectangleGeometry) {\n const rectangle = rectangleGeometry._rectangle;\n const ellipsoid = rectangleGeometry._ellipsoid;\n const computedOptions = RectangleGeometryLibrary.computeOptions(\n rectangle,\n rectangleGeometry._granularity,\n rectangleGeometry._rotation,\n 0,\n rectangleScratch,\n nwScratch\n );\n\n let geometry;\n let boundingSphere;\n\n if (\n CesiumMath.equalsEpsilon(\n rectangle.north,\n rectangle.south,\n CesiumMath.EPSILON10\n ) ||\n CesiumMath.equalsEpsilon(\n rectangle.east,\n rectangle.west,\n CesiumMath.EPSILON10\n )\n ) {\n return undefined;\n }\n\n const surfaceHeight = rectangleGeometry._surfaceHeight;\n const extrudedHeight = rectangleGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n surfaceHeight,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n let offsetValue;\n if (extrude) {\n geometry = constructExtrudedRectangle(rectangleGeometry, computedOptions);\n if (defined(rectangleGeometry._offsetAttribute)) {\n const size = geometry.attributes.position.values.length / 3;\n let offsetAttribute = new Uint8Array(size);\n if (rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.TOP) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else {\n offsetValue =\n rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n });\n }\n const topBS = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n surfaceHeight,\n topBoundingSphere\n );\n const bottomBS = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n extrudedHeight,\n bottomBoundingSphere\n );\n boundingSphere = BoundingSphere.union(topBS, bottomBS);\n } else {\n geometry = constructRectangle(rectangleGeometry, computedOptions);\n geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n geometry.attributes.position.values,\n surfaceHeight,\n ellipsoid,\n false\n );\n\n if (defined(rectangleGeometry._offsetAttribute)) {\n const length = geometry.attributes.position.values.length;\n offsetValue =\n rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n boundingSphere = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n surfaceHeight\n );\n }\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: boundingSphere,\n offsetAttribute: rectangleGeometry._offsetAttribute,\n });\n};\nexport default RectangleOutlineGeometry;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport IntersectionTests from \"../Core/IntersectionTests.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport Plane from \"../Core/Plane.js\";\nimport Ray from \"../Core/Ray.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport RectangleOutlineGeometry from \"../Core/RectangleOutlineGeometry.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport Primitive from \"./Primitive.js\";\nimport SceneMode from \"./SceneMode.js\";\n\n/**\n * A tile bounding volume specified as a longitude/latitude/height region.\n * @alias TileBoundingRegion\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Rectangle} options.rectangle The rectangle specifying the longitude and latitude range of the region.\n * @param {number} [options.minimumHeight=0.0] The minimum height of the region.\n * @param {number} [options.maximumHeight=0.0] The maximum height of the region.\n * @param {Ellipsoid} [options.ellipsoid=Cesium.Ellipsoid.WGS84] The ellipsoid.\n * @param {boolean} [options.computeBoundingVolumes=true] True to compute the {@link TileBoundingRegion#boundingVolume} and\n * {@link TileBoundingVolume#boundingSphere}. If false, these properties will be undefined.\n *\n * @private\n */\nfunction TileBoundingRegion(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.object(\"options.rectangle\", options.rectangle);\n //>>includeEnd('debug');\n\n this.rectangle = Rectangle.clone(options.rectangle);\n this.minimumHeight = defaultValue(options.minimumHeight, 0.0);\n this.maximumHeight = defaultValue(options.maximumHeight, 0.0);\n\n /**\n * The world coordinates of the southwest corner of the tile's rectangle.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.southwestCornerCartesian = new Cartesian3();\n\n /**\n * The world coordinates of the northeast corner of the tile's rectangle.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.northeastCornerCartesian = new Cartesian3();\n\n /**\n * A normal that, along with southwestCornerCartesian, defines a plane at the western edge of\n * the tile. Any position above (in the direction of the normal) this plane is outside the tile.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.westNormal = new Cartesian3();\n\n /**\n * A normal that, along with southwestCornerCartesian, defines a plane at the southern edge of\n * the tile. Any position above (in the direction of the normal) this plane is outside the tile.\n * Because points of constant latitude do not necessary lie in a plane, positions below this\n * plane are not necessarily inside the tile, but they are close.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.southNormal = new Cartesian3();\n\n /**\n * A normal that, along with northeastCornerCartesian, defines a plane at the eastern edge of\n * the tile. Any position above (in the direction of the normal) this plane is outside the tile.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.eastNormal = new Cartesian3();\n\n /**\n * A normal that, along with northeastCornerCartesian, defines a plane at the eastern edge of\n * the tile. Any position above (in the direction of the normal) this plane is outside the tile.\n * Because points of constant latitude do not necessary lie in a plane, positions below this\n * plane are not necessarily inside the tile, but they are close.\n *\n * @type {Cartesian3}\n * @default Cartesian3()\n */\n this.northNormal = new Cartesian3();\n\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n computeBox(this, options.rectangle, ellipsoid);\n\n this._orientedBoundingBox = undefined;\n this._boundingSphere = undefined;\n\n if (defaultValue(options.computeBoundingVolumes, true)) {\n this.computeBoundingVolumes(ellipsoid);\n }\n}\n\nObject.defineProperties(TileBoundingRegion.prototype, {\n /**\n * The underlying bounding volume\n *\n * @memberof TileBoundingRegion.prototype\n *\n * @type {object}\n * @readonly\n */\n boundingVolume: {\n get: function () {\n return this._orientedBoundingBox;\n },\n },\n /**\n * The underlying bounding sphere\n *\n * @memberof TileBoundingRegion.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n return this._boundingSphere;\n },\n },\n});\n\nTileBoundingRegion.prototype.computeBoundingVolumes = function (ellipsoid) {\n // An oriented bounding box that encloses this tile's region. This is used to calculate tile visibility.\n this._orientedBoundingBox = OrientedBoundingBox.fromRectangle(\n this.rectangle,\n this.minimumHeight,\n this.maximumHeight,\n ellipsoid\n );\n\n this._boundingSphere = BoundingSphere.fromOrientedBoundingBox(\n this._orientedBoundingBox\n );\n};\n\nconst cartesian3Scratch = new Cartesian3();\nconst cartesian3Scratch2 = new Cartesian3();\nconst cartesian3Scratch3 = new Cartesian3();\nconst westNormalScratch = new Cartesian3();\nconst eastWestNormalScratch = new Cartesian3();\nconst westernMidpointScratch = new Cartesian3();\nconst easternMidpointScratch = new Cartesian3();\nconst cartographicScratch = new Cartographic();\nconst planeScratch = new Plane(Cartesian3.UNIT_X, 0.0);\nconst rayScratch = new Ray();\n\nfunction computeBox(tileBB, rectangle, ellipsoid) {\n ellipsoid.cartographicToCartesian(\n Rectangle.southwest(rectangle),\n tileBB.southwestCornerCartesian\n );\n ellipsoid.cartographicToCartesian(\n Rectangle.northeast(rectangle),\n tileBB.northeastCornerCartesian\n );\n\n // The middle latitude on the western edge.\n cartographicScratch.longitude = rectangle.west;\n cartographicScratch.latitude = (rectangle.south + rectangle.north) * 0.5;\n cartographicScratch.height = 0.0;\n const westernMidpointCartesian = ellipsoid.cartographicToCartesian(\n cartographicScratch,\n westernMidpointScratch\n );\n\n // Compute the normal of the plane on the western edge of the tile.\n const westNormal = Cartesian3.cross(\n westernMidpointCartesian,\n Cartesian3.UNIT_Z,\n westNormalScratch\n );\n Cartesian3.normalize(westNormal, tileBB.westNormal);\n\n // The middle latitude on the eastern edge.\n cartographicScratch.longitude = rectangle.east;\n const easternMidpointCartesian = ellipsoid.cartographicToCartesian(\n cartographicScratch,\n easternMidpointScratch\n );\n\n // Compute the normal of the plane on the eastern edge of the tile.\n const eastNormal = Cartesian3.cross(\n Cartesian3.UNIT_Z,\n easternMidpointCartesian,\n cartesian3Scratch\n );\n Cartesian3.normalize(eastNormal, tileBB.eastNormal);\n\n let westVector = Cartesian3.subtract(\n westernMidpointCartesian,\n easternMidpointCartesian,\n cartesian3Scratch\n );\n\n if (Cartesian3.magnitude(westVector) === 0.0) {\n westVector = Cartesian3.clone(westNormal, westVector);\n }\n\n const eastWestNormal = Cartesian3.normalize(\n westVector,\n eastWestNormalScratch\n );\n\n // Compute the normal of the plane bounding the southern edge of the tile.\n const south = rectangle.south;\n let southSurfaceNormal;\n\n if (south > 0.0) {\n // Compute a plane that doesn't cut through the tile.\n cartographicScratch.longitude = (rectangle.west + rectangle.east) * 0.5;\n cartographicScratch.latitude = south;\n const southCenterCartesian = ellipsoid.cartographicToCartesian(\n cartographicScratch,\n rayScratch.origin\n );\n Cartesian3.clone(eastWestNormal, rayScratch.direction);\n const westPlane = Plane.fromPointNormal(\n tileBB.southwestCornerCartesian,\n tileBB.westNormal,\n planeScratch\n );\n // Find a point that is on the west and the south planes\n IntersectionTests.rayPlane(\n rayScratch,\n westPlane,\n tileBB.southwestCornerCartesian\n );\n southSurfaceNormal = ellipsoid.geodeticSurfaceNormal(\n southCenterCartesian,\n cartesian3Scratch2\n );\n } else {\n southSurfaceNormal = ellipsoid.geodeticSurfaceNormalCartographic(\n Rectangle.southeast(rectangle),\n cartesian3Scratch2\n );\n }\n const southNormal = Cartesian3.cross(\n southSurfaceNormal,\n westVector,\n cartesian3Scratch3\n );\n Cartesian3.normalize(southNormal, tileBB.southNormal);\n\n // Compute the normal of the plane bounding the northern edge of the tile.\n const north = rectangle.north;\n let northSurfaceNormal;\n\n if (north < 0.0) {\n // Compute a plane that doesn't cut through the tile.\n cartographicScratch.longitude = (rectangle.west + rectangle.east) * 0.5;\n cartographicScratch.latitude = north;\n const northCenterCartesian = ellipsoid.cartographicToCartesian(\n cartographicScratch,\n rayScratch.origin\n );\n Cartesian3.negate(eastWestNormal, rayScratch.direction);\n const eastPlane = Plane.fromPointNormal(\n tileBB.northeastCornerCartesian,\n tileBB.eastNormal,\n planeScratch\n );\n // Find a point that is on the east and the north planes\n IntersectionTests.rayPlane(\n rayScratch,\n eastPlane,\n tileBB.northeastCornerCartesian\n );\n northSurfaceNormal = ellipsoid.geodeticSurfaceNormal(\n northCenterCartesian,\n cartesian3Scratch2\n );\n } else {\n northSurfaceNormal = ellipsoid.geodeticSurfaceNormalCartographic(\n Rectangle.northwest(rectangle),\n cartesian3Scratch2\n );\n }\n const northNormal = Cartesian3.cross(\n westVector,\n northSurfaceNormal,\n cartesian3Scratch3\n );\n Cartesian3.normalize(northNormal, tileBB.northNormal);\n}\n\nconst southwestCornerScratch = new Cartesian3();\nconst northeastCornerScratch = new Cartesian3();\nconst negativeUnitY = new Cartesian3(0.0, -1.0, 0.0);\nconst negativeUnitZ = new Cartesian3(0.0, 0.0, -1.0);\nconst vectorScratch = new Cartesian3();\n\nfunction distanceToCameraRegion(tileBB, frameState) {\n const camera = frameState.camera;\n const cameraCartesianPosition = camera.positionWC;\n const cameraCartographicPosition = camera.positionCartographic;\n\n let result = 0.0;\n if (!Rectangle.contains(tileBB.rectangle, cameraCartographicPosition)) {\n let southwestCornerCartesian = tileBB.southwestCornerCartesian;\n let northeastCornerCartesian = tileBB.northeastCornerCartesian;\n let westNormal = tileBB.westNormal;\n let southNormal = tileBB.southNormal;\n let eastNormal = tileBB.eastNormal;\n let northNormal = tileBB.northNormal;\n\n if (frameState.mode !== SceneMode.SCENE3D) {\n southwestCornerCartesian = frameState.mapProjection.project(\n Rectangle.southwest(tileBB.rectangle),\n southwestCornerScratch\n );\n southwestCornerCartesian.z = southwestCornerCartesian.y;\n southwestCornerCartesian.y = southwestCornerCartesian.x;\n southwestCornerCartesian.x = 0.0;\n northeastCornerCartesian = frameState.mapProjection.project(\n Rectangle.northeast(tileBB.rectangle),\n northeastCornerScratch\n );\n northeastCornerCartesian.z = northeastCornerCartesian.y;\n northeastCornerCartesian.y = northeastCornerCartesian.x;\n northeastCornerCartesian.x = 0.0;\n westNormal = negativeUnitY;\n eastNormal = Cartesian3.UNIT_Y;\n southNormal = negativeUnitZ;\n northNormal = Cartesian3.UNIT_Z;\n }\n\n const vectorFromSouthwestCorner = Cartesian3.subtract(\n cameraCartesianPosition,\n southwestCornerCartesian,\n vectorScratch\n );\n const distanceToWestPlane = Cartesian3.dot(\n vectorFromSouthwestCorner,\n westNormal\n );\n const distanceToSouthPlane = Cartesian3.dot(\n vectorFromSouthwestCorner,\n southNormal\n );\n\n const vectorFromNortheastCorner = Cartesian3.subtract(\n cameraCartesianPosition,\n northeastCornerCartesian,\n vectorScratch\n );\n const distanceToEastPlane = Cartesian3.dot(\n vectorFromNortheastCorner,\n eastNormal\n );\n const distanceToNorthPlane = Cartesian3.dot(\n vectorFromNortheastCorner,\n northNormal\n );\n\n if (distanceToWestPlane > 0.0) {\n result += distanceToWestPlane * distanceToWestPlane;\n } else if (distanceToEastPlane > 0.0) {\n result += distanceToEastPlane * distanceToEastPlane;\n }\n\n if (distanceToSouthPlane > 0.0) {\n result += distanceToSouthPlane * distanceToSouthPlane;\n } else if (distanceToNorthPlane > 0.0) {\n result += distanceToNorthPlane * distanceToNorthPlane;\n }\n }\n\n let cameraHeight;\n let minimumHeight;\n let maximumHeight;\n if (frameState.mode === SceneMode.SCENE3D) {\n cameraHeight = cameraCartographicPosition.height;\n minimumHeight = tileBB.minimumHeight;\n maximumHeight = tileBB.maximumHeight;\n } else {\n cameraHeight = cameraCartesianPosition.x;\n minimumHeight = 0.0;\n maximumHeight = 0.0;\n }\n\n if (cameraHeight > maximumHeight) {\n const distanceAboveTop = cameraHeight - maximumHeight;\n result += distanceAboveTop * distanceAboveTop;\n } else if (cameraHeight < minimumHeight) {\n const distanceBelowBottom = minimumHeight - cameraHeight;\n result += distanceBelowBottom * distanceBelowBottom;\n }\n\n return Math.sqrt(result);\n}\n\n/**\n * Gets the distance from the camera to the closest point on the tile. This is used for level of detail selection.\n *\n * @param {FrameState} frameState The state information of the current rendering frame.\n * @returns {number} The distance from the camera to the closest point on the tile, in meters.\n */\nTileBoundingRegion.prototype.distanceToCamera = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n const regionResult = distanceToCameraRegion(this, frameState);\n if (\n frameState.mode === SceneMode.SCENE3D &&\n defined(this._orientedBoundingBox)\n ) {\n const obbResult = Math.sqrt(\n this._orientedBoundingBox.distanceSquaredTo(frameState.camera.positionWC)\n );\n return Math.max(regionResult, obbResult);\n }\n return regionResult;\n};\n\n/**\n * Determines which side of a plane this box is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nTileBoundingRegion.prototype.intersectPlane = function (plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"plane\", plane);\n //>>includeEnd('debug');\n return this._orientedBoundingBox.intersectPlane(plane);\n};\n\n/**\n * Creates a debug primitive that shows the outline of the tile bounding region.\n *\n * @param {Color} color The desired color of the primitive's mesh\n * @return {Primitive}\n *\n * @private\n */\nTileBoundingRegion.prototype.createDebugVolume = function (color) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"color\", color);\n //>>includeEnd('debug');\n\n const modelMatrix = new Matrix4.clone(Matrix4.IDENTITY);\n const geometry = new RectangleOutlineGeometry({\n rectangle: this.rectangle,\n height: this.minimumHeight,\n extrudedHeight: this.maximumHeight,\n });\n const instance = new GeometryInstance({\n geometry: geometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n\n return new Primitive({\n geometryInstances: instance,\n appearance: new PerInstanceColorAppearance({\n translucent: false,\n flat: true,\n }),\n asynchronous: false,\n });\n};\nexport default TileBoundingRegion;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport OrientedBoundingBox from \"./OrientedBoundingBox.js\";\n\n/**\n * @private\n */\nconst CoplanarPolygonGeometryLibrary = {};\n\nconst scratchIntersectionPoint = new Cartesian3();\nconst scratchXAxis = new Cartesian3();\nconst scratchYAxis = new Cartesian3();\nconst scratchZAxis = new Cartesian3();\nconst obbScratch = new OrientedBoundingBox();\n\nCoplanarPolygonGeometryLibrary.validOutline = function (positions) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n //>>includeEnd('debug');\n\n const orientedBoundingBox = OrientedBoundingBox.fromPoints(\n positions,\n obbScratch\n );\n const halfAxes = orientedBoundingBox.halfAxes;\n const xAxis = Matrix3.getColumn(halfAxes, 0, scratchXAxis);\n const yAxis = Matrix3.getColumn(halfAxes, 1, scratchYAxis);\n const zAxis = Matrix3.getColumn(halfAxes, 2, scratchZAxis);\n\n const xMag = Cartesian3.magnitude(xAxis);\n const yMag = Cartesian3.magnitude(yAxis);\n const zMag = Cartesian3.magnitude(zAxis);\n\n // If all the points are on a line return undefined because we can't draw a polygon\n return !(\n (xMag === 0 && (yMag === 0 || zMag === 0)) ||\n (yMag === 0 && zMag === 0)\n );\n};\n\n// call after removeDuplicates\nCoplanarPolygonGeometryLibrary.computeProjectTo2DArguments = function (\n positions,\n centerResult,\n planeAxis1Result,\n planeAxis2Result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n Check.defined(\"centerResult\", centerResult);\n Check.defined(\"planeAxis1Result\", planeAxis1Result);\n Check.defined(\"planeAxis2Result\", planeAxis2Result);\n //>>includeEnd('debug');\n\n const orientedBoundingBox = OrientedBoundingBox.fromPoints(\n positions,\n obbScratch\n );\n const halfAxes = orientedBoundingBox.halfAxes;\n const xAxis = Matrix3.getColumn(halfAxes, 0, scratchXAxis);\n const yAxis = Matrix3.getColumn(halfAxes, 1, scratchYAxis);\n const zAxis = Matrix3.getColumn(halfAxes, 2, scratchZAxis);\n\n const xMag = Cartesian3.magnitude(xAxis);\n const yMag = Cartesian3.magnitude(yAxis);\n const zMag = Cartesian3.magnitude(zAxis);\n const min = Math.min(xMag, yMag, zMag);\n\n // If all the points are on a line return undefined because we can't draw a polygon\n if (\n (xMag === 0 && (yMag === 0 || zMag === 0)) ||\n (yMag === 0 && zMag === 0)\n ) {\n return false;\n }\n\n let planeAxis1;\n let planeAxis2;\n\n if (min === yMag || min === zMag) {\n planeAxis1 = xAxis;\n }\n if (min === xMag) {\n planeAxis1 = yAxis;\n } else if (min === zMag) {\n planeAxis2 = yAxis;\n }\n if (min === xMag || min === yMag) {\n planeAxis2 = zAxis;\n }\n\n Cartesian3.normalize(planeAxis1, planeAxis1Result);\n Cartesian3.normalize(planeAxis2, planeAxis2Result);\n Cartesian3.clone(orientedBoundingBox.center, centerResult);\n return true;\n};\n\nfunction projectTo2D(position, center, axis1, axis2, result) {\n const v = Cartesian3.subtract(position, center, scratchIntersectionPoint);\n const x = Cartesian3.dot(axis1, v);\n const y = Cartesian3.dot(axis2, v);\n\n return Cartesian2.fromElements(x, y, result);\n}\n\nCoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction = function (\n center,\n axis1,\n axis2\n) {\n return function (positions) {\n const positionResults = new Array(positions.length);\n for (let i = 0; i < positions.length; i++) {\n positionResults[i] = projectTo2D(positions[i], center, axis1, axis2);\n }\n\n return positionResults;\n };\n};\n\nCoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction = function (\n center,\n axis1,\n axis2\n) {\n return function (position, result) {\n return projectTo2D(position, center, axis1, axis2, result);\n };\n};\nexport default CoplanarPolygonGeometryLibrary;\n", "/**\n * A queue that can enqueue items at the end, and dequeue items from the front.\n *\n * @alias Queue\n * @constructor\n */\nfunction Queue() {\n this._array = [];\n this._offset = 0;\n this._length = 0;\n}\n\nObject.defineProperties(Queue.prototype, {\n /**\n * The length of the queue.\n *\n * @memberof Queue.prototype\n *\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._length;\n },\n },\n});\n\n/**\n * Enqueues the specified item.\n *\n * @param {*} item The item to enqueue.\n */\nQueue.prototype.enqueue = function (item) {\n this._array.push(item);\n this._length++;\n};\n\n/**\n * Dequeues an item. Returns undefined if the queue is empty.\n *\n * @returns {*} The the dequeued item.\n */\nQueue.prototype.dequeue = function () {\n if (this._length === 0) {\n return undefined;\n }\n\n const array = this._array;\n let offset = this._offset;\n const item = array[offset];\n array[offset] = undefined;\n\n offset++;\n if (offset > 10 && offset * 2 > array.length) {\n //compact array\n this._array = array.slice(offset);\n offset = 0;\n }\n\n this._offset = offset;\n this._length--;\n\n return item;\n};\n\n/**\n * Returns the item at the front of the queue. Returns undefined if the queue is empty.\n *\n * @returns {*} The item at the front of the queue.\n */\nQueue.prototype.peek = function () {\n if (this._length === 0) {\n return undefined;\n }\n\n return this._array[this._offset];\n};\n\n/**\n * Check whether this queue contains the specified item.\n *\n * @param {*} item The item to search for.\n */\nQueue.prototype.contains = function (item) {\n return this._array.indexOf(item) !== -1;\n};\n\n/**\n * Remove all items from the queue.\n */\nQueue.prototype.clear = function () {\n this._array.length = this._offset = this._length = 0;\n};\n\n/**\n * Sort the items in the queue in-place.\n *\n * @param {Queue.Comparator} compareFunction A function that defines the sort order.\n */\nQueue.prototype.sort = function (compareFunction) {\n if (this._offset > 0) {\n //compact array\n this._array = this._array.slice(this._offset);\n this._offset = 0;\n }\n\n this._array.sort(compareFunction);\n};\n\n/**\n * A function used to compare two items while sorting a queue.\n * @callback Queue.Comparator\n *\n * @param {*} a An item in the array.\n * @param {*} b An item in the array.\n * @returns {number} Returns a negative value if a is less than b,\n * a positive value if a is greater than b, or\n * 0 if a is equal to b.\n *\n * @example\n * function compareNumbers(a, b) {\n * return a - b;\n * }\n */\nexport default Queue;\n", "import ArcType from \"./ArcType.js\";\nimport arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidRhumbLine from \"./EllipsoidRhumbLine.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Queue from \"./Queue.js\";\nimport WindingOrder from \"./WindingOrder.js\";\n\n/**\n * @private\n */\nconst PolygonGeometryLibrary = {};\n\nPolygonGeometryLibrary.computeHierarchyPackedLength = function (\n polygonHierarchy,\n CartesianX\n) {\n let numComponents = 0;\n const stack = [polygonHierarchy];\n while (stack.length > 0) {\n const hierarchy = stack.pop();\n if (!defined(hierarchy)) {\n continue;\n }\n\n numComponents += 2;\n\n const positions = hierarchy.positions;\n const holes = hierarchy.holes;\n\n if (defined(positions) && positions.length > 0) {\n numComponents += positions.length * CartesianX.packedLength;\n }\n\n if (defined(holes)) {\n const length = holes.length;\n for (let i = 0; i < length; ++i) {\n stack.push(holes[i]);\n }\n }\n }\n\n return numComponents;\n};\n\nPolygonGeometryLibrary.packPolygonHierarchy = function (\n polygonHierarchy,\n array,\n startingIndex,\n CartesianX\n) {\n const stack = [polygonHierarchy];\n while (stack.length > 0) {\n const hierarchy = stack.pop();\n if (!defined(hierarchy)) {\n continue;\n }\n\n const positions = hierarchy.positions;\n const holes = hierarchy.holes;\n\n array[startingIndex++] = defined(positions) ? positions.length : 0;\n array[startingIndex++] = defined(holes) ? holes.length : 0;\n\n if (defined(positions)) {\n const positionsLength = positions.length;\n for (\n let i = 0;\n i < positionsLength;\n ++i, startingIndex += CartesianX.packedLength\n ) {\n CartesianX.pack(positions[i], array, startingIndex);\n }\n }\n\n if (defined(holes)) {\n const holesLength = holes.length;\n for (let j = 0; j < holesLength; ++j) {\n stack.push(holes[j]);\n }\n }\n }\n\n return startingIndex;\n};\n\nPolygonGeometryLibrary.unpackPolygonHierarchy = function (\n array,\n startingIndex,\n CartesianX\n) {\n const positionsLength = array[startingIndex++];\n const holesLength = array[startingIndex++];\n\n const positions = new Array(positionsLength);\n const holes = holesLength > 0 ? new Array(holesLength) : undefined;\n\n for (\n let i = 0;\n i < positionsLength;\n ++i, startingIndex += CartesianX.packedLength\n ) {\n positions[i] = CartesianX.unpack(array, startingIndex);\n }\n\n for (let j = 0; j < holesLength; ++j) {\n holes[j] = PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n CartesianX\n );\n startingIndex = holes[j].startingIndex;\n delete holes[j].startingIndex;\n }\n\n return {\n positions: positions,\n holes: holes,\n startingIndex: startingIndex,\n };\n};\n\nconst distance2DScratch = new Cartesian2();\nfunction getPointAtDistance2D(p0, p1, distance, length) {\n Cartesian2.subtract(p1, p0, distance2DScratch);\n Cartesian2.multiplyByScalar(\n distance2DScratch,\n distance / length,\n distance2DScratch\n );\n Cartesian2.add(p0, distance2DScratch, distance2DScratch);\n return [distance2DScratch.x, distance2DScratch.y];\n}\n\nconst distanceScratch = new Cartesian3();\nfunction getPointAtDistance(p0, p1, distance, length) {\n Cartesian3.subtract(p1, p0, distanceScratch);\n Cartesian3.multiplyByScalar(\n distanceScratch,\n distance / length,\n distanceScratch\n );\n Cartesian3.add(p0, distanceScratch, distanceScratch);\n return [distanceScratch.x, distanceScratch.y, distanceScratch.z];\n}\n\nPolygonGeometryLibrary.subdivideLineCount = function (p0, p1, minDistance) {\n const distance = Cartesian3.distance(p0, p1);\n const n = distance / minDistance;\n const countDivide = Math.max(0, Math.ceil(CesiumMath.log2(n)));\n return Math.pow(2, countDivide);\n};\n\nconst scratchCartographic0 = new Cartographic();\nconst scratchCartographic1 = new Cartographic();\nconst scratchCartographic2 = new Cartographic();\nconst scratchCartesian0 = new Cartesian3();\nconst scratchRhumbLine = new EllipsoidRhumbLine();\nPolygonGeometryLibrary.subdivideRhumbLineCount = function (\n ellipsoid,\n p0,\n p1,\n minDistance\n) {\n const c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);\n const c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);\n const rhumb = new EllipsoidRhumbLine(c0, c1, ellipsoid);\n const n = rhumb.surfaceDistance / minDistance;\n const countDivide = Math.max(0, Math.ceil(CesiumMath.log2(n)));\n return Math.pow(2, countDivide);\n};\n\n/**\n * Subdivides texture coordinates based on the subdivision of the associated world positions.\n *\n * @param {Cartesian2} t0 First texture coordinate.\n * @param {Cartesian2} t1 Second texture coordinate.\n * @param {Cartesian3} p0 First world position.\n * @param {Cartesian3} p1 Second world position.\n * @param {number} minDistance Minimum distance for a segment.\n * @param {Cartesian2[]} result The subdivided texture coordinates.\n *\n * @private\n */\nPolygonGeometryLibrary.subdivideTexcoordLine = function (\n t0,\n t1,\n p0,\n p1,\n minDistance,\n result\n) {\n // Compute the number of subdivisions.\n const subdivisions = PolygonGeometryLibrary.subdivideLineCount(\n p0,\n p1,\n minDistance\n );\n\n // Compute the distance between each subdivided point.\n const length2D = Cartesian2.distance(t0, t1);\n const distanceBetweenCoords = length2D / subdivisions;\n\n // Resize the result array.\n const texcoords = result;\n texcoords.length = subdivisions * 2;\n\n // Compute texture coordinates using linear interpolation.\n let index = 0;\n for (let i = 0; i < subdivisions; i++) {\n const t = getPointAtDistance2D(t0, t1, i * distanceBetweenCoords, length2D);\n texcoords[index++] = t[0];\n texcoords[index++] = t[1];\n }\n\n return texcoords;\n};\n\nPolygonGeometryLibrary.subdivideLine = function (p0, p1, minDistance, result) {\n const numVertices = PolygonGeometryLibrary.subdivideLineCount(\n p0,\n p1,\n minDistance\n );\n const length = Cartesian3.distance(p0, p1);\n const distanceBetweenVertices = length / numVertices;\n\n if (!defined(result)) {\n result = [];\n }\n\n const positions = result;\n positions.length = numVertices * 3;\n\n let index = 0;\n for (let i = 0; i < numVertices; i++) {\n const p = getPointAtDistance(p0, p1, i * distanceBetweenVertices, length);\n positions[index++] = p[0];\n positions[index++] = p[1];\n positions[index++] = p[2];\n }\n\n return positions;\n};\n\n/**\n * Subdivides texture coordinates based on the subdivision of the associated world positions using a rhumb line.\n *\n * @param {Cartesian2} t0 First texture coordinate.\n * @param {Cartesian2} t1 Second texture coordinate.\n * @param {Ellipsoid} ellipsoid The ellipsoid.\n * @param {Cartesian3} p0 First world position.\n * @param {Cartesian3} p1 Second world position.\n * @param {number} minDistance Minimum distance for a segment.\n * @param {Cartesian2[]} result The subdivided texture coordinates.\n *\n * @private\n */\nPolygonGeometryLibrary.subdivideTexcoordRhumbLine = function (\n t0,\n t1,\n ellipsoid,\n p0,\n p1,\n minDistance,\n result\n) {\n // Compute the surface distance.\n const c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);\n const c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);\n scratchRhumbLine.setEndPoints(c0, c1);\n const n = scratchRhumbLine.surfaceDistance / minDistance;\n\n // Compute the number of subdivisions.\n const countDivide = Math.max(0, Math.ceil(CesiumMath.log2(n)));\n const subdivisions = Math.pow(2, countDivide);\n\n // Compute the distance between each subdivided point.\n const length2D = Cartesian2.distance(t0, t1);\n const distanceBetweenCoords = length2D / subdivisions;\n\n // Resize the result array.\n const texcoords = result;\n texcoords.length = subdivisions * 2;\n\n // Compute texture coordinates using linear interpolation.\n let index = 0;\n for (let i = 0; i < subdivisions; i++) {\n const t = getPointAtDistance2D(t0, t1, i * distanceBetweenCoords, length2D);\n texcoords[index++] = t[0];\n texcoords[index++] = t[1];\n }\n\n return texcoords;\n};\n\nPolygonGeometryLibrary.subdivideRhumbLine = function (\n ellipsoid,\n p0,\n p1,\n minDistance,\n result\n) {\n const c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);\n const c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);\n const rhumb = new EllipsoidRhumbLine(c0, c1, ellipsoid);\n\n const n = rhumb.surfaceDistance / minDistance;\n const countDivide = Math.max(0, Math.ceil(CesiumMath.log2(n)));\n const numVertices = Math.pow(2, countDivide);\n const distanceBetweenVertices = rhumb.surfaceDistance / numVertices;\n\n if (!defined(result)) {\n result = [];\n }\n\n const positions = result;\n positions.length = numVertices * 3;\n\n let index = 0;\n for (let i = 0; i < numVertices; i++) {\n const c = rhumb.interpolateUsingSurfaceDistance(\n i * distanceBetweenVertices,\n scratchCartographic2\n );\n const p = ellipsoid.cartographicToCartesian(c, scratchCartesian0);\n positions[index++] = p.x;\n positions[index++] = p.y;\n positions[index++] = p.z;\n }\n\n return positions;\n};\n\nconst scaleToGeodeticHeightN1 = new Cartesian3();\nconst scaleToGeodeticHeightN2 = new Cartesian3();\nconst scaleToGeodeticHeightP1 = new Cartesian3();\nconst scaleToGeodeticHeightP2 = new Cartesian3();\n\nPolygonGeometryLibrary.scaleToGeodeticHeightExtruded = function (\n geometry,\n maxHeight,\n minHeight,\n ellipsoid,\n perPositionHeight\n) {\n ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n const n1 = scaleToGeodeticHeightN1;\n let n2 = scaleToGeodeticHeightN2;\n const p = scaleToGeodeticHeightP1;\n let p2 = scaleToGeodeticHeightP2;\n\n if (\n defined(geometry) &&\n defined(geometry.attributes) &&\n defined(geometry.attributes.position)\n ) {\n const positions = geometry.attributes.position.values;\n const length = positions.length / 2;\n\n for (let i = 0; i < length; i += 3) {\n Cartesian3.fromArray(positions, i, p);\n\n ellipsoid.geodeticSurfaceNormal(p, n1);\n p2 = ellipsoid.scaleToGeodeticSurface(p, p2);\n n2 = Cartesian3.multiplyByScalar(n1, minHeight, n2);\n n2 = Cartesian3.add(p2, n2, n2);\n positions[i + length] = n2.x;\n positions[i + 1 + length] = n2.y;\n positions[i + 2 + length] = n2.z;\n\n if (perPositionHeight) {\n p2 = Cartesian3.clone(p, p2);\n }\n n2 = Cartesian3.multiplyByScalar(n1, maxHeight, n2);\n n2 = Cartesian3.add(p2, n2, n2);\n positions[i] = n2.x;\n positions[i + 1] = n2.y;\n positions[i + 2] = n2.z;\n }\n }\n return geometry;\n};\n\nPolygonGeometryLibrary.polygonOutlinesFromHierarchy = function (\n polygonHierarchy,\n scaleToEllipsoidSurface,\n ellipsoid\n) {\n // create from a polygon hierarchy\n // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf\n const polygons = [];\n const queue = new Queue();\n queue.enqueue(polygonHierarchy);\n let i;\n let j;\n let length;\n while (queue.length !== 0) {\n const outerNode = queue.dequeue();\n let outerRing = outerNode.positions;\n if (scaleToEllipsoidSurface) {\n length = outerRing.length;\n for (i = 0; i < length; i++) {\n ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);\n }\n }\n outerRing = arrayRemoveDuplicates(\n outerRing,\n Cartesian3.equalsEpsilon,\n true\n );\n if (outerRing.length < 3) {\n continue;\n }\n\n const numChildren = outerNode.holes ? outerNode.holes.length : 0;\n // The outer polygon contains inner polygons\n for (i = 0; i < numChildren; i++) {\n const hole = outerNode.holes[i];\n let holePositions = hole.positions;\n if (scaleToEllipsoidSurface) {\n length = holePositions.length;\n for (j = 0; j < length; ++j) {\n ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);\n }\n }\n holePositions = arrayRemoveDuplicates(\n holePositions,\n Cartesian3.equalsEpsilon,\n true\n );\n if (holePositions.length < 3) {\n continue;\n }\n polygons.push(holePositions);\n\n let numGrandchildren = 0;\n if (defined(hole.holes)) {\n numGrandchildren = hole.holes.length;\n }\n\n for (j = 0; j < numGrandchildren; j++) {\n queue.enqueue(hole.holes[j]);\n }\n }\n\n polygons.push(outerRing);\n }\n\n return polygons;\n};\n\nPolygonGeometryLibrary.polygonsFromHierarchy = function (\n polygonHierarchy,\n keepDuplicates,\n projectPointsTo2D,\n scaleToEllipsoidSurface,\n ellipsoid\n) {\n // create from a polygon hierarchy\n // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf\n const hierarchy = [];\n const polygons = [];\n\n const queue = new Queue();\n queue.enqueue(polygonHierarchy);\n\n while (queue.length !== 0) {\n const outerNode = queue.dequeue();\n let outerRing = outerNode.positions;\n const holes = outerNode.holes;\n\n let i;\n let length;\n if (scaleToEllipsoidSurface) {\n length = outerRing.length;\n for (i = 0; i < length; i++) {\n ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);\n }\n }\n\n if (!keepDuplicates) {\n outerRing = arrayRemoveDuplicates(\n outerRing,\n Cartesian3.equalsEpsilon,\n true\n );\n }\n if (outerRing.length < 3) {\n continue;\n }\n\n let positions2D = projectPointsTo2D(outerRing);\n if (!defined(positions2D)) {\n continue;\n }\n const holeIndices = [];\n\n let originalWindingOrder = PolygonPipeline.computeWindingOrder2D(\n positions2D\n );\n if (originalWindingOrder === WindingOrder.CLOCKWISE) {\n positions2D.reverse();\n outerRing = outerRing.slice().reverse();\n }\n\n let positions = outerRing.slice();\n const numChildren = defined(holes) ? holes.length : 0;\n const polygonHoles = [];\n let j;\n\n for (i = 0; i < numChildren; i++) {\n const hole = holes[i];\n let holePositions = hole.positions;\n if (scaleToEllipsoidSurface) {\n length = holePositions.length;\n for (j = 0; j < length; ++j) {\n ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);\n }\n }\n\n if (!keepDuplicates) {\n holePositions = arrayRemoveDuplicates(\n holePositions,\n Cartesian3.equalsEpsilon,\n true\n );\n }\n if (holePositions.length < 3) {\n continue;\n }\n\n const holePositions2D = projectPointsTo2D(holePositions);\n if (!defined(holePositions2D)) {\n continue;\n }\n\n originalWindingOrder = PolygonPipeline.computeWindingOrder2D(\n holePositions2D\n );\n if (originalWindingOrder === WindingOrder.CLOCKWISE) {\n holePositions2D.reverse();\n holePositions = holePositions.slice().reverse();\n }\n\n polygonHoles.push(holePositions);\n holeIndices.push(positions.length);\n positions = positions.concat(holePositions);\n positions2D = positions2D.concat(holePositions2D);\n\n let numGrandchildren = 0;\n if (defined(hole.holes)) {\n numGrandchildren = hole.holes.length;\n }\n\n for (j = 0; j < numGrandchildren; j++) {\n queue.enqueue(hole.holes[j]);\n }\n }\n\n hierarchy.push({\n outerRing: outerRing,\n holes: polygonHoles,\n });\n polygons.push({\n positions: positions,\n positions2D: positions2D,\n holes: holeIndices,\n });\n }\n\n return {\n hierarchy: hierarchy,\n polygons: polygons,\n };\n};\n\nconst computeBoundingRectangleCartesian2 = new Cartesian2();\nconst computeBoundingRectangleCartesian3 = new Cartesian3();\nconst computeBoundingRectangleQuaternion = new Quaternion();\nconst computeBoundingRectangleMatrix3 = new Matrix3();\nPolygonGeometryLibrary.computeBoundingRectangle = function (\n planeNormal,\n projectPointTo2D,\n positions,\n angle,\n result\n) {\n const rotation = Quaternion.fromAxisAngle(\n planeNormal,\n angle,\n computeBoundingRectangleQuaternion\n );\n const textureMatrix = Matrix3.fromQuaternion(\n rotation,\n computeBoundingRectangleMatrix3\n );\n\n let minX = Number.POSITIVE_INFINITY;\n let maxX = Number.NEGATIVE_INFINITY;\n let minY = Number.POSITIVE_INFINITY;\n let maxY = Number.NEGATIVE_INFINITY;\n\n const length = positions.length;\n for (let i = 0; i < length; ++i) {\n const p = Cartesian3.clone(\n positions[i],\n computeBoundingRectangleCartesian3\n );\n Matrix3.multiplyByVector(textureMatrix, p, p);\n const st = projectPointTo2D(p, computeBoundingRectangleCartesian2);\n\n if (defined(st)) {\n minX = Math.min(minX, st.x);\n maxX = Math.max(maxX, st.x);\n\n minY = Math.min(minY, st.y);\n maxY = Math.max(maxY, st.y);\n }\n }\n\n result.x = minX;\n result.y = minY;\n result.width = maxX - minX;\n result.height = maxY - minY;\n return result;\n};\n\nPolygonGeometryLibrary.createGeometryFromPositions = function (\n ellipsoid,\n polygon,\n textureCoordinates,\n granularity,\n perPositionHeight,\n vertexFormat,\n arcType\n) {\n let indices = PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);\n\n /* If polygon is completely unrenderable, just use the first three vertices */\n if (indices.length < 3) {\n indices = [0, 1, 2];\n }\n\n const positions = polygon.positions;\n\n const hasTexcoords = defined(textureCoordinates);\n const texcoords = hasTexcoords ? textureCoordinates.positions : undefined;\n\n if (perPositionHeight) {\n const length = positions.length;\n const flattenedPositions = new Array(length * 3);\n let index = 0;\n for (let i = 0; i < length; i++) {\n const p = positions[i];\n flattenedPositions[index++] = p.x;\n flattenedPositions[index++] = p.y;\n flattenedPositions[index++] = p.z;\n }\n\n const geometryOptions = {\n attributes: {\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: flattenedPositions,\n }),\n },\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n };\n\n if (hasTexcoords) {\n geometryOptions.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: Cartesian2.packArray(texcoords),\n });\n }\n\n const geometry = new Geometry(geometryOptions);\n\n if (vertexFormat.normal) {\n return GeometryPipeline.computeNormal(geometry);\n }\n\n return geometry;\n }\n\n if (arcType === ArcType.GEODESIC) {\n return PolygonPipeline.computeSubdivision(\n ellipsoid,\n positions,\n indices,\n texcoords,\n granularity\n );\n } else if (arcType === ArcType.RHUMB) {\n return PolygonPipeline.computeRhumbLineSubdivision(\n ellipsoid,\n positions,\n indices,\n texcoords,\n granularity\n );\n }\n};\n\nconst computeWallTexcoordsSubdivided = [];\nconst computeWallIndicesSubdivided = [];\nconst p1Scratch = new Cartesian3();\nconst p2Scratch = new Cartesian3();\n\nPolygonGeometryLibrary.computeWallGeometry = function (\n positions,\n textureCoordinates,\n ellipsoid,\n granularity,\n perPositionHeight,\n arcType\n) {\n let edgePositions;\n let topEdgeLength;\n let i;\n let p1;\n let p2;\n let t1;\n let t2;\n let edgeTexcoords;\n let topEdgeTexcoordLength;\n\n let length = positions.length;\n let index = 0;\n let textureIndex = 0;\n\n const hasTexcoords = defined(textureCoordinates);\n const texcoords = hasTexcoords ? textureCoordinates.positions : undefined;\n\n if (!perPositionHeight) {\n const minDistance = CesiumMath.chordLength(\n granularity,\n ellipsoid.maximumRadius\n );\n\n let numVertices = 0;\n if (arcType === ArcType.GEODESIC) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideLineCount(\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n } else if (arcType === ArcType.RHUMB) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(\n ellipsoid,\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n }\n\n topEdgeLength = (numVertices + length) * 3;\n edgePositions = new Array(topEdgeLength * 2);\n\n if (hasTexcoords) {\n topEdgeTexcoordLength = (numVertices + length) * 2;\n edgeTexcoords = new Array(topEdgeTexcoordLength * 2);\n }\n\n for (i = 0; i < length; i++) {\n p1 = positions[i];\n p2 = positions[(i + 1) % length];\n\n let tempPositions;\n let tempTexcoords;\n\n if (hasTexcoords) {\n t1 = texcoords[i];\n t2 = texcoords[(i + 1) % length];\n }\n\n if (arcType === ArcType.GEODESIC) {\n tempPositions = PolygonGeometryLibrary.subdivideLine(\n p1,\n p2,\n minDistance,\n computeWallIndicesSubdivided\n );\n if (hasTexcoords) {\n tempTexcoords = PolygonGeometryLibrary.subdivideTexcoordLine(\n t1,\n t2,\n p1,\n p2,\n minDistance,\n computeWallTexcoordsSubdivided\n );\n }\n } else if (arcType === ArcType.RHUMB) {\n tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(\n ellipsoid,\n p1,\n p2,\n minDistance,\n computeWallIndicesSubdivided\n );\n if (hasTexcoords) {\n tempTexcoords = PolygonGeometryLibrary.subdivideTexcoordRhumbLine(\n t1,\n t2,\n ellipsoid,\n p1,\n p2,\n minDistance,\n computeWallTexcoordsSubdivided\n );\n }\n }\n const tempPositionsLength = tempPositions.length;\n for (let j = 0; j < tempPositionsLength; ++j, ++index) {\n edgePositions[index] = tempPositions[j];\n edgePositions[index + topEdgeLength] = tempPositions[j];\n }\n\n edgePositions[index] = p2.x;\n edgePositions[index + topEdgeLength] = p2.x;\n ++index;\n\n edgePositions[index] = p2.y;\n edgePositions[index + topEdgeLength] = p2.y;\n ++index;\n\n edgePositions[index] = p2.z;\n edgePositions[index + topEdgeLength] = p2.z;\n ++index;\n\n if (hasTexcoords) {\n const tempTexcoordsLength = tempTexcoords.length;\n for (let k = 0; k < tempTexcoordsLength; ++k, ++textureIndex) {\n edgeTexcoords[textureIndex] = tempTexcoords[k];\n edgeTexcoords[textureIndex + topEdgeTexcoordLength] =\n tempTexcoords[k];\n }\n\n edgeTexcoords[textureIndex] = t2.x;\n edgeTexcoords[textureIndex + topEdgeTexcoordLength] = t2.x;\n ++textureIndex;\n\n edgeTexcoords[textureIndex] = t2.y;\n edgeTexcoords[textureIndex + topEdgeTexcoordLength] = t2.y;\n ++textureIndex;\n }\n }\n } else {\n topEdgeLength = length * 3 * 2;\n edgePositions = new Array(topEdgeLength * 2);\n\n if (hasTexcoords) {\n topEdgeTexcoordLength = length * 2 * 2;\n edgeTexcoords = new Array(topEdgeTexcoordLength * 2);\n }\n\n for (i = 0; i < length; i++) {\n p1 = positions[i];\n p2 = positions[(i + 1) % length];\n edgePositions[index] = edgePositions[index + topEdgeLength] = p1.x;\n ++index;\n edgePositions[index] = edgePositions[index + topEdgeLength] = p1.y;\n ++index;\n edgePositions[index] = edgePositions[index + topEdgeLength] = p1.z;\n ++index;\n edgePositions[index] = edgePositions[index + topEdgeLength] = p2.x;\n ++index;\n edgePositions[index] = edgePositions[index + topEdgeLength] = p2.y;\n ++index;\n edgePositions[index] = edgePositions[index + topEdgeLength] = p2.z;\n ++index;\n\n if (hasTexcoords) {\n t1 = texcoords[i];\n t2 = texcoords[(i + 1) % length];\n edgeTexcoords[textureIndex] = edgeTexcoords[\n textureIndex + topEdgeTexcoordLength\n ] = t1.x;\n ++textureIndex;\n edgeTexcoords[textureIndex] = edgeTexcoords[\n textureIndex + topEdgeTexcoordLength\n ] = t1.y;\n ++textureIndex;\n edgeTexcoords[textureIndex] = edgeTexcoords[\n textureIndex + topEdgeTexcoordLength\n ] = t2.x;\n ++textureIndex;\n edgeTexcoords[textureIndex] = edgeTexcoords[\n textureIndex + topEdgeTexcoordLength\n ] = t2.y;\n ++textureIndex;\n }\n }\n }\n\n length = edgePositions.length;\n const indices = IndexDatatype.createTypedArray(\n length / 3,\n length - positions.length * 6\n );\n let edgeIndex = 0;\n length /= 6;\n\n for (i = 0; i < length; i++) {\n const UL = i;\n const UR = UL + 1;\n const LL = UL + length;\n const LR = LL + 1;\n\n p1 = Cartesian3.fromArray(edgePositions, UL * 3, p1Scratch);\n p2 = Cartesian3.fromArray(edgePositions, UR * 3, p2Scratch);\n if (\n Cartesian3.equalsEpsilon(\n p1,\n p2,\n CesiumMath.EPSILON10,\n CesiumMath.EPSILON10\n )\n ) {\n //skip corner\n continue;\n }\n\n indices[edgeIndex++] = UL;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = UR;\n indices[edgeIndex++] = UR;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = LR;\n }\n\n const geometryOptions = {\n attributes: new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: edgePositions,\n }),\n }),\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n };\n\n if (hasTexcoords) {\n geometryOptions.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: edgeTexcoords,\n });\n }\n\n const geometry = new Geometry(geometryOptions);\n\n return geometry;\n};\nexport default PolygonGeometryLibrary;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CoplanarPolygonGeometryLibrary from \"./CoplanarPolygonGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport PolygonGeometryLibrary from \"./PolygonGeometryLibrary.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nfunction createGeometryFromPositions(positions) {\n const length = positions.length;\n const flatPositions = new Float64Array(length * 3);\n const indices = IndexDatatype.createTypedArray(length, length * 2);\n\n let positionIndex = 0;\n let index = 0;\n\n for (let i = 0; i < length; i++) {\n const position = positions[i];\n flatPositions[positionIndex++] = position.x;\n flatPositions[positionIndex++] = position.y;\n flatPositions[positionIndex++] = position.z;\n\n indices[index++] = i;\n indices[index++] = (i + 1) % length;\n }\n\n const attributes = new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: flatPositions,\n }),\n });\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n });\n}\n\n/**\n * A description of the outline of a polygon composed of arbitrary coplanar positions.\n *\n * @alias CoplanarPolygonOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.\n *\n * @see CoplanarPolygonOutlineGeometry.createGeometry\n *\n * @example\n * const polygonOutline = new Cesium.CoplanarPolygonOutlineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArrayHeights([\n * -90.0, 30.0, 0.0,\n * -90.0, 30.0, 1000.0,\n * -80.0, 30.0, 1000.0,\n * -80.0, 30.0, 0.0\n * ])\n * });\n * const geometry = Cesium.CoplanarPolygonOutlineGeometry.createGeometry(polygonOutline);\n */\nfunction CoplanarPolygonOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const polygonHierarchy = options.polygonHierarchy;\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.polygonHierarchy\", polygonHierarchy);\n //>>includeEnd('debug');\n\n this._polygonHierarchy = polygonHierarchy;\n this._workerName = \"createCoplanarPolygonOutlineGeometry\";\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n PolygonGeometryLibrary.computeHierarchyPackedLength(\n polygonHierarchy,\n Cartesian3\n ) + 1;\n}\n\n/**\n * A description of a coplanar polygon outline from an array of positions.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.\n * @returns {CoplanarPolygonOutlineGeometry}\n */\nCoplanarPolygonOutlineGeometry.fromPositions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", options.positions);\n //>>includeEnd('debug');\n\n const newOptions = {\n polygonHierarchy: {\n positions: options.positions,\n },\n };\n return new CoplanarPolygonOutlineGeometry(newOptions);\n};\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CoplanarPolygonOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCoplanarPolygonOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._polygonHierarchy,\n array,\n startingIndex,\n Cartesian3\n );\n\n array[startingIndex] = value.packedLength;\n\n return array;\n};\n\nconst scratchOptions = {\n polygonHierarchy: {},\n};\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CoplanarPolygonOutlineGeometry} [result] The object into which to store the result.\n * @returns {CoplanarPolygonOutlineGeometry} The modified result parameter or a new CoplanarPolygonOutlineGeometry instance if one was not provided.\n */\nCoplanarPolygonOutlineGeometry.unpack = function (\n array,\n startingIndex,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian3\n );\n startingIndex = polygonHierarchy.startingIndex;\n delete polygonHierarchy.startingIndex;\n const packedLength = array[startingIndex];\n\n if (!defined(result)) {\n result = new CoplanarPolygonOutlineGeometry(scratchOptions);\n }\n\n result._polygonHierarchy = polygonHierarchy;\n result.packedLength = packedLength;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.\n *\n * @param {CoplanarPolygonOutlineGeometry} polygonGeometry A description of the polygon.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCoplanarPolygonOutlineGeometry.createGeometry = function (polygonGeometry) {\n const polygonHierarchy = polygonGeometry._polygonHierarchy;\n\n let outerPositions = polygonHierarchy.positions;\n outerPositions = arrayRemoveDuplicates(\n outerPositions,\n Cartesian3.equalsEpsilon,\n true\n );\n if (outerPositions.length < 3) {\n return;\n }\n const isValid = CoplanarPolygonGeometryLibrary.validOutline(outerPositions);\n if (!isValid) {\n return undefined;\n }\n\n const polygons = PolygonGeometryLibrary.polygonOutlinesFromHierarchy(\n polygonHierarchy,\n false\n );\n\n if (polygons.length === 0) {\n return undefined;\n }\n\n const geometries = [];\n\n for (let i = 0; i < polygons.length; i++) {\n const geometryInstance = new GeometryInstance({\n geometry: createGeometryFromPositions(polygons[i]),\n });\n geometries.push(geometryInstance);\n }\n\n const geometry = GeometryPipeline.combineInstances(geometries)[0];\n const boundingSphere = BoundingSphere.fromPoints(polygonHierarchy.positions);\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: boundingSphere,\n });\n};\nexport default CoplanarPolygonOutlineGeometry;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defined from \"../Core/defined.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Plane from \"../Core/Plane.js\";\nimport CoplanarPolygonOutlineGeometry from \"../Core/CoplanarPolygonOutlineGeometry.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport Primitive from \"./Primitive.js\";\nimport S2Cell from \"../Core/S2Cell.js\";\nlet centerCartographicScratch = new Cartographic();\n/**\n * A tile bounding volume specified as an S2 cell token with minimum and maximum heights.\n * The bounding volume is a k DOP. A k-DOP is the Boolean intersection of extents along k directions.\n *\n * @alias TileBoundingS2Cell\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.token The token of the S2 cell.\n * @param {number} [options.minimumHeight=0.0] The minimum height of the bounding volume.\n * @param {number} [options.maximumHeight=0.0] The maximum height of the bounding volume.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid.\n * @param {boolean} [options.computeBoundingVolumes=true] True to compute the {@link TileBoundingS2Cell#boundingVolume} and\n * {@link TileBoundingS2Cell#boundingSphere}. If false, these properties will be undefined.\n *\n * @private\n */\nfunction TileBoundingS2Cell(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.string(\"options.token\", options.token);\n //>>includeEnd('debug');\n\n const s2Cell = S2Cell.fromToken(options.token);\n const minimumHeight = defaultValue(options.minimumHeight, 0.0);\n const maximumHeight = defaultValue(options.maximumHeight, 0.0);\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n this.s2Cell = s2Cell;\n this.minimumHeight = minimumHeight;\n this.maximumHeight = maximumHeight;\n this.ellipsoid = ellipsoid;\n\n const boundingPlanes = computeBoundingPlanes(\n s2Cell,\n minimumHeight,\n maximumHeight,\n ellipsoid\n );\n this._boundingPlanes = boundingPlanes;\n\n // Pre-compute vertices to speed up the plane intersection test.\n const vertices = computeVertices(boundingPlanes);\n this._vertices = vertices;\n\n // Pre-compute edge normals to speed up the point-polygon distance check in distanceToCamera.\n this._edgeNormals = new Array(6);\n\n this._edgeNormals[0] = computeEdgeNormals(\n boundingPlanes[0],\n vertices.slice(0, 4)\n );\n let i;\n // Based on the way the edge normals are computed, the edge normals all point away from the \"face\"\n // of the polyhedron they surround, except the plane for the top plane. Therefore, we negate the normals\n // for the top plane.\n for (i = 0; i < 4; i++) {\n this._edgeNormals[0][i] = Cartesian3.negate(\n this._edgeNormals[0][i],\n this._edgeNormals[0][i]\n );\n }\n\n this._edgeNormals[1] = computeEdgeNormals(\n boundingPlanes[1],\n vertices.slice(4, 8)\n );\n for (i = 0; i < 4; i++) {\n // For each plane, iterate through the vertices in CCW order.\n this._edgeNormals[2 + i] = computeEdgeNormals(boundingPlanes[2 + i], [\n vertices[i % 4],\n vertices[(i + 1) % 4],\n vertices[4 + ((i + 1) % 4)],\n vertices[4 + i],\n ]);\n }\n\n this._planeVertices = [\n this._vertices.slice(0, 4),\n this._vertices.slice(4, 8),\n ];\n for (i = 0; i < 4; i++) {\n this._planeVertices.push([\n this._vertices[i % 4],\n this._vertices[(i + 1) % 4],\n this._vertices[4 + ((i + 1) % 4)],\n this._vertices[4 + i],\n ]);\n }\n\n const center = s2Cell.getCenter();\n centerCartographicScratch = ellipsoid.cartesianToCartographic(\n center,\n centerCartographicScratch\n );\n centerCartographicScratch.height = (maximumHeight + minimumHeight) / 2;\n this.center = ellipsoid.cartographicToCartesian(\n centerCartographicScratch,\n center\n );\n\n this._boundingSphere = BoundingSphere.fromPoints(vertices);\n}\n\nconst centerGeodeticNormalScratch = new Cartesian3();\nconst topCartographicScratch = new Cartographic();\nconst topScratch = new Cartesian3();\nconst vertexCartographicScratch = new Cartographic();\nconst vertexScratch = new Cartesian3();\nconst vertexGeodeticNormalScratch = new Cartesian3();\nconst sideNormalScratch = new Cartesian3();\nconst sideScratch = new Cartesian3();\n/**\n * Computes bounding planes of the kDOP.\n * @private\n */\nfunction computeBoundingPlanes(\n s2Cell,\n minimumHeight,\n maximumHeight,\n ellipsoid\n) {\n const planes = new Array(6);\n const centerPoint = s2Cell.getCenter();\n\n // Compute top plane.\n // - Get geodetic surface normal at the center of the S2 cell.\n // - Get center point at maximum height of bounding volume.\n // - Create top plane from surface normal and top point.\n const centerSurfaceNormal = ellipsoid.geodeticSurfaceNormal(\n centerPoint,\n centerGeodeticNormalScratch\n );\n const topCartographic = ellipsoid.cartesianToCartographic(\n centerPoint,\n topCartographicScratch\n );\n topCartographic.height = maximumHeight;\n const top = ellipsoid.cartographicToCartesian(topCartographic, topScratch);\n const topPlane = Plane.fromPointNormal(top, centerSurfaceNormal);\n planes[0] = topPlane;\n\n // Compute bottom plane.\n // - Iterate through bottom vertices\n // - Get distance from vertex to top plane\n // - Find longest distance from vertex to top plane\n // - Translate top plane by the distance\n let maxDistance = 0;\n let i;\n const vertices = [];\n let vertex, vertexCartographic;\n for (i = 0; i < 4; i++) {\n vertex = s2Cell.getVertex(i);\n vertices[i] = vertex;\n vertexCartographic = ellipsoid.cartesianToCartographic(\n vertex,\n vertexCartographicScratch\n );\n vertexCartographic.height = minimumHeight;\n const distance = Plane.getPointDistance(\n topPlane,\n ellipsoid.cartographicToCartesian(vertexCartographic, vertexScratch)\n );\n if (distance < maxDistance) {\n maxDistance = distance;\n }\n }\n const bottomPlane = Plane.clone(topPlane);\n // Negate the normal of the bottom plane since we want all normals to point \"outwards\".\n bottomPlane.normal = Cartesian3.negate(\n bottomPlane.normal,\n bottomPlane.normal\n );\n bottomPlane.distance = bottomPlane.distance * -1 + maxDistance;\n planes[1] = bottomPlane;\n\n // Compute side planes.\n // - Iterate through vertices (in CCW order, by default)\n // - Get a vertex and another vertex adjacent to it.\n // - Compute geodetic surface normal at one vertex.\n // - Compute vector between vertices.\n // - Compute normal of side plane. (cross product of top dir and side dir)\n for (i = 0; i < 4; i++) {\n vertex = vertices[i];\n const adjacentVertex = vertices[(i + 1) % 4];\n const geodeticNormal = ellipsoid.geodeticSurfaceNormal(\n vertex,\n vertexGeodeticNormalScratch\n );\n const side = Cartesian3.subtract(adjacentVertex, vertex, sideScratch);\n let sideNormal = Cartesian3.cross(side, geodeticNormal, sideNormalScratch);\n sideNormal = Cartesian3.normalize(sideNormal, sideNormal);\n planes[2 + i] = Plane.fromPointNormal(vertex, sideNormal);\n }\n\n return planes;\n}\n\nlet n0Scratch = new Cartesian3();\nlet n1Scratch = new Cartesian3();\nlet n2Scratch = new Cartesian3();\nlet x0Scratch = new Cartesian3();\nlet x1Scratch = new Cartesian3();\nlet x2Scratch = new Cartesian3();\nconst t0Scratch = new Cartesian3();\nconst t1Scratch = new Cartesian3();\nconst t2Scratch = new Cartesian3();\nlet f0Scratch = new Cartesian3();\nlet f1Scratch = new Cartesian3();\nlet f2Scratch = new Cartesian3();\nlet sScratch = new Cartesian3();\nconst matrixScratch = new Matrix3();\n/**\n * Computes intersection of 3 planes.\n * @private\n */\nfunction computeIntersection(p0, p1, p2) {\n n0Scratch = p0.normal;\n n1Scratch = p1.normal;\n n2Scratch = p2.normal;\n\n x0Scratch = Cartesian3.multiplyByScalar(p0.normal, -p0.distance, x0Scratch);\n x1Scratch = Cartesian3.multiplyByScalar(p1.normal, -p1.distance, x1Scratch);\n x2Scratch = Cartesian3.multiplyByScalar(p2.normal, -p2.distance, x2Scratch);\n\n f0Scratch = Cartesian3.multiplyByScalar(\n Cartesian3.cross(n1Scratch, n2Scratch, t0Scratch),\n Cartesian3.dot(x0Scratch, n0Scratch),\n f0Scratch\n );\n f1Scratch = Cartesian3.multiplyByScalar(\n Cartesian3.cross(n2Scratch, n0Scratch, t1Scratch),\n Cartesian3.dot(x1Scratch, n1Scratch),\n f1Scratch\n );\n f2Scratch = Cartesian3.multiplyByScalar(\n Cartesian3.cross(n0Scratch, n1Scratch, t2Scratch),\n Cartesian3.dot(x2Scratch, n2Scratch),\n f2Scratch\n );\n\n matrixScratch[0] = n0Scratch.x;\n matrixScratch[1] = n1Scratch.x;\n matrixScratch[2] = n2Scratch.x;\n matrixScratch[3] = n0Scratch.y;\n matrixScratch[4] = n1Scratch.y;\n matrixScratch[5] = n2Scratch.y;\n matrixScratch[6] = n0Scratch.z;\n matrixScratch[7] = n1Scratch.z;\n matrixScratch[8] = n2Scratch.z;\n const determinant = Matrix3.determinant(matrixScratch);\n sScratch = Cartesian3.add(f0Scratch, f1Scratch, sScratch);\n sScratch = Cartesian3.add(sScratch, f2Scratch, sScratch);\n return new Cartesian3(\n sScratch.x / determinant,\n sScratch.y / determinant,\n sScratch.z / determinant\n );\n}\n/**\n * Compute the vertices of the kDOP.\n * @private\n */\nfunction computeVertices(boundingPlanes) {\n const vertices = new Array(8);\n for (let i = 0; i < 4; i++) {\n // Vertices on the top plane.\n vertices[i] = computeIntersection(\n boundingPlanes[0],\n boundingPlanes[2 + ((i + 3) % 4)],\n boundingPlanes[2 + (i % 4)]\n );\n // Vertices on the bottom plane.\n vertices[i + 4] = computeIntersection(\n boundingPlanes[1],\n boundingPlanes[2 + ((i + 3) % 4)],\n boundingPlanes[2 + (i % 4)]\n );\n }\n return vertices;\n}\n\nlet edgeScratch = new Cartesian3();\nlet edgeNormalScratch = new Cartesian3();\n/**\n * Compute edge normals on a plane.\n * @private\n */\nfunction computeEdgeNormals(plane, vertices) {\n const edgeNormals = [];\n for (let i = 0; i < 4; i++) {\n edgeScratch = Cartesian3.subtract(\n vertices[(i + 1) % 4],\n vertices[i],\n edgeScratch\n );\n edgeNormalScratch = Cartesian3.cross(\n plane.normal,\n edgeScratch,\n edgeNormalScratch\n );\n edgeNormalScratch = Cartesian3.normalize(\n edgeNormalScratch,\n edgeNormalScratch\n );\n edgeNormals[i] = Cartesian3.clone(edgeNormalScratch);\n }\n return edgeNormals;\n}\n\nObject.defineProperties(TileBoundingS2Cell.prototype, {\n /**\n * The underlying bounding volume.\n *\n * @memberof TileOrientedBoundingBox.prototype\n *\n * @type {object}\n * @readonly\n */\n boundingVolume: {\n get: function () {\n return this;\n },\n },\n /**\n * The underlying bounding sphere.\n *\n * @memberof TileOrientedBoundingBox.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n return this._boundingSphere;\n },\n },\n});\n\nconst facePointScratch = new Cartesian3();\n/**\n * The distance to point check for this kDOP involves checking the signed distance of the point to each bounding\n * plane. A plane qualifies for a distance check if the point being tested against is in the half-space in the direction\n * of the normal i.e. if the signed distance of the point from the plane is greater than 0.\n *\n * There are 4 possible cases for a point if it is outside the polyhedron:\n *\n * \\ X / X \\ / \\ / \\ /\n * ---\\---------/--- ---\\---------/--- ---X---------/--- ---\\---------/---\n * \\ / \\ / \\ / \\ /\n * ---\\-----/--- ---\\-----/--- ---\\-----/--- ---\\-----/---\n * \\ / \\ / \\ / \\ /\n * \\ /\n * \\\n * / \\\n * / X \\\n *\n * I II III IV\n *\n * Case I: There is only one plane selected.\n * In this case, we project the point onto the plane and do a point polygon distance check to find the closest point on the polygon.\n * The point may lie inside the \"face\" of the polygon or outside. If it is outside, we need to determine which edges to test against.\n *\n * Case II: There are two planes selected.\n * In this case, the point will lie somewhere on the line created at the intersection of the selected planes or one of the planes.\n *\n * Case III: There are three planes selected.\n * In this case, the point will lie on the vertex, at the intersection of the selected planes.\n *\n * Case IV: There are more than three planes selected.\n * Since we are on an ellipsoid, this will only happen in the bottom plane, which is what we will use for the distance test.\n */\nTileBoundingS2Cell.prototype.distanceToCamera = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"frameState\", frameState);\n //>>includeEnd('debug');\n\n const point = frameState.camera.positionWC;\n\n const selectedPlaneIndices = [];\n const vertices = [];\n let edgeNormals;\n\n if (Plane.getPointDistance(this._boundingPlanes[0], point) > 0) {\n selectedPlaneIndices.push(0);\n vertices.push(this._planeVertices[0]);\n edgeNormals = this._edgeNormals[0];\n } else if (Plane.getPointDistance(this._boundingPlanes[1], point) > 0) {\n selectedPlaneIndices.push(1);\n vertices.push(this._planeVertices[1]);\n edgeNormals = this._edgeNormals[1];\n }\n\n let i;\n let sidePlaneIndex;\n for (i = 0; i < 4; i++) {\n sidePlaneIndex = 2 + i;\n if (\n Plane.getPointDistance(this._boundingPlanes[sidePlaneIndex], point) > 0\n ) {\n selectedPlaneIndices.push(sidePlaneIndex);\n // Store vertices in CCW order.\n vertices.push(this._planeVertices[sidePlaneIndex]);\n edgeNormals = this._edgeNormals[sidePlaneIndex];\n }\n }\n\n // Check if inside all planes.\n if (selectedPlaneIndices.length === 0) {\n return 0.0;\n }\n\n // We use the skip variable when the side plane indices are non-consecutive.\n let facePoint;\n let selectedPlane;\n if (selectedPlaneIndices.length === 1) {\n // Handles Case I\n selectedPlane = this._boundingPlanes[selectedPlaneIndices[0]];\n facePoint = closestPointPolygon(\n Plane.projectPointOntoPlane(selectedPlane, point, facePointScratch),\n vertices[0],\n selectedPlane,\n edgeNormals\n );\n\n return Cartesian3.distance(facePoint, point);\n } else if (selectedPlaneIndices.length === 2) {\n // Handles Case II\n // Since we are on the ellipsoid, the dihedral angle between a top plane and a side plane\n // will always be acute, so we can do a faster check there.\n if (selectedPlaneIndices[0] === 0) {\n const edge = [\n this._vertices[\n 4 * selectedPlaneIndices[0] + (selectedPlaneIndices[1] - 2)\n ],\n this._vertices[\n 4 * selectedPlaneIndices[0] + ((selectedPlaneIndices[1] - 2 + 1) % 4)\n ],\n ];\n facePoint = closestPointLineSegment(point, edge[0], edge[1]);\n return Cartesian3.distance(facePoint, point);\n }\n let minimumDistance = Number.MAX_VALUE;\n let distance;\n for (i = 0; i < 2; i++) {\n selectedPlane = this._boundingPlanes[selectedPlaneIndices[i]];\n facePoint = closestPointPolygon(\n Plane.projectPointOntoPlane(selectedPlane, point, facePointScratch),\n vertices[i],\n selectedPlane,\n this._edgeNormals[selectedPlaneIndices[i]]\n );\n\n distance = Cartesian3.distanceSquared(facePoint, point);\n if (distance < minimumDistance) {\n minimumDistance = distance;\n }\n }\n return Math.sqrt(minimumDistance);\n } else if (selectedPlaneIndices.length > 3) {\n // Handles Case IV\n facePoint = closestPointPolygon(\n Plane.projectPointOntoPlane(\n this._boundingPlanes[1],\n point,\n facePointScratch\n ),\n this._planeVertices[1],\n this._boundingPlanes[1],\n this._edgeNormals[1]\n );\n return Cartesian3.distance(facePoint, point);\n }\n\n // Handles Case III\n const skip =\n selectedPlaneIndices[1] === 2 && selectedPlaneIndices[2] === 5 ? 0 : 1;\n\n // Vertex is on top plane.\n if (selectedPlaneIndices[0] === 0) {\n return Cartesian3.distance(\n point,\n this._vertices[(selectedPlaneIndices[1] - 2 + skip) % 4]\n );\n }\n\n // Vertex is on bottom plane.\n return Cartesian3.distance(\n point,\n this._vertices[4 + ((selectedPlaneIndices[1] - 2 + skip) % 4)]\n );\n};\n\nconst dScratch = new Cartesian3();\nconst pL0Scratch = new Cartesian3();\n/**\n * Finds point on a line segment closest to a given point.\n * @private\n */\nfunction closestPointLineSegment(p, l0, l1) {\n const d = Cartesian3.subtract(l1, l0, dScratch);\n const pL0 = Cartesian3.subtract(p, l0, pL0Scratch);\n let t = Cartesian3.dot(d, pL0);\n\n if (t <= 0) {\n return l0;\n }\n\n const dMag = Cartesian3.dot(d, d);\n if (t >= dMag) {\n return l1;\n }\n\n t = t / dMag;\n return new Cartesian3(\n (1 - t) * l0.x + t * l1.x,\n (1 - t) * l0.y + t * l1.y,\n (1 - t) * l0.z + t * l1.z\n );\n}\n\nconst edgePlaneScratch = new Plane(Cartesian3.UNIT_X, 0.0);\n/**\n * Finds closes point on the polygon, created by the given vertices, from\n * a point. The test point and the polygon are all on the same plane.\n * @private\n */\nfunction closestPointPolygon(p, vertices, plane, edgeNormals) {\n let minDistance = Number.MAX_VALUE;\n let distance;\n let closestPoint;\n let closestPointOnEdge;\n\n for (let i = 0; i < vertices.length; i++) {\n const edgePlane = Plane.fromPointNormal(\n vertices[i],\n edgeNormals[i],\n edgePlaneScratch\n );\n const edgePlaneDistance = Plane.getPointDistance(edgePlane, p);\n\n // Skip checking against the edge if the point is not in the half-space that the\n // edgePlane's normal points towards i.e. if the edgePlane is facing away from the point.\n if (edgePlaneDistance < 0) {\n continue;\n }\n\n closestPointOnEdge = closestPointLineSegment(\n p,\n vertices[i],\n vertices[(i + 1) % 4]\n );\n\n distance = Cartesian3.distance(p, closestPointOnEdge);\n if (distance < minDistance) {\n minDistance = distance;\n closestPoint = closestPointOnEdge;\n }\n }\n\n if (!defined(closestPoint)) {\n return p;\n }\n return closestPoint;\n}\n\n/**\n * Determines which side of a plane this volume is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire volume is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire volume is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the volume\n * intersects the plane.\n */\nTileBoundingS2Cell.prototype.intersectPlane = function (plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"plane\", plane);\n //>>includeEnd('debug');\n\n let plusCount = 0;\n let negCount = 0;\n for (let i = 0; i < this._vertices.length; i++) {\n const distanceToPlane =\n Cartesian3.dot(plane.normal, this._vertices[i]) + plane.distance;\n if (distanceToPlane < 0) {\n negCount++;\n } else {\n plusCount++;\n }\n }\n\n if (plusCount === this._vertices.length) {\n return Intersect.INSIDE;\n } else if (negCount === this._vertices.length) {\n return Intersect.OUTSIDE;\n }\n return Intersect.INTERSECTING;\n};\n\n/**\n * Creates a debug primitive that shows the outline of the tile bounding\n * volume.\n *\n * @param {Color} color The desired color of the primitive's mesh\n * @return {Primitive}\n */\nTileBoundingS2Cell.prototype.createDebugVolume = function (color) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"color\", color);\n //>>includeEnd('debug');\n\n const modelMatrix = new Matrix4.clone(Matrix4.IDENTITY);\n const topPlanePolygon = new CoplanarPolygonOutlineGeometry({\n polygonHierarchy: {\n positions: this._planeVertices[0],\n },\n });\n const topPlaneGeometry = CoplanarPolygonOutlineGeometry.createGeometry(\n topPlanePolygon\n );\n const topPlaneInstance = new GeometryInstance({\n geometry: topPlaneGeometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n\n const bottomPlanePolygon = new CoplanarPolygonOutlineGeometry({\n polygonHierarchy: {\n positions: this._planeVertices[1],\n },\n });\n const bottomPlaneGeometry = CoplanarPolygonOutlineGeometry.createGeometry(\n bottomPlanePolygon\n );\n const bottomPlaneInstance = new GeometryInstance({\n geometry: bottomPlaneGeometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n\n const sideInstances = [];\n for (let i = 0; i < 4; i++) {\n const sidePlanePolygon = new CoplanarPolygonOutlineGeometry({\n polygonHierarchy: {\n positions: this._planeVertices[2 + i],\n },\n });\n const sidePlaneGeometry = CoplanarPolygonOutlineGeometry.createGeometry(\n sidePlanePolygon\n );\n sideInstances[i] = new GeometryInstance({\n geometry: sidePlaneGeometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n }\n\n return new Primitive({\n geometryInstances: [\n sideInstances[0],\n sideInstances[1],\n sideInstances[2],\n sideInstances[3],\n bottomPlaneInstance,\n topPlaneInstance,\n ],\n appearance: new PerInstanceColorAppearance({\n translucent: false,\n flat: true,\n }),\n asynchronous: false,\n });\n};\n\nexport default TileBoundingS2Cell;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nconst defaultRadii = new Cartesian3(1.0, 1.0, 1.0);\nconst cos = Math.cos;\nconst sin = Math.sin;\n\n/**\n * A description of the outline of an ellipsoid centered at the origin.\n *\n * @alias EllipsoidOutlineGeometry\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Cartesian3} [options.radii=Cartesian3(1.0, 1.0, 1.0)] The radii of the ellipsoid in the x, y, and z directions.\n * @param {Cartesian3} [options.innerRadii=options.radii] The inner radii of the ellipsoid in the x, y, and z directions.\n * @param {number} [options.minimumClock=0.0] The minimum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.\n * @param {number} [options.maximumClock=2*PI] The maximum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.\n * @param {number} [options.minimumCone=0.0] The minimum angle measured from the positive z-axis and toward the negative z-axis.\n * @param {number} [options.maximumCone=PI] The maximum angle measured from the positive z-axis and toward the negative z-axis.\n * @param {number} [options.stackPartitions=10] The count of stacks for the ellipsoid (1 greater than the number of parallel lines).\n * @param {number} [options.slicePartitions=8] The count of slices for the ellipsoid (Equal to the number of radial lines).\n * @param {number} [options.subdivisions=128] The number of points per line, determining the granularity of the curvature.\n *\n * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.\n * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.\n * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.\n *\n * @example\n * const ellipsoid = new Cesium.EllipsoidOutlineGeometry({\n * radii : new Cesium.Cartesian3(1000000.0, 500000.0, 500000.0),\n * stackPartitions: 6,\n * slicePartitions: 5\n * });\n * const geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(ellipsoid);\n */\nfunction EllipsoidOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const radii = defaultValue(options.radii, defaultRadii);\n const innerRadii = defaultValue(options.innerRadii, radii);\n const minimumClock = defaultValue(options.minimumClock, 0.0);\n const maximumClock = defaultValue(options.maximumClock, CesiumMath.TWO_PI);\n const minimumCone = defaultValue(options.minimumCone, 0.0);\n const maximumCone = defaultValue(options.maximumCone, CesiumMath.PI);\n const stackPartitions = Math.round(defaultValue(options.stackPartitions, 10));\n const slicePartitions = Math.round(defaultValue(options.slicePartitions, 8));\n const subdivisions = Math.round(defaultValue(options.subdivisions, 128));\n\n //>>includeStart('debug', pragmas.debug);\n if (stackPartitions < 1) {\n throw new DeveloperError(\"options.stackPartitions cannot be less than 1\");\n }\n if (slicePartitions < 0) {\n throw new DeveloperError(\"options.slicePartitions cannot be less than 0\");\n }\n if (subdivisions < 0) {\n throw new DeveloperError(\n \"options.subdivisions must be greater than or equal to zero.\"\n );\n }\n if (\n defined(options.offsetAttribute) &&\n options.offsetAttribute === GeometryOffsetAttribute.TOP\n ) {\n throw new DeveloperError(\n \"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n this._radii = Cartesian3.clone(radii);\n this._innerRadii = Cartesian3.clone(innerRadii);\n this._minimumClock = minimumClock;\n this._maximumClock = maximumClock;\n this._minimumCone = minimumCone;\n this._maximumCone = maximumCone;\n this._stackPartitions = stackPartitions;\n this._slicePartitions = slicePartitions;\n this._subdivisions = subdivisions;\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createEllipsoidOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nEllipsoidOutlineGeometry.packedLength = 2 * Cartesian3.packedLength + 8;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {EllipsoidOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nEllipsoidOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._radii, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n Cartesian3.pack(value._innerRadii, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n array[startingIndex++] = value._minimumClock;\n array[startingIndex++] = value._maximumClock;\n array[startingIndex++] = value._minimumCone;\n array[startingIndex++] = value._maximumCone;\n array[startingIndex++] = value._stackPartitions;\n array[startingIndex++] = value._slicePartitions;\n array[startingIndex++] = value._subdivisions;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchRadii = new Cartesian3();\nconst scratchInnerRadii = new Cartesian3();\nconst scratchOptions = {\n radii: scratchRadii,\n innerRadii: scratchInnerRadii,\n minimumClock: undefined,\n maximumClock: undefined,\n minimumCone: undefined,\n maximumCone: undefined,\n stackPartitions: undefined,\n slicePartitions: undefined,\n subdivisions: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {EllipsoidOutlineGeometry} [result] The object into which to store the result.\n * @returns {EllipsoidOutlineGeometry} The modified result parameter or a new EllipsoidOutlineGeometry instance if one was not provided.\n */\nEllipsoidOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const radii = Cartesian3.unpack(array, startingIndex, scratchRadii);\n startingIndex += Cartesian3.packedLength;\n\n const innerRadii = Cartesian3.unpack(array, startingIndex, scratchInnerRadii);\n startingIndex += Cartesian3.packedLength;\n\n const minimumClock = array[startingIndex++];\n const maximumClock = array[startingIndex++];\n const minimumCone = array[startingIndex++];\n const maximumCone = array[startingIndex++];\n const stackPartitions = array[startingIndex++];\n const slicePartitions = array[startingIndex++];\n const subdivisions = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.minimumClock = minimumClock;\n scratchOptions.maximumClock = maximumClock;\n scratchOptions.minimumCone = minimumCone;\n scratchOptions.maximumCone = maximumCone;\n scratchOptions.stackPartitions = stackPartitions;\n scratchOptions.slicePartitions = slicePartitions;\n scratchOptions.subdivisions = subdivisions;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new EllipsoidOutlineGeometry(scratchOptions);\n }\n\n result._radii = Cartesian3.clone(radii, result._radii);\n result._innerRadii = Cartesian3.clone(innerRadii, result._innerRadii);\n result._minimumClock = minimumClock;\n result._maximumClock = maximumClock;\n result._minimumCone = minimumCone;\n result._maximumCone = maximumCone;\n result._stackPartitions = stackPartitions;\n result._slicePartitions = slicePartitions;\n result._subdivisions = subdivisions;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an outline of an ellipsoid, including its vertices, indices, and a bounding sphere.\n *\n * @param {EllipsoidOutlineGeometry} ellipsoidGeometry A description of the ellipsoid outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nEllipsoidOutlineGeometry.createGeometry = function (ellipsoidGeometry) {\n const radii = ellipsoidGeometry._radii;\n if (radii.x <= 0 || radii.y <= 0 || radii.z <= 0) {\n return;\n }\n\n const innerRadii = ellipsoidGeometry._innerRadii;\n if (innerRadii.x <= 0 || innerRadii.y <= 0 || innerRadii.z <= 0) {\n return;\n }\n\n const minimumClock = ellipsoidGeometry._minimumClock;\n const maximumClock = ellipsoidGeometry._maximumClock;\n const minimumCone = ellipsoidGeometry._minimumCone;\n const maximumCone = ellipsoidGeometry._maximumCone;\n const subdivisions = ellipsoidGeometry._subdivisions;\n const ellipsoid = Ellipsoid.fromCartesian3(radii);\n\n // Add an extra slice and stack to remain consistent with EllipsoidGeometry\n let slicePartitions = ellipsoidGeometry._slicePartitions + 1;\n let stackPartitions = ellipsoidGeometry._stackPartitions + 1;\n\n slicePartitions = Math.round(\n (slicePartitions * Math.abs(maximumClock - minimumClock)) /\n CesiumMath.TWO_PI\n );\n stackPartitions = Math.round(\n (stackPartitions * Math.abs(maximumCone - minimumCone)) / CesiumMath.PI\n );\n\n if (slicePartitions < 2) {\n slicePartitions = 2;\n }\n if (stackPartitions < 2) {\n stackPartitions = 2;\n }\n\n let extraIndices = 0;\n let vertexMultiplier = 1.0;\n const hasInnerSurface =\n innerRadii.x !== radii.x ||\n innerRadii.y !== radii.y ||\n innerRadii.z !== radii.z;\n let isTopOpen = false;\n let isBotOpen = false;\n if (hasInnerSurface) {\n vertexMultiplier = 2.0;\n // Add 2x slicePartitions to connect the top/bottom of the outer to\n // the top/bottom of the inner\n if (minimumCone > 0.0) {\n isTopOpen = true;\n extraIndices += slicePartitions;\n }\n if (maximumCone < Math.PI) {\n isBotOpen = true;\n extraIndices += slicePartitions;\n }\n }\n\n const vertexCount =\n subdivisions * vertexMultiplier * (stackPartitions + slicePartitions);\n const positions = new Float64Array(vertexCount * 3);\n\n // Multiply by two because two points define each line segment\n const numIndices =\n 2 *\n (vertexCount +\n extraIndices -\n (slicePartitions + stackPartitions) * vertexMultiplier);\n const indices = IndexDatatype.createTypedArray(vertexCount, numIndices);\n\n let i;\n let j;\n let theta;\n let phi;\n let index = 0;\n\n // Calculate sin/cos phi\n const sinPhi = new Array(stackPartitions);\n const cosPhi = new Array(stackPartitions);\n for (i = 0; i < stackPartitions; i++) {\n phi =\n minimumCone + (i * (maximumCone - minimumCone)) / (stackPartitions - 1);\n sinPhi[i] = sin(phi);\n cosPhi[i] = cos(phi);\n }\n\n // Calculate sin/cos theta\n const sinTheta = new Array(subdivisions);\n const cosTheta = new Array(subdivisions);\n for (i = 0; i < subdivisions; i++) {\n theta =\n minimumClock + (i * (maximumClock - minimumClock)) / (subdivisions - 1);\n sinTheta[i] = sin(theta);\n cosTheta[i] = cos(theta);\n }\n\n // Calculate the latitude lines on the outer surface\n for (i = 0; i < stackPartitions; i++) {\n for (j = 0; j < subdivisions; j++) {\n positions[index++] = radii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = radii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = radii.z * cosPhi[i];\n }\n }\n\n // Calculate the latitude lines on the inner surface\n if (hasInnerSurface) {\n for (i = 0; i < stackPartitions; i++) {\n for (j = 0; j < subdivisions; j++) {\n positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = innerRadii.z * cosPhi[i];\n }\n }\n }\n\n // Calculate sin/cos phi\n sinPhi.length = subdivisions;\n cosPhi.length = subdivisions;\n for (i = 0; i < subdivisions; i++) {\n phi = minimumCone + (i * (maximumCone - minimumCone)) / (subdivisions - 1);\n sinPhi[i] = sin(phi);\n cosPhi[i] = cos(phi);\n }\n\n // Calculate sin/cos theta for each slice partition\n sinTheta.length = slicePartitions;\n cosTheta.length = slicePartitions;\n for (i = 0; i < slicePartitions; i++) {\n theta =\n minimumClock +\n (i * (maximumClock - minimumClock)) / (slicePartitions - 1);\n sinTheta[i] = sin(theta);\n cosTheta[i] = cos(theta);\n }\n\n // Calculate the longitude lines on the outer surface\n for (i = 0; i < subdivisions; i++) {\n for (j = 0; j < slicePartitions; j++) {\n positions[index++] = radii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = radii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = radii.z * cosPhi[i];\n }\n }\n\n // Calculate the longitude lines on the inner surface\n if (hasInnerSurface) {\n for (i = 0; i < subdivisions; i++) {\n for (j = 0; j < slicePartitions; j++) {\n positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = innerRadii.z * cosPhi[i];\n }\n }\n }\n\n // Create indices for the latitude lines\n index = 0;\n for (i = 0; i < stackPartitions * vertexMultiplier; i++) {\n const topOffset = i * subdivisions;\n for (j = 0; j < subdivisions - 1; j++) {\n indices[index++] = topOffset + j;\n indices[index++] = topOffset + j + 1;\n }\n }\n\n // Create indices for the outer longitude lines\n let offset = stackPartitions * subdivisions * vertexMultiplier;\n for (i = 0; i < slicePartitions; i++) {\n for (j = 0; j < subdivisions - 1; j++) {\n indices[index++] = offset + i + j * slicePartitions;\n indices[index++] = offset + i + (j + 1) * slicePartitions;\n }\n }\n\n // Create indices for the inner longitude lines\n if (hasInnerSurface) {\n offset =\n stackPartitions * subdivisions * vertexMultiplier +\n slicePartitions * subdivisions;\n for (i = 0; i < slicePartitions; i++) {\n for (j = 0; j < subdivisions - 1; j++) {\n indices[index++] = offset + i + j * slicePartitions;\n indices[index++] = offset + i + (j + 1) * slicePartitions;\n }\n }\n }\n\n if (hasInnerSurface) {\n let outerOffset = stackPartitions * subdivisions * vertexMultiplier;\n let innerOffset = outerOffset + subdivisions * slicePartitions;\n if (isTopOpen) {\n // Draw lines from the top of the inner surface to the top of the outer surface\n for (i = 0; i < slicePartitions; i++) {\n indices[index++] = outerOffset + i;\n indices[index++] = innerOffset + i;\n }\n }\n\n if (isBotOpen) {\n // Draw lines from the top of the inner surface to the top of the outer surface\n outerOffset += subdivisions * slicePartitions - slicePartitions;\n innerOffset += subdivisions * slicePartitions - slicePartitions;\n for (i = 0; i < slicePartitions; i++) {\n indices[index++] = outerOffset + i;\n indices[index++] = innerOffset + i;\n }\n }\n }\n\n const attributes = new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n }),\n });\n\n if (defined(ellipsoidGeometry._offsetAttribute)) {\n const length = positions.length;\n const offsetValue =\n ellipsoidGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: BoundingSphere.fromEllipsoid(ellipsoid),\n offsetAttribute: ellipsoidGeometry._offsetAttribute,\n });\n};\nexport default EllipsoidOutlineGeometry;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport EllipsoidOutlineGeometry from \"./EllipsoidOutlineGeometry.js\";\n\n/**\n * A description of the outline of a sphere.\n *\n * @alias SphereOutlineGeometry\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {number} [options.radius=1.0] The radius of the sphere.\n * @param {number} [options.stackPartitions=10] The count of stacks for the sphere (1 greater than the number of parallel lines).\n * @param {number} [options.slicePartitions=8] The count of slices for the sphere (Equal to the number of radial lines).\n * @param {number} [options.subdivisions=200] The number of points per line, determining the granularity of the curvature .\n *\n * @exception {DeveloperError} options.stackPartitions must be greater than or equal to one.\n * @exception {DeveloperError} options.slicePartitions must be greater than or equal to zero.\n * @exception {DeveloperError} options.subdivisions must be greater than or equal to zero.\n *\n * @example\n * const sphere = new Cesium.SphereOutlineGeometry({\n * radius : 100.0,\n * stackPartitions : 6,\n * slicePartitions: 5\n * });\n * const geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere);\n */\nfunction SphereOutlineGeometry(options) {\n const radius = defaultValue(options.radius, 1.0);\n const radii = new Cartesian3(radius, radius, radius);\n const ellipsoidOptions = {\n radii: radii,\n stackPartitions: options.stackPartitions,\n slicePartitions: options.slicePartitions,\n subdivisions: options.subdivisions,\n };\n\n this._ellipsoidGeometry = new EllipsoidOutlineGeometry(ellipsoidOptions);\n this._workerName = \"createSphereOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nSphereOutlineGeometry.packedLength = EllipsoidOutlineGeometry.packedLength;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {SphereOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nSphereOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n //>>includeEnd('debug');\n\n return EllipsoidOutlineGeometry.pack(\n value._ellipsoidGeometry,\n array,\n startingIndex\n );\n};\n\nconst scratchEllipsoidGeometry = new EllipsoidOutlineGeometry();\nconst scratchOptions = {\n radius: undefined,\n radii: new Cartesian3(),\n stackPartitions: undefined,\n slicePartitions: undefined,\n subdivisions: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {SphereOutlineGeometry} [result] The object into which to store the result.\n * @returns {SphereOutlineGeometry} The modified result parameter or a new SphereOutlineGeometry instance if one was not provided.\n */\nSphereOutlineGeometry.unpack = function (array, startingIndex, result) {\n const ellipsoidGeometry = EllipsoidOutlineGeometry.unpack(\n array,\n startingIndex,\n scratchEllipsoidGeometry\n );\n scratchOptions.stackPartitions = ellipsoidGeometry._stackPartitions;\n scratchOptions.slicePartitions = ellipsoidGeometry._slicePartitions;\n scratchOptions.subdivisions = ellipsoidGeometry._subdivisions;\n\n if (!defined(result)) {\n scratchOptions.radius = ellipsoidGeometry._radii.x;\n return new SphereOutlineGeometry(scratchOptions);\n }\n\n Cartesian3.clone(ellipsoidGeometry._radii, scratchOptions.radii);\n result._ellipsoidGeometry = new EllipsoidOutlineGeometry(scratchOptions);\n return result;\n};\n\n/**\n * Computes the geometric representation of an outline of a sphere, including its vertices, indices, and a bounding sphere.\n *\n * @param {SphereOutlineGeometry} sphereGeometry A description of the sphere outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nSphereOutlineGeometry.createGeometry = function (sphereGeometry) {\n return EllipsoidOutlineGeometry.createGeometry(\n sphereGeometry._ellipsoidGeometry\n );\n};\nexport default SphereOutlineGeometry;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport SphereOutlineGeometry from \"../Core/SphereOutlineGeometry.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport Primitive from \"./Primitive.js\";\n\n/**\n * A tile bounding volume specified as a sphere.\n * @alias TileBoundingSphere\n * @constructor\n *\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.\n * @param {number} [radius=0.0] The radius of the bounding sphere.\n *\n * @private\n */\nfunction TileBoundingSphere(center, radius) {\n if (radius === 0) {\n radius = CesiumMath.EPSILON7;\n }\n this._boundingSphere = new BoundingSphere(center, radius);\n}\n\nObject.defineProperties(TileBoundingSphere.prototype, {\n /**\n * The center of the bounding sphere\n *\n * @memberof TileBoundingSphere.prototype\n *\n * @type {Cartesian3}\n * @readonly\n */\n center: {\n get: function () {\n return this._boundingSphere.center;\n },\n },\n\n /**\n * The radius of the bounding sphere\n *\n * @memberof TileBoundingSphere.prototype\n *\n * @type {number}\n * @readonly\n */\n radius: {\n get: function () {\n return this._boundingSphere.radius;\n },\n },\n\n /**\n * The underlying bounding volume\n *\n * @memberof TileBoundingSphere.prototype\n *\n * @type {object}\n * @readonly\n */\n boundingVolume: {\n get: function () {\n return this._boundingSphere;\n },\n },\n /**\n * The underlying bounding sphere\n *\n * @memberof TileBoundingSphere.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n return this._boundingSphere;\n },\n },\n});\n\n/**\n * Computes the distance between this bounding sphere and the camera attached to frameState.\n *\n * @param {FrameState} frameState The frameState to which the camera is attached.\n * @returns {number} The distance between the camera and the bounding sphere in meters. Returns 0 if the camera is inside the bounding volume.\n *\n */\nTileBoundingSphere.prototype.distanceToCamera = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"frameState\", frameState);\n //>>includeEnd('debug');\n const boundingSphere = this._boundingSphere;\n return Math.max(\n 0.0,\n Cartesian3.distance(boundingSphere.center, frameState.camera.positionWC) -\n boundingSphere.radius\n );\n};\n\n/**\n * Determines which side of a plane this sphere is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere\n * intersects the plane.\n */\nTileBoundingSphere.prototype.intersectPlane = function (plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"plane\", plane);\n //>>includeEnd('debug');\n return BoundingSphere.intersectPlane(this._boundingSphere, plane);\n};\n\n/**\n * Update the bounding sphere after the tile is transformed.\n *\n * @param {Cartesian3} center The center of the bounding sphere.\n * @param {number} radius The radius of the bounding sphere.\n */\nTileBoundingSphere.prototype.update = function (center, radius) {\n Cartesian3.clone(center, this._boundingSphere.center);\n this._boundingSphere.radius = radius;\n};\n\n/**\n * Creates a debug primitive that shows the outline of the sphere.\n *\n * @param {Color} color The desired color of the primitive's mesh\n * @return {Primitive}\n */\nTileBoundingSphere.prototype.createDebugVolume = function (color) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"color\", color);\n //>>includeEnd('debug');\n const geometry = new SphereOutlineGeometry({\n radius: this.radius,\n });\n const modelMatrix = Matrix4.fromTranslation(\n this.center,\n new Matrix4.clone(Matrix4.IDENTITY)\n );\n const instance = new GeometryInstance({\n geometry: geometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n\n return new Primitive({\n geometryInstances: instance,\n appearance: new PerInstanceColorAppearance({\n translucent: false,\n flat: true,\n }),\n asynchronous: false,\n });\n};\nexport default TileBoundingSphere;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport BoxOutlineGeometry from \"../Core/BoxOutlineGeometry.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport PerInstanceColorAppearance from \"./PerInstanceColorAppearance.js\";\nimport Primitive from \"./Primitive.js\";\n\nconst scratchU = new Cartesian3();\nconst scratchV = new Cartesian3();\nconst scratchW = new Cartesian3();\nconst scratchCartesian = new Cartesian3();\n\nfunction computeMissingVector(a, b, result) {\n result = Cartesian3.cross(a, b, result);\n const magnitude = Cartesian3.magnitude(result);\n return Cartesian3.multiplyByScalar(\n result,\n CesiumMath.EPSILON7 / magnitude,\n result\n );\n}\n\nfunction findOrthogonalVector(a, result) {\n const temp = Cartesian3.normalize(a, scratchCartesian);\n const b = Cartesian3.equalsEpsilon(\n temp,\n Cartesian3.UNIT_X,\n CesiumMath.EPSILON6\n )\n ? Cartesian3.UNIT_Y\n : Cartesian3.UNIT_X;\n return computeMissingVector(a, b, result);\n}\n\nfunction checkHalfAxes(halfAxes) {\n let u = Matrix3.getColumn(halfAxes, 0, scratchU);\n let v = Matrix3.getColumn(halfAxes, 1, scratchV);\n let w = Matrix3.getColumn(halfAxes, 2, scratchW);\n\n const uZero = Cartesian3.equals(u, Cartesian3.ZERO);\n const vZero = Cartesian3.equals(v, Cartesian3.ZERO);\n const wZero = Cartesian3.equals(w, Cartesian3.ZERO);\n\n if (!uZero && !vZero && !wZero) {\n return halfAxes;\n }\n if (uZero && vZero && wZero) {\n halfAxes[0] = CesiumMath.EPSILON7;\n halfAxes[4] = CesiumMath.EPSILON7;\n halfAxes[8] = CesiumMath.EPSILON7;\n return halfAxes;\n }\n if (uZero && !vZero && !wZero) {\n u = computeMissingVector(v, w, u);\n } else if (!uZero && vZero && !wZero) {\n v = computeMissingVector(u, w, v);\n } else if (!uZero && !vZero && wZero) {\n w = computeMissingVector(v, u, w);\n } else if (!uZero) {\n v = findOrthogonalVector(u, v);\n w = computeMissingVector(v, u, w);\n } else if (!vZero) {\n u = findOrthogonalVector(v, u);\n w = computeMissingVector(v, u, w);\n } else if (!wZero) {\n u = findOrthogonalVector(w, u);\n v = computeMissingVector(w, u, v);\n }\n\n Matrix3.setColumn(halfAxes, 0, u, halfAxes);\n Matrix3.setColumn(halfAxes, 1, v, halfAxes);\n Matrix3.setColumn(halfAxes, 2, w, halfAxes);\n\n return halfAxes;\n}\n\n/**\n * A tile bounding volume specified as an oriented bounding box.\n * @alias TileOrientedBoundingBox\n * @constructor\n *\n * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the box.\n * @param {Matrix3} [halfAxes=Matrix3.ZERO] The three orthogonal half-axes of the bounding box.\n * Equivalently, the transformation matrix, to rotate and scale a 2x2x2\n * cube centered at the origin.\n *\n * @private\n */\nfunction TileOrientedBoundingBox(center, halfAxes) {\n halfAxes = checkHalfAxes(halfAxes);\n this._orientedBoundingBox = new OrientedBoundingBox(center, halfAxes);\n this._boundingSphere = BoundingSphere.fromOrientedBoundingBox(\n this._orientedBoundingBox\n );\n}\n\nObject.defineProperties(TileOrientedBoundingBox.prototype, {\n /**\n * The underlying bounding volume.\n *\n * @memberof TileOrientedBoundingBox.prototype\n *\n * @type {object}\n * @readonly\n */\n boundingVolume: {\n get: function () {\n return this._orientedBoundingBox;\n },\n },\n /**\n * The underlying bounding sphere.\n *\n * @memberof TileOrientedBoundingBox.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n return this._boundingSphere;\n },\n },\n});\n\n/**\n * Computes the distance between this bounding box and the camera attached to frameState.\n *\n * @param {FrameState} frameState The frameState to which the camera is attached.\n * @returns {number} The distance between the camera and the bounding box in meters. Returns 0 if the camera is inside the bounding volume.\n */\nTileOrientedBoundingBox.prototype.distanceToCamera = function (frameState) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"frameState\", frameState);\n //>>includeEnd('debug');\n return Math.sqrt(\n this._orientedBoundingBox.distanceSquaredTo(frameState.camera.positionWC)\n );\n};\n\n/**\n * Determines which side of a plane this box is located.\n *\n * @param {Plane} plane The plane to test against.\n * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane\n * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is\n * on the opposite side, and {@link Intersect.INTERSECTING} if the box\n * intersects the plane.\n */\nTileOrientedBoundingBox.prototype.intersectPlane = function (plane) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"plane\", plane);\n //>>includeEnd('debug');\n return this._orientedBoundingBox.intersectPlane(plane);\n};\n\n/**\n * Update the bounding box after the tile is transformed.\n *\n * @param {Cartesian3} center The center of the box.\n * @param {Matrix3} halfAxes The three orthogonal half-axes of the bounding box.\n * Equivalently, the transformation matrix, to rotate and scale a 2x2x2\n * cube centered at the origin.\n */\nTileOrientedBoundingBox.prototype.update = function (center, halfAxes) {\n Cartesian3.clone(center, this._orientedBoundingBox.center);\n halfAxes = checkHalfAxes(halfAxes);\n Matrix3.clone(halfAxes, this._orientedBoundingBox.halfAxes);\n BoundingSphere.fromOrientedBoundingBox(\n this._orientedBoundingBox,\n this._boundingSphere\n );\n};\n\n/**\n * Creates a debug primitive that shows the outline of the box.\n *\n * @param {Color} color The desired color of the primitive's mesh\n * @return {Primitive}\n */\nTileOrientedBoundingBox.prototype.createDebugVolume = function (color) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"color\", color);\n //>>includeEnd('debug');\n\n const geometry = new BoxOutlineGeometry({\n // Make a 2x2x2 cube\n minimum: new Cartesian3(-1.0, -1.0, -1.0),\n maximum: new Cartesian3(1.0, 1.0, 1.0),\n });\n const modelMatrix = Matrix4.fromRotationTranslation(\n this.boundingVolume.halfAxes,\n this.boundingVolume.center\n );\n const instance = new GeometryInstance({\n geometry: geometry,\n id: \"outline\",\n modelMatrix: modelMatrix,\n attributes: {\n color: ColorGeometryInstanceAttribute.fromColor(color),\n },\n });\n\n return new Primitive({\n geometryInstances: instance,\n appearance: new PerInstanceColorAppearance({\n translucent: false,\n flat: true,\n }),\n asynchronous: false,\n });\n};\nexport default TileOrientedBoundingBox;\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport CullingVolume from \"../Core/CullingVolume.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OrientedBoundingBox from \"../Core/OrientedBoundingBox.js\";\nimport OrthographicFrustum from \"../Core/OrthographicFrustum.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport Request from \"../Core/Request.js\";\nimport RequestScheduler from \"../Core/RequestScheduler.js\";\nimport RequestState from \"../Core/RequestState.js\";\nimport RequestType from \"../Core/RequestType.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Cesium3DContentGroup from \"./Cesium3DContentGroup.js\";\nimport Cesium3DTileContentFactory from \"./Cesium3DTileContentFactory.js\";\nimport Cesium3DTileContentState from \"./Cesium3DTileContentState.js\";\nimport Cesium3DTileContentType from \"./Cesium3DTileContentType.js\";\nimport Cesium3DTileOptimizationHint from \"./Cesium3DTileOptimizationHint.js\";\nimport Cesium3DTilePass from \"./Cesium3DTilePass.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\nimport Empty3DTileContent from \"./Empty3DTileContent.js\";\nimport findContentMetadata from \"./findContentMetadata.js\";\nimport findGroupMetadata from \"./findGroupMetadata.js\";\nimport findTileMetadata from \"./findTileMetadata.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport Multiple3DTileContent from \"./Multiple3DTileContent.js\";\nimport BoundingVolumeSemantics from \"./BoundingVolumeSemantics.js\";\nimport preprocess3DTileContent from \"./preprocess3DTileContent.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport TileBoundingRegion from \"./TileBoundingRegion.js\";\nimport TileBoundingS2Cell from \"./TileBoundingS2Cell.js\";\nimport TileBoundingSphere from \"./TileBoundingSphere.js\";\nimport TileOrientedBoundingBox from \"./TileOrientedBoundingBox.js\";\nimport Pass from \"../Renderer/Pass.js\";\n\n/**\n * A tile in a {@link Cesium3DTileset}. When a tile is first created, its content is not loaded;\n * the content is loaded on-demand when needed based on the view.\n *

\n * Do not construct this directly, instead access tiles through {@link Cesium3DTileset#tileVisible}.\n *

\n *\n * @alias Cesium3DTile\n * @constructor\n * @param {Cesium3DTileset} tileset The tileset\n * @param {Resource} baseResource The base resource for the tileset\n * @param {object} header The JSON header for the tile\n * @param {Cesium3DTile} parent The parent tile of the new tile\n */\nfunction Cesium3DTile(tileset, baseResource, header, parent) {\n this._tileset = tileset;\n this._header = header;\n\n const hasContentsArray = defined(header.contents);\n const hasMultipleContents =\n (hasContentsArray && header.contents.length > 1) ||\n hasExtension(header, \"3DTILES_multiple_contents\");\n\n // In the 1.0 schema, content is stored in tile.content instead of tile.contents\n const contentHeader =\n hasContentsArray && !hasMultipleContents\n ? header.contents[0]\n : header.content;\n\n this._contentHeader = contentHeader;\n\n /**\n * The local transform of this tile.\n * @type {Matrix4}\n */\n this.transform = defined(header.transform)\n ? Matrix4.unpack(header.transform)\n : Matrix4.clone(Matrix4.IDENTITY);\n\n const parentTransform = defined(parent)\n ? parent.computedTransform\n : tileset.modelMatrix;\n const computedTransform = Matrix4.multiply(\n parentTransform,\n this.transform,\n new Matrix4()\n );\n\n const parentInitialTransform = defined(parent)\n ? parent._initialTransform\n : Matrix4.IDENTITY;\n this._initialTransform = Matrix4.multiply(\n parentInitialTransform,\n this.transform,\n new Matrix4()\n );\n\n /**\n * The final computed transform of this tile.\n * @type {Matrix4}\n * @readonly\n */\n this.computedTransform = computedTransform;\n\n /**\n * When tile metadata is present (3D Tiles 1.1) or the 3DTILES_metadata extension is used,\n * this stores a {@link TileMetadata} object for accessing tile metadata.\n *\n * @type {TileMetadata}\n * @readonly\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.metadata = findTileMetadata(tileset, header);\n\n // Important: tile metadata must be parsed before this line so that the\n // metadata semantics TILE_BOUNDING_BOX, TILE_BOUNDING_REGION, or TILE_BOUNDING_SPHERE\n // can override header.boundingVolume (if necessary)\n this._boundingVolume = this.createBoundingVolume(\n header.boundingVolume,\n computedTransform\n );\n this._boundingVolume2D = undefined;\n\n let contentBoundingVolume;\n\n if (defined(contentHeader) && defined(contentHeader.boundingVolume)) {\n // Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume\n // around only the features in the tile. This box is useful for culling for rendering,\n // but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e.,\n // since it only bounds features in the tile, not the entire tile, children may be\n // outside of this box.\n contentBoundingVolume = this.createBoundingVolume(\n contentHeader.boundingVolume,\n computedTransform\n );\n }\n this._contentBoundingVolume = contentBoundingVolume;\n this._contentBoundingVolume2D = undefined;\n\n let viewerRequestVolume;\n if (defined(header.viewerRequestVolume)) {\n viewerRequestVolume = this.createBoundingVolume(\n header.viewerRequestVolume,\n computedTransform\n );\n }\n this._viewerRequestVolume = viewerRequestVolume;\n\n /**\n * The error, in meters, introduced if this tile is rendered and its children are not.\n * This is used to compute screen space error, i.e., the error measured in pixels.\n *\n * @type {number}\n * @readonly\n */\n this.geometricError = header.geometricError;\n this._geometricError = header.geometricError;\n\n if (!defined(this._geometricError)) {\n this._geometricError = defined(parent)\n ? parent._geometricError\n : tileset._geometricError;\n Cesium3DTile._deprecationWarning(\n \"geometricErrorUndefined\",\n \"Required property geometricError is undefined for this tile. Using parent's geometric error instead.\"\n );\n }\n\n this.updateGeometricErrorScale();\n\n let refine;\n if (defined(header.refine)) {\n if (header.refine === \"replace\" || header.refine === \"add\") {\n Cesium3DTile._deprecationWarning(\n \"lowercase-refine\",\n `This tile uses a lowercase refine \"${\n header.refine\n }\". Instead use \"${header.refine.toUpperCase()}\".`\n );\n }\n refine =\n header.refine.toUpperCase() === \"REPLACE\"\n ? Cesium3DTileRefine.REPLACE\n : Cesium3DTileRefine.ADD;\n } else if (defined(parent)) {\n // Inherit from parent tile if omitted.\n refine = parent.refine;\n } else {\n refine = Cesium3DTileRefine.REPLACE;\n }\n\n /**\n * Specifies the type of refinement that is used when traversing this tile for rendering.\n *\n * @type {Cesium3DTileRefine}\n * @readonly\n * @private\n */\n this.refine = refine;\n\n /**\n * Gets the tile's children.\n *\n * @type {Cesium3DTile[]}\n * @readonly\n */\n this.children = [];\n\n /**\n * This tile's parent or undefined if this tile is the root.\n *

\n * When a tile's content points to an external tileset JSON file, the external tileset's\n * root tile's parent is not undefined; instead, the parent references\n * the tile (with its content pointing to an external tileset JSON file) as if the two tilesets were merged.\n *

\n *\n * @type {Cesium3DTile}\n * @readonly\n */\n this.parent = parent;\n\n let content;\n let hasEmptyContent = false;\n let contentState;\n let contentResource;\n let serverKey;\n\n baseResource = Resource.createIfNeeded(baseResource);\n\n if (hasMultipleContents) {\n contentState = Cesium3DTileContentState.UNLOADED;\n // Each content may have its own URI, but they all need to be resolved\n // relative to the tileset, so the base resource is used.\n contentResource = baseResource.clone();\n } else if (defined(contentHeader)) {\n let contentHeaderUri = contentHeader.uri;\n if (defined(contentHeader.url)) {\n Cesium3DTile._deprecationWarning(\n \"contentUrl\",\n 'This tileset JSON uses the \"content.url\" property which has been deprecated. Use \"content.uri\" instead.'\n );\n contentHeaderUri = contentHeader.url;\n }\n if (contentHeaderUri === \"\") {\n Cesium3DTile._deprecationWarning(\n \"contentUriEmpty\",\n \"content.uri property is an empty string, which creates a circular dependency, making this tileset invalid. Omit the content property instead\"\n );\n content = new Empty3DTileContent(tileset, this);\n hasEmptyContent = true;\n contentState = Cesium3DTileContentState.READY;\n } else {\n contentState = Cesium3DTileContentState.UNLOADED;\n contentResource = baseResource.getDerivedResource({\n url: contentHeaderUri,\n });\n serverKey = RequestScheduler.getServerKey(\n contentResource.getUrlComponent()\n );\n }\n } else {\n content = new Empty3DTileContent(tileset, this);\n hasEmptyContent = true;\n contentState = Cesium3DTileContentState.READY;\n }\n\n this._content = content;\n this._contentResource = contentResource;\n this._contentState = contentState;\n this._expiredContent = undefined;\n\n this._serverKey = serverKey;\n\n /**\n * When true, the tile has no content.\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasEmptyContent = hasEmptyContent;\n\n /**\n * When true, the tile's content points to an external tileset.\n *

\n * This is false until the tile's content is loaded.\n *

\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasTilesetContent = false;\n\n /**\n * When true, the tile's content is an implicit tileset.\n *

\n * This is false until the tile's implicit content is loaded.\n *

\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.hasImplicitContent = false;\n\n /**\n * When true, the tile contains content metadata from implicit tiling. This flag is set\n * for tiles transcoded by Implicit3DTileContent.\n *

\n * This is false until the tile's content is loaded.\n *

\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.hasImplicitContentMetadata = false;\n\n /**\n * When true, the tile has multiple contents, either in the tile JSON (3D Tiles 1.1)\n * or via the 3DTILES_multiple_contents extension.\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_multiple_contents|3DTILES_multiple_contents extension}\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n this.hasMultipleContents = hasMultipleContents;\n\n /**\n * The node in the tileset's LRU cache, used to determine when to unload a tile's content.\n *\n * See {@link Cesium3DTilesetCache}\n *\n * @type {DoublyLinkedListNode}\n * @readonly\n *\n * @private\n */\n this.cacheNode = undefined;\n\n const expire = header.expire;\n let expireDuration;\n let expireDate;\n if (defined(expire)) {\n expireDuration = expire.duration;\n if (defined(expire.date)) {\n expireDate = JulianDate.fromIso8601(expire.date);\n }\n }\n\n /**\n * The time in seconds after the tile's content is ready when the content expires and new content is requested.\n *\n * @type {number}\n */\n this.expireDuration = expireDuration;\n\n /**\n * The date when the content expires and new content is requested.\n *\n * @type {JulianDate}\n */\n this.expireDate = expireDate;\n\n /**\n * The time when a style was last applied to this tile.\n *\n * @type {number}\n *\n * @private\n */\n this.lastStyleTime = 0.0;\n\n /**\n * Marks whether the tile's children bounds are fully contained within the tile's bounds\n *\n * @type {Cesium3DTileOptimizationHint}\n *\n * @private\n */\n this._optimChildrenWithinParent = Cesium3DTileOptimizationHint.NOT_COMPUTED;\n\n /**\n * Tracks if the tile's relationship with a ClippingPlaneCollection has changed with regards\n * to the ClippingPlaneCollection's state.\n *\n * @type {boolean}\n *\n * @private\n */\n this.clippingPlanesDirty = false;\n\n /**\n * Tracks if the tile's request should be deferred until all non-deferred\n * tiles load.\n *\n * @type {boolean}\n *\n * @private\n */\n this.priorityDeferred = false;\n\n /**\n * For implicit tiling, an ImplicitTileset object will be attached to a\n * placeholder tile with either implicit tiling in the JSON (3D Tiles 1.1)\n * or the 3DTILES_implicit_tiling extension.\n * This way the {@link Implicit3DTileContent} can access the tile later once the content is fetched.\n *\n * @type {ImplicitTileset|undefined}\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.implicitTileset = undefined;\n\n /**\n * For implicit tiling, the (level, x, y, [z]) coordinates within the\n * implicit tileset are stored in the tile.\n *\n * @type {ImplicitTileCoordinates|undefined}\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.implicitCoordinates = undefined;\n\n /**\n * For implicit tiling, each transcoded tile will hold a weak reference to\n * the {@link ImplicitSubtree}.\n *\n * @type {ImplicitSubtree|undefined}\n *\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n this.implicitSubtree = undefined;\n\n // Members that are updated every frame for tree traversal and rendering optimizations:\n this._distanceToCamera = 0.0;\n this._centerZDepth = 0.0;\n this._screenSpaceError = 0.0;\n this._screenSpaceErrorProgressiveResolution = 0.0; // The screen space error at a given screen height of tileset.progressiveResolutionHeightFraction * screenHeight\n this._visibilityPlaneMask = 0;\n this._visible = false;\n this._inRequestVolume = false;\n\n this._finalResolution = true;\n this._depth = 0;\n this._stackLength = 0;\n this._selectionDepth = 0;\n\n this._updatedVisibilityFrame = 0;\n this._touchedFrame = 0;\n this._visitedFrame = 0;\n this._selectedFrame = 0;\n this._requestedFrame = 0;\n this._ancestorWithContent = undefined;\n this._ancestorWithContentAvailable = undefined;\n this._refines = false;\n this._shouldSelect = false;\n this._isClipped = true;\n this._clippingPlanesState = 0; // encapsulates (_isClipped, clippingPlanes.enabled) and number/function\n this._debugBoundingVolume = undefined;\n this._debugContentBoundingVolume = undefined;\n this._debugViewerRequestVolume = undefined;\n this._debugColor = Color.fromRandom({ alpha: 1.0 });\n this._debugColorizeTiles = false;\n\n this._priority = 0.0; // The priority used for request sorting\n this._priorityHolder = this; // Reference to the ancestor up the tree that holds the _foveatedFactor and _distanceToCamera for all tiles in the refinement chain.\n this._priorityProgressiveResolution = false;\n this._priorityProgressiveResolutionScreenSpaceErrorLeaf = false;\n this._priorityReverseScreenSpaceError = 0.0;\n this._foveatedFactor = 0.0;\n this._wasMinPriorityChild = false; // Needed for knowing when to continue a refinement chain. Gets reset in updateTile in traversal and gets set in updateAndPushChildren in traversal.\n\n this._loadTimestamp = new JulianDate();\n\n this._commandsLength = 0;\n\n this._color = undefined;\n this._colorDirty = false;\n\n this._request = undefined;\n}\n\n// This can be overridden for testing purposes\nCesium3DTile._deprecationWarning = deprecationWarning;\n\nObject.defineProperties(Cesium3DTile.prototype, {\n /**\n * The tileset containing this tile.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {Cesium3DTileset}\n * @readonly\n */\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n /**\n * The tile's content. This represents the actual tile's payload,\n * not the content's metadata in the tileset JSON file.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {Cesium3DTileContent}\n * @readonly\n */\n content: {\n get: function () {\n return this._content;\n },\n },\n\n /**\n * Get the tile's bounding volume.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {TileBoundingVolume}\n * @readonly\n * @private\n */\n boundingVolume: {\n get: function () {\n return this._boundingVolume;\n },\n },\n\n /**\n * Get the bounding volume of the tile's contents. This defaults to the\n * tile's bounding volume when the content's bounding volume is\n * undefined.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {TileBoundingVolume}\n * @readonly\n * @private\n */\n contentBoundingVolume: {\n get: function () {\n return defaultValue(this._contentBoundingVolume, this._boundingVolume);\n },\n },\n\n /**\n * Get the bounding sphere derived from the tile's bounding volume.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n */\n boundingSphere: {\n get: function () {\n return this._boundingVolume.boundingSphere;\n },\n },\n\n /**\n * Determines if the tile is visible within the current field of view\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n isVisible: {\n get: function () {\n return this._visible && this._inRequestVolume;\n },\n },\n\n /**\n * Returns the extras property in the tileset JSON for this tile, which contains application specific metadata.\n * Returns undefined if extras does not exist.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {object}\n * @readonly\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}\n */\n extras: {\n get: function () {\n return this._header.extras;\n },\n },\n\n /**\n * Gets or sets the tile's highlight color.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {Color}\n *\n * @default {@link Color.WHITE}\n *\n * @private\n */\n color: {\n get: function () {\n if (!defined(this._color)) {\n this._color = new Color();\n }\n return Color.clone(this._color);\n },\n set: function (value) {\n this._color = Color.clone(value, this._color);\n this._colorDirty = true;\n },\n },\n\n /**\n * Determines if the tile's content is renderable. false if the\n * tile has empty content or if it points to an external tileset or implicit content\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n hasRenderableContent: {\n get: function () {\n return (\n !this.hasEmptyContent &&\n !this.hasTilesetContent &&\n !this.hasImplicitContent\n );\n },\n },\n\n /**\n * Determines if the tile has available content to render. true if the tile's\n * content is ready or if it has expired content that renders while new content loads; otherwise,\n * false.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n contentAvailable: {\n get: function () {\n return (\n (this.contentReady && this.hasRenderableContent) ||\n (defined(this._expiredContent) && !this.contentFailed)\n );\n },\n },\n\n /**\n * Determines if the tile's content is ready. This is automatically true for\n * tile's with empty content.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n contentReady: {\n get: function () {\n return this._contentState === Cesium3DTileContentState.READY;\n },\n },\n\n /**\n * Determines if the tile's content has not be requested. true if tile's\n * content has not be requested; otherwise, false.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n contentUnloaded: {\n get: function () {\n return this._contentState === Cesium3DTileContentState.UNLOADED;\n },\n },\n\n /**\n * Determines if the tile has renderable content which is unloaded\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n hasUnloadedRenderableContent: {\n get: function () {\n return this.hasRenderableContent && this.contentUnloaded;\n },\n },\n\n /**\n * Determines if the tile's content is expired. true if tile's\n * content is expired; otherwise, false.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n contentExpired: {\n get: function () {\n return this._contentState === Cesium3DTileContentState.EXPIRED;\n },\n },\n\n /**\n * Determines if the tile's content failed to load. true if the tile's\n * content failed to load; otherwise, false.\n *\n * @memberof Cesium3DTile.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @private\n */\n contentFailed: {\n get: function () {\n return this._contentState === Cesium3DTileContentState.FAILED;\n },\n },\n\n /**\n * Returns the number of draw commands used by this tile.\n *\n * @readonly\n *\n * @private\n */\n commandsLength: {\n get: function () {\n return this._commandsLength;\n },\n },\n});\n\nconst scratchCartesian = new Cartesian3();\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {Boolean}\n */\nfunction isPriorityDeferred(tile, frameState) {\n const { tileset, boundingSphere } = tile;\n const { radius, center } = boundingSphere;\n const { camera } = frameState;\n\n // If closest point on line is inside the sphere then set foveatedFactor to 0.\n // Otherwise, the dot product is with the line from camera to the point on the sphere that is closest to the line.\n const scaledCameraDirection = Cartesian3.multiplyByScalar(\n camera.directionWC,\n tile._centerZDepth,\n scratchCartesian\n );\n const closestPointOnLine = Cartesian3.add(\n camera.positionWC,\n scaledCameraDirection,\n scratchCartesian\n );\n // The distance from the camera's view direction to the tile.\n const toLine = Cartesian3.subtract(\n closestPointOnLine,\n center,\n scratchCartesian\n );\n const distanceToCenterLine = Cartesian3.magnitude(toLine);\n const notTouchingSphere = distanceToCenterLine > radius;\n\n // If camera's direction vector is inside the bounding sphere then consider\n // this tile right along the line of sight and set _foveatedFactor to 0.\n // Otherwise,_foveatedFactor is one minus the dot product of the camera's direction\n // and the vector between the camera and the point on the bounding sphere closest to the view line.\n if (notTouchingSphere) {\n const toLineNormalized = Cartesian3.normalize(toLine, scratchCartesian);\n const scaledToLine = Cartesian3.multiplyByScalar(\n toLineNormalized,\n radius,\n scratchCartesian\n );\n const closestOnSphere = Cartesian3.add(\n center,\n scaledToLine,\n scratchCartesian\n );\n const toClosestOnSphere = Cartesian3.subtract(\n closestOnSphere,\n camera.positionWC,\n scratchCartesian\n );\n const toClosestOnSphereNormalize = Cartesian3.normalize(\n toClosestOnSphere,\n scratchCartesian\n );\n tile._foveatedFactor =\n 1.0 -\n Math.abs(Cartesian3.dot(camera.directionWC, toClosestOnSphereNormalize));\n } else {\n tile._foveatedFactor = 0.0;\n }\n\n // Skip this feature if: non-skipLevelOfDetail and replace refine, if the foveated settings are turned off, if tile is progressive resolution and replace refine and skipLevelOfDetail (will help get rid of ancestor artifacts faster)\n // Or if the tile is a preload of any kind\n const replace = tile.refine === Cesium3DTileRefine.REPLACE;\n const skipLevelOfDetail = tileset.isSkippingLevelOfDetail;\n if (\n (replace && !skipLevelOfDetail) ||\n !tileset.foveatedScreenSpaceError ||\n tileset.foveatedConeSize === 1.0 ||\n (tile._priorityProgressiveResolution && replace && skipLevelOfDetail) ||\n tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ||\n tileset._pass === Cesium3DTilePass.PRELOAD\n ) {\n return false;\n }\n\n const maximumFovatedFactor = 1.0 - Math.cos(camera.frustum.fov * 0.5); // 0.14 for fov = 60. NOTE very hard to defer vertically foveated tiles since max is based on fovy (which is fov). Lowering the 0.5 to a smaller fraction of the screen height will start to defer vertically foveated tiles.\n const foveatedConeFactor = tileset.foveatedConeSize * maximumFovatedFactor;\n\n // If it's inside the user-defined view cone, then it should not be deferred.\n if (tile._foveatedFactor <= foveatedConeFactor) {\n return false;\n }\n\n // Relax SSE based on how big the angle is between the tile and the edge of the foveated cone.\n const range = maximumFovatedFactor - foveatedConeFactor;\n const normalizedFoveatedFactor = CesiumMath.clamp(\n (tile._foveatedFactor - foveatedConeFactor) / range,\n 0.0,\n 1.0\n );\n const sseRelaxation = tileset.foveatedInterpolationCallback(\n tileset.foveatedMinimumScreenSpaceErrorRelaxation,\n tileset.memoryAdjustedScreenSpaceError,\n normalizedFoveatedFactor\n );\n const sse =\n tile._screenSpaceError === 0.0 && defined(tile.parent)\n ? tile.parent._screenSpaceError * 0.5\n : tile._screenSpaceError;\n\n return tileset.memoryAdjustedScreenSpaceError - sseRelaxation <= sse;\n}\n\nconst scratchJulianDate = new JulianDate();\n\n/**\n * Get the tile's screen space error.\n *\n * @private\n * @param {FrameState} frameState\n * @param {Boolean} useParentGeometricError\n * @param {number} progressiveResolutionHeightFraction\n */\nCesium3DTile.prototype.getScreenSpaceError = function (\n frameState,\n useParentGeometricError,\n progressiveResolutionHeightFraction\n) {\n const tileset = this._tileset;\n const heightFraction = defaultValue(progressiveResolutionHeightFraction, 1.0);\n const parentGeometricError = defined(this.parent)\n ? this.parent.geometricError\n : tileset._scaledGeometricError;\n const geometricError = useParentGeometricError\n ? parentGeometricError\n : this.geometricError;\n if (geometricError === 0.0) {\n // Leaf tiles do not have any error so save the computation\n return 0.0;\n }\n const { camera, context } = frameState;\n let frustum = camera.frustum;\n const width = context.drawingBufferWidth;\n const height = context.drawingBufferHeight * heightFraction;\n let error;\n if (\n frameState.mode === SceneMode.SCENE2D ||\n frustum instanceof OrthographicFrustum\n ) {\n const offCenterFrustum = frustum.offCenterFrustum;\n if (defined(offCenterFrustum)) {\n frustum = offCenterFrustum;\n }\n const pixelSize =\n Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) /\n Math.max(width, height);\n error = geometricError / pixelSize;\n } else {\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);\n const sseDenominator = frustum.sseDenominator;\n error = (geometricError * height) / (distance * sseDenominator);\n if (tileset.dynamicScreenSpaceError) {\n const density = tileset._dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n const dynamicError = CesiumMath.fog(distance, density) * factor;\n error -= dynamicError;\n }\n }\n\n error /= frameState.pixelRatio;\n\n return error;\n};\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n * @returns {Boolean}\n */\nfunction isPriorityProgressiveResolution(tileset, tile) {\n if (\n tileset.progressiveResolutionHeightFraction <= 0.0 ||\n tileset.progressiveResolutionHeightFraction > 0.5\n ) {\n return false;\n }\n\n const maximumScreenSpaceError = tileset.memoryAdjustedScreenSpaceError;\n let isProgressiveResolutionTile =\n tile._screenSpaceErrorProgressiveResolution > maximumScreenSpaceError; // Mark non-SSE leaves\n tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = false; // Needed for skipLOD\n const parent = tile.parent;\n const tilePasses =\n tile._screenSpaceErrorProgressiveResolution <= maximumScreenSpaceError;\n const parentFails =\n defined(parent) &&\n parent._screenSpaceErrorProgressiveResolution > maximumScreenSpaceError;\n if (tilePasses && parentFails) {\n // A progressive resolution SSE leaf, promote its priority as well\n tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = true;\n isProgressiveResolutionTile = true;\n }\n return isProgressiveResolutionTile;\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n * @returns {number}\n */\nfunction getPriorityReverseScreenSpaceError(tileset, tile) {\n const parent = tile.parent;\n const useParentScreenSpaceError =\n defined(parent) &&\n (!tileset.isSkippingLevelOfDetail ||\n tile._screenSpaceError === 0.0 ||\n parent.hasTilesetContent ||\n parent.hasImplicitContent);\n const screenSpaceError = useParentScreenSpaceError\n ? parent._screenSpaceError\n : tile._screenSpaceError;\n return tileset.root._screenSpaceError - screenSpaceError;\n}\n\n/**\n * Update the tile's visibility.\n *\n * @private\n * @param {FrameState} frameState\n */\nCesium3DTile.prototype.updateVisibility = function (frameState) {\n const { parent, tileset } = this;\n if (this._updatedVisibilityFrame === tileset._updatedVisibilityFrame) {\n // The tile has already been updated for this frame\n return;\n }\n\n const parentTransform = defined(parent)\n ? parent.computedTransform\n : tileset.modelMatrix;\n const parentVisibilityPlaneMask = defined(parent)\n ? parent._visibilityPlaneMask\n : CullingVolume.MASK_INDETERMINATE;\n this.updateTransform(parentTransform);\n this._distanceToCamera = this.distanceToTile(frameState);\n this._centerZDepth = this.distanceToTileCenter(frameState);\n this._screenSpaceError = this.getScreenSpaceError(frameState, false);\n this._screenSpaceErrorProgressiveResolution = this.getScreenSpaceError(\n frameState,\n false,\n tileset.progressiveResolutionHeightFraction\n );\n this._visibilityPlaneMask = this.visibility(\n frameState,\n parentVisibilityPlaneMask\n ); // Use parent's plane mask to speed up visibility test\n this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;\n this._inRequestVolume = this.insideViewerRequestVolume(frameState);\n this._priorityReverseScreenSpaceError = getPriorityReverseScreenSpaceError(\n tileset,\n this\n );\n this._priorityProgressiveResolution = isPriorityProgressiveResolution(\n tileset,\n this\n );\n this.priorityDeferred = isPriorityDeferred(this, frameState);\n\n this._updatedVisibilityFrame = tileset._updatedVisibilityFrame;\n};\n\n/**\n * Update whether the tile has expired.\n *\n * @private\n */\nCesium3DTile.prototype.updateExpiration = function () {\n if (\n defined(this.expireDate) &&\n this.contentReady &&\n !this.hasEmptyContent &&\n !this.hasMultipleContents\n ) {\n const now = JulianDate.now(scratchJulianDate);\n if (JulianDate.lessThan(this.expireDate, now)) {\n this._contentState = Cesium3DTileContentState.EXPIRED;\n this._expiredContent = this._content;\n }\n }\n};\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n */\nfunction updateExpireDate(tile) {\n if (!defined(tile.expireDuration)) {\n return;\n }\n const expireDurationDate = JulianDate.now(scratchJulianDate);\n JulianDate.addSeconds(\n expireDurationDate,\n tile.expireDuration,\n expireDurationDate\n );\n\n if (defined(tile.expireDate)) {\n if (JulianDate.lessThan(tile.expireDate, expireDurationDate)) {\n JulianDate.clone(expireDurationDate, tile.expireDate);\n }\n } else {\n tile.expireDate = JulianDate.clone(expireDurationDate);\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @returns {Function}\n */\nfunction createPriorityFunction(tile) {\n return function () {\n return tile._priority;\n };\n}\n\n/**\n * Requests the tile's content.\n *

\n * The request may not be made if the Cesium Request Scheduler can't prioritize it.\n *

\n *\n * @return {Promise|undefined} A promise that resolves when the request completes, or undefined if there is no request needed, or the request cannot be scheduled.\n * @private\n */\nCesium3DTile.prototype.requestContent = function () {\n // empty contents don't require any HTTP requests\n if (this.hasEmptyContent) {\n return;\n }\n\n if (this.hasMultipleContents) {\n return requestMultipleContents(this);\n }\n\n return requestSingleContent(this);\n};\n\n/**\n * Multiple {@link Cesium3DTileContent}s are allowed within a single tile either through\n * the tile JSON (3D Tiles 1.1) or the 3DTILES_multiple_contents extension.\n * Due to differences in request scheduling, this is handled separately.\n *

\n * This implementation of multiple contents does not\n * support tile expiry like requestSingleContent does. If this changes,\n * note that the resource.setQueryParameters() details must go inside {@link Multiple3DTileContent} since that is per-request.\n *

\n *\n * @private\n * @param {Cesium3DTile} tile\n * @returns {Promise|Promise|undefined} A promise that resolves to the tile content once loaded, or a promise that resolves to undefined if the request was cancelled mid-flight, or undefined if the request cannot be scheduled this frame\n */\nfunction requestMultipleContents(tile) {\n let multipleContents = tile._content;\n const tileset = tile._tileset;\n\n if (!defined(multipleContents)) {\n // Create the content object immediately, it will handle scheduling\n // requests for inner contents.\n const contentsJson = hasExtension(tile._header, \"3DTILES_multiple_contents\")\n ? tile._header.extensions[\"3DTILES_multiple_contents\"]\n : tile._header;\n\n multipleContents = new Multiple3DTileContent(\n tileset,\n tile,\n tile._contentResource.clone(),\n contentsJson\n );\n tile._content = multipleContents;\n }\n\n const promise = multipleContents.requestInnerContents();\n\n if (!defined(promise)) {\n // Request could not all be scheduled this frame\n return;\n }\n\n tile._contentState = Cesium3DTileContentState.LOADING;\n return promise\n .then((content) => {\n if (tile.isDestroyed()) {\n // Tile is unloaded before the content can process\n return;\n }\n\n // Tile was canceled, try again later\n if (!defined(content)) {\n return;\n }\n\n tile._contentState = Cesium3DTileContentState.PROCESSING;\n return multipleContents;\n })\n .catch((error) => {\n if (tile.isDestroyed()) {\n // Tile is unloaded before the content can process\n return;\n }\n\n tile._contentState = Cesium3DTileContentState.FAILED;\n throw error;\n });\n}\n\nasync function processArrayBuffer(\n tile,\n tileset,\n request,\n expired,\n requestPromise\n) {\n const previousState = tile._contentState;\n tile._contentState = Cesium3DTileContentState.LOADING;\n ++tileset.statistics.numberOfPendingRequests;\n\n let arrayBuffer;\n try {\n arrayBuffer = await requestPromise;\n } catch (error) {\n --tileset.statistics.numberOfPendingRequests;\n if (tile.isDestroyed()) {\n // Tile is unloaded before the content can process\n return;\n }\n\n if (request.cancelled || request.state === RequestState.CANCELLED) {\n // Cancelled due to low priority - try again later.\n tile._contentState = previousState;\n ++tileset.statistics.numberOfAttemptedRequests;\n return;\n }\n\n tile._contentState = Cesium3DTileContentState.FAILED;\n throw error;\n }\n\n if (tile.isDestroyed()) {\n --tileset.statistics.numberOfPendingRequests;\n // Tile is unloaded before the content can process\n return;\n }\n\n if (request.cancelled || request.state === RequestState.CANCELLED) {\n // Cancelled due to low priority - try again later.\n tile._contentState = previousState;\n --tileset.statistics.numberOfPendingRequests;\n ++tileset.statistics.numberOfAttemptedRequests;\n return;\n }\n\n try {\n const content = await makeContent(tile, arrayBuffer);\n --tileset.statistics.numberOfPendingRequests;\n\n if (tile.isDestroyed()) {\n // Tile is unloaded before the content can process\n return;\n }\n\n if (expired) {\n tile.expireDate = undefined;\n }\n\n tile._content = content;\n tile._contentState = Cesium3DTileContentState.PROCESSING;\n\n return content;\n } catch (error) {\n --tileset.statistics.numberOfPendingRequests;\n if (tile.isDestroyed()) {\n // Tile is unloaded before the content can process\n return;\n }\n\n tile._contentState = Cesium3DTileContentState.FAILED;\n throw error;\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @returns {Promise|Promise|undefined} A promise that resolves to the tile content once loaded; a promise that resolves to undefined if the tile was destroyed before processing can happen or the request was cancelled mid-flight; or undefined if the request cannot be scheduled this frame.\n */\nfunction requestSingleContent(tile) {\n // it is important to clone here. The fetchArrayBuffer() below uses\n // throttling, but other uses of the resources do not.\n const resource = tile._contentResource.clone();\n const expired = tile.contentExpired;\n if (expired) {\n // Append a query parameter of the tile expiration date to prevent caching\n resource.setQueryParameters({\n expired: tile.expireDate.toString(),\n });\n }\n\n const request = new Request({\n throttle: true,\n throttleByServer: true,\n type: RequestType.TILES3D,\n priorityFunction: createPriorityFunction(tile),\n serverKey: tile._serverKey,\n });\n\n tile._request = request;\n resource.request = request;\n const tileset = tile._tileset;\n const promise = resource.fetchArrayBuffer();\n if (!defined(promise)) {\n ++tileset.statistics.numberOfAttemptedRequests;\n return;\n }\n\n return processArrayBuffer(tile, tileset, request, expired, promise);\n}\n\n/**\n * Given a downloaded content payload, construct a {@link Cesium3DTileContent}.\n *

\n * This is only used for single contents.\n *

\n *\n * @param {Cesium3DTile} tile The tile\n * @param {ArrayBuffer} arrayBuffer The downloaded payload containing data for the content\n * @return {Promise} A content object\n * @private\n */\nasync function makeContent(tile, arrayBuffer) {\n const preprocessed = preprocess3DTileContent(arrayBuffer);\n\n // Vector and Geometry tile rendering do not support the skip LOD optimization.\n const tileset = tile._tileset;\n tileset._disableSkipLevelOfDetail =\n tileset._disableSkipLevelOfDetail ||\n preprocessed.contentType === Cesium3DTileContentType.GEOMETRY ||\n preprocessed.contentType === Cesium3DTileContentType.VECTOR;\n\n if (\n preprocessed.contentType === Cesium3DTileContentType.IMPLICIT_SUBTREE ||\n preprocessed.contentType === Cesium3DTileContentType.IMPLICIT_SUBTREE_JSON\n ) {\n tile.hasImplicitContent = true;\n }\n\n if (preprocessed.contentType === Cesium3DTileContentType.EXTERNAL_TILESET) {\n tile.hasTilesetContent = true;\n }\n\n let content;\n const contentFactory = Cesium3DTileContentFactory[preprocessed.contentType];\n if (tile.isDestroyed()) {\n return;\n }\n\n if (defined(preprocessed.binaryPayload)) {\n content = await Promise.resolve(\n contentFactory(\n tileset,\n tile,\n tile._contentResource,\n preprocessed.binaryPayload.buffer,\n 0\n )\n );\n } else {\n // JSON formats\n content = await Promise.resolve(\n contentFactory(\n tileset,\n tile,\n tile._contentResource,\n preprocessed.jsonPayload\n )\n );\n }\n\n const contentHeader = tile._contentHeader;\n\n if (tile.hasImplicitContentMetadata) {\n const subtree = tile.implicitSubtree;\n const coordinates = tile.implicitCoordinates;\n content.metadata = subtree.getContentMetadataView(coordinates, 0);\n } else if (!tile.hasImplicitContent) {\n content.metadata = findContentMetadata(tileset, contentHeader);\n }\n\n const groupMetadata = findGroupMetadata(tileset, contentHeader);\n if (defined(groupMetadata)) {\n content.group = new Cesium3DContentGroup({\n metadata: groupMetadata,\n });\n }\n\n return content;\n}\n\n/**\n * Cancel requests for the tile's contents. This is called when the tile\n * goes out of view.\n *\n * @private\n */\nCesium3DTile.prototype.cancelRequests = function () {\n if (this.hasMultipleContents) {\n this._content.cancelRequests();\n } else {\n this._request.cancel();\n }\n};\n\n/**\n * Unloads the tile's content.\n *\n * @private\n */\nCesium3DTile.prototype.unloadContent = function () {\n if (!this.hasRenderableContent) {\n return;\n }\n\n this._content = this._content && this._content.destroy();\n this._contentState = Cesium3DTileContentState.UNLOADED;\n\n this.lastStyleTime = 0.0;\n this.clippingPlanesDirty = this._clippingPlanesState === 0;\n this._clippingPlanesState = 0;\n\n this._debugColorizeTiles = false;\n\n this._debugBoundingVolume =\n this._debugBoundingVolume && this._debugBoundingVolume.destroy();\n this._debugContentBoundingVolume =\n this._debugContentBoundingVolume &&\n this._debugContentBoundingVolume.destroy();\n this._debugViewerRequestVolume =\n this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();\n};\n\nconst scratchProjectedBoundingSphere = new BoundingSphere();\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {TileBoundingVolume}\n */\nfunction getBoundingVolume(tile, frameState) {\n if (\n frameState.mode !== SceneMode.SCENE3D &&\n !defined(tile._boundingVolume2D)\n ) {\n const boundingSphere = tile._boundingVolume.boundingSphere;\n const sphere = BoundingSphere.projectTo2D(\n boundingSphere,\n frameState.mapProjection,\n scratchProjectedBoundingSphere\n );\n tile._boundingVolume2D = new TileBoundingSphere(\n sphere.center,\n sphere.radius\n );\n }\n\n return frameState.mode !== SceneMode.SCENE3D\n ? tile._boundingVolume2D\n : tile._boundingVolume;\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {TileBoundingVolume}\n */\nfunction getContentBoundingVolume(tile, frameState) {\n if (\n frameState.mode !== SceneMode.SCENE3D &&\n !defined(tile._contentBoundingVolume2D)\n ) {\n const boundingSphere = tile._contentBoundingVolume.boundingSphere;\n const sphere = BoundingSphere.projectTo2D(\n boundingSphere,\n frameState.mapProjection,\n scratchProjectedBoundingSphere\n );\n tile._contentBoundingVolume2D = new TileBoundingSphere(\n sphere.center,\n sphere.radius\n );\n }\n return frameState.mode !== SceneMode.SCENE3D\n ? tile._contentBoundingVolume2D\n : tile._contentBoundingVolume;\n}\n\n/**\n * Determines whether the tile's bounding volume intersects the culling volume.\n *\n * @param {FrameState} frameState The frame state.\n * @param {number} parentVisibilityPlaneMask The parent's plane mask to speed up the visibility check.\n * @returns {number} A plane mask as described above in {@link CullingVolume#computeVisibilityWithPlaneMask}.\n *\n * @private\n */\nCesium3DTile.prototype.visibility = function (\n frameState,\n parentVisibilityPlaneMask\n) {\n const cullingVolume = frameState.cullingVolume;\n const boundingVolume = getBoundingVolume(this, frameState);\n\n const tileset = this._tileset;\n const clippingPlanes = tileset.clippingPlanes;\n if (defined(clippingPlanes) && clippingPlanes.enabled) {\n const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(\n boundingVolume,\n tileset.clippingPlanesOriginMatrix\n );\n this._isClipped = intersection !== Intersect.INSIDE;\n if (intersection === Intersect.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n }\n }\n\n return cullingVolume.computeVisibilityWithPlaneMask(\n boundingVolume,\n parentVisibilityPlaneMask\n );\n};\n\n/**\n * Assuming the tile's bounding volume intersects the culling volume, determines\n * whether the tile's content's bounding volume intersects the culling volume.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {Intersect} The result of the intersection: the tile's content is completely outside, completely inside, or intersecting the culling volume.\n *\n * @private\n */\nCesium3DTile.prototype.contentVisibility = function (frameState) {\n // Assumes the tile's bounding volume intersects the culling volume already, so\n // just return Intersect.INSIDE if there is no content bounding volume.\n if (!defined(this._contentBoundingVolume)) {\n return Intersect.INSIDE;\n }\n\n if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {\n // The tile's bounding volume is completely inside the culling volume so\n // the content bounding volume must also be inside.\n return Intersect.INSIDE;\n }\n\n // PERFORMANCE_IDEA: is it possible to burn less CPU on this test since we know the\n // tile's (not the content's) bounding volume intersects the culling volume?\n const cullingVolume = frameState.cullingVolume;\n const boundingVolume = getContentBoundingVolume(this, frameState);\n\n const tileset = this._tileset;\n const clippingPlanes = tileset.clippingPlanes;\n if (defined(clippingPlanes) && clippingPlanes.enabled) {\n const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(\n boundingVolume,\n tileset.clippingPlanesOriginMatrix\n );\n this._isClipped = intersection !== Intersect.INSIDE;\n if (intersection === Intersect.OUTSIDE) {\n return Intersect.OUTSIDE;\n }\n }\n\n return cullingVolume.computeVisibility(boundingVolume);\n};\n\n/**\n * Computes the (potentially approximate) distance from the closest point of the tile's bounding volume to the camera.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {number} The distance, in meters, or zero if the camera is inside the bounding volume.\n *\n * @private\n */\nCesium3DTile.prototype.distanceToTile = function (frameState) {\n const boundingVolume = getBoundingVolume(this, frameState);\n return boundingVolume.distanceToCamera(frameState);\n};\n\nconst scratchToTileCenter = new Cartesian3();\n\n/**\n * Computes the distance from the center of the tile's bounding volume to the camera's plane defined by its position and view direction.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {number} The distance, in meters.\n *\n * @private\n */\nCesium3DTile.prototype.distanceToTileCenter = function (frameState) {\n const tileBoundingVolume = getBoundingVolume(this, frameState);\n const boundingVolume = tileBoundingVolume.boundingVolume; // Gets the underlying OrientedBoundingBox or BoundingSphere\n const toCenter = Cartesian3.subtract(\n boundingVolume.center,\n frameState.camera.positionWC,\n scratchToTileCenter\n );\n return Cartesian3.dot(frameState.camera.directionWC, toCenter);\n};\n\n/**\n * Checks if the camera is inside the viewer request volume.\n *\n * @param {FrameState} frameState The frame state.\n * @returns {boolean} Whether the camera is inside the volume.\n *\n * @private\n */\nCesium3DTile.prototype.insideViewerRequestVolume = function (frameState) {\n const viewerRequestVolume = this._viewerRequestVolume;\n return (\n !defined(viewerRequestVolume) ||\n viewerRequestVolume.distanceToCamera(frameState) === 0.0\n );\n};\n\nconst scratchMatrix = new Matrix3();\nconst scratchScale = new Cartesian3();\nconst scratchHalfAxes = new Matrix3();\nconst scratchCenter = new Cartesian3();\nconst scratchRectangle = new Rectangle();\nconst scratchOrientedBoundingBox = new OrientedBoundingBox();\nconst scratchTransform = new Matrix4();\n\n/**\n * @private\n * @param {Array} box An array of 12 numbers that define an oriented bounding box\n * @param {Matrix4} transform\n * @param {TileBoundingVolume} [result]\n * @returns {TileOrientedBoundingBox}\n */\nfunction createBox(box, transform, result) {\n let center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter);\n let halfAxes = Matrix3.fromArray(box, 3, scratchHalfAxes);\n\n // Find the transformed center and halfAxes\n center = Matrix4.multiplyByPoint(transform, center, center);\n const rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);\n halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);\n\n if (defined(result)) {\n result.update(center, halfAxes);\n return result;\n }\n return new TileOrientedBoundingBox(center, halfAxes);\n}\n\n/**\n * @private\n * @param {Array} region An array of six numbers that define a bounding geographic region in EPSG:4979 coordinates with the order [west, south, east, north, minimum height, maximum height]\n * @param {Matrix4} transform\n * @param {Matrix4} initialTransform\n * @param {TileOrientedBoundingBox} [result]\n * @returns {TileOrientedBoundingBox}\n */\nfunction createBoxFromTransformedRegion(\n region,\n transform,\n initialTransform,\n result\n) {\n const rectangle = Rectangle.unpack(region, 0, scratchRectangle);\n const minimumHeight = region[4];\n const maximumHeight = region[5];\n\n const orientedBoundingBox = OrientedBoundingBox.fromRectangle(\n rectangle,\n minimumHeight,\n maximumHeight,\n Ellipsoid.WGS84,\n scratchOrientedBoundingBox\n );\n let center = orientedBoundingBox.center;\n let halfAxes = orientedBoundingBox.halfAxes;\n\n // A region bounding volume is not transformed by the transform in the tileset JSON,\n // but may be transformed by additional transforms applied in Cesium.\n // This is why the transform is calculated as the difference between the initial transform and the current transform.\n transform = Matrix4.multiplyTransformation(\n transform,\n Matrix4.inverseTransformation(initialTransform, scratchTransform),\n scratchTransform\n );\n center = Matrix4.multiplyByPoint(transform, center, center);\n const rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);\n halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);\n\n if (defined(result) && result instanceof TileOrientedBoundingBox) {\n result.update(center, halfAxes);\n return result;\n }\n\n return new TileOrientedBoundingBox(center, halfAxes);\n}\n\n/**\n * @private\n * @param {Array} region An array of six numbers that define a bounding geographic region in EPSG:4979 coordinates with the order [west, south, east, north, minimum height, maximum height]\n * @param {Matrix4} transform\n * @param {Matrix4} initialTransform\n * @param {TileBoundingVolume} [result]\n * @returns {TileBoundingVolume}\n */\nfunction createRegion(region, transform, initialTransform, result) {\n if (\n !Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)\n ) {\n return createBoxFromTransformedRegion(\n region,\n transform,\n initialTransform,\n result\n );\n }\n\n if (defined(result)) {\n return result;\n }\n\n const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);\n\n return new TileBoundingRegion({\n rectangle: rectangleRegion,\n minimumHeight: region[4],\n maximumHeight: region[5],\n });\n}\n\n/**\n * @private\n * @param {Array} sphere An array of four numbers that define a bounding sphere\n * @param {Matrix4} transform\n * @param {TileBoundingVolume} [result]\n * @returns {TileBoundingSphere}\n */\nfunction createSphere(sphere, transform, result) {\n let center = Cartesian3.fromElements(\n sphere[0],\n sphere[1],\n sphere[2],\n scratchCenter\n );\n let radius = sphere[3];\n\n // Find the transformed center and radius\n center = Matrix4.multiplyByPoint(transform, center, center);\n const scale = Matrix4.getScale(transform, scratchScale);\n const uniformScale = Cartesian3.maximumComponent(scale);\n radius *= uniformScale;\n\n if (defined(result)) {\n result.update(center, radius);\n return result;\n }\n return new TileBoundingSphere(center, radius);\n}\n\n/**\n * Create a bounding volume from the tile's bounding volume header.\n *\n * @param {object} boundingVolumeHeader The tile's bounding volume header.\n * @param {Matrix4} transform The transform to apply to the bounding volume.\n * @param {TileBoundingVolume} [result] The object onto which to store the result.\n *\n * @returns {TileBoundingVolume} The modified result parameter or a new TileBoundingVolume instance if none was provided.\n *\n * @private\n */\nCesium3DTile.prototype.createBoundingVolume = function (\n boundingVolumeHeader,\n transform,\n result\n) {\n // if explicit tile metadata includes TILE_BOUNDING_BOX, TILE_BOUNDING_REGION,\n // or TILE_BOUNDING_SPHERE, override tile.boundingVolume.\n const tileMetadata = this.metadata;\n let metadataBoundingVolumeHeader;\n if (defined(tileMetadata)) {\n metadataBoundingVolumeHeader = BoundingVolumeSemantics.parseBoundingVolumeSemantic(\n \"TILE\",\n tileMetadata\n );\n }\n if (defined(metadataBoundingVolumeHeader)) {\n boundingVolumeHeader = metadataBoundingVolumeHeader;\n }\n\n if (!defined(boundingVolumeHeader)) {\n throw new RuntimeError(\"boundingVolume must be defined\");\n }\n\n if (hasExtension(boundingVolumeHeader, \"3DTILES_bounding_volume_S2\")) {\n return new TileBoundingS2Cell(\n boundingVolumeHeader.extensions[\"3DTILES_bounding_volume_S2\"]\n );\n }\n\n const { box, region, sphere } = boundingVolumeHeader;\n if (defined(box)) {\n return createBox(box, transform, result);\n }\n if (defined(region)) {\n return createRegion(region, transform, this._initialTransform, result);\n }\n if (defined(sphere)) {\n return createSphere(sphere, transform, result);\n }\n throw new RuntimeError(\n \"boundingVolume must contain a sphere, region, or box\"\n );\n};\n\n/**\n * Update the tile's transform. The transform is applied to the tile's bounding volumes.\n *\n * @private\n * @param {Matrix4} parentTransform\n */\nCesium3DTile.prototype.updateTransform = function (parentTransform) {\n parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY);\n const computedTransform = Matrix4.multiplyTransformation(\n parentTransform,\n this.transform,\n scratchTransform\n );\n const transformChanged = !Matrix4.equals(\n computedTransform,\n this.computedTransform\n );\n\n if (!transformChanged) {\n return;\n }\n\n Matrix4.clone(computedTransform, this.computedTransform);\n\n // Update the bounding volumes\n const header = this._header;\n const contentHeader = this._contentHeader;\n this._boundingVolume = this.createBoundingVolume(\n header.boundingVolume,\n this.computedTransform,\n this._boundingVolume\n );\n if (defined(this._contentBoundingVolume)) {\n this._contentBoundingVolume = this.createBoundingVolume(\n contentHeader.boundingVolume,\n this.computedTransform,\n this._contentBoundingVolume\n );\n }\n if (defined(this._viewerRequestVolume)) {\n this._viewerRequestVolume = this.createBoundingVolume(\n header.viewerRequestVolume,\n this.computedTransform,\n this._viewerRequestVolume\n );\n }\n\n this.updateGeometricErrorScale();\n\n // Destroy the debug bounding volumes. They will be generated fresh.\n this._debugBoundingVolume =\n this._debugBoundingVolume && this._debugBoundingVolume.destroy();\n this._debugContentBoundingVolume =\n this._debugContentBoundingVolume &&\n this._debugContentBoundingVolume.destroy();\n this._debugViewerRequestVolume =\n this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();\n};\n\nCesium3DTile.prototype.updateGeometricErrorScale = function () {\n const scale = Matrix4.getScale(this.computedTransform, scratchScale);\n const uniformScale = Cartesian3.maximumComponent(scale);\n this.geometricError = this._geometricError * uniformScale;\n\n if (!defined(this.parent)) {\n // Update the tileset's geometric error\n const tileset = this._tileset;\n tileset._scaledGeometricError = tileset._geometricError * uniformScale;\n }\n};\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n * @param {object} passOptions\n */\nfunction applyDebugSettings(tile, tileset, frameState, passOptions) {\n if (!passOptions.isRender) {\n return;\n }\n\n const hasContentBoundingVolume =\n defined(tile._contentHeader) && defined(tile._contentHeader.boundingVolume);\n\n const showVolume =\n tileset.debugShowBoundingVolume ||\n (tileset.debugShowContentBoundingVolume && !hasContentBoundingVolume);\n if (showVolume) {\n let color;\n if (!tile._finalResolution) {\n color = Color.YELLOW;\n } else if (!tile.hasRenderableContent) {\n color = Color.DARKGRAY;\n } else {\n color = Color.WHITE;\n }\n if (!defined(tile._debugBoundingVolume)) {\n tile._debugBoundingVolume = tile._boundingVolume.createDebugVolume(color);\n }\n tile._debugBoundingVolume.update(frameState);\n const attributes = tile._debugBoundingVolume.getGeometryInstanceAttributes(\n \"outline\"\n );\n attributes.color = ColorGeometryInstanceAttribute.toValue(\n color,\n attributes.color\n );\n } else if (!showVolume && defined(tile._debugBoundingVolume)) {\n tile._debugBoundingVolume = tile._debugBoundingVolume.destroy();\n }\n\n if (tileset.debugShowContentBoundingVolume && hasContentBoundingVolume) {\n if (!defined(tile._debugContentBoundingVolume)) {\n tile._debugContentBoundingVolume = tile._contentBoundingVolume.createDebugVolume(\n Color.BLUE\n );\n }\n tile._debugContentBoundingVolume.update(frameState);\n } else if (\n !tileset.debugShowContentBoundingVolume &&\n defined(tile._debugContentBoundingVolume)\n ) {\n tile._debugContentBoundingVolume = tile._debugContentBoundingVolume.destroy();\n }\n\n if (\n tileset.debugShowViewerRequestVolume &&\n defined(tile._viewerRequestVolume)\n ) {\n if (!defined(tile._debugViewerRequestVolume)) {\n tile._debugViewerRequestVolume = tile._viewerRequestVolume.createDebugVolume(\n Color.YELLOW\n );\n }\n tile._debugViewerRequestVolume.update(frameState);\n } else if (\n !tileset.debugShowViewerRequestVolume &&\n defined(tile._debugViewerRequestVolume)\n ) {\n tile._debugViewerRequestVolume = tile._debugViewerRequestVolume.destroy();\n }\n\n const debugColorizeTilesOn =\n (tileset.debugColorizeTiles && !tile._debugColorizeTiles) ||\n defined(tileset._heatmap.tilePropertyName);\n const debugColorizeTilesOff =\n !tileset.debugColorizeTiles && tile._debugColorizeTiles;\n\n if (debugColorizeTilesOn) {\n tileset._heatmap.colorize(tile, frameState); // Skipped if tileset._heatmap.tilePropertyName is undefined\n tile._debugColorizeTiles = true;\n tile.color = tile._debugColor;\n } else if (debugColorizeTilesOff) {\n tile._debugColorizeTiles = false;\n tile.color = Color.WHITE;\n }\n\n if (tile._colorDirty) {\n tile._colorDirty = false;\n tile._content.applyDebugSettings(true, tile._color);\n }\n\n if (debugColorizeTilesOff) {\n tileset.makeStyleDirty(); // Re-apply style now that colorize is switched off\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction updateContent(tile, tileset, frameState) {\n const expiredContent = tile._expiredContent;\n\n // expired content is not supported for multiple contents\n if (!tile.hasMultipleContents && defined(expiredContent)) {\n if (!tile.contentReady) {\n // Render the expired content while the content loads\n try {\n expiredContent.update(tileset, frameState);\n } catch (error) {\n // Eat error for expired content\n }\n return;\n }\n\n // New content is ready, destroy expired content\n tile._expiredContent.destroy();\n tile._expiredContent = undefined;\n }\n\n if (!defined(tile.content)) {\n // Implicit placeholder tile\n return;\n }\n\n try {\n tile.content.update(tileset, frameState);\n } catch (error) {\n tile._contentState = Cesium3DTileContentState.FAILED;\n throw error;\n }\n}\n\n/**\n * Compute and compare ClippingPlanes state:\n * - enabled-ness - are clipping planes enabled? is this tile clipped?\n * - clipping plane count\n * - clipping function (union v. intersection)\n\n * @private\n * @param {Cesium3DTile} tile\n * @param {Cesium3DTileset} tileset\n */\nfunction updateClippingPlanes(tile, tileset) {\n const clippingPlanes = tileset.clippingPlanes;\n let currentClippingPlanesState = 0;\n if (defined(clippingPlanes) && tile._isClipped && clippingPlanes.enabled) {\n currentClippingPlanesState = clippingPlanes.clippingPlanesState;\n }\n // If clippingPlaneState for tile changed, mark clippingPlanesDirty so content can update\n if (currentClippingPlanesState !== tile._clippingPlanesState) {\n tile._clippingPlanesState = currentClippingPlanesState;\n tile.clippingPlanesDirty = true;\n }\n}\n\n/**\n * Get the draw commands needed to render this tile.\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n * @param {object} passOptions\n */\nCesium3DTile.prototype.update = function (tileset, frameState, passOptions) {\n const { commandList } = frameState;\n const commandStart = commandList.length;\n\n updateClippingPlanes(this, tileset);\n applyDebugSettings(this, tileset, frameState, passOptions);\n updateContent(this, tileset, frameState);\n\n const commandEnd = commandList.length;\n this._commandsLength = commandEnd - commandStart;\n\n for (let i = commandStart; i < commandEnd; ++i) {\n const command = commandList[i];\n const translucent = command.pass === Pass.TRANSLUCENT;\n command.depthForTranslucentClassification = translucent;\n }\n\n this.clippingPlanesDirty = false; // reset after content update\n};\n\nconst scratchCommandList = [];\n\n/**\n * Processes the tile's content, e.g., create WebGL resources, to move from the PROCESSING to READY state.\n *\n * @param {Cesium3DTileset} tileset The tileset containing this tile.\n * @param {FrameState} frameState The frame state.\n *\n * @private\n */\nCesium3DTile.prototype.process = function (tileset, frameState) {\n if (!this.contentExpired && !this.contentReady && this._content.ready) {\n updateExpireDate(this);\n\n // Refresh style for expired content\n this._selectedFrame = 0;\n this.lastStyleTime = 0.0;\n\n JulianDate.now(this._loadTimestamp);\n this._contentState = Cesium3DTileContentState.READY;\n\n if (!this.hasTilesetContent && !this.hasImplicitContent) {\n // RESEARCH_IDEA: ability to unload tiles (without content) for an\n // external tileset when all the tiles are unloaded.\n tileset._statistics.incrementLoadCounts(this.content);\n ++tileset._statistics.numberOfTilesWithContentReady;\n ++tileset._statistics.numberOfLoadedTilesTotal;\n\n // Add to the tile cache. Previously expired tiles are already in the cache and won't get re-added.\n tileset._cache.add(this);\n }\n }\n\n const savedCommandList = frameState.commandList;\n frameState.commandList = scratchCommandList;\n\n try {\n this._content.update(tileset, frameState);\n } catch (error) {\n this._contentState = Cesium3DTileContentState.FAILED;\n throw error;\n }\n\n scratchCommandList.length = 0;\n frameState.commandList = savedCommandList;\n};\n\n/**\n * @private\n * @param {number} normalizedValue\n * @param {number} numberOfDigits\n * @param {number} leftShift\n * @returns {number}\n */\nfunction isolateDigits(normalizedValue, numberOfDigits, leftShift) {\n const scaled = normalizedValue * Math.pow(10, numberOfDigits);\n const integer = parseInt(scaled);\n return integer * Math.pow(10, leftShift);\n}\n\n/**\n * @private\n * @param {number} value\n * @param {number} minimum\n * @param {number} maximum\n * @returns {number}\n */\nfunction priorityNormalizeAndClamp(value, minimum, maximum) {\n // Subtract epsilon since we only want decimal digits present in the output.\n return Math.max(\n CesiumMath.normalize(value, minimum, maximum) - CesiumMath.EPSILON7,\n 0.0\n );\n}\n\n/**\n * Sets the priority of the tile based on distance and depth\n * @private\n */\nCesium3DTile.prototype.updatePriority = function () {\n const tileset = this.tileset;\n const preferLeaves = tileset.preferLeaves;\n const minimumPriority = tileset._minimumPriority;\n const maximumPriority = tileset._maximumPriority;\n\n // Combine priority systems together by mapping them into a base 10 number where each priority controls a specific set of digits in the number.\n // For number priorities, map them to a 0.xxxxx number then left shift it up into a set number of digits before the decimal point. Chop of the fractional part then left shift again into the position it needs to go.\n // For blending number priorities, normalize them to 0-1 and interpolate to get a combined 0-1 number, then proceed as normal.\n // Booleans can just be 0 or 10^leftshift.\n // Think of digits as penalties since smaller numbers are higher priority. If a tile has some large quantity or has a flag raised it's (usually) penalized for it, expressed as a higher number for the digit.\n // Priority number format: preloadFlightDigits(1) | foveatedDeferDigits(1) | foveatedDigits(4) | preloadProgressiveResolutionDigits(1) | preferredSortingDigits(4) . depthDigits(the decimal digits)\n // Certain flags like preferLeaves will flip / turn off certain digits to get desired load order.\n\n // Setup leftShifts, digit counts, and scales (for booleans)\n const digitsForANumber = 4;\n const digitsForABoolean = 1;\n\n const preferredSortingLeftShift = 0;\n const preferredSortingDigitsCount = digitsForANumber;\n\n const foveatedLeftShift =\n preferredSortingLeftShift + preferredSortingDigitsCount;\n const foveatedDigitsCount = digitsForANumber;\n\n const preloadProgressiveResolutionLeftShift =\n foveatedLeftShift + foveatedDigitsCount;\n const preloadProgressiveResolutionDigitsCount = digitsForABoolean;\n const preloadProgressiveResolutionScale = Math.pow(\n 10,\n preloadProgressiveResolutionLeftShift\n );\n\n const foveatedDeferLeftShift =\n preloadProgressiveResolutionLeftShift +\n preloadProgressiveResolutionDigitsCount;\n const foveatedDeferDigitsCount = digitsForABoolean;\n const foveatedDeferScale = Math.pow(10, foveatedDeferLeftShift);\n\n const preloadFlightLeftShift =\n foveatedDeferLeftShift + foveatedDeferDigitsCount;\n const preloadFlightScale = Math.pow(10, preloadFlightLeftShift);\n\n // Compute the digits for each priority\n let depthDigits = priorityNormalizeAndClamp(\n this._depth,\n minimumPriority.depth,\n maximumPriority.depth\n );\n depthDigits = preferLeaves ? 1.0 - depthDigits : depthDigits;\n\n // Map 0-1 then convert to digit. Include a distance sort when doing non-skipLOD and replacement refinement, helps things like non-skipLOD photogrammetry\n const useDistance =\n !tileset.isSkippingLevelOfDetail &&\n this.refine === Cesium3DTileRefine.REPLACE;\n const normalizedPreferredSorting = useDistance\n ? priorityNormalizeAndClamp(\n this._priorityHolder._distanceToCamera,\n minimumPriority.distance,\n maximumPriority.distance\n )\n : priorityNormalizeAndClamp(\n this._priorityReverseScreenSpaceError,\n minimumPriority.reverseScreenSpaceError,\n maximumPriority.reverseScreenSpaceError\n );\n const preferredSortingDigits = isolateDigits(\n normalizedPreferredSorting,\n preferredSortingDigitsCount,\n preferredSortingLeftShift\n );\n\n const preloadProgressiveResolutionDigits = this._priorityProgressiveResolution\n ? 0\n : preloadProgressiveResolutionScale;\n\n const normalizedFoveatedFactor = priorityNormalizeAndClamp(\n this._priorityHolder._foveatedFactor,\n minimumPriority.foveatedFactor,\n maximumPriority.foveatedFactor\n );\n const foveatedDigits = isolateDigits(\n normalizedFoveatedFactor,\n foveatedDigitsCount,\n foveatedLeftShift\n );\n\n const foveatedDeferDigits = this.priorityDeferred ? foveatedDeferScale : 0;\n\n const preloadFlightDigits =\n tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ? 0 : preloadFlightScale;\n\n // Get the final base 10 number\n this._priority =\n depthDigits +\n preferredSortingDigits +\n preloadProgressiveResolutionDigits +\n foveatedDigits +\n foveatedDeferDigits +\n preloadFlightDigits;\n};\n\n/**\n * @private\n */\nCesium3DTile.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * @private\n */\nCesium3DTile.prototype.destroy = function () {\n // For the interval between new content being requested and downloaded, expiredContent === content, so don't destroy twice\n this._content = this._content && this._content.destroy();\n this._expiredContent =\n this._expiredContent &&\n !this._expiredContent.isDestroyed() &&\n this._expiredContent.destroy();\n this._debugBoundingVolume =\n this._debugBoundingVolume && this._debugBoundingVolume.destroy();\n this._debugContentBoundingVolume =\n this._debugContentBoundingVolume &&\n this._debugContentBoundingVolume.destroy();\n this._debugViewerRequestVolume =\n this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();\n return destroyObject(this);\n};\n\nexport default Cesium3DTile;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * Metadata about a group of {@link Cesium3DTileContent}\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.id The ID of the group.\n * @param {object} options.group The group JSON object.\n * @param {MetadataClass} options.class The class that group metadata conforms to.\n *\n * @alias GroupMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction GroupMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const id = options.id;\n const group = options.group;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.group\", group);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n const properties = defined(group.properties) ? group.properties : {};\n\n this._class = metadataClass;\n this._properties = properties;\n this._id = id;\n this._extras = group.extras;\n this._extensions = group.extensions;\n}\n\nObject.defineProperties(GroupMetadata.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof GroupMetadata.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * The ID of the group.\n *\n * @memberof GroupMetadata.prototype\n * @type {string}\n * @readonly\n * @private\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof GroupMetadata.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof GroupMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the group has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the group has this property.\n * @private\n */\nGroupMetadata.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the group has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the group has a property with the given semantic.\n * @private\n */\nGroupMetadata.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nGroupMetadata.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the group does not have this property.\n * @private\n */\nGroupMetadata.prototype.getProperty = function (propertyId) {\n return MetadataEntity.getProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nGroupMetadata.prototype.setProperty = function (propertyId, value) {\n return MetadataEntity.setProperty(\n propertyId,\n value,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the group does not have this semantic.\n * @private\n */\nGroupMetadata.prototype.getPropertyBySemantic = function (semantic) {\n return MetadataEntity.getPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nGroupMetadata.prototype.setPropertyBySemantic = function (semantic, value) {\n return MetadataEntity.setPropertyBySemantic(\n semantic,\n value,\n this._properties,\n this._class\n );\n};\n\nexport default GroupMetadata;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport MetadataEntity from \"./MetadataEntity.js\";\n\n/**\n * Metadata about the tileset.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.tileset The tileset metadata JSON object.\n * @param {MetadataClass} options.class The class that tileset metadata conforms to.\n *\n * @alias TilesetMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction TilesetMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const tileset = options.tileset;\n const metadataClass = options.class;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.tileset\", tileset);\n Check.typeOf.object(\"options.class\", metadataClass);\n //>>includeEnd('debug');\n\n const properties = defined(tileset.properties) ? tileset.properties : {};\n\n this._class = metadataClass;\n this._properties = properties;\n this._extras = tileset.extras;\n this._extensions = tileset.extensions;\n}\n\nObject.defineProperties(TilesetMetadata.prototype, {\n /**\n * The class that properties conform to.\n *\n * @memberof TilesetMetadata.prototype\n * @type {MetadataClass}\n * @readonly\n * @private\n */\n class: {\n get: function () {\n return this._class;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof TilesetMetadata.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof TilesetMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\n/**\n * Returns whether the tileset has this property.\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {boolean} Whether the tileset has this property.\n * @private\n */\nTilesetMetadata.prototype.hasProperty = function (propertyId) {\n return MetadataEntity.hasProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Returns whether the tileset has a property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {boolean} Whether the tileset has a property with the given semantic.\n * @private\n */\nTilesetMetadata.prototype.hasPropertyBySemantic = function (semantic) {\n return MetadataEntity.hasPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns an array of property IDs.\n *\n * @param {string[]} [results] An array into which to store the results.\n * @returns {string[]} The property IDs.\n * @private\n */\nTilesetMetadata.prototype.getPropertyIds = function (results) {\n return MetadataEntity.getPropertyIds(this._properties, this._class, results);\n};\n\n/**\n * Returns a copy of the value of the property with the given ID.\n *

\n * If the property is normalized the normalized value is returned.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @returns {*} The value of the property or undefined if the tileset does not have this property.\n * @private\n */\nTilesetMetadata.prototype.getProperty = function (propertyId) {\n return MetadataEntity.getProperty(propertyId, this._properties, this._class);\n};\n\n/**\n * Sets the value of the property with the given ID.\n *

\n * If the property is normalized a normalized value must be provided to this function.\n *

\n *\n * @param {string} propertyId The case-sensitive ID of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nTilesetMetadata.prototype.setProperty = function (propertyId, value) {\n return MetadataEntity.setProperty(\n propertyId,\n value,\n this._properties,\n this._class\n );\n};\n\n/**\n * Returns a copy of the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @returns {*} The value of the property or undefined if the tileset does not have this semantic.\n * @private\n */\nTilesetMetadata.prototype.getPropertyBySemantic = function (semantic) {\n return MetadataEntity.getPropertyBySemantic(\n semantic,\n this._properties,\n this._class\n );\n};\n\n/**\n * Sets the value of the property with the given semantic.\n *\n * @param {string} semantic The case-sensitive semantic of the property.\n * @param {*} value The value of the property that will be copied.\n * @returns {boolean} true if the property was set, false otherwise.\n * @private\n */\nTilesetMetadata.prototype.setPropertyBySemantic = function (semantic, value) {\n return MetadataEntity.setPropertyBySemantic(\n semantic,\n value,\n this._properties,\n this._class\n );\n};\n\nexport default TilesetMetadata;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport GroupMetadata from \"./GroupMetadata.js\";\nimport TilesetMetadata from \"./TilesetMetadata.js\";\n\n/**\n * An object containing metadata about a 3D Tileset.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles.\n *

\n *

\n * This object represents the tileset JSON (3D Tiles 1.1) or the 3DTILES_metadata object that contains\n * the schema ({@link MetadataSchema}), tileset metadata ({@link TilesetMetadata}), group metadata (dictionary of {@link GroupMetadata}), and metadata statistics (dictionary)\n *

\n *\n * @param {object} options Object with the following properties:\n * @param {object} options.metadataJson Either the tileset JSON (3D Tiles 1.1) or the 3DTILES_metadata extension object that contains the tileset metadata.\n * @param {MetadataSchema} options.schema The parsed schema.\n *\n * @alias Cesium3DTilesetMetadata\n * @constructor\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction Cesium3DTilesetMetadata(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const metadataJson = options.metadataJson;\n\n // The calling code is responsible for loading the schema.\n // This keeps metadata parsing synchronous.\n const schema = options.schema;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.metadataJson\", metadataJson);\n Check.typeOf.object(\"options.schema\", schema);\n //>>includeEnd('debug');\n\n // An older schema stored the tileset metadata in the \"tileset\" property.\n const metadata = defaultValue(metadataJson.metadata, metadataJson.tileset);\n\n let tileset;\n if (defined(metadata)) {\n tileset = new TilesetMetadata({\n tileset: metadata,\n class: schema.classes[metadata.class],\n });\n }\n\n let groupIds = [];\n const groups = [];\n const groupsJson = metadataJson.groups;\n if (Array.isArray(groupsJson)) {\n const length = groupsJson.length;\n for (let i = 0; i < length; i++) {\n const group = groupsJson[i];\n groups.push(\n new GroupMetadata({\n group: group,\n class: schema.classes[group.class],\n })\n );\n }\n } else if (defined(groupsJson)) {\n // An older version of group metadata stored groups in a dictionary\n // instead of an array.\n groupIds = Object.keys(groupsJson).sort();\n const length = groupIds.length;\n for (let i = 0; i < length; i++) {\n const groupId = groupIds[i];\n if (groupsJson.hasOwnProperty(groupId)) {\n const group = groupsJson[groupId];\n groups.push(\n new GroupMetadata({\n id: groupId,\n group: groupsJson[groupId],\n class: schema.classes[group.class],\n })\n );\n }\n }\n }\n\n this._schema = schema;\n this._groups = groups;\n this._groupIds = groupIds;\n this._tileset = tileset;\n\n this._statistics = metadataJson.statistics;\n this._extras = metadataJson.extras;\n this._extensions = metadataJson.extensions;\n}\n\nObject.defineProperties(Cesium3DTilesetMetadata.prototype, {\n /**\n * Schema containing classes and enums.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {MetadataSchema}\n * @readonly\n * @private\n */\n schema: {\n get: function () {\n return this._schema;\n },\n },\n\n /**\n * Metadata about groups of content.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {GroupMetadata[]}\n * @readonly\n * @private\n */\n groups: {\n get: function () {\n return this._groups;\n },\n },\n\n /**\n * The IDs of the group metadata in the corresponding groups dictionary.\n * Only populated if using the legacy schema.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {}\n * @readonly\n * @private\n */\n groupIds: {\n get: function () {\n return this._groupIds;\n },\n },\n\n /**\n * Metadata about the tileset as a whole.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {TilesetMetadata}\n * @readonly\n * @private\n */\n tileset: {\n get: function () {\n return this._tileset;\n },\n },\n\n /**\n * Statistics about the metadata.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/blob/main/extensions/3DTILES_metadata/schema/statistics.schema.json|statistics schema reference}\n * in the 3D Tiles spec for the full set of properties.\n *

\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n statistics: {\n get: function () {\n return this._statistics;\n },\n },\n\n /**\n * Extra user-defined properties.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {*}\n * @readonly\n * @private\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * An object containing extensions.\n *\n * @memberof Cesium3DTilesetMetadata.prototype\n * @type {object}\n * @readonly\n * @private\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n});\n\nexport default Cesium3DTilesetMetadata;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Cesium3DTileOptimizationHint from \"./Cesium3DTileOptimizationHint.js\";\nimport TileBoundingRegion from \"./TileBoundingRegion.js\";\nimport TileOrientedBoundingBox from \"./TileOrientedBoundingBox.js\";\n\n/**\n * Utility functions for computing optimization hints for a {@link Cesium3DTileset}.\n *\n * @namespace Cesium3DTileOptimizations\n *\n * @private\n */\nconst Cesium3DTileOptimizations = {};\n\nconst scratchAxis = new Cartesian3();\n\n/**\n * Evaluates support for the childrenWithinParent optimization. This is used to more tightly cull tilesets if\n * children bounds are fully contained within the parent. Currently, support for the optimization only works for\n * oriented bounding boxes, so both the child and parent tile must be either a {@link TileOrientedBoundingBox} or\n * {@link TileBoundingRegion}. The purpose of this check is to prevent use of a culling optimization when the child\n * bounds exceed those of the parent. If the child bounds are greater, it is more likely that the optimization will\n * waste CPU cycles. Bounding spheres are not supported for the reason that the child bounds can very often be\n * partially outside of the parent bounds.\n *\n * @param {Cesium3DTile} tile The tile to check.\n * @returns {boolean} Whether the childrenWithinParent optimization is supported.\n */\nCesium3DTileOptimizations.checkChildrenWithinParent = function (tile) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"tile\", tile);\n //>>includeEnd('debug');\n\n const children = tile.children;\n const length = children.length;\n\n // Check if the parent has an oriented bounding box.\n const boundingVolume = tile.boundingVolume;\n if (\n boundingVolume instanceof TileOrientedBoundingBox ||\n boundingVolume instanceof TileBoundingRegion\n ) {\n const orientedBoundingBox = boundingVolume._orientedBoundingBox;\n tile._optimChildrenWithinParent =\n Cesium3DTileOptimizationHint.USE_OPTIMIZATION;\n for (let i = 0; i < length; ++i) {\n const child = children[i];\n\n // Check if the child has an oriented bounding box.\n const childBoundingVolume = child.boundingVolume;\n if (\n !(\n childBoundingVolume instanceof TileOrientedBoundingBox ||\n childBoundingVolume instanceof TileBoundingRegion\n )\n ) {\n // Do not support if the parent and child both do not have oriented bounding boxes.\n tile._optimChildrenWithinParent =\n Cesium3DTileOptimizationHint.SKIP_OPTIMIZATION;\n break;\n }\n\n const childOrientedBoundingBox = childBoundingVolume._orientedBoundingBox;\n\n // Compute the axis from the parent to the child.\n const axis = Cartesian3.subtract(\n childOrientedBoundingBox.center,\n orientedBoundingBox.center,\n scratchAxis\n );\n const axisLength = Cartesian3.magnitude(axis);\n Cartesian3.divideByScalar(axis, axisLength, axis);\n\n // Project the bounding box of the parent onto the axis. Because the axis is a ray from the parent\n // to the child, the projection parameterized along the ray will be (+/- proj1).\n const proj1 =\n Math.abs(orientedBoundingBox.halfAxes[0] * axis.x) +\n Math.abs(orientedBoundingBox.halfAxes[1] * axis.y) +\n Math.abs(orientedBoundingBox.halfAxes[2] * axis.z) +\n Math.abs(orientedBoundingBox.halfAxes[3] * axis.x) +\n Math.abs(orientedBoundingBox.halfAxes[4] * axis.y) +\n Math.abs(orientedBoundingBox.halfAxes[5] * axis.z) +\n Math.abs(orientedBoundingBox.halfAxes[6] * axis.x) +\n Math.abs(orientedBoundingBox.halfAxes[7] * axis.y) +\n Math.abs(orientedBoundingBox.halfAxes[8] * axis.z);\n\n // Project the bounding box of the child onto the axis. Because the axis is a ray from the parent\n // to the child, the projection parameterized along the ray will be (+/- proj2) + axis.length.\n const proj2 =\n Math.abs(childOrientedBoundingBox.halfAxes[0] * axis.x) +\n Math.abs(childOrientedBoundingBox.halfAxes[1] * axis.y) +\n Math.abs(childOrientedBoundingBox.halfAxes[2] * axis.z) +\n Math.abs(childOrientedBoundingBox.halfAxes[3] * axis.x) +\n Math.abs(childOrientedBoundingBox.halfAxes[4] * axis.y) +\n Math.abs(childOrientedBoundingBox.halfAxes[5] * axis.z) +\n Math.abs(childOrientedBoundingBox.halfAxes[6] * axis.x) +\n Math.abs(childOrientedBoundingBox.halfAxes[7] * axis.y) +\n Math.abs(childOrientedBoundingBox.halfAxes[8] * axis.z);\n\n // If the child extends the parent's bounds, the optimization is not valid and we skip it.\n if (proj1 <= proj2 + axisLength) {\n tile._optimChildrenWithinParent =\n Cesium3DTileOptimizationHint.SKIP_OPTIMIZATION;\n break;\n }\n }\n }\n\n return (\n tile._optimChildrenWithinParent ===\n Cesium3DTileOptimizationHint.USE_OPTIMIZATION\n );\n};\nexport default Cesium3DTileOptimizations;\n", "import defined from \"./defined.js\";\n\n/**\n * @private\n */\nfunction DoublyLinkedList() {\n this.head = undefined;\n this.tail = undefined;\n this._length = 0;\n}\n\nObject.defineProperties(DoublyLinkedList.prototype, {\n length: {\n get: function () {\n return this._length;\n },\n },\n});\n\n/**\n * @private\n */\nfunction DoublyLinkedListNode(item, previous, next) {\n this.item = item;\n this.previous = previous;\n this.next = next;\n}\n\n/**\n * Adds the item to the end of the list\n * @param {*} [item]\n * @return {DoublyLinkedListNode}\n */\nDoublyLinkedList.prototype.add = function (item) {\n const node = new DoublyLinkedListNode(item, this.tail, undefined);\n\n if (defined(this.tail)) {\n this.tail.next = node;\n this.tail = node;\n } else {\n this.head = node;\n this.tail = node;\n }\n\n ++this._length;\n\n return node;\n};\n\nfunction remove(list, node) {\n if (defined(node.previous) && defined(node.next)) {\n node.previous.next = node.next;\n node.next.previous = node.previous;\n } else if (defined(node.previous)) {\n // Remove last node\n node.previous.next = undefined;\n list.tail = node.previous;\n } else if (defined(node.next)) {\n // Remove first node\n node.next.previous = undefined;\n list.head = node.next;\n } else {\n // Remove last node in the linked list\n list.head = undefined;\n list.tail = undefined;\n }\n\n node.next = undefined;\n node.previous = undefined;\n}\n\n/**\n * Removes the given node from the list\n * @param {DoublyLinkedListNode} node\n */\nDoublyLinkedList.prototype.remove = function (node) {\n if (!defined(node)) {\n return;\n }\n\n remove(this, node);\n\n --this._length;\n};\n\n/**\n * Moves nextNode after node\n * @param {DoublyLinkedListNode} node\n * @param {DoublyLinkedListNode} nextNode\n */\nDoublyLinkedList.prototype.splice = function (node, nextNode) {\n if (node === nextNode) {\n return;\n }\n\n // Remove nextNode, then insert after node\n remove(this, nextNode);\n\n const oldNodeNext = node.next;\n node.next = nextNode;\n\n // nextNode is the new tail\n if (this.tail === node) {\n this.tail = nextNode;\n } else {\n oldNodeNext.previous = nextNode;\n }\n\n nextNode.next = oldNodeNext;\n nextNode.previous = node;\n};\nexport default DoublyLinkedList;\n", "import defined from \"../Core/defined.js\";\nimport DoublyLinkedList from \"../Core/DoublyLinkedList.js\";\n\n/**\n * Stores tiles with content loaded.\n *\n * @private\n */\nfunction Cesium3DTilesetCache() {\n // [head, sentinel) -> tiles that weren't selected this frame and may be removed from the cache\n // (sentinel, tail] -> tiles that were selected this frame\n this._list = new DoublyLinkedList();\n this._sentinel = this._list.add();\n this._trimTiles = false;\n}\n\nCesium3DTilesetCache.prototype.reset = function () {\n // Move sentinel node to the tail so, at the start of the frame, all tiles\n // may be potentially replaced. Tiles are moved to the right of the sentinel\n // when they are selected so they will not be replaced.\n this._list.splice(this._list.tail, this._sentinel);\n};\n\nCesium3DTilesetCache.prototype.touch = function (tile) {\n const node = tile.cacheNode;\n if (defined(node)) {\n this._list.splice(this._sentinel, node);\n }\n};\n\nCesium3DTilesetCache.prototype.add = function (tile) {\n if (!defined(tile.cacheNode)) {\n tile.cacheNode = this._list.add(tile);\n }\n};\n\nCesium3DTilesetCache.prototype.unloadTile = function (\n tileset,\n tile,\n unloadCallback\n) {\n const node = tile.cacheNode;\n if (!defined(node)) {\n return;\n }\n\n this._list.remove(node);\n tile.cacheNode = undefined;\n unloadCallback(tileset, tile);\n};\n\nCesium3DTilesetCache.prototype.unloadTiles = function (\n tileset,\n unloadCallback\n) {\n const trimTiles = this._trimTiles;\n this._trimTiles = false;\n\n const list = this._list;\n\n // Traverse the list only to the sentinel since tiles/nodes to the\n // right of the sentinel were used this frame.\n //\n // The sub-list to the left of the sentinel is ordered from LRU to MRU.\n const sentinel = this._sentinel;\n let node = list.head;\n while (\n node !== sentinel &&\n (tileset.totalMemoryUsageInBytes > tileset.cacheBytes || trimTiles)\n ) {\n const tile = node.item;\n node = node.next;\n this.unloadTile(tileset, tile, unloadCallback);\n }\n};\n\nCesium3DTilesetCache.prototype.trim = function () {\n this._trimTiles = true;\n};\nexport default Cesium3DTilesetCache;\n", "import Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport CesiumMath from \"../Core/Math.js\";\n\n/**\n * A heatmap colorizer in a {@link Cesium3DTileset}. A tileset can colorize its visible tiles in a heatmap style.\n *\n * @alias Cesium3DTilesetHeatmap\n * @constructor\n * @private\n */\nfunction Cesium3DTilesetHeatmap(tilePropertyName) {\n /**\n * The tile variable to track for heatmap colorization.\n * Tile's will be colorized relative to the other visible tile's values for this variable.\n *\n * @type {string}\n */\n this.tilePropertyName = tilePropertyName;\n\n // Members that are updated every time a tile is colorized\n this._minimum = Number.MAX_VALUE;\n this._maximum = -Number.MAX_VALUE;\n\n // Members that are updated once every frame\n this._previousMinimum = Number.MAX_VALUE;\n this._previousMaximum = -Number.MAX_VALUE;\n\n // If defined uses a reference minimum maximum to colorize by instead of using last frames minimum maximum of rendered tiles.\n // For example, the _loadTimestamp can get a better colorization using setReferenceMinimumMaximum in order to take accurate colored timing diffs of various scenes.\n this._referenceMinimum = {};\n this._referenceMaximum = {};\n}\n\n/**\n * Convert to a usable heatmap value (i.e. a number). Ensures that tile values that aren't stored as numbers can be used for colorization.\n * @private\n */\nfunction getHeatmapValue(tileValue, tilePropertyName) {\n let value;\n if (tilePropertyName === \"_loadTimestamp\") {\n value = JulianDate.toDate(tileValue).getTime();\n } else {\n value = tileValue;\n }\n return value;\n}\n\n/**\n * Sets the reference minimum and maximum for the variable name. Converted to numbers before they are stored.\n *\n * @param {object} minimum The minimum reference value.\n * @param {object} maximum The maximum reference value.\n * @param {string} tilePropertyName The tile variable that will use these reference values when it is colorized.\n */\nCesium3DTilesetHeatmap.prototype.setReferenceMinimumMaximum = function (\n minimum,\n maximum,\n tilePropertyName\n) {\n this._referenceMinimum[tilePropertyName] = getHeatmapValue(\n minimum,\n tilePropertyName\n );\n this._referenceMaximum[tilePropertyName] = getHeatmapValue(\n maximum,\n tilePropertyName\n );\n};\n\nfunction getHeatmapValueAndUpdateMinimumMaximum(heatmap, tile) {\n const tilePropertyName = heatmap.tilePropertyName;\n if (defined(tilePropertyName)) {\n const heatmapValue = getHeatmapValue(\n tile[tilePropertyName],\n tilePropertyName\n );\n if (!defined(heatmapValue)) {\n heatmap.tilePropertyName = undefined;\n return heatmapValue;\n }\n heatmap._maximum = Math.max(heatmapValue, heatmap._maximum);\n heatmap._minimum = Math.min(heatmapValue, heatmap._minimum);\n return heatmapValue;\n }\n}\n\nconst heatmapColors = [\n new Color(0.1, 0.1, 0.1, 1), // Dark Gray\n new Color(0.153, 0.278, 0.878, 1), // Blue\n new Color(0.827, 0.231, 0.49, 1), // Pink\n new Color(0.827, 0.188, 0.22, 1), // Red\n new Color(1.0, 0.592, 0.259, 1), // Orange\n new Color(1.0, 0.843, 0.0, 1),\n]; // Yellow\n/**\n * Colorize the tile in heat map style based on where it lies within the minimum maximum window.\n * Heatmap colors are black, blue, pink, red, orange, yellow. 'Cold' or low numbers will be black and blue, 'Hot' or high numbers will be orange and yellow,\n * @param {Cesium3DTile} tile The tile to colorize relative to last frame's minimum and maximum values of all visible tiles.\n * @param {FrameState} frameState The frame state.\n */\nCesium3DTilesetHeatmap.prototype.colorize = function (tile, frameState) {\n const tilePropertyName = this.tilePropertyName;\n if (\n !defined(tilePropertyName) ||\n !tile.contentAvailable ||\n tile._selectedFrame !== frameState.frameNumber\n ) {\n return;\n }\n\n const heatmapValue = getHeatmapValueAndUpdateMinimumMaximum(this, tile);\n const minimum = this._previousMinimum;\n const maximum = this._previousMaximum;\n\n if (minimum === Number.MAX_VALUE || maximum === -Number.MAX_VALUE) {\n return;\n }\n\n // Shift the minimum maximum window down to 0\n const shiftedMax = maximum - minimum + CesiumMath.EPSILON7; // Prevent divide by 0\n const shiftedValue = CesiumMath.clamp(\n heatmapValue - minimum,\n 0.0,\n shiftedMax\n );\n\n // Get position between minimum and maximum and convert that to a position in the color array\n const zeroToOne = shiftedValue / shiftedMax;\n const lastIndex = heatmapColors.length - 1.0;\n const colorPosition = zeroToOne * lastIndex;\n\n // Take floor and ceil of the value to get the two colors to lerp between, lerp using the fractional portion\n const colorPositionFloor = Math.floor(colorPosition);\n const colorPositionCeil = Math.ceil(colorPosition);\n const t = colorPosition - colorPositionFloor;\n const colorZero = heatmapColors[colorPositionFloor];\n const colorOne = heatmapColors[colorPositionCeil];\n\n // Perform the lerp\n const finalColor = Color.clone(Color.WHITE);\n finalColor.red = CesiumMath.lerp(colorZero.red, colorOne.red, t);\n finalColor.green = CesiumMath.lerp(colorZero.green, colorOne.green, t);\n finalColor.blue = CesiumMath.lerp(colorZero.blue, colorOne.blue, t);\n tile._debugColor = finalColor;\n};\n\n/**\n * Resets the tracked minimum maximum values for heatmap colorization. Happens right before tileset traversal.\n */\nCesium3DTilesetHeatmap.prototype.resetMinimumMaximum = function () {\n // For heat map colorization\n const tilePropertyName = this.tilePropertyName;\n if (defined(tilePropertyName)) {\n const referenceMinimum = this._referenceMinimum[tilePropertyName];\n const referenceMaximum = this._referenceMaximum[tilePropertyName];\n const useReference = defined(referenceMinimum) && defined(referenceMaximum);\n this._previousMinimum = useReference ? referenceMinimum : this._minimum;\n this._previousMaximum = useReference ? referenceMaximum : this._maximum;\n this._minimum = Number.MAX_VALUE;\n this._maximum = -Number.MAX_VALUE;\n }\n};\nexport default Cesium3DTilesetHeatmap;\n", "import defined from \"../Core/defined.js\";\n\n/**\n * @private\n */\nfunction Cesium3DTilesetStatistics() {\n // Rendering statistics\n this.selected = 0;\n this.visited = 0;\n // Loading statistics\n this.numberOfCommands = 0;\n this.numberOfAttemptedRequests = 0;\n this.numberOfPendingRequests = 0;\n this.numberOfTilesProcessing = 0;\n this.numberOfTilesWithContentReady = 0; // Number of tiles with content loaded, does not include empty tiles\n this.numberOfTilesTotal = 0; // Number of tiles in tileset JSON (and other tileset JSON files as they are loaded)\n this.numberOfLoadedTilesTotal = 0; // Running total of loaded tiles for the lifetime of the session\n // Features statistics\n this.numberOfFeaturesSelected = 0; // Number of features rendered\n this.numberOfFeaturesLoaded = 0; // Number of features in memory\n this.numberOfPointsSelected = 0;\n this.numberOfPointsLoaded = 0;\n this.numberOfTrianglesSelected = 0;\n // Styling statistics\n this.numberOfTilesStyled = 0;\n this.numberOfFeaturesStyled = 0;\n // Optimization statistics\n this.numberOfTilesCulledWithChildrenUnion = 0;\n // Memory statistics\n this.geometryByteLength = 0;\n this.texturesByteLength = 0;\n this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for\n}\n\nCesium3DTilesetStatistics.prototype.clear = function () {\n this.selected = 0;\n this.visited = 0;\n this.numberOfCommands = 0;\n this.numberOfAttemptedRequests = 0;\n this.numberOfFeaturesSelected = 0;\n this.numberOfPointsSelected = 0;\n this.numberOfTrianglesSelected = 0;\n this.numberOfTilesStyled = 0;\n this.numberOfFeaturesStyled = 0;\n this.numberOfTilesCulledWithChildrenUnion = 0;\n};\n\nfunction updatePointAndFeatureCounts(statistics, content, decrement, load) {\n const contents = content.innerContents;\n const pointsLength = content.pointsLength;\n const trianglesLength = content.trianglesLength;\n const featuresLength = content.featuresLength;\n const geometryByteLength = content.geometryByteLength;\n const texturesByteLength = content.texturesByteLength;\n const batchTableByteLength = content.batchTableByteLength;\n\n if (load) {\n statistics.numberOfFeaturesLoaded += decrement\n ? -featuresLength\n : featuresLength;\n statistics.numberOfPointsLoaded += decrement ? -pointsLength : pointsLength;\n statistics.geometryByteLength += decrement\n ? -geometryByteLength\n : geometryByteLength;\n statistics.texturesByteLength += decrement\n ? -texturesByteLength\n : texturesByteLength;\n statistics.batchTableByteLength += decrement\n ? -batchTableByteLength\n : batchTableByteLength;\n } else {\n statistics.numberOfFeaturesSelected += decrement\n ? -featuresLength\n : featuresLength;\n statistics.numberOfPointsSelected += decrement\n ? -pointsLength\n : pointsLength;\n statistics.numberOfTrianglesSelected += decrement\n ? -trianglesLength\n : trianglesLength;\n }\n\n if (defined(contents)) {\n const length = contents.length;\n for (let i = 0; i < length; ++i) {\n updatePointAndFeatureCounts(statistics, contents[i], decrement, load);\n }\n }\n}\n\nCesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (\n content\n) {\n updatePointAndFeatureCounts(this, content, false, false);\n};\n\nCesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {\n updatePointAndFeatureCounts(this, content, false, true);\n};\n\nCesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {\n updatePointAndFeatureCounts(this, content, true, true);\n};\n\nCesium3DTilesetStatistics.clone = function (statistics, result) {\n result.selected = statistics.selected;\n result.visited = statistics.visited;\n result.numberOfCommands = statistics.numberOfCommands;\n result.selected = statistics.selected;\n result.numberOfAttemptedRequests = statistics.numberOfAttemptedRequests;\n result.numberOfPendingRequests = statistics.numberOfPendingRequests;\n result.numberOfTilesProcessing = statistics.numberOfTilesProcessing;\n result.numberOfTilesWithContentReady =\n statistics.numberOfTilesWithContentReady;\n result.numberOfTilesTotal = statistics.numberOfTilesTotal;\n result.numberOfFeaturesSelected = statistics.numberOfFeaturesSelected;\n result.numberOfFeaturesLoaded = statistics.numberOfFeaturesLoaded;\n result.numberOfPointsSelected = statistics.numberOfPointsSelected;\n result.numberOfPointsLoaded = statistics.numberOfPointsLoaded;\n result.numberOfTrianglesSelected = statistics.numberOfTrianglesSelected;\n result.numberOfTilesStyled = statistics.numberOfTilesStyled;\n result.numberOfFeaturesStyled = statistics.numberOfFeaturesStyled;\n result.numberOfTilesCulledWithChildrenUnion =\n statistics.numberOfTilesCulledWithChildrenUnion;\n result.geometryByteLength = statistics.geometryByteLength;\n result.texturesByteLength = statistics.texturesByteLength;\n result.batchTableByteLength = statistics.batchTableByteLength;\n};\nexport default Cesium3DTilesetStatistics;\n", "import defined from \"../Core/defined.js\";\n\n/**\n * @private\n */\nfunction Cesium3DTileStyleEngine() {\n this._style = undefined; // The style provided by the user\n this._styleDirty = false; // true when the style is reassigned\n this._lastStyleTime = 0; // The \"time\" when the last style was assigned\n}\n\nObject.defineProperties(Cesium3DTileStyleEngine.prototype, {\n style: {\n get: function () {\n return this._style;\n },\n set: function (value) {\n if (value === this._style) {\n return;\n }\n this._style = value;\n this._styleDirty = true;\n },\n },\n});\n\nCesium3DTileStyleEngine.prototype.makeDirty = function () {\n this._styleDirty = true;\n};\n\nCesium3DTileStyleEngine.prototype.resetDirty = function () {\n this._styleDirty = false;\n};\n\nCesium3DTileStyleEngine.prototype.applyStyle = function (tileset) {\n if (!defined(tileset.root)) {\n return;\n }\n\n if (defined(this._style) && !this._style._ready) {\n return;\n }\n\n const styleDirty = this._styleDirty;\n\n if (styleDirty) {\n // Increase \"time\", so the style is applied to all visible tiles\n ++this._lastStyleTime;\n }\n\n const lastStyleTime = this._lastStyleTime;\n const statistics = tileset._statistics;\n\n // If a new style was assigned, loop through all the visible tiles; otherwise, loop through\n // only the tiles that are newly visible, i.e., they are visible this frame, but were not\n // visible last frame. In many cases, the newly selected tiles list will be short or empty.\n const tiles = styleDirty\n ? tileset._selectedTiles\n : tileset._selectedTilesToStyle;\n // PERFORMANCE_IDEA: does mouse-over picking basically trash this? We need to style on\n // pick, for example, because a feature's show may be false.\n\n const length = tiles.length;\n for (let i = 0; i < length; ++i) {\n const tile = tiles[i];\n if (tile.lastStyleTime !== lastStyleTime) {\n // Apply the style to this tile if it wasn't already applied because:\n // 1) the user assigned a new style to the tileset\n // 2) this tile is now visible, but it wasn't visible when the style was first assigned\n const content = tile.content;\n tile.lastStyleTime = lastStyleTime;\n content.applyStyle(this._style);\n statistics.numberOfFeaturesStyled += content.featuresLength;\n ++statistics.numberOfTilesStyled;\n }\n }\n};\nexport default Cesium3DTileStyleEngine;\n", "import Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport defined from \"../Core/defined.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport ImplicitSubdivisionScheme from \"./ImplicitSubdivisionScheme.js\";\n\n/**\n * An ImplicitTileset is a simple struct that stores information about the\n * structure of a single implicit tileset. This includes template URIs for\n * locating resources, details from the implicit root tile (bounding volume,\n * geometricError, etc.), and details about the subtrees (e.g. subtreeLevels,\n * subdivisionScheme).\n *\n * @alias ImplicitTileset\n * @constructor\n *\n * @param {Resource} baseResource The base resource for the tileset\n * @param {object} tileJson The JSON header of the tile with either implicit tiling (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.\n * @param {MetadataSchema} [metadataSchema] The metadata schema containing the implicit tile metadata class.\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitTileset(baseResource, tileJson, metadataSchema) {\n const implicitTiling = hasExtension(tileJson, \"3DTILES_implicit_tiling\")\n ? tileJson.extensions[\"3DTILES_implicit_tiling\"]\n : tileJson.implicitTiling;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"implicitTiling\", implicitTiling);\n //>>includeEnd('debug');\n\n /**\n * The base resource for the tileset. This is stored here as it is needed\n * later when expanding Implicit3DTileContents so tile URLs are relative\n * to the tileset, not the subtree file.\n *\n * @type {Resource}\n * @readonly\n * @private\n */\n this.baseResource = baseResource;\n\n /**\n * The geometric error of the root tile\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.geometricError = tileJson.geometricError;\n\n /**\n * The metadata schema containing the implicit tile metadata class.\n *\n * @type {MetadataSchema|undefined}\n * @readonly\n * @private\n */\n this.metadataSchema = metadataSchema;\n\n const boundingVolume = tileJson.boundingVolume;\n if (\n !defined(boundingVolume.box) &&\n !defined(boundingVolume.region) &&\n !hasExtension(boundingVolume, \"3DTILES_bounding_volume_S2\") &&\n !hasExtension(boundingVolume, \"3DTILES_bounding_volume_cylinder\")\n ) {\n throw new RuntimeError(\n \"Only box, region, 3DTILES_bounding_volume_S2, and 3DTILES_bounding_volume_cylinder are supported for implicit tiling\"\n );\n }\n\n /**\n * The JSON representation of a bounding volume. This is either a box or a\n * region.\n *\n * @type {object}\n * @readonly\n * @private\n */\n this.boundingVolume = boundingVolume;\n\n /**\n * The refine strategy as a string, either 'ADD' or 'REPLACE'\n *\n * @type {string}\n * @readonly\n * @private\n */\n this.refine = tileJson.refine;\n\n /**\n * Template URI for the subtree resources, e.g.\n * https://example.com/{level}/{x}/{y}.subtree\n *\n * @type {Resource}\n * @readonly\n * @private\n */\n\n this.subtreeUriTemplate = new Resource({ url: implicitTiling.subtrees.uri });\n\n /**\n * Template URIs for locating content resources, e.g.\n * https://example.com/{level}/{x}/{y}.b3dm.\n *

\n * This is an array to support multiple contents.\n *

\n *\n * @type {Resource[]}\n * @readonly\n * @private\n */\n this.contentUriTemplates = [];\n\n /**\n * Store a copy of the content headers, so properties such as\n * extras or extensions are preserved when\n * {@link Cesium3DTile}s are created for each tile.\n *

\n * This is an array to support multiple contents.\n *

\n *\n * @type {Object[]}\n * @readonly\n * @private\n */\n this.contentHeaders = [];\n\n const contentHeaders = gatherContentHeaders(tileJson);\n for (let i = 0; i < contentHeaders.length; i++) {\n const contentHeader = contentHeaders[i];\n this.contentHeaders.push(clone(contentHeader, true));\n const contentResource = new Resource({ url: contentHeader.uri });\n this.contentUriTemplates.push(contentResource);\n }\n\n /**\n * The maximum number of contents as well as content availability bitstreams.\n * This is used for loop bounds when checking content availability.\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.contentCount = this.contentHeaders.length;\n\n /**\n * Stores a copy of the root implicit tile's JSON header. This is used\n * as a template for creating {@link Cesium3DTile}s. The following properties\n * are removed:\n *\n *
    \n *
  • tile.implicitTiling to prevent infinite loops of implicit tiling
  • \n *
  • tile.extensions[\"3DTILES_implicit_tiling\"], if used instead of tile.implicitTiling
  • \n *
  • tile.contents, since contents are handled separately
  • \n *
  • tile.content, if used instead of tile.contents
  • \n *
  • tile.extensions[\"3DTILES_multiple_contents\"], if used instead of tile.contents or tile.content
  • \n *
\n *\n * @type {object}\n * @readonly\n * @private\n */\n this.tileHeader = makeTileHeaderTemplate(tileJson);\n\n /**\n * The subdivision scheme for this implicit tileset; either OCTREE or QUADTREE\n *\n * @type {ImplicitSubdivisionScheme}\n * @readonly\n * @private\n */\n this.subdivisionScheme =\n ImplicitSubdivisionScheme[implicitTiling.subdivisionScheme];\n\n /**\n * The branching factor for this tileset. Either 4 for quadtrees or 8 for\n * octrees.\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.branchingFactor = ImplicitSubdivisionScheme.getBranchingFactor(\n this.subdivisionScheme\n );\n\n /**\n * How many distinct levels within each subtree. For example, a quadtree\n * with subtreeLevels = 2 will have 5 nodes per quadtree (1 root + 4 children)\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.subtreeLevels = implicitTiling.subtreeLevels;\n\n /**\n * The number of levels containing available tiles in the tileset.\n *\n * @type {number}\n * @readonly\n * @private\n */\n if (defined(implicitTiling.availableLevels)) {\n this.availableLevels = implicitTiling.availableLevels;\n } else {\n this.availableLevels = implicitTiling.maximumLevel + 1;\n }\n}\n\n/**\n * Gather JSON headers for all contents in the tile.\n * This handles both regular tiles and tiles with multiple contents, either\n * in the contents array (3D Tiles 1.1) or the `3DTILES_multiple_contents` extension\n *\n * @param {object} tileJson The JSON header of the tile with either implicit tiling (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.\n * @return {Object[]} An array of JSON headers for the contents of each tile\n * @private\n */\nfunction gatherContentHeaders(tileJson) {\n if (hasExtension(tileJson, \"3DTILES_multiple_contents\")) {\n const extension = tileJson.extensions[\"3DTILES_multiple_contents\"];\n return defined(extension.contents) ? extension.contents : extension.content;\n }\n\n if (defined(tileJson.contents)) {\n return tileJson.contents;\n }\n\n if (defined(tileJson.content)) {\n return [tileJson.content];\n }\n\n return [];\n}\n\nfunction makeTileHeaderTemplate(tileJson) {\n const template = clone(tileJson, true);\n\n // Remove the implicit tiling extension to prevent infinite loops,\n // as well as content-related properties since content is handled separately\n if (defined(template.extensions)) {\n delete template.extensions[\"3DTILES_implicit_tiling\"];\n delete template.extensions[\"3DTILES_multiple_contents\"];\n\n // if there are no other extensions, remove the extensions property to\n // keep each tile simple\n if (Object.keys(template.extensions).length === 0) {\n delete template.extensions;\n }\n }\n\n delete template.implicitTiling;\n delete template.contents;\n delete template.content;\n\n return template;\n}\n\nexport default ImplicitTileset;\n", "import Check from \"./Check.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Morton Order (aka Z-Order Curve) helper functions.\n * @see {@link https://en.wikipedia.org/wiki/Z-order_curve}\n *\n * @namespace MortonOrder\n * @private\n */\nconst MortonOrder = {};\n\n/**\n * Inserts one 0 bit of spacing between a number's bits. This is the opposite of removeOneSpacing.\n *\n * Example:\n * input: 6\n * input (binary): 110\n * output (binary): 10100\n * ^ ^ (added)\n * output: 20\n *\n * @private\n * @param {number} v A 16-bit unsigned integer.\n * @returns {number} A 32-bit unsigned integer.\n * @see {@link https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/}\n * @private\n */\nfunction insertOneSpacing(v) {\n v = (v ^ (v << 8)) & 0x00ff00ff;\n v = (v ^ (v << 4)) & 0x0f0f0f0f;\n v = (v ^ (v << 2)) & 0x33333333;\n v = (v ^ (v << 1)) & 0x55555555;\n return v;\n}\n\n/**\n * Inserts two 0 bits of spacing between a number's bits. This is the opposite of removeTwoSpacing.\n *\n * Example:\n * input: 6\n * input (binary): 110\n * output (binary): 1001000\n * ^^ ^^ (added)\n * output: 72\n *\n * @private\n * @param {number} v A 10-bit unsigned integer.\n * @returns {number} A 30-bit unsigned integer.\n * @see {@link https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/}\n */\nfunction insertTwoSpacing(v) {\n v = (v ^ (v << 16)) & 0x030000ff;\n v = (v ^ (v << 8)) & 0x0300f00f;\n v = (v ^ (v << 4)) & 0x030c30c3;\n v = (v ^ (v << 2)) & 0x09249249;\n return v;\n}\n\n/**\n * Removes one bit of spacing between bits. This is the opposite of insertOneSpacing.\n *\n * Example:\n * input: 20\n * input (binary): 10100\n * ^ ^ (removed)\n * output (binary): 110\n * output: 6\n *\n * @private\n * @param {number} v A 32-bit unsigned integer.\n * @returns {number} A 16-bit unsigned integer.\n * @see {@link https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/}\n */\nfunction removeOneSpacing(v) {\n v &= 0x55555555;\n v = (v ^ (v >> 1)) & 0x33333333;\n v = (v ^ (v >> 2)) & 0x0f0f0f0f;\n v = (v ^ (v >> 4)) & 0x00ff00ff;\n v = (v ^ (v >> 8)) & 0x0000ffff;\n return v;\n}\n\n/**\n * Removes two bits of spacing between bits. This is the opposite of insertTwoSpacing.\n *\n * Example:\n * input: 72\n * input (binary): 1001000\n * ^^ ^^ (removed)\n * output (binary): 110\n * output: 6\n *\n * @private\n * @param {number} v A 30-bit unsigned integer.\n * @returns {number} A 10-bit unsigned integer.\n * @see {@link https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/}\n */\nfunction removeTwoSpacing(v) {\n v &= 0x09249249;\n v = (v ^ (v >> 2)) & 0x030c30c3;\n v = (v ^ (v >> 4)) & 0x0300f00f;\n v = (v ^ (v >> 8)) & 0xff0000ff;\n v = (v ^ (v >> 16)) & 0x000003ff;\n return v;\n}\n\n/**\n * Computes the Morton index from 2D coordinates. This is equivalent to interleaving their bits.\n * The inputs must be 16-bit unsigned integers (resulting in 32-bit Morton index) due to 32-bit bitwise operator limitation in JavaScript.\n *\n * @param {number} x The X coordinate in the range [0, (2^16)-1].\n * @param {number} y The Y coordinate in the range [0, (2^16)-1].\n * @returns {number} The Morton index.\n * @private\n */\nMortonOrder.encode2D = function (x, y) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n if (x < 0 || x > 65535 || y < 0 || y > 65535) {\n throw new DeveloperError(\"inputs must be 16-bit unsigned integers\");\n }\n //>>includeEnd('debug');\n\n // Note: JavaScript bitwise operations return signed 32-bit integers, so the\n // final result needs to be reintepreted as an unsigned integer using >>> 0.\n // This is not needed for encode3D because the result is guaranteed to be at most\n // 30 bits and thus will always be interpreted as an unsigned value.\n return (insertOneSpacing(x) | (insertOneSpacing(y) << 1)) >>> 0;\n};\n\n/**\n * Computes the 2D coordinates from a Morton index. This is equivalent to deinterleaving their bits.\n * The input must be a 32-bit unsigned integer (resulting in 16 bits per coordinate) due to 32-bit bitwise operator limitation in JavaScript.\n *\n * @param {number} mortonIndex The Morton index in the range [0, (2^32)-1].\n * @param {number[]} [result] The array onto which to store the result.\n * @returns {number[]} An array containing the 2D coordinates correspoding to the Morton index.\n * @private\n */\nMortonOrder.decode2D = function (mortonIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"mortonIndex\", mortonIndex);\n if (mortonIndex < 0 || mortonIndex > 4294967295) {\n throw new DeveloperError(\"input must be a 32-bit unsigned integer\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Array(2);\n }\n\n result[0] = removeOneSpacing(mortonIndex);\n result[1] = removeOneSpacing(mortonIndex >> 1);\n return result;\n};\n\n/**\n * Computes the Morton index from 3D coordinates. This is equivalent to interleaving their bits.\n * The inputs must be 10-bit unsigned integers (resulting in 30-bit Morton index) due to 32-bit bitwise operator limitation in JavaScript.\n *\n * @param {number} x The X coordinate in the range [0, (2^10)-1].\n * @param {number} y The Y coordinate in the range [0, (2^10)-1].\n * @param {number} z The Z coordinate in the range [0, (2^10)-1].\n * @returns {number} The Morton index.\n * @private\n */\nMortonOrder.encode3D = function (x, y, z) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"x\", x);\n Check.typeOf.number(\"y\", y);\n Check.typeOf.number(\"z\", z);\n if (x < 0 || x > 1023 || y < 0 || y > 1023 || z < 0 || z > 1023) {\n throw new DeveloperError(\"inputs must be 10-bit unsigned integers\");\n }\n //>>includeEnd('debug');\n\n return (\n insertTwoSpacing(x) |\n (insertTwoSpacing(y) << 1) |\n (insertTwoSpacing(z) << 2)\n );\n};\n\n/**\n * Computes the 3D coordinates from a Morton index. This is equivalent to deinterleaving their bits.\n * The input must be a 30-bit unsigned integer (resulting in 10 bits per coordinate) due to 32-bit bitwise operator limitation in JavaScript.\n *\n * @param {number} mortonIndex The Morton index in the range [0, (2^30)-1].\n * @param {number[]} [result] The array onto which to store the result.\n * @returns {number[]} An array containing the 3D coordinates corresponding to the Morton index.\n * @private\n */\nMortonOrder.decode3D = function (mortonIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"mortonIndex\", mortonIndex);\n if (mortonIndex < 0 || mortonIndex > 1073741823) {\n throw new DeveloperError(\"input must be a 30-bit unsigned integer\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Array(3);\n }\n\n result[0] = removeTwoSpacing(mortonIndex);\n result[1] = removeTwoSpacing(mortonIndex >> 1);\n result[2] = removeTwoSpacing(mortonIndex >> 2);\n return result;\n};\n\nexport default MortonOrder;\n", "import CesiumMath from \"../Core/Math.js\";\nimport Check from \"../Core/Check.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport MortonOrder from \"../Core/MortonOrder.js\";\nimport ImplicitSubdivisionScheme from \"./ImplicitSubdivisionScheme.js\";\n\n/**\n * The coordinates for a tile in an implicit tileset. The coordinates\n * are (level, x, y) for quadtrees or (level, x, y, z) for octrees.\n *

\n * Level numbers are 0-indexed and typically start at the root of the implicit\n * tileset (the tile with either implicitTiling in its JSON (3D Tiles 1.1) or\n * the 3DTILES_implicit_tiling extension).\n * This object can also represent the relative offset from one set of coordinates\n * to another. See {@link ImplicitTileCoordinates#getOffsetCoordinates}. The term\n * local coordinates refers to coordinates that are relative to the root of a\n * subtree and the term global coordinates refers to coordinates relative to the\n * root of an implicit tileset.\n *

\n *

\n * For box bounding volumes, x, y, z increase along the +x, +y, and +z\n * directions defined by the half axes.\n *

\n *

\n * For region bounding volumes, x increases in the +longitude direction, y\n * increases in the +latitude direction, and z increases in the +height\n * direction.\n *

\n *

\n * Care must be taken when converting between implicit coordinates and Morton\n * indices because there is a 16-bit limit on {@link MortonOrder#encode2D} and\n * a 10-bit limit on {@link MortonOrder#encode3D}. Typically these conversions\n * should be done on local coordinates, not global coordinates, and the maximum\n * number of levels in the subtree should be 15 for quadtree and 9 for octree (to\n * account for the extra level needed by child subtree coordinates).\n *

\n *\n * @alias ImplicitTileCoordinates\n * @constructor\n *\n * @param {object} options An object with the following properties:\n * @param {ImplicitSubdivisionScheme} options.subdivisionScheme Whether the coordinates are for a quadtree or octree\n * @param {number} options.subtreeLevels The number of distinct levels within the coordinate's subtree\n * @param {number} options.level The level of a tile relative to the tile with the extension\n * @param {number} options.x The x coordinate of the tile\n * @param {number} options.y The y coordinate of the tile\n * @param {number} [options.z] The z coordinate of the tile. Only required when options.subdivisionScheme is ImplicitSubdivisionScheme.OCTREE\n * @private\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\nfunction ImplicitTileCoordinates(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"options.subdivisionScheme\", options.subdivisionScheme);\n Check.typeOf.number(\"options.subtreeLevels\", options.subtreeLevels);\n Check.typeOf.number(\"options.level\", options.level);\n Check.typeOf.number(\"options.x\", options.x);\n Check.typeOf.number(\"options.y\", options.y);\n if (options.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n Check.typeOf.number(\"options.z\", options.z);\n }\n // Check for values that are negative\n if (options.level < 0) {\n throw new DeveloperError(\"level must be non-negative\");\n }\n if (options.x < 0) {\n throw new DeveloperError(\"x must be non-negative\");\n }\n if (options.y < 0) {\n throw new DeveloperError(\"y must be non-negative\");\n }\n if (options.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n if (options.z < 0) {\n throw new DeveloperError(\"z must be non-negative\");\n }\n }\n\n // Check for values that are too large\n const dimensionAtLevel = 1 << options.level;\n if (options.x >= dimensionAtLevel) {\n throw new DeveloperError(\"x is out of range\");\n }\n if (options.y >= dimensionAtLevel) {\n throw new DeveloperError(\"y is out of range\");\n }\n if (options.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n if (options.z >= dimensionAtLevel) {\n throw new DeveloperError(\"z is out of range\");\n }\n }\n //>>includeEnd('debug');\n\n /**\n * Whether the tileset is a quadtree or octree\n *\n * @type {ImplicitSubdivisionScheme}\n * @readonly\n * @private\n */\n this.subdivisionScheme = options.subdivisionScheme;\n\n /**\n * The number of distinct levels within the coordinate's subtree\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.subtreeLevels = options.subtreeLevels;\n\n /**\n * Level of this tile, relative to the tile with implicit tiling in its JSON\n * (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.\n * Level numbers start at 0.\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.level = options.level;\n\n /**\n * X coordinate of this tile\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.x = options.x;\n\n /**\n * Y coordinate of this tile\n *\n * @type {number}\n * @readonly\n * @private\n */\n this.y = options.y;\n\n /**\n * Z coordinate of this tile. Only defined for octrees.\n *\n * @type {number|undefined}\n * @readonly\n * @private\n */\n this.z = undefined;\n if (options.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n this.z = options.z;\n }\n}\n\nObject.defineProperties(ImplicitTileCoordinates.prototype, {\n /**\n * An index in the range of [0, branchingFactor) that indicates\n * which child of the parent cell these coordinates correspond to.\n * This can be viewed as a morton index within the parent tile.\n *

\n * This is the last 3 bits of the morton index of the tile, but it can\n * be computed more directly by concatenating the bits [z0] y0 x0\n *

\n *\n * @type {number}\n * @readonly\n * @private\n */\n childIndex: {\n get: function () {\n let childIndex = 0;\n childIndex |= this.x & 1;\n childIndex |= (this.y & 1) << 1;\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n childIndex |= (this.z & 1) << 2;\n }\n\n return childIndex;\n },\n },\n\n /**\n * Get the Morton index for this tile within the current level by interleaving\n * the bits of the x, y and z coordinates.\n *\n * @type {number}\n * @readonly\n * @private\n */\n mortonIndex: {\n get: function () {\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n return MortonOrder.encode3D(this.x, this.y, this.z);\n }\n return MortonOrder.encode2D(this.x, this.y);\n },\n },\n\n /**\n * Get the tile index by adding the Morton index to the level offset\n *\n * @type {number}\n * @readonly\n * @private\n */\n tileIndex: {\n get: function () {\n const levelOffset =\n this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE\n ? // (8^N - 1) / (8-1)\n ((1 << (3 * this.level)) - 1) / 7\n : // (4^N - 1) / (4-1)\n ((1 << (2 * this.level)) - 1) / 3;\n\n const mortonIndex = this.mortonIndex;\n return levelOffset + mortonIndex;\n },\n },\n});\n\n/**\n * Check that the two coordinates are compatible\n * @param {ImplicitTileCoordinates} a\n * @param {ImplicitTileCoordinates} b\n * @private\n */\nfunction checkMatchingSubtreeShape(a, b) {\n if (a.subdivisionScheme !== b.subdivisionScheme) {\n throw new DeveloperError(\"coordinates must have same subdivisionScheme\");\n }\n if (a.subtreeLevels !== b.subtreeLevels) {\n throw new DeveloperError(\"coordinates must have same subtreeLevels\");\n }\n}\n\n/**\n * Compute the coordinates of a tile deeper in the tree with a (level, x, y, [z]) relative offset.\n *\n * @param {ImplicitTileCoordinates} offsetCoordinates The offset from the ancestor\n * @returns {ImplicitTileCoordinates} The coordinates of the descendant\n * @private\n */\nImplicitTileCoordinates.prototype.getDescendantCoordinates = function (\n offsetCoordinates\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"offsetCoordinates\", offsetCoordinates);\n checkMatchingSubtreeShape(this, offsetCoordinates);\n //>>includeEnd('debug');\n\n const descendantLevel = this.level + offsetCoordinates.level;\n const descendantX = (this.x << offsetCoordinates.level) + offsetCoordinates.x;\n const descendantY = (this.y << offsetCoordinates.level) + offsetCoordinates.y;\n\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n const descendantZ =\n (this.z << offsetCoordinates.level) + offsetCoordinates.z;\n\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: descendantLevel,\n x: descendantX,\n y: descendantY,\n z: descendantZ,\n });\n }\n\n // Quadtree\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: descendantLevel,\n x: descendantX,\n y: descendantY,\n });\n};\n\n/**\n * Compute the coordinates of a tile higher up in the tree by going up a number of levels.\n *\n * @param {number} offsetLevels The number of levels to go up in the tree\n * @returns {ImplicitTileCoordinates} The coordinates of the ancestor\n * @private\n */\nImplicitTileCoordinates.prototype.getAncestorCoordinates = function (\n offsetLevels\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"offsetLevels\", offsetLevels);\n if (offsetLevels < 0) {\n throw new DeveloperError(\"offsetLevels must be non-negative\");\n }\n if (offsetLevels > this.level) {\n throw new DeveloperError(\"ancestor cannot be above the tileset root\");\n }\n //>>includeEnd('debug');\n\n const divisor = 1 << offsetLevels;\n const ancestorLevel = this.level - offsetLevels;\n const ancestorX = Math.floor(this.x / divisor);\n const ancestorY = Math.floor(this.y / divisor);\n\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n const ancestorZ = Math.floor(this.z / divisor);\n\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: ancestorLevel,\n x: ancestorX,\n y: ancestorY,\n z: ancestorZ,\n });\n }\n\n // Quadtree\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: ancestorLevel,\n x: ancestorX,\n y: ancestorY,\n });\n};\n\n/**\n * Compute the (level, x, y, [z]) offset to a descendant\n *\n * @param {ImplicitTileCoordinates} descendantCoordinates The descendant coordinates\n * @returns {ImplicitTileCoordinates} The offset between the ancestor and the descendant\n */\nImplicitTileCoordinates.prototype.getOffsetCoordinates = function (\n descendantCoordinates\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"descendantCoordinates\", descendantCoordinates);\n if (\n !this.isEqual(descendantCoordinates) &&\n !this.isAncestor(descendantCoordinates)\n ) {\n throw new DeveloperError(\"this is not an ancestor of descendant\");\n }\n checkMatchingSubtreeShape(this, descendantCoordinates);\n //>>includeEnd('debug');\n\n const offsetLevel = descendantCoordinates.level - this.level;\n const dimensionAtOffsetLevel = 1 << offsetLevel;\n\n const offsetX = descendantCoordinates.x % dimensionAtOffsetLevel;\n const offsetY = descendantCoordinates.y % dimensionAtOffsetLevel;\n\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n const offsetZ = descendantCoordinates.z % dimensionAtOffsetLevel;\n\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: offsetLevel,\n x: offsetX,\n y: offsetY,\n z: offsetZ,\n });\n }\n\n // Quadtree\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: offsetLevel,\n x: offsetX,\n y: offsetY,\n });\n};\n\n/**\n * Given the morton index of the child, compute the coordinates of the child.\n * This is a special case of {@link ImplicitTileCoordinates#getDescendantCoordinates}.\n *\n * @param {number} childIndex The morton index of the child tile relative to its parent\n * @returns {ImplicitTileCoordinates} The tile coordinates of the child\n * @private\n */\nImplicitTileCoordinates.prototype.getChildCoordinates = function (childIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"childIndex\", childIndex);\n const branchingFactor = ImplicitSubdivisionScheme.getBranchingFactor(\n this.subdivisionScheme\n );\n if (childIndex < 0 || branchingFactor <= childIndex) {\n throw new DeveloperError(\n `childIndex must be at least 0 and less than ${branchingFactor}`\n );\n }\n //>>includeEnd('debug');\n\n const level = this.level + 1;\n const x = 2 * this.x + (childIndex % 2);\n const y = 2 * this.y + (Math.floor(childIndex / 2) % 2);\n\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n const z = 2 * this.z + (Math.floor(childIndex / 4) % 2);\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: level,\n x: x,\n y: y,\n z: z,\n });\n }\n\n // Quadtree\n return new ImplicitTileCoordinates({\n subdivisionScheme: this.subdivisionScheme,\n subtreeLevels: this.subtreeLevels,\n level: level,\n x: x,\n y: y,\n });\n};\n\n/**\n * Get the coordinates of the subtree that contains this tile. If the tile is\n * the root of the subtree, the root of the subtree is returned.\n *\n * @returns {ImplicitTileCoordinates} The subtree that contains this tile\n * @private\n */\nImplicitTileCoordinates.prototype.getSubtreeCoordinates = function () {\n return this.getAncestorCoordinates(this.level % this.subtreeLevels);\n};\n\n/**\n * Get the coordinates of the parent subtree that contains this tile\n *\n * @returns {ImplicitTileCoordinates} The parent subtree that contains this tile\n * @private\n */\nImplicitTileCoordinates.prototype.getParentSubtreeCoordinates = function () {\n return this.getAncestorCoordinates(\n (this.level % this.subtreeLevels) + this.subtreeLevels\n );\n};\n\n/**\n * Returns whether this tile is an ancestor of another tile\n *\n * @param {ImplicitTileCoordinates} descendantCoordinates the descendant coordinates\n * @returns {boolean} true if this tile is an ancestor of the other tile\n * @private\n */\nImplicitTileCoordinates.prototype.isAncestor = function (\n descendantCoordinates\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"descendantCoordinates\", descendantCoordinates);\n checkMatchingSubtreeShape(this, descendantCoordinates);\n //>>includeEnd('debug');\n\n const levelDifference = descendantCoordinates.level - this.level;\n if (levelDifference <= 0) {\n return false;\n }\n\n const ancestorX = descendantCoordinates.x >> levelDifference;\n const ancestorY = descendantCoordinates.y >> levelDifference;\n const isAncestorX = this.x === ancestorX;\n const isAncestorY = this.y === ancestorY;\n\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n const ancestorZ = descendantCoordinates.z >> levelDifference;\n const isAncestorZ = this.z === ancestorZ;\n return isAncestorX && isAncestorY && isAncestorZ;\n }\n\n // Quadtree\n return isAncestorX && isAncestorY;\n};\n\n/**\n * Returns whether the provided coordinates are equal to this coordinate\n *\n * @param {ImplicitTileCoordinates} otherCoordinates the other coordinates\n * @returns {boolean} true if the coordinates are equal\n * @private\n */\nImplicitTileCoordinates.prototype.isEqual = function (otherCoordinates) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"otherCoordinates\", otherCoordinates);\n //>>includeEnd('debug');\n\n return (\n this.subdivisionScheme === otherCoordinates.subdivisionScheme &&\n this.subtreeLevels === otherCoordinates.subtreeLevels &&\n this.level === otherCoordinates.level &&\n this.x === otherCoordinates.x &&\n this.y === otherCoordinates.y &&\n (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE\n ? this.z === otherCoordinates.z\n : true)\n );\n};\n\n/**\n * Returns whether this tile is the root of the implicit tileset\n *\n * @returns {boolean} true if this tile is the root\n * @private\n */\nImplicitTileCoordinates.prototype.isImplicitTilesetRoot = function () {\n return this.level === 0;\n};\n\n/**\n * Returns whether this tile is the root of the subtree\n *\n * @returns {boolean} true if this tile is the root of the subtree\n * @private\n */\nImplicitTileCoordinates.prototype.isSubtreeRoot = function () {\n return this.level % this.subtreeLevels === 0;\n};\n\n/**\n * Returns whether this tile is on the last row of tiles in the subtree\n *\n * @returns {boolean} true if this tile is on the last row of tiles in the subtree\n * @private\n */\nImplicitTileCoordinates.prototype.isBottomOfSubtree = function () {\n return this.level % this.subtreeLevels === this.subtreeLevels - 1;\n};\n\n/**\n * Get a dictionary of values for templating into an implicit template URI.\n *\n * @returns {object} An object suitable for use with {@link Resource#getDerivedResource}\n * @private\n */\nImplicitTileCoordinates.prototype.getTemplateValues = function () {\n const values = {\n level: this.level,\n x: this.x,\n y: this.y,\n };\n if (this.subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n values.z = this.z;\n }\n\n return values;\n};\n\nconst scratchCoordinatesArray = [0, 0, 0];\n\n/**\n * Given a level number, morton index, and whether the tileset is an\n * octree/quadtree, compute the (level, x, y, [z]) coordinates\n *\n * @param {ImplicitSubdivisionScheme} subdivisionScheme Whether the coordinates are for a quadtree or octree\n * @param {number} subtreeLevels The number of distinct levels within the coordinate's subtree\n * @param {number} level The level of the tree\n * @param {number} mortonIndex The morton index of the tile.\n * @returns {ImplicitTileCoordinates} The coordinates of the tile with the given Morton index\n * @private\n */\nImplicitTileCoordinates.fromMortonIndex = function (\n subdivisionScheme,\n subtreeLevels,\n level,\n mortonIndex\n) {\n let coordinatesArray;\n if (subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n coordinatesArray = MortonOrder.decode3D(\n mortonIndex,\n scratchCoordinatesArray\n );\n return new ImplicitTileCoordinates({\n subdivisionScheme: subdivisionScheme,\n subtreeLevels: subtreeLevels,\n level: level,\n x: coordinatesArray[0],\n y: coordinatesArray[1],\n z: coordinatesArray[2],\n });\n }\n\n coordinatesArray = MortonOrder.decode2D(mortonIndex, scratchCoordinatesArray);\n return new ImplicitTileCoordinates({\n subdivisionScheme: subdivisionScheme,\n subtreeLevels: subtreeLevels,\n level: level,\n x: coordinatesArray[0],\n y: coordinatesArray[1],\n });\n};\n\n/**\n * Given a tile index and whether the tileset is an octree/quadtree, compute\n * the (level, x, y, [z]) coordinates\n *\n * @param {ImplicitSubdivisionScheme} subdivisionScheme Whether the coordinates are for a quadtree or octree\n * @param {number} subtreeLevels The number of distinct levels within the coordinate's subtree\n * @param {number} tileIndex The tile's index\n * @returns {ImplicitTileCoordinates} The coordinates of the tile with the given tile index\n * @private\n */\nImplicitTileCoordinates.fromTileIndex = function (\n subdivisionScheme,\n subtreeLevels,\n tileIndex\n) {\n let level;\n let levelOffset;\n let mortonIndex;\n\n if (subdivisionScheme === ImplicitSubdivisionScheme.OCTREE) {\n // Node count up to octree level: (8^L - 1) / (8-1)\n // (8^L - 1) / (8-1) <= X < (8^(L+1) - 1) / (8-1)\n // 8^L <= (7x + 1) < 8^(L+1)\n // L <= log8(7x + 1) < L + 1\n // L = floor(log8(7x + 1))\n // L = floor(log2(7x + 1) / log2(8))\n // L = floor(log2(7x + 1) / 3)\n level = Math.floor(CesiumMath.log2(7 * tileIndex + 1) / 3);\n levelOffset = ((1 << (3 * level)) - 1) / 7;\n mortonIndex = tileIndex - levelOffset;\n } else {\n // Node count up to quadtree level: (4^L - 1) / (4-1)\n // (4^L - 1) / (4-1) <= X < (4^(L+1) - 1) / (4-1)\n // 4^L <= (3x + 1) < 4^(L+1)\n // L <= log4(3x + 1) < L + 1\n // L = floor(log4(3x + 1))\n // L = floor(log2(3x + 1) / log2(4))\n // L = floor(log2(3x + 1) / 2)\n level = Math.floor(CesiumMath.log2(3 * tileIndex + 1) / 2);\n levelOffset = ((1 << (2 * level)) - 1) / 3;\n mortonIndex = tileIndex - levelOffset;\n }\n\n return ImplicitTileCoordinates.fromMortonIndex(\n subdivisionScheme,\n subtreeLevels,\n level,\n mortonIndex\n );\n};\n\nexport default ImplicitTileCoordinates;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Intersect from \"../Core/Intersect.js\";\nimport Cesium3DTileOptimizationHint from \"./Cesium3DTileOptimizationHint.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\n\n/**\n * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render.\n * This type describes an interface and is not intended to be instantiated directly.\n *\n * @alias Cesium3DTilesetTraversal\n * @constructor\n * @abstract\n *\n * @see Cesium3DTilesetBaseTraversal\n * @see Cesium3DTilesetSkipTraversal\n * @see Cesium3DTilesetMostDetailedTraversal\n *\n * @private\n */\nfunction Cesium3DTilesetTraversal() {}\n\n/**\n * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render.\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.selectTiles = function (tileset, frameState) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * Sort by farthest child first since this is going on a stack\n *\n * @private\n * @param {Cesium3DTile} a\n * @param {Cesium3DTile} b\n * @returns {number}\n */\nCesium3DTilesetTraversal.sortChildrenByDistanceToCamera = function (a, b) {\n if (b._distanceToCamera === 0 && a._distanceToCamera === 0) {\n return b._centerZDepth - a._centerZDepth;\n }\n\n return b._distanceToCamera - a._distanceToCamera;\n};\n\n/**\n * Determine if a tile can and should be traversed for children tiles that\n * would contribute to rendering the current view\n *\n * @private\n * @param {Cesium3DTile} tile\n * @returns {boolean}\n */\nCesium3DTilesetTraversal.canTraverse = function (tile) {\n if (tile.children.length === 0) {\n return false;\n }\n if (tile.hasTilesetContent || tile.hasImplicitContent) {\n // Traverse external tileset to visit its root tile\n // Don't traverse if the subtree is expired because it will be destroyed\n return !tile.contentExpired;\n }\n return tile._screenSpaceError > tile.tileset.memoryAdjustedScreenSpaceError;\n};\n\n/**\n * Mark a tile as selected, and add it to the tileset's list of selected tiles\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.selectTile = function (tile, frameState) {\n if (tile.contentVisibility(frameState) === Intersect.OUTSIDE) {\n return;\n }\n\n const { content, tileset } = tile;\n if (content.featurePropertiesDirty) {\n // A feature's property in this tile changed, the tile needs to be re-styled.\n content.featurePropertiesDirty = false;\n tile.lastStyleTime = 0; // Force applying the style to this tile\n tileset._selectedTilesToStyle.push(tile);\n } else if (tile._selectedFrame < frameState.frameNumber - 1) {\n // Tile is newly selected; it is selected this frame, but was not selected last frame.\n tileset._selectedTilesToStyle.push(tile);\n }\n tile._selectedFrame = frameState.frameNumber;\n tileset._selectedTiles.push(tile);\n};\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.visitTile = function (tile, frameState) {\n ++tile.tileset._statistics.visited;\n tile._visitedFrame = frameState.frameNumber;\n};\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.touchTile = function (tile, frameState) {\n if (tile._touchedFrame === frameState.frameNumber) {\n // Prevents another pass from touching the frame again\n return;\n }\n tile.tileset._cache.touch(tile);\n tile._touchedFrame = frameState.frameNumber;\n};\n\n/**\n * Add a tile to the list of requested tiles, if appropriate\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.loadTile = function (tile, frameState) {\n const { tileset } = tile;\n if (\n tile._requestedFrame === frameState.frameNumber ||\n (!tile.hasUnloadedRenderableContent && !tile.contentExpired)\n ) {\n return;\n }\n\n if (!isOnScreenLongEnough(tile, frameState)) {\n return;\n }\n\n const cameraHasNotStoppedMovingLongEnough =\n frameState.camera.timeSinceMoved < tileset.foveatedTimeDelay;\n if (tile.priorityDeferred && cameraHasNotStoppedMovingLongEnough) {\n return;\n }\n\n tile._requestedFrame = frameState.frameNumber;\n tileset._requestedTiles.push(tile);\n};\n\n/**\n * Prevent unnecessary loads while camera is moving by getting the ratio of travel distance to tile size.\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction isOnScreenLongEnough(tile, frameState) {\n const { tileset } = tile;\n if (!tileset._cullRequestsWhileMoving) {\n return true;\n }\n\n const {\n positionWCDeltaMagnitude,\n positionWCDeltaMagnitudeLastFrame,\n } = frameState.camera;\n const deltaMagnitude =\n positionWCDeltaMagnitude !== 0.0\n ? positionWCDeltaMagnitude\n : positionWCDeltaMagnitudeLastFrame;\n\n // How do n frames of this movement compare to the tile's physical size.\n const diameter = Math.max(tile.boundingSphere.radius * 2.0, 1.0);\n const movementRatio =\n (tileset.cullRequestsWhileMovingMultiplier * deltaMagnitude) / diameter;\n\n return movementRatio < 1.0;\n}\n\n/**\n * Reset some of the tile's flags and re-evaluate visibility and priority\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nCesium3DTilesetTraversal.updateTile = function (tile, frameState) {\n updateTileVisibility(tile, frameState);\n tile.updateExpiration();\n\n tile._wasMinPriorityChild = false;\n tile._priorityHolder = tile;\n updateMinimumMaximumPriority(tile);\n\n // SkipLOD\n tile._shouldSelect = false;\n tile._finalResolution = true;\n};\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nfunction updateTileVisibility(tile, frameState) {\n tile.updateVisibility(frameState);\n\n if (!tile.isVisible) {\n return;\n }\n\n const hasChildren = tile.children.length > 0;\n if ((tile.hasTilesetContent || tile.hasImplicitContent) && hasChildren) {\n // Use the root tile's visibility instead of this tile's visibility.\n // The root tile may be culled by the children bounds optimization in which\n // case this tile should also be culled.\n const child = tile.children[0];\n updateTileVisibility(child, frameState);\n tile._visible = child._visible;\n return;\n }\n\n if (meetsScreenSpaceErrorEarly(tile, frameState)) {\n tile._visible = false;\n return;\n }\n\n // Optimization - if none of the tile's children are visible then this tile isn't visible\n const replace = tile.refine === Cesium3DTileRefine.REPLACE;\n const useOptimization =\n tile._optimChildrenWithinParent ===\n Cesium3DTileOptimizationHint.USE_OPTIMIZATION;\n if (replace && useOptimization && hasChildren) {\n if (!anyChildrenVisible(tile, frameState)) {\n ++tile.tileset._statistics.numberOfTilesCulledWithChildrenUnion;\n tile._visible = false;\n return;\n }\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction meetsScreenSpaceErrorEarly(tile, frameState) {\n const { parent, tileset } = tile;\n if (\n !defined(parent) ||\n parent.hasTilesetContent ||\n parent.hasImplicitContent ||\n parent.refine !== Cesium3DTileRefine.ADD\n ) {\n return false;\n }\n\n // Use parent's geometric error with child's box to see if the tile already meet the SSE\n return (\n tile.getScreenSpaceError(frameState, true) <=\n tileset.memoryAdjustedScreenSpaceError\n );\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction anyChildrenVisible(tile, frameState) {\n let anyVisible = false;\n const children = tile.children;\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n child.updateVisibility(frameState);\n anyVisible = anyVisible || child.isVisible;\n }\n return anyVisible;\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n */\nfunction updateMinimumMaximumPriority(tile) {\n const minimumPriority = tile.tileset._minimumPriority;\n const maximumPriority = tile.tileset._maximumPriority;\n const priorityHolder = tile._priorityHolder;\n\n maximumPriority.distance = Math.max(\n priorityHolder._distanceToCamera,\n maximumPriority.distance\n );\n minimumPriority.distance = Math.min(\n priorityHolder._distanceToCamera,\n minimumPriority.distance\n );\n maximumPriority.depth = Math.max(tile._depth, maximumPriority.depth);\n minimumPriority.depth = Math.min(tile._depth, minimumPriority.depth);\n maximumPriority.foveatedFactor = Math.max(\n priorityHolder._foveatedFactor,\n maximumPriority.foveatedFactor\n );\n minimumPriority.foveatedFactor = Math.min(\n priorityHolder._foveatedFactor,\n minimumPriority.foveatedFactor\n );\n maximumPriority.reverseScreenSpaceError = Math.max(\n tile._priorityReverseScreenSpaceError,\n maximumPriority.reverseScreenSpaceError\n );\n minimumPriority.reverseScreenSpaceError = Math.min(\n tile._priorityReverseScreenSpaceError,\n minimumPriority.reverseScreenSpaceError\n );\n}\n\nexport default Cesium3DTilesetTraversal;\n", "import Intersect from \"../Core/Intersect.js\";\nimport ManagedArray from \"../Core/ManagedArray.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\nimport Cesium3DTilesetTraversal from \"./Cesium3DTilesetTraversal.js\";\n\n/**\n * Traversal that loads all leaves that intersect the camera frustum.\n * Used to determine ray-tileset intersections during a pickFromRayMostDetailed call.\n *\n * @alias Cesium3DTilesetMostDetailedTraversal\n * @constructor\n *\n * @private\n */\nfunction Cesium3DTilesetMostDetailedTraversal() {}\n\nconst traversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n};\n\n/**\n * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render.\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n * @returns {boolean} Whether the appropriate tile is ready for picking\n */\nCesium3DTilesetMostDetailedTraversal.selectTiles = function (\n tileset,\n frameState\n) {\n tileset._selectedTiles.length = 0;\n tileset._requestedTiles.length = 0;\n tileset.hasMixedContent = false;\n\n let ready = true;\n\n const root = tileset.root;\n root.updateVisibility(frameState);\n\n if (!root.isVisible) {\n return ready;\n }\n\n const { touchTile, visitTile } = Cesium3DTilesetTraversal;\n\n const stack = traversal.stack;\n stack.push(root);\n\n while (stack.length > 0) {\n traversal.stackMaximumLength = Math.max(\n traversal.stackMaximumLength,\n stack.length\n );\n\n const tile = stack.pop();\n const add = tile.refine === Cesium3DTileRefine.ADD;\n const replace = tile.refine === Cesium3DTileRefine.REPLACE;\n const traverse = canTraverse(tile);\n\n if (traverse) {\n updateAndPushChildren(tile, stack, frameState);\n }\n\n if (add || (replace && !traverse)) {\n loadTile(tileset, tile);\n touchTile(tile, frameState);\n selectDesiredTile(tile, frameState);\n\n if (tile.hasRenderableContent && !tile.contentAvailable) {\n ready = false;\n }\n }\n\n visitTile(tile, frameState);\n }\n\n traversal.stack.trim(traversal.stackMaximumLength);\n\n return ready;\n};\n\nfunction canTraverse(tile) {\n if (tile.children.length === 0) {\n return false;\n }\n\n if (tile.hasTilesetContent || tile.hasImplicitContent) {\n // Traverse external tileset to visit its root tile\n // Don't traverse if the subtree is expired because it will be destroyed\n return !tile.contentExpired;\n }\n\n if (tile.hasEmptyContent) {\n return true;\n }\n\n return true; // Keep traversing until a leaf is hit\n}\n\nfunction updateAndPushChildren(tile, stack, frameState) {\n const { children } = tile;\n\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n child.updateVisibility(frameState);\n if (child.isVisible) {\n stack.push(child);\n }\n }\n}\n\nfunction loadTile(tileset, tile) {\n if (tile.hasUnloadedRenderableContent || tile.contentExpired) {\n tile._priority = 0.0; // Highest priority\n tileset._requestedTiles.push(tile);\n }\n}\n\nfunction selectDesiredTile(tile, frameState) {\n if (\n tile.contentAvailable &&\n tile.contentVisibility(frameState) !== Intersect.OUTSIDE\n ) {\n tile.tileset._selectedTiles.push(tile);\n }\n}\n\nexport default Cesium3DTilesetMostDetailedTraversal;\n", "import defined from \"../Core/defined.js\";\nimport ManagedArray from \"../Core/ManagedArray.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\nimport Cesium3DTilesetTraversal from \"./Cesium3DTilesetTraversal.js\";\n\n/**\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * A tile does not refine until all children are loaded.\n * This is the traditional replacement refinement approach and is called the base traversal.\n *\n * @alias Cesium3DTilesetBaseTraversal\n * @constructor\n *\n * @private\n */\nfunction Cesium3DTilesetBaseTraversal() {}\n\nconst traversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n};\n\nconst emptyTraversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n};\n\n/**\n * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render.\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nCesium3DTilesetBaseTraversal.selectTiles = function (tileset, frameState) {\n tileset._requestedTiles.length = 0;\n\n if (tileset.debugFreezeFrame) {\n return;\n }\n\n tileset._selectedTiles.length = 0;\n tileset._selectedTilesToStyle.length = 0;\n tileset._emptyTiles.length = 0;\n tileset.hasMixedContent = false;\n\n const root = tileset.root;\n Cesium3DTilesetTraversal.updateTile(root, frameState);\n\n if (!root.isVisible) {\n return;\n }\n\n if (\n root.getScreenSpaceError(frameState, true) <=\n tileset.memoryAdjustedScreenSpaceError\n ) {\n return;\n }\n\n executeTraversal(root, frameState);\n\n traversal.stack.trim(traversal.stackMaximumLength);\n emptyTraversal.stack.trim(emptyTraversal.stackMaximumLength);\n\n // Update the priority for any requests found during traversal\n // Update after traversal so that min and max values can be used to normalize priority values\n const requestedTiles = tileset._requestedTiles;\n for (let i = 0; i < requestedTiles.length; ++i) {\n requestedTiles[i].updatePriority();\n }\n};\n\n/**\n * Mark a tile as selected if it has content available.\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nfunction selectDesiredTile(tile, frameState) {\n if (tile.contentAvailable) {\n Cesium3DTilesetTraversal.selectTile(tile, frameState);\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {ManagedArray} stack\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction updateAndPushChildren(tile, stack, frameState) {\n const replace = tile.refine === Cesium3DTileRefine.REPLACE;\n const { tileset, children } = tile;\n const { updateTile, loadTile, touchTile } = Cesium3DTilesetTraversal;\n\n for (let i = 0; i < children.length; ++i) {\n updateTile(children[i], frameState);\n }\n\n // Sort by distance to take advantage of early Z and reduce artifacts for skipLevelOfDetail\n children.sort(Cesium3DTilesetTraversal.sortChildrenByDistanceToCamera);\n\n // For traditional replacement refinement only refine if all children are loaded.\n // Empty tiles are exempt since it looks better if children stream in as they are loaded to fill the empty space.\n const checkRefines = replace && tile.hasRenderableContent;\n let refines = true;\n\n let anyChildrenVisible = false;\n\n // Determining min child\n let minIndex = -1;\n let minimumPriority = Number.MAX_VALUE;\n\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n if (child.isVisible) {\n stack.push(child);\n if (child._foveatedFactor < minimumPriority) {\n minIndex = i;\n minimumPriority = child._foveatedFactor;\n }\n anyChildrenVisible = true;\n } else if (checkRefines || tileset.loadSiblings) {\n // Keep non-visible children loaded since they are still needed before the parent can refine.\n // Or loadSiblings is true so always load tiles regardless of visibility.\n if (child._foveatedFactor < minimumPriority) {\n minIndex = i;\n minimumPriority = child._foveatedFactor;\n }\n loadTile(child, frameState);\n touchTile(child, frameState);\n }\n if (checkRefines) {\n let childRefines;\n if (!child._inRequestVolume) {\n childRefines = false;\n } else if (!child.hasRenderableContent) {\n childRefines = executeEmptyTraversal(child, frameState);\n } else {\n childRefines = child.contentAvailable;\n }\n refines = refines && childRefines;\n }\n }\n\n if (!anyChildrenVisible) {\n refines = false;\n }\n\n if (minIndex !== -1 && replace) {\n // An ancestor will hold the _foveatedFactor and _distanceToCamera for descendants between itself and its highest priority descendant. Siblings of a min children along the way use this ancestor as their priority holder as well.\n // Priority of all tiles that refer to the _foveatedFactor and _distanceToCamera stored in the common ancestor will be differentiated based on their _depth.\n const minPriorityChild = children[minIndex];\n minPriorityChild._wasMinPriorityChild = true;\n const priorityHolder =\n (tile._wasMinPriorityChild || tile === tileset.root) &&\n minimumPriority <= tile._priorityHolder._foveatedFactor\n ? tile._priorityHolder\n : tile; // This is where priority dependency chains are wired up or started anew.\n priorityHolder._foveatedFactor = Math.min(\n minPriorityChild._foveatedFactor,\n priorityHolder._foveatedFactor\n );\n priorityHolder._distanceToCamera = Math.min(\n minPriorityChild._distanceToCamera,\n priorityHolder._distanceToCamera\n );\n\n for (let i = 0; i < children.length; ++i) {\n children[i]._priorityHolder = priorityHolder;\n }\n }\n\n return refines;\n}\n\n/**\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * A tile does not refine until all children are loaded.\n * This is the traditional replacement refinement approach and is called the base traversal.\n *\n * @private\n * @param {Cesium3DTile} root\n * @param {FrameState} frameState\n */\nfunction executeTraversal(root, frameState) {\n const { tileset } = root;\n\n const {\n canTraverse,\n loadTile,\n visitTile,\n touchTile,\n } = Cesium3DTilesetTraversal;\n const stack = traversal.stack;\n stack.push(root);\n\n while (stack.length > 0) {\n traversal.stackMaximumLength = Math.max(\n traversal.stackMaximumLength,\n stack.length\n );\n\n const tile = stack.pop();\n\n const parent = tile.parent;\n const parentRefines = !defined(parent) || parent._refines;\n\n tile._refines = canTraverse(tile)\n ? updateAndPushChildren(tile, stack, frameState) && parentRefines\n : false;\n\n const stoppedRefining = !tile._refines && parentRefines;\n\n if (!tile.hasRenderableContent) {\n // Add empty tile just to show its debug bounding volume\n // If the tile has tileset content load the external tileset\n tileset._emptyTiles.push(tile);\n loadTile(tile, frameState);\n if (stoppedRefining) {\n selectDesiredTile(tile, frameState);\n }\n } else if (tile.refine === Cesium3DTileRefine.ADD) {\n // Additive tiles are always loaded and selected\n selectDesiredTile(tile, frameState);\n loadTile(tile, frameState);\n } else if (tile.refine === Cesium3DTileRefine.REPLACE) {\n loadTile(tile, frameState);\n if (stoppedRefining) {\n selectDesiredTile(tile, frameState);\n }\n }\n\n visitTile(tile, frameState);\n touchTile(tile, frameState);\n }\n}\n\n/**\n * Depth-first traversal that checks if all nearest descendants with content are loaded.\n * Ignores visibility.\n *\n * @private\n * @param {Cesium3DTile} root\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction executeEmptyTraversal(root, frameState) {\n const {\n canTraverse,\n updateTile,\n loadTile,\n touchTile,\n } = Cesium3DTilesetTraversal;\n let allDescendantsLoaded = true;\n const stack = emptyTraversal.stack;\n stack.push(root);\n\n while (stack.length > 0) {\n emptyTraversal.stackMaximumLength = Math.max(\n emptyTraversal.stackMaximumLength,\n stack.length\n );\n\n const tile = stack.pop();\n const children = tile.children;\n const childrenLength = children.length;\n\n // Only traverse if the tile is empty - traversal stops at descendants with content\n const traverse = !tile.hasRenderableContent && canTraverse(tile);\n const emptyLeaf = !tile.hasRenderableContent && tile.children.length === 0;\n\n // Traversal stops but the tile does not have content yet\n // There will be holes if the parent tries to refine to its children, so don't refine\n // One exception: a parent may refine even if one of its descendants is an empty leaf\n if (!traverse && !tile.contentAvailable && !emptyLeaf) {\n allDescendantsLoaded = false;\n }\n\n updateTile(tile, frameState);\n if (!tile.isVisible) {\n // Load tiles that aren't visible since they are still needed for the parent to refine\n loadTile(tile, frameState);\n touchTile(tile, frameState);\n }\n\n if (traverse) {\n for (let i = 0; i < childrenLength; ++i) {\n const child = children[i];\n stack.push(child);\n }\n }\n }\n\n return allDescendantsLoaded;\n}\n\nexport default Cesium3DTilesetBaseTraversal;\n", "import defined from \"../Core/defined.js\";\nimport ManagedArray from \"../Core/ManagedArray.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\nimport Cesium3DTilesetTraversal from \"./Cesium3DTilesetTraversal.js\";\n\n/**\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * Allows for skipping levels of the tree and rendering children and parent tiles simultaneously.\n *\n * @alias Cesium3DTilesetSkipTraversal\n * @constructor\n *\n * @private\n */\nfunction Cesium3DTilesetSkipTraversal() {}\n\nconst traversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n};\n\nconst descendantTraversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n};\n\nconst selectionTraversal = {\n stack: new ManagedArray(),\n stackMaximumLength: 0,\n ancestorStack: new ManagedArray(),\n ancestorStackMaximumLength: 0,\n};\n\nconst descendantSelectionDepth = 2;\n\n/**\n * Traverses a {@link Cesium3DTileset} to determine which tiles to load and render.\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nCesium3DTilesetSkipTraversal.selectTiles = function (tileset, frameState) {\n tileset._requestedTiles.length = 0;\n\n if (tileset.debugFreezeFrame) {\n return;\n }\n\n tileset._selectedTiles.length = 0;\n tileset._selectedTilesToStyle.length = 0;\n tileset._emptyTiles.length = 0;\n tileset.hasMixedContent = false;\n\n const root = tileset.root;\n Cesium3DTilesetTraversal.updateTile(root, frameState);\n\n if (!root.isVisible) {\n return;\n }\n\n if (\n root.getScreenSpaceError(frameState, true) <=\n tileset.memoryAdjustedScreenSpaceError\n ) {\n return;\n }\n\n executeTraversal(root, frameState);\n traverseAndSelect(root, frameState);\n\n traversal.stack.trim(traversal.stackMaximumLength);\n descendantTraversal.stack.trim(descendantTraversal.stackMaximumLength);\n selectionTraversal.stack.trim(selectionTraversal.stackMaximumLength);\n selectionTraversal.ancestorStack.trim(\n selectionTraversal.ancestorStackMaximumLength\n );\n\n // Update the priority for any requests found during traversal\n // Update after traversal so that min and max values can be used to normalize priority values\n const requestedTiles = tileset._requestedTiles;\n for (let i = 0; i < requestedTiles.length; ++i) {\n requestedTiles[i].updatePriority();\n }\n};\n\n/**\n * Mark descendant tiles for rendering, and update as needed\n *\n * @private\n * @param {Cesium3DTile} root\n * @param {FrameState} frameState\n */\nfunction selectDescendants(root, frameState) {\n const { updateTile, touchTile, selectTile } = Cesium3DTilesetTraversal;\n const stack = descendantTraversal.stack;\n stack.push(root);\n while (stack.length > 0) {\n descendantTraversal.stackMaximumLength = Math.max(\n descendantTraversal.stackMaximumLength,\n stack.length\n );\n const tile = stack.pop();\n const children = tile.children;\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n if (child.isVisible) {\n if (child.contentAvailable) {\n updateTile(child, frameState);\n touchTile(child, frameState);\n selectTile(child, frameState);\n } else if (child._depth - root._depth < descendantSelectionDepth) {\n // Continue traversing, but not too far\n stack.push(child);\n }\n }\n }\n }\n}\n\n/**\n * Mark a tile as selected if it has content available.\n * If its content is not available, and we are skipping levels of detail,\n * select an ancestor or descendant tile instead\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nfunction selectDesiredTile(tile, frameState) {\n // If this tile is not loaded attempt to select its ancestor instead\n const loadedTile = tile.contentAvailable\n ? tile\n : tile._ancestorWithContentAvailable;\n if (defined(loadedTile)) {\n // Tiles will actually be selected in traverseAndSelect\n loadedTile._shouldSelect = true;\n } else {\n // If no ancestors are ready traverse down and select tiles to minimize empty regions.\n // This happens often for immediatelyLoadDesiredLevelOfDetail where parent tiles are not necessarily loaded before zooming out.\n selectDescendants(tile, frameState);\n }\n}\n\n/**\n * Update links to the ancestor tiles that have content\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {FrameState} frameState\n */\nfunction updateTileAncestorContentLinks(tile, frameState) {\n tile._ancestorWithContent = undefined;\n tile._ancestorWithContentAvailable = undefined;\n\n const { parent } = tile;\n if (!defined(parent)) {\n return;\n }\n const parentHasContent =\n !parent.hasUnloadedRenderableContent ||\n parent._requestedFrame === frameState.frameNumber;\n\n // ancestorWithContent is an ancestor that has content or has the potential to have\n // content. Used in conjunction with tileset.skipLevels to know when to skip a tile.\n tile._ancestorWithContent = parentHasContent\n ? parent\n : parent._ancestorWithContent;\n\n // ancestorWithContentAvailable is an ancestor that is rendered if a desired tile is not loaded\n tile._ancestorWithContentAvailable = parent.contentAvailable\n ? parent\n : parent._ancestorWithContentAvailable;\n}\n\n/**\n * Determine if a tile has reached the limit of level of detail skipping.\n * If so, it should _not_ be skipped: it should be loaded and rendered\n *\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n * @returns {boolean} true if this tile should not be skipped\n */\nfunction reachedSkippingThreshold(tileset, tile) {\n const ancestor = tile._ancestorWithContent;\n return (\n !tileset.immediatelyLoadDesiredLevelOfDetail &&\n (tile._priorityProgressiveResolutionScreenSpaceErrorLeaf ||\n (defined(ancestor) &&\n tile._screenSpaceError <\n ancestor._screenSpaceError / tileset.skipScreenSpaceErrorFactor &&\n tile._depth > ancestor._depth + tileset.skipLevels))\n );\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {ManagedArray} stack\n * @param {FrameState} frameState\n * @returns {boolean}\n */\nfunction updateAndPushChildren(tile, stack, frameState) {\n const { tileset, children } = tile;\n const { updateTile, loadTile, touchTile } = Cesium3DTilesetTraversal;\n\n for (let i = 0; i < children.length; ++i) {\n updateTile(children[i], frameState);\n }\n\n // Sort by distance to take advantage of early Z and reduce artifacts\n children.sort(Cesium3DTilesetTraversal.sortChildrenByDistanceToCamera);\n\n let anyChildrenVisible = false;\n\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n if (child.isVisible) {\n stack.push(child);\n anyChildrenVisible = true;\n } else if (tileset.loadSiblings) {\n loadTile(child, frameState);\n touchTile(child, frameState);\n }\n }\n\n return anyChildrenVisible;\n}\n\n/**\n * Determine if a tile is part of the base traversal.\n * If not, this tile could be considered for level of detail skipping\n *\n * @private\n * @param {Cesium3DTile} tile\n * @param {number} baseScreenSpaceError\n * @returns {boolean}\n */\nfunction inBaseTraversal(tile, baseScreenSpaceError) {\n const { tileset } = tile;\n if (tileset.immediatelyLoadDesiredLevelOfDetail) {\n return false;\n }\n if (!defined(tile._ancestorWithContent)) {\n // Include root or near-root tiles in the base traversal so there is something to select up to\n return true;\n }\n if (tile._screenSpaceError === 0.0) {\n // If a leaf, use parent's SSE\n return tile.parent._screenSpaceError > baseScreenSpaceError;\n }\n return tile._screenSpaceError > baseScreenSpaceError;\n}\n\n/**\n * Depth-first traversal that traverses all visible tiles and marks tiles for selection.\n * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,\n * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree\n * and rendering children and parent tiles simultaneously.\n *\n * @private\n * @param {Cesium3DTile} root\n * @param {FrameState} frameState\n */\nfunction executeTraversal(root, frameState) {\n const { tileset } = root;\n const baseScreenSpaceError = tileset.immediatelyLoadDesiredLevelOfDetail\n ? Number.MAX_VALUE\n : Math.max(\n tileset.baseScreenSpaceError,\n tileset.memoryAdjustedScreenSpaceError\n );\n const {\n canTraverse,\n loadTile,\n visitTile,\n touchTile,\n } = Cesium3DTilesetTraversal;\n const stack = traversal.stack;\n stack.push(root);\n\n while (stack.length > 0) {\n traversal.stackMaximumLength = Math.max(\n traversal.stackMaximumLength,\n stack.length\n );\n\n const tile = stack.pop();\n\n updateTileAncestorContentLinks(tile, frameState);\n const parent = tile.parent;\n const parentRefines = !defined(parent) || parent._refines;\n\n tile._refines = canTraverse(tile)\n ? updateAndPushChildren(tile, stack, frameState) && parentRefines\n : false;\n\n const stoppedRefining = !tile._refines && parentRefines;\n\n if (!tile.hasRenderableContent) {\n // Add empty tile just to show its debug bounding volume\n // If the tile has tileset content load the external tileset\n // If the tile cannot refine further select its nearest loaded ancestor\n tileset._emptyTiles.push(tile);\n loadTile(tile, frameState);\n if (stoppedRefining) {\n selectDesiredTile(tile, frameState);\n }\n } else if (tile.refine === Cesium3DTileRefine.ADD) {\n // Additive tiles are always loaded and selected\n selectDesiredTile(tile, frameState);\n loadTile(tile, frameState);\n } else if (tile.refine === Cesium3DTileRefine.REPLACE) {\n if (inBaseTraversal(tile, baseScreenSpaceError)) {\n // Always load tiles in the base traversal\n // Select tiles that can't refine further\n loadTile(tile, frameState);\n if (stoppedRefining) {\n selectDesiredTile(tile, frameState);\n }\n } else if (stoppedRefining) {\n // In skip traversal, load and select tiles that can't refine further\n selectDesiredTile(tile, frameState);\n loadTile(tile, frameState);\n } else if (reachedSkippingThreshold(tileset, tile)) {\n // In skip traversal, load tiles that aren't skipped\n loadTile(tile, frameState);\n }\n }\n\n visitTile(tile, frameState);\n touchTile(tile, frameState);\n }\n}\n\n/**\n * Traverse the tree and check if their selected frame is the current frame. If so, add it to a selection queue.\n * This is a preorder traversal so children tiles are selected before ancestor tiles.\n *\n * The reason for the preorder traversal is so that tiles can easily be marked with their\n * selection depth. A tile's _selectionDepth is its depth in the tree where all non-selected tiles are removed.\n * This property is important for use in the stencil test because we want to render deeper tiles on top of their\n * ancestors. If a tileset is very deep, the depth is unlikely to fit into the stencil buffer.\n *\n * We want to select children before their ancestors because there is no guarantee on the relationship between\n * the children's z-depth and the ancestor's z-depth. We cannot rely on Z because we want the child to appear on top\n * of ancestor regardless of true depth. The stencil tests used require children to be drawn first.\n *\n * NOTE: 3D Tiles uses 3 bits from the stencil buffer meaning this will not work when there is a chain of\n * selected tiles that is deeper than 7. This is not very likely.\n *\n * @private\n * @param {Cesium3DTile} root\n * @param {FrameState} frameState\n */\nfunction traverseAndSelect(root, frameState) {\n const { selectTile, canTraverse } = Cesium3DTilesetTraversal;\n const { stack, ancestorStack } = selectionTraversal;\n let lastAncestor;\n\n stack.push(root);\n\n while (stack.length > 0 || ancestorStack.length > 0) {\n selectionTraversal.stackMaximumLength = Math.max(\n selectionTraversal.stackMaximumLength,\n stack.length\n );\n selectionTraversal.ancestorStackMaximumLength = Math.max(\n selectionTraversal.ancestorStackMaximumLength,\n ancestorStack.length\n );\n\n if (ancestorStack.length > 0) {\n const waitingTile = ancestorStack.peek();\n if (waitingTile._stackLength === stack.length) {\n ancestorStack.pop();\n if (waitingTile !== lastAncestor) {\n waitingTile._finalResolution = false;\n }\n selectTile(waitingTile, frameState);\n continue;\n }\n }\n\n const tile = stack.pop();\n if (!defined(tile)) {\n // stack is empty but ancestorStack isn't\n continue;\n }\n\n const traverse = canTraverse(tile);\n\n if (tile._shouldSelect) {\n if (tile.refine === Cesium3DTileRefine.ADD) {\n selectTile(tile, frameState);\n } else {\n tile._selectionDepth = ancestorStack.length;\n if (tile._selectionDepth > 0) {\n tile.tileset.hasMixedContent = true;\n }\n lastAncestor = tile;\n if (!traverse) {\n selectTile(tile, frameState);\n continue;\n }\n ancestorStack.push(tile);\n tile._stackLength = stack.length;\n }\n }\n\n if (traverse) {\n const children = tile.children;\n for (let i = 0; i < children.length; ++i) {\n const child = children[i];\n if (child.isVisible) {\n stack.push(child);\n }\n }\n }\n }\n}\n\nexport default Cesium3DTilesetSkipTraversal;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport clone from \"../Core/clone.js\";\nimport Color from \"../Core/Color.js\";\nimport Credit from \"../Core/Credit.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport deprecationWarning from \"../Core/deprecationWarning.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Event from \"../Core/Event.js\";\nimport ImageBasedLighting from \"./ImageBasedLighting.js\";\nimport IonResource from \"../Core/IonResource.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport ManagedArray from \"../Core/ManagedArray.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport ClearCommand from \"../Renderer/ClearCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport Axis from \"./Axis.js\";\nimport Cesium3DTile from \"./Cesium3DTile.js\";\nimport Cesium3DTileColorBlendMode from \"./Cesium3DTileColorBlendMode.js\";\nimport Cesium3DTileContentState from \"./Cesium3DTileContentState.js\";\nimport Cesium3DTilesetMetadata from \"./Cesium3DTilesetMetadata.js\";\nimport Cesium3DTileOptimizations from \"./Cesium3DTileOptimizations.js\";\nimport Cesium3DTilePass from \"./Cesium3DTilePass.js\";\nimport Cesium3DTileRefine from \"./Cesium3DTileRefine.js\";\nimport Cesium3DTilesetCache from \"./Cesium3DTilesetCache.js\";\nimport Cesium3DTilesetHeatmap from \"./Cesium3DTilesetHeatmap.js\";\nimport Cesium3DTilesetStatistics from \"./Cesium3DTilesetStatistics.js\";\nimport Cesium3DTileStyleEngine from \"./Cesium3DTileStyleEngine.js\";\nimport ClippingPlaneCollection from \"./ClippingPlaneCollection.js\";\nimport hasExtension from \"./hasExtension.js\";\nimport ImplicitTileset from \"./ImplicitTileset.js\";\nimport ImplicitTileCoordinates from \"./ImplicitTileCoordinates.js\";\nimport LabelCollection from \"./LabelCollection.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport PointCloudEyeDomeLighting from \"./PointCloudEyeDomeLighting.js\";\nimport PointCloudShading from \"./PointCloudShading.js\";\nimport ResourceCache from \"./ResourceCache.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport ShadowMode from \"./ShadowMode.js\";\nimport SplitDirection from \"./SplitDirection.js\";\nimport StencilConstants from \"./StencilConstants.js\";\nimport TileBoundingRegion from \"./TileBoundingRegion.js\";\nimport TileBoundingSphere from \"./TileBoundingSphere.js\";\nimport TileOrientedBoundingBox from \"./TileOrientedBoundingBox.js\";\nimport Cesium3DTilesetMostDetailedTraversal from \"./Cesium3DTilesetMostDetailedTraversal.js\";\nimport Cesium3DTilesetBaseTraversal from \"./Cesium3DTilesetBaseTraversal.js\";\nimport Cesium3DTilesetSkipTraversal from \"./Cesium3DTilesetSkipTraversal.js\";\n\n/**\n * @typedef {Object} Cesium3DTileset.ConstructorOptions\n *\n * Initialization options for the Cesium3DTileset constructor\n *\n * @property {boolean} [show=true] Determines if the tileset will be shown.\n * @property {Matrix4} [modelMatrix=Matrix4.IDENTITY] A 4x4 transformation matrix that transforms the tileset's root tile.\n * @property {Axis} [modelUpAxis=Axis.Y] Which axis is considered up when loading models for tile contents.\n * @property {Axis} [modelForwardAxis=Axis.X] Which axis is considered forward when loading models for tile contents.\n * @property {ShadowMode} [shadows=ShadowMode.ENABLED] Determines whether the tileset casts or receives shadows from light sources.\n * @property {number} [maximumScreenSpaceError=16] The maximum screen space error used to drive level of detail refinement.\n * @property {number} [maximumMemoryUsage=512] The maximum amount of memory in MB that can be used by the tileset. Deprecated.\n * @property {number} [cacheBytes=536870912] The size (in bytes) to which the tile cache will be trimmed, if the cache contains tiles not needed for the current view.\n * @property {number} [maximumCacheOverflowBytes=536870912] The maximum additional memory (in bytes) to allow for cache headroom, if more than {@link Cesium3DTileset#cacheBytes} are needed for the current view.\n * @property {boolean} [cullWithChildrenBounds=true] Optimization option. Whether to cull tiles using the union of their children bounding volumes.\n * @property {boolean} [cullRequestsWhileMoving=true] Optimization option. Don't request tiles that will likely be unused when they come back because of the camera's movement. This optimization only applies to stationary tilesets.\n * @property {number} [cullRequestsWhileMovingMultiplier=60.0] Optimization option. Multiplier used in culling requests while moving. Larger is more aggressive culling, smaller less aggressive culling.\n * @property {boolean} [preloadWhenHidden=false] Preload tiles when tileset.show is false. Loads tiles as if the tileset is visible but does not render them.\n * @property {boolean} [preloadFlightDestinations=true] Optimization option. Preload tiles at the camera's flight destination while the camera is in flight.\n * @property {boolean} [preferLeaves=false] Optimization option. Prefer loading of leaves first.\n * @property {boolean} [dynamicScreenSpaceError=false] Optimization option. Reduce the screen space error for tiles that are further away from the camera.\n * @property {number} [dynamicScreenSpaceErrorDensity=0.00278] Density used to adjust the dynamic screen space error, similar to fog density.\n * @property {number} [dynamicScreenSpaceErrorFactor=4.0] A factor used to increase the computed dynamic screen space error.\n * @property {number} [dynamicScreenSpaceErrorHeightFalloff=0.25] A ratio of the tileset's height at which the density starts to falloff.\n * @property {number} [progressiveResolutionHeightFraction=0.3] Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of progressiveResolutionHeightFraction*screenHeight will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load.\n * @property {boolean} [foveatedScreenSpaceError=true] Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the screen space error for tiles around the edge of the screen. Screen space error returns to normal once all the tiles in the center of the screen as determined by the {@link Cesium3DTileset#foveatedConeSize} are loaded.\n * @property {number} [foveatedConeSize=0.1] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the cone size that determines which tiles are deferred. Tiles that are inside this cone are loaded immediately. Tiles outside the cone are potentially deferred based on how far outside the cone they are and their screen space error. This is controlled by {@link Cesium3DTileset#foveatedInterpolationCallback} and {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation}. Setting this to 0.0 means the cone will be the line formed by the camera position and its view direction. Setting this to 1.0 means the cone encompasses the entire field of view of the camera, disabling the effect.\n * @property {number} [foveatedMinimumScreenSpaceErrorRelaxation=0.0] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the starting screen space error relaxation for tiles outside the foveated cone. The screen space error will be raised starting with tileset value up to {@link Cesium3DTileset#maximumScreenSpaceError} based on the provided {@link Cesium3DTileset#foveatedInterpolationCallback}.\n * @property {Cesium3DTileset.foveatedInterpolationCallback} [foveatedInterpolationCallback=Math.lerp] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how much to raise the screen space error for tiles outside the foveated cone, interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}\n * @property {number} [foveatedTimeDelay=0.2] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how long in seconds to wait after the camera stops moving before deferred tiles start loading in. This time delay prevents requesting tiles around the edges of the screen when the camera is moving. Setting this to 0.0 will immediately request all tiles in any given view.\n * @property {boolean} [skipLevelOfDetail=false] Optimization option. Determines if level of detail skipping should be applied during the traversal.\n * @property {number} [baseScreenSpaceError=1024] When skipLevelOfDetail is true, the screen space error that must be reached before skipping levels of detail.\n * @property {number} [skipScreenSpaceErrorFactor=16] When skipLevelOfDetail is true, a multiplier defining the minimum screen space error to skip. Used in conjunction with skipLevels to determine which tiles to load.\n * @property {number} [skipLevels=1] When skipLevelOfDetail is true, a constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped. Used in conjunction with skipScreenSpaceErrorFactor to determine which tiles to load.\n * @property {boolean} [immediatelyLoadDesiredLevelOfDetail=false] When skipLevelOfDetail is true, only tiles that meet the maximum screen space error will ever be downloaded. Skipping factors are ignored and just the desired tiles are loaded.\n * @property {boolean} [loadSiblings=false] When skipLevelOfDetail is true, determines whether siblings of visible tiles are always downloaded during traversal.\n * @property {ClippingPlaneCollection} [clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.\n * @property {ClassificationType} [classificationType] Determines whether terrain, 3D Tiles or both will be classified by this tileset. See {@link Cesium3DTileset#classificationType} for details about restrictions and limitations.\n * @property {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid determining the size and shape of the globe.\n * @property {object} [pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation based on geometric error and lighting.\n * @property {Cartesian3} [lightColor] The light color when shading models. When undefined the scene's light color is used instead.\n * @property {ImageBasedLighting} [imageBasedLighting] The properties for managing image-based lighting for this tileset.\n * @property {boolean} [backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the glTF material's doubleSided property; when false, back face culling is disabled.\n * @property {boolean} [enableShowOutline=true] Whether to enable outlines for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set to false to avoid the additional processing of geometry at load time. When false, the showOutlines and outlineColor options are ignored.\n * @property {boolean} [showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.\n * @property {Color} [outlineColor=Color.BLACK] The color to use when rendering outlines.\n * @property {boolean} [vectorClassificationOnly=false] Indicates that only the tileset's vector tiles should be used for classification.\n * @property {boolean} [vectorKeepDecodedPositions=false] Whether vector tiles should keep decoded positions in memory. This is used with {@link Cesium3DTileFeature.getPolylinePositions}.\n * @property {string|number} [featureIdLabel=\"featureId_0\"] Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or \"featureId_N\" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled \"featureId_N\" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string \"featureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @property {string|number} [instanceFeatureIdLabel=\"instanceFeatureId_0\"] Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string \"instanceFeatureId_N\" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.\n * @property {boolean} [showCreditsOnScreen=false] Whether to display the credits of this tileset on screen.\n * @property {SplitDirection} [splitDirection=SplitDirection.NONE] The {@link SplitDirection} split to apply to this tileset.\n * @property {boolean} [projectTo2D=false] Whether to accurately project the tileset to 2D. If this is true, the tileset will be projected accurately to 2D, but it will use more memory to do so. If this is false, the tileset will use less memory and will still render in 2D / CV mode, but its projected positions may be inaccurate. This cannot be set after the tileset has loaded.\n * @property {string} [debugHeatmapTilePropertyName] The tile variable to colorize as a heatmap. All rendered tiles will be colorized relative to each other's specified variable value.\n * @property {boolean} [debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering.\n * @property {boolean} [debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.\n * @property {boolean} [enableDebugWireframe] For debugging only. This must be true for debugWireframe to work in WebGL1. This cannot be set after the tileset has loaded.\n * @property {boolean} [debugWireframe=false] For debugging only. When true, render's each tile's content as a wireframe.\n * @property {boolean} [debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile.\n * @property {boolean} [debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content.\n * @property {boolean} [debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile.\n * @property {boolean} [debugShowGeometricError=false] For debugging only. When true, draws labels to indicate the geometric error of each tile.\n * @property {boolean} [debugShowRenderingStatistics=false] For debugging only. When true, draws labels to indicate the number of commands, points, triangles and features for each tile.\n * @property {boolean} [debugShowMemoryUsage=false] For debugging only. When true, draws labels to indicate the texture and geometry memory in megabytes used by each tile.\n * @property {boolean} [debugShowUrl=false] For debugging only. When true, draws labels to indicate the url of each tile.\n */\n\n/**\n * A {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},\n * used for streaming massive heterogeneous 3D geospatial datasets.\n *\n *
\n * This object is normally not instantiated directly, use {@link Cesium3DTileset.fromUrl}.\n *
\n *\n * @alias Cesium3DTileset\n * @constructor\n *\n * @param {Cesium3DTileset.ConstructorOptions} options An object describing initialization options\n *\n * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.\n *\n * @example\n * try {\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\"\n * );\n * scene.primitives.add(tileset);\n * } catch (error) {\n * console.error(`Error creating tileset: ${error}`);\n * }\n *\n * @example\n * // Common setting for the skipLevelOfDetail optimization\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\", {\n * skipLevelOfDetail: true,\n * baseScreenSpaceError: 1024,\n * skipScreenSpaceErrorFactor: 16,\n * skipLevels: 1,\n * immediatelyLoadDesiredLevelOfDetail: false,\n * loadSiblings: false,\n * cullWithChildrenBounds: true\n * });\n * scene.primitives.add(tileset);\n *\n * @example\n * // Common settings for the dynamicScreenSpaceError optimization\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\", {\n * dynamicScreenSpaceError: true,\n * dynamicScreenSpaceErrorDensity: 0.00278,\n * dynamicScreenSpaceErrorFactor: 4.0,\n * dynamicScreenSpaceErrorHeightFalloff: 0.25\n * });\n * scene.primitives.add(tileset);\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles specification}\n */\nfunction Cesium3DTileset(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._url = undefined;\n this._basePath = undefined;\n this._root = undefined;\n this._resource = undefined;\n this._asset = undefined; // Metadata for the entire tileset\n this._properties = undefined; // Metadata for per-model/point/etc properties\n this._geometricError = undefined; // Geometric error when the tree is not rendered at all\n this._scaledGeometricError = undefined; // Geometric error scaled by root tile scale\n this._extensionsUsed = undefined;\n this._extensions = undefined;\n this._modelUpAxis = undefined;\n this._modelForwardAxis = undefined;\n this._cache = new Cesium3DTilesetCache();\n this._processingQueue = [];\n this._selectedTiles = [];\n this._emptyTiles = [];\n this._requestedTiles = [];\n this._selectedTilesToStyle = [];\n this._loadTimestamp = undefined;\n this._timeSinceLoad = 0.0;\n this._updatedVisibilityFrame = 0;\n this._updatedModelMatrixFrame = 0;\n this._modelMatrixChanged = false;\n this._previousModelMatrix = undefined;\n this._extras = undefined;\n this._credits = undefined;\n\n this._showCreditsOnScreen = defaultValue(options.showCreditsOnScreen, false);\n\n this._cullWithChildrenBounds = defaultValue(\n options.cullWithChildrenBounds,\n true\n );\n this._allTilesAdditive = true;\n\n this._hasMixedContent = false;\n\n this._stencilClearCommand = undefined;\n this._backfaceCommands = new ManagedArray();\n\n this._maximumScreenSpaceError = defaultValue(\n options.maximumScreenSpaceError,\n 16\n );\n this._memoryAdjustedScreenSpaceError = this._maximumScreenSpaceError;\n\n let defaultCacheBytes = 512 * 1024 * 1024;\n if (defined(options.maximumMemoryUsage)) {\n deprecationWarning(\n \"Cesium3DTileset.maximumMemoryUsage\",\n \"Cesium3DTileset.maximumMemoryUsage was deprecated in CesiumJS 1.107. It will be removed in CesiumJS 1.110. Use Cesium3DTileset.cacheBytes instead.\"\n );\n defaultCacheBytes = options.maximumMemoryUsage * 1024 * 1024;\n }\n this._cacheBytes = defaultValue(options.cacheBytes, defaultCacheBytes);\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"cacheBytes\", this._cacheBytes, 0);\n //>>includeEnd('debug');\n\n const maximumCacheOverflowBytes = defaultValue(\n options.maximumCacheOverflowBytes,\n 512 * 1024 * 1024\n );\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\n \"maximumCacheOverflowBytes\",\n maximumCacheOverflowBytes,\n 0\n );\n //>>includeEnd('debug');\n this._maximumCacheOverflowBytes = maximumCacheOverflowBytes;\n\n this._styleEngine = new Cesium3DTileStyleEngine();\n this._styleApplied = false;\n\n this._modelMatrix = defined(options.modelMatrix)\n ? Matrix4.clone(options.modelMatrix)\n : Matrix4.clone(Matrix4.IDENTITY);\n\n this._statistics = new Cesium3DTilesetStatistics();\n this._statisticsLast = new Cesium3DTilesetStatistics();\n this._statisticsPerPass = new Array(Cesium3DTilePass.NUMBER_OF_PASSES);\n\n for (let i = 0; i < Cesium3DTilePass.NUMBER_OF_PASSES; ++i) {\n this._statisticsPerPass[i] = new Cesium3DTilesetStatistics();\n }\n\n this._requestedTilesInFlight = [];\n\n this._maximumPriority = {\n foveatedFactor: -Number.MAX_VALUE,\n depth: -Number.MAX_VALUE,\n distance: -Number.MAX_VALUE,\n reverseScreenSpaceError: -Number.MAX_VALUE,\n };\n this._minimumPriority = {\n foveatedFactor: Number.MAX_VALUE,\n depth: Number.MAX_VALUE,\n distance: Number.MAX_VALUE,\n reverseScreenSpaceError: Number.MAX_VALUE,\n };\n this._heatmap = new Cesium3DTilesetHeatmap(\n options.debugHeatmapTilePropertyName\n );\n\n /**\n * Optimization option. Don't request tiles that will likely be unused when they come back because of the camera's movement. This optimization only applies to stationary tilesets.\n *\n * @type {boolean}\n * @default true\n */\n this.cullRequestsWhileMoving = defaultValue(\n options.cullRequestsWhileMoving,\n true\n );\n this._cullRequestsWhileMoving = false;\n\n /**\n * Optimization option. Multiplier used in culling requests while moving. Larger is more aggressive culling, smaller less aggressive culling.\n *\n * @type {number}\n * @default 60.0\n */\n this.cullRequestsWhileMovingMultiplier = defaultValue(\n options.cullRequestsWhileMovingMultiplier,\n 60.0\n );\n\n /**\n * Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of progressiveResolutionHeightFraction*screenHeight will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load.\n *\n * @type {number}\n * @default 0.3\n */\n this.progressiveResolutionHeightFraction = CesiumMath.clamp(\n defaultValue(options.progressiveResolutionHeightFraction, 0.3),\n 0.0,\n 0.5\n );\n\n /**\n * Optimization option. Prefer loading of leaves first.\n *\n * @type {boolean}\n * @default false\n */\n this.preferLeaves = defaultValue(options.preferLeaves, false);\n\n this._tilesLoaded = false;\n this._initialTilesLoaded = false;\n\n this._tileDebugLabels = undefined;\n\n this._classificationType = options.classificationType;\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n this._initialClippingPlanesOriginMatrix = Matrix4.IDENTITY; // Computed from the tileset JSON.\n this._clippingPlanesOriginMatrix = undefined; // Combines the above with any run-time transforms.\n this._clippingPlanesOriginMatrixDirty = true;\n\n this._vectorClassificationOnly = defaultValue(\n options.vectorClassificationOnly,\n false\n );\n\n this._vectorKeepDecodedPositions = defaultValue(\n options.vectorKeepDecodedPositions,\n false\n );\n\n /**\n * Preload tiles when tileset.show is false. Loads tiles as if the tileset is visible but does not render them.\n *\n * @type {boolean}\n * @default false\n */\n this.preloadWhenHidden = defaultValue(options.preloadWhenHidden, false);\n\n /**\n * Optimization option. Fetch tiles at the camera's flight destination while the camera is in flight.\n *\n * @type {boolean}\n * @default true\n */\n this.preloadFlightDestinations = defaultValue(\n options.preloadFlightDestinations,\n true\n );\n this._pass = undefined; // Cesium3DTilePass\n\n /**\n * Optimization option. Whether the tileset should refine based on a dynamic screen space error. Tiles that are further\n * away will be rendered with lower detail than closer tiles. This improves performance by rendering fewer\n * tiles and making less requests, but may result in a slight drop in visual quality for tiles in the distance.\n * The algorithm is biased towards \"street views\" where the camera is close to the ground plane of the tileset and looking\n * at the horizon. In addition results are more accurate for tightly fitting bounding volumes like box and region.\n *\n * @type {boolean}\n * @default false\n */\n this.dynamicScreenSpaceError = defaultValue(\n options.dynamicScreenSpaceError,\n false\n );\n\n /**\n * Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the\n * screen space error for tiles around the edge of the screen. Screen space error returns to normal once all\n * the tiles in the center of the screen as determined by the {@link Cesium3DTileset#foveatedConeSize} are loaded.\n *\n * @type {boolean}\n * @default true\n */\n this.foveatedScreenSpaceError = defaultValue(\n options.foveatedScreenSpaceError,\n true\n );\n this._foveatedConeSize = defaultValue(options.foveatedConeSize, 0.1);\n this._foveatedMinimumScreenSpaceErrorRelaxation = defaultValue(\n options.foveatedMinimumScreenSpaceErrorRelaxation,\n 0.0\n );\n\n /**\n * Gets or sets a callback to control how much to raise the screen space error for tiles outside the foveated cone,\n * interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}.\n *\n * @type {Cesium3DTileset.foveatedInterpolationCallback}\n */\n this.foveatedInterpolationCallback = defaultValue(\n options.foveatedInterpolationCallback,\n CesiumMath.lerp\n );\n\n /**\n * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control\n * how long in seconds to wait after the camera stops moving before deferred tiles start loading in.\n * This time delay prevents requesting tiles around the edges of the screen when the camera is moving.\n * Setting this to 0.0 will immediately request all tiles in any given view.\n *\n * @type {number}\n * @default 0.2\n */\n this.foveatedTimeDelay = defaultValue(options.foveatedTimeDelay, 0.2);\n\n /**\n * A scalar that determines the density used to adjust the dynamic screen space error, similar to {@link Fog}. Increasing this\n * value has the effect of increasing the maximum screen space error for all tiles, but in a non-linear fashion.\n * The error starts at 0.0 and increases exponentially until a midpoint is reached, and then approaches 1.0 asymptotically.\n * This has the effect of keeping high detail in the closer tiles and lower detail in the further tiles, with all tiles\n * beyond a certain distance all roughly having an error of 1.0.\n *

\n * The dynamic error is in the range [0.0, 1.0) and is multiplied by dynamicScreenSpaceErrorFactor to produce the\n * final dynamic error. This dynamic error is then subtracted from the tile's actual screen space error.\n *

\n *

\n * Increasing dynamicScreenSpaceErrorDensity has the effect of moving the error midpoint closer to the camera.\n * It is analogous to moving fog closer to the camera.\n *

\n *\n * @type {number}\n * @default 0.00278\n */\n this.dynamicScreenSpaceErrorDensity = 0.00278;\n\n /**\n * A factor used to increase the screen space error of tiles for dynamic screen space error. As this value increases less tiles\n * are requested for rendering and tiles in the distance will have lower detail. If set to zero, the feature will be disabled.\n *\n * @type {number}\n * @default 4.0\n */\n this.dynamicScreenSpaceErrorFactor = 4.0;\n\n /**\n * A ratio of the tileset's height at which the density starts to falloff. If the camera is below this height the\n * full computed density is applied, otherwise the density falls off. This has the effect of higher density at\n * street level views.\n *

\n * Valid values are between 0.0 and 1.0.\n *

\n *\n * @type {number}\n * @default 0.25\n */\n this.dynamicScreenSpaceErrorHeightFalloff = 0.25;\n\n this._dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction\n\n /**\n * Determines whether the tileset casts or receives shadows from light sources.\n *

\n * Enabling shadows has a performance impact. A tileset that casts shadows must be rendered twice, once from the camera and again from the light's point of view.\n *

\n *

\n * Shadows are rendered only when {@link Viewer#shadows} is true.\n *

\n *\n * @type {ShadowMode}\n * @default ShadowMode.ENABLED\n */\n this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED);\n\n /**\n * Determines if the tileset will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * Defines how per-feature colors set from the Cesium API or declarative styling blend with the source colors from\n * the original feature, e.g. glTF material or per-point color in the tile.\n *\n * @type {Cesium3DTileColorBlendMode}\n * @default Cesium3DTileColorBlendMode.HIGHLIGHT\n */\n this.colorBlendMode = Cesium3DTileColorBlendMode.HIGHLIGHT;\n\n /**\n * Defines the value used to linearly interpolate between the source color and feature color when the {@link Cesium3DTileset#colorBlendMode} is MIX.\n * A value of 0.0 results in the source color while a value of 1.0 results in the feature color, with any value in-between\n * resulting in a mix of the source color and feature color.\n *\n * @type {number}\n * @default 0.5\n */\n this.colorBlendAmount = 0.5;\n\n this._pointCloudShading = new PointCloudShading(options.pointCloudShading);\n this._pointCloudEyeDomeLighting = new PointCloudEyeDomeLighting();\n\n /**\n * The event fired to indicate progress of loading new tiles. This event is fired when a new tile\n * is requested, when a requested tile is finished downloading, and when a downloaded tile has been\n * processed and is ready to render.\n *

\n * The number of pending tile requests, numberOfPendingRequests, and number of tiles\n * processing, numberOfTilesProcessing are passed to the event listener.\n *

\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberOfTilesProcessing) {\n * if ((numberOfPendingRequests === 0) && (numberOfTilesProcessing === 0)) {\n * console.log('Stopped loading');\n * return;\n * }\n *\n * console.log(`Loading: requests: ${numberOfPendingRequests}, processing: ${numberOfTilesProcessing}`);\n * });\n */\n this.loadProgress = new Event();\n\n /**\n * The event fired to indicate that all tiles that meet the screen space error this frame are loaded. The tileset\n * is completely loaded for this view.\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.allTilesLoaded.addEventListener(function() {\n * console.log('All tiles are loaded');\n * });\n *\n * @see Cesium3DTileset#tilesLoaded\n */\n this.allTilesLoaded = new Event();\n\n /**\n * The event fired to indicate that all tiles that meet the screen space error this frame are loaded. This event\n * is fired once when all tiles in the initial view are loaded.\n *

\n * This event is fired at the end of the frame after the scene is rendered.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.initialTilesLoaded.addEventListener(function() {\n * console.log('Initial tiles are loaded');\n * });\n *\n * @see Cesium3DTileset#allTilesLoaded\n */\n this.initialTilesLoaded = new Event();\n\n /**\n * The event fired to indicate that a tile's content was loaded.\n *

\n * The loaded {@link Cesium3DTile} is passed to the event listener.\n *

\n *

\n * This event is fired during the tileset traversal while the frame is being rendered\n * so that updates to the tile take effect in the same frame. Do not create or modify\n * Cesium entities or primitives during the event listener.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.tileLoad.addEventListener(function(tile) {\n * console.log('A tile was loaded.');\n * });\n */\n this.tileLoad = new Event();\n\n /**\n * The event fired to indicate that a tile's content was unloaded.\n *

\n * The unloaded {@link Cesium3DTile} is passed to the event listener.\n *

\n *

\n * This event is fired immediately before the tile's content is unloaded while the frame is being\n * rendered so that the event listener has access to the tile's content. Do not create\n * or modify Cesium entities or primitives during the event listener.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.tileUnload.addEventListener(function(tile) {\n * console.log('A tile was unloaded from the cache.');\n * });\n *\n * @see Cesium3DTileset#cacheBytes\n * @see Cesium3DTileset#trimLoadedTiles\n */\n this.tileUnload = new Event();\n\n /**\n * The event fired to indicate that a tile's content failed to load.\n *

\n * If there are no event listeners, error messages will be logged to the console.\n *

\n *

\n * The error object passed to the listener contains two properties:\n *

    \n *
  • url: the url of the failed tile.
  • \n *
  • message: the error message.
  • \n *
\n *

\n * If multiple contents are present, this event is raised once per inner content with errors.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.tileFailed.addEventListener(function(error) {\n * console.log(`An error occurred loading tile: ${error.url}`);\n * console.log(`Error: ${error.message}`);\n * });\n */\n this.tileFailed = new Event();\n\n /**\n * This event fires once for each visible tile in a frame. This can be used to manually\n * style a tileset.\n *

\n * The visible {@link Cesium3DTile} is passed to the event listener.\n *

\n *

\n * This event is fired during the tileset traversal while the frame is being rendered\n * so that updates to the tile take effect in the same frame. Do not create or modify\n * Cesium entities or primitives during the event listener.\n *

\n *\n * @type {Event}\n * @default new Event()\n *\n * @example\n * tileset.tileVisible.addEventListener(function(tile) {\n * if (tile.content instanceof Cesium.Model3DTileContent) {\n * console.log('A 3D model tile is visible.');\n * }\n * });\n *\n * @example\n * // Apply a red style and then manually set random colors for every other feature when the tile becomes visible.\n * tileset.style = new Cesium.Cesium3DTileStyle({\n * color : 'color(\"red\")'\n * });\n * tileset.tileVisible.addEventListener(function(tile) {\n * const content = tile.content;\n * const featuresLength = content.featuresLength;\n * for (let i = 0; i < featuresLength; i+=2) {\n * content.getFeature(i).color = Cesium.Color.fromRandom();\n * }\n * });\n */\n this.tileVisible = new Event();\n\n /**\n * Optimization option. Determines if level of detail skipping should be applied during the traversal.\n *

\n * The common strategy for replacement-refinement traversal is to store all levels of the tree in memory and require\n * all children to be loaded before the parent can refine. With this optimization levels of the tree can be skipped\n * entirely and children can be rendered alongside their parents. The tileset requires significantly less memory when\n * using this optimization.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.skipLevelOfDetail = defaultValue(options.skipLevelOfDetail, false);\n\n this._disableSkipLevelOfDetail = false;\n\n /**\n * The screen space error that must be reached before skipping levels of detail.\n *

\n * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is true.\n *

\n *\n * @type {number}\n * @default 1024\n */\n this.baseScreenSpaceError = defaultValue(options.baseScreenSpaceError, 1024);\n\n /**\n * Multiplier defining the minimum screen space error to skip.\n * For example, if a tile has screen space error of 100, no tiles will be loaded unless they\n * are leaves or have a screen space error <= 100 / skipScreenSpaceErrorFactor.\n *

\n * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is true.\n *

\n *\n * @type {number}\n * @default 16\n */\n this.skipScreenSpaceErrorFactor = defaultValue(\n options.skipScreenSpaceErrorFactor,\n 16\n );\n\n /**\n * Constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped.\n * For example, if a tile is level 1, no tiles will be loaded unless they are at level greater than 2.\n *

\n * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is true.\n *

\n *\n * @type {number}\n * @default 1\n */\n this.skipLevels = defaultValue(options.skipLevels, 1);\n\n /**\n * When true, only tiles that meet the maximum screen space error will ever be downloaded.\n * Skipping factors are ignored and just the desired tiles are loaded.\n *

\n * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is true.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.immediatelyLoadDesiredLevelOfDetail = defaultValue(\n options.immediatelyLoadDesiredLevelOfDetail,\n false\n );\n\n /**\n * Determines whether siblings of visible tiles are always downloaded during traversal.\n * This may be useful for ensuring that tiles are already available when the viewer turns left/right.\n *

\n * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is true.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.loadSiblings = defaultValue(options.loadSiblings, false);\n\n this._clippingPlanes = undefined;\n this.clippingPlanes = options.clippingPlanes;\n\n if (defined(options.imageBasedLighting)) {\n this._imageBasedLighting = options.imageBasedLighting;\n this._shouldDestroyImageBasedLighting = false;\n } else {\n this._imageBasedLighting = new ImageBasedLighting();\n this._shouldDestroyImageBasedLighting = true;\n }\n\n /**\n * The light color when shading models. When undefined the scene's light color is used instead.\n *

\n * For example, disabling additional light sources by setting\n * tileset.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)\n * will make the tileset much darker. Here, increasing the intensity of the light source will make the tileset brighter.\n *

\n *\n * @type {Cartesian3}\n * @default undefined\n */\n this.lightColor = options.lightColor;\n\n /**\n * Whether to cull back-facing geometry. When true, back face culling is determined\n * by the glTF material's doubleSided property; when false, back face culling is disabled.\n *\n * @type {boolean}\n * @default true\n */\n this.backFaceCulling = defaultValue(options.backFaceCulling, true);\n\n this._enableShowOutline = defaultValue(options.enableShowOutline, true);\n\n /**\n * Whether to display the outline for models using the\n * {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension.\n * When true, outlines are displayed. When false, outlines are not displayed.\n *\n * @type {boolean}\n * @default true\n */\n this.showOutline = defaultValue(options.showOutline, true);\n\n /**\n * The color to use when rendering outlines.\n *\n * @type {Color}\n * @default Color.BLACK\n */\n this.outlineColor = defaultValue(options.outlineColor, Color.BLACK);\n\n /**\n * The {@link SplitDirection} to apply to this tileset.\n *\n * @type {SplitDirection}\n * @default {@link SplitDirection.NONE}\n */\n this.splitDirection = defaultValue(\n options.splitDirection,\n SplitDirection.NONE\n );\n\n this._projectTo2D = defaultValue(options.projectTo2D, false);\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * Determines if only the tiles from last frame should be used for rendering. This\n * effectively \"freezes\" the tileset to the previous frame so it is possible to zoom\n * out and see what was rendered.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugFreezeFrame = defaultValue(options.debugFreezeFrame, false);\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, assigns a random color to each tile. This is useful for visualizing\n * what features belong to what tiles, especially with additive refinement where features\n * from parent tiles may be interleaved with features from child tiles.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugColorizeTiles = defaultValue(options.debugColorizeTiles, false);\n\n this._enableDebugWireframe = defaultValue(\n options.enableDebugWireframe,\n false\n );\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, renders each tile's content as a wireframe.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugWireframe = defaultValue(options.debugWireframe, false);\n\n // Warning for improper setup of debug wireframe\n if (this.debugWireframe === true && this._enableDebugWireframe === false) {\n oneTimeWarning(\n \"tileset-debug-wireframe-ignored\",\n \"enableDebugWireframe must be set to true in the Cesium3DTileset constructor, otherwise debugWireframe will be ignored.\"\n );\n }\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, renders the bounding volume for each visible tile. The bounding volume is\n * white if the tile has a content bounding volume or is empty; otherwise, it is red. Tiles that don't meet the\n * screen space error and are still refining to their descendants are yellow.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, renders the bounding volume for each visible tile's content. The bounding volume is\n * blue if the tile has a content bounding volume; otherwise it is red.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowContentBoundingVolume = defaultValue(\n options.debugShowContentBoundingVolume,\n false\n );\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, renders the viewer request volume for each tile.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowViewerRequestVolume = defaultValue(\n options.debugShowViewerRequestVolume,\n false\n );\n\n /**\n * @private\n * @type {LabelCollection|undefined}\n */\n this._tileDebugLabels = undefined;\n this.debugPickedTileLabelOnly = false;\n this.debugPickedTile = undefined;\n this.debugPickPosition = undefined;\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, draws labels to indicate the geometric error of each tile.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowGeometricError = defaultValue(\n options.debugShowGeometricError,\n false\n );\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, draws labels to indicate the number of commands, points, triangles and features of each tile.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowRenderingStatistics = defaultValue(\n options.debugShowRenderingStatistics,\n false\n );\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, draws labels to indicate the geometry and texture memory usage of each tile.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowMemoryUsage = defaultValue(options.debugShowMemoryUsage, false);\n\n /**\n * This property is for debugging only; it is not optimized for production use.\n *

\n * When true, draws labels to indicate the url of each tile.\n *

\n *\n * @type {boolean}\n * @default false\n */\n this.debugShowUrl = defaultValue(options.debugShowUrl, false);\n\n /**\n * Function for examining vector lines as they are being streamed.\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n *\n * @type {Function}\n */\n this.examineVectorLinesFunction = undefined;\n\n // this is the underlying Cesium3DTileMetadata object, whether it came from\n // the 3DTILES_metadata extension or a 3D Tiles 1.1 tileset JSON. Getters\n // like tileset.metadata and tileset.schema will delegate to this object.\n this._metadataExtension = undefined;\n\n this._customShader = options.customShader;\n\n let featureIdLabel = defaultValue(options.featureIdLabel, \"featureId_0\");\n if (typeof featureIdLabel === \"number\") {\n featureIdLabel = `featureId_${featureIdLabel}`;\n }\n this._featureIdLabel = featureIdLabel;\n\n let instanceFeatureIdLabel = defaultValue(\n options.instanceFeatureIdLabel,\n \"instanceFeatureId_0\"\n );\n if (typeof instanceFeatureIdLabel === \"number\") {\n instanceFeatureIdLabel = `instanceFeatureId_${instanceFeatureIdLabel}`;\n }\n this._instanceFeatureIdLabel = instanceFeatureIdLabel;\n}\n\nObject.defineProperties(Cesium3DTileset.prototype, {\n /**\n * NOTE: This getter exists so that `Picking.js` can differentiate between\n * PrimitiveCollection and Cesium3DTileset objects without inflating\n * the size of the module via `instanceof Cesium3DTileset`\n * @private\n */\n isCesium3DTileset: {\n get: function () {\n return true;\n },\n },\n\n /**\n * Gets the tileset's asset object property, which contains metadata about the tileset.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#reference-asset|asset schema reference}\n * in the 3D Tiles spec for the full set of properties.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {object}\n * @readonly\n */\n asset: {\n get: function () {\n return this._asset;\n },\n },\n\n /**\n * Gets the tileset's extensions object property.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {object}\n * @readonly\n */\n extensions: {\n get: function () {\n return this._extensions;\n },\n },\n\n /**\n * The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {ClippingPlaneCollection}\n */\n clippingPlanes: {\n get: function () {\n return this._clippingPlanes;\n },\n set: function (value) {\n ClippingPlaneCollection.setOwner(value, this, \"_clippingPlanes\");\n },\n },\n\n /**\n * Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.\n *

\n * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#reference-properties|properties schema reference}\n * in the 3D Tiles spec for the full set of properties.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {object}\n * @readonly\n *\n * @example\n * console.log(`Maximum building height: ${tileset.properties.height.maximum}`);\n * console.log(`Minimum building height: ${tileset.properties.height.minimum}`);\n *\n * @see Cesium3DTileFeature#getProperty\n * @see Cesium3DTileFeature#setProperty\n */\n properties: {\n get: function () {\n return this._properties;\n },\n },\n\n /**\n * When true, all tiles that meet the screen space error this frame are loaded. The tileset is\n * completely loaded for this view.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {boolean}\n * @readonly\n *\n * @default false\n *\n * @see Cesium3DTileset#allTilesLoaded\n */\n tilesLoaded: {\n get: function () {\n return this._tilesLoaded;\n },\n },\n\n /**\n * The resource used to fetch the tileset JSON file\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {Resource}\n * @readonly\n */\n resource: {\n get: function () {\n return this._resource;\n },\n },\n\n /**\n * The base path that non-absolute paths in tileset JSON file are relative to.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {string}\n * @readonly\n * @deprecated\n */\n basePath: {\n get: function () {\n deprecationWarning(\n \"Cesium3DTileset.basePath\",\n \"Cesium3DTileset.basePath has been deprecated. All tiles are relative to the url of the tileset JSON file that contains them. Use the url property instead.\"\n );\n return this._basePath;\n },\n },\n\n /**\n * The style, defined using the\n * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language},\n * applied to each feature in the tileset.\n *

\n * Assign undefined to remove the style, which will restore the visual\n * appearance of the tileset to its default when no style was applied.\n *

\n *

\n * The style is applied to a tile before the {@link Cesium3DTileset#tileVisible}\n * event is raised, so code in tileVisible can manually set a feature's\n * properties (e.g. color and show) after the style is applied. When\n * a new style is assigned any manually set properties are overwritten.\n *

\n *

\n * Use an always \"true\" condition to specify the Color for all objects that are not\n * overridden by pre-existing conditions. Otherwise, the default color Cesium.Color.White\n * will be used. Similarly, use an always \"true\" condition to specify the show property\n * for all objects that are not overridden by pre-existing conditions. Otherwise, the\n * default show value true will be used.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {Cesium3DTileStyle|undefined}\n *\n * @default undefined\n *\n * @example\n * tileset.style = new Cesium.Cesium3DTileStyle({\n * color : {\n * conditions : [\n * ['${Height} >= 100', 'color(\"purple\", 0.5)'],\n * ['${Height} >= 50', 'color(\"red\")'],\n * ['true', 'color(\"blue\")']\n * ]\n * },\n * show : '${Height} > 0',\n * meta : {\n * description : '\"Building id ${id} has height ${Height}.\"'\n * }\n * });\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}\n */\n style: {\n get: function () {\n return this._styleEngine.style;\n },\n set: function (value) {\n this._styleEngine.style = value;\n },\n },\n\n /**\n * A custom shader to apply to all tiles in the tileset. Only used for\n * contents that use {@link Model}. Using custom shaders with a\n * {@link Cesium3DTileStyle} may lead to undefined behavior.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {CustomShader|undefined}\n *\n * @default undefined\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n customShader: {\n get: function () {\n return this._customShader;\n },\n set: function (value) {\n this._customShader = value;\n },\n },\n\n /**\n * Whether the tileset is rendering different levels of detail in the same view.\n * Only relevant if {@link Cesium3DTileset.isSkippingLevelOfDetail} is true.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {boolean}\n * @private\n */\n hasMixedContent: {\n get: function () {\n return this._hasMixedContent;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.bool(\"value\", value);\n //>>includeEnd('debug');\n\n this._hasMixedContent = value;\n },\n },\n\n /**\n * Whether this tileset is actually skipping levels of detail.\n * The user option may have been disabled if all tiles are using additive refinement,\n * or if some tiles have a content type for which rendering does not support skipping\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {boolean}\n * @private\n * @readonly\n */\n isSkippingLevelOfDetail: {\n get: function () {\n return (\n this.skipLevelOfDetail &&\n !defined(this._classificationType) &&\n !this._disableSkipLevelOfDetail &&\n !this._allTilesAdditive\n );\n },\n },\n\n /**\n * The tileset's schema, groups, tileset metadata and other details from the\n * 3DTILES_metadata extension or a 3D Tiles 1.1 tileset JSON. This getter is\n * for internal use by other classes.\n *\n * @memberof Cesium3DTileset.prototype\n * @type {Cesium3DTilesetMetadata}\n * @private\n * @readonly\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n metadataExtension: {\n get: function () {\n return this._metadataExtension;\n },\n },\n\n /**\n * The metadata properties attached to the tileset as a whole.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {TilesetMetadata}\n * @private\n * @readonly\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n metadata: {\n get: function () {\n if (defined(this._metadataExtension)) {\n return this._metadataExtension.tileset;\n }\n\n return undefined;\n },\n },\n\n /**\n * The metadata schema used in this tileset. Shorthand for\n * tileset.metadataExtension.schema\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {MetadataSchema}\n * @private\n * @readonly\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n schema: {\n get: function () {\n if (defined(this._metadataExtension)) {\n return this._metadataExtension.schema;\n }\n\n return undefined;\n },\n },\n\n /**\n * The maximum screen space error used to drive level of detail refinement. This value helps determine when a tile\n * refines to its descendants, and therefore plays a major role in balancing performance with visual quality.\n *

\n * A tile's screen space error is roughly equivalent to the number of pixels wide that would be drawn if a sphere with a\n * radius equal to the tile's geometric error were rendered at the tile's position. If this value exceeds\n * maximumScreenSpaceError the tile refines to its descendants.\n *

\n *

\n * Depending on the tileset, maximumScreenSpaceError may need to be tweaked to achieve the right balance.\n * Higher values provide better performance but lower visual quality.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 16\n *\n * @exception {DeveloperError} maximumScreenSpaceError must be greater than or equal to zero.\n */\n maximumScreenSpaceError: {\n get: function () {\n return this._maximumScreenSpaceError;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\n \"maximumScreenSpaceError\",\n value,\n 0\n );\n //>>includeEnd('debug');\n\n this._maximumScreenSpaceError = value;\n this._memoryAdjustedScreenSpaceError = value;\n },\n },\n\n /**\n * The maximum amount of GPU memory (in MB) that may be used to cache tiles. This value is estimated from\n * geometry, textures, and batch table textures of loaded tiles. For point clouds, this value also\n * includes per-point metadata.\n *

\n * Tiles not in view are unloaded to enforce this.\n *

\n *

\n * If decreasing this value results in unloading tiles, the tiles are unloaded the next frame.\n *

\n *

\n * If tiles sized more than maximumMemoryUsage are needed\n * to meet the desired screen space error, determined by {@link Cesium3DTileset#maximumScreenSpaceError},\n * for the current view, then the memory usage of the tiles loaded will exceed\n * maximumMemoryUsage. For example, if the maximum is 256 MB, but\n * 300 MB of tiles are needed to meet the screen space error, then 300 MB of tiles may be loaded. When\n * these tiles go out of view, they will be unloaded.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 512\n *\n * @exception {DeveloperError} maximumMemoryUsage must be greater than or equal to zero.\n * @see Cesium3DTileset#totalMemoryUsageInBytes\n *\n * @deprecated\n */\n maximumMemoryUsage: {\n get: function () {\n deprecationWarning(\n \"Cesium3DTileset.maximumMemoryUsage\",\n \"Cesium3DTileset.maximumMemoryUsage was deprecated in CesiumJS 1.107. It will be removed in CesiumJS 1.110. Use Cesium3DTileset.cacheBytes instead.\"\n );\n return this._maximumMemoryUsage;\n },\n set: function (value) {\n deprecationWarning(\n \"Cesium3DTileset.maximumMemoryUsage\",\n \"Cesium3DTileset.maximumMemoryUsage was deprecated in CesiumJS 1.107. It will be removed in CesiumJS 1.110. Use Cesium3DTileset.cacheBytes instead.\"\n );\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"value\", value, 0);\n //>>includeEnd('debug');\n\n this._maximumMemoryUsage = value;\n this._cacheBytes = value * 1024 * 1024;\n },\n },\n\n /**\n * The amount of GPU memory (in bytes) used to cache tiles. This memory usage is estimated from\n * geometry, textures, and batch table textures of loaded tiles. For point clouds, this value also\n * includes per-point metadata.\n *

\n * Tiles not in view are unloaded to enforce this.\n *

\n *

\n * If decreasing this value results in unloading tiles, the tiles are unloaded the next frame.\n *

\n *

\n * If tiles sized more than cacheBytes are needed to meet the\n * desired screen space error, determined by {@link Cesium3DTileset#maximumScreenSpaceError},\n * for the current view, then the memory usage of the tiles loaded will exceed\n * cacheBytes by up to maximumCacheOverflowBytes.\n * For example, if cacheBytes is 500000, but 600000 bytes\n * of tiles are needed to meet the screen space error, then 600000 bytes of tiles\n * may be loaded (if maximumCacheOverflowBytes is at least 100000).\n * When these tiles go out of view, they will be unloaded.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 536870912\n *\n * @exception {DeveloperError} cacheBytes must be typeof 'number' and greater than or equal to 0\n * @see Cesium3DTileset#totalMemoryUsageInBytes\n */\n cacheBytes: {\n get: function () {\n return this._cacheBytes;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"value\", value, 0);\n //>>includeEnd('debug');\n\n this._cacheBytes = value;\n },\n },\n\n /**\n * The maximum additional amount of GPU memory (in bytes) that will be used to cache tiles.\n *

\n * If tiles sized more than cacheBytes plus maximumCacheOverflowBytes\n * are needed to meet the desired screen space error, determined by\n * {@link Cesium3DTileset#maximumScreenSpaceError} for the current view, then\n * {@link Cesium3DTileset#memoryAdjustedScreenSpaceError} will be adjusted\n * until the tiles required to meet the adjusted screen space error use less\n * than cacheBytes plus maximumCacheOverflowBytes.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 536870912\n *\n * @exception {DeveloperError} maximumCacheOverflowBytes must be typeof 'number' and greater than or equal to 0\n * @see Cesium3DTileset#totalMemoryUsageInBytes\n */\n maximumCacheOverflowBytes: {\n get: function () {\n return this._maximumCacheOverflowBytes;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"value\", value, 0);\n //>>includeEnd('debug');\n\n this._maximumCacheOverflowBytes = value;\n },\n },\n\n /**\n * If loading the level of detail required by @{link Cesium3DTileset#maximumScreenSpaceError}\n * results in the memory usage exceeding @{link Cesium3DTileset#cacheBytes}\n * plus @{link Cesium3DTileset#maximumCacheOverflowBytes}, level of detail refinement\n * will instead use this (larger) adjusted screen space error to achieve the\n * best possible visual quality within the available memory\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @readonly\n *\n * @private\n */\n memoryAdjustedScreenSpaceError: {\n get: function () {\n return this._memoryAdjustedScreenSpaceError;\n },\n },\n\n /**\n * Options for controlling point size based on geometric error and eye dome lighting.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {PointCloudShading}\n */\n pointCloudShading: {\n get: function () {\n return this._pointCloudShading;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"pointCloudShading\", value);\n //>>includeEnd('debug');\n this._pointCloudShading = value;\n },\n },\n\n /**\n * The root tile.\n *\n * @memberOf Cesium3DTileset.prototype\n *\n * @type {Cesium3DTile}\n * @readonly\n */\n root: {\n get: function () {\n return this._root;\n },\n },\n\n /**\n * The tileset's bounding sphere.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {BoundingSphere}\n * @readonly\n *\n * @example\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\"http://localhost:8002/tilesets/Seattle/tileset.json\");\n *\n * viewer.scene.primitives.add(tileset);\n *\n * // Set the camera to view the newly added tileset\n * viewer.camera.viewBoundingSphere(tileset.boundingSphere, new Cesium.HeadingPitchRange(0, -0.5, 0));\n */\n boundingSphere: {\n get: function () {\n this._root.updateTransform(this._modelMatrix);\n return this._root.boundingSphere;\n },\n },\n\n /**\n * A 4x4 transformation matrix that transforms the entire tileset.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {Matrix4}\n * @default Matrix4.IDENTITY\n *\n * @example\n * // Adjust a tileset's height from the globe's surface.\n * const heightOffset = 20.0;\n * const boundingSphere = tileset.boundingSphere;\n * const cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);\n * const surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);\n * const offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);\n * const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());\n * tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);\n */\n modelMatrix: {\n get: function () {\n return this._modelMatrix;\n },\n set: function (value) {\n this._modelMatrix = Matrix4.clone(value, this._modelMatrix);\n },\n },\n\n /**\n * Returns the time, in milliseconds, since the tileset was loaded and first updated.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @readonly\n */\n timeSinceLoad: {\n get: function () {\n return this._timeSinceLoad;\n },\n },\n\n /**\n * The total amount of GPU memory in bytes used by the tileset. This value is estimated from\n * geometry, texture, batch table textures, and binary metadata of loaded tiles.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @readonly\n *\n * @see Cesium3DTileset#cacheBytes\n */\n totalMemoryUsageInBytes: {\n get: function () {\n const statistics = this._statistics;\n return (\n statistics.texturesByteLength +\n statistics.geometryByteLength +\n statistics.batchTableByteLength\n );\n },\n },\n\n /**\n * @private\n */\n clippingPlanesOriginMatrix: {\n get: function () {\n if (!defined(this._clippingPlanesOriginMatrix)) {\n return Matrix4.IDENTITY;\n }\n\n if (this._clippingPlanesOriginMatrixDirty) {\n Matrix4.multiply(\n this.root.computedTransform,\n this._initialClippingPlanesOriginMatrix,\n this._clippingPlanesOriginMatrix\n );\n this._clippingPlanesOriginMatrixDirty = false;\n }\n\n return this._clippingPlanesOriginMatrix;\n },\n },\n\n /**\n * @private\n */\n styleEngine: {\n get: function () {\n return this._styleEngine;\n },\n },\n\n /**\n * @private\n */\n statistics: {\n get: function () {\n return this._statistics;\n },\n },\n\n /**\n * Determines whether terrain, 3D Tiles, or both will be classified by this tileset.\n *

\n * This option is only applied to tilesets containing batched 3D models,\n * glTF content, geometry data, or vector data. Even when undefined, vector\n * and geometry data must render as classifications and will default to\n * rendering on both terrain and other 3D Tiles tilesets.\n *

\n *

\n * When enabled for batched 3D model and glTF tilesets, there are a few\n * requirements/limitations on the glTF:\n *

    \n *
  • The glTF cannot contain morph targets, skins, or animations.
  • \n *
  • The glTF cannot contain the EXT_mesh_gpu_instancing extension.
  • \n *
  • Only meshes with TRIANGLES can be used to classify other assets.
  • \n *
  • The POSITION semantic is required.
  • \n *
  • If _BATCHIDs and an index buffer are both present, all indices with the same batch id must occupy contiguous sections of the index buffer.
  • \n *
  • If _BATCHIDs are present with no index buffer, all positions with the same batch id must occupy contiguous sections of the position buffer.
  • \n *
\n *

\n *

\n * Additionally, classification is not supported for points or instanced 3D\n * models.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {ClassificationType}\n * @default undefined\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n * @readonly\n */\n classificationType: {\n get: function () {\n return this._classificationType;\n },\n },\n\n /**\n * Gets an ellipsoid describing the shape of the globe.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {Ellipsoid}\n * @readonly\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n\n /**\n * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the cone size that determines which tiles are deferred.\n * Tiles that are inside this cone are loaded immediately. Tiles outside the cone are potentially deferred based on how far outside the cone they are and {@link Cesium3DTileset#foveatedInterpolationCallback} and {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation}.\n * Setting this to 0.0 means the cone will be the line formed by the camera position and its view direction. Setting this to 1.0 means the cone encompasses the entire field of view of the camera, essentially disabling the effect.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 0.3\n */\n foveatedConeSize: {\n get: function () {\n return this._foveatedConeSize;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\"foveatedConeSize\", value, 0.0);\n Check.typeOf.number.lessThanOrEquals(\"foveatedConeSize\", value, 1.0);\n //>>includeEnd('debug');\n\n this._foveatedConeSize = value;\n },\n },\n\n /**\n * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the starting screen space error relaxation for tiles outside the foveated cone.\n * The screen space error will be raised starting with this value up to {@link Cesium3DTileset#maximumScreenSpaceError} based on the provided {@link Cesium3DTileset#foveatedInterpolationCallback}.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {number}\n * @default 0.0\n */\n foveatedMinimumScreenSpaceErrorRelaxation: {\n get: function () {\n return this._foveatedMinimumScreenSpaceErrorRelaxation;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number.greaterThanOrEquals(\n \"foveatedMinimumScreenSpaceErrorRelaxation\",\n value,\n 0.0\n );\n Check.typeOf.number.lessThanOrEquals(\n \"foveatedMinimumScreenSpaceErrorRelaxation\",\n value,\n this.maximumScreenSpaceError\n );\n //>>includeEnd('debug');\n\n this._foveatedMinimumScreenSpaceErrorRelaxation = value;\n },\n },\n\n /**\n * Returns the extras property at the top-level of the tileset JSON, which contains application specific metadata.\n * Returns undefined if extras does not exist.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {*}\n * @readonly\n *\n * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}\n */\n extras: {\n get: function () {\n return this._extras;\n },\n },\n\n /**\n * The properties for managing image-based lighting on this tileset.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {ImageBasedLighting}\n */\n imageBasedLighting: {\n get: function () {\n return this._imageBasedLighting;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"imageBasedLighting\", this._imageBasedLighting);\n //>>includeEnd('debug');\n if (value !== this._imageBasedLighting) {\n if (\n this._shouldDestroyImageBasedLighting &&\n !this._imageBasedLighting.isDestroyed()\n ) {\n this._imageBasedLighting.destroy();\n }\n this._imageBasedLighting = value;\n this._shouldDestroyImageBasedLighting = false;\n }\n },\n },\n\n /**\n * Indicates that only the tileset's vector tiles should be used for classification.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n *\n * @type {boolean}\n * @default false\n */\n vectorClassificationOnly: {\n get: function () {\n return this._vectorClassificationOnly;\n },\n },\n\n /**\n * Whether vector tiles should keep decoded positions in memory.\n * This is used with {@link Cesium3DTileFeature.getPolylinePositions}.\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n *\n * @type {boolean}\n * @default false\n */\n vectorKeepDecodedPositions: {\n get: function () {\n return this._vectorKeepDecodedPositions;\n },\n },\n\n /**\n * Determines whether the credits of the tileset will be displayed on the screen\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {boolean}\n * @default false\n */\n showCreditsOnScreen: {\n get: function () {\n return this._showCreditsOnScreen;\n },\n set: function (value) {\n this._showCreditsOnScreen = value;\n },\n },\n\n /**\n * Label of the feature ID set to use for picking and styling.\n *

\n * For EXT_mesh_features, this is the feature ID's label property, or\n * \"featureId_N\" (where N is the index in the featureIds array) when not\n * specified. EXT_feature_metadata did not have a label field, so such\n * feature ID sets are always labeled \"featureId_N\" where N is the index in\n * the list of all feature Ids, where feature ID attributes are listed before\n * feature ID textures.\n *

\n *

\n * If featureIdLabel is set to an integer N, it is converted to\n * the string \"featureId_N\" automatically. If both per-primitive and\n * per-instance feature IDs are present, the instance feature IDs take\n * priority.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n featureIdLabel: {\n get: function () {\n return this._featureIdLabel;\n },\n set: function (value) {\n // indices get converted into featureId_N\n if (typeof value === \"number\") {\n value = `featureId_${value}`;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"value\", value);\n //>>includeEnd('debug');\n\n this._featureIdLabel = value;\n },\n },\n\n /**\n * Label of the instance feature ID set used for picking and styling.\n *

\n * If instanceFeatureIdLabel is set to an integer N, it is converted to\n * the string \"instanceFeatureId_N\" automatically.\n * If both per-primitive and per-instance feature IDs are present, the\n * instance feature IDs take priority.\n *

\n *\n * @memberof Cesium3DTileset.prototype\n *\n * @type {string}\n * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.\n */\n instanceFeatureIdLabel: {\n get: function () {\n return this._instanceFeatureIdLabel;\n },\n set: function (value) {\n // indices get converted into instanceFeatureId_N\n if (typeof value === \"number\") {\n value = `instanceFeatureId_${value}`;\n }\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"value\", value);\n //>>includeEnd('debug');\n\n this._instanceFeatureIdLabel = value;\n },\n },\n});\n\n/**\n * Creates a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},\n * used for streaming massive heterogeneous 3D geospatial datasets, from a Cesium ion asset ID.\n *\n * @param {number} assetId The Cesium ion asset id.\n * @param {Cesium3DTileset.ConstructorOptions} options An object describing initialization options\n * @returns {Promise}\n *\n * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.\n *\n * @see Cesium3DTileset#fromUrl\n *\n * @example\n * // Load a Cesium3DTileset with a Cesium ion asset ID of 124624234\n * try {\n * const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(124624234);\n * scene.primitives.add(tileset);\n * } catch (error) {\n * console.error(`Error creating tileset: ${error}`);\n * }\n */\nCesium3DTileset.fromIonAssetId = async function (assetId, options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"assetId\", assetId);\n //>>includeEnd('debug');\n\n const resource = await IonResource.fromAssetId(assetId);\n return Cesium3DTileset.fromUrl(resource, options);\n};\n\n/**\n * Creates a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},\n * used for streaming massive heterogeneous 3D geospatial datasets.\n *\n * @param {Resource|string} url The url to a tileset JSON file.\n * @param {Cesium3DTileset.ConstructorOptions} [options] An object describing initialization options\n * @returns {Promise}\n *\n * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.\n *\n * @see Cesium3DTileset#fromIonAssetId\n *\n * @example\n * try {\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\"\n * );\n * scene.primitives.add(tileset);\n * } catch (error) {\n * console.error(`Error creating tileset: ${error}`);\n * }\n *\n * @example\n * // Common setting for the skipLevelOfDetail optimization\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\", {\n * skipLevelOfDetail: true,\n * baseScreenSpaceError: 1024,\n * skipScreenSpaceErrorFactor: 16,\n * skipLevels: 1,\n * immediatelyLoadDesiredLevelOfDetail: false,\n * loadSiblings: false,\n * cullWithChildrenBounds: true\n * });\n * scene.primitives.add(tileset);\n *\n * @example\n * // Common settings for the dynamicScreenSpaceError optimization\n * const tileset = await Cesium.Cesium3DTileset.fromUrl(\n * \"http://localhost:8002/tilesets/Seattle/tileset.json\", {\n * dynamicScreenSpaceError: true,\n * dynamicScreenSpaceErrorDensity: 0.00278,\n * dynamicScreenSpaceErrorFactor: 4.0,\n * dynamicScreenSpaceErrorHeightFalloff: 0.25\n * });\n * scene.primitives.add(tileset);\n */\nCesium3DTileset.fromUrl = async function (url, options) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"url\", url);\n //>>includeEnd('debug');\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const resource = Resource.createIfNeeded(url);\n let basePath;\n if (resource.extension === \"json\") {\n basePath = resource.getBaseUri(true);\n } else if (resource.isDataUri) {\n basePath = \"\";\n }\n\n const tilesetJson = await Cesium3DTileset.loadJson(resource);\n const metadataExtension = await processMetadataExtension(\n resource,\n tilesetJson\n );\n\n const tileset = new Cesium3DTileset(options);\n tileset._resource = resource;\n tileset._url = resource.url;\n tileset._basePath = basePath;\n tileset._metadataExtension = metadataExtension;\n // Set these before loading the tileset since _geometricError\n // and _scaledGeometricError get accessed during tile creation\n tileset._geometricError = tilesetJson.geometricError;\n tileset._scaledGeometricError = tilesetJson.geometricError;\n\n const asset = tilesetJson.asset;\n tileset._asset = asset;\n tileset._extras = tilesetJson.extras;\n\n let credits = resource.credits;\n if (!defined(credits)) {\n credits = [];\n }\n\n const assetExtras = asset.extras;\n if (\n defined(assetExtras) &&\n defined(assetExtras.cesium) &&\n defined(assetExtras.cesium.credits)\n ) {\n const extraCredits = assetExtras.cesium.credits;\n for (let i = 0; i < extraCredits.length; ++i) {\n const credit = extraCredits[i];\n credits.push(new Credit(credit.html, tileset._showCreditsOnScreen));\n }\n }\n tileset._credits = credits;\n\n // Handle legacy gltfUpAxis option\n const gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis)\n ? Axis.fromName(tilesetJson.asset.gltfUpAxis)\n : Axis.Y;\n const modelUpAxis = defaultValue(options.modelUpAxis, gltfUpAxis);\n const modelForwardAxis = defaultValue(options.modelForwardAxis, Axis.X);\n\n tileset._properties = tilesetJson.properties;\n tileset._extensionsUsed = tilesetJson.extensionsUsed;\n tileset._extensions = tilesetJson.extensions;\n tileset._modelUpAxis = modelUpAxis;\n tileset._modelForwardAxis = modelForwardAxis;\n\n tileset._root = tileset.loadTileset(resource, tilesetJson);\n\n // Save the original, untransformed bounding volume position so we can apply\n // the tile transform and model matrix at run time\n const boundingVolume = tileset._root.createBoundingVolume(\n tilesetJson.root.boundingVolume,\n Matrix4.IDENTITY\n );\n const clippingPlanesOrigin = boundingVolume.boundingSphere.center;\n // If this origin is above the surface of the earth\n // we want to apply an ENU orientation as our best guess of orientation.\n // Otherwise, we assume it gets its position/orientation completely from the\n // root tile transform and the tileset's model matrix\n const originCartographic = tileset._ellipsoid.cartesianToCartographic(\n clippingPlanesOrigin\n );\n if (\n defined(originCartographic) &&\n originCartographic.height >\n ApproximateTerrainHeights._defaultMinTerrainHeight\n ) {\n tileset._initialClippingPlanesOriginMatrix = Transforms.eastNorthUpToFixedFrame(\n clippingPlanesOrigin\n );\n }\n tileset._clippingPlanesOriginMatrix = Matrix4.clone(\n tileset._initialClippingPlanesOriginMatrix\n );\n\n return tileset;\n};\n\n/**\n * Provides a hook to override the method used to request the tileset json\n * useful when fetching tilesets from remote servers\n * @param {Resource|string} tilesetUrl The url of the json file to be fetched\n * @returns {Promise} A promise that resolves with the fetched json data\n */\nCesium3DTileset.loadJson = function (tilesetUrl) {\n const resource = Resource.createIfNeeded(tilesetUrl);\n return resource.fetchJson();\n};\n\n/**\n * Marks the tileset's {@link Cesium3DTileset#style} as dirty, which forces all\n * features to re-evaluate the style in the next frame each is visible.\n */\nCesium3DTileset.prototype.makeStyleDirty = function () {\n this._styleEngine.makeDirty();\n};\n\n/**\n * Loads the main tileset JSON file or a tileset JSON file referenced from a tile.\n *\n * @private\n */\nCesium3DTileset.prototype.loadTileset = function (\n resource,\n tilesetJson,\n parentTile\n) {\n const asset = tilesetJson.asset;\n if (!defined(asset)) {\n throw new RuntimeError(\"Tileset must have an asset property.\");\n }\n if (\n asset.version !== \"0.0\" &&\n asset.version !== \"1.0\" &&\n asset.version !== \"1.1\"\n ) {\n throw new RuntimeError(\n \"The tileset must be 3D Tiles version 0.0, 1.0, or 1.1\"\n );\n }\n\n if (defined(tilesetJson.extensionsRequired)) {\n Cesium3DTileset.checkSupportedExtensions(tilesetJson.extensionsRequired);\n }\n\n const statistics = this._statistics;\n\n const tilesetVersion = asset.tilesetVersion;\n if (defined(tilesetVersion)) {\n // Append the tileset version to the resource\n this._basePath += `?v=${tilesetVersion}`;\n resource = resource.clone();\n resource.setQueryParameters({ v: tilesetVersion });\n }\n\n // A tileset JSON file referenced from a tile may exist in a different directory than the root tileset.\n // Get the basePath relative to the external tileset.\n const rootTile = makeTile(this, resource, tilesetJson.root, parentTile);\n\n // If there is a parentTile, add the root of the currently loading tileset\n // to parentTile's children, and update its _depth.\n if (defined(parentTile)) {\n parentTile.children.push(rootTile);\n rootTile._depth = parentTile._depth + 1;\n }\n\n const stack = [];\n stack.push(rootTile);\n\n while (stack.length > 0) {\n const tile = stack.pop();\n ++statistics.numberOfTilesTotal;\n this._allTilesAdditive =\n this._allTilesAdditive && tile.refine === Cesium3DTileRefine.ADD;\n const children = tile._header.children;\n if (defined(children)) {\n for (let i = 0; i < children.length; ++i) {\n const childHeader = children[i];\n const childTile = makeTile(this, resource, childHeader, tile);\n tile.children.push(childTile);\n childTile._depth = tile._depth + 1;\n stack.push(childTile);\n }\n }\n\n if (this._cullWithChildrenBounds) {\n Cesium3DTileOptimizations.checkChildrenWithinParent(tile);\n }\n }\n\n return rootTile;\n};\n\n/**\n * Make a {@link Cesium3DTile} for a specific tile. If the tile's header has implicit\n * tiling (3D Tiles 1.1) or uses the 3DTILES_implicit_tiling extension,\n * it creates a placeholder tile instead for lazy evaluation of the implicit tileset.\n *\n * @param {Cesium3DTileset} tileset The tileset\n * @param {Resource} baseResource The base resource for the tileset\n * @param {object} tileHeader The JSON header for the tile\n * @param {Cesium3DTile} [parentTile] The parent tile of the new tile\n * @returns {Cesium3DTile} The newly created tile\n *\n * @private\n */\nfunction makeTile(tileset, baseResource, tileHeader, parentTile) {\n const hasImplicitTiling =\n defined(tileHeader.implicitTiling) ||\n hasExtension(tileHeader, \"3DTILES_implicit_tiling\");\n\n if (!hasImplicitTiling) {\n return new Cesium3DTile(tileset, baseResource, tileHeader, parentTile);\n }\n\n const metadataSchema = tileset.schema;\n\n const implicitTileset = new ImplicitTileset(\n baseResource,\n tileHeader,\n metadataSchema\n );\n const rootCoordinates = new ImplicitTileCoordinates({\n subdivisionScheme: implicitTileset.subdivisionScheme,\n subtreeLevels: implicitTileset.subtreeLevels,\n level: 0,\n x: 0,\n y: 0,\n // The constructor will only use this for octrees.\n z: 0,\n });\n\n // Create a placeholder Cesium3DTile that has an ImplicitTileset\n // object and whose content will resolve to an Implicit3DTileContent\n const contentUri = implicitTileset.subtreeUriTemplate.getDerivedResource({\n templateValues: rootCoordinates.getTemplateValues(),\n }).url;\n\n const deepCopy = true;\n const tileJson = clone(tileHeader, deepCopy);\n // Replace contents with the subtree\n tileJson.contents = [\n {\n uri: contentUri,\n },\n ];\n\n delete tileJson.content;\n\n // The placeholder tile does not have any extensions. If there are any\n // extensions beyond 3DTILES_implicit_tiling, Implicit3DTileContent will\n // copy them to the transcoded tiles.\n delete tileJson.extensions;\n\n const tile = new Cesium3DTile(tileset, baseResource, tileJson, parentTile);\n tile.implicitTileset = implicitTileset;\n tile.implicitCoordinates = rootCoordinates;\n return tile;\n}\n\n/**\n * If tileset metadata is present, initialize the {@link Cesium3DTilesetMetadata}\n * instance. This is asynchronous since metadata schemas may be external.\n *\n * @param {Cesium3DTileset} tileset The tileset\n * @param {object} tilesetJson The tileset JSON\n * @return {Promise} The loaded Cesium3DTilesetMetadata\n * @private\n */\nasync function processMetadataExtension(resource, tilesetJson) {\n const metadataJson = hasExtension(tilesetJson, \"3DTILES_metadata\")\n ? tilesetJson.extensions[\"3DTILES_metadata\"]\n : tilesetJson;\n\n let schemaLoader;\n if (defined(metadataJson.schemaUri)) {\n resource = resource.getDerivedResource({\n url: metadataJson.schemaUri,\n });\n schemaLoader = ResourceCache.getSchemaLoader({\n resource: resource,\n });\n } else if (defined(metadataJson.schema)) {\n schemaLoader = ResourceCache.getSchemaLoader({\n schema: metadataJson.schema,\n });\n } else {\n return;\n }\n\n await schemaLoader.load();\n\n const metadataExtension = new Cesium3DTilesetMetadata({\n schema: schemaLoader.schema,\n metadataJson: metadataJson,\n });\n\n ResourceCache.unload(schemaLoader);\n\n return metadataExtension;\n}\n\nconst scratchPositionNormal = new Cartesian3();\nconst scratchCartographic = new Cartographic();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Cartesian3();\nconst scratchPosition = new Cartesian3();\nconst scratchDirection = new Cartesian3();\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction updateDynamicScreenSpaceError(tileset, frameState) {\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const camera = frameState.camera;\n const root = tileset._root;\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(\n root.computedTransform,\n scratchMatrix\n );\n const ellipsoid = frameState.mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = tileset.dynamicScreenSpaceErrorHeightFalloff;\n const heightClose =\n minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = CesiumMath.clamp(\n (height - heightClose) / (heightFar - heightClose),\n 0.0,\n 1.0\n );\n\n // Increase density as the camera tilts towards the horizon\n let horizonFactor = 1.0 - Math.abs(Cartesian3.dot(direction, up));\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n tileset._dynamicScreenSpaceErrorComputedDensity =\n tileset.dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction requestContent(tileset, tile) {\n if (tile.hasEmptyContent) {\n return;\n }\n\n const { statistics } = tileset;\n const contentExpired = tile.contentExpired;\n\n const promise = tile.requestContent();\n if (!defined(promise)) {\n return;\n }\n\n promise\n .then((content) => {\n if (!defined(content) || tile.isDestroyed() || tileset.isDestroyed()) {\n return;\n }\n\n tileset._processingQueue.push(tile);\n ++statistics.numberOfTilesProcessing;\n })\n .catch((error) => {\n handleTileFailure(error, tileset, tile);\n });\n\n if (contentExpired) {\n if (tile.hasTilesetContent || tile.hasImplicitContent) {\n destroySubtree(tileset, tile);\n } else {\n statistics.decrementLoadCounts(tile.content);\n --statistics.numberOfTilesWithContentReady;\n }\n }\n\n tileset._requestedTilesInFlight.push(tile);\n}\n\nfunction sortTilesByPriority(a, b) {\n return a._priority - b._priority;\n}\n\n/**\n * Perform any pass invariant tasks here. Called after the render pass.\n * @private\n * @param {FrameState} frameState\n */\nCesium3DTileset.prototype.postPassesUpdate = function (frameState) {\n if (!defined(this._root)) {\n return;\n }\n\n cancelOutOfViewRequests(this, frameState);\n raiseLoadProgressEvent(this, frameState);\n this._cache.unloadTiles(this, unloadTile);\n\n // If the style wasn't able to be applied this frame (for example,\n // the tileset was hidden), keep it dirty so the engine can try\n // to apply the style next frame.\n if (this._styleApplied) {\n this._styleEngine.resetDirty();\n }\n this._styleApplied = false;\n};\n\n/**\n * Perform any pass invariant tasks here. Called before any passes are executed.\n * @private\n * @param {FrameState} frameState\n */\nCesium3DTileset.prototype.prePassesUpdate = function (frameState) {\n if (!defined(this._root)) {\n return;\n }\n\n processTiles(this, frameState);\n\n // Update clipping planes\n const clippingPlanes = this._clippingPlanes;\n this._clippingPlanesOriginMatrixDirty = true;\n if (defined(clippingPlanes) && clippingPlanes.enabled) {\n clippingPlanes.update(frameState);\n }\n\n if (!defined(this._loadTimestamp)) {\n this._loadTimestamp = JulianDate.clone(frameState.time);\n }\n this._timeSinceLoad = Math.max(\n JulianDate.secondsDifference(frameState.time, this._loadTimestamp) * 1000,\n 0.0\n );\n\n if (this.dynamicScreenSpaceError) {\n updateDynamicScreenSpaceError(this, frameState);\n }\n\n if (frameState.newFrame) {\n this._cache.reset();\n }\n};\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction cancelOutOfViewRequests(tileset, frameState) {\n const requestedTilesInFlight = tileset._requestedTilesInFlight;\n let removeCount = 0;\n for (let i = 0; i < requestedTilesInFlight.length; ++i) {\n const tile = requestedTilesInFlight[i];\n\n // NOTE: This is framerate dependant so make sure the threshold check is small\n const outOfView = frameState.frameNumber - tile._touchedFrame >= 1;\n if (tile._contentState !== Cesium3DTileContentState.LOADING) {\n // No longer fetching from host, don't need to track it anymore. Gets marked as LOADING in Cesium3DTile::requestContent().\n ++removeCount;\n continue;\n } else if (outOfView) {\n // RequestScheduler will take care of cancelling it\n tile.cancelRequests();\n ++removeCount;\n continue;\n }\n\n if (removeCount > 0) {\n requestedTilesInFlight[i - removeCount] = tile;\n }\n }\n\n requestedTilesInFlight.length -= removeCount;\n}\n\n/**\n * Sort requests by priority before making any requests.\n * This makes it less likely that requests will be cancelled after being issued.\n * @private\n * @param {Cesium3DTileset} tileset\n */\nfunction requestTiles(tileset) {\n const requestedTiles = tileset._requestedTiles;\n requestedTiles.sort(sortTilesByPriority);\n for (let i = 0; i < requestedTiles.length; ++i) {\n requestContent(tileset, requestedTiles[i]);\n }\n}\n\n/**\n * @private\n * @param {Error} error\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction handleTileFailure(error, tileset, tile) {\n if (tileset.isDestroyed()) {\n return;\n }\n\n let url;\n if (!tile.isDestroyed()) {\n url = tile._contentResource.url;\n }\n\n const message = defined(error.message) ? error.message : error.toString();\n if (tileset.tileFailed.numberOfListeners > 0) {\n tileset.tileFailed.raiseEvent({\n url: url,\n message: message,\n });\n } else {\n console.log(`A 3D tile failed to load: ${url}`);\n console.log(`Error: ${message}`);\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n */\nfunction filterProcessingQueue(tileset) {\n const tiles = tileset._processingQueue;\n\n let removeCount = 0;\n for (let i = 0; i < tiles.length; ++i) {\n const tile = tiles[i];\n if (\n tile.isDestroyed() ||\n tile._contentState !== Cesium3DTileContentState.PROCESSING\n ) {\n ++removeCount;\n continue;\n }\n if (removeCount > 0) {\n tiles[i - removeCount] = tile;\n }\n }\n tiles.length -= removeCount;\n}\n\n/**\n * Process tiles in the PROCESSING state so they will eventually move to the READY state.\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction processTiles(tileset, frameState) {\n filterProcessingQueue(tileset);\n const tiles = tileset._processingQueue;\n\n const { cacheBytes, maximumCacheOverflowBytes, statistics } = tileset;\n const cacheByteLimit = cacheBytes + maximumCacheOverflowBytes;\n\n let memoryExceeded = false;\n for (let i = 0; i < tiles.length; ++i) {\n if (tileset.totalMemoryUsageInBytes > cacheByteLimit) {\n memoryExceeded = true;\n break;\n }\n\n const tile = tiles[i];\n try {\n tile.process(tileset, frameState);\n\n if (tile.contentReady) {\n --statistics.numberOfTilesProcessing;\n tileset.tileLoad.raiseEvent(tile);\n }\n } catch (error) {\n --statistics.numberOfTilesProcessing;\n handleTileFailure(error, tileset, tile);\n }\n }\n\n if (tileset.totalMemoryUsageInBytes < cacheBytes) {\n decreaseScreenSpaceError(tileset);\n } else if (memoryExceeded && tiles.length > 0) {\n increaseScreenSpaceError(tileset);\n }\n}\n\nfunction increaseScreenSpaceError(tileset) {\n //>>includeStart('debug', pragmas.debug);\n oneTimeWarning(\n \"increase-screenSpaceError\",\n `The tiles needed to meet maximumScreenSpaceError would use more memory than allocated for this tileset.\n The tileset will be rendered with a larger screen space error (see memoryAdjustedScreenSpaceError).\n Consider using larger values for cacheBytes and maximumCacheOverflowBytes.`\n );\n //>>includeEnd('debug');\n\n tileset._memoryAdjustedScreenSpaceError *= 1.02;\n const tiles = tileset._processingQueue;\n for (let i = 0; i < tiles.length; ++i) {\n tiles[i].updatePriority();\n }\n tiles.sort(sortTilesByPriority);\n}\n\nfunction decreaseScreenSpaceError(tileset) {\n tileset._memoryAdjustedScreenSpaceError = Math.max(\n tileset.memoryAdjustedScreenSpaceError / 1.02,\n tileset.maximumScreenSpaceError\n );\n}\n\nconst scratchCartesian = new Cartesian3();\n\nconst stringOptions = {\n maximumFractionDigits: 3,\n};\n\n/**\n * @private\n * @param {number} memorySizeInBytes\n * @returns {string}\n */\nfunction formatMemoryString(memorySizeInBytes) {\n const memoryInMegabytes = memorySizeInBytes / 1048576;\n if (memoryInMegabytes < 1.0) {\n return memoryInMegabytes.toLocaleString(undefined, stringOptions);\n }\n return Math.round(memoryInMegabytes).toLocaleString();\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @returns {Cartesian3}\n */\nfunction computeTileLabelPosition(tile) {\n const { halfAxes, radius, center } = tile.boundingVolume.boundingVolume;\n\n let position = Cartesian3.clone(center, scratchCartesian);\n if (defined(halfAxes)) {\n position.x += 0.75 * (halfAxes[0] + halfAxes[3] + halfAxes[6]);\n position.y += 0.75 * (halfAxes[1] + halfAxes[4] + halfAxes[7]);\n position.z += 0.75 * (halfAxes[2] + halfAxes[5] + halfAxes[8]);\n } else if (defined(radius)) {\n let normal = Cartesian3.normalize(center, scratchCartesian);\n normal = Cartesian3.multiplyByScalar(\n normal,\n 0.75 * radius,\n scratchCartesian\n );\n position = Cartesian3.add(normal, center, scratchCartesian);\n }\n return position;\n}\n\n/**\n * @private\n * @param {Cesium3DTile} tile\n * @param {Cesium3DTileset} tileset\n * @param {Cartesian3} position\n * @returns {Label}\n */\nfunction addTileDebugLabel(tile, tileset, position) {\n let labelString = \"\";\n let attributes = 0;\n\n if (tileset.debugShowGeometricError) {\n labelString += `\\nGeometric error: ${tile.geometricError}`;\n attributes++;\n }\n\n if (tileset.debugShowRenderingStatistics) {\n labelString += `\\nCommands: ${tile.commandsLength}`;\n attributes++;\n\n // Don't display number of points or triangles if 0.\n const numberOfPoints = tile.content.pointsLength;\n if (numberOfPoints > 0) {\n labelString += `\\nPoints: ${tile.content.pointsLength}`;\n attributes++;\n }\n\n const numberOfTriangles = tile.content.trianglesLength;\n if (numberOfTriangles > 0) {\n labelString += `\\nTriangles: ${tile.content.trianglesLength}`;\n attributes++;\n }\n\n labelString += `\\nFeatures: ${tile.content.featuresLength}`;\n attributes++;\n }\n\n if (tileset.debugShowMemoryUsage) {\n labelString += `\\nTexture Memory: ${formatMemoryString(\n tile.content.texturesByteLength\n )}`;\n labelString += `\\nGeometry Memory: ${formatMemoryString(\n tile.content.geometryByteLength\n )}`;\n attributes += 2;\n }\n\n if (tileset.debugShowUrl) {\n if (tile.hasMultipleContents) {\n labelString += \"\\nUrls:\";\n const urls = tile.content.innerContentUrls;\n for (let i = 0; i < urls.length; i++) {\n labelString += `\\n- ${urls[i]}`;\n }\n attributes += urls.length;\n } else {\n labelString += `\\nUrl: ${tile._contentHeader.uri}`;\n attributes++;\n }\n }\n\n const newLabel = {\n text: labelString.substring(1),\n position: position,\n font: `${19 - attributes}px sans-serif`,\n showBackground: true,\n disableDepthTestDistance: Number.POSITIVE_INFINITY,\n };\n\n return tileset._tileDebugLabels.add(newLabel);\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction updateTileDebugLabels(tileset, frameState) {\n const selectedTiles = tileset._selectedTiles;\n const selectedLength = selectedTiles.length;\n const emptyTiles = tileset._emptyTiles;\n const emptyLength = emptyTiles.length;\n tileset._tileDebugLabels.removeAll();\n\n if (tileset.debugPickedTileLabelOnly) {\n if (defined(tileset.debugPickedTile)) {\n const position = defined(tileset.debugPickPosition)\n ? tileset.debugPickPosition\n : computeTileLabelPosition(tileset.debugPickedTile);\n const label = addTileDebugLabel(\n tileset.debugPickedTile,\n tileset,\n position\n );\n label.pixelOffset = new Cartesian2(15, -15); // Offset to avoid picking the label.\n }\n } else {\n for (let i = 0; i < selectedLength; ++i) {\n const tile = selectedTiles[i];\n addTileDebugLabel(tile, tileset, computeTileLabelPosition(tile));\n }\n for (let i = 0; i < emptyLength; ++i) {\n const tile = emptyTiles[i];\n if (tile.hasTilesetContent || tile.hasImplicitContent) {\n addTileDebugLabel(tile, tileset, computeTileLabelPosition(tile));\n }\n }\n }\n tileset._tileDebugLabels.update(frameState);\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n * @param {object} passOptions\n */\nfunction updateTiles(tileset, frameState, passOptions) {\n tileset._styleEngine.applyStyle(tileset);\n tileset._styleApplied = true;\n\n const { commandList, context } = frameState;\n const numberOfInitialCommands = commandList.length;\n const selectedTiles = tileset._selectedTiles;\n\n const bivariateVisibilityTest =\n tileset.isSkippingLevelOfDetail &&\n tileset._hasMixedContent &&\n context.stencilBuffer &&\n selectedTiles.length > 0;\n\n tileset._backfaceCommands.length = 0;\n\n if (bivariateVisibilityTest) {\n if (!defined(tileset._stencilClearCommand)) {\n tileset._stencilClearCommand = new ClearCommand({\n stencil: 0,\n pass: Pass.CESIUM_3D_TILE,\n renderState: RenderState.fromCache({\n stencilMask: StencilConstants.SKIP_LOD_MASK,\n }),\n });\n }\n commandList.push(tileset._stencilClearCommand);\n }\n\n const { statistics, tileVisible } = tileset;\n const isRender = passOptions.isRender;\n const lengthBeforeUpdate = commandList.length;\n\n for (let i = 0; i < selectedTiles.length; ++i) {\n const tile = selectedTiles[i];\n // Raise the tileVisible event before update in case the tileVisible event\n // handler makes changes that update needs to apply to WebGL resources\n if (isRender) {\n tileVisible.raiseEvent(tile);\n }\n tile.update(tileset, frameState, passOptions);\n statistics.incrementSelectionCounts(tile.content);\n ++statistics.selected;\n }\n const emptyTiles = tileset._emptyTiles;\n for (let i = 0; i < emptyTiles.length; ++i) {\n const tile = emptyTiles[i];\n tile.update(tileset, frameState, passOptions);\n }\n\n let addedCommandsLength = commandList.length - lengthBeforeUpdate;\n\n tileset._backfaceCommands.trim();\n\n if (bivariateVisibilityTest) {\n /*\n * Consider 'effective leaf' tiles as selected tiles that have no selected descendants. They may have children,\n * but they are currently our effective leaves because they do not have selected descendants. These tiles\n * are those where with tile._finalResolution === true.\n * Let 'unresolved' tiles be those with tile._finalResolution === false.\n *\n * 1. Render just the backfaces of unresolved tiles in order to lay down z\n * 2. Render all frontfaces wherever tile._selectionDepth > stencilBuffer.\n * Replace stencilBuffer with tile._selectionDepth, when passing the z test.\n * Because children are always drawn before ancestors {@link Cesium3DTilesetTraversal#traverseAndSelect},\n * this effectively draws children first and does not draw ancestors if a descendant has already\n * been drawn at that pixel.\n * Step 1 prevents child tiles from appearing on top when they are truly behind ancestor content.\n * If they are behind the backfaces of the ancestor, then they will not be drawn.\n *\n * NOTE: Step 2 sometimes causes visual artifacts when backfacing child content has some faces that\n * partially face the camera and are inside of the ancestor content. Because they are inside, they will\n * not be culled by the depth writes in Step 1, and because they partially face the camera, the stencil tests\n * will draw them on top of the ancestor content.\n *\n * NOTE: Because we always render backfaces of unresolved tiles, if the camera is looking at the backfaces\n * of an object, they will always be drawn while loading, even if backface culling is enabled.\n */\n\n const backfaceCommands = tileset._backfaceCommands.values;\n const backfaceCommandsLength = backfaceCommands.length;\n\n commandList.length += backfaceCommandsLength;\n\n // copy commands to the back of the commandList\n for (let i = addedCommandsLength - 1; i >= 0; --i) {\n commandList[lengthBeforeUpdate + backfaceCommandsLength + i] =\n commandList[lengthBeforeUpdate + i];\n }\n\n // move backface commands to the front of the commandList\n for (let i = 0; i < backfaceCommandsLength; ++i) {\n commandList[lengthBeforeUpdate + i] = backfaceCommands[i];\n }\n }\n\n // Number of commands added by each update above\n addedCommandsLength = commandList.length - numberOfInitialCommands;\n statistics.numberOfCommands = addedCommandsLength;\n\n if (!isRender) {\n return;\n }\n\n // Only run EDL if simple attenuation is on\n if (\n tileset.pointCloudShading.attenuation &&\n tileset.pointCloudShading.eyeDomeLighting &&\n addedCommandsLength > 0\n ) {\n tileset._pointCloudEyeDomeLighting.update(\n frameState,\n numberOfInitialCommands,\n tileset.pointCloudShading,\n tileset.boundingSphere\n );\n }\n\n if (\n tileset.debugShowGeometricError ||\n tileset.debugShowRenderingStatistics ||\n tileset.debugShowMemoryUsage ||\n tileset.debugShowUrl\n ) {\n if (!defined(tileset._tileDebugLabels)) {\n tileset._tileDebugLabels = new LabelCollection();\n }\n updateTileDebugLabels(tileset, frameState);\n } else {\n tileset._tileDebugLabels =\n tileset._tileDebugLabels && tileset._tileDebugLabels.destroy();\n }\n}\n\nconst scratchStack = [];\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction destroySubtree(tileset, tile) {\n const root = tile;\n const stack = scratchStack;\n stack.push(tile);\n while (stack.length > 0) {\n tile = stack.pop();\n const children = tile.children;\n for (let i = 0; i < children.length; ++i) {\n stack.push(children[i]);\n }\n if (tile !== root) {\n destroyTile(tileset, tile);\n --tileset._statistics.numberOfTilesTotal;\n }\n }\n root.children = [];\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction unloadTile(tileset, tile) {\n tileset.tileUnload.raiseEvent(tile);\n tileset._statistics.decrementLoadCounts(tile.content);\n --tileset._statistics.numberOfTilesWithContentReady;\n tile.unloadContent();\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {Cesium3DTile} tile\n */\nfunction destroyTile(tileset, tile) {\n tileset._cache.unloadTile(tileset, tile, unloadTile);\n tile.destroy();\n}\n\n/**\n * Unloads all tiles that weren't selected the previous frame. This can be used to\n * explicitly manage the tile cache and reduce the total number of tiles loaded below\n * {@link Cesium3DTileset#cacheBytes}.\n *

\n * Tile unloads occur at the next frame to keep all the WebGL delete calls\n * within the render loop.\n *

\n */\nCesium3DTileset.prototype.trimLoadedTiles = function () {\n this._cache.trim();\n};\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction raiseLoadProgressEvent(tileset, frameState) {\n const statistics = tileset._statistics;\n const statisticsLast = tileset._statisticsLast;\n\n const numberOfPendingRequests = statistics.numberOfPendingRequests;\n const numberOfTilesProcessing = statistics.numberOfTilesProcessing;\n const lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests;\n const lastNumberOfTilesProcessing = statisticsLast.numberOfTilesProcessing;\n\n Cesium3DTilesetStatistics.clone(statistics, statisticsLast);\n\n const progressChanged =\n numberOfPendingRequests !== lastNumberOfPendingRequest ||\n numberOfTilesProcessing !== lastNumberOfTilesProcessing;\n\n if (progressChanged) {\n frameState.afterRender.push(function () {\n tileset.loadProgress.raiseEvent(\n numberOfPendingRequests,\n numberOfTilesProcessing\n );\n\n return true;\n });\n }\n\n tileset._tilesLoaded =\n statistics.numberOfPendingRequests === 0 &&\n statistics.numberOfTilesProcessing === 0 &&\n statistics.numberOfAttemptedRequests === 0;\n\n // Events are raised (added to the afterRender queue) here since promises\n // may resolve outside of the update loop that then raise events, e.g.,\n // model's readyEvent\n if (progressChanged && tileset._tilesLoaded) {\n frameState.afterRender.push(function () {\n tileset.allTilesLoaded.raiseEvent();\n return true;\n });\n if (!tileset._initialTilesLoaded) {\n tileset._initialTilesLoaded = true;\n frameState.afterRender.push(function () {\n tileset.initialTilesLoaded.raiseEvent();\n return true;\n });\n }\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n */\nfunction resetMinimumMaximum(tileset) {\n tileset._heatmap.resetMinimumMaximum();\n tileset._minimumPriority.depth = Number.MAX_VALUE;\n tileset._maximumPriority.depth = -Number.MAX_VALUE;\n tileset._minimumPriority.foveatedFactor = Number.MAX_VALUE;\n tileset._maximumPriority.foveatedFactor = -Number.MAX_VALUE;\n tileset._minimumPriority.distance = Number.MAX_VALUE;\n tileset._maximumPriority.distance = -Number.MAX_VALUE;\n tileset._minimumPriority.reverseScreenSpaceError = Number.MAX_VALUE;\n tileset._maximumPriority.reverseScreenSpaceError = -Number.MAX_VALUE;\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n */\nfunction detectModelMatrixChanged(tileset, frameState) {\n if (\n frameState.frameNumber === tileset._updatedModelMatrixFrame &&\n defined(tileset._previousModelMatrix)\n ) {\n return;\n }\n\n tileset._updatedModelMatrixFrame = frameState.frameNumber;\n tileset._modelMatrixChanged = !Matrix4.equals(\n tileset.modelMatrix,\n tileset._previousModelMatrix\n );\n if (tileset._modelMatrixChanged) {\n tileset._previousModelMatrix = Matrix4.clone(\n tileset.modelMatrix,\n tileset._previousModelMatrix\n );\n }\n}\n\n/**\n * @private\n * @param {Cesium3DTileset} tileset\n * @param {FrameState} frameState\n * @param {Cesium3DTilesetStatistics} passStatistics\n * @param {object} passOptions\n * @returns {boolean}\n */\nfunction update(tileset, frameState, passStatistics, passOptions) {\n if (frameState.mode === SceneMode.MORPHING) {\n return false;\n }\n\n if (!defined(tileset._root)) {\n return false;\n }\n\n const statistics = tileset._statistics;\n statistics.clear();\n\n // Resets the visibility check for each pass\n ++tileset._updatedVisibilityFrame;\n\n // Update any tracked min max values\n resetMinimumMaximum(tileset);\n\n detectModelMatrixChanged(tileset, frameState);\n tileset._cullRequestsWhileMoving =\n tileset.cullRequestsWhileMoving && !tileset._modelMatrixChanged;\n\n const ready = tileset\n .getTraversal(passOptions)\n .selectTiles(tileset, frameState);\n\n if (passOptions.requestTiles) {\n requestTiles(tileset);\n }\n\n updateTiles(tileset, frameState, passOptions);\n\n // Update pass statistics\n Cesium3DTilesetStatistics.clone(statistics, passStatistics);\n\n if (passOptions.isRender) {\n const credits = tileset._credits;\n if (defined(credits) && statistics.selected !== 0) {\n for (let i = 0; i < credits.length; ++i) {\n const credit = credits[i];\n credit.showOnScreen =\n tileset._showCreditsOnScreen || credit._isDefaultToken;\n frameState.creditDisplay.addCreditToNextFrame(credit);\n }\n }\n }\n\n return ready;\n}\n\n/**\n * @private\n * @param {object} passOptions\n * @returns {Cesium3DTilesetTraversal}\n */\nCesium3DTileset.prototype.getTraversal = function (passOptions) {\n const { pass } = passOptions;\n if (\n pass === Cesium3DTilePass.MOST_DETAILED_PRELOAD ||\n pass === Cesium3DTilePass.MOST_DETAILED_PICK\n ) {\n return Cesium3DTilesetMostDetailedTraversal;\n }\n return this.isSkippingLevelOfDetail\n ? Cesium3DTilesetSkipTraversal\n : Cesium3DTilesetBaseTraversal;\n};\n\n/**\n * @private\n * @param {FrameState} frameState\n */\nCesium3DTileset.prototype.update = function (frameState) {\n this.updateForPass(frameState, frameState.tilesetPassState);\n};\n\n/**\n * @private\n * @param {FrameState} frameState\n * @param {object} tilesetPassState\n */\nCesium3DTileset.prototype.updateForPass = function (\n frameState,\n tilesetPassState\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"frameState\", frameState);\n Check.typeOf.object(\"tilesetPassState\", tilesetPassState);\n //>>includeEnd('debug');\n\n const pass = tilesetPassState.pass;\n if (\n (pass === Cesium3DTilePass.PRELOAD &&\n (!this.preloadWhenHidden || this.show)) ||\n (pass === Cesium3DTilePass.PRELOAD_FLIGHT &&\n (!this.preloadFlightDestinations ||\n (!this.show && !this.preloadWhenHidden))) ||\n (pass === Cesium3DTilePass.REQUEST_RENDER_MODE_DEFER_CHECK &&\n ((!this._cullRequestsWhileMoving && this.foveatedTimeDelay <= 0) ||\n !this.show))\n ) {\n return;\n }\n\n const originalCommandList = frameState.commandList;\n const originalCamera = frameState.camera;\n const originalCullingVolume = frameState.cullingVolume;\n\n tilesetPassState.ready = false;\n\n const passOptions = Cesium3DTilePass.getPassOptions(pass);\n const ignoreCommands = passOptions.ignoreCommands;\n\n const commandList = defaultValue(\n tilesetPassState.commandList,\n originalCommandList\n );\n const commandStart = commandList.length;\n\n frameState.commandList = commandList;\n frameState.camera = defaultValue(tilesetPassState.camera, originalCamera);\n frameState.cullingVolume = defaultValue(\n tilesetPassState.cullingVolume,\n originalCullingVolume\n );\n\n const passStatistics = this._statisticsPerPass[pass];\n\n if (this.show || ignoreCommands) {\n this._pass = pass;\n tilesetPassState.ready = update(\n this,\n frameState,\n passStatistics,\n passOptions\n );\n }\n\n if (ignoreCommands) {\n commandList.length = commandStart;\n }\n\n frameState.commandList = originalCommandList;\n frameState.camera = originalCamera;\n frameState.cullingVolume = originalCullingVolume;\n};\n\n/**\n * true if the tileset JSON file lists the extension in extensionsUsed; otherwise, false.\n * @param {string} extensionName The name of the extension to check.\n *\n * @returns {boolean} true if the tileset JSON file lists the extension in extensionsUsed; otherwise, false.\n */\nCesium3DTileset.prototype.hasExtension = function (extensionName) {\n if (!defined(this._extensionsUsed)) {\n return false;\n }\n\n return this._extensionsUsed.indexOf(extensionName) > -1;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see Cesium3DTileset#destroy\n */\nCesium3DTileset.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * tileset = tileset && tileset.destroy();\n *\n * @see Cesium3DTileset#isDestroyed\n */\nCesium3DTileset.prototype.destroy = function () {\n this._tileDebugLabels =\n this._tileDebugLabels && this._tileDebugLabels.destroy();\n this._clippingPlanes = this._clippingPlanes && this._clippingPlanes.destroy();\n\n // Traverse the tree and destroy all tiles\n if (defined(this._root)) {\n const stack = scratchStack;\n stack.push(this._root);\n\n while (stack.length > 0) {\n const tile = stack.pop();\n tile.destroy();\n\n const children = tile.children;\n for (let i = 0; i < children.length; ++i) {\n stack.push(children[i]);\n }\n }\n }\n this._root = undefined;\n\n if (\n this._shouldDestroyImageBasedLighting &&\n !this._imageBasedLighting.isDestroyed()\n ) {\n this._imageBasedLighting.destroy();\n }\n this._imageBasedLighting = undefined;\n\n return destroyObject(this);\n};\n\nCesium3DTileset.supportedExtensions = {\n \"3DTILES_metadata\": true,\n \"3DTILES_implicit_tiling\": true,\n \"3DTILES_content_gltf\": true,\n \"3DTILES_multiple_contents\": true,\n \"3DTILES_bounding_volume_S2\": true,\n \"3DTILES_batch_table_hierarchy\": true,\n \"3DTILES_draco_point_compression\": true,\n MAXAR_content_geojson: true,\n};\n\n/**\n * Checks to see if a given extension is supported by Cesium3DTileset. If\n * the extension is not supported by Cesium3DTileset, it throws a RuntimeError.\n *\n * @param {object} extensionsRequired The extensions we wish to check\n *\n * @private\n */\nCesium3DTileset.checkSupportedExtensions = function (extensionsRequired) {\n for (let i = 0; i < extensionsRequired.length; i++) {\n if (!Cesium3DTileset.supportedExtensions[extensionsRequired[i]]) {\n throw new RuntimeError(\n `Unsupported 3D Tiles Extension: ${extensionsRequired[i]}`\n );\n }\n }\n};\n\n/**\n * Optimization option. Used as a callback when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how much to raise the screen space error for tiles outside the foveated cone,\n * interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}.\n *\n * @callback Cesium3DTileset.foveatedInterpolationCallback\n * @default Math.lerp\n *\n * @param {number} p The start value to interpolate.\n * @param {number} q The end value to interpolate.\n * @param {number} time The time of interpolation generally in the range [0.0, 1.0].\n * @returns {number} The interpolated value.\n */\nexport default Cesium3DTileset;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Resource from \"../Core/Resource.js\";\nimport Cesium3DTileset from \"../Scene/Cesium3DTileset.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\n\nconst modelMatrixScratch = new Matrix4();\n\n/**\n * A {@link Visualizer} which maps {@link Entity#tileset} to a {@link Cesium3DTileset}.\n * @alias Cesium3DTilesetVisualizer\n * @constructor\n *\n * @param {Scene} scene The scene the primitives will be rendered in.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction Cesium3DTilesetVisualizer(scene, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n if (!defined(entityCollection)) {\n throw new DeveloperError(\"entityCollection is required.\");\n }\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n Cesium3DTilesetVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._scene = scene;\n this._primitives = scene.primitives;\n this._entityCollection = entityCollection;\n this._tilesetHash = {};\n this._entitiesToVisualize = new AssociativeArray();\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\n/**\n * Updates models created this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nCesium3DTilesetVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const entities = this._entitiesToVisualize.values;\n const tilesetHash = this._tilesetHash;\n const primitives = this._primitives;\n\n for (let i = 0, len = entities.length; i < len; i++) {\n const entity = entities[i];\n const tilesetGraphics = entity._tileset;\n\n let resource;\n const tilesetData = tilesetHash[entity.id];\n const show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n Property.getValueOrDefault(tilesetGraphics._show, time, true);\n\n let modelMatrix;\n if (show) {\n modelMatrix = entity.computeModelMatrix(time, modelMatrixScratch);\n resource = Resource.createIfNeeded(\n Property.getValueOrUndefined(tilesetGraphics._uri, time)\n );\n }\n\n const tileset = defined(tilesetData)\n ? tilesetData.tilesetPrimitive\n : undefined;\n\n if (!show) {\n if (defined(tileset)) {\n tileset.show = false;\n }\n continue;\n }\n\n if (!defined(tilesetData) || resource.url !== tilesetData.url) {\n if (defined(tileset)) {\n primitives.removeAndDestroy(tileset);\n }\n\n delete tilesetHash[entity.id];\n\n createTileset(resource, tilesetHash, entity, primitives);\n }\n\n if (!defined(tileset)) {\n continue;\n }\n\n tileset.show = true;\n if (defined(modelMatrix)) {\n tileset.modelMatrix = modelMatrix;\n }\n tileset.maximumScreenSpaceError = Property.getValueOrDefault(\n tilesetGraphics.maximumScreenSpaceError,\n time,\n tileset.maximumScreenSpaceError\n );\n }\n\n return true;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nCesium3DTilesetVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nCesium3DTilesetVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n Cesium3DTilesetVisualizer.prototype._onCollectionChanged,\n this\n );\n const entities = this._entitiesToVisualize.values;\n const tilesetHash = this._tilesetHash;\n const primitives = this._primitives;\n for (let i = entities.length - 1; i > -1; i--) {\n removeTileset(this, entities[i], tilesetHash, primitives);\n }\n return destroyObject(this);\n};\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nCesium3DTilesetVisualizer.prototype.getBoundingSphere = function (\n entity,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const tilesetData = this._tilesetHash[entity.id];\n if (!defined(tilesetData) || tilesetData.loadFail) {\n return BoundingSphereState.FAILED;\n }\n\n const primitive = tilesetData.tilesetPrimitive;\n if (!defined(primitive)) {\n return BoundingSphereState.PENDING;\n }\n\n if (!primitive.show) {\n return BoundingSphereState.FAILED;\n }\n\n BoundingSphere.clone(primitive.boundingSphere, result);\n\n return BoundingSphereState.DONE;\n};\n\n/**\n * @private\n */\nCesium3DTilesetVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n const entities = this._entitiesToVisualize;\n const tilesetHash = this._tilesetHash;\n const primitives = this._primitives;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._tileset)) {\n entities.set(entity.id, entity);\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._tileset)) {\n entities.set(entity.id, entity);\n } else {\n removeTileset(this, entity, tilesetHash, primitives);\n entities.remove(entity.id);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n removeTileset(this, entity, tilesetHash, primitives);\n entities.remove(entity.id);\n }\n};\n\nfunction removeTileset(visualizer, entity, tilesetHash, primitives) {\n const tilesetData = tilesetHash[entity.id];\n if (defined(tilesetData)) {\n if (defined(tilesetData.tilesetPrimitive)) {\n primitives.removeAndDestroy(tilesetData.tilesetPrimitive);\n }\n delete tilesetHash[entity.id];\n }\n}\n\nasync function createTileset(resource, tilesetHash, entity, primitives) {\n tilesetHash[entity.id] = {\n url: resource.url,\n loadFail: false,\n };\n\n try {\n const tileset = await Cesium3DTileset.fromUrl(resource);\n tileset.id = entity;\n primitives.add(tileset);\n\n if (!defined(tilesetHash[entity.id])) {\n return;\n }\n\n tilesetHash[entity.id].tilesetPrimitive = tileset;\n } catch (error) {\n console.error(error);\n tilesetHash[entity.id].loadFail = true;\n }\n}\n\nexport default Cesium3DTilesetVisualizer;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultEvenColor = Color.WHITE;\nconst defaultOddColor = Color.BLACK;\nconst defaultRepeat = new Cartesian2(2.0, 2.0);\n\n/**\n * A {@link MaterialProperty} that maps to checkerboard {@link Material} uniforms.\n * @alias CheckerboardMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Color} [options.evenColor=Color.WHITE] A Property specifying the first {@link Color}.\n * @param {Property|Color} [options.oddColor=Color.BLACK] A Property specifying the second {@link Color}.\n * @param {Property|Cartesian2} [options.repeat=new Cartesian2(2.0, 2.0)] A {@link Cartesian2} Property specifying how many times the tiles repeat in each direction.\n */\nfunction CheckerboardMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._evenColor = undefined;\n this._evenColorSubscription = undefined;\n this._oddColor = undefined;\n this._oddColorSubscription = undefined;\n this._repeat = undefined;\n this._repeatSubscription = undefined;\n\n this.evenColor = options.evenColor;\n this.oddColor = options.oddColor;\n this.repeat = options.repeat;\n}\n\nObject.defineProperties(CheckerboardMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof CheckerboardMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._evenColor) && //\n Property.isConstant(this._oddColor) && //\n Property.isConstant(this._repeat)\n );\n },\n },\n\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof CheckerboardMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the Property specifying the first {@link Color}.\n * @memberof CheckerboardMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n evenColor: createPropertyDescriptor(\"evenColor\"),\n\n /**\n * Gets or sets the Property specifying the second {@link Color}.\n * @memberof CheckerboardMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n oddColor: createPropertyDescriptor(\"oddColor\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying how many times the tiles repeat in each direction.\n * @memberof CheckerboardMaterialProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(2.0, 2.0)\n */\n repeat: createPropertyDescriptor(\"repeat\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nCheckerboardMaterialProperty.prototype.getType = function (time) {\n return \"Checkerboard\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nCheckerboardMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.lightColor = Property.getValueOrClonedDefault(\n this._evenColor,\n time,\n defaultEvenColor,\n result.lightColor\n );\n result.darkColor = Property.getValueOrClonedDefault(\n this._oddColor,\n time,\n defaultOddColor,\n result.darkColor\n );\n result.repeat = Property.getValueOrDefault(this._repeat, time, defaultRepeat);\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCheckerboardMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof CheckerboardMaterialProperty && //\n Property.equals(this._evenColor, other._evenColor) && //\n Property.equals(this._oddColor, other._oddColor) && //\n Property.equals(this._repeat, other._repeat))\n );\n};\nexport default CheckerboardMaterialProperty;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport Entity from \"./Entity.js\";\n\nconst entityOptionsScratch = {\n id: undefined,\n};\n\nfunction fireChangedEvent(collection) {\n if (collection._firing) {\n collection._refire = true;\n return;\n }\n\n if (collection._suspendCount === 0) {\n const added = collection._addedEntities;\n const removed = collection._removedEntities;\n const changed = collection._changedEntities;\n if (changed.length !== 0 || added.length !== 0 || removed.length !== 0) {\n collection._firing = true;\n do {\n collection._refire = false;\n const addedArray = added.values.slice(0);\n const removedArray = removed.values.slice(0);\n const changedArray = changed.values.slice(0);\n\n added.removeAll();\n removed.removeAll();\n changed.removeAll();\n collection._collectionChanged.raiseEvent(\n collection,\n addedArray,\n removedArray,\n changedArray\n );\n } while (collection._refire);\n collection._firing = false;\n }\n }\n}\n\n/**\n * An observable collection of {@link Entity} instances where each entity has a unique id.\n * @alias EntityCollection\n * @constructor\n *\n * @param {DataSource|CompositeEntityCollection} [owner] The data source (or composite entity collection) which created this collection.\n */\nfunction EntityCollection(owner) {\n this._owner = owner;\n this._entities = new AssociativeArray();\n this._addedEntities = new AssociativeArray();\n this._removedEntities = new AssociativeArray();\n this._changedEntities = new AssociativeArray();\n this._suspendCount = 0;\n this._collectionChanged = new Event();\n this._id = createGuid();\n this._show = true;\n this._firing = false;\n this._refire = false;\n}\n\n/**\n * Prevents {@link EntityCollection#collectionChanged} events from being raised\n * until a corresponding call is made to {@link EntityCollection#resumeEvents}, at which\n * point a single event will be raised that covers all suspended operations.\n * This allows for many items to be added and removed efficiently.\n * This function can be safely called multiple times as long as there\n * are corresponding calls to {@link EntityCollection#resumeEvents}.\n */\nEntityCollection.prototype.suspendEvents = function () {\n this._suspendCount++;\n};\n\n/**\n * Resumes raising {@link EntityCollection#collectionChanged} events immediately\n * when an item is added or removed. Any modifications made while while events were suspended\n * will be triggered as a single event when this function is called.\n * This function is reference counted and can safely be called multiple times as long as there\n * are corresponding calls to {@link EntityCollection#resumeEvents}.\n *\n * @exception {DeveloperError} resumeEvents can not be called before suspendEvents.\n */\nEntityCollection.prototype.resumeEvents = function () {\n //>>includeStart('debug', pragmas.debug);\n if (this._suspendCount === 0) {\n throw new DeveloperError(\n \"resumeEvents can not be called before suspendEvents.\"\n );\n }\n //>>includeEnd('debug');\n\n this._suspendCount--;\n fireChangedEvent(this);\n};\n\n/**\n * The signature of the event generated by {@link EntityCollection#collectionChanged}.\n * @callback EntityCollection.CollectionChangedEventCallback\n *\n * @param {EntityCollection} collection The collection that triggered the event.\n * @param {Entity[]} added The array of {@link Entity} instances that have been added to the collection.\n * @param {Entity[]} removed The array of {@link Entity} instances that have been removed from the collection.\n * @param {Entity[]} changed The array of {@link Entity} instances that have been modified.\n */\n\nObject.defineProperties(EntityCollection.prototype, {\n /**\n * Gets the event that is fired when entities are added or removed from the collection.\n * The generated event is a {@link EntityCollection.CollectionChangedEventCallback}.\n * @memberof EntityCollection.prototype\n * @readonly\n * @type {Event}\n */\n collectionChanged: {\n get: function () {\n return this._collectionChanged;\n },\n },\n /**\n * Gets a globally unique identifier for this collection.\n * @memberof EntityCollection.prototype\n * @readonly\n * @type {string}\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * Gets the array of Entity instances in the collection.\n * This array should not be modified directly.\n * @memberof EntityCollection.prototype\n * @readonly\n * @type {Entity[]}\n */\n values: {\n get: function () {\n return this._entities.values;\n },\n },\n /**\n * Gets whether or not this entity collection should be\n * displayed. When true, each entity is only displayed if\n * its own show property is also true.\n * @memberof EntityCollection.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (value === this._show) {\n return;\n }\n\n //Since entity.isShowing includes the EntityCollection.show state\n //in its calculation, we need to loop over the entities array\n //twice, once to get the old showing value and a second time\n //to raise the changed event.\n this.suspendEvents();\n\n let i;\n const oldShows = [];\n const entities = this._entities.values;\n const entitiesLength = entities.length;\n\n for (i = 0; i < entitiesLength; i++) {\n oldShows.push(entities[i].isShowing);\n }\n\n this._show = value;\n\n for (i = 0; i < entitiesLength; i++) {\n const oldShow = oldShows[i];\n const entity = entities[i];\n if (oldShow !== entity.isShowing) {\n entity.definitionChanged.raiseEvent(\n entity,\n \"isShowing\",\n entity.isShowing,\n oldShow\n );\n }\n }\n\n this.resumeEvents();\n },\n },\n /**\n * Gets the owner of this entity collection, ie. the data source or composite entity collection which created it.\n * @memberof EntityCollection.prototype\n * @readonly\n * @type {DataSource|CompositeEntityCollection}\n */\n owner: {\n get: function () {\n return this._owner;\n },\n },\n});\n\n/**\n * Computes the maximum availability of the entities in the collection.\n * If the collection contains a mix of infinitely available data and non-infinite data,\n * it will return the interval pertaining to the non-infinite data only. If all\n * data is infinite, an infinite interval will be returned.\n *\n * @returns {TimeInterval} The availability of entities in the collection.\n */\nEntityCollection.prototype.computeAvailability = function () {\n let startTime = Iso8601.MAXIMUM_VALUE;\n let stopTime = Iso8601.MINIMUM_VALUE;\n const entities = this._entities.values;\n for (let i = 0, len = entities.length; i < len; i++) {\n const entity = entities[i];\n const availability = entity.availability;\n if (defined(availability)) {\n const start = availability.start;\n const stop = availability.stop;\n if (\n JulianDate.lessThan(start, startTime) &&\n !start.equals(Iso8601.MINIMUM_VALUE)\n ) {\n startTime = start;\n }\n if (\n JulianDate.greaterThan(stop, stopTime) &&\n !stop.equals(Iso8601.MAXIMUM_VALUE)\n ) {\n stopTime = stop;\n }\n }\n }\n\n if (Iso8601.MAXIMUM_VALUE.equals(startTime)) {\n startTime = Iso8601.MINIMUM_VALUE;\n }\n if (Iso8601.MINIMUM_VALUE.equals(stopTime)) {\n stopTime = Iso8601.MAXIMUM_VALUE;\n }\n return new TimeInterval({\n start: startTime,\n stop: stopTime,\n });\n};\n\n/**\n * Add an entity to the collection.\n *\n * @param {Entity | Entity.ConstructorOptions} entity The entity to be added.\n * @returns {Entity} The entity that was added.\n * @exception {DeveloperError} An entity with already exists in this collection.\n */\nEntityCollection.prototype.add = function (entity) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n //>>includeEnd('debug');\n\n if (!(entity instanceof Entity)) {\n entity = new Entity(entity);\n }\n\n const id = entity.id;\n const entities = this._entities;\n if (entities.contains(id)) {\n throw new RuntimeError(\n `An entity with id ${id} already exists in this collection.`\n );\n }\n\n entity.entityCollection = this;\n entities.set(id, entity);\n\n if (!this._removedEntities.remove(id)) {\n this._addedEntities.set(id, entity);\n }\n entity.definitionChanged.addEventListener(\n EntityCollection.prototype._onEntityDefinitionChanged,\n this\n );\n\n fireChangedEvent(this);\n return entity;\n};\n\n/**\n * Removes an entity from the collection.\n *\n * @param {Entity} entity The entity to be removed.\n * @returns {boolean} true if the item was removed, false if it did not exist in the collection.\n */\nEntityCollection.prototype.remove = function (entity) {\n if (!defined(entity)) {\n return false;\n }\n return this.removeById(entity.id);\n};\n\n/**\n * Returns true if the provided entity is in this collection, false otherwise.\n *\n * @param {Entity} entity The entity.\n * @returns {boolean} true if the provided entity is in this collection, false otherwise.\n */\nEntityCollection.prototype.contains = function (entity) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required\");\n }\n //>>includeEnd('debug');\n return this._entities.get(entity.id) === entity;\n};\n\n/**\n * Removes an entity with the provided id from the collection.\n *\n * @param {string} id The id of the entity to remove.\n * @returns {boolean} true if the item was removed, false if no item with the provided id existed in the collection.\n */\nEntityCollection.prototype.removeById = function (id) {\n if (!defined(id)) {\n return false;\n }\n\n const entities = this._entities;\n const entity = entities.get(id);\n if (!this._entities.remove(id)) {\n return false;\n }\n\n if (!this._addedEntities.remove(id)) {\n this._removedEntities.set(id, entity);\n this._changedEntities.remove(id);\n }\n this._entities.remove(id);\n entity.definitionChanged.removeEventListener(\n EntityCollection.prototype._onEntityDefinitionChanged,\n this\n );\n fireChangedEvent(this);\n\n return true;\n};\n\n/**\n * Removes all Entities from the collection.\n */\nEntityCollection.prototype.removeAll = function () {\n //The event should only contain items added before events were suspended\n //and the contents of the collection.\n const entities = this._entities;\n const entitiesLength = entities.length;\n const array = entities.values;\n\n const addedEntities = this._addedEntities;\n const removed = this._removedEntities;\n\n for (let i = 0; i < entitiesLength; i++) {\n const existingItem = array[i];\n const existingItemId = existingItem.id;\n const addedItem = addedEntities.get(existingItemId);\n if (!defined(addedItem)) {\n existingItem.definitionChanged.removeEventListener(\n EntityCollection.prototype._onEntityDefinitionChanged,\n this\n );\n removed.set(existingItemId, existingItem);\n }\n }\n\n entities.removeAll();\n addedEntities.removeAll();\n this._changedEntities.removeAll();\n fireChangedEvent(this);\n};\n\n/**\n * Gets an entity with the specified id.\n *\n * @param {string} id The id of the entity to retrieve.\n * @returns {Entity|undefined} The entity with the provided id or undefined if the id did not exist in the collection.\n */\nEntityCollection.prototype.getById = function (id) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n //>>includeEnd('debug');\n\n return this._entities.get(id);\n};\n\n/**\n * Gets an entity with the specified id or creates it and adds it to the collection if it does not exist.\n *\n * @param {string} id The id of the entity to retrieve or create.\n * @returns {Entity} The new or existing object.\n */\nEntityCollection.prototype.getOrCreateEntity = function (id) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required.\");\n }\n //>>includeEnd('debug');\n\n let entity = this._entities.get(id);\n if (!defined(entity)) {\n entityOptionsScratch.id = id;\n entity = new Entity(entityOptionsScratch);\n this.add(entity);\n }\n return entity;\n};\n\nEntityCollection.prototype._onEntityDefinitionChanged = function (entity) {\n const id = entity.id;\n if (!this._addedEntities.contains(id)) {\n this._changedEntities.set(id, entity);\n }\n fireChangedEvent(this);\n};\nexport default EntityCollection;\n", "import createGuid from \"../Core/createGuid.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Entity from \"./Entity.js\";\nimport EntityCollection from \"./EntityCollection.js\";\n\nconst entityOptionsScratch = {\n id: undefined,\n};\nconst entityIdScratch = new Array(2);\n\nfunction clean(entity) {\n const propertyNames = entity.propertyNames;\n const propertyNamesLength = propertyNames.length;\n for (let i = 0; i < propertyNamesLength; i++) {\n entity[propertyNames[i]] = undefined;\n }\n entity._name = undefined;\n entity._availability = undefined;\n}\n\nfunction subscribeToEntity(that, eventHash, collectionId, entity) {\n entityIdScratch[0] = collectionId;\n entityIdScratch[1] = entity.id;\n eventHash[\n JSON.stringify(entityIdScratch)\n ] = entity.definitionChanged.addEventListener(\n CompositeEntityCollection.prototype._onDefinitionChanged,\n that\n );\n}\n\nfunction unsubscribeFromEntity(that, eventHash, collectionId, entity) {\n entityIdScratch[0] = collectionId;\n entityIdScratch[1] = entity.id;\n const id = JSON.stringify(entityIdScratch);\n eventHash[id]();\n eventHash[id] = undefined;\n}\n\nfunction recomposite(that) {\n that._shouldRecomposite = true;\n if (that._suspendCount !== 0) {\n return;\n }\n\n const collections = that._collections;\n const collectionsLength = collections.length;\n\n const collectionsCopy = that._collectionsCopy;\n const collectionsCopyLength = collectionsCopy.length;\n\n let i;\n let entity;\n let entities;\n let iEntities;\n let collection;\n const composite = that._composite;\n const newEntities = new EntityCollection(that);\n const eventHash = that._eventHash;\n let collectionId;\n\n for (i = 0; i < collectionsCopyLength; i++) {\n collection = collectionsCopy[i];\n collection.collectionChanged.removeEventListener(\n CompositeEntityCollection.prototype._onCollectionChanged,\n that\n );\n entities = collection.values;\n collectionId = collection.id;\n for (iEntities = entities.length - 1; iEntities > -1; iEntities--) {\n entity = entities[iEntities];\n unsubscribeFromEntity(that, eventHash, collectionId, entity);\n }\n }\n\n for (i = collectionsLength - 1; i >= 0; i--) {\n collection = collections[i];\n collection.collectionChanged.addEventListener(\n CompositeEntityCollection.prototype._onCollectionChanged,\n that\n );\n\n //Merge all of the existing entities.\n entities = collection.values;\n collectionId = collection.id;\n for (iEntities = entities.length - 1; iEntities > -1; iEntities--) {\n entity = entities[iEntities];\n subscribeToEntity(that, eventHash, collectionId, entity);\n\n let compositeEntity = newEntities.getById(entity.id);\n if (!defined(compositeEntity)) {\n compositeEntity = composite.getById(entity.id);\n if (!defined(compositeEntity)) {\n entityOptionsScratch.id = entity.id;\n compositeEntity = new Entity(entityOptionsScratch);\n } else {\n clean(compositeEntity);\n }\n newEntities.add(compositeEntity);\n }\n compositeEntity.merge(entity);\n }\n }\n that._collectionsCopy = collections.slice(0);\n\n composite.suspendEvents();\n composite.removeAll();\n const newEntitiesArray = newEntities.values;\n for (i = 0; i < newEntitiesArray.length; i++) {\n composite.add(newEntitiesArray[i]);\n }\n composite.resumeEvents();\n}\n\n/**\n * Non-destructively composites multiple {@link EntityCollection} instances into a single collection.\n * If a Entity with the same ID exists in multiple collections, it is non-destructively\n * merged into a single new entity instance. If an entity has the same property in multiple\n * collections, the property of the Entity in the last collection of the list it\n * belongs to is used. CompositeEntityCollection can be used almost anywhere that a\n * EntityCollection is used.\n *\n * @alias CompositeEntityCollection\n * @constructor\n *\n * @param {EntityCollection[]} [collections] The initial list of EntityCollection instances to merge.\n * @param {DataSource|CompositeEntityCollection} [owner] The data source (or composite entity collection) which created this collection.\n */\nfunction CompositeEntityCollection(collections, owner) {\n this._owner = owner;\n this._composite = new EntityCollection(this);\n this._suspendCount = 0;\n this._collections = defined(collections) ? collections.slice() : [];\n this._collectionsCopy = [];\n this._id = createGuid();\n this._eventHash = {};\n recomposite(this);\n this._shouldRecomposite = false;\n}\n\nObject.defineProperties(CompositeEntityCollection.prototype, {\n /**\n * Gets the event that is fired when entities are added or removed from the collection.\n * The generated event is a {@link EntityCollection.collectionChangedEventCallback}.\n * @memberof CompositeEntityCollection.prototype\n * @readonly\n * @type {Event}\n */\n collectionChanged: {\n get: function () {\n return this._composite._collectionChanged;\n },\n },\n /**\n * Gets a globally unique identifier for this collection.\n * @memberof CompositeEntityCollection.prototype\n * @readonly\n * @type {string}\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * Gets the array of Entity instances in the collection.\n * This array should not be modified directly.\n * @memberof CompositeEntityCollection.prototype\n * @readonly\n * @type {Entity[]}\n */\n values: {\n get: function () {\n return this._composite.values;\n },\n },\n /**\n * Gets the owner of this composite entity collection, ie. the data source or composite entity collection which created it.\n * @memberof CompositeEntityCollection.prototype\n * @readonly\n * @type {DataSource|CompositeEntityCollection}\n */\n owner: {\n get: function () {\n return this._owner;\n },\n },\n});\n\n/**\n * Adds a collection to the composite.\n *\n * @param {EntityCollection} collection the collection to add.\n * @param {number} [index] the index to add the collection at. If omitted, the collection will\n * added on top of all existing collections.\n *\n * @exception {DeveloperError} index, if supplied, must be greater than or equal to zero and less than or equal to the number of collections.\n */\nCompositeEntityCollection.prototype.addCollection = function (\n collection,\n index\n) {\n const hasIndex = defined(index);\n //>>includeStart('debug', pragmas.debug);\n if (!defined(collection)) {\n throw new DeveloperError(\"collection is required.\");\n }\n if (hasIndex) {\n if (index < 0) {\n throw new DeveloperError(\"index must be greater than or equal to zero.\");\n } else if (index > this._collections.length) {\n throw new DeveloperError(\n \"index must be less than or equal to the number of collections.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n if (!hasIndex) {\n index = this._collections.length;\n this._collections.push(collection);\n } else {\n this._collections.splice(index, 0, collection);\n }\n\n recomposite(this);\n};\n\n/**\n * Removes a collection from this composite, if present.\n *\n * @param {EntityCollection} collection The collection to remove.\n * @returns {boolean} true if the collection was in the composite and was removed,\n * false if the collection was not in the composite.\n */\nCompositeEntityCollection.prototype.removeCollection = function (collection) {\n const index = this._collections.indexOf(collection);\n if (index !== -1) {\n this._collections.splice(index, 1);\n recomposite(this);\n return true;\n }\n return false;\n};\n\n/**\n * Removes all collections from this composite.\n */\nCompositeEntityCollection.prototype.removeAllCollections = function () {\n this._collections.length = 0;\n recomposite(this);\n};\n\n/**\n * Checks to see if the composite contains a given collection.\n *\n * @param {EntityCollection} collection the collection to check for.\n * @returns {boolean} true if the composite contains the collection, false otherwise.\n */\nCompositeEntityCollection.prototype.containsCollection = function (collection) {\n return this._collections.indexOf(collection) !== -1;\n};\n\n/**\n * Returns true if the provided entity is in this collection, false otherwise.\n *\n * @param {Entity} entity The entity.\n * @returns {boolean} true if the provided entity is in this collection, false otherwise.\n */\nCompositeEntityCollection.prototype.contains = function (entity) {\n return this._composite.contains(entity);\n};\n\n/**\n * Determines the index of a given collection in the composite.\n *\n * @param {EntityCollection} collection The collection to find the index of.\n * @returns {number} The index of the collection in the composite, or -1 if the collection does not exist in the composite.\n */\nCompositeEntityCollection.prototype.indexOfCollection = function (collection) {\n return this._collections.indexOf(collection);\n};\n\n/**\n * Gets a collection by index from the composite.\n *\n * @param {number} index the index to retrieve.\n */\nCompositeEntityCollection.prototype.getCollection = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\", \"index\");\n }\n //>>includeEnd('debug');\n\n return this._collections[index];\n};\n\n/**\n * Gets the number of collections in this composite.\n */\nCompositeEntityCollection.prototype.getCollectionsLength = function () {\n return this._collections.length;\n};\n\nfunction getCollectionIndex(collections, collection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(collection)) {\n throw new DeveloperError(\"collection is required.\");\n }\n //>>includeEnd('debug');\n\n const index = collections.indexOf(collection);\n\n //>>includeStart('debug', pragmas.debug);\n if (index === -1) {\n throw new DeveloperError(\"collection is not in this composite.\");\n }\n //>>includeEnd('debug');\n\n return index;\n}\n\nfunction swapCollections(composite, i, j) {\n const arr = composite._collections;\n i = CesiumMath.clamp(i, 0, arr.length - 1);\n j = CesiumMath.clamp(j, 0, arr.length - 1);\n\n if (i === j) {\n return;\n }\n\n const temp = arr[i];\n arr[i] = arr[j];\n arr[j] = temp;\n\n recomposite(composite);\n}\n\n/**\n * Raises a collection up one position in the composite.\n *\n * @param {EntityCollection} collection the collection to move.\n *\n * @exception {DeveloperError} collection is not in this composite.\n */\nCompositeEntityCollection.prototype.raiseCollection = function (collection) {\n const index = getCollectionIndex(this._collections, collection);\n swapCollections(this, index, index + 1);\n};\n\n/**\n * Lowers a collection down one position in the composite.\n *\n * @param {EntityCollection} collection the collection to move.\n *\n * @exception {DeveloperError} collection is not in this composite.\n */\nCompositeEntityCollection.prototype.lowerCollection = function (collection) {\n const index = getCollectionIndex(this._collections, collection);\n swapCollections(this, index, index - 1);\n};\n\n/**\n * Raises a collection to the top of the composite.\n *\n * @param {EntityCollection} collection the collection to move.\n *\n * @exception {DeveloperError} collection is not in this composite.\n */\nCompositeEntityCollection.prototype.raiseCollectionToTop = function (\n collection\n) {\n const index = getCollectionIndex(this._collections, collection);\n if (index === this._collections.length - 1) {\n return;\n }\n this._collections.splice(index, 1);\n this._collections.push(collection);\n\n recomposite(this);\n};\n\n/**\n * Lowers a collection to the bottom of the composite.\n *\n * @param {EntityCollection} collection the collection to move.\n *\n * @exception {DeveloperError} collection is not in this composite.\n */\nCompositeEntityCollection.prototype.lowerCollectionToBottom = function (\n collection\n) {\n const index = getCollectionIndex(this._collections, collection);\n if (index === 0) {\n return;\n }\n this._collections.splice(index, 1);\n this._collections.splice(0, 0, collection);\n\n recomposite(this);\n};\n\n/**\n * Prevents {@link EntityCollection#collectionChanged} events from being raised\n * until a corresponding call is made to {@link EntityCollection#resumeEvents}, at which\n * point a single event will be raised that covers all suspended operations.\n * This allows for many items to be added and removed efficiently.\n * While events are suspended, recompositing of the collections will\n * also be suspended, as this can be a costly operation.\n * This function can be safely called multiple times as long as there\n * are corresponding calls to {@link EntityCollection#resumeEvents}.\n */\nCompositeEntityCollection.prototype.suspendEvents = function () {\n this._suspendCount++;\n this._composite.suspendEvents();\n};\n\n/**\n * Resumes raising {@link EntityCollection#collectionChanged} events immediately\n * when an item is added or removed. Any modifications made while while events were suspended\n * will be triggered as a single event when this function is called. This function also ensures\n * the collection is recomposited if events are also resumed.\n * This function is reference counted and can safely be called multiple times as long as there\n * are corresponding calls to {@link EntityCollection#resumeEvents}.\n *\n * @exception {DeveloperError} resumeEvents can not be called before suspendEvents.\n */\nCompositeEntityCollection.prototype.resumeEvents = function () {\n //>>includeStart('debug', pragmas.debug);\n if (this._suspendCount === 0) {\n throw new DeveloperError(\n \"resumeEvents can not be called before suspendEvents.\"\n );\n }\n //>>includeEnd('debug');\n\n this._suspendCount--;\n // recomposite before triggering events (but only if required for performance) that might depend on a composited collection\n if (this._shouldRecomposite && this._suspendCount === 0) {\n recomposite(this);\n this._shouldRecomposite = false;\n }\n\n this._composite.resumeEvents();\n};\n\n/**\n * Computes the maximum availability of the entities in the collection.\n * If the collection contains a mix of infinitely available data and non-infinite data,\n * It will return the interval pertaining to the non-infinite data only. If all\n * data is infinite, an infinite interval will be returned.\n *\n * @returns {TimeInterval} The availability of entities in the collection.\n */\nCompositeEntityCollection.prototype.computeAvailability = function () {\n return this._composite.computeAvailability();\n};\n\n/**\n * Gets an entity with the specified id.\n *\n * @param {string} id The id of the entity to retrieve.\n * @returns {Entity|undefined} The entity with the provided id or undefined if the id did not exist in the collection.\n */\nCompositeEntityCollection.prototype.getById = function (id) {\n return this._composite.getById(id);\n};\n\nCompositeEntityCollection.prototype._onCollectionChanged = function (\n collection,\n added,\n removed\n) {\n const collections = this._collectionsCopy;\n const collectionsLength = collections.length;\n const composite = this._composite;\n composite.suspendEvents();\n\n let i;\n let q;\n let entity;\n let compositeEntity;\n const removedLength = removed.length;\n const eventHash = this._eventHash;\n const collectionId = collection.id;\n for (i = 0; i < removedLength; i++) {\n const removedEntity = removed[i];\n unsubscribeFromEntity(this, eventHash, collectionId, removedEntity);\n\n const removedId = removedEntity.id;\n //Check if the removed entity exists in any of the remaining collections\n //If so, we clean and remerge it.\n for (q = collectionsLength - 1; q >= 0; q--) {\n entity = collections[q].getById(removedId);\n if (defined(entity)) {\n if (!defined(compositeEntity)) {\n compositeEntity = composite.getById(removedId);\n clean(compositeEntity);\n }\n compositeEntity.merge(entity);\n }\n }\n //We never retrieved the compositeEntity, which means it no longer\n //exists in any of the collections, remove it from the composite.\n if (!defined(compositeEntity)) {\n composite.removeById(removedId);\n }\n compositeEntity = undefined;\n }\n\n const addedLength = added.length;\n for (i = 0; i < addedLength; i++) {\n const addedEntity = added[i];\n subscribeToEntity(this, eventHash, collectionId, addedEntity);\n\n const addedId = addedEntity.id;\n //We know the added entity exists in at least one collection,\n //but we need to check all collections and re-merge in order\n //to maintain the priority of properties.\n for (q = collectionsLength - 1; q >= 0; q--) {\n entity = collections[q].getById(addedId);\n if (defined(entity)) {\n if (!defined(compositeEntity)) {\n compositeEntity = composite.getById(addedId);\n if (!defined(compositeEntity)) {\n entityOptionsScratch.id = addedId;\n compositeEntity = new Entity(entityOptionsScratch);\n composite.add(compositeEntity);\n } else {\n clean(compositeEntity);\n }\n }\n compositeEntity.merge(entity);\n }\n }\n compositeEntity = undefined;\n }\n\n composite.resumeEvents();\n};\n\nCompositeEntityCollection.prototype._onDefinitionChanged = function (\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n const collections = this._collections;\n const composite = this._composite;\n\n const collectionsLength = collections.length;\n const id = entity.id;\n const compositeEntity = composite.getById(id);\n let compositeProperty = compositeEntity[propertyName];\n const newProperty = !defined(compositeProperty);\n\n let firstTime = true;\n for (let q = collectionsLength - 1; q >= 0; q--) {\n const innerEntity = collections[q].getById(entity.id);\n if (defined(innerEntity)) {\n const property = innerEntity[propertyName];\n if (defined(property)) {\n if (firstTime) {\n firstTime = false;\n //We only want to clone if the property is also mergeable.\n //This ensures that leaf properties are referenced and not copied,\n //which is the entire point of compositing.\n if (defined(property.merge) && defined(property.clone)) {\n compositeProperty = property.clone(compositeProperty);\n } else {\n compositeProperty = property;\n break;\n }\n }\n compositeProperty.merge(property);\n }\n }\n }\n\n if (\n newProperty &&\n compositeEntity.propertyNames.indexOf(propertyName) === -1\n ) {\n compositeEntity.addProperty(propertyName);\n }\n\n compositeEntity[propertyName] = compositeProperty;\n};\nexport default CompositeEntityCollection;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * A convenience object that simplifies the common pattern of attaching event listeners\n * to several events, then removing all those listeners at once later, for example, in\n * a destroy method.\n *\n * @alias EventHelper\n * @constructor\n *\n *\n * @example\n * const helper = new Cesium.EventHelper();\n *\n * helper.add(someObject.event, listener1, this);\n * helper.add(otherObject.event, listener2, this);\n *\n * // later...\n * helper.removeAll();\n *\n * @see Event\n */\nfunction EventHelper() {\n this._removalFunctions = [];\n}\n\n/**\n * Adds a listener to an event, and records the registration to be cleaned up later.\n *\n * @param {Event} event The event to attach to.\n * @param {Function} listener The function to be executed when the event is raised.\n * @param {object} [scope] An optional object scope to serve as the this\n * pointer in which the listener function will execute.\n * @returns {EventHelper.RemoveCallback} A function that will remove this event listener when invoked.\n *\n * @see Event#addEventListener\n */\nEventHelper.prototype.add = function (event, listener, scope) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(event)) {\n throw new DeveloperError(\"event is required\");\n }\n //>>includeEnd('debug');\n\n const removalFunction = event.addEventListener(listener, scope);\n this._removalFunctions.push(removalFunction);\n\n const that = this;\n return function () {\n removalFunction();\n const removalFunctions = that._removalFunctions;\n removalFunctions.splice(removalFunctions.indexOf(removalFunction), 1);\n };\n};\n\n/**\n * Unregisters all previously added listeners.\n *\n * @see Event#removeEventListener\n */\nEventHelper.prototype.removeAll = function () {\n const removalFunctions = this._removalFunctions;\n for (let i = 0, len = removalFunctions.length; i < len; ++i) {\n removalFunctions[i]();\n }\n removalFunctions.length = 0;\n};\n\n/**\n * A function that removes a listener.\n * @callback EventHelper.RemoveCallback\n */\nexport default EventHelper;\n", "import binarySearch from \"./binarySearch.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Event from \"./Event.js\";\nimport GregorianDate from \"./GregorianDate.js\";\nimport isLeapYear from \"./isLeapYear.js\";\nimport Iso8601 from \"./Iso8601.js\";\nimport JulianDate from \"./JulianDate.js\";\nimport TimeInterval from \"./TimeInterval.js\";\n\nfunction compareIntervalStartTimes(left, right) {\n return JulianDate.compare(left.start, right.start);\n}\n\n/**\n * A non-overlapping collection of {@link TimeInterval} instances sorted by start time.\n * @alias TimeIntervalCollection\n * @constructor\n *\n * @param {TimeInterval[]} [intervals] An array of intervals to add to the collection.\n */\nfunction TimeIntervalCollection(intervals) {\n this._intervals = [];\n this._changedEvent = new Event();\n\n if (defined(intervals)) {\n const length = intervals.length;\n for (let i = 0; i < length; i++) {\n this.addInterval(intervals[i]);\n }\n }\n}\n\nObject.defineProperties(TimeIntervalCollection.prototype, {\n /**\n * Gets an event that is raised whenever the collection of intervals change.\n * @memberof TimeIntervalCollection.prototype\n * @type {Event}\n * @readonly\n */\n changedEvent: {\n get: function () {\n return this._changedEvent;\n },\n },\n\n /**\n * Gets the start time of the collection.\n * @memberof TimeIntervalCollection.prototype\n * @type {JulianDate}\n * @readonly\n */\n start: {\n get: function () {\n const intervals = this._intervals;\n return intervals.length === 0 ? undefined : intervals[0].start;\n },\n },\n\n /**\n * Gets whether or not the start time is included in the collection.\n * @memberof TimeIntervalCollection.prototype\n * @type {boolean}\n * @readonly\n */\n isStartIncluded: {\n get: function () {\n const intervals = this._intervals;\n return intervals.length === 0 ? false : intervals[0].isStartIncluded;\n },\n },\n\n /**\n * Gets the stop time of the collection.\n * @memberof TimeIntervalCollection.prototype\n * @type {JulianDate}\n * @readonly\n */\n stop: {\n get: function () {\n const intervals = this._intervals;\n const length = intervals.length;\n return length === 0 ? undefined : intervals[length - 1].stop;\n },\n },\n\n /**\n * Gets whether or not the stop time is included in the collection.\n * @memberof TimeIntervalCollection.prototype\n * @type {boolean}\n * @readonly\n */\n isStopIncluded: {\n get: function () {\n const intervals = this._intervals;\n const length = intervals.length;\n return length === 0 ? false : intervals[length - 1].isStopIncluded;\n },\n },\n\n /**\n * Gets the number of intervals in the collection.\n * @memberof TimeIntervalCollection.prototype\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._intervals.length;\n },\n },\n\n /**\n * Gets whether or not the collection is empty.\n * @memberof TimeIntervalCollection.prototype\n * @type {boolean}\n * @readonly\n */\n isEmpty: {\n get: function () {\n return this._intervals.length === 0;\n },\n },\n});\n\n/**\n * Compares this instance against the provided instance componentwise and returns\n * true if they are equal, false otherwise.\n *\n * @param {TimeIntervalCollection} [right] The right hand side collection.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @returns {boolean} true if they are equal, false otherwise.\n */\nTimeIntervalCollection.prototype.equals = function (right, dataComparer) {\n if (this === right) {\n return true;\n }\n if (!(right instanceof TimeIntervalCollection)) {\n return false;\n }\n const intervals = this._intervals;\n const rightIntervals = right._intervals;\n const length = intervals.length;\n if (length !== rightIntervals.length) {\n return false;\n }\n for (let i = 0; i < length; i++) {\n if (!TimeInterval.equals(intervals[i], rightIntervals[i], dataComparer)) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Gets the interval at the specified index.\n *\n * @param {number} index The index of the interval to retrieve.\n * @returns {TimeInterval|undefined} The interval at the specified index, or undefined if no interval exists as that index.\n */\nTimeIntervalCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n return this._intervals[index];\n};\n\n/**\n * Removes all intervals from the collection.\n */\nTimeIntervalCollection.prototype.removeAll = function () {\n if (this._intervals.length > 0) {\n this._intervals.length = 0;\n this._changedEvent.raiseEvent(this);\n }\n};\n\n/**\n * Finds and returns the interval that contains the specified date.\n *\n * @param {JulianDate} date The date to search for.\n * @returns {TimeInterval|undefined} The interval containing the specified date, undefined if no such interval exists.\n */\nTimeIntervalCollection.prototype.findIntervalContainingDate = function (date) {\n const index = this.indexOf(date);\n return index >= 0 ? this._intervals[index] : undefined;\n};\n\n/**\n * Finds and returns the data for the interval that contains the specified date.\n *\n * @param {JulianDate} date The date to search for.\n * @returns {object} The data for the interval containing the specified date, or undefined if no such interval exists.\n */\nTimeIntervalCollection.prototype.findDataForIntervalContainingDate = function (\n date\n) {\n const index = this.indexOf(date);\n return index >= 0 ? this._intervals[index].data : undefined;\n};\n\n/**\n * Checks if the specified date is inside this collection.\n *\n * @param {JulianDate} julianDate The date to check.\n * @returns {boolean} true if the collection contains the specified date, false otherwise.\n */\nTimeIntervalCollection.prototype.contains = function (julianDate) {\n return this.indexOf(julianDate) >= 0;\n};\n\nconst indexOfScratch = new TimeInterval();\n\n/**\n * Finds and returns the index of the interval in the collection that contains the specified date.\n *\n * @param {JulianDate} date The date to search for.\n * @returns {number} The index of the interval that contains the specified date, if no such interval exists,\n * it returns a negative number which is the bitwise complement of the index of the next interval that\n * starts after the date, or if no interval starts after the specified date, the bitwise complement of\n * the length of the collection.\n */\nTimeIntervalCollection.prototype.indexOf = function (date) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(date)) {\n throw new DeveloperError(\"date is required\");\n }\n //>>includeEnd('debug');\n\n const intervals = this._intervals;\n indexOfScratch.start = date;\n indexOfScratch.stop = date;\n let index = binarySearch(\n intervals,\n indexOfScratch,\n compareIntervalStartTimes\n );\n if (index >= 0) {\n if (intervals[index].isStartIncluded) {\n return index;\n }\n\n if (\n index > 0 &&\n intervals[index - 1].stop.equals(date) &&\n intervals[index - 1].isStopIncluded\n ) {\n return index - 1;\n }\n return ~index;\n }\n\n index = ~index;\n if (\n index > 0 &&\n index - 1 < intervals.length &&\n TimeInterval.contains(intervals[index - 1], date)\n ) {\n return index - 1;\n }\n return ~index;\n};\n\n/**\n * Returns the first interval in the collection that matches the specified parameters.\n * All parameters are optional and undefined parameters are treated as a don't care condition.\n *\n * @param {object} [options] Object with the following properties:\n * @param {JulianDate} [options.start] The start time of the interval.\n * @param {JulianDate} [options.stop] The stop time of the interval.\n * @param {boolean} [options.isStartIncluded] true if options.start is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded] true if options.stop is included in the interval, false otherwise.\n * @returns {TimeInterval|undefined} The first interval in the collection that matches the specified parameters.\n */\nTimeIntervalCollection.prototype.findInterval = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const start = options.start;\n const stop = options.stop;\n const isStartIncluded = options.isStartIncluded;\n const isStopIncluded = options.isStopIncluded;\n\n const intervals = this._intervals;\n for (let i = 0, len = intervals.length; i < len; i++) {\n const interval = intervals[i];\n if (\n (!defined(start) || interval.start.equals(start)) &&\n (!defined(stop) || interval.stop.equals(stop)) &&\n (!defined(isStartIncluded) ||\n interval.isStartIncluded === isStartIncluded) &&\n (!defined(isStopIncluded) || interval.isStopIncluded === isStopIncluded)\n ) {\n return intervals[i];\n }\n }\n return undefined;\n};\n\n/**\n * Adds an interval to the collection, merging intervals that contain the same data and\n * splitting intervals of different data as needed in order to maintain a non-overlapping collection.\n * The data in the new interval takes precedence over any existing intervals in the collection.\n *\n * @param {TimeInterval} interval The interval to add.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n */\nTimeIntervalCollection.prototype.addInterval = function (\n interval,\n dataComparer\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(interval)) {\n throw new DeveloperError(\"interval is required\");\n }\n //>>includeEnd('debug');\n\n if (interval.isEmpty) {\n return;\n }\n\n const intervals = this._intervals;\n\n // Handle the common case quickly: we're adding a new interval which is after all existing intervals.\n if (\n intervals.length === 0 ||\n JulianDate.greaterThan(interval.start, intervals[intervals.length - 1].stop)\n ) {\n intervals.push(interval);\n this._changedEvent.raiseEvent(this);\n return;\n }\n\n // Keep the list sorted by the start date\n let index = binarySearch(intervals, interval, compareIntervalStartTimes);\n if (index < 0) {\n index = ~index;\n } else {\n // interval's start date exactly equals the start date of at least one interval in the collection.\n // It could actually equal the start date of two intervals if one of them does not actually\n // include the date. In that case, the binary search could have found either. We need to\n // look at the surrounding intervals and their IsStartIncluded properties in order to make sure\n // we're working with the correct interval.\n\n // eslint-disable-next-line no-lonely-if\n if (\n index > 0 &&\n interval.isStartIncluded &&\n intervals[index - 1].isStartIncluded &&\n intervals[index - 1].start.equals(interval.start)\n ) {\n --index;\n } else if (\n index < intervals.length &&\n !interval.isStartIncluded &&\n intervals[index].isStartIncluded &&\n intervals[index].start.equals(interval.start)\n ) {\n ++index;\n }\n }\n\n let comparison;\n if (index > 0) {\n // Not the first thing in the list, so see if the interval before this one\n // overlaps this one.\n\n comparison = JulianDate.compare(intervals[index - 1].stop, interval.start);\n if (\n comparison > 0 ||\n (comparison === 0 &&\n (intervals[index - 1].isStopIncluded || interval.isStartIncluded))\n ) {\n // There is an overlap\n if (\n defined(dataComparer)\n ? dataComparer(intervals[index - 1].data, interval.data)\n : intervals[index - 1].data === interval.data\n ) {\n // Overlapping intervals have the same data, so combine them\n if (JulianDate.greaterThan(interval.stop, intervals[index - 1].stop)) {\n interval = new TimeInterval({\n start: intervals[index - 1].start,\n stop: interval.stop,\n isStartIncluded: intervals[index - 1].isStartIncluded,\n isStopIncluded: interval.isStopIncluded,\n data: interval.data,\n });\n } else {\n interval = new TimeInterval({\n start: intervals[index - 1].start,\n stop: intervals[index - 1].stop,\n isStartIncluded: intervals[index - 1].isStartIncluded,\n isStopIncluded:\n intervals[index - 1].isStopIncluded ||\n (interval.stop.equals(intervals[index - 1].stop) &&\n interval.isStopIncluded),\n data: interval.data,\n });\n }\n intervals.splice(index - 1, 1);\n --index;\n } else {\n // Overlapping intervals have different data. The new interval\n // being added 'wins' so truncate the previous interval.\n // If the existing interval extends past the end of the new one,\n // split the existing interval into two intervals.\n comparison = JulianDate.compare(\n intervals[index - 1].stop,\n interval.stop\n );\n if (\n comparison > 0 ||\n (comparison === 0 &&\n intervals[index - 1].isStopIncluded &&\n !interval.isStopIncluded)\n ) {\n intervals.splice(\n index,\n 0,\n new TimeInterval({\n start: interval.stop,\n stop: intervals[index - 1].stop,\n isStartIncluded: !interval.isStopIncluded,\n isStopIncluded: intervals[index - 1].isStopIncluded,\n data: intervals[index - 1].data,\n })\n );\n }\n intervals[index - 1] = new TimeInterval({\n start: intervals[index - 1].start,\n stop: interval.start,\n isStartIncluded: intervals[index - 1].isStartIncluded,\n isStopIncluded: !interval.isStartIncluded,\n data: intervals[index - 1].data,\n });\n }\n }\n }\n\n while (index < intervals.length) {\n // Not the last thing in the list, so see if the intervals after this one overlap this one.\n comparison = JulianDate.compare(interval.stop, intervals[index].start);\n if (\n comparison > 0 ||\n (comparison === 0 &&\n (interval.isStopIncluded || intervals[index].isStartIncluded))\n ) {\n // There is an overlap\n if (\n defined(dataComparer)\n ? dataComparer(intervals[index].data, interval.data)\n : intervals[index].data === interval.data\n ) {\n // Overlapping intervals have the same data, so combine them\n interval = new TimeInterval({\n start: interval.start,\n stop: JulianDate.greaterThan(intervals[index].stop, interval.stop)\n ? intervals[index].stop\n : interval.stop,\n isStartIncluded: interval.isStartIncluded,\n isStopIncluded: JulianDate.greaterThan(\n intervals[index].stop,\n interval.stop\n )\n ? intervals[index].isStopIncluded\n : interval.isStopIncluded,\n data: interval.data,\n });\n intervals.splice(index, 1);\n } else {\n // Overlapping intervals have different data. The new interval\n // being added 'wins' so truncate the next interval.\n intervals[index] = new TimeInterval({\n start: interval.stop,\n stop: intervals[index].stop,\n isStartIncluded: !interval.isStopIncluded,\n isStopIncluded: intervals[index].isStopIncluded,\n data: intervals[index].data,\n });\n\n if (intervals[index].isEmpty) {\n intervals.splice(index, 1);\n } else {\n // Found a partial span, so it is not possible for the next\n // interval to be spanned at all. Stop looking.\n break;\n }\n }\n } else {\n // Found the last one we're spanning, so stop looking.\n break;\n }\n }\n\n // Add the new interval\n intervals.splice(index, 0, interval);\n this._changedEvent.raiseEvent(this);\n};\n\n/**\n * Removes the specified interval from this interval collection, creating a hole over the specified interval.\n * The data property of the input interval is ignored.\n *\n * @param {TimeInterval} interval The interval to remove.\n * @returns {boolean} true if the interval was removed, false if no part of the interval was in the collection.\n */\nTimeIntervalCollection.prototype.removeInterval = function (interval) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(interval)) {\n throw new DeveloperError(\"interval is required\");\n }\n //>>includeEnd('debug');\n\n if (interval.isEmpty) {\n return false;\n }\n\n const intervals = this._intervals;\n\n let index = binarySearch(intervals, interval, compareIntervalStartTimes);\n if (index < 0) {\n index = ~index;\n }\n\n let result = false;\n\n // Check for truncation of the end of the previous interval.\n if (\n index > 0 &&\n (JulianDate.greaterThan(intervals[index - 1].stop, interval.start) ||\n (intervals[index - 1].stop.equals(interval.start) &&\n intervals[index - 1].isStopIncluded &&\n interval.isStartIncluded))\n ) {\n result = true;\n\n if (\n JulianDate.greaterThan(intervals[index - 1].stop, interval.stop) ||\n (intervals[index - 1].isStopIncluded &&\n !interval.isStopIncluded &&\n intervals[index - 1].stop.equals(interval.stop))\n ) {\n // Break the existing interval into two pieces\n intervals.splice(\n index,\n 0,\n new TimeInterval({\n start: interval.stop,\n stop: intervals[index - 1].stop,\n isStartIncluded: !interval.isStopIncluded,\n isStopIncluded: intervals[index - 1].isStopIncluded,\n data: intervals[index - 1].data,\n })\n );\n }\n intervals[index - 1] = new TimeInterval({\n start: intervals[index - 1].start,\n stop: interval.start,\n isStartIncluded: intervals[index - 1].isStartIncluded,\n isStopIncluded: !interval.isStartIncluded,\n data: intervals[index - 1].data,\n });\n }\n\n // Check if the Start of the current interval should remain because interval.start is the same but\n // it is not included.\n if (\n index < intervals.length &&\n !interval.isStartIncluded &&\n intervals[index].isStartIncluded &&\n interval.start.equals(intervals[index].start)\n ) {\n result = true;\n\n intervals.splice(\n index,\n 0,\n new TimeInterval({\n start: intervals[index].start,\n stop: intervals[index].start,\n isStartIncluded: true,\n isStopIncluded: true,\n data: intervals[index].data,\n })\n );\n ++index;\n }\n\n // Remove any intervals that are completely overlapped by the input interval.\n while (\n index < intervals.length &&\n JulianDate.greaterThan(interval.stop, intervals[index].stop)\n ) {\n result = true;\n intervals.splice(index, 1);\n }\n\n // Check for the case where the input interval ends on the same date\n // as an existing interval.\n if (index < intervals.length && interval.stop.equals(intervals[index].stop)) {\n result = true;\n\n if (!interval.isStopIncluded && intervals[index].isStopIncluded) {\n // Last point of interval should remain because the stop date is included in\n // the existing interval but is not included in the input interval.\n if (\n index + 1 < intervals.length &&\n intervals[index + 1].start.equals(interval.stop) &&\n intervals[index].data === intervals[index + 1].data\n ) {\n // Combine single point with the next interval\n intervals.splice(index, 1);\n intervals[index] = new TimeInterval({\n start: intervals[index].start,\n stop: intervals[index].stop,\n isStartIncluded: true,\n isStopIncluded: intervals[index].isStopIncluded,\n data: intervals[index].data,\n });\n } else {\n intervals[index] = new TimeInterval({\n start: interval.stop,\n stop: interval.stop,\n isStartIncluded: true,\n isStopIncluded: true,\n data: intervals[index].data,\n });\n }\n } else {\n // Interval is completely overlapped\n intervals.splice(index, 1);\n }\n }\n\n // Truncate any partially-overlapped intervals.\n if (\n index < intervals.length &&\n (JulianDate.greaterThan(interval.stop, intervals[index].start) ||\n (interval.stop.equals(intervals[index].start) &&\n interval.isStopIncluded &&\n intervals[index].isStartIncluded))\n ) {\n result = true;\n intervals[index] = new TimeInterval({\n start: interval.stop,\n stop: intervals[index].stop,\n isStartIncluded: !interval.isStopIncluded,\n isStopIncluded: intervals[index].isStopIncluded,\n data: intervals[index].data,\n });\n }\n\n if (result) {\n this._changedEvent.raiseEvent(this);\n }\n\n return result;\n};\n\n/**\n * Creates a new instance that is the intersection of this collection and the provided collection.\n *\n * @param {TimeIntervalCollection} other The collection to intersect with.\n * @param {TimeInterval.DataComparer} [dataComparer] A function which compares the data of the two intervals. If omitted, reference equality is used.\n * @param {TimeInterval.MergeCallback} [mergeCallback] A function which merges the data of the two intervals. If omitted, the data from the left interval will be used.\n * @returns {TimeIntervalCollection} A new TimeIntervalCollection which is the intersection of this collection and the provided collection.\n */\nTimeIntervalCollection.prototype.intersect = function (\n other,\n dataComparer,\n mergeCallback\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(other)) {\n throw new DeveloperError(\"other is required.\");\n }\n //>>includeEnd('debug');\n\n const result = new TimeIntervalCollection();\n let left = 0;\n let right = 0;\n const intervals = this._intervals;\n const otherIntervals = other._intervals;\n\n while (left < intervals.length && right < otherIntervals.length) {\n const leftInterval = intervals[left];\n const rightInterval = otherIntervals[right];\n if (JulianDate.lessThan(leftInterval.stop, rightInterval.start)) {\n ++left;\n } else if (JulianDate.lessThan(rightInterval.stop, leftInterval.start)) {\n ++right;\n } else {\n // The following will return an intersection whose data is 'merged' if the callback is defined\n if (\n defined(mergeCallback) ||\n (defined(dataComparer) &&\n dataComparer(leftInterval.data, rightInterval.data)) ||\n (!defined(dataComparer) && rightInterval.data === leftInterval.data)\n ) {\n const intersection = TimeInterval.intersect(\n leftInterval,\n rightInterval,\n new TimeInterval(),\n mergeCallback\n );\n if (!intersection.isEmpty) {\n // Since we start with an empty collection for 'result', and there are no overlapping intervals in 'this' (as a rule),\n // the 'intersection' will never overlap with a previous interval in 'result'. So, no need to do any additional 'merging'.\n result.addInterval(intersection, dataComparer);\n }\n }\n\n if (\n JulianDate.lessThan(leftInterval.stop, rightInterval.stop) ||\n (leftInterval.stop.equals(rightInterval.stop) &&\n !leftInterval.isStopIncluded &&\n rightInterval.isStopIncluded)\n ) {\n ++left;\n } else {\n ++right;\n }\n }\n }\n return result;\n};\n\n/**\n * Creates a new instance from a JulianDate array.\n *\n * @param {object} options Object with the following properties:\n * @param {JulianDate[]} options.julianDates An array of ISO 8601 dates.\n * @param {boolean} [options.isStartIncluded=true] true if start time is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if stop time is included in the interval, false otherwise.\n * @param {boolean} [options.leadingInterval=false] true if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, false otherwise.\n * @param {boolean} [options.trailingInterval=false] true if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, false otherwise.\n * @param {Function} [options.dataCallback] A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.\n * @param {TimeIntervalCollection} [result] An existing instance to use for the result.\n * @returns {TimeIntervalCollection} The modified result parameter or a new instance if none was provided.\n */\nTimeIntervalCollection.fromJulianDateArray = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options)) {\n throw new DeveloperError(\"options is required.\");\n }\n if (!defined(options.julianDates)) {\n throw new DeveloperError(\"options.iso8601Array is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new TimeIntervalCollection();\n }\n\n const julianDates = options.julianDates;\n const length = julianDates.length;\n const dataCallback = options.dataCallback;\n\n const isStartIncluded = defaultValue(options.isStartIncluded, true);\n const isStopIncluded = defaultValue(options.isStopIncluded, true);\n const leadingInterval = defaultValue(options.leadingInterval, false);\n const trailingInterval = defaultValue(options.trailingInterval, false);\n let interval;\n\n // Add a default interval, which will only end up being used up to first interval\n let startIndex = 0;\n if (leadingInterval) {\n ++startIndex;\n interval = new TimeInterval({\n start: Iso8601.MINIMUM_VALUE,\n stop: julianDates[0],\n isStartIncluded: true,\n isStopIncluded: !isStartIncluded,\n });\n interval.data = defined(dataCallback)\n ? dataCallback(interval, result.length)\n : result.length;\n result.addInterval(interval);\n }\n\n for (let i = 0; i < length - 1; ++i) {\n let startDate = julianDates[i];\n const endDate = julianDates[i + 1];\n\n interval = new TimeInterval({\n start: startDate,\n stop: endDate,\n isStartIncluded: result.length === startIndex ? isStartIncluded : true,\n isStopIncluded: i === length - 2 ? isStopIncluded : false,\n });\n interval.data = defined(dataCallback)\n ? dataCallback(interval, result.length)\n : result.length;\n result.addInterval(interval);\n\n startDate = endDate;\n }\n\n if (trailingInterval) {\n interval = new TimeInterval({\n start: julianDates[length - 1],\n stop: Iso8601.MAXIMUM_VALUE,\n isStartIncluded: !isStopIncluded,\n isStopIncluded: true,\n });\n interval.data = defined(dataCallback)\n ? dataCallback(interval, result.length)\n : result.length;\n result.addInterval(interval);\n }\n\n return result;\n};\n\nconst scratchGregorianDate = new GregorianDate();\nconst monthLengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\n/**\n * Adds duration represented as a GregorianDate to a JulianDate\n *\n * @param {JulianDate} julianDate The date.\n * @param {GregorianDate} duration An duration represented as a GregorianDate.\n * @param {JulianDate} result An existing instance to use for the result.\n * @returns {JulianDate} The modified result parameter.\n *\n * @private\n */\nfunction addToDate(julianDate, duration, result) {\n if (!defined(result)) {\n result = new JulianDate();\n }\n JulianDate.toGregorianDate(julianDate, scratchGregorianDate);\n\n let millisecond = scratchGregorianDate.millisecond + duration.millisecond;\n let second = scratchGregorianDate.second + duration.second;\n let minute = scratchGregorianDate.minute + duration.minute;\n let hour = scratchGregorianDate.hour + duration.hour;\n let day = scratchGregorianDate.day + duration.day;\n let month = scratchGregorianDate.month + duration.month;\n let year = scratchGregorianDate.year + duration.year;\n\n if (millisecond >= 1000) {\n second += Math.floor(millisecond / 1000);\n millisecond = millisecond % 1000;\n }\n\n if (second >= 60) {\n minute += Math.floor(second / 60);\n second = second % 60;\n }\n\n if (minute >= 60) {\n hour += Math.floor(minute / 60);\n minute = minute % 60;\n }\n\n if (hour >= 24) {\n day += Math.floor(hour / 24);\n hour = hour % 24;\n }\n\n // If days is greater than the month's length we need to remove those number of days,\n // readjust month and year and repeat until days is less than the month's length.\n monthLengths[2] = isLeapYear(year) ? 29 : 28;\n while (day > monthLengths[month] || month >= 13) {\n if (day > monthLengths[month]) {\n day -= monthLengths[month];\n ++month;\n }\n\n if (month >= 13) {\n --month;\n year += Math.floor(month / 12);\n month = month % 12;\n ++month;\n }\n\n monthLengths[2] = isLeapYear(year) ? 29 : 28;\n }\n\n scratchGregorianDate.millisecond = millisecond;\n scratchGregorianDate.second = second;\n scratchGregorianDate.minute = minute;\n scratchGregorianDate.hour = hour;\n scratchGregorianDate.day = day;\n scratchGregorianDate.month = month;\n scratchGregorianDate.year = year;\n\n return JulianDate.fromGregorianDate(scratchGregorianDate, result);\n}\n\nconst scratchJulianDate = new JulianDate();\nconst durationRegex = /P(?:([\\d.,]+)Y)?(?:([\\d.,]+)M)?(?:([\\d.,]+)W)?(?:([\\d.,]+)D)?(?:T(?:([\\d.,]+)H)?(?:([\\d.,]+)M)?(?:([\\d.,]+)S)?)?/;\n\n/**\n * Parses ISO8601 duration string\n *\n * @param {string} iso8601 An ISO 8601 duration.\n * @param {GregorianDate} result An existing instance to use for the result.\n * @returns {boolean} True is parsing succeeded, false otherwise\n *\n * @private\n */\nfunction parseDuration(iso8601, result) {\n if (!defined(iso8601) || iso8601.length === 0) {\n return false;\n }\n\n // Reset object\n result.year = 0;\n result.month = 0;\n result.day = 0;\n result.hour = 0;\n result.minute = 0;\n result.second = 0;\n result.millisecond = 0;\n\n if (iso8601[0] === \"P\") {\n const matches = iso8601.match(durationRegex);\n if (!defined(matches)) {\n return false;\n }\n if (defined(matches[1])) {\n // Years\n result.year = Number(matches[1].replace(\",\", \".\"));\n }\n if (defined(matches[2])) {\n // Months\n result.month = Number(matches[2].replace(\",\", \".\"));\n }\n if (defined(matches[3])) {\n // Weeks\n result.day = Number(matches[3].replace(\",\", \".\")) * 7;\n }\n if (defined(matches[4])) {\n // Days\n result.day += Number(matches[4].replace(\",\", \".\"));\n }\n if (defined(matches[5])) {\n // Hours\n result.hour = Number(matches[5].replace(\",\", \".\"));\n }\n if (defined(matches[6])) {\n // Weeks\n result.minute = Number(matches[6].replace(\",\", \".\"));\n }\n if (defined(matches[7])) {\n // Seconds\n const seconds = Number(matches[7].replace(\",\", \".\"));\n result.second = Math.floor(seconds);\n result.millisecond = (seconds % 1) * 1000;\n }\n } else {\n // They can technically specify the duration as a normal date with some caveats. Try our best to load it.\n if (iso8601[iso8601.length - 1] !== \"Z\") {\n // It's not a date, its a duration, so it always has to be UTC\n iso8601 += \"Z\";\n }\n JulianDate.toGregorianDate(\n JulianDate.fromIso8601(iso8601, scratchJulianDate),\n result\n );\n }\n\n // A duration of 0 will cause an infinite loop, so just make sure something is non-zero\n return (\n result.year ||\n result.month ||\n result.day ||\n result.hour ||\n result.minute ||\n result.second ||\n result.millisecond\n );\n}\n\nconst scratchDuration = new GregorianDate();\n/**\n * Creates a new instance from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} time interval (start/end/duration).\n *\n * @param {object} options Object with the following properties:\n * @param {string} options.iso8601 An ISO 8601 interval.\n * @param {boolean} [options.isStartIncluded=true] true if start time is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if stop time is included in the interval, false otherwise.\n * @param {boolean} [options.leadingInterval=false] true if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, false otherwise.\n * @param {boolean} [options.trailingInterval=false] true if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, false otherwise.\n * @param {Function} [options.dataCallback] A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.\n * @param {TimeIntervalCollection} [result] An existing instance to use for the result.\n * @returns {TimeIntervalCollection} The modified result parameter or a new instance if none was provided.\n */\nTimeIntervalCollection.fromIso8601 = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options)) {\n throw new DeveloperError(\"options is required.\");\n }\n if (!defined(options.iso8601)) {\n throw new DeveloperError(\"options.iso8601 is required.\");\n }\n //>>includeEnd('debug');\n\n const dates = options.iso8601.split(\"/\");\n const start = JulianDate.fromIso8601(dates[0]);\n const stop = JulianDate.fromIso8601(dates[1]);\n const julianDates = [];\n\n if (!parseDuration(dates[2], scratchDuration)) {\n julianDates.push(start, stop);\n } else {\n let date = JulianDate.clone(start);\n julianDates.push(date);\n while (JulianDate.compare(date, stop) < 0) {\n date = addToDate(date, scratchDuration);\n const afterStop = JulianDate.compare(stop, date) <= 0;\n if (afterStop) {\n JulianDate.clone(stop, date);\n }\n\n julianDates.push(date);\n }\n }\n\n return TimeIntervalCollection.fromJulianDateArray(\n {\n julianDates: julianDates,\n isStartIncluded: options.isStartIncluded,\n isStopIncluded: options.isStopIncluded,\n leadingInterval: options.leadingInterval,\n trailingInterval: options.trailingInterval,\n dataCallback: options.dataCallback,\n },\n result\n );\n};\n\n/**\n * Creates a new instance from a {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date array.\n *\n * @param {object} options Object with the following properties:\n * @param {string[]} options.iso8601Dates An array of ISO 8601 dates.\n * @param {boolean} [options.isStartIncluded=true] true if start time is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if stop time is included in the interval, false otherwise.\n * @param {boolean} [options.leadingInterval=false] true if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, false otherwise.\n * @param {boolean} [options.trailingInterval=false] true if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, false otherwise.\n * @param {Function} [options.dataCallback] A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.\n * @param {TimeIntervalCollection} [result] An existing instance to use for the result.\n * @returns {TimeIntervalCollection} The modified result parameter or a new instance if none was provided.\n */\nTimeIntervalCollection.fromIso8601DateArray = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options)) {\n throw new DeveloperError(\"options is required.\");\n }\n if (!defined(options.iso8601Dates)) {\n throw new DeveloperError(\"options.iso8601Dates is required.\");\n }\n //>>includeEnd('debug');\n\n return TimeIntervalCollection.fromJulianDateArray(\n {\n julianDates: options.iso8601Dates.map(function (date) {\n return JulianDate.fromIso8601(date);\n }),\n isStartIncluded: options.isStartIncluded,\n isStopIncluded: options.isStopIncluded,\n leadingInterval: options.leadingInterval,\n trailingInterval: options.trailingInterval,\n dataCallback: options.dataCallback,\n },\n result\n );\n};\n\n/**\n * Creates a new instance from a {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} duration array.\n *\n * @param {object} options Object with the following properties:\n * @param {JulianDate} options.epoch An date that the durations are relative to.\n * @param {string} options.iso8601Durations An array of ISO 8601 durations.\n * @param {boolean} [options.relativeToPrevious=false] true if durations are relative to previous date, false if always relative to the epoch.\n * @param {boolean} [options.isStartIncluded=true] true if start time is included in the interval, false otherwise.\n * @param {boolean} [options.isStopIncluded=true] true if stop time is included in the interval, false otherwise.\n * @param {boolean} [options.leadingInterval=false] true if you want to add a interval from Iso8601.MINIMUM_VALUE to start time, false otherwise.\n * @param {boolean} [options.trailingInterval=false] true if you want to add a interval from stop time to Iso8601.MAXIMUM_VALUE, false otherwise.\n * @param {Function} [options.dataCallback] A function that will be return the data that is called with each interval before it is added to the collection. If unspecified, the data will be the index in the collection.\n * @param {TimeIntervalCollection} [result] An existing instance to use for the result.\n * @returns {TimeIntervalCollection} The modified result parameter or a new instance if none was provided.\n */\nTimeIntervalCollection.fromIso8601DurationArray = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(options)) {\n throw new DeveloperError(\"options is required.\");\n }\n if (!defined(options.epoch)) {\n throw new DeveloperError(\"options.epoch is required.\");\n }\n if (!defined(options.iso8601Durations)) {\n throw new DeveloperError(\"options.iso8601Durations is required.\");\n }\n //>>includeEnd('debug');\n\n const epoch = options.epoch;\n const iso8601Durations = options.iso8601Durations;\n const relativeToPrevious = defaultValue(options.relativeToPrevious, false);\n const julianDates = [];\n let date, previousDate;\n\n const length = iso8601Durations.length;\n for (let i = 0; i < length; ++i) {\n // Allow a duration of 0 on the first iteration, because then it is just the epoch\n if (parseDuration(iso8601Durations[i], scratchDuration) || i === 0) {\n if (relativeToPrevious && defined(previousDate)) {\n date = addToDate(previousDate, scratchDuration);\n } else {\n date = addToDate(epoch, scratchDuration);\n }\n julianDates.push(date);\n previousDate = date;\n }\n }\n\n return TimeIntervalCollection.fromJulianDateArray(\n {\n julianDates: julianDates,\n isStartIncluded: options.isStartIncluded,\n isStopIncluded: options.isStopIncluded,\n leadingInterval: options.leadingInterval,\n trailingInterval: options.trailingInterval,\n dataCallback: options.dataCallback,\n },\n result\n );\n};\nexport default TimeIntervalCollection;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport EventHelper from \"../Core/EventHelper.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport Property from \"./Property.js\";\n\nfunction subscribeAll(property, eventHelper, definitionChanged, intervals) {\n function callback() {\n definitionChanged.raiseEvent(property);\n }\n const items = [];\n eventHelper.removeAll();\n const length = intervals.length;\n for (let i = 0; i < length; i++) {\n const interval = intervals.get(i);\n if (defined(interval.data) && items.indexOf(interval.data) === -1) {\n eventHelper.add(interval.data.definitionChanged, callback);\n }\n }\n}\n\n/**\n * A {@link Property} which is defined by a {@link TimeIntervalCollection}, where the\n * data property of each {@link TimeInterval} is another Property instance which is\n * evaluated at the provided time.\n *\n * @alias CompositeProperty\n * @constructor\n *\n *\n * @example\n * const constantProperty = ...;\n * const sampledProperty = ...;\n *\n * //Create a composite property from two previously defined properties\n * //where the property is valid on August 1st, 2012 and uses a constant\n * //property for the first half of the day and a sampled property for the\n * //remaining half.\n * const composite = new Cesium.CompositeProperty();\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T00:00:00.00Z/2012-08-01T12:00:00.00Z',\n * data : constantProperty\n * }));\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T12:00:00.00Z/2012-08-02T00:00:00.00Z',\n * isStartIncluded : false,\n * isStopIncluded : false,\n * data : sampledProperty\n * }));\n *\n * @see CompositeMaterialProperty\n * @see CompositePositionProperty\n */\nfunction CompositeProperty() {\n this._eventHelper = new EventHelper();\n this._definitionChanged = new Event();\n this._intervals = new TimeIntervalCollection();\n this._intervals.changedEvent.addEventListener(\n CompositeProperty.prototype._intervalsChanged,\n this\n );\n}\n\nObject.defineProperties(CompositeProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof CompositeProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._intervals.isEmpty;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value.\n * @memberof CompositeProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the interval collection.\n * @memberof CompositeProperty.prototype\n *\n * @type {TimeIntervalCollection}\n */\n intervals: {\n get: function () {\n return this._intervals;\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nCompositeProperty.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required\");\n }\n //>>includeEnd('debug');\n\n const innerProperty = this._intervals.findDataForIntervalContainingDate(time);\n if (defined(innerProperty)) {\n return innerProperty.getValue(time, result);\n }\n return undefined;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCompositeProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof CompositeProperty && //\n this._intervals.equals(other._intervals, Property.equals))\n );\n};\n\n/**\n * @private\n */\nCompositeProperty.prototype._intervalsChanged = function () {\n subscribeAll(\n this,\n this._eventHelper,\n this._definitionChanged,\n this._intervals\n );\n this._definitionChanged.raiseEvent(this);\n};\nexport default CompositeProperty;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport CompositeProperty from \"./CompositeProperty.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link CompositeProperty} which is also a {@link MaterialProperty}.\n *\n * @alias CompositeMaterialProperty\n * @constructor\n */\nfunction CompositeMaterialProperty() {\n this._definitionChanged = new Event();\n this._composite = new CompositeProperty();\n this._composite.definitionChanged.addEventListener(\n CompositeMaterialProperty.prototype._raiseDefinitionChanged,\n this\n );\n}\n\nObject.defineProperties(CompositeMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof CompositeMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._composite.isConstant;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value.\n * @memberof CompositeMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the interval collection.\n * @memberof CompositeMaterialProperty.prototype\n *\n * @type {TimeIntervalCollection}\n */\n intervals: {\n get: function () {\n return this._composite._intervals;\n },\n },\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nCompositeMaterialProperty.prototype.getType = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required\");\n }\n //>>includeEnd('debug');\n\n const innerProperty = this._composite._intervals.findDataForIntervalContainingDate(\n time\n );\n if (defined(innerProperty)) {\n return innerProperty.getType(time);\n }\n return undefined;\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nCompositeMaterialProperty.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required\");\n }\n //>>includeEnd('debug');\n\n const innerProperty = this._composite._intervals.findDataForIntervalContainingDate(\n time\n );\n if (defined(innerProperty)) {\n return innerProperty.getValue(time, result);\n }\n return undefined;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCompositeMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof CompositeMaterialProperty && //\n this._composite.equals(other._composite, Property.equals))\n );\n};\n\n/**\n * @private\n */\nCompositeMaterialProperty.prototype._raiseDefinitionChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default CompositeMaterialProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport CompositeProperty from \"./CompositeProperty.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link CompositeProperty} which is also a {@link PositionProperty}.\n *\n * @alias CompositePositionProperty\n * @constructor\n *\n * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.\n */\nfunction CompositePositionProperty(referenceFrame) {\n this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n this._definitionChanged = new Event();\n this._composite = new CompositeProperty();\n this._composite.definitionChanged.addEventListener(\n CompositePositionProperty.prototype._raiseDefinitionChanged,\n this\n );\n}\n\nObject.defineProperties(CompositePositionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof CompositePositionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._composite.isConstant;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value.\n * @memberof CompositePositionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the interval collection.\n * @memberof CompositePositionProperty.prototype\n *\n * @type {TimeIntervalCollection}\n */\n intervals: {\n get: function () {\n return this._composite.intervals;\n },\n },\n /**\n * Gets or sets the reference frame which this position presents itself as.\n * Each PositionProperty making up this object has it's own reference frame,\n * so this property merely exposes a \"preferred\" reference frame for clients\n * to use.\n * @memberof CompositePositionProperty.prototype\n *\n * @type {ReferenceFrame}\n */\n referenceFrame: {\n get: function () {\n return this._referenceFrame;\n },\n set: function (value) {\n this._referenceFrame = value;\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time in the fixed frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nCompositePositionProperty.prototype.getValue = function (time, result) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nCompositePositionProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n if (!defined(referenceFrame)) {\n throw new DeveloperError(\"referenceFrame is required.\");\n }\n //>>includeEnd('debug');\n\n const innerProperty = this._composite._intervals.findDataForIntervalContainingDate(\n time\n );\n if (defined(innerProperty)) {\n return innerProperty.getValueInReferenceFrame(time, referenceFrame, result);\n }\n return undefined;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nCompositePositionProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof CompositePositionProperty && //\n this._referenceFrame === other._referenceFrame && //\n this._composite.equals(other._composite, Property.equals))\n );\n};\n\n/**\n * @private\n */\nCompositePositionProperty.prototype._raiseDefinitionChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default CompositePositionProperty;\n", "/**\n * Style options for corners.\n *\n * @demo The {@link https://sandcastle.cesium.com/index.html?src=Corridor.html&label=Geometries|Corridor Demo}\n * demonstrates the three corner types, as used by {@link CorridorGraphics}.\n *\n * @enum {number}\n */\nconst CornerType = {\n /**\n * \n *\n * Corner has a smooth edge.\n * @type {number}\n * @constant\n */\n ROUNDED: 0,\n\n /**\n * \n *\n * Corner point is the intersection of adjacent edges.\n * @type {number}\n * @constant\n */\n MITERED: 1,\n\n /**\n * \n *\n * Corner is clipped.\n * @type {number}\n * @constant\n */\n BEVELED: 2,\n};\nexport default Object.freeze(CornerType);\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartesian4 from \"./Cartesian4.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport CornerType from \"./CornerType.js\";\nimport EllipsoidTangentPlane from \"./EllipsoidTangentPlane.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Matrix4 from \"./Matrix4.js\";\nimport PolylinePipeline from \"./PolylinePipeline.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Transforms from \"./Transforms.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\n\nconst scratch2Array = [new Cartesian3(), new Cartesian3()];\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartesian3 = new Cartesian3();\nconst scratchCartesian4 = new Cartesian3();\nconst scratchCartesian5 = new Cartesian3();\nconst scratchCartesian6 = new Cartesian3();\nconst scratchCartesian7 = new Cartesian3();\nconst scratchCartesian8 = new Cartesian3();\nconst scratchCartesian9 = new Cartesian3();\n\nconst scratch1 = new Cartesian3();\nconst scratch2 = new Cartesian3();\n\n/**\n * @private\n */\nconst PolylineVolumeGeometryLibrary = {};\n\nlet cartographic = new Cartographic();\nfunction scaleToSurface(positions, ellipsoid) {\n const heights = new Array(positions.length);\n for (let i = 0; i < positions.length; i++) {\n const pos = positions[i];\n cartographic = ellipsoid.cartesianToCartographic(pos, cartographic);\n heights[i] = cartographic.height;\n positions[i] = ellipsoid.scaleToGeodeticSurface(pos, pos);\n }\n return heights;\n}\n\nfunction subdivideHeights(points, h0, h1, granularity) {\n const p0 = points[0];\n const p1 = points[1];\n const angleBetween = Cartesian3.angleBetween(p0, p1);\n const numPoints = Math.ceil(angleBetween / granularity);\n const heights = new Array(numPoints);\n let i;\n if (h0 === h1) {\n for (i = 0; i < numPoints; i++) {\n heights[i] = h0;\n }\n heights.push(h1);\n return heights;\n }\n\n const dHeight = h1 - h0;\n const heightPerVertex = dHeight / numPoints;\n\n for (i = 1; i < numPoints; i++) {\n const h = h0 + i * heightPerVertex;\n heights[i] = h;\n }\n\n heights[0] = h0;\n heights.push(h1);\n return heights;\n}\n\nconst nextScratch = new Cartesian3();\nconst prevScratch = new Cartesian3();\n\nfunction computeRotationAngle(start, end, position, ellipsoid) {\n const tangentPlane = new EllipsoidTangentPlane(position, ellipsoid);\n const next = tangentPlane.projectPointOntoPlane(\n Cartesian3.add(position, start, nextScratch),\n nextScratch\n );\n const prev = tangentPlane.projectPointOntoPlane(\n Cartesian3.add(position, end, prevScratch),\n prevScratch\n );\n const angle = Cartesian2.angleBetween(next, prev);\n\n return prev.x * next.y - prev.y * next.x >= 0.0 ? -angle : angle;\n}\n\nconst negativeX = new Cartesian3(-1, 0, 0);\nlet transform = new Matrix4();\nconst translation = new Matrix4();\nlet rotationZ = new Matrix3();\nconst scaleMatrix = Matrix3.IDENTITY.clone();\nconst westScratch = new Cartesian3();\nconst finalPosScratch = new Cartesian4();\nconst heightCartesian = new Cartesian3();\nfunction addPosition(\n center,\n left,\n shape,\n finalPositions,\n ellipsoid,\n height,\n xScalar,\n repeat\n) {\n let west = westScratch;\n let finalPosition = finalPosScratch;\n transform = Transforms.eastNorthUpToFixedFrame(center, ellipsoid, transform);\n\n west = Matrix4.multiplyByPointAsVector(transform, negativeX, west);\n west = Cartesian3.normalize(west, west);\n const angle = computeRotationAngle(west, left, center, ellipsoid);\n rotationZ = Matrix3.fromRotationZ(angle, rotationZ);\n\n heightCartesian.z = height;\n transform = Matrix4.multiplyTransformation(\n transform,\n Matrix4.fromRotationTranslation(rotationZ, heightCartesian, translation),\n transform\n );\n const scale = scaleMatrix;\n scale[0] = xScalar;\n\n for (let j = 0; j < repeat; j++) {\n for (let i = 0; i < shape.length; i += 3) {\n finalPosition = Cartesian3.fromArray(shape, i, finalPosition);\n finalPosition = Matrix3.multiplyByVector(\n scale,\n finalPosition,\n finalPosition\n );\n finalPosition = Matrix4.multiplyByPoint(\n transform,\n finalPosition,\n finalPosition\n );\n finalPositions.push(finalPosition.x, finalPosition.y, finalPosition.z);\n }\n }\n\n return finalPositions;\n}\n\nconst centerScratch = new Cartesian3();\nfunction addPositions(\n centers,\n left,\n shape,\n finalPositions,\n ellipsoid,\n heights,\n xScalar\n) {\n for (let i = 0; i < centers.length; i += 3) {\n const center = Cartesian3.fromArray(centers, i, centerScratch);\n finalPositions = addPosition(\n center,\n left,\n shape,\n finalPositions,\n ellipsoid,\n heights[i / 3],\n xScalar,\n 1\n );\n }\n return finalPositions;\n}\n\nfunction convertShapeTo3DDuplicate(shape2D, boundingRectangle) {\n //orientate 2D shape to XZ plane center at (0, 0, 0), duplicate points\n const length = shape2D.length;\n const shape = new Array(length * 6);\n let index = 0;\n const xOffset = boundingRectangle.x + boundingRectangle.width / 2;\n const yOffset = boundingRectangle.y + boundingRectangle.height / 2;\n\n let point = shape2D[0];\n shape[index++] = point.x - xOffset;\n shape[index++] = 0.0;\n shape[index++] = point.y - yOffset;\n for (let i = 1; i < length; i++) {\n point = shape2D[i];\n const x = point.x - xOffset;\n const z = point.y - yOffset;\n shape[index++] = x;\n shape[index++] = 0.0;\n shape[index++] = z;\n\n shape[index++] = x;\n shape[index++] = 0.0;\n shape[index++] = z;\n }\n point = shape2D[0];\n shape[index++] = point.x - xOffset;\n shape[index++] = 0.0;\n shape[index++] = point.y - yOffset;\n\n return shape;\n}\n\nfunction convertShapeTo3D(shape2D, boundingRectangle) {\n //orientate 2D shape to XZ plane center at (0, 0, 0)\n const length = shape2D.length;\n const shape = new Array(length * 3);\n let index = 0;\n const xOffset = boundingRectangle.x + boundingRectangle.width / 2;\n const yOffset = boundingRectangle.y + boundingRectangle.height / 2;\n\n for (let i = 0; i < length; i++) {\n shape[index++] = shape2D[i].x - xOffset;\n shape[index++] = 0;\n shape[index++] = shape2D[i].y - yOffset;\n }\n\n return shape;\n}\n\nconst quaterion = new Quaternion();\nconst startPointScratch = new Cartesian3();\nconst rotMatrix = new Matrix3();\nfunction computeRoundCorner(\n pivot,\n startPoint,\n endPoint,\n cornerType,\n leftIsOutside,\n ellipsoid,\n finalPositions,\n shape,\n height,\n duplicatePoints\n) {\n const angle = Cartesian3.angleBetween(\n Cartesian3.subtract(startPoint, pivot, scratch1),\n Cartesian3.subtract(endPoint, pivot, scratch2)\n );\n const granularity =\n cornerType === CornerType.BEVELED\n ? 0\n : Math.ceil(angle / CesiumMath.toRadians(5));\n\n let m;\n if (leftIsOutside) {\n m = Matrix3.fromQuaternion(\n Quaternion.fromAxisAngle(\n Cartesian3.negate(pivot, scratch1),\n angle / (granularity + 1),\n quaterion\n ),\n rotMatrix\n );\n } else {\n m = Matrix3.fromQuaternion(\n Quaternion.fromAxisAngle(pivot, angle / (granularity + 1), quaterion),\n rotMatrix\n );\n }\n\n let left;\n let surfacePoint;\n startPoint = Cartesian3.clone(startPoint, startPointScratch);\n if (granularity > 0) {\n const repeat = duplicatePoints ? 2 : 1;\n for (let i = 0; i < granularity; i++) {\n startPoint = Matrix3.multiplyByVector(m, startPoint, startPoint);\n left = Cartesian3.subtract(startPoint, pivot, scratch1);\n left = Cartesian3.normalize(left, left);\n if (!leftIsOutside) {\n left = Cartesian3.negate(left, left);\n }\n surfacePoint = ellipsoid.scaleToGeodeticSurface(startPoint, scratch2);\n finalPositions = addPosition(\n surfacePoint,\n left,\n shape,\n finalPositions,\n ellipsoid,\n height,\n 1,\n repeat\n );\n }\n } else {\n left = Cartesian3.subtract(startPoint, pivot, scratch1);\n left = Cartesian3.normalize(left, left);\n if (!leftIsOutside) {\n left = Cartesian3.negate(left, left);\n }\n surfacePoint = ellipsoid.scaleToGeodeticSurface(startPoint, scratch2);\n finalPositions = addPosition(\n surfacePoint,\n left,\n shape,\n finalPositions,\n ellipsoid,\n height,\n 1,\n 1\n );\n\n endPoint = Cartesian3.clone(endPoint, startPointScratch);\n left = Cartesian3.subtract(endPoint, pivot, scratch1);\n left = Cartesian3.normalize(left, left);\n if (!leftIsOutside) {\n left = Cartesian3.negate(left, left);\n }\n surfacePoint = ellipsoid.scaleToGeodeticSurface(endPoint, scratch2);\n finalPositions = addPosition(\n surfacePoint,\n left,\n shape,\n finalPositions,\n ellipsoid,\n height,\n 1,\n 1\n );\n }\n\n return finalPositions;\n}\n\nPolylineVolumeGeometryLibrary.removeDuplicatesFromShape = function (\n shapePositions\n) {\n const length = shapePositions.length;\n const cleanedPositions = [];\n for (let i0 = length - 1, i1 = 0; i1 < length; i0 = i1++) {\n const v0 = shapePositions[i0];\n const v1 = shapePositions[i1];\n\n if (!Cartesian2.equals(v0, v1)) {\n cleanedPositions.push(v1); // Shallow copy!\n }\n }\n\n return cleanedPositions;\n};\n\nPolylineVolumeGeometryLibrary.angleIsGreaterThanPi = function (\n forward,\n backward,\n position,\n ellipsoid\n) {\n const tangentPlane = new EllipsoidTangentPlane(position, ellipsoid);\n const next = tangentPlane.projectPointOntoPlane(\n Cartesian3.add(position, forward, nextScratch),\n nextScratch\n );\n const prev = tangentPlane.projectPointOntoPlane(\n Cartesian3.add(position, backward, prevScratch),\n prevScratch\n );\n\n return prev.x * next.y - prev.y * next.x >= 0.0;\n};\n\nconst scratchForwardProjection = new Cartesian3();\nconst scratchBackwardProjection = new Cartesian3();\n\nPolylineVolumeGeometryLibrary.computePositions = function (\n positions,\n shape2D,\n boundingRectangle,\n geometry,\n duplicatePoints\n) {\n const ellipsoid = geometry._ellipsoid;\n const heights = scaleToSurface(positions, ellipsoid);\n const granularity = geometry._granularity;\n const cornerType = geometry._cornerType;\n const shapeForSides = duplicatePoints\n ? convertShapeTo3DDuplicate(shape2D, boundingRectangle)\n : convertShapeTo3D(shape2D, boundingRectangle);\n const shapeForEnds = duplicatePoints\n ? convertShapeTo3D(shape2D, boundingRectangle)\n : undefined;\n const heightOffset = boundingRectangle.height / 2;\n const width = boundingRectangle.width / 2;\n let length = positions.length;\n let finalPositions = [];\n let ends = duplicatePoints ? [] : undefined;\n\n let forward = scratchCartesian1;\n let backward = scratchCartesian2;\n let cornerDirection = scratchCartesian3;\n let surfaceNormal = scratchCartesian4;\n let pivot = scratchCartesian5;\n let start = scratchCartesian6;\n let end = scratchCartesian7;\n let left = scratchCartesian8;\n let previousPosition = scratchCartesian9;\n\n let position = positions[0];\n let nextPosition = positions[1];\n surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal);\n forward = Cartesian3.subtract(nextPosition, position, forward);\n forward = Cartesian3.normalize(forward, forward);\n left = Cartesian3.cross(surfaceNormal, forward, left);\n left = Cartesian3.normalize(left, left);\n let h0 = heights[0];\n let h1 = heights[1];\n if (duplicatePoints) {\n ends = addPosition(\n position,\n left,\n shapeForEnds,\n ends,\n ellipsoid,\n h0 + heightOffset,\n 1,\n 1\n );\n }\n previousPosition = Cartesian3.clone(position, previousPosition);\n position = nextPosition;\n backward = Cartesian3.negate(forward, backward);\n let subdividedHeights;\n let subdividedPositions;\n for (let i = 1; i < length - 1; i++) {\n const repeat = duplicatePoints ? 2 : 1;\n nextPosition = positions[i + 1];\n if (position.equals(nextPosition)) {\n oneTimeWarning(\n \"Positions are too close and are considered equivalent with rounding error.\"\n );\n continue;\n }\n forward = Cartesian3.subtract(nextPosition, position, forward);\n forward = Cartesian3.normalize(forward, forward);\n cornerDirection = Cartesian3.add(forward, backward, cornerDirection);\n cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection);\n surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal);\n\n const forwardProjection = Cartesian3.multiplyByScalar(\n surfaceNormal,\n Cartesian3.dot(forward, surfaceNormal),\n scratchForwardProjection\n );\n Cartesian3.subtract(forward, forwardProjection, forwardProjection);\n Cartesian3.normalize(forwardProjection, forwardProjection);\n\n const backwardProjection = Cartesian3.multiplyByScalar(\n surfaceNormal,\n Cartesian3.dot(backward, surfaceNormal),\n scratchBackwardProjection\n );\n Cartesian3.subtract(backward, backwardProjection, backwardProjection);\n Cartesian3.normalize(backwardProjection, backwardProjection);\n\n const doCorner = !CesiumMath.equalsEpsilon(\n Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)),\n 1.0,\n CesiumMath.EPSILON7\n );\n\n if (doCorner) {\n cornerDirection = Cartesian3.cross(\n cornerDirection,\n surfaceNormal,\n cornerDirection\n );\n cornerDirection = Cartesian3.cross(\n surfaceNormal,\n cornerDirection,\n cornerDirection\n );\n cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection);\n const scalar =\n 1 /\n Math.max(\n 0.25,\n Cartesian3.magnitude(\n Cartesian3.cross(cornerDirection, backward, scratch1)\n )\n );\n const leftIsOutside = PolylineVolumeGeometryLibrary.angleIsGreaterThanPi(\n forward,\n backward,\n position,\n ellipsoid\n );\n if (leftIsOutside) {\n pivot = Cartesian3.add(\n position,\n Cartesian3.multiplyByScalar(\n cornerDirection,\n scalar * width,\n cornerDirection\n ),\n pivot\n );\n start = Cartesian3.add(\n pivot,\n Cartesian3.multiplyByScalar(left, width, start),\n start\n );\n scratch2Array[0] = Cartesian3.clone(previousPosition, scratch2Array[0]);\n scratch2Array[1] = Cartesian3.clone(start, scratch2Array[1]);\n subdividedHeights = subdivideHeights(\n scratch2Array,\n h0 + heightOffset,\n h1 + heightOffset,\n granularity\n );\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scratch2Array,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n finalPositions = addPositions(\n subdividedPositions,\n left,\n shapeForSides,\n finalPositions,\n ellipsoid,\n subdividedHeights,\n 1\n );\n left = Cartesian3.cross(surfaceNormal, forward, left);\n left = Cartesian3.normalize(left, left);\n end = Cartesian3.add(\n pivot,\n Cartesian3.multiplyByScalar(left, width, end),\n end\n );\n if (\n cornerType === CornerType.ROUNDED ||\n cornerType === CornerType.BEVELED\n ) {\n computeRoundCorner(\n pivot,\n start,\n end,\n cornerType,\n leftIsOutside,\n ellipsoid,\n finalPositions,\n shapeForSides,\n h1 + heightOffset,\n duplicatePoints\n );\n } else {\n cornerDirection = Cartesian3.negate(cornerDirection, cornerDirection);\n finalPositions = addPosition(\n position,\n cornerDirection,\n shapeForSides,\n finalPositions,\n ellipsoid,\n h1 + heightOffset,\n scalar,\n repeat\n );\n }\n previousPosition = Cartesian3.clone(end, previousPosition);\n } else {\n pivot = Cartesian3.add(\n position,\n Cartesian3.multiplyByScalar(\n cornerDirection,\n scalar * width,\n cornerDirection\n ),\n pivot\n );\n start = Cartesian3.add(\n pivot,\n Cartesian3.multiplyByScalar(left, -width, start),\n start\n );\n scratch2Array[0] = Cartesian3.clone(previousPosition, scratch2Array[0]);\n scratch2Array[1] = Cartesian3.clone(start, scratch2Array[1]);\n subdividedHeights = subdivideHeights(\n scratch2Array,\n h0 + heightOffset,\n h1 + heightOffset,\n granularity\n );\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scratch2Array,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n finalPositions = addPositions(\n subdividedPositions,\n left,\n shapeForSides,\n finalPositions,\n ellipsoid,\n subdividedHeights,\n 1\n );\n left = Cartesian3.cross(surfaceNormal, forward, left);\n left = Cartesian3.normalize(left, left);\n end = Cartesian3.add(\n pivot,\n Cartesian3.multiplyByScalar(left, -width, end),\n end\n );\n if (\n cornerType === CornerType.ROUNDED ||\n cornerType === CornerType.BEVELED\n ) {\n computeRoundCorner(\n pivot,\n start,\n end,\n cornerType,\n leftIsOutside,\n ellipsoid,\n finalPositions,\n shapeForSides,\n h1 + heightOffset,\n duplicatePoints\n );\n } else {\n finalPositions = addPosition(\n position,\n cornerDirection,\n shapeForSides,\n finalPositions,\n ellipsoid,\n h1 + heightOffset,\n scalar,\n repeat\n );\n }\n previousPosition = Cartesian3.clone(end, previousPosition);\n }\n backward = Cartesian3.negate(forward, backward);\n } else {\n finalPositions = addPosition(\n previousPosition,\n left,\n shapeForSides,\n finalPositions,\n ellipsoid,\n h0 + heightOffset,\n 1,\n 1\n );\n previousPosition = position;\n }\n h0 = h1;\n h1 = heights[i + 1];\n position = nextPosition;\n }\n\n scratch2Array[0] = Cartesian3.clone(previousPosition, scratch2Array[0]);\n scratch2Array[1] = Cartesian3.clone(position, scratch2Array[1]);\n subdividedHeights = subdivideHeights(\n scratch2Array,\n h0 + heightOffset,\n h1 + heightOffset,\n granularity\n );\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scratch2Array,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n finalPositions = addPositions(\n subdividedPositions,\n left,\n shapeForSides,\n finalPositions,\n ellipsoid,\n subdividedHeights,\n 1\n );\n if (duplicatePoints) {\n ends = addPosition(\n position,\n left,\n shapeForEnds,\n ends,\n ellipsoid,\n h1 + heightOffset,\n 1,\n 1\n );\n }\n\n length = finalPositions.length;\n const posLength = duplicatePoints ? length + ends.length : length;\n const combinedPositions = new Float64Array(posLength);\n combinedPositions.set(finalPositions);\n if (duplicatePoints) {\n combinedPositions.set(ends, length);\n }\n\n return combinedPositions;\n};\nexport default PolylineVolumeGeometryLibrary;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport CornerType from \"./CornerType.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PolylinePipeline from \"./PolylinePipeline.js\";\nimport PolylineVolumeGeometryLibrary from \"./PolylineVolumeGeometryLibrary.js\";\nimport Quaternion from \"./Quaternion.js\";\n\n/**\n * @private\n */\nconst CorridorGeometryLibrary = {};\n\nconst scratch1 = new Cartesian3();\nconst scratch2 = new Cartesian3();\nconst scratch3 = new Cartesian3();\nconst scratch4 = new Cartesian3();\n\nconst scaleArray2 = [new Cartesian3(), new Cartesian3()];\n\nconst cartesian1 = new Cartesian3();\nconst cartesian2 = new Cartesian3();\nconst cartesian3 = new Cartesian3();\nconst cartesian4 = new Cartesian3();\nconst cartesian5 = new Cartesian3();\nconst cartesian6 = new Cartesian3();\nconst cartesian7 = new Cartesian3();\nconst cartesian8 = new Cartesian3();\nconst cartesian9 = new Cartesian3();\nconst cartesian10 = new Cartesian3();\n\nconst quaterion = new Quaternion();\nconst rotMatrix = new Matrix3();\nfunction computeRoundCorner(\n cornerPoint,\n startPoint,\n endPoint,\n cornerType,\n leftIsOutside\n) {\n const angle = Cartesian3.angleBetween(\n Cartesian3.subtract(startPoint, cornerPoint, scratch1),\n Cartesian3.subtract(endPoint, cornerPoint, scratch2)\n );\n const granularity =\n cornerType === CornerType.BEVELED\n ? 1\n : Math.ceil(angle / CesiumMath.toRadians(5)) + 1;\n\n const size = granularity * 3;\n const array = new Array(size);\n\n array[size - 3] = endPoint.x;\n array[size - 2] = endPoint.y;\n array[size - 1] = endPoint.z;\n\n let m;\n if (leftIsOutside) {\n m = Matrix3.fromQuaternion(\n Quaternion.fromAxisAngle(\n Cartesian3.negate(cornerPoint, scratch1),\n angle / granularity,\n quaterion\n ),\n rotMatrix\n );\n } else {\n m = Matrix3.fromQuaternion(\n Quaternion.fromAxisAngle(cornerPoint, angle / granularity, quaterion),\n rotMatrix\n );\n }\n\n let index = 0;\n startPoint = Cartesian3.clone(startPoint, scratch1);\n for (let i = 0; i < granularity; i++) {\n startPoint = Matrix3.multiplyByVector(m, startPoint, startPoint);\n array[index++] = startPoint.x;\n array[index++] = startPoint.y;\n array[index++] = startPoint.z;\n }\n\n return array;\n}\n\nfunction addEndCaps(calculatedPositions) {\n let cornerPoint = cartesian1;\n let startPoint = cartesian2;\n let endPoint = cartesian3;\n\n let leftEdge = calculatedPositions[1];\n startPoint = Cartesian3.fromArray(\n calculatedPositions[1],\n leftEdge.length - 3,\n startPoint\n );\n endPoint = Cartesian3.fromArray(calculatedPositions[0], 0, endPoint);\n cornerPoint = Cartesian3.midpoint(startPoint, endPoint, cornerPoint);\n const firstEndCap = computeRoundCorner(\n cornerPoint,\n startPoint,\n endPoint,\n CornerType.ROUNDED,\n false\n );\n\n const length = calculatedPositions.length - 1;\n const rightEdge = calculatedPositions[length - 1];\n leftEdge = calculatedPositions[length];\n startPoint = Cartesian3.fromArray(\n rightEdge,\n rightEdge.length - 3,\n startPoint\n );\n endPoint = Cartesian3.fromArray(leftEdge, 0, endPoint);\n cornerPoint = Cartesian3.midpoint(startPoint, endPoint, cornerPoint);\n const lastEndCap = computeRoundCorner(\n cornerPoint,\n startPoint,\n endPoint,\n CornerType.ROUNDED,\n false\n );\n\n return [firstEndCap, lastEndCap];\n}\n\nfunction computeMiteredCorner(\n position,\n leftCornerDirection,\n lastPoint,\n leftIsOutside\n) {\n let cornerPoint = scratch1;\n if (leftIsOutside) {\n cornerPoint = Cartesian3.add(position, leftCornerDirection, cornerPoint);\n } else {\n leftCornerDirection = Cartesian3.negate(\n leftCornerDirection,\n leftCornerDirection\n );\n cornerPoint = Cartesian3.add(position, leftCornerDirection, cornerPoint);\n }\n return [\n cornerPoint.x,\n cornerPoint.y,\n cornerPoint.z,\n lastPoint.x,\n lastPoint.y,\n lastPoint.z,\n ];\n}\n\nfunction addShiftedPositions(positions, left, scalar, calculatedPositions) {\n const rightPositions = new Array(positions.length);\n const leftPositions = new Array(positions.length);\n const scaledLeft = Cartesian3.multiplyByScalar(left, scalar, scratch1);\n const scaledRight = Cartesian3.negate(scaledLeft, scratch2);\n let rightIndex = 0;\n let leftIndex = positions.length - 1;\n\n for (let i = 0; i < positions.length; i += 3) {\n const pos = Cartesian3.fromArray(positions, i, scratch3);\n const rightPos = Cartesian3.add(pos, scaledRight, scratch4);\n rightPositions[rightIndex++] = rightPos.x;\n rightPositions[rightIndex++] = rightPos.y;\n rightPositions[rightIndex++] = rightPos.z;\n\n const leftPos = Cartesian3.add(pos, scaledLeft, scratch4);\n leftPositions[leftIndex--] = leftPos.z;\n leftPositions[leftIndex--] = leftPos.y;\n leftPositions[leftIndex--] = leftPos.x;\n }\n calculatedPositions.push(rightPositions, leftPositions);\n\n return calculatedPositions;\n}\n\n/**\n * @private\n */\nCorridorGeometryLibrary.addAttribute = function (\n attribute,\n value,\n front,\n back\n) {\n const x = value.x;\n const y = value.y;\n const z = value.z;\n if (defined(front)) {\n attribute[front] = x;\n attribute[front + 1] = y;\n attribute[front + 2] = z;\n }\n if (defined(back)) {\n attribute[back] = z;\n attribute[back - 1] = y;\n attribute[back - 2] = x;\n }\n};\n\nconst scratchForwardProjection = new Cartesian3();\nconst scratchBackwardProjection = new Cartesian3();\n\n/**\n * @private\n */\nCorridorGeometryLibrary.computePositions = function (params) {\n const granularity = params.granularity;\n const positions = params.positions;\n const ellipsoid = params.ellipsoid;\n const width = params.width / 2;\n const cornerType = params.cornerType;\n const saveAttributes = params.saveAttributes;\n let normal = cartesian1;\n let forward = cartesian2;\n let backward = cartesian3;\n let left = cartesian4;\n let cornerDirection = cartesian5;\n let startPoint = cartesian6;\n let previousPos = cartesian7;\n let rightPos = cartesian8;\n let leftPos = cartesian9;\n let center = cartesian10;\n let calculatedPositions = [];\n const calculatedLefts = saveAttributes ? [] : undefined;\n const calculatedNormals = saveAttributes ? [] : undefined;\n let position = positions[0]; //add first point\n let nextPosition = positions[1];\n\n forward = Cartesian3.normalize(\n Cartesian3.subtract(nextPosition, position, forward),\n forward\n );\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n left = Cartesian3.normalize(Cartesian3.cross(normal, forward, left), left);\n if (saveAttributes) {\n calculatedLefts.push(left.x, left.y, left.z);\n calculatedNormals.push(normal.x, normal.y, normal.z);\n }\n previousPos = Cartesian3.clone(position, previousPos);\n position = nextPosition;\n backward = Cartesian3.negate(forward, backward);\n\n let subdividedPositions;\n const corners = [];\n let i;\n const length = positions.length;\n for (i = 1; i < length - 1; i++) {\n // add middle points and corners\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n nextPosition = positions[i + 1];\n forward = Cartesian3.normalize(\n Cartesian3.subtract(nextPosition, position, forward),\n forward\n );\n cornerDirection = Cartesian3.normalize(\n Cartesian3.add(forward, backward, cornerDirection),\n cornerDirection\n );\n\n const forwardProjection = Cartesian3.multiplyByScalar(\n normal,\n Cartesian3.dot(forward, normal),\n scratchForwardProjection\n );\n Cartesian3.subtract(forward, forwardProjection, forwardProjection);\n Cartesian3.normalize(forwardProjection, forwardProjection);\n\n const backwardProjection = Cartesian3.multiplyByScalar(\n normal,\n Cartesian3.dot(backward, normal),\n scratchBackwardProjection\n );\n Cartesian3.subtract(backward, backwardProjection, backwardProjection);\n Cartesian3.normalize(backwardProjection, backwardProjection);\n\n const doCorner = !CesiumMath.equalsEpsilon(\n Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)),\n 1.0,\n CesiumMath.EPSILON7\n );\n\n if (doCorner) {\n cornerDirection = Cartesian3.cross(\n cornerDirection,\n normal,\n cornerDirection\n );\n cornerDirection = Cartesian3.cross(\n normal,\n cornerDirection,\n cornerDirection\n );\n cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection);\n const scalar =\n width /\n Math.max(\n 0.25,\n Cartesian3.magnitude(\n Cartesian3.cross(cornerDirection, backward, scratch1)\n )\n );\n const leftIsOutside = PolylineVolumeGeometryLibrary.angleIsGreaterThanPi(\n forward,\n backward,\n position,\n ellipsoid\n );\n cornerDirection = Cartesian3.multiplyByScalar(\n cornerDirection,\n scalar,\n cornerDirection\n );\n if (leftIsOutside) {\n rightPos = Cartesian3.add(position, cornerDirection, rightPos);\n center = Cartesian3.add(\n rightPos,\n Cartesian3.multiplyByScalar(left, width, center),\n center\n );\n leftPos = Cartesian3.add(\n rightPos,\n Cartesian3.multiplyByScalar(left, width * 2, leftPos),\n leftPos\n );\n scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);\n scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]);\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scaleArray2,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n calculatedPositions = addShiftedPositions(\n subdividedPositions,\n left,\n width,\n calculatedPositions\n );\n if (saveAttributes) {\n calculatedLefts.push(left.x, left.y, left.z);\n calculatedNormals.push(normal.x, normal.y, normal.z);\n }\n startPoint = Cartesian3.clone(leftPos, startPoint);\n left = Cartesian3.normalize(\n Cartesian3.cross(normal, forward, left),\n left\n );\n leftPos = Cartesian3.add(\n rightPos,\n Cartesian3.multiplyByScalar(left, width * 2, leftPos),\n leftPos\n );\n previousPos = Cartesian3.add(\n rightPos,\n Cartesian3.multiplyByScalar(left, width, previousPos),\n previousPos\n );\n if (\n cornerType === CornerType.ROUNDED ||\n cornerType === CornerType.BEVELED\n ) {\n corners.push({\n leftPositions: computeRoundCorner(\n rightPos,\n startPoint,\n leftPos,\n cornerType,\n leftIsOutside\n ),\n });\n } else {\n corners.push({\n leftPositions: computeMiteredCorner(\n position,\n Cartesian3.negate(cornerDirection, cornerDirection),\n leftPos,\n leftIsOutside\n ),\n });\n }\n } else {\n leftPos = Cartesian3.add(position, cornerDirection, leftPos);\n center = Cartesian3.add(\n leftPos,\n Cartesian3.negate(\n Cartesian3.multiplyByScalar(left, width, center),\n center\n ),\n center\n );\n rightPos = Cartesian3.add(\n leftPos,\n Cartesian3.negate(\n Cartesian3.multiplyByScalar(left, width * 2, rightPos),\n rightPos\n ),\n rightPos\n );\n scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);\n scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]);\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scaleArray2,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n calculatedPositions = addShiftedPositions(\n subdividedPositions,\n left,\n width,\n calculatedPositions\n );\n if (saveAttributes) {\n calculatedLefts.push(left.x, left.y, left.z);\n calculatedNormals.push(normal.x, normal.y, normal.z);\n }\n startPoint = Cartesian3.clone(rightPos, startPoint);\n left = Cartesian3.normalize(\n Cartesian3.cross(normal, forward, left),\n left\n );\n rightPos = Cartesian3.add(\n leftPos,\n Cartesian3.negate(\n Cartesian3.multiplyByScalar(left, width * 2, rightPos),\n rightPos\n ),\n rightPos\n );\n previousPos = Cartesian3.add(\n leftPos,\n Cartesian3.negate(\n Cartesian3.multiplyByScalar(left, width, previousPos),\n previousPos\n ),\n previousPos\n );\n if (\n cornerType === CornerType.ROUNDED ||\n cornerType === CornerType.BEVELED\n ) {\n corners.push({\n rightPositions: computeRoundCorner(\n leftPos,\n startPoint,\n rightPos,\n cornerType,\n leftIsOutside\n ),\n });\n } else {\n corners.push({\n rightPositions: computeMiteredCorner(\n position,\n cornerDirection,\n rightPos,\n leftIsOutside\n ),\n });\n }\n }\n backward = Cartesian3.negate(forward, backward);\n }\n position = nextPosition;\n }\n\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);\n scaleArray2[1] = Cartesian3.clone(position, scaleArray2[1]);\n subdividedPositions = PolylinePipeline.generateArc({\n positions: scaleArray2,\n granularity: granularity,\n ellipsoid: ellipsoid,\n });\n calculatedPositions = addShiftedPositions(\n subdividedPositions,\n left,\n width,\n calculatedPositions\n );\n if (saveAttributes) {\n calculatedLefts.push(left.x, left.y, left.z);\n calculatedNormals.push(normal.x, normal.y, normal.z);\n }\n\n let endPositions;\n if (cornerType === CornerType.ROUNDED) {\n endPositions = addEndCaps(calculatedPositions);\n }\n\n return {\n positions: calculatedPositions,\n corners: corners,\n lefts: calculatedLefts,\n normals: calculatedNormals,\n endPositions: endPositions,\n };\n};\nexport default CorridorGeometryLibrary;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CornerType from \"./CornerType.js\";\nimport CorridorGeometryLibrary from \"./CorridorGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst cartesian1 = new Cartesian3();\nconst cartesian2 = new Cartesian3();\nconst cartesian3 = new Cartesian3();\nconst cartesian4 = new Cartesian3();\nconst cartesian5 = new Cartesian3();\nconst cartesian6 = new Cartesian3();\n\nconst scratch1 = new Cartesian3();\nconst scratch2 = new Cartesian3();\n\nfunction scaleToSurface(positions, ellipsoid) {\n for (let i = 0; i < positions.length; i++) {\n positions[i] = ellipsoid.scaleToGeodeticSurface(positions[i], positions[i]);\n }\n return positions;\n}\n\nfunction addNormals(attr, normal, left, front, back, vertexFormat) {\n const normals = attr.normals;\n const tangents = attr.tangents;\n const bitangents = attr.bitangents;\n const forward = Cartesian3.normalize(\n Cartesian3.cross(left, normal, scratch1),\n scratch1\n );\n if (vertexFormat.normal) {\n CorridorGeometryLibrary.addAttribute(normals, normal, front, back);\n }\n if (vertexFormat.tangent) {\n CorridorGeometryLibrary.addAttribute(tangents, forward, front, back);\n }\n if (vertexFormat.bitangent) {\n CorridorGeometryLibrary.addAttribute(bitangents, left, front, back);\n }\n}\n\nfunction combine(computedPositions, vertexFormat, ellipsoid) {\n const positions = computedPositions.positions;\n const corners = computedPositions.corners;\n const endPositions = computedPositions.endPositions;\n const computedLefts = computedPositions.lefts;\n const computedNormals = computedPositions.normals;\n const attributes = new GeometryAttributes();\n let corner;\n let leftCount = 0;\n let rightCount = 0;\n let i;\n let indicesLength = 0;\n let length;\n for (i = 0; i < positions.length; i += 2) {\n length = positions[i].length - 3;\n leftCount += length; //subtracting 3 to account for duplicate points at corners\n indicesLength += length * 2;\n rightCount += positions[i + 1].length - 3;\n }\n leftCount += 3; //add back count for end positions\n rightCount += 3;\n for (i = 0; i < corners.length; i++) {\n corner = corners[i];\n const leftSide = corners[i].leftPositions;\n if (defined(leftSide)) {\n length = leftSide.length;\n leftCount += length;\n indicesLength += length;\n } else {\n length = corners[i].rightPositions.length;\n rightCount += length;\n indicesLength += length;\n }\n }\n\n const addEndPositions = defined(endPositions);\n let endPositionLength;\n if (addEndPositions) {\n endPositionLength = endPositions[0].length - 3;\n leftCount += endPositionLength;\n rightCount += endPositionLength;\n endPositionLength /= 3;\n indicesLength += endPositionLength * 6;\n }\n const size = leftCount + rightCount;\n const finalPositions = new Float64Array(size);\n const normals = vertexFormat.normal ? new Float32Array(size) : undefined;\n const tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(size)\n : undefined;\n const attr = {\n normals: normals,\n tangents: tangents,\n bitangents: bitangents,\n };\n let front = 0;\n let back = size - 1;\n let UL, LL, UR, LR;\n let normal = cartesian1;\n let left = cartesian2;\n let rightPos, leftPos;\n const halfLength = endPositionLength / 2;\n\n const indices = IndexDatatype.createTypedArray(size / 3, indicesLength);\n let index = 0;\n if (addEndPositions) {\n // add rounded end\n leftPos = cartesian3;\n rightPos = cartesian4;\n const firstEndPositions = endPositions[0];\n normal = Cartesian3.fromArray(computedNormals, 0, normal);\n left = Cartesian3.fromArray(computedLefts, 0, left);\n for (i = 0; i < halfLength; i++) {\n leftPos = Cartesian3.fromArray(\n firstEndPositions,\n (halfLength - 1 - i) * 3,\n leftPos\n );\n rightPos = Cartesian3.fromArray(\n firstEndPositions,\n (halfLength + i) * 3,\n rightPos\n );\n CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front);\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n leftPos,\n undefined,\n back\n );\n addNormals(attr, normal, left, front, back, vertexFormat);\n\n LL = front / 3;\n LR = LL + 1;\n UL = (back - 2) / 3;\n UR = UL - 1;\n indices[index++] = UL;\n indices[index++] = LL;\n indices[index++] = UR;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n }\n\n let posIndex = 0;\n let compIndex = 0;\n let rightEdge = positions[posIndex++]; //add first two edges\n let leftEdge = positions[posIndex++];\n finalPositions.set(rightEdge, front);\n finalPositions.set(leftEdge, back - leftEdge.length + 1);\n\n left = Cartesian3.fromArray(computedLefts, compIndex, left);\n let rightNormal;\n let leftNormal;\n length = leftEdge.length - 3;\n for (i = 0; i < length; i += 3) {\n rightNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(rightEdge, i, scratch1),\n scratch1\n );\n leftNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(leftEdge, length - i, scratch2),\n scratch2\n );\n normal = Cartesian3.normalize(\n Cartesian3.add(rightNormal, leftNormal, normal),\n normal\n );\n addNormals(attr, normal, left, front, back, vertexFormat);\n\n LL = front / 3;\n LR = LL + 1;\n UL = (back - 2) / 3;\n UR = UL - 1;\n indices[index++] = UL;\n indices[index++] = LL;\n indices[index++] = UR;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n\n rightNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(rightEdge, length, scratch1),\n scratch1\n );\n leftNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(leftEdge, length, scratch2),\n scratch2\n );\n normal = Cartesian3.normalize(\n Cartesian3.add(rightNormal, leftNormal, normal),\n normal\n );\n compIndex += 3;\n for (i = 0; i < corners.length; i++) {\n let j;\n corner = corners[i];\n const l = corner.leftPositions;\n const r = corner.rightPositions;\n let pivot;\n let start;\n let outsidePoint = cartesian6;\n let previousPoint = cartesian3;\n let nextPoint = cartesian4;\n normal = Cartesian3.fromArray(computedNormals, compIndex, normal);\n if (defined(l)) {\n addNormals(attr, normal, left, undefined, back, vertexFormat);\n back -= 3;\n pivot = LR;\n start = UR;\n for (j = 0; j < l.length / 3; j++) {\n outsidePoint = Cartesian3.fromArray(l, j * 3, outsidePoint);\n indices[index++] = pivot;\n indices[index++] = start - j - 1;\n indices[index++] = start - j;\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n outsidePoint,\n undefined,\n back\n );\n previousPoint = Cartesian3.fromArray(\n finalPositions,\n (start - j - 1) * 3,\n previousPoint\n );\n nextPoint = Cartesian3.fromArray(finalPositions, pivot * 3, nextPoint);\n left = Cartesian3.normalize(\n Cartesian3.subtract(previousPoint, nextPoint, left),\n left\n );\n addNormals(attr, normal, left, undefined, back, vertexFormat);\n back -= 3;\n }\n outsidePoint = Cartesian3.fromArray(\n finalPositions,\n pivot * 3,\n outsidePoint\n );\n previousPoint = Cartesian3.subtract(\n Cartesian3.fromArray(finalPositions, start * 3, previousPoint),\n outsidePoint,\n previousPoint\n );\n nextPoint = Cartesian3.subtract(\n Cartesian3.fromArray(finalPositions, (start - j) * 3, nextPoint),\n outsidePoint,\n nextPoint\n );\n left = Cartesian3.normalize(\n Cartesian3.add(previousPoint, nextPoint, left),\n left\n );\n addNormals(attr, normal, left, front, undefined, vertexFormat);\n front += 3;\n } else {\n addNormals(attr, normal, left, front, undefined, vertexFormat);\n front += 3;\n pivot = UR;\n start = LR;\n for (j = 0; j < r.length / 3; j++) {\n outsidePoint = Cartesian3.fromArray(r, j * 3, outsidePoint);\n indices[index++] = pivot;\n indices[index++] = start + j;\n indices[index++] = start + j + 1;\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n outsidePoint,\n front\n );\n previousPoint = Cartesian3.fromArray(\n finalPositions,\n pivot * 3,\n previousPoint\n );\n nextPoint = Cartesian3.fromArray(\n finalPositions,\n (start + j) * 3,\n nextPoint\n );\n left = Cartesian3.normalize(\n Cartesian3.subtract(previousPoint, nextPoint, left),\n left\n );\n addNormals(attr, normal, left, front, undefined, vertexFormat);\n front += 3;\n }\n outsidePoint = Cartesian3.fromArray(\n finalPositions,\n pivot * 3,\n outsidePoint\n );\n previousPoint = Cartesian3.subtract(\n Cartesian3.fromArray(finalPositions, (start + j) * 3, previousPoint),\n outsidePoint,\n previousPoint\n );\n nextPoint = Cartesian3.subtract(\n Cartesian3.fromArray(finalPositions, start * 3, nextPoint),\n outsidePoint,\n nextPoint\n );\n left = Cartesian3.normalize(\n Cartesian3.negate(Cartesian3.add(nextPoint, previousPoint, left), left),\n left\n );\n addNormals(attr, normal, left, undefined, back, vertexFormat);\n back -= 3;\n }\n rightEdge = positions[posIndex++];\n leftEdge = positions[posIndex++];\n rightEdge.splice(0, 3); //remove duplicate points added by corner\n leftEdge.splice(leftEdge.length - 3, 3);\n finalPositions.set(rightEdge, front);\n finalPositions.set(leftEdge, back - leftEdge.length + 1);\n length = leftEdge.length - 3;\n\n compIndex += 3;\n left = Cartesian3.fromArray(computedLefts, compIndex, left);\n for (j = 0; j < leftEdge.length; j += 3) {\n rightNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(rightEdge, j, scratch1),\n scratch1\n );\n leftNormal = ellipsoid.geodeticSurfaceNormal(\n Cartesian3.fromArray(leftEdge, length - j, scratch2),\n scratch2\n );\n normal = Cartesian3.normalize(\n Cartesian3.add(rightNormal, leftNormal, normal),\n normal\n );\n addNormals(attr, normal, left, front, back, vertexFormat);\n\n LR = front / 3;\n LL = LR - 1;\n UR = (back - 2) / 3;\n UL = UR + 1;\n indices[index++] = UL;\n indices[index++] = LL;\n indices[index++] = UR;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n front -= 3;\n back += 3;\n }\n normal = Cartesian3.fromArray(\n computedNormals,\n computedNormals.length - 3,\n normal\n );\n addNormals(attr, normal, left, front, back, vertexFormat);\n\n if (addEndPositions) {\n // add rounded end\n front += 3;\n back -= 3;\n leftPos = cartesian3;\n rightPos = cartesian4;\n const lastEndPositions = endPositions[1];\n for (i = 0; i < halfLength; i++) {\n leftPos = Cartesian3.fromArray(\n lastEndPositions,\n (endPositionLength - i - 1) * 3,\n leftPos\n );\n rightPos = Cartesian3.fromArray(lastEndPositions, i * 3, rightPos);\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n leftPos,\n undefined,\n back\n );\n CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front);\n addNormals(attr, normal, left, front, back, vertexFormat);\n\n LR = front / 3;\n LL = LR - 1;\n UR = (back - 2) / 3;\n UL = UR + 1;\n indices[index++] = UL;\n indices[index++] = LL;\n indices[index++] = UR;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n }\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: finalPositions,\n });\n\n if (vertexFormat.st) {\n const st = new Float32Array((size / 3) * 2);\n let rightSt;\n let leftSt;\n let stIndex = 0;\n if (addEndPositions) {\n leftCount /= 3;\n rightCount /= 3;\n const theta = Math.PI / (endPositionLength + 1);\n leftSt = 1 / (leftCount - endPositionLength + 1);\n rightSt = 1 / (rightCount - endPositionLength + 1);\n let a;\n const halfEndPos = endPositionLength / 2;\n for (i = halfEndPos + 1; i < endPositionLength + 1; i++) {\n // lower left rounded end\n a = CesiumMath.PI_OVER_TWO + theta * i;\n st[stIndex++] = rightSt * (1 + Math.cos(a));\n st[stIndex++] = 0.5 * (1 + Math.sin(a));\n }\n for (i = 1; i < rightCount - endPositionLength + 1; i++) {\n // bottom edge\n st[stIndex++] = i * rightSt;\n st[stIndex++] = 0;\n }\n for (i = endPositionLength; i > halfEndPos; i--) {\n // lower right rounded end\n a = CesiumMath.PI_OVER_TWO - i * theta;\n st[stIndex++] = 1 - rightSt * (1 + Math.cos(a));\n st[stIndex++] = 0.5 * (1 + Math.sin(a));\n }\n for (i = halfEndPos; i > 0; i--) {\n // upper right rounded end\n a = CesiumMath.PI_OVER_TWO - theta * i;\n st[stIndex++] = 1 - leftSt * (1 + Math.cos(a));\n st[stIndex++] = 0.5 * (1 + Math.sin(a));\n }\n for (i = leftCount - endPositionLength; i > 0; i--) {\n // top edge\n st[stIndex++] = i * leftSt;\n st[stIndex++] = 1;\n }\n for (i = 1; i < halfEndPos + 1; i++) {\n // upper left rounded end\n a = CesiumMath.PI_OVER_TWO + theta * i;\n st[stIndex++] = leftSt * (1 + Math.cos(a));\n st[stIndex++] = 0.5 * (1 + Math.sin(a));\n }\n } else {\n leftCount /= 3;\n rightCount /= 3;\n leftSt = 1 / (leftCount - 1);\n rightSt = 1 / (rightCount - 1);\n for (i = 0; i < rightCount; i++) {\n // bottom edge\n st[stIndex++] = i * rightSt;\n st[stIndex++] = 0;\n }\n for (i = leftCount; i > 0; i--) {\n // top edge\n st[stIndex++] = (i - 1) * leftSt;\n st[stIndex++] = 1;\n }\n }\n\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: st,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attr.normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attr.tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attr.bitangents,\n });\n }\n\n return {\n attributes: attributes,\n indices: indices,\n };\n}\n\nfunction extrudedAttributes(attributes, vertexFormat) {\n if (\n !vertexFormat.normal &&\n !vertexFormat.tangent &&\n !vertexFormat.bitangent &&\n !vertexFormat.st\n ) {\n return attributes;\n }\n const positions = attributes.position.values;\n let topNormals;\n let topBitangents;\n if (vertexFormat.normal || vertexFormat.bitangent) {\n topNormals = attributes.normal.values;\n topBitangents = attributes.bitangent.values;\n }\n const size = attributes.position.values.length / 18;\n const threeSize = size * 3;\n const twoSize = size * 2;\n const sixSize = threeSize * 2;\n let i;\n if (vertexFormat.normal || vertexFormat.bitangent || vertexFormat.tangent) {\n const normals = vertexFormat.normal\n ? new Float32Array(threeSize * 6)\n : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(threeSize * 6)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(threeSize * 6)\n : undefined;\n let topPosition = cartesian1;\n let bottomPosition = cartesian2;\n let previousPosition = cartesian3;\n let normal = cartesian4;\n let tangent = cartesian5;\n let bitangent = cartesian6;\n let attrIndex = sixSize;\n for (i = 0; i < threeSize; i += 3) {\n const attrIndexOffset = attrIndex + sixSize;\n topPosition = Cartesian3.fromArray(positions, i, topPosition);\n bottomPosition = Cartesian3.fromArray(\n positions,\n i + threeSize,\n bottomPosition\n );\n previousPosition = Cartesian3.fromArray(\n positions,\n (i + 3) % threeSize,\n previousPosition\n );\n bottomPosition = Cartesian3.subtract(\n bottomPosition,\n topPosition,\n bottomPosition\n );\n previousPosition = Cartesian3.subtract(\n previousPosition,\n topPosition,\n previousPosition\n );\n normal = Cartesian3.normalize(\n Cartesian3.cross(bottomPosition, previousPosition, normal),\n normal\n );\n if (vertexFormat.normal) {\n CorridorGeometryLibrary.addAttribute(normals, normal, attrIndexOffset);\n CorridorGeometryLibrary.addAttribute(\n normals,\n normal,\n attrIndexOffset + 3\n );\n CorridorGeometryLibrary.addAttribute(normals, normal, attrIndex);\n CorridorGeometryLibrary.addAttribute(normals, normal, attrIndex + 3);\n }\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n bitangent = Cartesian3.fromArray(topNormals, i, bitangent);\n if (vertexFormat.bitangent) {\n CorridorGeometryLibrary.addAttribute(\n bitangents,\n bitangent,\n attrIndexOffset\n );\n CorridorGeometryLibrary.addAttribute(\n bitangents,\n bitangent,\n attrIndexOffset + 3\n );\n CorridorGeometryLibrary.addAttribute(\n bitangents,\n bitangent,\n attrIndex\n );\n CorridorGeometryLibrary.addAttribute(\n bitangents,\n bitangent,\n attrIndex + 3\n );\n }\n\n if (vertexFormat.tangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(bitangent, normal, tangent),\n tangent\n );\n CorridorGeometryLibrary.addAttribute(\n tangents,\n tangent,\n attrIndexOffset\n );\n CorridorGeometryLibrary.addAttribute(\n tangents,\n tangent,\n attrIndexOffset + 3\n );\n CorridorGeometryLibrary.addAttribute(tangents, tangent, attrIndex);\n CorridorGeometryLibrary.addAttribute(\n tangents,\n tangent,\n attrIndex + 3\n );\n }\n }\n attrIndex += 6;\n }\n\n if (vertexFormat.normal) {\n normals.set(topNormals); //top\n for (i = 0; i < threeSize; i += 3) {\n //bottom normals\n normals[i + threeSize] = -topNormals[i];\n normals[i + threeSize + 1] = -topNormals[i + 1];\n normals[i + threeSize + 2] = -topNormals[i + 2];\n }\n attributes.normal.values = normals;\n } else {\n attributes.normal = undefined;\n }\n\n if (vertexFormat.bitangent) {\n bitangents.set(topBitangents); //top\n bitangents.set(topBitangents, threeSize); //bottom\n attributes.bitangent.values = bitangents;\n } else {\n attributes.bitangent = undefined;\n }\n\n if (vertexFormat.tangent) {\n const topTangents = attributes.tangent.values;\n tangents.set(topTangents); //top\n tangents.set(topTangents, threeSize); //bottom\n attributes.tangent.values = tangents;\n }\n }\n if (vertexFormat.st) {\n const topSt = attributes.st.values;\n const st = new Float32Array(twoSize * 6);\n st.set(topSt); //top\n st.set(topSt, twoSize); //bottom\n let index = twoSize * 2;\n\n for (let j = 0; j < 2; j++) {\n st[index++] = topSt[0];\n st[index++] = topSt[1];\n for (i = 2; i < twoSize; i += 2) {\n const s = topSt[i];\n const t = topSt[i + 1];\n st[index++] = s;\n st[index++] = t;\n st[index++] = s;\n st[index++] = t;\n }\n st[index++] = topSt[0];\n st[index++] = topSt[1];\n }\n attributes.st.values = st;\n }\n\n return attributes;\n}\n\nfunction addWallPositions(positions, index, wallPositions) {\n wallPositions[index++] = positions[0];\n wallPositions[index++] = positions[1];\n wallPositions[index++] = positions[2];\n for (let i = 3; i < positions.length; i += 3) {\n const x = positions[i];\n const y = positions[i + 1];\n const z = positions[i + 2];\n wallPositions[index++] = x;\n wallPositions[index++] = y;\n wallPositions[index++] = z;\n wallPositions[index++] = x;\n wallPositions[index++] = y;\n wallPositions[index++] = z;\n }\n wallPositions[index++] = positions[0];\n wallPositions[index++] = positions[1];\n wallPositions[index++] = positions[2];\n\n return wallPositions;\n}\n\nfunction computePositionsExtruded(params, vertexFormat) {\n const topVertexFormat = new VertexFormat({\n position: vertexFormat.position,\n normal:\n vertexFormat.normal || vertexFormat.bitangent || params.shadowVolume,\n tangent: vertexFormat.tangent,\n bitangent: vertexFormat.normal || vertexFormat.bitangent,\n st: vertexFormat.st,\n });\n const ellipsoid = params.ellipsoid;\n const computedPositions = CorridorGeometryLibrary.computePositions(params);\n const attr = combine(computedPositions, topVertexFormat, ellipsoid);\n const height = params.height;\n const extrudedHeight = params.extrudedHeight;\n let attributes = attr.attributes;\n const indices = attr.indices;\n let positions = attributes.position.values;\n let length = positions.length;\n const newPositions = new Float64Array(length * 6);\n let extrudedPositions = new Float64Array(length);\n extrudedPositions.set(positions);\n let wallPositions = new Float64Array(length * 4);\n\n positions = PolygonPipeline.scaleToGeodeticHeight(\n positions,\n height,\n ellipsoid\n );\n wallPositions = addWallPositions(positions, 0, wallPositions);\n extrudedPositions = PolygonPipeline.scaleToGeodeticHeight(\n extrudedPositions,\n extrudedHeight,\n ellipsoid\n );\n wallPositions = addWallPositions(\n extrudedPositions,\n length * 2,\n wallPositions\n );\n newPositions.set(positions);\n newPositions.set(extrudedPositions, length);\n newPositions.set(wallPositions, length * 2);\n attributes.position.values = newPositions;\n\n attributes = extrudedAttributes(attributes, vertexFormat);\n let i;\n const size = length / 3;\n if (params.shadowVolume) {\n const topNormals = attributes.normal.values;\n length = topNormals.length;\n\n let extrudeNormals = new Float32Array(length * 6);\n for (i = 0; i < length; i++) {\n topNormals[i] = -topNormals[i];\n }\n //only get normals for bottom layer that's going to be pushed down\n extrudeNormals.set(topNormals, length); //bottom face\n extrudeNormals = addWallPositions(topNormals, length * 4, extrudeNormals); //bottom wall\n attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: extrudeNormals,\n });\n if (!vertexFormat.normal) {\n attributes.normal = undefined;\n }\n }\n if (defined(params.offsetAttribute)) {\n let applyOffset = new Uint8Array(size * 6);\n if (params.offsetAttribute === GeometryOffsetAttribute.TOP) {\n applyOffset = applyOffset\n .fill(1, 0, size) // top face\n .fill(1, size * 2, size * 4); // top wall\n } else {\n const applyOffsetValue =\n params.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n applyOffset = applyOffset.fill(applyOffsetValue);\n }\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n const iLength = indices.length;\n const twoSize = size + size;\n const newIndices = IndexDatatype.createTypedArray(\n newPositions.length / 3,\n iLength * 2 + twoSize * 3\n );\n newIndices.set(indices);\n let index = iLength;\n for (i = 0; i < iLength; i += 3) {\n // bottom indices\n const v0 = indices[i];\n const v1 = indices[i + 1];\n const v2 = indices[i + 2];\n newIndices[index++] = v2 + size;\n newIndices[index++] = v1 + size;\n newIndices[index++] = v0 + size;\n }\n\n let UL, LL, UR, LR;\n\n for (i = 0; i < twoSize; i += 2) {\n //wall indices\n UL = i + twoSize;\n LL = UL + twoSize;\n UR = UL + 1;\n LR = LL + 1;\n newIndices[index++] = UL;\n newIndices[index++] = LL;\n newIndices[index++] = UR;\n newIndices[index++] = UR;\n newIndices[index++] = LL;\n newIndices[index++] = LR;\n }\n\n return {\n attributes: attributes,\n indices: newIndices,\n };\n}\n\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartographic = new Cartographic();\n\nfunction computeOffsetPoints(\n position1,\n position2,\n ellipsoid,\n halfWidth,\n min,\n max\n) {\n // Compute direction of offset the point\n const direction = Cartesian3.subtract(\n position2,\n position1,\n scratchCartesian1\n );\n Cartesian3.normalize(direction, direction);\n const normal = ellipsoid.geodeticSurfaceNormal(position1, scratchCartesian2);\n const offsetDirection = Cartesian3.cross(\n direction,\n normal,\n scratchCartesian1\n );\n Cartesian3.multiplyByScalar(offsetDirection, halfWidth, offsetDirection);\n\n let minLat = min.latitude;\n let minLon = min.longitude;\n let maxLat = max.latitude;\n let maxLon = max.longitude;\n\n // Compute 2 offset points\n Cartesian3.add(position1, offsetDirection, scratchCartesian2);\n ellipsoid.cartesianToCartographic(scratchCartesian2, scratchCartographic);\n\n let lat = scratchCartographic.latitude;\n let lon = scratchCartographic.longitude;\n minLat = Math.min(minLat, lat);\n minLon = Math.min(minLon, lon);\n maxLat = Math.max(maxLat, lat);\n maxLon = Math.max(maxLon, lon);\n\n Cartesian3.subtract(position1, offsetDirection, scratchCartesian2);\n ellipsoid.cartesianToCartographic(scratchCartesian2, scratchCartographic);\n\n lat = scratchCartographic.latitude;\n lon = scratchCartographic.longitude;\n minLat = Math.min(minLat, lat);\n minLon = Math.min(minLon, lon);\n maxLat = Math.max(maxLat, lat);\n maxLon = Math.max(maxLon, lon);\n\n min.latitude = minLat;\n min.longitude = minLon;\n max.latitude = maxLat;\n max.longitude = maxLon;\n}\n\nconst scratchCartesianOffset = new Cartesian3();\nconst scratchCartesianEnds = new Cartesian3();\nconst scratchCartographicMin = new Cartographic();\nconst scratchCartographicMax = new Cartographic();\n\nfunction computeRectangle(positions, ellipsoid, width, cornerType, result) {\n positions = scaleToSurface(positions, ellipsoid);\n const cleanPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n const length = cleanPositions.length;\n if (length < 2 || width <= 0) {\n return new Rectangle();\n }\n const halfWidth = width * 0.5;\n\n scratchCartographicMin.latitude = Number.POSITIVE_INFINITY;\n scratchCartographicMin.longitude = Number.POSITIVE_INFINITY;\n scratchCartographicMax.latitude = Number.NEGATIVE_INFINITY;\n scratchCartographicMax.longitude = Number.NEGATIVE_INFINITY;\n\n let lat, lon;\n if (cornerType === CornerType.ROUNDED) {\n // Compute start cap\n const first = cleanPositions[0];\n Cartesian3.subtract(first, cleanPositions[1], scratchCartesianOffset);\n Cartesian3.normalize(scratchCartesianOffset, scratchCartesianOffset);\n Cartesian3.multiplyByScalar(\n scratchCartesianOffset,\n halfWidth,\n scratchCartesianOffset\n );\n Cartesian3.add(first, scratchCartesianOffset, scratchCartesianEnds);\n\n ellipsoid.cartesianToCartographic(\n scratchCartesianEnds,\n scratchCartographic\n );\n lat = scratchCartographic.latitude;\n lon = scratchCartographic.longitude;\n scratchCartographicMin.latitude = Math.min(\n scratchCartographicMin.latitude,\n lat\n );\n scratchCartographicMin.longitude = Math.min(\n scratchCartographicMin.longitude,\n lon\n );\n scratchCartographicMax.latitude = Math.max(\n scratchCartographicMax.latitude,\n lat\n );\n scratchCartographicMax.longitude = Math.max(\n scratchCartographicMax.longitude,\n lon\n );\n }\n\n // Compute the rest\n for (let i = 0; i < length - 1; ++i) {\n computeOffsetPoints(\n cleanPositions[i],\n cleanPositions[i + 1],\n ellipsoid,\n halfWidth,\n scratchCartographicMin,\n scratchCartographicMax\n );\n }\n\n // Compute ending point\n const last = cleanPositions[length - 1];\n Cartesian3.subtract(last, cleanPositions[length - 2], scratchCartesianOffset);\n Cartesian3.normalize(scratchCartesianOffset, scratchCartesianOffset);\n Cartesian3.multiplyByScalar(\n scratchCartesianOffset,\n halfWidth,\n scratchCartesianOffset\n );\n Cartesian3.add(last, scratchCartesianOffset, scratchCartesianEnds);\n computeOffsetPoints(\n last,\n scratchCartesianEnds,\n ellipsoid,\n halfWidth,\n scratchCartographicMin,\n scratchCartographicMax\n );\n\n if (cornerType === CornerType.ROUNDED) {\n // Compute end cap\n ellipsoid.cartesianToCartographic(\n scratchCartesianEnds,\n scratchCartographic\n );\n lat = scratchCartographic.latitude;\n lon = scratchCartographic.longitude;\n scratchCartographicMin.latitude = Math.min(\n scratchCartographicMin.latitude,\n lat\n );\n scratchCartographicMin.longitude = Math.min(\n scratchCartographicMin.longitude,\n lon\n );\n scratchCartographicMax.latitude = Math.max(\n scratchCartographicMax.latitude,\n lat\n );\n scratchCartographicMax.longitude = Math.max(\n scratchCartographicMax.longitude,\n lon\n );\n }\n\n const rectangle = defined(result) ? result : new Rectangle();\n rectangle.north = scratchCartographicMax.latitude;\n rectangle.south = scratchCartographicMin.latitude;\n rectangle.east = scratchCartographicMax.longitude;\n rectangle.west = scratchCartographicMin.longitude;\n\n return rectangle;\n}\n\n/**\n * A description of a corridor. Corridor geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.\n *\n * @alias CorridorGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that define the center of the corridor.\n * @param {number} options.width The distance between the edges of the corridor in meters.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number} [options.height=0] The distance in meters between the ellipsoid surface and the positions.\n * @param {number} [options.extrudedHeight] The distance in meters between the ellipsoid surface and the extruded face.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.\n *\n * @see CorridorGeometry.createGeometry\n * @see Packable\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}\n *\n * @example\n * const corridor = new Cesium.CorridorGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,\n * positions : Cesium.Cartesian3.fromDegreesArray([-72.0, 40.0, -70.0, 35.0]),\n * width : 100000\n * });\n */\nfunction CorridorGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n const width = options.width;\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", positions);\n Check.defined(\"options.width\", width);\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._positions = positions;\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._vertexFormat = VertexFormat.clone(\n defaultValue(options.vertexFormat, VertexFormat.DEFAULT)\n );\n this._width = width;\n this._height = Math.max(height, extrudedHeight);\n this._extrudedHeight = Math.min(height, extrudedHeight);\n this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._shadowVolume = defaultValue(options.shadowVolume, false);\n this._workerName = \"createCorridorGeometry\";\n this._offsetAttribute = options.offsetAttribute;\n this._rectangle = undefined;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n 1 +\n positions.length * Cartesian3.packedLength +\n Ellipsoid.packedLength +\n VertexFormat.packedLength +\n 7;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CorridorGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCorridorGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const positions = value._positions;\n const length = positions.length;\n array[startingIndex++] = length;\n\n for (let i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._width;\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._cornerType;\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n positions: undefined,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n width: undefined,\n height: undefined,\n extrudedHeight: undefined,\n cornerType: undefined,\n granularity: undefined,\n shadowVolume: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CorridorGeometry} [result] The object into which to store the result.\n * @returns {CorridorGeometry} The modified result parameter or a new CorridorGeometry instance if one was not provided.\n */\nCorridorGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const length = array[startingIndex++];\n const positions = new Array(length);\n\n for (let i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const width = array[startingIndex++];\n const height = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const cornerType = array[startingIndex++];\n const granularity = array[startingIndex++];\n const shadowVolume = array[startingIndex++] === 1.0;\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.positions = positions;\n scratchOptions.width = width;\n scratchOptions.height = height;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.cornerType = cornerType;\n scratchOptions.granularity = granularity;\n scratchOptions.shadowVolume = shadowVolume;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return new CorridorGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._width = width;\n result._height = height;\n result._extrudedHeight = extrudedHeight;\n result._cornerType = cornerType;\n result._granularity = granularity;\n result._shadowVolume = shadowVolume;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the bounding rectangle given the provided options\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that define the center of the corridor.\n * @param {number} options.width The distance between the edges of the corridor in meters.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.\n * @param {Rectangle} [result] An object in which to store the result.\n *\n * @returns {Rectangle} The result rectangle.\n */\nCorridorGeometry.computeRectangle = function (options, result) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n const width = options.width;\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", positions);\n Check.defined(\"options.width\", width);\n //>>includeEnd('debug');\n\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);\n\n return computeRectangle(positions, ellipsoid, width, cornerType, result);\n};\n\n/**\n * Computes the geometric representation of a corridor, including its vertices, indices, and a bounding sphere.\n *\n * @param {CorridorGeometry} corridorGeometry A description of the corridor.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCorridorGeometry.createGeometry = function (corridorGeometry) {\n let positions = corridorGeometry._positions;\n const width = corridorGeometry._width;\n const ellipsoid = corridorGeometry._ellipsoid;\n\n positions = scaleToSurface(positions, ellipsoid);\n const cleanPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n\n if (cleanPositions.length < 2 || width <= 0) {\n return;\n }\n\n const height = corridorGeometry._height;\n const extrudedHeight = corridorGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n height,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n\n const vertexFormat = corridorGeometry._vertexFormat;\n const params = {\n ellipsoid: ellipsoid,\n positions: cleanPositions,\n width: width,\n cornerType: corridorGeometry._cornerType,\n granularity: corridorGeometry._granularity,\n saveAttributes: true,\n };\n let attr;\n if (extrude) {\n params.height = height;\n params.extrudedHeight = extrudedHeight;\n params.shadowVolume = corridorGeometry._shadowVolume;\n params.offsetAttribute = corridorGeometry._offsetAttribute;\n attr = computePositionsExtruded(params, vertexFormat);\n } else {\n const computedPositions = CorridorGeometryLibrary.computePositions(params);\n attr = combine(computedPositions, vertexFormat, ellipsoid);\n attr.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n attr.attributes.position.values,\n height,\n ellipsoid\n );\n\n if (defined(corridorGeometry._offsetAttribute)) {\n const applyOffsetValue =\n corridorGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const length = attr.attributes.position.values.length;\n const applyOffset = new Uint8Array(length / 3).fill(applyOffsetValue);\n attr.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n }\n const attributes = attr.attributes;\n const boundingSphere = BoundingSphere.fromVertices(\n attributes.position.values,\n undefined,\n 3\n );\n if (!vertexFormat.position) {\n attr.attributes.position.values = undefined;\n }\n\n return new Geometry({\n attributes: attributes,\n indices: attr.indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: boundingSphere,\n offsetAttribute: corridorGeometry._offsetAttribute,\n });\n};\n\n/**\n * @private\n */\nCorridorGeometry.createShadowVolume = function (\n corridorGeometry,\n minHeightFunc,\n maxHeightFunc\n) {\n const granularity = corridorGeometry._granularity;\n const ellipsoid = corridorGeometry._ellipsoid;\n\n const minHeight = minHeightFunc(granularity, ellipsoid);\n const maxHeight = maxHeightFunc(granularity, ellipsoid);\n\n return new CorridorGeometry({\n positions: corridorGeometry._positions,\n width: corridorGeometry._width,\n cornerType: corridorGeometry._cornerType,\n ellipsoid: ellipsoid,\n granularity: granularity,\n extrudedHeight: minHeight,\n height: maxHeight,\n vertexFormat: VertexFormat.POSITION_ONLY,\n shadowVolume: true,\n });\n};\n\nObject.defineProperties(CorridorGeometry.prototype, {\n /**\n * @private\n */\n rectangle: {\n get: function () {\n if (!defined(this._rectangle)) {\n this._rectangle = computeRectangle(\n this._positions,\n this._ellipsoid,\n this._width,\n this._cornerType\n );\n }\n return this._rectangle;\n },\n },\n /**\n * For remapping texture coordinates when rendering CorridorGeometries as GroundPrimitives.\n *\n * Corridors don't support stRotation,\n * so just return the corners of the original system.\n * @private\n */\n textureCoordinateRotationPoints: {\n get: function () {\n return [0, 0, 0, 1, 1, 0];\n },\n },\n});\nexport default CorridorGeometry;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CornerType from \"./CornerType.js\";\nimport CorridorGeometryLibrary from \"./CorridorGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nconst cartesian1 = new Cartesian3();\nconst cartesian2 = new Cartesian3();\nconst cartesian3 = new Cartesian3();\n\nfunction scaleToSurface(positions, ellipsoid) {\n for (let i = 0; i < positions.length; i++) {\n positions[i] = ellipsoid.scaleToGeodeticSurface(positions[i], positions[i]);\n }\n return positions;\n}\n\nfunction combine(computedPositions, cornerType) {\n const wallIndices = [];\n const positions = computedPositions.positions;\n const corners = computedPositions.corners;\n const endPositions = computedPositions.endPositions;\n const attributes = new GeometryAttributes();\n let corner;\n let leftCount = 0;\n let rightCount = 0;\n let i;\n let indicesLength = 0;\n let length;\n for (i = 0; i < positions.length; i += 2) {\n length = positions[i].length - 3;\n leftCount += length; //subtracting 3 to account for duplicate points at corners\n indicesLength += (length / 3) * 4;\n rightCount += positions[i + 1].length - 3;\n }\n leftCount += 3; //add back count for end positions\n rightCount += 3;\n for (i = 0; i < corners.length; i++) {\n corner = corners[i];\n const leftSide = corners[i].leftPositions;\n if (defined(leftSide)) {\n length = leftSide.length;\n leftCount += length;\n indicesLength += (length / 3) * 2;\n } else {\n length = corners[i].rightPositions.length;\n rightCount += length;\n indicesLength += (length / 3) * 2;\n }\n }\n\n const addEndPositions = defined(endPositions);\n let endPositionLength;\n if (addEndPositions) {\n endPositionLength = endPositions[0].length - 3;\n leftCount += endPositionLength;\n rightCount += endPositionLength;\n endPositionLength /= 3;\n indicesLength += endPositionLength * 4;\n }\n const size = leftCount + rightCount;\n const finalPositions = new Float64Array(size);\n let front = 0;\n let back = size - 1;\n let UL, LL, UR, LR;\n let rightPos, leftPos;\n const halfLength = endPositionLength / 2;\n\n const indices = IndexDatatype.createTypedArray(size / 3, indicesLength + 4);\n let index = 0;\n\n indices[index++] = front / 3;\n indices[index++] = (back - 2) / 3;\n if (addEndPositions) {\n // add rounded end\n wallIndices.push(front / 3);\n leftPos = cartesian1;\n rightPos = cartesian2;\n const firstEndPositions = endPositions[0];\n for (i = 0; i < halfLength; i++) {\n leftPos = Cartesian3.fromArray(\n firstEndPositions,\n (halfLength - 1 - i) * 3,\n leftPos\n );\n rightPos = Cartesian3.fromArray(\n firstEndPositions,\n (halfLength + i) * 3,\n rightPos\n );\n CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front);\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n leftPos,\n undefined,\n back\n );\n\n LL = front / 3;\n LR = LL + 1;\n UL = (back - 2) / 3;\n UR = UL - 1;\n indices[index++] = UL;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n }\n\n let posIndex = 0;\n let rightEdge = positions[posIndex++]; //add first two edges\n let leftEdge = positions[posIndex++];\n finalPositions.set(rightEdge, front);\n finalPositions.set(leftEdge, back - leftEdge.length + 1);\n\n length = leftEdge.length - 3;\n wallIndices.push(front / 3, (back - 2) / 3);\n for (i = 0; i < length; i += 3) {\n LL = front / 3;\n LR = LL + 1;\n UL = (back - 2) / 3;\n UR = UL - 1;\n indices[index++] = UL;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n\n for (i = 0; i < corners.length; i++) {\n let j;\n corner = corners[i];\n const l = corner.leftPositions;\n const r = corner.rightPositions;\n let start;\n let outsidePoint = cartesian3;\n if (defined(l)) {\n back -= 3;\n start = UR;\n wallIndices.push(LR);\n for (j = 0; j < l.length / 3; j++) {\n outsidePoint = Cartesian3.fromArray(l, j * 3, outsidePoint);\n indices[index++] = start - j - 1;\n indices[index++] = start - j;\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n outsidePoint,\n undefined,\n back\n );\n back -= 3;\n }\n wallIndices.push(start - Math.floor(l.length / 6));\n if (cornerType === CornerType.BEVELED) {\n wallIndices.push((back - 2) / 3 + 1);\n }\n front += 3;\n } else {\n front += 3;\n start = LR;\n wallIndices.push(UR);\n for (j = 0; j < r.length / 3; j++) {\n outsidePoint = Cartesian3.fromArray(r, j * 3, outsidePoint);\n indices[index++] = start + j;\n indices[index++] = start + j + 1;\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n outsidePoint,\n front\n );\n front += 3;\n }\n wallIndices.push(start + Math.floor(r.length / 6));\n if (cornerType === CornerType.BEVELED) {\n wallIndices.push(front / 3 - 1);\n }\n back -= 3;\n }\n rightEdge = positions[posIndex++];\n leftEdge = positions[posIndex++];\n rightEdge.splice(0, 3); //remove duplicate points added by corner\n leftEdge.splice(leftEdge.length - 3, 3);\n finalPositions.set(rightEdge, front);\n finalPositions.set(leftEdge, back - leftEdge.length + 1);\n length = leftEdge.length - 3;\n\n for (j = 0; j < leftEdge.length; j += 3) {\n LR = front / 3;\n LL = LR - 1;\n UR = (back - 2) / 3;\n UL = UR + 1;\n indices[index++] = UL;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n front += 3;\n back -= 3;\n }\n front -= 3;\n back += 3;\n wallIndices.push(front / 3, (back - 2) / 3);\n }\n\n if (addEndPositions) {\n // add rounded end\n front += 3;\n back -= 3;\n leftPos = cartesian1;\n rightPos = cartesian2;\n const lastEndPositions = endPositions[1];\n for (i = 0; i < halfLength; i++) {\n leftPos = Cartesian3.fromArray(\n lastEndPositions,\n (endPositionLength - i - 1) * 3,\n leftPos\n );\n rightPos = Cartesian3.fromArray(lastEndPositions, i * 3, rightPos);\n CorridorGeometryLibrary.addAttribute(\n finalPositions,\n leftPos,\n undefined,\n back\n );\n CorridorGeometryLibrary.addAttribute(finalPositions, rightPos, front);\n\n LR = front / 3;\n LL = LR - 1;\n UR = (back - 2) / 3;\n UL = UR + 1;\n indices[index++] = UL;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n\n front += 3;\n back -= 3;\n }\n\n wallIndices.push(front / 3);\n } else {\n wallIndices.push(front / 3, (back - 2) / 3);\n }\n indices[index++] = front / 3;\n indices[index++] = (back - 2) / 3;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: finalPositions,\n });\n\n return {\n attributes: attributes,\n indices: indices,\n wallIndices: wallIndices,\n };\n}\n\nfunction computePositionsExtruded(params) {\n const ellipsoid = params.ellipsoid;\n const computedPositions = CorridorGeometryLibrary.computePositions(params);\n const attr = combine(computedPositions, params.cornerType);\n const wallIndices = attr.wallIndices;\n const height = params.height;\n const extrudedHeight = params.extrudedHeight;\n const attributes = attr.attributes;\n const indices = attr.indices;\n let positions = attributes.position.values;\n let length = positions.length;\n let extrudedPositions = new Float64Array(length);\n extrudedPositions.set(positions);\n const newPositions = new Float64Array(length * 2);\n\n positions = PolygonPipeline.scaleToGeodeticHeight(\n positions,\n height,\n ellipsoid\n );\n extrudedPositions = PolygonPipeline.scaleToGeodeticHeight(\n extrudedPositions,\n extrudedHeight,\n ellipsoid\n );\n newPositions.set(positions);\n newPositions.set(extrudedPositions, length);\n attributes.position.values = newPositions;\n\n length /= 3;\n if (defined(params.offsetAttribute)) {\n let applyOffset = new Uint8Array(length * 2);\n if (params.offsetAttribute === GeometryOffsetAttribute.TOP) {\n applyOffset = applyOffset.fill(1, 0, length);\n } else {\n const applyOffsetValue =\n params.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n applyOffset = applyOffset.fill(applyOffsetValue);\n }\n\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n let i;\n const iLength = indices.length;\n const newIndices = IndexDatatype.createTypedArray(\n newPositions.length / 3,\n (iLength + wallIndices.length) * 2\n );\n newIndices.set(indices);\n let index = iLength;\n for (i = 0; i < iLength; i += 2) {\n // bottom indices\n const v0 = indices[i];\n const v1 = indices[i + 1];\n newIndices[index++] = v0 + length;\n newIndices[index++] = v1 + length;\n }\n\n let UL, LL;\n for (i = 0; i < wallIndices.length; i++) {\n //wall indices\n UL = wallIndices[i];\n LL = UL + length;\n newIndices[index++] = UL;\n newIndices[index++] = LL;\n }\n\n return {\n attributes: attributes,\n indices: newIndices,\n };\n}\n\n/**\n * A description of a corridor outline.\n *\n * @alias CorridorOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that define the center of the corridor outline.\n * @param {number} options.width The distance between the edges of the corridor outline.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number} [options.height=0] The distance in meters between the positions and the ellipsoid surface.\n * @param {number} [options.extrudedHeight] The distance in meters between the extruded face and the ellipsoid surface.\n * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.\n *\n * @see CorridorOutlineGeometry.createGeometry\n *\n * @example\n * const corridor = new Cesium.CorridorOutlineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([-72.0, 40.0, -70.0, 35.0]),\n * width : 100000\n * });\n */\nfunction CorridorOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n const width = options.width;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options.positions\", positions);\n Check.typeOf.number(\"options.width\", width);\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._positions = positions;\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._width = width;\n this._height = Math.max(height, extrudedHeight);\n this._extrudedHeight = Math.min(height, extrudedHeight);\n this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createCorridorOutlineGeometry\";\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + 6;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CorridorOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCorridorOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.typeOf.object(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const positions = value._positions;\n const length = positions.length;\n array[startingIndex++] = length;\n\n for (let i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex++] = value._width;\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._cornerType;\n array[startingIndex++] = value._granularity;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchOptions = {\n positions: undefined,\n ellipsoid: scratchEllipsoid,\n width: undefined,\n height: undefined,\n extrudedHeight: undefined,\n cornerType: undefined,\n granularity: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CorridorOutlineGeometry} [result] The object into which to store the result.\n * @returns {CorridorOutlineGeometry} The modified result parameter or a new CorridorOutlineGeometry instance if one was not provided.\n */\nCorridorOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const length = array[startingIndex++];\n const positions = new Array(length);\n\n for (let i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const width = array[startingIndex++];\n const height = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const cornerType = array[startingIndex++];\n const granularity = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.positions = positions;\n scratchOptions.width = width;\n scratchOptions.height = height;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.cornerType = cornerType;\n scratchOptions.granularity = granularity;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new CorridorOutlineGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._width = width;\n result._height = height;\n result._extrudedHeight = extrudedHeight;\n result._cornerType = cornerType;\n result._granularity = granularity;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of a corridor, including its vertices, indices, and a bounding sphere.\n *\n * @param {CorridorOutlineGeometry} corridorOutlineGeometry A description of the corridor.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCorridorOutlineGeometry.createGeometry = function (corridorOutlineGeometry) {\n let positions = corridorOutlineGeometry._positions;\n const width = corridorOutlineGeometry._width;\n const ellipsoid = corridorOutlineGeometry._ellipsoid;\n\n positions = scaleToSurface(positions, ellipsoid);\n const cleanPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n\n if (cleanPositions.length < 2 || width <= 0) {\n return;\n }\n\n const height = corridorOutlineGeometry._height;\n const extrudedHeight = corridorOutlineGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n height,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n\n const params = {\n ellipsoid: ellipsoid,\n positions: cleanPositions,\n width: width,\n cornerType: corridorOutlineGeometry._cornerType,\n granularity: corridorOutlineGeometry._granularity,\n saveAttributes: false,\n };\n let attr;\n if (extrude) {\n params.height = height;\n params.extrudedHeight = extrudedHeight;\n params.offsetAttribute = corridorOutlineGeometry._offsetAttribute;\n attr = computePositionsExtruded(params);\n } else {\n const computedPositions = CorridorGeometryLibrary.computePositions(params);\n attr = combine(computedPositions, params.cornerType);\n attr.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n attr.attributes.position.values,\n height,\n ellipsoid\n );\n\n if (defined(corridorOutlineGeometry._offsetAttribute)) {\n const length = attr.attributes.position.values.length;\n const offsetValue =\n corridorOutlineGeometry._offsetAttribute ===\n GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attr.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n }\n const attributes = attr.attributes;\n const boundingSphere = BoundingSphere.fromVertices(\n attributes.position.values,\n undefined,\n 3\n );\n\n return new Geometry({\n attributes: attributes,\n indices: attr.indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: boundingSphere,\n offsetAttribute: corridorOutlineGeometry._offsetAttribute,\n });\n};\nexport default CorridorOutlineGeometry;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport GeometryOffsetAttribute from \"../Core/GeometryOffsetAttribute.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport CallbackProperty from \"./CallbackProperty.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport TerrainOffsetProperty from \"./TerrainOffsetProperty.js\";\n\nconst defaultZIndex = new ConstantProperty(0);\n\n/**\n * An abstract class for updating ground geometry entities.\n * @constructor\n * @alias GroundGeometryUpdater\n * @param {object} options An object with the following properties:\n * @param {Entity} options.entity The entity containing the geometry to be visualized.\n * @param {Scene} options.scene The scene where visualization is taking place.\n * @param {object} options.geometryOptions Options for the geometry\n * @param {string} options.geometryPropertyName The geometry property name\n * @param {string[]} options.observedPropertyNames The entity properties this geometry cares about\n */\nfunction GroundGeometryUpdater(options) {\n GeometryUpdater.call(this, options);\n\n this._zIndex = 0;\n this._terrainOffsetProperty = undefined;\n}\n\nif (defined(Object.create)) {\n GroundGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n GroundGeometryUpdater.prototype.constructor = GroundGeometryUpdater;\n}\n\nObject.defineProperties(GroundGeometryUpdater.prototype, {\n /**\n * Gets the zindex\n * @type {number}\n * @memberof GroundGeometryUpdater.prototype\n * @readonly\n */\n zIndex: {\n get: function () {\n return this._zIndex;\n },\n },\n\n /**\n * Gets the terrain offset property\n * @type {TerrainOffsetProperty}\n * @memberof GroundGeometryUpdater.prototype\n * @readonly\n * @private\n */\n terrainOffsetProperty: {\n get: function () {\n return this._terrainOffsetProperty;\n },\n },\n});\n\nGroundGeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {\n return (\n this._fillEnabled &&\n !defined(geometry.height) &&\n !defined(geometry.extrudedHeight) &&\n GroundPrimitive.isSupported(this._scene)\n );\n};\n\nGroundGeometryUpdater.prototype._getIsClosed = function (options) {\n const height = options.height;\n const extrudedHeight = options.extrudedHeight;\n return height === 0 || (defined(extrudedHeight) && extrudedHeight !== height);\n};\n\nGroundGeometryUpdater.prototype._computeCenter =\n DeveloperError.throwInstantiationError;\n\nGroundGeometryUpdater.prototype._onEntityPropertyChanged = function (\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n GeometryUpdater.prototype._onEntityPropertyChanged.call(\n this,\n entity,\n propertyName,\n newValue,\n oldValue\n );\n if (this._observedPropertyNames.indexOf(propertyName) === -1) {\n return;\n }\n\n const geometry = this._entity[this._geometryPropertyName];\n if (!defined(geometry)) {\n return;\n }\n if (\n defined(geometry.zIndex) &&\n (defined(geometry.height) || defined(geometry.extrudedHeight))\n ) {\n oneTimeWarning(oneTimeWarning.geometryZIndex);\n }\n\n this._zIndex = defaultValue(geometry.zIndex, defaultZIndex);\n\n if (defined(this._terrainOffsetProperty)) {\n this._terrainOffsetProperty.destroy();\n this._terrainOffsetProperty = undefined;\n }\n\n const heightReferenceProperty = geometry.heightReference;\n const extrudedHeightReferenceProperty = geometry.extrudedHeightReference;\n\n if (\n defined(heightReferenceProperty) ||\n defined(extrudedHeightReferenceProperty)\n ) {\n const centerPosition = new CallbackProperty(\n this._computeCenter.bind(this),\n !this._dynamic\n );\n this._terrainOffsetProperty = new TerrainOffsetProperty(\n this._scene,\n centerPosition,\n heightReferenceProperty,\n extrudedHeightReferenceProperty\n );\n }\n};\n\n/**\n * Destroys and resources used by the object. Once an object is destroyed, it should not be used.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nGroundGeometryUpdater.prototype.destroy = function () {\n if (defined(this._terrainOffsetProperty)) {\n this._terrainOffsetProperty.destroy();\n this._terrainOffsetProperty = undefined;\n }\n\n GeometryUpdater.prototype.destroy.call(this);\n};\n\n/**\n * @private\n */\nGroundGeometryUpdater.getGeometryHeight = function (height, heightReference) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"heightReference\", heightReference);\n //>>includeEnd('debug');\n if (!defined(height)) {\n if (heightReference !== HeightReference.NONE) {\n oneTimeWarning(oneTimeWarning.geometryHeightReference);\n }\n return;\n }\n\n if (heightReference !== HeightReference.CLAMP_TO_GROUND) {\n return height;\n }\n return 0.0;\n};\n\n/**\n * @private\n */\nGroundGeometryUpdater.getGeometryExtrudedHeight = function (\n extrudedHeight,\n extrudedHeightReference\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"extrudedHeightReference\", extrudedHeightReference);\n //>>includeEnd('debug');\n if (!defined(extrudedHeight)) {\n if (extrudedHeightReference !== HeightReference.NONE) {\n oneTimeWarning(oneTimeWarning.geometryExtrudedHeightReference);\n }\n return;\n }\n if (extrudedHeightReference !== HeightReference.CLAMP_TO_GROUND) {\n return extrudedHeight;\n }\n\n return GroundGeometryUpdater.CLAMP_TO_GROUND;\n};\n\n/**\n * @private\n */\nGroundGeometryUpdater.CLAMP_TO_GROUND = \"clamp\";\n\n/**\n * @private\n */\nGroundGeometryUpdater.computeGeometryOffsetAttribute = function (\n height,\n heightReference,\n extrudedHeight,\n extrudedHeightReference\n) {\n if (!defined(height) || !defined(heightReference)) {\n heightReference = HeightReference.NONE;\n }\n if (!defined(extrudedHeight) || !defined(extrudedHeightReference)) {\n extrudedHeightReference = HeightReference.NONE;\n }\n let n = 0;\n if (heightReference !== HeightReference.NONE) {\n n++;\n }\n if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) {\n n++;\n }\n if (n === 2) {\n return GeometryOffsetAttribute.ALL;\n }\n if (n === 1) {\n return GeometryOffsetAttribute.TOP;\n }\n\n return undefined;\n};\nexport default GroundGeometryUpdater;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport CorridorGeometry from \"../Core/CorridorGeometry.js\";\nimport CorridorOutlineGeometry from \"../Core/CorridorOutlineGeometry.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport GroundGeometryUpdater from \"./GroundGeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\nconst scratchRectangle = new Rectangle();\n\nfunction CorridorGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.positions = undefined;\n this.width = undefined;\n this.cornerType = undefined;\n this.height = undefined;\n this.extrudedHeight = undefined;\n this.granularity = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for corridors.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias CorridorGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction CorridorGeometryUpdater(entity, scene) {\n GroundGeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new CorridorGeometryOptions(entity),\n geometryPropertyName: \"corridor\",\n observedPropertyNames: [\"availability\", \"corridor\"],\n });\n\n this._onEntityPropertyChanged(entity, \"corridor\", entity.corridor, undefined);\n}\n\nif (defined(Object.create)) {\n CorridorGeometryUpdater.prototype = Object.create(\n GroundGeometryUpdater.prototype\n );\n CorridorGeometryUpdater.prototype.constructor = CorridorGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nCorridorGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n ),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n this._distanceDisplayConditionProperty.getValue(time)\n ),\n offset: undefined,\n color: undefined,\n };\n\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new CorridorGeometry(this._options),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nCorridorGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n this._distanceDisplayConditionProperty.getValue(time)\n ),\n offset: undefined,\n };\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new CorridorOutlineGeometry(this._options),\n attributes: attributes,\n });\n};\n\nCorridorGeometryUpdater.prototype._computeCenter = function (time, result) {\n const positions = Property.getValueOrUndefined(\n this._entity.corridor.positions,\n time\n );\n if (!defined(positions) || positions.length === 0) {\n return;\n }\n return Cartesian3.clone(\n positions[Math.floor(positions.length / 2.0)],\n result\n );\n};\n\nCorridorGeometryUpdater.prototype._isHidden = function (entity, corridor) {\n return (\n !defined(corridor.positions) ||\n !defined(corridor.width) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, corridor)\n );\n};\n\nCorridorGeometryUpdater.prototype._isDynamic = function (entity, corridor) {\n return (\n !corridor.positions.isConstant || //\n !Property.isConstant(corridor.height) || //\n !Property.isConstant(corridor.extrudedHeight) || //\n !Property.isConstant(corridor.granularity) || //\n !Property.isConstant(corridor.width) || //\n !Property.isConstant(corridor.outlineWidth) || //\n !Property.isConstant(corridor.cornerType) || //\n !Property.isConstant(corridor.zIndex) || //\n (this._onTerrain &&\n !Property.isConstant(this._materialProperty) &&\n !(this._materialProperty instanceof ColorMaterialProperty))\n );\n};\n\nCorridorGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n corridor\n) {\n let heightValue = Property.getValueOrUndefined(\n corridor.height,\n Iso8601.MINIMUM_VALUE\n );\n const heightReferenceValue = Property.getValueOrDefault(\n corridor.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n corridor.extrudedHeight,\n Iso8601.MINIMUM_VALUE\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n corridor.extrudedHeightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n const options = this._options;\n options.vertexFormat =\n this._materialProperty instanceof ColorMaterialProperty\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.positions = corridor.positions.getValue(\n Iso8601.MINIMUM_VALUE,\n options.positions\n );\n options.width = corridor.width.getValue(Iso8601.MINIMUM_VALUE);\n options.granularity = Property.getValueOrUndefined(\n corridor.granularity,\n Iso8601.MINIMUM_VALUE\n );\n options.cornerType = Property.getValueOrUndefined(\n corridor.cornerType,\n Iso8601.MINIMUM_VALUE\n );\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n CorridorGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\n\nCorridorGeometryUpdater.DynamicGeometryUpdater = DynamicCorridorGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicCorridorGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicCorridorGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicCorridorGeometryUpdater.prototype.constructor = DynamicCorridorGeometryUpdater;\n}\n\nDynamicCorridorGeometryUpdater.prototype._isHidden = function (\n entity,\n corridor,\n time\n) {\n const options = this._options;\n return (\n !defined(options.positions) ||\n !defined(options.width) ||\n DynamicGeometryUpdater.prototype._isHidden.call(\n this,\n entity,\n corridor,\n time\n )\n );\n};\n\nDynamicCorridorGeometryUpdater.prototype._setOptions = function (\n entity,\n corridor,\n time\n) {\n const options = this._options;\n let heightValue = Property.getValueOrUndefined(corridor.height, time);\n const heightReferenceValue = Property.getValueOrDefault(\n corridor.heightReference,\n time,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n corridor.extrudedHeight,\n time\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n corridor.extrudedHeightReference,\n time,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n options.positions = Property.getValueOrUndefined(corridor.positions, time);\n options.width = Property.getValueOrUndefined(corridor.width, time);\n options.granularity = Property.getValueOrUndefined(\n corridor.granularity,\n time\n );\n options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time);\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n CorridorGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\nexport default CorridorGeometryUpdater;\n", "import DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * Defines the interface for data sources, which turn arbitrary data into a\n * {@link EntityCollection} for generic consumption. This object is an interface\n * for documentation purposes and is not intended to be instantiated directly.\n * @alias DataSource\n * @constructor\n *\n * @see Entity\n * @see DataSourceDisplay\n */\nfunction DataSource() {\n DeveloperError.throwInstantiationError();\n}\n\nObject.defineProperties(DataSource.prototype, {\n /**\n * Gets a human-readable name for this instance.\n * @memberof DataSource.prototype\n * @type {string}\n */\n name: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the preferred clock settings for this data source.\n * @memberof DataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof DataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets a value indicating if the data source is currently loading data.\n * @memberof DataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof DataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof DataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets an event that will be raised when the value of isLoading changes.\n * @memberof DataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: DeveloperError.throwInstantiationError,\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof DataSource.prototype\n * @type {boolean}\n */\n show: {\n get: DeveloperError.throwInstantiationError,\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof DataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: DeveloperError.throwInstantiationError,\n },\n});\n\n/**\n * Updates the data source to the provided time. This function is optional and\n * is not required to be implemented. It is provided for data sources which\n * retrieve data based on the current animation time or scene state.\n * If implemented, update will be called by {@link DataSourceDisplay} once a frame.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nDataSource.prototype.update = function (time) {\n DeveloperError.throwInstantiationError();\n};\n\n/**\n * @private\n */\nDataSource.setLoading = function (dataSource, isLoading) {\n if (dataSource._isLoading !== isLoading) {\n if (isLoading) {\n dataSource._entityCollection.suspendEvents();\n } else {\n dataSource._entityCollection.resumeEvents();\n }\n dataSource._isLoading = isLoading;\n dataSource._loading.raiseEvent(dataSource, isLoading);\n }\n};\nexport default DataSource;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Rectangle from \"./Rectangle.js\";\n\n/**\n * Determine whether or not other objects are visible or hidden behind the visible horizon defined by\n * an {@link Ellipsoid} and a camera position. The ellipsoid is assumed to be located at the\n * origin of the coordinate system. This class uses the algorithm described in the\n * {@link https://cesium.com/blog/2013/04/25/Horizon-culling/|Horizon Culling} blog post.\n *\n * @alias EllipsoidalOccluder\n *\n * @param {Ellipsoid} ellipsoid The ellipsoid to use as an occluder.\n * @param {Cartesian3} [cameraPosition] The coordinate of the viewer/camera. If this parameter is not\n * specified, {@link EllipsoidalOccluder#cameraPosition} must be called before\n * testing visibility.\n *\n * @constructor\n *\n * @example\n * // Construct an ellipsoidal occluder with radii 1.0, 1.1, and 0.9.\n * const cameraPosition = new Cesium.Cartesian3(5.0, 6.0, 7.0);\n * const occluderEllipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\n * const occluder = new Cesium.EllipsoidalOccluder(occluderEllipsoid, cameraPosition);\n *\n * @private\n */\nfunction EllipsoidalOccluder(ellipsoid, cameraPosition) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"ellipsoid\", ellipsoid);\n //>>includeEnd('debug');\n\n this._ellipsoid = ellipsoid;\n this._cameraPosition = new Cartesian3();\n this._cameraPositionInScaledSpace = new Cartesian3();\n this._distanceToLimbInScaledSpaceSquared = 0.0;\n\n // cameraPosition fills in the above values\n if (defined(cameraPosition)) {\n this.cameraPosition = cameraPosition;\n }\n}\n\nObject.defineProperties(EllipsoidalOccluder.prototype, {\n /**\n * Gets the occluding ellipsoid.\n * @memberof EllipsoidalOccluder.prototype\n * @type {Ellipsoid}\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n },\n /**\n * Gets or sets the position of the camera.\n * @memberof EllipsoidalOccluder.prototype\n * @type {Cartesian3}\n */\n cameraPosition: {\n get: function () {\n return this._cameraPosition;\n },\n set: function (cameraPosition) {\n // See https://cesium.com/blog/2013/04/25/Horizon-culling/\n const ellipsoid = this._ellipsoid;\n const cv = ellipsoid.transformPositionToScaledSpace(\n cameraPosition,\n this._cameraPositionInScaledSpace\n );\n const vhMagnitudeSquared = Cartesian3.magnitudeSquared(cv) - 1.0;\n\n Cartesian3.clone(cameraPosition, this._cameraPosition);\n this._cameraPositionInScaledSpace = cv;\n this._distanceToLimbInScaledSpaceSquared = vhMagnitudeSquared;\n },\n },\n});\n\nconst scratchCartesian = new Cartesian3();\n\n/**\n * Determines whether or not a point, the occludee, is hidden from view by the occluder.\n *\n * @param {Cartesian3} occludee The point to test for visibility.\n * @returns {boolean} true if the occludee is visible; otherwise false.\n *\n * @example\n * const cameraPosition = new Cesium.Cartesian3(0, 0, 2.5);\n * const ellipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\n * const occluder = new Cesium.EllipsoidalOccluder(ellipsoid, cameraPosition);\n * const point = new Cesium.Cartesian3(0, -3, -3);\n * occluder.isPointVisible(point); //returns true\n */\nEllipsoidalOccluder.prototype.isPointVisible = function (occludee) {\n const ellipsoid = this._ellipsoid;\n const occludeeScaledSpacePosition = ellipsoid.transformPositionToScaledSpace(\n occludee,\n scratchCartesian\n );\n return isScaledSpacePointVisible(\n occludeeScaledSpacePosition,\n this._cameraPositionInScaledSpace,\n this._distanceToLimbInScaledSpaceSquared\n );\n};\n\n/**\n * Determines whether or not a point expressed in the ellipsoid scaled space, is hidden from view by the\n * occluder. To transform a Cartesian X, Y, Z position in the coordinate system aligned with the ellipsoid\n * into the scaled space, call {@link Ellipsoid#transformPositionToScaledSpace}.\n *\n * @param {Cartesian3} occludeeScaledSpacePosition The point to test for visibility, represented in the scaled space.\n * @returns {boolean} true if the occludee is visible; otherwise false.\n *\n * @example\n * const cameraPosition = new Cesium.Cartesian3(0, 0, 2.5);\n * const ellipsoid = new Cesium.Ellipsoid(1.0, 1.1, 0.9);\n * const occluder = new Cesium.EllipsoidalOccluder(ellipsoid, cameraPosition);\n * const point = new Cesium.Cartesian3(0, -3, -3);\n * const scaledSpacePoint = ellipsoid.transformPositionToScaledSpace(point);\n * occluder.isScaledSpacePointVisible(scaledSpacePoint); //returns true\n */\nEllipsoidalOccluder.prototype.isScaledSpacePointVisible = function (\n occludeeScaledSpacePosition\n) {\n return isScaledSpacePointVisible(\n occludeeScaledSpacePosition,\n this._cameraPositionInScaledSpace,\n this._distanceToLimbInScaledSpaceSquared\n );\n};\n\nconst scratchCameraPositionInScaledSpaceShrunk = new Cartesian3();\n\n/**\n * Similar to {@link EllipsoidalOccluder#isScaledSpacePointVisible} except tests against an\n * ellipsoid that has been shrunk by the minimum height when the minimum height is below\n * the ellipsoid. This is intended to be used with points generated by\n * {@link EllipsoidalOccluder#computeHorizonCullingPointPossiblyUnderEllipsoid} or\n * {@link EllipsoidalOccluder#computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid}.\n *\n * @param {Cartesian3} occludeeScaledSpacePosition The point to test for visibility, represented in the scaled space of the possibly-shrunk ellipsoid.\n * @returns {boolean} true if the occludee is visible; otherwise false.\n */\nEllipsoidalOccluder.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid = function (\n occludeeScaledSpacePosition,\n minimumHeight\n) {\n const ellipsoid = this._ellipsoid;\n let vhMagnitudeSquared;\n let cv;\n\n if (\n defined(minimumHeight) &&\n minimumHeight < 0.0 &&\n ellipsoid.minimumRadius > -minimumHeight\n ) {\n // This code is similar to the cameraPosition setter, but unrolled for performance because it will be called a lot.\n cv = scratchCameraPositionInScaledSpaceShrunk;\n cv.x = this._cameraPosition.x / (ellipsoid.radii.x + minimumHeight);\n cv.y = this._cameraPosition.y / (ellipsoid.radii.y + minimumHeight);\n cv.z = this._cameraPosition.z / (ellipsoid.radii.z + minimumHeight);\n vhMagnitudeSquared = cv.x * cv.x + cv.y * cv.y + cv.z * cv.z - 1.0;\n } else {\n cv = this._cameraPositionInScaledSpace;\n vhMagnitudeSquared = this._distanceToLimbInScaledSpaceSquared;\n }\n\n return isScaledSpacePointVisible(\n occludeeScaledSpacePosition,\n cv,\n vhMagnitudeSquared\n );\n};\n\n/**\n * Computes a point that can be used for horizon culling from a list of positions. If the point is below\n * the horizon, all of the positions are guaranteed to be below the horizon as well. The returned point\n * is expressed in the ellipsoid-scaled space and is suitable for use with\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\n *\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\n * A reasonable direction to use is the direction from the center of the ellipsoid to\n * the center of the bounding sphere computed from the positions. The direction need not\n * be normalized.\n * @param {Cartesian3[]} positions The positions from which to compute the horizon culling point. The positions\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\n * ellipsoid's axes.\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\n */\nEllipsoidalOccluder.prototype.computeHorizonCullingPoint = function (\n directionToPoint,\n positions,\n result\n) {\n return computeHorizonCullingPointFromPositions(\n this._ellipsoid,\n directionToPoint,\n positions,\n result\n );\n};\n\nconst scratchEllipsoidShrunk = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\n\n/**\n * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPoint} except computes the culling\n * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below\n * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable\n * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.\n *\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\n * A reasonable direction to use is the direction from the center of the ellipsoid to\n * the center of the bounding sphere computed from the positions. The direction need not\n * be normalized.\n * @param {Cartesian3[]} positions The positions from which to compute the horizon culling point. The positions\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\n * ellipsoid's axes.\n * @param {number} [minimumHeight] The minimum height of all positions. If this value is undefined, all positions are assumed to be above the ellipsoid.\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\n * @returns {Cartesian3} The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.\n */\nEllipsoidalOccluder.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid = function (\n directionToPoint,\n positions,\n minimumHeight,\n result\n) {\n const possiblyShrunkEllipsoid = getPossiblyShrunkEllipsoid(\n this._ellipsoid,\n minimumHeight,\n scratchEllipsoidShrunk\n );\n return computeHorizonCullingPointFromPositions(\n possiblyShrunkEllipsoid,\n directionToPoint,\n positions,\n result\n );\n};\n/**\n * Computes a point that can be used for horizon culling from a list of positions. If the point is below\n * the horizon, all of the positions are guaranteed to be below the horizon as well. The returned point\n * is expressed in the ellipsoid-scaled space and is suitable for use with\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\n *\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\n * A reasonable direction to use is the direction from the center of the ellipsoid to\n * the center of the bounding sphere computed from the positions. The direction need not\n * be normalized.\n * @param {number[]} vertices The vertices from which to compute the horizon culling point. The positions\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\n * ellipsoid's axes.\n * @param {number} [stride=3]\n * @param {Cartesian3} [center=Cartesian3.ZERO]\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\n */\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromVertices = function (\n directionToPoint,\n vertices,\n stride,\n center,\n result\n) {\n return computeHorizonCullingPointFromVertices(\n this._ellipsoid,\n directionToPoint,\n vertices,\n stride,\n center,\n result\n );\n};\n\n/**\n * Similar to {@link EllipsoidalOccluder#computeHorizonCullingPointFromVertices} except computes the culling\n * point relative to an ellipsoid that has been shrunk by the minimum height when the minimum height is below\n * the ellipsoid. The returned point is expressed in the possibly-shrunk ellipsoid-scaled space and is suitable\n * for use with {@link EllipsoidalOccluder#isScaledSpacePointVisiblePossiblyUnderEllipsoid}.\n *\n * @param {Cartesian3} directionToPoint The direction that the computed point will lie along.\n * A reasonable direction to use is the direction from the center of the ellipsoid to\n * the center of the bounding sphere computed from the positions. The direction need not\n * be normalized.\n * @param {number[]} vertices The vertices from which to compute the horizon culling point. The positions\n * must be expressed in a reference frame centered at the ellipsoid and aligned with the\n * ellipsoid's axes.\n * @param {number} [stride=3]\n * @param {Cartesian3} [center=Cartesian3.ZERO]\n * @param {number} [minimumHeight] The minimum height of all vertices. If this value is undefined, all vertices are assumed to be above the ellipsoid.\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\n * @returns {Cartesian3} The computed horizon culling point, expressed in the possibly-shrunk ellipsoid-scaled space.\n */\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid = function (\n directionToPoint,\n vertices,\n stride,\n center,\n minimumHeight,\n result\n) {\n const possiblyShrunkEllipsoid = getPossiblyShrunkEllipsoid(\n this._ellipsoid,\n minimumHeight,\n scratchEllipsoidShrunk\n );\n return computeHorizonCullingPointFromVertices(\n possiblyShrunkEllipsoid,\n directionToPoint,\n vertices,\n stride,\n center,\n result\n );\n};\n\nconst subsampleScratch = [];\n\n/**\n * Computes a point that can be used for horizon culling of a rectangle. If the point is below\n * the horizon, the ellipsoid-conforming rectangle is guaranteed to be below the horizon as well.\n * The returned point is expressed in the ellipsoid-scaled space and is suitable for use with\n * {@link EllipsoidalOccluder#isScaledSpacePointVisible}.\n *\n * @param {Rectangle} rectangle The rectangle for which to compute the horizon culling point.\n * @param {Ellipsoid} ellipsoid The ellipsoid on which the rectangle is defined. This may be different from\n * the ellipsoid used by this instance for occlusion testing.\n * @param {Cartesian3} [result] The instance on which to store the result instead of allocating a new instance.\n * @returns {Cartesian3} The computed horizon culling point, expressed in the ellipsoid-scaled space.\n */\nEllipsoidalOccluder.prototype.computeHorizonCullingPointFromRectangle = function (\n rectangle,\n ellipsoid,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n const positions = Rectangle.subsample(\n rectangle,\n ellipsoid,\n 0.0,\n subsampleScratch\n );\n const bs = BoundingSphere.fromPoints(positions);\n\n // If the bounding sphere center is too close to the center of the occluder, it doesn't make\n // sense to try to horizon cull it.\n if (Cartesian3.magnitude(bs.center) < 0.1 * ellipsoid.minimumRadius) {\n return undefined;\n }\n\n return this.computeHorizonCullingPoint(bs.center, positions, result);\n};\n\nconst scratchEllipsoidShrunkRadii = new Cartesian3();\n\nfunction getPossiblyShrunkEllipsoid(ellipsoid, minimumHeight, result) {\n if (\n defined(minimumHeight) &&\n minimumHeight < 0.0 &&\n ellipsoid.minimumRadius > -minimumHeight\n ) {\n const ellipsoidShrunkRadii = Cartesian3.fromElements(\n ellipsoid.radii.x + minimumHeight,\n ellipsoid.radii.y + minimumHeight,\n ellipsoid.radii.z + minimumHeight,\n scratchEllipsoidShrunkRadii\n );\n ellipsoid = Ellipsoid.fromCartesian3(ellipsoidShrunkRadii, result);\n }\n return ellipsoid;\n}\n\nfunction computeHorizonCullingPointFromPositions(\n ellipsoid,\n directionToPoint,\n positions,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"directionToPoint\", directionToPoint);\n Check.defined(\"positions\", positions);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n const scaledSpaceDirectionToPoint = computeScaledSpaceDirectionToPoint(\n ellipsoid,\n directionToPoint\n );\n let resultMagnitude = 0.0;\n\n for (let i = 0, len = positions.length; i < len; ++i) {\n const position = positions[i];\n const candidateMagnitude = computeMagnitude(\n ellipsoid,\n position,\n scaledSpaceDirectionToPoint\n );\n if (candidateMagnitude < 0.0) {\n // all points should face the same direction, but this one doesn't, so return undefined\n return undefined;\n }\n resultMagnitude = Math.max(resultMagnitude, candidateMagnitude);\n }\n\n return magnitudeToPoint(scaledSpaceDirectionToPoint, resultMagnitude, result);\n}\n\nconst positionScratch = new Cartesian3();\n\nfunction computeHorizonCullingPointFromVertices(\n ellipsoid,\n directionToPoint,\n vertices,\n stride,\n center,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"directionToPoint\", directionToPoint);\n Check.defined(\"vertices\", vertices);\n Check.typeOf.number(\"stride\", stride);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Cartesian3();\n }\n\n stride = defaultValue(stride, 3);\n center = defaultValue(center, Cartesian3.ZERO);\n const scaledSpaceDirectionToPoint = computeScaledSpaceDirectionToPoint(\n ellipsoid,\n directionToPoint\n );\n let resultMagnitude = 0.0;\n\n for (let i = 0, len = vertices.length; i < len; i += stride) {\n positionScratch.x = vertices[i] + center.x;\n positionScratch.y = vertices[i + 1] + center.y;\n positionScratch.z = vertices[i + 2] + center.z;\n\n const candidateMagnitude = computeMagnitude(\n ellipsoid,\n positionScratch,\n scaledSpaceDirectionToPoint\n );\n if (candidateMagnitude < 0.0) {\n // all points should face the same direction, but this one doesn't, so return undefined\n return undefined;\n }\n resultMagnitude = Math.max(resultMagnitude, candidateMagnitude);\n }\n\n return magnitudeToPoint(scaledSpaceDirectionToPoint, resultMagnitude, result);\n}\n\nfunction isScaledSpacePointVisible(\n occludeeScaledSpacePosition,\n cameraPositionInScaledSpace,\n distanceToLimbInScaledSpaceSquared\n) {\n // See https://cesium.com/blog/2013/04/25/Horizon-culling/\n const cv = cameraPositionInScaledSpace;\n const vhMagnitudeSquared = distanceToLimbInScaledSpaceSquared;\n const vt = Cartesian3.subtract(\n occludeeScaledSpacePosition,\n cv,\n scratchCartesian\n );\n const vtDotVc = -Cartesian3.dot(vt, cv);\n // If vhMagnitudeSquared < 0 then we are below the surface of the ellipsoid and\n // in this case, set the culling plane to be on V.\n const isOccluded =\n vhMagnitudeSquared < 0\n ? vtDotVc > 0\n : vtDotVc > vhMagnitudeSquared &&\n (vtDotVc * vtDotVc) / Cartesian3.magnitudeSquared(vt) >\n vhMagnitudeSquared;\n return !isOccluded;\n}\n\nconst scaledSpaceScratch = new Cartesian3();\nconst directionScratch = new Cartesian3();\n\nfunction computeMagnitude(ellipsoid, position, scaledSpaceDirectionToPoint) {\n const scaledSpacePosition = ellipsoid.transformPositionToScaledSpace(\n position,\n scaledSpaceScratch\n );\n let magnitudeSquared = Cartesian3.magnitudeSquared(scaledSpacePosition);\n let magnitude = Math.sqrt(magnitudeSquared);\n const direction = Cartesian3.divideByScalar(\n scaledSpacePosition,\n magnitude,\n directionScratch\n );\n\n // For the purpose of this computation, points below the ellipsoid are consider to be on it instead.\n magnitudeSquared = Math.max(1.0, magnitudeSquared);\n magnitude = Math.max(1.0, magnitude);\n\n const cosAlpha = Cartesian3.dot(direction, scaledSpaceDirectionToPoint);\n const sinAlpha = Cartesian3.magnitude(\n Cartesian3.cross(direction, scaledSpaceDirectionToPoint, direction)\n );\n const cosBeta = 1.0 / magnitude;\n const sinBeta = Math.sqrt(magnitudeSquared - 1.0) * cosBeta;\n\n return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta);\n}\n\nfunction magnitudeToPoint(\n scaledSpaceDirectionToPoint,\n resultMagnitude,\n result\n) {\n // The horizon culling point is undefined if there were no positions from which to compute it,\n // the directionToPoint is pointing opposite all of the positions, or if we computed NaN or infinity.\n if (\n resultMagnitude <= 0.0 ||\n resultMagnitude === 1.0 / 0.0 ||\n resultMagnitude !== resultMagnitude\n ) {\n return undefined;\n }\n\n return Cartesian3.multiplyByScalar(\n scaledSpaceDirectionToPoint,\n resultMagnitude,\n result\n );\n}\n\nconst directionToPointScratch = new Cartesian3();\n\nfunction computeScaledSpaceDirectionToPoint(ellipsoid, directionToPoint) {\n if (Cartesian3.equals(directionToPoint, Cartesian3.ZERO)) {\n return directionToPoint;\n }\n\n ellipsoid.transformPositionToScaledSpace(\n directionToPoint,\n directionToPointScratch\n );\n return Cartesian3.normalize(directionToPointScratch, directionToPointScratch);\n}\nexport default EllipsoidalOccluder;\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartesian4 from \"../Core/Cartesian4.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport SceneMode from \"./SceneMode.js\";\nimport SceneTransforms from \"./SceneTransforms.js\";\n\n/**\n *
\n * A point is created and its initial properties are set by calling {@link PointPrimitiveCollection#add}. Do not call the constructor directly.\n *
\n * A graphical point positioned in the 3D scene, that is created\n * and rendered using a {@link PointPrimitiveCollection}.\n *\n * @alias PointPrimitive\n *\n * @performance Reading a property, e.g., {@link PointPrimitive#show}, is constant time.\n * Assigning to a property is constant time but results in\n * CPU to GPU traffic when {@link PointPrimitiveCollection#update} is called. The per-pointPrimitive traffic is\n * the same regardless of how many properties were updated. If most pointPrimitives in a collection need to be\n * updated, it may be more efficient to clear the collection with {@link PointPrimitiveCollection#removeAll}\n * and add new pointPrimitives instead of modifying each one.\n *\n * @exception {DeveloperError} scaleByDistance.far must be greater than scaleByDistance.near\n * @exception {DeveloperError} translucencyByDistance.far must be greater than translucencyByDistance.near\n * @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near\n *\n * @see PointPrimitiveCollection\n * @see PointPrimitiveCollection#add\n *\n * @internalConstructor\n * @class\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Points.html|Cesium Sandcastle Points Demo}\n */\nfunction PointPrimitive(options, pointPrimitiveCollection) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n if (\n defined(options.disableDepthTestDistance) &&\n options.disableDepthTestDistance < 0.0\n ) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than or equal to 0.0.\"\n );\n }\n //>>includeEnd('debug');\n\n let translucencyByDistance = options.translucencyByDistance;\n let scaleByDistance = options.scaleByDistance;\n let distanceDisplayCondition = options.distanceDisplayCondition;\n if (defined(translucencyByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (translucencyByDistance.far <= translucencyByDistance.near) {\n throw new DeveloperError(\n \"translucencyByDistance.far must be greater than translucencyByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n translucencyByDistance = NearFarScalar.clone(translucencyByDistance);\n }\n if (defined(scaleByDistance)) {\n //>>includeStart('debug', pragmas.debug);\n if (scaleByDistance.far <= scaleByDistance.near) {\n throw new DeveloperError(\n \"scaleByDistance.far must be greater than scaleByDistance.near.\"\n );\n }\n //>>includeEnd('debug');\n scaleByDistance = NearFarScalar.clone(scaleByDistance);\n }\n if (defined(distanceDisplayCondition)) {\n //>>includeStart('debug', pragmas.debug);\n if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {\n throw new DeveloperError(\n \"distanceDisplayCondition.far must be greater than distanceDisplayCondition.near.\"\n );\n }\n //>>includeEnd('debug');\n distanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition\n );\n }\n\n this._show = defaultValue(options.show, true);\n this._position = Cartesian3.clone(\n defaultValue(options.position, Cartesian3.ZERO)\n );\n this._actualPosition = Cartesian3.clone(this._position); // For columbus view and 2D\n this._color = Color.clone(defaultValue(options.color, Color.WHITE));\n this._outlineColor = Color.clone(\n defaultValue(options.outlineColor, Color.TRANSPARENT)\n );\n this._outlineWidth = defaultValue(options.outlineWidth, 0.0);\n this._pixelSize = defaultValue(options.pixelSize, 10.0);\n this._scaleByDistance = scaleByDistance;\n this._translucencyByDistance = translucencyByDistance;\n this._distanceDisplayCondition = distanceDisplayCondition;\n this._disableDepthTestDistance = defaultValue(\n options.disableDepthTestDistance,\n 0.0\n );\n this._id = options.id;\n this._collection = defaultValue(options.collection, pointPrimitiveCollection);\n\n this._clusterShow = true;\n\n this._pickId = undefined;\n this._pointPrimitiveCollection = pointPrimitiveCollection;\n this._dirty = false;\n this._index = -1; //Used only by PointPrimitiveCollection\n}\n\nconst SHOW_INDEX = (PointPrimitive.SHOW_INDEX = 0);\nconst POSITION_INDEX = (PointPrimitive.POSITION_INDEX = 1);\nconst COLOR_INDEX = (PointPrimitive.COLOR_INDEX = 2);\nconst OUTLINE_COLOR_INDEX = (PointPrimitive.OUTLINE_COLOR_INDEX = 3);\nconst OUTLINE_WIDTH_INDEX = (PointPrimitive.OUTLINE_WIDTH_INDEX = 4);\nconst PIXEL_SIZE_INDEX = (PointPrimitive.PIXEL_SIZE_INDEX = 5);\nconst SCALE_BY_DISTANCE_INDEX = (PointPrimitive.SCALE_BY_DISTANCE_INDEX = 6);\nconst TRANSLUCENCY_BY_DISTANCE_INDEX = (PointPrimitive.TRANSLUCENCY_BY_DISTANCE_INDEX = 7);\nconst DISTANCE_DISPLAY_CONDITION_INDEX = (PointPrimitive.DISTANCE_DISPLAY_CONDITION_INDEX = 8);\nconst DISABLE_DEPTH_DISTANCE_INDEX = (PointPrimitive.DISABLE_DEPTH_DISTANCE_INDEX = 9);\nPointPrimitive.NUMBER_OF_PROPERTIES = 10;\n\nfunction makeDirty(pointPrimitive, propertyChanged) {\n const pointPrimitiveCollection = pointPrimitive._pointPrimitiveCollection;\n if (defined(pointPrimitiveCollection)) {\n pointPrimitiveCollection._updatePointPrimitive(\n pointPrimitive,\n propertyChanged\n );\n pointPrimitive._dirty = true;\n }\n}\n\nObject.defineProperties(PointPrimitive.prototype, {\n /**\n * Determines if this point will be shown. Use this to hide or show a point, instead\n * of removing it and re-adding it to the collection.\n * @memberof PointPrimitive.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._show;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._show !== value) {\n this._show = value;\n makeDirty(this, SHOW_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the Cartesian position of this point.\n * @memberof PointPrimitive.prototype\n * @type {Cartesian3}\n */\n position: {\n get: function () {\n return this._position;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug)\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const position = this._position;\n if (!Cartesian3.equals(position, value)) {\n Cartesian3.clone(value, position);\n Cartesian3.clone(value, this._actualPosition);\n\n makeDirty(this, POSITION_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets near and far scaling properties of a point based on the point's distance from the camera.\n * A point's scale will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the point's scale remains clamped to the nearest bound. This scale\n * multiplies the pixelSize and outlineWidth to affect the total size of the point. If undefined,\n * scaleByDistance will be disabled.\n * @memberof PointPrimitive.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a pointPrimitive's scaleByDistance to scale to 15 when the\n * // camera is 1500 meters from the pointPrimitive and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * p.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 15, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable scaling by distance\n * p.scaleByDistance = undefined;\n */\n scaleByDistance: {\n get: function () {\n return this._scaleByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n const scaleByDistance = this._scaleByDistance;\n if (!NearFarScalar.equals(scaleByDistance, value)) {\n this._scaleByDistance = NearFarScalar.clone(value, scaleByDistance);\n makeDirty(this, SCALE_BY_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets near and far translucency properties of a point based on the point's distance from the camera.\n * A point's translucency will interpolate between the {@link NearFarScalar#nearValue} and\n * {@link NearFarScalar#farValue} while the camera distance falls within the lower and upper bounds\n * of the specified {@link NearFarScalar#near} and {@link NearFarScalar#far}.\n * Outside of these ranges the point's translucency remains clamped to the nearest bound. If undefined,\n * translucencyByDistance will be disabled.\n * @memberof PointPrimitive.prototype\n * @type {NearFarScalar}\n *\n * @example\n * // Example 1.\n * // Set a point's translucency to 1.0 when the\n * // camera is 1500 meters from the point and disappear as\n * // the camera distance approaches 8.0e6 meters.\n * p.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);\n *\n * @example\n * // Example 2.\n * // disable translucency by distance\n * p.translucencyByDistance = undefined;\n */\n translucencyByDistance: {\n get: function () {\n return this._translucencyByDistance;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\n \"far distance must be greater than near distance.\"\n );\n }\n //>>includeEnd('debug');\n\n const translucencyByDistance = this._translucencyByDistance;\n if (!NearFarScalar.equals(translucencyByDistance, value)) {\n this._translucencyByDistance = NearFarScalar.clone(\n value,\n translucencyByDistance\n );\n makeDirty(this, TRANSLUCENCY_BY_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the inner size of the point in pixels.\n * @memberof PointPrimitive.prototype\n * @type {number}\n */\n pixelSize: {\n get: function () {\n return this._pixelSize;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._pixelSize !== value) {\n this._pixelSize = value;\n makeDirty(this, PIXEL_SIZE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the inner color of the point.\n * The red, green, blue, and alpha values are indicated by value's red, green,\n * blue, and alpha properties as shown in Example 1. These components range from 0.0\n * (no intensity) to 1.0 (full intensity).\n * @memberof PointPrimitive.prototype\n * @type {Color}\n *\n * @example\n * // Example 1. Assign yellow.\n * p.color = Cesium.Color.YELLOW;\n *\n * @example\n * // Example 2. Make a pointPrimitive 50% translucent.\n * p.color = new Cesium.Color(1.0, 1.0, 1.0, 0.5);\n */\n color: {\n get: function () {\n return this._color;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const color = this._color;\n if (!Color.equals(color, value)) {\n Color.clone(value, color);\n makeDirty(this, COLOR_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the outline color of the point.\n * @memberof PointPrimitive.prototype\n * @type {Color}\n */\n outlineColor: {\n get: function () {\n return this._outlineColor;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n const outlineColor = this._outlineColor;\n if (!Color.equals(outlineColor, value)) {\n Color.clone(value, outlineColor);\n makeDirty(this, OUTLINE_COLOR_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the outline width in pixels. This width adds to pixelSize,\n * increasing the total size of the point.\n * @memberof PointPrimitive.prototype\n * @type {number}\n */\n outlineWidth: {\n get: function () {\n return this._outlineWidth;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required.\");\n }\n //>>includeEnd('debug');\n\n if (this._outlineWidth !== value) {\n this._outlineWidth = value;\n makeDirty(this, OUTLINE_WIDTH_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the condition specifying at what distance from the camera that this point will be displayed.\n * @memberof PointPrimitive.prototype\n * @type {DistanceDisplayCondition}\n * @default undefined\n */\n distanceDisplayCondition: {\n get: function () {\n return this._distanceDisplayCondition;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (defined(value) && value.far <= value.near) {\n throw new DeveloperError(\"far must be greater than near\");\n }\n //>>includeEnd('debug');\n if (\n !DistanceDisplayCondition.equals(this._distanceDisplayCondition, value)\n ) {\n this._distanceDisplayCondition = DistanceDisplayCondition.clone(\n value,\n this._distanceDisplayCondition\n );\n makeDirty(this, DISTANCE_DISPLAY_CONDITION_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.\n * When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.\n * @memberof PointPrimitive.prototype\n * @type {number}\n * @default 0.0\n */\n disableDepthTestDistance: {\n get: function () {\n return this._disableDepthTestDistance;\n },\n set: function (value) {\n if (this._disableDepthTestDistance !== value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value) || value < 0.0) {\n throw new DeveloperError(\n \"disableDepthTestDistance must be greater than or equal to 0.0.\"\n );\n }\n //>>includeEnd('debug');\n this._disableDepthTestDistance = value;\n makeDirty(this, DISABLE_DEPTH_DISTANCE_INDEX);\n }\n },\n },\n\n /**\n * Gets or sets the user-defined value returned when the point is picked.\n * @memberof PointPrimitive.prototype\n * @type {*}\n */\n id: {\n get: function () {\n return this._id;\n },\n set: function (value) {\n this._id = value;\n if (defined(this._pickId)) {\n this._pickId.object.id = value;\n }\n },\n },\n\n /**\n * @private\n */\n pickId: {\n get: function () {\n return this._pickId;\n },\n },\n\n /**\n * Determines whether or not this point will be shown or hidden because it was clustered.\n * @memberof PointPrimitive.prototype\n * @type {boolean}\n * @private\n */\n clusterShow: {\n get: function () {\n return this._clusterShow;\n },\n set: function (value) {\n if (this._clusterShow !== value) {\n this._clusterShow = value;\n makeDirty(this, SHOW_INDEX);\n }\n },\n },\n});\n\nPointPrimitive.prototype.getPickId = function (context) {\n if (!defined(this._pickId)) {\n this._pickId = context.createPickId({\n primitive: this,\n collection: this._collection,\n id: this._id,\n });\n }\n\n return this._pickId;\n};\n\nPointPrimitive.prototype._getActualPosition = function () {\n return this._actualPosition;\n};\n\nPointPrimitive.prototype._setActualPosition = function (value) {\n Cartesian3.clone(value, this._actualPosition);\n makeDirty(this, POSITION_INDEX);\n};\n\nconst tempCartesian3 = new Cartesian4();\nPointPrimitive._computeActualPosition = function (\n position,\n frameState,\n modelMatrix\n) {\n if (frameState.mode === SceneMode.SCENE3D) {\n return position;\n }\n\n Matrix4.multiplyByPoint(modelMatrix, position, tempCartesian3);\n return SceneTransforms.computeActualWgs84Position(frameState, tempCartesian3);\n};\n\nconst scratchCartesian4 = new Cartesian4();\n\n// This function is basically a stripped-down JavaScript version of PointPrimitiveCollectionVS.glsl\nPointPrimitive._computeScreenSpacePosition = function (\n modelMatrix,\n position,\n scene,\n result\n) {\n // Model to world coordinates\n const positionWorld = Matrix4.multiplyByVector(\n modelMatrix,\n Cartesian4.fromElements(\n position.x,\n position.y,\n position.z,\n 1,\n scratchCartesian4\n ),\n scratchCartesian4\n );\n const positionWC = SceneTransforms.wgs84ToWindowCoordinates(\n scene,\n positionWorld,\n result\n );\n return positionWC;\n};\n\n/**\n * Computes the screen-space position of the point's origin.\n * The screen space origin is the top, left corner of the canvas; x increases from\n * left to right, and y increases from top to bottom.\n *\n * @param {Scene} scene The scene.\n * @param {Cartesian2} [result] The object onto which to store the result.\n * @returns {Cartesian2} The screen-space position of the point.\n *\n * @exception {DeveloperError} PointPrimitive must be in a collection.\n *\n * @example\n * console.log(p.computeScreenSpacePosition(scene).toString());\n */\nPointPrimitive.prototype.computeScreenSpacePosition = function (scene, result) {\n const pointPrimitiveCollection = this._pointPrimitiveCollection;\n if (!defined(result)) {\n result = new Cartesian2();\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(pointPrimitiveCollection)) {\n throw new DeveloperError(\"PointPrimitive must be in a collection.\");\n }\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n //>>includeEnd('debug');\n\n const modelMatrix = pointPrimitiveCollection.modelMatrix;\n const windowCoordinates = PointPrimitive._computeScreenSpacePosition(\n modelMatrix,\n this._actualPosition,\n scene,\n result\n );\n if (!defined(windowCoordinates)) {\n return undefined;\n }\n\n windowCoordinates.y = scene.canvas.clientHeight - windowCoordinates.y;\n return windowCoordinates;\n};\n\n/**\n * Gets a point's screen space bounding box centered around screenSpacePosition.\n * @param {PointPrimitive} point The point to get the screen space bounding box for.\n * @param {Cartesian2} screenSpacePosition The screen space center of the label.\n * @param {BoundingRectangle} [result] The object onto which to store the result.\n * @returns {BoundingRectangle} The screen space bounding box.\n *\n * @private\n */\nPointPrimitive.getScreenSpaceBoundingBox = function (\n point,\n screenSpacePosition,\n result\n) {\n const size = point.pixelSize;\n const halfSize = size * 0.5;\n\n const x = screenSpacePosition.x - halfSize;\n const y = screenSpacePosition.y - halfSize;\n const width = size;\n const height = size;\n\n if (!defined(result)) {\n result = new BoundingRectangle();\n }\n\n result.x = x;\n result.y = y;\n result.width = width;\n result.height = height;\n\n return result;\n};\n\n/**\n * Determines if this point equals another point. Points are equal if all their properties\n * are equal. Points in different collections can be equal.\n *\n * @param {PointPrimitive} other The point to compare for equality.\n * @returns {boolean} true if the points are equal; otherwise, false.\n */\nPointPrimitive.prototype.equals = function (other) {\n return (\n this === other ||\n (defined(other) &&\n this._id === other._id &&\n Cartesian3.equals(this._position, other._position) &&\n Color.equals(this._color, other._color) &&\n this._pixelSize === other._pixelSize &&\n this._outlineWidth === other._outlineWidth &&\n this._show === other._show &&\n Color.equals(this._outlineColor, other._outlineColor) &&\n NearFarScalar.equals(this._scaleByDistance, other._scaleByDistance) &&\n NearFarScalar.equals(\n this._translucencyByDistance,\n other._translucencyByDistance\n ) &&\n DistanceDisplayCondition.equals(\n this._distanceDisplayCondition,\n other._distanceDisplayCondition\n ) &&\n this._disableDepthTestDistance === other._disableDepthTestDistance)\n );\n};\n\nPointPrimitive.prototype._destroy = function () {\n this._pickId = this._pickId && this._pickId.destroy();\n this._pointPrimitiveCollection = undefined;\n};\nexport default PointPrimitive;\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"in vec4 v_color;\\n\\\nin vec4 v_outlineColor;\\n\\\nin float v_innerPercent;\\n\\\nin float v_pixelDistance;\\n\\\nin vec4 v_pickColor;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n // The distance in UV space from this fragment to the center of the point, at most 0.5.\\n\\\n float distanceToCenter = length(gl_PointCoord - vec2(0.5));\\n\\\n // The max distance stops one pixel shy of the edge to leave space for anti-aliasing.\\n\\\n float maxDistance = max(0.0, 0.5 - v_pixelDistance);\\n\\\n float wholeAlpha = 1.0 - smoothstep(maxDistance, 0.5, distanceToCenter);\\n\\\n float innerAlpha = 1.0 - smoothstep(maxDistance * v_innerPercent, 0.5 * v_innerPercent, distanceToCenter);\\n\\\n\\n\\\n vec4 color = mix(v_outlineColor, v_color, innerAlpha);\\n\\\n color.a *= wholeAlpha;\\n\\\n\\n\\\n// Fully transparent parts of the billboard are not pickable.\\n\\\n#if !defined(OPAQUE) && !defined(TRANSLUCENT)\\n\\\n if (color.a < 0.005) // matches 0/255 and 1/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#else\\n\\\n// The billboard is rendered twice. The opaque pass discards translucent fragments\\n\\\n// and the translucent pass discards opaque fragments.\\n\\\n#ifdef OPAQUE\\n\\\n if (color.a < 0.995) // matches < 254/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#else\\n\\\n if (color.a >= 0.995) // matches 254/255 and 255/255\\n\\\n {\\n\\\n discard;\\n\\\n }\\n\\\n#endif\\n\\\n#endif\\n\\\n\\n\\\n out_FragColor = czm_gammaCorrect(color);\\n\\\n czm_writeLogDepth();\\n\\\n}\\n\\\n\";\n", "//This file is automatically rebuilt by the Cesium build process.\nexport default \"uniform float u_maxTotalPointSize;\\n\\\n\\n\\\nin vec4 positionHighAndSize;\\n\\\nin vec4 positionLowAndOutline;\\n\\\nin vec4 compressedAttribute0; // color, outlineColor, pick color\\n\\\nin vec4 compressedAttribute1; // show, translucency by distance, some free space\\n\\\nin vec4 scaleByDistance; // near, nearScale, far, farScale\\n\\\nin vec3 distanceDisplayConditionAndDisableDepth; // near, far, disableDepthTestDistance\\n\\\n\\n\\\nout vec4 v_color;\\n\\\nout vec4 v_outlineColor;\\n\\\nout float v_innerPercent;\\n\\\nout float v_pixelDistance;\\n\\\nout vec4 v_pickColor;\\n\\\n\\n\\\nconst float SHIFT_LEFT8 = 256.0;\\n\\\nconst float SHIFT_RIGHT8 = 1.0 / 256.0;\\n\\\n\\n\\\nvoid main()\\n\\\n{\\n\\\n // Modifying this shader may also require modifications to PointPrimitive._computeScreenSpacePosition\\n\\\n\\n\\\n // unpack attributes\\n\\\n vec3 positionHigh = positionHighAndSize.xyz;\\n\\\n vec3 positionLow = positionLowAndOutline.xyz;\\n\\\n float outlineWidthBothSides = 2.0 * positionLowAndOutline.w;\\n\\\n float totalSize = positionHighAndSize.w + outlineWidthBothSides;\\n\\\n float outlinePercent = outlineWidthBothSides / totalSize;\\n\\\n // Scale in response to browser-zoom.\\n\\\n totalSize *= czm_pixelRatio;\\n\\\n\\n\\\n float temp = compressedAttribute1.x * SHIFT_RIGHT8;\\n\\\n float show = floor(temp);\\n\\\n\\n\\\n#ifdef EYE_DISTANCE_TRANSLUCENCY\\n\\\n vec4 translucencyByDistance;\\n\\\n translucencyByDistance.x = compressedAttribute1.z;\\n\\\n translucencyByDistance.z = compressedAttribute1.w;\\n\\\n\\n\\\n translucencyByDistance.y = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\\n\\\n\\n\\\n temp = compressedAttribute1.y * SHIFT_RIGHT8;\\n\\\n translucencyByDistance.w = ((temp - floor(temp)) * SHIFT_LEFT8) / 255.0;\\n\\\n#endif\\n\\\n\\n\\\n ///////////////////////////////////////////////////////////////////////////\\n\\\n\\n\\\n vec4 color;\\n\\\n vec4 outlineColor;\\n\\\n vec4 pickColor;\\n\\\n\\n\\\n // compressedAttribute0.z => pickColor.rgb\\n\\\n\\n\\\n temp = compressedAttribute0.z * SHIFT_RIGHT8;\\n\\\n pickColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n pickColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n pickColor.r = floor(temp);\\n\\\n\\n\\\n // compressedAttribute0.x => color.rgb\\n\\\n\\n\\\n temp = compressedAttribute0.x * SHIFT_RIGHT8;\\n\\\n color.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n color.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n color.r = floor(temp);\\n\\\n\\n\\\n // compressedAttribute0.y => outlineColor.rgb\\n\\\n\\n\\\n temp = compressedAttribute0.y * SHIFT_RIGHT8;\\n\\\n outlineColor.b = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n outlineColor.g = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n outlineColor.r = floor(temp);\\n\\\n\\n\\\n // compressedAttribute0.w => color.a, outlineColor.a, pickColor.a\\n\\\n\\n\\\n temp = compressedAttribute0.w * SHIFT_RIGHT8;\\n\\\n pickColor.a = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n pickColor = pickColor / 255.0;\\n\\\n\\n\\\n temp = floor(temp) * SHIFT_RIGHT8;\\n\\\n outlineColor.a = (temp - floor(temp)) * SHIFT_LEFT8;\\n\\\n outlineColor /= 255.0;\\n\\\n color.a = floor(temp);\\n\\\n color /= 255.0;\\n\\\n\\n\\\n ///////////////////////////////////////////////////////////////////////////\\n\\\n\\n\\\n vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);\\n\\\n vec4 positionEC = czm_modelViewRelativeToEye * p;\\n\\\n\\n\\\n ///////////////////////////////////////////////////////////////////////////\\n\\\n\\n\\\n#if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)\\n\\\n float lengthSq;\\n\\\n if (czm_sceneMode == czm_sceneMode2D)\\n\\\n {\\n\\\n // 2D camera distance is a special case\\n\\\n // treat all billboards as flattened to the z=0.0 plane\\n\\\n lengthSq = czm_eyeHeight2D.y;\\n\\\n }\\n\\\n else\\n\\\n {\\n\\\n lengthSq = dot(positionEC.xyz, positionEC.xyz);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef EYE_DISTANCE_SCALING\\n\\\n totalSize *= czm_nearFarScalar(scaleByDistance, lengthSq);\\n\\\n#endif\\n\\\n if (totalSize > 0.0) {\\n\\\n // Add padding for anti-aliasing on both sides.\\n\\\n totalSize += 3.0;\\n\\\n }\\n\\\n\\n\\\n // Clamp to max point size.\\n\\\n totalSize = min(totalSize, u_maxTotalPointSize);\\n\\\n // If size is too small, push vertex behind near plane for clipping.\\n\\\n // Note that context.minimumAliasedPointSize \\\"will be at most 1.0\\\".\\n\\\n if (totalSize < 1.0)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n totalSize = 1.0;\\n\\\n }\\n\\\n\\n\\\n float translucency = 1.0;\\n\\\n#ifdef EYE_DISTANCE_TRANSLUCENCY\\n\\\n translucency = czm_nearFarScalar(translucencyByDistance, lengthSq);\\n\\\n // push vertex behind near plane for clipping\\n\\\n if (translucency < 0.004)\\n\\\n {\\n\\\n positionEC.xyz = vec3(0.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n#ifdef DISTANCE_DISPLAY_CONDITION\\n\\\n float nearSq = distanceDisplayConditionAndDisableDepth.x;\\n\\\n float farSq = distanceDisplayConditionAndDisableDepth.y;\\n\\\n if (lengthSq < nearSq || lengthSq > farSq) {\\n\\\n // push vertex behind camera to force it to be clipped\\n\\\n positionEC.xyz = vec3(0.0, 0.0, 1.0);\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n gl_Position = czm_projection * positionEC;\\n\\\n czm_vertexLogDepth();\\n\\\n\\n\\\n#ifdef DISABLE_DEPTH_DISTANCE\\n\\\n float disableDepthTestDistance = distanceDisplayConditionAndDisableDepth.z;\\n\\\n if (disableDepthTestDistance == 0.0 && czm_minimumDisableDepthTestDistance != 0.0)\\n\\\n {\\n\\\n disableDepthTestDistance = czm_minimumDisableDepthTestDistance;\\n\\\n }\\n\\\n\\n\\\n if (disableDepthTestDistance != 0.0)\\n\\\n {\\n\\\n // Don't try to \\\"multiply both sides\\\" by w. Greater/less-than comparisons won't work for negative values of w.\\n\\\n float zclip = gl_Position.z / gl_Position.w;\\n\\\n bool clipped = (zclip < -1.0 || zclip > 1.0);\\n\\\n if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))\\n\\\n {\\n\\\n // Position z on the near plane.\\n\\\n gl_Position.z = -gl_Position.w;\\n\\\n#ifdef LOG_DEPTH\\n\\\n czm_vertexLogDepth(vec4(czm_currentFrustum.x));\\n\\\n#endif\\n\\\n }\\n\\\n }\\n\\\n#endif\\n\\\n\\n\\\n v_color = color;\\n\\\n v_color.a *= translucency * show;\\n\\\n v_outlineColor = outlineColor;\\n\\\n v_outlineColor.a *= translucency * show;\\n\\\n\\n\\\n v_innerPercent = 1.0 - outlinePercent;\\n\\\n v_pixelDistance = 2.0 / totalSize;\\n\\\n gl_PointSize = totalSize * show;\\n\\\n gl_Position *= show;\\n\\\n\\n\\\n v_pickColor = pickColor;\\n\\\n}\\n\\\n\";\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Color from \"../Core/Color.js\";\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport EncodedCartesian3 from \"../Core/EncodedCartesian3.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PrimitiveType from \"../Core/PrimitiveType.js\";\nimport WebGLConstants from \"../Core/WebGLConstants.js\";\nimport BufferUsage from \"../Renderer/BufferUsage.js\";\nimport ContextLimits from \"../Renderer/ContextLimits.js\";\nimport DrawCommand from \"../Renderer/DrawCommand.js\";\nimport Pass from \"../Renderer/Pass.js\";\nimport RenderState from \"../Renderer/RenderState.js\";\nimport ShaderProgram from \"../Renderer/ShaderProgram.js\";\nimport ShaderSource from \"../Renderer/ShaderSource.js\";\nimport VertexArrayFacade from \"../Renderer/VertexArrayFacade.js\";\nimport PointPrimitiveCollectionFS from \"../Shaders/PointPrimitiveCollectionFS.js\";\nimport PointPrimitiveCollectionVS from \"../Shaders/PointPrimitiveCollectionVS.js\";\nimport BlendingState from \"./BlendingState.js\";\nimport BlendOption from \"./BlendOption.js\";\nimport PointPrimitive from \"./PointPrimitive.js\";\nimport SceneMode from \"./SceneMode.js\";\n\nconst SHOW_INDEX = PointPrimitive.SHOW_INDEX;\nconst POSITION_INDEX = PointPrimitive.POSITION_INDEX;\nconst COLOR_INDEX = PointPrimitive.COLOR_INDEX;\nconst OUTLINE_COLOR_INDEX = PointPrimitive.OUTLINE_COLOR_INDEX;\nconst OUTLINE_WIDTH_INDEX = PointPrimitive.OUTLINE_WIDTH_INDEX;\nconst PIXEL_SIZE_INDEX = PointPrimitive.PIXEL_SIZE_INDEX;\nconst SCALE_BY_DISTANCE_INDEX = PointPrimitive.SCALE_BY_DISTANCE_INDEX;\nconst TRANSLUCENCY_BY_DISTANCE_INDEX =\n PointPrimitive.TRANSLUCENCY_BY_DISTANCE_INDEX;\nconst DISTANCE_DISPLAY_CONDITION_INDEX =\n PointPrimitive.DISTANCE_DISPLAY_CONDITION_INDEX;\nconst DISABLE_DEPTH_DISTANCE_INDEX =\n PointPrimitive.DISABLE_DEPTH_DISTANCE_INDEX;\nconst NUMBER_OF_PROPERTIES = PointPrimitive.NUMBER_OF_PROPERTIES;\n\nconst attributeLocations = {\n positionHighAndSize: 0,\n positionLowAndOutline: 1,\n compressedAttribute0: 2, // color, outlineColor, pick color\n compressedAttribute1: 3, // show, translucency by distance, some free space\n scaleByDistance: 4,\n distanceDisplayConditionAndDisableDepth: 5,\n};\n\n/**\n * A renderable collection of points.\n *

\n * Points are added and removed from the collection using {@link PointPrimitiveCollection#add}\n * and {@link PointPrimitiveCollection#remove}.\n *\n * @alias PointPrimitiveCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each point from model to world coordinates.\n * @param {boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.\n * @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The point blending option. The default\n * is used for rendering both opaque and translucent points. However, if either all of the points are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.\n * @param {boolean} [options.show=true] Determines if the primitives in the collection will be shown.\n *\n * @performance For best performance, prefer a few collections, each with many points, to\n * many collections with only a few points each. Organize collections so that points\n * with the same update frequency are in the same collection, i.e., points that do not\n * change should be in one collection; points that change every frame should be in another\n * collection; and so on.\n *\n *\n * @example\n * // Create a pointPrimitive collection with two points\n * const points = scene.primitives.add(new Cesium.PointPrimitiveCollection());\n * points.add({\n * position : new Cesium.Cartesian3(1.0, 2.0, 3.0),\n * color : Cesium.Color.YELLOW\n * });\n * points.add({\n * position : new Cesium.Cartesian3(4.0, 5.0, 6.0),\n * color : Cesium.Color.CYAN\n * });\n *\n * @see PointPrimitiveCollection#add\n * @see PointPrimitiveCollection#remove\n * @see PointPrimitive\n */\nfunction PointPrimitiveCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._sp = undefined;\n this._spTranslucent = undefined;\n this._rsOpaque = undefined;\n this._rsTranslucent = undefined;\n this._vaf = undefined;\n\n this._pointPrimitives = [];\n this._pointPrimitivesToUpdate = [];\n this._pointPrimitivesToUpdateIndex = 0;\n this._pointPrimitivesRemoved = false;\n this._createVertexArray = false;\n\n this._shaderScaleByDistance = false;\n this._compiledShaderScaleByDistance = false;\n\n this._shaderTranslucencyByDistance = false;\n this._compiledShaderTranslucencyByDistance = false;\n\n this._shaderDistanceDisplayCondition = false;\n this._compiledShaderDistanceDisplayCondition = false;\n\n this._shaderDisableDepthDistance = false;\n this._compiledShaderDisableDepthDistance = false;\n\n this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);\n\n this._maxPixelSize = 1.0;\n\n this._baseVolume = new BoundingSphere();\n this._baseVolumeWC = new BoundingSphere();\n this._baseVolume2D = new BoundingSphere();\n this._boundingVolume = new BoundingSphere();\n this._boundingVolumeDirty = false;\n\n this._colorCommands = [];\n\n /**\n * Determines if primitives in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * The 4x4 transformation matrix that transforms each point in this collection from model to world coordinates.\n * When this is the identity matrix, the pointPrimitives are drawn in world coordinates, i.e., Earth's WGS84 coordinates.\n * Local reference frames can be used by providing a different transformation matrix, like that returned\n * by {@link Transforms.eastNorthUpToFixedFrame}.\n *\n * @type {Matrix4}\n * @default {@link Matrix4.IDENTITY}\n *\n *\n * @example\n * const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);\n * pointPrimitives.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);\n * pointPrimitives.add({\n * color : Cesium.Color.ORANGE,\n * position : new Cesium.Cartesian3(0.0, 0.0, 0.0) // center\n * });\n * pointPrimitives.add({\n * color : Cesium.Color.YELLOW,\n * position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0) // east\n * });\n * pointPrimitives.add({\n * color : Cesium.Color.GREEN,\n * position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0) // north\n * });\n * pointPrimitives.add({\n * color : Cesium.Color.CYAN,\n * position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0) // up\n * });\n *\n * @see Transforms.eastNorthUpToFixedFrame\n */\n this.modelMatrix = Matrix4.clone(\n defaultValue(options.modelMatrix, Matrix4.IDENTITY)\n );\n this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);\n\n /**\n * This property is for debugging only; it is not for production use nor is it optimized.\n *

\n * Draws the bounding sphere for each draw command in the primitive.\n *

\n *\n * @type {boolean}\n *\n * @default false\n */\n this.debugShowBoundingVolume = defaultValue(\n options.debugShowBoundingVolume,\n false\n );\n\n /**\n * The point blending option. The default is used for rendering both opaque and translucent points.\n * However, if either all of the points are completely opaque or all are completely translucent,\n * setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve\n * performance by up to 2x.\n * @type {BlendOption}\n * @default BlendOption.OPAQUE_AND_TRANSLUCENT\n */\n this.blendOption = defaultValue(\n options.blendOption,\n BlendOption.OPAQUE_AND_TRANSLUCENT\n );\n this._blendOption = undefined;\n\n this._mode = SceneMode.SCENE3D;\n this._maxTotalPointSize = 1;\n\n // The buffer usage for each attribute is determined based on the usage of the attribute over time.\n this._buffersUsage = [\n BufferUsage.STATIC_DRAW, // SHOW_INDEX\n BufferUsage.STATIC_DRAW, // POSITION_INDEX\n BufferUsage.STATIC_DRAW, // COLOR_INDEX\n BufferUsage.STATIC_DRAW, // OUTLINE_COLOR_INDEX\n BufferUsage.STATIC_DRAW, // OUTLINE_WIDTH_INDEX\n BufferUsage.STATIC_DRAW, // PIXEL_SIZE_INDEX\n BufferUsage.STATIC_DRAW, // SCALE_BY_DISTANCE_INDEX\n BufferUsage.STATIC_DRAW, // TRANSLUCENCY_BY_DISTANCE_INDEX\n BufferUsage.STATIC_DRAW, // DISTANCE_DISPLAY_CONDITION_INDEX\n ];\n\n const that = this;\n this._uniforms = {\n u_maxTotalPointSize: function () {\n return that._maxTotalPointSize;\n },\n };\n}\n\nObject.defineProperties(PointPrimitiveCollection.prototype, {\n /**\n * Returns the number of points in this collection. This is commonly used with\n * {@link PointPrimitiveCollection#get} to iterate over all the points\n * in the collection.\n * @memberof PointPrimitiveCollection.prototype\n * @type {number}\n */\n length: {\n get: function () {\n removePointPrimitives(this);\n return this._pointPrimitives.length;\n },\n },\n});\n\nfunction destroyPointPrimitives(pointPrimitives) {\n const length = pointPrimitives.length;\n for (let i = 0; i < length; ++i) {\n if (pointPrimitives[i]) {\n pointPrimitives[i]._destroy();\n }\n }\n}\n\n/**\n * Creates and adds a point with the specified initial properties to the collection.\n * The added point is returned so it can be modified or removed from the collection later.\n *\n * @param {object}[options] A template describing the point's properties as shown in Example 1.\n * @returns {PointPrimitive} The point that was added to the collection.\n *\n * @performance Calling add is expected constant time. However, the collection's vertex buffer\n * is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For\n * best performance, add as many pointPrimitives as possible before calling update.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Example 1: Add a point, specifying all the default values.\n * const p = pointPrimitives.add({\n * show : true,\n * position : Cesium.Cartesian3.ZERO,\n * pixelSize : 10.0,\n * color : Cesium.Color.WHITE,\n * outlineColor : Cesium.Color.TRANSPARENT,\n * outlineWidth : 0.0,\n * id : undefined\n * });\n *\n * @example\n * // Example 2: Specify only the point's cartographic position.\n * const p = pointPrimitives.add({\n * position : Cesium.Cartesian3.fromDegrees(longitude, latitude, height)\n * });\n *\n * @see PointPrimitiveCollection#remove\n * @see PointPrimitiveCollection#removeAll\n */\nPointPrimitiveCollection.prototype.add = function (options) {\n const p = new PointPrimitive(options, this);\n p._index = this._pointPrimitives.length;\n\n this._pointPrimitives.push(p);\n this._createVertexArray = true;\n\n return p;\n};\n\n/**\n * Removes a point from the collection.\n *\n * @param {PointPrimitive} pointPrimitive The point to remove.\n * @returns {boolean} true if the point was removed; false if the point was not found in the collection.\n *\n * @performance Calling remove is expected constant time. However, the collection's vertex buffer\n * is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For\n * best performance, remove as many points as possible before calling update.\n * If you intend to temporarily hide a point, it is usually more efficient to call\n * {@link PointPrimitive#show} instead of removing and re-adding the point.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * const p = pointPrimitives.add(...);\n * pointPrimitives.remove(p); // Returns true\n *\n * @see PointPrimitiveCollection#add\n * @see PointPrimitiveCollection#removeAll\n * @see PointPrimitive#show\n */\nPointPrimitiveCollection.prototype.remove = function (pointPrimitive) {\n if (this.contains(pointPrimitive)) {\n this._pointPrimitives[pointPrimitive._index] = null; // Removed later\n this._pointPrimitivesRemoved = true;\n this._createVertexArray = true;\n pointPrimitive._destroy();\n return true;\n }\n\n return false;\n};\n\n/**\n * Removes all points from the collection.\n *\n * @performance O(n). It is more efficient to remove all the points\n * from a collection and then add new ones than to create a new collection entirely.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * pointPrimitives.add(...);\n * pointPrimitives.add(...);\n * pointPrimitives.removeAll();\n *\n * @see PointPrimitiveCollection#add\n * @see PointPrimitiveCollection#remove\n */\nPointPrimitiveCollection.prototype.removeAll = function () {\n destroyPointPrimitives(this._pointPrimitives);\n this._pointPrimitives = [];\n this._pointPrimitivesToUpdate = [];\n this._pointPrimitivesToUpdateIndex = 0;\n this._pointPrimitivesRemoved = false;\n\n this._createVertexArray = true;\n};\n\nfunction removePointPrimitives(pointPrimitiveCollection) {\n if (pointPrimitiveCollection._pointPrimitivesRemoved) {\n pointPrimitiveCollection._pointPrimitivesRemoved = false;\n\n const newPointPrimitives = [];\n const pointPrimitives = pointPrimitiveCollection._pointPrimitives;\n const length = pointPrimitives.length;\n for (let i = 0, j = 0; i < length; ++i) {\n const pointPrimitive = pointPrimitives[i];\n if (pointPrimitive) {\n pointPrimitive._index = j++;\n newPointPrimitives.push(pointPrimitive);\n }\n }\n\n pointPrimitiveCollection._pointPrimitives = newPointPrimitives;\n }\n}\n\nPointPrimitiveCollection.prototype._updatePointPrimitive = function (\n pointPrimitive,\n propertyChanged\n) {\n if (!pointPrimitive._dirty) {\n this._pointPrimitivesToUpdate[\n this._pointPrimitivesToUpdateIndex++\n ] = pointPrimitive;\n }\n\n ++this._propertiesChanged[propertyChanged];\n};\n\n/**\n * Check whether this collection contains a given point.\n *\n * @param {PointPrimitive} [pointPrimitive] The point to check for.\n * @returns {boolean} true if this collection contains the point, false otherwise.\n *\n * @see PointPrimitiveCollection#get\n */\nPointPrimitiveCollection.prototype.contains = function (pointPrimitive) {\n return (\n defined(pointPrimitive) && pointPrimitive._pointPrimitiveCollection === this\n );\n};\n\n/**\n * Returns the point in the collection at the specified index. Indices are zero-based\n * and increase as points are added. Removing a point shifts all points after\n * it to the left, changing their indices. This function is commonly used with\n * {@link PointPrimitiveCollection#length} to iterate over all the points\n * in the collection.\n *\n * @param {number} index The zero-based index of the point.\n * @returns {PointPrimitive} The point at the specified index.\n *\n * @performance Expected constant time. If points were removed from the collection and\n * {@link PointPrimitiveCollection#update} was not called, an implicit O(n)\n * operation is performed.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Toggle the show property of every point in the collection\n * const len = pointPrimitives.length;\n * for (let i = 0; i < len; ++i) {\n * const p = pointPrimitives.get(i);\n * p.show = !p.show;\n * }\n *\n * @see PointPrimitiveCollection#length\n */\nPointPrimitiveCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n removePointPrimitives(this);\n return this._pointPrimitives[index];\n};\n\nPointPrimitiveCollection.prototype.computeNewBuffersUsage = function () {\n const buffersUsage = this._buffersUsage;\n let usageChanged = false;\n\n const properties = this._propertiesChanged;\n for (let k = 0; k < NUMBER_OF_PROPERTIES; ++k) {\n const newUsage =\n properties[k] === 0 ? BufferUsage.STATIC_DRAW : BufferUsage.STREAM_DRAW;\n usageChanged = usageChanged || buffersUsage[k] !== newUsage;\n buffersUsage[k] = newUsage;\n }\n\n return usageChanged;\n};\n\nfunction createVAF(context, numberOfPointPrimitives, buffersUsage) {\n return new VertexArrayFacade(\n context,\n [\n {\n index: attributeLocations.positionHighAndSize,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[POSITION_INDEX],\n },\n {\n index: attributeLocations.positionLowAndShow,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[POSITION_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute0,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[COLOR_INDEX],\n },\n {\n index: attributeLocations.compressedAttribute1,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[TRANSLUCENCY_BY_DISTANCE_INDEX],\n },\n {\n index: attributeLocations.scaleByDistance,\n componentsPerAttribute: 4,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[SCALE_BY_DISTANCE_INDEX],\n },\n {\n index: attributeLocations.distanceDisplayConditionAndDisableDepth,\n componentsPerAttribute: 3,\n componentDatatype: ComponentDatatype.FLOAT,\n usage: buffersUsage[DISTANCE_DISPLAY_CONDITION_INDEX],\n },\n ],\n numberOfPointPrimitives\n ); // 1 vertex per pointPrimitive\n}\n\n///////////////////////////////////////////////////////////////////////////\n\n// PERFORMANCE_IDEA: Save memory if a property is the same for all pointPrimitives, use a latched attribute state,\n// instead of storing it in a vertex buffer.\n\nconst writePositionScratch = new EncodedCartesian3();\n\nfunction writePositionSizeAndOutline(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n const i = pointPrimitive._index;\n const position = pointPrimitive._getActualPosition();\n\n if (pointPrimitiveCollection._mode === SceneMode.SCENE3D) {\n BoundingSphere.expand(\n pointPrimitiveCollection._baseVolume,\n position,\n pointPrimitiveCollection._baseVolume\n );\n pointPrimitiveCollection._boundingVolumeDirty = true;\n }\n\n EncodedCartesian3.fromCartesian(position, writePositionScratch);\n const pixelSize = pointPrimitive.pixelSize;\n const outlineWidth = pointPrimitive.outlineWidth;\n\n pointPrimitiveCollection._maxPixelSize = Math.max(\n pointPrimitiveCollection._maxPixelSize,\n pixelSize + outlineWidth\n );\n\n const positionHighWriter = vafWriters[attributeLocations.positionHighAndSize];\n const high = writePositionScratch.high;\n positionHighWriter(i, high.x, high.y, high.z, pixelSize);\n\n const positionLowWriter =\n vafWriters[attributeLocations.positionLowAndOutline];\n const low = writePositionScratch.low;\n positionLowWriter(i, low.x, low.y, low.z, outlineWidth);\n}\n\nconst LEFT_SHIFT16 = 65536.0; // 2^16\nconst LEFT_SHIFT8 = 256.0; // 2^8\n\nfunction writeCompressedAttrib0(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n const i = pointPrimitive._index;\n\n const color = pointPrimitive.color;\n const pickColor = pointPrimitive.getPickId(context).color;\n const outlineColor = pointPrimitive.outlineColor;\n\n let red = Color.floatToByte(color.red);\n let green = Color.floatToByte(color.green);\n let blue = Color.floatToByte(color.blue);\n const compressed0 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n red = Color.floatToByte(outlineColor.red);\n green = Color.floatToByte(outlineColor.green);\n blue = Color.floatToByte(outlineColor.blue);\n const compressed1 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n red = Color.floatToByte(pickColor.red);\n green = Color.floatToByte(pickColor.green);\n blue = Color.floatToByte(pickColor.blue);\n const compressed2 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;\n\n const compressed3 =\n Color.floatToByte(color.alpha) * LEFT_SHIFT16 +\n Color.floatToByte(outlineColor.alpha) * LEFT_SHIFT8 +\n Color.floatToByte(pickColor.alpha);\n\n const writer = vafWriters[attributeLocations.compressedAttribute0];\n writer(i, compressed0, compressed1, compressed2, compressed3);\n}\n\nfunction writeCompressedAttrib1(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n const i = pointPrimitive._index;\n\n let near = 0.0;\n let nearValue = 1.0;\n let far = 1.0;\n let farValue = 1.0;\n\n const translucency = pointPrimitive.translucencyByDistance;\n if (defined(translucency)) {\n near = translucency.near;\n nearValue = translucency.nearValue;\n far = translucency.far;\n farValue = translucency.farValue;\n\n if (nearValue !== 1.0 || farValue !== 1.0) {\n // translucency by distance calculation in shader need not be enabled\n // until a pointPrimitive with near and far !== 1.0 is found\n pointPrimitiveCollection._shaderTranslucencyByDistance = true;\n }\n }\n\n let show = pointPrimitive.show && pointPrimitive.clusterShow;\n\n // If the color alphas are zero, do not show this pointPrimitive. This lets us avoid providing\n // color during the pick pass and also eliminates a discard in the fragment shader.\n if (\n pointPrimitive.color.alpha === 0.0 &&\n pointPrimitive.outlineColor.alpha === 0.0\n ) {\n show = false;\n }\n\n nearValue = CesiumMath.clamp(nearValue, 0.0, 1.0);\n nearValue = nearValue === 1.0 ? 255.0 : (nearValue * 255.0) | 0;\n const compressed0 = (show ? 1.0 : 0.0) * LEFT_SHIFT8 + nearValue;\n\n farValue = CesiumMath.clamp(farValue, 0.0, 1.0);\n farValue = farValue === 1.0 ? 255.0 : (farValue * 255.0) | 0;\n const compressed1 = farValue;\n\n const writer = vafWriters[attributeLocations.compressedAttribute1];\n writer(i, compressed0, compressed1, near, far);\n}\n\nfunction writeScaleByDistance(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n const i = pointPrimitive._index;\n const writer = vafWriters[attributeLocations.scaleByDistance];\n let near = 0.0;\n let nearValue = 1.0;\n let far = 1.0;\n let farValue = 1.0;\n\n const scale = pointPrimitive.scaleByDistance;\n if (defined(scale)) {\n near = scale.near;\n nearValue = scale.nearValue;\n far = scale.far;\n farValue = scale.farValue;\n\n if (nearValue !== 1.0 || farValue !== 1.0) {\n // scale by distance calculation in shader need not be enabled\n // until a pointPrimitive with near and far !== 1.0 is found\n pointPrimitiveCollection._shaderScaleByDistance = true;\n }\n }\n\n writer(i, near, nearValue, far, farValue);\n}\n\nfunction writeDistanceDisplayConditionAndDepthDisable(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n const i = pointPrimitive._index;\n const writer =\n vafWriters[attributeLocations.distanceDisplayConditionAndDisableDepth];\n let near = 0.0;\n let far = Number.MAX_VALUE;\n\n const distanceDisplayCondition = pointPrimitive.distanceDisplayCondition;\n if (defined(distanceDisplayCondition)) {\n near = distanceDisplayCondition.near;\n far = distanceDisplayCondition.far;\n\n near *= near;\n far *= far;\n\n pointPrimitiveCollection._shaderDistanceDisplayCondition = true;\n }\n\n let disableDepthTestDistance = pointPrimitive.disableDepthTestDistance;\n disableDepthTestDistance *= disableDepthTestDistance;\n if (disableDepthTestDistance > 0.0) {\n pointPrimitiveCollection._shaderDisableDepthDistance = true;\n if (disableDepthTestDistance === Number.POSITIVE_INFINITY) {\n disableDepthTestDistance = -1.0;\n }\n }\n\n writer(i, near, far, disableDepthTestDistance);\n}\n\nfunction writePointPrimitive(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n) {\n writePositionSizeAndOutline(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n );\n writeCompressedAttrib0(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n );\n writeCompressedAttrib1(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n );\n writeScaleByDistance(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n );\n writeDistanceDisplayConditionAndDepthDisable(\n pointPrimitiveCollection,\n context,\n vafWriters,\n pointPrimitive\n );\n}\n\nfunction recomputeActualPositions(\n pointPrimitiveCollection,\n pointPrimitives,\n length,\n frameState,\n modelMatrix,\n recomputeBoundingVolume\n) {\n let boundingVolume;\n if (frameState.mode === SceneMode.SCENE3D) {\n boundingVolume = pointPrimitiveCollection._baseVolume;\n pointPrimitiveCollection._boundingVolumeDirty = true;\n } else {\n boundingVolume = pointPrimitiveCollection._baseVolume2D;\n }\n\n const positions = [];\n for (let i = 0; i < length; ++i) {\n const pointPrimitive = pointPrimitives[i];\n const position = pointPrimitive.position;\n const actualPosition = PointPrimitive._computeActualPosition(\n position,\n frameState,\n modelMatrix\n );\n if (defined(actualPosition)) {\n pointPrimitive._setActualPosition(actualPosition);\n\n if (recomputeBoundingVolume) {\n positions.push(actualPosition);\n } else {\n BoundingSphere.expand(boundingVolume, actualPosition, boundingVolume);\n }\n }\n }\n\n if (recomputeBoundingVolume) {\n BoundingSphere.fromPoints(positions, boundingVolume);\n }\n}\n\nfunction updateMode(pointPrimitiveCollection, frameState) {\n const mode = frameState.mode;\n\n const pointPrimitives = pointPrimitiveCollection._pointPrimitives;\n const pointPrimitivesToUpdate =\n pointPrimitiveCollection._pointPrimitivesToUpdate;\n const modelMatrix = pointPrimitiveCollection._modelMatrix;\n\n if (\n pointPrimitiveCollection._createVertexArray ||\n pointPrimitiveCollection._mode !== mode ||\n (mode !== SceneMode.SCENE3D &&\n !Matrix4.equals(modelMatrix, pointPrimitiveCollection.modelMatrix))\n ) {\n pointPrimitiveCollection._mode = mode;\n Matrix4.clone(pointPrimitiveCollection.modelMatrix, modelMatrix);\n pointPrimitiveCollection._createVertexArray = true;\n\n if (\n mode === SceneMode.SCENE3D ||\n mode === SceneMode.SCENE2D ||\n mode === SceneMode.COLUMBUS_VIEW\n ) {\n recomputeActualPositions(\n pointPrimitiveCollection,\n pointPrimitives,\n pointPrimitives.length,\n frameState,\n modelMatrix,\n true\n );\n }\n } else if (mode === SceneMode.MORPHING) {\n recomputeActualPositions(\n pointPrimitiveCollection,\n pointPrimitives,\n pointPrimitives.length,\n frameState,\n modelMatrix,\n true\n );\n } else if (mode === SceneMode.SCENE2D || mode === SceneMode.COLUMBUS_VIEW) {\n recomputeActualPositions(\n pointPrimitiveCollection,\n pointPrimitivesToUpdate,\n pointPrimitiveCollection._pointPrimitivesToUpdateIndex,\n frameState,\n modelMatrix,\n false\n );\n }\n}\n\nfunction updateBoundingVolume(collection, frameState, boundingVolume) {\n const pixelSize = frameState.camera.getPixelSize(\n boundingVolume,\n frameState.context.drawingBufferWidth,\n frameState.context.drawingBufferHeight\n );\n const size = pixelSize * collection._maxPixelSize;\n boundingVolume.radius += size;\n}\n\nconst scratchWriterArray = [];\n\n/**\n * @private\n */\nPointPrimitiveCollection.prototype.update = function (frameState) {\n removePointPrimitives(this);\n\n if (!this.show) {\n return;\n }\n\n this._maxTotalPointSize = ContextLimits.maximumAliasedPointSize;\n\n updateMode(this, frameState);\n\n const pointPrimitives = this._pointPrimitives;\n const pointPrimitivesLength = pointPrimitives.length;\n const pointPrimitivesToUpdate = this._pointPrimitivesToUpdate;\n const pointPrimitivesToUpdateLength = this._pointPrimitivesToUpdateIndex;\n\n const properties = this._propertiesChanged;\n\n const createVertexArray = this._createVertexArray;\n\n let vafWriters;\n const context = frameState.context;\n const pass = frameState.passes;\n const picking = pass.pick;\n\n // PERFORMANCE_IDEA: Round robin multiple buffers.\n if (createVertexArray || (!picking && this.computeNewBuffersUsage())) {\n this._createVertexArray = false;\n\n for (let k = 0; k < NUMBER_OF_PROPERTIES; ++k) {\n properties[k] = 0;\n }\n\n this._vaf = this._vaf && this._vaf.destroy();\n\n if (pointPrimitivesLength > 0) {\n // PERFORMANCE_IDEA: Instead of creating a new one, resize like std::vector.\n this._vaf = createVAF(context, pointPrimitivesLength, this._buffersUsage);\n vafWriters = this._vaf.writers;\n\n // Rewrite entire buffer if pointPrimitives were added or removed.\n for (let i = 0; i < pointPrimitivesLength; ++i) {\n const pointPrimitive = this._pointPrimitives[i];\n pointPrimitive._dirty = false; // In case it needed an update.\n writePointPrimitive(this, context, vafWriters, pointPrimitive);\n }\n\n this._vaf.commit();\n }\n\n this._pointPrimitivesToUpdateIndex = 0;\n } else if (pointPrimitivesToUpdateLength > 0) {\n // PointPrimitives were modified, but none were added or removed.\n const writers = scratchWriterArray;\n writers.length = 0;\n\n if (\n properties[POSITION_INDEX] ||\n properties[OUTLINE_WIDTH_INDEX] ||\n properties[PIXEL_SIZE_INDEX]\n ) {\n writers.push(writePositionSizeAndOutline);\n }\n\n if (properties[COLOR_INDEX] || properties[OUTLINE_COLOR_INDEX]) {\n writers.push(writeCompressedAttrib0);\n }\n\n if (properties[SHOW_INDEX] || properties[TRANSLUCENCY_BY_DISTANCE_INDEX]) {\n writers.push(writeCompressedAttrib1);\n }\n\n if (properties[SCALE_BY_DISTANCE_INDEX]) {\n writers.push(writeScaleByDistance);\n }\n\n if (\n properties[DISTANCE_DISPLAY_CONDITION_INDEX] ||\n properties[DISABLE_DEPTH_DISTANCE_INDEX]\n ) {\n writers.push(writeDistanceDisplayConditionAndDepthDisable);\n }\n\n const numWriters = writers.length;\n\n vafWriters = this._vaf.writers;\n\n if (pointPrimitivesToUpdateLength / pointPrimitivesLength > 0.1) {\n // If more than 10% of pointPrimitive change, rewrite the entire buffer.\n\n // PERFORMANCE_IDEA: I totally made up 10% :).\n\n for (let m = 0; m < pointPrimitivesToUpdateLength; ++m) {\n const b = pointPrimitivesToUpdate[m];\n b._dirty = false;\n\n for (let n = 0; n < numWriters; ++n) {\n writers[n](this, context, vafWriters, b);\n }\n }\n this._vaf.commit();\n } else {\n for (let h = 0; h < pointPrimitivesToUpdateLength; ++h) {\n const bb = pointPrimitivesToUpdate[h];\n bb._dirty = false;\n\n for (let o = 0; o < numWriters; ++o) {\n writers[o](this, context, vafWriters, bb);\n }\n this._vaf.subCommit(bb._index, 1);\n }\n this._vaf.endSubCommits();\n }\n\n this._pointPrimitivesToUpdateIndex = 0;\n }\n\n // If the number of total pointPrimitives ever shrinks considerably\n // Truncate pointPrimitivesToUpdate so that we free memory that we're\n // not going to be using.\n if (pointPrimitivesToUpdateLength > pointPrimitivesLength * 1.5) {\n pointPrimitivesToUpdate.length = pointPrimitivesLength;\n }\n\n if (!defined(this._vaf) || !defined(this._vaf.va)) {\n return;\n }\n\n if (this._boundingVolumeDirty) {\n this._boundingVolumeDirty = false;\n BoundingSphere.transform(\n this._baseVolume,\n this.modelMatrix,\n this._baseVolumeWC\n );\n }\n\n let boundingVolume;\n let modelMatrix = Matrix4.IDENTITY;\n if (frameState.mode === SceneMode.SCENE3D) {\n modelMatrix = this.modelMatrix;\n boundingVolume = BoundingSphere.clone(\n this._baseVolumeWC,\n this._boundingVolume\n );\n } else {\n boundingVolume = BoundingSphere.clone(\n this._baseVolume2D,\n this._boundingVolume\n );\n }\n updateBoundingVolume(this, frameState, boundingVolume);\n\n const blendOptionChanged = this._blendOption !== this.blendOption;\n this._blendOption = this.blendOption;\n\n if (blendOptionChanged) {\n if (\n this._blendOption === BlendOption.OPAQUE ||\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT\n ) {\n this._rsOpaque = RenderState.fromCache({\n depthTest: {\n enabled: true,\n func: WebGLConstants.LEQUAL,\n },\n depthMask: true,\n });\n } else {\n this._rsOpaque = undefined;\n }\n\n if (\n this._blendOption === BlendOption.TRANSLUCENT ||\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT\n ) {\n this._rsTranslucent = RenderState.fromCache({\n depthTest: {\n enabled: true,\n func: WebGLConstants.LEQUAL,\n },\n depthMask: false,\n blending: BlendingState.ALPHA_BLEND,\n });\n } else {\n this._rsTranslucent = undefined;\n }\n }\n\n this._shaderDisableDepthDistance =\n this._shaderDisableDepthDistance ||\n frameState.minimumDisableDepthTestDistance !== 0.0;\n let vs;\n let fs;\n\n if (\n blendOptionChanged ||\n (this._shaderScaleByDistance && !this._compiledShaderScaleByDistance) ||\n (this._shaderTranslucencyByDistance &&\n !this._compiledShaderTranslucencyByDistance) ||\n (this._shaderDistanceDisplayCondition &&\n !this._compiledShaderDistanceDisplayCondition) ||\n this._shaderDisableDepthDistance !==\n this._compiledShaderDisableDepthDistance\n ) {\n vs = new ShaderSource({\n sources: [PointPrimitiveCollectionVS],\n });\n if (this._shaderScaleByDistance) {\n vs.defines.push(\"EYE_DISTANCE_SCALING\");\n }\n if (this._shaderTranslucencyByDistance) {\n vs.defines.push(\"EYE_DISTANCE_TRANSLUCENCY\");\n }\n if (this._shaderDistanceDisplayCondition) {\n vs.defines.push(\"DISTANCE_DISPLAY_CONDITION\");\n }\n if (this._shaderDisableDepthDistance) {\n vs.defines.push(\"DISABLE_DEPTH_DISTANCE\");\n }\n\n if (this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {\n fs = new ShaderSource({\n defines: [\"OPAQUE\"],\n sources: [PointPrimitiveCollectionFS],\n });\n this._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._sp,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n\n fs = new ShaderSource({\n defines: [\"TRANSLUCENT\"],\n sources: [PointPrimitiveCollectionFS],\n });\n this._spTranslucent = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._spTranslucent,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n if (this._blendOption === BlendOption.OPAQUE) {\n fs = new ShaderSource({\n sources: [PointPrimitiveCollectionFS],\n });\n this._sp = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._sp,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n if (this._blendOption === BlendOption.TRANSLUCENT) {\n fs = new ShaderSource({\n sources: [PointPrimitiveCollectionFS],\n });\n this._spTranslucent = ShaderProgram.replaceCache({\n context: context,\n shaderProgram: this._spTranslucent,\n vertexShaderSource: vs,\n fragmentShaderSource: fs,\n attributeLocations: attributeLocations,\n });\n }\n\n this._compiledShaderScaleByDistance = this._shaderScaleByDistance;\n this._compiledShaderTranslucencyByDistance = this._shaderTranslucencyByDistance;\n this._compiledShaderDistanceDisplayCondition = this._shaderDistanceDisplayCondition;\n this._compiledShaderDisableDepthDistance = this._shaderDisableDepthDistance;\n }\n\n let va;\n let vaLength;\n let command;\n let j;\n\n const commandList = frameState.commandList;\n\n if (pass.render || picking) {\n const colorList = this._colorCommands;\n\n const opaque = this._blendOption === BlendOption.OPAQUE;\n const opaqueAndTranslucent =\n this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT;\n\n va = this._vaf.va;\n vaLength = va.length;\n\n colorList.length = vaLength;\n const totalLength = opaqueAndTranslucent ? vaLength * 2 : vaLength;\n for (j = 0; j < totalLength; ++j) {\n const opaqueCommand = opaque || (opaqueAndTranslucent && j % 2 === 0);\n\n command = colorList[j];\n if (!defined(command)) {\n command = colorList[j] = new DrawCommand();\n }\n\n command.primitiveType = PrimitiveType.POINTS;\n command.pass =\n opaqueCommand || !opaqueAndTranslucent ? Pass.OPAQUE : Pass.TRANSLUCENT;\n command.owner = this;\n\n const index = opaqueAndTranslucent ? Math.floor(j / 2.0) : j;\n command.boundingVolume = boundingVolume;\n command.modelMatrix = modelMatrix;\n command.shaderProgram = opaqueCommand ? this._sp : this._spTranslucent;\n command.uniformMap = this._uniforms;\n command.vertexArray = va[index].va;\n command.renderState = opaqueCommand\n ? this._rsOpaque\n : this._rsTranslucent;\n command.debugShowBoundingVolume = this.debugShowBoundingVolume;\n command.pickId = \"v_pickColor\";\n\n commandList.push(command);\n }\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see PointPrimitiveCollection#destroy\n */\nPointPrimitiveCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * pointPrimitives = pointPrimitives && pointPrimitives.destroy();\n *\n * @see PointPrimitiveCollection#isDestroyed\n */\nPointPrimitiveCollection.prototype.destroy = function () {\n this._sp = this._sp && this._sp.destroy();\n this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy();\n this._spPick = this._spPick && this._spPick.destroy();\n this._vaf = this._vaf && this._vaf.destroy();\n destroyPointPrimitives(this._pointPrimitives);\n\n return destroyObject(this);\n};\nexport default PointPrimitiveCollection;\n", "\nconst ARRAY_TYPES = [\n Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array,\n Int32Array, Uint32Array, Float32Array, Float64Array\n];\n\n/** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */\n\nconst VERSION = 1; // serialized format version\nconst HEADER_SIZE = 8;\n\nexport default class KDBush {\n\n /**\n * Creates an index from raw `ArrayBuffer` data.\n * @param {ArrayBuffer} data\n */\n static from(data) {\n if (!(data instanceof ArrayBuffer)) {\n throw new Error('Data must be an instance of ArrayBuffer.');\n }\n const [magic, versionAndType] = new Uint8Array(data, 0, 2);\n if (magic !== 0xdb) {\n throw new Error('Data does not appear to be in a KDBush format.');\n }\n const version = versionAndType >> 4;\n if (version !== VERSION) {\n throw new Error(`Got v${version} data when expected v${VERSION}.`);\n }\n const ArrayType = ARRAY_TYPES[versionAndType & 0x0f];\n if (!ArrayType) {\n throw new Error('Unrecognized array type.');\n }\n const [nodeSize] = new Uint16Array(data, 2, 1);\n const [numItems] = new Uint32Array(data, 4, 1);\n\n return new KDBush(numItems, nodeSize, ArrayType, data);\n }\n\n /**\n * Creates an index that will hold a given number of items.\n * @param {number} numItems\n * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).\n * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).\n * @param {ArrayBuffer} [data] (For internal use only)\n */\n constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {\n if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);\n\n this.numItems = +numItems;\n this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);\n this.ArrayType = ArrayType;\n this.IndexArrayType = numItems < 65536 ? Uint16Array : Uint32Array;\n\n const arrayTypeIndex = ARRAY_TYPES.indexOf(this.ArrayType);\n const coordsByteSize = numItems * 2 * this.ArrayType.BYTES_PER_ELEMENT;\n const idsByteSize = numItems * this.IndexArrayType.BYTES_PER_ELEMENT;\n const padCoords = (8 - idsByteSize % 8) % 8;\n\n if (arrayTypeIndex < 0) {\n throw new Error(`Unexpected typed array class: ${ArrayType}.`);\n }\n\n if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer\n this.data = data;\n this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);\n this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = numItems * 2;\n this._finished = true;\n } else { // initialize a new index\n this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);\n this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);\n this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);\n this._pos = 0;\n this._finished = false;\n\n // set header\n new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);\n new Uint16Array(this.data, 2, 1)[0] = nodeSize;\n new Uint32Array(this.data, 4, 1)[0] = numItems;\n }\n }\n\n /**\n * Add a point to the index.\n * @param {number} x\n * @param {number} y\n * @returns {number} An incremental index associated with the added item (starting from `0`).\n */\n add(x, y) {\n const index = this._pos >> 1;\n this.ids[index] = index;\n this.coords[this._pos++] = x;\n this.coords[this._pos++] = y;\n return index;\n }\n\n /**\n * Perform indexing of the added points.\n */\n finish() {\n const numAdded = this._pos >> 1;\n if (numAdded !== this.numItems) {\n throw new Error(`Added ${numAdded} items when expected ${this.numItems}.`);\n }\n // kd-sort both arrays for efficient search\n sort(this.ids, this.coords, this.nodeSize, 0, this.numItems - 1, 0);\n\n this._finished = true;\n return this;\n }\n\n /**\n * Search the index for items within a given bounding box.\n * @param {number} minX\n * @param {number} minY\n * @param {number} maxX\n * @param {number} maxY\n * @returns {number[]} An array of indices correponding to the found items.\n */\n range(minX, minY, maxX, maxY) {\n if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');\n\n const {ids, coords, nodeSize} = this;\n const stack = [0, ids.length - 1, 0];\n const result = [];\n\n // recursively search for items in range in the kd-sorted arrays\n while (stack.length) {\n const axis = stack.pop() || 0;\n const right = stack.pop() || 0;\n const left = stack.pop() || 0;\n\n // if we reached \"tree node\", search linearly\n if (right - left <= nodeSize) {\n for (let i = left; i <= right; i++) {\n const x = coords[2 * i];\n const y = coords[2 * i + 1];\n if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[i]);\n }\n continue;\n }\n\n // otherwise find the middle index\n const m = (left + right) >> 1;\n\n // include the middle item if it's in range\n const x = coords[2 * m];\n const y = coords[2 * m + 1];\n if (x >= minX && x <= maxX && y >= minY && y <= maxY) result.push(ids[m]);\n\n // queue search in halves that intersect the query\n if (axis === 0 ? minX <= x : minY <= y) {\n stack.push(left);\n stack.push(m - 1);\n stack.push(1 - axis);\n }\n if (axis === 0 ? maxX >= x : maxY >= y) {\n stack.push(m + 1);\n stack.push(right);\n stack.push(1 - axis);\n }\n }\n\n return result;\n }\n\n /**\n * Search the index for items within a given radius.\n * @param {number} qx\n * @param {number} qy\n * @param {number} r Query radius.\n * @returns {number[]} An array of indices correponding to the found items.\n */\n within(qx, qy, r) {\n if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');\n\n const {ids, coords, nodeSize} = this;\n const stack = [0, ids.length - 1, 0];\n const result = [];\n const r2 = r * r;\n\n // recursively search for items within radius in the kd-sorted arrays\n while (stack.length) {\n const axis = stack.pop() || 0;\n const right = stack.pop() || 0;\n const left = stack.pop() || 0;\n\n // if we reached \"tree node\", search linearly\n if (right - left <= nodeSize) {\n for (let i = left; i <= right; i++) {\n if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);\n }\n continue;\n }\n\n // otherwise find the middle index\n const m = (left + right) >> 1;\n\n // include the middle item if it's in range\n const x = coords[2 * m];\n const y = coords[2 * m + 1];\n if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);\n\n // queue search in halves that intersect the query\n if (axis === 0 ? qx - r <= x : qy - r <= y) {\n stack.push(left);\n stack.push(m - 1);\n stack.push(1 - axis);\n }\n if (axis === 0 ? qx + r >= x : qy + r >= y) {\n stack.push(m + 1);\n stack.push(right);\n stack.push(1 - axis);\n }\n }\n\n return result;\n }\n}\n\n/**\n * @param {Uint16Array | Uint32Array} ids\n * @param {InstanceType} coords\n * @param {number} nodeSize\n * @param {number} left\n * @param {number} right\n * @param {number} axis\n */\nfunction sort(ids, coords, nodeSize, left, right, axis) {\n if (right - left <= nodeSize) return;\n\n const m = (left + right) >> 1; // middle index\n\n // sort ids and coords around the middle index so that the halves lie\n // either left/right or top/bottom correspondingly (taking turns)\n select(ids, coords, m, left, right, axis);\n\n // recursively kd-sort first half and second half on the opposite axis\n sort(ids, coords, nodeSize, left, m - 1, 1 - axis);\n sort(ids, coords, nodeSize, m + 1, right, 1 - axis);\n}\n\n/**\n * Custom Floyd-Rivest selection algorithm: sort ids and coords so that\n * [left..k-1] items are smaller than k-th item (on either x or y axis)\n * @param {Uint16Array | Uint32Array} ids\n * @param {InstanceType} coords\n * @param {number} k\n * @param {number} left\n * @param {number} right\n * @param {number} axis\n */\nfunction select(ids, coords, k, left, right, axis) {\n\n while (right > left) {\n if (right - left > 600) {\n const n = right - left + 1;\n const m = k - left + 1;\n const z = Math.log(n);\n const s = 0.5 * Math.exp(2 * z / 3);\n const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n select(ids, coords, k, newLeft, newRight, axis);\n }\n\n const t = coords[2 * k + axis];\n let i = left;\n let j = right;\n\n swapItem(ids, coords, left, k);\n if (coords[2 * right + axis] > t) swapItem(ids, coords, left, right);\n\n while (i < j) {\n swapItem(ids, coords, i, j);\n i++;\n j--;\n while (coords[2 * i + axis] < t) i++;\n while (coords[2 * j + axis] > t) j--;\n }\n\n if (coords[2 * left + axis] === t) swapItem(ids, coords, left, j);\n else {\n j++;\n swapItem(ids, coords, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\n/**\n * @param {Uint16Array | Uint32Array} ids\n * @param {InstanceType} coords\n * @param {number} i\n * @param {number} j\n */\nfunction swapItem(ids, coords, i, j) {\n swap(ids, i, j);\n swap(coords, 2 * i, 2 * j);\n swap(coords, 2 * i + 1, 2 * j + 1);\n}\n\n/**\n * @param {InstanceType} arr\n * @param {number} i\n * @param {number} j\n */\nfunction swap(arr, i, j) {\n const tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n\n/**\n * @param {number} ax\n * @param {number} ay\n * @param {number} bx\n * @param {number} by\n */\nfunction sqDist(ax, ay, bx, by) {\n const dx = ax - bx;\n const dy = ay - by;\n return dx * dx + dy * dy;\n}\n", "import BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport EllipsoidalOccluder from \"../Core/EllipsoidalOccluder.js\";\nimport Event from \"../Core/Event.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Billboard from \"../Scene/Billboard.js\";\nimport BillboardCollection from \"../Scene/BillboardCollection.js\";\nimport Label from \"../Scene/Label.js\";\nimport LabelCollection from \"../Scene/LabelCollection.js\";\nimport PointPrimitive from \"../Scene/PointPrimitive.js\";\nimport PointPrimitiveCollection from \"../Scene/PointPrimitiveCollection.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport KDBush from \"kdbush\";\n\n/**\n * Defines how screen space objects (billboards, points, labels) are clustered.\n *\n * @param {object} [options] An object with the following properties:\n * @param {boolean} [options.enabled=false] Whether or not to enable clustering.\n * @param {number} [options.pixelRange=80] The pixel range to extend the screen space bounding box.\n * @param {number} [options.minimumClusterSize=2] The minimum number of screen space objects that can be clustered.\n * @param {boolean} [options.clusterBillboards=true] Whether or not to cluster the billboards of an entity.\n * @param {boolean} [options.clusterLabels=true] Whether or not to cluster the labels of an entity.\n * @param {boolean} [options.clusterPoints=true] Whether or not to cluster the points of an entity.\n * @param {boolean} [options.show=true] Determines if the entities in the cluster will be shown.\n *\n * @alias EntityCluster\n * @constructor\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Clustering.html|Cesium Sandcastle Clustering Demo}\n */\nfunction EntityCluster(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._enabled = defaultValue(options.enabled, false);\n this._pixelRange = defaultValue(options.pixelRange, 80);\n this._minimumClusterSize = defaultValue(options.minimumClusterSize, 2);\n this._clusterBillboards = defaultValue(options.clusterBillboards, true);\n this._clusterLabels = defaultValue(options.clusterLabels, true);\n this._clusterPoints = defaultValue(options.clusterPoints, true);\n\n this._labelCollection = undefined;\n this._billboardCollection = undefined;\n this._pointCollection = undefined;\n\n this._clusterBillboardCollection = undefined;\n this._clusterLabelCollection = undefined;\n this._clusterPointCollection = undefined;\n\n this._collectionIndicesByEntity = {};\n\n this._unusedLabelIndices = [];\n this._unusedBillboardIndices = [];\n this._unusedPointIndices = [];\n\n this._previousClusters = [];\n this._previousHeight = undefined;\n\n this._enabledDirty = false;\n this._clusterDirty = false;\n\n this._cluster = undefined;\n this._removeEventListener = undefined;\n\n this._clusterEvent = new Event();\n\n /**\n * Determines if entities in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n}\n\nfunction expandBoundingBox(bbox, pixelRange) {\n bbox.x -= pixelRange;\n bbox.y -= pixelRange;\n bbox.width += pixelRange * 2.0;\n bbox.height += pixelRange * 2.0;\n}\n\nconst labelBoundingBoxScratch = new BoundingRectangle();\n\nfunction getBoundingBox(item, coord, pixelRange, entityCluster, result) {\n if (defined(item._labelCollection) && entityCluster._clusterLabels) {\n result = Label.getScreenSpaceBoundingBox(item, coord, result);\n } else if (\n defined(item._billboardCollection) &&\n entityCluster._clusterBillboards\n ) {\n result = Billboard.getScreenSpaceBoundingBox(item, coord, result);\n } else if (\n defined(item._pointPrimitiveCollection) &&\n entityCluster._clusterPoints\n ) {\n result = PointPrimitive.getScreenSpaceBoundingBox(item, coord, result);\n }\n\n expandBoundingBox(result, pixelRange);\n\n if (\n entityCluster._clusterLabels &&\n !defined(item._labelCollection) &&\n defined(item.id) &&\n hasLabelIndex(entityCluster, item.id.id) &&\n defined(item.id._label)\n ) {\n const labelIndex =\n entityCluster._collectionIndicesByEntity[item.id.id].labelIndex;\n const label = entityCluster._labelCollection.get(labelIndex);\n const labelBBox = Label.getScreenSpaceBoundingBox(\n label,\n coord,\n labelBoundingBoxScratch\n );\n expandBoundingBox(labelBBox, pixelRange);\n result = BoundingRectangle.union(result, labelBBox, result);\n }\n\n return result;\n}\n\nfunction addNonClusteredItem(item, entityCluster) {\n item.clusterShow = true;\n\n if (\n !defined(item._labelCollection) &&\n defined(item.id) &&\n hasLabelIndex(entityCluster, item.id.id) &&\n defined(item.id._label)\n ) {\n const labelIndex =\n entityCluster._collectionIndicesByEntity[item.id.id].labelIndex;\n const label = entityCluster._labelCollection.get(labelIndex);\n label.clusterShow = true;\n }\n}\n\nfunction addCluster(position, numPoints, ids, entityCluster) {\n const cluster = {\n billboard: entityCluster._clusterBillboardCollection.add(),\n label: entityCluster._clusterLabelCollection.add(),\n point: entityCluster._clusterPointCollection.add(),\n };\n\n cluster.billboard.show = false;\n cluster.point.show = false;\n cluster.label.show = true;\n cluster.label.text = numPoints.toLocaleString();\n cluster.label.id = ids;\n cluster.billboard.position = cluster.label.position = cluster.point.position = position;\n\n entityCluster._clusterEvent.raiseEvent(ids, cluster);\n}\n\nfunction hasLabelIndex(entityCluster, entityId) {\n return (\n defined(entityCluster) &&\n defined(entityCluster._collectionIndicesByEntity[entityId]) &&\n defined(entityCluster._collectionIndicesByEntity[entityId].labelIndex)\n );\n}\n\nfunction getScreenSpacePositions(\n collection,\n points,\n scene,\n occluder,\n entityCluster\n) {\n if (!defined(collection)) {\n return;\n }\n\n const length = collection.length;\n for (let i = 0; i < length; ++i) {\n const item = collection.get(i);\n item.clusterShow = false;\n\n if (\n !item.show ||\n (entityCluster._scene.mode === SceneMode.SCENE3D &&\n !occluder.isPointVisible(item.position))\n ) {\n continue;\n }\n\n const canClusterLabels =\n entityCluster._clusterLabels && defined(item._labelCollection);\n const canClusterBillboards =\n entityCluster._clusterBillboards && defined(item.id._billboard);\n const canClusterPoints =\n entityCluster._clusterPoints && defined(item.id._point);\n if (canClusterLabels && (canClusterPoints || canClusterBillboards)) {\n continue;\n }\n\n const coord = item.computeScreenSpacePosition(scene);\n if (!defined(coord)) {\n continue;\n }\n\n points.push({\n index: i,\n collection: collection,\n clustered: false,\n coord: coord,\n });\n }\n}\n\nconst pointBoundinRectangleScratch = new BoundingRectangle();\nconst totalBoundingRectangleScratch = new BoundingRectangle();\nconst neighborBoundingRectangleScratch = new BoundingRectangle();\n\nfunction createDeclutterCallback(entityCluster) {\n return function (amount) {\n if ((defined(amount) && amount < 0.05) || !entityCluster.enabled) {\n return;\n }\n\n const scene = entityCluster._scene;\n\n const labelCollection = entityCluster._labelCollection;\n const billboardCollection = entityCluster._billboardCollection;\n const pointCollection = entityCluster._pointCollection;\n\n if (\n (!defined(labelCollection) &&\n !defined(billboardCollection) &&\n !defined(pointCollection)) ||\n (!entityCluster._clusterBillboards &&\n !entityCluster._clusterLabels &&\n !entityCluster._clusterPoints)\n ) {\n return;\n }\n\n let clusteredLabelCollection = entityCluster._clusterLabelCollection;\n let clusteredBillboardCollection =\n entityCluster._clusterBillboardCollection;\n let clusteredPointCollection = entityCluster._clusterPointCollection;\n\n if (defined(clusteredLabelCollection)) {\n clusteredLabelCollection.removeAll();\n } else {\n clusteredLabelCollection = entityCluster._clusterLabelCollection = new LabelCollection(\n {\n scene: scene,\n }\n );\n }\n\n if (defined(clusteredBillboardCollection)) {\n clusteredBillboardCollection.removeAll();\n } else {\n clusteredBillboardCollection = entityCluster._clusterBillboardCollection = new BillboardCollection(\n {\n scene: scene,\n }\n );\n }\n\n if (defined(clusteredPointCollection)) {\n clusteredPointCollection.removeAll();\n } else {\n clusteredPointCollection = entityCluster._clusterPointCollection = new PointPrimitiveCollection();\n }\n\n const pixelRange = entityCluster._pixelRange;\n const minimumClusterSize = entityCluster._minimumClusterSize;\n\n const clusters = entityCluster._previousClusters;\n const newClusters = [];\n\n const previousHeight = entityCluster._previousHeight;\n const currentHeight = scene.camera.positionCartographic.height;\n\n const ellipsoid = scene.mapProjection.ellipsoid;\n const cameraPosition = scene.camera.positionWC;\n const occluder = new EllipsoidalOccluder(ellipsoid, cameraPosition);\n\n const points = [];\n if (entityCluster._clusterLabels) {\n getScreenSpacePositions(\n labelCollection,\n points,\n scene,\n occluder,\n entityCluster\n );\n }\n if (entityCluster._clusterBillboards) {\n getScreenSpacePositions(\n billboardCollection,\n points,\n scene,\n occluder,\n entityCluster\n );\n }\n if (entityCluster._clusterPoints) {\n getScreenSpacePositions(\n pointCollection,\n points,\n scene,\n occluder,\n entityCluster\n );\n }\n\n let i;\n let j;\n let length;\n let bbox;\n let neighbors;\n let neighborLength;\n let neighborIndex;\n let neighborPoint;\n let ids;\n let numPoints;\n\n let collection;\n let collectionIndex;\n\n if (points.length > 0) {\n const index = new KDBush(points.length, 64, Uint32Array);\n for (let p = 0; p < points.length; ++p) {\n index.add(points[p].coord.x, points[p].coord.y);\n }\n index.finish();\n\n if (currentHeight < previousHeight) {\n length = clusters.length;\n for (i = 0; i < length; ++i) {\n const cluster = clusters[i];\n\n if (!occluder.isPointVisible(cluster.position)) {\n continue;\n }\n\n const coord = Billboard._computeScreenSpacePosition(\n Matrix4.IDENTITY,\n cluster.position,\n Cartesian3.ZERO,\n Cartesian2.ZERO,\n scene\n );\n if (!defined(coord)) {\n continue;\n }\n\n const factor = 1.0 - currentHeight / previousHeight;\n let width = (cluster.width = cluster.width * factor);\n let height = (cluster.height = cluster.height * factor);\n\n width = Math.max(width, cluster.minimumWidth);\n height = Math.max(height, cluster.minimumHeight);\n\n const minX = coord.x - width * 0.5;\n const minY = coord.y - height * 0.5;\n const maxX = coord.x + width;\n const maxY = coord.y + height;\n\n neighbors = index.range(minX, minY, maxX, maxY);\n neighborLength = neighbors.length;\n numPoints = 0;\n ids = [];\n\n for (j = 0; j < neighborLength; ++j) {\n neighborIndex = neighbors[j];\n neighborPoint = points[neighborIndex];\n if (!neighborPoint.clustered) {\n ++numPoints;\n\n collection = neighborPoint.collection;\n collectionIndex = neighborPoint.index;\n ids.push(collection.get(collectionIndex).id);\n }\n }\n\n if (numPoints >= minimumClusterSize) {\n addCluster(cluster.position, numPoints, ids, entityCluster);\n newClusters.push(cluster);\n\n for (j = 0; j < neighborLength; ++j) {\n points[neighbors[j]].clustered = true;\n }\n }\n }\n }\n\n length = points.length;\n for (i = 0; i < length; ++i) {\n const point = points[i];\n if (point.clustered) {\n continue;\n }\n\n point.clustered = true;\n\n collection = point.collection;\n collectionIndex = point.index;\n\n const item = collection.get(collectionIndex);\n bbox = getBoundingBox(\n item,\n point.coord,\n pixelRange,\n entityCluster,\n pointBoundinRectangleScratch\n );\n const totalBBox = BoundingRectangle.clone(\n bbox,\n totalBoundingRectangleScratch\n );\n\n neighbors = index.range(\n bbox.x,\n bbox.y,\n bbox.x + bbox.width,\n bbox.y + bbox.height\n );\n neighborLength = neighbors.length;\n\n const clusterPosition = Cartesian3.clone(item.position);\n numPoints = 1;\n ids = [item.id];\n\n for (j = 0; j < neighborLength; ++j) {\n neighborIndex = neighbors[j];\n neighborPoint = points[neighborIndex];\n if (!neighborPoint.clustered) {\n const neighborItem = neighborPoint.collection.get(\n neighborPoint.index\n );\n const neighborBBox = getBoundingBox(\n neighborItem,\n neighborPoint.coord,\n pixelRange,\n entityCluster,\n neighborBoundingRectangleScratch\n );\n\n Cartesian3.add(\n neighborItem.position,\n clusterPosition,\n clusterPosition\n );\n\n BoundingRectangle.union(totalBBox, neighborBBox, totalBBox);\n ++numPoints;\n\n ids.push(neighborItem.id);\n }\n }\n\n if (numPoints >= minimumClusterSize) {\n const position = Cartesian3.multiplyByScalar(\n clusterPosition,\n 1.0 / numPoints,\n clusterPosition\n );\n addCluster(position, numPoints, ids, entityCluster);\n newClusters.push({\n position: position,\n width: totalBBox.width,\n height: totalBBox.height,\n minimumWidth: bbox.width,\n minimumHeight: bbox.height,\n });\n\n for (j = 0; j < neighborLength; ++j) {\n points[neighbors[j]].clustered = true;\n }\n } else {\n addNonClusteredItem(item, entityCluster);\n }\n }\n }\n\n if (clusteredLabelCollection.length === 0) {\n clusteredLabelCollection.destroy();\n entityCluster._clusterLabelCollection = undefined;\n }\n\n if (clusteredBillboardCollection.length === 0) {\n clusteredBillboardCollection.destroy();\n entityCluster._clusterBillboardCollection = undefined;\n }\n\n if (clusteredPointCollection.length === 0) {\n clusteredPointCollection.destroy();\n entityCluster._clusterPointCollection = undefined;\n }\n\n entityCluster._previousClusters = newClusters;\n entityCluster._previousHeight = currentHeight;\n };\n}\n\nEntityCluster.prototype._initialize = function (scene) {\n this._scene = scene;\n\n const cluster = createDeclutterCallback(this);\n this._cluster = cluster;\n this._removeEventListener = scene.camera.changed.addEventListener(cluster);\n};\n\nObject.defineProperties(EntityCluster.prototype, {\n /**\n * Gets or sets whether clustering is enabled.\n * @memberof EntityCluster.prototype\n * @type {boolean}\n */\n enabled: {\n get: function () {\n return this._enabled;\n },\n set: function (value) {\n this._enabledDirty = value !== this._enabled;\n this._enabled = value;\n },\n },\n /**\n * Gets or sets the pixel range to extend the screen space bounding box.\n * @memberof EntityCluster.prototype\n * @type {number}\n */\n pixelRange: {\n get: function () {\n return this._pixelRange;\n },\n set: function (value) {\n this._clusterDirty = this._clusterDirty || value !== this._pixelRange;\n this._pixelRange = value;\n },\n },\n /**\n * Gets or sets the minimum number of screen space objects that can be clustered.\n * @memberof EntityCluster.prototype\n * @type {number}\n */\n minimumClusterSize: {\n get: function () {\n return this._minimumClusterSize;\n },\n set: function (value) {\n this._clusterDirty =\n this._clusterDirty || value !== this._minimumClusterSize;\n this._minimumClusterSize = value;\n },\n },\n /**\n * Gets the event that will be raised when a new cluster will be displayed. The signature of the event listener is {@link EntityCluster.newClusterCallback}.\n * @memberof EntityCluster.prototype\n * @type {Event}\n */\n clusterEvent: {\n get: function () {\n return this._clusterEvent;\n },\n },\n /**\n * Gets or sets whether clustering billboard entities is enabled.\n * @memberof EntityCluster.prototype\n * @type {boolean}\n */\n clusterBillboards: {\n get: function () {\n return this._clusterBillboards;\n },\n set: function (value) {\n this._clusterDirty =\n this._clusterDirty || value !== this._clusterBillboards;\n this._clusterBillboards = value;\n },\n },\n /**\n * Gets or sets whether clustering labels entities is enabled.\n * @memberof EntityCluster.prototype\n * @type {boolean}\n */\n clusterLabels: {\n get: function () {\n return this._clusterLabels;\n },\n set: function (value) {\n this._clusterDirty = this._clusterDirty || value !== this._clusterLabels;\n this._clusterLabels = value;\n },\n },\n /**\n * Gets or sets whether clustering point entities is enabled.\n * @memberof EntityCluster.prototype\n * @type {boolean}\n */\n clusterPoints: {\n get: function () {\n return this._clusterPoints;\n },\n set: function (value) {\n this._clusterDirty = this._clusterDirty || value !== this._clusterPoints;\n this._clusterPoints = value;\n },\n },\n});\n\nfunction createGetEntity(\n collectionProperty,\n CollectionConstructor,\n unusedIndicesProperty,\n entityIndexProperty\n) {\n return function (entity) {\n let collection = this[collectionProperty];\n\n if (!defined(this._collectionIndicesByEntity)) {\n this._collectionIndicesByEntity = {};\n }\n\n let entityIndices = this._collectionIndicesByEntity[entity.id];\n\n if (!defined(entityIndices)) {\n entityIndices = this._collectionIndicesByEntity[entity.id] = {\n billboardIndex: undefined,\n labelIndex: undefined,\n pointIndex: undefined,\n };\n }\n\n if (defined(collection) && defined(entityIndices[entityIndexProperty])) {\n return collection.get(entityIndices[entityIndexProperty]);\n }\n\n if (!defined(collection)) {\n collection = this[collectionProperty] = new CollectionConstructor({\n scene: this._scene,\n });\n }\n\n let index;\n let entityItem;\n\n const unusedIndices = this[unusedIndicesProperty];\n if (unusedIndices.length > 0) {\n index = unusedIndices.pop();\n entityItem = collection.get(index);\n } else {\n entityItem = collection.add();\n index = collection.length - 1;\n }\n\n entityIndices[entityIndexProperty] = index;\n\n const that = this;\n Promise.resolve().then(function () {\n that._clusterDirty = true;\n });\n\n return entityItem;\n };\n}\n\nfunction removeEntityIndicesIfUnused(entityCluster, entityId) {\n const indices = entityCluster._collectionIndicesByEntity[entityId];\n\n if (\n !defined(indices.billboardIndex) &&\n !defined(indices.labelIndex) &&\n !defined(indices.pointIndex)\n ) {\n delete entityCluster._collectionIndicesByEntity[entityId];\n }\n}\n\n/**\n * Returns a new {@link Label}.\n * @param {Entity} entity The entity that will use the returned {@link Label} for visualization.\n * @returns {Label} The label that will be used to visualize an entity.\n *\n * @private\n */\nEntityCluster.prototype.getLabel = createGetEntity(\n \"_labelCollection\",\n LabelCollection,\n \"_unusedLabelIndices\",\n \"labelIndex\"\n);\n\n/**\n * Removes the {@link Label} associated with an entity so it can be reused by another entity.\n * @param {Entity} entity The entity that will uses the returned {@link Label} for visualization.\n *\n * @private\n */\nEntityCluster.prototype.removeLabel = function (entity) {\n const entityIndices =\n this._collectionIndicesByEntity &&\n this._collectionIndicesByEntity[entity.id];\n if (\n !defined(this._labelCollection) ||\n !defined(entityIndices) ||\n !defined(entityIndices.labelIndex)\n ) {\n return;\n }\n\n const index = entityIndices.labelIndex;\n entityIndices.labelIndex = undefined;\n removeEntityIndicesIfUnused(this, entity.id);\n\n const label = this._labelCollection.get(index);\n label.show = false;\n label.text = \"\";\n label.id = undefined;\n\n this._unusedLabelIndices.push(index);\n\n this._clusterDirty = true;\n};\n\n/**\n * Returns a new {@link Billboard}.\n * @param {Entity} entity The entity that will use the returned {@link Billboard} for visualization.\n * @returns {Billboard} The label that will be used to visualize an entity.\n *\n * @private\n */\nEntityCluster.prototype.getBillboard = createGetEntity(\n \"_billboardCollection\",\n BillboardCollection,\n \"_unusedBillboardIndices\",\n \"billboardIndex\"\n);\n\n/**\n * Removes the {@link Billboard} associated with an entity so it can be reused by another entity.\n * @param {Entity} entity The entity that will uses the returned {@link Billboard} for visualization.\n *\n * @private\n */\nEntityCluster.prototype.removeBillboard = function (entity) {\n const entityIndices =\n this._collectionIndicesByEntity &&\n this._collectionIndicesByEntity[entity.id];\n if (\n !defined(this._billboardCollection) ||\n !defined(entityIndices) ||\n !defined(entityIndices.billboardIndex)\n ) {\n return;\n }\n\n const index = entityIndices.billboardIndex;\n entityIndices.billboardIndex = undefined;\n removeEntityIndicesIfUnused(this, entity.id);\n\n const billboard = this._billboardCollection.get(index);\n billboard.id = undefined;\n billboard.show = false;\n billboard.image = undefined;\n\n this._unusedBillboardIndices.push(index);\n\n this._clusterDirty = true;\n};\n\n/**\n * Returns a new {@link Point}.\n * @param {Entity} entity The entity that will use the returned {@link Point} for visualization.\n * @returns {Point} The label that will be used to visualize an entity.\n *\n * @private\n */\nEntityCluster.prototype.getPoint = createGetEntity(\n \"_pointCollection\",\n PointPrimitiveCollection,\n \"_unusedPointIndices\",\n \"pointIndex\"\n);\n\n/**\n * Removes the {@link Point} associated with an entity so it can be reused by another entity.\n * @param {Entity} entity The entity that will uses the returned {@link Point} for visualization.\n *\n * @private\n */\nEntityCluster.prototype.removePoint = function (entity) {\n const entityIndices =\n this._collectionIndicesByEntity &&\n this._collectionIndicesByEntity[entity.id];\n if (\n !defined(this._pointCollection) ||\n !defined(entityIndices) ||\n !defined(entityIndices.pointIndex)\n ) {\n return;\n }\n\n const index = entityIndices.pointIndex;\n entityIndices.pointIndex = undefined;\n removeEntityIndicesIfUnused(this, entity.id);\n\n const point = this._pointCollection.get(index);\n point.show = false;\n point.id = undefined;\n\n this._unusedPointIndices.push(index);\n\n this._clusterDirty = true;\n};\n\nfunction disableCollectionClustering(collection) {\n if (!defined(collection)) {\n return;\n }\n\n const length = collection.length;\n for (let i = 0; i < length; ++i) {\n collection.get(i).clusterShow = true;\n }\n}\n\nfunction updateEnable(entityCluster) {\n if (entityCluster.enabled) {\n return;\n }\n\n if (defined(entityCluster._clusterLabelCollection)) {\n entityCluster._clusterLabelCollection.destroy();\n }\n if (defined(entityCluster._clusterBillboardCollection)) {\n entityCluster._clusterBillboardCollection.destroy();\n }\n if (defined(entityCluster._clusterPointCollection)) {\n entityCluster._clusterPointCollection.destroy();\n }\n\n entityCluster._clusterLabelCollection = undefined;\n entityCluster._clusterBillboardCollection = undefined;\n entityCluster._clusterPointCollection = undefined;\n\n disableCollectionClustering(entityCluster._labelCollection);\n disableCollectionClustering(entityCluster._billboardCollection);\n disableCollectionClustering(entityCluster._pointCollection);\n}\n\n/**\n * Gets the draw commands for the clustered billboards/points/labels if enabled, otherwise,\n * queues the draw commands for billboards/points/labels created for entities.\n * @private\n */\nEntityCluster.prototype.update = function (frameState) {\n if (!this.show) {\n return;\n }\n\n // If clustering is enabled before the label collection is updated,\n // the glyphs haven't been created so the screen space bounding boxes\n // are incorrect.\n let commandList;\n if (\n defined(this._labelCollection) &&\n this._labelCollection.length > 0 &&\n this._labelCollection.get(0)._glyphs.length === 0\n ) {\n commandList = frameState.commandList;\n frameState.commandList = [];\n this._labelCollection.update(frameState);\n frameState.commandList = commandList;\n }\n\n // If clustering is enabled before the billboard collection is updated,\n // the images haven't been added to the image atlas so the screen space bounding boxes\n // are incorrect.\n if (\n defined(this._billboardCollection) &&\n this._billboardCollection.length > 0 &&\n !defined(this._billboardCollection.get(0).width)\n ) {\n commandList = frameState.commandList;\n frameState.commandList = [];\n this._billboardCollection.update(frameState);\n frameState.commandList = commandList;\n }\n\n if (this._enabledDirty) {\n this._enabledDirty = false;\n updateEnable(this);\n this._clusterDirty = true;\n }\n\n if (this._clusterDirty) {\n this._clusterDirty = false;\n this._cluster();\n }\n\n if (defined(this._clusterLabelCollection)) {\n this._clusterLabelCollection.update(frameState);\n }\n if (defined(this._clusterBillboardCollection)) {\n this._clusterBillboardCollection.update(frameState);\n }\n if (defined(this._clusterPointCollection)) {\n this._clusterPointCollection.update(frameState);\n }\n\n if (defined(this._labelCollection)) {\n this._labelCollection.update(frameState);\n }\n if (defined(this._billboardCollection)) {\n this._billboardCollection.update(frameState);\n }\n if (defined(this._pointCollection)) {\n this._pointCollection.update(frameState);\n }\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Unlike other objects that use WebGL resources, this object can be reused. For example, if a data source is removed\n * from a data source collection and added to another.\n *

\n */\nEntityCluster.prototype.destroy = function () {\n this._labelCollection =\n this._labelCollection && this._labelCollection.destroy();\n this._billboardCollection =\n this._billboardCollection && this._billboardCollection.destroy();\n this._pointCollection =\n this._pointCollection && this._pointCollection.destroy();\n\n this._clusterLabelCollection =\n this._clusterLabelCollection && this._clusterLabelCollection.destroy();\n this._clusterBillboardCollection =\n this._clusterBillboardCollection &&\n this._clusterBillboardCollection.destroy();\n this._clusterPointCollection =\n this._clusterPointCollection && this._clusterPointCollection.destroy();\n\n if (defined(this._removeEventListener)) {\n this._removeEventListener();\n this._removeEventListener = undefined;\n }\n\n this._labelCollection = undefined;\n this._billboardCollection = undefined;\n this._pointCollection = undefined;\n\n this._clusterBillboardCollection = undefined;\n this._clusterLabelCollection = undefined;\n this._clusterPointCollection = undefined;\n\n this._collectionIndicesByEntity = undefined;\n\n this._unusedLabelIndices = [];\n this._unusedBillboardIndices = [];\n this._unusedPointIndices = [];\n\n this._previousClusters = [];\n this._previousHeight = undefined;\n\n this._enabledDirty = false;\n this._pixelRangeDirty = false;\n this._minimumClusterSizeDirty = false;\n\n return undefined;\n};\n\n/**\n * A event listener function used to style clusters.\n * @callback EntityCluster.newClusterCallback\n *\n * @param {Entity[]} clusteredEntities An array of the entities contained in the cluster.\n * @param {object} cluster An object containing the Billboard, Label, and Point\n * primitives that represent this cluster of entities.\n * @param {Billboard} cluster.billboard\n * @param {Label} cluster.label\n * @param {PointPrimitive} cluster.point\n *\n * @example\n * // The default cluster values.\n * dataSource.clustering.clusterEvent.addEventListener(function(entities, cluster) {\n * cluster.label.show = true;\n * cluster.label.text = entities.length.toLocaleString();\n * });\n */\nexport default EntityCluster;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport DataSource from \"./DataSource.js\";\nimport EntityCluster from \"./EntityCluster.js\";\nimport EntityCollection from \"./EntityCollection.js\";\n\n/**\n * A {@link DataSource} implementation which can be used to manually manage a group of entities.\n *\n * @alias CustomDataSource\n * @constructor\n *\n * @param {string} [name] A human-readable name for this instance.\n *\n * @example\n * const dataSource = new Cesium.CustomDataSource('myData');\n *\n * const entity = dataSource.entities.add({\n * position : Cesium.Cartesian3.fromDegrees(1, 2, 0),\n * billboard : {\n * image : 'image.png'\n * }\n * });\n *\n * viewer.dataSources.add(dataSource);\n */\nfunction CustomDataSource(name) {\n this._name = name;\n this._clock = undefined;\n this._changed = new Event();\n this._error = new Event();\n this._isLoading = false;\n this._loading = new Event();\n this._entityCollection = new EntityCollection(this);\n this._entityCluster = new EntityCluster();\n}\n\nObject.defineProperties(CustomDataSource.prototype, {\n /**\n * Gets or sets a human-readable name for this instance.\n * @memberof CustomDataSource.prototype\n * @type {string}\n */\n name: {\n get: function () {\n return this._name;\n },\n set: function (value) {\n if (this._name !== value) {\n this._name = value;\n this._changed.raiseEvent(this);\n }\n },\n },\n /**\n * Gets or sets the clock for this instance.\n * @memberof CustomDataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n get: function () {\n return this._clock;\n },\n set: function (value) {\n if (this._clock !== value) {\n this._clock = value;\n this._changed.raiseEvent(this);\n }\n },\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof CustomDataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: function () {\n return this._entityCollection;\n },\n },\n /**\n * Gets or sets whether the data source is currently loading data.\n * @memberof CustomDataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: function () {\n return this._isLoading;\n },\n set: function (value) {\n DataSource.setLoading(this, value);\n },\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof CustomDataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: function () {\n return this._changed;\n },\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof CustomDataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: function () {\n return this._error;\n },\n },\n /**\n * Gets an event that will be raised when the data source either starts or stops loading.\n * @memberof CustomDataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: function () {\n return this._loading;\n },\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof CustomDataSource.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._entityCollection.show;\n },\n set: function (value) {\n this._entityCollection.show = value;\n },\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof CustomDataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: function () {\n return this._entityCluster;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value must be defined.\");\n }\n //>>includeEnd('debug');\n this._entityCluster = value;\n },\n },\n});\n\n/**\n * Updates the data source to the provided time. This function is optional and\n * is not required to be implemented. It is provided for data sources which\n * retrieve data based on the current animation time or scene state.\n * If implemented, update will be called by {@link DataSourceDisplay} once a frame.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nCustomDataSource.prototype.update = function (time) {\n return true;\n};\n\nexport default CustomDataSource;\n", "import CesiumMath from \"./Math.js\";\n\n/**\n * @private\n */\nconst CylinderGeometryLibrary = {};\n\n/**\n * @private\n */\nCylinderGeometryLibrary.computePositions = function (\n length,\n topRadius,\n bottomRadius,\n slices,\n fill\n) {\n const topZ = length * 0.5;\n const bottomZ = -topZ;\n\n const twoSlice = slices + slices;\n const size = fill ? 2 * twoSlice : twoSlice;\n const positions = new Float64Array(size * 3);\n let i;\n let index = 0;\n let tbIndex = 0;\n const bottomOffset = fill ? twoSlice * 3 : 0;\n const topOffset = fill ? (twoSlice + slices) * 3 : slices * 3;\n\n for (i = 0; i < slices; i++) {\n const angle = (i / slices) * CesiumMath.TWO_PI;\n const x = Math.cos(angle);\n const y = Math.sin(angle);\n const bottomX = x * bottomRadius;\n const bottomY = y * bottomRadius;\n const topX = x * topRadius;\n const topY = y * topRadius;\n\n positions[tbIndex + bottomOffset] = bottomX;\n positions[tbIndex + bottomOffset + 1] = bottomY;\n positions[tbIndex + bottomOffset + 2] = bottomZ;\n\n positions[tbIndex + topOffset] = topX;\n positions[tbIndex + topOffset + 1] = topY;\n positions[tbIndex + topOffset + 2] = topZ;\n tbIndex += 3;\n if (fill) {\n positions[index++] = bottomX;\n positions[index++] = bottomY;\n positions[index++] = bottomZ;\n positions[index++] = topX;\n positions[index++] = topY;\n positions[index++] = topZ;\n }\n }\n\n return positions;\n};\nexport default CylinderGeometryLibrary;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CylinderGeometryLibrary from \"./CylinderGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst radiusScratch = new Cartesian2();\nconst normalScratch = new Cartesian3();\nconst bitangentScratch = new Cartesian3();\nconst tangentScratch = new Cartesian3();\nconst positionScratch = new Cartesian3();\n\n/**\n * A description of a cylinder.\n *\n * @alias CylinderGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.length The length of the cylinder.\n * @param {number} options.topRadius The radius of the top of the cylinder.\n * @param {number} options.bottomRadius The radius of the bottom of the cylinder.\n * @param {number} [options.slices=128] The number of edges around the perimeter of the cylinder.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @exception {DeveloperError} options.slices must be greater than or equal to 3.\n *\n * @see CylinderGeometry.createGeometry\n *\n * @example\n * // create cylinder geometry\n * const cylinder = new Cesium.CylinderGeometry({\n * length: 200000,\n * topRadius: 80000,\n * bottomRadius: 200000,\n * });\n * const geometry = Cesium.CylinderGeometry.createGeometry(cylinder);\n */\nfunction CylinderGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const length = options.length;\n const topRadius = options.topRadius;\n const bottomRadius = options.bottomRadius;\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n const slices = defaultValue(options.slices, 128);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(length)) {\n throw new DeveloperError(\"options.length must be defined.\");\n }\n if (!defined(topRadius)) {\n throw new DeveloperError(\"options.topRadius must be defined.\");\n }\n if (!defined(bottomRadius)) {\n throw new DeveloperError(\"options.bottomRadius must be defined.\");\n }\n if (slices < 3) {\n throw new DeveloperError(\n \"options.slices must be greater than or equal to 3.\"\n );\n }\n if (\n defined(options.offsetAttribute) &&\n options.offsetAttribute === GeometryOffsetAttribute.TOP\n ) {\n throw new DeveloperError(\n \"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n this._length = length;\n this._topRadius = topRadius;\n this._bottomRadius = bottomRadius;\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._slices = slices;\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createCylinderGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nCylinderGeometry.packedLength = VertexFormat.packedLength + 5;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CylinderGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCylinderGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._length;\n array[startingIndex++] = value._topRadius;\n array[startingIndex++] = value._bottomRadius;\n array[startingIndex++] = value._slices;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n vertexFormat: scratchVertexFormat,\n length: undefined,\n topRadius: undefined,\n bottomRadius: undefined,\n slices: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CylinderGeometry} [result] The object into which to store the result.\n * @returns {CylinderGeometry} The modified result parameter or a new CylinderGeometry instance if one was not provided.\n */\nCylinderGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const length = array[startingIndex++];\n const topRadius = array[startingIndex++];\n const bottomRadius = array[startingIndex++];\n const slices = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.length = length;\n scratchOptions.topRadius = topRadius;\n scratchOptions.bottomRadius = bottomRadius;\n scratchOptions.slices = slices;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new CylinderGeometry(scratchOptions);\n }\n\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._length = length;\n result._topRadius = topRadius;\n result._bottomRadius = bottomRadius;\n result._slices = slices;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of a cylinder, including its vertices, indices, and a bounding sphere.\n *\n * @param {CylinderGeometry} cylinderGeometry A description of the cylinder.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCylinderGeometry.createGeometry = function (cylinderGeometry) {\n let length = cylinderGeometry._length;\n const topRadius = cylinderGeometry._topRadius;\n const bottomRadius = cylinderGeometry._bottomRadius;\n const vertexFormat = cylinderGeometry._vertexFormat;\n const slices = cylinderGeometry._slices;\n\n if (\n length <= 0 ||\n topRadius < 0 ||\n bottomRadius < 0 ||\n (topRadius === 0 && bottomRadius === 0)\n ) {\n return;\n }\n\n const twoSlices = slices + slices;\n const threeSlices = slices + twoSlices;\n const numVertices = twoSlices + twoSlices;\n\n const positions = CylinderGeometryLibrary.computePositions(\n length,\n topRadius,\n bottomRadius,\n slices,\n true\n );\n\n const st = vertexFormat.st ? new Float32Array(numVertices * 2) : undefined;\n const normals = vertexFormat.normal\n ? new Float32Array(numVertices * 3)\n : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(numVertices * 3)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(numVertices * 3)\n : undefined;\n\n let i;\n const computeNormal =\n vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent;\n\n if (computeNormal) {\n const computeTangent = vertexFormat.tangent || vertexFormat.bitangent;\n\n let normalIndex = 0;\n let tangentIndex = 0;\n let bitangentIndex = 0;\n\n const theta = Math.atan2(bottomRadius - topRadius, length);\n const normal = normalScratch;\n normal.z = Math.sin(theta);\n const normalScale = Math.cos(theta);\n let tangent = tangentScratch;\n let bitangent = bitangentScratch;\n\n for (i = 0; i < slices; i++) {\n const angle = (i / slices) * CesiumMath.TWO_PI;\n const x = normalScale * Math.cos(angle);\n const y = normalScale * Math.sin(angle);\n if (computeNormal) {\n normal.x = x;\n normal.y = y;\n\n if (computeTangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent),\n tangent\n );\n }\n\n if (vertexFormat.normal) {\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n }\n\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n }\n }\n }\n\n for (i = 0; i < slices; i++) {\n if (vertexFormat.normal) {\n normals[normalIndex++] = 0;\n normals[normalIndex++] = 0;\n normals[normalIndex++] = -1;\n }\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = 1;\n tangents[tangentIndex++] = 0;\n tangents[tangentIndex++] = 0;\n }\n if (vertexFormat.bitangent) {\n bitangents[bitangentIndex++] = 0;\n bitangents[bitangentIndex++] = -1;\n bitangents[bitangentIndex++] = 0;\n }\n }\n\n for (i = 0; i < slices; i++) {\n if (vertexFormat.normal) {\n normals[normalIndex++] = 0;\n normals[normalIndex++] = 0;\n normals[normalIndex++] = 1;\n }\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = 1;\n tangents[tangentIndex++] = 0;\n tangents[tangentIndex++] = 0;\n }\n if (vertexFormat.bitangent) {\n bitangents[bitangentIndex++] = 0;\n bitangents[bitangentIndex++] = 1;\n bitangents[bitangentIndex++] = 0;\n }\n }\n }\n\n const numIndices = 12 * slices - 12;\n const indices = IndexDatatype.createTypedArray(numVertices, numIndices);\n let index = 0;\n let j = 0;\n for (i = 0; i < slices - 1; i++) {\n indices[index++] = j;\n indices[index++] = j + 2;\n indices[index++] = j + 3;\n\n indices[index++] = j;\n indices[index++] = j + 3;\n indices[index++] = j + 1;\n\n j += 2;\n }\n\n indices[index++] = twoSlices - 2;\n indices[index++] = 0;\n indices[index++] = 1;\n indices[index++] = twoSlices - 2;\n indices[index++] = 1;\n indices[index++] = twoSlices - 1;\n\n for (i = 1; i < slices - 1; i++) {\n indices[index++] = twoSlices + i + 1;\n indices[index++] = twoSlices + i;\n indices[index++] = twoSlices;\n }\n\n for (i = 1; i < slices - 1; i++) {\n indices[index++] = threeSlices;\n indices[index++] = threeSlices + i;\n indices[index++] = threeSlices + i + 1;\n }\n\n let textureCoordIndex = 0;\n if (vertexFormat.st) {\n const rad = Math.max(topRadius, bottomRadius);\n for (i = 0; i < numVertices; i++) {\n const position = Cartesian3.fromArray(positions, i * 3, positionScratch);\n st[textureCoordIndex++] = (position.x + rad) / (2.0 * rad);\n st[textureCoordIndex++] = (position.y + rad) / (2.0 * rad);\n }\n }\n\n const attributes = new GeometryAttributes();\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: st,\n });\n }\n\n radiusScratch.x = length * 0.5;\n radiusScratch.y = Math.max(bottomRadius, topRadius);\n\n const boundingSphere = new BoundingSphere(\n Cartesian3.ZERO,\n Cartesian2.magnitude(radiusScratch)\n );\n\n if (defined(cylinderGeometry._offsetAttribute)) {\n length = positions.length;\n const offsetValue =\n cylinderGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: boundingSphere,\n offsetAttribute: cylinderGeometry._offsetAttribute,\n });\n};\n\nlet unitCylinderGeometry;\n\n/**\n * Returns the geometric representation of a unit cylinder, including its vertices, indices, and a bounding sphere.\n * @returns {Geometry} The computed vertices and indices.\n *\n * @private\n */\nCylinderGeometry.getUnitCylinder = function () {\n if (!defined(unitCylinderGeometry)) {\n unitCylinderGeometry = CylinderGeometry.createGeometry(\n new CylinderGeometry({\n topRadius: 1.0,\n bottomRadius: 1.0,\n length: 1.0,\n vertexFormat: VertexFormat.POSITION_ONLY,\n })\n );\n }\n return unitCylinderGeometry;\n};\nexport default CylinderGeometry;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CylinderGeometryLibrary from \"./CylinderGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nconst radiusScratch = new Cartesian2();\n\n/**\n * A description of the outline of a cylinder.\n *\n * @alias CylinderOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {number} options.length The length of the cylinder.\n * @param {number} options.topRadius The radius of the top of the cylinder.\n * @param {number} options.bottomRadius The radius of the bottom of the cylinder.\n * @param {number} [options.slices=128] The number of edges around the perimeter of the cylinder.\n * @param {number} [options.numberOfVerticalLines=16] Number of lines to draw between the top and bottom surfaces of the cylinder.\n *\n * @exception {DeveloperError} options.length must be greater than 0.\n * @exception {DeveloperError} options.topRadius must be greater than 0.\n * @exception {DeveloperError} options.bottomRadius must be greater than 0.\n * @exception {DeveloperError} bottomRadius and topRadius cannot both equal 0.\n * @exception {DeveloperError} options.slices must be greater than or equal to 3.\n *\n * @see CylinderOutlineGeometry.createGeometry\n *\n * @example\n * // create cylinder geometry\n * const cylinder = new Cesium.CylinderOutlineGeometry({\n * length: 200000,\n * topRadius: 80000,\n * bottomRadius: 200000,\n * });\n * const geometry = Cesium.CylinderOutlineGeometry.createGeometry(cylinder);\n */\nfunction CylinderOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const length = options.length;\n const topRadius = options.topRadius;\n const bottomRadius = options.bottomRadius;\n const slices = defaultValue(options.slices, 128);\n const numberOfVerticalLines = Math.max(\n defaultValue(options.numberOfVerticalLines, 16),\n 0\n );\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.number(\"options.positions\", length);\n Check.typeOf.number(\"options.topRadius\", topRadius);\n Check.typeOf.number(\"options.bottomRadius\", bottomRadius);\n Check.typeOf.number.greaterThanOrEquals(\"options.slices\", slices, 3);\n if (\n defined(options.offsetAttribute) &&\n options.offsetAttribute === GeometryOffsetAttribute.TOP\n ) {\n throw new DeveloperError(\n \"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n this._length = length;\n this._topRadius = topRadius;\n this._bottomRadius = bottomRadius;\n this._slices = slices;\n this._numberOfVerticalLines = numberOfVerticalLines;\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createCylinderOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nCylinderOutlineGeometry.packedLength = 6;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CylinderOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCylinderOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n array[startingIndex++] = value._length;\n array[startingIndex++] = value._topRadius;\n array[startingIndex++] = value._bottomRadius;\n array[startingIndex++] = value._slices;\n array[startingIndex++] = value._numberOfVerticalLines;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchOptions = {\n length: undefined,\n topRadius: undefined,\n bottomRadius: undefined,\n slices: undefined,\n numberOfVerticalLines: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CylinderOutlineGeometry} [result] The object into which to store the result.\n * @returns {CylinderOutlineGeometry} The modified result parameter or a new CylinderOutlineGeometry instance if one was not provided.\n */\nCylinderOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const length = array[startingIndex++];\n const topRadius = array[startingIndex++];\n const bottomRadius = array[startingIndex++];\n const slices = array[startingIndex++];\n const numberOfVerticalLines = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.length = length;\n scratchOptions.topRadius = topRadius;\n scratchOptions.bottomRadius = bottomRadius;\n scratchOptions.slices = slices;\n scratchOptions.numberOfVerticalLines = numberOfVerticalLines;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new CylinderOutlineGeometry(scratchOptions);\n }\n\n result._length = length;\n result._topRadius = topRadius;\n result._bottomRadius = bottomRadius;\n result._slices = slices;\n result._numberOfVerticalLines = numberOfVerticalLines;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an outline of a cylinder, including its vertices, indices, and a bounding sphere.\n *\n * @param {CylinderOutlineGeometry} cylinderGeometry A description of the cylinder outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCylinderOutlineGeometry.createGeometry = function (cylinderGeometry) {\n let length = cylinderGeometry._length;\n const topRadius = cylinderGeometry._topRadius;\n const bottomRadius = cylinderGeometry._bottomRadius;\n const slices = cylinderGeometry._slices;\n const numberOfVerticalLines = cylinderGeometry._numberOfVerticalLines;\n\n if (\n length <= 0 ||\n topRadius < 0 ||\n bottomRadius < 0 ||\n (topRadius === 0 && bottomRadius === 0)\n ) {\n return;\n }\n\n const numVertices = slices * 2;\n\n const positions = CylinderGeometryLibrary.computePositions(\n length,\n topRadius,\n bottomRadius,\n slices,\n false\n );\n let numIndices = slices * 2;\n let numSide;\n if (numberOfVerticalLines > 0) {\n const numSideLines = Math.min(numberOfVerticalLines, slices);\n numSide = Math.round(slices / numSideLines);\n numIndices += numSideLines;\n }\n\n const indices = IndexDatatype.createTypedArray(numVertices, numIndices * 2);\n let index = 0;\n let i;\n for (i = 0; i < slices - 1; i++) {\n indices[index++] = i;\n indices[index++] = i + 1;\n indices[index++] = i + slices;\n indices[index++] = i + 1 + slices;\n }\n\n indices[index++] = slices - 1;\n indices[index++] = 0;\n indices[index++] = slices + slices - 1;\n indices[index++] = slices;\n\n if (numberOfVerticalLines > 0) {\n for (i = 0; i < slices; i += numSide) {\n indices[index++] = i;\n indices[index++] = i + slices;\n }\n }\n\n const attributes = new GeometryAttributes();\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n radiusScratch.x = length * 0.5;\n radiusScratch.y = Math.max(bottomRadius, topRadius);\n\n const boundingSphere = new BoundingSphere(\n Cartesian3.ZERO,\n Cartesian2.magnitude(radiusScratch)\n );\n\n if (defined(cylinderGeometry._offsetAttribute)) {\n length = positions.length;\n const offsetValue =\n cylinderGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: boundingSphere,\n offsetAttribute: cylinderGeometry._offsetAttribute,\n });\n};\nexport default CylinderOutlineGeometry;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport CylinderGeometry from \"../Core/CylinderGeometry.js\";\nimport CylinderOutlineGeometry from \"../Core/CylinderOutlineGeometry.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"../Core/GeometryOffsetAttribute.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport heightReferenceOnEntityPropertyChanged from \"./heightReferenceOnEntityPropertyChanged.js\";\nimport Property from \"./Property.js\";\n\nconst defaultOffset = Cartesian3.ZERO;\n\nconst offsetScratch = new Cartesian3();\nconst positionScratch = new Cartesian3();\nconst scratchColor = new Color();\n\nfunction CylinderGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.length = undefined;\n this.topRadius = undefined;\n this.bottomRadius = undefined;\n this.slices = undefined;\n this.numberOfVerticalLines = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for cylinders.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias CylinderGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction CylinderGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new CylinderGeometryOptions(entity),\n geometryPropertyName: \"cylinder\",\n observedPropertyNames: [\n \"availability\",\n \"position\",\n \"orientation\",\n \"cylinder\",\n ],\n });\n\n this._onEntityPropertyChanged(entity, \"cylinder\", entity.cylinder, undefined);\n}\n\nif (defined(Object.create)) {\n CylinderGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n CylinderGeometryUpdater.prototype.constructor = CylinderGeometryUpdater;\n}\n\nObject.defineProperties(CylinderGeometryUpdater.prototype, {\n /**\n * Gets the terrain offset property\n * @type {TerrainOffsetProperty}\n * @memberof CylinderGeometryUpdater.prototype\n * @readonly\n * @private\n */\n terrainOffsetProperty: {\n get: function () {\n return this._terrainOffsetProperty;\n },\n },\n});\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nCylinderGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n\n const attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: undefined,\n offset: undefined,\n };\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new CylinderGeometry(this._options),\n modelMatrix: entity.computeModelMatrixForHeightReference(\n time,\n entity.cylinder.heightReference,\n this._options.length * 0.5,\n this._scene.mapProjection.ellipsoid\n ),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nCylinderGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new CylinderOutlineGeometry(this._options),\n modelMatrix: entity.computeModelMatrixForHeightReference(\n time,\n entity.cylinder.heightReference,\n this._options.length * 0.5,\n this._scene.mapProjection.ellipsoid\n ),\n attributes: attributes,\n });\n};\n\nCylinderGeometryUpdater.prototype._computeCenter = function (time, result) {\n return Property.getValueOrUndefined(this._entity.position, time, result);\n};\n\nCylinderGeometryUpdater.prototype._isHidden = function (entity, cylinder) {\n return (\n !defined(entity.position) ||\n !defined(cylinder.length) ||\n !defined(cylinder.topRadius) ||\n !defined(cylinder.bottomRadius) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, cylinder)\n );\n};\n\nCylinderGeometryUpdater.prototype._isDynamic = function (entity, cylinder) {\n return (\n !entity.position.isConstant || //\n !Property.isConstant(entity.orientation) || //\n !cylinder.length.isConstant || //\n !cylinder.topRadius.isConstant || //\n !cylinder.bottomRadius.isConstant || //\n !Property.isConstant(cylinder.slices) || //\n !Property.isConstant(cylinder.outlineWidth) || //\n !Property.isConstant(cylinder.numberOfVerticalLines)\n );\n};\n\nCylinderGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n cylinder\n) {\n const heightReference = Property.getValueOrDefault(\n cylinder.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n const options = this._options;\n options.vertexFormat =\n this._materialProperty instanceof ColorMaterialProperty\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.length = cylinder.length.getValue(Iso8601.MINIMUM_VALUE);\n options.topRadius = cylinder.topRadius.getValue(Iso8601.MINIMUM_VALUE);\n options.bottomRadius = cylinder.bottomRadius.getValue(Iso8601.MINIMUM_VALUE);\n options.slices = Property.getValueOrUndefined(\n cylinder.slices,\n Iso8601.MINIMUM_VALUE\n );\n options.numberOfVerticalLines = Property.getValueOrUndefined(\n cylinder.numberOfVerticalLines,\n Iso8601.MINIMUM_VALUE\n );\n options.offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n};\n\nCylinderGeometryUpdater.prototype._onEntityPropertyChanged = heightReferenceOnEntityPropertyChanged;\n\nCylinderGeometryUpdater.DynamicGeometryUpdater = DynamicCylinderGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicCylinderGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicCylinderGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicCylinderGeometryUpdater.prototype.constructor = DynamicCylinderGeometryUpdater;\n}\n\nDynamicCylinderGeometryUpdater.prototype._isHidden = function (\n entity,\n cylinder,\n time\n) {\n const options = this._options;\n const position = Property.getValueOrUndefined(\n entity.position,\n time,\n positionScratch\n );\n return (\n !defined(position) ||\n !defined(options.length) ||\n !defined(options.topRadius) || //\n !defined(options.bottomRadius) ||\n DynamicGeometryUpdater.prototype._isHidden.call(\n this,\n entity,\n cylinder,\n time\n )\n );\n};\n\nDynamicCylinderGeometryUpdater.prototype._setOptions = function (\n entity,\n cylinder,\n time\n) {\n const heightReference = Property.getValueOrDefault(\n cylinder.heightReference,\n time,\n HeightReference.NONE\n );\n const options = this._options;\n options.length = Property.getValueOrUndefined(cylinder.length, time);\n options.topRadius = Property.getValueOrUndefined(cylinder.topRadius, time);\n options.bottomRadius = Property.getValueOrUndefined(\n cylinder.bottomRadius,\n time\n );\n options.slices = Property.getValueOrUndefined(cylinder.slices, time);\n options.numberOfVerticalLines = Property.getValueOrUndefined(\n cylinder.numberOfVerticalLines,\n time\n );\n options.offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n};\nexport default CylinderGeometryUpdater;\n", "/**\n * Constants used by {@link Clock#tick} to determine behavior\n * when {@link Clock#startTime} or {@link Clock#stopTime} is reached.\n *\n * @enum {number}\n *\n * @see Clock\n * @see ClockStep\n */\nconst ClockRange = {\n /**\n * {@link Clock#tick} will always advances the clock in its current direction.\n *\n * @type {number}\n * @constant\n */\n UNBOUNDED: 0,\n\n /**\n * When {@link Clock#startTime} or {@link Clock#stopTime} is reached,\n * {@link Clock#tick} will not advance {@link Clock#currentTime} any further.\n *\n * @type {number}\n * @constant\n */\n CLAMPED: 1,\n\n /**\n * When {@link Clock#stopTime} is reached, {@link Clock#tick} will advance\n * {@link Clock#currentTime} to the opposite end of the interval. When\n * time is moving backwards, {@link Clock#tick} will not advance past\n * {@link Clock#startTime}\n *\n * @type {number}\n * @constant\n */\n LOOP_STOP: 2,\n};\nexport default Object.freeze(ClockRange);\n", "/**\n * Constants to determine how much time advances with each call\n * to {@link Clock#tick}.\n *\n * @enum {number}\n *\n * @see Clock\n * @see ClockRange\n */\nconst ClockStep = {\n /**\n * {@link Clock#tick} advances the current time by a fixed step,\n * which is the number of seconds specified by {@link Clock#multiplier}.\n *\n * @type {number}\n * @constant\n */\n TICK_DEPENDENT: 0,\n\n /**\n * {@link Clock#tick} advances the current time by the amount of system\n * time elapsed since the previous call multiplied by {@link Clock#multiplier}.\n *\n * @type {number}\n * @constant\n */\n SYSTEM_CLOCK_MULTIPLIER: 1,\n\n /**\n * {@link Clock#tick} sets the clock to the current system time;\n * ignoring all other settings.\n *\n * @type {number}\n * @constant\n */\n SYSTEM_CLOCK: 2,\n};\nexport default Object.freeze(ClockStep);\n", "/**\n * Constants to determine how an interpolated value is extrapolated\n * when querying outside the bounds of available data.\n *\n * @enum {number}\n *\n * @see SampledProperty\n */\nconst ExtrapolationType = {\n /**\n * No extrapolation occurs.\n *\n * @type {number}\n * @constant\n */\n NONE: 0,\n\n /**\n * The first or last value is used when outside the range of sample data.\n *\n * @type {number}\n * @constant\n */\n HOLD: 1,\n\n /**\n * The value is extrapolated.\n *\n * @type {number}\n * @constant\n */\n EXTRAPOLATE: 2,\n};\nexport default Object.freeze(ExtrapolationType);\n", "import Uri from \"urijs\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * Given a URI, returns the last segment of the URI, removing any path or query information.\n * @function getFilenameFromUri\n *\n * @param {string} uri The Uri.\n * @returns {string} The last segment of the Uri.\n *\n * @example\n * //fileName will be\"simple.czml\";\n * const fileName = Cesium.getFilenameFromUri('/Gallery/simple.czml?value=true&example=false');\n */\nfunction getFilenameFromUri(uri) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(uri)) {\n throw new DeveloperError(\"uri is required.\");\n }\n //>>includeEnd('debug');\n\n const uriObject = new Uri(uri);\n uriObject.normalize();\n let path = uriObject.path();\n const index = path.lastIndexOf(\"/\");\n if (index !== -1) {\n path = path.substr(index + 1);\n }\n return path;\n}\nexport default getFilenameFromUri;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\nconst factorial = CesiumMath.factorial;\n\nfunction calculateCoefficientTerm(\n x,\n zIndices,\n xTable,\n derivOrder,\n termOrder,\n reservedIndices\n) {\n let result = 0;\n let reserved;\n let i;\n let j;\n\n if (derivOrder > 0) {\n for (i = 0; i < termOrder; i++) {\n reserved = false;\n for (j = 0; j < reservedIndices.length && !reserved; j++) {\n if (i === reservedIndices[j]) {\n reserved = true;\n }\n }\n\n if (!reserved) {\n reservedIndices.push(i);\n result += calculateCoefficientTerm(\n x,\n zIndices,\n xTable,\n derivOrder - 1,\n termOrder,\n reservedIndices\n );\n reservedIndices.splice(reservedIndices.length - 1, 1);\n }\n }\n\n return result;\n }\n\n result = 1;\n for (i = 0; i < termOrder; i++) {\n reserved = false;\n for (j = 0; j < reservedIndices.length && !reserved; j++) {\n if (i === reservedIndices[j]) {\n reserved = true;\n }\n }\n\n if (!reserved) {\n result *= x - xTable[zIndices[i]];\n }\n }\n\n return result;\n}\n\n/**\n * An {@link InterpolationAlgorithm} for performing Hermite interpolation.\n *\n * @namespace HermitePolynomialApproximation\n */\nconst HermitePolynomialApproximation = {\n type: \"Hermite\",\n};\n\n/**\n * Given the desired degree, returns the number of data points required for interpolation.\n *\n * @param {number} degree The desired degree of interpolation.\n * @param {number} [inputOrder=0] The order of the inputs (0 means just the data, 1 means the data and its derivative, etc).\n * @returns {number} The number of required data points needed for the desired degree of interpolation.\n * @exception {DeveloperError} degree must be 0 or greater.\n * @exception {DeveloperError} inputOrder must be 0 or greater.\n */\nHermitePolynomialApproximation.getRequiredDataPoints = function (\n degree,\n inputOrder\n) {\n inputOrder = defaultValue(inputOrder, 0);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(degree)) {\n throw new DeveloperError(\"degree is required.\");\n }\n if (degree < 0) {\n throw new DeveloperError(\"degree must be 0 or greater.\");\n }\n if (inputOrder < 0) {\n throw new DeveloperError(\"inputOrder must be 0 or greater.\");\n }\n //>>includeEnd('debug');\n\n return Math.max(Math.floor((degree + 1) / (inputOrder + 1)), 2);\n};\n\n/**\n * Interpolates values using Hermite Polynomial Approximation.\n *\n * @param {number} x The independent variable for which the dependent variables will be interpolated.\n * @param {number[]} xTable The array of independent variables to use to interpolate. The values\n * in this array must be in increasing order and the same value must not occur twice in the array.\n * @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three\n * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.\n * @param {number} yStride The number of dependent variable values in yTable corresponding to\n * each independent variable value in xTable.\n * @param {number[]} [result] An existing array into which to store the result.\n * @returns {number[]} The array of interpolated values, or the result parameter if one was provided.\n */\nHermitePolynomialApproximation.interpolateOrderZero = function (\n x,\n xTable,\n yTable,\n yStride,\n result\n) {\n if (!defined(result)) {\n result = new Array(yStride);\n }\n\n let i;\n let j;\n let d;\n let s;\n let len;\n let index;\n const length = xTable.length;\n const coefficients = new Array(yStride);\n\n for (i = 0; i < yStride; i++) {\n result[i] = 0;\n\n const l = new Array(length);\n coefficients[i] = l;\n for (j = 0; j < length; j++) {\n l[j] = [];\n }\n }\n\n const zIndicesLength = length,\n zIndices = new Array(zIndicesLength);\n\n for (i = 0; i < zIndicesLength; i++) {\n zIndices[i] = i;\n }\n\n let highestNonZeroCoef = length - 1;\n for (s = 0; s < yStride; s++) {\n for (j = 0; j < zIndicesLength; j++) {\n index = zIndices[j] * yStride + s;\n coefficients[s][0].push(yTable[index]);\n }\n\n for (i = 1; i < zIndicesLength; i++) {\n let nonZeroCoefficients = false;\n for (j = 0; j < zIndicesLength - i; j++) {\n const zj = xTable[zIndices[j]];\n const zn = xTable[zIndices[j + i]];\n\n let numerator;\n if (zn - zj <= 0) {\n index = zIndices[j] * yStride + yStride * i + s;\n numerator = yTable[index];\n coefficients[s][i].push(numerator / factorial(i));\n } else {\n numerator = coefficients[s][i - 1][j + 1] - coefficients[s][i - 1][j];\n coefficients[s][i].push(numerator / (zn - zj));\n }\n nonZeroCoefficients = nonZeroCoefficients || numerator !== 0;\n }\n\n if (!nonZeroCoefficients) {\n highestNonZeroCoef = i - 1;\n }\n }\n }\n\n for (d = 0, len = 0; d <= len; d++) {\n for (i = d; i <= highestNonZeroCoef; i++) {\n const tempTerm = calculateCoefficientTerm(x, zIndices, xTable, d, i, []);\n for (s = 0; s < yStride; s++) {\n const coeff = coefficients[s][i][0];\n result[s + d * yStride] += coeff * tempTerm;\n }\n }\n }\n\n return result;\n};\n\nconst arrayScratch = [];\n\n/**\n * Interpolates values using Hermite Polynomial Approximation.\n *\n * @param {number} x The independent variable for which the dependent variables will be interpolated.\n * @param {number[]} xTable The array of independent variables to use to interpolate. The values\n * in this array must be in increasing order and the same value must not occur twice in the array.\n * @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three\n * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.\n * @param {number} yStride The number of dependent variable values in yTable corresponding to\n * each independent variable value in xTable.\n * @param {number} inputOrder The number of derivatives supplied for input.\n * @param {number} outputOrder The number of derivatives desired for output.\n * @param {number[]} [result] An existing array into which to store the result.\n *\n * @returns {number[]} The array of interpolated values, or the result parameter if one was provided.\n */\nHermitePolynomialApproximation.interpolate = function (\n x,\n xTable,\n yTable,\n yStride,\n inputOrder,\n outputOrder,\n result\n) {\n const resultLength = yStride * (outputOrder + 1);\n if (!defined(result)) {\n result = new Array(resultLength);\n }\n for (let r = 0; r < resultLength; r++) {\n result[r] = 0;\n }\n\n const length = xTable.length;\n // The zIndices array holds copies of the addresses of the xTable values\n // in the range we're looking at. Even though this just holds information already\n // available in xTable this is a much more convenient format.\n const zIndices = new Array(length * (inputOrder + 1));\n let i;\n for (i = 0; i < length; i++) {\n for (let j = 0; j < inputOrder + 1; j++) {\n zIndices[i * (inputOrder + 1) + j] = i;\n }\n }\n\n const zIndiceslength = zIndices.length;\n const coefficients = arrayScratch;\n const highestNonZeroCoef = fillCoefficientList(\n coefficients,\n zIndices,\n xTable,\n yTable,\n yStride,\n inputOrder\n );\n const reservedIndices = [];\n\n const tmp = (zIndiceslength * (zIndiceslength + 1)) / 2;\n const loopStop = Math.min(highestNonZeroCoef, outputOrder);\n for (let d = 0; d <= loopStop; d++) {\n for (i = d; i <= highestNonZeroCoef; i++) {\n reservedIndices.length = 0;\n const tempTerm = calculateCoefficientTerm(\n x,\n zIndices,\n xTable,\n d,\n i,\n reservedIndices\n );\n const dimTwo = Math.floor((i * (1 - i)) / 2) + zIndiceslength * i;\n\n for (let s = 0; s < yStride; s++) {\n const dimOne = Math.floor(s * tmp);\n const coef = coefficients[dimOne + dimTwo];\n result[s + d * yStride] += coef * tempTerm;\n }\n }\n }\n\n return result;\n};\n\nfunction fillCoefficientList(\n coefficients,\n zIndices,\n xTable,\n yTable,\n yStride,\n inputOrder\n) {\n let j;\n let index;\n let highestNonZero = -1;\n const zIndiceslength = zIndices.length;\n const tmp = (zIndiceslength * (zIndiceslength + 1)) / 2;\n\n for (let s = 0; s < yStride; s++) {\n const dimOne = Math.floor(s * tmp);\n\n for (j = 0; j < zIndiceslength; j++) {\n index = zIndices[j] * yStride * (inputOrder + 1) + s;\n coefficients[dimOne + j] = yTable[index];\n }\n\n for (let i = 1; i < zIndiceslength; i++) {\n let coefIndex = 0;\n const dimTwo = Math.floor((i * (1 - i)) / 2) + zIndiceslength * i;\n let nonZeroCoefficients = false;\n\n for (j = 0; j < zIndiceslength - i; j++) {\n const zj = xTable[zIndices[j]];\n const zn = xTable[zIndices[j + i]];\n\n let numerator;\n let coefficient;\n if (zn - zj <= 0) {\n index = zIndices[j] * yStride * (inputOrder + 1) + yStride * i + s;\n numerator = yTable[index];\n coefficient = numerator / CesiumMath.factorial(i);\n coefficients[dimOne + dimTwo + coefIndex] = coefficient;\n coefIndex++;\n } else {\n const dimTwoMinusOne =\n Math.floor(((i - 1) * (2 - i)) / 2) + zIndiceslength * (i - 1);\n numerator =\n coefficients[dimOne + dimTwoMinusOne + j + 1] -\n coefficients[dimOne + dimTwoMinusOne + j];\n coefficient = numerator / (zn - zj);\n coefficients[dimOne + dimTwo + coefIndex] = coefficient;\n coefIndex++;\n }\n nonZeroCoefficients = nonZeroCoefficients || numerator !== 0.0;\n }\n\n if (nonZeroCoefficients) {\n highestNonZero = Math.max(highestNonZero, i);\n }\n }\n }\n\n return highestNonZero;\n}\nexport default HermitePolynomialApproximation;\n", "import defined from \"./defined.js\";\n\n/**\n * An {@link InterpolationAlgorithm} for performing Lagrange interpolation.\n *\n * @namespace LagrangePolynomialApproximation\n */\nconst LagrangePolynomialApproximation = {\n type: \"Lagrange\",\n};\n\n/**\n * Given the desired degree, returns the number of data points required for interpolation.\n *\n * @param {number} degree The desired degree of interpolation.\n * @returns {number} The number of required data points needed for the desired degree of interpolation.\n */\nLagrangePolynomialApproximation.getRequiredDataPoints = function (degree) {\n return Math.max(degree + 1.0, 2);\n};\n\n/**\n * Interpolates values using Lagrange Polynomial Approximation.\n *\n * @param {number} x The independent variable for which the dependent variables will be interpolated.\n * @param {number[]} xTable The array of independent variables to use to interpolate. The values\n * in this array must be in increasing order and the same value must not occur twice in the array.\n * @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three\n * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.\n * @param {number} yStride The number of dependent variable values in yTable corresponding to\n * each independent variable value in xTable.\n * @param {number[]} [result] An existing array into which to store the result.\n * @returns {number[]} The array of interpolated values, or the result parameter if one was provided.\n */\nLagrangePolynomialApproximation.interpolateOrderZero = function (\n x,\n xTable,\n yTable,\n yStride,\n result\n) {\n if (!defined(result)) {\n result = new Array(yStride);\n }\n\n let i;\n let j;\n const length = xTable.length;\n\n for (i = 0; i < yStride; i++) {\n result[i] = 0;\n }\n\n for (i = 0; i < length; i++) {\n let coefficient = 1;\n\n for (j = 0; j < length; j++) {\n if (j !== i) {\n const diffX = xTable[i] - xTable[j];\n coefficient *= (x - xTable[j]) / diffX;\n }\n }\n\n for (j = 0; j < yStride; j++) {\n result[j] += coefficient * yTable[i * yStride + j];\n }\n }\n\n return result;\n};\nexport default LagrangePolynomialApproximation;\n", "import defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\n\n/**\n * An {@link InterpolationAlgorithm} for performing linear interpolation.\n *\n * @namespace LinearApproximation\n */\nconst LinearApproximation = {\n type: \"Linear\",\n};\n\n/**\n * Given the desired degree, returns the number of data points required for interpolation.\n * Since linear interpolation can only generate a first degree polynomial, this function\n * always returns 2.\n * @param {number} degree The desired degree of interpolation.\n * @returns {number} This function always returns 2.\n *\n */\nLinearApproximation.getRequiredDataPoints = function (degree) {\n return 2;\n};\n\n/**\n * Interpolates values using linear approximation.\n *\n * @param {number} x The independent variable for which the dependent variables will be interpolated.\n * @param {number[]} xTable The array of independent variables to use to interpolate. The values\n * in this array must be in increasing order and the same value must not occur twice in the array.\n * @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three\n * dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.\n * @param {number} yStride The number of dependent variable values in yTable corresponding to\n * each independent variable value in xTable.\n * @param {number[]} [result] An existing array into which to store the result.\n * @returns {number[]} The array of interpolated values, or the result parameter if one was provided.\n */\nLinearApproximation.interpolateOrderZero = function (\n x,\n xTable,\n yTable,\n yStride,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (xTable.length !== 2) {\n throw new DeveloperError(\n \"The xTable provided to the linear interpolator must have exactly two elements.\"\n );\n } else if (yStride <= 0) {\n throw new DeveloperError(\n \"There must be at least 1 dependent variable for each independent variable.\"\n );\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = new Array(yStride);\n }\n\n let i;\n let y0;\n let y1;\n const x0 = xTable[0];\n const x1 = xTable[1];\n\n //>>includeStart('debug', pragmas.debug);\n if (x0 === x1) {\n throw new DeveloperError(\n \"Divide by zero error: xTable[0] and xTable[1] are equal\"\n );\n }\n //>>includeEnd('debug');\n\n for (i = 0; i < yStride; i++) {\n y0 = yTable[i];\n y1 = yTable[i + yStride];\n result[i] = ((y1 - y0) * x + x1 * y0 - x0 * y1) / (x1 - x0);\n }\n\n return result;\n};\nexport default LinearApproximation;\n", "import Check from \"./Check.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * A set of curvilinear 3-dimensional coordinates.\n *\n * @alias Spherical\n * @constructor\n *\n * @param {number} [clock=0.0] The angular coordinate lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.\n * @param {number} [cone=0.0] The angular coordinate measured from the positive z-axis and toward the negative z-axis.\n * @param {number} [magnitude=1.0] The linear coordinate measured from the origin.\n */\nfunction Spherical(clock, cone, magnitude) {\n /**\n * The clock component.\n * @type {number}\n * @default 0.0\n */\n this.clock = defaultValue(clock, 0.0);\n /**\n * The cone component.\n * @type {number}\n * @default 0.0\n */\n this.cone = defaultValue(cone, 0.0);\n /**\n * The magnitude component.\n * @type {number}\n * @default 1.0\n */\n this.magnitude = defaultValue(magnitude, 1.0);\n}\n\n/**\n * Converts the provided Cartesian3 into Spherical coordinates.\n *\n * @param {Cartesian3} cartesian3 The Cartesian3 to be converted to Spherical.\n * @param {Spherical} [result] The object in which the result will be stored, if undefined a new instance will be created.\n * @returns {Spherical} The modified result parameter, or a new instance if one was not provided.\n */\nSpherical.fromCartesian3 = function (cartesian3, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"cartesian3\", cartesian3);\n //>>includeEnd('debug');\n\n const x = cartesian3.x;\n const y = cartesian3.y;\n const z = cartesian3.z;\n const radialSquared = x * x + y * y;\n\n if (!defined(result)) {\n result = new Spherical();\n }\n\n result.clock = Math.atan2(y, x);\n result.cone = Math.atan2(Math.sqrt(radialSquared), z);\n result.magnitude = Math.sqrt(radialSquared + z * z);\n return result;\n};\n\n/**\n * Creates a duplicate of a Spherical.\n *\n * @param {Spherical} spherical The spherical to clone.\n * @param {Spherical} [result] The object to store the result into, if undefined a new instance will be created.\n * @returns {Spherical} The modified result parameter or a new instance if result was undefined. (Returns undefined if spherical is undefined)\n */\nSpherical.clone = function (spherical, result) {\n if (!defined(spherical)) {\n return undefined;\n }\n\n if (!defined(result)) {\n return new Spherical(spherical.clock, spherical.cone, spherical.magnitude);\n }\n\n result.clock = spherical.clock;\n result.cone = spherical.cone;\n result.magnitude = spherical.magnitude;\n return result;\n};\n\n/**\n * Computes the normalized version of the provided spherical.\n *\n * @param {Spherical} spherical The spherical to be normalized.\n * @param {Spherical} [result] The object to store the result into, if undefined a new instance will be created.\n * @returns {Spherical} The modified result parameter or a new instance if result was undefined.\n */\nSpherical.normalize = function (spherical, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"spherical\", spherical);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new Spherical(spherical.clock, spherical.cone, 1.0);\n }\n\n result.clock = spherical.clock;\n result.cone = spherical.cone;\n result.magnitude = 1.0;\n return result;\n};\n\n/**\n * Returns true if the first spherical is equal to the second spherical, false otherwise.\n *\n * @param {Spherical} left The first Spherical to be compared.\n * @param {Spherical} right The second Spherical to be compared.\n * @returns {boolean} true if the first spherical is equal to the second spherical, false otherwise.\n */\nSpherical.equals = function (left, right) {\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n left.clock === right.clock &&\n left.cone === right.cone &&\n left.magnitude === right.magnitude)\n );\n};\n\n/**\n * Returns true if the first spherical is within the provided epsilon of the second spherical, false otherwise.\n *\n * @param {Spherical} left The first Spherical to be compared.\n * @param {Spherical} right The second Spherical to be compared.\n * @param {number} [epsilon=0.0] The epsilon to compare against.\n * @returns {boolean} true if the first spherical is within the provided epsilon of the second spherical, false otherwise.\n */\nSpherical.equalsEpsilon = function (left, right, epsilon) {\n epsilon = defaultValue(epsilon, 0.0);\n return (\n left === right ||\n (defined(left) &&\n defined(right) &&\n Math.abs(left.clock - right.clock) <= epsilon &&\n Math.abs(left.cone - right.cone) <= epsilon &&\n Math.abs(left.magnitude - right.magnitude) <= epsilon)\n );\n};\n\n/**\n * Returns true if this spherical is equal to the provided spherical, false otherwise.\n *\n * @param {Spherical} other The Spherical to be compared.\n * @returns {boolean} true if this spherical is equal to the provided spherical, false otherwise.\n */\nSpherical.prototype.equals = function (other) {\n return Spherical.equals(this, other);\n};\n\n/**\n * Creates a duplicate of this Spherical.\n *\n * @param {Spherical} [result] The object to store the result into, if undefined a new instance will be created.\n * @returns {Spherical} The modified result parameter or a new instance if result was undefined.\n */\nSpherical.prototype.clone = function (result) {\n return Spherical.clone(this, result);\n};\n\n/**\n * Returns true if this spherical is within the provided epsilon of the provided spherical, false otherwise.\n *\n * @param {Spherical} other The Spherical to be compared.\n * @param {number} epsilon The epsilon to compare against.\n * @returns {boolean} true if this spherical is within the provided epsilon of the provided spherical, false otherwise.\n */\nSpherical.prototype.equalsEpsilon = function (other, epsilon) {\n return Spherical.equalsEpsilon(this, other, epsilon);\n};\n\n/**\n * Returns a string representing this instance in the format (clock, cone, magnitude).\n *\n * @returns {string} A string representing this instance.\n */\nSpherical.prototype.toString = function () {\n return `(${this.clock}, ${this.cone}, ${this.magnitude})`;\n};\nexport default Spherical;\n", "import ArcType from \"../Core/ArcType.js\";\nimport BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport ClockRange from \"../Core/ClockRange.js\";\nimport ClockStep from \"../Core/ClockStep.js\";\nimport Color from \"../Core/Color.js\";\nimport CornerType from \"../Core/CornerType.js\";\nimport Credit from \"../Core/Credit.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Event from \"../Core/Event.js\";\nimport ExtrapolationType from \"../Core/ExtrapolationType.js\";\nimport getFilenameFromUri from \"../Core/getFilenameFromUri.js\";\nimport HermitePolynomialApproximation from \"../Core/HermitePolynomialApproximation.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport LagrangePolynomialApproximation from \"../Core/LagrangePolynomialApproximation.js\";\nimport LinearApproximation from \"../Core/LinearApproximation.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport PolygonHierarchy from \"../Core/PolygonHierarchy.js\";\nimport Quaternion from \"../Core/Quaternion.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport Spherical from \"../Core/Spherical.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport ClassificationType from \"../Scene/ClassificationType.js\";\nimport ColorBlendMode from \"../Scene/ColorBlendMode.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport LabelStyle from \"../Scene/LabelStyle.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport Uri from \"urijs\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport BoxGraphics from \"./BoxGraphics.js\";\nimport CallbackProperty from \"./CallbackProperty.js\";\nimport CheckerboardMaterialProperty from \"./CheckerboardMaterialProperty.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport CompositeMaterialProperty from \"./CompositeMaterialProperty.js\";\nimport CompositePositionProperty from \"./CompositePositionProperty.js\";\nimport CompositeProperty from \"./CompositeProperty.js\";\nimport ConstantPositionProperty from \"./ConstantPositionProperty.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport CorridorGraphics from \"./CorridorGraphics.js\";\nimport CylinderGraphics from \"./CylinderGraphics.js\";\nimport DataSource from \"./DataSource.js\";\nimport DataSourceClock from \"./DataSourceClock.js\";\nimport EllipseGraphics from \"./EllipseGraphics.js\";\nimport EllipsoidGraphics from \"./EllipsoidGraphics.js\";\nimport EntityCluster from \"./EntityCluster.js\";\nimport EntityCollection from \"./EntityCollection.js\";\nimport GridMaterialProperty from \"./GridMaterialProperty.js\";\nimport ImageMaterialProperty from \"./ImageMaterialProperty.js\";\nimport LabelGraphics from \"./LabelGraphics.js\";\nimport ModelGraphics from \"./ModelGraphics.js\";\nimport NodeTransformationProperty from \"./NodeTransformationProperty.js\";\nimport PathGraphics from \"./PathGraphics.js\";\nimport PointGraphics from \"./PointGraphics.js\";\nimport PolygonGraphics from \"./PolygonGraphics.js\";\nimport PolylineArrowMaterialProperty from \"./PolylineArrowMaterialProperty.js\";\nimport PolylineDashMaterialProperty from \"./PolylineDashMaterialProperty.js\";\nimport PolylineGlowMaterialProperty from \"./PolylineGlowMaterialProperty.js\";\nimport PolylineGraphics from \"./PolylineGraphics.js\";\nimport PolylineOutlineMaterialProperty from \"./PolylineOutlineMaterialProperty.js\";\nimport PolylineVolumeGraphics from \"./PolylineVolumeGraphics.js\";\nimport PositionPropertyArray from \"./PositionPropertyArray.js\";\nimport Property from \"./Property.js\";\nimport PropertyArray from \"./PropertyArray.js\";\nimport PropertyBag from \"./PropertyBag.js\";\nimport RectangleGraphics from \"./RectangleGraphics.js\";\nimport ReferenceProperty from \"./ReferenceProperty.js\";\nimport Rotation from \"./Rotation.js\";\nimport SampledPositionProperty from \"./SampledPositionProperty.js\";\nimport SampledProperty from \"./SampledProperty.js\";\nimport StripeMaterialProperty from \"./StripeMaterialProperty.js\";\nimport StripeOrientation from \"./StripeOrientation.js\";\nimport TimeIntervalCollectionPositionProperty from \"./TimeIntervalCollectionPositionProperty.js\";\nimport TimeIntervalCollectionProperty from \"./TimeIntervalCollectionProperty.js\";\nimport VelocityOrientationProperty from \"./VelocityOrientationProperty.js\";\nimport VelocityVectorProperty from \"./VelocityVectorProperty.js\";\nimport WallGraphics from \"./WallGraphics.js\";\nimport Cesium3DTilesetGraphics from \"./Cesium3DTilesetGraphics.js\";\n\n// A marker type to distinguish CZML properties where we need to end up with a unit vector.\n// The data is still loaded into Cartesian3 objects but they are normalized.\nfunction UnitCartesian3() {}\nUnitCartesian3.packedLength = Cartesian3.packedLength;\nUnitCartesian3.unpack = Cartesian3.unpack;\nUnitCartesian3.pack = Cartesian3.pack;\n\n// As a side note, for the purposes of CZML, Quaternion always indicates a unit quaternion.\n\nlet currentId;\n\nfunction createReferenceProperty(entityCollection, referenceString) {\n if (referenceString[0] === \"#\") {\n referenceString = currentId + referenceString;\n }\n return ReferenceProperty.fromString(entityCollection, referenceString);\n}\n\nfunction createSpecializedProperty(type, entityCollection, packetData) {\n if (defined(packetData.reference)) {\n return createReferenceProperty(entityCollection, packetData.reference);\n }\n\n if (defined(packetData.velocityReference)) {\n const referenceProperty = createReferenceProperty(\n entityCollection,\n packetData.velocityReference\n );\n switch (type) {\n case Cartesian3:\n case UnitCartesian3:\n return new VelocityVectorProperty(\n referenceProperty,\n type === UnitCartesian3\n );\n case Quaternion:\n return new VelocityOrientationProperty(referenceProperty);\n }\n }\n\n throw new RuntimeError(`${JSON.stringify(packetData)} is not valid CZML.`);\n}\n\nfunction createAdapterProperty(property, adapterFunction) {\n return new CallbackProperty(function (time, result) {\n return adapterFunction(property.getValue(time, result));\n }, property.isConstant);\n}\n\nconst scratchCartesian = new Cartesian3();\nconst scratchSpherical = new Spherical();\nconst scratchCartographic = new Cartographic();\nconst scratchTimeInterval = new TimeInterval();\nconst scratchQuaternion = new Quaternion();\n\nfunction unwrapColorInterval(czmlInterval) {\n let rgbaf = czmlInterval.rgbaf;\n if (defined(rgbaf)) {\n return rgbaf;\n }\n\n const rgba = czmlInterval.rgba;\n if (!defined(rgba)) {\n return undefined;\n }\n\n const length = rgba.length;\n if (length === Color.packedLength) {\n return [\n Color.byteToFloat(rgba[0]),\n Color.byteToFloat(rgba[1]),\n Color.byteToFloat(rgba[2]),\n Color.byteToFloat(rgba[3]),\n ];\n }\n\n rgbaf = new Array(length);\n for (let i = 0; i < length; i += 5) {\n rgbaf[i] = rgba[i];\n rgbaf[i + 1] = Color.byteToFloat(rgba[i + 1]);\n rgbaf[i + 2] = Color.byteToFloat(rgba[i + 2]);\n rgbaf[i + 3] = Color.byteToFloat(rgba[i + 3]);\n rgbaf[i + 4] = Color.byteToFloat(rgba[i + 4]);\n }\n return rgbaf;\n}\n\nfunction unwrapUriInterval(czmlInterval, sourceUri) {\n const uri = defaultValue(czmlInterval.uri, czmlInterval);\n if (defined(sourceUri)) {\n return sourceUri.getDerivedResource({\n url: uri,\n });\n }\n\n return Resource.createIfNeeded(uri);\n}\n\nfunction unwrapRectangleInterval(czmlInterval) {\n let wsen = czmlInterval.wsen;\n if (defined(wsen)) {\n return wsen;\n }\n\n const wsenDegrees = czmlInterval.wsenDegrees;\n if (!defined(wsenDegrees)) {\n return undefined;\n }\n\n const length = wsenDegrees.length;\n if (length === Rectangle.packedLength) {\n return [\n CesiumMath.toRadians(wsenDegrees[0]),\n CesiumMath.toRadians(wsenDegrees[1]),\n CesiumMath.toRadians(wsenDegrees[2]),\n CesiumMath.toRadians(wsenDegrees[3]),\n ];\n }\n\n wsen = new Array(length);\n for (let i = 0; i < length; i += 5) {\n wsen[i] = wsenDegrees[i];\n wsen[i + 1] = CesiumMath.toRadians(wsenDegrees[i + 1]);\n wsen[i + 2] = CesiumMath.toRadians(wsenDegrees[i + 2]);\n wsen[i + 3] = CesiumMath.toRadians(wsenDegrees[i + 3]);\n wsen[i + 4] = CesiumMath.toRadians(wsenDegrees[i + 4]);\n }\n return wsen;\n}\n\nfunction convertUnitSphericalToCartesian(unitSpherical) {\n const length = unitSpherical.length;\n scratchSpherical.magnitude = 1.0;\n if (length === 2) {\n scratchSpherical.clock = unitSpherical[0];\n scratchSpherical.cone = unitSpherical[1];\n Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);\n return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];\n }\n\n const result = new Array((length / 3) * 4);\n for (let i = 0, j = 0; i < length; i += 3, j += 4) {\n result[j] = unitSpherical[i];\n\n scratchSpherical.clock = unitSpherical[i + 1];\n scratchSpherical.cone = unitSpherical[i + 2];\n Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);\n\n result[j + 1] = scratchCartesian.x;\n result[j + 2] = scratchCartesian.y;\n result[j + 3] = scratchCartesian.z;\n }\n return result;\n}\n\nfunction convertSphericalToCartesian(spherical) {\n const length = spherical.length;\n if (length === 3) {\n scratchSpherical.clock = spherical[0];\n scratchSpherical.cone = spherical[1];\n scratchSpherical.magnitude = spherical[2];\n Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);\n return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];\n }\n\n const result = new Array(length);\n for (let i = 0; i < length; i += 4) {\n result[i] = spherical[i];\n\n scratchSpherical.clock = spherical[i + 1];\n scratchSpherical.cone = spherical[i + 2];\n scratchSpherical.magnitude = spherical[i + 3];\n Cartesian3.fromSpherical(scratchSpherical, scratchCartesian);\n\n result[i + 1] = scratchCartesian.x;\n result[i + 2] = scratchCartesian.y;\n result[i + 3] = scratchCartesian.z;\n }\n return result;\n}\n\nfunction convertCartographicRadiansToCartesian(cartographicRadians) {\n const length = cartographicRadians.length;\n if (length === 3) {\n scratchCartographic.longitude = cartographicRadians[0];\n scratchCartographic.latitude = cartographicRadians[1];\n scratchCartographic.height = cartographicRadians[2];\n Ellipsoid.WGS84.cartographicToCartesian(\n scratchCartographic,\n scratchCartesian\n );\n return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];\n }\n\n const result = new Array(length);\n for (let i = 0; i < length; i += 4) {\n result[i] = cartographicRadians[i];\n\n scratchCartographic.longitude = cartographicRadians[i + 1];\n scratchCartographic.latitude = cartographicRadians[i + 2];\n scratchCartographic.height = cartographicRadians[i + 3];\n Ellipsoid.WGS84.cartographicToCartesian(\n scratchCartographic,\n scratchCartesian\n );\n\n result[i + 1] = scratchCartesian.x;\n result[i + 2] = scratchCartesian.y;\n result[i + 3] = scratchCartesian.z;\n }\n return result;\n}\n\nfunction convertCartographicDegreesToCartesian(cartographicDegrees) {\n const length = cartographicDegrees.length;\n if (length === 3) {\n scratchCartographic.longitude = CesiumMath.toRadians(\n cartographicDegrees[0]\n );\n scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[1]);\n scratchCartographic.height = cartographicDegrees[2];\n Ellipsoid.WGS84.cartographicToCartesian(\n scratchCartographic,\n scratchCartesian\n );\n return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z];\n }\n\n const result = new Array(length);\n for (let i = 0; i < length; i += 4) {\n result[i] = cartographicDegrees[i];\n\n scratchCartographic.longitude = CesiumMath.toRadians(\n cartographicDegrees[i + 1]\n );\n scratchCartographic.latitude = CesiumMath.toRadians(\n cartographicDegrees[i + 2]\n );\n scratchCartographic.height = cartographicDegrees[i + 3];\n Ellipsoid.WGS84.cartographicToCartesian(\n scratchCartographic,\n scratchCartesian\n );\n\n result[i + 1] = scratchCartesian.x;\n result[i + 2] = scratchCartesian.y;\n result[i + 3] = scratchCartesian.z;\n }\n return result;\n}\n\nfunction unwrapCartesianInterval(czmlInterval) {\n const cartesian = czmlInterval.cartesian;\n if (defined(cartesian)) {\n return cartesian;\n }\n\n const cartesianVelocity = czmlInterval.cartesianVelocity;\n if (defined(cartesianVelocity)) {\n return cartesianVelocity;\n }\n\n const unitCartesian = czmlInterval.unitCartesian;\n if (defined(unitCartesian)) {\n return unitCartesian;\n }\n\n const unitSpherical = czmlInterval.unitSpherical;\n if (defined(unitSpherical)) {\n return convertUnitSphericalToCartesian(unitSpherical);\n }\n\n const spherical = czmlInterval.spherical;\n if (defined(spherical)) {\n return convertSphericalToCartesian(spherical);\n }\n\n const cartographicRadians = czmlInterval.cartographicRadians;\n if (defined(cartographicRadians)) {\n return convertCartographicRadiansToCartesian(cartographicRadians);\n }\n\n const cartographicDegrees = czmlInterval.cartographicDegrees;\n if (defined(cartographicDegrees)) {\n return convertCartographicDegreesToCartesian(cartographicDegrees);\n }\n\n throw new RuntimeError(\n `${JSON.stringify(czmlInterval)} is not a valid CZML interval.`\n );\n}\n\nfunction normalizePackedCartesianArray(array, startingIndex) {\n Cartesian3.unpack(array, startingIndex, scratchCartesian);\n Cartesian3.normalize(scratchCartesian, scratchCartesian);\n Cartesian3.pack(scratchCartesian, array, startingIndex);\n}\n\nfunction unwrapUnitCartesianInterval(czmlInterval) {\n const cartesian = unwrapCartesianInterval(czmlInterval);\n if (cartesian.length === 3) {\n normalizePackedCartesianArray(cartesian, 0);\n return cartesian;\n }\n\n for (let i = 1; i < cartesian.length; i += 4) {\n normalizePackedCartesianArray(cartesian, i);\n }\n\n return cartesian;\n}\n\nfunction normalizePackedQuaternionArray(array, startingIndex) {\n Quaternion.unpack(array, startingIndex, scratchQuaternion);\n Quaternion.normalize(scratchQuaternion, scratchQuaternion);\n Quaternion.pack(scratchQuaternion, array, startingIndex);\n}\n\nfunction unwrapQuaternionInterval(czmlInterval) {\n const unitQuaternion = czmlInterval.unitQuaternion;\n if (defined(unitQuaternion)) {\n if (unitQuaternion.length === 4) {\n normalizePackedQuaternionArray(unitQuaternion, 0);\n return unitQuaternion;\n }\n\n for (let i = 1; i < unitQuaternion.length; i += 5) {\n normalizePackedQuaternionArray(unitQuaternion, i);\n }\n }\n return unitQuaternion;\n}\n\nfunction getPropertyType(czmlInterval) {\n // The associations in this function need to be kept in sync with the\n // associations in unwrapInterval.\n\n // Intentionally omitted due to conficts in CZML property names:\n // * Image (conflicts with Uri)\n // * Rotation (conflicts with Number)\n //\n // cartesianVelocity is also omitted due to incomplete support for\n // derivative information in CZML properties.\n // (Currently cartesianVelocity is hacked directly into the position processing code)\n if (typeof czmlInterval === \"boolean\") {\n return Boolean;\n } else if (typeof czmlInterval === \"number\") {\n return Number;\n } else if (typeof czmlInterval === \"string\") {\n return String;\n } else if (czmlInterval.hasOwnProperty(\"array\")) {\n return Array;\n } else if (czmlInterval.hasOwnProperty(\"boolean\")) {\n return Boolean;\n } else if (czmlInterval.hasOwnProperty(\"boundingRectangle\")) {\n return BoundingRectangle;\n } else if (czmlInterval.hasOwnProperty(\"cartesian2\")) {\n return Cartesian2;\n } else if (\n czmlInterval.hasOwnProperty(\"cartesian\") ||\n czmlInterval.hasOwnProperty(\"spherical\") ||\n czmlInterval.hasOwnProperty(\"cartographicRadians\") ||\n czmlInterval.hasOwnProperty(\"cartographicDegrees\")\n ) {\n return Cartesian3;\n } else if (\n czmlInterval.hasOwnProperty(\"unitCartesian\") ||\n czmlInterval.hasOwnProperty(\"unitSpherical\")\n ) {\n return UnitCartesian3;\n } else if (\n czmlInterval.hasOwnProperty(\"rgba\") ||\n czmlInterval.hasOwnProperty(\"rgbaf\")\n ) {\n return Color;\n } else if (czmlInterval.hasOwnProperty(\"arcType\")) {\n return ArcType;\n } else if (czmlInterval.hasOwnProperty(\"classificationType\")) {\n return ClassificationType;\n } else if (czmlInterval.hasOwnProperty(\"colorBlendMode\")) {\n return ColorBlendMode;\n } else if (czmlInterval.hasOwnProperty(\"cornerType\")) {\n return CornerType;\n } else if (czmlInterval.hasOwnProperty(\"heightReference\")) {\n return HeightReference;\n } else if (czmlInterval.hasOwnProperty(\"horizontalOrigin\")) {\n return HorizontalOrigin;\n } else if (czmlInterval.hasOwnProperty(\"date\")) {\n return JulianDate;\n } else if (czmlInterval.hasOwnProperty(\"labelStyle\")) {\n return LabelStyle;\n } else if (czmlInterval.hasOwnProperty(\"number\")) {\n return Number;\n } else if (czmlInterval.hasOwnProperty(\"nearFarScalar\")) {\n return NearFarScalar;\n } else if (czmlInterval.hasOwnProperty(\"distanceDisplayCondition\")) {\n return DistanceDisplayCondition;\n } else if (\n czmlInterval.hasOwnProperty(\"object\") ||\n czmlInterval.hasOwnProperty(\"value\")\n ) {\n return Object;\n } else if (czmlInterval.hasOwnProperty(\"unitQuaternion\")) {\n return Quaternion;\n } else if (czmlInterval.hasOwnProperty(\"shadowMode\")) {\n return ShadowMode;\n } else if (czmlInterval.hasOwnProperty(\"string\")) {\n return String;\n } else if (czmlInterval.hasOwnProperty(\"stripeOrientation\")) {\n return StripeOrientation;\n } else if (\n czmlInterval.hasOwnProperty(\"wsen\") ||\n czmlInterval.hasOwnProperty(\"wsenDegrees\")\n ) {\n return Rectangle;\n } else if (czmlInterval.hasOwnProperty(\"uri\")) {\n return Uri;\n } else if (czmlInterval.hasOwnProperty(\"verticalOrigin\")) {\n return VerticalOrigin;\n }\n // fallback case\n return Object;\n}\n\nfunction unwrapInterval(type, czmlInterval, sourceUri) {\n // The associations in this function need to be kept in sync with the\n // associations in getPropertyType\n switch (type) {\n case ArcType:\n return ArcType[defaultValue(czmlInterval.arcType, czmlInterval)];\n case Array:\n return czmlInterval.array;\n case Boolean:\n return defaultValue(czmlInterval[\"boolean\"], czmlInterval);\n case BoundingRectangle:\n return czmlInterval.boundingRectangle;\n case Cartesian2:\n return czmlInterval.cartesian2;\n case Cartesian3:\n return unwrapCartesianInterval(czmlInterval);\n case UnitCartesian3:\n return unwrapUnitCartesianInterval(czmlInterval);\n case Color:\n return unwrapColorInterval(czmlInterval);\n case ClassificationType:\n return ClassificationType[\n defaultValue(czmlInterval.classificationType, czmlInterval)\n ];\n case ColorBlendMode:\n return ColorBlendMode[\n defaultValue(czmlInterval.colorBlendMode, czmlInterval)\n ];\n case CornerType:\n return CornerType[defaultValue(czmlInterval.cornerType, czmlInterval)];\n case HeightReference:\n return HeightReference[\n defaultValue(czmlInterval.heightReference, czmlInterval)\n ];\n case HorizontalOrigin:\n return HorizontalOrigin[\n defaultValue(czmlInterval.horizontalOrigin, czmlInterval)\n ];\n case Image:\n return unwrapUriInterval(czmlInterval, sourceUri);\n case JulianDate:\n return JulianDate.fromIso8601(\n defaultValue(czmlInterval.date, czmlInterval)\n );\n case LabelStyle:\n return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)];\n case Number:\n return defaultValue(czmlInterval.number, czmlInterval);\n case NearFarScalar:\n return czmlInterval.nearFarScalar;\n case DistanceDisplayCondition:\n return czmlInterval.distanceDisplayCondition;\n case Object:\n return defaultValue(\n defaultValue(czmlInterval.object, czmlInterval.value),\n czmlInterval\n );\n case Quaternion:\n return unwrapQuaternionInterval(czmlInterval);\n case Rotation:\n return defaultValue(czmlInterval.number, czmlInterval);\n case ShadowMode:\n return ShadowMode[\n defaultValue(\n defaultValue(czmlInterval.shadowMode, czmlInterval.shadows),\n czmlInterval\n )\n ];\n case String:\n return defaultValue(czmlInterval.string, czmlInterval);\n case StripeOrientation:\n return StripeOrientation[\n defaultValue(czmlInterval.stripeOrientation, czmlInterval)\n ];\n case Rectangle:\n return unwrapRectangleInterval(czmlInterval);\n case Uri:\n return unwrapUriInterval(czmlInterval, sourceUri);\n case VerticalOrigin:\n return VerticalOrigin[\n defaultValue(czmlInterval.verticalOrigin, czmlInterval)\n ];\n default:\n throw new RuntimeError(type);\n }\n}\n\nconst interpolators = {\n HERMITE: HermitePolynomialApproximation,\n LAGRANGE: LagrangePolynomialApproximation,\n LINEAR: LinearApproximation,\n};\n\nfunction updateInterpolationSettings(packetData, property) {\n const interpolationAlgorithm = packetData.interpolationAlgorithm;\n const interpolationDegree = packetData.interpolationDegree;\n if (defined(interpolationAlgorithm) || defined(interpolationDegree)) {\n property.setInterpolationOptions({\n interpolationAlgorithm: interpolators[interpolationAlgorithm],\n interpolationDegree: interpolationDegree,\n });\n }\n\n const forwardExtrapolationType = packetData.forwardExtrapolationType;\n if (defined(forwardExtrapolationType)) {\n property.forwardExtrapolationType =\n ExtrapolationType[forwardExtrapolationType];\n }\n\n const forwardExtrapolationDuration = packetData.forwardExtrapolationDuration;\n if (defined(forwardExtrapolationDuration)) {\n property.forwardExtrapolationDuration = forwardExtrapolationDuration;\n }\n\n const backwardExtrapolationType = packetData.backwardExtrapolationType;\n if (defined(backwardExtrapolationType)) {\n property.backwardExtrapolationType =\n ExtrapolationType[backwardExtrapolationType];\n }\n\n const backwardExtrapolationDuration =\n packetData.backwardExtrapolationDuration;\n if (defined(backwardExtrapolationDuration)) {\n property.backwardExtrapolationDuration = backwardExtrapolationDuration;\n }\n}\n\nconst iso8601Scratch = {\n iso8601: undefined,\n};\n\nfunction intervalFromString(intervalString) {\n if (!defined(intervalString)) {\n return undefined;\n }\n iso8601Scratch.iso8601 = intervalString;\n return TimeInterval.fromIso8601(iso8601Scratch);\n}\n\nfunction wrapPropertyInInfiniteInterval(property) {\n const interval = Iso8601.MAXIMUM_INTERVAL.clone();\n interval.data = property;\n return interval;\n}\n\nfunction convertPropertyToComposite(property) {\n // Create the composite and add the old property, wrapped in an infinite interval.\n const composite = new CompositeProperty();\n composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));\n return composite;\n}\n\nfunction convertPositionPropertyToComposite(property) {\n // Create the composite and add the old property, wrapped in an infinite interval.\n const composite = new CompositePositionProperty(property.referenceFrame);\n composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));\n return composite;\n}\n\nfunction processProperty(\n type,\n object,\n propertyName,\n packetData,\n constrainedInterval,\n sourceUri,\n entityCollection\n) {\n let combinedInterval = intervalFromString(packetData.interval);\n if (defined(constrainedInterval)) {\n if (defined(combinedInterval)) {\n combinedInterval = TimeInterval.intersect(\n combinedInterval,\n constrainedInterval,\n scratchTimeInterval\n );\n } else {\n combinedInterval = constrainedInterval;\n }\n }\n\n let packedLength;\n let unwrappedInterval;\n let unwrappedIntervalLength;\n\n // CZML properties can be defined in many ways. Most ways represent a structure for\n // encoding a single value (number, string, cartesian, etc.) Regardless of the value type,\n // if it encodes a single value it will get loaded into a ConstantProperty eventually.\n // Alternatively, there are ways of defining a property that require specialized\n // client-side representation. Currently, these are ReferenceProperty,\n // and client-side velocity computation properties such as VelocityVectorProperty.\n const isValue =\n !defined(packetData.reference) && !defined(packetData.velocityReference);\n const hasInterval =\n defined(combinedInterval) &&\n !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);\n\n if (packetData.delete === true) {\n // If deleting this property for all time, we can simply set to undefined and return.\n if (!hasInterval) {\n object[propertyName] = undefined;\n return;\n }\n\n // Deleting depends on the type of property we have.\n return removePropertyData(object[propertyName], combinedInterval);\n }\n\n let isSampled = false;\n\n if (isValue) {\n unwrappedInterval = unwrapInterval(type, packetData, sourceUri);\n if (!defined(unwrappedInterval)) {\n // not a known value type, bail\n return;\n }\n packedLength = defaultValue(type.packedLength, 1);\n unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);\n isSampled =\n !defined(packetData.array) &&\n typeof unwrappedInterval !== \"string\" &&\n unwrappedIntervalLength > packedLength &&\n type !== Object;\n }\n\n // Rotation is a special case because it represents a native type (Number)\n // and therefore does not need to be unpacked when loaded as a constant value.\n const needsUnpacking = typeof type.unpack === \"function\" && type !== Rotation;\n\n // Any time a constant value is assigned, it completely blows away anything else.\n if (!isSampled && !hasInterval) {\n if (isValue) {\n object[propertyName] = new ConstantProperty(\n needsUnpacking ? type.unpack(unwrappedInterval, 0) : unwrappedInterval\n );\n } else {\n object[propertyName] = createSpecializedProperty(\n type,\n entityCollection,\n packetData\n );\n }\n return;\n }\n\n let property = object[propertyName];\n\n let epoch;\n const packetEpoch = packetData.epoch;\n if (defined(packetEpoch)) {\n epoch = JulianDate.fromIso8601(packetEpoch);\n }\n\n // Without an interval, any sampled value is infinite, meaning it completely\n // replaces any non-sampled property that may exist.\n if (isSampled && !hasInterval) {\n if (!(property instanceof SampledProperty)) {\n object[propertyName] = property = new SampledProperty(type);\n }\n property.addSamplesPackedArray(unwrappedInterval, epoch);\n updateInterpolationSettings(packetData, property);\n return;\n }\n\n let interval;\n\n // A constant value with an interval is normally part of a TimeIntervalCollection,\n // However, if the current property is not a time-interval collection, we need\n // to turn it into a Composite, preserving the old data with the new interval.\n if (!isSampled && hasInterval) {\n // Create a new interval for the constant value.\n combinedInterval = combinedInterval.clone();\n if (isValue) {\n combinedInterval.data = needsUnpacking\n ? type.unpack(unwrappedInterval, 0)\n : unwrappedInterval;\n } else {\n combinedInterval.data = createSpecializedProperty(\n type,\n entityCollection,\n packetData\n );\n }\n\n // If no property exists, simply use a new interval collection\n if (!defined(property)) {\n object[propertyName] = property = isValue\n ? new TimeIntervalCollectionProperty()\n : new CompositeProperty();\n }\n\n if (isValue && property instanceof TimeIntervalCollectionProperty) {\n // If we created a collection, or it already was one, use it.\n property.intervals.addInterval(combinedInterval);\n } else if (property instanceof CompositeProperty) {\n // If the collection was already a CompositeProperty, use it.\n if (isValue) {\n combinedInterval.data = new ConstantProperty(combinedInterval.data);\n }\n property.intervals.addInterval(combinedInterval);\n } else {\n // Otherwise, create a CompositeProperty but preserve the existing data.\n object[propertyName] = property = convertPropertyToComposite(property);\n\n // Change the new data to a ConstantProperty and add it.\n if (isValue) {\n combinedInterval.data = new ConstantProperty(combinedInterval.data);\n }\n property.intervals.addInterval(combinedInterval);\n }\n\n return;\n }\n\n // isSampled && hasInterval\n if (!defined(property)) {\n object[propertyName] = property = new CompositeProperty();\n }\n\n // Create a CompositeProperty but preserve the existing data.\n if (!(property instanceof CompositeProperty)) {\n object[propertyName] = property = convertPropertyToComposite(property);\n }\n\n // Check if the interval already exists in the composite.\n const intervals = property.intervals;\n interval = intervals.findInterval(combinedInterval);\n if (!defined(interval) || !(interval.data instanceof SampledProperty)) {\n // If not, create a SampledProperty for it.\n interval = combinedInterval.clone();\n interval.data = new SampledProperty(type);\n intervals.addInterval(interval);\n }\n interval.data.addSamplesPackedArray(unwrappedInterval, epoch);\n updateInterpolationSettings(packetData, interval.data);\n}\n\nfunction removePropertyData(property, interval) {\n if (property instanceof SampledProperty) {\n property.removeSamples(interval);\n return;\n } else if (property instanceof TimeIntervalCollectionProperty) {\n property.intervals.removeInterval(interval);\n return;\n } else if (property instanceof CompositeProperty) {\n const intervals = property.intervals;\n for (let i = 0; i < intervals.length; ++i) {\n const intersection = TimeInterval.intersect(\n intervals.get(i),\n interval,\n scratchTimeInterval\n );\n if (!intersection.isEmpty) {\n // remove data from the contained properties\n removePropertyData(intersection.data, interval);\n }\n }\n // remove the intervals from the composite\n intervals.removeInterval(interval);\n return;\n }\n}\n\nfunction processPacketData(\n type,\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, len = packetData.length; i < len; ++i) {\n processProperty(\n type,\n object,\n propertyName,\n packetData[i],\n interval,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processProperty(\n type,\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processPositionProperty(\n object,\n propertyName,\n packetData,\n constrainedInterval,\n sourceUri,\n entityCollection\n) {\n let combinedInterval = intervalFromString(packetData.interval);\n if (defined(constrainedInterval)) {\n if (defined(combinedInterval)) {\n combinedInterval = TimeInterval.intersect(\n combinedInterval,\n constrainedInterval,\n scratchTimeInterval\n );\n } else {\n combinedInterval = constrainedInterval;\n }\n }\n\n const numberOfDerivatives = defined(packetData.cartesianVelocity) ? 1 : 0;\n const packedLength = Cartesian3.packedLength * (numberOfDerivatives + 1);\n let unwrappedInterval;\n let unwrappedIntervalLength;\n const isValue = !defined(packetData.reference);\n const hasInterval =\n defined(combinedInterval) &&\n !combinedInterval.equals(Iso8601.MAXIMUM_INTERVAL);\n\n if (packetData.delete === true) {\n // If deleting this property for all time, we can simply set to undefined and return.\n if (!hasInterval) {\n object[propertyName] = undefined;\n return;\n }\n\n // Deleting depends on the type of property we have.\n return removePositionPropertyData(object[propertyName], combinedInterval);\n }\n\n let referenceFrame;\n let isSampled = false;\n\n if (isValue) {\n if (defined(packetData.referenceFrame)) {\n referenceFrame = ReferenceFrame[packetData.referenceFrame];\n }\n referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n unwrappedInterval = unwrapCartesianInterval(packetData);\n unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1);\n isSampled = unwrappedIntervalLength > packedLength;\n }\n\n // Any time a constant value is assigned, it completely blows away anything else.\n if (!isSampled && !hasInterval) {\n if (isValue) {\n object[propertyName] = new ConstantPositionProperty(\n Cartesian3.unpack(unwrappedInterval),\n referenceFrame\n );\n } else {\n object[propertyName] = createReferenceProperty(\n entityCollection,\n packetData.reference\n );\n }\n return;\n }\n\n let property = object[propertyName];\n\n let epoch;\n const packetEpoch = packetData.epoch;\n if (defined(packetEpoch)) {\n epoch = JulianDate.fromIso8601(packetEpoch);\n }\n\n // Without an interval, any sampled value is infinite, meaning it completely\n // replaces any non-sampled property that may exist.\n if (isSampled && !hasInterval) {\n if (\n !(property instanceof SampledPositionProperty) ||\n (defined(referenceFrame) && property.referenceFrame !== referenceFrame)\n ) {\n object[propertyName] = property = new SampledPositionProperty(\n referenceFrame,\n numberOfDerivatives\n );\n }\n property.addSamplesPackedArray(unwrappedInterval, epoch);\n updateInterpolationSettings(packetData, property);\n return;\n }\n\n let interval;\n\n // A constant value with an interval is normally part of a TimeIntervalCollection,\n // However, if the current property is not a time-interval collection, we need\n // to turn it into a Composite, preserving the old data with the new interval.\n if (!isSampled && hasInterval) {\n // Create a new interval for the constant value.\n combinedInterval = combinedInterval.clone();\n if (isValue) {\n combinedInterval.data = Cartesian3.unpack(unwrappedInterval);\n } else {\n combinedInterval.data = createReferenceProperty(\n entityCollection,\n packetData.reference\n );\n }\n\n // If no property exists, simply use a new interval collection\n if (!defined(property)) {\n if (isValue) {\n property = new TimeIntervalCollectionPositionProperty(referenceFrame);\n } else {\n property = new CompositePositionProperty(referenceFrame);\n }\n object[propertyName] = property;\n }\n\n if (\n isValue &&\n property instanceof TimeIntervalCollectionPositionProperty &&\n defined(referenceFrame) &&\n property.referenceFrame === referenceFrame\n ) {\n // If we create a collection, or it already existed, use it.\n property.intervals.addInterval(combinedInterval);\n } else if (property instanceof CompositePositionProperty) {\n // If the collection was already a CompositePositionProperty, use it.\n if (isValue) {\n combinedInterval.data = new ConstantPositionProperty(\n combinedInterval.data,\n referenceFrame\n );\n }\n property.intervals.addInterval(combinedInterval);\n } else {\n // Otherwise, create a CompositePositionProperty but preserve the existing data.\n object[propertyName] = property = convertPositionPropertyToComposite(\n property\n );\n\n // Change the new data to a ConstantPositionProperty and add it.\n if (isValue) {\n combinedInterval.data = new ConstantPositionProperty(\n combinedInterval.data,\n referenceFrame\n );\n }\n property.intervals.addInterval(combinedInterval);\n }\n\n return;\n }\n\n // isSampled && hasInterval\n if (!defined(property)) {\n object[propertyName] = property = new CompositePositionProperty(\n referenceFrame\n );\n } else if (!(property instanceof CompositePositionProperty)) {\n // Create a CompositeProperty but preserve the existing data.\n object[propertyName] = property = convertPositionPropertyToComposite(\n property\n );\n }\n\n // Check if the interval already exists in the composite.\n const intervals = property.intervals;\n interval = intervals.findInterval(combinedInterval);\n if (\n !defined(interval) ||\n !(interval.data instanceof SampledPositionProperty) ||\n (defined(referenceFrame) && interval.data.referenceFrame !== referenceFrame)\n ) {\n // If not, create a SampledPositionProperty for it.\n interval = combinedInterval.clone();\n interval.data = new SampledPositionProperty(\n referenceFrame,\n numberOfDerivatives\n );\n intervals.addInterval(interval);\n }\n interval.data.addSamplesPackedArray(unwrappedInterval, epoch);\n updateInterpolationSettings(packetData, interval.data);\n}\n\nfunction removePositionPropertyData(property, interval) {\n if (property instanceof SampledPositionProperty) {\n property.removeSamples(interval);\n return;\n } else if (property instanceof TimeIntervalCollectionPositionProperty) {\n property.intervals.removeInterval(interval);\n return;\n } else if (property instanceof CompositePositionProperty) {\n const intervals = property.intervals;\n for (let i = 0; i < intervals.length; ++i) {\n const intersection = TimeInterval.intersect(\n intervals.get(i),\n interval,\n scratchTimeInterval\n );\n if (!intersection.isEmpty) {\n // remove data from the contained properties\n removePositionPropertyData(intersection.data, interval);\n }\n }\n // remove the intervals from the composite\n intervals.removeInterval(interval);\n return;\n }\n}\n\nfunction processPositionPacketData(\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, len = packetData.length; i < len; ++i) {\n processPositionProperty(\n object,\n propertyName,\n packetData[i],\n interval,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processPositionProperty(\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processShapePacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n if (defined(packetData.references)) {\n processReferencesArrayPacketData(\n object,\n propertyName,\n packetData.references,\n packetData.interval,\n entityCollection,\n PropertyArray,\n CompositeProperty\n );\n } else {\n if (defined(packetData.cartesian2)) {\n packetData.array = Cartesian2.unpackArray(packetData.cartesian2);\n } else if (defined(packetData.cartesian)) {\n // for backwards compatibility, also accept `cartesian`\n packetData.array = Cartesian2.unpackArray(packetData.cartesian);\n }\n\n if (defined(packetData.array)) {\n processPacketData(\n Array,\n object,\n propertyName,\n packetData,\n undefined,\n undefined,\n entityCollection\n );\n }\n }\n}\n\nfunction processMaterialProperty(\n object,\n propertyName,\n packetData,\n constrainedInterval,\n sourceUri,\n entityCollection\n) {\n let combinedInterval = intervalFromString(packetData.interval);\n if (defined(constrainedInterval)) {\n if (defined(combinedInterval)) {\n combinedInterval = TimeInterval.intersect(\n combinedInterval,\n constrainedInterval,\n scratchTimeInterval\n );\n } else {\n combinedInterval = constrainedInterval;\n }\n }\n\n let property = object[propertyName];\n let existingMaterial;\n let existingInterval;\n\n if (defined(combinedInterval)) {\n if (!(property instanceof CompositeMaterialProperty)) {\n property = new CompositeMaterialProperty();\n object[propertyName] = property;\n }\n //See if we already have data at that interval.\n const thisIntervals = property.intervals;\n existingInterval = thisIntervals.findInterval({\n start: combinedInterval.start,\n stop: combinedInterval.stop,\n });\n if (defined(existingInterval)) {\n //We have an interval, but we need to make sure the\n //new data is the same type of material as the old data.\n existingMaterial = existingInterval.data;\n } else {\n //If not, create it.\n existingInterval = combinedInterval.clone();\n thisIntervals.addInterval(existingInterval);\n }\n } else {\n existingMaterial = property;\n }\n\n let materialData;\n if (defined(packetData.solidColor)) {\n if (!(existingMaterial instanceof ColorMaterialProperty)) {\n existingMaterial = new ColorMaterialProperty();\n }\n materialData = packetData.solidColor;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n undefined,\n entityCollection\n );\n } else if (defined(packetData.grid)) {\n if (!(existingMaterial instanceof GridMaterialProperty)) {\n existingMaterial = new GridMaterialProperty();\n }\n materialData = packetData.grid;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"cellAlpha\",\n materialData.cellAlpha,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n existingMaterial,\n \"lineCount\",\n materialData.lineCount,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n existingMaterial,\n \"lineThickness\",\n materialData.lineThickness,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n existingMaterial,\n \"lineOffset\",\n materialData.lineOffset,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.image)) {\n if (!(existingMaterial instanceof ImageMaterialProperty)) {\n existingMaterial = new ImageMaterialProperty();\n }\n materialData = packetData.image;\n processPacketData(\n Image,\n existingMaterial,\n \"image\",\n materialData.image,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n existingMaterial,\n \"repeat\",\n materialData.repeat,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n existingMaterial,\n \"transparent\",\n materialData.transparent,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.stripe)) {\n if (!(existingMaterial instanceof StripeMaterialProperty)) {\n existingMaterial = new StripeMaterialProperty();\n }\n materialData = packetData.stripe;\n processPacketData(\n StripeOrientation,\n existingMaterial,\n \"orientation\",\n materialData.orientation,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"evenColor\",\n materialData.evenColor,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"oddColor\",\n materialData.oddColor,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"offset\",\n materialData.offset,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"repeat\",\n materialData.repeat,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.polylineOutline)) {\n if (!(existingMaterial instanceof PolylineOutlineMaterialProperty)) {\n existingMaterial = new PolylineOutlineMaterialProperty();\n }\n materialData = packetData.polylineOutline;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"outlineColor\",\n materialData.outlineColor,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"outlineWidth\",\n materialData.outlineWidth,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.polylineGlow)) {\n if (!(existingMaterial instanceof PolylineGlowMaterialProperty)) {\n existingMaterial = new PolylineGlowMaterialProperty();\n }\n materialData = packetData.polylineGlow;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"glowPower\",\n materialData.glowPower,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"taperPower\",\n materialData.taperPower,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.polylineArrow)) {\n if (!(existingMaterial instanceof PolylineArrowMaterialProperty)) {\n existingMaterial = new PolylineArrowMaterialProperty();\n }\n materialData = packetData.polylineArrow;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n undefined,\n entityCollection\n );\n } else if (defined(packetData.polylineDash)) {\n if (!(existingMaterial instanceof PolylineDashMaterialProperty)) {\n existingMaterial = new PolylineDashMaterialProperty();\n }\n materialData = packetData.polylineDash;\n processPacketData(\n Color,\n existingMaterial,\n \"color\",\n materialData.color,\n undefined,\n undefined,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"gapColor\",\n materialData.gapColor,\n undefined,\n undefined,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"dashLength\",\n materialData.dashLength,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n existingMaterial,\n \"dashPattern\",\n materialData.dashPattern,\n undefined,\n sourceUri,\n entityCollection\n );\n } else if (defined(packetData.checkerboard)) {\n if (!(existingMaterial instanceof CheckerboardMaterialProperty)) {\n existingMaterial = new CheckerboardMaterialProperty();\n }\n materialData = packetData.checkerboard;\n processPacketData(\n Color,\n existingMaterial,\n \"evenColor\",\n materialData.evenColor,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n existingMaterial,\n \"oddColor\",\n materialData.oddColor,\n undefined,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n existingMaterial,\n \"repeat\",\n materialData.repeat,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n\n if (defined(existingInterval)) {\n existingInterval.data = existingMaterial;\n } else {\n object[propertyName] = existingMaterial;\n }\n}\n\nfunction processMaterialPacketData(\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, len = packetData.length; i < len; ++i) {\n processMaterialProperty(\n object,\n propertyName,\n packetData[i],\n interval,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processMaterialProperty(\n object,\n propertyName,\n packetData,\n interval,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processName(entity, packet, entityCollection, sourceUri) {\n const nameData = packet.name;\n if (defined(nameData)) {\n entity.name = packet.name;\n }\n}\n\nfunction processDescription(entity, packet, entityCollection, sourceUri) {\n const descriptionData = packet.description;\n if (defined(descriptionData)) {\n processPacketData(\n String,\n entity,\n \"description\",\n descriptionData,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processPosition(entity, packet, entityCollection, sourceUri) {\n const positionData = packet.position;\n if (defined(positionData)) {\n processPositionPacketData(\n entity,\n \"position\",\n positionData,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processViewFrom(entity, packet, entityCollection, sourceUri) {\n const viewFromData = packet.viewFrom;\n if (defined(viewFromData)) {\n processPacketData(\n Cartesian3,\n entity,\n \"viewFrom\",\n viewFromData,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processOrientation(entity, packet, entityCollection, sourceUri) {\n const orientationData = packet.orientation;\n if (defined(orientationData)) {\n processPacketData(\n Quaternion,\n entity,\n \"orientation\",\n orientationData,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processProperties(entity, packet, entityCollection, sourceUri) {\n const propertiesData = packet.properties;\n if (defined(propertiesData)) {\n if (!defined(entity.properties)) {\n entity.properties = new PropertyBag();\n }\n\n // We cannot simply call processPacketData(entity, 'properties', propertyData, undefined, sourceUri, entityCollection)\n // because each property of \"properties\" may vary separately.\n // The properties will be accessible as entity.properties.myprop.getValue(time).\n\n for (const key in propertiesData) {\n if (propertiesData.hasOwnProperty(key)) {\n if (!entity.properties.hasProperty(key)) {\n entity.properties.addProperty(key);\n }\n\n const propertyData = propertiesData[key];\n if (Array.isArray(propertyData)) {\n for (let i = 0, len = propertyData.length; i < len; ++i) {\n processProperty(\n getPropertyType(propertyData[i]),\n entity.properties,\n key,\n propertyData[i],\n undefined,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processProperty(\n getPropertyType(propertyData),\n entity.properties,\n key,\n propertyData,\n undefined,\n sourceUri,\n entityCollection\n );\n }\n }\n }\n }\n}\n\nfunction processReferencesArrayPacketData(\n object,\n propertyName,\n references,\n interval,\n entityCollection,\n PropertyArrayType,\n CompositePropertyArrayType\n) {\n const properties = references.map(function (reference) {\n return createReferenceProperty(entityCollection, reference);\n });\n\n if (defined(interval)) {\n interval = intervalFromString(interval);\n let property = object[propertyName];\n if (!(property instanceof CompositePropertyArrayType)) {\n // If the property was not already a CompositeProperty,\n // create a CompositeProperty but preserve the existing data.\n\n // Create the composite and add the old property, wrapped in an infinite interval.\n const composite = new CompositePropertyArrayType();\n composite.intervals.addInterval(wrapPropertyInInfiniteInterval(property));\n\n object[propertyName] = property = composite;\n }\n\n interval.data = new PropertyArrayType(properties);\n property.intervals.addInterval(interval);\n } else {\n object[propertyName] = new PropertyArrayType(properties);\n }\n}\n\nfunction processArrayPacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n const references = packetData.references;\n if (defined(references)) {\n processReferencesArrayPacketData(\n object,\n propertyName,\n references,\n packetData.interval,\n entityCollection,\n PropertyArray,\n CompositeProperty\n );\n } else {\n processPacketData(\n Array,\n object,\n propertyName,\n packetData,\n undefined,\n undefined,\n entityCollection\n );\n }\n}\n\nfunction processArray(object, propertyName, packetData, entityCollection) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, length = packetData.length; i < length; ++i) {\n processArrayPacketData(\n object,\n propertyName,\n packetData[i],\n entityCollection\n );\n }\n } else {\n processArrayPacketData(object, propertyName, packetData, entityCollection);\n }\n}\n\nfunction processPositionArrayPacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n const references = packetData.references;\n if (defined(references)) {\n processReferencesArrayPacketData(\n object,\n propertyName,\n references,\n packetData.interval,\n entityCollection,\n PositionPropertyArray,\n CompositePositionProperty\n );\n } else {\n if (defined(packetData.cartesian)) {\n packetData.array = Cartesian3.unpackArray(packetData.cartesian);\n } else if (defined(packetData.cartographicRadians)) {\n packetData.array = Cartesian3.fromRadiansArrayHeights(\n packetData.cartographicRadians,\n Ellipsoid.WGS84\n );\n } else if (defined(packetData.cartographicDegrees)) {\n packetData.array = Cartesian3.fromDegreesArrayHeights(\n packetData.cartographicDegrees,\n Ellipsoid.WGS84\n );\n }\n\n if (defined(packetData.array)) {\n processPacketData(\n Array,\n object,\n propertyName,\n packetData,\n undefined,\n undefined,\n entityCollection\n );\n }\n }\n}\n\nfunction processPositionArray(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, length = packetData.length; i < length; ++i) {\n processPositionArrayPacketData(\n object,\n propertyName,\n packetData[i],\n entityCollection\n );\n }\n } else {\n processPositionArrayPacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n );\n }\n}\n\nfunction unpackCartesianArray(array) {\n return Cartesian3.unpackArray(array);\n}\n\nfunction unpackCartographicRadiansArray(array) {\n return Cartesian3.fromRadiansArrayHeights(array, Ellipsoid.WGS84);\n}\n\nfunction unpackCartographicDegreesArray(array) {\n return Cartesian3.fromDegreesArrayHeights(array, Ellipsoid.WGS84);\n}\n\nfunction processPositionArrayOfArraysPacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n const references = packetData.references;\n if (defined(references)) {\n const properties = references.map(function (referenceArray) {\n const tempObj = {};\n processReferencesArrayPacketData(\n tempObj,\n \"positions\",\n referenceArray,\n packetData.interval,\n entityCollection,\n PositionPropertyArray,\n CompositePositionProperty\n );\n return tempObj.positions;\n });\n object[propertyName] = new PositionPropertyArray(properties);\n } else {\n if (defined(packetData.cartesian)) {\n packetData.array = packetData.cartesian.map(unpackCartesianArray);\n } else if (defined(packetData.cartographicRadians)) {\n packetData.array = packetData.cartographicRadians.map(\n unpackCartographicRadiansArray\n );\n } else if (defined(packetData.cartographicDegrees)) {\n packetData.array = packetData.cartographicDegrees.map(\n unpackCartographicDegreesArray\n );\n }\n\n if (defined(packetData.array)) {\n processPacketData(\n Array,\n object,\n propertyName,\n packetData,\n undefined,\n undefined,\n entityCollection\n );\n }\n }\n}\n\nfunction processPositionArrayOfArrays(\n object,\n propertyName,\n packetData,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, length = packetData.length; i < length; ++i) {\n processPositionArrayOfArraysPacketData(\n object,\n propertyName,\n packetData[i],\n entityCollection\n );\n }\n } else {\n processPositionArrayOfArraysPacketData(\n object,\n propertyName,\n packetData,\n entityCollection\n );\n }\n}\n\nfunction processShape(object, propertyName, packetData, entityCollection) {\n if (!defined(packetData)) {\n return;\n }\n\n if (Array.isArray(packetData)) {\n for (let i = 0, length = packetData.length; i < length; i++) {\n processShapePacketData(\n object,\n propertyName,\n packetData[i],\n entityCollection\n );\n }\n } else {\n processShapePacketData(object, propertyName, packetData, entityCollection);\n }\n}\n\nfunction processAvailability(entity, packet, entityCollection, sourceUri) {\n const packetData = packet.availability;\n if (!defined(packetData)) {\n return;\n }\n\n let intervals;\n if (Array.isArray(packetData)) {\n for (let i = 0, len = packetData.length; i < len; ++i) {\n if (!defined(intervals)) {\n intervals = new TimeIntervalCollection();\n }\n intervals.addInterval(intervalFromString(packetData[i]));\n }\n } else {\n intervals = new TimeIntervalCollection();\n intervals.addInterval(intervalFromString(packetData));\n }\n entity.availability = intervals;\n}\n\nfunction processAlignedAxis(\n billboard,\n packetData,\n interval,\n sourceUri,\n entityCollection\n) {\n if (!defined(packetData)) {\n return;\n }\n\n processPacketData(\n UnitCartesian3,\n billboard,\n \"alignedAxis\",\n packetData,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processBillboard(entity, packet, entityCollection, sourceUri) {\n const billboardData = packet.billboard;\n if (!defined(billboardData)) {\n return;\n }\n\n const interval = intervalFromString(billboardData.interval);\n let billboard = entity.billboard;\n if (!defined(billboard)) {\n entity.billboard = billboard = new BillboardGraphics();\n }\n\n processPacketData(\n Boolean,\n billboard,\n \"show\",\n billboardData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Image,\n billboard,\n \"image\",\n billboardData.image,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n billboard,\n \"scale\",\n billboardData.scale,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n billboard,\n \"pixelOffset\",\n billboardData.pixelOffset,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n billboard,\n \"eyeOffset\",\n billboardData.eyeOffset,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HorizontalOrigin,\n billboard,\n \"horizontalOrigin\",\n billboardData.horizontalOrigin,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n VerticalOrigin,\n billboard,\n \"verticalOrigin\",\n billboardData.verticalOrigin,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n billboard,\n \"heightReference\",\n billboardData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n billboard,\n \"color\",\n billboardData.color,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n billboard,\n \"rotation\",\n billboardData.rotation,\n interval,\n sourceUri,\n entityCollection\n );\n processAlignedAxis(\n billboard,\n billboardData.alignedAxis,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n billboard,\n \"sizeInMeters\",\n billboardData.sizeInMeters,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n billboard,\n \"width\",\n billboardData.width,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n billboard,\n \"height\",\n billboardData.height,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n billboard,\n \"scaleByDistance\",\n billboardData.scaleByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n billboard,\n \"translucencyByDistance\",\n billboardData.translucencyByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n billboard,\n \"pixelOffsetScaleByDistance\",\n billboardData.pixelOffsetScaleByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n BoundingRectangle,\n billboard,\n \"imageSubRegion\",\n billboardData.imageSubRegion,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n billboard,\n \"distanceDisplayCondition\",\n billboardData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n billboard,\n \"disableDepthTestDistance\",\n billboardData.disableDepthTestDistance,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processBox(entity, packet, entityCollection, sourceUri) {\n const boxData = packet.box;\n if (!defined(boxData)) {\n return;\n }\n\n const interval = intervalFromString(boxData.interval);\n let box = entity.box;\n if (!defined(box)) {\n entity.box = box = new BoxGraphics();\n }\n\n processPacketData(\n Boolean,\n box,\n \"show\",\n boxData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n box,\n \"dimensions\",\n boxData.dimensions,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n box,\n \"heightReference\",\n boxData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n box,\n \"fill\",\n boxData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n box,\n \"material\",\n boxData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n box,\n \"outline\",\n boxData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n box,\n \"outlineColor\",\n boxData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n box,\n \"outlineWidth\",\n boxData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n box,\n \"shadows\",\n boxData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n box,\n \"distanceDisplayCondition\",\n boxData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processCorridor(entity, packet, entityCollection, sourceUri) {\n const corridorData = packet.corridor;\n if (!defined(corridorData)) {\n return;\n }\n\n const interval = intervalFromString(corridorData.interval);\n let corridor = entity.corridor;\n if (!defined(corridor)) {\n entity.corridor = corridor = new CorridorGraphics();\n }\n\n processPacketData(\n Boolean,\n corridor,\n \"show\",\n corridorData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPositionArray(\n corridor,\n \"positions\",\n corridorData.positions,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"width\",\n corridorData.width,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"height\",\n corridorData.height,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n corridor,\n \"heightReference\",\n corridorData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"extrudedHeight\",\n corridorData.extrudedHeight,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n corridor,\n \"extrudedHeightReference\",\n corridorData.extrudedHeightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n CornerType,\n corridor,\n \"cornerType\",\n corridorData.cornerType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"granularity\",\n corridorData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n corridor,\n \"fill\",\n corridorData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n corridor,\n \"material\",\n corridorData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n corridor,\n \"outline\",\n corridorData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n corridor,\n \"outlineColor\",\n corridorData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"outlineWidth\",\n corridorData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n corridor,\n \"shadows\",\n corridorData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n corridor,\n \"distanceDisplayCondition\",\n corridorData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ClassificationType,\n corridor,\n \"classificationType\",\n corridorData.classificationType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n corridor,\n \"zIndex\",\n corridorData.zIndex,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processCylinder(entity, packet, entityCollection, sourceUri) {\n const cylinderData = packet.cylinder;\n if (!defined(cylinderData)) {\n return;\n }\n\n const interval = intervalFromString(cylinderData.interval);\n let cylinder = entity.cylinder;\n if (!defined(cylinder)) {\n entity.cylinder = cylinder = new CylinderGraphics();\n }\n\n processPacketData(\n Boolean,\n cylinder,\n \"show\",\n cylinderData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"length\",\n cylinderData.length,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"topRadius\",\n cylinderData.topRadius,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"bottomRadius\",\n cylinderData.bottomRadius,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n cylinder,\n \"heightReference\",\n cylinderData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n cylinder,\n \"fill\",\n cylinderData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n cylinder,\n \"material\",\n cylinderData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n cylinder,\n \"outline\",\n cylinderData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n cylinder,\n \"outlineColor\",\n cylinderData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"outlineWidth\",\n cylinderData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"numberOfVerticalLines\",\n cylinderData.numberOfVerticalLines,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n cylinder,\n \"slices\",\n cylinderData.slices,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n cylinder,\n \"shadows\",\n cylinderData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n cylinder,\n \"distanceDisplayCondition\",\n cylinderData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processDocument(packet, dataSource) {\n const version = packet.version;\n if (defined(version)) {\n if (typeof version === \"string\") {\n const tokens = version.split(\".\");\n if (tokens.length === 2) {\n if (tokens[0] !== \"1\") {\n throw new RuntimeError(\"Cesium only supports CZML version 1.\");\n }\n dataSource._version = version;\n }\n }\n }\n\n if (!defined(dataSource._version)) {\n throw new RuntimeError(\n \"CZML version information invalid. It is expected to be a property on the document object in the . version format.\"\n );\n }\n\n const documentPacket = dataSource._documentPacket;\n\n if (defined(packet.name)) {\n documentPacket.name = packet.name;\n }\n\n const clockPacket = packet.clock;\n if (defined(clockPacket)) {\n const clock = documentPacket.clock;\n if (!defined(clock)) {\n documentPacket.clock = {\n interval: clockPacket.interval,\n currentTime: clockPacket.currentTime,\n range: clockPacket.range,\n step: clockPacket.step,\n multiplier: clockPacket.multiplier,\n };\n } else {\n clock.interval = defaultValue(clockPacket.interval, clock.interval);\n clock.currentTime = defaultValue(\n clockPacket.currentTime,\n clock.currentTime\n );\n clock.range = defaultValue(clockPacket.range, clock.range);\n clock.step = defaultValue(clockPacket.step, clock.step);\n clock.multiplier = defaultValue(clockPacket.multiplier, clock.multiplier);\n }\n }\n}\n\nfunction processEllipse(entity, packet, entityCollection, sourceUri) {\n const ellipseData = packet.ellipse;\n if (!defined(ellipseData)) {\n return;\n }\n\n const interval = intervalFromString(ellipseData.interval);\n let ellipse = entity.ellipse;\n if (!defined(ellipse)) {\n entity.ellipse = ellipse = new EllipseGraphics();\n }\n\n processPacketData(\n Boolean,\n ellipse,\n \"show\",\n ellipseData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"semiMajorAxis\",\n ellipseData.semiMajorAxis,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"semiMinorAxis\",\n ellipseData.semiMinorAxis,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"height\",\n ellipseData.height,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n ellipse,\n \"heightReference\",\n ellipseData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"extrudedHeight\",\n ellipseData.extrudedHeight,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n ellipse,\n \"extrudedHeightReference\",\n ellipseData.extrudedHeightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n ellipse,\n \"rotation\",\n ellipseData.rotation,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n ellipse,\n \"stRotation\",\n ellipseData.stRotation,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"granularity\",\n ellipseData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n ellipse,\n \"fill\",\n ellipseData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n ellipse,\n \"material\",\n ellipseData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n ellipse,\n \"outline\",\n ellipseData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n ellipse,\n \"outlineColor\",\n ellipseData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"outlineWidth\",\n ellipseData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"numberOfVerticalLines\",\n ellipseData.numberOfVerticalLines,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n ellipse,\n \"shadows\",\n ellipseData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n ellipse,\n \"distanceDisplayCondition\",\n ellipseData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ClassificationType,\n ellipse,\n \"classificationType\",\n ellipseData.classificationType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipse,\n \"zIndex\",\n ellipseData.zIndex,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processEllipsoid(entity, packet, entityCollection, sourceUri) {\n const ellipsoidData = packet.ellipsoid;\n if (!defined(ellipsoidData)) {\n return;\n }\n\n const interval = intervalFromString(ellipsoidData.interval);\n let ellipsoid = entity.ellipsoid;\n if (!defined(ellipsoid)) {\n entity.ellipsoid = ellipsoid = new EllipsoidGraphics();\n }\n\n processPacketData(\n Boolean,\n ellipsoid,\n \"show\",\n ellipsoidData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n ellipsoid,\n \"radii\",\n ellipsoidData.radii,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n ellipsoid,\n \"innerRadii\",\n ellipsoidData.innerRadii,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"minimumClock\",\n ellipsoidData.minimumClock,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"maximumClock\",\n ellipsoidData.maximumClock,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"minimumCone\",\n ellipsoidData.minimumCone,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"maximumCone\",\n ellipsoidData.maximumCone,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n ellipsoid,\n \"heightReference\",\n ellipsoidData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n ellipsoid,\n \"fill\",\n ellipsoidData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n ellipsoid,\n \"material\",\n ellipsoidData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n ellipsoid,\n \"outline\",\n ellipsoidData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n ellipsoid,\n \"outlineColor\",\n ellipsoidData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"outlineWidth\",\n ellipsoidData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"stackPartitions\",\n ellipsoidData.stackPartitions,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"slicePartitions\",\n ellipsoidData.slicePartitions,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n ellipsoid,\n \"subdivisions\",\n ellipsoidData.subdivisions,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n ellipsoid,\n \"shadows\",\n ellipsoidData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n ellipsoid,\n \"distanceDisplayCondition\",\n ellipsoidData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processLabel(entity, packet, entityCollection, sourceUri) {\n const labelData = packet.label;\n if (!defined(labelData)) {\n return;\n }\n\n const interval = intervalFromString(labelData.interval);\n let label = entity.label;\n if (!defined(label)) {\n entity.label = label = new LabelGraphics();\n }\n\n processPacketData(\n Boolean,\n label,\n \"show\",\n labelData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n String,\n label,\n \"text\",\n labelData.text,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n String,\n label,\n \"font\",\n labelData.font,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n LabelStyle,\n label,\n \"style\",\n labelData.style,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n label,\n \"scale\",\n labelData.scale,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n label,\n \"showBackground\",\n labelData.showBackground,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n label,\n \"backgroundColor\",\n labelData.backgroundColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n label,\n \"backgroundPadding\",\n labelData.backgroundPadding,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian2,\n label,\n \"pixelOffset\",\n labelData.pixelOffset,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n label,\n \"eyeOffset\",\n labelData.eyeOffset,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HorizontalOrigin,\n label,\n \"horizontalOrigin\",\n labelData.horizontalOrigin,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n VerticalOrigin,\n label,\n \"verticalOrigin\",\n labelData.verticalOrigin,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n label,\n \"heightReference\",\n labelData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n label,\n \"fillColor\",\n labelData.fillColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n label,\n \"outlineColor\",\n labelData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n label,\n \"outlineWidth\",\n labelData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n label,\n \"translucencyByDistance\",\n labelData.translucencyByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n label,\n \"pixelOffsetScaleByDistance\",\n labelData.pixelOffsetScaleByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n label,\n \"scaleByDistance\",\n labelData.scaleByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n label,\n \"distanceDisplayCondition\",\n labelData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n label,\n \"disableDepthTestDistance\",\n labelData.disableDepthTestDistance,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processModel(entity, packet, entityCollection, sourceUri) {\n const modelData = packet.model;\n if (!defined(modelData)) {\n return;\n }\n\n const interval = intervalFromString(modelData.interval);\n let model = entity.model;\n if (!defined(model)) {\n entity.model = model = new ModelGraphics();\n }\n\n processPacketData(\n Boolean,\n model,\n \"show\",\n modelData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Uri,\n model,\n \"uri\",\n modelData.gltf,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n model,\n \"scale\",\n modelData.scale,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n model,\n \"minimumPixelSize\",\n modelData.minimumPixelSize,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n model,\n \"maximumScale\",\n modelData.maximumScale,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n model,\n \"incrementallyLoadTextures\",\n modelData.incrementallyLoadTextures,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n model,\n \"runAnimations\",\n modelData.runAnimations,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n model,\n \"clampAnimations\",\n modelData.clampAnimations,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n model,\n \"shadows\",\n modelData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n model,\n \"heightReference\",\n modelData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n model,\n \"silhouetteColor\",\n modelData.silhouetteColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n model,\n \"silhouetteSize\",\n modelData.silhouetteSize,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n model,\n \"color\",\n modelData.color,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ColorBlendMode,\n model,\n \"colorBlendMode\",\n modelData.colorBlendMode,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n model,\n \"colorBlendAmount\",\n modelData.colorBlendAmount,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n model,\n \"distanceDisplayCondition\",\n modelData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n\n let i, len;\n const nodeTransformationsData = modelData.nodeTransformations;\n if (defined(nodeTransformationsData)) {\n if (Array.isArray(nodeTransformationsData)) {\n for (i = 0, len = nodeTransformationsData.length; i < len; ++i) {\n processNodeTransformations(\n model,\n nodeTransformationsData[i],\n interval,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processNodeTransformations(\n model,\n nodeTransformationsData,\n interval,\n sourceUri,\n entityCollection\n );\n }\n }\n\n const articulationsData = modelData.articulations;\n if (defined(articulationsData)) {\n if (Array.isArray(articulationsData)) {\n for (i = 0, len = articulationsData.length; i < len; ++i) {\n processArticulations(\n model,\n articulationsData[i],\n interval,\n sourceUri,\n entityCollection\n );\n }\n } else {\n processArticulations(\n model,\n articulationsData,\n interval,\n sourceUri,\n entityCollection\n );\n }\n }\n}\n\nfunction processNodeTransformations(\n model,\n nodeTransformationsData,\n constrainedInterval,\n sourceUri,\n entityCollection\n) {\n let combinedInterval = intervalFromString(nodeTransformationsData.interval);\n if (defined(constrainedInterval)) {\n if (defined(combinedInterval)) {\n combinedInterval = TimeInterval.intersect(\n combinedInterval,\n constrainedInterval,\n scratchTimeInterval\n );\n } else {\n combinedInterval = constrainedInterval;\n }\n }\n\n let nodeTransformations = model.nodeTransformations;\n const nodeNames = Object.keys(nodeTransformationsData);\n for (let i = 0, len = nodeNames.length; i < len; ++i) {\n const nodeName = nodeNames[i];\n if (nodeName === \"interval\") {\n continue;\n }\n\n const nodeTransformationData = nodeTransformationsData[nodeName];\n if (!defined(nodeTransformationData)) {\n continue;\n }\n\n if (!defined(nodeTransformations)) {\n model.nodeTransformations = nodeTransformations = new PropertyBag();\n }\n\n if (!nodeTransformations.hasProperty(nodeName)) {\n nodeTransformations.addProperty(nodeName);\n }\n\n let nodeTransformation = nodeTransformations[nodeName];\n if (!defined(nodeTransformation)) {\n nodeTransformations[\n nodeName\n ] = nodeTransformation = new NodeTransformationProperty();\n }\n\n processPacketData(\n Cartesian3,\n nodeTransformation,\n \"translation\",\n nodeTransformationData.translation,\n combinedInterval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Quaternion,\n nodeTransformation,\n \"rotation\",\n nodeTransformationData.rotation,\n combinedInterval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Cartesian3,\n nodeTransformation,\n \"scale\",\n nodeTransformationData.scale,\n combinedInterval,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processArticulations(\n model,\n articulationsData,\n constrainedInterval,\n sourceUri,\n entityCollection\n) {\n let combinedInterval = intervalFromString(articulationsData.interval);\n if (defined(constrainedInterval)) {\n if (defined(combinedInterval)) {\n combinedInterval = TimeInterval.intersect(\n combinedInterval,\n constrainedInterval,\n scratchTimeInterval\n );\n } else {\n combinedInterval = constrainedInterval;\n }\n }\n\n let articulations = model.articulations;\n const keys = Object.keys(articulationsData);\n for (let i = 0, len = keys.length; i < len; ++i) {\n const key = keys[i];\n if (key === \"interval\") {\n continue;\n }\n\n const articulationStageData = articulationsData[key];\n if (!defined(articulationStageData)) {\n continue;\n }\n\n if (!defined(articulations)) {\n model.articulations = articulations = new PropertyBag();\n }\n\n if (!articulations.hasProperty(key)) {\n articulations.addProperty(key);\n }\n\n processPacketData(\n Number,\n articulations,\n key,\n articulationStageData,\n combinedInterval,\n sourceUri,\n entityCollection\n );\n }\n}\n\nfunction processPath(entity, packet, entityCollection, sourceUri) {\n const pathData = packet.path;\n if (!defined(pathData)) {\n return;\n }\n\n const interval = intervalFromString(pathData.interval);\n let path = entity.path;\n if (!defined(path)) {\n entity.path = path = new PathGraphics();\n }\n\n processPacketData(\n Boolean,\n path,\n \"show\",\n pathData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n path,\n \"leadTime\",\n pathData.leadTime,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n path,\n \"trailTime\",\n pathData.trailTime,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n path,\n \"width\",\n pathData.width,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n path,\n \"resolution\",\n pathData.resolution,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n path,\n \"material\",\n pathData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n path,\n \"distanceDisplayCondition\",\n pathData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processPoint(entity, packet, entityCollection, sourceUri) {\n const pointData = packet.point;\n if (!defined(pointData)) {\n return;\n }\n\n const interval = intervalFromString(pointData.interval);\n let point = entity.point;\n if (!defined(point)) {\n entity.point = point = new PointGraphics();\n }\n\n processPacketData(\n Boolean,\n point,\n \"show\",\n pointData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n point,\n \"pixelSize\",\n pointData.pixelSize,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n point,\n \"heightReference\",\n pointData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n point,\n \"color\",\n pointData.color,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n point,\n \"outlineColor\",\n pointData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n point,\n \"outlineWidth\",\n pointData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n point,\n \"scaleByDistance\",\n pointData.scaleByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n NearFarScalar,\n point,\n \"translucencyByDistance\",\n pointData.translucencyByDistance,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n point,\n \"distanceDisplayCondition\",\n pointData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n point,\n \"disableDepthTestDistance\",\n pointData.disableDepthTestDistance,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction PolygonHierarchyProperty(polygon) {\n this.polygon = polygon;\n this._definitionChanged = new Event();\n}\n\nObject.defineProperties(PolygonHierarchyProperty.prototype, {\n isConstant: {\n get: function () {\n const positions = this.polygon._positions;\n const holes = this.polygon._holes;\n return (\n (!defined(positions) || positions.isConstant) &&\n (!defined(holes) || holes.isConstant)\n );\n },\n },\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\nPolygonHierarchyProperty.prototype.getValue = function (time, result) {\n let positions;\n if (defined(this.polygon._positions)) {\n positions = this.polygon._positions.getValue(time);\n }\n\n let holes;\n if (defined(this.polygon._holes)) {\n holes = this.polygon._holes.getValue(time);\n if (defined(holes)) {\n holes = holes.map(function (holePositions) {\n return new PolygonHierarchy(holePositions);\n });\n }\n }\n\n if (!defined(result)) {\n return new PolygonHierarchy(positions, holes);\n }\n\n result.positions = positions;\n result.holes = holes;\n return result;\n};\n\nPolygonHierarchyProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof PolygonHierarchyProperty &&\n Property.equals(this.polygon._positions, other.polygon._positions) &&\n Property.equals(this.polygon._holes, other.polygon._holes))\n );\n};\n\nfunction processPolygon(entity, packet, entityCollection, sourceUri) {\n const polygonData = packet.polygon;\n if (!defined(polygonData)) {\n return;\n }\n\n const interval = intervalFromString(polygonData.interval);\n let polygon = entity.polygon;\n if (!defined(polygon)) {\n entity.polygon = polygon = new PolygonGraphics();\n }\n\n processPacketData(\n Boolean,\n polygon,\n \"show\",\n polygonData.show,\n interval,\n sourceUri,\n entityCollection\n );\n\n // adapt 'position' property producing Cartesian[]\n // and 'holes' property producing Cartesian[][]\n // to a single property producing PolygonHierarchy\n processPositionArray(\n polygon,\n \"_positions\",\n polygonData.positions,\n entityCollection\n );\n processPositionArrayOfArrays(\n polygon,\n \"_holes\",\n polygonData.holes,\n entityCollection\n );\n if (defined(polygon._positions) || defined(polygon._holes)) {\n polygon.hierarchy = new PolygonHierarchyProperty(polygon);\n }\n\n processPacketData(\n Number,\n polygon,\n \"height\",\n polygonData.height,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n polygon,\n \"heightReference\",\n polygonData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polygon,\n \"extrudedHeight\",\n polygonData.extrudedHeight,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n polygon,\n \"extrudedHeightReference\",\n polygonData.extrudedHeightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n polygon,\n \"stRotation\",\n polygonData.stRotation,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polygon,\n \"granularity\",\n polygonData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polygon,\n \"fill\",\n polygonData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n polygon,\n \"material\",\n polygonData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polygon,\n \"outline\",\n polygonData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n polygon,\n \"outlineColor\",\n polygonData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polygon,\n \"outlineWidth\",\n polygonData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polygon,\n \"perPositionHeight\",\n polygonData.perPositionHeight,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polygon,\n \"closeTop\",\n polygonData.closeTop,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polygon,\n \"closeBottom\",\n polygonData.closeBottom,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ArcType,\n polygon,\n \"arcType\",\n polygonData.arcType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n polygon,\n \"shadows\",\n polygonData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n polygon,\n \"distanceDisplayCondition\",\n polygonData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ClassificationType,\n polygon,\n \"classificationType\",\n polygonData.classificationType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polygon,\n \"zIndex\",\n polygonData.zIndex,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction adaptFollowSurfaceToArcType(followSurface) {\n return followSurface ? ArcType.GEODESIC : ArcType.NONE;\n}\n\nfunction processPolyline(entity, packet, entityCollection, sourceUri) {\n const polylineData = packet.polyline;\n if (!defined(polylineData)) {\n return;\n }\n\n const interval = intervalFromString(polylineData.interval);\n let polyline = entity.polyline;\n if (!defined(polyline)) {\n entity.polyline = polyline = new PolylineGraphics();\n }\n\n processPacketData(\n Boolean,\n polyline,\n \"show\",\n polylineData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPositionArray(\n polyline,\n \"positions\",\n polylineData.positions,\n entityCollection\n );\n processPacketData(\n Number,\n polyline,\n \"width\",\n polylineData.width,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polyline,\n \"granularity\",\n polylineData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n polyline,\n \"material\",\n polylineData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n polyline,\n \"depthFailMaterial\",\n polylineData.depthFailMaterial,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ArcType,\n polyline,\n \"arcType\",\n polylineData.arcType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polyline,\n \"clampToGround\",\n polylineData.clampToGround,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n polyline,\n \"shadows\",\n polylineData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n polyline,\n \"distanceDisplayCondition\",\n polylineData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ClassificationType,\n polyline,\n \"classificationType\",\n polylineData.classificationType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polyline,\n \"zIndex\",\n polylineData.zIndex,\n interval,\n sourceUri,\n entityCollection\n );\n\n // for backwards compatibility, adapt CZML followSurface to arcType.\n if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) {\n const tempObj = {};\n processPacketData(\n Boolean,\n tempObj,\n \"followSurface\",\n polylineData.followSurface,\n interval,\n sourceUri,\n entityCollection\n );\n polyline.arcType = createAdapterProperty(\n tempObj.followSurface,\n adaptFollowSurfaceToArcType\n );\n }\n}\n\nfunction processPolylineVolume(entity, packet, entityCollection, sourceUri) {\n const polylineVolumeData = packet.polylineVolume;\n if (!defined(polylineVolumeData)) {\n return;\n }\n\n const interval = intervalFromString(polylineVolumeData.interval);\n let polylineVolume = entity.polylineVolume;\n if (!defined(polylineVolume)) {\n entity.polylineVolume = polylineVolume = new PolylineVolumeGraphics();\n }\n\n processPositionArray(\n polylineVolume,\n \"positions\",\n polylineVolumeData.positions,\n entityCollection\n );\n processShape(\n polylineVolume,\n \"shape\",\n polylineVolumeData.shape,\n entityCollection\n );\n processPacketData(\n Boolean,\n polylineVolume,\n \"show\",\n polylineVolumeData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n CornerType,\n polylineVolume,\n \"cornerType\",\n polylineVolumeData.cornerType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polylineVolume,\n \"fill\",\n polylineVolumeData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n polylineVolume,\n \"material\",\n polylineVolumeData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n polylineVolume,\n \"outline\",\n polylineVolumeData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n polylineVolume,\n \"outlineColor\",\n polylineVolumeData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polylineVolume,\n \"outlineWidth\",\n polylineVolumeData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n polylineVolume,\n \"granularity\",\n polylineVolumeData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n polylineVolume,\n \"shadows\",\n polylineVolumeData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n polylineVolume,\n \"distanceDisplayCondition\",\n polylineVolumeData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processRectangle(entity, packet, entityCollection, sourceUri) {\n const rectangleData = packet.rectangle;\n if (!defined(rectangleData)) {\n return;\n }\n\n const interval = intervalFromString(rectangleData.interval);\n let rectangle = entity.rectangle;\n if (!defined(rectangle)) {\n entity.rectangle = rectangle = new RectangleGraphics();\n }\n\n processPacketData(\n Boolean,\n rectangle,\n \"show\",\n rectangleData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rectangle,\n rectangle,\n \"coordinates\",\n rectangleData.coordinates,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n rectangle,\n \"height\",\n rectangleData.height,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n rectangle,\n \"heightReference\",\n rectangleData.heightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n rectangle,\n \"extrudedHeight\",\n rectangleData.extrudedHeight,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n HeightReference,\n rectangle,\n \"extrudedHeightReference\",\n rectangleData.extrudedHeightReference,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n rectangle,\n \"rotation\",\n rectangleData.rotation,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Rotation,\n rectangle,\n \"stRotation\",\n rectangleData.stRotation,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n rectangle,\n \"granularity\",\n rectangleData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n rectangle,\n \"fill\",\n rectangleData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n rectangle,\n \"material\",\n rectangleData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n rectangle,\n \"outline\",\n rectangleData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n rectangle,\n \"outlineColor\",\n rectangleData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n rectangle,\n \"outlineWidth\",\n rectangleData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n rectangle,\n \"shadows\",\n rectangleData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n rectangle,\n \"distanceDisplayCondition\",\n rectangleData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ClassificationType,\n rectangle,\n \"classificationType\",\n rectangleData.classificationType,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n rectangle,\n \"zIndex\",\n rectangleData.zIndex,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processTileset(entity, packet, entityCollection, sourceUri) {\n const tilesetData = packet.tileset;\n if (!defined(tilesetData)) {\n return;\n }\n\n const interval = intervalFromString(tilesetData.interval);\n let tileset = entity.tileset;\n if (!defined(tileset)) {\n entity.tileset = tileset = new Cesium3DTilesetGraphics();\n }\n\n processPacketData(\n Boolean,\n tileset,\n \"show\",\n tilesetData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Uri,\n tileset,\n \"uri\",\n tilesetData.uri,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n tileset,\n \"maximumScreenSpaceError\",\n tilesetData.maximumScreenSpaceError,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processWall(entity, packet, entityCollection, sourceUri) {\n const wallData = packet.wall;\n if (!defined(wallData)) {\n return;\n }\n\n const interval = intervalFromString(wallData.interval);\n let wall = entity.wall;\n if (!defined(wall)) {\n entity.wall = wall = new WallGraphics();\n }\n\n processPacketData(\n Boolean,\n wall,\n \"show\",\n wallData.show,\n interval,\n sourceUri,\n entityCollection\n );\n processPositionArray(wall, \"positions\", wallData.positions, entityCollection);\n processArray(\n wall,\n \"minimumHeights\",\n wallData.minimumHeights,\n entityCollection\n );\n processArray(\n wall,\n \"maximumHeights\",\n wallData.maximumHeights,\n entityCollection\n );\n processPacketData(\n Number,\n wall,\n \"granularity\",\n wallData.granularity,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n wall,\n \"fill\",\n wallData.fill,\n interval,\n sourceUri,\n entityCollection\n );\n processMaterialPacketData(\n wall,\n \"material\",\n wallData.material,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Boolean,\n wall,\n \"outline\",\n wallData.outline,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Color,\n wall,\n \"outlineColor\",\n wallData.outlineColor,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n Number,\n wall,\n \"outlineWidth\",\n wallData.outlineWidth,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n ShadowMode,\n wall,\n \"shadows\",\n wallData.shadows,\n interval,\n sourceUri,\n entityCollection\n );\n processPacketData(\n DistanceDisplayCondition,\n wall,\n \"distanceDisplayCondition\",\n wallData.distanceDisplayCondition,\n interval,\n sourceUri,\n entityCollection\n );\n}\n\nfunction processCzmlPacket(\n packet,\n entityCollection,\n updaterFunctions,\n sourceUri,\n dataSource\n) {\n let objectId = packet.id;\n if (!defined(objectId)) {\n objectId = createGuid();\n }\n\n currentId = objectId;\n\n if (!defined(dataSource._version) && objectId !== \"document\") {\n throw new RuntimeError(\n \"The first CZML packet is required to be the document object.\"\n );\n }\n\n if (packet[\"delete\"] === true) {\n entityCollection.removeById(objectId);\n } else if (objectId === \"document\") {\n processDocument(packet, dataSource);\n } else {\n const entity = entityCollection.getOrCreateEntity(objectId);\n\n const parentId = packet.parent;\n if (defined(parentId)) {\n entity.parent = entityCollection.getOrCreateEntity(parentId);\n }\n\n for (let i = updaterFunctions.length - 1; i > -1; i--) {\n updaterFunctions[i](entity, packet, entityCollection, sourceUri);\n }\n }\n\n currentId = undefined;\n}\n\nfunction updateClock(dataSource) {\n let clock;\n const clockPacket = dataSource._documentPacket.clock;\n if (!defined(clockPacket)) {\n if (!defined(dataSource._clock)) {\n const availability = dataSource._entityCollection.computeAvailability();\n if (!availability.start.equals(Iso8601.MINIMUM_VALUE)) {\n const startTime = availability.start;\n const stopTime = availability.stop;\n const totalSeconds = JulianDate.secondsDifference(stopTime, startTime);\n const multiplier = Math.round(totalSeconds / 120.0);\n\n clock = new DataSourceClock();\n clock.startTime = JulianDate.clone(startTime);\n clock.stopTime = JulianDate.clone(stopTime);\n clock.clockRange = ClockRange.LOOP_STOP;\n clock.multiplier = multiplier;\n clock.currentTime = JulianDate.clone(startTime);\n clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n dataSource._clock = clock;\n return true;\n }\n }\n return false;\n }\n\n if (defined(dataSource._clock)) {\n clock = dataSource._clock.clone();\n } else {\n clock = new DataSourceClock();\n clock.startTime = Iso8601.MINIMUM_VALUE.clone();\n clock.stopTime = Iso8601.MAXIMUM_VALUE.clone();\n clock.currentTime = Iso8601.MINIMUM_VALUE.clone();\n clock.clockRange = ClockRange.LOOP_STOP;\n clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n clock.multiplier = 1.0;\n }\n\n const interval = intervalFromString(clockPacket.interval);\n if (defined(interval)) {\n clock.startTime = interval.start;\n clock.stopTime = interval.stop;\n }\n\n if (defined(clockPacket.currentTime)) {\n clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime);\n }\n if (defined(clockPacket.range)) {\n clock.clockRange = defaultValue(\n ClockRange[clockPacket.range],\n ClockRange.LOOP_STOP\n );\n }\n if (defined(clockPacket.step)) {\n clock.clockStep = defaultValue(\n ClockStep[clockPacket.step],\n ClockStep.SYSTEM_CLOCK_MULTIPLIER\n );\n }\n if (defined(clockPacket.multiplier)) {\n clock.multiplier = clockPacket.multiplier;\n }\n\n if (!clock.equals(dataSource._clock)) {\n dataSource._clock = clock.clone(dataSource._clock);\n return true;\n }\n\n return false;\n}\n\nfunction load(dataSource, czml, options, clear) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(czml)) {\n throw new DeveloperError(\"czml is required.\");\n }\n //>>includeEnd('debug');\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n let promise = czml;\n let sourceUri = options.sourceUri;\n\n // User specified credit\n let credit = options.credit;\n if (typeof credit === \"string\") {\n credit = new Credit(credit);\n }\n dataSource._credit = credit;\n\n // If the czml is a URL\n if (typeof czml === \"string\" || czml instanceof Resource) {\n czml = Resource.createIfNeeded(czml);\n promise = czml.fetchJson();\n sourceUri = defaultValue(sourceUri, czml.clone());\n\n // Add resource credits to our list of credits to display\n const resourceCredits = dataSource._resourceCredits;\n const credits = czml.credits;\n if (defined(credits)) {\n const length = credits.length;\n for (let i = 0; i < length; i++) {\n resourceCredits.push(credits[i]);\n }\n }\n }\n\n sourceUri = Resource.createIfNeeded(sourceUri);\n\n DataSource.setLoading(dataSource, true);\n\n return Promise.resolve(promise)\n .then(function (czml) {\n return loadCzml(dataSource, czml, sourceUri, clear);\n })\n .catch(function (error) {\n DataSource.setLoading(dataSource, false);\n dataSource._error.raiseEvent(dataSource, error);\n console.log(error);\n return Promise.reject(error);\n });\n}\n\nfunction loadCzml(dataSource, czml, sourceUri, clear) {\n DataSource.setLoading(dataSource, true);\n const entityCollection = dataSource._entityCollection;\n\n if (clear) {\n dataSource._version = undefined;\n dataSource._documentPacket = new DocumentPacket();\n entityCollection.removeAll();\n }\n\n CzmlDataSource._processCzml(\n czml,\n entityCollection,\n sourceUri,\n undefined,\n dataSource\n );\n\n let raiseChangedEvent = updateClock(dataSource);\n\n const documentPacket = dataSource._documentPacket;\n if (\n defined(documentPacket.name) &&\n dataSource._name !== documentPacket.name\n ) {\n dataSource._name = documentPacket.name;\n raiseChangedEvent = true;\n } else if (!defined(dataSource._name) && defined(sourceUri)) {\n dataSource._name = getFilenameFromUri(sourceUri.getUrlComponent());\n raiseChangedEvent = true;\n }\n\n DataSource.setLoading(dataSource, false);\n if (raiseChangedEvent) {\n dataSource._changed.raiseEvent(dataSource);\n }\n\n return dataSource;\n}\n\nfunction DocumentPacket() {\n this.name = undefined;\n this.clock = undefined;\n}\n\n/**\n * @typedef {object} CzmlDataSource.LoadOptions\n *\n * Initialization options for the load method.\n *\n * @property {Resource|string} [sourceUri] Overrides the url to use for resolving relative links.\n * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.\n */\n\n/**\n * A {@link DataSource} which processes {@link https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CZML-Guide|CZML}.\n * @alias CzmlDataSource\n * @constructor\n *\n * @param {string} [name] An optional name for the data source. This value will be overwritten if a loaded document contains a name.\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=CZML.html|Cesium Sandcastle CZML Demo}\n */\nfunction CzmlDataSource(name) {\n this._name = name;\n this._changed = new Event();\n this._error = new Event();\n this._isLoading = false;\n this._loading = new Event();\n this._clock = undefined;\n this._documentPacket = new DocumentPacket();\n this._version = undefined;\n this._entityCollection = new EntityCollection(this);\n this._entityCluster = new EntityCluster();\n this._credit = undefined;\n this._resourceCredits = [];\n}\n\n/**\n * Creates a Promise to a new instance loaded with the provided CZML data.\n *\n * @param {Resource|string|object} czml A url or CZML object to be processed.\n * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that resolves to the new instance once the data is processed.\n */\nCzmlDataSource.load = function (czml, options) {\n return new CzmlDataSource().load(czml, options);\n};\n\nObject.defineProperties(CzmlDataSource.prototype, {\n /**\n * Gets a human-readable name for this instance.\n * @memberof CzmlDataSource.prototype\n * @type {string}\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n /**\n * Gets the clock settings defined by the loaded CZML. If no clock is explicitly\n * defined in the CZML, the combined availability of all objects is returned. If\n * only static data exists, this value is undefined.\n * @memberof CzmlDataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n get: function () {\n return this._clock;\n },\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof CzmlDataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: function () {\n return this._entityCollection;\n },\n },\n /**\n * Gets a value indicating if the data source is currently loading data.\n * @memberof CzmlDataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: function () {\n return this._isLoading;\n },\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof CzmlDataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: function () {\n return this._changed;\n },\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof CzmlDataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: function () {\n return this._error;\n },\n },\n /**\n * Gets an event that will be raised when the data source either starts or stops loading.\n * @memberof CzmlDataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: function () {\n return this._loading;\n },\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof CzmlDataSource.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._entityCollection.show;\n },\n set: function (value) {\n this._entityCollection.show = value;\n },\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof CzmlDataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: function () {\n return this._entityCluster;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value must be defined.\");\n }\n //>>includeEnd('debug');\n this._entityCluster = value;\n },\n },\n /**\n * Gets the credit that will be displayed for the data source\n * @memberof CzmlDataSource.prototype\n * @type {Credit}\n */\n credit: {\n get: function () {\n return this._credit;\n },\n },\n});\n\n/**\n * @callback CzmlDataSource.UpdaterFunction\n *\n * A CZML processing function that adds or updates entities in the provided\n * collection based on the provided CZML packet.\n *\n * @param {Entity} entity\n * @param {object} packet\n * @param {EntityCollection} entityCollection\n * @param {string} sourceUri\n */\n\n/**\n * Gets the array of CZML processing functions.\n * @memberof CzmlDataSource\n * @type {CzmlDataSource.UpdaterFunction[]}\n */\nCzmlDataSource.updaters = [\n processBillboard, //\n processBox, //\n processCorridor, //\n processCylinder, //\n processEllipse, //\n processEllipsoid, //\n processLabel, //\n processModel, //\n processName, //\n processDescription, //\n processPath, //\n processPoint, //\n processPolygon, //\n processPolyline, //\n processPolylineVolume, //\n processProperties, //\n processRectangle, //\n processPosition, //\n processTileset, //\n processViewFrom, //\n processWall, //\n processOrientation, //\n processAvailability,\n];\n\n/**\n * Processes the provided url or CZML object without clearing any existing data.\n *\n * @param {Resource|string|object} czml A url or CZML object to be processed.\n * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that resolves to this instances once the data is processed.\n */\nCzmlDataSource.prototype.process = function (czml, options) {\n return load(this, czml, options, false);\n};\n\n/**\n * Loads the provided url or CZML object, replacing any existing data.\n *\n * @param {Resource|string|object} czml A url or CZML object to be processed.\n * @param {CzmlDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that resolves to this instances once the data is processed.\n */\nCzmlDataSource.prototype.load = function (czml, options) {\n return load(this, czml, options, true);\n};\n\n/**\n * Updates the data source to the provided time. This function is optional and\n * is not required to be implemented. It is provided for data sources which\n * retrieve data based on the current animation time or scene state.\n * If implemented, update will be called by {@link DataSourceDisplay} once a frame.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nCzmlDataSource.prototype.update = function (time) {\n return true;\n};\n\n/**\n * A helper function used by custom CZML updater functions\n * which creates or updates a {@link Property} from a CZML packet.\n * @function\n *\n * @param {Function} type The constructor function for the property being processed.\n * @param {object} object The object on which the property will be added or updated.\n * @param {string} propertyName The name of the property on the object.\n * @param {object} packetData The CZML packet being processed.\n * @param {TimeInterval} interval A constraining interval for which the data is valid.\n * @param {string} sourceUri The originating uri of the data being processed.\n * @param {EntityCollection} entityCollection The collection being processsed.\n */\nCzmlDataSource.processPacketData = processPacketData;\n\n/**\n * A helper function used by custom CZML updater functions\n * which creates or updates a {@link PositionProperty} from a CZML packet.\n * @function\n *\n * @param {object} object The object on which the property will be added or updated.\n * @param {string} propertyName The name of the property on the object.\n * @param {object} packetData The CZML packet being processed.\n * @param {TimeInterval} interval A constraining interval for which the data is valid.\n * @param {string} sourceUri The originating uri of the data being processed.\n * @param {EntityCollection} entityCollection The collection being processsed.\n */\nCzmlDataSource.processPositionPacketData = processPositionPacketData;\n\n/**\n * A helper function used by custom CZML updater functions\n * which creates or updates a {@link MaterialProperty} from a CZML packet.\n * @function\n *\n * @param {object} object The object on which the property will be added or updated.\n * @param {string} propertyName The name of the property on the object.\n * @param {object} packetData The CZML packet being processed.\n * @param {TimeInterval} interval A constraining interval for which the data is valid.\n * @param {string} sourceUri The originating uri of the data being processed.\n * @param {EntityCollection} entityCollection The collection being processsed.\n */\nCzmlDataSource.processMaterialPacketData = processMaterialPacketData;\n\nCzmlDataSource._processCzml = function (\n czml,\n entityCollection,\n sourceUri,\n updaterFunctions,\n dataSource\n) {\n updaterFunctions = defaultValue(updaterFunctions, CzmlDataSource.updaters);\n\n if (Array.isArray(czml)) {\n for (let i = 0, len = czml.length; i < len; ++i) {\n processCzmlPacket(\n czml[i],\n entityCollection,\n updaterFunctions,\n sourceUri,\n dataSource\n );\n }\n } else {\n processCzmlPacket(\n czml,\n entityCollection,\n updaterFunctions,\n sourceUri,\n dataSource\n );\n }\n};\nexport default CzmlDataSource;\n", "/**\n * Gets a timestamp that can be used in measuring the time between events. Timestamps\n * are expressed in milliseconds, but it is not specified what the milliseconds are\n * measured from. This function uses performance.now() if it is available, or Date.now()\n * otherwise.\n *\n * @function getTimestamp\n *\n * @returns {number} The timestamp in milliseconds since some unspecified reference time.\n */\nlet getTimestamp;\n\nif (\n typeof performance !== \"undefined\" &&\n typeof performance.now === \"function\" &&\n isFinite(performance.now())\n) {\n getTimestamp = function () {\n return performance.now();\n };\n} else {\n getTimestamp = function () {\n return Date.now();\n };\n}\nexport default getTimestamp;\n", "import ClockRange from \"./ClockRange.js\";\nimport ClockStep from \"./ClockStep.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Event from \"./Event.js\";\nimport getTimestamp from \"./getTimestamp.js\";\nimport JulianDate from \"./JulianDate.js\";\n\n/**\n * A simple clock for keeping track of simulated time.\n *\n * @alias Clock\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {JulianDate} [options.startTime] The start time of the clock.\n * @param {JulianDate} [options.stopTime] The stop time of the clock.\n * @param {JulianDate} [options.currentTime] The current time.\n * @param {number} [options.multiplier=1.0] Determines how much time advances when {@link Clock#tick} is called, negative values allow for advancing backwards.\n * @param {ClockStep} [options.clockStep=ClockStep.SYSTEM_CLOCK_MULTIPLIER] Determines if calls to {@link Clock#tick} are frame dependent or system clock dependent.\n * @param {ClockRange} [options.clockRange=ClockRange.UNBOUNDED] Determines how the clock should behave when {@link Clock#startTime} or {@link Clock#stopTime} is reached.\n * @param {boolean} [options.canAnimate=true] Indicates whether {@link Clock#tick} can advance time. This could be false if data is being buffered, for example. The clock will only tick when both {@link Clock#canAnimate} and {@link Clock#shouldAnimate} are true.\n * @param {boolean} [options.shouldAnimate=false] Indicates whether {@link Clock#tick} should attempt to advance time. The clock will only tick when both {@link Clock#canAnimate} and {@link Clock#shouldAnimate} are true.\n *\n * @exception {DeveloperError} startTime must come before stopTime.\n *\n *\n * @example\n * // Create a clock that loops on Christmas day 2013 and runs in real-time.\n * const clock = new Cesium.Clock({\n * startTime : Cesium.JulianDate.fromIso8601(\"2013-12-25\"),\n * currentTime : Cesium.JulianDate.fromIso8601(\"2013-12-25\"),\n * stopTime : Cesium.JulianDate.fromIso8601(\"2013-12-26\"),\n * clockRange : Cesium.ClockRange.LOOP_STOP,\n * clockStep : Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER\n * });\n *\n * @see ClockStep\n * @see ClockRange\n * @see JulianDate\n */\nfunction Clock(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n let currentTime = options.currentTime;\n let startTime = options.startTime;\n let stopTime = options.stopTime;\n\n if (!defined(currentTime)) {\n // if not specified, current time is the start time,\n // or if that is not specified, 1 day before the stop time,\n // or if that is not specified, then now.\n if (defined(startTime)) {\n currentTime = JulianDate.clone(startTime);\n } else if (defined(stopTime)) {\n currentTime = JulianDate.addDays(stopTime, -1.0, new JulianDate());\n } else {\n currentTime = JulianDate.now();\n }\n } else {\n currentTime = JulianDate.clone(currentTime);\n }\n\n if (!defined(startTime)) {\n // if not specified, start time is the current time\n // (as determined above)\n startTime = JulianDate.clone(currentTime);\n } else {\n startTime = JulianDate.clone(startTime);\n }\n\n if (!defined(stopTime)) {\n // if not specified, stop time is 1 day after the start time\n // (as determined above)\n stopTime = JulianDate.addDays(startTime, 1.0, new JulianDate());\n } else {\n stopTime = JulianDate.clone(stopTime);\n }\n\n //>>includeStart('debug', pragmas.debug);\n if (JulianDate.greaterThan(startTime, stopTime)) {\n throw new DeveloperError(\"startTime must come before stopTime.\");\n }\n //>>includeEnd('debug');\n\n /**\n * The start time of the clock.\n * @type {JulianDate}\n */\n this.startTime = startTime;\n\n /**\n * The stop time of the clock.\n * @type {JulianDate}\n */\n this.stopTime = stopTime;\n\n /**\n * Determines how the clock should behave when\n * {@link Clock#startTime} or {@link Clock#stopTime}\n * is reached.\n * @type {ClockRange}\n * @default {@link ClockRange.UNBOUNDED}\n */\n this.clockRange = defaultValue(options.clockRange, ClockRange.UNBOUNDED);\n\n /**\n * Indicates whether {@link Clock#tick} can advance time. This could be false if data is being buffered,\n * for example. The clock will only advance time when both\n * {@link Clock#canAnimate} and {@link Clock#shouldAnimate} are true.\n * @type {boolean}\n * @default true\n */\n this.canAnimate = defaultValue(options.canAnimate, true);\n\n /**\n * An {@link Event} that is fired whenever {@link Clock#tick} is called.\n * @type {Event}\n */\n this.onTick = new Event();\n /**\n * An {@link Event} that is fired whenever {@link Clock#stopTime} is reached.\n * @type {Event}\n */\n this.onStop = new Event();\n\n this._currentTime = undefined;\n this._multiplier = undefined;\n this._clockStep = undefined;\n this._shouldAnimate = undefined;\n this._lastSystemTime = getTimestamp();\n\n // set values using the property setters to\n // make values consistent.\n\n this.currentTime = currentTime;\n this.multiplier = defaultValue(options.multiplier, 1.0);\n this.shouldAnimate = defaultValue(options.shouldAnimate, false);\n this.clockStep = defaultValue(\n options.clockStep,\n ClockStep.SYSTEM_CLOCK_MULTIPLIER\n );\n}\n\nObject.defineProperties(Clock.prototype, {\n /**\n * The current time.\n * Changing this property will change\n * {@link Clock#clockStep} from {@link ClockStep.SYSTEM_CLOCK} to\n * {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}.\n * @memberof Clock.prototype\n * @type {JulianDate}\n */\n currentTime: {\n get: function () {\n return this._currentTime;\n },\n set: function (value) {\n if (JulianDate.equals(this._currentTime, value)) {\n return;\n }\n\n if (this._clockStep === ClockStep.SYSTEM_CLOCK) {\n this._clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n }\n\n this._currentTime = value;\n },\n },\n\n /**\n * Gets or sets how much time advances when {@link Clock#tick} is called. Negative values allow for advancing backwards.\n * If {@link Clock#clockStep} is set to {@link ClockStep.TICK_DEPENDENT}, this is the number of seconds to advance.\n * If {@link Clock#clockStep} is set to {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}, this value is multiplied by the\n * elapsed system time since the last call to {@link Clock#tick}.\n * Changing this property will change\n * {@link Clock#clockStep} from {@link ClockStep.SYSTEM_CLOCK} to\n * {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}.\n * @memberof Clock.prototype\n * @type {number}\n * @default 1.0\n */\n multiplier: {\n get: function () {\n return this._multiplier;\n },\n set: function (value) {\n if (this._multiplier === value) {\n return;\n }\n\n if (this._clockStep === ClockStep.SYSTEM_CLOCK) {\n this._clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n }\n\n this._multiplier = value;\n },\n },\n\n /**\n * Determines if calls to {@link Clock#tick} are frame dependent or system clock dependent.\n * Changing this property to {@link ClockStep.SYSTEM_CLOCK} will set\n * {@link Clock#multiplier} to 1.0, {@link Clock#shouldAnimate} to true, and\n * {@link Clock#currentTime} to the current system clock time.\n * @memberof Clock.prototype\n * @type ClockStep\n * @default {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}\n */\n clockStep: {\n get: function () {\n return this._clockStep;\n },\n set: function (value) {\n if (value === ClockStep.SYSTEM_CLOCK) {\n this._multiplier = 1.0;\n this._shouldAnimate = true;\n this._currentTime = JulianDate.now();\n }\n\n this._clockStep = value;\n },\n },\n\n /**\n * Indicates whether {@link Clock#tick} should attempt to advance time.\n * The clock will only advance time when both\n * {@link Clock#canAnimate} and {@link Clock#shouldAnimate} are true.\n * Changing this property will change\n * {@link Clock#clockStep} from {@link ClockStep.SYSTEM_CLOCK} to\n * {@link ClockStep.SYSTEM_CLOCK_MULTIPLIER}.\n * @memberof Clock.prototype\n * @type {boolean}\n * @default false\n */\n shouldAnimate: {\n get: function () {\n return this._shouldAnimate;\n },\n set: function (value) {\n if (this._shouldAnimate === value) {\n return;\n }\n\n if (this._clockStep === ClockStep.SYSTEM_CLOCK) {\n this._clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n }\n\n this._shouldAnimate = value;\n },\n },\n});\n\n/**\n * Advances the clock from the current time based on the current configuration options.\n * tick should be called every frame, regardless of whether animation is taking place\n * or not. To control animation, use the {@link Clock#shouldAnimate} property.\n *\n * @returns {JulianDate} The new value of the {@link Clock#currentTime} property.\n */\nClock.prototype.tick = function () {\n const currentSystemTime = getTimestamp();\n let currentTime = JulianDate.clone(this._currentTime);\n\n if (this.canAnimate && this._shouldAnimate) {\n const clockStep = this._clockStep;\n if (clockStep === ClockStep.SYSTEM_CLOCK) {\n currentTime = JulianDate.now(currentTime);\n } else {\n const multiplier = this._multiplier;\n\n if (clockStep === ClockStep.TICK_DEPENDENT) {\n currentTime = JulianDate.addSeconds(\n currentTime,\n multiplier,\n currentTime\n );\n } else {\n const milliseconds = currentSystemTime - this._lastSystemTime;\n currentTime = JulianDate.addSeconds(\n currentTime,\n multiplier * (milliseconds / 1000.0),\n currentTime\n );\n }\n\n const clockRange = this.clockRange;\n const startTime = this.startTime;\n const stopTime = this.stopTime;\n\n if (clockRange === ClockRange.CLAMPED) {\n if (JulianDate.lessThan(currentTime, startTime)) {\n currentTime = JulianDate.clone(startTime, currentTime);\n } else if (JulianDate.greaterThan(currentTime, stopTime)) {\n currentTime = JulianDate.clone(stopTime, currentTime);\n this.onStop.raiseEvent(this);\n }\n } else if (clockRange === ClockRange.LOOP_STOP) {\n if (JulianDate.lessThan(currentTime, startTime)) {\n currentTime = JulianDate.clone(startTime, currentTime);\n }\n while (JulianDate.greaterThan(currentTime, stopTime)) {\n currentTime = JulianDate.addSeconds(\n startTime,\n JulianDate.secondsDifference(currentTime, stopTime),\n currentTime\n );\n this.onStop.raiseEvent(this);\n }\n }\n }\n }\n\n this._currentTime = currentTime;\n this._lastSystemTime = currentSystemTime;\n this.onTick.raiseEvent(this);\n return currentTime;\n};\nexport default Clock;\n", "import Clock from \"../Core/Clock.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport createRawPropertyDescriptor from \"./createRawPropertyDescriptor.js\";\n\n/**\n * Represents desired clock settings for a particular {@link DataSource}. These settings may be applied\n * to the {@link Clock} when the DataSource is loaded.\n *\n * @alias DataSourceClock\n * @constructor\n */\nfunction DataSourceClock() {\n this._definitionChanged = new Event();\n this._startTime = undefined;\n this._stopTime = undefined;\n this._currentTime = undefined;\n this._clockRange = undefined;\n this._clockStep = undefined;\n this._multiplier = undefined;\n}\n\nObject.defineProperties(DataSourceClock.prototype, {\n /**\n * Gets the event that is raised whenever a new property is assigned.\n * @memberof DataSourceClock.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the desired start time of the clock.\n * See {@link Clock#startTime}.\n * @memberof DataSourceClock.prototype\n * @type {JulianDate}\n */\n startTime: createRawPropertyDescriptor(\"startTime\"),\n\n /**\n * Gets or sets the desired stop time of the clock.\n * See {@link Clock#stopTime}.\n * @memberof DataSourceClock.prototype\n * @type {JulianDate}\n */\n stopTime: createRawPropertyDescriptor(\"stopTime\"),\n\n /**\n * Gets or sets the desired current time when this data source is loaded.\n * See {@link Clock#currentTime}.\n * @memberof DataSourceClock.prototype\n * @type {JulianDate}\n */\n currentTime: createRawPropertyDescriptor(\"currentTime\"),\n\n /**\n * Gets or sets the desired clock range setting.\n * See {@link Clock#clockRange}.\n * @memberof DataSourceClock.prototype\n * @type {ClockRange}\n */\n clockRange: createRawPropertyDescriptor(\"clockRange\"),\n\n /**\n * Gets or sets the desired clock step setting.\n * See {@link Clock#clockStep}.\n * @memberof DataSourceClock.prototype\n * @type {ClockStep}\n */\n clockStep: createRawPropertyDescriptor(\"clockStep\"),\n\n /**\n * Gets or sets the desired clock multiplier.\n * See {@link Clock#multiplier}.\n * @memberof DataSourceClock.prototype\n * @type {number}\n */\n multiplier: createRawPropertyDescriptor(\"multiplier\"),\n});\n\n/**\n * Duplicates a DataSourceClock instance.\n *\n * @param {DataSourceClock} [result] The object onto which to store the result.\n * @returns {DataSourceClock} The modified result parameter or a new instance if one was not provided.\n */\nDataSourceClock.prototype.clone = function (result) {\n if (!defined(result)) {\n result = new DataSourceClock();\n }\n result.startTime = this.startTime;\n result.stopTime = this.stopTime;\n result.currentTime = this.currentTime;\n result.clockRange = this.clockRange;\n result.clockStep = this.clockStep;\n result.multiplier = this.multiplier;\n return result;\n};\n\n/**\n * Returns true if this DataSourceClock is equivalent to the other\n *\n * @param {DataSourceClock} other The other DataSourceClock to compare to.\n * @returns {boolean} true if the DataSourceClocks are equal; otherwise, false.\n */\nDataSourceClock.prototype.equals = function (other) {\n return (\n this === other ||\n (defined(other) &&\n JulianDate.equals(this.startTime, other.startTime) &&\n JulianDate.equals(this.stopTime, other.stopTime) &&\n JulianDate.equals(this.currentTime, other.currentTime) &&\n this.clockRange === other.clockRange &&\n this.clockStep === other.clockStep &&\n this.multiplier === other.multiplier)\n );\n};\n\n/**\n * Assigns each unassigned property on this object to the value\n * of the same property on the provided source object.\n *\n * @param {DataSourceClock} source The object to be merged into this object.\n */\nDataSourceClock.prototype.merge = function (source) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(source)) {\n throw new DeveloperError(\"source is required.\");\n }\n //>>includeEnd('debug');\n\n this.startTime = defaultValue(this.startTime, source.startTime);\n this.stopTime = defaultValue(this.stopTime, source.stopTime);\n this.currentTime = defaultValue(this.currentTime, source.currentTime);\n this.clockRange = defaultValue(this.clockRange, source.clockRange);\n this.clockStep = defaultValue(this.clockStep, source.clockStep);\n this.multiplier = defaultValue(this.multiplier, source.multiplier);\n};\n\n/**\n * Gets the value of this clock instance as a {@link Clock} object.\n *\n * @returns {Clock} The modified result parameter or a new instance if one was not provided.\n */\nDataSourceClock.prototype.getValue = function (result) {\n if (!defined(result)) {\n result = new Clock();\n }\n result.startTime = defaultValue(this.startTime, result.startTime);\n result.stopTime = defaultValue(this.stopTime, result.stopTime);\n result.currentTime = defaultValue(this.currentTime, result.currentTime);\n result.clockRange = defaultValue(this.clockRange, result.clockRange);\n result.multiplier = defaultValue(this.multiplier, result.multiplier);\n result.clockStep = defaultValue(this.clockStep, result.clockStep);\n return result;\n};\nexport default DataSourceClock;\n", "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultCellAlpha = 0.1;\nconst defaultLineCount = new Cartesian2(8, 8);\nconst defaultLineOffset = new Cartesian2(0, 0);\nconst defaultLineThickness = new Cartesian2(1, 1);\n\n/**\n * A {@link MaterialProperty} that maps to grid {@link Material} uniforms.\n * @alias GridMaterialProperty\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the grid {@link Color}.\n * @param {Property|number} [options.cellAlpha=0.1] A numeric Property specifying cell alpha values.\n * @param {Property|Cartesian2} [options.lineCount=new Cartesian2(8, 8)] A {@link Cartesian2} Property specifying the number of grid lines along each axis.\n * @param {Property|Cartesian2} [options.lineThickness=new Cartesian2(1.0, 1.0)] A {@link Cartesian2} Property specifying the thickness of grid lines along each axis.\n * @param {Property|Cartesian2} [options.lineOffset=new Cartesian2(0.0, 0.0)] A {@link Cartesian2} Property specifying starting offset of grid lines along each axis.\n *\n * @constructor\n */\nfunction GridMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n this._cellAlpha = undefined;\n this._cellAlphaSubscription = undefined;\n this._lineCount = undefined;\n this._lineCountSubscription = undefined;\n this._lineThickness = undefined;\n this._lineThicknessSubscription = undefined;\n this._lineOffset = undefined;\n this._lineOffsetSubscription = undefined;\n\n this.color = options.color;\n this.cellAlpha = options.cellAlpha;\n this.lineCount = options.lineCount;\n this.lineThickness = options.lineThickness;\n this.lineOffset = options.lineOffset;\n}\n\nObject.defineProperties(GridMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof GridMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._color) &&\n Property.isConstant(this._cellAlpha) &&\n Property.isConstant(this._lineCount) &&\n Property.isConstant(this._lineThickness) &&\n Property.isConstant(this._lineOffset)\n );\n },\n },\n\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof GridMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the Property specifying the grid {@link Color}.\n * @memberof GridMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the numeric Property specifying cell alpha values.\n * @memberof GridMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 0.1\n */\n cellAlpha: createPropertyDescriptor(\"cellAlpha\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the number of grid lines along each axis.\n * @memberof GridMaterialProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(8.0, 8.0)\n */\n lineCount: createPropertyDescriptor(\"lineCount\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the thickness of grid lines along each axis.\n * @memberof GridMaterialProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(1.0, 1.0)\n */\n lineThickness: createPropertyDescriptor(\"lineThickness\"),\n\n /**\n * Gets or sets the {@link Cartesian2} Property specifying the starting offset of grid lines along each axis.\n * @memberof GridMaterialProperty.prototype\n * @type {Property|undefined}\n * @default new Cartesian2(0.0, 0.0)\n */\n lineOffset: createPropertyDescriptor(\"lineOffset\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nGridMaterialProperty.prototype.getType = function (time) {\n return \"Grid\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nGridMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n defaultColor,\n result.color\n );\n result.cellAlpha = Property.getValueOrDefault(\n this._cellAlpha,\n time,\n defaultCellAlpha\n );\n result.lineCount = Property.getValueOrClonedDefault(\n this._lineCount,\n time,\n defaultLineCount,\n result.lineCount\n );\n result.lineThickness = Property.getValueOrClonedDefault(\n this._lineThickness,\n time,\n defaultLineThickness,\n result.lineThickness\n );\n result.lineOffset = Property.getValueOrClonedDefault(\n this._lineOffset,\n time,\n defaultLineOffset,\n result.lineOffset\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nGridMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof GridMaterialProperty && //\n Property.equals(this._color, other._color) && //\n Property.equals(this._cellAlpha, other._cellAlpha) && //\n Property.equals(this._lineCount, other._lineCount) && //\n Property.equals(this._lineThickness, other._lineThickness) && //\n Property.equals(this._lineOffset, other._lineOffset))\n );\n};\nexport default GridMaterialProperty;\n", "import Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link MaterialProperty} that maps to PolylineArrow {@link Material} uniforms.\n *\n * @param {Property|Color} [color=Color.WHITE] The {@link Color} Property to be used.\n *\n * @alias PolylineArrowMaterialProperty\n * @constructor\n */\nfunction PolylineArrowMaterialProperty(color) {\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n\n this.color = color;\n}\n\nObject.defineProperties(PolylineArrowMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof PolylineArrowMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return Property.isConstant(this._color);\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof PolylineArrowMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the {@link Color} {@link Property}.\n * @memberof PolylineArrowMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nPolylineArrowMaterialProperty.prototype.getType = function (time) {\n return \"PolylineArrow\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPolylineArrowMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n Color.WHITE,\n result.color\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPolylineArrowMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PolylineArrowMaterialProperty && //\n Property.equals(this._color, other._color))\n );\n};\nexport default PolylineArrowMaterialProperty;\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultGapColor = Color.TRANSPARENT;\nconst defaultDashLength = 16.0;\nconst defaultDashPattern = 255.0;\n\n/**\n * A {@link MaterialProperty} that maps to polyline dash {@link Material} uniforms.\n * @alias PolylineDashMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.\n * @param {Property|Color} [options.gapColor=Color.TRANSPARENT] A Property specifying the {@link Color} of the gaps in the line.\n * @param {Property|number} [options.dashLength=16.0] A numeric Property specifying the length of the dash pattern in pixels.\n * @param {Property|number} [options.dashPattern=255.0] A numeric Property specifying a 16 bit pattern for the dash\n */\nfunction PolylineDashMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n this._gapColor = undefined;\n this._gapColorSubscription = undefined;\n this._dashLength = undefined;\n this._dashLengthSubscription = undefined;\n this._dashPattern = undefined;\n this._dashPatternSubscription = undefined;\n\n this.color = options.color;\n this.gapColor = options.gapColor;\n this.dashLength = options.dashLength;\n this.dashPattern = options.dashPattern;\n}\n\nObject.defineProperties(PolylineDashMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._color) &&\n Property.isConstant(this._gapColor) &&\n Property.isConstant(this._dashLength) &&\n Property.isConstant(this._dashPattern)\n );\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the Property specifying the {@link Color} of the line.\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {Property|undefined}\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the gaps in the line.\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {Property|undefined}\n */\n gapColor: createPropertyDescriptor(\"gapColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the length of a dash cycle\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {Property|undefined}\n */\n dashLength: createPropertyDescriptor(\"dashLength\"),\n\n /**\n * Gets or sets the numeric Property specifying a dash pattern\n * @memberof PolylineDashMaterialProperty.prototype\n * @type {Property|undefined}\n */\n dashPattern: createPropertyDescriptor(\"dashPattern\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nPolylineDashMaterialProperty.prototype.getType = function (time) {\n return \"PolylineDash\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPolylineDashMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n defaultColor,\n result.color\n );\n result.gapColor = Property.getValueOrClonedDefault(\n this._gapColor,\n time,\n defaultGapColor,\n result.gapColor\n );\n result.dashLength = Property.getValueOrDefault(\n this._dashLength,\n time,\n defaultDashLength,\n result.dashLength\n );\n result.dashPattern = Property.getValueOrDefault(\n this._dashPattern,\n time,\n defaultDashPattern,\n result.dashPattern\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPolylineDashMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PolylineDashMaterialProperty &&\n Property.equals(this._color, other._color) &&\n Property.equals(this._gapColor, other._gapColor) &&\n Property.equals(this._dashLength, other._dashLength) &&\n Property.equals(this._dashPattern, other._dashPattern))\n );\n};\nexport default PolylineDashMaterialProperty;\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultGlowPower = 0.25;\nconst defaultTaperPower = 1.0;\n\n/**\n * A {@link MaterialProperty} that maps to polyline glow {@link Material} uniforms.\n * @alias PolylineGlowMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.\n * @param {Property|number} [options.glowPower=0.25] A numeric Property specifying the strength of the glow, as a percentage of the total line width.\n * @param {Property|number} [options.taperPower=1.0] A numeric Property specifying the strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.\n */\nfunction PolylineGlowMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n this._glowPower = undefined;\n this._glowPowerSubscription = undefined;\n this._taperPower = undefined;\n this._taperPowerSubscription = undefined;\n\n this.color = options.color;\n this.glowPower = options.glowPower;\n this.taperPower = options.taperPower;\n}\n\nObject.defineProperties(PolylineGlowMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof PolylineGlowMaterialProperty.prototype\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._color) && Property.isConstant(this._glow)\n );\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof PolylineGlowMaterialProperty.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the Property specifying the {@link Color} of the line.\n * @memberof PolylineGlowMaterialProperty.prototype\n * @type {Property|undefined}\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the numeric Property specifying the strength of the glow, as a percentage of the total line width (less than 1.0).\n * @memberof PolylineGlowMaterialProperty.prototype\n * @type {Property|undefined}\n */\n glowPower: createPropertyDescriptor(\"glowPower\"),\n\n /**\n * Gets or sets the numeric Property specifying the strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used.\n * @memberof PolylineGlowMaterialProperty.prototype\n * @type {Property|undefined}\n */\n taperPower: createPropertyDescriptor(\"taperPower\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nPolylineGlowMaterialProperty.prototype.getType = function (time) {\n return \"PolylineGlow\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPolylineGlowMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n defaultColor,\n result.color\n );\n result.glowPower = Property.getValueOrDefault(\n this._glowPower,\n time,\n defaultGlowPower,\n result.glowPower\n );\n result.taperPower = Property.getValueOrDefault(\n this._taperPower,\n time,\n defaultTaperPower,\n result.taperPower\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPolylineGlowMaterialProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof PolylineGlowMaterialProperty &&\n Property.equals(this._color, other._color) &&\n Property.equals(this._glowPower, other._glowPower) &&\n Property.equals(this._taperPower, other._taperPower))\n );\n};\nexport default PolylineGlowMaterialProperty;\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultOutlineColor = Color.BLACK;\nconst defaultOutlineWidth = 1.0;\n\n/**\n * A {@link MaterialProperty} that maps to polyline outline {@link Material} uniforms.\n * @alias PolylineOutlineMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|Color} [options.color=Color.WHITE] A Property specifying the {@link Color} of the line.\n * @param {Property|Color} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.\n * @param {Property|number} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline, in pixels.\n */\nfunction PolylineOutlineMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._color = undefined;\n this._colorSubscription = undefined;\n this._outlineColor = undefined;\n this._outlineColorSubscription = undefined;\n this._outlineWidth = undefined;\n this._outlineWidthSubscription = undefined;\n\n this.color = options.color;\n this.outlineColor = options.outlineColor;\n this.outlineWidth = options.outlineWidth;\n}\n\nObject.defineProperties(PolylineOutlineMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof PolylineOutlineMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._color) &&\n Property.isConstant(this._outlineColor) &&\n Property.isConstant(this._outlineWidth)\n );\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof PolylineOutlineMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the Property specifying the {@link Color} of the line.\n * @memberof PolylineOutlineMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n color: createPropertyDescriptor(\"color\"),\n\n /**\n * Gets or sets the Property specifying the {@link Color} of the outline.\n * @memberof PolylineOutlineMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n outlineColor: createPropertyDescriptor(\"outlineColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the width of the outline.\n * @memberof PolylineOutlineMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n outlineWidth: createPropertyDescriptor(\"outlineWidth\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nPolylineOutlineMaterialProperty.prototype.getType = function (time) {\n return \"PolylineOutline\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPolylineOutlineMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.color = Property.getValueOrClonedDefault(\n this._color,\n time,\n defaultColor,\n result.color\n );\n result.outlineColor = Property.getValueOrClonedDefault(\n this._outlineColor,\n time,\n defaultOutlineColor,\n result.outlineColor\n );\n result.outlineWidth = Property.getValueOrDefault(\n this._outlineWidth,\n time,\n defaultOutlineWidth\n );\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPolylineOutlineMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PolylineOutlineMaterialProperty && //\n Property.equals(this._color, other._color) && //\n Property.equals(this._outlineColor, other._outlineColor) && //\n Property.equals(this._outlineWidth, other._outlineWidth))\n );\n};\nexport default PolylineOutlineMaterialProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport EventHelper from \"../Core/EventHelper.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link Property} whose value is an array whose items are the computed value\n * of other PositionProperty instances.\n *\n * @alias PositionPropertyArray\n * @constructor\n *\n * @param {Property[]} [value] An array of Property instances.\n * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.\n */\nfunction PositionPropertyArray(value, referenceFrame) {\n this._value = undefined;\n this._definitionChanged = new Event();\n this._eventHelper = new EventHelper();\n this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n this.setValue(value);\n}\n\nObject.defineProperties(PositionPropertyArray.prototype, {\n /**\n * Gets a value indicating if this property is constant. This property\n * is considered constant if all property items in the array are constant.\n * @memberof PositionPropertyArray.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n const value = this._value;\n if (!defined(value)) {\n return true;\n }\n\n const length = value.length;\n for (let i = 0; i < length; i++) {\n if (!Property.isConstant(value[i])) {\n return false;\n }\n }\n return true;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value or one of the properties in the array also changes.\n * @memberof PositionPropertyArray.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the reference frame in which the position is defined.\n * @memberof PositionPropertyArray.prototype\n * @type {ReferenceFrame}\n * @default ReferenceFrame.FIXED;\n */\n referenceFrame: {\n get: function () {\n return this._referenceFrame;\n },\n },\n});\n\n/**\n * Gets the value of the property.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPositionPropertyArray.prototype.getValue = function (time, result) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3[]} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3[]} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nPositionPropertyArray.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n if (!defined(referenceFrame)) {\n throw new DeveloperError(\"referenceFrame is required.\");\n }\n //>>includeEnd('debug');\n\n const value = this._value;\n if (!defined(value)) {\n return undefined;\n }\n\n const length = value.length;\n if (!defined(result)) {\n result = new Array(length);\n }\n let i = 0;\n let x = 0;\n while (i < length) {\n const property = value[i];\n const itemValue = property.getValueInReferenceFrame(\n time,\n referenceFrame,\n result[i]\n );\n if (defined(itemValue)) {\n result[x] = itemValue;\n x++;\n }\n i++;\n }\n result.length = x;\n return result;\n};\n\n/**\n * Sets the value of the property.\n *\n * @param {Property[]} value An array of Property instances.\n */\nPositionPropertyArray.prototype.setValue = function (value) {\n const eventHelper = this._eventHelper;\n eventHelper.removeAll();\n\n if (defined(value)) {\n this._value = value.slice();\n const length = value.length;\n for (let i = 0; i < length; i++) {\n const property = value[i];\n if (defined(property)) {\n eventHelper.add(\n property.definitionChanged,\n PositionPropertyArray.prototype._raiseDefinitionChanged,\n this\n );\n }\n }\n } else {\n this._value = undefined;\n }\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPositionPropertyArray.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PositionPropertyArray && //\n this._referenceFrame === other._referenceFrame && //\n Property.arrayEquals(this._value, other._value))\n );\n};\n\nPositionPropertyArray.prototype._raiseDefinitionChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default PositionPropertyArray;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport EventHelper from \"../Core/EventHelper.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link Property} whose value is an array whose items are the computed value\n * of other property instances.\n *\n * @alias PropertyArray\n * @constructor\n *\n * @param {Property[]} [value] An array of Property instances.\n */\nfunction PropertyArray(value) {\n this._value = undefined;\n this._definitionChanged = new Event();\n this._eventHelper = new EventHelper();\n this.setValue(value);\n}\n\nObject.defineProperties(PropertyArray.prototype, {\n /**\n * Gets a value indicating if this property is constant. This property\n * is considered constant if all property items in the array are constant.\n * @memberof PropertyArray.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n const value = this._value;\n if (!defined(value)) {\n return true;\n }\n const length = value.length;\n for (let i = 0; i < length; i++) {\n if (!Property.isConstant(value[i])) {\n return false;\n }\n }\n return true;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value or one of the properties in the array also changes.\n * @memberof PropertyArray.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n});\n\n/**\n * Gets the value of the property.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {Object[]} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Object[]} The modified result parameter, which is an array of values produced by evaluating each of the contained properties at the given time or a new instance if the result parameter was not supplied.\n */\nPropertyArray.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const value = this._value;\n if (!defined(value)) {\n return undefined;\n }\n\n const length = value.length;\n if (!defined(result)) {\n result = new Array(length);\n }\n let i = 0;\n let x = 0;\n while (i < length) {\n const property = this._value[i];\n const itemValue = property.getValue(time, result[i]);\n if (defined(itemValue)) {\n result[x] = itemValue;\n x++;\n }\n i++;\n }\n result.length = x;\n return result;\n};\n\n/**\n * Sets the value of the property.\n *\n * @param {Property[]} value An array of Property instances.\n */\nPropertyArray.prototype.setValue = function (value) {\n const eventHelper = this._eventHelper;\n eventHelper.removeAll();\n\n if (defined(value)) {\n this._value = value.slice();\n const length = value.length;\n for (let i = 0; i < length; i++) {\n const property = value[i];\n if (defined(property)) {\n eventHelper.add(\n property.definitionChanged,\n PropertyArray.prototype._raiseDefinitionChanged,\n this\n );\n }\n }\n } else {\n this._value = undefined;\n }\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nPropertyArray.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof PropertyArray && //\n Property.arrayEquals(this._value, other._value))\n );\n};\n\nPropertyArray.prototype._raiseDefinitionChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default PropertyArray;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport Property from \"./Property.js\";\n\nfunction resolve(that) {\n let targetProperty = that._targetProperty;\n\n if (!defined(targetProperty)) {\n let targetEntity = that._targetEntity;\n\n if (!defined(targetEntity)) {\n targetEntity = that._targetCollection.getById(that._targetId);\n\n if (!defined(targetEntity)) {\n // target entity not found\n that._targetEntity = that._targetProperty = undefined;\n return;\n }\n\n // target entity was found. listen for changes to entity definition\n targetEntity.definitionChanged.addEventListener(\n ReferenceProperty.prototype._onTargetEntityDefinitionChanged,\n that\n );\n that._targetEntity = targetEntity;\n }\n\n // walk the list of property names and resolve properties\n const targetPropertyNames = that._targetPropertyNames;\n targetProperty = that._targetEntity;\n for (\n let i = 0, len = targetPropertyNames.length;\n i < len && defined(targetProperty);\n ++i\n ) {\n targetProperty = targetProperty[targetPropertyNames[i]];\n }\n\n // target property may or may not be defined, depending on if it was found\n that._targetProperty = targetProperty;\n }\n\n return targetProperty;\n}\n\n/**\n * A {@link Property} which transparently links to another property on a provided object.\n *\n * @alias ReferenceProperty\n * @constructor\n *\n * @param {EntityCollection} targetCollection The entity collection which will be used to resolve the reference.\n * @param {string} targetId The id of the entity which is being referenced.\n * @param {string[]} targetPropertyNames The names of the property on the target entity which we will use.\n *\n * @example\n * const collection = new Cesium.EntityCollection();\n *\n * //Create a new entity and assign a billboard scale.\n * const object1 = new Cesium.Entity({id:'object1'});\n * object1.billboard = new Cesium.BillboardGraphics();\n * object1.billboard.scale = new Cesium.ConstantProperty(2.0);\n * collection.add(object1);\n *\n * //Create a second entity and reference the scale from the first one.\n * const object2 = new Cesium.Entity({id:'object2'});\n * object2.model = new Cesium.ModelGraphics();\n * object2.model.scale = new Cesium.ReferenceProperty(collection, 'object1', ['billboard', 'scale']);\n * collection.add(object2);\n *\n * //Create a third object, but use the fromString helper function.\n * const object3 = new Cesium.Entity({id:'object3'});\n * object3.billboard = new Cesium.BillboardGraphics();\n * object3.billboard.scale = Cesium.ReferenceProperty.fromString(collection, 'object1#billboard.scale');\n * collection.add(object3);\n *\n * //You can refer to an entity with a # or . in id and property names by escaping them.\n * const object4 = new Cesium.Entity({id:'#object.4'});\n * object4.billboard = new Cesium.BillboardGraphics();\n * object4.billboard.scale = new Cesium.ConstantProperty(2.0);\n * collection.add(object4);\n *\n * const object5 = new Cesium.Entity({id:'object5'});\n * object5.billboard = new Cesium.BillboardGraphics();\n * object5.billboard.scale = Cesium.ReferenceProperty.fromString(collection, '\\\\#object\\\\.4#billboard.scale');\n * collection.add(object5);\n */\nfunction ReferenceProperty(targetCollection, targetId, targetPropertyNames) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(targetCollection)) {\n throw new DeveloperError(\"targetCollection is required.\");\n }\n if (!defined(targetId) || targetId === \"\") {\n throw new DeveloperError(\"targetId is required.\");\n }\n if (!defined(targetPropertyNames) || targetPropertyNames.length === 0) {\n throw new DeveloperError(\"targetPropertyNames is required.\");\n }\n for (let i = 0; i < targetPropertyNames.length; i++) {\n const item = targetPropertyNames[i];\n if (!defined(item) || item === \"\") {\n throw new DeveloperError(\"reference contains invalid properties.\");\n }\n }\n //>>includeEnd('debug');\n\n this._targetCollection = targetCollection;\n this._targetId = targetId;\n this._targetPropertyNames = targetPropertyNames;\n this._targetProperty = undefined;\n this._targetEntity = undefined;\n this._definitionChanged = new Event();\n\n targetCollection.collectionChanged.addEventListener(\n ReferenceProperty.prototype._onCollectionChanged,\n this\n );\n}\n\nObject.defineProperties(ReferenceProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * @memberof ReferenceProperty.prototype\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return Property.isConstant(resolve(this));\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever the referenced property's definition is changed.\n * @memberof ReferenceProperty.prototype\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the reference frame that the position is defined in.\n * This property is only valid if the referenced property is a {@link PositionProperty}.\n * @memberof ReferenceProperty.prototype\n * @type {ReferenceFrame}\n * @readonly\n */\n referenceFrame: {\n get: function () {\n const target = resolve(this);\n return defined(target) ? target.referenceFrame : undefined;\n },\n },\n /**\n * Gets the id of the entity being referenced.\n * @memberof ReferenceProperty.prototype\n * @type {string}\n * @readonly\n */\n targetId: {\n get: function () {\n return this._targetId;\n },\n },\n /**\n * Gets the collection containing the entity being referenced.\n * @memberof ReferenceProperty.prototype\n * @type {EntityCollection}\n * @readonly\n */\n targetCollection: {\n get: function () {\n return this._targetCollection;\n },\n },\n /**\n * Gets the array of property names used to retrieve the referenced property.\n * @memberof ReferenceProperty.prototype\n * @type {}\n * @readonly\n */\n targetPropertyNames: {\n get: function () {\n return this._targetPropertyNames;\n },\n },\n /**\n * Gets the resolved instance of the underlying referenced property.\n * @memberof ReferenceProperty.prototype\n * @type {Property|undefined}\n * @readonly\n */\n resolvedProperty: {\n get: function () {\n return resolve(this);\n },\n },\n});\n\n/**\n * Creates a new instance given the entity collection that will\n * be used to resolve it and a string indicating the target entity id and property.\n * The format of the string is \"objectId#foo.bar\", where # separates the id from\n * property path and . separates sub-properties. If the reference identifier or\n * or any sub-properties contains a # . or \\ they must be escaped.\n *\n * @param {EntityCollection} targetCollection\n * @param {string} referenceString\n * @returns {ReferenceProperty} A new instance of ReferenceProperty.\n *\n * @exception {DeveloperError} invalid referenceString.\n */\nReferenceProperty.fromString = function (targetCollection, referenceString) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(targetCollection)) {\n throw new DeveloperError(\"targetCollection is required.\");\n }\n if (!defined(referenceString)) {\n throw new DeveloperError(\"referenceString is required.\");\n }\n //>>includeEnd('debug');\n\n let identifier;\n const values = [];\n\n let inIdentifier = true;\n let isEscaped = false;\n let token = \"\";\n for (let i = 0; i < referenceString.length; ++i) {\n const c = referenceString.charAt(i);\n\n if (isEscaped) {\n token += c;\n isEscaped = false;\n } else if (c === \"\\\\\") {\n isEscaped = true;\n } else if (inIdentifier && c === \"#\") {\n identifier = token;\n inIdentifier = false;\n token = \"\";\n } else if (!inIdentifier && c === \".\") {\n values.push(token);\n token = \"\";\n } else {\n token += c;\n }\n }\n values.push(token);\n\n return new ReferenceProperty(targetCollection, identifier, values);\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nReferenceProperty.prototype.getValue = function (time, result) {\n const target = resolve(this);\n return defined(target) ? target.getValue(time, result) : undefined;\n};\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n * This method is only valid if the property being referenced is a {@link PositionProperty}.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nReferenceProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n const target = resolve(this);\n return defined(target)\n ? target.getValueInReferenceFrame(time, referenceFrame, result)\n : undefined;\n};\n\n/**\n * Gets the {@link Material} type at the provided time.\n * This method is only valid if the property being referenced is a {@link MaterialProperty}.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nReferenceProperty.prototype.getType = function (time) {\n const target = resolve(this);\n return defined(target) ? target.getType(time) : undefined;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nReferenceProperty.prototype.equals = function (other) {\n if (this === other) {\n return true;\n }\n\n const names = this._targetPropertyNames;\n const otherNames = other._targetPropertyNames;\n\n if (\n this._targetCollection !== other._targetCollection || //\n this._targetId !== other._targetId || //\n names.length !== otherNames.length\n ) {\n return false;\n }\n\n const length = this._targetPropertyNames.length;\n for (let i = 0; i < length; i++) {\n if (names[i] !== otherNames[i]) {\n return false;\n }\n }\n\n return true;\n};\n\nReferenceProperty.prototype._onTargetEntityDefinitionChanged = function (\n targetEntity,\n name,\n value,\n oldValue\n) {\n if (defined(this._targetProperty) && this._targetPropertyNames[0] === name) {\n this._targetProperty = undefined;\n this._definitionChanged.raiseEvent(this);\n }\n};\n\nReferenceProperty.prototype._onCollectionChanged = function (\n collection,\n added,\n removed\n) {\n let targetEntity = this._targetEntity;\n if (defined(targetEntity) && removed.indexOf(targetEntity) !== -1) {\n targetEntity.definitionChanged.removeEventListener(\n ReferenceProperty.prototype._onTargetEntityDefinitionChanged,\n this\n );\n this._targetEntity = this._targetProperty = undefined;\n } else if (!defined(targetEntity)) {\n targetEntity = resolve(this);\n if (defined(targetEntity)) {\n this._definitionChanged.raiseEvent(this);\n }\n }\n};\nexport default ReferenceProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport CesiumMath from \"../Core/Math.js\";\n\n/**\n * Represents a {@link Packable} number that always interpolates values\n * towards the shortest angle of rotation. This object is never used directly\n * but is instead passed to the constructor of {@link SampledProperty}\n * in order to represent a two-dimensional angle of rotation.\n *\n * @interface Rotation\n *\n *\n * @example\n * const time1 = Cesium.JulianDate.fromIso8601('2010-05-07T00:00:00');\n * const time2 = Cesium.JulianDate.fromIso8601('2010-05-07T00:01:00');\n * const time3 = Cesium.JulianDate.fromIso8601('2010-05-07T00:02:00');\n *\n * const property = new Cesium.SampledProperty(Cesium.Rotation);\n * property.addSample(time1, 0);\n * property.addSample(time3, Cesium.Math.toRadians(350));\n *\n * //Getting the value at time2 will equal 355 degrees instead\n * //of 175 degrees (which is what you get if you construct\n * //a SampledProperty(Number) instead. Note, the actual\n * //return value is in radians, not degrees.\n * property.getValue(time2);\n *\n * @see PackableForInterpolation\n */\nconst Rotation = {\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n packedLength: 1,\n\n /**\n * Stores the provided instance into the provided array.\n *\n * @param {Rotation} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\n pack: function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n array[startingIndex] = value;\n\n return array;\n },\n\n /**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {Rotation} [result] The object into which to store the result.\n * @returns {Rotation} The modified result parameter or a new Rotation instance if one was not provided.\n */\n unpack: function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n return array[startingIndex];\n },\n\n /**\n * Converts a packed array into a form suitable for interpolation.\n *\n * @param {number[]} packedArray The packed array.\n * @param {number} [startingIndex=0] The index of the first element to be converted.\n * @param {number} [lastIndex=packedArray.length] The index of the last element to be converted.\n * @param {number[]} [result] The object into which to store the result.\n */\n convertPackedArrayForInterpolation: function (\n packedArray,\n startingIndex,\n lastIndex,\n result\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(packedArray)) {\n throw new DeveloperError(\"packedArray is required\");\n }\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n result = [];\n }\n\n startingIndex = defaultValue(startingIndex, 0);\n lastIndex = defaultValue(lastIndex, packedArray.length);\n\n let previousValue;\n for (let i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {\n const value = packedArray[startingIndex + i];\n if (i === 0 || Math.abs(previousValue - value) < Math.PI) {\n result[i] = value;\n } else {\n result[i] = value - CesiumMath.TWO_PI;\n }\n previousValue = value;\n }\n },\n\n /**\n * Retrieves an instance from a packed array converted with {@link Rotation.convertPackedArrayForInterpolation}.\n *\n * @param {number[]} array The array previously packed for interpolation.\n * @param {number[]} sourceArray The original packed array.\n * @param {number} [firstIndex=0] The firstIndex used to convert the array.\n * @param {number} [lastIndex=packedArray.length] The lastIndex used to convert the array.\n * @param {Rotation} [result] The object into which to store the result.\n * @returns {Rotation} The modified result parameter or a new Rotation instance if one was not provided.\n */\n unpackInterpolationResult: function (\n array,\n sourceArray,\n firstIndex,\n lastIndex,\n result\n ) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n if (!defined(sourceArray)) {\n throw new DeveloperError(\"sourceArray is required\");\n }\n //>>includeEnd('debug');\n\n result = array[0];\n if (result < 0) {\n return result + CesiumMath.TWO_PI;\n }\n return result;\n },\n};\nexport default Rotation;\n", "import binarySearch from \"../Core/binarySearch.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ExtrapolationType from \"../Core/ExtrapolationType.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport LinearApproximation from \"../Core/LinearApproximation.js\";\n\nconst PackableNumber = {\n packedLength: 1,\n pack: function (value, array, startingIndex) {\n startingIndex = defaultValue(startingIndex, 0);\n array[startingIndex] = value;\n },\n unpack: function (array, startingIndex, result) {\n startingIndex = defaultValue(startingIndex, 0);\n return array[startingIndex];\n },\n};\n\n//We can't use splice for inserting new elements because function apply can't handle\n//a huge number of arguments. See https://code.google.com/p/chromium/issues/detail?id=56588\nfunction arrayInsert(array, startIndex, items) {\n let i;\n const arrayLength = array.length;\n const itemsLength = items.length;\n const newLength = arrayLength + itemsLength;\n\n array.length = newLength;\n if (arrayLength !== startIndex) {\n let q = arrayLength - 1;\n for (i = newLength - 1; i >= startIndex; i--) {\n array[i] = array[q--];\n }\n }\n\n for (i = 0; i < itemsLength; i++) {\n array[startIndex++] = items[i];\n }\n}\n\nfunction convertDate(date, epoch) {\n if (date instanceof JulianDate) {\n return date;\n }\n if (typeof date === \"string\") {\n return JulianDate.fromIso8601(date);\n }\n return JulianDate.addSeconds(epoch, date, new JulianDate());\n}\n\nconst timesSpliceArgs = [];\nconst valuesSpliceArgs = [];\n\nfunction mergeNewSamples(epoch, times, values, newData, packedLength) {\n let newDataIndex = 0;\n let i;\n let prevItem;\n let timesInsertionPoint;\n let valuesInsertionPoint;\n let currentTime;\n let nextTime;\n\n while (newDataIndex < newData.length) {\n currentTime = convertDate(newData[newDataIndex], epoch);\n timesInsertionPoint = binarySearch(times, currentTime, JulianDate.compare);\n let timesSpliceArgsCount = 0;\n let valuesSpliceArgsCount = 0;\n\n if (timesInsertionPoint < 0) {\n //Doesn't exist, insert as many additional values as we can.\n timesInsertionPoint = ~timesInsertionPoint;\n\n valuesInsertionPoint = timesInsertionPoint * packedLength;\n prevItem = undefined;\n nextTime = times[timesInsertionPoint];\n while (newDataIndex < newData.length) {\n currentTime = convertDate(newData[newDataIndex], epoch);\n if (\n (defined(prevItem) &&\n JulianDate.compare(prevItem, currentTime) >= 0) ||\n (defined(nextTime) && JulianDate.compare(currentTime, nextTime) >= 0)\n ) {\n break;\n }\n timesSpliceArgs[timesSpliceArgsCount++] = currentTime;\n newDataIndex = newDataIndex + 1;\n for (i = 0; i < packedLength; i++) {\n valuesSpliceArgs[valuesSpliceArgsCount++] = newData[newDataIndex];\n newDataIndex = newDataIndex + 1;\n }\n prevItem = currentTime;\n }\n\n if (timesSpliceArgsCount > 0) {\n valuesSpliceArgs.length = valuesSpliceArgsCount;\n arrayInsert(values, valuesInsertionPoint, valuesSpliceArgs);\n\n timesSpliceArgs.length = timesSpliceArgsCount;\n arrayInsert(times, timesInsertionPoint, timesSpliceArgs);\n }\n } else {\n //Found an exact match\n for (i = 0; i < packedLength; i++) {\n newDataIndex++;\n values[timesInsertionPoint * packedLength + i] = newData[newDataIndex];\n }\n newDataIndex++;\n }\n }\n}\n\n/**\n * A {@link Property} whose value is interpolated for a given time from the\n * provided set of samples and specified interpolation algorithm and degree.\n * @alias SampledProperty\n * @constructor\n *\n * @param {number|Packable} type The type of property.\n * @param {Packable[]} [derivativeTypes] When supplied, indicates that samples will contain derivative information of the specified types.\n *\n *\n * @example\n * //Create a linearly interpolated Cartesian2\n * const property = new Cesium.SampledProperty(Cesium.Cartesian2);\n *\n * //Populate it with data\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:00:00.00Z'), new Cesium.Cartesian2(0, 0));\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-02T00:00:00.00Z'), new Cesium.Cartesian2(4, 7));\n *\n * //Retrieve an interpolated value\n * const result = property.getValue(Cesium.JulianDate.fromIso8601('2012-08-01T12:00:00.00Z'));\n *\n * @example\n * //Create a simple numeric SampledProperty that uses third degree Hermite Polynomial Approximation\n * const property = new Cesium.SampledProperty(Number);\n * property.setInterpolationOptions({\n * interpolationDegree : 3,\n * interpolationAlgorithm : Cesium.HermitePolynomialApproximation\n * });\n *\n * //Populate it with data\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:00:00.00Z'), 1.0);\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:01:00.00Z'), 6.0);\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:02:00.00Z'), 12.0);\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:03:30.00Z'), 5.0);\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:06:30.00Z'), 2.0);\n *\n * //Samples can be added in any order.\n * property.addSample(Cesium.JulianDate.fromIso8601('2012-08-01T00:00:30.00Z'), 6.2);\n *\n * //Retrieve an interpolated value\n * const result = property.getValue(Cesium.JulianDate.fromIso8601('2012-08-01T00:02:34.00Z'));\n *\n * @see SampledPositionProperty\n */\nfunction SampledProperty(type, derivativeTypes) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"type\", type);\n //>>includeEnd('debug');\n\n let innerType = type;\n if (innerType === Number) {\n innerType = PackableNumber;\n }\n let packedLength = innerType.packedLength;\n let packedInterpolationLength = defaultValue(\n innerType.packedInterpolationLength,\n packedLength\n );\n\n let inputOrder = 0;\n let innerDerivativeTypes;\n if (defined(derivativeTypes)) {\n const length = derivativeTypes.length;\n innerDerivativeTypes = new Array(length);\n for (let i = 0; i < length; i++) {\n let derivativeType = derivativeTypes[i];\n if (derivativeType === Number) {\n derivativeType = PackableNumber;\n }\n const derivativePackedLength = derivativeType.packedLength;\n packedLength += derivativePackedLength;\n packedInterpolationLength += defaultValue(\n derivativeType.packedInterpolationLength,\n derivativePackedLength\n );\n innerDerivativeTypes[i] = derivativeType;\n }\n inputOrder = length;\n }\n\n this._type = type;\n this._innerType = innerType;\n this._interpolationDegree = 1;\n this._interpolationAlgorithm = LinearApproximation;\n this._numberOfPoints = 0;\n this._times = [];\n this._values = [];\n this._xTable = [];\n this._yTable = [];\n this._packedLength = packedLength;\n this._packedInterpolationLength = packedInterpolationLength;\n this._updateTableLength = true;\n this._interpolationResult = new Array(packedInterpolationLength);\n this._definitionChanged = new Event();\n this._derivativeTypes = derivativeTypes;\n this._innerDerivativeTypes = innerDerivativeTypes;\n this._inputOrder = inputOrder;\n this._forwardExtrapolationType = ExtrapolationType.NONE;\n this._forwardExtrapolationDuration = 0;\n this._backwardExtrapolationType = ExtrapolationType.NONE;\n this._backwardExtrapolationDuration = 0;\n}\n\nObject.defineProperties(SampledProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof SampledProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._values.length === 0;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof SampledProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the type of property.\n * @memberof SampledProperty.prototype\n * @type {*}\n */\n type: {\n get: function () {\n return this._type;\n },\n },\n /**\n * Gets the derivative types used by this property.\n * @memberof SampledProperty.prototype\n * @type {Packable[]}\n */\n derivativeTypes: {\n get: function () {\n return this._derivativeTypes;\n },\n },\n /**\n * Gets the degree of interpolation to perform when retrieving a value.\n * @memberof SampledProperty.prototype\n * @type {number}\n * @default 1\n */\n interpolationDegree: {\n get: function () {\n return this._interpolationDegree;\n },\n },\n /**\n * Gets the interpolation algorithm to use when retrieving a value.\n * @memberof SampledProperty.prototype\n * @type {InterpolationAlgorithm}\n * @default LinearApproximation\n */\n interpolationAlgorithm: {\n get: function () {\n return this._interpolationAlgorithm;\n },\n },\n /**\n * Gets or sets the type of extrapolation to perform when a value\n * is requested at a time after any available samples.\n * @memberof SampledProperty.prototype\n * @type {ExtrapolationType}\n * @default ExtrapolationType.NONE\n */\n forwardExtrapolationType: {\n get: function () {\n return this._forwardExtrapolationType;\n },\n set: function (value) {\n if (this._forwardExtrapolationType !== value) {\n this._forwardExtrapolationType = value;\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n /**\n * Gets or sets the amount of time to extrapolate forward before\n * the property becomes undefined. A value of 0 will extrapolate forever.\n * @memberof SampledProperty.prototype\n * @type {number}\n * @default 0\n */\n forwardExtrapolationDuration: {\n get: function () {\n return this._forwardExtrapolationDuration;\n },\n set: function (value) {\n if (this._forwardExtrapolationDuration !== value) {\n this._forwardExtrapolationDuration = value;\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n /**\n * Gets or sets the type of extrapolation to perform when a value\n * is requested at a time before any available samples.\n * @memberof SampledProperty.prototype\n * @type {ExtrapolationType}\n * @default ExtrapolationType.NONE\n */\n backwardExtrapolationType: {\n get: function () {\n return this._backwardExtrapolationType;\n },\n set: function (value) {\n if (this._backwardExtrapolationType !== value) {\n this._backwardExtrapolationType = value;\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n /**\n * Gets or sets the amount of time to extrapolate backward\n * before the property becomes undefined. A value of 0 will extrapolate forever.\n * @memberof SampledProperty.prototype\n * @type {number}\n * @default 0\n */\n backwardExtrapolationDuration: {\n get: function () {\n return this._backwardExtrapolationDuration;\n },\n set: function (value) {\n if (this._backwardExtrapolationDuration !== value) {\n this._backwardExtrapolationDuration = value;\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nSampledProperty.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const times = this._times;\n const timesLength = times.length;\n if (timesLength === 0) {\n return undefined;\n }\n\n let timeout;\n const innerType = this._innerType;\n const values = this._values;\n let index = binarySearch(times, time, JulianDate.compare);\n\n if (index < 0) {\n index = ~index;\n\n if (index === 0) {\n const startTime = times[index];\n timeout = this._backwardExtrapolationDuration;\n if (\n this._backwardExtrapolationType === ExtrapolationType.NONE ||\n (timeout !== 0 &&\n JulianDate.secondsDifference(startTime, time) > timeout)\n ) {\n return undefined;\n }\n if (this._backwardExtrapolationType === ExtrapolationType.HOLD) {\n return innerType.unpack(values, 0, result);\n }\n }\n\n if (index >= timesLength) {\n index = timesLength - 1;\n const endTime = times[index];\n timeout = this._forwardExtrapolationDuration;\n if (\n this._forwardExtrapolationType === ExtrapolationType.NONE ||\n (timeout !== 0 && JulianDate.secondsDifference(time, endTime) > timeout)\n ) {\n return undefined;\n }\n if (this._forwardExtrapolationType === ExtrapolationType.HOLD) {\n index = timesLength - 1;\n return innerType.unpack(values, index * innerType.packedLength, result);\n }\n }\n\n const xTable = this._xTable;\n const yTable = this._yTable;\n const interpolationAlgorithm = this._interpolationAlgorithm;\n const packedInterpolationLength = this._packedInterpolationLength;\n const inputOrder = this._inputOrder;\n\n if (this._updateTableLength) {\n this._updateTableLength = false;\n const numberOfPoints = Math.min(\n interpolationAlgorithm.getRequiredDataPoints(\n this._interpolationDegree,\n inputOrder\n ),\n timesLength\n );\n if (numberOfPoints !== this._numberOfPoints) {\n this._numberOfPoints = numberOfPoints;\n xTable.length = numberOfPoints;\n yTable.length = numberOfPoints * packedInterpolationLength;\n }\n }\n\n const degree = this._numberOfPoints - 1;\n if (degree < 1) {\n return undefined;\n }\n\n let firstIndex = 0;\n let lastIndex = timesLength - 1;\n const pointsInCollection = lastIndex - firstIndex + 1;\n\n if (pointsInCollection >= degree + 1) {\n let computedFirstIndex = index - ((degree / 2) | 0) - 1;\n if (computedFirstIndex < firstIndex) {\n computedFirstIndex = firstIndex;\n }\n let computedLastIndex = computedFirstIndex + degree;\n if (computedLastIndex > lastIndex) {\n computedLastIndex = lastIndex;\n computedFirstIndex = computedLastIndex - degree;\n if (computedFirstIndex < firstIndex) {\n computedFirstIndex = firstIndex;\n }\n }\n\n firstIndex = computedFirstIndex;\n lastIndex = computedLastIndex;\n }\n const length = lastIndex - firstIndex + 1;\n\n // Build the tables\n for (let i = 0; i < length; ++i) {\n xTable[i] = JulianDate.secondsDifference(\n times[firstIndex + i],\n times[lastIndex]\n );\n }\n\n if (!defined(innerType.convertPackedArrayForInterpolation)) {\n let destinationIndex = 0;\n const packedLength = this._packedLength;\n let sourceIndex = firstIndex * packedLength;\n const stop = (lastIndex + 1) * packedLength;\n\n while (sourceIndex < stop) {\n yTable[destinationIndex] = values[sourceIndex];\n sourceIndex++;\n destinationIndex++;\n }\n } else {\n innerType.convertPackedArrayForInterpolation(\n values,\n firstIndex,\n lastIndex,\n yTable\n );\n }\n\n // Interpolate!\n const x = JulianDate.secondsDifference(time, times[lastIndex]);\n let interpolationResult;\n if (inputOrder === 0 || !defined(interpolationAlgorithm.interpolate)) {\n interpolationResult = interpolationAlgorithm.interpolateOrderZero(\n x,\n xTable,\n yTable,\n packedInterpolationLength,\n this._interpolationResult\n );\n } else {\n const yStride = Math.floor(packedInterpolationLength / (inputOrder + 1));\n interpolationResult = interpolationAlgorithm.interpolate(\n x,\n xTable,\n yTable,\n yStride,\n inputOrder,\n inputOrder,\n this._interpolationResult\n );\n }\n\n if (!defined(innerType.unpackInterpolationResult)) {\n return innerType.unpack(interpolationResult, 0, result);\n }\n return innerType.unpackInterpolationResult(\n interpolationResult,\n values,\n firstIndex,\n lastIndex,\n result\n );\n }\n return innerType.unpack(values, index * this._packedLength, result);\n};\n\n/**\n * Sets the algorithm and degree to use when interpolating a value.\n *\n * @param {object} [options] Object with the following properties:\n * @param {InterpolationAlgorithm} [options.interpolationAlgorithm] The new interpolation algorithm. If undefined, the existing property will be unchanged.\n * @param {number} [options.interpolationDegree] The new interpolation degree. If undefined, the existing property will be unchanged.\n */\nSampledProperty.prototype.setInterpolationOptions = function (options) {\n if (!defined(options)) {\n return;\n }\n\n let valuesChanged = false;\n\n const interpolationAlgorithm = options.interpolationAlgorithm;\n const interpolationDegree = options.interpolationDegree;\n\n if (\n defined(interpolationAlgorithm) &&\n this._interpolationAlgorithm !== interpolationAlgorithm\n ) {\n this._interpolationAlgorithm = interpolationAlgorithm;\n valuesChanged = true;\n }\n\n if (\n defined(interpolationDegree) &&\n this._interpolationDegree !== interpolationDegree\n ) {\n this._interpolationDegree = interpolationDegree;\n valuesChanged = true;\n }\n\n if (valuesChanged) {\n this._updateTableLength = true;\n this._definitionChanged.raiseEvent(this);\n }\n};\n\n/**\n * Adds a new sample.\n *\n * @param {JulianDate} time The sample time.\n * @param {Packable} value The value at the provided time.\n * @param {Packable[]} [derivatives] The array of derivatives at the provided time.\n */\nSampledProperty.prototype.addSample = function (time, value, derivatives) {\n const innerDerivativeTypes = this._innerDerivativeTypes;\n const hasDerivatives = defined(innerDerivativeTypes);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n Check.defined(\"value\", value);\n if (hasDerivatives) {\n Check.defined(\"derivatives\", derivatives);\n }\n //>>includeEnd('debug');\n\n const innerType = this._innerType;\n const data = [];\n data.push(time);\n innerType.pack(value, data, data.length);\n\n if (hasDerivatives) {\n const derivativesLength = innerDerivativeTypes.length;\n for (let x = 0; x < derivativesLength; x++) {\n innerDerivativeTypes[x].pack(derivatives[x], data, data.length);\n }\n }\n mergeNewSamples(\n undefined,\n this._times,\n this._values,\n data,\n this._packedLength\n );\n this._updateTableLength = true;\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Adds an array of samples.\n *\n * @param {JulianDate[]} times An array of JulianDate instances where each index is a sample time.\n * @param {Packable[]} values The array of values, where each value corresponds to the provided times index.\n * @param {Array[]} [derivativeValues] An array where each item is the array of derivatives at the equivalent time index.\n *\n * @exception {DeveloperError} times and values must be the same length.\n * @exception {DeveloperError} times and derivativeValues must be the same length.\n */\nSampledProperty.prototype.addSamples = function (\n times,\n values,\n derivativeValues\n) {\n const innerDerivativeTypes = this._innerDerivativeTypes;\n const hasDerivatives = defined(innerDerivativeTypes);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"times\", times);\n Check.defined(\"values\", values);\n if (times.length !== values.length) {\n throw new DeveloperError(\"times and values must be the same length.\");\n }\n if (\n hasDerivatives &&\n (!defined(derivativeValues) || derivativeValues.length !== times.length)\n ) {\n throw new DeveloperError(\n \"times and derivativeValues must be the same length.\"\n );\n }\n //>>includeEnd('debug');\n\n const innerType = this._innerType;\n const length = times.length;\n const data = [];\n for (let i = 0; i < length; i++) {\n data.push(times[i]);\n innerType.pack(values[i], data, data.length);\n\n if (hasDerivatives) {\n const derivatives = derivativeValues[i];\n const derivativesLength = innerDerivativeTypes.length;\n for (let x = 0; x < derivativesLength; x++) {\n innerDerivativeTypes[x].pack(derivatives[x], data, data.length);\n }\n }\n }\n mergeNewSamples(\n undefined,\n this._times,\n this._values,\n data,\n this._packedLength\n );\n this._updateTableLength = true;\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Adds samples as a single packed array where each new sample is represented as a date,\n * followed by the packed representation of the corresponding value and derivatives.\n *\n * @param {number[]} packedSamples The array of packed samples.\n * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds.\n */\nSampledProperty.prototype.addSamplesPackedArray = function (\n packedSamples,\n epoch\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"packedSamples\", packedSamples);\n //>>includeEnd('debug');\n\n mergeNewSamples(\n epoch,\n this._times,\n this._values,\n packedSamples,\n this._packedLength\n );\n this._updateTableLength = true;\n this._definitionChanged.raiseEvent(this);\n};\n\n/**\n * Removes a sample at the given time, if present.\n *\n * @param {JulianDate} time The sample time.\n * @returns {boolean} true if a sample at time was removed, false otherwise.\n */\nSampledProperty.prototype.removeSample = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const index = binarySearch(this._times, time, JulianDate.compare);\n if (index < 0) {\n return false;\n }\n removeSamples(this, index, 1);\n return true;\n};\n\nfunction removeSamples(property, startIndex, numberToRemove) {\n const packedLength = property._packedLength;\n property._times.splice(startIndex, numberToRemove);\n property._values.splice(\n startIndex * packedLength,\n numberToRemove * packedLength\n );\n property._updateTableLength = true;\n property._definitionChanged.raiseEvent(property);\n}\n\n/**\n * Removes all samples for the given time interval.\n *\n * @param {TimeInterval} time The time interval for which to remove all samples.\n */\nSampledProperty.prototype.removeSamples = function (timeInterval) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"timeInterval\", timeInterval);\n //>>includeEnd('debug');\n\n const times = this._times;\n let startIndex = binarySearch(times, timeInterval.start, JulianDate.compare);\n if (startIndex < 0) {\n startIndex = ~startIndex;\n } else if (!timeInterval.isStartIncluded) {\n ++startIndex;\n }\n let stopIndex = binarySearch(times, timeInterval.stop, JulianDate.compare);\n if (stopIndex < 0) {\n stopIndex = ~stopIndex;\n } else if (timeInterval.isStopIncluded) {\n ++stopIndex;\n }\n\n removeSamples(this, startIndex, stopIndex - startIndex);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nSampledProperty.prototype.equals = function (other) {\n if (this === other) {\n return true;\n }\n if (!defined(other)) {\n return false;\n }\n\n if (\n this._type !== other._type || //\n this._interpolationDegree !== other._interpolationDegree || //\n this._interpolationAlgorithm !== other._interpolationAlgorithm\n ) {\n return false;\n }\n\n const derivativeTypes = this._derivativeTypes;\n const hasDerivatives = defined(derivativeTypes);\n const otherDerivativeTypes = other._derivativeTypes;\n const otherHasDerivatives = defined(otherDerivativeTypes);\n if (hasDerivatives !== otherHasDerivatives) {\n return false;\n }\n\n let i;\n let length;\n if (hasDerivatives) {\n length = derivativeTypes.length;\n if (length !== otherDerivativeTypes.length) {\n return false;\n }\n\n for (i = 0; i < length; i++) {\n if (derivativeTypes[i] !== otherDerivativeTypes[i]) {\n return false;\n }\n }\n }\n\n const times = this._times;\n const otherTimes = other._times;\n length = times.length;\n\n if (length !== otherTimes.length) {\n return false;\n }\n\n for (i = 0; i < length; i++) {\n if (!JulianDate.equals(times[i], otherTimes[i])) {\n return false;\n }\n }\n\n const values = this._values;\n const otherValues = other._values;\n length = values.length;\n\n //Since time lengths are equal, values length and other length are guaranteed to be equal.\n for (i = 0; i < length; i++) {\n if (values[i] !== otherValues[i]) {\n return false;\n }\n }\n\n return true;\n};\n\n//Exposed for testing.\nSampledProperty._mergeNewSamples = mergeNewSamples;\nexport default SampledProperty;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport PositionProperty from \"./PositionProperty.js\";\nimport Property from \"./Property.js\";\nimport SampledProperty from \"./SampledProperty.js\";\n\n/**\n * A {@link SampledProperty} which is also a {@link PositionProperty}.\n *\n * @alias SampledPositionProperty\n * @constructor\n *\n * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.\n * @param {number} [numberOfDerivatives=0] The number of derivatives that accompany each position; i.e. velocity, acceleration, etc...\n */\nfunction SampledPositionProperty(referenceFrame, numberOfDerivatives) {\n numberOfDerivatives = defaultValue(numberOfDerivatives, 0);\n\n let derivativeTypes;\n if (numberOfDerivatives > 0) {\n derivativeTypes = new Array(numberOfDerivatives);\n for (let i = 0; i < numberOfDerivatives; i++) {\n derivativeTypes[i] = Cartesian3;\n }\n }\n\n this._numberOfDerivatives = numberOfDerivatives;\n this._property = new SampledProperty(Cartesian3, derivativeTypes);\n this._definitionChanged = new Event();\n this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n\n this._property._definitionChanged.addEventListener(function () {\n this._definitionChanged.raiseEvent(this);\n }, this);\n}\n\nObject.defineProperties(SampledPositionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof SampledPositionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._property.isConstant;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof SampledPositionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the reference frame in which the position is defined.\n * @memberof SampledPositionProperty.prototype\n * @type {ReferenceFrame}\n * @default ReferenceFrame.FIXED;\n */\n referenceFrame: {\n get: function () {\n return this._referenceFrame;\n },\n },\n /**\n * Gets the degree of interpolation to perform when retrieving a value. Call setInterpolationOptions to set this.\n * @memberof SampledPositionProperty.prototype\n *\n * @type {number}\n * @default 1\n * @readonly\n */\n interpolationDegree: {\n get: function () {\n return this._property.interpolationDegree;\n },\n },\n /**\n * Gets the interpolation algorithm to use when retrieving a value. Call setInterpolationOptions to set this.\n * @memberof SampledPositionProperty.prototype\n *\n * @type {InterpolationAlgorithm}\n * @default LinearApproximation\n * @readonly\n */\n interpolationAlgorithm: {\n get: function () {\n return this._property.interpolationAlgorithm;\n },\n },\n /**\n * The number of derivatives contained by this property; i.e. 0 for just position, 1 for velocity, etc.\n * @memberof SampledPositionProperty.prototype\n *\n * @type {number}\n * @default 0\n */\n numberOfDerivatives: {\n get: function () {\n return this._numberOfDerivatives;\n },\n },\n /**\n * Gets or sets the type of extrapolation to perform when a value\n * is requested at a time after any available samples.\n * @memberof SampledPositionProperty.prototype\n * @type {ExtrapolationType}\n * @default ExtrapolationType.NONE\n */\n forwardExtrapolationType: {\n get: function () {\n return this._property.forwardExtrapolationType;\n },\n set: function (value) {\n this._property.forwardExtrapolationType = value;\n },\n },\n /**\n * Gets or sets the amount of time to extrapolate forward before\n * the property becomes undefined. A value of 0 will extrapolate forever.\n * @memberof SampledPositionProperty.prototype\n * @type {number}\n * @default 0\n */\n forwardExtrapolationDuration: {\n get: function () {\n return this._property.forwardExtrapolationDuration;\n },\n set: function (value) {\n this._property.forwardExtrapolationDuration = value;\n },\n },\n /**\n * Gets or sets the type of extrapolation to perform when a value\n * is requested at a time before any available samples.\n * @memberof SampledPositionProperty.prototype\n * @type {ExtrapolationType}\n * @default ExtrapolationType.NONE\n */\n backwardExtrapolationType: {\n get: function () {\n return this._property.backwardExtrapolationType;\n },\n set: function (value) {\n this._property.backwardExtrapolationType = value;\n },\n },\n /**\n * Gets or sets the amount of time to extrapolate backward\n * before the property becomes undefined. A value of 0 will extrapolate forever.\n * @memberof SampledPositionProperty.prototype\n * @type {number}\n * @default 0\n */\n backwardExtrapolationDuration: {\n get: function () {\n return this._property.backwardExtrapolationDuration;\n },\n set: function (value) {\n this._property.backwardExtrapolationDuration = value;\n },\n },\n});\n\n/**\n * Gets the position at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nSampledPositionProperty.prototype.getValue = function (time, result) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\n/**\n * Gets the position at the provided time and in the provided reference frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nSampledPositionProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n Check.defined(\"referenceFrame\", referenceFrame);\n //>>includeEnd('debug');\n\n result = this._property.getValue(time, result);\n if (defined(result)) {\n return PositionProperty.convertToReferenceFrame(\n time,\n result,\n this._referenceFrame,\n referenceFrame,\n result\n );\n }\n return undefined;\n};\n\n/**\n * Sets the algorithm and degree to use when interpolating a position.\n *\n * @param {object} [options] Object with the following properties:\n * @param {InterpolationAlgorithm} [options.interpolationAlgorithm] The new interpolation algorithm. If undefined, the existing property will be unchanged.\n * @param {number} [options.interpolationDegree] The new interpolation degree. If undefined, the existing property will be unchanged.\n */\nSampledPositionProperty.prototype.setInterpolationOptions = function (options) {\n this._property.setInterpolationOptions(options);\n};\n\n/**\n * Adds a new sample.\n *\n * @param {JulianDate} time The sample time.\n * @param {Cartesian3} position The position at the provided time.\n * @param {Cartesian3[]} [derivatives] The array of derivative values at the provided time.\n */\nSampledPositionProperty.prototype.addSample = function (\n time,\n position,\n derivatives\n) {\n const numberOfDerivatives = this._numberOfDerivatives;\n //>>includeStart('debug', pragmas.debug);\n if (\n numberOfDerivatives > 0 &&\n (!defined(derivatives) || derivatives.length !== numberOfDerivatives)\n ) {\n throw new DeveloperError(\n \"derivatives length must be equal to the number of derivatives.\"\n );\n }\n //>>includeEnd('debug');\n this._property.addSample(time, position, derivatives);\n};\n\n/**\n * Adds multiple samples via parallel arrays.\n *\n * @param {JulianDate[]} times An array of JulianDate instances where each index is a sample time.\n * @param {Cartesian3[]} positions An array of Cartesian3 position instances, where each value corresponds to the provided time index.\n * @param {Array[]} [derivatives] An array where each value is another array containing derivatives for the corresponding time index.\n *\n * @exception {DeveloperError} All arrays must be the same length.\n */\nSampledPositionProperty.prototype.addSamples = function (\n times,\n positions,\n derivatives\n) {\n this._property.addSamples(times, positions, derivatives);\n};\n\n/**\n * Adds samples as a single packed array where each new sample is represented as a date,\n * followed by the packed representation of the corresponding value and derivatives.\n *\n * @param {number[]} packedSamples The array of packed samples.\n * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds.\n */\nSampledPositionProperty.prototype.addSamplesPackedArray = function (\n packedSamples,\n epoch\n) {\n this._property.addSamplesPackedArray(packedSamples, epoch);\n};\n\n/**\n * Removes a sample at the given time, if present.\n *\n * @param {JulianDate} time The sample time.\n * @returns {boolean} true if a sample at time was removed, false otherwise.\n */\nSampledPositionProperty.prototype.removeSample = function (time) {\n return this._property.removeSample(time);\n};\n\n/**\n * Removes all samples for the given time interval.\n *\n * @param {TimeInterval} time The time interval for which to remove all samples.\n */\nSampledPositionProperty.prototype.removeSamples = function (timeInterval) {\n this._property.removeSamples(timeInterval);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nSampledPositionProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof SampledPositionProperty &&\n Property.equals(this._property, other._property) && //\n this._referenceFrame === other._referenceFrame)\n );\n};\nexport default SampledPositionProperty;\n", "/**\n * Defined the orientation of stripes in {@link StripeMaterialProperty}.\n *\n * @enum {number}\n */\nconst StripeOrientation = {\n /**\n * Horizontal orientation.\n * @type {number}\n */\n HORIZONTAL: 0,\n\n /**\n * Vertical orientation.\n * @type {number}\n */\n VERTICAL: 1,\n};\nexport default Object.freeze(StripeOrientation);\n", "import Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\nimport createPropertyDescriptor from \"./createPropertyDescriptor.js\";\nimport Property from \"./Property.js\";\nimport StripeOrientation from \"./StripeOrientation.js\";\n\nconst defaultOrientation = StripeOrientation.HORIZONTAL;\nconst defaultEvenColor = Color.WHITE;\nconst defaultOddColor = Color.BLACK;\nconst defaultOffset = 0;\nconst defaultRepeat = 1;\n\n/**\n * A {@link MaterialProperty} that maps to stripe {@link Material} uniforms.\n * @alias StripeMaterialProperty\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Property|StripeOrientation} [options.orientation=StripeOrientation.HORIZONTAL] A Property specifying the {@link StripeOrientation}.\n * @param {Property|Color} [options.evenColor=Color.WHITE] A Property specifying the first {@link Color}.\n * @param {Property|Color} [options.oddColor=Color.BLACK] A Property specifying the second {@link Color}.\n * @param {Property|number} [options.offset=0] A numeric Property specifying how far into the pattern to start the material.\n * @param {Property|number} [options.repeat=1] A numeric Property specifying how many times the stripes repeat.\n */\nfunction StripeMaterialProperty(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._definitionChanged = new Event();\n this._orientation = undefined;\n this._orientationSubscription = undefined;\n this._evenColor = undefined;\n this._evenColorSubscription = undefined;\n this._oddColor = undefined;\n this._oddColorSubscription = undefined;\n this._offset = undefined;\n this._offsetSubscription = undefined;\n this._repeat = undefined;\n this._repeatSubscription = undefined;\n\n this.orientation = options.orientation;\n this.evenColor = options.evenColor;\n this.oddColor = options.oddColor;\n this.offset = options.offset;\n this.repeat = options.repeat;\n}\n\nObject.defineProperties(StripeMaterialProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof StripeMaterialProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return (\n Property.isConstant(this._orientation) && //\n Property.isConstant(this._evenColor) && //\n Property.isConstant(this._oddColor) && //\n Property.isConstant(this._offset) && //\n Property.isConstant(this._repeat)\n );\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof StripeMaterialProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n\n /**\n * Gets or sets the Property specifying the {@link StripeOrientation}/\n * @memberof StripeMaterialProperty.prototype\n * @type {Property|undefined}\n * @default StripeOrientation.HORIZONTAL\n */\n orientation: createPropertyDescriptor(\"orientation\"),\n\n /**\n * Gets or sets the Property specifying the first {@link Color}.\n * @memberof StripeMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.WHITE\n */\n evenColor: createPropertyDescriptor(\"evenColor\"),\n\n /**\n * Gets or sets the Property specifying the second {@link Color}.\n * @memberof StripeMaterialProperty.prototype\n * @type {Property|undefined}\n * @default Color.BLACK\n */\n oddColor: createPropertyDescriptor(\"oddColor\"),\n\n /**\n * Gets or sets the numeric Property specifying the point into the pattern\n * to begin drawing; with 0.0 being the beginning of the even color, 1.0 the beginning\n * of the odd color, 2.0 being the even color again, and any multiple or fractional values\n * being in between.\n * @memberof StripeMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 0.0\n */\n offset: createPropertyDescriptor(\"offset\"),\n\n /**\n * Gets or sets the numeric Property specifying how many times the stripes repeat.\n * @memberof StripeMaterialProperty.prototype\n * @type {Property|undefined}\n * @default 1.0\n */\n repeat: createPropertyDescriptor(\"repeat\"),\n});\n\n/**\n * Gets the {@link Material} type at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the type.\n * @returns {string} The type of material.\n */\nStripeMaterialProperty.prototype.getType = function (time) {\n return \"Stripe\";\n};\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nStripeMaterialProperty.prototype.getValue = function (time, result) {\n if (!defined(result)) {\n result = {};\n }\n result.horizontal =\n Property.getValueOrDefault(this._orientation, time, defaultOrientation) ===\n StripeOrientation.HORIZONTAL;\n result.evenColor = Property.getValueOrClonedDefault(\n this._evenColor,\n time,\n defaultEvenColor,\n result.evenColor\n );\n result.oddColor = Property.getValueOrClonedDefault(\n this._oddColor,\n time,\n defaultOddColor,\n result.oddColor\n );\n result.offset = Property.getValueOrDefault(this._offset, time, defaultOffset);\n result.repeat = Property.getValueOrDefault(this._repeat, time, defaultRepeat);\n return result;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nStripeMaterialProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof StripeMaterialProperty && //\n Property.equals(this._orientation, other._orientation) && //\n Property.equals(this._evenColor, other._evenColor) && //\n Property.equals(this._oddColor, other._oddColor) && //\n Property.equals(this._offset, other._offset) && //\n Property.equals(this._repeat, other._repeat))\n );\n};\nexport default StripeMaterialProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport PositionProperty from \"./PositionProperty.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link TimeIntervalCollectionProperty} which is also a {@link PositionProperty}.\n *\n * @alias TimeIntervalCollectionPositionProperty\n * @constructor\n *\n * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.\n */\nfunction TimeIntervalCollectionPositionProperty(referenceFrame) {\n this._definitionChanged = new Event();\n this._intervals = new TimeIntervalCollection();\n this._intervals.changedEvent.addEventListener(\n TimeIntervalCollectionPositionProperty.prototype._intervalsChanged,\n this\n );\n this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);\n}\n\nObject.defineProperties(TimeIntervalCollectionPositionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof TimeIntervalCollectionPositionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._intervals.isEmpty;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is considered to have changed if a call to getValue would return\n * a different result for the same time.\n * @memberof TimeIntervalCollectionPositionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the interval collection.\n * @memberof TimeIntervalCollectionPositionProperty.prototype\n * @type {TimeIntervalCollection}\n * @readonly\n */\n intervals: {\n get: function () {\n return this._intervals;\n },\n },\n /**\n * Gets the reference frame in which the position is defined.\n * @memberof TimeIntervalCollectionPositionProperty.prototype\n * @type {ReferenceFrame}\n * @readonly\n * @default ReferenceFrame.FIXED;\n */\n referenceFrame: {\n get: function () {\n return this._referenceFrame;\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time in the fixed frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nTimeIntervalCollectionPositionProperty.prototype.getValue = function (\n time,\n result\n) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\n/**\n * Gets the value of the property at the provided time and in the provided reference frame.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nTimeIntervalCollectionPositionProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n if (!defined(referenceFrame)) {\n throw new DeveloperError(\"referenceFrame is required.\");\n }\n //>>includeEnd('debug');\n\n const position = this._intervals.findDataForIntervalContainingDate(time);\n if (defined(position)) {\n return PositionProperty.convertToReferenceFrame(\n time,\n position,\n this._referenceFrame,\n referenceFrame,\n result\n );\n }\n return undefined;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nTimeIntervalCollectionPositionProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof TimeIntervalCollectionPositionProperty && //\n this._intervals.equals(other._intervals, Property.equals) && //\n this._referenceFrame === other._referenceFrame)\n );\n};\n\n/**\n * @private\n */\nTimeIntervalCollectionPositionProperty.prototype._intervalsChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default TimeIntervalCollectionPositionProperty;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link Property} which is defined by a {@link TimeIntervalCollection}, where the\n * data property of each {@link TimeInterval} represents the value at time.\n *\n * @alias TimeIntervalCollectionProperty\n * @constructor\n *\n * @example\n * //Create a Cartesian2 interval property which contains data on August 1st, 2012\n * //and uses a different value every 6 hours.\n * const composite = new Cesium.TimeIntervalCollectionProperty();\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T00:00:00.00Z/2012-08-01T06:00:00.00Z',\n * isStartIncluded : true,\n * isStopIncluded : false,\n * data : new Cesium.Cartesian2(2.0, 3.4)\n * }));\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T06:00:00.00Z/2012-08-01T12:00:00.00Z',\n * isStartIncluded : true,\n * isStopIncluded : false,\n * data : new Cesium.Cartesian2(12.0, 2.7)\n * }));\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T12:00:00.00Z/2012-08-01T18:00:00.00Z',\n * isStartIncluded : true,\n * isStopIncluded : false,\n * data : new Cesium.Cartesian2(5.0, 12.4)\n * }));\n * composite.intervals.addInterval(Cesium.TimeInterval.fromIso8601({\n * iso8601 : '2012-08-01T18:00:00.00Z/2012-08-02T00:00:00.00Z',\n * isStartIncluded : true,\n * isStopIncluded : true,\n * data : new Cesium.Cartesian2(85.0, 4.1)\n * }));\n */\nfunction TimeIntervalCollectionProperty() {\n this._definitionChanged = new Event();\n this._intervals = new TimeIntervalCollection();\n this._intervals.changedEvent.addEventListener(\n TimeIntervalCollectionProperty.prototype._intervalsChanged,\n this\n );\n}\n\nObject.defineProperties(TimeIntervalCollectionProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant. A property is considered\n * constant if getValue always returns the same result for the current definition.\n * @memberof TimeIntervalCollectionProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return this._intervals.isEmpty;\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * The definition is changed whenever setValue is called with data different\n * than the current value.\n * @memberof TimeIntervalCollectionProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets the interval collection.\n * @memberof TimeIntervalCollectionProperty.prototype\n *\n * @type {TimeIntervalCollection}\n * @readonly\n */\n intervals: {\n get: function () {\n return this._intervals;\n },\n },\n});\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve the value.\n * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nTimeIntervalCollectionProperty.prototype.getValue = function (time, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required\");\n }\n //>>includeEnd('debug');\n\n const value = this._intervals.findDataForIntervalContainingDate(time);\n if (defined(value) && typeof value.clone === \"function\") {\n return value.clone(result);\n }\n return value;\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nTimeIntervalCollectionProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof TimeIntervalCollectionProperty && //\n this._intervals.equals(other._intervals, Property.equals))\n );\n};\n\n/**\n * @private\n */\nTimeIntervalCollectionProperty.prototype._intervalsChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default TimeIntervalCollectionProperty;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport Property from \"./Property.js\";\n\n/**\n * A {@link Property} which evaluates to a {@link Cartesian3} vector\n * based on the velocity of the provided {@link PositionProperty}.\n *\n * @alias VelocityVectorProperty\n * @constructor\n *\n * @param {PositionProperty} [position] The position property used to compute the velocity.\n * @param {boolean} [normalize=true] Whether to normalize the computed velocity vector.\n *\n * @example\n * //Create an entity with a billboard rotated to match its velocity.\n * const position = new Cesium.SampledProperty();\n * position.addSamples(...);\n * const entity = viewer.entities.add({\n * position : position,\n * billboard : {\n * image : 'image.png',\n * alignedAxis : new Cesium.VelocityVectorProperty(position, true) // alignedAxis must be a unit vector\n * }\n * }));\n */\nfunction VelocityVectorProperty(position, normalize) {\n this._position = undefined;\n this._subscription = undefined;\n this._definitionChanged = new Event();\n this._normalize = defaultValue(normalize, true);\n\n this.position = position;\n}\n\nObject.defineProperties(VelocityVectorProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * @memberof VelocityVectorProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return Property.isConstant(this._position);\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * @memberof VelocityVectorProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the position property used to compute the velocity vector.\n * @memberof VelocityVectorProperty.prototype\n *\n * @type {Property|undefined}\n */\n position: {\n get: function () {\n return this._position;\n },\n set: function (value) {\n const oldValue = this._position;\n if (oldValue !== value) {\n if (defined(oldValue)) {\n this._subscription();\n }\n\n this._position = value;\n\n if (defined(value)) {\n this._subscription = value._definitionChanged.addEventListener(\n function () {\n this._definitionChanged.raiseEvent(this);\n },\n this\n );\n }\n\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n /**\n * Gets or sets whether the vector produced by this property\n * will be normalized or not.\n * @memberof VelocityVectorProperty.prototype\n *\n * @type {boolean}\n */\n normalize: {\n get: function () {\n return this._normalize;\n },\n set: function (value) {\n if (this._normalize === value) {\n return;\n }\n\n this._normalize = value;\n this._definitionChanged.raiseEvent(this);\n },\n },\n});\n\nconst position1Scratch = new Cartesian3();\nconst position2Scratch = new Cartesian3();\nconst timeScratch = new JulianDate();\nconst step = 1.0 / 60.0;\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} [time] The time for which to retrieve the value.\n * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nVelocityVectorProperty.prototype.getValue = function (time, result) {\n return this._getValue(time, result);\n};\n\n/**\n * @private\n */\nVelocityVectorProperty.prototype._getValue = function (\n time,\n velocityResult,\n positionResult\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required\");\n }\n //>>includeEnd('debug');\n\n if (!defined(velocityResult)) {\n velocityResult = new Cartesian3();\n }\n\n const property = this._position;\n if (Property.isConstant(property)) {\n return this._normalize\n ? undefined\n : Cartesian3.clone(Cartesian3.ZERO, velocityResult);\n }\n\n let position1 = property.getValue(time, position1Scratch);\n let position2 = property.getValue(\n JulianDate.addSeconds(time, step, timeScratch),\n position2Scratch\n );\n\n //If we don't have a position for now, return undefined.\n if (!defined(position1)) {\n return undefined;\n }\n\n //If we don't have a position for now + step, see if we have a position for now - step.\n if (!defined(position2)) {\n position2 = position1;\n position1 = property.getValue(\n JulianDate.addSeconds(time, -step, timeScratch),\n position2Scratch\n );\n\n if (!defined(position1)) {\n return undefined;\n }\n }\n\n if (Cartesian3.equals(position1, position2)) {\n return this._normalize\n ? undefined\n : Cartesian3.clone(Cartesian3.ZERO, velocityResult);\n }\n\n if (defined(positionResult)) {\n position1.clone(positionResult);\n }\n\n const velocity = Cartesian3.subtract(position2, position1, velocityResult);\n if (this._normalize) {\n return Cartesian3.normalize(velocity, velocityResult);\n }\n\n return Cartesian3.divideByScalar(velocity, step, velocityResult);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nVelocityVectorProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof VelocityVectorProperty &&\n Property.equals(this._position, other._position))\n );\n};\nexport default VelocityVectorProperty;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Event from \"../Core/Event.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Quaternion from \"../Core/Quaternion.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport Property from \"./Property.js\";\nimport VelocityVectorProperty from \"./VelocityVectorProperty.js\";\n\n/**\n * A {@link Property} which evaluates to a {@link Quaternion} rotation\n * based on the velocity of the provided {@link PositionProperty}.\n *\n * @alias VelocityOrientationProperty\n * @constructor\n *\n * @param {PositionProperty} [position] The position property used to compute the orientation.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine which way is up.\n *\n * @example\n * //Create an entity with position and orientation.\n * const position = new Cesium.SampledProperty();\n * position.addSamples(...);\n * const entity = viewer.entities.add({\n * position : position,\n * orientation : new Cesium.VelocityOrientationProperty(position)\n * }));\n */\nfunction VelocityOrientationProperty(position, ellipsoid) {\n this._velocityVectorProperty = new VelocityVectorProperty(position, true);\n this._subscription = undefined;\n this._ellipsoid = undefined;\n this._definitionChanged = new Event();\n\n this.ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n const that = this;\n this._velocityVectorProperty.definitionChanged.addEventListener(function () {\n that._definitionChanged.raiseEvent(that);\n });\n}\n\nObject.defineProperties(VelocityOrientationProperty.prototype, {\n /**\n * Gets a value indicating if this property is constant.\n * @memberof VelocityOrientationProperty.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isConstant: {\n get: function () {\n return Property.isConstant(this._velocityVectorProperty);\n },\n },\n /**\n * Gets the event that is raised whenever the definition of this property changes.\n * @memberof VelocityOrientationProperty.prototype\n *\n * @type {Event}\n * @readonly\n */\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n /**\n * Gets or sets the position property used to compute orientation.\n * @memberof VelocityOrientationProperty.prototype\n *\n * @type {Property|undefined}\n */\n position: {\n get: function () {\n return this._velocityVectorProperty.position;\n },\n set: function (value) {\n this._velocityVectorProperty.position = value;\n },\n },\n /**\n * Gets or sets the ellipsoid used to determine which way is up.\n * @memberof VelocityOrientationProperty.prototype\n *\n * @type {Property|undefined}\n */\n ellipsoid: {\n get: function () {\n return this._ellipsoid;\n },\n set: function (value) {\n const oldValue = this._ellipsoid;\n if (oldValue !== value) {\n this._ellipsoid = value;\n this._definitionChanged.raiseEvent(this);\n }\n },\n },\n});\n\nconst positionScratch = new Cartesian3();\nconst velocityScratch = new Cartesian3();\nconst rotationScratch = new Matrix3();\n\n/**\n * Gets the value of the property at the provided time.\n *\n * @param {JulianDate} [time] The time for which to retrieve the value.\n * @param {Quaternion} [result] The object to store the value into, if omitted, a new instance is created and returned.\n * @returns {Quaternion} The modified result parameter or a new instance if the result parameter was not supplied.\n */\nVelocityOrientationProperty.prototype.getValue = function (time, result) {\n const velocity = this._velocityVectorProperty._getValue(\n time,\n velocityScratch,\n positionScratch\n );\n\n if (!defined(velocity)) {\n return undefined;\n }\n\n Transforms.rotationMatrixFromPositionVelocity(\n positionScratch,\n velocity,\n this._ellipsoid,\n rotationScratch\n );\n return Quaternion.fromRotationMatrix(rotationScratch, result);\n};\n\n/**\n * Compares this property to the provided property and returns\n * true if they are equal, false otherwise.\n *\n * @param {Property} [other] The other property.\n * @returns {boolean} true if left and right are equal, false otherwise.\n */\nVelocityOrientationProperty.prototype.equals = function (other) {\n return (\n this === other || //\n (other instanceof VelocityOrientationProperty &&\n Property.equals(\n this._velocityVectorProperty,\n other._velocityVectorProperty\n ) &&\n (this._ellipsoid === other._ellipsoid ||\n this._ellipsoid.equals(other._ellipsoid)))\n );\n};\nexport default VelocityOrientationProperty;\n", "import defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport CesiumMath from \"../Core/Math.js\";\n\n/**\n * A collection of {@link DataSource} instances.\n * @alias DataSourceCollection\n * @constructor\n */\nfunction DataSourceCollection() {\n this._dataSources = [];\n this._dataSourceAdded = new Event();\n this._dataSourceRemoved = new Event();\n this._dataSourceMoved = new Event();\n}\n\nObject.defineProperties(DataSourceCollection.prototype, {\n /**\n * Gets the number of data sources in this collection.\n * @memberof DataSourceCollection.prototype\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._dataSources.length;\n },\n },\n\n /**\n * An event that is raised when a data source is added to the collection.\n * Event handlers are passed the data source that was added.\n * @memberof DataSourceCollection.prototype\n * @type {Event}\n * @readonly\n */\n dataSourceAdded: {\n get: function () {\n return this._dataSourceAdded;\n },\n },\n\n /**\n * An event that is raised when a data source is removed from the collection.\n * Event handlers are passed the data source that was removed.\n * @memberof DataSourceCollection.prototype\n * @type {Event}\n * @readonly\n */\n dataSourceRemoved: {\n get: function () {\n return this._dataSourceRemoved;\n },\n },\n\n /**\n * An event that is raised when a data source changes position in the collection. Event handlers are passed the data source\n * that was moved, its new index after the move, and its old index prior to the move.\n * @memberof DataSourceCollection.prototype\n * @type {Event}\n * @readonly\n */\n dataSourceMoved: {\n get: function () {\n return this._dataSourceMoved;\n },\n },\n});\n\n/**\n * Adds a data source to the collection.\n *\n * @param {DataSource|Promise} dataSource A data source or a promise to a data source to add to the collection.\n * When passing a promise, the data source will not actually be added\n * to the collection until the promise resolves successfully.\n * @returns {Promise} A Promise that resolves once the data source has been added to the collection.\n */\nDataSourceCollection.prototype.add = function (dataSource) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(dataSource)) {\n throw new DeveloperError(\"dataSource is required.\");\n }\n //>>includeEnd('debug');\n\n const that = this;\n const dataSources = this._dataSources;\n return Promise.resolve(dataSource).then(function (value) {\n //Only add the data source if removeAll has not been called\n //Since it was added.\n if (dataSources === that._dataSources) {\n that._dataSources.push(value);\n that._dataSourceAdded.raiseEvent(that, value);\n }\n return value;\n });\n};\n\n/**\n * Removes a data source from this collection, if present.\n *\n * @param {DataSource} dataSource The data source to remove.\n * @param {boolean} [destroy=false] Whether to destroy the data source in addition to removing it.\n * @returns {boolean} true if the data source was in the collection and was removed,\n * false if the data source was not in the collection.\n */\nDataSourceCollection.prototype.remove = function (dataSource, destroy) {\n destroy = defaultValue(destroy, false);\n\n const index = this._dataSources.indexOf(dataSource);\n if (index !== -1) {\n this._dataSources.splice(index, 1);\n this._dataSourceRemoved.raiseEvent(this, dataSource);\n\n if (destroy && typeof dataSource.destroy === \"function\") {\n dataSource.destroy();\n }\n\n return true;\n }\n\n return false;\n};\n\n/**\n * Removes all data sources from this collection.\n *\n * @param {boolean} [destroy=false] whether to destroy the data sources in addition to removing them.\n */\nDataSourceCollection.prototype.removeAll = function (destroy) {\n destroy = defaultValue(destroy, false);\n\n const dataSources = this._dataSources;\n for (let i = 0, len = dataSources.length; i < len; ++i) {\n const dataSource = dataSources[i];\n this._dataSourceRemoved.raiseEvent(this, dataSource);\n\n if (destroy && typeof dataSource.destroy === \"function\") {\n dataSource.destroy();\n }\n }\n this._dataSources = [];\n};\n\n/**\n * Checks to see if the collection contains a given data source.\n *\n * @param {DataSource} dataSource The data source to check for.\n * @returns {boolean} true if the collection contains the data source, false otherwise.\n */\nDataSourceCollection.prototype.contains = function (dataSource) {\n return this.indexOf(dataSource) !== -1;\n};\n\n/**\n * Determines the index of a given data source in the collection.\n *\n * @param {DataSource} dataSource The data source to find the index of.\n * @returns {number} The index of the data source in the collection, or -1 if the data source does not exist in the collection.\n */\nDataSourceCollection.prototype.indexOf = function (dataSource) {\n return this._dataSources.indexOf(dataSource);\n};\n\n/**\n * Gets a data source by index from the collection.\n *\n * @param {number} index the index to retrieve.\n * @returns {DataSource} The data source at the specified index.\n */\nDataSourceCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n return this._dataSources[index];\n};\n\n/**\n * Gets a data source by name from the collection.\n *\n * @param {string} name The name to retrieve.\n * @returns {DataSource[]} A list of all data sources matching the provided name.\n */\nDataSourceCollection.prototype.getByName = function (name) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(name)) {\n throw new DeveloperError(\"name is required.\");\n }\n //>>includeEnd('debug');\n\n return this._dataSources.filter(function (dataSource) {\n return dataSource.name === name;\n });\n};\n\nfunction getIndex(dataSources, dataSource) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(dataSource)) {\n throw new DeveloperError(\"dataSource is required.\");\n }\n //>>includeEnd('debug');\n\n const index = dataSources.indexOf(dataSource);\n\n //>>includeStart('debug', pragmas.debug);\n if (index === -1) {\n throw new DeveloperError(\"dataSource is not in this collection.\");\n }\n //>>includeEnd('debug');\n\n return index;\n}\n\nfunction swapDataSources(collection, i, j) {\n const arr = collection._dataSources;\n const length = arr.length - 1;\n i = CesiumMath.clamp(i, 0, length);\n j = CesiumMath.clamp(j, 0, length);\n\n if (i === j) {\n return;\n }\n\n const temp = arr[i];\n arr[i] = arr[j];\n arr[j] = temp;\n\n collection.dataSourceMoved.raiseEvent(temp, j, i);\n}\n\n/**\n * Raises a data source up one position in the collection.\n *\n * @param {DataSource} dataSource The data source to move.\n *\n * @exception {DeveloperError} dataSource is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nDataSourceCollection.prototype.raise = function (dataSource) {\n const index = getIndex(this._dataSources, dataSource);\n swapDataSources(this, index, index + 1);\n};\n\n/**\n * Lowers a data source down one position in the collection.\n *\n * @param {DataSource} dataSource The data source to move.\n *\n * @exception {DeveloperError} dataSource is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nDataSourceCollection.prototype.lower = function (dataSource) {\n const index = getIndex(this._dataSources, dataSource);\n swapDataSources(this, index, index - 1);\n};\n\n/**\n * Raises a data source to the top of the collection.\n *\n * @param {DataSource} dataSource The data source to move.\n *\n * @exception {DeveloperError} dataSource is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nDataSourceCollection.prototype.raiseToTop = function (dataSource) {\n const index = getIndex(this._dataSources, dataSource);\n if (index === this._dataSources.length - 1) {\n return;\n }\n this._dataSources.splice(index, 1);\n this._dataSources.push(dataSource);\n\n this.dataSourceMoved.raiseEvent(\n dataSource,\n this._dataSources.length - 1,\n index\n );\n};\n\n/**\n * Lowers a data source to the bottom of the collection.\n *\n * @param {DataSource} dataSource The data source to move.\n *\n * @exception {DeveloperError} dataSource is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nDataSourceCollection.prototype.lowerToBottom = function (dataSource) {\n const index = getIndex(this._dataSources, dataSource);\n if (index === 0) {\n return;\n }\n this._dataSources.splice(index, 1);\n this._dataSources.splice(0, 0, dataSource);\n\n this.dataSourceMoved.raiseEvent(dataSource, 0, index);\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} true if this object was destroyed; otherwise, false.\n *\n * @see DataSourceCollection#destroy\n */\nDataSourceCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the resources held by all data sources in this collection. Explicitly destroying this\n * object allows for deterministic release of WebGL resources, instead of relying on the garbage\n * collector. Once this object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * dataSourceCollection = dataSourceCollection && dataSourceCollection.destroy();\n *\n * @see DataSourceCollection#isDestroyed\n */\nDataSourceCollection.prototype.destroy = function () {\n this.removeAll(true);\n return destroyObject(this);\n};\nexport default DataSourceCollection;\n", "import createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * A collection of primitives. This is most often used with {@link Scene#primitives},\n * but PrimitiveCollection is also a primitive itself so collections can\n * be added to collections forming a hierarchy.\n *\n * @alias PrimitiveCollection\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {boolean} [options.show=true] Determines if the primitives in the collection will be shown.\n * @param {boolean} [options.destroyPrimitives=true] Determines if primitives in the collection are destroyed when they are removed.\n *\n * @example\n * const billboards = new Cesium.BillboardCollection();\n * const labels = new Cesium.LabelCollection();\n *\n * const collection = new Cesium.PrimitiveCollection();\n * collection.add(billboards);\n *\n * scene.primitives.add(collection); // Add collection\n * scene.primitives.add(labels); // Add regular primitive\n */\nfunction PrimitiveCollection(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n this._primitives = [];\n this._guid = createGuid();\n\n // Used by the OrderedGroundPrimitiveCollection\n this._zIndex = undefined;\n\n /**\n * Determines if primitives in this collection will be shown.\n *\n * @type {boolean}\n * @default true\n */\n this.show = defaultValue(options.show, true);\n\n /**\n * Determines if primitives in the collection are destroyed when they are removed by\n * {@link PrimitiveCollection#destroy} or {@link PrimitiveCollection#remove} or implicitly\n * by {@link PrimitiveCollection#removeAll}.\n *\n * @type {boolean}\n * @default true\n *\n * @example\n * // Example 1. Primitives are destroyed by default.\n * const primitives = new Cesium.PrimitiveCollection();\n * const labels = primitives.add(new Cesium.LabelCollection());\n * primitives = primitives.destroy();\n * const b = labels.isDestroyed(); // true\n *\n * @example\n * // Example 2. Do not destroy primitives in a collection.\n * const primitives = new Cesium.PrimitiveCollection();\n * primitives.destroyPrimitives = false;\n * const labels = primitives.add(new Cesium.LabelCollection());\n * primitives = primitives.destroy();\n * const b = labels.isDestroyed(); // false\n * labels = labels.destroy(); // explicitly destroy\n */\n this.destroyPrimitives = defaultValue(options.destroyPrimitives, true);\n}\n\nObject.defineProperties(PrimitiveCollection.prototype, {\n /**\n * Gets the number of primitives in the collection.\n *\n * @memberof PrimitiveCollection.prototype\n *\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._primitives.length;\n },\n },\n});\n\n/**\n * Adds a primitive to the collection.\n *\n * @param {object} primitive The primitive to add.\n * @param {number} [index] The index to add the layer at. If omitted, the primitive will be added at the bottom of all existing primitives.\n * @returns {object} The primitive added to the collection.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @example\n * const billboards = scene.primitives.add(new Cesium.BillboardCollection());\n */\nPrimitiveCollection.prototype.add = function (primitive, index) {\n const hasIndex = defined(index);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(primitive)) {\n throw new DeveloperError(\"primitive is required.\");\n }\n if (hasIndex) {\n if (index < 0) {\n throw new DeveloperError(\"index must be greater than or equal to zero.\");\n } else if (index > this._primitives.length) {\n throw new DeveloperError(\n \"index must be less than or equal to the number of primitives.\"\n );\n }\n }\n //>>includeEnd('debug');\n\n const external = (primitive._external = primitive._external || {});\n const composites = (external._composites = external._composites || {});\n composites[this._guid] = {\n collection: this,\n };\n\n if (!hasIndex) {\n this._primitives.push(primitive);\n } else {\n this._primitives.splice(index, 0, primitive);\n }\n\n return primitive;\n};\n\n/**\n * Removes a primitive from the collection.\n *\n * @param {object} [primitive] The primitive to remove.\n * @returns {boolean} true if the primitive was removed; false if the primitive is undefined or was not found in the collection.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * const billboards = scene.primitives.add(new Cesium.BillboardCollection());\n * scene.primitives.remove(billboards); // Returns true\n *\n * @see PrimitiveCollection#destroyPrimitives\n */\nPrimitiveCollection.prototype.remove = function (primitive) {\n // PERFORMANCE_IDEA: We can obviously make this a lot faster.\n if (this.contains(primitive)) {\n const index = this._primitives.indexOf(primitive);\n if (index !== -1) {\n this._primitives.splice(index, 1);\n\n delete primitive._external._composites[this._guid];\n\n if (this.destroyPrimitives) {\n primitive.destroy();\n }\n\n return true;\n }\n // else ... this is not possible, I swear.\n }\n\n return false;\n};\n\n/**\n * Removes and destroys a primitive, regardless of destroyPrimitives setting.\n * @private\n */\nPrimitiveCollection.prototype.removeAndDestroy = function (primitive) {\n const removed = this.remove(primitive);\n if (removed && !this.destroyPrimitives) {\n primitive.destroy();\n }\n return removed;\n};\n\n/**\n * Removes all primitives in the collection.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#destroyPrimitives\n */\nPrimitiveCollection.prototype.removeAll = function () {\n const primitives = this._primitives;\n const length = primitives.length;\n for (let i = 0; i < length; ++i) {\n delete primitives[i]._external._composites[this._guid];\n if (this.destroyPrimitives) {\n primitives[i].destroy();\n }\n }\n this._primitives = [];\n};\n\n/**\n * Determines if this collection contains a primitive.\n *\n * @param {object} [primitive] The primitive to check for.\n * @returns {boolean} true if the primitive is in the collection; false if the primitive is undefined or was not found in the collection.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#get\n */\nPrimitiveCollection.prototype.contains = function (primitive) {\n return !!(\n defined(primitive) &&\n primitive._external &&\n primitive._external._composites &&\n primitive._external._composites[this._guid]\n );\n};\n\nfunction getPrimitiveIndex(compositePrimitive, primitive) {\n //>>includeStart('debug', pragmas.debug);\n if (!compositePrimitive.contains(primitive)) {\n throw new DeveloperError(\"primitive is not in this collection.\");\n }\n //>>includeEnd('debug');\n\n return compositePrimitive._primitives.indexOf(primitive);\n}\n\n/**\n * Raises a primitive \"up one\" in the collection. If all primitives in the collection are drawn\n * on the globe surface, this visually moves the primitive up one.\n *\n * @param {object} [primitive] The primitive to raise.\n *\n * @exception {DeveloperError} primitive is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#raiseToTop\n * @see PrimitiveCollection#lower\n * @see PrimitiveCollection#lowerToBottom\n */\nPrimitiveCollection.prototype.raise = function (primitive) {\n if (defined(primitive)) {\n const index = getPrimitiveIndex(this, primitive);\n const primitives = this._primitives;\n\n if (index !== primitives.length - 1) {\n const p = primitives[index];\n primitives[index] = primitives[index + 1];\n primitives[index + 1] = p;\n }\n }\n};\n\n/**\n * Raises a primitive to the \"top\" of the collection. If all primitives in the collection are drawn\n * on the globe surface, this visually moves the primitive to the top.\n *\n * @param {object} [primitive] The primitive to raise the top.\n *\n * @exception {DeveloperError} primitive is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#raise\n * @see PrimitiveCollection#lower\n * @see PrimitiveCollection#lowerToBottom\n */\nPrimitiveCollection.prototype.raiseToTop = function (primitive) {\n if (defined(primitive)) {\n const index = getPrimitiveIndex(this, primitive);\n const primitives = this._primitives;\n\n if (index !== primitives.length - 1) {\n // PERFORMANCE_IDEA: Could be faster\n primitives.splice(index, 1);\n primitives.push(primitive);\n }\n }\n};\n\n/**\n * Lowers a primitive \"down one\" in the collection. If all primitives in the collection are drawn\n * on the globe surface, this visually moves the primitive down one.\n *\n * @param {object} [primitive] The primitive to lower.\n *\n * @exception {DeveloperError} primitive is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#lowerToBottom\n * @see PrimitiveCollection#raise\n * @see PrimitiveCollection#raiseToTop\n */\nPrimitiveCollection.prototype.lower = function (primitive) {\n if (defined(primitive)) {\n const index = getPrimitiveIndex(this, primitive);\n const primitives = this._primitives;\n\n if (index !== 0) {\n const p = primitives[index];\n primitives[index] = primitives[index - 1];\n primitives[index - 1] = p;\n }\n }\n};\n\n/**\n * Lowers a primitive to the \"bottom\" of the collection. If all primitives in the collection are drawn\n * on the globe surface, this visually moves the primitive to the bottom.\n *\n * @param {object} [primitive] The primitive to lower to the bottom.\n *\n * @exception {DeveloperError} primitive is not in this collection.\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see PrimitiveCollection#lower\n * @see PrimitiveCollection#raise\n * @see PrimitiveCollection#raiseToTop\n */\nPrimitiveCollection.prototype.lowerToBottom = function (primitive) {\n if (defined(primitive)) {\n const index = getPrimitiveIndex(this, primitive);\n const primitives = this._primitives;\n\n if (index !== 0) {\n // PERFORMANCE_IDEA: Could be faster\n primitives.splice(index, 1);\n primitives.unshift(primitive);\n }\n }\n};\n\n/**\n * Returns the primitive in the collection at the specified index.\n *\n * @param {number} index The zero-based index of the primitive to return.\n * @returns {object} The primitive at the index.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * // Toggle the show property of every primitive in the collection.\n * const primitives = scene.primitives;\n * const length = primitives.length;\n * for (let i = 0; i < length; ++i) {\n * const p = primitives.get(i);\n * p.show = !p.show;\n * }\n *\n * @see PrimitiveCollection#length\n */\nPrimitiveCollection.prototype.get = function (index) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(index)) {\n throw new DeveloperError(\"index is required.\");\n }\n //>>includeEnd('debug');\n\n return this._primitives[index];\n};\n\n/**\n * @private\n */\nPrimitiveCollection.prototype.update = function (frameState) {\n if (!this.show) {\n return;\n }\n\n const primitives = this._primitives;\n // Using primitives.length in the loop is a temporary workaround\n // to allow quadtree updates to add and remove primitives in\n // update(). This will be changed to manage added and removed lists.\n for (let i = 0; i < primitives.length; ++i) {\n primitives[i].update(frameState);\n }\n};\n\n/**\n * @private\n */\nPrimitiveCollection.prototype.prePassesUpdate = function (frameState) {\n const primitives = this._primitives;\n // Using primitives.length in the loop is a temporary workaround\n // to allow quadtree updates to add and remove primitives in\n // update(). This will be changed to manage added and removed lists.\n for (let i = 0; i < primitives.length; ++i) {\n const primitive = primitives[i];\n if (defined(primitive.prePassesUpdate)) {\n primitive.prePassesUpdate(frameState);\n }\n }\n};\n\n/**\n * @private\n */\nPrimitiveCollection.prototype.updateForPass = function (frameState, passState) {\n const primitives = this._primitives;\n // Using primitives.length in the loop is a temporary workaround\n // to allow quadtree updates to add and remove primitives in\n // update(). This will be changed to manage added and removed lists.\n for (let i = 0; i < primitives.length; ++i) {\n const primitive = primitives[i];\n if (defined(primitive.updateForPass)) {\n primitive.updateForPass(frameState, passState);\n }\n }\n};\n\n/**\n * @private\n */\nPrimitiveCollection.prototype.postPassesUpdate = function (frameState) {\n const primitives = this._primitives;\n // Using primitives.length in the loop is a temporary workaround\n // to allow quadtree updates to add and remove primitives in\n // update(). This will be changed to manage added and removed lists.\n for (let i = 0; i < primitives.length; ++i) {\n const primitive = primitives[i];\n if (defined(primitive.postPassesUpdate)) {\n primitive.postPassesUpdate(frameState);\n }\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see PrimitiveCollection#destroy\n */\nPrimitiveCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by each primitive in this collection. Explicitly destroying this\n * collection allows for deterministic release of WebGL resources, instead of relying on the garbage\n * collector to destroy this collection.\n *

\n * Since destroying a collection destroys all the contained primitives, only destroy a collection\n * when you are sure no other code is still using any of the contained primitives.\n *

\n * Once this collection is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * primitives = primitives && primitives.destroy();\n *\n * @see PrimitiveCollection#isDestroyed\n */\nPrimitiveCollection.prototype.destroy = function () {\n this.removeAll();\n return destroyObject(this);\n};\nexport default PrimitiveCollection;\n", "import Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport PrimitiveCollection from \"./PrimitiveCollection.js\";\n\n/**\n * A primitive collection for helping maintain the order or ground primitives based on a z-index\n *\n * @private\n */\nfunction OrderedGroundPrimitiveCollection() {\n this._length = 0;\n this._collections = {};\n this._collectionsArray = [];\n\n this.show = true;\n}\n\nObject.defineProperties(OrderedGroundPrimitiveCollection.prototype, {\n /**\n * Gets the number of primitives in the collection.\n *\n * @memberof OrderedGroundPrimitiveCollection.prototype\n *\n * @type {number}\n * @readonly\n */\n length: {\n get: function () {\n return this._length;\n },\n },\n});\n\n/**\n * Adds a primitive to the collection.\n *\n * @param {GroundPrimitive} primitive The primitive to add.\n * @param {number} [zIndex = 0] The index of the primitive\n * @returns {GroundPrimitive} The primitive added to the collection.\n */\nOrderedGroundPrimitiveCollection.prototype.add = function (primitive, zIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"primitive\", primitive);\n if (defined(zIndex)) {\n Check.typeOf.number(\"zIndex\", zIndex);\n }\n //>>includeEnd('debug');\n\n zIndex = defaultValue(zIndex, 0);\n let collection = this._collections[zIndex];\n if (!defined(collection)) {\n collection = new PrimitiveCollection({ destroyPrimitives: false });\n collection._zIndex = zIndex;\n this._collections[zIndex] = collection;\n const array = this._collectionsArray;\n let i = 0;\n while (i < array.length && array[i]._zIndex < zIndex) {\n i++;\n }\n array.splice(i, 0, collection);\n }\n\n collection.add(primitive);\n this._length++;\n primitive._zIndex = zIndex;\n\n return primitive;\n};\n\n/**\n * Adjusts the z-index\n * @param {GroundPrimitive} primitive\n * @param {number} zIndex\n */\nOrderedGroundPrimitiveCollection.prototype.set = function (primitive, zIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"primitive\", primitive);\n Check.typeOf.number(\"zIndex\", zIndex);\n //>>includeEnd('debug');\n\n if (zIndex === primitive._zIndex) {\n return primitive;\n }\n\n this.remove(primitive, true);\n this.add(primitive, zIndex);\n\n return primitive;\n};\n\n/**\n * Removes a primitive from the collection.\n *\n * @param {object} primitive The primitive to remove.\n * @param {boolean} [doNotDestroy = false]\n * @returns {boolean} true if the primitive was removed; false if the primitive is undefined or was not found in the collection.\n */\nOrderedGroundPrimitiveCollection.prototype.remove = function (\n primitive,\n doNotDestroy\n) {\n if (this.contains(primitive)) {\n const index = primitive._zIndex;\n const collection = this._collections[index];\n let result;\n if (doNotDestroy) {\n result = collection.remove(primitive);\n } else {\n result = collection.removeAndDestroy(primitive);\n }\n\n if (result) {\n this._length--;\n }\n\n if (collection.length === 0) {\n this._collectionsArray.splice(\n this._collectionsArray.indexOf(collection),\n 1\n );\n this._collections[index] = undefined;\n collection.destroy();\n }\n\n return result;\n }\n\n return false;\n};\n\n/**\n * Removes all primitives in the collection.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n * @see OrderedGroundPrimitiveCollection#destroyPrimitives\n */\nOrderedGroundPrimitiveCollection.prototype.removeAll = function () {\n const collections = this._collectionsArray;\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i];\n collection.destroyPrimitives = true;\n collection.destroy();\n }\n\n this._collections = {};\n this._collectionsArray = [];\n this._length = 0;\n};\n\n/**\n * Determines if this collection contains a primitive.\n *\n * @param {object} primitive The primitive to check for.\n * @returns {boolean} true if the primitive is in the collection; false if the primitive is undefined or was not found in the collection.\n */\nOrderedGroundPrimitiveCollection.prototype.contains = function (primitive) {\n if (!defined(primitive)) {\n return false;\n }\n const collection = this._collections[primitive._zIndex];\n return defined(collection) && collection.contains(primitive);\n};\n\n/**\n * @private\n */\nOrderedGroundPrimitiveCollection.prototype.update = function (frameState) {\n if (!this.show) {\n return;\n }\n\n const collections = this._collectionsArray;\n for (let i = 0; i < collections.length; i++) {\n collections[i].update(frameState);\n }\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see OrderedGroundPrimitiveCollection#destroy\n */\nOrderedGroundPrimitiveCollection.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by each primitive in this collection. Explicitly destroying this\n * collection allows for deterministic release of WebGL resources, instead of relying on the garbage\n * collector to destroy this collection.\n *

\n * Since destroying a collection destroys all the contained primitives, only destroy a collection\n * when you are sure no other code is still using any of the contained primitives.\n *

\n * Once this collection is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * primitives = primitives && primitives.destroy();\n *\n * @see OrderedGroundPrimitiveCollection#isDestroyed\n */\nOrderedGroundPrimitiveCollection.prototype.destroy = function () {\n this.removeAll();\n return destroyObject(this);\n};\nexport default OrderedGroundPrimitiveCollection;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport defined from \"../Core/defined.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\n\n/**\n * @private\n */\nfunction DynamicGeometryBatch(primitives, orderedGroundPrimitives) {\n this._primitives = primitives;\n this._orderedGroundPrimitives = orderedGroundPrimitives;\n this._dynamicUpdaters = new AssociativeArray();\n}\n\nDynamicGeometryBatch.prototype.add = function (time, updater) {\n this._dynamicUpdaters.set(\n updater.id,\n updater.createDynamicUpdater(\n this._primitives,\n this._orderedGroundPrimitives\n )\n );\n};\n\nDynamicGeometryBatch.prototype.remove = function (updater) {\n const id = updater.id;\n const dynamicUpdater = this._dynamicUpdaters.get(id);\n if (defined(dynamicUpdater)) {\n this._dynamicUpdaters.remove(id);\n dynamicUpdater.destroy();\n }\n};\n\nDynamicGeometryBatch.prototype.update = function (time) {\n const geometries = this._dynamicUpdaters.values;\n for (let i = 0, len = geometries.length; i < len; i++) {\n geometries[i].update(time);\n }\n return true;\n};\n\nDynamicGeometryBatch.prototype.removeAllPrimitives = function () {\n const geometries = this._dynamicUpdaters.values;\n for (let i = 0, len = geometries.length; i < len; i++) {\n geometries[i].destroy();\n }\n this._dynamicUpdaters.removeAll();\n};\n\nDynamicGeometryBatch.prototype.getBoundingSphere = function (updater, result) {\n updater = this._dynamicUpdaters.get(updater.id);\n if (defined(updater) && defined(updater.getBoundingSphere)) {\n return updater.getBoundingSphere(result);\n }\n return BoundingSphereState.FAILED;\n};\nexport default DynamicGeometryBatch;\n", "import Cartesian3 from \"./Cartesian3.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport Quaternion from \"./Quaternion.js\";\n\nconst EllipseGeometryLibrary = {};\n\nconst rotAxis = new Cartesian3();\nconst tempVec = new Cartesian3();\nconst unitQuat = new Quaternion();\nconst rotMtx = new Matrix3();\n\nfunction pointOnEllipsoid(\n theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n result\n) {\n const azimuth = theta + rotation;\n\n Cartesian3.multiplyByScalar(eastVec, Math.cos(azimuth), rotAxis);\n Cartesian3.multiplyByScalar(northVec, Math.sin(azimuth), tempVec);\n Cartesian3.add(rotAxis, tempVec, rotAxis);\n\n let cosThetaSquared = Math.cos(theta);\n cosThetaSquared = cosThetaSquared * cosThetaSquared;\n\n let sinThetaSquared = Math.sin(theta);\n sinThetaSquared = sinThetaSquared * sinThetaSquared;\n\n const radius =\n ab / Math.sqrt(bSqr * cosThetaSquared + aSqr * sinThetaSquared);\n const angle = radius / mag;\n\n // Create the quaternion to rotate the position vector to the boundary of the ellipse.\n Quaternion.fromAxisAngle(rotAxis, angle, unitQuat);\n Matrix3.fromQuaternion(unitQuat, rotMtx);\n\n Matrix3.multiplyByVector(rotMtx, unitPos, result);\n Cartesian3.normalize(result, result);\n Cartesian3.multiplyByScalar(result, mag, result);\n return result;\n}\n\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartesian3 = new Cartesian3();\nconst scratchNormal = new Cartesian3();\n/**\n * Returns the positions raised to the given heights\n * @private\n */\nEllipseGeometryLibrary.raisePositionsToHeight = function (\n positions,\n options,\n extrude\n) {\n const ellipsoid = options.ellipsoid;\n const height = options.height;\n const extrudedHeight = options.extrudedHeight;\n const size = extrude ? (positions.length / 3) * 2 : positions.length / 3;\n\n const finalPositions = new Float64Array(size * 3);\n\n const length = positions.length;\n const bottomOffset = extrude ? length : 0;\n for (let i = 0; i < length; i += 3) {\n const i1 = i + 1;\n const i2 = i + 2;\n\n const position = Cartesian3.fromArray(positions, i, scratchCartesian1);\n ellipsoid.scaleToGeodeticSurface(position, position);\n\n const extrudedPosition = Cartesian3.clone(position, scratchCartesian2);\n const normal = ellipsoid.geodeticSurfaceNormal(position, scratchNormal);\n const scaledNormal = Cartesian3.multiplyByScalar(\n normal,\n height,\n scratchCartesian3\n );\n Cartesian3.add(position, scaledNormal, position);\n\n if (extrude) {\n Cartesian3.multiplyByScalar(normal, extrudedHeight, scaledNormal);\n Cartesian3.add(extrudedPosition, scaledNormal, extrudedPosition);\n\n finalPositions[i + bottomOffset] = extrudedPosition.x;\n finalPositions[i1 + bottomOffset] = extrudedPosition.y;\n finalPositions[i2 + bottomOffset] = extrudedPosition.z;\n }\n\n finalPositions[i] = position.x;\n finalPositions[i1] = position.y;\n finalPositions[i2] = position.z;\n }\n\n return finalPositions;\n};\n\nconst unitPosScratch = new Cartesian3();\nconst eastVecScratch = new Cartesian3();\nconst northVecScratch = new Cartesian3();\n/**\n * Returns an array of positions that make up the ellipse.\n * @private\n */\nEllipseGeometryLibrary.computeEllipsePositions = function (\n options,\n addFillPositions,\n addEdgePositions\n) {\n const semiMinorAxis = options.semiMinorAxis;\n const semiMajorAxis = options.semiMajorAxis;\n const rotation = options.rotation;\n const center = options.center;\n\n // Computing the arc-length of the ellipse is too expensive to be practical. Estimating it using the\n // arc length of the sphere is too inaccurate and creates sharp edges when either the semi-major or\n // semi-minor axis is much bigger than the other. Instead, scale the angle delta to make\n // the distance along the ellipse boundary more closely match the granularity.\n const granularity = options.granularity * 8.0;\n\n const aSqr = semiMinorAxis * semiMinorAxis;\n const bSqr = semiMajorAxis * semiMajorAxis;\n const ab = semiMajorAxis * semiMinorAxis;\n\n const mag = Cartesian3.magnitude(center);\n\n const unitPos = Cartesian3.normalize(center, unitPosScratch);\n let eastVec = Cartesian3.cross(Cartesian3.UNIT_Z, center, eastVecScratch);\n eastVec = Cartesian3.normalize(eastVec, eastVec);\n const northVec = Cartesian3.cross(unitPos, eastVec, northVecScratch);\n\n // The number of points in the first quadrant\n let numPts = 1 + Math.ceil(CesiumMath.PI_OVER_TWO / granularity);\n\n const deltaTheta = CesiumMath.PI_OVER_TWO / (numPts - 1);\n let theta = CesiumMath.PI_OVER_TWO - numPts * deltaTheta;\n if (theta < 0.0) {\n numPts -= Math.ceil(Math.abs(theta) / deltaTheta);\n }\n\n // If the number of points were three, the ellipse\n // would be tessellated like below:\n //\n // *---*\n // / | \\ | \\\n // *---*---*---*\n // / | \\ | \\ | \\ | \\\n // / .*---*---*---*. \\\n // * ` | \\ | \\ | \\ | `*\n // \\`.*---*---*---*.`/\n // \\ | \\ | \\ | \\ | /\n // *---*---*---*\n // \\ | \\ | /\n // *---*\n // The first and last column have one position and fan to connect to the adjacent column.\n // Each other vertical column contains an even number of positions.\n const size = 2 * (numPts * (numPts + 2));\n const positions = addFillPositions ? new Array(size * 3) : undefined;\n let positionIndex = 0;\n let position = scratchCartesian1;\n let reflectedPosition = scratchCartesian2;\n\n const outerPositionsLength = numPts * 4 * 3;\n let outerRightIndex = outerPositionsLength - 1;\n let outerLeftIndex = 0;\n const outerPositions = addEdgePositions\n ? new Array(outerPositionsLength)\n : undefined;\n\n let i;\n let j;\n let numInterior;\n let t;\n let interiorPosition;\n\n // Compute points in the 'eastern' half of the ellipse\n theta = CesiumMath.PI_OVER_TWO;\n position = pointOnEllipsoid(\n theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n position\n );\n if (addFillPositions) {\n positions[positionIndex++] = position.x;\n positions[positionIndex++] = position.y;\n positions[positionIndex++] = position.z;\n }\n if (addEdgePositions) {\n outerPositions[outerRightIndex--] = position.z;\n outerPositions[outerRightIndex--] = position.y;\n outerPositions[outerRightIndex--] = position.x;\n }\n theta = CesiumMath.PI_OVER_TWO - deltaTheta;\n for (i = 1; i < numPts + 1; ++i) {\n position = pointOnEllipsoid(\n theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n position\n );\n reflectedPosition = pointOnEllipsoid(\n Math.PI - theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n reflectedPosition\n );\n\n if (addFillPositions) {\n positions[positionIndex++] = position.x;\n positions[positionIndex++] = position.y;\n positions[positionIndex++] = position.z;\n\n numInterior = 2 * i + 2;\n for (j = 1; j < numInterior - 1; ++j) {\n t = j / (numInterior - 1);\n interiorPosition = Cartesian3.lerp(\n position,\n reflectedPosition,\n t,\n scratchCartesian3\n );\n positions[positionIndex++] = interiorPosition.x;\n positions[positionIndex++] = interiorPosition.y;\n positions[positionIndex++] = interiorPosition.z;\n }\n\n positions[positionIndex++] = reflectedPosition.x;\n positions[positionIndex++] = reflectedPosition.y;\n positions[positionIndex++] = reflectedPosition.z;\n }\n\n if (addEdgePositions) {\n outerPositions[outerRightIndex--] = position.z;\n outerPositions[outerRightIndex--] = position.y;\n outerPositions[outerRightIndex--] = position.x;\n outerPositions[outerLeftIndex++] = reflectedPosition.x;\n outerPositions[outerLeftIndex++] = reflectedPosition.y;\n outerPositions[outerLeftIndex++] = reflectedPosition.z;\n }\n\n theta = CesiumMath.PI_OVER_TWO - (i + 1) * deltaTheta;\n }\n\n // Compute points in the 'western' half of the ellipse\n for (i = numPts; i > 1; --i) {\n theta = CesiumMath.PI_OVER_TWO - (i - 1) * deltaTheta;\n\n position = pointOnEllipsoid(\n -theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n position\n );\n reflectedPosition = pointOnEllipsoid(\n theta + Math.PI,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n reflectedPosition\n );\n\n if (addFillPositions) {\n positions[positionIndex++] = position.x;\n positions[positionIndex++] = position.y;\n positions[positionIndex++] = position.z;\n\n numInterior = 2 * (i - 1) + 2;\n for (j = 1; j < numInterior - 1; ++j) {\n t = j / (numInterior - 1);\n interiorPosition = Cartesian3.lerp(\n position,\n reflectedPosition,\n t,\n scratchCartesian3\n );\n positions[positionIndex++] = interiorPosition.x;\n positions[positionIndex++] = interiorPosition.y;\n positions[positionIndex++] = interiorPosition.z;\n }\n\n positions[positionIndex++] = reflectedPosition.x;\n positions[positionIndex++] = reflectedPosition.y;\n positions[positionIndex++] = reflectedPosition.z;\n }\n\n if (addEdgePositions) {\n outerPositions[outerRightIndex--] = position.z;\n outerPositions[outerRightIndex--] = position.y;\n outerPositions[outerRightIndex--] = position.x;\n outerPositions[outerLeftIndex++] = reflectedPosition.x;\n outerPositions[outerLeftIndex++] = reflectedPosition.y;\n outerPositions[outerLeftIndex++] = reflectedPosition.z;\n }\n }\n\n theta = CesiumMath.PI_OVER_TWO;\n position = pointOnEllipsoid(\n -theta,\n rotation,\n northVec,\n eastVec,\n aSqr,\n ab,\n bSqr,\n mag,\n unitPos,\n position\n );\n\n const r = {};\n if (addFillPositions) {\n positions[positionIndex++] = position.x;\n positions[positionIndex++] = position.y;\n positions[positionIndex++] = position.z;\n r.positions = positions;\n r.numPts = numPts;\n }\n if (addEdgePositions) {\n outerPositions[outerRightIndex--] = position.z;\n outerPositions[outerRightIndex--] = position.y;\n outerPositions[outerRightIndex--] = position.x;\n r.outerPositions = outerPositions;\n }\n\n return r;\n};\nexport default EllipseGeometryLibrary;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport EllipseGeometryLibrary from \"./EllipseGeometryLibrary.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport GeographicProjection from \"./GeographicProjection.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst scratchCartesian1 = new Cartesian3();\nconst scratchCartesian2 = new Cartesian3();\nconst scratchCartesian3 = new Cartesian3();\nconst scratchCartesian4 = new Cartesian3();\nconst texCoordScratch = new Cartesian2();\nconst textureMatrixScratch = new Matrix3();\nconst tangentMatrixScratch = new Matrix3();\nconst quaternionScratch = new Quaternion();\n\nconst scratchNormal = new Cartesian3();\nconst scratchTangent = new Cartesian3();\nconst scratchBitangent = new Cartesian3();\n\nconst scratchCartographic = new Cartographic();\nconst projectedCenterScratch = new Cartesian3();\n\nconst scratchMinTexCoord = new Cartesian2();\nconst scratchMaxTexCoord = new Cartesian2();\n\nfunction computeTopBottomAttributes(positions, options, extrude) {\n const vertexFormat = options.vertexFormat;\n const center = options.center;\n const semiMajorAxis = options.semiMajorAxis;\n const semiMinorAxis = options.semiMinorAxis;\n const ellipsoid = options.ellipsoid;\n const stRotation = options.stRotation;\n const size = extrude ? (positions.length / 3) * 2 : positions.length / 3;\n const shadowVolume = options.shadowVolume;\n\n const textureCoordinates = vertexFormat.st\n ? new Float32Array(size * 2)\n : undefined;\n const normals = vertexFormat.normal ? new Float32Array(size * 3) : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(size * 3)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(size * 3)\n : undefined;\n\n const extrudeNormals = shadowVolume ? new Float32Array(size * 3) : undefined;\n\n let textureCoordIndex = 0;\n\n // Raise positions to a height above the ellipsoid and compute the\n // texture coordinates, normals, tangents, and bitangents.\n let normal = scratchNormal;\n let tangent = scratchTangent;\n let bitangent = scratchBitangent;\n\n const projection = new GeographicProjection(ellipsoid);\n const projectedCenter = projection.project(\n ellipsoid.cartesianToCartographic(center, scratchCartographic),\n projectedCenterScratch\n );\n\n const geodeticNormal = ellipsoid.scaleToGeodeticSurface(\n center,\n scratchCartesian1\n );\n ellipsoid.geodeticSurfaceNormal(geodeticNormal, geodeticNormal);\n\n let textureMatrix = textureMatrixScratch;\n let tangentMatrix = tangentMatrixScratch;\n if (stRotation !== 0) {\n let rotation = Quaternion.fromAxisAngle(\n geodeticNormal,\n stRotation,\n quaternionScratch\n );\n textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrix);\n\n rotation = Quaternion.fromAxisAngle(\n geodeticNormal,\n -stRotation,\n quaternionScratch\n );\n tangentMatrix = Matrix3.fromQuaternion(rotation, tangentMatrix);\n } else {\n textureMatrix = Matrix3.clone(Matrix3.IDENTITY, textureMatrix);\n tangentMatrix = Matrix3.clone(Matrix3.IDENTITY, tangentMatrix);\n }\n\n const minTexCoord = Cartesian2.fromElements(\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n scratchMinTexCoord\n );\n const maxTexCoord = Cartesian2.fromElements(\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n scratchMaxTexCoord\n );\n\n let length = positions.length;\n const bottomOffset = extrude ? length : 0;\n const stOffset = (bottomOffset / 3) * 2;\n for (let i = 0; i < length; i += 3) {\n const i1 = i + 1;\n const i2 = i + 2;\n const position = Cartesian3.fromArray(positions, i, scratchCartesian1);\n\n if (vertexFormat.st) {\n const rotatedPoint = Matrix3.multiplyByVector(\n textureMatrix,\n position,\n scratchCartesian2\n );\n const projectedPoint = projection.project(\n ellipsoid.cartesianToCartographic(rotatedPoint, scratchCartographic),\n scratchCartesian3\n );\n Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);\n\n texCoordScratch.x =\n (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);\n texCoordScratch.y =\n (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);\n\n minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);\n minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);\n maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);\n maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);\n\n if (extrude) {\n textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;\n textureCoordinates[textureCoordIndex + 1 + stOffset] =\n texCoordScratch.y;\n }\n\n textureCoordinates[textureCoordIndex++] = texCoordScratch.x;\n textureCoordinates[textureCoordIndex++] = texCoordScratch.y;\n }\n\n if (\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent ||\n shadowVolume\n ) {\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n\n if (shadowVolume) {\n extrudeNormals[i + bottomOffset] = -normal.x;\n extrudeNormals[i1 + bottomOffset] = -normal.y;\n extrudeNormals[i2 + bottomOffset] = -normal.z;\n }\n\n if (\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent\n ) {\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent),\n tangent\n );\n Matrix3.multiplyByVector(tangentMatrix, tangent, tangent);\n }\n if (vertexFormat.normal) {\n normals[i] = normal.x;\n normals[i1] = normal.y;\n normals[i2] = normal.z;\n if (extrude) {\n normals[i + bottomOffset] = -normal.x;\n normals[i1 + bottomOffset] = -normal.y;\n normals[i2 + bottomOffset] = -normal.z;\n }\n }\n\n if (vertexFormat.tangent) {\n tangents[i] = tangent.x;\n tangents[i1] = tangent.y;\n tangents[i2] = tangent.z;\n if (extrude) {\n tangents[i + bottomOffset] = -tangent.x;\n tangents[i1 + bottomOffset] = -tangent.y;\n tangents[i2 + bottomOffset] = -tangent.z;\n }\n }\n\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n bitangents[i] = bitangent.x;\n bitangents[i1] = bitangent.y;\n bitangents[i2] = bitangent.z;\n if (extrude) {\n bitangents[i + bottomOffset] = bitangent.x;\n bitangents[i1 + bottomOffset] = bitangent.y;\n bitangents[i2 + bottomOffset] = bitangent.z;\n }\n }\n }\n }\n }\n\n if (vertexFormat.st) {\n length = textureCoordinates.length;\n for (let k = 0; k < length; k += 2) {\n textureCoordinates[k] =\n (textureCoordinates[k] - minTexCoord.x) /\n (maxTexCoord.x - minTexCoord.x);\n textureCoordinates[k + 1] =\n (textureCoordinates[k + 1] - minTexCoord.y) /\n (maxTexCoord.y - minTexCoord.y);\n }\n }\n\n const attributes = new GeometryAttributes();\n\n if (vertexFormat.position) {\n const finalPositions = EllipseGeometryLibrary.raisePositionsToHeight(\n positions,\n options,\n extrude\n );\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: finalPositions,\n });\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (shadowVolume) {\n attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: extrudeNormals,\n });\n }\n\n if (extrude && defined(options.offsetAttribute)) {\n let offsetAttribute = new Uint8Array(size);\n if (options.offsetAttribute === GeometryOffsetAttribute.TOP) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else {\n const offsetValue =\n options.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n });\n }\n\n return attributes;\n}\n\nfunction topIndices(numPts) {\n // numTriangles in half = 3 + 8 + 12 + ... = -1 + 4 + (4 + 4) + (4 + 4 + 4) + ... = -1 + 4 * (1 + 2 + 3 + ...)\n // = -1 + 4 * ((n * ( n + 1)) / 2)\n // total triangles = 2 * numTrangles in half\n // indices = total triangles * 3;\n // Substitute numPts for n above\n\n const indices = new Array(12 * (numPts * (numPts + 1)) - 6);\n let indicesIndex = 0;\n let prevIndex;\n let numInterior;\n let positionIndex;\n let i;\n let j;\n // Indices triangles to the 'right' of the north vector\n\n prevIndex = 0;\n positionIndex = 1;\n for (i = 0; i < 3; i++) {\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n\n for (i = 2; i < numPts + 1; ++i) {\n positionIndex = i * (i + 1) - 1;\n prevIndex = (i - 1) * i - 1;\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n\n numInterior = 2 * i;\n for (j = 0; j < numInterior - 1; ++j) {\n indices[indicesIndex++] = positionIndex;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n\n // Indices for center column of triangles\n numInterior = numPts * 2;\n ++positionIndex;\n ++prevIndex;\n for (i = 0; i < numInterior - 1; ++i) {\n indices[indicesIndex++] = positionIndex;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n\n indices[indicesIndex++] = positionIndex;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n\n // Reverse the process creating indices to the 'left' of the north vector\n ++prevIndex;\n for (i = numPts - 1; i > 1; --i) {\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n\n numInterior = 2 * i;\n for (j = 0; j < numInterior - 1; ++j) {\n indices[indicesIndex++] = positionIndex;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n\n indices[indicesIndex++] = positionIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = positionIndex++;\n }\n\n for (i = 0; i < 3; i++) {\n indices[indicesIndex++] = prevIndex++;\n indices[indicesIndex++] = prevIndex;\n indices[indicesIndex++] = positionIndex;\n }\n return indices;\n}\n\nlet boundingSphereCenter = new Cartesian3();\n\nfunction computeEllipse(options) {\n const center = options.center;\n boundingSphereCenter = Cartesian3.multiplyByScalar(\n options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter),\n options.height,\n boundingSphereCenter\n );\n boundingSphereCenter = Cartesian3.add(\n center,\n boundingSphereCenter,\n boundingSphereCenter\n );\n const boundingSphere = new BoundingSphere(\n boundingSphereCenter,\n options.semiMajorAxis\n );\n const cep = EllipseGeometryLibrary.computeEllipsePositions(\n options,\n true,\n false\n );\n const positions = cep.positions;\n const numPts = cep.numPts;\n const attributes = computeTopBottomAttributes(positions, options, false);\n let indices = topIndices(numPts);\n indices = IndexDatatype.createTypedArray(positions.length / 3, indices);\n return {\n boundingSphere: boundingSphere,\n attributes: attributes,\n indices: indices,\n };\n}\n\nfunction computeWallAttributes(positions, options) {\n const vertexFormat = options.vertexFormat;\n const center = options.center;\n const semiMajorAxis = options.semiMajorAxis;\n const semiMinorAxis = options.semiMinorAxis;\n const ellipsoid = options.ellipsoid;\n const height = options.height;\n const extrudedHeight = options.extrudedHeight;\n const stRotation = options.stRotation;\n const size = (positions.length / 3) * 2;\n\n const finalPositions = new Float64Array(size * 3);\n const textureCoordinates = vertexFormat.st\n ? new Float32Array(size * 2)\n : undefined;\n const normals = vertexFormat.normal ? new Float32Array(size * 3) : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(size * 3)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(size * 3)\n : undefined;\n\n const shadowVolume = options.shadowVolume;\n const extrudeNormals = shadowVolume ? new Float32Array(size * 3) : undefined;\n\n let textureCoordIndex = 0;\n\n // Raise positions to a height above the ellipsoid and compute the\n // texture coordinates, normals, tangents, and bitangents.\n let normal = scratchNormal;\n let tangent = scratchTangent;\n let bitangent = scratchBitangent;\n\n const projection = new GeographicProjection(ellipsoid);\n const projectedCenter = projection.project(\n ellipsoid.cartesianToCartographic(center, scratchCartographic),\n projectedCenterScratch\n );\n\n const geodeticNormal = ellipsoid.scaleToGeodeticSurface(\n center,\n scratchCartesian1\n );\n ellipsoid.geodeticSurfaceNormal(geodeticNormal, geodeticNormal);\n const rotation = Quaternion.fromAxisAngle(\n geodeticNormal,\n stRotation,\n quaternionScratch\n );\n const textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrixScratch);\n\n const minTexCoord = Cartesian2.fromElements(\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n scratchMinTexCoord\n );\n const maxTexCoord = Cartesian2.fromElements(\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n scratchMaxTexCoord\n );\n\n let length = positions.length;\n const stOffset = (length / 3) * 2;\n for (let i = 0; i < length; i += 3) {\n const i1 = i + 1;\n const i2 = i + 2;\n let position = Cartesian3.fromArray(positions, i, scratchCartesian1);\n let extrudedPosition;\n\n if (vertexFormat.st) {\n const rotatedPoint = Matrix3.multiplyByVector(\n textureMatrix,\n position,\n scratchCartesian2\n );\n const projectedPoint = projection.project(\n ellipsoid.cartesianToCartographic(rotatedPoint, scratchCartographic),\n scratchCartesian3\n );\n Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);\n\n texCoordScratch.x =\n (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);\n texCoordScratch.y =\n (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);\n\n minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);\n minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);\n maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);\n maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);\n\n textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;\n textureCoordinates[textureCoordIndex + 1 + stOffset] = texCoordScratch.y;\n\n textureCoordinates[textureCoordIndex++] = texCoordScratch.x;\n textureCoordinates[textureCoordIndex++] = texCoordScratch.y;\n }\n\n position = ellipsoid.scaleToGeodeticSurface(position, position);\n extrudedPosition = Cartesian3.clone(position, scratchCartesian2);\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n\n if (shadowVolume) {\n extrudeNormals[i + length] = -normal.x;\n extrudeNormals[i1 + length] = -normal.y;\n extrudeNormals[i2 + length] = -normal.z;\n }\n\n let scaledNormal = Cartesian3.multiplyByScalar(\n normal,\n height,\n scratchCartesian4\n );\n position = Cartesian3.add(position, scaledNormal, position);\n scaledNormal = Cartesian3.multiplyByScalar(\n normal,\n extrudedHeight,\n scaledNormal\n );\n extrudedPosition = Cartesian3.add(\n extrudedPosition,\n scaledNormal,\n extrudedPosition\n );\n\n if (vertexFormat.position) {\n finalPositions[i + length] = extrudedPosition.x;\n finalPositions[i1 + length] = extrudedPosition.y;\n finalPositions[i2 + length] = extrudedPosition.z;\n\n finalPositions[i] = position.x;\n finalPositions[i1] = position.y;\n finalPositions[i2] = position.z;\n }\n\n if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {\n bitangent = Cartesian3.clone(normal, bitangent);\n const next = Cartesian3.fromArray(\n positions,\n (i + 3) % length,\n scratchCartesian4\n );\n Cartesian3.subtract(next, position, next);\n const bottom = Cartesian3.subtract(\n extrudedPosition,\n position,\n scratchCartesian3\n );\n\n normal = Cartesian3.normalize(\n Cartesian3.cross(bottom, next, normal),\n normal\n );\n\n if (vertexFormat.normal) {\n normals[i] = normal.x;\n normals[i1] = normal.y;\n normals[i2] = normal.z;\n\n normals[i + length] = normal.x;\n normals[i1 + length] = normal.y;\n normals[i2 + length] = normal.z;\n }\n\n if (vertexFormat.tangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(bitangent, normal, tangent),\n tangent\n );\n tangents[i] = tangent.x;\n tangents[i1] = tangent.y;\n tangents[i2] = tangent.z;\n\n tangents[i + length] = tangent.x;\n tangents[i + 1 + length] = tangent.y;\n tangents[i + 2 + length] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n bitangents[i] = bitangent.x;\n bitangents[i1] = bitangent.y;\n bitangents[i2] = bitangent.z;\n\n bitangents[i + length] = bitangent.x;\n bitangents[i1 + length] = bitangent.y;\n bitangents[i2 + length] = bitangent.z;\n }\n }\n }\n\n if (vertexFormat.st) {\n length = textureCoordinates.length;\n for (let k = 0; k < length; k += 2) {\n textureCoordinates[k] =\n (textureCoordinates[k] - minTexCoord.x) /\n (maxTexCoord.x - minTexCoord.x);\n textureCoordinates[k + 1] =\n (textureCoordinates[k + 1] - minTexCoord.y) /\n (maxTexCoord.y - minTexCoord.y);\n }\n }\n\n const attributes = new GeometryAttributes();\n\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: finalPositions,\n });\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (shadowVolume) {\n attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: extrudeNormals,\n });\n }\n\n if (defined(options.offsetAttribute)) {\n let offsetAttribute = new Uint8Array(size);\n if (options.offsetAttribute === GeometryOffsetAttribute.TOP) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else {\n const offsetValue =\n options.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n });\n }\n\n return attributes;\n}\n\nfunction computeWallIndices(positions) {\n const length = positions.length / 3;\n const indices = IndexDatatype.createTypedArray(length, length * 6);\n let index = 0;\n for (let i = 0; i < length; i++) {\n const UL = i;\n const LL = i + length;\n const UR = (UL + 1) % length;\n const LR = UR + length;\n indices[index++] = UL;\n indices[index++] = LL;\n indices[index++] = UR;\n indices[index++] = UR;\n indices[index++] = LL;\n indices[index++] = LR;\n }\n\n return indices;\n}\n\nconst topBoundingSphere = new BoundingSphere();\nconst bottomBoundingSphere = new BoundingSphere();\n\nfunction computeExtrudedEllipse(options) {\n const center = options.center;\n const ellipsoid = options.ellipsoid;\n const semiMajorAxis = options.semiMajorAxis;\n let scaledNormal = Cartesian3.multiplyByScalar(\n ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1),\n options.height,\n scratchCartesian1\n );\n topBoundingSphere.center = Cartesian3.add(\n center,\n scaledNormal,\n topBoundingSphere.center\n );\n topBoundingSphere.radius = semiMajorAxis;\n\n scaledNormal = Cartesian3.multiplyByScalar(\n ellipsoid.geodeticSurfaceNormal(center, scaledNormal),\n options.extrudedHeight,\n scaledNormal\n );\n bottomBoundingSphere.center = Cartesian3.add(\n center,\n scaledNormal,\n bottomBoundingSphere.center\n );\n bottomBoundingSphere.radius = semiMajorAxis;\n\n const cep = EllipseGeometryLibrary.computeEllipsePositions(\n options,\n true,\n true\n );\n const positions = cep.positions;\n const numPts = cep.numPts;\n const outerPositions = cep.outerPositions;\n const boundingSphere = BoundingSphere.union(\n topBoundingSphere,\n bottomBoundingSphere\n );\n const topBottomAttributes = computeTopBottomAttributes(\n positions,\n options,\n true\n );\n let indices = topIndices(numPts);\n const length = indices.length;\n indices.length = length * 2;\n const posLength = positions.length / 3;\n for (let i = 0; i < length; i += 3) {\n indices[i + length] = indices[i + 2] + posLength;\n indices[i + 1 + length] = indices[i + 1] + posLength;\n indices[i + 2 + length] = indices[i] + posLength;\n }\n\n const topBottomIndices = IndexDatatype.createTypedArray(\n (posLength * 2) / 3,\n indices\n );\n\n const topBottomGeo = new Geometry({\n attributes: topBottomAttributes,\n indices: topBottomIndices,\n primitiveType: PrimitiveType.TRIANGLES,\n });\n\n const wallAttributes = computeWallAttributes(outerPositions, options);\n indices = computeWallIndices(outerPositions);\n const wallIndices = IndexDatatype.createTypedArray(\n (outerPositions.length * 2) / 3,\n indices\n );\n\n const wallGeo = new Geometry({\n attributes: wallAttributes,\n indices: wallIndices,\n primitiveType: PrimitiveType.TRIANGLES,\n });\n\n const geo = GeometryPipeline.combineInstances([\n new GeometryInstance({\n geometry: topBottomGeo,\n }),\n new GeometryInstance({\n geometry: wallGeo,\n }),\n ]);\n\n return {\n boundingSphere: boundingSphere,\n attributes: geo[0].attributes,\n indices: geo[0].indices,\n };\n}\n\nfunction computeRectangle(\n center,\n semiMajorAxis,\n semiMinorAxis,\n rotation,\n granularity,\n ellipsoid,\n result\n) {\n const cep = EllipseGeometryLibrary.computeEllipsePositions(\n {\n center: center,\n semiMajorAxis: semiMajorAxis,\n semiMinorAxis: semiMinorAxis,\n rotation: rotation,\n granularity: granularity,\n },\n false,\n true\n );\n const positionsFlat = cep.outerPositions;\n const positionsCount = positionsFlat.length / 3;\n const positions = new Array(positionsCount);\n for (let i = 0; i < positionsCount; ++i) {\n positions[i] = Cartesian3.fromArray(positionsFlat, i * 3);\n }\n const rectangle = Rectangle.fromCartesianArray(positions, ellipsoid, result);\n // Rectangle width goes beyond 180 degrees when the ellipse crosses a pole.\n // When this happens, make the rectangle into a \"circle\" around the pole\n if (rectangle.width > CesiumMath.PI) {\n rectangle.north =\n rectangle.north > 0.0\n ? CesiumMath.PI_OVER_TWO - CesiumMath.EPSILON7\n : rectangle.north;\n rectangle.south =\n rectangle.south < 0.0\n ? CesiumMath.EPSILON7 - CesiumMath.PI_OVER_TWO\n : rectangle.south;\n rectangle.east = CesiumMath.PI;\n rectangle.west = -CesiumMath.PI;\n }\n return rectangle;\n}\n\n/**\n * A description of an ellipse on an ellipsoid. Ellipse geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.\n *\n * @alias EllipseGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.\n * @param {number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.\n * @param {number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.\n * @param {number} [options.height=0.0] The distance in meters between the ellipse and the ellipsoid surface.\n * @param {number} [options.extrudedHeight] The distance in meters between the ellipse's extruded face and the ellipsoid surface.\n * @param {number} [options.rotation=0.0] The angle of rotation counter-clockwise from north.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates counter-clockwise from north.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The angular distance between points on the ellipse in radians.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @exception {DeveloperError} semiMajorAxis and semiMinorAxis must be greater than zero.\n * @exception {DeveloperError} semiMajorAxis must be greater than or equal to the semiMinorAxis.\n * @exception {DeveloperError} granularity must be greater than zero.\n *\n *\n * @example\n * // Create an ellipse.\n * const ellipse = new Cesium.EllipseGeometry({\n * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),\n * semiMajorAxis : 500000.0,\n * semiMinorAxis : 300000.0,\n * rotation : Cesium.Math.toRadians(60.0)\n * });\n * const geometry = Cesium.EllipseGeometry.createGeometry(ellipse);\n *\n * @see EllipseGeometry.createGeometry\n */\nfunction EllipseGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const center = options.center;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const semiMajorAxis = options.semiMajorAxis;\n const semiMinorAxis = options.semiMinorAxis;\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.center\", center);\n Check.typeOf.number(\"options.semiMajorAxis\", semiMajorAxis);\n Check.typeOf.number(\"options.semiMinorAxis\", semiMinorAxis);\n if (semiMajorAxis < semiMinorAxis) {\n throw new DeveloperError(\n \"semiMajorAxis must be greater than or equal to the semiMinorAxis.\"\n );\n }\n if (granularity <= 0.0) {\n throw new DeveloperError(\"granularity must be greater than zero.\");\n }\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._center = Cartesian3.clone(center);\n this._semiMajorAxis = semiMajorAxis;\n this._semiMinorAxis = semiMinorAxis;\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._rotation = defaultValue(options.rotation, 0.0);\n this._stRotation = defaultValue(options.stRotation, 0.0);\n this._height = Math.max(extrudedHeight, height);\n this._granularity = granularity;\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._extrudedHeight = Math.min(extrudedHeight, height);\n this._shadowVolume = defaultValue(options.shadowVolume, false);\n this._workerName = \"createEllipseGeometry\";\n this._offsetAttribute = options.offsetAttribute;\n\n this._rectangle = undefined;\n this._textureCoordinateRotationPoints = undefined;\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nEllipseGeometry.packedLength =\n Cartesian3.packedLength +\n Ellipsoid.packedLength +\n VertexFormat.packedLength +\n 9;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {EllipseGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nEllipseGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._center, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._semiMajorAxis;\n array[startingIndex++] = value._semiMinorAxis;\n array[startingIndex++] = value._rotation;\n array[startingIndex++] = value._stRotation;\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchCenter = new Cartesian3();\nconst scratchEllipsoid = new Ellipsoid();\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n center: scratchCenter,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n semiMajorAxis: undefined,\n semiMinorAxis: undefined,\n rotation: undefined,\n stRotation: undefined,\n height: undefined,\n granularity: undefined,\n extrudedHeight: undefined,\n shadowVolume: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {EllipseGeometry} [result] The object into which to store the result.\n * @returns {EllipseGeometry} The modified result parameter or a new EllipseGeometry instance if one was not provided.\n */\nEllipseGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const center = Cartesian3.unpack(array, startingIndex, scratchCenter);\n startingIndex += Cartesian3.packedLength;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const semiMajorAxis = array[startingIndex++];\n const semiMinorAxis = array[startingIndex++];\n const rotation = array[startingIndex++];\n const stRotation = array[startingIndex++];\n const height = array[startingIndex++];\n const granularity = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const shadowVolume = array[startingIndex++] === 1.0;\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.height = height;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.granularity = granularity;\n scratchOptions.stRotation = stRotation;\n scratchOptions.rotation = rotation;\n scratchOptions.semiMajorAxis = semiMajorAxis;\n scratchOptions.semiMinorAxis = semiMinorAxis;\n scratchOptions.shadowVolume = shadowVolume;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return new EllipseGeometry(scratchOptions);\n }\n\n result._center = Cartesian3.clone(center, result._center);\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._semiMajorAxis = semiMajorAxis;\n result._semiMinorAxis = semiMinorAxis;\n result._rotation = rotation;\n result._stRotation = stRotation;\n result._height = height;\n result._granularity = granularity;\n result._extrudedHeight = extrudedHeight;\n result._shadowVolume = shadowVolume;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the bounding rectangle based on the provided options\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.\n * @param {number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.\n * @param {number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.\n * @param {number} [options.rotation=0.0] The angle of rotation counter-clockwise from north.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The angular distance between points on the ellipse in radians.\n * @param {Rectangle} [result] An object in which to store the result\n *\n * @returns {Rectangle} The result rectangle\n */\nEllipseGeometry.computeRectangle = function (options, result) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const center = options.center;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const semiMajorAxis = options.semiMajorAxis;\n const semiMinorAxis = options.semiMinorAxis;\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const rotation = defaultValue(options.rotation, 0.0);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.center\", center);\n Check.typeOf.number(\"options.semiMajorAxis\", semiMajorAxis);\n Check.typeOf.number(\"options.semiMinorAxis\", semiMinorAxis);\n if (semiMajorAxis < semiMinorAxis) {\n throw new DeveloperError(\n \"semiMajorAxis must be greater than or equal to the semiMinorAxis.\"\n );\n }\n if (granularity <= 0.0) {\n throw new DeveloperError(\"granularity must be greater than zero.\");\n }\n //>>includeEnd('debug');\n\n return computeRectangle(\n center,\n semiMajorAxis,\n semiMinorAxis,\n rotation,\n granularity,\n ellipsoid,\n result\n );\n};\n\n/**\n * Computes the geometric representation of a ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere.\n *\n * @param {EllipseGeometry} ellipseGeometry A description of the ellipse.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nEllipseGeometry.createGeometry = function (ellipseGeometry) {\n if (\n ellipseGeometry._semiMajorAxis <= 0.0 ||\n ellipseGeometry._semiMinorAxis <= 0.0\n ) {\n return;\n }\n\n const height = ellipseGeometry._height;\n const extrudedHeight = ellipseGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n height,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n\n ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(\n ellipseGeometry._center,\n ellipseGeometry._center\n );\n const options = {\n center: ellipseGeometry._center,\n semiMajorAxis: ellipseGeometry._semiMajorAxis,\n semiMinorAxis: ellipseGeometry._semiMinorAxis,\n ellipsoid: ellipseGeometry._ellipsoid,\n rotation: ellipseGeometry._rotation,\n height: height,\n granularity: ellipseGeometry._granularity,\n vertexFormat: ellipseGeometry._vertexFormat,\n stRotation: ellipseGeometry._stRotation,\n };\n let geometry;\n if (extrude) {\n options.extrudedHeight = extrudedHeight;\n options.shadowVolume = ellipseGeometry._shadowVolume;\n options.offsetAttribute = ellipseGeometry._offsetAttribute;\n geometry = computeExtrudedEllipse(options);\n } else {\n geometry = computeEllipse(options);\n\n if (defined(ellipseGeometry._offsetAttribute)) {\n const length = geometry.attributes.position.values.length;\n const offsetValue =\n ellipseGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n }\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: geometry.boundingSphere,\n offsetAttribute: ellipseGeometry._offsetAttribute,\n });\n};\n\n/**\n * @private\n */\nEllipseGeometry.createShadowVolume = function (\n ellipseGeometry,\n minHeightFunc,\n maxHeightFunc\n) {\n const granularity = ellipseGeometry._granularity;\n const ellipsoid = ellipseGeometry._ellipsoid;\n\n const minHeight = minHeightFunc(granularity, ellipsoid);\n const maxHeight = maxHeightFunc(granularity, ellipsoid);\n\n return new EllipseGeometry({\n center: ellipseGeometry._center,\n semiMajorAxis: ellipseGeometry._semiMajorAxis,\n semiMinorAxis: ellipseGeometry._semiMinorAxis,\n ellipsoid: ellipsoid,\n rotation: ellipseGeometry._rotation,\n stRotation: ellipseGeometry._stRotation,\n granularity: granularity,\n extrudedHeight: minHeight,\n height: maxHeight,\n vertexFormat: VertexFormat.POSITION_ONLY,\n shadowVolume: true,\n });\n};\n\nfunction textureCoordinateRotationPoints(ellipseGeometry) {\n const stRotation = -ellipseGeometry._stRotation;\n if (stRotation === 0.0) {\n return [0, 0, 0, 1, 1, 0];\n }\n\n const cep = EllipseGeometryLibrary.computeEllipsePositions(\n {\n center: ellipseGeometry._center,\n semiMajorAxis: ellipseGeometry._semiMajorAxis,\n semiMinorAxis: ellipseGeometry._semiMinorAxis,\n rotation: ellipseGeometry._rotation,\n granularity: ellipseGeometry._granularity,\n },\n false,\n true\n );\n const positionsFlat = cep.outerPositions;\n const positionsCount = positionsFlat.length / 3;\n const positions = new Array(positionsCount);\n for (let i = 0; i < positionsCount; ++i) {\n positions[i] = Cartesian3.fromArray(positionsFlat, i * 3);\n }\n\n const ellipsoid = ellipseGeometry._ellipsoid;\n const boundingRectangle = ellipseGeometry.rectangle;\n return Geometry._textureCoordinateRotationPoints(\n positions,\n stRotation,\n ellipsoid,\n boundingRectangle\n );\n}\n\nObject.defineProperties(EllipseGeometry.prototype, {\n /**\n * @private\n */\n rectangle: {\n get: function () {\n if (!defined(this._rectangle)) {\n this._rectangle = computeRectangle(\n this._center,\n this._semiMajorAxis,\n this._semiMinorAxis,\n this._rotation,\n this._granularity,\n this._ellipsoid\n );\n }\n return this._rectangle;\n },\n },\n /**\n * For remapping texture coordinates when rendering EllipseGeometries as GroundPrimitives.\n * @private\n */\n textureCoordinateRotationPoints: {\n get: function () {\n if (!defined(this._textureCoordinateRotationPoints)) {\n this._textureCoordinateRotationPoints = textureCoordinateRotationPoints(\n this\n );\n }\n return this._textureCoordinateRotationPoints;\n },\n },\n});\nexport default EllipseGeometry;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport EllipseGeometryLibrary from \"./EllipseGeometryLibrary.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\nconst scratchCartesian1 = new Cartesian3();\nlet boundingSphereCenter = new Cartesian3();\n\nfunction computeEllipse(options) {\n const center = options.center;\n boundingSphereCenter = Cartesian3.multiplyByScalar(\n options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter),\n options.height,\n boundingSphereCenter\n );\n boundingSphereCenter = Cartesian3.add(\n center,\n boundingSphereCenter,\n boundingSphereCenter\n );\n const boundingSphere = new BoundingSphere(\n boundingSphereCenter,\n options.semiMajorAxis\n );\n const positions = EllipseGeometryLibrary.computeEllipsePositions(\n options,\n false,\n true\n ).outerPositions;\n\n const attributes = new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: EllipseGeometryLibrary.raisePositionsToHeight(\n positions,\n options,\n false\n ),\n }),\n });\n\n const length = positions.length / 3;\n const indices = IndexDatatype.createTypedArray(length, length * 2);\n let index = 0;\n for (let i = 0; i < length; ++i) {\n indices[index++] = i;\n indices[index++] = (i + 1) % length;\n }\n\n return {\n boundingSphere: boundingSphere,\n attributes: attributes,\n indices: indices,\n };\n}\n\nconst topBoundingSphere = new BoundingSphere();\nconst bottomBoundingSphere = new BoundingSphere();\nfunction computeExtrudedEllipse(options) {\n const center = options.center;\n const ellipsoid = options.ellipsoid;\n const semiMajorAxis = options.semiMajorAxis;\n let scaledNormal = Cartesian3.multiplyByScalar(\n ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1),\n options.height,\n scratchCartesian1\n );\n topBoundingSphere.center = Cartesian3.add(\n center,\n scaledNormal,\n topBoundingSphere.center\n );\n topBoundingSphere.radius = semiMajorAxis;\n\n scaledNormal = Cartesian3.multiplyByScalar(\n ellipsoid.geodeticSurfaceNormal(center, scaledNormal),\n options.extrudedHeight,\n scaledNormal\n );\n bottomBoundingSphere.center = Cartesian3.add(\n center,\n scaledNormal,\n bottomBoundingSphere.center\n );\n bottomBoundingSphere.radius = semiMajorAxis;\n\n let positions = EllipseGeometryLibrary.computeEllipsePositions(\n options,\n false,\n true\n ).outerPositions;\n const attributes = new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: EllipseGeometryLibrary.raisePositionsToHeight(\n positions,\n options,\n true\n ),\n }),\n });\n\n positions = attributes.position.values;\n const boundingSphere = BoundingSphere.union(\n topBoundingSphere,\n bottomBoundingSphere\n );\n let length = positions.length / 3;\n\n if (defined(options.offsetAttribute)) {\n let applyOffset = new Uint8Array(length);\n if (options.offsetAttribute === GeometryOffsetAttribute.TOP) {\n applyOffset = applyOffset.fill(1, 0, length / 2);\n } else {\n const offsetValue =\n options.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n applyOffset = applyOffset.fill(offsetValue);\n }\n\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n let numberOfVerticalLines = defaultValue(options.numberOfVerticalLines, 16);\n numberOfVerticalLines = CesiumMath.clamp(\n numberOfVerticalLines,\n 0,\n length / 2\n );\n\n const indices = IndexDatatype.createTypedArray(\n length,\n length * 2 + numberOfVerticalLines * 2\n );\n\n length /= 2;\n let index = 0;\n let i;\n for (i = 0; i < length; ++i) {\n indices[index++] = i;\n indices[index++] = (i + 1) % length;\n indices[index++] = i + length;\n indices[index++] = ((i + 1) % length) + length;\n }\n\n let numSide;\n if (numberOfVerticalLines > 0) {\n const numSideLines = Math.min(numberOfVerticalLines, length);\n numSide = Math.round(length / numSideLines);\n\n const maxI = Math.min(numSide * numberOfVerticalLines, length);\n for (i = 0; i < maxI; i += numSide) {\n indices[index++] = i;\n indices[index++] = i + length;\n }\n }\n\n return {\n boundingSphere: boundingSphere,\n attributes: attributes,\n indices: indices,\n };\n}\n\n/**\n * A description of the outline of an ellipse on an ellipsoid.\n *\n * @alias EllipseOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.\n * @param {number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.\n * @param {number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.\n * @param {number} [options.height=0.0] The distance in meters between the ellipse and the ellipsoid surface.\n * @param {number} [options.extrudedHeight] The distance in meters between the ellipse's extruded face and the ellipsoid surface.\n * @param {number} [options.rotation=0.0] The angle from north (counter-clockwise) in radians.\n * @param {number} [options.granularity=0.02] The angular distance between points on the ellipse in radians.\n * @param {number} [options.numberOfVerticalLines=16] Number of lines to draw between the top and bottom surface of an extruded ellipse.\n *\n * @exception {DeveloperError} semiMajorAxis and semiMinorAxis must be greater than zero.\n * @exception {DeveloperError} semiMajorAxis must be greater than or equal to the semiMinorAxis.\n * @exception {DeveloperError} granularity must be greater than zero.\n *\n * @see EllipseOutlineGeometry.createGeometry\n *\n * @example\n * const ellipse = new Cesium.EllipseOutlineGeometry({\n * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),\n * semiMajorAxis : 500000.0,\n * semiMinorAxis : 300000.0,\n * rotation : Cesium.Math.toRadians(60.0)\n * });\n * const geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse);\n */\nfunction EllipseOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const center = options.center;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const semiMajorAxis = options.semiMajorAxis;\n const semiMinorAxis = options.semiMinorAxis;\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(center)) {\n throw new DeveloperError(\"center is required.\");\n }\n if (!defined(semiMajorAxis)) {\n throw new DeveloperError(\"semiMajorAxis is required.\");\n }\n if (!defined(semiMinorAxis)) {\n throw new DeveloperError(\"semiMinorAxis is required.\");\n }\n if (semiMajorAxis < semiMinorAxis) {\n throw new DeveloperError(\n \"semiMajorAxis must be greater than or equal to the semiMinorAxis.\"\n );\n }\n if (granularity <= 0.0) {\n throw new DeveloperError(\"granularity must be greater than zero.\");\n }\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._center = Cartesian3.clone(center);\n this._semiMajorAxis = semiMajorAxis;\n this._semiMinorAxis = semiMinorAxis;\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._rotation = defaultValue(options.rotation, 0.0);\n this._height = Math.max(extrudedHeight, height);\n this._granularity = granularity;\n this._extrudedHeight = Math.min(extrudedHeight, height);\n this._numberOfVerticalLines = Math.max(\n defaultValue(options.numberOfVerticalLines, 16),\n 0\n );\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createEllipseOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nEllipseOutlineGeometry.packedLength =\n Cartesian3.packedLength + Ellipsoid.packedLength + 8;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {EllipseOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nEllipseOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._center, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex++] = value._semiMajorAxis;\n array[startingIndex++] = value._semiMinorAxis;\n array[startingIndex++] = value._rotation;\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._numberOfVerticalLines;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchCenter = new Cartesian3();\nconst scratchEllipsoid = new Ellipsoid();\nconst scratchOptions = {\n center: scratchCenter,\n ellipsoid: scratchEllipsoid,\n semiMajorAxis: undefined,\n semiMinorAxis: undefined,\n rotation: undefined,\n height: undefined,\n granularity: undefined,\n extrudedHeight: undefined,\n numberOfVerticalLines: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {EllipseOutlineGeometry} [result] The object into which to store the result.\n * @returns {EllipseOutlineGeometry} The modified result parameter or a new EllipseOutlineGeometry instance if one was not provided.\n */\nEllipseOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const center = Cartesian3.unpack(array, startingIndex, scratchCenter);\n startingIndex += Cartesian3.packedLength;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const semiMajorAxis = array[startingIndex++];\n const semiMinorAxis = array[startingIndex++];\n const rotation = array[startingIndex++];\n const height = array[startingIndex++];\n const granularity = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const numberOfVerticalLines = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.height = height;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.granularity = granularity;\n scratchOptions.rotation = rotation;\n scratchOptions.semiMajorAxis = semiMajorAxis;\n scratchOptions.semiMinorAxis = semiMinorAxis;\n scratchOptions.numberOfVerticalLines = numberOfVerticalLines;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return new EllipseOutlineGeometry(scratchOptions);\n }\n\n result._center = Cartesian3.clone(center, result._center);\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._semiMajorAxis = semiMajorAxis;\n result._semiMinorAxis = semiMinorAxis;\n result._rotation = rotation;\n result._height = height;\n result._granularity = granularity;\n result._extrudedHeight = extrudedHeight;\n result._numberOfVerticalLines = numberOfVerticalLines;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an outline of an ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere.\n *\n * @param {EllipseOutlineGeometry} ellipseGeometry A description of the ellipse.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nEllipseOutlineGeometry.createGeometry = function (ellipseGeometry) {\n if (\n ellipseGeometry._semiMajorAxis <= 0.0 ||\n ellipseGeometry._semiMinorAxis <= 0.0\n ) {\n return;\n }\n\n const height = ellipseGeometry._height;\n const extrudedHeight = ellipseGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n height,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n\n ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(\n ellipseGeometry._center,\n ellipseGeometry._center\n );\n const options = {\n center: ellipseGeometry._center,\n semiMajorAxis: ellipseGeometry._semiMajorAxis,\n semiMinorAxis: ellipseGeometry._semiMinorAxis,\n ellipsoid: ellipseGeometry._ellipsoid,\n rotation: ellipseGeometry._rotation,\n height: height,\n granularity: ellipseGeometry._granularity,\n numberOfVerticalLines: ellipseGeometry._numberOfVerticalLines,\n };\n let geometry;\n if (extrude) {\n options.extrudedHeight = extrudedHeight;\n options.offsetAttribute = ellipseGeometry._offsetAttribute;\n geometry = computeExtrudedEllipse(options);\n } else {\n geometry = computeEllipse(options);\n\n if (defined(ellipseGeometry._offsetAttribute)) {\n const length = geometry.attributes.position.values.length;\n const offsetValue =\n ellipseGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n }\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: geometry.boundingSphere,\n offsetAttribute: ellipseGeometry._offsetAttribute,\n });\n};\nexport default EllipseOutlineGeometry;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport EllipseGeometry from \"../Core/EllipseGeometry.js\";\nimport EllipseOutlineGeometry from \"../Core/EllipseOutlineGeometry.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport GroundGeometryUpdater from \"./GroundGeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\nconst scratchRectangle = new Rectangle();\n\nfunction EllipseGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.center = undefined;\n this.semiMajorAxis = undefined;\n this.semiMinorAxis = undefined;\n this.rotation = undefined;\n this.height = undefined;\n this.extrudedHeight = undefined;\n this.granularity = undefined;\n this.stRotation = undefined;\n this.numberOfVerticalLines = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for ellipses.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias EllipseGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction EllipseGeometryUpdater(entity, scene) {\n GroundGeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new EllipseGeometryOptions(entity),\n geometryPropertyName: \"ellipse\",\n observedPropertyNames: [\"availability\", \"position\", \"ellipse\"],\n });\n\n this._onEntityPropertyChanged(entity, \"ellipse\", entity.ellipse, undefined);\n}\n\nif (defined(Object.create)) {\n EllipseGeometryUpdater.prototype = Object.create(\n GroundGeometryUpdater.prototype\n );\n EllipseGeometryUpdater.prototype.constructor = EllipseGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nEllipseGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n ),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n this._distanceDisplayConditionProperty.getValue(time)\n ),\n offset: undefined,\n color: undefined,\n };\n\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new EllipseGeometry(this._options),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nEllipseGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new EllipseOutlineGeometry(this._options),\n attributes: attributes,\n });\n};\n\nEllipseGeometryUpdater.prototype._computeCenter = function (time, result) {\n return Property.getValueOrUndefined(this._entity.position, time, result);\n};\n\nEllipseGeometryUpdater.prototype._isHidden = function (entity, ellipse) {\n const position = entity.position;\n\n return (\n !defined(position) ||\n !defined(ellipse.semiMajorAxis) ||\n !defined(ellipse.semiMinorAxis) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, ellipse)\n );\n};\n\nEllipseGeometryUpdater.prototype._isDynamic = function (entity, ellipse) {\n return (\n !entity.position.isConstant || //\n !ellipse.semiMajorAxis.isConstant || //\n !ellipse.semiMinorAxis.isConstant || //\n !Property.isConstant(ellipse.rotation) || //\n !Property.isConstant(ellipse.height) || //\n !Property.isConstant(ellipse.extrudedHeight) || //\n !Property.isConstant(ellipse.granularity) || //\n !Property.isConstant(ellipse.stRotation) || //\n !Property.isConstant(ellipse.outlineWidth) || //\n !Property.isConstant(ellipse.numberOfVerticalLines) || //\n !Property.isConstant(ellipse.zIndex) || //\n (this._onTerrain &&\n !Property.isConstant(this._materialProperty) &&\n !(this._materialProperty instanceof ColorMaterialProperty))\n );\n};\n\nEllipseGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n ellipse\n) {\n let heightValue = Property.getValueOrUndefined(\n ellipse.height,\n Iso8601.MINIMUM_VALUE\n );\n const heightReferenceValue = Property.getValueOrDefault(\n ellipse.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n ellipse.extrudedHeight,\n Iso8601.MINIMUM_VALUE\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n ellipse.extrudedHeightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n const options = this._options;\n options.vertexFormat =\n this._materialProperty instanceof ColorMaterialProperty\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.center = entity.position.getValue(\n Iso8601.MINIMUM_VALUE,\n options.center\n );\n options.semiMajorAxis = ellipse.semiMajorAxis.getValue(\n Iso8601.MINIMUM_VALUE,\n options.semiMajorAxis\n );\n options.semiMinorAxis = ellipse.semiMinorAxis.getValue(\n Iso8601.MINIMUM_VALUE,\n options.semiMinorAxis\n );\n options.rotation = Property.getValueOrUndefined(\n ellipse.rotation,\n Iso8601.MINIMUM_VALUE\n );\n options.granularity = Property.getValueOrUndefined(\n ellipse.granularity,\n Iso8601.MINIMUM_VALUE\n );\n options.stRotation = Property.getValueOrUndefined(\n ellipse.stRotation,\n Iso8601.MINIMUM_VALUE\n );\n options.numberOfVerticalLines = Property.getValueOrUndefined(\n ellipse.numberOfVerticalLines,\n Iso8601.MINIMUM_VALUE\n );\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n EllipseGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\n\nEllipseGeometryUpdater.DynamicGeometryUpdater = DynamicEllipseGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicEllipseGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicEllipseGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicEllipseGeometryUpdater.prototype.constructor = DynamicEllipseGeometryUpdater;\n}\n\nDynamicEllipseGeometryUpdater.prototype._isHidden = function (\n entity,\n ellipse,\n time\n) {\n const options = this._options;\n return (\n !defined(options.center) ||\n !defined(options.semiMajorAxis) ||\n !defined(options.semiMinorAxis) ||\n DynamicGeometryUpdater.prototype._isHidden.call(this, entity, ellipse, time)\n );\n};\n\nDynamicEllipseGeometryUpdater.prototype._setOptions = function (\n entity,\n ellipse,\n time\n) {\n const options = this._options;\n let heightValue = Property.getValueOrUndefined(ellipse.height, time);\n const heightReferenceValue = Property.getValueOrDefault(\n ellipse.heightReference,\n time,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n ellipse.extrudedHeight,\n time\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n ellipse.extrudedHeightReference,\n time,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n options.center = Property.getValueOrUndefined(\n entity.position,\n time,\n options.center\n );\n options.semiMajorAxis = Property.getValueOrUndefined(\n ellipse.semiMajorAxis,\n time\n );\n options.semiMinorAxis = Property.getValueOrUndefined(\n ellipse.semiMinorAxis,\n time\n );\n options.rotation = Property.getValueOrUndefined(ellipse.rotation, time);\n options.granularity = Property.getValueOrUndefined(ellipse.granularity, time);\n options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time);\n options.numberOfVerticalLines = Property.getValueOrUndefined(\n ellipse.numberOfVerticalLines,\n time\n );\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n EllipseGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\nexport default EllipseGeometryUpdater;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst scratchPosition = new Cartesian3();\nconst scratchNormal = new Cartesian3();\nconst scratchTangent = new Cartesian3();\nconst scratchBitangent = new Cartesian3();\nconst scratchNormalST = new Cartesian3();\nconst defaultRadii = new Cartesian3(1.0, 1.0, 1.0);\n\nconst cos = Math.cos;\nconst sin = Math.sin;\n\n/**\n * A description of an ellipsoid centered at the origin.\n *\n * @alias EllipsoidGeometry\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {Cartesian3} [options.radii=Cartesian3(1.0, 1.0, 1.0)] The radii of the ellipsoid in the x, y, and z directions.\n * @param {Cartesian3} [options.innerRadii=options.radii] The inner radii of the ellipsoid in the x, y, and z directions.\n * @param {number} [options.minimumClock=0.0] The minimum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.\n * @param {number} [options.maximumClock=2*PI] The maximum angle lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.\n * @param {number} [options.minimumCone=0.0] The minimum angle measured from the positive z-axis and toward the negative z-axis.\n * @param {number} [options.maximumCone=PI] The maximum angle measured from the positive z-axis and toward the negative z-axis.\n * @param {number} [options.stackPartitions=64] The number of times to partition the ellipsoid into stacks.\n * @param {number} [options.slicePartitions=64] The number of times to partition the ellipsoid into radial slices.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @exception {DeveloperError} options.slicePartitions cannot be less than three.\n * @exception {DeveloperError} options.stackPartitions cannot be less than three.\n *\n * @see EllipsoidGeometry#createGeometry\n *\n * @example\n * const ellipsoid = new Cesium.EllipsoidGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,\n * radii : new Cesium.Cartesian3(1000000.0, 500000.0, 500000.0)\n * });\n * const geometry = Cesium.EllipsoidGeometry.createGeometry(ellipsoid);\n */\nfunction EllipsoidGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const radii = defaultValue(options.radii, defaultRadii);\n const innerRadii = defaultValue(options.innerRadii, radii);\n const minimumClock = defaultValue(options.minimumClock, 0.0);\n const maximumClock = defaultValue(options.maximumClock, CesiumMath.TWO_PI);\n const minimumCone = defaultValue(options.minimumCone, 0.0);\n const maximumCone = defaultValue(options.maximumCone, CesiumMath.PI);\n const stackPartitions = Math.round(defaultValue(options.stackPartitions, 64));\n const slicePartitions = Math.round(defaultValue(options.slicePartitions, 64));\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n\n //>>includeStart('debug', pragmas.debug);\n if (slicePartitions < 3) {\n throw new DeveloperError(\n \"options.slicePartitions cannot be less than three.\"\n );\n }\n if (stackPartitions < 3) {\n throw new DeveloperError(\n \"options.stackPartitions cannot be less than three.\"\n );\n }\n //>>includeEnd('debug');\n\n this._radii = Cartesian3.clone(radii);\n this._innerRadii = Cartesian3.clone(innerRadii);\n this._minimumClock = minimumClock;\n this._maximumClock = maximumClock;\n this._minimumCone = minimumCone;\n this._maximumCone = maximumCone;\n this._stackPartitions = stackPartitions;\n this._slicePartitions = slicePartitions;\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createEllipsoidGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nEllipsoidGeometry.packedLength =\n 2 * Cartesian3.packedLength + VertexFormat.packedLength + 7;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {EllipsoidGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nEllipsoidGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Cartesian3.pack(value._radii, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n Cartesian3.pack(value._innerRadii, array, startingIndex);\n startingIndex += Cartesian3.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._minimumClock;\n array[startingIndex++] = value._maximumClock;\n array[startingIndex++] = value._minimumCone;\n array[startingIndex++] = value._maximumCone;\n array[startingIndex++] = value._stackPartitions;\n array[startingIndex++] = value._slicePartitions;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchRadii = new Cartesian3();\nconst scratchInnerRadii = new Cartesian3();\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n radii: scratchRadii,\n innerRadii: scratchInnerRadii,\n vertexFormat: scratchVertexFormat,\n minimumClock: undefined,\n maximumClock: undefined,\n minimumCone: undefined,\n maximumCone: undefined,\n stackPartitions: undefined,\n slicePartitions: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {EllipsoidGeometry} [result] The object into which to store the result.\n * @returns {EllipsoidGeometry} The modified result parameter or a new EllipsoidGeometry instance if one was not provided.\n */\nEllipsoidGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const radii = Cartesian3.unpack(array, startingIndex, scratchRadii);\n startingIndex += Cartesian3.packedLength;\n\n const innerRadii = Cartesian3.unpack(array, startingIndex, scratchInnerRadii);\n startingIndex += Cartesian3.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const minimumClock = array[startingIndex++];\n const maximumClock = array[startingIndex++];\n const minimumCone = array[startingIndex++];\n const maximumCone = array[startingIndex++];\n const stackPartitions = array[startingIndex++];\n const slicePartitions = array[startingIndex++];\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.minimumClock = minimumClock;\n scratchOptions.maximumClock = maximumClock;\n scratchOptions.minimumCone = minimumCone;\n scratchOptions.maximumCone = maximumCone;\n scratchOptions.stackPartitions = stackPartitions;\n scratchOptions.slicePartitions = slicePartitions;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n return new EllipsoidGeometry(scratchOptions);\n }\n\n result._radii = Cartesian3.clone(radii, result._radii);\n result._innerRadii = Cartesian3.clone(innerRadii, result._innerRadii);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._minimumClock = minimumClock;\n result._maximumClock = maximumClock;\n result._minimumCone = minimumCone;\n result._maximumCone = maximumCone;\n result._stackPartitions = stackPartitions;\n result._slicePartitions = slicePartitions;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an ellipsoid, including its vertices, indices, and a bounding sphere.\n *\n * @param {EllipsoidGeometry} ellipsoidGeometry A description of the ellipsoid.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nEllipsoidGeometry.createGeometry = function (ellipsoidGeometry) {\n const radii = ellipsoidGeometry._radii;\n if (radii.x <= 0 || radii.y <= 0 || radii.z <= 0) {\n return;\n }\n\n const innerRadii = ellipsoidGeometry._innerRadii;\n if (innerRadii.x <= 0 || innerRadii.y <= 0 || innerRadii.z <= 0) {\n return;\n }\n\n const minimumClock = ellipsoidGeometry._minimumClock;\n const maximumClock = ellipsoidGeometry._maximumClock;\n const minimumCone = ellipsoidGeometry._minimumCone;\n const maximumCone = ellipsoidGeometry._maximumCone;\n const vertexFormat = ellipsoidGeometry._vertexFormat;\n\n // Add an extra slice and stack so that the number of partitions is the\n // number of surfaces rather than the number of joints\n let slicePartitions = ellipsoidGeometry._slicePartitions + 1;\n let stackPartitions = ellipsoidGeometry._stackPartitions + 1;\n\n slicePartitions = Math.round(\n (slicePartitions * Math.abs(maximumClock - minimumClock)) /\n CesiumMath.TWO_PI\n );\n stackPartitions = Math.round(\n (stackPartitions * Math.abs(maximumCone - minimumCone)) / CesiumMath.PI\n );\n\n if (slicePartitions < 2) {\n slicePartitions = 2;\n }\n if (stackPartitions < 2) {\n stackPartitions = 2;\n }\n\n let i;\n let j;\n let index = 0;\n\n // Create arrays for theta and phi. Duplicate first and last angle to\n // allow different normals at the intersections.\n const phis = [minimumCone];\n const thetas = [minimumClock];\n for (i = 0; i < stackPartitions; i++) {\n phis.push(\n minimumCone + (i * (maximumCone - minimumCone)) / (stackPartitions - 1)\n );\n }\n phis.push(maximumCone);\n for (j = 0; j < slicePartitions; j++) {\n thetas.push(\n minimumClock + (j * (maximumClock - minimumClock)) / (slicePartitions - 1)\n );\n }\n thetas.push(maximumClock);\n const numPhis = phis.length;\n const numThetas = thetas.length;\n\n // Allow for extra indices if there is an inner surface and if we need\n // to close the sides if the clock range is not a full circle\n let extraIndices = 0;\n let vertexMultiplier = 1.0;\n const hasInnerSurface =\n innerRadii.x !== radii.x ||\n innerRadii.y !== radii.y ||\n innerRadii.z !== radii.z;\n let isTopOpen = false;\n let isBotOpen = false;\n let isClockOpen = false;\n if (hasInnerSurface) {\n vertexMultiplier = 2.0;\n if (minimumCone > 0.0) {\n isTopOpen = true;\n extraIndices += slicePartitions - 1;\n }\n if (maximumCone < Math.PI) {\n isBotOpen = true;\n extraIndices += slicePartitions - 1;\n }\n if ((maximumClock - minimumClock) % CesiumMath.TWO_PI) {\n isClockOpen = true;\n extraIndices += (stackPartitions - 1) * 2 + 1;\n } else {\n extraIndices += 1;\n }\n }\n\n const vertexCount = numThetas * numPhis * vertexMultiplier;\n const positions = new Float64Array(vertexCount * 3);\n const isInner = new Array(vertexCount).fill(false);\n const negateNormal = new Array(vertexCount).fill(false);\n\n // Multiply by 6 because there are two triangles per sector\n const indexCount = slicePartitions * stackPartitions * vertexMultiplier;\n const numIndices =\n 6 *\n (indexCount +\n extraIndices +\n 1 -\n (slicePartitions + stackPartitions) * vertexMultiplier);\n const indices = IndexDatatype.createTypedArray(indexCount, numIndices);\n\n const normals = vertexFormat.normal\n ? new Float32Array(vertexCount * 3)\n : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(vertexCount * 3)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(vertexCount * 3)\n : undefined;\n const st = vertexFormat.st ? new Float32Array(vertexCount * 2) : undefined;\n\n // Calculate sin/cos phi\n const sinPhi = new Array(numPhis);\n const cosPhi = new Array(numPhis);\n for (i = 0; i < numPhis; i++) {\n sinPhi[i] = sin(phis[i]);\n cosPhi[i] = cos(phis[i]);\n }\n\n // Calculate sin/cos theta\n const sinTheta = new Array(numThetas);\n const cosTheta = new Array(numThetas);\n for (j = 0; j < numThetas; j++) {\n cosTheta[j] = cos(thetas[j]);\n sinTheta[j] = sin(thetas[j]);\n }\n\n // Create outer surface\n for (i = 0; i < numPhis; i++) {\n for (j = 0; j < numThetas; j++) {\n positions[index++] = radii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = radii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = radii.z * cosPhi[i];\n }\n }\n\n // Create inner surface\n let vertexIndex = vertexCount / 2.0;\n if (hasInnerSurface) {\n for (i = 0; i < numPhis; i++) {\n for (j = 0; j < numThetas; j++) {\n positions[index++] = innerRadii.x * sinPhi[i] * cosTheta[j];\n positions[index++] = innerRadii.y * sinPhi[i] * sinTheta[j];\n positions[index++] = innerRadii.z * cosPhi[i];\n\n // Keep track of which vertices are the inner and which ones\n // need the normal to be negated\n isInner[vertexIndex] = true;\n if (i > 0 && i !== numPhis - 1 && j !== 0 && j !== numThetas - 1) {\n negateNormal[vertexIndex] = true;\n }\n vertexIndex++;\n }\n }\n }\n\n // Create indices for outer surface\n index = 0;\n let topOffset;\n let bottomOffset;\n for (i = 1; i < numPhis - 2; i++) {\n topOffset = i * numThetas;\n bottomOffset = (i + 1) * numThetas;\n\n for (j = 1; j < numThetas - 2; j++) {\n indices[index++] = bottomOffset + j;\n indices[index++] = bottomOffset + j + 1;\n indices[index++] = topOffset + j + 1;\n\n indices[index++] = bottomOffset + j;\n indices[index++] = topOffset + j + 1;\n indices[index++] = topOffset + j;\n }\n }\n\n // Create indices for inner surface\n if (hasInnerSurface) {\n const offset = numPhis * numThetas;\n for (i = 1; i < numPhis - 2; i++) {\n topOffset = offset + i * numThetas;\n bottomOffset = offset + (i + 1) * numThetas;\n\n for (j = 1; j < numThetas - 2; j++) {\n indices[index++] = bottomOffset + j;\n indices[index++] = topOffset + j;\n indices[index++] = topOffset + j + 1;\n\n indices[index++] = bottomOffset + j;\n indices[index++] = topOffset + j + 1;\n indices[index++] = bottomOffset + j + 1;\n }\n }\n }\n\n let outerOffset;\n let innerOffset;\n if (hasInnerSurface) {\n if (isTopOpen) {\n // Connect the top of the inner surface to the top of the outer surface\n innerOffset = numPhis * numThetas;\n for (i = 1; i < numThetas - 2; i++) {\n indices[index++] = i;\n indices[index++] = i + 1;\n indices[index++] = innerOffset + i + 1;\n\n indices[index++] = i;\n indices[index++] = innerOffset + i + 1;\n indices[index++] = innerOffset + i;\n }\n }\n\n if (isBotOpen) {\n // Connect the bottom of the inner surface to the bottom of the outer surface\n outerOffset = numPhis * numThetas - numThetas;\n innerOffset = numPhis * numThetas * vertexMultiplier - numThetas;\n for (i = 1; i < numThetas - 2; i++) {\n indices[index++] = outerOffset + i + 1;\n indices[index++] = outerOffset + i;\n indices[index++] = innerOffset + i;\n\n indices[index++] = outerOffset + i + 1;\n indices[index++] = innerOffset + i;\n indices[index++] = innerOffset + i + 1;\n }\n }\n }\n\n // Connect the edges if clock is not closed\n if (isClockOpen) {\n for (i = 1; i < numPhis - 2; i++) {\n innerOffset = numThetas * numPhis + numThetas * i;\n outerOffset = numThetas * i;\n indices[index++] = innerOffset;\n indices[index++] = outerOffset + numThetas;\n indices[index++] = outerOffset;\n\n indices[index++] = innerOffset;\n indices[index++] = innerOffset + numThetas;\n indices[index++] = outerOffset + numThetas;\n }\n\n for (i = 1; i < numPhis - 2; i++) {\n innerOffset = numThetas * numPhis + numThetas * (i + 1) - 1;\n outerOffset = numThetas * (i + 1) - 1;\n indices[index++] = outerOffset + numThetas;\n indices[index++] = innerOffset;\n indices[index++] = outerOffset;\n\n indices[index++] = outerOffset + numThetas;\n indices[index++] = innerOffset + numThetas;\n indices[index++] = innerOffset;\n }\n }\n\n const attributes = new GeometryAttributes();\n\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n }\n\n let stIndex = 0;\n let normalIndex = 0;\n let tangentIndex = 0;\n let bitangentIndex = 0;\n const vertexCountHalf = vertexCount / 2.0;\n\n let ellipsoid;\n const ellipsoidOuter = Ellipsoid.fromCartesian3(radii);\n const ellipsoidInner = Ellipsoid.fromCartesian3(innerRadii);\n\n if (\n vertexFormat.st ||\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent\n ) {\n for (i = 0; i < vertexCount; i++) {\n ellipsoid = isInner[i] ? ellipsoidInner : ellipsoidOuter;\n const position = Cartesian3.fromArray(positions, i * 3, scratchPosition);\n const normal = ellipsoid.geodeticSurfaceNormal(position, scratchNormal);\n if (negateNormal[i]) {\n Cartesian3.negate(normal, normal);\n }\n\n if (vertexFormat.st) {\n const normalST = Cartesian2.negate(normal, scratchNormalST);\n st[stIndex++] =\n Math.atan2(normalST.y, normalST.x) / CesiumMath.TWO_PI + 0.5;\n st[stIndex++] = Math.asin(normal.z) / Math.PI + 0.5;\n }\n\n if (vertexFormat.normal) {\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n }\n\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n const tangent = scratchTangent;\n\n // Use UNIT_X for the poles\n let tangetOffset = 0;\n let unit;\n if (isInner[i]) {\n tangetOffset = vertexCountHalf;\n }\n if (\n !isTopOpen &&\n i >= tangetOffset &&\n i < tangetOffset + numThetas * 2\n ) {\n unit = Cartesian3.UNIT_X;\n } else {\n unit = Cartesian3.UNIT_Z;\n }\n Cartesian3.cross(unit, normal, tangent);\n Cartesian3.normalize(tangent, tangent);\n\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n const bitangent = Cartesian3.cross(normal, tangent, scratchBitangent);\n Cartesian3.normalize(bitangent, bitangent);\n\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n }\n }\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: st,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n }\n\n if (defined(ellipsoidGeometry._offsetAttribute)) {\n const length = positions.length;\n const offsetValue =\n ellipsoidGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: BoundingSphere.fromEllipsoid(ellipsoidOuter),\n offsetAttribute: ellipsoidGeometry._offsetAttribute,\n });\n};\n\nlet unitEllipsoidGeometry;\n\n/**\n * Returns the geometric representation of a unit ellipsoid, including its vertices, indices, and a bounding sphere.\n * @returns {Geometry} The computed vertices and indices.\n *\n * @private\n */\nEllipsoidGeometry.getUnitEllipsoid = function () {\n if (!defined(unitEllipsoidGeometry)) {\n unitEllipsoidGeometry = EllipsoidGeometry.createGeometry(\n new EllipsoidGeometry({\n radii: new Cartesian3(1.0, 1.0, 1.0),\n vertexFormat: VertexFormat.POSITION_ONLY,\n })\n );\n }\n return unitEllipsoidGeometry;\n};\nexport default EllipsoidGeometry;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport EllipsoidGeometry from \"../Core/EllipsoidGeometry.js\";\nimport EllipsoidOutlineGeometry from \"../Core/EllipsoidOutlineGeometry.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"../Core/GeometryOffsetAttribute.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport Primitive from \"../Scene/Primitive.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport heightReferenceOnEntityPropertyChanged from \"./heightReferenceOnEntityPropertyChanged.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst defaultMaterial = new ColorMaterialProperty(Color.WHITE);\nconst defaultOffset = Cartesian3.ZERO;\n\nconst offsetScratch = new Cartesian3();\nconst radiiScratch = new Cartesian3();\nconst innerRadiiScratch = new Cartesian3();\nconst scratchColor = new Color();\nconst unitSphere = new Cartesian3(1, 1, 1);\n\nfunction EllipsoidGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.radii = undefined;\n this.innerRadii = undefined;\n this.minimumClock = undefined;\n this.maximumClock = undefined;\n this.minimumCone = undefined;\n this.maximumCone = undefined;\n this.stackPartitions = undefined;\n this.slicePartitions = undefined;\n this.subdivisions = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for ellipsoids.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias EllipsoidGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction EllipsoidGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new EllipsoidGeometryOptions(entity),\n geometryPropertyName: \"ellipsoid\",\n observedPropertyNames: [\n \"availability\",\n \"position\",\n \"orientation\",\n \"ellipsoid\",\n ],\n });\n\n this._onEntityPropertyChanged(\n entity,\n \"ellipsoid\",\n entity.ellipsoid,\n undefined\n );\n}\n\nif (defined(Object.create)) {\n EllipsoidGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n EllipsoidGeometryUpdater.prototype.constructor = EllipsoidGeometryUpdater;\n}\n\nObject.defineProperties(EllipsoidGeometryUpdater.prototype, {\n /**\n * Gets the terrain offset property\n * @type {TerrainOffsetProperty}\n * @memberof EllipsoidGeometryUpdater.prototype\n * @readonly\n * @private\n */\n terrainOffsetProperty: {\n get: function () {\n return this._terrainOffsetProperty;\n },\n },\n});\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @param {boolean} [skipModelMatrix=false] Whether to compute a model matrix for the geometry instance\n * @param {Matrix4} [modelMatrixResult] Used to store the result of the model matrix calculation\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nEllipsoidGeometryUpdater.prototype.createFillGeometryInstance = function (\n time,\n skipModelMatrix,\n modelMatrixResult\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n let color;\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n\n const attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: undefined,\n offset: undefined,\n };\n\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n attributes.color = color;\n }\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new EllipsoidGeometry(this._options),\n modelMatrix: skipModelMatrix\n ? undefined\n : entity.computeModelMatrixForHeightReference(\n time,\n entity.ellipsoid.heightReference,\n this._options.radii.z * 0.5,\n this._scene.mapProjection.ellipsoid,\n modelMatrixResult\n ),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @param {boolean} [skipModelMatrix=false] Whether to compute a model matrix for the geometry instance\n * @param {Matrix4} [modelMatrixResult] Used to store the result of the model matrix calculation\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nEllipsoidGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time,\n skipModelMatrix,\n modelMatrixResult\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new EllipsoidOutlineGeometry(this._options),\n modelMatrix: skipModelMatrix\n ? undefined\n : entity.computeModelMatrixForHeightReference(\n time,\n entity.ellipsoid.heightReference,\n this._options.radii.z * 0.5,\n this._scene.mapProjection.ellipsoid,\n modelMatrixResult\n ),\n attributes: attributes,\n });\n};\n\nEllipsoidGeometryUpdater.prototype._computeCenter = function (time, result) {\n return Property.getValueOrUndefined(this._entity.position, time, result);\n};\n\nEllipsoidGeometryUpdater.prototype._isHidden = function (entity, ellipsoid) {\n return (\n !defined(entity.position) ||\n !defined(ellipsoid.radii) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, ellipsoid)\n );\n};\n\nEllipsoidGeometryUpdater.prototype._isDynamic = function (entity, ellipsoid) {\n return (\n !entity.position.isConstant || //\n !Property.isConstant(entity.orientation) || //\n !ellipsoid.radii.isConstant || //\n !Property.isConstant(ellipsoid.innerRadii) || //\n !Property.isConstant(ellipsoid.stackPartitions) || //\n !Property.isConstant(ellipsoid.slicePartitions) || //\n !Property.isConstant(ellipsoid.outlineWidth) || //\n !Property.isConstant(ellipsoid.minimumClock) || //\n !Property.isConstant(ellipsoid.maximumClock) || //\n !Property.isConstant(ellipsoid.minimumCone) || //\n !Property.isConstant(ellipsoid.maximumCone) || //\n !Property.isConstant(ellipsoid.subdivisions)\n );\n};\n\nEllipsoidGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n ellipsoid\n) {\n const heightReference = Property.getValueOrDefault(\n ellipsoid.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n const options = this._options;\n options.vertexFormat =\n this._materialProperty instanceof ColorMaterialProperty\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.radii = ellipsoid.radii.getValue(\n Iso8601.MINIMUM_VALUE,\n options.radii\n );\n options.innerRadii = Property.getValueOrUndefined(\n ellipsoid.innerRadii,\n options.radii\n );\n options.minimumClock = Property.getValueOrUndefined(\n ellipsoid.minimumClock,\n Iso8601.MINIMUM_VALUE\n );\n options.maximumClock = Property.getValueOrUndefined(\n ellipsoid.maximumClock,\n Iso8601.MINIMUM_VALUE\n );\n options.minimumCone = Property.getValueOrUndefined(\n ellipsoid.minimumCone,\n Iso8601.MINIMUM_VALUE\n );\n options.maximumCone = Property.getValueOrUndefined(\n ellipsoid.maximumCone,\n Iso8601.MINIMUM_VALUE\n );\n options.stackPartitions = Property.getValueOrUndefined(\n ellipsoid.stackPartitions,\n Iso8601.MINIMUM_VALUE\n );\n options.slicePartitions = Property.getValueOrUndefined(\n ellipsoid.slicePartitions,\n Iso8601.MINIMUM_VALUE\n );\n options.subdivisions = Property.getValueOrUndefined(\n ellipsoid.subdivisions,\n Iso8601.MINIMUM_VALUE\n );\n options.offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n};\n\nEllipsoidGeometryUpdater.prototype._onEntityPropertyChanged = heightReferenceOnEntityPropertyChanged;\n\nEllipsoidGeometryUpdater.DynamicGeometryUpdater = DynamicEllipsoidGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicEllipsoidGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n\n this._scene = geometryUpdater._scene;\n this._modelMatrix = new Matrix4();\n this._attributes = undefined;\n this._outlineAttributes = undefined;\n this._lastSceneMode = undefined;\n this._lastShow = undefined;\n this._lastOutlineShow = undefined;\n this._lastOutlineWidth = undefined;\n this._lastOutlineColor = undefined;\n this._lastOffset = new Cartesian3();\n this._material = {};\n}\n\nif (defined(Object.create)) {\n DynamicEllipsoidGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicEllipsoidGeometryUpdater.prototype.constructor = DynamicEllipsoidGeometryUpdater;\n}\n\nDynamicEllipsoidGeometryUpdater.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const ellipsoid = entity.ellipsoid;\n if (\n !entity.isShowing ||\n !entity.isAvailable(time) ||\n !Property.getValueOrDefault(ellipsoid.show, time, true)\n ) {\n if (defined(this._primitive)) {\n this._primitive.show = false;\n }\n\n if (defined(this._outlinePrimitive)) {\n this._outlinePrimitive.show = false;\n }\n return;\n }\n\n const radii = Property.getValueOrUndefined(\n ellipsoid.radii,\n time,\n radiiScratch\n );\n let modelMatrix = defined(radii)\n ? entity.computeModelMatrixForHeightReference(\n time,\n ellipsoid.heightReference,\n radii.z * 0.5,\n this._scene.mapProjection.ellipsoid,\n this._modelMatrix\n )\n : undefined;\n if (!defined(modelMatrix) || !defined(radii)) {\n if (defined(this._primitive)) {\n this._primitive.show = false;\n }\n\n if (defined(this._outlinePrimitive)) {\n this._outlinePrimitive.show = false;\n }\n return;\n }\n\n //Compute attributes and material.\n const showFill = Property.getValueOrDefault(ellipsoid.fill, time, true);\n const showOutline = Property.getValueOrDefault(\n ellipsoid.outline,\n time,\n false\n );\n const outlineColor = Property.getValueOrClonedDefault(\n ellipsoid.outlineColor,\n time,\n Color.BLACK,\n scratchColor\n );\n const material = MaterialProperty.getValue(\n time,\n defaultValue(ellipsoid.material, defaultMaterial),\n this._material\n );\n\n // Check properties that could trigger a primitive rebuild.\n const innerRadii = Property.getValueOrUndefined(\n ellipsoid.innerRadii,\n time,\n innerRadiiScratch\n );\n const minimumClock = Property.getValueOrUndefined(\n ellipsoid.minimumClock,\n time\n );\n const maximumClock = Property.getValueOrUndefined(\n ellipsoid.maximumClock,\n time\n );\n const minimumCone = Property.getValueOrUndefined(ellipsoid.minimumCone, time);\n const maximumCone = Property.getValueOrUndefined(ellipsoid.maximumCone, time);\n const stackPartitions = Property.getValueOrUndefined(\n ellipsoid.stackPartitions,\n time\n );\n const slicePartitions = Property.getValueOrUndefined(\n ellipsoid.slicePartitions,\n time\n );\n const subdivisions = Property.getValueOrUndefined(\n ellipsoid.subdivisions,\n time\n );\n const outlineWidth = Property.getValueOrDefault(\n ellipsoid.outlineWidth,\n time,\n 1.0\n );\n const heightReference = Property.getValueOrDefault(\n ellipsoid.heightReference,\n time,\n HeightReference.NONE\n );\n const offsetAttribute =\n heightReference !== HeightReference.NONE\n ? GeometryOffsetAttribute.ALL\n : undefined;\n\n //In 3D we use a fast path by modifying Primitive.modelMatrix instead of regenerating the primitive every frame.\n //Also check for height reference because this method doesn't work when the height is relative to terrain.\n const sceneMode = this._scene.mode;\n const in3D =\n sceneMode === SceneMode.SCENE3D && heightReference === HeightReference.NONE;\n\n const options = this._options;\n\n const shadows = this._geometryUpdater.shadowsProperty.getValue(time);\n\n const distanceDisplayConditionProperty = this._geometryUpdater\n .distanceDisplayConditionProperty;\n const distanceDisplayCondition = distanceDisplayConditionProperty.getValue(\n time\n );\n\n const offset = Property.getValueOrDefault(\n this._geometryUpdater.terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n );\n\n //We only rebuild the primitive if something other than the radii has changed\n //For the radii, we use unit sphere and then deform it with a scale matrix.\n const rebuildPrimitives =\n !in3D ||\n this._lastSceneMode !== sceneMode ||\n !defined(this._primitive) || //\n options.stackPartitions !== stackPartitions ||\n options.slicePartitions !== slicePartitions || //\n (defined(innerRadii) &&\n !Cartesian3.equals(options.innerRadii !== innerRadii)) ||\n options.minimumClock !== minimumClock || //\n options.maximumClock !== maximumClock ||\n options.minimumCone !== minimumCone || //\n options.maximumCone !== maximumCone ||\n options.subdivisions !== subdivisions || //\n this._lastOutlineWidth !== outlineWidth ||\n options.offsetAttribute !== offsetAttribute;\n\n if (rebuildPrimitives) {\n const primitives = this._primitives;\n primitives.removeAndDestroy(this._primitive);\n primitives.removeAndDestroy(this._outlinePrimitive);\n this._primitive = undefined;\n this._outlinePrimitive = undefined;\n this._lastSceneMode = sceneMode;\n this._lastOutlineWidth = outlineWidth;\n\n options.stackPartitions = stackPartitions;\n options.slicePartitions = slicePartitions;\n options.subdivisions = subdivisions;\n options.offsetAttribute = offsetAttribute;\n options.radii = Cartesian3.clone(in3D ? unitSphere : radii, options.radii);\n if (defined(innerRadii)) {\n if (in3D) {\n const mag = Cartesian3.magnitude(radii);\n options.innerRadii = Cartesian3.fromElements(\n innerRadii.x / mag,\n innerRadii.y / mag,\n innerRadii.z / mag,\n options.innerRadii\n );\n } else {\n options.innerRadii = Cartesian3.clone(innerRadii, options.innerRadii);\n }\n } else {\n options.innerRadii = undefined;\n }\n options.minimumClock = minimumClock;\n options.maximumClock = maximumClock;\n options.minimumCone = minimumCone;\n options.maximumCone = maximumCone;\n\n const appearance = new MaterialAppearance({\n material: material,\n translucent: material.isTranslucent(),\n closed: true,\n });\n options.vertexFormat = appearance.vertexFormat;\n\n const fillInstance = this._geometryUpdater.createFillGeometryInstance(\n time,\n in3D,\n this._modelMatrix\n );\n\n this._primitive = primitives.add(\n new Primitive({\n geometryInstances: fillInstance,\n appearance: appearance,\n asynchronous: false,\n shadows: shadows,\n })\n );\n\n const outlineInstance = this._geometryUpdater.createOutlineGeometryInstance(\n time,\n in3D,\n this._modelMatrix\n );\n this._outlinePrimitive = primitives.add(\n new Primitive({\n geometryInstances: outlineInstance,\n appearance: new PerInstanceColorAppearance({\n flat: true,\n translucent: outlineInstance.attributes.color.value[3] !== 255,\n renderState: {\n lineWidth: this._geometryUpdater._scene.clampLineWidth(\n outlineWidth\n ),\n },\n }),\n asynchronous: false,\n shadows: shadows,\n })\n );\n\n this._lastShow = showFill;\n this._lastOutlineShow = showOutline;\n this._lastOutlineColor = Color.clone(outlineColor, this._lastOutlineColor);\n this._lastDistanceDisplayCondition = distanceDisplayCondition;\n this._lastOffset = Cartesian3.clone(offset, this._lastOffset);\n } else if (this._primitive.ready) {\n //Update attributes only.\n const primitive = this._primitive;\n const outlinePrimitive = this._outlinePrimitive;\n\n primitive.show = true;\n outlinePrimitive.show = true;\n primitive.appearance.material = material;\n\n let attributes = this._attributes;\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(entity);\n this._attributes = attributes;\n }\n if (showFill !== this._lastShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n showFill,\n attributes.show\n );\n this._lastShow = showFill;\n }\n\n let outlineAttributes = this._outlineAttributes;\n\n if (!defined(outlineAttributes)) {\n outlineAttributes = outlinePrimitive.getGeometryInstanceAttributes(\n entity\n );\n this._outlineAttributes = outlineAttributes;\n }\n\n if (showOutline !== this._lastOutlineShow) {\n outlineAttributes.show = ShowGeometryInstanceAttribute.toValue(\n showOutline,\n outlineAttributes.show\n );\n this._lastOutlineShow = showOutline;\n }\n\n if (!Color.equals(outlineColor, this._lastOutlineColor)) {\n outlineAttributes.color = ColorGeometryInstanceAttribute.toValue(\n outlineColor,\n outlineAttributes.color\n );\n Color.clone(outlineColor, this._lastOutlineColor);\n }\n\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n this._lastDistanceDisplayCondition\n )\n ) {\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n outlineAttributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n outlineAttributes.distanceDisplayCondition\n );\n DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n this._lastDistanceDisplayCondition\n );\n }\n\n if (!Cartesian3.equals(offset, this._lastOffset)) {\n attributes.offset = OffsetGeometryInstanceAttribute.toValue(\n offset,\n attributes.offset\n );\n outlineAttributes.offset = OffsetGeometryInstanceAttribute.toValue(\n offset,\n attributes.offset\n );\n Cartesian3.clone(offset, this._lastOffset);\n }\n }\n\n if (in3D) {\n //Since we are scaling a unit sphere, we can't let any of the values go to zero.\n //Instead we clamp them to a small value. To the naked eye, this produces the same results\n //that you get passing EllipsoidGeometry a radii with a zero component.\n radii.x = Math.max(radii.x, 0.001);\n radii.y = Math.max(radii.y, 0.001);\n radii.z = Math.max(radii.z, 0.001);\n\n modelMatrix = Matrix4.multiplyByScale(modelMatrix, radii, modelMatrix);\n this._primitive.modelMatrix = modelMatrix;\n this._outlinePrimitive.modelMatrix = modelMatrix;\n }\n};\nexport default EllipsoidGeometryUpdater;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\n/**\n * Describes geometry representing a plane centered at the origin, with a unit width and length.\n *\n * @alias PlaneGeometry\n * @constructor\n *\n * @param {object} [options] Object with the following properties:\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @example\n * const planeGeometry = new Cesium.PlaneGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY\n * });\n */\nfunction PlaneGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n\n this._vertexFormat = vertexFormat;\n this._workerName = \"createPlaneGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nPlaneGeometry.packedLength = VertexFormat.packedLength;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PlaneGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPlaneGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n\n return array;\n};\n\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n vertexFormat: scratchVertexFormat,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PlaneGeometry} [result] The object into which to store the result.\n * @returns {PlaneGeometry} The modified result parameter or a new PlaneGeometry instance if one was not provided.\n */\nPlaneGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n\n if (!defined(result)) {\n return new PlaneGeometry(scratchOptions);\n }\n\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n\n return result;\n};\n\nconst min = new Cartesian3(-0.5, -0.5, 0.0);\nconst max = new Cartesian3(0.5, 0.5, 0.0);\n\n/**\n * Computes the geometric representation of a plane, including its vertices, indices, and a bounding sphere.\n *\n * @param {PlaneGeometry} planeGeometry A description of the plane.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPlaneGeometry.createGeometry = function (planeGeometry) {\n const vertexFormat = planeGeometry._vertexFormat;\n\n const attributes = new GeometryAttributes();\n let indices;\n let positions;\n\n if (vertexFormat.position) {\n // 4 corner points. Duplicated 3 times each for each incident edge/face.\n positions = new Float64Array(4 * 3);\n\n // +z face\n positions[0] = min.x;\n positions[1] = min.y;\n positions[2] = 0.0;\n positions[3] = max.x;\n positions[4] = min.y;\n positions[5] = 0.0;\n positions[6] = max.x;\n positions[7] = max.y;\n positions[8] = 0.0;\n positions[9] = min.x;\n positions[10] = max.y;\n positions[11] = 0.0;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n if (vertexFormat.normal) {\n const normals = new Float32Array(4 * 3);\n\n // +z face\n normals[0] = 0.0;\n normals[1] = 0.0;\n normals[2] = 1.0;\n normals[3] = 0.0;\n normals[4] = 0.0;\n normals[5] = 1.0;\n normals[6] = 0.0;\n normals[7] = 0.0;\n normals[8] = 1.0;\n normals[9] = 0.0;\n normals[10] = 0.0;\n normals[11] = 1.0;\n\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.st) {\n const texCoords = new Float32Array(4 * 2);\n\n // +z face\n texCoords[0] = 0.0;\n texCoords[1] = 0.0;\n texCoords[2] = 1.0;\n texCoords[3] = 0.0;\n texCoords[4] = 1.0;\n texCoords[5] = 1.0;\n texCoords[6] = 0.0;\n texCoords[7] = 1.0;\n\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: texCoords,\n });\n }\n\n if (vertexFormat.tangent) {\n const tangents = new Float32Array(4 * 3);\n\n // +z face\n tangents[0] = 1.0;\n tangents[1] = 0.0;\n tangents[2] = 0.0;\n tangents[3] = 1.0;\n tangents[4] = 0.0;\n tangents[5] = 0.0;\n tangents[6] = 1.0;\n tangents[7] = 0.0;\n tangents[8] = 0.0;\n tangents[9] = 1.0;\n tangents[10] = 0.0;\n tangents[11] = 0.0;\n\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n const bitangents = new Float32Array(4 * 3);\n\n // +z face\n bitangents[0] = 0.0;\n bitangents[1] = 1.0;\n bitangents[2] = 0.0;\n bitangents[3] = 0.0;\n bitangents[4] = 1.0;\n bitangents[5] = 0.0;\n bitangents[6] = 0.0;\n bitangents[7] = 1.0;\n bitangents[8] = 0.0;\n bitangents[9] = 0.0;\n bitangents[10] = 1.0;\n bitangents[11] = 0.0;\n\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n // 2 triangles\n indices = new Uint16Array(2 * 3);\n\n // +z face\n indices[0] = 0;\n indices[1] = 1;\n indices[2] = 2;\n indices[3] = 0;\n indices[4] = 2;\n indices[5] = 3;\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: new BoundingSphere(Cartesian3.ZERO, Math.sqrt(2.0)),\n });\n};\nexport default PlaneGeometry;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defined from \"./defined.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\n\n/**\n * Describes geometry representing the outline of a plane centered at the origin, with a unit width and length.\n *\n * @alias PlaneOutlineGeometry\n * @constructor\n *\n */\nfunction PlaneOutlineGeometry() {\n this._workerName = \"createPlaneOutlineGeometry\";\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nPlaneOutlineGeometry.packedLength = 0;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PlaneOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n *\n * @returns {number[]} The array that was packed into\n */\nPlaneOutlineGeometry.pack = function (value, array) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n return array;\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PlaneOutlineGeometry} [result] The object into which to store the result.\n * @returns {PlaneOutlineGeometry} The modified result parameter or a new PlaneOutlineGeometry instance if one was not provided.\n */\nPlaneOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n if (!defined(result)) {\n return new PlaneOutlineGeometry();\n }\n\n return result;\n};\n\nconst min = new Cartesian3(-0.5, -0.5, 0.0);\nconst max = new Cartesian3(0.5, 0.5, 0.0);\n\n/**\n * Computes the geometric representation of an outline of a plane, including its vertices, indices, and a bounding sphere.\n *\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPlaneOutlineGeometry.createGeometry = function () {\n const attributes = new GeometryAttributes();\n const indices = new Uint16Array(4 * 2);\n const positions = new Float64Array(4 * 3);\n\n positions[0] = min.x;\n positions[1] = min.y;\n positions[2] = min.z;\n positions[3] = max.x;\n positions[4] = min.y;\n positions[5] = min.z;\n positions[6] = max.x;\n positions[7] = max.y;\n positions[8] = min.z;\n positions[9] = min.x;\n positions[10] = max.y;\n positions[11] = min.z;\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n indices[0] = 0;\n indices[1] = 1;\n indices[2] = 1;\n indices[3] = 2;\n indices[4] = 2;\n indices[5] = 3;\n indices[6] = 3;\n indices[7] = 0;\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: new BoundingSphere(Cartesian3.ZERO, Math.sqrt(2.0)),\n });\n};\nexport default PlaneOutlineGeometry;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport PlaneGeometry from \"../Core/PlaneGeometry.js\";\nimport PlaneOutlineGeometry from \"../Core/PlaneOutlineGeometry.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst positionScratch = new Cartesian3();\nconst scratchColor = new Color();\n\nfunction PlaneGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.plane = undefined;\n this.dimensions = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for planes.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias PlaneGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction PlaneGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new PlaneGeometryOptions(entity),\n geometryPropertyName: \"plane\",\n observedPropertyNames: [\"availability\", \"position\", \"orientation\", \"plane\"],\n });\n\n this._onEntityPropertyChanged(entity, \"plane\", entity.plane, undefined);\n}\n\nif (defined(Object.create)) {\n PlaneGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n PlaneGeometryUpdater.prototype.constructor = PlaneGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nPlaneGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n let attributes;\n\n let color;\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: color,\n };\n } else {\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n };\n }\n\n const planeGraphics = entity.plane;\n const options = this._options;\n let modelMatrix = entity.computeModelMatrix(time);\n const plane = Property.getValueOrDefault(\n planeGraphics.plane,\n time,\n options.plane\n );\n const dimensions = Property.getValueOrUndefined(\n planeGraphics.dimensions,\n time,\n options.dimensions\n );\n\n options.plane = plane;\n options.dimensions = dimensions;\n\n modelMatrix = createPrimitiveMatrix(\n plane,\n dimensions,\n modelMatrix,\n modelMatrix\n );\n\n return new GeometryInstance({\n id: entity,\n geometry: new PlaneGeometry(this._options),\n modelMatrix: modelMatrix,\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nPlaneGeometryUpdater.prototype.createOutlineGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const planeGraphics = entity.plane;\n const options = this._options;\n let modelMatrix = entity.computeModelMatrix(time);\n const plane = Property.getValueOrDefault(\n planeGraphics.plane,\n time,\n options.plane\n );\n const dimensions = Property.getValueOrUndefined(\n planeGraphics.dimensions,\n time,\n options.dimensions\n );\n\n options.plane = plane;\n options.dimensions = dimensions;\n\n modelMatrix = createPrimitiveMatrix(\n plane,\n dimensions,\n modelMatrix,\n modelMatrix\n );\n\n return new GeometryInstance({\n id: entity,\n geometry: new PlaneOutlineGeometry(),\n modelMatrix: modelMatrix,\n attributes: {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n },\n });\n};\n\nPlaneGeometryUpdater.prototype._isHidden = function (entity, plane) {\n return (\n !defined(plane.plane) ||\n !defined(plane.dimensions) ||\n !defined(entity.position) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, plane)\n );\n};\n\nPlaneGeometryUpdater.prototype._getIsClosed = function (options) {\n return false;\n};\n\nPlaneGeometryUpdater.prototype._isDynamic = function (entity, plane) {\n return (\n !entity.position.isConstant || //\n !Property.isConstant(entity.orientation) || //\n !plane.plane.isConstant || //\n !plane.dimensions.isConstant || //\n !Property.isConstant(plane.outlineWidth)\n );\n};\n\nPlaneGeometryUpdater.prototype._setStaticOptions = function (entity, plane) {\n const isColorMaterial =\n this._materialProperty instanceof ColorMaterialProperty;\n\n const options = this._options;\n options.vertexFormat = isColorMaterial\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.plane = plane.plane.getValue(Iso8601.MINIMUM_VALUE, options.plane);\n options.dimensions = plane.dimensions.getValue(\n Iso8601.MINIMUM_VALUE,\n options.dimensions\n );\n};\n\nPlaneGeometryUpdater.DynamicGeometryUpdater = DynamicPlaneGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicPlaneGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicPlaneGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicPlaneGeometryUpdater.prototype.constructor = DynamicPlaneGeometryUpdater;\n}\n\nDynamicPlaneGeometryUpdater.prototype._isHidden = function (\n entity,\n plane,\n time\n) {\n const options = this._options;\n const position = Property.getValueOrUndefined(\n entity.position,\n time,\n positionScratch\n );\n return (\n !defined(position) ||\n !defined(options.plane) ||\n !defined(options.dimensions) ||\n DynamicGeometryUpdater.prototype._isHidden.call(this, entity, plane, time)\n );\n};\n\nDynamicPlaneGeometryUpdater.prototype._setOptions = function (\n entity,\n plane,\n time\n) {\n const options = this._options;\n options.plane = Property.getValueOrDefault(plane.plane, time, options.plane);\n options.dimensions = Property.getValueOrUndefined(\n plane.dimensions,\n time,\n options.dimensions\n );\n};\n\nconst scratchAxis = new Cartesian3();\nconst scratchUp = new Cartesian3();\nconst scratchTranslation = new Cartesian3();\nconst scratchScale = new Cartesian3();\nconst scratchRotation = new Matrix3();\nconst scratchRotationScale = new Matrix3();\nconst scratchLocalTransform = new Matrix4();\nfunction createPrimitiveMatrix(plane, dimensions, transform, result) {\n const normal = plane.normal;\n const distance = plane.distance;\n\n const translation = Cartesian3.multiplyByScalar(\n normal,\n -distance,\n scratchTranslation\n );\n\n let up = Cartesian3.clone(Cartesian3.UNIT_Z, scratchUp);\n if (\n CesiumMath.equalsEpsilon(\n Math.abs(Cartesian3.dot(up, normal)),\n 1.0,\n CesiumMath.EPSILON8\n )\n ) {\n up = Cartesian3.clone(Cartesian3.UNIT_Y, up);\n }\n\n const left = Cartesian3.cross(up, normal, scratchAxis);\n up = Cartesian3.cross(normal, left, up);\n Cartesian3.normalize(left, left);\n Cartesian3.normalize(up, up);\n\n const rotationMatrix = scratchRotation;\n Matrix3.setColumn(rotationMatrix, 0, left, rotationMatrix);\n Matrix3.setColumn(rotationMatrix, 1, up, rotationMatrix);\n Matrix3.setColumn(rotationMatrix, 2, normal, rotationMatrix);\n\n const scale = Cartesian3.fromElements(\n dimensions.x,\n dimensions.y,\n 1.0,\n scratchScale\n );\n const rotationScaleMatrix = Matrix3.multiplyByScale(\n rotationMatrix,\n scale,\n scratchRotationScale\n );\n\n const localTransform = Matrix4.fromRotationTranslation(\n rotationScaleMatrix,\n translation,\n scratchLocalTransform\n );\n return Matrix4.multiplyTransformation(transform, localTransform, result);\n}\n\n/**\n * @private\n */\nPlaneGeometryUpdater.createPrimitiveMatrix = createPrimitiveMatrix;\nexport default PlaneGeometryUpdater;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingRectangle from \"./BoundingRectangle.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CoplanarPolygonGeometryLibrary from \"./CoplanarPolygonGeometryLibrary.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PolygonGeometryLibrary from \"./PolygonGeometryLibrary.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst scratchPosition = new Cartesian3();\nconst scratchBR = new BoundingRectangle();\nconst stScratch = new Cartesian2();\nconst textureCoordinatesOrigin = new Cartesian2();\nconst scratchNormal = new Cartesian3();\nconst scratchTangent = new Cartesian3();\nconst scratchBitangent = new Cartesian3();\nconst centerScratch = new Cartesian3();\nconst axis1Scratch = new Cartesian3();\nconst axis2Scratch = new Cartesian3();\nconst quaternionScratch = new Quaternion();\nconst textureMatrixScratch = new Matrix3();\nconst tangentRotationScratch = new Matrix3();\nconst surfaceNormalScratch = new Cartesian3();\n\nfunction createGeometryFromPolygon(\n polygon,\n vertexFormat,\n boundingRectangle,\n stRotation,\n hardcodedTextureCoordinates,\n projectPointTo2D,\n normal,\n tangent,\n bitangent\n) {\n const positions = polygon.positions;\n let indices = PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);\n\n /* If polygon is completely unrenderable, just use the first three vertices */\n if (indices.length < 3) {\n indices = [0, 1, 2];\n }\n\n const newIndices = IndexDatatype.createTypedArray(\n positions.length,\n indices.length\n );\n newIndices.set(indices);\n\n let textureMatrix = textureMatrixScratch;\n if (stRotation !== 0.0) {\n let rotation = Quaternion.fromAxisAngle(\n normal,\n stRotation,\n quaternionScratch\n );\n textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrix);\n\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n rotation = Quaternion.fromAxisAngle(\n normal,\n -stRotation,\n quaternionScratch\n );\n const tangentRotation = Matrix3.fromQuaternion(\n rotation,\n tangentRotationScratch\n );\n\n tangent = Cartesian3.normalize(\n Matrix3.multiplyByVector(tangentRotation, tangent, tangent),\n tangent\n );\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n }\n }\n } else {\n textureMatrix = Matrix3.clone(Matrix3.IDENTITY, textureMatrix);\n }\n\n const stOrigin = textureCoordinatesOrigin;\n if (vertexFormat.st) {\n stOrigin.x = boundingRectangle.x;\n stOrigin.y = boundingRectangle.y;\n }\n\n const length = positions.length;\n const size = length * 3;\n const flatPositions = new Float64Array(size);\n const normals = vertexFormat.normal ? new Float32Array(size) : undefined;\n const tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(size)\n : undefined;\n const textureCoordinates = vertexFormat.st\n ? new Float32Array(length * 2)\n : undefined;\n\n let positionIndex = 0;\n let normalIndex = 0;\n let bitangentIndex = 0;\n let tangentIndex = 0;\n let stIndex = 0;\n\n for (let i = 0; i < length; i++) {\n const position = positions[i];\n flatPositions[positionIndex++] = position.x;\n flatPositions[positionIndex++] = position.y;\n flatPositions[positionIndex++] = position.z;\n\n if (vertexFormat.st) {\n if (\n defined(hardcodedTextureCoordinates) &&\n hardcodedTextureCoordinates.positions.length === length\n ) {\n textureCoordinates[stIndex++] =\n hardcodedTextureCoordinates.positions[i].x;\n textureCoordinates[stIndex++] =\n hardcodedTextureCoordinates.positions[i].y;\n } else {\n const p = Matrix3.multiplyByVector(\n textureMatrix,\n position,\n scratchPosition\n );\n const st = projectPointTo2D(p, stScratch);\n Cartesian2.subtract(st, stOrigin, st);\n\n const stx = CesiumMath.clamp(st.x / boundingRectangle.width, 0, 1);\n const sty = CesiumMath.clamp(st.y / boundingRectangle.height, 0, 1);\n textureCoordinates[stIndex++] = stx;\n textureCoordinates[stIndex++] = sty;\n }\n }\n\n if (vertexFormat.normal) {\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n }\n\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n }\n }\n\n const attributes = new GeometryAttributes();\n\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: flatPositions,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n return new Geometry({\n attributes: attributes,\n indices: newIndices,\n primitiveType: PrimitiveType.TRIANGLES,\n });\n}\n\n/**\n * A description of a polygon composed of arbitrary coplanar positions.\n *\n * @alias CoplanarPolygonGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points.\n *\n * @example\n * const polygonGeometry = new Cesium.CoplanarPolygonGeometry({\n * polygonHierarchy: new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArrayHeights([\n * -90.0, 30.0, 0.0,\n * -90.0, 30.0, 300000.0,\n * -80.0, 30.0, 300000.0,\n * -80.0, 30.0, 0.0\n * ]))\n * });\n *\n */\nfunction CoplanarPolygonGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const polygonHierarchy = options.polygonHierarchy;\n const textureCoordinates = options.textureCoordinates;\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.polygonHierarchy\", polygonHierarchy);\n //>>includeEnd('debug');\n\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._polygonHierarchy = polygonHierarchy;\n this._stRotation = defaultValue(options.stRotation, 0.0);\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._workerName = \"createCoplanarPolygonGeometry\";\n this._textureCoordinates = textureCoordinates;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n PolygonGeometryLibrary.computeHierarchyPackedLength(\n polygonHierarchy,\n Cartesian3\n ) +\n VertexFormat.packedLength +\n Ellipsoid.packedLength +\n (defined(textureCoordinates)\n ? PolygonGeometryLibrary.computeHierarchyPackedLength(\n textureCoordinates,\n Cartesian2\n )\n : 1) +\n 2;\n}\n\n/**\n * A description of a coplanar polygon from an array of positions.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points.\n * @returns {CoplanarPolygonGeometry}\n *\n * @example\n * // create a polygon from points\n * const polygon = Cesium.CoplanarPolygonGeometry.fromPositions({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * });\n * const geometry = Cesium.PolygonGeometry.createGeometry(polygon);\n *\n * @see PolygonGeometry#createGeometry\n */\nCoplanarPolygonGeometry.fromPositions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", options.positions);\n //>>includeEnd('debug');\n\n const newOptions = {\n polygonHierarchy: {\n positions: options.positions,\n },\n vertexFormat: options.vertexFormat,\n stRotation: options.stRotation,\n ellipsoid: options.ellipsoid,\n textureCoordinates: options.textureCoordinates,\n };\n return new CoplanarPolygonGeometry(newOptions);\n};\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {CoplanarPolygonGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nCoplanarPolygonGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._polygonHierarchy,\n array,\n startingIndex,\n Cartesian3\n );\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._stRotation;\n if (defined(value._textureCoordinates)) {\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._textureCoordinates,\n array,\n startingIndex,\n Cartesian2\n );\n } else {\n array[startingIndex++] = -1.0;\n }\n array[startingIndex++] = value.packedLength;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n polygonHierarchy: {},\n};\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {CoplanarPolygonGeometry} [result] The object into which to store the result.\n * @returns {CoplanarPolygonGeometry} The modified result parameter or a new CoplanarPolygonGeometry instance if one was not provided.\n */\nCoplanarPolygonGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian3\n );\n startingIndex = polygonHierarchy.startingIndex;\n delete polygonHierarchy.startingIndex;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const stRotation = array[startingIndex++];\n const textureCoordinates =\n array[startingIndex] === -1.0\n ? undefined\n : PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian2\n );\n if (defined(textureCoordinates)) {\n startingIndex = textureCoordinates.startingIndex;\n delete textureCoordinates.startingIndex;\n } else {\n startingIndex++;\n }\n const packedLength = array[startingIndex++];\n\n if (!defined(result)) {\n result = new CoplanarPolygonGeometry(scratchOptions);\n }\n\n result._polygonHierarchy = polygonHierarchy;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._stRotation = stRotation;\n result._textureCoordinates = textureCoordinates;\n result.packedLength = packedLength;\n\n return result;\n};\n\n/**\n * Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.\n *\n * @param {CoplanarPolygonGeometry} polygonGeometry A description of the polygon.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nCoplanarPolygonGeometry.createGeometry = function (polygonGeometry) {\n const vertexFormat = polygonGeometry._vertexFormat;\n const polygonHierarchy = polygonGeometry._polygonHierarchy;\n const stRotation = polygonGeometry._stRotation;\n const textureCoordinates = polygonGeometry._textureCoordinates;\n const hasTextureCoordinates = defined(textureCoordinates);\n\n let outerPositions = polygonHierarchy.positions;\n outerPositions = arrayRemoveDuplicates(\n outerPositions,\n Cartesian3.equalsEpsilon,\n true\n );\n if (outerPositions.length < 3) {\n return;\n }\n\n let normal = scratchNormal;\n let tangent = scratchTangent;\n let bitangent = scratchBitangent;\n let axis1 = axis1Scratch;\n const axis2 = axis2Scratch;\n\n const validGeometry = CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(\n outerPositions,\n centerScratch,\n axis1,\n axis2\n );\n if (!validGeometry) {\n return undefined;\n }\n\n normal = Cartesian3.cross(axis1, axis2, normal);\n normal = Cartesian3.normalize(normal, normal);\n\n if (\n !Cartesian3.equalsEpsilon(\n centerScratch,\n Cartesian3.ZERO,\n CesiumMath.EPSILON6\n )\n ) {\n const surfaceNormal = polygonGeometry._ellipsoid.geodeticSurfaceNormal(\n centerScratch,\n surfaceNormalScratch\n );\n if (Cartesian3.dot(normal, surfaceNormal) < 0) {\n normal = Cartesian3.negate(normal, normal);\n axis1 = Cartesian3.negate(axis1, axis1);\n }\n }\n\n const projectPoints = CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(\n centerScratch,\n axis1,\n axis2\n );\n const projectPoint = CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(\n centerScratch,\n axis1,\n axis2\n );\n\n if (vertexFormat.tangent) {\n tangent = Cartesian3.clone(axis1, tangent);\n }\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.clone(axis2, bitangent);\n }\n\n const results = PolygonGeometryLibrary.polygonsFromHierarchy(\n polygonHierarchy,\n hasTextureCoordinates,\n projectPoints,\n false\n );\n const hierarchy = results.hierarchy;\n const polygons = results.polygons;\n\n const dummyFunction = function (identity) {\n return identity;\n };\n\n const textureCoordinatePolygons = hasTextureCoordinates\n ? PolygonGeometryLibrary.polygonsFromHierarchy(\n textureCoordinates,\n true,\n dummyFunction,\n false\n ).polygons\n : undefined;\n\n if (hierarchy.length === 0) {\n return;\n }\n outerPositions = hierarchy[0].outerRing;\n\n const boundingSphere = BoundingSphere.fromPoints(outerPositions);\n const boundingRectangle = PolygonGeometryLibrary.computeBoundingRectangle(\n normal,\n projectPoint,\n outerPositions,\n stRotation,\n scratchBR\n );\n\n const geometries = [];\n for (let i = 0; i < polygons.length; i++) {\n const geometryInstance = new GeometryInstance({\n geometry: createGeometryFromPolygon(\n polygons[i],\n vertexFormat,\n boundingRectangle,\n stRotation,\n hasTextureCoordinates ? textureCoordinatePolygons[i] : undefined,\n projectPoint,\n normal,\n tangent,\n bitangent\n ),\n });\n\n geometries.push(geometryInstance);\n }\n\n const geometry = GeometryPipeline.combineInstances(geometries)[0];\n geometry.attributes.position.values = new Float64Array(\n geometry.attributes.position.values\n );\n geometry.indices = IndexDatatype.createTypedArray(\n geometry.attributes.position.values.length / 3,\n geometry.indices\n );\n\n const attributes = geometry.attributes;\n if (!vertexFormat.position) {\n delete attributes.position;\n }\n return new Geometry({\n attributes: attributes,\n indices: geometry.indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: boundingSphere,\n });\n};\nexport default CoplanarPolygonGeometry;\n", "import ArcType from \"./ArcType.js\";\nimport BoundingRectangle from \"./BoundingRectangle.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidGeodesic from \"./EllipsoidGeodesic.js\";\nimport EllipsoidTangentPlane from \"./EllipsoidTangentPlane.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PolygonGeometryLibrary from \"./PolygonGeometryLibrary.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport VertexFormat from \"./VertexFormat.js\";\nimport WindingOrder from \"./WindingOrder.js\";\n\nconst scratchCarto1 = new Cartographic();\nconst scratchCarto2 = new Cartographic();\nfunction adjustPosHeightsForNormal(position, p1, p2, ellipsoid) {\n const carto1 = ellipsoid.cartesianToCartographic(position, scratchCarto1);\n const height = carto1.height;\n const p1Carto = ellipsoid.cartesianToCartographic(p1, scratchCarto2);\n p1Carto.height = height;\n ellipsoid.cartographicToCartesian(p1Carto, p1);\n\n const p2Carto = ellipsoid.cartesianToCartographic(p2, scratchCarto2);\n p2Carto.height = height - 100;\n ellipsoid.cartographicToCartesian(p2Carto, p2);\n}\n\nconst scratchBoundingRectangle = new BoundingRectangle();\nconst scratchPosition = new Cartesian3();\nconst scratchNormal = new Cartesian3();\nconst scratchTangent = new Cartesian3();\nconst scratchBitangent = new Cartesian3();\nconst p1Scratch = new Cartesian3();\nconst p2Scratch = new Cartesian3();\nlet scratchPerPosNormal = new Cartesian3();\nlet scratchPerPosTangent = new Cartesian3();\nlet scratchPerPosBitangent = new Cartesian3();\n\nconst appendTextureCoordinatesOrigin = new Cartesian2();\nconst appendTextureCoordinatesCartesian2 = new Cartesian2();\nconst appendTextureCoordinatesCartesian3 = new Cartesian3();\nconst appendTextureCoordinatesQuaternion = new Quaternion();\nconst appendTextureCoordinatesMatrix3 = new Matrix3();\nconst tangentMatrixScratch = new Matrix3();\n\nfunction computeAttributes(options) {\n const vertexFormat = options.vertexFormat;\n const geometry = options.geometry;\n const shadowVolume = options.shadowVolume;\n const flatPositions = geometry.attributes.position.values;\n const flatTexcoords = defined(geometry.attributes.st)\n ? geometry.attributes.st.values\n : undefined;\n\n let length = flatPositions.length;\n const wall = options.wall;\n const top = options.top || wall;\n const bottom = options.bottom || wall;\n if (\n vertexFormat.st ||\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent ||\n shadowVolume\n ) {\n // PERFORMANCE_IDEA: Compute before subdivision, then just interpolate during subdivision.\n // PERFORMANCE_IDEA: Compute with createGeometryFromPositions() for fast path when there's no holes.\n const boundingRectangle = options.boundingRectangle;\n const tangentPlane = options.tangentPlane;\n const ellipsoid = options.ellipsoid;\n const stRotation = options.stRotation;\n const perPositionHeight = options.perPositionHeight;\n\n const origin = appendTextureCoordinatesOrigin;\n origin.x = boundingRectangle.x;\n origin.y = boundingRectangle.y;\n\n const textureCoordinates = vertexFormat.st\n ? new Float32Array(2 * (length / 3))\n : undefined;\n let normals;\n if (vertexFormat.normal) {\n if (perPositionHeight && top && !wall) {\n normals = geometry.attributes.normal.values;\n } else {\n normals = new Float32Array(length);\n }\n }\n const tangents = vertexFormat.tangent\n ? new Float32Array(length)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(length)\n : undefined;\n const extrudeNormals = shadowVolume ? new Float32Array(length) : undefined;\n\n let textureCoordIndex = 0;\n let attrIndex = 0;\n\n let normal = scratchNormal;\n let tangent = scratchTangent;\n let bitangent = scratchBitangent;\n let recomputeNormal = true;\n\n let textureMatrix = appendTextureCoordinatesMatrix3;\n let tangentRotationMatrix = tangentMatrixScratch;\n if (stRotation !== 0.0) {\n let rotation = Quaternion.fromAxisAngle(\n tangentPlane._plane.normal,\n stRotation,\n appendTextureCoordinatesQuaternion\n );\n textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrix);\n\n rotation = Quaternion.fromAxisAngle(\n tangentPlane._plane.normal,\n -stRotation,\n appendTextureCoordinatesQuaternion\n );\n tangentRotationMatrix = Matrix3.fromQuaternion(\n rotation,\n tangentRotationMatrix\n );\n } else {\n textureMatrix = Matrix3.clone(Matrix3.IDENTITY, textureMatrix);\n tangentRotationMatrix = Matrix3.clone(\n Matrix3.IDENTITY,\n tangentRotationMatrix\n );\n }\n\n let bottomOffset = 0;\n let bottomOffset2 = 0;\n\n if (top && bottom) {\n bottomOffset = length / 2;\n bottomOffset2 = length / 3;\n\n length /= 2;\n }\n\n for (let i = 0; i < length; i += 3) {\n const position = Cartesian3.fromArray(\n flatPositions,\n i,\n appendTextureCoordinatesCartesian3\n );\n\n if (vertexFormat.st) {\n if (!defined(flatTexcoords)) {\n let p = Matrix3.multiplyByVector(\n textureMatrix,\n position,\n scratchPosition\n );\n p = ellipsoid.scaleToGeodeticSurface(p, p);\n const st = tangentPlane.projectPointOntoPlane(\n p,\n appendTextureCoordinatesCartesian2\n );\n Cartesian2.subtract(st, origin, st);\n\n const stx = CesiumMath.clamp(st.x / boundingRectangle.width, 0, 1);\n const sty = CesiumMath.clamp(st.y / boundingRectangle.height, 0, 1);\n if (bottom) {\n textureCoordinates[textureCoordIndex + bottomOffset2] = stx;\n textureCoordinates[textureCoordIndex + 1 + bottomOffset2] = sty;\n }\n if (top) {\n textureCoordinates[textureCoordIndex] = stx;\n textureCoordinates[textureCoordIndex + 1] = sty;\n }\n\n textureCoordIndex += 2;\n }\n }\n\n if (\n vertexFormat.normal ||\n vertexFormat.tangent ||\n vertexFormat.bitangent ||\n shadowVolume\n ) {\n const attrIndex1 = attrIndex + 1;\n const attrIndex2 = attrIndex + 2;\n\n if (wall) {\n if (i + 3 < length) {\n const p1 = Cartesian3.fromArray(flatPositions, i + 3, p1Scratch);\n\n if (recomputeNormal) {\n const p2 = Cartesian3.fromArray(\n flatPositions,\n i + length,\n p2Scratch\n );\n if (perPositionHeight) {\n adjustPosHeightsForNormal(position, p1, p2, ellipsoid);\n }\n Cartesian3.subtract(p1, position, p1);\n Cartesian3.subtract(p2, position, p2);\n normal = Cartesian3.normalize(\n Cartesian3.cross(p2, p1, normal),\n normal\n );\n recomputeNormal = false;\n }\n\n if (Cartesian3.equalsEpsilon(p1, position, CesiumMath.EPSILON10)) {\n // if we've reached a corner\n recomputeNormal = true;\n }\n }\n\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n bitangent = ellipsoid.geodeticSurfaceNormal(position, bitangent);\n if (vertexFormat.tangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(bitangent, normal, tangent),\n tangent\n );\n }\n }\n } else {\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n if (perPositionHeight) {\n scratchPerPosNormal = Cartesian3.fromArray(\n normals,\n attrIndex,\n scratchPerPosNormal\n );\n scratchPerPosTangent = Cartesian3.cross(\n Cartesian3.UNIT_Z,\n scratchPerPosNormal,\n scratchPerPosTangent\n );\n scratchPerPosTangent = Cartesian3.normalize(\n Matrix3.multiplyByVector(\n tangentRotationMatrix,\n scratchPerPosTangent,\n scratchPerPosTangent\n ),\n scratchPerPosTangent\n );\n if (vertexFormat.bitangent) {\n scratchPerPosBitangent = Cartesian3.normalize(\n Cartesian3.cross(\n scratchPerPosNormal,\n scratchPerPosTangent,\n scratchPerPosBitangent\n ),\n scratchPerPosBitangent\n );\n }\n }\n\n tangent = Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent);\n tangent = Cartesian3.normalize(\n Matrix3.multiplyByVector(tangentRotationMatrix, tangent, tangent),\n tangent\n );\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n }\n }\n }\n\n if (vertexFormat.normal) {\n if (options.wall) {\n normals[attrIndex + bottomOffset] = normal.x;\n normals[attrIndex1 + bottomOffset] = normal.y;\n normals[attrIndex2 + bottomOffset] = normal.z;\n } else if (bottom) {\n normals[attrIndex + bottomOffset] = -normal.x;\n normals[attrIndex1 + bottomOffset] = -normal.y;\n normals[attrIndex2 + bottomOffset] = -normal.z;\n }\n\n if ((top && !perPositionHeight) || wall) {\n normals[attrIndex] = normal.x;\n normals[attrIndex1] = normal.y;\n normals[attrIndex2] = normal.z;\n }\n }\n\n if (shadowVolume) {\n if (wall) {\n normal = ellipsoid.geodeticSurfaceNormal(position, normal);\n }\n extrudeNormals[attrIndex + bottomOffset] = -normal.x;\n extrudeNormals[attrIndex1 + bottomOffset] = -normal.y;\n extrudeNormals[attrIndex2 + bottomOffset] = -normal.z;\n }\n\n if (vertexFormat.tangent) {\n if (options.wall) {\n tangents[attrIndex + bottomOffset] = tangent.x;\n tangents[attrIndex1 + bottomOffset] = tangent.y;\n tangents[attrIndex2 + bottomOffset] = tangent.z;\n } else if (bottom) {\n tangents[attrIndex + bottomOffset] = -tangent.x;\n tangents[attrIndex1 + bottomOffset] = -tangent.y;\n tangents[attrIndex2 + bottomOffset] = -tangent.z;\n }\n\n if (top) {\n if (perPositionHeight) {\n tangents[attrIndex] = scratchPerPosTangent.x;\n tangents[attrIndex1] = scratchPerPosTangent.y;\n tangents[attrIndex2] = scratchPerPosTangent.z;\n } else {\n tangents[attrIndex] = tangent.x;\n tangents[attrIndex1] = tangent.y;\n tangents[attrIndex2] = tangent.z;\n }\n }\n }\n\n if (vertexFormat.bitangent) {\n if (bottom) {\n bitangents[attrIndex + bottomOffset] = bitangent.x;\n bitangents[attrIndex1 + bottomOffset] = bitangent.y;\n bitangents[attrIndex2 + bottomOffset] = bitangent.z;\n }\n if (top) {\n if (perPositionHeight) {\n bitangents[attrIndex] = scratchPerPosBitangent.x;\n bitangents[attrIndex1] = scratchPerPosBitangent.y;\n bitangents[attrIndex2] = scratchPerPosBitangent.z;\n } else {\n bitangents[attrIndex] = bitangent.x;\n bitangents[attrIndex1] = bitangent.y;\n bitangents[attrIndex2] = bitangent.z;\n }\n }\n }\n attrIndex += 3;\n }\n }\n\n if (vertexFormat.st && !defined(flatTexcoords)) {\n geometry.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n if (vertexFormat.normal) {\n geometry.attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n geometry.attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n geometry.attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (shadowVolume) {\n geometry.attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: extrudeNormals,\n });\n }\n }\n\n if (options.extrude && defined(options.offsetAttribute)) {\n const size = flatPositions.length / 3;\n let offsetAttribute = new Uint8Array(size);\n\n if (options.offsetAttribute === GeometryOffsetAttribute.TOP) {\n if ((top && bottom) || wall) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else if (top) {\n offsetAttribute = offsetAttribute.fill(1);\n }\n } else {\n const offsetValue =\n options.offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n });\n }\n\n return geometry;\n}\n\nconst startCartographicScratch = new Cartographic();\nconst endCartographicScratch = new Cartographic();\nconst idlCross = {\n westOverIDL: 0.0,\n eastOverIDL: 0.0,\n};\nlet ellipsoidGeodesic = new EllipsoidGeodesic();\nfunction computeRectangle(positions, ellipsoid, arcType, granularity, result) {\n result = defaultValue(result, new Rectangle());\n if (!defined(positions) || positions.length < 3) {\n result.west = 0.0;\n result.north = 0.0;\n result.south = 0.0;\n result.east = 0.0;\n return result;\n }\n\n if (arcType === ArcType.RHUMB) {\n return Rectangle.fromCartesianArray(positions, ellipsoid, result);\n }\n\n if (!ellipsoidGeodesic.ellipsoid.equals(ellipsoid)) {\n ellipsoidGeodesic = new EllipsoidGeodesic(undefined, undefined, ellipsoid);\n }\n\n result.west = Number.POSITIVE_INFINITY;\n result.east = Number.NEGATIVE_INFINITY;\n result.south = Number.POSITIVE_INFINITY;\n result.north = Number.NEGATIVE_INFINITY;\n\n idlCross.westOverIDL = Number.POSITIVE_INFINITY;\n idlCross.eastOverIDL = Number.NEGATIVE_INFINITY;\n\n const inverseChordLength =\n 1.0 / CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);\n const positionsLength = positions.length;\n let endCartographic = ellipsoid.cartesianToCartographic(\n positions[0],\n endCartographicScratch\n );\n let startCartographic = startCartographicScratch;\n let swap;\n\n for (let i = 1; i < positionsLength; i++) {\n swap = startCartographic;\n startCartographic = endCartographic;\n endCartographic = ellipsoid.cartesianToCartographic(positions[i], swap);\n ellipsoidGeodesic.setEndPoints(startCartographic, endCartographic);\n interpolateAndGrowRectangle(\n ellipsoidGeodesic,\n inverseChordLength,\n result,\n idlCross\n );\n }\n\n swap = startCartographic;\n startCartographic = endCartographic;\n endCartographic = ellipsoid.cartesianToCartographic(positions[0], swap);\n ellipsoidGeodesic.setEndPoints(startCartographic, endCartographic);\n interpolateAndGrowRectangle(\n ellipsoidGeodesic,\n inverseChordLength,\n result,\n idlCross\n );\n\n if (result.east - result.west > idlCross.eastOverIDL - idlCross.westOverIDL) {\n result.west = idlCross.westOverIDL;\n result.east = idlCross.eastOverIDL;\n\n if (result.east > CesiumMath.PI) {\n result.east = result.east - CesiumMath.TWO_PI;\n }\n if (result.west > CesiumMath.PI) {\n result.west = result.west - CesiumMath.TWO_PI;\n }\n }\n\n return result;\n}\n\nconst interpolatedCartographicScratch = new Cartographic();\nfunction interpolateAndGrowRectangle(\n ellipsoidGeodesic,\n inverseChordLength,\n result,\n idlCross\n) {\n const segmentLength = ellipsoidGeodesic.surfaceDistance;\n\n const numPoints = Math.ceil(segmentLength * inverseChordLength);\n const subsegmentDistance =\n numPoints > 0 ? segmentLength / (numPoints - 1) : Number.POSITIVE_INFINITY;\n let interpolationDistance = 0.0;\n\n for (let i = 0; i < numPoints; i++) {\n const interpolatedCartographic = ellipsoidGeodesic.interpolateUsingSurfaceDistance(\n interpolationDistance,\n interpolatedCartographicScratch\n );\n interpolationDistance += subsegmentDistance;\n const longitude = interpolatedCartographic.longitude;\n const latitude = interpolatedCartographic.latitude;\n\n result.west = Math.min(result.west, longitude);\n result.east = Math.max(result.east, longitude);\n result.south = Math.min(result.south, latitude);\n result.north = Math.max(result.north, latitude);\n\n const lonAdjusted =\n longitude >= 0 ? longitude : longitude + CesiumMath.TWO_PI;\n idlCross.westOverIDL = Math.min(idlCross.westOverIDL, lonAdjusted);\n idlCross.eastOverIDL = Math.max(idlCross.eastOverIDL, lonAdjusted);\n }\n}\n\nconst createGeometryFromPositionsExtrudedPositions = [];\n\nfunction createGeometryFromPositionsExtruded(\n ellipsoid,\n polygon,\n textureCoordinates,\n granularity,\n hierarchy,\n perPositionHeight,\n closeTop,\n closeBottom,\n vertexFormat,\n arcType\n) {\n const geos = {\n walls: [],\n };\n let i;\n\n if (closeTop || closeBottom) {\n const topGeo = PolygonGeometryLibrary.createGeometryFromPositions(\n ellipsoid,\n polygon,\n textureCoordinates,\n granularity,\n perPositionHeight,\n vertexFormat,\n arcType\n );\n\n const edgePoints = topGeo.attributes.position.values;\n const indices = topGeo.indices;\n let numPositions;\n let newIndices;\n\n if (closeTop && closeBottom) {\n const topBottomPositions = edgePoints.concat(edgePoints);\n\n numPositions = topBottomPositions.length / 3;\n\n newIndices = IndexDatatype.createTypedArray(\n numPositions,\n indices.length * 2\n );\n newIndices.set(indices);\n const ilength = indices.length;\n\n const length = numPositions / 2;\n\n for (i = 0; i < ilength; i += 3) {\n const i0 = newIndices[i] + length;\n const i1 = newIndices[i + 1] + length;\n const i2 = newIndices[i + 2] + length;\n\n newIndices[i + ilength] = i2;\n newIndices[i + 1 + ilength] = i1;\n newIndices[i + 2 + ilength] = i0;\n }\n\n topGeo.attributes.position.values = topBottomPositions;\n if (perPositionHeight && vertexFormat.normal) {\n const normals = topGeo.attributes.normal.values;\n topGeo.attributes.normal.values = new Float32Array(\n topBottomPositions.length\n );\n topGeo.attributes.normal.values.set(normals);\n }\n\n if (vertexFormat.st && defined(textureCoordinates)) {\n const texcoords = topGeo.attributes.st.values;\n topGeo.attributes.st.values = new Float32Array(numPositions * 2);\n topGeo.attributes.st.values = texcoords.concat(texcoords);\n }\n\n topGeo.indices = newIndices;\n } else if (closeBottom) {\n numPositions = edgePoints.length / 3;\n newIndices = IndexDatatype.createTypedArray(numPositions, indices.length);\n\n for (i = 0; i < indices.length; i += 3) {\n newIndices[i] = indices[i + 2];\n newIndices[i + 1] = indices[i + 1];\n newIndices[i + 2] = indices[i];\n }\n\n topGeo.indices = newIndices;\n }\n\n geos.topAndBottom = new GeometryInstance({\n geometry: topGeo,\n });\n }\n\n let outerRing = hierarchy.outerRing;\n let tangentPlane = EllipsoidTangentPlane.fromPoints(outerRing, ellipsoid);\n let positions2D = tangentPlane.projectPointsOntoPlane(\n outerRing,\n createGeometryFromPositionsExtrudedPositions\n );\n\n let windingOrder = PolygonPipeline.computeWindingOrder2D(positions2D);\n if (windingOrder === WindingOrder.CLOCKWISE) {\n outerRing = outerRing.slice().reverse();\n }\n\n let wallGeo = PolygonGeometryLibrary.computeWallGeometry(\n outerRing,\n textureCoordinates,\n ellipsoid,\n granularity,\n perPositionHeight,\n arcType\n );\n geos.walls.push(\n new GeometryInstance({\n geometry: wallGeo,\n })\n );\n\n const holes = hierarchy.holes;\n for (i = 0; i < holes.length; i++) {\n let hole = holes[i];\n\n tangentPlane = EllipsoidTangentPlane.fromPoints(hole, ellipsoid);\n positions2D = tangentPlane.projectPointsOntoPlane(\n hole,\n createGeometryFromPositionsExtrudedPositions\n );\n\n windingOrder = PolygonPipeline.computeWindingOrder2D(positions2D);\n if (windingOrder === WindingOrder.COUNTER_CLOCKWISE) {\n hole = hole.slice().reverse();\n }\n\n wallGeo = PolygonGeometryLibrary.computeWallGeometry(\n hole,\n textureCoordinates,\n ellipsoid,\n granularity,\n perPositionHeight,\n arcType\n );\n geos.walls.push(\n new GeometryInstance({\n geometry: wallGeo,\n })\n );\n }\n\n return geos;\n}\n\n/**\n * A description of a polygon on the ellipsoid. The polygon is defined by a polygon hierarchy. Polygon geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.\n *\n * @alias PolygonGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.\n * @param {number} [options.height=0.0] The distance in meters between the polygon and the ellipsoid surface.\n * @param {number} [options.extrudedHeight] The distance in meters between the polygon's extruded face and the ellipsoid surface.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.\n * @param {boolean} [options.closeTop=true] When false, leaves off the top of an extruded polygon open.\n * @param {boolean} [options.closeBottom=true] When false, leaves off the bottom of an extruded polygon open.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polygon edges must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points. Has no effect for ground primitives.\n *\n * @see PolygonGeometry#createGeometry\n * @see PolygonGeometry#fromPositions\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polygon.html|Cesium Sandcastle Polygon Demo}\n *\n * @example\n * // 1. create a polygon from points\n * const polygon = new Cesium.PolygonGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * )\n * });\n * const geometry = Cesium.PolygonGeometry.createGeometry(polygon);\n *\n * // 2. create a nested polygon with holes\n * const polygonWithHole = new Cesium.PolygonGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -109.0, 30.0,\n * -95.0, 30.0,\n * -95.0, 40.0,\n * -109.0, 40.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -107.0, 31.0,\n * -107.0, 39.0,\n * -97.0, 39.0,\n * -97.0, 31.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 33.0,\n * -99.0, 33.0,\n * -99.0, 37.0,\n * -105.0, 37.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -103.0, 34.0,\n * -101.0, 34.0,\n * -101.0, 36.0,\n * -103.0, 36.0\n * ])\n * )]\n * )]\n * )]\n * )\n * });\n * const geometry = Cesium.PolygonGeometry.createGeometry(polygonWithHole);\n *\n * // 3. create extruded polygon\n * const extrudedPolygon = new Cesium.PolygonGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * ),\n * extrudedHeight: 300000\n * });\n * const geometry = Cesium.PolygonGeometry.createGeometry(extrudedPolygon);\n */\nfunction PolygonGeometry(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.object(\"options.polygonHierarchy\", options.polygonHierarchy);\n if (\n defined(options.perPositionHeight) &&\n options.perPositionHeight &&\n defined(options.height)\n ) {\n throw new DeveloperError(\n \"Cannot use both options.perPositionHeight and options.height\"\n );\n }\n if (\n defined(options.arcType) &&\n options.arcType !== ArcType.GEODESIC &&\n options.arcType !== ArcType.RHUMB\n ) {\n throw new DeveloperError(\n \"Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.\"\n );\n }\n //>>includeEnd('debug');\n\n const polygonHierarchy = options.polygonHierarchy;\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const stRotation = defaultValue(options.stRotation, 0.0);\n const textureCoordinates = options.textureCoordinates;\n const perPositionHeight = defaultValue(options.perPositionHeight, false);\n const perPositionHeightExtrude =\n perPositionHeight && defined(options.extrudedHeight);\n let height = defaultValue(options.height, 0.0);\n let extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n if (!perPositionHeightExtrude) {\n const h = Math.max(height, extrudedHeight);\n extrudedHeight = Math.min(height, extrudedHeight);\n height = h;\n }\n\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._granularity = granularity;\n this._stRotation = stRotation;\n this._height = height;\n this._extrudedHeight = extrudedHeight;\n this._closeTop = defaultValue(options.closeTop, true);\n this._closeBottom = defaultValue(options.closeBottom, true);\n this._polygonHierarchy = polygonHierarchy;\n this._perPositionHeight = perPositionHeight;\n this._perPositionHeightExtrude = perPositionHeightExtrude;\n this._shadowVolume = defaultValue(options.shadowVolume, false);\n this._workerName = \"createPolygonGeometry\";\n this._offsetAttribute = options.offsetAttribute;\n this._arcType = defaultValue(options.arcType, ArcType.GEODESIC);\n\n this._rectangle = undefined;\n this._textureCoordinateRotationPoints = undefined;\n this._textureCoordinates = textureCoordinates;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n PolygonGeometryLibrary.computeHierarchyPackedLength(\n polygonHierarchy,\n Cartesian3\n ) +\n Ellipsoid.packedLength +\n VertexFormat.packedLength +\n (textureCoordinates\n ? PolygonGeometryLibrary.computeHierarchyPackedLength(\n textureCoordinates,\n Cartesian2\n )\n : 1) +\n 12;\n}\n\n/**\n * A description of a polygon from an array of positions. Polygon geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.\n * @param {number} [options.height=0.0] The height of the polygon.\n * @param {number} [options.extrudedHeight] The height of the polygon extrusion.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.\n * @param {boolean} [options.closeTop=true] When false, leaves off the top of an extruded polygon open.\n * @param {boolean} [options.closeBottom=true] When false, leaves off the bottom of an extruded polygon open.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polygon edges must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points. Has no effect for ground primitives.\n * @returns {PolygonGeometry}\n *\n * @example\n * // create a polygon from points\n * const polygon = Cesium.PolygonGeometry.fromPositions({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * });\n * const geometry = Cesium.PolygonGeometry.createGeometry(polygon);\n *\n * @see PolygonGeometry#createGeometry\n */\nPolygonGeometry.fromPositions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", options.positions);\n //>>includeEnd('debug');\n\n const newOptions = {\n polygonHierarchy: {\n positions: options.positions,\n },\n height: options.height,\n extrudedHeight: options.extrudedHeight,\n vertexFormat: options.vertexFormat,\n stRotation: options.stRotation,\n ellipsoid: options.ellipsoid,\n granularity: options.granularity,\n perPositionHeight: options.perPositionHeight,\n closeTop: options.closeTop,\n closeBottom: options.closeBottom,\n offsetAttribute: options.offsetAttribute,\n arcType: options.arcType,\n textureCoordinates: options.textureCoordinates,\n };\n return new PolygonGeometry(newOptions);\n};\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolygonGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPolygonGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._polygonHierarchy,\n array,\n startingIndex,\n Cartesian3\n );\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._stRotation;\n array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0;\n array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0;\n array[startingIndex++] = value._closeTop ? 1.0 : 0.0;\n array[startingIndex++] = value._closeBottom ? 1.0 : 0.0;\n array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0;\n array[startingIndex++] = defaultValue(value._offsetAttribute, -1);\n array[startingIndex++] = value._arcType;\n if (defined(value._textureCoordinates)) {\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._textureCoordinates,\n array,\n startingIndex,\n Cartesian2\n );\n } else {\n array[startingIndex++] = -1.0;\n }\n array[startingIndex++] = value.packedLength;\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\n\n//Only used to avoid inability to default construct.\nconst dummyOptions = {\n polygonHierarchy: {},\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolygonGeometry} [result] The object into which to store the result.\n */\nPolygonGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian3\n );\n startingIndex = polygonHierarchy.startingIndex;\n delete polygonHierarchy.startingIndex;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const height = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const granularity = array[startingIndex++];\n const stRotation = array[startingIndex++];\n const perPositionHeightExtrude = array[startingIndex++] === 1.0;\n const perPositionHeight = array[startingIndex++] === 1.0;\n const closeTop = array[startingIndex++] === 1.0;\n const closeBottom = array[startingIndex++] === 1.0;\n const shadowVolume = array[startingIndex++] === 1.0;\n const offsetAttribute = array[startingIndex++];\n const arcType = array[startingIndex++];\n const textureCoordinates =\n array[startingIndex] === -1.0\n ? undefined\n : PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian2\n );\n if (defined(textureCoordinates)) {\n startingIndex = textureCoordinates.startingIndex;\n delete textureCoordinates.startingIndex;\n } else {\n startingIndex++;\n }\n const packedLength = array[startingIndex++];\n\n if (!defined(result)) {\n result = new PolygonGeometry(dummyOptions);\n }\n\n result._polygonHierarchy = polygonHierarchy;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._height = height;\n result._extrudedHeight = extrudedHeight;\n result._granularity = granularity;\n result._stRotation = stRotation;\n result._perPositionHeightExtrude = perPositionHeightExtrude;\n result._perPositionHeight = perPositionHeight;\n result._closeTop = closeTop;\n result._closeBottom = closeBottom;\n result._shadowVolume = shadowVolume;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n result._arcType = arcType;\n result._textureCoordinates = textureCoordinates;\n result.packedLength = packedLength;\n\n return result;\n};\n\n/**\n * Returns the bounding rectangle given the provided options\n *\n * @param {object} options Object with the following properties:\n * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions sampled.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polygon edges must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {Rectangle} [result] An object in which to store the result.\n *\n * @returns {Rectangle} The result rectangle\n */\nPolygonGeometry.computeRectangle = function (options, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.object(\"options.polygonHierarchy\", options.polygonHierarchy);\n //>>includeEnd('debug');\n\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const arcType = defaultValue(options.arcType, ArcType.GEODESIC);\n //>>includeStart('debug', pragmas.debug);\n if (arcType !== ArcType.GEODESIC && arcType !== ArcType.RHUMB) {\n throw new DeveloperError(\n \"Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.\"\n );\n }\n //>>includeEnd('debug');\n\n const polygonHierarchy = options.polygonHierarchy;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n return computeRectangle(\n polygonHierarchy.positions,\n ellipsoid,\n arcType,\n granularity,\n result\n );\n};\n\n/**\n * Computes the geometric representation of a polygon, including its vertices, indices, and a bounding sphere.\n *\n * @param {PolygonGeometry} polygonGeometry A description of the polygon.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPolygonGeometry.createGeometry = function (polygonGeometry) {\n const vertexFormat = polygonGeometry._vertexFormat;\n const ellipsoid = polygonGeometry._ellipsoid;\n const granularity = polygonGeometry._granularity;\n const stRotation = polygonGeometry._stRotation;\n const polygonHierarchy = polygonGeometry._polygonHierarchy;\n const perPositionHeight = polygonGeometry._perPositionHeight;\n const closeTop = polygonGeometry._closeTop;\n const closeBottom = polygonGeometry._closeBottom;\n const arcType = polygonGeometry._arcType;\n const textureCoordinates = polygonGeometry._textureCoordinates;\n\n const hasTextureCoordinates = defined(textureCoordinates);\n\n let outerPositions = polygonHierarchy.positions;\n if (outerPositions.length < 3) {\n return;\n }\n\n const tangentPlane = EllipsoidTangentPlane.fromPoints(\n outerPositions,\n ellipsoid\n );\n\n const results = PolygonGeometryLibrary.polygonsFromHierarchy(\n polygonHierarchy,\n hasTextureCoordinates,\n tangentPlane.projectPointsOntoPlane.bind(tangentPlane),\n !perPositionHeight,\n ellipsoid\n );\n\n const hierarchy = results.hierarchy;\n const polygons = results.polygons;\n\n const dummyFunction = function (identity) {\n return identity;\n };\n\n const textureCoordinatePolygons = hasTextureCoordinates\n ? PolygonGeometryLibrary.polygonsFromHierarchy(\n textureCoordinates,\n true,\n dummyFunction,\n false\n ).polygons\n : undefined;\n\n if (hierarchy.length === 0) {\n return;\n }\n\n outerPositions = hierarchy[0].outerRing;\n const boundingRectangle = PolygonGeometryLibrary.computeBoundingRectangle(\n tangentPlane.plane.normal,\n tangentPlane.projectPointOntoPlane.bind(tangentPlane),\n outerPositions,\n stRotation,\n scratchBoundingRectangle\n );\n\n const geometries = [];\n\n const height = polygonGeometry._height;\n const extrudedHeight = polygonGeometry._extrudedHeight;\n const extrude =\n polygonGeometry._perPositionHeightExtrude ||\n !CesiumMath.equalsEpsilon(height, extrudedHeight, 0, CesiumMath.EPSILON2);\n\n const options = {\n perPositionHeight: perPositionHeight,\n vertexFormat: vertexFormat,\n geometry: undefined,\n tangentPlane: tangentPlane,\n boundingRectangle: boundingRectangle,\n ellipsoid: ellipsoid,\n stRotation: stRotation,\n textureCoordinates: undefined,\n bottom: false,\n top: true,\n wall: false,\n extrude: false,\n arcType: arcType,\n };\n\n let i;\n\n if (extrude) {\n options.extrude = true;\n options.top = closeTop;\n options.bottom = closeBottom;\n options.shadowVolume = polygonGeometry._shadowVolume;\n options.offsetAttribute = polygonGeometry._offsetAttribute;\n for (i = 0; i < polygons.length; i++) {\n const splitGeometry = createGeometryFromPositionsExtruded(\n ellipsoid,\n polygons[i],\n hasTextureCoordinates ? textureCoordinatePolygons[i] : undefined,\n granularity,\n hierarchy[i],\n perPositionHeight,\n closeTop,\n closeBottom,\n vertexFormat,\n arcType\n );\n\n let topAndBottom;\n if (closeTop && closeBottom) {\n topAndBottom = splitGeometry.topAndBottom;\n options.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(\n topAndBottom.geometry,\n height,\n extrudedHeight,\n ellipsoid,\n perPositionHeight\n );\n } else if (closeTop) {\n topAndBottom = splitGeometry.topAndBottom;\n topAndBottom.geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n topAndBottom.geometry.attributes.position.values,\n height,\n ellipsoid,\n !perPositionHeight\n );\n options.geometry = topAndBottom.geometry;\n } else if (closeBottom) {\n topAndBottom = splitGeometry.topAndBottom;\n topAndBottom.geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n topAndBottom.geometry.attributes.position.values,\n extrudedHeight,\n ellipsoid,\n true\n );\n options.geometry = topAndBottom.geometry;\n }\n if (closeTop || closeBottom) {\n options.wall = false;\n topAndBottom.geometry = computeAttributes(options);\n geometries.push(topAndBottom);\n }\n\n const walls = splitGeometry.walls;\n options.wall = true;\n for (let k = 0; k < walls.length; k++) {\n const wall = walls[k];\n options.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(\n wall.geometry,\n height,\n extrudedHeight,\n ellipsoid,\n perPositionHeight\n );\n wall.geometry = computeAttributes(options);\n geometries.push(wall);\n }\n }\n } else {\n for (i = 0; i < polygons.length; i++) {\n const geometryInstance = new GeometryInstance({\n geometry: PolygonGeometryLibrary.createGeometryFromPositions(\n ellipsoid,\n polygons[i],\n hasTextureCoordinates ? textureCoordinatePolygons[i] : undefined,\n granularity,\n perPositionHeight,\n vertexFormat,\n arcType\n ),\n });\n geometryInstance.geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n geometryInstance.geometry.attributes.position.values,\n height,\n ellipsoid,\n !perPositionHeight\n );\n options.geometry = geometryInstance.geometry;\n\n geometryInstance.geometry = computeAttributes(options);\n\n if (defined(polygonGeometry._offsetAttribute)) {\n const length =\n geometryInstance.geometry.attributes.position.values.length;\n const offsetValue =\n polygonGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute(\n {\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n }\n );\n }\n\n geometries.push(geometryInstance);\n }\n }\n\n const geometry = GeometryPipeline.combineInstances(geometries)[0];\n geometry.attributes.position.values = new Float64Array(\n geometry.attributes.position.values\n );\n geometry.indices = IndexDatatype.createTypedArray(\n geometry.attributes.position.values.length / 3,\n geometry.indices\n );\n\n const attributes = geometry.attributes;\n const boundingSphere = BoundingSphere.fromVertices(\n attributes.position.values\n );\n\n if (!vertexFormat.position) {\n delete attributes.position;\n }\n\n return new Geometry({\n attributes: attributes,\n indices: geometry.indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: boundingSphere,\n offsetAttribute: polygonGeometry._offsetAttribute,\n });\n};\n\n/**\n * @private\n */\nPolygonGeometry.createShadowVolume = function (\n polygonGeometry,\n minHeightFunc,\n maxHeightFunc\n) {\n const granularity = polygonGeometry._granularity;\n const ellipsoid = polygonGeometry._ellipsoid;\n\n const minHeight = minHeightFunc(granularity, ellipsoid);\n const maxHeight = maxHeightFunc(granularity, ellipsoid);\n\n return new PolygonGeometry({\n polygonHierarchy: polygonGeometry._polygonHierarchy,\n ellipsoid: ellipsoid,\n stRotation: polygonGeometry._stRotation,\n granularity: granularity,\n perPositionHeight: false,\n extrudedHeight: minHeight,\n height: maxHeight,\n vertexFormat: VertexFormat.POSITION_ONLY,\n shadowVolume: true,\n arcType: polygonGeometry._arcType,\n });\n};\n\nfunction textureCoordinateRotationPoints(polygonGeometry) {\n const stRotation = -polygonGeometry._stRotation;\n if (stRotation === 0.0) {\n return [0, 0, 0, 1, 1, 0];\n }\n const ellipsoid = polygonGeometry._ellipsoid;\n const positions = polygonGeometry._polygonHierarchy.positions;\n const boundingRectangle = polygonGeometry.rectangle;\n return Geometry._textureCoordinateRotationPoints(\n positions,\n stRotation,\n ellipsoid,\n boundingRectangle\n );\n}\n\nObject.defineProperties(PolygonGeometry.prototype, {\n /**\n * @private\n */\n rectangle: {\n get: function () {\n if (!defined(this._rectangle)) {\n const positions = this._polygonHierarchy.positions;\n this._rectangle = computeRectangle(\n positions,\n this._ellipsoid,\n this._arcType,\n this._granularity\n );\n }\n\n return this._rectangle;\n },\n },\n /**\n * For remapping texture coordinates when rendering PolygonGeometries as GroundPrimitives.\n * @private\n */\n textureCoordinateRotationPoints: {\n get: function () {\n if (!defined(this._textureCoordinateRotationPoints)) {\n this._textureCoordinateRotationPoints = textureCoordinateRotationPoints(\n this\n );\n }\n return this._textureCoordinateRotationPoints;\n },\n },\n});\nexport default PolygonGeometry;\n", "import ArcType from \"./ArcType.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport EllipsoidTangentPlane from \"./EllipsoidTangentPlane.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolygonGeometryLibrary from \"./PolygonGeometryLibrary.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport WindingOrder from \"./WindingOrder.js\";\nconst createGeometryFromPositionsPositions = [];\nconst createGeometryFromPositionsSubdivided = [];\n\nfunction createGeometryFromPositions(\n ellipsoid,\n positions,\n minDistance,\n perPositionHeight,\n arcType\n) {\n const tangentPlane = EllipsoidTangentPlane.fromPoints(positions, ellipsoid);\n const positions2D = tangentPlane.projectPointsOntoPlane(\n positions,\n createGeometryFromPositionsPositions\n );\n\n const originalWindingOrder = PolygonPipeline.computeWindingOrder2D(\n positions2D\n );\n if (originalWindingOrder === WindingOrder.CLOCKWISE) {\n positions2D.reverse();\n positions = positions.slice().reverse();\n }\n\n let subdividedPositions;\n let i;\n\n let length = positions.length;\n let index = 0;\n\n if (!perPositionHeight) {\n let numVertices = 0;\n if (arcType === ArcType.GEODESIC) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideLineCount(\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n } else if (arcType === ArcType.RHUMB) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(\n ellipsoid,\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n }\n subdividedPositions = new Float64Array(numVertices * 3);\n for (i = 0; i < length; i++) {\n let tempPositions;\n if (arcType === ArcType.GEODESIC) {\n tempPositions = PolygonGeometryLibrary.subdivideLine(\n positions[i],\n positions[(i + 1) % length],\n minDistance,\n createGeometryFromPositionsSubdivided\n );\n } else if (arcType === ArcType.RHUMB) {\n tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(\n ellipsoid,\n positions[i],\n positions[(i + 1) % length],\n minDistance,\n createGeometryFromPositionsSubdivided\n );\n }\n const tempPositionsLength = tempPositions.length;\n for (let j = 0; j < tempPositionsLength; ++j) {\n subdividedPositions[index++] = tempPositions[j];\n }\n }\n } else {\n subdividedPositions = new Float64Array(length * 2 * 3);\n for (i = 0; i < length; i++) {\n const p0 = positions[i];\n const p1 = positions[(i + 1) % length];\n subdividedPositions[index++] = p0.x;\n subdividedPositions[index++] = p0.y;\n subdividedPositions[index++] = p0.z;\n subdividedPositions[index++] = p1.x;\n subdividedPositions[index++] = p1.y;\n subdividedPositions[index++] = p1.z;\n }\n }\n\n length = subdividedPositions.length / 3;\n const indicesSize = length * 2;\n const indices = IndexDatatype.createTypedArray(length, indicesSize);\n index = 0;\n for (i = 0; i < length - 1; i++) {\n indices[index++] = i;\n indices[index++] = i + 1;\n }\n indices[index++] = length - 1;\n indices[index++] = 0;\n\n return new GeometryInstance({\n geometry: new Geometry({\n attributes: new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: subdividedPositions,\n }),\n }),\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n }),\n });\n}\n\nfunction createGeometryFromPositionsExtruded(\n ellipsoid,\n positions,\n minDistance,\n perPositionHeight,\n arcType\n) {\n const tangentPlane = EllipsoidTangentPlane.fromPoints(positions, ellipsoid);\n const positions2D = tangentPlane.projectPointsOntoPlane(\n positions,\n createGeometryFromPositionsPositions\n );\n\n const originalWindingOrder = PolygonPipeline.computeWindingOrder2D(\n positions2D\n );\n if (originalWindingOrder === WindingOrder.CLOCKWISE) {\n positions2D.reverse();\n positions = positions.slice().reverse();\n }\n\n let subdividedPositions;\n let i;\n\n let length = positions.length;\n const corners = new Array(length);\n let index = 0;\n\n if (!perPositionHeight) {\n let numVertices = 0;\n if (arcType === ArcType.GEODESIC) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideLineCount(\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n } else if (arcType === ArcType.RHUMB) {\n for (i = 0; i < length; i++) {\n numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(\n ellipsoid,\n positions[i],\n positions[(i + 1) % length],\n minDistance\n );\n }\n }\n\n subdividedPositions = new Float64Array(numVertices * 3 * 2);\n for (i = 0; i < length; ++i) {\n corners[i] = index / 3;\n let tempPositions;\n if (arcType === ArcType.GEODESIC) {\n tempPositions = PolygonGeometryLibrary.subdivideLine(\n positions[i],\n positions[(i + 1) % length],\n minDistance,\n createGeometryFromPositionsSubdivided\n );\n } else if (arcType === ArcType.RHUMB) {\n tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(\n ellipsoid,\n positions[i],\n positions[(i + 1) % length],\n minDistance,\n createGeometryFromPositionsSubdivided\n );\n }\n const tempPositionsLength = tempPositions.length;\n for (let j = 0; j < tempPositionsLength; ++j) {\n subdividedPositions[index++] = tempPositions[j];\n }\n }\n } else {\n subdividedPositions = new Float64Array(length * 2 * 3 * 2);\n for (i = 0; i < length; ++i) {\n corners[i] = index / 3;\n const p0 = positions[i];\n const p1 = positions[(i + 1) % length];\n\n subdividedPositions[index++] = p0.x;\n subdividedPositions[index++] = p0.y;\n subdividedPositions[index++] = p0.z;\n subdividedPositions[index++] = p1.x;\n subdividedPositions[index++] = p1.y;\n subdividedPositions[index++] = p1.z;\n }\n }\n\n length = subdividedPositions.length / (3 * 2);\n const cornersLength = corners.length;\n\n const indicesSize = (length * 2 + cornersLength) * 2;\n const indices = IndexDatatype.createTypedArray(\n length + cornersLength,\n indicesSize\n );\n\n index = 0;\n for (i = 0; i < length; ++i) {\n indices[index++] = i;\n indices[index++] = (i + 1) % length;\n indices[index++] = i + length;\n indices[index++] = ((i + 1) % length) + length;\n }\n\n for (i = 0; i < cornersLength; i++) {\n const corner = corners[i];\n indices[index++] = corner;\n indices[index++] = corner + length;\n }\n\n return new GeometryInstance({\n geometry: new Geometry({\n attributes: new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: subdividedPositions,\n }),\n }),\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n }),\n });\n}\n\n/**\n * A description of the outline of a polygon on the ellipsoid. The polygon is defined by a polygon hierarchy.\n *\n * @alias PolygonOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.\n * @param {number} [options.height=0.0] The distance in meters between the polygon and the ellipsoid surface.\n * @param {number} [options.extrudedHeight] The distance in meters between the polygon's extruded face and the ellipsoid surface.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.\n *\n * @see PolygonOutlineGeometry#createGeometry\n * @see PolygonOutlineGeometry#fromPositions\n *\n * @example\n * // 1. create a polygon outline from points\n * const polygon = new Cesium.PolygonOutlineGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * )\n * });\n * const geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);\n *\n * // 2. create a nested polygon with holes outline\n * const polygonWithHole = new Cesium.PolygonOutlineGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -109.0, 30.0,\n * -95.0, 30.0,\n * -95.0, 40.0,\n * -109.0, 40.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -107.0, 31.0,\n * -107.0, 39.0,\n * -97.0, 39.0,\n * -97.0, 31.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -105.0, 33.0,\n * -99.0, 33.0,\n * -99.0, 37.0,\n * -105.0, 37.0\n * ]),\n * [new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -103.0, 34.0,\n * -101.0, 34.0,\n * -101.0, 36.0,\n * -103.0, 36.0\n * ])\n * )]\n * )]\n * )]\n * )\n * });\n * const geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygonWithHole);\n *\n * // 3. create extruded polygon outline\n * const extrudedPolygon = new Cesium.PolygonOutlineGeometry({\n * polygonHierarchy : new Cesium.PolygonHierarchy(\n * Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * ),\n * extrudedHeight: 300000\n * });\n * const geometry = Cesium.PolygonOutlineGeometry.createGeometry(extrudedPolygon);\n */\nfunction PolygonOutlineGeometry(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.object(\"options.polygonHierarchy\", options.polygonHierarchy);\n\n if (options.perPositionHeight && defined(options.height)) {\n throw new DeveloperError(\n \"Cannot use both options.perPositionHeight and options.height\"\n );\n }\n if (\n defined(options.arcType) &&\n options.arcType !== ArcType.GEODESIC &&\n options.arcType !== ArcType.RHUMB\n ) {\n throw new DeveloperError(\n \"Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.\"\n );\n }\n //>>includeEnd('debug');\n\n const polygonHierarchy = options.polygonHierarchy;\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const perPositionHeight = defaultValue(options.perPositionHeight, false);\n const perPositionHeightExtrude =\n perPositionHeight && defined(options.extrudedHeight);\n const arcType = defaultValue(options.arcType, ArcType.GEODESIC);\n\n let height = defaultValue(options.height, 0.0);\n let extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n if (!perPositionHeightExtrude) {\n const h = Math.max(height, extrudedHeight);\n extrudedHeight = Math.min(height, extrudedHeight);\n height = h;\n }\n\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._granularity = granularity;\n this._height = height;\n this._extrudedHeight = extrudedHeight;\n this._arcType = arcType;\n this._polygonHierarchy = polygonHierarchy;\n this._perPositionHeight = perPositionHeight;\n this._perPositionHeightExtrude = perPositionHeightExtrude;\n this._offsetAttribute = options.offsetAttribute;\n this._workerName = \"createPolygonOutlineGeometry\";\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n PolygonGeometryLibrary.computeHierarchyPackedLength(\n polygonHierarchy,\n Cartesian3\n ) +\n Ellipsoid.packedLength +\n 8;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolygonOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPolygonOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n startingIndex = PolygonGeometryLibrary.packPolygonHierarchy(\n value._polygonHierarchy,\n array,\n startingIndex,\n Cartesian3\n );\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex++] = value._height;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0;\n array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0;\n array[startingIndex++] = value._arcType;\n array[startingIndex++] = defaultValue(value._offsetAttribute, -1);\n array[startingIndex] = value.packedLength;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst dummyOptions = {\n polygonHierarchy: {},\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolygonOutlineGeometry} [result] The object into which to store the result.\n * @returns {PolygonOutlineGeometry} The modified result parameter or a new PolygonOutlineGeometry instance if one was not provided.\n */\nPolygonOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy(\n array,\n startingIndex,\n Cartesian3\n );\n startingIndex = polygonHierarchy.startingIndex;\n delete polygonHierarchy.startingIndex;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const height = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const granularity = array[startingIndex++];\n const perPositionHeightExtrude = array[startingIndex++] === 1.0;\n const perPositionHeight = array[startingIndex++] === 1.0;\n const arcType = array[startingIndex++];\n const offsetAttribute = array[startingIndex++];\n const packedLength = array[startingIndex];\n\n if (!defined(result)) {\n result = new PolygonOutlineGeometry(dummyOptions);\n }\n\n result._polygonHierarchy = polygonHierarchy;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._height = height;\n result._extrudedHeight = extrudedHeight;\n result._granularity = granularity;\n result._perPositionHeight = perPositionHeight;\n result._perPositionHeightExtrude = perPositionHeightExtrude;\n result._arcType = arcType;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n result.packedLength = packedLength;\n\n return result;\n};\n\n/**\n * A description of a polygon outline from an array of positions.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.\n * @param {number} [options.height=0.0] The height of the polygon.\n * @param {number} [options.extrudedHeight] The height of the polygon extrusion.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link LinkType.GEODESIC} and {@link ArcType.RHUMB}.\n * @returns {PolygonOutlineGeometry}\n *\n *\n * @example\n * // create a polygon from points\n * const polygon = Cesium.PolygonOutlineGeometry.fromPositions({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0,\n * -75.0, 30.0,\n * -70.0, 30.0,\n * -68.0, 40.0\n * ])\n * });\n * const geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);\n *\n * @see PolygonOutlineGeometry#createGeometry\n */\nPolygonOutlineGeometry.fromPositions = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"options.positions\", options.positions);\n //>>includeEnd('debug');\n\n const newOptions = {\n polygonHierarchy: {\n positions: options.positions,\n },\n height: options.height,\n extrudedHeight: options.extrudedHeight,\n ellipsoid: options.ellipsoid,\n granularity: options.granularity,\n perPositionHeight: options.perPositionHeight,\n arcType: options.arcType,\n offsetAttribute: options.offsetAttribute,\n };\n return new PolygonOutlineGeometry(newOptions);\n};\n\n/**\n * Computes the geometric representation of a polygon outline, including its vertices, indices, and a bounding sphere.\n *\n * @param {PolygonOutlineGeometry} polygonGeometry A description of the polygon outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPolygonOutlineGeometry.createGeometry = function (polygonGeometry) {\n const ellipsoid = polygonGeometry._ellipsoid;\n const granularity = polygonGeometry._granularity;\n const polygonHierarchy = polygonGeometry._polygonHierarchy;\n const perPositionHeight = polygonGeometry._perPositionHeight;\n const arcType = polygonGeometry._arcType;\n\n const polygons = PolygonGeometryLibrary.polygonOutlinesFromHierarchy(\n polygonHierarchy,\n !perPositionHeight,\n ellipsoid\n );\n\n if (polygons.length === 0) {\n return undefined;\n }\n\n let geometryInstance;\n const geometries = [];\n const minDistance = CesiumMath.chordLength(\n granularity,\n ellipsoid.maximumRadius\n );\n\n const height = polygonGeometry._height;\n const extrudedHeight = polygonGeometry._extrudedHeight;\n const extrude =\n polygonGeometry._perPositionHeightExtrude ||\n !CesiumMath.equalsEpsilon(height, extrudedHeight, 0, CesiumMath.EPSILON2);\n let offsetValue;\n let i;\n if (extrude) {\n for (i = 0; i < polygons.length; i++) {\n geometryInstance = createGeometryFromPositionsExtruded(\n ellipsoid,\n polygons[i],\n minDistance,\n perPositionHeight,\n arcType\n );\n geometryInstance.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(\n geometryInstance.geometry,\n height,\n extrudedHeight,\n ellipsoid,\n perPositionHeight\n );\n if (defined(polygonGeometry._offsetAttribute)) {\n const size =\n geometryInstance.geometry.attributes.position.values.length / 3;\n let offsetAttribute = new Uint8Array(size);\n if (polygonGeometry._offsetAttribute === GeometryOffsetAttribute.TOP) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else {\n offsetValue =\n polygonGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n\n geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute(\n {\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n }\n );\n }\n geometries.push(geometryInstance);\n }\n } else {\n for (i = 0; i < polygons.length; i++) {\n geometryInstance = createGeometryFromPositions(\n ellipsoid,\n polygons[i],\n minDistance,\n perPositionHeight,\n arcType\n );\n geometryInstance.geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n geometryInstance.geometry.attributes.position.values,\n height,\n ellipsoid,\n !perPositionHeight\n );\n\n if (defined(polygonGeometry._offsetAttribute)) {\n const length =\n geometryInstance.geometry.attributes.position.values.length;\n offsetValue =\n polygonGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute(\n {\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n }\n );\n }\n\n geometries.push(geometryInstance);\n }\n }\n\n const geometry = GeometryPipeline.combineInstances(geometries)[0];\n const boundingSphere = BoundingSphere.fromVertices(\n geometry.attributes.position.values\n );\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: boundingSphere,\n offsetAttribute: polygonGeometry._offsetAttribute,\n });\n};\nexport default PolygonOutlineGeometry;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport ArcType from \"../Core/ArcType.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport CoplanarPolygonGeometry from \"../Core/CoplanarPolygonGeometry.js\";\nimport CoplanarPolygonOutlineGeometry from \"../Core/CoplanarPolygonOutlineGeometry.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport EllipsoidTangentPlane from \"../Core/EllipsoidTangentPlane.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport PolygonGeometry from \"../Core/PolygonGeometry.js\";\nimport PolygonOutlineGeometry from \"../Core/PolygonOutlineGeometry.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport GroundGeometryUpdater from \"./GroundGeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst heightAndPerPositionHeightWarning =\n \"Entity polygons cannot have both height and perPositionHeight. height will be ignored\";\nconst heightReferenceAndPerPositionHeightWarning =\n \"heightReference is not supported for entity polygons with perPositionHeight. heightReference will be ignored\";\n\nconst scratchColor = new Color();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\nconst scratchRectangle = new Rectangle();\nconst scratch2DPositions = [];\nconst cart2Scratch = new Cartesian2();\n\nfunction PolygonGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.polygonHierarchy = undefined;\n this.perPositionHeight = undefined;\n this.closeTop = undefined;\n this.closeBottom = undefined;\n this.height = undefined;\n this.extrudedHeight = undefined;\n this.granularity = undefined;\n this.stRotation = undefined;\n this.offsetAttribute = undefined;\n this.arcType = undefined;\n this.textureCoordinates = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for polygons.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias PolygonGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction PolygonGeometryUpdater(entity, scene) {\n GroundGeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new PolygonGeometryOptions(entity),\n geometryPropertyName: \"polygon\",\n observedPropertyNames: [\"availability\", \"polygon\"],\n });\n\n this._onEntityPropertyChanged(entity, \"polygon\", entity.polygon, undefined);\n}\n\nif (defined(Object.create)) {\n PolygonGeometryUpdater.prototype = Object.create(\n GroundGeometryUpdater.prototype\n );\n PolygonGeometryUpdater.prototype.constructor = PolygonGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nPolygonGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const options = this._options;\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n ),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n this._distanceDisplayConditionProperty.getValue(time)\n ),\n offset: undefined,\n color: undefined,\n };\n\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n if (defined(options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n let geometry;\n if (options.perPositionHeight && !defined(options.extrudedHeight)) {\n geometry = new CoplanarPolygonGeometry(options);\n } else {\n geometry = new PolygonGeometry(options);\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: geometry,\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nPolygonGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const options = this._options;\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n\n if (defined(options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n let geometry;\n if (options.perPositionHeight && !defined(options.extrudedHeight)) {\n geometry = new CoplanarPolygonOutlineGeometry(options);\n } else {\n geometry = new PolygonOutlineGeometry(options);\n }\n return new GeometryInstance({\n id: entity,\n geometry: geometry,\n attributes: attributes,\n });\n};\n\nPolygonGeometryUpdater.prototype._computeCenter = function (time, result) {\n const hierarchy = Property.getValueOrUndefined(\n this._entity.polygon.hierarchy,\n time\n );\n if (!defined(hierarchy)) {\n return;\n }\n const positions = hierarchy.positions;\n if (positions.length === 0) {\n return;\n }\n const ellipsoid = this._scene.mapProjection.ellipsoid;\n\n const tangentPlane = EllipsoidTangentPlane.fromPoints(positions, ellipsoid);\n const positions2D = tangentPlane.projectPointsOntoPlane(\n positions,\n scratch2DPositions\n );\n\n const length = positions2D.length;\n let area = 0;\n let j = length - 1;\n let centroid2D = new Cartesian2();\n for (let i = 0; i < length; j = i++) {\n const p1 = positions2D[i];\n const p2 = positions2D[j];\n const f = p1.x * p2.y - p2.x * p1.y;\n\n let sum = Cartesian2.add(p1, p2, cart2Scratch);\n sum = Cartesian2.multiplyByScalar(sum, f, sum);\n centroid2D = Cartesian2.add(centroid2D, sum, centroid2D);\n\n area += f;\n }\n\n const a = 1.0 / (area * 3.0);\n centroid2D = Cartesian2.multiplyByScalar(centroid2D, a, centroid2D);\n return tangentPlane.projectPointOntoEllipsoid(centroid2D, result);\n};\n\nPolygonGeometryUpdater.prototype._isHidden = function (entity, polygon) {\n return (\n !defined(polygon.hierarchy) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, polygon)\n );\n};\n\nPolygonGeometryUpdater.prototype._isOnTerrain = function (entity, polygon) {\n const onTerrain = GroundGeometryUpdater.prototype._isOnTerrain.call(\n this,\n entity,\n polygon\n );\n const perPositionHeightProperty = polygon.perPositionHeight;\n const perPositionHeightEnabled =\n defined(perPositionHeightProperty) &&\n (perPositionHeightProperty.isConstant\n ? perPositionHeightProperty.getValue(Iso8601.MINIMUM_VALUE)\n : true);\n return onTerrain && !perPositionHeightEnabled;\n};\n\nPolygonGeometryUpdater.prototype._isDynamic = function (entity, polygon) {\n return (\n !polygon.hierarchy.isConstant || //\n !Property.isConstant(polygon.height) || //\n !Property.isConstant(polygon.extrudedHeight) || //\n !Property.isConstant(polygon.granularity) || //\n !Property.isConstant(polygon.stRotation) || //\n !Property.isConstant(polygon.textureCoordinates) || //\n !Property.isConstant(polygon.outlineWidth) || //\n !Property.isConstant(polygon.perPositionHeight) || //\n !Property.isConstant(polygon.closeTop) || //\n !Property.isConstant(polygon.closeBottom) || //\n !Property.isConstant(polygon.zIndex) || //\n !Property.isConstant(polygon.arcType) || //\n (this._onTerrain &&\n !Property.isConstant(this._materialProperty) &&\n !(this._materialProperty instanceof ColorMaterialProperty))\n );\n};\n\nPolygonGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n polygon\n) {\n const isColorMaterial =\n this._materialProperty instanceof ColorMaterialProperty;\n\n const options = this._options;\n options.vertexFormat = isColorMaterial\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n\n const hierarchyValue = polygon.hierarchy.getValue(Iso8601.MINIMUM_VALUE);\n let heightValue = Property.getValueOrUndefined(\n polygon.height,\n Iso8601.MINIMUM_VALUE\n );\n const heightReferenceValue = Property.getValueOrDefault(\n polygon.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n polygon.extrudedHeight,\n Iso8601.MINIMUM_VALUE\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n polygon.extrudedHeightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n const perPositionHeightValue = Property.getValueOrDefault(\n polygon.perPositionHeight,\n Iso8601.MINIMUM_VALUE,\n false\n );\n\n heightValue = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n let offsetAttribute;\n if (perPositionHeightValue) {\n if (defined(heightValue)) {\n heightValue = undefined;\n oneTimeWarning(heightAndPerPositionHeightWarning);\n }\n if (\n heightReferenceValue !== HeightReference.NONE &&\n perPositionHeightValue\n ) {\n heightValue = undefined;\n oneTimeWarning(heightReferenceAndPerPositionHeightWarning);\n }\n } else {\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n }\n\n options.polygonHierarchy = hierarchyValue;\n options.granularity = Property.getValueOrUndefined(\n polygon.granularity,\n Iso8601.MINIMUM_VALUE\n );\n options.stRotation = Property.getValueOrUndefined(\n polygon.stRotation,\n Iso8601.MINIMUM_VALUE\n );\n options.perPositionHeight = perPositionHeightValue;\n options.closeTop = Property.getValueOrDefault(\n polygon.closeTop,\n Iso8601.MINIMUM_VALUE,\n true\n );\n options.closeBottom = Property.getValueOrDefault(\n polygon.closeBottom,\n Iso8601.MINIMUM_VALUE,\n true\n );\n options.offsetAttribute = offsetAttribute;\n options.height = heightValue;\n options.arcType = Property.getValueOrDefault(\n polygon.arcType,\n Iso8601.MINIMUM_VALUE,\n ArcType.GEODESIC\n );\n options.textureCoordinates = Property.getValueOrUndefined(\n polygon.textureCoordinates,\n Iso8601.MINIMUM_VALUE\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n PolygonGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\n\nPolygonGeometryUpdater.prototype._getIsClosed = function (options) {\n const height = options.height;\n const extrudedHeight = options.extrudedHeight;\n const isExtruded = defined(extrudedHeight) && extrudedHeight !== height;\n return (\n !options.perPositionHeight &&\n ((!isExtruded && height === 0) ||\n (isExtruded && options.closeTop && options.closeBottom))\n );\n};\n\nPolygonGeometryUpdater.DynamicGeometryUpdater = DyanmicPolygonGeometryUpdater;\n\n/**\n * @private\n */\nfunction DyanmicPolygonGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DyanmicPolygonGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DyanmicPolygonGeometryUpdater.prototype.constructor = DyanmicPolygonGeometryUpdater;\n}\n\nDyanmicPolygonGeometryUpdater.prototype._isHidden = function (\n entity,\n polygon,\n time\n) {\n return (\n !defined(this._options.polygonHierarchy) ||\n DynamicGeometryUpdater.prototype._isHidden.call(this, entity, polygon, time)\n );\n};\n\nDyanmicPolygonGeometryUpdater.prototype._setOptions = function (\n entity,\n polygon,\n time\n) {\n const options = this._options;\n\n options.polygonHierarchy = Property.getValueOrUndefined(\n polygon.hierarchy,\n time\n );\n\n let heightValue = Property.getValueOrUndefined(polygon.height, time);\n const heightReferenceValue = Property.getValueOrDefault(\n polygon.heightReference,\n time,\n HeightReference.NONE\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n polygon.extrudedHeightReference,\n time,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n polygon.extrudedHeight,\n time\n );\n const perPositionHeightValue = Property.getValueOrUndefined(\n polygon.perPositionHeight,\n time\n );\n\n heightValue = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n extrudedHeightReferenceValue\n );\n\n let offsetAttribute;\n if (perPositionHeightValue) {\n if (defined(heightValue)) {\n heightValue = undefined;\n oneTimeWarning(heightAndPerPositionHeightWarning);\n }\n if (\n heightReferenceValue !== HeightReference.NONE &&\n perPositionHeightValue\n ) {\n heightValue = undefined;\n oneTimeWarning(heightReferenceAndPerPositionHeightWarning);\n }\n } else {\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n }\n\n options.granularity = Property.getValueOrUndefined(polygon.granularity, time);\n options.stRotation = Property.getValueOrUndefined(polygon.stRotation, time);\n options.textureCoordinates = Property.getValueOrUndefined(\n polygon.textureCoordinates,\n time\n );\n options.perPositionHeight = Property.getValueOrUndefined(\n polygon.perPositionHeight,\n time\n );\n options.closeTop = Property.getValueOrDefault(polygon.closeTop, time, true);\n options.closeBottom = Property.getValueOrDefault(\n polygon.closeBottom,\n time,\n true\n );\n options.offsetAttribute = offsetAttribute;\n options.height = heightValue;\n options.arcType = Property.getValueOrDefault(\n polygon.arcType,\n time,\n ArcType.GEODESIC\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n PolygonGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\nexport default PolygonGeometryUpdater;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingRectangle from \"./BoundingRectangle.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CornerType from \"./CornerType.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport oneTimeWarning from \"./oneTimeWarning.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PolylineVolumeGeometryLibrary from \"./PolylineVolumeGeometryLibrary.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\nimport WindingOrder from \"./WindingOrder.js\";\n\nfunction computeAttributes(\n combinedPositions,\n shape,\n boundingRectangle,\n vertexFormat\n) {\n const attributes = new GeometryAttributes();\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: combinedPositions,\n });\n }\n const shapeLength = shape.length;\n const vertexCount = combinedPositions.length / 3;\n const length = (vertexCount - shapeLength * 2) / (shapeLength * 2);\n const firstEndIndices = PolygonPipeline.triangulate(shape);\n\n const indicesCount =\n (length - 1) * shapeLength * 6 + firstEndIndices.length * 2;\n const indices = IndexDatatype.createTypedArray(vertexCount, indicesCount);\n let i, j;\n let ll, ul, ur, lr;\n const offset = shapeLength * 2;\n let index = 0;\n for (i = 0; i < length - 1; i++) {\n for (j = 0; j < shapeLength - 1; j++) {\n ll = j * 2 + i * shapeLength * 2;\n lr = ll + offset;\n ul = ll + 1;\n ur = ul + offset;\n\n indices[index++] = ul;\n indices[index++] = ll;\n indices[index++] = ur;\n indices[index++] = ur;\n indices[index++] = ll;\n indices[index++] = lr;\n }\n ll = shapeLength * 2 - 2 + i * shapeLength * 2;\n ul = ll + 1;\n ur = ul + offset;\n lr = ll + offset;\n\n indices[index++] = ul;\n indices[index++] = ll;\n indices[index++] = ur;\n indices[index++] = ur;\n indices[index++] = ll;\n indices[index++] = lr;\n }\n\n if (vertexFormat.st || vertexFormat.tangent || vertexFormat.bitangent) {\n // st required for tangent/bitangent calculation\n const st = new Float32Array(vertexCount * 2);\n const lengthSt = 1 / (length - 1);\n const heightSt = 1 / boundingRectangle.height;\n const heightOffset = boundingRectangle.height / 2;\n let s, t;\n let stindex = 0;\n for (i = 0; i < length; i++) {\n s = i * lengthSt;\n t = heightSt * (shape[0].y + heightOffset);\n st[stindex++] = s;\n st[stindex++] = t;\n for (j = 1; j < shapeLength; j++) {\n t = heightSt * (shape[j].y + heightOffset);\n st[stindex++] = s;\n st[stindex++] = t;\n st[stindex++] = s;\n st[stindex++] = t;\n }\n t = heightSt * (shape[0].y + heightOffset);\n st[stindex++] = s;\n st[stindex++] = t;\n }\n for (j = 0; j < shapeLength; j++) {\n s = 0;\n t = heightSt * (shape[j].y + heightOffset);\n st[stindex++] = s;\n st[stindex++] = t;\n }\n for (j = 0; j < shapeLength; j++) {\n s = (length - 1) * lengthSt;\n t = heightSt * (shape[j].y + heightOffset);\n st[stindex++] = s;\n st[stindex++] = t;\n }\n\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: new Float32Array(st),\n });\n }\n\n const endOffset = vertexCount - shapeLength * 2;\n for (i = 0; i < firstEndIndices.length; i += 3) {\n const v0 = firstEndIndices[i] + endOffset;\n const v1 = firstEndIndices[i + 1] + endOffset;\n const v2 = firstEndIndices[i + 2] + endOffset;\n\n indices[index++] = v0;\n indices[index++] = v1;\n indices[index++] = v2;\n indices[index++] = v2 + shapeLength;\n indices[index++] = v1 + shapeLength;\n indices[index++] = v0 + shapeLength;\n }\n\n let geometry = new Geometry({\n attributes: attributes,\n indices: indices,\n boundingSphere: BoundingSphere.fromVertices(combinedPositions),\n primitiveType: PrimitiveType.TRIANGLES,\n });\n\n if (vertexFormat.normal) {\n geometry = GeometryPipeline.computeNormal(geometry);\n }\n\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n try {\n geometry = GeometryPipeline.computeTangentAndBitangent(geometry);\n } catch (e) {\n oneTimeWarning(\n \"polyline-volume-tangent-bitangent\",\n \"Unable to compute tangents and bitangents for polyline volume geometry\"\n );\n //TODO https://github.com/CesiumGS/cesium/issues/3609\n }\n\n if (!vertexFormat.tangent) {\n geometry.attributes.tangent = undefined;\n }\n if (!vertexFormat.bitangent) {\n geometry.attributes.bitangent = undefined;\n }\n if (!vertexFormat.st) {\n geometry.attributes.st = undefined;\n }\n }\n\n return geometry;\n}\n\n/**\n * A description of a polyline with a volume (a 2D shape extruded along a polyline).\n *\n * @alias PolylineVolumeGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.polylinePositions An array of {@link Cartesian3} positions that define the center of the polyline volume.\n * @param {Cartesian2[]} options.shapePositions An array of {@link Cartesian2} positions that define the shape to be extruded along the polyline\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.\n *\n * @see PolylineVolumeGeometry#createGeometry\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline%20Volume.html|Cesium Sandcastle Polyline Volume Demo}\n *\n * @example\n * function computeCircle(radius) {\n * const positions = [];\n * for (let i = 0; i < 360; i++) {\n * const radians = Cesium.Math.toRadians(i);\n * positions.push(new Cesium.Cartesian2(radius * Math.cos(radians), radius * Math.sin(radians)));\n * }\n * return positions;\n * }\n *\n * const volume = new Cesium.PolylineVolumeGeometry({\n * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,\n * polylinePositions : Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0\n * ]),\n * shapePositions : computeCircle(100000.0)\n * });\n */\nfunction PolylineVolumeGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.polylinePositions;\n const shape = options.shapePositions;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.polylinePositions is required.\");\n }\n if (!defined(shape)) {\n throw new DeveloperError(\"options.shapePositions is required.\");\n }\n //>>includeEnd('debug');\n\n this._positions = positions;\n this._shape = shape;\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);\n this._vertexFormat = VertexFormat.clone(\n defaultValue(options.vertexFormat, VertexFormat.DEFAULT)\n );\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._workerName = \"createPolylineVolumeGeometry\";\n\n let numComponents = 1 + positions.length * Cartesian3.packedLength;\n numComponents += 1 + shape.length * Cartesian2.packedLength;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 2;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolylineVolumeGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPolylineVolumeGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n const positions = value._positions;\n let length = positions.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n const shape = value._shape;\n length = shape.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) {\n Cartesian2.pack(shape[i], array, startingIndex);\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._cornerType;\n array[startingIndex] = value._granularity;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n polylinePositions: undefined,\n shapePositions: undefined,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n cornerType: undefined,\n granularity: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolylineVolumeGeometry} [result] The object into which to store the result.\n * @returns {PolylineVolumeGeometry} The modified result parameter or a new PolylineVolumeGeometry instance if one was not provided.\n */\nPolylineVolumeGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n let length = array[startingIndex++];\n const positions = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n length = array[startingIndex++];\n const shape = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) {\n shape[i] = Cartesian2.unpack(array, startingIndex);\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const cornerType = array[startingIndex++];\n const granularity = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.polylinePositions = positions;\n scratchOptions.shapePositions = shape;\n scratchOptions.cornerType = cornerType;\n scratchOptions.granularity = granularity;\n return new PolylineVolumeGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._shape = shape;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._cornerType = cornerType;\n result._granularity = granularity;\n\n return result;\n};\n\nconst brScratch = new BoundingRectangle();\n\n/**\n * Computes the geometric representation of a polyline with a volume, including its vertices, indices, and a bounding sphere.\n *\n * @param {PolylineVolumeGeometry} polylineVolumeGeometry A description of the polyline volume.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPolylineVolumeGeometry.createGeometry = function (polylineVolumeGeometry) {\n const positions = polylineVolumeGeometry._positions;\n const cleanPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n let shape2D = polylineVolumeGeometry._shape;\n shape2D = PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);\n\n if (cleanPositions.length < 2 || shape2D.length < 3) {\n return undefined;\n }\n\n if (\n PolygonPipeline.computeWindingOrder2D(shape2D) === WindingOrder.CLOCKWISE\n ) {\n shape2D.reverse();\n }\n const boundingRectangle = BoundingRectangle.fromPoints(shape2D, brScratch);\n\n const computedPositions = PolylineVolumeGeometryLibrary.computePositions(\n cleanPositions,\n shape2D,\n boundingRectangle,\n polylineVolumeGeometry,\n true\n );\n return computeAttributes(\n computedPositions,\n shape2D,\n boundingRectangle,\n polylineVolumeGeometry._vertexFormat\n );\n};\nexport default PolylineVolumeGeometry;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingRectangle from \"./BoundingRectangle.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport CornerType from \"./CornerType.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PolylineVolumeGeometryLibrary from \"./PolylineVolumeGeometryLibrary.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport WindingOrder from \"./WindingOrder.js\";\n\nfunction computeAttributes(positions, shape) {\n const attributes = new GeometryAttributes();\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n\n const shapeLength = shape.length;\n const vertexCount = attributes.position.values.length / 3;\n const positionLength = positions.length / 3;\n const shapeCount = positionLength / shapeLength;\n const indices = IndexDatatype.createTypedArray(\n vertexCount,\n 2 * shapeLength * (shapeCount + 1)\n );\n let i, j;\n let index = 0;\n i = 0;\n let offset = i * shapeLength;\n for (j = 0; j < shapeLength - 1; j++) {\n indices[index++] = j + offset;\n indices[index++] = j + offset + 1;\n }\n indices[index++] = shapeLength - 1 + offset;\n indices[index++] = offset;\n\n i = shapeCount - 1;\n offset = i * shapeLength;\n for (j = 0; j < shapeLength - 1; j++) {\n indices[index++] = j + offset;\n indices[index++] = j + offset + 1;\n }\n indices[index++] = shapeLength - 1 + offset;\n indices[index++] = offset;\n\n for (i = 0; i < shapeCount - 1; i++) {\n const firstOffset = shapeLength * i;\n const secondOffset = firstOffset + shapeLength;\n for (j = 0; j < shapeLength; j++) {\n indices[index++] = j + firstOffset;\n indices[index++] = j + secondOffset;\n }\n }\n\n const geometry = new Geometry({\n attributes: attributes,\n indices: IndexDatatype.createTypedArray(vertexCount, indices),\n boundingSphere: BoundingSphere.fromVertices(positions),\n primitiveType: PrimitiveType.LINES,\n });\n\n return geometry;\n}\n\n/**\n * A description of a polyline with a volume (a 2D shape extruded along a polyline).\n *\n * @alias PolylineVolumeOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.polylinePositions An array of positions that define the center of the polyline volume.\n * @param {Cartesian2[]} options.shapePositions An array of positions that define the shape to be extruded along the polyline\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {CornerType} [options.cornerType=CornerType.ROUNDED] Determines the style of the corners.\n *\n * @see PolylineVolumeOutlineGeometry#createGeometry\n *\n * @example\n * function computeCircle(radius) {\n * const positions = [];\n * for (let i = 0; i < 360; i++) {\n * const radians = Cesium.Math.toRadians(i);\n * positions.push(new Cesium.Cartesian2(radius * Math.cos(radians), radius * Math.sin(radians)));\n * }\n * return positions;\n * }\n *\n * const volumeOutline = new Cesium.PolylineVolumeOutlineGeometry({\n * polylinePositions : Cesium.Cartesian3.fromDegreesArray([\n * -72.0, 40.0,\n * -70.0, 35.0\n * ]),\n * shapePositions : computeCircle(100000.0)\n * });\n */\nfunction PolylineVolumeOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.polylinePositions;\n const shape = options.shapePositions;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.polylinePositions is required.\");\n }\n if (!defined(shape)) {\n throw new DeveloperError(\"options.shapePositions is required.\");\n }\n //>>includeEnd('debug');\n\n this._positions = positions;\n this._shape = shape;\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED);\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._workerName = \"createPolylineVolumeOutlineGeometry\";\n\n let numComponents = 1 + positions.length * Cartesian3.packedLength;\n numComponents += 1 + shape.length * Cartesian2.packedLength;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength = numComponents + Ellipsoid.packedLength + 2;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolylineVolumeOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPolylineVolumeOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n const positions = value._positions;\n let length = positions.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n const shape = value._shape;\n length = shape.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) {\n Cartesian2.pack(shape[i], array, startingIndex);\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex++] = value._cornerType;\n array[startingIndex] = value._granularity;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchOptions = {\n polylinePositions: undefined,\n shapePositions: undefined,\n ellipsoid: scratchEllipsoid,\n height: undefined,\n cornerType: undefined,\n granularity: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolylineVolumeOutlineGeometry} [result] The object into which to store the result.\n * @returns {PolylineVolumeOutlineGeometry} The modified result parameter or a new PolylineVolumeOutlineGeometry instance if one was not provided.\n */\nPolylineVolumeOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n let length = array[startingIndex++];\n const positions = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n length = array[startingIndex++];\n const shape = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian2.packedLength) {\n shape[i] = Cartesian2.unpack(array, startingIndex);\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const cornerType = array[startingIndex++];\n const granularity = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.polylinePositions = positions;\n scratchOptions.shapePositions = shape;\n scratchOptions.cornerType = cornerType;\n scratchOptions.granularity = granularity;\n return new PolylineVolumeOutlineGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._shape = shape;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._cornerType = cornerType;\n result._granularity = granularity;\n\n return result;\n};\n\nconst brScratch = new BoundingRectangle();\n\n/**\n * Computes the geometric representation of the outline of a polyline with a volume, including its vertices, indices, and a bounding sphere.\n *\n * @param {PolylineVolumeOutlineGeometry} polylineVolumeOutlineGeometry A description of the polyline volume outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPolylineVolumeOutlineGeometry.createGeometry = function (\n polylineVolumeOutlineGeometry\n) {\n const positions = polylineVolumeOutlineGeometry._positions;\n const cleanPositions = arrayRemoveDuplicates(\n positions,\n Cartesian3.equalsEpsilon\n );\n let shape2D = polylineVolumeOutlineGeometry._shape;\n shape2D = PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);\n\n if (cleanPositions.length < 2 || shape2D.length < 3) {\n return undefined;\n }\n\n if (\n PolygonPipeline.computeWindingOrder2D(shape2D) === WindingOrder.CLOCKWISE\n ) {\n shape2D.reverse();\n }\n const boundingRectangle = BoundingRectangle.fromPoints(shape2D, brScratch);\n\n const computedPositions = PolylineVolumeGeometryLibrary.computePositions(\n cleanPositions,\n shape2D,\n boundingRectangle,\n polylineVolumeOutlineGeometry,\n false\n );\n return computeAttributes(computedPositions, shape2D);\n};\nexport default PolylineVolumeOutlineGeometry;\n", "import Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport PolylineVolumeGeometry from \"../Core/PolylineVolumeGeometry.js\";\nimport PolylineVolumeOutlineGeometry from \"../Core/PolylineVolumeOutlineGeometry.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\n\nfunction PolylineVolumeGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.polylinePositions = undefined;\n this.shapePositions = undefined;\n this.cornerType = undefined;\n this.granularity = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for polyline volumes.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias PolylineVolumeGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction PolylineVolumeGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new PolylineVolumeGeometryOptions(entity),\n geometryPropertyName: \"polylineVolume\",\n observedPropertyNames: [\"availability\", \"polylineVolume\"],\n });\n\n this._onEntityPropertyChanged(\n entity,\n \"polylineVolume\",\n entity.polylineVolume,\n undefined\n );\n}\n\nif (defined(Object.create)) {\n PolylineVolumeGeometryUpdater.prototype = Object.create(\n GeometryUpdater.prototype\n );\n PolylineVolumeGeometryUpdater.prototype.constructor = PolylineVolumeGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nPolylineVolumeGeometryUpdater.prototype.createFillGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n let attributes;\n\n let color;\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: color,\n };\n } else {\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n };\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new PolylineVolumeGeometry(this._options),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nPolylineVolumeGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n return new GeometryInstance({\n id: entity,\n geometry: new PolylineVolumeOutlineGeometry(this._options),\n attributes: {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n },\n });\n};\n\nPolylineVolumeGeometryUpdater.prototype._isHidden = function (\n entity,\n polylineVolume\n) {\n return (\n !defined(polylineVolume.positions) ||\n !defined(polylineVolume.shape) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume)\n );\n};\n\nPolylineVolumeGeometryUpdater.prototype._isDynamic = function (\n entity,\n polylineVolume\n) {\n return (\n !polylineVolume.positions.isConstant || //\n !polylineVolume.shape.isConstant || //\n !Property.isConstant(polylineVolume.granularity) || //\n !Property.isConstant(polylineVolume.outlineWidth) || //\n !Property.isConstant(polylineVolume.cornerType)\n );\n};\n\nPolylineVolumeGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n polylineVolume\n) {\n const granularity = polylineVolume.granularity;\n const cornerType = polylineVolume.cornerType;\n\n const options = this._options;\n const isColorMaterial =\n this._materialProperty instanceof ColorMaterialProperty;\n options.vertexFormat = isColorMaterial\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.polylinePositions = polylineVolume.positions.getValue(\n Iso8601.MINIMUM_VALUE,\n options.polylinePositions\n );\n options.shapePositions = polylineVolume.shape.getValue(\n Iso8601.MINIMUM_VALUE,\n options.shape\n );\n options.granularity = defined(granularity)\n ? granularity.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n options.cornerType = defined(cornerType)\n ? cornerType.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n};\n\nPolylineVolumeGeometryUpdater.DynamicGeometryUpdater = DynamicPolylineVolumeGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicPolylineVolumeGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicPolylineVolumeGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicPolylineVolumeGeometryUpdater.prototype.constructor = DynamicPolylineVolumeGeometryUpdater;\n}\n\nDynamicPolylineVolumeGeometryUpdater.prototype._isHidden = function (\n entity,\n polylineVolume,\n time\n) {\n const options = this._options;\n return (\n !defined(options.polylinePositions) ||\n !defined(options.shapePositions) ||\n DynamicGeometryUpdater.prototype._isHidden.call(\n this,\n entity,\n polylineVolume,\n time\n )\n );\n};\n\nDynamicPolylineVolumeGeometryUpdater.prototype._setOptions = function (\n entity,\n polylineVolume,\n time\n) {\n const options = this._options;\n options.polylinePositions = Property.getValueOrUndefined(\n polylineVolume.positions,\n time,\n options.polylinePositions\n );\n options.shapePositions = Property.getValueOrUndefined(\n polylineVolume.shape,\n time\n );\n options.granularity = Property.getValueOrUndefined(\n polylineVolume.granularity,\n time\n );\n options.cornerType = Property.getValueOrUndefined(\n polylineVolume.cornerType,\n time\n );\n};\nexport default PolylineVolumeGeometryUpdater;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport Check from \"./Check.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryInstance from \"./GeometryInstance.js\";\nimport GeometryOffsetAttribute from \"./GeometryOffsetAttribute.js\";\nimport GeometryPipeline from \"./GeometryPipeline.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport Matrix2 from \"./Matrix2.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport PolygonPipeline from \"./PolygonPipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport Quaternion from \"./Quaternion.js\";\nimport Rectangle from \"./Rectangle.js\";\nimport RectangleGeometryLibrary from \"./RectangleGeometryLibrary.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst positionScratch = new Cartesian3();\nconst normalScratch = new Cartesian3();\nconst tangentScratch = new Cartesian3();\nconst bitangentScratch = new Cartesian3();\nconst rectangleScratch = new Rectangle();\nconst stScratch = new Cartesian2();\nconst bottomBoundingSphere = new BoundingSphere();\nconst topBoundingSphere = new BoundingSphere();\n\nfunction createAttributes(vertexFormat, attributes) {\n const geo = new Geometry({\n attributes: new GeometryAttributes(),\n primitiveType: PrimitiveType.TRIANGLES,\n });\n\n geo.attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: attributes.positions,\n });\n if (vertexFormat.normal) {\n geo.attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attributes.normals,\n });\n }\n if (vertexFormat.tangent) {\n geo.attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attributes.tangents,\n });\n }\n if (vertexFormat.bitangent) {\n geo.attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: attributes.bitangents,\n });\n }\n return geo;\n}\n\nfunction calculateAttributes(\n positions,\n vertexFormat,\n ellipsoid,\n tangentRotationMatrix\n) {\n const length = positions.length;\n\n const normals = vertexFormat.normal ? new Float32Array(length) : undefined;\n const tangents = vertexFormat.tangent ? new Float32Array(length) : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(length)\n : undefined;\n\n let attrIndex = 0;\n const bitangent = bitangentScratch;\n const tangent = tangentScratch;\n let normal = normalScratch;\n if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {\n for (let i = 0; i < length; i += 3) {\n const p = Cartesian3.fromArray(positions, i, positionScratch);\n const attrIndex1 = attrIndex + 1;\n const attrIndex2 = attrIndex + 2;\n\n normal = ellipsoid.geodeticSurfaceNormal(p, normal);\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent);\n Matrix3.multiplyByVector(tangentRotationMatrix, tangent, tangent);\n Cartesian3.normalize(tangent, tangent);\n\n if (vertexFormat.bitangent) {\n Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n }\n }\n\n if (vertexFormat.normal) {\n normals[attrIndex] = normal.x;\n normals[attrIndex1] = normal.y;\n normals[attrIndex2] = normal.z;\n }\n if (vertexFormat.tangent) {\n tangents[attrIndex] = tangent.x;\n tangents[attrIndex1] = tangent.y;\n tangents[attrIndex2] = tangent.z;\n }\n if (vertexFormat.bitangent) {\n bitangents[attrIndex] = bitangent.x;\n bitangents[attrIndex1] = bitangent.y;\n bitangents[attrIndex2] = bitangent.z;\n }\n attrIndex += 3;\n }\n }\n return createAttributes(vertexFormat, {\n positions: positions,\n normals: normals,\n tangents: tangents,\n bitangents: bitangents,\n });\n}\n\nconst v1Scratch = new Cartesian3();\nconst v2Scratch = new Cartesian3();\n\nfunction calculateAttributesWall(positions, vertexFormat, ellipsoid) {\n const length = positions.length;\n\n const normals = vertexFormat.normal ? new Float32Array(length) : undefined;\n const tangents = vertexFormat.tangent ? new Float32Array(length) : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(length)\n : undefined;\n\n let normalIndex = 0;\n let tangentIndex = 0;\n let bitangentIndex = 0;\n let recomputeNormal = true;\n\n let bitangent = bitangentScratch;\n let tangent = tangentScratch;\n let normal = normalScratch;\n if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {\n for (let i = 0; i < length; i += 6) {\n const p = Cartesian3.fromArray(positions, i, positionScratch);\n const p1 = Cartesian3.fromArray(positions, (i + 6) % length, v1Scratch);\n if (recomputeNormal) {\n const p2 = Cartesian3.fromArray(positions, (i + 3) % length, v2Scratch);\n Cartesian3.subtract(p1, p, p1);\n Cartesian3.subtract(p2, p, p2);\n normal = Cartesian3.normalize(Cartesian3.cross(p2, p1, normal), normal);\n recomputeNormal = false;\n }\n\n if (Cartesian3.equalsEpsilon(p1, p, CesiumMath.EPSILON10)) {\n // if we've reached a corner\n recomputeNormal = true;\n }\n\n if (vertexFormat.tangent || vertexFormat.bitangent) {\n bitangent = ellipsoid.geodeticSurfaceNormal(p, bitangent);\n if (vertexFormat.tangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.cross(bitangent, normal, tangent),\n tangent\n );\n }\n }\n\n if (vertexFormat.normal) {\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n }\n\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n }\n }\n }\n\n return createAttributes(vertexFormat, {\n positions: positions,\n normals: normals,\n tangents: tangents,\n bitangents: bitangents,\n });\n}\n\nfunction constructRectangle(rectangleGeometry, computedOptions) {\n const vertexFormat = rectangleGeometry._vertexFormat;\n const ellipsoid = rectangleGeometry._ellipsoid;\n const height = computedOptions.height;\n const width = computedOptions.width;\n const northCap = computedOptions.northCap;\n const southCap = computedOptions.southCap;\n\n let rowStart = 0;\n let rowEnd = height;\n let rowHeight = height;\n let size = 0;\n if (northCap) {\n rowStart = 1;\n rowHeight -= 1;\n size += 1;\n }\n if (southCap) {\n rowEnd -= 1;\n rowHeight -= 1;\n size += 1;\n }\n size += width * rowHeight;\n\n const positions = vertexFormat.position\n ? new Float64Array(size * 3)\n : undefined;\n const textureCoordinates = vertexFormat.st\n ? new Float32Array(size * 2)\n : undefined;\n\n let posIndex = 0;\n let stIndex = 0;\n\n const position = positionScratch;\n const st = stScratch;\n\n let minX = Number.MAX_VALUE;\n let minY = Number.MAX_VALUE;\n let maxX = -Number.MAX_VALUE;\n let maxY = -Number.MAX_VALUE;\n\n for (let row = rowStart; row < rowEnd; ++row) {\n for (let col = 0; col < width; ++col) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n vertexFormat.st,\n row,\n col,\n position,\n st\n );\n\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n\n if (vertexFormat.st) {\n textureCoordinates[stIndex++] = st.x;\n textureCoordinates[stIndex++] = st.y;\n\n minX = Math.min(minX, st.x);\n minY = Math.min(minY, st.y);\n maxX = Math.max(maxX, st.x);\n maxY = Math.max(maxY, st.y);\n }\n }\n }\n if (northCap) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n vertexFormat.st,\n 0,\n 0,\n position,\n st\n );\n\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex++] = position.z;\n\n if (vertexFormat.st) {\n textureCoordinates[stIndex++] = st.x;\n textureCoordinates[stIndex++] = st.y;\n\n minX = st.x;\n minY = st.y;\n maxX = st.x;\n maxY = st.y;\n }\n }\n if (southCap) {\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n vertexFormat.st,\n height - 1,\n 0,\n position,\n st\n );\n\n positions[posIndex++] = position.x;\n positions[posIndex++] = position.y;\n positions[posIndex] = position.z;\n\n if (vertexFormat.st) {\n textureCoordinates[stIndex++] = st.x;\n textureCoordinates[stIndex] = st.y;\n\n minX = Math.min(minX, st.x);\n minY = Math.min(minY, st.y);\n maxX = Math.max(maxX, st.x);\n maxY = Math.max(maxY, st.y);\n }\n }\n\n if (\n vertexFormat.st &&\n (minX < 0.0 || minY < 0.0 || maxX > 1.0 || maxY > 1.0)\n ) {\n for (let k = 0; k < textureCoordinates.length; k += 2) {\n textureCoordinates[k] = (textureCoordinates[k] - minX) / (maxX - minX);\n textureCoordinates[k + 1] =\n (textureCoordinates[k + 1] - minY) / (maxY - minY);\n }\n }\n\n const geo = calculateAttributes(\n positions,\n vertexFormat,\n ellipsoid,\n computedOptions.tangentRotationMatrix\n );\n\n let indicesSize = 6 * (width - 1) * (rowHeight - 1);\n if (northCap) {\n indicesSize += 3 * (width - 1);\n }\n if (southCap) {\n indicesSize += 3 * (width - 1);\n }\n const indices = IndexDatatype.createTypedArray(size, indicesSize);\n let index = 0;\n let indicesIndex = 0;\n let i;\n for (i = 0; i < rowHeight - 1; ++i) {\n for (let j = 0; j < width - 1; ++j) {\n const upperLeft = index;\n const lowerLeft = upperLeft + width;\n const lowerRight = lowerLeft + 1;\n const upperRight = upperLeft + 1;\n indices[indicesIndex++] = upperLeft;\n indices[indicesIndex++] = lowerLeft;\n indices[indicesIndex++] = upperRight;\n indices[indicesIndex++] = upperRight;\n indices[indicesIndex++] = lowerLeft;\n indices[indicesIndex++] = lowerRight;\n ++index;\n }\n ++index;\n }\n if (northCap || southCap) {\n let northIndex = size - 1;\n const southIndex = size - 1;\n if (northCap && southCap) {\n northIndex = size - 2;\n }\n\n let p1;\n let p2;\n index = 0;\n\n if (northCap) {\n for (i = 0; i < width - 1; i++) {\n p1 = index;\n p2 = p1 + 1;\n indices[indicesIndex++] = northIndex;\n indices[indicesIndex++] = p1;\n indices[indicesIndex++] = p2;\n ++index;\n }\n }\n if (southCap) {\n index = (rowHeight - 1) * width;\n for (i = 0; i < width - 1; i++) {\n p1 = index;\n p2 = p1 + 1;\n indices[indicesIndex++] = p1;\n indices[indicesIndex++] = southIndex;\n indices[indicesIndex++] = p2;\n ++index;\n }\n }\n }\n\n geo.indices = indices;\n if (vertexFormat.st) {\n geo.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n return geo;\n}\n\nfunction addWallPositions(\n wallPositions,\n posIndex,\n i,\n topPositions,\n bottomPositions\n) {\n wallPositions[posIndex++] = topPositions[i];\n wallPositions[posIndex++] = topPositions[i + 1];\n wallPositions[posIndex++] = topPositions[i + 2];\n wallPositions[posIndex++] = bottomPositions[i];\n wallPositions[posIndex++] = bottomPositions[i + 1];\n wallPositions[posIndex] = bottomPositions[i + 2];\n return wallPositions;\n}\n\nfunction addWallTextureCoordinates(wallTextures, stIndex, i, st) {\n wallTextures[stIndex++] = st[i];\n wallTextures[stIndex++] = st[i + 1];\n wallTextures[stIndex++] = st[i];\n wallTextures[stIndex] = st[i + 1];\n return wallTextures;\n}\n\nconst scratchVertexFormat = new VertexFormat();\n\nfunction constructExtrudedRectangle(rectangleGeometry, computedOptions) {\n const shadowVolume = rectangleGeometry._shadowVolume;\n const offsetAttributeValue = rectangleGeometry._offsetAttribute;\n const vertexFormat = rectangleGeometry._vertexFormat;\n const minHeight = rectangleGeometry._extrudedHeight;\n const maxHeight = rectangleGeometry._surfaceHeight;\n const ellipsoid = rectangleGeometry._ellipsoid;\n\n const height = computedOptions.height;\n const width = computedOptions.width;\n\n let i;\n\n if (shadowVolume) {\n const newVertexFormat = VertexFormat.clone(\n vertexFormat,\n scratchVertexFormat\n );\n newVertexFormat.normal = true;\n rectangleGeometry._vertexFormat = newVertexFormat;\n }\n\n const topBottomGeo = constructRectangle(rectangleGeometry, computedOptions);\n\n if (shadowVolume) {\n rectangleGeometry._vertexFormat = vertexFormat;\n }\n\n let topPositions = PolygonPipeline.scaleToGeodeticHeight(\n topBottomGeo.attributes.position.values,\n maxHeight,\n ellipsoid,\n false\n );\n topPositions = new Float64Array(topPositions);\n let length = topPositions.length;\n const newLength = length * 2;\n const positions = new Float64Array(newLength);\n positions.set(topPositions);\n const bottomPositions = PolygonPipeline.scaleToGeodeticHeight(\n topBottomGeo.attributes.position.values,\n minHeight,\n ellipsoid\n );\n positions.set(bottomPositions, length);\n topBottomGeo.attributes.position.values = positions;\n\n const normals = vertexFormat.normal ? new Float32Array(newLength) : undefined;\n const tangents = vertexFormat.tangent\n ? new Float32Array(newLength)\n : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(newLength)\n : undefined;\n const textures = vertexFormat.st\n ? new Float32Array((newLength / 3) * 2)\n : undefined;\n let topSt;\n let topNormals;\n if (vertexFormat.normal) {\n topNormals = topBottomGeo.attributes.normal.values;\n normals.set(topNormals);\n for (i = 0; i < length; i++) {\n topNormals[i] = -topNormals[i];\n }\n normals.set(topNormals, length);\n topBottomGeo.attributes.normal.values = normals;\n }\n if (shadowVolume) {\n topNormals = topBottomGeo.attributes.normal.values;\n if (!vertexFormat.normal) {\n topBottomGeo.attributes.normal = undefined;\n }\n const extrudeNormals = new Float32Array(newLength);\n for (i = 0; i < length; i++) {\n topNormals[i] = -topNormals[i];\n }\n extrudeNormals.set(topNormals, length); //only get normals for bottom layer that's going to be pushed down\n topBottomGeo.attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: extrudeNormals,\n });\n }\n\n let offsetValue;\n const hasOffsets = defined(offsetAttributeValue);\n if (hasOffsets) {\n const size = (length / 3) * 2;\n let offsetAttribute = new Uint8Array(size);\n if (offsetAttributeValue === GeometryOffsetAttribute.TOP) {\n offsetAttribute = offsetAttribute.fill(1, 0, size / 2);\n } else {\n offsetValue =\n offsetAttributeValue === GeometryOffsetAttribute.NONE ? 0 : 1;\n offsetAttribute = offsetAttribute.fill(offsetValue);\n }\n\n topBottomGeo.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: offsetAttribute,\n });\n }\n\n if (vertexFormat.tangent) {\n const topTangents = topBottomGeo.attributes.tangent.values;\n tangents.set(topTangents);\n for (i = 0; i < length; i++) {\n topTangents[i] = -topTangents[i];\n }\n tangents.set(topTangents, length);\n topBottomGeo.attributes.tangent.values = tangents;\n }\n if (vertexFormat.bitangent) {\n const topBitangents = topBottomGeo.attributes.bitangent.values;\n bitangents.set(topBitangents);\n bitangents.set(topBitangents, length);\n topBottomGeo.attributes.bitangent.values = bitangents;\n }\n if (vertexFormat.st) {\n topSt = topBottomGeo.attributes.st.values;\n textures.set(topSt);\n textures.set(topSt, (length / 3) * 2);\n topBottomGeo.attributes.st.values = textures;\n }\n\n const indices = topBottomGeo.indices;\n const indicesLength = indices.length;\n const posLength = length / 3;\n const newIndices = IndexDatatype.createTypedArray(\n newLength / 3,\n indicesLength * 2\n );\n newIndices.set(indices);\n for (i = 0; i < indicesLength; i += 3) {\n newIndices[i + indicesLength] = indices[i + 2] + posLength;\n newIndices[i + 1 + indicesLength] = indices[i + 1] + posLength;\n newIndices[i + 2 + indicesLength] = indices[i] + posLength;\n }\n topBottomGeo.indices = newIndices;\n\n const northCap = computedOptions.northCap;\n const southCap = computedOptions.southCap;\n\n let rowHeight = height;\n let widthMultiplier = 2;\n let perimeterPositions = 0;\n let corners = 4;\n let dupliateCorners = 4;\n if (northCap) {\n widthMultiplier -= 1;\n rowHeight -= 1;\n perimeterPositions += 1;\n corners -= 2;\n dupliateCorners -= 1;\n }\n if (southCap) {\n widthMultiplier -= 1;\n rowHeight -= 1;\n perimeterPositions += 1;\n corners -= 2;\n dupliateCorners -= 1;\n }\n perimeterPositions += widthMultiplier * width + 2 * rowHeight - corners;\n\n const wallCount = (perimeterPositions + dupliateCorners) * 2;\n\n let wallPositions = new Float64Array(wallCount * 3);\n const wallExtrudeNormals = shadowVolume\n ? new Float32Array(wallCount * 3)\n : undefined;\n let wallOffsetAttribute = hasOffsets ? new Uint8Array(wallCount) : undefined;\n let wallTextures = vertexFormat.st\n ? new Float32Array(wallCount * 2)\n : undefined;\n\n const computeTopOffsets =\n offsetAttributeValue === GeometryOffsetAttribute.TOP;\n if (hasOffsets && !computeTopOffsets) {\n offsetValue = offsetAttributeValue === GeometryOffsetAttribute.ALL ? 1 : 0;\n wallOffsetAttribute = wallOffsetAttribute.fill(offsetValue);\n }\n\n let posIndex = 0;\n let stIndex = 0;\n let extrudeNormalIndex = 0;\n let wallOffsetIndex = 0;\n const area = width * rowHeight;\n let threeI;\n for (i = 0; i < area; i += width) {\n threeI = i * 3;\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n i * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n\n if (!southCap) {\n for (i = area - width; i < area; i++) {\n threeI = i * 3;\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n i * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n } else {\n const southIndex = northCap ? area + 1 : area;\n threeI = southIndex * 3;\n\n for (i = 0; i < 2; i++) {\n // duplicate corner points\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n southIndex * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n }\n\n for (i = area - 1; i > 0; i -= width) {\n threeI = i * 3;\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n i * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n\n if (!northCap) {\n for (i = width - 1; i >= 0; i--) {\n threeI = i * 3;\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n i * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n } else {\n const northIndex = area;\n threeI = northIndex * 3;\n\n for (i = 0; i < 2; i++) {\n // duplicate corner points\n wallPositions = addWallPositions(\n wallPositions,\n posIndex,\n threeI,\n topPositions,\n bottomPositions\n );\n posIndex += 6;\n if (vertexFormat.st) {\n wallTextures = addWallTextureCoordinates(\n wallTextures,\n stIndex,\n northIndex * 2,\n topSt\n );\n stIndex += 4;\n }\n if (shadowVolume) {\n extrudeNormalIndex += 3;\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1];\n wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2];\n }\n if (computeTopOffsets) {\n wallOffsetAttribute[wallOffsetIndex++] = 1;\n wallOffsetIndex += 1;\n }\n }\n }\n\n let geo = calculateAttributesWall(wallPositions, vertexFormat, ellipsoid);\n\n if (vertexFormat.st) {\n geo.attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: wallTextures,\n });\n }\n if (shadowVolume) {\n geo.attributes.extrudeDirection = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: wallExtrudeNormals,\n });\n }\n if (hasOffsets) {\n geo.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: wallOffsetAttribute,\n });\n }\n\n const wallIndices = IndexDatatype.createTypedArray(\n wallCount,\n perimeterPositions * 6\n );\n\n let upperLeft;\n let lowerLeft;\n let lowerRight;\n let upperRight;\n length = wallPositions.length / 3;\n let index = 0;\n for (i = 0; i < length - 1; i += 2) {\n upperLeft = i;\n upperRight = (upperLeft + 2) % length;\n const p1 = Cartesian3.fromArray(wallPositions, upperLeft * 3, v1Scratch);\n const p2 = Cartesian3.fromArray(wallPositions, upperRight * 3, v2Scratch);\n if (Cartesian3.equalsEpsilon(p1, p2, CesiumMath.EPSILON10)) {\n continue;\n }\n lowerLeft = (upperLeft + 1) % length;\n lowerRight = (lowerLeft + 2) % length;\n wallIndices[index++] = upperLeft;\n wallIndices[index++] = lowerLeft;\n wallIndices[index++] = upperRight;\n wallIndices[index++] = upperRight;\n wallIndices[index++] = lowerLeft;\n wallIndices[index++] = lowerRight;\n }\n\n geo.indices = wallIndices;\n\n geo = GeometryPipeline.combineInstances([\n new GeometryInstance({\n geometry: topBottomGeo,\n }),\n new GeometryInstance({\n geometry: geo,\n }),\n ]);\n\n return geo[0];\n}\n\nconst scratchRectanglePoints = [\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n new Cartesian3(),\n];\nconst nwScratch = new Cartographic();\nconst stNwScratch = new Cartographic();\nfunction computeRectangle(rectangle, granularity, rotation, ellipsoid, result) {\n if (rotation === 0.0) {\n return Rectangle.clone(rectangle, result);\n }\n\n const computedOptions = RectangleGeometryLibrary.computeOptions(\n rectangle,\n granularity,\n rotation,\n 0,\n rectangleScratch,\n nwScratch\n );\n\n const height = computedOptions.height;\n const width = computedOptions.width;\n\n const positions = scratchRectanglePoints;\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n 0,\n 0,\n positions[0]\n );\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n 0,\n width - 1,\n positions[1]\n );\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n height - 1,\n 0,\n positions[2]\n );\n RectangleGeometryLibrary.computePosition(\n computedOptions,\n ellipsoid,\n false,\n height - 1,\n width - 1,\n positions[3]\n );\n\n return Rectangle.fromCartesianArray(positions, ellipsoid, result);\n}\n\n/**\n * A description of a cartographic rectangle on an ellipsoid centered at the origin. Rectangle geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.\n *\n * @alias RectangleGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Rectangle} options.rectangle A cartographic rectangle with north, south, east and west properties in radians.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle lies.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number} [options.height=0.0] The distance in meters between the rectangle and the ellipsoid surface.\n * @param {number} [options.rotation=0.0] The rotation of the rectangle, in radians. A positive rotation is counter-clockwise.\n * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.\n * @param {number} [options.extrudedHeight] The distance in meters between the rectangle's extruded face and the ellipsoid surface.\n *\n * @exception {DeveloperError} options.rectangle.north must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} options.rectangle.south must be in the interval [-Pi/2, Pi/2].\n * @exception {DeveloperError} options.rectangle.east must be in the interval [-Pi, Pi].\n * @exception {DeveloperError} options.rectangle.west must be in the interval [-Pi, Pi].\n * @exception {DeveloperError} options.rectangle.north must be greater than options.rectangle.south.\n *\n * @see RectangleGeometry#createGeometry\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Rectangle.html|Cesium Sandcastle Rectangle Demo}\n *\n * @example\n * // 1. create a rectangle\n * const rectangle = new Cesium.RectangleGeometry({\n * ellipsoid : Cesium.Ellipsoid.WGS84,\n * rectangle : Cesium.Rectangle.fromDegrees(-80.0, 39.0, -74.0, 42.0),\n * height : 10000.0\n * });\n * const geometry = Cesium.RectangleGeometry.createGeometry(rectangle);\n *\n * // 2. create an extruded rectangle without a top\n * const rectangle = new Cesium.RectangleGeometry({\n * ellipsoid : Cesium.Ellipsoid.WGS84,\n * rectangle : Cesium.Rectangle.fromDegrees(-80.0, 39.0, -74.0, 42.0),\n * height : 10000.0,\n * extrudedHeight: 300000\n * });\n * const geometry = Cesium.RectangleGeometry.createGeometry(rectangle);\n */\nfunction RectangleGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const rectangle = options.rectangle;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Rectangle.validate(rectangle);\n if (rectangle.north < rectangle.south) {\n throw new DeveloperError(\n \"options.rectangle.north must be greater than or equal to options.rectangle.south\"\n );\n }\n //>>includeEnd('debug');\n\n const height = defaultValue(options.height, 0.0);\n const extrudedHeight = defaultValue(options.extrudedHeight, height);\n\n this._rectangle = Rectangle.clone(rectangle);\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._surfaceHeight = Math.max(height, extrudedHeight);\n this._rotation = defaultValue(options.rotation, 0.0);\n this._stRotation = defaultValue(options.stRotation, 0.0);\n this._vertexFormat = VertexFormat.clone(\n defaultValue(options.vertexFormat, VertexFormat.DEFAULT)\n );\n this._extrudedHeight = Math.min(height, extrudedHeight);\n this._shadowVolume = defaultValue(options.shadowVolume, false);\n this._workerName = \"createRectangleGeometry\";\n this._offsetAttribute = options.offsetAttribute;\n this._rotatedRectangle = undefined;\n\n this._textureCoordinateRotationPoints = undefined;\n}\n\n/**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\nRectangleGeometry.packedLength =\n Rectangle.packedLength +\n Ellipsoid.packedLength +\n VertexFormat.packedLength +\n 7;\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {RectangleGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nRectangleGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"value\", value);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n Rectangle.pack(value._rectangle, array, startingIndex);\n startingIndex += Rectangle.packedLength;\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._granularity;\n array[startingIndex++] = value._surfaceHeight;\n array[startingIndex++] = value._rotation;\n array[startingIndex++] = value._stRotation;\n array[startingIndex++] = value._extrudedHeight;\n array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0;\n array[startingIndex] = defaultValue(value._offsetAttribute, -1);\n\n return array;\n};\n\nconst scratchRectangle = new Rectangle();\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchOptions = {\n rectangle: scratchRectangle,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n granularity: undefined,\n height: undefined,\n rotation: undefined,\n stRotation: undefined,\n extrudedHeight: undefined,\n shadowVolume: undefined,\n offsetAttribute: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {RectangleGeometry} [result] The object into which to store the result.\n * @returns {RectangleGeometry} The modified result parameter or a new RectangleGeometry instance if one was not provided.\n */\nRectangleGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"array\", array);\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n const rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);\n startingIndex += Rectangle.packedLength;\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const granularity = array[startingIndex++];\n const surfaceHeight = array[startingIndex++];\n const rotation = array[startingIndex++];\n const stRotation = array[startingIndex++];\n const extrudedHeight = array[startingIndex++];\n const shadowVolume = array[startingIndex++] === 1.0;\n const offsetAttribute = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.granularity = granularity;\n scratchOptions.height = surfaceHeight;\n scratchOptions.rotation = rotation;\n scratchOptions.stRotation = stRotation;\n scratchOptions.extrudedHeight = extrudedHeight;\n scratchOptions.shadowVolume = shadowVolume;\n scratchOptions.offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return new RectangleGeometry(scratchOptions);\n }\n\n result._rectangle = Rectangle.clone(rectangle, result._rectangle);\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._granularity = granularity;\n result._surfaceHeight = surfaceHeight;\n result._rotation = rotation;\n result._stRotation = stRotation;\n result._extrudedHeight = extrudedHeight;\n result._shadowVolume = shadowVolume;\n result._offsetAttribute =\n offsetAttribute === -1 ? undefined : offsetAttribute;\n\n return result;\n};\n\n/**\n * Computes the bounding rectangle based on the provided options\n *\n * @param {object} options Object with the following properties:\n * @param {Rectangle} options.rectangle A cartographic rectangle with north, south, east and west properties in radians.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the rectangle lies.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number} [options.rotation=0.0] The rotation of the rectangle, in radians. A positive rotation is counter-clockwise.\n * @param {Rectangle} [result] An object in which to store the result.\n *\n * @returns {Rectangle} The result rectangle\n */\nRectangleGeometry.computeRectangle = function (options, result) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const rectangle = options.rectangle;\n\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n Rectangle.validate(rectangle);\n if (rectangle.north < rectangle.south) {\n throw new DeveloperError(\n \"options.rectangle.north must be greater than or equal to options.rectangle.south\"\n );\n }\n //>>includeEnd('debug');\n\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n const rotation = defaultValue(options.rotation, 0.0);\n\n return computeRectangle(rectangle, granularity, rotation, ellipsoid, result);\n};\n\nconst tangentRotationMatrixScratch = new Matrix3();\nconst quaternionScratch = new Quaternion();\nconst centerScratch = new Cartographic();\n/**\n * Computes the geometric representation of a rectangle, including its vertices, indices, and a bounding sphere.\n *\n * @param {RectangleGeometry} rectangleGeometry A description of the rectangle.\n * @returns {Geometry|undefined} The computed vertices and indices.\n *\n * @exception {DeveloperError} Rotated rectangle is invalid.\n */\nRectangleGeometry.createGeometry = function (rectangleGeometry) {\n if (\n CesiumMath.equalsEpsilon(\n rectangleGeometry._rectangle.north,\n rectangleGeometry._rectangle.south,\n CesiumMath.EPSILON10\n ) ||\n CesiumMath.equalsEpsilon(\n rectangleGeometry._rectangle.east,\n rectangleGeometry._rectangle.west,\n CesiumMath.EPSILON10\n )\n ) {\n return undefined;\n }\n\n let rectangle = rectangleGeometry._rectangle;\n const ellipsoid = rectangleGeometry._ellipsoid;\n const rotation = rectangleGeometry._rotation;\n const stRotation = rectangleGeometry._stRotation;\n const vertexFormat = rectangleGeometry._vertexFormat;\n\n const computedOptions = RectangleGeometryLibrary.computeOptions(\n rectangle,\n rectangleGeometry._granularity,\n rotation,\n stRotation,\n rectangleScratch,\n nwScratch,\n stNwScratch\n );\n\n const tangentRotationMatrix = tangentRotationMatrixScratch;\n if (stRotation !== 0 || rotation !== 0) {\n const center = Rectangle.center(rectangle, centerScratch);\n const axis = ellipsoid.geodeticSurfaceNormalCartographic(center, v1Scratch);\n Quaternion.fromAxisAngle(axis, -stRotation, quaternionScratch);\n Matrix3.fromQuaternion(quaternionScratch, tangentRotationMatrix);\n } else {\n Matrix3.clone(Matrix3.IDENTITY, tangentRotationMatrix);\n }\n\n const surfaceHeight = rectangleGeometry._surfaceHeight;\n const extrudedHeight = rectangleGeometry._extrudedHeight;\n const extrude = !CesiumMath.equalsEpsilon(\n surfaceHeight,\n extrudedHeight,\n 0,\n CesiumMath.EPSILON2\n );\n\n computedOptions.lonScalar = 1.0 / rectangleGeometry._rectangle.width;\n computedOptions.latScalar = 1.0 / rectangleGeometry._rectangle.height;\n computedOptions.tangentRotationMatrix = tangentRotationMatrix;\n\n let geometry;\n let boundingSphere;\n rectangle = rectangleGeometry._rectangle;\n if (extrude) {\n geometry = constructExtrudedRectangle(rectangleGeometry, computedOptions);\n const topBS = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n surfaceHeight,\n topBoundingSphere\n );\n const bottomBS = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n extrudedHeight,\n bottomBoundingSphere\n );\n boundingSphere = BoundingSphere.union(topBS, bottomBS);\n } else {\n geometry = constructRectangle(rectangleGeometry, computedOptions);\n geometry.attributes.position.values = PolygonPipeline.scaleToGeodeticHeight(\n geometry.attributes.position.values,\n surfaceHeight,\n ellipsoid,\n false\n );\n\n if (defined(rectangleGeometry._offsetAttribute)) {\n const length = geometry.attributes.position.values.length;\n const offsetValue =\n rectangleGeometry._offsetAttribute === GeometryOffsetAttribute.NONE\n ? 0\n : 1;\n const applyOffset = new Uint8Array(length / 3).fill(offsetValue);\n geometry.attributes.applyOffset = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 1,\n values: applyOffset,\n });\n }\n\n boundingSphere = BoundingSphere.fromRectangle3D(\n rectangle,\n ellipsoid,\n surfaceHeight\n );\n }\n\n if (!vertexFormat.position) {\n delete geometry.attributes.position;\n }\n\n return new Geometry({\n attributes: geometry.attributes,\n indices: geometry.indices,\n primitiveType: geometry.primitiveType,\n boundingSphere: boundingSphere,\n offsetAttribute: rectangleGeometry._offsetAttribute,\n });\n};\n\n/**\n * @private\n */\nRectangleGeometry.createShadowVolume = function (\n rectangleGeometry,\n minHeightFunc,\n maxHeightFunc\n) {\n const granularity = rectangleGeometry._granularity;\n const ellipsoid = rectangleGeometry._ellipsoid;\n\n const minHeight = minHeightFunc(granularity, ellipsoid);\n const maxHeight = maxHeightFunc(granularity, ellipsoid);\n\n return new RectangleGeometry({\n rectangle: rectangleGeometry._rectangle,\n rotation: rectangleGeometry._rotation,\n ellipsoid: ellipsoid,\n stRotation: rectangleGeometry._stRotation,\n granularity: granularity,\n extrudedHeight: maxHeight,\n height: minHeight,\n vertexFormat: VertexFormat.POSITION_ONLY,\n shadowVolume: true,\n });\n};\n\nconst unrotatedTextureRectangleScratch = new Rectangle();\nconst points2DScratch = [new Cartesian2(), new Cartesian2(), new Cartesian2()];\nconst rotation2DScratch = new Matrix2();\nconst rectangleCenterScratch = new Cartographic();\n\nfunction textureCoordinateRotationPoints(rectangleGeometry) {\n if (rectangleGeometry._stRotation === 0.0) {\n return [0, 0, 0, 1, 1, 0];\n }\n\n const rectangle = Rectangle.clone(\n rectangleGeometry._rectangle,\n unrotatedTextureRectangleScratch\n );\n const granularity = rectangleGeometry._granularity;\n const ellipsoid = rectangleGeometry._ellipsoid;\n\n // Rotate to align the texture coordinates with ENU\n const rotation = rectangleGeometry._rotation - rectangleGeometry._stRotation;\n\n const unrotatedTextureRectangle = computeRectangle(\n rectangle,\n granularity,\n rotation,\n ellipsoid,\n unrotatedTextureRectangleScratch\n );\n\n // Assume a computed \"east-north\" texture coordinate system based on spherical or planar tricks, bounded by `boundingRectangle`.\n // The \"desired\" texture coordinate system forms an oriented rectangle (un-oriented computed) around the geometry that completely and tightly bounds it.\n // We want to map from the \"east-north\" texture coordinate system into the \"desired\" system using a pair of lines (analagous planes in 2D)\n // Compute 3 corners of the \"desired\" texture coordinate system in \"east-north\" texture space by the following in cartographic space:\n // - rotate 3 of the corners in unrotatedTextureRectangle by stRotation around the center of the bounding rectangle\n // - apply the \"east-north\" system's normalization formula to the rotated cartographics, even though this is likely to produce values outside [0-1].\n // This gives us a set of points in the \"east-north\" texture coordinate system that can be used to map \"east-north\" texture coordinates to \"desired.\"\n\n const points2D = points2DScratch;\n points2D[0].x = unrotatedTextureRectangle.west;\n points2D[0].y = unrotatedTextureRectangle.south;\n\n points2D[1].x = unrotatedTextureRectangle.west;\n points2D[1].y = unrotatedTextureRectangle.north;\n\n points2D[2].x = unrotatedTextureRectangle.east;\n points2D[2].y = unrotatedTextureRectangle.south;\n\n const boundingRectangle = rectangleGeometry.rectangle;\n const toDesiredInComputed = Matrix2.fromRotation(\n rectangleGeometry._stRotation,\n rotation2DScratch\n );\n const boundingRectangleCenter = Rectangle.center(\n boundingRectangle,\n rectangleCenterScratch\n );\n\n for (let i = 0; i < 3; ++i) {\n const point2D = points2D[i];\n point2D.x -= boundingRectangleCenter.longitude;\n point2D.y -= boundingRectangleCenter.latitude;\n Matrix2.multiplyByVector(toDesiredInComputed, point2D, point2D);\n point2D.x += boundingRectangleCenter.longitude;\n point2D.y += boundingRectangleCenter.latitude;\n\n // Convert point into east-north texture coordinate space\n point2D.x = (point2D.x - boundingRectangle.west) / boundingRectangle.width;\n point2D.y =\n (point2D.y - boundingRectangle.south) / boundingRectangle.height;\n }\n\n const minXYCorner = points2D[0];\n const maxYCorner = points2D[1];\n const maxXCorner = points2D[2];\n const result = new Array(6);\n Cartesian2.pack(minXYCorner, result);\n Cartesian2.pack(maxYCorner, result, 2);\n Cartesian2.pack(maxXCorner, result, 4);\n return result;\n}\n\nObject.defineProperties(RectangleGeometry.prototype, {\n /**\n * @private\n */\n rectangle: {\n get: function () {\n if (!defined(this._rotatedRectangle)) {\n this._rotatedRectangle = computeRectangle(\n this._rectangle,\n this._granularity,\n this._rotation,\n this._ellipsoid\n );\n }\n return this._rotatedRectangle;\n },\n },\n /**\n * For remapping texture coordinates when rendering RectangleGeometries as GroundPrimitives.\n * This version permits skew in textures by computing offsets directly in cartographic space and\n * more accurately approximates rendering RectangleGeometries with height as standard Primitives.\n * @see Geometry#_textureCoordinateRotationPoints\n * @private\n */\n textureCoordinateRotationPoints: {\n get: function () {\n if (!defined(this._textureCoordinateRotationPoints)) {\n this._textureCoordinateRotationPoints = textureCoordinateRotationPoints(\n this\n );\n }\n return this._textureCoordinateRotationPoints;\n },\n },\n});\nexport default RectangleGeometry;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport RectangleGeometry from \"../Core/RectangleGeometry.js\";\nimport RectangleOutlineGeometry from \"../Core/RectangleOutlineGeometry.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport GroundGeometryUpdater from \"./GroundGeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\nconst scratchRectangle = new Rectangle();\nconst scratchCenterRect = new Rectangle();\nconst scratchCarto = new Cartographic();\n\nfunction RectangleGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.rectangle = undefined;\n this.height = undefined;\n this.extrudedHeight = undefined;\n this.granularity = undefined;\n this.stRotation = undefined;\n this.rotation = undefined;\n this.offsetAttribute = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for rectangles.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias RectangleGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction RectangleGeometryUpdater(entity, scene) {\n GroundGeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new RectangleGeometryOptions(entity),\n geometryPropertyName: \"rectangle\",\n observedPropertyNames: [\"availability\", \"rectangle\"],\n });\n\n this._onEntityPropertyChanged(\n entity,\n \"rectangle\",\n entity.rectangle,\n undefined\n );\n}\n\nif (defined(Object.create)) {\n RectangleGeometryUpdater.prototype = Object.create(\n GroundGeometryUpdater.prototype\n );\n RectangleGeometryUpdater.prototype.constructor = RectangleGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nRectangleGeometryUpdater.prototype.createFillGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n ),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n this._distanceDisplayConditionProperty.getValue(time)\n ),\n offset: undefined,\n color: undefined,\n };\n\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new RectangleGeometry(this._options),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nRectangleGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n const attributes = {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n offset: undefined,\n };\n\n if (defined(this._options.offsetAttribute)) {\n attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(\n Property.getValueOrDefault(\n this._terrainOffsetProperty,\n time,\n defaultOffset,\n offsetScratch\n )\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new RectangleOutlineGeometry(this._options),\n attributes: attributes,\n });\n};\n\nRectangleGeometryUpdater.prototype._computeCenter = function (time, result) {\n const rect = Property.getValueOrUndefined(\n this._entity.rectangle.coordinates,\n time,\n scratchCenterRect\n );\n if (!defined(rect)) {\n return;\n }\n const center = Rectangle.center(rect, scratchCarto);\n return Cartographic.toCartesian(center, Ellipsoid.WGS84, result);\n};\n\nRectangleGeometryUpdater.prototype._isHidden = function (entity, rectangle) {\n return (\n !defined(rectangle.coordinates) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, rectangle)\n );\n};\n\nRectangleGeometryUpdater.prototype._isDynamic = function (entity, rectangle) {\n return (\n !rectangle.coordinates.isConstant || //\n !Property.isConstant(rectangle.height) || //\n !Property.isConstant(rectangle.extrudedHeight) || //\n !Property.isConstant(rectangle.granularity) || //\n !Property.isConstant(rectangle.stRotation) || //\n !Property.isConstant(rectangle.rotation) || //\n !Property.isConstant(rectangle.outlineWidth) || //\n !Property.isConstant(rectangle.zIndex) || //\n (this._onTerrain &&\n !Property.isConstant(this._materialProperty) &&\n !(this._materialProperty instanceof ColorMaterialProperty))\n );\n};\n\nRectangleGeometryUpdater.prototype._setStaticOptions = function (\n entity,\n rectangle\n) {\n const isColorMaterial =\n this._materialProperty instanceof ColorMaterialProperty;\n\n let heightValue = Property.getValueOrUndefined(\n rectangle.height,\n Iso8601.MINIMUM_VALUE\n );\n const heightReferenceValue = Property.getValueOrDefault(\n rectangle.heightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n rectangle.extrudedHeight,\n Iso8601.MINIMUM_VALUE\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n rectangle.extrudedHeightReference,\n Iso8601.MINIMUM_VALUE,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n const options = this._options;\n options.vertexFormat = isColorMaterial\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.rectangle = rectangle.coordinates.getValue(\n Iso8601.MINIMUM_VALUE,\n options.rectangle\n );\n options.granularity = Property.getValueOrUndefined(\n rectangle.granularity,\n Iso8601.MINIMUM_VALUE\n );\n options.stRotation = Property.getValueOrUndefined(\n rectangle.stRotation,\n Iso8601.MINIMUM_VALUE\n );\n options.rotation = Property.getValueOrUndefined(\n rectangle.rotation,\n Iso8601.MINIMUM_VALUE\n );\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n RectangleGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\n\nRectangleGeometryUpdater.DynamicGeometryUpdater = DynamicRectangleGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicRectangleGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicRectangleGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicRectangleGeometryUpdater.prototype.constructor = DynamicRectangleGeometryUpdater;\n}\n\nDynamicRectangleGeometryUpdater.prototype._isHidden = function (\n entity,\n rectangle,\n time\n) {\n return (\n !defined(this._options.rectangle) ||\n DynamicGeometryUpdater.prototype._isHidden.call(\n this,\n entity,\n rectangle,\n time\n )\n );\n};\n\nDynamicRectangleGeometryUpdater.prototype._setOptions = function (\n entity,\n rectangle,\n time\n) {\n const options = this._options;\n let heightValue = Property.getValueOrUndefined(rectangle.height, time);\n const heightReferenceValue = Property.getValueOrDefault(\n rectangle.heightReference,\n time,\n HeightReference.NONE\n );\n let extrudedHeightValue = Property.getValueOrUndefined(\n rectangle.extrudedHeight,\n time\n );\n const extrudedHeightReferenceValue = Property.getValueOrDefault(\n rectangle.extrudedHeightReference,\n time,\n HeightReference.NONE\n );\n if (defined(extrudedHeightValue) && !defined(heightValue)) {\n heightValue = 0;\n }\n\n options.rectangle = Property.getValueOrUndefined(\n rectangle.coordinates,\n time,\n options.rectangle\n );\n options.granularity = Property.getValueOrUndefined(\n rectangle.granularity,\n time\n );\n options.stRotation = Property.getValueOrUndefined(rectangle.stRotation, time);\n options.rotation = Property.getValueOrUndefined(rectangle.rotation, time);\n options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(\n heightValue,\n heightReferenceValue,\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n options.height = GroundGeometryUpdater.getGeometryHeight(\n heightValue,\n heightReferenceValue\n );\n\n extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(\n extrudedHeightValue,\n extrudedHeightReferenceValue\n );\n if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {\n extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(\n RectangleGeometry.computeRectangle(options, scratchRectangle)\n ).minimumTerrainHeight;\n }\n\n options.extrudedHeight = extrudedHeightValue;\n};\nexport default RectangleGeometryUpdater;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport Primitive from \"../Scene/Primitive.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst colorScratch = new Color();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\n\nfunction Batch(\n primitives,\n translucent,\n appearanceType,\n depthFailAppearanceType,\n depthFailMaterialProperty,\n closed,\n shadows\n) {\n this.translucent = translucent;\n this.appearanceType = appearanceType;\n this.depthFailAppearanceType = depthFailAppearanceType;\n this.depthFailMaterialProperty = depthFailMaterialProperty;\n this.depthFailMaterial = undefined;\n this.closed = closed;\n this.shadows = shadows;\n this.primitives = primitives;\n this.createPrimitive = false;\n this.waitingOnCreate = false;\n this.primitive = undefined;\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.updaters = new AssociativeArray();\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n this.itemsToRemove = [];\n this.invalidated = false;\n\n let removeMaterialSubscription;\n if (defined(depthFailMaterialProperty)) {\n removeMaterialSubscription = depthFailMaterialProperty.definitionChanged.addEventListener(\n Batch.prototype.onMaterialChanged,\n this\n );\n }\n this.removeMaterialSubscription = removeMaterialSubscription;\n}\n\nBatch.prototype.onMaterialChanged = function () {\n this.invalidated = true;\n};\n\nBatch.prototype.isMaterial = function (updater) {\n const material = this.depthFailMaterialProperty;\n const updaterMaterial = updater.depthFailMaterialProperty;\n if (updaterMaterial === material) {\n return true;\n }\n if (defined(material)) {\n return material.equals(updaterMaterial);\n }\n return false;\n};\n\nBatch.prototype.add = function (updater, instance) {\n const id = updater.id;\n this.createPrimitive = true;\n this.geometry.set(id, instance);\n this.updaters.set(id, updater);\n if (\n !updater.hasConstantFill ||\n !updater.fillMaterialProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty) ||\n !Property.isConstant(updater.terrainOffsetProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n this.showsUpdated.remove(id);\n }\n return true;\n }\n return false;\n};\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n let removedCount = 0;\n let primitive = this.primitive;\n const primitives = this.primitives;\n let i;\n\n if (this.createPrimitive) {\n const geometries = this.geometry.values;\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n primitives.remove(primitive);\n }\n }\n\n let depthFailAppearance;\n if (defined(this.depthFailAppearanceType)) {\n if (defined(this.depthFailMaterialProperty)) {\n this.depthFailMaterial = MaterialProperty.getValue(\n time,\n this.depthFailMaterialProperty,\n this.depthFailMaterial\n );\n }\n depthFailAppearance = new this.depthFailAppearanceType({\n material: this.depthFailMaterial,\n translucent: this.translucent,\n closed: this.closed,\n });\n }\n\n primitive = new Primitive({\n show: false,\n asynchronous: true,\n geometryInstances: geometries.slice(),\n appearance: new this.appearanceType({\n translucent: this.translucent,\n closed: this.closed,\n }),\n depthFailAppearance: depthFailAppearance,\n shadows: this.shadows,\n });\n primitives.add(primitive);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n primitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n this.waitingOnCreate = true;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n primitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n\n if (\n defined(this.depthFailAppearanceType) &&\n !(this.depthFailMaterialProperty instanceof ColorMaterialProperty)\n ) {\n this.depthFailMaterial = MaterialProperty.getValue(\n time,\n this.depthFailMaterialProperty,\n this.depthFailMaterial\n );\n this.primitive.depthFailAppearance.material = this.depthFailMaterial;\n }\n\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n const waitingOnCreate = this.waitingOnCreate;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n if (!updater.fillMaterialProperty.isConstant || waitingOnCreate) {\n const colorProperty = updater.fillMaterialProperty.color;\n const resultColor = Property.getValueOrDefault(\n colorProperty,\n time,\n Color.WHITE,\n colorScratch\n );\n if (!Color.equals(attributes._lastColor, resultColor)) {\n attributes._lastColor = Color.clone(\n resultColor,\n attributes._lastColor\n );\n attributes.color = ColorGeometryInstanceAttribute.toValue(\n resultColor,\n attributes.color\n );\n if (\n (this.translucent && attributes.color[3] === 255) ||\n (!this.translucent && attributes.color[3] !== 255)\n ) {\n this.itemsToRemove[removedCount++] = updater;\n }\n }\n }\n\n if (\n defined(this.depthFailAppearanceType) &&\n updater.depthFailMaterialProperty instanceof ColorMaterialProperty &&\n (!updater.depthFailMaterialProperty.isConstant || waitingOnCreate)\n ) {\n const depthFailColorProperty = updater.depthFailMaterialProperty.color;\n const depthColor = Property.getValueOrDefault(\n depthFailColorProperty,\n time,\n Color.WHITE,\n colorScratch\n );\n if (!Color.equals(attributes._lastDepthFailColor, depthColor)) {\n attributes._lastDepthFailColor = Color.clone(\n depthColor,\n attributes._lastDepthFailColor\n );\n attributes.depthFailColor = ColorGeometryInstanceAttribute.toValue(\n depthColor,\n attributes.depthFailColor\n );\n }\n }\n\n const show =\n updater.entity.isShowing &&\n (updater.hasConstantFill || updater.isFilled(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n\n const offsetProperty = updater.terrainOffsetProperty;\n if (!Property.isConstant(offsetProperty)) {\n const offset = Property.getValueOrDefault(\n offsetProperty,\n time,\n defaultOffset,\n offsetScratch\n );\n if (!Cartesian3.equals(offset, attributes._lastOffset)) {\n attributes._lastOffset = Cartesian3.clone(\n offset,\n attributes._lastOffset\n );\n attributes.offset = OffsetGeometryInstanceAttribute.toValue(\n offset,\n attributes.offset\n );\n }\n }\n }\n\n this.updateShows(primitive);\n this.waitingOnCreate = false;\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n this.itemsToRemove.length = removedCount;\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = updater.entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n const attributes = primitive.getGeometryInstanceAttributes(updater.entity);\n if (\n !defined(attributes) ||\n !defined(attributes.boundingSphere) || //\n (defined(attributes.show) && attributes.show[0] === 0)\n ) {\n return BoundingSphereState.FAILED;\n }\n attributes.boundingSphere.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.destroy = function () {\n const primitive = this.primitive;\n const primitives = this.primitives;\n if (defined(primitive)) {\n primitives.remove(primitive);\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n }\n if (defined(this.removeMaterialSubscription)) {\n this.removeMaterialSubscription();\n }\n};\n\n/**\n * @private\n */\nfunction StaticGeometryColorBatch(\n primitives,\n appearanceType,\n depthFailAppearanceType,\n closed,\n shadows\n) {\n this._solidItems = [];\n this._translucentItems = [];\n this._primitives = primitives;\n this._appearanceType = appearanceType;\n this._depthFailAppearanceType = depthFailAppearanceType;\n this._closed = closed;\n this._shadows = shadows;\n}\n\nStaticGeometryColorBatch.prototype.add = function (time, updater) {\n let items;\n let translucent;\n const instance = updater.createFillGeometryInstance(time);\n if (instance.attributes.color.value[3] === 255) {\n items = this._solidItems;\n translucent = false;\n } else {\n items = this._translucentItems;\n translucent = true;\n }\n\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.isMaterial(updater)) {\n item.add(updater, instance);\n return;\n }\n }\n const batch = new Batch(\n this._primitives,\n translucent,\n this._appearanceType,\n this._depthFailAppearanceType,\n updater.depthFailMaterialProperty,\n this._closed,\n this._shadows\n );\n batch.add(updater, instance);\n items.push(batch);\n};\n\nfunction removeItem(items, updater) {\n const length = items.length;\n for (let i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.remove(updater)) {\n if (item.updaters.length === 0) {\n items.splice(i, 1);\n item.destroy();\n }\n return true;\n }\n }\n return false;\n}\n\nStaticGeometryColorBatch.prototype.remove = function (updater) {\n if (!removeItem(this._solidItems, updater)) {\n removeItem(this._translucentItems, updater);\n }\n};\n\nfunction moveItems(batch, items, time) {\n let itemsMoved = false;\n const length = items.length;\n for (let i = 0; i < length; ++i) {\n const item = items[i];\n const itemsToRemove = item.itemsToRemove;\n const itemsToMoveLength = itemsToRemove.length;\n if (itemsToMoveLength > 0) {\n for (i = 0; i < itemsToMoveLength; i++) {\n const updater = itemsToRemove[i];\n item.remove(updater);\n batch.add(time, updater);\n itemsMoved = true;\n }\n }\n }\n return itemsMoved;\n}\n\nfunction updateItems(batch, items, time, isUpdated) {\n let length = items.length;\n let i;\n for (i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.invalidated) {\n items.splice(i, 1);\n const updaters = item.updaters.values;\n const updatersLength = updaters.length;\n for (let h = 0; h < updatersLength; h++) {\n batch.add(time, updaters[h]);\n }\n item.destroy();\n }\n }\n\n length = items.length;\n for (i = 0; i < length; ++i) {\n isUpdated = items[i].update(time) && isUpdated;\n }\n return isUpdated;\n}\n\nStaticGeometryColorBatch.prototype.update = function (time) {\n //Perform initial update\n let isUpdated = updateItems(this, this._solidItems, time, true);\n isUpdated =\n updateItems(this, this._translucentItems, time, isUpdated) && isUpdated;\n\n //If any items swapped between solid/translucent, we need to\n //move them between batches\n const solidsMoved = moveItems(this, this._solidItems, time);\n const translucentsMoved = moveItems(this, this._translucentItems, time);\n\n //If we moved anything around, we need to re-build the primitive\n if (solidsMoved || translucentsMoved) {\n isUpdated =\n updateItems(this, this._solidItems, time, isUpdated) && isUpdated;\n isUpdated =\n updateItems(this, this._translucentItems, time, isUpdated) && isUpdated;\n }\n\n return isUpdated;\n};\n\nfunction getBoundingSphere(items, updater, result) {\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.contains(updater)) {\n return item.getBoundingSphere(updater, result);\n }\n }\n return BoundingSphereState.FAILED;\n}\n\nStaticGeometryColorBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n const boundingSphere = getBoundingSphere(this._solidItems, updater, result);\n if (boundingSphere === BoundingSphereState.FAILED) {\n return getBoundingSphere(this._translucentItems, updater, result);\n }\n return boundingSphere;\n};\n\nfunction removeAllPrimitives(items) {\n const length = items.length;\n for (let i = 0; i < length; i++) {\n items[i].destroy();\n }\n items.length = 0;\n}\n\nStaticGeometryColorBatch.prototype.removeAllPrimitives = function () {\n removeAllPrimitives(this._solidItems);\n removeAllPrimitives(this._translucentItems);\n};\nexport default StaticGeometryColorBatch;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport Primitive from \"../Scene/Primitive.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\n\nfunction Batch(\n primitives,\n appearanceType,\n materialProperty,\n depthFailAppearanceType,\n depthFailMaterialProperty,\n closed,\n shadows\n) {\n this.primitives = primitives;\n this.appearanceType = appearanceType;\n this.materialProperty = materialProperty;\n this.depthFailAppearanceType = depthFailAppearanceType;\n this.depthFailMaterialProperty = depthFailMaterialProperty;\n this.closed = closed;\n this.shadows = shadows;\n this.updaters = new AssociativeArray();\n this.createPrimitive = true;\n this.primitive = undefined;\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.material = undefined;\n this.depthFailMaterial = undefined;\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.invalidated = false;\n this.removeMaterialSubscription = materialProperty.definitionChanged.addEventListener(\n Batch.prototype.onMaterialChanged,\n this\n );\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n}\n\nBatch.prototype.onMaterialChanged = function () {\n this.invalidated = true;\n};\n\nBatch.prototype.isMaterial = function (updater) {\n const material = this.materialProperty;\n const updaterMaterial = updater.fillMaterialProperty;\n const depthFailMaterial = this.depthFailMaterialProperty;\n const updaterDepthFailMaterial = updater.depthFailMaterialProperty;\n\n if (\n updaterMaterial === material &&\n updaterDepthFailMaterial === depthFailMaterial\n ) {\n return true;\n }\n let equals = defined(material) && material.equals(updaterMaterial);\n equals =\n ((!defined(depthFailMaterial) && !defined(updaterDepthFailMaterial)) ||\n (defined(depthFailMaterial) &&\n depthFailMaterial.equals(updaterDepthFailMaterial))) &&\n equals;\n return equals;\n};\n\nBatch.prototype.add = function (time, updater) {\n const id = updater.id;\n this.updaters.set(id, updater);\n this.geometry.set(id, updater.createFillGeometryInstance(time));\n if (\n !updater.hasConstantFill ||\n !updater.fillMaterialProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty) ||\n !Property.isConstant(updater.terrainOffsetProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n this.createPrimitive = true;\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n this.showsUpdated.remove(id);\n }\n return true;\n }\n return false;\n};\n\nconst colorScratch = new Color();\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n let primitive = this.primitive;\n const primitives = this.primitives;\n const geometries = this.geometry.values;\n let i;\n\n if (this.createPrimitive) {\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n primitives.remove(primitive);\n }\n }\n\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n\n let depthFailAppearance;\n if (defined(this.depthFailMaterialProperty)) {\n this.depthFailMaterial = MaterialProperty.getValue(\n time,\n this.depthFailMaterialProperty,\n this.depthFailMaterial\n );\n depthFailAppearance = new this.depthFailAppearanceType({\n material: this.depthFailMaterial,\n translucent: this.depthFailMaterial.isTranslucent(),\n closed: this.closed,\n });\n }\n\n primitive = new Primitive({\n show: false,\n asynchronous: true,\n geometryInstances: geometries.slice(),\n appearance: new this.appearanceType({\n material: this.material,\n translucent: this.material.isTranslucent(),\n closed: this.closed,\n }),\n depthFailAppearance: depthFailAppearance,\n shadows: this.shadows,\n });\n\n primitives.add(primitive);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n primitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n primitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n this.primitive.appearance.material = this.material;\n\n if (\n defined(this.depthFailAppearanceType) &&\n !(this.depthFailMaterialProperty instanceof ColorMaterialProperty)\n ) {\n this.depthFailMaterial = MaterialProperty.getValue(\n time,\n this.depthFailMaterialProperty,\n this.depthFailMaterial\n );\n this.primitive.depthFailAppearance.material = this.depthFailMaterial;\n }\n\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n if (\n defined(this.depthFailAppearanceType) &&\n this.depthFailMaterialProperty instanceof ColorMaterialProperty &&\n !updater.depthFailMaterialProperty.isConstant\n ) {\n const depthFailColorProperty = updater.depthFailMaterialProperty.color;\n const depthFailColor = Property.getValueOrDefault(\n depthFailColorProperty,\n time,\n Color.WHITE,\n colorScratch\n );\n if (!Color.equals(attributes._lastDepthFailColor, depthFailColor)) {\n attributes._lastDepthFailColor = Color.clone(\n depthFailColor,\n attributes._lastDepthFailColor\n );\n attributes.depthFailColor = ColorGeometryInstanceAttribute.toValue(\n depthFailColor,\n attributes.depthFailColor\n );\n }\n }\n\n const show =\n entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n\n const offsetProperty = updater.terrainOffsetProperty;\n if (!Property.isConstant(offsetProperty)) {\n const offset = Property.getValueOrDefault(\n offsetProperty,\n time,\n defaultOffset,\n offsetScratch\n );\n if (!Cartesian3.equals(offset, attributes._lastOffset)) {\n attributes._lastOffset = Cartesian3.clone(\n offset,\n attributes._lastOffset\n );\n attributes.offset = OffsetGeometryInstanceAttribute.toValue(\n offset,\n attributes.offset\n );\n }\n }\n }\n\n this.updateShows(primitive);\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n const attributes = primitive.getGeometryInstanceAttributes(updater.entity);\n if (\n !defined(attributes) ||\n !defined(attributes.boundingSphere) ||\n (defined(attributes.show) && attributes.show[0] === 0)\n ) {\n return BoundingSphereState.FAILED;\n }\n attributes.boundingSphere.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.destroy = function () {\n const primitive = this.primitive;\n const primitives = this.primitives;\n if (defined(primitive)) {\n primitives.remove(primitive);\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n }\n this.removeMaterialSubscription();\n};\n\n/**\n * @private\n */\nfunction StaticGeometryPerMaterialBatch(\n primitives,\n appearanceType,\n depthFailAppearanceType,\n closed,\n shadows\n) {\n this._items = [];\n this._primitives = primitives;\n this._appearanceType = appearanceType;\n this._depthFailAppearanceType = depthFailAppearanceType;\n this._closed = closed;\n this._shadows = shadows;\n}\n\nStaticGeometryPerMaterialBatch.prototype.add = function (time, updater) {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.isMaterial(updater)) {\n item.add(time, updater);\n return;\n }\n }\n const batch = new Batch(\n this._primitives,\n this._appearanceType,\n updater.fillMaterialProperty,\n this._depthFailAppearanceType,\n updater.depthFailMaterialProperty,\n this._closed,\n this._shadows\n );\n batch.add(time, updater);\n items.push(batch);\n};\n\nStaticGeometryPerMaterialBatch.prototype.remove = function (updater) {\n const items = this._items;\n const length = items.length;\n for (let i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.remove(updater)) {\n if (item.updaters.length === 0) {\n items.splice(i, 1);\n item.destroy();\n }\n break;\n }\n }\n};\n\nStaticGeometryPerMaterialBatch.prototype.update = function (time) {\n let i;\n const items = this._items;\n const length = items.length;\n\n for (i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.invalidated) {\n items.splice(i, 1);\n const updaters = item.updaters.values;\n const updatersLength = updaters.length;\n for (let h = 0; h < updatersLength; h++) {\n this.add(time, updaters[h]);\n }\n item.destroy();\n }\n }\n\n let isUpdated = true;\n for (i = 0; i < items.length; i++) {\n isUpdated = items[i].update(time) && isUpdated;\n }\n return isUpdated;\n};\n\nStaticGeometryPerMaterialBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.contains(updater)) {\n return item.getBoundingSphere(updater, result);\n }\n }\n return BoundingSphereState.FAILED;\n};\n\nStaticGeometryPerMaterialBatch.prototype.removeAllPrimitives = function () {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n items[i].destroy();\n }\n this._items.length = 0;\n};\nexport default StaticGeometryPerMaterialBatch;\n", "import RBush from \"rbush\";\nimport Check from \"./Check.js\";\n\n/**\n * Wrapper around rbush for use with Rectangle types.\n * @private\n */\nfunction RectangleCollisionChecker() {\n this._tree = new RBush();\n}\n\nfunction RectangleWithId() {\n this.minX = 0.0;\n this.minY = 0.0;\n this.maxX = 0.0;\n this.maxY = 0.0;\n this.id = \"\";\n}\n\nRectangleWithId.fromRectangleAndId = function (id, rectangle, result) {\n result.minX = rectangle.west;\n result.minY = rectangle.south;\n result.maxX = rectangle.east;\n result.maxY = rectangle.north;\n result.id = id;\n return result;\n};\n\n/**\n * Insert a rectangle into the collision checker.\n *\n * @param {string} id Unique string ID for the rectangle being inserted.\n * @param {Rectangle} rectangle A Rectangle\n * @private\n */\nRectangleCollisionChecker.prototype.insert = function (id, rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"id\", id);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n const withId = RectangleWithId.fromRectangleAndId(\n id,\n rectangle,\n new RectangleWithId()\n );\n this._tree.insert(withId);\n};\n\nfunction idCompare(a, b) {\n return a.id === b.id;\n}\n\nconst removalScratch = new RectangleWithId();\n/**\n * Remove a rectangle from the collision checker.\n *\n * @param {string} id Unique string ID for the rectangle being removed.\n * @param {Rectangle} rectangle A Rectangle\n * @private\n */\nRectangleCollisionChecker.prototype.remove = function (id, rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.string(\"id\", id);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n const withId = RectangleWithId.fromRectangleAndId(\n id,\n rectangle,\n removalScratch\n );\n this._tree.remove(withId, idCompare);\n};\n\nconst collisionScratch = new RectangleWithId();\n/**\n * Checks if a given rectangle collides with any of the rectangles in the collection.\n *\n * @param {Rectangle} rectangle A Rectangle that should be checked against the rectangles in the collision checker.\n * @returns {boolean} Whether the rectangle collides with any of the rectangles in the collision checker.\n */\nRectangleCollisionChecker.prototype.collides = function (rectangle) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"rectangle\", rectangle);\n //>>includeEnd('debug');\n\n const withId = RectangleWithId.fromRectangleAndId(\n \"\",\n rectangle,\n collisionScratch\n );\n return this._tree.collides(withId);\n};\nexport default RectangleCollisionChecker;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\nimport RectangleCollisionChecker from \"../Core/RectangleCollisionChecker.js\";\n\nconst colorScratch = new Color();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\n\nfunction Batch(primitives, classificationType, color, zIndex) {\n this.primitives = primitives;\n this.zIndex = zIndex;\n this.classificationType = classificationType;\n this.color = color;\n this.createPrimitive = false;\n this.waitingOnCreate = false;\n this.primitive = undefined;\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.updaters = new AssociativeArray();\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n this.itemsToRemove = [];\n this.isDirty = false;\n this.rectangleCollisionCheck = new RectangleCollisionChecker();\n}\n\nBatch.prototype.overlapping = function (rectangle) {\n return this.rectangleCollisionCheck.collides(rectangle);\n};\n\nBatch.prototype.add = function (updater, instance) {\n const id = updater.id;\n this.createPrimitive = true;\n this.geometry.set(id, instance);\n this.updaters.set(id, updater);\n this.rectangleCollisionCheck.insert(id, instance.geometry.rectangle);\n if (\n !updater.hasConstantFill ||\n !updater.fillMaterialProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n const geometryInstance = this.geometry.get(id);\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.rectangleCollisionCheck.remove(\n id,\n geometryInstance.geometry.rectangle\n );\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n this.showsUpdated.remove(id);\n }\n return true;\n }\n return false;\n};\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n const removedCount = 0;\n let primitive = this.primitive;\n const primitives = this.primitives;\n let i;\n\n if (this.createPrimitive) {\n const geometries = this.geometry.values;\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n primitives.remove(primitive);\n }\n }\n\n primitive = new GroundPrimitive({\n show: false,\n asynchronous: true,\n geometryInstances: geometries.slice(),\n classificationType: this.classificationType,\n });\n primitives.add(primitive, this.zIndex);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n primitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n this.waitingOnCreate = true;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n primitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n const waitingOnCreate = this.waitingOnCreate;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n if (!updater.fillMaterialProperty.isConstant || waitingOnCreate) {\n const colorProperty = updater.fillMaterialProperty.color;\n const fillColor = Property.getValueOrDefault(\n colorProperty,\n time,\n Color.WHITE,\n colorScratch\n );\n\n if (!Color.equals(attributes._lastColor, fillColor)) {\n attributes._lastColor = Color.clone(fillColor, attributes._lastColor);\n attributes.color = ColorGeometryInstanceAttribute.toValue(\n fillColor,\n attributes.color\n );\n }\n }\n\n const show =\n updater.entity.isShowing &&\n (updater.hasConstantFill || updater.isFilled(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n }\n\n this.updateShows(primitive);\n this.waitingOnCreate = false;\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n this.itemsToRemove.length = removedCount;\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = updater.entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n\n const bs = primitive.getBoundingSphere(updater.entity);\n if (!defined(bs)) {\n return BoundingSphereState.FAILED;\n }\n\n bs.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.removeAllPrimitives = function () {\n const primitives = this.primitives;\n\n const primitive = this.primitive;\n if (defined(primitive)) {\n primitives.remove(primitive);\n this.primitive = undefined;\n this.geometry.removeAll();\n this.updaters.removeAll();\n }\n\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n};\n\n/**\n * @private\n */\nfunction StaticGroundGeometryColorBatch(primitives, classificationType) {\n this._batches = [];\n this._primitives = primitives;\n this._classificationType = classificationType;\n}\n\nStaticGroundGeometryColorBatch.prototype.add = function (time, updater) {\n const instance = updater.createFillGeometryInstance(time);\n const batches = this._batches;\n const zIndex = Property.getValueOrDefault(updater.zIndex, 0);\n let batch;\n const length = batches.length;\n for (let i = 0; i < length; ++i) {\n const item = batches[i];\n if (\n item.zIndex === zIndex &&\n !item.overlapping(instance.geometry.rectangle)\n ) {\n batch = item;\n break;\n }\n }\n\n if (!defined(batch)) {\n batch = new Batch(\n this._primitives,\n this._classificationType,\n instance.attributes.color.value,\n zIndex\n );\n batches.push(batch);\n }\n batch.add(updater, instance);\n return batch;\n};\n\nStaticGroundGeometryColorBatch.prototype.remove = function (updater) {\n const batches = this._batches;\n const count = batches.length;\n for (let i = 0; i < count; ++i) {\n if (batches[i].remove(updater)) {\n return;\n }\n }\n};\n\nStaticGroundGeometryColorBatch.prototype.update = function (time) {\n let i;\n let updater;\n\n //Perform initial update\n let isUpdated = true;\n const batches = this._batches;\n const batchCount = batches.length;\n for (i = 0; i < batchCount; ++i) {\n isUpdated = batches[i].update(time) && isUpdated;\n }\n\n //If any items swapped between batches we need to move them\n for (i = 0; i < batchCount; ++i) {\n const oldBatch = batches[i];\n const itemsToRemove = oldBatch.itemsToRemove;\n const itemsToMoveLength = itemsToRemove.length;\n for (let j = 0; j < itemsToMoveLength; j++) {\n updater = itemsToRemove[j];\n oldBatch.remove(updater);\n const newBatch = this.add(time, updater);\n oldBatch.isDirty = true;\n newBatch.isDirty = true;\n }\n }\n\n //If we moved anything around, we need to re-build the primitive and remove empty batches\n for (i = batchCount - 1; i >= 0; --i) {\n const batch = batches[i];\n if (batch.isDirty) {\n isUpdated = batches[i].update(time) && isUpdated;\n batch.isDirty = false;\n }\n if (batch.geometry.length === 0) {\n batches.splice(i, 1);\n }\n }\n\n return isUpdated;\n};\n\nStaticGroundGeometryColorBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n const batches = this._batches;\n const batchCount = batches.length;\n for (let i = 0; i < batchCount; ++i) {\n const batch = batches[i];\n if (batch.contains(updater)) {\n return batch.getBoundingSphere(updater, result);\n }\n }\n\n return BoundingSphereState.FAILED;\n};\n\nStaticGroundGeometryColorBatch.prototype.removeAllPrimitives = function () {\n const batches = this._batches;\n const batchCount = batches.length;\n for (let i = 0; i < batchCount; ++i) {\n batches[i].removeAllPrimitives();\n }\n};\nexport default StaticGroundGeometryColorBatch;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport RectangleCollisionChecker from \"../Core/RectangleCollisionChecker.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport ShadowVolumeAppearance from \"../Scene/ShadowVolumeAppearance.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\n\n// Encapsulates a Primitive and all the entities that it represents.\nfunction Batch(\n primitives,\n classificationType,\n appearanceType,\n materialProperty,\n usingSphericalTextureCoordinates,\n zIndex\n) {\n this.primitives = primitives; // scene level primitive collection\n this.classificationType = classificationType;\n this.appearanceType = appearanceType;\n this.materialProperty = materialProperty;\n this.updaters = new AssociativeArray();\n this.createPrimitive = true;\n this.primitive = undefined; // a GroundPrimitive encapsulating all the entities\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.material = undefined;\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.invalidated = false;\n this.removeMaterialSubscription = materialProperty.definitionChanged.addEventListener(\n Batch.prototype.onMaterialChanged,\n this\n );\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n this.usingSphericalTextureCoordinates = usingSphericalTextureCoordinates;\n this.zIndex = zIndex;\n this.rectangleCollisionCheck = new RectangleCollisionChecker();\n}\n\nBatch.prototype.onMaterialChanged = function () {\n this.invalidated = true;\n};\n\nBatch.prototype.overlapping = function (rectangle) {\n return this.rectangleCollisionCheck.collides(rectangle);\n};\n\n// Check if the given updater's material is compatible with this batch\nBatch.prototype.isMaterial = function (updater) {\n const material = this.materialProperty;\n const updaterMaterial = updater.fillMaterialProperty;\n\n if (\n updaterMaterial === material ||\n (updaterMaterial instanceof ColorMaterialProperty &&\n material instanceof ColorMaterialProperty)\n ) {\n return true;\n }\n return defined(material) && material.equals(updaterMaterial);\n};\n\nBatch.prototype.add = function (time, updater, geometryInstance) {\n const id = updater.id;\n this.updaters.set(id, updater);\n this.geometry.set(id, geometryInstance);\n this.rectangleCollisionCheck.insert(id, geometryInstance.geometry.rectangle);\n // Updaters with dynamic attributes must be tracked separately, may exit the batch\n if (\n !updater.hasConstantFill ||\n !updater.fillMaterialProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n // Listen for show changes. These will be synchronized in updateShows.\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n this.createPrimitive = true;\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n const geometryInstance = this.geometry.get(id);\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.rectangleCollisionCheck.remove(\n id,\n geometryInstance.geometry.rectangle\n );\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n }\n return true;\n }\n return false;\n};\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n let primitive = this.primitive;\n const primitives = this.primitives;\n const geometries = this.geometry.values;\n let i;\n\n if (this.createPrimitive) {\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n // Keep a handle to the old primitive so it can be removed when the updated version is ready.\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n // For if the new primitive changes again before it is ready.\n primitives.remove(primitive);\n }\n }\n\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n\n primitive = new GroundPrimitive({\n show: false,\n asynchronous: true,\n geometryInstances: geometries.slice(),\n appearance: new this.appearanceType({\n material: this.material,\n // translucent and closed properties overridden\n }),\n classificationType: this.classificationType,\n });\n\n primitives.add(primitive, this.zIndex);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n primitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n primitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n this.primitive.appearance.material = this.material;\n\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show =\n entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n }\n\n this.updateShows(primitive);\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n const attributes = primitive.getGeometryInstanceAttributes(updater.entity);\n if (\n !defined(attributes) ||\n !defined(attributes.boundingSphere) ||\n (defined(attributes.show) && attributes.show[0] === 0)\n ) {\n return BoundingSphereState.FAILED;\n }\n attributes.boundingSphere.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.destroy = function () {\n const primitive = this.primitive;\n const primitives = this.primitives;\n if (defined(primitive)) {\n primitives.remove(primitive);\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n }\n this.removeMaterialSubscription();\n};\n\n/**\n * @private\n */\nfunction StaticGroundGeometryPerMaterialBatch(\n primitives,\n classificationType,\n appearanceType\n) {\n this._items = [];\n this._primitives = primitives;\n this._classificationType = classificationType;\n this._appearanceType = appearanceType;\n}\n\nStaticGroundGeometryPerMaterialBatch.prototype.add = function (time, updater) {\n const items = this._items;\n const length = items.length;\n const geometryInstance = updater.createFillGeometryInstance(time);\n const usingSphericalTextureCoordinates = ShadowVolumeAppearance.shouldUseSphericalCoordinates(\n geometryInstance.geometry.rectangle\n );\n const zIndex = Property.getValueOrDefault(updater.zIndex, 0);\n // Check if the Entity represented by the updater can be placed in an existing batch. Requirements:\n // * compatible material (same material or same color)\n // * same type of texture coordinates (spherical vs. planar)\n // * conservatively non-overlapping with any entities in the existing batch\n for (let i = 0; i < length; ++i) {\n const item = items[i];\n if (\n item.isMaterial(updater) &&\n item.usingSphericalTextureCoordinates ===\n usingSphericalTextureCoordinates &&\n item.zIndex === zIndex &&\n !item.overlapping(geometryInstance.geometry.rectangle)\n ) {\n item.add(time, updater, geometryInstance);\n return;\n }\n }\n // If a compatible batch wasn't found, create a new batch.\n const batch = new Batch(\n this._primitives,\n this._classificationType,\n this._appearanceType,\n updater.fillMaterialProperty,\n usingSphericalTextureCoordinates,\n zIndex\n );\n batch.add(time, updater, geometryInstance);\n items.push(batch);\n};\n\nStaticGroundGeometryPerMaterialBatch.prototype.remove = function (updater) {\n const items = this._items;\n const length = items.length;\n for (let i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.remove(updater)) {\n if (item.updaters.length === 0) {\n items.splice(i, 1);\n item.destroy();\n }\n break;\n }\n }\n};\n\nStaticGroundGeometryPerMaterialBatch.prototype.update = function (time) {\n let i;\n const items = this._items;\n const length = items.length;\n\n for (i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.invalidated) {\n items.splice(i, 1);\n const updaters = item.updaters.values;\n const updatersLength = updaters.length;\n for (let h = 0; h < updatersLength; h++) {\n this.add(time, updaters[h]);\n }\n item.destroy();\n }\n }\n\n let isUpdated = true;\n for (i = 0; i < items.length; i++) {\n isUpdated = items[i].update(time) && isUpdated;\n }\n return isUpdated;\n};\n\nStaticGroundGeometryPerMaterialBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.contains(updater)) {\n return item.getBoundingSphere(updater, result);\n }\n }\n return BoundingSphereState.FAILED;\n};\n\nStaticGroundGeometryPerMaterialBatch.prototype.removeAllPrimitives = function () {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n items[i].destroy();\n }\n this._items.length = 0;\n};\nexport default StaticGroundGeometryPerMaterialBatch;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport OffsetGeometryInstanceAttribute from \"../Core/OffsetGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport Primitive from \"../Scene/Primitive.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\n\nconst colorScratch = new Color();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\nconst defaultOffset = Cartesian3.ZERO;\nconst offsetScratch = new Cartesian3();\n\nfunction Batch(primitives, translucent, width, shadows) {\n this.translucent = translucent;\n this.width = width;\n this.shadows = shadows;\n this.primitives = primitives;\n this.createPrimitive = false;\n this.waitingOnCreate = false;\n this.primitive = undefined;\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.updaters = new AssociativeArray();\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.itemsToRemove = [];\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n}\nBatch.prototype.add = function (updater, instance) {\n const id = updater.id;\n this.createPrimitive = true;\n this.geometry.set(id, instance);\n this.updaters.set(id, updater);\n if (\n !updater.hasConstantOutline ||\n !updater.outlineColorProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty) ||\n !Property.isConstant(updater.terrainOffsetProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n this.showsUpdated.remove(id);\n }\n return true;\n }\n return false;\n};\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n let removedCount = 0;\n let primitive = this.primitive;\n const primitives = this.primitives;\n let i;\n\n if (this.createPrimitive) {\n const geometries = this.geometry.values;\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n primitives.remove(primitive);\n }\n }\n\n primitive = new Primitive({\n show: false,\n asynchronous: true,\n geometryInstances: geometries.slice(),\n appearance: new PerInstanceColorAppearance({\n flat: true,\n translucent: this.translucent,\n renderState: {\n lineWidth: this.width,\n },\n }),\n shadows: this.shadows,\n });\n\n primitives.add(primitive);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n primitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n this.waitingOnCreate = true;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n primitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n const waitingOnCreate = this.waitingOnCreate;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n if (!updater.outlineColorProperty.isConstant || waitingOnCreate) {\n const outlineColorProperty = updater.outlineColorProperty;\n const outlineColor = Property.getValueOrDefault(\n outlineColorProperty,\n time,\n Color.WHITE,\n colorScratch\n );\n if (!Color.equals(attributes._lastColor, outlineColor)) {\n attributes._lastColor = Color.clone(\n outlineColor,\n attributes._lastColor\n );\n attributes.color = ColorGeometryInstanceAttribute.toValue(\n outlineColor,\n attributes.color\n );\n if (\n (this.translucent && attributes.color[3] === 255) ||\n (!this.translucent && attributes.color[3] !== 255)\n ) {\n this.itemsToRemove[removedCount++] = updater;\n }\n }\n }\n\n const show =\n updater.entity.isShowing &&\n (updater.hasConstantOutline || updater.isOutlineVisible(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n\n const offsetProperty = updater.terrainOffsetProperty;\n if (!Property.isConstant(offsetProperty)) {\n const offset = Property.getValueOrDefault(\n offsetProperty,\n time,\n defaultOffset,\n offsetScratch\n );\n if (!Cartesian3.equals(offset, attributes._lastOffset)) {\n attributes._lastOffset = Cartesian3.clone(\n offset,\n attributes._lastOffset\n );\n attributes.offset = OffsetGeometryInstanceAttribute.toValue(\n offset,\n attributes.offset\n );\n }\n }\n }\n\n this.updateShows(primitive);\n this.waitingOnCreate = false;\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n\n this.itemsToRemove.length = removedCount;\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = updater.entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n const attributes = primitive.getGeometryInstanceAttributes(updater.entity);\n if (\n !defined(attributes) ||\n !defined(attributes.boundingSphere) || //\n (defined(attributes.show) && attributes.show[0] === 0)\n ) {\n return BoundingSphereState.FAILED;\n }\n attributes.boundingSphere.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.removeAllPrimitives = function () {\n const primitives = this.primitives;\n\n const primitive = this.primitive;\n if (defined(primitive)) {\n primitives.remove(primitive);\n this.primitive = undefined;\n this.geometry.removeAll();\n this.updaters.removeAll();\n }\n\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n primitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n};\n\n/**\n * @private\n */\nfunction StaticOutlineGeometryBatch(primitives, scene, shadows) {\n this._primitives = primitives;\n this._scene = scene;\n this._shadows = shadows;\n this._solidBatches = new AssociativeArray();\n this._translucentBatches = new AssociativeArray();\n}\nStaticOutlineGeometryBatch.prototype.add = function (time, updater) {\n const instance = updater.createOutlineGeometryInstance(time);\n const width = this._scene.clampLineWidth(updater.outlineWidth);\n let batches;\n let batch;\n if (instance.attributes.color.value[3] === 255) {\n batches = this._solidBatches;\n batch = batches.get(width);\n if (!defined(batch)) {\n batch = new Batch(this._primitives, false, width, this._shadows);\n batches.set(width, batch);\n }\n batch.add(updater, instance);\n } else {\n batches = this._translucentBatches;\n batch = batches.get(width);\n if (!defined(batch)) {\n batch = new Batch(this._primitives, true, width, this._shadows);\n batches.set(width, batch);\n }\n batch.add(updater, instance);\n }\n};\n\nStaticOutlineGeometryBatch.prototype.remove = function (updater) {\n let i;\n\n const solidBatches = this._solidBatches.values;\n const solidBatchesLength = solidBatches.length;\n for (i = 0; i < solidBatchesLength; i++) {\n if (solidBatches[i].remove(updater)) {\n return;\n }\n }\n\n const translucentBatches = this._translucentBatches.values;\n const translucentBatchesLength = translucentBatches.length;\n for (i = 0; i < translucentBatchesLength; i++) {\n if (translucentBatches[i].remove(updater)) {\n return;\n }\n }\n};\n\nStaticOutlineGeometryBatch.prototype.update = function (time) {\n let i;\n let x;\n let updater;\n let batch;\n const solidBatches = this._solidBatches.values;\n const solidBatchesLength = solidBatches.length;\n const translucentBatches = this._translucentBatches.values;\n const translucentBatchesLength = translucentBatches.length;\n let itemsToRemove;\n let isUpdated = true;\n let needUpdate = false;\n\n do {\n needUpdate = false;\n for (x = 0; x < solidBatchesLength; x++) {\n batch = solidBatches[x];\n //Perform initial update\n isUpdated = batch.update(time);\n\n //If any items swapped between solid/translucent, we need to\n //move them between batches\n itemsToRemove = batch.itemsToRemove;\n const solidsToMoveLength = itemsToRemove.length;\n if (solidsToMoveLength > 0) {\n needUpdate = true;\n for (i = 0; i < solidsToMoveLength; i++) {\n updater = itemsToRemove[i];\n batch.remove(updater);\n this.add(time, updater);\n }\n }\n }\n for (x = 0; x < translucentBatchesLength; x++) {\n batch = translucentBatches[x];\n //Perform initial update\n isUpdated = batch.update(time);\n\n //If any items swapped between solid/translucent, we need to\n //move them between batches\n itemsToRemove = batch.itemsToRemove;\n const translucentToMoveLength = itemsToRemove.length;\n if (translucentToMoveLength > 0) {\n needUpdate = true;\n for (i = 0; i < translucentToMoveLength; i++) {\n updater = itemsToRemove[i];\n batch.remove(updater);\n this.add(time, updater);\n }\n }\n }\n } while (needUpdate);\n\n return isUpdated;\n};\n\nStaticOutlineGeometryBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n let i;\n\n const solidBatches = this._solidBatches.values;\n const solidBatchesLength = solidBatches.length;\n for (i = 0; i < solidBatchesLength; i++) {\n const solidBatch = solidBatches[i];\n if (solidBatch.contains(updater)) {\n return solidBatch.getBoundingSphere(updater, result);\n }\n }\n\n const translucentBatches = this._translucentBatches.values;\n const translucentBatchesLength = translucentBatches.length;\n for (i = 0; i < translucentBatchesLength; i++) {\n const translucentBatch = translucentBatches[i];\n if (translucentBatch.contains(updater)) {\n return translucentBatch.getBoundingSphere(updater, result);\n }\n }\n\n return BoundingSphereState.FAILED;\n};\n\nStaticOutlineGeometryBatch.prototype.removeAllPrimitives = function () {\n let i;\n\n const solidBatches = this._solidBatches.values;\n const solidBatchesLength = solidBatches.length;\n for (i = 0; i < solidBatchesLength; i++) {\n solidBatches[i].removeAllPrimitives();\n }\n\n const translucentBatches = this._translucentBatches.values;\n const translucentBatchesLength = translucentBatches.length;\n for (i = 0; i < translucentBatchesLength; i++) {\n translucentBatches[i].removeAllPrimitives();\n }\n};\nexport default StaticOutlineGeometryBatch;\n", "import arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Cartographic from \"./Cartographic.js\";\nimport defined from \"./defined.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolylinePipeline from \"./PolylinePipeline.js\";\n\n/**\n * @private\n */\nconst WallGeometryLibrary = {};\n\nfunction latLonEquals(c0, c1) {\n return (\n CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, CesiumMath.EPSILON10) &&\n CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, CesiumMath.EPSILON10)\n );\n}\n\nconst scratchCartographic1 = new Cartographic();\nconst scratchCartographic2 = new Cartographic();\nfunction removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) {\n positions = arrayRemoveDuplicates(positions, Cartesian3.equalsEpsilon);\n\n const length = positions.length;\n if (length < 2) {\n return;\n }\n\n const hasBottomHeights = defined(bottomHeights);\n const hasTopHeights = defined(topHeights);\n\n const cleanedPositions = new Array(length);\n const cleanedTopHeights = new Array(length);\n const cleanedBottomHeights = new Array(length);\n\n const v0 = positions[0];\n cleanedPositions[0] = v0;\n\n const c0 = ellipsoid.cartesianToCartographic(v0, scratchCartographic1);\n if (hasTopHeights) {\n c0.height = topHeights[0];\n }\n\n cleanedTopHeights[0] = c0.height;\n\n if (hasBottomHeights) {\n cleanedBottomHeights[0] = bottomHeights[0];\n } else {\n cleanedBottomHeights[0] = 0.0;\n }\n\n const startTopHeight = cleanedTopHeights[0];\n const startBottomHeight = cleanedBottomHeights[0];\n let hasAllSameHeights = startTopHeight === startBottomHeight;\n\n let index = 1;\n for (let i = 1; i < length; ++i) {\n const v1 = positions[i];\n const c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);\n if (hasTopHeights) {\n c1.height = topHeights[i];\n }\n hasAllSameHeights = hasAllSameHeights && c1.height === 0;\n\n if (!latLonEquals(c0, c1)) {\n cleanedPositions[index] = v1; // Shallow copy!\n cleanedTopHeights[index] = c1.height;\n\n if (hasBottomHeights) {\n cleanedBottomHeights[index] = bottomHeights[i];\n } else {\n cleanedBottomHeights[index] = 0.0;\n }\n hasAllSameHeights =\n hasAllSameHeights &&\n cleanedTopHeights[index] === cleanedBottomHeights[index];\n\n Cartographic.clone(c1, c0);\n ++index;\n } else if (c0.height < c1.height) {\n // two adjacent positions are the same, so use whichever has the greater height\n cleanedTopHeights[index - 1] = c1.height;\n }\n }\n\n if (hasAllSameHeights || index < 2) {\n return;\n }\n\n cleanedPositions.length = index;\n cleanedTopHeights.length = index;\n cleanedBottomHeights.length = index;\n\n return {\n positions: cleanedPositions,\n topHeights: cleanedTopHeights,\n bottomHeights: cleanedBottomHeights,\n };\n}\n\nconst positionsArrayScratch = new Array(2);\nconst heightsArrayScratch = new Array(2);\nconst generateArcOptionsScratch = {\n positions: undefined,\n height: undefined,\n granularity: undefined,\n ellipsoid: undefined,\n};\n\n/**\n * @private\n */\nWallGeometryLibrary.computePositions = function (\n ellipsoid,\n wallPositions,\n maximumHeights,\n minimumHeights,\n granularity,\n duplicateCorners\n) {\n const o = removeDuplicates(\n ellipsoid,\n wallPositions,\n maximumHeights,\n minimumHeights\n );\n\n if (!defined(o)) {\n return;\n }\n\n wallPositions = o.positions;\n maximumHeights = o.topHeights;\n minimumHeights = o.bottomHeights;\n\n const length = wallPositions.length;\n const numCorners = length - 2;\n let topPositions;\n let bottomPositions;\n\n const minDistance = CesiumMath.chordLength(\n granularity,\n ellipsoid.maximumRadius\n );\n\n const generateArcOptions = generateArcOptionsScratch;\n generateArcOptions.minDistance = minDistance;\n generateArcOptions.ellipsoid = ellipsoid;\n\n if (duplicateCorners) {\n let count = 0;\n let i;\n\n for (i = 0; i < length - 1; i++) {\n count +=\n PolylinePipeline.numberOfPoints(\n wallPositions[i],\n wallPositions[i + 1],\n minDistance\n ) + 1;\n }\n\n topPositions = new Float64Array(count * 3);\n bottomPositions = new Float64Array(count * 3);\n\n const generateArcPositions = positionsArrayScratch;\n const generateArcHeights = heightsArrayScratch;\n generateArcOptions.positions = generateArcPositions;\n generateArcOptions.height = generateArcHeights;\n\n let offset = 0;\n for (i = 0; i < length - 1; i++) {\n generateArcPositions[0] = wallPositions[i];\n generateArcPositions[1] = wallPositions[i + 1];\n\n generateArcHeights[0] = maximumHeights[i];\n generateArcHeights[1] = maximumHeights[i + 1];\n\n const pos = PolylinePipeline.generateArc(generateArcOptions);\n topPositions.set(pos, offset);\n\n generateArcHeights[0] = minimumHeights[i];\n generateArcHeights[1] = minimumHeights[i + 1];\n\n bottomPositions.set(\n PolylinePipeline.generateArc(generateArcOptions),\n offset\n );\n\n offset += pos.length;\n }\n } else {\n generateArcOptions.positions = wallPositions;\n generateArcOptions.height = maximumHeights;\n topPositions = new Float64Array(\n PolylinePipeline.generateArc(generateArcOptions)\n );\n\n generateArcOptions.height = minimumHeights;\n bottomPositions = new Float64Array(\n PolylinePipeline.generateArc(generateArcOptions)\n );\n }\n\n return {\n bottomPositions: bottomPositions,\n topPositions: topPositions,\n numCorners: numCorners,\n };\n};\nexport default WallGeometryLibrary;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\nimport WallGeometryLibrary from \"./WallGeometryLibrary.js\";\n\nconst scratchCartesian3Position1 = new Cartesian3();\nconst scratchCartesian3Position2 = new Cartesian3();\nconst scratchCartesian3Position4 = new Cartesian3();\nconst scratchCartesian3Position5 = new Cartesian3();\nconst scratchBitangent = new Cartesian3();\nconst scratchTangent = new Cartesian3();\nconst scratchNormal = new Cartesian3();\n\n/**\n * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,\n * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.\n *\n * @alias WallGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number[]} [options.maximumHeights] An array parallel to positions that give the maximum height of the\n * wall at positions. If undefined, the height of each position in used.\n * @param {number[]} [options.minimumHeights] An array parallel to positions that give the minimum height of the\n * wall at positions. If undefined, the height at each position is 0.0.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n *\n * @exception {DeveloperError} positions length must be greater than or equal to 2.\n * @exception {DeveloperError} positions and maximumHeights must have the same length.\n * @exception {DeveloperError} positions and minimumHeights must have the same length.\n *\n * @see WallGeometry#createGeometry\n * @see WallGeometry#fromConstantHeight\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Wall.html|Cesium Sandcastle Wall Demo}\n *\n * @example\n * // create a wall that spans from ground level to 10000 meters\n * const wall = new Cesium.WallGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArrayHeights([\n * 19.0, 47.0, 10000.0,\n * 19.0, 48.0, 10000.0,\n * 20.0, 48.0, 10000.0,\n * 20.0, 47.0, 10000.0,\n * 19.0, 47.0, 10000.0\n * ])\n * });\n * const geometry = Cesium.WallGeometry.createGeometry(wall);\n */\nfunction WallGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const wallPositions = options.positions;\n const maximumHeights = options.maximumHeights;\n const minimumHeights = options.minimumHeights;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(wallPositions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n if (\n defined(maximumHeights) &&\n maximumHeights.length !== wallPositions.length\n ) {\n throw new DeveloperError(\n \"options.positions and options.maximumHeights must have the same length.\"\n );\n }\n if (\n defined(minimumHeights) &&\n minimumHeights.length !== wallPositions.length\n ) {\n throw new DeveloperError(\n \"options.positions and options.minimumHeights must have the same length.\"\n );\n }\n //>>includeEnd('debug');\n\n const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n this._positions = wallPositions;\n this._minimumHeights = minimumHeights;\n this._maximumHeights = maximumHeights;\n this._vertexFormat = VertexFormat.clone(vertexFormat);\n this._granularity = granularity;\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._workerName = \"createWallGeometry\";\n\n let numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2;\n if (defined(minimumHeights)) {\n numComponents += minimumHeights.length;\n }\n if (defined(maximumHeights)) {\n numComponents += maximumHeights.length;\n }\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 1;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {WallGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nWallGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n const positions = value._positions;\n let length = positions.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n const minimumHeights = value._minimumHeights;\n length = defined(minimumHeights) ? minimumHeights.length : 0;\n array[startingIndex++] = length;\n\n if (defined(minimumHeights)) {\n for (i = 0; i < length; ++i) {\n array[startingIndex++] = minimumHeights[i];\n }\n }\n\n const maximumHeights = value._maximumHeights;\n length = defined(maximumHeights) ? maximumHeights.length : 0;\n array[startingIndex++] = length;\n\n if (defined(maximumHeights)) {\n for (i = 0; i < length; ++i) {\n array[startingIndex++] = maximumHeights[i];\n }\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex] = value._granularity;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n positions: undefined,\n minimumHeights: undefined,\n maximumHeights: undefined,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n granularity: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {WallGeometry} [result] The object into which to store the result.\n * @returns {WallGeometry} The modified result parameter or a new WallGeometry instance if one was not provided.\n */\nWallGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n let length = array[startingIndex++];\n const positions = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n length = array[startingIndex++];\n let minimumHeights;\n\n if (length > 0) {\n minimumHeights = new Array(length);\n for (i = 0; i < length; ++i) {\n minimumHeights[i] = array[startingIndex++];\n }\n }\n\n length = array[startingIndex++];\n let maximumHeights;\n\n if (length > 0) {\n maximumHeights = new Array(length);\n for (i = 0; i < length; ++i) {\n maximumHeights[i] = array[startingIndex++];\n }\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const granularity = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.positions = positions;\n scratchOptions.minimumHeights = minimumHeights;\n scratchOptions.maximumHeights = maximumHeights;\n scratchOptions.granularity = granularity;\n return new WallGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._minimumHeights = minimumHeights;\n result._maximumHeights = maximumHeights;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._granularity = granularity;\n\n return result;\n};\n\n/**\n * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,\n * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.\n * @param {number} [options.maximumHeight] A constant that defines the maximum height of the\n * wall at positions. If undefined, the height of each position in used.\n * @param {number} [options.minimumHeight] A constant that defines the minimum height of the\n * wall at positions. If undefined, the height at each position is 0.0.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @returns {WallGeometry}\n *\n *\n * @example\n * // create a wall that spans from 10000 meters to 20000 meters\n * const wall = Cesium.WallGeometry.fromConstantHeights({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 19.0, 47.0,\n * 19.0, 48.0,\n * 20.0, 48.0,\n * 20.0, 47.0,\n * 19.0, 47.0,\n * ]),\n * minimumHeight : 20000.0,\n * maximumHeight : 10000.0\n * });\n * const geometry = Cesium.WallGeometry.createGeometry(wall);\n *\n * @see WallGeometry#createGeometry\n */\nWallGeometry.fromConstantHeights = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n //>>includeEnd('debug');\n\n let minHeights;\n let maxHeights;\n\n const min = options.minimumHeight;\n const max = options.maximumHeight;\n\n const doMin = defined(min);\n const doMax = defined(max);\n if (doMin || doMax) {\n const length = positions.length;\n minHeights = doMin ? new Array(length) : undefined;\n maxHeights = doMax ? new Array(length) : undefined;\n\n for (let i = 0; i < length; ++i) {\n if (doMin) {\n minHeights[i] = min;\n }\n\n if (doMax) {\n maxHeights[i] = max;\n }\n }\n }\n\n const newOptions = {\n positions: positions,\n maximumHeights: maxHeights,\n minimumHeights: minHeights,\n ellipsoid: options.ellipsoid,\n vertexFormat: options.vertexFormat,\n };\n return new WallGeometry(newOptions);\n};\n\n/**\n * Computes the geometric representation of a wall, including its vertices, indices, and a bounding sphere.\n *\n * @param {WallGeometry} wallGeometry A description of the wall.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nWallGeometry.createGeometry = function (wallGeometry) {\n const wallPositions = wallGeometry._positions;\n const minimumHeights = wallGeometry._minimumHeights;\n const maximumHeights = wallGeometry._maximumHeights;\n const vertexFormat = wallGeometry._vertexFormat;\n const granularity = wallGeometry._granularity;\n const ellipsoid = wallGeometry._ellipsoid;\n\n const pos = WallGeometryLibrary.computePositions(\n ellipsoid,\n wallPositions,\n maximumHeights,\n minimumHeights,\n granularity,\n true\n );\n if (!defined(pos)) {\n return;\n }\n\n const bottomPositions = pos.bottomPositions;\n const topPositions = pos.topPositions;\n const numCorners = pos.numCorners;\n\n let length = topPositions.length;\n let size = length * 2;\n\n const positions = vertexFormat.position ? new Float64Array(size) : undefined;\n const normals = vertexFormat.normal ? new Float32Array(size) : undefined;\n const tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;\n const bitangents = vertexFormat.bitangent\n ? new Float32Array(size)\n : undefined;\n const textureCoordinates = vertexFormat.st\n ? new Float32Array((size / 3) * 2)\n : undefined;\n\n let positionIndex = 0;\n let normalIndex = 0;\n let bitangentIndex = 0;\n let tangentIndex = 0;\n let stIndex = 0;\n\n // add lower and upper points one after the other, lower\n // points being even and upper points being odd\n let normal = scratchNormal;\n let tangent = scratchTangent;\n let bitangent = scratchBitangent;\n let recomputeNormal = true;\n length /= 3;\n let i;\n let s = 0;\n const ds = 1 / (length - numCorners - 1);\n for (i = 0; i < length; ++i) {\n const i3 = i * 3;\n const topPosition = Cartesian3.fromArray(\n topPositions,\n i3,\n scratchCartesian3Position1\n );\n const bottomPosition = Cartesian3.fromArray(\n bottomPositions,\n i3,\n scratchCartesian3Position2\n );\n if (vertexFormat.position) {\n // insert the lower point\n positions[positionIndex++] = bottomPosition.x;\n positions[positionIndex++] = bottomPosition.y;\n positions[positionIndex++] = bottomPosition.z;\n\n // insert the upper point\n positions[positionIndex++] = topPosition.x;\n positions[positionIndex++] = topPosition.y;\n positions[positionIndex++] = topPosition.z;\n }\n\n if (vertexFormat.st) {\n textureCoordinates[stIndex++] = s;\n textureCoordinates[stIndex++] = 0.0;\n\n textureCoordinates[stIndex++] = s;\n textureCoordinates[stIndex++] = 1.0;\n }\n\n if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.bitangent) {\n let nextTop = Cartesian3.clone(\n Cartesian3.ZERO,\n scratchCartesian3Position5\n );\n const groundPosition = Cartesian3.subtract(\n topPosition,\n ellipsoid.geodeticSurfaceNormal(\n topPosition,\n scratchCartesian3Position2\n ),\n scratchCartesian3Position2\n );\n if (i + 1 < length) {\n nextTop = Cartesian3.fromArray(\n topPositions,\n i3 + 3,\n scratchCartesian3Position5\n );\n }\n\n if (recomputeNormal) {\n const scalednextPosition = Cartesian3.subtract(\n nextTop,\n topPosition,\n scratchCartesian3Position4\n );\n const scaledGroundPosition = Cartesian3.subtract(\n groundPosition,\n topPosition,\n scratchCartesian3Position1\n );\n normal = Cartesian3.normalize(\n Cartesian3.cross(scaledGroundPosition, scalednextPosition, normal),\n normal\n );\n recomputeNormal = false;\n }\n\n if (\n Cartesian3.equalsEpsilon(topPosition, nextTop, CesiumMath.EPSILON10)\n ) {\n recomputeNormal = true;\n } else {\n s += ds;\n if (vertexFormat.tangent) {\n tangent = Cartesian3.normalize(\n Cartesian3.subtract(nextTop, topPosition, tangent),\n tangent\n );\n }\n if (vertexFormat.bitangent) {\n bitangent = Cartesian3.normalize(\n Cartesian3.cross(normal, tangent, bitangent),\n bitangent\n );\n }\n }\n\n if (vertexFormat.normal) {\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n\n normals[normalIndex++] = normal.x;\n normals[normalIndex++] = normal.y;\n normals[normalIndex++] = normal.z;\n }\n\n if (vertexFormat.tangent) {\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n\n tangents[tangentIndex++] = tangent.x;\n tangents[tangentIndex++] = tangent.y;\n tangents[tangentIndex++] = tangent.z;\n }\n\n if (vertexFormat.bitangent) {\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n\n bitangents[bitangentIndex++] = bitangent.x;\n bitangents[bitangentIndex++] = bitangent.y;\n bitangents[bitangentIndex++] = bitangent.z;\n }\n }\n }\n\n const attributes = new GeometryAttributes();\n\n if (vertexFormat.position) {\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n });\n }\n\n if (vertexFormat.normal) {\n attributes.normal = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: normals,\n });\n }\n\n if (vertexFormat.tangent) {\n attributes.tangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: tangents,\n });\n }\n\n if (vertexFormat.bitangent) {\n attributes.bitangent = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 3,\n values: bitangents,\n });\n }\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: textureCoordinates,\n });\n }\n\n // prepare the side walls, two triangles for each wall\n //\n // A (i+1) B (i+3) E\n // +--------+-------+\n // | / | /| triangles: A C B\n // | / | / | B C D\n // | / | / |\n // | / | / |\n // | / | / |\n // | / | / |\n // +--------+-------+\n // C (i) D (i+2) F\n //\n\n const numVertices = size / 3;\n size -= 6 * (numCorners + 1);\n const indices = IndexDatatype.createTypedArray(numVertices, size);\n\n let edgeIndex = 0;\n for (i = 0; i < numVertices - 2; i += 2) {\n const LL = i;\n const LR = i + 2;\n const pl = Cartesian3.fromArray(\n positions,\n LL * 3,\n scratchCartesian3Position1\n );\n const pr = Cartesian3.fromArray(\n positions,\n LR * 3,\n scratchCartesian3Position2\n );\n if (Cartesian3.equalsEpsilon(pl, pr, CesiumMath.EPSILON10)) {\n continue;\n }\n const UL = i + 1;\n const UR = i + 3;\n\n indices[edgeIndex++] = UL;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = UR;\n indices[edgeIndex++] = UR;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = LR;\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: new BoundingSphere.fromVertices(positions),\n });\n};\nexport default WallGeometry;\n", "import BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport WallGeometryLibrary from \"./WallGeometryLibrary.js\";\n\nconst scratchCartesian3Position1 = new Cartesian3();\nconst scratchCartesian3Position2 = new Cartesian3();\n\n/**\n * A description of a wall outline. A wall is defined by a series of points,\n * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.\n *\n * @alias WallOutlineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.\n * @param {number[]} [options.maximumHeights] An array parallel to positions that give the maximum height of the\n * wall at positions. If undefined, the height of each position in used.\n * @param {number[]} [options.minimumHeights] An array parallel to positions that give the minimum height of the\n * wall at positions. If undefined, the height at each position is 0.0.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation\n *\n * @exception {DeveloperError} positions length must be greater than or equal to 2.\n * @exception {DeveloperError} positions and maximumHeights must have the same length.\n * @exception {DeveloperError} positions and minimumHeights must have the same length.\n *\n * @see WallGeometry#createGeometry\n * @see WallGeometry#fromConstantHeight\n *\n * @example\n * // create a wall outline that spans from ground level to 10000 meters\n * const wall = new Cesium.WallOutlineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArrayHeights([\n * 19.0, 47.0, 10000.0,\n * 19.0, 48.0, 10000.0,\n * 20.0, 48.0, 10000.0,\n * 20.0, 47.0, 10000.0,\n * 19.0, 47.0, 10000.0\n * ])\n * });\n * const geometry = Cesium.WallOutlineGeometry.createGeometry(wall);\n */\nfunction WallOutlineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n const wallPositions = options.positions;\n const maximumHeights = options.maximumHeights;\n const minimumHeights = options.minimumHeights;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(wallPositions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n if (\n defined(maximumHeights) &&\n maximumHeights.length !== wallPositions.length\n ) {\n throw new DeveloperError(\n \"options.positions and options.maximumHeights must have the same length.\"\n );\n }\n if (\n defined(minimumHeights) &&\n minimumHeights.length !== wallPositions.length\n ) {\n throw new DeveloperError(\n \"options.positions and options.minimumHeights must have the same length.\"\n );\n }\n //>>includeEnd('debug');\n\n const granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n this._positions = wallPositions;\n this._minimumHeights = minimumHeights;\n this._maximumHeights = maximumHeights;\n this._granularity = granularity;\n this._ellipsoid = Ellipsoid.clone(ellipsoid);\n this._workerName = \"createWallOutlineGeometry\";\n\n let numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2;\n if (defined(minimumHeights)) {\n numComponents += minimumHeights.length;\n }\n if (defined(maximumHeights)) {\n numComponents += maximumHeights.length;\n }\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength = numComponents + Ellipsoid.packedLength + 1;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {WallOutlineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nWallOutlineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n const positions = value._positions;\n let length = positions.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n const minimumHeights = value._minimumHeights;\n length = defined(minimumHeights) ? minimumHeights.length : 0;\n array[startingIndex++] = length;\n\n if (defined(minimumHeights)) {\n for (i = 0; i < length; ++i) {\n array[startingIndex++] = minimumHeights[i];\n }\n }\n\n const maximumHeights = value._maximumHeights;\n length = defined(maximumHeights) ? maximumHeights.length : 0;\n array[startingIndex++] = length;\n\n if (defined(maximumHeights)) {\n for (i = 0; i < length; ++i) {\n array[startingIndex++] = maximumHeights[i];\n }\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n array[startingIndex] = value._granularity;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchOptions = {\n positions: undefined,\n minimumHeights: undefined,\n maximumHeights: undefined,\n ellipsoid: scratchEllipsoid,\n granularity: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {WallOutlineGeometry} [result] The object into which to store the result.\n * @returns {WallOutlineGeometry} The modified result parameter or a new WallOutlineGeometry instance if one was not provided.\n */\nWallOutlineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n let length = array[startingIndex++];\n const positions = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n length = array[startingIndex++];\n let minimumHeights;\n\n if (length > 0) {\n minimumHeights = new Array(length);\n for (i = 0; i < length; ++i) {\n minimumHeights[i] = array[startingIndex++];\n }\n }\n\n length = array[startingIndex++];\n let maximumHeights;\n\n if (length > 0) {\n maximumHeights = new Array(length);\n for (i = 0; i < length; ++i) {\n maximumHeights[i] = array[startingIndex++];\n }\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const granularity = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.positions = positions;\n scratchOptions.minimumHeights = minimumHeights;\n scratchOptions.maximumHeights = maximumHeights;\n scratchOptions.granularity = granularity;\n return new WallOutlineGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._minimumHeights = minimumHeights;\n result._maximumHeights = maximumHeights;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._granularity = granularity;\n\n return result;\n};\n\n/**\n * A description of a walloutline. A wall is defined by a series of points,\n * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.\n * @param {number} [options.maximumHeight] A constant that defines the maximum height of the\n * wall at positions. If undefined, the height of each position in used.\n * @param {number} [options.minimumHeight] A constant that defines the minimum height of the\n * wall at positions. If undefined, the height at each position is 0.0.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation\n * @returns {WallOutlineGeometry}\n *\n *\n * @example\n * // create a wall that spans from 10000 meters to 20000 meters\n * const wall = Cesium.WallOutlineGeometry.fromConstantHeights({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 19.0, 47.0,\n * 19.0, 48.0,\n * 20.0, 48.0,\n * 20.0, 47.0,\n * 19.0, 47.0,\n * ]),\n * minimumHeight : 20000.0,\n * maximumHeight : 10000.0\n * });\n * const geometry = Cesium.WallOutlineGeometry.createGeometry(wall);\n *\n * @see WallOutlineGeometry#createGeometry\n */\nWallOutlineGeometry.fromConstantHeights = function (options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions)) {\n throw new DeveloperError(\"options.positions is required.\");\n }\n //>>includeEnd('debug');\n\n let minHeights;\n let maxHeights;\n\n const min = options.minimumHeight;\n const max = options.maximumHeight;\n\n const doMin = defined(min);\n const doMax = defined(max);\n if (doMin || doMax) {\n const length = positions.length;\n minHeights = doMin ? new Array(length) : undefined;\n maxHeights = doMax ? new Array(length) : undefined;\n\n for (let i = 0; i < length; ++i) {\n if (doMin) {\n minHeights[i] = min;\n }\n\n if (doMax) {\n maxHeights[i] = max;\n }\n }\n }\n\n const newOptions = {\n positions: positions,\n maximumHeights: maxHeights,\n minimumHeights: minHeights,\n ellipsoid: options.ellipsoid,\n };\n return new WallOutlineGeometry(newOptions);\n};\n\n/**\n * Computes the geometric representation of a wall outline, including its vertices, indices, and a bounding sphere.\n *\n * @param {WallOutlineGeometry} wallGeometry A description of the wall outline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nWallOutlineGeometry.createGeometry = function (wallGeometry) {\n const wallPositions = wallGeometry._positions;\n const minimumHeights = wallGeometry._minimumHeights;\n const maximumHeights = wallGeometry._maximumHeights;\n const granularity = wallGeometry._granularity;\n const ellipsoid = wallGeometry._ellipsoid;\n\n const pos = WallGeometryLibrary.computePositions(\n ellipsoid,\n wallPositions,\n maximumHeights,\n minimumHeights,\n granularity,\n false\n );\n if (!defined(pos)) {\n return;\n }\n\n const bottomPositions = pos.bottomPositions;\n const topPositions = pos.topPositions;\n\n let length = topPositions.length;\n let size = length * 2;\n\n const positions = new Float64Array(size);\n let positionIndex = 0;\n\n // add lower and upper points one after the other, lower\n // points being even and upper points being odd\n length /= 3;\n let i;\n for (i = 0; i < length; ++i) {\n const i3 = i * 3;\n const topPosition = Cartesian3.fromArray(\n topPositions,\n i3,\n scratchCartesian3Position1\n );\n const bottomPosition = Cartesian3.fromArray(\n bottomPositions,\n i3,\n scratchCartesian3Position2\n );\n\n // insert the lower point\n positions[positionIndex++] = bottomPosition.x;\n positions[positionIndex++] = bottomPosition.y;\n positions[positionIndex++] = bottomPosition.z;\n\n // insert the upper point\n positions[positionIndex++] = topPosition.x;\n positions[positionIndex++] = topPosition.y;\n positions[positionIndex++] = topPosition.z;\n }\n\n const attributes = new GeometryAttributes({\n position: new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: positions,\n }),\n });\n\n const numVertices = size / 3;\n size = 2 * numVertices - 4 + numVertices;\n const indices = IndexDatatype.createTypedArray(numVertices, size);\n\n let edgeIndex = 0;\n for (i = 0; i < numVertices - 2; i += 2) {\n const LL = i;\n const LR = i + 2;\n const pl = Cartesian3.fromArray(\n positions,\n LL * 3,\n scratchCartesian3Position1\n );\n const pr = Cartesian3.fromArray(\n positions,\n LR * 3,\n scratchCartesian3Position2\n );\n if (Cartesian3.equalsEpsilon(pl, pr, CesiumMath.EPSILON10)) {\n continue;\n }\n const UL = i + 1;\n const UR = i + 3;\n\n indices[edgeIndex++] = UL;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = UL;\n indices[edgeIndex++] = UR;\n indices[edgeIndex++] = LL;\n indices[edgeIndex++] = LR;\n }\n\n indices[edgeIndex++] = numVertices - 2;\n indices[edgeIndex++] = numVertices - 1;\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.LINES,\n boundingSphere: new BoundingSphere.fromVertices(positions),\n });\n};\nexport default WallOutlineGeometry;\n", "import Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport WallGeometry from \"../Core/WallGeometry.js\";\nimport WallOutlineGeometry from \"../Core/WallOutlineGeometry.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryUpdater from \"./DynamicGeometryUpdater.js\";\nimport GeometryUpdater from \"./GeometryUpdater.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\n\nfunction WallGeometryOptions(entity) {\n this.id = entity;\n this.vertexFormat = undefined;\n this.positions = undefined;\n this.minimumHeights = undefined;\n this.maximumHeights = undefined;\n this.granularity = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for walls.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias WallGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction WallGeometryUpdater(entity, scene) {\n GeometryUpdater.call(this, {\n entity: entity,\n scene: scene,\n geometryOptions: new WallGeometryOptions(entity),\n geometryPropertyName: \"wall\",\n observedPropertyNames: [\"availability\", \"wall\"],\n });\n\n this._onEntityPropertyChanged(entity, \"wall\", entity.wall, undefined);\n}\n\nif (defined(Object.create)) {\n WallGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);\n WallGeometryUpdater.prototype.constructor = WallGeometryUpdater;\n}\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nWallGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n\n let attributes;\n\n let color;\n const show = new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._fillProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n if (this._materialProperty instanceof ColorMaterialProperty) {\n let currentColor;\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n color: color,\n };\n } else {\n attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n };\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new WallGeometry(this._options),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nWallGeometryUpdater.prototype.createOutlineGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n\n if (!this._outlineEnabled) {\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const outlineColor = Property.getValueOrDefault(\n this._outlineColorProperty,\n time,\n Color.BLACK,\n scratchColor\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n\n return new GeometryInstance({\n id: entity,\n geometry: new WallOutlineGeometry(this._options),\n attributes: {\n show: new ShowGeometryInstanceAttribute(\n isAvailable &&\n entity.isShowing &&\n this._showProperty.getValue(time) &&\n this._showOutlineProperty.getValue(time)\n ),\n color: ColorGeometryInstanceAttribute.fromColor(outlineColor),\n distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n ),\n },\n });\n};\n\nWallGeometryUpdater.prototype._isHidden = function (entity, wall) {\n return (\n !defined(wall.positions) ||\n GeometryUpdater.prototype._isHidden.call(this, entity, wall)\n );\n};\n\nWallGeometryUpdater.prototype._getIsClosed = function (options) {\n return false;\n};\n\nWallGeometryUpdater.prototype._isDynamic = function (entity, wall) {\n return (\n !wall.positions.isConstant || //\n !Property.isConstant(wall.minimumHeights) || //\n !Property.isConstant(wall.maximumHeights) || //\n !Property.isConstant(wall.outlineWidth) || //\n !Property.isConstant(wall.granularity)\n );\n};\n\nWallGeometryUpdater.prototype._setStaticOptions = function (entity, wall) {\n const minimumHeights = wall.minimumHeights;\n const maximumHeights = wall.maximumHeights;\n const granularity = wall.granularity;\n const isColorMaterial =\n this._materialProperty instanceof ColorMaterialProperty;\n\n const options = this._options;\n options.vertexFormat = isColorMaterial\n ? PerInstanceColorAppearance.VERTEX_FORMAT\n : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;\n options.positions = wall.positions.getValue(\n Iso8601.MINIMUM_VALUE,\n options.positions\n );\n options.minimumHeights = defined(minimumHeights)\n ? minimumHeights.getValue(Iso8601.MINIMUM_VALUE, options.minimumHeights)\n : undefined;\n options.maximumHeights = defined(maximumHeights)\n ? maximumHeights.getValue(Iso8601.MINIMUM_VALUE, options.maximumHeights)\n : undefined;\n options.granularity = defined(granularity)\n ? granularity.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n};\n\nWallGeometryUpdater.DynamicGeometryUpdater = DynamicWallGeometryUpdater;\n\n/**\n * @private\n */\nfunction DynamicWallGeometryUpdater(\n geometryUpdater,\n primitives,\n groundPrimitives\n) {\n DynamicGeometryUpdater.call(\n this,\n geometryUpdater,\n primitives,\n groundPrimitives\n );\n}\n\nif (defined(Object.create)) {\n DynamicWallGeometryUpdater.prototype = Object.create(\n DynamicGeometryUpdater.prototype\n );\n DynamicWallGeometryUpdater.prototype.constructor = DynamicWallGeometryUpdater;\n}\n\nDynamicWallGeometryUpdater.prototype._isHidden = function (entity, wall, time) {\n return (\n !defined(this._options.positions) ||\n DynamicGeometryUpdater.prototype._isHidden.call(this, entity, wall, time)\n );\n};\n\nDynamicWallGeometryUpdater.prototype._setOptions = function (\n entity,\n wall,\n time\n) {\n const options = this._options;\n options.positions = Property.getValueOrUndefined(\n wall.positions,\n time,\n options.positions\n );\n options.minimumHeights = Property.getValueOrUndefined(\n wall.minimumHeights,\n time,\n options.minimumHeights\n );\n options.maximumHeights = Property.getValueOrUndefined(\n wall.maximumHeights,\n time,\n options.maximumHeights\n );\n options.granularity = Property.getValueOrUndefined(wall.granularity, time);\n};\nexport default WallGeometryUpdater;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport Event from \"../Core/Event.js\";\nimport EventHelper from \"../Core/EventHelper.js\";\nimport ClassificationType from \"../Scene/ClassificationType.js\";\nimport MaterialAppearance from \"../Scene/MaterialAppearance.js\";\nimport PerInstanceColorAppearance from \"../Scene/PerInstanceColorAppearance.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport BoxGeometryUpdater from \"./BoxGeometryUpdater.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport CorridorGeometryUpdater from \"./CorridorGeometryUpdater.js\";\nimport CylinderGeometryUpdater from \"./CylinderGeometryUpdater.js\";\nimport DynamicGeometryBatch from \"./DynamicGeometryBatch.js\";\nimport EllipseGeometryUpdater from \"./EllipseGeometryUpdater.js\";\nimport EllipsoidGeometryUpdater from \"./EllipsoidGeometryUpdater.js\";\nimport Entity from \"./Entity.js\";\nimport PlaneGeometryUpdater from \"./PlaneGeometryUpdater.js\";\nimport PolygonGeometryUpdater from \"./PolygonGeometryUpdater.js\";\nimport PolylineVolumeGeometryUpdater from \"./PolylineVolumeGeometryUpdater.js\";\nimport RectangleGeometryUpdater from \"./RectangleGeometryUpdater.js\";\nimport StaticGeometryColorBatch from \"./StaticGeometryColorBatch.js\";\nimport StaticGeometryPerMaterialBatch from \"./StaticGeometryPerMaterialBatch.js\";\nimport StaticGroundGeometryColorBatch from \"./StaticGroundGeometryColorBatch.js\";\nimport StaticGroundGeometryPerMaterialBatch from \"./StaticGroundGeometryPerMaterialBatch.js\";\nimport StaticOutlineGeometryBatch from \"./StaticOutlineGeometryBatch.js\";\nimport WallGeometryUpdater from \"./WallGeometryUpdater.js\";\n\nconst emptyArray = [];\n\nconst geometryUpdaters = [\n BoxGeometryUpdater,\n CylinderGeometryUpdater,\n CorridorGeometryUpdater,\n EllipseGeometryUpdater,\n EllipsoidGeometryUpdater,\n PlaneGeometryUpdater,\n PolygonGeometryUpdater,\n PolylineVolumeGeometryUpdater,\n RectangleGeometryUpdater,\n WallGeometryUpdater,\n];\n\nfunction GeometryUpdaterSet(entity, scene) {\n this.entity = entity;\n this.scene = scene;\n const updaters = new Array(geometryUpdaters.length);\n const geometryChanged = new Event();\n function raiseEvent(geometry) {\n geometryChanged.raiseEvent(geometry);\n }\n const eventHelper = new EventHelper();\n for (let i = 0; i < updaters.length; i++) {\n const updater = new geometryUpdaters[i](entity, scene);\n eventHelper.add(updater.geometryChanged, raiseEvent);\n updaters[i] = updater;\n }\n this.updaters = updaters;\n this.geometryChanged = geometryChanged;\n this.eventHelper = eventHelper;\n\n this._removeEntitySubscription = entity.definitionChanged.addEventListener(\n GeometryUpdaterSet.prototype._onEntityPropertyChanged,\n this\n );\n}\n\nGeometryUpdaterSet.prototype._onEntityPropertyChanged = function (\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n const updaters = this.updaters;\n for (let i = 0; i < updaters.length; i++) {\n updaters[i]._onEntityPropertyChanged(\n entity,\n propertyName,\n newValue,\n oldValue\n );\n }\n};\n\nGeometryUpdaterSet.prototype.forEach = function (callback) {\n const updaters = this.updaters;\n for (let i = 0; i < updaters.length; i++) {\n callback(updaters[i]);\n }\n};\n\nGeometryUpdaterSet.prototype.destroy = function () {\n this.eventHelper.removeAll();\n const updaters = this.updaters;\n for (let i = 0; i < updaters.length; i++) {\n updaters[i].destroy();\n }\n this._removeEntitySubscription();\n destroyObject(this);\n};\n\n/**\n * A general purpose visualizer for geometry represented by {@link Primitive} instances.\n * @alias GeometryVisualizer\n * @constructor\n *\n * @param {Scene} scene The scene the primitives will be rendered in.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n * @param {PrimitiveCollection} [primitives=scene.primitives] A collection to add primitives related to the entities\n * @param {PrimitiveCollection} [groundPrimitives=scene.groundPrimitives] A collection to add ground primitives related to the entities\n */\nfunction GeometryVisualizer(\n scene,\n entityCollection,\n primitives,\n groundPrimitives\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"scene\", scene);\n Check.defined(\"entityCollection\", entityCollection);\n //>>includeEnd('debug');\n\n primitives = defaultValue(primitives, scene.primitives);\n groundPrimitives = defaultValue(groundPrimitives, scene.groundPrimitives);\n\n this._scene = scene;\n this._primitives = primitives;\n this._groundPrimitives = groundPrimitives;\n this._entityCollection = undefined;\n this._addedObjects = new AssociativeArray();\n this._removedObjects = new AssociativeArray();\n this._changedObjects = new AssociativeArray();\n\n const numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES;\n this._outlineBatches = new Array(numberOfShadowModes * 2);\n this._closedColorBatches = new Array(numberOfShadowModes * 2);\n this._closedMaterialBatches = new Array(numberOfShadowModes * 2);\n this._openColorBatches = new Array(numberOfShadowModes * 2);\n this._openMaterialBatches = new Array(numberOfShadowModes * 2);\n\n const supportsMaterialsforEntitiesOnTerrain = Entity.supportsMaterialsforEntitiesOnTerrain(\n scene\n );\n this._supportsMaterialsforEntitiesOnTerrain = supportsMaterialsforEntitiesOnTerrain;\n\n let i;\n for (i = 0; i < numberOfShadowModes; ++i) {\n this._outlineBatches[i] = new StaticOutlineGeometryBatch(\n primitives,\n scene,\n i,\n false\n );\n this._outlineBatches[\n numberOfShadowModes + i\n ] = new StaticOutlineGeometryBatch(primitives, scene, i, true);\n\n this._closedColorBatches[i] = new StaticGeometryColorBatch(\n primitives,\n PerInstanceColorAppearance,\n undefined,\n true,\n i,\n true\n );\n this._closedColorBatches[\n numberOfShadowModes + i\n ] = new StaticGeometryColorBatch(\n primitives,\n PerInstanceColorAppearance,\n undefined,\n true,\n i,\n false\n );\n\n this._closedMaterialBatches[i] = new StaticGeometryPerMaterialBatch(\n primitives,\n MaterialAppearance,\n undefined,\n true,\n i,\n true\n );\n this._closedMaterialBatches[\n numberOfShadowModes + i\n ] = new StaticGeometryPerMaterialBatch(\n primitives,\n MaterialAppearance,\n undefined,\n true,\n i,\n false\n );\n\n this._openColorBatches[i] = new StaticGeometryColorBatch(\n primitives,\n PerInstanceColorAppearance,\n undefined,\n false,\n i,\n true\n );\n this._openColorBatches[\n numberOfShadowModes + i\n ] = new StaticGeometryColorBatch(\n primitives,\n PerInstanceColorAppearance,\n undefined,\n false,\n i,\n false\n );\n\n this._openMaterialBatches[i] = new StaticGeometryPerMaterialBatch(\n primitives,\n MaterialAppearance,\n undefined,\n false,\n i,\n true\n );\n this._openMaterialBatches[\n numberOfShadowModes + i\n ] = new StaticGeometryPerMaterialBatch(\n primitives,\n MaterialAppearance,\n undefined,\n false,\n i,\n false\n );\n }\n\n const numberOfClassificationTypes =\n ClassificationType.NUMBER_OF_CLASSIFICATION_TYPES;\n const groundColorBatches = new Array(numberOfClassificationTypes);\n const groundMaterialBatches = [];\n if (supportsMaterialsforEntitiesOnTerrain) {\n for (i = 0; i < numberOfClassificationTypes; ++i) {\n groundMaterialBatches.push(\n new StaticGroundGeometryPerMaterialBatch(\n groundPrimitives,\n i,\n MaterialAppearance\n )\n );\n groundColorBatches[i] = new StaticGroundGeometryColorBatch(\n groundPrimitives,\n i\n );\n }\n } else {\n for (i = 0; i < numberOfClassificationTypes; ++i) {\n groundColorBatches[i] = new StaticGroundGeometryColorBatch(\n groundPrimitives,\n i\n );\n }\n }\n\n this._groundColorBatches = groundColorBatches;\n this._groundMaterialBatches = groundMaterialBatches;\n\n this._dynamicBatch = new DynamicGeometryBatch(primitives, groundPrimitives);\n\n this._batches = this._outlineBatches.concat(\n this._closedColorBatches,\n this._closedMaterialBatches,\n this._openColorBatches,\n this._openMaterialBatches,\n this._groundColorBatches,\n this._groundMaterialBatches,\n this._dynamicBatch\n );\n\n this._subscriptions = new AssociativeArray();\n this._updaterSets = new AssociativeArray();\n\n this._entityCollection = entityCollection;\n entityCollection.collectionChanged.addEventListener(\n GeometryVisualizer.prototype._onCollectionChanged,\n this\n );\n this._onCollectionChanged(\n entityCollection,\n entityCollection.values,\n emptyArray\n );\n}\n\n/**\n * Updates all of the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} True if the visualizer successfully updated to the provided time,\n * false if the visualizer is waiting for asynchronous primitives to be created.\n */\nGeometryVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const addedObjects = this._addedObjects;\n const added = addedObjects.values;\n const removedObjects = this._removedObjects;\n const removed = removedObjects.values;\n const changedObjects = this._changedObjects;\n const changed = changedObjects.values;\n\n let i;\n let entity;\n let id;\n let updaterSet;\n const that = this;\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n id = entity.id;\n updaterSet = this._updaterSets.get(id);\n\n //If in a single update, an entity gets removed and a new instance\n //re-added with the same id, the updater no longer tracks the\n //correct entity, we need to both remove the old one and\n //add the new one, which is done by pushing the entity\n //onto the removed/added lists.\n if (updaterSet.entity === entity) {\n updaterSet.forEach(function (updater) {\n that._removeUpdater(updater);\n that._insertUpdaterIntoBatch(time, updater);\n });\n } else {\n removed.push(entity);\n added.push(entity);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n id = entity.id;\n updaterSet = this._updaterSets.get(id);\n updaterSet.forEach(this._removeUpdater.bind(this));\n updaterSet.destroy();\n this._updaterSets.remove(id);\n this._subscriptions.get(id)();\n this._subscriptions.remove(id);\n }\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n id = entity.id;\n updaterSet = new GeometryUpdaterSet(entity, this._scene);\n this._updaterSets.set(id, updaterSet);\n updaterSet.forEach(function (updater) {\n that._insertUpdaterIntoBatch(time, updater);\n });\n this._subscriptions.set(\n id,\n updaterSet.geometryChanged.addEventListener(\n GeometryVisualizer._onGeometryChanged,\n this\n )\n );\n }\n\n addedObjects.removeAll();\n removedObjects.removeAll();\n changedObjects.removeAll();\n\n let isUpdated = true;\n const batches = this._batches;\n const length = batches.length;\n for (i = 0; i < length; i++) {\n isUpdated = batches[i].update(time) && isUpdated;\n }\n\n return isUpdated;\n};\n\nconst getBoundingSphereArrayScratch = [];\nconst getBoundingSphereBoundingSphereScratch = new BoundingSphere();\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nGeometryVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"entity\", entity);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n const boundingSpheres = getBoundingSphereArrayScratch;\n const tmp = getBoundingSphereBoundingSphereScratch;\n\n let count = 0;\n let state = BoundingSphereState.DONE;\n const batches = this._batches;\n const batchesLength = batches.length;\n\n const id = entity.id;\n const updaters = this._updaterSets.get(id).updaters;\n\n for (let j = 0; j < updaters.length; j++) {\n const updater = updaters[j];\n for (let i = 0; i < batchesLength; i++) {\n state = batches[i].getBoundingSphere(updater, tmp);\n if (state === BoundingSphereState.PENDING) {\n return BoundingSphereState.PENDING;\n } else if (state === BoundingSphereState.DONE) {\n boundingSpheres[count] = BoundingSphere.clone(\n tmp,\n boundingSpheres[count]\n );\n count++;\n }\n }\n }\n\n if (count === 0) {\n return BoundingSphereState.FAILED;\n }\n\n boundingSpheres.length = count;\n BoundingSphere.fromBoundingSpheres(boundingSpheres, result);\n return BoundingSphereState.DONE;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nGeometryVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nGeometryVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n GeometryVisualizer.prototype._onCollectionChanged,\n this\n );\n this._addedObjects.removeAll();\n this._removedObjects.removeAll();\n\n let i;\n const batches = this._batches;\n let length = batches.length;\n for (i = 0; i < length; i++) {\n batches[i].removeAllPrimitives();\n }\n\n const subscriptions = this._subscriptions.values;\n length = subscriptions.length;\n for (i = 0; i < length; i++) {\n subscriptions[i]();\n }\n this._subscriptions.removeAll();\n\n const updaterSets = this._updaterSets.values;\n length = updaterSets.length;\n for (i = 0; i < length; i++) {\n updaterSets[i].destroy();\n }\n this._updaterSets.removeAll();\n return destroyObject(this);\n};\n\n/**\n * @private\n */\nGeometryVisualizer.prototype._removeUpdater = function (updater) {\n //We don't keep track of which batch an updater is in, so just remove it from all of them.\n const batches = this._batches;\n const length = batches.length;\n for (let i = 0; i < length; i++) {\n batches[i].remove(updater);\n }\n};\n\n/**\n * @private\n */\nGeometryVisualizer.prototype._insertUpdaterIntoBatch = function (\n time,\n updater\n) {\n if (updater.isDynamic) {\n this._dynamicBatch.add(time, updater);\n return;\n }\n\n let shadows;\n if (updater.outlineEnabled || updater.fillEnabled) {\n shadows = updater.shadowsProperty.getValue(time);\n }\n\n const numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES;\n if (updater.outlineEnabled) {\n if (defined(updater.terrainOffsetProperty)) {\n this._outlineBatches[numberOfShadowModes + shadows].add(time, updater);\n } else {\n this._outlineBatches[shadows].add(time, updater);\n }\n }\n\n if (updater.fillEnabled) {\n if (updater.onTerrain) {\n const classificationType = updater.classificationTypeProperty.getValue(\n time\n );\n if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {\n this._groundColorBatches[classificationType].add(time, updater);\n } else {\n // If unsupported, updater will not be on terrain.\n this._groundMaterialBatches[classificationType].add(time, updater);\n }\n } else if (updater.isClosed) {\n if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {\n if (defined(updater.terrainOffsetProperty)) {\n this._closedColorBatches[numberOfShadowModes + shadows].add(\n time,\n updater\n );\n } else {\n this._closedColorBatches[shadows].add(time, updater);\n }\n } else if (defined(updater.terrainOffsetProperty)) {\n this._closedMaterialBatches[numberOfShadowModes + shadows].add(\n time,\n updater\n );\n } else {\n this._closedMaterialBatches[shadows].add(time, updater);\n }\n } else if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {\n if (defined(updater.terrainOffsetProperty)) {\n this._openColorBatches[numberOfShadowModes + shadows].add(\n time,\n updater\n );\n } else {\n this._openColorBatches[shadows].add(time, updater);\n }\n } else if (defined(updater.terrainOffsetProperty)) {\n this._openMaterialBatches[numberOfShadowModes + shadows].add(\n time,\n updater\n );\n } else {\n this._openMaterialBatches[shadows].add(time, updater);\n }\n }\n};\n\n/**\n * @private\n */\nGeometryVisualizer._onGeometryChanged = function (updater) {\n const removedObjects = this._removedObjects;\n const changedObjects = this._changedObjects;\n\n const entity = updater.entity;\n const id = entity.id;\n\n if (!defined(removedObjects.get(id)) && !defined(changedObjects.get(id))) {\n changedObjects.set(id, entity);\n }\n};\n\n/**\n * @private\n */\nGeometryVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed\n) {\n const addedObjects = this._addedObjects;\n const removedObjects = this._removedObjects;\n const changedObjects = this._changedObjects;\n\n let i;\n let id;\n let entity;\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n id = entity.id;\n if (!addedObjects.remove(id)) {\n removedObjects.set(id, entity);\n changedObjects.remove(id);\n }\n }\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n id = entity.id;\n if (removedObjects.remove(id)) {\n changedObjects.set(id, entity);\n } else {\n addedObjects.set(id, entity);\n }\n }\n};\nexport default GeometryVisualizer;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport LabelStyle from \"../Scene/LabelStyle.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\n\nconst defaultScale = 1.0;\nconst defaultFont = \"30px sans-serif\";\nconst defaultStyle = LabelStyle.FILL;\nconst defaultFillColor = Color.WHITE;\nconst defaultOutlineColor = Color.BLACK;\nconst defaultOutlineWidth = 1.0;\nconst defaultShowBackground = false;\nconst defaultBackgroundColor = new Color(0.165, 0.165, 0.165, 0.8);\nconst defaultBackgroundPadding = new Cartesian2(7, 5);\nconst defaultPixelOffset = Cartesian2.ZERO;\nconst defaultEyeOffset = Cartesian3.ZERO;\nconst defaultHeightReference = HeightReference.NONE;\nconst defaultHorizontalOrigin = HorizontalOrigin.CENTER;\nconst defaultVerticalOrigin = VerticalOrigin.CENTER;\n\nconst positionScratch = new Cartesian3();\nconst fillColorScratch = new Color();\nconst outlineColorScratch = new Color();\nconst backgroundColorScratch = new Color();\nconst backgroundPaddingScratch = new Cartesian2();\nconst eyeOffsetScratch = new Cartesian3();\nconst pixelOffsetScratch = new Cartesian2();\nconst translucencyByDistanceScratch = new NearFarScalar();\nconst pixelOffsetScaleByDistanceScratch = new NearFarScalar();\nconst scaleByDistanceScratch = new NearFarScalar();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\n\nfunction EntityData(entity) {\n this.entity = entity;\n this.label = undefined;\n this.index = undefined;\n}\n\n/**\n * A {@link Visualizer} which maps the {@link LabelGraphics} instance\n * in {@link Entity#label} to a {@link Label}.\n * @alias LabelVisualizer\n * @constructor\n *\n * @param {EntityCluster} entityCluster The entity cluster to manage the collection of billboards and optionally cluster with other entities.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction LabelVisualizer(entityCluster, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entityCluster)) {\n throw new DeveloperError(\"entityCluster is required.\");\n }\n if (!defined(entityCollection)) {\n throw new DeveloperError(\"entityCollection is required.\");\n }\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n LabelVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._cluster = entityCluster;\n this._entityCollection = entityCollection;\n this._items = new AssociativeArray();\n\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\n/**\n * Updates the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nLabelVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const items = this._items.values;\n const cluster = this._cluster;\n\n for (let i = 0, len = items.length; i < len; i++) {\n const item = items[i];\n const entity = item.entity;\n const labelGraphics = entity._label;\n let text;\n let label = item.label;\n let show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n Property.getValueOrDefault(labelGraphics._show, time, true);\n let position;\n if (show) {\n position = Property.getValueOrUndefined(\n entity._position,\n time,\n positionScratch\n );\n text = Property.getValueOrUndefined(labelGraphics._text, time);\n show = defined(position) && defined(text);\n }\n\n if (!show) {\n //don't bother creating or updating anything else\n returnPrimitive(item, entity, cluster);\n continue;\n }\n\n if (!Property.isConstant(entity._position)) {\n cluster._clusterDirty = true;\n }\n\n let updateClamping = false;\n const heightReference = Property.getValueOrDefault(\n labelGraphics._heightReference,\n time,\n defaultHeightReference\n );\n\n if (!defined(label)) {\n label = cluster.getLabel(entity);\n label.id = entity;\n item.label = label;\n\n // If this new label happens to have a position and height reference that match our new values,\n // label._updateClamping will not be called automatically. That's a problem because the clamped\n // height may be based on different terrain than is now loaded. So we'll manually call\n // _updateClamping below.\n updateClamping =\n Cartesian3.equals(label.position, position) &&\n label.heightReference === heightReference;\n }\n\n label.show = true;\n label.position = position;\n label.text = text;\n label.scale = Property.getValueOrDefault(\n labelGraphics._scale,\n time,\n defaultScale\n );\n label.font = Property.getValueOrDefault(\n labelGraphics._font,\n time,\n defaultFont\n );\n label.style = Property.getValueOrDefault(\n labelGraphics._style,\n time,\n defaultStyle\n );\n label.fillColor = Property.getValueOrDefault(\n labelGraphics._fillColor,\n time,\n defaultFillColor,\n fillColorScratch\n );\n label.outlineColor = Property.getValueOrDefault(\n labelGraphics._outlineColor,\n time,\n defaultOutlineColor,\n outlineColorScratch\n );\n label.outlineWidth = Property.getValueOrDefault(\n labelGraphics._outlineWidth,\n time,\n defaultOutlineWidth\n );\n label.showBackground = Property.getValueOrDefault(\n labelGraphics._showBackground,\n time,\n defaultShowBackground\n );\n label.backgroundColor = Property.getValueOrDefault(\n labelGraphics._backgroundColor,\n time,\n defaultBackgroundColor,\n backgroundColorScratch\n );\n label.backgroundPadding = Property.getValueOrDefault(\n labelGraphics._backgroundPadding,\n time,\n defaultBackgroundPadding,\n backgroundPaddingScratch\n );\n label.pixelOffset = Property.getValueOrDefault(\n labelGraphics._pixelOffset,\n time,\n defaultPixelOffset,\n pixelOffsetScratch\n );\n label.eyeOffset = Property.getValueOrDefault(\n labelGraphics._eyeOffset,\n time,\n defaultEyeOffset,\n eyeOffsetScratch\n );\n label.heightReference = heightReference;\n label.horizontalOrigin = Property.getValueOrDefault(\n labelGraphics._horizontalOrigin,\n time,\n defaultHorizontalOrigin\n );\n label.verticalOrigin = Property.getValueOrDefault(\n labelGraphics._verticalOrigin,\n time,\n defaultVerticalOrigin\n );\n label.translucencyByDistance = Property.getValueOrUndefined(\n labelGraphics._translucencyByDistance,\n time,\n translucencyByDistanceScratch\n );\n label.pixelOffsetScaleByDistance = Property.getValueOrUndefined(\n labelGraphics._pixelOffsetScaleByDistance,\n time,\n pixelOffsetScaleByDistanceScratch\n );\n label.scaleByDistance = Property.getValueOrUndefined(\n labelGraphics._scaleByDistance,\n time,\n scaleByDistanceScratch\n );\n label.distanceDisplayCondition = Property.getValueOrUndefined(\n labelGraphics._distanceDisplayCondition,\n time,\n distanceDisplayConditionScratch\n );\n label.disableDepthTestDistance = Property.getValueOrUndefined(\n labelGraphics._disableDepthTestDistance,\n time\n );\n\n if (updateClamping) {\n label._updateClamping();\n }\n }\n return true;\n};\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nLabelVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const item = this._items.get(entity.id);\n if (!defined(item) || !defined(item.label)) {\n return BoundingSphereState.FAILED;\n }\n\n const label = item.label;\n result.center = Cartesian3.clone(\n defaultValue(label._clampedPosition, label.position),\n result.center\n );\n result.radius = 0;\n return BoundingSphereState.DONE;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nLabelVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nLabelVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n LabelVisualizer.prototype._onCollectionChanged,\n this\n );\n const entities = this._entityCollection.values;\n for (let i = 0; i < entities.length; i++) {\n this._cluster.removeLabel(entities[i]);\n }\n return destroyObject(this);\n};\n\nLabelVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n const items = this._items;\n const cluster = this._cluster;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._label) && defined(entity._position)) {\n items.set(entity.id, new EntityData(entity));\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._label) && defined(entity._position)) {\n if (!items.contains(entity.id)) {\n items.set(entity.id, new EntityData(entity));\n }\n } else {\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n};\n\nfunction returnPrimitive(item, entity, cluster) {\n if (defined(item)) {\n item.label = undefined;\n cluster.removeLabel(entity);\n }\n}\nexport default LabelVisualizer;\n", "import Check from \"./Check.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Initiates a terrain height query for an array of {@link Cartographic} positions by\n * requesting tiles from a terrain provider, sampling, and interpolating. The interpolation\n * matches the triangles used to render the terrain at the specified level. The query\n * happens asynchronously, so this function returns a promise that is resolved when\n * the query completes. Each point height is modified in place. If a height can not be\n * determined because no terrain data is available for the specified level at that location,\n * or another error occurs, the height is set to undefined. As is typical of the\n * {@link Cartographic} type, the supplied height is a height above the reference ellipsoid\n * (such as {@link Ellipsoid.WGS84}) rather than an altitude above mean sea level. In other\n * words, it will not necessarily be 0.0 if sampled in the ocean. This function needs the\n * terrain level of detail as input, if you need to get the altitude of the terrain as precisely\n * as possible (i.e. with maximum level of detail) use {@link sampleTerrainMostDetailed}.\n *\n * @function sampleTerrain\n *\n * @param {TerrainProvider} terrainProvider The terrain provider from which to query heights.\n * @param {number} level The terrain level-of-detail from which to query terrain heights.\n * @param {Cartographic[]} positions The positions to update with terrain heights.\n * @returns {Promise} A promise that resolves to the provided list of positions when terrain the query has completed.\n *\n * @see sampleTerrainMostDetailed\n *\n * @example\n * // Query the terrain height of two Cartographic positions\n * const terrainProvider = await Cesium.createWorldTerrainAsync();\n * const positions = [\n * Cesium.Cartographic.fromDegrees(86.925145, 27.988257),\n * Cesium.Cartographic.fromDegrees(87.0, 28.0)\n * ];\n * const updatedPositions = await Cesium.sampleTerrain(terrainProvider, 11, positions);\n * // positions[0].height and positions[1].height have been updated.\n * // updatedPositions is just a reference to positions.\n */\nasync function sampleTerrain(terrainProvider, level, positions) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"terrainProvider\", terrainProvider);\n Check.typeOf.number(\"level\", level);\n Check.defined(\"positions\", positions);\n //>>includeEnd('debug');\n\n return doSampling(terrainProvider, level, positions);\n}\n\n/**\n * @param {object[]} tileRequests The mutated list of requests, the first one will be attempted\n * @param {Array>} results The list to put the result promises into\n * @returns {boolean} true if the request was made, and we are okay to attempt the next item immediately,\n * or false if we were throttled and should wait awhile before retrying.\n *\n * @private\n */\nfunction attemptConsumeNextQueueItem(tileRequests, results) {\n const tileRequest = tileRequests[0];\n const requestPromise = tileRequest.terrainProvider.requestTileGeometry(\n tileRequest.x,\n tileRequest.y,\n tileRequest.level\n );\n\n if (!requestPromise) {\n // getting back undefined instead of a promise indicates we should retry a bit later\n return false;\n }\n\n const promise = requestPromise\n .then(createInterpolateFunction(tileRequest))\n .catch(createMarkFailedFunction(tileRequest));\n\n // remove the request we've just done from the queue\n // and add its promise result to the result list\n tileRequests.shift();\n results.push(promise);\n\n // indicate we should synchronously attempt the next request as well\n return true;\n}\n\n/**\n * Wrap window.setTimeout in a Promise\n * @param {number} ms\n * @private\n */\nfunction delay(ms) {\n return new Promise(function (res) {\n setTimeout(res, ms);\n });\n}\n\n/**\n * Recursively consumes all the tileRequests until the list has been emptied\n * and a Promise of each result has been put into the results list\n * @param {object[]} tileRequests The list of requests desired to be made\n * @param {Array>} results The list to put all the result promises into\n * @returns {Promise} A promise which resolves once all requests have been started\n *\n * @private\n */\nfunction drainTileRequestQueue(tileRequests, results) {\n // nothing left to do\n if (!tileRequests.length) {\n return Promise.resolve();\n }\n\n // consume an item from the queue, which will\n // mutate the request and result lists, and return true if we should\n // immediately attempt to consume the next item as well\n const success = attemptConsumeNextQueueItem(tileRequests, results);\n if (success) {\n return drainTileRequestQueue(tileRequests, results);\n }\n\n // wait a small fixed amount of time first, before retrying the same request again\n return delay(100).then(() => {\n return drainTileRequestQueue(tileRequests, results);\n });\n}\n\nfunction doSampling(terrainProvider, level, positions) {\n const tilingScheme = terrainProvider.tilingScheme;\n\n let i;\n\n // Sort points into a set of tiles\n const tileRequests = []; // Result will be an Array as it's easier to work with\n const tileRequestSet = {}; // A unique set\n for (i = 0; i < positions.length; ++i) {\n const xy = tilingScheme.positionToTileXY(positions[i], level);\n if (!defined(xy)) {\n continue;\n }\n\n const key = xy.toString();\n\n if (!tileRequestSet.hasOwnProperty(key)) {\n // When tile is requested for the first time\n const value = {\n x: xy.x,\n y: xy.y,\n level: level,\n tilingScheme: tilingScheme,\n terrainProvider: terrainProvider,\n positions: [],\n };\n tileRequestSet[key] = value;\n tileRequests.push(value);\n }\n\n // Now append to array of points for the tile\n tileRequestSet[key].positions.push(positions[i]);\n }\n\n // create our list of result promises to be filled\n const tilePromises = [];\n return drainTileRequestQueue(tileRequests, tilePromises).then(function () {\n // now all the required requests have been started\n // we just wait for them all to finish\n return Promise.all(tilePromises).then(function () {\n return positions;\n });\n });\n}\n\n/**\n * Calls {@link TerrainData#interpolateHeight} on a given {@link TerrainData} for a given {@link Cartographic} and\n * will assign the height property if the return value is not undefined.\n *\n * If the return value is false; it's suggesting that you should call {@link TerrainData#createMesh} first.\n * @param {Cartographic} position The position to interpolate for and assign the height value to\n * @param {TerrainData} terrainData\n * @param {Rectangle} rectangle\n * @returns {boolean} If the height was actually interpolated and assigned\n * @private\n */\nfunction interpolateAndAssignHeight(position, terrainData, rectangle) {\n const height = terrainData.interpolateHeight(\n rectangle,\n position.longitude,\n position.latitude\n );\n if (height === undefined) {\n // if height comes back as undefined, it may implicitly mean the terrain data\n // requires us to call TerrainData.createMesh() first (ArcGIS requires this in particular)\n // so we'll return false and do that next!\n return false;\n }\n position.height = height;\n return true;\n}\n\nfunction createInterpolateFunction(tileRequest) {\n const tilePositions = tileRequest.positions;\n const rectangle = tileRequest.tilingScheme.tileXYToRectangle(\n tileRequest.x,\n tileRequest.y,\n tileRequest.level\n );\n return function (terrainData) {\n let isMeshRequired = false;\n for (let i = 0; i < tilePositions.length; ++i) {\n const position = tilePositions[i];\n const isHeightAssigned = interpolateAndAssignHeight(\n position,\n terrainData,\n rectangle\n );\n // we've found a position which returned undefined - hinting to us\n // that we probably need to create a mesh for this terrain data.\n // so break out of this loop and create the mesh - then we'll interpolate all the heights again\n if (!isHeightAssigned) {\n isMeshRequired = true;\n break;\n }\n }\n\n if (!isMeshRequired) {\n // all position heights were interpolated - we don't need the mesh\n return Promise.resolve();\n }\n\n // create the mesh - and interpolate all the positions again\n // note: terrain exaggeration is not passed in - we are only interested in the raw data\n return terrainData\n .createMesh({\n tilingScheme: tileRequest.tilingScheme,\n x: tileRequest.x,\n y: tileRequest.y,\n level: tileRequest.level,\n // don't throttle this mesh creation because we've asked to sample these points;\n // so sample them! We don't care how many tiles that is!\n throttle: false,\n })\n .then(function () {\n // mesh has been created - so go through every position (maybe again)\n // and re-interpolate the heights - presumably using the mesh this time\n for (let i = 0; i < tilePositions.length; ++i) {\n const position = tilePositions[i];\n // if it doesn't work this time - that's fine, we tried.\n interpolateAndAssignHeight(position, terrainData, rectangle);\n }\n });\n };\n}\n\nfunction createMarkFailedFunction(tileRequest) {\n const tilePositions = tileRequest.positions;\n return function () {\n for (let i = 0; i < tilePositions.length; ++i) {\n const position = tilePositions[i];\n position.height = undefined;\n }\n };\n}\n\nexport default sampleTerrain;\n", "import Cartesian2 from \"./Cartesian2.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport sampleTerrain from \"./sampleTerrain.js\";\n\nconst scratchCartesian2 = new Cartesian2();\n\n/**\n * Initiates a sampleTerrain() request at the maximum available tile level for a terrain dataset.\n *\n * @function sampleTerrainMostDetailed\n *\n * @param {TerrainProvider} terrainProvider The terrain provider from which to query heights.\n * @param {Cartographic[]} positions The positions to update with terrain heights.\n * @returns {Promise} A promise that resolves to the provided list of positions when terrain the query has completed. This\n * promise will reject if the terrain provider's `availability` property is undefined.\n *\n * @example\n * // Query the terrain height of two Cartographic positions\n * const terrainProvider = await Cesium.createWorldTerrainAsync();\n * const positions = [\n * Cesium.Cartographic.fromDegrees(86.925145, 27.988257),\n * Cesium.Cartographic.fromDegrees(87.0, 28.0)\n * ];\n * const updatedPositions = await Cesium.sampleTerrainMostDetailed(terrainProvider, positions);\n * // positions[0].height and positions[1].height have been updated.\n * // updatedPositions is just a reference to positions.\n */\nasync function sampleTerrainMostDetailed(terrainProvider, positions) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(terrainProvider)) {\n throw new DeveloperError(\"terrainProvider is required.\");\n }\n if (!defined(positions)) {\n throw new DeveloperError(\"positions is required.\");\n }\n //>>includeEnd('debug');\n\n const byLevel = [];\n const maxLevels = [];\n\n const availability = terrainProvider.availability;\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(availability)) {\n throw new DeveloperError(\n \"sampleTerrainMostDetailed requires a terrain provider that has tile availability.\"\n );\n }\n //>>includeEnd('debug');\n\n const promises = [];\n for (let i = 0; i < positions.length; ++i) {\n const position = positions[i];\n const maxLevel = availability.computeMaximumLevelAtPosition(position);\n maxLevels[i] = maxLevel;\n if (maxLevel === 0) {\n // This is a special case where we have a parent terrain and we are requesting\n // heights from an area that isn't covered by the top level terrain at all.\n // This will essentially trigger the loading of the parent terrains root tile\n terrainProvider.tilingScheme.positionToTileXY(\n position,\n 1,\n scratchCartesian2\n );\n const promise = terrainProvider.loadTileDataAvailability(\n scratchCartesian2.x,\n scratchCartesian2.y,\n 1\n );\n if (defined(promise)) {\n promises.push(promise);\n }\n }\n\n let atLevel = byLevel[maxLevel];\n if (!defined(atLevel)) {\n byLevel[maxLevel] = atLevel = [];\n }\n atLevel.push(position);\n }\n\n await Promise.all(promises);\n await Promise.all(\n byLevel.map(function (positionsAtLevel, index) {\n if (defined(positionsAtLevel)) {\n return sampleTerrain(terrainProvider, index, positionsAtLevel);\n }\n })\n );\n const changedPositions = [];\n for (let i = 0; i < positions.length; ++i) {\n const position = positions[i];\n const maxLevel = availability.computeMaximumLevelAtPosition(position);\n\n if (maxLevel !== maxLevels[i]) {\n // Now that we loaded the max availability, a higher level has become available\n changedPositions.push(position);\n }\n }\n\n if (changedPositions.length > 0) {\n await sampleTerrainMostDetailed(terrainProvider, changedPositions);\n }\n\n return positions;\n}\nexport default sampleTerrainMostDetailed;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Resource from \"../Core/Resource.js\";\nimport ColorBlendMode from \"../Scene/ColorBlendMode.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport Model from \"../Scene/Model/Model.js\";\nimport ModelAnimationLoop from \"../Scene/ModelAnimationLoop.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\nimport sampleTerrainMostDetailed from \"../Core/sampleTerrainMostDetailed.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\n\nconst defaultScale = 1.0;\nconst defaultMinimumPixelSize = 0.0;\nconst defaultIncrementallyLoadTextures = true;\nconst defaultClampAnimations = true;\nconst defaultShadows = ShadowMode.ENABLED;\nconst defaultHeightReference = HeightReference.NONE;\nconst defaultSilhouetteColor = Color.RED;\nconst defaultSilhouetteSize = 0.0;\nconst defaultColor = Color.WHITE;\nconst defaultColorBlendMode = ColorBlendMode.HIGHLIGHT;\nconst defaultColorBlendAmount = 0.5;\nconst defaultImageBasedLightingFactor = new Cartesian2(1.0, 1.0);\n\nconst modelMatrixScratch = new Matrix4();\nconst nodeMatrixScratch = new Matrix4();\n\nconst scratchColor = new Color();\nconst scratchArray = new Array(4);\nconst scratchCartesian = new Cartesian3();\n\n/**\n * A {@link Visualizer} which maps {@link Entity#model} to a {@link Model}.\n * @alias ModelVisualizer\n * @constructor\n *\n * @param {Scene} scene The scene the primitives will be rendered in.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction ModelVisualizer(scene, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"scene\", scene);\n Check.typeOf.object(\"entityCollection\", entityCollection);\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n ModelVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._scene = scene;\n this._primitives = scene.primitives;\n this._entityCollection = entityCollection;\n this._modelHash = {};\n this._entitiesToVisualize = new AssociativeArray();\n\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\nasync function createModelPrimitive(\n visualizer,\n entity,\n resource,\n incrementallyLoadTextures\n) {\n const primitives = visualizer._primitives;\n const modelHash = visualizer._modelHash;\n\n try {\n const model = await Model.fromGltfAsync({\n url: resource,\n incrementallyLoadTextures: incrementallyLoadTextures,\n scene: visualizer._scene,\n });\n\n if (visualizer.isDestroyed() || !defined(modelHash[entity.id])) {\n return;\n }\n\n model.id = entity;\n primitives.add(model);\n modelHash[entity.id].modelPrimitive = model;\n model.errorEvent.addEventListener((error) => {\n if (!defined(modelHash[entity.id])) {\n return;\n }\n\n console.log(error);\n\n // Texture failures when incrementallyLoadTextures\n // will not affect the ability to compute the bounding sphere\n if (error.name !== \"TextureError\" && model.incrementallyLoadTextures) {\n modelHash[entity.id].loadFailed = true;\n }\n });\n } catch (error) {\n if (visualizer.isDestroyed() || !defined(modelHash[entity.id])) {\n return;\n }\n\n console.log(error);\n modelHash[entity.id].loadFailed = true;\n }\n}\n\n/**\n * Updates models created this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nModelVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const entities = this._entitiesToVisualize.values;\n const modelHash = this._modelHash;\n const primitives = this._primitives;\n\n for (let i = 0, len = entities.length; i < len; i++) {\n const entity = entities[i];\n const modelGraphics = entity._model;\n\n let resource;\n let modelData = modelHash[entity.id];\n let show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n Property.getValueOrDefault(modelGraphics._show, time, true);\n\n let modelMatrix;\n if (show) {\n modelMatrix = entity.computeModelMatrix(time, modelMatrixScratch);\n resource = Resource.createIfNeeded(\n Property.getValueOrUndefined(modelGraphics._uri, time)\n );\n show = defined(modelMatrix) && defined(resource);\n }\n\n if (!show) {\n if (defined(modelData) && modelData.modelPrimitive) {\n modelData.modelPrimitive.show = false;\n }\n continue;\n }\n\n if (!defined(modelData) || resource.url !== modelData.url) {\n if (defined(modelData?.modelPrimitive)) {\n primitives.removeAndDestroy(modelData.modelPrimitive);\n delete modelHash[entity.id];\n }\n\n modelData = {\n modelPrimitive: undefined,\n url: resource.url,\n animationsRunning: false,\n nodeTransformationsScratch: {},\n articulationsScratch: {},\n loadFailed: false,\n modelUpdated: false,\n awaitingSampleTerrain: false,\n clampedBoundingSphere: undefined,\n sampleTerrainFailed: false,\n };\n modelHash[entity.id] = modelData;\n\n const incrementallyLoadTextures = Property.getValueOrDefault(\n modelGraphics._incrementallyLoadTextures,\n time,\n defaultIncrementallyLoadTextures\n );\n\n createModelPrimitive(this, entity, resource, incrementallyLoadTextures);\n }\n\n const model = modelData.modelPrimitive;\n if (!defined(model)) {\n continue;\n }\n\n model.show = true;\n model.scale = Property.getValueOrDefault(\n modelGraphics._scale,\n time,\n defaultScale\n );\n model.minimumPixelSize = Property.getValueOrDefault(\n modelGraphics._minimumPixelSize,\n time,\n defaultMinimumPixelSize\n );\n model.maximumScale = Property.getValueOrUndefined(\n modelGraphics._maximumScale,\n time\n );\n model.modelMatrix = Matrix4.clone(modelMatrix, model.modelMatrix);\n model.shadows = Property.getValueOrDefault(\n modelGraphics._shadows,\n time,\n defaultShadows\n );\n model.heightReference = Property.getValueOrDefault(\n modelGraphics._heightReference,\n time,\n defaultHeightReference\n );\n model.distanceDisplayCondition = Property.getValueOrUndefined(\n modelGraphics._distanceDisplayCondition,\n time\n );\n model.silhouetteColor = Property.getValueOrDefault(\n modelGraphics._silhouetteColor,\n time,\n defaultSilhouetteColor,\n scratchColor\n );\n model.silhouetteSize = Property.getValueOrDefault(\n modelGraphics._silhouetteSize,\n time,\n defaultSilhouetteSize\n );\n model.color = Property.getValueOrDefault(\n modelGraphics._color,\n time,\n defaultColor,\n scratchColor\n );\n model.colorBlendMode = Property.getValueOrDefault(\n modelGraphics._colorBlendMode,\n time,\n defaultColorBlendMode\n );\n model.colorBlendAmount = Property.getValueOrDefault(\n modelGraphics._colorBlendAmount,\n time,\n defaultColorBlendAmount\n );\n model.clippingPlanes = Property.getValueOrUndefined(\n modelGraphics._clippingPlanes,\n time\n );\n model.clampAnimations = Property.getValueOrDefault(\n modelGraphics._clampAnimations,\n time,\n defaultClampAnimations\n );\n model.imageBasedLighting.imageBasedLightingFactor = Property.getValueOrDefault(\n modelGraphics._imageBasedLightingFactor,\n time,\n defaultImageBasedLightingFactor\n );\n let lightColor = Property.getValueOrUndefined(\n modelGraphics._lightColor,\n time\n );\n\n // Convert from Color to Cartesian3\n if (defined(lightColor)) {\n Color.pack(lightColor, scratchArray, 0);\n lightColor = Cartesian3.unpack(scratchArray, 0, scratchCartesian);\n }\n\n model.lightColor = lightColor;\n model.customShader = Property.getValueOrUndefined(\n modelGraphics._customShader,\n time\n );\n\n // It's possible for getBoundingSphere to run before\n // model becomes ready and these properties are updated\n modelHash[entity.id].modelUpdated = true;\n\n if (model.ready) {\n const runAnimations = Property.getValueOrDefault(\n modelGraphics._runAnimations,\n time,\n true\n );\n if (modelData.animationsRunning !== runAnimations) {\n if (runAnimations) {\n model.activeAnimations.addAll({\n loop: ModelAnimationLoop.REPEAT,\n });\n } else {\n model.activeAnimations.removeAll();\n }\n modelData.animationsRunning = runAnimations;\n }\n\n // Apply node transformations\n const nodeTransformations = Property.getValueOrUndefined(\n modelGraphics._nodeTransformations,\n time,\n modelData.nodeTransformationsScratch\n );\n if (defined(nodeTransformations)) {\n const nodeNames = Object.keys(nodeTransformations);\n for (\n let nodeIndex = 0, nodeLength = nodeNames.length;\n nodeIndex < nodeLength;\n ++nodeIndex\n ) {\n const nodeName = nodeNames[nodeIndex];\n\n const nodeTransformation = nodeTransformations[nodeName];\n if (!defined(nodeTransformation)) {\n continue;\n }\n\n const modelNode = model.getNode(nodeName);\n if (!defined(modelNode)) {\n continue;\n }\n\n const transformationMatrix = Matrix4.fromTranslationRotationScale(\n nodeTransformation,\n nodeMatrixScratch\n );\n modelNode.matrix = Matrix4.multiply(\n modelNode.originalMatrix,\n transformationMatrix,\n transformationMatrix\n );\n }\n }\n\n // Apply articulations\n let anyArticulationUpdated = false;\n const articulations = Property.getValueOrUndefined(\n modelGraphics._articulations,\n time,\n modelData.articulationsScratch\n );\n if (defined(articulations)) {\n const articulationStageKeys = Object.keys(articulations);\n for (\n let s = 0, numKeys = articulationStageKeys.length;\n s < numKeys;\n ++s\n ) {\n const key = articulationStageKeys[s];\n\n const articulationStageValue = articulations[key];\n if (!defined(articulationStageValue)) {\n continue;\n }\n\n anyArticulationUpdated = true;\n model.setArticulationStage(key, articulationStageValue);\n }\n }\n\n if (anyArticulationUpdated) {\n model.applyArticulations();\n }\n }\n }\n\n return true;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nModelVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nModelVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n ModelVisualizer.prototype._onCollectionChanged,\n this\n );\n const entities = this._entitiesToVisualize.values;\n const modelHash = this._modelHash;\n const primitives = this._primitives;\n for (let i = entities.length - 1; i > -1; i--) {\n removeModel(this, entities[i], modelHash, primitives);\n }\n return destroyObject(this);\n};\n\n// Used for testing.\nModelVisualizer._sampleTerrainMostDetailed = sampleTerrainMostDetailed;\n\nconst scratchPosition = new Cartesian3();\nconst scratchCartographic = new Cartographic();\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nModelVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const modelData = this._modelHash[entity.id];\n if (!defined(modelData)) {\n return BoundingSphereState.FAILED;\n }\n\n if (modelData.loadFailed) {\n return BoundingSphereState.FAILED;\n }\n\n const model = modelData.modelPrimitive;\n if (!defined(model) || !model.show) {\n return BoundingSphereState.PENDING;\n }\n\n if (!model.ready || !modelData.modelUpdated) {\n return BoundingSphereState.PENDING;\n }\n\n const scene = this._scene;\n const globe = scene.globe;\n\n // cannot access a terrain provider if there is no globe; formally set to undefined\n const terrainProvider = defined(globe) ? globe.terrainProvider : undefined;\n const hasHeightReference = model.heightReference !== HeightReference.NONE;\n if (defined(globe) && hasHeightReference) {\n const ellipsoid = globe.ellipsoid;\n const modelMatrix = model.modelMatrix;\n scratchPosition.x = modelMatrix[12];\n scratchPosition.y = modelMatrix[13];\n scratchPosition.z = modelMatrix[14];\n const cartoPosition = ellipsoid.cartesianToCartographic(scratchPosition);\n\n // For a terrain provider that does not have availability, like the EllipsoidTerrainProvider,\n // we can directly assign the bounding sphere's center from model matrix's translation.\n if (!defined(terrainProvider.availability)) {\n // Regardless of what the original model's position is set to, for CLAMP_TO_GROUND, we reset it to 0\n // when computing the position to zoom/fly to.\n if (model.heightReference === HeightReference.CLAMP_TO_GROUND) {\n cartoPosition.height = 0;\n }\n\n const scratchPosition = ellipsoid.cartographicToCartesian(cartoPosition);\n BoundingSphere.clone(model.boundingSphere, result);\n result.center = scratchPosition;\n\n return BoundingSphereState.DONE;\n }\n\n // Otherwise, in the case of terrain providers with availability,\n // since the model's bounding sphere may be clamped to a lower LOD tile if\n // the camera is initially far away, we use sampleTerrainMostDetailed to estimate\n // where the bounding sphere should be and set that as the target bounding sphere\n // for the camera.\n let clampedBoundingSphere = this._modelHash[entity.id]\n .clampedBoundingSphere;\n\n // Check if the sample terrain function has failed.\n const sampleTerrainFailed = this._modelHash[entity.id].sampleTerrainFailed;\n if (sampleTerrainFailed) {\n this._modelHash[entity.id].sampleTerrainFailed = false;\n return BoundingSphereState.FAILED;\n }\n\n if (!defined(clampedBoundingSphere)) {\n clampedBoundingSphere = new BoundingSphere();\n\n // Since this function is called per-frame, we set a flag when sampleTerrainMostDetailed\n // is called and check for it to avoid calling it again.\n const awaitingSampleTerrain = this._modelHash[entity.id]\n .awaitingSampleTerrain;\n if (!awaitingSampleTerrain) {\n Cartographic.clone(cartoPosition, scratchCartographic);\n this._modelHash[entity.id].awaitingSampleTerrain = true;\n ModelVisualizer._sampleTerrainMostDetailed(terrainProvider, [\n scratchCartographic,\n ])\n .then((result) => {\n if (this.isDestroyed()) {\n return;\n }\n\n this._modelHash[entity.id].awaitingSampleTerrain = false;\n\n const updatedCartographic = result[0];\n if (model.heightReference === HeightReference.RELATIVE_TO_GROUND) {\n updatedCartographic.height += cartoPosition.height;\n }\n ellipsoid.cartographicToCartesian(\n updatedCartographic,\n scratchPosition\n );\n\n // Update the bounding sphere with the updated position.\n BoundingSphere.clone(model.boundingSphere, clampedBoundingSphere);\n clampedBoundingSphere.center = scratchPosition;\n\n this._modelHash[\n entity.id\n ].clampedBoundingSphere = BoundingSphere.clone(\n clampedBoundingSphere\n );\n })\n .catch((e) => {\n if (this.isDestroyed()) {\n return;\n }\n\n this._modelHash[entity.id].sampleTerrainFailed = true;\n this._modelHash[entity.id].awaitingSampleTerrain = false;\n });\n }\n\n // We will return the state as pending until the clamped bounding sphere is defined,\n // which happens when the sampleTerrainMostDetailed promise returns.\n return BoundingSphereState.PENDING;\n }\n\n BoundingSphere.clone(clampedBoundingSphere, result);\n // Reset the clamped bounding sphere.\n this._modelHash[entity.id].clampedBoundingSphere = undefined;\n return BoundingSphereState.DONE;\n }\n\n BoundingSphere.clone(model.boundingSphere, result);\n return BoundingSphereState.DONE;\n};\n\n/**\n * @private\n */\nModelVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n const entities = this._entitiesToVisualize;\n const modelHash = this._modelHash;\n const primitives = this._primitives;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._model) && defined(entity._position)) {\n entities.set(entity.id, entity);\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._model) && defined(entity._position)) {\n clearNodeTransformationsArticulationsScratch(entity, modelHash);\n entities.set(entity.id, entity);\n } else {\n removeModel(this, entity, modelHash, primitives);\n entities.remove(entity.id);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n removeModel(this, entity, modelHash, primitives);\n entities.remove(entity.id);\n }\n};\n\nfunction removeModel(visualizer, entity, modelHash, primitives) {\n const modelData = modelHash[entity.id];\n if (defined(modelData)) {\n primitives.removeAndDestroy(modelData.modelPrimitive);\n delete modelHash[entity.id];\n }\n}\n\nfunction clearNodeTransformationsArticulationsScratch(entity, modelHash) {\n const modelData = modelHash[entity.id];\n if (defined(modelData)) {\n modelData.nodeTransformationsScratch = {};\n modelData.articulationsScratch = {};\n }\n}\n\nexport default ModelVisualizer;\n", "import defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Event from \"../Core/Event.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport Property from \"./Property.js\";\n\n/**\n * This is a temporary class for scaling position properties to the WGS84 surface.\n * It will go away or be refactored to support data with arbitrary height references.\n * @private\n */\nfunction ScaledPositionProperty(value) {\n this._definitionChanged = new Event();\n this._value = undefined;\n this._removeSubscription = undefined;\n this.setValue(value);\n}\n\nObject.defineProperties(ScaledPositionProperty.prototype, {\n isConstant: {\n get: function () {\n return Property.isConstant(this._value);\n },\n },\n definitionChanged: {\n get: function () {\n return this._definitionChanged;\n },\n },\n referenceFrame: {\n get: function () {\n return defined(this._value)\n ? this._value.referenceFrame\n : ReferenceFrame.FIXED;\n },\n },\n});\n\nScaledPositionProperty.prototype.getValue = function (time, result) {\n return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);\n};\n\nScaledPositionProperty.prototype.setValue = function (value) {\n if (this._value !== value) {\n this._value = value;\n\n if (defined(this._removeSubscription)) {\n this._removeSubscription();\n this._removeSubscription = undefined;\n }\n\n if (defined(value)) {\n this._removeSubscription = value.definitionChanged.addEventListener(\n this._raiseDefinitionChanged,\n this\n );\n }\n this._definitionChanged.raiseEvent(this);\n }\n};\n\nScaledPositionProperty.prototype.getValueInReferenceFrame = function (\n time,\n referenceFrame,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n if (!defined(referenceFrame)) {\n throw new DeveloperError(\"referenceFrame is required.\");\n }\n //>>includeEnd('debug');\n\n if (!defined(this._value)) {\n return undefined;\n }\n\n result = this._value.getValueInReferenceFrame(time, referenceFrame, result);\n return defined(result)\n ? Ellipsoid.WGS84.scaleToGeodeticSurface(result, result)\n : undefined;\n};\n\nScaledPositionProperty.prototype.equals = function (other) {\n return (\n this === other ||\n (other instanceof ScaledPositionProperty && this._value === other._value)\n );\n};\n\nScaledPositionProperty.prototype._raiseDefinitionChanged = function () {\n this._definitionChanged.raiseEvent(this);\n};\nexport default ScaledPositionProperty;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport PolylineCollection from \"../Scene/PolylineCollection.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport CompositePositionProperty from \"./CompositePositionProperty.js\";\nimport ConstantPositionProperty from \"./ConstantPositionProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\nimport ReferenceProperty from \"./ReferenceProperty.js\";\nimport SampledPositionProperty from \"./SampledPositionProperty.js\";\nimport ScaledPositionProperty from \"./ScaledPositionProperty.js\";\nimport TimeIntervalCollectionPositionProperty from \"./TimeIntervalCollectionPositionProperty.js\";\n\nconst defaultResolution = 60.0;\nconst defaultWidth = 1.0;\n\nconst scratchTimeInterval = new TimeInterval();\nconst subSampleCompositePropertyScratch = new TimeInterval();\nconst subSampleIntervalPropertyScratch = new TimeInterval();\n\nfunction EntityData(entity) {\n this.entity = entity;\n this.polyline = undefined;\n this.index = undefined;\n this.updater = undefined;\n}\n\nfunction subSampleSampledProperty(\n property,\n start,\n stop,\n times,\n updateTime,\n referenceFrame,\n maximumStep,\n startingIndex,\n result\n) {\n let r = startingIndex;\n //Always step exactly on start (but only use it if it exists.)\n let tmp;\n tmp = property.getValueInReferenceFrame(start, referenceFrame, result[r]);\n if (defined(tmp)) {\n result[r++] = tmp;\n }\n\n let steppedOnNow =\n !defined(updateTime) ||\n JulianDate.lessThanOrEquals(updateTime, start) ||\n JulianDate.greaterThanOrEquals(updateTime, stop);\n\n //Iterate over all interval times and add the ones that fall in our\n //time range. Note that times can contain data outside of\n //the intervals range. This is by design for use with interpolation.\n let t = 0;\n const len = times.length;\n let current = times[t];\n const loopStop = stop;\n let sampling = false;\n let sampleStepsToTake;\n let sampleStepsTaken;\n let sampleStepSize;\n\n while (t < len) {\n if (!steppedOnNow && JulianDate.greaterThanOrEquals(current, updateTime)) {\n tmp = property.getValueInReferenceFrame(\n updateTime,\n referenceFrame,\n result[r]\n );\n if (defined(tmp)) {\n result[r++] = tmp;\n }\n steppedOnNow = true;\n }\n if (\n JulianDate.greaterThan(current, start) &&\n JulianDate.lessThan(current, loopStop) &&\n !current.equals(updateTime)\n ) {\n tmp = property.getValueInReferenceFrame(\n current,\n referenceFrame,\n result[r]\n );\n if (defined(tmp)) {\n result[r++] = tmp;\n }\n }\n\n if (t < len - 1) {\n if (maximumStep > 0 && !sampling) {\n const next = times[t + 1];\n const secondsUntilNext = JulianDate.secondsDifference(next, current);\n sampling = secondsUntilNext > maximumStep;\n\n if (sampling) {\n sampleStepsToTake = Math.ceil(secondsUntilNext / maximumStep);\n sampleStepsTaken = 0;\n sampleStepSize = secondsUntilNext / Math.max(sampleStepsToTake, 2);\n sampleStepsToTake = Math.max(sampleStepsToTake - 1, 1);\n }\n }\n\n if (sampling && sampleStepsTaken < sampleStepsToTake) {\n current = JulianDate.addSeconds(\n current,\n sampleStepSize,\n new JulianDate()\n );\n sampleStepsTaken++;\n continue;\n }\n }\n sampling = false;\n t++;\n current = times[t];\n }\n\n //Always step exactly on stop (but only use it if it exists.)\n tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[r]);\n if (defined(tmp)) {\n result[r++] = tmp;\n }\n\n return r;\n}\n\nfunction subSampleGenericProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n startingIndex,\n result\n) {\n let tmp;\n let i = 0;\n let index = startingIndex;\n let time = start;\n const stepSize = Math.max(maximumStep, 60);\n let steppedOnNow =\n !defined(updateTime) ||\n JulianDate.lessThanOrEquals(updateTime, start) ||\n JulianDate.greaterThanOrEquals(updateTime, stop);\n while (JulianDate.lessThan(time, stop)) {\n if (!steppedOnNow && JulianDate.greaterThanOrEquals(time, updateTime)) {\n steppedOnNow = true;\n tmp = property.getValueInReferenceFrame(\n updateTime,\n referenceFrame,\n result[index]\n );\n if (defined(tmp)) {\n result[index] = tmp;\n index++;\n }\n }\n tmp = property.getValueInReferenceFrame(\n time,\n referenceFrame,\n result[index]\n );\n if (defined(tmp)) {\n result[index] = tmp;\n index++;\n }\n i++;\n time = JulianDate.addSeconds(start, stepSize * i, new JulianDate());\n }\n //Always sample stop.\n tmp = property.getValueInReferenceFrame(stop, referenceFrame, result[index]);\n if (defined(tmp)) {\n result[index] = tmp;\n index++;\n }\n return index;\n}\n\nfunction subSampleIntervalProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n startingIndex,\n result\n) {\n subSampleIntervalPropertyScratch.start = start;\n subSampleIntervalPropertyScratch.stop = stop;\n\n let index = startingIndex;\n const intervals = property.intervals;\n for (let i = 0; i < intervals.length; i++) {\n const interval = intervals.get(i);\n if (\n !TimeInterval.intersect(\n interval,\n subSampleIntervalPropertyScratch,\n scratchTimeInterval\n ).isEmpty\n ) {\n let time = interval.start;\n if (!interval.isStartIncluded) {\n if (interval.isStopIncluded) {\n time = interval.stop;\n } else {\n time = JulianDate.addSeconds(\n interval.start,\n JulianDate.secondsDifference(interval.stop, interval.start) / 2,\n new JulianDate()\n );\n }\n }\n const tmp = property.getValueInReferenceFrame(\n time,\n referenceFrame,\n result[index]\n );\n if (defined(tmp)) {\n result[index] = tmp;\n index++;\n }\n }\n }\n return index;\n}\n\nfunction subSampleConstantProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n startingIndex,\n result\n) {\n const tmp = property.getValueInReferenceFrame(\n start,\n referenceFrame,\n result[startingIndex]\n );\n if (defined(tmp)) {\n result[startingIndex++] = tmp;\n }\n return startingIndex;\n}\n\nfunction subSampleCompositeProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n startingIndex,\n result\n) {\n subSampleCompositePropertyScratch.start = start;\n subSampleCompositePropertyScratch.stop = stop;\n\n let index = startingIndex;\n const intervals = property.intervals;\n for (let i = 0; i < intervals.length; i++) {\n const interval = intervals.get(i);\n if (\n !TimeInterval.intersect(\n interval,\n subSampleCompositePropertyScratch,\n scratchTimeInterval\n ).isEmpty\n ) {\n const intervalStart = interval.start;\n const intervalStop = interval.stop;\n\n let sampleStart = start;\n if (JulianDate.greaterThan(intervalStart, sampleStart)) {\n sampleStart = intervalStart;\n }\n\n let sampleStop = stop;\n if (JulianDate.lessThan(intervalStop, sampleStop)) {\n sampleStop = intervalStop;\n }\n\n index = reallySubSample(\n interval.data,\n sampleStart,\n sampleStop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n }\n }\n return index;\n}\n\nfunction reallySubSample(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n) {\n //Unwrap any references until we have the actual property.\n while (property instanceof ReferenceProperty) {\n property = property.resolvedProperty;\n }\n\n if (property instanceof SampledPositionProperty) {\n const times = property._property._times;\n index = subSampleSampledProperty(\n property,\n start,\n stop,\n times,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n } else if (property instanceof CompositePositionProperty) {\n index = subSampleCompositeProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n } else if (property instanceof TimeIntervalCollectionPositionProperty) {\n index = subSampleIntervalProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n } else if (\n property instanceof ConstantPositionProperty ||\n (property instanceof ScaledPositionProperty &&\n Property.isConstant(property))\n ) {\n index = subSampleConstantProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n } else {\n //Fallback to generic sampling.\n index = subSampleGenericProperty(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n index,\n result\n );\n }\n return index;\n}\n\nfunction subSample(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n result\n) {\n if (!defined(result)) {\n result = [];\n }\n\n const length = reallySubSample(\n property,\n start,\n stop,\n updateTime,\n referenceFrame,\n maximumStep,\n 0,\n result\n );\n result.length = length;\n return result;\n}\n\nconst toFixedScratch = new Matrix3();\nfunction PolylineUpdater(scene, referenceFrame) {\n this._unusedIndexes = [];\n this._polylineCollection = new PolylineCollection();\n this._scene = scene;\n this._referenceFrame = referenceFrame;\n scene.primitives.add(this._polylineCollection);\n}\n\nPolylineUpdater.prototype.update = function (time) {\n if (this._referenceFrame === ReferenceFrame.INERTIAL) {\n let toFixed = Transforms.computeIcrfToFixedMatrix(time, toFixedScratch);\n if (!defined(toFixed)) {\n toFixed = Transforms.computeTemeToPseudoFixedMatrix(time, toFixedScratch);\n }\n Matrix4.fromRotationTranslation(\n toFixed,\n Cartesian3.ZERO,\n this._polylineCollection.modelMatrix\n );\n }\n};\n\nPolylineUpdater.prototype.updateObject = function (time, item) {\n const entity = item.entity;\n const pathGraphics = entity._path;\n const positionProperty = entity._position;\n\n let sampleStart;\n let sampleStop;\n const showProperty = pathGraphics._show;\n let polyline = item.polyline;\n let show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n (!defined(showProperty) || showProperty.getValue(time));\n\n //While we want to show the path, there may not actually be anything to show\n //depending on lead/trail settings. Compute the interval of the path to\n //show and check against actual availability.\n if (show) {\n const leadTime = Property.getValueOrUndefined(pathGraphics._leadTime, time);\n const trailTime = Property.getValueOrUndefined(\n pathGraphics._trailTime,\n time\n );\n const availability = entity._availability;\n const hasAvailability = defined(availability);\n const hasLeadTime = defined(leadTime);\n const hasTrailTime = defined(trailTime);\n\n //Objects need to have either defined availability or both a lead and trail time in order to\n //draw a path (since we can't draw \"infinite\" paths.\n show = hasAvailability || (hasLeadTime && hasTrailTime);\n\n //The final step is to compute the actual start/stop times of the path to show.\n //If current time is outside of the availability interval, there's a chance that\n //we won't have to draw anything anyway.\n if (show) {\n if (hasTrailTime) {\n sampleStart = JulianDate.addSeconds(time, -trailTime, new JulianDate());\n }\n if (hasLeadTime) {\n sampleStop = JulianDate.addSeconds(time, leadTime, new JulianDate());\n }\n\n if (hasAvailability) {\n const start = availability.start;\n const stop = availability.stop;\n\n if (!hasTrailTime || JulianDate.greaterThan(start, sampleStart)) {\n sampleStart = start;\n }\n\n if (!hasLeadTime || JulianDate.lessThan(stop, sampleStop)) {\n sampleStop = stop;\n }\n }\n show = JulianDate.lessThan(sampleStart, sampleStop);\n }\n }\n\n if (!show) {\n //don't bother creating or updating anything else\n if (defined(polyline)) {\n this._unusedIndexes.push(item.index);\n item.polyline = undefined;\n polyline.show = false;\n item.index = undefined;\n }\n return;\n }\n\n if (!defined(polyline)) {\n const unusedIndexes = this._unusedIndexes;\n const length = unusedIndexes.length;\n if (length > 0) {\n const index = unusedIndexes.pop();\n polyline = this._polylineCollection.get(index);\n item.index = index;\n } else {\n item.index = this._polylineCollection.length;\n polyline = this._polylineCollection.add();\n }\n polyline.id = entity;\n item.polyline = polyline;\n }\n\n const resolution = Property.getValueOrDefault(\n pathGraphics._resolution,\n time,\n defaultResolution\n );\n\n polyline.show = true;\n polyline.positions = subSample(\n positionProperty,\n sampleStart,\n sampleStop,\n time,\n this._referenceFrame,\n resolution,\n polyline.positions.slice()\n );\n polyline.material = MaterialProperty.getValue(\n time,\n pathGraphics._material,\n polyline.material\n );\n polyline.width = Property.getValueOrDefault(\n pathGraphics._width,\n time,\n defaultWidth\n );\n polyline.distanceDisplayCondition = Property.getValueOrUndefined(\n pathGraphics._distanceDisplayCondition,\n time,\n polyline.distanceDisplayCondition\n );\n};\n\nPolylineUpdater.prototype.removeObject = function (item) {\n const polyline = item.polyline;\n if (defined(polyline)) {\n this._unusedIndexes.push(item.index);\n item.polyline = undefined;\n polyline.show = false;\n polyline.id = undefined;\n item.index = undefined;\n }\n};\n\nPolylineUpdater.prototype.destroy = function () {\n this._scene.primitives.remove(this._polylineCollection);\n return destroyObject(this);\n};\n\n/**\n * A {@link Visualizer} which maps {@link Entity#path} to a {@link Polyline}.\n * @alias PathVisualizer\n * @constructor\n *\n * @param {Scene} scene The scene the primitives will be rendered in.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction PathVisualizer(scene, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required.\");\n }\n if (!defined(entityCollection)) {\n throw new DeveloperError(\"entityCollection is required.\");\n }\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n PathVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._scene = scene;\n this._updaters = {};\n this._entityCollection = entityCollection;\n this._items = new AssociativeArray();\n\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\n/**\n * Updates all of the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nPathVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const updaters = this._updaters;\n for (const key in updaters) {\n if (updaters.hasOwnProperty(key)) {\n updaters[key].update(time);\n }\n }\n\n const items = this._items.values;\n if (\n items.length === 0 &&\n defined(this._updaters) &&\n Object.keys(this._updaters).length > 0\n ) {\n for (const u in updaters) {\n if (updaters.hasOwnProperty(u)) {\n updaters[u].destroy();\n }\n }\n this._updaters = {};\n }\n\n for (let i = 0, len = items.length; i < len; i++) {\n const item = items[i];\n const entity = item.entity;\n const positionProperty = entity._position;\n\n const lastUpdater = item.updater;\n\n let frameToVisualize = ReferenceFrame.FIXED;\n if (this._scene.mode === SceneMode.SCENE3D) {\n frameToVisualize = positionProperty.referenceFrame;\n }\n\n let currentUpdater = this._updaters[frameToVisualize];\n\n if (lastUpdater === currentUpdater && defined(currentUpdater)) {\n currentUpdater.updateObject(time, item);\n continue;\n }\n\n if (defined(lastUpdater)) {\n lastUpdater.removeObject(item);\n }\n\n if (!defined(currentUpdater)) {\n currentUpdater = new PolylineUpdater(this._scene, frameToVisualize);\n currentUpdater.update(time);\n this._updaters[frameToVisualize] = currentUpdater;\n }\n\n item.updater = currentUpdater;\n if (defined(currentUpdater)) {\n currentUpdater.updateObject(time, item);\n }\n }\n return true;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nPathVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nPathVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n PathVisualizer.prototype._onCollectionChanged,\n this\n );\n\n const updaters = this._updaters;\n for (const key in updaters) {\n if (updaters.hasOwnProperty(key)) {\n updaters[key].destroy();\n }\n }\n\n return destroyObject(this);\n};\n\nPathVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n let item;\n const items = this._items;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._path) && defined(entity._position)) {\n items.set(entity.id, new EntityData(entity));\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._path) && defined(entity._position)) {\n if (!items.contains(entity.id)) {\n items.set(entity.id, new EntityData(entity));\n }\n } else {\n item = items.get(entity.id);\n if (defined(item)) {\n if (defined(item.updater)) {\n item.updater.removeObject(item);\n }\n items.remove(entity.id);\n }\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n item = items.get(entity.id);\n if (defined(item)) {\n if (defined(item.updater)) {\n item.updater.removeObject(item);\n }\n items.remove(entity.id);\n }\n }\n};\n\n//for testing\nPathVisualizer._subSample = subSample;\nexport default PathVisualizer;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport createBillboardPointCallback from \"../Scene/createBillboardPointCallback.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport Property from \"./Property.js\";\n\nconst defaultColor = Color.WHITE;\nconst defaultOutlineColor = Color.BLACK;\nconst defaultOutlineWidth = 0.0;\nconst defaultPixelSize = 1.0;\nconst defaultDisableDepthTestDistance = 0.0;\n\nconst colorScratch = new Color();\nconst positionScratch = new Cartesian3();\nconst outlineColorScratch = new Color();\nconst scaleByDistanceScratch = new NearFarScalar();\nconst translucencyByDistanceScratch = new NearFarScalar();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\n\nfunction EntityData(entity) {\n this.entity = entity;\n this.pointPrimitive = undefined;\n this.billboard = undefined;\n this.color = undefined;\n this.outlineColor = undefined;\n this.pixelSize = undefined;\n this.outlineWidth = undefined;\n}\n\n/**\n * A {@link Visualizer} which maps {@link Entity#point} to a {@link PointPrimitive}.\n * @alias PointVisualizer\n * @constructor\n *\n * @param {EntityCluster} entityCluster The entity cluster to manage the collection of billboards and optionally cluster with other entities.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n */\nfunction PointVisualizer(entityCluster, entityCollection) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entityCluster)) {\n throw new DeveloperError(\"entityCluster is required.\");\n }\n if (!defined(entityCollection)) {\n throw new DeveloperError(\"entityCollection is required.\");\n }\n //>>includeEnd('debug');\n\n entityCollection.collectionChanged.addEventListener(\n PointVisualizer.prototype._onCollectionChanged,\n this\n );\n\n this._cluster = entityCluster;\n this._entityCollection = entityCollection;\n this._items = new AssociativeArray();\n this._onCollectionChanged(entityCollection, entityCollection.values, [], []);\n}\n\n/**\n * Updates the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} This function always returns true.\n */\nPointVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n //>>includeEnd('debug');\n\n const items = this._items.values;\n const cluster = this._cluster;\n for (let i = 0, len = items.length; i < len; i++) {\n const item = items[i];\n const entity = item.entity;\n const pointGraphics = entity._point;\n let pointPrimitive = item.pointPrimitive;\n let billboard = item.billboard;\n const heightReference = Property.getValueOrDefault(\n pointGraphics._heightReference,\n time,\n HeightReference.NONE\n );\n let show =\n entity.isShowing &&\n entity.isAvailable(time) &&\n Property.getValueOrDefault(pointGraphics._show, time, true);\n let position;\n if (show) {\n position = Property.getValueOrUndefined(\n entity._position,\n time,\n positionScratch\n );\n show = defined(position);\n }\n if (!show) {\n returnPrimitive(item, entity, cluster);\n continue;\n }\n\n if (!Property.isConstant(entity._position)) {\n cluster._clusterDirty = true;\n }\n\n let needsRedraw = false;\n let updateClamping = false;\n if (heightReference !== HeightReference.NONE && !defined(billboard)) {\n if (defined(pointPrimitive)) {\n returnPrimitive(item, entity, cluster);\n pointPrimitive = undefined;\n }\n\n billboard = cluster.getBillboard(entity);\n billboard.id = entity;\n billboard.image = undefined;\n item.billboard = billboard;\n needsRedraw = true;\n\n // If this new billboard happens to have a position and height reference that match our new values,\n // billboard._updateClamping will not be called automatically. That's a problem because the clamped\n // height may be based on different terrain than is now loaded. So we'll manually call\n // _updateClamping below.\n updateClamping =\n Cartesian3.equals(billboard.position, position) &&\n billboard.heightReference === heightReference;\n } else if (\n heightReference === HeightReference.NONE &&\n !defined(pointPrimitive)\n ) {\n if (defined(billboard)) {\n returnPrimitive(item, entity, cluster);\n billboard = undefined;\n }\n\n pointPrimitive = cluster.getPoint(entity);\n pointPrimitive.id = entity;\n item.pointPrimitive = pointPrimitive;\n }\n\n if (defined(pointPrimitive)) {\n pointPrimitive.show = true;\n pointPrimitive.position = position;\n pointPrimitive.scaleByDistance = Property.getValueOrUndefined(\n pointGraphics._scaleByDistance,\n time,\n scaleByDistanceScratch\n );\n pointPrimitive.translucencyByDistance = Property.getValueOrUndefined(\n pointGraphics._translucencyByDistance,\n time,\n translucencyByDistanceScratch\n );\n pointPrimitive.color = Property.getValueOrDefault(\n pointGraphics._color,\n time,\n defaultColor,\n colorScratch\n );\n pointPrimitive.outlineColor = Property.getValueOrDefault(\n pointGraphics._outlineColor,\n time,\n defaultOutlineColor,\n outlineColorScratch\n );\n pointPrimitive.outlineWidth = Property.getValueOrDefault(\n pointGraphics._outlineWidth,\n time,\n defaultOutlineWidth\n );\n pointPrimitive.pixelSize = Property.getValueOrDefault(\n pointGraphics._pixelSize,\n time,\n defaultPixelSize\n );\n pointPrimitive.distanceDisplayCondition = Property.getValueOrUndefined(\n pointGraphics._distanceDisplayCondition,\n time,\n distanceDisplayConditionScratch\n );\n pointPrimitive.disableDepthTestDistance = Property.getValueOrDefault(\n pointGraphics._disableDepthTestDistance,\n time,\n defaultDisableDepthTestDistance\n );\n } else if (defined(billboard)) {\n billboard.show = true;\n billboard.position = position;\n billboard.scaleByDistance = Property.getValueOrUndefined(\n pointGraphics._scaleByDistance,\n time,\n scaleByDistanceScratch\n );\n billboard.translucencyByDistance = Property.getValueOrUndefined(\n pointGraphics._translucencyByDistance,\n time,\n translucencyByDistanceScratch\n );\n billboard.distanceDisplayCondition = Property.getValueOrUndefined(\n pointGraphics._distanceDisplayCondition,\n time,\n distanceDisplayConditionScratch\n );\n billboard.disableDepthTestDistance = Property.getValueOrDefault(\n pointGraphics._disableDepthTestDistance,\n time,\n defaultDisableDepthTestDistance\n );\n billboard.heightReference = heightReference;\n\n const newColor = Property.getValueOrDefault(\n pointGraphics._color,\n time,\n defaultColor,\n colorScratch\n );\n const newOutlineColor = Property.getValueOrDefault(\n pointGraphics._outlineColor,\n time,\n defaultOutlineColor,\n outlineColorScratch\n );\n const newOutlineWidth = Math.round(\n Property.getValueOrDefault(\n pointGraphics._outlineWidth,\n time,\n defaultOutlineWidth\n )\n );\n let newPixelSize = Math.max(\n 1,\n Math.round(\n Property.getValueOrDefault(\n pointGraphics._pixelSize,\n time,\n defaultPixelSize\n )\n )\n );\n\n if (newOutlineWidth > 0) {\n billboard.scale = 1.0;\n needsRedraw =\n needsRedraw || //\n newOutlineWidth !== item.outlineWidth || //\n newPixelSize !== item.pixelSize || //\n !Color.equals(newColor, item.color) || //\n !Color.equals(newOutlineColor, item.outlineColor);\n } else {\n billboard.scale = newPixelSize / 50.0;\n newPixelSize = 50.0;\n needsRedraw =\n needsRedraw || //\n newOutlineWidth !== item.outlineWidth || //\n !Color.equals(newColor, item.color) || //\n !Color.equals(newOutlineColor, item.outlineColor);\n }\n\n if (needsRedraw) {\n item.color = Color.clone(newColor, item.color);\n item.outlineColor = Color.clone(newOutlineColor, item.outlineColor);\n item.pixelSize = newPixelSize;\n item.outlineWidth = newOutlineWidth;\n\n const centerAlpha = newColor.alpha;\n const cssColor = newColor.toCssColorString();\n const cssOutlineColor = newOutlineColor.toCssColorString();\n const textureId = JSON.stringify([\n cssColor,\n newPixelSize,\n cssOutlineColor,\n newOutlineWidth,\n ]);\n\n billboard.setImage(\n textureId,\n createBillboardPointCallback(\n centerAlpha,\n cssColor,\n cssOutlineColor,\n newOutlineWidth,\n newPixelSize\n )\n );\n }\n\n if (updateClamping) {\n billboard._updateClamping();\n }\n }\n }\n return true;\n};\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nPointVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required.\");\n }\n if (!defined(result)) {\n throw new DeveloperError(\"result is required.\");\n }\n //>>includeEnd('debug');\n\n const item = this._items.get(entity.id);\n if (\n !defined(item) ||\n !(defined(item.pointPrimitive) || defined(item.billboard))\n ) {\n return BoundingSphereState.FAILED;\n }\n\n if (defined(item.pointPrimitive)) {\n result.center = Cartesian3.clone(\n item.pointPrimitive.position,\n result.center\n );\n } else {\n const billboard = item.billboard;\n if (!defined(billboard._clampedPosition)) {\n return BoundingSphereState.PENDING;\n }\n result.center = Cartesian3.clone(billboard._clampedPosition, result.center);\n }\n\n result.radius = 0;\n return BoundingSphereState.DONE;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nPointVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nPointVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n PointVisualizer.prototype._onCollectionChanged,\n this\n );\n const entities = this._entityCollection.values;\n for (let i = 0; i < entities.length; i++) {\n this._cluster.removePoint(entities[i]);\n }\n return destroyObject(this);\n};\n\nPointVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed,\n changed\n) {\n let i;\n let entity;\n const items = this._items;\n const cluster = this._cluster;\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n if (defined(entity._point) && defined(entity._position)) {\n items.set(entity.id, new EntityData(entity));\n }\n }\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n if (defined(entity._point) && defined(entity._position)) {\n if (!items.contains(entity.id)) {\n items.set(entity.id, new EntityData(entity));\n }\n } else {\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n returnPrimitive(items.get(entity.id), entity, cluster);\n items.remove(entity.id);\n }\n};\n\nfunction returnPrimitive(item, entity, cluster) {\n if (defined(item)) {\n const pointPrimitive = item.pointPrimitive;\n if (defined(pointPrimitive)) {\n item.pointPrimitive = undefined;\n cluster.removePoint(entity);\n return;\n }\n const billboard = item.billboard;\n if (defined(billboard)) {\n item.billboard = undefined;\n cluster.removeBillboard(entity);\n }\n }\n}\nexport default PointVisualizer;\n", "import ArcType from \"./ArcType.js\";\nimport arrayRemoveDuplicates from \"./arrayRemoveDuplicates.js\";\nimport BoundingSphere from \"./BoundingSphere.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Color from \"./Color.js\";\nimport ComponentDatatype from \"./ComponentDatatype.js\";\nimport defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Ellipsoid from \"./Ellipsoid.js\";\nimport Geometry from \"./Geometry.js\";\nimport GeometryAttribute from \"./GeometryAttribute.js\";\nimport GeometryAttributes from \"./GeometryAttributes.js\";\nimport GeometryType from \"./GeometryType.js\";\nimport IndexDatatype from \"./IndexDatatype.js\";\nimport CesiumMath from \"./Math.js\";\nimport PolylinePipeline from \"./PolylinePipeline.js\";\nimport PrimitiveType from \"./PrimitiveType.js\";\nimport VertexFormat from \"./VertexFormat.js\";\n\nconst scratchInterpolateColorsArray = [];\n\nfunction interpolateColors(p0, p1, color0, color1, numPoints) {\n const colors = scratchInterpolateColorsArray;\n colors.length = numPoints;\n let i;\n\n const r0 = color0.red;\n const g0 = color0.green;\n const b0 = color0.blue;\n const a0 = color0.alpha;\n\n const r1 = color1.red;\n const g1 = color1.green;\n const b1 = color1.blue;\n const a1 = color1.alpha;\n\n if (Color.equals(color0, color1)) {\n for (i = 0; i < numPoints; i++) {\n colors[i] = Color.clone(color0);\n }\n return colors;\n }\n\n const redPerVertex = (r1 - r0) / numPoints;\n const greenPerVertex = (g1 - g0) / numPoints;\n const bluePerVertex = (b1 - b0) / numPoints;\n const alphaPerVertex = (a1 - a0) / numPoints;\n\n for (i = 0; i < numPoints; i++) {\n colors[i] = new Color(\n r0 + i * redPerVertex,\n g0 + i * greenPerVertex,\n b0 + i * bluePerVertex,\n a0 + i * alphaPerVertex\n );\n }\n\n return colors;\n}\n\n/**\n * A description of a polyline modeled as a line strip; the first two positions define a line segment,\n * and each additional position defines a line segment from the previous position. The polyline is capable of\n * displaying with a material.\n *\n * @alias PolylineGeometry\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Cartesian3[]} options.positions An array of {@link Cartesian3} defining the positions in the polyline as a line strip.\n * @param {number} [options.width=1.0] The width in pixels.\n * @param {Color[]} [options.colors] An Array of {@link Color} defining the per vertex or per segment colors.\n * @param {boolean} [options.colorsPerVertex=false] A boolean that determines whether the colors will be flat across each segment of the line or interpolated across the vertices.\n * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polyline segments must follow.\n * @param {number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude if options.arcType is not ArcType.NONE. Determines the number of positions in the buffer.\n * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.\n *\n * @exception {DeveloperError} At least two positions are required.\n * @exception {DeveloperError} width must be greater than or equal to one.\n * @exception {DeveloperError} colors has an invalid length.\n *\n * @see PolylineGeometry#createGeometry\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}\n *\n * @example\n * // A polyline with two connected line segments\n * const polyline = new Cesium.PolylineGeometry({\n * positions : Cesium.Cartesian3.fromDegreesArray([\n * 0.0, 0.0,\n * 5.0, 0.0,\n * 5.0, 5.0\n * ]),\n * width : 10.0\n * });\n * const geometry = Cesium.PolylineGeometry.createGeometry(polyline);\n */\nfunction PolylineGeometry(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const positions = options.positions;\n const colors = options.colors;\n const width = defaultValue(options.width, 1.0);\n const colorsPerVertex = defaultValue(options.colorsPerVertex, false);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(positions) || positions.length < 2) {\n throw new DeveloperError(\"At least two positions are required.\");\n }\n if (typeof width !== \"number\") {\n throw new DeveloperError(\"width must be a number\");\n }\n if (\n defined(colors) &&\n ((colorsPerVertex && colors.length < positions.length) ||\n (!colorsPerVertex && colors.length < positions.length - 1))\n ) {\n throw new DeveloperError(\"colors has an invalid length.\");\n }\n //>>includeEnd('debug');\n\n this._positions = positions;\n this._colors = colors;\n this._width = width;\n this._colorsPerVertex = colorsPerVertex;\n this._vertexFormat = VertexFormat.clone(\n defaultValue(options.vertexFormat, VertexFormat.DEFAULT)\n );\n\n this._arcType = defaultValue(options.arcType, ArcType.GEODESIC);\n this._granularity = defaultValue(\n options.granularity,\n CesiumMath.RADIANS_PER_DEGREE\n );\n this._ellipsoid = Ellipsoid.clone(\n defaultValue(options.ellipsoid, Ellipsoid.WGS84)\n );\n this._workerName = \"createPolylineGeometry\";\n\n let numComponents = 1 + positions.length * Cartesian3.packedLength;\n numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1;\n\n /**\n * The number of elements used to pack the object into an array.\n * @type {number}\n */\n this.packedLength =\n numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4;\n}\n\n/**\n * Stores the provided instance into the provided array.\n *\n * @param {PolylineGeometry} value The value to pack.\n * @param {number[]} array The array to pack into.\n * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.\n *\n * @returns {number[]} The array that was packed into\n */\nPolylineGeometry.pack = function (value, array, startingIndex) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value is required\");\n }\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n const positions = value._positions;\n let length = positions.length;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n Cartesian3.pack(positions[i], array, startingIndex);\n }\n\n const colors = value._colors;\n length = defined(colors) ? colors.length : 0.0;\n array[startingIndex++] = length;\n\n for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {\n Color.pack(colors[i], array, startingIndex);\n }\n\n Ellipsoid.pack(value._ellipsoid, array, startingIndex);\n startingIndex += Ellipsoid.packedLength;\n\n VertexFormat.pack(value._vertexFormat, array, startingIndex);\n startingIndex += VertexFormat.packedLength;\n\n array[startingIndex++] = value._width;\n array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;\n array[startingIndex++] = value._arcType;\n array[startingIndex] = value._granularity;\n\n return array;\n};\n\nconst scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);\nconst scratchVertexFormat = new VertexFormat();\nconst scratchOptions = {\n positions: undefined,\n colors: undefined,\n ellipsoid: scratchEllipsoid,\n vertexFormat: scratchVertexFormat,\n width: undefined,\n colorsPerVertex: undefined,\n arcType: undefined,\n granularity: undefined,\n};\n\n/**\n * Retrieves an instance from a packed array.\n *\n * @param {number[]} array The packed array.\n * @param {number} [startingIndex=0] The starting index of the element to be unpacked.\n * @param {PolylineGeometry} [result] The object into which to store the result.\n * @returns {PolylineGeometry} The modified result parameter or a new PolylineGeometry instance if one was not provided.\n */\nPolylineGeometry.unpack = function (array, startingIndex, result) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(array)) {\n throw new DeveloperError(\"array is required\");\n }\n //>>includeEnd('debug');\n\n startingIndex = defaultValue(startingIndex, 0);\n\n let i;\n\n let length = array[startingIndex++];\n const positions = new Array(length);\n\n for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {\n positions[i] = Cartesian3.unpack(array, startingIndex);\n }\n\n length = array[startingIndex++];\n const colors = length > 0 ? new Array(length) : undefined;\n\n for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {\n colors[i] = Color.unpack(array, startingIndex);\n }\n\n const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);\n startingIndex += Ellipsoid.packedLength;\n\n const vertexFormat = VertexFormat.unpack(\n array,\n startingIndex,\n scratchVertexFormat\n );\n startingIndex += VertexFormat.packedLength;\n\n const width = array[startingIndex++];\n const colorsPerVertex = array[startingIndex++] === 1.0;\n const arcType = array[startingIndex++];\n const granularity = array[startingIndex];\n\n if (!defined(result)) {\n scratchOptions.positions = positions;\n scratchOptions.colors = colors;\n scratchOptions.width = width;\n scratchOptions.colorsPerVertex = colorsPerVertex;\n scratchOptions.arcType = arcType;\n scratchOptions.granularity = granularity;\n return new PolylineGeometry(scratchOptions);\n }\n\n result._positions = positions;\n result._colors = colors;\n result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);\n result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);\n result._width = width;\n result._colorsPerVertex = colorsPerVertex;\n result._arcType = arcType;\n result._granularity = granularity;\n\n return result;\n};\n\nconst scratchCartesian3 = new Cartesian3();\nconst scratchPosition = new Cartesian3();\nconst scratchPrevPosition = new Cartesian3();\nconst scratchNextPosition = new Cartesian3();\n\n/**\n * Computes the geometric representation of a polyline, including its vertices, indices, and a bounding sphere.\n *\n * @param {PolylineGeometry} polylineGeometry A description of the polyline.\n * @returns {Geometry|undefined} The computed vertices and indices.\n */\nPolylineGeometry.createGeometry = function (polylineGeometry) {\n const width = polylineGeometry._width;\n const vertexFormat = polylineGeometry._vertexFormat;\n let colors = polylineGeometry._colors;\n const colorsPerVertex = polylineGeometry._colorsPerVertex;\n const arcType = polylineGeometry._arcType;\n const granularity = polylineGeometry._granularity;\n const ellipsoid = polylineGeometry._ellipsoid;\n\n let i;\n let j;\n let k;\n\n const removedIndices = [];\n let positions = arrayRemoveDuplicates(\n polylineGeometry._positions,\n Cartesian3.equalsEpsilon,\n false,\n removedIndices\n );\n\n if (defined(colors) && removedIndices.length > 0) {\n let removedArrayIndex = 0;\n let nextRemovedIndex = removedIndices[0];\n colors = colors.filter(function (color, index) {\n let remove = false;\n if (colorsPerVertex) {\n remove =\n index === nextRemovedIndex || (index === 0 && nextRemovedIndex === 1);\n } else {\n remove = index + 1 === nextRemovedIndex;\n }\n\n if (remove) {\n removedArrayIndex++;\n nextRemovedIndex = removedIndices[removedArrayIndex];\n return false;\n }\n return true;\n });\n }\n\n let positionsLength = positions.length;\n\n // A width of a pixel or less is not a valid geometry, but in order to support external data\n // that may have errors we treat this as an empty geometry.\n if (positionsLength < 2 || width <= 0.0) {\n return undefined;\n }\n\n if (arcType === ArcType.GEODESIC || arcType === ArcType.RHUMB) {\n let subdivisionSize;\n let numberOfPointsFunction;\n if (arcType === ArcType.GEODESIC) {\n subdivisionSize = CesiumMath.chordLength(\n granularity,\n ellipsoid.maximumRadius\n );\n numberOfPointsFunction = PolylinePipeline.numberOfPoints;\n } else {\n subdivisionSize = granularity;\n numberOfPointsFunction = PolylinePipeline.numberOfPointsRhumbLine;\n }\n\n const heights = PolylinePipeline.extractHeights(positions, ellipsoid);\n\n if (defined(colors)) {\n let colorLength = 1;\n for (i = 0; i < positionsLength - 1; ++i) {\n colorLength += numberOfPointsFunction(\n positions[i],\n positions[i + 1],\n subdivisionSize\n );\n }\n\n const newColors = new Array(colorLength);\n let newColorIndex = 0;\n\n for (i = 0; i < positionsLength - 1; ++i) {\n const p0 = positions[i];\n const p1 = positions[i + 1];\n const c0 = colors[i];\n\n const numColors = numberOfPointsFunction(p0, p1, subdivisionSize);\n if (colorsPerVertex && i < colorLength) {\n const c1 = colors[i + 1];\n const interpolatedColors = interpolateColors(\n p0,\n p1,\n c0,\n c1,\n numColors\n );\n const interpolatedColorsLength = interpolatedColors.length;\n for (j = 0; j < interpolatedColorsLength; ++j) {\n newColors[newColorIndex++] = interpolatedColors[j];\n }\n } else {\n for (j = 0; j < numColors; ++j) {\n newColors[newColorIndex++] = Color.clone(c0);\n }\n }\n }\n\n newColors[newColorIndex] = Color.clone(colors[colors.length - 1]);\n colors = newColors;\n\n scratchInterpolateColorsArray.length = 0;\n }\n\n if (arcType === ArcType.GEODESIC) {\n positions = PolylinePipeline.generateCartesianArc({\n positions: positions,\n minDistance: subdivisionSize,\n ellipsoid: ellipsoid,\n height: heights,\n });\n } else {\n positions = PolylinePipeline.generateCartesianRhumbArc({\n positions: positions,\n granularity: subdivisionSize,\n ellipsoid: ellipsoid,\n height: heights,\n });\n }\n }\n\n positionsLength = positions.length;\n const size = positionsLength * 4.0 - 4.0;\n\n const finalPositions = new Float64Array(size * 3);\n const prevPositions = new Float64Array(size * 3);\n const nextPositions = new Float64Array(size * 3);\n const expandAndWidth = new Float32Array(size * 2);\n const st = vertexFormat.st ? new Float32Array(size * 2) : undefined;\n const finalColors = defined(colors) ? new Uint8Array(size * 4) : undefined;\n\n let positionIndex = 0;\n let expandAndWidthIndex = 0;\n let stIndex = 0;\n let colorIndex = 0;\n let position;\n\n for (j = 0; j < positionsLength; ++j) {\n if (j === 0) {\n position = scratchCartesian3;\n Cartesian3.subtract(positions[0], positions[1], position);\n Cartesian3.add(positions[0], position, position);\n } else {\n position = positions[j - 1];\n }\n\n Cartesian3.clone(position, scratchPrevPosition);\n Cartesian3.clone(positions[j], scratchPosition);\n\n if (j === positionsLength - 1) {\n position = scratchCartesian3;\n Cartesian3.subtract(\n positions[positionsLength - 1],\n positions[positionsLength - 2],\n position\n );\n Cartesian3.add(positions[positionsLength - 1], position, position);\n } else {\n position = positions[j + 1];\n }\n\n Cartesian3.clone(position, scratchNextPosition);\n\n let color0, color1;\n if (defined(finalColors)) {\n if (j !== 0 && !colorsPerVertex) {\n color0 = colors[j - 1];\n } else {\n color0 = colors[j];\n }\n\n if (j !== positionsLength - 1) {\n color1 = colors[j];\n }\n }\n\n const startK = j === 0 ? 2 : 0;\n const endK = j === positionsLength - 1 ? 2 : 4;\n\n for (k = startK; k < endK; ++k) {\n Cartesian3.pack(scratchPosition, finalPositions, positionIndex);\n Cartesian3.pack(scratchPrevPosition, prevPositions, positionIndex);\n Cartesian3.pack(scratchNextPosition, nextPositions, positionIndex);\n positionIndex += 3;\n\n const direction = k - 2 < 0 ? -1.0 : 1.0;\n expandAndWidth[expandAndWidthIndex++] = 2 * (k % 2) - 1; // expand direction\n expandAndWidth[expandAndWidthIndex++] = direction * width;\n\n if (vertexFormat.st) {\n st[stIndex++] = j / (positionsLength - 1);\n st[stIndex++] = Math.max(expandAndWidth[expandAndWidthIndex - 2], 0.0);\n }\n\n if (defined(finalColors)) {\n const color = k < 2 ? color0 : color1;\n\n finalColors[colorIndex++] = Color.floatToByte(color.red);\n finalColors[colorIndex++] = Color.floatToByte(color.green);\n finalColors[colorIndex++] = Color.floatToByte(color.blue);\n finalColors[colorIndex++] = Color.floatToByte(color.alpha);\n }\n }\n }\n\n const attributes = new GeometryAttributes();\n\n attributes.position = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: finalPositions,\n });\n\n attributes.prevPosition = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: prevPositions,\n });\n\n attributes.nextPosition = new GeometryAttribute({\n componentDatatype: ComponentDatatype.DOUBLE,\n componentsPerAttribute: 3,\n values: nextPositions,\n });\n\n attributes.expandAndWidth = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: expandAndWidth,\n });\n\n if (vertexFormat.st) {\n attributes.st = new GeometryAttribute({\n componentDatatype: ComponentDatatype.FLOAT,\n componentsPerAttribute: 2,\n values: st,\n });\n }\n\n if (defined(finalColors)) {\n attributes.color = new GeometryAttribute({\n componentDatatype: ComponentDatatype.UNSIGNED_BYTE,\n componentsPerAttribute: 4,\n values: finalColors,\n normalize: true,\n });\n }\n\n const indices = IndexDatatype.createTypedArray(size, positionsLength * 6 - 6);\n let index = 0;\n let indicesIndex = 0;\n const length = positionsLength - 1.0;\n for (j = 0; j < length; ++j) {\n indices[indicesIndex++] = index;\n indices[indicesIndex++] = index + 2;\n indices[indicesIndex++] = index + 1;\n\n indices[indicesIndex++] = index + 1;\n indices[indicesIndex++] = index + 2;\n indices[indicesIndex++] = index + 3;\n\n index += 4;\n }\n\n return new Geometry({\n attributes: attributes,\n indices: indices,\n primitiveType: PrimitiveType.TRIANGLES,\n boundingSphere: BoundingSphere.fromPoints(positions),\n geometryType: GeometryType.POLYLINES,\n });\n};\nexport default PolylineGeometry;\n", "import ArcType from \"../Core/ArcType.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport Event from \"../Core/Event.js\";\nimport GeometryInstance from \"../Core/GeometryInstance.js\";\nimport GroundPolylineGeometry from \"../Core/GroundPolylineGeometry.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport PolylineGeometry from \"../Core/PolylineGeometry.js\";\nimport PolylinePipeline from \"../Core/PolylinePipeline.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport Entity from \"../DataSources/Entity.js\";\nimport ClassificationType from \"../Scene/ClassificationType.js\";\nimport GroundPolylinePrimitive from \"../Scene/GroundPolylinePrimitive.js\";\nimport PolylineCollection from \"../Scene/PolylineCollection.js\";\nimport PolylineColorAppearance from \"../Scene/PolylineColorAppearance.js\";\nimport PolylineMaterialAppearance from \"../Scene/PolylineMaterialAppearance.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst defaultZIndex = new ConstantProperty(0);\n\n//We use this object to create one polyline collection per-scene.\nconst polylineCollections = {};\n\nconst scratchColor = new Color();\nconst defaultMaterial = new ColorMaterialProperty(Color.WHITE);\nconst defaultShow = new ConstantProperty(true);\nconst defaultShadows = new ConstantProperty(ShadowMode.DISABLED);\nconst defaultDistanceDisplayCondition = new ConstantProperty(\n new DistanceDisplayCondition()\n);\nconst defaultClassificationType = new ConstantProperty(ClassificationType.BOTH);\n\nfunction GeometryOptions() {\n this.vertexFormat = undefined;\n this.positions = undefined;\n this.width = undefined;\n this.arcType = undefined;\n this.granularity = undefined;\n}\n\nfunction GroundGeometryOptions() {\n this.positions = undefined;\n this.width = undefined;\n this.arcType = undefined;\n this.granularity = undefined;\n}\n\n/**\n * A {@link GeometryUpdater} for polylines.\n * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.\n * @alias PolylineGeometryUpdater\n * @constructor\n *\n * @param {Entity} entity The entity containing the geometry to be visualized.\n * @param {Scene} scene The scene where visualization is taking place.\n */\nfunction PolylineGeometryUpdater(entity, scene) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entity)) {\n throw new DeveloperError(\"entity is required\");\n }\n if (!defined(scene)) {\n throw new DeveloperError(\"scene is required\");\n }\n //>>includeEnd('debug');\n\n this._entity = entity;\n this._scene = scene;\n this._entitySubscription = entity.definitionChanged.addEventListener(\n PolylineGeometryUpdater.prototype._onEntityPropertyChanged,\n this\n );\n this._fillEnabled = false;\n this._dynamic = false;\n this._geometryChanged = new Event();\n this._showProperty = undefined;\n this._materialProperty = undefined;\n this._shadowsProperty = undefined;\n this._distanceDisplayConditionProperty = undefined;\n this._classificationTypeProperty = undefined;\n this._depthFailMaterialProperty = undefined;\n this._geometryOptions = new GeometryOptions();\n this._groundGeometryOptions = new GroundGeometryOptions();\n this._id = `polyline-${entity.id}`;\n this._clampToGround = false;\n this._supportsPolylinesOnTerrain = Entity.supportsPolylinesOnTerrain(scene);\n\n this._zIndex = 0;\n\n this._onEntityPropertyChanged(entity, \"polyline\", entity.polyline, undefined);\n}\n\nObject.defineProperties(PolylineGeometryUpdater.prototype, {\n /**\n * Gets the unique ID associated with this updater\n * @memberof PolylineGeometryUpdater.prototype\n * @type {string}\n * @readonly\n */\n id: {\n get: function () {\n return this._id;\n },\n },\n /**\n * Gets the entity associated with this geometry.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {Entity}\n * @readonly\n */\n entity: {\n get: function () {\n return this._entity;\n },\n },\n /**\n * Gets a value indicating if the geometry has a fill component.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n fillEnabled: {\n get: function () {\n return this._fillEnabled;\n },\n },\n /**\n * Gets a value indicating if fill visibility varies with simulation time.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n hasConstantFill: {\n get: function () {\n return (\n !this._fillEnabled ||\n (!defined(this._entity.availability) &&\n Property.isConstant(this._showProperty))\n );\n },\n },\n /**\n * Gets the material property used to fill the geometry.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {MaterialProperty}\n * @readonly\n */\n fillMaterialProperty: {\n get: function () {\n return this._materialProperty;\n },\n },\n /**\n * Gets the material property used to fill the geometry when it fails the depth test.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {MaterialProperty}\n * @readonly\n */\n depthFailMaterialProperty: {\n get: function () {\n return this._depthFailMaterialProperty;\n },\n },\n /**\n * Gets a value indicating if the geometry has an outline component.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n outlineEnabled: {\n value: false,\n },\n /**\n * Gets a value indicating if outline visibility varies with simulation time.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n hasConstantOutline: {\n value: true,\n },\n /**\n * Gets the {@link Color} property for the geometry outline.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n outlineColorProperty: {\n value: undefined,\n },\n /**\n * Gets the property specifying whether the geometry\n * casts or receives shadows from light sources.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n shadowsProperty: {\n get: function () {\n return this._shadowsProperty;\n },\n },\n /**\n * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this geometry will be displayed.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n distanceDisplayConditionProperty: {\n get: function () {\n return this._distanceDisplayConditionProperty;\n },\n },\n /**\n * Gets or sets the {@link ClassificationType} Property specifying if this geometry will classify terrain, 3D Tiles, or both when on the ground.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {Property}\n * @readonly\n */\n classificationTypeProperty: {\n get: function () {\n return this._classificationTypeProperty;\n },\n },\n /**\n * Gets a value indicating if the geometry is time-varying.\n * If true, all visualization is delegated to the {@link DynamicGeometryUpdater}\n * returned by GeometryUpdater#createDynamicUpdater.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isDynamic: {\n get: function () {\n return this._dynamic;\n },\n },\n /**\n * Gets a value indicating if the geometry is closed.\n * This property is only valid for static geometry.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n isClosed: {\n value: false,\n },\n /**\n * Gets an event that is raised whenever the public properties\n * of this updater change.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n geometryChanged: {\n get: function () {\n return this._geometryChanged;\n },\n },\n\n /**\n * Gets a value indicating if the path of the line.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {ArcType}\n * @readonly\n */\n arcType: {\n get: function () {\n return this._arcType;\n },\n },\n\n /**\n * Gets a value indicating if the geometry is clamped to the ground.\n * Returns false if polylines on terrain is not supported.\n * @memberof PolylineGeometryUpdater.prototype\n *\n * @type {boolean}\n * @readonly\n */\n clampToGround: {\n get: function () {\n return this._clampToGround && this._supportsPolylinesOnTerrain;\n },\n },\n\n /**\n * Gets the zindex\n * @type {number}\n * @memberof PolylineGeometryUpdater.prototype\n * @readonly\n */\n zIndex: {\n get: function () {\n return this._zIndex;\n },\n },\n});\n\n/**\n * Checks if the geometry is outlined at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve visibility.\n * @returns {boolean} true if geometry is outlined at the provided time, false otherwise.\n */\nPolylineGeometryUpdater.prototype.isOutlineVisible = function (time) {\n return false;\n};\n\n/**\n * Checks if the geometry is filled at the provided time.\n *\n * @param {JulianDate} time The time for which to retrieve visibility.\n * @returns {boolean} true if geometry is filled at the provided time, false otherwise.\n */\nPolylineGeometryUpdater.prototype.isFilled = function (time) {\n const entity = this._entity;\n const visible =\n this._fillEnabled &&\n entity.isAvailable(time) &&\n this._showProperty.getValue(time);\n return defaultValue(visible, false);\n};\n\n/**\n * Creates the geometry instance which represents the fill of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent a filled geometry.\n */\nPolylineGeometryUpdater.prototype.createFillGeometryInstance = function (time) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(time)) {\n throw new DeveloperError(\"time is required.\");\n }\n\n if (!this._fillEnabled) {\n throw new DeveloperError(\n \"This instance does not represent a filled geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n const entity = this._entity;\n const isAvailable = entity.isAvailable(time);\n const show = new ShowGeometryInstanceAttribute(\n isAvailable && entity.isShowing && this._showProperty.getValue(time)\n );\n const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(\n time\n );\n const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(\n distanceDisplayCondition\n );\n\n const attributes = {\n show: show,\n distanceDisplayCondition: distanceDisplayConditionAttribute,\n };\n\n let currentColor;\n if (this._materialProperty instanceof ColorMaterialProperty) {\n if (\n defined(this._materialProperty.color) &&\n (this._materialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._materialProperty.color.getValue(time, scratchColor);\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);\n }\n\n if (this.clampToGround) {\n return new GeometryInstance({\n id: entity,\n geometry: new GroundPolylineGeometry(this._groundGeometryOptions),\n attributes: attributes,\n });\n }\n\n if (\n defined(this._depthFailMaterialProperty) &&\n this._depthFailMaterialProperty instanceof ColorMaterialProperty\n ) {\n if (\n defined(this._depthFailMaterialProperty.color) &&\n (this._depthFailMaterialProperty.color.isConstant || isAvailable)\n ) {\n currentColor = this._depthFailMaterialProperty.color.getValue(\n time,\n scratchColor\n );\n }\n if (!defined(currentColor)) {\n currentColor = Color.WHITE;\n }\n attributes.depthFailColor = ColorGeometryInstanceAttribute.fromColor(\n currentColor\n );\n }\n\n return new GeometryInstance({\n id: entity,\n geometry: new PolylineGeometry(this._geometryOptions),\n attributes: attributes,\n });\n};\n\n/**\n * Creates the geometry instance which represents the outline of the geometry.\n *\n * @param {JulianDate} time The time to use when retrieving initial attribute values.\n * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.\n *\n * @exception {DeveloperError} This instance does not represent an outlined geometry.\n */\nPolylineGeometryUpdater.prototype.createOutlineGeometryInstance = function (\n time\n) {\n //>>includeStart('debug', pragmas.debug);\n throw new DeveloperError(\n \"This instance does not represent an outlined geometry.\"\n );\n //>>includeEnd('debug');\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nPolylineGeometryUpdater.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys and resources used by the object. Once an object is destroyed, it should not be used.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n */\nPolylineGeometryUpdater.prototype.destroy = function () {\n this._entitySubscription();\n destroyObject(this);\n};\n\nPolylineGeometryUpdater.prototype._onEntityPropertyChanged = function (\n entity,\n propertyName,\n newValue,\n oldValue\n) {\n if (!(propertyName === \"availability\" || propertyName === \"polyline\")) {\n return;\n }\n\n const polyline = this._entity.polyline;\n\n if (!defined(polyline)) {\n if (this._fillEnabled) {\n this._fillEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n const positionsProperty = polyline.positions;\n\n const show = polyline.show;\n if (\n (defined(show) &&\n show.isConstant &&\n !show.getValue(Iso8601.MINIMUM_VALUE)) || //\n !defined(positionsProperty)\n ) {\n if (this._fillEnabled) {\n this._fillEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n const zIndex = polyline.zIndex;\n const material = defaultValue(polyline.material, defaultMaterial);\n const isColorMaterial = material instanceof ColorMaterialProperty;\n this._materialProperty = material;\n this._depthFailMaterialProperty = polyline.depthFailMaterial;\n this._showProperty = defaultValue(show, defaultShow);\n this._shadowsProperty = defaultValue(polyline.shadows, defaultShadows);\n this._distanceDisplayConditionProperty = defaultValue(\n polyline.distanceDisplayCondition,\n defaultDistanceDisplayCondition\n );\n this._classificationTypeProperty = defaultValue(\n polyline.classificationType,\n defaultClassificationType\n );\n this._fillEnabled = true;\n this._zIndex = defaultValue(zIndex, defaultZIndex);\n\n const width = polyline.width;\n const arcType = polyline.arcType;\n const clampToGround = polyline.clampToGround;\n const granularity = polyline.granularity;\n\n if (\n !positionsProperty.isConstant ||\n !Property.isConstant(width) ||\n !Property.isConstant(arcType) ||\n !Property.isConstant(granularity) ||\n !Property.isConstant(clampToGround) ||\n !Property.isConstant(zIndex)\n ) {\n if (!this._dynamic) {\n this._dynamic = true;\n this._geometryChanged.raiseEvent(this);\n }\n } else {\n const geometryOptions = this._geometryOptions;\n const positions = positionsProperty.getValue(\n Iso8601.MINIMUM_VALUE,\n geometryOptions.positions\n );\n\n //Because of the way we currently handle reference properties,\n //we can't automatically assume the positions are always valid.\n if (!defined(positions) || positions.length < 2) {\n if (this._fillEnabled) {\n this._fillEnabled = false;\n this._geometryChanged.raiseEvent(this);\n }\n return;\n }\n\n let vertexFormat;\n if (\n isColorMaterial &&\n (!defined(this._depthFailMaterialProperty) ||\n this._depthFailMaterialProperty instanceof ColorMaterialProperty)\n ) {\n vertexFormat = PolylineColorAppearance.VERTEX_FORMAT;\n } else {\n vertexFormat = PolylineMaterialAppearance.VERTEX_FORMAT;\n }\n\n geometryOptions.vertexFormat = vertexFormat;\n geometryOptions.positions = positions;\n geometryOptions.width = defined(width)\n ? width.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n geometryOptions.arcType = defined(arcType)\n ? arcType.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n geometryOptions.granularity = defined(granularity)\n ? granularity.getValue(Iso8601.MINIMUM_VALUE)\n : undefined;\n\n const groundGeometryOptions = this._groundGeometryOptions;\n groundGeometryOptions.positions = positions;\n groundGeometryOptions.width = geometryOptions.width;\n groundGeometryOptions.arcType = geometryOptions.arcType;\n groundGeometryOptions.granularity = geometryOptions.granularity;\n\n this._clampToGround = defined(clampToGround)\n ? clampToGround.getValue(Iso8601.MINIMUM_VALUE)\n : false;\n\n if (!this._clampToGround && defined(zIndex)) {\n oneTimeWarning(\n \"Entity polylines must have clampToGround: true when using zIndex. zIndex will be ignored.\"\n );\n }\n\n this._dynamic = false;\n this._geometryChanged.raiseEvent(this);\n }\n};\n\n/**\n * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true.\n *\n * @param {PrimitiveCollection} primitives The primitive collection to use.\n * @param {PrimitiveCollection|OrderedGroundPrimitiveCollection} groundPrimitives The primitive collection to use for ordered ground primitives.\n * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame.\n *\n * @exception {DeveloperError} This instance does not represent dynamic geometry.\n * @private\n */\nPolylineGeometryUpdater.prototype.createDynamicUpdater = function (\n primitives,\n groundPrimitives\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"primitives\", primitives);\n Check.defined(\"groundPrimitives\", groundPrimitives);\n\n if (!this._dynamic) {\n throw new DeveloperError(\n \"This instance does not represent dynamic geometry.\"\n );\n }\n //>>includeEnd('debug');\n\n return new DynamicGeometryUpdater(primitives, groundPrimitives, this);\n};\n\n/**\n * @private\n */\nconst generateCartesianArcOptions = {\n positions: undefined,\n granularity: undefined,\n height: undefined,\n ellipsoid: undefined,\n};\n\nfunction DynamicGeometryUpdater(primitives, groundPrimitives, geometryUpdater) {\n this._line = undefined;\n this._primitives = primitives;\n this._groundPrimitives = groundPrimitives;\n this._groundPolylinePrimitive = undefined;\n this._material = undefined;\n this._geometryUpdater = geometryUpdater;\n this._positions = [];\n}\n\nfunction getLine(dynamicGeometryUpdater) {\n if (defined(dynamicGeometryUpdater._line)) {\n return dynamicGeometryUpdater._line;\n }\n\n const sceneId = dynamicGeometryUpdater._geometryUpdater._scene.id;\n let polylineCollection = polylineCollections[sceneId];\n const primitives = dynamicGeometryUpdater._primitives;\n if (!defined(polylineCollection) || polylineCollection.isDestroyed()) {\n polylineCollection = new PolylineCollection();\n polylineCollections[sceneId] = polylineCollection;\n primitives.add(polylineCollection);\n } else if (!primitives.contains(polylineCollection)) {\n primitives.add(polylineCollection);\n }\n\n const line = polylineCollection.add();\n line.id = dynamicGeometryUpdater._geometryUpdater._entity;\n dynamicGeometryUpdater._line = line;\n return line;\n}\n\nDynamicGeometryUpdater.prototype.update = function (time) {\n const geometryUpdater = this._geometryUpdater;\n const entity = geometryUpdater._entity;\n const polyline = entity.polyline;\n\n const positionsProperty = polyline.positions;\n let positions = Property.getValueOrUndefined(\n positionsProperty,\n time,\n this._positions\n );\n\n // Synchronize with geometryUpdater for GroundPolylinePrimitive\n geometryUpdater._clampToGround = Property.getValueOrDefault(\n polyline._clampToGround,\n time,\n false\n );\n geometryUpdater._groundGeometryOptions.positions = positions;\n geometryUpdater._groundGeometryOptions.width = Property.getValueOrDefault(\n polyline._width,\n time,\n 1\n );\n geometryUpdater._groundGeometryOptions.arcType = Property.getValueOrDefault(\n polyline._arcType,\n time,\n ArcType.GEODESIC\n );\n geometryUpdater._groundGeometryOptions.granularity = Property.getValueOrDefault(\n polyline._granularity,\n time,\n 9999\n );\n\n const groundPrimitives = this._groundPrimitives;\n\n if (defined(this._groundPolylinePrimitive)) {\n groundPrimitives.remove(this._groundPolylinePrimitive); // destroys by default\n this._groundPolylinePrimitive = undefined;\n }\n\n if (geometryUpdater.clampToGround) {\n if (\n !entity.isShowing ||\n !entity.isAvailable(time) ||\n !Property.getValueOrDefault(polyline._show, time, true)\n ) {\n return;\n }\n\n if (!defined(positions) || positions.length < 2) {\n return;\n }\n\n const fillMaterialProperty = geometryUpdater.fillMaterialProperty;\n let appearance;\n if (fillMaterialProperty instanceof ColorMaterialProperty) {\n appearance = new PolylineColorAppearance();\n } else {\n const material = MaterialProperty.getValue(\n time,\n fillMaterialProperty,\n this._material\n );\n appearance = new PolylineMaterialAppearance({\n material: material,\n translucent: material.isTranslucent(),\n });\n this._material = material;\n }\n\n this._groundPolylinePrimitive = groundPrimitives.add(\n new GroundPolylinePrimitive({\n geometryInstances: geometryUpdater.createFillGeometryInstance(time),\n appearance: appearance,\n classificationType: geometryUpdater.classificationTypeProperty.getValue(\n time\n ),\n asynchronous: false,\n }),\n Property.getValueOrUndefined(geometryUpdater.zIndex, time)\n );\n\n // Hide the polyline in the collection, if any\n if (defined(this._line)) {\n this._line.show = false;\n }\n return;\n }\n\n const line = getLine(this);\n\n if (\n !entity.isShowing ||\n !entity.isAvailable(time) ||\n !Property.getValueOrDefault(polyline._show, time, true)\n ) {\n line.show = false;\n return;\n }\n\n if (!defined(positions) || positions.length < 2) {\n line.show = false;\n return;\n }\n\n let arcType = ArcType.GEODESIC;\n arcType = Property.getValueOrDefault(polyline._arcType, time, arcType);\n\n const globe = geometryUpdater._scene.globe;\n if (arcType !== ArcType.NONE && defined(globe)) {\n generateCartesianArcOptions.ellipsoid = globe.ellipsoid;\n generateCartesianArcOptions.positions = positions;\n generateCartesianArcOptions.granularity = Property.getValueOrUndefined(\n polyline._granularity,\n time\n );\n generateCartesianArcOptions.height = PolylinePipeline.extractHeights(\n positions,\n globe.ellipsoid\n );\n if (arcType === ArcType.GEODESIC) {\n positions = PolylinePipeline.generateCartesianArc(\n generateCartesianArcOptions\n );\n } else {\n positions = PolylinePipeline.generateCartesianRhumbArc(\n generateCartesianArcOptions\n );\n }\n }\n\n line.show = true;\n line.positions = positions.slice();\n line.material = MaterialProperty.getValue(\n time,\n geometryUpdater.fillMaterialProperty,\n line.material\n );\n line.width = Property.getValueOrDefault(polyline._width, time, 1);\n line.distanceDisplayCondition = Property.getValueOrUndefined(\n polyline._distanceDisplayCondition,\n time,\n line.distanceDisplayCondition\n );\n};\n\nDynamicGeometryUpdater.prototype.getBoundingSphere = function (result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n if (!this._geometryUpdater.clampToGround) {\n const line = getLine(this);\n if (line.show && line.positions.length > 0) {\n BoundingSphere.fromPoints(line.positions, result);\n return BoundingSphereState.DONE;\n }\n } else {\n const groundPolylinePrimitive = this._groundPolylinePrimitive;\n if (\n defined(groundPolylinePrimitive) &&\n groundPolylinePrimitive.show &&\n groundPolylinePrimitive.ready\n ) {\n const attributes = groundPolylinePrimitive.getGeometryInstanceAttributes(\n this._geometryUpdater._entity\n );\n if (defined(attributes) && defined(attributes.boundingSphere)) {\n BoundingSphere.clone(attributes.boundingSphere, result);\n return BoundingSphereState.DONE;\n }\n }\n\n if (defined(groundPolylinePrimitive) && !groundPolylinePrimitive.ready) {\n return BoundingSphereState.PENDING;\n }\n\n return BoundingSphereState.DONE;\n }\n\n return BoundingSphereState.FAILED;\n};\n\nDynamicGeometryUpdater.prototype.isDestroyed = function () {\n return false;\n};\n\nDynamicGeometryUpdater.prototype.destroy = function () {\n const geometryUpdater = this._geometryUpdater;\n const sceneId = geometryUpdater._scene.id;\n const polylineCollection = polylineCollections[sceneId];\n if (defined(polylineCollection)) {\n polylineCollection.remove(this._line);\n if (polylineCollection.length === 0) {\n this._primitives.removeAndDestroy(polylineCollection);\n delete polylineCollections[sceneId];\n }\n }\n if (defined(this._groundPolylinePrimitive)) {\n this._groundPrimitives.remove(this._groundPolylinePrimitive);\n }\n destroyObject(this);\n};\nexport default PolylineGeometryUpdater;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport Color from \"../Core/Color.js\";\nimport ColorGeometryInstanceAttribute from \"../Core/ColorGeometryInstanceAttribute.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DistanceDisplayCondition from \"../Core/DistanceDisplayCondition.js\";\nimport DistanceDisplayConditionGeometryInstanceAttribute from \"../Core/DistanceDisplayConditionGeometryInstanceAttribute.js\";\nimport ShowGeometryInstanceAttribute from \"../Core/ShowGeometryInstanceAttribute.js\";\nimport GroundPolylinePrimitive from \"../Scene/GroundPolylinePrimitive.js\";\nimport PolylineColorAppearance from \"../Scene/PolylineColorAppearance.js\";\nimport PolylineMaterialAppearance from \"../Scene/PolylineMaterialAppearance.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport MaterialProperty from \"./MaterialProperty.js\";\nimport Property from \"./Property.js\";\n\nconst scratchColor = new Color();\nconst distanceDisplayConditionScratch = new DistanceDisplayCondition();\nconst defaultDistanceDisplayCondition = new DistanceDisplayCondition();\n\n// Encapsulates a Primitive and all the entities that it represents.\nfunction Batch(\n orderedGroundPrimitives,\n classificationType,\n materialProperty,\n zIndex,\n asynchronous\n) {\n let appearanceType;\n if (materialProperty instanceof ColorMaterialProperty) {\n appearanceType = PolylineColorAppearance;\n } else {\n appearanceType = PolylineMaterialAppearance;\n }\n\n this.orderedGroundPrimitives = orderedGroundPrimitives; // scene level primitive collection\n this.classificationType = classificationType;\n this.appearanceType = appearanceType;\n this.materialProperty = materialProperty;\n this.updaters = new AssociativeArray();\n this.createPrimitive = true;\n this.primitive = undefined; // a GroundPolylinePrimitive encapsulating all the entities\n this.oldPrimitive = undefined;\n this.geometry = new AssociativeArray();\n this.material = undefined;\n this.updatersWithAttributes = new AssociativeArray();\n this.attributes = new AssociativeArray();\n this.invalidated = false;\n this.removeMaterialSubscription = materialProperty.definitionChanged.addEventListener(\n Batch.prototype.onMaterialChanged,\n this\n );\n this.subscriptions = new AssociativeArray();\n this.showsUpdated = new AssociativeArray();\n this.zIndex = zIndex;\n\n this._asynchronous = asynchronous;\n}\n\nBatch.prototype.onMaterialChanged = function () {\n this.invalidated = true;\n};\n\n// Check if the given updater's material is compatible with this batch\nBatch.prototype.isMaterial = function (updater) {\n const material = this.materialProperty;\n const updaterMaterial = updater.fillMaterialProperty;\n\n if (\n updaterMaterial === material ||\n (updaterMaterial instanceof ColorMaterialProperty &&\n material instanceof ColorMaterialProperty)\n ) {\n return true;\n }\n return defined(material) && material.equals(updaterMaterial);\n};\n\nBatch.prototype.add = function (time, updater, geometryInstance) {\n const id = updater.id;\n this.updaters.set(id, updater);\n this.geometry.set(id, geometryInstance);\n // Updaters with dynamic attributes must be tracked separately, may exit the batch\n if (\n !updater.hasConstantFill ||\n !updater.fillMaterialProperty.isConstant ||\n !Property.isConstant(updater.distanceDisplayConditionProperty)\n ) {\n this.updatersWithAttributes.set(id, updater);\n } else {\n const that = this;\n // Listen for show changes. These will be synchronized in updateShows.\n this.subscriptions.set(\n id,\n updater.entity.definitionChanged.addEventListener(function (\n entity,\n propertyName,\n newValue,\n oldValue\n ) {\n if (propertyName === \"isShowing\") {\n that.showsUpdated.set(updater.id, updater);\n }\n })\n );\n }\n this.createPrimitive = true;\n};\n\nBatch.prototype.remove = function (updater) {\n const id = updater.id;\n this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;\n if (this.updaters.remove(id)) {\n this.updatersWithAttributes.remove(id);\n const unsubscribe = this.subscriptions.get(id);\n if (defined(unsubscribe)) {\n unsubscribe();\n this.subscriptions.remove(id);\n }\n return true;\n }\n return false;\n};\n\nBatch.prototype.update = function (time) {\n let isUpdated = true;\n let primitive = this.primitive;\n const orderedGroundPrimitives = this.orderedGroundPrimitives;\n const geometries = this.geometry.values;\n let i;\n\n if (this.createPrimitive) {\n const geometriesLength = geometries.length;\n if (geometriesLength > 0) {\n if (defined(primitive)) {\n // Keep a handle to the old primitive so it can be removed when the updated version is ready.\n if (!defined(this.oldPrimitive)) {\n this.oldPrimitive = primitive;\n } else {\n // For if the new primitive changes again before it is ready.\n orderedGroundPrimitives.remove(primitive);\n }\n }\n\n primitive = new GroundPolylinePrimitive({\n show: false,\n asynchronous: this._asynchronous,\n geometryInstances: geometries.slice(),\n appearance: new this.appearanceType(),\n classificationType: this.classificationType,\n });\n\n if (this.appearanceType === PolylineMaterialAppearance) {\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n primitive.appearance.material = this.material;\n }\n\n orderedGroundPrimitives.add(primitive, this.zIndex);\n isUpdated = false;\n } else {\n if (defined(primitive)) {\n orderedGroundPrimitives.remove(primitive);\n primitive = undefined;\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n orderedGroundPrimitives.remove(oldPrimitive);\n this.oldPrimitive = undefined;\n }\n }\n\n this.attributes.removeAll();\n this.primitive = primitive;\n this.createPrimitive = false;\n } else if (defined(primitive) && primitive.ready) {\n primitive.show = true;\n if (defined(this.oldPrimitive)) {\n orderedGroundPrimitives.remove(this.oldPrimitive);\n this.oldPrimitive = undefined;\n }\n\n if (this.appearanceType === PolylineMaterialAppearance) {\n this.material = MaterialProperty.getValue(\n time,\n this.materialProperty,\n this.material\n );\n this.primitive.appearance.material = this.material;\n }\n const updatersWithAttributes = this.updatersWithAttributes.values;\n const length = updatersWithAttributes.length;\n for (i = 0; i < length; i++) {\n const updater = updatersWithAttributes[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n if (!updater.fillMaterialProperty.isConstant) {\n const colorProperty = updater.fillMaterialProperty.color;\n const resultColor = Property.getValueOrDefault(\n colorProperty,\n time,\n Color.WHITE,\n scratchColor\n );\n if (!Color.equals(attributes._lastColor, resultColor)) {\n attributes._lastColor = Color.clone(\n resultColor,\n attributes._lastColor\n );\n attributes.color = ColorGeometryInstanceAttribute.toValue(\n resultColor,\n attributes.color\n );\n }\n }\n\n const show =\n entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n }\n\n const distanceDisplayConditionProperty =\n updater.distanceDisplayConditionProperty;\n if (!Property.isConstant(distanceDisplayConditionProperty)) {\n const distanceDisplayCondition = Property.getValueOrDefault(\n distanceDisplayConditionProperty,\n time,\n defaultDistanceDisplayCondition,\n distanceDisplayConditionScratch\n );\n if (\n !DistanceDisplayCondition.equals(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n )\n ) {\n attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(\n distanceDisplayCondition,\n attributes._lastDistanceDisplayCondition\n );\n attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(\n distanceDisplayCondition,\n attributes.distanceDisplayCondition\n );\n }\n }\n }\n\n this.updateShows(primitive);\n } else if (defined(primitive) && !primitive.ready) {\n isUpdated = false;\n }\n return isUpdated;\n};\n\nBatch.prototype.updateShows = function (primitive) {\n const showsUpdated = this.showsUpdated.values;\n const length = showsUpdated.length;\n for (let i = 0; i < length; i++) {\n const updater = showsUpdated[i];\n const entity = updater.entity;\n const instance = this.geometry.get(updater.id);\n\n let attributes = this.attributes.get(instance.id.id);\n if (!defined(attributes)) {\n attributes = primitive.getGeometryInstanceAttributes(instance.id);\n this.attributes.set(instance.id.id, attributes);\n }\n\n const show = entity.isShowing;\n const currentShow = attributes.show[0] === 1;\n if (show !== currentShow) {\n attributes.show = ShowGeometryInstanceAttribute.toValue(\n show,\n attributes.show\n );\n instance.attributes.show.value[0] = attributes.show[0];\n }\n }\n this.showsUpdated.removeAll();\n};\n\nBatch.prototype.contains = function (updater) {\n return this.updaters.contains(updater.id);\n};\n\nBatch.prototype.getBoundingSphere = function (updater, result) {\n const primitive = this.primitive;\n if (!primitive.ready) {\n return BoundingSphereState.PENDING;\n }\n const attributes = primitive.getGeometryInstanceAttributes(updater.entity);\n if (\n !defined(attributes) ||\n !defined(attributes.boundingSphere) ||\n (defined(attributes.show) && attributes.show[0] === 0)\n ) {\n return BoundingSphereState.FAILED;\n }\n attributes.boundingSphere.clone(result);\n return BoundingSphereState.DONE;\n};\n\nBatch.prototype.destroy = function () {\n const primitive = this.primitive;\n const orderedGroundPrimitives = this.orderedGroundPrimitives;\n if (defined(primitive)) {\n orderedGroundPrimitives.remove(primitive);\n }\n const oldPrimitive = this.oldPrimitive;\n if (defined(oldPrimitive)) {\n orderedGroundPrimitives.remove(oldPrimitive);\n }\n this.removeMaterialSubscription();\n};\n\n/**\n * @private\n */\nfunction StaticGroundPolylinePerMaterialBatch(\n orderedGroundPrimitives,\n classificationType,\n asynchronous\n) {\n this._items = [];\n this._orderedGroundPrimitives = orderedGroundPrimitives;\n this._classificationType = classificationType;\n this._asynchronous = defaultValue(asynchronous, true);\n}\n\nStaticGroundPolylinePerMaterialBatch.prototype.add = function (time, updater) {\n const items = this._items;\n const length = items.length;\n const geometryInstance = updater.createFillGeometryInstance(time);\n const zIndex = Property.getValueOrDefault(updater.zIndex, 0);\n // Check if the Entity represented by the updater has the same material or a material representable with per-instance color.\n for (let i = 0; i < length; ++i) {\n const item = items[i];\n if (item.isMaterial(updater) && item.zIndex === zIndex) {\n item.add(time, updater, geometryInstance);\n return;\n }\n }\n // If a compatible batch wasn't found, create a new batch.\n const batch = new Batch(\n this._orderedGroundPrimitives,\n this._classificationType,\n updater.fillMaterialProperty,\n zIndex,\n this._asynchronous\n );\n batch.add(time, updater, geometryInstance);\n items.push(batch);\n};\n\nStaticGroundPolylinePerMaterialBatch.prototype.remove = function (updater) {\n const items = this._items;\n const length = items.length;\n for (let i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.remove(updater)) {\n if (item.updaters.length === 0) {\n items.splice(i, 1);\n item.destroy();\n }\n break;\n }\n }\n};\n\nStaticGroundPolylinePerMaterialBatch.prototype.update = function (time) {\n let i;\n const items = this._items;\n const length = items.length;\n\n for (i = length - 1; i >= 0; i--) {\n const item = items[i];\n if (item.invalidated) {\n items.splice(i, 1);\n const updaters = item.updaters.values;\n const updatersLength = updaters.length;\n for (let h = 0; h < updatersLength; h++) {\n this.add(time, updaters[h]);\n }\n item.destroy();\n }\n }\n\n let isUpdated = true;\n for (i = 0; i < items.length; i++) {\n isUpdated = items[i].update(time) && isUpdated;\n }\n return isUpdated;\n};\n\nStaticGroundPolylinePerMaterialBatch.prototype.getBoundingSphere = function (\n updater,\n result\n) {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n const item = items[i];\n if (item.contains(updater)) {\n return item.getBoundingSphere(updater, result);\n }\n }\n return BoundingSphereState.FAILED;\n};\n\nStaticGroundPolylinePerMaterialBatch.prototype.removeAllPrimitives = function () {\n const items = this._items;\n const length = items.length;\n for (let i = 0; i < length; i++) {\n items[i].destroy();\n }\n this._items.length = 0;\n};\nexport default StaticGroundPolylinePerMaterialBatch;\n", "import AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport ClassificationType from \"../Scene/ClassificationType.js\";\nimport PolylineColorAppearance from \"../Scene/PolylineColorAppearance.js\";\nimport PolylineMaterialAppearance from \"../Scene/PolylineMaterialAppearance.js\";\nimport ShadowMode from \"../Scene/ShadowMode.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport DynamicGeometryBatch from \"./DynamicGeometryBatch.js\";\nimport PolylineGeometryUpdater from \"./PolylineGeometryUpdater.js\";\nimport StaticGeometryColorBatch from \"./StaticGeometryColorBatch.js\";\nimport StaticGeometryPerMaterialBatch from \"./StaticGeometryPerMaterialBatch.js\";\nimport StaticGroundPolylinePerMaterialBatch from \"./StaticGroundPolylinePerMaterialBatch.js\";\n\nconst emptyArray = [];\n\nfunction removeUpdater(that, updater) {\n //We don't keep track of which batch an updater is in, so just remove it from all of them.\n const batches = that._batches;\n const length = batches.length;\n for (let i = 0; i < length; i++) {\n batches[i].remove(updater);\n }\n}\n\nfunction insertUpdaterIntoBatch(that, time, updater) {\n if (updater.isDynamic) {\n that._dynamicBatch.add(time, updater);\n return;\n }\n\n if (updater.clampToGround && updater.fillEnabled) {\n // Also checks for support\n const classificationType = updater.classificationTypeProperty.getValue(\n time\n );\n that._groundBatches[classificationType].add(time, updater);\n return;\n }\n\n let shadows;\n if (updater.fillEnabled) {\n shadows = updater.shadowsProperty.getValue(time);\n }\n\n let multiplier = 0;\n if (defined(updater.depthFailMaterialProperty)) {\n multiplier =\n updater.depthFailMaterialProperty instanceof ColorMaterialProperty\n ? 1\n : 2;\n }\n\n let index;\n if (defined(shadows)) {\n index = shadows + multiplier * ShadowMode.NUMBER_OF_SHADOW_MODES;\n }\n\n if (updater.fillEnabled) {\n if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {\n that._colorBatches[index].add(time, updater);\n } else {\n that._materialBatches[index].add(time, updater);\n }\n }\n}\n\n/**\n * A visualizer for polylines represented by {@link Primitive} instances.\n * @alias PolylineVisualizer\n * @constructor\n *\n * @param {Scene} scene The scene the primitives will be rendered in.\n * @param {EntityCollection} entityCollection The entityCollection to visualize.\n * @param {PrimitiveCollection} [primitives=scene.primitives] A collection to add primitives related to the entities\n * @param {PrimitiveCollection} [groundPrimitives=scene.groundPrimitives] A collection to add ground primitives related to the entities\n */\nfunction PolylineVisualizer(\n scene,\n entityCollection,\n primitives,\n groundPrimitives\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"scene\", scene);\n Check.defined(\"entityCollection\", entityCollection);\n //>>includeEnd('debug');\n\n groundPrimitives = defaultValue(groundPrimitives, scene.groundPrimitives);\n primitives = defaultValue(primitives, scene.primitives);\n\n this._scene = scene;\n this._primitives = primitives;\n this._entityCollection = undefined;\n this._addedObjects = new AssociativeArray();\n this._removedObjects = new AssociativeArray();\n this._changedObjects = new AssociativeArray();\n\n let i;\n const numberOfShadowModes = ShadowMode.NUMBER_OF_SHADOW_MODES;\n this._colorBatches = new Array(numberOfShadowModes * 3);\n this._materialBatches = new Array(numberOfShadowModes * 3);\n\n for (i = 0; i < numberOfShadowModes; ++i) {\n this._colorBatches[i] = new StaticGeometryColorBatch(\n primitives,\n PolylineColorAppearance,\n undefined,\n false,\n i\n ); // no depth fail appearance\n this._materialBatches[i] = new StaticGeometryPerMaterialBatch(\n primitives,\n PolylineMaterialAppearance,\n undefined,\n false,\n i\n );\n\n this._colorBatches[i + numberOfShadowModes] = new StaticGeometryColorBatch(\n primitives,\n PolylineColorAppearance,\n PolylineColorAppearance,\n false,\n i\n ); //depth fail appearance variations\n this._materialBatches[\n i + numberOfShadowModes\n ] = new StaticGeometryPerMaterialBatch(\n primitives,\n PolylineMaterialAppearance,\n PolylineColorAppearance,\n false,\n i\n );\n\n this._colorBatches[\n i + numberOfShadowModes * 2\n ] = new StaticGeometryColorBatch(\n primitives,\n PolylineColorAppearance,\n PolylineMaterialAppearance,\n false,\n i\n );\n this._materialBatches[\n i + numberOfShadowModes * 2\n ] = new StaticGeometryPerMaterialBatch(\n primitives,\n PolylineMaterialAppearance,\n PolylineMaterialAppearance,\n false,\n i\n );\n }\n\n this._dynamicBatch = new DynamicGeometryBatch(primitives, groundPrimitives);\n\n const numberOfClassificationTypes =\n ClassificationType.NUMBER_OF_CLASSIFICATION_TYPES;\n this._groundBatches = new Array(numberOfClassificationTypes);\n\n for (i = 0; i < numberOfClassificationTypes; ++i) {\n this._groundBatches[i] = new StaticGroundPolylinePerMaterialBatch(\n groundPrimitives,\n i\n );\n }\n\n this._batches = this._colorBatches.concat(\n this._materialBatches,\n this._dynamicBatch,\n this._groundBatches\n );\n\n this._subscriptions = new AssociativeArray();\n this._updaters = new AssociativeArray();\n\n this._entityCollection = entityCollection;\n entityCollection.collectionChanged.addEventListener(\n PolylineVisualizer.prototype._onCollectionChanged,\n this\n );\n this._onCollectionChanged(\n entityCollection,\n entityCollection.values,\n emptyArray\n );\n}\n\n/**\n * Updates all of the primitives created by this visualizer to match their\n * Entity counterpart at the given time.\n *\n * @param {JulianDate} time The time to update to.\n * @returns {boolean} True if the visualizer successfully updated to the provided time,\n * false if the visualizer is waiting for asynchronous primitives to be created.\n */\nPolylineVisualizer.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const addedObjects = this._addedObjects;\n const added = addedObjects.values;\n const removedObjects = this._removedObjects;\n const removed = removedObjects.values;\n const changedObjects = this._changedObjects;\n const changed = changedObjects.values;\n\n let i;\n let entity;\n let id;\n let updater;\n\n for (i = changed.length - 1; i > -1; i--) {\n entity = changed[i];\n id = entity.id;\n updater = this._updaters.get(id);\n\n //If in a single update, an entity gets removed and a new instance\n //re-added with the same id, the updater no longer tracks the\n //correct entity, we need to both remove the old one and\n //add the new one, which is done by pushing the entity\n //onto the removed/added lists.\n if (updater.entity === entity) {\n removeUpdater(this, updater);\n insertUpdaterIntoBatch(this, time, updater);\n } else {\n removed.push(entity);\n added.push(entity);\n }\n }\n\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n id = entity.id;\n updater = this._updaters.get(id);\n removeUpdater(this, updater);\n updater.destroy();\n this._updaters.remove(id);\n this._subscriptions.get(id)();\n this._subscriptions.remove(id);\n }\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n id = entity.id;\n updater = new PolylineGeometryUpdater(entity, this._scene);\n this._updaters.set(id, updater);\n insertUpdaterIntoBatch(this, time, updater);\n this._subscriptions.set(\n id,\n updater.geometryChanged.addEventListener(\n PolylineVisualizer._onGeometryChanged,\n this\n )\n );\n }\n\n addedObjects.removeAll();\n removedObjects.removeAll();\n changedObjects.removeAll();\n\n let isUpdated = true;\n const batches = this._batches;\n const length = batches.length;\n for (i = 0; i < length; i++) {\n isUpdated = batches[i].update(time) && isUpdated;\n }\n\n return isUpdated;\n};\n\nconst getBoundingSphereArrayScratch = [];\nconst getBoundingSphereBoundingSphereScratch = new BoundingSphere();\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nPolylineVisualizer.prototype.getBoundingSphere = function (entity, result) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"entity\", entity);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n const boundingSpheres = getBoundingSphereArrayScratch;\n const tmp = getBoundingSphereBoundingSphereScratch;\n\n let count = 0;\n let state = BoundingSphereState.DONE;\n const batches = this._batches;\n const batchesLength = batches.length;\n const updater = this._updaters.get(entity.id);\n for (let i = 0; i < batchesLength; i++) {\n state = batches[i].getBoundingSphere(updater, tmp);\n if (state === BoundingSphereState.PENDING) {\n return BoundingSphereState.PENDING;\n } else if (state === BoundingSphereState.DONE) {\n boundingSpheres[count] = BoundingSphere.clone(\n tmp,\n boundingSpheres[count]\n );\n count++;\n }\n }\n\n if (count === 0) {\n return BoundingSphereState.FAILED;\n }\n\n boundingSpheres.length = count;\n BoundingSphere.fromBoundingSpheres(boundingSpheres, result);\n return BoundingSphereState.DONE;\n};\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nPolylineVisualizer.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Removes and destroys all primitives created by this instance.\n */\nPolylineVisualizer.prototype.destroy = function () {\n this._entityCollection.collectionChanged.removeEventListener(\n PolylineVisualizer.prototype._onCollectionChanged,\n this\n );\n this._addedObjects.removeAll();\n this._removedObjects.removeAll();\n\n let i;\n const batches = this._batches;\n let length = batches.length;\n for (i = 0; i < length; i++) {\n batches[i].removeAllPrimitives();\n }\n\n const subscriptions = this._subscriptions.values;\n length = subscriptions.length;\n for (i = 0; i < length; i++) {\n subscriptions[i]();\n }\n this._subscriptions.removeAll();\n return destroyObject(this);\n};\n\n/**\n * @private\n */\nPolylineVisualizer._onGeometryChanged = function (updater) {\n const removedObjects = this._removedObjects;\n const changedObjects = this._changedObjects;\n\n const entity = updater.entity;\n const id = entity.id;\n\n if (!defined(removedObjects.get(id)) && !defined(changedObjects.get(id))) {\n changedObjects.set(id, entity);\n }\n};\n\n/**\n * @private\n */\nPolylineVisualizer.prototype._onCollectionChanged = function (\n entityCollection,\n added,\n removed\n) {\n const addedObjects = this._addedObjects;\n const removedObjects = this._removedObjects;\n const changedObjects = this._changedObjects;\n\n let i;\n let id;\n let entity;\n for (i = removed.length - 1; i > -1; i--) {\n entity = removed[i];\n id = entity.id;\n if (!addedObjects.remove(id)) {\n removedObjects.set(id, entity);\n changedObjects.remove(id);\n }\n }\n\n for (i = added.length - 1; i > -1; i--) {\n entity = added[i];\n id = entity.id;\n if (removedObjects.remove(id)) {\n changedObjects.set(id, entity);\n } else {\n addedObjects.set(id, entity);\n }\n }\n};\nexport default PolylineVisualizer;\n", "import ApproximateTerrainHeights from \"../Core/ApproximateTerrainHeights.js\";\nimport BoundingSphere from \"../Core/BoundingSphere.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport destroyObject from \"../Core/destroyObject.js\";\nimport EventHelper from \"../Core/EventHelper.js\";\nimport GroundPolylinePrimitive from \"../Scene/GroundPolylinePrimitive.js\";\nimport GroundPrimitive from \"../Scene/GroundPrimitive.js\";\nimport OrderedGroundPrimitiveCollection from \"../Scene/OrderedGroundPrimitiveCollection.js\";\nimport PrimitiveCollection from \"../Scene/PrimitiveCollection.js\";\nimport BillboardVisualizer from \"./BillboardVisualizer.js\";\nimport BoundingSphereState from \"./BoundingSphereState.js\";\nimport CustomDataSource from \"./CustomDataSource.js\";\nimport GeometryVisualizer from \"./GeometryVisualizer.js\";\nimport LabelVisualizer from \"./LabelVisualizer.js\";\nimport ModelVisualizer from \"./ModelVisualizer.js\";\nimport Cesium3DTilesetVisualizer from \"./Cesium3DTilesetVisualizer.js\";\nimport PathVisualizer from \"./PathVisualizer.js\";\nimport PointVisualizer from \"./PointVisualizer.js\";\nimport PolylineVisualizer from \"./PolylineVisualizer.js\";\n\n/**\n * Visualizes a collection of {@link DataSource} instances.\n * @alias DataSourceDisplay\n * @constructor\n *\n * @param {object} options Object with the following properties:\n * @param {Scene} options.scene The scene in which to display the data.\n * @param {DataSourceCollection} options.dataSourceCollection The data sources to display.\n * @param {DataSourceDisplay.VisualizersCallback} [options.visualizersCallback=DataSourceDisplay.defaultVisualizersCallback]\n * A function which creates an array of visualizers used for visualization.\n * If undefined, all standard visualizers are used.\n */\nfunction DataSourceDisplay(options) {\n //>>includeStart('debug', pragmas.debug);\n Check.typeOf.object(\"options\", options);\n Check.typeOf.object(\"options.scene\", options.scene);\n Check.typeOf.object(\n \"options.dataSourceCollection\",\n options.dataSourceCollection\n );\n //>>includeEnd('debug');\n\n GroundPrimitive.initializeTerrainHeights();\n GroundPolylinePrimitive.initializeTerrainHeights();\n\n const scene = options.scene;\n const dataSourceCollection = options.dataSourceCollection;\n\n this._eventHelper = new EventHelper();\n this._eventHelper.add(\n dataSourceCollection.dataSourceAdded,\n this._onDataSourceAdded,\n this\n );\n this._eventHelper.add(\n dataSourceCollection.dataSourceRemoved,\n this._onDataSourceRemoved,\n this\n );\n this._eventHelper.add(\n dataSourceCollection.dataSourceMoved,\n this._onDataSourceMoved,\n this\n );\n this._eventHelper.add(scene.postRender, this._postRender, this);\n\n this._dataSourceCollection = dataSourceCollection;\n this._scene = scene;\n this._visualizersCallback = defaultValue(\n options.visualizersCallback,\n DataSourceDisplay.defaultVisualizersCallback\n );\n\n let primitivesAdded = false;\n const primitives = new PrimitiveCollection();\n const groundPrimitives = new PrimitiveCollection();\n\n if (dataSourceCollection.length > 0) {\n scene.primitives.add(primitives);\n scene.groundPrimitives.add(groundPrimitives);\n primitivesAdded = true;\n }\n\n this._primitives = primitives;\n this._groundPrimitives = groundPrimitives;\n\n for (let i = 0, len = dataSourceCollection.length; i < len; i++) {\n this._onDataSourceAdded(dataSourceCollection, dataSourceCollection.get(i));\n }\n\n const defaultDataSource = new CustomDataSource();\n this._onDataSourceAdded(undefined, defaultDataSource);\n this._defaultDataSource = defaultDataSource;\n\n let removeDefaultDataSourceListener;\n let removeDataSourceCollectionListener;\n if (!primitivesAdded) {\n const that = this;\n const addPrimitives = function () {\n scene.primitives.add(primitives);\n scene.groundPrimitives.add(groundPrimitives);\n removeDefaultDataSourceListener();\n removeDataSourceCollectionListener();\n that._removeDefaultDataSourceListener = undefined;\n that._removeDataSourceCollectionListener = undefined;\n };\n removeDefaultDataSourceListener = defaultDataSource.entities.collectionChanged.addEventListener(\n addPrimitives\n );\n removeDataSourceCollectionListener = dataSourceCollection.dataSourceAdded.addEventListener(\n addPrimitives\n );\n }\n\n this._removeDefaultDataSourceListener = removeDefaultDataSourceListener;\n this._removeDataSourceCollectionListener = removeDataSourceCollectionListener;\n\n this._ready = false;\n}\n\n/**\n * Gets or sets the default function which creates an array of visualizers used for visualization.\n * By default, this function uses all standard visualizers.\n *\n * @type {DataSourceDisplay.VisualizersCallback}\n */\nDataSourceDisplay.defaultVisualizersCallback = function (\n scene,\n entityCluster,\n dataSource\n) {\n const entities = dataSource.entities;\n return [\n new BillboardVisualizer(entityCluster, entities),\n new GeometryVisualizer(\n scene,\n entities,\n dataSource._primitives,\n dataSource._groundPrimitives\n ),\n new LabelVisualizer(entityCluster, entities),\n new ModelVisualizer(scene, entities),\n new Cesium3DTilesetVisualizer(scene, entities),\n new PointVisualizer(entityCluster, entities),\n new PathVisualizer(scene, entities),\n new PolylineVisualizer(\n scene,\n entities,\n dataSource._primitives,\n dataSource._groundPrimitives\n ),\n ];\n};\n\nObject.defineProperties(DataSourceDisplay.prototype, {\n /**\n * Gets the scene associated with this display.\n * @memberof DataSourceDisplay.prototype\n * @type {Scene}\n */\n scene: {\n get: function () {\n return this._scene;\n },\n },\n /**\n * Gets the collection of data sources to display.\n * @memberof DataSourceDisplay.prototype\n * @type {DataSourceCollection}\n */\n dataSources: {\n get: function () {\n return this._dataSourceCollection;\n },\n },\n /**\n * Gets the default data source instance which can be used to\n * manually create and visualize entities not tied to\n * a specific data source. This instance is always available\n * and does not appear in the list dataSources collection.\n * @memberof DataSourceDisplay.prototype\n * @type {CustomDataSource}\n */\n defaultDataSource: {\n get: function () {\n return this._defaultDataSource;\n },\n },\n\n /**\n * Gets a value indicating whether or not all entities in the data source are ready\n * @memberof DataSourceDisplay.prototype\n * @type {boolean}\n * @readonly\n */\n ready: {\n get: function () {\n return this._ready;\n },\n },\n});\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n *

\n * If this object was destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception.\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n *\n * @see DataSourceDisplay#destroy\n */\nDataSourceDisplay.prototype.isDestroyed = function () {\n return false;\n};\n\n/**\n * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic\n * release of WebGL resources, instead of relying on the garbage collector to destroy this object.\n *

\n * Once an object is destroyed, it should not be used; calling any function other than\n * isDestroyed will result in a {@link DeveloperError} exception. Therefore,\n * assign the return value (undefined) to the object as done in the example.\n *\n * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.\n *\n *\n * @example\n * dataSourceDisplay = dataSourceDisplay.destroy();\n *\n * @see DataSourceDisplay#isDestroyed\n */\nDataSourceDisplay.prototype.destroy = function () {\n this._eventHelper.removeAll();\n\n const dataSourceCollection = this._dataSourceCollection;\n for (let i = 0, length = dataSourceCollection.length; i < length; ++i) {\n this._onDataSourceRemoved(\n this._dataSourceCollection,\n dataSourceCollection.get(i)\n );\n }\n this._onDataSourceRemoved(undefined, this._defaultDataSource);\n\n if (defined(this._removeDefaultDataSourceListener)) {\n this._removeDefaultDataSourceListener();\n this._removeDataSourceCollectionListener();\n } else {\n this._scene.primitives.remove(this._primitives);\n this._scene.groundPrimitives.remove(this._groundPrimitives);\n }\n\n return destroyObject(this);\n};\n\n/**\n * Updates the display to the provided time.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if all data sources are ready to be displayed, false otherwise.\n */\nDataSourceDisplay.prototype.update = function (time) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n if (!ApproximateTerrainHeights.initialized) {\n this._ready = false;\n return false;\n }\n\n let result = true;\n\n let i;\n let x;\n let visualizers;\n let vLength;\n const dataSources = this._dataSourceCollection;\n const length = dataSources.length;\n for (i = 0; i < length; i++) {\n const dataSource = dataSources.get(i);\n if (defined(dataSource.update)) {\n result = dataSource.update(time) && result;\n }\n\n visualizers = dataSource._visualizers;\n vLength = visualizers.length;\n for (x = 0; x < vLength; x++) {\n result = visualizers[x].update(time) && result;\n }\n }\n\n visualizers = this._defaultDataSource._visualizers;\n vLength = visualizers.length;\n for (x = 0; x < vLength; x++) {\n result = visualizers[x].update(time) && result;\n }\n\n this._ready = result;\n\n return result;\n};\n\nDataSourceDisplay.prototype._postRender = function () {\n // Adds credits for all datasources\n const frameState = this._scene.frameState;\n const dataSources = this._dataSourceCollection;\n const length = dataSources.length;\n for (let i = 0; i < length; i++) {\n const dataSource = dataSources.get(i);\n\n const credit = dataSource.credit;\n if (defined(credit)) {\n frameState.creditDisplay.addCreditToNextFrame(credit);\n }\n\n // Credits from the resource that the user can't remove\n const credits = dataSource._resourceCredits;\n if (defined(credits)) {\n const creditCount = credits.length;\n for (let c = 0; c < creditCount; c++) {\n frameState.creditDisplay.addCreditToNextFrame(credits[c]);\n }\n }\n }\n};\n\nconst getBoundingSphereArrayScratch = [];\nconst getBoundingSphereBoundingSphereScratch = new BoundingSphere();\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {boolean} allowPartial If true, pending bounding spheres are ignored and an answer will be returned from the currently available data.\n * If false, the the function will halt and return pending if any of the bounding spheres are pending.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nDataSourceDisplay.prototype.getBoundingSphere = function (\n entity,\n allowPartial,\n result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"entity\", entity);\n Check.typeOf.bool(\"allowPartial\", allowPartial);\n Check.defined(\"result\", result);\n //>>includeEnd('debug');\n\n if (!this._ready) {\n return BoundingSphereState.PENDING;\n }\n\n let i;\n let length;\n let dataSource = this._defaultDataSource;\n if (!dataSource.entities.contains(entity)) {\n dataSource = undefined;\n\n const dataSources = this._dataSourceCollection;\n length = dataSources.length;\n for (i = 0; i < length; i++) {\n const d = dataSources.get(i);\n if (d.entities.contains(entity)) {\n dataSource = d;\n break;\n }\n }\n }\n\n if (!defined(dataSource)) {\n return BoundingSphereState.FAILED;\n }\n\n const boundingSpheres = getBoundingSphereArrayScratch;\n const tmp = getBoundingSphereBoundingSphereScratch;\n\n let count = 0;\n let state = BoundingSphereState.DONE;\n const visualizers = dataSource._visualizers;\n const visualizersLength = visualizers.length;\n\n for (i = 0; i < visualizersLength; i++) {\n const visualizer = visualizers[i];\n if (defined(visualizer.getBoundingSphere)) {\n state = visualizers[i].getBoundingSphere(entity, tmp);\n if (!allowPartial && state === BoundingSphereState.PENDING) {\n return BoundingSphereState.PENDING;\n } else if (state === BoundingSphereState.DONE) {\n boundingSpheres[count] = BoundingSphere.clone(\n tmp,\n boundingSpheres[count]\n );\n count++;\n }\n }\n }\n\n if (count === 0) {\n return BoundingSphereState.FAILED;\n }\n\n boundingSpheres.length = count;\n BoundingSphere.fromBoundingSpheres(boundingSpheres, result);\n return BoundingSphereState.DONE;\n};\n\nDataSourceDisplay.prototype._onDataSourceAdded = function (\n dataSourceCollection,\n dataSource\n) {\n const scene = this._scene;\n\n const displayPrimitives = this._primitives;\n const displayGroundPrimitives = this._groundPrimitives;\n\n const primitives = displayPrimitives.add(new PrimitiveCollection());\n const groundPrimitives = displayGroundPrimitives.add(\n new OrderedGroundPrimitiveCollection()\n );\n\n dataSource._primitives = primitives;\n dataSource._groundPrimitives = groundPrimitives;\n\n const entityCluster = dataSource.clustering;\n entityCluster._initialize(scene);\n\n primitives.add(entityCluster);\n\n dataSource._visualizers = this._visualizersCallback(\n scene,\n entityCluster,\n dataSource\n );\n};\n\nDataSourceDisplay.prototype._onDataSourceRemoved = function (\n dataSourceCollection,\n dataSource\n) {\n const displayPrimitives = this._primitives;\n const displayGroundPrimitives = this._groundPrimitives;\n\n const primitives = dataSource._primitives;\n const groundPrimitives = dataSource._groundPrimitives;\n\n const entityCluster = dataSource.clustering;\n primitives.remove(entityCluster);\n\n const visualizers = dataSource._visualizers;\n const length = visualizers.length;\n for (let i = 0; i < length; i++) {\n visualizers[i].destroy();\n }\n\n displayPrimitives.remove(primitives);\n displayGroundPrimitives.remove(groundPrimitives);\n\n dataSource._visualizers = undefined;\n};\n\nDataSourceDisplay.prototype._onDataSourceMoved = function (\n dataSource,\n newIndex,\n oldIndex\n) {\n const displayPrimitives = this._primitives;\n const displayGroundPrimitives = this._groundPrimitives;\n\n const primitives = dataSource._primitives;\n const groundPrimitives = dataSource._groundPrimitives;\n\n if (newIndex === oldIndex + 1) {\n displayPrimitives.raise(primitives);\n displayGroundPrimitives.raise(groundPrimitives);\n } else if (newIndex === oldIndex - 1) {\n displayPrimitives.lower(primitives);\n displayGroundPrimitives.lower(groundPrimitives);\n } else if (newIndex === 0) {\n displayPrimitives.lowerToBottom(primitives);\n displayGroundPrimitives.lowerToBottom(groundPrimitives);\n displayPrimitives.raise(primitives); // keep defaultDataSource primitives at index 0 since it's not in the collection\n displayGroundPrimitives.raise(groundPrimitives);\n } else {\n displayPrimitives.raiseToTop(primitives);\n displayGroundPrimitives.raiseToTop(groundPrimitives);\n }\n};\n\n/**\n * A function which creates an array of visualizers used for visualization.\n * @callback DataSourceDisplay.VisualizersCallback\n *\n * @param {Scene} scene The scene to create visualizers for.\n * @param {EntityCluster} entityCluster The entity cluster to create visualizers for.\n * @param {DataSource} dataSource The data source to create visualizers for.\n * @returns {Visualizer[]} An array of visualizers used for visualization.\n *\n * @example\n * function createVisualizers(scene, entityCluster, dataSource) {\n * return [new Cesium.BillboardVisualizer(entityCluster, dataSource.entities)];\n * }\n */\nexport default DataSourceDisplay;\n", "import defaultValue from \"./defaultValue.js\";\nimport defined from \"./defined.js\";\n\n/**\n * Defines a heading angle, pitch angle, and range in a local frame.\n * Heading is the rotation from the local north direction where a positive angle is increasing eastward.\n * Pitch is the rotation from the local xy-plane. Positive pitch angles are above the plane. Negative pitch\n * angles are below the plane. Range is the distance from the center of the frame.\n * @alias HeadingPitchRange\n * @constructor\n *\n * @param {number} [heading=0.0] The heading angle in radians.\n * @param {number} [pitch=0.0] The pitch angle in radians.\n * @param {number} [range=0.0] The distance from the center in meters.\n */\nfunction HeadingPitchRange(heading, pitch, range) {\n /**\n * Heading is the rotation from the local north direction where a positive angle is increasing eastward.\n * @type {number}\n * @default 0.0\n */\n this.heading = defaultValue(heading, 0.0);\n\n /**\n * Pitch is the rotation from the local xy-plane. Positive pitch angles\n * are above the plane. Negative pitch angles are below the plane.\n * @type {number}\n * @default 0.0\n */\n this.pitch = defaultValue(pitch, 0.0);\n\n /**\n * Range is the distance from the center of the local frame.\n * @type {number}\n * @default 0.0\n */\n this.range = defaultValue(range, 0.0);\n}\n\n/**\n * Duplicates a HeadingPitchRange instance.\n *\n * @param {HeadingPitchRange} hpr The HeadingPitchRange to duplicate.\n * @param {HeadingPitchRange} [result] The object onto which to store the result.\n * @returns {HeadingPitchRange} The modified result parameter or a new HeadingPitchRange instance if one was not provided. (Returns undefined if hpr is undefined)\n */\nHeadingPitchRange.clone = function (hpr, result) {\n if (!defined(hpr)) {\n return undefined;\n }\n if (!defined(result)) {\n result = new HeadingPitchRange();\n }\n\n result.heading = hpr.heading;\n result.pitch = hpr.pitch;\n result.range = hpr.range;\n return result;\n};\nexport default HeadingPitchRange;\n", "import Cartesian3 from \"../Core/Cartesian3.js\";\nimport Check from \"../Core/Check.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport HeadingPitchRange from \"../Core/HeadingPitchRange.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Matrix3 from \"../Core/Matrix3.js\";\nimport Matrix4 from \"../Core/Matrix4.js\";\nimport Transforms from \"../Core/Transforms.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\n\nconst updateTransformMatrix3Scratch1 = new Matrix3();\nconst updateTransformMatrix3Scratch2 = new Matrix3();\nconst updateTransformMatrix3Scratch3 = new Matrix3();\nconst updateTransformMatrix4Scratch = new Matrix4();\nconst updateTransformCartesian3Scratch1 = new Cartesian3();\nconst updateTransformCartesian3Scratch2 = new Cartesian3();\nconst updateTransformCartesian3Scratch3 = new Cartesian3();\nconst updateTransformCartesian3Scratch4 = new Cartesian3();\nconst updateTransformCartesian3Scratch5 = new Cartesian3();\nconst updateTransformCartesian3Scratch6 = new Cartesian3();\nconst deltaTime = new JulianDate();\nconst northUpAxisFactor = 1.25; // times ellipsoid's maximum radius\n\nfunction updateTransform(\n that,\n camera,\n updateLookAt,\n saveCamera,\n positionProperty,\n time,\n ellipsoid\n) {\n const mode = that.scene.mode;\n let cartesian = positionProperty.getValue(time, that._lastCartesian);\n if (defined(cartesian)) {\n let hasBasis = false;\n let invertVelocity = false;\n let xBasis;\n let yBasis;\n let zBasis;\n\n if (mode === SceneMode.SCENE3D) {\n // The time delta was determined based on how fast satellites move compared to vehicles near the surface.\n // Slower moving vehicles will most likely default to east-north-up, while faster ones will be VVLH.\n JulianDate.addSeconds(time, 0.001, deltaTime);\n let deltaCartesian = positionProperty.getValue(\n deltaTime,\n updateTransformCartesian3Scratch1\n );\n\n // If no valid position at (time + 0.001), sample at (time - 0.001) and invert the vector\n if (!defined(deltaCartesian)) {\n JulianDate.addSeconds(time, -0.001, deltaTime);\n deltaCartesian = positionProperty.getValue(\n deltaTime,\n updateTransformCartesian3Scratch1\n );\n invertVelocity = true;\n }\n\n if (defined(deltaCartesian)) {\n let toInertial = Transforms.computeFixedToIcrfMatrix(\n time,\n updateTransformMatrix3Scratch1\n );\n let toInertialDelta = Transforms.computeFixedToIcrfMatrix(\n deltaTime,\n updateTransformMatrix3Scratch2\n );\n let toFixed;\n\n if (!defined(toInertial) || !defined(toInertialDelta)) {\n toFixed = Transforms.computeTemeToPseudoFixedMatrix(\n time,\n updateTransformMatrix3Scratch3\n );\n toInertial = Matrix3.transpose(\n toFixed,\n updateTransformMatrix3Scratch1\n );\n toInertialDelta = Transforms.computeTemeToPseudoFixedMatrix(\n deltaTime,\n updateTransformMatrix3Scratch2\n );\n Matrix3.transpose(toInertialDelta, toInertialDelta);\n } else {\n toFixed = Matrix3.transpose(\n toInertial,\n updateTransformMatrix3Scratch3\n );\n }\n\n const inertialCartesian = Matrix3.multiplyByVector(\n toInertial,\n cartesian,\n updateTransformCartesian3Scratch5\n );\n const inertialDeltaCartesian = Matrix3.multiplyByVector(\n toInertialDelta,\n deltaCartesian,\n updateTransformCartesian3Scratch6\n );\n\n Cartesian3.subtract(\n inertialCartesian,\n inertialDeltaCartesian,\n updateTransformCartesian3Scratch4\n );\n const inertialVelocity =\n Cartesian3.magnitude(updateTransformCartesian3Scratch4) * 1000.0; // meters/sec\n\n const mu = CesiumMath.GRAVITATIONALPARAMETER; // m^3 / sec^2\n const semiMajorAxis =\n -mu /\n (inertialVelocity * inertialVelocity -\n (2 * mu) / Cartesian3.magnitude(inertialCartesian));\n\n if (\n semiMajorAxis < 0 ||\n semiMajorAxis > northUpAxisFactor * ellipsoid.maximumRadius\n ) {\n // North-up viewing from deep space.\n\n // X along the nadir\n xBasis = updateTransformCartesian3Scratch2;\n Cartesian3.normalize(cartesian, xBasis);\n Cartesian3.negate(xBasis, xBasis);\n\n // Z is North\n zBasis = Cartesian3.clone(\n Cartesian3.UNIT_Z,\n updateTransformCartesian3Scratch3\n );\n\n // Y is along the cross of z and x (right handed basis / in the direction of motion)\n yBasis = Cartesian3.cross(\n zBasis,\n xBasis,\n updateTransformCartesian3Scratch1\n );\n if (Cartesian3.magnitude(yBasis) > CesiumMath.EPSILON7) {\n Cartesian3.normalize(xBasis, xBasis);\n Cartesian3.normalize(yBasis, yBasis);\n\n zBasis = Cartesian3.cross(\n xBasis,\n yBasis,\n updateTransformCartesian3Scratch3\n );\n Cartesian3.normalize(zBasis, zBasis);\n\n hasBasis = true;\n }\n } else if (\n !Cartesian3.equalsEpsilon(\n cartesian,\n deltaCartesian,\n CesiumMath.EPSILON7\n )\n ) {\n // Approximation of VVLH (Vehicle Velocity Local Horizontal) with the Z-axis flipped.\n\n // Z along the position\n zBasis = updateTransformCartesian3Scratch2;\n Cartesian3.normalize(inertialCartesian, zBasis);\n Cartesian3.normalize(inertialDeltaCartesian, inertialDeltaCartesian);\n\n // Y is along the angular momentum vector (e.g. \"orbit normal\")\n yBasis = Cartesian3.cross(\n zBasis,\n inertialDeltaCartesian,\n updateTransformCartesian3Scratch3\n );\n\n if (invertVelocity) {\n yBasis = Cartesian3.multiplyByScalar(yBasis, -1, yBasis);\n }\n\n if (\n !Cartesian3.equalsEpsilon(\n yBasis,\n Cartesian3.ZERO,\n CesiumMath.EPSILON7\n )\n ) {\n // X is along the cross of y and z (right handed basis / in the direction of motion)\n xBasis = Cartesian3.cross(\n yBasis,\n zBasis,\n updateTransformCartesian3Scratch1\n );\n\n Matrix3.multiplyByVector(toFixed, xBasis, xBasis);\n Matrix3.multiplyByVector(toFixed, yBasis, yBasis);\n Matrix3.multiplyByVector(toFixed, zBasis, zBasis);\n\n Cartesian3.normalize(xBasis, xBasis);\n Cartesian3.normalize(yBasis, yBasis);\n Cartesian3.normalize(zBasis, zBasis);\n\n hasBasis = true;\n }\n }\n }\n }\n\n if (defined(that.boundingSphere)) {\n cartesian = that.boundingSphere.center;\n }\n\n let position;\n let direction;\n let up;\n\n if (saveCamera) {\n position = Cartesian3.clone(\n camera.position,\n updateTransformCartesian3Scratch4\n );\n direction = Cartesian3.clone(\n camera.direction,\n updateTransformCartesian3Scratch5\n );\n up = Cartesian3.clone(camera.up, updateTransformCartesian3Scratch6);\n }\n\n const transform = updateTransformMatrix4Scratch;\n if (hasBasis) {\n transform[0] = xBasis.x;\n transform[1] = xBasis.y;\n transform[2] = xBasis.z;\n transform[3] = 0.0;\n transform[4] = yBasis.x;\n transform[5] = yBasis.y;\n transform[6] = yBasis.z;\n transform[7] = 0.0;\n transform[8] = zBasis.x;\n transform[9] = zBasis.y;\n transform[10] = zBasis.z;\n transform[11] = 0.0;\n transform[12] = cartesian.x;\n transform[13] = cartesian.y;\n transform[14] = cartesian.z;\n transform[15] = 0.0;\n } else {\n // Stationary or slow-moving, low-altitude objects use East-North-Up.\n Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid, transform);\n }\n\n camera._setTransform(transform);\n\n if (saveCamera) {\n Cartesian3.clone(position, camera.position);\n Cartesian3.clone(direction, camera.direction);\n Cartesian3.clone(up, camera.up);\n Cartesian3.cross(direction, up, camera.right);\n }\n }\n\n if (updateLookAt) {\n const offset =\n mode === SceneMode.SCENE2D ||\n Cartesian3.equals(that._offset3D, Cartesian3.ZERO)\n ? undefined\n : that._offset3D;\n camera.lookAtTransform(camera.transform, offset);\n }\n}\n\n/**\n * A utility object for tracking an entity with the camera.\n * @alias EntityView\n * @constructor\n *\n * @param {Entity} entity The entity to track with the camera.\n * @param {Scene} scene The scene to use.\n * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use for orienting the camera.\n */\nfunction EntityView(entity, scene, ellipsoid) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"entity\", entity);\n Check.defined(\"scene\", scene);\n //>>includeEnd('debug');\n\n /**\n * The entity to track with the camera.\n * @type {Entity}\n */\n this.entity = entity;\n\n /**\n * The scene in which to track the object.\n * @type {Scene}\n */\n this.scene = scene;\n\n /**\n * The ellipsoid to use for orienting the camera.\n * @type {Ellipsoid}\n */\n this.ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);\n\n /**\n * The bounding sphere of the object.\n * @type {BoundingSphere}\n */\n this.boundingSphere = undefined;\n\n // Shadow copies of the objects so we can detect changes.\n this._lastEntity = undefined;\n this._mode = undefined;\n\n this._lastCartesian = new Cartesian3();\n this._defaultOffset3D = undefined;\n\n this._offset3D = new Cartesian3();\n}\n\n// STATIC properties defined here, not per-instance.\nObject.defineProperties(EntityView, {\n /**\n * Gets or sets a camera offset that will be used to\n * initialize subsequent EntityViews.\n * @memberof EntityView\n * @type {Cartesian3}\n */\n defaultOffset3D: {\n get: function () {\n return this._defaultOffset3D;\n },\n set: function (vector) {\n this._defaultOffset3D = Cartesian3.clone(vector, new Cartesian3());\n },\n },\n});\n\n// Initialize the static property.\nEntityView.defaultOffset3D = new Cartesian3(-14000, 3500, 3500);\n\nconst scratchHeadingPitchRange = new HeadingPitchRange();\nconst scratchCartesian = new Cartesian3();\n\n/**\n * Should be called each animation frame to update the camera\n * to the latest settings.\n * @param {JulianDate} time The current animation time.\n * @param {BoundingSphere} [boundingSphere] bounding sphere of the object.\n */\nEntityView.prototype.update = function (time, boundingSphere) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"time\", time);\n //>>includeEnd('debug');\n\n const scene = this.scene;\n const ellipsoid = this.ellipsoid;\n const sceneMode = scene.mode;\n if (sceneMode === SceneMode.MORPHING) {\n return;\n }\n\n const entity = this.entity;\n const positionProperty = entity.position;\n if (!defined(positionProperty)) {\n return;\n }\n const objectChanged = entity !== this._lastEntity;\n const sceneModeChanged = sceneMode !== this._mode;\n\n const camera = scene.camera;\n\n let updateLookAt = objectChanged || sceneModeChanged;\n let saveCamera = true;\n\n if (objectChanged) {\n const viewFromProperty = entity.viewFrom;\n const hasViewFrom = defined(viewFromProperty);\n\n if (!hasViewFrom && defined(boundingSphere)) {\n // The default HPR is not ideal for high altitude objects so\n // we scale the pitch as we get further from the earth for a more\n // downward view.\n scratchHeadingPitchRange.pitch = -CesiumMath.PI_OVER_FOUR;\n scratchHeadingPitchRange.range = 0;\n const position = positionProperty.getValue(time, scratchCartesian);\n if (defined(position)) {\n const factor =\n 2 -\n 1 /\n Math.max(\n 1,\n Cartesian3.magnitude(position) / ellipsoid.maximumRadius\n );\n scratchHeadingPitchRange.pitch *= factor;\n }\n\n camera.viewBoundingSphere(boundingSphere, scratchHeadingPitchRange);\n this.boundingSphere = boundingSphere;\n updateLookAt = false;\n saveCamera = false;\n } else if (\n !hasViewFrom ||\n !defined(viewFromProperty.getValue(time, this._offset3D))\n ) {\n Cartesian3.clone(EntityView._defaultOffset3D, this._offset3D);\n }\n } else if (!sceneModeChanged && this._mode !== SceneMode.SCENE2D) {\n Cartesian3.clone(camera.position, this._offset3D);\n }\n\n this._lastEntity = entity;\n this._mode = sceneMode;\n\n updateTransform(\n this,\n camera,\n updateLookAt,\n saveCamera,\n positionProperty,\n time,\n ellipsoid\n );\n};\nexport default EntityView;\n", "import buildModuleUrl from \"./buildModuleUrl.js\";\nimport Color from \"./Color.js\";\nimport defined from \"./defined.js\";\nimport DeveloperError from \"./DeveloperError.js\";\nimport Resource from \"./Resource.js\";\nimport writeTextToCanvas from \"./writeTextToCanvas.js\";\n\n/**\n * A utility class for generating custom map pins as canvas elements.\n *

\n *
\n *
\n * Example pins generated using both the maki icon set, which ships with Cesium, and single character text.\n *
\n *\n * @alias PinBuilder\n * @constructor\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Map%20Pins.html|Cesium Sandcastle PinBuilder Demo}\n */\nfunction PinBuilder() {\n this._cache = {};\n}\n\n/**\n * Creates an empty pin of the specified color and size.\n *\n * @param {Color} color The color of the pin.\n * @param {number} size The size of the pin, in pixels.\n * @returns {HTMLCanvasElement} The canvas element that represents the generated pin.\n */\nPinBuilder.prototype.fromColor = function (color, size) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(color)) {\n throw new DeveloperError(\"color is required\");\n }\n if (!defined(size)) {\n throw new DeveloperError(\"size is required\");\n }\n //>>includeEnd('debug');\n return createPin(undefined, undefined, color, size, this._cache);\n};\n\n/**\n * Creates a pin with the specified icon, color, and size.\n *\n * @param {Resource|string} url The url of the image to be stamped onto the pin.\n * @param {Color} color The color of the pin.\n * @param {number} size The size of the pin, in pixels.\n * @returns {HTMLCanvasElement|Promise} The canvas element or a Promise to the canvas element that represents the generated pin.\n */\nPinBuilder.prototype.fromUrl = function (url, color, size) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(url)) {\n throw new DeveloperError(\"url is required\");\n }\n if (!defined(color)) {\n throw new DeveloperError(\"color is required\");\n }\n if (!defined(size)) {\n throw new DeveloperError(\"size is required\");\n }\n //>>includeEnd('debug');\n return createPin(url, undefined, color, size, this._cache);\n};\n\n/**\n * Creates a pin with the specified {@link https://www.mapbox.com/maki/|maki} icon identifier, color, and size.\n *\n * @param {string} id The id of the maki icon to be stamped onto the pin.\n * @param {Color} color The color of the pin.\n * @param {number} size The size of the pin, in pixels.\n * @returns {HTMLCanvasElement|Promise} The canvas element or a Promise to the canvas element that represents the generated pin.\n */\nPinBuilder.prototype.fromMakiIconId = function (id, color, size) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(id)) {\n throw new DeveloperError(\"id is required\");\n }\n if (!defined(color)) {\n throw new DeveloperError(\"color is required\");\n }\n if (!defined(size)) {\n throw new DeveloperError(\"size is required\");\n }\n //>>includeEnd('debug');\n return createPin(\n buildModuleUrl(`Assets/Textures/maki/${encodeURIComponent(id)}.png`),\n undefined,\n color,\n size,\n this._cache\n );\n};\n\n/**\n * Creates a pin with the specified text, color, and size. The text will be sized to be as large as possible\n * while still being contained completely within the pin.\n *\n * @param {string} text The text to be stamped onto the pin.\n * @param {Color} color The color of the pin.\n * @param {number} size The size of the pin, in pixels.\n * @returns {HTMLCanvasElement} The canvas element that represents the generated pin.\n */\nPinBuilder.prototype.fromText = function (text, color, size) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(text)) {\n throw new DeveloperError(\"text is required\");\n }\n if (!defined(color)) {\n throw new DeveloperError(\"color is required\");\n }\n if (!defined(size)) {\n throw new DeveloperError(\"size is required\");\n }\n //>>includeEnd('debug');\n\n return createPin(undefined, text, color, size, this._cache);\n};\n\nconst colorScratch = new Color();\n\n//This function (except for the 3 commented lines) was auto-generated from an online tool,\n//http://www.professorcloud.com/svg-to-canvas/, using Assets/Textures/pin.svg as input.\n//The reason we simply can't load and draw the SVG directly to the canvas is because\n//it taints the canvas in Internet Explorer (and possibly some other browsers); making\n//it impossible to create a WebGL texture from the result.\nfunction drawPin(context2D, color, size) {\n context2D.save();\n context2D.scale(size / 24, size / 24); //Added to auto-generated code to scale up to desired size.\n context2D.fillStyle = color.toCssColorString(); //Modified from auto-generated code.\n context2D.strokeStyle = color.brighten(0.6, colorScratch).toCssColorString(); //Modified from auto-generated code.\n context2D.lineWidth = 0.846;\n context2D.beginPath();\n context2D.moveTo(6.72, 0.422);\n context2D.lineTo(17.28, 0.422);\n context2D.bezierCurveTo(18.553, 0.422, 19.577, 1.758, 19.577, 3.415);\n context2D.lineTo(19.577, 10.973);\n context2D.bezierCurveTo(19.577, 12.63, 18.553, 13.966, 17.282, 13.966);\n context2D.lineTo(14.386, 14.008);\n context2D.lineTo(11.826, 23.578);\n context2D.lineTo(9.614, 14.008);\n context2D.lineTo(6.719, 13.965);\n context2D.bezierCurveTo(5.446, 13.983, 4.422, 12.629, 4.422, 10.972);\n context2D.lineTo(4.422, 3.416);\n context2D.bezierCurveTo(4.423, 1.76, 5.447, 0.423, 6.718, 0.423);\n context2D.closePath();\n context2D.fill();\n context2D.stroke();\n context2D.restore();\n}\n\n//This function takes an image or canvas and uses it as a template\n//to \"stamp\" the pin with a white image outlined in black. The color\n//values of the input image are ignored completely and only the alpha\n//values are used.\nfunction drawIcon(context2D, image, size) {\n //Size is the largest image that looks good inside of pin box.\n const imageSize = size / 2.5;\n let sizeX = imageSize;\n let sizeY = imageSize;\n\n if (image.width > image.height) {\n sizeY = imageSize * (image.height / image.width);\n } else if (image.width < image.height) {\n sizeX = imageSize * (image.width / image.height);\n }\n\n //x and y are the center of the pin box\n const x = Math.round((size - sizeX) / 2);\n const y = Math.round((7 / 24) * size - sizeY / 2);\n\n context2D.globalCompositeOperation = \"destination-out\";\n context2D.drawImage(image, x - 1, y, sizeX, sizeY);\n context2D.drawImage(image, x, y - 1, sizeX, sizeY);\n context2D.drawImage(image, x + 1, y, sizeX, sizeY);\n context2D.drawImage(image, x, y + 1, sizeX, sizeY);\n\n context2D.globalCompositeOperation = \"destination-over\";\n context2D.fillStyle = Color.BLACK.toCssColorString();\n context2D.fillRect(x - 1, y - 1, sizeX + 2, sizeY + 2);\n\n context2D.globalCompositeOperation = \"destination-out\";\n context2D.drawImage(image, x, y, sizeX, sizeY);\n\n context2D.globalCompositeOperation = \"destination-over\";\n context2D.fillStyle = Color.WHITE.toCssColorString();\n context2D.fillRect(x - 1, y - 2, sizeX + 2, sizeY + 2);\n}\n\nconst stringifyScratch = new Array(4);\nfunction createPin(url, label, color, size, cache) {\n //Use the parameters as a unique ID for caching.\n stringifyScratch[0] = url;\n stringifyScratch[1] = label;\n stringifyScratch[2] = color;\n stringifyScratch[3] = size;\n const id = JSON.stringify(stringifyScratch);\n\n const item = cache[id];\n if (defined(item)) {\n return item;\n }\n\n const canvas = document.createElement(\"canvas\");\n canvas.width = size;\n canvas.height = size;\n\n const context2D = canvas.getContext(\"2d\");\n drawPin(context2D, color, size);\n\n if (defined(url)) {\n const resource = Resource.createIfNeeded(url);\n\n //If we have an image url, load it and then stamp the pin.\n const promise = resource.fetchImage().then(function (image) {\n drawIcon(context2D, image, size);\n cache[id] = canvas;\n return canvas;\n });\n cache[id] = promise;\n return promise;\n } else if (defined(label)) {\n //If we have a label, write it to a canvas and then stamp the pin.\n const image = writeTextToCanvas(label, {\n font: `bold ${size}px sans-serif`,\n });\n drawIcon(context2D, image, size);\n }\n\n cache[id] = canvas;\n return canvas;\n}\nexport default PinBuilder;\n", "export default function(x) {\n return x;\n}\n", "import identity from \"./identity.js\";\n\nexport default function(transform) {\n if (transform == null) return identity;\n var x0,\n y0,\n kx = transform.scale[0],\n ky = transform.scale[1],\n dx = transform.translate[0],\n dy = transform.translate[1];\n return function(input, i) {\n if (!i) x0 = y0 = 0;\n var j = 2, n = input.length, output = new Array(n);\n output[0] = (x0 += input[0]) * kx + dx;\n output[1] = (y0 += input[1]) * ky + dy;\n while (j < n) output[j] = input[j], ++j;\n return output;\n };\n}\n", "export default function(array, n) {\n var t, j = array.length, i = j - n;\n while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;\n}\n", "import reverse from \"./reverse.js\";\nimport transform from \"./transform.js\";\n\nexport default function(topology, o) {\n if (typeof o === \"string\") o = topology.objects[o];\n return o.type === \"GeometryCollection\"\n ? {type: \"FeatureCollection\", features: o.geometries.map(function(o) { return feature(topology, o); })}\n : feature(topology, o);\n}\n\nfunction feature(topology, o) {\n var id = o.id,\n bbox = o.bbox,\n properties = o.properties == null ? {} : o.properties,\n geometry = object(topology, o);\n return id == null && bbox == null ? {type: \"Feature\", properties: properties, geometry: geometry}\n : bbox == null ? {type: \"Feature\", id: id, properties: properties, geometry: geometry}\n : {type: \"Feature\", id: id, bbox: bbox, properties: properties, geometry: geometry};\n}\n\nexport function object(topology, o) {\n var transformPoint = transform(topology.transform),\n arcs = topology.arcs;\n\n function arc(i, points) {\n if (points.length) points.pop();\n for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {\n points.push(transformPoint(a[k], k));\n }\n if (i < 0) reverse(points, n);\n }\n\n function point(p) {\n return transformPoint(p);\n }\n\n function line(arcs) {\n var points = [];\n for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);\n if (points.length < 2) points.push(points[0]); // This should never happen per the specification.\n return points;\n }\n\n function ring(arcs) {\n var points = line(arcs);\n while (points.length < 4) points.push(points[0]); // This may happen if an arc has only two points.\n return points;\n }\n\n function polygon(arcs) {\n return arcs.map(ring);\n }\n\n function geometry(o) {\n var type = o.type, coordinates;\n switch (type) {\n case \"GeometryCollection\": return {type: type, geometries: o.geometries.map(geometry)};\n case \"Point\": coordinates = point(o.coordinates); break;\n case \"MultiPoint\": coordinates = o.coordinates.map(point); break;\n case \"LineString\": coordinates = line(o.arcs); break;\n case \"MultiLineString\": coordinates = o.arcs.map(line); break;\n case \"Polygon\": coordinates = polygon(o.arcs); break;\n case \"MultiPolygon\": coordinates = o.arcs.map(polygon); break;\n default: return null;\n }\n return {type: type, coordinates: coordinates};\n }\n\n return geometry(o);\n}\n", "import ArcType from \"../Core/ArcType.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport Credit from \"../Core/Credit.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport getFilenameFromUri from \"../Core/getFilenameFromUri.js\";\nimport PinBuilder from \"../Core/PinBuilder.js\";\nimport PolygonHierarchy from \"../Core/PolygonHierarchy.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport * as topojson from \"topojson-client\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport CallbackProperty from \"./CallbackProperty.js\";\nimport ColorMaterialProperty from \"./ColorMaterialProperty.js\";\nimport ConstantPositionProperty from \"./ConstantPositionProperty.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport DataSource from \"./DataSource.js\";\nimport EntityCluster from \"./EntityCluster.js\";\nimport EntityCollection from \"./EntityCollection.js\";\nimport PolygonGraphics from \"./PolygonGraphics.js\";\nimport PolylineGraphics from \"./PolylineGraphics.js\";\n\nfunction defaultCrsFunction(coordinates) {\n return Cartesian3.fromDegrees(coordinates[0], coordinates[1], coordinates[2]);\n}\n\nconst crsNames = {\n \"urn:ogc:def:crs:OGC:1.3:CRS84\": defaultCrsFunction,\n \"EPSG:4326\": defaultCrsFunction,\n \"urn:ogc:def:crs:EPSG::4326\": defaultCrsFunction,\n};\n\nconst crsLinkHrefs = {};\nconst crsLinkTypes = {};\nlet defaultMarkerSize = 48;\nlet defaultMarkerSymbol;\nlet defaultMarkerColor = Color.ROYALBLUE;\nlet defaultStroke = Color.YELLOW;\nlet defaultStrokeWidth = 2;\nlet defaultFill = Color.fromBytes(255, 255, 0, 100);\nlet defaultClampToGround = false;\n\nconst sizes = {\n small: 24,\n medium: 48,\n large: 64,\n};\n\nconst simpleStyleIdentifiers = [\n \"title\",\n \"description\", //\n \"marker-size\",\n \"marker-symbol\",\n \"marker-color\",\n \"stroke\", //\n \"stroke-opacity\",\n \"stroke-width\",\n \"fill\",\n \"fill-opacity\",\n];\n\nfunction defaultDescribe(properties, nameProperty) {\n let html = \"\";\n for (const key in properties) {\n if (properties.hasOwnProperty(key)) {\n if (key === nameProperty || simpleStyleIdentifiers.indexOf(key) !== -1) {\n continue;\n }\n const value = properties[key];\n if (defined(value)) {\n if (typeof value === \"object\") {\n html += `${key}${defaultDescribe(value)}`;\n } else {\n html += `${key}${value}`;\n }\n }\n }\n }\n\n if (html.length > 0) {\n html = `${html}
`;\n }\n\n return html;\n}\n\nfunction createDescriptionCallback(describe, properties, nameProperty) {\n let description;\n return function (time, result) {\n if (!defined(description)) {\n description = describe(properties, nameProperty);\n }\n return description;\n };\n}\n\nfunction defaultDescribeProperty(properties, nameProperty) {\n return new CallbackProperty(\n createDescriptionCallback(defaultDescribe, properties, nameProperty),\n true\n );\n}\n\n//GeoJSON specifies only the Feature object has a usable id property\n//But since \"multi\" geometries create multiple entity,\n//we can't use it for them either.\nfunction createObject(geoJson, entityCollection, describe) {\n let id = geoJson.id;\n if (!defined(id) || geoJson.type !== \"Feature\") {\n id = createGuid();\n } else {\n let i = 2;\n let finalId = id;\n while (defined(entityCollection.getById(finalId))) {\n finalId = `${id}_${i}`;\n i++;\n }\n id = finalId;\n }\n\n const entity = entityCollection.getOrCreateEntity(id);\n const properties = geoJson.properties;\n if (defined(properties)) {\n entity.properties = properties;\n\n let nameProperty;\n\n //Check for the simplestyle specified name first.\n const name = properties.title;\n if (defined(name)) {\n entity.name = name;\n nameProperty = \"title\";\n } else {\n //Else, find the name by selecting an appropriate property.\n //The name will be obtained based on this order:\n //1) The first case-insensitive property with the name 'title',\n //2) The first case-insensitive property with the name 'name',\n //3) The first property containing the word 'title'.\n //4) The first property containing the word 'name',\n let namePropertyPrecedence = Number.MAX_VALUE;\n for (const key in properties) {\n if (properties.hasOwnProperty(key) && properties[key]) {\n const lowerKey = key.toLowerCase();\n\n if (namePropertyPrecedence > 1 && lowerKey === \"title\") {\n namePropertyPrecedence = 1;\n nameProperty = key;\n break;\n } else if (namePropertyPrecedence > 2 && lowerKey === \"name\") {\n namePropertyPrecedence = 2;\n nameProperty = key;\n } else if (namePropertyPrecedence > 3 && /title/i.test(key)) {\n namePropertyPrecedence = 3;\n nameProperty = key;\n } else if (namePropertyPrecedence > 4 && /name/i.test(key)) {\n namePropertyPrecedence = 4;\n nameProperty = key;\n }\n }\n }\n if (defined(nameProperty)) {\n entity.name = properties[nameProperty];\n }\n }\n\n const description = properties.description;\n if (description !== null) {\n entity.description = !defined(description)\n ? describe(properties, nameProperty)\n : new ConstantProperty(description);\n }\n }\n return entity;\n}\n\nfunction coordinatesArrayToCartesianArray(coordinates, crsFunction) {\n const positions = new Array(coordinates.length);\n for (let i = 0; i < coordinates.length; i++) {\n positions[i] = crsFunction(coordinates[i]);\n }\n return positions;\n}\n\nconst geoJsonObjectTypes = {\n Feature: processFeature,\n FeatureCollection: processFeatureCollection,\n GeometryCollection: processGeometryCollection,\n LineString: processLineString,\n MultiLineString: processMultiLineString,\n MultiPoint: processMultiPoint,\n MultiPolygon: processMultiPolygon,\n Point: processPoint,\n Polygon: processPolygon,\n Topology: processTopology,\n};\n\nconst geometryTypes = {\n GeometryCollection: processGeometryCollection,\n LineString: processLineString,\n MultiLineString: processMultiLineString,\n MultiPoint: processMultiPoint,\n MultiPolygon: processMultiPolygon,\n Point: processPoint,\n Polygon: processPolygon,\n Topology: processTopology,\n};\n\n// GeoJSON processing functions\nfunction processFeature(dataSource, feature, notUsed, crsFunction, options) {\n if (feature.geometry === null) {\n //Null geometry is allowed, so just create an empty entity instance for it.\n createObject(feature, dataSource._entityCollection, options.describe);\n return;\n }\n\n if (!defined(feature.geometry)) {\n throw new RuntimeError(\"feature.geometry is required.\");\n }\n\n const geometryType = feature.geometry.type;\n const geometryHandler = geometryTypes[geometryType];\n if (!defined(geometryHandler)) {\n throw new RuntimeError(`Unknown geometry type: ${geometryType}`);\n }\n geometryHandler(dataSource, feature, feature.geometry, crsFunction, options);\n}\n\nfunction processFeatureCollection(\n dataSource,\n featureCollection,\n notUsed,\n crsFunction,\n options\n) {\n const features = featureCollection.features;\n for (let i = 0, len = features.length; i < len; i++) {\n processFeature(dataSource, features[i], undefined, crsFunction, options);\n }\n}\n\nfunction processGeometryCollection(\n dataSource,\n geoJson,\n geometryCollection,\n crsFunction,\n options\n) {\n const geometries = geometryCollection.geometries;\n for (let i = 0, len = geometries.length; i < len; i++) {\n const geometry = geometries[i];\n const geometryType = geometry.type;\n const geometryHandler = geometryTypes[geometryType];\n if (!defined(geometryHandler)) {\n throw new RuntimeError(`Unknown geometry type: ${geometryType}`);\n }\n geometryHandler(dataSource, geoJson, geometry, crsFunction, options);\n }\n}\n\nfunction createPoint(dataSource, geoJson, crsFunction, coordinates, options) {\n let symbol = options.markerSymbol;\n let color = options.markerColor;\n let size = options.markerSize;\n\n const properties = geoJson.properties;\n if (defined(properties)) {\n const cssColor = properties[\"marker-color\"];\n if (defined(cssColor)) {\n color = Color.fromCssColorString(cssColor);\n }\n\n size = defaultValue(sizes[properties[\"marker-size\"]], size);\n const markerSymbol = properties[\"marker-symbol\"];\n if (defined(markerSymbol)) {\n symbol = markerSymbol;\n }\n }\n\n let canvasOrPromise;\n if (defined(symbol)) {\n if (symbol.length === 1) {\n canvasOrPromise = dataSource._pinBuilder.fromText(\n symbol.toUpperCase(),\n color,\n size\n );\n } else {\n canvasOrPromise = dataSource._pinBuilder.fromMakiIconId(\n symbol,\n color,\n size\n );\n }\n } else {\n canvasOrPromise = dataSource._pinBuilder.fromColor(color, size);\n }\n\n const billboard = new BillboardGraphics();\n billboard.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);\n\n // Clamp to ground if there isn't a height specified\n if (coordinates.length === 2 && options.clampToGround) {\n billboard.heightReference = HeightReference.CLAMP_TO_GROUND;\n }\n\n const entity = createObject(\n geoJson,\n dataSource._entityCollection,\n options.describe\n );\n entity.billboard = billboard;\n entity.position = new ConstantPositionProperty(crsFunction(coordinates));\n\n const promise = Promise.resolve(canvasOrPromise)\n .then(function (image) {\n billboard.image = new ConstantProperty(image);\n })\n .catch(function () {\n billboard.image = new ConstantProperty(\n dataSource._pinBuilder.fromColor(color, size)\n );\n });\n\n dataSource._promises.push(promise);\n}\n\nfunction processPoint(dataSource, geoJson, geometry, crsFunction, options) {\n createPoint(dataSource, geoJson, crsFunction, geometry.coordinates, options);\n}\n\nfunction processMultiPoint(\n dataSource,\n geoJson,\n geometry,\n crsFunction,\n options\n) {\n const coordinates = geometry.coordinates;\n for (let i = 0; i < coordinates.length; i++) {\n createPoint(dataSource, geoJson, crsFunction, coordinates[i], options);\n }\n}\n\nfunction createLineString(\n dataSource,\n geoJson,\n crsFunction,\n coordinates,\n options\n) {\n let material = options.strokeMaterialProperty;\n let widthProperty = options.strokeWidthProperty;\n\n const properties = geoJson.properties;\n if (defined(properties)) {\n const width = properties[\"stroke-width\"];\n if (defined(width)) {\n widthProperty = new ConstantProperty(width);\n }\n\n let color;\n const stroke = properties.stroke;\n if (defined(stroke)) {\n color = Color.fromCssColorString(stroke);\n }\n const opacity = properties[\"stroke-opacity\"];\n if (defined(opacity) && opacity !== 1.0) {\n if (!defined(color)) {\n color = material.color.getValue().clone();\n }\n color.alpha = opacity;\n }\n if (defined(color)) {\n material = new ColorMaterialProperty(color);\n }\n }\n\n const entity = createObject(\n geoJson,\n dataSource._entityCollection,\n options.describe\n );\n const polylineGraphics = new PolylineGraphics();\n entity.polyline = polylineGraphics;\n\n polylineGraphics.clampToGround = options.clampToGround;\n polylineGraphics.material = material;\n polylineGraphics.width = widthProperty;\n polylineGraphics.positions = new ConstantProperty(\n coordinatesArrayToCartesianArray(coordinates, crsFunction)\n );\n polylineGraphics.arcType = ArcType.RHUMB;\n}\n\nfunction processLineString(\n dataSource,\n geoJson,\n geometry,\n crsFunction,\n options\n) {\n createLineString(\n dataSource,\n geoJson,\n crsFunction,\n geometry.coordinates,\n options\n );\n}\n\nfunction processMultiLineString(\n dataSource,\n geoJson,\n geometry,\n crsFunction,\n options\n) {\n const lineStrings = geometry.coordinates;\n for (let i = 0; i < lineStrings.length; i++) {\n createLineString(dataSource, geoJson, crsFunction, lineStrings[i], options);\n }\n}\n\nfunction createPolygon(dataSource, geoJson, crsFunction, coordinates, options) {\n if (coordinates.length === 0 || coordinates[0].length === 0) {\n return;\n }\n\n let outlineColorProperty = options.strokeMaterialProperty.color;\n let material = options.fillMaterialProperty;\n let widthProperty = options.strokeWidthProperty;\n\n const properties = geoJson.properties;\n if (defined(properties)) {\n const width = properties[\"stroke-width\"];\n if (defined(width)) {\n widthProperty = new ConstantProperty(width);\n }\n\n let color;\n const stroke = properties.stroke;\n if (defined(stroke)) {\n color = Color.fromCssColorString(stroke);\n }\n let opacity = properties[\"stroke-opacity\"];\n if (defined(opacity) && opacity !== 1.0) {\n if (!defined(color)) {\n color = outlineColorProperty.getValue().clone();\n }\n color.alpha = opacity;\n }\n\n if (defined(color)) {\n outlineColorProperty = new ConstantProperty(color);\n }\n\n let fillColor;\n const fill = properties.fill;\n const materialColor = material.color.getValue();\n if (defined(fill)) {\n fillColor = Color.fromCssColorString(fill);\n fillColor.alpha = materialColor.alpha;\n }\n opacity = properties[\"fill-opacity\"];\n if (defined(opacity) && opacity !== materialColor.alpha) {\n if (!defined(fillColor)) {\n fillColor = materialColor.clone();\n }\n fillColor.alpha = opacity;\n }\n if (defined(fillColor)) {\n material = new ColorMaterialProperty(fillColor);\n }\n }\n\n const polygon = new PolygonGraphics();\n polygon.outline = new ConstantProperty(true);\n polygon.outlineColor = outlineColorProperty;\n polygon.outlineWidth = widthProperty;\n polygon.material = material;\n polygon.arcType = ArcType.RHUMB;\n\n const holes = [];\n for (let i = 1, len = coordinates.length; i < len; i++) {\n holes.push(\n new PolygonHierarchy(\n coordinatesArrayToCartesianArray(coordinates[i], crsFunction)\n )\n );\n }\n\n const positions = coordinates[0];\n polygon.hierarchy = new ConstantProperty(\n new PolygonHierarchy(\n coordinatesArrayToCartesianArray(positions, crsFunction),\n holes\n )\n );\n if (positions[0].length > 2) {\n polygon.perPositionHeight = new ConstantProperty(true);\n } else if (!options.clampToGround) {\n polygon.height = 0;\n }\n\n const entity = createObject(\n geoJson,\n dataSource._entityCollection,\n options.describe\n );\n entity.polygon = polygon;\n}\n\nfunction processPolygon(dataSource, geoJson, geometry, crsFunction, options) {\n createPolygon(\n dataSource,\n geoJson,\n crsFunction,\n geometry.coordinates,\n options\n );\n}\n\nfunction processMultiPolygon(\n dataSource,\n geoJson,\n geometry,\n crsFunction,\n options\n) {\n const polygons = geometry.coordinates;\n for (let i = 0; i < polygons.length; i++) {\n createPolygon(dataSource, geoJson, crsFunction, polygons[i], options);\n }\n}\n\nfunction processTopology(dataSource, geoJson, geometry, crsFunction, options) {\n for (const property in geometry.objects) {\n if (geometry.objects.hasOwnProperty(property)) {\n const feature = topojson.feature(geometry, geometry.objects[property]);\n const typeHandler = geoJsonObjectTypes[feature.type];\n typeHandler(dataSource, feature, feature, crsFunction, options);\n }\n }\n}\n\n/**\n * @typedef {object} GeoJsonDataSource.LoadOptions\n *\n * Initialization options for the load method.\n *\n * @property {string} [sourceUri] Overrides the url to use for resolving relative links.\n * @property {GeoJsonDataSource.describe} [describe=GeoJsonDataSource.defaultDescribeProperty] A function which returns a Property object (or just a string).\n * @property {number} [markerSize=GeoJsonDataSource.markerSize] The default size of the map pin created for each point, in pixels.\n * @property {string} [markerSymbol=GeoJsonDataSource.markerSymbol] The default symbol of the map pin created for each point.\n * @property {Color} [markerColor=GeoJsonDataSource.markerColor] The default color of the map pin created for each point.\n * @property {Color} [stroke=GeoJsonDataSource.stroke] The default color of polylines and polygon outlines.\n * @property {number} [strokeWidth=GeoJsonDataSource.strokeWidth] The default width of polylines and polygon outlines.\n * @property {Color} [fill=GeoJsonDataSource.fill] The default color for polygon interiors.\n * @property {boolean} [clampToGround=GeoJsonDataSource.clampToGround] true if we want the geometry features (polygons or linestrings) clamped to the ground.\n * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.\n */\n\n/**\n * A {@link DataSource} which processes both\n * {@link http://www.geojson.org/|GeoJSON} and {@link https://github.com/mbostock/topojson|TopoJSON} data.\n * {@link https://github.com/mapbox/simplestyle-spec|simplestyle-spec} properties will also be used if they\n * are present.\n *\n * @alias GeoJsonDataSource\n * @constructor\n *\n * @param {string} [name] The name of this data source. If undefined, a name will be taken from\n * the name of the GeoJSON file.\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=GeoJSON%20and%20TopoJSON.html|Cesium Sandcastle GeoJSON and TopoJSON Demo}\n * @demo {@link https://sandcastle.cesium.com/index.html?src=GeoJSON%20simplestyle.html|Cesium Sandcastle GeoJSON simplestyle Demo}\n *\n * @example\n * const viewer = new Cesium.Viewer('cesiumContainer');\n * viewer.dataSources.add(Cesium.GeoJsonDataSource.load('../../SampleData/ne_10m_us_states.topojson', {\n * stroke: Cesium.Color.HOTPINK,\n * fill: Cesium.Color.PINK,\n * strokeWidth: 3,\n * markerSymbol: '?'\n * }));\n */\nfunction GeoJsonDataSource(name) {\n this._name = name;\n this._changed = new Event();\n this._error = new Event();\n this._isLoading = false;\n this._loading = new Event();\n this._entityCollection = new EntityCollection(this);\n this._promises = [];\n this._pinBuilder = new PinBuilder();\n this._entityCluster = new EntityCluster();\n this._credit = undefined;\n this._resourceCredits = [];\n}\n\n/**\n * Creates a Promise to a new instance loaded with the provided GeoJSON or TopoJSON data.\n *\n * @param {Resource|string|object} data A url, GeoJSON object, or TopoJSON object to be loaded.\n * @param {GeoJsonDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that will resolve when the data is loaded.\n */\nGeoJsonDataSource.load = function (data, options) {\n return new GeoJsonDataSource().load(data, options);\n};\n\nObject.defineProperties(GeoJsonDataSource, {\n /**\n * Gets or sets the default size of the map pin created for each point, in pixels.\n * @memberof GeoJsonDataSource\n * @type {number}\n * @default 48\n */\n markerSize: {\n get: function () {\n return defaultMarkerSize;\n },\n set: function (value) {\n defaultMarkerSize = value;\n },\n },\n /**\n * Gets or sets the default symbol of the map pin created for each point.\n * This can be any valid {@link http://mapbox.com/maki/|Maki} identifier, any single character,\n * or blank if no symbol is to be used.\n * @memberof GeoJsonDataSource\n * @type {string}\n */\n markerSymbol: {\n get: function () {\n return defaultMarkerSymbol;\n },\n set: function (value) {\n defaultMarkerSymbol = value;\n },\n },\n /**\n * Gets or sets the default color of the map pin created for each point.\n * @memberof GeoJsonDataSource\n * @type {Color}\n * @default Color.ROYALBLUE\n */\n markerColor: {\n get: function () {\n return defaultMarkerColor;\n },\n set: function (value) {\n defaultMarkerColor = value;\n },\n },\n /**\n * Gets or sets the default color of polylines and polygon outlines.\n * @memberof GeoJsonDataSource\n * @type {Color}\n * @default Color.BLACK\n */\n stroke: {\n get: function () {\n return defaultStroke;\n },\n set: function (value) {\n defaultStroke = value;\n },\n },\n /**\n * Gets or sets the default width of polylines and polygon outlines.\n * @memberof GeoJsonDataSource\n * @type {number}\n * @default 2.0\n */\n strokeWidth: {\n get: function () {\n return defaultStrokeWidth;\n },\n set: function (value) {\n defaultStrokeWidth = value;\n },\n },\n /**\n * Gets or sets default color for polygon interiors.\n * @memberof GeoJsonDataSource\n * @type {Color}\n * @default Color.YELLOW\n */\n fill: {\n get: function () {\n return defaultFill;\n },\n set: function (value) {\n defaultFill = value;\n },\n },\n /**\n * Gets or sets default of whether to clamp to the ground.\n * @memberof GeoJsonDataSource\n * @type {boolean}\n * @default false\n */\n clampToGround: {\n get: function () {\n return defaultClampToGround;\n },\n set: function (value) {\n defaultClampToGround = value;\n },\n },\n\n /**\n * Gets an object that maps the name of a crs to a callback function which takes a GeoJSON coordinate\n * and transforms it into a WGS84 Earth-fixed Cartesian. Older versions of GeoJSON which\n * supported the EPSG type can be added to this list as well, by specifying the complete EPSG name,\n * for example 'EPSG:4326'.\n * @memberof GeoJsonDataSource\n * @type {object}\n */\n crsNames: {\n get: function () {\n return crsNames;\n },\n },\n\n /**\n * Gets an object that maps the href property of a crs link to a callback function\n * which takes the crs properties object and returns a Promise that resolves\n * to a function that takes a GeoJSON coordinate and transforms it into a WGS84 Earth-fixed Cartesian.\n * Items in this object take precedence over those defined in crsLinkHrefs, assuming\n * the link has a type specified.\n * @memberof GeoJsonDataSource\n * @type {object}\n */\n crsLinkHrefs: {\n get: function () {\n return crsLinkHrefs;\n },\n },\n\n /**\n * Gets an object that maps the type property of a crs link to a callback function\n * which takes the crs properties object and returns a Promise that resolves\n * to a function that takes a GeoJSON coordinate and transforms it into a WGS84 Earth-fixed Cartesian.\n * Items in crsLinkHrefs take precedence over this object.\n * @memberof GeoJsonDataSource\n * @type {object}\n */\n crsLinkTypes: {\n get: function () {\n return crsLinkTypes;\n },\n },\n});\n\nObject.defineProperties(GeoJsonDataSource.prototype, {\n /**\n * Gets or sets a human-readable name for this instance.\n * @memberof GeoJsonDataSource.prototype\n * @type {string}\n */\n name: {\n get: function () {\n return this._name;\n },\n set: function (value) {\n if (this._name !== value) {\n this._name = value;\n this._changed.raiseEvent(this);\n }\n },\n },\n /**\n * This DataSource only defines static data, therefore this property is always undefined.\n * @memberof GeoJsonDataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n value: undefined,\n writable: false,\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof GeoJsonDataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: function () {\n return this._entityCollection;\n },\n },\n /**\n * Gets a value indicating if the data source is currently loading data.\n * @memberof GeoJsonDataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: function () {\n return this._isLoading;\n },\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof GeoJsonDataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: function () {\n return this._changed;\n },\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof GeoJsonDataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: function () {\n return this._error;\n },\n },\n /**\n * Gets an event that will be raised when the data source either starts or stops loading.\n * @memberof GeoJsonDataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: function () {\n return this._loading;\n },\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof GeoJsonDataSource.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._entityCollection.show;\n },\n set: function (value) {\n this._entityCollection.show = value;\n },\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof GeoJsonDataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: function () {\n return this._entityCluster;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value must be defined.\");\n }\n //>>includeEnd('debug');\n this._entityCluster = value;\n },\n },\n /**\n * Gets the credit that will be displayed for the data source\n * @memberof GeoJsonDataSource.prototype\n * @type {Credit}\n */\n credit: {\n get: function () {\n return this._credit;\n },\n },\n});\n\n/**\n * Asynchronously loads the provided GeoJSON or TopoJSON data, replacing any existing data.\n *\n * @param {Resource|string|object} data A url, GeoJSON object, or TopoJSON object to be loaded.\n * @param {GeoJsonDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} a promise that will resolve when the GeoJSON is loaded.\n */\nGeoJsonDataSource.prototype.load = function (data, options) {\n return preload(this, data, options, true);\n};\n\n/**\n * Asynchronously loads the provided GeoJSON or TopoJSON data, without replacing any existing data.\n *\n * @param {Resource|string|object} data A url, GeoJSON object, or TopoJSON object to be loaded.\n * @param {GeoJsonDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} a promise that will resolve when the GeoJSON is loaded.\n */\nGeoJsonDataSource.prototype.process = function (data, options) {\n return preload(this, data, options, false);\n};\n\nfunction preload(that, data, options, clear) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(data)) {\n throw new DeveloperError(\"data is required.\");\n }\n //>>includeEnd('debug');\n\n DataSource.setLoading(that, true);\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n\n // User specified credit\n let credit = options.credit;\n if (typeof credit === \"string\") {\n credit = new Credit(credit);\n }\n that._credit = credit;\n\n let promise = data;\n let sourceUri = options.sourceUri;\n if (typeof data === \"string\" || data instanceof Resource) {\n data = Resource.createIfNeeded(data);\n promise = data.fetchJson();\n sourceUri = defaultValue(sourceUri, data.getUrlComponent());\n\n // Add resource credits to our list of credits to display\n const resourceCredits = that._resourceCredits;\n const credits = data.credits;\n if (defined(credits)) {\n const length = credits.length;\n for (let i = 0; i < length; i++) {\n resourceCredits.push(credits[i]);\n }\n }\n }\n\n options = {\n describe: defaultValue(options.describe, defaultDescribeProperty),\n markerSize: defaultValue(options.markerSize, defaultMarkerSize),\n markerSymbol: defaultValue(options.markerSymbol, defaultMarkerSymbol),\n markerColor: defaultValue(options.markerColor, defaultMarkerColor),\n strokeWidthProperty: new ConstantProperty(\n defaultValue(options.strokeWidth, defaultStrokeWidth)\n ),\n strokeMaterialProperty: new ColorMaterialProperty(\n defaultValue(options.stroke, defaultStroke)\n ),\n fillMaterialProperty: new ColorMaterialProperty(\n defaultValue(options.fill, defaultFill)\n ),\n clampToGround: defaultValue(options.clampToGround, defaultClampToGround),\n };\n\n return Promise.resolve(promise)\n .then(function (geoJson) {\n return load(that, geoJson, options, sourceUri, clear);\n })\n .catch(function (error) {\n DataSource.setLoading(that, false);\n that._error.raiseEvent(that, error);\n throw error;\n });\n}\n\n/**\n * Updates the data source to the provided time. This function is optional and\n * is not required to be implemented. It is provided for data sources which\n * retrieve data based on the current animation time or scene state.\n * If implemented, update will be called by {@link DataSourceDisplay} once a frame.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nGeoJsonDataSource.prototype.update = function (time) {\n return true;\n};\n\nfunction load(that, geoJson, options, sourceUri, clear) {\n let name;\n if (defined(sourceUri)) {\n name = getFilenameFromUri(sourceUri);\n }\n\n if (defined(name) && that._name !== name) {\n that._name = name;\n that._changed.raiseEvent(that);\n }\n\n const typeHandler = geoJsonObjectTypes[geoJson.type];\n if (!defined(typeHandler)) {\n throw new RuntimeError(`Unsupported GeoJSON object type: ${geoJson.type}`);\n }\n\n //Check for a Coordinate Reference System.\n const crs = geoJson.crs;\n let crsFunction = crs !== null ? defaultCrsFunction : null;\n\n if (defined(crs)) {\n if (!defined(crs.properties)) {\n throw new RuntimeError(\"crs.properties is undefined.\");\n }\n\n const properties = crs.properties;\n if (crs.type === \"name\") {\n crsFunction = crsNames[properties.name];\n if (!defined(crsFunction)) {\n throw new RuntimeError(`Unknown crs name: ${properties.name}`);\n }\n } else if (crs.type === \"link\") {\n let handler = crsLinkHrefs[properties.href];\n if (!defined(handler)) {\n handler = crsLinkTypes[properties.type];\n }\n\n if (!defined(handler)) {\n throw new RuntimeError(\n `Unable to resolve crs link: ${JSON.stringify(properties)}`\n );\n }\n\n crsFunction = handler(properties);\n } else if (crs.type === \"EPSG\") {\n crsFunction = crsNames[`EPSG:${properties.code}`];\n if (!defined(crsFunction)) {\n throw new RuntimeError(`Unknown crs EPSG code: ${properties.code}`);\n }\n } else {\n throw new RuntimeError(`Unknown crs type: ${crs.type}`);\n }\n }\n\n return Promise.resolve(crsFunction).then(function (crsFunction) {\n if (clear) {\n that._entityCollection.removeAll();\n }\n\n // null is a valid value for the crs, but means the entire load process becomes a no-op\n // because we can't assume anything about the coordinates.\n if (crsFunction !== null) {\n typeHandler(that, geoJson, geoJson, crsFunction, options);\n }\n\n return Promise.all(that._promises).then(function () {\n that._promises.length = 0;\n DataSource.setLoading(that, false);\n return that;\n });\n });\n}\n\n/**\n * This callback is displayed as part of the GeoJsonDataSource class.\n * @callback GeoJsonDataSource.describe\n * @param {object} properties The properties of the feature.\n * @param {string} nameProperty The property key that Cesium estimates to have the name of the feature.\n */\nexport default GeoJsonDataSource;\n", null, null, null, null, null, null, null, null, "/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n function next() {\n while (env.stack.length) {\n var rec = env.stack.pop();\n try {\n var result = rec.dispose && rec.dispose.call(rec.value);\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n catch (e) {\n fail(e);\n }\n }\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "import Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport ClockRange from \"../Core/ClockRange.js\";\nimport ClockStep from \"../Core/ClockStep.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Event from \"../Core/Event.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport PinBuilder from \"../Core/PinBuilder.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport LabelStyle from \"../Scene/LabelStyle.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport Autolinker from \"autolinker\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport ConstantProperty from \"./ConstantProperty.js\";\nimport DataSource from \"./DataSource.js\";\nimport DataSourceClock from \"./DataSourceClock.js\";\nimport EntityCluster from \"./EntityCluster.js\";\nimport EntityCollection from \"./EntityCollection.js\";\nimport LabelGraphics from \"./LabelGraphics.js\";\nimport PolylineGraphics from \"./PolylineGraphics.js\";\nimport PolylineOutlineMaterialProperty from \"./PolylineOutlineMaterialProperty.js\";\nimport SampledPositionProperty from \"./SampledPositionProperty.js\";\n\nlet parser;\nif (typeof DOMParser !== \"undefined\") {\n parser = new DOMParser();\n}\n\nconst autolinker = new Autolinker({\n stripPrefix: false,\n email: false,\n replaceFn: function (linker, match) {\n //Prevent matching of non-explicit urls.\n //i.e. foo.id won't match but http://foo.id will\n return match.urlMatchType === \"scheme\" || match.urlMatchType === \"www\";\n },\n});\n\nconst BILLBOARD_SIZE = 32;\nconst BILLBOARD_NEAR_DISTANCE = 2414016;\nconst BILLBOARD_NEAR_RATIO = 1.0;\nconst BILLBOARD_FAR_DISTANCE = 1.6093e7;\nconst BILLBOARD_FAR_RATIO = 0.1;\n\nconst gpxNamespaces = [null, undefined, \"http://www.topografix.com/GPX/1/1\"];\nconst namespaces = {\n gpx: gpxNamespaces,\n};\n\nfunction readBlobAsText(blob) {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", function () {\n resolve(reader.result);\n });\n reader.addEventListener(\"error\", function () {\n reject(reader.error);\n });\n reader.readAsText(blob);\n });\n}\n\nfunction getOrCreateEntity(node, entityCollection) {\n let id = queryStringAttribute(node, \"id\");\n id = defined(id) ? id : createGuid();\n const entity = entityCollection.getOrCreateEntity(id);\n return entity;\n}\n\nfunction readCoordinateFromNode(node) {\n const longitude = queryNumericAttribute(node, \"lon\");\n const latitude = queryNumericAttribute(node, \"lat\");\n const elevation = queryNumericValue(node, \"ele\", namespaces.gpx);\n return Cartesian3.fromDegrees(longitude, latitude, elevation);\n}\n\nfunction queryNumericAttribute(node, attributeName) {\n if (!defined(node)) {\n return undefined;\n }\n\n const value = node.getAttribute(attributeName);\n if (value !== null) {\n const result = parseFloat(value);\n return !isNaN(result) ? result : undefined;\n }\n return undefined;\n}\n\nfunction queryStringAttribute(node, attributeName) {\n if (!defined(node)) {\n return undefined;\n }\n const value = node.getAttribute(attributeName);\n return value !== null ? value : undefined;\n}\n\nfunction queryFirstNode(node, tagName, namespace) {\n if (!defined(node)) {\n return undefined;\n }\n const childNodes = node.childNodes;\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === tagName &&\n namespace.indexOf(child.namespaceURI) !== -1\n ) {\n return child;\n }\n }\n return undefined;\n}\n\nfunction queryNodes(node, tagName, namespace) {\n if (!defined(node)) {\n return undefined;\n }\n const result = [];\n const childNodes = node.getElementsByTagName(tagName);\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === tagName &&\n namespace.indexOf(child.namespaceURI) !== -1\n ) {\n result.push(child);\n }\n }\n return result;\n}\n\nfunction queryNumericValue(node, tagName, namespace) {\n const resultNode = queryFirstNode(node, tagName, namespace);\n if (defined(resultNode)) {\n const result = parseFloat(resultNode.textContent);\n return !isNaN(result) ? result : undefined;\n }\n return undefined;\n}\n\nfunction queryStringValue(node, tagName, namespace) {\n const result = queryFirstNode(node, tagName, namespace);\n if (defined(result)) {\n return result.textContent.trim();\n }\n return undefined;\n}\n\nfunction createDefaultBillboard(image) {\n const billboard = new BillboardGraphics();\n billboard.width = BILLBOARD_SIZE;\n billboard.height = BILLBOARD_SIZE;\n billboard.scaleByDistance = new NearFarScalar(\n BILLBOARD_NEAR_DISTANCE,\n BILLBOARD_NEAR_RATIO,\n BILLBOARD_FAR_DISTANCE,\n BILLBOARD_FAR_RATIO\n );\n billboard.pixelOffsetScaleByDistance = new NearFarScalar(\n BILLBOARD_NEAR_DISTANCE,\n BILLBOARD_NEAR_RATIO,\n BILLBOARD_FAR_DISTANCE,\n BILLBOARD_FAR_RATIO\n );\n billboard.verticalOrigin = new ConstantProperty(VerticalOrigin.BOTTOM);\n billboard.image = image;\n return billboard;\n}\n\nfunction createDefaultLabel() {\n const label = new LabelGraphics();\n label.translucencyByDistance = new NearFarScalar(3000000, 1.0, 5000000, 0.0);\n label.pixelOffset = new Cartesian2(17, 0);\n label.horizontalOrigin = HorizontalOrigin.LEFT;\n label.font = \"16px sans-serif\";\n label.style = LabelStyle.FILL_AND_OUTLINE;\n return label;\n}\n\nfunction createDefaultPolyline(color) {\n const polyline = new PolylineGraphics();\n polyline.width = 4;\n polyline.material = new PolylineOutlineMaterialProperty();\n polyline.material.color = defined(color) ? color : Color.RED;\n polyline.material.outlineWidth = 2;\n polyline.material.outlineColor = Color.BLACK;\n return polyline;\n}\n\n// This is a list of the Optional Description Information:\n// GPS comment of the waypoint\n// Descriptive description of the waypoint\n// Source of the waypoint data\n// Type (category) of waypoint\nconst descriptiveInfoTypes = {\n time: {\n text: \"Time\",\n tag: \"time\",\n },\n comment: {\n text: \"Comment\",\n tag: \"cmt\",\n },\n description: {\n text: \"Description\",\n tag: \"desc\",\n },\n source: {\n text: \"Source\",\n tag: \"src\",\n },\n number: {\n text: \"GPS track/route number\",\n tag: \"number\",\n },\n type: {\n text: \"Type\",\n tag: \"type\",\n },\n};\n\nlet scratchDiv;\nif (typeof document !== \"undefined\") {\n scratchDiv = document.createElement(\"div\");\n}\nfunction processDescription(node, entity) {\n let i;\n\n let text = \"\";\n const infoTypeNames = Object.keys(descriptiveInfoTypes);\n const length = infoTypeNames.length;\n for (i = 0; i < length; i++) {\n const infoTypeName = infoTypeNames[i];\n const infoType = descriptiveInfoTypes[infoTypeName];\n infoType.value = defaultValue(\n queryStringValue(node, infoType.tag, namespaces.gpx),\n \"\"\n );\n if (defined(infoType.value) && infoType.value !== \"\") {\n text = `${text}

${infoType.text}: ${infoType.value}

`;\n }\n }\n\n if (!defined(text) || text === \"\") {\n // No description\n return;\n }\n\n // Turns non-explicit links into clickable links.\n text = autolinker.link(text);\n\n // Use a temporary div to manipulate the links\n // so that they open in a new window.\n scratchDiv.innerHTML = text;\n const links = scratchDiv.querySelectorAll(\"a\");\n\n for (i = 0; i < links.length; i++) {\n links[i].setAttribute(\"target\", \"_blank\");\n }\n\n const background = Color.WHITE;\n const foreground = Color.BLACK;\n let tmp = '
`;\n scratchDiv.innerHTML = \"\";\n\n // return the final HTML as the description.\n return tmp;\n}\n\nfunction processWpt(dataSource, geometryNode, entityCollection, options) {\n const position = readCoordinateFromNode(geometryNode);\n\n const entity = getOrCreateEntity(geometryNode, entityCollection);\n entity.position = position;\n\n // Get billboard image\n const image = defined(options.waypointImage)\n ? options.waypointImage\n : dataSource._pinBuilder.fromMakiIconId(\n \"marker\",\n Color.RED,\n BILLBOARD_SIZE\n );\n entity.billboard = createDefaultBillboard(image);\n\n const name = queryStringValue(geometryNode, \"name\", namespaces.gpx);\n entity.name = name;\n entity.label = createDefaultLabel();\n entity.label.text = name;\n entity.description = processDescription(geometryNode, entity);\n\n if (options.clampToGround) {\n entity.billboard.heightReference = HeightReference.CLAMP_TO_GROUND;\n entity.label.heightReference = HeightReference.CLAMP_TO_GROUND;\n }\n}\n\n// rte represents route - an ordered list of waypoints representing a series of turn points leading to a destination\nfunction processRte(dataSource, geometryNode, entityCollection, options) {\n const entity = getOrCreateEntity(geometryNode, entityCollection);\n entity.description = processDescription(geometryNode, entity);\n\n // a list of waypoint\n const routePoints = queryNodes(geometryNode, \"rtept\", namespaces.gpx);\n const coordinateTuples = new Array(routePoints.length);\n for (let i = 0; i < routePoints.length; i++) {\n processWpt(dataSource, routePoints[i], entityCollection, options);\n coordinateTuples[i] = readCoordinateFromNode(routePoints[i]);\n }\n entity.polyline = createDefaultPolyline(options.routeColor);\n if (options.clampToGround) {\n entity.polyline.clampToGround = true;\n }\n entity.polyline.positions = coordinateTuples;\n}\n\n// trk represents a track - an ordered list of points describing a path.\nfunction processTrk(dataSource, geometryNode, entityCollection, options) {\n const entity = getOrCreateEntity(geometryNode, entityCollection);\n entity.description = processDescription(geometryNode, entity);\n\n const trackSegs = queryNodes(geometryNode, \"trkseg\", namespaces.gpx);\n let positions = [];\n let times = [];\n let trackSegInfo;\n let isTimeDynamic = true;\n const property = new SampledPositionProperty();\n for (let i = 0; i < trackSegs.length; i++) {\n trackSegInfo = processTrkSeg(trackSegs[i]);\n positions = positions.concat(trackSegInfo.positions);\n if (trackSegInfo.times.length > 0) {\n times = times.concat(trackSegInfo.times);\n property.addSamples(times, positions);\n // if one track segment is non dynamic the whole track must also be\n isTimeDynamic = isTimeDynamic && true;\n } else {\n isTimeDynamic = false;\n }\n }\n if (isTimeDynamic) {\n // Assign billboard image\n const image = defined(options.waypointImage)\n ? options.waypointImage\n : dataSource._pinBuilder.fromMakiIconId(\n \"marker\",\n Color.RED,\n BILLBOARD_SIZE\n );\n entity.billboard = createDefaultBillboard(image);\n entity.position = property;\n if (options.clampToGround) {\n entity.billboard.heightReference = HeightReference.CLAMP_TO_GROUND;\n }\n entity.availability = new TimeIntervalCollection();\n entity.availability.addInterval(\n new TimeInterval({\n start: times[0],\n stop: times[times.length - 1],\n })\n );\n }\n entity.polyline = createDefaultPolyline(options.trackColor);\n entity.polyline.positions = positions;\n if (options.clampToGround) {\n entity.polyline.clampToGround = true;\n }\n}\n\nfunction processTrkSeg(node) {\n const result = {\n positions: [],\n times: [],\n };\n const trackPoints = queryNodes(node, \"trkpt\", namespaces.gpx);\n let time;\n for (let i = 0; i < trackPoints.length; i++) {\n const position = readCoordinateFromNode(trackPoints[i]);\n result.positions.push(position);\n\n time = queryStringValue(trackPoints[i], \"time\", namespaces.gpx);\n if (defined(time)) {\n result.times.push(JulianDate.fromIso8601(time));\n }\n }\n return result;\n}\n\n// Processes a metadataType node and returns a metadata object\n// {@link http://www.topografix.com/gpx/1/1/#type_metadataType|GPX Schema}\nfunction processMetadata(node) {\n const metadataNode = queryFirstNode(node, \"metadata\", namespaces.gpx);\n if (defined(metadataNode)) {\n const metadata = {\n name: queryStringValue(metadataNode, \"name\", namespaces.gpx),\n desc: queryStringValue(metadataNode, \"desc\", namespaces.gpx),\n author: getPerson(metadataNode),\n copyright: getCopyright(metadataNode),\n link: getLink(metadataNode),\n time: queryStringValue(metadataNode, \"time\", namespaces.gpx),\n keywords: queryStringValue(metadataNode, \"keywords\", namespaces.gpx),\n bounds: getBounds(metadataNode),\n };\n if (\n defined(metadata.name) ||\n defined(metadata.desc) ||\n defined(metadata.author) ||\n defined(metadata.copyright) ||\n defined(metadata.link) ||\n defined(metadata.time) ||\n defined(metadata.keywords) ||\n defined(metadata.bounds)\n ) {\n return metadata;\n }\n }\n return undefined;\n}\n\n// Receives a XML node and returns a personType object, refer to\n// {@link http://www.topografix.com/gpx/1/1/#type_personType|GPX Schema}\nfunction getPerson(node) {\n const personNode = queryFirstNode(node, \"author\", namespaces.gpx);\n if (defined(personNode)) {\n const person = {\n name: queryStringValue(personNode, \"name\", namespaces.gpx),\n email: getEmail(personNode),\n link: getLink(personNode),\n };\n if (defined(person.name) || defined(person.email) || defined(person.link)) {\n return person;\n }\n }\n return undefined;\n}\n\n// Receives a XML node and returns an email address (from emailType), refer to\n// {@link http://www.topografix.com/gpx/1/1/#type_emailType|GPX Schema}\nfunction getEmail(node) {\n const emailNode = queryFirstNode(node, \"email\", namespaces.gpx);\n if (defined(emailNode)) {\n const id = queryStringValue(emailNode, \"id\", namespaces.gpx);\n const domain = queryStringValue(emailNode, \"domain\", namespaces.gpx);\n return `${id}@${domain}`;\n }\n return undefined;\n}\n\n// Receives a XML node and returns a linkType object, refer to\n// {@link http://www.topografix.com/gpx/1/1/#type_linkType|GPX Schema}\nfunction getLink(node) {\n const linkNode = queryFirstNode(node, \"link\", namespaces.gpx);\n if (defined(linkNode)) {\n const link = {\n href: queryStringAttribute(linkNode, \"href\"),\n text: queryStringValue(linkNode, \"text\", namespaces.gpx),\n mimeType: queryStringValue(linkNode, \"type\", namespaces.gpx),\n };\n if (defined(link.href) || defined(link.text) || defined(link.mimeType)) {\n return link;\n }\n }\n return undefined;\n}\n\n// Receives a XML node and returns a copyrightType object, refer to\n// {@link http://www.topografix.com/gpx/1/1/#type_copyrightType|GPX Schema}\nfunction getCopyright(node) {\n const copyrightNode = queryFirstNode(node, \"copyright\", namespaces.gpx);\n if (defined(copyrightNode)) {\n const copyright = {\n author: queryStringAttribute(copyrightNode, \"author\"),\n year: queryStringValue(copyrightNode, \"year\", namespaces.gpx),\n license: queryStringValue(copyrightNode, \"license\", namespaces.gpx),\n };\n if (\n defined(copyright.author) ||\n defined(copyright.year) ||\n defined(copyright.license)\n ) {\n return copyright;\n }\n }\n return undefined;\n}\n\n// Receives a XML node and returns a boundsType object, refer to\n// {@link http://www.topografix.com/gpx/1/1/#type_boundsType|GPX Schema}\nfunction getBounds(node) {\n const boundsNode = queryFirstNode(node, \"bounds\", namespaces.gpx);\n if (defined(boundsNode)) {\n const bounds = {\n minLat: queryNumericValue(boundsNode, \"minlat\", namespaces.gpx),\n maxLat: queryNumericValue(boundsNode, \"maxlat\", namespaces.gpx),\n minLon: queryNumericValue(boundsNode, \"minlon\", namespaces.gpx),\n maxLon: queryNumericValue(boundsNode, \"maxlon\", namespaces.gpx),\n };\n if (\n defined(bounds.minLat) ||\n defined(bounds.maxLat) ||\n defined(bounds.minLon) ||\n defined(bounds.maxLon)\n ) {\n return bounds;\n }\n }\n return undefined;\n}\n\nconst complexTypes = {\n wpt: processWpt,\n rte: processRte,\n trk: processTrk,\n};\n\nfunction processGpx(dataSource, node, entityCollection, options) {\n const complexTypeNames = Object.keys(complexTypes);\n const complexTypeNamesLength = complexTypeNames.length;\n\n for (let i = 0; i < complexTypeNamesLength; i++) {\n const typeName = complexTypeNames[i];\n const processComplexTypeNode = complexTypes[typeName];\n\n const childNodes = node.childNodes;\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === typeName &&\n namespaces.gpx.indexOf(child.namespaceURI) !== -1\n ) {\n processComplexTypeNode(dataSource, child, entityCollection, options);\n }\n }\n }\n}\n\nfunction loadGpx(dataSource, gpx, options) {\n const entityCollection = dataSource._entityCollection;\n\n entityCollection.removeAll();\n\n const element = gpx.documentElement;\n const version = queryStringAttribute(element, \"version\");\n const creator = queryStringAttribute(element, \"creator\");\n\n let name;\n const metadata = processMetadata(element);\n if (defined(metadata)) {\n name = metadata.name;\n }\n\n if (element.localName === \"gpx\") {\n processGpx(dataSource, element, entityCollection, options);\n } else {\n console.log(`GPX - Unsupported node: ${element.localName}`);\n }\n\n let clock;\n const availability = entityCollection.computeAvailability();\n\n let start = availability.start;\n let stop = availability.stop;\n const isMinStart = JulianDate.equals(start, Iso8601.MINIMUM_VALUE);\n const isMaxStop = JulianDate.equals(stop, Iso8601.MAXIMUM_VALUE);\n if (!isMinStart || !isMaxStop) {\n let date;\n\n // If start is min time just start at midnight this morning, local time\n if (isMinStart) {\n date = new Date();\n date.setHours(0, 0, 0, 0);\n start = JulianDate.fromDate(date);\n }\n\n // If stop is max value just stop at midnight tonight, local time\n if (isMaxStop) {\n date = new Date();\n date.setHours(24, 0, 0, 0);\n stop = JulianDate.fromDate(date);\n }\n\n clock = new DataSourceClock();\n clock.startTime = start;\n clock.stopTime = stop;\n clock.currentTime = JulianDate.clone(start);\n clock.clockRange = ClockRange.LOOP_STOP;\n clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n clock.multiplier = Math.round(\n Math.min(\n Math.max(JulianDate.secondsDifference(stop, start) / 60, 1),\n 3.15569e7\n )\n );\n }\n let changed = false;\n if (dataSource._name !== name) {\n dataSource._name = name;\n changed = true;\n }\n\n if (dataSource._creator !== creator) {\n dataSource._creator = creator;\n changed = true;\n }\n\n if (metadataChanged(dataSource._metadata, metadata)) {\n dataSource._metadata = metadata;\n changed = true;\n }\n\n if (dataSource._version !== version) {\n dataSource._version = version;\n changed = true;\n }\n\n if (clock !== dataSource._clock) {\n changed = true;\n dataSource._clock = clock;\n }\n\n if (changed) {\n dataSource._changed.raiseEvent(dataSource);\n }\n\n DataSource.setLoading(dataSource, false);\n return dataSource;\n}\n\nfunction metadataChanged(old, current) {\n if (!defined(old) && !defined(current)) {\n return false;\n } else if (defined(old) && defined(current)) {\n if (\n old.name !== current.name ||\n old.dec !== current.desc ||\n old.src !== current.src ||\n old.author !== current.author ||\n old.copyright !== current.copyright ||\n old.link !== current.link ||\n old.time !== current.time ||\n old.bounds !== current.bounds\n ) {\n return true;\n }\n return false;\n }\n return true;\n}\n\nfunction load(dataSource, entityCollection, data, options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n let promise = data;\n if (typeof data === \"string\" || data instanceof Resource) {\n data = Resource.createIfNeeded(data);\n promise = data.fetchBlob();\n\n // Add resource credits to our list of credits to display\n const resourceCredits = dataSource._resourceCredits;\n const credits = data.credits;\n if (defined(credits)) {\n const length = credits.length;\n for (let i = 0; i < length; i++) {\n resourceCredits.push(credits[i]);\n }\n }\n }\n\n return Promise.resolve(promise)\n .then(function (dataToLoad) {\n if (dataToLoad instanceof Blob) {\n return readBlobAsText(dataToLoad).then(function (text) {\n // There's no official way to validate if a parse was successful.\n // The following check detects the error on various browsers.\n // IE raises an exception\n let gpx;\n let error;\n try {\n gpx = parser.parseFromString(text, \"application/xml\");\n } catch (e) {\n error = e.toString();\n }\n\n // The parse succeeds on Chrome and Firefox, but the error\n // handling is different in each.\n if (\n defined(error) ||\n gpx.body ||\n gpx.documentElement.tagName === \"parsererror\"\n ) {\n // Firefox has error information as the firstChild nodeValue.\n let msg = defined(error)\n ? error\n : gpx.documentElement.firstChild.nodeValue;\n\n // Chrome has it in the body text.\n if (!msg) {\n msg = gpx.body.innerText;\n }\n\n // Return the error\n throw new RuntimeError(msg);\n }\n return loadGpx(dataSource, gpx, options);\n });\n }\n return loadGpx(dataSource, dataToLoad, options);\n })\n .catch(function (error) {\n dataSource._error.raiseEvent(dataSource, error);\n console.log(error);\n return Promise.reject(error);\n });\n}\n\n/**\n * A {@link DataSource} which processes the GPS Exchange Format (GPX).\n *\n * @alias GpxDataSource\n * @constructor\n *\n * @see {@link http://www.topografix.com/gpx.asp|Topografix GPX Standard}\n * @see {@link http://www.topografix.com/gpx/1/1/|Topografix GPX Documentation}\n *\n * @demo {@link http://sandcastle.cesium.com/index.html?src=GPX.html}\n *\n * @example\n * const viewer = new Cesium.Viewer('cesiumContainer');\n * viewer.dataSources.add(Cesium.GpxDataSource.load('../../SampleData/track.gpx'));\n */\nfunction GpxDataSource() {\n this._changed = new Event();\n this._error = new Event();\n this._loading = new Event();\n this._clock = undefined;\n this._entityCollection = new EntityCollection(this);\n this._entityCluster = new EntityCluster();\n this._name = undefined;\n this._version = undefined;\n this._creator = undefined;\n this._metadata = undefined;\n this._isLoading = false;\n this._pinBuilder = new PinBuilder();\n}\n\n/**\n * Creates a Promise to a new instance loaded with the provided GPX data.\n *\n * @param {string|Document|Blob} data A url, parsed GPX document, or Blob containing binary GPX data.\n * @param {object} [options] An object with the following properties:\n * @param {boolean} [options.clampToGround] True if the symbols should be rendered at the same height as the terrain\n * @param {string} [options.waypointImage] Image to use for waypoint billboards.\n * @param {string} [options.trackImage] Image to use for track billboards.\n * @param {string} [options.trackColor] Color to use for track lines.\n * @param {string} [options.routeColor] Color to use for route lines.\n * @returns {Promise} A promise that will resolve to a new GpxDataSource instance once the gpx is loaded.\n */\nGpxDataSource.load = function (data, options) {\n return new GpxDataSource().load(data, options);\n};\n\nObject.defineProperties(GpxDataSource.prototype, {\n /**\n * Gets a human-readable name for this instance.\n * This will be automatically be set to the GPX document name on load.\n * @memberof GpxDataSource.prototype\n * @type {string}\n */\n name: {\n get: function () {\n return this._name;\n },\n },\n /**\n * Gets the version of the GPX Schema in use.\n * @memberof GpxDataSource.prototype\n * @type {string}\n */\n version: {\n get: function () {\n return this._version;\n },\n },\n /**\n * Gets the creator of the GPX document.\n * @memberof GpxDataSource.prototype\n * @type {string}\n */\n creator: {\n get: function () {\n return this._creator;\n },\n },\n /**\n * Gets an object containing metadata about the GPX file.\n * @memberof GpxDataSource.prototype\n * @type {object}\n */\n metadata: {\n get: function () {\n return this._metadata;\n },\n },\n /**\n * Gets the clock settings defined by the loaded GPX. This represents the total\n * availability interval for all time-dynamic data. If the GPX does not contain\n * time-dynamic data, this value is undefined.\n * @memberof GpxDataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n get: function () {\n return this._clock;\n },\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof GpxDataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: function () {\n return this._entityCollection;\n },\n },\n /**\n * Gets a value indicating if the data source is currently loading data.\n * @memberof GpxDataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: function () {\n return this._isLoading;\n },\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof GpxDataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: function () {\n return this._changed;\n },\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof GpxDataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: function () {\n return this._error;\n },\n },\n /**\n * Gets an event that will be raised when the data source either starts or stops loading.\n * @memberof GpxDataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: function () {\n return this._loading;\n },\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof GpxDataSource.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._entityCollection.show;\n },\n set: function (value) {\n this._entityCollection.show = value;\n },\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof GpxDataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: function () {\n return this._entityCluster;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value must be defined.\");\n }\n //>>includeEnd('debug');\n this._entityCluster = value;\n },\n },\n});\n\n/**\n * Updates the data source to the provided time. This function is optional and\n * is not required to be implemented. It is provided for data sources which\n * retrieve data based on the current animation time or scene state.\n * If implemented, update will be called by {@link DataSourceDisplay} once a frame.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nGpxDataSource.prototype.update = function (time) {\n return true;\n};\n\n/**\n * Asynchronously loads the provided GPX data, replacing any existing data.\n *\n * @param {string|Document|Blob} data A url, parsed GPX document, or Blob containing binary GPX data or a parsed GPX document.\n * @param {object} [options] An object with the following properties:\n * @param {boolean} [options.clampToGround] True if the symbols should be rendered at the same height as the terrain\n * @param {string} [options.waypointImage] Image to use for waypoint billboards.\n * @param {string} [options.trackImage] Image to use for track billboards.\n * @param {string} [options.trackColor] Color to use for track lines.\n * @param {string} [options.routeColor] Color to use for route lines.\n * @returns {Promise} A promise that will resolve to this instances once the GPX is loaded.\n */\nGpxDataSource.prototype.load = function (data, options) {\n if (!defined(data)) {\n throw new DeveloperError(\"data is required.\");\n }\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n DataSource.setLoading(this, true);\n const oldName = this._name;\n const that = this;\n return load(this, this._entityCollection, data, options)\n .then(function () {\n let clock;\n\n const availability = that._entityCollection.computeAvailability();\n\n let start = availability.start;\n let stop = availability.stop;\n const isMinStart = JulianDate.equals(start, Iso8601.MINIMUM_VALUE);\n const isMaxStop = JulianDate.equals(stop, Iso8601.MAXIMUM_VALUE);\n if (!isMinStart || !isMaxStop) {\n let date;\n\n // If start is min time just start at midnight this morning, local time\n if (isMinStart) {\n date = new Date();\n date.setHours(0, 0, 0, 0);\n start = JulianDate.fromDate(date);\n }\n\n // If stop is max value just stop at midnight tonight, local time\n if (isMaxStop) {\n date = new Date();\n date.setHours(24, 0, 0, 0);\n stop = JulianDate.fromDate(date);\n }\n\n clock = new DataSourceClock();\n clock.startTime = start;\n clock.stopTime = stop;\n clock.currentTime = JulianDate.clone(start);\n clock.clockRange = ClockRange.LOOP_STOP;\n clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n clock.multiplier = Math.round(\n Math.min(\n Math.max(JulianDate.secondsDifference(stop, start) / 60, 1),\n 3.15569e7\n )\n );\n }\n\n let changed = false;\n if (clock !== that._clock) {\n that._clock = clock;\n changed = true;\n }\n\n if (oldName !== that._name) {\n changed = true;\n }\n\n if (changed) {\n that._changed.raiseEvent(that);\n }\n\n DataSource.setLoading(that, false);\n\n return that;\n })\n .catch(function (error) {\n DataSource.setLoading(that, false);\n that._error.raiseEvent(that, error);\n console.log(error);\n return Promise.reject(error);\n });\n};\n\nexport default GpxDataSource;\n", "/**\n * Representation of from KML\n * @alias KmlCamera\n * @constructor\n *\n * @param {Cartesian3} position camera position\n * @param {HeadingPitchRoll} headingPitchRoll camera orientation\n */\nfunction KmlCamera(position, headingPitchRoll) {\n this.position = position;\n this.headingPitchRoll = headingPitchRoll;\n}\nexport default KmlCamera;\n", "import ArcType from \"../Core/ArcType.js\";\nimport AssociativeArray from \"../Core/AssociativeArray.js\";\nimport BoundingRectangle from \"../Core/BoundingRectangle.js\";\nimport buildModuleUrl from \"../Core/buildModuleUrl.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport ClockRange from \"../Core/ClockRange.js\";\nimport ClockStep from \"../Core/ClockStep.js\";\nimport clone from \"../Core/clone.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport Credit from \"../Core/Credit.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defer from \"../Core/defer.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Event from \"../Core/Event.js\";\nimport getExtensionFromUri from \"../Core/getExtensionFromUri.js\";\nimport getFilenameFromUri from \"../Core/getFilenameFromUri.js\";\nimport getTimestamp from \"../Core/getTimestamp.js\";\nimport HeadingPitchRange from \"../Core/HeadingPitchRange.js\";\nimport HeadingPitchRoll from \"../Core/HeadingPitchRoll.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport NearFarScalar from \"../Core/NearFarScalar.js\";\nimport objectToQuery from \"../Core/objectToQuery.js\";\nimport oneTimeWarning from \"../Core/oneTimeWarning.js\";\nimport PinBuilder from \"../Core/PinBuilder.js\";\nimport PolygonHierarchy from \"../Core/PolygonHierarchy.js\";\nimport queryToObject from \"../Core/queryToObject.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport LabelStyle from \"../Scene/LabelStyle.js\";\nimport SceneMode from \"../Scene/SceneMode.js\";\nimport Autolinker from \"autolinker\";\nimport Uri from \"urijs\";\nimport * as zip from \"@zip.js/zip.js/lib/zip-no-worker.js\";\nimport getElement from \"./getElement.js\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport CompositePositionProperty from \"./CompositePositionProperty.js\";\nimport DataSource from \"./DataSource.js\";\nimport DataSourceClock from \"./DataSourceClock.js\";\nimport Entity from \"./Entity.js\";\nimport EntityCluster from \"./EntityCluster.js\";\nimport EntityCollection from \"./EntityCollection.js\";\nimport KmlCamera from \"./KmlCamera.js\";\nimport KmlLookAt from \"./KmlLookAt.js\";\nimport KmlTour from \"./KmlTour.js\";\nimport KmlTourFlyTo from \"./KmlTourFlyTo.js\";\nimport KmlTourWait from \"./KmlTourWait.js\";\nimport LabelGraphics from \"./LabelGraphics.js\";\nimport PathGraphics from \"./PathGraphics.js\";\nimport PolygonGraphics from \"./PolygonGraphics.js\";\nimport PolylineGraphics from \"./PolylineGraphics.js\";\nimport PositionPropertyArray from \"./PositionPropertyArray.js\";\nimport RectangleGraphics from \"./RectangleGraphics.js\";\nimport ReferenceProperty from \"./ReferenceProperty.js\";\nimport SampledPositionProperty from \"./SampledPositionProperty.js\";\nimport ScaledPositionProperty from \"./ScaledPositionProperty.js\";\nimport TimeIntervalCollectionProperty from \"./TimeIntervalCollectionProperty.js\";\nimport WallGraphics from \"./WallGraphics.js\";\n\n//This is by no means an exhaustive list of MIME types.\n//The purpose of this list is to be able to accurately identify content embedded\n//in KMZ files. Eventually, we can make this configurable by the end user so they can add\n//there own content types if they have KMZ files that require it.\nconst MimeTypes = {\n avi: \"video/x-msvideo\",\n bmp: \"image/bmp\",\n bz2: \"application/x-bzip2\",\n chm: \"application/vnd.ms-htmlhelp\",\n css: \"text/css\",\n csv: \"text/csv\",\n doc: \"application/msword\",\n dvi: \"application/x-dvi\",\n eps: \"application/postscript\",\n flv: \"video/x-flv\",\n gif: \"image/gif\",\n gz: \"application/x-gzip\",\n htm: \"text/html\",\n html: \"text/html\",\n ico: \"image/vnd.microsoft.icon\",\n jnlp: \"application/x-java-jnlp-file\",\n jpeg: \"image/jpeg\",\n jpg: \"image/jpeg\",\n m3u: \"audio/x-mpegurl\",\n m4v: \"video/mp4\",\n mathml: \"application/mathml+xml\",\n mid: \"audio/midi\",\n midi: \"audio/midi\",\n mov: \"video/quicktime\",\n mp3: \"audio/mpeg\",\n mp4: \"video/mp4\",\n mp4v: \"video/mp4\",\n mpeg: \"video/mpeg\",\n mpg: \"video/mpeg\",\n odp: \"application/vnd.oasis.opendocument.presentation\",\n ods: \"application/vnd.oasis.opendocument.spreadsheet\",\n odt: \"application/vnd.oasis.opendocument.text\",\n ogg: \"application/ogg\",\n pdf: \"application/pdf\",\n png: \"image/png\",\n pps: \"application/vnd.ms-powerpoint\",\n ppt: \"application/vnd.ms-powerpoint\",\n ps: \"application/postscript\",\n qt: \"video/quicktime\",\n rdf: \"application/rdf+xml\",\n rss: \"application/rss+xml\",\n rtf: \"application/rtf\",\n svg: \"image/svg+xml\",\n swf: \"application/x-shockwave-flash\",\n text: \"text/plain\",\n tif: \"image/tiff\",\n tiff: \"image/tiff\",\n txt: \"text/plain\",\n wav: \"audio/x-wav\",\n wma: \"audio/x-ms-wma\",\n wmv: \"video/x-ms-wmv\",\n xml: \"application/xml\",\n zip: \"application/zip\",\n\n detectFromFilename: function (filename) {\n let ext = filename.toLowerCase();\n ext = getExtensionFromUri(ext);\n return MimeTypes[ext];\n },\n};\n\nlet parser;\nif (typeof DOMParser !== \"undefined\") {\n parser = new DOMParser();\n}\n\nconst autolinker = new Autolinker({\n stripPrefix: false,\n email: false,\n replaceFn: function (match) {\n //Prevent matching of non-explicit urls.\n //i.e. foo.id won't match but http://foo.id will\n return match.urlMatchType === \"scheme\" || match.urlMatchType === \"www\";\n },\n});\n\nconst BILLBOARD_SIZE = 32;\n\nconst BILLBOARD_NEAR_DISTANCE = 2414016;\nconst BILLBOARD_NEAR_RATIO = 1.0;\nconst BILLBOARD_FAR_DISTANCE = 1.6093e7;\nconst BILLBOARD_FAR_RATIO = 0.1;\n\nconst kmlNamespaces = [\n null,\n undefined,\n \"http://www.opengis.net/kml/2.2\",\n \"http://earth.google.com/kml/2.2\",\n \"http://earth.google.com/kml/2.1\",\n \"http://earth.google.com/kml/2.0\",\n];\nconst gxNamespaces = [\"http://www.google.com/kml/ext/2.2\"];\nconst atomNamespaces = [\"http://www.w3.org/2005/Atom\"];\nconst namespaces = {\n kml: kmlNamespaces,\n gx: gxNamespaces,\n atom: atomNamespaces,\n kmlgx: kmlNamespaces.concat(gxNamespaces),\n};\n\n// Ensure Specs/Data/KML/unsupported.kml is kept up to date with these supported types\nconst featureTypes = {\n Document: processDocument,\n Folder: processFolder,\n Placemark: processPlacemark,\n NetworkLink: processNetworkLink,\n GroundOverlay: processGroundOverlay,\n PhotoOverlay: processUnsupportedFeature,\n ScreenOverlay: processScreenOverlay,\n Tour: processTour,\n};\n\nfunction DeferredLoading(dataSource) {\n this._dataSource = dataSource;\n this._deferred = defer();\n this._stack = [];\n this._promises = [];\n this._timeoutSet = false;\n this._used = false;\n\n this._started = 0;\n this._timeThreshold = 1000; // Initial load is 1 second\n}\n\nObject.defineProperties(DeferredLoading.prototype, {\n dataSource: {\n get: function () {\n return this._dataSource;\n },\n },\n});\n\nDeferredLoading.prototype.addNodes = function (nodes, processingData) {\n this._stack.push({\n nodes: nodes,\n index: 0,\n processingData: processingData,\n });\n this._used = true;\n};\n\nDeferredLoading.prototype.addPromise = function (promise) {\n this._promises.push(promise);\n};\n\nDeferredLoading.prototype.wait = function () {\n // Case where we had a non-document/folder as the root\n const deferred = this._deferred;\n if (!this._used) {\n deferred.resolve();\n }\n\n return Promise.all([deferred.promise, Promise.all(this._promises)]);\n};\n\nDeferredLoading.prototype.process = function () {\n const isFirstCall = this._stack.length === 1;\n if (isFirstCall) {\n this._started = KmlDataSource._getTimestamp();\n }\n\n return this._process(isFirstCall);\n};\n\nDeferredLoading.prototype._giveUpTime = function () {\n if (this._timeoutSet) {\n // Timeout was already set so just return\n return;\n }\n\n this._timeoutSet = true;\n this._timeThreshold = 50; // After the first load lower threshold to 0.5 seconds\n const that = this;\n setTimeout(function () {\n that._timeoutSet = false;\n that._started = KmlDataSource._getTimestamp();\n that._process(true);\n }, 0);\n};\n\nDeferredLoading.prototype._nextNode = function () {\n const stack = this._stack;\n const top = stack[stack.length - 1];\n const index = top.index;\n const nodes = top.nodes;\n if (index === nodes.length) {\n return;\n }\n ++top.index;\n\n return nodes[index];\n};\n\nDeferredLoading.prototype._pop = function () {\n const stack = this._stack;\n stack.pop();\n\n // Return false if we are done\n if (stack.length === 0) {\n this._deferred.resolve();\n return false;\n }\n\n return true;\n};\n\nDeferredLoading.prototype._process = function (isFirstCall) {\n const dataSource = this.dataSource;\n const processingData = this._stack[this._stack.length - 1].processingData;\n\n let child = this._nextNode();\n while (defined(child)) {\n const featureProcessor = featureTypes[child.localName];\n if (\n defined(featureProcessor) &&\n (namespaces.kml.indexOf(child.namespaceURI) !== -1 ||\n namespaces.gx.indexOf(child.namespaceURI) !== -1)\n ) {\n featureProcessor(dataSource, child, processingData, this);\n\n // Give up time and continue loading later\n if (\n this._timeoutSet ||\n KmlDataSource._getTimestamp() > this._started + this._timeThreshold\n ) {\n this._giveUpTime();\n return;\n }\n }\n\n child = this._nextNode();\n }\n\n // If we are a recursive call from a subfolder, just return so the parent folder can continue processing\n // If we aren't then make another call to processNodes because there is stuff still left in the queue\n if (this._pop() && isFirstCall) {\n this._process(true);\n }\n};\n\nfunction isZipFile(blob) {\n const magicBlob = blob.slice(0, Math.min(4, blob.size));\n const deferred = defer();\n const reader = new FileReader();\n reader.addEventListener(\"load\", function () {\n deferred.resolve(\n new DataView(reader.result).getUint32(0, false) === 0x504b0304\n );\n });\n reader.addEventListener(\"error\", function () {\n deferred.reject(reader.error);\n });\n reader.readAsArrayBuffer(magicBlob);\n return deferred.promise;\n}\n\nfunction readBlobAsText(blob) {\n const deferred = defer();\n const reader = new FileReader();\n reader.addEventListener(\"load\", function () {\n deferred.resolve(reader.result);\n });\n reader.addEventListener(\"error\", function () {\n deferred.reject(reader.error);\n });\n reader.readAsText(blob);\n return deferred.promise;\n}\n\nfunction insertNamespaces(text) {\n const namespaceMap = {\n xsi: \"http://www.w3.org/2001/XMLSchema-instance\",\n };\n let firstPart, lastPart, reg, declaration;\n\n for (const key in namespaceMap) {\n if (namespaceMap.hasOwnProperty(key)) {\n reg = RegExp(`[< ]${key}:`);\n declaration = `xmlns:${key}=`;\n if (reg.test(text) && text.indexOf(declaration) === -1) {\n if (!defined(firstPart)) {\n firstPart = text.substr(0, text.indexOf(\"\", index);\n let namespace, startIndex, endIndex;\n\n while (index !== -1 && index < endDeclaration) {\n namespace = text.slice(index, text.indexOf('\"', index));\n startIndex = index;\n index = text.indexOf(namespace, index + 1);\n if (index !== -1) {\n endIndex = text.indexOf('\"', text.indexOf('\"', index) + 1);\n text = text.slice(0, index - 1) + text.slice(endIndex + 1, text.length);\n index = text.indexOf(\"xmlns:\", startIndex - 1);\n } else {\n index = text.indexOf(\"xmlns:\", startIndex + 1);\n }\n }\n\n return text;\n}\n\nfunction loadXmlFromZip(entry, uriResolver) {\n return Promise.resolve(entry.getData(new zip.TextWriter())).then(function (\n text\n ) {\n text = insertNamespaces(text);\n text = removeDuplicateNamespaces(text);\n uriResolver.kml = parser.parseFromString(text, \"application/xml\");\n });\n}\n\nfunction loadDataUriFromZip(entry, uriResolver) {\n const mimeType = defaultValue(\n MimeTypes.detectFromFilename(entry.filename),\n \"application/octet-stream\"\n );\n return Promise.resolve(entry.getData(new zip.Data64URIWriter(mimeType))).then(\n function (dataUri) {\n uriResolver[entry.filename] = dataUri;\n }\n );\n}\n\nfunction embedDataUris(div, elementType, attributeName, uriResolver) {\n const keys = uriResolver.keys;\n const baseUri = new Uri(\".\");\n const elements = div.querySelectorAll(elementType);\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n const value = element.getAttribute(attributeName);\n if (defined(value)) {\n const relativeUri = new Uri(value);\n const uri = relativeUri.absoluteTo(baseUri).toString();\n const index = keys.indexOf(uri);\n if (index !== -1) {\n const key = keys[index];\n element.setAttribute(attributeName, uriResolver[key]);\n if (elementType === \"a\" && element.getAttribute(\"download\") === null) {\n element.setAttribute(\"download\", key);\n }\n }\n }\n }\n}\n\nfunction applyBasePath(div, elementType, attributeName, sourceResource) {\n const elements = div.querySelectorAll(elementType);\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n const value = element.getAttribute(attributeName);\n const resource = resolveHref(value, sourceResource);\n if (defined(resource)) {\n element.setAttribute(attributeName, resource.url);\n }\n }\n}\n\n// an optional context is passed to allow for some malformed kmls (those with multiple geometries with same ids) to still parse\n// correctly, as they do in Google Earth.\nfunction createEntity(node, entityCollection, context) {\n let id = queryStringAttribute(node, \"id\");\n id = defined(id) && id.length !== 0 ? id : createGuid();\n if (defined(context)) {\n id = context + id;\n }\n\n // If we have a duplicate ID just generate one.\n // This isn't valid KML but Google Earth handles this case.\n let entity = entityCollection.getById(id);\n if (defined(entity)) {\n id = createGuid();\n if (defined(context)) {\n id = context + id;\n }\n }\n\n entity = entityCollection.add(new Entity({ id: id }));\n if (!defined(entity.kml)) {\n entity.addProperty(\"kml\");\n entity.kml = new KmlFeatureData();\n }\n return entity;\n}\n\nfunction isExtrudable(altitudeMode, gxAltitudeMode) {\n return (\n altitudeMode === \"absolute\" ||\n altitudeMode === \"relativeToGround\" ||\n gxAltitudeMode === \"relativeToSeaFloor\"\n );\n}\n\nfunction readCoordinate(value, ellipsoid) {\n //Google Earth treats empty or missing coordinates as 0.\n if (!defined(value)) {\n return Cartesian3.fromDegrees(0, 0, 0, ellipsoid);\n }\n\n const digits = value.match(/[^\\s,\\n]+/g);\n if (!defined(digits)) {\n return Cartesian3.fromDegrees(0, 0, 0, ellipsoid);\n }\n\n let longitude = parseFloat(digits[0]);\n let latitude = parseFloat(digits[1]);\n let height = parseFloat(digits[2]);\n\n longitude = isNaN(longitude) ? 0.0 : longitude;\n latitude = isNaN(latitude) ? 0.0 : latitude;\n height = isNaN(height) ? 0.0 : height;\n\n return Cartesian3.fromDegrees(longitude, latitude, height, ellipsoid);\n}\n\nfunction readCoordinates(element, ellipsoid) {\n if (!defined(element)) {\n return undefined;\n }\n\n const tuples = element.textContent.match(/[^\\s\\n]+/g);\n if (!defined(tuples)) {\n return undefined;\n }\n\n const length = tuples.length;\n const result = new Array(length);\n let resultIndex = 0;\n for (let i = 0; i < length; i++) {\n result[resultIndex++] = readCoordinate(tuples[i], ellipsoid);\n }\n return result;\n}\n\nfunction queryNumericAttribute(node, attributeName) {\n if (!defined(node)) {\n return undefined;\n }\n\n const value = node.getAttribute(attributeName);\n if (value !== null) {\n const result = parseFloat(value);\n return !isNaN(result) ? result : undefined;\n }\n return undefined;\n}\n\nfunction queryStringAttribute(node, attributeName) {\n if (!defined(node)) {\n return undefined;\n }\n const value = node.getAttribute(attributeName);\n return value !== null ? value : undefined;\n}\n\nfunction queryFirstNode(node, tagName, namespace) {\n if (!defined(node)) {\n return undefined;\n }\n const childNodes = node.childNodes;\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === tagName &&\n namespace.indexOf(child.namespaceURI) !== -1\n ) {\n return child;\n }\n }\n return undefined;\n}\n\nfunction queryNodes(node, tagName, namespace) {\n if (!defined(node)) {\n return undefined;\n }\n const result = [];\n const childNodes = node.getElementsByTagNameNS(\"*\", tagName);\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === tagName &&\n namespace.indexOf(child.namespaceURI) !== -1\n ) {\n result.push(child);\n }\n }\n return result;\n}\n\nfunction queryChildNodes(node, tagName, namespace) {\n if (!defined(node)) {\n return [];\n }\n const result = [];\n const childNodes = node.childNodes;\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (\n child.localName === tagName &&\n namespace.indexOf(child.namespaceURI) !== -1\n ) {\n result.push(child);\n }\n }\n return result;\n}\n\nfunction queryNumericValue(node, tagName, namespace) {\n const resultNode = queryFirstNode(node, tagName, namespace);\n if (defined(resultNode)) {\n const result = parseFloat(resultNode.textContent);\n return !isNaN(result) ? result : undefined;\n }\n return undefined;\n}\n\nfunction queryStringValue(node, tagName, namespace) {\n const result = queryFirstNode(node, tagName, namespace);\n if (defined(result)) {\n return result.textContent.trim();\n }\n return undefined;\n}\n\nfunction queryBooleanValue(node, tagName, namespace) {\n const result = queryFirstNode(node, tagName, namespace);\n if (defined(result)) {\n const value = result.textContent.trim();\n return value === \"1\" || /^true$/i.test(value);\n }\n return undefined;\n}\n\nfunction resolveHref(href, sourceResource, uriResolver) {\n if (!defined(href)) {\n return undefined;\n }\n\n let resource;\n if (defined(uriResolver)) {\n // To resolve issues with KML sources defined in Windows style paths.\n href = href.replace(/\\\\/g, \"/\");\n let blob = uriResolver[href];\n if (defined(blob)) {\n resource = new Resource({\n url: blob,\n });\n } else {\n // Needed for multiple levels of KML files in a KMZ\n const baseUri = new Uri(sourceResource.getUrlComponent());\n const uri = new Uri(href);\n blob = uriResolver[uri.absoluteTo(baseUri)];\n if (defined(blob)) {\n resource = new Resource({\n url: blob,\n });\n }\n }\n }\n\n if (!defined(resource)) {\n resource = sourceResource.getDerivedResource({\n url: href,\n });\n }\n\n return resource;\n}\n\nconst colorOptions = {\n maximumRed: undefined,\n red: undefined,\n maximumGreen: undefined,\n green: undefined,\n maximumBlue: undefined,\n blue: undefined,\n};\n\nfunction parseColorString(value, isRandom) {\n if (!defined(value) || /^\\s*$/gm.test(value)) {\n return undefined;\n }\n\n if (value[0] === \"#\") {\n value = value.substring(1);\n }\n\n const alpha = parseInt(value.substring(0, 2), 16) / 255.0;\n const blue = parseInt(value.substring(2, 4), 16) / 255.0;\n const green = parseInt(value.substring(4, 6), 16) / 255.0;\n const red = parseInt(value.substring(6, 8), 16) / 255.0;\n\n if (!isRandom) {\n return new Color(red, green, blue, alpha);\n }\n\n if (red > 0) {\n colorOptions.maximumRed = red;\n colorOptions.red = undefined;\n } else {\n colorOptions.maximumRed = undefined;\n colorOptions.red = 0;\n }\n if (green > 0) {\n colorOptions.maximumGreen = green;\n colorOptions.green = undefined;\n } else {\n colorOptions.maximumGreen = undefined;\n colorOptions.green = 0;\n }\n if (blue > 0) {\n colorOptions.maximumBlue = blue;\n colorOptions.blue = undefined;\n } else {\n colorOptions.maximumBlue = undefined;\n colorOptions.blue = 0;\n }\n colorOptions.alpha = alpha;\n return Color.fromRandom(colorOptions);\n}\n\nfunction queryColorValue(node, tagName, namespace) {\n const value = queryStringValue(node, tagName, namespace);\n if (!defined(value)) {\n return undefined;\n }\n return parseColorString(\n value,\n queryStringValue(node, \"colorMode\", namespace) === \"random\"\n );\n}\n\nfunction processTimeStamp(featureNode) {\n const node = queryFirstNode(featureNode, \"TimeStamp\", namespaces.kmlgx);\n const whenString = queryStringValue(node, \"when\", namespaces.kmlgx);\n\n if (!defined(node) || !defined(whenString) || whenString.length === 0) {\n return undefined;\n }\n\n //According to the KML spec, a TimeStamp represents a \"single moment in time\"\n //However, since Cesium animates much differently than Google Earth, that doesn't\n //Make much sense here. Instead, we use the TimeStamp as the moment the feature\n //comes into existence. This works much better and gives a similar feel to\n //GE's experience.\n const when = JulianDate.fromIso8601(whenString);\n const result = new TimeIntervalCollection();\n result.addInterval(\n new TimeInterval({\n start: when,\n stop: Iso8601.MAXIMUM_VALUE,\n })\n );\n return result;\n}\n\nfunction processTimeSpan(featureNode) {\n const node = queryFirstNode(featureNode, \"TimeSpan\", namespaces.kmlgx);\n if (!defined(node)) {\n return undefined;\n }\n let result;\n\n const beginNode = queryFirstNode(node, \"begin\", namespaces.kmlgx);\n let beginDate = defined(beginNode)\n ? JulianDate.fromIso8601(beginNode.textContent)\n : undefined;\n\n const endNode = queryFirstNode(node, \"end\", namespaces.kmlgx);\n let endDate = defined(endNode)\n ? JulianDate.fromIso8601(endNode.textContent)\n : undefined;\n\n if (defined(beginDate) && defined(endDate)) {\n if (JulianDate.lessThan(endDate, beginDate)) {\n const tmp = beginDate;\n beginDate = endDate;\n endDate = tmp;\n }\n result = new TimeIntervalCollection();\n result.addInterval(\n new TimeInterval({\n start: beginDate,\n stop: endDate,\n })\n );\n } else if (defined(beginDate)) {\n result = new TimeIntervalCollection();\n result.addInterval(\n new TimeInterval({\n start: beginDate,\n stop: Iso8601.MAXIMUM_VALUE,\n })\n );\n } else if (defined(endDate)) {\n result = new TimeIntervalCollection();\n result.addInterval(\n new TimeInterval({\n start: Iso8601.MINIMUM_VALUE,\n stop: endDate,\n })\n );\n }\n\n return result;\n}\n\nfunction createDefaultBillboard() {\n const billboard = new BillboardGraphics();\n billboard.width = BILLBOARD_SIZE;\n billboard.height = BILLBOARD_SIZE;\n billboard.scaleByDistance = new NearFarScalar(\n BILLBOARD_NEAR_DISTANCE,\n BILLBOARD_NEAR_RATIO,\n BILLBOARD_FAR_DISTANCE,\n BILLBOARD_FAR_RATIO\n );\n billboard.pixelOffsetScaleByDistance = new NearFarScalar(\n BILLBOARD_NEAR_DISTANCE,\n BILLBOARD_NEAR_RATIO,\n BILLBOARD_FAR_DISTANCE,\n BILLBOARD_FAR_RATIO\n );\n return billboard;\n}\n\nfunction createDefaultPolygon() {\n const polygon = new PolygonGraphics();\n polygon.outline = true;\n polygon.outlineColor = Color.WHITE;\n return polygon;\n}\n\nfunction createDefaultLabel() {\n const label = new LabelGraphics();\n label.translucencyByDistance = new NearFarScalar(3000000, 1.0, 5000000, 0.0);\n label.pixelOffset = new Cartesian2(17, 0);\n label.horizontalOrigin = HorizontalOrigin.LEFT;\n label.font = \"16px sans-serif\";\n label.style = LabelStyle.FILL_AND_OUTLINE;\n return label;\n}\n\nfunction getIconHref(\n iconNode,\n dataSource,\n sourceResource,\n uriResolver,\n canRefresh\n) {\n let href = queryStringValue(iconNode, \"href\", namespaces.kml);\n if (!defined(href) || href.length === 0) {\n return undefined;\n }\n\n if (href.indexOf(\"root://icons/palette-\") === 0) {\n const palette = href.charAt(21);\n\n // Get the icon number\n let x = defaultValue(queryNumericValue(iconNode, \"x\", namespaces.gx), 0);\n let y = defaultValue(queryNumericValue(iconNode, \"y\", namespaces.gx), 0);\n x = Math.min(x / 32, 7);\n y = 7 - Math.min(y / 32, 7);\n const iconNum = 8 * y + x;\n\n href = `https://maps.google.com/mapfiles/kml/pal${palette}/icon${iconNum}.png`;\n }\n\n const hrefResource = resolveHref(href, sourceResource, uriResolver);\n\n if (canRefresh) {\n const refreshMode = queryStringValue(\n iconNode,\n \"refreshMode\",\n namespaces.kml\n );\n const viewRefreshMode = queryStringValue(\n iconNode,\n \"viewRefreshMode\",\n namespaces.kml\n );\n if (refreshMode === \"onInterval\" || refreshMode === \"onExpire\") {\n oneTimeWarning(\n `kml-refreshMode-${refreshMode}`,\n `KML - Unsupported Icon refreshMode: ${refreshMode}`\n );\n } else if (viewRefreshMode === \"onStop\" || viewRefreshMode === \"onRegion\") {\n oneTimeWarning(\n `kml-refreshMode-${viewRefreshMode}`,\n `KML - Unsupported Icon viewRefreshMode: ${viewRefreshMode}`\n );\n }\n\n const viewBoundScale = defaultValue(\n queryStringValue(iconNode, \"viewBoundScale\", namespaces.kml),\n 1.0\n );\n const defaultViewFormat =\n viewRefreshMode === \"onStop\"\n ? \"BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]\"\n : \"\";\n const viewFormat = defaultValue(\n queryStringValue(iconNode, \"viewFormat\", namespaces.kml),\n defaultViewFormat\n );\n const httpQuery = queryStringValue(iconNode, \"httpQuery\", namespaces.kml);\n if (defined(viewFormat)) {\n hrefResource.setQueryParameters(queryToObject(cleanupString(viewFormat)));\n }\n if (defined(httpQuery)) {\n hrefResource.setQueryParameters(queryToObject(cleanupString(httpQuery)));\n }\n\n const ellipsoid = dataSource._ellipsoid;\n processNetworkLinkQueryString(\n hrefResource,\n dataSource.camera,\n dataSource.canvas,\n viewBoundScale,\n dataSource._lastCameraView.bbox,\n ellipsoid\n );\n\n return hrefResource;\n }\n\n return hrefResource;\n}\n\nfunction processBillboardIcon(\n dataSource,\n node,\n targetEntity,\n sourceResource,\n uriResolver\n) {\n let scale = queryNumericValue(node, \"scale\", namespaces.kml);\n const heading = queryNumericValue(node, \"heading\", namespaces.kml);\n const color = queryColorValue(node, \"color\", namespaces.kml);\n\n const iconNode = queryFirstNode(node, \"Icon\", namespaces.kml);\n let icon = getIconHref(\n iconNode,\n dataSource,\n sourceResource,\n uriResolver,\n false\n );\n\n // If icon tags are present but blank, we do not want to show an icon\n if (defined(iconNode) && !defined(icon)) {\n icon = false;\n }\n\n const x = queryNumericValue(iconNode, \"x\", namespaces.gx);\n const y = queryNumericValue(iconNode, \"y\", namespaces.gx);\n const w = queryNumericValue(iconNode, \"w\", namespaces.gx);\n const h = queryNumericValue(iconNode, \"h\", namespaces.gx);\n\n const hotSpotNode = queryFirstNode(node, \"hotSpot\", namespaces.kml);\n const hotSpotX = queryNumericAttribute(hotSpotNode, \"x\");\n const hotSpotY = queryNumericAttribute(hotSpotNode, \"y\");\n const hotSpotXUnit = queryStringAttribute(hotSpotNode, \"xunits\");\n const hotSpotYUnit = queryStringAttribute(hotSpotNode, \"yunits\");\n\n let billboard = targetEntity.billboard;\n if (!defined(billboard)) {\n billboard = createDefaultBillboard();\n targetEntity.billboard = billboard;\n }\n\n billboard.image = icon;\n billboard.scale = scale;\n billboard.color = color;\n\n if (defined(x) || defined(y) || defined(w) || defined(h)) {\n billboard.imageSubRegion = new BoundingRectangle(x, y, w, h);\n }\n\n //GE treats a heading of zero as no heading\n //You can still point north using a 360 degree angle (or any multiple of 360)\n if (defined(heading) && heading !== 0) {\n billboard.rotation = CesiumMath.toRadians(-heading);\n billboard.alignedAxis = Cartesian3.UNIT_Z;\n }\n\n //Hotpot is the KML equivalent of pixel offset\n //The hotspot origin is the lower left, but we leave\n //our billboard origin at the center and simply\n //modify the pixel offset to take this into account\n scale = defaultValue(scale, 1.0);\n\n let xOffset;\n let yOffset;\n if (defined(hotSpotX)) {\n if (hotSpotXUnit === \"pixels\") {\n xOffset = -hotSpotX * scale;\n } else if (hotSpotXUnit === \"insetPixels\") {\n xOffset = (hotSpotX - BILLBOARD_SIZE) * scale;\n } else if (hotSpotXUnit === \"fraction\") {\n xOffset = -hotSpotX * BILLBOARD_SIZE * scale;\n }\n xOffset += BILLBOARD_SIZE * 0.5 * scale;\n }\n\n if (defined(hotSpotY)) {\n if (hotSpotYUnit === \"pixels\") {\n yOffset = hotSpotY * scale;\n } else if (hotSpotYUnit === \"insetPixels\") {\n yOffset = (-hotSpotY + BILLBOARD_SIZE) * scale;\n } else if (hotSpotYUnit === \"fraction\") {\n yOffset = hotSpotY * BILLBOARD_SIZE * scale;\n }\n\n yOffset -= BILLBOARD_SIZE * 0.5 * scale;\n }\n\n if (defined(xOffset) || defined(yOffset)) {\n billboard.pixelOffset = new Cartesian2(xOffset, yOffset);\n }\n}\n\nfunction applyStyle(\n dataSource,\n styleNode,\n targetEntity,\n sourceResource,\n uriResolver\n) {\n for (let i = 0, len = styleNode.childNodes.length; i < len; i++) {\n const node = styleNode.childNodes.item(i);\n if (node.localName === \"IconStyle\") {\n processBillboardIcon(\n dataSource,\n node,\n targetEntity,\n sourceResource,\n uriResolver\n );\n } else if (node.localName === \"LabelStyle\") {\n let label = targetEntity.label;\n if (!defined(label)) {\n label = createDefaultLabel();\n targetEntity.label = label;\n }\n label.scale = defaultValue(\n queryNumericValue(node, \"scale\", namespaces.kml),\n label.scale\n );\n label.fillColor = defaultValue(\n queryColorValue(node, \"color\", namespaces.kml),\n label.fillColor\n );\n label.text = targetEntity.name;\n } else if (node.localName === \"LineStyle\") {\n let polyline = targetEntity.polyline;\n if (!defined(polyline)) {\n polyline = new PolylineGraphics();\n targetEntity.polyline = polyline;\n }\n polyline.width = queryNumericValue(node, \"width\", namespaces.kml);\n polyline.material = queryColorValue(node, \"color\", namespaces.kml);\n if (defined(queryColorValue(node, \"outerColor\", namespaces.gx))) {\n oneTimeWarning(\n \"kml-gx:outerColor\",\n \"KML - gx:outerColor is not supported in a LineStyle\"\n );\n }\n if (defined(queryNumericValue(node, \"outerWidth\", namespaces.gx))) {\n oneTimeWarning(\n \"kml-gx:outerWidth\",\n \"KML - gx:outerWidth is not supported in a LineStyle\"\n );\n }\n if (defined(queryNumericValue(node, \"physicalWidth\", namespaces.gx))) {\n oneTimeWarning(\n \"kml-gx:physicalWidth\",\n \"KML - gx:physicalWidth is not supported in a LineStyle\"\n );\n }\n if (defined(queryBooleanValue(node, \"labelVisibility\", namespaces.gx))) {\n oneTimeWarning(\n \"kml-gx:labelVisibility\",\n \"KML - gx:labelVisibility is not supported in a LineStyle\"\n );\n }\n } else if (node.localName === \"PolyStyle\") {\n let polygon = targetEntity.polygon;\n if (!defined(polygon)) {\n polygon = createDefaultPolygon();\n targetEntity.polygon = polygon;\n }\n polygon.material = defaultValue(\n queryColorValue(node, \"color\", namespaces.kml),\n polygon.material\n );\n polygon.fill = defaultValue(\n queryBooleanValue(node, \"fill\", namespaces.kml),\n polygon.fill\n );\n polygon.outline = defaultValue(\n queryBooleanValue(node, \"outline\", namespaces.kml),\n polygon.outline\n );\n } else if (node.localName === \"BalloonStyle\") {\n const bgColor = defaultValue(\n parseColorString(queryStringValue(node, \"bgColor\", namespaces.kml)),\n Color.WHITE\n );\n const textColor = defaultValue(\n parseColorString(queryStringValue(node, \"textColor\", namespaces.kml)),\n Color.BLACK\n );\n const text = queryStringValue(node, \"text\", namespaces.kml);\n\n //This is purely an internal property used in style processing,\n //it never ends up on the final entity.\n targetEntity.addProperty(\"balloonStyle\");\n targetEntity.balloonStyle = {\n bgColor: bgColor,\n textColor: textColor,\n text: text,\n };\n } else if (node.localName === \"ListStyle\") {\n const listItemType = queryStringValue(\n node,\n \"listItemType\",\n namespaces.kml\n );\n if (listItemType === \"radioFolder\" || listItemType === \"checkOffOnly\") {\n oneTimeWarning(\n `kml-listStyle-${listItemType}`,\n `KML - Unsupported ListStyle with listItemType: ${listItemType}`\n );\n }\n }\n }\n}\n\n//Processes and merges any inline styles for the provided node into the provided entity.\nfunction computeFinalStyle(\n dataSource,\n placeMark,\n styleCollection,\n sourceResource,\n uriResolver\n) {\n const result = new Entity();\n let styleEntity;\n\n //Google earth seems to always use the last inline Style/StyleMap only\n let styleIndex = -1;\n const childNodes = placeMark.childNodes;\n const length = childNodes.length;\n for (let q = 0; q < length; q++) {\n const child = childNodes[q];\n if (child.localName === \"Style\" || child.localName === \"StyleMap\") {\n styleIndex = q;\n }\n }\n\n if (styleIndex !== -1) {\n const inlineStyleNode = childNodes[styleIndex];\n if (inlineStyleNode.localName === \"Style\") {\n applyStyle(\n dataSource,\n inlineStyleNode,\n result,\n sourceResource,\n uriResolver\n );\n } else {\n // StyleMap\n const pairs = queryChildNodes(inlineStyleNode, \"Pair\", namespaces.kml);\n for (let p = 0; p < pairs.length; p++) {\n const pair = pairs[p];\n const key = queryStringValue(pair, \"key\", namespaces.kml);\n if (key === \"normal\") {\n const styleUrl = queryStringValue(pair, \"styleUrl\", namespaces.kml);\n if (defined(styleUrl)) {\n styleEntity = styleCollection.getById(styleUrl);\n if (!defined(styleEntity)) {\n styleEntity = styleCollection.getById(`#${styleUrl}`);\n }\n if (defined(styleEntity)) {\n result.merge(styleEntity);\n }\n } else {\n const node = queryFirstNode(pair, \"Style\", namespaces.kml);\n applyStyle(dataSource, node, result, sourceResource, uriResolver);\n }\n } else {\n oneTimeWarning(\n `kml-styleMap-${key}`,\n `KML - Unsupported StyleMap key: ${key}`\n );\n }\n }\n }\n }\n\n //Google earth seems to always use the first external style only.\n const externalStyle = queryStringValue(placeMark, \"styleUrl\", namespaces.kml);\n if (defined(externalStyle)) {\n let id = externalStyle;\n if (externalStyle[0] !== \"#\" && externalStyle.indexOf(\"#\") !== -1) {\n const tokens = externalStyle.split(\"#\");\n const uri = tokens[0];\n const resource = sourceResource.getDerivedResource({\n url: uri,\n });\n\n id = `${resource.getUrlComponent()}#${tokens[1]}`;\n }\n\n styleEntity = styleCollection.getById(id);\n if (!defined(styleEntity)) {\n styleEntity = styleCollection.getById(`#${id}`);\n }\n if (defined(styleEntity)) {\n result.merge(styleEntity);\n }\n }\n\n return result;\n}\n\n//Asynchronously processes an external style file.\nfunction processExternalStyles(dataSource, resource, styleCollection) {\n return resource.fetchXML().then(function (styleKml) {\n return processStyles(dataSource, styleKml, styleCollection, resource, true);\n });\n}\n\n//Processes all shared and external styles and stores\n//their id into the provided styleCollection.\n//Returns an array of promises that will resolve when\n//each style is loaded.\nfunction processStyles(\n dataSource,\n kml,\n styleCollection,\n sourceResource,\n isExternal,\n uriResolver\n) {\n let i;\n let id;\n let styleEntity;\n\n let node;\n const styleNodes = queryNodes(kml, \"Style\", namespaces.kml);\n if (defined(styleNodes)) {\n const styleNodesLength = styleNodes.length;\n for (i = 0; i < styleNodesLength; i++) {\n node = styleNodes[i];\n id = queryStringAttribute(node, \"id\");\n if (defined(id)) {\n id = `#${id}`;\n if (isExternal && defined(sourceResource)) {\n id = sourceResource.getUrlComponent() + id;\n }\n if (!defined(styleCollection.getById(id))) {\n styleEntity = new Entity({\n id: id,\n });\n styleCollection.add(styleEntity);\n applyStyle(\n dataSource,\n node,\n styleEntity,\n sourceResource,\n uriResolver\n );\n }\n }\n }\n }\n\n const styleMaps = queryNodes(kml, \"StyleMap\", namespaces.kml);\n if (defined(styleMaps)) {\n const styleMapsLength = styleMaps.length;\n for (i = 0; i < styleMapsLength; i++) {\n const styleMap = styleMaps[i];\n id = queryStringAttribute(styleMap, \"id\");\n if (defined(id)) {\n const pairs = queryChildNodes(styleMap, \"Pair\", namespaces.kml);\n for (let p = 0; p < pairs.length; p++) {\n const pair = pairs[p];\n const key = queryStringValue(pair, \"key\", namespaces.kml);\n if (key === \"normal\") {\n id = `#${id}`;\n if (isExternal && defined(sourceResource)) {\n id = sourceResource.getUrlComponent() + id;\n }\n if (!defined(styleCollection.getById(id))) {\n styleEntity = styleCollection.getOrCreateEntity(id);\n\n let styleUrl = queryStringValue(pair, \"styleUrl\", namespaces.kml);\n if (defined(styleUrl)) {\n if (styleUrl[0] !== \"#\") {\n styleUrl = `#${styleUrl}`;\n }\n\n if (isExternal && defined(sourceResource)) {\n styleUrl = sourceResource.getUrlComponent() + styleUrl;\n }\n const base = styleCollection.getById(styleUrl);\n\n if (defined(base)) {\n styleEntity.merge(base);\n }\n } else {\n node = queryFirstNode(pair, \"Style\", namespaces.kml);\n applyStyle(\n dataSource,\n node,\n styleEntity,\n sourceResource,\n uriResolver\n );\n }\n }\n } else {\n oneTimeWarning(\n `kml-styleMap-${key}`,\n `KML - Unsupported StyleMap key: ${key}`\n );\n }\n }\n }\n }\n }\n\n const promises = [];\n const styleUrlNodes = kml.getElementsByTagName(\"styleUrl\");\n const styleUrlNodesLength = styleUrlNodes.length;\n for (i = 0; i < styleUrlNodesLength; i++) {\n const styleReference = styleUrlNodes[i].textContent;\n if (styleReference[0] !== \"#\") {\n //According to the spec, all local styles should start with a #\n //and everything else is an external style that has a # seperating\n //the URL of the document and the style. However, Google Earth\n //also accepts styleUrls without a # as meaning a local style.\n const tokens = styleReference.split(\"#\");\n if (tokens.length === 2) {\n const uri = tokens[0];\n const resource = sourceResource.getDerivedResource({\n url: uri,\n });\n\n promises.push(\n processExternalStyles(dataSource, resource, styleCollection)\n );\n }\n }\n }\n\n return promises;\n}\n\nfunction createDropLine(entityCollection, entity, styleEntity) {\n const entityPosition = new ReferenceProperty(entityCollection, entity.id, [\n \"position\",\n ]);\n const surfacePosition = new ScaledPositionProperty(entity.position);\n entity.polyline = defined(styleEntity.polyline)\n ? styleEntity.polyline.clone()\n : new PolylineGraphics();\n entity.polyline.positions = new PositionPropertyArray([\n entityPosition,\n surfacePosition,\n ]);\n}\n\nfunction heightReferenceFromAltitudeMode(altitudeMode, gxAltitudeMode) {\n if (\n (!defined(altitudeMode) && !defined(gxAltitudeMode)) ||\n altitudeMode === \"clampToGround\"\n ) {\n return HeightReference.CLAMP_TO_GROUND;\n }\n\n if (altitudeMode === \"relativeToGround\") {\n return HeightReference.RELATIVE_TO_GROUND;\n }\n\n if (altitudeMode === \"absolute\") {\n return HeightReference.NONE;\n }\n\n if (gxAltitudeMode === \"clampToSeaFloor\") {\n oneTimeWarning(\n \"kml-gx:altitudeMode-clampToSeaFloor\",\n \"KML - :clampToSeaFloor is currently not supported, using :clampToGround.\"\n );\n return HeightReference.CLAMP_TO_GROUND;\n }\n\n if (gxAltitudeMode === \"relativeToSeaFloor\") {\n oneTimeWarning(\n \"kml-gx:altitudeMode-relativeToSeaFloor\",\n \"KML - :relativeToSeaFloor is currently not supported, using :relativeToGround.\"\n );\n return HeightReference.RELATIVE_TO_GROUND;\n }\n\n if (defined(altitudeMode)) {\n oneTimeWarning(\n \"kml-altitudeMode-unknown\",\n `KML - Unknown :${altitudeMode}, using :CLAMP_TO_GROUND.`\n );\n } else {\n oneTimeWarning(\n \"kml-gx:altitudeMode-unknown\",\n `KML - Unknown :${gxAltitudeMode}, using :CLAMP_TO_GROUND.`\n );\n }\n\n // Clamp to ground is the default\n return HeightReference.CLAMP_TO_GROUND;\n}\n\nfunction createPositionPropertyFromAltitudeMode(\n property,\n altitudeMode,\n gxAltitudeMode\n) {\n if (\n gxAltitudeMode === \"relativeToSeaFloor\" ||\n altitudeMode === \"absolute\" ||\n altitudeMode === \"relativeToGround\"\n ) {\n //Just return the ellipsoid referenced property until we support MSL\n return property;\n }\n\n if (\n (defined(altitudeMode) && altitudeMode !== \"clampToGround\") || //\n (defined(gxAltitudeMode) && gxAltitudeMode !== \"clampToSeaFloor\")\n ) {\n oneTimeWarning(\n \"kml-altitudeMode-unknown\",\n `KML - Unknown altitudeMode: ${defaultValue(\n altitudeMode,\n gxAltitudeMode\n )}`\n );\n }\n\n // Clamp to ground is the default\n return new ScaledPositionProperty(property);\n}\n\nfunction createPositionPropertyArrayFromAltitudeMode(\n properties,\n altitudeMode,\n gxAltitudeMode,\n ellipsoid\n) {\n if (!defined(properties)) {\n return undefined;\n }\n\n if (\n gxAltitudeMode === \"relativeToSeaFloor\" ||\n altitudeMode === \"absolute\" ||\n altitudeMode === \"relativeToGround\"\n ) {\n //Just return the ellipsoid referenced property until we support MSL\n return properties;\n }\n\n if (\n (defined(altitudeMode) && altitudeMode !== \"clampToGround\") || //\n (defined(gxAltitudeMode) && gxAltitudeMode !== \"clampToSeaFloor\")\n ) {\n oneTimeWarning(\n \"kml-altitudeMode-unknown\",\n `KML - Unknown altitudeMode: ${defaultValue(\n altitudeMode,\n gxAltitudeMode\n )}`\n );\n }\n\n // Clamp to ground is the default\n const propertiesLength = properties.length;\n for (let i = 0; i < propertiesLength; i++) {\n const property = properties[i];\n ellipsoid.scaleToGeodeticSurface(property, property);\n }\n return properties;\n}\n\nfunction processPositionGraphics(\n dataSource,\n entity,\n styleEntity,\n heightReference\n) {\n let label = entity.label;\n if (!defined(label)) {\n label = defined(styleEntity.label)\n ? styleEntity.label.clone()\n : createDefaultLabel();\n entity.label = label;\n }\n label.text = entity.name;\n\n let billboard = entity.billboard;\n if (!defined(billboard)) {\n billboard = defined(styleEntity.billboard)\n ? styleEntity.billboard.clone()\n : createDefaultBillboard();\n entity.billboard = billboard;\n }\n\n if (!defined(billboard.image)) {\n billboard.image = dataSource._pinBuilder.fromColor(Color.YELLOW, 64);\n\n // If there were empty tags in the KML, then billboard.image was set to false above\n // However, in this case, the false value would have been converted to a property afterwards\n // Thus, we check if billboard.image is defined with value of false\n } else if (!billboard.image.getValue()) {\n billboard.image = undefined;\n }\n\n let scale = 1.0;\n if (defined(billboard.scale)) {\n scale = billboard.scale.getValue();\n if (scale !== 0) {\n label.pixelOffset = new Cartesian2(scale * 16 + 1, 0);\n } else {\n //Minor tweaks to better match Google Earth.\n label.pixelOffset = undefined;\n label.horizontalOrigin = undefined;\n }\n }\n\n if (defined(heightReference) && dataSource._clampToGround) {\n billboard.heightReference = heightReference;\n label.heightReference = heightReference;\n }\n}\n\nfunction processPathGraphics(entity, styleEntity) {\n let path = entity.path;\n if (!defined(path)) {\n path = new PathGraphics();\n path.leadTime = 0;\n entity.path = path;\n }\n\n const polyline = styleEntity.polyline;\n if (defined(polyline)) {\n path.material = polyline.material;\n path.width = polyline.width;\n }\n}\n\nfunction processPoint(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n const coordinatesString = queryStringValue(\n geometryNode,\n \"coordinates\",\n namespaces.kml\n );\n const altitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.kml\n );\n const gxAltitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.gx\n );\n const extrude = queryBooleanValue(geometryNode, \"extrude\", namespaces.kml);\n const ellipsoid = dataSource._ellipsoid;\n const position = readCoordinate(coordinatesString, ellipsoid);\n\n entity.position = position;\n processPositionGraphics(\n dataSource,\n entity,\n styleEntity,\n heightReferenceFromAltitudeMode(altitudeMode, gxAltitudeMode)\n );\n\n if (extrude && isExtrudable(altitudeMode, gxAltitudeMode)) {\n createDropLine(entityCollection, entity, styleEntity);\n }\n\n return true;\n}\n\nfunction processLineStringOrLinearRing(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n const coordinatesNode = queryFirstNode(\n geometryNode,\n \"coordinates\",\n namespaces.kml\n );\n const altitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.kml\n );\n const gxAltitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.gx\n );\n const extrude = queryBooleanValue(geometryNode, \"extrude\", namespaces.kml);\n const tessellate = queryBooleanValue(\n geometryNode,\n \"tessellate\",\n namespaces.kml\n );\n const canExtrude = isExtrudable(altitudeMode, gxAltitudeMode);\n const zIndex = queryNumericValue(geometryNode, \"drawOrder\", namespaces.gx);\n\n const ellipsoid = dataSource._ellipsoid;\n const coordinates = readCoordinates(coordinatesNode, ellipsoid);\n let polyline = styleEntity.polyline;\n if (canExtrude && extrude) {\n const wall = new WallGraphics();\n entity.wall = wall;\n wall.positions = coordinates;\n const polygon = styleEntity.polygon;\n\n if (defined(polygon)) {\n wall.fill = polygon.fill;\n wall.material = polygon.material;\n }\n\n //Always outline walls so they show up in 2D.\n wall.outline = true;\n if (defined(polyline)) {\n wall.outlineColor = defined(polyline.material)\n ? polyline.material.color\n : Color.WHITE;\n wall.outlineWidth = polyline.width;\n } else if (defined(polygon)) {\n wall.outlineColor = defined(polygon.material)\n ? polygon.material.color\n : Color.WHITE;\n }\n } else if (dataSource._clampToGround && !canExtrude && tessellate) {\n const polylineGraphics = new PolylineGraphics();\n polylineGraphics.clampToGround = true;\n entity.polyline = polylineGraphics;\n polylineGraphics.positions = coordinates;\n if (defined(polyline)) {\n polylineGraphics.material = defined(polyline.material)\n ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE)\n : Color.WHITE;\n polylineGraphics.width = defaultValue(polyline.width, 1.0);\n } else {\n polylineGraphics.material = Color.WHITE;\n polylineGraphics.width = 1.0;\n }\n polylineGraphics.zIndex = zIndex;\n } else {\n if (defined(zIndex)) {\n oneTimeWarning(\n \"kml-gx:drawOrder\",\n \"KML - gx:drawOrder is not supported in LineStrings when clampToGround is false\"\n );\n }\n if (dataSource._clampToGround && !tessellate) {\n oneTimeWarning(\n \"kml-line-tesselate\",\n \"Ignoring clampToGround for KML lines without the tessellate flag.\"\n );\n }\n\n polyline = defined(polyline) ? polyline.clone() : new PolylineGraphics();\n entity.polyline = polyline;\n polyline.positions = createPositionPropertyArrayFromAltitudeMode(\n coordinates,\n altitudeMode,\n gxAltitudeMode,\n ellipsoid\n );\n if (!tessellate || canExtrude) {\n polyline.arcType = ArcType.NONE;\n }\n }\n\n return true;\n}\n\nfunction processPolygon(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n const outerBoundaryIsNode = queryFirstNode(\n geometryNode,\n \"outerBoundaryIs\",\n namespaces.kml\n );\n let linearRingNode = queryFirstNode(\n outerBoundaryIsNode,\n \"LinearRing\",\n namespaces.kml\n );\n let coordinatesNode = queryFirstNode(\n linearRingNode,\n \"coordinates\",\n namespaces.kml\n );\n const ellipsoid = dataSource._ellipsoid;\n let coordinates = readCoordinates(coordinatesNode, ellipsoid);\n const extrude = queryBooleanValue(geometryNode, \"extrude\", namespaces.kml);\n const altitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.kml\n );\n const gxAltitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.gx\n );\n const canExtrude = isExtrudable(altitudeMode, gxAltitudeMode);\n\n const polygon = defined(styleEntity.polygon)\n ? styleEntity.polygon.clone()\n : createDefaultPolygon();\n\n const polyline = styleEntity.polyline;\n if (defined(polyline)) {\n polygon.outlineColor = defined(polyline.material)\n ? polyline.material.color\n : Color.WHITE;\n polygon.outlineWidth = polyline.width;\n }\n entity.polygon = polygon;\n\n if (canExtrude) {\n polygon.perPositionHeight = true;\n polygon.extrudedHeight = extrude ? 0 : undefined;\n } else if (!dataSource._clampToGround) {\n polygon.height = 0;\n }\n\n if (defined(coordinates)) {\n const hierarchy = new PolygonHierarchy(coordinates);\n const innerBoundaryIsNodes = queryChildNodes(\n geometryNode,\n \"innerBoundaryIs\",\n namespaces.kml\n );\n for (let j = 0; j < innerBoundaryIsNodes.length; j++) {\n linearRingNode = queryChildNodes(\n innerBoundaryIsNodes[j],\n \"LinearRing\",\n namespaces.kml\n );\n for (let k = 0; k < linearRingNode.length; k++) {\n coordinatesNode = queryFirstNode(\n linearRingNode[k],\n \"coordinates\",\n namespaces.kml\n );\n coordinates = readCoordinates(coordinatesNode, ellipsoid);\n if (defined(coordinates)) {\n hierarchy.holes.push(new PolygonHierarchy(coordinates));\n }\n }\n }\n polygon.hierarchy = hierarchy;\n }\n\n return true;\n}\n\nfunction processTrack(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n const altitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.kml\n );\n const gxAltitudeMode = queryStringValue(\n geometryNode,\n \"altitudeMode\",\n namespaces.gx\n );\n const coordNodes = queryChildNodes(geometryNode, \"coord\", namespaces.gx);\n const angleNodes = queryChildNodes(geometryNode, \"angles\", namespaces.gx);\n const timeNodes = queryChildNodes(geometryNode, \"when\", namespaces.kml);\n const extrude = queryBooleanValue(geometryNode, \"extrude\", namespaces.kml);\n const canExtrude = isExtrudable(altitudeMode, gxAltitudeMode);\n const ellipsoid = dataSource._ellipsoid;\n\n if (angleNodes.length > 0) {\n oneTimeWarning(\n \"kml-gx:angles\",\n \"KML - gx:angles are not supported in gx:Tracks\"\n );\n }\n\n const length = Math.min(coordNodes.length, timeNodes.length);\n const coordinates = [];\n const times = [];\n for (let i = 0; i < length; i++) {\n const position = readCoordinate(coordNodes[i].textContent, ellipsoid);\n coordinates.push(position);\n times.push(JulianDate.fromIso8601(timeNodes[i].textContent));\n }\n const property = new SampledPositionProperty();\n property.addSamples(times, coordinates);\n entity.position = property;\n processPositionGraphics(\n dataSource,\n entity,\n styleEntity,\n heightReferenceFromAltitudeMode(altitudeMode, gxAltitudeMode)\n );\n processPathGraphics(entity, styleEntity);\n\n entity.availability = new TimeIntervalCollection();\n\n if (timeNodes.length > 0) {\n entity.availability.addInterval(\n new TimeInterval({\n start: times[0],\n stop: times[times.length - 1],\n })\n );\n }\n\n if (canExtrude && extrude) {\n createDropLine(entityCollection, entity, styleEntity);\n }\n\n return true;\n}\n\nfunction addToMultiTrack(\n times,\n positions,\n composite,\n availability,\n dropShowProperty,\n extrude,\n altitudeMode,\n gxAltitudeMode,\n includeEndPoints\n) {\n const start = times[0];\n const stop = times[times.length - 1];\n\n const data = new SampledPositionProperty();\n data.addSamples(times, positions);\n\n composite.intervals.addInterval(\n new TimeInterval({\n start: start,\n stop: stop,\n isStartIncluded: includeEndPoints,\n isStopIncluded: includeEndPoints,\n data: createPositionPropertyFromAltitudeMode(\n data,\n altitudeMode,\n gxAltitudeMode\n ),\n })\n );\n availability.addInterval(\n new TimeInterval({\n start: start,\n stop: stop,\n isStartIncluded: includeEndPoints,\n isStopIncluded: includeEndPoints,\n })\n );\n dropShowProperty.intervals.addInterval(\n new TimeInterval({\n start: start,\n stop: stop,\n isStartIncluded: includeEndPoints,\n isStopIncluded: includeEndPoints,\n data: extrude,\n })\n );\n}\n\nfunction processMultiTrack(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n // Multitrack options do not work in GE as detailed in the spec,\n // rather than altitudeMode being at the MultiTrack level,\n // GE just defers all settings to the underlying track.\n\n const interpolate = queryBooleanValue(\n geometryNode,\n \"interpolate\",\n namespaces.gx\n );\n const trackNodes = queryChildNodes(geometryNode, \"Track\", namespaces.gx);\n\n let times;\n let lastStop;\n let lastStopPosition;\n let needDropLine = false;\n const dropShowProperty = new TimeIntervalCollectionProperty();\n const availability = new TimeIntervalCollection();\n const composite = new CompositePositionProperty();\n const ellipsoid = dataSource._ellipsoid;\n for (let i = 0, len = trackNodes.length; i < len; i++) {\n const trackNode = trackNodes[i];\n const timeNodes = queryChildNodes(trackNode, \"when\", namespaces.kml);\n const coordNodes = queryChildNodes(trackNode, \"coord\", namespaces.gx);\n const altitudeMode = queryStringValue(\n trackNode,\n \"altitudeMode\",\n namespaces.kml\n );\n const gxAltitudeMode = queryStringValue(\n trackNode,\n \"altitudeMode\",\n namespaces.gx\n );\n const canExtrude = isExtrudable(altitudeMode, gxAltitudeMode);\n const extrude = queryBooleanValue(trackNode, \"extrude\", namespaces.kml);\n\n const length = Math.min(coordNodes.length, timeNodes.length);\n\n const positions = [];\n times = [];\n for (let x = 0; x < length; x++) {\n const position = readCoordinate(coordNodes[x].textContent, ellipsoid);\n positions.push(position);\n times.push(JulianDate.fromIso8601(timeNodes[x].textContent));\n }\n\n if (interpolate) {\n //If we are interpolating, then we need to fill in the end of\n //the last track and the beginning of this one with a sampled\n //property. From testing in Google Earth, this property\n //is never extruded and always absolute.\n if (defined(lastStop)) {\n addToMultiTrack(\n [lastStop, times[0]],\n [lastStopPosition, positions[0]],\n composite,\n availability,\n dropShowProperty,\n false,\n \"absolute\",\n undefined,\n false\n );\n }\n lastStop = times[length - 1];\n lastStopPosition = positions[positions.length - 1];\n }\n\n addToMultiTrack(\n times,\n positions,\n composite,\n availability,\n dropShowProperty,\n canExtrude && extrude,\n altitudeMode,\n gxAltitudeMode,\n true\n );\n needDropLine = needDropLine || (canExtrude && extrude);\n }\n\n entity.availability = availability;\n entity.position = composite;\n processPositionGraphics(dataSource, entity, styleEntity);\n processPathGraphics(entity, styleEntity);\n if (needDropLine) {\n createDropLine(entityCollection, entity, styleEntity);\n entity.polyline.show = dropShowProperty;\n }\n\n return true;\n}\n\nconst geometryTypes = {\n Point: processPoint,\n LineString: processLineStringOrLinearRing,\n LinearRing: processLineStringOrLinearRing,\n Polygon: processPolygon,\n Track: processTrack,\n MultiTrack: processMultiTrack,\n MultiGeometry: processMultiGeometry,\n Model: processUnsupportedGeometry,\n};\n\nfunction processMultiGeometry(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity,\n context\n) {\n const childNodes = geometryNode.childNodes;\n let hasGeometry = false;\n for (let i = 0, len = childNodes.length; i < len; i++) {\n const childNode = childNodes.item(i);\n const geometryProcessor = geometryTypes[childNode.localName];\n if (defined(geometryProcessor)) {\n const childEntity = createEntity(childNode, entityCollection, context);\n childEntity.parent = entity;\n childEntity.name = entity.name;\n childEntity.availability = entity.availability;\n childEntity.description = entity.description;\n childEntity.kml = entity.kml;\n if (\n geometryProcessor(\n dataSource,\n entityCollection,\n childNode,\n childEntity,\n styleEntity\n )\n ) {\n hasGeometry = true;\n }\n }\n }\n\n return hasGeometry;\n}\n\nfunction processUnsupportedGeometry(\n dataSource,\n entityCollection,\n geometryNode,\n entity,\n styleEntity\n) {\n oneTimeWarning(\n \"kml-unsupportedGeometry\",\n `KML - Unsupported geometry: ${geometryNode.localName}`\n );\n return false;\n}\n\nfunction processExtendedData(node, entity) {\n const extendedDataNode = queryFirstNode(node, \"ExtendedData\", namespaces.kml);\n\n if (!defined(extendedDataNode)) {\n return undefined;\n }\n\n if (defined(queryFirstNode(extendedDataNode, \"SchemaData\", namespaces.kml))) {\n oneTimeWarning(\"kml-schemaData\", \"KML - SchemaData is unsupported\");\n }\n if (defined(queryStringAttribute(extendedDataNode, \"xmlns:prefix\"))) {\n oneTimeWarning(\n \"kml-extendedData\",\n \"KML - ExtendedData with xmlns:prefix is unsupported\"\n );\n }\n\n const result = {};\n const dataNodes = queryChildNodes(extendedDataNode, \"Data\", namespaces.kml);\n if (defined(dataNodes)) {\n const length = dataNodes.length;\n for (let i = 0; i < length; i++) {\n const dataNode = dataNodes[i];\n const name = queryStringAttribute(dataNode, \"name\");\n if (defined(name)) {\n result[name] = {\n displayName: queryStringValue(\n dataNode,\n \"displayName\",\n namespaces.kml\n ),\n value: queryStringValue(dataNode, \"value\", namespaces.kml),\n };\n }\n }\n }\n entity.kml.extendedData = result;\n}\n\nlet scratchDiv;\nif (typeof document !== \"undefined\") {\n scratchDiv = document.createElement(\"div\");\n}\n\nfunction processDescription(\n node,\n entity,\n styleEntity,\n uriResolver,\n sourceResource\n) {\n let i;\n let key;\n let keys;\n\n const kmlData = entity.kml;\n const extendedData = kmlData.extendedData;\n const description = queryStringValue(node, \"description\", namespaces.kml);\n\n const balloonStyle = defaultValue(\n entity.balloonStyle,\n styleEntity.balloonStyle\n );\n\n let background = Color.WHITE;\n let foreground = Color.BLACK;\n let text = description;\n\n if (defined(balloonStyle)) {\n background = defaultValue(balloonStyle.bgColor, Color.WHITE);\n foreground = defaultValue(balloonStyle.textColor, Color.BLACK);\n text = defaultValue(balloonStyle.text, description);\n }\n\n let value;\n if (defined(text)) {\n text = text.replace(\"$[name]\", defaultValue(entity.name, \"\"));\n text = text.replace(\"$[description]\", defaultValue(description, \"\"));\n text = text.replace(\"$[address]\", defaultValue(kmlData.address, \"\"));\n text = text.replace(\"$[Snippet]\", defaultValue(kmlData.snippet, \"\"));\n text = text.replace(\"$[id]\", entity.id);\n\n //While not explicitly defined by the OGC spec, in Google Earth\n //The appearance of geDirections adds the directions to/from links\n //We simply replace this string with nothing.\n text = text.replace(\"$[geDirections]\", \"\");\n\n if (defined(extendedData)) {\n const matches = text.match(/\\$\\[.+?\\]/g);\n if (matches !== null) {\n for (i = 0; i < matches.length; i++) {\n const token = matches[i];\n let propertyName = token.substr(2, token.length - 3);\n const isDisplayName = /\\/displayName$/.test(propertyName);\n propertyName = propertyName.replace(/\\/displayName$/, \"\");\n\n value = extendedData[propertyName];\n if (defined(value)) {\n value = isDisplayName ? value.displayName : value.value;\n }\n if (defined(value)) {\n text = text.replace(token, defaultValue(value, \"\"));\n }\n }\n }\n }\n } else if (defined(extendedData)) {\n //If no description exists, build a table out of the extended data\n keys = Object.keys(extendedData);\n if (keys.length > 0) {\n text =\n '';\n for (i = 0; i < keys.length; i++) {\n key = keys[i];\n value = extendedData[key];\n text += ``;\n }\n text += \"
${defaultValue(\n value.displayName,\n key\n )}${defaultValue(value.value, \"\")}
\";\n }\n }\n\n if (!defined(text)) {\n //No description\n return;\n }\n\n //Turns non-explicit links into clickable links.\n text = autolinker.link(text);\n\n //Use a temporary div to manipulate the links\n //so that they open in a new window.\n scratchDiv.innerHTML = text;\n const links = scratchDiv.querySelectorAll(\"a\");\n for (i = 0; i < links.length; i++) {\n links[i].setAttribute(\"target\", \"_blank\");\n }\n\n //Rewrite any KMZ embedded urls\n if (defined(uriResolver) && uriResolver.keys.length > 1) {\n embedDataUris(scratchDiv, \"a\", \"href\", uriResolver);\n embedDataUris(scratchDiv, \"link\", \"href\", uriResolver);\n embedDataUris(scratchDiv, \"area\", \"href\", uriResolver);\n embedDataUris(scratchDiv, \"img\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"iframe\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"video\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"audio\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"source\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"track\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"input\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"embed\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"script\", \"src\", uriResolver);\n embedDataUris(scratchDiv, \"video\", \"poster\", uriResolver);\n }\n\n //Make relative urls absolute using the sourceResource\n applyBasePath(scratchDiv, \"a\", \"href\", sourceResource);\n applyBasePath(scratchDiv, \"link\", \"href\", sourceResource);\n applyBasePath(scratchDiv, \"area\", \"href\", sourceResource);\n applyBasePath(scratchDiv, \"img\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"iframe\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"video\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"audio\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"source\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"track\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"input\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"embed\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"script\", \"src\", sourceResource);\n applyBasePath(scratchDiv, \"video\", \"poster\", sourceResource);\n\n let tmp = '
`;\n scratchDiv.innerHTML = \"\";\n\n //Set the final HTML as the description.\n entity.description = tmp;\n}\n\nfunction processFeature(dataSource, featureNode, processingData) {\n const entityCollection = processingData.entityCollection;\n const parent = processingData.parentEntity;\n const sourceResource = processingData.sourceResource;\n const uriResolver = processingData.uriResolver;\n\n const entity = createEntity(\n featureNode,\n entityCollection,\n processingData.context\n );\n const kmlData = entity.kml;\n const styleEntity = computeFinalStyle(\n dataSource,\n featureNode,\n processingData.styleCollection,\n sourceResource,\n uriResolver\n );\n\n const name = queryStringValue(featureNode, \"name\", namespaces.kml);\n entity.name = name;\n entity.parent = parent;\n\n let availability = processTimeSpan(featureNode);\n if (!defined(availability)) {\n availability = processTimeStamp(featureNode);\n }\n entity.availability = availability;\n\n mergeAvailabilityWithParent(entity);\n\n // Per KML spec \"A Feature is visible only if it and all its ancestors are visible.\"\n function ancestryIsVisible(parentEntity) {\n if (!parentEntity) {\n return true;\n }\n return parentEntity.show && ancestryIsVisible(parentEntity.parent);\n }\n\n const visibility = queryBooleanValue(\n featureNode,\n \"visibility\",\n namespaces.kml\n );\n entity.show = ancestryIsVisible(parent) && defaultValue(visibility, true);\n //const open = queryBooleanValue(featureNode, 'open', namespaces.kml);\n\n const authorNode = queryFirstNode(featureNode, \"author\", namespaces.atom);\n const author = kmlData.author;\n author.name = queryStringValue(authorNode, \"name\", namespaces.atom);\n author.uri = queryStringValue(authorNode, \"uri\", namespaces.atom);\n author.email = queryStringValue(authorNode, \"email\", namespaces.atom);\n\n const linkNode = queryFirstNode(featureNode, \"link\", namespaces.atom);\n const link = kmlData.link;\n link.href = queryStringAttribute(linkNode, \"href\");\n link.hreflang = queryStringAttribute(linkNode, \"hreflang\");\n link.rel = queryStringAttribute(linkNode, \"rel\");\n link.type = queryStringAttribute(linkNode, \"type\");\n link.title = queryStringAttribute(linkNode, \"title\");\n link.length = queryStringAttribute(linkNode, \"length\");\n\n kmlData.address = queryStringValue(featureNode, \"address\", namespaces.kml);\n kmlData.phoneNumber = queryStringValue(\n featureNode,\n \"phoneNumber\",\n namespaces.kml\n );\n kmlData.snippet = queryStringValue(featureNode, \"Snippet\", namespaces.kml);\n\n processExtendedData(featureNode, entity);\n processDescription(\n featureNode,\n entity,\n styleEntity,\n uriResolver,\n sourceResource\n );\n\n const ellipsoid = dataSource._ellipsoid;\n processLookAt(featureNode, entity, ellipsoid);\n processCamera(featureNode, entity, ellipsoid);\n\n if (defined(queryFirstNode(featureNode, \"Region\", namespaces.kml))) {\n oneTimeWarning(\"kml-region\", \"KML - Placemark Regions are unsupported\");\n }\n\n return {\n entity: entity,\n styleEntity: styleEntity,\n };\n}\n\nfunction processDocument(dataSource, node, processingData, deferredLoading) {\n deferredLoading.addNodes(node.childNodes, processingData);\n deferredLoading.process();\n}\n\nfunction processFolder(dataSource, node, processingData, deferredLoading) {\n const r = processFeature(dataSource, node, processingData);\n const newProcessingData = clone(processingData);\n newProcessingData.parentEntity = r.entity;\n processDocument(dataSource, node, newProcessingData, deferredLoading);\n}\n\nfunction processPlacemark(\n dataSource,\n placemark,\n processingData,\n deferredLoading\n) {\n const r = processFeature(dataSource, placemark, processingData);\n const entity = r.entity;\n const styleEntity = r.styleEntity;\n\n let hasGeometry = false;\n const childNodes = placemark.childNodes;\n for (let i = 0, len = childNodes.length; i < len && !hasGeometry; i++) {\n const childNode = childNodes.item(i);\n const geometryProcessor = geometryTypes[childNode.localName];\n if (defined(geometryProcessor)) {\n // pass the placemark entity id as a context for case of defining multiple child entities together to handle case\n // where some malformed kmls reuse the same id across placemarks, which works in GE, but is not technically to spec.\n geometryProcessor(\n dataSource,\n processingData.entityCollection,\n childNode,\n entity,\n styleEntity,\n entity.id\n );\n hasGeometry = true;\n }\n }\n\n if (!hasGeometry) {\n entity.merge(styleEntity);\n processPositionGraphics(dataSource, entity, styleEntity);\n }\n}\n\nconst playlistNodeProcessors = {\n FlyTo: processTourFlyTo,\n Wait: processTourWait,\n SoundCue: processTourUnsupportedNode,\n AnimatedUpdate: processTourUnsupportedNode,\n TourControl: processTourUnsupportedNode,\n};\n\nfunction processTour(dataSource, node, processingData, deferredLoading) {\n const name = queryStringValue(node, \"name\", namespaces.kml);\n const id = queryStringAttribute(node, \"id\");\n const tour = new KmlTour(name, id);\n\n const playlistNode = queryFirstNode(node, \"Playlist\", namespaces.gx);\n if (playlistNode) {\n const ellipsoid = dataSource._ellipsoid;\n const childNodes = playlistNode.childNodes;\n for (let i = 0; i < childNodes.length; i++) {\n const entryNode = childNodes[i];\n if (entryNode.localName) {\n const playlistNodeProcessor =\n playlistNodeProcessors[entryNode.localName];\n if (playlistNodeProcessor) {\n playlistNodeProcessor(tour, entryNode, ellipsoid);\n } else {\n console.log(\n `Unknown KML Tour playlist entry type ${entryNode.localName}`\n );\n }\n }\n }\n }\n\n dataSource._kmlTours.push(tour);\n}\n\nfunction processTourUnsupportedNode(tour, entryNode) {\n oneTimeWarning(`KML Tour unsupported node ${entryNode.localName}`);\n}\n\nfunction processTourWait(tour, entryNode) {\n const duration = queryNumericValue(entryNode, \"duration\", namespaces.gx);\n tour.addPlaylistEntry(new KmlTourWait(duration));\n}\n\nfunction processTourFlyTo(tour, entryNode, ellipsoid) {\n const duration = queryNumericValue(entryNode, \"duration\", namespaces.gx);\n const flyToMode = queryStringValue(entryNode, \"flyToMode\", namespaces.gx);\n\n const t = { kml: {} };\n\n processLookAt(entryNode, t, ellipsoid);\n processCamera(entryNode, t, ellipsoid);\n\n const view = t.kml.lookAt || t.kml.camera;\n\n const flyto = new KmlTourFlyTo(duration, flyToMode, view);\n tour.addPlaylistEntry(flyto);\n}\n\nfunction processCamera(featureNode, entity, ellipsoid) {\n const camera = queryFirstNode(featureNode, \"Camera\", namespaces.kml);\n if (defined(camera)) {\n const lon = defaultValue(\n queryNumericValue(camera, \"longitude\", namespaces.kml),\n 0.0\n );\n const lat = defaultValue(\n queryNumericValue(camera, \"latitude\", namespaces.kml),\n 0.0\n );\n const altitude = defaultValue(\n queryNumericValue(camera, \"altitude\", namespaces.kml),\n 0.0\n );\n\n const heading = defaultValue(\n queryNumericValue(camera, \"heading\", namespaces.kml),\n 0.0\n );\n const tilt = defaultValue(\n queryNumericValue(camera, \"tilt\", namespaces.kml),\n 0.0\n );\n const roll = defaultValue(\n queryNumericValue(camera, \"roll\", namespaces.kml),\n 0.0\n );\n\n const position = Cartesian3.fromDegrees(lon, lat, altitude, ellipsoid);\n const hpr = HeadingPitchRoll.fromDegrees(heading, tilt - 90.0, roll);\n\n entity.kml.camera = new KmlCamera(position, hpr);\n }\n}\n\nfunction processLookAt(featureNode, entity, ellipsoid) {\n const lookAt = queryFirstNode(featureNode, \"LookAt\", namespaces.kml);\n if (defined(lookAt)) {\n const lon = defaultValue(\n queryNumericValue(lookAt, \"longitude\", namespaces.kml),\n 0.0\n );\n const lat = defaultValue(\n queryNumericValue(lookAt, \"latitude\", namespaces.kml),\n 0.0\n );\n const altitude = defaultValue(\n queryNumericValue(lookAt, \"altitude\", namespaces.kml),\n 0.0\n );\n let heading = queryNumericValue(lookAt, \"heading\", namespaces.kml);\n let tilt = queryNumericValue(lookAt, \"tilt\", namespaces.kml);\n const range = defaultValue(\n queryNumericValue(lookAt, \"range\", namespaces.kml),\n 0.0\n );\n\n tilt = CesiumMath.toRadians(defaultValue(tilt, 0.0));\n heading = CesiumMath.toRadians(defaultValue(heading, 0.0));\n\n const hpr = new HeadingPitchRange(\n heading,\n tilt - CesiumMath.PI_OVER_TWO,\n range\n );\n const viewPoint = Cartesian3.fromDegrees(lon, lat, altitude, ellipsoid);\n\n entity.kml.lookAt = new KmlLookAt(viewPoint, hpr);\n }\n}\n\nfunction processScreenOverlay(\n dataSource,\n screenOverlayNode,\n processingData,\n deferredLoading\n) {\n const screenOverlay = processingData.screenOverlayContainer;\n if (!defined(screenOverlay)) {\n return undefined;\n }\n\n const sourceResource = processingData.sourceResource;\n const uriResolver = processingData.uriResolver;\n\n const iconNode = queryFirstNode(screenOverlayNode, \"Icon\", namespaces.kml);\n const icon = getIconHref(\n iconNode,\n dataSource,\n sourceResource,\n uriResolver,\n false\n );\n\n if (!defined(icon)) {\n return undefined;\n }\n\n const img = document.createElement(\"img\");\n dataSource._screenOverlays.push(img);\n\n img.src = icon.url;\n img.onload = function () {\n const styles = [\"position: absolute\"];\n\n const screenXY = queryFirstNode(\n screenOverlayNode,\n \"screenXY\",\n namespaces.kml\n );\n const overlayXY = queryFirstNode(\n screenOverlayNode,\n \"overlayXY\",\n namespaces.kml\n );\n const size = queryFirstNode(screenOverlayNode, \"size\", namespaces.kml);\n\n let x, y;\n let xUnit, yUnit;\n let xStyle, yStyle;\n\n if (defined(size)) {\n x = queryNumericAttribute(size, \"x\");\n y = queryNumericAttribute(size, \"y\");\n xUnit = queryStringAttribute(size, \"xunits\");\n yUnit = queryStringAttribute(size, \"yunits\");\n\n if (defined(x) && x !== -1 && x !== 0) {\n if (xUnit === \"fraction\") {\n xStyle = `width: ${Math.floor(x * 100)}%`;\n } else if (xUnit === \"pixels\") {\n xStyle = `width: ${x}px`;\n }\n\n styles.push(xStyle);\n }\n\n if (defined(y) && y !== -1 && y !== 0) {\n if (yUnit === \"fraction\") {\n yStyle = `height: ${Math.floor(y * 100)}%`;\n } else if (yUnit === \"pixels\") {\n yStyle = `height: ${y}px`;\n }\n\n styles.push(yStyle);\n }\n }\n\n // set the interim style so the width/height properties get calculated\n img.style = styles.join(\";\");\n\n let xOrigin = 0;\n let yOrigin = img.height;\n\n if (defined(overlayXY)) {\n x = queryNumericAttribute(overlayXY, \"x\");\n y = queryNumericAttribute(overlayXY, \"y\");\n xUnit = queryStringAttribute(overlayXY, \"xunits\");\n yUnit = queryStringAttribute(overlayXY, \"yunits\");\n\n if (defined(x)) {\n if (xUnit === \"fraction\") {\n xOrigin = x * img.width;\n } else if (xUnit === \"pixels\") {\n xOrigin = x;\n } else if (xUnit === \"insetPixels\") {\n xOrigin = x;\n }\n }\n\n if (defined(y)) {\n if (yUnit === \"fraction\") {\n yOrigin = y * img.height;\n } else if (yUnit === \"pixels\") {\n yOrigin = y;\n } else if (yUnit === \"insetPixels\") {\n yOrigin = y;\n }\n }\n }\n\n if (defined(screenXY)) {\n x = queryNumericAttribute(screenXY, \"x\");\n y = queryNumericAttribute(screenXY, \"y\");\n xUnit = queryStringAttribute(screenXY, \"xunits\");\n yUnit = queryStringAttribute(screenXY, \"yunits\");\n\n if (defined(x)) {\n if (xUnit === \"fraction\") {\n xStyle = `${\"left: \" + \"calc(\"}${Math.floor(\n x * 100\n )}% - ${xOrigin}px)`;\n } else if (xUnit === \"pixels\") {\n xStyle = `left: ${x - xOrigin}px`;\n } else if (xUnit === \"insetPixels\") {\n xStyle = `right: ${x - xOrigin}px`;\n }\n\n styles.push(xStyle);\n }\n\n if (defined(y)) {\n if (yUnit === \"fraction\") {\n yStyle = `${\"bottom: \" + \"calc(\"}${Math.floor(\n y * 100\n )}% - ${yOrigin}px)`;\n } else if (yUnit === \"pixels\") {\n yStyle = `bottom: ${y - yOrigin}px`;\n } else if (yUnit === \"insetPixels\") {\n yStyle = `top: ${y - yOrigin}px`;\n }\n\n styles.push(yStyle);\n }\n }\n\n img.style = styles.join(\";\");\n };\n\n screenOverlay.appendChild(img);\n}\n\nfunction processGroundOverlay(\n dataSource,\n groundOverlay,\n processingData,\n deferredLoading\n) {\n const r = processFeature(dataSource, groundOverlay, processingData);\n const entity = r.entity;\n\n let geometry;\n let isLatLonQuad = false;\n\n const ellipsoid = dataSource._ellipsoid;\n const positions = readCoordinates(\n queryFirstNode(groundOverlay, \"LatLonQuad\", namespaces.gx),\n ellipsoid\n );\n const zIndex = queryNumericValue(groundOverlay, \"drawOrder\", namespaces.kml);\n if (defined(positions)) {\n geometry = createDefaultPolygon();\n geometry.hierarchy = new PolygonHierarchy(positions);\n geometry.zIndex = zIndex;\n entity.polygon = geometry;\n isLatLonQuad = true;\n } else {\n geometry = new RectangleGraphics();\n geometry.zIndex = zIndex;\n entity.rectangle = geometry;\n\n const latLonBox = queryFirstNode(\n groundOverlay,\n \"LatLonBox\",\n namespaces.kml\n );\n if (defined(latLonBox)) {\n let west = queryNumericValue(latLonBox, \"west\", namespaces.kml);\n let south = queryNumericValue(latLonBox, \"south\", namespaces.kml);\n let east = queryNumericValue(latLonBox, \"east\", namespaces.kml);\n let north = queryNumericValue(latLonBox, \"north\", namespaces.kml);\n\n if (defined(west)) {\n west = CesiumMath.negativePiToPi(CesiumMath.toRadians(west));\n }\n if (defined(south)) {\n south = CesiumMath.clampToLatitudeRange(CesiumMath.toRadians(south));\n }\n if (defined(east)) {\n east = CesiumMath.negativePiToPi(CesiumMath.toRadians(east));\n }\n if (defined(north)) {\n north = CesiumMath.clampToLatitudeRange(CesiumMath.toRadians(north));\n }\n geometry.coordinates = new Rectangle(west, south, east, north);\n\n const rotation = queryNumericValue(latLonBox, \"rotation\", namespaces.kml);\n if (defined(rotation)) {\n const rotationRadians = CesiumMath.toRadians(rotation);\n geometry.rotation = rotationRadians;\n geometry.stRotation = rotationRadians;\n }\n }\n }\n\n const iconNode = queryFirstNode(groundOverlay, \"Icon\", namespaces.kml);\n const href = getIconHref(\n iconNode,\n dataSource,\n processingData.sourceResource,\n processingData.uriResolver,\n true\n );\n if (defined(href)) {\n if (isLatLonQuad) {\n oneTimeWarning(\n \"kml-gx:LatLonQuad\",\n \"KML - gx:LatLonQuad Icon does not support texture projection.\"\n );\n }\n const x = queryNumericValue(iconNode, \"x\", namespaces.gx);\n const y = queryNumericValue(iconNode, \"y\", namespaces.gx);\n const w = queryNumericValue(iconNode, \"w\", namespaces.gx);\n const h = queryNumericValue(iconNode, \"h\", namespaces.gx);\n\n if (defined(x) || defined(y) || defined(w) || defined(h)) {\n oneTimeWarning(\n \"kml-groundOverlay-xywh\",\n \"KML - gx:x, gx:y, gx:w, gx:h aren't supported for GroundOverlays\"\n );\n }\n\n geometry.material = href;\n geometry.material.color = queryColorValue(\n groundOverlay,\n \"color\",\n namespaces.kml\n );\n geometry.material.transparent = true;\n } else {\n geometry.material = queryColorValue(groundOverlay, \"color\", namespaces.kml);\n }\n\n let altitudeMode = queryStringValue(\n groundOverlay,\n \"altitudeMode\",\n namespaces.kml\n );\n\n if (defined(altitudeMode)) {\n if (altitudeMode === \"absolute\") {\n //Use height above ellipsoid until we support MSL.\n geometry.height = queryNumericValue(\n groundOverlay,\n \"altitude\",\n namespaces.kml\n );\n geometry.zIndex = undefined;\n } else if (altitudeMode !== \"clampToGround\") {\n oneTimeWarning(\n \"kml-altitudeMode-unknown\",\n `KML - Unknown altitudeMode: ${altitudeMode}`\n );\n }\n // else just use the default of 0 until we support 'clampToGround'\n } else {\n altitudeMode = queryStringValue(\n groundOverlay,\n \"altitudeMode\",\n namespaces.gx\n );\n if (altitudeMode === \"relativeToSeaFloor\") {\n oneTimeWarning(\n \"kml-altitudeMode-relativeToSeaFloor\",\n \"KML - altitudeMode relativeToSeaFloor is currently not supported, treating as absolute.\"\n );\n geometry.height = queryNumericValue(\n groundOverlay,\n \"altitude\",\n namespaces.kml\n );\n geometry.zIndex = undefined;\n } else if (altitudeMode === \"clampToSeaFloor\") {\n oneTimeWarning(\n \"kml-altitudeMode-clampToSeaFloor\",\n \"KML - altitudeMode clampToSeaFloor is currently not supported, treating as clampToGround.\"\n );\n } else if (defined(altitudeMode)) {\n oneTimeWarning(\n \"kml-altitudeMode-unknown\",\n `KML - Unknown altitudeMode: ${altitudeMode}`\n );\n }\n }\n}\n\nfunction processUnsupportedFeature(\n dataSource,\n node,\n processingData,\n deferredLoading\n) {\n dataSource._unsupportedNode.raiseEvent(\n dataSource,\n processingData.parentEntity,\n node,\n processingData.entityCollection,\n processingData.styleCollection,\n processingData.sourceResource,\n processingData.uriResolver\n );\n oneTimeWarning(\n `kml-unsupportedFeature-${node.nodeName}`,\n `KML - Unsupported feature: ${node.nodeName}`\n );\n}\n\nconst RefreshMode = {\n INTERVAL: 0,\n EXPIRE: 1,\n STOP: 2,\n};\n\nfunction cleanupString(s) {\n if (!defined(s) || s.length === 0) {\n return \"\";\n }\n\n const sFirst = s[0];\n if (sFirst === \"&\" || sFirst === \"?\") {\n s = s.substring(1);\n }\n\n return s;\n}\n\nconst zeroRectangle = new Rectangle();\nconst scratchCartographic = new Cartographic();\nconst scratchCartesian2 = new Cartesian2();\nconst scratchCartesian3 = new Cartesian3();\n\nfunction processNetworkLinkQueryString(\n resource,\n camera,\n canvas,\n viewBoundScale,\n bbox,\n ellipsoid\n) {\n function fixLatitude(value) {\n if (value < -CesiumMath.PI_OVER_TWO) {\n return -CesiumMath.PI_OVER_TWO;\n } else if (value > CesiumMath.PI_OVER_TWO) {\n return CesiumMath.PI_OVER_TWO;\n }\n return value;\n }\n\n function fixLongitude(value) {\n if (value > CesiumMath.PI) {\n return value - CesiumMath.TWO_PI;\n } else if (value < -CesiumMath.PI) {\n return value + CesiumMath.TWO_PI;\n }\n\n return value;\n }\n\n let queryString = objectToQuery(resource.queryParameters);\n\n // objectToQuery escapes [ and ], so fix that\n queryString = queryString.replace(/%5B/g, \"[\").replace(/%5D/g, \"]\");\n\n if (defined(camera) && camera._mode !== SceneMode.MORPHING) {\n let centerCartesian;\n let centerCartographic;\n\n bbox = defaultValue(bbox, zeroRectangle);\n if (defined(canvas)) {\n scratchCartesian2.x = canvas.clientWidth * 0.5;\n scratchCartesian2.y = canvas.clientHeight * 0.5;\n centerCartesian = camera.pickEllipsoid(\n scratchCartesian2,\n ellipsoid,\n scratchCartesian3\n );\n }\n\n if (defined(centerCartesian)) {\n centerCartographic = ellipsoid.cartesianToCartographic(\n centerCartesian,\n scratchCartographic\n );\n } else {\n centerCartographic = Rectangle.center(bbox, scratchCartographic);\n centerCartesian = ellipsoid.cartographicToCartesian(centerCartographic);\n }\n\n if (\n defined(viewBoundScale) &&\n !CesiumMath.equalsEpsilon(viewBoundScale, 1.0, CesiumMath.EPSILON9)\n ) {\n const newHalfWidth = bbox.width * viewBoundScale * 0.5;\n const newHalfHeight = bbox.height * viewBoundScale * 0.5;\n bbox = new Rectangle(\n fixLongitude(centerCartographic.longitude - newHalfWidth),\n fixLatitude(centerCartographic.latitude - newHalfHeight),\n fixLongitude(centerCartographic.longitude + newHalfWidth),\n fixLatitude(centerCartographic.latitude + newHalfHeight)\n );\n }\n\n queryString = queryString.replace(\n \"[bboxWest]\",\n CesiumMath.toDegrees(bbox.west).toString()\n );\n queryString = queryString.replace(\n \"[bboxSouth]\",\n CesiumMath.toDegrees(bbox.south).toString()\n );\n queryString = queryString.replace(\n \"[bboxEast]\",\n CesiumMath.toDegrees(bbox.east).toString()\n );\n queryString = queryString.replace(\n \"[bboxNorth]\",\n CesiumMath.toDegrees(bbox.north).toString()\n );\n\n const lon = CesiumMath.toDegrees(centerCartographic.longitude).toString();\n const lat = CesiumMath.toDegrees(centerCartographic.latitude).toString();\n queryString = queryString.replace(\"[lookatLon]\", lon);\n queryString = queryString.replace(\"[lookatLat]\", lat);\n queryString = queryString.replace(\n \"[lookatTilt]\",\n CesiumMath.toDegrees(camera.pitch).toString()\n );\n queryString = queryString.replace(\n \"[lookatHeading]\",\n CesiumMath.toDegrees(camera.heading).toString()\n );\n queryString = queryString.replace(\n \"[lookatRange]\",\n Cartesian3.distance(camera.positionWC, centerCartesian)\n );\n queryString = queryString.replace(\"[lookatTerrainLon]\", lon);\n queryString = queryString.replace(\"[lookatTerrainLat]\", lat);\n queryString = queryString.replace(\n \"[lookatTerrainAlt]\",\n centerCartographic.height.toString()\n );\n\n ellipsoid.cartesianToCartographic(camera.positionWC, scratchCartographic);\n queryString = queryString.replace(\n \"[cameraLon]\",\n CesiumMath.toDegrees(scratchCartographic.longitude).toString()\n );\n queryString = queryString.replace(\n \"[cameraLat]\",\n CesiumMath.toDegrees(scratchCartographic.latitude).toString()\n );\n queryString = queryString.replace(\n \"[cameraAlt]\",\n CesiumMath.toDegrees(scratchCartographic.height).toString()\n );\n\n const frustum = camera.frustum;\n const aspectRatio = frustum.aspectRatio;\n let horizFov = \"\";\n let vertFov = \"\";\n if (defined(aspectRatio)) {\n const fov = CesiumMath.toDegrees(frustum.fov);\n if (aspectRatio > 1.0) {\n horizFov = fov;\n vertFov = fov / aspectRatio;\n } else {\n vertFov = fov;\n horizFov = fov * aspectRatio;\n }\n }\n queryString = queryString.replace(\"[horizFov]\", horizFov.toString());\n queryString = queryString.replace(\"[vertFov]\", vertFov.toString());\n } else {\n queryString = queryString.replace(\"[bboxWest]\", \"-180\");\n queryString = queryString.replace(\"[bboxSouth]\", \"-90\");\n queryString = queryString.replace(\"[bboxEast]\", \"180\");\n queryString = queryString.replace(\"[bboxNorth]\", \"90\");\n\n queryString = queryString.replace(\"[lookatLon]\", \"\");\n queryString = queryString.replace(\"[lookatLat]\", \"\");\n queryString = queryString.replace(\"[lookatRange]\", \"\");\n queryString = queryString.replace(\"[lookatTilt]\", \"\");\n queryString = queryString.replace(\"[lookatHeading]\", \"\");\n queryString = queryString.replace(\"[lookatTerrainLon]\", \"\");\n queryString = queryString.replace(\"[lookatTerrainLat]\", \"\");\n queryString = queryString.replace(\"[lookatTerrainAlt]\", \"\");\n\n queryString = queryString.replace(\"[cameraLon]\", \"\");\n queryString = queryString.replace(\"[cameraLat]\", \"\");\n queryString = queryString.replace(\"[cameraAlt]\", \"\");\n queryString = queryString.replace(\"[horizFov]\", \"\");\n queryString = queryString.replace(\"[vertFov]\", \"\");\n }\n\n if (defined(canvas)) {\n queryString = queryString.replace(\"[horizPixels]\", canvas.clientWidth);\n queryString = queryString.replace(\"[vertPixels]\", canvas.clientHeight);\n } else {\n queryString = queryString.replace(\"[horizPixels]\", \"\");\n queryString = queryString.replace(\"[vertPixels]\", \"\");\n }\n\n queryString = queryString.replace(\"[terrainEnabled]\", \"1\");\n queryString = queryString.replace(\"[clientVersion]\", \"1\");\n queryString = queryString.replace(\"[kmlVersion]\", \"2.2\");\n queryString = queryString.replace(\"[clientName]\", \"Cesium\");\n queryString = queryString.replace(\"[language]\", \"English\");\n\n resource.setQueryParameters(queryToObject(queryString));\n}\n\nfunction processNetworkLink(dataSource, node, processingData, deferredLoading) {\n const r = processFeature(dataSource, node, processingData);\n const networkEntity = r.entity;\n\n const sourceResource = processingData.sourceResource;\n const uriResolver = processingData.uriResolver;\n\n let link = queryFirstNode(node, \"Link\", namespaces.kml);\n\n if (!defined(link)) {\n link = queryFirstNode(node, \"Url\", namespaces.kml);\n }\n if (defined(link)) {\n let href = queryStringValue(link, \"href\", namespaces.kml);\n let viewRefreshMode;\n let viewBoundScale;\n if (defined(href)) {\n let newSourceUri = href;\n href = resolveHref(href, sourceResource, processingData.uriResolver);\n\n // We need to pass in the original path if resolveHref returns a data uri because the network link\n // references a document in a KMZ archive\n if (/^data:/.test(href.getUrlComponent())) {\n // So if sourceUri isn't the kmz file, then its another kml in the archive, so resolve it\n if (!/\\.kmz/i.test(sourceResource.getUrlComponent())) {\n newSourceUri = sourceResource.getDerivedResource({\n url: newSourceUri,\n });\n }\n } else {\n newSourceUri = href.clone(); // Not a data uri so use the fully qualified uri\n viewRefreshMode = queryStringValue(\n link,\n \"viewRefreshMode\",\n namespaces.kml\n );\n if (viewRefreshMode === \"onRegion\") {\n oneTimeWarning(\n \"kml-refrehMode-onRegion\",\n \"KML - Unsupported viewRefreshMode: onRegion\"\n );\n return;\n }\n viewBoundScale = defaultValue(\n queryStringValue(link, \"viewBoundScale\", namespaces.kml),\n 1.0\n );\n const defaultViewFormat =\n viewRefreshMode === \"onStop\"\n ? \"BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]\"\n : \"\";\n const viewFormat = defaultValue(\n queryStringValue(link, \"viewFormat\", namespaces.kml),\n defaultViewFormat\n );\n const httpQuery = queryStringValue(link, \"httpQuery\", namespaces.kml);\n if (defined(viewFormat)) {\n href.setQueryParameters(queryToObject(cleanupString(viewFormat)));\n }\n if (defined(httpQuery)) {\n href.setQueryParameters(queryToObject(cleanupString(httpQuery)));\n }\n\n const ellipsoid = dataSource._ellipsoid;\n processNetworkLinkQueryString(\n href,\n dataSource.camera,\n dataSource.canvas,\n viewBoundScale,\n dataSource._lastCameraView.bbox,\n ellipsoid\n );\n }\n\n const options = {\n sourceUri: newSourceUri,\n uriResolver: uriResolver,\n context: networkEntity.id,\n screenOverlayContainer: processingData.screenOverlayContainer,\n };\n const networkLinkCollection = new EntityCollection();\n const promise = load(dataSource, networkLinkCollection, href, options)\n .then(function (rootElement) {\n const entities = dataSource._entityCollection;\n const newEntities = networkLinkCollection.values;\n entities.suspendEvents();\n for (let i = 0; i < newEntities.length; i++) {\n const newEntity = newEntities[i];\n if (!defined(newEntity.parent)) {\n newEntity.parent = networkEntity;\n mergeAvailabilityWithParent(newEntity);\n }\n\n entities.add(newEntity);\n }\n entities.resumeEvents();\n\n // Add network links to a list if we need they will need to be updated\n const refreshMode = queryStringValue(\n link,\n \"refreshMode\",\n namespaces.kml\n );\n let refreshInterval = defaultValue(\n queryNumericValue(link, \"refreshInterval\", namespaces.kml),\n 0\n );\n if (\n (refreshMode === \"onInterval\" && refreshInterval > 0) ||\n refreshMode === \"onExpire\" ||\n viewRefreshMode === \"onStop\"\n ) {\n const networkLinkControl = queryFirstNode(\n rootElement,\n \"NetworkLinkControl\",\n namespaces.kml\n );\n const hasNetworkLinkControl = defined(networkLinkControl);\n\n const now = JulianDate.now();\n const networkLinkInfo = {\n id: createGuid(),\n href: href,\n cookie: {},\n lastUpdated: now,\n updating: false,\n entity: networkEntity,\n viewBoundScale: viewBoundScale,\n needsUpdate: false,\n cameraUpdateTime: now,\n };\n\n let minRefreshPeriod = 0;\n if (hasNetworkLinkControl) {\n networkLinkInfo.cookie = queryToObject(\n defaultValue(\n queryStringValue(\n networkLinkControl,\n \"cookie\",\n namespaces.kml\n ),\n \"\"\n )\n );\n minRefreshPeriod = defaultValue(\n queryNumericValue(\n networkLinkControl,\n \"minRefreshPeriod\",\n namespaces.kml\n ),\n 0\n );\n }\n\n if (refreshMode === \"onInterval\") {\n if (hasNetworkLinkControl) {\n refreshInterval = Math.max(minRefreshPeriod, refreshInterval);\n }\n networkLinkInfo.refreshMode = RefreshMode.INTERVAL;\n networkLinkInfo.time = refreshInterval;\n } else if (refreshMode === \"onExpire\") {\n let expires;\n if (hasNetworkLinkControl) {\n expires = queryStringValue(\n networkLinkControl,\n \"expires\",\n namespaces.kml\n );\n }\n if (defined(expires)) {\n try {\n const date = JulianDate.fromIso8601(expires);\n const diff = JulianDate.secondsDifference(date, now);\n if (diff > 0 && diff < minRefreshPeriod) {\n JulianDate.addSeconds(now, minRefreshPeriod, date);\n }\n networkLinkInfo.refreshMode = RefreshMode.EXPIRE;\n networkLinkInfo.time = date;\n } catch (e) {\n oneTimeWarning(\n \"kml-refreshMode-onInterval-onExpire\",\n \"KML - NetworkLinkControl expires is not a valid date\"\n );\n }\n } else {\n oneTimeWarning(\n \"kml-refreshMode-onExpire\",\n \"KML - refreshMode of onExpire requires the NetworkLinkControl to have an expires element\"\n );\n }\n } else if (defined(dataSource.camera)) {\n // Only allow onStop refreshes if we have a camera\n networkLinkInfo.refreshMode = RefreshMode.STOP;\n networkLinkInfo.time = defaultValue(\n queryNumericValue(link, \"viewRefreshTime\", namespaces.kml),\n 0\n );\n } else {\n oneTimeWarning(\n \"kml-refrehMode-onStop-noCamera\",\n \"A NetworkLink with viewRefreshMode=onStop requires the `camera` property to be defined.\"\n );\n }\n\n if (defined(networkLinkInfo.refreshMode)) {\n dataSource._networkLinks.set(networkLinkInfo.id, networkLinkInfo);\n }\n }\n })\n .catch(function (error) {\n oneTimeWarning(`An error occured during loading ${href.url}`);\n dataSource._error.raiseEvent(dataSource, error);\n });\n\n deferredLoading.addPromise(promise);\n }\n }\n}\n\nfunction processFeatureNode(dataSource, node, processingData, deferredLoading) {\n const featureProcessor = featureTypes[node.localName];\n if (defined(featureProcessor)) {\n return featureProcessor(dataSource, node, processingData, deferredLoading);\n }\n\n return processUnsupportedFeature(\n dataSource,\n node,\n processingData,\n deferredLoading\n );\n}\n\nfunction loadKml(\n dataSource,\n entityCollection,\n kml,\n sourceResource,\n uriResolver,\n screenOverlayContainer,\n context\n) {\n entityCollection.removeAll();\n\n const documentElement = kml.documentElement;\n const document =\n documentElement.localName === \"Document\"\n ? documentElement\n : queryFirstNode(documentElement, \"Document\", namespaces.kml);\n let name = queryStringValue(document, \"name\", namespaces.kml);\n if (!defined(name)) {\n name = getFilenameFromUri(sourceResource.getUrlComponent());\n }\n\n // Only set the name from the root document\n if (!defined(dataSource._name)) {\n dataSource._name = name;\n }\n\n const deferredLoading = new KmlDataSource._DeferredLoading(dataSource);\n const styleCollection = new EntityCollection(dataSource);\n return Promise.all(\n processStyles(\n dataSource,\n kml,\n styleCollection,\n sourceResource,\n false,\n uriResolver\n )\n ).then(function () {\n let element = kml.documentElement;\n if (element.localName === \"kml\") {\n const childNodes = element.childNodes;\n for (let i = 0; i < childNodes.length; i++) {\n const tmp = childNodes[i];\n if (defined(featureTypes[tmp.localName])) {\n element = tmp;\n break;\n }\n }\n }\n\n const processingData = {\n parentEntity: undefined,\n entityCollection: entityCollection,\n styleCollection: styleCollection,\n sourceResource: sourceResource,\n uriResolver: uriResolver,\n context: context,\n screenOverlayContainer: screenOverlayContainer,\n };\n\n entityCollection.suspendEvents();\n processFeatureNode(dataSource, element, processingData, deferredLoading);\n entityCollection.resumeEvents();\n\n return deferredLoading.wait().then(function () {\n return kml.documentElement;\n });\n });\n}\n\nfunction loadKmz(\n dataSource,\n entityCollection,\n blob,\n sourceResource,\n screenOverlayContainer\n) {\n const zWorkerUrl = buildModuleUrl(\"ThirdParty/Workers/z-worker-pako.js\");\n zip.configure({\n workerScripts: {\n deflate: [zWorkerUrl, \"./pako_deflate.min.js\"],\n inflate: [zWorkerUrl, \"./pako_inflate.min.js\"],\n },\n });\n\n const reader = new zip.ZipReader(new zip.BlobReader(blob));\n return Promise.resolve(reader.getEntries()).then(function (entries) {\n const promises = [];\n const uriResolver = {};\n let docEntry;\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!entry.directory) {\n if (/\\.kml$/i.test(entry.filename)) {\n // We use the first KML document we come across\n // https://developers.google.com/kml/documentation/kmzarchives\n // Unless we come across a .kml file at the root of the archive because GE does this\n if (!defined(docEntry) || !/\\//i.test(entry.filename)) {\n if (defined(docEntry)) {\n // We found one at the root so load the initial kml as a data uri\n promises.push(loadDataUriFromZip(docEntry, uriResolver));\n }\n docEntry = entry;\n } else {\n // Wasn't the first kml and wasn't at the root\n promises.push(loadDataUriFromZip(entry, uriResolver));\n }\n } else {\n promises.push(loadDataUriFromZip(entry, uriResolver));\n }\n }\n }\n\n // Now load the root KML document\n if (defined(docEntry)) {\n promises.push(loadXmlFromZip(docEntry, uriResolver));\n }\n return Promise.all(promises).then(function () {\n reader.close();\n if (!defined(uriResolver.kml)) {\n throw new RuntimeError(\"KMZ file does not contain a KML document.\");\n }\n uriResolver.keys = Object.keys(uriResolver);\n return loadKml(\n dataSource,\n entityCollection,\n uriResolver.kml,\n sourceResource,\n uriResolver,\n screenOverlayContainer\n );\n });\n });\n}\n\nfunction load(dataSource, entityCollection, data, options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n let sourceUri = options.sourceUri;\n const uriResolver = options.uriResolver;\n const context = options.context;\n let screenOverlayContainer = options.screenOverlayContainer;\n\n let promise = data;\n if (typeof data === \"string\" || data instanceof Resource) {\n data = Resource.createIfNeeded(data);\n promise = data.fetchBlob();\n sourceUri = defaultValue(sourceUri, data.clone());\n\n // Add resource credits to our list of credits to display\n const resourceCredits = dataSource._resourceCredits;\n const credits = data.credits;\n if (defined(credits)) {\n const length = credits.length;\n for (let i = 0; i < length; i++) {\n resourceCredits.push(credits[i]);\n }\n }\n } else {\n sourceUri = defaultValue(sourceUri, Resource.DEFAULT.clone());\n }\n\n sourceUri = Resource.createIfNeeded(sourceUri);\n\n if (defined(screenOverlayContainer)) {\n screenOverlayContainer = getElement(screenOverlayContainer);\n }\n\n return Promise.resolve(promise)\n .then(function (dataToLoad) {\n if (dataToLoad instanceof Blob) {\n return isZipFile(dataToLoad).then(function (isZip) {\n if (isZip) {\n return loadKmz(\n dataSource,\n entityCollection,\n dataToLoad,\n sourceUri,\n screenOverlayContainer\n );\n }\n return readBlobAsText(dataToLoad).then(function (text) {\n //There's no official way to validate if a parse was successful.\n //The following check detects the error on various browsers.\n\n //Insert missing namespaces\n text = insertNamespaces(text);\n\n //Remove Duplicate Namespaces\n text = removeDuplicateNamespaces(text);\n\n //IE raises an exception\n let kml;\n let error;\n try {\n kml = parser.parseFromString(text, \"application/xml\");\n } catch (e) {\n error = e.toString();\n }\n\n //The parse succeeds on Chrome and Firefox, but the error\n //handling is different in each.\n if (\n defined(error) ||\n kml.body ||\n kml.documentElement.tagName === \"parsererror\"\n ) {\n //Firefox has error information as the firstChild nodeValue.\n let msg = defined(error)\n ? error\n : kml.documentElement.firstChild.nodeValue;\n\n //Chrome has it in the body text.\n if (!msg) {\n msg = kml.body.innerText;\n }\n\n //Return the error\n throw new RuntimeError(msg);\n }\n return loadKml(\n dataSource,\n entityCollection,\n kml,\n sourceUri,\n uriResolver,\n screenOverlayContainer,\n context\n );\n });\n });\n }\n return loadKml(\n dataSource,\n entityCollection,\n dataToLoad,\n sourceUri,\n uriResolver,\n screenOverlayContainer,\n context\n );\n })\n .catch(function (error) {\n dataSource._error.raiseEvent(dataSource, error);\n console.log(error);\n return Promise.reject(error);\n });\n}\n\n// NOTE: LoadOptions properties are repeated in ConstructorOptions because some\n// tooling does not support \"base types\" for @typedef. Remove if/when\n// https://github.com/microsoft/TypeScript/issues/20077 and/or\n// https://github.com/jsdoc/jsdoc/issues/1199 actually get resolved\n/**\n * @typedef {object} KmlDataSource.LoadOptions\n *\n * Initialization options for the `load` method.\n *\n * @property {string} [sourceUri] Overrides the url to use for resolving relative links and other KML network features.\n * @property {boolean} [clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground.\n * @property {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.\n * @property {Element|string} [screenOverlayContainer] A container for ScreenOverlay images.\n */\n\n/**\n * @typedef {object} KmlDataSource.ConstructorOptions\n *\n * Options for constructing a new KmlDataSource, or calling the static `load` method.\n *\n * @property {Camera} [camera] The camera that is used for viewRefreshModes and sending camera properties to network links.\n * @property {HTMLCanvasElement} [canvas] The canvas that is used for sending viewer properties to network links.\n * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.\n *\n * @property {string} [sourceUri] Overrides the url to use for resolving relative links and other KML network features.\n * @property {boolean} [clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground.\n * @property {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.\n * @property {Element|string} [screenOverlayContainer] A container for ScreenOverlay images.\n\n*/\n\n/**\n * A {@link DataSource} which processes Keyhole Markup Language 2.2 (KML).\n *

\n * KML support in Cesium is incomplete, but a large amount of the standard,\n * as well as Google's gx extension namespace, is supported. See Github issue\n * {@link https://github.com/CesiumGS/cesium/issues/873|#873} for a\n * detailed list of what is and isn't supported. Cesium will also write information to the\n * console when it encounters most unsupported features.\n *

\n *

\n * Non visual feature data, such as atom:author and ExtendedData\n * is exposed via an instance of {@link KmlFeatureData}, which is added to each {@link Entity}\n * under the kml property.\n *

\n *\n * @alias KmlDataSource\n * @constructor\n *\n * @param {KmlDataSource.ConstructorOptions} [options] Object describing initialization options\n *\n * @see {@link http://www.opengeospatial.org/standards/kml/|Open Geospatial Consortium KML Standard}\n * @see {@link https://developers.google.com/kml/|Google KML Documentation}\n *\n * @demo {@link https://sandcastle.cesium.com/index.html?src=KML.html|Cesium Sandcastle KML Demo}\n *\n * @example\n * const viewer = new Cesium.Viewer('cesiumContainer');\n * viewer.dataSources.add(Cesium.KmlDataSource.load('../../SampleData/facilities.kmz',\n * {\n * camera: viewer.scene.camera,\n * canvas: viewer.scene.canvas\n * })\n * );\n */\nfunction KmlDataSource(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const camera = options.camera;\n const canvas = options.canvas;\n\n this._changed = new Event();\n this._error = new Event();\n this._loading = new Event();\n this._refresh = new Event();\n this._unsupportedNode = new Event();\n\n this._clock = undefined;\n this._entityCollection = new EntityCollection(this);\n this._name = undefined;\n this._isLoading = false;\n this._pinBuilder = new PinBuilder();\n this._networkLinks = new AssociativeArray();\n this._entityCluster = new EntityCluster();\n\n /**\n * The current size of this Canvas will be used to populate the Link parameters\n * for client height and width.\n *\n * @type {HTMLCanvasElement | undefined}\n */\n this.canvas = canvas;\n\n /**\n * The position and orientation of this {@link Camera} will be used to\n * populate various camera parameters when making network requests.\n * Camera movement will determine when to trigger NetworkLink refresh if\n * viewRefreshMode is onStop.\n *\n * @type {Camera | undefined}\n */\n this.camera = camera;\n\n this._lastCameraView = {\n position: defined(camera) ? Cartesian3.clone(camera.positionWC) : undefined,\n direction: defined(camera)\n ? Cartesian3.clone(camera.directionWC)\n : undefined,\n up: defined(camera) ? Cartesian3.clone(camera.upWC) : undefined,\n bbox: defined(camera)\n ? camera.computeViewRectangle()\n : Rectangle.clone(Rectangle.MAX_VALUE),\n };\n\n this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);\n\n // User specified credit\n let credit = options.credit;\n if (typeof credit === \"string\") {\n credit = new Credit(credit);\n }\n this._credit = credit;\n\n // Create a list of Credit's from the resource that the user can't remove\n this._resourceCredits = [];\n\n this._kmlTours = [];\n\n this._screenOverlays = [];\n}\n\n/**\n * Creates a Promise to a new instance loaded with the provided KML data.\n *\n * @param {Resource|string|Document|Blob} data A url, parsed KML document, or Blob containing binary KMZ data or a parsed KML document.\n * @param {KmlDataSource.ConstructorOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that will resolve to a new KmlDataSource instance once the KML is loaded.\n */\nKmlDataSource.load = function (data, options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const dataSource = new KmlDataSource(options);\n return dataSource.load(data, options);\n};\n\nObject.defineProperties(KmlDataSource.prototype, {\n /**\n * Gets or sets a human-readable name for this instance.\n * This will be automatically be set to the KML document name on load.\n * @memberof KmlDataSource.prototype\n * @type {string}\n */\n name: {\n get: function () {\n return this._name;\n },\n set: function (value) {\n if (this._name !== value) {\n this._name = value;\n this._changed.raiseEvent(this);\n }\n },\n },\n /**\n * Gets the clock settings defined by the loaded KML. This represents the total\n * availability interval for all time-dynamic data. If the KML does not contain\n * time-dynamic data, this value is undefined.\n * @memberof KmlDataSource.prototype\n * @type {DataSourceClock}\n */\n clock: {\n get: function () {\n return this._clock;\n },\n },\n /**\n * Gets the collection of {@link Entity} instances.\n * @memberof KmlDataSource.prototype\n * @type {EntityCollection}\n */\n entities: {\n get: function () {\n return this._entityCollection;\n },\n },\n /**\n * Gets a value indicating if the data source is currently loading data.\n * @memberof KmlDataSource.prototype\n * @type {boolean}\n */\n isLoading: {\n get: function () {\n return this._isLoading;\n },\n },\n /**\n * Gets an event that will be raised when the underlying data changes.\n * @memberof KmlDataSource.prototype\n * @type {Event}\n */\n changedEvent: {\n get: function () {\n return this._changed;\n },\n },\n /**\n * Gets an event that will be raised if an error is encountered during processing.\n * @memberof KmlDataSource.prototype\n * @type {Event}\n */\n errorEvent: {\n get: function () {\n return this._error;\n },\n },\n /**\n * Gets an event that will be raised when the data source either starts or stops loading.\n * @memberof KmlDataSource.prototype\n * @type {Event}\n */\n loadingEvent: {\n get: function () {\n return this._loading;\n },\n },\n /**\n * Gets an event that will be raised when the data source refreshes a network link.\n * @memberof KmlDataSource.prototype\n * @type {Event}\n */\n refreshEvent: {\n get: function () {\n return this._refresh;\n },\n },\n /**\n * Gets an event that will be raised when the data source finds an unsupported node type.\n * @memberof KmlDataSource.prototype\n * @type {Event}\n */\n unsupportedNodeEvent: {\n get: function () {\n return this._unsupportedNode;\n },\n },\n /**\n * Gets whether or not this data source should be displayed.\n * @memberof KmlDataSource.prototype\n * @type {boolean}\n */\n show: {\n get: function () {\n return this._entityCollection.show;\n },\n set: function (value) {\n this._entityCollection.show = value;\n },\n },\n\n /**\n * Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.\n *\n * @memberof KmlDataSource.prototype\n * @type {EntityCluster}\n */\n clustering: {\n get: function () {\n return this._entityCluster;\n },\n set: function (value) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(value)) {\n throw new DeveloperError(\"value must be defined.\");\n }\n //>>includeEnd('debug');\n this._entityCluster = value;\n },\n },\n /**\n * Gets the credit that will be displayed for the data source\n * @memberof KmlDataSource.prototype\n * @type {Credit}\n */\n credit: {\n get: function () {\n return this._credit;\n },\n },\n /**\n * Gets the KML Tours that are used to guide the camera to specified destinations on given time intervals.\n * @memberof KmlDataSource.prototype\n * @type {KmlTour[]}\n */\n kmlTours: {\n get: function () {\n return this._kmlTours;\n },\n },\n});\n\n/**\n * Asynchronously loads the provided KML data, replacing any existing data.\n *\n * @param {Resource|string|Document|Blob} data A url, parsed KML document, or Blob containing binary KMZ data or a parsed KML document.\n * @param {KmlDataSource.LoadOptions} [options] An object specifying configuration options\n *\n * @returns {Promise} A promise that will resolve to this instances once the KML is loaded.\n */\nKmlDataSource.prototype.load = function (data, options) {\n //>>includeStart('debug', pragmas.debug);\n if (!defined(data)) {\n throw new DeveloperError(\"data is required.\");\n }\n //>>includeEnd('debug');\n\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n DataSource.setLoading(this, true);\n\n const oldName = this._name;\n this._name = undefined;\n this._clampToGround = defaultValue(options.clampToGround, false);\n\n const that = this;\n return load(this, this._entityCollection, data, options)\n .then(function () {\n let clock;\n\n const availability = that._entityCollection.computeAvailability();\n\n let start = availability.start;\n let stop = availability.stop;\n const isMinStart = JulianDate.equals(start, Iso8601.MINIMUM_VALUE);\n const isMaxStop = JulianDate.equals(stop, Iso8601.MAXIMUM_VALUE);\n if (!isMinStart || !isMaxStop) {\n let date;\n\n //If start is min time just start at midnight this morning, local time\n if (isMinStart) {\n date = new Date();\n date.setHours(0, 0, 0, 0);\n start = JulianDate.fromDate(date);\n }\n\n //If stop is max value just stop at midnight tonight, local time\n if (isMaxStop) {\n date = new Date();\n date.setHours(24, 0, 0, 0);\n stop = JulianDate.fromDate(date);\n }\n\n clock = new DataSourceClock();\n clock.startTime = start;\n clock.stopTime = stop;\n clock.currentTime = JulianDate.clone(start);\n clock.clockRange = ClockRange.LOOP_STOP;\n clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;\n clock.multiplier = Math.round(\n Math.min(\n Math.max(JulianDate.secondsDifference(stop, start) / 60, 1),\n 3.15569e7\n )\n );\n }\n\n let changed = false;\n if (clock !== that._clock) {\n that._clock = clock;\n changed = true;\n }\n\n if (oldName !== that._name) {\n changed = true;\n }\n\n if (changed) {\n that._changed.raiseEvent(that);\n }\n\n DataSource.setLoading(that, false);\n\n return that;\n })\n .catch(function (error) {\n DataSource.setLoading(that, false);\n that._error.raiseEvent(that, error);\n console.log(error);\n return Promise.reject(error);\n });\n};\n\n/**\n * Cleans up any non-entity elements created by the data source. Currently this only affects ScreenOverlay elements.\n */\nKmlDataSource.prototype.destroy = function () {\n while (this._screenOverlays.length > 0) {\n const elem = this._screenOverlays.pop();\n elem.remove();\n }\n};\n\nfunction mergeAvailabilityWithParent(child) {\n const parent = child.parent;\n if (defined(parent)) {\n const parentAvailability = parent.availability;\n if (defined(parentAvailability)) {\n const childAvailability = child.availability;\n if (defined(childAvailability)) {\n childAvailability.intersect(parentAvailability);\n } else {\n child.availability = parentAvailability;\n }\n }\n }\n}\n\nfunction getNetworkLinkUpdateCallback(\n dataSource,\n networkLink,\n newEntityCollection,\n networkLinks,\n processedHref\n) {\n return function (rootElement) {\n if (!networkLinks.contains(networkLink.id)) {\n // Got into the odd case where a parent network link was updated while a child\n // network link update was in flight, so just throw it away.\n return;\n }\n let remove = false;\n const networkLinkControl = queryFirstNode(\n rootElement,\n \"NetworkLinkControl\",\n namespaces.kml\n );\n const hasNetworkLinkControl = defined(networkLinkControl);\n\n let minRefreshPeriod = 0;\n if (hasNetworkLinkControl) {\n if (\n defined(queryFirstNode(networkLinkControl, \"Update\", namespaces.kml))\n ) {\n oneTimeWarning(\n \"kml-networkLinkControl-update\",\n \"KML - NetworkLinkControl updates aren't supported.\"\n );\n networkLink.updating = false;\n networkLinks.remove(networkLink.id);\n return;\n }\n networkLink.cookie = queryToObject(\n defaultValue(\n queryStringValue(networkLinkControl, \"cookie\", namespaces.kml),\n \"\"\n )\n );\n minRefreshPeriod = defaultValue(\n queryNumericValue(\n networkLinkControl,\n \"minRefreshPeriod\",\n namespaces.kml\n ),\n 0\n );\n }\n\n const now = JulianDate.now();\n const refreshMode = networkLink.refreshMode;\n if (refreshMode === RefreshMode.INTERVAL) {\n if (defined(networkLinkControl)) {\n networkLink.time = Math.max(minRefreshPeriod, networkLink.time);\n }\n } else if (refreshMode === RefreshMode.EXPIRE) {\n let expires;\n if (defined(networkLinkControl)) {\n expires = queryStringValue(\n networkLinkControl,\n \"expires\",\n namespaces.kml\n );\n }\n if (defined(expires)) {\n try {\n const date = JulianDate.fromIso8601(expires);\n const diff = JulianDate.secondsDifference(date, now);\n if (diff > 0 && diff < minRefreshPeriod) {\n JulianDate.addSeconds(now, minRefreshPeriod, date);\n }\n networkLink.time = date;\n } catch (e) {\n oneTimeWarning(\n \"kml-networkLinkControl-expires\",\n \"KML - NetworkLinkControl expires is not a valid date\"\n );\n remove = true;\n }\n } else {\n oneTimeWarning(\n \"kml-refreshMode-onExpire\",\n \"KML - refreshMode of onExpire requires the NetworkLinkControl to have an expires element\"\n );\n remove = true;\n }\n }\n\n const networkLinkEntity = networkLink.entity;\n const entityCollection = dataSource._entityCollection;\n const newEntities = newEntityCollection.values;\n\n function removeChildren(entity) {\n entityCollection.remove(entity);\n const children = entity._children;\n const count = children.length;\n for (let i = 0; i < count; ++i) {\n removeChildren(children[i]);\n }\n }\n\n // Remove old entities\n entityCollection.suspendEvents();\n const entitiesCopy = entityCollection.values.slice();\n let i;\n for (i = 0; i < entitiesCopy.length; ++i) {\n const entityToRemove = entitiesCopy[i];\n if (entityToRemove.parent === networkLinkEntity) {\n entityToRemove.parent = undefined;\n removeChildren(entityToRemove);\n }\n }\n entityCollection.resumeEvents();\n\n // Add new entities\n entityCollection.suspendEvents();\n for (i = 0; i < newEntities.length; i++) {\n const newEntity = newEntities[i];\n if (!defined(newEntity.parent)) {\n newEntity.parent = networkLinkEntity;\n mergeAvailabilityWithParent(newEntity);\n }\n entityCollection.add(newEntity);\n }\n entityCollection.resumeEvents();\n\n // No refresh information remove it, otherwise update lastUpdate time\n if (remove) {\n networkLinks.remove(networkLink.id);\n } else {\n networkLink.lastUpdated = now;\n }\n\n const availability = entityCollection.computeAvailability();\n\n const start = availability.start;\n const stop = availability.stop;\n const isMinStart = JulianDate.equals(start, Iso8601.MINIMUM_VALUE);\n const isMaxStop = JulianDate.equals(stop, Iso8601.MAXIMUM_VALUE);\n if (!isMinStart || !isMaxStop) {\n const clock = dataSource._clock;\n\n if (clock.startTime !== start || clock.stopTime !== stop) {\n clock.startTime = start;\n clock.stopTime = stop;\n dataSource._changed.raiseEvent(dataSource);\n }\n }\n\n networkLink.updating = false;\n networkLink.needsUpdate = false;\n dataSource._refresh.raiseEvent(\n dataSource,\n processedHref.getUrlComponent(true)\n );\n };\n}\n\nconst entitiesToIgnore = new AssociativeArray();\n\n/**\n * Updates any NetworkLink that require updating.\n *\n * @param {JulianDate} time The simulation time.\n * @returns {boolean} True if this data source is ready to be displayed at the provided time, false otherwise.\n */\nKmlDataSource.prototype.update = function (time) {\n const networkLinks = this._networkLinks;\n if (networkLinks.length === 0) {\n return true;\n }\n\n const now = JulianDate.now();\n const that = this;\n\n entitiesToIgnore.removeAll();\n\n function recurseIgnoreEntities(entity) {\n const children = entity._children;\n const count = children.length;\n for (let i = 0; i < count; ++i) {\n const child = children[i];\n entitiesToIgnore.set(child.id, child);\n recurseIgnoreEntities(child);\n }\n }\n\n let cameraViewUpdate = false;\n const lastCameraView = this._lastCameraView;\n const camera = this.camera;\n if (\n defined(camera) &&\n !(\n camera.positionWC.equalsEpsilon(\n lastCameraView.position,\n CesiumMath.EPSILON7\n ) &&\n camera.directionWC.equalsEpsilon(\n lastCameraView.direction,\n CesiumMath.EPSILON7\n ) &&\n camera.upWC.equalsEpsilon(lastCameraView.up, CesiumMath.EPSILON7)\n )\n ) {\n // Camera has changed so update the last view\n lastCameraView.position = Cartesian3.clone(camera.positionWC);\n lastCameraView.direction = Cartesian3.clone(camera.directionWC);\n lastCameraView.up = Cartesian3.clone(camera.upWC);\n lastCameraView.bbox = camera.computeViewRectangle();\n cameraViewUpdate = true;\n }\n\n const newNetworkLinks = new AssociativeArray();\n let changed = false;\n networkLinks.values.forEach(function (networkLink) {\n const entity = networkLink.entity;\n if (entitiesToIgnore.contains(entity.id)) {\n return;\n }\n\n if (!networkLink.updating) {\n let doUpdate = false;\n if (networkLink.refreshMode === RefreshMode.INTERVAL) {\n if (\n JulianDate.secondsDifference(now, networkLink.lastUpdated) >\n networkLink.time\n ) {\n doUpdate = true;\n }\n } else if (networkLink.refreshMode === RefreshMode.EXPIRE) {\n if (JulianDate.greaterThan(now, networkLink.time)) {\n doUpdate = true;\n }\n } else if (networkLink.refreshMode === RefreshMode.STOP) {\n if (cameraViewUpdate) {\n networkLink.needsUpdate = true;\n networkLink.cameraUpdateTime = now;\n }\n\n if (\n networkLink.needsUpdate &&\n JulianDate.secondsDifference(now, networkLink.cameraUpdateTime) >=\n networkLink.time\n ) {\n doUpdate = true;\n }\n }\n\n if (doUpdate) {\n recurseIgnoreEntities(entity);\n networkLink.updating = true;\n const newEntityCollection = new EntityCollection();\n const href = networkLink.href.clone();\n\n href.setQueryParameters(networkLink.cookie);\n const ellipsoid = defaultValue(that._ellipsoid, Ellipsoid.WGS84);\n processNetworkLinkQueryString(\n href,\n that.camera,\n that.canvas,\n networkLink.viewBoundScale,\n lastCameraView.bbox,\n ellipsoid\n );\n\n load(that, newEntityCollection, href, {\n context: entity.id,\n })\n .then(\n getNetworkLinkUpdateCallback(\n that,\n networkLink,\n newEntityCollection,\n newNetworkLinks,\n href\n )\n )\n .catch(function (error) {\n const msg = `NetworkLink ${networkLink.href} refresh failed: ${error}`;\n console.log(msg);\n that._error.raiseEvent(that, msg);\n });\n changed = true;\n }\n }\n newNetworkLinks.set(networkLink.id, networkLink);\n });\n\n if (changed) {\n this._networkLinks = newNetworkLinks;\n this._changed.raiseEvent(this);\n }\n\n return true;\n};\n\n/**\n * Contains KML Feature data loaded into the Entity.kml property by {@link KmlDataSource}.\n * @alias KmlFeatureData\n * @constructor\n */\nfunction KmlFeatureData() {\n /**\n * @typedef KmlFeatureData.Author\n * @type {object}\n * @property {string} name Gets the name.\n * @property {string} uri Gets the URI.\n * @property {number} age Gets the email.\n */\n\n /**\n * Gets the atom syndication format author field.\n * @type {KmlFeatureData.Author}\n */\n this.author = {\n name: undefined,\n uri: undefined,\n email: undefined,\n };\n\n /**\n * @typedef KmlFeatureData.Link\n * @type {object}\n * @property {string} href Gets the href.\n * @property {string} hreflang Gets the language of the linked resource.\n * @property {string} rel Gets the link relation.\n * @property {string} type Gets the link type.\n * @property {string} title Gets the link title.\n * @property {string} length Gets the link length.\n */\n\n /**\n * Gets the link.\n * @type {KmlFeatureData.Link}\n */\n this.link = {\n href: undefined,\n hreflang: undefined,\n rel: undefined,\n type: undefined,\n title: undefined,\n length: undefined,\n };\n\n /**\n * Gets the unstructured address field.\n * @type {string}\n */\n this.address = undefined;\n /**\n * Gets the phone number.\n * @type {string}\n */\n this.phoneNumber = undefined;\n /**\n * Gets the snippet.\n * @type {string}\n */\n this.snippet = undefined;\n /**\n * Gets the extended data, parsed into a JSON object.\n * Currently only the Data property is supported.\n * SchemaData and custom data are ignored.\n * @type {string}\n */\n this.extendedData = undefined;\n}\n\n// For testing\nKmlDataSource._DeferredLoading = DeferredLoading;\nKmlDataSource._getTimestamp = getTimestamp;\n\nexport default KmlDataSource;\n", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/*\n * This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.\n * JZlib is based on zlib-1.1.3, so all credit should go authors\n * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)\n * and contributors of zlib.\n */\n\n// deno-lint-ignore-file no-this-alias prefer-const\n\n// Global\n\nconst MAX_BITS = 15;\nconst D_CODES = 30;\nconst BL_CODES = 19;\n\nconst LENGTH_CODES = 29;\nconst LITERALS = 256;\nconst L_CODES = (LITERALS + 1 + LENGTH_CODES);\nconst HEAP_SIZE = (2 * L_CODES + 1);\n\nconst END_BLOCK = 256;\n\n// Bit length codes must not exceed MAX_BL_BITS bits\nconst MAX_BL_BITS = 7;\n\n// repeat previous bit length 3-6 times (2 bits of repeat count)\nconst REP_3_6 = 16;\n\n// repeat a zero length 3-10 times (3 bits of repeat count)\nconst REPZ_3_10 = 17;\n\n// repeat a zero length 11-138 times (7 bits of repeat count)\nconst REPZ_11_138 = 18;\n\n// The lengths of the bit length codes are sent in order of decreasing\n// probability, to avoid transmitting the lengths for unused bit\n// length codes.\n\nconst Buf_size = 8 * 2;\n\n// JZlib version : \"1.0.2\"\nconst Z_DEFAULT_COMPRESSION = -1;\n\n// compression strategy\nconst Z_FILTERED = 1;\nconst Z_HUFFMAN_ONLY = 2;\nconst Z_DEFAULT_STRATEGY = 0;\n\nconst Z_NO_FLUSH = 0;\nconst Z_PARTIAL_FLUSH = 1;\nconst Z_FULL_FLUSH = 3;\nconst Z_FINISH = 4;\n\nconst Z_OK = 0;\nconst Z_STREAM_END = 1;\nconst Z_NEED_DICT = 2;\nconst Z_STREAM_ERROR = -2;\nconst Z_DATA_ERROR = -3;\nconst Z_BUF_ERROR = -5;\n\n// Tree\n\nfunction extractArray(array) {\n\treturn flatArray(array.map(([length, value]) => (new Array(length)).fill(value, 0, length)));\n}\n\nfunction flatArray(array) {\n\treturn array.reduce((a, b) => a.concat(Array.isArray(b) ? flatArray(b) : b), []);\n}\n\n// see definition of array dist_code below\nconst _dist_code = [0, 1, 2, 3].concat(...extractArray([\n\t[2, 4], [2, 5], [4, 6], [4, 7], [8, 8], [8, 9], [16, 10], [16, 11], [32, 12], [32, 13], [64, 14], [64, 15], [2, 0], [1, 16],\n\t[1, 17], [2, 18], [2, 19], [4, 20], [4, 21], [8, 22], [8, 23], [16, 24], [16, 25], [32, 26], [32, 27], [64, 28], [64, 29]\n]));\n\nfunction Tree() {\n\tconst that = this;\n\n\t// dyn_tree; // the dynamic tree\n\t// max_code; // largest code with non zero frequency\n\t// stat_desc; // the corresponding static tree\n\n\t// Compute the optimal bit lengths for a tree and update the total bit\n\t// length\n\t// for the current block.\n\t// IN assertion: the fields freq and dad are set, heap[heap_max] and\n\t// above are the tree nodes sorted by increasing frequency.\n\t// OUT assertions: the field len is set to the optimal bit length, the\n\t// array bl_count contains the frequencies for each bit length.\n\t// The length opt_len is updated; static_len is also updated if stree is\n\t// not null.\n\tfunction gen_bitlen(s) {\n\t\tconst tree = that.dyn_tree;\n\t\tconst stree = that.stat_desc.static_tree;\n\t\tconst extra = that.stat_desc.extra_bits;\n\t\tconst base = that.stat_desc.extra_base;\n\t\tconst max_length = that.stat_desc.max_length;\n\t\tlet h; // heap index\n\t\tlet n, m; // iterate over the tree elements\n\t\tlet bits; // bit length\n\t\tlet xbits; // extra bits\n\t\tlet f; // frequency\n\t\tlet overflow = 0; // number of elements with bit length too large\n\n\t\tfor (bits = 0; bits <= MAX_BITS; bits++)\n\t\t\ts.bl_count[bits] = 0;\n\n\t\t// In a first pass, compute the optimal bit lengths (which may\n\t\t// overflow in the case of the bit length tree).\n\t\ttree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap\n\n\t\tfor (h = s.heap_max + 1; h < HEAP_SIZE; h++) {\n\t\t\tn = s.heap[h];\n\t\t\tbits = tree[tree[n * 2 + 1] * 2 + 1] + 1;\n\t\t\tif (bits > max_length) {\n\t\t\t\tbits = max_length;\n\t\t\t\toverflow++;\n\t\t\t}\n\t\t\ttree[n * 2 + 1] = bits;\n\t\t\t// We overwrite tree[n*2+1] which is no longer needed\n\n\t\t\tif (n > that.max_code)\n\t\t\t\tcontinue; // not a leaf node\n\n\t\t\ts.bl_count[bits]++;\n\t\t\txbits = 0;\n\t\t\tif (n >= base)\n\t\t\t\txbits = extra[n - base];\n\t\t\tf = tree[n * 2];\n\t\t\ts.opt_len += f * (bits + xbits);\n\t\t\tif (stree)\n\t\t\t\ts.static_len += f * (stree[n * 2 + 1] + xbits);\n\t\t}\n\t\tif (overflow === 0)\n\t\t\treturn;\n\n\t\t// This happens for example on obj2 and pic of the Calgary corpus\n\t\t// Find the first bit length which could increase:\n\t\tdo {\n\t\t\tbits = max_length - 1;\n\t\t\twhile (s.bl_count[bits] === 0)\n\t\t\t\tbits--;\n\t\t\ts.bl_count[bits]--; // move one leaf down the tree\n\t\t\ts.bl_count[bits + 1] += 2; // move one overflow item as its brother\n\t\t\ts.bl_count[max_length]--;\n\t\t\t// The brother of the overflow item also moves one step up,\n\t\t\t// but this does not affect bl_count[max_length]\n\t\t\toverflow -= 2;\n\t\t} while (overflow > 0);\n\n\t\tfor (bits = max_length; bits !== 0; bits--) {\n\t\t\tn = s.bl_count[bits];\n\t\t\twhile (n !== 0) {\n\t\t\t\tm = s.heap[--h];\n\t\t\t\tif (m > that.max_code)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (tree[m * 2 + 1] != bits) {\n\t\t\t\t\ts.opt_len += (bits - tree[m * 2 + 1]) * tree[m * 2];\n\t\t\t\t\ttree[m * 2 + 1] = bits;\n\t\t\t\t}\n\t\t\t\tn--;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Reverse the first len bits of a code, using straightforward code (a\n\t// faster\n\t// method would use a table)\n\t// IN assertion: 1 <= len <= 15\n\tfunction bi_reverse(code, // the value to invert\n\t\tlen // its bit length\n\t) {\n\t\tlet res = 0;\n\t\tdo {\n\t\t\tres |= code & 1;\n\t\t\tcode >>>= 1;\n\t\t\tres <<= 1;\n\t\t} while (--len > 0);\n\t\treturn res >>> 1;\n\t}\n\n\t// Generate the codes for a given tree and bit counts (which need not be\n\t// optimal).\n\t// IN assertion: the array bl_count contains the bit length statistics for\n\t// the given tree and the field len is set for all tree elements.\n\t// OUT assertion: the field code is set for all tree elements of non\n\t// zero code length.\n\tfunction gen_codes(tree, // the tree to decorate\n\t\tmax_code, // largest code with non zero frequency\n\t\tbl_count // number of codes at each bit length\n\t) {\n\t\tconst next_code = []; // next code value for each\n\t\t// bit length\n\t\tlet code = 0; // running code value\n\t\tlet bits; // bit index\n\t\tlet n; // code index\n\t\tlet len;\n\n\t\t// The distribution counts are first used to generate the code values\n\t\t// without bit reversal.\n\t\tfor (bits = 1; bits <= MAX_BITS; bits++) {\n\t\t\tnext_code[bits] = code = ((code + bl_count[bits - 1]) << 1);\n\t\t}\n\n\t\t// Check that the bit counts in bl_count are consistent. The last code\n\t\t// must be all ones.\n\t\t// Assert (code + bl_count[MAX_BITS]-1 == (1<= 1; n--)\n\t\t\ts.pqdownheap(tree, n);\n\n\t\t// Construct the Huffman tree by repeatedly combining the least two\n\t\t// frequent nodes.\n\n\t\tnode = elems; // next internal node of the tree\n\t\tdo {\n\t\t\t// n = node of least frequency\n\t\t\tn = s.heap[1];\n\t\t\ts.heap[1] = s.heap[s.heap_len--];\n\t\t\ts.pqdownheap(tree, 1);\n\t\t\tm = s.heap[1]; // m = node of next least frequency\n\n\t\t\ts.heap[--s.heap_max] = n; // keep the nodes sorted by frequency\n\t\t\ts.heap[--s.heap_max] = m;\n\n\t\t\t// Create a new node father of n and m\n\t\t\ttree[node * 2] = (tree[n * 2] + tree[m * 2]);\n\t\t\ts.depth[node] = Math.max(s.depth[n], s.depth[m]) + 1;\n\t\t\ttree[n * 2 + 1] = tree[m * 2 + 1] = node;\n\n\t\t\t// and insert the new node in the heap\n\t\t\ts.heap[1] = node++;\n\t\t\ts.pqdownheap(tree, 1);\n\t\t} while (s.heap_len >= 2);\n\n\t\ts.heap[--s.heap_max] = s.heap[1];\n\n\t\t// At this point, the fields freq and dad are set. We can now\n\t\t// generate the bit lengths.\n\n\t\tgen_bitlen(s);\n\n\t\t// The field len is now set, we can generate the bit codes\n\t\tgen_codes(tree, that.max_code, s.bl_count);\n\t};\n\n}\n\nTree._length_code = [0, 1, 2, 3, 4, 5, 6, 7].concat(...extractArray([\n\t[2, 8], [2, 9], [2, 10], [2, 11], [4, 12], [4, 13], [4, 14], [4, 15], [8, 16], [8, 17], [8, 18], [8, 19],\n\t[16, 20], [16, 21], [16, 22], [16, 23], [32, 24], [32, 25], [32, 26], [31, 27], [1, 28]]));\n\nTree.base_length = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0];\n\nTree.base_dist = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384,\n\t24576];\n\n// Mapping from a distance to a distance code. dist is the distance - 1 and\n// must not have side effects. _dist_code[256] and _dist_code[257] are never\n// used.\nTree.d_code = function (dist) {\n\treturn ((dist) < 256 ? _dist_code[dist] : _dist_code[256 + ((dist) >>> 7)]);\n};\n\n// extra bits for each length code\nTree.extra_lbits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0];\n\n// extra bits for each distance code\nTree.extra_dbits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];\n\n// extra bits for each bit length code\nTree.extra_blbits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];\n\nTree.bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];\n\n// StaticTree\n\nfunction StaticTree(static_tree, extra_bits, extra_base, elems, max_length) {\n\tconst that = this;\n\tthat.static_tree = static_tree;\n\tthat.extra_bits = extra_bits;\n\tthat.extra_base = extra_base;\n\tthat.elems = elems;\n\tthat.max_length = max_length;\n}\n\nconst static_ltree2_first_part = [12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82,\n\t210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86,\n\t214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81,\n\t209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85,\n\t213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 19, 275, 147, 403, 83, 339, 211, 467, 51, 307,\n\t179, 435, 115, 371, 243, 499, 11, 267, 139, 395, 75, 331, 203, 459, 43, 299, 171, 427, 107, 363, 235, 491, 27, 283, 155, 411, 91, 347, 219, 475,\n\t59, 315, 187, 443, 123, 379, 251, 507, 7, 263, 135, 391, 71, 327, 199, 455, 39, 295, 167, 423, 103, 359, 231, 487, 23, 279, 151, 407, 87, 343, 215,\n\t471, 55, 311, 183, 439, 119, 375, 247, 503, 15, 271, 143, 399, 79, 335, 207, 463, 47, 303, 175, 431, 111, 367, 239, 495, 31, 287, 159, 415, 95,\n\t351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511, 0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36, 100, 20, 84, 52,\n\t116, 3, 131, 67, 195, 35, 163, 99, 227];\nconst static_ltree2_second_part = extractArray([[144, 8], [112, 9], [24, 7], [8, 8]]);\nStaticTree.static_ltree = flatArray(static_ltree2_first_part.map((value, index) => [value, static_ltree2_second_part[index]]));\n\nconst static_dtree_first_part = [0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23];\nconst static_dtree_second_part = extractArray([[30, 5]]);\nStaticTree.static_dtree = flatArray(static_dtree_first_part.map((value, index) => [value, static_dtree_second_part[index]]));\n\nStaticTree.static_l_desc = new StaticTree(StaticTree.static_ltree, Tree.extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);\n\nStaticTree.static_d_desc = new StaticTree(StaticTree.static_dtree, Tree.extra_dbits, 0, D_CODES, MAX_BITS);\n\nStaticTree.static_bl_desc = new StaticTree(null, Tree.extra_blbits, 0, BL_CODES, MAX_BL_BITS);\n\n// Deflate\n\nconst MAX_MEM_LEVEL = 9;\nconst DEF_MEM_LEVEL = 8;\n\nfunction Config(good_length, max_lazy, nice_length, max_chain, func) {\n\tconst that = this;\n\tthat.good_length = good_length;\n\tthat.max_lazy = max_lazy;\n\tthat.nice_length = nice_length;\n\tthat.max_chain = max_chain;\n\tthat.func = func;\n}\n\nconst STORED = 0;\nconst FAST = 1;\nconst SLOW = 2;\nconst config_table = [\n\tnew Config(0, 0, 0, 0, STORED),\n\tnew Config(4, 4, 8, 4, FAST),\n\tnew Config(4, 5, 16, 8, FAST),\n\tnew Config(4, 6, 32, 32, FAST),\n\tnew Config(4, 4, 16, 16, SLOW),\n\tnew Config(8, 16, 32, 32, SLOW),\n\tnew Config(8, 16, 128, 128, SLOW),\n\tnew Config(8, 32, 128, 256, SLOW),\n\tnew Config(32, 128, 258, 1024, SLOW),\n\tnew Config(32, 258, 258, 4096, SLOW)\n];\n\nconst z_errmsg = [\"need dictionary\", // Z_NEED_DICT\n\t// 2\n\t\"stream end\", // Z_STREAM_END 1\n\t\"\", // Z_OK 0\n\t\"\", // Z_ERRNO (-1)\n\t\"stream error\", // Z_STREAM_ERROR (-2)\n\t\"data error\", // Z_DATA_ERROR (-3)\n\t\"\", // Z_MEM_ERROR (-4)\n\t\"buffer error\", // Z_BUF_ERROR (-5)\n\t\"\",// Z_VERSION_ERROR (-6)\n\t\"\"];\n\n// block not completed, need more input or more output\nconst NeedMore = 0;\n\n// block flush performed\nconst BlockDone = 1;\n\n// finish started, need only more output at next deflate\nconst FinishStarted = 2;\n\n// finish done, accept no more input or output\nconst FinishDone = 3;\n\n// preset dictionary flag in zlib header\nconst PRESET_DICT = 0x20;\n\nconst INIT_STATE = 42;\nconst BUSY_STATE = 113;\nconst FINISH_STATE = 666;\n\n// The deflate compression method\nconst Z_DEFLATED = 8;\n\nconst STORED_BLOCK = 0;\nconst STATIC_TREES = 1;\nconst DYN_TREES = 2;\n\nconst MIN_MATCH = 3;\nconst MAX_MATCH = 258;\nconst MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);\n\nfunction smaller(tree, n, m, depth) {\n\tconst tn2 = tree[n * 2];\n\tconst tm2 = tree[m * 2];\n\treturn (tn2 < tm2 || (tn2 == tm2 && depth[n] <= depth[m]));\n}\n\nfunction Deflate() {\n\n\tconst that = this;\n\tlet strm; // pointer back to this zlib stream\n\tlet status; // as the name implies\n\t// pending_buf; // output still pending\n\tlet pending_buf_size; // size of pending_buf\n\t// pending_out; // next pending byte to output to the stream\n\t// pending; // nb of bytes in the pending buffer\n\n\t// dist_buf; // buffer for distances\n\t// lc_buf; // buffer for literals or lengths\n\t// To simplify the code, dist_buf and lc_buf have the same number of elements.\n\t// To use different lengths, an extra flag array would be necessary.\n\n\tlet last_flush; // value of flush param for previous deflate call\n\n\tlet w_size; // LZ77 win size (32K by default)\n\tlet w_bits; // log2(w_size) (8..16)\n\tlet w_mask; // w_size - 1\n\n\tlet win;\n\t// Sliding win. Input bytes are read into the second half of the win,\n\t// and move to the first half later to keep a dictionary of at least wSize\n\t// bytes. With this organization, matches are limited to a distance of\n\t// wSize-MAX_MATCH bytes, but this ensures that IO is always\n\t// performed with a length multiple of the block size. Also, it limits\n\t// the win size to 64K, which is quite useful on MSDOS.\n\t// To do: use the user input buffer as sliding win.\n\n\tlet window_size;\n\t// Actual size of win: 2*wSize, except when the user input buffer\n\t// is directly used as sliding win.\n\n\tlet prev;\n\t// Link to older string with same hash index. To limit the size of this\n\t// array to 64K, this link is maintained only for the last 32K strings.\n\t// An index in this array is thus a win index modulo 32K.\n\n\tlet head; // Heads of the hash chains or NIL.\n\n\tlet ins_h; // hash index of string to be inserted\n\tlet hash_size; // number of elements in hash table\n\tlet hash_bits; // log2(hash_size)\n\tlet hash_mask; // hash_size-1\n\n\t// Number of bits by which ins_h must be shifted at each input\n\t// step. It must be such that after MIN_MATCH steps, the oldest\n\t// byte no longer takes part in the hash key, that is:\n\t// hash_shift * MIN_MATCH >= hash_bits\n\tlet hash_shift;\n\n\t// Window position at the beginning of the current output block. Gets\n\t// negative when the win is moved backwards.\n\n\tlet block_start;\n\n\tlet match_length; // length of best match\n\tlet prev_match; // previous match\n\tlet match_available; // set if previous match exists\n\tlet strstart; // start of string to insert\n\tlet match_start; // start of matching string\n\tlet lookahead; // number of valid bytes ahead in win\n\n\t// Length of the best match at previous step. Matches not greater than this\n\t// are discarded. This is used in the lazy match evaluation.\n\tlet prev_length;\n\n\t// To speed up deflation, hash chains are never searched beyond this\n\t// length. A higher limit improves compression ratio but degrades the speed.\n\tlet max_chain_length;\n\n\t// Attempt to find a better match only when the current match is strictly\n\t// smaller than this value. This mechanism is used only for compression\n\t// levels >= 4.\n\tlet max_lazy_match;\n\n\t// Insert new strings in the hash table only if the match length is not\n\t// greater than this length. This saves time but degrades compression.\n\t// max_insert_length is used only for compression levels <= 3.\n\n\tlet level; // compression level (1..9)\n\tlet strategy; // favor or force Huffman coding\n\n\t// Use a faster search when the previous match is longer than this\n\tlet good_match;\n\n\t// Stop searching when current match exceeds this\n\tlet nice_match;\n\n\tlet dyn_ltree; // literal and length tree\n\tlet dyn_dtree; // distance tree\n\tlet bl_tree; // Huffman tree for bit lengths\n\n\tconst l_desc = new Tree(); // desc for literal tree\n\tconst d_desc = new Tree(); // desc for distance tree\n\tconst bl_desc = new Tree(); // desc for bit length tree\n\n\t// that.heap_len; // number of elements in the heap\n\t// that.heap_max; // element of largest frequency\n\t// The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.\n\t// The same heap array is used to build all trees.\n\n\t// Depth of each subtree used as tie breaker for trees of equal frequency\n\tthat.depth = [];\n\n\t// Size of match buffer for literals/lengths. There are 4 reasons for\n\t// limiting lit_bufsize to 64K:\n\t// - frequencies can be kept in 16 bit counters\n\t// - if compression is not successful for the first block, all input\n\t// data is still in the win so we can still emit a stored block even\n\t// when input comes from standard input. (This can also be done for\n\t// all blocks if lit_bufsize is not greater than 32K.)\n\t// - if compression is not successful for a file smaller than 64K, we can\n\t// even emit a stored file instead of a stored block (saving 5 bytes).\n\t// This is applicable only for zip (not gzip or zlib).\n\t// - creating new Huffman trees less frequently may not provide fast\n\t// adaptation to changes in the input data statistics. (Take for\n\t// example a binary file with poorly compressible code followed by\n\t// a highly compressible string table.) Smaller buffer sizes give\n\t// fast adaptation but have of course the overhead of transmitting\n\t// trees more frequently.\n\t// - I can't count above 4\n\tlet lit_bufsize;\n\n\tlet last_lit; // running index in dist_buf and lc_buf\n\n\t// that.opt_len; // bit length of current block with optimal trees\n\t// that.static_len; // bit length of current block with static trees\n\tlet matches; // number of string matches in current block\n\tlet last_eob_len; // bit length of EOB code for last block\n\n\t// Output buffer. bits are inserted starting at the bottom (least\n\t// significant bits).\n\tlet bi_buf;\n\n\t// Number of valid bits in bi_buf. All bits above the last valid bit\n\t// are always zero.\n\tlet bi_valid;\n\n\t// number of codes at each bit length for an optimal tree\n\tthat.bl_count = [];\n\n\t// heap used to build the Huffman trees\n\tthat.heap = [];\n\n\tdyn_ltree = [];\n\tdyn_dtree = [];\n\tbl_tree = [];\n\n\tfunction lm_init() {\n\t\twindow_size = 2 * w_size;\n\n\t\thead[hash_size - 1] = 0;\n\t\tfor (let i = 0; i < hash_size - 1; i++) {\n\t\t\thead[i] = 0;\n\t\t}\n\n\t\t// Set the default configuration parameters:\n\t\tmax_lazy_match = config_table[level].max_lazy;\n\t\tgood_match = config_table[level].good_length;\n\t\tnice_match = config_table[level].nice_length;\n\t\tmax_chain_length = config_table[level].max_chain;\n\n\t\tstrstart = 0;\n\t\tblock_start = 0;\n\t\tlookahead = 0;\n\t\tmatch_length = prev_length = MIN_MATCH - 1;\n\t\tmatch_available = 0;\n\t\tins_h = 0;\n\t}\n\n\tfunction init_block() {\n\t\tlet i;\n\t\t// Initialize the trees.\n\t\tfor (i = 0; i < L_CODES; i++)\n\t\t\tdyn_ltree[i * 2] = 0;\n\t\tfor (i = 0; i < D_CODES; i++)\n\t\t\tdyn_dtree[i * 2] = 0;\n\t\tfor (i = 0; i < BL_CODES; i++)\n\t\t\tbl_tree[i * 2] = 0;\n\n\t\tdyn_ltree[END_BLOCK * 2] = 1;\n\t\tthat.opt_len = that.static_len = 0;\n\t\tlast_lit = matches = 0;\n\t}\n\n\t// Initialize the tree data structures for a new zlib stream.\n\tfunction tr_init() {\n\n\t\tl_desc.dyn_tree = dyn_ltree;\n\t\tl_desc.stat_desc = StaticTree.static_l_desc;\n\n\t\td_desc.dyn_tree = dyn_dtree;\n\t\td_desc.stat_desc = StaticTree.static_d_desc;\n\n\t\tbl_desc.dyn_tree = bl_tree;\n\t\tbl_desc.stat_desc = StaticTree.static_bl_desc;\n\n\t\tbi_buf = 0;\n\t\tbi_valid = 0;\n\t\tlast_eob_len = 8; // enough lookahead for inflate\n\n\t\t// Initialize the first block of the first file:\n\t\tinit_block();\n\t}\n\n\t// Restore the heap property by moving down the tree starting at node k,\n\t// exchanging a node with the smallest of its two sons if necessary,\n\t// stopping\n\t// when the heap property is re-established (each father smaller than its\n\t// two sons).\n\tthat.pqdownheap = function (tree, // the tree to restore\n\t\tk // node to move down\n\t) {\n\t\tconst heap = that.heap;\n\t\tconst v = heap[k];\n\t\tlet j = k << 1; // left son of k\n\t\twhile (j <= that.heap_len) {\n\t\t\t// Set j to the smallest of the two sons:\n\t\t\tif (j < that.heap_len && smaller(tree, heap[j + 1], heap[j], that.depth)) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\t// Exit if v is smaller than both sons\n\t\t\tif (smaller(tree, v, heap[j], that.depth))\n\t\t\t\tbreak;\n\n\t\t\t// Exchange v with the smallest son\n\t\t\theap[k] = heap[j];\n\t\t\tk = j;\n\t\t\t// And continue down the tree, setting j to the left son of k\n\t\t\tj <<= 1;\n\t\t}\n\t\theap[k] = v;\n\t};\n\n\t// Scan a literal or distance tree to determine the frequencies of the codes\n\t// in the bit length tree.\n\tfunction scan_tree(tree,// the tree to be scanned\n\t\tmax_code // and its largest code of non zero frequency\n\t) {\n\t\tlet prevlen = -1; // last emitted length\n\t\tlet curlen; // length of current code\n\t\tlet nextlen = tree[0 * 2 + 1]; // length of next code\n\t\tlet count = 0; // repeat count of the current code\n\t\tlet max_count = 7; // max repeat count\n\t\tlet min_count = 4; // min repeat count\n\n\t\tif (nextlen === 0) {\n\t\t\tmax_count = 138;\n\t\t\tmin_count = 3;\n\t\t}\n\t\ttree[(max_code + 1) * 2 + 1] = 0xffff; // guard\n\n\t\tfor (let n = 0; n <= max_code; n++) {\n\t\t\tcurlen = nextlen;\n\t\t\tnextlen = tree[(n + 1) * 2 + 1];\n\t\t\tif (++count < max_count && curlen == nextlen) {\n\t\t\t\tcontinue;\n\t\t\t} else if (count < min_count) {\n\t\t\t\tbl_tree[curlen * 2] += count;\n\t\t\t} else if (curlen !== 0) {\n\t\t\t\tif (curlen != prevlen)\n\t\t\t\t\tbl_tree[curlen * 2]++;\n\t\t\t\tbl_tree[REP_3_6 * 2]++;\n\t\t\t} else if (count <= 10) {\n\t\t\t\tbl_tree[REPZ_3_10 * 2]++;\n\t\t\t} else {\n\t\t\t\tbl_tree[REPZ_11_138 * 2]++;\n\t\t\t}\n\t\t\tcount = 0;\n\t\t\tprevlen = curlen;\n\t\t\tif (nextlen === 0) {\n\t\t\t\tmax_count = 138;\n\t\t\t\tmin_count = 3;\n\t\t\t} else if (curlen == nextlen) {\n\t\t\t\tmax_count = 6;\n\t\t\t\tmin_count = 3;\n\t\t\t} else {\n\t\t\t\tmax_count = 7;\n\t\t\t\tmin_count = 4;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Construct the Huffman tree for the bit lengths and return the index in\n\t// bl_order of the last bit length code to send.\n\tfunction build_bl_tree() {\n\t\tlet max_blindex; // index of last bit length code of non zero freq\n\n\t\t// Determine the bit length frequencies for literal and distance trees\n\t\tscan_tree(dyn_ltree, l_desc.max_code);\n\t\tscan_tree(dyn_dtree, d_desc.max_code);\n\n\t\t// Build the bit length tree:\n\t\tbl_desc.build_tree(that);\n\t\t// opt_len now includes the length of the tree representations, except\n\t\t// the lengths of the bit lengths codes and the 5+5+4 bits for the\n\t\t// counts.\n\n\t\t// Determine the number of bit length codes to send. The pkzip format\n\t\t// requires that at least 4 bit length codes be sent. (appnote.txt says\n\t\t// 3 but the actual value used is 4.)\n\t\tfor (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {\n\t\t\tif (bl_tree[Tree.bl_order[max_blindex] * 2 + 1] !== 0)\n\t\t\t\tbreak;\n\t\t}\n\t\t// Update opt_len to include the bit length tree and counts\n\t\tthat.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;\n\n\t\treturn max_blindex;\n\t}\n\n\t// Output a byte on the stream.\n\t// IN assertion: there is enough room in pending_buf.\n\tfunction put_byte(p) {\n\t\tthat.pending_buf[that.pending++] = p;\n\t}\n\n\tfunction put_short(w) {\n\t\tput_byte(w & 0xff);\n\t\tput_byte((w >>> 8) & 0xff);\n\t}\n\n\tfunction putShortMSB(b) {\n\t\tput_byte((b >> 8) & 0xff);\n\t\tput_byte((b & 0xff) & 0xff);\n\t}\n\n\tfunction send_bits(value, length) {\n\t\tlet val;\n\t\tconst len = length;\n\t\tif (bi_valid > Buf_size - len) {\n\t\t\tval = value;\n\t\t\t// bi_buf |= (val << bi_valid);\n\t\t\tbi_buf |= ((val << bi_valid) & 0xffff);\n\t\t\tput_short(bi_buf);\n\t\t\tbi_buf = val >>> (Buf_size - bi_valid);\n\t\t\tbi_valid += len - Buf_size;\n\t\t} else {\n\t\t\t// bi_buf |= (value) << bi_valid;\n\t\t\tbi_buf |= (((value) << bi_valid) & 0xffff);\n\t\t\tbi_valid += len;\n\t\t}\n\t}\n\n\tfunction send_code(c, tree) {\n\t\tconst c2 = c * 2;\n\t\tsend_bits(tree[c2] & 0xffff, tree[c2 + 1] & 0xffff);\n\t}\n\n\t// Send a literal or distance tree in compressed form, using the codes in\n\t// bl_tree.\n\tfunction send_tree(tree,// the tree to be sent\n\t\tmax_code // and its largest code of non zero frequency\n\t) {\n\t\tlet n; // iterates over all tree elements\n\t\tlet prevlen = -1; // last emitted length\n\t\tlet curlen; // length of current code\n\t\tlet nextlen = tree[0 * 2 + 1]; // length of next code\n\t\tlet count = 0; // repeat count of the current code\n\t\tlet max_count = 7; // max repeat count\n\t\tlet min_count = 4; // min repeat count\n\n\t\tif (nextlen === 0) {\n\t\t\tmax_count = 138;\n\t\t\tmin_count = 3;\n\t\t}\n\n\t\tfor (n = 0; n <= max_code; n++) {\n\t\t\tcurlen = nextlen;\n\t\t\tnextlen = tree[(n + 1) * 2 + 1];\n\t\t\tif (++count < max_count && curlen == nextlen) {\n\t\t\t\tcontinue;\n\t\t\t} else if (count < min_count) {\n\t\t\t\tdo {\n\t\t\t\t\tsend_code(curlen, bl_tree);\n\t\t\t\t} while (--count !== 0);\n\t\t\t} else if (curlen !== 0) {\n\t\t\t\tif (curlen != prevlen) {\n\t\t\t\t\tsend_code(curlen, bl_tree);\n\t\t\t\t\tcount--;\n\t\t\t\t}\n\t\t\t\tsend_code(REP_3_6, bl_tree);\n\t\t\t\tsend_bits(count - 3, 2);\n\t\t\t} else if (count <= 10) {\n\t\t\t\tsend_code(REPZ_3_10, bl_tree);\n\t\t\t\tsend_bits(count - 3, 3);\n\t\t\t} else {\n\t\t\t\tsend_code(REPZ_11_138, bl_tree);\n\t\t\t\tsend_bits(count - 11, 7);\n\t\t\t}\n\t\t\tcount = 0;\n\t\t\tprevlen = curlen;\n\t\t\tif (nextlen === 0) {\n\t\t\t\tmax_count = 138;\n\t\t\t\tmin_count = 3;\n\t\t\t} else if (curlen == nextlen) {\n\t\t\t\tmax_count = 6;\n\t\t\t\tmin_count = 3;\n\t\t\t} else {\n\t\t\t\tmax_count = 7;\n\t\t\t\tmin_count = 4;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Send the header for a block using dynamic Huffman trees: the counts, the\n\t// lengths of the bit length codes, the literal tree and the distance tree.\n\t// IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.\n\tfunction send_all_trees(lcodes, dcodes, blcodes) {\n\t\tlet rank; // index in bl_order\n\n\t\tsend_bits(lcodes - 257, 5); // not +255 as stated in appnote.txt\n\t\tsend_bits(dcodes - 1, 5);\n\t\tsend_bits(blcodes - 4, 4); // not -3 as stated in appnote.txt\n\t\tfor (rank = 0; rank < blcodes; rank++) {\n\t\t\tsend_bits(bl_tree[Tree.bl_order[rank] * 2 + 1], 3);\n\t\t}\n\t\tsend_tree(dyn_ltree, lcodes - 1); // literal tree\n\t\tsend_tree(dyn_dtree, dcodes - 1); // distance tree\n\t}\n\n\t// Flush the bit buffer, keeping at most 7 bits in it.\n\tfunction bi_flush() {\n\t\tif (bi_valid == 16) {\n\t\t\tput_short(bi_buf);\n\t\t\tbi_buf = 0;\n\t\t\tbi_valid = 0;\n\t\t} else if (bi_valid >= 8) {\n\t\t\tput_byte(bi_buf & 0xff);\n\t\t\tbi_buf >>>= 8;\n\t\t\tbi_valid -= 8;\n\t\t}\n\t}\n\n\t// Send one empty static block to give enough lookahead for inflate.\n\t// This takes 10 bits, of which 7 may remain in the bit buffer.\n\t// The current inflate code requires 9 bits of lookahead. If the\n\t// last two codes for the previous block (real code plus EOB) were coded\n\t// on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode\n\t// the last real code. In this case we send two empty static blocks instead\n\t// of one. (There are no problems if the previous block is stored or fixed.)\n\t// To simplify the code, we assume the worst case of last real code encoded\n\t// on one bit only.\n\tfunction _tr_align() {\n\t\tsend_bits(STATIC_TREES << 1, 3);\n\t\tsend_code(END_BLOCK, StaticTree.static_ltree);\n\n\t\tbi_flush();\n\n\t\t// Of the 10 bits for the empty block, we have already sent\n\t\t// (10 - bi_valid) bits. The lookahead for the last real code (before\n\t\t// the EOB of the previous block) was thus at least one plus the length\n\t\t// of the EOB plus what we have just sent of the empty static block.\n\t\tif (1 + last_eob_len + 10 - bi_valid < 9) {\n\t\t\tsend_bits(STATIC_TREES << 1, 3);\n\t\t\tsend_code(END_BLOCK, StaticTree.static_ltree);\n\t\t\tbi_flush();\n\t\t}\n\t\tlast_eob_len = 7;\n\t}\n\n\t// Save the match info and tally the frequency counts. Return true if\n\t// the current block must be flushed.\n\tfunction _tr_tally(dist, // distance of matched string\n\t\tlc // match length-MIN_MATCH or unmatched char (if dist==0)\n\t) {\n\t\tlet out_length, in_length, dcode;\n\t\tthat.dist_buf[last_lit] = dist;\n\t\tthat.lc_buf[last_lit] = lc & 0xff;\n\t\tlast_lit++;\n\n\t\tif (dist === 0) {\n\t\t\t// lc is the unmatched char\n\t\t\tdyn_ltree[lc * 2]++;\n\t\t} else {\n\t\t\tmatches++;\n\t\t\t// Here, lc is the match length - MIN_MATCH\n\t\t\tdist--; // dist = match distance - 1\n\t\t\tdyn_ltree[(Tree._length_code[lc] + LITERALS + 1) * 2]++;\n\t\t\tdyn_dtree[Tree.d_code(dist) * 2]++;\n\t\t}\n\n\t\tif ((last_lit & 0x1fff) === 0 && level > 2) {\n\t\t\t// Compute an upper bound for the compressed length\n\t\t\tout_length = last_lit * 8;\n\t\t\tin_length = strstart - block_start;\n\t\t\tfor (dcode = 0; dcode < D_CODES; dcode++) {\n\t\t\t\tout_length += dyn_dtree[dcode * 2] * (5 + Tree.extra_dbits[dcode]);\n\t\t\t}\n\t\t\tout_length >>>= 3;\n\t\t\tif ((matches < Math.floor(last_lit / 2)) && out_length < Math.floor(in_length / 2))\n\t\t\t\treturn true;\n\t\t}\n\n\t\treturn (last_lit == lit_bufsize - 1);\n\t\t// We avoid equality with lit_bufsize because of wraparound at 64K\n\t\t// on 16 bit machines and because stored blocks are restricted to\n\t\t// 64K-1 bytes.\n\t}\n\n\t// Send the block data compressed using the given Huffman trees\n\tfunction compress_block(ltree, dtree) {\n\t\tlet dist; // distance of matched string\n\t\tlet lc; // match length or unmatched char (if dist === 0)\n\t\tlet lx = 0; // running index in dist_buf and lc_buf\n\t\tlet code; // the code to send\n\t\tlet extra; // number of extra bits to send\n\n\t\tif (last_lit !== 0) {\n\t\t\tdo {\n\t\t\t\tdist = that.dist_buf[lx];\n\t\t\t\tlc = that.lc_buf[lx];\n\t\t\t\tlx++;\n\n\t\t\t\tif (dist === 0) {\n\t\t\t\t\tsend_code(lc, ltree); // send a literal byte\n\t\t\t\t} else {\n\t\t\t\t\t// Here, lc is the match length - MIN_MATCH\n\t\t\t\t\tcode = Tree._length_code[lc];\n\n\t\t\t\t\tsend_code(code + LITERALS + 1, ltree); // send the length\n\t\t\t\t\t// code\n\t\t\t\t\textra = Tree.extra_lbits[code];\n\t\t\t\t\tif (extra !== 0) {\n\t\t\t\t\t\tlc -= Tree.base_length[code];\n\t\t\t\t\t\tsend_bits(lc, extra); // send the extra length bits\n\t\t\t\t\t}\n\t\t\t\t\tdist--; // dist is now the match distance - 1\n\t\t\t\t\tcode = Tree.d_code(dist);\n\n\t\t\t\t\tsend_code(code, dtree); // send the distance code\n\t\t\t\t\textra = Tree.extra_dbits[code];\n\t\t\t\t\tif (extra !== 0) {\n\t\t\t\t\t\tdist -= Tree.base_dist[code];\n\t\t\t\t\t\tsend_bits(dist, extra); // send the extra distance bits\n\t\t\t\t\t}\n\t\t\t\t} // literal or match pair ?\n\t\t\t} while (lx < last_lit);\n\t\t}\n\n\t\tsend_code(END_BLOCK, ltree);\n\t\tlast_eob_len = ltree[END_BLOCK * 2 + 1];\n\t}\n\n\t// Flush the bit buffer and align the output on a byte boundary\n\tfunction bi_windup() {\n\t\tif (bi_valid > 8) {\n\t\t\tput_short(bi_buf);\n\t\t} else if (bi_valid > 0) {\n\t\t\tput_byte(bi_buf & 0xff);\n\t\t}\n\t\tbi_buf = 0;\n\t\tbi_valid = 0;\n\t}\n\n\t// Copy a stored block, storing first the length and its\n\t// one's complement if requested.\n\tfunction copy_block(buf, // the input data\n\t\tlen, // its length\n\t\theader // true if block header must be written\n\t) {\n\t\tbi_windup(); // align on byte boundary\n\t\tlast_eob_len = 8; // enough lookahead for inflate\n\n\t\tif (header) {\n\t\t\tput_short(len);\n\t\t\tput_short(~len);\n\t\t}\n\n\t\tthat.pending_buf.set(win.subarray(buf, buf + len), that.pending);\n\t\tthat.pending += len;\n\t}\n\n\t// Send a stored block\n\tfunction _tr_stored_block(buf, // input block\n\t\tstored_len, // length of input block\n\t\teof // true if this is the last block for a file\n\t) {\n\t\tsend_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type\n\t\tcopy_block(buf, stored_len, true); // with header\n\t}\n\n\t// Determine the best encoding for the current block: dynamic trees, static\n\t// trees or store, and output the encoded block to the zip file.\n\tfunction _tr_flush_block(buf, // input block, or NULL if too old\n\t\tstored_len, // length of input block\n\t\teof // true if this is the last block for a file\n\t) {\n\t\tlet opt_lenb, static_lenb;// opt_len and static_len in bytes\n\t\tlet max_blindex = 0; // index of last bit length code of non zero freq\n\n\t\t// Build the Huffman trees unless a stored block is forced\n\t\tif (level > 0) {\n\t\t\t// Construct the literal and distance trees\n\t\t\tl_desc.build_tree(that);\n\n\t\t\td_desc.build_tree(that);\n\n\t\t\t// At this point, opt_len and static_len are the total bit lengths\n\t\t\t// of\n\t\t\t// the compressed block data, excluding the tree representations.\n\n\t\t\t// Build the bit length tree for the above two trees, and get the\n\t\t\t// index\n\t\t\t// in bl_order of the last bit length code to send.\n\t\t\tmax_blindex = build_bl_tree();\n\n\t\t\t// Determine the best encoding. Compute first the block length in\n\t\t\t// bytes\n\t\t\topt_lenb = (that.opt_len + 3 + 7) >>> 3;\n\t\t\tstatic_lenb = (that.static_len + 3 + 7) >>> 3;\n\n\t\t\tif (static_lenb <= opt_lenb)\n\t\t\t\topt_lenb = static_lenb;\n\t\t} else {\n\t\t\topt_lenb = static_lenb = stored_len + 5; // force a stored block\n\t\t}\n\n\t\tif ((stored_len + 4 <= opt_lenb) && buf != -1) {\n\t\t\t// 4: two words for the lengths\n\t\t\t// The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.\n\t\t\t// Otherwise we can't have processed more than WSIZE input bytes\n\t\t\t// since\n\t\t\t// the last block flush, because compression would have been\n\t\t\t// successful. If LIT_BUFSIZE <= WSIZE, it is never too late to\n\t\t\t// transform a block into a stored block.\n\t\t\t_tr_stored_block(buf, stored_len, eof);\n\t\t} else if (static_lenb == opt_lenb) {\n\t\t\tsend_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3);\n\t\t\tcompress_block(StaticTree.static_ltree, StaticTree.static_dtree);\n\t\t} else {\n\t\t\tsend_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3);\n\t\t\tsend_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, max_blindex + 1);\n\t\t\tcompress_block(dyn_ltree, dyn_dtree);\n\t\t}\n\n\t\t// The above check is made mod 2^32, for files larger than 512 MB\n\t\t// and uLong implemented on 32 bits.\n\n\t\tinit_block();\n\n\t\tif (eof) {\n\t\t\tbi_windup();\n\t\t}\n\t}\n\n\tfunction flush_block_only(eof) {\n\t\t_tr_flush_block(block_start >= 0 ? block_start : -1, strstart - block_start, eof);\n\t\tblock_start = strstart;\n\t\tstrm.flush_pending();\n\t}\n\n\t// Fill the win when the lookahead becomes insufficient.\n\t// Updates strstart and lookahead.\n\t//\n\t// IN assertion: lookahead < MIN_LOOKAHEAD\n\t// OUT assertions: strstart <= window_size-MIN_LOOKAHEAD\n\t// At least one byte has been read, or avail_in === 0; reads are\n\t// performed for at least two bytes (required for the zip translate_eol\n\t// option -- not supported here).\n\tfunction fill_window() {\n\t\tlet n, m;\n\t\tlet p;\n\t\tlet more; // Amount of free space at the end of the win.\n\n\t\tdo {\n\t\t\tmore = (window_size - lookahead - strstart);\n\n\t\t\t// Deal with !@#$% 64K limit:\n\t\t\tif (more === 0 && strstart === 0 && lookahead === 0) {\n\t\t\t\tmore = w_size;\n\t\t\t} else if (more == -1) {\n\t\t\t\t// Very unlikely, but possible on 16 bit machine if strstart ==\n\t\t\t\t// 0\n\t\t\t\t// and lookahead == 1 (input done one byte at time)\n\t\t\t\tmore--;\n\n\t\t\t\t// If the win is almost full and there is insufficient\n\t\t\t\t// lookahead,\n\t\t\t\t// move the upper half to the lower one to make room in the\n\t\t\t\t// upper half.\n\t\t\t} else if (strstart >= w_size + w_size - MIN_LOOKAHEAD) {\n\t\t\t\twin.set(win.subarray(w_size, w_size + w_size), 0);\n\n\t\t\t\tmatch_start -= w_size;\n\t\t\t\tstrstart -= w_size; // we now have strstart >= MAX_DIST\n\t\t\t\tblock_start -= w_size;\n\n\t\t\t\t// Slide the hash table (could be avoided with 32 bit values\n\t\t\t\t// at the expense of memory usage). We slide even when level ==\n\t\t\t\t// 0\n\t\t\t\t// to keep the hash table consistent if we switch back to level\n\t\t\t\t// > 0\n\t\t\t\t// later. (Using level 0 permanently is not an optimal usage of\n\t\t\t\t// zlib, so we don't care about this pathological case.)\n\n\t\t\t\tn = hash_size;\n\t\t\t\tp = n;\n\t\t\t\tdo {\n\t\t\t\t\tm = (head[--p] & 0xffff);\n\t\t\t\t\thead[p] = (m >= w_size ? m - w_size : 0);\n\t\t\t\t} while (--n !== 0);\n\n\t\t\t\tn = w_size;\n\t\t\t\tp = n;\n\t\t\t\tdo {\n\t\t\t\t\tm = (prev[--p] & 0xffff);\n\t\t\t\t\tprev[p] = (m >= w_size ? m - w_size : 0);\n\t\t\t\t\t// If n is not on any hash chain, prev[n] is garbage but\n\t\t\t\t\t// its value will never be used.\n\t\t\t\t} while (--n !== 0);\n\t\t\t\tmore += w_size;\n\t\t\t}\n\n\t\t\tif (strm.avail_in === 0)\n\t\t\t\treturn;\n\n\t\t\t// If there was no sliding:\n\t\t\t// strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&\n\t\t\t// more == window_size - lookahead - strstart\n\t\t\t// => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)\n\t\t\t// => more >= window_size - 2*WSIZE + 2\n\t\t\t// In the BIG_MEM or MMAP case (not yet supported),\n\t\t\t// window_size == input_size + MIN_LOOKAHEAD &&\n\t\t\t// strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.\n\t\t\t// Otherwise, window_size == 2*WSIZE so more >= 2.\n\t\t\t// If there was sliding, more >= WSIZE. So in all cases, more >= 2.\n\n\t\t\tn = strm.read_buf(win, strstart + lookahead, more);\n\t\t\tlookahead += n;\n\n\t\t\t// Initialize the hash value now that we have some input:\n\t\t\tif (lookahead >= MIN_MATCH) {\n\t\t\t\tins_h = win[strstart] & 0xff;\n\t\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[strstart + 1] & 0xff)) & hash_mask;\n\t\t\t}\n\t\t\t// If the whole input has less than MIN_MATCH bytes, ins_h is\n\t\t\t// garbage,\n\t\t\t// but this is not important since only literal bytes will be\n\t\t\t// emitted.\n\t\t} while (lookahead < MIN_LOOKAHEAD && strm.avail_in !== 0);\n\t}\n\n\t// Copy without compression as much as possible from the input stream,\n\t// return\n\t// the current block state.\n\t// This function does not insert new strings in the dictionary since\n\t// uncompressible data is probably not useful. This function is used\n\t// only for the level=0 compression option.\n\t// NOTE: this function should be optimized to avoid extra copying from\n\t// win to pending_buf.\n\tfunction deflate_stored(flush) {\n\t\t// Stored blocks are limited to 0xffff bytes, pending_buf is limited\n\t\t// to pending_buf_size, and each stored block has a 5 byte header:\n\n\t\tlet max_block_size = 0xffff;\n\t\tlet max_start;\n\n\t\tif (max_block_size > pending_buf_size - 5) {\n\t\t\tmax_block_size = pending_buf_size - 5;\n\t\t}\n\n\t\t// Copy as much as possible from input to output:\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\t// Fill the win as much as possible:\n\t\t\tif (lookahead <= 1) {\n\t\t\t\tfill_window();\n\t\t\t\tif (lookahead === 0 && flush == Z_NO_FLUSH)\n\t\t\t\t\treturn NeedMore;\n\t\t\t\tif (lookahead === 0)\n\t\t\t\t\tbreak; // flush the current block\n\t\t\t}\n\n\t\t\tstrstart += lookahead;\n\t\t\tlookahead = 0;\n\n\t\t\t// Emit a stored block if pending_buf will be full:\n\t\t\tmax_start = block_start + max_block_size;\n\t\t\tif (strstart === 0 || strstart >= max_start) {\n\t\t\t\t// strstart === 0 is possible when wraparound on 16-bit machine\n\t\t\t\tlookahead = (strstart - max_start);\n\t\t\t\tstrstart = max_start;\n\n\t\t\t\tflush_block_only(false);\n\t\t\t\tif (strm.avail_out === 0)\n\t\t\t\t\treturn NeedMore;\n\n\t\t\t}\n\n\t\t\t// Flush if we may have to slide, otherwise block_start may become\n\t\t\t// negative and the data will be gone:\n\t\t\tif (strstart - block_start >= w_size - MIN_LOOKAHEAD) {\n\t\t\t\tflush_block_only(false);\n\t\t\t\tif (strm.avail_out === 0)\n\t\t\t\t\treturn NeedMore;\n\t\t\t}\n\t\t}\n\n\t\tflush_block_only(flush == Z_FINISH);\n\t\tif (strm.avail_out === 0)\n\t\t\treturn (flush == Z_FINISH) ? FinishStarted : NeedMore;\n\n\t\treturn flush == Z_FINISH ? FinishDone : BlockDone;\n\t}\n\n\tfunction longest_match(cur_match) {\n\t\tlet chain_length = max_chain_length; // max hash chain length\n\t\tlet scan = strstart; // current string\n\t\tlet match; // matched string\n\t\tlet len; // length of current match\n\t\tlet best_len = prev_length; // best match length so far\n\t\tconst limit = strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0;\n\t\tlet _nice_match = nice_match;\n\n\t\t// Stop when cur_match becomes <= limit. To simplify the code,\n\t\t// we prevent matches with the string of win index 0.\n\n\t\tconst wmask = w_mask;\n\n\t\tconst strend = strstart + MAX_MATCH;\n\t\tlet scan_end1 = win[scan + best_len - 1];\n\t\tlet scan_end = win[scan + best_len];\n\n\t\t// The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of\n\t\t// 16.\n\t\t// It is easy to get rid of this optimization if necessary.\n\n\t\t// Do not waste too much time if we already have a good match:\n\t\tif (prev_length >= good_match) {\n\t\t\tchain_length >>= 2;\n\t\t}\n\n\t\t// Do not look for matches beyond the end of the input. This is\n\t\t// necessary\n\t\t// to make deflate deterministic.\n\t\tif (_nice_match > lookahead)\n\t\t\t_nice_match = lookahead;\n\n\t\tdo {\n\t\t\tmatch = cur_match;\n\n\t\t\t// Skip to next match if the match length cannot increase\n\t\t\t// or if the match length is less than 2:\n\t\t\tif (win[match + best_len] != scan_end || win[match + best_len - 1] != scan_end1 || win[match] != win[scan]\n\t\t\t\t|| win[++match] != win[scan + 1])\n\t\t\t\tcontinue;\n\n\t\t\t// The check at best_len-1 can be removed because it will be made\n\t\t\t// again later. (This heuristic is not always a win.)\n\t\t\t// It is not necessary to compare scan[2] and match[2] since they\n\t\t\t// are always equal when the other bytes match, given that\n\t\t\t// the hash keys are equal and that HASH_BITS >= 8.\n\t\t\tscan += 2;\n\t\t\tmatch++;\n\n\t\t\t// We check for insufficient lookahead only every 8th comparison;\n\t\t\t// the 256th check will be made at strstart+258.\n\t\t\t// eslint-disable-next-line no-empty\n\t\t\tdo {\n\t\t\t\t// empty block\n\t\t\t} while (win[++scan] == win[++match] && win[++scan] == win[++match] && win[++scan] == win[++match]\n\t\t\t&& win[++scan] == win[++match] && win[++scan] == win[++match] && win[++scan] == win[++match]\n\t\t\t&& win[++scan] == win[++match] && win[++scan] == win[++match] && scan < strend);\n\n\t\t\tlen = MAX_MATCH - (strend - scan);\n\t\t\tscan = strend - MAX_MATCH;\n\n\t\t\tif (len > best_len) {\n\t\t\t\tmatch_start = cur_match;\n\t\t\t\tbest_len = len;\n\t\t\t\tif (len >= _nice_match)\n\t\t\t\t\tbreak;\n\t\t\t\tscan_end1 = win[scan + best_len - 1];\n\t\t\t\tscan_end = win[scan + best_len];\n\t\t\t}\n\n\t\t} while ((cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length !== 0);\n\n\t\tif (best_len <= lookahead)\n\t\t\treturn best_len;\n\t\treturn lookahead;\n\t}\n\n\t// Compress as much as possible from the input stream, return the current\n\t// block state.\n\t// This function does not perform lazy evaluation of matches and inserts\n\t// new strings in the dictionary only for unmatched strings or for short\n\t// matches. It is used only for the fast compression options.\n\tfunction deflate_fast(flush) {\n\t\t// short hash_head = 0; // head of the hash chain\n\t\tlet hash_head = 0; // head of the hash chain\n\t\tlet bflush; // set if current block must be flushed\n\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\t// Make sure that we always have enough lookahead, except\n\t\t\t// at the end of the input file. We need MAX_MATCH bytes\n\t\t\t// for the next match, plus MIN_MATCH bytes to insert the\n\t\t\t// string following the next match.\n\t\t\tif (lookahead < MIN_LOOKAHEAD) {\n\t\t\t\tfill_window();\n\t\t\t\tif (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {\n\t\t\t\t\treturn NeedMore;\n\t\t\t\t}\n\t\t\t\tif (lookahead === 0)\n\t\t\t\t\tbreak; // flush the current block\n\t\t\t}\n\n\t\t\t// Insert the string win[strstart .. strstart+2] in the\n\t\t\t// dictionary, and set hash_head to the head of the hash chain:\n\t\t\tif (lookahead >= MIN_MATCH) {\n\t\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;\n\n\t\t\t\t// prev[strstart&w_mask]=hash_head=head[ins_h];\n\t\t\t\thash_head = (head[ins_h] & 0xffff);\n\t\t\t\tprev[strstart & w_mask] = head[ins_h];\n\t\t\t\thead[ins_h] = strstart;\n\t\t\t}\n\n\t\t\t// Find the longest match, discarding those <= prev_length.\n\t\t\t// At this point we have always match_length < MIN_MATCH\n\n\t\t\tif (hash_head !== 0 && ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD) {\n\t\t\t\t// To simplify the code, we prevent matches with the string\n\t\t\t\t// of win index 0 (in particular we have to avoid a match\n\t\t\t\t// of the string with itself at the start of the input file).\n\t\t\t\tif (strategy != Z_HUFFMAN_ONLY) {\n\t\t\t\t\tmatch_length = longest_match(hash_head);\n\t\t\t\t}\n\t\t\t\t// longest_match() sets match_start\n\t\t\t}\n\t\t\tif (match_length >= MIN_MATCH) {\n\t\t\t\t// check_match(strstart, match_start, match_length);\n\n\t\t\t\tbflush = _tr_tally(strstart - match_start, match_length - MIN_MATCH);\n\n\t\t\t\tlookahead -= match_length;\n\n\t\t\t\t// Insert new strings in the hash table only if the match length\n\t\t\t\t// is not too large. This saves time but degrades compression.\n\t\t\t\tif (match_length <= max_lazy_match && lookahead >= MIN_MATCH) {\n\t\t\t\t\tmatch_length--; // string at strstart already in hash table\n\t\t\t\t\tdo {\n\t\t\t\t\t\tstrstart++;\n\n\t\t\t\t\t\tins_h = ((ins_h << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;\n\t\t\t\t\t\t// prev[strstart&w_mask]=hash_head=head[ins_h];\n\t\t\t\t\t\thash_head = (head[ins_h] & 0xffff);\n\t\t\t\t\t\tprev[strstart & w_mask] = head[ins_h];\n\t\t\t\t\t\thead[ins_h] = strstart;\n\n\t\t\t\t\t\t// strstart never exceeds WSIZE-MAX_MATCH, so there are\n\t\t\t\t\t\t// always MIN_MATCH bytes ahead.\n\t\t\t\t\t} while (--match_length !== 0);\n\t\t\t\t\tstrstart++;\n\t\t\t\t} else {\n\t\t\t\t\tstrstart += match_length;\n\t\t\t\t\tmatch_length = 0;\n\t\t\t\t\tins_h = win[strstart] & 0xff;\n\n\t\t\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[strstart + 1] & 0xff)) & hash_mask;\n\t\t\t\t\t// If lookahead < MIN_MATCH, ins_h is garbage, but it does\n\t\t\t\t\t// not\n\t\t\t\t\t// matter since it will be recomputed at next deflate call.\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No match, output a literal byte\n\n\t\t\t\tbflush = _tr_tally(0, win[strstart] & 0xff);\n\t\t\t\tlookahead--;\n\t\t\t\tstrstart++;\n\t\t\t}\n\t\t\tif (bflush) {\n\n\t\t\t\tflush_block_only(false);\n\t\t\t\tif (strm.avail_out === 0)\n\t\t\t\t\treturn NeedMore;\n\t\t\t}\n\t\t}\n\n\t\tflush_block_only(flush == Z_FINISH);\n\t\tif (strm.avail_out === 0) {\n\t\t\tif (flush == Z_FINISH)\n\t\t\t\treturn FinishStarted;\n\t\t\telse\n\t\t\t\treturn NeedMore;\n\t\t}\n\t\treturn flush == Z_FINISH ? FinishDone : BlockDone;\n\t}\n\n\t// Same as above, but achieves better compression. We use a lazy\n\t// evaluation for matches: a match is finally adopted only if there is\n\t// no better match at the next win position.\n\tfunction deflate_slow(flush) {\n\t\t// short hash_head = 0; // head of hash chain\n\t\tlet hash_head = 0; // head of hash chain\n\t\tlet bflush; // set if current block must be flushed\n\t\tlet max_insert;\n\n\t\t// Process the input block.\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\t// Make sure that we always have enough lookahead, except\n\t\t\t// at the end of the input file. We need MAX_MATCH bytes\n\t\t\t// for the next match, plus MIN_MATCH bytes to insert the\n\t\t\t// string following the next match.\n\n\t\t\tif (lookahead < MIN_LOOKAHEAD) {\n\t\t\t\tfill_window();\n\t\t\t\tif (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {\n\t\t\t\t\treturn NeedMore;\n\t\t\t\t}\n\t\t\t\tif (lookahead === 0)\n\t\t\t\t\tbreak; // flush the current block\n\t\t\t}\n\n\t\t\t// Insert the string win[strstart .. strstart+2] in the\n\t\t\t// dictionary, and set hash_head to the head of the hash chain:\n\n\t\t\tif (lookahead >= MIN_MATCH) {\n\t\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;\n\t\t\t\t// prev[strstart&w_mask]=hash_head=head[ins_h];\n\t\t\t\thash_head = (head[ins_h] & 0xffff);\n\t\t\t\tprev[strstart & w_mask] = head[ins_h];\n\t\t\t\thead[ins_h] = strstart;\n\t\t\t}\n\n\t\t\t// Find the longest match, discarding those <= prev_length.\n\t\t\tprev_length = match_length;\n\t\t\tprev_match = match_start;\n\t\t\tmatch_length = MIN_MATCH - 1;\n\n\t\t\tif (hash_head !== 0 && prev_length < max_lazy_match && ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD) {\n\t\t\t\t// To simplify the code, we prevent matches with the string\n\t\t\t\t// of win index 0 (in particular we have to avoid a match\n\t\t\t\t// of the string with itself at the start of the input file).\n\n\t\t\t\tif (strategy != Z_HUFFMAN_ONLY) {\n\t\t\t\t\tmatch_length = longest_match(hash_head);\n\t\t\t\t}\n\t\t\t\t// longest_match() sets match_start\n\n\t\t\t\tif (match_length <= 5 && (strategy == Z_FILTERED || (match_length == MIN_MATCH && strstart - match_start > 4096))) {\n\n\t\t\t\t\t// If prev_match is also MIN_MATCH, match_start is garbage\n\t\t\t\t\t// but we will ignore the current match anyway.\n\t\t\t\t\tmatch_length = MIN_MATCH - 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If there was a match at the previous step and the current\n\t\t\t// match is not better, output the previous match:\n\t\t\tif (prev_length >= MIN_MATCH && match_length <= prev_length) {\n\t\t\t\tmax_insert = strstart + lookahead - MIN_MATCH;\n\t\t\t\t// Do not insert strings in hash table beyond this.\n\n\t\t\t\t// check_match(strstart-1, prev_match, prev_length);\n\n\t\t\t\tbflush = _tr_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH);\n\n\t\t\t\t// Insert in hash table all strings up to the end of the match.\n\t\t\t\t// strstart-1 and strstart are already inserted. If there is not\n\t\t\t\t// enough lookahead, the last two strings are not inserted in\n\t\t\t\t// the hash table.\n\t\t\t\tlookahead -= prev_length - 1;\n\t\t\t\tprev_length -= 2;\n\t\t\t\tdo {\n\t\t\t\t\tif (++strstart <= max_insert) {\n\t\t\t\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;\n\t\t\t\t\t\t// prev[strstart&w_mask]=hash_head=head[ins_h];\n\t\t\t\t\t\thash_head = (head[ins_h] & 0xffff);\n\t\t\t\t\t\tprev[strstart & w_mask] = head[ins_h];\n\t\t\t\t\t\thead[ins_h] = strstart;\n\t\t\t\t\t}\n\t\t\t\t} while (--prev_length !== 0);\n\t\t\t\tmatch_available = 0;\n\t\t\t\tmatch_length = MIN_MATCH - 1;\n\t\t\t\tstrstart++;\n\n\t\t\t\tif (bflush) {\n\t\t\t\t\tflush_block_only(false);\n\t\t\t\t\tif (strm.avail_out === 0)\n\t\t\t\t\t\treturn NeedMore;\n\t\t\t\t}\n\t\t\t} else if (match_available !== 0) {\n\n\t\t\t\t// If there was no match at the previous position, output a\n\t\t\t\t// single literal. If there was a match but the current match\n\t\t\t\t// is longer, truncate the previous match to a single literal.\n\n\t\t\t\tbflush = _tr_tally(0, win[strstart - 1] & 0xff);\n\n\t\t\t\tif (bflush) {\n\t\t\t\t\tflush_block_only(false);\n\t\t\t\t}\n\t\t\t\tstrstart++;\n\t\t\t\tlookahead--;\n\t\t\t\tif (strm.avail_out === 0)\n\t\t\t\t\treturn NeedMore;\n\t\t\t} else {\n\t\t\t\t// There is no previous match to compare with, wait for\n\t\t\t\t// the next step to decide.\n\n\t\t\t\tmatch_available = 1;\n\t\t\t\tstrstart++;\n\t\t\t\tlookahead--;\n\t\t\t}\n\t\t}\n\n\t\tif (match_available !== 0) {\n\t\t\tbflush = _tr_tally(0, win[strstart - 1] & 0xff);\n\t\t\tmatch_available = 0;\n\t\t}\n\t\tflush_block_only(flush == Z_FINISH);\n\n\t\tif (strm.avail_out === 0) {\n\t\t\tif (flush == Z_FINISH)\n\t\t\t\treturn FinishStarted;\n\t\t\telse\n\t\t\t\treturn NeedMore;\n\t\t}\n\n\t\treturn flush == Z_FINISH ? FinishDone : BlockDone;\n\t}\n\n\tfunction deflateReset(strm) {\n\t\tstrm.total_in = strm.total_out = 0;\n\t\tstrm.msg = null; //\n\n\t\tthat.pending = 0;\n\t\tthat.pending_out = 0;\n\n\t\tstatus = BUSY_STATE;\n\n\t\tlast_flush = Z_NO_FLUSH;\n\n\t\ttr_init();\n\t\tlm_init();\n\t\treturn Z_OK;\n\t}\n\n\tthat.deflateInit = function (strm, _level, bits, _method, memLevel, _strategy) {\n\t\tif (!_method)\n\t\t\t_method = Z_DEFLATED;\n\t\tif (!memLevel)\n\t\t\tmemLevel = DEF_MEM_LEVEL;\n\t\tif (!_strategy)\n\t\t\t_strategy = Z_DEFAULT_STRATEGY;\n\n\t\t// byte[] my_version=ZLIB_VERSION;\n\n\t\t//\n\t\t// if (!version || version[0] != my_version[0]\n\t\t// || stream_size != sizeof(z_stream)) {\n\t\t// return Z_VERSION_ERROR;\n\t\t// }\n\n\t\tstrm.msg = null;\n\n\t\tif (_level == Z_DEFAULT_COMPRESSION)\n\t\t\t_level = 6;\n\n\t\tif (memLevel < 1 || memLevel > MAX_MEM_LEVEL || _method != Z_DEFLATED || bits < 9 || bits > 15 || _level < 0 || _level > 9 || _strategy < 0\n\t\t\t|| _strategy > Z_HUFFMAN_ONLY) {\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\n\t\tstrm.dstate = that;\n\n\t\tw_bits = bits;\n\t\tw_size = 1 << w_bits;\n\t\tw_mask = w_size - 1;\n\n\t\thash_bits = memLevel + 7;\n\t\thash_size = 1 << hash_bits;\n\t\thash_mask = hash_size - 1;\n\t\thash_shift = Math.floor((hash_bits + MIN_MATCH - 1) / MIN_MATCH);\n\n\t\twin = new Uint8Array(w_size * 2);\n\t\tprev = [];\n\t\thead = [];\n\n\t\tlit_bufsize = 1 << (memLevel + 6); // 16K elements by default\n\n\t\tthat.pending_buf = new Uint8Array(lit_bufsize * 4);\n\t\tpending_buf_size = lit_bufsize * 4;\n\n\t\tthat.dist_buf = new Uint16Array(lit_bufsize);\n\t\tthat.lc_buf = new Uint8Array(lit_bufsize);\n\n\t\tlevel = _level;\n\n\t\tstrategy = _strategy;\n\n\t\treturn deflateReset(strm);\n\t};\n\n\tthat.deflateEnd = function () {\n\t\tif (status != INIT_STATE && status != BUSY_STATE && status != FINISH_STATE) {\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\t\t// Deallocate in reverse order of allocations:\n\t\tthat.lc_buf = null;\n\t\tthat.dist_buf = null;\n\t\tthat.pending_buf = null;\n\t\thead = null;\n\t\tprev = null;\n\t\twin = null;\n\t\t// free\n\t\tthat.dstate = null;\n\t\treturn status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;\n\t};\n\n\tthat.deflateParams = function (strm, _level, _strategy) {\n\t\tlet err = Z_OK;\n\n\t\tif (_level == Z_DEFAULT_COMPRESSION) {\n\t\t\t_level = 6;\n\t\t}\n\t\tif (_level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) {\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\n\t\tif (config_table[level].func != config_table[_level].func && strm.total_in !== 0) {\n\t\t\t// Flush the last buffer:\n\t\t\terr = strm.deflate(Z_PARTIAL_FLUSH);\n\t\t}\n\n\t\tif (level != _level) {\n\t\t\tlevel = _level;\n\t\t\tmax_lazy_match = config_table[level].max_lazy;\n\t\t\tgood_match = config_table[level].good_length;\n\t\t\tnice_match = config_table[level].nice_length;\n\t\t\tmax_chain_length = config_table[level].max_chain;\n\t\t}\n\t\tstrategy = _strategy;\n\t\treturn err;\n\t};\n\n\tthat.deflateSetDictionary = function (_strm, dictionary, dictLength) {\n\t\tlet length = dictLength;\n\t\tlet n, index = 0;\n\n\t\tif (!dictionary || status != INIT_STATE)\n\t\t\treturn Z_STREAM_ERROR;\n\n\t\tif (length < MIN_MATCH)\n\t\t\treturn Z_OK;\n\t\tif (length > w_size - MIN_LOOKAHEAD) {\n\t\t\tlength = w_size - MIN_LOOKAHEAD;\n\t\t\tindex = dictLength - length; // use the tail of the dictionary\n\t\t}\n\t\twin.set(dictionary.subarray(index, index + length), 0);\n\n\t\tstrstart = length;\n\t\tblock_start = length;\n\n\t\t// Insert all strings in the hash table (except for the last two bytes).\n\t\t// s->lookahead stays null, so s->ins_h will be recomputed at the next\n\t\t// call of fill_window.\n\n\t\tins_h = win[0] & 0xff;\n\t\tins_h = (((ins_h) << hash_shift) ^ (win[1] & 0xff)) & hash_mask;\n\n\t\tfor (n = 0; n <= length - MIN_MATCH; n++) {\n\t\t\tins_h = (((ins_h) << hash_shift) ^ (win[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;\n\t\t\tprev[n & w_mask] = head[ins_h];\n\t\t\thead[ins_h] = n;\n\t\t}\n\t\treturn Z_OK;\n\t};\n\n\tthat.deflate = function (_strm, flush) {\n\t\tlet i, header, level_flags, old_flush, bstate;\n\n\t\tif (flush > Z_FINISH || flush < 0) {\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\n\t\tif (!_strm.next_out || (!_strm.next_in && _strm.avail_in !== 0) || (status == FINISH_STATE && flush != Z_FINISH)) {\n\t\t\t_strm.msg = z_errmsg[Z_NEED_DICT - (Z_STREAM_ERROR)];\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\t\tif (_strm.avail_out === 0) {\n\t\t\t_strm.msg = z_errmsg[Z_NEED_DICT - (Z_BUF_ERROR)];\n\t\t\treturn Z_BUF_ERROR;\n\t\t}\n\n\t\tstrm = _strm; // just in case\n\t\told_flush = last_flush;\n\t\tlast_flush = flush;\n\n\t\t// Write the zlib header\n\t\tif (status == INIT_STATE) {\n\t\t\theader = (Z_DEFLATED + ((w_bits - 8) << 4)) << 8;\n\t\t\tlevel_flags = ((level - 1) & 0xff) >> 1;\n\n\t\t\tif (level_flags > 3)\n\t\t\t\tlevel_flags = 3;\n\t\t\theader |= (level_flags << 6);\n\t\t\tif (strstart !== 0)\n\t\t\t\theader |= PRESET_DICT;\n\t\t\theader += 31 - (header % 31);\n\n\t\t\tstatus = BUSY_STATE;\n\t\t\tputShortMSB(header);\n\t\t}\n\n\t\t// Flush as much pending output as possible\n\t\tif (that.pending !== 0) {\n\t\t\tstrm.flush_pending();\n\t\t\tif (strm.avail_out === 0) {\n\t\t\t\t// console.log(\" avail_out==0\");\n\t\t\t\t// Since avail_out is 0, deflate will be called again with\n\t\t\t\t// more output space, but possibly with both pending and\n\t\t\t\t// avail_in equal to zero. There won't be anything to do,\n\t\t\t\t// but this is not an error situation so make sure we\n\t\t\t\t// return OK instead of BUF_ERROR at next call of deflate:\n\t\t\t\tlast_flush = -1;\n\t\t\t\treturn Z_OK;\n\t\t\t}\n\n\t\t\t// Make sure there is something to do and avoid duplicate\n\t\t\t// consecutive\n\t\t\t// flushes. For repeated and useless calls with Z_FINISH, we keep\n\t\t\t// returning Z_STREAM_END instead of Z_BUFF_ERROR.\n\t\t} else if (strm.avail_in === 0 && flush <= old_flush && flush != Z_FINISH) {\n\t\t\tstrm.msg = z_errmsg[Z_NEED_DICT - (Z_BUF_ERROR)];\n\t\t\treturn Z_BUF_ERROR;\n\t\t}\n\n\t\t// User must not provide more input after the first FINISH:\n\t\tif (status == FINISH_STATE && strm.avail_in !== 0) {\n\t\t\t_strm.msg = z_errmsg[Z_NEED_DICT - (Z_BUF_ERROR)];\n\t\t\treturn Z_BUF_ERROR;\n\t\t}\n\n\t\t// Start a new block or continue the current one.\n\t\tif (strm.avail_in !== 0 || lookahead !== 0 || (flush != Z_NO_FLUSH && status != FINISH_STATE)) {\n\t\t\tbstate = -1;\n\t\t\tswitch (config_table[level].func) {\n\t\t\t\tcase STORED:\n\t\t\t\t\tbstate = deflate_stored(flush);\n\t\t\t\t\tbreak;\n\t\t\t\tcase FAST:\n\t\t\t\t\tbstate = deflate_fast(flush);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SLOW:\n\t\t\t\t\tbstate = deflate_slow(flush);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t}\n\n\t\t\tif (bstate == FinishStarted || bstate == FinishDone) {\n\t\t\t\tstatus = FINISH_STATE;\n\t\t\t}\n\t\t\tif (bstate == NeedMore || bstate == FinishStarted) {\n\t\t\t\tif (strm.avail_out === 0) {\n\t\t\t\t\tlast_flush = -1; // avoid BUF_ERROR next call, see above\n\t\t\t\t}\n\t\t\t\treturn Z_OK;\n\t\t\t\t// If flush != Z_NO_FLUSH && avail_out === 0, the next call\n\t\t\t\t// of deflate should use the same flush parameter to make sure\n\t\t\t\t// that the flush is complete. So we don't have to output an\n\t\t\t\t// empty block here, this will be done at next call. This also\n\t\t\t\t// ensures that for a very small output buffer, we emit at most\n\t\t\t\t// one empty block.\n\t\t\t}\n\n\t\t\tif (bstate == BlockDone) {\n\t\t\t\tif (flush == Z_PARTIAL_FLUSH) {\n\t\t\t\t\t_tr_align();\n\t\t\t\t} else { // FULL_FLUSH or SYNC_FLUSH\n\t\t\t\t\t_tr_stored_block(0, 0, false);\n\t\t\t\t\t// For a full flush, this empty block will be recognized\n\t\t\t\t\t// as a special marker by inflate_sync().\n\t\t\t\t\tif (flush == Z_FULL_FLUSH) {\n\t\t\t\t\t\t// state.head[s.hash_size-1]=0;\n\t\t\t\t\t\tfor (i = 0; i < hash_size/*-1*/; i++)\n\t\t\t\t\t\t\t// forget history\n\t\t\t\t\t\t\thead[i] = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstrm.flush_pending();\n\t\t\t\tif (strm.avail_out === 0) {\n\t\t\t\t\tlast_flush = -1; // avoid BUF_ERROR at next call, see above\n\t\t\t\t\treturn Z_OK;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (flush != Z_FINISH)\n\t\t\treturn Z_OK;\n\t\treturn Z_STREAM_END;\n\t};\n}\n\n// ZStream\n\nfunction ZStream() {\n\tconst that = this;\n\tthat.next_in_index = 0;\n\tthat.next_out_index = 0;\n\t// that.next_in; // next input byte\n\tthat.avail_in = 0; // number of bytes available at next_in\n\tthat.total_in = 0; // total nb of input bytes read so far\n\t// that.next_out; // next output byte should be put there\n\tthat.avail_out = 0; // remaining free space at next_out\n\tthat.total_out = 0; // total nb of bytes output so far\n\t// that.msg;\n\t// that.dstate;\n}\n\nZStream.prototype = {\n\tdeflateInit: function (level, bits) {\n\t\tconst that = this;\n\t\tthat.dstate = new Deflate();\n\t\tif (!bits)\n\t\t\tbits = MAX_BITS;\n\t\treturn that.dstate.deflateInit(that, level, bits);\n\t},\n\n\tdeflate: function (flush) {\n\t\tconst that = this;\n\t\tif (!that.dstate) {\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\t\treturn that.dstate.deflate(that, flush);\n\t},\n\n\tdeflateEnd: function () {\n\t\tconst that = this;\n\t\tif (!that.dstate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\tconst ret = that.dstate.deflateEnd();\n\t\tthat.dstate = null;\n\t\treturn ret;\n\t},\n\n\tdeflateParams: function (level, strategy) {\n\t\tconst that = this;\n\t\tif (!that.dstate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn that.dstate.deflateParams(that, level, strategy);\n\t},\n\n\tdeflateSetDictionary: function (dictionary, dictLength) {\n\t\tconst that = this;\n\t\tif (!that.dstate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn that.dstate.deflateSetDictionary(that, dictionary, dictLength);\n\t},\n\n\t// Read a new buffer from the current input stream, update the\n\t// total number of bytes read. All deflate() input goes through\n\t// this function so some applications may wish to modify it to avoid\n\t// allocating a large strm->next_in buffer and copying from it.\n\t// (See also flush_pending()).\n\tread_buf: function (buf, start, size) {\n\t\tconst that = this;\n\t\tlet len = that.avail_in;\n\t\tif (len > size)\n\t\t\tlen = size;\n\t\tif (len === 0)\n\t\t\treturn 0;\n\t\tthat.avail_in -= len;\n\t\tbuf.set(that.next_in.subarray(that.next_in_index, that.next_in_index + len), start);\n\t\tthat.next_in_index += len;\n\t\tthat.total_in += len;\n\t\treturn len;\n\t},\n\n\t// Flush as much pending output as possible. All deflate() output goes\n\t// through this function so some applications may wish to modify it\n\t// to avoid allocating a large strm->next_out buffer and copying into it.\n\t// (See also read_buf()).\n\tflush_pending: function () {\n\t\tconst that = this;\n\t\tlet len = that.dstate.pending;\n\n\t\tif (len > that.avail_out)\n\t\t\tlen = that.avail_out;\n\t\tif (len === 0)\n\t\t\treturn;\n\n\t\t// if (that.dstate.pending_buf.length <= that.dstate.pending_out || that.next_out.length <= that.next_out_index\n\t\t// || that.dstate.pending_buf.length < (that.dstate.pending_out + len) || that.next_out.length < (that.next_out_index +\n\t\t// len)) {\n\t\t// console.log(that.dstate.pending_buf.length + \", \" + that.dstate.pending_out + \", \" + that.next_out.length + \", \" +\n\t\t// that.next_out_index + \", \" + len);\n\t\t// console.log(\"avail_out=\" + that.avail_out);\n\t\t// }\n\n\t\tthat.next_out.set(that.dstate.pending_buf.subarray(that.dstate.pending_out, that.dstate.pending_out + len), that.next_out_index);\n\n\t\tthat.next_out_index += len;\n\t\tthat.dstate.pending_out += len;\n\t\tthat.total_out += len;\n\t\tthat.avail_out -= len;\n\t\tthat.dstate.pending -= len;\n\t\tif (that.dstate.pending === 0) {\n\t\t\tthat.dstate.pending_out = 0;\n\t\t}\n\t}\n};\n\n// Deflate\n\nfunction ZipDeflate(options) {\n\tconst that = this;\n\tconst z = new ZStream();\n\tconst bufsize = getMaximumCompressedSize(options && options.chunkSize ? options.chunkSize : 64 * 1024);\n\tconst flush = Z_NO_FLUSH;\n\tconst buf = new Uint8Array(bufsize);\n\tlet level = options ? options.level : Z_DEFAULT_COMPRESSION;\n\tif (typeof level == \"undefined\")\n\t\tlevel = Z_DEFAULT_COMPRESSION;\n\tz.deflateInit(level);\n\tz.next_out = buf;\n\n\tthat.append = function (data, onprogress) {\n\t\tlet err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;\n\t\tconst buffers = [];\n\t\tif (!data.length)\n\t\t\treturn;\n\t\tz.next_in_index = 0;\n\t\tz.next_in = data;\n\t\tz.avail_in = data.length;\n\t\tdo {\n\t\t\tz.next_out_index = 0;\n\t\t\tz.avail_out = bufsize;\n\t\t\terr = z.deflate(flush);\n\t\t\tif (err != Z_OK)\n\t\t\t\tthrow new Error(\"deflating: \" + z.msg);\n\t\t\tif (z.next_out_index)\n\t\t\t\tif (z.next_out_index == bufsize)\n\t\t\t\t\tbuffers.push(new Uint8Array(buf));\n\t\t\t\telse\n\t\t\t\t\tbuffers.push(buf.slice(0, z.next_out_index));\n\t\t\tbufferSize += z.next_out_index;\n\t\t\tif (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {\n\t\t\t\tonprogress(z.next_in_index);\n\t\t\t\tlastIndex = z.next_in_index;\n\t\t\t}\n\t\t} while (z.avail_in > 0 || z.avail_out === 0);\n\t\tif (buffers.length > 1) {\n\t\t\tarray = new Uint8Array(bufferSize);\n\t\t\tbuffers.forEach(function (chunk) {\n\t\t\t\tarray.set(chunk, bufferIndex);\n\t\t\t\tbufferIndex += chunk.length;\n\t\t\t});\n\t\t} else {\n\t\t\tarray = buffers[0] || new Uint8Array(0);\n\t\t}\n\t\treturn array;\n\t};\n\tthat.flush = function () {\n\t\tlet err, array, bufferIndex = 0, bufferSize = 0;\n\t\tconst buffers = [];\n\t\tdo {\n\t\t\tz.next_out_index = 0;\n\t\t\tz.avail_out = bufsize;\n\t\t\terr = z.deflate(Z_FINISH);\n\t\t\tif (err != Z_STREAM_END && err != Z_OK)\n\t\t\t\tthrow new Error(\"deflating: \" + z.msg);\n\t\t\tif (bufsize - z.avail_out > 0)\n\t\t\t\tbuffers.push(buf.slice(0, z.next_out_index));\n\t\t\tbufferSize += z.next_out_index;\n\t\t} while (z.avail_in > 0 || z.avail_out === 0);\n\t\tz.deflateEnd();\n\t\tarray = new Uint8Array(bufferSize);\n\t\tbuffers.forEach(function (chunk) {\n\t\t\tarray.set(chunk, bufferIndex);\n\t\t\tbufferIndex += chunk.length;\n\t\t});\n\t\treturn array;\n\t};\n}\n\nfunction getMaximumCompressedSize(uncompressedSize) {\n\treturn uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));\n}\n\nexport default ZipDeflate;", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/*\n * This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.\n * JZlib is based on zlib-1.1.3, so all credit should go authors\n * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)\n * and contributors of zlib.\n */\n\n// deno-lint-ignore-file no-this-alias prefer-const\n\n// Global\nconst MAX_BITS = 15;\n\nconst Z_OK = 0;\nconst Z_STREAM_END = 1;\nconst Z_NEED_DICT = 2;\nconst Z_STREAM_ERROR = -2;\nconst Z_DATA_ERROR = -3;\nconst Z_MEM_ERROR = -4;\nconst Z_BUF_ERROR = -5;\n\nconst inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff,\n\t0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];\n\nconst MANY = 1440;\n\n// JZlib version : \"1.0.2\"\nconst Z_NO_FLUSH = 0;\nconst Z_FINISH = 4;\n\n// InfTree\nconst fixed_bl = 9;\nconst fixed_bd = 5;\n\nconst fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0,\n\t0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40,\n\t0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13,\n\t0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60,\n\t0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7,\n\t35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8,\n\t26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80,\n\t7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0,\n\t8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0,\n\t8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97,\n\t0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,\n\t81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117,\n\t0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,\n\t84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83,\n\t0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,\n\t80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139,\n\t0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,\n\t0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111,\n\t0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9,\n\t193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8,\n\t120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8,\n\t227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8,\n\t92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9,\n\t249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8,\n\t130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9,\n\t181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8,\n\t102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9,\n\t221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0,\n\t8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9,\n\t147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8,\n\t85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9,\n\t235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8,\n\t141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9,\n\t167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8,\n\t107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9,\n\t207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8,\n\t127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];\nconst fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5,\n\t8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5,\n\t24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];\n\n// Tables for deflate from PKZIP's appnote.txt.\nconst cplens = [ // Copy lengths for literal codes 257..285\n\t3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];\n\n// see note #13 above about 258\nconst cplext = [ // Extra bits for literal codes 257..285\n\t0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112 // 112==invalid\n];\n\nconst cpdist = [ // Copy offsets for distance codes 0..29\n\t1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];\n\nconst cpdext = [ // Extra bits for distance codes\n\t0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];\n\n// If BMAX needs to be larger than 16, then h and x[] should be uLong.\nconst BMAX = 15; // maximum bit length of any code\n\nfunction InfTree() {\n\tconst that = this;\n\n\tlet hn; // hufts used in space\n\tlet v; // work area for huft_build\n\tlet c; // bit length count table\n\tlet r; // table entry for structure assignment\n\tlet u; // table stack\n\tlet x; // bit offsets, then code stack\n\n\tfunction huft_build(b, // code lengths in bits (all assumed <=\n\t\t// BMAX)\n\t\tbindex, n, // number of codes (assumed <= 288)\n\t\ts, // number of simple-valued codes (0..s-1)\n\t\td, // list of base values for non-simple codes\n\t\te, // list of extra bits for non-simple codes\n\t\tt, // result: starting table\n\t\tm, // maximum lookup bits, returns actual\n\t\thp,// space for trees\n\t\thn,// hufts used in space\n\t\tv // working area: values in order of bit length\n\t) {\n\t\t// Given a list of code lengths and a maximum table size, make a set of\n\t\t// tables to decode that set of codes. Return Z_OK on success,\n\t\t// Z_BUF_ERROR\n\t\t// if the given code set is incomplete (the tables are still built in\n\t\t// this\n\t\t// case), Z_DATA_ERROR if the input is invalid (an over-subscribed set\n\t\t// of\n\t\t// lengths), or Z_MEM_ERROR if not enough memory.\n\n\t\tlet a; // counter for codes of length k\n\t\tlet f; // i repeats in table every f entries\n\t\tlet g; // maximum code length\n\t\tlet h; // table level\n\t\tlet i; // counter, current code\n\t\tlet j; // counter\n\t\tlet k; // number of bits in current code\n\t\tlet l; // bits per table (returned in m)\n\t\tlet mask; // (1 << w) - 1, to avoid cc -O bug on HP\n\t\tlet p; // pointer into c[], b[], or v[]\n\t\tlet q; // points to current table\n\t\tlet w; // bits before this table == (l * h)\n\t\tlet xp; // pointer into x\n\t\tlet y; // number of dummy codes added\n\t\tlet z; // number of entries in current table\n\n\t\t// Generate counts for each bit length\n\n\t\tp = 0;\n\t\ti = n;\n\t\tdo {\n\t\t\tc[b[bindex + p]]++;\n\t\t\tp++;\n\t\t\ti--; // assume all entries <= BMAX\n\t\t} while (i !== 0);\n\n\t\tif (c[0] == n) { // null input--all zero length codes\n\t\t\tt[0] = -1;\n\t\t\tm[0] = 0;\n\t\t\treturn Z_OK;\n\t\t}\n\n\t\t// Find minimum and maximum length, bound *m by those\n\t\tl = m[0];\n\t\tfor (j = 1; j <= BMAX; j++)\n\t\t\tif (c[j] !== 0)\n\t\t\t\tbreak;\n\t\tk = j; // minimum code length\n\t\tif (l < j) {\n\t\t\tl = j;\n\t\t}\n\t\tfor (i = BMAX; i !== 0; i--) {\n\t\t\tif (c[i] !== 0)\n\t\t\t\tbreak;\n\t\t}\n\t\tg = i; // maximum code length\n\t\tif (l > i) {\n\t\t\tl = i;\n\t\t}\n\t\tm[0] = l;\n\n\t\t// Adjust last length count to fill out codes, if needed\n\t\tfor (y = 1 << j; j < i; j++, y <<= 1) {\n\t\t\tif ((y -= c[j]) < 0) {\n\t\t\t\treturn Z_DATA_ERROR;\n\t\t\t}\n\t\t}\n\t\tif ((y -= c[i]) < 0) {\n\t\t\treturn Z_DATA_ERROR;\n\t\t}\n\t\tc[i] += y;\n\n\t\t// Generate starting offsets into the value table for each length\n\t\tx[1] = j = 0;\n\t\tp = 1;\n\t\txp = 2;\n\t\twhile (--i !== 0) { // note that i == g from above\n\t\t\tx[xp] = (j += c[p]);\n\t\t\txp++;\n\t\t\tp++;\n\t\t}\n\n\t\t// Make a table of values in order of bit lengths\n\t\ti = 0;\n\t\tp = 0;\n\t\tdo {\n\t\t\tif ((j = b[bindex + p]) !== 0) {\n\t\t\t\tv[x[j]++] = i;\n\t\t\t}\n\t\t\tp++;\n\t\t} while (++i < n);\n\t\tn = x[g]; // set n to length of v\n\n\t\t// Generate the Huffman codes and for each, make the table entries\n\t\tx[0] = i = 0; // first Huffman code is zero\n\t\tp = 0; // grab values in bit order\n\t\th = -1; // no tables yet--level -1\n\t\tw = -l; // bits decoded == (l * h)\n\t\tu[0] = 0; // just to keep compilers happy\n\t\tq = 0; // ditto\n\t\tz = 0; // ditto\n\n\t\t// go through the bit lengths (k already is bits in shortest code)\n\t\tfor (; k <= g; k++) {\n\t\t\ta = c[k];\n\t\t\twhile (a-- !== 0) {\n\t\t\t\t// here i is the Huffman code of length k bits for value *p\n\t\t\t\t// make tables up to required level\n\t\t\t\twhile (k > w + l) {\n\t\t\t\t\th++;\n\t\t\t\t\tw += l; // previous table always l bits\n\t\t\t\t\t// compute minimum size table less than or equal to l bits\n\t\t\t\t\tz = g - w;\n\t\t\t\t\tz = (z > l) ? l : z; // table size upper limit\n\t\t\t\t\tif ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table\n\t\t\t\t\t\t// too few codes for\n\t\t\t\t\t\t// k-w bit table\n\t\t\t\t\t\tf -= a + 1; // deduct codes from patterns left\n\t\t\t\t\t\txp = k;\n\t\t\t\t\t\tif (j < z) {\n\t\t\t\t\t\t\twhile (++j < z) { // try smaller tables up to z bits\n\t\t\t\t\t\t\t\tif ((f <<= 1) <= c[++xp])\n\t\t\t\t\t\t\t\t\tbreak; // enough codes to use up j bits\n\t\t\t\t\t\t\t\tf -= c[xp]; // else deduct codes from patterns\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tz = 1 << j; // table entries for j-bit table\n\n\t\t\t\t\t// allocate new table\n\t\t\t\t\tif (hn[0] + z > MANY) { // (note: doesn't matter for fixed)\n\t\t\t\t\t\treturn Z_DATA_ERROR; // overflow of MANY\n\t\t\t\t\t}\n\t\t\t\t\tu[h] = q = /* hp+ */hn[0]; // DEBUG\n\t\t\t\t\thn[0] += z;\n\n\t\t\t\t\t// connect to last table, if there is one\n\t\t\t\t\tif (h !== 0) {\n\t\t\t\t\t\tx[h] = i; // save pattern for backing up\n\t\t\t\t\t\tr[0] = /* (byte) */j; // bits in this table\n\t\t\t\t\t\tr[1] = /* (byte) */l; // bits to dump before this table\n\t\t\t\t\t\tj = i >>> (w - l);\n\t\t\t\t\t\tr[2] = /* (int) */(q - u[h - 1] - j); // offset to this table\n\t\t\t\t\t\thp.set(r, (u[h - 1] + j) * 3);\n\t\t\t\t\t\t// to\n\t\t\t\t\t\t// last\n\t\t\t\t\t\t// table\n\t\t\t\t\t} else {\n\t\t\t\t\t\tt[0] = q; // first table is returned result\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// set up table entry in r\n\t\t\t\tr[1] = /* (byte) */(k - w);\n\t\t\t\tif (p >= n) {\n\t\t\t\t\tr[0] = 128 + 64; // out of values--invalid code\n\t\t\t\t} else if (v[p] < s) {\n\t\t\t\t\tr[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is\n\t\t\t\t\t// end-of-block\n\t\t\t\t\tr[2] = v[p++]; // simple code is just the value\n\t\t\t\t} else {\n\t\t\t\t\tr[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look\n\t\t\t\t\t// up in lists\n\t\t\t\t\tr[2] = d[v[p++] - s];\n\t\t\t\t}\n\n\t\t\t\t// fill code-like entries with r\n\t\t\t\tf = 1 << (k - w);\n\t\t\t\tfor (j = i >>> w; j < z; j += f) {\n\t\t\t\t\thp.set(r, (q + j) * 3);\n\t\t\t\t}\n\n\t\t\t\t// backwards increment the k-bit code i\n\t\t\t\tfor (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) {\n\t\t\t\t\ti ^= j;\n\t\t\t\t}\n\t\t\t\ti ^= j;\n\n\t\t\t\t// backup over finished tables\n\t\t\t\tmask = (1 << w) - 1; // needed on HP, cc -O bug\n\t\t\t\twhile ((i & mask) != x[h]) {\n\t\t\t\t\th--; // don't need to update q\n\t\t\t\t\tw -= l;\n\t\t\t\t\tmask = (1 << w) - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Return Z_BUF_ERROR if we were given an incomplete table\n\t\treturn y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK;\n\t}\n\n\tfunction initWorkArea(vsize) {\n\t\tlet i;\n\t\tif (!hn) {\n\t\t\thn = []; // []; //new Array(1);\n\t\t\tv = []; // new Array(vsize);\n\t\t\tc = new Int32Array(BMAX + 1); // new Array(BMAX + 1);\n\t\t\tr = []; // new Array(3);\n\t\t\tu = new Int32Array(BMAX); // new Array(BMAX);\n\t\t\tx = new Int32Array(BMAX + 1); // new Array(BMAX + 1);\n\t\t}\n\t\tif (v.length < vsize) {\n\t\t\tv = []; // new Array(vsize);\n\t\t}\n\t\tfor (i = 0; i < vsize; i++) {\n\t\t\tv[i] = 0;\n\t\t}\n\t\tfor (i = 0; i < BMAX + 1; i++) {\n\t\t\tc[i] = 0;\n\t\t}\n\t\tfor (i = 0; i < 3; i++) {\n\t\t\tr[i] = 0;\n\t\t}\n\t\t// for(int i=0; i 257)) {\n\t\t\tif (result == Z_DATA_ERROR) {\n\t\t\t\tz.msg = \"oversubscribed distance tree\";\n\t\t\t} else if (result == Z_BUF_ERROR) {\n\t\t\t\tz.msg = \"incomplete distance tree\";\n\t\t\t\tresult = Z_DATA_ERROR;\n\t\t\t} else if (result != Z_MEM_ERROR) {\n\t\t\t\tz.msg = \"empty distance tree with lengths\";\n\t\t\t\tresult = Z_DATA_ERROR;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn Z_OK;\n\t};\n\n}\n\nInfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth\n\tbd, // distance desired/actual bit depth\n\ttl,// literal/length tree result\n\ttd// distance tree result\n) {\n\tbl[0] = fixed_bl;\n\tbd[0] = fixed_bd;\n\ttl[0] = fixed_tl;\n\ttd[0] = fixed_td;\n\treturn Z_OK;\n};\n\n// InfCodes\n\n// waiting for \"i:\"=input,\n// \"o:\"=output,\n// \"x:\"=nothing\nconst START = 0; // x: set up for LEN\nconst LEN = 1; // i: get length/literal/eob next\nconst LENEXT = 2; // i: getting length extra (have base)\nconst DIST = 3; // i: get distance next\nconst DISTEXT = 4;// i: getting distance extra\nconst COPY = 5; // o: copying bytes in win, waiting\n// for space\nconst LIT = 6; // o: got literal, waiting for output\n// space\nconst WASH = 7; // o: got eob, possibly still output\n// waiting\nconst END = 8; // x: got eob and all data flushed\nconst BADCODE = 9;// x: got error\n\nfunction InfCodes() {\n\tconst that = this;\n\n\tlet mode; // current inflate_codes mode\n\n\t// mode dependent information\n\tlet len = 0;\n\n\tlet tree; // pointer into tree\n\tlet tree_index = 0;\n\tlet need = 0; // bits needed\n\n\tlet lit = 0;\n\n\t// if EXT or COPY, where and how much\n\tlet get = 0; // bits to get for extra\n\tlet dist = 0; // distance back to copy from\n\n\tlet lbits = 0; // ltree bits decoded per branch\n\tlet dbits = 0; // dtree bits decoder per branch\n\tlet ltree; // literal/length/eob tree\n\tlet ltree_index = 0; // literal/length/eob tree\n\tlet dtree; // distance tree\n\tlet dtree_index = 0; // distance tree\n\n\t// Called with number of bytes left to write in win at least 258\n\t// (the maximum string length) and number of input bytes available\n\t// at least ten. The ten bytes are six bytes for the longest length/\n\t// distance pair plus four bytes for overloading the bit buffer.\n\n\tfunction inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) {\n\t\tlet t; // temporary pointer\n\t\tlet tp; // temporary pointer\n\t\tlet tp_index; // temporary pointer\n\t\tlet e; // extra bits or operation\n\t\tlet b; // bit buffer\n\t\tlet k; // bits in bit buffer\n\t\tlet p; // input data pointer\n\t\tlet n; // bytes available there\n\t\tlet q; // output win write pointer\n\t\tlet m; // bytes to end of win or read pointer\n\t\tlet ml; // mask for literal/length tree\n\t\tlet md; // mask for distance tree\n\t\tlet c; // bytes to copy\n\t\tlet d; // distance back to copy from\n\t\tlet r; // copy source pointer\n\n\t\tlet tp_index_t_3; // (tp_index+t)*3\n\n\t\t// load input, output, bit values\n\t\tp = z.next_in_index;\n\t\tn = z.avail_in;\n\t\tb = s.bitb;\n\t\tk = s.bitk;\n\t\tq = s.write;\n\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t// initialize masks\n\t\tml = inflate_mask[bl];\n\t\tmd = inflate_mask[bd];\n\n\t\t// do until not enough input or output space for fast loop\n\t\tdo { // assume called with m >= 258 && n >= 10\n\t\t\t// get literal/length code\n\t\t\twhile (k < (20)) { // max bits for literal/length code\n\t\t\t\tn--;\n\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\tk += 8;\n\t\t\t}\n\n\t\t\tt = b & ml;\n\t\t\ttp = tl;\n\t\t\ttp_index = tl_index;\n\t\t\ttp_index_t_3 = (tp_index + t) * 3;\n\t\t\tif ((e = tp[tp_index_t_3]) === 0) {\n\t\t\t\tb >>= (tp[tp_index_t_3 + 1]);\n\t\t\t\tk -= (tp[tp_index_t_3 + 1]);\n\n\t\t\t\ts.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];\n\t\t\t\tm--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdo {\n\n\t\t\t\tb >>= (tp[tp_index_t_3 + 1]);\n\t\t\t\tk -= (tp[tp_index_t_3 + 1]);\n\n\t\t\t\tif ((e & 16) !== 0) {\n\t\t\t\t\te &= 15;\n\t\t\t\t\tc = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]);\n\n\t\t\t\t\tb >>= e;\n\t\t\t\t\tk -= e;\n\n\t\t\t\t\t// decode distance base of block to copy\n\t\t\t\t\twhile (k < (15)) { // max bits for distance code\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\tt = b & md;\n\t\t\t\t\ttp = td;\n\t\t\t\t\ttp_index = td_index;\n\t\t\t\t\ttp_index_t_3 = (tp_index + t) * 3;\n\t\t\t\t\te = tp[tp_index_t_3];\n\n\t\t\t\t\tdo {\n\n\t\t\t\t\t\tb >>= (tp[tp_index_t_3 + 1]);\n\t\t\t\t\t\tk -= (tp[tp_index_t_3 + 1]);\n\n\t\t\t\t\t\tif ((e & 16) !== 0) {\n\t\t\t\t\t\t\t// get extra bits to add to distance base\n\t\t\t\t\t\t\te &= 15;\n\t\t\t\t\t\t\twhile (k < (e)) { // get extra bits (up to 13)\n\t\t\t\t\t\t\t\tn--;\n\t\t\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\t\t\tk += 8;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\td = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);\n\n\t\t\t\t\t\t\tb >>= (e);\n\t\t\t\t\t\t\tk -= (e);\n\n\t\t\t\t\t\t\t// do the copy\n\t\t\t\t\t\t\tm -= c;\n\t\t\t\t\t\t\tif (q >= d) { // offset before dest\n\t\t\t\t\t\t\t\t// just copy\n\t\t\t\t\t\t\t\tr = q - d;\n\t\t\t\t\t\t\t\tif (q - r > 0 && 2 > (q - r)) {\n\t\t\t\t\t\t\t\t\ts.win[q++] = s.win[r++]; // minimum\n\t\t\t\t\t\t\t\t\t// count is\n\t\t\t\t\t\t\t\t\t// three,\n\t\t\t\t\t\t\t\t\ts.win[q++] = s.win[r++]; // so unroll\n\t\t\t\t\t\t\t\t\t// loop a\n\t\t\t\t\t\t\t\t\t// little\n\t\t\t\t\t\t\t\t\tc -= 2;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\ts.win.set(s.win.subarray(r, r + 2), q);\n\t\t\t\t\t\t\t\t\tq += 2;\n\t\t\t\t\t\t\t\t\tr += 2;\n\t\t\t\t\t\t\t\t\tc -= 2;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else { // else offset after destination\n\t\t\t\t\t\t\t\tr = q - d;\n\t\t\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\t\t\tr += s.end; // force pointer in win\n\t\t\t\t\t\t\t\t} while (r < 0); // covers invalid distances\n\t\t\t\t\t\t\t\te = s.end - r;\n\t\t\t\t\t\t\t\tif (c > e) { // if source crosses,\n\t\t\t\t\t\t\t\t\tc -= e; // wrapped copy\n\t\t\t\t\t\t\t\t\tif (q - r > 0 && e > (q - r)) {\n\t\t\t\t\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\t\t\t\t\ts.win[q++] = s.win[r++];\n\t\t\t\t\t\t\t\t\t\t} while (--e !== 0);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\ts.win.set(s.win.subarray(r, r + e), q);\n\t\t\t\t\t\t\t\t\t\tq += e;\n\t\t\t\t\t\t\t\t\t\tr += e;\n\t\t\t\t\t\t\t\t\t\te = 0;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tr = 0; // copy rest from start of win\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// copy all or what's left\n\t\t\t\t\t\t\tif (q - r > 0 && c > (q - r)) {\n\t\t\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\t\t\ts.win[q++] = s.win[r++];\n\t\t\t\t\t\t\t\t} while (--c !== 0);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\ts.win.set(s.win.subarray(r, r + c), q);\n\t\t\t\t\t\t\t\tq += c;\n\t\t\t\t\t\t\t\tr += c;\n\t\t\t\t\t\t\t\tc = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else if ((e & 64) === 0) {\n\t\t\t\t\t\t\tt += tp[tp_index_t_3 + 2];\n\t\t\t\t\t\t\tt += (b & inflate_mask[e]);\n\t\t\t\t\t\t\ttp_index_t_3 = (tp_index + t) * 3;\n\t\t\t\t\t\t\te = tp[tp_index_t_3];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tz.msg = \"invalid distance code\";\n\n\t\t\t\t\t\t\tc = z.avail_in - n;\n\t\t\t\t\t\t\tc = (k >> 3) < c ? k >> 3 : c;\n\t\t\t\t\t\t\tn += c;\n\t\t\t\t\t\t\tp -= c;\n\t\t\t\t\t\t\tk -= c << 3;\n\n\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\ts.write = q;\n\n\t\t\t\t\t\t\treturn Z_DATA_ERROR;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// eslint-disable-next-line no-constant-condition\n\t\t\t\t\t} while (true);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif ((e & 64) === 0) {\n\t\t\t\t\tt += tp[tp_index_t_3 + 2];\n\t\t\t\t\tt += (b & inflate_mask[e]);\n\t\t\t\t\ttp_index_t_3 = (tp_index + t) * 3;\n\t\t\t\t\tif ((e = tp[tp_index_t_3]) === 0) {\n\n\t\t\t\t\t\tb >>= (tp[tp_index_t_3 + 1]);\n\t\t\t\t\t\tk -= (tp[tp_index_t_3 + 1]);\n\n\t\t\t\t\t\ts.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];\n\t\t\t\t\t\tm--;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else if ((e & 32) !== 0) {\n\n\t\t\t\t\tc = z.avail_in - n;\n\t\t\t\t\tc = (k >> 3) < c ? k >> 3 : c;\n\t\t\t\t\tn += c;\n\t\t\t\t\tp -= c;\n\t\t\t\t\tk -= c << 3;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\n\t\t\t\t\treturn Z_STREAM_END;\n\t\t\t\t} else {\n\t\t\t\t\tz.msg = \"invalid literal/length code\";\n\n\t\t\t\t\tc = z.avail_in - n;\n\t\t\t\t\tc = (k >> 3) < c ? k >> 3 : c;\n\t\t\t\t\tn += c;\n\t\t\t\t\tp -= c;\n\t\t\t\t\tk -= c << 3;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\n\t\t\t\t\treturn Z_DATA_ERROR;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line no-constant-condition\n\t\t\t} while (true);\n\t\t} while (m >= 258 && n >= 10);\n\n\t\t// not enough input or output--restore pointers and return\n\t\tc = z.avail_in - n;\n\t\tc = (k >> 3) < c ? k >> 3 : c;\n\t\tn += c;\n\t\tp -= c;\n\t\tk -= c << 3;\n\n\t\ts.bitb = b;\n\t\ts.bitk = k;\n\t\tz.avail_in = n;\n\t\tz.total_in += p - z.next_in_index;\n\t\tz.next_in_index = p;\n\t\ts.write = q;\n\n\t\treturn Z_OK;\n\t}\n\n\tthat.init = function (bl, bd, tl, tl_index, td, td_index) {\n\t\tmode = START;\n\t\tlbits = /* (byte) */bl;\n\t\tdbits = /* (byte) */bd;\n\t\tltree = tl;\n\t\tltree_index = tl_index;\n\t\tdtree = td;\n\t\tdtree_index = td_index;\n\t\ttree = null;\n\t};\n\n\tthat.proc = function (s, z, r) {\n\t\tlet j; // temporary storage\n\t\tlet tindex; // temporary pointer\n\t\tlet e; // extra bits or operation\n\t\tlet b = 0; // bit buffer\n\t\tlet k = 0; // bits in bit buffer\n\t\tlet p = 0; // input data pointer\n\t\tlet n; // bytes available there\n\t\tlet q; // output win write pointer\n\t\tlet m; // bytes to end of win or read pointer\n\t\tlet f; // pointer to copy strings from\n\n\t\t// copy input/output information to locals (UPDATE macro restores)\n\t\tp = z.next_in_index;\n\t\tn = z.avail_in;\n\t\tb = s.bitb;\n\t\tk = s.bitk;\n\t\tq = s.write;\n\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t// process input and output based on current state\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tswitch (mode) {\n\t\t\t\t// waiting for \"i:\"=input, \"o:\"=output, \"x:\"=nothing\n\t\t\t\tcase START: // x: set up for LEN\n\t\t\t\t\tif (m >= 258 && n >= 10) {\n\n\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\tr = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);\n\n\t\t\t\t\t\tp = z.next_in_index;\n\t\t\t\t\t\tn = z.avail_in;\n\t\t\t\t\t\tb = s.bitb;\n\t\t\t\t\t\tk = s.bitk;\n\t\t\t\t\t\tq = s.write;\n\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t\t\t\t\tif (r != Z_OK) {\n\t\t\t\t\t\t\tmode = r == Z_STREAM_END ? WASH : BADCODE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tneed = lbits;\n\t\t\t\t\ttree = ltree;\n\t\t\t\t\ttree_index = ltree_index;\n\n\t\t\t\t\tmode = LEN;\n\t\t\t\t/* falls through */\n\t\t\t\tcase LEN: // i: get length/literal/eob next\n\t\t\t\t\tj = need;\n\n\t\t\t\t\twhile (k < (j)) {\n\t\t\t\t\t\tif (n !== 0)\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\telse {\n\n\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\ttindex = (tree_index + (b & inflate_mask[j])) * 3;\n\n\t\t\t\t\tb >>>= (tree[tindex + 1]);\n\t\t\t\t\tk -= (tree[tindex + 1]);\n\n\t\t\t\t\te = tree[tindex];\n\n\t\t\t\t\tif (e === 0) { // literal\n\t\t\t\t\t\tlit = tree[tindex + 2];\n\t\t\t\t\t\tmode = LIT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((e & 16) !== 0) { // length\n\t\t\t\t\t\tget = e & 15;\n\t\t\t\t\t\tlen = tree[tindex + 2];\n\t\t\t\t\t\tmode = LENEXT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((e & 64) === 0) { // next table\n\t\t\t\t\t\tneed = e;\n\t\t\t\t\t\ttree_index = tindex / 3 + tree[tindex + 2];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((e & 32) !== 0) { // end of block\n\t\t\t\t\t\tmode = WASH;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tmode = BADCODE; // invalid code\n\t\t\t\t\tz.msg = \"invalid literal/length code\";\n\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\t\t\t\t\treturn s.inflate_flush(z, r);\n\n\t\t\t\tcase LENEXT: // i: getting length extra (have base)\n\t\t\t\t\tj = get;\n\n\t\t\t\t\twhile (k < (j)) {\n\t\t\t\t\t\tif (n !== 0)\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\telse {\n\n\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\tlen += (b & inflate_mask[j]);\n\n\t\t\t\t\tb >>= j;\n\t\t\t\t\tk -= j;\n\n\t\t\t\t\tneed = dbits;\n\t\t\t\t\ttree = dtree;\n\t\t\t\t\ttree_index = dtree_index;\n\t\t\t\t\tmode = DIST;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DIST: // i: get distance next\n\t\t\t\t\tj = need;\n\n\t\t\t\t\twhile (k < (j)) {\n\t\t\t\t\t\tif (n !== 0)\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\telse {\n\n\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\ttindex = (tree_index + (b & inflate_mask[j])) * 3;\n\n\t\t\t\t\tb >>= tree[tindex + 1];\n\t\t\t\t\tk -= tree[tindex + 1];\n\n\t\t\t\t\te = (tree[tindex]);\n\t\t\t\t\tif ((e & 16) !== 0) { // distance\n\t\t\t\t\t\tget = e & 15;\n\t\t\t\t\t\tdist = tree[tindex + 2];\n\t\t\t\t\t\tmode = DISTEXT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((e & 64) === 0) { // next table\n\t\t\t\t\t\tneed = e;\n\t\t\t\t\t\ttree_index = tindex / 3 + tree[tindex + 2];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tmode = BADCODE; // invalid code\n\t\t\t\t\tz.msg = \"invalid distance code\";\n\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\t\t\t\t\treturn s.inflate_flush(z, r);\n\n\t\t\t\tcase DISTEXT: // i: getting distance extra\n\t\t\t\t\tj = get;\n\n\t\t\t\t\twhile (k < (j)) {\n\t\t\t\t\t\tif (n !== 0)\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\telse {\n\n\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\tdist += (b & inflate_mask[j]);\n\n\t\t\t\t\tb >>= j;\n\t\t\t\t\tk -= j;\n\n\t\t\t\t\tmode = COPY;\n\t\t\t\t/* falls through */\n\t\t\t\tcase COPY: // o: copying bytes in win, waiting for space\n\t\t\t\t\tf = q - dist;\n\t\t\t\t\twhile (f < 0) { // modulo win size-\"while\" instead\n\t\t\t\t\t\tf += s.end; // of \"if\" handles invalid distances\n\t\t\t\t\t}\n\t\t\t\t\twhile (len !== 0) {\n\n\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\tif (q == s.end && s.read !== 0) {\n\t\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\t\tr = s.inflate_flush(z, r);\n\t\t\t\t\t\t\t\tq = s.write;\n\t\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t\t\t\t\t\t\tif (q == s.end && s.read !== 0) {\n\t\t\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ts.win[q++] = s.win[f++];\n\t\t\t\t\t\tm--;\n\n\t\t\t\t\t\tif (f == s.end)\n\t\t\t\t\t\t\tf = 0;\n\t\t\t\t\t\tlen--;\n\t\t\t\t\t}\n\t\t\t\t\tmode = START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LIT: // o: got literal, waiting for output space\n\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\tif (q == s.end && s.read !== 0) {\n\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\tr = s.inflate_flush(z, r);\n\t\t\t\t\t\t\tq = s.write;\n\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t\t\t\t\t\tif (q == s.end && s.read !== 0) {\n\t\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tr = Z_OK;\n\n\t\t\t\t\ts.win[q++] = /* (byte) */lit;\n\t\t\t\t\tm--;\n\n\t\t\t\t\tmode = START;\n\t\t\t\t\tbreak;\n\t\t\t\tcase WASH: // o: got eob, possibly more output\n\t\t\t\t\tif (k > 7) { // return unused byte, if any\n\t\t\t\t\t\tk -= 8;\n\t\t\t\t\t\tn++;\n\t\t\t\t\t\tp--; // can always return one\n\t\t\t\t\t}\n\n\t\t\t\t\ts.write = q;\n\t\t\t\t\tr = s.inflate_flush(z, r);\n\t\t\t\t\tq = s.write;\n\t\t\t\t\tm = q < s.read ? s.read - q - 1 : s.end - q;\n\n\t\t\t\t\tif (s.read != s.write) {\n\t\t\t\t\t\ts.bitb = b;\n\t\t\t\t\t\ts.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\ts.write = q;\n\t\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tmode = END;\n\t\t\t\t/* falls through */\n\t\t\t\tcase END:\n\t\t\t\t\tr = Z_STREAM_END;\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\t\t\t\t\treturn s.inflate_flush(z, r);\n\n\t\t\t\tcase BADCODE: // x: got error\n\n\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\t\t\t\t\treturn s.inflate_flush(z, r);\n\n\t\t\t\tdefault:\n\t\t\t\t\tr = Z_STREAM_ERROR;\n\n\t\t\t\t\ts.bitb = b;\n\t\t\t\t\ts.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\ts.write = q;\n\t\t\t\t\treturn s.inflate_flush(z, r);\n\t\t\t}\n\t\t}\n\t};\n\n\tthat.free = function () {\n\t\t// ZFREE(z, c);\n\t};\n\n}\n\n// InfBlocks\n\n// Table for deflate from PKZIP's appnote.txt.\nconst border = [ // Order of the bit length code lengths\n\t16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];\n\nconst TYPE = 0; // get type bits (3, including end bit)\nconst LENS = 1; // get lengths for stored\nconst STORED = 2;// processing stored block\nconst TABLE = 3; // get table lengths\nconst BTREE = 4; // get bit lengths tree for a dynamic\n// block\nconst DTREE = 5; // get length, distance trees for a\n// dynamic block\nconst CODES = 6; // processing fixed or dynamic block\nconst DRY = 7; // output remaining win bytes\nconst DONELOCKS = 8; // finished last block, done\nconst BADBLOCKS = 9; // ot a data error--stuck here\n\nfunction InfBlocks(z, w) {\n\tconst that = this;\n\n\tlet mode = TYPE; // current inflate_block mode\n\n\tlet left = 0; // if STORED, bytes left to copy\n\n\tlet table = 0; // table lengths (14 bits)\n\tlet index = 0; // index into blens (or border)\n\tlet blens; // bit lengths of codes\n\tconst bb = [0]; // bit length tree depth\n\tconst tb = [0]; // bit length decoding tree\n\n\tconst codes = new InfCodes(); // if CODES, current state\n\n\tlet last = 0; // true if this block is the last block\n\n\tlet hufts = new Int32Array(MANY * 3); // single malloc for tree space\n\tconst check = 0; // check on output\n\tconst inftree = new InfTree();\n\n\tthat.bitk = 0; // bits in bit buffer\n\tthat.bitb = 0; // bit buffer\n\tthat.win = new Uint8Array(w); // sliding win\n\tthat.end = w; // one byte after sliding win\n\tthat.read = 0; // win read pointer\n\tthat.write = 0; // win write pointer\n\n\tthat.reset = function (z, c) {\n\t\tif (c)\n\t\t\tc[0] = check;\n\t\t// if (mode == BTREE || mode == DTREE) {\n\t\t// }\n\t\tif (mode == CODES) {\n\t\t\tcodes.free(z);\n\t\t}\n\t\tmode = TYPE;\n\t\tthat.bitk = 0;\n\t\tthat.bitb = 0;\n\t\tthat.read = that.write = 0;\n\t};\n\n\tthat.reset(z, null);\n\n\t// copy as much as possible from the sliding win to the output area\n\tthat.inflate_flush = function (z, r) {\n\t\tlet n;\n\t\tlet p;\n\t\tlet q;\n\n\t\t// local copies of source and destination pointers\n\t\tp = z.next_out_index;\n\t\tq = that.read;\n\n\t\t// compute number of bytes to copy as far as end of win\n\t\tn = /* (int) */((q <= that.write ? that.write : that.end) - q);\n\t\tif (n > z.avail_out)\n\t\t\tn = z.avail_out;\n\t\tif (n !== 0 && r == Z_BUF_ERROR)\n\t\t\tr = Z_OK;\n\n\t\t// update counters\n\t\tz.avail_out -= n;\n\t\tz.total_out += n;\n\n\t\t// copy as far as end of win\n\t\tz.next_out.set(that.win.subarray(q, q + n), p);\n\t\tp += n;\n\t\tq += n;\n\n\t\t// see if more to copy at beginning of win\n\t\tif (q == that.end) {\n\t\t\t// wrap pointers\n\t\t\tq = 0;\n\t\t\tif (that.write == that.end)\n\t\t\t\tthat.write = 0;\n\n\t\t\t// compute bytes to copy\n\t\t\tn = that.write - q;\n\t\t\tif (n > z.avail_out)\n\t\t\t\tn = z.avail_out;\n\t\t\tif (n !== 0 && r == Z_BUF_ERROR)\n\t\t\t\tr = Z_OK;\n\n\t\t\t// update counters\n\t\t\tz.avail_out -= n;\n\t\t\tz.total_out += n;\n\n\t\t\t// copy\n\t\t\tz.next_out.set(that.win.subarray(q, q + n), p);\n\t\t\tp += n;\n\t\t\tq += n;\n\t\t}\n\n\t\t// update pointers\n\t\tz.next_out_index = p;\n\t\tthat.read = q;\n\n\t\t// done\n\t\treturn r;\n\t};\n\n\tthat.proc = function (z, r) {\n\t\tlet t; // temporary storage\n\t\tlet b; // bit buffer\n\t\tlet k; // bits in bit buffer\n\t\tlet p; // input data pointer\n\t\tlet n; // bytes available there\n\t\tlet q; // output win write pointer\n\t\tlet m; // bytes to end of win or read pointer\n\n\t\tlet i;\n\n\t\t// copy input/output information to locals (UPDATE macro restores)\n\t\t// {\n\t\tp = z.next_in_index;\n\t\tn = z.avail_in;\n\t\tb = that.bitb;\n\t\tk = that.bitk;\n\t\t// }\n\t\t// {\n\t\tq = that.write;\n\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\t\t// }\n\n\t\t// process input based on current state\n\t\t// DEBUG dtree\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tlet bl, bd, tl, td, bl_, bd_, tl_, td_;\n\t\t\tswitch (mode) {\n\t\t\t\tcase TYPE:\n\n\t\t\t\t\twhile (k < (3)) {\n\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\t\t\t\t\tt = /* (int) */(b & 7);\n\t\t\t\t\tlast = t & 1;\n\n\t\t\t\t\tswitch (t >>> 1) {\n\t\t\t\t\t\tcase 0: // stored\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tb >>>= (3);\n\t\t\t\t\t\t\tk -= (3);\n\t\t\t\t\t\t\t// }\n\t\t\t\t\t\t\tt = k & 7; // go to byte boundary\n\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tb >>>= (t);\n\t\t\t\t\t\t\tk -= (t);\n\t\t\t\t\t\t\t// }\n\t\t\t\t\t\t\tmode = LENS; // get length of stored block\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1: // fixed\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tbl = []; // new Array(1);\n\t\t\t\t\t\t\tbd = []; // new Array(1);\n\t\t\t\t\t\t\ttl = [[]]; // new Array(1);\n\t\t\t\t\t\t\ttd = [[]]; // new Array(1);\n\n\t\t\t\t\t\t\tInfTree.inflate_trees_fixed(bl, bd, tl, td);\n\t\t\t\t\t\t\tcodes.init(bl[0], bd[0], tl[0], 0, td[0], 0);\n\t\t\t\t\t\t\t// }\n\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tb >>>= (3);\n\t\t\t\t\t\t\tk -= (3);\n\t\t\t\t\t\t\t// }\n\n\t\t\t\t\t\t\tmode = CODES;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2: // dynamic\n\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tb >>>= (3);\n\t\t\t\t\t\t\tk -= (3);\n\t\t\t\t\t\t\t// }\n\n\t\t\t\t\t\t\tmode = TABLE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3: // illegal\n\n\t\t\t\t\t\t\t// {\n\t\t\t\t\t\t\tb >>>= (3);\n\t\t\t\t\t\t\tk -= (3);\n\t\t\t\t\t\t\t// }\n\t\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\t\tz.msg = \"invalid block type\";\n\t\t\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase LENS:\n\n\t\t\t\t\twhile (k < (32)) {\n\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {\n\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\tz.msg = \"invalid stored block lengths\";\n\t\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tleft = (b & 0xffff);\n\t\t\t\t\tb = k = 0; // dump bits\n\t\t\t\t\tmode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE);\n\t\t\t\t\tbreak;\n\t\t\t\tcase STORED:\n\t\t\t\t\tif (n === 0) {\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\tif (q == that.end && that.read !== 0) {\n\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\tr = that.inflate_flush(z, r);\n\t\t\t\t\t\t\tq = that.write;\n\t\t\t\t\t\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\t\t\t\t\t\t\tif (q == that.end && that.read !== 0) {\n\t\t\t\t\t\t\t\tq = 0;\n\t\t\t\t\t\t\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (m === 0) {\n\t\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tr = Z_OK;\n\n\t\t\t\t\tt = left;\n\t\t\t\t\tif (t > n)\n\t\t\t\t\t\tt = n;\n\t\t\t\t\tif (t > m)\n\t\t\t\t\t\tt = m;\n\t\t\t\t\tthat.win.set(z.read_buf(p, t), q);\n\t\t\t\t\tp += t;\n\t\t\t\t\tn -= t;\n\t\t\t\t\tq += t;\n\t\t\t\t\tm -= t;\n\t\t\t\t\tif ((left -= t) !== 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tmode = last !== 0 ? DRY : TYPE;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TABLE:\n\n\t\t\t\t\twhile (k < (14)) {\n\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tn--;\n\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\tk += 8;\n\t\t\t\t\t}\n\n\t\t\t\t\ttable = t = (b & 0x3fff);\n\t\t\t\t\tif ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {\n\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\tz.msg = \"too many length or distance symbols\";\n\t\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tt = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);\n\t\t\t\t\tif (!blens || blens.length < t) {\n\t\t\t\t\t\tblens = []; // new Array(t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (i = 0; i < t; i++) {\n\t\t\t\t\t\t\tblens[i] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// {\n\t\t\t\t\tb >>>= (14);\n\t\t\t\t\tk -= (14);\n\t\t\t\t\t// }\n\n\t\t\t\t\tindex = 0;\n\t\t\t\t\tmode = BTREE;\n\t\t\t\t/* falls through */\n\t\t\t\tcase BTREE:\n\t\t\t\t\twhile (index < 4 + (table >>> 10)) {\n\t\t\t\t\t\twhile (k < (3)) {\n\t\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tn--;\n\t\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\t\tk += 8;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tblens[border[index++]] = b & 7;\n\n\t\t\t\t\t\t// {\n\t\t\t\t\t\tb >>>= (3);\n\t\t\t\t\t\tk -= (3);\n\t\t\t\t\t\t// }\n\t\t\t\t\t}\n\n\t\t\t\t\twhile (index < 19) {\n\t\t\t\t\t\tblens[border[index++]] = 0;\n\t\t\t\t\t}\n\n\t\t\t\t\tbb[0] = 7;\n\t\t\t\t\tt = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);\n\t\t\t\t\tif (t != Z_OK) {\n\t\t\t\t\t\tr = t;\n\t\t\t\t\t\tif (r == Z_DATA_ERROR) {\n\t\t\t\t\t\t\tblens = null;\n\t\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\n\t\t\t\t\tindex = 0;\n\t\t\t\t\tmode = DTREE;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DTREE:\n\t\t\t\t\t// eslint-disable-next-line no-constant-condition\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\tt = table;\n\t\t\t\t\t\tif (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet j, c;\n\n\t\t\t\t\t\tt = bb[0];\n\n\t\t\t\t\t\twhile (k < (t)) {\n\t\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tn--;\n\t\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\t\tk += 8;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// if (tb[0] == -1) {\n\t\t\t\t\t\t// System.err.println(\"null...\");\n\t\t\t\t\t\t// }\n\n\t\t\t\t\t\tt = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];\n\t\t\t\t\t\tc = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];\n\n\t\t\t\t\t\tif (c < 16) {\n\t\t\t\t\t\t\tb >>>= (t);\n\t\t\t\t\t\t\tk -= (t);\n\t\t\t\t\t\t\tblens[index++] = c;\n\t\t\t\t\t\t} else { // c == 16..18\n\t\t\t\t\t\t\ti = c == 18 ? 7 : c - 14;\n\t\t\t\t\t\t\tj = c == 18 ? 11 : 3;\n\n\t\t\t\t\t\t\twhile (k < (t + i)) {\n\t\t\t\t\t\t\t\tif (n !== 0) {\n\t\t\t\t\t\t\t\t\tr = Z_OK;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tn--;\n\t\t\t\t\t\t\t\tb |= (z.read_byte(p++) & 0xff) << k;\n\t\t\t\t\t\t\t\tk += 8;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tb >>>= (t);\n\t\t\t\t\t\t\tk -= (t);\n\n\t\t\t\t\t\t\tj += (b & inflate_mask[i]);\n\n\t\t\t\t\t\t\tb >>>= (i);\n\t\t\t\t\t\t\tk -= (i);\n\n\t\t\t\t\t\t\ti = index;\n\t\t\t\t\t\t\tt = table;\n\t\t\t\t\t\t\tif (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {\n\t\t\t\t\t\t\t\tblens = null;\n\t\t\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\t\t\tz.msg = \"invalid bit length repeat\";\n\t\t\t\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tc = c == 16 ? blens[i - 1] : 0;\n\t\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\t\tblens[i++] = c;\n\t\t\t\t\t\t\t} while (--j !== 0);\n\t\t\t\t\t\t\tindex = i;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttb[0] = -1;\n\t\t\t\t\t// {\n\t\t\t\t\tbl_ = []; // new Array(1);\n\t\t\t\t\tbd_ = []; // new Array(1);\n\t\t\t\t\ttl_ = []; // new Array(1);\n\t\t\t\t\ttd_ = []; // new Array(1);\n\t\t\t\t\tbl_[0] = 9; // must be <= 9 for lookahead assumptions\n\t\t\t\t\tbd_[0] = 6; // must be <= 9 for lookahead assumptions\n\n\t\t\t\t\tt = table;\n\t\t\t\t\tt = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z);\n\n\t\t\t\t\tif (t != Z_OK) {\n\t\t\t\t\t\tif (t == Z_DATA_ERROR) {\n\t\t\t\t\t\t\tblens = null;\n\t\t\t\t\t\t\tmode = BADBLOCKS;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tr = t;\n\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tcodes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]);\n\t\t\t\t\t// }\n\t\t\t\t\tmode = CODES;\n\t\t\t\t/* falls through */\n\t\t\t\tcase CODES:\n\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\tthat.write = q;\n\n\t\t\t\t\tif ((r = codes.proc(that, z, r)) != Z_STREAM_END) {\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tr = Z_OK;\n\t\t\t\t\tcodes.free(z);\n\n\t\t\t\t\tp = z.next_in_index;\n\t\t\t\t\tn = z.avail_in;\n\t\t\t\t\tb = that.bitb;\n\t\t\t\t\tk = that.bitk;\n\t\t\t\t\tq = that.write;\n\t\t\t\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\n\t\t\t\t\tif (last === 0) {\n\t\t\t\t\t\tmode = TYPE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tmode = DRY;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DRY:\n\t\t\t\t\tthat.write = q;\n\t\t\t\t\tr = that.inflate_flush(z, r);\n\t\t\t\t\tq = that.write;\n\t\t\t\t\tm = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);\n\t\t\t\t\tif (that.read != that.write) {\n\t\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\t\tthat.write = q;\n\t\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\t\t}\n\t\t\t\t\tmode = DONELOCKS;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DONELOCKS:\n\t\t\t\t\tr = Z_STREAM_END;\n\n\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\tthat.write = q;\n\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t\tcase BADBLOCKS:\n\t\t\t\t\tr = Z_DATA_ERROR;\n\n\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\tthat.write = q;\n\t\t\t\t\treturn that.inflate_flush(z, r);\n\n\t\t\t\tdefault:\n\t\t\t\t\tr = Z_STREAM_ERROR;\n\n\t\t\t\t\tthat.bitb = b;\n\t\t\t\t\tthat.bitk = k;\n\t\t\t\t\tz.avail_in = n;\n\t\t\t\t\tz.total_in += p - z.next_in_index;\n\t\t\t\t\tz.next_in_index = p;\n\t\t\t\t\tthat.write = q;\n\t\t\t\t\treturn that.inflate_flush(z, r);\n\t\t\t}\n\t\t}\n\t};\n\n\tthat.free = function (z) {\n\t\tthat.reset(z, null);\n\t\tthat.win = null;\n\t\thufts = null;\n\t\t// ZFREE(z, s);\n\t};\n\n\tthat.set_dictionary = function (d, start, n) {\n\t\tthat.win.set(d.subarray(start, start + n), 0);\n\t\tthat.read = that.write = n;\n\t};\n\n\t// Returns true if inflate is currently at the end of a block generated\n\t// by Z_SYNC_FLUSH or Z_FULL_FLUSH.\n\tthat.sync_point = function () {\n\t\treturn mode == LENS ? 1 : 0;\n\t};\n\n}\n\n// Inflate\n\n// preset dictionary flag in zlib header\nconst PRESET_DICT = 0x20;\n\nconst Z_DEFLATED = 8;\n\nconst METHOD = 0; // waiting for method byte\nconst FLAG = 1; // waiting for flag byte\nconst DICT4 = 2; // four dictionary check bytes to go\nconst DICT3 = 3; // three dictionary check bytes to go\nconst DICT2 = 4; // two dictionary check bytes to go\nconst DICT1 = 5; // one dictionary check byte to go\nconst DICT0 = 6; // waiting for inflateSetDictionary\nconst BLOCKS = 7; // decompressing blocks\nconst DONE = 12; // finished check, done\nconst BAD = 13; // got an error--stay here\n\nconst mark = [0, 0, 0xff, 0xff];\n\nfunction Inflate() {\n\tconst that = this;\n\n\tthat.mode = 0; // current inflate mode\n\n\t// mode dependent information\n\tthat.method = 0; // if FLAGS, method byte\n\n\t// if CHECK, check values to compare\n\tthat.was = [0]; // new Array(1); // computed check value\n\tthat.need = 0; // stream check value\n\n\t// if BAD, inflateSync's marker bytes count\n\tthat.marker = 0;\n\n\t// mode independent information\n\tthat.wbits = 0; // log2(win size) (8..15, defaults to 15)\n\n\t// this.blocks; // current inflate_blocks state\n\n\tfunction inflateReset(z) {\n\t\tif (!z || !z.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\n\t\tz.total_in = z.total_out = 0;\n\t\tz.msg = null;\n\t\tz.istate.mode = BLOCKS;\n\t\tz.istate.blocks.reset(z, null);\n\t\treturn Z_OK;\n\t}\n\n\tthat.inflateEnd = function (z) {\n\t\tif (that.blocks)\n\t\t\tthat.blocks.free(z);\n\t\tthat.blocks = null;\n\t\t// ZFREE(z, z->state);\n\t\treturn Z_OK;\n\t};\n\n\tthat.inflateInit = function (z, w) {\n\t\tz.msg = null;\n\t\tthat.blocks = null;\n\n\t\t// set win size\n\t\tif (w < 8 || w > 15) {\n\t\t\tthat.inflateEnd(z);\n\t\t\treturn Z_STREAM_ERROR;\n\t\t}\n\t\tthat.wbits = w;\n\n\t\tz.istate.blocks = new InfBlocks(z, 1 << w);\n\n\t\t// reset state\n\t\tinflateReset(z);\n\t\treturn Z_OK;\n\t};\n\n\tthat.inflate = function (z, f) {\n\t\tlet r;\n\t\tlet b;\n\n\t\tif (!z || !z.istate || !z.next_in)\n\t\t\treturn Z_STREAM_ERROR;\n\t\tconst istate = z.istate;\n\t\tf = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;\n\t\tr = Z_BUF_ERROR;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tswitch (istate.mode) {\n\t\t\t\tcase METHOD:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tif (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) {\n\t\t\t\t\t\tistate.mode = BAD;\n\t\t\t\t\t\tz.msg = \"unknown compression method\";\n\t\t\t\t\t\tistate.marker = 5; // can't try inflateSync\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((istate.method >> 4) + 8 > istate.wbits) {\n\t\t\t\t\t\tistate.mode = BAD;\n\t\t\t\t\t\tz.msg = \"invalid win size\";\n\t\t\t\t\t\tistate.marker = 5; // can't try inflateSync\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tistate.mode = FLAG;\n\t\t\t\t/* falls through */\n\t\t\t\tcase FLAG:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tb = (z.read_byte(z.next_in_index++)) & 0xff;\n\n\t\t\t\t\tif ((((istate.method << 8) + b) % 31) !== 0) {\n\t\t\t\t\t\tistate.mode = BAD;\n\t\t\t\t\t\tz.msg = \"incorrect header check\";\n\t\t\t\t\t\tistate.marker = 5; // can't try inflateSync\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ((b & PRESET_DICT) === 0) {\n\t\t\t\t\t\tistate.mode = BLOCKS;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tistate.mode = DICT4;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DICT4:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tistate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000;\n\t\t\t\t\tistate.mode = DICT3;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DICT3:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tistate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000;\n\t\t\t\t\tistate.mode = DICT2;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DICT2:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tistate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00;\n\t\t\t\t\tistate.mode = DICT1;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DICT1:\n\n\t\t\t\t\tif (z.avail_in === 0)\n\t\t\t\t\t\treturn r;\n\t\t\t\t\tr = f;\n\n\t\t\t\t\tz.avail_in--;\n\t\t\t\t\tz.total_in++;\n\t\t\t\t\tistate.need += (z.read_byte(z.next_in_index++) & 0xff);\n\t\t\t\t\tistate.mode = DICT0;\n\t\t\t\t\treturn Z_NEED_DICT;\n\t\t\t\tcase DICT0:\n\t\t\t\t\tistate.mode = BAD;\n\t\t\t\t\tz.msg = \"need dictionary\";\n\t\t\t\t\tistate.marker = 0; // can try inflateSync\n\t\t\t\t\treturn Z_STREAM_ERROR;\n\t\t\t\tcase BLOCKS:\n\n\t\t\t\t\tr = istate.blocks.proc(z, r);\n\t\t\t\t\tif (r == Z_DATA_ERROR) {\n\t\t\t\t\t\tistate.mode = BAD;\n\t\t\t\t\t\tistate.marker = 0; // can try inflateSync\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (r == Z_OK) {\n\t\t\t\t\t\tr = f;\n\t\t\t\t\t}\n\t\t\t\t\tif (r != Z_STREAM_END) {\n\t\t\t\t\t\treturn r;\n\t\t\t\t\t}\n\t\t\t\t\tr = f;\n\t\t\t\t\tistate.blocks.reset(z, istate.was);\n\t\t\t\t\tistate.mode = DONE;\n\t\t\t\t/* falls through */\n\t\t\t\tcase DONE:\n\t\t\t\t\tz.avail_in = 0;\n\t\t\t\t\treturn Z_STREAM_END;\n\t\t\t\tcase BAD:\n\t\t\t\t\treturn Z_DATA_ERROR;\n\t\t\t\tdefault:\n\t\t\t\t\treturn Z_STREAM_ERROR;\n\t\t\t}\n\t\t}\n\t};\n\n\tthat.inflateSetDictionary = function (z, dictionary, dictLength) {\n\t\tlet index = 0, length = dictLength;\n\t\tif (!z || !z.istate || z.istate.mode != DICT0)\n\t\t\treturn Z_STREAM_ERROR;\n\t\tconst istate = z.istate;\n\t\tif (length >= (1 << istate.wbits)) {\n\t\t\tlength = (1 << istate.wbits) - 1;\n\t\t\tindex = dictLength - length;\n\t\t}\n\t\tistate.blocks.set_dictionary(dictionary, index, length);\n\t\tistate.mode = BLOCKS;\n\t\treturn Z_OK;\n\t};\n\n\tthat.inflateSync = function (z) {\n\t\tlet n; // number of bytes to look at\n\t\tlet p; // pointer to bytes\n\t\tlet m; // number of marker bytes found in a row\n\t\tlet r, w; // temporaries to save total_in and total_out\n\n\t\t// set up\n\t\tif (!z || !z.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\tconst istate = z.istate;\n\t\tif (istate.mode != BAD) {\n\t\t\tistate.mode = BAD;\n\t\t\tistate.marker = 0;\n\t\t}\n\t\tif ((n = z.avail_in) === 0)\n\t\t\treturn Z_BUF_ERROR;\n\t\tp = z.next_in_index;\n\t\tm = istate.marker;\n\n\t\t// search\n\t\twhile (n !== 0 && m < 4) {\n\t\t\tif (z.read_byte(p) == mark[m]) {\n\t\t\t\tm++;\n\t\t\t} else if (z.read_byte(p) !== 0) {\n\t\t\t\tm = 0;\n\t\t\t} else {\n\t\t\t\tm = 4 - m;\n\t\t\t}\n\t\t\tp++;\n\t\t\tn--;\n\t\t}\n\n\t\t// restore\n\t\tz.total_in += p - z.next_in_index;\n\t\tz.next_in_index = p;\n\t\tz.avail_in = n;\n\t\tistate.marker = m;\n\n\t\t// return no joy or set up to restart on a new block\n\t\tif (m != 4) {\n\t\t\treturn Z_DATA_ERROR;\n\t\t}\n\t\tr = z.total_in;\n\t\tw = z.total_out;\n\t\tinflateReset(z);\n\t\tz.total_in = r;\n\t\tz.total_out = w;\n\t\tistate.mode = BLOCKS;\n\t\treturn Z_OK;\n\t};\n\n\t// Returns true if inflate is currently at the end of a block generated\n\t// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP\n\t// implementation to provide an additional safety check. PPP uses\n\t// Z_SYNC_FLUSH\n\t// but removes the length bytes of the resulting empty stored block. When\n\t// decompressing, PPP checks that at the end of input packet, inflate is\n\t// waiting for these length bytes.\n\tthat.inflateSyncPoint = function (z) {\n\t\tif (!z || !z.istate || !z.istate.blocks)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn z.istate.blocks.sync_point();\n\t};\n}\n\n// ZStream\n\nfunction ZStream() {\n}\n\nZStream.prototype = {\n\tinflateInit: function (bits) {\n\t\tconst that = this;\n\t\tthat.istate = new Inflate();\n\t\tif (!bits)\n\t\t\tbits = MAX_BITS;\n\t\treturn that.istate.inflateInit(that, bits);\n\t},\n\n\tinflate: function (f) {\n\t\tconst that = this;\n\t\tif (!that.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn that.istate.inflate(that, f);\n\t},\n\n\tinflateEnd: function () {\n\t\tconst that = this;\n\t\tif (!that.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\tconst ret = that.istate.inflateEnd(that);\n\t\tthat.istate = null;\n\t\treturn ret;\n\t},\n\n\tinflateSync: function () {\n\t\tconst that = this;\n\t\tif (!that.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn that.istate.inflateSync(that);\n\t},\n\tinflateSetDictionary: function (dictionary, dictLength) {\n\t\tconst that = this;\n\t\tif (!that.istate)\n\t\t\treturn Z_STREAM_ERROR;\n\t\treturn that.istate.inflateSetDictionary(that, dictionary, dictLength);\n\t},\n\tread_byte: function (start) {\n\t\tconst that = this;\n\t\treturn that.next_in[start];\n\t},\n\tread_buf: function (start, size) {\n\t\tconst that = this;\n\t\treturn that.next_in.subarray(start, start + size);\n\t}\n};\n\n// Inflater\n\nfunction ZipInflate(options) {\n\tconst that = this;\n\tconst z = new ZStream();\n\tconst bufsize = options && options.chunkSize ? Math.floor(options.chunkSize * 2) : 128 * 1024;\n\tconst flush = Z_NO_FLUSH;\n\tconst buf = new Uint8Array(bufsize);\n\tlet nomoreinput = false;\n\n\tz.inflateInit();\n\tz.next_out = buf;\n\n\tthat.append = function (data, onprogress) {\n\t\tconst buffers = [];\n\t\tlet err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;\n\t\tif (data.length === 0)\n\t\t\treturn;\n\t\tz.next_in_index = 0;\n\t\tz.next_in = data;\n\t\tz.avail_in = data.length;\n\t\tdo {\n\t\t\tz.next_out_index = 0;\n\t\t\tz.avail_out = bufsize;\n\t\t\tif ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it\n\t\t\t\tz.next_in_index = 0;\n\t\t\t\tnomoreinput = true;\n\t\t\t}\n\t\t\terr = z.inflate(flush);\n\t\t\tif (nomoreinput && (err === Z_BUF_ERROR)) {\n\t\t\t\tif (z.avail_in !== 0)\n\t\t\t\t\tthrow new Error(\"inflating: bad input\");\n\t\t\t} else if (err !== Z_OK && err !== Z_STREAM_END)\n\t\t\t\tthrow new Error(\"inflating: \" + z.msg);\n\t\t\tif ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length))\n\t\t\t\tthrow new Error(\"inflating: bad input\");\n\t\t\tif (z.next_out_index)\n\t\t\t\tif (z.next_out_index === bufsize)\n\t\t\t\t\tbuffers.push(new Uint8Array(buf));\n\t\t\t\telse\n\t\t\t\t\tbuffers.push(buf.slice(0, z.next_out_index));\n\t\t\tbufferSize += z.next_out_index;\n\t\t\tif (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {\n\t\t\t\tonprogress(z.next_in_index);\n\t\t\t\tlastIndex = z.next_in_index;\n\t\t\t}\n\t\t} while (z.avail_in > 0 || z.avail_out === 0);\n\t\tif (buffers.length > 1) {\n\t\t\tarray = new Uint8Array(bufferSize);\n\t\t\tbuffers.forEach(function (chunk) {\n\t\t\t\tarray.set(chunk, bufferIndex);\n\t\t\t\tbufferIndex += chunk.length;\n\t\t\t});\n\t\t} else {\n\t\t\tarray = buffers[0] || new Uint8Array(0);\n\t\t}\n\t\treturn array;\n\t};\n\tthat.flush = function () {\n\t\tz.inflateEnd();\n\t};\n}\n\nexport default ZipInflate;", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global navigator */\n\nconst DEFAULT_CONFIGURATION = {\n\tchunkSize: 512 * 1024,\n\tmaxWorkers: (typeof navigator != \"undefined\" && navigator.hardwareConcurrency) || 2,\n\tterminateWorkerTimeout: 5000,\n\tuseWebWorkers: true,\n\tworkerScripts: undefined\n};\n\nconst config = Object.assign({}, DEFAULT_CONFIGURATION);\n\nexport {\n\tconfigure,\n\tgetConfiguration\n};\n\nfunction getConfiguration() {\n\treturn config;\n}\n\nfunction configure(configuration) {\n\tif (configuration.baseURL !== undefined) {\n\t\tconfig.baseURL = configuration.baseURL;\n\t}\n\tif (configuration.chunkSize !== undefined) {\n\t\tconfig.chunkSize = configuration.chunkSize;\n\t}\n\tif (configuration.maxWorkers !== undefined) {\n\t\tconfig.maxWorkers = configuration.maxWorkers;\n\t}\n\tif (configuration.terminateWorkerTimeout !== undefined) {\n\t\tconfig.terminateWorkerTimeout = configuration.terminateWorkerTimeout;\n\t}\n\tif (configuration.useWebWorkers !== undefined) {\n\t\tconfig.useWebWorkers = configuration.useWebWorkers;\n\t}\n\tif (configuration.Deflate !== undefined) {\n\t\tconfig.Deflate = configuration.Deflate;\n\t}\n\tif (configuration.Inflate !== undefined) {\n\t\tconfig.Inflate = configuration.Inflate;\n\t}\n\tif (configuration.workerScripts !== undefined) {\n\t\tif (configuration.workerScripts.deflate) {\n\t\t\tif (!Array.isArray(configuration.workerScripts.deflate)) {\n\t\t\t\tthrow new Error(\"workerScripts.deflate must be an array\");\n\t\t\t}\n\t\t\tif (!config.workerScripts) {\n\t\t\t\tconfig.workerScripts = {};\n\t\t\t}\n\t\t\tconfig.workerScripts.deflate = configuration.workerScripts.deflate;\n\t\t}\n\t\tif (configuration.workerScripts.inflate) {\n\t\t\tif (!Array.isArray(configuration.workerScripts.inflate)) {\n\t\t\t\tthrow new Error(\"workerScripts.inflate must be an array\");\n\t\t\t}\n\t\t\tif (!config.workerScripts) {\n\t\t\t\tconfig.workerScripts = {};\n\t\t\t}\n\t\t\tconfig.workerScripts.inflate = configuration.workerScripts.inflate;\n\t\t}\n\t}\n}\n", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst table = [];\nfor (let i = 0; i < 256; i++) {\n\tlet t = i;\n\tfor (let j = 0; j < 8; j++) {\n\t\tif (t & 1) {\n\t\t\tt = (t >>> 1) ^ 0xEDB88320;\n\t\t} else {\n\t\t\tt = t >>> 1;\n\t\t}\n\t}\n\ttable[i] = t;\n}\n\nclass Crc32 {\n\n\tconstructor(crc) {\n\t\tthis.crc = crc || -1;\n\t}\n\n\tappend(data) {\n\t\tlet crc = this.crc | 0;\n\t\tfor (let offset = 0, length = data.length | 0; offset < length; offset++) {\n\t\t\tcrc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];\n\t\t}\n\t\tthis.crc = crc;\n\t}\n\n\tget() {\n\t\treturn ~this.crc;\n\t}\n}\n\nexport default Crc32;", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global TextEncoder */\n\nexport default encodeText;\n\nfunction encodeText(value) {\n\tif (typeof TextEncoder == \"undefined\") {\n\t\tvalue = unescape(encodeURIComponent(value));\n\t\tconst result = new Uint8Array(value.length);\n\t\tfor (let i = 0; i < result.length; i++) {\n\t\t\tresult[i] = value.charCodeAt(i);\n\t\t}\n\t\treturn result;\n\t} else {\n\t\treturn new TextEncoder().encode(value);\n\t}\n}", "// Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl\n\n/*// deno-lint-ignore-file no-this-alias *\n\n/*\n * SJCL is open. You can use, modify and redistribute it under a BSD\n * license or under the GNU GPL, version 2.0.\n */\n\n/** @fileOverview Javascript cryptography implementation.\n *\n * Crush to remove comments, shorten variable names and\n * generally reduce transmission size.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */\n\n/** @fileOverview Arrays of bits, encoded as arrays of Numbers.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/**\n * Arrays of bits, encoded as arrays of Numbers.\n * @namespace\n * @description\n *

\n * These objects are the currency accepted by SJCL's crypto functions.\n *

\n *\n *

\n * Most of our crypto primitives operate on arrays of 4-byte words internally,\n * but many of them can take arguments that are not a multiple of 4 bytes.\n * This library encodes arrays of bits (whose size need not be a multiple of 8\n * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an\n * array of words, 32 bits at a time. Since the words are double-precision\n * floating point numbers, they fit some extra data. We use this (in a private,\n * possibly-changing manner) to encode the number of bits actually present\n * in the last word of the array.\n *

\n *\n *

\n * Because bitwise ops clear this out-of-band data, these arrays can be passed\n * to ciphers like AES which want arrays of words.\n *

\n */\nconst bitArray = {\n\t/**\n\t * Concatenate two bit arrays.\n\t * @param {bitArray} a1 The first array.\n\t * @param {bitArray} a2 The second array.\n\t * @return {bitArray} The concatenation of a1 and a2.\n\t */\n\tconcat(a1, a2) {\n\t\tif (a1.length === 0 || a2.length === 0) {\n\t\t\treturn a1.concat(a2);\n\t\t}\n\n\t\tconst last = a1[a1.length - 1], shift = bitArray.getPartial(last);\n\t\tif (shift === 32) {\n\t\t\treturn a1.concat(a2);\n\t\t} else {\n\t\t\treturn bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));\n\t\t}\n\t},\n\n\t/**\n\t * Find the length of an array of bits.\n\t * @param {bitArray} a The array.\n\t * @return {Number} The length of a, in bits.\n\t */\n\tbitLength(a) {\n\t\tconst l = a.length;\n\t\tif (l === 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tconst x = a[l - 1];\n\t\treturn (l - 1) * 32 + bitArray.getPartial(x);\n\t},\n\n\t/**\n\t * Truncate an array.\n\t * @param {bitArray} a The array.\n\t * @param {Number} len The length to truncate to, in bits.\n\t * @return {bitArray} A new array, truncated to len bits.\n\t */\n\tclamp(a, len) {\n\t\tif (a.length * 32 < len) {\n\t\t\treturn a;\n\t\t}\n\t\ta = a.slice(0, Math.ceil(len / 32));\n\t\tconst l = a.length;\n\t\tlen = len & 31;\n\t\tif (l > 0 && len) {\n\t\t\ta[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);\n\t\t}\n\t\treturn a;\n\t},\n\n\t/**\n\t * Make a partial word for a bit array.\n\t * @param {Number} len The number of bits in the word.\n\t * @param {Number} x The bits.\n\t * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.\n\t * @return {Number} The partial word.\n\t */\n\tpartial(len, x, _end) {\n\t\tif (len === 32) {\n\t\t\treturn x;\n\t\t}\n\t\treturn (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;\n\t},\n\n\t/**\n\t * Get the number of bits used by a partial word.\n\t * @param {Number} x The partial word.\n\t * @return {Number} The number of bits used by the partial word.\n\t */\n\tgetPartial(x) {\n\t\treturn Math.round(x / 0x10000000000) || 32;\n\t},\n\n\t/** Shift an array right.\n\t * @param {bitArray} a The array to shift.\n\t * @param {Number} shift The number of bits to shift.\n\t * @param {Number} [carry=0] A byte to carry in\n\t * @param {bitArray} [out=[]] An array to prepend to the output.\n\t * @private\n\t */\n\t_shiftRight(a, shift, carry, out) {\n\t\tif (out === undefined) {\n\t\t\tout = [];\n\t\t}\n\n\t\tfor (; shift >= 32; shift -= 32) {\n\t\t\tout.push(carry);\n\t\t\tcarry = 0;\n\t\t}\n\t\tif (shift === 0) {\n\t\t\treturn out.concat(a);\n\t\t}\n\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tout.push(carry | a[i] >>> shift);\n\t\t\tcarry = a[i] << (32 - shift);\n\t\t}\n\t\tconst last2 = a.length ? a[a.length - 1] : 0;\n\t\tconst shift2 = bitArray.getPartial(last2);\n\t\tout.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));\n\t\treturn out;\n\t}\n};\n\n/** @fileOverview Bit array codec implementations.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/**\n * Arrays of bytes\n * @namespace\n */\nconst codec = {\n\tbytes: {\n\t\t/** Convert from a bitArray to an array of bytes. */\n\t\tfromBits(arr) {\n\t\t\tconst bl = bitArray.bitLength(arr);\n\t\t\tconst byteLength = bl / 8;\n\t\t\tconst out = new Uint8Array(byteLength);\n\t\t\tlet tmp;\n\t\t\tfor (let i = 0; i < byteLength; i++) {\n\t\t\t\tif ((i & 3) === 0) {\n\t\t\t\t\ttmp = arr[i / 4];\n\t\t\t\t}\n\t\t\t\tout[i] = tmp >>> 24;\n\t\t\t\ttmp <<= 8;\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n\t\t/** Convert from an array of bytes to a bitArray. */\n\t\ttoBits(bytes) {\n\t\t\tconst out = [];\n\t\t\tlet i;\n\t\t\tlet tmp = 0;\n\t\t\tfor (i = 0; i < bytes.length; i++) {\n\t\t\t\ttmp = tmp << 8 | bytes[i];\n\t\t\t\tif ((i & 3) === 3) {\n\t\t\t\t\tout.push(tmp);\n\t\t\t\t\ttmp = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i & 3) {\n\t\t\t\tout.push(bitArray.partial(8 * (i & 3), tmp));\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t}\n};\n\nconst hash = {};\n\n/**\n * Context for a SHA-1 operation in progress.\n * @constructor\n */\nhash.sha1 = function (hash) {\n\tif (hash) {\n\t\tthis._h = hash._h.slice(0);\n\t\tthis._buffer = hash._buffer.slice(0);\n\t\tthis._length = hash._length;\n\t} else {\n\t\tthis.reset();\n\t}\n};\n\nhash.sha1.prototype = {\n\t/**\n\t * The hash's block size, in bits.\n\t * @constant\n\t */\n\tblockSize: 512,\n\n\t/**\n\t * Reset the hash state.\n\t * @return this\n\t */\n\treset: function () {\n\t\tconst sha1 = this;\n\t\tsha1._h = this._init.slice(0);\n\t\tsha1._buffer = [];\n\t\tsha1._length = 0;\n\t\treturn sha1;\n\t},\n\n\t/**\n\t * Input several words to the hash.\n\t * @param {bitArray|String} data the data to hash.\n\t * @return this\n\t */\n\tupdate: function (data) {\n\t\tconst sha1 = this;\n\t\tif (typeof data === \"string\") {\n\t\t\tdata = codec.utf8String.toBits(data);\n\t\t}\n\t\tconst b = sha1._buffer = bitArray.concat(sha1._buffer, data);\n\t\tconst ol = sha1._length;\n\t\tconst nl = sha1._length = ol + bitArray.bitLength(data);\n\t\tif (nl > 9007199254740991) {\n\t\t\tthrow new Error(\"Cannot hash more than 2^53 - 1 bits\");\n\t\t}\n\t\tconst c = new Uint32Array(b);\n\t\tlet j = 0;\n\t\tfor (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;\n\t\t\ti += sha1.blockSize) {\n\t\t\tsha1._block(c.subarray(16 * j, 16 * (j + 1)));\n\t\t\tj += 1;\n\t\t}\n\t\tb.splice(0, 16 * j);\n\t\treturn sha1;\n\t},\n\n\t/**\n\t * Complete hashing and output the hash value.\n\t * @return {bitArray} The hash value, an array of 5 big-endian words. TODO\n\t */\n\tfinalize: function () {\n\t\tconst sha1 = this;\n\t\tlet b = sha1._buffer;\n\t\tconst h = sha1._h;\n\n\t\t// Round out and push the buffer\n\t\tb = bitArray.concat(b, [bitArray.partial(1, 1)]);\n\t\t// Round out the buffer to a multiple of 16 words, less the 2 length words.\n\t\tfor (let i = b.length + 2; i & 15; i++) {\n\t\t\tb.push(0);\n\t\t}\n\n\t\t// append the length\n\t\tb.push(Math.floor(sha1._length / 0x100000000));\n\t\tb.push(sha1._length | 0);\n\n\t\twhile (b.length) {\n\t\t\tsha1._block(b.splice(0, 16));\n\t\t}\n\n\t\tsha1.reset();\n\t\treturn h;\n\t},\n\n\t/**\n\t * The SHA-1 initialization vector.\n\t * @private\n\t */\n\t_init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],\n\n\t/**\n\t * The SHA-1 hash key.\n\t * @private\n\t */\n\t_key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],\n\n\t/**\n\t * The SHA-1 logical functions f(0), f(1), ..., f(79).\n\t * @private\n\t */\n\t_f: function (t, b, c, d) {\n\t\tif (t <= 19) {\n\t\t\treturn (b & c) | (~b & d);\n\t\t} else if (t <= 39) {\n\t\t\treturn b ^ c ^ d;\n\t\t} else if (t <= 59) {\n\t\t\treturn (b & c) | (b & d) | (c & d);\n\t\t} else if (t <= 79) {\n\t\t\treturn b ^ c ^ d;\n\t\t}\n\t},\n\n\t/**\n\t * Circular left-shift operator.\n\t * @private\n\t */\n\t_S: function (n, x) {\n\t\treturn (x << n) | (x >>> 32 - n);\n\t},\n\n\t/**\n\t * Perform one cycle of SHA-1.\n\t * @param {Uint32Array|bitArray} words one block of words.\n\t * @private\n\t */\n\t_block: function (words) {\n\t\tconst sha1 = this;\n\t\tconst h = sha1._h;\n\t\t// When words is passed to _block, it has 16 elements. SHA1 _block\n\t\t// function extends words with new elements (at the end there are 80 elements). \n\t\t// The problem is that if we use Uint32Array instead of Array, \n\t\t// the length of Uint32Array cannot be changed. Thus, we replace words with a \n\t\t// normal Array here.\n\t\tconst w = Array(80); // do not use Uint32Array here as the instantiation is slower\n\t\tfor (let j = 0; j < 16; j++) {\n\t\t\tw[j] = words[j];\n\t\t}\n\n\t\tlet a = h[0];\n\t\tlet b = h[1];\n\t\tlet c = h[2];\n\t\tlet d = h[3];\n\t\tlet e = h[4];\n\n\t\tfor (let t = 0; t <= 79; t++) {\n\t\t\tif (t >= 16) {\n\t\t\t\tw[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);\n\t\t\t}\n\t\t\tconst tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +\n\t\t\t\tsha1._key[Math.floor(t / 20)]) | 0;\n\t\t\te = d;\n\t\t\td = c;\n\t\t\tc = sha1._S(30, b);\n\t\t\tb = a;\n\t\t\ta = tmp;\n\t\t}\n\n\t\th[0] = (h[0] + a) | 0;\n\t\th[1] = (h[1] + b) | 0;\n\t\th[2] = (h[2] + c) | 0;\n\t\th[3] = (h[3] + d) | 0;\n\t\th[4] = (h[4] + e) | 0;\n\t}\n};\n\n/** @fileOverview Low-level AES implementation.\n *\n * This file contains a low-level implementation of AES, optimized for\n * size and for efficiency on several browsers. It is based on\n * OpenSSL's aes_core.c, a public-domain implementation by Vincent\n * Rijmen, Antoon Bosselaers and Paulo Barreto.\n *\n * An older version of this implementation is available in the public\n * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,\n * Stanford University 2008-2010 and BSD-licensed for liability\n * reasons.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\nconst cipher = {};\n\n/**\n * Schedule out an AES key for both encryption and decryption. This\n * is a low-level class. Use a cipher mode to do bulk encryption.\n *\n * @constructor\n * @param {Array} key The key as an array of 4, 6 or 8 words.\n */\ncipher.aes = class {\n\tconstructor(key) {\n\t\t/**\n\t\t * The expanded S-box and inverse S-box tables. These will be computed\n\t\t * on the client so that we don't have to send them down the wire.\n\t\t *\n\t\t * There are two tables, _tables[0] is for encryption and\n\t\t * _tables[1] is for decryption.\n\t\t *\n\t\t * The first 4 sub-tables are the expanded S-box with MixColumns. The\n\t\t * last (_tables[01][4]) is the S-box itself.\n\t\t *\n\t\t * @private\n\t\t */\n\t\tconst aes = this;\n\t\taes._tables = [[[], [], [], [], []], [[], [], [], [], []]];\n\n\t\tif (!aes._tables[0][0][0]) {\n\t\t\taes._precompute();\n\t\t}\n\n\t\tconst sbox = aes._tables[0][4];\n\t\tconst decTable = aes._tables[1];\n\t\tconst keyLen = key.length;\n\n\t\tlet i, encKey, decKey, rcon = 1;\n\n\t\tif (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {\n\t\t\tthrow new Error(\"invalid aes key size\");\n\t\t}\n\n\t\taes._key = [encKey = key.slice(0), decKey = []];\n\n\t\t// schedule encryption keys\n\t\tfor (i = keyLen; i < 4 * keyLen + 28; i++) {\n\t\t\tlet tmp = encKey[i - 1];\n\n\t\t\t// apply sbox\n\t\t\tif (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {\n\t\t\t\ttmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];\n\n\t\t\t\t// shift rows and add rcon\n\t\t\t\tif (i % keyLen === 0) {\n\t\t\t\t\ttmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;\n\t\t\t\t\trcon = rcon << 1 ^ (rcon >> 7) * 283;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tencKey[i] = encKey[i - keyLen] ^ tmp;\n\t\t}\n\n\t\t// schedule decryption keys\n\t\tfor (let j = 0; i; j++, i--) {\n\t\t\tconst tmp = encKey[j & 3 ? i : i - 4];\n\t\t\tif (i <= 4 || j < 4) {\n\t\t\t\tdecKey[j] = tmp;\n\t\t\t} else {\n\t\t\t\tdecKey[j] = decTable[0][sbox[tmp >>> 24]] ^\n\t\t\t\t\tdecTable[1][sbox[tmp >> 16 & 255]] ^\n\t\t\t\t\tdecTable[2][sbox[tmp >> 8 & 255]] ^\n\t\t\t\t\tdecTable[3][sbox[tmp & 255]];\n\t\t\t}\n\t\t}\n\t}\n\t// public\n\t/* Something like this might appear here eventually\n\tname: \"AES\",\n\tblockSize: 4,\n\tkeySizes: [4,6,8],\n\t*/\n\n\t/**\n\t * Encrypt an array of 4 big-endian words.\n\t * @param {Array} data The plaintext.\n\t * @return {Array} The ciphertext.\n\t */\n\tencrypt(data) {\n\t\treturn this._crypt(data, 0);\n\t}\n\n\t/**\n\t * Decrypt an array of 4 big-endian words.\n\t * @param {Array} data The ciphertext.\n\t * @return {Array} The plaintext.\n\t */\n\tdecrypt(data) {\n\t\treturn this._crypt(data, 1);\n\t}\n\n\t/**\n\t * Expand the S-box tables.\n\t *\n\t * @private\n\t */\n\t_precompute() {\n\t\tconst encTable = this._tables[0];\n\t\tconst decTable = this._tables[1];\n\t\tconst sbox = encTable[4];\n\t\tconst sboxInv = decTable[4];\n\t\tconst d = [];\n\t\tconst th = [];\n\t\tlet xInv, x2, x4, x8;\n\n\t\t// Compute double and third tables\n\t\tfor (let i = 0; i < 256; i++) {\n\t\t\tth[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;\n\t\t}\n\n\t\tfor (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {\n\t\t\t// Compute sbox\n\t\t\tlet s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;\n\t\t\ts = s >> 8 ^ s & 255 ^ 99;\n\t\t\tsbox[x] = s;\n\t\t\tsboxInv[s] = x;\n\n\t\t\t// Compute MixColumns\n\t\t\tx8 = d[x4 = d[x2 = d[x]]];\n\t\t\tlet tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;\n\t\t\tlet tEnc = d[s] * 0x101 ^ s * 0x1010100;\n\n\t\t\tfor (let i = 0; i < 4; i++) {\n\t\t\t\tencTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;\n\t\t\t\tdecTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;\n\t\t\t}\n\t\t}\n\n\t\t// Compactify. Considerable speedup on Firefox.\n\t\tfor (let i = 0; i < 5; i++) {\n\t\t\tencTable[i] = encTable[i].slice(0);\n\t\t\tdecTable[i] = decTable[i].slice(0);\n\t\t}\n\t}\n\n\t/**\n\t * Encryption and decryption core.\n\t * @param {Array} input Four words to be encrypted or decrypted.\n\t * @param dir The direction, 0 for encrypt and 1 for decrypt.\n\t * @return {Array} The four encrypted or decrypted words.\n\t * @private\n\t */\n\t_crypt(input, dir) {\n\t\tif (input.length !== 4) {\n\t\t\tthrow new Error(\"invalid aes block size\");\n\t\t}\n\n\t\tconst key = this._key[dir];\n\n\t\tconst nInnerRounds = key.length / 4 - 2;\n\t\tconst out = [0, 0, 0, 0];\n\t\tconst table = this._tables[dir];\n\n\t\t// load up the tables\n\t\tconst t0 = table[0];\n\t\tconst t1 = table[1];\n\t\tconst t2 = table[2];\n\t\tconst t3 = table[3];\n\t\tconst sbox = table[4];\n\n\t\t// state variables a,b,c,d are loaded with pre-whitened data\n\t\tlet a = input[0] ^ key[0];\n\t\tlet b = input[dir ? 3 : 1] ^ key[1];\n\t\tlet c = input[2] ^ key[2];\n\t\tlet d = input[dir ? 1 : 3] ^ key[3];\n\t\tlet kIndex = 4;\n\t\tlet a2, b2, c2;\n\n\t\t// Inner rounds. Cribbed from OpenSSL.\n\t\tfor (let i = 0; i < nInnerRounds; i++) {\n\t\t\ta2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];\n\t\t\tb2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];\n\t\t\tc2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];\n\t\t\td = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];\n\t\t\tkIndex += 4;\n\t\t\ta = a2; b = b2; c = c2;\n\t\t}\n\n\t\t// Last round.\n\t\tfor (let i = 0; i < 4; i++) {\n\t\t\tout[dir ? 3 & -i : i] =\n\t\t\t\tsbox[a >>> 24] << 24 ^\n\t\t\t\tsbox[b >> 16 & 255] << 16 ^\n\t\t\t\tsbox[c >> 8 & 255] << 8 ^\n\t\t\t\tsbox[d & 255] ^\n\t\t\t\tkey[kIndex++];\n\t\t\ta2 = a; a = b; b = c; c = d; d = a2;\n\t\t}\n\n\t\treturn out;\n\t}\n};\n\n/**\n * Random values\n * @namespace\n */\nconst random = {\n\t/** \n\t * Generate random words with pure js, cryptographically not as strong & safe as native implementation.\n\t * @param {TypedArray} typedArray The array to fill.\n\t * @return {TypedArray} The random values.\n\t */\n\tgetRandomValues(typedArray) {\n\t\tconst words = new Uint32Array(typedArray.buffer);\n\t\tconst r = (m_w) => {\n\t\t\tlet m_z = 0x3ade68b1;\n\t\t\tconst mask = 0xffffffff;\n\t\t\treturn function () {\n\t\t\t\tm_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;\n\t\t\t\tm_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;\n\t\t\t\tconst result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;\n\t\t\t\treturn result * (Math.random() > .5 ? 1 : -1);\n\t\t\t};\n\t\t};\n\t\tfor (let i = 0, rcache; i < typedArray.length; i += 4) {\n\t\t\tconst _r = r((rcache || Math.random()) * 0x100000000);\n\t\t\trcache = _r() * 0x3ade67b7;\n\t\t\twords[i / 4] = (_r() * 0x100000000) | 0;\n\t\t}\n\t\treturn typedArray;\n\t}\n};\n\n/** @fileOverview CTR mode implementation.\n *\n * Special thanks to Roy Nicholson for pointing out a bug in our\n * implementation.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/** Brian Gladman's CTR Mode.\n* @constructor\n* @param {Object} _prf The aes instance to generate key.\n* @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.\n*/\n\nconst mode = {};\n\n/**\n * Brian Gladman's CTR Mode.\n * @namespace\n */\nmode.ctrGladman = class {\n\tconstructor(prf, iv) {\n\t\tthis._prf = prf;\n\t\tthis._initIv = iv;\n\t\tthis._iv = iv;\n\t}\n\n\treset() {\n\t\tthis._iv = this._initIv;\n\t}\n\n\t/** Input some data to calculate.\n\t * @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.\n\t */\n\tupdate(data) {\n\t\treturn this.calculate(this._prf, data, this._iv);\n\t}\n\n\tincWord(word) {\n\t\tif (((word >> 24) & 0xff) === 0xff) { //overflow\n\t\t\tlet b1 = (word >> 16) & 0xff;\n\t\t\tlet b2 = (word >> 8) & 0xff;\n\t\t\tlet b3 = word & 0xff;\n\n\t\t\tif (b1 === 0xff) { // overflow b1 \n\t\t\t\tb1 = 0;\n\t\t\t\tif (b2 === 0xff) {\n\t\t\t\t\tb2 = 0;\n\t\t\t\t\tif (b3 === 0xff) {\n\t\t\t\t\t\tb3 = 0;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t++b3;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t++b2;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t++b1;\n\t\t\t}\n\n\t\t\tword = 0;\n\t\t\tword += (b1 << 16);\n\t\t\tword += (b2 << 8);\n\t\t\tword += b3;\n\t\t} else {\n\t\t\tword += (0x01 << 24);\n\t\t}\n\t\treturn word;\n\t}\n\n\tincCounter(counter) {\n\t\tif ((counter[0] = this.incWord(counter[0])) === 0) {\n\t\t\t// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8\n\t\t\tcounter[1] = this.incWord(counter[1]);\n\t\t}\n\t}\n\n\tcalculate(prf, data, iv) {\n\t\tlet l;\n\t\tif (!(l = data.length)) {\n\t\t\treturn [];\n\t\t}\n\t\tconst bl = bitArray.bitLength(data);\n\t\tfor (let i = 0; i < l; i += 4) {\n\t\t\tthis.incCounter(iv);\n\t\t\tconst e = prf.encrypt(iv);\n\t\t\tdata[i] ^= e[0];\n\t\t\tdata[i + 1] ^= e[1];\n\t\t\tdata[i + 2] ^= e[2];\n\t\t\tdata[i + 3] ^= e[3];\n\t\t}\n\t\treturn bitArray.clamp(data, bl);\n\t}\n};\n\nconst misc = {\n\timportKey(password) {\n\t\treturn new misc.hmacSha1(codec.bytes.toBits(password));\n\t},\n\tpbkdf2(prf, salt, count, length) {\n\t\tcount = count || 10000;\n\t\tif (length < 0 || count < 0) {\n\t\t\tthrow new Error(\"invalid params to pbkdf2\");\n\t\t}\n\t\tconst byteLength = ((length >> 5) + 1) << 2;\n\t\tlet u, ui, i, j, k;\n\t\tconst arrayBuffer = new ArrayBuffer(byteLength);\n\t\tconst out = new DataView(arrayBuffer);\n\t\tlet outLength = 0;\n\t\tconst b = bitArray;\n\t\tsalt = codec.bytes.toBits(salt);\n\t\tfor (k = 1; outLength < (byteLength || 1); k++) {\n\t\t\tu = ui = prf.encrypt(b.concat(salt, [k]));\n\t\t\tfor (i = 1; i < count; i++) {\n\t\t\t\tui = prf.encrypt(ui);\n\t\t\t\tfor (j = 0; j < ui.length; j++) {\n\t\t\t\t\tu[j] ^= ui[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {\n\t\t\t\tout.setInt32(outLength, u[i]);\n\t\t\t\toutLength += 4;\n\t\t\t}\n\t\t}\n\t\treturn arrayBuffer.slice(0, length / 8);\n\t}\n};\n\n/** @fileOverview HMAC implementation.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/** HMAC with the specified hash function.\n * @constructor\n * @param {bitArray} key the key for HMAC.\n * @param {Object} [Hash=hash.sha1] The hash function to use.\n */\nmisc.hmacSha1 = class {\n\n\tconstructor(key) {\n\t\tconst hmac = this;\n\t\tconst Hash = hmac._hash = hash.sha1;\n\t\tconst exKey = [[], []];\n\t\tconst bs = Hash.prototype.blockSize / 32;\n\t\thmac._baseHash = [new Hash(), new Hash()];\n\n\t\tif (key.length > bs) {\n\t\t\tkey = Hash.hash(key);\n\t\t}\n\n\t\tfor (let i = 0; i < bs; i++) {\n\t\t\texKey[0][i] = key[i] ^ 0x36363636;\n\t\t\texKey[1][i] = key[i] ^ 0x5C5C5C5C;\n\t\t}\n\n\t\thmac._baseHash[0].update(exKey[0]);\n\t\thmac._baseHash[1].update(exKey[1]);\n\t\thmac._resultHash = new Hash(hmac._baseHash[0]);\n\t}\n\treset() {\n\t\tconst hmac = this;\n\t\thmac._resultHash = new hmac._hash(hmac._baseHash[0]);\n\t\thmac._updated = false;\n\t}\n\n\tupdate(data) {\n\t\tconst hmac = this;\n\t\thmac._updated = true;\n\t\thmac._resultHash.update(data);\n\t}\n\n\tdigest() {\n\t\tconst hmac = this;\n\t\tconst w = hmac._resultHash.finalize();\n\t\tconst result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();\n\n\t\thmac.reset();\n\n\t\treturn result;\n\t}\n\n\tencrypt(data) {\n\t\tif (!this._updated) {\n\t\t\tthis.update(data);\n\t\t\treturn this.digest(data);\n\t\t} else {\n\t\t\tthrow new Error(\"encrypt on already updated hmac called!\");\n\t\t}\n\t}\n};\n\nexport {\n\tcipher,\n\tcodec,\n\tmisc,\n\tmode,\n\trandom\n};", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global crypto */\n// deno-lint-ignore-file no-this-alias\n\nimport encodeText from \"./../util/encode-text.js\";\nimport { cipher, codec, misc, mode, random } from \"./sjcl.js\";\n\nconst ERR_INVALID_PASSWORD = \"Invalid pasword\";\nconst BLOCK_LENGTH = 16;\nconst RAW_FORMAT = \"raw\";\nconst PBKDF2_ALGORITHM = { name: \"PBKDF2\" };\nconst HASH_ALGORITHM = { name: \"HMAC\" };\nconst HASH_FUNCTION = \"SHA-1\";\nconst BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);\nconst DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);\nconst DERIVED_BITS_USAGE = [\"deriveBits\"];\nconst SALT_LENGTH = [8, 12, 16];\nconst KEY_LENGTH = [16, 24, 32];\nconst SIGNATURE_LENGTH = 10;\nconst COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];\nconst CRYPTO_API_SUPPORTED = typeof crypto != \"undefined\";\nconst SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof crypto.subtle != \"undefined\";\nconst codecBytes = codec.bytes;\nconst Aes = cipher.aes;\nconst CtrGladman = mode.ctrGladman;\nconst HmacSha1 = misc.hmacSha1;\nclass AESDecrypt {\n\n\tconstructor(password, signed, strength) {\n\t\tObject.assign(this, {\n\t\t\tpassword,\n\t\t\tsigned,\n\t\t\tstrength: strength - 1,\n\t\t\tpendingInput: new Uint8Array(0)\n\t\t});\n\t}\n\n\tasync append(input) {\n\t\tconst aesCrypto = this;\n\t\tif (aesCrypto.password) {\n\t\t\tconst preamble = subarray(input, 0, SALT_LENGTH[aesCrypto.strength] + 2);\n\t\t\tawait createDecryptionKeys(aesCrypto, preamble, aesCrypto.password);\n\t\t\taesCrypto.password = null;\n\t\t\taesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));\n\t\t\taesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);\n\t\t\tinput = subarray(input, SALT_LENGTH[aesCrypto.strength] + 2);\n\t\t}\n\t\tconst output = new Uint8Array(input.length - SIGNATURE_LENGTH - ((input.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));\n\t\treturn append(aesCrypto, input, output, 0, SIGNATURE_LENGTH, true);\n\t}\n\n\tflush() {\n\t\tconst aesCrypto = this;\n\t\tconst pendingInput = aesCrypto.pendingInput;\n\t\tconst chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - SIGNATURE_LENGTH);\n\t\tconst originalSignature = subarray(pendingInput, pendingInput.length - SIGNATURE_LENGTH);\n\t\tlet decryptedChunkArray = new Uint8Array(0);\n\t\tif (chunkToDecrypt.length) {\n\t\t\tconst encryptedChunk = codecBytes.toBits(chunkToDecrypt);\n\t\t\taesCrypto.hmac.update(encryptedChunk);\n\t\t\tconst decryptedChunk = aesCrypto.aesCtrGladman.update(encryptedChunk);\n\t\t\tdecryptedChunkArray = codecBytes.fromBits(decryptedChunk);\n\t\t}\n\t\tlet valid = true;\n\t\tif (aesCrypto.signed) {\n\t\t\tconst signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);\n\t\t\tfor (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {\n\t\t\t\tif (signature[indexSignature] != originalSignature[indexSignature]) {\n\t\t\t\t\tvalid = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tvalid,\n\t\t\tdata: decryptedChunkArray\n\t\t};\n\t}\n}\n\nclass AESEncrypt {\n\n\tconstructor(password, strength) {\n\t\tObject.assign(this, {\n\t\t\tpassword,\n\t\t\tstrength: strength - 1,\n\t\t\tpendingInput: new Uint8Array(0)\n\t\t});\n\t}\n\n\tasync append(input) {\n\t\tconst aesCrypto = this;\n\t\tlet preamble = new Uint8Array(0);\n\t\tif (aesCrypto.password) {\n\t\t\tpreamble = await createEncryptionKeys(aesCrypto, aesCrypto.password);\n\t\t\taesCrypto.password = null;\n\t\t\taesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));\n\t\t\taesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);\n\t\t}\n\t\tconst output = new Uint8Array(preamble.length + input.length - (input.length % BLOCK_LENGTH));\n\t\toutput.set(preamble, 0);\n\t\treturn append(aesCrypto, input, output, preamble.length, 0);\n\t}\n\n\tflush() {\n\t\tconst aesCrypto = this;\n\t\tlet encryptedChunkArray = new Uint8Array(0);\n\t\tif (aesCrypto.pendingInput.length) {\n\t\t\tconst encryptedChunk = aesCrypto.aesCtrGladman.update(codecBytes.toBits(aesCrypto.pendingInput));\n\t\t\taesCrypto.hmac.update(encryptedChunk);\n\t\t\tencryptedChunkArray = codecBytes.fromBits(encryptedChunk);\n\t\t}\n\t\tconst signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);\n\t\treturn {\n\t\t\tdata: concat(encryptedChunkArray, signature),\n\t\t\tsignature\n\t\t};\n\t}\n}\n\nexport {\n\tAESDecrypt,\n\tAESEncrypt,\n\tERR_INVALID_PASSWORD\n};\n\nfunction append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {\n\tconst inputLength = input.length - paddingEnd;\n\tif (aesCrypto.pendingInput.length) {\n\t\tinput = concat(aesCrypto.pendingInput, input);\n\t\toutput = expand(output, inputLength - (inputLength % BLOCK_LENGTH));\n\t}\n\tlet offset;\n\tfor (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {\n\t\tconst inputChunk = codecBytes.toBits(subarray(input, offset, offset + BLOCK_LENGTH));\n\t\tif (verifySignature) {\n\t\t\taesCrypto.hmac.update(inputChunk);\n\t\t}\n\t\tconst outputChunk = aesCrypto.aesCtrGladman.update(inputChunk);\n\t\tif (!verifySignature) {\n\t\t\taesCrypto.hmac.update(outputChunk);\n\t\t}\n\t\toutput.set(codecBytes.fromBits(outputChunk), offset + paddingStart);\n\t}\n\taesCrypto.pendingInput = subarray(input, offset);\n\treturn output;\n}\n\nasync function createDecryptionKeys(decrypt, preambleArray, password) {\n\tawait createKeys(decrypt, password, subarray(preambleArray, 0, SALT_LENGTH[decrypt.strength]));\n\tconst passwordVerification = subarray(preambleArray, SALT_LENGTH[decrypt.strength]);\n\tconst passwordVerificationKey = decrypt.keys.passwordVerification;\n\tif (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {\n\t\tthrow new Error(ERR_INVALID_PASSWORD);\n\t}\n}\n\nasync function createEncryptionKeys(encrypt, password) {\n\tconst salt = getRandomValues(new Uint8Array(SALT_LENGTH[encrypt.strength]));\n\tawait createKeys(encrypt, password, salt);\n\treturn concat(salt, encrypt.keys.passwordVerification);\n}\n\nasync function createKeys(target, password, salt) {\n\tconst encodedPassword = encodeText(password);\n\tconst basekey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);\n\tconst derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), basekey, 8 * ((KEY_LENGTH[target.strength] * 2) + 2));\n\tconst compositeKey = new Uint8Array(derivedBits);\n\ttarget.keys = {\n\t\tkey: codecBytes.toBits(subarray(compositeKey, 0, KEY_LENGTH[target.strength])),\n\t\tauthentication: codecBytes.toBits(subarray(compositeKey, KEY_LENGTH[target.strength], KEY_LENGTH[target.strength] * 2)),\n\t\tpasswordVerification: subarray(compositeKey, KEY_LENGTH[target.strength] * 2)\n\t};\n}\n\nfunction getRandomValues(array) {\n\tif (CRYPTO_API_SUPPORTED && typeof crypto.getRandomValues == \"function\") {\n\t\treturn crypto.getRandomValues(array);\n\t} else {\n\t\treturn random.getRandomValues(array);\n\t}\n}\n\nfunction importKey(format, password, algorithm, extractable, keyUsages) {\n\tif (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.importKey == \"function\") {\n\t\treturn crypto.subtle.importKey(format, password, algorithm, extractable, keyUsages);\n\t} else {\n\t\treturn misc.importKey(password);\n\t}\n}\n\nasync function deriveBits(algorithm, baseKey, length) {\n\tif (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.deriveBits == \"function\") {\n\t\treturn await crypto.subtle.deriveBits(algorithm, baseKey, length);\n\t} else {\n\t\treturn misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);\n\t}\n}\n\nfunction concat(leftArray, rightArray) {\n\tlet array = leftArray;\n\tif (leftArray.length + rightArray.length) {\n\t\tarray = new Uint8Array(leftArray.length + rightArray.length);\n\t\tarray.set(leftArray, 0);\n\t\tarray.set(rightArray, leftArray.length);\n\t}\n\treturn array;\n}\n\nfunction expand(inputArray, length) {\n\tif (length && length > inputArray.length) {\n\t\tconst array = inputArray;\n\t\tinputArray = new Uint8Array(length);\n\t\tinputArray.set(array, 0);\n\t}\n\treturn inputArray;\n}\n\nfunction subarray(array, begin, end) {\n\treturn array.subarray(begin, end);\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global crypto */\n// deno-lint-ignore-file no-this-alias\n\nimport Crc32 from \"./crc32.js\";\nimport { ERR_INVALID_PASSWORD } from \"./aes-crypto.js\";\n\nconst HEADER_LENGTH = 12;\n\nclass ZipCryptoDecrypt {\n\n\tconstructor(password, passwordVerification) {\n\t\tconst zipCrypto = this;\n\t\tObject.assign(zipCrypto, {\n\t\t\tpassword,\n\t\t\tpasswordVerification\n\t\t});\n\t\tcreateKeys(zipCrypto, password);\n\t}\n\n\tappend(input) {\n\t\tconst zipCrypto = this;\n\t\tif (zipCrypto.password) {\n\t\t\tconst decryptedHeader = decrypt(zipCrypto, input.subarray(0, HEADER_LENGTH));\n\t\t\tzipCrypto.password = null;\n\t\t\tif (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {\n\t\t\t\tthrow new Error(ERR_INVALID_PASSWORD);\n\t\t\t}\n\t\t\tinput = input.subarray(HEADER_LENGTH);\n\t\t}\n\t\treturn decrypt(zipCrypto, input);\n\t}\n\n\tflush() {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdata: new Uint8Array(0)\n\t\t};\n\t}\n}\n\nclass ZipCryptoEncrypt {\n\n\tconstructor(password, passwordVerification) {\n\t\tconst zipCrypto = this;\n\t\tObject.assign(zipCrypto, {\n\t\t\tpassword,\n\t\t\tpasswordVerification\n\t\t});\n\t\tcreateKeys(zipCrypto, password);\n\t}\n\n\tappend(input) {\n\t\tconst zipCrypto = this;\n\t\tlet output;\n\t\tlet offset;\n\t\tif (zipCrypto.password) {\n\t\t\tzipCrypto.password = null;\n\t\t\tconst header = crypto.getRandomValues(new Uint8Array(HEADER_LENGTH));\n\t\t\theader[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;\n\t\t\toutput = new Uint8Array(input.length + header.length);\n\t\t\toutput.set(encrypt(zipCrypto, header), 0);\n\t\t\toffset = HEADER_LENGTH;\n\t\t} else {\n\t\t\toutput = new Uint8Array(input.length);\n\t\t\toffset = 0;\n\t\t}\n\t\toutput.set(encrypt(zipCrypto, input), offset);\n\t\treturn output;\n\t}\n\n\tflush() {\n\t\treturn {\n\t\t\tdata: new Uint8Array(0)\n\t\t};\n\t}\n}\n\nexport {\n\tZipCryptoDecrypt,\n\tZipCryptoEncrypt,\n\tERR_INVALID_PASSWORD\n};\n\nfunction decrypt(target, input) {\n\tconst output = new Uint8Array(input.length);\n\tfor (let index = 0; index < input.length; index++) {\n\t\toutput[index] = getByte(target) ^ input[index];\n\t\tupdateKeys(target, output[index]);\n\t}\n\treturn output;\n}\n\nfunction encrypt(target, input) {\n\tconst output = new Uint8Array(input.length);\n\tfor (let index = 0; index < input.length; index++) {\n\t\toutput[index] = getByte(target) ^ input[index];\n\t\tupdateKeys(target, input[index]);\n\t}\n\treturn output;\n}\n\nfunction createKeys(target, password) {\n\ttarget.keys = [0x12345678, 0x23456789, 0x34567890];\n\ttarget.crcKey0 = new Crc32(target.keys[0]);\n\ttarget.crcKey2 = new Crc32(target.keys[2]);\n\tfor (let index = 0; index < password.length; index++) {\n\t\tupdateKeys(target, password.charCodeAt(index));\n\t}\n}\n\nfunction updateKeys(target, byte) {\n\ttarget.crcKey0.append([byte]);\n\ttarget.keys[0] = ~target.crcKey0.get();\n\ttarget.keys[1] = getInt32(target.keys[1] + getInt8(target.keys[0]));\n\ttarget.keys[1] = getInt32(Math.imul(target.keys[1], 134775813) + 1);\n\ttarget.crcKey2.append([target.keys[1] >>> 24]);\n\ttarget.keys[2] = ~target.crcKey2.get();\n}\n\nfunction getByte(target) {\n\tconst temp = target.keys[2] | 2;\n\treturn getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);\n}\n\nfunction getInt8(number) {\n\treturn number & 0xFF;\n}\n\nfunction getInt32(number) {\n\treturn number & 0xFFFFFFFF;\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n// deno-lint-ignore-file no-this-alias\n\nimport Crc32 from \"./crc32.js\";\nimport { AESEncrypt, AESDecrypt, ERR_INVALID_PASSWORD } from \"./aes-crypto.js\";\nimport { ZipCryptoDecrypt, ZipCryptoEncrypt } from \"./zip-crypto.js\";\n\nconst CODEC_DEFLATE = \"deflate\";\nconst CODEC_INFLATE = \"inflate\";\nconst ERR_INVALID_SIGNATURE = \"Invalid signature\";\n\nclass Inflate {\n\n\tconstructor(codecConstructor, {\n\t\tsignature,\n\t\tpassword,\n\t\tsigned,\n\t\tcompressed,\n\t\tzipCrypto,\n\t\tpasswordVerification,\n\t\tencryptionStrength\n\t}, { chunkSize }) {\n\t\tconst encrypted = Boolean(password);\n\t\tObject.assign(this, {\n\t\t\tsignature,\n\t\t\tencrypted,\n\t\t\tsigned,\n\t\t\tcompressed,\n\t\t\tinflate: compressed && new codecConstructor({ chunkSize }),\n\t\t\tcrc32: signed && new Crc32(),\n\t\t\tzipCrypto,\n\t\t\tdecrypt: encrypted && zipCrypto ?\n\t\t\t\tnew ZipCryptoDecrypt(password, passwordVerification) :\n\t\t\t\tnew AESDecrypt(password, signed, encryptionStrength)\n\t\t});\n\t}\n\n\tasync append(data) {\n\t\tconst codec = this;\n\t\tif (codec.encrypted && data.length) {\n\t\t\tdata = await codec.decrypt.append(data);\n\t\t}\n\t\tif (codec.compressed && data.length) {\n\t\t\tdata = await codec.inflate.append(data);\n\t\t}\n\t\tif ((!codec.encrypted || codec.zipCrypto) && codec.signed && data.length) {\n\t\t\tcodec.crc32.append(data);\n\t\t}\n\t\treturn data;\n\t}\n\n\tasync flush() {\n\t\tconst codec = this;\n\t\tlet signature;\n\t\tlet data = new Uint8Array(0);\n\t\tif (codec.encrypted) {\n\t\t\tconst result = codec.decrypt.flush();\n\t\t\tif (!result.valid) {\n\t\t\t\tthrow new Error(ERR_INVALID_SIGNATURE);\n\t\t\t}\n\t\t\tdata = result.data;\n\t\t}\n\t\tif ((!codec.encrypted || codec.zipCrypto) && codec.signed) {\n\t\t\tconst dataViewSignature = new DataView(new Uint8Array(4).buffer);\n\t\t\tsignature = codec.crc32.get();\n\t\t\tdataViewSignature.setUint32(0, signature);\n\t\t\tif (codec.signature != dataViewSignature.getUint32(0, false)) {\n\t\t\t\tthrow new Error(ERR_INVALID_SIGNATURE);\n\t\t\t}\n\t\t}\n\t\tif (codec.compressed) {\n\t\t\tdata = (await codec.inflate.append(data)) || new Uint8Array(0);\n\t\t\tawait codec.inflate.flush();\n\t\t}\n\t\treturn { data, signature };\n\t}\n}\n\nclass Deflate {\n\n\tconstructor(codecConstructor, {\n\t\tencrypted,\n\t\tsigned,\n\t\tcompressed,\n\t\tlevel,\n\t\tzipCrypto,\n\t\tpassword,\n\t\tpasswordVerification,\n\t\tencryptionStrength\n\t}, { chunkSize }) {\n\t\tObject.assign(this, {\n\t\t\tencrypted,\n\t\t\tsigned,\n\t\t\tcompressed,\n\t\t\tdeflate: compressed && new codecConstructor({ level: level || 5, chunkSize }),\n\t\t\tcrc32: signed && new Crc32(),\n\t\t\tzipCrypto,\n\t\t\tencrypt: encrypted && zipCrypto ?\n\t\t\t\tnew ZipCryptoEncrypt(password, passwordVerification) :\n\t\t\t\tnew AESEncrypt(password, encryptionStrength)\n\t\t});\n\t}\n\n\tasync append(inputData) {\n\t\tconst codec = this;\n\t\tlet data = inputData;\n\t\tif (codec.compressed && inputData.length) {\n\t\t\tdata = await codec.deflate.append(inputData);\n\t\t}\n\t\tif (codec.encrypted && data.length) {\n\t\t\tdata = await codec.encrypt.append(data);\n\t\t}\n\t\tif ((!codec.encrypted || codec.zipCrypto) && codec.signed && inputData.length) {\n\t\t\tcodec.crc32.append(inputData);\n\t\t}\n\t\treturn data;\n\t}\n\n\tasync flush() {\n\t\tconst codec = this;\n\t\tlet signature;\n\t\tlet data = new Uint8Array(0);\n\t\tif (codec.compressed) {\n\t\t\tdata = (await codec.deflate.flush()) || new Uint8Array(0);\n\t\t}\n\t\tif (codec.encrypted) {\n\t\t\tdata = await codec.encrypt.append(data);\n\t\t\tconst result = codec.encrypt.flush();\n\t\t\tsignature = result.signature;\n\t\t\tconst newData = new Uint8Array(data.length + result.data.length);\n\t\t\tnewData.set(data, 0);\n\t\t\tnewData.set(result.data, data.length);\n\t\t\tdata = newData;\n\t\t}\n\t\tif ((!codec.encrypted || codec.zipCrypto) && codec.signed) {\n\t\t\tsignature = codec.crc32.get();\n\t\t}\n\t\treturn { data, signature };\n\t}\n}\n\nexport {\n\tInflate,\n\tDeflate,\n\tcreateCodec,\n\tCODEC_DEFLATE,\n\tCODEC_INFLATE,\n\tERR_INVALID_SIGNATURE,\n\tERR_INVALID_PASSWORD\n};\n\nfunction createCodec(codecConstructor, options, config) {\n\tif (options.codecType.startsWith(CODEC_DEFLATE)) {\n\t\treturn new Deflate(codecConstructor, options, config);\n\t} else if (options.codecType.startsWith(CODEC_INFLATE)) {\n\t\treturn new Inflate(codecConstructor, options, config);\n\t}\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global Worker, URL */\n\nimport { createCodec } from \"./codec.js\";\n\nconst MESSAGE_INIT = \"init\";\nconst MESSAGE_APPEND = \"append\";\nconst MESSAGE_FLUSH = \"flush\";\nconst MESSAGE_EVENT_TYPE = \"message\";\n\nlet classicWorkersSupported = true;\n\nexport default (workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts) => {\n\tObject.assign(workerData, {\n\t\tbusy: true,\n\t\tcodecConstructor,\n\t\toptions: Object.assign({}, options),\n\t\tscripts,\n\t\tterminate() {\n\t\t\tif (workerData.worker && !workerData.busy) {\n\t\t\t\tworkerData.worker.terminate();\n\t\t\t\tworkerData.interface = null;\n\t\t\t}\n\t\t},\n\t\tonTaskFinished() {\n\t\t\tworkerData.busy = false;\n\t\t\tonTaskFinished(workerData);\n\t\t}\n\t});\n\treturn webWorker ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);\n};\n\nfunction createWorkerInterface(workerData, config) {\n\tconst interfaceCodec = createCodec(workerData.codecConstructor, workerData.options, config);\n\treturn {\n\t\tasync append(data) {\n\t\t\ttry {\n\t\t\t\treturn await interfaceCodec.append(data);\n\t\t\t} catch (error) {\n\t\t\t\tworkerData.onTaskFinished();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tasync flush() {\n\t\t\ttry {\n\t\t\t\treturn await interfaceCodec.flush();\n\t\t\t} finally {\n\t\t\t\tworkerData.onTaskFinished();\n\t\t\t}\n\t\t},\n\t\tabort() {\n\t\t\tworkerData.onTaskFinished();\n\t\t}\n\t};\n}\n\nfunction createWebWorkerInterface(workerData, config) {\n\tlet messageTask;\n\tconst workerOptions = { type: \"module\" };\n\tif (!workerData.interface) {\n\t\tif (!classicWorkersSupported) {\n\t\t\tworkerData.worker = getWorker(workerOptions, config.baseURL);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tworkerData.worker = getWorker({}, config.baseURL);\n\t\t\t} catch (_error) {\n\t\t\t\tclassicWorkersSupported = false;\n\t\t\t\tworkerData.worker = getWorker(workerOptions, config.baseURL);\n\t\t\t}\n\t\t}\n\t\tworkerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);\n\t\tworkerData.interface = {\n\t\t\tappend(data) {\n\t\t\t\treturn initAndSendMessage({ type: MESSAGE_APPEND, data });\n\t\t\t},\n\t\t\tflush() {\n\t\t\t\treturn initAndSendMessage({ type: MESSAGE_FLUSH });\n\t\t\t},\n\t\t\tabort() {\n\t\t\t\tworkerData.onTaskFinished();\n\t\t\t}\n\t\t};\n\t}\n\treturn workerData.interface;\n\n\tfunction getWorker(options, baseURL) {\n\t\tlet url, scriptUrl;\n\t\turl = workerData.scripts[0];\n\t\tif (typeof url == \"function\") {\n\t\t\turl = url();\n\t\t}\n\t\ttry {\n\t\t\tscriptUrl = new URL(url, baseURL);\n\t\t} catch (_error) {\n\t\t\tscriptUrl = url;\n\t\t}\n\t\treturn new Worker(scriptUrl, options);\n\t}\n\n\tasync function initAndSendMessage(message) {\n\t\tif (!messageTask) {\n\t\t\tconst options = workerData.options;\n\t\t\tconst scripts = workerData.scripts.slice(1);\n\t\t\tawait sendMessage({ scripts, type: MESSAGE_INIT, options, config: { chunkSize: config.chunkSize } });\n\t\t}\n\t\treturn sendMessage(message);\n\t}\n\n\tfunction sendMessage(message) {\n\t\tconst worker = workerData.worker;\n\t\tconst result = new Promise((resolve, reject) => messageTask = { resolve, reject });\n\t\ttry {\n\t\t\tif (message.data) {\n\t\t\t\ttry {\n\t\t\t\t\tmessage.data = message.data.buffer;\n\t\t\t\t\tworker.postMessage(message, [message.data]);\n\t\t\t\t} catch (_error) {\n\t\t\t\t\tworker.postMessage(message);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tworker.postMessage(message);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tmessageTask.reject(error);\n\t\t\tmessageTask = null;\n\t\t\tworkerData.onTaskFinished();\n\t\t}\n\t\treturn result;\n\t}\n\n\tfunction onMessage(event) {\n\t\tconst message = event.data;\n\t\tif (messageTask) {\n\t\t\tconst reponseError = message.error;\n\t\t\tconst type = message.type;\n\t\t\tif (reponseError) {\n\t\t\t\tconst error = new Error(reponseError.message);\n\t\t\t\terror.stack = reponseError.stack;\n\t\t\t\tmessageTask.reject(error);\n\t\t\t\tmessageTask = null;\n\t\t\t\tworkerData.onTaskFinished();\n\t\t\t} else if (type == MESSAGE_INIT || type == MESSAGE_FLUSH || type == MESSAGE_APPEND) {\n\t\t\t\tconst data = message.data;\n\t\t\t\tif (type == MESSAGE_FLUSH) {\n\t\t\t\t\tmessageTask.resolve({ data: new Uint8Array(data), signature: message.signature });\n\t\t\t\t\tmessageTask = null;\n\t\t\t\t\tworkerData.onTaskFinished();\n\t\t\t\t} else {\n\t\t\t\t\tmessageTask.resolve(data && new Uint8Array(data));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global setTimeout, clearTimeout */\n\nimport { CODEC_INFLATE, CODEC_DEFLATE, ERR_INVALID_SIGNATURE, ERR_INVALID_PASSWORD } from \"./codec.js\";\nimport getWorker from \"./codec-pool-worker.js\";\n\nlet pool = [];\nconst pendingRequests = [];\n\nexport {\n\tcreateCodec,\n\tterminateWorkers,\n\tCODEC_DEFLATE,\n\tCODEC_INFLATE,\n\tERR_INVALID_SIGNATURE,\n\tERR_INVALID_PASSWORD\n};\n\nfunction createCodec(codecConstructor, options, config) {\n\tconst streamCopy = !options.compressed && !options.signed && !options.encrypted;\n\tconst webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));\n\tconst scripts = webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];\n\tif (pool.length < config.maxWorkers) {\n\t\tconst workerData = {};\n\t\tpool.push(workerData);\n\t\treturn getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);\n\t} else {\n\t\tconst workerData = pool.find(workerData => !workerData.busy);\n\t\tif (workerData) {\n\t\t\tclearTerminateTimeout(workerData);\n\t\t\treturn getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);\n\t\t} else {\n\t\t\treturn new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, options, webWorker, scripts }));\n\t\t}\n\t}\n\n\tfunction onTaskFinished(workerData) {\n\t\tif (pendingRequests.length) {\n\t\t\tconst [{ resolve, codecConstructor, options, webWorker, scripts }] = pendingRequests.splice(0, 1);\n\t\t\tresolve(getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts));\n\t\t} else if (workerData.worker) {\n\t\t\tclearTerminateTimeout(workerData);\n\t\t\tif (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {\n\t\t\t\tworkerData.terminateTimeout = setTimeout(() => {\n\t\t\t\t\tpool = pool.filter(data => data != workerData);\n\t\t\t\t\tworkerData.terminate();\n\t\t\t\t}, config.terminateWorkerTimeout);\n\t\t\t}\n\t\t} else {\n\t\t\tpool = pool.filter(data => data != workerData);\n\t\t}\n\t}\n}\n\nfunction clearTerminateTimeout(workerData) {\n\tif (workerData.terminateTimeout) {\n\t\tclearTimeout(workerData.terminateTimeout);\n\t\tworkerData.terminateTimeout = null;\n\t}\n}\n\nfunction terminateWorkers() {\n\tpool.forEach(workerData => {\n\t\tclearTerminateTimeout(workerData);\n\t\tworkerData.terminate();\n\t});\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst MINIMUM_CHUNK_SIZE = 64;\nconst ERR_ABORT = \"Abort error\";\n\nexport {\n\tERR_ABORT,\n\tprocessData\n};\n\nasync function processData(codec, reader, writer, offset, inputLengthGetter, config, options) {\n\tconst chunkSize = Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);\n\treturn processChunk();\n\n\tasync function processChunk(chunkOffset = 0, outputLength = 0) {\n\t\tconst signal = options.signal;\n\t\tconst inputLength = inputLengthGetter();\n\t\tif (chunkOffset < inputLength) {\n\t\t\ttestAborted(signal, codec);\n\t\t\tconst inputData = await reader.readUint8Array(chunkOffset + offset, Math.min(chunkSize, inputLength - chunkOffset));\n\t\t\tconst chunkLength = inputData.length;\n\t\t\ttestAborted(signal, codec);\n\t\t\tconst data = await codec.append(inputData);\n\t\t\ttestAborted(signal, codec);\n\t\t\toutputLength += await writeData(writer, data);\n\t\t\tif (options.onprogress) {\n\t\t\t\ttry {\n\t\t\t\t\toptions.onprogress(chunkOffset + chunkLength, inputLength);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// ignored\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn processChunk(chunkOffset + chunkSize, outputLength);\n\t\t} else {\n\t\t\tconst result = await codec.flush();\n\t\t\toutputLength += await writeData(writer, result.data);\n\t\t\treturn { signature: result.signature, length: outputLength };\n\t\t}\n\t}\n}\n\nfunction testAborted(signal, codec) {\n\tif (signal && signal.aborted) {\n\t\tcodec.abort();\n\t\tthrow new Error(ERR_ABORT);\n\t}\n}\n\nasync function writeData(writer, data) {\n\tif (data.length) {\n\t\tawait writer.writeUint8Array(data);\n\t}\n\treturn data.length;\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global Blob, FileReader, atob, btoa, XMLHttpRequest, document, fetch */\n\nconst ERR_HTTP_STATUS = \"HTTP error \";\nconst ERR_HTTP_RANGE = \"HTTP Range not supported\";\nconst ERR_NOT_SEEKABLE_READER = \"Reader is not seekable\";\n\nconst CONTENT_TYPE_TEXT_PLAIN = \"text/plain\";\nconst HTTP_HEADER_CONTENT_LENGTH = \"Content-Length\";\nconst HTTP_HEADER_CONTENT_RANGE = \"Content-Range\";\nconst HTTP_HEADER_ACCEPT_RANGES = \"Accept-Ranges\";\nconst HTTP_HEADER_RANGE = \"Range\";\nconst HTTP_METHOD_HEAD = \"HEAD\";\nconst HTTP_METHOD_GET = \"GET\";\nconst HTTP_RANGE_UNIT = \"bytes\";\n\nclass Stream {\n\n\tconstructor() {\n\t\tthis.size = 0;\n\t}\n\n\tinit() {\n\t\tthis.initialized = true;\n\t}\n}\n\nclass Reader extends Stream {\n}\n\nclass Writer extends Stream {\n\n\twriteUint8Array(array) {\n\t\tthis.size += array.length;\n\t}\n}\n\nclass TextReader extends Reader {\n\n\tconstructor(text) {\n\t\tsuper();\n\t\tthis.blobReader = new BlobReader(new Blob([text], { type: CONTENT_TYPE_TEXT_PLAIN }));\n\t}\n\n\tinit() {\n\t\tsuper.init();\n\t\tthis.blobReader.init();\n\t\tthis.size = this.blobReader.size;\n\t}\n\n\treadUint8Array(offset, length) {\n\t\treturn this.blobReader.readUint8Array(offset, length);\n\t}\n}\n\nclass TextWriter extends Writer {\n\n\tconstructor(encoding) {\n\t\tsuper();\n\t\tthis.encoding = encoding;\n\t\tthis.blob = new Blob([], { type: CONTENT_TYPE_TEXT_PLAIN });\n\t}\n\n\twriteUint8Array(array) {\n\t\tsuper.writeUint8Array(array);\n\t\tthis.blob = new Blob([this.blob, array.buffer], { type: CONTENT_TYPE_TEXT_PLAIN });\n\t}\n\n\tgetData() {\n\t\tif (this.blob.text) {\n\t\t\treturn this.blob.text();\n\t\t} else {\n\t\t\tconst reader = new FileReader();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\treader.onload = event => resolve(event.target.result);\n\t\t\t\treader.onerror = () => reject(reader.error);\n\t\t\t\treader.readAsText(this.blob, this.encoding);\n\t\t\t});\n\t\t}\n\t}\n}\n\nclass Data64URIReader extends Reader {\n\n\tconstructor(dataURI) {\n\t\tsuper();\n\t\tthis.dataURI = dataURI;\n\t\tlet dataEnd = dataURI.length;\n\t\twhile (dataURI.charAt(dataEnd - 1) == \"=\") {\n\t\t\tdataEnd--;\n\t\t}\n\t\tthis.dataStart = dataURI.indexOf(\",\") + 1;\n\t\tthis.size = Math.floor((dataEnd - this.dataStart) * 0.75);\n\t}\n\n\treadUint8Array(offset, length) {\n\t\tconst dataArray = new Uint8Array(length);\n\t\tconst start = Math.floor(offset / 3) * 4;\n\t\tconst bytes = atob(this.dataURI.substring(start + this.dataStart, Math.ceil((offset + length) / 3) * 4 + this.dataStart));\n\t\tconst delta = offset - Math.floor(start / 4) * 3;\n\t\tfor (let indexByte = delta; indexByte < delta + length; indexByte++) {\n\t\t\tdataArray[indexByte - delta] = bytes.charCodeAt(indexByte);\n\t\t}\n\t\treturn dataArray;\n\t}\n}\n\nclass Data64URIWriter extends Writer {\n\n\tconstructor(contentType) {\n\t\tsuper();\n\t\tthis.data = \"data:\" + (contentType || \"\") + \";base64,\";\n\t\tthis.pending = [];\n\t}\n\n\twriteUint8Array(array) {\n\t\tsuper.writeUint8Array(array);\n\t\tlet indexArray = 0;\n\t\tlet dataString = this.pending;\n\t\tconst delta = this.pending.length;\n\t\tthis.pending = \"\";\n\t\tfor (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {\n\t\t\tdataString += String.fromCharCode(array[indexArray]);\n\t\t}\n\t\tfor (; indexArray < array.length; indexArray++) {\n\t\t\tthis.pending += String.fromCharCode(array[indexArray]);\n\t\t}\n\t\tif (dataString.length > 2) {\n\t\t\tthis.data += btoa(dataString);\n\t\t} else {\n\t\t\tthis.pending = dataString;\n\t\t}\n\t}\n\n\tgetData() {\n\t\treturn this.data + btoa(this.pending);\n\t}\n}\n\nclass BlobReader extends Reader {\n\n\tconstructor(blob) {\n\t\tsuper();\n\t\tthis.blob = blob;\n\t\tthis.size = blob.size;\n\t}\n\n\tasync readUint8Array(offset, length) {\n\t\tif (this.blob.arrayBuffer) {\n\t\t\treturn new Uint8Array(await this.blob.slice(offset, offset + length).arrayBuffer());\n\t\t} else {\n\t\t\tconst reader = new FileReader();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\treader.onload = event => resolve(new Uint8Array(event.target.result));\n\t\t\t\treader.onerror = () => reject(reader.error);\n\t\t\t\treader.readAsArrayBuffer(this.blob.slice(offset, offset + length));\n\t\t\t});\n\t\t}\n\t}\n}\n\nclass BlobWriter extends Writer {\n\n\tconstructor(contentType) {\n\t\tsuper();\n\t\tthis.contentType = contentType;\n\t\tthis.arrayBuffersMaxlength = 8;\n\t\tinitArrayBuffers(this);\n\t}\n\n\twriteUint8Array(array) {\n\t\tsuper.writeUint8Array(array);\n\t\tif (this.arrayBuffers.length == this.arrayBuffersMaxlength) {\n\t\t\tflushArrayBuffers(this);\n\t\t}\n\t\tthis.arrayBuffers.push(array.buffer);\n\t}\n\n\tgetData() {\n\t\tif (!this.blob) {\n\t\t\tif (this.arrayBuffers.length) {\n\t\t\t\tflushArrayBuffers(this);\n\t\t\t}\n\t\t\tthis.blob = this.pendingBlob;\n\t\t\tinitArrayBuffers(this);\n\t\t}\n\t\treturn this.blob;\n\t}\n}\n\nfunction initArrayBuffers(blobWriter) {\n\tblobWriter.pendingBlob = new Blob([], { type: blobWriter.contentType });\n\tblobWriter.arrayBuffers = [];\n}\n\nfunction flushArrayBuffers(blobWriter) {\n\tblobWriter.pendingBlob = new Blob([blobWriter.pendingBlob, ...blobWriter.arrayBuffers], { type: blobWriter.contentType });\n\tblobWriter.arrayBuffers = [];\n}\n\nclass ReadableStreamReader {\n\n\tconstructor(readableStream) {\n\t\tthis.readableStream = readableStream;\n\t\tthis.reader = readableStream.getReader();\n\t\tthis.size = Infinity;\n\t\tthis.index = 0;\n\t\tthis.currentSize = 0;\n\t\tthis.pendingValue = new Uint8Array();\n\t}\n\n\tinit() {\n\t\tthis.initialized = true;\n\t}\n\n\tasync readUint8Array(index, length) {\n\t\tif (this.index != index) {\n\t\t\tthrow new Error(ERR_NOT_SEEKABLE_READER);\n\t\t}\n\t\tlet data = new Uint8Array(length);\n\t\tlet size = 0, done;\n\t\tdo {\n\t\t\tconst result = await this.reader.read();\n\t\t\tlet { value } = result;\n\t\t\tdone = result.done;\n\t\t\tif (value) {\n\t\t\t\tthis.currentSize += value.length;\n\t\t\t} else {\n\t\t\t\tvalue = this.pendingValue;\n\t\t\t\tthis.pendingValue = new Uint8Array();\n\t\t\t}\n\t\t\tif (this.pendingValue.length) {\n\t\t\t\tconst newValue = new Uint8Array(this.pendingValue.length + value.length);\n\t\t\t\tnewValue.set(this.pendingValue);\n\t\t\t\tnewValue.set(value, this.pendingValue.length);\n\t\t\t\tthis.pendingValue = new Uint8Array();\n\t\t\t\tvalue = newValue;\n\t\t\t}\n\t\t\tif (size + value.length > length) {\n\t\t\t\tdata.set(value.subarray(0, length), size);\n\t\t\t\tthis.pendingValue = value.subarray(length);\n\t\t\t\tsize += length;\n\t\t\t} else {\n\t\t\t\tdata.set(value, size);\n\t\t\t\tsize += value.length;\n\t\t\t}\n\t\t} while (size < length && !done);\n\t\tif (done && this.size == Infinity) {\n\t\t\tthis.size = this.currentSize;\n\t\t}\n\t\tif (this.size < length) {\n\t\t\tdata = data.slice(0, this.size);\n\t\t\tlength = this.size;\n\t\t}\n\t\tthis.index += length;\n\t\treturn data;\n\t}\n}\n\nclass WritableStreamWriter extends Writer {\n\n\tconstructor(writableStream) {\n\t\tsuper();\n\t\tthis.writableStream = writableStream;\n\t\tthis.writer = writableStream.getWriter();\n\t}\n\n\tasync writeUint8Array(array) {\n\t\tawait this.writer.ready;\n\t\treturn this.writer.write(array);\n\t}\n\n\tasync getData() {\n\t\tawait this.writer.ready;\n\t\tawait this.writer.close();\n\t\treturn this.writableStream;\n\t}\n}\n\nclass FetchReader extends Reader {\n\n\tconstructor(url, options) {\n\t\tsuper();\n\t\tthis.url = url;\n\t\tthis.preventHeadRequest = options.preventHeadRequest;\n\t\tthis.useRangeHeader = options.useRangeHeader;\n\t\tthis.forceRangeRequests = options.forceRangeRequests;\n\t\tthis.options = Object.assign({}, options);\n\t\tdelete this.options.preventHeadRequest;\n\t\tdelete this.options.useRangeHeader;\n\t\tdelete this.options.forceRangeRequests;\n\t\tdelete this.options.useXHR;\n\t}\n\n\tasync init() {\n\t\tsuper.init();\n\t\tawait initHttpReader(this, sendFetchRequest, getFetchRequestData);\n\t}\n\n\treadUint8Array(index, length) {\n\t\treturn readUint8ArrayHttpReader(this, index, length, sendFetchRequest, getFetchRequestData);\n\t}\n}\n\nclass XHRReader extends Reader {\n\n\tconstructor(url, options) {\n\t\tsuper();\n\t\tthis.url = url;\n\t\tthis.preventHeadRequest = options.preventHeadRequest;\n\t\tthis.useRangeHeader = options.useRangeHeader;\n\t\tthis.forceRangeRequests = options.forceRangeRequests;\n\t\tthis.options = options;\n\t}\n\n\tasync init() {\n\t\tsuper.init();\n\t\tawait initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);\n\t}\n\n\treadUint8Array(index, length) {\n\t\treturn readUint8ArrayHttpReader(this, index, length, sendXMLHttpRequest, getXMLHttpRequestData);\n\t}\n}\n\nasync function initHttpReader(httpReader, sendRequest, getRequestData) {\n\tif (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {\n\t\tconst response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));\n\t\tif (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {\n\t\t\tthrow new Error(ERR_HTTP_RANGE);\n\t\t} else {\n\t\t\tlet contentSize;\n\t\t\tconst contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);\n\t\t\tif (contentRangeHeader) {\n\t\t\t\tconst splitHeader = contentRangeHeader.trim().split(/\\s*\\/\\s*/);\n\t\t\t\tif (splitHeader.length) {\n\t\t\t\t\tconst headerValue = splitHeader[1];\n\t\t\t\t\tif (headerValue && headerValue != \"*\") {\n\t\t\t\t\t\tcontentSize = Number(headerValue);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (contentSize === undefined) {\n\t\t\t\tawait getContentLength(httpReader, sendRequest, getRequestData);\n\t\t\t} else {\n\t\t\t\thttpReader.size = contentSize;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tawait getContentLength(httpReader, sendRequest, getRequestData);\n\t}\n}\n\nasync function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {\n\tif (httpReader.useRangeHeader || httpReader.forceRangeRequests) {\n\t\tconst response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));\n\t\tif (response.status != 206) {\n\t\t\tthrow new Error(ERR_HTTP_RANGE);\n\t\t}\n\t\treturn new Uint8Array(await response.arrayBuffer());\n\t} else {\n\t\tif (!httpReader.data) {\n\t\t\tawait getRequestData(httpReader, httpReader.options);\n\t\t}\n\t\treturn new Uint8Array(httpReader.data.subarray(index, index + length));\n\t}\n}\n\nfunction getRangeHeaders(httpReader, index = 0, length = 1) {\n\treturn Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + \"=\" + index + \"-\" + (index + length - 1) });\n}\n\nfunction getHeaders(httpReader) {\n\tconst headers = httpReader.options.headers;\n\tif (headers) {\n\t\tif (Symbol.iterator in headers) {\n\t\t\treturn Object.fromEntries(headers);\n\t\t} else {\n\t\t\treturn headers;\n\t\t}\n\t}\n}\n\nasync function getFetchRequestData(httpReader) {\n\tawait getRequestData(httpReader, sendFetchRequest);\n}\n\nasync function getXMLHttpRequestData(httpReader) {\n\tawait getRequestData(httpReader, sendXMLHttpRequest);\n}\n\nasync function getRequestData(httpReader, sendRequest) {\n\tconst response = await sendRequest(HTTP_METHOD_GET, httpReader, getHeaders(httpReader));\n\thttpReader.data = new Uint8Array(await response.arrayBuffer());\n\tif (!httpReader.size) {\n\t\thttpReader.size = httpReader.data.length;\n\t}\n}\n\nasync function getContentLength(httpReader, sendRequest, getRequestData) {\n\tif (httpReader.preventHeadRequest) {\n\t\tawait getRequestData(httpReader, httpReader.options);\n\t} else {\n\t\tconst response = await sendRequest(HTTP_METHOD_HEAD, httpReader, getHeaders(httpReader));\n\t\tconst contentLength = response.headers.get(HTTP_HEADER_CONTENT_LENGTH);\n\t\tif (contentLength) {\n\t\t\thttpReader.size = Number(contentLength);\n\t\t} else {\n\t\t\tawait getRequestData(httpReader, httpReader.options);\n\t\t}\n\t}\n}\n\nasync function sendFetchRequest(method, { options, url }, headers) {\n\tconst response = await fetch(url, Object.assign({}, options, { method, headers }));\n\tif (response.status < 400) {\n\t\treturn response;\n\t} else {\n\t\tthrow new Error(ERR_HTTP_STATUS + (response.statusText || response.status));\n\t}\n}\n\nfunction sendXMLHttpRequest(method, { url }, headers) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst request = new XMLHttpRequest();\n\t\trequest.addEventListener(\"load\", () => {\n\t\t\tif (request.status < 400) {\n\t\t\t\tconst headers = [];\n\t\t\t\trequest.getAllResponseHeaders().trim().split(/[\\r\\n]+/).forEach(header => {\n\t\t\t\t\tconst splitHeader = header.trim().split(/\\s*:\\s*/);\n\t\t\t\t\tsplitHeader[0] = splitHeader[0].trim().replace(/^[a-z]|-[a-z]/g, value => value.toUpperCase());\n\t\t\t\t\theaders.push(splitHeader);\n\t\t\t\t});\n\t\t\t\tresolve({\n\t\t\t\t\tstatus: request.status,\n\t\t\t\t\tarrayBuffer: () => request.response,\n\t\t\t\t\theaders: new Map(headers)\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treject(new Error(ERR_HTTP_STATUS + (request.statusText || request.status)));\n\t\t\t}\n\t\t}, false);\n\t\trequest.addEventListener(\"error\", event => reject(event.detail.error), false);\n\t\trequest.open(method, url);\n\t\tif (headers) {\n\t\t\tfor (const entry of Object.entries(headers)) {\n\t\t\t\trequest.setRequestHeader(entry[0], entry[1]);\n\t\t\t}\n\t\t}\n\t\trequest.responseType = \"arraybuffer\";\n\t\trequest.send();\n\t});\n}\n\nclass HttpReader extends Reader {\n\n\tconstructor(url, options = {}) {\n\t\tsuper();\n\t\tthis.url = url;\n\t\tif (options.useXHR) {\n\t\t\tthis.reader = new XHRReader(url, options);\n\t\t} else {\n\t\t\tthis.reader = new FetchReader(url, options);\n\t\t}\n\t}\n\n\tset size(value) {\n\t\t// ignored\n\t}\n\n\tget size() {\n\t\treturn this.reader.size;\n\t}\n\n\tasync init() {\n\t\tsuper.init();\n\t\tawait this.reader.init();\n\t}\n\n\treadUint8Array(index, length) {\n\t\treturn this.reader.readUint8Array(index, length);\n\t}\n}\n\nclass HttpRangeReader extends HttpReader {\n\n\tconstructor(url, options = {}) {\n\t\toptions.useRangeHeader = true;\n\t\tsuper(url, options);\n\t}\n}\n\n\nclass Uint8ArrayReader extends Reader {\n\n\tconstructor(array) {\n\t\tsuper();\n\t\tthis.array = array;\n\t\tthis.size = array.length;\n\t}\n\n\treadUint8Array(index, length) {\n\t\treturn this.array.slice(index, index + length);\n\t}\n}\n\nclass Uint8ArrayWriter extends Writer {\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.array = new Uint8Array(0);\n\t}\n\n\twriteUint8Array(array) {\n\t\tsuper.writeUint8Array(array);\n\t\tconst previousArray = this.array;\n\t\tthis.array = new Uint8Array(previousArray.length + array.length);\n\t\tthis.array.set(previousArray);\n\t\tthis.array.set(array, previousArray.length);\n\t}\n\n\tgetData() {\n\t\treturn this.array;\n\t}\n}\n\nfunction isHttpFamily(url) {\n\tif (typeof document != \"undefined\") {\n\t\tconst anchor = document.createElement(\"a\");\n\t\tanchor.href = url;\n\t\treturn anchor.protocol == \"http:\" || anchor.protocol == \"https:\";\n\t} else {\n\t\treturn /^https?:\\/\\//i.test(url);\n\t}\n}\n\nexport {\n\tReader,\n\tWriter,\n\tTextReader,\n\tTextWriter,\n\tData64URIReader,\n\tData64URIWriter,\n\tBlobReader,\n\tBlobWriter,\n\tUint8ArrayReader,\n\tUint8ArrayWriter,\n\tHttpReader,\n\tHttpRangeReader,\n\tReadableStreamReader,\n\tWritableStreamWriter,\n\tERR_HTTP_RANGE,\n\tERR_NOT_SEEKABLE_READER\n};\n", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst MAX_32_BITS = 0xffffffff;\nconst MAX_16_BITS = 0xffff;\nconst COMPRESSION_METHOD_DEFLATE = 0x08;\nconst COMPRESSION_METHOD_STORE = 0x00;\nconst COMPRESSION_METHOD_AES = 0x63;\n\nconst LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;\nconst DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;\nconst CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;\nconst END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;\nconst ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;\nconst ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;\nconst END_OF_CENTRAL_DIR_LENGTH = 22;\nconst ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;\nconst ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;\nconst ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;\n\nconst ZIP64_TOTAL_NUMBER_OF_DISKS = 1;\n\nconst EXTRAFIELD_TYPE_ZIP64 = 0x0001;\nconst EXTRAFIELD_TYPE_AES = 0x9901;\nconst EXTRAFIELD_TYPE_NTFS = 0x000a;\nconst EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;\nconst EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;\nconst EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;\nconst EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;\n\nconst BITFLAG_ENCRYPTED = 0x01;\nconst BITFLAG_LEVEL = 0x06;\nconst BITFLAG_DATA_DESCRIPTOR = 0x0008;\nconst BITFLAG_LANG_ENCODING_FLAG = 0x0800;\nconst FILE_ATTR_MSDOS_DIR_MASK = 0x10;\n\nconst VERSION_DEFLATE = 0x14;\nconst VERSION_ZIP64 = 0x2D;\nconst VERSION_AES = 0x33;\n\nconst DIRECTORY_SIGNATURE = \"/\";\n\nconst MAX_DATE = new Date(2107, 11, 31);\nconst MIN_DATE = new Date(1980, 0, 1);\n\nexport {\n\tMAX_32_BITS,\n\tMAX_16_BITS,\n\tCOMPRESSION_METHOD_DEFLATE,\n\tCOMPRESSION_METHOD_STORE,\n\tCOMPRESSION_METHOD_AES,\n\tLOCAL_FILE_HEADER_SIGNATURE,\n\tDATA_DESCRIPTOR_RECORD_SIGNATURE,\n\tCENTRAL_FILE_HEADER_SIGNATURE,\n\tEND_OF_CENTRAL_DIR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_SIGNATURE,\n\tEXTRAFIELD_TYPE_ZIP64,\n\tEXTRAFIELD_TYPE_AES,\n\tEXTRAFIELD_TYPE_NTFS,\n\tEXTRAFIELD_TYPE_NTFS_TAG1,\n\tEXTRAFIELD_TYPE_EXTENDED_TIMESTAMP,\n\tEXTRAFIELD_TYPE_UNICODE_PATH,\n\tEXTRAFIELD_TYPE_UNICODE_COMMENT,\n\tEND_OF_CENTRAL_DIR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH,\n\tZIP64_TOTAL_NUMBER_OF_DISKS,\n\tBITFLAG_ENCRYPTED,\n\tBITFLAG_LEVEL,\n\tBITFLAG_DATA_DESCRIPTOR,\n\tBITFLAG_LANG_ENCODING_FLAG,\n\tFILE_ATTR_MSDOS_DIR_MASK,\n\tVERSION_DEFLATE,\n\tVERSION_ZIP64,\n\tVERSION_AES,\n\tDIRECTORY_SIGNATURE,\n\tMIN_DATE,\n\tMAX_DATE\n};", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst CP437 = \"\\0\u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\u00B6\u00A7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00C7\u00FC\u00E9\u00E2\u00E4\u00E0\u00E5\u00E7\u00EA\u00EB\u00E8\u00EF\u00EE\u00EC\u00C4\u00C5\u00C9\u00E6\u00C6\u00F4\u00F6\u00F2\u00FB\u00F9\u00FF\u00D6\u00DC\u00A2\u00A3\u00A5\u20A7\u0192\u00E1\u00ED\u00F3\u00FA\u00F1\u00D1\u00AA\u00BA\u00BF\u2310\u00AC\u00BD\u00BC\u00A1\u00AB\u00BB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\u00DF\u0393\u03C0\u03A3\u03C3\u00B5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\u00B1\u2265\u2264\u2320\u2321\u00F7\u2248\u00B0\u2219\u00B7\u221A\u207F\u00B2\u25A0 \".split(\"\");\n\nexport default stringValue => {\n\tlet result = \"\";\n\tfor (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {\n\t\tresult += CP437[stringValue[indexCharacter]];\n\t}\n\treturn result;\n};", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global TextDecoder, FileReader, Blob */\n\nimport decodeCP437 from \"./cp437-decode.js\";\n\nexport default decodeText;\n\nfunction decodeText(value, encoding) {\n\tif (encoding && encoding.trim().toLowerCase() == \"cp437\") {\n\t\treturn decodeCP437(value);\n\t} else if (typeof TextDecoder == \"undefined\") {\n\t\tconst fileReader = new FileReader();\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tfileReader.onload = event => resolve(event.target.result);\n\t\t\tfileReader.onerror = () => reject(fileReader.error);\n\t\t\tfileReader.readAsText(new Blob([value]));\n\t\t});\n\t} else {\n\t\treturn new TextDecoder(encoding).decode(value);\n\t}\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nconst PROPERTY_NAMES = [\n\t\"filename\", \"rawFilename\", \"directory\", \"encrypted\", \"compressedSize\", \"uncompressedSize\",\n\t\"lastModDate\", \"rawLastModDate\", \"comment\", \"rawComment\", \"signature\", \"extraField\",\n\t\"rawExtraField\", \"bitFlag\", \"extraFieldZip64\", \"extraFieldUnicodePath\", \"extraFieldUnicodeComment\",\n\t\"extraFieldAES\", \"filenameUTF8\", \"commentUTF8\", \"offset\", \"zip64\", \"compressionMethod\",\n\t\"extraFieldNTFS\", \"lastAccessDate\", \"creationDate\", \"extraFieldExtendedTimestamp\",\n\t\"version\", \"versionMadeBy\", \"msDosCompatible\", \"internalFileAttribute\", \"externalFileAttribute\"];\n\nexport default class Entry {\n\n\tconstructor(data) {\n\t\tPROPERTY_NAMES.forEach(name => this[name] = data[name]);\n\t}\n\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global BigInt */\n\nimport {\n\tMAX_32_BITS,\n\tMAX_16_BITS,\n\tCOMPRESSION_METHOD_DEFLATE,\n\tCOMPRESSION_METHOD_STORE,\n\tCOMPRESSION_METHOD_AES,\n\tLOCAL_FILE_HEADER_SIGNATURE,\n\tCENTRAL_FILE_HEADER_SIGNATURE,\n\tEND_OF_CENTRAL_DIR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_SIGNATURE,\n\tEXTRAFIELD_TYPE_ZIP64,\n\tEXTRAFIELD_TYPE_UNICODE_PATH,\n\tEXTRAFIELD_TYPE_UNICODE_COMMENT,\n\tEXTRAFIELD_TYPE_AES,\n\tEXTRAFIELD_TYPE_NTFS,\n\tEXTRAFIELD_TYPE_NTFS_TAG1,\n\tEXTRAFIELD_TYPE_EXTENDED_TIMESTAMP,\n\tEND_OF_CENTRAL_DIR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_LENGTH,\n\tBITFLAG_ENCRYPTED,\n\tBITFLAG_LEVEL,\n\tBITFLAG_DATA_DESCRIPTOR,\n\tBITFLAG_LANG_ENCODING_FLAG,\n\tFILE_ATTR_MSDOS_DIR_MASK,\n\tDIRECTORY_SIGNATURE\n} from \"./constants.js\";\nimport { getConfiguration } from \"./configuration.js\";\nimport { createCodec, CODEC_INFLATE, ERR_INVALID_SIGNATURE, ERR_INVALID_PASSWORD } from \"./codecs/codec-pool.js\";\nimport decodeText from \"./util/decode-text.js\";\nimport Crc32 from \"./codecs/crc32.js\";\nimport { processData } from \"./engine.js\";\nimport Entry from \"./zip-entry.js\";\n\nconst ERR_BAD_FORMAT = \"File format is not recognized\";\nconst ERR_EOCDR_NOT_FOUND = \"End of central directory not found\";\nconst ERR_EOCDR_ZIP64_NOT_FOUND = \"End of Zip64 central directory not found\";\nconst ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = \"End of Zip64 central directory locator not found\";\nconst ERR_CENTRAL_DIRECTORY_NOT_FOUND = \"Central directory header not found\";\nconst ERR_LOCAL_FILE_HEADER_NOT_FOUND = \"Local file header not found\";\nconst ERR_EXTRAFIELD_ZIP64_NOT_FOUND = \"Zip64 extra field not found\";\nconst ERR_ENCRYPTED = \"File contains encrypted entry\";\nconst ERR_UNSUPPORTED_ENCRYPTION = \"Encryption method not supported\";\nconst ERR_UNSUPPORTED_COMPRESSION = \"Compression method not supported\";\nconst CHARSET_UTF8 = \"utf-8\";\nconst CHARSET_CP437 = \"cp437\";\nconst ZIP64_PROPERTIES = [\"uncompressedSize\", \"compressedSize\", \"offset\"];\n\nclass ZipReader {\n\n\tconstructor(reader, options = {}) {\n\t\tObject.assign(this, {\n\t\t\treader,\n\t\t\toptions,\n\t\t\tconfig: getConfiguration()\n\t\t});\n\t}\n\n\tasync* getEntriesGenerator(options = {}) {\n\t\tconst zipReader = this;\n\t\tconst reader = zipReader.reader;\n\t\tif (!reader.initialized) {\n\t\t\tawait reader.init();\n\t\t}\n\t\tif (reader.size < END_OF_CENTRAL_DIR_LENGTH) {\n\t\t\tthrow new Error(ERR_BAD_FORMAT);\n\t\t}\n\t\tconst endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);\n\t\tif (!endOfDirectoryInfo) {\n\t\t\tthrow new Error(ERR_EOCDR_NOT_FOUND);\n\t\t}\n\t\tconst endOfDirectoryView = getDataView(endOfDirectoryInfo);\n\t\tlet directoryDataLength = getUint32(endOfDirectoryView, 12);\n\t\tlet directoryDataOffset = getUint32(endOfDirectoryView, 16);\n\t\tlet filesLength = getUint16(endOfDirectoryView, 8);\n\t\tlet prependedDataLength = 0;\n\t\tif (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) {\n\t\t\tconst endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);\n\t\t\tconst endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);\n\t\t\tif (getUint32(endOfDirectoryLocatorView, 0) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {\n\t\t\t\tthrow new Error(ERR_EOCDR_ZIP64_NOT_FOUND);\n\t\t\t}\n\t\t\tdirectoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);\n\t\t\tlet endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);\n\t\t\tlet endOfDirectoryView = getDataView(endOfDirectoryArray);\n\t\t\tconst expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;\n\t\t\tif (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {\n\t\t\t\tconst originalDirectoryDataOffset = directoryDataOffset;\n\t\t\t\tdirectoryDataOffset = expectedDirectoryDataOffset;\n\t\t\t\tprependedDataLength = directoryDataOffset - originalDirectoryDataOffset;\n\t\t\t\tendOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);\n\t\t\t\tendOfDirectoryView = getDataView(endOfDirectoryArray);\n\t\t\t}\n\t\t\tif (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {\n\t\t\t\tthrow new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);\n\t\t\t}\n\t\t\tfilesLength = getBigUint64(endOfDirectoryView, 32);\n\t\t\tdirectoryDataLength = getBigUint64(endOfDirectoryView, 40);\n\t\t\tdirectoryDataOffset -= directoryDataLength;\n\t\t}\n\t\tif (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {\n\t\t\tthrow new Error(ERR_BAD_FORMAT);\n\t\t}\n\t\tlet offset = 0;\n\t\tlet directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);\n\t\tlet directoryView = getDataView(directoryArray);\n\t\tif (directoryDataLength) {\n\t\t\tconst expectedDirectoryDataOffset = endOfDirectoryInfo.offset - directoryDataLength;\n\t\t\tif (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {\n\t\t\t\tconst originalDirectoryDataOffset = directoryDataOffset;\n\t\t\t\tdirectoryDataOffset = expectedDirectoryDataOffset;\n\t\t\t\tprependedDataLength = directoryDataOffset - originalDirectoryDataOffset;\n\t\t\t\tdirectoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);\n\t\t\t\tdirectoryView = getDataView(directoryArray);\n\t\t\t}\n\t\t}\n\t\tif (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {\n\t\t\tthrow new Error(ERR_BAD_FORMAT);\n\t\t}\n\t\tfor (let indexFile = 0; indexFile < filesLength; indexFile++) {\n\t\t\tconst fileEntry = new ZipEntry(reader, zipReader.config, zipReader.options);\n\t\t\tif (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {\n\t\t\t\tthrow new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);\n\t\t\t}\n\t\t\treadCommonHeader(fileEntry, directoryView, offset + 6);\n\t\t\tconst languageEncodingFlag = Boolean(fileEntry.bitFlag.languageEncodingFlag);\n\t\t\tconst filenameOffset = offset + 46;\n\t\t\tconst extraFieldOffset = filenameOffset + fileEntry.filenameLength;\n\t\t\tconst commentOffset = extraFieldOffset + fileEntry.extraFieldLength;\n\t\t\tconst versionMadeBy = getUint16(directoryView, offset + 4);\n\t\t\tconst msDosCompatible = (versionMadeBy & 0) == 0;\n\t\t\tObject.assign(fileEntry, {\n\t\t\t\tversionMadeBy,\n\t\t\t\tmsDosCompatible,\n\t\t\t\tcompressedSize: 0,\n\t\t\t\tuncompressedSize: 0,\n\t\t\t\tcommentLength: getUint16(directoryView, offset + 32),\n\t\t\t\tdirectory: msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK),\n\t\t\t\toffset: getUint32(directoryView, offset + 42) + prependedDataLength,\n\t\t\t\tinternalFileAttribute: getUint32(directoryView, offset + 34),\n\t\t\t\texternalFileAttribute: getUint32(directoryView, offset + 38),\n\t\t\t\trawFilename: directoryArray.subarray(filenameOffset, extraFieldOffset),\n\t\t\t\tfilenameUTF8: languageEncodingFlag,\n\t\t\t\tcommentUTF8: languageEncodingFlag,\n\t\t\t\trawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)\n\t\t\t});\n\t\t\tconst endOffset = commentOffset + fileEntry.commentLength;\n\t\t\tfileEntry.rawComment = directoryArray.subarray(commentOffset, endOffset);\n\t\t\tconst filenameEncoding = getOptionValue(zipReader, options, \"filenameEncoding\");\n\t\t\tconst commentEncoding = getOptionValue(zipReader, options, \"commentEncoding\");\n\t\t\tconst [filename, comment] = await Promise.all([\n\t\t\t\tdecodeText(fileEntry.rawFilename, fileEntry.filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),\n\t\t\t\tdecodeText(fileEntry.rawComment, fileEntry.commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)\n\t\t\t]);\n\t\t\tfileEntry.filename = filename;\n\t\t\tfileEntry.comment = comment;\n\t\t\tif (!fileEntry.directory && fileEntry.filename.endsWith(DIRECTORY_SIGNATURE)) {\n\t\t\t\tfileEntry.directory = true;\n\t\t\t}\n\t\t\tawait readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);\n\t\t\tconst entry = new Entry(fileEntry);\n\t\t\tentry.getData = (writer, options) => fileEntry.getData(writer, entry, options);\n\t\t\toffset = endOffset;\n\t\t\tif (options.onprogress) {\n\t\t\t\ttry {\n\t\t\t\t\toptions.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));\n\t\t\t\t} catch (_error) {\n\t\t\t\t\t// ignored\n\t\t\t\t}\n\t\t\t}\n\t\t\tyield entry;\n\t\t}\n\t\treturn true;\n\t}\n\n\tasync getEntries(options = {}) {\n\t\tconst entries = [];\n\t\tconst iter = this.getEntriesGenerator(options);\n\t\tlet curr = iter.next();\n\t\twhile(!(await curr).done) {\n\t\t\tentries.push((await curr).value);\n\t\t\tcurr = iter.next();\n\t\t}\n\t\treturn entries;\n\t}\n\n\tasync close() {\n\t}\n}\n\nexport {\n\tZipReader,\n\tERR_BAD_FORMAT,\n\tERR_EOCDR_NOT_FOUND,\n\tERR_EOCDR_ZIP64_NOT_FOUND,\n\tERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,\n\tERR_CENTRAL_DIRECTORY_NOT_FOUND,\n\tERR_LOCAL_FILE_HEADER_NOT_FOUND,\n\tERR_EXTRAFIELD_ZIP64_NOT_FOUND,\n\tERR_ENCRYPTED,\n\tERR_UNSUPPORTED_ENCRYPTION,\n\tERR_UNSUPPORTED_COMPRESSION,\n\tERR_INVALID_SIGNATURE,\n\tERR_INVALID_PASSWORD\n};\n\nclass ZipEntry {\n\n\tconstructor(reader, config, options) {\n\t\tObject.assign(this, {\n\t\t\treader,\n\t\t\tconfig,\n\t\t\toptions\n\t\t});\n\t}\n\n\tasync getData(writer, fileEntry, options = {}) {\n\t\tconst zipEntry = this;\n\t\tconst {\n\t\t\treader,\n\t\t\toffset,\n\t\t\textraFieldAES,\n\t\t\tcompressionMethod,\n\t\t\tconfig,\n\t\t\tbitFlag,\n\t\t\tsignature,\n\t\t\trawLastModDate,\n\t\t\tcompressedSize\n\t\t} = zipEntry;\n\t\tconst localDirectory = zipEntry.localDirectory = {};\n\t\tif (!reader.initialized) {\n\t\t\tawait reader.init();\n\t\t}\n\t\tlet dataArray = await readUint8Array(reader, offset, 30);\n\t\tconst dataView = getDataView(dataArray);\n\t\tlet password = getOptionValue(zipEntry, options, \"password\");\n\t\tpassword = password && password.length && password;\n\t\tif (extraFieldAES) {\n\t\t\tif (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {\n\t\t\t\tthrow new Error(ERR_UNSUPPORTED_COMPRESSION);\n\t\t\t}\n\t\t}\n\t\tif (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {\n\t\t\tthrow new Error(ERR_UNSUPPORTED_COMPRESSION);\n\t\t}\n\t\tif (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {\n\t\t\tthrow new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);\n\t\t}\n\t\treadCommonHeader(localDirectory, dataView, 4);\n\t\tdataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength);\n\t\tlocalDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);\n\t\tawait readCommonFooter(zipEntry, localDirectory, dataView, 4);\n\t\tfileEntry.lastAccessDate = localDirectory.lastAccessDate;\n\t\tfileEntry.creationDate = localDirectory.creationDate;\n\t\tconst encrypted = zipEntry.encrypted && localDirectory.encrypted;\n\t\tconst zipCrypto = encrypted && !extraFieldAES;\n\t\tif (encrypted) {\n\t\t\tif (!zipCrypto && extraFieldAES.strength === undefined) {\n\t\t\t\tthrow new Error(ERR_UNSUPPORTED_ENCRYPTION);\n\t\t\t} else if (!password) {\n\t\t\t\tthrow new Error(ERR_ENCRYPTED);\n\t\t\t}\n\t\t}\n\t\tconst codec = await createCodec(config.Inflate, {\n\t\t\tcodecType: CODEC_INFLATE,\n\t\t\tpassword,\n\t\t\tzipCrypto,\n\t\t\tencryptionStrength: extraFieldAES && extraFieldAES.strength,\n\t\t\tsigned: getOptionValue(zipEntry, options, \"checkSignature\"),\n\t\t\tpasswordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),\n\t\t\tsignature,\n\t\t\tcompressed: compressionMethod != 0,\n\t\t\tencrypted,\n\t\t\tuseWebWorkers: getOptionValue(zipEntry, options, \"useWebWorkers\")\n\t\t}, config);\n\t\tif (!writer.initialized) {\n\t\t\tawait writer.init();\n\t\t}\n\t\tconst signal = getOptionValue(zipEntry, options, \"signal\");\n\t\tconst dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;\n\t\tawait processData(codec, reader, writer, dataOffset, () => compressedSize, config, { onprogress: options.onprogress, signal });\n\t\treturn writer.getData();\n\t}\n}\n\nfunction readCommonHeader(directory, dataView, offset) {\n\tconst rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);\n\tconst encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;\n\tconst rawLastModDate = getUint32(dataView, offset + 6);\n\tObject.assign(directory, {\n\t\tencrypted,\n\t\tversion: getUint16(dataView, offset),\n\t\tbitFlag: {\n\t\t\tlevel: (rawBitFlag & BITFLAG_LEVEL) >> 1,\n\t\t\tdataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,\n\t\t\tlanguageEncodingFlag: (rawBitFlag & BITFLAG_LANG_ENCODING_FLAG) == BITFLAG_LANG_ENCODING_FLAG\n\t\t},\n\t\trawLastModDate,\n\t\tlastModDate: getDate(rawLastModDate),\n\t\tfilenameLength: getUint16(dataView, offset + 22),\n\t\textraFieldLength: getUint16(dataView, offset + 24)\n\t});\n}\n\nasync function readCommonFooter(fileEntry, directory, dataView, offset) {\n\tconst rawExtraField = directory.rawExtraField;\n\tconst extraField = directory.extraField = new Map();\n\tconst rawExtraFieldView = getDataView(new Uint8Array(rawExtraField));\n\tlet offsetExtraField = 0;\n\ttry {\n\t\twhile (offsetExtraField < rawExtraField.length) {\n\t\t\tconst type = getUint16(rawExtraFieldView, offsetExtraField);\n\t\t\tconst size = getUint16(rawExtraFieldView, offsetExtraField + 2);\n\t\t\textraField.set(type, {\n\t\t\t\ttype,\n\t\t\t\tdata: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)\n\t\t\t});\n\t\t\toffsetExtraField += 4 + size;\n\t\t}\n\t} catch (_error) {\n\t\t// ignored\n\t}\n\tconst compressionMethod = getUint16(dataView, offset + 4);\n\tdirectory.signature = getUint32(dataView, offset + 10);\n\tdirectory.uncompressedSize = getUint32(dataView, offset + 18);\n\tdirectory.compressedSize = getUint32(dataView, offset + 14);\n\tconst extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);\n\tif (extraFieldZip64) {\n\t\treadExtraFieldZip64(extraFieldZip64, directory);\n\t\tdirectory.extraFieldZip64 = extraFieldZip64;\n\t}\n\tconst extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);\n\tif (extraFieldUnicodePath) {\n\t\tawait readExtraFieldUnicode(extraFieldUnicodePath, \"filename\", \"rawFilename\", directory, fileEntry);\n\t\tdirectory.extraFieldUnicodePath = extraFieldUnicodePath;\n\t}\n\tconst extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);\n\tif (extraFieldUnicodeComment) {\n\t\tawait readExtraFieldUnicode(extraFieldUnicodeComment, \"comment\", \"rawComment\", directory, fileEntry);\n\t\tdirectory.extraFieldUnicodeComment = extraFieldUnicodeComment;\n\t}\n\tconst extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);\n\tif (extraFieldAES) {\n\t\treadExtraFieldAES(extraFieldAES, directory, compressionMethod);\n\t\tdirectory.extraFieldAES = extraFieldAES;\n\t} else {\n\t\tdirectory.compressionMethod = compressionMethod;\n\t}\n\tconst extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);\n\tif (extraFieldNTFS) {\n\t\treadExtraFieldNTFS(extraFieldNTFS, directory);\n\t\tdirectory.extraFieldNTFS = extraFieldNTFS;\n\t}\n\tconst extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);\n\tif (extraFieldExtendedTimestamp) {\n\t\treadExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory);\n\t\tdirectory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;\n\t}\n}\n\nfunction readExtraFieldZip64(extraFieldZip64, directory) {\n\tdirectory.zip64 = true;\n\tconst extraFieldView = getDataView(extraFieldZip64.data);\n\textraFieldZip64.values = [];\n\tfor (let indexValue = 0; indexValue < Math.floor(extraFieldZip64.data.length / 8); indexValue++) {\n\t\textraFieldZip64.values.push(getBigUint64(extraFieldView, 0 + indexValue * 8));\n\t}\n\tconst missingProperties = ZIP64_PROPERTIES.filter(propertyName => directory[propertyName] == MAX_32_BITS);\n\tfor (let indexMissingProperty = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {\n\t\textraFieldZip64[missingProperties[indexMissingProperty]] = extraFieldZip64.values[indexMissingProperty];\n\t}\n\tZIP64_PROPERTIES.forEach(propertyName => {\n\t\tif (directory[propertyName] == MAX_32_BITS) {\n\t\t\tif (extraFieldZip64[propertyName] !== undefined) {\n\t\t\t\tdirectory[propertyName] = extraFieldZip64[propertyName];\n\t\t\t} else {\n\t\t\t\tthrow new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);\n\t\t\t}\n\t\t}\n\t});\n}\n\nasync function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {\n\tconst extraFieldView = getDataView(extraFieldUnicode.data);\n\textraFieldUnicode.version = getUint8(extraFieldView, 0);\n\textraFieldUnicode.signature = getUint32(extraFieldView, 1);\n\tconst crc32 = new Crc32();\n\tcrc32.append(fileEntry[rawPropertyName]);\n\tconst dataViewSignature = getDataView(new Uint8Array(4));\n\tdataViewSignature.setUint32(0, crc32.get(), true);\n\textraFieldUnicode[propertyName] = await decodeText(extraFieldUnicode.data.subarray(5));\n\textraFieldUnicode.valid = !fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0);\n\tif (extraFieldUnicode.valid) {\n\t\tdirectory[propertyName] = extraFieldUnicode[propertyName];\n\t\tdirectory[propertyName + \"UTF8\"] = true;\n\t}\n}\n\nfunction readExtraFieldAES(extraFieldAES, directory, compressionMethod) {\n\tconst extraFieldView = getDataView(extraFieldAES.data);\n\textraFieldAES.vendorVersion = getUint8(extraFieldView, 0);\n\textraFieldAES.vendorId = getUint8(extraFieldView, 2);\n\tconst strength = getUint8(extraFieldView, 4);\n\textraFieldAES.strength = strength;\n\textraFieldAES.originalCompressionMethod = compressionMethod;\n\tdirectory.compressionMethod = extraFieldAES.compressionMethod = getUint16(extraFieldView, 5);\n}\n\nfunction readExtraFieldNTFS(extraFieldNTFS, directory) {\n\tconst extraFieldView = getDataView(extraFieldNTFS.data);\n\tlet offsetExtraField = 4;\n\tlet tag1Data;\n\ttry {\n\t\twhile (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {\n\t\t\tconst tagValue = getUint16(extraFieldView, offsetExtraField);\n\t\t\tconst attributeSize = getUint16(extraFieldView, offsetExtraField + 2);\n\t\t\tif (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {\n\t\t\t\ttag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);\n\t\t\t}\n\t\t\toffsetExtraField += 4 + attributeSize;\n\t\t}\n\t} catch (_error) {\n\t\t// ignored\n\t}\n\ttry {\n\t\tif (tag1Data && tag1Data.length == 24) {\n\t\t\tconst tag1View = getDataView(tag1Data);\n\t\t\tconst rawLastModDate = tag1View.getBigUint64(0, true);\n\t\t\tconst rawLastAccessDate = tag1View.getBigUint64(8, true);\n\t\t\tconst rawCreationDate = tag1View.getBigUint64(16, true);\n\t\t\tObject.assign(extraFieldNTFS, {\n\t\t\t\trawLastModDate,\n\t\t\t\trawLastAccessDate,\n\t\t\t\trawCreationDate\n\t\t\t});\n\t\t\tconst lastModDate = getDateNTFS(rawLastModDate);\n\t\t\tconst lastAccessDate = getDateNTFS(rawLastAccessDate);\n\t\t\tconst creationDate = getDateNTFS(rawCreationDate);\n\t\t\tconst extraFieldData = { lastModDate, lastAccessDate, creationDate };\n\t\t\tObject.assign(extraFieldNTFS, extraFieldData);\n\t\t\tObject.assign(directory, extraFieldData);\n\t\t}\n\t} catch (_error) {\n\t\t// ignored\n\t}\n}\n\nfunction readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory) {\n\tconst extraFieldView = getDataView(extraFieldExtendedTimestamp.data);\n\tconst flags = getUint8(extraFieldView, 0);\n\tconst timeProperties = [];\n\tconst timeRawProperties = [];\n\tif ((flags & 0x1) == 0x1) {\n\t\ttimeProperties.push(\"lastModDate\");\n\t\ttimeRawProperties.push(\"rawLastModDate\");\n\t}\n\tif ((flags & 0x2) == 0x2) {\n\t\ttimeProperties.push(\"lastAccessDate\");\n\t\ttimeRawProperties.push(\"rawLastAccessDate\");\n\t}\n\tif ((flags & 0x4) == 0x4) {\n\t\ttimeProperties.push(\"creationDate\");\n\t\ttimeRawProperties.push(\"rawCreationDate\");\n\t}\n\tlet offset = 1;\n\ttimeProperties.forEach((propertyName, indexProperty) => {\n\t\tif (extraFieldExtendedTimestamp.data.length >= offset + 4) {\n\t\t\tconst time = getUint32(extraFieldView, offset);\n\t\t\tdirectory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date(time * 1000);\n\t\t\tconst rawPropertyName = timeRawProperties[indexProperty];\n\t\t\textraFieldExtendedTimestamp[rawPropertyName] = time;\n\t\t}\n\t\toffset += 4;\n\t});\n}\n\nasync function seekSignature(reader, signature, startOffset, minimumBytes, maximumLength) {\n\tconst signatureArray = new Uint8Array(4);\n\tconst signatureView = getDataView(signatureArray);\n\tsetUint32(signatureView, 0, signature);\n\tconst maximumBytes = minimumBytes + maximumLength;\n\treturn (await seek(minimumBytes)) || await seek(Math.min(maximumBytes, startOffset));\n\n\tasync function seek(length) {\n\t\tconst offset = startOffset - length;\n\t\tconst bytes = await readUint8Array(reader, offset, length);\n\t\tfor (let indexByte = bytes.length - minimumBytes; indexByte >= 0; indexByte--) {\n\t\t\tif (bytes[indexByte] == signatureArray[0] && bytes[indexByte + 1] == signatureArray[1] &&\n\t\t\t\tbytes[indexByte + 2] == signatureArray[2] && bytes[indexByte + 3] == signatureArray[3]) {\n\t\t\t\treturn {\n\t\t\t\t\toffset: offset + indexByte,\n\t\t\t\t\tbuffer: bytes.slice(indexByte, indexByte + minimumBytes).buffer\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction getOptionValue(zipReader, options, name) {\n\treturn options[name] === undefined ? zipReader.options[name] : options[name];\n}\n\nfunction getDate(timeRaw) {\n\tconst date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;\n\ttry {\n\t\treturn new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);\n\t} catch (_error) {\n\t\t// ignored\n\t}\n}\n\nfunction getDateNTFS(timeRaw) {\n\treturn new Date((Number((timeRaw / BigInt(10000)) - BigInt(11644473600000))));\n}\n\nfunction getUint8(view, offset) {\n\treturn view.getUint8(offset);\n}\n\nfunction getUint16(view, offset) {\n\treturn view.getUint16(offset, true);\n}\n\nfunction getUint32(view, offset) {\n\treturn view.getUint32(offset, true);\n}\n\nfunction getBigUint64(view, offset) {\n\treturn Number(view.getBigUint64(offset, true));\n}\n\nfunction setUint32(view, offset, value) {\n\tview.setUint32(offset, value, true);\n}\n\nfunction getDataView(array) {\n\treturn new DataView(array.buffer);\n}\n\nfunction readUint8Array(reader, offset, size) {\n\treturn reader.readUint8Array(offset, size);\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n/* global BigInt, FileReader */\n\nimport {\n\tMAX_32_BITS,\n\tMAX_16_BITS,\n\tCOMPRESSION_METHOD_DEFLATE,\n\tCOMPRESSION_METHOD_STORE,\n\tCOMPRESSION_METHOD_AES,\n\tLOCAL_FILE_HEADER_SIGNATURE,\n\tDATA_DESCRIPTOR_RECORD_SIGNATURE,\n\tCENTRAL_FILE_HEADER_SIGNATURE,\n\tEND_OF_CENTRAL_DIR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE,\n\tZIP64_END_OF_CENTRAL_DIR_SIGNATURE,\n\tZIP64_TOTAL_NUMBER_OF_DISKS,\n\tEXTRAFIELD_TYPE_AES,\n\tEXTRAFIELD_TYPE_ZIP64,\n\tEXTRAFIELD_TYPE_EXTENDED_TIMESTAMP,\n\tEXTRAFIELD_TYPE_NTFS,\n\tEXTRAFIELD_TYPE_NTFS_TAG1,\n\tEND_OF_CENTRAL_DIR_LENGTH,\n\tZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH,\n\tBITFLAG_ENCRYPTED,\n\tBITFLAG_DATA_DESCRIPTOR,\n\tBITFLAG_LANG_ENCODING_FLAG,\n\tFILE_ATTR_MSDOS_DIR_MASK,\n\tVERSION_DEFLATE,\n\tVERSION_ZIP64,\n\tVERSION_AES,\n\tDIRECTORY_SIGNATURE,\n\tMIN_DATE,\n\tMAX_DATE\n} from \"./constants.js\";\nimport { getConfiguration } from \"./configuration.js\";\nimport { CODEC_DEFLATE, createCodec } from \"./codecs/codec-pool.js\";\nimport encodeText from \"./util/encode-text.js\";\nimport { BlobWriter } from \"./io.js\";\nimport { processData } from \"./engine.js\";\nimport Entry from \"./zip-entry.js\";\n\nconst ERR_DUPLICATED_NAME = \"File already exists\";\nconst ERR_INVALID_COMMENT = \"Zip file comment exceeds 64KB\";\nconst ERR_INVALID_ENTRY_COMMENT = \"File entry comment exceeds 64KB\";\nconst ERR_INVALID_ENTRY_NAME = \"File entry name exceeds 64KB\";\nconst ERR_INVALID_VERSION = \"Version exceeds 65535\";\nconst ERR_INVALID_ENCRYPTION_STRENGTH = \"The strength must equal 1, 2, or 3\";\nconst ERR_INVALID_EXTRAFIELD_TYPE = \"Extra field type exceeds 65535\";\nconst ERR_INVALID_EXTRAFIELD_DATA = \"Extra field data exceeds 64KB\";\nconst ERR_UNSUPPORTED_FORMAT = \"Zip64 is not supported\";\n\nconst EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);\nconst EXTRAFIELD_LENGTH_ZIP64 = 24;\n\nlet workers = 0;\n\nclass ZipWriter {\n\n\tconstructor(writer, options = {}) {\n\t\tObject.assign(this, {\n\t\t\twriter,\n\t\t\toptions,\n\t\t\tconfig: getConfiguration(),\n\t\t\tfiles: new Map(),\n\t\t\toffset: writer.size,\n\t\t\tpendingCompressedSize: 0,\n\t\t\tpendingEntries: [],\n\t\t\tpendingAddFileCalls: new Set()\n\t\t});\n\t}\n\n\tasync add(name = \"\", reader, options = {}) {\n\t\tconst zipWriter = this;\n\t\tif (workers < zipWriter.config.maxWorkers) {\n\t\t\tworkers++;\n\t\t\tlet promiseAddFile;\n\t\t\ttry {\n\t\t\t\tpromiseAddFile = addFile(zipWriter, name, reader, options);\n\t\t\t\tthis.pendingAddFileCalls.add(promiseAddFile);\n\t\t\t\treturn await promiseAddFile;\n\t\t\t} finally {\n\t\t\t\tthis.pendingAddFileCalls.delete(promiseAddFile);\n\t\t\t\tworkers--;\n\t\t\t\tconst pendingEntry = zipWriter.pendingEntries.shift();\n\t\t\t\tif (pendingEntry) {\n\t\t\t\t\tzipWriter.add(pendingEntry.name, pendingEntry.reader, pendingEntry.options)\n\t\t\t\t\t\t.then(pendingEntry.resolve)\n\t\t\t\t\t\t.catch(pendingEntry.reject);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn new Promise((resolve, reject) => zipWriter.pendingEntries.push({ name, reader, options, resolve, reject }));\n\t\t}\n\t}\n\n\tasync close(comment = new Uint8Array(0), options = {}) {\n\t\twhile (this.pendingAddFileCalls.size) {\n\t\t\tawait Promise.all(Array.from(this.pendingAddFileCalls));\n\t\t}\n\t\tawait closeFile(this, comment, options);\n\t\treturn this.writer.getData();\n\t}\n}\n\nexport {\n\tZipWriter,\n\tERR_DUPLICATED_NAME,\n\tERR_INVALID_COMMENT,\n\tERR_INVALID_ENTRY_NAME,\n\tERR_INVALID_ENTRY_COMMENT,\n\tERR_INVALID_VERSION,\n\tERR_INVALID_EXTRAFIELD_TYPE,\n\tERR_INVALID_EXTRAFIELD_DATA,\n\tERR_INVALID_ENCRYPTION_STRENGTH,\n\tERR_UNSUPPORTED_FORMAT\n};\n\nasync function addFile(zipWriter, name, reader, options) {\n\tname = name.trim();\n\tif (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {\n\t\tname += DIRECTORY_SIGNATURE;\n\t} else {\n\t\toptions.directory = name.endsWith(DIRECTORY_SIGNATURE);\n\t}\n\tif (zipWriter.files.has(name)) {\n\t\tthrow new Error(ERR_DUPLICATED_NAME);\n\t}\n\tconst rawFilename = encodeText(name);\n\tif (rawFilename.length > MAX_16_BITS) {\n\t\tthrow new Error(ERR_INVALID_ENTRY_NAME);\n\t}\n\tconst comment = options.comment || \"\";\n\tconst rawComment = encodeText(comment);\n\tif (rawComment.length > MAX_16_BITS) {\n\t\tthrow new Error(ERR_INVALID_ENTRY_COMMENT);\n\t}\n\tconst version = zipWriter.options.version || options.version || 0;\n\tif (version > MAX_16_BITS) {\n\t\tthrow new Error(ERR_INVALID_VERSION);\n\t}\n\tconst versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;\n\tif (versionMadeBy > MAX_16_BITS) {\n\t\tthrow new Error(ERR_INVALID_VERSION);\n\t}\n\tconst lastModDate = getOptionValue(zipWriter, options, \"lastModDate\") || new Date();\n\tconst lastAccessDate = getOptionValue(zipWriter, options, \"lastAccessDate\");\n\tconst creationDate = getOptionValue(zipWriter, options, \"creationDate\");\n\tconst password = getOptionValue(zipWriter, options, \"password\");\n\tconst encryptionStrength = getOptionValue(zipWriter, options, \"encryptionStrength\") || 3;\n\tconst zipCrypto = getOptionValue(zipWriter, options, \"zipCrypto\");\n\tif (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {\n\t\tthrow new Error(ERR_INVALID_ENCRYPTION_STRENGTH);\n\t}\n\tlet rawExtraField = new Uint8Array(0);\n\tconst extraField = options.extraField;\n\tif (extraField) {\n\t\tlet extraFieldSize = 0;\n\t\tlet offset = 0;\n\t\textraField.forEach(data => extraFieldSize += 4 + data.length);\n\t\trawExtraField = new Uint8Array(extraFieldSize);\n\t\textraField.forEach((data, type) => {\n\t\t\tif (type > MAX_16_BITS) {\n\t\t\t\tthrow new Error(ERR_INVALID_EXTRAFIELD_TYPE);\n\t\t\t}\n\t\t\tif (data.length > MAX_16_BITS) {\n\t\t\t\tthrow new Error(ERR_INVALID_EXTRAFIELD_DATA);\n\t\t\t}\n\t\t\tarraySet(rawExtraField, new Uint16Array([type]), offset);\n\t\t\tarraySet(rawExtraField, new Uint16Array([data.length]), offset + 2);\n\t\t\tarraySet(rawExtraField, data, offset + 4);\n\t\t\toffset += 4 + data.length;\n\t\t});\n\t}\n\tlet extendedTimestamp = getOptionValue(zipWriter, options, \"extendedTimestamp\");\n\tif (extendedTimestamp === undefined) {\n\t\textendedTimestamp = true;\n\t}\n\tlet maximumCompressedSize = 0;\n\tlet keepOrder = getOptionValue(zipWriter, options, \"keepOrder\");\n\tif (keepOrder === undefined) {\n\t\tkeepOrder = true;\n\t}\n\tlet uncompressedSize = 0;\n\tlet msDosCompatible = getOptionValue(zipWriter, options, \"msDosCompatible\");\n\tif (msDosCompatible === undefined) {\n\t\tmsDosCompatible = true;\n\t}\n\tconst internalFileAttribute = getOptionValue(zipWriter, options, \"internalFileAttribute\") || 0;\n\tconst externalFileAttribute = getOptionValue(zipWriter, options, \"externalFileAttribute\") || 0;\n\tif (reader) {\n\t\tif (!reader.initialized) {\n\t\t\tawait reader.init();\n\t\t}\n\t\tuncompressedSize = reader.size;\n\t\tmaximumCompressedSize = getMaximumCompressedSize(uncompressedSize);\n\t}\n\tlet zip64 = options.zip64 || zipWriter.options.zip64 || false;\n\tif (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||\n\t\tuncompressedSize >= MAX_32_BITS ||\n\t\tmaximumCompressedSize >= MAX_32_BITS) {\n\t\tif (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {\n\t\t\tthrow new Error(ERR_UNSUPPORTED_FORMAT);\n\t\t} else {\n\t\t\tzip64 = true;\n\t\t}\n\t}\n\tzipWriter.pendingCompressedSize += maximumCompressedSize;\n\tawait Promise.resolve();\n\tconst level = getOptionValue(zipWriter, options, \"level\");\n\tconst useWebWorkers = getOptionValue(zipWriter, options, \"useWebWorkers\");\n\tconst bufferedWrite = getOptionValue(zipWriter, options, \"bufferedWrite\");\n\tlet dataDescriptor = getOptionValue(zipWriter, options, \"dataDescriptor\");\n\tlet dataDescriptorSignature = getOptionValue(zipWriter, options, \"dataDescriptorSignature\");\n\tconst signal = getOptionValue(zipWriter, options, \"signal\");\n\tif (dataDescriptor === undefined) {\n\t\tdataDescriptor = true;\n\t}\n\tif (dataDescriptor && dataDescriptorSignature === undefined) {\n\t\tdataDescriptorSignature = false;\n\t}\n\tconst fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {\n\t\trawFilename,\n\t\trawComment,\n\t\tversion,\n\t\tversionMadeBy,\n\t\tlastModDate,\n\t\tlastAccessDate,\n\t\tcreationDate,\n\t\trawExtraField,\n\t\tzip64,\n\t\tpassword,\n\t\tlevel,\n\t\tuseWebWorkers,\n\t\tencryptionStrength,\n\t\textendedTimestamp,\n\t\tzipCrypto,\n\t\tbufferedWrite,\n\t\tkeepOrder,\n\t\tdataDescriptor,\n\t\tdataDescriptorSignature,\n\t\tsignal,\n\t\tmsDosCompatible,\n\t\tinternalFileAttribute,\n\t\texternalFileAttribute\n\t}));\n\tif (maximumCompressedSize) {\n\t\tzipWriter.pendingCompressedSize -= maximumCompressedSize;\n\t}\n\tObject.assign(fileEntry, { name, comment, extraField });\n\treturn new Entry(fileEntry);\n}\n\nasync function getFileEntry(zipWriter, name, reader, options) {\n\tconst files = zipWriter.files;\n\tconst writer = zipWriter.writer;\n\tconst previousFileEntry = Array.from(files.values()).pop();\n\tlet fileEntry = {};\n\tlet bufferedWrite;\n\tlet resolveLockUnbufferedWrite;\n\tlet resolveLockCurrentFileEntry;\n\tfiles.set(name, fileEntry);\n\ttry {\n\t\tlet lockPreviousFileEntry;\n\t\tlet fileWriter;\n\t\tlet lockCurrentFileEntry;\n\t\tif (options.keepOrder) {\n\t\t\tlockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;\n\t\t}\n\t\tfileEntry.lock = lockCurrentFileEntry = new Promise(resolve => resolveLockCurrentFileEntry = resolve);\n\t\tif (options.bufferedWrite || zipWriter.lockWrite || !options.dataDescriptor) {\n\t\t\tfileWriter = new BlobWriter();\n\t\t\tfileWriter.init();\n\t\t\tbufferedWrite = true;\n\t\t} else {\n\t\t\tzipWriter.lockWrite = new Promise(resolve => resolveLockUnbufferedWrite = resolve);\n\t\t\tif (!writer.initialized) {\n\t\t\t\tawait writer.init();\n\t\t\t}\n\t\t\tfileWriter = writer;\n\t\t}\n\t\tfileEntry = await createFileEntry(reader, fileWriter, zipWriter.config, options);\n\t\tfileEntry.lock = lockCurrentFileEntry;\n\t\tfiles.set(name, fileEntry);\n\t\tfileEntry.filename = name;\n\t\tif (bufferedWrite) {\n\t\t\tlet indexWrittenData = 0;\n\t\t\tconst blob = fileWriter.getData();\n\t\t\tawait Promise.all([zipWriter.lockWrite, lockPreviousFileEntry]);\n\t\t\tlet pendingFileEntry;\n\t\t\tdo {\n\t\t\t\tpendingFileEntry = Array.from(files.values()).find(fileEntry => fileEntry.writingBufferedData);\n\t\t\t\tif (pendingFileEntry) {\n\t\t\t\t\tawait pendingFileEntry.lock;\n\t\t\t\t}\n\t\t\t} while (pendingFileEntry && pendingFileEntry.lock);\n\t\t\tfileEntry.writingBufferedData = true;\n\t\t\tif (!options.dataDescriptor) {\n\t\t\t\tconst headerLength = 26;\n\t\t\t\tconst arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);\n\t\t\t\tconst arrayBufferView = new DataView(arrayBuffer);\n\t\t\t\tif (!fileEntry.encrypted || options.zipCrypto) {\n\t\t\t\t\tsetUint32(arrayBufferView, 14, fileEntry.signature);\n\t\t\t\t}\n\t\t\t\tif (fileEntry.zip64) {\n\t\t\t\t\tsetUint32(arrayBufferView, 18, MAX_32_BITS);\n\t\t\t\t\tsetUint32(arrayBufferView, 22, MAX_32_BITS);\n\t\t\t\t} else {\n\t\t\t\t\tsetUint32(arrayBufferView, 18, fileEntry.compressedSize);\n\t\t\t\t\tsetUint32(arrayBufferView, 22, fileEntry.uncompressedSize);\n\t\t\t\t}\n\t\t\t\tawait writer.writeUint8Array(new Uint8Array(arrayBuffer));\n\t\t\t\tindexWrittenData = headerLength;\n\t\t\t}\n\t\t\tawait writeBlob(writer, blob, indexWrittenData);\n\t\t\tdelete fileEntry.writingBufferedData;\n\t\t}\n\t\tfileEntry.offset = zipWriter.offset;\n\t\tif (fileEntry.zip64) {\n\t\t\tconst rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);\n\t\t\tsetBigUint64(rawExtraFieldZip64View, 20, BigInt(fileEntry.offset));\n\t\t} else if (fileEntry.offset >= MAX_32_BITS) {\n\t\t\tthrow new Error(ERR_UNSUPPORTED_FORMAT);\n\t\t}\n\t\tzipWriter.offset += fileEntry.length;\n\t\treturn fileEntry;\n\t} catch (error) {\n\t\tif ((bufferedWrite && fileEntry.writingBufferedData) || (!bufferedWrite && fileEntry.dataWritten)) {\n\t\t\terror.corruptedEntry = zipWriter.hasCorruptedEntries = true;\n\t\t\tif (fileEntry.uncompressedSize) {\n\t\t\t\tzipWriter.offset += fileEntry.uncompressedSize;\n\t\t\t}\n\t\t}\n\t\tfiles.delete(name);\n\t\tthrow error;\n\t} finally {\n\t\tresolveLockCurrentFileEntry();\n\t\tif (resolveLockUnbufferedWrite) {\n\t\t\tresolveLockUnbufferedWrite();\n\t\t}\n\t}\n}\n\nasync function createFileEntry(reader, writer, config, options) {\n\tconst {\n\t\trawFilename,\n\t\tlastAccessDate,\n\t\tcreationDate,\n\t\tpassword,\n\t\tlevel,\n\t\tzip64,\n\t\tzipCrypto,\n\t\tdataDescriptor,\n\t\tdataDescriptorSignature,\n\t\tdirectory,\n\t\tversion,\n\t\tversionMadeBy,\n\t\trawComment,\n\t\trawExtraField,\n\t\tuseWebWorkers,\n\t\tonprogress,\n\t\tsignal,\n\t\tencryptionStrength,\n\t\textendedTimestamp,\n\t\tmsDosCompatible,\n\t\tinternalFileAttribute,\n\t\texternalFileAttribute\n\t} = options;\n\tconst encrypted = Boolean(password && password.length);\n\tconst compressed = level !== 0 && !directory;\n\tlet rawExtraFieldAES;\n\tif (encrypted && !zipCrypto) {\n\t\trawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);\n\t\tconst extraFieldAESView = getDataView(rawExtraFieldAES);\n\t\tsetUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES);\n\t\tarraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);\n\t\tsetUint8(extraFieldAESView, 8, encryptionStrength);\n\t} else {\n\t\trawExtraFieldAES = new Uint8Array(0);\n\t}\n\tlet rawExtraFieldNTFS;\n\tlet rawExtraFieldExtendedTimestamp;\n\tif (extendedTimestamp) {\n\t\trawExtraFieldExtendedTimestamp = new Uint8Array(9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0));\n\t\tconst extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);\n\t\tsetUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);\n\t\tsetUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);\n\t\tconst extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);\n\t\tsetUint8(extraFieldExtendedTimestampView, 4, extraFieldExtendedTimestampFlag);\n\t\tsetUint32(extraFieldExtendedTimestampView, 5, Math.floor(options.lastModDate.getTime() / 1000));\n\t\tif (lastAccessDate) {\n\t\t\tsetUint32(extraFieldExtendedTimestampView, 9, Math.floor(lastAccessDate.getTime() / 1000));\n\t\t}\n\t\tif (creationDate) {\n\t\t\tsetUint32(extraFieldExtendedTimestampView, 13, Math.floor(creationDate.getTime() / 1000));\n\t\t}\n\t\ttry {\n\t\t\trawExtraFieldNTFS = new Uint8Array(36);\n\t\t\tconst extraFieldNTFSView = getDataView(rawExtraFieldNTFS);\n\t\t\tconst lastModTimeNTFS = getTimeNTFS(options.lastModDate);\n\t\t\tsetUint16(extraFieldNTFSView, 0, EXTRAFIELD_TYPE_NTFS);\n\t\t\tsetUint16(extraFieldNTFSView, 2, 32);\n\t\t\tsetUint16(extraFieldNTFSView, 8, EXTRAFIELD_TYPE_NTFS_TAG1);\n\t\t\tsetUint16(extraFieldNTFSView, 10, 24);\n\t\t\tsetBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);\n\t\t\tsetBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);\n\t\t\tsetBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);\n\t\t} catch (_error) {\n\t\t\trawExtraFieldNTFS = new Uint8Array(0);\n\t\t}\n\t} else {\n\t\trawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);\n\t}\n\tconst fileEntry = {\n\t\tversion: version || VERSION_DEFLATE,\n\t\tversionMadeBy,\n\t\tzip64,\n\t\tdirectory: Boolean(directory),\n\t\tfilenameUTF8: true,\n\t\trawFilename,\n\t\tcommentUTF8: true,\n\t\trawComment,\n\t\trawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0),\n\t\trawExtraFieldExtendedTimestamp,\n\t\trawExtraFieldNTFS,\n\t\trawExtraFieldAES,\n\t\trawExtraField,\n\t\textendedTimestamp,\n\t\tmsDosCompatible,\n\t\tinternalFileAttribute,\n\t\texternalFileAttribute\n\t};\n\tlet uncompressedSize = fileEntry.uncompressedSize = 0;\n\tlet bitFlag = BITFLAG_LANG_ENCODING_FLAG;\n\tif (dataDescriptor) {\n\t\tbitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;\n\t}\n\tlet compressionMethod = COMPRESSION_METHOD_STORE;\n\tif (compressed) {\n\t\tcompressionMethod = COMPRESSION_METHOD_DEFLATE;\n\t}\n\tif (zip64) {\n\t\tfileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;\n\t}\n\tif (encrypted) {\n\t\tbitFlag = bitFlag | BITFLAG_ENCRYPTED;\n\t\tif (!zipCrypto) {\n\t\t\tfileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;\n\t\t\tcompressionMethod = COMPRESSION_METHOD_AES;\n\t\t\tif (compressed) {\n\t\t\t\tfileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;\n\t\t\t}\n\t\t}\n\t}\n\tfileEntry.compressionMethod = compressionMethod;\n\tconst headerArray = fileEntry.headerArray = new Uint8Array(26);\n\tconst headerView = getDataView(headerArray);\n\tsetUint16(headerView, 0, fileEntry.version);\n\tsetUint16(headerView, 2, bitFlag);\n\tsetUint16(headerView, 4, compressionMethod);\n\tconst dateArray = new Uint32Array(1);\n\tconst dateView = getDataView(dateArray);\n\tlet lastModDate;\n\tif (options.lastModDate < MIN_DATE) {\n\t\tlastModDate = MIN_DATE;\n\t} else if (options.lastModDate > MAX_DATE) {\n\t\tlastModDate = MAX_DATE;\n\t} else {\n\t\tlastModDate = options.lastModDate;\n\t}\n\tsetUint16(dateView, 0, (((lastModDate.getHours() << 6) | lastModDate.getMinutes()) << 5) | lastModDate.getSeconds() / 2);\n\tsetUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());\n\tconst rawLastModDate = dateArray[0];\n\tsetUint32(headerView, 6, rawLastModDate);\n\tsetUint16(headerView, 22, rawFilename.length);\n\tconst extraFieldLength = rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + fileEntry.rawExtraField.length;\n\tsetUint16(headerView, 24, extraFieldLength);\n\tconst localHeaderArray = new Uint8Array(30 + rawFilename.length + extraFieldLength);\n\tconst localHeaderView = getDataView(localHeaderArray);\n\tsetUint32(localHeaderView, 0, LOCAL_FILE_HEADER_SIGNATURE);\n\tarraySet(localHeaderArray, headerArray, 4);\n\tarraySet(localHeaderArray, rawFilename, 30);\n\tarraySet(localHeaderArray, rawExtraFieldAES, 30 + rawFilename.length);\n\tarraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);\n\tarraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);\n\tarraySet(localHeaderArray, fileEntry.rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);\n\tlet result;\n\tlet compressedSize = 0;\n\tif (reader) {\n\t\tconst codec = await createCodec(config.Deflate, {\n\t\t\tcodecType: CODEC_DEFLATE,\n\t\t\tlevel,\n\t\t\tpassword,\n\t\t\tencryptionStrength,\n\t\t\tzipCrypto: encrypted && zipCrypto,\n\t\t\tpasswordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,\n\t\t\tsigned: true,\n\t\t\tcompressed,\n\t\t\tencrypted,\n\t\t\tuseWebWorkers\n\t\t}, config);\n\t\tawait writer.writeUint8Array(localHeaderArray);\n\t\tfileEntry.dataWritten = true;\n\t\tresult = await processData(codec, reader, writer, 0, () => reader.size, config, { onprogress, signal });\n\t\tuncompressedSize = fileEntry.uncompressedSize = reader.size;\n\t\tcompressedSize = result.length;\n\t} else {\n\t\tawait writer.writeUint8Array(localHeaderArray);\n\t\tfileEntry.dataWritten = true;\n\t}\n\tlet dataDescriptorArray = new Uint8Array(0);\n\tlet dataDescriptorView, dataDescriptorOffset = 0;\n\tif (dataDescriptor) {\n\t\tdataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));\n\t\tdataDescriptorView = getDataView(dataDescriptorArray);\n\t\tif (dataDescriptorSignature) {\n\t\t\tdataDescriptorOffset = 4;\n\t\t\tsetUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);\n\t\t}\n\t}\n\tif (reader) {\n\t\tconst signature = result.signature;\n\t\tif ((!encrypted || zipCrypto) && signature !== undefined) {\n\t\t\tsetUint32(headerView, 10, signature);\n\t\t\tfileEntry.signature = signature;\n\t\t\tif (dataDescriptor) {\n\t\t\t\tsetUint32(dataDescriptorView, dataDescriptorOffset, signature);\n\t\t\t}\n\t\t}\n\t\tif (zip64) {\n\t\t\tconst rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);\n\t\t\tsetUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);\n\t\t\tsetUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);\n\t\t\tsetUint32(headerView, 14, MAX_32_BITS);\n\t\t\tsetBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));\n\t\t\tsetUint32(headerView, 18, MAX_32_BITS);\n\t\t\tsetBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));\n\t\t\tif (dataDescriptor) {\n\t\t\t\tsetBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));\n\t\t\t\tsetBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));\n\t\t\t}\n\t\t} else {\n\t\t\tsetUint32(headerView, 14, compressedSize);\n\t\t\tsetUint32(headerView, 18, uncompressedSize);\n\t\t\tif (dataDescriptor) {\n\t\t\t\tsetUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);\n\t\t\t\tsetUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);\n\t\t\t}\n\t\t}\n\t}\n\tif (dataDescriptor) {\n\t\tawait writer.writeUint8Array(dataDescriptorArray);\n\t}\n\tconst length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;\n\tObject.assign(fileEntry, { compressedSize, lastModDate, rawLastModDate, creationDate, lastAccessDate, encrypted, length });\n\treturn fileEntry;\n}\n\nasync function closeFile(zipWriter, comment, options) {\n\tconst writer = zipWriter.writer;\n\tconst files = zipWriter.files;\n\tlet offset = 0;\n\tlet directoryDataLength = 0;\n\tlet directoryOffset = zipWriter.offset;\n\tlet filesLength = files.size;\n\tfor (const [, fileEntry] of files) {\n\t\tdirectoryDataLength += 46 +\n\t\t\tfileEntry.rawFilename.length +\n\t\t\tfileEntry.rawComment.length +\n\t\t\tfileEntry.rawExtraFieldZip64.length +\n\t\t\tfileEntry.rawExtraFieldAES.length +\n\t\t\tfileEntry.rawExtraFieldExtendedTimestamp.length +\n\t\t\tfileEntry.rawExtraFieldNTFS.length +\n\t\t\tfileEntry.rawExtraField.length;\n\t}\n\tlet zip64 = options.zip64 || zipWriter.options.zip64 || false;\n\tif (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {\n\t\tif (options.zip64 === false || zipWriter.options.zip64 === false) {\n\t\t\tthrow new Error(ERR_UNSUPPORTED_FORMAT);\n\t\t} else {\n\t\t\tzip64 = true;\n\t\t}\n\t}\n\tconst directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH));\n\tconst directoryView = getDataView(directoryArray);\n\tif (comment && comment.length) {\n\t\tif (comment.length <= MAX_16_BITS) {\n\t\t\tsetUint16(directoryView, offset + 20, comment.length);\n\t\t} else {\n\t\t\tthrow new Error(ERR_INVALID_COMMENT);\n\t\t}\n\t}\n\tfor (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {\n\t\tconst {\n\t\t\trawFilename,\n\t\t\trawExtraFieldZip64,\n\t\t\trawExtraFieldAES,\n\t\t\trawExtraField,\n\t\t\trawComment,\n\t\t\tversionMadeBy,\n\t\t\theaderArray,\n\t\t\tdirectory,\n\t\t\tzip64,\n\t\t\tmsDosCompatible,\n\t\t\tinternalFileAttribute,\n\t\t\texternalFileAttribute\n\t\t} = fileEntry;\n\t\tlet rawExtraFieldExtendedTimestamp;\n\t\tlet rawExtraFieldNTFS;\n\t\tif (fileEntry.extendedTimestamp) {\n\t\t\trawExtraFieldNTFS = fileEntry.rawExtraFieldNTFS;\n\t\t\trawExtraFieldExtendedTimestamp = new Uint8Array(9);\n\t\t\tconst extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);\n\t\t\tsetUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);\n\t\t\tsetUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);\n\t\t\tsetUint8(extraFieldExtendedTimestampView, 4, 0x1);\n\t\t\tsetUint32(extraFieldExtendedTimestampView, 5, Math.floor(fileEntry.lastModDate.getTime() / 1000));\n\t\t} else {\n\t\t\trawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);\n\t\t}\n\t\tconst extraFieldLength = rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + rawExtraField.length;\n\t\tsetUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);\n\t\tsetUint16(directoryView, offset + 4, versionMadeBy);\n\t\tarraySet(directoryArray, headerArray, offset + 6);\n\t\tsetUint16(directoryView, offset + 30, extraFieldLength);\n\t\tsetUint16(directoryView, offset + 32, rawComment.length);\n\t\tsetUint32(directoryView, offset + 34, internalFileAttribute);\n\t\tif (externalFileAttribute) {\n\t\t\tsetUint32(directoryView, offset + 38, externalFileAttribute);\n\t\t} else if (directory && msDosCompatible) {\n\t\t\tsetUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);\n\t\t}\n\t\tif (zip64) {\n\t\t\tsetUint32(directoryView, offset + 42, MAX_32_BITS);\n\t\t} else {\n\t\t\tsetUint32(directoryView, offset + 42, fileEntry.offset);\n\t\t}\n\t\tarraySet(directoryArray, rawFilename, offset + 46);\n\t\tarraySet(directoryArray, rawExtraFieldZip64, offset + 46 + rawFilename.length);\n\t\tarraySet(directoryArray, rawExtraFieldAES, offset + 46 + rawFilename.length + rawExtraFieldZip64.length);\n\t\tarraySet(directoryArray, rawExtraFieldExtendedTimestamp, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length);\n\t\tarraySet(directoryArray, rawExtraFieldNTFS, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);\n\t\tarraySet(directoryArray, rawExtraField, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);\n\t\tarraySet(directoryArray, rawComment, offset + 46 + rawFilename.length + extraFieldLength);\n\t\toffset += 46 + rawFilename.length + extraFieldLength + rawComment.length;\n\t\tif (options.onprogress) {\n\t\t\ttry {\n\t\t\t\toptions.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));\n\t\t\t} catch (_error) {\n\t\t\t\t// ignored\n\t\t\t}\n\t\t}\n\t}\n\tif (zip64) {\n\t\tsetUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);\n\t\tsetBigUint64(directoryView, offset + 4, BigInt(44));\n\t\tsetUint16(directoryView, offset + 12, 45);\n\t\tsetUint16(directoryView, offset + 14, 45);\n\t\tsetBigUint64(directoryView, offset + 24, BigInt(filesLength));\n\t\tsetBigUint64(directoryView, offset + 32, BigInt(filesLength));\n\t\tsetBigUint64(directoryView, offset + 40, BigInt(directoryDataLength));\n\t\tsetBigUint64(directoryView, offset + 48, BigInt(directoryOffset));\n\t\tsetUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);\n\t\tsetBigUint64(directoryView, offset + 64, BigInt(directoryOffset) + BigInt(directoryDataLength));\n\t\tsetUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS);\n\t\tfilesLength = MAX_16_BITS;\n\t\tdirectoryOffset = MAX_32_BITS;\n\t\tdirectoryDataLength = MAX_32_BITS;\n\t\toffset += 76;\n\t}\n\tsetUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);\n\tsetUint16(directoryView, offset + 8, filesLength);\n\tsetUint16(directoryView, offset + 10, filesLength);\n\tsetUint32(directoryView, offset + 12, directoryDataLength);\n\tsetUint32(directoryView, offset + 16, directoryOffset);\n\tawait writer.writeUint8Array(directoryArray);\n\tif (comment && comment.length) {\n\t\tawait writer.writeUint8Array(comment);\n\t}\n}\n\nfunction sliceAsArrayBuffer(blob, start, end) {\n\tif (blob.arrayBuffer) {\n\t\tif (start || end) {\n\t\t\treturn blob.slice(start, end).arrayBuffer();\n\t\t} else {\n\t\t\treturn blob.arrayBuffer();\n\t\t}\n\t} else {\n\t\tconst fileReader = new FileReader();\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tfileReader.onload = event => resolve(event.target.result);\n\t\t\tfileReader.onerror = () => reject(fileReader.error);\n\t\t\tfileReader.readAsArrayBuffer(start || end ? blob.slice(start, end) : blob);\n\t\t});\n\t}\n}\n\nasync function writeBlob(writer, blob, start = 0) {\n\tconst blockSize = 512 * 1024 * 1024;\n\tawait writeSlice();\n\n\tasync function writeSlice() {\n\t\tif (start < blob.size) {\n\t\t\tconst arrayBuffer = await sliceAsArrayBuffer(blob, start, start + blockSize);\n\t\t\tawait writer.writeUint8Array(new Uint8Array(arrayBuffer));\n\t\t\tstart += blockSize;\n\t\t\tawait writeSlice();\n\t\t}\n\t}\n}\n\nfunction getTimeNTFS(date) {\n\tif (date) {\n\t\treturn ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));\n\t}\n}\n\nfunction getOptionValue(zipWriter, options, name) {\n\treturn options[name] === undefined ? zipWriter.options[name] : options[name];\n}\n\nfunction getMaximumCompressedSize(uncompressedSize) {\n\treturn uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));\n}\n\nfunction setUint8(view, offset, value) {\n\tview.setUint8(offset, value);\n}\n\nfunction setUint16(view, offset, value) {\n\tview.setUint16(offset, value, true);\n}\n\nfunction setUint32(view, offset, value) {\n\tview.setUint32(offset, value, true);\n}\n\nfunction setBigUint64(view, offset, value) {\n\tview.setBigUint64(offset, value, true);\n}\n\nfunction arraySet(array, typedArray, offset) {\n\tarray.set(typedArray, offset);\n}\n\nfunction getDataView(array) {\n\treturn new DataView(array.buffer);\n}", "/*\n Copyright (c) 2022 Gildas Lormeau. All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice,\n this list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright \n notice, this list of conditions and the following disclaimer in \n the documentation and/or other materials provided with the distribution.\n\n 3. The names of the authors may not be used to endorse or promote products\n derived from this software without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\n INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,\n INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,\n INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport Deflate from \"./core/codecs/deflate.js\";\nimport Inflate from \"./core/codecs/inflate.js\";\nimport { configure } from \"./core/configuration.js\";\nimport { getMimeType } from \"./core/util/default-mime-type.js\";\nimport { terminateWorkers } from \"./core/codecs/codec-pool.js\";\n\nconfigure({ Deflate, Inflate });\n\nexport { ERR_ABORT } from \"./core/engine.js\";\nexport * from \"./core/io.js\";\nexport * from \"./core/zip-reader.js\";\nexport * from \"./core/zip-writer.js\";\nexport {\n\tconfigure,\n\tgetMimeType,\n\tterminateWorkers\n};", "import DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * If element is a string, look up the element in the DOM by ID. Otherwise return element.\n *\n * @private\n *\n * @exception {DeveloperError} Element with id \"id\" does not exist in the document.\n */\nfunction getElement(element) {\n if (typeof element === \"string\") {\n const foundElement = document.getElementById(element);\n\n //>>includeStart('debug', pragmas.debug);\n if (foundElement === null) {\n throw new DeveloperError(\n `Element with id \"${element}\" does not exist in the document.`\n );\n }\n //>>includeEnd('debug');\n\n element = foundElement;\n }\n return element;\n}\nexport default getElement;\n", "/**\n * @alias KmlLookAt\n * @constructor\n *\n * @param {Cartesian3} position camera position\n * @param {HeadingPitchRange} headingPitchRange camera orientation\n */\nfunction KmlLookAt(position, headingPitchRange) {\n this.position = position;\n this.headingPitchRange = headingPitchRange;\n}\nexport default KmlLookAt;\n", "import defined from \"../Core/defined.js\";\nimport Event from \"../Core/Event.js\";\n/**\n * Describes a KmlTour, which uses KmlTourFlyTo, and KmlTourWait to\n * guide the camera to a specified destinations on given time intervals.\n *\n * @alias KmlTour\n * @constructor\n *\n * @param {string} name name parsed from KML\n * @param {string} id id parsed from KML\n * @param {Array} playlist array with KmlTourFlyTos and KmlTourWaits\n *\n * @see KmlTourFlyTo\n * @see KmlTourWait\n *\n * @demo {@link https://sandcastle.cesium.com/?src=KML%20Tours.html|KML Tours}\n */\nfunction KmlTour(name, id) {\n /**\n * Id of kml gx:Tour entry\n * @type {string}\n */\n this.id = id;\n /**\n * Tour name\n * @type {string}\n */\n this.name = name;\n /**\n * Index of current entry from playlist\n * @type {number}\n */\n this.playlistIndex = 0;\n /**\n * Array of playlist entries\n * @type {Array}\n */\n this.playlist = [];\n /**\n * Event will be called when tour starts to play,\n * before any playlist entry starts to play.\n * @type Event\n */\n this.tourStart = new Event();\n /**\n * Event will be called when all playlist entries are\n * played, or tour playback being canceled.\n *\n * If tour playback was terminated, event callback will\n * be called with terminated=true parameter.\n * @type Event\n */\n this.tourEnd = new Event();\n /**\n * Event will be called when entry from playlist starts to play.\n *\n * Event callback will be called with curent entry as first parameter.\n * @type Event\n */\n this.entryStart = new Event();\n /**\n * Event will be called when entry from playlist ends to play.\n *\n * Event callback will be called with following parameters:\n * 1. entry - entry\n * 2. terminated - true if playback was terminated by calling {@link KmlTour#stop}\n * @type Event\n */\n this.entryEnd = new Event();\n\n this._activeEntries = [];\n}\n\n/**\n * Add entry to this tour playlist.\n *\n * @param {KmlTourFlyTo|KmlTourWait} entry an entry to add to the playlist.\n */\nKmlTour.prototype.addPlaylistEntry = function (entry) {\n this.playlist.push(entry);\n};\n\n/**\n * Play this tour.\n *\n * @param {CesiumWidget} widget The widget.\n * @param {object} [cameraOptions] these options will be merged with {@link Camera#flyTo}\n * options for FlyTo playlist entries.\n */\nKmlTour.prototype.play = function (widget, cameraOptions) {\n this.tourStart.raiseEvent();\n\n const tour = this;\n playEntry.call(this, widget, cameraOptions, function (terminated) {\n tour.playlistIndex = 0;\n // Stop nonblocking entries\n if (!terminated) {\n cancelAllEntries(tour._activeEntries);\n }\n tour.tourEnd.raiseEvent(terminated);\n });\n};\n\n/**\n * Stop curently playing tour.\n */\nKmlTour.prototype.stop = function () {\n cancelAllEntries(this._activeEntries);\n};\n\n// Stop all activeEntries.\nfunction cancelAllEntries(activeEntries) {\n for (\n let entry = activeEntries.pop();\n entry !== undefined;\n entry = activeEntries.pop()\n ) {\n entry.stop();\n }\n}\n\n// Play playlist entry.\n// This function is called recursevly with playNext and iterates over all entries from playlist.\nfunction playEntry(widget, cameraOptions, allDone) {\n const entry = this.playlist[this.playlistIndex];\n if (entry) {\n const _playNext = playNext.bind(this, widget, cameraOptions, allDone);\n this._activeEntries.push(entry);\n this.entryStart.raiseEvent(entry);\n if (entry.blocking) {\n entry.play(_playNext, widget.scene.camera, cameraOptions);\n } else {\n const tour = this;\n entry.play(function () {\n tour.entryEnd.raiseEvent(entry);\n const indx = tour._activeEntries.indexOf(entry);\n if (indx >= 0) {\n tour._activeEntries.splice(indx, 1);\n }\n });\n _playNext(widget, cameraOptions, allDone);\n }\n } else if (defined(allDone)) {\n allDone(false);\n }\n}\n\n// Increment playlistIndex and call playEntry if terminated isn't true.\nfunction playNext(widget, cameraOptions, allDone, terminated) {\n const entry = this.playlist[this.playlistIndex];\n this.entryEnd.raiseEvent(entry, terminated);\n\n if (terminated) {\n allDone(terminated);\n } else {\n const indx = this._activeEntries.indexOf(entry);\n if (indx >= 0) {\n this._activeEntries.splice(indx, 1);\n }\n this.playlistIndex++;\n playEntry.call(this, widget, cameraOptions, allDone);\n }\n}\nexport default KmlTour;\n", "/**\n * The Ease class provides a collection of easing functions for use with tween.js.\n */\nvar Easing = Object.freeze({\n Linear: Object.freeze({\n None: function (amount) {\n return amount;\n },\n In: function (amount) {\n return this.None(amount);\n },\n Out: function (amount) {\n return this.None(amount);\n },\n InOut: function (amount) {\n return this.None(amount);\n },\n }),\n Quadratic: Object.freeze({\n In: function (amount) {\n return amount * amount;\n },\n Out: function (amount) {\n return amount * (2 - amount);\n },\n InOut: function (amount) {\n if ((amount *= 2) < 1) {\n return 0.5 * amount * amount;\n }\n return -0.5 * (--amount * (amount - 2) - 1);\n },\n }),\n Cubic: Object.freeze({\n In: function (amount) {\n return amount * amount * amount;\n },\n Out: function (amount) {\n return --amount * amount * amount + 1;\n },\n InOut: function (amount) {\n if ((amount *= 2) < 1) {\n return 0.5 * amount * amount * amount;\n }\n return 0.5 * ((amount -= 2) * amount * amount + 2);\n },\n }),\n Quartic: Object.freeze({\n In: function (amount) {\n return amount * amount * amount * amount;\n },\n Out: function (amount) {\n return 1 - --amount * amount * amount * amount;\n },\n InOut: function (amount) {\n if ((amount *= 2) < 1) {\n return 0.5 * amount * amount * amount * amount;\n }\n return -0.5 * ((amount -= 2) * amount * amount * amount - 2);\n },\n }),\n Quintic: Object.freeze({\n In: function (amount) {\n return amount * amount * amount * amount * amount;\n },\n Out: function (amount) {\n return --amount * amount * amount * amount * amount + 1;\n },\n InOut: function (amount) {\n if ((amount *= 2) < 1) {\n return 0.5 * amount * amount * amount * amount * amount;\n }\n return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);\n },\n }),\n Sinusoidal: Object.freeze({\n In: function (amount) {\n return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);\n },\n Out: function (amount) {\n return Math.sin((amount * Math.PI) / 2);\n },\n InOut: function (amount) {\n return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));\n },\n }),\n Exponential: Object.freeze({\n In: function (amount) {\n return amount === 0 ? 0 : Math.pow(1024, amount - 1);\n },\n Out: function (amount) {\n return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);\n },\n InOut: function (amount) {\n if (amount === 0) {\n return 0;\n }\n if (amount === 1) {\n return 1;\n }\n if ((amount *= 2) < 1) {\n return 0.5 * Math.pow(1024, amount - 1);\n }\n return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);\n },\n }),\n Circular: Object.freeze({\n In: function (amount) {\n return 1 - Math.sqrt(1 - amount * amount);\n },\n Out: function (amount) {\n return Math.sqrt(1 - --amount * amount);\n },\n InOut: function (amount) {\n if ((amount *= 2) < 1) {\n return -0.5 * (Math.sqrt(1 - amount * amount) - 1);\n }\n return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);\n },\n }),\n Elastic: Object.freeze({\n In: function (amount) {\n if (amount === 0) {\n return 0;\n }\n if (amount === 1) {\n return 1;\n }\n return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);\n },\n Out: function (amount) {\n if (amount === 0) {\n return 0;\n }\n if (amount === 1) {\n return 1;\n }\n return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;\n },\n InOut: function (amount) {\n if (amount === 0) {\n return 0;\n }\n if (amount === 1) {\n return 1;\n }\n amount *= 2;\n if (amount < 1) {\n return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);\n }\n return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;\n },\n }),\n Back: Object.freeze({\n In: function (amount) {\n var s = 1.70158;\n return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);\n },\n Out: function (amount) {\n var s = 1.70158;\n return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;\n },\n InOut: function (amount) {\n var s = 1.70158 * 1.525;\n if ((amount *= 2) < 1) {\n return 0.5 * (amount * amount * ((s + 1) * amount - s));\n }\n return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);\n },\n }),\n Bounce: Object.freeze({\n In: function (amount) {\n return 1 - Easing.Bounce.Out(1 - amount);\n },\n Out: function (amount) {\n if (amount < 1 / 2.75) {\n return 7.5625 * amount * amount;\n }\n else if (amount < 2 / 2.75) {\n return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;\n }\n else if (amount < 2.5 / 2.75) {\n return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;\n }\n else {\n return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;\n }\n },\n InOut: function (amount) {\n if (amount < 0.5) {\n return Easing.Bounce.In(amount * 2) * 0.5;\n }\n return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;\n },\n }),\n generatePow: function (power) {\n if (power === void 0) { power = 4; }\n power = power < Number.EPSILON ? Number.EPSILON : power;\n power = power > 10000 ? 10000 : power;\n return {\n In: function (amount) {\n return Math.pow(amount, power);\n },\n Out: function (amount) {\n return 1 - Math.pow((1 - amount), power);\n },\n InOut: function (amount) {\n if (amount < 0.5) {\n return Math.pow((amount * 2), power) / 2;\n }\n return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;\n },\n };\n },\n});\n\nvar now = function () { return performance.now(); };\n\n/**\n * Controlling groups of tweens\n *\n * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.\n * In these cases, you may want to create your own smaller groups of tween\n */\nvar Group = /** @class */ (function () {\n function Group() {\n this._tweens = {};\n this._tweensAddedDuringUpdate = {};\n }\n Group.prototype.getAll = function () {\n var _this = this;\n return Object.keys(this._tweens).map(function (tweenId) {\n return _this._tweens[tweenId];\n });\n };\n Group.prototype.removeAll = function () {\n this._tweens = {};\n };\n Group.prototype.add = function (tween) {\n this._tweens[tween.getId()] = tween;\n this._tweensAddedDuringUpdate[tween.getId()] = tween;\n };\n Group.prototype.remove = function (tween) {\n delete this._tweens[tween.getId()];\n delete this._tweensAddedDuringUpdate[tween.getId()];\n };\n Group.prototype.update = function (time, preserve) {\n if (time === void 0) { time = now(); }\n if (preserve === void 0) { preserve = false; }\n var tweenIds = Object.keys(this._tweens);\n if (tweenIds.length === 0) {\n return false;\n }\n // Tweens are updated in \"batches\". If you add a new tween during an\n // update, then the new tween will be updated in the next batch.\n // If you remove a tween during an update, it may or may not be updated.\n // However, if the removed tween was added during the current batch,\n // then it will not be updated.\n while (tweenIds.length > 0) {\n this._tweensAddedDuringUpdate = {};\n for (var i = 0; i < tweenIds.length; i++) {\n var tween = this._tweens[tweenIds[i]];\n var autoStart = !preserve;\n if (tween && tween.update(time, autoStart) === false && !preserve) {\n delete this._tweens[tweenIds[i]];\n }\n }\n tweenIds = Object.keys(this._tweensAddedDuringUpdate);\n }\n return true;\n };\n return Group;\n}());\n\n/**\n *\n */\nvar Interpolation = {\n Linear: function (v, k) {\n var m = v.length - 1;\n var f = m * k;\n var i = Math.floor(f);\n var fn = Interpolation.Utils.Linear;\n if (k < 0) {\n return fn(v[0], v[1], f);\n }\n if (k > 1) {\n return fn(v[m], v[m - 1], m - f);\n }\n return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);\n },\n Bezier: function (v, k) {\n var b = 0;\n var n = v.length - 1;\n var pw = Math.pow;\n var bn = Interpolation.Utils.Bernstein;\n for (var i = 0; i <= n; i++) {\n b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);\n }\n return b;\n },\n CatmullRom: function (v, k) {\n var m = v.length - 1;\n var f = m * k;\n var i = Math.floor(f);\n var fn = Interpolation.Utils.CatmullRom;\n if (v[0] === v[m]) {\n if (k < 0) {\n i = Math.floor((f = m * (1 + k)));\n }\n return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);\n }\n else {\n if (k < 0) {\n return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);\n }\n if (k > 1) {\n return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);\n }\n return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);\n }\n },\n Utils: {\n Linear: function (p0, p1, t) {\n return (p1 - p0) * t + p0;\n },\n Bernstein: function (n, i) {\n var fc = Interpolation.Utils.Factorial;\n return fc(n) / fc(i) / fc(n - i);\n },\n Factorial: (function () {\n var a = [1];\n return function (n) {\n var s = 1;\n if (a[n]) {\n return a[n];\n }\n for (var i = n; i > 1; i--) {\n s *= i;\n }\n a[n] = s;\n return s;\n };\n })(),\n CatmullRom: function (p0, p1, p2, p3, t) {\n var v0 = (p2 - p0) * 0.5;\n var v1 = (p3 - p1) * 0.5;\n var t2 = t * t;\n var t3 = t * t2;\n return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;\n },\n },\n};\n\n/**\n * Utils\n */\nvar Sequence = /** @class */ (function () {\n function Sequence() {\n }\n Sequence.nextId = function () {\n return Sequence._nextId++;\n };\n Sequence._nextId = 0;\n return Sequence;\n}());\n\nvar mainGroup = new Group();\n\n/**\n * Tween.js - Licensed under the MIT license\n * https://github.com/tweenjs/tween.js\n * ----------------------------------------------\n *\n * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.\n * Thank you all, you're awesome!\n */\nvar Tween = /** @class */ (function () {\n function Tween(_object, _group) {\n if (_group === void 0) { _group = mainGroup; }\n this._object = _object;\n this._group = _group;\n this._isPaused = false;\n this._pauseStart = 0;\n this._valuesStart = {};\n this._valuesEnd = {};\n this._valuesStartRepeat = {};\n this._duration = 1000;\n this._isDynamic = false;\n this._initialRepeat = 0;\n this._repeat = 0;\n this._yoyo = false;\n this._isPlaying = false;\n this._reversed = false;\n this._delayTime = 0;\n this._startTime = 0;\n this._easingFunction = Easing.Linear.None;\n this._interpolationFunction = Interpolation.Linear;\n // eslint-disable-next-line\n this._chainedTweens = [];\n this._onStartCallbackFired = false;\n this._onEveryStartCallbackFired = false;\n this._id = Sequence.nextId();\n this._isChainStopped = false;\n this._propertiesAreSetUp = false;\n this._goToEnd = false;\n }\n Tween.prototype.getId = function () {\n return this._id;\n };\n Tween.prototype.isPlaying = function () {\n return this._isPlaying;\n };\n Tween.prototype.isPaused = function () {\n return this._isPaused;\n };\n Tween.prototype.to = function (target, duration) {\n if (duration === void 0) { duration = 1000; }\n if (this._isPlaying)\n throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');\n this._valuesEnd = target;\n this._propertiesAreSetUp = false;\n this._duration = duration;\n return this;\n };\n Tween.prototype.duration = function (duration) {\n if (duration === void 0) { duration = 1000; }\n this._duration = duration;\n return this;\n };\n Tween.prototype.dynamic = function (dynamic) {\n if (dynamic === void 0) { dynamic = false; }\n this._isDynamic = dynamic;\n return this;\n };\n Tween.prototype.start = function (time, overrideStartingValues) {\n if (time === void 0) { time = now(); }\n if (overrideStartingValues === void 0) { overrideStartingValues = false; }\n if (this._isPlaying) {\n return this;\n }\n // eslint-disable-next-line\n this._group && this._group.add(this);\n this._repeat = this._initialRepeat;\n if (this._reversed) {\n // If we were reversed (f.e. using the yoyo feature) then we need to\n // flip the tween direction back to forward.\n this._reversed = false;\n for (var property in this._valuesStartRepeat) {\n this._swapEndStartRepeatValues(property);\n this._valuesStart[property] = this._valuesStartRepeat[property];\n }\n }\n this._isPlaying = true;\n this._isPaused = false;\n this._onStartCallbackFired = false;\n this._onEveryStartCallbackFired = false;\n this._isChainStopped = false;\n this._startTime = time;\n this._startTime += this._delayTime;\n if (!this._propertiesAreSetUp || overrideStartingValues) {\n this._propertiesAreSetUp = true;\n // If dynamic is not enabled, clone the end values instead of using the passed-in end values.\n if (!this._isDynamic) {\n var tmp = {};\n for (var prop in this._valuesEnd)\n tmp[prop] = this._valuesEnd[prop];\n this._valuesEnd = tmp;\n }\n this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);\n }\n return this;\n };\n Tween.prototype.startFromCurrentValues = function (time) {\n return this.start(time, true);\n };\n Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {\n for (var property in _valuesEnd) {\n var startValue = _object[property];\n var startValueIsArray = Array.isArray(startValue);\n var propType = startValueIsArray ? 'array' : typeof startValue;\n var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);\n // If `to()` specifies a property that doesn't exist in the source object,\n // we should not set that property in the object\n if (propType === 'undefined' || propType === 'function') {\n continue;\n }\n // Check if an Array was provided as property value\n if (isInterpolationList) {\n var endValues = _valuesEnd[property];\n if (endValues.length === 0) {\n continue;\n }\n // Handle an array of relative values.\n // Creates a local copy of the Array with the start value at the front\n var temp = [startValue];\n for (var i = 0, l = endValues.length; i < l; i += 1) {\n var value = this._handleRelativeValue(startValue, endValues[i]);\n if (isNaN(value)) {\n isInterpolationList = false;\n console.warn('Found invalid interpolation list. Skipping.');\n break;\n }\n temp.push(value);\n }\n if (isInterpolationList) {\n // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.\n _valuesEnd[property] = temp;\n // }\n }\n }\n // handle the deepness of the values\n if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {\n _valuesStart[property] = startValueIsArray ? [] : {};\n var nestedObject = startValue;\n for (var prop in nestedObject) {\n _valuesStart[property][prop] = nestedObject[prop];\n }\n // TODO? repeat nested values? And yoyo? And array values?\n _valuesStartRepeat[property] = startValueIsArray ? [] : {};\n var endValues = _valuesEnd[property];\n // If dynamic is not enabled, clone the end values instead of using the passed-in end values.\n if (!this._isDynamic) {\n var tmp = {};\n for (var prop in endValues)\n tmp[prop] = endValues[prop];\n _valuesEnd[property] = endValues = tmp;\n }\n this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);\n }\n else {\n // Save the starting value, but only once unless override is requested.\n if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {\n _valuesStart[property] = startValue;\n }\n if (!startValueIsArray) {\n // eslint-disable-next-line\n // @ts-ignore FIXME?\n _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings\n }\n if (isInterpolationList) {\n // eslint-disable-next-line\n // @ts-ignore FIXME?\n _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();\n }\n else {\n _valuesStartRepeat[property] = _valuesStart[property] || 0;\n }\n }\n }\n };\n Tween.prototype.stop = function () {\n if (!this._isChainStopped) {\n this._isChainStopped = true;\n this.stopChainedTweens();\n }\n if (!this._isPlaying) {\n return this;\n }\n // eslint-disable-next-line\n this._group && this._group.remove(this);\n this._isPlaying = false;\n this._isPaused = false;\n if (this._onStopCallback) {\n this._onStopCallback(this._object);\n }\n return this;\n };\n Tween.prototype.end = function () {\n this._goToEnd = true;\n this.update(Infinity);\n return this;\n };\n Tween.prototype.pause = function (time) {\n if (time === void 0) { time = now(); }\n if (this._isPaused || !this._isPlaying) {\n return this;\n }\n this._isPaused = true;\n this._pauseStart = time;\n // eslint-disable-next-line\n this._group && this._group.remove(this);\n return this;\n };\n Tween.prototype.resume = function (time) {\n if (time === void 0) { time = now(); }\n if (!this._isPaused || !this._isPlaying) {\n return this;\n }\n this._isPaused = false;\n this._startTime += time - this._pauseStart;\n this._pauseStart = 0;\n // eslint-disable-next-line\n this._group && this._group.add(this);\n return this;\n };\n Tween.prototype.stopChainedTweens = function () {\n for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n this._chainedTweens[i].stop();\n }\n return this;\n };\n Tween.prototype.group = function (group) {\n if (group === void 0) { group = mainGroup; }\n this._group = group;\n return this;\n };\n Tween.prototype.delay = function (amount) {\n if (amount === void 0) { amount = 0; }\n this._delayTime = amount;\n return this;\n };\n Tween.prototype.repeat = function (times) {\n if (times === void 0) { times = 0; }\n this._initialRepeat = times;\n this._repeat = times;\n return this;\n };\n Tween.prototype.repeatDelay = function (amount) {\n this._repeatDelayTime = amount;\n return this;\n };\n Tween.prototype.yoyo = function (yoyo) {\n if (yoyo === void 0) { yoyo = false; }\n this._yoyo = yoyo;\n return this;\n };\n Tween.prototype.easing = function (easingFunction) {\n if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }\n this._easingFunction = easingFunction;\n return this;\n };\n Tween.prototype.interpolation = function (interpolationFunction) {\n if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }\n this._interpolationFunction = interpolationFunction;\n return this;\n };\n // eslint-disable-next-line\n Tween.prototype.chain = function () {\n var tweens = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n tweens[_i] = arguments[_i];\n }\n this._chainedTweens = tweens;\n return this;\n };\n Tween.prototype.onStart = function (callback) {\n this._onStartCallback = callback;\n return this;\n };\n Tween.prototype.onEveryStart = function (callback) {\n this._onEveryStartCallback = callback;\n return this;\n };\n Tween.prototype.onUpdate = function (callback) {\n this._onUpdateCallback = callback;\n return this;\n };\n Tween.prototype.onRepeat = function (callback) {\n this._onRepeatCallback = callback;\n return this;\n };\n Tween.prototype.onComplete = function (callback) {\n this._onCompleteCallback = callback;\n return this;\n };\n Tween.prototype.onStop = function (callback) {\n this._onStopCallback = callback;\n return this;\n };\n /**\n * @returns true if the tween is still playing after the update, false\n * otherwise (calling update on a paused tween still returns true because\n * it is still playing, just paused).\n */\n Tween.prototype.update = function (time, autoStart) {\n if (time === void 0) { time = now(); }\n if (autoStart === void 0) { autoStart = true; }\n if (this._isPaused)\n return true;\n var property;\n var elapsed;\n var endTime = this._startTime + this._duration;\n if (!this._goToEnd && !this._isPlaying) {\n if (time > endTime)\n return false;\n if (autoStart)\n this.start(time, true);\n }\n this._goToEnd = false;\n if (time < this._startTime) {\n return true;\n }\n if (this._onStartCallbackFired === false) {\n if (this._onStartCallback) {\n this._onStartCallback(this._object);\n }\n this._onStartCallbackFired = true;\n }\n if (this._onEveryStartCallbackFired === false) {\n if (this._onEveryStartCallback) {\n this._onEveryStartCallback(this._object);\n }\n this._onEveryStartCallbackFired = true;\n }\n elapsed = (time - this._startTime) / this._duration;\n elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;\n var value = this._easingFunction(elapsed);\n // properties transformations\n this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);\n if (this._onUpdateCallback) {\n this._onUpdateCallback(this._object, elapsed);\n }\n if (elapsed === 1) {\n if (this._repeat > 0) {\n if (isFinite(this._repeat)) {\n this._repeat--;\n }\n // Reassign starting values, restart by making startTime = now\n for (property in this._valuesStartRepeat) {\n if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {\n this._valuesStartRepeat[property] =\n // eslint-disable-next-line\n // @ts-ignore FIXME?\n this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);\n }\n if (this._yoyo) {\n this._swapEndStartRepeatValues(property);\n }\n this._valuesStart[property] = this._valuesStartRepeat[property];\n }\n if (this._yoyo) {\n this._reversed = !this._reversed;\n }\n if (this._repeatDelayTime !== undefined) {\n this._startTime = time + this._repeatDelayTime;\n }\n else {\n this._startTime = time + this._delayTime;\n }\n if (this._onRepeatCallback) {\n this._onRepeatCallback(this._object);\n }\n this._onEveryStartCallbackFired = false;\n return true;\n }\n else {\n if (this._onCompleteCallback) {\n this._onCompleteCallback(this._object);\n }\n for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {\n // Make the chained tweens start exactly at the time they should,\n // even if the `update()` method was called way past the duration of the tween\n this._chainedTweens[i].start(this._startTime + this._duration, false);\n }\n this._isPlaying = false;\n return false;\n }\n }\n return true;\n };\n Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {\n for (var property in _valuesEnd) {\n // Don't update properties that do not exist in the source object\n if (_valuesStart[property] === undefined) {\n continue;\n }\n var start = _valuesStart[property] || 0;\n var end = _valuesEnd[property];\n var startIsArray = Array.isArray(_object[property]);\n var endIsArray = Array.isArray(end);\n var isInterpolationList = !startIsArray && endIsArray;\n if (isInterpolationList) {\n _object[property] = this._interpolationFunction(end, value);\n }\n else if (typeof end === 'object' && end) {\n // eslint-disable-next-line\n // @ts-ignore FIXME?\n this._updateProperties(_object[property], start, end, value);\n }\n else {\n // Parses relative end values with start as base (e.g.: +10, -3)\n end = this._handleRelativeValue(start, end);\n // Protect against non numeric properties.\n if (typeof end === 'number') {\n // eslint-disable-next-line\n // @ts-ignore FIXME?\n _object[property] = start + (end - start) * value;\n }\n }\n }\n };\n Tween.prototype._handleRelativeValue = function (start, end) {\n if (typeof end !== 'string') {\n return end;\n }\n if (end.charAt(0) === '+' || end.charAt(0) === '-') {\n return start + parseFloat(end);\n }\n return parseFloat(end);\n };\n Tween.prototype._swapEndStartRepeatValues = function (property) {\n var tmp = this._valuesStartRepeat[property];\n var endValue = this._valuesEnd[property];\n if (typeof endValue === 'string') {\n this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);\n }\n else {\n this._valuesStartRepeat[property] = this._valuesEnd[property];\n }\n this._valuesEnd[property] = tmp;\n };\n return Tween;\n}());\n\nvar VERSION = '21.0.0';\n\n/**\n * Tween.js - Licensed under the MIT license\n * https://github.com/tweenjs/tween.js\n * ----------------------------------------------\n *\n * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.\n * Thank you all, you're awesome!\n */\nvar nextId = Sequence.nextId;\n/**\n * Controlling groups of tweens\n *\n * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.\n * In these cases, you may want to create your own smaller groups of tweens.\n */\nvar TWEEN = mainGroup;\n// This is the best way to export things in a way that's compatible with both ES\n// Modules and CommonJS, without build hacks, and so as not to break the\n// existing API.\n// https://github.com/rollup/rollup/issues/1961#issuecomment-423037881\nvar getAll = TWEEN.getAll.bind(TWEEN);\nvar removeAll = TWEEN.removeAll.bind(TWEEN);\nvar add = TWEEN.add.bind(TWEEN);\nvar remove = TWEEN.remove.bind(TWEEN);\nvar update = TWEEN.update.bind(TWEEN);\nvar exports = {\n Easing: Easing,\n Group: Group,\n Interpolation: Interpolation,\n now: now,\n Sequence: Sequence,\n nextId: nextId,\n Tween: Tween,\n VERSION: VERSION,\n getAll: getAll,\n removeAll: removeAll,\n add: add,\n remove: remove,\n update: update,\n};\n\nexport { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };\n", "import { Easing } from \"@tweenjs/tween.js\";\n\n/**\n * Easing functions for use with TweenCollection. These function are from\n * {@link https://github.com/sole/tween.js/|Tween.js} and Robert Penner. See the\n * {@link http://sole.github.io/tween.js/examples/03_graphs.html|Tween.js graphs for each function}.\n *\n * @namespace\n */\nconst EasingFunction = {\n /**\n * Linear easing.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n LINEAR_NONE: Easing.Linear.None,\n\n /**\n * Quadratic in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUADRATIC_IN: Easing.Quadratic.In,\n /**\n * Quadratic out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUADRATIC_OUT: Easing.Quadratic.Out,\n /**\n * Quadratic in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUADRATIC_IN_OUT: Easing.Quadratic.InOut,\n\n /**\n * Cubic in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CUBIC_IN: Easing.Cubic.In,\n /**\n * Cubic out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CUBIC_OUT: Easing.Cubic.Out,\n /**\n * Cubic in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CUBIC_IN_OUT: Easing.Cubic.InOut,\n\n /**\n * Quartic in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUARTIC_IN: Easing.Quartic.In,\n /**\n * Quartic out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUARTIC_OUT: Easing.Quartic.Out,\n /**\n * Quartic in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUARTIC_IN_OUT: Easing.Quartic.InOut,\n\n /**\n * Quintic in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUINTIC_IN: Easing.Quintic.In,\n /**\n * Quintic out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUINTIC_OUT: Easing.Quintic.Out,\n /**\n * Quintic in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n QUINTIC_IN_OUT: Easing.Quintic.InOut,\n\n /**\n * Sinusoidal in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n SINUSOIDAL_IN: Easing.Sinusoidal.In,\n /**\n * Sinusoidal out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n SINUSOIDAL_OUT: Easing.Sinusoidal.Out,\n /**\n * Sinusoidal in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n SINUSOIDAL_IN_OUT: Easing.Sinusoidal.InOut,\n\n /**\n * Exponential in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n EXPONENTIAL_IN: Easing.Exponential.In,\n /**\n * Exponential out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n EXPONENTIAL_OUT: Easing.Exponential.Out,\n /**\n * Exponential in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n EXPONENTIAL_IN_OUT: Easing.Exponential.InOut,\n\n /**\n * Circular in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CIRCULAR_IN: Easing.Circular.In,\n /**\n * Circular out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CIRCULAR_OUT: Easing.Circular.Out,\n /**\n * Circular in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n CIRCULAR_IN_OUT: Easing.Circular.InOut,\n\n /**\n * Elastic in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n ELASTIC_IN: Easing.Elastic.In,\n /**\n * Elastic out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n ELASTIC_OUT: Easing.Elastic.Out,\n /**\n * Elastic in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n ELASTIC_IN_OUT: Easing.Elastic.InOut,\n\n /**\n * Back in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BACK_IN: Easing.Back.In,\n /**\n * Back out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BACK_OUT: Easing.Back.Out,\n /**\n * Back in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BACK_IN_OUT: Easing.Back.InOut,\n\n /**\n * Bounce in.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BOUNCE_IN: Easing.Bounce.In,\n /**\n * Bounce out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BOUNCE_OUT: Easing.Bounce.Out,\n /**\n * Bounce in then out.\n *\n * @type {EasingFunction.Callback}\n * @constant\n */\n BOUNCE_IN_OUT: Easing.Bounce.InOut,\n};\n\n/**\n * Function interface for implementing a custom easing function.\n * @callback EasingFunction.Callback\n * @param {number} time The time in the range [0, 1].\n * @returns {number} The value of the function at the given time.\n *\n * @example\n * function quadraticIn(time) {\n * return time * time;\n * }\n *\n * @example\n * function quadraticOut(time) {\n * return time * (2.0 - time);\n * }\n */\n\nexport default Object.freeze(EasingFunction);\n", "import BoundingSphere from \"../Core/BoundingSphere.js\";\nimport combine from \"../Core/combine.js\";\nimport defined from \"../Core/defined.js\";\nimport EasingFunction from \"../Core/EasingFunction.js\";\n/**\n * Transitions the KmlTour to the next destination. This transition is facilitated\n * using a specified flyToMode over a given number of seconds.\n *\n * @alias KmlTourFlyTo\n * @constructor\n *\n * @param {number} duration entry duration\n * @param {string} flyToMode KML fly to mode: bounce, smooth, etc\n * @param {KmlCamera|KmlLookAt} view KmlCamera or KmlLookAt\n *\n * @see KmlTour\n * @see KmlTourWait\n */\nfunction KmlTourFlyTo(duration, flyToMode, view) {\n this.type = \"KmlTourFlyTo\";\n this.blocking = true;\n this.activeCamera = null;\n this.activeCallback = null;\n\n this.duration = duration;\n this.view = view;\n this.flyToMode = flyToMode;\n}\n\n/**\n * Play this playlist entry\n *\n * @param {KmlTourFlyTo.DoneCallback} done function which will be called when playback ends\n * @param {Camera} camera Cesium camera\n * @param {object} [cameraOptions] which will be merged with camera flyTo options. See {@link Camera#flyTo}\n */\nKmlTourFlyTo.prototype.play = function (done, camera, cameraOptions) {\n this.activeCamera = camera;\n if (defined(done) && done !== null) {\n const self = this;\n this.activeCallback = function (terminated) {\n delete self.activeCallback;\n delete self.activeCamera;\n done(defined(terminated) ? false : terminated);\n };\n }\n\n const options = this.getCameraOptions(cameraOptions);\n if (this.view.headingPitchRoll) {\n camera.flyTo(options);\n } else if (this.view.headingPitchRange) {\n const target = new BoundingSphere(this.view.position);\n camera.flyToBoundingSphere(target, options);\n }\n};\n\n/**\n * Stop execution of curent entry. Cancel camera flyTo\n */\nKmlTourFlyTo.prototype.stop = function () {\n if (defined(this.activeCamera)) {\n this.activeCamera.cancelFlight();\n }\n if (defined(this.activeCallback)) {\n this.activeCallback(true);\n }\n};\n\n/**\n * Returns options for {@link Camera#flyTo} or {@link Camera#flyToBoundingSphere}\n * depends on this.view type.\n *\n * @param {object} cameraOptions options to merge with generated. See {@link Camera#flyTo}\n * @returns {object} {@link Camera#flyTo} or {@link Camera#flyToBoundingSphere} options\n */\nKmlTourFlyTo.prototype.getCameraOptions = function (cameraOptions) {\n let options = {\n duration: this.duration,\n };\n\n if (defined(this.activeCallback)) {\n options.complete = this.activeCallback;\n }\n\n if (this.flyToMode === \"smooth\") {\n options.easingFunction = EasingFunction.LINEAR_NONE;\n }\n\n if (this.view.headingPitchRoll) {\n options.destination = this.view.position;\n options.orientation = this.view.headingPitchRoll;\n } else if (this.view.headingPitchRange) {\n options.offset = this.view.headingPitchRange;\n }\n\n if (defined(cameraOptions)) {\n options = combine(options, cameraOptions);\n }\n return options;\n};\n\n/**\n * A function that will be executed when the flight completes.\n * @callback KmlTourFlyTo.DoneCallback\n *\n * @param {boolean} terminated true if {@link KmlTourFlyTo#stop} was\n * called before entry done playback.\n */\nexport default KmlTourFlyTo;\n", "import defined from \"../Core/defined.js\";\n/**\n * Pauses the KmlTour for a given number of seconds.\n *\n * @alias KmlTourWait\n * @constructor\n *\n * @param {number} duration entry duration\n *\n * @see KmlTour\n * @see KmlTourFlyTo\n */\nfunction KmlTourWait(duration) {\n this.type = \"KmlTourWait\";\n this.blocking = true;\n this.duration = duration;\n\n this.timeout = null;\n}\n\n/**\n * Play this playlist entry\n *\n * @param {KmlTourWait.DoneCallback} done function which will be called when playback ends\n */\nKmlTourWait.prototype.play = function (done) {\n const self = this;\n this.activeCallback = done;\n this.timeout = setTimeout(function () {\n delete self.activeCallback;\n done(false);\n }, this.duration * 1000);\n};\n\n/**\n * Stop execution of curent entry, cancel curent timeout\n */\nKmlTourWait.prototype.stop = function () {\n clearTimeout(this.timeout);\n if (defined(this.activeCallback)) {\n this.activeCallback(true);\n }\n};\n\n/**\n * A function which will be called when playback ends.\n *\n * @callback KmlTourWait.DoneCallback\n * @param {boolean} terminated true if {@link KmlTourWait#stop} was\n * called before entry done playback.\n */\nexport default KmlTourWait;\n", "import DeveloperError from \"../Core/DeveloperError.js\";\n\n/**\n * Defines the interface for visualizers. Visualizers are plug-ins to\n * {@link DataSourceDisplay} that render data associated with\n * {@link DataSource} instances.\n * This object is an interface for documentation purposes and is not intended\n * to be instantiated directly.\n * @alias Visualizer\n * @constructor\n *\n * @see BillboardVisualizer\n * @see LabelVisualizer\n * @see ModelVisualizer\n * @see PathVisualizer\n * @see PointVisualizer\n * @see GeometryVisualizer\n */\nfunction Visualizer() {\n DeveloperError.throwInstantiationError();\n}\n\n/**\n * Updates the visualization to the provided time.\n * @function\n *\n * @param {JulianDate} time The time.\n *\n * @returns {boolean} True if the display was updated to the provided time,\n * false if the visualizer is waiting for an asynchronous operation to\n * complete before data can be updated.\n */\nVisualizer.prototype.update = DeveloperError.throwInstantiationError;\n\n/**\n * Computes a bounding sphere which encloses the visualization produced for the specified entity.\n * The bounding sphere is in the fixed frame of the scene's globe.\n *\n * @param {Entity} entity The entity whose bounding sphere to compute.\n * @param {BoundingSphere} result The bounding sphere onto which to store the result.\n * @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,\n * BoundingSphereState.PENDING if the result is still being computed, or\n * BoundingSphereState.FAILED if the entity has no visualization in the current scene.\n * @private\n */\nVisualizer.prototype.getBoundingSphere = DeveloperError.throwInstantiationError;\n\n/**\n * Returns true if this object was destroyed; otherwise, false.\n * @function\n *\n * @returns {boolean} True if this object was destroyed; otherwise, false.\n */\nVisualizer.prototype.isDestroyed = DeveloperError.throwInstantiationError;\n\n/**\n * Removes all visualization and cleans up any resources associated with this instance.\n * @function\n */\nVisualizer.prototype.destroy = DeveloperError.throwInstantiationError;\nexport default Visualizer;\n", "import buildModuleUrl from \"../Core/buildModuleUrl.js\";\nimport Cartesian2 from \"../Core/Cartesian2.js\";\nimport Cartesian3 from \"../Core/Cartesian3.js\";\nimport Cartographic from \"../Core/Cartographic.js\";\nimport Color from \"../Core/Color.js\";\nimport createGuid from \"../Core/createGuid.js\";\nimport defaultValue from \"../Core/defaultValue.js\";\nimport defined from \"../Core/defined.js\";\nimport DeveloperError from \"../Core/DeveloperError.js\";\nimport Ellipsoid from \"../Core/Ellipsoid.js\";\nimport Iso8601 from \"../Core/Iso8601.js\";\nimport JulianDate from \"../Core/JulianDate.js\";\nimport CesiumMath from \"../Core/Math.js\";\nimport Rectangle from \"../Core/Rectangle.js\";\nimport ReferenceFrame from \"../Core/ReferenceFrame.js\";\nimport Resource from \"../Core/Resource.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport TimeInterval from \"../Core/TimeInterval.js\";\nimport TimeIntervalCollection from \"../Core/TimeIntervalCollection.js\";\nimport HeightReference from \"../Scene/HeightReference.js\";\nimport HorizontalOrigin from \"../Scene/HorizontalOrigin.js\";\nimport VerticalOrigin from \"../Scene/VerticalOrigin.js\";\nimport * as zip from \"@zip.js/zip.js/lib/zip-no-worker.js\";\nimport BillboardGraphics from \"./BillboardGraphics.js\";\nimport CompositePositionProperty from \"./CompositePositionProperty.js\";\nimport ModelGraphics from \"./ModelGraphics.js\";\nimport RectangleGraphics from \"./RectangleGraphics.js\";\nimport SampledPositionProperty from \"./SampledPositionProperty.js\";\nimport SampledProperty from \"./SampledProperty.js\";\nimport ScaledPositionProperty from \"./ScaledPositionProperty.js\";\n\nconst BILLBOARD_SIZE = 32;\nconst kmlNamespace = \"http://www.opengis.net/kml/2.2\";\nconst gxNamespace = \"http://www.google.com/kml/ext/2.2\";\nconst xmlnsNamespace = \"http://www.w3.org/2000/xmlns/\";\n\n//\n// Handles files external to the KML (eg. textures and models)\n//\nfunction ExternalFileHandler(modelCallback) {\n this._files = {};\n this._promises = [];\n this._count = 0;\n this._modelCallback = modelCallback;\n}\n\nconst imageTypeRegex = /^data:image\\/([^,;]+)/;\nExternalFileHandler.prototype.texture = function (texture) {\n const that = this;\n let filename;\n\n if (typeof texture === \"string\" || texture instanceof Resource) {\n texture = Resource.createIfNeeded(texture);\n if (!texture.isDataUri) {\n return texture.url;\n }\n\n // If its a data URI try and get the correct extension and then fetch the blob\n const regexResult = texture.url.match(imageTypeRegex);\n filename = `texture_${++this._count}`;\n if (defined(regexResult)) {\n filename += `.${regexResult[1]}`;\n }\n\n const promise = texture.fetchBlob().then(function (blob) {\n that._files[filename] = blob;\n });\n\n this._promises.push(promise);\n\n return filename;\n }\n\n if (texture instanceof HTMLCanvasElement) {\n filename = `texture_${++this._count}.png`;\n const promise = new Promise((resolve) => {\n texture.toBlob(function (blob) {\n that._files[filename] = blob;\n resolve();\n });\n });\n this._promises.push(promise);\n\n return filename;\n }\n\n return \"\";\n};\n\nfunction getModelBlobHander(that, filename) {\n return function (blob) {\n that._files[filename] = blob;\n };\n}\n\nExternalFileHandler.prototype.model = function (model, time) {\n const modelCallback = this._modelCallback;\n if (!defined(modelCallback)) {\n throw new RuntimeError(\n \"Encountered a model entity while exporting to KML, but no model callback was supplied.\"\n );\n }\n\n const externalFiles = {};\n const url = modelCallback(model, time, externalFiles);\n\n // Iterate through external files and add them to our list once the promise resolves\n for (const filename in externalFiles) {\n if (externalFiles.hasOwnProperty(filename)) {\n const promise = Promise.resolve(externalFiles[filename]);\n this._promises.push(promise);\n\n promise.then(getModelBlobHander(this, filename));\n }\n }\n\n return url;\n};\n\nObject.defineProperties(ExternalFileHandler.prototype, {\n promise: {\n get: function () {\n return Promise.all(this._promises);\n },\n },\n files: {\n get: function () {\n return this._files;\n },\n },\n});\n\n//\n// Handles getting values from properties taking the desired time and default values into account\n//\nfunction ValueGetter(time) {\n this._time = time;\n}\n\nValueGetter.prototype.get = function (property, defaultVal, result) {\n let value;\n if (defined(property)) {\n value = defined(property.getValue)\n ? property.getValue(this._time, result)\n : property;\n }\n\n return defaultValue(value, defaultVal);\n};\n\nValueGetter.prototype.getColor = function (property, defaultVal) {\n const result = this.get(property, defaultVal);\n if (defined(result)) {\n return colorToString(result);\n }\n};\n\nValueGetter.prototype.getMaterialType = function (property) {\n if (!defined(property)) {\n return;\n }\n\n return property.getType(this._time);\n};\n\n//\n// Caches styles so we don't generate a ton of duplicate styles\n//\nfunction StyleCache() {\n this._ids = {};\n this._styles = {};\n this._count = 0;\n}\n\nStyleCache.prototype.get = function (element) {\n const ids = this._ids;\n const key = element.innerHTML;\n if (defined(ids[key])) {\n return ids[key];\n }\n\n let styleId = `style-${++this._count}`;\n element.setAttribute(\"id\", styleId);\n\n // Store with #\n styleId = `#${styleId}`;\n ids[key] = styleId;\n this._styles[key] = element;\n\n return styleId;\n};\n\nStyleCache.prototype.save = function (parentElement) {\n const styles = this._styles;\n\n const firstElement = parentElement.childNodes[0];\n for (const key in styles) {\n if (styles.hasOwnProperty(key)) {\n parentElement.insertBefore(styles[key], firstElement);\n }\n }\n};\n\n//\n// Manages the generation of IDs because an entity may have geometry and a Folder for children\n//\nfunction IdManager() {\n this._ids = {};\n}\n\nIdManager.prototype.get = function (id) {\n if (!defined(id)) {\n return this.get(createGuid());\n }\n\n const ids = this._ids;\n if (!defined(ids[id])) {\n ids[id] = 0;\n return id;\n }\n\n return `${id.toString()}-${++ids[id]}`;\n};\n\n/**\n * @typedef exportKmlResultKml\n * @type {object}\n * @property {string} kml The generated KML.\n * @property {Object} externalFiles An object dictionary of external files\n */\n\n/**\n * @typedef exportKmlResultKmz\n * @type {object}\n * @property {Blob} kmz The generated kmz file.\n */\n\n/**\n * Exports an EntityCollection as a KML document. Only Point, Billboard, Model, Path, Polygon, Polyline geometries\n * will be exported. Note that there is not a 1 to 1 mapping of Entity properties to KML Feature properties. For\n * example, entity properties that are time dynamic but cannot be dynamic in KML are exported with their values at\n * options.time or the beginning of the EntityCollection's time interval if not specified. For time-dynamic properties\n * that are supported in KML, we use the samples if it is a {@link SampledProperty} otherwise we sample the value using\n * the options.sampleDuration. Point, Billboard, Model and Path geometries with time-dynamic positions will be exported\n * as gx:Track Features. Not all Materials are representable in KML, so for more advanced Materials just the primary\n * color is used. Canvas objects are exported as PNG images.\n *\n * @function exportKml\n *\n * @param {object} options An object with the following properties:\n * @param {EntityCollection} options.entities The EntityCollection to export as KML.\n * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for the output file.\n * @param {exportKmlModelCallback} [options.modelCallback] A callback that will be called with a {@link ModelGraphics} instance and should return the URI to use in the KML. Required if a model exists in the entity collection.\n * @param {JulianDate} [options.time=entities.computeAvailability().start] The time value to use to get properties that are not time varying in KML.\n * @param {TimeInterval} [options.defaultAvailability=entities.computeAvailability()] The interval that will be sampled if an entity doesn't have an availability.\n * @param {number} [options.sampleDuration=60] The number of seconds to sample properties that are varying in KML.\n * @param {boolean} [options.kmz=false] If true KML and external files will be compressed into a kmz file.\n *\n * @returns {Promise} A promise that resolved to an object containing the KML string and a dictionary of external file blobs, or a kmz file as a blob if options.kmz is true.\n * @demo {@link https://sandcastle.cesium.com/index.html?src=Export%20KML.html|Cesium Sandcastle KML Export Demo}\n * @example\n * Cesium.exportKml({\n * entities: entityCollection\n * })\n * .then(function(result) {\n * // The XML string is in result.kml\n *\n * const externalFiles = result.externalFiles\n * for(const file in externalFiles) {\n * // file is the name of the file used in the KML document as the href\n * // externalFiles[file] is a blob with the contents of the file\n * }\n * });\n *\n */\nfunction exportKml(options) {\n options = defaultValue(options, defaultValue.EMPTY_OBJECT);\n const entities = options.entities;\n const kmz = defaultValue(options.kmz, false);\n\n //>>includeStart('debug', pragmas.debug);\n if (!defined(entities)) {\n throw new DeveloperError(\"entities is required.\");\n }\n //>>includeEnd('debug');\n\n // Get the state that is passed around during the recursion\n // This is separated out for testing.\n const state = exportKml._createState(options);\n\n // Filter EntityCollection so we only have top level entities\n const rootEntities = entities.values.filter(function (entity) {\n return !defined(entity.parent);\n });\n\n // Add the \n const kmlDoc = state.kmlDoc;\n const kmlElement = kmlDoc.documentElement;\n kmlElement.setAttributeNS(xmlnsNamespace, \"xmlns:gx\", gxNamespace);\n const kmlDocumentElement = kmlDoc.createElement(\"Document\");\n kmlElement.appendChild(kmlDocumentElement);\n\n // Create the KML Hierarchy\n recurseEntities(state, kmlDocumentElement, rootEntities);\n\n // Write out the